sti_compositor.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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_drm_crtc.h"
  15. #include "sti_drm_drv.h"
  16. #include "sti_drm_plane.h"
  17. #include "sti_gdp.h"
  18. #include "sti_vtg.h"
  19. /*
  20. * stiH407 compositor properties
  21. */
  22. struct sti_compositor_data stih407_compositor_data = {
  23. .nb_subdev = 8,
  24. .subdev_desc = {
  25. {STI_CURSOR_SUBDEV, (int)STI_CURSOR, 0x000},
  26. {STI_GPD_SUBDEV, (int)STI_GDP_0, 0x100},
  27. {STI_GPD_SUBDEV, (int)STI_GDP_1, 0x200},
  28. {STI_GPD_SUBDEV, (int)STI_GDP_2, 0x300},
  29. {STI_GPD_SUBDEV, (int)STI_GDP_3, 0x400},
  30. {STI_VID_SUBDEV, (int)STI_VID_0, 0x700},
  31. {STI_MIXER_MAIN_SUBDEV, STI_MIXER_MAIN, 0xC00},
  32. {STI_MIXER_AUX_SUBDEV, STI_MIXER_AUX, 0xD00},
  33. },
  34. };
  35. /*
  36. * stiH416 compositor properties
  37. * Note:
  38. * on stih416 MIXER_AUX has a different base address from MIXER_MAIN
  39. * Moreover, GDPx is different for Main and Aux Mixer. So this subdev map does
  40. * not fit for stiH416 if we want to enable the MIXER_AUX.
  41. */
  42. struct sti_compositor_data stih416_compositor_data = {
  43. .nb_subdev = 3,
  44. .subdev_desc = {
  45. {STI_GPD_SUBDEV, (int)STI_GDP_0, 0x100},
  46. {STI_GPD_SUBDEV, (int)STI_GDP_1, 0x200},
  47. {STI_MIXER_MAIN_SUBDEV, STI_MIXER_MAIN, 0xC00}
  48. },
  49. };
  50. static int sti_compositor_init_subdev(struct sti_compositor *compo,
  51. struct sti_compositor_subdev_descriptor *desc,
  52. unsigned int array_size)
  53. {
  54. unsigned int i, mixer_id = 0, layer_id = 0;
  55. for (i = 0; i < array_size; i++) {
  56. switch (desc[i].type) {
  57. case STI_MIXER_MAIN_SUBDEV:
  58. case STI_MIXER_AUX_SUBDEV:
  59. compo->mixer[mixer_id++] =
  60. sti_mixer_create(compo->dev, desc[i].id,
  61. compo->regs + desc[i].offset);
  62. break;
  63. case STI_GPD_SUBDEV:
  64. case STI_VID_SUBDEV:
  65. case STI_CURSOR_SUBDEV:
  66. compo->layer[layer_id++] =
  67. sti_layer_create(compo->dev, desc[i].id,
  68. compo->regs + desc[i].offset);
  69. break;
  70. default:
  71. DRM_ERROR("Unknow subdev compoment type\n");
  72. return 1;
  73. }
  74. }
  75. compo->nb_mixers = mixer_id;
  76. compo->nb_layers = layer_id;
  77. return 0;
  78. }
  79. static int sti_compositor_bind(struct device *dev, struct device *master,
  80. void *data)
  81. {
  82. struct sti_compositor *compo = dev_get_drvdata(dev);
  83. struct drm_device *drm_dev = data;
  84. unsigned int i, crtc = 0, plane = 0;
  85. struct sti_drm_private *dev_priv = drm_dev->dev_private;
  86. struct drm_plane *cursor = NULL;
  87. struct drm_plane *primary = NULL;
  88. dev_priv->compo = compo;
  89. for (i = 0; i < compo->nb_layers; i++) {
  90. if (compo->layer[i]) {
  91. enum sti_layer_desc desc = compo->layer[i]->desc;
  92. enum sti_layer_type type = desc & STI_LAYER_TYPE_MASK;
  93. enum drm_plane_type plane_type = DRM_PLANE_TYPE_OVERLAY;
  94. if (crtc < compo->nb_mixers)
  95. plane_type = DRM_PLANE_TYPE_PRIMARY;
  96. switch (type) {
  97. case STI_CUR:
  98. cursor = sti_drm_plane_init(drm_dev,
  99. compo->layer[i],
  100. 1, DRM_PLANE_TYPE_CURSOR);
  101. break;
  102. case STI_GDP:
  103. case STI_VID:
  104. primary = sti_drm_plane_init(drm_dev,
  105. compo->layer[i],
  106. (1 << compo->nb_mixers) - 1,
  107. plane_type);
  108. plane++;
  109. break;
  110. case STI_BCK:
  111. case STI_VDP:
  112. break;
  113. }
  114. /* The first planes are reserved for primary planes*/
  115. if (crtc < compo->nb_mixers && primary) {
  116. sti_drm_crtc_init(drm_dev, compo->mixer[crtc],
  117. primary, cursor);
  118. crtc++;
  119. cursor = NULL;
  120. primary = NULL;
  121. }
  122. }
  123. }
  124. drm_vblank_init(drm_dev, crtc);
  125. /* Allow usage of vblank without having to call drm_irq_install */
  126. drm_dev->irq_enabled = 1;
  127. DRM_DEBUG_DRIVER("Initialized %d DRM CRTC(s) and %d DRM plane(s)\n",
  128. crtc, plane);
  129. DRM_DEBUG_DRIVER("DRM plane(s) for VID/VDP not created yet\n");
  130. return 0;
  131. }
  132. static void sti_compositor_unbind(struct device *dev, struct device *master,
  133. void *data)
  134. {
  135. /* do nothing */
  136. }
  137. static const struct component_ops sti_compositor_ops = {
  138. .bind = sti_compositor_bind,
  139. .unbind = sti_compositor_unbind,
  140. };
  141. static const struct of_device_id compositor_of_match[] = {
  142. {
  143. .compatible = "st,stih416-compositor",
  144. .data = &stih416_compositor_data,
  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. int err;
  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. compo->vtg_vblank_nb.notifier_call = sti_drm_crtc_vblank_cb;
  168. /* populate data structure depending on compatibility */
  169. BUG_ON(!of_match_node(compositor_of_match, np)->data);
  170. memcpy(&compo->data, of_match_node(compositor_of_match, np)->data,
  171. sizeof(struct sti_compositor_data));
  172. /* Get Memory ressources */
  173. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  174. if (res == NULL) {
  175. DRM_ERROR("Get memory resource failed\n");
  176. return -ENXIO;
  177. }
  178. compo->regs = devm_ioremap(dev, res->start, resource_size(res));
  179. if (compo->regs == NULL) {
  180. DRM_ERROR("Register mapping failed\n");
  181. return -ENXIO;
  182. }
  183. /* Get clock resources */
  184. compo->clk_compo_main = devm_clk_get(dev, "compo_main");
  185. if (IS_ERR(compo->clk_compo_main)) {
  186. DRM_ERROR("Cannot get compo_main clock\n");
  187. return PTR_ERR(compo->clk_compo_main);
  188. }
  189. compo->clk_compo_aux = devm_clk_get(dev, "compo_aux");
  190. if (IS_ERR(compo->clk_compo_aux)) {
  191. DRM_ERROR("Cannot get compo_aux clock\n");
  192. return PTR_ERR(compo->clk_compo_aux);
  193. }
  194. compo->clk_pix_main = devm_clk_get(dev, "pix_main");
  195. if (IS_ERR(compo->clk_pix_main)) {
  196. DRM_ERROR("Cannot get pix_main clock\n");
  197. return PTR_ERR(compo->clk_pix_main);
  198. }
  199. compo->clk_pix_aux = devm_clk_get(dev, "pix_aux");
  200. if (IS_ERR(compo->clk_pix_aux)) {
  201. DRM_ERROR("Cannot get pix_aux clock\n");
  202. return PTR_ERR(compo->clk_pix_aux);
  203. }
  204. /* Get reset resources */
  205. compo->rst_main = devm_reset_control_get(dev, "compo-main");
  206. /* Take compo main out of reset */
  207. if (!IS_ERR(compo->rst_main))
  208. reset_control_deassert(compo->rst_main);
  209. compo->rst_aux = devm_reset_control_get(dev, "compo-aux");
  210. /* Take compo aux out of reset */
  211. if (!IS_ERR(compo->rst_aux))
  212. reset_control_deassert(compo->rst_aux);
  213. vtg_np = of_parse_phandle(pdev->dev.of_node, "st,vtg", 0);
  214. if (vtg_np)
  215. compo->vtg_main = of_vtg_find(vtg_np);
  216. vtg_np = of_parse_phandle(pdev->dev.of_node, "st,vtg", 1);
  217. if (vtg_np)
  218. compo->vtg_aux = of_vtg_find(vtg_np);
  219. /* Initialize compositor subdevices */
  220. err = sti_compositor_init_subdev(compo, compo->data.subdev_desc,
  221. compo->data.nb_subdev);
  222. if (err)
  223. return err;
  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. static 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_platform_driver(sti_compositor_driver);
  241. MODULE_AUTHOR("Benjamin Gaignard <benjamin.gaignard@st.com>");
  242. MODULE_DESCRIPTION("STMicroelectronics SoC DRM driver");
  243. MODULE_LICENSE("GPL");