mtk_mipi_tx.c 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195
  1. /*
  2. * Copyright (c) 2015 MediaTek Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/clk.h>
  14. #include <linux/clk-provider.h>
  15. #include <linux/delay.h>
  16. #include <linux/io.h>
  17. #include <linux/module.h>
  18. #include <linux/of_device.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/phy/phy.h>
  21. #include "mtk_log.h"
  22. #include "mtk_drm_crtc.h"
  23. #include "mtk_drm_drv.h"
  24. #include "mtk_panel_ext.h"
  25. #include "mtk_dump.h"
  26. #include "mtk_mipi_tx.h"
  27. #define MIPITX_DSI_CON 0x00
  28. #define RG_DSI_LDOCORE_EN BIT(0)
  29. #define RG_DSI_CKG_LDOOUT_EN BIT(1)
  30. #define RG_DSI_BCLK_SEL (3 << 2)
  31. #define RG_DSI_LD_IDX_SEL (7 << 4)
  32. #define RG_DSI_PHYCLK_SEL (2 << 8)
  33. #define RG_DSI_DSICLK_FREQ_SEL BIT(10)
  34. #define RG_DSI_LPTX_CLMP_EN BIT(11)
  35. #define MIPITX_DSI_CLOCK_LANE 0x04
  36. #define MIPITX_DSI_DATA_LANE0 0x08
  37. #define MIPITX_DSI_DATA_LANE1 0x0c
  38. #define MIPITX_DSI_DATA_LANE2 0x10
  39. #define MIPITX_DSI_DATA_LANE3 0x14
  40. #define RG_DSI_LNTx_LDOOUT_EN BIT(0)
  41. #define RG_DSI_LNTx_CKLANE_EN BIT(1)
  42. #define RG_DSI_LNTx_LPTX_IPLUS1 BIT(2)
  43. #define RG_DSI_LNTx_LPTX_IPLUS2 BIT(3)
  44. #define RG_DSI_LNTx_LPTX_IMINUS BIT(4)
  45. #define RG_DSI_LNTx_LPCD_IPLUS BIT(5)
  46. #define RG_DSI_LNTx_LPCD_IMINUS BIT(6)
  47. #define RG_DSI_LNTx_RT_CODE (0xf << 8)
  48. #define MIPITX_DSI_TOP_CON 0x40
  49. #define RG_DSI_LNT_INTR_EN BIT(0)
  50. #define RG_DSI_LNT_HS_BIAS_EN BIT(1)
  51. #define RG_DSI_LNT_IMP_CAL_EN BIT(2)
  52. #define RG_DSI_LNT_TESTMODE_EN BIT(3)
  53. #define RG_DSI_LNT_IMP_CAL_CODE (0xf << 4)
  54. #define RG_DSI_LNT_AIO_SEL (7 << 8)
  55. #define RG_DSI_PAD_TIE_LOW_EN BIT(11)
  56. #define RG_DSI_DEBUG_INPUT_EN BIT(12)
  57. #define RG_DSI_PRESERVE (7 << 13)
  58. #define MIPITX_DSI_BG_CON 0x44
  59. #define RG_DSI_BG_CORE_EN BIT(0)
  60. #define RG_DSI_BG_CKEN BIT(1)
  61. #define RG_DSI_BG_DIV (0x3 << 2)
  62. #define RG_DSI_BG_FAST_CHARGE BIT(4)
  63. #define RG_DSI_VOUT_MSK (0x3ffff << 5)
  64. #define RG_DSI_V12_SEL (7 << 5)
  65. #define RG_DSI_V10_SEL (7 << 8)
  66. #define RG_DSI_V072_SEL (7 << 11)
  67. #define RG_DSI_V04_SEL (7 << 14)
  68. #define RG_DSI_V032_SEL (7 << 17)
  69. #define RG_DSI_V02_SEL (7 << 20)
  70. #define RG_DSI_BG_R1_TRIM (0xf << 24)
  71. #define RG_DSI_BG_R2_TRIM (0xf << 28)
  72. #define MIPITX_DSI_PLL_CON0 0x50
  73. #define RG_DSI_MPPLL_PLL_EN BIT(0)
  74. #define RG_DSI_MPPLL_DIV_MSK (0x1ff << 1)
  75. #define RG_DSI_MPPLL_PREDIV (3 << 1)
  76. #define RG_DSI_MPPLL_TXDIV0 (3 << 3)
  77. #define RG_DSI_MPPLL_TXDIV1 (3 << 5)
  78. #define RG_DSI_MPPLL_POSDIV (7 << 7)
  79. #define RG_DSI_MPPLL_MONVC_EN BIT(10)
  80. #define RG_DSI_MPPLL_MONREF_EN BIT(11)
  81. #define RG_DSI_MPPLL_VOD_EN BIT(12)
  82. #define MIPITX_DSI_PLL_CON1 0x54
  83. #define RG_DSI_MPPLL_SDM_FRA_EN BIT(0)
  84. #define RG_DSI_MPPLL_SDM_SSC_PH_INIT BIT(1)
  85. #define RG_DSI_MPPLL_SDM_SSC_EN BIT(2)
  86. #define RG_DSI_MPPLL_SDM_SSC_PRD (0xffff << 16)
  87. #define MIPITX_DSI_PLL_CON2 0x58
  88. /* use to reset DPHY */
  89. #define MIPITX_SW_CTRL_CON4 0x60
  90. #define MIPITX_DSI_PLL_TOP 0x64
  91. #define RG_DSI_MPPLL_PRESERVE (0xff << 8)
  92. #define MIPITX_DSI_PLL_PWR 0x68
  93. #define RG_DSI_MPPLL_SDM_PWR_ON BIT(0)
  94. #define RG_DSI_MPPLL_SDM_ISO_EN BIT(1)
  95. #define RG_DSI_MPPLL_SDM_PWR_ACK BIT(8)
  96. #define MIPITX_DSI_SW_CTRL 0x80
  97. #define SW_CTRL_EN BIT(0)
  98. #define MIPITX_DSI_SW_CTRL_CON0 0x84
  99. #define SW_LNTC_LPTX_PRE_OE BIT(0)
  100. #define SW_LNTC_LPTX_OE BIT(1)
  101. #define SW_LNTC_LPTX_P BIT(2)
  102. #define SW_LNTC_LPTX_N BIT(3)
  103. #define SW_LNTC_HSTX_PRE_OE BIT(4)
  104. #define SW_LNTC_HSTX_OE BIT(5)
  105. #define SW_LNTC_HSTX_ZEROCLK BIT(6)
  106. #define SW_LNT0_LPTX_PRE_OE BIT(7)
  107. #define SW_LNT0_LPTX_OE BIT(8)
  108. #define SW_LNT0_LPTX_P BIT(9)
  109. #define SW_LNT0_LPTX_N BIT(10)
  110. #define SW_LNT0_HSTX_PRE_OE BIT(11)
  111. #define SW_LNT0_HSTX_OE BIT(12)
  112. #define SW_LNT0_LPRX_EN BIT(13)
  113. #define SW_LNT1_LPTX_PRE_OE BIT(14)
  114. #define SW_LNT1_LPTX_OE BIT(15)
  115. #define SW_LNT1_LPTX_P BIT(16)
  116. #define SW_LNT1_LPTX_N BIT(17)
  117. #define SW_LNT1_HSTX_PRE_OE BIT(18)
  118. #define SW_LNT1_HSTX_OE BIT(19)
  119. #define SW_LNT2_LPTX_PRE_OE BIT(20)
  120. #define SW_LNT2_LPTX_OE BIT(21)
  121. #define SW_LNT2_LPTX_P BIT(22)
  122. #define SW_LNT2_LPTX_N BIT(23)
  123. #define SW_LNT2_HSTX_PRE_OE BIT(24)
  124. #define SW_LNT2_HSTX_OE BIT(25)
  125. #define MIPITX_LANE_CON (0x000CUL)
  126. #define MIPITX_VOLTAGE_SEL (0x0010UL)
  127. #define FLD_RG_DSI_HSTX_LDO_REF_SEL (0xf << 6)
  128. #define MIPITX_PRESERVED (0x0014UL)
  129. #define MIPITX_PLL_PWR (0x0028UL)
  130. #define AD_DSI_PLL_SDM_PWR_ON BIT(0)
  131. #define AD_DSI_PLL_SDM_ISO_EN BIT(1)
  132. #define DA_DSI_PLL_SDM_PWR_ACK BIT(8)
  133. #define MIPITX_PLL_CON0 (0x002CUL)
  134. #define MIPITX_PLL_CON1 (0x0030UL)
  135. #define RG_DSI_PLL_SDM_PCW_CHG BIT(0)
  136. #define RG_DSI_PLL_EN BIT(4)
  137. #define MIPITX_PLL_CON2 (0x0034UL)
  138. #define MIPITX_PLL_CON3 (0x0038UL)
  139. #define MIPITX_PLL_CON4 (0x003CUL)
  140. #define MIPITX_D2_SW_CTL_EN (0x0144UL)
  141. #define DSI_D2_SW_CTL_EN BIT(0)
  142. #define MIPITX_D0_SW_CTL_EN (0x0244UL)
  143. #define DSI_D0_SW_CTL_EN BIT(0)
  144. #define MIPITX_CK_SW_CTL_EN (0x0344UL)
  145. #define DSI_CK_SW_CTL_EN BIT(0)
  146. #define MIPITX_D1_SW_CTL_EN (0x0444UL)
  147. #define DSI_D1_SW_CTL_EN BIT(0)
  148. #define MIPITX_D3_SW_CTL_EN (0x0544UL)
  149. #define DSI_D3_SW_CTL_EN BIT(0)
  150. #define MIPITX_PHY_SEL0 (0x0040UL)
  151. #define FLD_MIPI_TX_CPHY_EN (0x1 << 0)
  152. #define FLD_MIPI_TX_PHY2_SEL (0xf << 4)
  153. #define FLD_MIPI_TX_CPHY0BC_SEL (0xf << 8)
  154. #define FLD_MIPI_TX_PHY0_SEL (0xf << 12)
  155. #define FLD_MIPI_TX_PHY1AB_SEL (0xf << 16)
  156. #define FLD_MIPI_TX_PHYC_SEL (0xf << 20)
  157. #define FLD_MIPI_TX_CPHY1CA_SEL (0xf << 24)
  158. #define FLD_MIPI_TX_PHY1_SEL (0xf << 28)
  159. #define MIPITX_PHY_SEL1 (0x0044UL)
  160. #define FLD_MIPI_TX_PHY2BC_SEL (0xf << 0)
  161. #define FLD_MIPI_TX_PHY3_SEL (0xf << 4)
  162. #define FLD_MIPI_TX_CPHYXXX_SEL (0xf << 8)
  163. #define FLD_MIPI_TX_LPRX0AB_SEL (0xf << 12)
  164. #define FLD_MIPI_TX_LPRX0BC_SEL (0xf << 16)
  165. #define FLD_MIPI_TX_LPRX0CA_SEL (0xf << 20)
  166. #define FLD_MIPI_TX_CPHY0_HS_SEL (0xf << 24)
  167. #define FLD_MIPI_TX_CPHY1_HS_SEL (0xf << 26)
  168. #define FLD_MIPI_TX_CPHY2_HS_SEL (0xf << 28)
  169. #define MIPITX_PHY_SEL2 (0x0048UL)
  170. #define FLD_MIPI_TX_PHY2_HSDATA_SEL (0xf << 0)
  171. #define FLD_MIPI_TX_CPHY0BC_HSDATA_SEL (0xf << 4)
  172. #define FLD_MIPI_TX_PHY0_HSDATA_SEL (0xf << 8)
  173. #define FLD_MIPI_TX_PHY1AB_HSDATA_SEL (0xf << 12)
  174. #define FLD_MIPI_TX_PHYC_HSDATA_SEL (0xf << 16)
  175. #define FLD_MIPI_TX_CPHY1CA_HSDATA_SEL (0xf << 20)
  176. #define FLD_MIPI_TX_PHY1_HSDATA_SEL (0xf << 24)
  177. #define FLD_MIPI_TX_PHY2BC_HSDATA_SEL (0xf << 28)
  178. #define MIPITX_PHY_SEL3 (0x004CUL)
  179. #define FLD_MIPI_TX_PHY3_HSDATA_SEL (0xf << 0)
  180. #define MIPITX_D2P_RTCODE0 (0x0100UL)
  181. #define MIPITX_D2N_RTCODE0 (0x0114UL)
  182. #define MIPITX_D2P_RT_DEM_CODE (0x01C8UL)
  183. #define MIPITX_D2N_RT_DEM_CODE (0x01CCUL)
  184. #define MIPITX_D2_CKMODE_EN (0x0128UL)
  185. #define MIPITX_D0_CKMODE_EN (0x0228UL)
  186. #define MIPITX_CK_CKMODE_EN (0x0328UL)
  187. #define MIPITX_D1_CKMODE_EN (0x0428UL)
  188. #define MIPITX_D3_CKMODE_EN (0x0528UL)
  189. #define FLD_DSI_SW_CTL_EN BIT(0)
  190. #define FLD_AD_DSI_PLL_SDM_PWR_ON BIT(0)
  191. #define FLD_AD_DSI_PLL_SDM_ISO_EN BIT(1)
  192. #define FLD_RG_DSI_PLL_POSDIV (0x7 << 8)
  193. #define FLD_RG_DSI_PLL_POSDIV_ REG_FLD_MSB_LSB(10, 8)
  194. #define MIPITX_D0_SW_LPTX_PRE_OE (0x0248UL)
  195. #define MIPITX_D0C_SW_LPTX_PRE_OE (0x0268UL)
  196. #define MIPITX_D1_SW_LPTX_PRE_OE (0x0448UL)
  197. #define MIPITX_D1C_SW_LPTX_PRE_OE (0x0468UL)
  198. #define MIPITX_D2_SW_LPTX_PRE_OE (0x0148UL)
  199. #define MIPITX_D2C_SW_LPTX_PRE_OE (0x0168UL)
  200. #define MIPITX_D3_SW_LPTX_PRE_OE (0x0548UL)
  201. #define MIPITX_D3C_SW_LPTX_PRE_OE (0x0568UL)
  202. #define MIPITX_CK_SW_LPTX_PRE_OE (0x0348UL)
  203. #define MIPITX_CKC_SW_LPTX_PRE_OE (0x0368UL)
  204. enum MIPITX_PAD_VALUE {
  205. PAD_D2P_T0A = 0,
  206. PAD_D2N_T0B,
  207. PAD_D0P_T0C,
  208. PAD_D0N_T1A,
  209. PAD_CKP_T1B,
  210. PAD_CKN_T1C,
  211. PAD_D1P_T2A,
  212. PAD_D1N_T2B,
  213. PAD_D3P_T2C,
  214. PAD_D3N_XXX,
  215. PAD_NUM
  216. };
  217. struct mtk_mipitx_data {
  218. const u32 mppll_preserve;
  219. int (*pll_prepare)(struct clk_hw *hw);
  220. int (*power_on_signal)(struct phy *phy);
  221. void (*pll_unprepare)(struct clk_hw *hw);
  222. int (*power_off_signal)(struct phy *phy);
  223. };
  224. struct mtk_mipi_tx {
  225. struct device *dev;
  226. void __iomem *regs;
  227. resource_size_t regs_pa;
  228. struct cmdq_base *cmdq_base;
  229. u32 data_rate;
  230. u32 data_rate_adpt;
  231. const struct mtk_mipitx_data *driver_data;
  232. struct clk_hw pll_hw;
  233. struct clk *pll;
  234. };
  235. static inline struct mtk_mipi_tx *mtk_mipi_tx_from_clk_hw(struct clk_hw *hw)
  236. {
  237. return container_of(hw, struct mtk_mipi_tx, pll_hw);
  238. }
  239. static void mtk_mipi_tx_clear_bits(struct mtk_mipi_tx *mipi_tx, u32 offset,
  240. u32 bits)
  241. {
  242. u32 temp = readl(mipi_tx->regs + offset);
  243. writel(temp & ~bits, mipi_tx->regs + offset);
  244. }
  245. static void mtk_mipi_tx_set_bits(struct mtk_mipi_tx *mipi_tx, u32 offset,
  246. u32 bits)
  247. {
  248. u32 temp = readl(mipi_tx->regs + offset);
  249. writel(temp | bits, mipi_tx->regs + offset);
  250. }
  251. static void mtk_mipi_tx_update_bits(struct mtk_mipi_tx *mipi_tx, u32 offset,
  252. u32 mask, u32 data)
  253. {
  254. u32 temp = readl(mipi_tx->regs + offset);
  255. writel((temp & ~mask) | (data & mask), mipi_tx->regs + offset);
  256. }
  257. unsigned int mtk_mipi_tx_pll_get_rate(struct phy *phy)
  258. {
  259. #ifndef CONFIG_FPGA_EARLY_PORTING
  260. int i = 0;
  261. unsigned int pcw;
  262. unsigned int prediv;
  263. unsigned int posdiv;
  264. struct mtk_mipi_tx *mipi_tx = phy_get_drvdata(phy);
  265. pcw = readl(mipi_tx->regs + MIPITX_PLL_CON0);
  266. pcw = (pcw >> 24) & 0xff;
  267. prediv = 1;
  268. posdiv = DISP_REG_GET_FIELD(FLD_RG_DSI_PLL_POSDIV_,
  269. MIPITX_PLL_CON1 + mipi_tx->regs);
  270. posdiv = (1 << posdiv);
  271. DDPINFO("%s, pcw: %d, prediv: %d, posdiv: %d", __func__, pcw, prediv,
  272. posdiv);
  273. i = prediv * posdiv;
  274. if (i > 0)
  275. return 26 * pcw / i;
  276. #endif /* CONFIG_FPGA_EARLY_PORTING */
  277. return 0;
  278. }
  279. int mtk_mipi_tx_dump(struct phy *phy)
  280. {
  281. struct mtk_mipi_tx *mipi_tx = phy_get_drvdata(phy);
  282. int k;
  283. DDPDUMP("== MIPI REGS ==\n");
  284. for (k = 0; k < 0x6A0; k += 16) {
  285. DDPDUMP("0x%04x: 0x%08x 0x%08x 0x%08x 0x%08x\n", k,
  286. readl(mipi_tx->regs + k),
  287. readl(mipi_tx->regs + k + 0x4),
  288. readl(mipi_tx->regs + k + 0x8),
  289. readl(mipi_tx->regs + k + 0xc));
  290. }
  291. return 0;
  292. }
  293. int mtk_mipi_tx_cphy_lane_config(struct phy *phy,
  294. struct mtk_panel_ext *mtk_panel)
  295. {
  296. struct mtk_mipi_tx *mipi_tx = phy_get_drvdata(phy);
  297. struct mtk_panel_params *params = mtk_panel->params;
  298. int i = 0;
  299. enum MIPITX_PHY_LANE_SWAP *swap_base;
  300. enum MIPITX_PAD_VALUE pad_mapping[MIPITX_PHY_LANE_NUM] = {
  301. PAD_D2P_T0A, PAD_D0N_T1A, PAD_D1P_T2A,
  302. PAD_D1P_T2A, PAD_D1P_T2A, PAD_D1P_T2A};
  303. /* TODO: support dual port MIPI lane_swap */
  304. swap_base = params->lane_swap[i];
  305. DDPINFO("%s+\n", __func__);
  306. DDPDBG("MIPITX Lane Swap Enabled for DSI Port %d\n", i);
  307. DDPDBG("MIPITX Lane Swap mapping: %d|%d|%d|%d|%d|%d\n",
  308. swap_base[MIPITX_PHY_LANE_0],
  309. swap_base[MIPITX_PHY_LANE_1],
  310. swap_base[MIPITX_PHY_LANE_2],
  311. swap_base[MIPITX_PHY_LANE_3],
  312. swap_base[MIPITX_PHY_LANE_CK],
  313. swap_base[MIPITX_PHY_LANE_RX]);
  314. /*set volate*/
  315. writel(0x4444236A, mipi_tx->regs + MIPITX_VOLTAGE_SEL);
  316. /*set lane swap*/
  317. if (!mtk_panel->params->lane_swap_en) {
  318. writel(0x65432101, mipi_tx->regs + MIPITX_PHY_SEL0);
  319. writel(0x24210987, mipi_tx->regs + MIPITX_PHY_SEL1);
  320. writel(0x68543102, mipi_tx->regs + MIPITX_PHY_SEL2);
  321. writel(0x00000007, mipi_tx->regs + MIPITX_PHY_SEL3);
  322. return 0;
  323. }
  324. /* ENABLE CPHY*/
  325. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL0,
  326. 0x1, 0x1);
  327. /* CPHY_LANE_T0 */
  328. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL0,
  329. FLD_MIPI_TX_PHY2_SEL,
  330. (pad_mapping[swap_base[MIPITX_PHY_LANE_0]]) << 4);
  331. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL0,
  332. FLD_MIPI_TX_CPHY0BC_SEL,
  333. (pad_mapping[swap_base[MIPITX_PHY_LANE_0]] + 1) << 8);
  334. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL0,
  335. FLD_MIPI_TX_PHY0_SEL,
  336. (pad_mapping[swap_base[MIPITX_PHY_LANE_0]] + 2) << 12);
  337. /* CPHY_LANE_T1 */
  338. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL0,
  339. FLD_MIPI_TX_PHY1AB_SEL,
  340. (pad_mapping[swap_base[MIPITX_PHY_LANE_1]]) << 16);
  341. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL0,
  342. FLD_MIPI_TX_PHYC_SEL,
  343. (pad_mapping[swap_base[MIPITX_PHY_LANE_1]] + 1) << 20);
  344. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL0,
  345. FLD_MIPI_TX_CPHY1CA_SEL,
  346. (pad_mapping[swap_base[MIPITX_PHY_LANE_1]] + 2) << 24);
  347. /* CPHY_LANE_T2 */
  348. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL0,
  349. FLD_MIPI_TX_PHY1_SEL,
  350. (pad_mapping[swap_base[MIPITX_PHY_LANE_2]]) << 28);
  351. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL1,
  352. FLD_MIPI_TX_PHY2BC_SEL,
  353. (pad_mapping[swap_base[MIPITX_PHY_LANE_2]] + 1) << 0);
  354. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL1,
  355. FLD_MIPI_TX_PHY3_SEL,
  356. (pad_mapping[swap_base[MIPITX_PHY_LANE_2]] + 2) << 4);
  357. /* LPRX SETTING */
  358. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL1,
  359. FLD_MIPI_TX_LPRX0AB_SEL,
  360. (pad_mapping[swap_base[MIPITX_PHY_LANE_0]]) << 12);
  361. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL1,
  362. FLD_MIPI_TX_LPRX0BC_SEL,
  363. (pad_mapping[swap_base[MIPITX_PHY_LANE_0]] + 1) << 16);
  364. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL1,
  365. FLD_MIPI_TX_LPRX0CA_SEL,
  366. (pad_mapping[swap_base[MIPITX_PHY_LANE_0]] + 2) << 20);
  367. /* HS SETTING */
  368. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL1,
  369. FLD_MIPI_TX_CPHY0_HS_SEL,
  370. (pad_mapping[swap_base[MIPITX_PHY_LANE_0]]) / 3 << 24);
  371. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL1,
  372. FLD_MIPI_TX_CPHY1_HS_SEL,
  373. (pad_mapping[swap_base[MIPITX_PHY_LANE_1]] / 3) << 26);
  374. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL1,
  375. FLD_MIPI_TX_CPHY2_HS_SEL,
  376. (pad_mapping[swap_base[MIPITX_PHY_LANE_2]] / 3) << 28);
  377. /* HS_DATA_SETTING */
  378. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL2,
  379. FLD_MIPI_TX_PHY2_HSDATA_SEL,
  380. (pad_mapping[swap_base[MIPITX_PHY_LANE_0]] + 2) << 0);
  381. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL2,
  382. FLD_MIPI_TX_CPHY0BC_HSDATA_SEL,
  383. (pad_mapping[swap_base[MIPITX_PHY_LANE_0]]) << 4);
  384. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL2,
  385. FLD_MIPI_TX_PHY0_HSDATA_SEL,
  386. (pad_mapping[swap_base[MIPITX_PHY_LANE_0]] + 1) << 8);
  387. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL2,
  388. FLD_MIPI_TX_PHY1AB_HSDATA_SEL,
  389. (pad_mapping[swap_base[MIPITX_PHY_LANE_1]]) << 12);
  390. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL2,
  391. FLD_MIPI_TX_PHYC_HSDATA_SEL,
  392. (pad_mapping[swap_base[MIPITX_PHY_LANE_1]] + 1) << 16);
  393. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL2,
  394. FLD_MIPI_TX_CPHY1CA_HSDATA_SEL,
  395. (pad_mapping[swap_base[MIPITX_PHY_LANE_1]] + 2) << 20);
  396. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL2,
  397. FLD_MIPI_TX_PHY1_HSDATA_SEL,
  398. (pad_mapping[swap_base[MIPITX_PHY_LANE_2]] + 2) << 24);
  399. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL2,
  400. FLD_MIPI_TX_PHY2BC_HSDATA_SEL,
  401. (pad_mapping[swap_base[MIPITX_PHY_LANE_2]]) << 28);
  402. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL3,
  403. FLD_MIPI_TX_PHY3_HSDATA_SEL,
  404. (pad_mapping[swap_base[MIPITX_PHY_LANE_2]] + 1) << 0);
  405. return 0;
  406. }
  407. int mtk_mipi_tx_dphy_lane_config(struct phy *phy,
  408. struct mtk_panel_ext *mtk_panel)
  409. {
  410. struct mtk_mipi_tx *mipi_tx = phy_get_drvdata(phy);
  411. struct mtk_panel_params *params = mtk_panel->params;
  412. int j, i = 0;
  413. enum MIPITX_PHY_LANE_SWAP *swap_base;
  414. enum MIPITX_PAD_VALUE pad_mapping[MIPITX_PHY_LANE_NUM] = {
  415. PAD_D0P_T0C, PAD_D1P_T2A, PAD_D2P_T0A,
  416. PAD_D3P_T2C, PAD_CKP_T1B, PAD_CKP_T1B};
  417. if (!mtk_panel->params->lane_swap_en) {
  418. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_CK_CKMODE_EN,
  419. 0x1, 0x1);
  420. return 0;
  421. }
  422. /* TODO: support dual port MIPI lane_swap */
  423. swap_base = params->lane_swap[i];
  424. DDPDBG("MIPITX Lane Swap Enabled for DSI Port %d\n", i);
  425. DDPDBG("MIPITX Lane Swap mapping: %d|%d|%d|%d|%d|%d\n",
  426. swap_base[MIPITX_PHY_LANE_0],
  427. swap_base[MIPITX_PHY_LANE_1],
  428. swap_base[MIPITX_PHY_LANE_2],
  429. swap_base[MIPITX_PHY_LANE_3],
  430. swap_base[MIPITX_PHY_LANE_CK],
  431. swap_base[MIPITX_PHY_LANE_RX]);
  432. for (j = MIPITX_PHY_LANE_0; j < MIPITX_PHY_LANE_CK; j++) {
  433. if (swap_base[j] == MIPITX_PHY_LANE_CK)
  434. break;
  435. }
  436. switch (j) {
  437. case MIPITX_PHY_LANE_0:
  438. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_D0_CKMODE_EN,
  439. 0x1, 0x1);
  440. break;
  441. case MIPITX_PHY_LANE_1:
  442. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_D1_CKMODE_EN,
  443. 0x1, 0x1);
  444. break;
  445. case MIPITX_PHY_LANE_2:
  446. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_D2_CKMODE_EN,
  447. 0x1, 0x1);
  448. break;
  449. case MIPITX_PHY_LANE_3:
  450. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_D3_CKMODE_EN,
  451. 0x1, 0x1);
  452. break;
  453. case MIPITX_PHY_LANE_CK:
  454. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_CK_CKMODE_EN,
  455. 0x1, 0x1);
  456. break;
  457. default:
  458. break;
  459. }
  460. /* LANE_0 */
  461. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL0,
  462. FLD_MIPI_TX_PHY0_SEL,
  463. (pad_mapping[swap_base[MIPITX_PHY_LANE_0]]) << 12);
  464. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL0,
  465. FLD_MIPI_TX_PHY1AB_SEL,
  466. (pad_mapping[swap_base[MIPITX_PHY_LANE_0]] + 1) << 16);
  467. /* LANE_1 */
  468. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL0,
  469. FLD_MIPI_TX_PHY1_SEL,
  470. (pad_mapping[swap_base[MIPITX_PHY_LANE_1]]) << 28);
  471. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL1,
  472. FLD_MIPI_TX_PHY2BC_SEL,
  473. (pad_mapping[swap_base[MIPITX_PHY_LANE_1]] + 1) << 0);
  474. /* LANE_2 */
  475. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL0,
  476. FLD_MIPI_TX_PHY2_SEL,
  477. (pad_mapping[swap_base[MIPITX_PHY_LANE_2]]) << 4);
  478. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL0,
  479. FLD_MIPI_TX_CPHY0BC_SEL,
  480. (pad_mapping[swap_base[MIPITX_PHY_LANE_2]] + 1) << 8);
  481. /* LANE_3 */
  482. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL1,
  483. FLD_MIPI_TX_PHY3_SEL,
  484. (pad_mapping[swap_base[MIPITX_PHY_LANE_3]]) << 4);
  485. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL1,
  486. FLD_MIPI_TX_CPHYXXX_SEL,
  487. (pad_mapping[swap_base[MIPITX_PHY_LANE_3]] + 1) << 8);
  488. /* CK_LANE */
  489. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL0,
  490. FLD_MIPI_TX_PHYC_SEL,
  491. (pad_mapping[swap_base[MIPITX_PHY_LANE_0]]) << 20);
  492. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL0,
  493. FLD_MIPI_TX_CPHY1CA_SEL,
  494. (pad_mapping[swap_base[MIPITX_PHY_LANE_0]] + 1) << 24);
  495. /* LPRX SETTING */
  496. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL1,
  497. FLD_MIPI_TX_LPRX0AB_SEL,
  498. (pad_mapping[swap_base[MIPITX_PHY_LANE_RX]]) << 12);
  499. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL1,
  500. FLD_MIPI_TX_LPRX0BC_SEL,
  501. (pad_mapping[swap_base[MIPITX_PHY_LANE_RX]] + 1) << 16);
  502. /* HS_DATA_SETTING */
  503. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL2,
  504. FLD_MIPI_TX_PHY2_HSDATA_SEL,
  505. (pad_mapping[swap_base[MIPITX_PHY_LANE_2]]) << 0);
  506. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL2,
  507. FLD_MIPI_TX_PHY0_HSDATA_SEL,
  508. (pad_mapping[swap_base[MIPITX_PHY_LANE_0]]) << 8);
  509. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL2,
  510. FLD_MIPI_TX_PHYC_HSDATA_SEL,
  511. (pad_mapping[swap_base[MIPITX_PHY_LANE_CK]]) << 16);
  512. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL2,
  513. FLD_MIPI_TX_PHY1_HSDATA_SEL,
  514. (pad_mapping[swap_base[MIPITX_PHY_LANE_1]]) << 24);
  515. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PHY_SEL3,
  516. FLD_MIPI_TX_PHY3_HSDATA_SEL,
  517. (pad_mapping[swap_base[MIPITX_PHY_LANE_3]]) << 0);
  518. return 0;
  519. }
  520. void mtk_mipi_tx_sw_control_en(struct phy *phy, bool en)
  521. {
  522. struct mtk_mipi_tx *mipi_tx = phy_get_drvdata(phy);
  523. if (en) {
  524. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D0_SW_CTL_EN,
  525. DSI_D0_SW_CTL_EN);
  526. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D1_SW_CTL_EN,
  527. DSI_D1_SW_CTL_EN);
  528. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D2_SW_CTL_EN,
  529. DSI_D2_SW_CTL_EN);
  530. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D3_SW_CTL_EN,
  531. DSI_D3_SW_CTL_EN);
  532. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_CK_SW_CTL_EN,
  533. DSI_CK_SW_CTL_EN);
  534. } else {
  535. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_D0_SW_CTL_EN,
  536. DSI_D0_SW_CTL_EN);
  537. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_D1_SW_CTL_EN,
  538. DSI_D1_SW_CTL_EN);
  539. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_D2_SW_CTL_EN,
  540. DSI_D2_SW_CTL_EN);
  541. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_D3_SW_CTL_EN,
  542. DSI_D3_SW_CTL_EN);
  543. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_CK_SW_CTL_EN,
  544. DSI_CK_SW_CTL_EN);
  545. }
  546. }
  547. void mtk_mipi_tx_pre_oe_config(struct phy *phy, bool en)
  548. {
  549. struct mtk_mipi_tx *mipi_tx = phy_get_drvdata(phy);
  550. if (en) {
  551. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D2_SW_LPTX_PRE_OE, 1);
  552. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D2C_SW_LPTX_PRE_OE, 1);
  553. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D0_SW_LPTX_PRE_OE, 1);
  554. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D0C_SW_LPTX_PRE_OE, 1);
  555. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_CK_SW_LPTX_PRE_OE, 1);
  556. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_CKC_SW_LPTX_PRE_OE, 1);
  557. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D1_SW_LPTX_PRE_OE, 1);
  558. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D1C_SW_LPTX_PRE_OE, 1);
  559. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D3_SW_LPTX_PRE_OE, 1);
  560. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D3C_SW_LPTX_PRE_OE, 1);
  561. } else {
  562. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_D2_SW_LPTX_PRE_OE, 1);
  563. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_D2C_SW_LPTX_PRE_OE, 1);
  564. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_D0_SW_LPTX_PRE_OE, 1);
  565. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_D0C_SW_LPTX_PRE_OE, 1);
  566. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_CK_SW_LPTX_PRE_OE, 1);
  567. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_CKC_SW_LPTX_PRE_OE, 1);
  568. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_D1_SW_LPTX_PRE_OE, 1);
  569. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_D1C_SW_LPTX_PRE_OE, 1);
  570. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_D3_SW_LPTX_PRE_OE, 1);
  571. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_D3C_SW_LPTX_PRE_OE, 1);
  572. }
  573. }
  574. static int mtk_mipi_tx_pll_prepare(struct clk_hw *hw)
  575. {
  576. struct mtk_mipi_tx *mipi_tx = mtk_mipi_tx_from_clk_hw(hw);
  577. u8 txdiv, txdiv0, txdiv1;
  578. u64 pcw;
  579. dev_dbg(mipi_tx->dev, "prepare: %u Hz\n", mipi_tx->data_rate);
  580. if (mipi_tx->data_rate >= 500000000) {
  581. txdiv = 1;
  582. txdiv0 = 0;
  583. txdiv1 = 0;
  584. } else if (mipi_tx->data_rate >= 250000000) {
  585. txdiv = 2;
  586. txdiv0 = 1;
  587. txdiv1 = 0;
  588. } else if (mipi_tx->data_rate >= 125000000) {
  589. txdiv = 4;
  590. txdiv0 = 2;
  591. txdiv1 = 0;
  592. } else if (mipi_tx->data_rate > 62000000) {
  593. txdiv = 8;
  594. txdiv0 = 2;
  595. txdiv1 = 1;
  596. } else if (mipi_tx->data_rate >= 50000000) {
  597. txdiv = 16;
  598. txdiv0 = 2;
  599. txdiv1 = 2;
  600. } else {
  601. return -EINVAL;
  602. }
  603. mtk_mipi_tx_update_bits(
  604. mipi_tx, MIPITX_DSI_BG_CON,
  605. RG_DSI_VOUT_MSK | RG_DSI_BG_CKEN | RG_DSI_BG_CORE_EN,
  606. (4 << 20) | (4 << 17) | (4 << 14) | (4 << 11) | (4 << 8) |
  607. (4 << 5) | RG_DSI_BG_CKEN | RG_DSI_BG_CORE_EN);
  608. usleep_range(30, 100);
  609. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_DSI_TOP_CON,
  610. RG_DSI_LNT_IMP_CAL_CODE | RG_DSI_LNT_HS_BIAS_EN,
  611. (8 << 4) | RG_DSI_LNT_HS_BIAS_EN);
  612. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_DSI_CON,
  613. RG_DSI_CKG_LDOOUT_EN | RG_DSI_LDOCORE_EN);
  614. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_DSI_PLL_PWR,
  615. RG_DSI_MPPLL_SDM_PWR_ON |
  616. RG_DSI_MPPLL_SDM_ISO_EN,
  617. RG_DSI_MPPLL_SDM_PWR_ON);
  618. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_DSI_PLL_CON0,
  619. RG_DSI_MPPLL_PLL_EN);
  620. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_DSI_PLL_CON0,
  621. RG_DSI_MPPLL_TXDIV0 | RG_DSI_MPPLL_TXDIV1 |
  622. RG_DSI_MPPLL_PREDIV,
  623. (txdiv0 << 3) | (txdiv1 << 5));
  624. /*
  625. * PLL PCW config
  626. * PCW bit 24~30 = integer part of pcw
  627. * PCW bit 0~23 = fractional part of pcw
  628. * pcw = data_Rate*4*txdiv/(Ref_clk*2);
  629. * Post DIV =4, so need data_Rate*4
  630. * Ref_clk is 26MHz
  631. */
  632. pcw = div_u64(((u64)mipi_tx->data_rate * 2 * txdiv) << 24, 26000000);
  633. writel(pcw, mipi_tx->regs + MIPITX_DSI_PLL_CON2);
  634. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_DSI_PLL_CON1,
  635. RG_DSI_MPPLL_SDM_FRA_EN);
  636. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_DSI_PLL_CON0, RG_DSI_MPPLL_PLL_EN);
  637. usleep_range(20, 100);
  638. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_DSI_PLL_CON1,
  639. RG_DSI_MPPLL_SDM_SSC_EN);
  640. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_DSI_PLL_TOP,
  641. RG_DSI_MPPLL_PRESERVE,
  642. mipi_tx->driver_data->mppll_preserve);
  643. return 0;
  644. }
  645. static bool mtk_is_mipi_tx_enable(struct clk_hw *hw)
  646. {
  647. struct mtk_mipi_tx *mipi_tx = mtk_mipi_tx_from_clk_hw(hw);
  648. u32 tmp = readl(mipi_tx->regs + MIPITX_PLL_CON1);
  649. return ((tmp & RG_DSI_PLL_EN) > 0);
  650. }
  651. static inline unsigned int _dsi_get_pcw(unsigned long data_rate,
  652. unsigned int pcw_ratio)
  653. {
  654. unsigned int pcw, tmp, pcw_floor;
  655. /**
  656. * PCW bit 24~30 = floor(pcw)
  657. * PCW bit 16~23 = (pcw - floor(pcw))*256
  658. * PCW bit 8~15 = (pcw*256 - floor(pcw)*256)*256
  659. * PCW bit 0~7 = (pcw*256*256 - floor(pcw)*256*256)*256
  660. */
  661. pcw = data_rate * pcw_ratio / 26;
  662. pcw_floor = data_rate * pcw_ratio % 26;
  663. tmp = ((pcw & 0xFF) << 24) | (((256 * pcw_floor / 26) & 0xFF) << 16) |
  664. (((256 * (256 * pcw_floor % 26) / 26) & 0xFF) << 8) |
  665. ((256 * (256 * (256 * pcw_floor % 26) % 26) / 26) & 0xFF);
  666. return tmp;
  667. }
  668. static int mtk_mipi_tx_pll_prepare_mt6779(struct clk_hw *hw)
  669. {
  670. struct mtk_mipi_tx *mipi_tx = mtk_mipi_tx_from_clk_hw(hw);
  671. unsigned int txdiv, txdiv0, txdiv1, tmp;
  672. u64 pcw;
  673. DDPINFO("%s+\n", __func__);
  674. /* if mipitx is on, skip it... */
  675. if (mtk_is_mipi_tx_enable(hw)) {
  676. DDPINFO("%s: mipitx already on\n", __func__);
  677. return 0;
  678. }
  679. dev_dbg(mipi_tx->dev, "prepare: %u Hz\n", mipi_tx->data_rate);
  680. if (mipi_tx->data_rate >= 2000000000) {
  681. txdiv = 1;
  682. txdiv0 = 0;
  683. txdiv1 = 0;
  684. } else if (mipi_tx->data_rate >= 1000000000) {
  685. txdiv = 2;
  686. txdiv0 = 1;
  687. txdiv1 = 0;
  688. } else if (mipi_tx->data_rate >= 500000000) {
  689. txdiv = 4;
  690. txdiv0 = 2;
  691. txdiv1 = 0;
  692. } else if (mipi_tx->data_rate > 250000000) {
  693. txdiv = 8;
  694. txdiv0 = 3;
  695. txdiv1 = 0;
  696. } else if (mipi_tx->data_rate >= 125000000) {
  697. txdiv = 16;
  698. txdiv0 = 4;
  699. txdiv1 = 0;
  700. } else {
  701. return -EINVAL;
  702. }
  703. writel(0x00FF12E0, mipi_tx->regs + MIPITX_PLL_CON4);
  704. /* BG_LPF_EN / BG_CORE_EN */
  705. writel(0x3FFF0180, mipi_tx->regs + MIPITX_LANE_CON);
  706. usleep_range(500, 600);
  707. writel(0x3FFF0080, mipi_tx->regs + MIPITX_LANE_CON);
  708. /* Switch OFF each Lane */
  709. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_D0_SW_CTL_EN, FLD_DSI_SW_CTL_EN,
  710. 0);
  711. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_D1_SW_CTL_EN, FLD_DSI_SW_CTL_EN,
  712. 0);
  713. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_D2_SW_CTL_EN, FLD_DSI_SW_CTL_EN,
  714. 0);
  715. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_D3_SW_CTL_EN, FLD_DSI_SW_CTL_EN,
  716. 0);
  717. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_CK_SW_CTL_EN, FLD_DSI_SW_CTL_EN,
  718. 0);
  719. /* step 1: SDM_RWR_ON / SDM_ISO_EN */
  720. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PLL_PWR,
  721. FLD_AD_DSI_PLL_SDM_PWR_ON, 1);
  722. usleep_range(30, 100);
  723. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PLL_PWR,
  724. FLD_AD_DSI_PLL_SDM_ISO_EN, 0);
  725. pcw = (mipi_tx->data_rate / 1000000) * txdiv / 26;
  726. tmp = ((pcw & 0xFF) << 24) |
  727. (((256 * ((mipi_tx->data_rate / 1000000) * txdiv % 26) / 26) &
  728. 0xFF)
  729. << 16) |
  730. (((256 *
  731. (256 * ((mipi_tx->data_rate / 1000000) * txdiv % 26) % 26) /
  732. 26) &
  733. 0xFF)
  734. << 8) |
  735. ((256 *
  736. (256 *
  737. (256 * ((mipi_tx->data_rate / 1000000) * txdiv % 26) % 26) %
  738. 26) /
  739. 26) &
  740. 0xFF);
  741. writel(tmp, mipi_tx->regs + MIPITX_PLL_CON0);
  742. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PLL_CON1,
  743. FLD_RG_DSI_PLL_POSDIV, txdiv0);
  744. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_PLL_CON1,
  745. RG_DSI_PLL_EN);
  746. usleep_range(50, 100);
  747. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_SW_CTRL_CON4, 1);
  748. DDPINFO("%s-\n", __func__);
  749. return 0;
  750. }
  751. static int mtk_mipi_tx_pll_prepare_mt6885(struct clk_hw *hw)
  752. {
  753. struct mtk_mipi_tx *mipi_tx = mtk_mipi_tx_from_clk_hw(hw);
  754. unsigned int txdiv, txdiv0, txdiv1, tmp;
  755. u32 rate;
  756. DDPDBG("%s+\n", __func__);
  757. /* if mipitx is on, skip it... */
  758. if (mtk_is_mipi_tx_enable(hw)) {
  759. DDPINFO("%s: mipitx already on\n", __func__);
  760. return 0;
  761. }
  762. rate = (mipi_tx->data_rate_adpt) ? mipi_tx->data_rate_adpt :
  763. mipi_tx->data_rate / 1000000;
  764. dev_dbg(mipi_tx->dev, "prepare: %u MHz\n", rate);
  765. if (rate >= 2000) {
  766. txdiv = 1;
  767. txdiv0 = 0;
  768. txdiv1 = 0;
  769. } else if (rate >= 1000) {
  770. txdiv = 2;
  771. txdiv0 = 1;
  772. txdiv1 = 0;
  773. } else if (rate >= 500) {
  774. txdiv = 4;
  775. txdiv0 = 2;
  776. txdiv1 = 0;
  777. } else if (rate > 250) {
  778. txdiv = 8;
  779. txdiv0 = 3;
  780. txdiv1 = 0;
  781. } else if (rate >= 125) {
  782. txdiv = 16;
  783. txdiv0 = 4;
  784. txdiv1 = 0;
  785. } else {
  786. return -EINVAL;
  787. }
  788. writel(0x0, mipi_tx->regs + MIPITX_PRESERVED);
  789. writel(0x00FF12E0, mipi_tx->regs + MIPITX_PLL_CON4);
  790. /* BG_LPF_EN / BG_CORE_EN */
  791. writel(0x3FFF0180, mipi_tx->regs + MIPITX_LANE_CON);
  792. usleep_range(500, 600);
  793. writel(0x3FFF0080, mipi_tx->regs + MIPITX_LANE_CON);
  794. #if 1
  795. /* Switch OFF each Lane */
  796. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_D0_SW_CTL_EN, FLD_DSI_SW_CTL_EN,
  797. 1);
  798. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_D1_SW_CTL_EN, FLD_DSI_SW_CTL_EN,
  799. 1);
  800. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_D2_SW_CTL_EN, FLD_DSI_SW_CTL_EN,
  801. 1);
  802. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_D3_SW_CTL_EN, FLD_DSI_SW_CTL_EN,
  803. 1);
  804. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_CK_SW_CTL_EN, FLD_DSI_SW_CTL_EN,
  805. 1);
  806. #endif
  807. /* step 1: SDM_RWR_ON / SDM_ISO_EN */
  808. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PLL_PWR,
  809. FLD_AD_DSI_PLL_SDM_PWR_ON, 1);
  810. usleep_range(30, 100);
  811. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PLL_PWR,
  812. FLD_AD_DSI_PLL_SDM_ISO_EN, 0);
  813. tmp = _dsi_get_pcw(rate, txdiv);
  814. writel(tmp, mipi_tx->regs + MIPITX_PLL_CON0);
  815. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PLL_CON1,
  816. FLD_RG_DSI_PLL_POSDIV, txdiv0 << 8);
  817. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_PLL_CON1,
  818. RG_DSI_PLL_EN);
  819. usleep_range(50, 100);
  820. /* TODO: should write bit8 to set SW_ANA_CK_EN here */
  821. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_SW_CTRL_CON4, 1);
  822. DDPDBG("%s-\n", __func__);
  823. return 0;
  824. }
  825. static int mtk_mipi_tx_pll_prepare_mt6873(struct clk_hw *hw)
  826. {
  827. struct mtk_mipi_tx *mipi_tx = mtk_mipi_tx_from_clk_hw(hw);
  828. unsigned int txdiv, txdiv0, txdiv1, tmp;
  829. u32 rate;
  830. DDPDBG("%s+\n", __func__);
  831. /* if mipitx is on, skip it... */
  832. if (mtk_is_mipi_tx_enable(hw)) {
  833. DDPINFO("%s: mipitx already on\n", __func__);
  834. return 0;
  835. }
  836. rate = (mipi_tx->data_rate_adpt) ? mipi_tx->data_rate_adpt :
  837. mipi_tx->data_rate / 1000000;
  838. dev_dbg(mipi_tx->dev, "prepare: %u MHz\n", rate);
  839. if (rate >= 2000) {
  840. txdiv = 1;
  841. txdiv0 = 0;
  842. txdiv1 = 0;
  843. } else if (rate >= 1000) {
  844. txdiv = 2;
  845. txdiv0 = 1;
  846. txdiv1 = 0;
  847. } else if (rate >= 500) {
  848. txdiv = 4;
  849. txdiv0 = 2;
  850. txdiv1 = 0;
  851. } else if (rate > 250) {
  852. txdiv = 8;
  853. txdiv0 = 3;
  854. txdiv1 = 0;
  855. } else if (rate >= 125) {
  856. txdiv = 16;
  857. txdiv0 = 4;
  858. txdiv1 = 0;
  859. } else {
  860. return -EINVAL;
  861. }
  862. writel(0x0, mipi_tx->regs + MIPITX_PRESERVED);
  863. writel(0x00FF12E0, mipi_tx->regs + MIPITX_PLL_CON4);
  864. /* BG_LPF_EN / BG_CORE_EN */
  865. writel(0x3FFF0180, mipi_tx->regs + MIPITX_LANE_CON);
  866. usleep_range(500, 600);
  867. writel(0x3FFF0080, mipi_tx->regs + MIPITX_LANE_CON);
  868. #if 1
  869. /* Switch OFF each Lane */
  870. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_D0_SW_CTL_EN, FLD_DSI_SW_CTL_EN,
  871. 1);
  872. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_D1_SW_CTL_EN, FLD_DSI_SW_CTL_EN,
  873. 1);
  874. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_D2_SW_CTL_EN, FLD_DSI_SW_CTL_EN,
  875. 1);
  876. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_D3_SW_CTL_EN, FLD_DSI_SW_CTL_EN,
  877. 1);
  878. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_CK_SW_CTL_EN, FLD_DSI_SW_CTL_EN,
  879. 1);
  880. #endif
  881. /* step 1: SDM_RWR_ON / SDM_ISO_EN */
  882. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PLL_PWR,
  883. FLD_AD_DSI_PLL_SDM_PWR_ON, 1);
  884. usleep_range(30, 100);
  885. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PLL_PWR,
  886. FLD_AD_DSI_PLL_SDM_ISO_EN, 0);
  887. tmp = _dsi_get_pcw(rate, txdiv);
  888. writel(tmp, mipi_tx->regs + MIPITX_PLL_CON0);
  889. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PLL_CON1,
  890. FLD_RG_DSI_PLL_POSDIV, txdiv0 << 8);
  891. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_PLL_CON1,
  892. RG_DSI_PLL_EN);
  893. usleep_range(50, 100);
  894. /* TODO: should write bit8 to set SW_ANA_CK_EN here */
  895. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_SW_CTRL_CON4, 1);
  896. if (mipi_volt) {
  897. /* set mipi_tx voltage */
  898. DDPMSG(" %s+ mipi_volt change: %d\n", __func__, mipi_volt);
  899. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_VOLTAGE_SEL,
  900. FLD_RG_DSI_HSTX_LDO_REF_SEL, mipi_volt << 6);
  901. }
  902. DDPDBG("%s-\n", __func__);
  903. return 0;
  904. }
  905. static int mtk_mipi_tx_pll_cphy_prepare_mt6873(struct clk_hw *hw)
  906. {
  907. struct mtk_mipi_tx *mipi_tx = mtk_mipi_tx_from_clk_hw(hw);
  908. unsigned int txdiv, txdiv0, txdiv1, tmp;
  909. u32 rate;
  910. DDPDBG("%s+\n", __func__);
  911. /* if mipitx is on, skip it... */
  912. if (mtk_is_mipi_tx_enable(hw)) {
  913. DDPINFO("%s: mipitx already on\n", __func__);
  914. return 0;
  915. }
  916. rate = (mipi_tx->data_rate_adpt) ? mipi_tx->data_rate_adpt :
  917. mipi_tx->data_rate / 1000000;
  918. dev_dbg(mipi_tx->dev, "prepare: %u MHz\n", rate);
  919. if (rate >= 2000) {
  920. txdiv = 1;
  921. txdiv0 = 0;
  922. txdiv1 = 0;
  923. } else if (rate >= 1000) {
  924. txdiv = 2;
  925. txdiv0 = 1;
  926. txdiv1 = 0;
  927. } else if (rate >= 500) {
  928. txdiv = 4;
  929. txdiv0 = 2;
  930. txdiv1 = 0;
  931. } else if (rate > 250) {
  932. txdiv = 8;
  933. txdiv0 = 3;
  934. txdiv1 = 0;
  935. } else if (rate >= 125) {
  936. txdiv = 16;
  937. txdiv0 = 4;
  938. txdiv1 = 0;
  939. } else {
  940. return -EINVAL;
  941. }
  942. /*set volate*/
  943. writel(0x4444236A, mipi_tx->regs + MIPITX_VOLTAGE_SEL);
  944. /* change the mipi_volt */
  945. if (mipi_volt) {
  946. DDPMSG("%s+ mipi_volt change: %d\n", __func__, mipi_volt);
  947. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_VOLTAGE_SEL,
  948. FLD_RG_DSI_HSTX_LDO_REF_SEL, mipi_volt<<6);
  949. }
  950. writel(0x0, mipi_tx->regs + MIPITX_PRESERVED);
  951. /* step 0 */
  952. /* BG_LPF_EN / BG_CORE_EN */
  953. writel(0x00FF12E0, mipi_tx->regs + MIPITX_PLL_CON4);
  954. /* BG_LPF_EN=0 BG_CORE_EN=1 */
  955. writel(0x3FFF0088, mipi_tx->regs + MIPITX_LANE_CON);
  956. //usleep_range(1, 1); /* 1us */
  957. /* BG_LPF_EN=1 */
  958. writel(0x3FFF00C8, mipi_tx->regs + MIPITX_LANE_CON);
  959. /* step 1: SDM_RWR_ON / SDM_ISO_EN */
  960. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PLL_PWR,
  961. FLD_AD_DSI_PLL_SDM_PWR_ON, 1);
  962. usleep_range(30, 100);
  963. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PLL_PWR,
  964. FLD_AD_DSI_PLL_SDM_ISO_EN, 0);
  965. tmp = _dsi_get_pcw(rate, txdiv);
  966. writel(tmp, mipi_tx->regs + MIPITX_PLL_CON0);
  967. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PLL_CON1,
  968. FLD_RG_DSI_PLL_POSDIV, txdiv0 << 8);
  969. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_PLL_CON1,
  970. RG_DSI_PLL_EN);
  971. usleep_range(50, 100);
  972. DDPDBG("%s-\n", __func__);
  973. return 0;
  974. }
  975. static int mtk_mipi_tx_pll_prepare_mt6853(struct clk_hw *hw)
  976. {
  977. struct mtk_mipi_tx *mipi_tx = mtk_mipi_tx_from_clk_hw(hw);
  978. unsigned int txdiv, txdiv0, txdiv1, tmp;
  979. u32 rate;
  980. DDPDBG("%s+\n", __func__);
  981. /* if mipitx is on, skip it... */
  982. if (mtk_is_mipi_tx_enable(hw)) {
  983. DDPINFO("%s: mipitx already on\n", __func__);
  984. return 0;
  985. }
  986. rate = (mipi_tx->data_rate_adpt) ? mipi_tx->data_rate_adpt :
  987. mipi_tx->data_rate / 1000000;
  988. dev_dbg(mipi_tx->dev, "prepare: %u MHz\n", rate);
  989. if (rate >= 2000) {
  990. txdiv = 1;
  991. txdiv0 = 0;
  992. txdiv1 = 0;
  993. } else if (rate >= 1000) {
  994. txdiv = 2;
  995. txdiv0 = 1;
  996. txdiv1 = 0;
  997. } else if (rate >= 500) {
  998. txdiv = 4;
  999. txdiv0 = 2;
  1000. txdiv1 = 0;
  1001. } else if (rate > 250) {
  1002. txdiv = 8;
  1003. txdiv0 = 3;
  1004. txdiv1 = 0;
  1005. } else if (rate >= 125) {
  1006. txdiv = 16;
  1007. txdiv0 = 4;
  1008. txdiv1 = 0;
  1009. } else {
  1010. return -EINVAL;
  1011. }
  1012. writel(0x0, mipi_tx->regs + MIPITX_PRESERVED);
  1013. writel(0x00FF12E0, mipi_tx->regs + MIPITX_PLL_CON4);
  1014. /* BG_LPF_EN / BG_CORE_EN */
  1015. writel(0x3FFF0180, mipi_tx->regs + MIPITX_LANE_CON);
  1016. usleep_range(500, 600);
  1017. writel(0x3FFF0080, mipi_tx->regs + MIPITX_LANE_CON);
  1018. #if 1
  1019. /* Switch OFF each Lane */
  1020. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_D0_SW_CTL_EN, FLD_DSI_SW_CTL_EN,
  1021. 1);
  1022. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_D1_SW_CTL_EN, FLD_DSI_SW_CTL_EN,
  1023. 1);
  1024. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_D2_SW_CTL_EN, FLD_DSI_SW_CTL_EN,
  1025. 1);
  1026. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_D3_SW_CTL_EN, FLD_DSI_SW_CTL_EN,
  1027. 1);
  1028. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_CK_SW_CTL_EN, FLD_DSI_SW_CTL_EN,
  1029. 1);
  1030. #endif
  1031. /* step 1: SDM_RWR_ON / SDM_ISO_EN */
  1032. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PLL_PWR,
  1033. FLD_AD_DSI_PLL_SDM_PWR_ON, 1);
  1034. usleep_range(30, 100);
  1035. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PLL_PWR,
  1036. FLD_AD_DSI_PLL_SDM_ISO_EN, 0);
  1037. tmp = _dsi_get_pcw(rate, txdiv);
  1038. writel(tmp, mipi_tx->regs + MIPITX_PLL_CON0);
  1039. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PLL_CON1,
  1040. FLD_RG_DSI_PLL_POSDIV, txdiv0 << 8);
  1041. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_PLL_CON1,
  1042. RG_DSI_PLL_EN);
  1043. usleep_range(50, 100);
  1044. /* TODO: should write bit8 to set SW_ANA_CK_EN here */
  1045. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_SW_CTRL_CON4, 1);
  1046. DDPDBG("%s-\n", __func__);
  1047. return 0;
  1048. }
  1049. static int mtk_mipi_tx_pll_prepare_mt6833(struct clk_hw *hw)
  1050. {
  1051. struct mtk_mipi_tx *mipi_tx = mtk_mipi_tx_from_clk_hw(hw);
  1052. unsigned int txdiv, txdiv0, txdiv1, tmp;
  1053. u32 rate;
  1054. DDPDBG("%s+\n", __func__);
  1055. /* if mipitx is on, skip it... */
  1056. if (mtk_is_mipi_tx_enable(hw)) {
  1057. DDPINFO("%s: mipitx already on\n", __func__);
  1058. return 0;
  1059. }
  1060. rate = (mipi_tx->data_rate_adpt) ? mipi_tx->data_rate_adpt :
  1061. mipi_tx->data_rate / 1000000;
  1062. dev_dbg(mipi_tx->dev, "prepare: %u MHz\n", rate);
  1063. if (rate >= 2000) {
  1064. txdiv = 1;
  1065. txdiv0 = 0;
  1066. txdiv1 = 0;
  1067. } else if (rate >= 1000) {
  1068. txdiv = 2;
  1069. txdiv0 = 1;
  1070. txdiv1 = 0;
  1071. } else if (rate >= 500) {
  1072. txdiv = 4;
  1073. txdiv0 = 2;
  1074. txdiv1 = 0;
  1075. } else if (rate > 250) {
  1076. txdiv = 8;
  1077. txdiv0 = 3;
  1078. txdiv1 = 0;
  1079. } else if (rate >= 125) {
  1080. txdiv = 16;
  1081. txdiv0 = 4;
  1082. txdiv1 = 0;
  1083. } else {
  1084. return -EINVAL;
  1085. }
  1086. writel(0x00FF12E0, mipi_tx->regs + MIPITX_PLL_CON4);
  1087. /* BG_LPF_EN / BG_CORE_EN */
  1088. writel(0x3FFF0180, mipi_tx->regs + MIPITX_LANE_CON);
  1089. usleep_range(500, 600);
  1090. writel(0x3FFF0080, mipi_tx->regs + MIPITX_LANE_CON);
  1091. #if 1
  1092. /* Switch OFF each Lane */
  1093. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_D0_SW_CTL_EN, FLD_DSI_SW_CTL_EN,
  1094. 1);
  1095. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_D1_SW_CTL_EN, FLD_DSI_SW_CTL_EN,
  1096. 1);
  1097. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_D2_SW_CTL_EN, FLD_DSI_SW_CTL_EN,
  1098. 1);
  1099. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_D3_SW_CTL_EN, FLD_DSI_SW_CTL_EN,
  1100. 1);
  1101. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_CK_SW_CTL_EN, FLD_DSI_SW_CTL_EN,
  1102. 1);
  1103. #endif
  1104. /* step 1: SDM_RWR_ON / SDM_ISO_EN */
  1105. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PLL_PWR,
  1106. FLD_AD_DSI_PLL_SDM_PWR_ON, 1);
  1107. usleep_range(30, 100);
  1108. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PLL_PWR,
  1109. FLD_AD_DSI_PLL_SDM_ISO_EN, 0);
  1110. tmp = _dsi_get_pcw(rate, txdiv);
  1111. writel(tmp, mipi_tx->regs + MIPITX_PLL_CON0);
  1112. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_PLL_CON1,
  1113. FLD_RG_DSI_PLL_POSDIV, txdiv0 << 8);
  1114. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_PLL_CON1,
  1115. RG_DSI_PLL_EN);
  1116. usleep_range(50, 100);
  1117. /* TODO: should write bit8 to set SW_ANA_CK_EN here */
  1118. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_SW_CTRL_CON4, 1);
  1119. DDPDBG("%s-\n", __func__);
  1120. return 0;
  1121. }
  1122. static void mtk_mipi_tx_pll_unprepare(struct clk_hw *hw)
  1123. {
  1124. struct mtk_mipi_tx *mipi_tx = mtk_mipi_tx_from_clk_hw(hw);
  1125. dev_dbg(mipi_tx->dev, "unprepare\n");
  1126. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_DSI_PLL_CON0,
  1127. RG_DSI_MPPLL_PLL_EN);
  1128. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_DSI_PLL_TOP,
  1129. RG_DSI_MPPLL_PRESERVE,
  1130. mipi_tx->driver_data->mppll_preserve);
  1131. mtk_mipi_tx_update_bits(mipi_tx, MIPITX_DSI_PLL_PWR,
  1132. RG_DSI_MPPLL_SDM_ISO_EN |
  1133. RG_DSI_MPPLL_SDM_PWR_ON,
  1134. RG_DSI_MPPLL_SDM_ISO_EN);
  1135. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_DSI_TOP_CON,
  1136. RG_DSI_LNT_HS_BIAS_EN);
  1137. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_DSI_CON,
  1138. RG_DSI_CKG_LDOOUT_EN | RG_DSI_LDOCORE_EN);
  1139. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_DSI_BG_CON,
  1140. RG_DSI_BG_CKEN | RG_DSI_BG_CORE_EN);
  1141. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_DSI_PLL_CON0,
  1142. RG_DSI_MPPLL_DIV_MSK);
  1143. }
  1144. static void mtk_mipi_tx_pll_unprepare_mt6779(struct clk_hw *hw)
  1145. {
  1146. struct mtk_mipi_tx *mipi_tx = mtk_mipi_tx_from_clk_hw(hw);
  1147. DDPINFO("%s+\n", __func__);
  1148. dev_dbg(mipi_tx->dev, "unprepare\n");
  1149. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_PLL_CON1, RG_DSI_PLL_EN);
  1150. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_SW_CTRL_CON4, 1);
  1151. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_PLL_PWR, AD_DSI_PLL_SDM_ISO_EN);
  1152. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_PLL_PWR, AD_DSI_PLL_SDM_PWR_ON);
  1153. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D0_SW_CTL_EN, DSI_D0_SW_CTL_EN);
  1154. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D1_SW_CTL_EN, DSI_D1_SW_CTL_EN);
  1155. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D2_SW_CTL_EN, DSI_D2_SW_CTL_EN);
  1156. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D3_SW_CTL_EN, DSI_D3_SW_CTL_EN);
  1157. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_CK_SW_CTL_EN, DSI_CK_SW_CTL_EN);
  1158. writel(0x3FFF0180, mipi_tx->regs + MIPITX_LANE_CON);
  1159. writel(0x3FFF0100, mipi_tx->regs + MIPITX_LANE_CON);
  1160. DDPINFO("%s-\n", __func__);
  1161. }
  1162. static void mtk_mipi_tx_pll_unprepare_mt6885(struct clk_hw *hw)
  1163. {
  1164. struct mtk_mipi_tx *mipi_tx = mtk_mipi_tx_from_clk_hw(hw);
  1165. DDPDBG("%s+\n", __func__);
  1166. dev_dbg(mipi_tx->dev, "unprepare\n");
  1167. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_PLL_CON1, RG_DSI_PLL_EN);
  1168. /* TODO: should clear bit8 to set SW_ANA_CK_EN here */
  1169. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_SW_CTRL_CON4, 1);
  1170. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_PLL_PWR, AD_DSI_PLL_SDM_ISO_EN);
  1171. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_PLL_PWR, AD_DSI_PLL_SDM_PWR_ON);
  1172. #if 0
  1173. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D0_SW_CTL_EN, DSI_D0_SW_CTL_EN);
  1174. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D1_SW_CTL_EN, DSI_D1_SW_CTL_EN);
  1175. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D2_SW_CTL_EN, DSI_D2_SW_CTL_EN);
  1176. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D3_SW_CTL_EN, DSI_D3_SW_CTL_EN);
  1177. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_CK_SW_CTL_EN, DSI_CK_SW_CTL_EN);
  1178. #endif
  1179. writel(0x3FFF0180, mipi_tx->regs + MIPITX_LANE_CON);
  1180. writel(0x3FFF0100, mipi_tx->regs + MIPITX_LANE_CON);
  1181. DDPINFO("%s-\n", __func__);
  1182. }
  1183. static void mtk_mipi_tx_pll_unprepare_mt6873(struct clk_hw *hw)
  1184. {
  1185. struct mtk_mipi_tx *mipi_tx = mtk_mipi_tx_from_clk_hw(hw);
  1186. DDPDBG("%s+\n", __func__);
  1187. dev_dbg(mipi_tx->dev, "unprepare\n");
  1188. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_PLL_CON1, RG_DSI_PLL_EN);
  1189. /* TODO: should clear bit8 to set SW_ANA_CK_EN here */
  1190. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_SW_CTRL_CON4, 1);
  1191. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_PLL_PWR, AD_DSI_PLL_SDM_ISO_EN);
  1192. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_PLL_PWR, AD_DSI_PLL_SDM_PWR_ON);
  1193. #if 0
  1194. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D0_SW_CTL_EN, DSI_D0_SW_CTL_EN);
  1195. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D1_SW_CTL_EN, DSI_D1_SW_CTL_EN);
  1196. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D2_SW_CTL_EN, DSI_D2_SW_CTL_EN);
  1197. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D3_SW_CTL_EN, DSI_D3_SW_CTL_EN);
  1198. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_CK_SW_CTL_EN, DSI_CK_SW_CTL_EN);
  1199. #endif
  1200. writel(0x3FFF0180, mipi_tx->regs + MIPITX_LANE_CON);
  1201. writel(0x3FFF0100, mipi_tx->regs + MIPITX_LANE_CON);
  1202. DDPINFO("%s-\n", __func__);
  1203. }
  1204. static void mtk_mipi_tx_pll_cphy_unprepare_mt6873(struct clk_hw *hw)
  1205. {
  1206. struct mtk_mipi_tx *mipi_tx = mtk_mipi_tx_from_clk_hw(hw);
  1207. DDPDBG("%s+\n", __func__);
  1208. dev_dbg(mipi_tx->dev, "cphy unprepare\n");
  1209. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_PLL_CON1, RG_DSI_PLL_EN);
  1210. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_PLL_PWR, AD_DSI_PLL_SDM_ISO_EN);
  1211. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_PLL_PWR, AD_DSI_PLL_SDM_PWR_ON);
  1212. writel(0x3FFF0080, mipi_tx->regs + MIPITX_LANE_CON);
  1213. writel(0x3FFF0000, mipi_tx->regs + MIPITX_LANE_CON);
  1214. DDPINFO("%s-\n", __func__);
  1215. }
  1216. static void mtk_mipi_tx_pll_unprepare_mt6853(struct clk_hw *hw)
  1217. {
  1218. struct mtk_mipi_tx *mipi_tx = mtk_mipi_tx_from_clk_hw(hw);
  1219. DDPDBG("%s+\n", __func__);
  1220. dev_dbg(mipi_tx->dev, "unprepare\n");
  1221. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_PLL_CON1, RG_DSI_PLL_EN);
  1222. /* TODO: should clear bit8 to set SW_ANA_CK_EN here */
  1223. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_SW_CTRL_CON4, 1);
  1224. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_PLL_PWR, AD_DSI_PLL_SDM_ISO_EN);
  1225. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_PLL_PWR, AD_DSI_PLL_SDM_PWR_ON);
  1226. #if 0
  1227. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D0_SW_CTL_EN, DSI_D0_SW_CTL_EN);
  1228. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D1_SW_CTL_EN, DSI_D1_SW_CTL_EN);
  1229. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D2_SW_CTL_EN, DSI_D2_SW_CTL_EN);
  1230. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D3_SW_CTL_EN, DSI_D3_SW_CTL_EN);
  1231. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_CK_SW_CTL_EN, DSI_CK_SW_CTL_EN);
  1232. #endif
  1233. writel(0x3FFF0180, mipi_tx->regs + MIPITX_LANE_CON);
  1234. writel(0x3FFF0100, mipi_tx->regs + MIPITX_LANE_CON);
  1235. DDPINFO("%s-\n", __func__);
  1236. }
  1237. static void mtk_mipi_tx_pll_unprepare_mt6833(struct clk_hw *hw)
  1238. {
  1239. struct mtk_mipi_tx *mipi_tx = mtk_mipi_tx_from_clk_hw(hw);
  1240. DDPDBG("%s+\n", __func__);
  1241. dev_dbg(mipi_tx->dev, "unprepare\n");
  1242. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_PLL_CON1, RG_DSI_PLL_EN);
  1243. /* TODO: should clear bit8 to set SW_ANA_CK_EN here */
  1244. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_SW_CTRL_CON4, 1);
  1245. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_PLL_PWR, AD_DSI_PLL_SDM_ISO_EN);
  1246. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_PLL_PWR, AD_DSI_PLL_SDM_PWR_ON);
  1247. #if 0
  1248. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D0_SW_CTL_EN, DSI_D0_SW_CTL_EN);
  1249. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D1_SW_CTL_EN, DSI_D1_SW_CTL_EN);
  1250. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D2_SW_CTL_EN, DSI_D2_SW_CTL_EN);
  1251. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_D3_SW_CTL_EN, DSI_D3_SW_CTL_EN);
  1252. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_CK_SW_CTL_EN, DSI_CK_SW_CTL_EN);
  1253. #endif
  1254. writel(0x3FFF0180, mipi_tx->regs + MIPITX_LANE_CON);
  1255. writel(0x3FFF0100, mipi_tx->regs + MIPITX_LANE_CON);
  1256. DDPINFO("%s-\n", __func__);
  1257. }
  1258. void mtk_mipi_tx_pll_rate_set_adpt(struct phy *phy, unsigned long rate)
  1259. {
  1260. struct mtk_mipi_tx *mipi_tx = phy_get_drvdata(phy);
  1261. mipi_tx->data_rate_adpt = rate;
  1262. }
  1263. void mtk_mipi_tx_pll_rate_switch_gce(struct phy *phy,
  1264. void *handle, unsigned long rate)
  1265. {
  1266. struct mtk_mipi_tx *mipi_tx = phy_get_drvdata(phy);
  1267. unsigned int txdiv, txdiv0, txdiv1, tmp;
  1268. u32 reg_val;
  1269. DDPINFO("%s+ %lu\n", __func__, rate);
  1270. /* parameter rate should be MHz */
  1271. if (rate >= 2000) {
  1272. txdiv = 1;
  1273. txdiv0 = 0;
  1274. txdiv1 = 0;
  1275. } else if (rate >= 1000) {
  1276. txdiv = 2;
  1277. txdiv0 = 1;
  1278. txdiv1 = 0;
  1279. } else if (rate >= 500) {
  1280. txdiv = 4;
  1281. txdiv0 = 2;
  1282. txdiv1 = 0;
  1283. } else if (rate > 250) {
  1284. txdiv = 8;
  1285. txdiv0 = 3;
  1286. txdiv1 = 0;
  1287. } else if (rate >= 125) {
  1288. txdiv = 16;
  1289. txdiv0 = 4;
  1290. txdiv1 = 0;
  1291. } else {
  1292. return;
  1293. }
  1294. tmp = _dsi_get_pcw(rate, txdiv);
  1295. cmdq_pkt_write(handle, mipi_tx->cmdq_base,
  1296. mipi_tx->regs_pa + MIPITX_PLL_CON0, tmp, ~0);
  1297. reg_val = readl(mipi_tx->regs + MIPITX_PLL_CON1);
  1298. reg_val = ((reg_val & ~FLD_RG_DSI_PLL_POSDIV) |
  1299. ((txdiv0 << 8) & FLD_RG_DSI_PLL_POSDIV));
  1300. reg_val = (reg_val & ~RG_DSI_PLL_SDM_PCW_CHG) |
  1301. (0 & RG_DSI_PLL_SDM_PCW_CHG);
  1302. cmdq_pkt_write(handle, mipi_tx->cmdq_base,
  1303. mipi_tx->regs_pa + MIPITX_PLL_CON1, reg_val, ~0);
  1304. reg_val = (reg_val & ~RG_DSI_PLL_SDM_PCW_CHG) |
  1305. (1 & RG_DSI_PLL_SDM_PCW_CHG);
  1306. cmdq_pkt_write(handle, mipi_tx->cmdq_base,
  1307. mipi_tx->regs_pa + MIPITX_PLL_CON1, reg_val, ~0);
  1308. reg_val = (reg_val & ~RG_DSI_PLL_SDM_PCW_CHG) |
  1309. (0 & RG_DSI_PLL_SDM_PCW_CHG);
  1310. cmdq_pkt_write(handle, mipi_tx->cmdq_base,
  1311. mipi_tx->regs_pa + MIPITX_PLL_CON1, reg_val, ~0);
  1312. DDPDBG("%s-\n", __func__);
  1313. return;
  1314. }
  1315. static long mtk_mipi_tx_pll_round_rate(struct clk_hw *hw, unsigned long rate,
  1316. unsigned long *prate)
  1317. {
  1318. return clamp_val(rate, 50000000, 1250000000);
  1319. }
  1320. static int mtk_mipi_tx_pll_set_rate(struct clk_hw *hw, unsigned long rate,
  1321. unsigned long parent_rate)
  1322. {
  1323. struct mtk_mipi_tx *mipi_tx = mtk_mipi_tx_from_clk_hw(hw);
  1324. dev_dbg(mipi_tx->dev, "set rate: %lu Hz\n", rate);
  1325. mipi_tx->data_rate = rate;
  1326. return 0;
  1327. }
  1328. static unsigned long mtk_mipi_tx_pll_recalc_rate(struct clk_hw *hw,
  1329. unsigned long parent_rate)
  1330. {
  1331. struct mtk_mipi_tx *mipi_tx = mtk_mipi_tx_from_clk_hw(hw);
  1332. return mipi_tx->data_rate;
  1333. }
  1334. static struct clk_ops mtk_mipi_tx_pll_ops = {
  1335. .unprepare = mtk_mipi_tx_pll_unprepare,
  1336. .round_rate = mtk_mipi_tx_pll_round_rate,
  1337. .set_rate = mtk_mipi_tx_pll_set_rate,
  1338. .recalc_rate = mtk_mipi_tx_pll_recalc_rate,
  1339. };
  1340. static int mtk_mipi_tx_power_on_signal(struct phy *phy)
  1341. {
  1342. #if !defined(CONFIG_MACH_MT6885) && !defined(CONFIG_MACH_MT6873) \
  1343. && !defined(CONFIG_MACH_MT6893) && !defined(CONFIG_MACH_MT6853) \
  1344. && !defined(CONFIG_MACH_MT6833)
  1345. struct mtk_mipi_tx *mipi_tx = phy_get_drvdata(phy);
  1346. u32 reg;
  1347. for (reg = MIPITX_DSI_CLOCK_LANE; reg <= MIPITX_DSI_DATA_LANE3;
  1348. reg += 4)
  1349. mtk_mipi_tx_set_bits(mipi_tx, reg, RG_DSI_LNTx_LDOOUT_EN);
  1350. mtk_mipi_tx_clear_bits(mipi_tx, MIPITX_DSI_TOP_CON,
  1351. RG_DSI_PAD_TIE_LOW_EN);
  1352. #endif
  1353. return 0;
  1354. }
  1355. #ifdef MTK_FILL_MIPI_IMPEDANCE
  1356. unsigned int rt_code_backup0[2][25];
  1357. unsigned int rt_code_backup1[2][25];
  1358. unsigned int rt_dem_code_backup0[2][5];
  1359. unsigned int rt_dem_code_backup1[2][5];
  1360. #define SECOND_PHY_OFFSET (0x10000UL)
  1361. static void backup_mipitx_impedance(struct mtk_mipi_tx *mipi_tx)
  1362. {
  1363. unsigned int i = 0;
  1364. unsigned int j = 0;
  1365. unsigned int k = 0;
  1366. /* backup mipitx impedance */
  1367. for (i = 0; i < 2; i++) {
  1368. if (i == 0) {
  1369. for (j = 0; j < 5; j++)
  1370. for (k = 0; k < 5; k++) {
  1371. rt_code_backup0[0][j*5 + k] =
  1372. readl(mipi_tx->regs +
  1373. MIPITX_D2P_RTCODE0 +
  1374. k * 0x4 + j * 0x100);
  1375. rt_code_backup1[0][j*5 + k] =
  1376. readl(mipi_tx->regs +
  1377. MIPITX_D2N_RTCODE0 +
  1378. k * 0x4 + j * 0x100);
  1379. }
  1380. } else {
  1381. for (j = 0; j < 5; j++) {
  1382. rt_dem_code_backup0[0][j] =
  1383. readl(mipi_tx->regs +
  1384. MIPITX_D2P_RT_DEM_CODE +
  1385. j * 0x100);
  1386. rt_dem_code_backup1[0][j] =
  1387. readl(mipi_tx->regs +
  1388. MIPITX_D2N_RT_DEM_CODE +
  1389. j * 0x100);
  1390. }
  1391. }
  1392. }
  1393. #if 0 /* Verification log */
  1394. for (i = 0; i < 10; i++) {
  1395. if (i < 5)
  1396. k = i * 0x100;
  1397. else
  1398. k = (i - 5) * 0x100;
  1399. if (i < 5) {
  1400. DDPDUMP("MIPI_TX ");
  1401. DDPDUMP("[0x%08x]:0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
  1402. mipi_tx->regs_pa +
  1403. MIPITX_D2P_RTCODE0 + k,
  1404. readl((mipi_tx->regs +
  1405. MIPITX_D2P_RTCODE0 + k)),
  1406. readl((mipi_tx->regs +
  1407. MIPITX_D2P_RTCODE0 + k + 0x4)),
  1408. readl((mipi_tx->regs +
  1409. MIPITX_D2P_RTCODE0 + k + 0x8)),
  1410. readl((mipi_tx->regs +
  1411. MIPITX_D2P_RTCODE0 + k + 0xC)),
  1412. readl((mipi_tx->regs +
  1413. MIPITX_D2P_RTCODE0 + k + 0x10)));
  1414. DDPDUMP("MIPI_TX2");
  1415. DDPDUMP("[0x%08x]:0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
  1416. mipi_tx->regs_pa +
  1417. MIPITX_D2N_RTCODE0 + k,
  1418. readl((mipi_tx->regs +
  1419. MIPITX_D2N_RTCODE0 + k)),
  1420. readl((mipi_tx->regs +
  1421. MIPITX_D2N_RTCODE0 + k + 0x4)),
  1422. readl((mipi_tx->regs +
  1423. MIPITX_D2N_RTCODE0 + k + 0x8)),
  1424. readl((mipi_tx->regs +
  1425. MIPITX_D2N_RTCODE0 + k + 0xC)),
  1426. readl((mipi_tx->regs +
  1427. MIPITX_D2N_RTCODE0 + k + 0x10)));
  1428. } else {
  1429. DDPDUMP("MIPI_TX[0x%08x]: 0x%08x\n",
  1430. mipi_tx->regs_pa +
  1431. MIPITX_D2P_RT_DEM_CODE + k,
  1432. readl((mipi_tx->regs +
  1433. MIPITX_D2P_RT_DEM_CODE + k)));
  1434. DDPDUMP("MIPI_TX[0x%08x]: 0x%08x\n",
  1435. mipi_tx->regs_pa +
  1436. MIPITX_D2N_RT_DEM_CODE + k,
  1437. readl((mipi_tx->regs +
  1438. MIPITX_D2N_RT_DEM_CODE + k)));
  1439. }
  1440. }
  1441. #endif /* mipitx impedance print */
  1442. #if defined(CONFIG_MACH_MT6885) || defined(CONFIG_MACH_MT6893)
  1443. #if 0 /* Second mipi tx is not currently in use */
  1444. /* backup second mipitx impedance */
  1445. for (i = 0; i < 2; i++) {
  1446. if (i == 0) {
  1447. for (j = 0; j < 5; j++)
  1448. for (k = 0; k < 5; k++) {
  1449. rt_code_backup0[1][j*5 + k] =
  1450. readl(mipi_tx->regs +
  1451. SECOND_PHY_OFFSET +
  1452. MIPITX_D2P_RTCODE0 +
  1453. k * 0x4 + j * 0x100);
  1454. rt_code_backup1[1][j*5 + k] =
  1455. readl(mipi_tx->regs +
  1456. SECOND_PHY_OFFSET +
  1457. MIPITX_D2N_RTCODE0 +
  1458. k * 0x4 + j * 0x100);
  1459. }
  1460. } else {
  1461. for (j = 0; j < 5; j++) {
  1462. rt_dem_code_backup0[1][j] =
  1463. readl(mipi_tx->regs +
  1464. SECOND_PHY_OFFSET +
  1465. MIPITX_D2P_RT_DEM_CODE +
  1466. j * 0x100);
  1467. rt_dem_code_backup1[1][j] =
  1468. readl(mipi_tx->regs +
  1469. SECOND_PHY_OFFSET +
  1470. MIPITX_D2N_RT_DEM_CODE +
  1471. j * 0x100);
  1472. }
  1473. }
  1474. }
  1475. #endif /* sedond mipi tx is not currently in use */
  1476. #if 0 /* Verification log */
  1477. for (i = 0; i < 10; i++) {
  1478. if (i < 5)
  1479. k = i * 0x100;
  1480. else
  1481. k = (i - 5) * 0x100;
  1482. if (i < 5) {
  1483. DDPDUMP("MIPI_TX ");
  1484. DDPDUMP("[0x%08x]:0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
  1485. mipi_tx->regs_pa + SECOND_PHY_OFFSET +
  1486. MIPITX_D2P_RTCODE0 + k,
  1487. readl((mipi_tx->regs + SECOND_PHY_OFFSET +
  1488. MIPITX_D2P_RTCODE0 + k)),
  1489. readl((mipi_tx->regs + SECOND_PHY_OFFSET +
  1490. MIPITX_D2P_RTCODE0 + k + 0x4)),
  1491. readl((mipi_tx->regs + SECOND_PHY_OFFSET +
  1492. MIPITX_D2P_RTCODE0 + k + 0x8)),
  1493. readl((mipi_tx->regs + SECOND_PHY_OFFSET +
  1494. MIPITX_D2P_RTCODE0 + k + 0xC)),
  1495. readl((mipi_tx->regs + SECOND_PHY_OFFSET +
  1496. MIPITX_D2P_RTCODE0 + k + 0x10)));
  1497. DDPDUMP("MIPI_TX2");
  1498. DDPDUMP("[0x%08x]:0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
  1499. mipi_tx->regs_pa + SECOND_PHY_OFFSET +
  1500. MIPITX_D2N_RTCODE0 + k,
  1501. readl((mipi_tx->regs + SECOND_PHY_OFFSET +
  1502. MIPITX_D2N_RTCODE0 + k)),
  1503. readl((mipi_tx->regs + SECOND_PHY_OFFSET +
  1504. MIPITX_D2N_RTCODE0 + k + 0x4)),
  1505. readl((mipi_tx->regs + SECOND_PHY_OFFSET +
  1506. MIPITX_D2N_RTCODE0 + k + 0x8)),
  1507. readl((mipi_tx->regs + SECOND_PHY_OFFSET +
  1508. MIPITX_D2N_RTCODE0 + k + 0xC)),
  1509. readl((mipi_tx->regs + SECOND_PHY_OFFSET +
  1510. MIPITX_D2N_RTCODE0 + k + 0x10)));
  1511. } else {
  1512. DDPDUMP("MIPI_TX[0x%08x]: 0x%08x\n",
  1513. mipi_tx->regs_pa + SECOND_PHY_OFFSET +
  1514. MIPITX_D2P_RT_DEM_CODE + k,
  1515. readl((mipi_tx->regs + SECOND_PHY_OFFSET +
  1516. MIPITX_D2P_RT_DEM_CODE + k)));
  1517. DDPDUMP("MIPI_TX[0x%08x]: 0x%08x\n",
  1518. mipi_tx->regs_pa + SECOND_PHY_OFFSET +
  1519. MIPITX_D2N_RT_DEM_CODE + k,
  1520. readl((mipi_tx->regs + SECOND_PHY_OFFSET +
  1521. MIPITX_D2N_RT_DEM_CODE + k)));
  1522. }
  1523. }
  1524. #endif /* second mipitx impedance print */
  1525. #endif /* end define MACH_MT6885 */
  1526. }
  1527. static void refill_mipitx_impedance(struct mtk_mipi_tx *mipi_tx)
  1528. {
  1529. unsigned int i = 0;
  1530. unsigned int j = 0;
  1531. unsigned int k = 0;
  1532. /* backup mipitx impedance */
  1533. for (i = 0; i < 2; i++) {
  1534. if (i == 0) {
  1535. for (j = 0; j < 5; j++)
  1536. for (k = 0; k < 5; k++) {
  1537. writel(rt_code_backup0[0][j*5 + k],
  1538. (mipi_tx->regs +
  1539. MIPITX_D2P_RTCODE0 +
  1540. k * 0x4 + j * 0x100));
  1541. writel(rt_code_backup1[0][j*5 + k],
  1542. (mipi_tx->regs +
  1543. MIPITX_D2N_RTCODE0 +
  1544. k * 0x4 + j * 0x100));
  1545. }
  1546. } else {
  1547. for (j = 0; j < 5; j++) {
  1548. writel(rt_dem_code_backup0[0][j],
  1549. (mipi_tx->regs +
  1550. MIPITX_D2P_RT_DEM_CODE +
  1551. j * 0x100));
  1552. writel(rt_dem_code_backup1[0][j],
  1553. (mipi_tx->regs +
  1554. MIPITX_D2N_RT_DEM_CODE +
  1555. j * 0x100));
  1556. }
  1557. }
  1558. }
  1559. #if 0 /* Verification log */
  1560. for (i = 0; i < 10; i++) {
  1561. if (i < 5)
  1562. k = i * 0x100;
  1563. else
  1564. k = (i - 5) * 0x100;
  1565. if (i < 5) {
  1566. DDPDUMP("MIPI_TX ");
  1567. DDPDUMP("[0x%08x]:0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
  1568. mipi_tx->regs_pa +
  1569. MIPITX_D2P_RTCODE0 + k,
  1570. readl((mipi_tx->regs +
  1571. MIPITX_D2P_RTCODE0 + k)),
  1572. readl((mipi_tx->regs +
  1573. MIPITX_D2P_RTCODE0 + k + 0x4)),
  1574. readl((mipi_tx->regs +
  1575. MIPITX_D2P_RTCODE0 + k + 0x8)),
  1576. readl((mipi_tx->regs +
  1577. MIPITX_D2P_RTCODE0 + k + 0xC)),
  1578. readl((mipi_tx->regs +
  1579. MIPITX_D2P_RTCODE0 + k + 0x10)));
  1580. DDPDUMP("MIPI_TX2");
  1581. DDPDUMP("[0x%08x]:0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
  1582. mipi_tx->regs_pa +
  1583. MIPITX_D2N_RTCODE0 + k,
  1584. readl((mipi_tx->regs +
  1585. MIPITX_D2N_RTCODE0 + k)),
  1586. readl((mipi_tx->regs +
  1587. MIPITX_D2N_RTCODE0 + k + 0x4)),
  1588. readl((mipi_tx->regs +
  1589. MIPITX_D2N_RTCODE0 + k + 0x8)),
  1590. readl((mipi_tx->regs +
  1591. MIPITX_D2N_RTCODE0 + k + 0xC)),
  1592. readl((mipi_tx->regs +
  1593. MIPITX_D2N_RTCODE0 + k + 0x10)));
  1594. } else {
  1595. DDPDUMP("MIPI_TX[0x%08x]: 0x%08x\n",
  1596. mipi_tx->regs_pa +
  1597. MIPITX_D2P_RT_DEM_CODE + k,
  1598. readl((mipi_tx->regs +
  1599. MIPITX_D2P_RT_DEM_CODE + k)));
  1600. DDPDUMP("MIPI_TX[0x%08x]: 0x%08x\n",
  1601. mipi_tx->regs_pa +
  1602. MIPITX_D2N_RT_DEM_CODE + k,
  1603. readl((mipi_tx->regs +
  1604. MIPITX_D2N_RT_DEM_CODE + k)));
  1605. }
  1606. }
  1607. #endif /* mipitx impedance print */
  1608. #if defined(CONFIG_MACH_MT6885) || defined(CONFIG_MACH_MT6893)
  1609. #if 0 /* Second mipi tx is not currently in use */
  1610. /* refill second mipitx impedance */
  1611. for (i = 0; i < 2; i++) {
  1612. if (i == 0) {
  1613. for (j = 0; j < 5; j++)
  1614. for (k = 0; k < 5; k++) {
  1615. writel(rt_code_backup0[1][j*5 + k],
  1616. (mipi_tx->regs +
  1617. SECOND_PHY_OFFSET +
  1618. MIPITX_D2P_RTCODE0 +
  1619. k * 0x4 + j * 0x100));
  1620. writel(rt_code_backup1[1][j*5 + k],
  1621. (mipi_tx->regs +
  1622. SECOND_PHY_OFFSET +
  1623. MIPITX_D2N_RTCODE0 +
  1624. k * 0x4 + j * 0x100));
  1625. }
  1626. } else {
  1627. for (j = 0; j < 5; j++) {
  1628. writel(rt_dem_code_backup0[1][j],
  1629. (mipi_tx->regs +
  1630. SECOND_PHY_OFFSET +
  1631. MIPITX_D2P_RT_DEM_CODE +
  1632. j * 0x100));
  1633. writel(rt_dem_code_backup1[1][j],
  1634. (mipi_tx->regs +
  1635. SECOND_PHY_OFFSET +
  1636. MIPITX_D2N_RT_DEM_CODE +
  1637. j * 0x100));
  1638. }
  1639. }
  1640. }
  1641. #endif /* Second mipi tx is not currently in use */
  1642. #if 0 /* Verification log */
  1643. for (i = 0; i < 10; i++) {
  1644. if (i < 5)
  1645. k = i * 0x100;
  1646. else
  1647. k = (i - 5) * 0x100;
  1648. if (i < 5) {
  1649. DDPDUMP("MIPI_TX ");
  1650. DDPDUMP("[0x%08x]:0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
  1651. mipi_tx->regs_pa + SECOND_PHY_OFFSET +
  1652. MIPITX_D2P_RTCODE0 + k,
  1653. readl((mipi_tx->regs + SECOND_PHY_OFFSET +
  1654. MIPITX_D2P_RTCODE0 + k)),
  1655. readl((mipi_tx->regs + SECOND_PHY_OFFSET +
  1656. MIPITX_D2P_RTCODE0 + k + 0x4)),
  1657. readl((mipi_tx->regs + SECOND_PHY_OFFSET +
  1658. MIPITX_D2P_RTCODE0 + k + 0x8)),
  1659. readl((mipi_tx->regs + SECOND_PHY_OFFSET +
  1660. MIPITX_D2P_RTCODE0 + k + 0xC)),
  1661. readl((mipi_tx->regs + SECOND_PHY_OFFSET +
  1662. MIPITX_D2P_RTCODE0 + k + 0x10)));
  1663. DDPDUMP("MIPI_TX2");
  1664. DDPDUMP("[0x%08x]:0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
  1665. mipi_tx->regs_pa + SECOND_PHY_OFFSET +
  1666. MIPITX_D2N_RTCODE0 + k,
  1667. readl((mipi_tx->regs + SECOND_PHY_OFFSET +
  1668. MIPITX_D2N_RTCODE0 + k)),
  1669. readl((mipi_tx->regs + SECOND_PHY_OFFSET +
  1670. MIPITX_D2N_RTCODE0 + k + 0x4)),
  1671. readl((mipi_tx->regs + SECOND_PHY_OFFSET +
  1672. MIPITX_D2N_RTCODE0 + k + 0x8)),
  1673. readl((mipi_tx->regs + SECOND_PHY_OFFSET +
  1674. MIPITX_D2N_RTCODE0 + k + 0xC)),
  1675. readl((mipi_tx->regs + SECOND_PHY_OFFSET +
  1676. MIPITX_D2N_RTCODE0 + k + 0x10)));
  1677. } else {
  1678. DDPDUMP("MIPI_TX[0x%08x]: 0x%08x\n",
  1679. mipi_tx->regs_pa + SECOND_PHY_OFFSET +
  1680. MIPITX_D2P_RT_DEM_CODE + k,
  1681. readl((mipi_tx->regs + SECOND_PHY_OFFSET +
  1682. MIPITX_D2P_RT_DEM_CODE + k)));
  1683. DDPDUMP("MIPI_TX[0x%08x]: 0x%08x\n",
  1684. mipi_tx->regs_pa + SECOND_PHY_OFFSET +
  1685. MIPITX_D2N_RT_DEM_CODE + k,
  1686. readl((mipi_tx->regs + SECOND_PHY_OFFSET +
  1687. MIPITX_D2N_RT_DEM_CODE + k)));
  1688. }
  1689. }
  1690. #endif /* second mipitx impedance print */
  1691. #endif /* end define MACH_MT6885 */
  1692. }
  1693. #endif
  1694. static int mtk_mipi_tx_power_on(struct phy *phy)
  1695. {
  1696. struct mtk_mipi_tx *mipi_tx = phy_get_drvdata(phy);
  1697. int ret;
  1698. /* Power up core and enable PLL */
  1699. ret = clk_prepare_enable(mipi_tx->pll);
  1700. if (ret < 0)
  1701. return ret;
  1702. /* Enable DSI Lane LDO outputs, disable pad tie low */
  1703. if (mipi_tx->driver_data->power_on_signal)
  1704. mipi_tx->driver_data->power_on_signal(phy);
  1705. #ifdef MTK_FILL_MIPI_IMPEDANCE
  1706. refill_mipitx_impedance(mipi_tx);
  1707. #endif
  1708. return 0;
  1709. }
  1710. static void mtk_mipi_tx_power_off_signal(struct phy *phy)
  1711. {
  1712. #if !defined(CONFIG_MACH_MT6885) && !defined(CONFIG_MACH_MT6873) \
  1713. && !defined(CONFIG_MACH_MT6893) && !defined(CONFIG_MACH_MT6853) \
  1714. && !defined(CONFIG_MACH_MT6833)
  1715. struct mtk_mipi_tx *mipi_tx = phy_get_drvdata(phy);
  1716. u32 reg;
  1717. mtk_mipi_tx_set_bits(mipi_tx, MIPITX_DSI_TOP_CON,
  1718. RG_DSI_PAD_TIE_LOW_EN);
  1719. for (reg = MIPITX_DSI_CLOCK_LANE; reg <= MIPITX_DSI_DATA_LANE3;
  1720. reg += 4)
  1721. mtk_mipi_tx_clear_bits(mipi_tx, reg, RG_DSI_LNTx_LDOOUT_EN);
  1722. #endif
  1723. }
  1724. static int mtk_mipi_tx_power_off(struct phy *phy)
  1725. {
  1726. struct mtk_mipi_tx *mipi_tx = phy_get_drvdata(phy);
  1727. /* Enable pad tie low, disable DSI Lane LDO outputs */
  1728. mtk_mipi_tx_power_off_signal(phy);
  1729. /* Disable PLL and power down core */
  1730. clk_disable_unprepare(mipi_tx->pll);
  1731. return 0;
  1732. }
  1733. static const struct phy_ops mtk_mipi_tx_ops = {
  1734. .power_on = mtk_mipi_tx_power_on,
  1735. .power_off = mtk_mipi_tx_power_off,
  1736. .owner = THIS_MODULE,
  1737. };
  1738. static int mtk_mipi_tx_probe(struct platform_device *pdev)
  1739. {
  1740. struct device *dev = &pdev->dev;
  1741. struct mtk_mipi_tx *mipi_tx;
  1742. struct resource *mem;
  1743. struct clk *ref_clk;
  1744. const char *ref_clk_name;
  1745. struct clk_init_data clk_init = {
  1746. .ops = &mtk_mipi_tx_pll_ops,
  1747. .num_parents = 1,
  1748. .parent_names = (const char *const *)&ref_clk_name,
  1749. .flags = CLK_SET_RATE_GATE,
  1750. };
  1751. struct phy *phy;
  1752. struct phy_provider *phy_provider;
  1753. int ret;
  1754. DDPINFO("%s+\n", __func__);
  1755. mipi_tx = devm_kzalloc(dev, sizeof(*mipi_tx), GFP_KERNEL);
  1756. if (!mipi_tx)
  1757. return -ENOMEM;
  1758. mipi_tx->driver_data =
  1759. (struct mtk_mipitx_data *)of_device_get_match_data(&pdev->dev);
  1760. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1761. mipi_tx->regs = devm_ioremap_resource(dev, mem);
  1762. if (IS_ERR(mipi_tx->regs)) {
  1763. ret = PTR_ERR(mipi_tx->regs);
  1764. dev_err(dev, "Failed to get memory resource: %d\n", ret);
  1765. return ret;
  1766. }
  1767. mipi_tx->regs_pa = mem->start;
  1768. mipi_tx->cmdq_base = cmdq_register_device(dev);
  1769. ref_clk = devm_clk_get(dev, NULL);
  1770. if (IS_ERR(ref_clk)) {
  1771. ret = PTR_ERR(ref_clk);
  1772. dev_err(dev, "Failed to get reference clock: %d\n", ret);
  1773. return ret;
  1774. }
  1775. ref_clk_name = __clk_get_name(ref_clk);
  1776. ret = of_property_read_string(dev->of_node, "clock-output-names",
  1777. &clk_init.name);
  1778. if (ret < 0) {
  1779. dev_err(dev, "Failed to read clock-output-names: %d\n", ret);
  1780. return ret;
  1781. }
  1782. mtk_mipi_tx_pll_ops.prepare = mipi_tx->driver_data->pll_prepare;
  1783. mtk_mipi_tx_pll_ops.unprepare = mipi_tx->driver_data->pll_unprepare;
  1784. mipi_tx->pll_hw.init = &clk_init;
  1785. mipi_tx->pll = devm_clk_register(dev, &mipi_tx->pll_hw);
  1786. if (IS_ERR(mipi_tx->pll)) {
  1787. ret = PTR_ERR(mipi_tx->pll);
  1788. dev_err(dev, "Failed to register PLL: %d\n", ret);
  1789. return ret;
  1790. }
  1791. phy = devm_phy_create(dev, NULL, &mtk_mipi_tx_ops);
  1792. if (IS_ERR(phy)) {
  1793. ret = PTR_ERR(phy);
  1794. dev_err(dev, "Failed to create MIPI D-PHY: %d\n", ret);
  1795. return ret;
  1796. }
  1797. phy_set_drvdata(phy, mipi_tx);
  1798. phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
  1799. if (IS_ERR(phy_provider)) {
  1800. ret = PTR_ERR(phy_provider);
  1801. return ret;
  1802. }
  1803. mipi_tx->dev = dev;
  1804. #ifdef MTK_FILL_MIPI_IMPEDANCE
  1805. backup_mipitx_impedance(mipi_tx);
  1806. #endif
  1807. DDPINFO("%s-\n", __func__);
  1808. return of_clk_add_provider(dev->of_node, of_clk_src_simple_get,
  1809. mipi_tx->pll);
  1810. }
  1811. static int mtk_mipi_tx_remove(struct platform_device *pdev)
  1812. {
  1813. of_clk_del_provider(pdev->dev.of_node);
  1814. return 0;
  1815. }
  1816. static const struct mtk_mipitx_data mt2701_mipitx_data = {
  1817. .mppll_preserve = (3 << 8),
  1818. .pll_prepare = mtk_mipi_tx_pll_prepare,
  1819. .pll_unprepare = mtk_mipi_tx_pll_unprepare,
  1820. .power_on_signal = mtk_mipi_tx_power_on_signal,
  1821. };
  1822. static const struct mtk_mipitx_data mt6779_mipitx_data = {
  1823. .mppll_preserve = (0 << 8),
  1824. .pll_prepare = mtk_mipi_tx_pll_prepare_mt6779,
  1825. .pll_unprepare = mtk_mipi_tx_pll_unprepare_mt6779,
  1826. };
  1827. static const struct mtk_mipitx_data mt6885_mipitx_data = {
  1828. .mppll_preserve = (0 << 8),
  1829. .pll_prepare = mtk_mipi_tx_pll_prepare_mt6885,
  1830. .pll_unprepare = mtk_mipi_tx_pll_unprepare_mt6885,
  1831. };
  1832. static const struct mtk_mipitx_data mt6885_mipitx_cphy_data = {
  1833. .mppll_preserve = (0 << 8),
  1834. .pll_prepare = mtk_mipi_tx_pll_cphy_prepare_mt6873,
  1835. .pll_unprepare = mtk_mipi_tx_pll_cphy_unprepare_mt6873,
  1836. };
  1837. static const struct mtk_mipitx_data mt6873_mipitx_data = {
  1838. .mppll_preserve = (0 << 8),
  1839. .pll_prepare = mtk_mipi_tx_pll_prepare_mt6873,
  1840. .pll_unprepare = mtk_mipi_tx_pll_unprepare_mt6873,
  1841. };
  1842. static const struct mtk_mipitx_data mt6873_mipitx_cphy_data = {
  1843. .mppll_preserve = (0 << 8),
  1844. .pll_prepare = mtk_mipi_tx_pll_cphy_prepare_mt6873,
  1845. .pll_unprepare = mtk_mipi_tx_pll_cphy_unprepare_mt6873,
  1846. };
  1847. static const struct mtk_mipitx_data mt6853_mipitx_data = {
  1848. .mppll_preserve = (0 << 8),
  1849. .pll_prepare = mtk_mipi_tx_pll_prepare_mt6853,
  1850. .pll_unprepare = mtk_mipi_tx_pll_unprepare_mt6853,
  1851. };
  1852. static const struct mtk_mipitx_data mt6833_mipitx_data = {
  1853. .mppll_preserve = (0 << 8),
  1854. .pll_prepare = mtk_mipi_tx_pll_prepare_mt6833,
  1855. .pll_unprepare = mtk_mipi_tx_pll_unprepare_mt6833,
  1856. };
  1857. static const struct mtk_mipitx_data mt8173_mipitx_data = {
  1858. .mppll_preserve = (0 << 8),
  1859. .pll_prepare = mtk_mipi_tx_pll_prepare,
  1860. .pll_unprepare = mtk_mipi_tx_pll_unprepare,
  1861. .power_on_signal = mtk_mipi_tx_power_on_signal,
  1862. };
  1863. static const struct of_device_id mtk_mipi_tx_match[] = {
  1864. {.compatible = "mediatek,mt2701-mipi-tx", .data = &mt2701_mipitx_data},
  1865. {.compatible = "mediatek,mt6779-mipi-tx", .data = &mt6779_mipitx_data},
  1866. {.compatible = "mediatek,mt8173-mipi-tx", .data = &mt8173_mipitx_data},
  1867. {.compatible = "mediatek,mt6885-mipi-tx", .data = &mt6885_mipitx_data},
  1868. {.compatible = "mediatek,mt6873-mipi-tx", .data = &mt6873_mipitx_data},
  1869. {.compatible = "mediatek,mt6853-mipi-tx", .data = &mt6853_mipitx_data},
  1870. {.compatible = "mediatek,mt6833-mipi-tx", .data = &mt6833_mipitx_data},
  1871. {.compatible = "mediatek,mt6873-mipi-tx-cphy",
  1872. .data = &mt6873_mipitx_cphy_data},
  1873. {.compatible = "mediatek,mt6885-mipi-tx-cphy",
  1874. .data = &mt6885_mipitx_cphy_data},
  1875. {},
  1876. };
  1877. struct platform_driver mtk_mipi_tx_driver = {
  1878. .probe = mtk_mipi_tx_probe,
  1879. .remove = mtk_mipi_tx_remove,
  1880. .driver = {
  1881. .name = "mediatek-mipi-tx",
  1882. .of_match_table = mtk_mipi_tx_match,
  1883. },
  1884. };