sti_compositor.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. static const 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. int sti_compositor_debugfs_init(struct sti_compositor *compo,
  38. struct drm_minor *minor)
  39. {
  40. unsigned int i;
  41. for (i = 0; i < STI_MAX_VID; i++)
  42. if (compo->vid[i])
  43. vid_debugfs_init(compo->vid[i], minor);
  44. for (i = 0; i < STI_MAX_MIXER; i++)
  45. if (compo->mixer[i])
  46. sti_mixer_debugfs_init(compo->mixer[i], minor);
  47. return 0;
  48. }
  49. static int sti_compositor_bind(struct device *dev,
  50. struct device *master,
  51. void *data)
  52. {
  53. struct sti_compositor *compo = dev_get_drvdata(dev);
  54. struct drm_device *drm_dev = data;
  55. unsigned int i, mixer_id = 0, vid_id = 0, crtc_id = 0;
  56. struct sti_private *dev_priv = drm_dev->dev_private;
  57. struct drm_plane *cursor = NULL;
  58. struct drm_plane *primary = NULL;
  59. struct sti_compositor_subdev_descriptor *desc = compo->data.subdev_desc;
  60. unsigned int array_size = compo->data.nb_subdev;
  61. dev_priv->compo = compo;
  62. /* Register mixer subdev and video subdev first */
  63. for (i = 0; i < array_size; i++) {
  64. switch (desc[i].type) {
  65. case STI_VID_SUBDEV:
  66. compo->vid[vid_id++] =
  67. sti_vid_create(compo->dev, drm_dev, desc[i].id,
  68. compo->regs + desc[i].offset);
  69. break;
  70. case STI_MIXER_MAIN_SUBDEV:
  71. case STI_MIXER_AUX_SUBDEV:
  72. compo->mixer[mixer_id++] =
  73. sti_mixer_create(compo->dev, drm_dev, desc[i].id,
  74. compo->regs + desc[i].offset);
  75. break;
  76. case STI_GPD_SUBDEV:
  77. case STI_CURSOR_SUBDEV:
  78. /* Nothing to do, wait for the second round */
  79. break;
  80. default:
  81. DRM_ERROR("Unknow subdev compoment type\n");
  82. return 1;
  83. }
  84. }
  85. /* Register the other subdevs, create crtc and planes */
  86. for (i = 0; i < array_size; i++) {
  87. enum drm_plane_type plane_type = DRM_PLANE_TYPE_OVERLAY;
  88. if (crtc_id < mixer_id)
  89. plane_type = DRM_PLANE_TYPE_PRIMARY;
  90. switch (desc[i].type) {
  91. case STI_MIXER_MAIN_SUBDEV:
  92. case STI_MIXER_AUX_SUBDEV:
  93. case STI_VID_SUBDEV:
  94. /* Nothing to do, already done at the first round */
  95. break;
  96. case STI_CURSOR_SUBDEV:
  97. cursor = sti_cursor_create(drm_dev, compo->dev,
  98. desc[i].id,
  99. compo->regs + desc[i].offset,
  100. 1);
  101. if (!cursor) {
  102. DRM_ERROR("Can't create CURSOR plane\n");
  103. break;
  104. }
  105. break;
  106. case STI_GPD_SUBDEV:
  107. primary = sti_gdp_create(drm_dev, compo->dev,
  108. desc[i].id,
  109. compo->regs + desc[i].offset,
  110. (1 << mixer_id) - 1,
  111. plane_type);
  112. if (!primary) {
  113. DRM_ERROR("Can't create GDP plane\n");
  114. break;
  115. }
  116. break;
  117. default:
  118. DRM_ERROR("Unknown subdev compoment type\n");
  119. return 1;
  120. }
  121. /* The first planes are reserved for primary planes*/
  122. if (crtc_id < mixer_id && primary) {
  123. sti_crtc_init(drm_dev, compo->mixer[crtc_id],
  124. primary, cursor);
  125. crtc_id++;
  126. cursor = NULL;
  127. primary = NULL;
  128. }
  129. }
  130. drm_vblank_init(drm_dev, crtc_id);
  131. /* Allow usage of vblank without having to call drm_irq_install */
  132. drm_dev->irq_enabled = 1;
  133. return 0;
  134. }
  135. static void sti_compositor_unbind(struct device *dev, struct device *master,
  136. void *data)
  137. {
  138. /* do nothing */
  139. }
  140. static const struct component_ops sti_compositor_ops = {
  141. .bind = sti_compositor_bind,
  142. .unbind = sti_compositor_unbind,
  143. };
  144. static const struct of_device_id compositor_of_match[] = {
  145. {
  146. .compatible = "st,stih407-compositor",
  147. .data = &stih407_compositor_data,
  148. }, {
  149. /* end node */
  150. }
  151. };
  152. MODULE_DEVICE_TABLE(of, compositor_of_match);
  153. static int sti_compositor_probe(struct platform_device *pdev)
  154. {
  155. struct device *dev = &pdev->dev;
  156. struct device_node *np = dev->of_node;
  157. struct device_node *vtg_np;
  158. struct sti_compositor *compo;
  159. struct resource *res;
  160. unsigned int i;
  161. compo = devm_kzalloc(dev, sizeof(*compo), GFP_KERNEL);
  162. if (!compo) {
  163. DRM_ERROR("Failed to allocate compositor context\n");
  164. return -ENOMEM;
  165. }
  166. compo->dev = dev;
  167. for (i = 0; i < STI_MAX_MIXER; i++)
  168. compo->vtg_vblank_nb[i].notifier_call = sti_crtc_vblank_cb;
  169. /* populate data structure depending on compatibility */
  170. BUG_ON(!of_match_node(compositor_of_match, np)->data);
  171. memcpy(&compo->data, of_match_node(compositor_of_match, np)->data,
  172. sizeof(struct sti_compositor_data));
  173. /* Get Memory ressources */
  174. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  175. if (res == NULL) {
  176. DRM_ERROR("Get memory resource failed\n");
  177. return -ENXIO;
  178. }
  179. compo->regs = devm_ioremap(dev, res->start, resource_size(res));
  180. if (compo->regs == NULL) {
  181. DRM_ERROR("Register mapping failed\n");
  182. return -ENXIO;
  183. }
  184. /* Get clock resources */
  185. compo->clk_compo_main = devm_clk_get(dev, "compo_main");
  186. if (IS_ERR(compo->clk_compo_main)) {
  187. DRM_ERROR("Cannot get compo_main clock\n");
  188. return PTR_ERR(compo->clk_compo_main);
  189. }
  190. compo->clk_compo_aux = devm_clk_get(dev, "compo_aux");
  191. if (IS_ERR(compo->clk_compo_aux)) {
  192. DRM_ERROR("Cannot get compo_aux clock\n");
  193. return PTR_ERR(compo->clk_compo_aux);
  194. }
  195. compo->clk_pix_main = devm_clk_get(dev, "pix_main");
  196. if (IS_ERR(compo->clk_pix_main)) {
  197. DRM_ERROR("Cannot get pix_main clock\n");
  198. return PTR_ERR(compo->clk_pix_main);
  199. }
  200. compo->clk_pix_aux = devm_clk_get(dev, "pix_aux");
  201. if (IS_ERR(compo->clk_pix_aux)) {
  202. DRM_ERROR("Cannot get pix_aux clock\n");
  203. return PTR_ERR(compo->clk_pix_aux);
  204. }
  205. /* Get reset resources */
  206. compo->rst_main = devm_reset_control_get_shared(dev, "compo-main");
  207. /* Take compo main out of reset */
  208. if (!IS_ERR(compo->rst_main))
  209. reset_control_deassert(compo->rst_main);
  210. compo->rst_aux = devm_reset_control_get_shared(dev, "compo-aux");
  211. /* Take compo aux out of reset */
  212. if (!IS_ERR(compo->rst_aux))
  213. reset_control_deassert(compo->rst_aux);
  214. vtg_np = of_parse_phandle(pdev->dev.of_node, "st,vtg", 0);
  215. if (vtg_np)
  216. compo->vtg[STI_MIXER_MAIN] = of_vtg_find(vtg_np);
  217. of_node_put(vtg_np);
  218. vtg_np = of_parse_phandle(pdev->dev.of_node, "st,vtg", 1);
  219. if (vtg_np)
  220. compo->vtg[STI_MIXER_AUX] = of_vtg_find(vtg_np);
  221. of_node_put(vtg_np);
  222. platform_set_drvdata(pdev, compo);
  223. return component_add(&pdev->dev, &sti_compositor_ops);
  224. }
  225. static int sti_compositor_remove(struct platform_device *pdev)
  226. {
  227. component_del(&pdev->dev, &sti_compositor_ops);
  228. return 0;
  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 = sti_compositor_remove,
  237. };
  238. MODULE_AUTHOR("Benjamin Gaignard <benjamin.gaignard@st.com>");
  239. MODULE_DESCRIPTION("STMicroelectronics SoC DRM driver");
  240. MODULE_LICENSE("GPL");