1 // SPDX-License-Identifier: GPL-2.0
6 // Weibing <http://weibing.blogbus.com> and
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>
38 #include <mach/irqs.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 = {
96 .pullup_pin = S3C2410_GPC(5),
100 /* LCD timing and setup */
103 * This macro simplifies the table bellow
105 #define _LCD_DECLARE(_clock, _xres, margin_left, margin_right, hsync, \
106 _yres, margin_top, margin_bottom, vsync, refresh) \
111 .left_margin = margin_left, \
112 .right_margin = margin_right, \
113 .upper_margin = margin_top, \
114 .lower_margin = margin_bottom, \
115 .hsync_len = hsync, \
116 .vsync_len = vsync, \
117 .pixclock = ((_clock*100000000000LL) / \
119 (hsync + margin_left + _xres + margin_right) * \
120 (vsync + margin_top + _yres + margin_bottom))), \
122 .type = (S3C2410_LCDCON1_TFT16BPP |\
125 static struct s3c2410fb_display mini2440_lcd_cfg[] __initdata = {
126 [0] = { /* mini2440 + 3.5" TFT + touchscreen */
128 7, /* The 3.5 is quite fast */
129 240, 21, 38, 6, /* x timing */
130 320, 4, 4, 2, /* y timing */
131 60), /* refresh rate */
132 .lcdcon5 = (S3C2410_LCDCON5_FRM565 |
133 S3C2410_LCDCON5_INVVLINE |
134 S3C2410_LCDCON5_INVVFRAME |
135 S3C2410_LCDCON5_INVVDEN |
136 S3C2410_LCDCON5_PWREN),
138 [1] = { /* mini2440 + 7" TFT + touchscreen */
140 10, /* the 7" runs slower */
141 800, 40, 40, 48, /* x timing */
142 480, 29, 3, 3, /* y timing */
143 50), /* refresh rate */
144 .lcdcon5 = (S3C2410_LCDCON5_FRM565 |
145 S3C2410_LCDCON5_INVVLINE |
146 S3C2410_LCDCON5_INVVFRAME |
147 S3C2410_LCDCON5_PWREN),
149 /* The VGA shield can outout at several resolutions. All share
150 * the same timings, however, anything smaller than 1024x768
151 * will only be displayed in the top left corner of a 1024x768
152 * XGA output unless you add optional dip switches to the shield.
153 * Therefore timings for other resolutions have been omitted here.
158 1024, 1, 2, 2, /* y timing */
159 768, 200, 16, 16, /* x timing */
160 24), /* refresh rate, maximum stable,
161 * tested with the FPGA shield
163 .lcdcon5 = (S3C2410_LCDCON5_FRM565 |
164 S3C2410_LCDCON5_HWSWP),
166 /* mini2440 + 3.5" TFT (LCD-W35i, LQ035Q1DG06 type) + touchscreen*/
171 /* xres, margin_right, margin_left, hsync */
173 /* yres, margin_top, margin_bottom, vsync */
177 .lcdcon5 = (S3C2410_LCDCON5_FRM565 |
178 S3C2410_LCDCON5_INVVDEN |
179 S3C2410_LCDCON5_INVVFRAME |
180 S3C2410_LCDCON5_INVVLINE |
181 S3C2410_LCDCON5_INVVCLK |
182 S3C2410_LCDCON5_HWSWP),
186 /* todo - put into gpio header */
188 #define S3C2410_GPCCON_MASK(x) (3 << ((x) * 2))
189 #define S3C2410_GPDCON_MASK(x) (3 << ((x) * 2))
191 static struct s3c2410fb_mach_info mini2440_fb_info __initdata = {
192 .displays = &mini2440_lcd_cfg[0], /* not constant! see init */
194 .default_display = 0,
196 /* Enable VD[2..7], VD[10..15], VD[18..23] and VCLK, syncs, VDEN
197 * 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 .gpccon_reg = S3C2410_GPCCON,
216 .gpcup_reg = S3C2410_GPCUP,
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)),
234 .gpdcon_reg = S3C2410_GPDCON,
235 .gpdup_reg = S3C2410_GPDUP,
240 static struct s3c24xx_mci_pdata mini2440_mmc_cfg __initdata = {
241 .wprotect_invert = 1,
242 .set_power = s3c24xx_mci_def_set_power,
243 .ocr_avail = MMC_VDD_32_33|MMC_VDD_33_34,
246 static struct gpiod_lookup_table mini2440_mmc_gpio_table = {
247 .dev_id = "s3c2410-sdi",
249 /* Card detect S3C2410_GPG(8) */
250 GPIO_LOOKUP("GPIOG", 8, "cd", GPIO_ACTIVE_LOW),
251 /* Write protect S3C2410_GPH(8) */
252 GPIO_LOOKUP("GPIOH", 8, "wp", GPIO_ACTIVE_HIGH),
254 GPIO_LOOKUP_IDX("GPIOE", 5, "bus", 0, GPIO_ACTIVE_HIGH),
255 GPIO_LOOKUP_IDX("GPIOE", 6, "bus", 1, GPIO_ACTIVE_HIGH),
256 GPIO_LOOKUP_IDX("GPIOE", 7, "bus", 2, GPIO_ACTIVE_HIGH),
257 GPIO_LOOKUP_IDX("GPIOE", 8, "bus", 3, GPIO_ACTIVE_HIGH),
258 GPIO_LOOKUP_IDX("GPIOE", 9, "bus", 4, GPIO_ACTIVE_HIGH),
259 GPIO_LOOKUP_IDX("GPIOE", 10, "bus", 5, GPIO_ACTIVE_HIGH),
264 /* NAND Flash on MINI2440 board */
266 static struct mtd_partition mini2440_default_nand_part[] __initdata = {
273 .name = "u-boot-env",
279 /* 5 megabytes, for a kernel with no modules
280 * or a uImage with a ramdisk attached
283 .offset = SZ_256K + SZ_128K,
287 .offset = SZ_256K + SZ_128K + 0x00500000,
288 .size = MTDPART_SIZ_FULL,
292 static struct s3c2410_nand_set mini2440_nand_sets[] __initdata = {
296 .nr_partitions = ARRAY_SIZE(mini2440_default_nand_part),
297 .partitions = mini2440_default_nand_part,
298 .flash_bbt = 1, /* we use u-boot to create a BBT */
302 static struct s3c2410_platform_nand mini2440_nand_info __initdata = {
306 .nr_sets = ARRAY_SIZE(mini2440_nand_sets),
307 .sets = mini2440_nand_sets,
308 .ignore_unset_ecc = 1,
309 .engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST,
312 /* DM9000AEP 10/100 ethernet controller */
314 static struct resource mini2440_dm9k_resource[] = {
315 [0] = DEFINE_RES_MEM(MACH_MINI2440_DM9K_BASE, 4),
316 [1] = DEFINE_RES_MEM(MACH_MINI2440_DM9K_BASE + 4, 4),
317 [2] = DEFINE_RES_NAMED(IRQ_EINT7, 1, NULL, IORESOURCE_IRQ
318 | IORESOURCE_IRQ_HIGHEDGE),
322 * The DM9000 has no eeprom, and it's MAC address is set by
323 * the bootloader before starting the kernel.
325 static struct dm9000_plat_data mini2440_dm9k_pdata = {
326 .flags = (DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM),
329 static struct platform_device mini2440_device_eth = {
332 .num_resources = ARRAY_SIZE(mini2440_dm9k_resource),
333 .resource = mini2440_dm9k_resource,
335 .platform_data = &mini2440_dm9k_pdata,
356 static struct gpio_keys_button mini2440_buttons[] = {
358 .gpio = S3C2410_GPG(0), /* K1 */
364 .gpio = S3C2410_GPG(3), /* K2 */
370 .gpio = S3C2410_GPG(5), /* K3 */
376 .gpio = S3C2410_GPG(6), /* K4 */
382 .gpio = S3C2410_GPG(7), /* K5 */
388 /* this pin is also known as TCLK1 and seems to already
389 * marked as "in use" somehow in the kernel -- possibly wrongly
392 .gpio = S3C2410_GPG(11), /* K6 */
400 static struct gpio_keys_platform_data mini2440_button_data = {
401 .buttons = mini2440_buttons,
402 .nbuttons = ARRAY_SIZE(mini2440_buttons),
405 static struct platform_device mini2440_button_device = {
409 .platform_data = &mini2440_button_data,
415 static struct gpiod_lookup_table mini2440_led1_gpio_table = {
416 .dev_id = "s3c24xx_led.1",
418 GPIO_LOOKUP("GPB", 5, NULL, GPIO_ACTIVE_LOW | GPIO_OPEN_DRAIN),
423 static struct gpiod_lookup_table mini2440_led2_gpio_table = {
424 .dev_id = "s3c24xx_led.2",
426 GPIO_LOOKUP("GPB", 6, NULL, GPIO_ACTIVE_LOW | GPIO_OPEN_DRAIN),
431 static struct gpiod_lookup_table mini2440_led3_gpio_table = {
432 .dev_id = "s3c24xx_led.3",
434 GPIO_LOOKUP("GPB", 7, NULL, GPIO_ACTIVE_LOW | GPIO_OPEN_DRAIN),
439 static struct gpiod_lookup_table mini2440_led4_gpio_table = {
440 .dev_id = "s3c24xx_led.4",
442 GPIO_LOOKUP("GPB", 8, NULL, GPIO_ACTIVE_LOW | GPIO_OPEN_DRAIN),
447 static struct gpiod_lookup_table mini2440_backlight_gpio_table = {
448 .dev_id = "s3c24xx_led.5",
450 GPIO_LOOKUP("GPG", 4, NULL, GPIO_ACTIVE_HIGH),
455 static struct s3c24xx_led_platdata mini2440_led1_pdata = {
457 .def_trigger = "heartbeat",
460 static struct s3c24xx_led_platdata mini2440_led2_pdata = {
462 .def_trigger = "nand-disk",
465 static struct s3c24xx_led_platdata mini2440_led3_pdata = {
467 .def_trigger = "mmc0",
470 static struct s3c24xx_led_platdata mini2440_led4_pdata = {
475 static struct s3c24xx_led_platdata mini2440_led_backlight_pdata = {
477 .def_trigger = "backlight",
480 static struct platform_device mini2440_led1 = {
481 .name = "s3c24xx_led",
484 .platform_data = &mini2440_led1_pdata,
488 static struct platform_device mini2440_led2 = {
489 .name = "s3c24xx_led",
492 .platform_data = &mini2440_led2_pdata,
496 static struct platform_device mini2440_led3 = {
497 .name = "s3c24xx_led",
500 .platform_data = &mini2440_led3_pdata,
504 static struct platform_device mini2440_led4 = {
505 .name = "s3c24xx_led",
508 .platform_data = &mini2440_led4_pdata,
512 static struct platform_device mini2440_led_backlight = {
513 .name = "s3c24xx_led",
516 .platform_data = &mini2440_led_backlight_pdata,
522 static struct s3c24xx_uda134x_platform_data mini2440_audio_pins = {
523 .l3_clk = S3C2410_GPB(4),
524 .l3_mode = S3C2410_GPB(2),
525 .l3_data = S3C2410_GPB(3),
526 .model = UDA134X_UDA1341
529 static struct platform_device mini2440_audio = {
530 .name = "s3c24xx_uda134x",
533 .platform_data = &mini2440_audio_pins,
540 static const struct property_entry mini2440_at24_properties[] = {
541 PROPERTY_ENTRY_U32("pagesize", 16),
545 static const struct software_node mini2440_at24_node = {
546 .properties = mini2440_at24_properties,
549 static struct i2c_board_info mini2440_i2c_devs[] __initdata = {
551 I2C_BOARD_INFO("24c08", 0x50),
552 .swnode = &mini2440_at24_node,
556 static struct uda134x_platform_data s3c24xx_uda134x = {
558 .gpio_clk = S3C2410_GPB(4),
559 .gpio_data = S3C2410_GPB(3),
560 .gpio_mode = S3C2410_GPB(2),
569 .model = UDA134X_UDA1341,
572 static struct platform_device uda1340_codec = {
573 .name = "uda134x-codec",
576 .platform_data = &s3c24xx_uda134x,
580 static struct platform_device *mini2440_devices[] __initdata = {
585 &s3c_device_usbgadget,
586 &mini2440_device_eth,
591 &mini2440_button_device,
600 static void __init mini2440_map_io(void)
602 s3c24xx_init_io(mini2440_iodesc, ARRAY_SIZE(mini2440_iodesc));
603 s3c24xx_init_uarts(mini2440_uartcfgs, ARRAY_SIZE(mini2440_uartcfgs));
604 s3c24xx_set_timer_source(S3C24XX_PWM3, S3C24XX_PWM4);
607 static void __init mini2440_init_time(void)
609 s3c2440_init_clocks(12000000);
610 s3c24xx_timer_init();
614 * mini2440_features string
616 * t = Touchscreen present
617 * b = backlight control
619 * 0-9 LCD configuration
622 static char mini2440_features_str[12] __initdata = "0tb";
624 static int __init mini2440_features_setup(char *str)
627 strlcpy(mini2440_features_str, str,
628 sizeof(mini2440_features_str));
632 __setup("mini2440=", mini2440_features_setup);
634 #define FEATURE_SCREEN (1 << 0)
635 #define FEATURE_BACKLIGHT (1 << 1)
636 #define FEATURE_TOUCH (1 << 2)
637 #define FEATURE_CAMERA (1 << 3)
639 struct mini2440_features_t {
643 struct platform_device *optional[8];
646 static void __init mini2440_parse_features(
647 struct mini2440_features_t *features,
648 const char *features_str)
650 const char *fp = features_str;
654 features->lcd_index = -1;
660 case '0'...'9': /* tft screen */
661 if (features->done & FEATURE_SCREEN) {
662 pr_info("MINI2440: '%c' ignored, screen type already set\n",
667 if (li >= ARRAY_SIZE(mini2440_lcd_cfg))
668 pr_info("MINI2440: '%c' out of range LCD mode\n",
671 features->optional[features->count++] =
673 features->lcd_index = li;
676 features->done |= FEATURE_SCREEN;
679 if (features->done & FEATURE_BACKLIGHT)
680 pr_info("MINI2440: '%c' ignored, backlight already set\n",
683 features->optional[features->count++] =
684 &mini2440_led_backlight;
686 features->done |= FEATURE_BACKLIGHT;
689 pr_info("MINI2440: '%c' ignored, touchscreen not compiled in\n",
693 if (features->done & FEATURE_CAMERA)
694 pr_info("MINI2440: '%c' ignored, camera already registered\n",
697 features->optional[features->count++] =
699 features->done |= FEATURE_CAMERA;
705 static void __init mini2440_init(void)
707 struct mini2440_features_t features = { 0 };
710 pr_info("MINI2440: Option string mini2440=%s\n",
711 mini2440_features_str);
713 /* Parse the feature string */
714 mini2440_parse_features(&features, mini2440_features_str);
717 s3c_gpio_cfgpin(S3C2410_GPC(0), S3C2410_GPC0_LEND);
719 /* Turn the backlight early on */
720 WARN_ON(gpio_request_one(S3C2410_GPG(4), GPIOF_OUT_INIT_HIGH, NULL));
721 gpio_free(S3C2410_GPG(4));
723 /* remove pullup on optional PWM backlight -- unused on 3.5 and 7"s */
724 gpio_request_one(S3C2410_GPB(1), GPIOF_IN, NULL);
725 s3c_gpio_setpull(S3C2410_GPB(1), S3C_GPIO_PULL_UP);
726 gpio_free(S3C2410_GPB(1));
728 /* mark the key as input, without pullups (there is one on the board) */
729 for (i = 0; i < ARRAY_SIZE(mini2440_buttons); i++) {
730 s3c_gpio_setpull(mini2440_buttons[i].gpio, S3C_GPIO_PULL_UP);
731 s3c_gpio_cfgpin(mini2440_buttons[i].gpio, S3C2410_GPIO_INPUT);
734 /* Configure the I2S pins (GPE0...GPE4) in correct mode */
735 s3c_gpio_cfgall_range(S3C2410_GPE(0), 5, S3C_GPIO_SFN(2),
738 if (features.lcd_index != -1) {
741 mini2440_fb_info.displays =
742 &mini2440_lcd_cfg[features.lcd_index];
744 pr_info("MINI2440: LCD");
745 for (li = 0; li < ARRAY_SIZE(mini2440_lcd_cfg); li++)
746 if (li == features.lcd_index)
747 pr_cont(" [%d:%dx%d]", li,
748 mini2440_lcd_cfg[li].width,
749 mini2440_lcd_cfg[li].height);
751 pr_cont(" %d:%dx%d", li,
752 mini2440_lcd_cfg[li].width,
753 mini2440_lcd_cfg[li].height);
755 s3c24xx_fb_set_platdata(&mini2440_fb_info);
758 s3c24xx_udc_set_platdata(&mini2440_udc_cfg);
759 gpiod_add_lookup_table(&mini2440_mmc_gpio_table);
760 s3c24xx_mci_set_platdata(&mini2440_mmc_cfg);
761 s3c_nand_set_platdata(&mini2440_nand_info);
762 s3c_i2c0_set_platdata(NULL);
764 i2c_register_board_info(0, mini2440_i2c_devs,
765 ARRAY_SIZE(mini2440_i2c_devs));
767 /* Disable pull-up on the LED lines */
768 s3c_gpio_setpull(S3C2410_GPB(5), S3C_GPIO_PULL_NONE);
769 s3c_gpio_setpull(S3C2410_GPB(6), S3C_GPIO_PULL_NONE);
770 s3c_gpio_setpull(S3C2410_GPB(7), S3C_GPIO_PULL_NONE);
771 s3c_gpio_setpull(S3C2410_GPB(8), S3C_GPIO_PULL_NONE);
772 s3c_gpio_setpull(S3C2410_GPG(4), S3C_GPIO_PULL_NONE);
774 /* Add lookups for the lines */
775 gpiod_add_lookup_table(&mini2440_led1_gpio_table);
776 gpiod_add_lookup_table(&mini2440_led2_gpio_table);
777 gpiod_add_lookup_table(&mini2440_led3_gpio_table);
778 gpiod_add_lookup_table(&mini2440_led4_gpio_table);
779 gpiod_add_lookup_table(&mini2440_backlight_gpio_table);
781 platform_add_devices(mini2440_devices, ARRAY_SIZE(mini2440_devices));
783 if (features.count) /* the optional features */
784 platform_add_devices(features.optional, features.count);
789 MACHINE_START(MINI2440, "MINI2440")
791 .atag_offset = 0x100,
792 .map_io = mini2440_map_io,
793 .init_machine = mini2440_init,
794 .init_irq = s3c2440_init_irq,
795 .init_time = mini2440_init_time,