1 // SPDX-License-Identifier: GPL-2.0
3 * Wrapper driver for SERDES used in J721E
5 * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com/
6 * Author: Kishon Vijay Abraham I <kishon@ti.com>
9 #include <dt-bindings/phy/phy.h>
10 #include <dt-bindings/phy/phy-ti.h>
11 #include <linux/slab.h>
12 #include <linux/clk.h>
13 #include <linux/clk-provider.h>
14 #include <linux/gpio.h>
15 #include <linux/gpio/consumer.h>
17 #include <linux/module.h>
18 #include <linux/mfd/syscon.h>
19 #include <linux/mux/consumer.h>
20 #include <linux/of_address.h>
21 #include <linux/of_platform.h>
22 #include <linux/platform_device.h>
23 #include <linux/pm_runtime.h>
24 #include <linux/regmap.h>
25 #include <linux/reset-controller.h>
27 #define REF_CLK_19_2MHZ 19200000
28 #define REF_CLK_25MHZ 25000000
29 #define REF_CLK_100MHZ 100000000
30 #define REF_CLK_156_25MHZ 156250000
33 #define SERDES_SUP_CTRL 0x4400
36 #define WIZ_SERDES_CTRL 0x404
37 #define WIZ_SERDES_TOP_CTRL 0x408
38 #define WIZ_SERDES_RST 0x40c
39 #define WIZ_SERDES_TYPEC 0x410
40 #define WIZ_LANECTL(n) (0x480 + (0x40 * (n)))
41 #define WIZ_LANEDIV(n) (0x484 + (0x40 * (n)))
43 #define WIZ_MAX_INPUT_CLOCKS 4
44 /* To include mux clocks, divider clocks and gate clocks */
45 #define WIZ_MAX_OUTPUT_CLOCKS 32
47 #define WIZ_MAX_LANES 4
48 #define WIZ_MUX_NUM_CLOCKS 3
49 #define WIZ_DIV_NUM_CLOCKS_16G 2
50 #define WIZ_DIV_NUM_CLOCKS_10G 1
52 #define WIZ_SERDES_TYPEC_LN10_SWAP BIT(30)
54 enum wiz_lane_standard_mode
{
62 * List of master lanes used for lane swapping
64 enum wiz_typec_master_lane
{
69 enum wiz_refclk_mux_sel
{
75 enum wiz_refclk_div_sel
{
80 enum wiz_clock_input
{
87 static const struct reg_field por_en
= REG_FIELD(WIZ_SERDES_CTRL
, 31, 31);
88 static const struct reg_field phy_reset_n
= REG_FIELD(WIZ_SERDES_RST
, 31, 31);
89 static const struct reg_field phy_en_refclk
= REG_FIELD(WIZ_SERDES_RST
, 30, 30);
90 static const struct reg_field pll1_refclk_mux_sel
=
91 REG_FIELD(WIZ_SERDES_RST
, 29, 29);
92 static const struct reg_field pll1_refclk_mux_sel_2
=
93 REG_FIELD(WIZ_SERDES_RST
, 22, 23);
94 static const struct reg_field pll0_refclk_mux_sel
=
95 REG_FIELD(WIZ_SERDES_RST
, 28, 28);
96 static const struct reg_field pll0_refclk_mux_sel_2
=
97 REG_FIELD(WIZ_SERDES_RST
, 28, 29);
98 static const struct reg_field refclk_dig_sel_16g
=
99 REG_FIELD(WIZ_SERDES_RST
, 24, 25);
100 static const struct reg_field refclk_dig_sel_10g
=
101 REG_FIELD(WIZ_SERDES_RST
, 24, 24);
102 static const struct reg_field pma_cmn_refclk_int_mode
=
103 REG_FIELD(WIZ_SERDES_TOP_CTRL
, 28, 29);
104 static const struct reg_field pma_cmn_refclk1_int_mode
=
105 REG_FIELD(WIZ_SERDES_TOP_CTRL
, 20, 21);
106 static const struct reg_field pma_cmn_refclk_mode
=
107 REG_FIELD(WIZ_SERDES_TOP_CTRL
, 30, 31);
108 static const struct reg_field pma_cmn_refclk_dig_div
=
109 REG_FIELD(WIZ_SERDES_TOP_CTRL
, 26, 27);
110 static const struct reg_field pma_cmn_refclk1_dig_div
=
111 REG_FIELD(WIZ_SERDES_TOP_CTRL
, 24, 25);
113 static const struct reg_field sup_pll0_refclk_mux_sel
=
114 REG_FIELD(SERDES_SUP_CTRL
, 0, 1);
115 static const struct reg_field sup_pll1_refclk_mux_sel
=
116 REG_FIELD(SERDES_SUP_CTRL
, 2, 3);
117 static const struct reg_field sup_pma_cmn_refclk1_int_mode
=
118 REG_FIELD(SERDES_SUP_CTRL
, 4, 5);
119 static const struct reg_field sup_refclk_dig_sel_10g
=
120 REG_FIELD(SERDES_SUP_CTRL
, 6, 7);
121 static const struct reg_field sup_legacy_clk_override
=
122 REG_FIELD(SERDES_SUP_CTRL
, 8, 8);
124 static const char * const output_clk_names
[] = {
125 [TI_WIZ_PLL0_REFCLK
] = "pll0-refclk",
126 [TI_WIZ_PLL1_REFCLK
] = "pll1-refclk",
127 [TI_WIZ_REFCLK_DIG
] = "refclk-dig",
128 [TI_WIZ_PHY_EN_REFCLK
] = "phy-en-refclk",
131 static const struct reg_field p_enable
[WIZ_MAX_LANES
] = {
132 REG_FIELD(WIZ_LANECTL(0), 30, 31),
133 REG_FIELD(WIZ_LANECTL(1), 30, 31),
134 REG_FIELD(WIZ_LANECTL(2), 30, 31),
135 REG_FIELD(WIZ_LANECTL(3), 30, 31),
138 enum p_enable
{ P_ENABLE
= 2, P_ENABLE_FORCE
= 1, P_ENABLE_DISABLE
= 0 };
140 static const struct reg_field p_align
[WIZ_MAX_LANES
] = {
141 REG_FIELD(WIZ_LANECTL(0), 29, 29),
142 REG_FIELD(WIZ_LANECTL(1), 29, 29),
143 REG_FIELD(WIZ_LANECTL(2), 29, 29),
144 REG_FIELD(WIZ_LANECTL(3), 29, 29),
147 static const struct reg_field p_raw_auto_start
[WIZ_MAX_LANES
] = {
148 REG_FIELD(WIZ_LANECTL(0), 28, 28),
149 REG_FIELD(WIZ_LANECTL(1), 28, 28),
150 REG_FIELD(WIZ_LANECTL(2), 28, 28),
151 REG_FIELD(WIZ_LANECTL(3), 28, 28),
154 static const struct reg_field p_standard_mode
[WIZ_MAX_LANES
] = {
155 REG_FIELD(WIZ_LANECTL(0), 24, 25),
156 REG_FIELD(WIZ_LANECTL(1), 24, 25),
157 REG_FIELD(WIZ_LANECTL(2), 24, 25),
158 REG_FIELD(WIZ_LANECTL(3), 24, 25),
161 static const struct reg_field p0_fullrt_div
[WIZ_MAX_LANES
] = {
162 REG_FIELD(WIZ_LANECTL(0), 22, 23),
163 REG_FIELD(WIZ_LANECTL(1), 22, 23),
164 REG_FIELD(WIZ_LANECTL(2), 22, 23),
165 REG_FIELD(WIZ_LANECTL(3), 22, 23),
168 static const struct reg_field p0_mac_src_sel
[WIZ_MAX_LANES
] = {
169 REG_FIELD(WIZ_LANECTL(0), 20, 21),
170 REG_FIELD(WIZ_LANECTL(1), 20, 21),
171 REG_FIELD(WIZ_LANECTL(2), 20, 21),
172 REG_FIELD(WIZ_LANECTL(3), 20, 21),
175 static const struct reg_field p0_rxfclk_sel
[WIZ_MAX_LANES
] = {
176 REG_FIELD(WIZ_LANECTL(0), 6, 7),
177 REG_FIELD(WIZ_LANECTL(1), 6, 7),
178 REG_FIELD(WIZ_LANECTL(2), 6, 7),
179 REG_FIELD(WIZ_LANECTL(3), 6, 7),
182 static const struct reg_field p0_refclk_sel
[WIZ_MAX_LANES
] = {
183 REG_FIELD(WIZ_LANECTL(0), 18, 19),
184 REG_FIELD(WIZ_LANECTL(1), 18, 19),
185 REG_FIELD(WIZ_LANECTL(2), 18, 19),
186 REG_FIELD(WIZ_LANECTL(3), 18, 19),
188 static const struct reg_field p_mac_div_sel0
[WIZ_MAX_LANES
] = {
189 REG_FIELD(WIZ_LANEDIV(0), 16, 22),
190 REG_FIELD(WIZ_LANEDIV(1), 16, 22),
191 REG_FIELD(WIZ_LANEDIV(2), 16, 22),
192 REG_FIELD(WIZ_LANEDIV(3), 16, 22),
195 static const struct reg_field p_mac_div_sel1
[WIZ_MAX_LANES
] = {
196 REG_FIELD(WIZ_LANEDIV(0), 0, 8),
197 REG_FIELD(WIZ_LANEDIV(1), 0, 8),
198 REG_FIELD(WIZ_LANEDIV(2), 0, 8),
199 REG_FIELD(WIZ_LANEDIV(3), 0, 8),
202 static const struct reg_field typec_ln10_swap
=
203 REG_FIELD(WIZ_SERDES_TYPEC
, 30, 30);
205 static const struct reg_field typec_ln23_swap
=
206 REG_FIELD(WIZ_SERDES_TYPEC
, 31, 31);
210 struct regmap_field
*field
;
212 struct clk_init_data clk_data
;
215 #define to_wiz_clk_mux(_hw) container_of(_hw, struct wiz_clk_mux, hw)
217 struct wiz_clk_divider
{
219 struct regmap_field
*field
;
220 const struct clk_div_table
*table
;
221 struct clk_init_data clk_data
;
224 #define to_wiz_clk_div(_hw) container_of(_hw, struct wiz_clk_divider, hw)
226 struct wiz_clk_mux_sel
{
227 u32 table
[WIZ_MAX_INPUT_CLOCKS
];
228 const char *node_name
;
230 u32 parents
[WIZ_MAX_INPUT_CLOCKS
];
233 struct wiz_clk_div_sel
{
234 const struct clk_div_table
*table
;
235 const char *node_name
;
238 struct wiz_phy_en_refclk
{
240 struct regmap_field
*phy_en_refclk
;
241 struct clk_init_data clk_data
;
244 #define to_wiz_phy_en_refclk(_hw) container_of(_hw, struct wiz_phy_en_refclk, hw)
246 static const struct wiz_clk_mux_sel clk_mux_sel_16g
[] = {
249 * Mux value to be configured for each of the input clocks
250 * in the order populated in device tree
253 .node_name
= "pll0-refclk",
257 .node_name
= "pll1-refclk",
260 .table
= { 1, 3, 0, 2 },
261 .node_name
= "refclk-dig",
265 static const struct wiz_clk_mux_sel clk_mux_sel_10g
[] = {
268 * Mux value to be configured for each of the input clocks
269 * in the order populated in device tree
272 .parents
= { WIZ_CORE_REFCLK
, WIZ_EXT_REFCLK
},
274 .node_name
= "pll0-refclk",
278 .parents
= { WIZ_CORE_REFCLK
, WIZ_EXT_REFCLK
},
280 .node_name
= "pll1-refclk",
284 .parents
= { WIZ_CORE_REFCLK
, WIZ_EXT_REFCLK
},
286 .node_name
= "refclk-dig",
290 static const struct wiz_clk_mux_sel clk_mux_sel_10g_2_refclk
[] = {
293 .parents
= { WIZ_CORE_REFCLK
, WIZ_CORE_REFCLK1
, WIZ_EXT_REFCLK
},
294 .table
= { 2, 3, 0 },
295 .node_name
= "pll0-refclk",
299 .parents
= { WIZ_CORE_REFCLK
, WIZ_CORE_REFCLK1
, WIZ_EXT_REFCLK
},
300 .table
= { 2, 3, 0 },
301 .node_name
= "pll1-refclk",
305 .parents
= { WIZ_CORE_REFCLK
, WIZ_CORE_REFCLK1
, WIZ_EXT_REFCLK
},
306 .table
= { 2, 3, 0 },
307 .node_name
= "refclk-dig",
311 static const struct clk_div_table clk_div_table
[] = {
312 { .val
= 0, .div
= 1, },
313 { .val
= 1, .div
= 2, },
314 { .val
= 2, .div
= 4, },
315 { .val
= 3, .div
= 8, },
319 static const struct wiz_clk_div_sel clk_div_sel
[] = {
321 .table
= clk_div_table
,
322 .node_name
= "cmn-refclk-dig-div",
325 .table
= clk_div_table
,
326 .node_name
= "cmn-refclk1-dig-div",
332 J721E_WIZ_10G
, /* Also for J7200 SR1.0 */
334 J7200_WIZ_10G
, /* J7200 SR2.0 */
341 const struct reg_field
*pll0_refclk_mux_sel
;
342 const struct reg_field
*pll1_refclk_mux_sel
;
343 const struct reg_field
*refclk_dig_sel
;
344 const struct reg_field
*pma_cmn_refclk1_dig_div
;
345 const struct reg_field
*pma_cmn_refclk1_int_mode
;
346 const struct wiz_clk_mux_sel
*clk_mux_sel
;
347 unsigned int clk_div_sel_num
;
350 #define WIZ_TYPEC_DIR_DEBOUNCE_MIN 100 /* ms */
351 #define WIZ_TYPEC_DIR_DEBOUNCE_MAX 1000
354 struct regmap
*regmap
;
355 struct regmap
*scm_regmap
;
357 const struct wiz_clk_mux_sel
*clk_mux_sel
;
358 const struct wiz_clk_div_sel
*clk_div_sel
;
359 unsigned int clk_div_sel_num
;
360 struct regmap_field
*por_en
;
361 struct regmap_field
*phy_reset_n
;
362 struct regmap_field
*phy_en_refclk
;
363 struct regmap_field
*p_enable
[WIZ_MAX_LANES
];
364 struct regmap_field
*p_align
[WIZ_MAX_LANES
];
365 struct regmap_field
*p_raw_auto_start
[WIZ_MAX_LANES
];
366 struct regmap_field
*p_standard_mode
[WIZ_MAX_LANES
];
367 struct regmap_field
*p_mac_div_sel0
[WIZ_MAX_LANES
];
368 struct regmap_field
*p_mac_div_sel1
[WIZ_MAX_LANES
];
369 struct regmap_field
*p0_fullrt_div
[WIZ_MAX_LANES
];
370 struct regmap_field
*p0_mac_src_sel
[WIZ_MAX_LANES
];
371 struct regmap_field
*p0_rxfclk_sel
[WIZ_MAX_LANES
];
372 struct regmap_field
*p0_refclk_sel
[WIZ_MAX_LANES
];
373 struct regmap_field
*pma_cmn_refclk_int_mode
;
374 struct regmap_field
*pma_cmn_refclk1_int_mode
;
375 struct regmap_field
*pma_cmn_refclk_mode
;
376 struct regmap_field
*pma_cmn_refclk_dig_div
;
377 struct regmap_field
*pma_cmn_refclk1_dig_div
;
378 struct regmap_field
*mux_sel_field
[WIZ_MUX_NUM_CLOCKS
];
379 struct regmap_field
*div_sel_field
[WIZ_DIV_NUM_CLOCKS_16G
];
380 struct regmap_field
*typec_ln10_swap
;
381 struct regmap_field
*typec_ln23_swap
;
382 struct regmap_field
*sup_legacy_clk_override
;
386 struct platform_device
*serdes_pdev
;
387 struct reset_controller_dev wiz_phy_reset_dev
;
388 struct gpio_desc
*gpio_typec_dir
;
390 u32 lane_phy_type
[WIZ_MAX_LANES
];
391 u32 master_lane_num
[WIZ_MAX_LANES
];
392 struct clk
*input_clks
[WIZ_MAX_INPUT_CLOCKS
];
393 struct clk
*output_clks
[WIZ_MAX_OUTPUT_CLOCKS
];
394 struct clk_onecell_data clk_data
;
395 const struct wiz_data
*data
;
398 static int wiz_reset(struct wiz
*wiz
)
402 ret
= regmap_field_write(wiz
->por_en
, 0x1);
408 ret
= regmap_field_write(wiz
->por_en
, 0x0);
415 static int wiz_p_mac_div_sel(struct wiz
*wiz
)
417 u32 num_lanes
= wiz
->num_lanes
;
421 for (i
= 0; i
< num_lanes
; i
++) {
422 if (wiz
->lane_phy_type
[i
] == PHY_TYPE_SGMII
||
423 wiz
->lane_phy_type
[i
] == PHY_TYPE_QSGMII
||
424 wiz
->lane_phy_type
[i
] == PHY_TYPE_USXGMII
) {
425 ret
= regmap_field_write(wiz
->p_mac_div_sel0
[i
], 1);
429 ret
= regmap_field_write(wiz
->p_mac_div_sel1
[i
], 2);
438 static int wiz_mode_select(struct wiz
*wiz
)
440 u32 num_lanes
= wiz
->num_lanes
;
441 enum wiz_lane_standard_mode mode
;
445 for (i
= 0; i
< num_lanes
; i
++) {
446 if (wiz
->lane_phy_type
[i
] == PHY_TYPE_DP
) {
447 mode
= LANE_MODE_GEN1
;
448 } else if (wiz
->lane_phy_type
[i
] == PHY_TYPE_QSGMII
) {
449 mode
= LANE_MODE_GEN2
;
450 } else if (wiz
->lane_phy_type
[i
] == PHY_TYPE_USXGMII
) {
451 ret
= regmap_field_write(wiz
->p0_mac_src_sel
[i
], 0x3);
452 ret
= regmap_field_write(wiz
->p0_rxfclk_sel
[i
], 0x3);
453 ret
= regmap_field_write(wiz
->p0_refclk_sel
[i
], 0x2);
454 mode
= LANE_MODE_GEN2
;
459 ret
= regmap_field_write(wiz
->p_standard_mode
[i
], mode
);
467 static int wiz_init_raw_interface(struct wiz
*wiz
, bool enable
)
469 u32 num_lanes
= wiz
->num_lanes
;
473 for (i
= 0; i
< num_lanes
; i
++) {
474 ret
= regmap_field_write(wiz
->p_align
[i
], enable
);
478 ret
= regmap_field_write(wiz
->p_raw_auto_start
[i
], enable
);
486 static int wiz_init(struct wiz
*wiz
)
488 struct device
*dev
= wiz
->dev
;
491 ret
= wiz_reset(wiz
);
493 dev_err(dev
, "WIZ reset failed\n");
497 ret
= wiz_mode_select(wiz
);
499 dev_err(dev
, "WIZ mode select failed\n");
503 ret
= wiz_p_mac_div_sel(wiz
);
505 dev_err(dev
, "Configuring P0 MAC DIV SEL failed\n");
509 ret
= wiz_init_raw_interface(wiz
, true);
511 dev_err(dev
, "WIZ interface initialization failed\n");
518 static int wiz_regfield_init(struct wiz
*wiz
)
520 struct regmap
*regmap
= wiz
->regmap
;
521 struct regmap
*scm_regmap
= wiz
->regmap
; /* updated later to scm_regmap if applicable */
522 int num_lanes
= wiz
->num_lanes
;
523 struct device
*dev
= wiz
->dev
;
524 const struct wiz_data
*data
= wiz
->data
;
527 wiz
->por_en
= devm_regmap_field_alloc(dev
, regmap
, por_en
);
528 if (IS_ERR(wiz
->por_en
)) {
529 dev_err(dev
, "POR_EN reg field init failed\n");
530 return PTR_ERR(wiz
->por_en
);
533 wiz
->phy_reset_n
= devm_regmap_field_alloc(dev
, regmap
,
535 if (IS_ERR(wiz
->phy_reset_n
)) {
536 dev_err(dev
, "PHY_RESET_N reg field init failed\n");
537 return PTR_ERR(wiz
->phy_reset_n
);
540 wiz
->pma_cmn_refclk_int_mode
=
541 devm_regmap_field_alloc(dev
, regmap
, pma_cmn_refclk_int_mode
);
542 if (IS_ERR(wiz
->pma_cmn_refclk_int_mode
)) {
543 dev_err(dev
, "PMA_CMN_REFCLK_INT_MODE reg field init failed\n");
544 return PTR_ERR(wiz
->pma_cmn_refclk_int_mode
);
547 wiz
->pma_cmn_refclk_mode
=
548 devm_regmap_field_alloc(dev
, regmap
, pma_cmn_refclk_mode
);
549 if (IS_ERR(wiz
->pma_cmn_refclk_mode
)) {
550 dev_err(dev
, "PMA_CMN_REFCLK_MODE reg field init failed\n");
551 return PTR_ERR(wiz
->pma_cmn_refclk_mode
);
554 wiz
->div_sel_field
[CMN_REFCLK_DIG_DIV
] =
555 devm_regmap_field_alloc(dev
, regmap
, pma_cmn_refclk_dig_div
);
556 if (IS_ERR(wiz
->div_sel_field
[CMN_REFCLK_DIG_DIV
])) {
557 dev_err(dev
, "PMA_CMN_REFCLK_DIG_DIV reg field init failed\n");
558 return PTR_ERR(wiz
->div_sel_field
[CMN_REFCLK_DIG_DIV
]);
561 if (data
->pma_cmn_refclk1_dig_div
) {
562 wiz
->div_sel_field
[CMN_REFCLK1_DIG_DIV
] =
563 devm_regmap_field_alloc(dev
, regmap
,
564 *data
->pma_cmn_refclk1_dig_div
);
565 if (IS_ERR(wiz
->div_sel_field
[CMN_REFCLK1_DIG_DIV
])) {
566 dev_err(dev
, "PMA_CMN_REFCLK1_DIG_DIV reg field init failed\n");
567 return PTR_ERR(wiz
->div_sel_field
[CMN_REFCLK1_DIG_DIV
]);
571 if (wiz
->scm_regmap
) {
572 scm_regmap
= wiz
->scm_regmap
;
573 wiz
->sup_legacy_clk_override
=
574 devm_regmap_field_alloc(dev
, scm_regmap
, sup_legacy_clk_override
);
575 if (IS_ERR(wiz
->sup_legacy_clk_override
)) {
576 dev_err(dev
, "SUP_LEGACY_CLK_OVERRIDE reg field init failed\n");
577 return PTR_ERR(wiz
->sup_legacy_clk_override
);
581 wiz
->mux_sel_field
[PLL0_REFCLK
] =
582 devm_regmap_field_alloc(dev
, scm_regmap
, *data
->pll0_refclk_mux_sel
);
583 if (IS_ERR(wiz
->mux_sel_field
[PLL0_REFCLK
])) {
584 dev_err(dev
, "PLL0_REFCLK_SEL reg field init failed\n");
585 return PTR_ERR(wiz
->mux_sel_field
[PLL0_REFCLK
]);
588 wiz
->mux_sel_field
[PLL1_REFCLK
] =
589 devm_regmap_field_alloc(dev
, scm_regmap
, *data
->pll1_refclk_mux_sel
);
590 if (IS_ERR(wiz
->mux_sel_field
[PLL1_REFCLK
])) {
591 dev_err(dev
, "PLL1_REFCLK_SEL reg field init failed\n");
592 return PTR_ERR(wiz
->mux_sel_field
[PLL1_REFCLK
]);
595 wiz
->mux_sel_field
[REFCLK_DIG
] = devm_regmap_field_alloc(dev
, scm_regmap
,
596 *data
->refclk_dig_sel
);
597 if (IS_ERR(wiz
->mux_sel_field
[REFCLK_DIG
])) {
598 dev_err(dev
, "REFCLK_DIG_SEL reg field init failed\n");
599 return PTR_ERR(wiz
->mux_sel_field
[REFCLK_DIG
]);
602 if (data
->pma_cmn_refclk1_int_mode
) {
603 wiz
->pma_cmn_refclk1_int_mode
=
604 devm_regmap_field_alloc(dev
, scm_regmap
, *data
->pma_cmn_refclk1_int_mode
);
605 if (IS_ERR(wiz
->pma_cmn_refclk1_int_mode
)) {
606 dev_err(dev
, "PMA_CMN_REFCLK1_INT_MODE reg field init failed\n");
607 return PTR_ERR(wiz
->pma_cmn_refclk1_int_mode
);
611 for (i
= 0; i
< num_lanes
; i
++) {
612 wiz
->p_enable
[i
] = devm_regmap_field_alloc(dev
, regmap
,
614 if (IS_ERR(wiz
->p_enable
[i
])) {
615 dev_err(dev
, "P%d_ENABLE reg field init failed\n", i
);
616 return PTR_ERR(wiz
->p_enable
[i
]);
619 wiz
->p_align
[i
] = devm_regmap_field_alloc(dev
, regmap
,
621 if (IS_ERR(wiz
->p_align
[i
])) {
622 dev_err(dev
, "P%d_ALIGN reg field init failed\n", i
);
623 return PTR_ERR(wiz
->p_align
[i
]);
626 wiz
->p_raw_auto_start
[i
] =
627 devm_regmap_field_alloc(dev
, regmap
, p_raw_auto_start
[i
]);
628 if (IS_ERR(wiz
->p_raw_auto_start
[i
])) {
629 dev_err(dev
, "P%d_RAW_AUTO_START reg field init fail\n",
631 return PTR_ERR(wiz
->p_raw_auto_start
[i
]);
634 wiz
->p_standard_mode
[i
] =
635 devm_regmap_field_alloc(dev
, regmap
, p_standard_mode
[i
]);
636 if (IS_ERR(wiz
->p_standard_mode
[i
])) {
637 dev_err(dev
, "P%d_STANDARD_MODE reg field init fail\n",
639 return PTR_ERR(wiz
->p_standard_mode
[i
]);
642 wiz
->p0_fullrt_div
[i
] = devm_regmap_field_alloc(dev
, regmap
, p0_fullrt_div
[i
]);
643 if (IS_ERR(wiz
->p0_fullrt_div
[i
])) {
644 dev_err(dev
, "P%d_FULLRT_DIV reg field init failed\n", i
);
645 return PTR_ERR(wiz
->p0_fullrt_div
[i
]);
648 wiz
->p0_mac_src_sel
[i
] = devm_regmap_field_alloc(dev
, regmap
, p0_mac_src_sel
[i
]);
649 if (IS_ERR(wiz
->p0_mac_src_sel
[i
])) {
650 dev_err(dev
, "P%d_MAC_SRC_SEL reg field init failed\n", i
);
651 return PTR_ERR(wiz
->p0_mac_src_sel
[i
]);
654 wiz
->p0_rxfclk_sel
[i
] = devm_regmap_field_alloc(dev
, regmap
, p0_rxfclk_sel
[i
]);
655 if (IS_ERR(wiz
->p0_rxfclk_sel
[i
])) {
656 dev_err(dev
, "P%d_RXFCLK_SEL reg field init failed\n", i
);
657 return PTR_ERR(wiz
->p0_rxfclk_sel
[i
]);
660 wiz
->p0_refclk_sel
[i
] = devm_regmap_field_alloc(dev
, regmap
, p0_refclk_sel
[i
]);
661 if (IS_ERR(wiz
->p0_refclk_sel
[i
])) {
662 dev_err(dev
, "P%d_REFCLK_SEL reg field init failed\n", i
);
663 return PTR_ERR(wiz
->p0_refclk_sel
[i
]);
666 wiz
->p_mac_div_sel0
[i
] =
667 devm_regmap_field_alloc(dev
, regmap
, p_mac_div_sel0
[i
]);
668 if (IS_ERR(wiz
->p_mac_div_sel0
[i
])) {
669 dev_err(dev
, "P%d_MAC_DIV_SEL0 reg field init fail\n",
671 return PTR_ERR(wiz
->p_mac_div_sel0
[i
]);
674 wiz
->p_mac_div_sel1
[i
] =
675 devm_regmap_field_alloc(dev
, regmap
, p_mac_div_sel1
[i
]);
676 if (IS_ERR(wiz
->p_mac_div_sel1
[i
])) {
677 dev_err(dev
, "P%d_MAC_DIV_SEL1 reg field init fail\n",
679 return PTR_ERR(wiz
->p_mac_div_sel1
[i
]);
683 wiz
->typec_ln10_swap
= devm_regmap_field_alloc(dev
, regmap
,
685 if (IS_ERR(wiz
->typec_ln10_swap
)) {
686 dev_err(dev
, "LN10_SWAP reg field init failed\n");
687 return PTR_ERR(wiz
->typec_ln10_swap
);
690 wiz
->typec_ln23_swap
= devm_regmap_field_alloc(dev
, regmap
,
692 if (IS_ERR(wiz
->typec_ln23_swap
)) {
693 dev_err(dev
, "LN23_SWAP reg field init failed\n");
694 return PTR_ERR(wiz
->typec_ln23_swap
);
697 wiz
->phy_en_refclk
= devm_regmap_field_alloc(dev
, regmap
, phy_en_refclk
);
698 if (IS_ERR(wiz
->phy_en_refclk
)) {
699 dev_err(dev
, "PHY_EN_REFCLK reg field init failed\n");
700 return PTR_ERR(wiz
->phy_en_refclk
);
706 static int wiz_phy_en_refclk_enable(struct clk_hw
*hw
)
708 struct wiz_phy_en_refclk
*wiz_phy_en_refclk
= to_wiz_phy_en_refclk(hw
);
709 struct regmap_field
*phy_en_refclk
= wiz_phy_en_refclk
->phy_en_refclk
;
711 regmap_field_write(phy_en_refclk
, 1);
716 static void wiz_phy_en_refclk_disable(struct clk_hw
*hw
)
718 struct wiz_phy_en_refclk
*wiz_phy_en_refclk
= to_wiz_phy_en_refclk(hw
);
719 struct regmap_field
*phy_en_refclk
= wiz_phy_en_refclk
->phy_en_refclk
;
721 regmap_field_write(phy_en_refclk
, 0);
724 static int wiz_phy_en_refclk_is_enabled(struct clk_hw
*hw
)
726 struct wiz_phy_en_refclk
*wiz_phy_en_refclk
= to_wiz_phy_en_refclk(hw
);
727 struct regmap_field
*phy_en_refclk
= wiz_phy_en_refclk
->phy_en_refclk
;
730 regmap_field_read(phy_en_refclk
, &val
);
735 static const struct clk_ops wiz_phy_en_refclk_ops
= {
736 .enable
= wiz_phy_en_refclk_enable
,
737 .disable
= wiz_phy_en_refclk_disable
,
738 .is_enabled
= wiz_phy_en_refclk_is_enabled
,
741 static int wiz_phy_en_refclk_register(struct wiz
*wiz
)
743 struct wiz_phy_en_refclk
*wiz_phy_en_refclk
;
744 struct device
*dev
= wiz
->dev
;
745 struct clk_init_data
*init
;
750 wiz_phy_en_refclk
= devm_kzalloc(dev
, sizeof(*wiz_phy_en_refclk
), GFP_KERNEL
);
751 if (!wiz_phy_en_refclk
)
754 init
= &wiz_phy_en_refclk
->clk_data
;
756 init
->ops
= &wiz_phy_en_refclk_ops
;
759 sz
= strlen(dev_name(dev
)) + strlen(output_clk_names
[TI_WIZ_PHY_EN_REFCLK
]) + 2;
761 clk_name
= kzalloc(sz
, GFP_KERNEL
);
765 snprintf(clk_name
, sz
, "%s_%s", dev_name(dev
), output_clk_names
[TI_WIZ_PHY_EN_REFCLK
]);
766 init
->name
= clk_name
;
768 wiz_phy_en_refclk
->phy_en_refclk
= wiz
->phy_en_refclk
;
769 wiz_phy_en_refclk
->hw
.init
= init
;
771 clk
= devm_clk_register(dev
, &wiz_phy_en_refclk
->hw
);
778 wiz
->output_clks
[TI_WIZ_PHY_EN_REFCLK
] = clk
;
783 static u8
wiz_clk_mux_get_parent(struct clk_hw
*hw
)
785 struct wiz_clk_mux
*mux
= to_wiz_clk_mux(hw
);
786 struct regmap_field
*field
= mux
->field
;
789 regmap_field_read(field
, &val
);
790 return clk_mux_val_to_index(hw
, (u32
*)mux
->table
, 0, val
);
793 static int wiz_clk_mux_set_parent(struct clk_hw
*hw
, u8 index
)
795 struct wiz_clk_mux
*mux
= to_wiz_clk_mux(hw
);
796 struct regmap_field
*field
= mux
->field
;
799 val
= mux
->table
[index
];
800 return regmap_field_write(field
, val
);
803 static const struct clk_ops wiz_clk_mux_ops
= {
804 .determine_rate
= __clk_mux_determine_rate
,
805 .set_parent
= wiz_clk_mux_set_parent
,
806 .get_parent
= wiz_clk_mux_get_parent
,
809 static int wiz_mux_clk_register(struct wiz
*wiz
, struct regmap_field
*field
,
810 const struct wiz_clk_mux_sel
*mux_sel
, int clk_index
)
812 struct device
*dev
= wiz
->dev
;
813 struct clk_init_data
*init
;
814 const char **parent_names
;
815 unsigned int num_parents
;
816 struct wiz_clk_mux
*mux
;
821 mux
= devm_kzalloc(dev
, sizeof(*mux
), GFP_KERNEL
);
825 num_parents
= mux_sel
->num_parents
;
827 parent_names
= kzalloc((sizeof(char *) * num_parents
), GFP_KERNEL
);
831 for (i
= 0; i
< num_parents
; i
++) {
832 clk
= wiz
->input_clks
[mux_sel
->parents
[i
]];
833 if (IS_ERR_OR_NULL(clk
)) {
834 dev_err(dev
, "Failed to get parent clk for %s\n",
835 output_clk_names
[clk_index
]);
839 parent_names
[i
] = __clk_get_name(clk
);
842 snprintf(clk_name
, sizeof(clk_name
), "%s_%s", dev_name(dev
), output_clk_names
[clk_index
]);
844 init
= &mux
->clk_data
;
846 init
->ops
= &wiz_clk_mux_ops
;
847 init
->flags
= CLK_SET_RATE_NO_REPARENT
;
848 init
->parent_names
= parent_names
;
849 init
->num_parents
= num_parents
;
850 init
->name
= clk_name
;
853 mux
->table
= mux_sel
->table
;
856 clk
= devm_clk_register(dev
, &mux
->hw
);
862 wiz
->output_clks
[clk_index
] = clk
;
870 static int wiz_mux_of_clk_register(struct wiz
*wiz
, struct device_node
*node
,
871 struct regmap_field
*field
, const u32
*table
)
873 struct device
*dev
= wiz
->dev
;
874 struct clk_init_data
*init
;
875 const char **parent_names
;
876 unsigned int num_parents
;
877 struct wiz_clk_mux
*mux
;
882 mux
= devm_kzalloc(dev
, sizeof(*mux
), GFP_KERNEL
);
886 num_parents
= of_clk_get_parent_count(node
);
887 if (num_parents
< 2) {
888 dev_err(dev
, "SERDES clock must have parents\n");
892 parent_names
= devm_kzalloc(dev
, (sizeof(char *) * num_parents
),
897 of_clk_parent_fill(node
, parent_names
, num_parents
);
899 snprintf(clk_name
, sizeof(clk_name
), "%s_%s", dev_name(dev
),
902 init
= &mux
->clk_data
;
904 init
->ops
= &wiz_clk_mux_ops
;
905 init
->flags
= CLK_SET_RATE_NO_REPARENT
;
906 init
->parent_names
= parent_names
;
907 init
->num_parents
= num_parents
;
908 init
->name
= clk_name
;
914 clk
= devm_clk_register(dev
, &mux
->hw
);
918 ret
= of_clk_add_provider(node
, of_clk_src_simple_get
, clk
);
920 dev_err(dev
, "Failed to add clock provider: %s\n", clk_name
);
925 static unsigned long wiz_clk_div_recalc_rate(struct clk_hw
*hw
,
926 unsigned long parent_rate
)
928 struct wiz_clk_divider
*div
= to_wiz_clk_div(hw
);
929 struct regmap_field
*field
= div
->field
;
932 regmap_field_read(field
, &val
);
934 return divider_recalc_rate(hw
, parent_rate
, val
, div
->table
, 0x0, 2);
937 static long wiz_clk_div_round_rate(struct clk_hw
*hw
, unsigned long rate
,
938 unsigned long *prate
)
940 struct wiz_clk_divider
*div
= to_wiz_clk_div(hw
);
942 return divider_round_rate(hw
, rate
, prate
, div
->table
, 2, 0x0);
945 static int wiz_clk_div_set_rate(struct clk_hw
*hw
, unsigned long rate
,
946 unsigned long parent_rate
)
948 struct wiz_clk_divider
*div
= to_wiz_clk_div(hw
);
949 struct regmap_field
*field
= div
->field
;
952 val
= divider_get_val(rate
, parent_rate
, div
->table
, 2, 0x0);
956 return regmap_field_write(field
, val
);
959 static const struct clk_ops wiz_clk_div_ops
= {
960 .recalc_rate
= wiz_clk_div_recalc_rate
,
961 .round_rate
= wiz_clk_div_round_rate
,
962 .set_rate
= wiz_clk_div_set_rate
,
965 static int wiz_div_clk_register(struct wiz
*wiz
, struct device_node
*node
,
966 struct regmap_field
*field
,
967 const struct clk_div_table
*table
)
969 struct device
*dev
= wiz
->dev
;
970 struct wiz_clk_divider
*div
;
971 struct clk_init_data
*init
;
972 const char **parent_names
;
977 div
= devm_kzalloc(dev
, sizeof(*div
), GFP_KERNEL
);
981 snprintf(clk_name
, sizeof(clk_name
), "%s_%s", dev_name(dev
),
984 parent_names
= devm_kzalloc(dev
, sizeof(char *), GFP_KERNEL
);
988 of_clk_parent_fill(node
, parent_names
, 1);
990 init
= &div
->clk_data
;
992 init
->ops
= &wiz_clk_div_ops
;
994 init
->parent_names
= parent_names
;
995 init
->num_parents
= 1;
996 init
->name
= clk_name
;
1000 div
->hw
.init
= init
;
1002 clk
= devm_clk_register(dev
, &div
->hw
);
1004 return PTR_ERR(clk
);
1006 ret
= of_clk_add_provider(node
, of_clk_src_simple_get
, clk
);
1008 dev_err(dev
, "Failed to add clock provider: %s\n", clk_name
);
1013 static void wiz_clock_cleanup(struct wiz
*wiz
, struct device_node
*node
)
1015 const struct wiz_clk_mux_sel
*clk_mux_sel
= wiz
->clk_mux_sel
;
1016 struct device
*dev
= wiz
->dev
;
1017 struct device_node
*clk_node
;
1020 switch (wiz
->type
) {
1023 case J784S4_WIZ_10G
:
1024 case J721S2_WIZ_10G
:
1025 of_clk_del_provider(dev
->of_node
);
1031 for (i
= 0; i
< WIZ_MUX_NUM_CLOCKS
; i
++) {
1032 clk_node
= of_get_child_by_name(node
, clk_mux_sel
[i
].node_name
);
1033 of_clk_del_provider(clk_node
);
1034 of_node_put(clk_node
);
1037 for (i
= 0; i
< wiz
->clk_div_sel_num
; i
++) {
1038 clk_node
= of_get_child_by_name(node
, clk_div_sel
[i
].node_name
);
1039 of_clk_del_provider(clk_node
);
1040 of_node_put(clk_node
);
1043 of_clk_del_provider(wiz
->dev
->of_node
);
1046 static int wiz_clock_register(struct wiz
*wiz
)
1048 const struct wiz_clk_mux_sel
*clk_mux_sel
= wiz
->clk_mux_sel
;
1049 struct device
*dev
= wiz
->dev
;
1050 struct device_node
*node
= dev
->of_node
;
1055 clk_index
= TI_WIZ_PLL0_REFCLK
;
1056 for (i
= 0; i
< WIZ_MUX_NUM_CLOCKS
; i
++, clk_index
++) {
1057 ret
= wiz_mux_clk_register(wiz
, wiz
->mux_sel_field
[i
], &clk_mux_sel
[i
], clk_index
);
1059 dev_err(dev
, "Failed to register clk: %s\n", output_clk_names
[clk_index
]);
1064 ret
= wiz_phy_en_refclk_register(wiz
);
1066 dev_err(dev
, "Failed to add phy-en-refclk\n");
1070 wiz
->clk_data
.clks
= wiz
->output_clks
;
1071 wiz
->clk_data
.clk_num
= WIZ_MAX_OUTPUT_CLOCKS
;
1072 ret
= of_clk_add_provider(node
, of_clk_src_onecell_get
, &wiz
->clk_data
);
1074 dev_err(dev
, "Failed to add clock provider: %s\n", node
->name
);
1079 static void wiz_clock_init(struct wiz
*wiz
)
1083 rate
= clk_get_rate(wiz
->input_clks
[WIZ_CORE_REFCLK
]);
1084 if (rate
>= REF_CLK_100MHZ
)
1085 regmap_field_write(wiz
->pma_cmn_refclk_int_mode
, 0x1);
1087 regmap_field_write(wiz
->pma_cmn_refclk_int_mode
, 0x3);
1089 switch (wiz
->type
) {
1093 case REF_CLK_100MHZ
:
1094 regmap_field_write(wiz
->div_sel_field
[CMN_REFCLK_DIG_DIV
], 0x2);
1096 case REF_CLK_156_25MHZ
:
1097 regmap_field_write(wiz
->div_sel_field
[CMN_REFCLK_DIG_DIV
], 0x3);
1100 regmap_field_write(wiz
->div_sel_field
[CMN_REFCLK_DIG_DIV
], 0);
1108 if (wiz
->input_clks
[WIZ_CORE_REFCLK1
]) {
1109 rate
= clk_get_rate(wiz
->input_clks
[WIZ_CORE_REFCLK1
]);
1110 if (rate
>= REF_CLK_100MHZ
)
1111 regmap_field_write(wiz
->pma_cmn_refclk1_int_mode
, 0x1);
1113 regmap_field_write(wiz
->pma_cmn_refclk1_int_mode
, 0x3);
1116 rate
= clk_get_rate(wiz
->input_clks
[WIZ_EXT_REFCLK
]);
1117 if (rate
>= REF_CLK_100MHZ
)
1118 regmap_field_write(wiz
->pma_cmn_refclk_mode
, 0x0);
1120 regmap_field_write(wiz
->pma_cmn_refclk_mode
, 0x2);
1123 static int wiz_clock_probe(struct wiz
*wiz
, struct device_node
*node
)
1125 const struct wiz_clk_mux_sel
*clk_mux_sel
= wiz
->clk_mux_sel
;
1126 struct device
*dev
= wiz
->dev
;
1127 struct device_node
*clk_node
;
1128 const char *node_name
;
1133 clk
= devm_clk_get(dev
, "core_ref_clk");
1135 return dev_err_probe(dev
, PTR_ERR(clk
),
1136 "core_ref_clk clock not found\n");
1138 wiz
->input_clks
[WIZ_CORE_REFCLK
] = clk
;
1140 if (wiz
->data
->pma_cmn_refclk1_int_mode
) {
1141 clk
= devm_clk_get(dev
, "core_ref1_clk");
1143 return dev_err_probe(dev
, PTR_ERR(clk
),
1144 "core_ref1_clk clock not found\n");
1146 wiz
->input_clks
[WIZ_CORE_REFCLK1
] = clk
;
1149 clk
= devm_clk_get(dev
, "ext_ref_clk");
1151 return dev_err_probe(dev
, PTR_ERR(clk
),
1152 "ext_ref_clk clock not found\n");
1154 wiz
->input_clks
[WIZ_EXT_REFCLK
] = clk
;
1156 wiz_clock_init(wiz
);
1158 switch (wiz
->type
) {
1161 case J784S4_WIZ_10G
:
1162 case J721S2_WIZ_10G
:
1163 ret
= wiz_clock_register(wiz
);
1165 return dev_err_probe(dev
, ret
, "Failed to register wiz clocks\n");
1172 for (i
= 0; i
< WIZ_MUX_NUM_CLOCKS
; i
++) {
1173 node_name
= clk_mux_sel
[i
].node_name
;
1174 clk_node
= of_get_child_by_name(node
, node_name
);
1176 ret
= dev_err_probe(dev
, -EINVAL
, "Unable to get %s node\n", node_name
);
1180 ret
= wiz_mux_of_clk_register(wiz
, clk_node
, wiz
->mux_sel_field
[i
],
1181 clk_mux_sel
[i
].table
);
1182 of_node_put(clk_node
);
1184 dev_err_probe(dev
, ret
, "Failed to register %s clock\n",
1191 for (i
= 0; i
< wiz
->clk_div_sel_num
; i
++) {
1192 node_name
= clk_div_sel
[i
].node_name
;
1193 clk_node
= of_get_child_by_name(node
, node_name
);
1195 ret
= dev_err_probe(dev
, -EINVAL
, "Unable to get %s node\n", node_name
);
1199 ret
= wiz_div_clk_register(wiz
, clk_node
, wiz
->div_sel_field
[i
],
1200 clk_div_sel
[i
].table
);
1201 of_node_put(clk_node
);
1203 dev_err_probe(dev
, ret
, "Failed to register %s clock\n",
1211 wiz_clock_cleanup(wiz
, node
);
1216 static int wiz_phy_reset_assert(struct reset_controller_dev
*rcdev
,
1219 struct device
*dev
= rcdev
->dev
;
1220 struct wiz
*wiz
= dev_get_drvdata(dev
);
1224 ret
= regmap_field_write(wiz
->phy_reset_n
, false);
1228 ret
= regmap_field_write(wiz
->p_enable
[id
- 1], P_ENABLE_DISABLE
);
1232 static int wiz_phy_fullrt_div(struct wiz
*wiz
, int lane
)
1234 switch (wiz
->type
) {
1236 if (wiz
->lane_phy_type
[lane
] == PHY_TYPE_PCIE
)
1237 return regmap_field_write(wiz
->p0_fullrt_div
[lane
], 0x1);
1243 case J721S2_WIZ_10G
:
1244 case J784S4_WIZ_10G
:
1245 if (wiz
->lane_phy_type
[lane
] == PHY_TYPE_SGMII
)
1246 return regmap_field_write(wiz
->p0_fullrt_div
[lane
], 0x2);
1254 static int wiz_phy_reset_deassert(struct reset_controller_dev
*rcdev
,
1257 struct device
*dev
= rcdev
->dev
;
1258 struct wiz
*wiz
= dev_get_drvdata(dev
);
1262 /* if typec-dir gpio was specified, set LN10 SWAP bit based on that */
1263 if (wiz
->gpio_typec_dir
) {
1264 if (wiz
->typec_dir_delay
)
1265 msleep_interruptible(wiz
->typec_dir_delay
);
1267 if (gpiod_get_value_cansleep(wiz
->gpio_typec_dir
))
1268 regmap_field_write(wiz
->typec_ln10_swap
, 1);
1270 regmap_field_write(wiz
->typec_ln10_swap
, 0);
1272 /* if no typec-dir gpio is specified and PHY type is USB3
1273 * with master lane number is '0' or '2', then set LN10 or
1274 * LN23 SWAP bit to '1' respectively.
1276 u32 num_lanes
= wiz
->num_lanes
;
1279 for (i
= 0; i
< num_lanes
; i
++) {
1280 if (wiz
->lane_phy_type
[i
] == PHY_TYPE_USB3
) {
1281 switch (wiz
->master_lane_num
[i
]) {
1283 regmap_field_write(wiz
->typec_ln10_swap
, 1);
1286 regmap_field_write(wiz
->typec_ln23_swap
, 1);
1297 ret
= regmap_field_write(wiz
->phy_reset_n
, true);
1301 ret
= wiz_phy_fullrt_div(wiz
, id
- 1);
1305 if (wiz
->lane_phy_type
[id
- 1] == PHY_TYPE_DP
)
1306 ret
= regmap_field_write(wiz
->p_enable
[id
- 1], P_ENABLE
);
1308 ret
= regmap_field_write(wiz
->p_enable
[id
- 1], P_ENABLE_FORCE
);
1313 static const struct reset_control_ops wiz_phy_reset_ops
= {
1314 .assert = wiz_phy_reset_assert
,
1315 .deassert
= wiz_phy_reset_deassert
,
1318 static const struct regmap_config wiz_regmap_config
= {
1325 static struct wiz_data j721e_16g_data
= {
1326 .type
= J721E_WIZ_16G
,
1327 .pll0_refclk_mux_sel
= &pll0_refclk_mux_sel
,
1328 .pll1_refclk_mux_sel
= &pll1_refclk_mux_sel
,
1329 .refclk_dig_sel
= &refclk_dig_sel_16g
,
1330 .pma_cmn_refclk1_dig_div
= &pma_cmn_refclk1_dig_div
,
1331 .clk_mux_sel
= clk_mux_sel_16g
,
1332 .clk_div_sel_num
= WIZ_DIV_NUM_CLOCKS_16G
,
1335 static struct wiz_data j721e_10g_data
= {
1336 .type
= J721E_WIZ_10G
,
1337 .pll0_refclk_mux_sel
= &pll0_refclk_mux_sel
,
1338 .pll1_refclk_mux_sel
= &pll1_refclk_mux_sel
,
1339 .refclk_dig_sel
= &refclk_dig_sel_10g
,
1340 .clk_mux_sel
= clk_mux_sel_10g
,
1341 .clk_div_sel_num
= WIZ_DIV_NUM_CLOCKS_10G
,
1344 static struct wiz_data am64_10g_data
= {
1345 .type
= AM64_WIZ_10G
,
1346 .pll0_refclk_mux_sel
= &pll0_refclk_mux_sel
,
1347 .pll1_refclk_mux_sel
= &pll1_refclk_mux_sel
,
1348 .refclk_dig_sel
= &refclk_dig_sel_10g
,
1349 .clk_mux_sel
= clk_mux_sel_10g
,
1350 .clk_div_sel_num
= WIZ_DIV_NUM_CLOCKS_10G
,
1353 static struct wiz_data j7200_pg2_10g_data
= {
1354 .type
= J7200_WIZ_10G
,
1355 .pll0_refclk_mux_sel
= &sup_pll0_refclk_mux_sel
,
1356 .pll1_refclk_mux_sel
= &sup_pll1_refclk_mux_sel
,
1357 .refclk_dig_sel
= &sup_refclk_dig_sel_10g
,
1358 .pma_cmn_refclk1_int_mode
= &sup_pma_cmn_refclk1_int_mode
,
1359 .clk_mux_sel
= clk_mux_sel_10g_2_refclk
,
1360 .clk_div_sel_num
= WIZ_DIV_NUM_CLOCKS_10G
,
1363 static struct wiz_data j784s4_10g_data
= {
1364 .type
= J784S4_WIZ_10G
,
1365 .pll0_refclk_mux_sel
= &pll0_refclk_mux_sel_2
,
1366 .pll1_refclk_mux_sel
= &pll1_refclk_mux_sel_2
,
1367 .refclk_dig_sel
= &refclk_dig_sel_16g
,
1368 .pma_cmn_refclk1_int_mode
= &pma_cmn_refclk1_int_mode
,
1369 .clk_mux_sel
= clk_mux_sel_10g_2_refclk
,
1370 .clk_div_sel_num
= WIZ_DIV_NUM_CLOCKS_10G
,
1373 static struct wiz_data j721s2_10g_data
= {
1374 .type
= J721S2_WIZ_10G
,
1375 .pll0_refclk_mux_sel
= &pll0_refclk_mux_sel
,
1376 .pll1_refclk_mux_sel
= &pll1_refclk_mux_sel
,
1377 .refclk_dig_sel
= &refclk_dig_sel_10g
,
1378 .clk_mux_sel
= clk_mux_sel_10g
,
1379 .clk_div_sel_num
= WIZ_DIV_NUM_CLOCKS_10G
,
1382 static const struct of_device_id wiz_id_table
[] = {
1384 .compatible
= "ti,j721e-wiz-16g", .data
= &j721e_16g_data
,
1387 .compatible
= "ti,j721e-wiz-10g", .data
= &j721e_10g_data
,
1390 .compatible
= "ti,am64-wiz-10g", .data
= &am64_10g_data
,
1393 .compatible
= "ti,j7200-wiz-10g", .data
= &j7200_pg2_10g_data
,
1396 .compatible
= "ti,j784s4-wiz-10g", .data
= &j784s4_10g_data
,
1399 .compatible
= "ti,j721s2-wiz-10g", .data
= &j721s2_10g_data
,
1403 MODULE_DEVICE_TABLE(of
, wiz_id_table
);
1405 static int wiz_get_lane_phy_types(struct device
*dev
, struct wiz
*wiz
)
1407 struct device_node
*serdes
;
1409 serdes
= of_get_child_by_name(dev
->of_node
, "serdes");
1411 dev_err(dev
, "%s: Getting \"serdes\"-node failed\n", __func__
);
1415 for_each_child_of_node_scoped(serdes
, subnode
) {
1416 u32 reg
, num_lanes
= 1, phy_type
= PHY_NONE
;
1419 if (!(of_node_name_eq(subnode
, "phy") ||
1420 of_node_name_eq(subnode
, "link")))
1423 ret
= of_property_read_u32(subnode
, "reg", ®
);
1426 "%s: Reading \"reg\" from \"%s\" failed: %d\n",
1427 __func__
, subnode
->name
, ret
);
1430 of_property_read_u32(subnode
, "cdns,num-lanes", &num_lanes
);
1431 of_property_read_u32(subnode
, "cdns,phy-type", &phy_type
);
1433 dev_dbg(dev
, "%s: Lanes %u-%u have phy-type %u\n", __func__
,
1434 reg
, reg
+ num_lanes
- 1, phy_type
);
1436 for (i
= reg
; i
< reg
+ num_lanes
; i
++) {
1437 wiz
->master_lane_num
[i
] = reg
;
1438 wiz
->lane_phy_type
[i
] = phy_type
;
1445 static int wiz_probe(struct platform_device
*pdev
)
1447 struct reset_controller_dev
*phy_reset_dev
;
1448 struct device
*dev
= &pdev
->dev
;
1449 struct device_node
*node
= dev
->of_node
;
1450 struct platform_device
*serdes_pdev
;
1451 bool already_configured
= false;
1452 struct device_node
*child_node
;
1453 struct regmap
*regmap
;
1454 struct resource res
;
1459 const struct wiz_data
*data
;
1461 wiz
= devm_kzalloc(dev
, sizeof(*wiz
), GFP_KERNEL
);
1465 data
= of_device_get_match_data(dev
);
1467 dev_err(dev
, "NULL device data\n");
1472 wiz
->type
= data
->type
;
1474 child_node
= of_get_child_by_name(node
, "serdes");
1476 dev_err(dev
, "Failed to get SERDES child DT node\n");
1480 ret
= of_address_to_resource(child_node
, 0, &res
);
1482 dev_err(dev
, "Failed to get memory resource\n");
1483 goto err_addr_to_resource
;
1486 base
= devm_ioremap(dev
, res
.start
, resource_size(&res
));
1489 goto err_addr_to_resource
;
1492 regmap
= devm_regmap_init_mmio(dev
, base
, &wiz_regmap_config
);
1493 if (IS_ERR(regmap
)) {
1494 dev_err(dev
, "Failed to initialize regmap\n");
1495 ret
= PTR_ERR(regmap
);
1496 goto err_addr_to_resource
;
1499 wiz
->scm_regmap
= syscon_regmap_lookup_by_phandle(node
, "ti,scm");
1500 if (IS_ERR(wiz
->scm_regmap
)) {
1501 if (wiz
->type
== J7200_WIZ_10G
) {
1502 dev_err(dev
, "Couldn't get ti,scm regmap\n");
1504 goto err_addr_to_resource
;
1507 wiz
->scm_regmap
= NULL
;
1510 ret
= of_property_read_u32(node
, "num-lanes", &num_lanes
);
1512 dev_err(dev
, "Failed to read num-lanes property\n");
1513 goto err_addr_to_resource
;
1516 if (num_lanes
> WIZ_MAX_LANES
) {
1517 dev_err(dev
, "Cannot support %d lanes\n", num_lanes
);
1519 goto err_addr_to_resource
;
1522 wiz
->gpio_typec_dir
= devm_gpiod_get_optional(dev
, "typec-dir",
1524 if (IS_ERR(wiz
->gpio_typec_dir
)) {
1525 ret
= PTR_ERR(wiz
->gpio_typec_dir
);
1526 if (ret
!= -EPROBE_DEFER
)
1527 dev_err(dev
, "Failed to request typec-dir gpio: %d\n",
1529 goto err_addr_to_resource
;
1532 if (wiz
->gpio_typec_dir
) {
1533 ret
= of_property_read_u32(node
, "typec-dir-debounce-ms",
1534 &wiz
->typec_dir_delay
);
1535 if (ret
&& ret
!= -EINVAL
) {
1536 dev_err(dev
, "Invalid typec-dir-debounce property\n");
1537 goto err_addr_to_resource
;
1540 /* use min. debounce from Type-C spec if not provided in DT */
1542 wiz
->typec_dir_delay
= WIZ_TYPEC_DIR_DEBOUNCE_MIN
;
1544 if (wiz
->typec_dir_delay
< WIZ_TYPEC_DIR_DEBOUNCE_MIN
||
1545 wiz
->typec_dir_delay
> WIZ_TYPEC_DIR_DEBOUNCE_MAX
) {
1547 dev_err(dev
, "Invalid typec-dir-debounce property\n");
1548 goto err_addr_to_resource
;
1552 ret
= wiz_get_lane_phy_types(dev
, wiz
);
1554 goto err_addr_to_resource
;
1557 wiz
->regmap
= regmap
;
1558 wiz
->num_lanes
= num_lanes
;
1559 wiz
->clk_mux_sel
= data
->clk_mux_sel
;
1560 wiz
->clk_div_sel
= clk_div_sel
;
1561 wiz
->clk_div_sel_num
= data
->clk_div_sel_num
;
1563 platform_set_drvdata(pdev
, wiz
);
1565 ret
= wiz_regfield_init(wiz
);
1567 dev_err(dev
, "Failed to initialize regfields\n");
1568 goto err_addr_to_resource
;
1571 /* Enable supplemental Control override if available */
1572 if (wiz
->scm_regmap
)
1573 regmap_field_write(wiz
->sup_legacy_clk_override
, 1);
1575 phy_reset_dev
= &wiz
->wiz_phy_reset_dev
;
1576 phy_reset_dev
->dev
= dev
;
1577 phy_reset_dev
->ops
= &wiz_phy_reset_ops
;
1578 phy_reset_dev
->owner
= THIS_MODULE
;
1579 phy_reset_dev
->of_node
= node
;
1580 /* Reset for each of the lane and one for the entire SERDES */
1581 phy_reset_dev
->nr_resets
= num_lanes
+ 1;
1583 ret
= devm_reset_controller_register(dev
, phy_reset_dev
);
1585 dev_warn(dev
, "Failed to register reset controller\n");
1586 goto err_addr_to_resource
;
1589 pm_runtime_enable(dev
);
1590 ret
= pm_runtime_get_sync(dev
);
1592 dev_err(dev
, "pm_runtime_get_sync failed\n");
1596 ret
= wiz_clock_probe(wiz
, node
);
1598 dev_warn(dev
, "Failed to initialize clocks\n");
1602 for (i
= 0; i
< wiz
->num_lanes
; i
++) {
1603 regmap_field_read(wiz
->p_enable
[i
], &val
);
1604 if (val
& (P_ENABLE
| P_ENABLE_FORCE
)) {
1605 already_configured
= true;
1610 if (!already_configured
) {
1611 ret
= wiz_init(wiz
);
1613 dev_err(dev
, "WIZ initialization failed\n");
1618 serdes_pdev
= of_platform_device_create(child_node
, NULL
, dev
);
1620 dev_WARN(dev
, "Unable to create SERDES platform device\n");
1624 wiz
->serdes_pdev
= serdes_pdev
;
1626 of_node_put(child_node
);
1630 wiz_clock_cleanup(wiz
, node
);
1633 pm_runtime_put(dev
);
1634 pm_runtime_disable(dev
);
1636 err_addr_to_resource
:
1637 of_node_put(child_node
);
1642 static void wiz_remove(struct platform_device
*pdev
)
1644 struct device
*dev
= &pdev
->dev
;
1645 struct device_node
*node
= dev
->of_node
;
1646 struct platform_device
*serdes_pdev
;
1649 wiz
= dev_get_drvdata(dev
);
1650 serdes_pdev
= wiz
->serdes_pdev
;
1652 of_platform_device_destroy(&serdes_pdev
->dev
, NULL
);
1653 wiz_clock_cleanup(wiz
, node
);
1654 pm_runtime_put(dev
);
1655 pm_runtime_disable(dev
);
1658 static int wiz_resume_noirq(struct device
*dev
)
1660 struct device_node
*node
= dev
->of_node
;
1661 struct wiz
*wiz
= dev_get_drvdata(dev
);
1664 /* Enable supplemental Control override if available */
1665 if (wiz
->sup_legacy_clk_override
)
1666 regmap_field_write(wiz
->sup_legacy_clk_override
, 1);
1668 wiz_clock_init(wiz
);
1670 ret
= wiz_init(wiz
);
1672 dev_err(dev
, "WIZ initialization failed\n");
1679 wiz_clock_cleanup(wiz
, node
);
1684 static DEFINE_NOIRQ_DEV_PM_OPS(wiz_pm_ops
, NULL
, wiz_resume_noirq
);
1686 static struct platform_driver wiz_driver
= {
1688 .remove
= wiz_remove
,
1691 .of_match_table
= wiz_id_table
,
1692 .pm
= pm_sleep_ptr(&wiz_pm_ops
),
1695 module_platform_driver(wiz_driver
);
1697 MODULE_AUTHOR("Texas Instruments Inc.");
1698 MODULE_DESCRIPTION("TI J721E WIZ driver");
1699 MODULE_LICENSE("GPL v2");