dpi.c 19 KB

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