1 // SPDX-License-Identifier: GPL-2.0
3 // Copyright (c) 2008 Ramax Lo <ramaxlo@gmail.com>
4 // Based on mach-anubis.c by Ben Dooks <ben@simtec.co.uk>
5 // and modifications by SBZ <sbz@spgui.org> and
6 // Weibing <http://weibing.blogbus.com> and
7 // Michel Pollet <buserror@gmail.com>
9 // For product information, visit http://code.google.com/p/mini2440/
11 #include <linux/kernel.h>
12 #include <linux/types.h>
13 #include <linux/interrupt.h>
14 #include <linux/list.h>
15 #include <linux/timer.h>
16 #include <linux/init.h>
17 #include <linux/gpio.h>
18 #include <linux/input.h>
20 #include <linux/serial_core.h>
21 #include <linux/serial_s3c.h>
22 #include <linux/dm9000.h>
23 #include <linux/property.h>
24 #include <linux/platform_device.h>
25 #include <linux/gpio_keys.h>
26 #include <linux/i2c.h>
27 #include <linux/mmc/host.h>
29 #include <asm/mach/arch.h>
30 #include <asm/mach/map.h>
32 #include <mach/hardware.h>
34 #include <asm/mach-types.h>
36 #include <mach/regs-gpio.h>
37 #include <linux/platform_data/leds-s3c24xx.h>
38 #include <mach/regs-lcd.h>
39 #include <mach/irqs.h>
40 #include <mach/gpio-samsung.h>
41 #include <linux/platform_data/mtd-nand-s3c2410.h>
42 #include <linux/platform_data/i2c-s3c2410.h>
43 #include <linux/platform_data/mmc-s3cmci.h>
44 #include <linux/platform_data/usb-s3c2410_udc.h>
46 #include <linux/mtd/mtd.h>
47 #include <linux/mtd/rawnand.h>
48 #include <linux/mtd/nand_ecc.h>
49 #include <linux/mtd/partitions.h>
51 #include <plat/gpio-cfg.h>
52 #include <plat/devs.h>
54 #include <plat/samsung-time.h>
56 #include <sound/s3c24xx_uda134x.h>
60 #define MACH_MINI2440_DM9K_BASE (S3C2410_CS4 + 0x300)
62 static struct map_desc mini2440_iodesc[] __initdata = {
63 /* nothing to declare, move along */
66 #define UCON S3C2410_UCON_DEFAULT
67 #define ULCON S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB
68 #define UFCON S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE
71 static struct s3c2410_uartcfg mini2440_uartcfgs[] __initdata = {
95 /* USB device UDC support */
97 static struct s3c2410_udc_mach_info mini2440_udc_cfg __initdata = {
98 .pullup_pin = S3C2410_GPC(5),
102 /* LCD timing and setup */
105 * This macro simplifies the table bellow
107 #define _LCD_DECLARE(_clock,_xres,margin_left,margin_right,hsync, \
108 _yres,margin_top,margin_bottom,vsync, refresh) \
113 .left_margin = margin_left, \
114 .right_margin = margin_right, \
115 .upper_margin = margin_top, \
116 .lower_margin = margin_bottom, \
117 .hsync_len = hsync, \
118 .vsync_len = vsync, \
119 .pixclock = ((_clock*100000000000LL) / \
121 (hsync + margin_left + _xres + margin_right) * \
122 (vsync + margin_top + _yres + margin_bottom))), \
124 .type = (S3C2410_LCDCON1_TFT16BPP |\
127 static struct s3c2410fb_display mini2440_lcd_cfg[] __initdata = {
128 [0] = { /* mini2440 + 3.5" TFT + touchscreen */
130 7, /* The 3.5 is quite fast */
131 240, 21, 38, 6, /* x timing */
132 320, 4, 4, 2, /* y timing */
133 60), /* refresh rate */
134 .lcdcon5 = (S3C2410_LCDCON5_FRM565 |
135 S3C2410_LCDCON5_INVVLINE |
136 S3C2410_LCDCON5_INVVFRAME |
137 S3C2410_LCDCON5_INVVDEN |
138 S3C2410_LCDCON5_PWREN),
140 [1] = { /* mini2440 + 7" TFT + touchscreen */
142 10, /* the 7" runs slower */
143 800, 40, 40, 48, /* x timing */
144 480, 29, 3, 3, /* y timing */
145 50), /* refresh rate */
146 .lcdcon5 = (S3C2410_LCDCON5_FRM565 |
147 S3C2410_LCDCON5_INVVLINE |
148 S3C2410_LCDCON5_INVVFRAME |
149 S3C2410_LCDCON5_PWREN),
151 /* The VGA shield can outout at several resolutions. All share
152 * the same timings, however, anything smaller than 1024x768
153 * will only be displayed in the top left corner of a 1024x768
154 * XGA output unless you add optional dip switches to the shield.
155 * Therefore timings for other resolutions have been omitted here.
160 1024, 1, 2, 2, /* y timing */
161 768, 200, 16, 16, /* x timing */
162 24), /* refresh rate, maximum stable,
163 tested with the FPGA shield */
164 .lcdcon5 = (S3C2410_LCDCON5_FRM565 |
165 S3C2410_LCDCON5_HWSWP),
167 /* mini2440 + 3.5" TFT (LCD-W35i, LQ035Q1DG06 type) + touchscreen*/
172 /* xres, margin_right, margin_left, hsync */
174 /* yres, margin_top, margin_bottom, vsync */
178 .lcdcon5 = (S3C2410_LCDCON5_FRM565 |
179 S3C2410_LCDCON5_INVVDEN |
180 S3C2410_LCDCON5_INVVFRAME |
181 S3C2410_LCDCON5_INVVLINE |
182 S3C2410_LCDCON5_INVVCLK |
183 S3C2410_LCDCON5_HWSWP),
187 /* todo - put into gpio header */
189 #define S3C2410_GPCCON_MASK(x) (3 << ((x) * 2))
190 #define S3C2410_GPDCON_MASK(x) (3 << ((x) * 2))
192 static struct s3c2410fb_mach_info mini2440_fb_info __initdata = {
193 .displays = &mini2440_lcd_cfg[0], /* not constant! see init */
195 .default_display = 0,
197 /* Enable VD[2..7], VD[10..15], VD[18..23] and VCLK, syncs, VDEN
198 * and disable the pull down resistors on pins we are using for LCD
201 .gpcup = (0xf << 1) | (0x3f << 10),
203 .gpccon = (S3C2410_GPC1_VCLK | S3C2410_GPC2_VLINE |
204 S3C2410_GPC3_VFRAME | S3C2410_GPC4_VM |
205 S3C2410_GPC10_VD2 | S3C2410_GPC11_VD3 |
206 S3C2410_GPC12_VD4 | S3C2410_GPC13_VD5 |
207 S3C2410_GPC14_VD6 | S3C2410_GPC15_VD7),
209 .gpccon_mask = (S3C2410_GPCCON_MASK(1) | S3C2410_GPCCON_MASK(2) |
210 S3C2410_GPCCON_MASK(3) | S3C2410_GPCCON_MASK(4) |
211 S3C2410_GPCCON_MASK(10) | S3C2410_GPCCON_MASK(11) |
212 S3C2410_GPCCON_MASK(12) | S3C2410_GPCCON_MASK(13) |
213 S3C2410_GPCCON_MASK(14) | S3C2410_GPCCON_MASK(15)),
215 .gpdup = (0x3f << 2) | (0x3f << 10),
217 .gpdcon = (S3C2410_GPD2_VD10 | S3C2410_GPD3_VD11 |
218 S3C2410_GPD4_VD12 | S3C2410_GPD5_VD13 |
219 S3C2410_GPD6_VD14 | S3C2410_GPD7_VD15 |
220 S3C2410_GPD10_VD18 | S3C2410_GPD11_VD19 |
221 S3C2410_GPD12_VD20 | S3C2410_GPD13_VD21 |
222 S3C2410_GPD14_VD22 | S3C2410_GPD15_VD23),
224 .gpdcon_mask = (S3C2410_GPDCON_MASK(2) | S3C2410_GPDCON_MASK(3) |
225 S3C2410_GPDCON_MASK(4) | S3C2410_GPDCON_MASK(5) |
226 S3C2410_GPDCON_MASK(6) | S3C2410_GPDCON_MASK(7) |
227 S3C2410_GPDCON_MASK(10) | S3C2410_GPDCON_MASK(11)|
228 S3C2410_GPDCON_MASK(12) | S3C2410_GPDCON_MASK(13)|
229 S3C2410_GPDCON_MASK(14) | S3C2410_GPDCON_MASK(15)),
234 static struct s3c24xx_mci_pdata mini2440_mmc_cfg __initdata = {
235 .gpio_detect = S3C2410_GPG(8),
236 .gpio_wprotect = S3C2410_GPH(8),
238 .ocr_avail = MMC_VDD_32_33|MMC_VDD_33_34,
241 /* NAND Flash on MINI2440 board */
243 static struct mtd_partition mini2440_default_nand_part[] __initdata = {
250 .name = "u-boot-env",
256 /* 5 megabytes, for a kernel with no modules
257 * or a uImage with a ramdisk attached */
259 .offset = SZ_256K + SZ_128K,
263 .offset = SZ_256K + SZ_128K + 0x00500000,
264 .size = MTDPART_SIZ_FULL,
268 static struct s3c2410_nand_set mini2440_nand_sets[] __initdata = {
272 .nr_partitions = ARRAY_SIZE(mini2440_default_nand_part),
273 .partitions = mini2440_default_nand_part,
274 .flash_bbt = 1, /* we use u-boot to create a BBT */
278 static struct s3c2410_platform_nand mini2440_nand_info __initdata = {
282 .nr_sets = ARRAY_SIZE(mini2440_nand_sets),
283 .sets = mini2440_nand_sets,
284 .ignore_unset_ecc = 1,
285 .ecc_mode = NAND_ECC_HW,
288 /* DM9000AEP 10/100 ethernet controller */
290 static struct resource mini2440_dm9k_resource[] = {
291 [0] = DEFINE_RES_MEM(MACH_MINI2440_DM9K_BASE, 4),
292 [1] = DEFINE_RES_MEM(MACH_MINI2440_DM9K_BASE + 4, 4),
293 [2] = DEFINE_RES_NAMED(IRQ_EINT7, 1, NULL, IORESOURCE_IRQ \
294 | IORESOURCE_IRQ_HIGHEDGE),
298 * The DM9000 has no eeprom, and it's MAC address is set by
299 * the bootloader before starting the kernel.
301 static struct dm9000_plat_data mini2440_dm9k_pdata = {
302 .flags = (DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM),
305 static struct platform_device mini2440_device_eth = {
308 .num_resources = ARRAY_SIZE(mini2440_dm9k_resource),
309 .resource = mini2440_dm9k_resource,
311 .platform_data = &mini2440_dm9k_pdata,
332 static struct gpio_keys_button mini2440_buttons[] = {
334 .gpio = S3C2410_GPG(0), /* K1 */
340 .gpio = S3C2410_GPG(3), /* K2 */
346 .gpio = S3C2410_GPG(5), /* K3 */
352 .gpio = S3C2410_GPG(6), /* K4 */
358 .gpio = S3C2410_GPG(7), /* K5 */
364 /* this pin is also known as TCLK1 and seems to already
365 * marked as "in use" somehow in the kernel -- possibly wrongly */
367 .gpio = S3C2410_GPG(11), /* K6 */
375 static struct gpio_keys_platform_data mini2440_button_data = {
376 .buttons = mini2440_buttons,
377 .nbuttons = ARRAY_SIZE(mini2440_buttons),
380 static struct platform_device mini2440_button_device = {
384 .platform_data = &mini2440_button_data,
390 static struct s3c24xx_led_platdata mini2440_led1_pdata = {
392 .gpio = S3C2410_GPB(5),
393 .flags = S3C24XX_LEDF_ACTLOW | S3C24XX_LEDF_TRISTATE,
394 .def_trigger = "heartbeat",
397 static struct s3c24xx_led_platdata mini2440_led2_pdata = {
399 .gpio = S3C2410_GPB(6),
400 .flags = S3C24XX_LEDF_ACTLOW | S3C24XX_LEDF_TRISTATE,
401 .def_trigger = "nand-disk",
404 static struct s3c24xx_led_platdata mini2440_led3_pdata = {
406 .gpio = S3C2410_GPB(7),
407 .flags = S3C24XX_LEDF_ACTLOW | S3C24XX_LEDF_TRISTATE,
408 .def_trigger = "mmc0",
411 static struct s3c24xx_led_platdata mini2440_led4_pdata = {
413 .gpio = S3C2410_GPB(8),
414 .flags = S3C24XX_LEDF_ACTLOW | S3C24XX_LEDF_TRISTATE,
418 static struct s3c24xx_led_platdata mini2440_led_backlight_pdata = {
420 .gpio = S3C2410_GPG(4),
421 .def_trigger = "backlight",
424 static struct platform_device mini2440_led1 = {
425 .name = "s3c24xx_led",
428 .platform_data = &mini2440_led1_pdata,
432 static struct platform_device mini2440_led2 = {
433 .name = "s3c24xx_led",
436 .platform_data = &mini2440_led2_pdata,
440 static struct platform_device mini2440_led3 = {
441 .name = "s3c24xx_led",
444 .platform_data = &mini2440_led3_pdata,
448 static struct platform_device mini2440_led4 = {
449 .name = "s3c24xx_led",
452 .platform_data = &mini2440_led4_pdata,
456 static struct platform_device mini2440_led_backlight = {
457 .name = "s3c24xx_led",
460 .platform_data = &mini2440_led_backlight_pdata,
466 static struct s3c24xx_uda134x_platform_data mini2440_audio_pins = {
467 .l3_clk = S3C2410_GPB(4),
468 .l3_mode = S3C2410_GPB(2),
469 .l3_data = S3C2410_GPB(3),
470 .model = UDA134X_UDA1341
473 static struct platform_device mini2440_audio = {
474 .name = "s3c24xx_uda134x",
477 .platform_data = &mini2440_audio_pins,
484 static const struct property_entry mini2440_at24_properties[] = {
485 PROPERTY_ENTRY_U32("pagesize", 16),
489 static struct i2c_board_info mini2440_i2c_devs[] __initdata = {
491 I2C_BOARD_INFO("24c08", 0x50),
492 .properties = mini2440_at24_properties,
496 static struct uda134x_platform_data s3c24xx_uda134x = {
498 .gpio_clk = S3C2410_GPB(4),
499 .gpio_data = S3C2410_GPB(3),
500 .gpio_mode = S3C2410_GPB(2),
509 .model = UDA134X_UDA1341,
512 static struct platform_device uda1340_codec = {
513 .name = "uda134x-codec",
516 .platform_data = &s3c24xx_uda134x,
520 static struct platform_device *mini2440_devices[] __initdata = {
525 &s3c_device_usbgadget,
526 &mini2440_device_eth,
531 &mini2440_button_device,
540 static void __init mini2440_map_io(void)
542 s3c24xx_init_io(mini2440_iodesc, ARRAY_SIZE(mini2440_iodesc));
543 s3c24xx_init_uarts(mini2440_uartcfgs, ARRAY_SIZE(mini2440_uartcfgs));
544 samsung_set_timer_source(SAMSUNG_PWM3, SAMSUNG_PWM4);
547 static void __init mini2440_init_time(void)
549 s3c2440_init_clocks(12000000);
550 samsung_timer_init();
554 * mini2440_features string
556 * t = Touchscreen present
557 * b = backlight control
559 * 0-9 LCD configuration
562 static char mini2440_features_str[12] __initdata = "0tb";
564 static int __init mini2440_features_setup(char *str)
567 strlcpy(mini2440_features_str, str, sizeof(mini2440_features_str));
571 __setup("mini2440=", mini2440_features_setup);
573 #define FEATURE_SCREEN (1 << 0)
574 #define FEATURE_BACKLIGHT (1 << 1)
575 #define FEATURE_TOUCH (1 << 2)
576 #define FEATURE_CAMERA (1 << 3)
578 struct mini2440_features_t {
582 struct platform_device *optional[8];
585 static void __init mini2440_parse_features(
586 struct mini2440_features_t * features,
587 const char * features_str )
589 const char * fp = features_str;
593 features->lcd_index = -1;
599 case '0'...'9': /* tft screen */
600 if (features->done & FEATURE_SCREEN) {
601 printk(KERN_INFO "MINI2440: '%c' ignored, "
602 "screen type already set\n", f);
605 if (li >= ARRAY_SIZE(mini2440_lcd_cfg))
606 printk(KERN_INFO "MINI2440: "
607 "'%c' out of range LCD mode\n", f);
609 features->optional[features->count++] =
611 features->lcd_index = li;
614 features->done |= FEATURE_SCREEN;
617 if (features->done & FEATURE_BACKLIGHT)
618 printk(KERN_INFO "MINI2440: '%c' ignored, "
619 "backlight already set\n", f);
621 features->optional[features->count++] =
622 &mini2440_led_backlight;
624 features->done |= FEATURE_BACKLIGHT;
627 printk(KERN_INFO "MINI2440: '%c' ignored, "
628 "touchscreen not compiled in\n", f);
631 if (features->done & FEATURE_CAMERA)
632 printk(KERN_INFO "MINI2440: '%c' ignored, "
633 "camera already registered\n", f);
635 features->optional[features->count++] =
637 features->done |= FEATURE_CAMERA;
643 static void __init mini2440_init(void)
645 struct mini2440_features_t features = { 0 };
648 printk(KERN_INFO "MINI2440: Option string mini2440=%s\n",
649 mini2440_features_str);
651 /* Parse the feature string */
652 mini2440_parse_features(&features, mini2440_features_str);
655 s3c_gpio_cfgpin(S3C2410_GPC(0), S3C2410_GPC0_LEND);
657 /* Turn the backlight early on */
658 WARN_ON(gpio_request_one(S3C2410_GPG(4), GPIOF_OUT_INIT_HIGH, NULL));
659 gpio_free(S3C2410_GPG(4));
661 /* remove pullup on optional PWM backlight -- unused on 3.5 and 7"s */
662 gpio_request_one(S3C2410_GPB(1), GPIOF_IN, NULL);
663 s3c_gpio_setpull(S3C2410_GPB(1), S3C_GPIO_PULL_UP);
664 gpio_free(S3C2410_GPB(1));
666 /* mark the key as input, without pullups (there is one on the board) */
667 for (i = 0; i < ARRAY_SIZE(mini2440_buttons); i++) {
668 s3c_gpio_setpull(mini2440_buttons[i].gpio, S3C_GPIO_PULL_UP);
669 s3c_gpio_cfgpin(mini2440_buttons[i].gpio, S3C2410_GPIO_INPUT);
671 if (features.lcd_index != -1) {
674 mini2440_fb_info.displays =
675 &mini2440_lcd_cfg[features.lcd_index];
677 printk(KERN_INFO "MINI2440: LCD");
678 for (li = 0; li < ARRAY_SIZE(mini2440_lcd_cfg); li++)
679 if (li == features.lcd_index)
680 printk(" [%d:%dx%d]", li,
681 mini2440_lcd_cfg[li].width,
682 mini2440_lcd_cfg[li].height);
684 printk(" %d:%dx%d", li,
685 mini2440_lcd_cfg[li].width,
686 mini2440_lcd_cfg[li].height);
688 s3c24xx_fb_set_platdata(&mini2440_fb_info);
691 s3c24xx_udc_set_platdata(&mini2440_udc_cfg);
692 s3c24xx_mci_set_platdata(&mini2440_mmc_cfg);
693 s3c_nand_set_platdata(&mini2440_nand_info);
694 s3c_i2c0_set_platdata(NULL);
696 i2c_register_board_info(0, mini2440_i2c_devs,
697 ARRAY_SIZE(mini2440_i2c_devs));
699 platform_add_devices(mini2440_devices, ARRAY_SIZE(mini2440_devices));
701 if (features.count) /* the optional features */
702 platform_add_devices(features.optional, features.count);
707 MACHINE_START(MINI2440, "MINI2440")
708 /* Maintainer: Michel Pollet <buserror@gmail.com> */
709 .atag_offset = 0x100,
710 .map_io = mini2440_map_io,
711 .init_machine = mini2440_init,
712 .init_irq = s3c2440_init_irq,
713 .init_time = mini2440_init_time,