1 /* linux/arch/arm/mach-s3c2440/mach-mini2440.c
6 * Weibing <http://weibing.blogbus.com> and
9 * For product information, visit http://code.google.com/p/mini2440/
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
16 #include <linux/kernel.h>
17 #include <linux/types.h>
18 #include <linux/interrupt.h>
19 #include <linux/list.h>
20 #include <linux/timer.h>
21 #include <linux/init.h>
22 #include <linux/gpio.h>
23 #include <linux/input.h>
25 #include <linux/serial_core.h>
26 #include <linux/serial_s3c.h>
27 #include <linux/dm9000.h>
28 #include <linux/platform_data/at24.h>
29 #include <linux/platform_device.h>
30 #include <linux/gpio_keys.h>
31 #include <linux/i2c.h>
32 #include <linux/mmc/host.h>
34 #include <asm/mach/arch.h>
35 #include <asm/mach/map.h>
37 #include <mach/hardware.h>
39 #include <asm/mach-types.h>
41 #include <mach/regs-gpio.h>
42 #include <linux/platform_data/leds-s3c24xx.h>
43 #include <mach/regs-lcd.h>
44 #include <mach/irqs.h>
45 #include <mach/gpio-samsung.h>
46 #include <linux/platform_data/mtd-nand-s3c2410.h>
47 #include <linux/platform_data/i2c-s3c2410.h>
48 #include <linux/platform_data/mmc-s3cmci.h>
49 #include <linux/platform_data/usb-s3c2410_udc.h>
51 #include <linux/mtd/mtd.h>
52 #include <linux/mtd/nand.h>
53 #include <linux/mtd/nand_ecc.h>
54 #include <linux/mtd/partitions.h>
56 #include <plat/gpio-cfg.h>
57 #include <plat/devs.h>
59 #include <plat/samsung-time.h>
61 #include <sound/s3c24xx_uda134x.h>
65 #define MACH_MINI2440_DM9K_BASE (S3C2410_CS4 + 0x300)
67 static struct map_desc mini2440_iodesc[] __initdata = {
68 /* nothing to declare, move along */
71 #define UCON S3C2410_UCON_DEFAULT
72 #define ULCON S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB
73 #define UFCON S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE
76 static struct s3c2410_uartcfg mini2440_uartcfgs[] __initdata = {
100 /* USB device UDC support */
102 static struct s3c2410_udc_mach_info mini2440_udc_cfg __initdata = {
103 .pullup_pin = S3C2410_GPC(5),
107 /* LCD timing and setup */
110 * This macro simplifies the table bellow
112 #define _LCD_DECLARE(_clock,_xres,margin_left,margin_right,hsync, \
113 _yres,margin_top,margin_bottom,vsync, refresh) \
118 .left_margin = margin_left, \
119 .right_margin = margin_right, \
120 .upper_margin = margin_top, \
121 .lower_margin = margin_bottom, \
122 .hsync_len = hsync, \
123 .vsync_len = vsync, \
124 .pixclock = ((_clock*100000000000LL) / \
126 (hsync + margin_left + _xres + margin_right) * \
127 (vsync + margin_top + _yres + margin_bottom))), \
129 .type = (S3C2410_LCDCON1_TFT16BPP |\
132 static struct s3c2410fb_display mini2440_lcd_cfg[] __initdata = {
133 [0] = { /* mini2440 + 3.5" TFT + touchscreen */
135 7, /* The 3.5 is quite fast */
136 240, 21, 38, 6, /* x timing */
137 320, 4, 4, 2, /* y timing */
138 60), /* refresh rate */
139 .lcdcon5 = (S3C2410_LCDCON5_FRM565 |
140 S3C2410_LCDCON5_INVVLINE |
141 S3C2410_LCDCON5_INVVFRAME |
142 S3C2410_LCDCON5_INVVDEN |
143 S3C2410_LCDCON5_PWREN),
145 [1] = { /* mini2440 + 7" TFT + touchscreen */
147 10, /* the 7" runs slower */
148 800, 40, 40, 48, /* x timing */
149 480, 29, 3, 3, /* y timing */
150 50), /* refresh rate */
151 .lcdcon5 = (S3C2410_LCDCON5_FRM565 |
152 S3C2410_LCDCON5_INVVLINE |
153 S3C2410_LCDCON5_INVVFRAME |
154 S3C2410_LCDCON5_PWREN),
156 /* The VGA shield can outout at several resolutions. All share
157 * the same timings, however, anything smaller than 1024x768
158 * will only be displayed in the top left corner of a 1024x768
159 * XGA output unless you add optional dip switches to the shield.
160 * Therefore timings for other resolutions have been omitted here.
165 1024, 1, 2, 2, /* y timing */
166 768, 200, 16, 16, /* x timing */
167 24), /* refresh rate, maximum stable,
168 tested with the FPGA shield */
169 .lcdcon5 = (S3C2410_LCDCON5_FRM565 |
170 S3C2410_LCDCON5_HWSWP),
172 /* mini2440 + 3.5" TFT (LCD-W35i, LQ035Q1DG06 type) + touchscreen*/
177 /* xres, margin_right, margin_left, hsync */
179 /* yres, margin_top, margin_bottom, vsync */
183 .lcdcon5 = (S3C2410_LCDCON5_FRM565 |
184 S3C2410_LCDCON5_INVVDEN |
185 S3C2410_LCDCON5_INVVFRAME |
186 S3C2410_LCDCON5_INVVLINE |
187 S3C2410_LCDCON5_INVVCLK |
188 S3C2410_LCDCON5_HWSWP),
192 /* todo - put into gpio header */
194 #define S3C2410_GPCCON_MASK(x) (3 << ((x) * 2))
195 #define S3C2410_GPDCON_MASK(x) (3 << ((x) * 2))
197 static struct s3c2410fb_mach_info mini2440_fb_info __initdata = {
198 .displays = &mini2440_lcd_cfg[0], /* not constant! see init */
200 .default_display = 0,
202 /* Enable VD[2..7], VD[10..15], VD[18..23] and VCLK, syncs, VDEN
203 * and disable the pull down resistors on pins we are using for LCD
206 .gpcup = (0xf << 1) | (0x3f << 10),
208 .gpccon = (S3C2410_GPC1_VCLK | S3C2410_GPC2_VLINE |
209 S3C2410_GPC3_VFRAME | S3C2410_GPC4_VM |
210 S3C2410_GPC10_VD2 | S3C2410_GPC11_VD3 |
211 S3C2410_GPC12_VD4 | S3C2410_GPC13_VD5 |
212 S3C2410_GPC14_VD6 | S3C2410_GPC15_VD7),
214 .gpccon_mask = (S3C2410_GPCCON_MASK(1) | S3C2410_GPCCON_MASK(2) |
215 S3C2410_GPCCON_MASK(3) | S3C2410_GPCCON_MASK(4) |
216 S3C2410_GPCCON_MASK(10) | S3C2410_GPCCON_MASK(11) |
217 S3C2410_GPCCON_MASK(12) | S3C2410_GPCCON_MASK(13) |
218 S3C2410_GPCCON_MASK(14) | S3C2410_GPCCON_MASK(15)),
220 .gpdup = (0x3f << 2) | (0x3f << 10),
222 .gpdcon = (S3C2410_GPD2_VD10 | S3C2410_GPD3_VD11 |
223 S3C2410_GPD4_VD12 | S3C2410_GPD5_VD13 |
224 S3C2410_GPD6_VD14 | S3C2410_GPD7_VD15 |
225 S3C2410_GPD10_VD18 | S3C2410_GPD11_VD19 |
226 S3C2410_GPD12_VD20 | S3C2410_GPD13_VD21 |
227 S3C2410_GPD14_VD22 | S3C2410_GPD15_VD23),
229 .gpdcon_mask = (S3C2410_GPDCON_MASK(2) | S3C2410_GPDCON_MASK(3) |
230 S3C2410_GPDCON_MASK(4) | S3C2410_GPDCON_MASK(5) |
231 S3C2410_GPDCON_MASK(6) | S3C2410_GPDCON_MASK(7) |
232 S3C2410_GPDCON_MASK(10) | S3C2410_GPDCON_MASK(11)|
233 S3C2410_GPDCON_MASK(12) | S3C2410_GPDCON_MASK(13)|
234 S3C2410_GPDCON_MASK(14) | S3C2410_GPDCON_MASK(15)),
239 static struct s3c24xx_mci_pdata mini2440_mmc_cfg __initdata = {
240 .gpio_detect = S3C2410_GPG(8),
241 .gpio_wprotect = S3C2410_GPH(8),
243 .ocr_avail = MMC_VDD_32_33|MMC_VDD_33_34,
246 /* NAND Flash on MINI2440 board */
248 static struct mtd_partition mini2440_default_nand_part[] __initdata = {
255 .name = "u-boot-env",
261 /* 5 megabytes, for a kernel with no modules
262 * or a uImage with a ramdisk attached */
264 .offset = SZ_256K + SZ_128K,
268 .offset = SZ_256K + SZ_128K + 0x00500000,
269 .size = MTDPART_SIZ_FULL,
273 static struct s3c2410_nand_set mini2440_nand_sets[] __initdata = {
277 .nr_partitions = ARRAY_SIZE(mini2440_default_nand_part),
278 .partitions = mini2440_default_nand_part,
279 .flash_bbt = 1, /* we use u-boot to create a BBT */
283 static struct s3c2410_platform_nand mini2440_nand_info __initdata = {
287 .nr_sets = ARRAY_SIZE(mini2440_nand_sets),
288 .sets = mini2440_nand_sets,
289 .ignore_unset_ecc = 1,
290 .ecc_mode = NAND_ECC_SOFT,
293 /* DM9000AEP 10/100 ethernet controller */
295 static struct resource mini2440_dm9k_resource[] = {
296 [0] = DEFINE_RES_MEM(MACH_MINI2440_DM9K_BASE, 4),
297 [1] = DEFINE_RES_MEM(MACH_MINI2440_DM9K_BASE + 4, 4),
298 [2] = DEFINE_RES_NAMED(IRQ_EINT7, 1, NULL, IORESOURCE_IRQ \
299 | IORESOURCE_IRQ_HIGHEDGE),
303 * The DM9000 has no eeprom, and it's MAC address is set by
304 * the bootloader before starting the kernel.
306 static struct dm9000_plat_data mini2440_dm9k_pdata = {
307 .flags = (DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM),
310 static struct platform_device mini2440_device_eth = {
313 .num_resources = ARRAY_SIZE(mini2440_dm9k_resource),
314 .resource = mini2440_dm9k_resource,
316 .platform_data = &mini2440_dm9k_pdata,
337 static struct gpio_keys_button mini2440_buttons[] = {
339 .gpio = S3C2410_GPG(0), /* K1 */
345 .gpio = S3C2410_GPG(3), /* K2 */
351 .gpio = S3C2410_GPG(5), /* K3 */
357 .gpio = S3C2410_GPG(6), /* K4 */
363 .gpio = S3C2410_GPG(7), /* K5 */
369 /* this pin is also known as TCLK1 and seems to already
370 * marked as "in use" somehow in the kernel -- possibly wrongly */
372 .gpio = S3C2410_GPG(11), /* K6 */
380 static struct gpio_keys_platform_data mini2440_button_data = {
381 .buttons = mini2440_buttons,
382 .nbuttons = ARRAY_SIZE(mini2440_buttons),
385 static struct platform_device mini2440_button_device = {
389 .platform_data = &mini2440_button_data,
395 static struct s3c24xx_led_platdata mini2440_led1_pdata = {
397 .gpio = S3C2410_GPB(5),
398 .flags = S3C24XX_LEDF_ACTLOW | S3C24XX_LEDF_TRISTATE,
399 .def_trigger = "heartbeat",
402 static struct s3c24xx_led_platdata mini2440_led2_pdata = {
404 .gpio = S3C2410_GPB(6),
405 .flags = S3C24XX_LEDF_ACTLOW | S3C24XX_LEDF_TRISTATE,
406 .def_trigger = "nand-disk",
409 static struct s3c24xx_led_platdata mini2440_led3_pdata = {
411 .gpio = S3C2410_GPB(7),
412 .flags = S3C24XX_LEDF_ACTLOW | S3C24XX_LEDF_TRISTATE,
413 .def_trigger = "mmc0",
416 static struct s3c24xx_led_platdata mini2440_led4_pdata = {
418 .gpio = S3C2410_GPB(8),
419 .flags = S3C24XX_LEDF_ACTLOW | S3C24XX_LEDF_TRISTATE,
423 static struct s3c24xx_led_platdata mini2440_led_backlight_pdata = {
425 .gpio = S3C2410_GPG(4),
426 .def_trigger = "backlight",
429 static struct platform_device mini2440_led1 = {
430 .name = "s3c24xx_led",
433 .platform_data = &mini2440_led1_pdata,
437 static struct platform_device mini2440_led2 = {
438 .name = "s3c24xx_led",
441 .platform_data = &mini2440_led2_pdata,
445 static struct platform_device mini2440_led3 = {
446 .name = "s3c24xx_led",
449 .platform_data = &mini2440_led3_pdata,
453 static struct platform_device mini2440_led4 = {
454 .name = "s3c24xx_led",
457 .platform_data = &mini2440_led4_pdata,
461 static struct platform_device mini2440_led_backlight = {
462 .name = "s3c24xx_led",
465 .platform_data = &mini2440_led_backlight_pdata,
471 static struct s3c24xx_uda134x_platform_data mini2440_audio_pins = {
472 .l3_clk = S3C2410_GPB(4),
473 .l3_mode = S3C2410_GPB(2),
474 .l3_data = S3C2410_GPB(3),
475 .model = UDA134X_UDA1341
478 static struct platform_device mini2440_audio = {
479 .name = "s3c24xx_uda134x",
482 .platform_data = &mini2440_audio_pins,
489 static struct at24_platform_data at24c08 = {
490 .byte_len = SZ_8K / 8,
494 static struct i2c_board_info mini2440_i2c_devs[] __initdata = {
496 I2C_BOARD_INFO("24c08", 0x50),
497 .platform_data = &at24c08,
501 static struct uda134x_platform_data s3c24xx_uda134x = {
503 .gpio_clk = S3C2410_GPB(4),
504 .gpio_data = S3C2410_GPB(3),
505 .gpio_mode = S3C2410_GPB(2),
514 .model = UDA134X_UDA1341,
517 static struct platform_device uda1340_codec = {
518 .name = "uda134x-codec",
521 .platform_data = &s3c24xx_uda134x,
525 static struct platform_device *mini2440_devices[] __initdata = {
530 &s3c_device_usbgadget,
531 &mini2440_device_eth,
536 &mini2440_button_device,
545 static void __init mini2440_map_io(void)
547 s3c24xx_init_io(mini2440_iodesc, ARRAY_SIZE(mini2440_iodesc));
548 s3c24xx_init_uarts(mini2440_uartcfgs, ARRAY_SIZE(mini2440_uartcfgs));
549 samsung_set_timer_source(SAMSUNG_PWM3, SAMSUNG_PWM4);
552 static void __init mini2440_init_time(void)
554 s3c2440_init_clocks(12000000);
555 samsung_timer_init();
559 * mini2440_features string
561 * t = Touchscreen present
562 * b = backlight control
564 * 0-9 LCD configuration
567 static char mini2440_features_str[12] __initdata = "0tb";
569 static int __init mini2440_features_setup(char *str)
572 strlcpy(mini2440_features_str, str, sizeof(mini2440_features_str));
576 __setup("mini2440=", mini2440_features_setup);
578 #define FEATURE_SCREEN (1 << 0)
579 #define FEATURE_BACKLIGHT (1 << 1)
580 #define FEATURE_TOUCH (1 << 2)
581 #define FEATURE_CAMERA (1 << 3)
583 struct mini2440_features_t {
587 struct platform_device *optional[8];
590 static void __init mini2440_parse_features(
591 struct mini2440_features_t * features,
592 const char * features_str )
594 const char * fp = features_str;
598 features->lcd_index = -1;
604 case '0'...'9': /* tft screen */
605 if (features->done & FEATURE_SCREEN) {
606 printk(KERN_INFO "MINI2440: '%c' ignored, "
607 "screen type already set\n", f);
610 if (li >= ARRAY_SIZE(mini2440_lcd_cfg))
611 printk(KERN_INFO "MINI2440: "
612 "'%c' out of range LCD mode\n", f);
614 features->optional[features->count++] =
616 features->lcd_index = li;
619 features->done |= FEATURE_SCREEN;
622 if (features->done & FEATURE_BACKLIGHT)
623 printk(KERN_INFO "MINI2440: '%c' ignored, "
624 "backlight already set\n", f);
626 features->optional[features->count++] =
627 &mini2440_led_backlight;
629 features->done |= FEATURE_BACKLIGHT;
632 printk(KERN_INFO "MINI2440: '%c' ignored, "
633 "touchscreen not compiled in\n", f);
636 if (features->done & FEATURE_CAMERA)
637 printk(KERN_INFO "MINI2440: '%c' ignored, "
638 "camera already registered\n", f);
640 features->optional[features->count++] =
642 features->done |= FEATURE_CAMERA;
648 static void __init mini2440_init(void)
650 struct mini2440_features_t features = { 0 };
653 printk(KERN_INFO "MINI2440: Option string mini2440=%s\n",
654 mini2440_features_str);
656 /* Parse the feature string */
657 mini2440_parse_features(&features, mini2440_features_str);
660 s3c_gpio_cfgpin(S3C2410_GPC(0), S3C2410_GPC0_LEND);
662 /* Turn the backlight early on */
663 WARN_ON(gpio_request_one(S3C2410_GPG(4), GPIOF_OUT_INIT_HIGH, NULL));
664 gpio_free(S3C2410_GPG(4));
666 /* remove pullup on optional PWM backlight -- unused on 3.5 and 7"s */
667 gpio_request_one(S3C2410_GPB(1), GPIOF_IN, NULL);
668 s3c_gpio_setpull(S3C2410_GPB(1), S3C_GPIO_PULL_UP);
669 gpio_free(S3C2410_GPB(1));
671 /* mark the key as input, without pullups (there is one on the board) */
672 for (i = 0; i < ARRAY_SIZE(mini2440_buttons); i++) {
673 s3c_gpio_setpull(mini2440_buttons[i].gpio, S3C_GPIO_PULL_UP);
674 s3c_gpio_cfgpin(mini2440_buttons[i].gpio, S3C2410_GPIO_INPUT);
676 if (features.lcd_index != -1) {
679 mini2440_fb_info.displays =
680 &mini2440_lcd_cfg[features.lcd_index];
682 printk(KERN_INFO "MINI2440: LCD");
683 for (li = 0; li < ARRAY_SIZE(mini2440_lcd_cfg); li++)
684 if (li == features.lcd_index)
685 printk(" [%d:%dx%d]", li,
686 mini2440_lcd_cfg[li].width,
687 mini2440_lcd_cfg[li].height);
689 printk(" %d:%dx%d", li,
690 mini2440_lcd_cfg[li].width,
691 mini2440_lcd_cfg[li].height);
693 s3c24xx_fb_set_platdata(&mini2440_fb_info);
696 s3c24xx_udc_set_platdata(&mini2440_udc_cfg);
697 s3c24xx_mci_set_platdata(&mini2440_mmc_cfg);
698 s3c_nand_set_platdata(&mini2440_nand_info);
699 s3c_i2c0_set_platdata(NULL);
701 i2c_register_board_info(0, mini2440_i2c_devs,
702 ARRAY_SIZE(mini2440_i2c_devs));
704 platform_add_devices(mini2440_devices, ARRAY_SIZE(mini2440_devices));
706 if (features.count) /* the optional features */
707 platform_add_devices(features.optional, features.count);
712 MACHINE_START(MINI2440, "MINI2440")
714 .atag_offset = 0x100,
715 .map_io = mini2440_map_io,
716 .init_machine = mini2440_init,
717 .init_irq = s3c2440_init_irq,
718 .init_time = mini2440_init_time,