dpi.c 17 KB

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