blob: b588ae41f00391ea6ccfaa80ee6cf32cdacc798d [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Stefan Roese33357862016-05-23 11:12:05 +02002/*
3 * Copyright (C) 2015-2016 Marvell International Ltd.
Stefan Roese33357862016-05-23 11:12:05 +02004 */
5
6#ifndef _COMPHY_H_
7#define _COMPHY_H_
8
9#include <dt-bindings/comphy/comphy_data.h>
10#include <fdtdec.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/* COMPHY registers */
21#define COMMON_PHY_CFG1_REG 0x0
22#define COMMON_PHY_CFG1_PWR_UP_OFFSET 1
23#define COMMON_PHY_CFG1_PWR_UP_MASK \
24 (0x1 << COMMON_PHY_CFG1_PWR_UP_OFFSET)
25#define COMMON_PHY_CFG1_PIPE_SELECT_OFFSET 2
26#define COMMON_PHY_CFG1_PIPE_SELECT_MASK \
27 (0x1 << COMMON_PHY_CFG1_PIPE_SELECT_OFFSET)
28#define COMMON_PHY_CFG1_PWR_ON_RESET_OFFSET 13
29#define COMMON_PHY_CFG1_PWR_ON_RESET_MASK \
30 (0x1 << COMMON_PHY_CFG1_PWR_ON_RESET_OFFSET)
31#define COMMON_PHY_CFG1_CORE_RSTN_OFFSET 14
32#define COMMON_PHY_CFG1_CORE_RSTN_MASK \
33 (0x1 << COMMON_PHY_CFG1_CORE_RSTN_OFFSET)
34#define COMMON_PHY_PHY_MODE_OFFSET 15
35#define COMMON_PHY_PHY_MODE_MASK \
36 (0x1 << COMMON_PHY_PHY_MODE_OFFSET)
37
38#define COMMON_PHY_CFG6_REG 0x14
39#define COMMON_PHY_CFG6_IF_40_SEL_OFFSET 18
40#define COMMON_PHY_CFG6_IF_40_SEL_MASK \
41 (0x1 << COMMON_PHY_CFG6_IF_40_SEL_OFFSET)
42
43#define COMMON_SELECTOR_PHY_OFFSET 0x140
44#define COMMON_SELECTOR_PIPE_OFFSET 0x144
45
46#define COMMON_PHY_SD_CTRL1 0x148
47#define COMMON_PHY_SD_CTRL1_COMPHY_0_4_PORT_OFFSET 0
48#define COMMON_PHY_SD_CTRL1_COMPHY_0_4_PORT_MASK 0xFFFF
49#define COMMON_PHY_SD_CTRL1_PCIE_X4_EN_OFFSET 24
50#define COMMON_PHY_SD_CTRL1_PCIE_X4_EN_MASK \
51 (0x1 << COMMON_PHY_SD_CTRL1_PCIE_X4_EN_OFFSET)
52#define COMMON_PHY_SD_CTRL1_PCIE_X2_EN_OFFSET 25
53#define COMMON_PHY_SD_CTRL1_PCIE_X2_EN_MASK \
54 (0x1 << COMMON_PHY_SD_CTRL1_PCIE_X2_EN_OFFSET)
55#define COMMON_PHY_SD_CTRL1_RXAUI1_OFFSET 26
56#define COMMON_PHY_SD_CTRL1_RXAUI1_MASK \
57 (0x1 << COMMON_PHY_SD_CTRL1_RXAUI1_OFFSET)
58#define COMMON_PHY_SD_CTRL1_RXAUI0_OFFSET 27
59#define COMMON_PHY_SD_CTRL1_RXAUI0_MASK \
60 (0x1 << COMMON_PHY_SD_CTRL1_RXAUI0_OFFSET)
61
Stefan Roesec0132f62016-08-30 16:48:20 +020062/* ToDo: Get this address via DT */
63#define MVEBU_CP0_REGS_BASE 0xF2000000UL
64
Stefan Roese33357862016-05-23 11:12:05 +020065#define DFX_DEV_GEN_CTRL12 (MVEBU_CP0_REGS_BASE + 0x400280)
66#define DFX_DEV_GEN_PCIE_CLK_SRC_OFFSET 7
67#define DFX_DEV_GEN_PCIE_CLK_SRC_MASK \
68 (0x3 << DFX_DEV_GEN_PCIE_CLK_SRC_OFFSET)
69
70#define MAX_LANE_OPTIONS 10
Stefan Roesee8c31562016-10-25 18:16:25 +020071#define MAX_UTMI_PHY_COUNT 3
Stefan Roese33357862016-05-23 11:12:05 +020072
73struct comphy_mux_options {
74 u32 type;
75 u32 mux_value;
76};
77
78struct comphy_mux_data {
79 u32 max_lane_values;
80 struct comphy_mux_options mux_values[MAX_LANE_OPTIONS];
81};
82
83struct comphy_map {
84 u32 type;
85 u32 speed;
86 u32 invert;
87 bool clk_src;
Stefan Roese7dda98e2017-04-24 18:45:22 +030088 bool end_point;
Stefan Roese33357862016-05-23 11:12:05 +020089};
90
91struct chip_serdes_phy_config {
92 struct comphy_mux_data *mux_data;
93 int (*ptr_comphy_chip_init)(struct chip_serdes_phy_config *,
94 struct comphy_map *);
95 void __iomem *comphy_base_addr;
96 void __iomem *hpipe3_base_addr;
97 u32 comphy_lanes_count;
98 u32 comphy_mux_bitcount;
Marek BehĂșn7586ac22018-04-24 17:21:21 +020099 const fdt32_t *comphy_mux_lane_order;
Igal Liberman528213d2017-04-24 18:45:32 +0300100 u32 cp_index;
Stefan Roese33357862016-05-23 11:12:05 +0200101};
102
103/* Register helper functions */
Marek BehĂșn2d7a0f42018-04-24 17:21:28 +0200104static inline void reg_set_silent(void __iomem *addr, u32 data, u32 mask)
105{
106 u32 reg_data;
107
108 reg_data = readl(addr);
109 reg_data &= ~mask;
110 reg_data |= data;
111 writel(reg_data, addr);
112}
113
114static inline void reg_set(void __iomem *addr, u32 data, u32 mask)
115{
116 debug("Write to address = %#010lx, data = %#010x (mask = %#010x) - ",
117 (unsigned long)addr, data, mask);
118 debug("old value = %#010x ==> ", readl(addr));
119 reg_set_silent(addr, data, mask);
120 debug("new value %#010x\n", readl(addr));
121}
122
123static inline void reg_set_silent16(void __iomem *addr, u16 data, u16 mask)
124{
125 u16 reg_data;
126
127 reg_data = readw(addr);
128 reg_data &= ~mask;
129 reg_data |= data;
130 writew(reg_data, addr);
131}
132
133static inline void reg_set16(void __iomem *addr, u16 data, u16 mask)
134{
135 debug("Write to address = %#010lx, data = %#06x (mask = %#06x) - ",
136 (unsigned long)addr, data, mask);
137 debug("old value = %#06x ==> ", readw(addr));
138 reg_set_silent16(addr, data, mask);
139 debug("new value %#06x\n", readw(addr));
140}
Stefan Roese33357862016-05-23 11:12:05 +0200141
142/* SoC specific init functions */
143#ifdef CONFIG_ARMADA_3700
144int comphy_a3700_init(struct chip_serdes_phy_config *ptr_chip_cfg,
145 struct comphy_map *serdes_map);
146#else
147static inline int comphy_a3700_init(struct chip_serdes_phy_config *ptr_chip_cfg,
148 struct comphy_map *serdes_map)
149{
150 /*
151 * This function should never be called in this configuration, so
152 * lets return an error here.
153 */
154 return -1;
155}
156#endif
Stefan Roesec0132f62016-08-30 16:48:20 +0200157
158#ifdef CONFIG_ARMADA_8K
Stefan Roese33357862016-05-23 11:12:05 +0200159int comphy_cp110_init(struct chip_serdes_phy_config *ptr_chip_cfg,
160 struct comphy_map *serdes_map);
Stefan Roesec0132f62016-08-30 16:48:20 +0200161#else
162static inline int comphy_cp110_init(struct chip_serdes_phy_config *ptr_chip_cfg,
163 struct comphy_map *serdes_map)
164{
165 /*
166 * This function should never be called in this configuration, so
167 * lets return an error here.
168 */
169 return -1;
170}
171#endif
Stefan Roese33357862016-05-23 11:12:05 +0200172
173void comphy_dedicated_phys_init(void);
174
175/* MUX function */
176void comphy_mux_init(struct chip_serdes_phy_config *ptr_chip_cfg,
177 struct comphy_map *comphy_map_data,
178 void __iomem *selector_base);
179
180void comphy_pcie_config_set(u32 comphy_max_count,
181 struct comphy_map *serdes_map);
182void comphy_pcie_config_detect(u32 comphy_max_count,
183 struct comphy_map *serdes_map);
184void comphy_pcie_unit_general_config(u32 pex_index);
185
186#endif /* _COMPHY_H_ */
187