dpi.c 16 KB

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