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 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(struct dpi_data *dpi,
  52. 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(dpi->dss, 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(dpi->dss, DSS_CLK_SRC_PLL1_3))
  70. return DSS_CLK_SRC_PLL1_3;
  71. if (dss_pll_find_by_src(dpi->dss, 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(dpi->dss, DSS_CLK_SRC_PLL2_1))
  78. return DSS_CLK_SRC_PLL2_1;
  79. if (dss_pll_find_by_src(dpi->dss, 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(struct dpi_data *dpi)
  89. {
  90. enum omap_channel channel = dpi->output.dispc_channel;
  91. /*
  92. * XXX we can't currently use DSI PLL for DPI with OMAP3, as the DSI PLL
  93. * would also be used for DISPC fclk. Meaning, when the DPI output is
  94. * disabled, DISPC clock will be disabled, and TV out will stop.
  95. */
  96. switch (dpi->dss_model) {
  97. case DSS_MODEL_OMAP2:
  98. case DSS_MODEL_OMAP3:
  99. return DSS_CLK_SRC_FCK;
  100. case DSS_MODEL_OMAP4:
  101. switch (channel) {
  102. case OMAP_DSS_CHANNEL_LCD:
  103. return DSS_CLK_SRC_PLL1_1;
  104. case OMAP_DSS_CHANNEL_LCD2:
  105. return DSS_CLK_SRC_PLL2_1;
  106. default:
  107. return DSS_CLK_SRC_FCK;
  108. }
  109. case DSS_MODEL_OMAP5:
  110. switch (channel) {
  111. case OMAP_DSS_CHANNEL_LCD:
  112. return DSS_CLK_SRC_PLL1_1;
  113. case OMAP_DSS_CHANNEL_LCD3:
  114. return DSS_CLK_SRC_PLL2_1;
  115. case OMAP_DSS_CHANNEL_LCD2:
  116. default:
  117. return DSS_CLK_SRC_FCK;
  118. }
  119. case DSS_MODEL_DRA7:
  120. return dpi_get_clk_src_dra7xx(dpi, channel);
  121. default:
  122. return DSS_CLK_SRC_FCK;
  123. }
  124. }
  125. struct dpi_clk_calc_ctx {
  126. struct dpi_data *dpi;
  127. unsigned int clkout_idx;
  128. /* inputs */
  129. unsigned long pck_min, pck_max;
  130. /* outputs */
  131. struct dss_pll_clock_info pll_cinfo;
  132. unsigned long fck;
  133. struct dispc_clock_info dispc_cinfo;
  134. };
  135. static bool dpi_calc_dispc_cb(int lckd, int pckd, unsigned long lck,
  136. unsigned long pck, void *data)
  137. {
  138. struct dpi_clk_calc_ctx *ctx = data;
  139. /*
  140. * Odd dividers give us uneven duty cycle, causing problem when level
  141. * shifted. So skip all odd dividers when the pixel clock is on the
  142. * higher side.
  143. */
  144. if (ctx->pck_min >= 100000000) {
  145. if (lckd > 1 && lckd % 2 != 0)
  146. return false;
  147. if (pckd > 1 && pckd % 2 != 0)
  148. return false;
  149. }
  150. ctx->dispc_cinfo.lck_div = lckd;
  151. ctx->dispc_cinfo.pck_div = pckd;
  152. ctx->dispc_cinfo.lck = lck;
  153. ctx->dispc_cinfo.pck = pck;
  154. return true;
  155. }
  156. static bool dpi_calc_hsdiv_cb(int m_dispc, unsigned long dispc,
  157. void *data)
  158. {
  159. struct dpi_clk_calc_ctx *ctx = data;
  160. ctx->pll_cinfo.mX[ctx->clkout_idx] = m_dispc;
  161. ctx->pll_cinfo.clkout[ctx->clkout_idx] = dispc;
  162. return dispc_div_calc(ctx->dpi->dss->dispc, dispc,
  163. 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->dpi->pll, clkdco,
  176. ctx->pck_min, dss_get_max_fck_rate(ctx->dpi->dss),
  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(ctx->dpi->dss->dispc, fck,
  184. ctx->pck_min, ctx->pck_max,
  185. dpi_calc_dispc_cb, ctx);
  186. }
  187. static bool dpi_pll_clk_calc(struct dpi_data *dpi, unsigned long pck,
  188. struct dpi_clk_calc_ctx *ctx)
  189. {
  190. unsigned long clkin;
  191. memset(ctx, 0, sizeof(*ctx));
  192. ctx->dpi = dpi;
  193. ctx->clkout_idx = dss_pll_get_clkout_idx_for_src(dpi->clk_src);
  194. clkin = clk_get_rate(dpi->pll->clkin);
  195. if (dpi->pll->hw->type == DSS_PLL_TYPE_A) {
  196. unsigned long pll_min, pll_max;
  197. ctx->pck_min = pck - 1000;
  198. ctx->pck_max = pck + 1000;
  199. pll_min = 0;
  200. pll_max = 0;
  201. return dss_pll_calc_a(ctx->dpi->pll, clkin,
  202. pll_min, pll_max,
  203. dpi_calc_pll_cb, ctx);
  204. } else { /* DSS_PLL_TYPE_B */
  205. dss_pll_calc_b(dpi->pll, clkin, pck, &ctx->pll_cinfo);
  206. ctx->dispc_cinfo.lck_div = 1;
  207. ctx->dispc_cinfo.pck_div = 1;
  208. ctx->dispc_cinfo.lck = ctx->pll_cinfo.clkout[0];
  209. ctx->dispc_cinfo.pck = ctx->dispc_cinfo.lck;
  210. return true;
  211. }
  212. }
  213. static bool dpi_dss_clk_calc(struct dpi_data *dpi, unsigned long pck,
  214. struct dpi_clk_calc_ctx *ctx)
  215. {
  216. int i;
  217. /*
  218. * DSS fck gives us very few possibilities, so finding a good pixel
  219. * clock may not be possible. We try multiple times to find the clock,
  220. * each time widening the pixel clock range we look for, up to
  221. * +/- ~15MHz.
  222. */
  223. for (i = 0; i < 25; ++i) {
  224. bool ok;
  225. memset(ctx, 0, sizeof(*ctx));
  226. ctx->dpi = dpi;
  227. if (pck > 1000 * i * i * i)
  228. ctx->pck_min = max(pck - 1000 * i * i * i, 0lu);
  229. else
  230. ctx->pck_min = 0;
  231. ctx->pck_max = pck + 1000 * i * i * i;
  232. ok = dss_div_calc(dpi->dss, pck, ctx->pck_min,
  233. 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(dpi->dss, 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(dpi, pck_req, &ctx);
  266. if (!ok)
  267. return -EINVAL;
  268. r = dss_set_fck_rate(dpi->dss, 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 videomode *vm = &dpi->vm;
  280. int lck_div = 0, pck_div = 0;
  281. unsigned long fck = 0;
  282. unsigned long pck;
  283. int r = 0;
  284. if (dpi->pll)
  285. r = dpi_set_pll_clk(dpi, dpi->output.dispc_channel,
  286. vm->pixelclock, &fck, &lck_div, &pck_div);
  287. else
  288. r = dpi_set_dispc_clk(dpi, vm->pixelclock, &fck,
  289. &lck_div, &pck_div);
  290. if (r)
  291. return r;
  292. pck = fck / lck_div / pck_div;
  293. if (pck != vm->pixelclock) {
  294. DSSWARN("Could not find exact pixel clock. Requested %lu Hz, got %lu Hz\n",
  295. vm->pixelclock, pck);
  296. vm->pixelclock = pck;
  297. }
  298. dss_mgr_set_timings(&dpi->output, vm);
  299. return 0;
  300. }
  301. static void dpi_config_lcd_manager(struct dpi_data *dpi)
  302. {
  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(&dpi->output, &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. int r;
  315. mutex_lock(&dpi->lock);
  316. if (!out->dispc_channel_connected) {
  317. DSSERR("failed to enable display: no output/manager\n");
  318. r = -ENODEV;
  319. goto err_no_out_mgr;
  320. }
  321. if (dpi->vdds_dsi_reg) {
  322. r = regulator_enable(dpi->vdds_dsi_reg);
  323. if (r)
  324. goto err_reg_enable;
  325. }
  326. r = dispc_runtime_get(dpi->dss->dispc);
  327. if (r)
  328. goto err_get_dispc;
  329. r = dss_dpi_select_source(dpi->dss, out->port_num, out->dispc_channel);
  330. if (r)
  331. goto err_src_sel;
  332. if (dpi->pll) {
  333. r = dss_pll_enable(dpi->pll);
  334. if (r)
  335. goto err_pll_init;
  336. }
  337. r = dpi_set_mode(dpi);
  338. if (r)
  339. goto err_set_mode;
  340. dpi_config_lcd_manager(dpi);
  341. mdelay(2);
  342. r = dss_mgr_enable(&dpi->output);
  343. if (r)
  344. goto err_mgr_enable;
  345. mutex_unlock(&dpi->lock);
  346. return 0;
  347. err_mgr_enable:
  348. err_set_mode:
  349. if (dpi->pll)
  350. dss_pll_disable(dpi->pll);
  351. err_pll_init:
  352. err_src_sel:
  353. dispc_runtime_put(dpi->dss->dispc);
  354. err_get_dispc:
  355. if (dpi->vdds_dsi_reg)
  356. regulator_disable(dpi->vdds_dsi_reg);
  357. err_reg_enable:
  358. err_no_out_mgr:
  359. mutex_unlock(&dpi->lock);
  360. return r;
  361. }
  362. static void dpi_display_disable(struct omap_dss_device *dssdev)
  363. {
  364. struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
  365. mutex_lock(&dpi->lock);
  366. dss_mgr_disable(&dpi->output);
  367. if (dpi->pll) {
  368. dss_select_lcd_clk_source(dpi->dss, dpi->output.dispc_channel,
  369. DSS_CLK_SRC_FCK);
  370. dss_pll_disable(dpi->pll);
  371. }
  372. dispc_runtime_put(dpi->dss->dispc);
  373. if (dpi->vdds_dsi_reg)
  374. regulator_disable(dpi->vdds_dsi_reg);
  375. mutex_unlock(&dpi->lock);
  376. }
  377. static void dpi_set_timings(struct omap_dss_device *dssdev,
  378. struct videomode *vm)
  379. {
  380. struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
  381. DSSDBG("dpi_set_timings\n");
  382. mutex_lock(&dpi->lock);
  383. dpi->vm = *vm;
  384. mutex_unlock(&dpi->lock);
  385. }
  386. static void dpi_get_timings(struct omap_dss_device *dssdev,
  387. struct videomode *vm)
  388. {
  389. struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
  390. mutex_lock(&dpi->lock);
  391. *vm = dpi->vm;
  392. mutex_unlock(&dpi->lock);
  393. }
  394. static int dpi_check_timings(struct omap_dss_device *dssdev,
  395. struct videomode *vm)
  396. {
  397. struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
  398. enum omap_channel channel = dpi->output.dispc_channel;
  399. int lck_div, pck_div;
  400. unsigned long fck;
  401. unsigned long pck;
  402. struct dpi_clk_calc_ctx ctx;
  403. bool ok;
  404. if (vm->hactive % 8 != 0)
  405. return -EINVAL;
  406. if (!dispc_mgr_timings_ok(dpi->dss->dispc, channel, vm))
  407. return -EINVAL;
  408. if (vm->pixelclock == 0)
  409. return -EINVAL;
  410. if (dpi->pll) {
  411. ok = dpi_pll_clk_calc(dpi, vm->pixelclock, &ctx);
  412. if (!ok)
  413. return -EINVAL;
  414. fck = ctx.pll_cinfo.clkout[ctx.clkout_idx];
  415. } else {
  416. ok = dpi_dss_clk_calc(dpi, vm->pixelclock, &ctx);
  417. if (!ok)
  418. return -EINVAL;
  419. fck = ctx.fck;
  420. }
  421. lck_div = ctx.dispc_cinfo.lck_div;
  422. pck_div = ctx.dispc_cinfo.pck_div;
  423. pck = fck / lck_div / pck_div;
  424. vm->pixelclock = pck;
  425. return 0;
  426. }
  427. static int dpi_verify_pll(struct dss_pll *pll)
  428. {
  429. int r;
  430. /* do initial setup with the PLL to see if it is operational */
  431. r = dss_pll_enable(pll);
  432. if (r)
  433. return r;
  434. dss_pll_disable(pll);
  435. return 0;
  436. }
  437. static const struct soc_device_attribute dpi_soc_devices[] = {
  438. { .machine = "OMAP3[456]*" },
  439. { .machine = "[AD]M37*" },
  440. { /* sentinel */ }
  441. };
  442. static int dpi_init_regulator(struct dpi_data *dpi)
  443. {
  444. struct regulator *vdds_dsi;
  445. /*
  446. * The DPI uses the DSI VDDS on OMAP34xx, OMAP35xx, OMAP36xx, AM37xx and
  447. * DM37xx only.
  448. */
  449. if (!soc_device_match(dpi_soc_devices))
  450. return 0;
  451. if (dpi->vdds_dsi_reg)
  452. return 0;
  453. vdds_dsi = devm_regulator_get(&dpi->pdev->dev, "vdds_dsi");
  454. if (IS_ERR(vdds_dsi)) {
  455. if (PTR_ERR(vdds_dsi) != -EPROBE_DEFER)
  456. DSSERR("can't get VDDS_DSI regulator\n");
  457. return PTR_ERR(vdds_dsi);
  458. }
  459. dpi->vdds_dsi_reg = vdds_dsi;
  460. return 0;
  461. }
  462. static void dpi_init_pll(struct dpi_data *dpi)
  463. {
  464. struct dss_pll *pll;
  465. if (dpi->pll)
  466. return;
  467. dpi->clk_src = dpi_get_clk_src(dpi);
  468. pll = dss_pll_find_by_src(dpi->dss, dpi->clk_src);
  469. if (!pll)
  470. return;
  471. if (dpi_verify_pll(pll)) {
  472. DSSWARN("PLL not operational\n");
  473. return;
  474. }
  475. dpi->pll = pll;
  476. }
  477. /*
  478. * Return a hardcoded channel for the DPI output. This should work for
  479. * current use cases, but this can be later expanded to either resolve
  480. * the channel in some more dynamic manner, or get the channel as a user
  481. * parameter.
  482. */
  483. static enum omap_channel dpi_get_channel(struct dpi_data *dpi, int port_num)
  484. {
  485. switch (dpi->dss_model) {
  486. case DSS_MODEL_OMAP2:
  487. case DSS_MODEL_OMAP3:
  488. return OMAP_DSS_CHANNEL_LCD;
  489. case DSS_MODEL_DRA7:
  490. switch (port_num) {
  491. case 2:
  492. return OMAP_DSS_CHANNEL_LCD3;
  493. case 1:
  494. return OMAP_DSS_CHANNEL_LCD2;
  495. case 0:
  496. default:
  497. return OMAP_DSS_CHANNEL_LCD;
  498. }
  499. case DSS_MODEL_OMAP4:
  500. return OMAP_DSS_CHANNEL_LCD2;
  501. case DSS_MODEL_OMAP5:
  502. return OMAP_DSS_CHANNEL_LCD3;
  503. default:
  504. DSSWARN("unsupported DSS version\n");
  505. return OMAP_DSS_CHANNEL_LCD;
  506. }
  507. }
  508. static int dpi_connect(struct omap_dss_device *dssdev,
  509. struct omap_dss_device *dst)
  510. {
  511. struct dpi_data *dpi = dpi_get_data_from_dssdev(dssdev);
  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(&dpi->output, 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(&dpi->output, 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. WARN_ON(dst != dssdev->dst);
  534. if (dst != dssdev->dst)
  535. return;
  536. omapdss_output_unset_device(dssdev);
  537. dss_mgr_disconnect(&dpi->output, 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 dss_device *dss, struct platform_device *pdev,
  584. struct device_node *port, 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. dpi->dss = dss;
  606. port->data = dpi;
  607. mutex_init(&dpi->lock);
  608. dpi_init_output_port(dpi, port);
  609. return 0;
  610. err_datalines:
  611. of_node_put(ep);
  612. return r;
  613. }
  614. void dpi_uninit_port(struct device_node *port)
  615. {
  616. struct dpi_data *dpi = port->data;
  617. if (!dpi)
  618. return;
  619. dpi_uninit_output_port(port);
  620. }