imx-ldb.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * i.MX drm driver - LVDS display bridge
  4. *
  5. * Copyright (C) 2012 Sascha Hauer, Pengutronix
  6. */
  7. #include <linux/clk.h>
  8. #include <linux/component.h>
  9. #include <linux/i2c.h>
  10. #include <linux/media-bus-format.h>
  11. #include <linux/mfd/syscon.h>
  12. #include <linux/mfd/syscon/imx6q-iomuxc-gpr.h>
  13. #include <linux/module.h>
  14. #include <linux/of.h>
  15. #include <linux/of_graph.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/property.h>
  18. #include <linux/regmap.h>
  19. #include <linux/videodev2.h>
  20. #include <drm/drm_atomic.h>
  21. #include <drm/drm_atomic_helper.h>
  22. #include <drm/drm_bridge.h>
  23. #include <drm/drm_bridge_connector.h>
  24. #include <drm/drm_managed.h>
  25. #include <drm/drm_of.h>
  26. #include <drm/drm_print.h>
  27. #include <drm/drm_probe_helper.h>
  28. #include <drm/drm_simple_kms_helper.h>
  29. #include <drm/bridge/imx.h>
  30. #include "imx-drm.h"
  31. #define DRIVER_NAME "imx-ldb"
  32. #define LDB_CH0_MODE_EN_TO_DI0 (1 << 0)
  33. #define LDB_CH0_MODE_EN_TO_DI1 (3 << 0)
  34. #define LDB_CH0_MODE_EN_MASK (3 << 0)
  35. #define LDB_CH1_MODE_EN_TO_DI0 (1 << 2)
  36. #define LDB_CH1_MODE_EN_TO_DI1 (3 << 2)
  37. #define LDB_CH1_MODE_EN_MASK (3 << 2)
  38. #define LDB_SPLIT_MODE_EN (1 << 4)
  39. #define LDB_DATA_WIDTH_CH0_24 (1 << 5)
  40. #define LDB_BIT_MAP_CH0_JEIDA (1 << 6)
  41. #define LDB_DATA_WIDTH_CH1_24 (1 << 7)
  42. #define LDB_BIT_MAP_CH1_JEIDA (1 << 8)
  43. #define LDB_DI0_VS_POL_ACT_LOW (1 << 9)
  44. #define LDB_DI1_VS_POL_ACT_LOW (1 << 10)
  45. #define LDB_BGREF_RMODE_INT (1 << 15)
  46. struct imx_ldb_channel;
  47. struct imx_ldb_encoder {
  48. struct drm_encoder encoder;
  49. struct imx_ldb_channel *channel;
  50. };
  51. struct imx_ldb;
  52. struct imx_ldb_channel {
  53. struct imx_ldb *ldb;
  54. struct drm_bridge *bridge;
  55. struct device_node *child;
  56. int chno;
  57. u32 bus_format;
  58. };
  59. static inline struct imx_ldb_channel *enc_to_imx_ldb_ch(struct drm_encoder *e)
  60. {
  61. return container_of(e, struct imx_ldb_encoder, encoder)->channel;
  62. }
  63. struct bus_mux {
  64. int reg;
  65. int shift;
  66. int mask;
  67. };
  68. struct imx_ldb {
  69. struct regmap *regmap;
  70. struct device *dev;
  71. struct imx_ldb_channel channel[2];
  72. struct clk *clk[2]; /* our own clock */
  73. struct clk *clk_sel[4]; /* parent of display clock */
  74. struct clk *clk_parent[4]; /* original parent of clk_sel */
  75. struct clk *clk_pll[2]; /* upstream clock we can adjust */
  76. u32 ldb_ctrl;
  77. const struct bus_mux *lvds_mux;
  78. };
  79. static void imx_ldb_ch_set_bus_format(struct imx_ldb_channel *imx_ldb_ch,
  80. u32 bus_format)
  81. {
  82. struct imx_ldb *ldb = imx_ldb_ch->ldb;
  83. int dual = ldb->ldb_ctrl & LDB_SPLIT_MODE_EN;
  84. switch (bus_format) {
  85. case MEDIA_BUS_FMT_RGB666_1X7X3_SPWG:
  86. break;
  87. case MEDIA_BUS_FMT_RGB888_1X7X4_SPWG:
  88. if (imx_ldb_ch->chno == 0 || dual)
  89. ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH0_24;
  90. if (imx_ldb_ch->chno == 1 || dual)
  91. ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH1_24;
  92. break;
  93. case MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA:
  94. if (imx_ldb_ch->chno == 0 || dual)
  95. ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH0_24 |
  96. LDB_BIT_MAP_CH0_JEIDA;
  97. if (imx_ldb_ch->chno == 1 || dual)
  98. ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH1_24 |
  99. LDB_BIT_MAP_CH1_JEIDA;
  100. break;
  101. }
  102. }
  103. static void imx_ldb_set_clock(struct imx_ldb *ldb, int mux, int chno,
  104. unsigned long serial_clk, unsigned long di_clk)
  105. {
  106. int ret;
  107. dev_dbg(ldb->dev, "%s: now: %ld want: %ld\n", __func__,
  108. clk_get_rate(ldb->clk_pll[chno]), serial_clk);
  109. clk_set_rate(ldb->clk_pll[chno], serial_clk);
  110. dev_dbg(ldb->dev, "%s after: %ld\n", __func__,
  111. clk_get_rate(ldb->clk_pll[chno]));
  112. dev_dbg(ldb->dev, "%s: now: %ld want: %ld\n", __func__,
  113. clk_get_rate(ldb->clk[chno]),
  114. (long int)di_clk);
  115. clk_set_rate(ldb->clk[chno], di_clk);
  116. dev_dbg(ldb->dev, "%s after: %ld\n", __func__,
  117. clk_get_rate(ldb->clk[chno]));
  118. /* set display clock mux to LDB input clock */
  119. ret = clk_set_parent(ldb->clk_sel[mux], ldb->clk[chno]);
  120. if (ret)
  121. dev_err(ldb->dev,
  122. "unable to set di%d parent clock to ldb_di%d\n", mux,
  123. chno);
  124. }
  125. static void imx_ldb_encoder_enable(struct drm_encoder *encoder)
  126. {
  127. struct imx_ldb_channel *imx_ldb_ch = enc_to_imx_ldb_ch(encoder);
  128. struct imx_ldb *ldb = imx_ldb_ch->ldb;
  129. int dual = ldb->ldb_ctrl & LDB_SPLIT_MODE_EN;
  130. int mux = drm_of_encoder_active_port_id(imx_ldb_ch->child, encoder);
  131. if (mux < 0 || mux >= ARRAY_SIZE(ldb->clk_sel)) {
  132. dev_warn(ldb->dev, "%s: invalid mux %d\n", __func__, mux);
  133. return;
  134. }
  135. if (dual) {
  136. clk_set_parent(ldb->clk_sel[mux], ldb->clk[0]);
  137. clk_set_parent(ldb->clk_sel[mux], ldb->clk[1]);
  138. clk_prepare_enable(ldb->clk[0]);
  139. clk_prepare_enable(ldb->clk[1]);
  140. } else {
  141. clk_set_parent(ldb->clk_sel[mux], ldb->clk[imx_ldb_ch->chno]);
  142. }
  143. if (imx_ldb_ch == &ldb->channel[0] || dual) {
  144. ldb->ldb_ctrl &= ~LDB_CH0_MODE_EN_MASK;
  145. if (mux == 0 || ldb->lvds_mux)
  146. ldb->ldb_ctrl |= LDB_CH0_MODE_EN_TO_DI0;
  147. else if (mux == 1)
  148. ldb->ldb_ctrl |= LDB_CH0_MODE_EN_TO_DI1;
  149. }
  150. if (imx_ldb_ch == &ldb->channel[1] || dual) {
  151. ldb->ldb_ctrl &= ~LDB_CH1_MODE_EN_MASK;
  152. if (mux == 1 || ldb->lvds_mux)
  153. ldb->ldb_ctrl |= LDB_CH1_MODE_EN_TO_DI1;
  154. else if (mux == 0)
  155. ldb->ldb_ctrl |= LDB_CH1_MODE_EN_TO_DI0;
  156. }
  157. if (ldb->lvds_mux) {
  158. const struct bus_mux *lvds_mux = NULL;
  159. if (imx_ldb_ch == &ldb->channel[0])
  160. lvds_mux = &ldb->lvds_mux[0];
  161. else if (imx_ldb_ch == &ldb->channel[1])
  162. lvds_mux = &ldb->lvds_mux[1];
  163. regmap_update_bits(ldb->regmap, lvds_mux->reg, lvds_mux->mask,
  164. mux << lvds_mux->shift);
  165. }
  166. regmap_write(ldb->regmap, IOMUXC_GPR2, ldb->ldb_ctrl);
  167. }
  168. static void
  169. imx_ldb_encoder_atomic_mode_set(struct drm_encoder *encoder,
  170. struct drm_crtc_state *crtc_state,
  171. struct drm_connector_state *connector_state)
  172. {
  173. struct imx_ldb_channel *imx_ldb_ch = enc_to_imx_ldb_ch(encoder);
  174. struct drm_display_mode *mode = &crtc_state->adjusted_mode;
  175. struct imx_ldb *ldb = imx_ldb_ch->ldb;
  176. int dual = ldb->ldb_ctrl & LDB_SPLIT_MODE_EN;
  177. unsigned long serial_clk;
  178. unsigned long di_clk = mode->clock * 1000;
  179. int mux = drm_of_encoder_active_port_id(imx_ldb_ch->child, encoder);
  180. u32 bus_format = imx_ldb_ch->bus_format;
  181. if (mux < 0 || mux >= ARRAY_SIZE(ldb->clk_sel)) {
  182. dev_warn(ldb->dev, "%s: invalid mux %d\n", __func__, mux);
  183. return;
  184. }
  185. if (mode->clock > 170000) {
  186. dev_warn(ldb->dev,
  187. "%s: mode exceeds 170 MHz pixel clock\n", __func__);
  188. }
  189. if (mode->clock > 85000 && !dual) {
  190. dev_warn(ldb->dev,
  191. "%s: mode exceeds 85 MHz pixel clock\n", __func__);
  192. }
  193. if (!IS_ALIGNED(mode->hdisplay, 8)) {
  194. dev_warn(ldb->dev,
  195. "%s: hdisplay does not align to 8 byte\n", __func__);
  196. }
  197. if (dual) {
  198. serial_clk = 3500UL * mode->clock;
  199. imx_ldb_set_clock(ldb, mux, 0, serial_clk, di_clk);
  200. imx_ldb_set_clock(ldb, mux, 1, serial_clk, di_clk);
  201. } else {
  202. serial_clk = 7000UL * mode->clock;
  203. imx_ldb_set_clock(ldb, mux, imx_ldb_ch->chno, serial_clk,
  204. di_clk);
  205. }
  206. /* FIXME - assumes straight connections DI0 --> CH0, DI1 --> CH1 */
  207. if (imx_ldb_ch == &ldb->channel[0] || dual) {
  208. if (mode->flags & DRM_MODE_FLAG_NVSYNC)
  209. ldb->ldb_ctrl |= LDB_DI0_VS_POL_ACT_LOW;
  210. else if (mode->flags & DRM_MODE_FLAG_PVSYNC)
  211. ldb->ldb_ctrl &= ~LDB_DI0_VS_POL_ACT_LOW;
  212. }
  213. if (imx_ldb_ch == &ldb->channel[1] || dual) {
  214. if (mode->flags & DRM_MODE_FLAG_NVSYNC)
  215. ldb->ldb_ctrl |= LDB_DI1_VS_POL_ACT_LOW;
  216. else if (mode->flags & DRM_MODE_FLAG_PVSYNC)
  217. ldb->ldb_ctrl &= ~LDB_DI1_VS_POL_ACT_LOW;
  218. }
  219. if (!bus_format) {
  220. struct drm_connector *connector = connector_state->connector;
  221. struct drm_display_info *di = &connector->display_info;
  222. if (di->num_bus_formats)
  223. bus_format = di->bus_formats[0];
  224. }
  225. imx_ldb_ch_set_bus_format(imx_ldb_ch, bus_format);
  226. }
  227. static void imx_ldb_encoder_disable(struct drm_encoder *encoder)
  228. {
  229. struct imx_ldb_channel *imx_ldb_ch = enc_to_imx_ldb_ch(encoder);
  230. struct imx_ldb *ldb = imx_ldb_ch->ldb;
  231. int dual = ldb->ldb_ctrl & LDB_SPLIT_MODE_EN;
  232. int mux, ret;
  233. if (imx_ldb_ch == &ldb->channel[0] || dual)
  234. ldb->ldb_ctrl &= ~LDB_CH0_MODE_EN_MASK;
  235. if (imx_ldb_ch == &ldb->channel[1] || dual)
  236. ldb->ldb_ctrl &= ~LDB_CH1_MODE_EN_MASK;
  237. regmap_write(ldb->regmap, IOMUXC_GPR2, ldb->ldb_ctrl);
  238. if (dual) {
  239. clk_disable_unprepare(ldb->clk[0]);
  240. clk_disable_unprepare(ldb->clk[1]);
  241. }
  242. if (ldb->lvds_mux) {
  243. const struct bus_mux *lvds_mux = NULL;
  244. if (imx_ldb_ch == &ldb->channel[0])
  245. lvds_mux = &ldb->lvds_mux[0];
  246. else if (imx_ldb_ch == &ldb->channel[1])
  247. lvds_mux = &ldb->lvds_mux[1];
  248. regmap_read(ldb->regmap, lvds_mux->reg, &mux);
  249. mux &= lvds_mux->mask;
  250. mux >>= lvds_mux->shift;
  251. } else {
  252. mux = (imx_ldb_ch == &ldb->channel[0]) ? 0 : 1;
  253. }
  254. /* set display clock mux back to original input clock */
  255. ret = clk_set_parent(ldb->clk_sel[mux], ldb->clk_parent[mux]);
  256. if (ret)
  257. dev_err(ldb->dev,
  258. "unable to set di%d parent clock to original parent\n",
  259. mux);
  260. }
  261. static int imx_ldb_encoder_atomic_check(struct drm_encoder *encoder,
  262. struct drm_crtc_state *crtc_state,
  263. struct drm_connector_state *conn_state)
  264. {
  265. struct imx_crtc_state *imx_crtc_state = to_imx_crtc_state(crtc_state);
  266. struct imx_ldb_channel *imx_ldb_ch = enc_to_imx_ldb_ch(encoder);
  267. struct drm_display_info *di = &conn_state->connector->display_info;
  268. u32 bus_format = imx_ldb_ch->bus_format;
  269. /* Bus format description in DT overrides connector display info. */
  270. if (!bus_format && di->num_bus_formats) {
  271. bus_format = di->bus_formats[0];
  272. } else {
  273. bus_format = imx_ldb_ch->bus_format;
  274. }
  275. imx_crtc_state->bus_flags = di->bus_flags;
  276. switch (bus_format) {
  277. case MEDIA_BUS_FMT_RGB666_1X7X3_SPWG:
  278. imx_crtc_state->bus_format = MEDIA_BUS_FMT_RGB666_1X18;
  279. break;
  280. case MEDIA_BUS_FMT_RGB888_1X7X4_SPWG:
  281. case MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA:
  282. imx_crtc_state->bus_format = MEDIA_BUS_FMT_RGB888_1X24;
  283. break;
  284. default:
  285. return -EINVAL;
  286. }
  287. imx_crtc_state->di_hsync_pin = 2;
  288. imx_crtc_state->di_vsync_pin = 3;
  289. return 0;
  290. }
  291. static const struct drm_encoder_helper_funcs imx_ldb_encoder_helper_funcs = {
  292. .atomic_mode_set = imx_ldb_encoder_atomic_mode_set,
  293. .enable = imx_ldb_encoder_enable,
  294. .disable = imx_ldb_encoder_disable,
  295. .atomic_check = imx_ldb_encoder_atomic_check,
  296. };
  297. static int imx_ldb_get_clk(struct imx_ldb *ldb, int chno)
  298. {
  299. char clkname[16];
  300. snprintf(clkname, sizeof(clkname), "di%d", chno);
  301. ldb->clk[chno] = devm_clk_get(ldb->dev, clkname);
  302. if (IS_ERR(ldb->clk[chno]))
  303. return PTR_ERR(ldb->clk[chno]);
  304. snprintf(clkname, sizeof(clkname), "di%d_pll", chno);
  305. ldb->clk_pll[chno] = devm_clk_get(ldb->dev, clkname);
  306. return PTR_ERR_OR_ZERO(ldb->clk_pll[chno]);
  307. }
  308. static int imx_ldb_register(struct drm_device *drm,
  309. struct imx_ldb_channel *imx_ldb_ch)
  310. {
  311. struct imx_ldb *ldb = imx_ldb_ch->ldb;
  312. struct imx_ldb_encoder *ldb_encoder;
  313. struct drm_connector *connector;
  314. struct drm_encoder *encoder;
  315. int ret;
  316. ldb_encoder = drmm_simple_encoder_alloc(drm, struct imx_ldb_encoder,
  317. encoder, DRM_MODE_ENCODER_LVDS);
  318. if (IS_ERR(ldb_encoder))
  319. return PTR_ERR(ldb_encoder);
  320. ldb_encoder->channel = imx_ldb_ch;
  321. encoder = &ldb_encoder->encoder;
  322. ret = imx_drm_encoder_parse_of(drm, encoder, imx_ldb_ch->child);
  323. if (ret)
  324. return ret;
  325. ret = imx_ldb_get_clk(ldb, imx_ldb_ch->chno);
  326. if (ret)
  327. return ret;
  328. if (ldb->ldb_ctrl & LDB_SPLIT_MODE_EN) {
  329. ret = imx_ldb_get_clk(ldb, 1);
  330. if (ret)
  331. return ret;
  332. }
  333. drm_encoder_helper_add(encoder, &imx_ldb_encoder_helper_funcs);
  334. ret = drm_bridge_attach(encoder, imx_ldb_ch->bridge, NULL,
  335. DRM_BRIDGE_ATTACH_NO_CONNECTOR);
  336. if (ret)
  337. return ret;
  338. connector = drm_bridge_connector_init(drm, encoder);
  339. if (IS_ERR(connector))
  340. return PTR_ERR(connector);
  341. drm_connector_attach_encoder(connector, encoder);
  342. return 0;
  343. }
  344. struct imx_ldb_bit_mapping {
  345. u32 bus_format;
  346. u32 datawidth;
  347. const char * const mapping;
  348. };
  349. static const struct imx_ldb_bit_mapping imx_ldb_bit_mappings[] = {
  350. { MEDIA_BUS_FMT_RGB666_1X7X3_SPWG, 18, "spwg" },
  351. { MEDIA_BUS_FMT_RGB888_1X7X4_SPWG, 24, "spwg" },
  352. { MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA, 24, "jeida" },
  353. };
  354. static u32 of_get_bus_format(struct device *dev, struct device_node *np)
  355. {
  356. const char *bm;
  357. u32 datawidth = 0;
  358. int ret, i;
  359. ret = of_property_read_string(np, "fsl,data-mapping", &bm);
  360. if (ret < 0)
  361. return ret;
  362. of_property_read_u32(np, "fsl,data-width", &datawidth);
  363. for (i = 0; i < ARRAY_SIZE(imx_ldb_bit_mappings); i++) {
  364. if (!strcasecmp(bm, imx_ldb_bit_mappings[i].mapping) &&
  365. datawidth == imx_ldb_bit_mappings[i].datawidth)
  366. return imx_ldb_bit_mappings[i].bus_format;
  367. }
  368. dev_err(dev, "invalid data mapping: %d-bit \"%s\"\n", datawidth, bm);
  369. return -ENOENT;
  370. }
  371. static struct bus_mux imx6q_lvds_mux[2] = {
  372. {
  373. .reg = IOMUXC_GPR3,
  374. .shift = 6,
  375. .mask = IMX6Q_GPR3_LVDS0_MUX_CTL_MASK,
  376. }, {
  377. .reg = IOMUXC_GPR3,
  378. .shift = 8,
  379. .mask = IMX6Q_GPR3_LVDS1_MUX_CTL_MASK,
  380. }
  381. };
  382. /*
  383. * For a device declaring compatible = "fsl,imx6q-ldb", "fsl,imx53-ldb",
  384. * of_match_device will walk through this list and take the first entry
  385. * matching any of its compatible values. Therefore, the more generic
  386. * entries (in this case fsl,imx53-ldb) need to be ordered last.
  387. */
  388. static const struct of_device_id imx_ldb_dt_ids[] = {
  389. { .compatible = "fsl,imx6q-ldb", .data = imx6q_lvds_mux, },
  390. { .compatible = "fsl,imx53-ldb", .data = NULL, },
  391. { }
  392. };
  393. MODULE_DEVICE_TABLE(of, imx_ldb_dt_ids);
  394. static int imx_ldb_bind(struct device *dev, struct device *master, void *data)
  395. {
  396. struct drm_device *drm = data;
  397. struct imx_ldb *imx_ldb = dev_get_drvdata(dev);
  398. int ret;
  399. int i;
  400. for (i = 0; i < 2; i++) {
  401. struct imx_ldb_channel *channel = &imx_ldb->channel[i];
  402. if (!channel->ldb)
  403. continue;
  404. ret = imx_ldb_register(drm, channel);
  405. if (ret)
  406. return ret;
  407. }
  408. return 0;
  409. }
  410. static const struct component_ops imx_ldb_ops = {
  411. .bind = imx_ldb_bind,
  412. };
  413. static int imx_ldb_probe(struct platform_device *pdev)
  414. {
  415. struct device *dev = &pdev->dev;
  416. struct device_node *np = dev->of_node;
  417. struct device_node *child;
  418. struct imx_ldb *imx_ldb;
  419. int dual;
  420. int ret;
  421. int i;
  422. imx_ldb = devm_kzalloc(dev, sizeof(*imx_ldb), GFP_KERNEL);
  423. if (!imx_ldb)
  424. return -ENOMEM;
  425. imx_ldb->regmap = syscon_regmap_lookup_by_phandle(np, "gpr");
  426. if (IS_ERR(imx_ldb->regmap)) {
  427. dev_err(dev, "failed to get parent regmap\n");
  428. return PTR_ERR(imx_ldb->regmap);
  429. }
  430. /* disable LDB by resetting the control register to POR default */
  431. regmap_write(imx_ldb->regmap, IOMUXC_GPR2, 0);
  432. imx_ldb->dev = dev;
  433. imx_ldb->lvds_mux = device_get_match_data(dev);
  434. dual = of_property_read_bool(np, "fsl,dual-channel");
  435. if (dual)
  436. imx_ldb->ldb_ctrl |= LDB_SPLIT_MODE_EN;
  437. /*
  438. * There are three different possible clock mux configurations:
  439. * i.MX53: ipu1_di0_sel, ipu1_di1_sel
  440. * i.MX6q: ipu1_di0_sel, ipu1_di1_sel, ipu2_di0_sel, ipu2_di1_sel
  441. * i.MX6dl: ipu1_di0_sel, ipu1_di1_sel, lcdif_sel
  442. * Map them all to di0_sel...di3_sel.
  443. */
  444. for (i = 0; i < 4; i++) {
  445. char clkname[16];
  446. snprintf(clkname, sizeof(clkname), "di%d_sel", i);
  447. imx_ldb->clk_sel[i] = devm_clk_get(imx_ldb->dev, clkname);
  448. if (IS_ERR(imx_ldb->clk_sel[i])) {
  449. ret = PTR_ERR(imx_ldb->clk_sel[i]);
  450. imx_ldb->clk_sel[i] = NULL;
  451. break;
  452. }
  453. imx_ldb->clk_parent[i] = clk_get_parent(imx_ldb->clk_sel[i]);
  454. }
  455. if (i == 0)
  456. return ret;
  457. for_each_child_of_node(np, child) {
  458. struct imx_ldb_channel *channel;
  459. int bus_format;
  460. ret = of_property_read_u32(child, "reg", &i);
  461. if (ret || i < 0 || i > 1) {
  462. ret = -EINVAL;
  463. goto free_child;
  464. }
  465. if (!of_device_is_available(child))
  466. continue;
  467. if (dual && i > 0) {
  468. dev_warn(dev, "dual-channel mode, ignoring second output\n");
  469. continue;
  470. }
  471. channel = &imx_ldb->channel[i];
  472. channel->ldb = imx_ldb;
  473. channel->chno = i;
  474. /*
  475. * The output port is port@4 with an external 4-port mux or
  476. * port@2 with the internal 2-port mux.
  477. */
  478. channel->bridge = devm_drm_of_get_bridge(dev, child,
  479. imx_ldb->lvds_mux ? 4 : 2, 0);
  480. if (IS_ERR(channel->bridge)) {
  481. ret = PTR_ERR(channel->bridge);
  482. if (ret != -ENODEV)
  483. goto free_child;
  484. channel->bridge = NULL;
  485. }
  486. bus_format = of_get_bus_format(dev, child);
  487. /*
  488. * If no bus format was specified in the device tree,
  489. * we can still get it from the connected panel later.
  490. */
  491. if (bus_format == -EINVAL && channel->bridge)
  492. bus_format = 0;
  493. if (bus_format < 0) {
  494. dev_err(dev, "could not determine data mapping: %d\n",
  495. bus_format);
  496. ret = bus_format;
  497. goto free_child;
  498. }
  499. channel->bus_format = bus_format;
  500. /*
  501. * legacy bridge doesn't handle bus_format, so create it after
  502. * checking the bus_format property.
  503. */
  504. if (!channel->bridge) {
  505. channel->bridge = devm_imx_drm_legacy_bridge(dev, child,
  506. DRM_MODE_CONNECTOR_LVDS);
  507. if (IS_ERR(channel->bridge)) {
  508. ret = PTR_ERR(channel->bridge);
  509. goto free_child;
  510. }
  511. }
  512. channel->child = child;
  513. }
  514. platform_set_drvdata(pdev, imx_ldb);
  515. return component_add(&pdev->dev, &imx_ldb_ops);
  516. free_child:
  517. of_node_put(child);
  518. return ret;
  519. }
  520. static void imx_ldb_remove(struct platform_device *pdev)
  521. {
  522. component_del(&pdev->dev, &imx_ldb_ops);
  523. }
  524. static struct platform_driver imx_ldb_driver = {
  525. .probe = imx_ldb_probe,
  526. .remove = imx_ldb_remove,
  527. .driver = {
  528. .of_match_table = imx_ldb_dt_ids,
  529. .name = DRIVER_NAME,
  530. },
  531. };
  532. module_platform_driver(imx_ldb_driver);
  533. MODULE_DESCRIPTION("i.MX LVDS driver");
  534. MODULE_AUTHOR("Sascha Hauer, Pengutronix");
  535. MODULE_LICENSE("GPL");