phy-miphy365x.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. /*
  2. * Copyright (C) 2014 STMicroelectronics – All Rights Reserved
  3. *
  4. * STMicroelectronics PHY driver MiPHY365 (for SoC STiH416).
  5. *
  6. * Authors: Alexandre Torgue <alexandre.torgue@st.com>
  7. * Lee Jones <lee.jones@linaro.org>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2, as
  11. * published by the Free Software Foundation.
  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 <dt-bindings/phy/phy.h>
  27. #define HFC_TIMEOUT 100
  28. #define SYSCFG_SELECT_SATA_MASK BIT(1)
  29. #define SYSCFG_SELECT_SATA_POS 1
  30. /* MiPHY365x register definitions */
  31. #define RESET_REG 0x00
  32. #define RST_PLL BIT(1)
  33. #define RST_PLL_CAL BIT(2)
  34. #define RST_RX BIT(4)
  35. #define RST_MACRO BIT(7)
  36. #define STATUS_REG 0x01
  37. #define IDLL_RDY BIT(0)
  38. #define PLL_RDY BIT(1)
  39. #define DES_BIT_LOCK BIT(2)
  40. #define DES_SYMBOL_LOCK BIT(3)
  41. #define CTRL_REG 0x02
  42. #define TERM_EN BIT(0)
  43. #define PCI_EN BIT(2)
  44. #define DES_BIT_LOCK_EN BIT(3)
  45. #define TX_POL BIT(5)
  46. #define INT_CTRL_REG 0x03
  47. #define BOUNDARY1_REG 0x10
  48. #define SPDSEL_SEL BIT(0)
  49. #define BOUNDARY3_REG 0x12
  50. #define TX_SPDSEL_GEN1_VAL 0
  51. #define TX_SPDSEL_GEN2_VAL 0x01
  52. #define TX_SPDSEL_GEN3_VAL 0x02
  53. #define RX_SPDSEL_GEN1_VAL 0
  54. #define RX_SPDSEL_GEN2_VAL (0x01 << 3)
  55. #define RX_SPDSEL_GEN3_VAL (0x02 << 3)
  56. #define PCIE_REG 0x16
  57. #define BUF_SEL_REG 0x20
  58. #define CONF_GEN_SEL_GEN3 0x02
  59. #define CONF_GEN_SEL_GEN2 0x01
  60. #define PD_VDDTFILTER BIT(4)
  61. #define TXBUF1_REG 0x21
  62. #define SWING_VAL 0x04
  63. #define SWING_VAL_GEN1 0x03
  64. #define PREEMPH_VAL (0x3 << 5)
  65. #define TXBUF2_REG 0x22
  66. #define TXSLEW_VAL 0x2
  67. #define TXSLEW_VAL_GEN1 0x4
  68. #define RXBUF_OFFSET_CTRL_REG 0x23
  69. #define RXBUF_REG 0x25
  70. #define SDTHRES_VAL 0x01
  71. #define EQ_ON3 (0x03 << 4)
  72. #define EQ_ON1 (0x01 << 4)
  73. #define COMP_CTRL1_REG 0x40
  74. #define START_COMSR BIT(0)
  75. #define START_COMZC BIT(1)
  76. #define COMSR_DONE BIT(2)
  77. #define COMZC_DONE BIT(3)
  78. #define COMP_AUTO_LOAD BIT(4)
  79. #define COMP_CTRL2_REG 0x41
  80. #define COMP_2MHZ_RAT_GEN1 0x1e
  81. #define COMP_2MHZ_RAT 0xf
  82. #define COMP_CTRL3_REG 0x42
  83. #define COMSR_COMP_REF 0x33
  84. #define COMP_IDLL_REG 0x47
  85. #define COMZC_IDLL 0x2a
  86. #define PLL_CTRL1_REG 0x50
  87. #define PLL_START_CAL BIT(0)
  88. #define BUF_EN BIT(2)
  89. #define SYNCHRO_TX BIT(3)
  90. #define SSC_EN BIT(6)
  91. #define CONFIG_PLL BIT(7)
  92. #define PLL_CTRL2_REG 0x51
  93. #define BYPASS_PLL_CAL BIT(1)
  94. #define PLL_RAT_REG 0x52
  95. #define PLL_SSC_STEP_MSB_REG 0x56
  96. #define PLL_SSC_STEP_MSB_VAL 0x03
  97. #define PLL_SSC_STEP_LSB_REG 0x57
  98. #define PLL_SSC_STEP_LSB_VAL 0x63
  99. #define PLL_SSC_PER_MSB_REG 0x58
  100. #define PLL_SSC_PER_MSB_VAL 0
  101. #define PLL_SSC_PER_LSB_REG 0x59
  102. #define PLL_SSC_PER_LSB_VAL 0xf1
  103. #define IDLL_TEST_REG 0x72
  104. #define START_CLK_HF BIT(6)
  105. #define DES_BITLOCK_REG 0x86
  106. #define BIT_LOCK_LEVEL 0x01
  107. #define BIT_LOCK_CNT_512 (0x03 << 5)
  108. struct miphy365x_phy {
  109. struct phy *phy;
  110. void __iomem *base;
  111. bool pcie_tx_pol_inv;
  112. bool sata_tx_pol_inv;
  113. u32 sata_gen;
  114. u32 ctrlreg;
  115. u8 type;
  116. };
  117. struct miphy365x_dev {
  118. struct device *dev;
  119. struct regmap *regmap;
  120. struct mutex miphy_mutex;
  121. struct miphy365x_phy **phys;
  122. int nphys;
  123. };
  124. /*
  125. * These values are represented in Device tree. They are considered to be ABI
  126. * and although they can be extended any existing values must not change.
  127. */
  128. enum miphy_sata_gen {
  129. SATA_GEN1 = 1,
  130. SATA_GEN2,
  131. SATA_GEN3
  132. };
  133. static u8 rx_tx_spd[] = {
  134. 0, /* GEN0 doesn't exist. */
  135. TX_SPDSEL_GEN1_VAL | RX_SPDSEL_GEN1_VAL,
  136. TX_SPDSEL_GEN2_VAL | RX_SPDSEL_GEN2_VAL,
  137. TX_SPDSEL_GEN3_VAL | RX_SPDSEL_GEN3_VAL
  138. };
  139. /*
  140. * This function selects the system configuration,
  141. * either two SATA, one SATA and one PCIe, or two PCIe lanes.
  142. */
  143. static int miphy365x_set_path(struct miphy365x_phy *miphy_phy,
  144. struct miphy365x_dev *miphy_dev)
  145. {
  146. bool sata = (miphy_phy->type == PHY_TYPE_SATA);
  147. return regmap_update_bits(miphy_dev->regmap,
  148. miphy_phy->ctrlreg,
  149. SYSCFG_SELECT_SATA_MASK,
  150. sata << SYSCFG_SELECT_SATA_POS);
  151. }
  152. static int miphy365x_init_pcie_port(struct miphy365x_phy *miphy_phy,
  153. struct miphy365x_dev *miphy_dev)
  154. {
  155. u8 val;
  156. if (miphy_phy->pcie_tx_pol_inv) {
  157. /* Invert Tx polarity and clear pci_txdetect_pol bit */
  158. val = TERM_EN | PCI_EN | DES_BIT_LOCK_EN | TX_POL;
  159. writeb_relaxed(val, miphy_phy->base + CTRL_REG);
  160. writeb_relaxed(0x00, miphy_phy->base + PCIE_REG);
  161. }
  162. return 0;
  163. }
  164. static inline int miphy365x_hfc_not_rdy(struct miphy365x_phy *miphy_phy,
  165. struct miphy365x_dev *miphy_dev)
  166. {
  167. unsigned long timeout = jiffies + msecs_to_jiffies(HFC_TIMEOUT);
  168. u8 mask = IDLL_RDY | PLL_RDY;
  169. u8 regval;
  170. do {
  171. regval = readb_relaxed(miphy_phy->base + STATUS_REG);
  172. if (!(regval & mask))
  173. return 0;
  174. usleep_range(2000, 2500);
  175. } while (time_before(jiffies, timeout));
  176. dev_err(miphy_dev->dev, "HFC ready timeout!\n");
  177. return -EBUSY;
  178. }
  179. static inline int miphy365x_rdy(struct miphy365x_phy *miphy_phy,
  180. struct miphy365x_dev *miphy_dev)
  181. {
  182. unsigned long timeout = jiffies + msecs_to_jiffies(HFC_TIMEOUT);
  183. u8 mask = IDLL_RDY | PLL_RDY;
  184. u8 regval;
  185. do {
  186. regval = readb_relaxed(miphy_phy->base + STATUS_REG);
  187. if ((regval & mask) == mask)
  188. return 0;
  189. usleep_range(2000, 2500);
  190. } while (time_before(jiffies, timeout));
  191. dev_err(miphy_dev->dev, "PHY not ready timeout!\n");
  192. return -EBUSY;
  193. }
  194. static inline void miphy365x_set_comp(struct miphy365x_phy *miphy_phy,
  195. struct miphy365x_dev *miphy_dev)
  196. {
  197. u8 val, mask;
  198. if (miphy_phy->sata_gen == SATA_GEN1)
  199. writeb_relaxed(COMP_2MHZ_RAT_GEN1,
  200. miphy_phy->base + COMP_CTRL2_REG);
  201. else
  202. writeb_relaxed(COMP_2MHZ_RAT,
  203. miphy_phy->base + COMP_CTRL2_REG);
  204. if (miphy_phy->sata_gen != SATA_GEN3) {
  205. writeb_relaxed(COMSR_COMP_REF,
  206. miphy_phy->base + COMP_CTRL3_REG);
  207. /*
  208. * Force VCO current to value defined by address 0x5A
  209. * and disable PCIe100Mref bit
  210. * Enable auto load compensation for pll_i_bias
  211. */
  212. writeb_relaxed(BYPASS_PLL_CAL, miphy_phy->base + PLL_CTRL2_REG);
  213. writeb_relaxed(COMZC_IDLL, miphy_phy->base + COMP_IDLL_REG);
  214. }
  215. /*
  216. * Force restart compensation and enable auto load
  217. * for Comzc_Tx, Comzc_Rx and Comsr on macro
  218. */
  219. val = START_COMSR | START_COMZC | COMP_AUTO_LOAD;
  220. writeb_relaxed(val, miphy_phy->base + COMP_CTRL1_REG);
  221. mask = COMSR_DONE | COMZC_DONE;
  222. while ((readb_relaxed(miphy_phy->base + COMP_CTRL1_REG) & mask) != mask)
  223. cpu_relax();
  224. }
  225. static inline void miphy365x_set_ssc(struct miphy365x_phy *miphy_phy,
  226. struct miphy365x_dev *miphy_dev)
  227. {
  228. u8 val;
  229. /*
  230. * SSC Settings. SSC will be enabled through Link
  231. * SSC Ampl. = 0.4%
  232. * SSC Freq = 31KHz
  233. */
  234. writeb_relaxed(PLL_SSC_STEP_MSB_VAL,
  235. miphy_phy->base + PLL_SSC_STEP_MSB_REG);
  236. writeb_relaxed(PLL_SSC_STEP_LSB_VAL,
  237. miphy_phy->base + PLL_SSC_STEP_LSB_REG);
  238. writeb_relaxed(PLL_SSC_PER_MSB_VAL,
  239. miphy_phy->base + PLL_SSC_PER_MSB_REG);
  240. writeb_relaxed(PLL_SSC_PER_LSB_VAL,
  241. miphy_phy->base + PLL_SSC_PER_LSB_REG);
  242. /* SSC Settings complete */
  243. if (miphy_phy->sata_gen == SATA_GEN1) {
  244. val = PLL_START_CAL | BUF_EN | SYNCHRO_TX | CONFIG_PLL;
  245. writeb_relaxed(val, miphy_phy->base + PLL_CTRL1_REG);
  246. } else {
  247. val = SSC_EN | PLL_START_CAL | BUF_EN | SYNCHRO_TX | CONFIG_PLL;
  248. writeb_relaxed(val, miphy_phy->base + PLL_CTRL1_REG);
  249. }
  250. }
  251. static int miphy365x_init_sata_port(struct miphy365x_phy *miphy_phy,
  252. struct miphy365x_dev *miphy_dev)
  253. {
  254. int ret;
  255. u8 val;
  256. /*
  257. * Force PHY macro reset, PLL calibration reset, PLL reset
  258. * and assert Deserializer Reset
  259. */
  260. val = RST_PLL | RST_PLL_CAL | RST_RX | RST_MACRO;
  261. writeb_relaxed(val, miphy_phy->base + RESET_REG);
  262. if (miphy_phy->sata_tx_pol_inv)
  263. writeb_relaxed(TX_POL, miphy_phy->base + CTRL_REG);
  264. /*
  265. * Force macro1 to use rx_lspd, tx_lspd
  266. * Force Rx_Clock on first I-DLL phase
  267. * Force Des in HP mode on macro, rx_lspd, tx_lspd for Gen2/3
  268. */
  269. writeb_relaxed(SPDSEL_SEL, miphy_phy->base + BOUNDARY1_REG);
  270. writeb_relaxed(START_CLK_HF, miphy_phy->base + IDLL_TEST_REG);
  271. val = rx_tx_spd[miphy_phy->sata_gen];
  272. writeb_relaxed(val, miphy_phy->base + BOUNDARY3_REG);
  273. /* Wait for HFC_READY = 0 */
  274. ret = miphy365x_hfc_not_rdy(miphy_phy, miphy_dev);
  275. if (ret)
  276. return ret;
  277. /* Compensation Recalibration */
  278. miphy365x_set_comp(miphy_phy, miphy_dev);
  279. switch (miphy_phy->sata_gen) {
  280. case SATA_GEN3:
  281. /*
  282. * TX Swing target 550-600mv peak to peak diff
  283. * Tx Slew target 90-110ps rising/falling time
  284. * Rx Eq ON3, Sigdet threshold SDTH1
  285. */
  286. val = PD_VDDTFILTER | CONF_GEN_SEL_GEN3;
  287. writeb_relaxed(val, miphy_phy->base + BUF_SEL_REG);
  288. val = SWING_VAL | PREEMPH_VAL;
  289. writeb_relaxed(val, miphy_phy->base + TXBUF1_REG);
  290. writeb_relaxed(TXSLEW_VAL, miphy_phy->base + TXBUF2_REG);
  291. writeb_relaxed(0x00, miphy_phy->base + RXBUF_OFFSET_CTRL_REG);
  292. val = SDTHRES_VAL | EQ_ON3;
  293. writeb_relaxed(val, miphy_phy->base + RXBUF_REG);
  294. break;
  295. case SATA_GEN2:
  296. /*
  297. * conf gen sel=0x1 to program Gen2 banked registers
  298. * VDDT filter ON
  299. * Tx Swing target 550-600mV peak-to-peak diff
  300. * Tx Slew target 90-110 ps rising/falling time
  301. * RX Equalization ON1, Sigdet threshold SDTH1
  302. */
  303. writeb_relaxed(CONF_GEN_SEL_GEN2,
  304. miphy_phy->base + BUF_SEL_REG);
  305. writeb_relaxed(SWING_VAL, miphy_phy->base + TXBUF1_REG);
  306. writeb_relaxed(TXSLEW_VAL, miphy_phy->base + TXBUF2_REG);
  307. val = SDTHRES_VAL | EQ_ON1;
  308. writeb_relaxed(val, miphy_phy->base + RXBUF_REG);
  309. break;
  310. case SATA_GEN1:
  311. /*
  312. * conf gen sel = 00b to program Gen1 banked registers
  313. * VDDT filter ON
  314. * Tx Swing target 500-550mV peak-to-peak diff
  315. * Tx Slew target120-140 ps rising/falling time
  316. */
  317. writeb_relaxed(PD_VDDTFILTER, miphy_phy->base + BUF_SEL_REG);
  318. writeb_relaxed(SWING_VAL_GEN1, miphy_phy->base + TXBUF1_REG);
  319. writeb_relaxed(TXSLEW_VAL_GEN1, miphy_phy->base + TXBUF2_REG);
  320. break;
  321. default:
  322. break;
  323. }
  324. /* Force Macro1 in partial mode & release pll cal reset */
  325. writeb_relaxed(RST_RX, miphy_phy->base + RESET_REG);
  326. usleep_range(100, 150);
  327. miphy365x_set_ssc(miphy_phy, miphy_dev);
  328. /* Wait for phy_ready */
  329. ret = miphy365x_rdy(miphy_phy, miphy_dev);
  330. if (ret)
  331. return ret;
  332. /*
  333. * Enable macro1 to use rx_lspd & tx_lspd
  334. * Release Rx_Clock on first I-DLL phase on macro1
  335. * Assert deserializer reset
  336. * des_bit_lock_en is set
  337. * bit lock detection strength
  338. * Deassert deserializer reset
  339. */
  340. writeb_relaxed(0x00, miphy_phy->base + BOUNDARY1_REG);
  341. writeb_relaxed(0x00, miphy_phy->base + IDLL_TEST_REG);
  342. writeb_relaxed(RST_RX, miphy_phy->base + RESET_REG);
  343. val = miphy_phy->sata_tx_pol_inv ?
  344. (TX_POL | DES_BIT_LOCK_EN) : DES_BIT_LOCK_EN;
  345. writeb_relaxed(val, miphy_phy->base + CTRL_REG);
  346. val = BIT_LOCK_CNT_512 | BIT_LOCK_LEVEL;
  347. writeb_relaxed(val, miphy_phy->base + DES_BITLOCK_REG);
  348. writeb_relaxed(0x00, miphy_phy->base + RESET_REG);
  349. return 0;
  350. }
  351. static int miphy365x_init(struct phy *phy)
  352. {
  353. struct miphy365x_phy *miphy_phy = phy_get_drvdata(phy);
  354. struct miphy365x_dev *miphy_dev = dev_get_drvdata(phy->dev.parent);
  355. int ret = 0;
  356. mutex_lock(&miphy_dev->miphy_mutex);
  357. ret = miphy365x_set_path(miphy_phy, miphy_dev);
  358. if (ret) {
  359. mutex_unlock(&miphy_dev->miphy_mutex);
  360. return ret;
  361. }
  362. /* Initialise Miphy for PCIe or SATA */
  363. if (miphy_phy->type == PHY_TYPE_PCIE)
  364. ret = miphy365x_init_pcie_port(miphy_phy, miphy_dev);
  365. else
  366. ret = miphy365x_init_sata_port(miphy_phy, miphy_dev);
  367. mutex_unlock(&miphy_dev->miphy_mutex);
  368. return ret;
  369. }
  370. static int miphy365x_get_addr(struct device *dev,
  371. struct miphy365x_phy *miphy_phy, int index)
  372. {
  373. struct device_node *phynode = miphy_phy->phy->dev.of_node;
  374. const char *name;
  375. int type = miphy_phy->type;
  376. int ret;
  377. ret = of_property_read_string_index(phynode, "reg-names", index, &name);
  378. if (ret) {
  379. dev_err(dev, "no reg-names property not found\n");
  380. return ret;
  381. }
  382. if (!((!strncmp(name, "sata", 4) && type == PHY_TYPE_SATA) ||
  383. (!strncmp(name, "pcie", 4) && type == PHY_TYPE_PCIE)))
  384. return 0;
  385. miphy_phy->base = of_iomap(phynode, index);
  386. if (!miphy_phy->base) {
  387. dev_err(dev, "Failed to map %s\n", phynode->full_name);
  388. return -EINVAL;
  389. }
  390. return 0;
  391. }
  392. static struct phy *miphy365x_xlate(struct device *dev,
  393. struct of_phandle_args *args)
  394. {
  395. struct miphy365x_dev *miphy_dev = dev_get_drvdata(dev);
  396. struct miphy365x_phy *miphy_phy = NULL;
  397. struct device_node *phynode = args->np;
  398. int ret, index;
  399. if (args->args_count != 1) {
  400. dev_err(dev, "Invalid number of cells in 'phy' property\n");
  401. return ERR_PTR(-EINVAL);
  402. }
  403. for (index = 0; index < miphy_dev->nphys; index++)
  404. if (phynode == miphy_dev->phys[index]->phy->dev.of_node) {
  405. miphy_phy = miphy_dev->phys[index];
  406. break;
  407. }
  408. if (!miphy_phy) {
  409. dev_err(dev, "Failed to find appropriate phy\n");
  410. return ERR_PTR(-EINVAL);
  411. }
  412. miphy_phy->type = args->args[0];
  413. if (!(miphy_phy->type == PHY_TYPE_SATA ||
  414. miphy_phy->type == PHY_TYPE_PCIE)) {
  415. dev_err(dev, "Unsupported device type: %d\n", miphy_phy->type);
  416. return ERR_PTR(-EINVAL);
  417. }
  418. /* Each port handles SATA and PCIE - third entry is always sysconf. */
  419. for (index = 0; index < 3; index++) {
  420. ret = miphy365x_get_addr(dev, miphy_phy, index);
  421. if (ret < 0)
  422. return ERR_PTR(ret);
  423. }
  424. return miphy_phy->phy;
  425. }
  426. static const struct phy_ops miphy365x_ops = {
  427. .init = miphy365x_init,
  428. .owner = THIS_MODULE,
  429. };
  430. static int miphy365x_of_probe(struct device_node *phynode,
  431. struct miphy365x_phy *miphy_phy)
  432. {
  433. of_property_read_u32(phynode, "st,sata-gen", &miphy_phy->sata_gen);
  434. if (!miphy_phy->sata_gen)
  435. miphy_phy->sata_gen = SATA_GEN1;
  436. miphy_phy->pcie_tx_pol_inv =
  437. of_property_read_bool(phynode, "st,pcie-tx-pol-inv");
  438. miphy_phy->sata_tx_pol_inv =
  439. of_property_read_bool(phynode, "st,sata-tx-pol-inv");
  440. return 0;
  441. }
  442. static int miphy365x_probe(struct platform_device *pdev)
  443. {
  444. struct device_node *child, *np = pdev->dev.of_node;
  445. struct miphy365x_dev *miphy_dev;
  446. struct phy_provider *provider;
  447. struct phy *phy;
  448. int ret, port = 0;
  449. miphy_dev = devm_kzalloc(&pdev->dev, sizeof(*miphy_dev), GFP_KERNEL);
  450. if (!miphy_dev)
  451. return -ENOMEM;
  452. miphy_dev->nphys = of_get_child_count(np);
  453. miphy_dev->phys = devm_kcalloc(&pdev->dev, miphy_dev->nphys,
  454. sizeof(*miphy_dev->phys), GFP_KERNEL);
  455. if (!miphy_dev->phys)
  456. return -ENOMEM;
  457. miphy_dev->regmap = syscon_regmap_lookup_by_phandle(np, "st,syscfg");
  458. if (IS_ERR(miphy_dev->regmap)) {
  459. dev_err(miphy_dev->dev, "No syscfg phandle specified\n");
  460. return PTR_ERR(miphy_dev->regmap);
  461. }
  462. miphy_dev->dev = &pdev->dev;
  463. dev_set_drvdata(&pdev->dev, miphy_dev);
  464. mutex_init(&miphy_dev->miphy_mutex);
  465. for_each_child_of_node(np, child) {
  466. struct miphy365x_phy *miphy_phy;
  467. miphy_phy = devm_kzalloc(&pdev->dev, sizeof(*miphy_phy),
  468. GFP_KERNEL);
  469. if (!miphy_phy) {
  470. ret = -ENOMEM;
  471. goto put_child;
  472. }
  473. miphy_dev->phys[port] = miphy_phy;
  474. phy = devm_phy_create(&pdev->dev, child, &miphy365x_ops);
  475. if (IS_ERR(phy)) {
  476. dev_err(&pdev->dev, "failed to create PHY\n");
  477. ret = PTR_ERR(phy);
  478. goto put_child;
  479. }
  480. miphy_dev->phys[port]->phy = phy;
  481. ret = miphy365x_of_probe(child, miphy_phy);
  482. if (ret)
  483. goto put_child;
  484. phy_set_drvdata(phy, miphy_dev->phys[port]);
  485. port++;
  486. /* sysconfig offsets are indexed from 1 */
  487. ret = of_property_read_u32_index(np, "st,syscfg", port,
  488. &miphy_phy->ctrlreg);
  489. if (ret) {
  490. dev_err(&pdev->dev, "No sysconfig offset found\n");
  491. goto put_child;
  492. }
  493. }
  494. provider = devm_of_phy_provider_register(&pdev->dev, miphy365x_xlate);
  495. return PTR_ERR_OR_ZERO(provider);
  496. put_child:
  497. of_node_put(child);
  498. return ret;
  499. }
  500. static const struct of_device_id miphy365x_of_match[] = {
  501. { .compatible = "st,miphy365x-phy", },
  502. { },
  503. };
  504. MODULE_DEVICE_TABLE(of, miphy365x_of_match);
  505. static struct platform_driver miphy365x_driver = {
  506. .probe = miphy365x_probe,
  507. .driver = {
  508. .name = "miphy365x-phy",
  509. .of_match_table = miphy365x_of_match,
  510. }
  511. };
  512. module_platform_driver(miphy365x_driver);
  513. MODULE_AUTHOR("Alexandre Torgue <alexandre.torgue@st.com>");
  514. MODULE_DESCRIPTION("STMicroelectronics miphy365x driver");
  515. MODULE_LICENSE("GPL v2");