phy-sun6i-mipi-dphy.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2016 Allwinnertech Co., Ltd.
  4. * Copyright (C) 2017-2018 Bootlin
  5. *
  6. * Maxime Ripard <[email protected]>
  7. */
  8. #include <linux/bitops.h>
  9. #include <linux/clk.h>
  10. #include <linux/module.h>
  11. #include <linux/of_address.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/regmap.h>
  14. #include <linux/reset.h>
  15. #include <linux/phy/phy.h>
  16. #include <linux/phy/phy-mipi-dphy.h>
  17. #define SUN6I_DPHY_GCTL_REG 0x00
  18. #define SUN6I_DPHY_GCTL_LANE_NUM(n) ((((n) - 1) & 3) << 4)
  19. #define SUN6I_DPHY_GCTL_EN BIT(0)
  20. #define SUN6I_DPHY_TX_CTL_REG 0x04
  21. #define SUN6I_DPHY_TX_CTL_HS_TX_CLK_CONT BIT(28)
  22. #define SUN6I_DPHY_RX_CTL_REG 0x08
  23. #define SUN6I_DPHY_RX_CTL_EN_DBC BIT(31)
  24. #define SUN6I_DPHY_RX_CTL_RX_CLK_FORCE BIT(24)
  25. #define SUN6I_DPHY_RX_CTL_RX_D3_FORCE BIT(23)
  26. #define SUN6I_DPHY_RX_CTL_RX_D2_FORCE BIT(22)
  27. #define SUN6I_DPHY_RX_CTL_RX_D1_FORCE BIT(21)
  28. #define SUN6I_DPHY_RX_CTL_RX_D0_FORCE BIT(20)
  29. #define SUN6I_DPHY_TX_TIME0_REG 0x10
  30. #define SUN6I_DPHY_TX_TIME0_HS_TRAIL(n) (((n) & 0xff) << 24)
  31. #define SUN6I_DPHY_TX_TIME0_HS_PREPARE(n) (((n) & 0xff) << 16)
  32. #define SUN6I_DPHY_TX_TIME0_LP_CLK_DIV(n) ((n) & 0xff)
  33. #define SUN6I_DPHY_TX_TIME1_REG 0x14
  34. #define SUN6I_DPHY_TX_TIME1_CLK_POST(n) (((n) & 0xff) << 24)
  35. #define SUN6I_DPHY_TX_TIME1_CLK_PRE(n) (((n) & 0xff) << 16)
  36. #define SUN6I_DPHY_TX_TIME1_CLK_ZERO(n) (((n) & 0xff) << 8)
  37. #define SUN6I_DPHY_TX_TIME1_CLK_PREPARE(n) ((n) & 0xff)
  38. #define SUN6I_DPHY_TX_TIME2_REG 0x18
  39. #define SUN6I_DPHY_TX_TIME2_CLK_TRAIL(n) ((n) & 0xff)
  40. #define SUN6I_DPHY_TX_TIME3_REG 0x1c
  41. #define SUN6I_DPHY_TX_TIME4_REG 0x20
  42. #define SUN6I_DPHY_TX_TIME4_HS_TX_ANA1(n) (((n) & 0xff) << 8)
  43. #define SUN6I_DPHY_TX_TIME4_HS_TX_ANA0(n) ((n) & 0xff)
  44. #define SUN6I_DPHY_RX_TIME0_REG 0x30
  45. #define SUN6I_DPHY_RX_TIME0_HS_RX_SYNC(n) (((n) & 0xff) << 24)
  46. #define SUN6I_DPHY_RX_TIME0_HS_RX_CLK_MISS(n) (((n) & 0xff) << 16)
  47. #define SUN6I_DPHY_RX_TIME0_LP_RX(n) (((n) & 0xff) << 8)
  48. #define SUN6I_DPHY_RX_TIME1_REG 0x34
  49. #define SUN6I_DPHY_RX_TIME1_RX_DLY(n) (((n) & 0xfff) << 20)
  50. #define SUN6I_DPHY_RX_TIME1_LP_RX_ULPS_WP(n) ((n) & 0xfffff)
  51. #define SUN6I_DPHY_RX_TIME2_REG 0x38
  52. #define SUN6I_DPHY_RX_TIME2_HS_RX_ANA1(n) (((n) & 0xff) << 8)
  53. #define SUN6I_DPHY_RX_TIME2_HS_RX_ANA0(n) ((n) & 0xff)
  54. #define SUN6I_DPHY_RX_TIME3_REG 0x40
  55. #define SUN6I_DPHY_RX_TIME3_LPRST_DLY(n) (((n) & 0xffff) << 16)
  56. #define SUN6I_DPHY_ANA0_REG 0x4c
  57. #define SUN6I_DPHY_ANA0_REG_PWS BIT(31)
  58. #define SUN6I_DPHY_ANA0_REG_DMPC BIT(28)
  59. #define SUN6I_DPHY_ANA0_REG_DMPD(n) (((n) & 0xf) << 24)
  60. #define SUN6I_DPHY_ANA0_REG_SLV(n) (((n) & 7) << 12)
  61. #define SUN6I_DPHY_ANA0_REG_DEN(n) (((n) & 0xf) << 8)
  62. #define SUN6I_DPHY_ANA0_REG_SFB(n) (((n) & 3) << 2)
  63. #define SUN6I_DPHY_ANA1_REG 0x50
  64. #define SUN6I_DPHY_ANA1_REG_VTTMODE BIT(31)
  65. #define SUN6I_DPHY_ANA1_REG_CSMPS(n) (((n) & 3) << 28)
  66. #define SUN6I_DPHY_ANA1_REG_SVTT(n) (((n) & 0xf) << 24)
  67. #define SUN6I_DPHY_ANA2_REG 0x54
  68. #define SUN6I_DPHY_ANA2_EN_P2S_CPU(n) (((n) & 0xf) << 24)
  69. #define SUN6I_DPHY_ANA2_EN_P2S_CPU_MASK GENMASK(27, 24)
  70. #define SUN6I_DPHY_ANA2_EN_CK_CPU BIT(4)
  71. #define SUN6I_DPHY_ANA2_REG_ENIB BIT(1)
  72. #define SUN6I_DPHY_ANA3_REG 0x58
  73. #define SUN6I_DPHY_ANA3_EN_VTTD(n) (((n) & 0xf) << 28)
  74. #define SUN6I_DPHY_ANA3_EN_VTTD_MASK GENMASK(31, 28)
  75. #define SUN6I_DPHY_ANA3_EN_VTTC BIT(27)
  76. #define SUN6I_DPHY_ANA3_EN_DIV BIT(26)
  77. #define SUN6I_DPHY_ANA3_EN_LDOC BIT(25)
  78. #define SUN6I_DPHY_ANA3_EN_LDOD BIT(24)
  79. #define SUN6I_DPHY_ANA3_EN_LDOR BIT(18)
  80. #define SUN6I_DPHY_ANA4_REG 0x5c
  81. #define SUN6I_DPHY_ANA4_REG_DMPLVC BIT(24)
  82. #define SUN6I_DPHY_ANA4_REG_DMPLVD(n) (((n) & 0xf) << 20)
  83. #define SUN6I_DPHY_ANA4_REG_CKDV(n) (((n) & 0x1f) << 12)
  84. #define SUN6I_DPHY_ANA4_REG_TMSC(n) (((n) & 3) << 10)
  85. #define SUN6I_DPHY_ANA4_REG_TMSD(n) (((n) & 3) << 8)
  86. #define SUN6I_DPHY_ANA4_REG_TXDNSC(n) (((n) & 3) << 6)
  87. #define SUN6I_DPHY_ANA4_REG_TXDNSD(n) (((n) & 3) << 4)
  88. #define SUN6I_DPHY_ANA4_REG_TXPUSC(n) (((n) & 3) << 2)
  89. #define SUN6I_DPHY_ANA4_REG_TXPUSD(n) ((n) & 3)
  90. #define SUN6I_DPHY_DBG5_REG 0xf4
  91. enum sun6i_dphy_direction {
  92. SUN6I_DPHY_DIRECTION_TX,
  93. SUN6I_DPHY_DIRECTION_RX,
  94. };
  95. struct sun6i_dphy {
  96. struct clk *bus_clk;
  97. struct clk *mod_clk;
  98. struct regmap *regs;
  99. struct reset_control *reset;
  100. struct phy *phy;
  101. struct phy_configure_opts_mipi_dphy config;
  102. enum sun6i_dphy_direction direction;
  103. };
  104. static int sun6i_dphy_init(struct phy *phy)
  105. {
  106. struct sun6i_dphy *dphy = phy_get_drvdata(phy);
  107. reset_control_deassert(dphy->reset);
  108. clk_prepare_enable(dphy->mod_clk);
  109. clk_set_rate_exclusive(dphy->mod_clk, 150000000);
  110. return 0;
  111. }
  112. static int sun6i_dphy_configure(struct phy *phy, union phy_configure_opts *opts)
  113. {
  114. struct sun6i_dphy *dphy = phy_get_drvdata(phy);
  115. int ret;
  116. ret = phy_mipi_dphy_config_validate(&opts->mipi_dphy);
  117. if (ret)
  118. return ret;
  119. memcpy(&dphy->config, opts, sizeof(dphy->config));
  120. return 0;
  121. }
  122. static int sun6i_dphy_tx_power_on(struct sun6i_dphy *dphy)
  123. {
  124. u8 lanes_mask = GENMASK(dphy->config.lanes - 1, 0);
  125. regmap_write(dphy->regs, SUN6I_DPHY_TX_CTL_REG,
  126. SUN6I_DPHY_TX_CTL_HS_TX_CLK_CONT);
  127. regmap_write(dphy->regs, SUN6I_DPHY_TX_TIME0_REG,
  128. SUN6I_DPHY_TX_TIME0_LP_CLK_DIV(14) |
  129. SUN6I_DPHY_TX_TIME0_HS_PREPARE(6) |
  130. SUN6I_DPHY_TX_TIME0_HS_TRAIL(10));
  131. regmap_write(dphy->regs, SUN6I_DPHY_TX_TIME1_REG,
  132. SUN6I_DPHY_TX_TIME1_CLK_PREPARE(7) |
  133. SUN6I_DPHY_TX_TIME1_CLK_ZERO(50) |
  134. SUN6I_DPHY_TX_TIME1_CLK_PRE(3) |
  135. SUN6I_DPHY_TX_TIME1_CLK_POST(10));
  136. regmap_write(dphy->regs, SUN6I_DPHY_TX_TIME2_REG,
  137. SUN6I_DPHY_TX_TIME2_CLK_TRAIL(30));
  138. regmap_write(dphy->regs, SUN6I_DPHY_TX_TIME3_REG, 0);
  139. regmap_write(dphy->regs, SUN6I_DPHY_TX_TIME4_REG,
  140. SUN6I_DPHY_TX_TIME4_HS_TX_ANA0(3) |
  141. SUN6I_DPHY_TX_TIME4_HS_TX_ANA1(3));
  142. regmap_write(dphy->regs, SUN6I_DPHY_GCTL_REG,
  143. SUN6I_DPHY_GCTL_LANE_NUM(dphy->config.lanes) |
  144. SUN6I_DPHY_GCTL_EN);
  145. regmap_write(dphy->regs, SUN6I_DPHY_ANA0_REG,
  146. SUN6I_DPHY_ANA0_REG_PWS |
  147. SUN6I_DPHY_ANA0_REG_DMPC |
  148. SUN6I_DPHY_ANA0_REG_SLV(7) |
  149. SUN6I_DPHY_ANA0_REG_DMPD(lanes_mask) |
  150. SUN6I_DPHY_ANA0_REG_DEN(lanes_mask));
  151. regmap_write(dphy->regs, SUN6I_DPHY_ANA1_REG,
  152. SUN6I_DPHY_ANA1_REG_CSMPS(1) |
  153. SUN6I_DPHY_ANA1_REG_SVTT(7));
  154. regmap_write(dphy->regs, SUN6I_DPHY_ANA4_REG,
  155. SUN6I_DPHY_ANA4_REG_CKDV(1) |
  156. SUN6I_DPHY_ANA4_REG_TMSC(1) |
  157. SUN6I_DPHY_ANA4_REG_TMSD(1) |
  158. SUN6I_DPHY_ANA4_REG_TXDNSC(1) |
  159. SUN6I_DPHY_ANA4_REG_TXDNSD(1) |
  160. SUN6I_DPHY_ANA4_REG_TXPUSC(1) |
  161. SUN6I_DPHY_ANA4_REG_TXPUSD(1) |
  162. SUN6I_DPHY_ANA4_REG_DMPLVC |
  163. SUN6I_DPHY_ANA4_REG_DMPLVD(lanes_mask));
  164. regmap_write(dphy->regs, SUN6I_DPHY_ANA2_REG,
  165. SUN6I_DPHY_ANA2_REG_ENIB);
  166. udelay(5);
  167. regmap_write(dphy->regs, SUN6I_DPHY_ANA3_REG,
  168. SUN6I_DPHY_ANA3_EN_LDOR |
  169. SUN6I_DPHY_ANA3_EN_LDOC |
  170. SUN6I_DPHY_ANA3_EN_LDOD);
  171. udelay(1);
  172. regmap_update_bits(dphy->regs, SUN6I_DPHY_ANA3_REG,
  173. SUN6I_DPHY_ANA3_EN_VTTC |
  174. SUN6I_DPHY_ANA3_EN_VTTD_MASK,
  175. SUN6I_DPHY_ANA3_EN_VTTC |
  176. SUN6I_DPHY_ANA3_EN_VTTD(lanes_mask));
  177. udelay(1);
  178. regmap_update_bits(dphy->regs, SUN6I_DPHY_ANA3_REG,
  179. SUN6I_DPHY_ANA3_EN_DIV,
  180. SUN6I_DPHY_ANA3_EN_DIV);
  181. udelay(1);
  182. regmap_update_bits(dphy->regs, SUN6I_DPHY_ANA2_REG,
  183. SUN6I_DPHY_ANA2_EN_CK_CPU,
  184. SUN6I_DPHY_ANA2_EN_CK_CPU);
  185. udelay(1);
  186. regmap_update_bits(dphy->regs, SUN6I_DPHY_ANA1_REG,
  187. SUN6I_DPHY_ANA1_REG_VTTMODE,
  188. SUN6I_DPHY_ANA1_REG_VTTMODE);
  189. regmap_update_bits(dphy->regs, SUN6I_DPHY_ANA2_REG,
  190. SUN6I_DPHY_ANA2_EN_P2S_CPU_MASK,
  191. SUN6I_DPHY_ANA2_EN_P2S_CPU(lanes_mask));
  192. return 0;
  193. }
  194. static int sun6i_dphy_rx_power_on(struct sun6i_dphy *dphy)
  195. {
  196. /* Physical clock rate is actually half of symbol rate with DDR. */
  197. unsigned long mipi_symbol_rate = dphy->config.hs_clk_rate;
  198. unsigned long dphy_clk_rate;
  199. unsigned int rx_dly;
  200. unsigned int lprst_dly;
  201. u32 value;
  202. dphy_clk_rate = clk_get_rate(dphy->mod_clk);
  203. if (!dphy_clk_rate)
  204. return -EINVAL;
  205. /* Hardcoded timing parameters from the Allwinner BSP. */
  206. regmap_write(dphy->regs, SUN6I_DPHY_RX_TIME0_REG,
  207. SUN6I_DPHY_RX_TIME0_HS_RX_SYNC(255) |
  208. SUN6I_DPHY_RX_TIME0_HS_RX_CLK_MISS(255) |
  209. SUN6I_DPHY_RX_TIME0_LP_RX(255));
  210. /*
  211. * Formula from the Allwinner BSP, with hardcoded coefficients
  212. * (probably internal divider/multiplier).
  213. */
  214. rx_dly = 8 * (unsigned int)(dphy_clk_rate / (mipi_symbol_rate / 8));
  215. /*
  216. * The Allwinner BSP has an alternative formula for LP_RX_ULPS_WP:
  217. * lp_ulps_wp_cnt = lp_ulps_wp_ms * lp_clk / 1000
  218. * but does not use it and hardcodes 255 instead.
  219. */
  220. regmap_write(dphy->regs, SUN6I_DPHY_RX_TIME1_REG,
  221. SUN6I_DPHY_RX_TIME1_RX_DLY(rx_dly) |
  222. SUN6I_DPHY_RX_TIME1_LP_RX_ULPS_WP(255));
  223. /* HS_RX_ANA0 value is hardcoded in the Allwinner BSP. */
  224. regmap_write(dphy->regs, SUN6I_DPHY_RX_TIME2_REG,
  225. SUN6I_DPHY_RX_TIME2_HS_RX_ANA0(4));
  226. /*
  227. * Formula from the Allwinner BSP, with hardcoded coefficients
  228. * (probably internal divider/multiplier).
  229. */
  230. lprst_dly = 4 * (unsigned int)(dphy_clk_rate / (mipi_symbol_rate / 2));
  231. regmap_write(dphy->regs, SUN6I_DPHY_RX_TIME3_REG,
  232. SUN6I_DPHY_RX_TIME3_LPRST_DLY(lprst_dly));
  233. /* Analog parameters are hardcoded in the Allwinner BSP. */
  234. regmap_write(dphy->regs, SUN6I_DPHY_ANA0_REG,
  235. SUN6I_DPHY_ANA0_REG_PWS |
  236. SUN6I_DPHY_ANA0_REG_SLV(7) |
  237. SUN6I_DPHY_ANA0_REG_SFB(2));
  238. regmap_write(dphy->regs, SUN6I_DPHY_ANA1_REG,
  239. SUN6I_DPHY_ANA1_REG_SVTT(4));
  240. regmap_write(dphy->regs, SUN6I_DPHY_ANA4_REG,
  241. SUN6I_DPHY_ANA4_REG_DMPLVC |
  242. SUN6I_DPHY_ANA4_REG_DMPLVD(1));
  243. regmap_write(dphy->regs, SUN6I_DPHY_ANA2_REG,
  244. SUN6I_DPHY_ANA2_REG_ENIB);
  245. regmap_write(dphy->regs, SUN6I_DPHY_ANA3_REG,
  246. SUN6I_DPHY_ANA3_EN_LDOR |
  247. SUN6I_DPHY_ANA3_EN_LDOC |
  248. SUN6I_DPHY_ANA3_EN_LDOD);
  249. /*
  250. * Delay comes from the Allwinner BSP, likely for internal regulator
  251. * ramp-up.
  252. */
  253. udelay(3);
  254. value = SUN6I_DPHY_RX_CTL_EN_DBC | SUN6I_DPHY_RX_CTL_RX_CLK_FORCE;
  255. /*
  256. * Rx data lane force-enable bits are used as regular RX enable by the
  257. * Allwinner BSP.
  258. */
  259. if (dphy->config.lanes >= 1)
  260. value |= SUN6I_DPHY_RX_CTL_RX_D0_FORCE;
  261. if (dphy->config.lanes >= 2)
  262. value |= SUN6I_DPHY_RX_CTL_RX_D1_FORCE;
  263. if (dphy->config.lanes >= 3)
  264. value |= SUN6I_DPHY_RX_CTL_RX_D2_FORCE;
  265. if (dphy->config.lanes == 4)
  266. value |= SUN6I_DPHY_RX_CTL_RX_D3_FORCE;
  267. regmap_write(dphy->regs, SUN6I_DPHY_RX_CTL_REG, value);
  268. regmap_write(dphy->regs, SUN6I_DPHY_GCTL_REG,
  269. SUN6I_DPHY_GCTL_LANE_NUM(dphy->config.lanes) |
  270. SUN6I_DPHY_GCTL_EN);
  271. return 0;
  272. }
  273. static int sun6i_dphy_power_on(struct phy *phy)
  274. {
  275. struct sun6i_dphy *dphy = phy_get_drvdata(phy);
  276. switch (dphy->direction) {
  277. case SUN6I_DPHY_DIRECTION_TX:
  278. return sun6i_dphy_tx_power_on(dphy);
  279. case SUN6I_DPHY_DIRECTION_RX:
  280. return sun6i_dphy_rx_power_on(dphy);
  281. default:
  282. return -EINVAL;
  283. }
  284. }
  285. static int sun6i_dphy_power_off(struct phy *phy)
  286. {
  287. struct sun6i_dphy *dphy = phy_get_drvdata(phy);
  288. regmap_write(dphy->regs, SUN6I_DPHY_GCTL_REG, 0);
  289. regmap_write(dphy->regs, SUN6I_DPHY_ANA0_REG, 0);
  290. regmap_write(dphy->regs, SUN6I_DPHY_ANA1_REG, 0);
  291. regmap_write(dphy->regs, SUN6I_DPHY_ANA2_REG, 0);
  292. regmap_write(dphy->regs, SUN6I_DPHY_ANA3_REG, 0);
  293. regmap_write(dphy->regs, SUN6I_DPHY_ANA4_REG, 0);
  294. return 0;
  295. }
  296. static int sun6i_dphy_exit(struct phy *phy)
  297. {
  298. struct sun6i_dphy *dphy = phy_get_drvdata(phy);
  299. clk_rate_exclusive_put(dphy->mod_clk);
  300. clk_disable_unprepare(dphy->mod_clk);
  301. reset_control_assert(dphy->reset);
  302. return 0;
  303. }
  304. static const struct phy_ops sun6i_dphy_ops = {
  305. .configure = sun6i_dphy_configure,
  306. .power_on = sun6i_dphy_power_on,
  307. .power_off = sun6i_dphy_power_off,
  308. .init = sun6i_dphy_init,
  309. .exit = sun6i_dphy_exit,
  310. };
  311. static const struct regmap_config sun6i_dphy_regmap_config = {
  312. .reg_bits = 32,
  313. .val_bits = 32,
  314. .reg_stride = 4,
  315. .max_register = SUN6I_DPHY_DBG5_REG,
  316. .name = "mipi-dphy",
  317. };
  318. static int sun6i_dphy_probe(struct platform_device *pdev)
  319. {
  320. struct phy_provider *phy_provider;
  321. struct sun6i_dphy *dphy;
  322. const char *direction;
  323. void __iomem *regs;
  324. int ret;
  325. dphy = devm_kzalloc(&pdev->dev, sizeof(*dphy), GFP_KERNEL);
  326. if (!dphy)
  327. return -ENOMEM;
  328. regs = devm_platform_ioremap_resource(pdev, 0);
  329. if (IS_ERR(regs)) {
  330. dev_err(&pdev->dev, "Couldn't map the DPHY encoder registers\n");
  331. return PTR_ERR(regs);
  332. }
  333. dphy->regs = devm_regmap_init_mmio_clk(&pdev->dev, "bus",
  334. regs, &sun6i_dphy_regmap_config);
  335. if (IS_ERR(dphy->regs)) {
  336. dev_err(&pdev->dev, "Couldn't create the DPHY encoder regmap\n");
  337. return PTR_ERR(dphy->regs);
  338. }
  339. dphy->reset = devm_reset_control_get_shared(&pdev->dev, NULL);
  340. if (IS_ERR(dphy->reset)) {
  341. dev_err(&pdev->dev, "Couldn't get our reset line\n");
  342. return PTR_ERR(dphy->reset);
  343. }
  344. dphy->mod_clk = devm_clk_get(&pdev->dev, "mod");
  345. if (IS_ERR(dphy->mod_clk)) {
  346. dev_err(&pdev->dev, "Couldn't get the DPHY mod clock\n");
  347. return PTR_ERR(dphy->mod_clk);
  348. }
  349. dphy->phy = devm_phy_create(&pdev->dev, NULL, &sun6i_dphy_ops);
  350. if (IS_ERR(dphy->phy)) {
  351. dev_err(&pdev->dev, "failed to create PHY\n");
  352. return PTR_ERR(dphy->phy);
  353. }
  354. dphy->direction = SUN6I_DPHY_DIRECTION_TX;
  355. ret = of_property_read_string(pdev->dev.of_node, "allwinner,direction",
  356. &direction);
  357. if (!ret && !strncmp(direction, "rx", 2))
  358. dphy->direction = SUN6I_DPHY_DIRECTION_RX;
  359. phy_set_drvdata(dphy->phy, dphy);
  360. phy_provider = devm_of_phy_provider_register(&pdev->dev, of_phy_simple_xlate);
  361. return PTR_ERR_OR_ZERO(phy_provider);
  362. }
  363. static const struct of_device_id sun6i_dphy_of_table[] = {
  364. { .compatible = "allwinner,sun6i-a31-mipi-dphy" },
  365. { }
  366. };
  367. MODULE_DEVICE_TABLE(of, sun6i_dphy_of_table);
  368. static struct platform_driver sun6i_dphy_platform_driver = {
  369. .probe = sun6i_dphy_probe,
  370. .driver = {
  371. .name = "sun6i-mipi-dphy",
  372. .of_match_table = sun6i_dphy_of_table,
  373. },
  374. };
  375. module_platform_driver(sun6i_dphy_platform_driver);
  376. MODULE_AUTHOR("Maxime Ripard <maxime.ripard@bootlin>");
  377. MODULE_DESCRIPTION("Allwinner A31 MIPI D-PHY Driver");
  378. MODULE_LICENSE("GPL");