sti_compositor.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) STMicroelectronics SA 2014
  4. * Authors: Benjamin Gaignard <benjamin.gaignard@st.com>
  5. * Fabien Dessenne <fabien.dessenne@st.com>
  6. * for STMicroelectronics.
  7. */
  8. #include <linux/component.h>
  9. #include <linux/io.h>
  10. #include <linux/module.h>
  11. #include <linux/of.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/reset.h>
  14. #include <drm/drm_device.h>
  15. #include <drm/drm_print.h>
  16. #include <drm/drm_vblank.h>
  17. #include "sti_compositor.h"
  18. #include "sti_crtc.h"
  19. #include "sti_cursor.h"
  20. #include "sti_drv.h"
  21. #include "sti_gdp.h"
  22. #include "sti_plane.h"
  23. #include "sti_vid.h"
  24. #include "sti_vtg.h"
  25. /*
  26. * stiH407 compositor properties
  27. */
  28. static const struct sti_compositor_data stih407_compositor_data = {
  29. .nb_subdev = 8,
  30. .subdev_desc = {
  31. {STI_CURSOR_SUBDEV, (int)STI_CURSOR, 0x000},
  32. {STI_GPD_SUBDEV, (int)STI_GDP_0, 0x100},
  33. {STI_GPD_SUBDEV, (int)STI_GDP_1, 0x200},
  34. {STI_GPD_SUBDEV, (int)STI_GDP_2, 0x300},
  35. {STI_GPD_SUBDEV, (int)STI_GDP_3, 0x400},
  36. {STI_VID_SUBDEV, (int)STI_HQVDP_0, 0x700},
  37. {STI_MIXER_MAIN_SUBDEV, STI_MIXER_MAIN, 0xC00},
  38. {STI_MIXER_AUX_SUBDEV, STI_MIXER_AUX, 0xD00},
  39. },
  40. };
  41. void sti_compositor_debugfs_init(struct sti_compositor *compo,
  42. struct drm_minor *minor)
  43. {
  44. unsigned int i;
  45. for (i = 0; i < STI_MAX_VID; i++)
  46. if (compo->vid[i])
  47. vid_debugfs_init(compo->vid[i], minor);
  48. for (i = 0; i < STI_MAX_MIXER; i++)
  49. if (compo->mixer[i])
  50. sti_mixer_debugfs_init(compo->mixer[i], minor);
  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, drm_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, drm_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("Unknown subdev component 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 component 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. return 0;
  135. }
  136. static void sti_compositor_unbind(struct device *dev, struct device *master,
  137. void *data)
  138. {
  139. /* do nothing */
  140. }
  141. static const struct component_ops sti_compositor_ops = {
  142. .bind = sti_compositor_bind,
  143. .unbind = sti_compositor_unbind,
  144. };
  145. static const struct of_device_id compositor_of_match[] = {
  146. {
  147. .compatible = "st,stih407-compositor",
  148. .data = &stih407_compositor_data,
  149. }, {
  150. /* end node */
  151. }
  152. };
  153. MODULE_DEVICE_TABLE(of, compositor_of_match);
  154. static int sti_compositor_probe(struct platform_device *pdev)
  155. {
  156. struct device *dev = &pdev->dev;
  157. struct device_node *np = dev->of_node;
  158. struct device_node *vtg_np;
  159. struct sti_compositor *compo;
  160. struct resource *res;
  161. unsigned int i;
  162. compo = devm_kzalloc(dev, sizeof(*compo), GFP_KERNEL);
  163. if (!compo) {
  164. DRM_ERROR("Failed to allocate compositor context\n");
  165. return -ENOMEM;
  166. }
  167. compo->dev = dev;
  168. for (i = 0; i < STI_MAX_MIXER; i++)
  169. compo->vtg_vblank_nb[i].notifier_call = sti_crtc_vblank_cb;
  170. /* populate data structure depending on compatibility */
  171. BUG_ON(!of_match_node(compositor_of_match, np)->data);
  172. memcpy(&compo->data, of_match_node(compositor_of_match, np)->data,
  173. sizeof(struct sti_compositor_data));
  174. /* Get Memory ressources */
  175. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  176. if (res == NULL) {
  177. DRM_ERROR("Get memory resource failed\n");
  178. return -ENXIO;
  179. }
  180. compo->regs = devm_ioremap(dev, res->start, resource_size(res));
  181. if (compo->regs == NULL) {
  182. DRM_ERROR("Register mapping failed\n");
  183. return -ENXIO;
  184. }
  185. /* Get clock resources */
  186. compo->clk_compo_main = devm_clk_get(dev, "compo_main");
  187. if (IS_ERR(compo->clk_compo_main)) {
  188. DRM_ERROR("Cannot get compo_main clock\n");
  189. return PTR_ERR(compo->clk_compo_main);
  190. }
  191. compo->clk_compo_aux = devm_clk_get(dev, "compo_aux");
  192. if (IS_ERR(compo->clk_compo_aux)) {
  193. DRM_ERROR("Cannot get compo_aux clock\n");
  194. return PTR_ERR(compo->clk_compo_aux);
  195. }
  196. compo->clk_pix_main = devm_clk_get(dev, "pix_main");
  197. if (IS_ERR(compo->clk_pix_main)) {
  198. DRM_ERROR("Cannot get pix_main clock\n");
  199. return PTR_ERR(compo->clk_pix_main);
  200. }
  201. compo->clk_pix_aux = devm_clk_get(dev, "pix_aux");
  202. if (IS_ERR(compo->clk_pix_aux)) {
  203. DRM_ERROR("Cannot get pix_aux clock\n");
  204. return PTR_ERR(compo->clk_pix_aux);
  205. }
  206. /* Get reset resources */
  207. compo->rst_main = devm_reset_control_get_shared(dev, "compo-main");
  208. /* Take compo main out of reset */
  209. if (!IS_ERR(compo->rst_main))
  210. reset_control_deassert(compo->rst_main);
  211. compo->rst_aux = devm_reset_control_get_shared(dev, "compo-aux");
  212. /* Take compo aux out of reset */
  213. if (!IS_ERR(compo->rst_aux))
  214. reset_control_deassert(compo->rst_aux);
  215. vtg_np = of_parse_phandle(pdev->dev.of_node, "st,vtg", 0);
  216. if (vtg_np)
  217. compo->vtg[STI_MIXER_MAIN] = of_vtg_find(vtg_np);
  218. of_node_put(vtg_np);
  219. vtg_np = of_parse_phandle(pdev->dev.of_node, "st,vtg", 1);
  220. if (vtg_np)
  221. compo->vtg[STI_MIXER_AUX] = of_vtg_find(vtg_np);
  222. of_node_put(vtg_np);
  223. platform_set_drvdata(pdev, compo);
  224. return component_add(&pdev->dev, &sti_compositor_ops);
  225. }
  226. static void sti_compositor_remove(struct platform_device *pdev)
  227. {
  228. component_del(&pdev->dev, &sti_compositor_ops);
  229. }
  230. struct platform_driver sti_compositor_driver = {
  231. .driver = {
  232. .name = "sti-compositor",
  233. .of_match_table = compositor_of_match,
  234. },
  235. .probe = sti_compositor_probe,
  236. .remove_new = sti_compositor_remove,
  237. };
  238. MODULE_AUTHOR("Benjamin Gaignard <benjamin.gaignard@st.com>");
  239. MODULE_DESCRIPTION("STMicroelectronics SoC DRM driver");
  240. MODULE_LICENSE("GPL");