dsi_v2.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. /* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. */
  13. #include <linux/delay.h>
  14. #include <linux/io.h>
  15. #include <linux/dma-mapping.h>
  16. #include <linux/slab.h>
  17. #include <linux/iopoll.h>
  18. #include <linux/of_device.h>
  19. #include <linux/of_gpio.h>
  20. #include "dsi_v2.h"
  21. static struct dsi_interface dsi_intf;
  22. static int dsi_off(struct mdss_panel_data *pdata)
  23. {
  24. int rc = 0;
  25. pr_debug("turn off dsi controller\n");
  26. if (dsi_intf.off)
  27. rc = dsi_intf.off(pdata);
  28. if (rc) {
  29. pr_err("mdss_dsi_off DSI failed %d\n", rc);
  30. return rc;
  31. }
  32. return rc;
  33. }
  34. static int dsi_on(struct mdss_panel_data *pdata)
  35. {
  36. int rc = 0;
  37. pr_debug("dsi_on DSI controller on\n");
  38. if (dsi_intf.on)
  39. rc = dsi_intf.on(pdata);
  40. if (rc) {
  41. pr_err("mdss_dsi_on DSI failed %d\n", rc);
  42. return rc;
  43. }
  44. return rc;
  45. }
  46. static int dsi_update_pconfig(struct mdss_panel_data *pdata,
  47. int mode)
  48. {
  49. int ret = 0;
  50. struct mdss_panel_info *pinfo = &pdata->panel_info;
  51. struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;
  52. if (!pdata)
  53. return -ENODEV;
  54. ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata,
  55. panel_data);
  56. if (mode == DSI_CMD_MODE) {
  57. pinfo->mipi.mode = DSI_CMD_MODE;
  58. pinfo->type = MIPI_CMD_PANEL;
  59. pinfo->mipi.vsync_enable = 1;
  60. pinfo->mipi.hw_vsync_mode = 1;
  61. } else {
  62. pinfo->mipi.mode = DSI_VIDEO_MODE;
  63. pinfo->type = MIPI_VIDEO_PANEL;
  64. pinfo->mipi.vsync_enable = 0;
  65. pinfo->mipi.hw_vsync_mode = 0;
  66. }
  67. ctrl_pdata->panel_mode = pinfo->mipi.mode;
  68. mdss_panel_get_dst_fmt(pinfo->bpp, pinfo->mipi.mode,
  69. pinfo->mipi.pixel_packing, &(pinfo->mipi.dst_format));
  70. pinfo->cont_splash_enabled = 0;
  71. return ret;
  72. }
  73. static int dsi_panel_handler(struct mdss_panel_data *pdata, int enable)
  74. {
  75. int rc = 0;
  76. struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;
  77. pr_info("%s+: enable=%d\n", __func__, enable);
  78. pr_debug("dsi_panel_handler enable=%d\n", enable);
  79. if (!pdata)
  80. return -ENODEV;
  81. ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata,
  82. panel_data);
  83. if (enable) {
  84. if (!pdata->panel_info.dynamic_switch_pending) {
  85. if (pdata->panel_info.type == MIPI_CMD_PANEL)
  86. dsi_ctrl_gpio_request(ctrl_pdata);
  87. mdss_dsi_panel_reset(pdata, 1);
  88. }
  89. pdata->panel_info.panel_power_on = 1;
  90. if (!pdata->panel_info.dynamic_switch_pending) {
  91. rc = ctrl_pdata->on(pdata);
  92. if (rc)
  93. pr_err("%s: panel on failed!\n", __func__);
  94. }
  95. if (pdata->panel_info.type == MIPI_CMD_PANEL &&
  96. pdata->panel_info.dynamic_switch_pending) {
  97. dsi_ctrl_gpio_request(ctrl_pdata);
  98. mdss_dsi_set_tear_on(ctrl_pdata);
  99. }
  100. } else {
  101. msm_dsi_sw_reset();
  102. if (dsi_intf.op_mode_config)
  103. dsi_intf.op_mode_config(DSI_CMD_MODE, pdata);
  104. if (pdata->panel_info.dynamic_switch_pending) {
  105. pr_info("%s: switching to %s mode\n", __func__,
  106. (pdata->panel_info.mipi.mode ? "video" : "command"));
  107. if (pdata->panel_info.type == MIPI_CMD_PANEL) {
  108. ctrl_pdata->switch_mode(pdata, DSI_VIDEO_MODE);
  109. dsi_ctrl_gpio_free(ctrl_pdata);
  110. } else if (pdata->panel_info.type == MIPI_VIDEO_PANEL) {
  111. ctrl_pdata->switch_mode(pdata, DSI_CMD_MODE);
  112. dsi_ctrl_gpio_request(ctrl_pdata);
  113. mdss_dsi_set_tear_off(ctrl_pdata);
  114. dsi_ctrl_gpio_free(ctrl_pdata);
  115. }
  116. }
  117. if (!pdata->panel_info.dynamic_switch_pending)
  118. rc = ctrl_pdata->off(pdata);
  119. pdata->panel_info.panel_power_on = 0;
  120. if (!pdata->panel_info.dynamic_switch_pending) {
  121. if (pdata->panel_info.type == MIPI_CMD_PANEL)
  122. dsi_ctrl_gpio_free(ctrl_pdata);
  123. mdss_dsi_panel_reset(pdata, 0);
  124. }
  125. }
  126. pr_info("%s-:\n", __func__);
  127. return rc;
  128. }
  129. static int dsi_splash_on(struct mdss_panel_data *pdata)
  130. {
  131. int rc = 0;
  132. pr_debug("%s:\n", __func__);
  133. if (dsi_intf.cont_on)
  134. rc = dsi_intf.cont_on(pdata);
  135. if (rc) {
  136. pr_err("mdss_dsi_on DSI failed %d\n", rc);
  137. return rc;
  138. }
  139. return rc;
  140. }
  141. static int dsi_clk_ctrl(struct mdss_panel_data *pdata, int enable)
  142. {
  143. int rc = 0;
  144. pr_debug("%s:\n", __func__);
  145. if (dsi_intf.clk_ctrl)
  146. rc = dsi_intf.clk_ctrl(pdata, enable);
  147. return rc;
  148. }
  149. #if defined(CONFIG_GET_LCD_ATTACHED)
  150. extern int get_lcd_attached(void);
  151. #endif
  152. static int dsi_event_handler(struct mdss_panel_data *pdata,
  153. int event, void *arg)
  154. {
  155. int rc = 0;
  156. #if defined(CONFIG_MDSS_DSI_EVENT_HANDLER_PANEL)
  157. struct mdss_dsi_ctrl_pdata *ctrl_pdata = NULL;
  158. #endif
  159. if (!pdata) {
  160. pr_err("%s: Invalid input data\n", __func__);
  161. return -ENODEV;
  162. }
  163. #if defined(CONFIG_MDSS_DSI_EVENT_HANDLER_PANEL)
  164. ctrl_pdata = container_of(pdata, struct mdss_dsi_ctrl_pdata,
  165. panel_data);
  166. #endif
  167. #if defined(CONFIG_GET_LCD_ATTACHED)
  168. if (get_lcd_attached() == 0)
  169. {
  170. pr_err("%s: get_lcd_attached(0)!\n",__func__);
  171. return 0;
  172. }
  173. #endif
  174. pr_info("%s : event = %d\n", __func__, event);
  175. switch (event) {
  176. case MDSS_EVENT_UNBLANK:
  177. rc = dsi_on(pdata);
  178. break;
  179. case MDSS_EVENT_BLANK:
  180. rc = dsi_off(pdata);
  181. break;
  182. case MDSS_EVENT_PANEL_ON:
  183. rc = dsi_panel_handler(pdata, 1);
  184. break;
  185. case MDSS_EVENT_PANEL_OFF:
  186. rc = dsi_panel_handler(pdata, 0);
  187. break;
  188. case MDSS_EVENT_CONT_SPLASH_BEGIN:
  189. rc = dsi_splash_on(pdata);
  190. break;
  191. case MDSS_EVENT_PANEL_CLK_CTRL:
  192. rc = dsi_clk_ctrl(pdata, (int)arg);
  193. break;
  194. case MDSS_EVENT_DSI_DYNAMIC_SWITCH:
  195. rc = dsi_update_pconfig(pdata, (int)(unsigned long) arg);
  196. break;
  197. #if defined(CONFIG_MDSS_DSI_EVENT_HANDLER_PANEL)
  198. case MDSS_EVENT_FB_REGISTERED:
  199. if (ctrl_pdata->registered) {
  200. pr_debug("%s:event=%d, calling panel registered callback \n",
  201. __func__, event);
  202. rc = ctrl_pdata->registered(pdata);
  203. /*
  204. * Okay, since framebuffer is registered, display the kernel logo if needed
  205. */
  206. }
  207. break;
  208. default:
  209. if(ctrl_pdata->event_handler) {
  210. rc = ctrl_pdata->event_handler(event);
  211. } else {
  212. pr_err("%s: unhandled event=%d\n", __func__, event);
  213. }
  214. break;
  215. #else
  216. default:
  217. pr_debug("%s: unhandled event=%d\n", __func__, event);
  218. break;
  219. #endif
  220. }
  221. return rc;
  222. }
  223. static int dsi_parse_gpio(struct platform_device *pdev,
  224. struct mdss_dsi_ctrl_pdata *ctrl_pdata)
  225. {
  226. struct device_node *np = pdev->dev.of_node;
  227. ctrl_pdata->disp_en_gpio = of_get_named_gpio(np,
  228. "qcom,platform-enable-gpio", 0);
  229. if (!gpio_is_valid(ctrl_pdata->disp_en_gpio))
  230. pr_err("%s:%d, Disp_en gpio not specified\n",
  231. __func__, __LINE__);
  232. ctrl_pdata->disp_te_gpio = -1;
  233. if (ctrl_pdata->panel_data.panel_info.mipi.mode == DSI_CMD_MODE ||
  234. ctrl_pdata->panel_data.panel_info.mipi.dynamic_switch_enabled) {
  235. ctrl_pdata->disp_te_gpio = of_get_named_gpio(np,
  236. "qcom,platform-te-gpio", 0);
  237. if (!gpio_is_valid(ctrl_pdata->disp_te_gpio))
  238. pr_err("%s:%d, Disp_te gpio not specified\n",
  239. __func__, __LINE__);
  240. }
  241. ctrl_pdata->rst_gpio = of_get_named_gpio(np,
  242. "qcom,platform-reset-gpio", 0);
  243. if (!gpio_is_valid(ctrl_pdata->rst_gpio))
  244. pr_err("%s:%d, reset gpio not specified\n",
  245. __func__, __LINE__);
  246. ctrl_pdata->mode_gpio = -1;
  247. if (ctrl_pdata->panel_data.panel_info.mode_gpio_state !=
  248. MODE_GPIO_NOT_VALID) {
  249. ctrl_pdata->mode_gpio = of_get_named_gpio(np,
  250. "qcom,platform-mode-gpio", 0);
  251. if (!gpio_is_valid(ctrl_pdata->mode_gpio))
  252. pr_info("%s:%d, reset gpio not specified\n",
  253. __func__, __LINE__);
  254. }
  255. return 0;
  256. }
  257. void dsi_ctrl_config_deinit(struct platform_device *pdev,
  258. struct mdss_dsi_ctrl_pdata *ctrl_pdata)
  259. {
  260. struct dss_module_power *module_power = &(ctrl_pdata->power_data);
  261. if (!module_power) {
  262. pr_err("%s: invalid input\n", __func__);
  263. return;
  264. }
  265. if (module_power->vreg_config) {
  266. devm_kfree(&(pdev->dev), module_power->vreg_config);
  267. module_power->vreg_config = NULL;
  268. }
  269. module_power->num_vreg = 0;
  270. }
  271. int dsi_ctrl_gpio_request(struct mdss_dsi_ctrl_pdata *ctrl_pdata)
  272. {
  273. int rc = 0;
  274. if (gpio_is_valid(ctrl_pdata->disp_te_gpio)) {
  275. rc = gpio_request(ctrl_pdata->disp_te_gpio, "disp_te");
  276. if (rc)
  277. ctrl_pdata->disp_te_gpio_requested = 0;
  278. else
  279. ctrl_pdata->disp_te_gpio_requested = 1;
  280. }
  281. return rc;
  282. }
  283. void dsi_ctrl_gpio_free(struct mdss_dsi_ctrl_pdata *ctrl_pdata)
  284. {
  285. if (ctrl_pdata->disp_te_gpio_requested) {
  286. gpio_free(ctrl_pdata->disp_te_gpio);
  287. ctrl_pdata->disp_te_gpio_requested = 0;
  288. }
  289. }
  290. static int dsi_parse_vreg(struct device *dev, struct dss_module_power *mp)
  291. {
  292. int i = 0, rc = 0;
  293. u32 tmp = 0;
  294. struct device_node *supply_node = NULL;
  295. struct device_node *np = NULL;
  296. if (!dev || !mp) {
  297. pr_err("%s: invalid input\n", __func__);
  298. rc = -EINVAL;
  299. return rc;
  300. }
  301. np = dev->of_node;
  302. mp->num_vreg = 0;
  303. for_each_child_of_node(np, supply_node) {
  304. if (!strncmp(supply_node->name, "qcom,platform-supply-entry",
  305. strlen("qcom,platform-supply-entry")))
  306. ++mp->num_vreg;
  307. }
  308. if (mp->num_vreg == 0) {
  309. pr_err("%s: no vreg\n", __func__);
  310. goto novreg;
  311. } else {
  312. pr_debug("%s: vreg found. count=%d\n", __func__, mp->num_vreg);
  313. }
  314. mp->vreg_config = devm_kzalloc(dev, sizeof(struct dss_vreg) *
  315. mp->num_vreg, GFP_KERNEL);
  316. if (!mp->vreg_config) {
  317. pr_err("%s: can't alloc vreg mem\n", __func__);
  318. rc = -ENOMEM;
  319. goto error;
  320. }
  321. for_each_child_of_node(np, supply_node) {
  322. if (!strncmp(supply_node->name, "qcom,platform-supply-entry",
  323. strlen("qcom,platform-supply-entry"))) {
  324. const char *st = NULL;
  325. /* vreg-name */
  326. rc = of_property_read_string(supply_node,
  327. "qcom,supply-name", &st);
  328. if (rc) {
  329. pr_err("%s: error reading name. rc=%d\n",
  330. __func__, rc);
  331. goto error;
  332. }
  333. strlcpy(mp->vreg_config[i].vreg_name, st,
  334. sizeof(mp->vreg_config[i].vreg_name));
  335. /* vreg-min-voltage */
  336. rc = of_property_read_u32(supply_node,
  337. "qcom,supply-min-voltage", &tmp);
  338. if (rc) {
  339. pr_err("%s: error reading min volt. rc=%d\n",
  340. __func__, rc);
  341. goto error;
  342. }
  343. mp->vreg_config[i].min_voltage = tmp;
  344. /* vreg-max-voltage */
  345. rc = of_property_read_u32(supply_node,
  346. "qcom,supply-max-voltage", &tmp);
  347. if (rc) {
  348. pr_err("%s: error reading max volt. rc=%d\n",
  349. __func__, rc);
  350. goto error;
  351. }
  352. mp->vreg_config[i].max_voltage = tmp;
  353. /* enable-load */
  354. rc = of_property_read_u32(supply_node,
  355. "qcom,supply-enable-load", &tmp);
  356. if (rc) {
  357. pr_err("%s: error reading enable load. rc=%d\n",
  358. __func__, rc);
  359. goto error;
  360. }
  361. mp->vreg_config[i].enable_load = tmp;
  362. /* disable-load */
  363. rc = of_property_read_u32(supply_node,
  364. "qcom,supply-disable-load", &tmp);
  365. if (rc) {
  366. pr_err("%s: error reading disable load. rc=%d\n",
  367. __func__, rc);
  368. goto error;
  369. }
  370. mp->vreg_config[i].disable_load = tmp;
  371. /* pre-sleep */
  372. rc = of_property_read_u32(supply_node,
  373. "qcom,supply-pre-on-sleep", &tmp);
  374. if (rc) {
  375. pr_debug("%s: error reading supply pre sleep value. rc=%d\n",
  376. __func__, rc);
  377. }
  378. mp->vreg_config[i].pre_on_sleep = (!rc ? tmp : 0);
  379. rc = of_property_read_u32(supply_node,
  380. "qcom,supply-pre-off-sleep", &tmp);
  381. if (rc) {
  382. pr_debug("%s: error reading supply pre sleep value. rc=%d\n",
  383. __func__, rc);
  384. }
  385. mp->vreg_config[i].pre_off_sleep = (!rc ? tmp : 0);
  386. /* post-sleep */
  387. rc = of_property_read_u32(supply_node,
  388. "qcom,supply-post-on-sleep", &tmp);
  389. if (rc) {
  390. pr_debug("%s: error reading supply post sleep value. rc=%d\n",
  391. __func__, rc);
  392. }
  393. mp->vreg_config[i].post_on_sleep = (!rc ? tmp : 0);
  394. rc = of_property_read_u32(supply_node,
  395. "qcom,supply-post-off-sleep", &tmp);
  396. if (rc) {
  397. pr_debug("%s: error reading supply post sleep value. rc=%d\n",
  398. __func__, rc);
  399. }
  400. mp->vreg_config[i].post_off_sleep = (!rc ? tmp : 0);
  401. pr_debug("%s: %s min=%d, max=%d, enable=%d, disable=%d, preonsleep=%d, postonsleep=%d, preoffsleep=%d, postoffsleep=%d\n",
  402. __func__,
  403. mp->vreg_config[i].vreg_name,
  404. mp->vreg_config[i].min_voltage,
  405. mp->vreg_config[i].max_voltage,
  406. mp->vreg_config[i].enable_load,
  407. mp->vreg_config[i].disable_load,
  408. mp->vreg_config[i].pre_on_sleep,
  409. mp->vreg_config[i].post_on_sleep,
  410. mp->vreg_config[i].pre_off_sleep,
  411. mp->vreg_config[i].post_off_sleep
  412. );
  413. ++i;
  414. }
  415. }
  416. return 0;
  417. error:
  418. if (mp->vreg_config) {
  419. devm_kfree(dev, mp->vreg_config);
  420. mp->vreg_config = NULL;
  421. }
  422. novreg:
  423. mp->num_vreg = 0;
  424. return rc;
  425. }
  426. static int dsi_parse_phy(struct platform_device *pdev,
  427. struct mdss_dsi_ctrl_pdata *ctrl_pdata)
  428. {
  429. struct device_node *np = pdev->dev.of_node;
  430. int i, len;
  431. const char *data;
  432. struct mdss_dsi_phy_ctrl *phy_db
  433. = &(ctrl_pdata->panel_data.panel_info.mipi.dsi_phy_db);
  434. data = of_get_property(np, "qcom,platform-regulator-settings", &len);
  435. if ((!data) || (len != 6)) {
  436. pr_err("%s:%d, Unable to read Phy regulator settings",
  437. __func__, __LINE__);
  438. return -EINVAL;
  439. }
  440. for (i = 0; i < len; i++)
  441. phy_db->regulator[i] = data[i];
  442. data = of_get_property(np, "qcom,platform-strength-ctrl", &len);
  443. if ((!data) || (len != 2)) {
  444. pr_err("%s:%d, Unable to read Phy Strength ctrl settings",
  445. __func__, __LINE__);
  446. return -EINVAL;
  447. }
  448. phy_db->strength[0] = data[0];
  449. phy_db->strength[1] = data[1];
  450. data = of_get_property(np, "qcom,platform-bist-ctrl", &len);
  451. if ((!data) || (len != 6)) {
  452. pr_err("%s:%d, Unable to read Phy Bist Ctrl settings",
  453. __func__, __LINE__);
  454. return -EINVAL;
  455. }
  456. for (i = 0; i < len; i++)
  457. phy_db->bistctrl[i] = data[i];
  458. data = of_get_property(np, "qcom,platform-lane-config", &len);
  459. if ((!data) || (len != 30)) {
  460. pr_err("%s:%d, Unable to read Phy lane configure settings",
  461. __func__, __LINE__);
  462. return -EINVAL;
  463. }
  464. for (i = 0; i < len; i++)
  465. phy_db->lanecfg[i] = data[i];
  466. return 0;
  467. }
  468. int dsi_ctrl_config_init(struct platform_device *pdev,
  469. struct mdss_dsi_ctrl_pdata *ctrl_pdata)
  470. {
  471. int rc;
  472. rc = dsi_parse_vreg(&pdev->dev, &ctrl_pdata->power_data);
  473. if (rc) {
  474. pr_err("%s:%d unable to get the regulator resources",
  475. __func__, __LINE__);
  476. return rc;
  477. }
  478. rc = dsi_parse_gpio(pdev, ctrl_pdata);
  479. if (rc) {
  480. pr_err("fail to parse panel GPIOs\n");
  481. return rc;
  482. }
  483. rc = dsi_parse_phy(pdev, ctrl_pdata);
  484. if (rc) {
  485. pr_err("fail to parse DSI PHY settings\n");
  486. return rc;
  487. }
  488. return 0;
  489. }
  490. int dsi_panel_device_register_v2(struct platform_device *dev,
  491. struct mdss_dsi_ctrl_pdata *ctrl_pdata)
  492. {
  493. struct mipi_panel_info *mipi;
  494. int rc;
  495. u8 lanes = 0, bpp;
  496. u32 h_period, v_period;
  497. struct mdss_panel_info *pinfo = &(ctrl_pdata->panel_data.panel_info);
  498. h_period = ((pinfo->lcdc.h_pulse_width)
  499. + (pinfo->lcdc.h_back_porch)
  500. + (pinfo->xres)
  501. + (pinfo->lcdc.h_front_porch));
  502. v_period = ((pinfo->lcdc.v_pulse_width)
  503. + (pinfo->lcdc.v_back_porch)
  504. + (pinfo->yres)
  505. + (pinfo->lcdc.v_front_porch));
  506. mipi = &pinfo->mipi;
  507. pinfo->type =
  508. ((mipi->mode == DSI_VIDEO_MODE)
  509. ? MIPI_VIDEO_PANEL : MIPI_CMD_PANEL);
  510. if (mipi->data_lane3)
  511. lanes += 1;
  512. if (mipi->data_lane2)
  513. lanes += 1;
  514. if (mipi->data_lane1)
  515. lanes += 1;
  516. if (mipi->data_lane0)
  517. lanes += 1;
  518. if ((mipi->dst_format == DSI_CMD_DST_FORMAT_RGB888)
  519. || (mipi->dst_format == DSI_VIDEO_DST_FORMAT_RGB888)
  520. || (mipi->dst_format == DSI_VIDEO_DST_FORMAT_RGB666_LOOSE))
  521. bpp = 3;
  522. else if ((mipi->dst_format == DSI_CMD_DST_FORMAT_RGB565)
  523. || (mipi->dst_format == DSI_VIDEO_DST_FORMAT_RGB565))
  524. bpp = 2;
  525. else
  526. bpp = 3; /* Default format set to RGB888 */
  527. if (pinfo->type == MIPI_VIDEO_PANEL &&
  528. !pinfo->clk_rate) {
  529. h_period += pinfo->lcdc.xres_pad;
  530. v_period += pinfo->lcdc.yres_pad;
  531. if (lanes > 0) {
  532. pinfo->clk_rate =
  533. ((h_period * v_period * (mipi->frame_rate) * bpp * 8)
  534. / lanes);
  535. } else {
  536. pr_err("%s: forcing mdss_dsi lanes to 1\n", __func__);
  537. pinfo->clk_rate =
  538. (h_period * v_period
  539. * (mipi->frame_rate) * bpp * 8);
  540. }
  541. }
  542. ctrl_pdata->panel_data.event_handler = dsi_event_handler;
  543. /*
  544. * register in mdp driver
  545. */
  546. rc = mdss_register_panel(dev, &(ctrl_pdata->panel_data));
  547. if (rc) {
  548. dev_err(&dev->dev, "unable to register MIPI DSI panel\n");
  549. return rc;
  550. }
  551. pr_debug("%s: Panal data initialized\n", __func__);
  552. return 0;
  553. }
  554. void dsi_register_interface(struct dsi_interface *intf)
  555. {
  556. dsi_intf = *intf;
  557. }
  558. int dsi_buf_alloc(struct dsi_buf *dp, int size)
  559. {
  560. dp->start = kmalloc(size, GFP_KERNEL);
  561. if (dp->start == NULL) {
  562. pr_err("%s:%u\n", __func__, __LINE__);
  563. return -ENOMEM;
  564. }
  565. dp->end = dp->start + size;
  566. dp->size = size;
  567. if ((int)dp->start & 0x07) {
  568. pr_err("%s: buf NOT 8 bytes aligned\n", __func__);
  569. return -EINVAL;
  570. }
  571. dp->data = dp->start;
  572. dp->len = 0;
  573. return 0;
  574. }