dpi.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  1. /*
  2. * linux/drivers/video/omap2/dss/dpi.c
  3. *
  4. * Copyright (C) 2009 Nokia Corporation
  5. * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
  6. *
  7. * Some code and ideas taken from drivers/video/omap/ driver
  8. * by Imre Deak.
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License version 2 as published by
  12. * the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  17. * more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along with
  20. * this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. #define DSS_SUBSYS_NAME "DPI"
  23. #include <linux/kernel.h>
  24. #include <linux/delay.h>
  25. #include <linux/export.h>
  26. #include <linux/err.h>
  27. #include <linux/errno.h>
  28. #include <linux/platform_device.h>
  29. #include <linux/regulator/consumer.h>
  30. #include <linux/string.h>
  31. #include <linux/of.h>
  32. #include <linux/clk.h>
  33. #include <video/omapdss.h>
  34. #include "dss.h"
  35. #include "dss_features.h"
  36. #define HSDIV_DISPC 0
  37. struct dpi_data {
  38. struct platform_device *pdev;
  39. struct regulator *vdds_dsi_reg;
  40. struct dss_pll *pll;
  41. struct mutex lock;
  42. struct omap_video_timings timings;
  43. struct dss_lcd_mgr_config mgr_config;
  44. int data_lines;
  45. struct omap_dss_device output;
  46. bool port_initialized;
  47. };
  48. static struct dpi_data *dpi_get_data_from_dssdev(struct omap_dss_device *dssdev)
  49. {
  50. return container_of(dssdev, struct dpi_data, output);
  51. }
  52. /* only used in non-DT mode */
  53. static struct dpi_data *dpi_get_data_from_pdev(struct platform_device *pdev)
  54. {
  55. return dev_get_drvdata(&pdev->dev);
  56. }
  57. static struct dss_pll *dpi_get_pll(enum omap_channel channel)
  58. {
  59. /*
  60. * XXX we can't currently use DSI PLL for DPI with OMAP3, as the DSI PLL
  61. * would also be used for DISPC fclk. Meaning, when the DPI output is
  62. * disabled, DISPC clock will be disabled, and TV out will stop.
  63. */
  64. switch (omapdss_get_version()) {
  65. case OMAPDSS_VER_OMAP24xx:
  66. case OMAPDSS_VER_OMAP34xx_ES1:
  67. case OMAPDSS_VER_OMAP34xx_ES3:
  68. case OMAPDSS_VER_OMAP3630:
  69. case OMAPDSS_VER_AM35xx:
  70. case OMAPDSS_VER_AM43xx:
  71. return NULL;
  72. case OMAPDSS_VER_OMAP4430_ES1:
  73. case OMAPDSS_VER_OMAP4430_ES2:
  74. case OMAPDSS_VER_OMAP4:
  75. switch (channel) {
  76. case OMAP_DSS_CHANNEL_LCD:
  77. return dss_pll_find("dsi0");
  78. case OMAP_DSS_CHANNEL_LCD2:
  79. return dss_pll_find("dsi1");
  80. default:
  81. return NULL;
  82. }
  83. case OMAPDSS_VER_OMAP5:
  84. switch (channel) {
  85. case OMAP_DSS_CHANNEL_LCD:
  86. return dss_pll_find("dsi0");
  87. case OMAP_DSS_CHANNEL_LCD3:
  88. return dss_pll_find("dsi1");
  89. default:
  90. return NULL;
  91. }
  92. default:
  93. return NULL;
  94. }
  95. }
  96. static enum omap_dss_clk_source dpi_get_alt_clk_src(enum omap_channel channel)
  97. {
  98. switch (channel) {
  99. case OMAP_DSS_CHANNEL_LCD:
  100. return OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC;
  101. case OMAP_DSS_CHANNEL_LCD2:
  102. return OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC;
  103. case OMAP_DSS_CHANNEL_LCD3:
  104. return OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC;
  105. default:
  106. /* this shouldn't happen */
  107. WARN_ON(1);
  108. return OMAP_DSS_CLK_SRC_FCK;
  109. }
  110. }
  111. struct dpi_clk_calc_ctx {
  112. struct dss_pll *pll;
  113. /* inputs */
  114. unsigned long pck_min, pck_max;
  115. /* outputs */
  116. struct dss_pll_clock_info dsi_cinfo;
  117. unsigned long fck;
  118. struct dispc_clock_info dispc_cinfo;
  119. };
  120. static bool dpi_calc_dispc_cb(int lckd, int pckd, unsigned long lck,
  121. unsigned long pck, void *data)
  122. {
  123. struct dpi_clk_calc_ctx *ctx = data;
  124. /*
  125. * Odd dividers give us uneven duty cycle, causing problem when level
  126. * shifted. So skip all odd dividers when the pixel clock is on the
  127. * higher side.
  128. */
  129. if (ctx->pck_min >= 100000000) {
  130. if (lckd > 1 && lckd % 2 != 0)
  131. return false;
  132. if (pckd > 1 && pckd % 2 != 0)
  133. return false;
  134. }
  135. ctx->dispc_cinfo.lck_div = lckd;
  136. ctx->dispc_cinfo.pck_div = pckd;
  137. ctx->dispc_cinfo.lck = lck;
  138. ctx->dispc_cinfo.pck = pck;
  139. return true;
  140. }
  141. static bool dpi_calc_hsdiv_cb(int m_dispc, unsigned long dispc,
  142. void *data)
  143. {
  144. struct dpi_clk_calc_ctx *ctx = data;
  145. /*
  146. * Odd dividers give us uneven duty cycle, causing problem when level
  147. * shifted. So skip all odd dividers when the pixel clock is on the
  148. * higher side.
  149. */
  150. if (m_dispc > 1 && m_dispc % 2 != 0 && ctx->pck_min >= 100000000)
  151. return false;
  152. ctx->dsi_cinfo.mX[HSDIV_DISPC] = m_dispc;
  153. ctx->dsi_cinfo.clkout[HSDIV_DISPC] = dispc;
  154. return dispc_div_calc(dispc, ctx->pck_min, ctx->pck_max,
  155. dpi_calc_dispc_cb, ctx);
  156. }
  157. static bool dpi_calc_pll_cb(int n, int m, unsigned long fint,
  158. unsigned long clkdco,
  159. void *data)
  160. {
  161. struct dpi_clk_calc_ctx *ctx = data;
  162. ctx->dsi_cinfo.n = n;
  163. ctx->dsi_cinfo.m = m;
  164. ctx->dsi_cinfo.fint = fint;
  165. ctx->dsi_cinfo.clkdco = clkdco;
  166. return dss_pll_hsdiv_calc(ctx->pll, clkdco,
  167. ctx->pck_min, dss_feat_get_param_max(FEAT_PARAM_DSS_FCK),
  168. dpi_calc_hsdiv_cb, ctx);
  169. }
  170. static bool dpi_calc_dss_cb(unsigned long fck, void *data)
  171. {
  172. struct dpi_clk_calc_ctx *ctx = data;
  173. ctx->fck = fck;
  174. return dispc_div_calc(fck, ctx->pck_min, ctx->pck_max,
  175. dpi_calc_dispc_cb, ctx);
  176. }
  177. static bool dpi_dsi_clk_calc(struct dpi_data *dpi, unsigned long pck,
  178. struct dpi_clk_calc_ctx *ctx)
  179. {
  180. unsigned long clkin;
  181. unsigned long pll_min, pll_max;
  182. memset(ctx, 0, sizeof(*ctx));
  183. ctx->pll = dpi->pll;
  184. ctx->pck_min = pck - 1000;
  185. ctx->pck_max = pck + 1000;
  186. pll_min = 0;
  187. pll_max = 0;
  188. clkin = clk_get_rate(ctx->pll->clkin);
  189. return dss_pll_calc(ctx->pll, clkin,
  190. pll_min, pll_max,
  191. dpi_calc_pll_cb, ctx);
  192. }
  193. static bool dpi_dss_clk_calc(unsigned long pck, struct dpi_clk_calc_ctx *ctx)
  194. {
  195. int i;
  196. /*
  197. * DSS fck gives us very few possibilities, so finding a good pixel
  198. * clock may not be possible. We try multiple times to find the clock,
  199. * each time widening the pixel clock range we look for, up to
  200. * +/- ~15MHz.
  201. */
  202. for (i = 0; i < 25; ++i) {
  203. bool ok;
  204. memset(ctx, 0, sizeof(*ctx));
  205. if (pck > 1000 * i * i * i)
  206. ctx->pck_min = max(pck - 1000 * i * i * i, 0lu);
  207. else
  208. ctx->pck_min = 0;
  209. ctx->pck_max = pck + 1000 * i * i * i;
  210. ok = dss_div_calc(pck, ctx->pck_min, dpi_calc_dss_cb, ctx);
  211. if (ok)
  212. return ok;
  213. }
  214. return false;
  215. }
  216. static int dpi_set_dsi_clk(struct dpi_data *dpi, enum omap_channel channel,
  217. unsigned long pck_req, unsigned long *fck, int *lck_div,
  218. int *pck_div)
  219. {
  220. struct dpi_clk_calc_ctx ctx;
  221. int r;
  222. bool ok;
  223. ok = dpi_dsi_clk_calc(dpi, pck_req, &ctx);
  224. if (!ok)
  225. return -EINVAL;
  226. r = dss_pll_set_config(dpi->pll, &ctx.dsi_cinfo);
  227. if (r)
  228. return r;
  229. dss_select_lcd_clk_source(channel,
  230. dpi_get_alt_clk_src(channel));
  231. dpi->mgr_config.clock_info = ctx.dispc_cinfo;
  232. *fck = ctx.dsi_cinfo.clkout[HSDIV_DISPC];
  233. *lck_div = ctx.dispc_cinfo.lck_div;
  234. *pck_div = ctx.dispc_cinfo.pck_div;
  235. return 0;
  236. }
  237. static int dpi_set_dispc_clk(struct dpi_data *dpi, unsigned long pck_req,
  238. unsigned long *fck, int *lck_div, int *pck_div)
  239. {
  240. struct dpi_clk_calc_ctx ctx;
  241. int r;
  242. bool ok;
  243. ok = dpi_dss_clk_calc(pck_req, &ctx);
  244. if (!ok)
  245. return -EINVAL;
  246. r = dss_set_fck_rate(ctx.fck);
  247. if (r)
  248. return r;
  249. dpi->mgr_config.clock_info = ctx.dispc_cinfo;
  250. *fck = ctx.fck;
  251. *lck_div = ctx.dispc_cinfo.lck_div;
  252. *pck_div = ctx.dispc_cinfo.pck_div;
  253. return 0;
  254. }
  255. static int dpi_set_mode(struct dpi_data *dpi)
  256. {
  257. struct omap_dss_device *out = &dpi->output;
  258. struct omap_overlay_manager *mgr = out->manager;
  259. struct omap_video_timings *t = &dpi->timings;
  260. int lck_div = 0, pck_div = 0;
  261. unsigned long fck = 0;
  262. unsigned long pck;
  263. int r = 0;
  264. if (dpi->pll)
  265. r = dpi_set_dsi_clk(dpi, mgr->id, t->pixelclock, &fck,
  266. &lck_div, &pck_div);
  267. else
  268. r = dpi_set_dispc_clk(dpi, t->pixelclock, &fck,
  269. &lck_div, &pck_div);
  270. if (r)
  271. return r;
  272. pck = fck / lck_div / pck_div;
  273. if (pck != t->pixelclock) {
  274. DSSWARN("Could not find exact pixel clock. Requested %d Hz, got %lu Hz\n",
  275. t->pixelclock, pck);
  276. t->pixelclock = pck;
  277. }
  278. dss_mgr_set_timings(mgr, t);
  279. return 0;
  280. }
  281. static void dpi_config_lcd_manager(struct dpi_data *dpi)
  282. {
  283. struct omap_dss_device *out = &dpi->output;
  284. struct omap_overlay_manager *mgr = out->manager;
  285. dpi->mgr_config.io_pad_mode = DSS_IO_PAD_MODE_BYPASS;
  286. dpi->mgr_config.stallmode = false;
  287. dpi->mgr_config.fifohandcheck = false;
  288. dpi->mgr_config.video_port_width = dpi->data_lines;
  289. dpi->mgr_config.lcden_sig_polarity = 0;
  290. dss_mgr_set_lcd_config(mgr, &dpi->mgr_config);
  291. }
  292. static int dpi_display_enable(struct omap_dss_device *dssdev)
  293. {
  294. struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
  295. struct omap_dss_device *out = &dpi->output;
  296. int r;
  297. mutex_lock(&dpi->lock);
  298. if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI) && !dpi->vdds_dsi_reg) {
  299. DSSERR("no VDSS_DSI regulator\n");
  300. r = -ENODEV;
  301. goto err_no_reg;
  302. }
  303. if (out == NULL || out->manager == NULL) {
  304. DSSERR("failed to enable display: no output/manager\n");
  305. r = -ENODEV;
  306. goto err_no_out_mgr;
  307. }
  308. if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI)) {
  309. r = regulator_enable(dpi->vdds_dsi_reg);
  310. if (r)
  311. goto err_reg_enable;
  312. }
  313. r = dispc_runtime_get();
  314. if (r)
  315. goto err_get_dispc;
  316. r = dss_dpi_select_source(out->port_num, out->manager->id);
  317. if (r)
  318. goto err_src_sel;
  319. if (dpi->pll) {
  320. r = dss_pll_enable(dpi->pll);
  321. if (r)
  322. goto err_dsi_pll_init;
  323. }
  324. r = dpi_set_mode(dpi);
  325. if (r)
  326. goto err_set_mode;
  327. dpi_config_lcd_manager(dpi);
  328. mdelay(2);
  329. r = dss_mgr_enable(out->manager);
  330. if (r)
  331. goto err_mgr_enable;
  332. mutex_unlock(&dpi->lock);
  333. return 0;
  334. err_mgr_enable:
  335. err_set_mode:
  336. if (dpi->pll)
  337. dss_pll_disable(dpi->pll);
  338. err_dsi_pll_init:
  339. err_src_sel:
  340. dispc_runtime_put();
  341. err_get_dispc:
  342. if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI))
  343. regulator_disable(dpi->vdds_dsi_reg);
  344. err_reg_enable:
  345. err_no_out_mgr:
  346. err_no_reg:
  347. mutex_unlock(&dpi->lock);
  348. return r;
  349. }
  350. static void dpi_display_disable(struct omap_dss_device *dssdev)
  351. {
  352. struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
  353. struct omap_overlay_manager *mgr = dpi->output.manager;
  354. mutex_lock(&dpi->lock);
  355. dss_mgr_disable(mgr);
  356. if (dpi->pll) {
  357. dss_select_lcd_clk_source(mgr->id, OMAP_DSS_CLK_SRC_FCK);
  358. dss_pll_disable(dpi->pll);
  359. }
  360. dispc_runtime_put();
  361. if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI))
  362. regulator_disable(dpi->vdds_dsi_reg);
  363. mutex_unlock(&dpi->lock);
  364. }
  365. static void dpi_set_timings(struct omap_dss_device *dssdev,
  366. struct omap_video_timings *timings)
  367. {
  368. struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
  369. DSSDBG("dpi_set_timings\n");
  370. mutex_lock(&dpi->lock);
  371. dpi->timings = *timings;
  372. mutex_unlock(&dpi->lock);
  373. }
  374. static void dpi_get_timings(struct omap_dss_device *dssdev,
  375. struct omap_video_timings *timings)
  376. {
  377. struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
  378. mutex_lock(&dpi->lock);
  379. *timings = dpi->timings;
  380. mutex_unlock(&dpi->lock);
  381. }
  382. static int dpi_check_timings(struct omap_dss_device *dssdev,
  383. struct omap_video_timings *timings)
  384. {
  385. struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
  386. struct omap_overlay_manager *mgr = dpi->output.manager;
  387. int lck_div, pck_div;
  388. unsigned long fck;
  389. unsigned long pck;
  390. struct dpi_clk_calc_ctx ctx;
  391. bool ok;
  392. if (mgr && !dispc_mgr_timings_ok(mgr->id, timings))
  393. return -EINVAL;
  394. if (timings->pixelclock == 0)
  395. return -EINVAL;
  396. if (dpi->pll) {
  397. ok = dpi_dsi_clk_calc(dpi, timings->pixelclock, &ctx);
  398. if (!ok)
  399. return -EINVAL;
  400. fck = ctx.dsi_cinfo.clkout[HSDIV_DISPC];
  401. } else {
  402. ok = dpi_dss_clk_calc(timings->pixelclock, &ctx);
  403. if (!ok)
  404. return -EINVAL;
  405. fck = ctx.fck;
  406. }
  407. lck_div = ctx.dispc_cinfo.lck_div;
  408. pck_div = ctx.dispc_cinfo.pck_div;
  409. pck = fck / lck_div / pck_div;
  410. timings->pixelclock = pck;
  411. return 0;
  412. }
  413. static void dpi_set_data_lines(struct omap_dss_device *dssdev, int data_lines)
  414. {
  415. struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
  416. mutex_lock(&dpi->lock);
  417. dpi->data_lines = data_lines;
  418. mutex_unlock(&dpi->lock);
  419. }
  420. static int dpi_verify_dsi_pll(struct dss_pll *pll)
  421. {
  422. int r;
  423. /* do initial setup with the PLL to see if it is operational */
  424. r = dss_pll_enable(pll);
  425. if (r)
  426. return r;
  427. dss_pll_disable(pll);
  428. return 0;
  429. }
  430. static int dpi_init_regulator(struct dpi_data *dpi)
  431. {
  432. struct regulator *vdds_dsi;
  433. if (!dss_has_feature(FEAT_DPI_USES_VDDS_DSI))
  434. return 0;
  435. if (dpi->vdds_dsi_reg)
  436. return 0;
  437. vdds_dsi = devm_regulator_get(&dpi->pdev->dev, "vdds_dsi");
  438. if (IS_ERR(vdds_dsi)) {
  439. if (PTR_ERR(vdds_dsi) != -EPROBE_DEFER)
  440. DSSERR("can't get VDDS_DSI regulator\n");
  441. return PTR_ERR(vdds_dsi);
  442. }
  443. dpi->vdds_dsi_reg = vdds_dsi;
  444. return 0;
  445. }
  446. static void dpi_init_pll(struct dpi_data *dpi)
  447. {
  448. struct dss_pll *pll;
  449. if (dpi->pll)
  450. return;
  451. pll = dpi_get_pll(dpi->output.dispc_channel);
  452. if (!pll)
  453. return;
  454. if (dpi_verify_dsi_pll(pll)) {
  455. DSSWARN("DSI PLL not operational\n");
  456. return;
  457. }
  458. dpi->pll = pll;
  459. }
  460. /*
  461. * Return a hardcoded channel for the DPI output. This should work for
  462. * current use cases, but this can be later expanded to either resolve
  463. * the channel in some more dynamic manner, or get the channel as a user
  464. * parameter.
  465. */
  466. static enum omap_channel dpi_get_channel(int port_num)
  467. {
  468. switch (omapdss_get_version()) {
  469. case OMAPDSS_VER_OMAP24xx:
  470. case OMAPDSS_VER_OMAP34xx_ES1:
  471. case OMAPDSS_VER_OMAP34xx_ES3:
  472. case OMAPDSS_VER_OMAP3630:
  473. case OMAPDSS_VER_AM35xx:
  474. case OMAPDSS_VER_AM43xx:
  475. return OMAP_DSS_CHANNEL_LCD;
  476. case OMAPDSS_VER_OMAP4430_ES1:
  477. case OMAPDSS_VER_OMAP4430_ES2:
  478. case OMAPDSS_VER_OMAP4:
  479. return OMAP_DSS_CHANNEL_LCD2;
  480. case OMAPDSS_VER_OMAP5:
  481. return OMAP_DSS_CHANNEL_LCD3;
  482. default:
  483. DSSWARN("unsupported DSS version\n");
  484. return OMAP_DSS_CHANNEL_LCD;
  485. }
  486. }
  487. static int dpi_connect(struct omap_dss_device *dssdev,
  488. struct omap_dss_device *dst)
  489. {
  490. struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
  491. struct omap_overlay_manager *mgr;
  492. int r;
  493. r = dpi_init_regulator(dpi);
  494. if (r)
  495. return r;
  496. dpi_init_pll(dpi);
  497. mgr = omap_dss_get_overlay_manager(dssdev->dispc_channel);
  498. if (!mgr)
  499. return -ENODEV;
  500. r = dss_mgr_connect(mgr, dssdev);
  501. if (r)
  502. return r;
  503. r = omapdss_output_set_device(dssdev, dst);
  504. if (r) {
  505. DSSERR("failed to connect output to new device: %s\n",
  506. dst->name);
  507. dss_mgr_disconnect(mgr, dssdev);
  508. return r;
  509. }
  510. return 0;
  511. }
  512. static void dpi_disconnect(struct omap_dss_device *dssdev,
  513. struct omap_dss_device *dst)
  514. {
  515. WARN_ON(dst != dssdev->dst);
  516. if (dst != dssdev->dst)
  517. return;
  518. omapdss_output_unset_device(dssdev);
  519. if (dssdev->manager)
  520. dss_mgr_disconnect(dssdev->manager, dssdev);
  521. }
  522. static const struct omapdss_dpi_ops dpi_ops = {
  523. .connect = dpi_connect,
  524. .disconnect = dpi_disconnect,
  525. .enable = dpi_display_enable,
  526. .disable = dpi_display_disable,
  527. .check_timings = dpi_check_timings,
  528. .set_timings = dpi_set_timings,
  529. .get_timings = dpi_get_timings,
  530. .set_data_lines = dpi_set_data_lines,
  531. };
  532. static void dpi_init_output(struct platform_device *pdev)
  533. {
  534. struct dpi_data *dpi = dpi_get_data_from_pdev(pdev);
  535. struct omap_dss_device *out = &dpi->output;
  536. out->dev = &pdev->dev;
  537. out->id = OMAP_DSS_OUTPUT_DPI;
  538. out->output_type = OMAP_DISPLAY_TYPE_DPI;
  539. out->name = "dpi.0";
  540. out->dispc_channel = dpi_get_channel(0);
  541. out->ops.dpi = &dpi_ops;
  542. out->owner = THIS_MODULE;
  543. omapdss_register_output(out);
  544. }
  545. static void __exit dpi_uninit_output(struct platform_device *pdev)
  546. {
  547. struct dpi_data *dpi = dpi_get_data_from_pdev(pdev);
  548. struct omap_dss_device *out = &dpi->output;
  549. omapdss_unregister_output(out);
  550. }
  551. static void dpi_init_output_port(struct platform_device *pdev,
  552. struct device_node *port)
  553. {
  554. struct dpi_data *dpi = port->data;
  555. struct omap_dss_device *out = &dpi->output;
  556. int r;
  557. u32 port_num;
  558. r = of_property_read_u32(port, "reg", &port_num);
  559. if (r)
  560. port_num = 0;
  561. switch (port_num) {
  562. case 2:
  563. out->name = "dpi.2";
  564. break;
  565. case 1:
  566. out->name = "dpi.1";
  567. break;
  568. case 0:
  569. default:
  570. out->name = "dpi.0";
  571. break;
  572. }
  573. out->dev = &pdev->dev;
  574. out->id = OMAP_DSS_OUTPUT_DPI;
  575. out->output_type = OMAP_DISPLAY_TYPE_DPI;
  576. out->dispc_channel = dpi_get_channel(port_num);
  577. out->port_num = port_num;
  578. out->ops.dpi = &dpi_ops;
  579. out->owner = THIS_MODULE;
  580. omapdss_register_output(out);
  581. }
  582. static void __exit dpi_uninit_output_port(struct device_node *port)
  583. {
  584. struct dpi_data *dpi = port->data;
  585. struct omap_dss_device *out = &dpi->output;
  586. omapdss_unregister_output(out);
  587. }
  588. static int omap_dpi_probe(struct platform_device *pdev)
  589. {
  590. struct dpi_data *dpi;
  591. dpi = devm_kzalloc(&pdev->dev, sizeof(*dpi), GFP_KERNEL);
  592. if (!dpi)
  593. return -ENOMEM;
  594. dpi->pdev = pdev;
  595. dev_set_drvdata(&pdev->dev, dpi);
  596. mutex_init(&dpi->lock);
  597. dpi_init_output(pdev);
  598. return 0;
  599. }
  600. static int __exit omap_dpi_remove(struct platform_device *pdev)
  601. {
  602. dpi_uninit_output(pdev);
  603. return 0;
  604. }
  605. static struct platform_driver omap_dpi_driver = {
  606. .probe = omap_dpi_probe,
  607. .remove = __exit_p(omap_dpi_remove),
  608. .driver = {
  609. .name = "omapdss_dpi",
  610. .suppress_bind_attrs = true,
  611. },
  612. };
  613. int __init dpi_init_platform_driver(void)
  614. {
  615. return platform_driver_register(&omap_dpi_driver);
  616. }
  617. void __exit dpi_uninit_platform_driver(void)
  618. {
  619. platform_driver_unregister(&omap_dpi_driver);
  620. }
  621. int __init dpi_init_port(struct platform_device *pdev, struct device_node *port)
  622. {
  623. struct dpi_data *dpi;
  624. struct device_node *ep;
  625. u32 datalines;
  626. int r;
  627. dpi = devm_kzalloc(&pdev->dev, sizeof(*dpi), GFP_KERNEL);
  628. if (!dpi)
  629. return -ENOMEM;
  630. ep = omapdss_of_get_next_endpoint(port, NULL);
  631. if (!ep)
  632. return 0;
  633. r = of_property_read_u32(ep, "data-lines", &datalines);
  634. if (r) {
  635. DSSERR("failed to parse datalines\n");
  636. goto err_datalines;
  637. }
  638. dpi->data_lines = datalines;
  639. of_node_put(ep);
  640. dpi->pdev = pdev;
  641. port->data = dpi;
  642. mutex_init(&dpi->lock);
  643. dpi_init_output_port(pdev, port);
  644. dpi->port_initialized = true;
  645. return 0;
  646. err_datalines:
  647. of_node_put(ep);
  648. return r;
  649. }
  650. void __exit dpi_uninit_port(struct device_node *port)
  651. {
  652. struct dpi_data *dpi = port->data;
  653. if (!dpi->port_initialized)
  654. return;
  655. dpi_uninit_output_port(port);
  656. }