gma500: strip unneeded version headers
[pandora-kernel.git] / drivers / staging / gma500 / mdfld_dsi_dbi.h
1 /*
2  * Copyright © 2010 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  *
23  * Authors:
24  * jim liu <jim.liu@intel.com>
25  * Jackie Li<yaodong.li@intel.com>
26  */
27
28 #ifndef __MDFLD_DSI_DBI_H__
29 #define __MDFLD_DSI_DBI_H__
30
31 #include <linux/backlight.h>
32 #include <drm/drmP.h>
33 #include <drm/drm.h>
34 #include <drm/drm_crtc.h>
35 #include <drm/drm_edid.h>
36
37 #include "psb_drv.h"
38 #include "psb_intel_drv.h"
39 #include "psb_intel_reg.h"
40 #include "power.h"
41
42 #include "mdfld_dsi_output.h"
43 #include "mdfld_output.h"
44
45 #define DRM_MODE_ENCODER_MIPI  5
46
47
48 /*
49  * DBI encoder which inherits from mdfld_dsi_encoder
50  */
51 struct mdfld_dsi_dbi_output {
52         struct mdfld_dsi_encoder base;
53         struct drm_display_mode *panel_fixed_mode;
54         u8 last_cmd;
55         u8 lane_count;
56         u8 channel_num;
57         struct drm_device *dev;
58
59         /* Backlight operations */
60
61         /* DSR timer */
62         spinlock_t dsr_timer_lock;
63         struct timer_list dsr_timer;
64         void(*dsi_timer_func)(unsigned long data);
65         u32 dsr_idle_count;
66         bool dsr_fb_update_done;
67
68         /* Mode setting flags */
69         u32 mode_flags;
70
71         /* Panel status */
72         bool dbi_panel_on;
73         bool first_boot;
74         struct panel_funcs *p_funcs;
75 };
76
77 #define MDFLD_DSI_DBI_OUTPUT(dsi_encoder) \
78         container_of(dsi_encoder, struct mdfld_dsi_dbi_output, base)
79
80 struct mdfld_dbi_dsr_info {
81         int dbi_output_num;
82         struct mdfld_dsi_dbi_output *dbi_outputs[2];
83
84         spinlock_t dsr_timer_lock;
85         struct timer_list dsr_timer;
86         u32 dsr_idle_count;
87 };
88
89 #define DBI_CB_TIMEOUT_COUNT    0xffff
90
91 /* DCS commands */
92 #define enter_sleep_mode        0x10
93 #define exit_sleep_mode         0x11
94 #define set_display_off         0x28
95 #define set_dispaly_on          0x29
96 #define set_column_address      0x2a
97 #define set_page_addr           0x2b
98 #define write_mem_start         0x2c
99
100 /* Offsets */
101 #define CMD_MEM_ADDR_OFFSET     0
102
103 #define CMD_DATA_SRC_SYSTEM_MEM 0
104 #define CMD_DATA_SRC_PIPE       1
105
106 static inline int mdfld_dsi_dbi_fifo_ready(struct mdfld_dsi_dbi_output *dbi_output)
107 {
108         struct drm_device *dev = dbi_output->dev;
109         u32 retry = DBI_CB_TIMEOUT_COUNT;
110         int reg_offset = (dbi_output->channel_num == 1) ? MIPIC_REG_OFFSET : 0;
111         int ret = 0;
112
113         /* Query the dbi fifo status*/
114         while (retry--) {
115                 if (REG_READ(MIPIA_GEN_FIFO_STAT_REG + reg_offset) & (1 << 27))
116                         break;
117         }
118
119         if (!retry) {
120                 DRM_ERROR("Timeout waiting for DBI FIFO empty\n");
121                 ret = -EAGAIN;
122         }
123         return ret;
124 }
125
126 static inline int mdfld_dsi_dbi_cmd_sent(struct mdfld_dsi_dbi_output *dbi_output)
127 {
128         struct drm_device *dev = dbi_output->dev;
129         u32 retry = DBI_CB_TIMEOUT_COUNT;
130         int reg_offset = (dbi_output->channel_num == 1) ? MIPIC_REG_OFFSET : 0;
131         int ret = 0;
132
133         /* Query the command execution status */
134         while (retry--)
135                 if (!(REG_READ(MIPIA_CMD_ADD_REG + reg_offset) & (1 << 10)))
136                         break;
137
138         if (!retry) {
139                 DRM_ERROR("Timeout waiting for DBI command status\n");
140                 ret = -EAGAIN;
141         }
142
143         return ret;
144 }
145
146 static inline int mdfld_dsi_dbi_cb_ready(struct mdfld_dsi_dbi_output *dbi_output)
147 {
148         int ret = 0;
149
150         /* Query the command execution status*/
151         ret = mdfld_dsi_dbi_cmd_sent(dbi_output);
152         if (ret) {
153                 DRM_ERROR("Peripheral is busy\n");
154                 ret = -EAGAIN;
155         }
156         /* Query the dbi fifo status*/
157         ret = mdfld_dsi_dbi_fifo_ready(dbi_output);
158         if (ret) {
159                 DRM_ERROR("DBI FIFO is not empty\n");
160                 ret = -EAGAIN;
161         }
162         return ret;
163 }
164
165 extern void mdfld_dsi_dbi_output_init(struct drm_device *dev,
166                         struct psb_intel_mode_device *mode_dev, int pipe);
167 extern void mdfld_dsi_dbi_exit_dsr(struct drm_device *dev, u32 update_src,
168                         void *p_surfaceAddr, bool check_hw_on_only);
169 extern void mdfld_dsi_dbi_enter_dsr(struct mdfld_dsi_dbi_output *dbi_output,
170                         int pipe);
171 extern int mdfld_dbi_dsr_init(struct drm_device *dev);
172 extern void mdfld_dbi_dsr_exit(struct drm_device *dev);
173 extern void mdfld_dbi_dsr_timer_start(struct mdfld_dbi_dsr_info *dsr_info);
174 extern struct mdfld_dsi_encoder *mdfld_dsi_dbi_init(struct drm_device *dev,
175                         struct mdfld_dsi_connector *dsi_connector,
176                         struct panel_funcs *p_funcs);
177 extern int mdfld_dsi_dbi_send_dcs(struct mdfld_dsi_dbi_output *dbi_output,
178                         u8 dcs, u8 *param, u32 num, u8 data_src);
179 extern int mdfld_dsi_dbi_update_area(struct mdfld_dsi_dbi_output *dbi_output,
180                         u16 x1, u16 y1, u16 x2, u16 y2);
181 extern void mdfld_dbi_dsr_timer_start(struct mdfld_dbi_dsr_info *dsr_info);
182 extern int mdfld_dsi_dbi_update_power(struct mdfld_dsi_dbi_output *dbi_output,
183                         int mode);
184 extern void mdfld_dsi_controller_dbi_init(struct mdfld_dsi_config *dsi_config,
185                         int pipe);
186
187 #endif /*__MDFLD_DSI_DBI_H__*/