dpi.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901
  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. enum omap_channel channel = out->dispc_channel;
  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, channel, 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(channel, 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. enum omap_channel channel = out->dispc_channel;
  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(channel, &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. enum omap_channel channel = out->dispc_channel;
  308. int r;
  309. mutex_lock(&dpi->lock);
  310. if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI) && !dpi->vdds_dsi_reg) {
  311. DSSERR("no VDSS_DSI regulator\n");
  312. r = -ENODEV;
  313. goto err_no_reg;
  314. }
  315. if (!out->dispc_channel_connected) {
  316. DSSERR("failed to enable display: no output/manager\n");
  317. r = -ENODEV;
  318. goto err_no_out_mgr;
  319. }
  320. if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI)) {
  321. r = regulator_enable(dpi->vdds_dsi_reg);
  322. if (r)
  323. goto err_reg_enable;
  324. }
  325. r = dispc_runtime_get();
  326. if (r)
  327. goto err_get_dispc;
  328. r = dss_dpi_select_source(out->port_num, channel);
  329. if (r)
  330. goto err_src_sel;
  331. if (dpi->pll) {
  332. r = dss_pll_enable(dpi->pll);
  333. if (r)
  334. goto err_dsi_pll_init;
  335. }
  336. r = dpi_set_mode(dpi);
  337. if (r)
  338. goto err_set_mode;
  339. dpi_config_lcd_manager(dpi);
  340. mdelay(2);
  341. r = dss_mgr_enable(channel);
  342. if (r)
  343. goto err_mgr_enable;
  344. mutex_unlock(&dpi->lock);
  345. return 0;
  346. err_mgr_enable:
  347. err_set_mode:
  348. if (dpi->pll)
  349. dss_pll_disable(dpi->pll);
  350. err_dsi_pll_init:
  351. err_src_sel:
  352. dispc_runtime_put();
  353. err_get_dispc:
  354. if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI))
  355. regulator_disable(dpi->vdds_dsi_reg);
  356. err_reg_enable:
  357. err_no_out_mgr:
  358. err_no_reg:
  359. mutex_unlock(&dpi->lock);
  360. return r;
  361. }
  362. static void dpi_display_disable(struct omap_dss_device *dssdev)
  363. {
  364. struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
  365. enum omap_channel channel = dpi->output.dispc_channel;
  366. mutex_lock(&dpi->lock);
  367. dss_mgr_disable(channel);
  368. if (dpi->pll) {
  369. dss_select_lcd_clk_source(channel, OMAP_DSS_CLK_SRC_FCK);
  370. dss_pll_disable(dpi->pll);
  371. }
  372. dispc_runtime_put();
  373. if (dss_has_feature(FEAT_DPI_USES_VDDS_DSI))
  374. regulator_disable(dpi->vdds_dsi_reg);
  375. mutex_unlock(&dpi->lock);
  376. }
  377. static void dpi_set_timings(struct omap_dss_device *dssdev,
  378. struct omap_video_timings *timings)
  379. {
  380. struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
  381. DSSDBG("dpi_set_timings\n");
  382. mutex_lock(&dpi->lock);
  383. dpi->timings = *timings;
  384. mutex_unlock(&dpi->lock);
  385. }
  386. static void dpi_get_timings(struct omap_dss_device *dssdev,
  387. struct omap_video_timings *timings)
  388. {
  389. struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
  390. mutex_lock(&dpi->lock);
  391. *timings = dpi->timings;
  392. mutex_unlock(&dpi->lock);
  393. }
  394. static int dpi_check_timings(struct omap_dss_device *dssdev,
  395. struct omap_video_timings *timings)
  396. {
  397. struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
  398. enum omap_channel channel = dpi->output.dispc_channel;
  399. int lck_div, pck_div;
  400. unsigned long fck;
  401. unsigned long pck;
  402. struct dpi_clk_calc_ctx ctx;
  403. bool ok;
  404. if (timings->x_res % 8 != 0)
  405. return -EINVAL;
  406. if (!dispc_mgr_timings_ok(channel, timings))
  407. return -EINVAL;
  408. if (timings->pixelclock == 0)
  409. return -EINVAL;
  410. if (dpi->pll) {
  411. ok = dpi_dsi_clk_calc(dpi, timings->pixelclock, &ctx);
  412. if (!ok)
  413. return -EINVAL;
  414. fck = ctx.dsi_cinfo.clkout[HSDIV_DISPC];
  415. } else {
  416. ok = dpi_dss_clk_calc(timings->pixelclock, &ctx);
  417. if (!ok)
  418. return -EINVAL;
  419. fck = ctx.fck;
  420. }
  421. lck_div = ctx.dispc_cinfo.lck_div;
  422. pck_div = ctx.dispc_cinfo.pck_div;
  423. pck = fck / lck_div / pck_div;
  424. timings->pixelclock = pck;
  425. return 0;
  426. }
  427. static void dpi_set_data_lines(struct omap_dss_device *dssdev, int data_lines)
  428. {
  429. struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
  430. mutex_lock(&dpi->lock);
  431. dpi->data_lines = data_lines;
  432. mutex_unlock(&dpi->lock);
  433. }
  434. static int dpi_verify_dsi_pll(struct dss_pll *pll)
  435. {
  436. int r;
  437. /* do initial setup with the PLL to see if it is operational */
  438. r = dss_pll_enable(pll);
  439. if (r)
  440. return r;
  441. dss_pll_disable(pll);
  442. return 0;
  443. }
  444. static int dpi_init_regulator(struct dpi_data *dpi)
  445. {
  446. struct regulator *vdds_dsi;
  447. if (!dss_has_feature(FEAT_DPI_USES_VDDS_DSI))
  448. return 0;
  449. if (dpi->vdds_dsi_reg)
  450. return 0;
  451. vdds_dsi = devm_regulator_get(&dpi->pdev->dev, "vdds_dsi");
  452. if (IS_ERR(vdds_dsi)) {
  453. if (PTR_ERR(vdds_dsi) != -EPROBE_DEFER)
  454. DSSERR("can't get VDDS_DSI regulator\n");
  455. return PTR_ERR(vdds_dsi);
  456. }
  457. dpi->vdds_dsi_reg = vdds_dsi;
  458. return 0;
  459. }
  460. static void dpi_init_pll(struct dpi_data *dpi)
  461. {
  462. struct dss_pll *pll;
  463. if (dpi->pll)
  464. return;
  465. pll = dpi_get_pll(dpi->output.dispc_channel);
  466. if (!pll)
  467. return;
  468. /* On DRA7 we need to set a mux to use the PLL */
  469. if (omapdss_get_version() == OMAPDSS_VER_DRA7xx)
  470. dss_ctrl_pll_set_control_mux(pll->id, dpi->output.dispc_channel);
  471. if (dpi_verify_dsi_pll(pll)) {
  472. DSSWARN("DSI PLL not operational\n");
  473. return;
  474. }
  475. dpi->pll = pll;
  476. }
  477. /*
  478. * Return a hardcoded channel for the DPI output. This should work for
  479. * current use cases, but this can be later expanded to either resolve
  480. * the channel in some more dynamic manner, or get the channel as a user
  481. * parameter.
  482. */
  483. static enum omap_channel dpi_get_channel(int port_num)
  484. {
  485. switch (omapdss_get_version()) {
  486. case OMAPDSS_VER_OMAP24xx:
  487. case OMAPDSS_VER_OMAP34xx_ES1:
  488. case OMAPDSS_VER_OMAP34xx_ES3:
  489. case OMAPDSS_VER_OMAP3630:
  490. case OMAPDSS_VER_AM35xx:
  491. case OMAPDSS_VER_AM43xx:
  492. return OMAP_DSS_CHANNEL_LCD;
  493. case OMAPDSS_VER_DRA7xx:
  494. switch (port_num) {
  495. case 2:
  496. return OMAP_DSS_CHANNEL_LCD3;
  497. case 1:
  498. return OMAP_DSS_CHANNEL_LCD2;
  499. case 0:
  500. default:
  501. return OMAP_DSS_CHANNEL_LCD;
  502. }
  503. case OMAPDSS_VER_OMAP4430_ES1:
  504. case OMAPDSS_VER_OMAP4430_ES2:
  505. case OMAPDSS_VER_OMAP4:
  506. return OMAP_DSS_CHANNEL_LCD2;
  507. case OMAPDSS_VER_OMAP5:
  508. return OMAP_DSS_CHANNEL_LCD3;
  509. default:
  510. DSSWARN("unsupported DSS version\n");
  511. return OMAP_DSS_CHANNEL_LCD;
  512. }
  513. }
  514. static int dpi_connect(struct omap_dss_device *dssdev,
  515. struct omap_dss_device *dst)
  516. {
  517. struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
  518. enum omap_channel channel = dpi->output.dispc_channel;
  519. int r;
  520. r = dpi_init_regulator(dpi);
  521. if (r)
  522. return r;
  523. dpi_init_pll(dpi);
  524. r = dss_mgr_connect(channel, 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(channel, 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. struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
  540. enum omap_channel channel = dpi->output.dispc_channel;
  541. WARN_ON(dst != dssdev->dst);
  542. if (dst != dssdev->dst)
  543. return;
  544. omapdss_output_unset_device(dssdev);
  545. dss_mgr_disconnect(channel, dssdev);
  546. }
  547. static const struct omapdss_dpi_ops dpi_ops = {
  548. .connect = dpi_connect,
  549. .disconnect = dpi_disconnect,
  550. .enable = dpi_display_enable,
  551. .disable = dpi_display_disable,
  552. .check_timings = dpi_check_timings,
  553. .set_timings = dpi_set_timings,
  554. .get_timings = dpi_get_timings,
  555. .set_data_lines = dpi_set_data_lines,
  556. };
  557. static void dpi_init_output(struct platform_device *pdev)
  558. {
  559. struct dpi_data *dpi = dpi_get_data_from_pdev(pdev);
  560. struct omap_dss_device *out = &dpi->output;
  561. out->dev = &pdev->dev;
  562. out->id = OMAP_DSS_OUTPUT_DPI;
  563. out->output_type = OMAP_DISPLAY_TYPE_DPI;
  564. out->name = "dpi.0";
  565. out->dispc_channel = dpi_get_channel(0);
  566. out->ops.dpi = &dpi_ops;
  567. out->owner = THIS_MODULE;
  568. omapdss_register_output(out);
  569. }
  570. static void dpi_uninit_output(struct platform_device *pdev)
  571. {
  572. struct dpi_data *dpi = dpi_get_data_from_pdev(pdev);
  573. struct omap_dss_device *out = &dpi->output;
  574. omapdss_unregister_output(out);
  575. }
  576. static void dpi_init_output_port(struct platform_device *pdev,
  577. struct device_node *port)
  578. {
  579. struct dpi_data *dpi = port->data;
  580. struct omap_dss_device *out = &dpi->output;
  581. int r;
  582. u32 port_num;
  583. r = of_property_read_u32(port, "reg", &port_num);
  584. if (r)
  585. port_num = 0;
  586. switch (port_num) {
  587. case 2:
  588. out->name = "dpi.2";
  589. break;
  590. case 1:
  591. out->name = "dpi.1";
  592. break;
  593. case 0:
  594. default:
  595. out->name = "dpi.0";
  596. break;
  597. }
  598. out->dev = &pdev->dev;
  599. out->id = OMAP_DSS_OUTPUT_DPI;
  600. out->output_type = OMAP_DISPLAY_TYPE_DPI;
  601. out->dispc_channel = dpi_get_channel(port_num);
  602. out->port_num = port_num;
  603. out->ops.dpi = &dpi_ops;
  604. out->owner = THIS_MODULE;
  605. omapdss_register_output(out);
  606. }
  607. static void dpi_uninit_output_port(struct device_node *port)
  608. {
  609. struct dpi_data *dpi = port->data;
  610. struct omap_dss_device *out = &dpi->output;
  611. omapdss_unregister_output(out);
  612. }
  613. static int dpi_bind(struct device *dev, struct device *master, void *data)
  614. {
  615. struct platform_device *pdev = to_platform_device(dev);
  616. struct dpi_data *dpi;
  617. dpi = devm_kzalloc(&pdev->dev, sizeof(*dpi), GFP_KERNEL);
  618. if (!dpi)
  619. return -ENOMEM;
  620. dpi->pdev = pdev;
  621. dev_set_drvdata(&pdev->dev, dpi);
  622. mutex_init(&dpi->lock);
  623. dpi_init_output(pdev);
  624. return 0;
  625. }
  626. static void dpi_unbind(struct device *dev, struct device *master, void *data)
  627. {
  628. struct platform_device *pdev = to_platform_device(dev);
  629. dpi_uninit_output(pdev);
  630. }
  631. static const struct component_ops dpi_component_ops = {
  632. .bind = dpi_bind,
  633. .unbind = dpi_unbind,
  634. };
  635. static int dpi_probe(struct platform_device *pdev)
  636. {
  637. return component_add(&pdev->dev, &dpi_component_ops);
  638. }
  639. static int dpi_remove(struct platform_device *pdev)
  640. {
  641. component_del(&pdev->dev, &dpi_component_ops);
  642. return 0;
  643. }
  644. static struct platform_driver omap_dpi_driver = {
  645. .probe = dpi_probe,
  646. .remove = dpi_remove,
  647. .driver = {
  648. .name = "omapdss_dpi",
  649. .suppress_bind_attrs = true,
  650. },
  651. };
  652. int __init dpi_init_platform_driver(void)
  653. {
  654. return platform_driver_register(&omap_dpi_driver);
  655. }
  656. void dpi_uninit_platform_driver(void)
  657. {
  658. platform_driver_unregister(&omap_dpi_driver);
  659. }
  660. int dpi_init_port(struct platform_device *pdev, struct device_node *port)
  661. {
  662. struct dpi_data *dpi;
  663. struct device_node *ep;
  664. u32 datalines;
  665. int r;
  666. dpi = devm_kzalloc(&pdev->dev, sizeof(*dpi), GFP_KERNEL);
  667. if (!dpi)
  668. return -ENOMEM;
  669. ep = omapdss_of_get_next_endpoint(port, NULL);
  670. if (!ep)
  671. return 0;
  672. r = of_property_read_u32(ep, "data-lines", &datalines);
  673. if (r) {
  674. DSSERR("failed to parse datalines\n");
  675. goto err_datalines;
  676. }
  677. dpi->data_lines = datalines;
  678. of_node_put(ep);
  679. dpi->pdev = pdev;
  680. port->data = dpi;
  681. mutex_init(&dpi->lock);
  682. dpi_init_output_port(pdev, port);
  683. dpi->port_initialized = true;
  684. return 0;
  685. err_datalines:
  686. of_node_put(ep);
  687. return r;
  688. }
  689. void dpi_uninit_port(struct device_node *port)
  690. {
  691. struct dpi_data *dpi = port->data;
  692. if (!dpi->port_initialized)
  693. return;
  694. dpi_uninit_output_port(port);
  695. }