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 #include <nvif/if0012.h> 28 29 void 30 nvif_outp_release(struct nvif_outp *outp) 31 { 32 int ret = nvif_mthd(&outp->object, NVIF_OUTP_V0_RELEASE, NULL, 0); 33 NVIF_ERRON(ret, &outp->object, "[RELEASE]"); 34 outp->or.id = -1; 35 } 36 37 static inline int 38 nvif_outp_acquire(struct nvif_outp *outp, u8 proto, struct nvif_outp_acquire_v0 *args) 39 { 40 int ret; 41 42 args->version = 0; 43 args->proto = proto; 44 45 ret = nvif_mthd(&outp->object, NVIF_OUTP_V0_ACQUIRE, args, sizeof(*args)); 46 if (ret) 47 return ret; 48 49 outp->or.id = args->or; 50 outp->or.link = args->link; 51 return 0; 52 } 53 54 int 55 nvif_outp_acquire_dp(struct nvif_outp *outp, bool hda) 56 { 57 struct nvif_outp_acquire_v0 args; 58 int ret; 59 60 args.dp.hda = hda; 61 62 ret = nvif_outp_acquire(outp, NVIF_OUTP_ACQUIRE_V0_DP, &args); 63 NVIF_ERRON(ret, &outp->object, 64 "[ACQUIRE proto:DP hda:%d] or:%d link:%d", args.dp.hda, args.or, args.link); 65 return ret; 66 } 67 68 int 69 nvif_outp_acquire_lvds(struct nvif_outp *outp) 70 { 71 struct nvif_outp_acquire_v0 args; 72 int ret; 73 74 ret = nvif_outp_acquire(outp, NVIF_OUTP_ACQUIRE_V0_LVDS, &args); 75 NVIF_ERRON(ret, &outp->object, "[ACQUIRE proto:LVDS] or:%d link:%d", args.or, args.link); 76 return ret; 77 } 78 79 int 80 nvif_outp_acquire_tmds(struct nvif_outp *outp, bool hda) 81 { 82 struct nvif_outp_acquire_v0 args; 83 int ret; 84 85 args.tmds.hda = hda; 86 87 ret = nvif_outp_acquire(outp, NVIF_OUTP_ACQUIRE_V0_TMDS, &args); 88 NVIF_ERRON(ret, &outp->object, 89 "[ACQUIRE proto:TMDS hda:%d] or:%d link:%d", args.tmds.hda, args.or, args.link); 90 return ret; 91 } 92 93 int 94 nvif_outp_acquire_rgb_crt(struct nvif_outp *outp) 95 { 96 struct nvif_outp_acquire_v0 args; 97 int ret; 98 99 ret = nvif_outp_acquire(outp, NVIF_OUTP_ACQUIRE_V0_RGB_CRT, &args); 100 NVIF_ERRON(ret, &outp->object, "[ACQUIRE proto:RGB_CRT] or:%d", args.or); 101 return ret; 102 } 103 104 int 105 nvif_outp_load_detect(struct nvif_outp *outp, u32 loadval) 106 { 107 struct nvif_outp_load_detect_v0 args; 108 int ret; 109 110 args.version = 0; 111 args.data = loadval; 112 113 ret = nvif_mthd(&outp->object, NVIF_OUTP_V0_LOAD_DETECT, &args, sizeof(args)); 114 NVIF_ERRON(ret, &outp->object, "[LOAD_DETECT data:%08x] load:%02x", args.data, args.load); 115 return ret < 0 ? ret : args.load; 116 } 117 118 void 119 nvif_outp_dtor(struct nvif_outp *outp) 120 { 121 nvif_object_dtor(&outp->object); 122 } 123 124 int 125 nvif_outp_ctor(struct nvif_disp *disp, const char *name, int id, struct nvif_outp *outp) 126 { 127 struct nvif_outp_v0 args; 128 int ret; 129 130 args.version = 0; 131 args.id = id; 132 133 ret = nvif_object_ctor(&disp->object, name ?: "nvifOutp", id, NVIF_CLASS_OUTP, 134 &args, sizeof(args), &outp->object); 135 NVIF_ERRON(ret, &disp->object, "[NEW outp id:%d]", id); 136 if (ret) 137 return ret; 138 139 outp->or.id = -1; 140 return 0; 141 } 142