dpi.c 17 KB

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