dw_hdmi-imx.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. };
  71. static const struct dw_hdmi_sym_term imx_sym_term[] = {
  72. /*pixelclk symbol term*/
  73. { 148500000, 0x800d, 0x0005 },
  74. { ~0UL, 0x0000, 0x0000 }
  75. };
  76. static int dw_hdmi_imx_parse_dt(struct imx_hdmi *hdmi)
  77. {
  78. struct device_node *np = hdmi->dev->of_node;
  79. hdmi->regmap = syscon_regmap_lookup_by_phandle(np, "gpr");
  80. if (IS_ERR(hdmi->regmap)) {
  81. dev_err(hdmi->dev, "Unable to get gpr\n");
  82. return PTR_ERR(hdmi->regmap);
  83. }
  84. return 0;
  85. }
  86. static void dw_hdmi_imx_encoder_disable(struct drm_encoder *encoder)
  87. {
  88. }
  89. static bool dw_hdmi_imx_encoder_mode_fixup(struct drm_encoder *encoder,
  90. const struct drm_display_mode *mode,
  91. struct drm_display_mode *adj_mode)
  92. {
  93. return true;
  94. }
  95. static void dw_hdmi_imx_encoder_mode_set(struct drm_encoder *encoder,
  96. struct drm_display_mode *mode,
  97. struct drm_display_mode *adj_mode)
  98. {
  99. }
  100. static void dw_hdmi_imx_encoder_commit(struct drm_encoder *encoder)
  101. {
  102. struct imx_hdmi *hdmi = container_of(encoder, struct imx_hdmi, encoder);
  103. int mux = imx_drm_encoder_get_mux_id(hdmi->dev->of_node, encoder);
  104. regmap_update_bits(hdmi->regmap, IOMUXC_GPR3,
  105. IMX6Q_GPR3_HDMI_MUX_CTL_MASK,
  106. mux << IMX6Q_GPR3_HDMI_MUX_CTL_SHIFT);
  107. }
  108. static void dw_hdmi_imx_encoder_prepare(struct drm_encoder *encoder)
  109. {
  110. imx_drm_panel_format(encoder, V4L2_PIX_FMT_RGB24);
  111. }
  112. static struct drm_encoder_helper_funcs dw_hdmi_imx_encoder_helper_funcs = {
  113. .mode_fixup = dw_hdmi_imx_encoder_mode_fixup,
  114. .mode_set = dw_hdmi_imx_encoder_mode_set,
  115. .prepare = dw_hdmi_imx_encoder_prepare,
  116. .commit = dw_hdmi_imx_encoder_commit,
  117. .disable = dw_hdmi_imx_encoder_disable,
  118. };
  119. static struct drm_encoder_funcs dw_hdmi_imx_encoder_funcs = {
  120. .destroy = drm_encoder_cleanup,
  121. };
  122. static struct dw_hdmi_plat_data imx6q_hdmi_drv_data = {
  123. .mpll_cfg = imx_mpll_cfg,
  124. .cur_ctr = imx_cur_ctr,
  125. .sym_term = imx_sym_term,
  126. .dev_type = IMX6Q_HDMI,
  127. };
  128. static struct dw_hdmi_plat_data imx6dl_hdmi_drv_data = {
  129. .mpll_cfg = imx_mpll_cfg,
  130. .cur_ctr = imx_cur_ctr,
  131. .sym_term = imx_sym_term,
  132. .dev_type = IMX6DL_HDMI,
  133. };
  134. static const struct of_device_id dw_hdmi_imx_dt_ids[] = {
  135. { .compatible = "fsl,imx6q-hdmi",
  136. .data = &imx6q_hdmi_drv_data
  137. }, {
  138. .compatible = "fsl,imx6dl-hdmi",
  139. .data = &imx6dl_hdmi_drv_data
  140. },
  141. {},
  142. };
  143. MODULE_DEVICE_TABLE(of, dw_hdmi_imx_dt_ids);
  144. static int dw_hdmi_imx_bind(struct device *dev, struct device *master,
  145. void *data)
  146. {
  147. struct platform_device *pdev = to_platform_device(dev);
  148. const struct dw_hdmi_plat_data *plat_data;
  149. const struct of_device_id *match;
  150. struct drm_device *drm = data;
  151. struct drm_encoder *encoder;
  152. struct imx_hdmi *hdmi;
  153. struct resource *iores;
  154. int irq;
  155. int ret;
  156. if (!pdev->dev.of_node)
  157. return -ENODEV;
  158. hdmi = devm_kzalloc(&pdev->dev, sizeof(*hdmi), GFP_KERNEL);
  159. if (!hdmi)
  160. return -ENOMEM;
  161. match = of_match_node(dw_hdmi_imx_dt_ids, pdev->dev.of_node);
  162. plat_data = match->data;
  163. hdmi->dev = &pdev->dev;
  164. encoder = &hdmi->encoder;
  165. irq = platform_get_irq(pdev, 0);
  166. if (irq < 0)
  167. return irq;
  168. iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  169. if (!iores)
  170. return -ENXIO;
  171. platform_set_drvdata(pdev, hdmi);
  172. encoder->possible_crtcs = drm_of_find_possible_crtcs(drm, dev->of_node);
  173. /*
  174. * If we failed to find the CRTC(s) which this encoder is
  175. * supposed to be connected to, it's because the CRTC has
  176. * not been registered yet. Defer probing, and hope that
  177. * the required CRTC is added later.
  178. */
  179. if (encoder->possible_crtcs == 0)
  180. return -EPROBE_DEFER;
  181. ret = dw_hdmi_imx_parse_dt(hdmi);
  182. if (ret < 0)
  183. return ret;
  184. drm_encoder_helper_add(encoder, &dw_hdmi_imx_encoder_helper_funcs);
  185. drm_encoder_init(drm, encoder, &dw_hdmi_imx_encoder_funcs,
  186. DRM_MODE_ENCODER_TMDS);
  187. return dw_hdmi_bind(dev, master, data, encoder, iores, irq, plat_data);
  188. }
  189. static void dw_hdmi_imx_unbind(struct device *dev, struct device *master,
  190. void *data)
  191. {
  192. return dw_hdmi_unbind(dev, master, data);
  193. }
  194. static const struct component_ops dw_hdmi_imx_ops = {
  195. .bind = dw_hdmi_imx_bind,
  196. .unbind = dw_hdmi_imx_unbind,
  197. };
  198. static int dw_hdmi_imx_probe(struct platform_device *pdev)
  199. {
  200. return component_add(&pdev->dev, &dw_hdmi_imx_ops);
  201. }
  202. static int dw_hdmi_imx_remove(struct platform_device *pdev)
  203. {
  204. component_del(&pdev->dev, &dw_hdmi_imx_ops);
  205. return 0;
  206. }
  207. static struct platform_driver dw_hdmi_imx_platform_driver = {
  208. .probe = dw_hdmi_imx_probe,
  209. .remove = dw_hdmi_imx_remove,
  210. .driver = {
  211. .name = "dwhdmi-imx",
  212. .of_match_table = dw_hdmi_imx_dt_ids,
  213. },
  214. };
  215. module_platform_driver(dw_hdmi_imx_platform_driver);
  216. MODULE_AUTHOR("Andy Yan <andy.yan@rock-chips.com>");
  217. MODULE_AUTHOR("Yakir Yang <ykk@rock-chips.com>");
  218. MODULE_DESCRIPTION("IMX6 Specific DW-HDMI Driver Extension");
  219. MODULE_LICENSE("GPL");
  220. MODULE_ALIAS("platform:dwhdmi-imx");