Merge branch 'devel-stable' of master.kernel.org:/home/rmk/linux-2.6-arm
[pandora-kernel.git] / drivers / video / omap2 / dss / dss_features.c
1 /*
2  * linux/drivers/video/omap2/dss/dss_features.c
3  *
4  * Copyright (C) 2010 Texas Instruments
5  * Author: Archit Taneja <archit@ti.com>
6  *
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.
10  *
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
14  * more details.
15  *
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/>.
18  */
19
20 #include <linux/kernel.h>
21 #include <linux/types.h>
22 #include <linux/err.h>
23 #include <linux/slab.h>
24
25 #include <plat/display.h>
26 #include <plat/cpu.h>
27
28 #include "dss_features.h"
29
30 /* Defines a generic omap register field */
31 struct dss_reg_field {
32         enum dss_feat_reg_field id;
33         u8 start, end;
34 };
35
36 struct omap_dss_features {
37         const struct dss_reg_field *reg_fields;
38         const int num_reg_fields;
39
40         const u32 has_feature;
41
42         const int num_mgrs;
43         const int num_ovls;
44         const enum omap_display_type *supported_displays;
45         const enum omap_color_mode *supported_color_modes;
46 };
47
48 /* This struct is assigned to one of the below during initialization */
49 static struct omap_dss_features *omap_current_dss_features;
50
51 static const struct dss_reg_field omap2_dss_reg_fields[] = {
52         { FEAT_REG_FIRHINC, 11, 0 },
53         { FEAT_REG_FIRVINC, 27, 16 },
54         { FEAT_REG_FIFOLOWTHRESHOLD, 8, 0 },
55         { FEAT_REG_FIFOHIGHTHRESHOLD, 24, 16 },
56         { FEAT_REG_FIFOSIZE, 8, 0 },
57 };
58
59 static const struct dss_reg_field omap3_dss_reg_fields[] = {
60         { FEAT_REG_FIRHINC, 12, 0 },
61         { FEAT_REG_FIRVINC, 28, 16 },
62         { FEAT_REG_FIFOLOWTHRESHOLD, 11, 0 },
63         { FEAT_REG_FIFOHIGHTHRESHOLD, 27, 16 },
64         { FEAT_REG_FIFOSIZE, 10, 0 },
65 };
66
67 static const enum omap_display_type omap2_dss_supported_displays[] = {
68         /* OMAP_DSS_CHANNEL_LCD */
69         OMAP_DISPLAY_TYPE_DPI | OMAP_DISPLAY_TYPE_DBI |
70         OMAP_DISPLAY_TYPE_SDI | OMAP_DISPLAY_TYPE_DSI,
71
72         /* OMAP_DSS_CHANNEL_DIGIT */
73         OMAP_DISPLAY_TYPE_VENC,
74 };
75
76 static const enum omap_display_type omap3_dss_supported_displays[] = {
77         /* OMAP_DSS_CHANNEL_LCD */
78         OMAP_DISPLAY_TYPE_DPI | OMAP_DISPLAY_TYPE_DBI |
79         OMAP_DISPLAY_TYPE_SDI | OMAP_DISPLAY_TYPE_DSI,
80
81         /* OMAP_DSS_CHANNEL_DIGIT */
82         OMAP_DISPLAY_TYPE_VENC,
83 };
84
85 static const enum omap_display_type omap4_dss_supported_displays[] = {
86         /* OMAP_DSS_CHANNEL_LCD */
87         OMAP_DISPLAY_TYPE_DBI | OMAP_DISPLAY_TYPE_DSI,
88
89         /* OMAP_DSS_CHANNEL_DIGIT */
90         OMAP_DISPLAY_TYPE_VENC,
91
92         /* OMAP_DSS_CHANNEL_LCD2 */
93         OMAP_DISPLAY_TYPE_DPI | OMAP_DISPLAY_TYPE_DBI |
94         OMAP_DISPLAY_TYPE_DSI,
95 };
96
97 static const enum omap_color_mode omap2_dss_supported_color_modes[] = {
98         /* OMAP_DSS_GFX */
99         OMAP_DSS_COLOR_CLUT1 | OMAP_DSS_COLOR_CLUT2 |
100         OMAP_DSS_COLOR_CLUT4 | OMAP_DSS_COLOR_CLUT8 |
101         OMAP_DSS_COLOR_RGB12U | OMAP_DSS_COLOR_RGB16 |
102         OMAP_DSS_COLOR_RGB24U | OMAP_DSS_COLOR_RGB24P,
103
104         /* OMAP_DSS_VIDEO1 */
105         OMAP_DSS_COLOR_RGB16 | OMAP_DSS_COLOR_RGB24U |
106         OMAP_DSS_COLOR_RGB24P | OMAP_DSS_COLOR_YUV2 |
107         OMAP_DSS_COLOR_UYVY,
108
109         /* OMAP_DSS_VIDEO2 */
110         OMAP_DSS_COLOR_RGB16 | OMAP_DSS_COLOR_RGB24U |
111         OMAP_DSS_COLOR_RGB24P | OMAP_DSS_COLOR_YUV2 |
112         OMAP_DSS_COLOR_UYVY,
113 };
114
115 static const enum omap_color_mode omap3_dss_supported_color_modes[] = {
116         /* OMAP_DSS_GFX */
117         OMAP_DSS_COLOR_CLUT1 | OMAP_DSS_COLOR_CLUT2 |
118         OMAP_DSS_COLOR_CLUT4 | OMAP_DSS_COLOR_CLUT8 |
119         OMAP_DSS_COLOR_RGB12U | OMAP_DSS_COLOR_ARGB16 |
120         OMAP_DSS_COLOR_RGB16 | OMAP_DSS_COLOR_RGB24U |
121         OMAP_DSS_COLOR_RGB24P | OMAP_DSS_COLOR_ARGB32 |
122         OMAP_DSS_COLOR_RGBA32 | OMAP_DSS_COLOR_RGBX32,
123
124         /* OMAP_DSS_VIDEO1 */
125         OMAP_DSS_COLOR_RGB24U | OMAP_DSS_COLOR_RGB24P |
126         OMAP_DSS_COLOR_RGB12U | OMAP_DSS_COLOR_RGB16 |
127         OMAP_DSS_COLOR_YUV2 | OMAP_DSS_COLOR_UYVY,
128
129         /* OMAP_DSS_VIDEO2 */
130         OMAP_DSS_COLOR_RGB12U | OMAP_DSS_COLOR_ARGB16 |
131         OMAP_DSS_COLOR_RGB16 | OMAP_DSS_COLOR_RGB24U |
132         OMAP_DSS_COLOR_RGB24P | OMAP_DSS_COLOR_YUV2 |
133         OMAP_DSS_COLOR_UYVY | OMAP_DSS_COLOR_ARGB32 |
134         OMAP_DSS_COLOR_RGBA32 | OMAP_DSS_COLOR_RGBX32,
135 };
136
137 /* OMAP2 DSS Features */
138 static struct omap_dss_features omap2_dss_features = {
139         .reg_fields = omap2_dss_reg_fields,
140         .num_reg_fields = ARRAY_SIZE(omap2_dss_reg_fields),
141
142         .has_feature    =
143                 FEAT_LCDENABLEPOL | FEAT_LCDENABLESIGNAL |
144                 FEAT_PCKFREEENABLE | FEAT_FUNCGATED,
145
146         .num_mgrs = 2,
147         .num_ovls = 3,
148         .supported_displays = omap2_dss_supported_displays,
149         .supported_color_modes = omap2_dss_supported_color_modes,
150 };
151
152 /* OMAP3 DSS Features */
153 static struct omap_dss_features omap3430_dss_features = {
154         .reg_fields = omap3_dss_reg_fields,
155         .num_reg_fields = ARRAY_SIZE(omap3_dss_reg_fields),
156
157         .has_feature    =
158                 FEAT_GLOBAL_ALPHA | FEAT_LCDENABLEPOL |
159                 FEAT_LCDENABLESIGNAL | FEAT_PCKFREEENABLE |
160                 FEAT_FUNCGATED,
161
162         .num_mgrs = 2,
163         .num_ovls = 3,
164         .supported_displays = omap3_dss_supported_displays,
165         .supported_color_modes = omap3_dss_supported_color_modes,
166 };
167
168 static struct omap_dss_features omap3630_dss_features = {
169         .reg_fields = omap3_dss_reg_fields,
170         .num_reg_fields = ARRAY_SIZE(omap3_dss_reg_fields),
171
172         .has_feature    =
173                 FEAT_GLOBAL_ALPHA | FEAT_LCDENABLEPOL |
174                 FEAT_LCDENABLESIGNAL | FEAT_PCKFREEENABLE |
175                 FEAT_PRE_MULT_ALPHA | FEAT_FUNCGATED,
176
177         .num_mgrs = 2,
178         .num_ovls = 3,
179         .supported_displays = omap3_dss_supported_displays,
180         .supported_color_modes = omap3_dss_supported_color_modes,
181 };
182
183 /* OMAP4 DSS Features */
184 static struct omap_dss_features omap4_dss_features = {
185         .reg_fields = omap3_dss_reg_fields,
186         .num_reg_fields = ARRAY_SIZE(omap3_dss_reg_fields),
187
188         .has_feature    =
189                 FEAT_GLOBAL_ALPHA | FEAT_PRE_MULT_ALPHA |
190                 FEAT_MGR_LCD2,
191
192         .num_mgrs = 3,
193         .num_ovls = 3,
194         .supported_displays = omap4_dss_supported_displays,
195         .supported_color_modes = omap3_dss_supported_color_modes,
196 };
197
198 /* Functions returning values related to a DSS feature */
199 int dss_feat_get_num_mgrs(void)
200 {
201         return omap_current_dss_features->num_mgrs;
202 }
203
204 int dss_feat_get_num_ovls(void)
205 {
206         return omap_current_dss_features->num_ovls;
207 }
208
209 enum omap_display_type dss_feat_get_supported_displays(enum omap_channel channel)
210 {
211         return omap_current_dss_features->supported_displays[channel];
212 }
213
214 enum omap_color_mode dss_feat_get_supported_color_modes(enum omap_plane plane)
215 {
216         return omap_current_dss_features->supported_color_modes[plane];
217 }
218
219 bool dss_feat_color_mode_supported(enum omap_plane plane,
220                 enum omap_color_mode color_mode)
221 {
222         return omap_current_dss_features->supported_color_modes[plane] &
223                         color_mode;
224 }
225
226 /* DSS has_feature check */
227 bool dss_has_feature(enum dss_feat_id id)
228 {
229         return omap_current_dss_features->has_feature & id;
230 }
231
232 void dss_feat_get_reg_field(enum dss_feat_reg_field id, u8 *start, u8 *end)
233 {
234         if (id >= omap_current_dss_features->num_reg_fields)
235                 BUG();
236
237         *start = omap_current_dss_features->reg_fields[id].start;
238         *end = omap_current_dss_features->reg_fields[id].end;
239 }
240
241 void dss_features_init(void)
242 {
243         if (cpu_is_omap24xx())
244                 omap_current_dss_features = &omap2_dss_features;
245         else if (cpu_is_omap3630())
246                 omap_current_dss_features = &omap3630_dss_features;
247         else if (cpu_is_omap34xx())
248                 omap_current_dss_features = &omap3430_dss_features;
249         else
250                 omap_current_dss_features = &omap4_dss_features;
251 }