2 * drivers/staging/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/>.
23 #include "drm_crtc_helper.h"
29 #define to_omap_encoder(x) container_of(x, struct omap_encoder, base)
32 struct drm_encoder base
;
33 struct omap_overlay_manager
*mgr
;
36 static void omap_encoder_destroy(struct drm_encoder
*encoder
)
38 struct omap_encoder
*omap_encoder
= to_omap_encoder(encoder
);
39 DBG("%s", omap_encoder
->mgr
->name
);
40 drm_encoder_cleanup(encoder
);
44 static void omap_encoder_dpms(struct drm_encoder
*encoder
, int mode
)
46 struct omap_encoder
*omap_encoder
= to_omap_encoder(encoder
);
47 DBG("%s: %d", omap_encoder
->mgr
->name
, mode
);
50 static bool omap_encoder_mode_fixup(struct drm_encoder
*encoder
,
51 struct drm_display_mode
*mode
,
52 struct drm_display_mode
*adjusted_mode
)
54 struct omap_encoder
*omap_encoder
= to_omap_encoder(encoder
);
55 DBG("%s", omap_encoder
->mgr
->name
);
59 static void omap_encoder_mode_set(struct drm_encoder
*encoder
,
60 struct drm_display_mode
*mode
,
61 struct drm_display_mode
*adjusted_mode
)
63 struct omap_encoder
*omap_encoder
= to_omap_encoder(encoder
);
64 struct drm_device
*dev
= encoder
->dev
;
65 struct omap_drm_private
*priv
= dev
->dev_private
;
70 DBG("%s: set mode: %dx%d", omap_encoder
->mgr
->name
,
71 mode
->hdisplay
, mode
->vdisplay
);
73 for (i
= 0; i
< priv
->num_connectors
; i
++) {
74 struct drm_connector
*connector
= priv
->connectors
[i
];
75 if (connector
->encoder
== encoder
) {
76 omap_connector_mode_set(connector
, mode
);
81 static void omap_encoder_prepare(struct drm_encoder
*encoder
)
83 struct omap_encoder
*omap_encoder
= to_omap_encoder(encoder
);
84 struct drm_encoder_helper_funcs
*encoder_funcs
=
85 encoder
->helper_private
;
86 DBG("%s", omap_encoder
->mgr
->name
);
87 encoder_funcs
->dpms(encoder
, DRM_MODE_DPMS_OFF
);
90 static void omap_encoder_commit(struct drm_encoder
*encoder
)
92 struct omap_encoder
*omap_encoder
= to_omap_encoder(encoder
);
93 struct drm_encoder_helper_funcs
*encoder_funcs
=
94 encoder
->helper_private
;
95 DBG("%s", omap_encoder
->mgr
->name
);
96 omap_encoder
->mgr
->apply(omap_encoder
->mgr
);
97 encoder_funcs
->dpms(encoder
, DRM_MODE_DPMS_ON
);
100 static const struct drm_encoder_funcs omap_encoder_funcs
= {
101 .destroy
= omap_encoder_destroy
,
104 static const struct drm_encoder_helper_funcs omap_encoder_helper_funcs
= {
105 .dpms
= omap_encoder_dpms
,
106 .mode_fixup
= omap_encoder_mode_fixup
,
107 .mode_set
= omap_encoder_mode_set
,
108 .prepare
= omap_encoder_prepare
,
109 .commit
= omap_encoder_commit
,
112 struct omap_overlay_manager
*omap_encoder_get_manager(
113 struct drm_encoder
*encoder
)
115 struct omap_encoder
*omap_encoder
= to_omap_encoder(encoder
);
116 return omap_encoder
->mgr
;
119 /* initialize encoder */
120 struct drm_encoder
*omap_encoder_init(struct drm_device
*dev
,
121 struct omap_overlay_manager
*mgr
)
123 struct drm_encoder
*encoder
= NULL
;
124 struct omap_encoder
*omap_encoder
;
125 struct omap_overlay_manager_info info
;
128 DBG("%s", mgr
->name
);
130 omap_encoder
= kzalloc(sizeof(*omap_encoder
), GFP_KERNEL
);
132 dev_err(dev
->dev
, "could not allocate encoder\n");
136 omap_encoder
->mgr
= mgr
;
137 encoder
= &omap_encoder
->base
;
139 drm_encoder_init(dev
, encoder
, &omap_encoder_funcs
,
140 DRM_MODE_ENCODER_TMDS
);
141 drm_encoder_helper_add(encoder
, &omap_encoder_helper_funcs
);
143 mgr
->get_manager_info(mgr
, &info
);
145 /* TODO: fix hard-coded setup.. */
146 info
.default_color
= 0x00000000;
147 info
.trans_key
= 0x00000000;
148 info
.trans_key_type
= OMAP_DSS_COLOR_KEY_GFX_DST
;
149 info
.trans_enabled
= false;
151 ret
= mgr
->set_manager_info(mgr
, &info
);
153 dev_err(dev
->dev
, "could not set manager info\n");
157 ret
= mgr
->apply(mgr
);
159 dev_err(dev
->dev
, "could not apply\n");
167 omap_encoder_destroy(encoder
);