WIP FPC-III support
[linux/fpc-iii.git] / drivers / gpu / drm / arc / arcpgu_sim.c
blob37d961668dfec9e5fb9a156208190d1f38202730
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * ARC PGU DRM driver.
5 * Copyright (C) 2016 Synopsys, Inc. (www.synopsys.com)
6 */
8 #include <drm/drm_atomic_helper.h>
9 #include <drm/drm_device.h>
10 #include <drm/drm_probe_helper.h>
12 #include "arcpgu.h"
14 #define XRES_DEF 640
15 #define YRES_DEF 480
17 #define XRES_MAX 8192
18 #define YRES_MAX 8192
21 struct arcpgu_drm_connector {
22 struct drm_connector connector;
25 static int arcpgu_drm_connector_get_modes(struct drm_connector *connector)
27 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;
34 static void arcpgu_drm_connector_destroy(struct drm_connector *connector)
36 drm_connector_unregister(connector);
37 drm_connector_cleanup(connector);
40 static const struct drm_connector_helper_funcs
41 arcpgu_drm_connector_helper_funcs = {
42 .get_modes = arcpgu_drm_connector_get_modes,
45 static const struct drm_connector_funcs arcpgu_drm_connector_funcs = {
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,
53 static struct drm_encoder_funcs arcpgu_drm_encoder_funcs = {
54 .destroy = drm_encoder_cleanup,
57 int arcpgu_drm_sim_init(struct drm_device *drm, struct device_node *np)
59 struct arcpgu_drm_connector *arcpgu_connector;
60 struct drm_encoder *encoder;
61 struct drm_connector *connector;
62 int ret;
64 encoder = devm_kzalloc(drm->dev, sizeof(*encoder), GFP_KERNEL);
65 if (encoder == NULL)
66 return -ENOMEM;
68 encoder->possible_crtcs = 1;
69 encoder->possible_clones = 0;
71 ret = drm_encoder_init(drm, encoder, &arcpgu_drm_encoder_funcs,
72 DRM_MODE_ENCODER_VIRTUAL, NULL);
73 if (ret)
74 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;
83 connector = &arcpgu_connector->connector;
84 drm_connector_helper_add(connector, &arcpgu_drm_connector_helper_funcs);
86 ret = drm_connector_init(drm, connector, &arcpgu_drm_connector_funcs,
87 DRM_MODE_CONNECTOR_VIRTUAL);
88 if (ret < 0) {
89 dev_err(drm->dev, "failed to initialize drm connector\n");
90 goto error_encoder_cleanup;
93 ret = drm_connector_attach_encoder(connector, encoder);
94 if (ret < 0) {
95 dev_err(drm->dev, "could not attach connector to encoder\n");
96 drm_connector_unregister(connector);
97 goto error_connector_cleanup;
100 return 0;
102 error_connector_cleanup:
103 drm_connector_cleanup(connector);
105 error_encoder_cleanup:
106 drm_encoder_cleanup(encoder);
107 return ret;