blob: 2ed059627f19ad19e67a93ff65986fc0f3188f74 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Copyright (c) 2009-2011, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13
14#ifndef MIPI_DSI_H
15#define MIPI_DSI_H
16
17#include <mach/scm-io.h>
18#include <linux/list.h>
19
20#ifdef BIT
21#undef BIT
22#endif
23
24#define BIT(x) (1<<(x))
25
26#define MMSS_CC_BASE_PHY 0x04000000 /* mmss clcok control */
27#define MMSS_SFPB_BASE_PHY 0x05700000 /* mmss SFPB CFG */
28#define MMSS_SERDES_BASE_PHY 0x04f01000 /* mmss (De)Serializer CFG */
29
30#define MIPI_DSI_BASE mipi_dsi_base
31
32#define MIPI_OUTP(addr, data) writel((data), (addr))
33#define MIPI_INP(addr) readl(addr)
34
35#ifdef CONFIG_MSM_SECURE_IO
36#define MIPI_OUTP_SECURE(addr, data) secure_writel((data), (addr))
37#define MIPI_INP_SECURE(addr) secure_readl(addr)
38#else
39#define MIPI_OUTP_SECURE(addr, data) writel((data), (addr))
40#define MIPI_INP_SECURE(addr) readl(addr)
41#endif
42
43#define MIPI_DSI_PRIM 1
44#define MIPI_DSI_SECD 2
45
46#define MIPI_DSI_PANEL_VGA 0
47#define MIPI_DSI_PANEL_WVGA 1
48#define MIPI_DSI_PANEL_WVGA_PT 2
49#define MIPI_DSI_PANEL_FWVGA_PT 3
50#define DSI_PANEL_MAX 3
51
52enum { /* mipi dsi panel */
53 DSI_VIDEO_MODE,
54 DSI_CMD_MODE,
55};
56
57enum {
58 ST_DSI_CLK_OFF,
59 ST_DSI_SUSPEND,
60 ST_DSI_RESUME,
61 ST_DSI_PLAYING,
62 ST_DSI_NUM
63};
64
65enum {
66 EV_DSI_UPDATE,
67 EV_DSI_DONE,
68 EV_DSI_TOUT,
69 EV_DSI_NUM
70};
71
72enum {
73 LANDSCAPE = 1,
74 PORTRAIT = 2,
75};
76
77#define DSI_NON_BURST_SYNCH_PULSE 0
78#define DSI_NON_BURST_SYNCH_EVENT 1
79#define DSI_BURST_MODE 2
80
81
82#define DSI_RGB_SWAP_RGB 0
83#define DSI_RGB_SWAP_RBG 1
84#define DSI_RGB_SWAP_BGR 2
85#define DSI_RGB_SWAP_BRG 3
86#define DSI_RGB_SWAP_GRB 4
87#define DSI_RGB_SWAP_GBR 5
88
89#define DSI_VIDEO_DST_FORMAT_RGB565 0
90#define DSI_VIDEO_DST_FORMAT_RGB666 1
91#define DSI_VIDEO_DST_FORMAT_RGB666_LOOSE 2
92#define DSI_VIDEO_DST_FORMAT_RGB888 3
93
94#define DSI_CMD_DST_FORMAT_RGB111 0
95#define DSI_CMD_DST_FORMAT_RGB332 3
96#define DSI_CMD_DST_FORMAT_RGB444 4
97#define DSI_CMD_DST_FORMAT_RGB565 6
98#define DSI_CMD_DST_FORMAT_RGB666 7
99#define DSI_CMD_DST_FORMAT_RGB888 8
100
101#define DSI_INTR_ERROR_MASK BIT(25)
102#define DSI_INTR_ERROR BIT(24)
103#define DSI_INTR_VIDEO_DONE_MASK BIT(17)
104#define DSI_INTR_VIDEO_DONE BIT(16)
105#define DSI_INTR_CMD_MDP_DONE_MASK BIT(9)
106#define DSI_INTR_CMD_MDP_DONE BIT(8)
107#define DSI_INTR_CMD_DMA_DONE_MASK BIT(1)
108#define DSI_INTR_CMD_DMA_DONE BIT(0)
109
110#define DSI_CMD_TRIGGER_NONE 0x0 /* mdp trigger */
111#define DSI_CMD_TRIGGER_TE 0x02
112#define DSI_CMD_TRIGGER_SW 0x04
113#define DSI_CMD_TRIGGER_SW_SEOF 0x05 /* cmd dma only */
114#define DSI_CMD_TRIGGER_SW_TE 0x06
115
116extern struct device dsi_dev;
117extern int mipi_dsi_clk_on;
118extern u32 dsi_irq;
119
120extern void __iomem *periph_base;
121extern char *mmss_cc_base; /* mutimedia sub system clock control */
122extern char *mmss_sfpb_base; /* mutimedia sub system sfpb */
123
124struct dsiphy_pll_divider_config {
125 u32 clk_rate;
126 u32 fb_divider;
127 u32 ref_divider_ratio;
128 u32 bit_clk_divider; /* oCLK1 */
129 u32 byte_clk_divider; /* oCLK2 */
130 u32 dsi_clk_divider; /* oCLK3 */
131};
132
133extern struct dsiphy_pll_divider_config pll_divider_config;
134
135struct dsi_clk_mnd_table {
136 uint8 lanes;
137 uint8 bpp;
138 uint8 dsiclk_div;
139 uint8 dsiclk_m;
140 uint8 dsiclk_n;
141 uint8 dsiclk_d;
142 uint8 pclk_m;
143 uint8 pclk_n;
144 uint8 pclk_d;
145};
146
147static const struct dsi_clk_mnd_table mnd_table[] = {
148 { 1, 2, 8, 1, 1, 0, 1, 2, 1},
149 { 1, 3, 8, 1, 1, 0, 1, 3, 2},
150 { 2, 2, 4, 1, 1, 0, 1, 2, 1},
151 { 2, 3, 4, 1, 1, 0, 1, 3, 2},
152 { 3, 2, 1, 3, 8, 4, 3, 16, 8},
153 { 3, 3, 1, 3, 8, 4, 1, 8, 4},
154 { 4, 2, 2, 1, 1, 0, 1, 2, 1},
155 { 4, 3, 2, 1, 1, 0, 1, 3, 2},
156};
157
158struct dsi_clk_desc {
159 uint32 src;
160 uint32 m;
161 uint32 n;
162 uint32 d;
163 uint32 mnd_mode;
164 uint32 pre_div_func;
165};
166
167#define DSI_HOST_HDR_SIZE 4
168#define DSI_HDR_LAST BIT(31)
169#define DSI_HDR_LONG_PKT BIT(30)
170#define DSI_HDR_BTA BIT(29)
171#define DSI_HDR_VC(vc) (((vc) & 0x03) << 22)
172#define DSI_HDR_DTYPE(dtype) (((dtype) & 0x03f) << 16)
173#define DSI_HDR_DATA2(data) (((data) & 0x0ff) << 8)
174#define DSI_HDR_DATA1(data) ((data) & 0x0ff)
175#define DSI_HDR_WC(wc) ((wc) & 0x0ffff)
176
177#define DSI_BUF_SIZE 1024
178#define MIPI_DSI_MRPS 0x04 /* Maximum Return Packet Size */
179
180#define MIPI_DSI_LEN 8 /* 4 x 4 - 6 - 2, bytes dcs header+crc-align */
181
182struct dsi_buf {
183 uint32 *hdr; /* dsi host header */
184 char *start; /* buffer start addr */
185 char *end; /* buffer end addr */
186 int size; /* size of buffer */
187 char *data; /* buffer */
188 int len; /* data length */
189 dma_addr_t dmap; /* mapped dma addr */
190};
191
192/* dcs read/write */
193#define DTYPE_DCS_WRITE 0x05 /* short write, 0 parameter */
194#define DTYPE_DCS_WRITE1 0x15 /* short write, 1 parameter */
195#define DTYPE_DCS_READ 0x06 /* read */
196#define DTYPE_DCS_LWRITE 0x39 /* long write */
197
198/* generic read/write */
199#define DTYPE_GEN_WRITE 0x03 /* short write, 0 parameter */
200#define DTYPE_GEN_WRITE1 0x13 /* short write, 1 parameter */
201#define DTYPE_GEN_WRITE2 0x23 /* short write, 2 parameter */
202#define DTYPE_GEN_LWRITE 0x29 /* long write */
203#define DTYPE_GEN_READ 0x04 /* long read, 0 parameter */
204#define DTYPE_GEN_READ1 0x14 /* long read, 1 parameter */
205#define DTYPE_GEN_READ2 0x24 /* long read, 2 parameter */
206
207#define DTYPE_TEAR_ON 0x35 /* set tear on */
208#define DTYPE_MAX_PKTSIZE 0x37 /* set max packet size */
209#define DTYPE_NULL_PKT 0x09 /* null packet, no data */
210#define DTYPE_BLANK_PKT 0x19 /* blankiing packet, no data */
211
212#define DTYPE_CM_ON 0x02 /* color mode off */
213#define DTYPE_CM_OFF 0x12 /* color mode on */
214#define DTYPE_PERIPHERAL_OFF 0x22
215#define DTYPE_PERIPHERAL_ON 0x32
216
217
218struct dsi_cmd_desc {
219 int dtype;
220 int last;
221 int vc;
222 int ack; /* ask ACK from peripheral */
223 int wait;
224 int dlen;
225 char *payload;
226};
227
228
229typedef void (*kickoff_act)(void *);
230
231struct dsi_kickoff_action {
232 struct list_head act_entry;
233 kickoff_act action;
234 void *data;
235};
236
237
238char *mipi_dsi_buf_reserve_hdr(struct dsi_buf *dp, int hlen);
239char *mipi_dsi_buf_init(struct dsi_buf *dp);
240void mipi_dsi_init(void);
241int mipi_dsi_buf_alloc(struct dsi_buf *, int size);
242int mipi_dsi_cmd_dma_add(struct dsi_buf *dp, struct dsi_cmd_desc *cm);
243int mipi_dsi_cmds_tx(struct msm_fb_data_type *mfd,
244 struct dsi_buf *dp, struct dsi_cmd_desc *cmds, int cnt);
245
246int mipi_dsi_cmd_dma_tx(struct dsi_buf *dp);
247int mipi_dsi_cmd_reg_tx(uint32 data);
248int mipi_dsi_cmds_rx(struct msm_fb_data_type *mfd,
249 struct dsi_buf *tp, struct dsi_buf *rp,
250 struct dsi_cmd_desc *cmds, int len);
251int mipi_dsi_cmd_dma_rx(struct dsi_buf *tp, int rlen);
252void mipi_dsi_host_init(struct mipi_panel_info *pinfo);
253void mipi_dsi_op_mode_config(int mode);
254void mipi_dsi_cmd_mode_ctrl(int enable);
255void mdp4_dsi_cmd_trigger(void);
256void mipi_dsi_cmd_mdp_sw_trigger(void);
257void mipi_dsi_cmd_bta_sw_trigger(void);
258void mipi_dsi_ack_err_status(void);
259void mipi_dsi_set_tear_on(struct msm_fb_data_type *mfd);
260void mipi_dsi_set_tear_off(struct msm_fb_data_type *mfd);
261void mipi_dsi_clk_enable(void);
262void mipi_dsi_clk_disable(void);
263void mipi_dsi_pre_kickoff_action(void);
264void mipi_dsi_post_kickoff_action(void);
265void mipi_dsi_pre_kickoff_add(struct dsi_kickoff_action *act);
266void mipi_dsi_post_kickoff_add(struct dsi_kickoff_action *act);
267void mipi_dsi_pre_kickoff_del(struct dsi_kickoff_action *act);
268void mipi_dsi_post_kickoff_del(struct dsi_kickoff_action *act);
269
270irqreturn_t mipi_dsi_isr(int irq, void *ptr);
271
272void mipi_set_tx_power_mode(int mode);
273void mipi_dsi_phy_ctrl(int on);
274void mipi_dsi_phy_init(int panel_ndx, struct msm_panel_info const *panel_info,
275 int target_type);
276int mipi_dsi_clk_div_config(uint8 bpp, uint8 lanes,
277 uint32 *expected_dsi_pclk);
278void mipi_dsi_clk_init(struct device *dev);
279void mipi_dsi_clk_deinit(struct device *dev);
280
281#ifdef CONFIG_FB_MSM_MDP303
282void update_lane_config(struct msm_panel_info *pinfo);
283#endif
284
285#endif /* MIPI_DSI_H */