imx-ldb.c 16 KB

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