imx-ldb.c 17 KB

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