mtk_mt8173_hdmi_phy.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. /*
  2. * Copyright (c) 2014 MediaTek Inc.
  3. * Author: Jie Qiu <jie.qiu@mediatek.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #include <linux/clk.h>
  15. #include <linux/clk-provider.h>
  16. #include <linux/delay.h>
  17. #include <linux/io.h>
  18. #include <linux/mfd/syscon.h>
  19. #include <linux/module.h>
  20. #include <linux/phy/phy.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/types.h>
  23. #define HDMI_CON0 0x00
  24. #define RG_HDMITX_PLL_EN BIT(31)
  25. #define RG_HDMITX_PLL_FBKDIV (0x7f << 24)
  26. #define PLL_FBKDIV_SHIFT 24
  27. #define RG_HDMITX_PLL_FBKSEL (0x3 << 22)
  28. #define PLL_FBKSEL_SHIFT 22
  29. #define RG_HDMITX_PLL_PREDIV (0x3 << 20)
  30. #define PREDIV_SHIFT 20
  31. #define RG_HDMITX_PLL_POSDIV (0x3 << 18)
  32. #define POSDIV_SHIFT 18
  33. #define RG_HDMITX_PLL_RST_DLY (0x3 << 16)
  34. #define RG_HDMITX_PLL_IR (0xf << 12)
  35. #define PLL_IR_SHIFT 12
  36. #define RG_HDMITX_PLL_IC (0xf << 8)
  37. #define PLL_IC_SHIFT 8
  38. #define RG_HDMITX_PLL_BP (0xf << 4)
  39. #define PLL_BP_SHIFT 4
  40. #define RG_HDMITX_PLL_BR (0x3 << 2)
  41. #define PLL_BR_SHIFT 2
  42. #define RG_HDMITX_PLL_BC (0x3 << 0)
  43. #define PLL_BC_SHIFT 0
  44. #define HDMI_CON1 0x04
  45. #define RG_HDMITX_PLL_DIVEN (0x7 << 29)
  46. #define PLL_DIVEN_SHIFT 29
  47. #define RG_HDMITX_PLL_AUTOK_EN BIT(28)
  48. #define RG_HDMITX_PLL_AUTOK_KF (0x3 << 26)
  49. #define RG_HDMITX_PLL_AUTOK_KS (0x3 << 24)
  50. #define RG_HDMITX_PLL_AUTOK_LOAD BIT(23)
  51. #define RG_HDMITX_PLL_BAND (0x3f << 16)
  52. #define RG_HDMITX_PLL_REF_SEL BIT(15)
  53. #define RG_HDMITX_PLL_BIAS_EN BIT(14)
  54. #define RG_HDMITX_PLL_BIAS_LPF_EN BIT(13)
  55. #define RG_HDMITX_PLL_TXDIV_EN BIT(12)
  56. #define RG_HDMITX_PLL_TXDIV (0x3 << 10)
  57. #define PLL_TXDIV_SHIFT 10
  58. #define RG_HDMITX_PLL_LVROD_EN BIT(9)
  59. #define RG_HDMITX_PLL_MONVC_EN BIT(8)
  60. #define RG_HDMITX_PLL_MONCK_EN BIT(7)
  61. #define RG_HDMITX_PLL_MONREF_EN BIT(6)
  62. #define RG_HDMITX_PLL_TST_EN BIT(5)
  63. #define RG_HDMITX_PLL_TST_CK_EN BIT(4)
  64. #define RG_HDMITX_PLL_TST_SEL (0xf << 0)
  65. #define HDMI_CON2 0x08
  66. #define RGS_HDMITX_PLL_AUTOK_BAND (0x7f << 8)
  67. #define RGS_HDMITX_PLL_AUTOK_FAIL BIT(1)
  68. #define RG_HDMITX_EN_TX_CKLDO BIT(0)
  69. #define HDMI_CON3 0x0c
  70. #define RG_HDMITX_SER_EN (0xf << 28)
  71. #define RG_HDMITX_PRD_EN (0xf << 24)
  72. #define RG_HDMITX_PRD_IMP_EN (0xf << 20)
  73. #define RG_HDMITX_DRV_EN (0xf << 16)
  74. #define RG_HDMITX_DRV_IMP_EN (0xf << 12)
  75. #define DRV_IMP_EN_SHIFT 12
  76. #define RG_HDMITX_MHLCK_FORCE BIT(10)
  77. #define RG_HDMITX_MHLCK_PPIX_EN BIT(9)
  78. #define RG_HDMITX_MHLCK_EN BIT(8)
  79. #define RG_HDMITX_SER_DIN_SEL (0xf << 4)
  80. #define RG_HDMITX_SER_5T1_BIST_EN BIT(3)
  81. #define RG_HDMITX_SER_BIST_TOG BIT(2)
  82. #define RG_HDMITX_SER_DIN_TOG BIT(1)
  83. #define RG_HDMITX_SER_CLKDIG_INV BIT(0)
  84. #define HDMI_CON4 0x10
  85. #define RG_HDMITX_PRD_IBIAS_CLK (0xf << 24)
  86. #define RG_HDMITX_PRD_IBIAS_D2 (0xf << 16)
  87. #define RG_HDMITX_PRD_IBIAS_D1 (0xf << 8)
  88. #define RG_HDMITX_PRD_IBIAS_D0 (0xf << 0)
  89. #define PRD_IBIAS_CLK_SHIFT 24
  90. #define PRD_IBIAS_D2_SHIFT 16
  91. #define PRD_IBIAS_D1_SHIFT 8
  92. #define PRD_IBIAS_D0_SHIFT 0
  93. #define HDMI_CON5 0x14
  94. #define RG_HDMITX_DRV_IBIAS_CLK (0x3f << 24)
  95. #define RG_HDMITX_DRV_IBIAS_D2 (0x3f << 16)
  96. #define RG_HDMITX_DRV_IBIAS_D1 (0x3f << 8)
  97. #define RG_HDMITX_DRV_IBIAS_D0 (0x3f << 0)
  98. #define DRV_IBIAS_CLK_SHIFT 24
  99. #define DRV_IBIAS_D2_SHIFT 16
  100. #define DRV_IBIAS_D1_SHIFT 8
  101. #define DRV_IBIAS_D0_SHIFT 0
  102. #define HDMI_CON6 0x18
  103. #define RG_HDMITX_DRV_IMP_CLK (0x3f << 24)
  104. #define RG_HDMITX_DRV_IMP_D2 (0x3f << 16)
  105. #define RG_HDMITX_DRV_IMP_D1 (0x3f << 8)
  106. #define RG_HDMITX_DRV_IMP_D0 (0x3f << 0)
  107. #define DRV_IMP_CLK_SHIFT 24
  108. #define DRV_IMP_D2_SHIFT 16
  109. #define DRV_IMP_D1_SHIFT 8
  110. #define DRV_IMP_D0_SHIFT 0
  111. #define HDMI_CON7 0x1c
  112. #define RG_HDMITX_MHLCK_DRV_IBIAS (0x1f << 27)
  113. #define RG_HDMITX_SER_DIN (0x3ff << 16)
  114. #define RG_HDMITX_CHLDC_TST (0xf << 12)
  115. #define RG_HDMITX_CHLCK_TST (0xf << 8)
  116. #define RG_HDMITX_RESERVE (0xff << 0)
  117. #define HDMI_CON8 0x20
  118. #define RGS_HDMITX_2T1_LEV (0xf << 16)
  119. #define RGS_HDMITX_2T1_EDG (0xf << 12)
  120. #define RGS_HDMITX_5T1_LEV (0xf << 8)
  121. #define RGS_HDMITX_5T1_EDG (0xf << 4)
  122. #define RGS_HDMITX_PLUG_TST BIT(0)
  123. struct mtk_hdmi_phy {
  124. void __iomem *regs;
  125. struct device *dev;
  126. struct clk *pll;
  127. struct clk_hw pll_hw;
  128. unsigned long pll_rate;
  129. u8 drv_imp_clk;
  130. u8 drv_imp_d2;
  131. u8 drv_imp_d1;
  132. u8 drv_imp_d0;
  133. u32 ibias;
  134. u32 ibias_up;
  135. };
  136. static const u8 PREDIV[3][4] = {
  137. {0x0, 0x0, 0x0, 0x0}, /* 27Mhz */
  138. {0x1, 0x1, 0x1, 0x1}, /* 74Mhz */
  139. {0x1, 0x1, 0x1, 0x1} /* 148Mhz */
  140. };
  141. static const u8 TXDIV[3][4] = {
  142. {0x3, 0x3, 0x3, 0x2}, /* 27Mhz */
  143. {0x2, 0x1, 0x1, 0x1}, /* 74Mhz */
  144. {0x1, 0x0, 0x0, 0x0} /* 148Mhz */
  145. };
  146. static const u8 FBKSEL[3][4] = {
  147. {0x1, 0x1, 0x1, 0x1}, /* 27Mhz */
  148. {0x1, 0x0, 0x1, 0x1}, /* 74Mhz */
  149. {0x1, 0x0, 0x1, 0x1} /* 148Mhz */
  150. };
  151. static const u8 FBKDIV[3][4] = {
  152. {19, 24, 29, 19}, /* 27Mhz */
  153. {19, 24, 14, 19}, /* 74Mhz */
  154. {19, 24, 14, 19} /* 148Mhz */
  155. };
  156. static const u8 DIVEN[3][4] = {
  157. {0x2, 0x1, 0x1, 0x2}, /* 27Mhz */
  158. {0x2, 0x2, 0x2, 0x2}, /* 74Mhz */
  159. {0x2, 0x2, 0x2, 0x2} /* 148Mhz */
  160. };
  161. static const u8 HTPLLBP[3][4] = {
  162. {0xc, 0xc, 0x8, 0xc}, /* 27Mhz */
  163. {0xc, 0xf, 0xf, 0xc}, /* 74Mhz */
  164. {0xc, 0xf, 0xf, 0xc} /* 148Mhz */
  165. };
  166. static const u8 HTPLLBC[3][4] = {
  167. {0x2, 0x3, 0x3, 0x2}, /* 27Mhz */
  168. {0x2, 0x3, 0x3, 0x2}, /* 74Mhz */
  169. {0x2, 0x3, 0x3, 0x2} /* 148Mhz */
  170. };
  171. static const u8 HTPLLBR[3][4] = {
  172. {0x1, 0x1, 0x0, 0x1}, /* 27Mhz */
  173. {0x1, 0x2, 0x2, 0x1}, /* 74Mhz */
  174. {0x1, 0x2, 0x2, 0x1} /* 148Mhz */
  175. };
  176. static void mtk_hdmi_phy_clear_bits(struct mtk_hdmi_phy *hdmi_phy, u32 offset,
  177. u32 bits)
  178. {
  179. void __iomem *reg = hdmi_phy->regs + offset;
  180. u32 tmp;
  181. tmp = readl(reg);
  182. tmp &= ~bits;
  183. writel(tmp, reg);
  184. }
  185. static void mtk_hdmi_phy_set_bits(struct mtk_hdmi_phy *hdmi_phy, u32 offset,
  186. u32 bits)
  187. {
  188. void __iomem *reg = hdmi_phy->regs + offset;
  189. u32 tmp;
  190. tmp = readl(reg);
  191. tmp |= bits;
  192. writel(tmp, reg);
  193. }
  194. static void mtk_hdmi_phy_mask(struct mtk_hdmi_phy *hdmi_phy, u32 offset,
  195. u32 val, u32 mask)
  196. {
  197. void __iomem *reg = hdmi_phy->regs + offset;
  198. u32 tmp;
  199. tmp = readl(reg);
  200. tmp = (tmp & ~mask) | (val & mask);
  201. writel(tmp, reg);
  202. }
  203. static inline struct mtk_hdmi_phy *to_mtk_hdmi_phy(struct clk_hw *hw)
  204. {
  205. return container_of(hw, struct mtk_hdmi_phy, pll_hw);
  206. }
  207. static int mtk_hdmi_pll_prepare(struct clk_hw *hw)
  208. {
  209. struct mtk_hdmi_phy *hdmi_phy = to_mtk_hdmi_phy(hw);
  210. dev_dbg(hdmi_phy->dev, "%s\n", __func__);
  211. mtk_hdmi_phy_set_bits(hdmi_phy, HDMI_CON1, RG_HDMITX_PLL_AUTOK_EN);
  212. mtk_hdmi_phy_set_bits(hdmi_phy, HDMI_CON0, RG_HDMITX_PLL_POSDIV);
  213. mtk_hdmi_phy_clear_bits(hdmi_phy, HDMI_CON3, RG_HDMITX_MHLCK_EN);
  214. mtk_hdmi_phy_set_bits(hdmi_phy, HDMI_CON1, RG_HDMITX_PLL_BIAS_EN);
  215. usleep_range(100, 150);
  216. mtk_hdmi_phy_set_bits(hdmi_phy, HDMI_CON0, RG_HDMITX_PLL_EN);
  217. usleep_range(100, 150);
  218. mtk_hdmi_phy_set_bits(hdmi_phy, HDMI_CON1, RG_HDMITX_PLL_BIAS_LPF_EN);
  219. mtk_hdmi_phy_set_bits(hdmi_phy, HDMI_CON1, RG_HDMITX_PLL_TXDIV_EN);
  220. return 0;
  221. }
  222. static void mtk_hdmi_pll_unprepare(struct clk_hw *hw)
  223. {
  224. struct mtk_hdmi_phy *hdmi_phy = to_mtk_hdmi_phy(hw);
  225. dev_dbg(hdmi_phy->dev, "%s\n", __func__);
  226. mtk_hdmi_phy_clear_bits(hdmi_phy, HDMI_CON1, RG_HDMITX_PLL_TXDIV_EN);
  227. mtk_hdmi_phy_clear_bits(hdmi_phy, HDMI_CON1, RG_HDMITX_PLL_BIAS_LPF_EN);
  228. usleep_range(100, 150);
  229. mtk_hdmi_phy_clear_bits(hdmi_phy, HDMI_CON0, RG_HDMITX_PLL_EN);
  230. usleep_range(100, 150);
  231. mtk_hdmi_phy_clear_bits(hdmi_phy, HDMI_CON1, RG_HDMITX_PLL_BIAS_EN);
  232. mtk_hdmi_phy_clear_bits(hdmi_phy, HDMI_CON0, RG_HDMITX_PLL_POSDIV);
  233. mtk_hdmi_phy_clear_bits(hdmi_phy, HDMI_CON1, RG_HDMITX_PLL_AUTOK_EN);
  234. usleep_range(100, 150);
  235. }
  236. static int mtk_hdmi_pll_set_rate(struct clk_hw *hw, unsigned long rate,
  237. unsigned long parent_rate)
  238. {
  239. struct mtk_hdmi_phy *hdmi_phy = to_mtk_hdmi_phy(hw);
  240. unsigned int pre_div;
  241. unsigned int div;
  242. unsigned int pre_ibias;
  243. unsigned int hdmi_ibias;
  244. unsigned int imp_en;
  245. dev_dbg(hdmi_phy->dev, "%s: %lu Hz, parent: %lu Hz\n", __func__,
  246. rate, parent_rate);
  247. if (rate <= 27000000) {
  248. pre_div = 0;
  249. div = 3;
  250. } else if (rate <= 74250000) {
  251. pre_div = 1;
  252. div = 2;
  253. } else {
  254. pre_div = 1;
  255. div = 1;
  256. }
  257. mtk_hdmi_phy_mask(hdmi_phy, HDMI_CON0,
  258. (pre_div << PREDIV_SHIFT), RG_HDMITX_PLL_PREDIV);
  259. mtk_hdmi_phy_set_bits(hdmi_phy, HDMI_CON0, RG_HDMITX_PLL_POSDIV);
  260. mtk_hdmi_phy_mask(hdmi_phy, HDMI_CON0,
  261. (0x1 << PLL_IC_SHIFT) | (0x1 << PLL_IR_SHIFT),
  262. RG_HDMITX_PLL_IC | RG_HDMITX_PLL_IR);
  263. mtk_hdmi_phy_mask(hdmi_phy, HDMI_CON1,
  264. (div << PLL_TXDIV_SHIFT), RG_HDMITX_PLL_TXDIV);
  265. mtk_hdmi_phy_mask(hdmi_phy, HDMI_CON0,
  266. (0x1 << PLL_FBKSEL_SHIFT) | (19 << PLL_FBKDIV_SHIFT),
  267. RG_HDMITX_PLL_FBKSEL | RG_HDMITX_PLL_FBKDIV);
  268. mtk_hdmi_phy_mask(hdmi_phy, HDMI_CON1,
  269. (0x2 << PLL_DIVEN_SHIFT), RG_HDMITX_PLL_DIVEN);
  270. mtk_hdmi_phy_mask(hdmi_phy, HDMI_CON0,
  271. (0xc << PLL_BP_SHIFT) | (0x2 << PLL_BC_SHIFT) |
  272. (0x1 << PLL_BR_SHIFT),
  273. RG_HDMITX_PLL_BP | RG_HDMITX_PLL_BC |
  274. RG_HDMITX_PLL_BR);
  275. if (rate < 165000000) {
  276. mtk_hdmi_phy_clear_bits(hdmi_phy, HDMI_CON3,
  277. RG_HDMITX_PRD_IMP_EN);
  278. pre_ibias = 0x3;
  279. imp_en = 0x0;
  280. hdmi_ibias = hdmi_phy->ibias;
  281. } else {
  282. mtk_hdmi_phy_set_bits(hdmi_phy, HDMI_CON3,
  283. RG_HDMITX_PRD_IMP_EN);
  284. pre_ibias = 0x6;
  285. imp_en = 0xf;
  286. hdmi_ibias = hdmi_phy->ibias_up;
  287. }
  288. mtk_hdmi_phy_mask(hdmi_phy, HDMI_CON4,
  289. (pre_ibias << PRD_IBIAS_CLK_SHIFT) |
  290. (pre_ibias << PRD_IBIAS_D2_SHIFT) |
  291. (pre_ibias << PRD_IBIAS_D1_SHIFT) |
  292. (pre_ibias << PRD_IBIAS_D0_SHIFT),
  293. RG_HDMITX_PRD_IBIAS_CLK |
  294. RG_HDMITX_PRD_IBIAS_D2 |
  295. RG_HDMITX_PRD_IBIAS_D1 |
  296. RG_HDMITX_PRD_IBIAS_D0);
  297. mtk_hdmi_phy_mask(hdmi_phy, HDMI_CON3,
  298. (imp_en << DRV_IMP_EN_SHIFT),
  299. RG_HDMITX_DRV_IMP_EN);
  300. mtk_hdmi_phy_mask(hdmi_phy, HDMI_CON6,
  301. (hdmi_phy->drv_imp_clk << DRV_IMP_CLK_SHIFT) |
  302. (hdmi_phy->drv_imp_d2 << DRV_IMP_D2_SHIFT) |
  303. (hdmi_phy->drv_imp_d1 << DRV_IMP_D1_SHIFT) |
  304. (hdmi_phy->drv_imp_d0 << DRV_IMP_D0_SHIFT),
  305. RG_HDMITX_DRV_IMP_CLK | RG_HDMITX_DRV_IMP_D2 |
  306. RG_HDMITX_DRV_IMP_D1 | RG_HDMITX_DRV_IMP_D0);
  307. mtk_hdmi_phy_mask(hdmi_phy, HDMI_CON5,
  308. (hdmi_ibias << DRV_IBIAS_CLK_SHIFT) |
  309. (hdmi_ibias << DRV_IBIAS_D2_SHIFT) |
  310. (hdmi_ibias << DRV_IBIAS_D1_SHIFT) |
  311. (hdmi_ibias << DRV_IBIAS_D0_SHIFT),
  312. RG_HDMITX_DRV_IBIAS_CLK |
  313. RG_HDMITX_DRV_IBIAS_D2 |
  314. RG_HDMITX_DRV_IBIAS_D1 |
  315. RG_HDMITX_DRV_IBIAS_D0);
  316. return 0;
  317. }
  318. static long mtk_hdmi_pll_round_rate(struct clk_hw *hw, unsigned long rate,
  319. unsigned long *parent_rate)
  320. {
  321. struct mtk_hdmi_phy *hdmi_phy = to_mtk_hdmi_phy(hw);
  322. hdmi_phy->pll_rate = rate;
  323. if (rate <= 74250000)
  324. *parent_rate = rate;
  325. else
  326. *parent_rate = rate / 2;
  327. return rate;
  328. }
  329. static unsigned long mtk_hdmi_pll_recalc_rate(struct clk_hw *hw,
  330. unsigned long parent_rate)
  331. {
  332. struct mtk_hdmi_phy *hdmi_phy = to_mtk_hdmi_phy(hw);
  333. return hdmi_phy->pll_rate;
  334. }
  335. static const struct clk_ops mtk_hdmi_pll_ops = {
  336. .prepare = mtk_hdmi_pll_prepare,
  337. .unprepare = mtk_hdmi_pll_unprepare,
  338. .set_rate = mtk_hdmi_pll_set_rate,
  339. .round_rate = mtk_hdmi_pll_round_rate,
  340. .recalc_rate = mtk_hdmi_pll_recalc_rate,
  341. };
  342. static void mtk_hdmi_phy_enable_tmds(struct mtk_hdmi_phy *hdmi_phy)
  343. {
  344. mtk_hdmi_phy_set_bits(hdmi_phy, HDMI_CON3,
  345. RG_HDMITX_SER_EN | RG_HDMITX_PRD_EN |
  346. RG_HDMITX_DRV_EN);
  347. usleep_range(100, 150);
  348. }
  349. static void mtk_hdmi_phy_disable_tmds(struct mtk_hdmi_phy *hdmi_phy)
  350. {
  351. mtk_hdmi_phy_clear_bits(hdmi_phy, HDMI_CON3,
  352. RG_HDMITX_DRV_EN | RG_HDMITX_PRD_EN |
  353. RG_HDMITX_SER_EN);
  354. }
  355. static int mtk_hdmi_phy_power_on(struct phy *phy)
  356. {
  357. struct mtk_hdmi_phy *hdmi_phy = phy_get_drvdata(phy);
  358. int ret;
  359. ret = clk_prepare_enable(hdmi_phy->pll);
  360. if (ret < 0)
  361. return ret;
  362. mtk_hdmi_phy_enable_tmds(hdmi_phy);
  363. return 0;
  364. }
  365. static int mtk_hdmi_phy_power_off(struct phy *phy)
  366. {
  367. struct mtk_hdmi_phy *hdmi_phy = phy_get_drvdata(phy);
  368. mtk_hdmi_phy_disable_tmds(hdmi_phy);
  369. clk_disable_unprepare(hdmi_phy->pll);
  370. return 0;
  371. }
  372. static const struct phy_ops mtk_hdmi_phy_ops = {
  373. .power_on = mtk_hdmi_phy_power_on,
  374. .power_off = mtk_hdmi_phy_power_off,
  375. .owner = THIS_MODULE,
  376. };
  377. static int mtk_hdmi_phy_probe(struct platform_device *pdev)
  378. {
  379. struct device *dev = &pdev->dev;
  380. struct mtk_hdmi_phy *hdmi_phy;
  381. struct resource *mem;
  382. struct clk *ref_clk;
  383. const char *ref_clk_name;
  384. struct clk_init_data clk_init = {
  385. .ops = &mtk_hdmi_pll_ops,
  386. .num_parents = 1,
  387. .parent_names = (const char * const *)&ref_clk_name,
  388. .flags = CLK_SET_RATE_PARENT | CLK_SET_RATE_GATE,
  389. };
  390. struct phy *phy;
  391. struct phy_provider *phy_provider;
  392. int ret;
  393. hdmi_phy = devm_kzalloc(dev, sizeof(*hdmi_phy), GFP_KERNEL);
  394. if (!hdmi_phy)
  395. return -ENOMEM;
  396. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  397. hdmi_phy->regs = devm_ioremap_resource(dev, mem);
  398. if (IS_ERR(hdmi_phy->regs)) {
  399. ret = PTR_ERR(hdmi_phy->regs);
  400. dev_err(dev, "Failed to get memory resource: %d\n", ret);
  401. return ret;
  402. }
  403. ref_clk = devm_clk_get(dev, "pll_ref");
  404. if (IS_ERR(ref_clk)) {
  405. ret = PTR_ERR(ref_clk);
  406. dev_err(&pdev->dev, "Failed to get PLL reference clock: %d\n",
  407. ret);
  408. return ret;
  409. }
  410. ref_clk_name = __clk_get_name(ref_clk);
  411. ret = of_property_read_string(dev->of_node, "clock-output-names",
  412. &clk_init.name);
  413. if (ret < 0) {
  414. dev_err(dev, "Failed to read clock-output-names: %d\n", ret);
  415. return ret;
  416. }
  417. hdmi_phy->pll_hw.init = &clk_init;
  418. hdmi_phy->pll = devm_clk_register(dev, &hdmi_phy->pll_hw);
  419. if (IS_ERR(hdmi_phy->pll)) {
  420. ret = PTR_ERR(hdmi_phy->pll);
  421. dev_err(dev, "Failed to register PLL: %d\n", ret);
  422. return ret;
  423. }
  424. ret = of_property_read_u32(dev->of_node, "mediatek,ibias",
  425. &hdmi_phy->ibias);
  426. if (ret < 0) {
  427. dev_err(&pdev->dev, "Failed to get ibias: %d\n", ret);
  428. return ret;
  429. }
  430. ret = of_property_read_u32(dev->of_node, "mediatek,ibias_up",
  431. &hdmi_phy->ibias_up);
  432. if (ret < 0) {
  433. dev_err(&pdev->dev, "Failed to get ibias up: %d\n", ret);
  434. return ret;
  435. }
  436. dev_info(dev, "Using default TX DRV impedance: 4.2k/36\n");
  437. hdmi_phy->drv_imp_clk = 0x30;
  438. hdmi_phy->drv_imp_d2 = 0x30;
  439. hdmi_phy->drv_imp_d1 = 0x30;
  440. hdmi_phy->drv_imp_d0 = 0x30;
  441. phy = devm_phy_create(dev, NULL, &mtk_hdmi_phy_ops);
  442. if (IS_ERR(phy)) {
  443. dev_err(dev, "Failed to create HDMI PHY\n");
  444. return PTR_ERR(phy);
  445. }
  446. phy_set_drvdata(phy, hdmi_phy);
  447. phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
  448. if (IS_ERR(phy_provider))
  449. return PTR_ERR(phy_provider);
  450. hdmi_phy->dev = dev;
  451. return of_clk_add_provider(dev->of_node, of_clk_src_simple_get,
  452. hdmi_phy->pll);
  453. }
  454. static int mtk_hdmi_phy_remove(struct platform_device *pdev)
  455. {
  456. return 0;
  457. }
  458. static const struct of_device_id mtk_hdmi_phy_match[] = {
  459. { .compatible = "mediatek,mt8173-hdmi-phy", },
  460. {},
  461. };
  462. struct platform_driver mtk_hdmi_phy_driver = {
  463. .probe = mtk_hdmi_phy_probe,
  464. .remove = mtk_hdmi_phy_remove,
  465. .driver = {
  466. .name = "mediatek-hdmi-phy",
  467. .of_match_table = mtk_hdmi_phy_match,
  468. },
  469. };
  470. MODULE_AUTHOR("Jie Qiu <jie.qiu@mediatek.com>");
  471. MODULE_DESCRIPTION("MediaTek MT8173 HDMI PHY Driver");
  472. MODULE_LICENSE("GPL v2");