11b255f1cSBen Skeggs /* 21b255f1cSBen Skeggs * Copyright 2021 Red Hat Inc. 31b255f1cSBen Skeggs * 41b255f1cSBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a 51b255f1cSBen Skeggs * copy of this software and associated documentation files (the "Software"), 61b255f1cSBen Skeggs * to deal in the Software without restriction, including without limitation 71b255f1cSBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense, 81b255f1cSBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the 91b255f1cSBen Skeggs * Software is furnished to do so, subject to the following conditions: 101b255f1cSBen Skeggs * 111b255f1cSBen Skeggs * The above copyright notice and this permission notice shall be included in 121b255f1cSBen Skeggs * all copies or substantial portions of the Software. 131b255f1cSBen Skeggs * 141b255f1cSBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 151b255f1cSBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 161b255f1cSBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 171b255f1cSBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 181b255f1cSBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 191b255f1cSBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 201b255f1cSBen Skeggs * OTHER DEALINGS IN THE SOFTWARE. 211b255f1cSBen Skeggs */ 221b255f1cSBen Skeggs #include <nvif/outp.h> 231b255f1cSBen Skeggs #include <nvif/disp.h> 241b255f1cSBen Skeggs #include <nvif/printf.h> 251b255f1cSBen Skeggs 261b255f1cSBen Skeggs #include <nvif/class.h> 27f530bc60SBen Skeggs 28f530bc60SBen Skeggs int 298c7d980dSBen Skeggs nvif_outp_dp_mst_vcpi(struct nvif_outp *outp, int head, 308c7d980dSBen Skeggs u8 start_slot, u8 num_slots, u16 pbn, u16 aligned_pbn) 318c7d980dSBen Skeggs { 328c7d980dSBen Skeggs struct nvif_outp_dp_mst_vcpi_v0 args; 338c7d980dSBen Skeggs int ret; 348c7d980dSBen Skeggs 358c7d980dSBen Skeggs args.version = 0; 368c7d980dSBen Skeggs args.head = head; 378c7d980dSBen Skeggs args.start_slot = start_slot; 388c7d980dSBen Skeggs args.num_slots = num_slots; 398c7d980dSBen Skeggs args.pbn = pbn; 408c7d980dSBen Skeggs args.aligned_pbn = aligned_pbn; 418c7d980dSBen Skeggs 428c7d980dSBen Skeggs ret = nvif_object_mthd(&outp->object, NVIF_OUTP_V0_DP_MST_VCPI, &args, sizeof(args)); 438c7d980dSBen Skeggs NVIF_ERRON(ret, &outp->object, 448c7d980dSBen Skeggs "[DP_MST_VCPI head:%d start_slot:%02x num_slots:%02x pbn:%04x aligned_pbn:%04x]", 458c7d980dSBen Skeggs args.head, args.start_slot, args.num_slots, args.pbn, args.aligned_pbn); 468c7d980dSBen Skeggs return ret; 478c7d980dSBen Skeggs } 488c7d980dSBen Skeggs 498c7d980dSBen Skeggs int 508bb30c88SBen Skeggs nvif_outp_dp_retrain(struct nvif_outp *outp) 518bb30c88SBen Skeggs { 528bb30c88SBen Skeggs int ret = nvif_object_mthd(&outp->object, NVIF_OUTP_V0_DP_RETRAIN, NULL, 0); 538bb30c88SBen Skeggs NVIF_ERRON(ret, &outp->object, "[DP_RETRAIN]"); 548bb30c88SBen Skeggs return ret; 558bb30c88SBen Skeggs } 568bb30c88SBen Skeggs 578bb30c88SBen Skeggs int 58a62b7493SBen Skeggs nvif_outp_dp_aux_pwr(struct nvif_outp *outp, bool enable) 59a62b7493SBen Skeggs { 60a62b7493SBen Skeggs struct nvif_outp_dp_aux_pwr_v0 args; 61a62b7493SBen Skeggs int ret; 62a62b7493SBen Skeggs 63a62b7493SBen Skeggs args.version = 0; 64a62b7493SBen Skeggs args.state = enable; 65a62b7493SBen Skeggs 66a62b7493SBen Skeggs ret = nvif_object_mthd(&outp->object, NVIF_OUTP_V0_DP_AUX_PWR, &args, sizeof(args)); 67a62b7493SBen Skeggs NVIF_ERRON(ret, &outp->object, "[DP_AUX_PWR state:%d]", args.state); 68a62b7493SBen Skeggs return ret; 69a62b7493SBen Skeggs } 70a62b7493SBen Skeggs 71a62b7493SBen Skeggs int 72a9f5d772SBen Skeggs nvif_outp_hda_eld(struct nvif_outp *outp, int head, void *data, u32 size) 73a9f5d772SBen Skeggs { 74a9f5d772SBen Skeggs struct { 75a9f5d772SBen Skeggs struct nvif_outp_hda_eld_v0 mthd; 76a9f5d772SBen Skeggs u8 data[128]; 77a9f5d772SBen Skeggs } args; 78a9f5d772SBen Skeggs int ret; 79a9f5d772SBen Skeggs 80a9f5d772SBen Skeggs if (WARN_ON(size > ARRAY_SIZE(args.data))) 81a9f5d772SBen Skeggs return -EINVAL; 82a9f5d772SBen Skeggs 83a9f5d772SBen Skeggs args.mthd.version = 0; 84a9f5d772SBen Skeggs args.mthd.head = head; 85a9f5d772SBen Skeggs 86a9f5d772SBen Skeggs memcpy(args.data, data, size); 87a9f5d772SBen Skeggs ret = nvif_mthd(&outp->object, NVIF_OUTP_V0_HDA_ELD, &args, sizeof(args.mthd) + size); 88a9f5d772SBen Skeggs NVIF_ERRON(ret, &outp->object, "[HDA_ELD head:%d size:%d]", head, size); 89a9f5d772SBen Skeggs return ret; 90a9f5d772SBen Skeggs } 91a9f5d772SBen Skeggs 92a9f5d772SBen Skeggs int 93f530bc60SBen Skeggs nvif_outp_infoframe(struct nvif_outp *outp, u8 type, struct nvif_outp_infoframe_v0 *args, u32 size) 94f530bc60SBen Skeggs { 95f530bc60SBen Skeggs int ret; 96f530bc60SBen Skeggs 97f530bc60SBen Skeggs args->type = type; 98f530bc60SBen Skeggs 99f530bc60SBen Skeggs ret = nvif_mthd(&outp->object, NVIF_OUTP_V0_INFOFRAME, args, sizeof(*args) + size); 100f530bc60SBen Skeggs NVIF_ERRON(ret, &outp->object, "[INFOFRAME type:%d size:%d]", type, size); 101f530bc60SBen Skeggs return ret; 102f530bc60SBen Skeggs } 1031b255f1cSBen Skeggs 104ea6143a8SBen Skeggs void 105ea6143a8SBen Skeggs nvif_outp_release(struct nvif_outp *outp) 106ea6143a8SBen Skeggs { 107ea6143a8SBen Skeggs int ret = nvif_mthd(&outp->object, NVIF_OUTP_V0_RELEASE, NULL, 0); 108ea6143a8SBen Skeggs NVIF_ERRON(ret, &outp->object, "[RELEASE]"); 109ea6143a8SBen Skeggs outp->or.id = -1; 110ea6143a8SBen Skeggs } 111ea6143a8SBen Skeggs 112ea6143a8SBen Skeggs static inline int 113ea6143a8SBen Skeggs nvif_outp_acquire(struct nvif_outp *outp, u8 proto, struct nvif_outp_acquire_v0 *args) 114ea6143a8SBen Skeggs { 115ea6143a8SBen Skeggs int ret; 116ea6143a8SBen Skeggs 117ea6143a8SBen Skeggs args->version = 0; 118ea6143a8SBen Skeggs args->proto = proto; 119ea6143a8SBen Skeggs 120ea6143a8SBen Skeggs ret = nvif_mthd(&outp->object, NVIF_OUTP_V0_ACQUIRE, args, sizeof(*args)); 121ea6143a8SBen Skeggs if (ret) 122ea6143a8SBen Skeggs return ret; 123ea6143a8SBen Skeggs 124ea6143a8SBen Skeggs outp->or.id = args->or; 125ea6143a8SBen Skeggs outp->or.link = args->link; 126ea6143a8SBen Skeggs return 0; 127ea6143a8SBen Skeggs } 128ea6143a8SBen Skeggs 129ea6143a8SBen Skeggs int 130*4076ea24SKees Cook nvif_outp_acquire_dp(struct nvif_outp *outp, u8 dpcd[DP_RECEIVER_CAP_SIZE], 13181344372SBen Skeggs int link_nr, int link_bw, bool hda, bool mst) 132ea6143a8SBen Skeggs { 133ea6143a8SBen Skeggs struct nvif_outp_acquire_v0 args; 134ea6143a8SBen Skeggs int ret; 135ea6143a8SBen Skeggs 13681344372SBen Skeggs args.dp.link_nr = link_nr; 13781344372SBen Skeggs args.dp.link_bw = link_bw; 138ea6143a8SBen Skeggs args.dp.hda = hda; 13981344372SBen Skeggs args.dp.mst = mst; 14081344372SBen Skeggs memcpy(args.dp.dpcd, dpcd, sizeof(args.dp.dpcd)); 141ea6143a8SBen Skeggs 142ea6143a8SBen Skeggs ret = nvif_outp_acquire(outp, NVIF_OUTP_ACQUIRE_V0_DP, &args); 143ea6143a8SBen Skeggs NVIF_ERRON(ret, &outp->object, 14481344372SBen Skeggs "[ACQUIRE proto:DP link_nr:%d link_bw:%02x hda:%d mst:%d] or:%d link:%d", 14581344372SBen Skeggs args.dp.link_nr, args.dp.link_bw, args.dp.hda, args.dp.mst, args.or, args.link); 146ea6143a8SBen Skeggs return ret; 147ea6143a8SBen Skeggs } 148ea6143a8SBen Skeggs 149ea6143a8SBen Skeggs int 1509793083fSBen Skeggs nvif_outp_acquire_lvds(struct nvif_outp *outp, bool dual, bool bpc8) 151ea6143a8SBen Skeggs { 152ea6143a8SBen Skeggs struct nvif_outp_acquire_v0 args; 153ea6143a8SBen Skeggs int ret; 154ea6143a8SBen Skeggs 1559793083fSBen Skeggs args.lvds.dual = dual; 1569793083fSBen Skeggs args.lvds.bpc8 = bpc8; 1579793083fSBen Skeggs 158ea6143a8SBen Skeggs ret = nvif_outp_acquire(outp, NVIF_OUTP_ACQUIRE_V0_LVDS, &args); 1599793083fSBen Skeggs NVIF_ERRON(ret, &outp->object, 1609793083fSBen Skeggs "[ACQUIRE proto:LVDS dual:%d 8bpc:%d] or:%d link:%d", 1619793083fSBen Skeggs args.lvds.dual, args.lvds.bpc8, args.or, args.link); 162ea6143a8SBen Skeggs return ret; 163ea6143a8SBen Skeggs } 164ea6143a8SBen Skeggs 165ea6143a8SBen Skeggs int 166f530bc60SBen Skeggs nvif_outp_acquire_tmds(struct nvif_outp *outp, int head, 167f530bc60SBen Skeggs bool hdmi, u8 max_ac_packet, u8 rekey, u8 scdc, bool hda) 168ea6143a8SBen Skeggs { 169ea6143a8SBen Skeggs struct nvif_outp_acquire_v0 args; 170ea6143a8SBen Skeggs int ret; 171ea6143a8SBen Skeggs 172f530bc60SBen Skeggs args.tmds.head = head; 173f530bc60SBen Skeggs args.tmds.hdmi = hdmi; 174f530bc60SBen Skeggs args.tmds.hdmi_max_ac_packet = max_ac_packet; 175f530bc60SBen Skeggs args.tmds.hdmi_rekey = rekey; 176f530bc60SBen Skeggs args.tmds.hdmi_scdc = scdc; 177f530bc60SBen Skeggs args.tmds.hdmi_hda = hda; 178ea6143a8SBen Skeggs 179ea6143a8SBen Skeggs ret = nvif_outp_acquire(outp, NVIF_OUTP_ACQUIRE_V0_TMDS, &args); 180ea6143a8SBen Skeggs NVIF_ERRON(ret, &outp->object, 181f530bc60SBen Skeggs "[ACQUIRE proto:TMDS head:%d hdmi:%d max_ac_packet:%d rekey:%d scdc:%d hda:%d]" 182f530bc60SBen Skeggs " or:%d link:%d", args.tmds.head, args.tmds.hdmi, args.tmds.hdmi_max_ac_packet, 183f530bc60SBen Skeggs args.tmds.hdmi_rekey, args.tmds.hdmi_scdc, args.tmds.hdmi_hda, 184f530bc60SBen Skeggs args.or, args.link); 185ea6143a8SBen Skeggs return ret; 186ea6143a8SBen Skeggs } 187ea6143a8SBen Skeggs 188ea6143a8SBen Skeggs int 189ea6143a8SBen Skeggs nvif_outp_acquire_rgb_crt(struct nvif_outp *outp) 190ea6143a8SBen Skeggs { 191ea6143a8SBen Skeggs struct nvif_outp_acquire_v0 args; 192ea6143a8SBen Skeggs int ret; 193ea6143a8SBen Skeggs 194ea6143a8SBen Skeggs ret = nvif_outp_acquire(outp, NVIF_OUTP_ACQUIRE_V0_RGB_CRT, &args); 195ea6143a8SBen Skeggs NVIF_ERRON(ret, &outp->object, "[ACQUIRE proto:RGB_CRT] or:%d", args.or); 196ea6143a8SBen Skeggs return ret; 197ea6143a8SBen Skeggs } 198ea6143a8SBen Skeggs 199dfc4005fSBen Skeggs int 200dfc4005fSBen Skeggs nvif_outp_load_detect(struct nvif_outp *outp, u32 loadval) 201dfc4005fSBen Skeggs { 202dfc4005fSBen Skeggs struct nvif_outp_load_detect_v0 args; 203dfc4005fSBen Skeggs int ret; 204dfc4005fSBen Skeggs 205dfc4005fSBen Skeggs args.version = 0; 206dfc4005fSBen Skeggs args.data = loadval; 207dfc4005fSBen Skeggs 208dfc4005fSBen Skeggs ret = nvif_mthd(&outp->object, NVIF_OUTP_V0_LOAD_DETECT, &args, sizeof(args)); 209dfc4005fSBen Skeggs NVIF_ERRON(ret, &outp->object, "[LOAD_DETECT data:%08x] load:%02x", args.data, args.load); 210dfc4005fSBen Skeggs return ret < 0 ? ret : args.load; 211dfc4005fSBen Skeggs } 212dfc4005fSBen Skeggs 2131b255f1cSBen Skeggs void 2141b255f1cSBen Skeggs nvif_outp_dtor(struct nvif_outp *outp) 2151b255f1cSBen Skeggs { 2161b255f1cSBen Skeggs nvif_object_dtor(&outp->object); 2171b255f1cSBen Skeggs } 2181b255f1cSBen Skeggs 2191b255f1cSBen Skeggs int 2201b255f1cSBen Skeggs nvif_outp_ctor(struct nvif_disp *disp, const char *name, int id, struct nvif_outp *outp) 2211b255f1cSBen Skeggs { 2221b255f1cSBen Skeggs struct nvif_outp_v0 args; 2231b255f1cSBen Skeggs int ret; 2241b255f1cSBen Skeggs 2251b255f1cSBen Skeggs args.version = 0; 2261b255f1cSBen Skeggs args.id = id; 2271b255f1cSBen Skeggs 2281b255f1cSBen Skeggs ret = nvif_object_ctor(&disp->object, name ?: "nvifOutp", id, NVIF_CLASS_OUTP, 2291b255f1cSBen Skeggs &args, sizeof(args), &outp->object); 2301b255f1cSBen Skeggs NVIF_ERRON(ret, &disp->object, "[NEW outp id:%d]", id); 231ea6143a8SBen Skeggs if (ret) 2321b255f1cSBen Skeggs return ret; 233ea6143a8SBen Skeggs 234ea6143a8SBen Skeggs outp->or.id = -1; 235ea6143a8SBen Skeggs return 0; 2361b255f1cSBen Skeggs } 237