sti_compositor.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /*
  2. * Copyright (C) STMicroelectronics SA 2014
  3. * Authors: Benjamin Gaignard <benjamin.gaignard@st.com>
  4. * Fabien Dessenne <fabien.dessenne@st.com>
  5. * for STMicroelectronics.
  6. * License terms: GNU General Public License (GPL), version 2
  7. */
  8. #include <linux/component.h>
  9. #include <linux/module.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/reset.h>
  12. #include <drm/drmP.h>
  13. #include "sti_compositor.h"
  14. #include "sti_crtc.h"
  15. #include "sti_cursor.h"
  16. #include "sti_drv.h"
  17. #include "sti_gdp.h"
  18. #include "sti_plane.h"
  19. #include "sti_vid.h"
  20. #include "sti_vtg.h"
  21. /*
  22. * stiH407 compositor properties
  23. */
  24. struct sti_compositor_data stih407_compositor_data = {
  25. .nb_subdev = 8,
  26. .subdev_desc = {
  27. {STI_CURSOR_SUBDEV, (int)STI_CURSOR, 0x000},
  28. {STI_GPD_SUBDEV, (int)STI_GDP_0, 0x100},
  29. {STI_GPD_SUBDEV, (int)STI_GDP_1, 0x200},
  30. {STI_GPD_SUBDEV, (int)STI_GDP_2, 0x300},
  31. {STI_GPD_SUBDEV, (int)STI_GDP_3, 0x400},
  32. {STI_VID_SUBDEV, (int)STI_HQVDP_0, 0x700},
  33. {STI_MIXER_MAIN_SUBDEV, STI_MIXER_MAIN, 0xC00},
  34. {STI_MIXER_AUX_SUBDEV, STI_MIXER_AUX, 0xD00},
  35. },
  36. };
  37. /*
  38. * stiH416 compositor properties
  39. * Note:
  40. * on stih416 MIXER_AUX has a different base address from MIXER_MAIN
  41. * Moreover, GDPx is different for Main and Aux Mixer. So this subdev map does
  42. * not fit for stiH416 if we want to enable the MIXER_AUX.
  43. */
  44. struct sti_compositor_data stih416_compositor_data = {
  45. .nb_subdev = 3,
  46. .subdev_desc = {
  47. {STI_GPD_SUBDEV, (int)STI_GDP_0, 0x100},
  48. {STI_GPD_SUBDEV, (int)STI_GDP_1, 0x200},
  49. {STI_MIXER_MAIN_SUBDEV, STI_MIXER_MAIN, 0xC00}
  50. },
  51. };
  52. static int sti_compositor_bind(struct device *dev,
  53. struct device *master,
  54. void *data)
  55. {
  56. struct sti_compositor *compo = dev_get_drvdata(dev);
  57. struct drm_device *drm_dev = data;
  58. unsigned int i, mixer_id = 0, vid_id = 0, crtc_id = 0;
  59. struct sti_private *dev_priv = drm_dev->dev_private;
  60. struct drm_plane *cursor = NULL;
  61. struct drm_plane *primary = NULL;
  62. struct sti_compositor_subdev_descriptor *desc = compo->data.subdev_desc;
  63. unsigned int array_size = compo->data.nb_subdev;
  64. dev_priv->compo = compo;
  65. /* Register mixer subdev and video subdev first */
  66. for (i = 0; i < array_size; i++) {
  67. switch (desc[i].type) {
  68. case STI_VID_SUBDEV:
  69. compo->vid[vid_id++] =
  70. sti_vid_create(compo->dev, desc[i].id,
  71. compo->regs + desc[i].offset);
  72. break;
  73. case STI_MIXER_MAIN_SUBDEV:
  74. case STI_MIXER_AUX_SUBDEV:
  75. compo->mixer[mixer_id++] =
  76. sti_mixer_create(compo->dev, desc[i].id,
  77. compo->regs + desc[i].offset);
  78. break;
  79. case STI_GPD_SUBDEV:
  80. case STI_CURSOR_SUBDEV:
  81. /* Nothing to do, wait for the second round */
  82. break;
  83. default:
  84. DRM_ERROR("Unknow subdev compoment type\n");
  85. return 1;
  86. }
  87. }
  88. /* Register the other subdevs, create crtc and planes */
  89. for (i = 0; i < array_size; i++) {
  90. enum drm_plane_type plane_type = DRM_PLANE_TYPE_OVERLAY;
  91. if (crtc_id < mixer_id)
  92. plane_type = DRM_PLANE_TYPE_PRIMARY;
  93. switch (desc[i].type) {
  94. case STI_MIXER_MAIN_SUBDEV:
  95. case STI_MIXER_AUX_SUBDEV:
  96. case STI_VID_SUBDEV:
  97. /* Nothing to do, already done at the first round */
  98. break;
  99. case STI_CURSOR_SUBDEV:
  100. cursor = sti_cursor_create(drm_dev, compo->dev,
  101. desc[i].id,
  102. compo->regs + desc[i].offset,
  103. 1);
  104. if (!cursor) {
  105. DRM_ERROR("Can't create CURSOR plane\n");
  106. break;
  107. }
  108. break;
  109. case STI_GPD_SUBDEV:
  110. primary = sti_gdp_create(drm_dev, compo->dev,
  111. desc[i].id,
  112. compo->regs + desc[i].offset,
  113. (1 << mixer_id) - 1,
  114. plane_type);
  115. if (!primary) {
  116. DRM_ERROR("Can't create GDP plane\n");
  117. break;
  118. }
  119. break;
  120. default:
  121. DRM_ERROR("Unknown subdev compoment type\n");
  122. return 1;
  123. }
  124. /* The first planes are reserved for primary planes*/
  125. if (crtc_id < mixer_id && primary) {
  126. sti_crtc_init(drm_dev, compo->mixer[crtc_id],
  127. primary, cursor);
  128. crtc_id++;
  129. cursor = NULL;
  130. primary = NULL;
  131. }
  132. }
  133. drm_vblank_init(drm_dev, crtc_id);
  134. /* Allow usage of vblank without having to call drm_irq_install */
  135. drm_dev->irq_enabled = 1;
  136. return 0;
  137. }
  138. static void sti_compositor_unbind(struct device *dev, struct device *master,
  139. void *data)
  140. {
  141. /* do nothing */
  142. }
  143. static const struct component_ops sti_compositor_ops = {
  144. .bind = sti_compositor_bind,
  145. .unbind = sti_compositor_unbind,
  146. };
  147. static const struct of_device_id compositor_of_match[] = {
  148. {
  149. .compatible = "st,stih416-compositor",
  150. .data = &stih416_compositor_data,
  151. }, {
  152. .compatible = "st,stih407-compositor",
  153. .data = &stih407_compositor_data,
  154. }, {
  155. /* end node */
  156. }
  157. };
  158. MODULE_DEVICE_TABLE(of, compositor_of_match);
  159. static int sti_compositor_probe(struct platform_device *pdev)
  160. {
  161. struct device *dev = &pdev->dev;
  162. struct device_node *np = dev->of_node;
  163. struct device_node *vtg_np;
  164. struct sti_compositor *compo;
  165. struct resource *res;
  166. compo = devm_kzalloc(dev, sizeof(*compo), GFP_KERNEL);
  167. if (!compo) {
  168. DRM_ERROR("Failed to allocate compositor context\n");
  169. return -ENOMEM;
  170. }
  171. compo->dev = dev;
  172. compo->vtg_vblank_nb.notifier_call = sti_crtc_vblank_cb;
  173. /* populate data structure depending on compatibility */
  174. BUG_ON(!of_match_node(compositor_of_match, np)->data);
  175. memcpy(&compo->data, of_match_node(compositor_of_match, np)->data,
  176. sizeof(struct sti_compositor_data));
  177. /* Get Memory ressources */
  178. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  179. if (res == NULL) {
  180. DRM_ERROR("Get memory resource failed\n");
  181. return -ENXIO;
  182. }
  183. compo->regs = devm_ioremap(dev, res->start, resource_size(res));
  184. if (compo->regs == NULL) {
  185. DRM_ERROR("Register mapping failed\n");
  186. return -ENXIO;
  187. }
  188. /* Get clock resources */
  189. compo->clk_compo_main = devm_clk_get(dev, "compo_main");
  190. if (IS_ERR(compo->clk_compo_main)) {
  191. DRM_ERROR("Cannot get compo_main clock\n");
  192. return PTR_ERR(compo->clk_compo_main);
  193. }
  194. compo->clk_compo_aux = devm_clk_get(dev, "compo_aux");
  195. if (IS_ERR(compo->clk_compo_aux)) {
  196. DRM_ERROR("Cannot get compo_aux clock\n");
  197. return PTR_ERR(compo->clk_compo_aux);
  198. }
  199. compo->clk_pix_main = devm_clk_get(dev, "pix_main");
  200. if (IS_ERR(compo->clk_pix_main)) {
  201. DRM_ERROR("Cannot get pix_main clock\n");
  202. return PTR_ERR(compo->clk_pix_main);
  203. }
  204. compo->clk_pix_aux = devm_clk_get(dev, "pix_aux");
  205. if (IS_ERR(compo->clk_pix_aux)) {
  206. DRM_ERROR("Cannot get pix_aux clock\n");
  207. return PTR_ERR(compo->clk_pix_aux);
  208. }
  209. /* Get reset resources */
  210. compo->rst_main = devm_reset_control_get(dev, "compo-main");
  211. /* Take compo main out of reset */
  212. if (!IS_ERR(compo->rst_main))
  213. reset_control_deassert(compo->rst_main);
  214. compo->rst_aux = devm_reset_control_get(dev, "compo-aux");
  215. /* Take compo aux out of reset */
  216. if (!IS_ERR(compo->rst_aux))
  217. reset_control_deassert(compo->rst_aux);
  218. vtg_np = of_parse_phandle(pdev->dev.of_node, "st,vtg", 0);
  219. if (vtg_np)
  220. compo->vtg_main = of_vtg_find(vtg_np);
  221. vtg_np = of_parse_phandle(pdev->dev.of_node, "st,vtg", 1);
  222. if (vtg_np)
  223. compo->vtg_aux = of_vtg_find(vtg_np);
  224. platform_set_drvdata(pdev, compo);
  225. return component_add(&pdev->dev, &sti_compositor_ops);
  226. }
  227. static int sti_compositor_remove(struct platform_device *pdev)
  228. {
  229. component_del(&pdev->dev, &sti_compositor_ops);
  230. return 0;
  231. }
  232. struct platform_driver sti_compositor_driver = {
  233. .driver = {
  234. .name = "sti-compositor",
  235. .of_match_table = compositor_of_match,
  236. },
  237. .probe = sti_compositor_probe,
  238. .remove = sti_compositor_remove,
  239. };
  240. MODULE_AUTHOR("Benjamin Gaignard <benjamin.gaignard@st.com>");
  241. MODULE_DESCRIPTION("STMicroelectronics SoC DRM driver");
  242. MODULE_LICENSE("GPL");