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/gpio/machine.h>
19 #include <linux/input.h>
21 #include <linux/serial_core.h>
22 #include <linux/serial_s3c.h>
23 #include <linux/dm9000.h>
24 #include <linux/property.h>
25 #include <linux/platform_device.h>
26 #include <linux/gpio_keys.h>
27 #include <linux/i2c.h>
28 #include <linux/mmc/host.h>
30 #include <asm/mach/arch.h>
31 #include <asm/mach/map.h>
33 #include <mach/hardware.h>
35 #include <asm/mach-types.h>
37 #include <mach/regs-gpio.h>
38 #include <linux/platform_data/leds-s3c24xx.h>
39 #include <mach/regs-lcd.h>
40 #include <mach/irqs.h>
41 #include <mach/gpio-samsung.h>
42 #include <linux/platform_data/mtd-nand-s3c2410.h>
43 #include <linux/platform_data/i2c-s3c2410.h>
44 #include <linux/platform_data/mmc-s3cmci.h>
45 #include <linux/platform_data/usb-s3c2410_udc.h>
47 #include <linux/mtd/mtd.h>
48 #include <linux/mtd/rawnand.h>
49 #include <linux/mtd/nand_ecc.h>
50 #include <linux/mtd/partitions.h>
52 #include <plat/gpio-cfg.h>
53 #include <plat/devs.h>
55 #include <plat/samsung-time.h>
57 #include <sound/s3c24xx_uda134x.h>
61 #define MACH_MINI2440_DM9K_BASE (S3C2410_CS4 + 0x300)
63 static struct map_desc mini2440_iodesc
[] __initdata
= {
64 /* nothing to declare, move along */
67 #define UCON S3C2410_UCON_DEFAULT
68 #define ULCON (S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB)
69 #define UFCON (S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE)
72 static struct s3c2410_uartcfg mini2440_uartcfgs
[] __initdata
= {
96 /* USB device UDC support */
98 static struct s3c2410_udc_mach_info mini2440_udc_cfg __initdata
= {
99 .pullup_pin
= S3C2410_GPC(5),
103 /* LCD timing and setup */
106 * This macro simplifies the table bellow
108 #define _LCD_DECLARE(_clock, _xres, margin_left, margin_right, hsync, \
109 _yres, margin_top, margin_bottom, vsync, refresh) \
114 .left_margin = margin_left, \
115 .right_margin = margin_right, \
116 .upper_margin = margin_top, \
117 .lower_margin = margin_bottom, \
118 .hsync_len = hsync, \
119 .vsync_len = vsync, \
120 .pixclock = ((_clock*100000000000LL) / \
122 (hsync + margin_left + _xres + margin_right) * \
123 (vsync + margin_top + _yres + margin_bottom))), \
125 .type = (S3C2410_LCDCON1_TFT16BPP |\
128 static struct s3c2410fb_display mini2440_lcd_cfg
[] __initdata
= {
129 [0] = { /* mini2440 + 3.5" TFT + touchscreen */
131 7, /* The 3.5 is quite fast */
132 240, 21, 38, 6, /* x timing */
133 320, 4, 4, 2, /* y timing */
134 60), /* refresh rate */
135 .lcdcon5
= (S3C2410_LCDCON5_FRM565
|
136 S3C2410_LCDCON5_INVVLINE
|
137 S3C2410_LCDCON5_INVVFRAME
|
138 S3C2410_LCDCON5_INVVDEN
|
139 S3C2410_LCDCON5_PWREN
),
141 [1] = { /* mini2440 + 7" TFT + touchscreen */
143 10, /* the 7" runs slower */
144 800, 40, 40, 48, /* x timing */
145 480, 29, 3, 3, /* y timing */
146 50), /* refresh rate */
147 .lcdcon5
= (S3C2410_LCDCON5_FRM565
|
148 S3C2410_LCDCON5_INVVLINE
|
149 S3C2410_LCDCON5_INVVFRAME
|
150 S3C2410_LCDCON5_PWREN
),
152 /* The VGA shield can outout at several resolutions. All share
153 * the same timings, however, anything smaller than 1024x768
154 * will only be displayed in the top left corner of a 1024x768
155 * XGA output unless you add optional dip switches to the shield.
156 * Therefore timings for other resolutions have been omitted here.
161 1024, 1, 2, 2, /* y timing */
162 768, 200, 16, 16, /* x timing */
163 24), /* refresh rate, maximum stable,
164 * tested with the FPGA shield
166 .lcdcon5
= (S3C2410_LCDCON5_FRM565
|
167 S3C2410_LCDCON5_HWSWP
),
169 /* mini2440 + 3.5" TFT (LCD-W35i, LQ035Q1DG06 type) + touchscreen*/
174 /* xres, margin_right, margin_left, hsync */
176 /* yres, margin_top, margin_bottom, vsync */
180 .lcdcon5
= (S3C2410_LCDCON5_FRM565
|
181 S3C2410_LCDCON5_INVVDEN
|
182 S3C2410_LCDCON5_INVVFRAME
|
183 S3C2410_LCDCON5_INVVLINE
|
184 S3C2410_LCDCON5_INVVCLK
|
185 S3C2410_LCDCON5_HWSWP
),
189 /* todo - put into gpio header */
191 #define S3C2410_GPCCON_MASK(x) (3 << ((x) * 2))
192 #define S3C2410_GPDCON_MASK(x) (3 << ((x) * 2))
194 static struct s3c2410fb_mach_info mini2440_fb_info __initdata
= {
195 .displays
= &mini2440_lcd_cfg
[0], /* not constant! see init */
197 .default_display
= 0,
199 /* Enable VD[2..7], VD[10..15], VD[18..23] and VCLK, syncs, VDEN
200 * and disable the pull down resistors on pins we are using for LCD
204 .gpcup
= (0xf << 1) | (0x3f << 10),
206 .gpccon
= (S3C2410_GPC1_VCLK
| S3C2410_GPC2_VLINE
|
207 S3C2410_GPC3_VFRAME
| S3C2410_GPC4_VM
|
208 S3C2410_GPC10_VD2
| S3C2410_GPC11_VD3
|
209 S3C2410_GPC12_VD4
| S3C2410_GPC13_VD5
|
210 S3C2410_GPC14_VD6
| S3C2410_GPC15_VD7
),
212 .gpccon_mask
= (S3C2410_GPCCON_MASK(1) | S3C2410_GPCCON_MASK(2) |
213 S3C2410_GPCCON_MASK(3) | S3C2410_GPCCON_MASK(4) |
214 S3C2410_GPCCON_MASK(10) | S3C2410_GPCCON_MASK(11) |
215 S3C2410_GPCCON_MASK(12) | S3C2410_GPCCON_MASK(13) |
216 S3C2410_GPCCON_MASK(14) | S3C2410_GPCCON_MASK(15)),
218 .gpdup
= (0x3f << 2) | (0x3f << 10),
220 .gpdcon
= (S3C2410_GPD2_VD10
| S3C2410_GPD3_VD11
|
221 S3C2410_GPD4_VD12
| S3C2410_GPD5_VD13
|
222 S3C2410_GPD6_VD14
| S3C2410_GPD7_VD15
|
223 S3C2410_GPD10_VD18
| S3C2410_GPD11_VD19
|
224 S3C2410_GPD12_VD20
| S3C2410_GPD13_VD21
|
225 S3C2410_GPD14_VD22
| S3C2410_GPD15_VD23
),
227 .gpdcon_mask
= (S3C2410_GPDCON_MASK(2) | S3C2410_GPDCON_MASK(3) |
228 S3C2410_GPDCON_MASK(4) | S3C2410_GPDCON_MASK(5) |
229 S3C2410_GPDCON_MASK(6) | S3C2410_GPDCON_MASK(7) |
230 S3C2410_GPDCON_MASK(10) | S3C2410_GPDCON_MASK(11)|
231 S3C2410_GPDCON_MASK(12) | S3C2410_GPDCON_MASK(13)|
232 S3C2410_GPDCON_MASK(14) | S3C2410_GPDCON_MASK(15)),
237 static struct s3c24xx_mci_pdata mini2440_mmc_cfg __initdata
= {
238 .wprotect_invert
= 1,
240 .ocr_avail
= MMC_VDD_32_33
|MMC_VDD_33_34
,
243 static struct gpiod_lookup_table mini2440_mmc_gpio_table
= {
244 .dev_id
= "s3c2410-sdi",
246 /* Card detect S3C2410_GPG(8) */
247 GPIO_LOOKUP("GPG", 8, "cd", GPIO_ACTIVE_LOW
),
248 /* Write protect S3C2410_GPH(8) */
249 GPIO_LOOKUP("GPH", 8, "wp", GPIO_ACTIVE_HIGH
),
254 /* NAND Flash on MINI2440 board */
256 static struct mtd_partition mini2440_default_nand_part
[] __initdata
= {
263 .name
= "u-boot-env",
269 /* 5 megabytes, for a kernel with no modules
270 * or a uImage with a ramdisk attached
273 .offset
= SZ_256K
+ SZ_128K
,
277 .offset
= SZ_256K
+ SZ_128K
+ 0x00500000,
278 .size
= MTDPART_SIZ_FULL
,
282 static struct s3c2410_nand_set mini2440_nand_sets
[] __initdata
= {
286 .nr_partitions
= ARRAY_SIZE(mini2440_default_nand_part
),
287 .partitions
= mini2440_default_nand_part
,
288 .flash_bbt
= 1, /* we use u-boot to create a BBT */
292 static struct s3c2410_platform_nand mini2440_nand_info __initdata
= {
296 .nr_sets
= ARRAY_SIZE(mini2440_nand_sets
),
297 .sets
= mini2440_nand_sets
,
298 .ignore_unset_ecc
= 1,
299 .ecc_mode
= NAND_ECC_HW
,
302 /* DM9000AEP 10/100 ethernet controller */
304 static struct resource mini2440_dm9k_resource
[] = {
305 [0] = DEFINE_RES_MEM(MACH_MINI2440_DM9K_BASE
, 4),
306 [1] = DEFINE_RES_MEM(MACH_MINI2440_DM9K_BASE
+ 4, 4),
307 [2] = DEFINE_RES_NAMED(IRQ_EINT7
, 1, NULL
, IORESOURCE_IRQ
308 | IORESOURCE_IRQ_HIGHEDGE
),
312 * The DM9000 has no eeprom, and it's MAC address is set by
313 * the bootloader before starting the kernel.
315 static struct dm9000_plat_data mini2440_dm9k_pdata
= {
316 .flags
= (DM9000_PLATF_16BITONLY
| DM9000_PLATF_NO_EEPROM
),
319 static struct platform_device mini2440_device_eth
= {
322 .num_resources
= ARRAY_SIZE(mini2440_dm9k_resource
),
323 .resource
= mini2440_dm9k_resource
,
325 .platform_data
= &mini2440_dm9k_pdata
,
346 static struct gpio_keys_button mini2440_buttons
[] = {
348 .gpio
= S3C2410_GPG(0), /* K1 */
354 .gpio
= S3C2410_GPG(3), /* K2 */
360 .gpio
= S3C2410_GPG(5), /* K3 */
366 .gpio
= S3C2410_GPG(6), /* K4 */
372 .gpio
= S3C2410_GPG(7), /* K5 */
378 /* this pin is also known as TCLK1 and seems to already
379 * marked as "in use" somehow in the kernel -- possibly wrongly
382 .gpio
= S3C2410_GPG(11), /* K6 */
390 static struct gpio_keys_platform_data mini2440_button_data
= {
391 .buttons
= mini2440_buttons
,
392 .nbuttons
= ARRAY_SIZE(mini2440_buttons
),
395 static struct platform_device mini2440_button_device
= {
399 .platform_data
= &mini2440_button_data
,
405 static struct s3c24xx_led_platdata mini2440_led1_pdata
= {
407 .gpio
= S3C2410_GPB(5),
408 .flags
= S3C24XX_LEDF_ACTLOW
| S3C24XX_LEDF_TRISTATE
,
409 .def_trigger
= "heartbeat",
412 static struct s3c24xx_led_platdata mini2440_led2_pdata
= {
414 .gpio
= S3C2410_GPB(6),
415 .flags
= S3C24XX_LEDF_ACTLOW
| S3C24XX_LEDF_TRISTATE
,
416 .def_trigger
= "nand-disk",
419 static struct s3c24xx_led_platdata mini2440_led3_pdata
= {
421 .gpio
= S3C2410_GPB(7),
422 .flags
= S3C24XX_LEDF_ACTLOW
| S3C24XX_LEDF_TRISTATE
,
423 .def_trigger
= "mmc0",
426 static struct s3c24xx_led_platdata mini2440_led4_pdata
= {
428 .gpio
= S3C2410_GPB(8),
429 .flags
= S3C24XX_LEDF_ACTLOW
| S3C24XX_LEDF_TRISTATE
,
433 static struct s3c24xx_led_platdata mini2440_led_backlight_pdata
= {
435 .gpio
= S3C2410_GPG(4),
436 .def_trigger
= "backlight",
439 static struct platform_device mini2440_led1
= {
440 .name
= "s3c24xx_led",
443 .platform_data
= &mini2440_led1_pdata
,
447 static struct platform_device mini2440_led2
= {
448 .name
= "s3c24xx_led",
451 .platform_data
= &mini2440_led2_pdata
,
455 static struct platform_device mini2440_led3
= {
456 .name
= "s3c24xx_led",
459 .platform_data
= &mini2440_led3_pdata
,
463 static struct platform_device mini2440_led4
= {
464 .name
= "s3c24xx_led",
467 .platform_data
= &mini2440_led4_pdata
,
471 static struct platform_device mini2440_led_backlight
= {
472 .name
= "s3c24xx_led",
475 .platform_data
= &mini2440_led_backlight_pdata
,
481 static struct s3c24xx_uda134x_platform_data mini2440_audio_pins
= {
482 .l3_clk
= S3C2410_GPB(4),
483 .l3_mode
= S3C2410_GPB(2),
484 .l3_data
= S3C2410_GPB(3),
485 .model
= UDA134X_UDA1341
488 static struct platform_device mini2440_audio
= {
489 .name
= "s3c24xx_uda134x",
492 .platform_data
= &mini2440_audio_pins
,
499 static const struct property_entry mini2440_at24_properties
[] = {
500 PROPERTY_ENTRY_U32("pagesize", 16),
504 static struct i2c_board_info mini2440_i2c_devs
[] __initdata
= {
506 I2C_BOARD_INFO("24c08", 0x50),
507 .properties
= mini2440_at24_properties
,
511 static struct uda134x_platform_data s3c24xx_uda134x
= {
513 .gpio_clk
= S3C2410_GPB(4),
514 .gpio_data
= S3C2410_GPB(3),
515 .gpio_mode
= S3C2410_GPB(2),
524 .model
= UDA134X_UDA1341
,
527 static struct platform_device uda1340_codec
= {
528 .name
= "uda134x-codec",
531 .platform_data
= &s3c24xx_uda134x
,
535 static struct platform_device
*mini2440_devices
[] __initdata
= {
540 &s3c_device_usbgadget
,
541 &mini2440_device_eth
,
546 &mini2440_button_device
,
555 static void __init
mini2440_map_io(void)
557 s3c24xx_init_io(mini2440_iodesc
, ARRAY_SIZE(mini2440_iodesc
));
558 s3c24xx_init_uarts(mini2440_uartcfgs
, ARRAY_SIZE(mini2440_uartcfgs
));
559 samsung_set_timer_source(SAMSUNG_PWM3
, SAMSUNG_PWM4
);
562 static void __init
mini2440_init_time(void)
564 s3c2440_init_clocks(12000000);
565 samsung_timer_init();
569 * mini2440_features string
571 * t = Touchscreen present
572 * b = backlight control
574 * 0-9 LCD configuration
577 static char mini2440_features_str
[12] __initdata
= "0tb";
579 static int __init
mini2440_features_setup(char *str
)
582 strlcpy(mini2440_features_str
, str
,
583 sizeof(mini2440_features_str
));
587 __setup("mini2440=", mini2440_features_setup
);
589 #define FEATURE_SCREEN (1 << 0)
590 #define FEATURE_BACKLIGHT (1 << 1)
591 #define FEATURE_TOUCH (1 << 2)
592 #define FEATURE_CAMERA (1 << 3)
594 struct mini2440_features_t
{
598 struct platform_device
*optional
[8];
601 static void __init
mini2440_parse_features(
602 struct mini2440_features_t
*features
,
603 const char *features_str
)
605 const char *fp
= features_str
;
609 features
->lcd_index
= -1;
615 case '0'...'9': /* tft screen */
616 if (features
->done
& FEATURE_SCREEN
) {
617 pr_info("MINI2440: '%c' ignored, screen type already set\n",
622 if (li
>= ARRAY_SIZE(mini2440_lcd_cfg
))
623 pr_info("MINI2440: '%c' out of range LCD mode\n",
626 features
->optional
[features
->count
++] =
628 features
->lcd_index
= li
;
631 features
->done
|= FEATURE_SCREEN
;
634 if (features
->done
& FEATURE_BACKLIGHT
)
635 pr_info("MINI2440: '%c' ignored, backlight already set\n",
638 features
->optional
[features
->count
++] =
639 &mini2440_led_backlight
;
641 features
->done
|= FEATURE_BACKLIGHT
;
644 pr_info("MINI2440: '%c' ignored, touchscreen not compiled in\n",
648 if (features
->done
& FEATURE_CAMERA
)
649 pr_info("MINI2440: '%c' ignored, camera already registered\n",
652 features
->optional
[features
->count
++] =
654 features
->done
|= FEATURE_CAMERA
;
660 static void __init
mini2440_init(void)
662 struct mini2440_features_t features
= { 0 };
665 pr_info("MINI2440: Option string mini2440=%s\n",
666 mini2440_features_str
);
668 /* Parse the feature string */
669 mini2440_parse_features(&features
, mini2440_features_str
);
672 s3c_gpio_cfgpin(S3C2410_GPC(0), S3C2410_GPC0_LEND
);
674 /* Turn the backlight early on */
675 WARN_ON(gpio_request_one(S3C2410_GPG(4), GPIOF_OUT_INIT_HIGH
, NULL
));
676 gpio_free(S3C2410_GPG(4));
678 /* remove pullup on optional PWM backlight -- unused on 3.5 and 7"s */
679 gpio_request_one(S3C2410_GPB(1), GPIOF_IN
, NULL
);
680 s3c_gpio_setpull(S3C2410_GPB(1), S3C_GPIO_PULL_UP
);
681 gpio_free(S3C2410_GPB(1));
683 /* mark the key as input, without pullups (there is one on the board) */
684 for (i
= 0; i
< ARRAY_SIZE(mini2440_buttons
); i
++) {
685 s3c_gpio_setpull(mini2440_buttons
[i
].gpio
, S3C_GPIO_PULL_UP
);
686 s3c_gpio_cfgpin(mini2440_buttons
[i
].gpio
, S3C2410_GPIO_INPUT
);
688 if (features
.lcd_index
!= -1) {
691 mini2440_fb_info
.displays
=
692 &mini2440_lcd_cfg
[features
.lcd_index
];
694 pr_info("MINI2440: LCD");
695 for (li
= 0; li
< ARRAY_SIZE(mini2440_lcd_cfg
); li
++)
696 if (li
== features
.lcd_index
)
697 pr_cont(" [%d:%dx%d]", li
,
698 mini2440_lcd_cfg
[li
].width
,
699 mini2440_lcd_cfg
[li
].height
);
701 pr_cont(" %d:%dx%d", li
,
702 mini2440_lcd_cfg
[li
].width
,
703 mini2440_lcd_cfg
[li
].height
);
705 s3c24xx_fb_set_platdata(&mini2440_fb_info
);
708 s3c24xx_udc_set_platdata(&mini2440_udc_cfg
);
709 gpiod_add_lookup_table(&mini2440_mmc_gpio_table
);
710 s3c24xx_mci_set_platdata(&mini2440_mmc_cfg
);
711 s3c_nand_set_platdata(&mini2440_nand_info
);
712 s3c_i2c0_set_platdata(NULL
);
714 i2c_register_board_info(0, mini2440_i2c_devs
,
715 ARRAY_SIZE(mini2440_i2c_devs
));
717 platform_add_devices(mini2440_devices
, ARRAY_SIZE(mini2440_devices
));
719 if (features
.count
) /* the optional features */
720 platform_add_devices(features
.optional
, features
.count
);
725 MACHINE_START(MINI2440
, "MINI2440")
726 /* Maintainer: Michel Pollet <buserror@gmail.com> */
727 .atag_offset
= 0x100,
728 .map_io
= mini2440_map_io
,
729 .init_machine
= mini2440_init
,
730 .init_irq
= s3c2440_init_irq
,
731 .init_time
= mini2440_init_time
,