dsi_host.c 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335
  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. #include "msm_kms.h"
  34. static int dsi_get_version(const void __iomem *base, u32 *major, u32 *minor)
  35. {
  36. u32 ver;
  37. if (!major || !minor)
  38. return -EINVAL;
  39. /*
  40. * From DSI6G(v3), addition of a 6G_HW_VERSION register at offset 0
  41. * makes all other registers 4-byte shifted down.
  42. *
  43. * In order to identify between DSI6G(v3) and beyond, and DSIv2 and
  44. * older, we read the DSI_VERSION register without any shift(offset
  45. * 0x1f0). In the case of DSIv2, this hast to be a non-zero value. In
  46. * the case of DSI6G, this has to be zero (the offset points to a
  47. * scratch register which we never touch)
  48. */
  49. ver = msm_readl(base + REG_DSI_VERSION);
  50. if (ver) {
  51. /* older dsi host, there is no register shift */
  52. ver = FIELD(ver, DSI_VERSION_MAJOR);
  53. if (ver <= MSM_DSI_VER_MAJOR_V2) {
  54. /* old versions */
  55. *major = ver;
  56. *minor = 0;
  57. return 0;
  58. } else {
  59. return -EINVAL;
  60. }
  61. } else {
  62. /*
  63. * newer host, offset 0 has 6G_HW_VERSION, the rest of the
  64. * registers are shifted down, read DSI_VERSION again with
  65. * the shifted offset
  66. */
  67. ver = msm_readl(base + DSI_6G_REG_SHIFT + REG_DSI_VERSION);
  68. ver = FIELD(ver, DSI_VERSION_MAJOR);
  69. if (ver == MSM_DSI_VER_MAJOR_6G) {
  70. /* 6G version */
  71. *major = ver;
  72. *minor = msm_readl(base + REG_DSI_6G_HW_VERSION);
  73. return 0;
  74. } else {
  75. return -EINVAL;
  76. }
  77. }
  78. }
  79. #define DSI_ERR_STATE_ACK 0x0000
  80. #define DSI_ERR_STATE_TIMEOUT 0x0001
  81. #define DSI_ERR_STATE_DLN0_PHY 0x0002
  82. #define DSI_ERR_STATE_FIFO 0x0004
  83. #define DSI_ERR_STATE_MDP_FIFO_UNDERFLOW 0x0008
  84. #define DSI_ERR_STATE_INTERLEAVE_OP_CONTENTION 0x0010
  85. #define DSI_ERR_STATE_PLL_UNLOCKED 0x0020
  86. #define DSI_CLK_CTRL_ENABLE_CLKS \
  87. (DSI_CLK_CTRL_AHBS_HCLK_ON | DSI_CLK_CTRL_AHBM_SCLK_ON | \
  88. DSI_CLK_CTRL_PCLK_ON | DSI_CLK_CTRL_DSICLK_ON | \
  89. DSI_CLK_CTRL_BYTECLK_ON | DSI_CLK_CTRL_ESCCLK_ON | \
  90. DSI_CLK_CTRL_FORCE_ON_DYN_AHBM_HCLK)
  91. struct msm_dsi_host {
  92. struct mipi_dsi_host base;
  93. struct platform_device *pdev;
  94. struct drm_device *dev;
  95. int id;
  96. void __iomem *ctrl_base;
  97. struct regulator_bulk_data supplies[DSI_DEV_REGULATOR_MAX];
  98. struct clk *bus_clks[DSI_BUS_CLK_MAX];
  99. struct clk *byte_clk;
  100. struct clk *esc_clk;
  101. struct clk *pixel_clk;
  102. struct clk *byte_clk_src;
  103. struct clk *pixel_clk_src;
  104. u32 byte_clk_rate;
  105. u32 esc_clk_rate;
  106. /* DSI v2 specific clocks */
  107. struct clk *src_clk;
  108. struct clk *esc_clk_src;
  109. struct clk *dsi_clk_src;
  110. u32 src_clk_rate;
  111. struct gpio_desc *disp_en_gpio;
  112. struct gpio_desc *te_gpio;
  113. const struct msm_dsi_cfg_handler *cfg_hnd;
  114. struct completion dma_comp;
  115. struct completion video_comp;
  116. struct mutex dev_mutex;
  117. struct mutex cmd_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. pm_runtime_get_sync(dev);
  186. ret = regulator_enable(gdsc_reg);
  187. if (ret) {
  188. pr_err("%s: unable to enable gdsc\n", __func__);
  189. goto put_clk;
  190. }
  191. ret = clk_prepare_enable(ahb_clk);
  192. if (ret) {
  193. pr_err("%s: unable to enable ahb_clk\n", __func__);
  194. goto disable_gdsc;
  195. }
  196. ret = dsi_get_version(msm_host->ctrl_base, &major, &minor);
  197. if (ret) {
  198. pr_err("%s: Invalid version\n", __func__);
  199. goto disable_clks;
  200. }
  201. cfg_hnd = msm_dsi_cfg_get(major, minor);
  202. DBG("%s: Version %x:%x\n", __func__, major, minor);
  203. disable_clks:
  204. clk_disable_unprepare(ahb_clk);
  205. disable_gdsc:
  206. regulator_disable(gdsc_reg);
  207. pm_runtime_put_sync(dev);
  208. put_clk:
  209. clk_put(ahb_clk);
  210. put_gdsc:
  211. regulator_put(gdsc_reg);
  212. exit:
  213. return cfg_hnd;
  214. }
  215. static inline struct msm_dsi_host *to_msm_dsi_host(struct mipi_dsi_host *host)
  216. {
  217. return container_of(host, struct msm_dsi_host, base);
  218. }
  219. static void dsi_host_regulator_disable(struct msm_dsi_host *msm_host)
  220. {
  221. struct regulator_bulk_data *s = msm_host->supplies;
  222. const struct dsi_reg_entry *regs = msm_host->cfg_hnd->cfg->reg_cfg.regs;
  223. int num = msm_host->cfg_hnd->cfg->reg_cfg.num;
  224. int i;
  225. DBG("");
  226. for (i = num - 1; i >= 0; i--)
  227. if (regs[i].disable_load >= 0)
  228. regulator_set_load(s[i].consumer,
  229. regs[i].disable_load);
  230. regulator_bulk_disable(num, s);
  231. }
  232. static int dsi_host_regulator_enable(struct msm_dsi_host *msm_host)
  233. {
  234. struct regulator_bulk_data *s = msm_host->supplies;
  235. const struct dsi_reg_entry *regs = msm_host->cfg_hnd->cfg->reg_cfg.regs;
  236. int num = msm_host->cfg_hnd->cfg->reg_cfg.num;
  237. int ret, i;
  238. DBG("");
  239. for (i = 0; i < num; i++) {
  240. if (regs[i].enable_load >= 0) {
  241. ret = regulator_set_load(s[i].consumer,
  242. regs[i].enable_load);
  243. if (ret < 0) {
  244. pr_err("regulator %d set op mode failed, %d\n",
  245. i, ret);
  246. goto fail;
  247. }
  248. }
  249. }
  250. ret = regulator_bulk_enable(num, s);
  251. if (ret < 0) {
  252. pr_err("regulator enable failed, %d\n", ret);
  253. goto fail;
  254. }
  255. return 0;
  256. fail:
  257. for (i--; i >= 0; i--)
  258. regulator_set_load(s[i].consumer, regs[i].disable_load);
  259. return ret;
  260. }
  261. static int dsi_regulator_init(struct msm_dsi_host *msm_host)
  262. {
  263. struct regulator_bulk_data *s = msm_host->supplies;
  264. const struct dsi_reg_entry *regs = msm_host->cfg_hnd->cfg->reg_cfg.regs;
  265. int num = msm_host->cfg_hnd->cfg->reg_cfg.num;
  266. int i, ret;
  267. for (i = 0; i < num; i++)
  268. s[i].supply = regs[i].name;
  269. ret = devm_regulator_bulk_get(&msm_host->pdev->dev, num, s);
  270. if (ret < 0) {
  271. pr_err("%s: failed to init regulator, ret=%d\n",
  272. __func__, ret);
  273. return ret;
  274. }
  275. return 0;
  276. }
  277. static int dsi_clk_init(struct msm_dsi_host *msm_host)
  278. {
  279. struct platform_device *pdev = msm_host->pdev;
  280. const struct msm_dsi_cfg_handler *cfg_hnd = msm_host->cfg_hnd;
  281. const struct msm_dsi_config *cfg = cfg_hnd->cfg;
  282. int i, ret = 0;
  283. /* get bus clocks */
  284. for (i = 0; i < cfg->num_bus_clks; i++) {
  285. msm_host->bus_clks[i] = msm_clk_get(pdev,
  286. cfg->bus_clk_names[i]);
  287. if (IS_ERR(msm_host->bus_clks[i])) {
  288. ret = PTR_ERR(msm_host->bus_clks[i]);
  289. pr_err("%s: Unable to get %s clock, ret = %d\n",
  290. __func__, cfg->bus_clk_names[i], ret);
  291. goto exit;
  292. }
  293. }
  294. /* get link and source clocks */
  295. msm_host->byte_clk = msm_clk_get(pdev, "byte");
  296. if (IS_ERR(msm_host->byte_clk)) {
  297. ret = PTR_ERR(msm_host->byte_clk);
  298. pr_err("%s: can't find dsi_byte clock. ret=%d\n",
  299. __func__, ret);
  300. msm_host->byte_clk = NULL;
  301. goto exit;
  302. }
  303. msm_host->pixel_clk = msm_clk_get(pdev, "pixel");
  304. if (IS_ERR(msm_host->pixel_clk)) {
  305. ret = PTR_ERR(msm_host->pixel_clk);
  306. pr_err("%s: can't find dsi_pixel clock. ret=%d\n",
  307. __func__, ret);
  308. msm_host->pixel_clk = NULL;
  309. goto exit;
  310. }
  311. msm_host->esc_clk = msm_clk_get(pdev, "core");
  312. if (IS_ERR(msm_host->esc_clk)) {
  313. ret = PTR_ERR(msm_host->esc_clk);
  314. pr_err("%s: can't find dsi_esc clock. ret=%d\n",
  315. __func__, ret);
  316. msm_host->esc_clk = NULL;
  317. goto exit;
  318. }
  319. msm_host->byte_clk_src = clk_get_parent(msm_host->byte_clk);
  320. if (!msm_host->byte_clk_src) {
  321. ret = -ENODEV;
  322. pr_err("%s: can't find byte_clk clock. ret=%d\n", __func__, ret);
  323. goto exit;
  324. }
  325. msm_host->pixel_clk_src = clk_get_parent(msm_host->pixel_clk);
  326. if (!msm_host->pixel_clk_src) {
  327. ret = -ENODEV;
  328. pr_err("%s: can't find pixel_clk clock. ret=%d\n", __func__, ret);
  329. goto exit;
  330. }
  331. if (cfg_hnd->major == MSM_DSI_VER_MAJOR_V2) {
  332. msm_host->src_clk = msm_clk_get(pdev, "src");
  333. if (IS_ERR(msm_host->src_clk)) {
  334. ret = PTR_ERR(msm_host->src_clk);
  335. pr_err("%s: can't find src clock. ret=%d\n",
  336. __func__, ret);
  337. msm_host->src_clk = NULL;
  338. goto exit;
  339. }
  340. msm_host->esc_clk_src = clk_get_parent(msm_host->esc_clk);
  341. if (!msm_host->esc_clk_src) {
  342. ret = -ENODEV;
  343. pr_err("%s: can't get esc clock parent. ret=%d\n",
  344. __func__, ret);
  345. goto exit;
  346. }
  347. msm_host->dsi_clk_src = clk_get_parent(msm_host->src_clk);
  348. if (!msm_host->dsi_clk_src) {
  349. ret = -ENODEV;
  350. pr_err("%s: can't get src clock parent. ret=%d\n",
  351. __func__, ret);
  352. }
  353. }
  354. exit:
  355. return ret;
  356. }
  357. static int dsi_bus_clk_enable(struct msm_dsi_host *msm_host)
  358. {
  359. const struct msm_dsi_config *cfg = msm_host->cfg_hnd->cfg;
  360. int i, ret;
  361. DBG("id=%d", msm_host->id);
  362. for (i = 0; i < cfg->num_bus_clks; i++) {
  363. ret = clk_prepare_enable(msm_host->bus_clks[i]);
  364. if (ret) {
  365. pr_err("%s: failed to enable bus clock %d ret %d\n",
  366. __func__, i, ret);
  367. goto err;
  368. }
  369. }
  370. return 0;
  371. err:
  372. for (; i > 0; i--)
  373. clk_disable_unprepare(msm_host->bus_clks[i]);
  374. return ret;
  375. }
  376. static void dsi_bus_clk_disable(struct msm_dsi_host *msm_host)
  377. {
  378. const struct msm_dsi_config *cfg = msm_host->cfg_hnd->cfg;
  379. int i;
  380. DBG("");
  381. for (i = cfg->num_bus_clks - 1; i >= 0; i--)
  382. clk_disable_unprepare(msm_host->bus_clks[i]);
  383. }
  384. int msm_dsi_runtime_suspend(struct device *dev)
  385. {
  386. struct platform_device *pdev = to_platform_device(dev);
  387. struct msm_dsi *msm_dsi = platform_get_drvdata(pdev);
  388. struct mipi_dsi_host *host = msm_dsi->host;
  389. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  390. if (!msm_host->cfg_hnd)
  391. return 0;
  392. dsi_bus_clk_disable(msm_host);
  393. return 0;
  394. }
  395. int msm_dsi_runtime_resume(struct device *dev)
  396. {
  397. struct platform_device *pdev = to_platform_device(dev);
  398. struct msm_dsi *msm_dsi = platform_get_drvdata(pdev);
  399. struct mipi_dsi_host *host = msm_dsi->host;
  400. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  401. if (!msm_host->cfg_hnd)
  402. return 0;
  403. return dsi_bus_clk_enable(msm_host);
  404. }
  405. static int dsi_link_clk_enable_6g(struct msm_dsi_host *msm_host)
  406. {
  407. int ret;
  408. DBG("Set clk rates: pclk=%d, byteclk=%d",
  409. msm_host->mode->clock, msm_host->byte_clk_rate);
  410. ret = clk_set_rate(msm_host->byte_clk, msm_host->byte_clk_rate);
  411. if (ret) {
  412. pr_err("%s: Failed to set rate byte clk, %d\n", __func__, ret);
  413. goto error;
  414. }
  415. ret = clk_set_rate(msm_host->pixel_clk, msm_host->mode->clock * 1000);
  416. if (ret) {
  417. pr_err("%s: Failed to set rate pixel clk, %d\n", __func__, ret);
  418. goto error;
  419. }
  420. ret = clk_prepare_enable(msm_host->esc_clk);
  421. if (ret) {
  422. pr_err("%s: Failed to enable dsi esc clk\n", __func__);
  423. goto error;
  424. }
  425. ret = clk_prepare_enable(msm_host->byte_clk);
  426. if (ret) {
  427. pr_err("%s: Failed to enable dsi byte clk\n", __func__);
  428. goto byte_clk_err;
  429. }
  430. ret = clk_prepare_enable(msm_host->pixel_clk);
  431. if (ret) {
  432. pr_err("%s: Failed to enable dsi pixel clk\n", __func__);
  433. goto pixel_clk_err;
  434. }
  435. return 0;
  436. pixel_clk_err:
  437. clk_disable_unprepare(msm_host->byte_clk);
  438. byte_clk_err:
  439. clk_disable_unprepare(msm_host->esc_clk);
  440. error:
  441. return ret;
  442. }
  443. static int dsi_link_clk_enable_v2(struct msm_dsi_host *msm_host)
  444. {
  445. int ret;
  446. DBG("Set clk rates: pclk=%d, byteclk=%d, esc_clk=%d, dsi_src_clk=%d",
  447. msm_host->mode->clock, msm_host->byte_clk_rate,
  448. msm_host->esc_clk_rate, msm_host->src_clk_rate);
  449. ret = clk_set_rate(msm_host->byte_clk, msm_host->byte_clk_rate);
  450. if (ret) {
  451. pr_err("%s: Failed to set rate byte clk, %d\n", __func__, ret);
  452. goto error;
  453. }
  454. ret = clk_set_rate(msm_host->esc_clk, msm_host->esc_clk_rate);
  455. if (ret) {
  456. pr_err("%s: Failed to set rate esc clk, %d\n", __func__, ret);
  457. goto error;
  458. }
  459. ret = clk_set_rate(msm_host->src_clk, msm_host->src_clk_rate);
  460. if (ret) {
  461. pr_err("%s: Failed to set rate src clk, %d\n", __func__, ret);
  462. goto error;
  463. }
  464. ret = clk_set_rate(msm_host->pixel_clk, msm_host->mode->clock * 1000);
  465. if (ret) {
  466. pr_err("%s: Failed to set rate pixel clk, %d\n", __func__, ret);
  467. goto error;
  468. }
  469. ret = clk_prepare_enable(msm_host->byte_clk);
  470. if (ret) {
  471. pr_err("%s: Failed to enable dsi byte clk\n", __func__);
  472. goto error;
  473. }
  474. ret = clk_prepare_enable(msm_host->esc_clk);
  475. if (ret) {
  476. pr_err("%s: Failed to enable dsi esc clk\n", __func__);
  477. goto esc_clk_err;
  478. }
  479. ret = clk_prepare_enable(msm_host->src_clk);
  480. if (ret) {
  481. pr_err("%s: Failed to enable dsi src clk\n", __func__);
  482. goto src_clk_err;
  483. }
  484. ret = clk_prepare_enable(msm_host->pixel_clk);
  485. if (ret) {
  486. pr_err("%s: Failed to enable dsi pixel clk\n", __func__);
  487. goto pixel_clk_err;
  488. }
  489. return 0;
  490. pixel_clk_err:
  491. clk_disable_unprepare(msm_host->src_clk);
  492. src_clk_err:
  493. clk_disable_unprepare(msm_host->esc_clk);
  494. esc_clk_err:
  495. clk_disable_unprepare(msm_host->byte_clk);
  496. error:
  497. return ret;
  498. }
  499. static int dsi_link_clk_enable(struct msm_dsi_host *msm_host)
  500. {
  501. const struct msm_dsi_cfg_handler *cfg_hnd = msm_host->cfg_hnd;
  502. if (cfg_hnd->major == MSM_DSI_VER_MAJOR_6G)
  503. return dsi_link_clk_enable_6g(msm_host);
  504. else
  505. return dsi_link_clk_enable_v2(msm_host);
  506. }
  507. static void dsi_link_clk_disable(struct msm_dsi_host *msm_host)
  508. {
  509. const struct msm_dsi_cfg_handler *cfg_hnd = msm_host->cfg_hnd;
  510. if (cfg_hnd->major == MSM_DSI_VER_MAJOR_6G) {
  511. clk_disable_unprepare(msm_host->esc_clk);
  512. clk_disable_unprepare(msm_host->pixel_clk);
  513. clk_disable_unprepare(msm_host->byte_clk);
  514. } else {
  515. clk_disable_unprepare(msm_host->pixel_clk);
  516. clk_disable_unprepare(msm_host->src_clk);
  517. clk_disable_unprepare(msm_host->esc_clk);
  518. clk_disable_unprepare(msm_host->byte_clk);
  519. }
  520. }
  521. static int dsi_calc_clk_rate(struct msm_dsi_host *msm_host)
  522. {
  523. struct drm_display_mode *mode = msm_host->mode;
  524. const struct msm_dsi_cfg_handler *cfg_hnd = msm_host->cfg_hnd;
  525. u8 lanes = msm_host->lanes;
  526. u32 bpp = dsi_get_bpp(msm_host->format);
  527. u32 pclk_rate;
  528. if (!mode) {
  529. pr_err("%s: mode not set\n", __func__);
  530. return -EINVAL;
  531. }
  532. pclk_rate = mode->clock * 1000;
  533. if (lanes > 0) {
  534. msm_host->byte_clk_rate = (pclk_rate * bpp) / (8 * lanes);
  535. } else {
  536. pr_err("%s: forcing mdss_dsi lanes to 1\n", __func__);
  537. msm_host->byte_clk_rate = (pclk_rate * bpp) / 8;
  538. }
  539. DBG("pclk=%d, bclk=%d", pclk_rate, msm_host->byte_clk_rate);
  540. msm_host->esc_clk_rate = clk_get_rate(msm_host->esc_clk);
  541. if (cfg_hnd->major == MSM_DSI_VER_MAJOR_V2) {
  542. unsigned int esc_mhz, esc_div;
  543. unsigned long byte_mhz;
  544. msm_host->src_clk_rate = (pclk_rate * bpp) / 8;
  545. /*
  546. * esc clock is byte clock followed by a 4 bit divider,
  547. * we need to find an escape clock frequency within the
  548. * mipi DSI spec range within the maximum divider limit
  549. * We iterate here between an escape clock frequencey
  550. * between 20 Mhz to 5 Mhz and pick up the first one
  551. * that can be supported by our divider
  552. */
  553. byte_mhz = msm_host->byte_clk_rate / 1000000;
  554. for (esc_mhz = 20; esc_mhz >= 5; esc_mhz--) {
  555. esc_div = DIV_ROUND_UP(byte_mhz, esc_mhz);
  556. /*
  557. * TODO: Ideally, we shouldn't know what sort of divider
  558. * is available in mmss_cc, we're just assuming that
  559. * it'll always be a 4 bit divider. Need to come up with
  560. * a better way here.
  561. */
  562. if (esc_div >= 1 && esc_div <= 16)
  563. break;
  564. }
  565. if (esc_mhz < 5)
  566. return -EINVAL;
  567. msm_host->esc_clk_rate = msm_host->byte_clk_rate / esc_div;
  568. DBG("esc=%d, src=%d", msm_host->esc_clk_rate,
  569. msm_host->src_clk_rate);
  570. }
  571. return 0;
  572. }
  573. static void dsi_intr_ctrl(struct msm_dsi_host *msm_host, u32 mask, int enable)
  574. {
  575. u32 intr;
  576. unsigned long flags;
  577. spin_lock_irqsave(&msm_host->intr_lock, flags);
  578. intr = dsi_read(msm_host, REG_DSI_INTR_CTRL);
  579. if (enable)
  580. intr |= mask;
  581. else
  582. intr &= ~mask;
  583. DBG("intr=%x enable=%d", intr, enable);
  584. dsi_write(msm_host, REG_DSI_INTR_CTRL, intr);
  585. spin_unlock_irqrestore(&msm_host->intr_lock, flags);
  586. }
  587. static inline enum dsi_traffic_mode dsi_get_traffic_mode(const u32 mode_flags)
  588. {
  589. if (mode_flags & MIPI_DSI_MODE_VIDEO_BURST)
  590. return BURST_MODE;
  591. else if (mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE)
  592. return NON_BURST_SYNCH_PULSE;
  593. return NON_BURST_SYNCH_EVENT;
  594. }
  595. static inline enum dsi_vid_dst_format dsi_get_vid_fmt(
  596. const enum mipi_dsi_pixel_format mipi_fmt)
  597. {
  598. switch (mipi_fmt) {
  599. case MIPI_DSI_FMT_RGB888: return VID_DST_FORMAT_RGB888;
  600. case MIPI_DSI_FMT_RGB666: return VID_DST_FORMAT_RGB666_LOOSE;
  601. case MIPI_DSI_FMT_RGB666_PACKED: return VID_DST_FORMAT_RGB666;
  602. case MIPI_DSI_FMT_RGB565: return VID_DST_FORMAT_RGB565;
  603. default: return VID_DST_FORMAT_RGB888;
  604. }
  605. }
  606. static inline enum dsi_cmd_dst_format dsi_get_cmd_fmt(
  607. const enum mipi_dsi_pixel_format mipi_fmt)
  608. {
  609. switch (mipi_fmt) {
  610. case MIPI_DSI_FMT_RGB888: return CMD_DST_FORMAT_RGB888;
  611. case MIPI_DSI_FMT_RGB666_PACKED:
  612. case MIPI_DSI_FMT_RGB666: return VID_DST_FORMAT_RGB666;
  613. case MIPI_DSI_FMT_RGB565: return CMD_DST_FORMAT_RGB565;
  614. default: return CMD_DST_FORMAT_RGB888;
  615. }
  616. }
  617. static void dsi_ctrl_config(struct msm_dsi_host *msm_host, bool enable,
  618. struct msm_dsi_phy_shared_timings *phy_shared_timings)
  619. {
  620. u32 flags = msm_host->mode_flags;
  621. enum mipi_dsi_pixel_format mipi_fmt = msm_host->format;
  622. const struct msm_dsi_cfg_handler *cfg_hnd = msm_host->cfg_hnd;
  623. u32 data = 0;
  624. if (!enable) {
  625. dsi_write(msm_host, REG_DSI_CTRL, 0);
  626. return;
  627. }
  628. if (flags & MIPI_DSI_MODE_VIDEO) {
  629. if (flags & MIPI_DSI_MODE_VIDEO_HSE)
  630. data |= DSI_VID_CFG0_PULSE_MODE_HSA_HE;
  631. if (flags & MIPI_DSI_MODE_VIDEO_HFP)
  632. data |= DSI_VID_CFG0_HFP_POWER_STOP;
  633. if (flags & MIPI_DSI_MODE_VIDEO_HBP)
  634. data |= DSI_VID_CFG0_HBP_POWER_STOP;
  635. if (flags & MIPI_DSI_MODE_VIDEO_HSA)
  636. data |= DSI_VID_CFG0_HSA_POWER_STOP;
  637. /* Always set low power stop mode for BLLP
  638. * to let command engine send packets
  639. */
  640. data |= DSI_VID_CFG0_EOF_BLLP_POWER_STOP |
  641. DSI_VID_CFG0_BLLP_POWER_STOP;
  642. data |= DSI_VID_CFG0_TRAFFIC_MODE(dsi_get_traffic_mode(flags));
  643. data |= DSI_VID_CFG0_DST_FORMAT(dsi_get_vid_fmt(mipi_fmt));
  644. data |= DSI_VID_CFG0_VIRT_CHANNEL(msm_host->channel);
  645. dsi_write(msm_host, REG_DSI_VID_CFG0, data);
  646. /* Do not swap RGB colors */
  647. data = DSI_VID_CFG1_RGB_SWAP(SWAP_RGB);
  648. dsi_write(msm_host, REG_DSI_VID_CFG1, 0);
  649. } else {
  650. /* Do not swap RGB colors */
  651. data = DSI_CMD_CFG0_RGB_SWAP(SWAP_RGB);
  652. data |= DSI_CMD_CFG0_DST_FORMAT(dsi_get_cmd_fmt(mipi_fmt));
  653. dsi_write(msm_host, REG_DSI_CMD_CFG0, data);
  654. data = DSI_CMD_CFG1_WR_MEM_START(MIPI_DCS_WRITE_MEMORY_START) |
  655. DSI_CMD_CFG1_WR_MEM_CONTINUE(
  656. MIPI_DCS_WRITE_MEMORY_CONTINUE);
  657. /* Always insert DCS command */
  658. data |= DSI_CMD_CFG1_INSERT_DCS_COMMAND;
  659. dsi_write(msm_host, REG_DSI_CMD_CFG1, data);
  660. }
  661. dsi_write(msm_host, REG_DSI_CMD_DMA_CTRL,
  662. DSI_CMD_DMA_CTRL_FROM_FRAME_BUFFER |
  663. DSI_CMD_DMA_CTRL_LOW_POWER);
  664. data = 0;
  665. /* Always assume dedicated TE pin */
  666. data |= DSI_TRIG_CTRL_TE;
  667. data |= DSI_TRIG_CTRL_MDP_TRIGGER(TRIGGER_NONE);
  668. data |= DSI_TRIG_CTRL_DMA_TRIGGER(TRIGGER_SW);
  669. data |= DSI_TRIG_CTRL_STREAM(msm_host->channel);
  670. if ((cfg_hnd->major == MSM_DSI_VER_MAJOR_6G) &&
  671. (cfg_hnd->minor >= MSM_DSI_6G_VER_MINOR_V1_2))
  672. data |= DSI_TRIG_CTRL_BLOCK_DMA_WITHIN_FRAME;
  673. dsi_write(msm_host, REG_DSI_TRIG_CTRL, data);
  674. data = DSI_CLKOUT_TIMING_CTRL_T_CLK_POST(phy_shared_timings->clk_post) |
  675. DSI_CLKOUT_TIMING_CTRL_T_CLK_PRE(phy_shared_timings->clk_pre);
  676. dsi_write(msm_host, REG_DSI_CLKOUT_TIMING_CTRL, data);
  677. if ((cfg_hnd->major == MSM_DSI_VER_MAJOR_6G) &&
  678. (cfg_hnd->minor > MSM_DSI_6G_VER_MINOR_V1_0) &&
  679. phy_shared_timings->clk_pre_inc_by_2)
  680. dsi_write(msm_host, REG_DSI_T_CLK_PRE_EXTEND,
  681. DSI_T_CLK_PRE_EXTEND_INC_BY_2_BYTECLK);
  682. data = 0;
  683. if (!(flags & MIPI_DSI_MODE_EOT_PACKET))
  684. data |= DSI_EOT_PACKET_CTRL_TX_EOT_APPEND;
  685. dsi_write(msm_host, REG_DSI_EOT_PACKET_CTRL, data);
  686. /* allow only ack-err-status to generate interrupt */
  687. dsi_write(msm_host, REG_DSI_ERR_INT_MASK0, 0x13ff3fe0);
  688. dsi_intr_ctrl(msm_host, DSI_IRQ_MASK_ERROR, 1);
  689. dsi_write(msm_host, REG_DSI_CLK_CTRL, DSI_CLK_CTRL_ENABLE_CLKS);
  690. data = DSI_CTRL_CLK_EN;
  691. DBG("lane number=%d", msm_host->lanes);
  692. data |= ((DSI_CTRL_LANE0 << msm_host->lanes) - DSI_CTRL_LANE0);
  693. dsi_write(msm_host, REG_DSI_LANE_SWAP_CTRL,
  694. DSI_LANE_SWAP_CTRL_DLN_SWAP_SEL(msm_host->dlane_swap));
  695. if (!(flags & MIPI_DSI_CLOCK_NON_CONTINUOUS))
  696. dsi_write(msm_host, REG_DSI_LANE_CTRL,
  697. DSI_LANE_CTRL_CLKLN_HS_FORCE_REQUEST);
  698. data |= DSI_CTRL_ENABLE;
  699. dsi_write(msm_host, REG_DSI_CTRL, data);
  700. }
  701. static void dsi_timing_setup(struct msm_dsi_host *msm_host)
  702. {
  703. struct drm_display_mode *mode = msm_host->mode;
  704. u32 hs_start = 0, vs_start = 0; /* take sync start as 0 */
  705. u32 h_total = mode->htotal;
  706. u32 v_total = mode->vtotal;
  707. u32 hs_end = mode->hsync_end - mode->hsync_start;
  708. u32 vs_end = mode->vsync_end - mode->vsync_start;
  709. u32 ha_start = h_total - mode->hsync_start;
  710. u32 ha_end = ha_start + mode->hdisplay;
  711. u32 va_start = v_total - mode->vsync_start;
  712. u32 va_end = va_start + mode->vdisplay;
  713. u32 wc;
  714. DBG("");
  715. if (msm_host->mode_flags & MIPI_DSI_MODE_VIDEO) {
  716. dsi_write(msm_host, REG_DSI_ACTIVE_H,
  717. DSI_ACTIVE_H_START(ha_start) |
  718. DSI_ACTIVE_H_END(ha_end));
  719. dsi_write(msm_host, REG_DSI_ACTIVE_V,
  720. DSI_ACTIVE_V_START(va_start) |
  721. DSI_ACTIVE_V_END(va_end));
  722. dsi_write(msm_host, REG_DSI_TOTAL,
  723. DSI_TOTAL_H_TOTAL(h_total - 1) |
  724. DSI_TOTAL_V_TOTAL(v_total - 1));
  725. dsi_write(msm_host, REG_DSI_ACTIVE_HSYNC,
  726. DSI_ACTIVE_HSYNC_START(hs_start) |
  727. DSI_ACTIVE_HSYNC_END(hs_end));
  728. dsi_write(msm_host, REG_DSI_ACTIVE_VSYNC_HPOS, 0);
  729. dsi_write(msm_host, REG_DSI_ACTIVE_VSYNC_VPOS,
  730. DSI_ACTIVE_VSYNC_VPOS_START(vs_start) |
  731. DSI_ACTIVE_VSYNC_VPOS_END(vs_end));
  732. } else { /* command mode */
  733. /* image data and 1 byte write_memory_start cmd */
  734. wc = mode->hdisplay * dsi_get_bpp(msm_host->format) / 8 + 1;
  735. dsi_write(msm_host, REG_DSI_CMD_MDP_STREAM_CTRL,
  736. DSI_CMD_MDP_STREAM_CTRL_WORD_COUNT(wc) |
  737. DSI_CMD_MDP_STREAM_CTRL_VIRTUAL_CHANNEL(
  738. msm_host->channel) |
  739. DSI_CMD_MDP_STREAM_CTRL_DATA_TYPE(
  740. MIPI_DSI_DCS_LONG_WRITE));
  741. dsi_write(msm_host, REG_DSI_CMD_MDP_STREAM_TOTAL,
  742. DSI_CMD_MDP_STREAM_TOTAL_H_TOTAL(mode->hdisplay) |
  743. DSI_CMD_MDP_STREAM_TOTAL_V_TOTAL(mode->vdisplay));
  744. }
  745. }
  746. static void dsi_sw_reset(struct msm_dsi_host *msm_host)
  747. {
  748. dsi_write(msm_host, REG_DSI_CLK_CTRL, DSI_CLK_CTRL_ENABLE_CLKS);
  749. wmb(); /* clocks need to be enabled before reset */
  750. dsi_write(msm_host, REG_DSI_RESET, 1);
  751. wmb(); /* make sure reset happen */
  752. dsi_write(msm_host, REG_DSI_RESET, 0);
  753. }
  754. static void dsi_op_mode_config(struct msm_dsi_host *msm_host,
  755. bool video_mode, bool enable)
  756. {
  757. u32 dsi_ctrl;
  758. dsi_ctrl = dsi_read(msm_host, REG_DSI_CTRL);
  759. if (!enable) {
  760. dsi_ctrl &= ~(DSI_CTRL_ENABLE | DSI_CTRL_VID_MODE_EN |
  761. DSI_CTRL_CMD_MODE_EN);
  762. dsi_intr_ctrl(msm_host, DSI_IRQ_MASK_CMD_MDP_DONE |
  763. DSI_IRQ_MASK_VIDEO_DONE, 0);
  764. } else {
  765. if (video_mode) {
  766. dsi_ctrl |= DSI_CTRL_VID_MODE_EN;
  767. } else { /* command mode */
  768. dsi_ctrl |= DSI_CTRL_CMD_MODE_EN;
  769. dsi_intr_ctrl(msm_host, DSI_IRQ_MASK_CMD_MDP_DONE, 1);
  770. }
  771. dsi_ctrl |= DSI_CTRL_ENABLE;
  772. }
  773. dsi_write(msm_host, REG_DSI_CTRL, dsi_ctrl);
  774. }
  775. static void dsi_set_tx_power_mode(int mode, struct msm_dsi_host *msm_host)
  776. {
  777. u32 data;
  778. data = dsi_read(msm_host, REG_DSI_CMD_DMA_CTRL);
  779. if (mode == 0)
  780. data &= ~DSI_CMD_DMA_CTRL_LOW_POWER;
  781. else
  782. data |= DSI_CMD_DMA_CTRL_LOW_POWER;
  783. dsi_write(msm_host, REG_DSI_CMD_DMA_CTRL, data);
  784. }
  785. static void dsi_wait4video_done(struct msm_dsi_host *msm_host)
  786. {
  787. dsi_intr_ctrl(msm_host, DSI_IRQ_MASK_VIDEO_DONE, 1);
  788. reinit_completion(&msm_host->video_comp);
  789. wait_for_completion_timeout(&msm_host->video_comp,
  790. msecs_to_jiffies(70));
  791. dsi_intr_ctrl(msm_host, DSI_IRQ_MASK_VIDEO_DONE, 0);
  792. }
  793. static void dsi_wait4video_eng_busy(struct msm_dsi_host *msm_host)
  794. {
  795. if (!(msm_host->mode_flags & MIPI_DSI_MODE_VIDEO))
  796. return;
  797. if (msm_host->power_on) {
  798. dsi_wait4video_done(msm_host);
  799. /* delay 4 ms to skip BLLP */
  800. usleep_range(2000, 4000);
  801. }
  802. }
  803. /* dsi_cmd */
  804. static int dsi_tx_buf_alloc(struct msm_dsi_host *msm_host, int size)
  805. {
  806. struct drm_device *dev = msm_host->dev;
  807. struct msm_drm_private *priv = dev->dev_private;
  808. const struct msm_dsi_cfg_handler *cfg_hnd = msm_host->cfg_hnd;
  809. int ret;
  810. uint64_t iova;
  811. if (cfg_hnd->major == MSM_DSI_VER_MAJOR_6G) {
  812. msm_host->tx_gem_obj = msm_gem_new(dev, size, MSM_BO_UNCACHED);
  813. if (IS_ERR(msm_host->tx_gem_obj)) {
  814. ret = PTR_ERR(msm_host->tx_gem_obj);
  815. pr_err("%s: failed to allocate gem, %d\n",
  816. __func__, ret);
  817. msm_host->tx_gem_obj = NULL;
  818. return ret;
  819. }
  820. ret = msm_gem_get_iova(msm_host->tx_gem_obj,
  821. priv->kms->aspace, &iova);
  822. mutex_unlock(&dev->struct_mutex);
  823. if (ret) {
  824. pr_err("%s: failed to get iova, %d\n", __func__, ret);
  825. return ret;
  826. }
  827. if (iova & 0x07) {
  828. pr_err("%s: buf NOT 8 bytes aligned\n", __func__);
  829. return -EINVAL;
  830. }
  831. msm_host->tx_size = msm_host->tx_gem_obj->size;
  832. } else {
  833. msm_host->tx_buf = dma_alloc_coherent(dev->dev, size,
  834. &msm_host->tx_buf_paddr, GFP_KERNEL);
  835. if (!msm_host->tx_buf) {
  836. ret = -ENOMEM;
  837. pr_err("%s: failed to allocate tx buf, %d\n",
  838. __func__, ret);
  839. return ret;
  840. }
  841. msm_host->tx_size = size;
  842. }
  843. return 0;
  844. }
  845. static void dsi_tx_buf_free(struct msm_dsi_host *msm_host)
  846. {
  847. struct drm_device *dev = msm_host->dev;
  848. if (msm_host->tx_gem_obj) {
  849. msm_gem_put_iova(msm_host->tx_gem_obj, 0);
  850. mutex_lock(&dev->struct_mutex);
  851. msm_gem_free_object(msm_host->tx_gem_obj);
  852. msm_host->tx_gem_obj = NULL;
  853. mutex_unlock(&dev->struct_mutex);
  854. }
  855. if (msm_host->tx_buf)
  856. dma_free_coherent(dev->dev, msm_host->tx_size, msm_host->tx_buf,
  857. msm_host->tx_buf_paddr);
  858. }
  859. /*
  860. * prepare cmd buffer to be txed
  861. */
  862. static int dsi_cmd_dma_add(struct msm_dsi_host *msm_host,
  863. const struct mipi_dsi_msg *msg)
  864. {
  865. const struct msm_dsi_cfg_handler *cfg_hnd = msm_host->cfg_hnd;
  866. struct mipi_dsi_packet packet;
  867. int len;
  868. int ret;
  869. u8 *data;
  870. ret = mipi_dsi_create_packet(&packet, msg);
  871. if (ret) {
  872. pr_err("%s: create packet failed, %d\n", __func__, ret);
  873. return ret;
  874. }
  875. len = (packet.size + 3) & (~0x3);
  876. if (len > msm_host->tx_size) {
  877. pr_err("%s: packet size is too big\n", __func__);
  878. return -EINVAL;
  879. }
  880. if (cfg_hnd->major == MSM_DSI_VER_MAJOR_6G) {
  881. data = msm_gem_get_vaddr(msm_host->tx_gem_obj);
  882. if (IS_ERR(data)) {
  883. ret = PTR_ERR(data);
  884. pr_err("%s: get vaddr failed, %d\n", __func__, ret);
  885. return ret;
  886. }
  887. } else {
  888. data = msm_host->tx_buf;
  889. }
  890. /* MSM specific command format in memory */
  891. data[0] = packet.header[1];
  892. data[1] = packet.header[2];
  893. data[2] = packet.header[0];
  894. data[3] = BIT(7); /* Last packet */
  895. if (mipi_dsi_packet_format_is_long(msg->type))
  896. data[3] |= BIT(6);
  897. if (msg->rx_buf && msg->rx_len)
  898. data[3] |= BIT(5);
  899. /* Long packet */
  900. if (packet.payload && packet.payload_length)
  901. memcpy(data + 4, packet.payload, packet.payload_length);
  902. /* Append 0xff to the end */
  903. if (packet.size < len)
  904. memset(data + packet.size, 0xff, len - packet.size);
  905. if (cfg_hnd->major == MSM_DSI_VER_MAJOR_6G)
  906. msm_gem_put_vaddr(msm_host->tx_gem_obj);
  907. return len;
  908. }
  909. /*
  910. * dsi_short_read1_resp: 1 parameter
  911. */
  912. static int dsi_short_read1_resp(u8 *buf, const struct mipi_dsi_msg *msg)
  913. {
  914. u8 *data = msg->rx_buf;
  915. if (data && (msg->rx_len >= 1)) {
  916. *data = buf[1]; /* strip out dcs type */
  917. return 1;
  918. } else {
  919. pr_err("%s: read data does not match with rx_buf len %zu\n",
  920. __func__, msg->rx_len);
  921. return -EINVAL;
  922. }
  923. }
  924. /*
  925. * dsi_short_read2_resp: 2 parameter
  926. */
  927. static int dsi_short_read2_resp(u8 *buf, const struct mipi_dsi_msg *msg)
  928. {
  929. u8 *data = msg->rx_buf;
  930. if (data && (msg->rx_len >= 2)) {
  931. data[0] = buf[1]; /* strip out dcs type */
  932. data[1] = buf[2];
  933. return 2;
  934. } else {
  935. pr_err("%s: read data does not match with rx_buf len %zu\n",
  936. __func__, msg->rx_len);
  937. return -EINVAL;
  938. }
  939. }
  940. static int dsi_long_read_resp(u8 *buf, const struct mipi_dsi_msg *msg)
  941. {
  942. /* strip out 4 byte dcs header */
  943. if (msg->rx_buf && msg->rx_len)
  944. memcpy(msg->rx_buf, buf + 4, msg->rx_len);
  945. return msg->rx_len;
  946. }
  947. static int dsi_cmd_dma_tx(struct msm_dsi_host *msm_host, int len)
  948. {
  949. const struct msm_dsi_cfg_handler *cfg_hnd = msm_host->cfg_hnd;
  950. struct drm_device *dev = msm_host->dev;
  951. struct msm_drm_private *priv = dev->dev_private;
  952. int ret;
  953. uint64_t dma_base;
  954. bool triggered;
  955. if (cfg_hnd->major == MSM_DSI_VER_MAJOR_6G) {
  956. ret = msm_gem_get_iova(msm_host->tx_gem_obj,
  957. priv->kms->aspace, &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_node(np, 1, 0);
  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. msm_dsi->host = &msm_host->base;
  1405. ret = dsi_host_parse_dt(msm_host);
  1406. if (ret) {
  1407. pr_err("%s: failed to parse dt\n", __func__);
  1408. goto fail;
  1409. }
  1410. msm_host->ctrl_base = msm_ioremap(pdev, "dsi_ctrl", "DSI CTRL");
  1411. if (IS_ERR(msm_host->ctrl_base)) {
  1412. pr_err("%s: unable to map Dsi ctrl base\n", __func__);
  1413. ret = PTR_ERR(msm_host->ctrl_base);
  1414. goto fail;
  1415. }
  1416. pm_runtime_enable(&pdev->dev);
  1417. msm_host->cfg_hnd = dsi_get_config(msm_host);
  1418. if (!msm_host->cfg_hnd) {
  1419. ret = -EINVAL;
  1420. pr_err("%s: get config failed\n", __func__);
  1421. goto fail;
  1422. }
  1423. msm_host->id = dsi_host_get_id(msm_host);
  1424. if (msm_host->id < 0) {
  1425. ret = msm_host->id;
  1426. pr_err("%s: unable to identify DSI host index\n", __func__);
  1427. goto fail;
  1428. }
  1429. /* fixup base address by io offset */
  1430. msm_host->ctrl_base += msm_host->cfg_hnd->cfg->io_offset;
  1431. ret = dsi_regulator_init(msm_host);
  1432. if (ret) {
  1433. pr_err("%s: regulator init failed\n", __func__);
  1434. goto fail;
  1435. }
  1436. ret = dsi_clk_init(msm_host);
  1437. if (ret) {
  1438. pr_err("%s: unable to initialize dsi clks\n", __func__);
  1439. goto fail;
  1440. }
  1441. msm_host->rx_buf = devm_kzalloc(&pdev->dev, SZ_4K, GFP_KERNEL);
  1442. if (!msm_host->rx_buf) {
  1443. ret = -ENOMEM;
  1444. pr_err("%s: alloc rx temp buf failed\n", __func__);
  1445. goto fail;
  1446. }
  1447. init_completion(&msm_host->dma_comp);
  1448. init_completion(&msm_host->video_comp);
  1449. mutex_init(&msm_host->dev_mutex);
  1450. mutex_init(&msm_host->cmd_mutex);
  1451. spin_lock_init(&msm_host->intr_lock);
  1452. /* setup workqueue */
  1453. msm_host->workqueue = alloc_ordered_workqueue("dsi_drm_work", 0);
  1454. INIT_WORK(&msm_host->err_work, dsi_err_worker);
  1455. INIT_WORK(&msm_host->hpd_work, dsi_hpd_worker);
  1456. msm_dsi->id = msm_host->id;
  1457. DBG("Dsi Host %d initialized", msm_host->id);
  1458. return 0;
  1459. fail:
  1460. return ret;
  1461. }
  1462. void msm_dsi_host_destroy(struct mipi_dsi_host *host)
  1463. {
  1464. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1465. DBG("");
  1466. dsi_tx_buf_free(msm_host);
  1467. if (msm_host->workqueue) {
  1468. flush_workqueue(msm_host->workqueue);
  1469. destroy_workqueue(msm_host->workqueue);
  1470. msm_host->workqueue = NULL;
  1471. }
  1472. mutex_destroy(&msm_host->cmd_mutex);
  1473. mutex_destroy(&msm_host->dev_mutex);
  1474. pm_runtime_disable(&msm_host->pdev->dev);
  1475. }
  1476. int msm_dsi_host_modeset_init(struct mipi_dsi_host *host,
  1477. struct drm_device *dev)
  1478. {
  1479. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1480. struct platform_device *pdev = msm_host->pdev;
  1481. int ret;
  1482. msm_host->irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
  1483. if (msm_host->irq < 0) {
  1484. ret = msm_host->irq;
  1485. dev_err(dev->dev, "failed to get irq: %d\n", ret);
  1486. return ret;
  1487. }
  1488. ret = devm_request_irq(&pdev->dev, msm_host->irq,
  1489. dsi_host_irq, IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
  1490. "dsi_isr", msm_host);
  1491. if (ret < 0) {
  1492. dev_err(&pdev->dev, "failed to request IRQ%u: %d\n",
  1493. msm_host->irq, ret);
  1494. return ret;
  1495. }
  1496. msm_host->dev = dev;
  1497. ret = dsi_tx_buf_alloc(msm_host, SZ_4K);
  1498. if (ret) {
  1499. pr_err("%s: alloc tx gem obj failed, %d\n", __func__, ret);
  1500. return ret;
  1501. }
  1502. return 0;
  1503. }
  1504. int msm_dsi_host_register(struct mipi_dsi_host *host, bool check_defer)
  1505. {
  1506. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1507. int ret;
  1508. /* Register mipi dsi host */
  1509. if (!msm_host->registered) {
  1510. host->dev = &msm_host->pdev->dev;
  1511. host->ops = &dsi_host_ops;
  1512. ret = mipi_dsi_host_register(host);
  1513. if (ret)
  1514. return ret;
  1515. msm_host->registered = true;
  1516. /* If the panel driver has not been probed after host register,
  1517. * we should defer the host's probe.
  1518. * It makes sure panel is connected when fbcon detects
  1519. * connector status and gets the proper display mode to
  1520. * create framebuffer.
  1521. * Don't try to defer if there is nothing connected to the dsi
  1522. * output
  1523. */
  1524. if (check_defer && msm_host->device_node) {
  1525. if (!of_drm_find_panel(msm_host->device_node))
  1526. if (!of_drm_find_bridge(msm_host->device_node))
  1527. return -EPROBE_DEFER;
  1528. }
  1529. }
  1530. return 0;
  1531. }
  1532. void msm_dsi_host_unregister(struct mipi_dsi_host *host)
  1533. {
  1534. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1535. if (msm_host->registered) {
  1536. mipi_dsi_host_unregister(host);
  1537. host->dev = NULL;
  1538. host->ops = NULL;
  1539. msm_host->registered = false;
  1540. }
  1541. }
  1542. int msm_dsi_host_xfer_prepare(struct mipi_dsi_host *host,
  1543. const struct mipi_dsi_msg *msg)
  1544. {
  1545. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1546. /* TODO: make sure dsi_cmd_mdp is idle.
  1547. * Since DSI6G v1.2.0, we can set DSI_TRIG_CTRL.BLOCK_DMA_WITHIN_FRAME
  1548. * to ask H/W to wait until cmd mdp is idle. S/W wait is not needed.
  1549. * How to handle the old versions? Wait for mdp cmd done?
  1550. */
  1551. /*
  1552. * mdss interrupt is generated in mdp core clock domain
  1553. * mdp clock need to be enabled to receive dsi interrupt
  1554. */
  1555. pm_runtime_get_sync(&msm_host->pdev->dev);
  1556. dsi_link_clk_enable(msm_host);
  1557. /* TODO: vote for bus bandwidth */
  1558. if (!(msg->flags & MIPI_DSI_MSG_USE_LPM))
  1559. dsi_set_tx_power_mode(0, msm_host);
  1560. msm_host->dma_cmd_ctrl_restore = dsi_read(msm_host, REG_DSI_CTRL);
  1561. dsi_write(msm_host, REG_DSI_CTRL,
  1562. msm_host->dma_cmd_ctrl_restore |
  1563. DSI_CTRL_CMD_MODE_EN |
  1564. DSI_CTRL_ENABLE);
  1565. dsi_intr_ctrl(msm_host, DSI_IRQ_MASK_CMD_DMA_DONE, 1);
  1566. return 0;
  1567. }
  1568. void msm_dsi_host_xfer_restore(struct mipi_dsi_host *host,
  1569. const struct mipi_dsi_msg *msg)
  1570. {
  1571. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1572. dsi_intr_ctrl(msm_host, DSI_IRQ_MASK_CMD_DMA_DONE, 0);
  1573. dsi_write(msm_host, REG_DSI_CTRL, msm_host->dma_cmd_ctrl_restore);
  1574. if (!(msg->flags & MIPI_DSI_MSG_USE_LPM))
  1575. dsi_set_tx_power_mode(1, msm_host);
  1576. /* TODO: unvote for bus bandwidth */
  1577. dsi_link_clk_disable(msm_host);
  1578. pm_runtime_put_autosuspend(&msm_host->pdev->dev);
  1579. }
  1580. int msm_dsi_host_cmd_tx(struct mipi_dsi_host *host,
  1581. const struct mipi_dsi_msg *msg)
  1582. {
  1583. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1584. return dsi_cmds2buf_tx(msm_host, msg);
  1585. }
  1586. int msm_dsi_host_cmd_rx(struct mipi_dsi_host *host,
  1587. const struct mipi_dsi_msg *msg)
  1588. {
  1589. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1590. const struct msm_dsi_cfg_handler *cfg_hnd = msm_host->cfg_hnd;
  1591. int data_byte, rx_byte, dlen, end;
  1592. int short_response, diff, pkt_size, ret = 0;
  1593. char cmd;
  1594. int rlen = msg->rx_len;
  1595. u8 *buf;
  1596. if (rlen <= 2) {
  1597. short_response = 1;
  1598. pkt_size = rlen;
  1599. rx_byte = 4;
  1600. } else {
  1601. short_response = 0;
  1602. data_byte = 10; /* first read */
  1603. if (rlen < data_byte)
  1604. pkt_size = rlen;
  1605. else
  1606. pkt_size = data_byte;
  1607. rx_byte = data_byte + 6; /* 4 header + 2 crc */
  1608. }
  1609. buf = msm_host->rx_buf;
  1610. end = 0;
  1611. while (!end) {
  1612. u8 tx[2] = {pkt_size & 0xff, pkt_size >> 8};
  1613. struct mipi_dsi_msg max_pkt_size_msg = {
  1614. .channel = msg->channel,
  1615. .type = MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE,
  1616. .tx_len = 2,
  1617. .tx_buf = tx,
  1618. };
  1619. DBG("rlen=%d pkt_size=%d rx_byte=%d",
  1620. rlen, pkt_size, rx_byte);
  1621. ret = dsi_cmds2buf_tx(msm_host, &max_pkt_size_msg);
  1622. if (ret < 2) {
  1623. pr_err("%s: Set max pkt size failed, %d\n",
  1624. __func__, ret);
  1625. return -EINVAL;
  1626. }
  1627. if ((cfg_hnd->major == MSM_DSI_VER_MAJOR_6G) &&
  1628. (cfg_hnd->minor >= MSM_DSI_6G_VER_MINOR_V1_1)) {
  1629. /* Clear the RDBK_DATA registers */
  1630. dsi_write(msm_host, REG_DSI_RDBK_DATA_CTRL,
  1631. DSI_RDBK_DATA_CTRL_CLR);
  1632. wmb(); /* make sure the RDBK registers are cleared */
  1633. dsi_write(msm_host, REG_DSI_RDBK_DATA_CTRL, 0);
  1634. wmb(); /* release cleared status before transfer */
  1635. }
  1636. ret = dsi_cmds2buf_tx(msm_host, msg);
  1637. if (ret < msg->tx_len) {
  1638. pr_err("%s: Read cmd Tx failed, %d\n", __func__, ret);
  1639. return ret;
  1640. }
  1641. /*
  1642. * once cmd_dma_done interrupt received,
  1643. * return data from client is ready and stored
  1644. * at RDBK_DATA register already
  1645. * since rx fifo is 16 bytes, dcs header is kept at first loop,
  1646. * after that dcs header lost during shift into registers
  1647. */
  1648. dlen = dsi_cmd_dma_rx(msm_host, buf, rx_byte, pkt_size);
  1649. if (dlen <= 0)
  1650. return 0;
  1651. if (short_response)
  1652. break;
  1653. if (rlen <= data_byte) {
  1654. diff = data_byte - rlen;
  1655. end = 1;
  1656. } else {
  1657. diff = 0;
  1658. rlen -= data_byte;
  1659. }
  1660. if (!end) {
  1661. dlen -= 2; /* 2 crc */
  1662. dlen -= diff;
  1663. buf += dlen; /* next start position */
  1664. data_byte = 14; /* NOT first read */
  1665. if (rlen < data_byte)
  1666. pkt_size += rlen;
  1667. else
  1668. pkt_size += data_byte;
  1669. DBG("buf=%p dlen=%d diff=%d", buf, dlen, diff);
  1670. }
  1671. }
  1672. /*
  1673. * For single Long read, if the requested rlen < 10,
  1674. * we need to shift the start position of rx
  1675. * data buffer to skip the bytes which are not
  1676. * updated.
  1677. */
  1678. if (pkt_size < 10 && !short_response)
  1679. buf = msm_host->rx_buf + (10 - rlen);
  1680. else
  1681. buf = msm_host->rx_buf;
  1682. cmd = buf[0];
  1683. switch (cmd) {
  1684. case MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT:
  1685. pr_err("%s: rx ACK_ERR_PACLAGE\n", __func__);
  1686. ret = 0;
  1687. break;
  1688. case MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_1BYTE:
  1689. case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE:
  1690. ret = dsi_short_read1_resp(buf, msg);
  1691. break;
  1692. case MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_2BYTE:
  1693. case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE:
  1694. ret = dsi_short_read2_resp(buf, msg);
  1695. break;
  1696. case MIPI_DSI_RX_GENERIC_LONG_READ_RESPONSE:
  1697. case MIPI_DSI_RX_DCS_LONG_READ_RESPONSE:
  1698. ret = dsi_long_read_resp(buf, msg);
  1699. break;
  1700. default:
  1701. pr_warn("%s:Invalid response cmd\n", __func__);
  1702. ret = 0;
  1703. }
  1704. return ret;
  1705. }
  1706. void msm_dsi_host_cmd_xfer_commit(struct mipi_dsi_host *host, u32 dma_base,
  1707. u32 len)
  1708. {
  1709. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1710. dsi_write(msm_host, REG_DSI_DMA_BASE, dma_base);
  1711. dsi_write(msm_host, REG_DSI_DMA_LEN, len);
  1712. dsi_write(msm_host, REG_DSI_TRIG_DMA, 1);
  1713. /* Make sure trigger happens */
  1714. wmb();
  1715. }
  1716. int msm_dsi_host_set_src_pll(struct mipi_dsi_host *host,
  1717. struct msm_dsi_pll *src_pll)
  1718. {
  1719. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1720. const struct msm_dsi_cfg_handler *cfg_hnd = msm_host->cfg_hnd;
  1721. struct clk *byte_clk_provider, *pixel_clk_provider;
  1722. int ret;
  1723. ret = msm_dsi_pll_get_clk_provider(src_pll,
  1724. &byte_clk_provider, &pixel_clk_provider);
  1725. if (ret) {
  1726. pr_info("%s: can't get provider from pll, don't set parent\n",
  1727. __func__);
  1728. return 0;
  1729. }
  1730. ret = clk_set_parent(msm_host->byte_clk_src, byte_clk_provider);
  1731. if (ret) {
  1732. pr_err("%s: can't set parent to byte_clk_src. ret=%d\n",
  1733. __func__, ret);
  1734. goto exit;
  1735. }
  1736. ret = clk_set_parent(msm_host->pixel_clk_src, pixel_clk_provider);
  1737. if (ret) {
  1738. pr_err("%s: can't set parent to pixel_clk_src. ret=%d\n",
  1739. __func__, ret);
  1740. goto exit;
  1741. }
  1742. if (cfg_hnd->major == MSM_DSI_VER_MAJOR_V2) {
  1743. ret = clk_set_parent(msm_host->dsi_clk_src, pixel_clk_provider);
  1744. if (ret) {
  1745. pr_err("%s: can't set parent to dsi_clk_src. ret=%d\n",
  1746. __func__, ret);
  1747. goto exit;
  1748. }
  1749. ret = clk_set_parent(msm_host->esc_clk_src, byte_clk_provider);
  1750. if (ret) {
  1751. pr_err("%s: can't set parent to esc_clk_src. ret=%d\n",
  1752. __func__, ret);
  1753. goto exit;
  1754. }
  1755. }
  1756. exit:
  1757. return ret;
  1758. }
  1759. void msm_dsi_host_reset_phy(struct mipi_dsi_host *host)
  1760. {
  1761. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1762. DBG("");
  1763. dsi_write(msm_host, REG_DSI_PHY_RESET, DSI_PHY_RESET_RESET);
  1764. /* Make sure fully reset */
  1765. wmb();
  1766. udelay(1000);
  1767. dsi_write(msm_host, REG_DSI_PHY_RESET, 0);
  1768. udelay(100);
  1769. }
  1770. void msm_dsi_host_get_phy_clk_req(struct mipi_dsi_host *host,
  1771. struct msm_dsi_phy_clk_request *clk_req)
  1772. {
  1773. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1774. int ret;
  1775. ret = dsi_calc_clk_rate(msm_host);
  1776. if (ret) {
  1777. pr_err("%s: unable to calc clk rate, %d\n", __func__, ret);
  1778. return;
  1779. }
  1780. clk_req->bitclk_rate = msm_host->byte_clk_rate * 8;
  1781. clk_req->escclk_rate = msm_host->esc_clk_rate;
  1782. }
  1783. int msm_dsi_host_enable(struct mipi_dsi_host *host)
  1784. {
  1785. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1786. dsi_op_mode_config(msm_host,
  1787. !!(msm_host->mode_flags & MIPI_DSI_MODE_VIDEO), true);
  1788. /* TODO: clock should be turned off for command mode,
  1789. * and only turned on before MDP START.
  1790. * This part of code should be enabled once mdp driver support it.
  1791. */
  1792. /* if (msm_panel->mode == MSM_DSI_CMD_MODE) {
  1793. * dsi_link_clk_disable(msm_host);
  1794. * pm_runtime_put_autosuspend(&msm_host->pdev->dev);
  1795. * }
  1796. */
  1797. return 0;
  1798. }
  1799. int msm_dsi_host_disable(struct mipi_dsi_host *host)
  1800. {
  1801. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1802. dsi_op_mode_config(msm_host,
  1803. !!(msm_host->mode_flags & MIPI_DSI_MODE_VIDEO), false);
  1804. /* Since we have disabled INTF, the video engine won't stop so that
  1805. * the cmd engine will be blocked.
  1806. * Reset to disable video engine so that we can send off cmd.
  1807. */
  1808. dsi_sw_reset(msm_host);
  1809. return 0;
  1810. }
  1811. static void msm_dsi_sfpb_config(struct msm_dsi_host *msm_host, bool enable)
  1812. {
  1813. enum sfpb_ahb_arb_master_port_en en;
  1814. if (!msm_host->sfpb)
  1815. return;
  1816. en = enable ? SFPB_MASTER_PORT_ENABLE : SFPB_MASTER_PORT_DISABLE;
  1817. regmap_update_bits(msm_host->sfpb, REG_SFPB_GPREG,
  1818. SFPB_GPREG_MASTER_PORT_EN__MASK,
  1819. SFPB_GPREG_MASTER_PORT_EN(en));
  1820. }
  1821. int msm_dsi_host_power_on(struct mipi_dsi_host *host,
  1822. struct msm_dsi_phy_shared_timings *phy_shared_timings)
  1823. {
  1824. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1825. int ret = 0;
  1826. mutex_lock(&msm_host->dev_mutex);
  1827. if (msm_host->power_on) {
  1828. DBG("dsi host already on");
  1829. goto unlock_ret;
  1830. }
  1831. msm_dsi_sfpb_config(msm_host, true);
  1832. ret = dsi_host_regulator_enable(msm_host);
  1833. if (ret) {
  1834. pr_err("%s:Failed to enable vregs.ret=%d\n",
  1835. __func__, ret);
  1836. goto unlock_ret;
  1837. }
  1838. pm_runtime_get_sync(&msm_host->pdev->dev);
  1839. ret = dsi_link_clk_enable(msm_host);
  1840. if (ret) {
  1841. pr_err("%s: failed to enable link clocks. ret=%d\n",
  1842. __func__, ret);
  1843. goto fail_disable_reg;
  1844. }
  1845. ret = pinctrl_pm_select_default_state(&msm_host->pdev->dev);
  1846. if (ret) {
  1847. pr_err("%s: failed to set pinctrl default state, %d\n",
  1848. __func__, ret);
  1849. goto fail_disable_clk;
  1850. }
  1851. dsi_timing_setup(msm_host);
  1852. dsi_sw_reset(msm_host);
  1853. dsi_ctrl_config(msm_host, true, phy_shared_timings);
  1854. if (msm_host->disp_en_gpio)
  1855. gpiod_set_value(msm_host->disp_en_gpio, 1);
  1856. msm_host->power_on = true;
  1857. mutex_unlock(&msm_host->dev_mutex);
  1858. return 0;
  1859. fail_disable_clk:
  1860. dsi_link_clk_disable(msm_host);
  1861. pm_runtime_put_autosuspend(&msm_host->pdev->dev);
  1862. fail_disable_reg:
  1863. dsi_host_regulator_disable(msm_host);
  1864. unlock_ret:
  1865. mutex_unlock(&msm_host->dev_mutex);
  1866. return ret;
  1867. }
  1868. int msm_dsi_host_power_off(struct mipi_dsi_host *host)
  1869. {
  1870. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1871. mutex_lock(&msm_host->dev_mutex);
  1872. if (!msm_host->power_on) {
  1873. DBG("dsi host already off");
  1874. goto unlock_ret;
  1875. }
  1876. dsi_ctrl_config(msm_host, false, NULL);
  1877. if (msm_host->disp_en_gpio)
  1878. gpiod_set_value(msm_host->disp_en_gpio, 0);
  1879. pinctrl_pm_select_sleep_state(&msm_host->pdev->dev);
  1880. dsi_link_clk_disable(msm_host);
  1881. pm_runtime_put_autosuspend(&msm_host->pdev->dev);
  1882. dsi_host_regulator_disable(msm_host);
  1883. msm_dsi_sfpb_config(msm_host, false);
  1884. DBG("-");
  1885. msm_host->power_on = false;
  1886. unlock_ret:
  1887. mutex_unlock(&msm_host->dev_mutex);
  1888. return 0;
  1889. }
  1890. int msm_dsi_host_set_display_mode(struct mipi_dsi_host *host,
  1891. struct drm_display_mode *mode)
  1892. {
  1893. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1894. if (msm_host->mode) {
  1895. drm_mode_destroy(msm_host->dev, msm_host->mode);
  1896. msm_host->mode = NULL;
  1897. }
  1898. msm_host->mode = drm_mode_duplicate(msm_host->dev, mode);
  1899. if (!msm_host->mode) {
  1900. pr_err("%s: cannot duplicate mode\n", __func__);
  1901. return -ENOMEM;
  1902. }
  1903. return 0;
  1904. }
  1905. struct drm_panel *msm_dsi_host_get_panel(struct mipi_dsi_host *host,
  1906. unsigned long *panel_flags)
  1907. {
  1908. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1909. struct drm_panel *panel;
  1910. panel = of_drm_find_panel(msm_host->device_node);
  1911. if (panel_flags)
  1912. *panel_flags = msm_host->mode_flags;
  1913. return panel;
  1914. }
  1915. struct drm_bridge *msm_dsi_host_get_bridge(struct mipi_dsi_host *host)
  1916. {
  1917. struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
  1918. return of_drm_find_bridge(msm_host->device_node);
  1919. }