2 * drivers/gpu/drm/omapdrm/omap_encoder.c
4 * Copyright (C) 2011 Texas Instruments
5 * Author: Rob Clark <rob@ti.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * You should have received a copy of the GNU General Public License along with
17 * this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <linux/list.h>
22 #include <drm/drm_crtc.h>
23 #include <drm/drm_crtc_helper.h>
24 #include <drm/drm_edid.h>
32 #define to_omap_encoder(x) container_of(x, struct omap_encoder, base)
34 /* The encoder and connector both map to same dssdev.. the encoder
35 * handles the 'active' parts, ie. anything the modifies the state
36 * of the hw, and the connector handles the 'read-only' parts, like
37 * detecting connection and reading edid.
40 struct drm_encoder base
;
41 struct omap_dss_device
*dssdev
;
44 struct omap_dss_device
*omap_encoder_get_dssdev(struct drm_encoder
*encoder
)
46 struct omap_encoder
*omap_encoder
= to_omap_encoder(encoder
);
48 return omap_encoder
->dssdev
;
51 static void omap_encoder_destroy(struct drm_encoder
*encoder
)
53 struct omap_encoder
*omap_encoder
= to_omap_encoder(encoder
);
55 drm_encoder_cleanup(encoder
);
59 static const struct drm_encoder_funcs omap_encoder_funcs
= {
60 .destroy
= omap_encoder_destroy
,
63 static void omap_encoder_mode_set(struct drm_encoder
*encoder
,
64 struct drm_display_mode
*mode
,
65 struct drm_display_mode
*adjusted_mode
)
67 struct drm_device
*dev
= encoder
->dev
;
68 struct omap_encoder
*omap_encoder
= to_omap_encoder(encoder
);
69 struct omap_dss_device
*dssdev
= omap_encoder
->dssdev
;
70 struct drm_connector
*connector
;
75 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
76 if (connector
->encoder
== encoder
) {
77 hdmi_mode
= omap_connector_get_hdmi_mode(connector
);
82 if (dssdev
->driver
->set_hdmi_mode
)
83 dssdev
->driver
->set_hdmi_mode(dssdev
, hdmi_mode
);
85 if (hdmi_mode
&& dssdev
->driver
->set_hdmi_infoframe
) {
86 struct hdmi_avi_infoframe avi
;
88 r
= drm_hdmi_avi_infoframe_from_display_mode(&avi
, adjusted_mode
);
90 dssdev
->driver
->set_hdmi_infoframe(dssdev
, &avi
);
94 static void omap_encoder_disable(struct drm_encoder
*encoder
)
96 struct omap_encoder
*omap_encoder
= to_omap_encoder(encoder
);
97 struct omap_dss_device
*dssdev
= omap_encoder
->dssdev
;
98 struct omap_dss_driver
*dssdrv
= dssdev
->driver
;
100 dssdrv
->disable(dssdev
);
103 static int omap_encoder_update(struct drm_encoder
*encoder
,
104 enum omap_channel channel
,
105 struct omap_video_timings
*timings
)
107 struct drm_device
*dev
= encoder
->dev
;
108 struct omap_encoder
*omap_encoder
= to_omap_encoder(encoder
);
109 struct omap_dss_device
*dssdev
= omap_encoder
->dssdev
;
110 struct omap_dss_driver
*dssdrv
= dssdev
->driver
;
113 dssdev
->src
->manager
= omap_dss_get_overlay_manager(channel
);
115 if (dssdrv
->check_timings
) {
116 ret
= dssdrv
->check_timings(dssdev
, timings
);
118 struct omap_video_timings t
= {0};
120 dssdrv
->get_timings(dssdev
, &t
);
122 if (memcmp(timings
, &t
, sizeof(struct omap_video_timings
)))
129 dev_err(dev
->dev
, "could not set timings: %d\n", ret
);
133 if (dssdrv
->set_timings
)
134 dssdrv
->set_timings(dssdev
, timings
);
139 static void omap_encoder_enable(struct drm_encoder
*encoder
)
141 struct omap_encoder
*omap_encoder
= to_omap_encoder(encoder
);
142 struct omap_dss_device
*dssdev
= omap_encoder
->dssdev
;
143 struct omap_dss_driver
*dssdrv
= dssdev
->driver
;
145 omap_encoder_update(encoder
, omap_crtc_channel(encoder
->crtc
),
146 omap_crtc_timings(encoder
->crtc
));
148 dssdrv
->enable(dssdev
);
151 static int omap_encoder_atomic_check(struct drm_encoder
*encoder
,
152 struct drm_crtc_state
*crtc_state
,
153 struct drm_connector_state
*conn_state
)
158 static const struct drm_encoder_helper_funcs omap_encoder_helper_funcs
= {
159 .mode_set
= omap_encoder_mode_set
,
160 .disable
= omap_encoder_disable
,
161 .enable
= omap_encoder_enable
,
162 .atomic_check
= omap_encoder_atomic_check
,
165 /* initialize encoder */
166 struct drm_encoder
*omap_encoder_init(struct drm_device
*dev
,
167 struct omap_dss_device
*dssdev
)
169 struct drm_encoder
*encoder
= NULL
;
170 struct omap_encoder
*omap_encoder
;
172 omap_encoder
= kzalloc(sizeof(*omap_encoder
), GFP_KERNEL
);
176 omap_encoder
->dssdev
= dssdev
;
178 encoder
= &omap_encoder
->base
;
180 drm_encoder_init(dev
, encoder
, &omap_encoder_funcs
,
181 DRM_MODE_ENCODER_TMDS
);
182 drm_encoder_helper_add(encoder
, &omap_encoder_helper_funcs
);
188 omap_encoder_destroy(encoder
);