arcpgu_sim.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 void arcpgu_drm_connector_destroy(struct drm_connector *connector)
  36. {
  37. drm_connector_unregister(connector);
  38. drm_connector_cleanup(connector);
  39. }
  40. static const struct drm_connector_helper_funcs
  41. arcpgu_drm_connector_helper_funcs = {
  42. .get_modes = arcpgu_drm_connector_get_modes,
  43. };
  44. static const struct drm_connector_funcs arcpgu_drm_connector_funcs = {
  45. .dpms = drm_helper_connector_dpms,
  46. .reset = drm_atomic_helper_connector_reset,
  47. .fill_modes = drm_helper_probe_single_connector_modes,
  48. .destroy = arcpgu_drm_connector_destroy,
  49. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  50. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  51. };
  52. static struct drm_encoder_funcs arcpgu_drm_encoder_funcs = {
  53. .destroy = drm_encoder_cleanup,
  54. };
  55. int arcpgu_drm_sim_init(struct drm_device *drm, struct device_node *np)
  56. {
  57. struct arcpgu_drm_connector *arcpgu_connector;
  58. struct drm_encoder_slave *encoder;
  59. struct drm_connector *connector;
  60. int ret;
  61. encoder = devm_kzalloc(drm->dev, sizeof(*encoder), GFP_KERNEL);
  62. if (encoder == NULL)
  63. return -ENOMEM;
  64. encoder->base.possible_crtcs = 1;
  65. encoder->base.possible_clones = 0;
  66. ret = drm_encoder_init(drm, &encoder->base, &arcpgu_drm_encoder_funcs,
  67. DRM_MODE_ENCODER_VIRTUAL, NULL);
  68. if (ret)
  69. return ret;
  70. arcpgu_connector = devm_kzalloc(drm->dev, sizeof(*arcpgu_connector),
  71. GFP_KERNEL);
  72. if (!arcpgu_connector) {
  73. ret = -ENOMEM;
  74. goto error_encoder_cleanup;
  75. }
  76. connector = &arcpgu_connector->connector;
  77. drm_connector_helper_add(connector, &arcpgu_drm_connector_helper_funcs);
  78. ret = drm_connector_init(drm, connector, &arcpgu_drm_connector_funcs,
  79. DRM_MODE_CONNECTOR_VIRTUAL);
  80. if (ret < 0) {
  81. dev_err(drm->dev, "failed to initialize drm connector\n");
  82. goto error_encoder_cleanup;
  83. }
  84. ret = drm_mode_connector_attach_encoder(connector, &encoder->base);
  85. if (ret < 0) {
  86. dev_err(drm->dev, "could not attach connector to encoder\n");
  87. drm_connector_unregister(connector);
  88. goto error_connector_cleanup;
  89. }
  90. arcpgu_connector->encoder_slave = encoder;
  91. return 0;
  92. error_connector_cleanup:
  93. drm_connector_cleanup(connector);
  94. error_encoder_cleanup:
  95. drm_encoder_cleanup(&encoder->base);
  96. return ret;
  97. }