Merge tag 'fbdev-updates-for-3.5' of git://github.com/schandinat/linux-2.6
[linux-2.6.git] / arch / arm / mach-s3c64xx / mach-hmt.c
blob689088162f77e4eaab4868cb519889e976ab4401
1 /* mach-hmt.c - Platform code for Airgoo HMT
3 * Copyright 2009 Peter Korsgaard <jacmet@sunsite.dk>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 */
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/serial_core.h>
14 #include <linux/platform_device.h>
15 #include <linux/io.h>
16 #include <linux/i2c.h>
17 #include <linux/fb.h>
18 #include <linux/gpio.h>
19 #include <linux/delay.h>
20 #include <linux/leds.h>
21 #include <linux/pwm_backlight.h>
22 #include <linux/mtd/mtd.h>
23 #include <linux/mtd/partitions.h>
25 #include <asm/mach/arch.h>
26 #include <asm/mach/map.h>
27 #include <asm/mach/irq.h>
29 #include <mach/hardware.h>
30 #include <mach/map.h>
32 #include <asm/hardware/vic.h>
33 #include <asm/irq.h>
34 #include <asm/mach-types.h>
36 #include <plat/regs-serial.h>
37 #include <plat/iic.h>
38 #include <plat/fb.h>
39 #include <plat/nand.h>
41 #include <plat/clock.h>
42 #include <plat/devs.h>
43 #include <plat/cpu.h>
44 #include <plat/regs-fb-v4.h>
46 #include "common.h"
48 #define UCON S3C2410_UCON_DEFAULT
49 #define ULCON (S3C2410_LCON_CS8 | S3C2410_LCON_PNONE)
50 #define UFCON (S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE)
52 static struct s3c2410_uartcfg hmt_uartcfgs[] __initdata = {
53 [0] = {
54 .hwport = 0,
55 .flags = 0,
56 .ucon = UCON,
57 .ulcon = ULCON,
58 .ufcon = UFCON,
60 [1] = {
61 .hwport = 1,
62 .flags = 0,
63 .ucon = UCON,
64 .ulcon = ULCON,
65 .ufcon = UFCON,
67 [2] = {
68 .hwport = 2,
69 .flags = 0,
70 .ucon = UCON,
71 .ulcon = ULCON,
72 .ufcon = UFCON,
76 static int hmt_bl_init(struct device *dev)
78 int ret;
80 ret = gpio_request(S3C64XX_GPB(4), "lcd backlight enable");
81 if (!ret)
82 ret = gpio_direction_output(S3C64XX_GPB(4), 0);
84 return ret;
87 static int hmt_bl_notify(struct device *dev, int brightness)
90 * translate from CIELUV/CIELAB L*->brightness, E.G. from
91 * perceived luminance to light output. Assumes range 0..25600
93 if (brightness < 0x800) {
94 /* Y = Yn * L / 903.3 */
95 brightness = (100*256 * brightness + 231245/2) / 231245;
96 } else {
97 /* Y = Yn * ((L + 16) / 116 )^3 */
98 int t = (brightness*4 + 16*1024 + 58)/116;
99 brightness = 25 * ((t * t * t + 0x100000/2) / 0x100000);
102 gpio_set_value(S3C64XX_GPB(4), brightness);
104 return brightness;
107 static void hmt_bl_exit(struct device *dev)
109 gpio_free(S3C64XX_GPB(4));
112 static struct platform_pwm_backlight_data hmt_backlight_data = {
113 .pwm_id = 1,
114 .max_brightness = 100 * 256,
115 .dft_brightness = 40 * 256,
116 .pwm_period_ns = 1000000000 / (100 * 256 * 20),
117 .init = hmt_bl_init,
118 .notify = hmt_bl_notify,
119 .exit = hmt_bl_exit,
123 static struct platform_device hmt_backlight_device = {
124 .name = "pwm-backlight",
125 .dev = {
126 .parent = &s3c_device_timer[1].dev,
127 .platform_data = &hmt_backlight_data,
131 static struct s3c_fb_pd_win hmt_fb_win0 = {
132 .max_bpp = 32,
133 .default_bpp = 16,
134 .xres = 800,
135 .yres = 480,
138 static struct fb_videomode hmt_lcd_timing = {
139 .left_margin = 8,
140 .right_margin = 13,
141 .upper_margin = 7,
142 .lower_margin = 5,
143 .hsync_len = 3,
144 .vsync_len = 1,
145 .xres = 800,
146 .yres = 480,
149 /* 405566 clocks per frame => 60Hz refresh requires 24333960Hz clock */
150 static struct s3c_fb_platdata hmt_lcd_pdata __initdata = {
151 .setup_gpio = s3c64xx_fb_gpio_setup_24bpp,
152 .vtiming = &hmt_lcd_timing,
153 .win[0] = &hmt_fb_win0,
154 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB,
155 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC,
158 static struct mtd_partition hmt_nand_part[] = {
159 [0] = {
160 .name = "uboot",
161 .size = SZ_512K,
162 .offset = 0,
164 [1] = {
165 .name = "uboot-env1",
166 .size = SZ_256K,
167 .offset = SZ_512K,
169 [2] = {
170 .name = "uboot-env2",
171 .size = SZ_256K,
172 .offset = SZ_512K + SZ_256K,
174 [3] = {
175 .name = "kernel",
176 .size = SZ_2M,
177 .offset = SZ_1M,
179 [4] = {
180 .name = "rootfs",
181 .size = MTDPART_SIZ_FULL,
182 .offset = SZ_1M + SZ_2M,
186 static struct s3c2410_nand_set hmt_nand_sets[] = {
187 [0] = {
188 .name = "nand",
189 .nr_chips = 1,
190 .nr_partitions = ARRAY_SIZE(hmt_nand_part),
191 .partitions = hmt_nand_part,
195 static struct s3c2410_platform_nand hmt_nand_info = {
196 .tacls = 25,
197 .twrph0 = 55,
198 .twrph1 = 40,
199 .nr_sets = ARRAY_SIZE(hmt_nand_sets),
200 .sets = hmt_nand_sets,
203 static struct gpio_led hmt_leds[] = {
204 { /* left function keys */
205 .name = "left:blue",
206 .gpio = S3C64XX_GPO(12),
207 .default_trigger = "default-on",
209 { /* right function keys - red */
210 .name = "right:red",
211 .gpio = S3C64XX_GPO(13),
213 { /* right function keys - green */
214 .name = "right:green",
215 .gpio = S3C64XX_GPO(14),
217 { /* right function keys - blue */
218 .name = "right:blue",
219 .gpio = S3C64XX_GPO(15),
220 .default_trigger = "default-on",
224 static struct gpio_led_platform_data hmt_led_data = {
225 .num_leds = ARRAY_SIZE(hmt_leds),
226 .leds = hmt_leds,
229 static struct platform_device hmt_leds_device = {
230 .name = "leds-gpio",
231 .id = -1,
232 .dev.platform_data = &hmt_led_data,
235 static struct map_desc hmt_iodesc[] = {};
237 static struct platform_device *hmt_devices[] __initdata = {
238 &s3c_device_i2c0,
239 &s3c_device_nand,
240 &s3c_device_fb,
241 &s3c_device_ohci,
242 &s3c_device_timer[1],
243 &hmt_backlight_device,
244 &hmt_leds_device,
247 static void __init hmt_map_io(void)
249 s3c64xx_init_io(hmt_iodesc, ARRAY_SIZE(hmt_iodesc));
250 s3c24xx_init_clocks(12000000);
251 s3c24xx_init_uarts(hmt_uartcfgs, ARRAY_SIZE(hmt_uartcfgs));
254 static void __init hmt_machine_init(void)
256 s3c_i2c0_set_platdata(NULL);
257 s3c_fb_set_platdata(&hmt_lcd_pdata);
258 s3c_nand_set_platdata(&hmt_nand_info);
260 gpio_request(S3C64XX_GPC(7), "usb power");
261 gpio_direction_output(S3C64XX_GPC(7), 0);
262 gpio_request(S3C64XX_GPM(0), "usb power");
263 gpio_direction_output(S3C64XX_GPM(0), 1);
264 gpio_request(S3C64XX_GPK(7), "usb power");
265 gpio_direction_output(S3C64XX_GPK(7), 1);
266 gpio_request(S3C64XX_GPF(13), "usb power");
267 gpio_direction_output(S3C64XX_GPF(13), 1);
269 platform_add_devices(hmt_devices, ARRAY_SIZE(hmt_devices));
272 MACHINE_START(HMT, "Airgoo-HMT")
273 /* Maintainer: Peter Korsgaard <jacmet@sunsite.dk> */
274 .atag_offset = 0x100,
275 .init_irq = s3c6410_init_irq,
276 .handle_irq = vic_handle_irq,
277 .map_io = hmt_map_io,
278 .init_machine = hmt_machine_init,
279 .init_late = s3c64xx_init_late,
280 .timer = &s3c24xx_timer,
281 .restart = s3c64xx_restart,
282 MACHINE_END