dsi_host.c 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318
  1. /*
  2. * Copyright (c) 2015, The Linux Foundation. All rights reserved.
  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 and
  6. * only version 2 as 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/delay.h>
  15. #include <linux/err.h>
  16. #include <linux/gpio.h>
  17. #include <linux/gpio/consumer.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/of_device.h>
  20. #include <linux/of_gpio.h>
  21. #include <linux/of_irq.h>
  22. #include <linux/pinctrl/consumer.h>
  23. #include <linux/of_graph.h>
  24. #include <linux/regulator/consumer.h>
  25. #include <linux/spinlock.h>
  26. #include <linux/mfd/syscon.h>
  27. #include <linux/regmap.h>
  28. #include <video/mipi_display.h>
  29. #include "dsi.h"
  30. #include "dsi.xml.h"
  31. #include "sfpb.xml.h"
  32. #include "dsi_cfg.h"
  33. static int dsi_get_version(const void __iomem *base, u32 *major, u32 *minor)
  34. {
  35. u32 ver;
  36. if (!major || !minor)
  37. return -EINVAL;
  38. /*
  39. * From DSI6G(v3), addition of a 6G_HW_VERSION register at offset 0
  40. * makes all other registers 4-byte shifted down.
  41. *
  42. * In order to identify between DSI6G(v3) and beyond, and DSIv2 and
  43. * older, we read the DSI_VERSION register without any shift(offset
  44. * 0x1f0). In the case of DSIv2, this hast to be a non-zero value. In
  45. * the case of DSI6G, this has to be zero (the offset points to a
  46. * scratch register which we never touch)
  47. */
  48. ver = msm_readl(base + REG_DSI_VERSION);
  49. if (ver) {
  50. /* older dsi host, there is no register shift */
  51. ver = FIELD(ver, DSI_VERSION_MAJOR);
  52. if (ver <= MSM_DSI_VER_MAJOR_V2) {
  53. /* old versions */
  54. *major = ver;
  55. *minor = 0;
  56. return 0;
  57. } else {
  58. return -EINVAL;
  59. }
  60. } else {
  61. /*
  62. * newer host, offset 0 has 6G_HW_VERSION, the rest of the
  63. * registers are shifted down, read DSI_VERSION again with
  64. * the shifted offset
  65. */
  66. ver = msm_readl(base + DSI_6G_REG_SHIFT + REG_DSI_VERSION);
  67. ver = FIELD(ver, DSI_VERSION_MAJOR);
  68. if (ver == MSM_DSI_VER_MAJOR_6G) {
  69. /* 6G version */
  70. *major = ver;
  71. *minor = msm_readl(base + REG_DSI_6G_HW_VERSION);
  72. return 0;
  73. } else {
  74. return -EINVAL;
  75. }
  76. }
  77. }
  78. #define DSI_ERR_STATE_ACK 0x0000
  79. #define DSI_ERR_STATE_TIMEOUT 0x0001
  80. #define DSI_ERR_STATE_DLN0_PHY 0x0002
  81. #define DSI_ERR_STATE_FIFO 0x0004
  82. #define DSI_ERR_STATE_MDP_FIFO_UNDERFLOW 0x0008
  83. #define DSI_ERR_STATE_INTERLEAVE_OP_CONTENTION 0x0010
  84. #define DSI_ERR_STATE_PLL_UNLOCKED 0x0020
  85. #define DSI_CLK_CTRL_ENABLE_CLKS \
  86. (DSI_CLK_CTRL_AHBS_HCLK_ON | DSI_CLK_CTRL_AHBM_SCLK_ON | \
  87. DSI_CLK_CTRL_PCLK_ON | DSI_CLK_CTRL_DSICLK_ON | \
  88. DSI_CLK_CTRL_BYTECLK_ON | DSI_CLK_CTRL_ESCCLK_ON | \
  89. DSI_CLK_CTRL_FORCE_ON_DYN_AHBM_HCLK)
  90. struct msm_dsi_host {
  91. struct mipi_dsi_host base;
  92. struct platform_device *pdev;
  93. struct drm_device *dev;
  94. int id;
  95. void __iomem *ctrl_base;
  96. struct regulator_bulk_data supplies[DSI_DEV_REGULATOR_MAX];
  97. struct clk *bus_clks[DSI_BUS_CLK_MAX];
  98. struct clk *byte_clk;
  99. struct clk *esc_clk;
  100. struct clk *pixel_clk;
  101. struct clk *byte_clk_src;
  102. struct clk *pixel_clk_src;
  103. u32 byte_clk_rate;
  104. u32 esc_clk_rate;
  105. /* DSI v2 specific clocks */
  106. struct clk *src_clk;
  107. struct clk *esc_clk_src;
  108. struct clk *dsi_clk_src;
  109. u32 src_clk_rate;
  110. struct gpio_desc *disp_en_gpio;
  111. struct gpio_desc *te_gpio;
  112. const struct msm_dsi_cfg_handler *cfg_hnd;
  113. struct completion dma_comp;
  114. struct completion video_comp;
  115. struct mutex dev_mutex;
  116. struct mutex cmd_mutex;
  117. struct mutex clk_mutex;
  118. spinlock_t intr_lock; /* Protect interrupt ctrl register */
  119. u32 err_work_state;
  120. struct work_struct err_work;
  121. struct work_struct hpd_work;
  122. struct workqueue_struct *workqueue;
  123. /* DSI 6G TX buffer*/
  124. struct drm_gem_object *tx_gem_obj;
  125. /* DSI v2 TX buffer */
  126. void *tx_buf;
  127. dma_addr_t tx_buf_paddr;
  128. int tx_size;
  129. u8 *rx_buf;
  130. struct regmap *sfpb;
  131. struct drm_display_mode *mode;
  132. /* connected device info */
  133. struct device_node *device_node;
  134. unsigned int channel;
  135. unsigned int lanes;
  136. enum mipi_dsi_pixel_format format;
  137. unsigned long mode_flags;
  138. /* lane data parsed via DT */
  139. int dlane_swap;
  140. int num_data_lanes;
  141. u32 dma_cmd_ctrl_restore;
  142. bool registered;
  143. bool power_on;
  144. int irq;
  145. };
  146. static u32 dsi_get_bpp(const enum mipi_dsi_pixel_format fmt)
  147. {
  148. switch (fmt) {
  149. case MIPI_DSI_FMT_RGB565: return 16;
  150. case MIPI_DSI_FMT_RGB666_PACKED: return 18;
  151. case MIPI_DSI_FMT_RGB666:
  152. case MIPI_DSI_FMT_RGB888:
  153. default: return 24;
  154. }
  155. }
  156. static inline u32 dsi_read(struct msm_dsi_host *msm_host, u32 reg)
  157. {
  158. return msm_readl(msm_host->ctrl_base + reg);
  159. }
  160. static inline void dsi_write(struct msm_dsi_host *msm_host, u32 reg, u32 data)
  161. {
  162. msm_writel(data, msm_host->ctrl_base + reg);
  163. }
  164. static int dsi_host_regulator_enable(struct msm_dsi_host *msm_host);
  165. static void dsi_host_regulator_disable(struct msm_dsi_host *msm_host);
  166. static const struct msm_dsi_cfg_handler *dsi_get_config(
  167. struct msm_dsi_host *msm_host)
  168. {
  169. const struct msm_dsi_cfg_handler *cfg_hnd = NULL;
  170. struct device *dev = &msm_host->pdev->dev;
  171. struct regulator *gdsc_reg;
  172. struct clk *ahb_clk;
  173. int ret;
  174. u32 major = 0, minor = 0;
  175. gdsc_reg = regulator_get(dev, "gdsc");
  176. if (IS_ERR(gdsc_reg)) {
  177. pr_err("%s: cannot get gdsc\n", __func__);
  178. goto exit;
  179. }
  180. ahb_clk = clk_get(dev, "iface_clk");
  181. if (IS_ERR(ahb_clk)) {
  182. pr_err("%s: cannot get interface clock\n", __func__);
  183. goto put_gdsc;
  184. }
  185. ret = regulator_enable(gdsc_reg);
  186. if (ret) {
  187. pr_err("%s: unable to enable gdsc\n", __func__);
  188. goto put_clk;
  189. }
  190. ret = clk_prepare_enable(ahb_clk);
  191. if (ret) {
  192. pr_err("%s: unable to enable ahb_clk\n", __func__);
  193. goto disable_gdsc;
  194. }
  195. ret = dsi_get_version(msm_host->ctrl_base, &major, &minor);
  196. if (ret) {
  197. pr_err("%s: Invalid version\n", __func__);
  198. goto disable_clks;
  199. }
  200. cfg_hnd = msm_dsi_cfg_get(major, minor);
  201. DBG("%s: Version %x:%x\n", __func__, major, minor);
  202. disable_clks:
  203. clk_disable_unprepare(ahb_clk);
  204. disable_gdsc:
  205. regulator_disable(gdsc_reg);
  206. put_clk:
  207. clk_put(ahb_clk);
  208. put_gdsc:
  209. regulator_put(gdsc_reg);
  210. exit:
  211. return cfg_hnd;
  212. }
  213. static inline struct msm_dsi_host *to_msm_dsi_host(struct mipi_dsi_host *host)
  214. {
  215. return container_of(host, struct msm_dsi_host, base);
  216. }
  217. static void dsi_host_regulator_disable(struct msm_dsi_host *msm_host)
  218. {
  219. struct regulator_bulk_data *s = msm_host->supplies;
  220. const struct dsi_reg_entry *regs = msm_host->cfg_hnd->cfg->reg_cfg.regs;
  221. int num = msm_host->cfg_hnd->cfg->reg_cfg.num;
  222. int i;
  223. DBG("");
  224. for (i = num - 1; i >= 0; i--)
  225. if (regs[i].disable_load >= 0)
  226. regulator_set_load(s[i].consumer,
  227. regs[i].disable_load);
  228. regulator_bulk_disable(num, s);
  229. }
  230. static int dsi_host_regulator_enable(struct msm_dsi_host *msm_host)
  231. {
  232. struct regulator_bulk_data *s = msm_host->supplies;
  233. const struct dsi_reg_entry *regs = msm_host->cfg_hnd->cfg->reg_cfg.regs;
  234. int num = msm_host->cfg_hnd->cfg->reg_cfg.num;
  235. int ret, i;
  236. DBG("");
  237. for (i = 0; i < num; i++) {
  238. if (regs[i].enable_load >= 0) {
  239. ret = regulator_set_load(s[i].consumer,
  240. regs[i].enable_load);
  241. if (ret < 0) {
  242. pr_err("regulator %d set op mode failed, %d\n",
  243. i, ret);
  244. goto fail;
  245. }
  246. }
  247. }
  248. ret = regulator_bulk_enable(num, s);
  249. if (ret < 0) {
  250. pr_err("regulator enable failed, %d\n", ret);
  251. goto fail;
  252. }
  253. return 0;
  254. fail:
  255. for (i--; i >= 0; i--)
  256. regulator_set_load(s[i].consumer, regs[i].disable_load);
  257. return ret;
  258. }
  259. static int dsi_regulator_init(struct msm_dsi_host *msm_host)
  260. {
  261. struct regulator_bulk_data *s = msm_host->supplies;
  262. const struct dsi_reg_entry *regs = msm_host->cfg_hnd->cfg->reg_cfg.regs;
  263. int num = msm_host->cfg_hnd->cfg->reg_cfg.num;
  264. int i, ret;
  265. for (i = 0; i < num; i++)
  266. s[i].supply = regs[i].name;
  267. ret = devm_regulator_bulk_get(&msm_host->pdev->dev, num, s);
  268. if (ret < 0) {
  269. pr_err("%s: failed to init regulator, ret=%d\n",
  270. __func__, ret);
  271. return ret;
  272. }
  273. return 0;
  274. }
  275. static int dsi_clk_init(struct msm_dsi_host *msm_host)
  276. {
  277. struct device *dev = &msm_host->pdev->dev;
  278. const struct msm_dsi_cfg_handler *cfg_hnd = msm_host->cfg_hnd;
  279. const struct msm_dsi_config *cfg = cfg_hnd->cfg;
  280. int i, ret = 0;
  281. /* get bus clocks */
  282. for (i = 0; i < cfg->num_bus_clks; i++) {
  283. msm_host->bus_clks[i] = devm_clk_get(dev,
  284. cfg->bus_clk_names[i]);
  285. if (IS_ERR(msm_host->bus_clks[i])) {
  286. ret = PTR_ERR(msm_host->bus_clks[i]);
  287. pr_err("%s: Unable to get %s, ret = %d\n",
  288. __func__, cfg->bus_clk_names[i], ret);
  289. goto exit;
  290. }
  291. }
  292. /* get link and source clocks */
  293. msm_host->byte_clk = devm_clk_get(dev, "byte_clk");
  294. if (IS_ERR(msm_host->byte_clk)) {
  295. ret = PTR_ERR(msm_host->byte_clk);
  296. pr_err("%s: can't find dsi_byte_clk. ret=%d\n",
  297. __func__, ret);
  298. msm_host->byte_clk = NULL;
  299. goto exit;
  300. }
  301. msm_host->pixel_clk = devm_clk_get(dev, "pixel_clk");
  302. if (IS_ERR(msm_host->pixel_clk)) {
  303. ret = PTR_ERR(msm_host->pixel_clk);
  304. pr_err("%s: can't find dsi_pixel_clk. ret=%d\n",
  305. __func__, ret);
  306. msm_host->pixel_clk = NULL;
  307. goto exit;
  308. }
  309. msm_host->esc_clk = devm_clk_get(dev, "core_clk");
  310. if (IS_ERR(msm_host->esc_clk)) {
  311. ret = PTR_ERR(msm_host->esc_clk);
  312. pr_err("%s: can't find dsi_esc_clk. ret=%d\n",
  313. __func__, ret);
  314. msm_host->esc_clk = NULL;
  315. goto exit;
  316. }
  317. msm_host->byte_clk_src = clk_get_parent(msm_host->byte_clk);
  318. if (!msm_host->byte_clk_src) {
  319. ret = -ENODEV;
  320. pr_err("%s: can't find byte_clk_src. ret=%d\n", __func__, ret);
  321. goto exit;
  322. }
  323. msm_host->pixel_clk_src = clk_get_parent(msm_host->pixel_clk);
  324. if (!msm_host->pixel_clk_src) {
  325. ret = -ENODEV;
  326. pr_err("%s: can't find pixel_clk_src. ret=%d\n", __func__, ret);
  327. goto exit;
  328. }
  329. if (cfg_hnd->major == MSM_DSI_VER_MAJOR_V2) {
  330. msm_host->src_clk = devm_clk_get(dev, "src_clk");
  331. if (IS_ERR(msm_host->src_clk)) {
  332. ret = PTR_ERR(msm_host->src_clk);
  333. pr_err("%s: can't find dsi_src_clk. ret=%d\n",
  334. __func__, ret);
  335. msm_host->src_clk = NULL;
  336. goto exit;
  337. }
  338. msm_host->esc_clk_src = clk_get_parent(msm_host->esc_clk);
  339. if (!msm_host->esc_clk_src) {
  340. ret = -ENODEV;
  341. pr_err("%s: can't get esc_clk_src. ret=%d\n",
  342. __func__, ret);
  343. goto exit;
  344. }
  345. msm_host->dsi_clk_src = clk_get_parent(msm_host->src_clk);
  346. if (!msm_host->dsi_clk_src) {
  347. ret = -ENODEV;
  348. pr_err("%s: can't get dsi_clk_src. ret=%d\n",
  349. __func__, ret);
  350. }
  351. }
  352. exit:
  353. return ret;
  354. }
  355. static int dsi_bus_clk_enable(struct msm_dsi_host *msm_host)
  356. {
  357. const struct msm_dsi_config *cfg = msm_host->cfg_hnd->cfg;
  358. int i, ret;
  359. DBG("id=%d", msm_host->id);
  360. for (i = 0; i < cfg->num_bus_clks; i++) {
  361. ret = clk_prepare_enable(msm_host->bus_clks[i]);
  362. if (ret) {
  363. pr_err("%s: failed to enable bus clock %d ret %d\n",
  364. __func__, i, ret);
  365. goto err;
  366. }
  367. }
  368. return 0;
  369. err:
  370. for (; i > 0; i--)
  371. clk_disable_unprepare(msm_host->bus_clks[i]);
  372. return ret;
  373. }
  374. static void dsi_bus_clk_disable(struct msm_dsi_host *msm_host)
  375. {
  376. const struct msm_dsi_config *cfg = msm_host->cfg_hnd->cfg;
  377. int i;
  378. DBG("");
  379. for (i = cfg->num_bus_clks - 1; i >= 0; i--)
  380. clk_disable_unprepare(msm_host->bus_clks[i]);
  381. }
  382. static int dsi_link_clk_enable_6g(struct msm_dsi_host *msm_host)
  383. {
  384. int ret;
  385. DBG("Set clk rates: pclk=%d, byteclk=%d",
  386. msm_host->mode->clock, msm_host->byte_clk_rate);
  387. ret = clk_set_rate(msm_host->byte_clk, msm_host->byte_clk_rate);
  388. if (ret) {
  389. pr_err("%s: Failed to set rate byte clk, %d\n", __func__, ret);
  390. goto error;
  391. }
  392. ret = clk_set_rate(msm_host->pixel_clk, msm_host->mode->clock * 1000);
  393. if (ret) {
  394. pr_err("%s: Failed to set rate pixel clk, %d\n", __func__, ret);
  395. goto error;
  396. }
  397. ret = clk_prepare_enable(msm_host->esc_clk);
  398. if (ret) {
  399. pr_err("%s: Failed to enable dsi esc clk\n", __func__);
  400. goto error;
  401. }
  402. ret = clk_prepare_enable(msm_host->byte_clk);
  403. if (ret) {
  404. pr_err("%s: Failed to enable dsi byte clk\n", __func__);
  405. goto byte_clk_err;
  406. }
  407. ret = clk_prepare_enable(msm_host->pixel_clk);
  408. if (ret) {
  409. pr_err("%s: Failed to enable dsi pixel clk\n", __func__);
  410. goto pixel_clk_err;
  411. }
  412. return 0;
  413. pixel_clk_err:
  414. clk_disable_unprepare(msm_host->byte_clk);
  415. byte_clk_err:
  416. clk_disable_unprepare(msm_host->esc_clk);
  417. error:
  418. return ret;
  419. }
  420. static int dsi_link_clk_enable_v2(struct msm_dsi_host *msm_host)
  421. {
  422. int ret;
  423. DBG("Set clk rates: pclk=%d, byteclk=%d, esc_clk=%d, dsi_src_clk=%d",
  424. msm_host->mode->clock, msm_host->byte_clk_rate,
  425. msm_host->esc_clk_rate, msm_host->src_clk_rate);
  426. ret = clk_set_rate(msm_host->byte_clk, msm_host->byte_clk_rate);
  427. if (ret) {
  428. pr_err("%s: Failed to set rate byte clk, %d\n", __func__, ret);
  429. goto error;
  430. }
  431. ret = clk_set_rate(msm_host->esc_clk, msm_host->esc_clk_rate);
  432. if (ret) {
  433. pr_err("%s: Failed to set rate esc clk, %d\n", __func__, ret);
  434. goto error;
  435. }
  436. ret = clk_set_rate(msm_host->src_clk, msm_host->src_clk_rate);
  437. if (ret) {
  438. pr_err("%s: Failed to set rate src clk, %d\n", __func__, ret);
  439. goto error;
  440. }
  441. ret = clk_set_rate(msm_host->pixel_clk, msm_host->mode->clock * 1000);
  442. if (ret) {
  443. pr_err("%s: Failed to set rate pixel clk, %d\n", __func__, ret);
  444. goto error;
  445. }
  446. ret = clk_prepare_enable(msm_host->byte_clk);
  447. if (ret) {
  448. pr_err("%s: Failed to enable dsi byte clk\n", __func__);
  449. goto error;
  450. }
  451. ret = clk_prepare_enable(msm_host->esc_clk);
  452. if (ret) {
  453. pr_err("%s: Failed to enable dsi esc clk\n", __func__);
  454. goto esc_clk_err;
  455. }
  456. ret = clk_prepare_enable(msm_host->src_clk);
  457. if (ret) {
  458. pr_err("%s: Failed to enable dsi src clk\n", __func__);
  459. goto src_clk_err;
  460. }
  461. ret = clk_prepare_enable(msm_host->pixel_clk);
  462. if (ret) {
  463. pr_err("%s: Failed to enable dsi pixel clk\n", __func__);
  464. goto pixel_clk_err;
  465. }
  466. return 0;
  467. pixel_clk_err:
  468. clk_disable_unprepare(msm_host->src_clk);
  469. src_clk_err:
  470. clk_disable_unprepare(msm_host->esc_clk);
  471. esc_clk_err:
  472. clk_disable_unprepare(msm_host->byte_clk);
  473. error:
  474. return ret;
  475. }
  476. static int dsi_link_clk_enable(struct msm_dsi_host *msm_host)
  477. {
  478. const struct msm_dsi_cfg_handler *cfg_hnd = msm_host->cfg_hnd;
  479. if (cfg_hnd->major == MSM_DSI_VER_MAJOR_6G)
  480. return dsi_link_clk_enable_6g(msm_host);
  481. else
  482. return dsi_link_clk_enable_v2(msm_host);
  483. }
  484. static void dsi_link_clk_disable(struct msm_dsi_host *msm_host)
  485. {
  486. const struct msm_dsi_cfg_handler *cfg_hnd = msm_host->cfg_hnd;
  487. if (cfg_hnd->major == MSM_DSI_VER_MAJOR_6G) {
  488. clk_disable_unprepare(msm_host->esc_clk);
  489. clk_disable_unprepare(msm_host->pixel_clk);
  490. clk_disable_unprepare(msm_host->byte_clk);
  491. } else {
  492. clk_disable_unprepare(msm_host->pixel_clk);
  493. clk_disable_unprepare(msm_host->src_clk);
  494. clk_disable_unprepare(msm_host->esc_clk);
  495. clk_disable_unprepare(msm_host->byte_clk);
  496. }
  497. }
  498. static int dsi_clk_ctrl(struct msm_dsi_host *msm_host, bool enable)
  499. {
  500. int ret = 0;
  501. mutex_lock(&msm_host->clk_mutex);
  502. if (enable) {
  503. ret = dsi_bus_clk_enable(msm_host);
  504. if (ret) {
  505. pr_err("%s: Can not enable bus clk, %d\n",
  506. __func__, ret);
  507. goto unlock_ret;
  508. }
  509. ret = dsi_link_clk_enable(msm_host);
  510. if (ret) {
  511. pr_err("%s: Can not enable link clk, %d\n",
  512. __func__, ret);
  513. dsi_bus_clk_disable(msm_host);
  514. goto unlock_ret;
  515. }
  516. } else {
  517. dsi_link_clk_disable(msm_host);
  518. dsi_bus_clk_disable(msm_host);
  519. }
  520. unlock_ret:
  521. mutex_unlock(&msm_host->clk_mutex);
  522. return ret;
  523. }
  524. static int dsi_calc_clk_rate(struct msm_dsi_host *msm_host)
  525. {
  526. struct drm_display_mode *mode = msm_host->mode;
  527. const struct msm_dsi_cfg_handler *cfg_hnd = msm_host->cfg_hnd;
  528. u8 lanes = msm_host->lanes;
  529. u32 bpp = dsi_get_bpp(msm_host->format);
  530. u32 pclk_rate;
  531. if (!mode) {
  532. pr_err("%s: mode not set\n", __func__);
  533. return -EINVAL;
  534. }
  535. pclk_rate = mode->clock * 1000;
  536. if (lanes > 0) {
  537. msm_host->byte_clk_rate = (pclk_rate * bpp) / (8 * lanes);
  538. } else {
  539. pr_err("%s: forcing mdss_dsi lanes to 1\n", __func__);
  540. msm_host->byte_clk_rate = (pclk_rate * bpp) / 8;
  541. }
  542. DBG("pclk=%d, bclk=%d", pclk_rate, msm_host->byte_clk_rate);
  543. msm_host->esc_clk_rate = clk_get_rate(msm_host->esc_clk);
  544. if (cfg_hnd->major == MSM_DSI_VER_MAJOR_V2) {
  545. unsigned int esc_mhz, esc_div;
  546. unsigned long byte_mhz;
  547. msm_host->src_clk_rate = (pclk_rate * bpp) / 8;
  548. /*
  549. * esc clock is byte clock followed by a 4 bit divider,
  550. * we need to find an escape clock frequency within the
  551. * mipi DSI spec range within the maximum divider limit
  552. * We iterate here between an escape clock frequencey
  553. * between 20 Mhz to 5 Mhz and pick up the first one
  554. * that can be supported by our divider
  555. */
  556. byte_mhz = msm_host->byte_clk_rate / 1000000;
  557. for (esc_mhz = 20; esc_mhz >= 5; esc_mhz--) {
  558. esc_div = DIV_ROUND_UP(byte_mhz, esc_mhz);
  559. /*
  560. * TODO: Ideally, we shouldn't know what sort of divider
  561. * is available in mmss_cc, we're just assuming that
  562. * it'll always be a 4 bit divider. Need to come up with
  563. * a better way here.
  564. */
  565. if (esc_div >= 1 && esc_div <= 16)
  566. break;
  567. }
  568. if (esc_mhz < 5)
  569. return -EINVAL;
  570. msm_host->esc_clk_rate = msm_host->byte_clk_rate / esc_div;
  571. DBG("esc=%d, src=%d", msm_host->esc_clk_rate,
  572. msm_host->src_clk_rate);
  573. }
  574. return 0;
  575. }
  576. static void dsi_intr_ctrl(struct msm_dsi_host *msm_host, u32 mask, int enable)
  577. {
  578. u32 intr;
  579. unsigned long flags;
  580. spin_lock_irqsave(&msm_host->intr_lock, flags);
  581. intr = dsi_read(msm_host, REG_DSI_INTR_CTRL);
  582. if (enable)
  583. intr |= mask;
  584. else
  585. intr &= ~mask;
  586. DBG("intr=%x enable=%d", intr, enable);
  587. dsi_write(msm_host, REG_DSI_INTR_CTRL, intr);
  588. spin_unlock_irqrestore(&msm_host->intr_lock, flags);
  589. }
  590. static inline enum dsi_traffic_mode dsi_get_traffic_mode(const u32 mode_flags)
  591. {
  592. if (mode_flags & MIPI_DSI_MODE_VIDEO_BURST)
  593. return BURST_MODE;
  594. else if (mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE)
  595. return NON_BURST_SYNCH_PULSE;
  596. return NON_BURST_SYNCH_EVENT;
  597. }
  598. static inline enum dsi_vid_dst_format dsi_get_vid_fmt(
  599. const enum mipi_dsi_pixel_format mipi_fmt)
  600. {
  601. switch (mipi_fmt) {
  602. case MIPI_DSI_FMT_RGB888: return VID_DST_FORMAT_RGB888;
  603. case MIPI_DSI_FMT_RGB666: return VID_DST_FORMAT_RGB666_LOOSE;
  604. case MIPI_DSI_FMT_RGB666_PACKED: return VID_DST_FORMAT_RGB666;
  605. case MIPI_DSI_FMT_RGB565: return VID_DST_FORMAT_RGB565;
  606. default: return VID_DST_FORMAT_RGB888;
  607. }
  608. }
  609. static inline enum dsi_cmd_dst_format dsi_get_cmd_fmt(
  610. const enum mipi_dsi_pixel_format mipi_fmt)
  611. {
  612. switch (mipi_fmt) {
  613. case MIPI_DSI_FMT_RGB888: return CMD_DST_FORMAT_RGB888;
  614. case MIPI_DSI_FMT_RGB666_PACKED:
  615. case MIPI_DSI_FMT_RGB666: return VID_DST_FORMAT_RGB666;
  616. case MIPI_DSI_FMT_RGB565: return CMD_DST_FORMAT_RGB565;
  617. default: return CMD_DST_FORMAT_RGB888;
  618. }
  619. }
  620. static void dsi_ctrl_config(struct msm_dsi_host *msm_host, bool enable,
  621. struct msm_dsi_phy_shared_timings *phy_shared_timings)
  622. {
  623. u32 flags = msm_host->mode_flags;
  624. enum mipi_dsi_pixel_format mipi_fmt = msm_host->format;
  625. const struct msm_dsi_cfg_handler *cfg_hnd = msm_host->cfg_hnd;
  626. u32 data = 0;
  627. if (!enable) {
  628. dsi_write(msm_host, REG_DSI_CTRL, 0);
  629. return;
  630. }
  631. if (flags & MIPI_DSI_MODE_VIDEO) {
  632. if (flags & MIPI_DSI_MODE_VIDEO_HSE)
  633. data |= DSI_VID_CFG0_PULSE_MODE_HSA_HE;
  634. if (flags & MIPI_DSI_MODE_VIDEO_HFP)
  635. data |= DSI_VID_CFG0_HFP_POWER_STOP;
  636. if (flags & MIPI_DSI_MODE_VIDEO_HBP)
  637. data |= DSI_VID_CFG0_HBP_POWER_STOP;
  638. if (flags & MIPI_DSI_MODE_VIDEO_HSA)
  639. data |= DSI_VID_CFG0_HSA_POWER_STOP;
  640. /* Always set low power stop mode for BLLP
  641. * to let command engine send packets
  642. */
  643. data |= DSI_VID_CFG0_EOF_BLLP_POWER_STOP |
  644. DSI_VID_CFG0_BLLP_POWER_STOP;
  645. data |= DSI_VID_CFG0_TRAFFIC_MODE(dsi_get_traffic_mode(flags));
  646. data |= DSI_VID_CFG0_DST_FORMAT(dsi_get_vid_fmt(mipi_fmt));
  647. data |= DSI_VID_CFG0_VIRT_CHANNEL(msm_host->channel);
  648. dsi_write(msm_host, REG_DSI_VID_CFG0, data);
  649. /* Do not swap RGB colors */
  650. data = DSI_VID_CFG1_RGB_SWAP(SWAP_RGB);
  651. dsi_write(msm_host, REG_DSI_VID_CFG1, 0);
  652. } else {
  653. /* Do not swap RGB colors */
  654. data = DSI_CMD_CFG0_RGB_SWAP(SWAP_RGB);
  655. data |= DSI_CMD_CFG0_DST_FORMAT(dsi_get_cmd_fmt(mipi_fmt));
  656. dsi_write(msm_host, REG_DSI_CMD_CFG0, data);
  657. data = DSI_CMD_CFG1_WR_MEM_START(MIPI_DCS_WRITE_MEMORY_START) |
  658. DSI_CMD_CFG1_WR_MEM_CONTINUE(
  659. MIPI_DCS_WRITE_MEMORY_CONTINUE);
  660. /* Always insert DCS command */
  661. data |= DSI_CMD_CFG1_INSERT_DCS_COMMAND;
  662. dsi_write(msm_host, REG_DSI_CMD_CFG1, data);
  663. }
  664. dsi_write(msm_host, REG_DSI_CMD_DMA_CTRL,
  665. DSI_CMD_DMA_CTRL_FROM_FRAME_BUFFER |
  666. DSI_CMD_DMA_CTRL_LOW_POWER);
  667. data = 0;
  668. /* Always assume dedicated TE pin */
  669. data |= DSI_TRIG_CTRL_TE;
  670. data |= DSI_TRIG_CTRL_MDP_TRIGGER(TRIGGER_NONE);
  671. data |= DSI_TRIG_CTRL_DMA_TRIGGER(TRIGGER_SW);
  672. data |= DSI_TRIG_CTRL_STREAM(msm_host->channel);
  673. if ((cfg_hnd->major == MSM_DSI_VER_MAJOR_6G) &&
  674. (cfg_hnd->minor >= MSM_DSI_6G_VER_MINOR_V1_2))
  675. data |= DSI_TRIG_CTRL_BLOCK_DMA_WITHIN_FRAME;
  676. dsi_write(msm_host, REG_DSI_TRIG_CTRL, data);
  677. data = DSI_CLKOUT_TIMING_CTRL_T_CLK_POST(phy_shared_timings->clk_post) |
  678. DSI_CLKOUT_TIMING_CTRL_T_CLK_PRE(phy_shared_timings->clk_pre);
  679. dsi_write(msm_host, REG_DSI_CLKOUT_TIMING_CTRL, data);
  680. if ((cfg_hnd->major == MSM_DSI_VER_MAJOR_6G) &&
  681. (cfg_hnd->minor > MSM_DSI_6G_VER_MINOR_V1_0) &&
  682. phy_shared_timings->clk_pre_inc_by_2)
  683. dsi_write(msm_host, REG_DSI_T_CLK_PRE_EXTEND,
  684. DSI_T_CLK_PRE_EXTEND_INC_BY_2_BYTECLK);
  685. data = 0;
  686. if (!(flags & MIPI_DSI_MODE_EOT_PACKET))
  687. data |= DSI_EOT_PACKET_CTRL_TX_EOT_APPEND;
  688. dsi_write(msm_host, REG_DSI_EOT_PACKET_CTRL, data);
  689. /* allow only ack-err-status to generate interrupt */
  690. dsi_write(msm_host, REG_DSI_ERR_INT_MASK0, 0x13ff3fe0);
  691. dsi_intr_ctrl(msm_host, DSI_IRQ_MASK_ERROR, 1);
  692. dsi_write(msm_host, REG_DSI_CLK_CTRL, DSI_CLK_CTRL_ENABLE_CLKS);
  693. data = DSI_CTRL_CLK_EN;
  694. DBG("lane number=%d", msm_host->lanes);
  695. data |= ((DSI_CTRL_LANE0 << msm_host->lanes) - DSI_CTRL_LANE0);
  696. dsi_write(msm_host, REG_DSI_LANE_SWAP_CTRL,
  697. DSI_LANE_SWAP_CTRL_DLN_SWAP_SEL(msm_host->dlane_swap));
  698. if (!(flags & MIPI_DSI_CLOCK_NON_CONTINUOUS))
  699. dsi_write(msm_host, REG_DSI_LANE_CTRL,
  700. DSI_LANE_CTRL_CLKLN_HS_FORCE_REQUEST);
  701. data |= DSI_CTRL_ENABLE;
  702. dsi_write(msm_host, REG_DSI_CTRL, data);
  703. }
  704. static void dsi_timing_setup(struct msm_dsi_host *msm_host)
  705. {
  706. struct drm_display_mode *mode = msm_host->mode;
  707. u32 hs_start = 0, vs_start = 0; /* take sync start as 0 */
  708. u32 h_total = mode->htotal;
  709. u32 v_total = mode->vtotal;
  710. u32 hs_end = mode->hsync_end - mode->hsync_start;
  711. u32 vs_end = mode->vsync_end - mode->vsync_start;
  712. u32 ha_start = h_total - mode->hsync_start;
  713. u32 ha_end = ha_start + mode->hdisplay;
  714. u32 va_start = v_total - mode->vsync_start;
  715. u32 va_end = va_start + mode->vdisplay;
  716. u32 wc;
  717. DBG("");
  718. if (msm_host->mode_flags & MIPI_DSI_MODE_VIDEO) {
  719. dsi_write(msm_host, REG_DSI_ACTIVE_H,
  720. DSI_ACTIVE_H_START(ha_start) |
  721. DSI_ACTIVE_H_END(ha_end));
  722. dsi_write(msm_host, REG_DSI_ACTIVE_V,
  723. DSI_ACTIVE_V_START(va_start) |
  724. DSI_ACTIVE_V_END(va_end));
  725. dsi_write(msm_host, REG_DSI_TOTAL,
  726. DSI_TOTAL_H_TOTAL(h_total - 1) |
  727. DSI_TOTAL_V_TOTAL(v_total - 1));
  728. dsi_write(msm_host, REG_DSI_ACTIVE_HSYNC,
  729. DSI_ACTIVE_HSYNC_START(hs_start) |
  730. DSI_ACTIVE_HSYNC_END(hs_end));
  731. dsi_write(msm_host, REG_DSI_ACTIVE_VSYNC_HPOS, 0);
  732. dsi_write(msm_host, REG_DSI_ACTIVE_VSYNC_VPOS,
  733. DSI_ACTIVE_VSYNC_VPOS_START(vs_start) |
  734. DSI_ACTIVE_VSYNC_VPOS_END(vs_end));
  735. } else { /* command mode */
  736. /* image data and 1 byte write_memory_start cmd */
  737. wc = mode->hdisplay * dsi_get_bpp(msm_host->format) / 8 + 1;
  738. dsi_write(msm_host, REG_DSI_CMD_MDP_STREAM_CTRL,
  739. DSI_CMD_MDP_STREAM_CTRL_WORD_COUNT(wc) |
  740. DSI_CMD_MDP_STREAM_CTRL_VIRTUAL_CHANNEL(
  741. msm_host->channel) |
  742. DSI_CMD_MDP_STREAM_CTRL_DATA_TYPE(
  743. MIPI_DSI_DCS_LONG_WRITE));
  744. dsi_write(msm_host, REG_DSI_CMD_MDP_STREAM_TOTAL,
  745. DSI_CMD_MDP_STREAM_TOTAL_H_TOTAL(mode->hdisplay) |
  746. DSI_CMD_MDP_STREAM_TOTAL_V_TOTAL(mode->vdisplay));
  747. }
  748. }
  749. static void dsi_sw_reset(struct msm_dsi_host *msm_host)
  750. {
  751. dsi_write(msm_host, REG_DSI_CLK_CTRL, DSI_CLK_CTRL_ENABLE_CLKS);
  752. wmb(); /* clocks need to be enabled before reset */
  753. dsi_write(msm_host, REG_DSI_RESET, 1);
  754. wmb(); /* make sure reset happen */
  755. dsi_write(msm_host, REG_DSI_RESET, 0);
  756. }
  757. static void dsi_op_mode_config(struct msm_dsi_host *msm_host,
  758. bool video_mode, bool enable)
  759. {
  760. u32 dsi_ctrl;
  761. dsi_ctrl = dsi_read(msm_host, REG_DSI_CTRL);
  762. if (!enable) {
  763. dsi_ctrl &= ~(DSI_CTRL_ENABLE | DSI_CTRL_VID_MODE_EN |
  764. DSI_CTRL_CMD_MODE_EN);
  765. dsi_intr_ctrl(msm_host, DSI_IRQ_MASK_CMD_MDP_DONE |
  766. DSI_IRQ_MASK_VIDEO_DONE, 0);
  767. } else {
  768. if (video_mode) {
  769. dsi_ctrl |= DSI_CTRL_VID_MODE_EN;
  770. } else { /* command mode */
  771. dsi_ctrl |= DSI_CTRL_CMD_MODE_EN;
  772. dsi_intr_ctrl(msm_host, DSI_IRQ_MASK_CMD_MDP_DONE, 1);
  773. }
  774. dsi_ctrl |= DSI_CTRL_ENABLE;
  775. }
  776. dsi_write(msm_host, REG_DSI_CTRL, dsi_ctrl);
  777. }
  778. static void dsi_set_tx_power_mode(int mode, struct msm_dsi_host *msm_host)
  779. {
  780. u32 data;
  781. data = dsi_read(msm_host, REG_DSI_CMD_DMA_CTRL);
  782. if (mode == 0)
  783. data &= ~DSI_CMD_DMA_CTRL_LOW_POWER;
  784. else
  785. data |= DSI_CMD_DMA_CTRL_LOW_POWER;
  786. dsi_write(msm_host, REG_DSI_CMD_DMA_CTRL, data);
  787. }
  788. static void dsi_wait4video_done(struct msm_dsi_host *msm_host)
  789. {
  790. dsi_intr_ctrl(msm_host, DSI_IRQ_MASK_VIDEO_DONE, 1);
  791. reinit_completion(&msm_host->video_comp);
  792. wait_for_completion_timeout(&msm_host->video_comp,
  793. msecs_to_jiffies(70));
  794. dsi_intr_ctrl(msm_host, DSI_IRQ_MASK_VIDEO_DONE, 0);
  795. }
  796. static void dsi_wait4video_eng_busy(struct msm_dsi_host *msm_host)
  797. {
  798. if (!(msm_host->mode_flags & MIPI_DSI_MODE_VIDEO))
  799. return;
  800. if (msm_host->power_on) {
  801. dsi_wait4video_done(msm_host);
  802. /* delay 4 ms to skip BLLP */
  803. usleep_range(2000, 4000);
  804. }
  805. }
  806. /* dsi_cmd */
  807. static int dsi_tx_buf_alloc(struct msm_dsi_host *msm_host, int size)
  808. {
  809. struct drm_device *dev = msm_host->dev;
  810. const struct msm_dsi_cfg_handler *cfg_hnd = msm_host->cfg_hnd;
  811. int ret;
  812. uint64_t iova;
  813. if (cfg_hnd->major == MSM_DSI_VER_MAJOR_6G) {
  814. mutex_lock(&dev->struct_mutex);
  815. msm_host->tx_gem_obj = msm_gem_new(dev, size, MSM_BO_UNCACHED);
  816. if (IS_ERR(msm_host->tx_gem_obj)) {
  817. ret = PTR_ERR(msm_host->tx_gem_obj);
  818. pr_err("%s: failed to allocate gem, %d\n",
  819. __func__, ret);
  820. msm_host->tx_gem_obj = NULL;
  821. mutex_unlock(&dev->struct_mutex);
  822. return ret;
  823. }
  824. ret = msm_gem_get_iova_locked(msm_host->tx_gem_obj, 0, &iova);
  825. mutex_unlock(&dev->struct_mutex);
  826. if (ret) {
  827. pr_err("%s: failed to get iova, %d\n", __func__, ret);
  828. return ret;
  829. }
  830. if (iova & 0x07) {
  831. pr_err("%s: buf NOT 8 bytes aligned\n", __func__);
  832. return -EINVAL;
  833. }
  834. msm_host->tx_size = msm_host->tx_gem_obj->size;
  835. } else {
  836. msm_host->tx_buf = dma_alloc_coherent(dev->dev, size,
  837. &msm_host->tx_buf_paddr, GFP_KERNEL);
  838. if (!msm_host->tx_buf) {
  839. ret = -ENOMEM;
  840. pr_err("%s: failed to allocate tx buf, %d\n",
  841. __func__, ret);
  842. return ret;
  843. }
  844. msm_host->tx_size = size;
  845. }
  846. return 0;
  847. }
  848. static void dsi_tx_buf_free(struct msm_dsi_host *msm_host)
  849. {
  850. struct drm_device *dev = msm_host->dev;
  851. if (msm_host->tx_gem_obj) {
  852. msm_gem_put_iova(msm_host->tx_gem_obj, 0);
  853. mutex_lock(&dev->struct_mutex);
  854. msm_gem_free_object(msm_host->tx_gem_obj);
  855. msm_host->tx_gem_obj = NULL;
  856. mutex_unlock(&dev->struct_mutex);
  857. }
  858. if (msm_host->tx_buf)
  859. dma_free_coherent(dev->dev, msm_host->tx_size, msm_host->tx_buf,
  860. msm_host->tx_buf_paddr);
  861. }
  862. /*
  863. * prepare cmd buffer to be txed
  864. */
  865. static int dsi_cmd_dma_add(struct msm_dsi_host *msm_host,
  866. const struct mipi_dsi_msg *msg)
  867. {
  868. const struct msm_dsi_cfg_handler *cfg_hnd = msm_host->cfg_hnd;
  869. struct mipi_dsi_packet packet;
  870. int len;
  871. int ret;
  872. u8 *data;
  873. ret = mipi_dsi_create_packet(&packet, msg);
  874. if (ret) {
  875. pr_err("%s: create packet failed, %d\n", __func__, ret);
  876. return ret;
  877. }
  878. len = (packet.size + 3) & (~0x3);
  879. if (len > msm_host->tx_size) {
  880. pr_err("%s: packet size is too big\n", __func__);
  881. return -EINVAL;
  882. }
  883. if (cfg_hnd->major == MSM_DSI_VER_MAJOR_6G) {
  884. data = msm_gem_get_vaddr(msm_host->tx_gem_obj);
  885. if (IS_ERR(data)) {
  886. ret = PTR_ERR(data);
  887. pr_err("%s: get vaddr failed, %d\n", __func__, ret);
  888. return ret;
  889. }
  890. } else {
  891. data = msm_host->tx_buf;
  892. }
  893. /* MSM specific command format in memory */
  894. data[0] = packet.header[1];
  895. data[1] = packet.header[2];
  896. data[2] = packet.header[0];
  897. data[3] = BIT(7); /* Last packet */
  898. if (mipi_dsi_packet_format_is_long(msg->type))
  899. data[3] |= BIT(6);
  900. if (msg->rx_buf && msg->rx_len)
  901. data[3] |= BIT(5);
  902. /* Long packet */
  903. if (packet.payload && packet.payload_length)
  904. memcpy(data + 4, packet.payload, packet.payload_length);
  905. /* Append 0xff to the end */
  906. if (packet.size < len)
  907. memset(data + packet.size, 0xff, len - packet.size);
  908. if (cfg_hnd->major == MSM_DSI_VER_MAJOR_6G)
  909. msm_gem_put_vaddr(msm_host->tx_gem_obj);
  910. return len;
  911. }
  912. /*
  913. * dsi_short_read1_resp: 1 parameter
  914. */
  915. static int dsi_short_read1_resp(u8 *buf, const struct mipi_dsi_msg *msg)
  916. {
  917. u8 *data = msg->rx_buf;
  918. if (data && (msg->rx_len >= 1)) {
  919. *data = buf[1]; /* strip out dcs type */
  920. return 1;
  921. } else {
  922. pr_err("%s: read data does not match with rx_buf len %zu\n",
  923. __func__, msg->rx_len);
  924. return -EINVAL;
  925. }
  926. }
  927. /*
  928. * dsi_short_read2_resp: 2 parameter
  929. */
  930. static int dsi_short_read2_resp(u8 *buf, const struct mipi_dsi_msg *msg)
  931. {
  932. u8 *data = msg->rx_buf;
  933. if (data && (msg->rx_len >= 2)) {
  934. data[0] = buf[1]; /* strip out dcs type */
  935. data[1] = buf[2];
  936. return 2;
  937. } else {
  938. pr_err("%s: read data does not match with rx_buf len %zu\n",
  939. __func__, msg->rx_len);
  940. return -EINVAL;
  941. }
  942. }
  943. static int dsi_long_read_resp(u8 *buf, const struct mipi_dsi_msg *msg)
  944. {
  945. /* strip out 4 byte dcs header */
  946. if (msg->rx_buf && msg->rx_len)
  947. memcpy(msg->rx_buf, buf + 4, msg->rx_len);
  948. return msg->rx_len;
  949. }
  950. static int dsi_cmd_dma_tx(struct msm_dsi_host *msm_host, int len)
  951. {
  952. const struct msm_dsi_cfg_handler *cfg_hnd = msm_host->cfg_hnd;
  953. int ret;
  954. uint64_t dma_base;
  955. bool triggered;
  956. if (cfg_hnd->major == MSM_DSI_VER_MAJOR_6G) {
  957. ret = msm_gem_get_iova(msm_host->tx_gem_obj, 0, &dma_base);
  958. if (ret) {
  959. pr_err("%s: failed to get iova: %d\n", __func__, ret);
  960. return ret;
  961. }
  962. } else {
  963. dma_base = msm_host->tx_buf_paddr;
  964. }
  965. reinit_completion(&msm_host->dma_comp);
  966. dsi_wait4video_eng_busy(msm_host);
  967. triggered = msm_dsi_manager_cmd_xfer_trigger(
  968. msm_host->id, dma_base, len);
  969. if (triggered) {
  970. ret = wait_for_completion_timeout(&msm_host->dma_comp,
  971. msecs_to_jiffies(200));
  972. DBG("ret=%d", ret);
  973. if (ret == 0)
  974. ret = -ETIMEDOUT;
  975. else
  976. ret = len;
  977. } else
  978. ret = len;
  979. return ret;
  980. }
  981. static int dsi_cmd_dma_rx(struct msm_dsi_host *msm_host,
  982. u8 *buf, int rx_byte, int pkt_size)
  983. {
  984. u32 *lp, *temp, data;
  985. int i, j = 0, cnt;
  986. u32 read_cnt;
  987. u8 reg[16];
  988. int repeated_bytes = 0;
  989. int buf_offset = buf - msm_host->rx_buf;
  990. lp = (u32 *)buf;
  991. temp = (u32 *)reg;
  992. cnt = (rx_byte + 3) >> 2;
  993. if (cnt > 4)
  994. cnt = 4; /* 4 x 32 bits registers only */
  995. if (rx_byte == 4)
  996. read_cnt = 4;
  997. else
  998. read_cnt = pkt_size + 6;
  999. /*
  1000. * In case of multiple reads from the panel, after the first read, there
  1001. * is possibility that there are some bytes in the payload repeating in
  1002. * the RDBK_DATA registers. Since we read all the parameters from the
  1003. * panel right from the first byte for every pass. We need to skip the
  1004. * repeating bytes and then append the new parameters to the rx buffer.
  1005. */
  1006. if (read_cnt > 16) {
  1007. int bytes_shifted;
  1008. /* Any data more than 16 bytes will be shifted out.
  1009. * The temp read buffer should already contain these bytes.
  1010. * The remaining bytes in read buffer are the repeated bytes.
  1011. */
  1012. bytes_shifted = read_cnt - 16;
  1013. repeated_bytes = buf_offset - bytes_shifted;
  1014. }
  1015. for (i = cnt - 1; i >= 0; i--) {
  1016. data = dsi_read(msm_host, REG_DSI_RDBK_DATA(i));
  1017. *temp++ = ntohl(data); /* to host byte order */
  1018. DBG("data = 0x%x and ntohl(data) = 0x%x", data, ntohl(data));
  1019. }
  1020. for (i = repeated_bytes; i < 16; i++)
  1021. buf[j++] = reg[i];
  1022. return j;
  1023. }
  1024. static int dsi_cmds2buf_tx(struct msm_dsi_host *msm_host,
  1025. const struct mipi_dsi_msg *msg)
  1026. {
  1027. int len, ret;
  1028. int bllp_len = msm_host->mode->hdisplay *
  1029. dsi_get_bpp(msm_host->format) / 8;
  1030. len = dsi_cmd_dma_add(msm_host, msg);
  1031. if (!len) {
  1032. pr_err("%s: failed to add cmd type = 0x%x\n",
  1033. __func__, msg->type);
  1034. return -EINVAL;
  1035. }
  1036. /* for video mode, do not send cmds more than
  1037. * one pixel line, since it only transmit it
  1038. * during BLLP.
  1039. */
  1040. /* TODO: if the command is sent in LP mode, the bit rate is only
  1041. * half of esc clk rate. In this case, if the video is already
  1042. * actively streaming, we need to check more carefully if the
  1043. * command can be fit into one BLLP.
  1044. */
  1045. if ((msm_host->mode_flags & MIPI_DSI_MODE_VIDEO) && (len > bllp_len)) {
  1046. pr_err("%s: cmd cannot fit into BLLP period, len=%d\n",
  1047. __func__, len);
  1048. return -EINVAL;
  1049. }
  1050. ret = dsi_cmd_dma_tx(msm_host, len);
  1051. if (ret < len) {
  1052. pr_err("%s: cmd dma tx failed, type=0x%x, data0=0x%x, len=%d\n",
  1053. __func__, msg->type, (*(u8 *)(msg->tx_buf)), len);
  1054. return -ECOMM;
  1055. }
  1056. return len;
  1057. }
  1058. static void dsi_sw_reset_restore(struct msm_dsi_host *msm_host)
  1059. {
  1060. u32 data0, data1;
  1061. data0 = dsi_read(msm_host, REG_DSI_CTRL);
  1062. data1 = data0;
  1063. data1 &= ~DSI_CTRL_ENABLE;
  1064. dsi_write(msm_host, REG_DSI_CTRL, data1);
  1065. /*
  1066. * dsi controller need to be disabled before
  1067. * clocks turned on
  1068. */
  1069. wmb();
  1070. dsi_write(msm_host, REG_DSI_CLK_CTRL, DSI_CLK_CTRL_ENABLE_CLKS);
  1071. wmb(); /* make sure clocks enabled */
  1072. /* dsi controller can only be reset while clocks are running */
  1073. dsi_write(msm_host, REG_DSI_RESET, 1);
  1074. wmb(); /* make sure reset happen */
  1075. dsi_write(msm_host, REG_DSI_RESET, 0);
  1076. wmb(); /* controller out of reset */
  1077. dsi_write(msm_host, REG_DSI_CTRL, data0);
  1078. wmb(); /* make sure dsi controller enabled again */
  1079. }
  1080. static void dsi_hpd_worker(struct work_struct *work)
  1081. {
  1082. struct msm_dsi_host *msm_host =
  1083. container_of(work, struct msm_dsi_host, hpd_work);
  1084. drm_helper_hpd_irq_event(msm_host->dev);
  1085. }
  1086. static void dsi_err_worker(struct work_struct *work)
  1087. {
  1088. struct msm_dsi_host *msm_host =
  1089. container_of(work, struct msm_dsi_host, err_work);
  1090. u32 status = msm_host->err_work_state;
  1091. pr_err_ratelimited("%s: status=%x\n", __func__, status);
  1092. if (status & DSI_ERR_STATE_MDP_FIFO_UNDERFLOW)
  1093. dsi_sw_reset_restore(msm_host);
  1094. /* It is safe to clear here because error irq is disabled. */
  1095. msm_host->err_work_state = 0;
  1096. /* enable dsi error interrupt */
  1097. dsi_intr_ctrl(msm_host, DSI_IRQ_MASK_ERROR, 1);
  1098. }
  1099. static void dsi_ack_err_status(struct msm_dsi_host *msm_host)
  1100. {
  1101. u32 status;
  1102. status = dsi_read(msm_host, REG_DSI_ACK_ERR_STATUS);
  1103. if (status) {
  1104. dsi_write(msm_host, REG_DSI_ACK_ERR_STATUS, status);
  1105. /* Writing of an extra 0 needed to clear error bits */
  1106. dsi_write(msm_host, REG_DSI_ACK_ERR_STATUS, 0);
  1107. msm_host->err_work_state |= DSI_ERR_STATE_ACK;
  1108. }
  1109. }
  1110. static void dsi_timeout_status(struct msm_dsi_host *msm_host)
  1111. {
  1112. u32 status;
  1113. status = dsi_read(msm_host, REG_DSI_TIMEOUT_STATUS);
  1114. if (status) {
  1115. dsi_write(msm_host, REG_DSI_TIMEOUT_STATUS, status);
  1116. msm_host->err_work_state |= DSI_ERR_STATE_TIMEOUT;
  1117. }
  1118. }
  1119. static void dsi_dln0_phy_err(struct msm_dsi_host *msm_host)
  1120. {
  1121. u32 status;
  1122. status = dsi_read(msm_host, REG_DSI_DLN0_PHY_ERR);
  1123. if (status & (DSI_DLN0_PHY_ERR_DLN0_ERR_ESC |
  1124. DSI_DLN0_PHY_ERR_DLN0_ERR_SYNC_ESC |
  1125. DSI_DLN0_PHY_ERR_DLN0_ERR_CONTROL |
  1126. DSI_DLN0_PHY_ERR_DLN0_ERR_CONTENTION_LP0 |
  1127. DSI_DLN0_PHY_ERR_DLN0_ERR_CONTENTION_LP1)) {
  1128. dsi_write(msm_host, REG_DSI_DLN0_PHY_ERR, status);
  1129. msm_host->err_work_state |= DSI_ERR_STATE_DLN0_PHY;
  1130. }
  1131. }
  1132. static void dsi_fifo_status(struct msm_dsi_host *msm_host)
  1133. {
  1134. u32 status;
  1135. status = dsi_read(msm_host, REG_DSI_FIFO_STATUS);
  1136. /* fifo underflow, overflow */
  1137. if (status) {
  1138. dsi_write(msm_host, REG_DSI_FIFO_STATUS, status);
  1139. msm_host->err_work_state |= DSI_ERR_STATE_FIFO;
  1140. if (status & DSI_FIFO_STATUS_CMD_MDP_FIFO_UNDERFLOW)
  1141. msm_host->err_work_state |=
  1142. DSI_ERR_STATE_MDP_FIFO_UNDERFLOW;
  1143. }
  1144. }
  1145. static void dsi_status(struct msm_dsi_host *msm_host)
  1146. {
  1147. u32 status;
  1148. status = dsi_read(msm_host, REG_DSI_STATUS0);
  1149. if (status & DSI_STATUS0_INTERLEAVE_OP_CONTENTION) {
  1150. dsi_write(msm_host, REG_DSI_STATUS0, status);
  1151. msm_host->err_work_state |=
  1152. DSI_ERR_STATE_INTERLEAVE_OP_CONTENTION;
  1153. }
  1154. }
  1155. static void dsi_clk_status(struct msm_dsi_host *msm_host)
  1156. {
  1157. u32 status;
  1158. status = dsi_read(msm_host, REG_DSI_CLK_STATUS);
  1159. if (status & DSI_CLK_STATUS_PLL_UNLOCKED) {
  1160. dsi_write(msm_host, REG_DSI_CLK_STATUS, status);
  1161. msm_host->err_work_state |= DSI_ERR_STATE_PLL_UNLOCKED;
  1162. }
  1163. }
  1164. static void dsi_error(struct msm_dsi_host *msm_host)
  1165. {
  1166. /* disable dsi error interrupt */
  1167. dsi_intr_ctrl(msm_host, DSI_IRQ_MASK_ERROR, 0);
  1168. dsi_clk_status(msm_host);
  1169. dsi_fifo_status(msm_host);
  1170. dsi_ack_err_status(msm_host);
  1171. dsi_timeout_status(msm_host);
  1172. dsi_status(msm_host);
  1173. dsi_dln0_phy_err(msm_host);
  1174. queue_work(msm_host->workqueue, &msm_host->err_work);
  1175. }
  1176. static irqreturn_t dsi_host_irq(int irq, void *ptr)
  1177. {
  1178. struct msm_dsi_host *msm_host = ptr;
  1179. u32 isr;
  1180. unsigned long flags;
  1181. if (!msm_host->ctrl_base)
  1182. return IRQ_HANDLED;
  1183. spin_lock_irqsave(&msm_host->intr_lock, flags);
  1184. isr = dsi_read(msm_host, REG_DSI_INTR_CTRL);
  1185. dsi_write(msm_host, REG_DSI_INTR_CTRL, isr);
  1186. spin_unlock_irqrestore(&msm_host->intr_lock, flags);
  1187. DBG("isr=0x%x, id=%d", isr, msm_host->id);
  1188. if (isr & DSI_IRQ_ERROR)
  1189. dsi_error(msm_host);
  1190. if (isr & DSI_IRQ_VIDEO_DONE)
  1191. complete(&msm_host->video_comp);
  1192. if (isr & DSI_IRQ_CMD_DMA_DONE)
  1193. complete(&msm_host->dma_comp);
  1194. return IRQ_HANDLED;
  1195. }
  1196. static int dsi_host_init_panel_gpios(struct msm_dsi_host *msm_host,
  1197. struct device *panel_device)
  1198. {
  1199. msm_host->disp_en_gpio = devm_gpiod_get_optional(panel_device,
  1200. "disp-enable",
  1201. GPIOD_OUT_LOW);
  1202. if (IS_ERR(msm_host->disp_en_gpio)) {
  1203. DBG("cannot get disp-enable-gpios %ld",
  1204. PTR_ERR(msm_host->disp_en_gpio));
  1205. return PTR_ERR(msm_host->disp_en_gpio);
  1206. }
  1207. msm_host->te_gpio = devm_gpiod_get_optional(panel_device, "disp-te",
  1208. GPIOD_IN);
  1209. if (IS_ERR(msm_host->te_gpio)) {
  1210. DBG("cannot get disp-te-gpios %ld", PTR_ERR(msm_host->te_gpio));
  1211. return PTR_ERR(msm_host->te_gpio);
  1212. }
  1213. return 0;
  1214. }
  1215. static int dsi_host_attach(struct mipi_dsi_host *host,
  1216. struct mipi_dsi_device *dsi)
  1217. {
  1218. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1219. int ret;
  1220. if (dsi->lanes > msm_host->num_data_lanes)
  1221. return -EINVAL;
  1222. msm_host->channel = dsi->channel;
  1223. msm_host->lanes = dsi->lanes;
  1224. msm_host->format = dsi->format;
  1225. msm_host->mode_flags = dsi->mode_flags;
  1226. msm_dsi_manager_attach_dsi_device(msm_host->id, dsi->mode_flags);
  1227. /* Some gpios defined in panel DT need to be controlled by host */
  1228. ret = dsi_host_init_panel_gpios(msm_host, &dsi->dev);
  1229. if (ret)
  1230. return ret;
  1231. DBG("id=%d", msm_host->id);
  1232. if (msm_host->dev)
  1233. queue_work(msm_host->workqueue, &msm_host->hpd_work);
  1234. return 0;
  1235. }
  1236. static int dsi_host_detach(struct mipi_dsi_host *host,
  1237. struct mipi_dsi_device *dsi)
  1238. {
  1239. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1240. msm_host->device_node = NULL;
  1241. DBG("id=%d", msm_host->id);
  1242. if (msm_host->dev)
  1243. queue_work(msm_host->workqueue, &msm_host->hpd_work);
  1244. return 0;
  1245. }
  1246. static ssize_t dsi_host_transfer(struct mipi_dsi_host *host,
  1247. const struct mipi_dsi_msg *msg)
  1248. {
  1249. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1250. int ret;
  1251. if (!msg || !msm_host->power_on)
  1252. return -EINVAL;
  1253. mutex_lock(&msm_host->cmd_mutex);
  1254. ret = msm_dsi_manager_cmd_xfer(msm_host->id, msg);
  1255. mutex_unlock(&msm_host->cmd_mutex);
  1256. return ret;
  1257. }
  1258. static struct mipi_dsi_host_ops dsi_host_ops = {
  1259. .attach = dsi_host_attach,
  1260. .detach = dsi_host_detach,
  1261. .transfer = dsi_host_transfer,
  1262. };
  1263. /*
  1264. * List of supported physical to logical lane mappings.
  1265. * For example, the 2nd entry represents the following mapping:
  1266. *
  1267. * "3012": Logic 3->Phys 0; Logic 0->Phys 1; Logic 1->Phys 2; Logic 2->Phys 3;
  1268. */
  1269. static const int supported_data_lane_swaps[][4] = {
  1270. { 0, 1, 2, 3 },
  1271. { 3, 0, 1, 2 },
  1272. { 2, 3, 0, 1 },
  1273. { 1, 2, 3, 0 },
  1274. { 0, 3, 2, 1 },
  1275. { 1, 0, 3, 2 },
  1276. { 2, 1, 0, 3 },
  1277. { 3, 2, 1, 0 },
  1278. };
  1279. static int dsi_host_parse_lane_data(struct msm_dsi_host *msm_host,
  1280. struct device_node *ep)
  1281. {
  1282. struct device *dev = &msm_host->pdev->dev;
  1283. struct property *prop;
  1284. u32 lane_map[4];
  1285. int ret, i, len, num_lanes;
  1286. prop = of_find_property(ep, "data-lanes", &len);
  1287. if (!prop) {
  1288. dev_dbg(dev,
  1289. "failed to find data lane mapping, using default\n");
  1290. return 0;
  1291. }
  1292. num_lanes = len / sizeof(u32);
  1293. if (num_lanes < 1 || num_lanes > 4) {
  1294. dev_err(dev, "bad number of data lanes\n");
  1295. return -EINVAL;
  1296. }
  1297. msm_host->num_data_lanes = num_lanes;
  1298. ret = of_property_read_u32_array(ep, "data-lanes", lane_map,
  1299. num_lanes);
  1300. if (ret) {
  1301. dev_err(dev, "failed to read lane data\n");
  1302. return ret;
  1303. }
  1304. /*
  1305. * compare DT specified physical-logical lane mappings with the ones
  1306. * supported by hardware
  1307. */
  1308. for (i = 0; i < ARRAY_SIZE(supported_data_lane_swaps); i++) {
  1309. const int *swap = supported_data_lane_swaps[i];
  1310. int j;
  1311. /*
  1312. * the data-lanes array we get from DT has a logical->physical
  1313. * mapping. The "data lane swap" register field represents
  1314. * supported configurations in a physical->logical mapping.
  1315. * Translate the DT mapping to what we understand and find a
  1316. * configuration that works.
  1317. */
  1318. for (j = 0; j < num_lanes; j++) {
  1319. if (lane_map[j] < 0 || lane_map[j] > 3)
  1320. dev_err(dev, "bad physical lane entry %u\n",
  1321. lane_map[j]);
  1322. if (swap[lane_map[j]] != j)
  1323. break;
  1324. }
  1325. if (j == num_lanes) {
  1326. msm_host->dlane_swap = i;
  1327. return 0;
  1328. }
  1329. }
  1330. return -EINVAL;
  1331. }
  1332. static int dsi_host_parse_dt(struct msm_dsi_host *msm_host)
  1333. {
  1334. struct device *dev = &msm_host->pdev->dev;
  1335. struct device_node *np = dev->of_node;
  1336. struct device_node *endpoint, *device_node;
  1337. int ret = 0;
  1338. /*
  1339. * Get the endpoint of the output port of the DSI host. In our case,
  1340. * this is mapped to port number with reg = 1. Don't return an error if
  1341. * the remote endpoint isn't defined. It's possible that there is
  1342. * nothing connected to the dsi output.
  1343. */
  1344. endpoint = of_graph_get_endpoint_by_regs(np, 1, -1);
  1345. if (!endpoint) {
  1346. dev_dbg(dev, "%s: no endpoint\n", __func__);
  1347. return 0;
  1348. }
  1349. ret = dsi_host_parse_lane_data(msm_host, endpoint);
  1350. if (ret) {
  1351. dev_err(dev, "%s: invalid lane configuration %d\n",
  1352. __func__, ret);
  1353. goto err;
  1354. }
  1355. /* Get panel node from the output port's endpoint data */
  1356. device_node = of_graph_get_remote_port_parent(endpoint);
  1357. if (!device_node) {
  1358. dev_dbg(dev, "%s: no valid device\n", __func__);
  1359. goto err;
  1360. }
  1361. msm_host->device_node = device_node;
  1362. if (of_property_read_bool(np, "syscon-sfpb")) {
  1363. msm_host->sfpb = syscon_regmap_lookup_by_phandle(np,
  1364. "syscon-sfpb");
  1365. if (IS_ERR(msm_host->sfpb)) {
  1366. dev_err(dev, "%s: failed to get sfpb regmap\n",
  1367. __func__);
  1368. ret = PTR_ERR(msm_host->sfpb);
  1369. }
  1370. }
  1371. of_node_put(device_node);
  1372. err:
  1373. of_node_put(endpoint);
  1374. return ret;
  1375. }
  1376. static int dsi_host_get_id(struct msm_dsi_host *msm_host)
  1377. {
  1378. struct platform_device *pdev = msm_host->pdev;
  1379. const struct msm_dsi_config *cfg = msm_host->cfg_hnd->cfg;
  1380. struct resource *res;
  1381. int i;
  1382. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dsi_ctrl");
  1383. if (!res)
  1384. return -EINVAL;
  1385. for (i = 0; i < cfg->num_dsi; i++) {
  1386. if (cfg->io_start[i] == res->start)
  1387. return i;
  1388. }
  1389. return -EINVAL;
  1390. }
  1391. int msm_dsi_host_init(struct msm_dsi *msm_dsi)
  1392. {
  1393. struct msm_dsi_host *msm_host = NULL;
  1394. struct platform_device *pdev = msm_dsi->pdev;
  1395. int ret;
  1396. msm_host = devm_kzalloc(&pdev->dev, sizeof(*msm_host), GFP_KERNEL);
  1397. if (!msm_host) {
  1398. pr_err("%s: FAILED: cannot alloc dsi host\n",
  1399. __func__);
  1400. ret = -ENOMEM;
  1401. goto fail;
  1402. }
  1403. msm_host->pdev = pdev;
  1404. ret = dsi_host_parse_dt(msm_host);
  1405. if (ret) {
  1406. pr_err("%s: failed to parse dt\n", __func__);
  1407. goto fail;
  1408. }
  1409. msm_host->ctrl_base = msm_ioremap(pdev, "dsi_ctrl", "DSI CTRL");
  1410. if (IS_ERR(msm_host->ctrl_base)) {
  1411. pr_err("%s: unable to map Dsi ctrl base\n", __func__);
  1412. ret = PTR_ERR(msm_host->ctrl_base);
  1413. goto fail;
  1414. }
  1415. msm_host->cfg_hnd = dsi_get_config(msm_host);
  1416. if (!msm_host->cfg_hnd) {
  1417. ret = -EINVAL;
  1418. pr_err("%s: get config failed\n", __func__);
  1419. goto fail;
  1420. }
  1421. msm_host->id = dsi_host_get_id(msm_host);
  1422. if (msm_host->id < 0) {
  1423. ret = msm_host->id;
  1424. pr_err("%s: unable to identify DSI host index\n", __func__);
  1425. goto fail;
  1426. }
  1427. /* fixup base address by io offset */
  1428. msm_host->ctrl_base += msm_host->cfg_hnd->cfg->io_offset;
  1429. ret = dsi_regulator_init(msm_host);
  1430. if (ret) {
  1431. pr_err("%s: regulator init failed\n", __func__);
  1432. goto fail;
  1433. }
  1434. ret = dsi_clk_init(msm_host);
  1435. if (ret) {
  1436. pr_err("%s: unable to initialize dsi clks\n", __func__);
  1437. goto fail;
  1438. }
  1439. msm_host->rx_buf = devm_kzalloc(&pdev->dev, SZ_4K, GFP_KERNEL);
  1440. if (!msm_host->rx_buf) {
  1441. pr_err("%s: alloc rx temp buf failed\n", __func__);
  1442. goto fail;
  1443. }
  1444. init_completion(&msm_host->dma_comp);
  1445. init_completion(&msm_host->video_comp);
  1446. mutex_init(&msm_host->dev_mutex);
  1447. mutex_init(&msm_host->cmd_mutex);
  1448. mutex_init(&msm_host->clk_mutex);
  1449. spin_lock_init(&msm_host->intr_lock);
  1450. /* setup workqueue */
  1451. msm_host->workqueue = alloc_ordered_workqueue("dsi_drm_work", 0);
  1452. INIT_WORK(&msm_host->err_work, dsi_err_worker);
  1453. INIT_WORK(&msm_host->hpd_work, dsi_hpd_worker);
  1454. msm_dsi->host = &msm_host->base;
  1455. msm_dsi->id = msm_host->id;
  1456. DBG("Dsi Host %d initialized", msm_host->id);
  1457. return 0;
  1458. fail:
  1459. return ret;
  1460. }
  1461. void msm_dsi_host_destroy(struct mipi_dsi_host *host)
  1462. {
  1463. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1464. DBG("");
  1465. dsi_tx_buf_free(msm_host);
  1466. if (msm_host->workqueue) {
  1467. flush_workqueue(msm_host->workqueue);
  1468. destroy_workqueue(msm_host->workqueue);
  1469. msm_host->workqueue = NULL;
  1470. }
  1471. mutex_destroy(&msm_host->clk_mutex);
  1472. mutex_destroy(&msm_host->cmd_mutex);
  1473. mutex_destroy(&msm_host->dev_mutex);
  1474. }
  1475. int msm_dsi_host_modeset_init(struct mipi_dsi_host *host,
  1476. struct drm_device *dev)
  1477. {
  1478. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1479. struct platform_device *pdev = msm_host->pdev;
  1480. int ret;
  1481. msm_host->irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
  1482. if (msm_host->irq < 0) {
  1483. ret = msm_host->irq;
  1484. dev_err(dev->dev, "failed to get irq: %d\n", ret);
  1485. return ret;
  1486. }
  1487. ret = devm_request_irq(&pdev->dev, msm_host->irq,
  1488. dsi_host_irq, IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
  1489. "dsi_isr", msm_host);
  1490. if (ret < 0) {
  1491. dev_err(&pdev->dev, "failed to request IRQ%u: %d\n",
  1492. msm_host->irq, ret);
  1493. return ret;
  1494. }
  1495. msm_host->dev = dev;
  1496. ret = dsi_tx_buf_alloc(msm_host, SZ_4K);
  1497. if (ret) {
  1498. pr_err("%s: alloc tx gem obj failed, %d\n", __func__, ret);
  1499. return ret;
  1500. }
  1501. return 0;
  1502. }
  1503. int msm_dsi_host_register(struct mipi_dsi_host *host, bool check_defer)
  1504. {
  1505. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1506. int ret;
  1507. /* Register mipi dsi host */
  1508. if (!msm_host->registered) {
  1509. host->dev = &msm_host->pdev->dev;
  1510. host->ops = &dsi_host_ops;
  1511. ret = mipi_dsi_host_register(host);
  1512. if (ret)
  1513. return ret;
  1514. msm_host->registered = true;
  1515. /* If the panel driver has not been probed after host register,
  1516. * we should defer the host's probe.
  1517. * It makes sure panel is connected when fbcon detects
  1518. * connector status and gets the proper display mode to
  1519. * create framebuffer.
  1520. * Don't try to defer if there is nothing connected to the dsi
  1521. * output
  1522. */
  1523. if (check_defer && msm_host->device_node) {
  1524. if (!of_drm_find_panel(msm_host->device_node))
  1525. if (!of_drm_find_bridge(msm_host->device_node))
  1526. return -EPROBE_DEFER;
  1527. }
  1528. }
  1529. return 0;
  1530. }
  1531. void msm_dsi_host_unregister(struct mipi_dsi_host *host)
  1532. {
  1533. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1534. if (msm_host->registered) {
  1535. mipi_dsi_host_unregister(host);
  1536. host->dev = NULL;
  1537. host->ops = NULL;
  1538. msm_host->registered = false;
  1539. }
  1540. }
  1541. int msm_dsi_host_xfer_prepare(struct mipi_dsi_host *host,
  1542. const struct mipi_dsi_msg *msg)
  1543. {
  1544. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1545. /* TODO: make sure dsi_cmd_mdp is idle.
  1546. * Since DSI6G v1.2.0, we can set DSI_TRIG_CTRL.BLOCK_DMA_WITHIN_FRAME
  1547. * to ask H/W to wait until cmd mdp is idle. S/W wait is not needed.
  1548. * How to handle the old versions? Wait for mdp cmd done?
  1549. */
  1550. /*
  1551. * mdss interrupt is generated in mdp core clock domain
  1552. * mdp clock need to be enabled to receive dsi interrupt
  1553. */
  1554. dsi_clk_ctrl(msm_host, 1);
  1555. /* TODO: vote for bus bandwidth */
  1556. if (!(msg->flags & MIPI_DSI_MSG_USE_LPM))
  1557. dsi_set_tx_power_mode(0, msm_host);
  1558. msm_host->dma_cmd_ctrl_restore = dsi_read(msm_host, REG_DSI_CTRL);
  1559. dsi_write(msm_host, REG_DSI_CTRL,
  1560. msm_host->dma_cmd_ctrl_restore |
  1561. DSI_CTRL_CMD_MODE_EN |
  1562. DSI_CTRL_ENABLE);
  1563. dsi_intr_ctrl(msm_host, DSI_IRQ_MASK_CMD_DMA_DONE, 1);
  1564. return 0;
  1565. }
  1566. void msm_dsi_host_xfer_restore(struct mipi_dsi_host *host,
  1567. const struct mipi_dsi_msg *msg)
  1568. {
  1569. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1570. dsi_intr_ctrl(msm_host, DSI_IRQ_MASK_CMD_DMA_DONE, 0);
  1571. dsi_write(msm_host, REG_DSI_CTRL, msm_host->dma_cmd_ctrl_restore);
  1572. if (!(msg->flags & MIPI_DSI_MSG_USE_LPM))
  1573. dsi_set_tx_power_mode(1, msm_host);
  1574. /* TODO: unvote for bus bandwidth */
  1575. dsi_clk_ctrl(msm_host, 0);
  1576. }
  1577. int msm_dsi_host_cmd_tx(struct mipi_dsi_host *host,
  1578. const struct mipi_dsi_msg *msg)
  1579. {
  1580. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1581. return dsi_cmds2buf_tx(msm_host, msg);
  1582. }
  1583. int msm_dsi_host_cmd_rx(struct mipi_dsi_host *host,
  1584. const struct mipi_dsi_msg *msg)
  1585. {
  1586. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1587. const struct msm_dsi_cfg_handler *cfg_hnd = msm_host->cfg_hnd;
  1588. int data_byte, rx_byte, dlen, end;
  1589. int short_response, diff, pkt_size, ret = 0;
  1590. char cmd;
  1591. int rlen = msg->rx_len;
  1592. u8 *buf;
  1593. if (rlen <= 2) {
  1594. short_response = 1;
  1595. pkt_size = rlen;
  1596. rx_byte = 4;
  1597. } else {
  1598. short_response = 0;
  1599. data_byte = 10; /* first read */
  1600. if (rlen < data_byte)
  1601. pkt_size = rlen;
  1602. else
  1603. pkt_size = data_byte;
  1604. rx_byte = data_byte + 6; /* 4 header + 2 crc */
  1605. }
  1606. buf = msm_host->rx_buf;
  1607. end = 0;
  1608. while (!end) {
  1609. u8 tx[2] = {pkt_size & 0xff, pkt_size >> 8};
  1610. struct mipi_dsi_msg max_pkt_size_msg = {
  1611. .channel = msg->channel,
  1612. .type = MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE,
  1613. .tx_len = 2,
  1614. .tx_buf = tx,
  1615. };
  1616. DBG("rlen=%d pkt_size=%d rx_byte=%d",
  1617. rlen, pkt_size, rx_byte);
  1618. ret = dsi_cmds2buf_tx(msm_host, &max_pkt_size_msg);
  1619. if (ret < 2) {
  1620. pr_err("%s: Set max pkt size failed, %d\n",
  1621. __func__, ret);
  1622. return -EINVAL;
  1623. }
  1624. if ((cfg_hnd->major == MSM_DSI_VER_MAJOR_6G) &&
  1625. (cfg_hnd->minor >= MSM_DSI_6G_VER_MINOR_V1_1)) {
  1626. /* Clear the RDBK_DATA registers */
  1627. dsi_write(msm_host, REG_DSI_RDBK_DATA_CTRL,
  1628. DSI_RDBK_DATA_CTRL_CLR);
  1629. wmb(); /* make sure the RDBK registers are cleared */
  1630. dsi_write(msm_host, REG_DSI_RDBK_DATA_CTRL, 0);
  1631. wmb(); /* release cleared status before transfer */
  1632. }
  1633. ret = dsi_cmds2buf_tx(msm_host, msg);
  1634. if (ret < msg->tx_len) {
  1635. pr_err("%s: Read cmd Tx failed, %d\n", __func__, ret);
  1636. return ret;
  1637. }
  1638. /*
  1639. * once cmd_dma_done interrupt received,
  1640. * return data from client is ready and stored
  1641. * at RDBK_DATA register already
  1642. * since rx fifo is 16 bytes, dcs header is kept at first loop,
  1643. * after that dcs header lost during shift into registers
  1644. */
  1645. dlen = dsi_cmd_dma_rx(msm_host, buf, rx_byte, pkt_size);
  1646. if (dlen <= 0)
  1647. return 0;
  1648. if (short_response)
  1649. break;
  1650. if (rlen <= data_byte) {
  1651. diff = data_byte - rlen;
  1652. end = 1;
  1653. } else {
  1654. diff = 0;
  1655. rlen -= data_byte;
  1656. }
  1657. if (!end) {
  1658. dlen -= 2; /* 2 crc */
  1659. dlen -= diff;
  1660. buf += dlen; /* next start position */
  1661. data_byte = 14; /* NOT first read */
  1662. if (rlen < data_byte)
  1663. pkt_size += rlen;
  1664. else
  1665. pkt_size += data_byte;
  1666. DBG("buf=%p dlen=%d diff=%d", buf, dlen, diff);
  1667. }
  1668. }
  1669. /*
  1670. * For single Long read, if the requested rlen < 10,
  1671. * we need to shift the start position of rx
  1672. * data buffer to skip the bytes which are not
  1673. * updated.
  1674. */
  1675. if (pkt_size < 10 && !short_response)
  1676. buf = msm_host->rx_buf + (10 - rlen);
  1677. else
  1678. buf = msm_host->rx_buf;
  1679. cmd = buf[0];
  1680. switch (cmd) {
  1681. case MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT:
  1682. pr_err("%s: rx ACK_ERR_PACLAGE\n", __func__);
  1683. ret = 0;
  1684. break;
  1685. case MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_1BYTE:
  1686. case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE:
  1687. ret = dsi_short_read1_resp(buf, msg);
  1688. break;
  1689. case MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_2BYTE:
  1690. case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE:
  1691. ret = dsi_short_read2_resp(buf, msg);
  1692. break;
  1693. case MIPI_DSI_RX_GENERIC_LONG_READ_RESPONSE:
  1694. case MIPI_DSI_RX_DCS_LONG_READ_RESPONSE:
  1695. ret = dsi_long_read_resp(buf, msg);
  1696. break;
  1697. default:
  1698. pr_warn("%s:Invalid response cmd\n", __func__);
  1699. ret = 0;
  1700. }
  1701. return ret;
  1702. }
  1703. void msm_dsi_host_cmd_xfer_commit(struct mipi_dsi_host *host, u32 dma_base,
  1704. u32 len)
  1705. {
  1706. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1707. dsi_write(msm_host, REG_DSI_DMA_BASE, dma_base);
  1708. dsi_write(msm_host, REG_DSI_DMA_LEN, len);
  1709. dsi_write(msm_host, REG_DSI_TRIG_DMA, 1);
  1710. /* Make sure trigger happens */
  1711. wmb();
  1712. }
  1713. int msm_dsi_host_set_src_pll(struct mipi_dsi_host *host,
  1714. struct msm_dsi_pll *src_pll)
  1715. {
  1716. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1717. const struct msm_dsi_cfg_handler *cfg_hnd = msm_host->cfg_hnd;
  1718. struct clk *byte_clk_provider, *pixel_clk_provider;
  1719. int ret;
  1720. ret = msm_dsi_pll_get_clk_provider(src_pll,
  1721. &byte_clk_provider, &pixel_clk_provider);
  1722. if (ret) {
  1723. pr_info("%s: can't get provider from pll, don't set parent\n",
  1724. __func__);
  1725. return 0;
  1726. }
  1727. ret = clk_set_parent(msm_host->byte_clk_src, byte_clk_provider);
  1728. if (ret) {
  1729. pr_err("%s: can't set parent to byte_clk_src. ret=%d\n",
  1730. __func__, ret);
  1731. goto exit;
  1732. }
  1733. ret = clk_set_parent(msm_host->pixel_clk_src, pixel_clk_provider);
  1734. if (ret) {
  1735. pr_err("%s: can't set parent to pixel_clk_src. ret=%d\n",
  1736. __func__, ret);
  1737. goto exit;
  1738. }
  1739. if (cfg_hnd->major == MSM_DSI_VER_MAJOR_V2) {
  1740. ret = clk_set_parent(msm_host->dsi_clk_src, pixel_clk_provider);
  1741. if (ret) {
  1742. pr_err("%s: can't set parent to dsi_clk_src. ret=%d\n",
  1743. __func__, ret);
  1744. goto exit;
  1745. }
  1746. ret = clk_set_parent(msm_host->esc_clk_src, byte_clk_provider);
  1747. if (ret) {
  1748. pr_err("%s: can't set parent to esc_clk_src. ret=%d\n",
  1749. __func__, ret);
  1750. goto exit;
  1751. }
  1752. }
  1753. exit:
  1754. return ret;
  1755. }
  1756. void msm_dsi_host_reset_phy(struct mipi_dsi_host *host)
  1757. {
  1758. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1759. DBG("");
  1760. dsi_write(msm_host, REG_DSI_PHY_RESET, DSI_PHY_RESET_RESET);
  1761. /* Make sure fully reset */
  1762. wmb();
  1763. udelay(1000);
  1764. dsi_write(msm_host, REG_DSI_PHY_RESET, 0);
  1765. udelay(100);
  1766. }
  1767. void msm_dsi_host_get_phy_clk_req(struct mipi_dsi_host *host,
  1768. struct msm_dsi_phy_clk_request *clk_req)
  1769. {
  1770. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1771. clk_req->bitclk_rate = msm_host->byte_clk_rate * 8;
  1772. clk_req->escclk_rate = msm_host->esc_clk_rate;
  1773. }
  1774. int msm_dsi_host_enable(struct mipi_dsi_host *host)
  1775. {
  1776. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1777. dsi_op_mode_config(msm_host,
  1778. !!(msm_host->mode_flags & MIPI_DSI_MODE_VIDEO), true);
  1779. /* TODO: clock should be turned off for command mode,
  1780. * and only turned on before MDP START.
  1781. * This part of code should be enabled once mdp driver support it.
  1782. */
  1783. /* if (msm_panel->mode == MSM_DSI_CMD_MODE)
  1784. dsi_clk_ctrl(msm_host, 0); */
  1785. return 0;
  1786. }
  1787. int msm_dsi_host_disable(struct mipi_dsi_host *host)
  1788. {
  1789. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1790. dsi_op_mode_config(msm_host,
  1791. !!(msm_host->mode_flags & MIPI_DSI_MODE_VIDEO), false);
  1792. /* Since we have disabled INTF, the video engine won't stop so that
  1793. * the cmd engine will be blocked.
  1794. * Reset to disable video engine so that we can send off cmd.
  1795. */
  1796. dsi_sw_reset(msm_host);
  1797. return 0;
  1798. }
  1799. static void msm_dsi_sfpb_config(struct msm_dsi_host *msm_host, bool enable)
  1800. {
  1801. enum sfpb_ahb_arb_master_port_en en;
  1802. if (!msm_host->sfpb)
  1803. return;
  1804. en = enable ? SFPB_MASTER_PORT_ENABLE : SFPB_MASTER_PORT_DISABLE;
  1805. regmap_update_bits(msm_host->sfpb, REG_SFPB_GPREG,
  1806. SFPB_GPREG_MASTER_PORT_EN__MASK,
  1807. SFPB_GPREG_MASTER_PORT_EN(en));
  1808. }
  1809. int msm_dsi_host_power_on(struct mipi_dsi_host *host,
  1810. struct msm_dsi_phy_shared_timings *phy_shared_timings)
  1811. {
  1812. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1813. int ret = 0;
  1814. mutex_lock(&msm_host->dev_mutex);
  1815. if (msm_host->power_on) {
  1816. DBG("dsi host already on");
  1817. goto unlock_ret;
  1818. }
  1819. msm_dsi_sfpb_config(msm_host, true);
  1820. ret = dsi_host_regulator_enable(msm_host);
  1821. if (ret) {
  1822. pr_err("%s:Failed to enable vregs.ret=%d\n",
  1823. __func__, ret);
  1824. goto unlock_ret;
  1825. }
  1826. ret = dsi_clk_ctrl(msm_host, 1);
  1827. if (ret) {
  1828. pr_err("%s: failed to enable clocks. ret=%d\n", __func__, ret);
  1829. goto fail_disable_reg;
  1830. }
  1831. ret = pinctrl_pm_select_default_state(&msm_host->pdev->dev);
  1832. if (ret) {
  1833. pr_err("%s: failed to set pinctrl default state, %d\n",
  1834. __func__, ret);
  1835. goto fail_disable_clk;
  1836. }
  1837. dsi_timing_setup(msm_host);
  1838. dsi_sw_reset(msm_host);
  1839. dsi_ctrl_config(msm_host, true, phy_shared_timings);
  1840. if (msm_host->disp_en_gpio)
  1841. gpiod_set_value(msm_host->disp_en_gpio, 1);
  1842. msm_host->power_on = true;
  1843. mutex_unlock(&msm_host->dev_mutex);
  1844. return 0;
  1845. fail_disable_clk:
  1846. dsi_clk_ctrl(msm_host, 0);
  1847. fail_disable_reg:
  1848. dsi_host_regulator_disable(msm_host);
  1849. unlock_ret:
  1850. mutex_unlock(&msm_host->dev_mutex);
  1851. return ret;
  1852. }
  1853. int msm_dsi_host_power_off(struct mipi_dsi_host *host)
  1854. {
  1855. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1856. mutex_lock(&msm_host->dev_mutex);
  1857. if (!msm_host->power_on) {
  1858. DBG("dsi host already off");
  1859. goto unlock_ret;
  1860. }
  1861. dsi_ctrl_config(msm_host, false, NULL);
  1862. if (msm_host->disp_en_gpio)
  1863. gpiod_set_value(msm_host->disp_en_gpio, 0);
  1864. pinctrl_pm_select_sleep_state(&msm_host->pdev->dev);
  1865. dsi_clk_ctrl(msm_host, 0);
  1866. dsi_host_regulator_disable(msm_host);
  1867. msm_dsi_sfpb_config(msm_host, false);
  1868. DBG("-");
  1869. msm_host->power_on = false;
  1870. unlock_ret:
  1871. mutex_unlock(&msm_host->dev_mutex);
  1872. return 0;
  1873. }
  1874. int msm_dsi_host_set_display_mode(struct mipi_dsi_host *host,
  1875. struct drm_display_mode *mode)
  1876. {
  1877. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1878. int ret;
  1879. if (msm_host->mode) {
  1880. drm_mode_destroy(msm_host->dev, msm_host->mode);
  1881. msm_host->mode = NULL;
  1882. }
  1883. msm_host->mode = drm_mode_duplicate(msm_host->dev, mode);
  1884. if (!msm_host->mode) {
  1885. pr_err("%s: cannot duplicate mode\n", __func__);
  1886. return -ENOMEM;
  1887. }
  1888. ret = dsi_calc_clk_rate(msm_host);
  1889. if (ret) {
  1890. pr_err("%s: unable to calc clk rate, %d\n", __func__, ret);
  1891. return ret;
  1892. }
  1893. return 0;
  1894. }
  1895. struct drm_panel *msm_dsi_host_get_panel(struct mipi_dsi_host *host,
  1896. unsigned long *panel_flags)
  1897. {
  1898. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1899. struct drm_panel *panel;
  1900. panel = of_drm_find_panel(msm_host->device_node);
  1901. if (panel_flags)
  1902. *panel_flags = msm_host->mode_flags;
  1903. return panel;
  1904. }
  1905. struct drm_bridge *msm_dsi_host_get_bridge(struct mipi_dsi_host *host)
  1906. {
  1907. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1908. return of_drm_find_bridge(msm_host->device_node);
  1909. }