imx-ldb.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. /*
  2. * i.MX drm driver - LVDS display bridge
  3. *
  4. * Copyright (C) 2012 Sascha Hauer, Pengutronix
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <linux/module.h>
  16. #include <linux/clk.h>
  17. #include <linux/component.h>
  18. #include <drm/drmP.h>
  19. #include <drm/drm_fb_helper.h>
  20. #include <drm/drm_crtc_helper.h>
  21. #include <linux/mfd/syscon.h>
  22. #include <linux/mfd/syscon/imx6q-iomuxc-gpr.h>
  23. #include <linux/of_address.h>
  24. #include <linux/of_device.h>
  25. #include <video/of_videomode.h>
  26. #include <linux/regmap.h>
  27. #include <linux/videodev2.h>
  28. #include "imx-drm.h"
  29. #define DRIVER_NAME "imx-ldb"
  30. #define LDB_CH0_MODE_EN_TO_DI0 (1 << 0)
  31. #define LDB_CH0_MODE_EN_TO_DI1 (3 << 0)
  32. #define LDB_CH0_MODE_EN_MASK (3 << 0)
  33. #define LDB_CH1_MODE_EN_TO_DI0 (1 << 2)
  34. #define LDB_CH1_MODE_EN_TO_DI1 (3 << 2)
  35. #define LDB_CH1_MODE_EN_MASK (3 << 2)
  36. #define LDB_SPLIT_MODE_EN (1 << 4)
  37. #define LDB_DATA_WIDTH_CH0_24 (1 << 5)
  38. #define LDB_BIT_MAP_CH0_JEIDA (1 << 6)
  39. #define LDB_DATA_WIDTH_CH1_24 (1 << 7)
  40. #define LDB_BIT_MAP_CH1_JEIDA (1 << 8)
  41. #define LDB_DI0_VS_POL_ACT_LOW (1 << 9)
  42. #define LDB_DI1_VS_POL_ACT_LOW (1 << 10)
  43. #define LDB_BGREF_RMODE_INT (1 << 15)
  44. #define con_to_imx_ldb_ch(x) container_of(x, struct imx_ldb_channel, connector)
  45. #define enc_to_imx_ldb_ch(x) container_of(x, struct imx_ldb_channel, encoder)
  46. struct imx_ldb;
  47. struct imx_ldb_channel {
  48. struct imx_ldb *ldb;
  49. struct drm_connector connector;
  50. struct drm_encoder encoder;
  51. struct device_node *child;
  52. int chno;
  53. void *edid;
  54. int edid_len;
  55. struct drm_display_mode mode;
  56. int mode_valid;
  57. };
  58. struct bus_mux {
  59. int reg;
  60. int shift;
  61. int mask;
  62. };
  63. struct imx_ldb {
  64. struct regmap *regmap;
  65. struct device *dev;
  66. struct imx_ldb_channel channel[2];
  67. struct clk *clk[2]; /* our own clock */
  68. struct clk *clk_sel[4]; /* parent of display clock */
  69. struct clk *clk_pll[2]; /* upstream clock we can adjust */
  70. u32 ldb_ctrl;
  71. const struct bus_mux *lvds_mux;
  72. };
  73. static enum drm_connector_status imx_ldb_connector_detect(
  74. struct drm_connector *connector, bool force)
  75. {
  76. return connector_status_connected;
  77. }
  78. static int imx_ldb_connector_get_modes(struct drm_connector *connector)
  79. {
  80. struct imx_ldb_channel *imx_ldb_ch = con_to_imx_ldb_ch(connector);
  81. int num_modes = 0;
  82. if (imx_ldb_ch->edid) {
  83. drm_mode_connector_update_edid_property(connector,
  84. imx_ldb_ch->edid);
  85. num_modes = drm_add_edid_modes(connector, imx_ldb_ch->edid);
  86. }
  87. if (imx_ldb_ch->mode_valid) {
  88. struct drm_display_mode *mode;
  89. mode = drm_mode_create(connector->dev);
  90. if (!mode)
  91. return -EINVAL;
  92. drm_mode_copy(mode, &imx_ldb_ch->mode);
  93. mode->type |= DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
  94. drm_mode_probed_add(connector, mode);
  95. num_modes++;
  96. }
  97. return num_modes;
  98. }
  99. static struct drm_encoder *imx_ldb_connector_best_encoder(
  100. struct drm_connector *connector)
  101. {
  102. struct imx_ldb_channel *imx_ldb_ch = con_to_imx_ldb_ch(connector);
  103. return &imx_ldb_ch->encoder;
  104. }
  105. static void imx_ldb_encoder_dpms(struct drm_encoder *encoder, int mode)
  106. {
  107. }
  108. static bool imx_ldb_encoder_mode_fixup(struct drm_encoder *encoder,
  109. const struct drm_display_mode *mode,
  110. struct drm_display_mode *adjusted_mode)
  111. {
  112. return true;
  113. }
  114. static void imx_ldb_set_clock(struct imx_ldb *ldb, int mux, int chno,
  115. unsigned long serial_clk, unsigned long di_clk)
  116. {
  117. int ret;
  118. dev_dbg(ldb->dev, "%s: now: %ld want: %ld\n", __func__,
  119. clk_get_rate(ldb->clk_pll[chno]), serial_clk);
  120. clk_set_rate(ldb->clk_pll[chno], serial_clk);
  121. dev_dbg(ldb->dev, "%s after: %ld\n", __func__,
  122. clk_get_rate(ldb->clk_pll[chno]));
  123. dev_dbg(ldb->dev, "%s: now: %ld want: %ld\n", __func__,
  124. clk_get_rate(ldb->clk[chno]),
  125. (long int)di_clk);
  126. clk_set_rate(ldb->clk[chno], di_clk);
  127. dev_dbg(ldb->dev, "%s after: %ld\n", __func__,
  128. clk_get_rate(ldb->clk[chno]));
  129. /* set display clock mux to LDB input clock */
  130. ret = clk_set_parent(ldb->clk_sel[mux], ldb->clk[chno]);
  131. if (ret)
  132. dev_err(ldb->dev,
  133. "unable to set di%d parent clock to ldb_di%d\n", mux,
  134. chno);
  135. }
  136. static void imx_ldb_encoder_prepare(struct drm_encoder *encoder)
  137. {
  138. struct imx_ldb_channel *imx_ldb_ch = enc_to_imx_ldb_ch(encoder);
  139. struct imx_ldb *ldb = imx_ldb_ch->ldb;
  140. struct drm_display_mode *mode = &encoder->crtc->hwmode;
  141. u32 pixel_fmt;
  142. unsigned long serial_clk;
  143. unsigned long di_clk = mode->clock * 1000;
  144. int mux = imx_drm_encoder_get_mux_id(imx_ldb_ch->child, encoder);
  145. if (ldb->ldb_ctrl & LDB_SPLIT_MODE_EN) {
  146. /* dual channel LVDS mode */
  147. serial_clk = 3500UL * mode->clock;
  148. imx_ldb_set_clock(ldb, mux, 0, serial_clk, di_clk);
  149. imx_ldb_set_clock(ldb, mux, 1, serial_clk, di_clk);
  150. } else {
  151. serial_clk = 7000UL * mode->clock;
  152. imx_ldb_set_clock(ldb, mux, imx_ldb_ch->chno, serial_clk,
  153. di_clk);
  154. }
  155. switch (imx_ldb_ch->chno) {
  156. case 0:
  157. pixel_fmt = (ldb->ldb_ctrl & LDB_DATA_WIDTH_CH0_24) ?
  158. V4L2_PIX_FMT_RGB24 : V4L2_PIX_FMT_BGR666;
  159. break;
  160. case 1:
  161. pixel_fmt = (ldb->ldb_ctrl & LDB_DATA_WIDTH_CH1_24) ?
  162. V4L2_PIX_FMT_RGB24 : V4L2_PIX_FMT_BGR666;
  163. break;
  164. default:
  165. dev_err(ldb->dev, "unable to config di%d panel format\n",
  166. imx_ldb_ch->chno);
  167. pixel_fmt = V4L2_PIX_FMT_RGB24;
  168. }
  169. imx_drm_panel_format(encoder, pixel_fmt);
  170. }
  171. static void imx_ldb_encoder_commit(struct drm_encoder *encoder)
  172. {
  173. struct imx_ldb_channel *imx_ldb_ch = enc_to_imx_ldb_ch(encoder);
  174. struct imx_ldb *ldb = imx_ldb_ch->ldb;
  175. int dual = ldb->ldb_ctrl & LDB_SPLIT_MODE_EN;
  176. int mux = imx_drm_encoder_get_mux_id(imx_ldb_ch->child, encoder);
  177. if (dual) {
  178. clk_prepare_enable(ldb->clk[0]);
  179. clk_prepare_enable(ldb->clk[1]);
  180. }
  181. if (imx_ldb_ch == &ldb->channel[0] || dual) {
  182. ldb->ldb_ctrl &= ~LDB_CH0_MODE_EN_MASK;
  183. if (mux == 0 || ldb->lvds_mux)
  184. ldb->ldb_ctrl |= LDB_CH0_MODE_EN_TO_DI0;
  185. else if (mux == 1)
  186. ldb->ldb_ctrl |= LDB_CH0_MODE_EN_TO_DI1;
  187. }
  188. if (imx_ldb_ch == &ldb->channel[1] || dual) {
  189. ldb->ldb_ctrl &= ~LDB_CH1_MODE_EN_MASK;
  190. if (mux == 1 || ldb->lvds_mux)
  191. ldb->ldb_ctrl |= LDB_CH1_MODE_EN_TO_DI1;
  192. else if (mux == 0)
  193. ldb->ldb_ctrl |= LDB_CH1_MODE_EN_TO_DI0;
  194. }
  195. if (ldb->lvds_mux) {
  196. const struct bus_mux *lvds_mux = NULL;
  197. if (imx_ldb_ch == &ldb->channel[0])
  198. lvds_mux = &ldb->lvds_mux[0];
  199. else if (imx_ldb_ch == &ldb->channel[1])
  200. lvds_mux = &ldb->lvds_mux[1];
  201. regmap_update_bits(ldb->regmap, lvds_mux->reg, lvds_mux->mask,
  202. mux << lvds_mux->shift);
  203. }
  204. regmap_write(ldb->regmap, IOMUXC_GPR2, ldb->ldb_ctrl);
  205. }
  206. static void imx_ldb_encoder_mode_set(struct drm_encoder *encoder,
  207. struct drm_display_mode *orig_mode,
  208. struct drm_display_mode *mode)
  209. {
  210. struct imx_ldb_channel *imx_ldb_ch = enc_to_imx_ldb_ch(encoder);
  211. struct imx_ldb *ldb = imx_ldb_ch->ldb;
  212. int dual = ldb->ldb_ctrl & LDB_SPLIT_MODE_EN;
  213. if (mode->clock > 170000) {
  214. dev_warn(ldb->dev,
  215. "%s: mode exceeds 170 MHz pixel clock\n", __func__);
  216. }
  217. if (mode->clock > 85000 && !dual) {
  218. dev_warn(ldb->dev,
  219. "%s: mode exceeds 85 MHz pixel clock\n", __func__);
  220. }
  221. /* FIXME - assumes straight connections DI0 --> CH0, DI1 --> CH1 */
  222. if (imx_ldb_ch == &ldb->channel[0]) {
  223. if (mode->flags & DRM_MODE_FLAG_NVSYNC)
  224. ldb->ldb_ctrl |= LDB_DI0_VS_POL_ACT_LOW;
  225. else if (mode->flags & DRM_MODE_FLAG_PVSYNC)
  226. ldb->ldb_ctrl &= ~LDB_DI0_VS_POL_ACT_LOW;
  227. }
  228. if (imx_ldb_ch == &ldb->channel[1]) {
  229. if (mode->flags & DRM_MODE_FLAG_NVSYNC)
  230. ldb->ldb_ctrl |= LDB_DI1_VS_POL_ACT_LOW;
  231. else if (mode->flags & DRM_MODE_FLAG_PVSYNC)
  232. ldb->ldb_ctrl &= ~LDB_DI1_VS_POL_ACT_LOW;
  233. }
  234. }
  235. static void imx_ldb_encoder_disable(struct drm_encoder *encoder)
  236. {
  237. struct imx_ldb_channel *imx_ldb_ch = enc_to_imx_ldb_ch(encoder);
  238. struct imx_ldb *ldb = imx_ldb_ch->ldb;
  239. /*
  240. * imx_ldb_encoder_disable is called by
  241. * drm_helper_disable_unused_functions without
  242. * the encoder being enabled before.
  243. */
  244. if (imx_ldb_ch == &ldb->channel[0] &&
  245. (ldb->ldb_ctrl & LDB_CH0_MODE_EN_MASK) == 0)
  246. return;
  247. else if (imx_ldb_ch == &ldb->channel[1] &&
  248. (ldb->ldb_ctrl & LDB_CH1_MODE_EN_MASK) == 0)
  249. return;
  250. if (imx_ldb_ch == &ldb->channel[0])
  251. ldb->ldb_ctrl &= ~LDB_CH0_MODE_EN_MASK;
  252. else if (imx_ldb_ch == &ldb->channel[1])
  253. ldb->ldb_ctrl &= ~LDB_CH1_MODE_EN_MASK;
  254. regmap_write(ldb->regmap, IOMUXC_GPR2, ldb->ldb_ctrl);
  255. if (ldb->ldb_ctrl & LDB_SPLIT_MODE_EN) {
  256. clk_disable_unprepare(ldb->clk[0]);
  257. clk_disable_unprepare(ldb->clk[1]);
  258. }
  259. }
  260. static struct drm_connector_funcs imx_ldb_connector_funcs = {
  261. .dpms = drm_helper_connector_dpms,
  262. .fill_modes = drm_helper_probe_single_connector_modes,
  263. .detect = imx_ldb_connector_detect,
  264. .destroy = imx_drm_connector_destroy,
  265. };
  266. static struct drm_connector_helper_funcs imx_ldb_connector_helper_funcs = {
  267. .get_modes = imx_ldb_connector_get_modes,
  268. .best_encoder = imx_ldb_connector_best_encoder,
  269. };
  270. static struct drm_encoder_funcs imx_ldb_encoder_funcs = {
  271. .destroy = imx_drm_encoder_destroy,
  272. };
  273. static struct drm_encoder_helper_funcs imx_ldb_encoder_helper_funcs = {
  274. .dpms = imx_ldb_encoder_dpms,
  275. .mode_fixup = imx_ldb_encoder_mode_fixup,
  276. .prepare = imx_ldb_encoder_prepare,
  277. .commit = imx_ldb_encoder_commit,
  278. .mode_set = imx_ldb_encoder_mode_set,
  279. .disable = imx_ldb_encoder_disable,
  280. };
  281. static int imx_ldb_get_clk(struct imx_ldb *ldb, int chno)
  282. {
  283. char clkname[16];
  284. snprintf(clkname, sizeof(clkname), "di%d", chno);
  285. ldb->clk[chno] = devm_clk_get(ldb->dev, clkname);
  286. if (IS_ERR(ldb->clk[chno]))
  287. return PTR_ERR(ldb->clk[chno]);
  288. snprintf(clkname, sizeof(clkname), "di%d_pll", chno);
  289. ldb->clk_pll[chno] = devm_clk_get(ldb->dev, clkname);
  290. return PTR_ERR_OR_ZERO(ldb->clk_pll[chno]);
  291. }
  292. static int imx_ldb_register(struct drm_device *drm,
  293. struct imx_ldb_channel *imx_ldb_ch)
  294. {
  295. struct imx_ldb *ldb = imx_ldb_ch->ldb;
  296. int ret;
  297. ret = imx_drm_encoder_parse_of(drm, &imx_ldb_ch->encoder,
  298. imx_ldb_ch->child);
  299. if (ret)
  300. return ret;
  301. ret = imx_ldb_get_clk(ldb, imx_ldb_ch->chno);
  302. if (ret)
  303. return ret;
  304. if (ldb->ldb_ctrl & LDB_SPLIT_MODE_EN) {
  305. ret = imx_ldb_get_clk(ldb, 1);
  306. if (ret)
  307. return ret;
  308. }
  309. drm_encoder_helper_add(&imx_ldb_ch->encoder,
  310. &imx_ldb_encoder_helper_funcs);
  311. drm_encoder_init(drm, &imx_ldb_ch->encoder, &imx_ldb_encoder_funcs,
  312. DRM_MODE_ENCODER_LVDS);
  313. drm_connector_helper_add(&imx_ldb_ch->connector,
  314. &imx_ldb_connector_helper_funcs);
  315. drm_connector_init(drm, &imx_ldb_ch->connector,
  316. &imx_ldb_connector_funcs, DRM_MODE_CONNECTOR_LVDS);
  317. drm_mode_connector_attach_encoder(&imx_ldb_ch->connector,
  318. &imx_ldb_ch->encoder);
  319. return 0;
  320. }
  321. enum {
  322. LVDS_BIT_MAP_SPWG,
  323. LVDS_BIT_MAP_JEIDA
  324. };
  325. static const char * const imx_ldb_bit_mappings[] = {
  326. [LVDS_BIT_MAP_SPWG] = "spwg",
  327. [LVDS_BIT_MAP_JEIDA] = "jeida",
  328. };
  329. static const int of_get_data_mapping(struct device_node *np)
  330. {
  331. const char *bm;
  332. int ret, i;
  333. ret = of_property_read_string(np, "fsl,data-mapping", &bm);
  334. if (ret < 0)
  335. return ret;
  336. for (i = 0; i < ARRAY_SIZE(imx_ldb_bit_mappings); i++)
  337. if (!strcasecmp(bm, imx_ldb_bit_mappings[i]))
  338. return i;
  339. return -EINVAL;
  340. }
  341. static struct bus_mux imx6q_lvds_mux[2] = {
  342. {
  343. .reg = IOMUXC_GPR3,
  344. .shift = 6,
  345. .mask = IMX6Q_GPR3_LVDS0_MUX_CTL_MASK,
  346. }, {
  347. .reg = IOMUXC_GPR3,
  348. .shift = 8,
  349. .mask = IMX6Q_GPR3_LVDS1_MUX_CTL_MASK,
  350. }
  351. };
  352. /*
  353. * For a device declaring compatible = "fsl,imx6q-ldb", "fsl,imx53-ldb",
  354. * of_match_device will walk through this list and take the first entry
  355. * matching any of its compatible values. Therefore, the more generic
  356. * entries (in this case fsl,imx53-ldb) need to be ordered last.
  357. */
  358. static const struct of_device_id imx_ldb_dt_ids[] = {
  359. { .compatible = "fsl,imx6q-ldb", .data = imx6q_lvds_mux, },
  360. { .compatible = "fsl,imx53-ldb", .data = NULL, },
  361. { }
  362. };
  363. MODULE_DEVICE_TABLE(of, imx_ldb_dt_ids);
  364. static int imx_ldb_bind(struct device *dev, struct device *master, void *data)
  365. {
  366. struct drm_device *drm = data;
  367. struct device_node *np = dev->of_node;
  368. const struct of_device_id *of_id =
  369. of_match_device(imx_ldb_dt_ids, dev);
  370. struct device_node *child;
  371. const u8 *edidp;
  372. struct imx_ldb *imx_ldb;
  373. int datawidth;
  374. int mapping;
  375. int dual;
  376. int ret;
  377. int i;
  378. imx_ldb = devm_kzalloc(dev, sizeof(*imx_ldb), GFP_KERNEL);
  379. if (!imx_ldb)
  380. return -ENOMEM;
  381. imx_ldb->regmap = syscon_regmap_lookup_by_phandle(np, "gpr");
  382. if (IS_ERR(imx_ldb->regmap)) {
  383. dev_err(dev, "failed to get parent regmap\n");
  384. return PTR_ERR(imx_ldb->regmap);
  385. }
  386. imx_ldb->dev = dev;
  387. if (of_id)
  388. imx_ldb->lvds_mux = of_id->data;
  389. dual = of_property_read_bool(np, "fsl,dual-channel");
  390. if (dual)
  391. imx_ldb->ldb_ctrl |= LDB_SPLIT_MODE_EN;
  392. /*
  393. * There are three different possible clock mux configurations:
  394. * i.MX53: ipu1_di0_sel, ipu1_di1_sel
  395. * i.MX6q: ipu1_di0_sel, ipu1_di1_sel, ipu2_di0_sel, ipu2_di1_sel
  396. * i.MX6dl: ipu1_di0_sel, ipu1_di1_sel, lcdif_sel
  397. * Map them all to di0_sel...di3_sel.
  398. */
  399. for (i = 0; i < 4; i++) {
  400. char clkname[16];
  401. sprintf(clkname, "di%d_sel", i);
  402. imx_ldb->clk_sel[i] = devm_clk_get(imx_ldb->dev, clkname);
  403. if (IS_ERR(imx_ldb->clk_sel[i])) {
  404. ret = PTR_ERR(imx_ldb->clk_sel[i]);
  405. imx_ldb->clk_sel[i] = NULL;
  406. break;
  407. }
  408. }
  409. if (i == 0)
  410. return ret;
  411. for_each_child_of_node(np, child) {
  412. struct imx_ldb_channel *channel;
  413. ret = of_property_read_u32(child, "reg", &i);
  414. if (ret || i < 0 || i > 1)
  415. return -EINVAL;
  416. if (dual && i > 0) {
  417. dev_warn(dev, "dual-channel mode, ignoring second output\n");
  418. continue;
  419. }
  420. if (!of_device_is_available(child))
  421. continue;
  422. channel = &imx_ldb->channel[i];
  423. channel->ldb = imx_ldb;
  424. channel->chno = i;
  425. channel->child = child;
  426. edidp = of_get_property(child, "edid", &channel->edid_len);
  427. if (edidp) {
  428. channel->edid = kmemdup(edidp, channel->edid_len,
  429. GFP_KERNEL);
  430. } else {
  431. ret = of_get_drm_display_mode(child, &channel->mode, 0);
  432. if (!ret)
  433. channel->mode_valid = 1;
  434. }
  435. ret = of_property_read_u32(child, "fsl,data-width", &datawidth);
  436. if (ret)
  437. datawidth = 0;
  438. else if (datawidth != 18 && datawidth != 24)
  439. return -EINVAL;
  440. mapping = of_get_data_mapping(child);
  441. switch (mapping) {
  442. case LVDS_BIT_MAP_SPWG:
  443. if (datawidth == 24) {
  444. if (i == 0 || dual)
  445. imx_ldb->ldb_ctrl |=
  446. LDB_DATA_WIDTH_CH0_24;
  447. if (i == 1 || dual)
  448. imx_ldb->ldb_ctrl |=
  449. LDB_DATA_WIDTH_CH1_24;
  450. }
  451. break;
  452. case LVDS_BIT_MAP_JEIDA:
  453. if (datawidth == 18) {
  454. dev_err(dev, "JEIDA standard only supported in 24 bit\n");
  455. return -EINVAL;
  456. }
  457. if (i == 0 || dual)
  458. imx_ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH0_24 |
  459. LDB_BIT_MAP_CH0_JEIDA;
  460. if (i == 1 || dual)
  461. imx_ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH1_24 |
  462. LDB_BIT_MAP_CH1_JEIDA;
  463. break;
  464. default:
  465. dev_err(dev, "data mapping not specified or invalid\n");
  466. return -EINVAL;
  467. }
  468. ret = imx_ldb_register(drm, channel);
  469. if (ret)
  470. return ret;
  471. }
  472. dev_set_drvdata(dev, imx_ldb);
  473. return 0;
  474. }
  475. static void imx_ldb_unbind(struct device *dev, struct device *master,
  476. void *data)
  477. {
  478. struct imx_ldb *imx_ldb = dev_get_drvdata(dev);
  479. int i;
  480. for (i = 0; i < 2; i++) {
  481. struct imx_ldb_channel *channel = &imx_ldb->channel[i];
  482. if (!channel->connector.funcs)
  483. continue;
  484. channel->connector.funcs->destroy(&channel->connector);
  485. channel->encoder.funcs->destroy(&channel->encoder);
  486. kfree(channel->edid);
  487. }
  488. }
  489. static const struct component_ops imx_ldb_ops = {
  490. .bind = imx_ldb_bind,
  491. .unbind = imx_ldb_unbind,
  492. };
  493. static int imx_ldb_probe(struct platform_device *pdev)
  494. {
  495. return component_add(&pdev->dev, &imx_ldb_ops);
  496. }
  497. static int imx_ldb_remove(struct platform_device *pdev)
  498. {
  499. component_del(&pdev->dev, &imx_ldb_ops);
  500. return 0;
  501. }
  502. static struct platform_driver imx_ldb_driver = {
  503. .probe = imx_ldb_probe,
  504. .remove = imx_ldb_remove,
  505. .driver = {
  506. .of_match_table = imx_ldb_dt_ids,
  507. .name = DRIVER_NAME,
  508. },
  509. };
  510. module_platform_driver(imx_ldb_driver);
  511. MODULE_DESCRIPTION("i.MX LVDS driver");
  512. MODULE_AUTHOR("Sascha Hauer, Pengutronix");
  513. MODULE_LICENSE("GPL");
  514. MODULE_ALIAS("platform:" DRIVER_NAME);