162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * Copyright 2021 Red Hat Inc. 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 562306a36Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 662306a36Sopenharmony_ci * to deal in the Software without restriction, including without limitation 762306a36Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 862306a36Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 962306a36Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 1062306a36Sopenharmony_ci * 1162306a36Sopenharmony_ci * The above copyright notice and this permission notice shall be included in 1262306a36Sopenharmony_ci * all copies or substantial portions of the Software. 1362306a36Sopenharmony_ci * 1462306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1562306a36Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1662306a36Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1762306a36Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 1862306a36Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 1962306a36Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 2062306a36Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE. 2162306a36Sopenharmony_ci */ 2262306a36Sopenharmony_ci#include <nvif/outp.h> 2362306a36Sopenharmony_ci#include <nvif/disp.h> 2462306a36Sopenharmony_ci#include <nvif/printf.h> 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci#include <nvif/class.h> 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ciint 2962306a36Sopenharmony_cinvif_outp_dp_mst_vcpi(struct nvif_outp *outp, int head, 3062306a36Sopenharmony_ci u8 start_slot, u8 num_slots, u16 pbn, u16 aligned_pbn) 3162306a36Sopenharmony_ci{ 3262306a36Sopenharmony_ci struct nvif_outp_dp_mst_vcpi_v0 args; 3362306a36Sopenharmony_ci int ret; 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci args.version = 0; 3662306a36Sopenharmony_ci args.head = head; 3762306a36Sopenharmony_ci args.start_slot = start_slot; 3862306a36Sopenharmony_ci args.num_slots = num_slots; 3962306a36Sopenharmony_ci args.pbn = pbn; 4062306a36Sopenharmony_ci args.aligned_pbn = aligned_pbn; 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ci ret = nvif_object_mthd(&outp->object, NVIF_OUTP_V0_DP_MST_VCPI, &args, sizeof(args)); 4362306a36Sopenharmony_ci NVIF_ERRON(ret, &outp->object, 4462306a36Sopenharmony_ci "[DP_MST_VCPI head:%d start_slot:%02x num_slots:%02x pbn:%04x aligned_pbn:%04x]", 4562306a36Sopenharmony_ci args.head, args.start_slot, args.num_slots, args.pbn, args.aligned_pbn); 4662306a36Sopenharmony_ci return ret; 4762306a36Sopenharmony_ci} 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ciint 5062306a36Sopenharmony_cinvif_outp_dp_retrain(struct nvif_outp *outp) 5162306a36Sopenharmony_ci{ 5262306a36Sopenharmony_ci int ret = nvif_object_mthd(&outp->object, NVIF_OUTP_V0_DP_RETRAIN, NULL, 0); 5362306a36Sopenharmony_ci NVIF_ERRON(ret, &outp->object, "[DP_RETRAIN]"); 5462306a36Sopenharmony_ci return ret; 5562306a36Sopenharmony_ci} 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ciint 5862306a36Sopenharmony_cinvif_outp_dp_aux_pwr(struct nvif_outp *outp, bool enable) 5962306a36Sopenharmony_ci{ 6062306a36Sopenharmony_ci struct nvif_outp_dp_aux_pwr_v0 args; 6162306a36Sopenharmony_ci int ret; 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci args.version = 0; 6462306a36Sopenharmony_ci args.state = enable; 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci ret = nvif_object_mthd(&outp->object, NVIF_OUTP_V0_DP_AUX_PWR, &args, sizeof(args)); 6762306a36Sopenharmony_ci NVIF_ERRON(ret, &outp->object, "[DP_AUX_PWR state:%d]", args.state); 6862306a36Sopenharmony_ci return ret; 6962306a36Sopenharmony_ci} 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ciint 7262306a36Sopenharmony_cinvif_outp_hda_eld(struct nvif_outp *outp, int head, void *data, u32 size) 7362306a36Sopenharmony_ci{ 7462306a36Sopenharmony_ci struct { 7562306a36Sopenharmony_ci struct nvif_outp_hda_eld_v0 mthd; 7662306a36Sopenharmony_ci u8 data[128]; 7762306a36Sopenharmony_ci } args; 7862306a36Sopenharmony_ci int ret; 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ci if (WARN_ON(size > ARRAY_SIZE(args.data))) 8162306a36Sopenharmony_ci return -EINVAL; 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ci args.mthd.version = 0; 8462306a36Sopenharmony_ci args.mthd.head = head; 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ci memcpy(args.data, data, size); 8762306a36Sopenharmony_ci ret = nvif_mthd(&outp->object, NVIF_OUTP_V0_HDA_ELD, &args, sizeof(args.mthd) + size); 8862306a36Sopenharmony_ci NVIF_ERRON(ret, &outp->object, "[HDA_ELD head:%d size:%d]", head, size); 8962306a36Sopenharmony_ci return ret; 9062306a36Sopenharmony_ci} 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ciint 9362306a36Sopenharmony_cinvif_outp_infoframe(struct nvif_outp *outp, u8 type, struct nvif_outp_infoframe_v0 *args, u32 size) 9462306a36Sopenharmony_ci{ 9562306a36Sopenharmony_ci int ret; 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ci args->type = type; 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_ci ret = nvif_mthd(&outp->object, NVIF_OUTP_V0_INFOFRAME, args, sizeof(*args) + size); 10062306a36Sopenharmony_ci NVIF_ERRON(ret, &outp->object, "[INFOFRAME type:%d size:%d]", type, size); 10162306a36Sopenharmony_ci return ret; 10262306a36Sopenharmony_ci} 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_civoid 10562306a36Sopenharmony_cinvif_outp_release(struct nvif_outp *outp) 10662306a36Sopenharmony_ci{ 10762306a36Sopenharmony_ci int ret = nvif_mthd(&outp->object, NVIF_OUTP_V0_RELEASE, NULL, 0); 10862306a36Sopenharmony_ci NVIF_ERRON(ret, &outp->object, "[RELEASE]"); 10962306a36Sopenharmony_ci outp->or.id = -1; 11062306a36Sopenharmony_ci} 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_cistatic inline int 11362306a36Sopenharmony_cinvif_outp_acquire(struct nvif_outp *outp, u8 proto, struct nvif_outp_acquire_v0 *args) 11462306a36Sopenharmony_ci{ 11562306a36Sopenharmony_ci int ret; 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_ci args->version = 0; 11862306a36Sopenharmony_ci args->proto = proto; 11962306a36Sopenharmony_ci 12062306a36Sopenharmony_ci ret = nvif_mthd(&outp->object, NVIF_OUTP_V0_ACQUIRE, args, sizeof(*args)); 12162306a36Sopenharmony_ci if (ret) 12262306a36Sopenharmony_ci return ret; 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ci outp->or.id = args->or; 12562306a36Sopenharmony_ci outp->or.link = args->link; 12662306a36Sopenharmony_ci return 0; 12762306a36Sopenharmony_ci} 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_ciint 13062306a36Sopenharmony_cinvif_outp_acquire_dp(struct nvif_outp *outp, u8 dpcd[DP_RECEIVER_CAP_SIZE], 13162306a36Sopenharmony_ci int link_nr, int link_bw, bool hda, bool mst) 13262306a36Sopenharmony_ci{ 13362306a36Sopenharmony_ci struct nvif_outp_acquire_v0 args; 13462306a36Sopenharmony_ci int ret; 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ci args.dp.link_nr = link_nr; 13762306a36Sopenharmony_ci args.dp.link_bw = link_bw; 13862306a36Sopenharmony_ci args.dp.hda = hda; 13962306a36Sopenharmony_ci args.dp.mst = mst; 14062306a36Sopenharmony_ci memcpy(args.dp.dpcd, dpcd, sizeof(args.dp.dpcd)); 14162306a36Sopenharmony_ci 14262306a36Sopenharmony_ci ret = nvif_outp_acquire(outp, NVIF_OUTP_ACQUIRE_V0_DP, &args); 14362306a36Sopenharmony_ci NVIF_ERRON(ret, &outp->object, 14462306a36Sopenharmony_ci "[ACQUIRE proto:DP link_nr:%d link_bw:%02x hda:%d mst:%d] or:%d link:%d", 14562306a36Sopenharmony_ci args.dp.link_nr, args.dp.link_bw, args.dp.hda, args.dp.mst, args.or, args.link); 14662306a36Sopenharmony_ci return ret; 14762306a36Sopenharmony_ci} 14862306a36Sopenharmony_ci 14962306a36Sopenharmony_ciint 15062306a36Sopenharmony_cinvif_outp_acquire_lvds(struct nvif_outp *outp, bool dual, bool bpc8) 15162306a36Sopenharmony_ci{ 15262306a36Sopenharmony_ci struct nvif_outp_acquire_v0 args; 15362306a36Sopenharmony_ci int ret; 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_ci args.lvds.dual = dual; 15662306a36Sopenharmony_ci args.lvds.bpc8 = bpc8; 15762306a36Sopenharmony_ci 15862306a36Sopenharmony_ci ret = nvif_outp_acquire(outp, NVIF_OUTP_ACQUIRE_V0_LVDS, &args); 15962306a36Sopenharmony_ci NVIF_ERRON(ret, &outp->object, 16062306a36Sopenharmony_ci "[ACQUIRE proto:LVDS dual:%d 8bpc:%d] or:%d link:%d", 16162306a36Sopenharmony_ci args.lvds.dual, args.lvds.bpc8, args.or, args.link); 16262306a36Sopenharmony_ci return ret; 16362306a36Sopenharmony_ci} 16462306a36Sopenharmony_ci 16562306a36Sopenharmony_ciint 16662306a36Sopenharmony_cinvif_outp_acquire_tmds(struct nvif_outp *outp, int head, 16762306a36Sopenharmony_ci bool hdmi, u8 max_ac_packet, u8 rekey, u8 scdc, bool hda) 16862306a36Sopenharmony_ci{ 16962306a36Sopenharmony_ci struct nvif_outp_acquire_v0 args; 17062306a36Sopenharmony_ci int ret; 17162306a36Sopenharmony_ci 17262306a36Sopenharmony_ci args.tmds.head = head; 17362306a36Sopenharmony_ci args.tmds.hdmi = hdmi; 17462306a36Sopenharmony_ci args.tmds.hdmi_max_ac_packet = max_ac_packet; 17562306a36Sopenharmony_ci args.tmds.hdmi_rekey = rekey; 17662306a36Sopenharmony_ci args.tmds.hdmi_scdc = scdc; 17762306a36Sopenharmony_ci args.tmds.hdmi_hda = hda; 17862306a36Sopenharmony_ci 17962306a36Sopenharmony_ci ret = nvif_outp_acquire(outp, NVIF_OUTP_ACQUIRE_V0_TMDS, &args); 18062306a36Sopenharmony_ci NVIF_ERRON(ret, &outp->object, 18162306a36Sopenharmony_ci "[ACQUIRE proto:TMDS head:%d hdmi:%d max_ac_packet:%d rekey:%d scdc:%d hda:%d]" 18262306a36Sopenharmony_ci " or:%d link:%d", args.tmds.head, args.tmds.hdmi, args.tmds.hdmi_max_ac_packet, 18362306a36Sopenharmony_ci args.tmds.hdmi_rekey, args.tmds.hdmi_scdc, args.tmds.hdmi_hda, 18462306a36Sopenharmony_ci args.or, args.link); 18562306a36Sopenharmony_ci return ret; 18662306a36Sopenharmony_ci} 18762306a36Sopenharmony_ci 18862306a36Sopenharmony_ciint 18962306a36Sopenharmony_cinvif_outp_acquire_rgb_crt(struct nvif_outp *outp) 19062306a36Sopenharmony_ci{ 19162306a36Sopenharmony_ci struct nvif_outp_acquire_v0 args; 19262306a36Sopenharmony_ci int ret; 19362306a36Sopenharmony_ci 19462306a36Sopenharmony_ci ret = nvif_outp_acquire(outp, NVIF_OUTP_ACQUIRE_V0_RGB_CRT, &args); 19562306a36Sopenharmony_ci NVIF_ERRON(ret, &outp->object, "[ACQUIRE proto:RGB_CRT] or:%d", args.or); 19662306a36Sopenharmony_ci return ret; 19762306a36Sopenharmony_ci} 19862306a36Sopenharmony_ci 19962306a36Sopenharmony_ciint 20062306a36Sopenharmony_cinvif_outp_load_detect(struct nvif_outp *outp, u32 loadval) 20162306a36Sopenharmony_ci{ 20262306a36Sopenharmony_ci struct nvif_outp_load_detect_v0 args; 20362306a36Sopenharmony_ci int ret; 20462306a36Sopenharmony_ci 20562306a36Sopenharmony_ci args.version = 0; 20662306a36Sopenharmony_ci args.data = loadval; 20762306a36Sopenharmony_ci 20862306a36Sopenharmony_ci ret = nvif_mthd(&outp->object, NVIF_OUTP_V0_LOAD_DETECT, &args, sizeof(args)); 20962306a36Sopenharmony_ci NVIF_ERRON(ret, &outp->object, "[LOAD_DETECT data:%08x] load:%02x", args.data, args.load); 21062306a36Sopenharmony_ci return ret < 0 ? ret : args.load; 21162306a36Sopenharmony_ci} 21262306a36Sopenharmony_ci 21362306a36Sopenharmony_civoid 21462306a36Sopenharmony_cinvif_outp_dtor(struct nvif_outp *outp) 21562306a36Sopenharmony_ci{ 21662306a36Sopenharmony_ci nvif_object_dtor(&outp->object); 21762306a36Sopenharmony_ci} 21862306a36Sopenharmony_ci 21962306a36Sopenharmony_ciint 22062306a36Sopenharmony_cinvif_outp_ctor(struct nvif_disp *disp, const char *name, int id, struct nvif_outp *outp) 22162306a36Sopenharmony_ci{ 22262306a36Sopenharmony_ci struct nvif_outp_v0 args; 22362306a36Sopenharmony_ci int ret; 22462306a36Sopenharmony_ci 22562306a36Sopenharmony_ci args.version = 0; 22662306a36Sopenharmony_ci args.id = id; 22762306a36Sopenharmony_ci 22862306a36Sopenharmony_ci ret = nvif_object_ctor(&disp->object, name ?: "nvifOutp", id, NVIF_CLASS_OUTP, 22962306a36Sopenharmony_ci &args, sizeof(args), &outp->object); 23062306a36Sopenharmony_ci NVIF_ERRON(ret, &disp->object, "[NEW outp id:%d]", id); 23162306a36Sopenharmony_ci if (ret) 23262306a36Sopenharmony_ci return ret; 23362306a36Sopenharmony_ci 23462306a36Sopenharmony_ci outp->or.id = -1; 23562306a36Sopenharmony_ci return 0; 23662306a36Sopenharmony_ci} 237