upload tizen1.0 source
[kernel/linux-2.6.36.git] / arch / arm / mach-s5pv310 / setup-fb.c
1 /* linux/arch/arm/mach-s5pv310/setup-fb.c
2  *
3  * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4  *              http://www.samsung.com/
5  *
6  * Base FIMD controller configuration
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11 */
12
13 #include <linux/clk.h>
14 #include <linux/delay.h>
15 #include <linux/err.h>
16 #include <linux/gpio.h>
17 #include <linux/kernel.h>
18 #include <linux/platform_device.h>
19 #include <linux/types.h>
20 #include <plat/clock.h>
21 #include <plat/gpio-cfg.h>
22 #include <mach/regs-clock.h>
23 #include <mach/regs-gpio.h>
24 #include <linux/io.h>
25 #include <mach/map.h>
26 #include <mach/gpio.h>
27 /* #include <mach/pd.h> */
28
29 struct platform_device; /* don't need the contents */
30
31 void s3cfb_cfg_gpio(struct platform_device *pdev)
32 {
33         int i;
34         u32 reg;
35
36         for (i = 0; i < 8; i++) {
37                 s3c_gpio_cfgpin(S5PV310_GPF0(i), S3C_GPIO_SFN(2));
38                 s3c_gpio_setpull(S5PV310_GPF0(i), S3C_GPIO_PULL_NONE);
39                 s5p_gpio_set_drvstr(S5PV310_GPF0(i), S5P_GPIO_DRVSTR_LV4);
40         }
41
42         for (i = 0; i < 8; i++) {
43                 s3c_gpio_cfgpin(S5PV310_GPF1(i), S3C_GPIO_SFN(2));
44                 s3c_gpio_setpull(S5PV310_GPF1(i), S3C_GPIO_PULL_NONE);
45                 s5p_gpio_set_drvstr(S5PV310_GPF1(i), S5P_GPIO_DRVSTR_LV4);
46         }
47
48         for (i = 0; i < 8; i++) {
49                 s3c_gpio_cfgpin(S5PV310_GPF2(i), S3C_GPIO_SFN(2));
50                 s3c_gpio_setpull(S5PV310_GPF2(i), S3C_GPIO_PULL_NONE);
51                 s5p_gpio_set_drvstr(S5PV310_GPF2(i), S5P_GPIO_DRVSTR_LV4);
52         }
53
54         for (i = 0; i < 4; i++) {
55                 s3c_gpio_cfgpin(S5PV310_GPF3(i), S3C_GPIO_SFN(2));
56                 s3c_gpio_setpull(S5PV310_GPF3(i), S3C_GPIO_PULL_NONE);
57                 s5p_gpio_set_drvstr(S5PV310_GPF3(i), S5P_GPIO_DRVSTR_LV4);
58         }
59
60         /* Set FIMD0 bypass */
61         reg = __raw_readl(S3C_VA_SYS + 0x0210);
62         reg |= (1<<1);
63         __raw_writel(reg, S3C_VA_SYS + 0x0210);
64 }
65
66 int s3cfb_clk_setup(struct platform_device *pdev, struct clk **out_clk)
67 {
68         struct clk *sclk = NULL;
69         struct clk *mout_mpll = NULL;
70         struct clk *lcd_clk = NULL;
71
72         u32 rate = 400000000;
73
74         lcd_clk = clk_get(&pdev->dev, "fimd0");
75         if (IS_ERR(lcd_clk)) {
76                 dev_err(&pdev->dev, "failed to get lcd_clk for fimd\n");
77                 goto err_clk1;
78         }
79
80         sclk = clk_get(&pdev->dev, "sclk_fimd0");
81         if (IS_ERR(sclk)) {
82                 dev_err(&pdev->dev, "failed to get sclk for fimd\n");
83                 goto err_clk2;
84         }
85         clk_enable(sclk);
86         lcd_clk->parent = sclk;
87
88         mout_mpll = clk_get(&pdev->dev, "mout_mpll");
89         if (IS_ERR(mout_mpll)) {
90                 dev_err(&pdev->dev, "failed to get mout_mpll\n");
91                 goto err_clk3;
92         }
93
94         clk_set_parent(sclk, mout_mpll);
95
96         if (!rate)
97                 rate = 134000000;
98
99         clk_set_rate(sclk, rate);
100         dev_dbg(&pdev->dev, "set fimd sclk rate to %d\n", rate);
101
102         clk_put(mout_mpll);
103         clk_put(sclk);
104         clk_put(lcd_clk);
105
106         *out_clk = lcd_clk;
107
108         return 0;
109
110 err_clk3:
111         clk_put(mout_mpll);
112 err_clk2:
113         clk_put(sclk);
114 err_clk1:
115         clk_put(lcd_clk);
116
117         return -EINVAL;
118
119 }
120
121 int s3cfb_clk_on(struct platform_device *pdev, struct clk *in_clk,
122                 unsigned int enable)
123 {
124         if (enable)
125                 clk_enable(in_clk);
126         else
127                 clk_disable(in_clk);
128
129         return 0;
130 }
131
132 void s3cfb_get_clk_name(char *clk_name)
133 {
134         strcpy(clk_name, "sclk_fimd");
135 }
136
137 #ifdef CONFIG_FB_S3C_WA101S
138 int s3cfb_backlight_on(struct platform_device *pdev)
139 {
140 #if !defined(CONFIG_BACKLIGHT_PWM)
141         int err;
142
143         err = gpio_request(S5PV310_GPD0(1), "GPD0");
144         if (err) {
145                 printk(KERN_ERR "failed to request GPD0 for "
146                         "lcd backlight control\n");
147                 return err;
148         }
149
150         gpio_direction_output(S5PV310_GPD0(1), 1);
151         gpio_free(S5PV310_GPD0(1));
152 #endif
153         return 0;
154 }
155
156 int s3cfb_backlight_off(struct platform_device *pdev)
157 {
158 #if !defined(CONFIG_BACKLIGHT_PWM)
159         int err;
160
161         err = gpio_request(S5PV310_GPD0(1), "GPD0");
162         if (err) {
163                 printk(KERN_ERR "failed to request GPD0 for "
164                         "lcd backlight control\n");
165                 return err;
166         }
167
168         gpio_direction_output(S5PV310_GPD0(1), 0);
169         gpio_free(S5PV310_GPD0(1));
170 #endif
171         return 0;
172 }
173
174 int s3cfb_lcd_on(struct platform_device *pdev)
175 {
176         return 0;
177 }
178
179 int s3cfb_lcd_off(struct platform_device *pdev)
180 {
181         return 0;
182 }
183
184 #elif defined(CONFIG_FB_S3C_LTE480WV)
185 int s3cfb_backlight_on(struct platform_device *pdev)
186 {
187 #if !defined(CONFIG_BACKLIGHT_PWM)
188         int err;
189
190         err = gpio_request(S5PV310_GPD0(1), "GPD0");
191         if (err) {
192                 printk(KERN_ERR "failed to request GPD0 for "
193                         "lcd backlight control\n");
194                 return err;
195         }
196
197         gpio_direction_output(S5PV310_GPD0(1), 1);
198         gpio_free(S5PV310_GPD0(1));
199 #endif
200         return 0;
201 }
202
203 int s3cfb_backlight_off(struct platform_device *pdev)
204 {
205 #if !defined(CONFIG_BACKLIGHT_PWM)
206         int err;
207
208         err = gpio_request(S5PV310_GPD0(1), "GPD0");
209         if (err) {
210                 printk(KERN_ERR "failed to request GPD0 for "
211                         "lcd backlight control\n");
212                 return err;
213         }
214
215         gpio_direction_output(S5PV310_GPD0(1), 0);
216         gpio_free(S5PV310_GPD0(1));
217 #endif
218         return 0;
219 }
220
221 int s3cfb_lcd_on(struct platform_device *pdev)
222 {
223         int err;
224
225         err = gpio_request(S5PV310_GPX0(6), "GPX0");
226         if (err) {
227                 printk(KERN_ERR "failed to request GPX0 for "
228                         "lcd reset control\n");
229                 return err;
230         }
231
232         gpio_direction_output(S5PV310_GPX0(6), 1);
233         mdelay(100);
234
235         gpio_set_value(S5PV310_GPX0(6), 0);
236         mdelay(10);
237
238         gpio_set_value(S5PV310_GPX0(6), 1);
239         mdelay(10);
240
241         gpio_free(S5PV310_GPX0(6));
242
243         return 0;
244 }
245
246 int s3cfb_lcd_off(struct platform_device *pdev)
247 {
248         return 0;
249 }
250 #elif defined(CONFIG_FB_S3C_HT101HD1)
251 int s3cfb_backlight_on(struct platform_device *pdev)
252 {
253 #if !defined(CONFIG_BACKLIGHT_PWM)
254         int err;
255
256         err = gpio_request(S5PV310_GPD0(0), "GPD0");
257         if (err) {
258                 printk(KERN_ERR "failed to request GPD0 for "
259                         "lcd backlight control\n");
260                 return err;
261         }
262
263         err = gpio_request(S5PV310_GPB(2), "GPB");
264         if (err) {
265                 printk(KERN_ERR "failed to request GPB for "
266                         "lcd LED_EN control\n");
267                 return err;
268         }
269
270         gpio_direction_output(S5PV310_GPD0(0), 1); /* BL pwm High */
271         gpio_direction_output(S5PV310_GPB(2), 1); /* LED_EN (SPI1_MOSI) */
272
273         gpio_free(S5PV310_GPD0(0));
274         gpio_free(S5PV310_GPB(2));
275 #endif
276         return 0;
277 }
278
279 int s3cfb_backlight_off(struct platform_device *pdev)
280 {
281 #if !defined(CONFIG_BACKLIGHT_PWM)
282         int err;
283
284         err = gpio_request(S5PV310_GPD0(0), "GPD0");
285         if (err) {
286                 printk(KERN_ERR "failed to request GPD0 for "
287                         "lcd backlight control\n");
288                 return err;
289         }
290
291         err = gpio_request(S5PV310_GPB(2), "GPB");
292         if (err) {
293                 printk(KERN_ERR "failed to request GPB for "
294                         "lcd LED_EN control\n");
295                 return err;
296         }
297
298         gpio_direction_output(S5PV310_GPD0(3), 0);
299         gpio_direction_output(S5PV310_GPB(2), 0);
300
301         gpio_free(S5PV310_GPD0(0));
302         gpio_free(S5PV310_GPB(2));
303 #endif
304         return 0;
305 }
306
307 int s3cfb_lcd_on(struct platform_device *pdev)
308 {
309         int err;
310
311         err = gpio_request(S5PV310_GPH0(1), "GPH0");
312         if (err) {
313                 printk(KERN_ERR "failed to request GPH0 for "
314                         "lcd reset control\n");
315                 return err;
316         }
317
318         gpio_direction_output(S5PV310_GPH0(1), 1);
319
320         gpio_set_value(S5PV310_GPH0(1), 0);
321         gpio_set_value(S5PV310_GPH0(1), 1);
322
323         gpio_free(S5PV310_GPH0(1));
324
325         return 0;
326 }
327
328 int s3cfb_lcd_off(struct platform_device *pdev)
329 {
330         return 0;
331 }
332 #elif defined(CONFIG_FB_S3C_AMS369FG06)
333 int s3cfb_backlight_on(struct platform_device *pdev)
334 {
335         return 0;
336 }
337
338 int s3cfb_backlight_off(struct platform_device *pdev)
339 {
340         return 0;
341 }
342
343 int s3cfb_lcd_on(struct platform_device *pdev)
344 {
345         int err;
346
347         err = gpio_request(S5PV310_GPX0(6), "GPX0");
348         if (err) {
349                 printk(KERN_ERR "failed to request GPX0 for "
350                         "lcd reset control\n");
351                 return err;
352         }
353
354         gpio_direction_output(S5PV310_GPX0(6), 1);
355         mdelay(100);
356
357         gpio_set_value(S5PV310_GPX0(6), 1);
358         mdelay(100);
359
360         gpio_free(S5PV310_GPX0(6));
361
362         return 0;
363 }
364
365 int s3cfb_lcd_off(struct platform_device *pdev)
366 {
367         return 0;
368 }
369
370 #else
371 int s3cfb_backlight_on(struct platform_device *pdev)
372 {
373         return 0;
374 }
375
376 int s3cfb_backlight_off(struct platform_device *pdev)
377 {
378         return 0;
379 }
380
381 int s3cfb_lcd_on(struct platform_device *pdev)
382 {
383         return 0;
384 }
385
386 int s3cfb_lcd_off(struct platform_device *pdev)
387 {
388         return 0;
389 }
390 #endif