1 /* $NetBSD: amdgpu_hw_factory_dce110.c,v 1.2 2021/12/18 23:45:04 riastradh Exp $ */ 2 3 /* 4 * Copyright 2013-15 Advanced Micro Devices, Inc. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the "Software"), 8 * to deal in the Software without restriction, including without limitation 9 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 * and/or sell copies of the Software, and to permit persons to whom the 11 * Software is furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 * OTHER DEALINGS IN THE SOFTWARE. 23 * 24 * Authors: AMD 25 * 26 */ 27 28 #include <sys/cdefs.h> 29 __KERNEL_RCSID(0, "$NetBSD: amdgpu_hw_factory_dce110.c,v 1.2 2021/12/18 23:45:04 riastradh Exp $"); 30 31 #include "dm_services.h" 32 33 #include "include/gpio_types.h" 34 #include "../hw_factory.h" 35 36 #include "../hw_gpio.h" 37 #include "../hw_ddc.h" 38 #include "../hw_hpd.h" 39 #include "../hw_generic.h" 40 41 #include "hw_factory_dce110.h" 42 43 #include "dce/dce_11_0_d.h" 44 #include "dce/dce_11_0_sh_mask.h" 45 46 /* set field name */ 47 #define SF_HPD(reg_name, field_name, post_fix)\ 48 .field_name = reg_name ## __ ## field_name ## post_fix 49 50 #define REG(reg_name)\ 51 mm ## reg_name 52 53 #define REGI(reg_name, block, id)\ 54 mm ## block ## id ## _ ## reg_name 55 56 #include "../hw_gpio.h" 57 #include "../hw_ddc.h" 58 #include "../hw_hpd.h" 59 60 #include "reg_helper.h" 61 #include "../hpd_regs.h" 62 63 #define hpd_regs(id) \ 64 {\ 65 HPD_REG_LIST(id)\ 66 } 67 68 static const struct hpd_registers hpd_regs[] = { 69 hpd_regs(0), 70 hpd_regs(1), 71 hpd_regs(2), 72 hpd_regs(3), 73 hpd_regs(4), 74 hpd_regs(5) 75 }; 76 77 static const struct hpd_sh_mask hpd_shift = { 78 HPD_MASK_SH_LIST(__SHIFT) 79 }; 80 81 static const struct hpd_sh_mask hpd_mask = { 82 HPD_MASK_SH_LIST(_MASK) 83 }; 84 85 #include "../ddc_regs.h" 86 87 /* set field name */ 88 #define SF_DDC(reg_name, field_name, post_fix)\ 89 .field_name = reg_name ## __ ## field_name ## post_fix 90 91 static const struct ddc_registers ddc_data_regs[] = { 92 ddc_data_regs(1), 93 ddc_data_regs(2), 94 ddc_data_regs(3), 95 ddc_data_regs(4), 96 ddc_data_regs(5), 97 ddc_data_regs(6), 98 ddc_vga_data_regs, 99 ddc_i2c_data_regs 100 }; 101 102 static const struct ddc_registers ddc_clk_regs[] = { 103 ddc_clk_regs(1), 104 ddc_clk_regs(2), 105 ddc_clk_regs(3), 106 ddc_clk_regs(4), 107 ddc_clk_regs(5), 108 ddc_clk_regs(6), 109 ddc_vga_clk_regs, 110 ddc_i2c_clk_regs 111 }; 112 113 static const struct ddc_sh_mask ddc_shift = { 114 DDC_MASK_SH_LIST(__SHIFT) 115 }; 116 117 static const struct ddc_sh_mask ddc_mask = { 118 DDC_MASK_SH_LIST(_MASK) 119 }; 120 121 static void define_ddc_registers( 122 struct hw_gpio_pin *pin, 123 uint32_t en) 124 { 125 struct hw_ddc *ddc = HW_DDC_FROM_BASE(pin); 126 127 switch (pin->id) { 128 case GPIO_ID_DDC_DATA: 129 ddc->regs = &ddc_data_regs[en]; 130 ddc->base.regs = &ddc_data_regs[en].gpio; 131 break; 132 case GPIO_ID_DDC_CLOCK: 133 ddc->regs = &ddc_clk_regs[en]; 134 ddc->base.regs = &ddc_clk_regs[en].gpio; 135 break; 136 default: 137 ASSERT_CRITICAL(false); 138 return; 139 } 140 141 ddc->shifts = &ddc_shift; 142 ddc->masks = &ddc_mask; 143 144 } 145 146 static void define_hpd_registers(struct hw_gpio_pin *pin, uint32_t en) 147 { 148 struct hw_hpd *hpd = HW_HPD_FROM_BASE(pin); 149 150 hpd->regs = &hpd_regs[en]; 151 hpd->shifts = &hpd_shift; 152 hpd->masks = &hpd_mask; 153 hpd->base.regs = &hpd_regs[en].gpio; 154 } 155 156 static const struct hw_factory_funcs funcs = { 157 .init_ddc_data = dal_hw_ddc_init, 158 .init_generic = NULL, 159 .init_hpd = dal_hw_hpd_init, 160 .get_ddc_pin = dal_hw_ddc_get_pin, 161 .get_hpd_pin = dal_hw_hpd_get_pin, 162 .get_generic_pin = NULL, 163 .define_hpd_registers = define_hpd_registers, 164 .define_ddc_registers = define_ddc_registers 165 }; 166 167 /* 168 * dal_hw_factory_dce110_init 169 * 170 * @brief 171 * Initialize HW factory function pointers and pin info 172 * 173 * @param 174 * struct hw_factory *factory - [out] struct of function pointers 175 */ 176 void dal_hw_factory_dce110_init(struct hw_factory *factory) 177 { 178 /*TODO check ASIC CAPs*/ 179 factory->number_of_pins[GPIO_ID_DDC_DATA] = 8; 180 factory->number_of_pins[GPIO_ID_DDC_CLOCK] = 8; 181 factory->number_of_pins[GPIO_ID_GENERIC] = 7; 182 factory->number_of_pins[GPIO_ID_HPD] = 6; 183 factory->number_of_pins[GPIO_ID_GPIO_PAD] = 31; 184 factory->number_of_pins[GPIO_ID_VIP_PAD] = 0; 185 factory->number_of_pins[GPIO_ID_SYNC] = 2; 186 factory->number_of_pins[GPIO_ID_GSL] = 4; 187 188 factory->funcs = &funcs; 189 } 190