blob: d2f797c79fbcd2989833d7d788dfd474b65a702e [file] [log] [blame]
Gabriel FERNANDEZ2c14e9b2014-11-04 11:51:19 +01001/*
2 * Copyright (C) 2014 STMicroelectronics
3 *
4 * STMicroelectronics PHY driver MiPHY28lp (for SoC STiH407).
5 *
6 * Author: Alexandre Torgue <alexandre.torgue@st.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2, as
10 * published by the Free Software Foundation.
11 *
12 */
13
14#include <linux/platform_device.h>
15#include <linux/io.h>
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/of.h>
19#include <linux/of_platform.h>
20#include <linux/of_address.h>
21#include <linux/clk.h>
22#include <linux/phy/phy.h>
23#include <linux/delay.h>
24#include <linux/mfd/syscon.h>
25#include <linux/regmap.h>
26#include <linux/reset.h>
27
28#include <dt-bindings/phy/phy.h>
29
30/* MiPHY registers */
31#define MIPHY_CONF_RESET 0x00
32#define RST_APPLI_SW BIT(0)
33#define RST_CONF_SW BIT(1)
34#define RST_MACRO_SW BIT(2)
35
36#define MIPHY_RESET 0x01
37#define RST_PLL_SW BIT(0)
38#define RST_COMP_SW BIT(2)
39
40#define MIPHY_STATUS_1 0x02
41#define PHY_RDY BIT(0)
42#define HFC_RDY BIT(1)
43#define HFC_PLL BIT(2)
44
45#define MIPHY_CONTROL 0x04
46#define TERM_EN_SW BIT(2)
47#define DIS_LINK_RST BIT(3)
48#define AUTO_RST_RX BIT(4)
49#define PX_RX_POL BIT(5)
50
51#define MIPHY_BOUNDARY_SEL 0x0a
52#define TX_SEL BIT(6)
53#define SSC_SEL BIT(4)
54#define GENSEL_SEL BIT(0)
55
56#define MIPHY_BOUNDARY_1 0x0b
57#define MIPHY_BOUNDARY_2 0x0c
58#define SSC_EN_SW BIT(2)
59
60#define MIPHY_PLL_CLKREF_FREQ 0x0d
61#define MIPHY_SPEED 0x0e
62#define TX_SPDSEL_80DEC 0
63#define TX_SPDSEL_40DEC 1
64#define TX_SPDSEL_20DEC 2
65#define RX_SPDSEL_80DEC 0
66#define RX_SPDSEL_40DEC (1 << 2)
67#define RX_SPDSEL_20DEC (2 << 2)
68
69#define MIPHY_CONF 0x0f
70#define MIPHY_CTRL_TEST_SEL 0x20
71#define MIPHY_CTRL_TEST_1 0x21
72#define MIPHY_CTRL_TEST_2 0x22
73#define MIPHY_CTRL_TEST_3 0x23
74#define MIPHY_CTRL_TEST_4 0x24
75#define MIPHY_FEEDBACK_TEST 0x25
76#define MIPHY_DEBUG_BUS 0x26
77#define MIPHY_DEBUG_STATUS_MSB 0x27
78#define MIPHY_DEBUG_STATUS_LSB 0x28
79#define MIPHY_PWR_RAIL_1 0x29
80#define MIPHY_PWR_RAIL_2 0x2a
81#define MIPHY_SYNCHAR_CONTROL 0x30
82
83#define MIPHY_COMP_FSM_1 0x3a
84#define COMP_START BIT(6)
85
86#define MIPHY_COMP_FSM_6 0x3f
87#define COMP_DONE BIT(7)
88
89#define MIPHY_COMP_POSTP 0x42
90#define MIPHY_TX_CTRL_1 0x49
91#define TX_REG_STEP_0V 0
92#define TX_REG_STEP_P_25MV 1
93#define TX_REG_STEP_P_50MV 2
94#define TX_REG_STEP_N_25MV 7
95#define TX_REG_STEP_N_50MV 6
96#define TX_REG_STEP_N_75MV 5
97
98#define MIPHY_TX_CTRL_2 0x4a
99#define TX_SLEW_SW_40_PS 0
100#define TX_SLEW_SW_80_PS 1
101#define TX_SLEW_SW_120_PS 2
102
103#define MIPHY_TX_CTRL_3 0x4b
104#define MIPHY_TX_CAL_MAN 0x4e
105#define TX_SLEW_CAL_MAN_EN BIT(0)
106
107#define MIPHY_TST_BIAS_BOOST_2 0x62
108#define MIPHY_BIAS_BOOST_1 0x63
109#define MIPHY_BIAS_BOOST_2 0x64
110#define MIPHY_RX_DESBUFF_FDB_2 0x67
111#define MIPHY_RX_DESBUFF_FDB_3 0x68
112#define MIPHY_SIGDET_COMPENS1 0x69
113#define MIPHY_SIGDET_COMPENS2 0x6a
114#define MIPHY_JITTER_PERIOD 0x6b
115#define MIPHY_JITTER_AMPLITUDE_1 0x6c
116#define MIPHY_JITTER_AMPLITUDE_2 0x6d
117#define MIPHY_JITTER_AMPLITUDE_3 0x6e
118#define MIPHY_RX_K_GAIN 0x78
119#define MIPHY_RX_BUFFER_CTRL 0x7a
120#define VGA_GAIN BIT(0)
121#define EQ_DC_GAIN BIT(2)
122#define EQ_BOOST_GAIN BIT(3)
123
124#define MIPHY_RX_VGA_GAIN 0x7b
125#define MIPHY_RX_EQU_GAIN_1 0x7f
126#define MIPHY_RX_EQU_GAIN_2 0x80
127#define MIPHY_RX_EQU_GAIN_3 0x81
128#define MIPHY_RX_CAL_CTRL_1 0x97
129#define MIPHY_RX_CAL_CTRL_2 0x98
130
131#define MIPHY_RX_CAL_OFFSET_CTRL 0x99
132#define CAL_OFFSET_VGA_64 (0x03 << 0)
133#define CAL_OFFSET_THRESHOLD_64 (0x03 << 2)
134#define VGA_OFFSET_POLARITY BIT(4)
135#define OFFSET_COMPENSATION_EN BIT(6)
136
137#define MIPHY_RX_CAL_VGA_STEP 0x9a
138#define MIPHY_RX_CAL_EYE_MIN 0x9d
139#define MIPHY_RX_CAL_OPT_LENGTH 0x9f
140#define MIPHY_RX_LOCK_CTRL_1 0xc1
141#define MIPHY_RX_LOCK_SETTINGS_OPT 0xc2
142#define MIPHY_RX_LOCK_STEP 0xc4
143
144#define MIPHY_RX_SIGDET_SLEEP_OA 0xc9
145#define MIPHY_RX_SIGDET_SLEEP_SEL 0xca
146#define MIPHY_RX_SIGDET_WAIT_SEL 0xcb
147#define MIPHY_RX_SIGDET_DATA_SEL 0xcc
148#define EN_ULTRA_LOW_POWER BIT(0)
149#define EN_FIRST_HALF BIT(1)
150#define EN_SECOND_HALF BIT(2)
151#define EN_DIGIT_SIGNAL_CHECK BIT(3)
152
153#define MIPHY_RX_POWER_CTRL_1 0xcd
154#define MIPHY_RX_POWER_CTRL_2 0xce
155#define MIPHY_PLL_CALSET_CTRL 0xd3
156#define MIPHY_PLL_CALSET_1 0xd4
157#define MIPHY_PLL_CALSET_2 0xd5
158#define MIPHY_PLL_CALSET_3 0xd6
159#define MIPHY_PLL_CALSET_4 0xd7
160#define MIPHY_PLL_SBR_1 0xe3
161#define SET_NEW_CHANGE BIT(1)
162
163#define MIPHY_PLL_SBR_2 0xe4
164#define MIPHY_PLL_SBR_3 0xe5
165#define MIPHY_PLL_SBR_4 0xe6
166#define MIPHY_PLL_COMMON_MISC_2 0xe9
167#define START_ACT_FILT BIT(6)
168
169#define MIPHY_PLL_SPAREIN 0xeb
170
171/*
172 * On STiH407 the glue logic can be different among MiPHY devices; for example:
173 * MiPHY0: OSC_FORCE_EXT means:
174 * 0: 30MHz crystal clk - 1: 100MHz ext clk routed through MiPHY1
175 * MiPHY1: OSC_FORCE_EXT means:
176 * 1: 30MHz crystal clk - 0: 100MHz ext clk routed through MiPHY1
177 * Some devices have not the possibility to check if the osc is ready.
178 */
179#define MIPHY_OSC_FORCE_EXT BIT(3)
180#define MIPHY_OSC_RDY BIT(5)
181
182#define MIPHY_CTRL_MASK 0x0f
183#define MIPHY_CTRL_DEFAULT 0
184#define MIPHY_CTRL_SYNC_D_EN BIT(2)
185
186/* SATA / PCIe defines */
187#define SATA_CTRL_MASK 0x07
188#define PCIE_CTRL_MASK 0xff
189#define SATA_CTRL_SELECT_SATA 1
190#define SATA_CTRL_SELECT_PCIE 0
191#define SYSCFG_PCIE_PCIE_VAL 0x80
192#define SATA_SPDMODE 1
193
Gabriel FERNANDEZ2b041b22014-11-04 11:51:21 +0100194#define MIPHY_SATA_BANK_NB 3
195
Gabriel FERNANDEZ2c14e9b2014-11-04 11:51:19 +0100196struct miphy28lp_phy {
197 struct phy *phy;
198 struct miphy28lp_dev *phydev;
199 void __iomem *base;
200 void __iomem *pipebase;
201
202 bool osc_force_ext;
203 bool osc_rdy;
204 bool px_rx_pol_inv;
Gabriel FERNANDEZ2b041b22014-11-04 11:51:21 +0100205 bool ssc;
Gabriel FERNANDEZ2c14e9b2014-11-04 11:51:19 +0100206
207 struct reset_control *miphy_rst;
208
209 u32 sata_gen;
210
211 /* Sysconfig registers offsets needed to configure the device */
212 u32 syscfg_miphy_ctrl;
213 u32 syscfg_miphy_status;
214 u32 syscfg_pci;
215 u32 syscfg_sata;
216 u8 type;
217};
218
219struct miphy28lp_dev {
220 struct device *dev;
221 struct regmap *regmap;
222 struct mutex miphy_mutex;
223 struct miphy28lp_phy **phys;
224};
225
226struct miphy_initval {
227 u16 reg;
228 u16 val;
229};
230
231enum miphy_sata_gen { SATA_GEN1, SATA_GEN2, SATA_GEN3 };
232
233static char *PHY_TYPE_name[] = { "sata-up", "pcie-up", "", "usb3-up" };
234
235struct pll_ratio {
236 int clk_ref;
237 int calset_1;
238 int calset_2;
239 int calset_3;
240 int calset_4;
241 int cal_ctrl;
242};
243
244static struct pll_ratio sata_pll_ratio = {
245 .clk_ref = 0x1e,
246 .calset_1 = 0xc8,
247 .calset_2 = 0x00,
248 .calset_3 = 0x00,
249 .calset_4 = 0x00,
250 .cal_ctrl = 0x00,
251};
252
253static struct pll_ratio pcie_pll_ratio = {
254 .clk_ref = 0x1e,
255 .calset_1 = 0xa6,
256 .calset_2 = 0xaa,
257 .calset_3 = 0xaa,
258 .calset_4 = 0x00,
259 .cal_ctrl = 0x00,
260};
261
262static struct pll_ratio usb3_pll_ratio = {
263 .clk_ref = 0x1e,
264 .calset_1 = 0xa6,
265 .calset_2 = 0xaa,
266 .calset_3 = 0xaa,
267 .calset_4 = 0x04,
268 .cal_ctrl = 0x00,
269};
270
271struct miphy28lp_pll_gen {
272 int bank;
273 int speed;
274 int bias_boost_1;
275 int bias_boost_2;
276 int tx_ctrl_1;
277 int tx_ctrl_2;
278 int tx_ctrl_3;
279 int rx_k_gain;
280 int rx_vga_gain;
281 int rx_equ_gain_1;
282 int rx_equ_gain_2;
283 int rx_equ_gain_3;
284 int rx_buff_ctrl;
285};
286
287static struct miphy28lp_pll_gen sata_pll_gen[] = {
288 {
289 .bank = 0x00,
290 .speed = TX_SPDSEL_80DEC | RX_SPDSEL_80DEC,
291 .bias_boost_1 = 0x00,
292 .bias_boost_2 = 0xae,
293 .tx_ctrl_2 = 0x53,
294 .tx_ctrl_3 = 0x00,
295 .rx_buff_ctrl = EQ_BOOST_GAIN | EQ_DC_GAIN | VGA_GAIN,
296 .rx_vga_gain = 0x00,
297 .rx_equ_gain_1 = 0x7d,
298 .rx_equ_gain_2 = 0x56,
299 .rx_equ_gain_3 = 0x00,
300 },
301 {
302 .bank = 0x01,
303 .speed = TX_SPDSEL_40DEC | RX_SPDSEL_40DEC,
304 .bias_boost_1 = 0x00,
305 .bias_boost_2 = 0xae,
306 .tx_ctrl_2 = 0x72,
307 .tx_ctrl_3 = 0x20,
308 .rx_buff_ctrl = EQ_BOOST_GAIN | EQ_DC_GAIN | VGA_GAIN,
309 .rx_vga_gain = 0x00,
310 .rx_equ_gain_1 = 0x7d,
311 .rx_equ_gain_2 = 0x56,
312 .rx_equ_gain_3 = 0x00,
313 },
314 {
315 .bank = 0x02,
316 .speed = TX_SPDSEL_20DEC | RX_SPDSEL_20DEC,
317 .bias_boost_1 = 0x00,
318 .bias_boost_2 = 0xae,
319 .tx_ctrl_2 = 0xc0,
320 .tx_ctrl_3 = 0x20,
321 .rx_buff_ctrl = EQ_BOOST_GAIN | EQ_DC_GAIN | VGA_GAIN,
322 .rx_vga_gain = 0x00,
323 .rx_equ_gain_1 = 0x7d,
324 .rx_equ_gain_2 = 0x56,
325 .rx_equ_gain_3 = 0x00,
326 },
327};
328
329static struct miphy28lp_pll_gen pcie_pll_gen[] = {
330 {
331 .bank = 0x00,
332 .speed = TX_SPDSEL_40DEC | RX_SPDSEL_40DEC,
333 .bias_boost_1 = 0x00,
334 .bias_boost_2 = 0xa5,
335 .tx_ctrl_1 = TX_REG_STEP_N_25MV,
336 .tx_ctrl_2 = 0x71,
337 .tx_ctrl_3 = 0x60,
338 .rx_k_gain = 0x98,
339 .rx_buff_ctrl = EQ_BOOST_GAIN | EQ_DC_GAIN | VGA_GAIN,
340 .rx_vga_gain = 0x00,
341 .rx_equ_gain_1 = 0x79,
342 .rx_equ_gain_2 = 0x56,
343 },
344 {
345 .bank = 0x01,
346 .speed = TX_SPDSEL_20DEC | RX_SPDSEL_20DEC,
347 .bias_boost_1 = 0x00,
348 .bias_boost_2 = 0xa5,
349 .tx_ctrl_1 = TX_REG_STEP_N_25MV,
350 .tx_ctrl_2 = 0x70,
351 .tx_ctrl_3 = 0x60,
352 .rx_k_gain = 0xcc,
353 .rx_buff_ctrl = EQ_BOOST_GAIN | EQ_DC_GAIN | VGA_GAIN,
354 .rx_vga_gain = 0x00,
355 .rx_equ_gain_1 = 0x78,
356 .rx_equ_gain_2 = 0x07,
357 },
358};
359
360static inline void miphy28lp_set_reset(struct miphy28lp_phy *miphy_phy)
361{
362 void *base = miphy_phy->base;
363 u8 val;
364
365 /* Putting Macro in reset */
366 writeb_relaxed(RST_APPLI_SW, base + MIPHY_CONF_RESET);
367
368 val = RST_APPLI_SW | RST_CONF_SW;
369 writeb_relaxed(val, base + MIPHY_CONF_RESET);
370
371 writeb_relaxed(RST_APPLI_SW, base + MIPHY_CONF_RESET);
372
373 /* Bringing the MIPHY-CPU registers out of reset */
374 if (miphy_phy->type == PHY_TYPE_PCIE) {
375 val = AUTO_RST_RX | TERM_EN_SW;
376 writeb_relaxed(val, base + MIPHY_CONTROL);
377 } else {
378 val = AUTO_RST_RX | TERM_EN_SW | DIS_LINK_RST;
379 writeb_relaxed(val, base + MIPHY_CONTROL);
380 }
381}
382
383static inline void miphy28lp_pll_calibration(struct miphy28lp_phy *miphy_phy,
384 struct pll_ratio *pll_ratio)
385{
386 void *base = miphy_phy->base;
387 u8 val;
388
389 /* Applying PLL Settings */
390 writeb_relaxed(0x1d, base + MIPHY_PLL_SPAREIN);
391 writeb_relaxed(pll_ratio->clk_ref, base + MIPHY_PLL_CLKREF_FREQ);
392
393 /* PLL Ratio */
394 writeb_relaxed(pll_ratio->calset_1, base + MIPHY_PLL_CALSET_1);
395 writeb_relaxed(pll_ratio->calset_2, base + MIPHY_PLL_CALSET_2);
396 writeb_relaxed(pll_ratio->calset_3, base + MIPHY_PLL_CALSET_3);
397 writeb_relaxed(pll_ratio->calset_4, base + MIPHY_PLL_CALSET_4);
398 writeb_relaxed(pll_ratio->cal_ctrl, base + MIPHY_PLL_CALSET_CTRL);
399
400 writeb_relaxed(TX_SEL, base + MIPHY_BOUNDARY_SEL);
401
402 val = (0x68 << 1) | TX_SLEW_CAL_MAN_EN;
403 writeb_relaxed(val, base + MIPHY_TX_CAL_MAN);
404
405 val = VGA_OFFSET_POLARITY | CAL_OFFSET_THRESHOLD_64 | CAL_OFFSET_VGA_64;
406
407 if (miphy_phy->type != PHY_TYPE_SATA)
408 val |= OFFSET_COMPENSATION_EN;
409
410 writeb_relaxed(val, base + MIPHY_RX_CAL_OFFSET_CTRL);
411
412 if (miphy_phy->type == PHY_TYPE_USB3) {
413 writeb_relaxed(0x00, base + MIPHY_CONF);
414 writeb_relaxed(0x70, base + MIPHY_RX_LOCK_STEP);
415 writeb_relaxed(EN_FIRST_HALF, base + MIPHY_RX_SIGDET_SLEEP_OA);
416 writeb_relaxed(EN_FIRST_HALF, base + MIPHY_RX_SIGDET_SLEEP_SEL);
417 writeb_relaxed(EN_FIRST_HALF, base + MIPHY_RX_SIGDET_WAIT_SEL);
418
419 val = EN_DIGIT_SIGNAL_CHECK | EN_FIRST_HALF;
420 writeb_relaxed(val, base + MIPHY_RX_SIGDET_DATA_SEL);
421 }
422
423}
424
425static inline void miphy28lp_sata_config_gen(struct miphy28lp_phy *miphy_phy)
426{
427 void __iomem *base = miphy_phy->base;
428 int i;
429
430 for (i = 0; i < ARRAY_SIZE(sata_pll_gen); i++) {
431 struct miphy28lp_pll_gen *gen = &sata_pll_gen[i];
432
433 /* Banked settings */
434 writeb_relaxed(gen->bank, base + MIPHY_CONF);
435 writeb_relaxed(gen->speed, base + MIPHY_SPEED);
436 writeb_relaxed(gen->bias_boost_1, base + MIPHY_BIAS_BOOST_1);
437 writeb_relaxed(gen->bias_boost_2, base + MIPHY_BIAS_BOOST_2);
438
439 /* TX buffer Settings */
440 writeb_relaxed(gen->tx_ctrl_2, base + MIPHY_TX_CTRL_2);
441 writeb_relaxed(gen->tx_ctrl_3, base + MIPHY_TX_CTRL_3);
442
443 /* RX Buffer Settings */
444 writeb_relaxed(gen->rx_buff_ctrl, base + MIPHY_RX_BUFFER_CTRL);
445 writeb_relaxed(gen->rx_vga_gain, base + MIPHY_RX_VGA_GAIN);
446 writeb_relaxed(gen->rx_equ_gain_1, base + MIPHY_RX_EQU_GAIN_1);
447 writeb_relaxed(gen->rx_equ_gain_2, base + MIPHY_RX_EQU_GAIN_2);
448 writeb_relaxed(gen->rx_equ_gain_3, base + MIPHY_RX_EQU_GAIN_3);
449 }
450}
451
452static inline void miphy28lp_pcie_config_gen(struct miphy28lp_phy *miphy_phy)
453{
454 void __iomem *base = miphy_phy->base;
455 int i;
456
457 for (i = 0; i < ARRAY_SIZE(pcie_pll_gen); i++) {
458 struct miphy28lp_pll_gen *gen = &pcie_pll_gen[i];
459
460 /* Banked settings */
461 writeb_relaxed(gen->bank, base + MIPHY_CONF);
462 writeb_relaxed(gen->speed, base + MIPHY_SPEED);
463 writeb_relaxed(gen->bias_boost_1, base + MIPHY_BIAS_BOOST_1);
464 writeb_relaxed(gen->bias_boost_2, base + MIPHY_BIAS_BOOST_2);
465
466 /* TX buffer Settings */
467 writeb_relaxed(gen->tx_ctrl_1, base + MIPHY_TX_CTRL_1);
468 writeb_relaxed(gen->tx_ctrl_2, base + MIPHY_TX_CTRL_2);
469 writeb_relaxed(gen->tx_ctrl_3, base + MIPHY_TX_CTRL_3);
470
471 writeb_relaxed(gen->rx_k_gain, base + MIPHY_RX_K_GAIN);
472
473 /* RX Buffer Settings */
474 writeb_relaxed(gen->rx_buff_ctrl, base + MIPHY_RX_BUFFER_CTRL);
475 writeb_relaxed(gen->rx_vga_gain, base + MIPHY_RX_VGA_GAIN);
476 writeb_relaxed(gen->rx_equ_gain_1, base + MIPHY_RX_EQU_GAIN_1);
477 writeb_relaxed(gen->rx_equ_gain_2, base + MIPHY_RX_EQU_GAIN_2);
478 }
479}
480
481static inline int miphy28lp_wait_compensation(struct miphy28lp_phy *miphy_phy)
482{
483 unsigned long finish = jiffies + 5 * HZ;
484 u8 val;
485
486 /* Waiting for Compensation to complete */
487 do {
488 val = readb_relaxed(miphy_phy->base + MIPHY_COMP_FSM_6);
489
490 if (time_after_eq(jiffies, finish))
491 return -EBUSY;
492 cpu_relax();
493 } while (!(val & COMP_DONE));
494
495 return 0;
496}
497
498
499static inline int miphy28lp_compensation(struct miphy28lp_phy *miphy_phy,
500 struct pll_ratio *pll_ratio)
501{
502 void __iomem *base = miphy_phy->base;
503
504 /* Poll for HFC ready after reset release */
505 /* Compensation measurement */
506 writeb_relaxed(RST_PLL_SW | RST_COMP_SW, base + MIPHY_RESET);
507
508 writeb_relaxed(0x00, base + MIPHY_PLL_COMMON_MISC_2);
509 writeb_relaxed(pll_ratio->clk_ref, base + MIPHY_PLL_CLKREF_FREQ);
510 writeb_relaxed(COMP_START, base + MIPHY_COMP_FSM_1);
511
512 if (miphy_phy->type == PHY_TYPE_PCIE)
513 writeb_relaxed(RST_PLL_SW, base + MIPHY_RESET);
514
515 writeb_relaxed(0x00, base + MIPHY_RESET);
516 writeb_relaxed(START_ACT_FILT, base + MIPHY_PLL_COMMON_MISC_2);
517 writeb_relaxed(SET_NEW_CHANGE, base + MIPHY_PLL_SBR_1);
518
519 /* TX compensation offset to re-center TX impedance */
520 writeb_relaxed(0x00, base + MIPHY_COMP_POSTP);
521
522 if (miphy_phy->type == PHY_TYPE_PCIE)
523 return miphy28lp_wait_compensation(miphy_phy);
524
525 return 0;
526}
527
528static inline void miphy28_usb3_miphy_reset(struct miphy28lp_phy *miphy_phy)
529{
530 void __iomem *base = miphy_phy->base;
531 u8 val;
532
533 /* MIPHY Reset */
534 writeb_relaxed(RST_APPLI_SW, base + MIPHY_CONF_RESET);
535 writeb_relaxed(0x00, base + MIPHY_CONF_RESET);
536 writeb_relaxed(RST_COMP_SW, base + MIPHY_RESET);
537
538 val = RST_COMP_SW | RST_PLL_SW;
539 writeb_relaxed(val, base + MIPHY_RESET);
540
541 writeb_relaxed(0x00, base + MIPHY_PLL_COMMON_MISC_2);
542 writeb_relaxed(0x1e, base + MIPHY_PLL_CLKREF_FREQ);
543 writeb_relaxed(COMP_START, base + MIPHY_COMP_FSM_1);
544 writeb_relaxed(RST_PLL_SW, base + MIPHY_RESET);
545 writeb_relaxed(0x00, base + MIPHY_RESET);
546 writeb_relaxed(START_ACT_FILT, base + MIPHY_PLL_COMMON_MISC_2);
547 writeb_relaxed(0x00, base + MIPHY_CONF);
548 writeb_relaxed(0x00, base + MIPHY_BOUNDARY_1);
549 writeb_relaxed(0x00, base + MIPHY_TST_BIAS_BOOST_2);
550 writeb_relaxed(0x00, base + MIPHY_CONF);
551 writeb_relaxed(SET_NEW_CHANGE, base + MIPHY_PLL_SBR_1);
552 writeb_relaxed(0xa5, base + MIPHY_DEBUG_BUS);
553 writeb_relaxed(0x00, base + MIPHY_CONF);
554}
555
Gabriel FERNANDEZ2b041b22014-11-04 11:51:21 +0100556static void miphy_sata_tune_ssc(struct miphy28lp_phy *miphy_phy)
557{
558 void __iomem *base = miphy_phy->base;
559 u8 val;
560
561 /* Compensate Tx impedance to avoid out of range values */
562 /*
563 * Enable the SSC on PLL for all banks
564 * SSC Modulation @ 31 KHz and 4000 ppm modulation amp
565 */
566 val = readb_relaxed(base + MIPHY_BOUNDARY_2);
567 val |= SSC_EN_SW;
568 writeb_relaxed(val, base + MIPHY_BOUNDARY_2);
569
570 val = readb_relaxed(base + MIPHY_BOUNDARY_SEL);
571 val |= SSC_SEL;
572 writeb_relaxed(val, base + MIPHY_BOUNDARY_SEL);
573
574 for (val = 0; val < MIPHY_SATA_BANK_NB; val++) {
575 writeb_relaxed(val, base + MIPHY_CONF);
576
577 /* Add value to each reference clock cycle */
578 /* and define the period length of the SSC */
579 writeb_relaxed(0x3c, base + MIPHY_PLL_SBR_2);
580 writeb_relaxed(0x6c, base + MIPHY_PLL_SBR_3);
581 writeb_relaxed(0x81, base + MIPHY_PLL_SBR_4);
582
583 /* Clear any previous request */
584 writeb_relaxed(0x00, base + MIPHY_PLL_SBR_1);
585
586 /* requests the PLL to take in account new parameters */
587 writeb_relaxed(SET_NEW_CHANGE, base + MIPHY_PLL_SBR_1);
588
589 /* To be sure there is no other pending requests */
590 writeb_relaxed(0x00, base + MIPHY_PLL_SBR_1);
591 }
592}
593
Gabriel FERNANDEZ2c14e9b2014-11-04 11:51:19 +0100594static inline int miphy28lp_configure_sata(struct miphy28lp_phy *miphy_phy)
595{
596 void __iomem *base = miphy_phy->base;
597 int err;
598 u8 val;
599
600 /* Putting Macro in reset */
601 miphy28lp_set_reset(miphy_phy);
602
603 /* PLL calibration */
604 miphy28lp_pll_calibration(miphy_phy, &sata_pll_ratio);
605
606 /* Banked settings Gen1/Gen2/Gen3 */
607 miphy28lp_sata_config_gen(miphy_phy);
608
609 /* Power control */
610 /* Input bridge enable, manual input bridge control */
611 writeb_relaxed(0x21, base + MIPHY_RX_POWER_CTRL_1);
612
613 /* Macro out of reset */
614 writeb_relaxed(0x00, base + MIPHY_CONF_RESET);
615
616 /* Poll for HFC ready after reset release */
617 /* Compensation measurement */
618 err = miphy28lp_compensation(miphy_phy, &sata_pll_ratio);
619 if (err)
620 return err;
621
622 if (miphy_phy->px_rx_pol_inv) {
623 /* Invert Rx polarity */
624 val = readb_relaxed(miphy_phy->base + MIPHY_CONTROL);
625 val |= PX_RX_POL;
626 writeb_relaxed(val, miphy_phy->base + MIPHY_CONTROL);
627 }
628
Gabriel FERNANDEZ2b041b22014-11-04 11:51:21 +0100629 if (miphy_phy->ssc)
630 miphy_sata_tune_ssc(miphy_phy);
631
Gabriel FERNANDEZ2c14e9b2014-11-04 11:51:19 +0100632 return 0;
633}
634
635static inline int miphy28lp_configure_pcie(struct miphy28lp_phy *miphy_phy)
636{
637 void __iomem *base = miphy_phy->base;
638 int err;
639
640 /* Putting Macro in reset */
641 miphy28lp_set_reset(miphy_phy);
642
643 /* PLL calibration */
644 miphy28lp_pll_calibration(miphy_phy, &pcie_pll_ratio);
645
646 /* Banked settings Gen1/Gen2 */
647 miphy28lp_pcie_config_gen(miphy_phy);
648
649 /* Power control */
650 /* Input bridge enable, manual input bridge control */
651 writeb_relaxed(0x21, base + MIPHY_RX_POWER_CTRL_1);
652
653 /* Macro out of reset */
654 writeb_relaxed(0x00, base + MIPHY_CONF_RESET);
655
656 /* Poll for HFC ready after reset release */
657 /* Compensation measurement */
658 err = miphy28lp_compensation(miphy_phy, &pcie_pll_ratio);
659 if (err)
660 return err;
661
662 return 0;
663}
664
665
666static inline void miphy28lp_configure_usb3(struct miphy28lp_phy *miphy_phy)
667{
668 void __iomem *base = miphy_phy->base;
669 u8 val;
670
671 /* Putting Macro in reset */
672 miphy28lp_set_reset(miphy_phy);
673
674 /* PLL calibration */
675 miphy28lp_pll_calibration(miphy_phy, &usb3_pll_ratio);
676
677 /* Writing The Speed Rate */
678 writeb_relaxed(0x00, base + MIPHY_CONF);
679
680 val = RX_SPDSEL_20DEC | TX_SPDSEL_20DEC;
681 writeb_relaxed(val, base + MIPHY_SPEED);
682
683 /* RX Channel compensation and calibration */
684 writeb_relaxed(0x1c, base + MIPHY_RX_LOCK_SETTINGS_OPT);
685 writeb_relaxed(0x51, base + MIPHY_RX_CAL_CTRL_1);
686 writeb_relaxed(0x70, base + MIPHY_RX_CAL_CTRL_2);
687
688 val = OFFSET_COMPENSATION_EN | VGA_OFFSET_POLARITY |
689 CAL_OFFSET_THRESHOLD_64 | CAL_OFFSET_VGA_64;
690 writeb_relaxed(val, base + MIPHY_RX_CAL_OFFSET_CTRL);
691 writeb_relaxed(0x22, base + MIPHY_RX_CAL_VGA_STEP);
692 writeb_relaxed(0x0e, base + MIPHY_RX_CAL_OPT_LENGTH);
693
694 val = EQ_DC_GAIN | VGA_GAIN;
695 writeb_relaxed(val, base + MIPHY_RX_BUFFER_CTRL);
696 writeb_relaxed(0x78, base + MIPHY_RX_EQU_GAIN_1);
697 writeb_relaxed(0x1b, base + MIPHY_SYNCHAR_CONTROL);
698
699 /* TX compensation offset to re-center TX impedance */
700 writeb_relaxed(0x02, base + MIPHY_COMP_POSTP);
701
702 /* Enable GENSEL_SEL and SSC */
703 /* TX_SEL=0 swing preemp forced by pipe registres */
704 val = SSC_SEL | GENSEL_SEL;
705 writeb_relaxed(val, base + MIPHY_BOUNDARY_SEL);
706
707 /* MIPHY Bias boost */
708 writeb_relaxed(0x00, base + MIPHY_BIAS_BOOST_1);
709 writeb_relaxed(0xa7, base + MIPHY_BIAS_BOOST_2);
710
711 /* SSC modulation */
712 writeb_relaxed(SSC_EN_SW, base + MIPHY_BOUNDARY_2);
713
714 /* MIPHY TX control */
715 writeb_relaxed(0x00, base + MIPHY_CONF);
716
717 /* Validate Step component */
718 writeb_relaxed(0x5a, base + MIPHY_PLL_SBR_3);
719 writeb_relaxed(0xa0, base + MIPHY_PLL_SBR_4);
720
721 /* Validate Period component */
722 writeb_relaxed(0x3c, base + MIPHY_PLL_SBR_2);
723 writeb_relaxed(0xa1, base + MIPHY_PLL_SBR_4);
724
725 /* Clear any previous request */
726 writeb_relaxed(0x00, base + MIPHY_PLL_SBR_1);
727
728 /* requests the PLL to take in account new parameters */
729 writeb_relaxed(0x02, base + MIPHY_PLL_SBR_1);
730
731 /* To be sure there is no other pending requests */
732 writeb_relaxed(0x00, base + MIPHY_PLL_SBR_1);
733
734 /* Rx PI controller settings */
735 writeb_relaxed(0xca, base + MIPHY_RX_K_GAIN);
736
737 /* MIPHY RX input bridge control */
738 /* INPUT_BRIDGE_EN_SW=1, manual input bridge control[0]=1 */
739 writeb_relaxed(0x21, base + MIPHY_RX_POWER_CTRL_1);
740 writeb_relaxed(0x29, base + MIPHY_RX_POWER_CTRL_1);
741 writeb_relaxed(0x1a, base + MIPHY_RX_POWER_CTRL_2);
742
743 /* MIPHY Reset for usb3 */
744 miphy28_usb3_miphy_reset(miphy_phy);
745}
746
747static inline int miphy_is_ready(struct miphy28lp_phy *miphy_phy)
748{
749 unsigned long finish = jiffies + 5 * HZ;
750 u8 mask = HFC_PLL | HFC_RDY;
751 u8 val;
752
753 /*
754 * For PCIe and USB3 check only that PLL and HFC are ready
755 * For SATA check also that phy is ready!
756 */
757 if (miphy_phy->type == PHY_TYPE_SATA)
758 mask |= PHY_RDY;
759
760 do {
761 val = readb_relaxed(miphy_phy->base + MIPHY_STATUS_1);
762 if ((val & mask) != mask)
763 cpu_relax();
764 else
765 return 0;
766 } while (!time_after_eq(jiffies, finish));
767
768 return -EBUSY;
769}
770
771static int miphy_osc_is_ready(struct miphy28lp_phy *miphy_phy)
772{
773 struct miphy28lp_dev *miphy_dev = miphy_phy->phydev;
774 unsigned long finish = jiffies + 5 * HZ;
775 u32 val;
776
777 if (!miphy_phy->osc_rdy)
778 return 0;
779
780 if (!miphy_phy->syscfg_miphy_status)
781 return -EINVAL;
782
783 do {
784 regmap_read(miphy_dev->regmap, miphy_phy->syscfg_miphy_status,
785 &val);
786
787 if ((val & MIPHY_OSC_RDY) != MIPHY_OSC_RDY)
788 cpu_relax();
789 else
790 return 0;
791 } while (!time_after_eq(jiffies, finish));
792
793 return -EBUSY;
794}
795
796static int miphy28lp_get_resource_byname(struct device_node *child,
797 char *rname, struct resource *res)
798{
799 int index;
800
801 index = of_property_match_string(child, "reg-names", rname);
802 if (index < 0)
803 return -ENODEV;
804
805 return of_address_to_resource(child, index, res);
806}
807
808static int miphy28lp_get_one_addr(struct device *dev,
809 struct device_node *child, char *rname,
810 void __iomem **base)
811{
812 struct resource res;
813 int ret;
814
815 ret = miphy28lp_get_resource_byname(child, rname, &res);
816 if (!ret) {
817 *base = devm_ioremap(dev, res.start, resource_size(&res));
818 if (!*base) {
819 dev_err(dev, "failed to ioremap %s address region\n"
820 , rname);
821 return -ENOENT;
822 }
823 }
824
825 return 0;
826}
827
828/* MiPHY reset and sysconf setup */
829static int miphy28lp_setup(struct miphy28lp_phy *miphy_phy, u32 miphy_val)
830{
831 int err;
832 struct miphy28lp_dev *miphy_dev = miphy_phy->phydev;
833
834 if (!miphy_phy->syscfg_miphy_ctrl)
835 return -EINVAL;
836
837 err = reset_control_assert(miphy_phy->miphy_rst);
838 if (err) {
839 dev_err(miphy_dev->dev, "unable to bring out of miphy reset\n");
840 return err;
841 }
842
843 if (miphy_phy->osc_force_ext)
844 miphy_val |= MIPHY_OSC_FORCE_EXT;
845
846 regmap_update_bits(miphy_dev->regmap, miphy_phy->syscfg_miphy_ctrl,
847 MIPHY_CTRL_MASK, miphy_val);
848
849 err = reset_control_deassert(miphy_phy->miphy_rst);
850 if (err) {
851 dev_err(miphy_dev->dev, "unable to bring out of miphy reset\n");
852 return err;
853 }
854
855 return miphy_osc_is_ready(miphy_phy);
856}
857
858static int miphy28lp_init_sata(struct miphy28lp_phy *miphy_phy)
859{
860 struct miphy28lp_dev *miphy_dev = miphy_phy->phydev;
861 int err, sata_conf = SATA_CTRL_SELECT_SATA;
862
863 if ((!miphy_phy->syscfg_sata) || (!miphy_phy->syscfg_pci)
864 || (!miphy_phy->base))
865 return -EINVAL;
866
867 dev_info(miphy_dev->dev, "sata-up mode, addr 0x%p\n", miphy_phy->base);
868
869 /* Configure the glue-logic */
870 sata_conf |= ((miphy_phy->sata_gen - SATA_GEN1) << SATA_SPDMODE);
871
872 regmap_update_bits(miphy_dev->regmap, miphy_phy->syscfg_sata,
873 SATA_CTRL_MASK, sata_conf);
874
875 regmap_update_bits(miphy_dev->regmap, miphy_phy->syscfg_pci,
876 PCIE_CTRL_MASK, SATA_CTRL_SELECT_PCIE);
877
878 /* MiPHY path and clocking init */
879 err = miphy28lp_setup(miphy_phy, MIPHY_CTRL_DEFAULT);
880
881 if (err) {
882 dev_err(miphy_dev->dev, "SATA phy setup failed\n");
883 return err;
884 }
885
886 /* initialize miphy */
887 miphy28lp_configure_sata(miphy_phy);
888
889 return miphy_is_ready(miphy_phy);
890}
891
892static int miphy28lp_init_pcie(struct miphy28lp_phy *miphy_phy)
893{
894 struct miphy28lp_dev *miphy_dev = miphy_phy->phydev;
895 int err;
896
897 if ((!miphy_phy->syscfg_sata) || (!miphy_phy->syscfg_pci)
898 || (!miphy_phy->base) || (!miphy_phy->pipebase))
899 return -EINVAL;
900
901 dev_info(miphy_dev->dev, "pcie-up mode, addr 0x%p\n", miphy_phy->base);
902
903 /* Configure the glue-logic */
904 regmap_update_bits(miphy_dev->regmap, miphy_phy->syscfg_sata,
905 SATA_CTRL_MASK, SATA_CTRL_SELECT_PCIE);
906
907 regmap_update_bits(miphy_dev->regmap, miphy_phy->syscfg_pci,
908 PCIE_CTRL_MASK, SYSCFG_PCIE_PCIE_VAL);
909
910 /* MiPHY path and clocking init */
911 err = miphy28lp_setup(miphy_phy, MIPHY_CTRL_DEFAULT);
912
913 if (err) {
914 dev_err(miphy_dev->dev, "PCIe phy setup failed\n");
915 return err;
916 }
917
918 /* initialize miphy */
919 err = miphy28lp_configure_pcie(miphy_phy);
920 if (err)
921 return err;
922
923 /* PIPE Wrapper Configuration */
924 writeb_relaxed(0x68, miphy_phy->pipebase + 0x104); /* Rise_0 */
925 writeb_relaxed(0x61, miphy_phy->pipebase + 0x105); /* Rise_1 */
926 writeb_relaxed(0x68, miphy_phy->pipebase + 0x108); /* Fall_0 */
927 writeb_relaxed(0x61, miphy_phy->pipebase + 0x109); /* Fall-1 */
928 writeb_relaxed(0x68, miphy_phy->pipebase + 0x10c); /* Threshold_0 */
929 writeb_relaxed(0x60, miphy_phy->pipebase + 0x10d); /* Threshold_1 */
930
931 /* Wait for phy_ready */
932 return miphy_is_ready(miphy_phy);
933}
934
935static int miphy28lp_init_usb3(struct miphy28lp_phy *miphy_phy)
936{
937 struct miphy28lp_dev *miphy_dev = miphy_phy->phydev;
938 int err;
939
940 if ((!miphy_phy->base) || (!miphy_phy->pipebase))
941 return -EINVAL;
942
943 dev_info(miphy_dev->dev, "usb3-up mode, addr 0x%p\n", miphy_phy->base);
944
945 /* MiPHY path and clocking init */
946 err = miphy28lp_setup(miphy_phy, MIPHY_CTRL_SYNC_D_EN);
947 if (err) {
948 dev_err(miphy_dev->dev, "USB3 phy setup failed\n");
949 return err;
950 }
951
952 /* initialize miphy */
953 miphy28lp_configure_usb3(miphy_phy);
954
955 /* PIPE Wrapper Configuration */
956 writeb_relaxed(0x68, miphy_phy->pipebase + 0x23);
957 writeb_relaxed(0x61, miphy_phy->pipebase + 0x24);
958 writeb_relaxed(0x68, miphy_phy->pipebase + 0x26);
959 writeb_relaxed(0x61, miphy_phy->pipebase + 0x27);
960 writeb_relaxed(0x18, miphy_phy->pipebase + 0x29);
961 writeb_relaxed(0x61, miphy_phy->pipebase + 0x2a);
962
963 /* pipe Wrapper usb3 TX swing de-emph margin PREEMPH[7:4], SWING[3:0] */
964 writeb_relaxed(0X67, miphy_phy->pipebase + 0x68);
965 writeb_relaxed(0x0d, miphy_phy->pipebase + 0x69);
966 writeb_relaxed(0X67, miphy_phy->pipebase + 0x6a);
967 writeb_relaxed(0X0d, miphy_phy->pipebase + 0x6b);
968 writeb_relaxed(0X67, miphy_phy->pipebase + 0x6c);
969 writeb_relaxed(0X0d, miphy_phy->pipebase + 0x6d);
970 writeb_relaxed(0X67, miphy_phy->pipebase + 0x6e);
971 writeb_relaxed(0X0d, miphy_phy->pipebase + 0x6f);
972
973 return miphy_is_ready(miphy_phy);
974}
975
976static int miphy28lp_init(struct phy *phy)
977{
978 struct miphy28lp_phy *miphy_phy = phy_get_drvdata(phy);
979 struct miphy28lp_dev *miphy_dev = miphy_phy->phydev;
980 int ret;
981
982 mutex_lock(&miphy_dev->miphy_mutex);
983
984 switch (miphy_phy->type) {
985
986 case PHY_TYPE_SATA:
987 ret = miphy28lp_init_sata(miphy_phy);
988 break;
989 case PHY_TYPE_PCIE:
990 ret = miphy28lp_init_pcie(miphy_phy);
991 break;
992 case PHY_TYPE_USB3:
993 ret = miphy28lp_init_usb3(miphy_phy);
994 break;
995 default:
996 return -EINVAL;
997 }
998
999 mutex_unlock(&miphy_dev->miphy_mutex);
1000
1001 return ret;
1002}
1003
1004static int miphy28lp_get_addr(struct miphy28lp_phy *miphy_phy)
1005{
1006 struct miphy28lp_dev *miphy_dev = miphy_phy->phydev;
1007 struct device_node *phynode = miphy_phy->phy->dev.of_node;
1008 int err;
1009
1010 if ((miphy_phy->type != PHY_TYPE_SATA) &&
1011 (miphy_phy->type != PHY_TYPE_PCIE) &&
1012 (miphy_phy->type != PHY_TYPE_USB3)) {
1013 return -EINVAL;
1014 }
1015
1016 err = miphy28lp_get_one_addr(miphy_dev->dev, phynode,
1017 PHY_TYPE_name[miphy_phy->type - PHY_TYPE_SATA],
1018 &miphy_phy->base);
1019 if (err)
1020 return err;
1021
1022 if ((miphy_phy->type == PHY_TYPE_PCIE) ||
1023 (miphy_phy->type == PHY_TYPE_USB3)) {
1024 err = miphy28lp_get_one_addr(miphy_dev->dev, phynode, "pipew",
1025 &miphy_phy->pipebase);
1026 if (err)
1027 return err;
1028 }
1029
1030 return 0;
1031}
1032
1033static struct phy *miphy28lp_xlate(struct device *dev,
1034 struct of_phandle_args *args)
1035{
1036 struct miphy28lp_dev *miphy_dev = dev_get_drvdata(dev);
1037 struct miphy28lp_phy *miphy_phy = NULL;
1038 struct device_node *phynode = args->np;
1039 int ret, index = 0;
1040
1041 if (!of_device_is_available(phynode)) {
1042 dev_warn(dev, "Requested PHY is disabled\n");
1043 return ERR_PTR(-ENODEV);
1044 }
1045
1046 if (args->args_count != 1) {
1047 dev_err(dev, "Invalid number of cells in 'phy' property\n");
1048 return ERR_PTR(-EINVAL);
1049 }
1050
1051 for (index = 0; index < of_get_child_count(dev->of_node); index++)
1052 if (phynode == miphy_dev->phys[index]->phy->dev.of_node) {
1053 miphy_phy = miphy_dev->phys[index];
1054 break;
1055 }
1056
1057 if (!miphy_phy) {
1058 dev_err(dev, "Failed to find appropriate phy\n");
1059 return ERR_PTR(-EINVAL);
1060 }
1061
1062 miphy_phy->type = args->args[0];
1063
1064 ret = miphy28lp_get_addr(miphy_phy);
1065 if (ret < 0)
1066 return ERR_PTR(ret);
1067
1068 return miphy_phy->phy;
1069}
1070
1071static struct phy_ops miphy28lp_ops = {
1072 .init = miphy28lp_init,
1073};
1074
1075static int miphy28lp_probe_resets(struct device_node *node,
1076 struct miphy28lp_phy *miphy_phy)
1077{
1078 struct miphy28lp_dev *miphy_dev = miphy_phy->phydev;
1079 int err;
1080
1081 miphy_phy->miphy_rst = of_reset_control_get(node, "miphy-sw-rst");
1082
1083 if (IS_ERR(miphy_phy->miphy_rst)) {
1084 dev_err(miphy_dev->dev,
1085 "miphy soft reset control not defined\n");
1086 return PTR_ERR(miphy_phy->miphy_rst);
1087 }
1088
1089 err = reset_control_deassert(miphy_phy->miphy_rst);
1090 if (err) {
1091 dev_err(miphy_dev->dev, "unable to bring out of miphy reset\n");
1092 return err;
1093 }
1094
1095 return 0;
1096}
1097
1098static int miphy28lp_of_probe(struct device_node *np,
1099 struct miphy28lp_phy *miphy_phy)
1100{
1101 struct resource res;
1102
1103 miphy_phy->osc_force_ext =
1104 of_property_read_bool(np, "st,osc-force-ext");
1105
1106 miphy_phy->osc_rdy = of_property_read_bool(np, "st,osc-rdy");
1107
1108 miphy_phy->px_rx_pol_inv =
1109 of_property_read_bool(np, "st,px_rx_pol_inv");
1110
Gabriel FERNANDEZ2b041b22014-11-04 11:51:21 +01001111 miphy_phy->ssc = of_property_read_bool(np, "st,ssc-on");
1112
Gabriel FERNANDEZ2c14e9b2014-11-04 11:51:19 +01001113 of_property_read_u32(np, "st,sata-gen", &miphy_phy->sata_gen);
1114 if (!miphy_phy->sata_gen)
1115 miphy_phy->sata_gen = SATA_GEN1;
1116
1117 if (!miphy28lp_get_resource_byname(np, "miphy-ctrl-glue", &res))
1118 miphy_phy->syscfg_miphy_ctrl = res.start;
1119
1120 if (!miphy28lp_get_resource_byname(np, "miphy-status-glue", &res))
1121 miphy_phy->syscfg_miphy_status = res.start;
1122
1123 if (!miphy28lp_get_resource_byname(np, "pcie-glue", &res))
1124 miphy_phy->syscfg_pci = res.start;
1125
1126 if (!miphy28lp_get_resource_byname(np, "sata-glue", &res))
1127 miphy_phy->syscfg_sata = res.start;
1128
1129
1130 return 0;
1131}
1132
1133static int miphy28lp_probe(struct platform_device *pdev)
1134{
1135 struct device_node *child, *np = pdev->dev.of_node;
1136 struct miphy28lp_dev *miphy_dev;
1137 struct phy_provider *provider;
1138 struct phy *phy;
1139 int chancount, port = 0;
1140 int ret;
1141
1142 miphy_dev = devm_kzalloc(&pdev->dev, sizeof(*miphy_dev), GFP_KERNEL);
1143 if (!miphy_dev)
1144 return -ENOMEM;
1145
1146 chancount = of_get_child_count(np);
1147 miphy_dev->phys = devm_kzalloc(&pdev->dev, sizeof(phy) * chancount,
1148 GFP_KERNEL);
1149 if (!miphy_dev->phys)
1150 return -ENOMEM;
1151
1152 miphy_dev->regmap = syscon_regmap_lookup_by_phandle(np, "st,syscfg");
1153 if (IS_ERR(miphy_dev->regmap)) {
1154 dev_err(miphy_dev->dev, "No syscfg phandle specified\n");
1155 return PTR_ERR(miphy_dev->regmap);
1156 }
1157
1158 miphy_dev->dev = &pdev->dev;
1159
1160 dev_set_drvdata(&pdev->dev, miphy_dev);
1161
1162 mutex_init(&miphy_dev->miphy_mutex);
1163
1164 for_each_child_of_node(np, child) {
1165 struct miphy28lp_phy *miphy_phy;
1166
1167 miphy_phy = devm_kzalloc(&pdev->dev, sizeof(*miphy_phy),
1168 GFP_KERNEL);
1169 if (!miphy_phy)
1170 return -ENOMEM;
1171
1172 miphy_dev->phys[port] = miphy_phy;
1173
1174 phy = devm_phy_create(&pdev->dev, child, &miphy28lp_ops, NULL);
1175 if (IS_ERR(phy)) {
1176 dev_err(&pdev->dev, "failed to create PHY\n");
1177 return PTR_ERR(phy);
1178 }
1179
1180 miphy_dev->phys[port]->phy = phy;
1181 miphy_dev->phys[port]->phydev = miphy_dev;
1182
1183 ret = miphy28lp_of_probe(child, miphy_phy);
1184 if (ret)
1185 return ret;
1186
1187 ret = miphy28lp_probe_resets(child, miphy_dev->phys[port]);
1188 if (ret)
1189 return ret;
1190
1191 phy_set_drvdata(phy, miphy_dev->phys[port]);
1192 port++;
1193
1194 }
1195
1196 provider = devm_of_phy_provider_register(&pdev->dev, miphy28lp_xlate);
1197 if (IS_ERR(provider))
1198 return PTR_ERR(provider);
1199
1200 return 0;
1201}
1202
1203static const struct of_device_id miphy28lp_of_match[] = {
1204 {.compatible = "st,miphy28lp-phy", },
1205 {},
1206};
1207
1208MODULE_DEVICE_TABLE(of, miphy28lp_of_match);
1209
1210static struct platform_driver miphy28lp_driver = {
1211 .probe = miphy28lp_probe,
1212 .driver = {
1213 .name = "miphy28lp-phy",
1214 .owner = THIS_MODULE,
1215 .of_match_table = miphy28lp_of_match,
1216 }
1217};
1218
1219module_platform_driver(miphy28lp_driver);
1220
1221MODULE_AUTHOR("Alexandre Torgue <alexandre.torgue@st.com>");
1222MODULE_DESCRIPTION("STMicroelectronics miphy28lp driver");
1223MODULE_LICENSE("GPL v2");