dpi.c 18 KB

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