xref: /rk3399_rockchip-uboot/drivers/phy/marvell/comphy.h (revision a284212963277114ad60e3442d74f095102a9de5)
13335786aSStefan Roese /*
23335786aSStefan Roese  * Copyright (C) 2015-2016 Marvell International Ltd.
33335786aSStefan Roese  *
43335786aSStefan Roese  * SPDX-License-Identifier:	GPL-2.0+
53335786aSStefan Roese  */
63335786aSStefan Roese 
73335786aSStefan Roese #ifndef _COMPHY_H_
83335786aSStefan Roese #define _COMPHY_H_
93335786aSStefan Roese 
103335786aSStefan Roese #include <dt-bindings/comphy/comphy_data.h>
113335786aSStefan Roese #include <fdtdec.h>
123335786aSStefan Roese 
133335786aSStefan Roese #if defined(DEBUG)
143335786aSStefan Roese #define debug_enter()	printf("----> Enter %s\n", __func__);
153335786aSStefan Roese #define debug_exit()	printf("<---- Exit  %s\n", __func__);
163335786aSStefan Roese #else
173335786aSStefan Roese #define debug_enter()
183335786aSStefan Roese #define debug_exit()
193335786aSStefan Roese #endif
203335786aSStefan Roese 
213335786aSStefan Roese /* COMPHY registers */
223335786aSStefan Roese #define COMMON_PHY_CFG1_REG			0x0
233335786aSStefan Roese #define COMMON_PHY_CFG1_PWR_UP_OFFSET		1
243335786aSStefan Roese #define COMMON_PHY_CFG1_PWR_UP_MASK		\
253335786aSStefan Roese 	(0x1 << COMMON_PHY_CFG1_PWR_UP_OFFSET)
263335786aSStefan Roese #define COMMON_PHY_CFG1_PIPE_SELECT_OFFSET	2
273335786aSStefan Roese #define COMMON_PHY_CFG1_PIPE_SELECT_MASK	\
283335786aSStefan Roese 	(0x1 << COMMON_PHY_CFG1_PIPE_SELECT_OFFSET)
293335786aSStefan Roese #define COMMON_PHY_CFG1_PWR_ON_RESET_OFFSET	13
303335786aSStefan Roese #define COMMON_PHY_CFG1_PWR_ON_RESET_MASK	\
313335786aSStefan Roese 	(0x1 << COMMON_PHY_CFG1_PWR_ON_RESET_OFFSET)
323335786aSStefan Roese #define COMMON_PHY_CFG1_CORE_RSTN_OFFSET	14
333335786aSStefan Roese #define COMMON_PHY_CFG1_CORE_RSTN_MASK		\
343335786aSStefan Roese 	(0x1 << COMMON_PHY_CFG1_CORE_RSTN_OFFSET)
353335786aSStefan Roese #define COMMON_PHY_PHY_MODE_OFFSET		15
363335786aSStefan Roese #define COMMON_PHY_PHY_MODE_MASK		\
373335786aSStefan Roese 	(0x1 << COMMON_PHY_PHY_MODE_OFFSET)
383335786aSStefan Roese 
393335786aSStefan Roese #define COMMON_PHY_CFG6_REG			0x14
403335786aSStefan Roese #define COMMON_PHY_CFG6_IF_40_SEL_OFFSET	18
413335786aSStefan Roese #define COMMON_PHY_CFG6_IF_40_SEL_MASK		\
423335786aSStefan Roese 	(0x1 << COMMON_PHY_CFG6_IF_40_SEL_OFFSET)
433335786aSStefan Roese 
443335786aSStefan Roese #define COMMON_SELECTOR_PHY_OFFSET		0x140
453335786aSStefan Roese #define COMMON_SELECTOR_PIPE_OFFSET		0x144
463335786aSStefan Roese 
473335786aSStefan Roese #define COMMON_PHY_SD_CTRL1			0x148
483335786aSStefan Roese #define COMMON_PHY_SD_CTRL1_COMPHY_0_4_PORT_OFFSET	0
493335786aSStefan Roese #define COMMON_PHY_SD_CTRL1_COMPHY_0_4_PORT_MASK	0xFFFF
503335786aSStefan Roese #define COMMON_PHY_SD_CTRL1_PCIE_X4_EN_OFFSET	24
513335786aSStefan Roese #define COMMON_PHY_SD_CTRL1_PCIE_X4_EN_MASK	\
523335786aSStefan Roese 	(0x1 << COMMON_PHY_SD_CTRL1_PCIE_X4_EN_OFFSET)
533335786aSStefan Roese #define COMMON_PHY_SD_CTRL1_PCIE_X2_EN_OFFSET	25
543335786aSStefan Roese #define COMMON_PHY_SD_CTRL1_PCIE_X2_EN_MASK	\
553335786aSStefan Roese 	(0x1 << COMMON_PHY_SD_CTRL1_PCIE_X2_EN_OFFSET)
563335786aSStefan Roese #define COMMON_PHY_SD_CTRL1_RXAUI1_OFFSET	26
573335786aSStefan Roese #define COMMON_PHY_SD_CTRL1_RXAUI1_MASK		\
583335786aSStefan Roese 	(0x1 << COMMON_PHY_SD_CTRL1_RXAUI1_OFFSET)
593335786aSStefan Roese #define COMMON_PHY_SD_CTRL1_RXAUI0_OFFSET	27
603335786aSStefan Roese #define COMMON_PHY_SD_CTRL1_RXAUI0_MASK		\
613335786aSStefan Roese 	(0x1 << COMMON_PHY_SD_CTRL1_RXAUI0_OFFSET)
623335786aSStefan Roese 
63c0132f60SStefan Roese /* ToDo: Get this address via DT */
64c0132f60SStefan Roese #define MVEBU_CP0_REGS_BASE			0xF2000000UL
65c0132f60SStefan Roese 
663335786aSStefan Roese #define DFX_DEV_GEN_CTRL12			(MVEBU_CP0_REGS_BASE + 0x400280)
673335786aSStefan Roese #define DFX_DEV_GEN_PCIE_CLK_SRC_OFFSET		7
683335786aSStefan Roese #define DFX_DEV_GEN_PCIE_CLK_SRC_MASK		\
693335786aSStefan Roese 	(0x3 << DFX_DEV_GEN_PCIE_CLK_SRC_OFFSET)
703335786aSStefan Roese 
713335786aSStefan Roese #define MAX_LANE_OPTIONS			10
72e8c3156eSStefan Roese #define MAX_UTMI_PHY_COUNT			3
733335786aSStefan Roese 
743335786aSStefan Roese struct comphy_mux_options {
753335786aSStefan Roese 	u32 type;
763335786aSStefan Roese 	u32 mux_value;
773335786aSStefan Roese };
783335786aSStefan Roese 
793335786aSStefan Roese struct comphy_mux_data {
803335786aSStefan Roese 	u32 max_lane_values;
813335786aSStefan Roese 	struct comphy_mux_options mux_values[MAX_LANE_OPTIONS];
823335786aSStefan Roese };
833335786aSStefan Roese 
843335786aSStefan Roese struct comphy_map {
853335786aSStefan Roese 	u32 type;
863335786aSStefan Roese 	u32 speed;
873335786aSStefan Roese 	u32 invert;
883335786aSStefan Roese 	bool clk_src;
897dda98e0SStefan Roese 	bool end_point;
903335786aSStefan Roese };
913335786aSStefan Roese 
923335786aSStefan Roese struct chip_serdes_phy_config {
933335786aSStefan Roese 	struct comphy_mux_data *mux_data;
943335786aSStefan Roese 	int (*ptr_comphy_chip_init)(struct chip_serdes_phy_config *,
953335786aSStefan Roese 				    struct comphy_map *);
963335786aSStefan Roese 	void __iomem *comphy_base_addr;
973335786aSStefan Roese 	void __iomem *hpipe3_base_addr;
983335786aSStefan Roese 	u32 comphy_lanes_count;
993335786aSStefan Roese 	u32 comphy_mux_bitcount;
100*528213d3SIgal Liberman 	u32 cp_index;
1013335786aSStefan Roese };
1023335786aSStefan Roese 
1033335786aSStefan Roese /* Register helper functions */
1043335786aSStefan Roese void reg_set(void __iomem *addr, u32 data, u32 mask);
1053335786aSStefan Roese void reg_set_silent(void __iomem *addr, u32 data, u32 mask);
1063335786aSStefan Roese void reg_set16(void __iomem *addr, u16 data, u16 mask);
1073335786aSStefan Roese void reg_set_silent16(void __iomem *addr, u16 data, u16 mask);
1083335786aSStefan Roese 
1093335786aSStefan Roese /* SoC specific init functions */
1103335786aSStefan Roese #ifdef CONFIG_ARMADA_3700
1113335786aSStefan Roese int comphy_a3700_init(struct chip_serdes_phy_config *ptr_chip_cfg,
1123335786aSStefan Roese 		      struct comphy_map *serdes_map);
1133335786aSStefan Roese #else
comphy_a3700_init(struct chip_serdes_phy_config * ptr_chip_cfg,struct comphy_map * serdes_map)1143335786aSStefan Roese static inline int comphy_a3700_init(struct chip_serdes_phy_config *ptr_chip_cfg,
1153335786aSStefan Roese 				    struct comphy_map *serdes_map)
1163335786aSStefan Roese {
1173335786aSStefan Roese 	/*
1183335786aSStefan Roese 	 * This function should never be called in this configuration, so
1193335786aSStefan Roese 	 * lets return an error here.
1203335786aSStefan Roese 	 */
1213335786aSStefan Roese 	return -1;
1223335786aSStefan Roese }
1233335786aSStefan Roese #endif
124c0132f60SStefan Roese 
125c0132f60SStefan Roese #ifdef CONFIG_ARMADA_8K
1263335786aSStefan Roese int comphy_cp110_init(struct chip_serdes_phy_config *ptr_chip_cfg,
1273335786aSStefan Roese 		      struct comphy_map *serdes_map);
128c0132f60SStefan Roese #else
comphy_cp110_init(struct chip_serdes_phy_config * ptr_chip_cfg,struct comphy_map * serdes_map)129c0132f60SStefan Roese static inline int comphy_cp110_init(struct chip_serdes_phy_config *ptr_chip_cfg,
130c0132f60SStefan Roese 		      struct comphy_map *serdes_map)
131c0132f60SStefan Roese {
132c0132f60SStefan Roese 	/*
133c0132f60SStefan Roese 	 * This function should never be called in this configuration, so
134c0132f60SStefan Roese 	 * lets return an error here.
135c0132f60SStefan Roese 	 */
136c0132f60SStefan Roese 	return -1;
137c0132f60SStefan Roese }
138c0132f60SStefan Roese #endif
1393335786aSStefan Roese 
1403335786aSStefan Roese void comphy_dedicated_phys_init(void);
1413335786aSStefan Roese 
1423335786aSStefan Roese /* MUX function */
1433335786aSStefan Roese void comphy_mux_init(struct chip_serdes_phy_config *ptr_chip_cfg,
1443335786aSStefan Roese 		     struct comphy_map *comphy_map_data,
1453335786aSStefan Roese 		     void __iomem *selector_base);
1463335786aSStefan Roese 
1473335786aSStefan Roese void comphy_pcie_config_set(u32 comphy_max_count,
1483335786aSStefan Roese 			    struct comphy_map *serdes_map);
1493335786aSStefan Roese void comphy_pcie_config_detect(u32 comphy_max_count,
1503335786aSStefan Roese 			       struct comphy_map *serdes_map);
1513335786aSStefan Roese void comphy_pcie_unit_general_config(u32 pex_index);
1523335786aSStefan Roese 
1533335786aSStefan Roese #endif /* _COMPHY_H_ */
1543335786aSStefan Roese 
155