sti_compositor.c 7.8 KB

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