dpi.c 16 KB

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