]>
Commit | Line | Data |
---|---|---|
a189d28e RD |
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 | ||
17 | #include <drm/drm_crtc_helper.h> | |
18 | #include <drm/drm_encoder_slave.h> | |
19 | #include <drm/drm_atomic_helper.h> | |
20 | ||
21 | #include "arcpgu.h" | |
22 | ||
23 | #define XRES_DEF 640 | |
24 | #define YRES_DEF 480 | |
25 | ||
26 | #define XRES_MAX 8192 | |
27 | #define YRES_MAX 8192 | |
28 | ||
29 | ||
30 | struct arcpgu_drm_connector { | |
31 | struct drm_connector connector; | |
32 | struct drm_encoder_slave *encoder_slave; | |
33 | }; | |
34 | ||
35 | static int arcpgu_drm_connector_get_modes(struct drm_connector *connector) | |
36 | { | |
37 | int count; | |
38 | ||
39 | count = drm_add_modes_noedid(connector, XRES_MAX, YRES_MAX); | |
40 | drm_set_preferred_mode(connector, XRES_DEF, YRES_DEF); | |
41 | return count; | |
42 | } | |
43 | ||
44 | static enum drm_connector_status | |
45 | arcpgu_drm_connector_detect(struct drm_connector *connector, bool force) | |
46 | { | |
47 | return connector_status_connected; | |
48 | } | |
49 | ||
50 | static void arcpgu_drm_connector_destroy(struct drm_connector *connector) | |
51 | { | |
52 | drm_connector_unregister(connector); | |
53 | drm_connector_cleanup(connector); | |
54 | } | |
55 | ||
56 | static const struct drm_connector_helper_funcs | |
57 | arcpgu_drm_connector_helper_funcs = { | |
58 | .get_modes = arcpgu_drm_connector_get_modes, | |
59 | }; | |
60 | ||
61 | static const struct drm_connector_funcs arcpgu_drm_connector_funcs = { | |
62 | .dpms = drm_helper_connector_dpms, | |
63 | .reset = drm_atomic_helper_connector_reset, | |
64 | .detect = arcpgu_drm_connector_detect, | |
65 | .fill_modes = drm_helper_probe_single_connector_modes, | |
66 | .destroy = arcpgu_drm_connector_destroy, | |
67 | .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, | |
68 | .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, | |
69 | }; | |
70 | ||
71 | static struct drm_encoder_funcs arcpgu_drm_encoder_funcs = { | |
72 | .destroy = drm_encoder_cleanup, | |
73 | }; | |
74 | ||
75 | int arcpgu_drm_sim_init(struct drm_device *drm, struct device_node *np) | |
76 | { | |
77 | struct arcpgu_drm_connector *arcpgu_connector; | |
78 | struct drm_encoder_slave *encoder; | |
79 | struct drm_connector *connector; | |
80 | int ret; | |
81 | ||
82 | encoder = devm_kzalloc(drm->dev, sizeof(*encoder), GFP_KERNEL); | |
83 | if (encoder == NULL) | |
84 | return -ENOMEM; | |
85 | ||
86 | encoder->base.possible_crtcs = 1; | |
87 | encoder->base.possible_clones = 0; | |
88 | ||
89 | ret = drm_encoder_init(drm, &encoder->base, &arcpgu_drm_encoder_funcs, | |
90 | DRM_MODE_ENCODER_VIRTUAL, NULL); | |
91 | if (ret) | |
92 | return ret; | |
93 | ||
94 | arcpgu_connector = devm_kzalloc(drm->dev, sizeof(*arcpgu_connector), | |
95 | GFP_KERNEL); | |
96 | if (!arcpgu_connector) { | |
97 | ret = -ENOMEM; | |
98 | goto error_encoder_cleanup; | |
99 | } | |
100 | ||
101 | connector = &arcpgu_connector->connector; | |
102 | drm_connector_helper_add(connector, &arcpgu_drm_connector_helper_funcs); | |
103 | ||
104 | ret = drm_connector_init(drm, connector, &arcpgu_drm_connector_funcs, | |
105 | DRM_MODE_CONNECTOR_VIRTUAL); | |
106 | if (ret < 0) { | |
107 | dev_err(drm->dev, "failed to initialize drm connector\n"); | |
108 | goto error_encoder_cleanup; | |
109 | } | |
110 | ||
111 | ret = drm_mode_connector_attach_encoder(connector, &encoder->base); | |
112 | if (ret < 0) { | |
113 | dev_err(drm->dev, "could not attach connector to encoder\n"); | |
114 | drm_connector_unregister(connector); | |
115 | goto error_connector_cleanup; | |
116 | } | |
117 | ||
118 | arcpgu_connector->encoder_slave = encoder; | |
119 | ||
120 | return 0; | |
121 | ||
122 | error_connector_cleanup: | |
123 | drm_connector_cleanup(connector); | |
124 | ||
125 | error_encoder_cleanup: | |
126 | drm_encoder_cleanup(&encoder->base); | |
127 | return ret; | |
128 | } |