sun8i_layer.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright (C) Icenowy Zheng <icenowy@aosc.io>
  3. *
  4. * Based on sun4i_layer.h, which is:
  5. * Copyright (C) 2015 Free Electrons
  6. * Copyright (C) 2015 NextThing Co
  7. *
  8. * Maxime Ripard <maxime.ripard@free-electrons.com>
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. */
  15. #include <drm/drm_atomic_helper.h>
  16. #include <drm/drm_plane_helper.h>
  17. #include <drm/drmP.h>
  18. #include "sun8i_layer.h"
  19. #include "sun8i_mixer.h"
  20. struct sun8i_plane_desc {
  21. enum drm_plane_type type;
  22. const uint32_t *formats;
  23. uint32_t nformats;
  24. };
  25. static void sun8i_mixer_layer_atomic_disable(struct drm_plane *plane,
  26. struct drm_plane_state *old_state)
  27. {
  28. struct sun8i_layer *layer = plane_to_sun8i_layer(plane);
  29. struct sun8i_mixer *mixer = layer->mixer;
  30. sun8i_mixer_layer_enable(mixer, layer->id, false);
  31. }
  32. static void sun8i_mixer_layer_atomic_update(struct drm_plane *plane,
  33. struct drm_plane_state *old_state)
  34. {
  35. struct sun8i_layer *layer = plane_to_sun8i_layer(plane);
  36. struct sun8i_mixer *mixer = layer->mixer;
  37. sun8i_mixer_update_layer_coord(mixer, layer->id, plane);
  38. sun8i_mixer_update_layer_formats(mixer, layer->id, plane);
  39. sun8i_mixer_update_layer_buffer(mixer, layer->id, plane);
  40. sun8i_mixer_layer_enable(mixer, layer->id, true);
  41. }
  42. static struct drm_plane_helper_funcs sun8i_mixer_layer_helper_funcs = {
  43. .atomic_disable = sun8i_mixer_layer_atomic_disable,
  44. .atomic_update = sun8i_mixer_layer_atomic_update,
  45. };
  46. static const struct drm_plane_funcs sun8i_mixer_layer_funcs = {
  47. .atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
  48. .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
  49. .destroy = drm_plane_cleanup,
  50. .disable_plane = drm_atomic_helper_disable_plane,
  51. .reset = drm_atomic_helper_plane_reset,
  52. .update_plane = drm_atomic_helper_update_plane,
  53. };
  54. static const uint32_t sun8i_mixer_layer_formats[] = {
  55. DRM_FORMAT_RGB888,
  56. DRM_FORMAT_ARGB8888,
  57. DRM_FORMAT_XRGB8888,
  58. };
  59. static const struct sun8i_plane_desc sun8i_mixer_planes[] = {
  60. {
  61. .type = DRM_PLANE_TYPE_PRIMARY,
  62. .formats = sun8i_mixer_layer_formats,
  63. .nformats = ARRAY_SIZE(sun8i_mixer_layer_formats),
  64. },
  65. };
  66. static struct sun8i_layer *sun8i_layer_init_one(struct drm_device *drm,
  67. struct sun8i_mixer *mixer,
  68. const struct sun8i_plane_desc *plane)
  69. {
  70. struct sun8i_layer *layer;
  71. int ret;
  72. layer = devm_kzalloc(drm->dev, sizeof(*layer), GFP_KERNEL);
  73. if (!layer)
  74. return ERR_PTR(-ENOMEM);
  75. /* possible crtcs are set later */
  76. ret = drm_universal_plane_init(drm, &layer->plane, 0,
  77. &sun8i_mixer_layer_funcs,
  78. plane->formats, plane->nformats,
  79. NULL, plane->type, NULL);
  80. if (ret) {
  81. dev_err(drm->dev, "Couldn't initialize layer\n");
  82. return ERR_PTR(ret);
  83. }
  84. drm_plane_helper_add(&layer->plane,
  85. &sun8i_mixer_layer_helper_funcs);
  86. layer->mixer = mixer;
  87. return layer;
  88. }
  89. struct drm_plane **sun8i_layers_init(struct drm_device *drm,
  90. struct sunxi_engine *engine)
  91. {
  92. struct drm_plane **planes;
  93. struct sun8i_mixer *mixer = engine_to_sun8i_mixer(engine);
  94. int i;
  95. planes = devm_kcalloc(drm->dev, ARRAY_SIZE(sun8i_mixer_planes) + 1,
  96. sizeof(*planes), GFP_KERNEL);
  97. if (!planes)
  98. return ERR_PTR(-ENOMEM);
  99. for (i = 0; i < ARRAY_SIZE(sun8i_mixer_planes); i++) {
  100. const struct sun8i_plane_desc *plane = &sun8i_mixer_planes[i];
  101. struct sun8i_layer *layer;
  102. layer = sun8i_layer_init_one(drm, mixer, plane);
  103. if (IS_ERR(layer)) {
  104. dev_err(drm->dev, "Couldn't initialize %s plane\n",
  105. i ? "overlay" : "primary");
  106. return ERR_CAST(layer);
  107. };
  108. layer->id = i;
  109. planes[i] = &layer->plane;
  110. };
  111. return planes;
  112. }