Commit | Line | Data |
---|---|---|
2896bda4 PK |
1 | /* mach-hmt.c - Platform code for Airgoo HMT |
2 | * | |
3 | * Copyright 2009 Peter Korsgaard <jacmet@sunsite.dk> | |
4 | * | |
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. | |
8 | * | |
9 | */ | |
10 | ||
11 | #include <linux/kernel.h> | |
12 | #include <linux/init.h> | |
13 | #include <linux/serial_core.h> | |
334a1c70 | 14 | #include <linux/serial_s3c.h> |
2896bda4 PK |
15 | #include <linux/platform_device.h> |
16 | #include <linux/io.h> | |
17 | #include <linux/i2c.h> | |
18 | #include <linux/fb.h> | |
19 | #include <linux/gpio.h> | |
20 | #include <linux/delay.h> | |
21 | #include <linux/leds.h> | |
22 | #include <linux/pwm_backlight.h> | |
23 | #include <linux/mtd/mtd.h> | |
24 | #include <linux/mtd/partitions.h> | |
25 | ||
26 | #include <asm/mach/arch.h> | |
27 | #include <asm/mach/map.h> | |
28 | #include <asm/mach/irq.h> | |
29 | ||
5a213a55 | 30 | #include <video/samsung_fimd.h> |
2896bda4 | 31 | #include <mach/hardware.h> |
2896bda4 PK |
32 | #include <mach/map.h> |
33 | ||
34 | #include <asm/irq.h> | |
35 | #include <asm/mach-types.h> | |
36 | ||
436d42c6 | 37 | #include <linux/platform_data/i2c-s3c2410.h> |
b0161caa | 38 | #include <mach/gpio-samsung.h> |
2896bda4 | 39 | #include <plat/fb.h> |
436d42c6 | 40 | #include <linux/platform_data/mtd-nand-s3c2410.h> |
2896bda4 | 41 | |
2896bda4 PK |
42 | #include <plat/clock.h> |
43 | #include <plat/devs.h> | |
44 | #include <plat/cpu.h> | |
04a49b71 | 45 | #include <plat/samsung-time.h> |
2896bda4 | 46 | |
b024043b KK |
47 | #include "common.h" |
48 | ||
2896bda4 PK |
49 | #define UCON S3C2410_UCON_DEFAULT |
50 | #define ULCON (S3C2410_LCON_CS8 | S3C2410_LCON_PNONE) | |
51 | #define UFCON (S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE) | |
52 | ||
53 | static struct s3c2410_uartcfg hmt_uartcfgs[] __initdata = { | |
54 | [0] = { | |
55 | .hwport = 0, | |
56 | .flags = 0, | |
57 | .ucon = UCON, | |
58 | .ulcon = ULCON, | |
59 | .ufcon = UFCON, | |
60 | }, | |
61 | [1] = { | |
62 | .hwport = 1, | |
63 | .flags = 0, | |
64 | .ucon = UCON, | |
65 | .ulcon = ULCON, | |
66 | .ufcon = UFCON, | |
67 | }, | |
68 | [2] = { | |
69 | .hwport = 2, | |
70 | .flags = 0, | |
71 | .ucon = UCON, | |
72 | .ulcon = ULCON, | |
73 | .ufcon = UFCON, | |
74 | }, | |
75 | }; | |
76 | ||
77 | static int hmt_bl_init(struct device *dev) | |
78 | { | |
79 | int ret; | |
80 | ||
81 | ret = gpio_request(S3C64XX_GPB(4), "lcd backlight enable"); | |
82 | if (!ret) | |
83 | ret = gpio_direction_output(S3C64XX_GPB(4), 0); | |
84 | ||
85 | return ret; | |
86 | } | |
87 | ||
1619ce11 | 88 | static int hmt_bl_notify(struct device *dev, int brightness) |
2896bda4 PK |
89 | { |
90 | /* | |
91 | * translate from CIELUV/CIELAB L*->brightness, E.G. from | |
92 | * perceived luminance to light output. Assumes range 0..25600 | |
93 | */ | |
94 | if (brightness < 0x800) { | |
95 | /* Y = Yn * L / 903.3 */ | |
96 | brightness = (100*256 * brightness + 231245/2) / 231245; | |
97 | } else { | |
98 | /* Y = Yn * ((L + 16) / 116 )^3 */ | |
99 | int t = (brightness*4 + 16*1024 + 58)/116; | |
100 | brightness = 25 * ((t * t * t + 0x100000/2) / 0x100000); | |
101 | } | |
102 | ||
103 | gpio_set_value(S3C64XX_GPB(4), brightness); | |
104 | ||
105 | return brightness; | |
106 | } | |
107 | ||
108 | static void hmt_bl_exit(struct device *dev) | |
109 | { | |
110 | gpio_free(S3C64XX_GPB(4)); | |
111 | } | |
112 | ||
113 | static struct platform_pwm_backlight_data hmt_backlight_data = { | |
114 | .pwm_id = 1, | |
115 | .max_brightness = 100 * 256, | |
116 | .dft_brightness = 40 * 256, | |
117 | .pwm_period_ns = 1000000000 / (100 * 256 * 20), | |
a63652f1 | 118 | .enable_gpio = -1, |
2896bda4 PK |
119 | .init = hmt_bl_init, |
120 | .notify = hmt_bl_notify, | |
121 | .exit = hmt_bl_exit, | |
122 | ||
123 | }; | |
124 | ||
125 | static struct platform_device hmt_backlight_device = { | |
126 | .name = "pwm-backlight", | |
127 | .dev = { | |
7fa33bdb | 128 | .parent = &samsung_device_pwm.dev, |
2896bda4 PK |
129 | .platform_data = &hmt_backlight_data, |
130 | }, | |
131 | }; | |
132 | ||
133 | static struct s3c_fb_pd_win hmt_fb_win0 = { | |
2896bda4 PK |
134 | .max_bpp = 32, |
135 | .default_bpp = 16, | |
79d3c41a TA |
136 | .xres = 800, |
137 | .yres = 480, | |
138 | }; | |
139 | ||
140 | static struct fb_videomode hmt_lcd_timing = { | |
141 | .left_margin = 8, | |
142 | .right_margin = 13, | |
143 | .upper_margin = 7, | |
144 | .lower_margin = 5, | |
145 | .hsync_len = 3, | |
146 | .vsync_len = 1, | |
147 | .xres = 800, | |
148 | .yres = 480, | |
2896bda4 PK |
149 | }; |
150 | ||
151 | /* 405566 clocks per frame => 60Hz refresh requires 24333960Hz clock */ | |
152 | static struct s3c_fb_platdata hmt_lcd_pdata __initdata = { | |
153 | .setup_gpio = s3c64xx_fb_gpio_setup_24bpp, | |
79d3c41a | 154 | .vtiming = &hmt_lcd_timing, |
2896bda4 PK |
155 | .win[0] = &hmt_fb_win0, |
156 | .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB, | |
157 | .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC, | |
158 | }; | |
159 | ||
160 | static struct mtd_partition hmt_nand_part[] = { | |
161 | [0] = { | |
162 | .name = "uboot", | |
163 | .size = SZ_512K, | |
164 | .offset = 0, | |
165 | }, | |
166 | [1] = { | |
167 | .name = "uboot-env1", | |
168 | .size = SZ_256K, | |
169 | .offset = SZ_512K, | |
170 | }, | |
171 | [2] = { | |
172 | .name = "uboot-env2", | |
173 | .size = SZ_256K, | |
174 | .offset = SZ_512K + SZ_256K, | |
175 | }, | |
176 | [3] = { | |
177 | .name = "kernel", | |
178 | .size = SZ_2M, | |
179 | .offset = SZ_1M, | |
180 | }, | |
181 | [4] = { | |
182 | .name = "rootfs", | |
183 | .size = MTDPART_SIZ_FULL, | |
184 | .offset = SZ_1M + SZ_2M, | |
185 | }, | |
186 | }; | |
187 | ||
188 | static struct s3c2410_nand_set hmt_nand_sets[] = { | |
189 | [0] = { | |
190 | .name = "nand", | |
191 | .nr_chips = 1, | |
192 | .nr_partitions = ARRAY_SIZE(hmt_nand_part), | |
193 | .partitions = hmt_nand_part, | |
194 | }, | |
195 | }; | |
196 | ||
197 | static struct s3c2410_platform_nand hmt_nand_info = { | |
198 | .tacls = 25, | |
199 | .twrph0 = 55, | |
200 | .twrph1 = 40, | |
201 | .nr_sets = ARRAY_SIZE(hmt_nand_sets), | |
202 | .sets = hmt_nand_sets, | |
203 | }; | |
204 | ||
205 | static struct gpio_led hmt_leds[] = { | |
206 | { /* left function keys */ | |
207 | .name = "left:blue", | |
208 | .gpio = S3C64XX_GPO(12), | |
209 | .default_trigger = "default-on", | |
210 | }, | |
211 | { /* right function keys - red */ | |
212 | .name = "right:red", | |
213 | .gpio = S3C64XX_GPO(13), | |
214 | }, | |
215 | { /* right function keys - green */ | |
216 | .name = "right:green", | |
217 | .gpio = S3C64XX_GPO(14), | |
218 | }, | |
219 | { /* right function keys - blue */ | |
220 | .name = "right:blue", | |
221 | .gpio = S3C64XX_GPO(15), | |
222 | .default_trigger = "default-on", | |
223 | }, | |
224 | }; | |
225 | ||
226 | static struct gpio_led_platform_data hmt_led_data = { | |
227 | .num_leds = ARRAY_SIZE(hmt_leds), | |
228 | .leds = hmt_leds, | |
229 | }; | |
230 | ||
231 | static struct platform_device hmt_leds_device = { | |
232 | .name = "leds-gpio", | |
233 | .id = -1, | |
234 | .dev.platform_data = &hmt_led_data, | |
235 | }; | |
236 | ||
237 | static struct map_desc hmt_iodesc[] = {}; | |
238 | ||
239 | static struct platform_device *hmt_devices[] __initdata = { | |
240 | &s3c_device_i2c0, | |
241 | &s3c_device_nand, | |
242 | &s3c_device_fb, | |
b813248c | 243 | &s3c_device_ohci, |
7fa33bdb | 244 | &samsung_device_pwm, |
2896bda4 PK |
245 | &hmt_backlight_device, |
246 | &hmt_leds_device, | |
247 | }; | |
248 | ||
249 | static void __init hmt_map_io(void) | |
250 | { | |
251 | s3c64xx_init_io(hmt_iodesc, ARRAY_SIZE(hmt_iodesc)); | |
b69f460d | 252 | s3c64xx_set_xtal_freq(12000000); |
2896bda4 | 253 | s3c24xx_init_uarts(hmt_uartcfgs, ARRAY_SIZE(hmt_uartcfgs)); |
04a49b71 | 254 | samsung_set_timer_source(SAMSUNG_PWM3, SAMSUNG_PWM4); |
2896bda4 PK |
255 | } |
256 | ||
257 | static void __init hmt_machine_init(void) | |
258 | { | |
259 | s3c_i2c0_set_platdata(NULL); | |
260 | s3c_fb_set_platdata(&hmt_lcd_pdata); | |
2a3a1804 | 261 | s3c_nand_set_platdata(&hmt_nand_info); |
2896bda4 PK |
262 | |
263 | gpio_request(S3C64XX_GPC(7), "usb power"); | |
264 | gpio_direction_output(S3C64XX_GPC(7), 0); | |
265 | gpio_request(S3C64XX_GPM(0), "usb power"); | |
266 | gpio_direction_output(S3C64XX_GPM(0), 1); | |
267 | gpio_request(S3C64XX_GPK(7), "usb power"); | |
268 | gpio_direction_output(S3C64XX_GPK(7), 1); | |
269 | gpio_request(S3C64XX_GPF(13), "usb power"); | |
270 | gpio_direction_output(S3C64XX_GPF(13), 1); | |
271 | ||
272 | platform_add_devices(hmt_devices, ARRAY_SIZE(hmt_devices)); | |
273 | } | |
274 | ||
275 | MACHINE_START(HMT, "Airgoo-HMT") | |
276 | /* Maintainer: Peter Korsgaard <jacmet@sunsite.dk> */ | |
170a5908 | 277 | .atag_offset = 0x100, |
2896bda4 PK |
278 | .init_irq = s3c6410_init_irq, |
279 | .map_io = hmt_map_io, | |
280 | .init_machine = hmt_machine_init, | |
cc8f252b | 281 | .init_late = s3c64xx_init_late, |
04a49b71 | 282 | .init_time = samsung_timer_init, |
ff84ded2 | 283 | .restart = s3c64xx_restart, |
2896bda4 | 284 | MACHINE_END |