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 https://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 <linux/platform_data/fb-s3c2410.h>
34 #include <asm/mach-types.h>
36 #include "regs-gpio.h"
37 #include <linux/platform_data/leds-s3c24xx.h>
39 #include "gpio-samsung.h"
40 #include <linux/platform_data/mtd-nand-s3c2410.h>
41 #include <linux/platform_data/i2c-s3c2410.h>
42 #include <linux/platform_data/mmc-s3cmci.h>
43 #include <linux/platform_data/usb-s3c2410_udc.h>
45 #include <linux/mtd/mtd.h>
46 #include <linux/mtd/rawnand.h>
47 #include <linux/mtd/nand-ecc-sw-hamming.h>
48 #include <linux/mtd/partitions.h>
54 #include <sound/s3c24xx_uda134x.h>
58 #define MACH_MINI2440_DM9K_BASE (S3C2410_CS4 + 0x300)
60 static struct map_desc mini2440_iodesc[] __initdata = {
61 /* nothing to declare, move along */
64 #define UCON S3C2410_UCON_DEFAULT
65 #define ULCON (S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB)
66 #define UFCON (S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE)
69 static struct s3c2410_uartcfg mini2440_uartcfgs[] __initdata = {
93 /* USB device UDC support */
95 static struct s3c2410_udc_mach_info mini2440_udc_cfg __initdata = {
98 static struct gpiod_lookup_table mini2440_udc_gpio_table = {
99 .dev_id = "s3c2410-usbgadget",
101 GPIO_LOOKUP("GPIOC", 5, "pullup", GPIO_ACTIVE_HIGH),
106 /* LCD timing and setup */
109 * This macro simplifies the table bellow
111 #define _LCD_DECLARE(_clock, _xres, margin_left, margin_right, hsync, \
112 _yres, margin_top, margin_bottom, vsync, refresh) \
117 .left_margin = margin_left, \
118 .right_margin = margin_right, \
119 .upper_margin = margin_top, \
120 .lower_margin = margin_bottom, \
121 .hsync_len = hsync, \
122 .vsync_len = vsync, \
123 .pixclock = ((_clock*100000000000LL) / \
125 (hsync + margin_left + _xres + margin_right) * \
126 (vsync + margin_top + _yres + margin_bottom))), \
128 .type = (S3C2410_LCDCON1_TFT16BPP |\
131 static struct s3c2410fb_display mini2440_lcd_cfg[] __initdata = {
132 [0] = { /* mini2440 + 3.5" TFT + touchscreen */
134 7, /* The 3.5 is quite fast */
135 240, 21, 38, 6, /* x timing */
136 320, 4, 4, 2, /* y timing */
137 60), /* refresh rate */
138 .lcdcon5 = (S3C2410_LCDCON5_FRM565 |
139 S3C2410_LCDCON5_INVVLINE |
140 S3C2410_LCDCON5_INVVFRAME |
141 S3C2410_LCDCON5_INVVDEN |
142 S3C2410_LCDCON5_PWREN),
144 [1] = { /* mini2440 + 7" TFT + touchscreen */
146 10, /* the 7" runs slower */
147 800, 40, 40, 48, /* x timing */
148 480, 29, 3, 3, /* y timing */
149 50), /* refresh rate */
150 .lcdcon5 = (S3C2410_LCDCON5_FRM565 |
151 S3C2410_LCDCON5_INVVLINE |
152 S3C2410_LCDCON5_INVVFRAME |
153 S3C2410_LCDCON5_PWREN),
155 /* The VGA shield can outout at several resolutions. All share
156 * the same timings, however, anything smaller than 1024x768
157 * will only be displayed in the top left corner of a 1024x768
158 * XGA output unless you add optional dip switches to the shield.
159 * Therefore timings for other resolutions have been omitted here.
164 1024, 1, 2, 2, /* y timing */
165 768, 200, 16, 16, /* x timing */
166 24), /* refresh rate, maximum stable,
167 * 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
207 .gpcup = (0xf << 1) | (0x3f << 10),
209 .gpccon = (S3C2410_GPC1_VCLK | S3C2410_GPC2_VLINE |
210 S3C2410_GPC3_VFRAME | S3C2410_GPC4_VM |
211 S3C2410_GPC10_VD2 | S3C2410_GPC11_VD3 |
212 S3C2410_GPC12_VD4 | S3C2410_GPC13_VD5 |
213 S3C2410_GPC14_VD6 | S3C2410_GPC15_VD7),
215 .gpccon_mask = (S3C2410_GPCCON_MASK(1) | S3C2410_GPCCON_MASK(2) |
216 S3C2410_GPCCON_MASK(3) | S3C2410_GPCCON_MASK(4) |
217 S3C2410_GPCCON_MASK(10) | S3C2410_GPCCON_MASK(11) |
218 S3C2410_GPCCON_MASK(12) | S3C2410_GPCCON_MASK(13) |
219 S3C2410_GPCCON_MASK(14) | S3C2410_GPCCON_MASK(15)),
221 .gpccon_reg = S3C2410_GPCCON,
222 .gpcup_reg = S3C2410_GPCUP,
224 .gpdup = (0x3f << 2) | (0x3f << 10),
226 .gpdcon = (S3C2410_GPD2_VD10 | S3C2410_GPD3_VD11 |
227 S3C2410_GPD4_VD12 | S3C2410_GPD5_VD13 |
228 S3C2410_GPD6_VD14 | S3C2410_GPD7_VD15 |
229 S3C2410_GPD10_VD18 | S3C2410_GPD11_VD19 |
230 S3C2410_GPD12_VD20 | S3C2410_GPD13_VD21 |
231 S3C2410_GPD14_VD22 | S3C2410_GPD15_VD23),
233 .gpdcon_mask = (S3C2410_GPDCON_MASK(2) | S3C2410_GPDCON_MASK(3) |
234 S3C2410_GPDCON_MASK(4) | S3C2410_GPDCON_MASK(5) |
235 S3C2410_GPDCON_MASK(6) | S3C2410_GPDCON_MASK(7) |
236 S3C2410_GPDCON_MASK(10) | S3C2410_GPDCON_MASK(11)|
237 S3C2410_GPDCON_MASK(12) | S3C2410_GPDCON_MASK(13)|
238 S3C2410_GPDCON_MASK(14) | S3C2410_GPDCON_MASK(15)),
240 .gpdcon_reg = S3C2410_GPDCON,
241 .gpdup_reg = S3C2410_GPDUP,
246 static struct s3c24xx_mci_pdata mini2440_mmc_cfg __initdata = {
247 .wprotect_invert = 1,
248 .set_power = s3c24xx_mci_def_set_power,
249 .ocr_avail = MMC_VDD_32_33|MMC_VDD_33_34,
252 static struct gpiod_lookup_table mini2440_mmc_gpio_table = {
253 .dev_id = "s3c2410-sdi",
255 /* Card detect S3C2410_GPG(8) */
256 GPIO_LOOKUP("GPIOG", 8, "cd", GPIO_ACTIVE_LOW),
257 /* Write protect S3C2410_GPH(8) */
258 GPIO_LOOKUP("GPIOH", 8, "wp", GPIO_ACTIVE_HIGH),
260 GPIO_LOOKUP_IDX("GPIOE", 5, "bus", 0, GPIO_ACTIVE_HIGH),
261 GPIO_LOOKUP_IDX("GPIOE", 6, "bus", 1, GPIO_ACTIVE_HIGH),
262 GPIO_LOOKUP_IDX("GPIOE", 7, "bus", 2, GPIO_ACTIVE_HIGH),
263 GPIO_LOOKUP_IDX("GPIOE", 8, "bus", 3, GPIO_ACTIVE_HIGH),
264 GPIO_LOOKUP_IDX("GPIOE", 9, "bus", 4, GPIO_ACTIVE_HIGH),
265 GPIO_LOOKUP_IDX("GPIOE", 10, "bus", 5, GPIO_ACTIVE_HIGH),
270 /* NAND Flash on MINI2440 board */
272 static struct mtd_partition mini2440_default_nand_part[] __initdata = {
279 .name = "u-boot-env",
285 /* 5 megabytes, for a kernel with no modules
286 * or a uImage with a ramdisk attached
289 .offset = SZ_256K + SZ_128K,
293 .offset = SZ_256K + SZ_128K + 0x00500000,
294 .size = MTDPART_SIZ_FULL,
298 static struct s3c2410_nand_set mini2440_nand_sets[] __initdata = {
302 .nr_partitions = ARRAY_SIZE(mini2440_default_nand_part),
303 .partitions = mini2440_default_nand_part,
304 .flash_bbt = 1, /* we use u-boot to create a BBT */
308 static struct s3c2410_platform_nand mini2440_nand_info __initdata = {
312 .nr_sets = ARRAY_SIZE(mini2440_nand_sets),
313 .sets = mini2440_nand_sets,
314 .ignore_unset_ecc = 1,
315 .engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST,
318 /* DM9000AEP 10/100 ethernet controller */
320 static struct resource mini2440_dm9k_resource[] = {
321 [0] = DEFINE_RES_MEM(MACH_MINI2440_DM9K_BASE, 4),
322 [1] = DEFINE_RES_MEM(MACH_MINI2440_DM9K_BASE + 4, 4),
323 [2] = DEFINE_RES_NAMED(IRQ_EINT7, 1, NULL, IORESOURCE_IRQ
324 | IORESOURCE_IRQ_HIGHEDGE),
328 * The DM9000 has no eeprom, and it's MAC address is set by
329 * the bootloader before starting the kernel.
331 static struct dm9000_plat_data mini2440_dm9k_pdata = {
332 .flags = (DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM),
335 static struct platform_device mini2440_device_eth = {
338 .num_resources = ARRAY_SIZE(mini2440_dm9k_resource),
339 .resource = mini2440_dm9k_resource,
341 .platform_data = &mini2440_dm9k_pdata,
362 static struct gpio_keys_button mini2440_buttons[] = {
364 .gpio = S3C2410_GPG(0), /* K1 */
370 .gpio = S3C2410_GPG(3), /* K2 */
376 .gpio = S3C2410_GPG(5), /* K3 */
382 .gpio = S3C2410_GPG(6), /* K4 */
388 .gpio = S3C2410_GPG(7), /* K5 */
394 /* this pin is also known as TCLK1 and seems to already
395 * marked as "in use" somehow in the kernel -- possibly wrongly
398 .gpio = S3C2410_GPG(11), /* K6 */
406 static struct gpio_keys_platform_data mini2440_button_data = {
407 .buttons = mini2440_buttons,
408 .nbuttons = ARRAY_SIZE(mini2440_buttons),
411 static struct platform_device mini2440_button_device = {
415 .platform_data = &mini2440_button_data,
421 static struct gpiod_lookup_table mini2440_led1_gpio_table = {
422 .dev_id = "s3c24xx_led.1",
424 GPIO_LOOKUP("GPB", 5, NULL, GPIO_ACTIVE_LOW | GPIO_OPEN_DRAIN),
429 static struct gpiod_lookup_table mini2440_led2_gpio_table = {
430 .dev_id = "s3c24xx_led.2",
432 GPIO_LOOKUP("GPB", 6, NULL, GPIO_ACTIVE_LOW | GPIO_OPEN_DRAIN),
437 static struct gpiod_lookup_table mini2440_led3_gpio_table = {
438 .dev_id = "s3c24xx_led.3",
440 GPIO_LOOKUP("GPB", 7, NULL, GPIO_ACTIVE_LOW | GPIO_OPEN_DRAIN),
445 static struct gpiod_lookup_table mini2440_led4_gpio_table = {
446 .dev_id = "s3c24xx_led.4",
448 GPIO_LOOKUP("GPB", 8, NULL, GPIO_ACTIVE_LOW | GPIO_OPEN_DRAIN),
453 static struct gpiod_lookup_table mini2440_backlight_gpio_table = {
454 .dev_id = "s3c24xx_led.5",
456 GPIO_LOOKUP("GPG", 4, NULL, GPIO_ACTIVE_HIGH),
461 static struct s3c24xx_led_platdata mini2440_led1_pdata = {
463 .def_trigger = "heartbeat",
466 static struct s3c24xx_led_platdata mini2440_led2_pdata = {
468 .def_trigger = "nand-disk",
471 static struct s3c24xx_led_platdata mini2440_led3_pdata = {
473 .def_trigger = "mmc0",
476 static struct s3c24xx_led_platdata mini2440_led4_pdata = {
481 static struct s3c24xx_led_platdata mini2440_led_backlight_pdata = {
483 .def_trigger = "backlight",
486 static struct platform_device mini2440_led1 = {
487 .name = "s3c24xx_led",
490 .platform_data = &mini2440_led1_pdata,
494 static struct platform_device mini2440_led2 = {
495 .name = "s3c24xx_led",
498 .platform_data = &mini2440_led2_pdata,
502 static struct platform_device mini2440_led3 = {
503 .name = "s3c24xx_led",
506 .platform_data = &mini2440_led3_pdata,
510 static struct platform_device mini2440_led4 = {
511 .name = "s3c24xx_led",
514 .platform_data = &mini2440_led4_pdata,
518 static struct platform_device mini2440_led_backlight = {
519 .name = "s3c24xx_led",
522 .platform_data = &mini2440_led_backlight_pdata,
528 static struct s3c24xx_uda134x_platform_data mini2440_audio_pins = {
529 .l3_clk = S3C2410_GPB(4),
530 .l3_mode = S3C2410_GPB(2),
531 .l3_data = S3C2410_GPB(3),
532 .model = UDA134X_UDA1341
535 static struct platform_device mini2440_audio = {
536 .name = "s3c24xx_uda134x",
539 .platform_data = &mini2440_audio_pins,
546 static const struct property_entry mini2440_at24_properties[] = {
547 PROPERTY_ENTRY_U32("pagesize", 16),
551 static const struct software_node mini2440_at24_node = {
552 .properties = mini2440_at24_properties,
555 static struct i2c_board_info mini2440_i2c_devs[] __initdata = {
557 I2C_BOARD_INFO("24c08", 0x50),
558 .swnode = &mini2440_at24_node,
562 static struct uda134x_platform_data s3c24xx_uda134x = {
564 .gpio_clk = S3C2410_GPB(4),
565 .gpio_data = S3C2410_GPB(3),
566 .gpio_mode = S3C2410_GPB(2),
575 .model = UDA134X_UDA1341,
578 static struct platform_device uda1340_codec = {
579 .name = "uda134x-codec",
582 .platform_data = &s3c24xx_uda134x,
586 static struct platform_device *mini2440_devices[] __initdata = {
591 &s3c_device_usbgadget,
592 &mini2440_device_eth,
597 &mini2440_button_device,
606 static void __init mini2440_map_io(void)
608 s3c24xx_init_io(mini2440_iodesc, ARRAY_SIZE(mini2440_iodesc));
609 s3c24xx_init_uarts(mini2440_uartcfgs, ARRAY_SIZE(mini2440_uartcfgs));
610 s3c24xx_set_timer_source(S3C24XX_PWM3, S3C24XX_PWM4);
613 static void __init mini2440_init_time(void)
615 s3c2440_init_clocks(12000000);
616 s3c24xx_timer_init();
620 * mini2440_features string
622 * t = Touchscreen present
623 * b = backlight control
625 * 0-9 LCD configuration
628 static char mini2440_features_str[12] __initdata = "0tb";
630 static int __init mini2440_features_setup(char *str)
633 strscpy(mini2440_features_str, str,
634 sizeof(mini2440_features_str));
638 __setup("mini2440=", mini2440_features_setup);
640 #define FEATURE_SCREEN (1 << 0)
641 #define FEATURE_BACKLIGHT (1 << 1)
642 #define FEATURE_TOUCH (1 << 2)
643 #define FEATURE_CAMERA (1 << 3)
645 struct mini2440_features_t {
649 struct platform_device *optional[8];
652 static void __init mini2440_parse_features(
653 struct mini2440_features_t *features,
654 const char *features_str)
656 const char *fp = features_str;
660 features->lcd_index = -1;
666 case '0'...'9': /* tft screen */
667 if (features->done & FEATURE_SCREEN) {
668 pr_info("MINI2440: '%c' ignored, screen type already set\n",
673 if (li >= ARRAY_SIZE(mini2440_lcd_cfg))
674 pr_info("MINI2440: '%c' out of range LCD mode\n",
677 features->optional[features->count++] =
679 features->lcd_index = li;
682 features->done |= FEATURE_SCREEN;
685 if (features->done & FEATURE_BACKLIGHT)
686 pr_info("MINI2440: '%c' ignored, backlight already set\n",
689 features->optional[features->count++] =
690 &mini2440_led_backlight;
692 features->done |= FEATURE_BACKLIGHT;
695 pr_info("MINI2440: '%c' ignored, touchscreen not compiled in\n",
699 if (features->done & FEATURE_CAMERA)
700 pr_info("MINI2440: '%c' ignored, camera already registered\n",
703 features->optional[features->count++] =
705 features->done |= FEATURE_CAMERA;
711 static void __init mini2440_init(void)
713 struct mini2440_features_t features = { 0 };
716 pr_info("MINI2440: Option string mini2440=%s\n",
717 mini2440_features_str);
719 /* Parse the feature string */
720 mini2440_parse_features(&features, mini2440_features_str);
723 s3c_gpio_cfgpin(S3C2410_GPC(0), S3C2410_GPC0_LEND);
725 /* Turn the backlight early on */
726 WARN_ON(gpio_request_one(S3C2410_GPG(4), GPIOF_OUT_INIT_HIGH, NULL));
727 gpio_free(S3C2410_GPG(4));
729 /* remove pullup on optional PWM backlight -- unused on 3.5 and 7"s */
730 gpio_request_one(S3C2410_GPB(1), GPIOF_IN, NULL);
731 s3c_gpio_setpull(S3C2410_GPB(1), S3C_GPIO_PULL_UP);
732 gpio_free(S3C2410_GPB(1));
734 /* mark the key as input, without pullups (there is one on the board) */
735 for (i = 0; i < ARRAY_SIZE(mini2440_buttons); i++) {
736 s3c_gpio_setpull(mini2440_buttons[i].gpio, S3C_GPIO_PULL_UP);
737 s3c_gpio_cfgpin(mini2440_buttons[i].gpio, S3C2410_GPIO_INPUT);
740 /* Configure the I2S pins (GPE0...GPE4) in correct mode */
741 s3c_gpio_cfgall_range(S3C2410_GPE(0), 5, S3C_GPIO_SFN(2),
744 if (features.lcd_index != -1) {
747 mini2440_fb_info.displays =
748 &mini2440_lcd_cfg[features.lcd_index];
750 pr_info("MINI2440: LCD");
751 for (li = 0; li < ARRAY_SIZE(mini2440_lcd_cfg); li++)
752 if (li == features.lcd_index)
753 pr_cont(" [%d:%dx%d]", li,
754 mini2440_lcd_cfg[li].width,
755 mini2440_lcd_cfg[li].height);
757 pr_cont(" %d:%dx%d", li,
758 mini2440_lcd_cfg[li].width,
759 mini2440_lcd_cfg[li].height);
761 s3c24xx_fb_set_platdata(&mini2440_fb_info);
764 gpiod_add_lookup_table(&mini2440_udc_gpio_table);
765 s3c24xx_udc_set_platdata(&mini2440_udc_cfg);
766 gpiod_add_lookup_table(&mini2440_mmc_gpio_table);
767 s3c24xx_mci_set_platdata(&mini2440_mmc_cfg);
768 s3c_nand_set_platdata(&mini2440_nand_info);
769 s3c_i2c0_set_platdata(NULL);
771 i2c_register_board_info(0, mini2440_i2c_devs,
772 ARRAY_SIZE(mini2440_i2c_devs));
774 /* Disable pull-up on the LED lines */
775 s3c_gpio_setpull(S3C2410_GPB(5), S3C_GPIO_PULL_NONE);
776 s3c_gpio_setpull(S3C2410_GPB(6), S3C_GPIO_PULL_NONE);
777 s3c_gpio_setpull(S3C2410_GPB(7), S3C_GPIO_PULL_NONE);
778 s3c_gpio_setpull(S3C2410_GPB(8), S3C_GPIO_PULL_NONE);
779 s3c_gpio_setpull(S3C2410_GPG(4), S3C_GPIO_PULL_NONE);
781 /* Add lookups for the lines */
782 gpiod_add_lookup_table(&mini2440_led1_gpio_table);
783 gpiod_add_lookup_table(&mini2440_led2_gpio_table);
784 gpiod_add_lookup_table(&mini2440_led3_gpio_table);
785 gpiod_add_lookup_table(&mini2440_led4_gpio_table);
786 gpiod_add_lookup_table(&mini2440_backlight_gpio_table);
788 platform_add_devices(mini2440_devices, ARRAY_SIZE(mini2440_devices));
790 if (features.count) /* the optional features */
791 platform_add_devices(features.optional, features.count);
796 MACHINE_START(MINI2440, "MINI2440")
797 /* Maintainer: Michel Pollet <buserror@gmail.com> */
798 .atag_offset = 0x100,
799 .nr_irqs = NR_IRQS_S3C2440,
800 .map_io = mini2440_map_io,
801 .init_machine = mini2440_init,
802 .init_irq = s3c2440_init_irq,
803 .init_time = mini2440_init_time,