1 /* 2 * Copyright 2021 Red Hat Inc. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 */ 22 #include <nvif/outp.h> 23 #include <nvif/disp.h> 24 #include <nvif/printf.h> 25 26 #include <nvif/class.h> 27 28 int 29 nvif_outp_infoframe(struct nvif_outp *outp, u8 type, struct nvif_outp_infoframe_v0 *args, u32 size) 30 { 31 int ret; 32 33 args->type = type; 34 35 ret = nvif_mthd(&outp->object, NVIF_OUTP_V0_INFOFRAME, args, sizeof(*args) + size); 36 NVIF_ERRON(ret, &outp->object, "[INFOFRAME type:%d size:%d]", type, size); 37 return ret; 38 } 39 40 void 41 nvif_outp_release(struct nvif_outp *outp) 42 { 43 int ret = nvif_mthd(&outp->object, NVIF_OUTP_V0_RELEASE, NULL, 0); 44 NVIF_ERRON(ret, &outp->object, "[RELEASE]"); 45 outp->or.id = -1; 46 } 47 48 static inline int 49 nvif_outp_acquire(struct nvif_outp *outp, u8 proto, struct nvif_outp_acquire_v0 *args) 50 { 51 int ret; 52 53 args->version = 0; 54 args->proto = proto; 55 56 ret = nvif_mthd(&outp->object, NVIF_OUTP_V0_ACQUIRE, args, sizeof(*args)); 57 if (ret) 58 return ret; 59 60 outp->or.id = args->or; 61 outp->or.link = args->link; 62 return 0; 63 } 64 65 int 66 nvif_outp_acquire_dp(struct nvif_outp *outp, bool hda) 67 { 68 struct nvif_outp_acquire_v0 args; 69 int ret; 70 71 args.dp.hda = hda; 72 73 ret = nvif_outp_acquire(outp, NVIF_OUTP_ACQUIRE_V0_DP, &args); 74 NVIF_ERRON(ret, &outp->object, 75 "[ACQUIRE proto:DP hda:%d] or:%d link:%d", args.dp.hda, args.or, args.link); 76 return ret; 77 } 78 79 int 80 nvif_outp_acquire_lvds(struct nvif_outp *outp, bool dual, bool bpc8) 81 { 82 struct nvif_outp_acquire_v0 args; 83 int ret; 84 85 args.lvds.dual = dual; 86 args.lvds.bpc8 = bpc8; 87 88 ret = nvif_outp_acquire(outp, NVIF_OUTP_ACQUIRE_V0_LVDS, &args); 89 NVIF_ERRON(ret, &outp->object, 90 "[ACQUIRE proto:LVDS dual:%d 8bpc:%d] or:%d link:%d", 91 args.lvds.dual, args.lvds.bpc8, args.or, args.link); 92 return ret; 93 } 94 95 int 96 nvif_outp_acquire_tmds(struct nvif_outp *outp, int head, 97 bool hdmi, u8 max_ac_packet, u8 rekey, u8 scdc, bool hda) 98 { 99 struct nvif_outp_acquire_v0 args; 100 int ret; 101 102 args.tmds.head = head; 103 args.tmds.hdmi = hdmi; 104 args.tmds.hdmi_max_ac_packet = max_ac_packet; 105 args.tmds.hdmi_rekey = rekey; 106 args.tmds.hdmi_scdc = scdc; 107 args.tmds.hdmi_hda = hda; 108 109 ret = nvif_outp_acquire(outp, NVIF_OUTP_ACQUIRE_V0_TMDS, &args); 110 NVIF_ERRON(ret, &outp->object, 111 "[ACQUIRE proto:TMDS head:%d hdmi:%d max_ac_packet:%d rekey:%d scdc:%d hda:%d]" 112 " or:%d link:%d", args.tmds.head, args.tmds.hdmi, args.tmds.hdmi_max_ac_packet, 113 args.tmds.hdmi_rekey, args.tmds.hdmi_scdc, args.tmds.hdmi_hda, 114 args.or, args.link); 115 return ret; 116 } 117 118 int 119 nvif_outp_acquire_rgb_crt(struct nvif_outp *outp) 120 { 121 struct nvif_outp_acquire_v0 args; 122 int ret; 123 124 ret = nvif_outp_acquire(outp, NVIF_OUTP_ACQUIRE_V0_RGB_CRT, &args); 125 NVIF_ERRON(ret, &outp->object, "[ACQUIRE proto:RGB_CRT] or:%d", args.or); 126 return ret; 127 } 128 129 int 130 nvif_outp_load_detect(struct nvif_outp *outp, u32 loadval) 131 { 132 struct nvif_outp_load_detect_v0 args; 133 int ret; 134 135 args.version = 0; 136 args.data = loadval; 137 138 ret = nvif_mthd(&outp->object, NVIF_OUTP_V0_LOAD_DETECT, &args, sizeof(args)); 139 NVIF_ERRON(ret, &outp->object, "[LOAD_DETECT data:%08x] load:%02x", args.data, args.load); 140 return ret < 0 ? ret : args.load; 141 } 142 143 void 144 nvif_outp_dtor(struct nvif_outp *outp) 145 { 146 nvif_object_dtor(&outp->object); 147 } 148 149 int 150 nvif_outp_ctor(struct nvif_disp *disp, const char *name, int id, struct nvif_outp *outp) 151 { 152 struct nvif_outp_v0 args; 153 int ret; 154 155 args.version = 0; 156 args.id = id; 157 158 ret = nvif_object_ctor(&disp->object, name ?: "nvifOutp", id, NVIF_CLASS_OUTP, 159 &args, sizeof(args), &outp->object); 160 NVIF_ERRON(ret, &disp->object, "[NEW outp id:%d]", id); 161 if (ret) 162 return ret; 163 164 outp->or.id = -1; 165 return 0; 166 } 167