arcpgu_sim.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * ARC PGU DRM driver.
  3. *
  4. * Copyright (C) 2016 Synopsys, Inc. (www.synopsys.com)
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. */
  16. #include <drm/drm_crtc_helper.h>
  17. #include <drm/drm_encoder_slave.h>
  18. #include <drm/drm_atomic_helper.h>
  19. #include "arcpgu.h"
  20. #define XRES_DEF 640
  21. #define YRES_DEF 480
  22. #define XRES_MAX 8192
  23. #define YRES_MAX 8192
  24. struct arcpgu_drm_connector {
  25. struct drm_connector connector;
  26. struct drm_encoder_slave *encoder_slave;
  27. };
  28. static int arcpgu_drm_connector_get_modes(struct drm_connector *connector)
  29. {
  30. int count;
  31. count = drm_add_modes_noedid(connector, XRES_MAX, YRES_MAX);
  32. drm_set_preferred_mode(connector, XRES_DEF, YRES_DEF);
  33. return count;
  34. }
  35. static enum drm_connector_status
  36. arcpgu_drm_connector_detect(struct drm_connector *connector, bool force)
  37. {
  38. return connector_status_connected;
  39. }
  40. static void arcpgu_drm_connector_destroy(struct drm_connector *connector)
  41. {
  42. drm_connector_unregister(connector);
  43. drm_connector_cleanup(connector);
  44. }
  45. static const struct drm_connector_helper_funcs
  46. arcpgu_drm_connector_helper_funcs = {
  47. .get_modes = arcpgu_drm_connector_get_modes,
  48. };
  49. static const struct drm_connector_funcs arcpgu_drm_connector_funcs = {
  50. .dpms = drm_helper_connector_dpms,
  51. .reset = drm_atomic_helper_connector_reset,
  52. .detect = arcpgu_drm_connector_detect,
  53. .fill_modes = drm_helper_probe_single_connector_modes,
  54. .destroy = arcpgu_drm_connector_destroy,
  55. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  56. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  57. };
  58. static struct drm_encoder_funcs arcpgu_drm_encoder_funcs = {
  59. .destroy = drm_encoder_cleanup,
  60. };
  61. int arcpgu_drm_sim_init(struct drm_device *drm, struct device_node *np)
  62. {
  63. struct arcpgu_drm_connector *arcpgu_connector;
  64. struct drm_encoder_slave *encoder;
  65. struct drm_connector *connector;
  66. int ret;
  67. encoder = devm_kzalloc(drm->dev, sizeof(*encoder), GFP_KERNEL);
  68. if (encoder == NULL)
  69. return -ENOMEM;
  70. encoder->base.possible_crtcs = 1;
  71. encoder->base.possible_clones = 0;
  72. ret = drm_encoder_init(drm, &encoder->base, &arcpgu_drm_encoder_funcs,
  73. DRM_MODE_ENCODER_VIRTUAL, NULL);
  74. if (ret)
  75. return ret;
  76. arcpgu_connector = devm_kzalloc(drm->dev, sizeof(*arcpgu_connector),
  77. GFP_KERNEL);
  78. if (!arcpgu_connector) {
  79. ret = -ENOMEM;
  80. goto error_encoder_cleanup;
  81. }
  82. connector = &arcpgu_connector->connector;
  83. drm_connector_helper_add(connector, &arcpgu_drm_connector_helper_funcs);
  84. ret = drm_connector_init(drm, connector, &arcpgu_drm_connector_funcs,
  85. DRM_MODE_CONNECTOR_VIRTUAL);
  86. if (ret < 0) {
  87. dev_err(drm->dev, "failed to initialize drm connector\n");
  88. goto error_encoder_cleanup;
  89. }
  90. ret = drm_mode_connector_attach_encoder(connector, &encoder->base);
  91. if (ret < 0) {
  92. dev_err(drm->dev, "could not attach connector to encoder\n");
  93. drm_connector_unregister(connector);
  94. goto error_connector_cleanup;
  95. }
  96. arcpgu_connector->encoder_slave = encoder;
  97. return 0;
  98. error_connector_cleanup:
  99. drm_connector_cleanup(connector);
  100. error_encoder_cleanup:
  101. drm_encoder_cleanup(&encoder->base);
  102. return ret;
  103. }