phy-mvebu-a3700-comphy.c 42 KB

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