1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Broadcom SATA3 AHCI Controller PHY Driver
5 * Copyright (C) 2016 Broadcom
8 #include <linux/delay.h>
9 #include <linux/device.h>
10 #include <linux/init.h>
11 #include <linux/interrupt.h>
13 #include <linux/kernel.h>
14 #include <linux/module.h>
16 #include <linux/phy/phy.h>
17 #include <linux/platform_device.h>
19 #define SATA_PCB_BANK_OFFSET 0x23c
20 #define SATA_PCB_REG_OFFSET(ofs) ((ofs) * 4)
24 /* Register offset between PHYs in PCB space */
25 #define SATA_PCB_REG_28NM_SPACE_SIZE 0x1000
27 /* The older SATA PHY registers duplicated per port registers within the map,
28 * rather than having a separate map per port.
30 #define SATA_PCB_REG_40NM_SPACE_SIZE 0x10
32 /* Register offset between PHYs in PHY control space */
33 #define SATA_PHY_CTRL_REG_28NM_SPACE_SIZE 0x8
35 enum brcm_sata_phy_version
{
36 BRCM_SATA_PHY_STB_16NM
,
37 BRCM_SATA_PHY_STB_28NM
,
38 BRCM_SATA_PHY_STB_40NM
,
39 BRCM_SATA_PHY_IPROC_NS2
,
40 BRCM_SATA_PHY_IPROC_NSP
,
41 BRCM_SATA_PHY_IPROC_SR
,
42 BRCM_SATA_PHY_DSL_28NM
,
45 enum brcm_sata_phy_rxaeq_mode
{
51 static enum brcm_sata_phy_rxaeq_mode
rxaeq_to_val(const char *m
)
53 if (!strcmp(m
, "auto"))
54 return RXAEQ_MODE_AUTO
;
55 else if (!strcmp(m
, "manual"))
56 return RXAEQ_MODE_MANUAL
;
58 return RXAEQ_MODE_OFF
;
61 struct brcm_sata_port
{
64 struct brcm_sata_phy
*phy_priv
;
66 enum brcm_sata_phy_rxaeq_mode rxaeq_mode
;
71 struct brcm_sata_phy
{
73 void __iomem
*phy_base
;
74 void __iomem
*ctrl_base
;
75 enum brcm_sata_phy_version version
;
77 struct brcm_sata_port phys
[MAX_PORTS
];
81 BLOCK0_REG_BANK
= 0x000,
82 BLOCK0_XGXSSTATUS
= 0x81,
83 BLOCK0_XGXSSTATUS_PLL_LOCK
= BIT(12),
85 BLOCK0_SPARE_OOB_CLK_SEL_MASK
= 0x3,
86 BLOCK0_SPARE_OOB_CLK_SEL_REFBY2
= 0x1,
88 BLOCK1_REG_BANK
= 0x10,
89 BLOCK1_TEST_TX
= 0x83,
90 BLOCK1_TEST_TX_AMP_SHIFT
= 12,
92 PLL_REG_BANK_0
= 0x050,
93 PLL_REG_BANK_0_PLLCONTROL_0
= 0x81,
94 PLLCONTROL_0_FREQ_DET_RESTART
= BIT(13),
95 PLLCONTROL_0_FREQ_MONITOR
= BIT(12),
96 PLLCONTROL_0_SEQ_START
= BIT(15),
97 PLL_CAP_CHARGE_TIME
= 0x83,
98 PLL_VCO_CAL_THRESH
= 0x84,
99 PLL_CAP_CONTROL
= 0x85,
100 PLL_FREQ_DET_TIME
= 0x86,
102 PLL_ACTRL2_SELDIV_MASK
= 0x1f,
103 PLL_ACTRL2_SELDIV_SHIFT
= 9,
106 PLL1_REG_BANK
= 0x060,
117 TX_ACTRL0_TXPOL_FLIP
= BIT(6),
119 TX_ACTRL5_SSC_EN
= BIT(11),
121 AEQRX_REG_BANK_0
= 0xd0,
123 AEQ_CONTROL1_ENABLE
= BIT(2),
124 AEQ_CONTROL1_FREEZE
= BIT(3),
126 AEQ_FRC_EQ_FORCE
= BIT(0),
127 AEQ_FRC_EQ_FORCE_VAL
= BIT(1),
128 AEQ_RFZ_FRC_VAL
= BIT(8),
129 AEQRX_REG_BANK_1
= 0xe0,
130 AEQRX_SLCAL0_CTRL0
= 0x82,
131 AEQRX_SLCAL1_CTRL0
= 0x86,
133 OOB_REG_BANK
= 0x150,
134 OOB1_REG_BANK
= 0x160,
136 OOB_CTRL1_BURST_MAX_MASK
= 0xf,
137 OOB_CTRL1_BURST_MAX_SHIFT
= 12,
138 OOB_CTRL1_BURST_MIN_MASK
= 0xf,
139 OOB_CTRL1_BURST_MIN_SHIFT
= 8,
140 OOB_CTRL1_WAKE_IDLE_MAX_MASK
= 0xf,
141 OOB_CTRL1_WAKE_IDLE_MAX_SHIFT
= 4,
142 OOB_CTRL1_WAKE_IDLE_MIN_MASK
= 0xf,
143 OOB_CTRL1_WAKE_IDLE_MIN_SHIFT
= 0,
145 OOB_CTRL2_SEL_ENA_SHIFT
= 15,
146 OOB_CTRL2_SEL_ENA_RC_SHIFT
= 14,
147 OOB_CTRL2_RESET_IDLE_MAX_MASK
= 0x3f,
148 OOB_CTRL2_RESET_IDLE_MAX_SHIFT
= 8,
149 OOB_CTRL2_BURST_CNT_MASK
= 0x3,
150 OOB_CTRL2_BURST_CNT_SHIFT
= 6,
151 OOB_CTRL2_RESET_IDLE_MIN_MASK
= 0x3f,
152 OOB_CTRL2_RESET_IDLE_MIN_SHIFT
= 0,
154 TXPMD_REG_BANK
= 0x1a0,
155 TXPMD_CONTROL1
= 0x81,
156 TXPMD_CONTROL1_TX_SSC_EN_FRC
= BIT(0),
157 TXPMD_CONTROL1_TX_SSC_EN_FRC_VAL
= BIT(1),
158 TXPMD_TX_FREQ_CTRL_CONTROL1
= 0x82,
159 TXPMD_TX_FREQ_CTRL_CONTROL2
= 0x83,
160 TXPMD_TX_FREQ_CTRL_CONTROL2_FMIN_MASK
= 0x3ff,
161 TXPMD_TX_FREQ_CTRL_CONTROL3
= 0x84,
162 TXPMD_TX_FREQ_CTRL_CONTROL3_FMAX_MASK
= 0x3ff,
164 RXPMD_REG_BANK
= 0x1c0,
165 RXPMD_RX_CDR_CONTROL1
= 0x81,
166 RXPMD_RX_PPM_VAL_MASK
= 0x1ff,
167 RXPMD_RXPMD_EN_FRC
= BIT(12),
168 RXPMD_RXPMD_EN_FRC_VAL
= BIT(13),
169 RXPMD_RX_CDR_CDR_PROP_BW
= 0x82,
170 RXPMD_G_CDR_PROP_BW_MASK
= 0x7,
171 RXPMD_G1_CDR_PROP_BW_SHIFT
= 0,
172 RXPMD_G2_CDR_PROP_BW_SHIFT
= 3,
173 RXPMD_G3_CDR_PROB_BW_SHIFT
= 6,
174 RXPMD_RX_CDR_CDR_ACQ_INTEG_BW
= 0x83,
175 RXPMD_G_CDR_ACQ_INT_BW_MASK
= 0x7,
176 RXPMD_G1_CDR_ACQ_INT_BW_SHIFT
= 0,
177 RXPMD_G2_CDR_ACQ_INT_BW_SHIFT
= 3,
178 RXPMD_G3_CDR_ACQ_INT_BW_SHIFT
= 6,
179 RXPMD_RX_CDR_CDR_LOCK_INTEG_BW
= 0x84,
180 RXPMD_G_CDR_LOCK_INT_BW_MASK
= 0x7,
181 RXPMD_G1_CDR_LOCK_INT_BW_SHIFT
= 0,
182 RXPMD_G2_CDR_LOCK_INT_BW_SHIFT
= 3,
183 RXPMD_G3_CDR_LOCK_INT_BW_SHIFT
= 6,
184 RXPMD_RX_FREQ_MON_CONTROL1
= 0x87,
185 RXPMD_MON_CORRECT_EN
= BIT(8),
186 RXPMD_MON_MARGIN_VAL_MASK
= 0xff,
189 enum sata_phy_ctrl_regs
{
191 PHY_CTRL_1_RESET
= BIT(0),
194 static inline void __iomem
*brcm_sata_ctrl_base(struct brcm_sata_port
*port
)
196 struct brcm_sata_phy
*priv
= port
->phy_priv
;
199 switch (priv
->version
) {
200 case BRCM_SATA_PHY_IPROC_NS2
:
201 size
= SATA_PHY_CTRL_REG_28NM_SPACE_SIZE
;
204 dev_err(priv
->dev
, "invalid phy version\n");
208 return priv
->ctrl_base
+ (port
->portnum
* size
);
211 static void brcm_sata_phy_wr(struct brcm_sata_port
*port
, u32 bank
,
212 u32 ofs
, u32 msk
, u32 value
)
214 struct brcm_sata_phy
*priv
= port
->phy_priv
;
215 void __iomem
*pcb_base
= priv
->phy_base
;
218 if (priv
->version
== BRCM_SATA_PHY_STB_40NM
)
219 bank
+= (port
->portnum
* SATA_PCB_REG_40NM_SPACE_SIZE
);
221 pcb_base
+= (port
->portnum
* SATA_PCB_REG_28NM_SPACE_SIZE
);
223 writel(bank
, pcb_base
+ SATA_PCB_BANK_OFFSET
);
224 tmp
= readl(pcb_base
+ SATA_PCB_REG_OFFSET(ofs
));
225 tmp
= (tmp
& msk
) | value
;
226 writel(tmp
, pcb_base
+ SATA_PCB_REG_OFFSET(ofs
));
229 static u32
brcm_sata_phy_rd(struct brcm_sata_port
*port
, u32 bank
, u32 ofs
)
231 struct brcm_sata_phy
*priv
= port
->phy_priv
;
232 void __iomem
*pcb_base
= priv
->phy_base
;
234 if (priv
->version
== BRCM_SATA_PHY_STB_40NM
)
235 bank
+= (port
->portnum
* SATA_PCB_REG_40NM_SPACE_SIZE
);
237 pcb_base
+= (port
->portnum
* SATA_PCB_REG_28NM_SPACE_SIZE
);
239 writel(bank
, pcb_base
+ SATA_PCB_BANK_OFFSET
);
240 return readl(pcb_base
+ SATA_PCB_REG_OFFSET(ofs
));
243 /* These defaults were characterized by H/W group */
244 #define STB_FMIN_VAL_DEFAULT 0x3df
245 #define STB_FMAX_VAL_DEFAULT 0x3df
246 #define STB_FMAX_VAL_SSC 0x83
248 static void brcm_stb_sata_ssc_init(struct brcm_sata_port
*port
)
250 struct brcm_sata_phy
*priv
= port
->phy_priv
;
253 /* override the TX spread spectrum setting */
254 tmp
= TXPMD_CONTROL1_TX_SSC_EN_FRC_VAL
| TXPMD_CONTROL1_TX_SSC_EN_FRC
;
255 brcm_sata_phy_wr(port
, TXPMD_REG_BANK
, TXPMD_CONTROL1
, ~tmp
, tmp
);
257 /* set fixed min freq */
258 brcm_sata_phy_wr(port
, TXPMD_REG_BANK
, TXPMD_TX_FREQ_CTRL_CONTROL2
,
259 ~TXPMD_TX_FREQ_CTRL_CONTROL2_FMIN_MASK
,
260 STB_FMIN_VAL_DEFAULT
);
262 /* set fixed max freq depending on SSC config */
264 dev_info(priv
->dev
, "enabling SSC on port%d\n", port
->portnum
);
265 tmp
= STB_FMAX_VAL_SSC
;
267 tmp
= STB_FMAX_VAL_DEFAULT
;
270 brcm_sata_phy_wr(port
, TXPMD_REG_BANK
, TXPMD_TX_FREQ_CTRL_CONTROL3
,
271 ~TXPMD_TX_FREQ_CTRL_CONTROL3_FMAX_MASK
, tmp
);
274 #define AEQ_FRC_EQ_VAL_SHIFT 2
275 #define AEQ_FRC_EQ_VAL_MASK 0x3f
277 static int brcm_stb_sata_rxaeq_init(struct brcm_sata_port
*port
)
279 u32 tmp
= 0, reg
= 0;
281 switch (port
->rxaeq_mode
) {
285 case RXAEQ_MODE_AUTO
:
287 tmp
= AEQ_CONTROL1_ENABLE
| AEQ_CONTROL1_FREEZE
;
290 case RXAEQ_MODE_MANUAL
:
292 tmp
= AEQ_FRC_EQ_FORCE
| AEQ_FRC_EQ_FORCE_VAL
;
293 if (port
->rxaeq_val
> AEQ_FRC_EQ_VAL_MASK
)
295 tmp
|= port
->rxaeq_val
<< AEQ_FRC_EQ_VAL_SHIFT
;
299 brcm_sata_phy_wr(port
, AEQRX_REG_BANK_0
, reg
, ~tmp
, tmp
);
300 brcm_sata_phy_wr(port
, AEQRX_REG_BANK_1
, reg
, ~tmp
, tmp
);
305 static int brcm_stb_sata_init(struct brcm_sata_port
*port
)
307 brcm_stb_sata_ssc_init(port
);
309 return brcm_stb_sata_rxaeq_init(port
);
312 static int brcm_stb_sata_16nm_ssc_init(struct brcm_sata_port
*port
)
316 /* Reduce CP tail current to 1/16th of its default value */
317 brcm_sata_phy_wr(port
, PLL1_REG_BANK
, PLL1_ACTRL6
, 0, 0x141);
319 /* Turn off CP tail current boost */
320 brcm_sata_phy_wr(port
, PLL1_REG_BANK
, PLL1_ACTRL8
, 0, 0xc006);
322 /* Set a specific AEQ equalizer value */
323 tmp
= AEQ_FRC_EQ_FORCE_VAL
| AEQ_FRC_EQ_FORCE
;
324 brcm_sata_phy_wr(port
, AEQRX_REG_BANK_0
, AEQ_FRC_EQ
,
325 ~(tmp
| AEQ_RFZ_FRC_VAL
|
326 AEQ_FRC_EQ_VAL_MASK
<< AEQ_FRC_EQ_VAL_SHIFT
),
327 tmp
| 32 << AEQ_FRC_EQ_VAL_SHIFT
);
329 /* Set RX PPM val center frequency */
334 brcm_sata_phy_wr(port
, RXPMD_REG_BANK
, RXPMD_RX_CDR_CONTROL1
,
335 ~RXPMD_RX_PPM_VAL_MASK
, value
);
337 /* Set proportional loop bandwith Gen1/2/3 */
338 tmp
= RXPMD_G_CDR_PROP_BW_MASK
<< RXPMD_G1_CDR_PROP_BW_SHIFT
|
339 RXPMD_G_CDR_PROP_BW_MASK
<< RXPMD_G2_CDR_PROP_BW_SHIFT
|
340 RXPMD_G_CDR_PROP_BW_MASK
<< RXPMD_G3_CDR_PROB_BW_SHIFT
;
342 value
= 2 << RXPMD_G1_CDR_PROP_BW_SHIFT
|
343 2 << RXPMD_G2_CDR_PROP_BW_SHIFT
|
344 2 << RXPMD_G3_CDR_PROB_BW_SHIFT
;
346 value
= 1 << RXPMD_G1_CDR_PROP_BW_SHIFT
|
347 1 << RXPMD_G2_CDR_PROP_BW_SHIFT
|
348 1 << RXPMD_G3_CDR_PROB_BW_SHIFT
;
349 brcm_sata_phy_wr(port
, RXPMD_REG_BANK
, RXPMD_RX_CDR_CDR_PROP_BW
, ~tmp
,
352 /* Set CDR integral loop acquisition bandwidth for Gen1/2/3 */
353 tmp
= RXPMD_G_CDR_ACQ_INT_BW_MASK
<< RXPMD_G1_CDR_ACQ_INT_BW_SHIFT
|
354 RXPMD_G_CDR_ACQ_INT_BW_MASK
<< RXPMD_G2_CDR_ACQ_INT_BW_SHIFT
|
355 RXPMD_G_CDR_ACQ_INT_BW_MASK
<< RXPMD_G3_CDR_ACQ_INT_BW_SHIFT
;
357 value
= 1 << RXPMD_G1_CDR_ACQ_INT_BW_SHIFT
|
358 1 << RXPMD_G2_CDR_ACQ_INT_BW_SHIFT
|
359 1 << RXPMD_G3_CDR_ACQ_INT_BW_SHIFT
;
362 brcm_sata_phy_wr(port
, RXPMD_REG_BANK
, RXPMD_RX_CDR_CDR_ACQ_INTEG_BW
,
365 /* Set CDR integral loop locking bandwidth to 1 for Gen 1/2/3 */
366 tmp
= RXPMD_G_CDR_LOCK_INT_BW_MASK
<< RXPMD_G1_CDR_LOCK_INT_BW_SHIFT
|
367 RXPMD_G_CDR_LOCK_INT_BW_MASK
<< RXPMD_G2_CDR_LOCK_INT_BW_SHIFT
|
368 RXPMD_G_CDR_LOCK_INT_BW_MASK
<< RXPMD_G3_CDR_LOCK_INT_BW_SHIFT
;
370 value
= 1 << RXPMD_G1_CDR_LOCK_INT_BW_SHIFT
|
371 1 << RXPMD_G2_CDR_LOCK_INT_BW_SHIFT
|
372 1 << RXPMD_G3_CDR_LOCK_INT_BW_SHIFT
;
375 brcm_sata_phy_wr(port
, RXPMD_REG_BANK
, RXPMD_RX_CDR_CDR_LOCK_INTEG_BW
,
378 /* Set no guard band and clamp CDR */
379 tmp
= RXPMD_MON_CORRECT_EN
| RXPMD_MON_MARGIN_VAL_MASK
;
384 brcm_sata_phy_wr(port
, RXPMD_REG_BANK
, RXPMD_RX_FREQ_MON_CONTROL1
,
385 ~tmp
, RXPMD_MON_CORRECT_EN
| value
);
387 tmp
= GENMASK(15, 12);
388 switch (port
->tx_amplitude_val
) {
390 value
= BIT(12) | BIT(13);
407 brcm_sata_phy_wr(port
, BLOCK1_REG_BANK
, BLOCK1_TEST_TX
, ~tmp
,
410 /* Turn on/off SSC */
411 brcm_sata_phy_wr(port
, TX_REG_BANK
, TX_ACTRL5
, ~TX_ACTRL5_SSC_EN
,
412 port
->ssc_en
? TX_ACTRL5_SSC_EN
: 0);
417 static int brcm_stb_sata_16nm_init(struct brcm_sata_port
*port
)
419 return brcm_stb_sata_16nm_ssc_init(port
);
422 /* NS2 SATA PLL1 defaults were characterized by H/W group */
423 #define NS2_PLL1_ACTRL2_MAGIC 0x1df8
424 #define NS2_PLL1_ACTRL3_MAGIC 0x2b00
425 #define NS2_PLL1_ACTRL4_MAGIC 0x8824
427 static int brcm_ns2_sata_init(struct brcm_sata_port
*port
)
431 void __iomem
*ctrl_base
= brcm_sata_ctrl_base(port
);
432 struct device
*dev
= port
->phy_priv
->dev
;
434 /* Configure OOB control */
436 val
|= (0xc << OOB_CTRL1_BURST_MAX_SHIFT
);
437 val
|= (0x4 << OOB_CTRL1_BURST_MIN_SHIFT
);
438 val
|= (0x9 << OOB_CTRL1_WAKE_IDLE_MAX_SHIFT
);
439 val
|= (0x3 << OOB_CTRL1_WAKE_IDLE_MIN_SHIFT
);
440 brcm_sata_phy_wr(port
, OOB_REG_BANK
, OOB_CTRL1
, 0x0, val
);
442 val
|= (0x1b << OOB_CTRL2_RESET_IDLE_MAX_SHIFT
);
443 val
|= (0x2 << OOB_CTRL2_BURST_CNT_SHIFT
);
444 val
|= (0x9 << OOB_CTRL2_RESET_IDLE_MIN_SHIFT
);
445 brcm_sata_phy_wr(port
, OOB_REG_BANK
, OOB_CTRL2
, 0x0, val
);
447 /* Configure PHY PLL register bank 1 */
448 val
= NS2_PLL1_ACTRL2_MAGIC
;
449 brcm_sata_phy_wr(port
, PLL1_REG_BANK
, PLL1_ACTRL2
, 0x0, val
);
450 val
= NS2_PLL1_ACTRL3_MAGIC
;
451 brcm_sata_phy_wr(port
, PLL1_REG_BANK
, PLL1_ACTRL3
, 0x0, val
);
452 val
= NS2_PLL1_ACTRL4_MAGIC
;
453 brcm_sata_phy_wr(port
, PLL1_REG_BANK
, PLL1_ACTRL4
, 0x0, val
);
455 /* Configure PHY BLOCK0 register bank */
456 /* Set oob_clk_sel to refclk/2 */
457 brcm_sata_phy_wr(port
, BLOCK0_REG_BANK
, BLOCK0_SPARE
,
458 ~BLOCK0_SPARE_OOB_CLK_SEL_MASK
,
459 BLOCK0_SPARE_OOB_CLK_SEL_REFBY2
);
461 /* Strobe PHY reset using PHY control register */
462 writel(PHY_CTRL_1_RESET
, ctrl_base
+ PHY_CTRL_1
);
464 writel(0x0, ctrl_base
+ PHY_CTRL_1
);
467 /* Wait for PHY PLL lock by polling pll_lock bit */
470 val
= brcm_sata_phy_rd(port
, BLOCK0_REG_BANK
,
472 if (val
& BLOCK0_XGXSSTATUS_PLL_LOCK
)
478 /* PLL did not lock; give up */
479 dev_err(dev
, "port%d PLL did not lock\n", port
->portnum
);
483 dev_dbg(dev
, "port%d initialized\n", port
->portnum
);
488 static int brcm_nsp_sata_init(struct brcm_sata_port
*port
)
490 struct device
*dev
= port
->phy_priv
->dev
;
491 unsigned int oob_bank
;
492 unsigned int val
, try;
494 /* Configure OOB control */
495 if (port
->portnum
== 0)
496 oob_bank
= OOB_REG_BANK
;
497 else if (port
->portnum
== 1)
498 oob_bank
= OOB1_REG_BANK
;
503 val
|= (0x0f << OOB_CTRL1_BURST_MAX_SHIFT
);
504 val
|= (0x06 << OOB_CTRL1_BURST_MIN_SHIFT
);
505 val
|= (0x0f << OOB_CTRL1_WAKE_IDLE_MAX_SHIFT
);
506 val
|= (0x06 << OOB_CTRL1_WAKE_IDLE_MIN_SHIFT
);
507 brcm_sata_phy_wr(port
, oob_bank
, OOB_CTRL1
, 0x0, val
);
510 val
|= (0x2e << OOB_CTRL2_RESET_IDLE_MAX_SHIFT
);
511 val
|= (0x02 << OOB_CTRL2_BURST_CNT_SHIFT
);
512 val
|= (0x16 << OOB_CTRL2_RESET_IDLE_MIN_SHIFT
);
513 brcm_sata_phy_wr(port
, oob_bank
, OOB_CTRL2
, 0x0, val
);
516 brcm_sata_phy_wr(port
, PLL_REG_BANK_0
, PLL_ACTRL2
,
517 ~(PLL_ACTRL2_SELDIV_MASK
<< PLL_ACTRL2_SELDIV_SHIFT
),
518 0x0c << PLL_ACTRL2_SELDIV_SHIFT
);
520 brcm_sata_phy_wr(port
, PLL_REG_BANK_0
, PLL_CAP_CONTROL
,
523 val
= PLLCONTROL_0_FREQ_DET_RESTART
| PLLCONTROL_0_FREQ_MONITOR
;
524 brcm_sata_phy_wr(port
, PLL_REG_BANK_0
, PLL_REG_BANK_0_PLLCONTROL_0
,
526 val
= PLLCONTROL_0_SEQ_START
;
527 brcm_sata_phy_wr(port
, PLL_REG_BANK_0
, PLL_REG_BANK_0_PLLCONTROL_0
,
530 brcm_sata_phy_wr(port
, PLL_REG_BANK_0
, PLL_REG_BANK_0_PLLCONTROL_0
,
533 /* Wait for pll_seq_done bit */
536 val
= brcm_sata_phy_rd(port
, BLOCK0_REG_BANK
,
538 if (val
& BLOCK0_XGXSSTATUS_PLL_LOCK
)
543 /* PLL did not lock; give up */
544 dev_err(dev
, "port%d PLL did not lock\n", port
->portnum
);
548 dev_dbg(dev
, "port%d initialized\n", port
->portnum
);
553 /* SR PHY PLL0 registers */
554 #define SR_PLL0_ACTRL6_MAGIC 0xa
556 /* SR PHY PLL1 registers */
557 #define SR_PLL1_ACTRL2_MAGIC 0x32
558 #define SR_PLL1_ACTRL3_MAGIC 0x2
559 #define SR_PLL1_ACTRL4_MAGIC 0x3e8
561 static int brcm_sr_sata_init(struct brcm_sata_port
*port
)
563 struct device
*dev
= port
->phy_priv
->dev
;
564 unsigned int val
, try;
566 /* Configure PHY PLL register bank 1 */
567 val
= SR_PLL1_ACTRL2_MAGIC
;
568 brcm_sata_phy_wr(port
, PLL1_REG_BANK
, PLL1_ACTRL2
, 0x0, val
);
569 val
= SR_PLL1_ACTRL3_MAGIC
;
570 brcm_sata_phy_wr(port
, PLL1_REG_BANK
, PLL1_ACTRL3
, 0x0, val
);
571 val
= SR_PLL1_ACTRL4_MAGIC
;
572 brcm_sata_phy_wr(port
, PLL1_REG_BANK
, PLL1_ACTRL4
, 0x0, val
);
574 /* Configure PHY PLL register bank 0 */
575 val
= SR_PLL0_ACTRL6_MAGIC
;
576 brcm_sata_phy_wr(port
, PLL_REG_BANK_0
, PLL_ACTRL6
, 0x0, val
);
578 /* Wait for PHY PLL lock by polling pll_lock bit */
581 val
= brcm_sata_phy_rd(port
, BLOCK0_REG_BANK
,
583 if (val
& BLOCK0_XGXSSTATUS_PLL_LOCK
)
589 if ((val
& BLOCK0_XGXSSTATUS_PLL_LOCK
) == 0) {
590 /* PLL did not lock; give up */
591 dev_err(dev
, "port%d PLL did not lock\n", port
->portnum
);
595 /* Invert Tx polarity */
596 brcm_sata_phy_wr(port
, TX_REG_BANK
, TX_ACTRL0
,
597 ~TX_ACTRL0_TXPOL_FLIP
, TX_ACTRL0_TXPOL_FLIP
);
599 /* Configure OOB control to handle 100MHz reference clock */
600 val
= ((0xc << OOB_CTRL1_BURST_MAX_SHIFT
) |
601 (0x4 << OOB_CTRL1_BURST_MIN_SHIFT
) |
602 (0x8 << OOB_CTRL1_WAKE_IDLE_MAX_SHIFT
) |
603 (0x3 << OOB_CTRL1_WAKE_IDLE_MIN_SHIFT
));
604 brcm_sata_phy_wr(port
, OOB_REG_BANK
, OOB_CTRL1
, 0x0, val
);
605 val
= ((0x1b << OOB_CTRL2_RESET_IDLE_MAX_SHIFT
) |
606 (0x2 << OOB_CTRL2_BURST_CNT_SHIFT
) |
607 (0x9 << OOB_CTRL2_RESET_IDLE_MIN_SHIFT
));
608 brcm_sata_phy_wr(port
, OOB_REG_BANK
, OOB_CTRL2
, 0x0, val
);
613 static int brcm_dsl_sata_init(struct brcm_sata_port
*port
)
615 struct device
*dev
= port
->phy_priv
->dev
;
619 brcm_sata_phy_wr(port
, PLL1_REG_BANK
, PLL1_ACTRL7
, 0, 0x873);
621 brcm_sata_phy_wr(port
, PLL1_REG_BANK
, PLL1_ACTRL6
, 0, 0xc000);
623 brcm_sata_phy_wr(port
, PLL_REG_BANK_0
, PLL_REG_BANK_0_PLLCONTROL_0
,
625 usleep_range(1000, 2000);
627 brcm_sata_phy_wr(port
, PLL_REG_BANK_0
, PLL_REG_BANK_0_PLLCONTROL_0
,
629 usleep_range(1000, 2000);
631 brcm_sata_phy_wr(port
, AEQRX_REG_BANK_1
, AEQRX_SLCAL0_CTRL0
,
634 brcm_sata_phy_wr(port
, AEQRX_REG_BANK_1
, AEQRX_SLCAL1_CTRL0
,
636 usleep_range(1000, 2000);
638 brcm_sata_phy_wr(port
, PLL_REG_BANK_0
, PLL_CAP_CHARGE_TIME
, 0, 0x32);
640 brcm_sata_phy_wr(port
, PLL_REG_BANK_0
, PLL_VCO_CAL_THRESH
, 0, 0xa);
642 brcm_sata_phy_wr(port
, PLL_REG_BANK_0
, PLL_FREQ_DET_TIME
, 0, 0x64);
643 usleep_range(1000, 2000);
645 /* Acquire PLL lock */
648 tmp
= brcm_sata_phy_rd(port
, BLOCK0_REG_BANK
,
650 if (tmp
& BLOCK0_XGXSSTATUS_PLL_LOCK
)
657 /* PLL did not lock; give up */
658 dev_err(dev
, "port%d PLL did not lock\n", port
->portnum
);
662 dev_dbg(dev
, "port%d initialized\n", port
->portnum
);
667 static int brcm_sata_phy_init(struct phy
*phy
)
670 struct brcm_sata_port
*port
= phy_get_drvdata(phy
);
672 switch (port
->phy_priv
->version
) {
673 case BRCM_SATA_PHY_STB_16NM
:
674 rc
= brcm_stb_sata_16nm_init(port
);
676 case BRCM_SATA_PHY_STB_28NM
:
677 case BRCM_SATA_PHY_STB_40NM
:
678 rc
= brcm_stb_sata_init(port
);
680 case BRCM_SATA_PHY_IPROC_NS2
:
681 rc
= brcm_ns2_sata_init(port
);
683 case BRCM_SATA_PHY_IPROC_NSP
:
684 rc
= brcm_nsp_sata_init(port
);
686 case BRCM_SATA_PHY_IPROC_SR
:
687 rc
= brcm_sr_sata_init(port
);
689 case BRCM_SATA_PHY_DSL_28NM
:
690 rc
= brcm_dsl_sata_init(port
);
699 static void brcm_stb_sata_calibrate(struct brcm_sata_port
*port
)
703 brcm_sata_phy_wr(port
, RXPMD_REG_BANK
, RXPMD_RX_FREQ_MON_CONTROL1
,
707 static int brcm_sata_phy_calibrate(struct phy
*phy
)
709 struct brcm_sata_port
*port
= phy_get_drvdata(phy
);
710 int rc
= -EOPNOTSUPP
;
712 switch (port
->phy_priv
->version
) {
713 case BRCM_SATA_PHY_STB_28NM
:
714 case BRCM_SATA_PHY_STB_40NM
:
715 brcm_stb_sata_calibrate(port
);
725 static const struct phy_ops phy_ops
= {
726 .init
= brcm_sata_phy_init
,
727 .calibrate
= brcm_sata_phy_calibrate
,
728 .owner
= THIS_MODULE
,
731 static const struct of_device_id brcm_sata_phy_of_match
[] = {
732 { .compatible
= "brcm,bcm7216-sata-phy",
733 .data
= (void *)BRCM_SATA_PHY_STB_16NM
},
734 { .compatible
= "brcm,bcm7445-sata-phy",
735 .data
= (void *)BRCM_SATA_PHY_STB_28NM
},
736 { .compatible
= "brcm,bcm7425-sata-phy",
737 .data
= (void *)BRCM_SATA_PHY_STB_40NM
},
738 { .compatible
= "brcm,iproc-ns2-sata-phy",
739 .data
= (void *)BRCM_SATA_PHY_IPROC_NS2
},
740 { .compatible
= "brcm,iproc-nsp-sata-phy",
741 .data
= (void *)BRCM_SATA_PHY_IPROC_NSP
},
742 { .compatible
= "brcm,iproc-sr-sata-phy",
743 .data
= (void *)BRCM_SATA_PHY_IPROC_SR
},
744 { .compatible
= "brcm,bcm63138-sata-phy",
745 .data
= (void *)BRCM_SATA_PHY_DSL_28NM
},
748 MODULE_DEVICE_TABLE(of
, brcm_sata_phy_of_match
);
750 static int brcm_sata_phy_probe(struct platform_device
*pdev
)
752 const char *rxaeq_mode
;
753 struct device
*dev
= &pdev
->dev
;
754 struct device_node
*dn
= dev
->of_node
, *child
;
755 const struct of_device_id
*of_id
;
756 struct brcm_sata_phy
*priv
;
757 struct phy_provider
*provider
;
760 if (of_get_child_count(dn
) == 0)
763 priv
= devm_kzalloc(dev
, sizeof(*priv
), GFP_KERNEL
);
766 dev_set_drvdata(dev
, priv
);
769 priv
->phy_base
= devm_platform_ioremap_resource_byname(pdev
, "phy");
770 if (IS_ERR(priv
->phy_base
))
771 return PTR_ERR(priv
->phy_base
);
773 of_id
= of_match_node(brcm_sata_phy_of_match
, dn
);
775 priv
->version
= (enum brcm_sata_phy_version
)of_id
->data
;
777 priv
->version
= BRCM_SATA_PHY_STB_28NM
;
779 if (priv
->version
== BRCM_SATA_PHY_IPROC_NS2
) {
780 priv
->ctrl_base
= devm_platform_ioremap_resource_byname(pdev
, "phy-ctrl");
781 if (IS_ERR(priv
->ctrl_base
))
782 return PTR_ERR(priv
->ctrl_base
);
785 for_each_available_child_of_node(dn
, child
) {
787 struct brcm_sata_port
*port
;
789 if (of_property_read_u32(child
, "reg", &id
)) {
790 dev_err(dev
, "missing reg property in node %pOFn\n",
796 if (id
>= MAX_PORTS
) {
797 dev_err(dev
, "invalid reg: %u\n", id
);
801 if (priv
->phys
[id
].phy
) {
802 dev_err(dev
, "already registered port %u\n", id
);
807 port
= &priv
->phys
[id
];
809 port
->phy_priv
= priv
;
810 port
->phy
= devm_phy_create(dev
, child
, &phy_ops
);
811 port
->rxaeq_mode
= RXAEQ_MODE_OFF
;
812 if (!of_property_read_string(child
, "brcm,rxaeq-mode",
814 port
->rxaeq_mode
= rxaeq_to_val(rxaeq_mode
);
815 if (port
->rxaeq_mode
== RXAEQ_MODE_MANUAL
)
816 of_property_read_u32(child
, "brcm,rxaeq-value",
819 of_property_read_u32(child
, "brcm,tx-amplitude-millivolt",
820 &port
->tx_amplitude_val
);
822 port
->ssc_en
= of_property_read_bool(child
, "brcm,enable-ssc");
823 if (IS_ERR(port
->phy
)) {
824 dev_err(dev
, "failed to create PHY\n");
825 ret
= PTR_ERR(port
->phy
);
829 phy_set_drvdata(port
->phy
, port
);
833 provider
= devm_of_phy_provider_register(dev
, of_phy_simple_xlate
);
834 if (IS_ERR(provider
)) {
835 dev_err(dev
, "could not register PHY provider\n");
836 return PTR_ERR(provider
);
839 dev_info(dev
, "registered %d port(s)\n", count
);
847 static struct platform_driver brcm_sata_phy_driver
= {
848 .probe
= brcm_sata_phy_probe
,
850 .of_match_table
= brcm_sata_phy_of_match
,
851 .name
= "brcm-sata-phy",
854 module_platform_driver(brcm_sata_phy_driver
);
856 MODULE_DESCRIPTION("Broadcom SATA PHY driver");
857 MODULE_LICENSE("GPL");
858 MODULE_AUTHOR("Marc Carino");
859 MODULE_AUTHOR("Brian Norris");
860 MODULE_ALIAS("platform:phy-brcm-sata");