video: tegra: dc: remove emc clock worker
[linux-2.6.git] / arch / arm / mach-tegra / include / mach / dc.h
1 /*
2  * arch/arm/mach-tegra/include/mach/dc.h
3  *
4  * Copyright (C) 2010 Google, Inc.
5  *
6  * Author:
7  *      Erik Gilling <konkers@google.com>
8  *
9  * Copyright (C) 2010-2011 NVIDIA Corporation
10  *
11  * This software is licensed under the terms of the GNU General Public
12  * License version 2, as published by the Free Software Foundation, and
13  * may be copied, distributed, and modified under those terms.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  */
21
22 #ifndef __MACH_TEGRA_DC_H
23 #define __MACH_TEGRA_DC_H
24
25 #include <linux/pm.h>
26 #include <linux/types.h>
27
28 #define TEGRA_MAX_DC            2
29 #define DC_N_WINDOWS            3
30
31
32 /* DSI pixel data format */
33 enum {
34         TEGRA_DSI_PIXEL_FORMAT_16BIT_P,
35         TEGRA_DSI_PIXEL_FORMAT_18BIT_P,
36         TEGRA_DSI_PIXEL_FORMAT_18BIT_NP,
37         TEGRA_DSI_PIXEL_FORMAT_24BIT_P,
38 };
39
40 /* DSI virtual channel number */
41 enum {
42         TEGRA_DSI_VIRTUAL_CHANNEL_0,
43         TEGRA_DSI_VIRTUAL_CHANNEL_1,
44         TEGRA_DSI_VIRTUAL_CHANNEL_2,
45         TEGRA_DSI_VIRTUAL_CHANNEL_3,
46 };
47
48 /* DSI transmit method for video data */
49 enum {
50         TEGRA_DSI_VIDEO_TYPE_VIDEO_MODE,
51         TEGRA_DSI_VIDEO_TYPE_COMMAND_MODE,
52 };
53
54 /* DSI HS clock mode */
55 enum {
56         TEGRA_DSI_VIDEO_CLOCK_CONTINUOUS,
57         TEGRA_DSI_VIDEO_CLOCK_TX_ONLY,
58 };
59
60 /* DSI burst mode setting in video mode. Each mode is assigned with a
61  * fixed value. The rationale behind this is to avoid change of these
62  * values, since the calculation of dsi clock depends on them. */
63 enum {
64         TEGRA_DSI_VIDEO_NONE_BURST_MODE = 0,
65         TEGRA_DSI_VIDEO_NONE_BURST_MODE_WITH_SYNC_END = 1,
66         TEGRA_DSI_VIDEO_BURST_MODE_LOWEST_SPEED = 2,
67         TEGRA_DSI_VIDEO_BURST_MODE_LOW_SPEED = 3,
68         TEGRA_DSI_VIDEO_BURST_MODE_MEDIUM_SPEED = 4,
69         TEGRA_DSI_VIDEO_BURST_MODE_FAST_SPEED = 5,
70         TEGRA_DSI_VIDEO_BURST_MODE_FASTEST_SPEED = 6,
71 };
72
73 enum {
74         TEGRA_DSI_PACKET_CMD,
75         TEGRA_DSI_DELAY_MS,
76 };
77
78 struct tegra_dsi_cmd {
79         u8      cmd_type;
80         u8      data_id;
81         union {
82                 u16 data_len;
83                 u16 delay_ms;
84                 struct{
85                         u8 data0;
86                         u8 data1;
87                 }sp;
88         }sp_len_dly;
89         u8      *pdata;
90 };
91
92 #define DSI_CMD_SHORT(di, p0, p1)       { \
93                                         .cmd_type = TEGRA_DSI_PACKET_CMD, \
94                                         .data_id = di, \
95                                         .sp_len_dly.sp.data0 = p0, \
96                                         .sp_len_dly.sp.data1 = p1, \
97                                         }
98 #define DSI_DLY_MS(ms)  { \
99                         .cmd_type = TEGRA_DSI_DELAY_MS, \
100                         .sp_len_dly.delay_ms = ms, \
101                         }
102
103 #define DSI_CMD_LONG(di, ptr)   { \
104                                 .cmd_type = TEGRA_DSI_PACKET_CMD, \
105                                 .data_id = di, \
106                                 .sp_len_dly.data_len = ARRAY_SIZE(ptr), \
107                                 .pdata = ptr, \
108                                 }
109
110 struct dsi_phy_timing_ns {
111         u16             t_hsdexit_ns;
112         u16             t_hstrail_ns;
113         u16             t_hsprepr_ns;
114         u16             t_datzero_ns;
115
116         u16             t_clktrail_ns;
117         u16             t_clkpost_ns;
118         u16             t_clkzero_ns;
119         u16             t_tlpx_ns;
120 };
121
122 struct tegra_dsi_out {
123         u8              n_data_lanes;                   /* required */
124         u8              pixel_format;                   /* required */
125         u8              refresh_rate;                   /* required */
126         u8              panel_reset;                    /* required */
127         u8              virtual_channel;                /* required */
128         u8              dsi_instance;
129
130         bool            panel_has_frame_buffer; /* required*/
131
132         struct tegra_dsi_cmd*   dsi_init_cmd;           /* required */
133         u16             n_init_cmd;                     /* required */
134
135         struct tegra_dsi_cmd*   dsi_suspend_cmd;        /* required */
136         u16             n_suspend_cmd;                  /* required */
137
138         u8              video_data_type;                /* required */
139         u8              video_clock_mode;
140         u8              video_burst_mode;
141
142         u16             panel_buffer_size_byte;
143         u16             panel_reset_timeout_msec;
144
145         bool            hs_cmd_mode_supported;
146         bool            hs_cmd_mode_on_blank_supported;
147         bool            enable_hs_clock_on_lp_cmd_mode;
148         bool            no_pkt_seq_eot; /* 1st generation panel may not
149                                          * support eot. Don't set it for
150                                          * most panels. */
151
152         u32             max_panel_freq_khz;
153         u32             lp_cmd_mode_freq_khz;
154         u32             hs_clk_in_lp_cmd_mode_freq_khz;
155         u32             burst_mode_freq_khz;
156
157         struct dsi_phy_timing_ns phy_timing;
158 };
159
160 enum {
161         TEGRA_DC_STEREO_MODE_2D,
162         TEGRA_DC_STEREO_MODE_3D
163 };
164
165 enum {
166         TEGRA_DC_STEREO_LANDSCAPE,
167         TEGRA_DC_STEREO_PORTRAIT
168 };
169
170 struct tegra_stereo_out {
171         int  mode_2d_3d;
172         int  orientation;
173
174         void (*set_mode)(int mode);
175         void (*set_orientation)(int orientation);
176 };
177
178 struct tegra_dc_mode {
179         int     pclk;
180         int     h_ref_to_sync;
181         int     v_ref_to_sync;
182         int     h_sync_width;
183         int     v_sync_width;
184         int     h_back_porch;
185         int     v_back_porch;
186         int     h_active;
187         int     v_active;
188         int     h_front_porch;
189         int     v_front_porch;
190         int     stereo_mode;
191         u32     flags;
192 };
193
194 #define TEGRA_DC_MODE_FLAG_NEG_V_SYNC   (1 << 0)
195 #define TEGRA_DC_MODE_FLAG_NEG_H_SYNC   (1 << 1)
196
197 enum {
198         TEGRA_DC_OUT_RGB,
199         TEGRA_DC_OUT_HDMI,
200         TEGRA_DC_OUT_DSI,
201 };
202
203 struct tegra_dc_out_pin {
204         int     name;
205         int     pol;
206 };
207
208 enum {
209         TEGRA_DC_OUT_PIN_DATA_ENABLE,
210         TEGRA_DC_OUT_PIN_H_SYNC,
211         TEGRA_DC_OUT_PIN_V_SYNC,
212         TEGRA_DC_OUT_PIN_PIXEL_CLOCK,
213 };
214
215 enum {
216         TEGRA_DC_OUT_PIN_POL_LOW,
217         TEGRA_DC_OUT_PIN_POL_HIGH,
218 };
219
220 enum {
221         TEGRA_DC_DISABLE_DITHER = 1,
222         TEGRA_DC_ORDERED_DITHER,
223         TEGRA_DC_ERRDIFF_DITHER,
224 };
225
226 typedef u8 tegra_dc_bl_output[256];
227 typedef u8 *p_tegra_dc_bl_output;
228
229 struct tegra_dc_sd_blp {
230         u16 time_constant;
231         u8 step;
232 };
233
234 struct tegra_dc_sd_fc {
235         u8 time_limit;
236         u8 threshold;
237 };
238
239 struct tegra_dc_sd_rgb {
240         u8 r;
241         u8 g;
242         u8 b;
243 };
244
245 struct tegra_dc_sd_settings {
246         unsigned enable;
247         bool use_auto_pwm;
248         u8 hw_update_delay;
249         unsigned bin_width;
250         u8 aggressiveness;
251
252         bool use_vid_luma;
253         struct tegra_dc_sd_rgb coeff;
254
255         struct tegra_dc_sd_fc fc;
256         struct tegra_dc_sd_blp blp;
257         u8 bltf[4][4][4];
258         struct tegra_dc_sd_rgb lut[4][9];
259
260         atomic_t *sd_brightness;
261         struct platform_device *bl_device;
262 };
263
264 enum {
265         TEGRA_PIN_OUT_CONFIG_SEL_LHP0_LD21,
266         TEGRA_PIN_OUT_CONFIG_SEL_LHP1_LD18,
267         TEGRA_PIN_OUT_CONFIG_SEL_LHP2_LD19,
268         TEGRA_PIN_OUT_CONFIG_SEL_LVP0_LVP0_Out,
269         TEGRA_PIN_OUT_CONFIG_SEL_LVP1_LD20,
270
271         TEGRA_PIN_OUT_CONFIG_SEL_LM1_M1,
272         TEGRA_PIN_OUT_CONFIG_SEL_LM1_LD21,
273         TEGRA_PIN_OUT_CONFIG_SEL_LM1_PM1,
274
275         TEGRA_PIN_OUT_CONFIG_SEL_LDI_LD22,
276         TEGRA_PIN_OUT_CONFIG_SEL_LPP_LD23,
277         TEGRA_PIN_OUT_CONFIG_SEL_LDC_SDC,
278         TEGRA_PIN_OUT_CONFIG_SEL_LSPI_DE,
279 };
280
281 struct tegra_dc_out {
282         int                             type;
283         unsigned                        flags;
284
285         /* size in mm */
286         unsigned                        h_size;
287         unsigned                        v_size;
288
289         int                             dcc_bus;
290         int                             hotplug_gpio;
291         const char                      *parent_clk;
292
293         unsigned                        max_pixclock;
294         unsigned                        order;
295         unsigned                        align;
296         unsigned                        depth;
297         unsigned                        dither;
298
299         struct tegra_dc_mode            *modes;
300         int                             n_modes;
301
302         struct tegra_dsi_out            *dsi;
303         struct tegra_stereo_out         *stereo;
304
305         unsigned                        height; /* mm */
306         unsigned                        width; /* mm */
307
308         struct tegra_dc_out_pin         *out_pins;
309         unsigned                        n_out_pins;
310
311         struct tegra_dc_sd_settings     *sd_settings;
312
313         u8                      *out_sel_configs;
314         unsigned                n_out_sel_configs;
315
316         int     (*enable)(void);
317         int     (*postpoweron)(void);
318         int     (*disable)(void);
319
320         int     (*hotplug_init)(void);
321         int     (*postsuspend)(void);
322 };
323
324 /* bits for tegra_dc_out.flags */
325 #define TEGRA_DC_OUT_HOTPLUG_HIGH               (0 << 1)
326 #define TEGRA_DC_OUT_HOTPLUG_LOW                (1 << 1)
327 #define TEGRA_DC_OUT_HOTPLUG_MASK               (1 << 1)
328 #define TEGRA_DC_OUT_NVHDCP_POLICY_ALWAYS_ON    (0 << 2)
329 #define TEGRA_DC_OUT_NVHDCP_POLICY_ON_DEMAND    (1 << 2)
330 #define TEGRA_DC_OUT_NVHDCP_POLICY_MASK         (1 << 2)
331
332 #define TEGRA_DC_ALIGN_MSB              0
333 #define TEGRA_DC_ALIGN_LSB              1
334
335 #define TEGRA_DC_ORDER_RED_BLUE         0
336 #define TEGRA_DC_ORDER_BLUE_RED         1
337
338 struct tegra_dc;
339 struct nvmap_handle_ref;
340
341 struct tegra_dc_win {
342         u8                      idx;
343         u8                      fmt;
344         u32                     flags;
345
346         void                    *virt_addr;
347         dma_addr_t              phys_addr;
348         unsigned                offset;
349         unsigned                offset_u;
350         unsigned                offset_v;
351         unsigned                stride;
352         unsigned                stride_uv;
353         unsigned                x;
354         unsigned                y;
355         unsigned                w;
356         unsigned                h;
357         unsigned                out_x;
358         unsigned                out_y;
359         unsigned                out_w;
360         unsigned                out_h;
361         unsigned                z;
362
363         int                     dirty;
364         int                     underflows;
365         struct tegra_dc         *dc;
366
367         struct nvmap_handle_ref *cur_handle;
368 };
369
370
371 #define TEGRA_WIN_FLAG_ENABLED          (1 << 0)
372 #define TEGRA_WIN_FLAG_BLEND_PREMULT    (1 << 1)
373 #define TEGRA_WIN_FLAG_BLEND_COVERAGE   (1 << 2)
374 #define TEGRA_WIN_FLAG_INVERT_H         (1 << 3)
375 #define TEGRA_WIN_FLAG_INVERT_V         (1 << 4)
376 #define TEGRA_WIN_FLAG_TILED            (1 << 5)
377 #define TEGRA_WIN_FLAG_H_FILTER         (1 << 6)
378 #define TEGRA_WIN_FLAG_V_FILTER         (1 << 7)
379
380 #define TEGRA_WIN_BLEND_FLAGS_MASK \
381         (TEGRA_WIN_FLAG_BLEND_PREMULT | TEGRA_WIN_FLAG_BLEND_COVERAGE)
382
383 /* Note: These are the actual values written to the DC_WIN_COLOR_DEPTH register
384  * and may change in new tegra architectures.
385  */
386 #define TEGRA_WIN_FMT_P1                0
387 #define TEGRA_WIN_FMT_P2                1
388 #define TEGRA_WIN_FMT_P4                2
389 #define TEGRA_WIN_FMT_P8                3
390 #define TEGRA_WIN_FMT_B4G4R4A4          4
391 #define TEGRA_WIN_FMT_B5G5R5A           5
392 #define TEGRA_WIN_FMT_B5G6R5            6
393 #define TEGRA_WIN_FMT_AB5G5R5           7
394 #define TEGRA_WIN_FMT_B8G8R8A8          12
395 #define TEGRA_WIN_FMT_R8G8B8A8          13
396 #define TEGRA_WIN_FMT_B6x2G6x2R6x2A8    14
397 #define TEGRA_WIN_FMT_R6x2G6x2B6x2A8    15
398 #define TEGRA_WIN_FMT_YCbCr422          16
399 #define TEGRA_WIN_FMT_YUV422            17
400 #define TEGRA_WIN_FMT_YCbCr420P         18
401 #define TEGRA_WIN_FMT_YUV420P           19
402 #define TEGRA_WIN_FMT_YCbCr422P         20
403 #define TEGRA_WIN_FMT_YUV422P           21
404 #define TEGRA_WIN_FMT_YCbCr422R         22
405 #define TEGRA_WIN_FMT_YUV422R           23
406 #define TEGRA_WIN_FMT_YCbCr422RA        24
407 #define TEGRA_WIN_FMT_YUV422RA          25
408
409 struct tegra_fb_data {
410         int             win;
411
412         int             xres;
413         int             yres;
414         int             bits_per_pixel; /* -1 means autodetect */
415
416         unsigned long   flags;
417 };
418
419 #define TEGRA_FB_FLIP_ON_PROBE          (1 << 0)
420
421 struct tegra_dc_platform_data {
422         unsigned long           flags;
423         unsigned long           emc_clk_rate;
424         struct tegra_dc_out     *default_out;
425         struct tegra_fb_data    *fb;
426 };
427
428 #define TEGRA_DC_FLAG_ENABLED           (1 << 0)
429
430 struct tegra_dc *tegra_dc_get_dc(unsigned idx);
431 struct tegra_dc_win *tegra_dc_get_window(struct tegra_dc *dc, unsigned win);
432
433 void tegra_dc_enable(struct tegra_dc *dc);
434 void tegra_dc_disable(struct tegra_dc *dc);
435
436 u32 tegra_dc_get_syncpt_id(const struct tegra_dc *dc);
437 u32 tegra_dc_incr_syncpt_max(struct tegra_dc *dc);
438 void tegra_dc_incr_syncpt_min(struct tegra_dc *dc, u32 val);
439
440 /* tegra_dc_update_windows and tegra_dc_sync_windows do not support windows
441  * with differenct dcs in one call
442  */
443 int tegra_dc_update_windows(struct tegra_dc_win *windows[], int n);
444 int tegra_dc_sync_windows(struct tegra_dc_win *windows[], int n);
445
446 int tegra_dc_set_mode(struct tegra_dc *dc, const struct tegra_dc_mode *mode);
447 struct fb_videomode;
448 int tegra_dc_set_fb_mode(struct tegra_dc *dc, const struct fb_videomode *fbmode,
449         bool stereo_mode);
450
451 unsigned tegra_dc_get_out_height(const struct tegra_dc *dc);
452 unsigned tegra_dc_get_out_width(const struct tegra_dc *dc);
453 unsigned tegra_dc_get_out_max_pixclock(const struct tegra_dc *dc);
454
455 /* PM0 and PM1 signal control */
456 #define TEGRA_PWM_PM0 0
457 #define TEGRA_PWM_PM1 1
458
459 struct tegra_dc_pwm_params {
460         int which_pwm;
461         unsigned int period;
462         unsigned int clk_div;
463         unsigned int clk_select;
464         unsigned int duty_cycle;
465 };
466
467 void tegra_dc_config_pwm(struct tegra_dc *dc, struct tegra_dc_pwm_params *cfg);
468
469 #endif