dpi.c 16 KB

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