phy-mvebu-a3700-comphy.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2018 Marvell
  4. *
  5. * Authors:
  6. * Evan Wang <[email protected]>
  7. * Miquèl Raynal <[email protected]>
  8. * Pali Rohár <[email protected]>
  9. * Marek Behún <[email protected]>
  10. *
  11. * Structure inspired from phy-mvebu-cp110-comphy.c written by Antoine Tenart.
  12. * Comphy code from ARM Trusted Firmware ported by Pali Rohár <[email protected]>
  13. * and Marek Behún <[email protected]>.
  14. */
  15. #include <linux/bitfield.h>
  16. #include <linux/clk.h>
  17. #include <linux/io.h>
  18. #include <linux/iopoll.h>
  19. #include <linux/mfd/syscon.h>
  20. #include <linux/module.h>
  21. #include <linux/phy.h>
  22. #include <linux/phy/phy.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/spinlock.h>
  25. #define PLL_SET_DELAY_US 600
  26. #define COMPHY_PLL_SLEEP 1000
  27. #define COMPHY_PLL_TIMEOUT 150000
  28. /* Comphy lane2 indirect access register offset */
  29. #define COMPHY_LANE2_INDIR_ADDR 0x0
  30. #define COMPHY_LANE2_INDIR_DATA 0x4
  31. /* SATA and USB3 PHY offset compared to SATA PHY */
  32. #define COMPHY_LANE2_REGS_BASE 0x200
  33. /*
  34. * When accessing common PHY lane registers directly, we need to shift by 1,
  35. * since the registers are 16-bit.
  36. */
  37. #define COMPHY_LANE_REG_DIRECT(reg) (((reg) & 0x7FF) << 1)
  38. /* COMPHY registers */
  39. #define COMPHY_POWER_PLL_CTRL 0x01
  40. #define PU_IVREF_BIT BIT(15)
  41. #define PU_PLL_BIT BIT(14)
  42. #define PU_RX_BIT BIT(13)
  43. #define PU_TX_BIT BIT(12)
  44. #define PU_TX_INTP_BIT BIT(11)
  45. #define PU_DFE_BIT BIT(10)
  46. #define RESET_DTL_RX_BIT BIT(9)
  47. #define PLL_LOCK_BIT BIT(8)
  48. #define REF_FREF_SEL_MASK GENMASK(4, 0)
  49. #define REF_FREF_SEL_SERDES_25MHZ FIELD_PREP(REF_FREF_SEL_MASK, 0x1)
  50. #define REF_FREF_SEL_SERDES_40MHZ FIELD_PREP(REF_FREF_SEL_MASK, 0x3)
  51. #define REF_FREF_SEL_SERDES_50MHZ FIELD_PREP(REF_FREF_SEL_MASK, 0x4)
  52. #define REF_FREF_SEL_PCIE_USB3_25MHZ FIELD_PREP(REF_FREF_SEL_MASK, 0x2)
  53. #define REF_FREF_SEL_PCIE_USB3_40MHZ FIELD_PREP(REF_FREF_SEL_MASK, 0x3)
  54. #define COMPHY_MODE_MASK GENMASK(7, 5)
  55. #define COMPHY_MODE_SATA FIELD_PREP(COMPHY_MODE_MASK, 0x0)
  56. #define COMPHY_MODE_PCIE FIELD_PREP(COMPHY_MODE_MASK, 0x3)
  57. #define COMPHY_MODE_SERDES FIELD_PREP(COMPHY_MODE_MASK, 0x4)
  58. #define COMPHY_MODE_USB3 FIELD_PREP(COMPHY_MODE_MASK, 0x5)
  59. #define COMPHY_KVCO_CAL_CTRL 0x02
  60. #define USE_MAX_PLL_RATE_BIT BIT(12)
  61. #define SPEED_PLL_MASK GENMASK(7, 2)
  62. #define SPEED_PLL_VALUE_16 FIELD_PREP(SPEED_PLL_MASK, 0x10)
  63. #define COMPHY_DIG_LOOPBACK_EN 0x23
  64. #define SEL_DATA_WIDTH_MASK GENMASK(11, 10)
  65. #define DATA_WIDTH_10BIT FIELD_PREP(SEL_DATA_WIDTH_MASK, 0x0)
  66. #define DATA_WIDTH_20BIT FIELD_PREP(SEL_DATA_WIDTH_MASK, 0x1)
  67. #define DATA_WIDTH_40BIT FIELD_PREP(SEL_DATA_WIDTH_MASK, 0x2)
  68. #define PLL_READY_TX_BIT BIT(4)
  69. #define COMPHY_SYNC_PATTERN 0x24
  70. #define TXD_INVERT_BIT BIT(10)
  71. #define RXD_INVERT_BIT BIT(11)
  72. #define COMPHY_SYNC_MASK_GEN 0x25
  73. #define PHY_GEN_MAX_MASK GENMASK(11, 10)
  74. #define PHY_GEN_MAX_USB3_5G FIELD_PREP(PHY_GEN_MAX_MASK, 0x1)
  75. #define COMPHY_ISOLATION_CTRL 0x26
  76. #define PHY_ISOLATE_MODE BIT(15)
  77. #define COMPHY_GEN2_SET2 0x3e
  78. #define GS2_TX_SSC_AMP_MASK GENMASK(15, 9)
  79. #define GS2_TX_SSC_AMP_4128 FIELD_PREP(GS2_TX_SSC_AMP_MASK, 0x20)
  80. #define GS2_VREG_RXTX_MAS_ISET_MASK GENMASK(8, 7)
  81. #define GS2_VREG_RXTX_MAS_ISET_60U FIELD_PREP(GS2_VREG_RXTX_MAS_ISET_MASK,\
  82. 0x0)
  83. #define GS2_VREG_RXTX_MAS_ISET_80U FIELD_PREP(GS2_VREG_RXTX_MAS_ISET_MASK,\
  84. 0x1)
  85. #define GS2_VREG_RXTX_MAS_ISET_100U FIELD_PREP(GS2_VREG_RXTX_MAS_ISET_MASK,\
  86. 0x2)
  87. #define GS2_VREG_RXTX_MAS_ISET_120U FIELD_PREP(GS2_VREG_RXTX_MAS_ISET_MASK,\
  88. 0x3)
  89. #define GS2_RSVD_6_0_MASK GENMASK(6, 0)
  90. #define COMPHY_GEN3_SET2 0x3f
  91. #define COMPHY_IDLE_SYNC_EN 0x48
  92. #define IDLE_SYNC_EN BIT(12)
  93. #define COMPHY_MISC_CTRL0 0x4F
  94. #define CLK100M_125M_EN BIT(4)
  95. #define TXDCLK_2X_SEL BIT(6)
  96. #define CLK500M_EN BIT(7)
  97. #define PHY_REF_CLK_SEL BIT(10)
  98. #define COMPHY_SFT_RESET 0x52
  99. #define SFT_RST BIT(9)
  100. #define SFT_RST_NO_REG BIT(10)
  101. #define COMPHY_MISC_CTRL1 0x73
  102. #define SEL_BITS_PCIE_FORCE BIT(15)
  103. #define COMPHY_GEN2_SET3 0x112
  104. #define GS3_FFE_CAP_SEL_MASK GENMASK(3, 0)
  105. #define GS3_FFE_CAP_SEL_VALUE FIELD_PREP(GS3_FFE_CAP_SEL_MASK, 0xF)
  106. /* PIPE registers */
  107. #define COMPHY_PIPE_LANE_CFG0 0x180
  108. #define PRD_TXDEEMPH0_MASK BIT(0)
  109. #define PRD_TXMARGIN_MASK GENMASK(3, 1)
  110. #define PRD_TXSWING_MASK BIT(4)
  111. #define CFG_TX_ALIGN_POS_MASK GENMASK(8, 5)
  112. #define COMPHY_PIPE_LANE_CFG1 0x181
  113. #define PRD_TXDEEMPH1_MASK BIT(15)
  114. #define USE_MAX_PLL_RATE_EN BIT(9)
  115. #define TX_DET_RX_MODE BIT(6)
  116. #define GEN2_TX_DATA_DLY_MASK GENMASK(4, 3)
  117. #define GEN2_TX_DATA_DLY_DEFT FIELD_PREP(GEN2_TX_DATA_DLY_MASK, 2)
  118. #define TX_ELEC_IDLE_MODE_EN BIT(0)
  119. #define COMPHY_PIPE_LANE_STAT1 0x183
  120. #define TXDCLK_PCLK_EN BIT(0)
  121. #define COMPHY_PIPE_LANE_CFG4 0x188
  122. #define SPREAD_SPECTRUM_CLK_EN BIT(7)
  123. #define COMPHY_PIPE_RST_CLK_CTRL 0x1C1
  124. #define PIPE_SOFT_RESET BIT(0)
  125. #define PIPE_REG_RESET BIT(1)
  126. #define MODE_CORE_CLK_FREQ_SEL BIT(9)
  127. #define MODE_PIPE_WIDTH_32 BIT(3)
  128. #define MODE_REFDIV_MASK GENMASK(5, 4)
  129. #define MODE_REFDIV_BY_4 FIELD_PREP(MODE_REFDIV_MASK, 0x2)
  130. #define COMPHY_PIPE_TEST_MODE_CTRL 0x1C2
  131. #define MODE_MARGIN_OVERRIDE BIT(2)
  132. #define COMPHY_PIPE_CLK_SRC_LO 0x1C3
  133. #define MODE_CLK_SRC BIT(0)
  134. #define BUNDLE_PERIOD_SEL BIT(1)
  135. #define BUNDLE_PERIOD_SCALE_MASK GENMASK(3, 2)
  136. #define BUNDLE_SAMPLE_CTRL BIT(4)
  137. #define PLL_READY_DLY_MASK GENMASK(7, 5)
  138. #define CFG_SEL_20B BIT(15)
  139. #define COMPHY_PIPE_PWR_MGM_TIM1 0x1D0
  140. #define CFG_PM_OSCCLK_WAIT_MASK GENMASK(15, 12)
  141. #define CFG_PM_RXDEN_WAIT_MASK GENMASK(11, 8)
  142. #define CFG_PM_RXDEN_WAIT_1_UNIT FIELD_PREP(CFG_PM_RXDEN_WAIT_MASK, 0x1)
  143. #define CFG_PM_RXDLOZ_WAIT_MASK GENMASK(7, 0)
  144. #define CFG_PM_RXDLOZ_WAIT_7_UNIT FIELD_PREP(CFG_PM_RXDLOZ_WAIT_MASK, 0x7)
  145. #define CFG_PM_RXDLOZ_WAIT_12_UNIT FIELD_PREP(CFG_PM_RXDLOZ_WAIT_MASK, 0xC)
  146. /*
  147. * This register is not from PHY lane register space. It only exists in the
  148. * indirect register space, before the actual PHY lane 2 registers. So the
  149. * offset is absolute, not relative to COMPHY_LANE2_REGS_BASE.
  150. * It is used only for SATA PHY initialization.
  151. */
  152. #define COMPHY_RESERVED_REG 0x0E
  153. #define PHYCTRL_FRM_PIN_BIT BIT(13)
  154. /* South Bridge PHY Configuration Registers */
  155. #define COMPHY_PHY_REG(lane, reg) (((1 - (lane)) * 0x28) + ((reg) & 0x3f))
  156. /*
  157. * lane0: USB3/GbE1 PHY Configuration 1
  158. * lane1: PCIe/GbE0 PHY Configuration 1
  159. * (used only by SGMII code)
  160. */
  161. #define COMPHY_PHY_CFG1 0x0
  162. #define PIN_PU_IVREF_BIT BIT(1)
  163. #define PIN_RESET_CORE_BIT BIT(11)
  164. #define PIN_RESET_COMPHY_BIT BIT(12)
  165. #define PIN_PU_PLL_BIT BIT(16)
  166. #define PIN_PU_RX_BIT BIT(17)
  167. #define PIN_PU_TX_BIT BIT(18)
  168. #define PIN_TX_IDLE_BIT BIT(19)
  169. #define GEN_RX_SEL_MASK GENMASK(25, 22)
  170. #define GEN_RX_SEL_VALUE(val) FIELD_PREP(GEN_RX_SEL_MASK, (val))
  171. #define GEN_TX_SEL_MASK GENMASK(29, 26)
  172. #define GEN_TX_SEL_VALUE(val) FIELD_PREP(GEN_TX_SEL_MASK, (val))
  173. #define SERDES_SPEED_1_25_G 0x6
  174. #define SERDES_SPEED_3_125_G 0x8
  175. #define PHY_RX_INIT_BIT BIT(30)
  176. /*
  177. * lane0: USB3/GbE1 PHY Status 1
  178. * lane1: PCIe/GbE0 PHY Status 1
  179. * (used only by SGMII code)
  180. */
  181. #define COMPHY_PHY_STAT1 0x18
  182. #define PHY_RX_INIT_DONE_BIT BIT(0)
  183. #define PHY_PLL_READY_RX_BIT BIT(2)
  184. #define PHY_PLL_READY_TX_BIT BIT(3)
  185. /* PHY Selector */
  186. #define COMPHY_SELECTOR_PHY_REG 0xFC
  187. /* bit0: 0: Lane1 is GbE0; 1: Lane1 is PCIe */
  188. #define COMPHY_SELECTOR_PCIE_GBE0_SEL_BIT BIT(0)
  189. /* bit4: 0: Lane0 is GbE1; 1: Lane0 is USB3 */
  190. #define COMPHY_SELECTOR_USB3_GBE1_SEL_BIT BIT(4)
  191. /* bit8: 0: Lane0 is USB3 instead of GbE1, Lane2 is SATA; 1: Lane2 is USB3 */
  192. #define COMPHY_SELECTOR_USB3_PHY_SEL_BIT BIT(8)
  193. struct mvebu_a3700_comphy_conf {
  194. unsigned int lane;
  195. enum phy_mode mode;
  196. int submode;
  197. };
  198. #define MVEBU_A3700_COMPHY_CONF(_lane, _mode, _smode) \
  199. { \
  200. .lane = _lane, \
  201. .mode = _mode, \
  202. .submode = _smode, \
  203. }
  204. #define MVEBU_A3700_COMPHY_CONF_GEN(_lane, _mode) \
  205. MVEBU_A3700_COMPHY_CONF(_lane, _mode, PHY_INTERFACE_MODE_NA)
  206. #define MVEBU_A3700_COMPHY_CONF_ETH(_lane, _smode) \
  207. MVEBU_A3700_COMPHY_CONF(_lane, PHY_MODE_ETHERNET, _smode)
  208. static const struct mvebu_a3700_comphy_conf mvebu_a3700_comphy_modes[] = {
  209. /* lane 0 */
  210. MVEBU_A3700_COMPHY_CONF_GEN(0, PHY_MODE_USB_HOST_SS),
  211. MVEBU_A3700_COMPHY_CONF_ETH(0, PHY_INTERFACE_MODE_SGMII),
  212. MVEBU_A3700_COMPHY_CONF_ETH(0, PHY_INTERFACE_MODE_1000BASEX),
  213. MVEBU_A3700_COMPHY_CONF_ETH(0, PHY_INTERFACE_MODE_2500BASEX),
  214. /* lane 1 */
  215. MVEBU_A3700_COMPHY_CONF_GEN(1, PHY_MODE_PCIE),
  216. MVEBU_A3700_COMPHY_CONF_ETH(1, PHY_INTERFACE_MODE_SGMII),
  217. MVEBU_A3700_COMPHY_CONF_ETH(1, PHY_INTERFACE_MODE_1000BASEX),
  218. MVEBU_A3700_COMPHY_CONF_ETH(1, PHY_INTERFACE_MODE_2500BASEX),
  219. /* lane 2 */
  220. MVEBU_A3700_COMPHY_CONF_GEN(2, PHY_MODE_SATA),
  221. MVEBU_A3700_COMPHY_CONF_GEN(2, PHY_MODE_USB_HOST_SS),
  222. };
  223. struct mvebu_a3700_comphy_priv {
  224. void __iomem *comphy_regs;
  225. void __iomem *lane0_phy_regs; /* USB3 and GbE1 */
  226. void __iomem *lane1_phy_regs; /* PCIe and GbE0 */
  227. void __iomem *lane2_phy_indirect; /* SATA and USB3 */
  228. spinlock_t lock; /* for PHY selector access */
  229. bool xtal_is_40m;
  230. };
  231. struct mvebu_a3700_comphy_lane {
  232. struct mvebu_a3700_comphy_priv *priv;
  233. struct device *dev;
  234. unsigned int id;
  235. enum phy_mode mode;
  236. int submode;
  237. bool invert_tx;
  238. bool invert_rx;
  239. };
  240. struct gbe_phy_init_data_fix {
  241. u16 addr;
  242. u16 value;
  243. };
  244. /* Changes to 40M1G25 mode data required for running 40M3G125 init mode */
  245. static struct gbe_phy_init_data_fix gbe_phy_init_fix[] = {
  246. { 0x005, 0x07CC }, { 0x015, 0x0000 }, { 0x01B, 0x0000 },
  247. { 0x01D, 0x0000 }, { 0x01E, 0x0000 }, { 0x01F, 0x0000 },
  248. { 0x020, 0x0000 }, { 0x021, 0x0030 }, { 0x026, 0x0888 },
  249. { 0x04D, 0x0152 }, { 0x04F, 0xA020 }, { 0x050, 0x07CC },
  250. { 0x053, 0xE9CA }, { 0x055, 0xBD97 }, { 0x071, 0x3015 },
  251. { 0x076, 0x03AA }, { 0x07C, 0x0FDF }, { 0x0C2, 0x3030 },
  252. { 0x0C3, 0x8000 }, { 0x0E2, 0x5550 }, { 0x0E3, 0x12A4 },
  253. { 0x0E4, 0x7D00 }, { 0x0E6, 0x0C83 }, { 0x101, 0xFCC0 },
  254. { 0x104, 0x0C10 }
  255. };
  256. /* 40M1G25 mode init data */
  257. static u16 gbe_phy_init[512] = {
  258. /* 0 1 2 3 4 5 6 7 */
  259. /*-----------------------------------------------------------*/
  260. /* 8 9 A B C D E F */
  261. 0x3110, 0xFD83, 0x6430, 0x412F, 0x82C0, 0x06FA, 0x4500, 0x6D26, /* 00 */
  262. 0xAFC0, 0x8000, 0xC000, 0x0000, 0x2000, 0x49CC, 0x0BC9, 0x2A52, /* 08 */
  263. 0x0BD2, 0x0CDE, 0x13D2, 0x0CE8, 0x1149, 0x10E0, 0x0000, 0x0000, /* 10 */
  264. 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x4134, 0x0D2D, 0xFFFF, /* 18 */
  265. 0xFFE0, 0x4030, 0x1016, 0x0030, 0x0000, 0x0800, 0x0866, 0x0000, /* 20 */
  266. 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, /* 28 */
  267. 0xFFFF, 0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 30 */
  268. 0x0000, 0x0000, 0x000F, 0x6A62, 0x1988, 0x3100, 0x3100, 0x3100, /* 38 */
  269. 0x3100, 0xA708, 0x2430, 0x0830, 0x1030, 0x4610, 0xFF00, 0xFF00, /* 40 */
  270. 0x0060, 0x1000, 0x0400, 0x0040, 0x00F0, 0x0155, 0x1100, 0xA02A, /* 48 */
  271. 0x06FA, 0x0080, 0xB008, 0xE3ED, 0x5002, 0xB592, 0x7A80, 0x0001, /* 50 */
  272. 0x020A, 0x8820, 0x6014, 0x8054, 0xACAA, 0xFC88, 0x2A02, 0x45CF, /* 58 */
  273. 0x000F, 0x1817, 0x2860, 0x064F, 0x0000, 0x0204, 0x1800, 0x6000, /* 60 */
  274. 0x810F, 0x4F23, 0x4000, 0x4498, 0x0850, 0x0000, 0x000E, 0x1002, /* 68 */
  275. 0x9D3A, 0x3009, 0xD066, 0x0491, 0x0001, 0x6AB0, 0x0399, 0x3780, /* 70 */
  276. 0x0040, 0x5AC0, 0x4A80, 0x0000, 0x01DF, 0x0000, 0x0007, 0x0000, /* 78 */
  277. 0x2D54, 0x00A1, 0x4000, 0x0100, 0xA20A, 0x0000, 0x0000, 0x0000, /* 80 */
  278. 0x0000, 0x0000, 0x0000, 0x7400, 0x0E81, 0x1000, 0x1242, 0x0210, /* 88 */
  279. 0x80DF, 0x0F1F, 0x2F3F, 0x4F5F, 0x6F7F, 0x0F1F, 0x2F3F, 0x4F5F, /* 90 */
  280. 0x6F7F, 0x4BAD, 0x0000, 0x0000, 0x0800, 0x0000, 0x2400, 0xB651, /* 98 */
  281. 0xC9E0, 0x4247, 0x0A24, 0x0000, 0xAF19, 0x1004, 0x0000, 0x0000, /* A0 */
  282. 0x0000, 0x0013, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* A8 */
  283. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* B0 */
  284. 0x0000, 0x0000, 0x0000, 0x0060, 0x0000, 0x0000, 0x0000, 0x0000, /* B8 */
  285. 0x0000, 0x0000, 0x3010, 0xFA00, 0x0000, 0x0000, 0x0000, 0x0003, /* C0 */
  286. 0x1618, 0x8200, 0x8000, 0x0400, 0x050F, 0x0000, 0x0000, 0x0000, /* C8 */
  287. 0x4C93, 0x0000, 0x1000, 0x1120, 0x0010, 0x1242, 0x1242, 0x1E00, /* D0 */
  288. 0x0000, 0x0000, 0x0000, 0x00F8, 0x0000, 0x0041, 0x0800, 0x0000, /* D8 */
  289. 0x82A0, 0x572E, 0x2490, 0x14A9, 0x4E00, 0x0000, 0x0803, 0x0541, /* E0 */
  290. 0x0C15, 0x0000, 0x0000, 0x0400, 0x2626, 0x0000, 0x0000, 0x4200, /* E8 */
  291. 0x0000, 0xAA55, 0x1020, 0x0000, 0x0000, 0x5010, 0x0000, 0x0000, /* F0 */
  292. 0x0000, 0x0000, 0x5000, 0x0000, 0x0000, 0x0000, 0x02F2, 0x0000, /* F8 */
  293. 0x101F, 0xFDC0, 0x4000, 0x8010, 0x0110, 0x0006, 0x0000, 0x0000, /*100 */
  294. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*108 */
  295. 0x04CF, 0x0000, 0x04CF, 0x0000, 0x04CF, 0x0000, 0x04C6, 0x0000, /*110 */
  296. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*118 */
  297. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*120 */
  298. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*128 */
  299. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*130 */
  300. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*138 */
  301. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*140 */
  302. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*148 */
  303. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*150 */
  304. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*158 */
  305. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*160 */
  306. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*168 */
  307. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*170 */
  308. 0x0000, 0x0000, 0x0000, 0x00F0, 0x08A2, 0x3112, 0x0A14, 0x0000, /*178 */
  309. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*180 */
  310. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*188 */
  311. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*190 */
  312. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*198 */
  313. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1A0 */
  314. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1A8 */
  315. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1B0 */
  316. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1B8 */
  317. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1C0 */
  318. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1C8 */
  319. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1D0 */
  320. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1D8 */
  321. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1E0 */
  322. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1E8 */
  323. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1F0 */
  324. 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 /*1F8 */
  325. };
  326. static inline void comphy_reg_set(void __iomem *addr, u32 data, u32 mask)
  327. {
  328. u32 val;
  329. val = readl(addr);
  330. val = (val & ~mask) | (data & mask);
  331. writel(val, addr);
  332. }
  333. static inline void comphy_reg_set16(void __iomem *addr, u16 data, u16 mask)
  334. {
  335. u16 val;
  336. val = readw(addr);
  337. val = (val & ~mask) | (data & mask);
  338. writew(val, addr);
  339. }
  340. /* Used for accessing lane 2 registers (SATA/USB3 PHY) */
  341. static void comphy_set_indirect(struct mvebu_a3700_comphy_priv *priv,
  342. u32 offset, u16 data, u16 mask)
  343. {
  344. writel(offset,
  345. priv->lane2_phy_indirect + COMPHY_LANE2_INDIR_ADDR);
  346. comphy_reg_set(priv->lane2_phy_indirect + COMPHY_LANE2_INDIR_DATA,
  347. data, mask);
  348. }
  349. static void comphy_lane_reg_set(struct mvebu_a3700_comphy_lane *lane,
  350. u16 reg, u16 data, u16 mask)
  351. {
  352. if (lane->id == 2) {
  353. /* lane 2 PHY registers are accessed indirectly */
  354. comphy_set_indirect(lane->priv,
  355. reg + COMPHY_LANE2_REGS_BASE,
  356. data, mask);
  357. } else {
  358. void __iomem *base = lane->id == 1 ?
  359. lane->priv->lane1_phy_regs :
  360. lane->priv->lane0_phy_regs;
  361. comphy_reg_set16(base + COMPHY_LANE_REG_DIRECT(reg),
  362. data, mask);
  363. }
  364. }
  365. static int comphy_lane_reg_poll(struct mvebu_a3700_comphy_lane *lane,
  366. u16 reg, u16 bits,
  367. ulong sleep_us, ulong timeout_us)
  368. {
  369. int ret;
  370. if (lane->id == 2) {
  371. u32 data;
  372. /* lane 2 PHY registers are accessed indirectly */
  373. writel(reg + COMPHY_LANE2_REGS_BASE,
  374. lane->priv->lane2_phy_indirect +
  375. COMPHY_LANE2_INDIR_ADDR);
  376. ret = readl_poll_timeout(lane->priv->lane2_phy_indirect +
  377. COMPHY_LANE2_INDIR_DATA,
  378. data, (data & bits) == bits,
  379. sleep_us, timeout_us);
  380. } else {
  381. void __iomem *base = lane->id == 1 ?
  382. lane->priv->lane1_phy_regs :
  383. lane->priv->lane0_phy_regs;
  384. u16 data;
  385. ret = readw_poll_timeout(base + COMPHY_LANE_REG_DIRECT(reg),
  386. data, (data & bits) == bits,
  387. sleep_us, timeout_us);
  388. }
  389. return ret;
  390. }
  391. static void comphy_periph_reg_set(struct mvebu_a3700_comphy_lane *lane,
  392. u8 reg, u32 data, u32 mask)
  393. {
  394. comphy_reg_set(lane->priv->comphy_regs + COMPHY_PHY_REG(lane->id, reg),
  395. data, mask);
  396. }
  397. static int comphy_periph_reg_poll(struct mvebu_a3700_comphy_lane *lane,
  398. u8 reg, u32 bits,
  399. ulong sleep_us, ulong timeout_us)
  400. {
  401. u32 data;
  402. return readl_poll_timeout(lane->priv->comphy_regs +
  403. COMPHY_PHY_REG(lane->id, reg),
  404. data, (data & bits) == bits,
  405. sleep_us, timeout_us);
  406. }
  407. /* PHY selector configures with corresponding modes */
  408. static int
  409. mvebu_a3700_comphy_set_phy_selector(struct mvebu_a3700_comphy_lane *lane)
  410. {
  411. u32 old, new, clr = 0, set = 0;
  412. unsigned long flags;
  413. switch (lane->mode) {
  414. case PHY_MODE_SATA:
  415. /* SATA must be in Lane2 */
  416. if (lane->id == 2)
  417. clr = COMPHY_SELECTOR_USB3_PHY_SEL_BIT;
  418. else
  419. goto error;
  420. break;
  421. case PHY_MODE_ETHERNET:
  422. if (lane->id == 0)
  423. clr = COMPHY_SELECTOR_USB3_GBE1_SEL_BIT;
  424. else if (lane->id == 1)
  425. clr = COMPHY_SELECTOR_PCIE_GBE0_SEL_BIT;
  426. else
  427. goto error;
  428. break;
  429. case PHY_MODE_USB_HOST_SS:
  430. if (lane->id == 2)
  431. set = COMPHY_SELECTOR_USB3_PHY_SEL_BIT;
  432. else if (lane->id == 0)
  433. set = COMPHY_SELECTOR_USB3_GBE1_SEL_BIT;
  434. else
  435. goto error;
  436. break;
  437. case PHY_MODE_PCIE:
  438. /* PCIE must be in Lane1 */
  439. if (lane->id == 1)
  440. set = COMPHY_SELECTOR_PCIE_GBE0_SEL_BIT;
  441. else
  442. goto error;
  443. break;
  444. default:
  445. goto error;
  446. }
  447. spin_lock_irqsave(&lane->priv->lock, flags);
  448. old = readl(lane->priv->comphy_regs + COMPHY_SELECTOR_PHY_REG);
  449. new = (old & ~clr) | set;
  450. writel(new, lane->priv->comphy_regs + COMPHY_SELECTOR_PHY_REG);
  451. spin_unlock_irqrestore(&lane->priv->lock, flags);
  452. dev_dbg(lane->dev,
  453. "COMPHY[%d] mode[%d] changed PHY selector 0x%08x -> 0x%08x\n",
  454. lane->id, lane->mode, old, new);
  455. return 0;
  456. error:
  457. dev_err(lane->dev, "COMPHY[%d] mode[%d] is invalid\n", lane->id,
  458. lane->mode);
  459. return -EINVAL;
  460. }
  461. static int
  462. mvebu_a3700_comphy_sata_power_on(struct mvebu_a3700_comphy_lane *lane)
  463. {
  464. u32 mask, data, ref_clk;
  465. int ret;
  466. /* Configure phy selector for SATA */
  467. ret = mvebu_a3700_comphy_set_phy_selector(lane);
  468. if (ret)
  469. return ret;
  470. /* Clear phy isolation mode to make it work in normal mode */
  471. comphy_lane_reg_set(lane, COMPHY_ISOLATION_CTRL,
  472. 0x0, PHY_ISOLATE_MODE);
  473. /* 0. Check the Polarity invert bits */
  474. data = 0x0;
  475. if (lane->invert_tx)
  476. data |= TXD_INVERT_BIT;
  477. if (lane->invert_rx)
  478. data |= RXD_INVERT_BIT;
  479. mask = TXD_INVERT_BIT | RXD_INVERT_BIT;
  480. comphy_lane_reg_set(lane, COMPHY_SYNC_PATTERN, data, mask);
  481. /* 1. Select 40-bit data width */
  482. comphy_lane_reg_set(lane, COMPHY_DIG_LOOPBACK_EN,
  483. DATA_WIDTH_40BIT, SEL_DATA_WIDTH_MASK);
  484. /* 2. Select reference clock(25M) and PHY mode (SATA) */
  485. if (lane->priv->xtal_is_40m)
  486. ref_clk = REF_FREF_SEL_SERDES_40MHZ;
  487. else
  488. ref_clk = REF_FREF_SEL_SERDES_25MHZ;
  489. data = ref_clk | COMPHY_MODE_SATA;
  490. mask = REF_FREF_SEL_MASK | COMPHY_MODE_MASK;
  491. comphy_lane_reg_set(lane, COMPHY_POWER_PLL_CTRL, data, mask);
  492. /* 3. Use maximum PLL rate (no power save) */
  493. comphy_lane_reg_set(lane, COMPHY_KVCO_CAL_CTRL,
  494. USE_MAX_PLL_RATE_BIT, USE_MAX_PLL_RATE_BIT);
  495. /* 4. Reset reserved bit */
  496. comphy_set_indirect(lane->priv, COMPHY_RESERVED_REG,
  497. 0x0, PHYCTRL_FRM_PIN_BIT);
  498. /* 5. Set vendor-specific configuration (It is done in sata driver) */
  499. /* XXX: in U-Boot below sequence was executed in this place, in Linux
  500. * not. Now it is done only in U-Boot before this comphy
  501. * initialization - tests shows that it works ok, but in case of any
  502. * future problem it is left for reference.
  503. * reg_set(MVEBU_REGS_BASE + 0xe00a0, 0, 0xffffffff);
  504. * reg_set(MVEBU_REGS_BASE + 0xe00a4, BIT(6), BIT(6));
  505. */
  506. /* Wait for > 55 us to allow PLL be enabled */
  507. udelay(PLL_SET_DELAY_US);
  508. /* Polling status */
  509. ret = comphy_lane_reg_poll(lane, COMPHY_DIG_LOOPBACK_EN,
  510. PLL_READY_TX_BIT, COMPHY_PLL_SLEEP,
  511. COMPHY_PLL_TIMEOUT);
  512. if (ret)
  513. dev_err(lane->dev, "Failed to lock SATA PLL\n");
  514. return ret;
  515. }
  516. static void comphy_gbe_phy_init(struct mvebu_a3700_comphy_lane *lane,
  517. bool is_1gbps)
  518. {
  519. int addr, fix_idx;
  520. u16 val;
  521. fix_idx = 0;
  522. for (addr = 0; addr < 512; addr++) {
  523. /*
  524. * All PHY register values are defined in full for 3.125Gbps
  525. * SERDES speed. The values required for 1.25 Gbps are almost
  526. * the same and only few registers should be "fixed" in
  527. * comparison to 3.125 Gbps values. These register values are
  528. * stored in "gbe_phy_init_fix" array.
  529. */
  530. if (!is_1gbps && gbe_phy_init_fix[fix_idx].addr == addr) {
  531. /* Use new value */
  532. val = gbe_phy_init_fix[fix_idx].value;
  533. if (fix_idx < ARRAY_SIZE(gbe_phy_init_fix))
  534. fix_idx++;
  535. } else {
  536. val = gbe_phy_init[addr];
  537. }
  538. comphy_lane_reg_set(lane, addr, val, 0xFFFF);
  539. }
  540. }
  541. static int
  542. mvebu_a3700_comphy_ethernet_power_on(struct mvebu_a3700_comphy_lane *lane)
  543. {
  544. u32 mask, data, speed_sel;
  545. int ret;
  546. /* Set selector */
  547. ret = mvebu_a3700_comphy_set_phy_selector(lane);
  548. if (ret)
  549. return ret;
  550. /*
  551. * 1. Reset PHY by setting PHY input port PIN_RESET=1.
  552. * 2. Set PHY input port PIN_TX_IDLE=1, PIN_PU_IVREF=1 to keep
  553. * PHY TXP/TXN output to idle state during PHY initialization
  554. * 3. Set PHY input port PIN_PU_PLL=0, PIN_PU_RX=0, PIN_PU_TX=0.
  555. */
  556. data = PIN_PU_IVREF_BIT | PIN_TX_IDLE_BIT | PIN_RESET_COMPHY_BIT;
  557. mask = data | PIN_RESET_CORE_BIT | PIN_PU_PLL_BIT | PIN_PU_RX_BIT |
  558. PIN_PU_TX_BIT | PHY_RX_INIT_BIT;
  559. comphy_periph_reg_set(lane, COMPHY_PHY_CFG1, data, mask);
  560. /* 4. Release reset to the PHY by setting PIN_RESET=0. */
  561. data = 0x0;
  562. mask = PIN_RESET_COMPHY_BIT;
  563. comphy_periph_reg_set(lane, COMPHY_PHY_CFG1, data, mask);
  564. /*
  565. * 5. Set PIN_PHY_GEN_TX[3:0] and PIN_PHY_GEN_RX[3:0] to decide COMPHY
  566. * bit rate
  567. */
  568. switch (lane->submode) {
  569. case PHY_INTERFACE_MODE_SGMII:
  570. case PHY_INTERFACE_MODE_1000BASEX:
  571. /* SGMII 1G, SerDes speed 1.25G */
  572. speed_sel = SERDES_SPEED_1_25_G;
  573. break;
  574. case PHY_INTERFACE_MODE_2500BASEX:
  575. /* 2500Base-X, SerDes speed 3.125G */
  576. speed_sel = SERDES_SPEED_3_125_G;
  577. break;
  578. default:
  579. /* Other rates are not supported */
  580. dev_err(lane->dev,
  581. "unsupported phy speed %d on comphy lane%d\n",
  582. lane->submode, lane->id);
  583. return -EINVAL;
  584. }
  585. data = GEN_RX_SEL_VALUE(speed_sel) | GEN_TX_SEL_VALUE(speed_sel);
  586. mask = GEN_RX_SEL_MASK | GEN_TX_SEL_MASK;
  587. comphy_periph_reg_set(lane, COMPHY_PHY_CFG1, data, mask);
  588. /*
  589. * 6. Wait 10mS for bandgap and reference clocks to stabilize; then
  590. * start SW programming.
  591. */
  592. mdelay(10);
  593. /* 7. Program COMPHY register PHY_MODE */
  594. data = COMPHY_MODE_SERDES;
  595. mask = COMPHY_MODE_MASK;
  596. comphy_lane_reg_set(lane, COMPHY_POWER_PLL_CTRL, data, mask);
  597. /*
  598. * 8. Set COMPHY register REFCLK_SEL to select the correct REFCLK
  599. * source
  600. */
  601. data = 0x0;
  602. mask = PHY_REF_CLK_SEL;
  603. comphy_lane_reg_set(lane, COMPHY_MISC_CTRL0, data, mask);
  604. /*
  605. * 9. Set correct reference clock frequency in COMPHY register
  606. * REF_FREF_SEL.
  607. */
  608. if (lane->priv->xtal_is_40m)
  609. data = REF_FREF_SEL_SERDES_50MHZ;
  610. else
  611. data = REF_FREF_SEL_SERDES_25MHZ;
  612. mask = REF_FREF_SEL_MASK;
  613. comphy_lane_reg_set(lane, COMPHY_POWER_PLL_CTRL, data, mask);
  614. /*
  615. * 10. Program COMPHY register PHY_GEN_MAX[1:0]
  616. * This step is mentioned in the flow received from verification team.
  617. * However the PHY_GEN_MAX value is only meaningful for other interfaces
  618. * (not SERDES). For instance, it selects SATA speed 1.5/3/6 Gbps or
  619. * PCIe speed 2.5/5 Gbps
  620. */
  621. /*
  622. * 11. Program COMPHY register SEL_BITS to set correct parallel data
  623. * bus width
  624. */
  625. data = DATA_WIDTH_10BIT;
  626. mask = SEL_DATA_WIDTH_MASK;
  627. comphy_lane_reg_set(lane, COMPHY_DIG_LOOPBACK_EN, data, mask);
  628. /*
  629. * 12. As long as DFE function needs to be enabled in any mode,
  630. * COMPHY register DFE_UPDATE_EN[5:0] shall be programmed to 0x3F
  631. * for real chip during COMPHY power on.
  632. * The value of the DFE_UPDATE_EN already is 0x3F, because it is the
  633. * default value after reset of the PHY.
  634. */
  635. /*
  636. * 13. Program COMPHY GEN registers.
  637. * These registers should be programmed based on the lab testing result
  638. * to achieve optimal performance. Please contact the CEA group to get
  639. * the related GEN table during real chip bring-up. We only required to
  640. * run though the entire registers programming flow defined by
  641. * "comphy_gbe_phy_init" when the REF clock is 40 MHz. For REF clock
  642. * 25 MHz the default values stored in PHY registers are OK.
  643. */
  644. dev_dbg(lane->dev, "Running C-DPI phy init %s mode\n",
  645. lane->submode == PHY_INTERFACE_MODE_2500BASEX ? "2G5" : "1G");
  646. if (lane->priv->xtal_is_40m)
  647. comphy_gbe_phy_init(lane,
  648. lane->submode != PHY_INTERFACE_MODE_2500BASEX);
  649. /*
  650. * 14. Check the PHY Polarity invert bit
  651. */
  652. data = 0x0;
  653. if (lane->invert_tx)
  654. data |= TXD_INVERT_BIT;
  655. if (lane->invert_rx)
  656. data |= RXD_INVERT_BIT;
  657. mask = TXD_INVERT_BIT | RXD_INVERT_BIT;
  658. comphy_lane_reg_set(lane, COMPHY_SYNC_PATTERN, data, mask);
  659. /*
  660. * 15. Set PHY input ports PIN_PU_PLL, PIN_PU_TX and PIN_PU_RX to 1 to
  661. * start PHY power up sequence. All the PHY register programming should
  662. * be done before PIN_PU_PLL=1. There should be no register programming
  663. * for normal PHY operation from this point.
  664. */
  665. data = PIN_PU_PLL_BIT | PIN_PU_RX_BIT | PIN_PU_TX_BIT;
  666. mask = data;
  667. comphy_periph_reg_set(lane, COMPHY_PHY_CFG1, data, mask);
  668. /*
  669. * 16. Wait for PHY power up sequence to finish by checking output ports
  670. * PIN_PLL_READY_TX=1 and PIN_PLL_READY_RX=1.
  671. */
  672. ret = comphy_periph_reg_poll(lane, COMPHY_PHY_STAT1,
  673. PHY_PLL_READY_TX_BIT |
  674. PHY_PLL_READY_RX_BIT,
  675. COMPHY_PLL_SLEEP, COMPHY_PLL_TIMEOUT);
  676. if (ret) {
  677. dev_err(lane->dev, "Failed to lock PLL for SERDES PHY %d\n",
  678. lane->id);
  679. return ret;
  680. }
  681. /*
  682. * 17. Set COMPHY input port PIN_TX_IDLE=0
  683. */
  684. comphy_periph_reg_set(lane, COMPHY_PHY_CFG1, 0x0, PIN_TX_IDLE_BIT);
  685. /*
  686. * 18. After valid data appear on PIN_RXDATA bus, set PIN_RX_INIT=1. To
  687. * start RX initialization. PIN_RX_INIT_DONE will be cleared to 0 by the
  688. * PHY After RX initialization is done, PIN_RX_INIT_DONE will be set to
  689. * 1 by COMPHY Set PIN_RX_INIT=0 after PIN_RX_INIT_DONE= 1. Please
  690. * refer to RX initialization part for details.
  691. */
  692. comphy_periph_reg_set(lane, COMPHY_PHY_CFG1,
  693. PHY_RX_INIT_BIT, PHY_RX_INIT_BIT);
  694. ret = comphy_periph_reg_poll(lane, COMPHY_PHY_STAT1,
  695. PHY_PLL_READY_TX_BIT |
  696. PHY_PLL_READY_RX_BIT,
  697. COMPHY_PLL_SLEEP, COMPHY_PLL_TIMEOUT);
  698. if (ret) {
  699. dev_err(lane->dev, "Failed to lock PLL for SERDES PHY %d\n",
  700. lane->id);
  701. return ret;
  702. }
  703. ret = comphy_periph_reg_poll(lane, COMPHY_PHY_STAT1,
  704. PHY_RX_INIT_DONE_BIT,
  705. COMPHY_PLL_SLEEP, COMPHY_PLL_TIMEOUT);
  706. if (ret)
  707. dev_err(lane->dev, "Failed to init RX of SERDES PHY %d\n",
  708. lane->id);
  709. return ret;
  710. }
  711. static int
  712. mvebu_a3700_comphy_usb3_power_on(struct mvebu_a3700_comphy_lane *lane)
  713. {
  714. u32 mask, data, cfg, ref_clk;
  715. int ret;
  716. /* Set phy seclector */
  717. ret = mvebu_a3700_comphy_set_phy_selector(lane);
  718. if (ret)
  719. return ret;
  720. /* COMPHY register reset (cleared automatically) */
  721. comphy_lane_reg_set(lane, COMPHY_SFT_RESET, SFT_RST, SFT_RST);
  722. /*
  723. * 0. Set PHY OTG Control(0x5d034), bit 4, Power up OTG module The
  724. * register belong to UTMI module, so it is set in UTMI phy driver.
  725. */
  726. /*
  727. * 1. Set PRD_TXDEEMPH (3.5db de-emph)
  728. */
  729. data = PRD_TXDEEMPH0_MASK;
  730. mask = PRD_TXDEEMPH0_MASK | PRD_TXMARGIN_MASK | PRD_TXSWING_MASK |
  731. CFG_TX_ALIGN_POS_MASK;
  732. comphy_lane_reg_set(lane, COMPHY_PIPE_LANE_CFG0, data, mask);
  733. /*
  734. * 2. Set BIT0: enable transmitter in high impedance mode
  735. * Set BIT[3:4]: delay 2 clock cycles for HiZ off latency
  736. * Set BIT6: Tx detect Rx at HiZ mode
  737. * Unset BIT15: set to 0 to set USB3 De-emphasize level to -3.5db
  738. * together with bit 0 of COMPHY_PIPE_LANE_CFG0 register
  739. */
  740. data = TX_DET_RX_MODE | GEN2_TX_DATA_DLY_DEFT | TX_ELEC_IDLE_MODE_EN;
  741. mask = PRD_TXDEEMPH1_MASK | TX_DET_RX_MODE | GEN2_TX_DATA_DLY_MASK |
  742. TX_ELEC_IDLE_MODE_EN;
  743. comphy_lane_reg_set(lane, COMPHY_PIPE_LANE_CFG1, data, mask);
  744. /*
  745. * 3. Set Spread Spectrum Clock Enabled
  746. */
  747. comphy_lane_reg_set(lane, COMPHY_PIPE_LANE_CFG4,
  748. SPREAD_SPECTRUM_CLK_EN, SPREAD_SPECTRUM_CLK_EN);
  749. /*
  750. * 4. Set Override Margining Controls From the MAC:
  751. * Use margining signals from lane configuration
  752. */
  753. comphy_lane_reg_set(lane, COMPHY_PIPE_TEST_MODE_CTRL,
  754. MODE_MARGIN_OVERRIDE, 0xFFFF);
  755. /*
  756. * 5. Set Lane-to-Lane Bundle Clock Sampling Period = per PCLK cycles
  757. * set Mode Clock Source = PCLK is generated from REFCLK
  758. */
  759. data = 0x0;
  760. mask = MODE_CLK_SRC | BUNDLE_PERIOD_SEL | BUNDLE_PERIOD_SCALE_MASK |
  761. BUNDLE_SAMPLE_CTRL | PLL_READY_DLY_MASK;
  762. comphy_lane_reg_set(lane, COMPHY_PIPE_CLK_SRC_LO, data, mask);
  763. /*
  764. * 6. Set G2 Spread Spectrum Clock Amplitude at 4K
  765. */
  766. comphy_lane_reg_set(lane, COMPHY_GEN2_SET2,
  767. GS2_TX_SSC_AMP_4128, GS2_TX_SSC_AMP_MASK);
  768. /*
  769. * 7. Unset G3 Spread Spectrum Clock Amplitude
  770. * set G3 TX and RX Register Master Current Select
  771. */
  772. data = GS2_VREG_RXTX_MAS_ISET_60U;
  773. mask = GS2_TX_SSC_AMP_MASK | GS2_VREG_RXTX_MAS_ISET_MASK |
  774. GS2_RSVD_6_0_MASK;
  775. comphy_lane_reg_set(lane, COMPHY_GEN3_SET2, data, mask);
  776. /*
  777. * 8. Check crystal jumper setting and program the Power and PLL Control
  778. * accordingly Change RX wait
  779. */
  780. if (lane->priv->xtal_is_40m) {
  781. ref_clk = REF_FREF_SEL_PCIE_USB3_40MHZ;
  782. cfg = CFG_PM_RXDLOZ_WAIT_12_UNIT;
  783. } else {
  784. ref_clk = REF_FREF_SEL_PCIE_USB3_25MHZ;
  785. cfg = CFG_PM_RXDLOZ_WAIT_7_UNIT;
  786. }
  787. data = PU_IVREF_BIT | PU_PLL_BIT | PU_RX_BIT | PU_TX_BIT |
  788. PU_TX_INTP_BIT | PU_DFE_BIT | COMPHY_MODE_USB3 | ref_clk;
  789. mask = PU_IVREF_BIT | PU_PLL_BIT | PU_RX_BIT | PU_TX_BIT |
  790. PU_TX_INTP_BIT | PU_DFE_BIT | PLL_LOCK_BIT | COMPHY_MODE_MASK |
  791. REF_FREF_SEL_MASK;
  792. comphy_lane_reg_set(lane, COMPHY_POWER_PLL_CTRL, data, mask);
  793. data = CFG_PM_RXDEN_WAIT_1_UNIT | cfg;
  794. mask = CFG_PM_OSCCLK_WAIT_MASK | CFG_PM_RXDEN_WAIT_MASK |
  795. CFG_PM_RXDLOZ_WAIT_MASK;
  796. comphy_lane_reg_set(lane, COMPHY_PIPE_PWR_MGM_TIM1, data, mask);
  797. /*
  798. * 9. Enable idle sync
  799. */
  800. comphy_lane_reg_set(lane, COMPHY_IDLE_SYNC_EN,
  801. IDLE_SYNC_EN, IDLE_SYNC_EN);
  802. /*
  803. * 10. Enable the output of 500M clock
  804. */
  805. comphy_lane_reg_set(lane, COMPHY_MISC_CTRL0, CLK500M_EN, CLK500M_EN);
  806. /*
  807. * 11. Set 20-bit data width
  808. */
  809. comphy_lane_reg_set(lane, COMPHY_DIG_LOOPBACK_EN,
  810. DATA_WIDTH_20BIT, 0xFFFF);
  811. /*
  812. * 12. Override Speed_PLL value and use MAC PLL
  813. */
  814. data = SPEED_PLL_VALUE_16 | USE_MAX_PLL_RATE_BIT;
  815. mask = 0xFFFF;
  816. comphy_lane_reg_set(lane, COMPHY_KVCO_CAL_CTRL, data, mask);
  817. /*
  818. * 13. Check the Polarity invert bit
  819. */
  820. data = 0x0;
  821. if (lane->invert_tx)
  822. data |= TXD_INVERT_BIT;
  823. if (lane->invert_rx)
  824. data |= RXD_INVERT_BIT;
  825. mask = TXD_INVERT_BIT | RXD_INVERT_BIT;
  826. comphy_lane_reg_set(lane, COMPHY_SYNC_PATTERN, data, mask);
  827. /*
  828. * 14. Set max speed generation to USB3.0 5Gbps
  829. */
  830. comphy_lane_reg_set(lane, COMPHY_SYNC_MASK_GEN,
  831. PHY_GEN_MAX_USB3_5G, PHY_GEN_MAX_MASK);
  832. /*
  833. * 15. Set capacitor value for FFE gain peaking to 0xF
  834. */
  835. comphy_lane_reg_set(lane, COMPHY_GEN2_SET3,
  836. GS3_FFE_CAP_SEL_VALUE, GS3_FFE_CAP_SEL_MASK);
  837. /*
  838. * 16. Release SW reset
  839. */
  840. data = MODE_CORE_CLK_FREQ_SEL | MODE_PIPE_WIDTH_32 | MODE_REFDIV_BY_4;
  841. mask = 0xFFFF;
  842. comphy_lane_reg_set(lane, COMPHY_PIPE_RST_CLK_CTRL, data, mask);
  843. /* Wait for > 55 us to allow PCLK be enabled */
  844. udelay(PLL_SET_DELAY_US);
  845. ret = comphy_lane_reg_poll(lane, COMPHY_PIPE_LANE_STAT1, TXDCLK_PCLK_EN,
  846. COMPHY_PLL_SLEEP, COMPHY_PLL_TIMEOUT);
  847. if (ret)
  848. dev_err(lane->dev, "Failed to lock USB3 PLL\n");
  849. return ret;
  850. }
  851. static int
  852. mvebu_a3700_comphy_pcie_power_on(struct mvebu_a3700_comphy_lane *lane)
  853. {
  854. u32 mask, data, ref_clk;
  855. int ret;
  856. /* Configure phy selector for PCIe */
  857. ret = mvebu_a3700_comphy_set_phy_selector(lane);
  858. if (ret)
  859. return ret;
  860. /* 1. Enable max PLL. */
  861. comphy_lane_reg_set(lane, COMPHY_PIPE_LANE_CFG1,
  862. USE_MAX_PLL_RATE_EN, USE_MAX_PLL_RATE_EN);
  863. /* 2. Select 20 bit SERDES interface. */
  864. comphy_lane_reg_set(lane, COMPHY_PIPE_CLK_SRC_LO,
  865. CFG_SEL_20B, CFG_SEL_20B);
  866. /* 3. Force to use reg setting for PCIe mode */
  867. comphy_lane_reg_set(lane, COMPHY_MISC_CTRL1,
  868. SEL_BITS_PCIE_FORCE, SEL_BITS_PCIE_FORCE);
  869. /* 4. Change RX wait */
  870. data = CFG_PM_RXDEN_WAIT_1_UNIT | CFG_PM_RXDLOZ_WAIT_12_UNIT;
  871. mask = CFG_PM_OSCCLK_WAIT_MASK | CFG_PM_RXDEN_WAIT_MASK |
  872. CFG_PM_RXDLOZ_WAIT_MASK;
  873. comphy_lane_reg_set(lane, COMPHY_PIPE_PWR_MGM_TIM1, data, mask);
  874. /* 5. Enable idle sync */
  875. comphy_lane_reg_set(lane, COMPHY_IDLE_SYNC_EN,
  876. IDLE_SYNC_EN, IDLE_SYNC_EN);
  877. /* 6. Enable the output of 100M/125M/500M clock */
  878. data = CLK500M_EN | TXDCLK_2X_SEL | CLK100M_125M_EN;
  879. mask = data;
  880. comphy_lane_reg_set(lane, COMPHY_MISC_CTRL0, data, mask);
  881. /*
  882. * 7. Enable TX, PCIE global register, 0xd0074814, it is done in
  883. * PCI-E driver
  884. */
  885. /*
  886. * 8. Check crystal jumper setting and program the Power and PLL
  887. * Control accordingly
  888. */
  889. if (lane->priv->xtal_is_40m)
  890. ref_clk = REF_FREF_SEL_PCIE_USB3_40MHZ;
  891. else
  892. ref_clk = REF_FREF_SEL_PCIE_USB3_25MHZ;
  893. data = PU_IVREF_BIT | PU_PLL_BIT | PU_RX_BIT | PU_TX_BIT |
  894. PU_TX_INTP_BIT | PU_DFE_BIT | COMPHY_MODE_PCIE | ref_clk;
  895. mask = 0xFFFF;
  896. comphy_lane_reg_set(lane, COMPHY_POWER_PLL_CTRL, data, mask);
  897. /* 9. Override Speed_PLL value and use MAC PLL */
  898. comphy_lane_reg_set(lane, COMPHY_KVCO_CAL_CTRL,
  899. SPEED_PLL_VALUE_16 | USE_MAX_PLL_RATE_BIT,
  900. 0xFFFF);
  901. /* 10. Check the Polarity invert bit */
  902. data = 0x0;
  903. if (lane->invert_tx)
  904. data |= TXD_INVERT_BIT;
  905. if (lane->invert_rx)
  906. data |= RXD_INVERT_BIT;
  907. mask = TXD_INVERT_BIT | RXD_INVERT_BIT;
  908. comphy_lane_reg_set(lane, COMPHY_SYNC_PATTERN, data, mask);
  909. /* 11. Release SW reset */
  910. data = MODE_CORE_CLK_FREQ_SEL | MODE_PIPE_WIDTH_32;
  911. mask = data | PIPE_SOFT_RESET | MODE_REFDIV_MASK;
  912. comphy_lane_reg_set(lane, COMPHY_PIPE_RST_CLK_CTRL, data, mask);
  913. /* Wait for > 55 us to allow PCLK be enabled */
  914. udelay(PLL_SET_DELAY_US);
  915. ret = comphy_lane_reg_poll(lane, COMPHY_PIPE_LANE_STAT1, TXDCLK_PCLK_EN,
  916. COMPHY_PLL_SLEEP, COMPHY_PLL_TIMEOUT);
  917. if (ret)
  918. dev_err(lane->dev, "Failed to lock PCIE PLL\n");
  919. return ret;
  920. }
  921. static void
  922. mvebu_a3700_comphy_sata_power_off(struct mvebu_a3700_comphy_lane *lane)
  923. {
  924. /* Set phy isolation mode */
  925. comphy_lane_reg_set(lane, COMPHY_ISOLATION_CTRL,
  926. PHY_ISOLATE_MODE, PHY_ISOLATE_MODE);
  927. /* Power off PLL, Tx, Rx */
  928. comphy_lane_reg_set(lane, COMPHY_POWER_PLL_CTRL,
  929. 0x0, PU_PLL_BIT | PU_RX_BIT | PU_TX_BIT);
  930. }
  931. static void
  932. mvebu_a3700_comphy_ethernet_power_off(struct mvebu_a3700_comphy_lane *lane)
  933. {
  934. u32 mask, data;
  935. data = PIN_RESET_CORE_BIT | PIN_RESET_COMPHY_BIT | PIN_PU_IVREF_BIT |
  936. PHY_RX_INIT_BIT;
  937. mask = data;
  938. comphy_periph_reg_set(lane, COMPHY_PHY_CFG1, data, mask);
  939. }
  940. static void
  941. mvebu_a3700_comphy_pcie_power_off(struct mvebu_a3700_comphy_lane *lane)
  942. {
  943. /* Power off PLL, Tx, Rx */
  944. comphy_lane_reg_set(lane, COMPHY_POWER_PLL_CTRL,
  945. 0x0, PU_PLL_BIT | PU_RX_BIT | PU_TX_BIT);
  946. }
  947. static void mvebu_a3700_comphy_usb3_power_off(struct mvebu_a3700_comphy_lane *lane)
  948. {
  949. /*
  950. * The USB3 MAC sets the USB3 PHY to low state, so we do not
  951. * need to power off USB3 PHY again.
  952. */
  953. }
  954. static bool mvebu_a3700_comphy_check_mode(int lane,
  955. enum phy_mode mode,
  956. int submode)
  957. {
  958. int i, n = ARRAY_SIZE(mvebu_a3700_comphy_modes);
  959. /* Unused PHY mux value is 0x0 */
  960. if (mode == PHY_MODE_INVALID)
  961. return false;
  962. for (i = 0; i < n; i++) {
  963. if (mvebu_a3700_comphy_modes[i].lane == lane &&
  964. mvebu_a3700_comphy_modes[i].mode == mode &&
  965. mvebu_a3700_comphy_modes[i].submode == submode)
  966. break;
  967. }
  968. if (i == n)
  969. return false;
  970. return true;
  971. }
  972. static int mvebu_a3700_comphy_set_mode(struct phy *phy, enum phy_mode mode,
  973. int submode)
  974. {
  975. struct mvebu_a3700_comphy_lane *lane = phy_get_drvdata(phy);
  976. if (!mvebu_a3700_comphy_check_mode(lane->id, mode, submode)) {
  977. dev_err(lane->dev, "invalid COMPHY mode\n");
  978. return -EINVAL;
  979. }
  980. /* Mode cannot be changed while the PHY is powered on */
  981. if (phy->power_count &&
  982. (lane->mode != mode || lane->submode != submode))
  983. return -EBUSY;
  984. /* Just remember the mode, ->power_on() will do the real setup */
  985. lane->mode = mode;
  986. lane->submode = submode;
  987. return 0;
  988. }
  989. static int mvebu_a3700_comphy_power_on(struct phy *phy)
  990. {
  991. struct mvebu_a3700_comphy_lane *lane = phy_get_drvdata(phy);
  992. if (!mvebu_a3700_comphy_check_mode(lane->id, lane->mode,
  993. lane->submode)) {
  994. dev_err(lane->dev, "invalid COMPHY mode\n");
  995. return -EINVAL;
  996. }
  997. switch (lane->mode) {
  998. case PHY_MODE_USB_HOST_SS:
  999. dev_dbg(lane->dev, "set lane %d to USB3 host mode\n", lane->id);
  1000. return mvebu_a3700_comphy_usb3_power_on(lane);
  1001. case PHY_MODE_SATA:
  1002. dev_dbg(lane->dev, "set lane %d to SATA mode\n", lane->id);
  1003. return mvebu_a3700_comphy_sata_power_on(lane);
  1004. case PHY_MODE_ETHERNET:
  1005. dev_dbg(lane->dev, "set lane %d to Ethernet mode\n", lane->id);
  1006. return mvebu_a3700_comphy_ethernet_power_on(lane);
  1007. case PHY_MODE_PCIE:
  1008. dev_dbg(lane->dev, "set lane %d to PCIe mode\n", lane->id);
  1009. return mvebu_a3700_comphy_pcie_power_on(lane);
  1010. default:
  1011. dev_err(lane->dev, "unsupported PHY mode (%d)\n", lane->mode);
  1012. return -EOPNOTSUPP;
  1013. }
  1014. }
  1015. static int mvebu_a3700_comphy_power_off(struct phy *phy)
  1016. {
  1017. struct mvebu_a3700_comphy_lane *lane = phy_get_drvdata(phy);
  1018. switch (lane->id) {
  1019. case 0:
  1020. mvebu_a3700_comphy_usb3_power_off(lane);
  1021. mvebu_a3700_comphy_ethernet_power_off(lane);
  1022. return 0;
  1023. case 1:
  1024. mvebu_a3700_comphy_pcie_power_off(lane);
  1025. mvebu_a3700_comphy_ethernet_power_off(lane);
  1026. return 0;
  1027. case 2:
  1028. mvebu_a3700_comphy_usb3_power_off(lane);
  1029. mvebu_a3700_comphy_sata_power_off(lane);
  1030. return 0;
  1031. default:
  1032. dev_err(lane->dev, "invalid COMPHY mode\n");
  1033. return -EINVAL;
  1034. }
  1035. }
  1036. static const struct phy_ops mvebu_a3700_comphy_ops = {
  1037. .power_on = mvebu_a3700_comphy_power_on,
  1038. .power_off = mvebu_a3700_comphy_power_off,
  1039. .set_mode = mvebu_a3700_comphy_set_mode,
  1040. .owner = THIS_MODULE,
  1041. };
  1042. static struct phy *mvebu_a3700_comphy_xlate(struct device *dev,
  1043. struct of_phandle_args *args)
  1044. {
  1045. struct mvebu_a3700_comphy_lane *lane;
  1046. unsigned int port;
  1047. struct phy *phy;
  1048. phy = of_phy_simple_xlate(dev, args);
  1049. if (IS_ERR(phy))
  1050. return phy;
  1051. lane = phy_get_drvdata(phy);
  1052. port = args->args[0];
  1053. if (port != 0 && (port != 1 || lane->id != 0)) {
  1054. dev_err(lane->dev, "invalid port number %u\n", port);
  1055. return ERR_PTR(-EINVAL);
  1056. }
  1057. lane->invert_tx = args->args[1] & BIT(0);
  1058. lane->invert_rx = args->args[1] & BIT(1);
  1059. return phy;
  1060. }
  1061. static int mvebu_a3700_comphy_probe(struct platform_device *pdev)
  1062. {
  1063. struct mvebu_a3700_comphy_priv *priv;
  1064. struct phy_provider *provider;
  1065. struct device_node *child;
  1066. struct resource *res;
  1067. struct clk *clk;
  1068. int ret;
  1069. priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
  1070. if (!priv)
  1071. return -ENOMEM;
  1072. spin_lock_init(&priv->lock);
  1073. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "comphy");
  1074. priv->comphy_regs = devm_ioremap_resource(&pdev->dev, res);
  1075. if (IS_ERR(priv->comphy_regs))
  1076. return PTR_ERR(priv->comphy_regs);
  1077. res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  1078. "lane1_pcie_gbe");
  1079. priv->lane1_phy_regs = devm_ioremap_resource(&pdev->dev, res);
  1080. if (IS_ERR(priv->lane1_phy_regs))
  1081. return PTR_ERR(priv->lane1_phy_regs);
  1082. res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  1083. "lane0_usb3_gbe");
  1084. priv->lane0_phy_regs = devm_ioremap_resource(&pdev->dev, res);
  1085. if (IS_ERR(priv->lane0_phy_regs))
  1086. return PTR_ERR(priv->lane0_phy_regs);
  1087. res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  1088. "lane2_sata_usb3");
  1089. priv->lane2_phy_indirect = devm_ioremap_resource(&pdev->dev, res);
  1090. if (IS_ERR(priv->lane2_phy_indirect))
  1091. return PTR_ERR(priv->lane2_phy_indirect);
  1092. /*
  1093. * Driver needs to know if reference xtal clock is 40MHz or 25MHz.
  1094. * Old DT bindings do not have xtal clk present. So do not fail here
  1095. * and expects that default 25MHz reference clock is used.
  1096. */
  1097. clk = clk_get(&pdev->dev, "xtal");
  1098. if (IS_ERR(clk)) {
  1099. if (PTR_ERR(clk) == -EPROBE_DEFER)
  1100. return -EPROBE_DEFER;
  1101. dev_warn(&pdev->dev, "missing 'xtal' clk (%ld)\n",
  1102. PTR_ERR(clk));
  1103. } else {
  1104. ret = clk_prepare_enable(clk);
  1105. if (ret) {
  1106. dev_warn(&pdev->dev, "enabling xtal clk failed (%d)\n",
  1107. ret);
  1108. } else {
  1109. if (clk_get_rate(clk) == 40000000)
  1110. priv->xtal_is_40m = true;
  1111. clk_disable_unprepare(clk);
  1112. }
  1113. clk_put(clk);
  1114. }
  1115. dev_set_drvdata(&pdev->dev, priv);
  1116. for_each_available_child_of_node(pdev->dev.of_node, child) {
  1117. struct mvebu_a3700_comphy_lane *lane;
  1118. struct phy *phy;
  1119. int ret;
  1120. u32 lane_id;
  1121. ret = of_property_read_u32(child, "reg", &lane_id);
  1122. if (ret < 0) {
  1123. dev_err(&pdev->dev, "missing 'reg' property (%d)\n",
  1124. ret);
  1125. continue;
  1126. }
  1127. if (lane_id >= 3) {
  1128. dev_err(&pdev->dev, "invalid 'reg' property\n");
  1129. continue;
  1130. }
  1131. lane = devm_kzalloc(&pdev->dev, sizeof(*lane), GFP_KERNEL);
  1132. if (!lane) {
  1133. of_node_put(child);
  1134. return -ENOMEM;
  1135. }
  1136. phy = devm_phy_create(&pdev->dev, child,
  1137. &mvebu_a3700_comphy_ops);
  1138. if (IS_ERR(phy)) {
  1139. of_node_put(child);
  1140. return PTR_ERR(phy);
  1141. }
  1142. lane->priv = priv;
  1143. lane->dev = &pdev->dev;
  1144. lane->mode = PHY_MODE_INVALID;
  1145. lane->submode = PHY_INTERFACE_MODE_NA;
  1146. lane->id = lane_id;
  1147. lane->invert_tx = false;
  1148. lane->invert_rx = false;
  1149. phy_set_drvdata(phy, lane);
  1150. /*
  1151. * To avoid relying on the bootloader/firmware configuration,
  1152. * power off all comphys.
  1153. */
  1154. mvebu_a3700_comphy_power_off(phy);
  1155. }
  1156. provider = devm_of_phy_provider_register(&pdev->dev,
  1157. mvebu_a3700_comphy_xlate);
  1158. return PTR_ERR_OR_ZERO(provider);
  1159. }
  1160. static const struct of_device_id mvebu_a3700_comphy_of_match_table[] = {
  1161. { .compatible = "marvell,comphy-a3700" },
  1162. { },
  1163. };
  1164. MODULE_DEVICE_TABLE(of, mvebu_a3700_comphy_of_match_table);
  1165. static struct platform_driver mvebu_a3700_comphy_driver = {
  1166. .probe = mvebu_a3700_comphy_probe,
  1167. .driver = {
  1168. .name = "mvebu-a3700-comphy",
  1169. .of_match_table = mvebu_a3700_comphy_of_match_table,
  1170. },
  1171. };
  1172. module_platform_driver(mvebu_a3700_comphy_driver);
  1173. MODULE_AUTHOR("Miquèl Raynal <[email protected]>");
  1174. MODULE_AUTHOR("Pali Rohár <[email protected]>");
  1175. MODULE_AUTHOR("Marek Behún <[email protected]>");
  1176. MODULE_DESCRIPTION("Common PHY driver for A3700");
  1177. MODULE_LICENSE("GPL v2");