arcpgu_sim.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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_atomic_helper.h>
  18. #include "arcpgu.h"
  19. #define XRES_DEF 640
  20. #define YRES_DEF 480
  21. #define XRES_MAX 8192
  22. #define YRES_MAX 8192
  23. struct arcpgu_drm_connector {
  24. struct drm_connector connector;
  25. };
  26. static int arcpgu_drm_connector_get_modes(struct drm_connector *connector)
  27. {
  28. int count;
  29. count = drm_add_modes_noedid(connector, XRES_MAX, YRES_MAX);
  30. drm_set_preferred_mode(connector, XRES_DEF, YRES_DEF);
  31. return count;
  32. }
  33. static void arcpgu_drm_connector_destroy(struct drm_connector *connector)
  34. {
  35. drm_connector_unregister(connector);
  36. drm_connector_cleanup(connector);
  37. }
  38. static const struct drm_connector_helper_funcs
  39. arcpgu_drm_connector_helper_funcs = {
  40. .get_modes = arcpgu_drm_connector_get_modes,
  41. };
  42. static const struct drm_connector_funcs arcpgu_drm_connector_funcs = {
  43. .dpms = drm_helper_connector_dpms,
  44. .reset = drm_atomic_helper_connector_reset,
  45. .fill_modes = drm_helper_probe_single_connector_modes,
  46. .destroy = arcpgu_drm_connector_destroy,
  47. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  48. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  49. };
  50. static struct drm_encoder_funcs arcpgu_drm_encoder_funcs = {
  51. .destroy = drm_encoder_cleanup,
  52. };
  53. int arcpgu_drm_sim_init(struct drm_device *drm, struct device_node *np)
  54. {
  55. struct arcpgu_drm_connector *arcpgu_connector;
  56. struct drm_encoder *encoder;
  57. struct drm_connector *connector;
  58. int ret;
  59. encoder = devm_kzalloc(drm->dev, sizeof(*encoder), GFP_KERNEL);
  60. if (encoder == NULL)
  61. return -ENOMEM;
  62. encoder->possible_crtcs = 1;
  63. encoder->possible_clones = 0;
  64. ret = drm_encoder_init(drm, encoder, &arcpgu_drm_encoder_funcs,
  65. DRM_MODE_ENCODER_VIRTUAL, NULL);
  66. if (ret)
  67. return ret;
  68. arcpgu_connector = devm_kzalloc(drm->dev, sizeof(*arcpgu_connector),
  69. GFP_KERNEL);
  70. if (!arcpgu_connector) {
  71. ret = -ENOMEM;
  72. goto error_encoder_cleanup;
  73. }
  74. connector = &arcpgu_connector->connector;
  75. drm_connector_helper_add(connector, &arcpgu_drm_connector_helper_funcs);
  76. ret = drm_connector_init(drm, connector, &arcpgu_drm_connector_funcs,
  77. DRM_MODE_CONNECTOR_VIRTUAL);
  78. if (ret < 0) {
  79. dev_err(drm->dev, "failed to initialize drm connector\n");
  80. goto error_encoder_cleanup;
  81. }
  82. ret = drm_connector_attach_encoder(connector, encoder);
  83. if (ret < 0) {
  84. dev_err(drm->dev, "could not attach connector to encoder\n");
  85. drm_connector_unregister(connector);
  86. goto error_connector_cleanup;
  87. }
  88. return 0;
  89. error_connector_cleanup:
  90. drm_connector_cleanup(connector);
  91. error_encoder_cleanup:
  92. drm_encoder_cleanup(encoder);
  93. return ret;
  94. }