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