1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3 * Copyright (C) 2015-2016 Marvell International Ltd.
4 */
5
6 #ifndef _COMPHY_CORE_H_
7 #define _COMPHY_CORE_H_
8
9 #include <fdtdec.h>
10 #include <mvebu/comphy.h>
11
12 #if defined(DEBUG)
13 #define debug_enter() printf("----> Enter %s\n", __func__);
14 #define debug_exit() printf("<---- Exit %s\n", __func__);
15 #else
16 #define debug_enter()
17 #define debug_exit()
18 #endif
19
20 #define MAX_LANE_OPTIONS 10
21 #define MAX_UTMI_PHY_COUNT 6
22
23 struct comphy_mux_options {
24 u32 type;
25 u32 mux_value;
26 };
27
28 struct comphy_mux_data {
29 u32 max_lane_values;
30 struct comphy_mux_options mux_values[MAX_LANE_OPTIONS];
31 };
32
33 struct chip_serdes_phy_config {
34 struct comphy_mux_data *mux_data;
35 int (*ptr_comphy_chip_init)(struct chip_serdes_phy_config *,
36 struct comphy_map *);
37 int (*rx_training)(struct chip_serdes_phy_config *, u32);
38 void __iomem *comphy_base_addr;
39 void __iomem *hpipe3_base_addr;
40 u32 comphy_lanes_count;
41 u32 comphy_mux_bitcount;
42 const fdt32_t *comphy_mux_lane_order;
43 u32 cp_index;
44 struct comphy_map comphy_map_data[MAX_LANE_OPTIONS];
45 };
46
47 /* Register helper functions */
reg_set_silent(void __iomem * addr,u32 data,u32 mask)48 static inline void reg_set_silent(void __iomem *addr, u32 data, u32 mask)
49 {
50 u32 reg_data;
51
52 reg_data = readl(addr);
53 reg_data &= ~mask;
54 reg_data |= data;
55 writel(reg_data, addr);
56 }
57
reg_set(void __iomem * addr,u32 data,u32 mask)58 static inline void reg_set(void __iomem *addr, u32 data, u32 mask)
59 {
60 debug("Write to address = %#010lx, data = %#010x (mask = %#010x) - ",
61 (unsigned long)addr, data, mask);
62 debug("old value = %#010x ==> ", readl(addr));
63 reg_set_silent(addr, data, mask);
64 debug("new value %#010x\n", readl(addr));
65 }
66
reg_set_silent16(void __iomem * addr,u16 data,u16 mask)67 static inline void reg_set_silent16(void __iomem *addr, u16 data, u16 mask)
68 {
69 u16 reg_data;
70
71 reg_data = readw(addr);
72 reg_data &= ~mask;
73 reg_data |= data;
74 writew(reg_data, addr);
75 }
76
reg_set16(void __iomem * addr,u16 data,u16 mask)77 static inline void reg_set16(void __iomem *addr, u16 data, u16 mask)
78 {
79 debug("Write to address = %#010lx, data = %#06x (mask = %#06x) - ",
80 (unsigned long)addr, data, mask);
81 debug("old value = %#06x ==> ", readw(addr));
82 reg_set_silent16(addr, data, mask);
83 debug("new value %#06x\n", readw(addr));
84 }
85
86 /* SoC specific init functions */
87 #ifdef CONFIG_ARMADA_3700
88 int comphy_a3700_init(struct chip_serdes_phy_config *ptr_chip_cfg,
89 struct comphy_map *serdes_map);
90 #else
comphy_a3700_init(struct chip_serdes_phy_config * ptr_chip_cfg,struct comphy_map * serdes_map)91 static inline int comphy_a3700_init(struct chip_serdes_phy_config *ptr_chip_cfg,
92 struct comphy_map *serdes_map)
93 {
94 /*
95 * This function should never be called in this configuration, so
96 * lets return an error here.
97 */
98 return -1;
99 }
100 #endif
101
102 #ifdef CONFIG_ARMADA_8K
103 int comphy_cp110_init(struct chip_serdes_phy_config *ptr_chip_cfg,
104 struct comphy_map *serdes_map);
105 int comphy_cp110_sfi_rx_training(struct chip_serdes_phy_config *ptr_chip_cfg,
106 u32 lane);
107 #else
comphy_cp110_init(struct chip_serdes_phy_config * ptr_chip_cfg,struct comphy_map * serdes_map)108 static inline int comphy_cp110_init(struct chip_serdes_phy_config *ptr_chip_cfg,
109 struct comphy_map *serdes_map)
110 {
111 /*
112 * This function should never be called in this configuration, so
113 * lets return an error here.
114 */
115 return -1;
116 }
117
comphy_cp110_sfi_rx_training(struct chip_serdes_phy_config * ptr_chip_cfg,u32 lane)118 static inline int comphy_cp110_sfi_rx_training(
119 struct chip_serdes_phy_config *ptr_chip_cfg,
120 u32 lane)
121 {
122 /*
123 * This function should never be called in this configuration, so
124 * lets return an error here.
125 */
126 return -1;
127 }
128 #endif
129
130 void comphy_dedicated_phys_init(void);
131
132 /* MUX function */
133 void comphy_mux_init(struct chip_serdes_phy_config *ptr_chip_cfg,
134 struct comphy_map *comphy_map_data,
135 void __iomem *selector_base);
136
137 void comphy_pcie_config_set(u32 comphy_max_count,
138 struct comphy_map *serdes_map);
139 void comphy_pcie_config_detect(u32 comphy_max_count,
140 struct comphy_map *serdes_map);
141 void comphy_pcie_unit_general_config(u32 pex_index);
142
143 #endif /* _COMPHY_CORE_H_ */
144