dw_hdmi-imx.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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 const struct dw_hdmi_mpll_config imx_mpll_cfg[] = {
  29. {
  30. 45250000, {
  31. { 0x01e0, 0x0000 },
  32. { 0x21e1, 0x0000 },
  33. { 0x41e2, 0x0000 }
  34. },
  35. }, {
  36. 92500000, {
  37. { 0x0140, 0x0005 },
  38. { 0x2141, 0x0005 },
  39. { 0x4142, 0x0005 },
  40. },
  41. }, {
  42. 148500000, {
  43. { 0x00a0, 0x000a },
  44. { 0x20a1, 0x000a },
  45. { 0x40a2, 0x000a },
  46. },
  47. }, {
  48. ~0UL, {
  49. { 0x00a0, 0x000a },
  50. { 0x2001, 0x000f },
  51. { 0x4002, 0x000f },
  52. },
  53. }
  54. };
  55. static const struct dw_hdmi_curr_ctrl imx_cur_ctr[] = {
  56. /* pixelclk bpp8 bpp10 bpp12 */
  57. {
  58. 54000000, { 0x091c, 0x091c, 0x06dc },
  59. }, {
  60. 58400000, { 0x091c, 0x06dc, 0x06dc },
  61. }, {
  62. 72000000, { 0x06dc, 0x06dc, 0x091c },
  63. }, {
  64. 74250000, { 0x06dc, 0x0b5c, 0x091c },
  65. }, {
  66. 118800000, { 0x091c, 0x091c, 0x06dc },
  67. }, {
  68. 216000000, { 0x06dc, 0x0b5c, 0x091c },
  69. }, {
  70. ~0UL, { 0x0000, 0x0000, 0x0000 },
  71. },
  72. };
  73. /*
  74. * Resistance term 133Ohm Cfg
  75. * PREEMP config 0.00
  76. * TX/CK level 10
  77. */
  78. static const struct dw_hdmi_phy_config imx_phy_config[] = {
  79. /*pixelclk symbol term vlev */
  80. { 148500000, 0x800d, 0x0005, 0x01ad},
  81. { ~0UL, 0x0000, 0x0000, 0x0000}
  82. };
  83. static int dw_hdmi_imx_parse_dt(struct imx_hdmi *hdmi)
  84. {
  85. struct device_node *np = hdmi->dev->of_node;
  86. hdmi->regmap = syscon_regmap_lookup_by_phandle(np, "gpr");
  87. if (IS_ERR(hdmi->regmap)) {
  88. dev_err(hdmi->dev, "Unable to get gpr\n");
  89. return PTR_ERR(hdmi->regmap);
  90. }
  91. return 0;
  92. }
  93. static void dw_hdmi_imx_encoder_disable(struct drm_encoder *encoder)
  94. {
  95. }
  96. static bool dw_hdmi_imx_encoder_mode_fixup(struct drm_encoder *encoder,
  97. const struct drm_display_mode *mode,
  98. struct drm_display_mode *adj_mode)
  99. {
  100. return true;
  101. }
  102. static void dw_hdmi_imx_encoder_mode_set(struct drm_encoder *encoder,
  103. struct drm_display_mode *mode,
  104. struct drm_display_mode *adj_mode)
  105. {
  106. }
  107. static void dw_hdmi_imx_encoder_commit(struct drm_encoder *encoder)
  108. {
  109. struct imx_hdmi *hdmi = container_of(encoder, struct imx_hdmi, encoder);
  110. int mux = imx_drm_encoder_get_mux_id(hdmi->dev->of_node, encoder);
  111. regmap_update_bits(hdmi->regmap, IOMUXC_GPR3,
  112. IMX6Q_GPR3_HDMI_MUX_CTL_MASK,
  113. mux << IMX6Q_GPR3_HDMI_MUX_CTL_SHIFT);
  114. }
  115. static void dw_hdmi_imx_encoder_prepare(struct drm_encoder *encoder)
  116. {
  117. imx_drm_set_bus_format(encoder, MEDIA_BUS_FMT_RGB888_1X24);
  118. }
  119. static struct drm_encoder_helper_funcs dw_hdmi_imx_encoder_helper_funcs = {
  120. .mode_fixup = dw_hdmi_imx_encoder_mode_fixup,
  121. .mode_set = dw_hdmi_imx_encoder_mode_set,
  122. .prepare = dw_hdmi_imx_encoder_prepare,
  123. .commit = dw_hdmi_imx_encoder_commit,
  124. .disable = dw_hdmi_imx_encoder_disable,
  125. };
  126. static struct drm_encoder_funcs dw_hdmi_imx_encoder_funcs = {
  127. .destroy = drm_encoder_cleanup,
  128. };
  129. static enum drm_mode_status imx6q_hdmi_mode_valid(struct drm_connector *con,
  130. struct drm_display_mode *mode)
  131. {
  132. if (mode->clock < 13500)
  133. return MODE_CLOCK_LOW;
  134. if (mode->clock > 266000)
  135. return MODE_CLOCK_HIGH;
  136. return MODE_OK;
  137. }
  138. static enum drm_mode_status imx6dl_hdmi_mode_valid(struct drm_connector *con,
  139. struct drm_display_mode *mode)
  140. {
  141. if (mode->clock < 13500)
  142. return MODE_CLOCK_LOW;
  143. if (mode->clock > 270000)
  144. return MODE_CLOCK_HIGH;
  145. return MODE_OK;
  146. }
  147. static struct dw_hdmi_plat_data imx6q_hdmi_drv_data = {
  148. .mpll_cfg = imx_mpll_cfg,
  149. .cur_ctr = imx_cur_ctr,
  150. .phy_config = imx_phy_config,
  151. .dev_type = IMX6Q_HDMI,
  152. .mode_valid = imx6q_hdmi_mode_valid,
  153. };
  154. static struct dw_hdmi_plat_data imx6dl_hdmi_drv_data = {
  155. .mpll_cfg = imx_mpll_cfg,
  156. .cur_ctr = imx_cur_ctr,
  157. .phy_config = imx_phy_config,
  158. .dev_type = IMX6DL_HDMI,
  159. .mode_valid = imx6dl_hdmi_mode_valid,
  160. };
  161. static const struct of_device_id dw_hdmi_imx_dt_ids[] = {
  162. { .compatible = "fsl,imx6q-hdmi",
  163. .data = &imx6q_hdmi_drv_data
  164. }, {
  165. .compatible = "fsl,imx6dl-hdmi",
  166. .data = &imx6dl_hdmi_drv_data
  167. },
  168. {},
  169. };
  170. MODULE_DEVICE_TABLE(of, dw_hdmi_imx_dt_ids);
  171. static int dw_hdmi_imx_bind(struct device *dev, struct device *master,
  172. void *data)
  173. {
  174. struct platform_device *pdev = to_platform_device(dev);
  175. const struct dw_hdmi_plat_data *plat_data;
  176. const struct of_device_id *match;
  177. struct drm_device *drm = data;
  178. struct drm_encoder *encoder;
  179. struct imx_hdmi *hdmi;
  180. struct resource *iores;
  181. int irq;
  182. int ret;
  183. if (!pdev->dev.of_node)
  184. return -ENODEV;
  185. hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL);
  186. if (!hdmi)
  187. return -ENOMEM;
  188. match = of_match_node(dw_hdmi_imx_dt_ids, pdev->dev.of_node);
  189. plat_data = match->data;
  190. hdmi->dev = &pdev->dev;
  191. encoder = &hdmi->encoder;
  192. irq = platform_get_irq(pdev, 0);
  193. if (irq < 0)
  194. return irq;
  195. iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  196. if (!iores)
  197. return -ENXIO;
  198. platform_set_drvdata(pdev, hdmi);
  199. encoder->possible_crtcs = drm_of_find_possible_crtcs(drm, dev->of_node);
  200. /*
  201. * If we failed to find the CRTC(s) which this encoder is
  202. * supposed to be connected to, it's because the CRTC has
  203. * not been registered yet. Defer probing, and hope that
  204. * the required CRTC is added later.
  205. */
  206. if (encoder->possible_crtcs == 0)
  207. return -EPROBE_DEFER;
  208. ret = dw_hdmi_imx_parse_dt(hdmi);
  209. if (ret < 0)
  210. return ret;
  211. drm_encoder_helper_add(encoder, &dw_hdmi_imx_encoder_helper_funcs);
  212. drm_encoder_init(drm, encoder, &dw_hdmi_imx_encoder_funcs,
  213. DRM_MODE_ENCODER_TMDS);
  214. return dw_hdmi_bind(dev, master, data, encoder, iores, irq, plat_data);
  215. }
  216. static void dw_hdmi_imx_unbind(struct device *dev, struct device *master,
  217. void *data)
  218. {
  219. return dw_hdmi_unbind(dev, master, data);
  220. }
  221. static const struct component_ops dw_hdmi_imx_ops = {
  222. .bind = dw_hdmi_imx_bind,
  223. .unbind = dw_hdmi_imx_unbind,
  224. };
  225. static int dw_hdmi_imx_probe(struct platform_device *pdev)
  226. {
  227. return component_add(&pdev->dev, &dw_hdmi_imx_ops);
  228. }
  229. static int dw_hdmi_imx_remove(struct platform_device *pdev)
  230. {
  231. component_del(&pdev->dev, &dw_hdmi_imx_ops);
  232. return 0;
  233. }
  234. static struct platform_driver dw_hdmi_imx_platform_driver = {
  235. .probe = dw_hdmi_imx_probe,
  236. .remove = dw_hdmi_imx_remove,
  237. .driver = {
  238. .name = "dwhdmi-imx",
  239. .of_match_table = dw_hdmi_imx_dt_ids,
  240. },
  241. };
  242. module_platform_driver(dw_hdmi_imx_platform_driver);
  243. MODULE_AUTHOR("Andy Yan <andy.yan@rock-chips.com>");
  244. MODULE_AUTHOR("Yakir Yang <ykk@rock-chips.com>");
  245. MODULE_DESCRIPTION("IMX6 Specific DW-HDMI Driver Extension");
  246. MODULE_LICENSE("GPL");
  247. MODULE_ALIAS("platform:dwhdmi-imx");