dpi.c 16 KB

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