sti_compositor.c 7.3 KB

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