dpi.c 19 KB

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