14562236bSHarry Wentland /*
24562236bSHarry Wentland  * Copyright 2013-15 Advanced Micro Devices, Inc.
34562236bSHarry Wentland  *
44562236bSHarry Wentland  * Permission is hereby granted, free of charge, to any person obtaining a
54562236bSHarry Wentland  * copy of this software and associated documentation files (the "Software"),
64562236bSHarry Wentland  * to deal in the Software without restriction, including without limitation
74562236bSHarry Wentland  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
84562236bSHarry Wentland  * and/or sell copies of the Software, and to permit persons to whom the
94562236bSHarry Wentland  * Software is furnished to do so, subject to the following conditions:
104562236bSHarry Wentland  *
114562236bSHarry Wentland  * The above copyright notice and this permission notice shall be included in
124562236bSHarry Wentland  * all copies or substantial portions of the Software.
134562236bSHarry Wentland  *
144562236bSHarry Wentland  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
154562236bSHarry Wentland  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
164562236bSHarry Wentland  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
174562236bSHarry Wentland  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
184562236bSHarry Wentland  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
194562236bSHarry Wentland  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
204562236bSHarry Wentland  * OTHER DEALINGS IN THE SOFTWARE.
214562236bSHarry Wentland  *
224562236bSHarry Wentland  * Authors: AMD
234562236bSHarry Wentland  *
244562236bSHarry Wentland  */
254562236bSHarry Wentland 
264562236bSHarry Wentland #include "dm_services.h"
2791db9311SSu Sung Chung 
284562236bSHarry Wentland #include "include/gpio_types.h"
294562236bSHarry Wentland #include "../hw_factory.h"
304562236bSHarry Wentland 
3191db9311SSu Sung Chung #include "../hw_gpio.h"
3291db9311SSu Sung Chung #include "../hw_ddc.h"
3391db9311SSu Sung Chung #include "../hw_hpd.h"
3491db9311SSu Sung Chung #include "../hw_generic.h"
3591db9311SSu Sung Chung 
364562236bSHarry Wentland #include "hw_factory_dce110.h"
374562236bSHarry Wentland 
384562236bSHarry Wentland #include "dce/dce_11_0_d.h"
394562236bSHarry Wentland #include "dce/dce_11_0_sh_mask.h"
404562236bSHarry Wentland 
414562236bSHarry Wentland /* set field name */
424562236bSHarry Wentland #define SF_HPD(reg_name, field_name, post_fix)\
434562236bSHarry Wentland 	.field_name = reg_name ## __ ## field_name ## post_fix
444562236bSHarry Wentland 
454562236bSHarry Wentland #define REG(reg_name)\
464562236bSHarry Wentland 		mm ## reg_name
474562236bSHarry Wentland 
484562236bSHarry Wentland #define REGI(reg_name, block, id)\
494562236bSHarry Wentland 	mm ## block ## id ## _ ## reg_name
504562236bSHarry Wentland 
514562236bSHarry Wentland #include "reg_helper.h"
524562236bSHarry Wentland #include "../hpd_regs.h"
534562236bSHarry Wentland 
544562236bSHarry Wentland #define hpd_regs(id) \
554562236bSHarry Wentland {\
564562236bSHarry Wentland 	HPD_REG_LIST(id)\
574562236bSHarry Wentland }
584562236bSHarry Wentland 
594562236bSHarry Wentland static const struct hpd_registers hpd_regs[] = {
604562236bSHarry Wentland 	hpd_regs(0),
614562236bSHarry Wentland 	hpd_regs(1),
624562236bSHarry Wentland 	hpd_regs(2),
634562236bSHarry Wentland 	hpd_regs(3),
644562236bSHarry Wentland 	hpd_regs(4),
654562236bSHarry Wentland 	hpd_regs(5)
664562236bSHarry Wentland };
674562236bSHarry Wentland 
684562236bSHarry Wentland static const struct hpd_sh_mask hpd_shift = {
694562236bSHarry Wentland 		HPD_MASK_SH_LIST(__SHIFT)
704562236bSHarry Wentland };
714562236bSHarry Wentland 
724562236bSHarry Wentland static const struct hpd_sh_mask hpd_mask = {
734562236bSHarry Wentland 		HPD_MASK_SH_LIST(_MASK)
744562236bSHarry Wentland };
754562236bSHarry Wentland 
764562236bSHarry Wentland #include "../ddc_regs.h"
774562236bSHarry Wentland 
784562236bSHarry Wentland  /* set field name */
794562236bSHarry Wentland #define SF_DDC(reg_name, field_name, post_fix)\
804562236bSHarry Wentland 	.field_name = reg_name ## __ ## field_name ## post_fix
814562236bSHarry Wentland 
824562236bSHarry Wentland static const struct ddc_registers ddc_data_regs[] = {
834562236bSHarry Wentland 	ddc_data_regs(1),
844562236bSHarry Wentland 	ddc_data_regs(2),
854562236bSHarry Wentland 	ddc_data_regs(3),
864562236bSHarry Wentland 	ddc_data_regs(4),
874562236bSHarry Wentland 	ddc_data_regs(5),
884562236bSHarry Wentland 	ddc_data_regs(6),
894562236bSHarry Wentland 	ddc_vga_data_regs,
904562236bSHarry Wentland 	ddc_i2c_data_regs
914562236bSHarry Wentland };
924562236bSHarry Wentland 
934562236bSHarry Wentland static const struct ddc_registers ddc_clk_regs[] = {
944562236bSHarry Wentland 	ddc_clk_regs(1),
954562236bSHarry Wentland 	ddc_clk_regs(2),
964562236bSHarry Wentland 	ddc_clk_regs(3),
974562236bSHarry Wentland 	ddc_clk_regs(4),
984562236bSHarry Wentland 	ddc_clk_regs(5),
994562236bSHarry Wentland 	ddc_clk_regs(6),
1004562236bSHarry Wentland 	ddc_vga_clk_regs,
1014562236bSHarry Wentland 	ddc_i2c_clk_regs
1024562236bSHarry Wentland };
1034562236bSHarry Wentland 
1044562236bSHarry Wentland static const struct ddc_sh_mask ddc_shift = {
1054562236bSHarry Wentland 		DDC_MASK_SH_LIST(__SHIFT)
1064562236bSHarry Wentland };
1074562236bSHarry Wentland 
1084562236bSHarry Wentland static const struct ddc_sh_mask ddc_mask = {
1094562236bSHarry Wentland 		DDC_MASK_SH_LIST(_MASK)
1104562236bSHarry Wentland };
1114562236bSHarry Wentland 
define_ddc_registers(struct hw_gpio_pin * pin,uint32_t en)1124562236bSHarry Wentland static void define_ddc_registers(
1134562236bSHarry Wentland 		struct hw_gpio_pin *pin,
1144562236bSHarry Wentland 		uint32_t en)
1154562236bSHarry Wentland {
1164562236bSHarry Wentland 	struct hw_ddc *ddc = HW_DDC_FROM_BASE(pin);
1174562236bSHarry Wentland 
1184562236bSHarry Wentland 	switch (pin->id) {
1194562236bSHarry Wentland 	case GPIO_ID_DDC_DATA:
1204562236bSHarry Wentland 		ddc->regs = &ddc_data_regs[en];
1214562236bSHarry Wentland 		ddc->base.regs = &ddc_data_regs[en].gpio;
1224562236bSHarry Wentland 		break;
1234562236bSHarry Wentland 	case GPIO_ID_DDC_CLOCK:
1244562236bSHarry Wentland 		ddc->regs = &ddc_clk_regs[en];
1254562236bSHarry Wentland 		ddc->base.regs = &ddc_clk_regs[en].gpio;
1264562236bSHarry Wentland 		break;
1274562236bSHarry Wentland 	default:
1284562236bSHarry Wentland 		ASSERT_CRITICAL(false);
1294562236bSHarry Wentland 		return;
1304562236bSHarry Wentland 	}
1314562236bSHarry Wentland 
1324562236bSHarry Wentland 	ddc->shifts = &ddc_shift;
1334562236bSHarry Wentland 	ddc->masks = &ddc_mask;
1344562236bSHarry Wentland 
1354562236bSHarry Wentland }
1364562236bSHarry Wentland 
define_hpd_registers(struct hw_gpio_pin * pin,uint32_t en)1374562236bSHarry Wentland static void define_hpd_registers(struct hw_gpio_pin *pin, uint32_t en)
1384562236bSHarry Wentland {
1394562236bSHarry Wentland 	struct hw_hpd *hpd = HW_HPD_FROM_BASE(pin);
1404562236bSHarry Wentland 
1414562236bSHarry Wentland 	hpd->regs = &hpd_regs[en];
1424562236bSHarry Wentland 	hpd->shifts = &hpd_shift;
1434562236bSHarry Wentland 	hpd->masks = &hpd_mask;
1444562236bSHarry Wentland 	hpd->base.regs = &hpd_regs[en].gpio;
1454562236bSHarry Wentland }
1464562236bSHarry Wentland 
1474562236bSHarry Wentland static const struct hw_factory_funcs funcs = {
14891db9311SSu Sung Chung 	.init_ddc_data = dal_hw_ddc_init,
14991db9311SSu Sung Chung 	.init_generic = NULL,
15091db9311SSu Sung Chung 	.init_hpd = dal_hw_hpd_init,
15191db9311SSu Sung Chung 	.get_ddc_pin = dal_hw_ddc_get_pin,
15291db9311SSu Sung Chung 	.get_hpd_pin = dal_hw_hpd_get_pin,
15391db9311SSu Sung Chung 	.get_generic_pin = NULL,
1544562236bSHarry Wentland 	.define_hpd_registers = define_hpd_registers,
1554562236bSHarry Wentland 	.define_ddc_registers = define_ddc_registers
1564562236bSHarry Wentland };
1574562236bSHarry Wentland 
1584562236bSHarry Wentland /*
1594562236bSHarry Wentland  * dal_hw_factory_dce110_init
1604562236bSHarry Wentland  *
1614562236bSHarry Wentland  * @brief
1624562236bSHarry Wentland  * Initialize HW factory function pointers and pin info
1634562236bSHarry Wentland  *
1644562236bSHarry Wentland  * @param
1654562236bSHarry Wentland  * struct hw_factory *factory - [out] struct of function pointers
1664562236bSHarry Wentland  */
dal_hw_factory_dce110_init(struct hw_factory * factory)1674562236bSHarry Wentland void dal_hw_factory_dce110_init(struct hw_factory *factory)
1684562236bSHarry Wentland {
1694562236bSHarry Wentland 	/*TODO check ASIC CAPs*/
1704562236bSHarry Wentland 	factory->number_of_pins[GPIO_ID_DDC_DATA] = 8;
1714562236bSHarry Wentland 	factory->number_of_pins[GPIO_ID_DDC_CLOCK] = 8;
1724562236bSHarry Wentland 	factory->number_of_pins[GPIO_ID_GENERIC] = 7;
1734562236bSHarry Wentland 	factory->number_of_pins[GPIO_ID_HPD] = 6;
1744562236bSHarry Wentland 	factory->number_of_pins[GPIO_ID_GPIO_PAD] = 31;
1754562236bSHarry Wentland 	factory->number_of_pins[GPIO_ID_VIP_PAD] = 0;
1764562236bSHarry Wentland 	factory->number_of_pins[GPIO_ID_SYNC] = 2;
1774562236bSHarry Wentland 	factory->number_of_pins[GPIO_ID_GSL] = 4;
1784562236bSHarry Wentland 
1794562236bSHarry Wentland 	factory->funcs = &funcs;
1804562236bSHarry Wentland }
181