imx-ldb.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  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. u32 pixel_fmt;
  141. switch (imx_ldb_ch->chno) {
  142. case 0:
  143. pixel_fmt = (ldb->ldb_ctrl & LDB_DATA_WIDTH_CH0_24) ?
  144. V4L2_PIX_FMT_RGB24 : V4L2_PIX_FMT_BGR666;
  145. break;
  146. case 1:
  147. pixel_fmt = (ldb->ldb_ctrl & LDB_DATA_WIDTH_CH1_24) ?
  148. V4L2_PIX_FMT_RGB24 : V4L2_PIX_FMT_BGR666;
  149. break;
  150. default:
  151. dev_err(ldb->dev, "unable to config di%d panel format\n",
  152. imx_ldb_ch->chno);
  153. pixel_fmt = V4L2_PIX_FMT_RGB24;
  154. }
  155. imx_drm_panel_format(encoder, pixel_fmt);
  156. }
  157. static void imx_ldb_encoder_commit(struct drm_encoder *encoder)
  158. {
  159. struct imx_ldb_channel *imx_ldb_ch = enc_to_imx_ldb_ch(encoder);
  160. struct imx_ldb *ldb = imx_ldb_ch->ldb;
  161. int dual = ldb->ldb_ctrl & LDB_SPLIT_MODE_EN;
  162. int mux = imx_drm_encoder_get_mux_id(imx_ldb_ch->child, encoder);
  163. if (dual) {
  164. clk_prepare_enable(ldb->clk[0]);
  165. clk_prepare_enable(ldb->clk[1]);
  166. }
  167. if (imx_ldb_ch == &ldb->channel[0] || dual) {
  168. ldb->ldb_ctrl &= ~LDB_CH0_MODE_EN_MASK;
  169. if (mux == 0 || ldb->lvds_mux)
  170. ldb->ldb_ctrl |= LDB_CH0_MODE_EN_TO_DI0;
  171. else if (mux == 1)
  172. ldb->ldb_ctrl |= LDB_CH0_MODE_EN_TO_DI1;
  173. }
  174. if (imx_ldb_ch == &ldb->channel[1] || dual) {
  175. ldb->ldb_ctrl &= ~LDB_CH1_MODE_EN_MASK;
  176. if (mux == 1 || ldb->lvds_mux)
  177. ldb->ldb_ctrl |= LDB_CH1_MODE_EN_TO_DI1;
  178. else if (mux == 0)
  179. ldb->ldb_ctrl |= LDB_CH1_MODE_EN_TO_DI0;
  180. }
  181. if (ldb->lvds_mux) {
  182. const struct bus_mux *lvds_mux = NULL;
  183. if (imx_ldb_ch == &ldb->channel[0])
  184. lvds_mux = &ldb->lvds_mux[0];
  185. else if (imx_ldb_ch == &ldb->channel[1])
  186. lvds_mux = &ldb->lvds_mux[1];
  187. regmap_update_bits(ldb->regmap, lvds_mux->reg, lvds_mux->mask,
  188. mux << lvds_mux->shift);
  189. }
  190. regmap_write(ldb->regmap, IOMUXC_GPR2, ldb->ldb_ctrl);
  191. }
  192. static void imx_ldb_encoder_mode_set(struct drm_encoder *encoder,
  193. struct drm_display_mode *orig_mode,
  194. struct drm_display_mode *mode)
  195. {
  196. struct imx_ldb_channel *imx_ldb_ch = enc_to_imx_ldb_ch(encoder);
  197. struct imx_ldb *ldb = imx_ldb_ch->ldb;
  198. int dual = ldb->ldb_ctrl & LDB_SPLIT_MODE_EN;
  199. unsigned long serial_clk;
  200. unsigned long di_clk = mode->clock * 1000;
  201. int mux = imx_drm_encoder_get_mux_id(imx_ldb_ch->child, encoder);
  202. if (mode->clock > 170000) {
  203. dev_warn(ldb->dev,
  204. "%s: mode exceeds 170 MHz pixel clock\n", __func__);
  205. }
  206. if (mode->clock > 85000 && !dual) {
  207. dev_warn(ldb->dev,
  208. "%s: mode exceeds 85 MHz pixel clock\n", __func__);
  209. }
  210. if (dual) {
  211. serial_clk = 3500UL * mode->clock;
  212. imx_ldb_set_clock(ldb, mux, 0, serial_clk, di_clk);
  213. imx_ldb_set_clock(ldb, mux, 1, serial_clk, di_clk);
  214. } else {
  215. serial_clk = 7000UL * mode->clock;
  216. imx_ldb_set_clock(ldb, mux, imx_ldb_ch->chno, serial_clk,
  217. di_clk);
  218. }
  219. /* FIXME - assumes straight connections DI0 --> CH0, DI1 --> CH1 */
  220. if (imx_ldb_ch == &ldb->channel[0]) {
  221. if (mode->flags & DRM_MODE_FLAG_NVSYNC)
  222. ldb->ldb_ctrl |= LDB_DI0_VS_POL_ACT_LOW;
  223. else if (mode->flags & DRM_MODE_FLAG_PVSYNC)
  224. ldb->ldb_ctrl &= ~LDB_DI0_VS_POL_ACT_LOW;
  225. }
  226. if (imx_ldb_ch == &ldb->channel[1]) {
  227. if (mode->flags & DRM_MODE_FLAG_NVSYNC)
  228. ldb->ldb_ctrl |= LDB_DI1_VS_POL_ACT_LOW;
  229. else if (mode->flags & DRM_MODE_FLAG_PVSYNC)
  230. ldb->ldb_ctrl &= ~LDB_DI1_VS_POL_ACT_LOW;
  231. }
  232. }
  233. static void imx_ldb_encoder_disable(struct drm_encoder *encoder)
  234. {
  235. struct imx_ldb_channel *imx_ldb_ch = enc_to_imx_ldb_ch(encoder);
  236. struct imx_ldb *ldb = imx_ldb_ch->ldb;
  237. /*
  238. * imx_ldb_encoder_disable is called by
  239. * drm_helper_disable_unused_functions without
  240. * the encoder being enabled before.
  241. */
  242. if (imx_ldb_ch == &ldb->channel[0] &&
  243. (ldb->ldb_ctrl & LDB_CH0_MODE_EN_MASK) == 0)
  244. return;
  245. else if (imx_ldb_ch == &ldb->channel[1] &&
  246. (ldb->ldb_ctrl & LDB_CH1_MODE_EN_MASK) == 0)
  247. return;
  248. if (imx_ldb_ch == &ldb->channel[0])
  249. ldb->ldb_ctrl &= ~LDB_CH0_MODE_EN_MASK;
  250. else if (imx_ldb_ch == &ldb->channel[1])
  251. ldb->ldb_ctrl &= ~LDB_CH1_MODE_EN_MASK;
  252. regmap_write(ldb->regmap, IOMUXC_GPR2, ldb->ldb_ctrl);
  253. if (ldb->ldb_ctrl & LDB_SPLIT_MODE_EN) {
  254. clk_disable_unprepare(ldb->clk[0]);
  255. clk_disable_unprepare(ldb->clk[1]);
  256. }
  257. }
  258. static struct drm_connector_funcs imx_ldb_connector_funcs = {
  259. .dpms = drm_helper_connector_dpms,
  260. .fill_modes = drm_helper_probe_single_connector_modes,
  261. .detect = imx_ldb_connector_detect,
  262. .destroy = imx_drm_connector_destroy,
  263. };
  264. static struct drm_connector_helper_funcs imx_ldb_connector_helper_funcs = {
  265. .get_modes = imx_ldb_connector_get_modes,
  266. .best_encoder = imx_ldb_connector_best_encoder,
  267. };
  268. static struct drm_encoder_funcs imx_ldb_encoder_funcs = {
  269. .destroy = imx_drm_encoder_destroy,
  270. };
  271. static struct drm_encoder_helper_funcs imx_ldb_encoder_helper_funcs = {
  272. .dpms = imx_ldb_encoder_dpms,
  273. .mode_fixup = imx_ldb_encoder_mode_fixup,
  274. .prepare = imx_ldb_encoder_prepare,
  275. .commit = imx_ldb_encoder_commit,
  276. .mode_set = imx_ldb_encoder_mode_set,
  277. .disable = imx_ldb_encoder_disable,
  278. };
  279. static int imx_ldb_get_clk(struct imx_ldb *ldb, int chno)
  280. {
  281. char clkname[16];
  282. snprintf(clkname, sizeof(clkname), "di%d", chno);
  283. ldb->clk[chno] = devm_clk_get(ldb->dev, clkname);
  284. if (IS_ERR(ldb->clk[chno]))
  285. return PTR_ERR(ldb->clk[chno]);
  286. snprintf(clkname, sizeof(clkname), "di%d_pll", chno);
  287. ldb->clk_pll[chno] = devm_clk_get(ldb->dev, clkname);
  288. return PTR_ERR_OR_ZERO(ldb->clk_pll[chno]);
  289. }
  290. static int imx_ldb_register(struct drm_device *drm,
  291. struct imx_ldb_channel *imx_ldb_ch)
  292. {
  293. struct imx_ldb *ldb = imx_ldb_ch->ldb;
  294. int ret;
  295. ret = imx_drm_encoder_parse_of(drm, &imx_ldb_ch->encoder,
  296. imx_ldb_ch->child);
  297. if (ret)
  298. return ret;
  299. ret = imx_ldb_get_clk(ldb, imx_ldb_ch->chno);
  300. if (ret)
  301. return ret;
  302. if (ldb->ldb_ctrl & LDB_SPLIT_MODE_EN) {
  303. ret = imx_ldb_get_clk(ldb, 1);
  304. if (ret)
  305. return ret;
  306. }
  307. drm_encoder_helper_add(&imx_ldb_ch->encoder,
  308. &imx_ldb_encoder_helper_funcs);
  309. drm_encoder_init(drm, &imx_ldb_ch->encoder, &imx_ldb_encoder_funcs,
  310. DRM_MODE_ENCODER_LVDS);
  311. drm_connector_helper_add(&imx_ldb_ch->connector,
  312. &imx_ldb_connector_helper_funcs);
  313. drm_connector_init(drm, &imx_ldb_ch->connector,
  314. &imx_ldb_connector_funcs, DRM_MODE_CONNECTOR_LVDS);
  315. drm_mode_connector_attach_encoder(&imx_ldb_ch->connector,
  316. &imx_ldb_ch->encoder);
  317. return 0;
  318. }
  319. enum {
  320. LVDS_BIT_MAP_SPWG,
  321. LVDS_BIT_MAP_JEIDA
  322. };
  323. static const char * const imx_ldb_bit_mappings[] = {
  324. [LVDS_BIT_MAP_SPWG] = "spwg",
  325. [LVDS_BIT_MAP_JEIDA] = "jeida",
  326. };
  327. static const int of_get_data_mapping(struct device_node *np)
  328. {
  329. const char *bm;
  330. int ret, i;
  331. ret = of_property_read_string(np, "fsl,data-mapping", &bm);
  332. if (ret < 0)
  333. return ret;
  334. for (i = 0; i < ARRAY_SIZE(imx_ldb_bit_mappings); i++)
  335. if (!strcasecmp(bm, imx_ldb_bit_mappings[i]))
  336. return i;
  337. return -EINVAL;
  338. }
  339. static struct bus_mux imx6q_lvds_mux[2] = {
  340. {
  341. .reg = IOMUXC_GPR3,
  342. .shift = 6,
  343. .mask = IMX6Q_GPR3_LVDS0_MUX_CTL_MASK,
  344. }, {
  345. .reg = IOMUXC_GPR3,
  346. .shift = 8,
  347. .mask = IMX6Q_GPR3_LVDS1_MUX_CTL_MASK,
  348. }
  349. };
  350. /*
  351. * For a device declaring compatible = "fsl,imx6q-ldb", "fsl,imx53-ldb",
  352. * of_match_device will walk through this list and take the first entry
  353. * matching any of its compatible values. Therefore, the more generic
  354. * entries (in this case fsl,imx53-ldb) need to be ordered last.
  355. */
  356. static const struct of_device_id imx_ldb_dt_ids[] = {
  357. { .compatible = "fsl,imx6q-ldb", .data = imx6q_lvds_mux, },
  358. { .compatible = "fsl,imx53-ldb", .data = NULL, },
  359. { }
  360. };
  361. MODULE_DEVICE_TABLE(of, imx_ldb_dt_ids);
  362. static int imx_ldb_bind(struct device *dev, struct device *master, void *data)
  363. {
  364. struct drm_device *drm = data;
  365. struct device_node *np = dev->of_node;
  366. const struct of_device_id *of_id =
  367. of_match_device(imx_ldb_dt_ids, dev);
  368. struct device_node *child;
  369. const u8 *edidp;
  370. struct imx_ldb *imx_ldb;
  371. int datawidth;
  372. int mapping;
  373. int dual;
  374. int ret;
  375. int i;
  376. imx_ldb = devm_kzalloc(dev, sizeof(*imx_ldb), GFP_KERNEL);
  377. if (!imx_ldb)
  378. return -ENOMEM;
  379. imx_ldb->regmap = syscon_regmap_lookup_by_phandle(np, "gpr");
  380. if (IS_ERR(imx_ldb->regmap)) {
  381. dev_err(dev, "failed to get parent regmap\n");
  382. return PTR_ERR(imx_ldb->regmap);
  383. }
  384. imx_ldb->dev = dev;
  385. if (of_id)
  386. imx_ldb->lvds_mux = of_id->data;
  387. dual = of_property_read_bool(np, "fsl,dual-channel");
  388. if (dual)
  389. imx_ldb->ldb_ctrl |= LDB_SPLIT_MODE_EN;
  390. /*
  391. * There are three different possible clock mux configurations:
  392. * i.MX53: ipu1_di0_sel, ipu1_di1_sel
  393. * i.MX6q: ipu1_di0_sel, ipu1_di1_sel, ipu2_di0_sel, ipu2_di1_sel
  394. * i.MX6dl: ipu1_di0_sel, ipu1_di1_sel, lcdif_sel
  395. * Map them all to di0_sel...di3_sel.
  396. */
  397. for (i = 0; i < 4; i++) {
  398. char clkname[16];
  399. sprintf(clkname, "di%d_sel", i);
  400. imx_ldb->clk_sel[i] = devm_clk_get(imx_ldb->dev, clkname);
  401. if (IS_ERR(imx_ldb->clk_sel[i])) {
  402. ret = PTR_ERR(imx_ldb->clk_sel[i]);
  403. imx_ldb->clk_sel[i] = NULL;
  404. break;
  405. }
  406. }
  407. if (i == 0)
  408. return ret;
  409. for_each_child_of_node(np, child) {
  410. struct imx_ldb_channel *channel;
  411. ret = of_property_read_u32(child, "reg", &i);
  412. if (ret || i < 0 || i > 1)
  413. return -EINVAL;
  414. if (dual && i > 0) {
  415. dev_warn(dev, "dual-channel mode, ignoring second output\n");
  416. continue;
  417. }
  418. if (!of_device_is_available(child))
  419. continue;
  420. channel = &imx_ldb->channel[i];
  421. channel->ldb = imx_ldb;
  422. channel->chno = i;
  423. channel->child = child;
  424. edidp = of_get_property(child, "edid", &channel->edid_len);
  425. if (edidp) {
  426. channel->edid = kmemdup(edidp, channel->edid_len,
  427. GFP_KERNEL);
  428. } else {
  429. ret = of_get_drm_display_mode(child, &channel->mode, 0);
  430. if (!ret)
  431. channel->mode_valid = 1;
  432. }
  433. ret = of_property_read_u32(child, "fsl,data-width", &datawidth);
  434. if (ret)
  435. datawidth = 0;
  436. else if (datawidth != 18 && datawidth != 24)
  437. return -EINVAL;
  438. mapping = of_get_data_mapping(child);
  439. switch (mapping) {
  440. case LVDS_BIT_MAP_SPWG:
  441. if (datawidth == 24) {
  442. if (i == 0 || dual)
  443. imx_ldb->ldb_ctrl |=
  444. LDB_DATA_WIDTH_CH0_24;
  445. if (i == 1 || dual)
  446. imx_ldb->ldb_ctrl |=
  447. LDB_DATA_WIDTH_CH1_24;
  448. }
  449. break;
  450. case LVDS_BIT_MAP_JEIDA:
  451. if (datawidth == 18) {
  452. dev_err(dev, "JEIDA standard only supported in 24 bit\n");
  453. return -EINVAL;
  454. }
  455. if (i == 0 || dual)
  456. imx_ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH0_24 |
  457. LDB_BIT_MAP_CH0_JEIDA;
  458. if (i == 1 || dual)
  459. imx_ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH1_24 |
  460. LDB_BIT_MAP_CH1_JEIDA;
  461. break;
  462. default:
  463. dev_err(dev, "data mapping not specified or invalid\n");
  464. return -EINVAL;
  465. }
  466. ret = imx_ldb_register(drm, channel);
  467. if (ret)
  468. return ret;
  469. }
  470. dev_set_drvdata(dev, imx_ldb);
  471. return 0;
  472. }
  473. static void imx_ldb_unbind(struct device *dev, struct device *master,
  474. void *data)
  475. {
  476. struct imx_ldb *imx_ldb = dev_get_drvdata(dev);
  477. int i;
  478. for (i = 0; i < 2; i++) {
  479. struct imx_ldb_channel *channel = &imx_ldb->channel[i];
  480. if (!channel->connector.funcs)
  481. continue;
  482. channel->connector.funcs->destroy(&channel->connector);
  483. channel->encoder.funcs->destroy(&channel->encoder);
  484. kfree(channel->edid);
  485. }
  486. }
  487. static const struct component_ops imx_ldb_ops = {
  488. .bind = imx_ldb_bind,
  489. .unbind = imx_ldb_unbind,
  490. };
  491. static int imx_ldb_probe(struct platform_device *pdev)
  492. {
  493. return component_add(&pdev->dev, &imx_ldb_ops);
  494. }
  495. static int imx_ldb_remove(struct platform_device *pdev)
  496. {
  497. component_del(&pdev->dev, &imx_ldb_ops);
  498. return 0;
  499. }
  500. static struct platform_driver imx_ldb_driver = {
  501. .probe = imx_ldb_probe,
  502. .remove = imx_ldb_remove,
  503. .driver = {
  504. .of_match_table = imx_ldb_dt_ids,
  505. .name = DRIVER_NAME,
  506. },
  507. };
  508. module_platform_driver(imx_ldb_driver);
  509. MODULE_DESCRIPTION("i.MX LVDS driver");
  510. MODULE_AUTHOR("Sascha Hauer, Pengutronix");
  511. MODULE_LICENSE("GPL");
  512. MODULE_ALIAS("platform:" DRIVER_NAME);