dpi.c 16 KB

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