Commit | Line | Data |
---|---|---|
9d200153 SM |
1 | /* Copyright (c) 2009, 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 | * You should have received a copy of the GNU General Public License | |
13 | * along with this program; if not, write to the Free Software | |
14 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | |
15 | * 02110-1301, USA. | |
16 | */ | |
17 | ||
18 | #include <linux/delay.h> | |
19 | #ifdef CONFIG_ARCH_MSM7X30 | |
20 | #include <linux/mfd/pmic8058.h> | |
21 | #endif | |
22 | #include <mach/gpio.h> | |
23 | #include "msm_fb.h" | |
24 | ||
25 | static int lcdc_sharp_panel_off(struct platform_device *pdev); | |
26 | ||
27 | static int spi_cs; | |
28 | static int spi_sclk; | |
29 | static int spi_mosi; | |
30 | static int spi_miso; | |
31 | static unsigned char bit_shift[8] = { (1 << 7), /* MSB */ | |
32 | (1 << 6), | |
33 | (1 << 5), | |
34 | (1 << 4), | |
35 | (1 << 3), | |
36 | (1 << 2), | |
37 | (1 << 1), | |
38 | (1 << 0) /* LSB */ | |
39 | }; | |
40 | ||
41 | struct sharp_state_type { | |
42 | boolean disp_initialized; | |
43 | boolean display_on; | |
44 | boolean disp_powered_up; | |
45 | }; | |
46 | ||
47 | struct sharp_spi_data { | |
48 | u8 addr; | |
49 | u8 data; | |
50 | }; | |
51 | ||
52 | static struct sharp_spi_data init_sequence[] = { | |
53 | { 15, 0x01 }, | |
54 | { 5, 0x01 }, | |
55 | { 7, 0x10 }, | |
56 | { 9, 0x1E }, | |
57 | { 10, 0x04 }, | |
58 | { 17, 0xFF }, | |
59 | { 21, 0x8A }, | |
60 | { 22, 0x00 }, | |
61 | { 23, 0x82 }, | |
62 | { 24, 0x24 }, | |
63 | { 25, 0x22 }, | |
64 | { 26, 0x6D }, | |
65 | { 27, 0xEB }, | |
66 | { 28, 0xB9 }, | |
67 | { 29, 0x3A }, | |
68 | { 49, 0x1A }, | |
69 | { 50, 0x16 }, | |
70 | { 51, 0x05 }, | |
71 | { 55, 0x7F }, | |
72 | { 56, 0x15 }, | |
73 | { 57, 0x7B }, | |
74 | { 60, 0x05 }, | |
75 | { 61, 0x0C }, | |
76 | { 62, 0x80 }, | |
77 | { 63, 0x00 }, | |
78 | { 92, 0x90 }, | |
79 | { 97, 0x01 }, | |
80 | { 98, 0xFF }, | |
81 | { 113, 0x11 }, | |
82 | { 114, 0x02 }, | |
83 | { 115, 0x08 }, | |
84 | { 123, 0xAB }, | |
85 | { 124, 0x04 }, | |
86 | { 6, 0x02 }, | |
87 | { 133, 0x00 }, | |
88 | { 134, 0xFE }, | |
89 | { 135, 0x22 }, | |
90 | { 136, 0x0B }, | |
91 | { 137, 0xFF }, | |
92 | { 138, 0x0F }, | |
93 | { 139, 0x00 }, | |
94 | { 140, 0xFE }, | |
95 | { 141, 0x22 }, | |
96 | { 142, 0x0B }, | |
97 | { 143, 0xFF }, | |
98 | { 144, 0x0F }, | |
99 | { 145, 0x00 }, | |
100 | { 146, 0xFE }, | |
101 | { 147, 0x22 }, | |
102 | { 148, 0x0B }, | |
103 | { 149, 0xFF }, | |
104 | { 150, 0x0F }, | |
105 | { 202, 0x30 }, | |
106 | { 30, 0x01 }, | |
107 | { 4, 0x01 }, | |
108 | { 31, 0x41 }, | |
109 | }; | |
110 | ||
111 | static struct sharp_state_type sharp_state = { 0 }; | |
112 | static struct msm_panel_common_pdata *lcdc_sharp_pdata; | |
113 | ||
114 | static void sharp_spi_write_byte(u8 val) | |
115 | { | |
116 | int i; | |
117 | ||
118 | /* Clock should be Low before entering */ | |
119 | for (i = 0; i < 8; i++) { | |
120 | /* #1: Drive the Data (High or Low) */ | |
121 | if (val & bit_shift[i]) | |
122 | gpio_set_value(spi_mosi, 1); | |
123 | else | |
124 | gpio_set_value(spi_mosi, 0); | |
125 | ||
126 | /* #2: Drive the Clk High and then Low */ | |
127 | gpio_set_value(spi_sclk, 1); | |
128 | gpio_set_value(spi_sclk, 0); | |
129 | } | |
130 | } | |
131 | ||
132 | static void serigo(u8 reg, u8 data) | |
133 | { | |
134 | /* Enable the Chip Select - low */ | |
135 | gpio_set_value(spi_cs, 0); | |
136 | udelay(1); | |
137 | ||
138 | /* Transmit register address first, then data */ | |
139 | sharp_spi_write_byte(reg); | |
140 | ||
141 | /* Idle state of MOSI is Low */ | |
142 | gpio_set_value(spi_mosi, 0); | |
143 | udelay(1); | |
144 | sharp_spi_write_byte(data); | |
145 | ||
146 | gpio_set_value(spi_mosi, 0); | |
147 | gpio_set_value(spi_cs, 1); | |
148 | } | |
149 | ||
150 | static void sharp_spi_init(void) | |
151 | { | |
152 | spi_sclk = *(lcdc_sharp_pdata->gpio_num); | |
153 | spi_cs = *(lcdc_sharp_pdata->gpio_num + 1); | |
154 | spi_mosi = *(lcdc_sharp_pdata->gpio_num + 2); | |
155 | spi_miso = *(lcdc_sharp_pdata->gpio_num + 3); | |
156 | ||
157 | /* Set the output so that we don't disturb the slave device */ | |
158 | gpio_set_value(spi_sclk, 0); | |
159 | gpio_set_value(spi_mosi, 0); | |
160 | ||
161 | /* Set the Chip Select deasserted (active low) */ | |
162 | gpio_set_value(spi_cs, 1); | |
163 | } | |
164 | ||
165 | static void sharp_disp_powerup(void) | |
166 | { | |
167 | if (!sharp_state.disp_powered_up && !sharp_state.display_on) | |
168 | sharp_state.disp_powered_up = TRUE; | |
169 | } | |
170 | ||
171 | static void sharp_disp_on(void) | |
172 | { | |
173 | int i; | |
174 | ||
175 | if (sharp_state.disp_powered_up && !sharp_state.display_on) { | |
176 | for (i = 0; i < ARRAY_SIZE(init_sequence); i++) { | |
177 | serigo(init_sequence[i].addr, | |
178 | init_sequence[i].data); | |
179 | } | |
180 | mdelay(10); | |
181 | serigo(31, 0xC1); | |
182 | mdelay(10); | |
183 | serigo(31, 0xD9); | |
184 | serigo(31, 0xDF); | |
185 | ||
186 | sharp_state.display_on = TRUE; | |
187 | } | |
188 | } | |
189 | ||
190 | static int lcdc_sharp_panel_on(struct platform_device *pdev) | |
191 | { | |
192 | if (!sharp_state.disp_initialized) { | |
193 | lcdc_sharp_pdata->panel_config_gpio(1); | |
194 | sharp_spi_init(); | |
195 | sharp_disp_powerup(); | |
196 | sharp_disp_on(); | |
197 | sharp_state.disp_initialized = TRUE; | |
198 | } | |
199 | return 0; | |
200 | } | |
201 | ||
202 | static int lcdc_sharp_panel_off(struct platform_device *pdev) | |
203 | { | |
204 | if (sharp_state.disp_powered_up && sharp_state.display_on) { | |
205 | serigo(4, 0x00); | |
206 | mdelay(40); | |
207 | serigo(31, 0xC1); | |
208 | mdelay(40); | |
209 | serigo(31, 0x00); | |
210 | mdelay(100); | |
211 | sharp_state.display_on = FALSE; | |
212 | sharp_state.disp_initialized = FALSE; | |
213 | } | |
214 | return 0; | |
215 | } | |
216 | ||
217 | static int __init sharp_probe(struct platform_device *pdev) | |
218 | { | |
219 | if (pdev->id == 0) { | |
220 | lcdc_sharp_pdata = pdev->dev.platform_data; | |
221 | return 0; | |
222 | } | |
223 | msm_fb_add_device(pdev); | |
224 | return 0; | |
225 | } | |
226 | ||
227 | static struct platform_driver this_driver = { | |
228 | .probe = sharp_probe, | |
229 | .driver = { | |
230 | .name = "lcdc_sharp_wvga", | |
231 | }, | |
232 | }; | |
233 | ||
234 | static struct msm_fb_panel_data sharp_panel_data = { | |
235 | .on = lcdc_sharp_panel_on, | |
236 | .off = lcdc_sharp_panel_off, | |
237 | }; | |
238 | ||
239 | static struct platform_device this_device = { | |
240 | .name = "lcdc_sharp_wvga", | |
241 | .id = 1, | |
242 | .dev = { | |
243 | .platform_data = &sharp_panel_data, | |
244 | } | |
245 | }; | |
246 | ||
247 | static int __init lcdc_sharp_panel_init(void) | |
248 | { | |
249 | int ret; | |
250 | struct msm_panel_info *pinfo; | |
251 | ||
252 | #ifdef CONFIG_FB_MSM_MDDI_AUTO_DETECT | |
253 | if (msm_fb_detect_client("lcdc_sharp_wvga_pt")) | |
254 | return 0; | |
255 | #endif | |
256 | ||
257 | ret = platform_driver_register(&this_driver); | |
258 | if (ret) | |
259 | return ret; | |
260 | ||
261 | pinfo = &sharp_panel_data.panel_info; | |
262 | pinfo->xres = 480; | |
263 | pinfo->yres = 800; | |
264 | pinfo->type = LCDC_PANEL; | |
265 | pinfo->pdest = DISPLAY_1; | |
266 | pinfo->wait_cycle = 0; | |
267 | pinfo->bpp = 18; | |
268 | pinfo->fb_num = 2; | |
269 | pinfo->clk_rate = 24500000; | |
270 | pinfo->bl_max = 4; | |
271 | pinfo->bl_min = 1; | |
272 | ||
273 | pinfo->lcdc.h_back_porch = 20; | |
274 | pinfo->lcdc.h_front_porch = 10; | |
275 | pinfo->lcdc.h_pulse_width = 10; | |
276 | pinfo->lcdc.v_back_porch = 2; | |
277 | pinfo->lcdc.v_front_porch = 2; | |
278 | pinfo->lcdc.v_pulse_width = 2; | |
279 | pinfo->lcdc.border_clr = 0; | |
280 | pinfo->lcdc.underflow_clr = 0xff; | |
281 | pinfo->lcdc.hsync_skew = 0; | |
282 | ||
283 | ret = platform_device_register(&this_device); | |
284 | if (ret) | |
285 | platform_driver_unregister(&this_driver); | |
286 | ||
287 | return ret; | |
288 | } | |
289 | ||
290 | module_init(lcdc_sharp_panel_init); |