diff options
Diffstat (limited to 'drivers/gpu/drm/rcar-du/rcar_du_vga.c')
-rw-r--r-- | drivers/gpu/drm/rcar-du/rcar_du_vga.c | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/drivers/gpu/drm/rcar-du/rcar_du_vga.c b/drivers/gpu/drm/rcar-du/rcar_du_vga.c new file mode 100644 index 000000000000..327289ec380d --- /dev/null +++ b/drivers/gpu/drm/rcar-du/rcar_du_vga.c | |||
@@ -0,0 +1,149 @@ | |||
1 | /* | ||
2 | * rcar_du_vga.c -- R-Car Display Unit VGA DAC and Connector | ||
3 | * | ||
4 | * Copyright (C) 2013 Renesas Corporation | ||
5 | * | ||
6 | * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com) | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | */ | ||
13 | |||
14 | #include <drm/drmP.h> | ||
15 | #include <drm/drm_crtc.h> | ||
16 | #include <drm/drm_crtc_helper.h> | ||
17 | |||
18 | #include "rcar_du_drv.h" | ||
19 | #include "rcar_du_kms.h" | ||
20 | #include "rcar_du_vga.h" | ||
21 | |||
22 | /* ----------------------------------------------------------------------------- | ||
23 | * Connector | ||
24 | */ | ||
25 | |||
26 | static int rcar_du_vga_connector_get_modes(struct drm_connector *connector) | ||
27 | { | ||
28 | return 0; | ||
29 | } | ||
30 | |||
31 | static int rcar_du_vga_connector_mode_valid(struct drm_connector *connector, | ||
32 | struct drm_display_mode *mode) | ||
33 | { | ||
34 | return MODE_OK; | ||
35 | } | ||
36 | |||
37 | static const struct drm_connector_helper_funcs connector_helper_funcs = { | ||
38 | .get_modes = rcar_du_vga_connector_get_modes, | ||
39 | .mode_valid = rcar_du_vga_connector_mode_valid, | ||
40 | .best_encoder = rcar_du_connector_best_encoder, | ||
41 | }; | ||
42 | |||
43 | static void rcar_du_vga_connector_destroy(struct drm_connector *connector) | ||
44 | { | ||
45 | drm_sysfs_connector_remove(connector); | ||
46 | drm_connector_cleanup(connector); | ||
47 | } | ||
48 | |||
49 | static enum drm_connector_status | ||
50 | rcar_du_vga_connector_detect(struct drm_connector *connector, bool force) | ||
51 | { | ||
52 | return connector_status_unknown; | ||
53 | } | ||
54 | |||
55 | static const struct drm_connector_funcs connector_funcs = { | ||
56 | .dpms = drm_helper_connector_dpms, | ||
57 | .detect = rcar_du_vga_connector_detect, | ||
58 | .fill_modes = drm_helper_probe_single_connector_modes, | ||
59 | .destroy = rcar_du_vga_connector_destroy, | ||
60 | }; | ||
61 | |||
62 | static int rcar_du_vga_connector_init(struct rcar_du_device *rcdu, | ||
63 | struct rcar_du_encoder *renc) | ||
64 | { | ||
65 | struct rcar_du_connector *rcon; | ||
66 | struct drm_connector *connector; | ||
67 | int ret; | ||
68 | |||
69 | rcon = devm_kzalloc(rcdu->dev, sizeof(*rcon), GFP_KERNEL); | ||
70 | if (rcon == NULL) | ||
71 | return -ENOMEM; | ||
72 | |||
73 | connector = &rcon->connector; | ||
74 | connector->display_info.width_mm = 0; | ||
75 | connector->display_info.height_mm = 0; | ||
76 | |||
77 | ret = drm_connector_init(rcdu->ddev, connector, &connector_funcs, | ||
78 | DRM_MODE_CONNECTOR_VGA); | ||
79 | if (ret < 0) | ||
80 | return ret; | ||
81 | |||
82 | drm_connector_helper_add(connector, &connector_helper_funcs); | ||
83 | ret = drm_sysfs_connector_add(connector); | ||
84 | if (ret < 0) | ||
85 | return ret; | ||
86 | |||
87 | drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF); | ||
88 | drm_object_property_set_value(&connector->base, | ||
89 | rcdu->ddev->mode_config.dpms_property, DRM_MODE_DPMS_OFF); | ||
90 | |||
91 | ret = drm_mode_connector_attach_encoder(connector, &renc->encoder); | ||
92 | if (ret < 0) | ||
93 | return ret; | ||
94 | |||
95 | connector->encoder = &renc->encoder; | ||
96 | rcon->encoder = renc; | ||
97 | |||
98 | return 0; | ||
99 | } | ||
100 | |||
101 | /* ----------------------------------------------------------------------------- | ||
102 | * Encoder | ||
103 | */ | ||
104 | |||
105 | static void rcar_du_vga_encoder_dpms(struct drm_encoder *encoder, int mode) | ||
106 | { | ||
107 | } | ||
108 | |||
109 | static bool rcar_du_vga_encoder_mode_fixup(struct drm_encoder *encoder, | ||
110 | const struct drm_display_mode *mode, | ||
111 | struct drm_display_mode *adjusted_mode) | ||
112 | { | ||
113 | return true; | ||
114 | } | ||
115 | |||
116 | static const struct drm_encoder_helper_funcs encoder_helper_funcs = { | ||
117 | .dpms = rcar_du_vga_encoder_dpms, | ||
118 | .mode_fixup = rcar_du_vga_encoder_mode_fixup, | ||
119 | .prepare = rcar_du_encoder_mode_prepare, | ||
120 | .commit = rcar_du_encoder_mode_commit, | ||
121 | .mode_set = rcar_du_encoder_mode_set, | ||
122 | }; | ||
123 | |||
124 | static const struct drm_encoder_funcs encoder_funcs = { | ||
125 | .destroy = drm_encoder_cleanup, | ||
126 | }; | ||
127 | |||
128 | int rcar_du_vga_init(struct rcar_du_device *rcdu, | ||
129 | const struct rcar_du_encoder_vga_data *data, | ||
130 | unsigned int output) | ||
131 | { | ||
132 | struct rcar_du_encoder *renc; | ||
133 | int ret; | ||
134 | |||
135 | renc = devm_kzalloc(rcdu->dev, sizeof(*renc), GFP_KERNEL); | ||
136 | if (renc == NULL) | ||
137 | return -ENOMEM; | ||
138 | |||
139 | renc->output = output; | ||
140 | |||
141 | ret = drm_encoder_init(rcdu->ddev, &renc->encoder, &encoder_funcs, | ||
142 | DRM_MODE_ENCODER_DAC); | ||
143 | if (ret < 0) | ||
144 | return ret; | ||
145 | |||
146 | drm_encoder_helper_add(&renc->encoder, &encoder_helper_funcs); | ||
147 | |||
148 | return rcar_du_vga_connector_init(rcdu, renc); | ||
149 | } | ||