blob: 7212eb9cfeb9f255f5581b485a2f34eb4afd0261 [file] [log] [blame]
Peter Korsgaard2896bda2009-07-01 17:47:09 +02001/* 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>
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>
24
25#include <asm/mach/arch.h>
26#include <asm/mach/map.h>
27#include <asm/mach/irq.h>
28
Leela Krishna Amudala5a213a52012-08-08 09:44:49 +090029#include <video/samsung_fimd.h>
Peter Korsgaard2896bda2009-07-01 17:47:09 +020030#include <mach/hardware.h>
Peter Korsgaard2896bda2009-07-01 17:47:09 +020031#include <mach/map.h>
32
33#include <asm/irq.h>
34#include <asm/mach-types.h>
35
36#include <plat/regs-serial.h>
Arnd Bergmann436d42c2012-08-24 15:22:12 +020037#include <linux/platform_data/i2c-s3c2410.h>
Peter Korsgaard2896bda2009-07-01 17:47:09 +020038#include <plat/fb.h>
Arnd Bergmann436d42c2012-08-24 15:22:12 +020039#include <linux/platform_data/mtd-nand-s3c2410.h>
Peter Korsgaard2896bda2009-07-01 17:47:09 +020040
Peter Korsgaard2896bda2009-07-01 17:47:09 +020041#include <plat/clock.h>
42#include <plat/devs.h>
43#include <plat/cpu.h>
44
Kukjin Kimb024043b2011-12-22 23:27:42 +010045#include "common.h"
46
Peter Korsgaard2896bda2009-07-01 17:47:09 +020047#define UCON S3C2410_UCON_DEFAULT
48#define ULCON (S3C2410_LCON_CS8 | S3C2410_LCON_PNONE)
49#define UFCON (S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE)
50
51static struct s3c2410_uartcfg hmt_uartcfgs[] __initdata = {
52 [0] = {
53 .hwport = 0,
54 .flags = 0,
55 .ucon = UCON,
56 .ulcon = ULCON,
57 .ufcon = UFCON,
58 },
59 [1] = {
60 .hwport = 1,
61 .flags = 0,
62 .ucon = UCON,
63 .ulcon = ULCON,
64 .ufcon = UFCON,
65 },
66 [2] = {
67 .hwport = 2,
68 .flags = 0,
69 .ucon = UCON,
70 .ulcon = ULCON,
71 .ufcon = UFCON,
72 },
73};
74
75static int hmt_bl_init(struct device *dev)
76{
77 int ret;
78
79 ret = gpio_request(S3C64XX_GPB(4), "lcd backlight enable");
80 if (!ret)
81 ret = gpio_direction_output(S3C64XX_GPB(4), 0);
82
83 return ret;
84}
85
Peter Korsgaard1619ce12010-01-21 22:56:58 +010086static int hmt_bl_notify(struct device *dev, int brightness)
Peter Korsgaard2896bda2009-07-01 17:47:09 +020087{
88 /*
89 * translate from CIELUV/CIELAB L*->brightness, E.G. from
90 * perceived luminance to light output. Assumes range 0..25600
91 */
92 if (brightness < 0x800) {
93 /* Y = Yn * L / 903.3 */
94 brightness = (100*256 * brightness + 231245/2) / 231245;
95 } else {
96 /* Y = Yn * ((L + 16) / 116 )^3 */
97 int t = (brightness*4 + 16*1024 + 58)/116;
98 brightness = 25 * ((t * t * t + 0x100000/2) / 0x100000);
99 }
100
101 gpio_set_value(S3C64XX_GPB(4), brightness);
102
103 return brightness;
104}
105
106static void hmt_bl_exit(struct device *dev)
107{
108 gpio_free(S3C64XX_GPB(4));
109}
110
111static struct platform_pwm_backlight_data hmt_backlight_data = {
112 .pwm_id = 1,
113 .max_brightness = 100 * 256,
114 .dft_brightness = 40 * 256,
115 .pwm_period_ns = 1000000000 / (100 * 256 * 20),
116 .init = hmt_bl_init,
117 .notify = hmt_bl_notify,
118 .exit = hmt_bl_exit,
119
120};
121
122static struct platform_device hmt_backlight_device = {
123 .name = "pwm-backlight",
124 .dev = {
125 .parent = &s3c_device_timer[1].dev,
126 .platform_data = &hmt_backlight_data,
127 },
128};
129
130static struct s3c_fb_pd_win hmt_fb_win0 = {
Peter Korsgaard2896bda2009-07-01 17:47:09 +0200131 .max_bpp = 32,
132 .default_bpp = 16,
Thomas Abraham79d3c412012-03-24 21:58:48 +0530133 .xres = 800,
134 .yres = 480,
135};
136
137static struct fb_videomode hmt_lcd_timing = {
138 .left_margin = 8,
139 .right_margin = 13,
140 .upper_margin = 7,
141 .lower_margin = 5,
142 .hsync_len = 3,
143 .vsync_len = 1,
144 .xres = 800,
145 .yres = 480,
Peter Korsgaard2896bda2009-07-01 17:47:09 +0200146};
147
148/* 405566 clocks per frame => 60Hz refresh requires 24333960Hz clock */
149static struct s3c_fb_platdata hmt_lcd_pdata __initdata = {
150 .setup_gpio = s3c64xx_fb_gpio_setup_24bpp,
Thomas Abraham79d3c412012-03-24 21:58:48 +0530151 .vtiming = &hmt_lcd_timing,
Peter Korsgaard2896bda2009-07-01 17:47:09 +0200152 .win[0] = &hmt_fb_win0,
153 .vidcon0 = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB,
154 .vidcon1 = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC,
155};
156
157static struct mtd_partition hmt_nand_part[] = {
158 [0] = {
159 .name = "uboot",
160 .size = SZ_512K,
161 .offset = 0,
162 },
163 [1] = {
164 .name = "uboot-env1",
165 .size = SZ_256K,
166 .offset = SZ_512K,
167 },
168 [2] = {
169 .name = "uboot-env2",
170 .size = SZ_256K,
171 .offset = SZ_512K + SZ_256K,
172 },
173 [3] = {
174 .name = "kernel",
175 .size = SZ_2M,
176 .offset = SZ_1M,
177 },
178 [4] = {
179 .name = "rootfs",
180 .size = MTDPART_SIZ_FULL,
181 .offset = SZ_1M + SZ_2M,
182 },
183};
184
185static struct s3c2410_nand_set hmt_nand_sets[] = {
186 [0] = {
187 .name = "nand",
188 .nr_chips = 1,
189 .nr_partitions = ARRAY_SIZE(hmt_nand_part),
190 .partitions = hmt_nand_part,
191 },
192};
193
194static struct s3c2410_platform_nand hmt_nand_info = {
195 .tacls = 25,
196 .twrph0 = 55,
197 .twrph1 = 40,
198 .nr_sets = ARRAY_SIZE(hmt_nand_sets),
199 .sets = hmt_nand_sets,
200};
201
202static struct gpio_led hmt_leds[] = {
203 { /* left function keys */
204 .name = "left:blue",
205 .gpio = S3C64XX_GPO(12),
206 .default_trigger = "default-on",
207 },
208 { /* right function keys - red */
209 .name = "right:red",
210 .gpio = S3C64XX_GPO(13),
211 },
212 { /* right function keys - green */
213 .name = "right:green",
214 .gpio = S3C64XX_GPO(14),
215 },
216 { /* right function keys - blue */
217 .name = "right:blue",
218 .gpio = S3C64XX_GPO(15),
219 .default_trigger = "default-on",
220 },
221};
222
223static struct gpio_led_platform_data hmt_led_data = {
224 .num_leds = ARRAY_SIZE(hmt_leds),
225 .leds = hmt_leds,
226};
227
228static struct platform_device hmt_leds_device = {
229 .name = "leds-gpio",
230 .id = -1,
231 .dev.platform_data = &hmt_led_data,
232};
233
234static struct map_desc hmt_iodesc[] = {};
235
236static struct platform_device *hmt_devices[] __initdata = {
237 &s3c_device_i2c0,
238 &s3c_device_nand,
239 &s3c_device_fb,
Ben Dooksb8132482009-11-23 00:13:39 +0000240 &s3c_device_ohci,
Peter Korsgaard2896bda2009-07-01 17:47:09 +0200241 &s3c_device_timer[1],
242 &hmt_backlight_device,
243 &hmt_leds_device,
244};
245
246static void __init hmt_map_io(void)
247{
248 s3c64xx_init_io(hmt_iodesc, ARRAY_SIZE(hmt_iodesc));
249 s3c24xx_init_clocks(12000000);
250 s3c24xx_init_uarts(hmt_uartcfgs, ARRAY_SIZE(hmt_uartcfgs));
251}
252
253static void __init hmt_machine_init(void)
254{
255 s3c_i2c0_set_platdata(NULL);
256 s3c_fb_set_platdata(&hmt_lcd_pdata);
Ben Dooks2a3a1802009-09-28 13:59:49 +0300257 s3c_nand_set_platdata(&hmt_nand_info);
Peter Korsgaard2896bda2009-07-01 17:47:09 +0200258
259 gpio_request(S3C64XX_GPC(7), "usb power");
260 gpio_direction_output(S3C64XX_GPC(7), 0);
261 gpio_request(S3C64XX_GPM(0), "usb power");
262 gpio_direction_output(S3C64XX_GPM(0), 1);
263 gpio_request(S3C64XX_GPK(7), "usb power");
264 gpio_direction_output(S3C64XX_GPK(7), 1);
265 gpio_request(S3C64XX_GPF(13), "usb power");
266 gpio_direction_output(S3C64XX_GPF(13), 1);
267
268 platform_add_devices(hmt_devices, ARRAY_SIZE(hmt_devices));
269}
270
271MACHINE_START(HMT, "Airgoo-HMT")
272 /* Maintainer: Peter Korsgaard <jacmet@sunsite.dk> */
Nicolas Pitre170a5902011-07-05 22:38:17 -0400273 .atag_offset = 0x100,
Peter Korsgaard2896bda2009-07-01 17:47:09 +0200274 .init_irq = s3c6410_init_irq,
Peter Korsgaard2896bda2009-07-01 17:47:09 +0200275 .map_io = hmt_map_io,
276 .init_machine = hmt_machine_init,
Shawn Guocc8f2522012-04-26 21:08:52 +0800277 .init_late = s3c64xx_init_late,
Stephen Warren6bb27d72012-11-08 12:40:59 -0700278 .init_time = s3c24xx_timer_init,
Kukjin Kimff84ded2012-01-03 14:03:30 +0100279 .restart = s3c64xx_restart,
Peter Korsgaard2896bda2009-07-01 17:47:09 +0200280MACHINE_END