2 * phy-ti-pipe3 - PIPE3 PHY driver.
4 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * Author: Kishon Vijay Abraham I <kishon@ti.com>
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
19 #include <linux/module.h>
20 #include <linux/platform_device.h>
21 #include <linux/slab.h>
22 #include <linux/phy/phy.h>
24 #include <linux/clk.h>
25 #include <linux/err.h>
27 #include <linux/pm_runtime.h>
28 #include <linux/delay.h>
29 #include <linux/phy/omap_control_phy.h>
30 #include <linux/of_platform.h>
31 #include <linux/mfd/syscon.h>
32 #include <linux/regmap.h>
34 #define PLL_STATUS 0x00000004
35 #define PLL_GO 0x00000008
36 #define PLL_CONFIGURATION1 0x0000000C
37 #define PLL_CONFIGURATION2 0x00000010
38 #define PLL_CONFIGURATION3 0x00000014
39 #define PLL_CONFIGURATION4 0x00000020
41 #define PLL_REGM_MASK 0x001FFE00
42 #define PLL_REGM_SHIFT 0x9
43 #define PLL_REGM_F_MASK 0x0003FFFF
44 #define PLL_REGM_F_SHIFT 0x0
45 #define PLL_REGN_MASK 0x000001FE
46 #define PLL_REGN_SHIFT 0x1
47 #define PLL_SELFREQDCO_MASK 0x0000000E
48 #define PLL_SELFREQDCO_SHIFT 0x1
49 #define PLL_SD_MASK 0x0003FC00
50 #define PLL_SD_SHIFT 10
51 #define SET_PLL_GO 0x1
52 #define PLL_LDOPWDN BIT(15)
53 #define PLL_TICOPWDN BIT(16)
57 #define SATA_PLL_SOFT_RESET BIT(18)
59 #define PIPE3_PHY_PWRCTL_CLK_CMD_MASK 0x003FC000
60 #define PIPE3_PHY_PWRCTL_CLK_CMD_SHIFT 14
62 #define PIPE3_PHY_PWRCTL_CLK_FREQ_MASK 0xFFC00000
63 #define PIPE3_PHY_PWRCTL_CLK_FREQ_SHIFT 22
65 #define PIPE3_PHY_TX_RX_POWERON 0x3
66 #define PIPE3_PHY_TX_RX_POWEROFF 0x0
68 #define PCIE_PCS_MASK 0xFF0000
69 #define PCIE_PCS_DELAY_COUNT_SHIFT 0x10
71 #define PCIEPHYRX_ANA_PROGRAMMABILITY 0x0000000C
72 #define INTERFACE_MASK GENMASK(31, 27)
73 #define INTERFACE_SHIFT 27
74 #define LOSD_MASK GENMASK(17, 14)
76 #define MEM_PLLDIV GENMASK(6, 5)
78 #define PCIEPHYRX_TRIM 0x0000001C
79 #define MEM_DLL_TRIM_SEL GENMASK(31, 30)
80 #define MEM_DLL_TRIM_SHIFT 30
82 #define PCIEPHYRX_DLL 0x00000024
83 #define MEM_DLL_PHINT_RATE GENMASK(31, 30)
85 #define PCIEPHYRX_DIGITAL_MODES 0x00000028
86 #define MEM_CDR_FASTLOCK BIT(23)
87 #define MEM_CDR_LBW GENMASK(22, 21)
88 #define MEM_CDR_STEPCNT GENMASK(20, 19)
89 #define MEM_CDR_STL_MASK GENMASK(18, 16)
90 #define MEM_CDR_STL_SHIFT 16
91 #define MEM_CDR_THR_MASK GENMASK(15, 13)
92 #define MEM_CDR_THR_SHIFT 13
93 #define MEM_CDR_THR_MODE BIT(12)
94 #define MEM_CDR_CDR_2NDO_SDM_MODE BIT(11)
95 #define MEM_OVRD_HS_RATE BIT(26)
97 #define PCIEPHYRX_EQUALIZER 0x00000038
98 #define MEM_EQLEV GENMASK(31, 16)
99 #define MEM_EQFTC GENMASK(15, 11)
100 #define MEM_EQCTL GENMASK(10, 7)
101 #define MEM_EQCTL_SHIFT 7
102 #define MEM_OVRD_EQLEV BIT(2)
103 #define MEM_OVRD_EQFTC BIT(1)
106 * This is an Empirical value that works, need to confirm the actual
107 * value required for the PIPE3PHY_PLL_CONFIGURATION2.PLL_IDLE status
108 * to be correctly reflected in the PIPE3PHY_PLL_STATUS register.
110 #define PLL_IDLE_TIME 100 /* in milliseconds */
111 #define PLL_LOCK_TIME 100 /* in milliseconds */
113 struct pipe3_dpll_params
{
121 struct pipe3_dpll_map
{
123 struct pipe3_dpll_params params
;
127 void __iomem
*pll_ctrl_base
;
128 void __iomem
*phy_rx
;
129 void __iomem
*phy_tx
;
131 struct device
*control_dev
;
136 struct pipe3_dpll_map
*dpll_map
;
137 struct regmap
*phy_power_syscon
; /* ctrl. reg. acces */
138 struct regmap
*pcs_syscon
; /* ctrl. reg. acces */
139 struct regmap
*dpll_reset_syscon
; /* ctrl. reg. acces */
140 unsigned int dpll_reset_reg
; /* reg. index within syscon */
141 unsigned int power_reg
; /* power reg. index within syscon */
142 unsigned int pcie_pcs_reg
; /* pcs reg. index in syscon */
143 bool sata_refclk_enabled
;
146 static struct pipe3_dpll_map dpll_map_usb
[] = {
147 {12000000, {1250, 5, 4, 20, 0} }, /* 12 MHz */
148 {16800000, {3125, 20, 4, 20, 0} }, /* 16.8 MHz */
149 {19200000, {1172, 8, 4, 20, 65537} }, /* 19.2 MHz */
150 {20000000, {1000, 7, 4, 10, 0} }, /* 20 MHz */
151 {26000000, {1250, 12, 4, 20, 0} }, /* 26 MHz */
152 {38400000, {3125, 47, 4, 20, 92843} }, /* 38.4 MHz */
153 { }, /* Terminator */
156 static struct pipe3_dpll_map dpll_map_sata
[] = {
157 {12000000, {625, 4, 4, 6, 0} }, /* 12 MHz */
158 {16800000, {625, 6, 4, 7, 0} }, /* 16.8 MHz */
159 {19200000, {625, 7, 4, 6, 0} }, /* 19.2 MHz */
160 {20000000, {750, 9, 4, 6, 0} }, /* 20 MHz */
161 {26000000, {750, 12, 4, 6, 0} }, /* 26 MHz */
162 {38400000, {625, 15, 4, 6, 0} }, /* 38.4 MHz */
163 { }, /* Terminator */
166 static inline u32
ti_pipe3_readl(void __iomem
*addr
, unsigned offset
)
168 return __raw_readl(addr
+ offset
);
171 static inline void ti_pipe3_writel(void __iomem
*addr
, unsigned offset
,
174 __raw_writel(data
, addr
+ offset
);
177 static struct pipe3_dpll_params
*ti_pipe3_get_dpll_params(struct ti_pipe3
*phy
)
180 struct pipe3_dpll_map
*dpll_map
= phy
->dpll_map
;
182 rate
= clk_get_rate(phy
->sys_clk
);
184 for (; dpll_map
->rate
; dpll_map
++) {
185 if (rate
== dpll_map
->rate
)
186 return &dpll_map
->params
;
189 dev_err(phy
->dev
, "No DPLL configuration for %lu Hz SYS CLK\n", rate
);
194 static int ti_pipe3_enable_clocks(struct ti_pipe3
*phy
);
195 static void ti_pipe3_disable_clocks(struct ti_pipe3
*phy
);
197 static int ti_pipe3_power_off(struct phy
*x
)
201 struct ti_pipe3
*phy
= phy_get_drvdata(x
);
203 if (!phy
->phy_power_syscon
) {
204 omap_control_phy_power(phy
->control_dev
, 0);
208 val
= PIPE3_PHY_TX_RX_POWEROFF
<< PIPE3_PHY_PWRCTL_CLK_CMD_SHIFT
;
210 ret
= regmap_update_bits(phy
->phy_power_syscon
, phy
->power_reg
,
211 PIPE3_PHY_PWRCTL_CLK_CMD_MASK
, val
);
215 static int ti_pipe3_power_on(struct phy
*x
)
221 struct ti_pipe3
*phy
= phy_get_drvdata(x
);
223 if (!phy
->phy_power_syscon
) {
224 omap_control_phy_power(phy
->control_dev
, 1);
228 rate
= clk_get_rate(phy
->sys_clk
);
230 dev_err(phy
->dev
, "Invalid clock rate\n");
233 rate
= rate
/ 1000000;
234 mask
= OMAP_CTRL_PIPE3_PHY_PWRCTL_CLK_CMD_MASK
|
235 OMAP_CTRL_PIPE3_PHY_PWRCTL_CLK_FREQ_MASK
;
236 val
= PIPE3_PHY_TX_RX_POWERON
<< PIPE3_PHY_PWRCTL_CLK_CMD_SHIFT
;
237 val
|= rate
<< OMAP_CTRL_PIPE3_PHY_PWRCTL_CLK_FREQ_SHIFT
;
239 ret
= regmap_update_bits(phy
->phy_power_syscon
, phy
->power_reg
,
244 static int ti_pipe3_dpll_wait_lock(struct ti_pipe3
*phy
)
247 unsigned long timeout
;
249 timeout
= jiffies
+ msecs_to_jiffies(PLL_LOCK_TIME
);
252 val
= ti_pipe3_readl(phy
->pll_ctrl_base
, PLL_STATUS
);
255 } while (!time_after(jiffies
, timeout
));
257 dev_err(phy
->dev
, "DPLL failed to lock\n");
261 static int ti_pipe3_dpll_program(struct ti_pipe3
*phy
)
264 struct pipe3_dpll_params
*dpll_params
;
266 dpll_params
= ti_pipe3_get_dpll_params(phy
);
270 val
= ti_pipe3_readl(phy
->pll_ctrl_base
, PLL_CONFIGURATION1
);
271 val
&= ~PLL_REGN_MASK
;
272 val
|= dpll_params
->n
<< PLL_REGN_SHIFT
;
273 ti_pipe3_writel(phy
->pll_ctrl_base
, PLL_CONFIGURATION1
, val
);
275 val
= ti_pipe3_readl(phy
->pll_ctrl_base
, PLL_CONFIGURATION2
);
276 val
&= ~PLL_SELFREQDCO_MASK
;
277 val
|= dpll_params
->freq
<< PLL_SELFREQDCO_SHIFT
;
278 ti_pipe3_writel(phy
->pll_ctrl_base
, PLL_CONFIGURATION2
, val
);
280 val
= ti_pipe3_readl(phy
->pll_ctrl_base
, PLL_CONFIGURATION1
);
281 val
&= ~PLL_REGM_MASK
;
282 val
|= dpll_params
->m
<< PLL_REGM_SHIFT
;
283 ti_pipe3_writel(phy
->pll_ctrl_base
, PLL_CONFIGURATION1
, val
);
285 val
= ti_pipe3_readl(phy
->pll_ctrl_base
, PLL_CONFIGURATION4
);
286 val
&= ~PLL_REGM_F_MASK
;
287 val
|= dpll_params
->mf
<< PLL_REGM_F_SHIFT
;
288 ti_pipe3_writel(phy
->pll_ctrl_base
, PLL_CONFIGURATION4
, val
);
290 val
= ti_pipe3_readl(phy
->pll_ctrl_base
, PLL_CONFIGURATION3
);
292 val
|= dpll_params
->sd
<< PLL_SD_SHIFT
;
293 ti_pipe3_writel(phy
->pll_ctrl_base
, PLL_CONFIGURATION3
, val
);
295 ti_pipe3_writel(phy
->pll_ctrl_base
, PLL_GO
, SET_PLL_GO
);
297 return ti_pipe3_dpll_wait_lock(phy
);
300 static void ti_pipe3_calibrate(struct ti_pipe3
*phy
)
304 val
= ti_pipe3_readl(phy
->phy_rx
, PCIEPHYRX_ANA_PROGRAMMABILITY
);
305 val
&= ~(INTERFACE_MASK
| LOSD_MASK
| MEM_PLLDIV
);
306 val
= (0x1 << INTERFACE_SHIFT
| 0xA << LOSD_SHIFT
);
307 ti_pipe3_writel(phy
->phy_rx
, PCIEPHYRX_ANA_PROGRAMMABILITY
, val
);
309 val
= ti_pipe3_readl(phy
->phy_rx
, PCIEPHYRX_DIGITAL_MODES
);
310 val
&= ~(MEM_CDR_STEPCNT
| MEM_CDR_STL_MASK
| MEM_CDR_THR_MASK
|
311 MEM_CDR_CDR_2NDO_SDM_MODE
| MEM_OVRD_HS_RATE
);
312 val
|= (MEM_CDR_FASTLOCK
| MEM_CDR_LBW
| 0x3 << MEM_CDR_STL_SHIFT
|
313 0x1 << MEM_CDR_THR_SHIFT
| MEM_CDR_THR_MODE
);
314 ti_pipe3_writel(phy
->phy_rx
, PCIEPHYRX_DIGITAL_MODES
, val
);
316 val
= ti_pipe3_readl(phy
->phy_rx
, PCIEPHYRX_TRIM
);
317 val
&= ~MEM_DLL_TRIM_SEL
;
318 val
|= 0x2 << MEM_DLL_TRIM_SHIFT
;
319 ti_pipe3_writel(phy
->phy_rx
, PCIEPHYRX_TRIM
, val
);
321 val
= ti_pipe3_readl(phy
->phy_rx
, PCIEPHYRX_DLL
);
322 val
|= MEM_DLL_PHINT_RATE
;
323 ti_pipe3_writel(phy
->phy_rx
, PCIEPHYRX_DLL
, val
);
325 val
= ti_pipe3_readl(phy
->phy_rx
, PCIEPHYRX_EQUALIZER
);
326 val
&= ~(MEM_EQLEV
| MEM_EQCTL
| MEM_OVRD_EQLEV
| MEM_OVRD_EQFTC
);
327 val
|= MEM_EQFTC
| 0x1 << MEM_EQCTL_SHIFT
;
328 ti_pipe3_writel(phy
->phy_rx
, PCIEPHYRX_EQUALIZER
, val
);
331 static int ti_pipe3_init(struct phy
*x
)
333 struct ti_pipe3
*phy
= phy_get_drvdata(x
);
337 ti_pipe3_enable_clocks(phy
);
339 * Set pcie_pcs register to 0x96 for proper functioning of phy
340 * as recommended in AM572x TRM SPRUHZ6, section 18.5.2.2, table
343 if (of_device_is_compatible(phy
->dev
->of_node
, "ti,phy-pipe3-pcie")) {
344 if (!phy
->pcs_syscon
) {
345 omap_control_pcie_pcs(phy
->control_dev
, 0x96);
349 val
= 0x96 << OMAP_CTRL_PCIE_PCS_DELAY_COUNT_SHIFT
;
350 ret
= regmap_update_bits(phy
->pcs_syscon
, phy
->pcie_pcs_reg
,
355 ti_pipe3_calibrate(phy
);
360 /* Bring it out of IDLE if it is IDLE */
361 val
= ti_pipe3_readl(phy
->pll_ctrl_base
, PLL_CONFIGURATION2
);
362 if (val
& PLL_IDLE
) {
364 ti_pipe3_writel(phy
->pll_ctrl_base
, PLL_CONFIGURATION2
, val
);
365 ret
= ti_pipe3_dpll_wait_lock(phy
);
368 /* SATA has issues if re-programmed when locked */
369 val
= ti_pipe3_readl(phy
->pll_ctrl_base
, PLL_STATUS
);
370 if ((val
& PLL_LOCK
) && of_device_is_compatible(phy
->dev
->of_node
,
371 "ti,phy-pipe3-sata"))
374 /* Program the DPLL */
375 ret
= ti_pipe3_dpll_program(phy
);
377 ti_pipe3_disable_clocks(phy
);
384 static int ti_pipe3_exit(struct phy
*x
)
386 struct ti_pipe3
*phy
= phy_get_drvdata(x
);
388 unsigned long timeout
;
390 /* If dpll_reset_syscon is not present we wont power down SATA DPLL
393 if (of_device_is_compatible(phy
->dev
->of_node
, "ti,phy-pipe3-sata") &&
394 !phy
->dpll_reset_syscon
)
397 /* PCIe doesn't have internal DPLL */
398 if (!of_device_is_compatible(phy
->dev
->of_node
, "ti,phy-pipe3-pcie")) {
399 /* Put DPLL in IDLE mode */
400 val
= ti_pipe3_readl(phy
->pll_ctrl_base
, PLL_CONFIGURATION2
);
402 ti_pipe3_writel(phy
->pll_ctrl_base
, PLL_CONFIGURATION2
, val
);
404 /* wait for LDO and Oscillator to power down */
405 timeout
= jiffies
+ msecs_to_jiffies(PLL_IDLE_TIME
);
408 val
= ti_pipe3_readl(phy
->pll_ctrl_base
, PLL_STATUS
);
409 if ((val
& PLL_TICOPWDN
) && (val
& PLL_LDOPWDN
))
411 } while (!time_after(jiffies
, timeout
));
413 if (!(val
& PLL_TICOPWDN
) || !(val
& PLL_LDOPWDN
)) {
414 dev_err(phy
->dev
, "Failed to power down: PLL_STATUS 0x%x\n",
420 /* i783: SATA needs control bit toggle after PLL unlock */
421 if (of_device_is_compatible(phy
->dev
->of_node
, "ti,phy-pipe3-sata")) {
422 regmap_update_bits(phy
->dpll_reset_syscon
, phy
->dpll_reset_reg
,
423 SATA_PLL_SOFT_RESET
, SATA_PLL_SOFT_RESET
);
424 regmap_update_bits(phy
->dpll_reset_syscon
, phy
->dpll_reset_reg
,
425 SATA_PLL_SOFT_RESET
, 0);
428 ti_pipe3_disable_clocks(phy
);
432 static const struct phy_ops ops
= {
433 .init
= ti_pipe3_init
,
434 .exit
= ti_pipe3_exit
,
435 .power_on
= ti_pipe3_power_on
,
436 .power_off
= ti_pipe3_power_off
,
437 .owner
= THIS_MODULE
,
440 static const struct of_device_id ti_pipe3_id_table
[];
442 static int ti_pipe3_get_clk(struct ti_pipe3
*phy
)
445 struct device
*dev
= phy
->dev
;
446 struct device_node
*node
= dev
->of_node
;
448 phy
->refclk
= devm_clk_get(dev
, "refclk");
449 if (IS_ERR(phy
->refclk
)) {
450 dev_err(dev
, "unable to get refclk\n");
451 /* older DTBs have missing refclk in SATA PHY
452 * so don't bail out in case of SATA PHY.
454 if (!of_device_is_compatible(node
, "ti,phy-pipe3-sata"))
455 return PTR_ERR(phy
->refclk
);
458 if (!of_device_is_compatible(node
, "ti,phy-pipe3-sata")) {
459 phy
->wkupclk
= devm_clk_get(dev
, "wkupclk");
460 if (IS_ERR(phy
->wkupclk
)) {
461 dev_err(dev
, "unable to get wkupclk\n");
462 return PTR_ERR(phy
->wkupclk
);
465 phy
->wkupclk
= ERR_PTR(-ENODEV
);
468 if (!of_device_is_compatible(node
, "ti,phy-pipe3-pcie") ||
469 phy
->phy_power_syscon
) {
470 phy
->sys_clk
= devm_clk_get(dev
, "sysclk");
471 if (IS_ERR(phy
->sys_clk
)) {
472 dev_err(dev
, "unable to get sysclk\n");
477 if (of_device_is_compatible(node
, "ti,phy-pipe3-pcie")) {
478 clk
= devm_clk_get(dev
, "dpll_ref");
480 dev_err(dev
, "unable to get dpll ref clk\n");
483 clk_set_rate(clk
, 1500000000);
485 clk
= devm_clk_get(dev
, "dpll_ref_m2");
487 dev_err(dev
, "unable to get dpll ref m2 clk\n");
490 clk_set_rate(clk
, 100000000);
492 clk
= devm_clk_get(dev
, "phy-div");
494 dev_err(dev
, "unable to get phy-div clk\n");
497 clk_set_rate(clk
, 100000000);
499 phy
->div_clk
= devm_clk_get(dev
, "div-clk");
500 if (IS_ERR(phy
->div_clk
)) {
501 dev_err(dev
, "unable to get div-clk\n");
502 return PTR_ERR(phy
->div_clk
);
505 phy
->div_clk
= ERR_PTR(-ENODEV
);
511 static int ti_pipe3_get_sysctrl(struct ti_pipe3
*phy
)
513 struct device
*dev
= phy
->dev
;
514 struct device_node
*node
= dev
->of_node
;
515 struct device_node
*control_node
;
516 struct platform_device
*control_pdev
;
518 phy
->phy_power_syscon
= syscon_regmap_lookup_by_phandle(node
,
520 if (IS_ERR(phy
->phy_power_syscon
)) {
522 "can't get syscon-phy-power, using control device\n");
523 phy
->phy_power_syscon
= NULL
;
525 if (of_property_read_u32_index(node
,
526 "syscon-phy-power", 1,
528 dev_err(dev
, "couldn't get power reg. offset\n");
533 if (!phy
->phy_power_syscon
) {
534 control_node
= of_parse_phandle(node
, "ctrl-module", 0);
536 dev_err(dev
, "Failed to get control device phandle\n");
540 control_pdev
= of_find_device_by_node(control_node
);
542 dev_err(dev
, "Failed to get control device\n");
546 phy
->control_dev
= &control_pdev
->dev
;
549 if (of_device_is_compatible(node
, "ti,phy-pipe3-pcie")) {
550 phy
->pcs_syscon
= syscon_regmap_lookup_by_phandle(node
,
552 if (IS_ERR(phy
->pcs_syscon
)) {
554 "can't get syscon-pcs, using omap control\n");
555 phy
->pcs_syscon
= NULL
;
557 if (of_property_read_u32_index(node
,
559 &phy
->pcie_pcs_reg
)) {
561 "couldn't get pcie pcs reg. offset\n");
567 if (of_device_is_compatible(node
, "ti,phy-pipe3-sata")) {
568 phy
->dpll_reset_syscon
= syscon_regmap_lookup_by_phandle(node
,
570 if (IS_ERR(phy
->dpll_reset_syscon
)) {
572 "can't get syscon-pllreset, sata dpll won't idle\n");
573 phy
->dpll_reset_syscon
= NULL
;
575 if (of_property_read_u32_index(node
,
576 "syscon-pllreset", 1,
577 &phy
->dpll_reset_reg
)) {
579 "couldn't get pllreset reg. offset\n");
588 static int ti_pipe3_get_tx_rx_base(struct ti_pipe3
*phy
)
590 struct resource
*res
;
591 struct device
*dev
= phy
->dev
;
592 struct device_node
*node
= dev
->of_node
;
593 struct platform_device
*pdev
= to_platform_device(dev
);
595 if (!of_device_is_compatible(node
, "ti,phy-pipe3-pcie"))
598 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
,
600 phy
->phy_rx
= devm_ioremap_resource(dev
, res
);
601 if (IS_ERR(phy
->phy_rx
))
602 return PTR_ERR(phy
->phy_rx
);
604 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
,
606 phy
->phy_tx
= devm_ioremap_resource(dev
, res
);
608 return PTR_ERR_OR_ZERO(phy
->phy_tx
);
611 static int ti_pipe3_get_pll_base(struct ti_pipe3
*phy
)
613 struct resource
*res
;
614 const struct of_device_id
*match
;
615 struct device
*dev
= phy
->dev
;
616 struct device_node
*node
= dev
->of_node
;
617 struct platform_device
*pdev
= to_platform_device(dev
);
619 if (of_device_is_compatible(node
, "ti,phy-pipe3-pcie"))
622 match
= of_match_device(ti_pipe3_id_table
, dev
);
626 phy
->dpll_map
= (struct pipe3_dpll_map
*)match
->data
;
627 if (!phy
->dpll_map
) {
628 dev_err(dev
, "no DPLL data\n");
632 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
,
634 phy
->pll_ctrl_base
= devm_ioremap_resource(dev
, res
);
635 return PTR_ERR_OR_ZERO(phy
->pll_ctrl_base
);
638 static int ti_pipe3_probe(struct platform_device
*pdev
)
640 struct ti_pipe3
*phy
;
641 struct phy
*generic_phy
;
642 struct phy_provider
*phy_provider
;
643 struct device_node
*node
= pdev
->dev
.of_node
;
644 struct device
*dev
= &pdev
->dev
;
647 phy
= devm_kzalloc(dev
, sizeof(*phy
), GFP_KERNEL
);
653 ret
= ti_pipe3_get_pll_base(phy
);
657 ret
= ti_pipe3_get_tx_rx_base(phy
);
661 ret
= ti_pipe3_get_sysctrl(phy
);
665 ret
= ti_pipe3_get_clk(phy
);
669 platform_set_drvdata(pdev
, phy
);
670 pm_runtime_enable(dev
);
673 * Prevent auto-disable of refclk for SATA PHY due to Errata i783
675 if (of_device_is_compatible(node
, "ti,phy-pipe3-sata")) {
676 if (!IS_ERR(phy
->refclk
)) {
677 clk_prepare_enable(phy
->refclk
);
678 phy
->sata_refclk_enabled
= true;
682 generic_phy
= devm_phy_create(dev
, NULL
, &ops
);
683 if (IS_ERR(generic_phy
))
684 return PTR_ERR(generic_phy
);
686 phy_set_drvdata(generic_phy
, phy
);
688 ti_pipe3_power_off(generic_phy
);
690 phy_provider
= devm_of_phy_provider_register(dev
, of_phy_simple_xlate
);
691 return PTR_ERR_OR_ZERO(phy_provider
);
694 static int ti_pipe3_remove(struct platform_device
*pdev
)
696 pm_runtime_disable(&pdev
->dev
);
701 static int ti_pipe3_enable_clocks(struct ti_pipe3
*phy
)
705 if (!IS_ERR(phy
->refclk
)) {
706 ret
= clk_prepare_enable(phy
->refclk
);
708 dev_err(phy
->dev
, "Failed to enable refclk %d\n", ret
);
713 if (!IS_ERR(phy
->wkupclk
)) {
714 ret
= clk_prepare_enable(phy
->wkupclk
);
716 dev_err(phy
->dev
, "Failed to enable wkupclk %d\n", ret
);
721 if (!IS_ERR(phy
->div_clk
)) {
722 ret
= clk_prepare_enable(phy
->div_clk
);
724 dev_err(phy
->dev
, "Failed to enable div_clk %d\n", ret
);
725 goto disable_wkupclk
;
732 if (!IS_ERR(phy
->wkupclk
))
733 clk_disable_unprepare(phy
->wkupclk
);
736 if (!IS_ERR(phy
->refclk
))
737 clk_disable_unprepare(phy
->refclk
);
742 static void ti_pipe3_disable_clocks(struct ti_pipe3
*phy
)
744 if (!IS_ERR(phy
->wkupclk
))
745 clk_disable_unprepare(phy
->wkupclk
);
746 if (!IS_ERR(phy
->refclk
)) {
747 clk_disable_unprepare(phy
->refclk
);
749 * SATA refclk needs an additional disable as we left it
750 * on in probe to avoid Errata i783
752 if (phy
->sata_refclk_enabled
) {
753 clk_disable_unprepare(phy
->refclk
);
754 phy
->sata_refclk_enabled
= false;
758 if (!IS_ERR(phy
->div_clk
))
759 clk_disable_unprepare(phy
->div_clk
);
762 static const struct of_device_id ti_pipe3_id_table
[] = {
764 .compatible
= "ti,phy-usb3",
765 .data
= dpll_map_usb
,
768 .compatible
= "ti,omap-usb3",
769 .data
= dpll_map_usb
,
772 .compatible
= "ti,phy-pipe3-sata",
773 .data
= dpll_map_sata
,
776 .compatible
= "ti,phy-pipe3-pcie",
780 MODULE_DEVICE_TABLE(of
, ti_pipe3_id_table
);
782 static struct platform_driver ti_pipe3_driver
= {
783 .probe
= ti_pipe3_probe
,
784 .remove
= ti_pipe3_remove
,
787 .of_match_table
= ti_pipe3_id_table
,
791 module_platform_driver(ti_pipe3_driver
);
793 MODULE_ALIAS("platform:ti_pipe3");
794 MODULE_AUTHOR("Texas Instruments Inc.");
795 MODULE_DESCRIPTION("TI PIPE3 phy driver");
796 MODULE_LICENSE("GPL v2");