dw_hdmi-imx.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /* Copyright (C) 2011-2013 Freescale Semiconductor, Inc.
  2. *
  3. * derived from imx-hdmi.c(renamed to bridge/dw_hdmi.c now)
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. #include <linux/module.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/component.h>
  12. #include <linux/mfd/syscon.h>
  13. #include <linux/mfd/syscon/imx6q-iomuxc-gpr.h>
  14. #include <drm/bridge/dw_hdmi.h>
  15. #include <video/imx-ipu-v3.h>
  16. #include <linux/regmap.h>
  17. #include <drm/drm_of.h>
  18. #include <drm/drmP.h>
  19. #include <drm/drm_crtc_helper.h>
  20. #include <drm/drm_edid.h>
  21. #include <drm/drm_encoder_slave.h>
  22. #include "imx-drm.h"
  23. struct imx_hdmi {
  24. struct device *dev;
  25. struct drm_encoder encoder;
  26. struct regmap *regmap;
  27. };
  28. static inline struct imx_hdmi *enc_to_imx_hdmi(struct drm_encoder *e)
  29. {
  30. return container_of(e, struct imx_hdmi, encoder);
  31. }
  32. static const struct dw_hdmi_mpll_config imx_mpll_cfg[] = {
  33. {
  34. 45250000, {
  35. { 0x01e0, 0x0000 },
  36. { 0x21e1, 0x0000 },
  37. { 0x41e2, 0x0000 }
  38. },
  39. }, {
  40. 92500000, {
  41. { 0x0140, 0x0005 },
  42. { 0x2141, 0x0005 },
  43. { 0x4142, 0x0005 },
  44. },
  45. }, {
  46. 148500000, {
  47. { 0x00a0, 0x000a },
  48. { 0x20a1, 0x000a },
  49. { 0x40a2, 0x000a },
  50. },
  51. }, {
  52. 216000000, {
  53. { 0x00a0, 0x000a },
  54. { 0x2001, 0x000f },
  55. { 0x4002, 0x000f },
  56. },
  57. }, {
  58. ~0UL, {
  59. { 0x0000, 0x0000 },
  60. { 0x0000, 0x0000 },
  61. { 0x0000, 0x0000 },
  62. },
  63. }
  64. };
  65. static const struct dw_hdmi_curr_ctrl imx_cur_ctr[] = {
  66. /* pixelclk bpp8 bpp10 bpp12 */
  67. {
  68. 54000000, { 0x091c, 0x091c, 0x06dc },
  69. }, {
  70. 58400000, { 0x091c, 0x06dc, 0x06dc },
  71. }, {
  72. 72000000, { 0x06dc, 0x06dc, 0x091c },
  73. }, {
  74. 74250000, { 0x06dc, 0x0b5c, 0x091c },
  75. }, {
  76. 118800000, { 0x091c, 0x091c, 0x06dc },
  77. }, {
  78. 216000000, { 0x06dc, 0x0b5c, 0x091c },
  79. }, {
  80. ~0UL, { 0x0000, 0x0000, 0x0000 },
  81. },
  82. };
  83. /*
  84. * Resistance term 133Ohm Cfg
  85. * PREEMP config 0.00
  86. * TX/CK level 10
  87. */
  88. static const struct dw_hdmi_phy_config imx_phy_config[] = {
  89. /*pixelclk symbol term vlev */
  90. { 216000000, 0x800d, 0x0005, 0x01ad},
  91. { ~0UL, 0x0000, 0x0000, 0x0000}
  92. };
  93. static int dw_hdmi_imx_parse_dt(struct imx_hdmi *hdmi)
  94. {
  95. struct device_node *np = hdmi->dev->of_node;
  96. hdmi->regmap = syscon_regmap_lookup_by_phandle(np, "gpr");
  97. if (IS_ERR(hdmi->regmap)) {
  98. dev_err(hdmi->dev, "Unable to get gpr\n");
  99. return PTR_ERR(hdmi->regmap);
  100. }
  101. return 0;
  102. }
  103. static void dw_hdmi_imx_encoder_disable(struct drm_encoder *encoder)
  104. {
  105. }
  106. static void dw_hdmi_imx_encoder_enable(struct drm_encoder *encoder)
  107. {
  108. struct imx_hdmi *hdmi = enc_to_imx_hdmi(encoder);
  109. int mux = drm_of_encoder_active_port_id(hdmi->dev->of_node, encoder);
  110. regmap_update_bits(hdmi->regmap, IOMUXC_GPR3,
  111. IMX6Q_GPR3_HDMI_MUX_CTL_MASK,
  112. mux << IMX6Q_GPR3_HDMI_MUX_CTL_SHIFT);
  113. }
  114. static int dw_hdmi_imx_atomic_check(struct drm_encoder *encoder,
  115. struct drm_crtc_state *crtc_state,
  116. struct drm_connector_state *conn_state)
  117. {
  118. struct imx_crtc_state *imx_crtc_state = to_imx_crtc_state(crtc_state);
  119. imx_crtc_state->bus_format = MEDIA_BUS_FMT_RGB888_1X24;
  120. imx_crtc_state->di_hsync_pin = 2;
  121. imx_crtc_state->di_vsync_pin = 3;
  122. return 0;
  123. }
  124. static const struct drm_encoder_helper_funcs dw_hdmi_imx_encoder_helper_funcs = {
  125. .enable = dw_hdmi_imx_encoder_enable,
  126. .disable = dw_hdmi_imx_encoder_disable,
  127. .atomic_check = dw_hdmi_imx_atomic_check,
  128. };
  129. static const struct drm_encoder_funcs dw_hdmi_imx_encoder_funcs = {
  130. .destroy = drm_encoder_cleanup,
  131. };
  132. static enum drm_mode_status imx6q_hdmi_mode_valid(struct drm_connector *con,
  133. struct drm_display_mode *mode)
  134. {
  135. if (mode->clock < 13500)
  136. return MODE_CLOCK_LOW;
  137. /* FIXME: Hardware is capable of 266MHz, but setup data is missing. */
  138. if (mode->clock > 216000)
  139. return MODE_CLOCK_HIGH;
  140. return MODE_OK;
  141. }
  142. static enum drm_mode_status imx6dl_hdmi_mode_valid(struct drm_connector *con,
  143. struct drm_display_mode *mode)
  144. {
  145. if (mode->clock < 13500)
  146. return MODE_CLOCK_LOW;
  147. /* FIXME: Hardware is capable of 270MHz, but setup data is missing. */
  148. if (mode->clock > 216000)
  149. return MODE_CLOCK_HIGH;
  150. return MODE_OK;
  151. }
  152. static struct dw_hdmi_plat_data imx6q_hdmi_drv_data = {
  153. .mpll_cfg = imx_mpll_cfg,
  154. .cur_ctr = imx_cur_ctr,
  155. .phy_config = imx_phy_config,
  156. .dev_type = IMX6Q_HDMI,
  157. .mode_valid = imx6q_hdmi_mode_valid,
  158. };
  159. static struct dw_hdmi_plat_data imx6dl_hdmi_drv_data = {
  160. .mpll_cfg = imx_mpll_cfg,
  161. .cur_ctr = imx_cur_ctr,
  162. .phy_config = imx_phy_config,
  163. .dev_type = IMX6DL_HDMI,
  164. .mode_valid = imx6dl_hdmi_mode_valid,
  165. };
  166. static const struct of_device_id dw_hdmi_imx_dt_ids[] = {
  167. { .compatible = "fsl,imx6q-hdmi",
  168. .data = &imx6q_hdmi_drv_data
  169. }, {
  170. .compatible = "fsl,imx6dl-hdmi",
  171. .data = &imx6dl_hdmi_drv_data
  172. },
  173. {},
  174. };
  175. MODULE_DEVICE_TABLE(of, dw_hdmi_imx_dt_ids);
  176. static int dw_hdmi_imx_bind(struct device *dev, struct device *master,
  177. void *data)
  178. {
  179. struct platform_device *pdev = to_platform_device(dev);
  180. const struct dw_hdmi_plat_data *plat_data;
  181. const struct of_device_id *match;
  182. struct drm_device *drm = data;
  183. struct drm_encoder *encoder;
  184. struct imx_hdmi *hdmi;
  185. struct resource *iores;
  186. int irq;
  187. int ret;
  188. if (!pdev->dev.of_node)
  189. return -ENODEV;
  190. hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL);
  191. if (!hdmi)
  192. return -ENOMEM;
  193. match = of_match_node(dw_hdmi_imx_dt_ids, pdev->dev.of_node);
  194. plat_data = match->data;
  195. hdmi->dev = &pdev->dev;
  196. encoder = &hdmi->encoder;
  197. irq = platform_get_irq(pdev, 0);
  198. if (irq < 0)
  199. return irq;
  200. iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  201. if (!iores)
  202. return -ENXIO;
  203. encoder->possible_crtcs = drm_of_find_possible_crtcs(drm, dev->of_node);
  204. /*
  205. * If we failed to find the CRTC(s) which this encoder is
  206. * supposed to be connected to, it's because the CRTC has
  207. * not been registered yet. Defer probing, and hope that
  208. * the required CRTC is added later.
  209. */
  210. if (encoder->possible_crtcs == 0)
  211. return -EPROBE_DEFER;
  212. ret = dw_hdmi_imx_parse_dt(hdmi);
  213. if (ret < 0)
  214. return ret;
  215. drm_encoder_helper_add(encoder, &dw_hdmi_imx_encoder_helper_funcs);
  216. drm_encoder_init(drm, encoder, &dw_hdmi_imx_encoder_funcs,
  217. DRM_MODE_ENCODER_TMDS, NULL);
  218. ret = dw_hdmi_bind(dev, master, data, encoder, iores, irq, plat_data);
  219. /*
  220. * If dw_hdmi_bind() fails we'll never call dw_hdmi_unbind(),
  221. * which would have called the encoder cleanup. Do it manually.
  222. */
  223. if (ret)
  224. drm_encoder_cleanup(encoder);
  225. return ret;
  226. }
  227. static void dw_hdmi_imx_unbind(struct device *dev, struct device *master,
  228. void *data)
  229. {
  230. return dw_hdmi_unbind(dev, master, data);
  231. }
  232. static const struct component_ops dw_hdmi_imx_ops = {
  233. .bind = dw_hdmi_imx_bind,
  234. .unbind = dw_hdmi_imx_unbind,
  235. };
  236. static int dw_hdmi_imx_probe(struct platform_device *pdev)
  237. {
  238. return component_add(&pdev->dev, &dw_hdmi_imx_ops);
  239. }
  240. static int dw_hdmi_imx_remove(struct platform_device *pdev)
  241. {
  242. component_del(&pdev->dev, &dw_hdmi_imx_ops);
  243. return 0;
  244. }
  245. static struct platform_driver dw_hdmi_imx_platform_driver = {
  246. .probe = dw_hdmi_imx_probe,
  247. .remove = dw_hdmi_imx_remove,
  248. .driver = {
  249. .name = "dwhdmi-imx",
  250. .of_match_table = dw_hdmi_imx_dt_ids,
  251. },
  252. };
  253. module_platform_driver(dw_hdmi_imx_platform_driver);
  254. MODULE_AUTHOR("Andy Yan <andy.yan@rock-chips.com>");
  255. MODULE_AUTHOR("Yakir Yang <ykk@rock-chips.com>");
  256. MODULE_DESCRIPTION("IMX6 Specific DW-HDMI Driver Extension");
  257. MODULE_LICENSE("GPL");
  258. MODULE_ALIAS("platform:dwhdmi-imx");