GNU Linux-libre 6.1.90-gnu
[releases.git] / arch / arm / mach-s3c / mach-mini2440.c
1 // SPDX-License-Identifier: GPL-2.0
2 //
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>
8 //
9 // For product information, visit https://code.google.com/p/mini2440/
10
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>
20 #include <linux/io.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>
29
30 #include <asm/mach/arch.h>
31 #include <asm/mach/map.h>
32
33 #include <linux/platform_data/fb-s3c2410.h>
34 #include <asm/mach-types.h>
35
36 #include "regs-gpio.h"
37 #include <linux/platform_data/leds-s3c24xx.h>
38 #include "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>
44
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>
49
50 #include "gpio-cfg.h"
51 #include "devs.h"
52 #include "cpu.h"
53
54 #include <sound/s3c24xx_uda134x.h>
55
56 #include "s3c24xx.h"
57
58 #define MACH_MINI2440_DM9K_BASE (S3C2410_CS4 + 0x300)
59
60 static struct map_desc mini2440_iodesc[] __initdata = {
61         /* nothing to declare, move along */
62 };
63
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)
67
68
69 static struct s3c2410_uartcfg mini2440_uartcfgs[] __initdata = {
70         [0] = {
71                 .hwport         = 0,
72                 .flags          = 0,
73                 .ucon           = UCON,
74                 .ulcon          = ULCON,
75                 .ufcon          = UFCON,
76         },
77         [1] = {
78                 .hwport         = 1,
79                 .flags          = 0,
80                 .ucon           = UCON,
81                 .ulcon          = ULCON,
82                 .ufcon          = UFCON,
83         },
84         [2] = {
85                 .hwport         = 2,
86                 .flags          = 0,
87                 .ucon           = UCON,
88                 .ulcon          = ULCON,
89                 .ufcon          = UFCON,
90         },
91 };
92
93 /* USB device UDC support */
94
95 static struct s3c2410_udc_mach_info mini2440_udc_cfg __initdata = {
96 };
97
98 static struct gpiod_lookup_table mini2440_udc_gpio_table = {
99         .dev_id = "s3c2410-usbgadget",
100         .table = {
101                 GPIO_LOOKUP("GPIOC", 5, "pullup", GPIO_ACTIVE_HIGH),
102                 { },
103         },
104 };
105
106 /* LCD timing and setup */
107
108 /*
109  * This macro simplifies the table bellow
110  */
111 #define _LCD_DECLARE(_clock, _xres, margin_left, margin_right, hsync, \
112                         _yres, margin_top, margin_bottom, vsync, refresh) \
113         .width = _xres, \
114         .xres = _xres, \
115         .height = _yres, \
116         .yres = _yres, \
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) /    \
124                            ((refresh) * \
125                            (hsync + margin_left + _xres + margin_right) * \
126                            (vsync + margin_top + _yres + margin_bottom))), \
127         .bpp            = 16,\
128         .type           = (S3C2410_LCDCON1_TFT16BPP |\
129                            S3C2410_LCDCON1_TFT)
130
131 static struct s3c2410fb_display mini2440_lcd_cfg[] __initdata = {
132         [0] = { /* mini2440 + 3.5" TFT + touchscreen */
133                 _LCD_DECLARE(
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),
143         },
144         [1] = { /* mini2440 + 7" TFT + touchscreen */
145                 _LCD_DECLARE(
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),
154         },
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.
160          */
161         [2] = {
162                 _LCD_DECLARE(
163                         10,
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
168                                  */
169                 .lcdcon5        = (S3C2410_LCDCON5_FRM565 |
170                                    S3C2410_LCDCON5_HWSWP),
171         },
172         /* mini2440 + 3.5" TFT (LCD-W35i, LQ035Q1DG06 type) + touchscreen*/
173         [3] = {
174                 _LCD_DECLARE(
175                         /* clock */
176                         7,
177                         /* xres, margin_right, margin_left, hsync */
178                         320, 68, 66, 4,
179                         /* yres, margin_top, margin_bottom, vsync */
180                         240, 4, 4, 9,
181                         /* refresh rate */
182                         60),
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),
189         },
190 };
191
192 /* todo - put into gpio header */
193
194 #define S3C2410_GPCCON_MASK(x)  (3 << ((x) * 2))
195 #define S3C2410_GPDCON_MASK(x)  (3 << ((x) * 2))
196
197 static struct s3c2410fb_mach_info mini2440_fb_info __initdata = {
198         .displays        = &mini2440_lcd_cfg[0], /* not constant! see init */
199         .num_displays    = 1,
200         .default_display = 0,
201
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
204          * data.
205          */
206
207         .gpcup          = (0xf << 1) | (0x3f << 10),
208
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),
214
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)),
220
221         .gpccon_reg     = S3C2410_GPCCON,
222         .gpcup_reg      = S3C2410_GPCUP,
223
224         .gpdup          = (0x3f << 2) | (0x3f << 10),
225
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),
232
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)),
239
240         .gpdcon_reg     = S3C2410_GPDCON,
241         .gpdup_reg      = S3C2410_GPDUP,
242 };
243
244 /* MMC/SD  */
245
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,
250 };
251
252 static struct gpiod_lookup_table mini2440_mmc_gpio_table = {
253         .dev_id = "s3c2410-sdi",
254         .table = {
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),
259                 /* bus pins */
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),
266                 { },
267         },
268 };
269
270 /* NAND Flash on MINI2440 board */
271
272 static struct mtd_partition mini2440_default_nand_part[] __initdata = {
273         [0] = {
274                 .name   = "u-boot",
275                 .size   = SZ_256K,
276                 .offset = 0,
277         },
278         [1] = {
279                 .name   = "u-boot-env",
280                 .size   = SZ_128K,
281                 .offset = SZ_256K,
282         },
283         [2] = {
284                 .name   = "kernel",
285                 /* 5 megabytes, for a kernel with no modules
286                  * or a uImage with a ramdisk attached
287                  */
288                 .size   = 0x00500000,
289                 .offset = SZ_256K + SZ_128K,
290         },
291         [3] = {
292                 .name   = "root",
293                 .offset = SZ_256K + SZ_128K + 0x00500000,
294                 .size   = MTDPART_SIZ_FULL,
295         },
296 };
297
298 static struct s3c2410_nand_set mini2440_nand_sets[] __initdata = {
299         [0] = {
300                 .name           = "nand",
301                 .nr_chips       = 1,
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 */
305         },
306 };
307
308 static struct s3c2410_platform_nand mini2440_nand_info __initdata = {
309         .tacls          = 0,
310         .twrph0         = 25,
311         .twrph1         = 15,
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,
316 };
317
318 /* DM9000AEP 10/100 ethernet controller */
319
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),
325 };
326
327 /*
328  * The DM9000 has no eeprom, and it's MAC address is set by
329  * the bootloader before starting the kernel.
330  */
331 static struct dm9000_plat_data mini2440_dm9k_pdata = {
332         .flags          = (DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM),
333 };
334
335 static struct platform_device mini2440_device_eth = {
336         .name           = "dm9000",
337         .id             = -1,
338         .num_resources  = ARRAY_SIZE(mini2440_dm9k_resource),
339         .resource       = mini2440_dm9k_resource,
340         .dev            = {
341                 .platform_data  = &mini2440_dm9k_pdata,
342         },
343 };
344
345 /*  CON5
346  *      +--+     /-----\
347  *      |  |    |       |
348  *      |  |    |  BAT  |
349  *      |  |     \_____/
350  *      |  |
351  *      |  |  +----+  +----+
352  *      |  |  | K5 |  | K1 |
353  *      |  |  +----+  +----+
354  *      |  |  +----+  +----+
355  *      |  |  | K4 |  | K2 |
356  *      |  |  +----+  +----+
357  *      |  |  +----+  +----+
358  *      |  |  | K6 |  | K3 |
359  *      |  |  +----+  +----+
360  *        .....
361  */
362 static struct gpio_keys_button mini2440_buttons[] = {
363         {
364                 .gpio           = S3C2410_GPG(0),               /* K1 */
365                 .code           = KEY_F1,
366                 .desc           = "Button 1",
367                 .active_low     = 1,
368         },
369         {
370                 .gpio           = S3C2410_GPG(3),               /* K2 */
371                 .code           = KEY_F2,
372                 .desc           = "Button 2",
373                 .active_low     = 1,
374         },
375         {
376                 .gpio           = S3C2410_GPG(5),               /* K3 */
377                 .code           = KEY_F3,
378                 .desc           = "Button 3",
379                 .active_low     = 1,
380         },
381         {
382                 .gpio           = S3C2410_GPG(6),               /* K4 */
383                 .code           = KEY_POWER,
384                 .desc           = "Power",
385                 .active_low     = 1,
386         },
387         {
388                 .gpio           = S3C2410_GPG(7),               /* K5 */
389                 .code           = KEY_F5,
390                 .desc           = "Button 5",
391                 .active_low     = 1,
392         },
393 #if 0
394         /* this pin is also known as TCLK1 and seems to already
395          * marked as "in use" somehow in the kernel -- possibly wrongly
396          */
397         {
398                 .gpio           = S3C2410_GPG(11),      /* K6 */
399                 .code           = KEY_F6,
400                 .desc           = "Button 6",
401                 .active_low     = 1,
402         },
403 #endif
404 };
405
406 static struct gpio_keys_platform_data mini2440_button_data = {
407         .buttons        = mini2440_buttons,
408         .nbuttons       = ARRAY_SIZE(mini2440_buttons),
409 };
410
411 static struct platform_device mini2440_button_device = {
412         .name           = "gpio-keys",
413         .id             = -1,
414         .dev            = {
415                 .platform_data  = &mini2440_button_data,
416         }
417 };
418
419 /* LEDS */
420
421 static struct gpiod_lookup_table mini2440_led1_gpio_table = {
422         .dev_id = "s3c24xx_led.1",
423         .table = {
424                 GPIO_LOOKUP("GPB", 5, NULL, GPIO_ACTIVE_LOW | GPIO_OPEN_DRAIN),
425                 { },
426         },
427 };
428
429 static struct gpiod_lookup_table mini2440_led2_gpio_table = {
430         .dev_id = "s3c24xx_led.2",
431         .table = {
432                 GPIO_LOOKUP("GPB", 6, NULL, GPIO_ACTIVE_LOW | GPIO_OPEN_DRAIN),
433                 { },
434         },
435 };
436
437 static struct gpiod_lookup_table mini2440_led3_gpio_table = {
438         .dev_id = "s3c24xx_led.3",
439         .table = {
440                 GPIO_LOOKUP("GPB", 7, NULL, GPIO_ACTIVE_LOW | GPIO_OPEN_DRAIN),
441                 { },
442         },
443 };
444
445 static struct gpiod_lookup_table mini2440_led4_gpio_table = {
446         .dev_id = "s3c24xx_led.4",
447         .table = {
448                 GPIO_LOOKUP("GPB", 8, NULL, GPIO_ACTIVE_LOW | GPIO_OPEN_DRAIN),
449                 { },
450         },
451 };
452
453 static struct gpiod_lookup_table mini2440_backlight_gpio_table = {
454         .dev_id = "s3c24xx_led.5",
455         .table = {
456                 GPIO_LOOKUP("GPG", 4, NULL, GPIO_ACTIVE_HIGH),
457                 { },
458         },
459 };
460
461 static struct s3c24xx_led_platdata mini2440_led1_pdata = {
462         .name           = "led1",
463         .def_trigger    = "heartbeat",
464 };
465
466 static struct s3c24xx_led_platdata mini2440_led2_pdata = {
467         .name           = "led2",
468         .def_trigger    = "nand-disk",
469 };
470
471 static struct s3c24xx_led_platdata mini2440_led3_pdata = {
472         .name           = "led3",
473         .def_trigger    = "mmc0",
474 };
475
476 static struct s3c24xx_led_platdata mini2440_led4_pdata = {
477         .name           = "led4",
478         .def_trigger    = "",
479 };
480
481 static struct s3c24xx_led_platdata mini2440_led_backlight_pdata = {
482         .name           = "backlight",
483         .def_trigger    = "backlight",
484 };
485
486 static struct platform_device mini2440_led1 = {
487         .name           = "s3c24xx_led",
488         .id             = 1,
489         .dev            = {
490                 .platform_data  = &mini2440_led1_pdata,
491         },
492 };
493
494 static struct platform_device mini2440_led2 = {
495         .name           = "s3c24xx_led",
496         .id             = 2,
497         .dev            = {
498                 .platform_data  = &mini2440_led2_pdata,
499         },
500 };
501
502 static struct platform_device mini2440_led3 = {
503         .name           = "s3c24xx_led",
504         .id             = 3,
505         .dev            = {
506                 .platform_data  = &mini2440_led3_pdata,
507         },
508 };
509
510 static struct platform_device mini2440_led4 = {
511         .name           = "s3c24xx_led",
512         .id             = 4,
513         .dev            = {
514                 .platform_data  = &mini2440_led4_pdata,
515         },
516 };
517
518 static struct platform_device mini2440_led_backlight = {
519         .name           = "s3c24xx_led",
520         .id             = 5,
521         .dev            = {
522                 .platform_data  = &mini2440_led_backlight_pdata,
523         },
524 };
525
526 /* AUDIO */
527
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
533 };
534
535 static struct platform_device mini2440_audio = {
536         .name           = "s3c24xx_uda134x",
537         .id             = 0,
538         .dev            = {
539                 .platform_data  = &mini2440_audio_pins,
540         },
541 };
542
543 /*
544  * I2C devices
545  */
546 static const struct property_entry mini2440_at24_properties[] = {
547         PROPERTY_ENTRY_U32("pagesize", 16),
548         { }
549 };
550
551 static const struct software_node mini2440_at24_node = {
552         .properties = mini2440_at24_properties,
553 };
554
555 static struct i2c_board_info mini2440_i2c_devs[] __initdata = {
556         {
557                 I2C_BOARD_INFO("24c08", 0x50),
558                 .swnode = &mini2440_at24_node,
559         },
560 };
561
562 static struct uda134x_platform_data s3c24xx_uda134x = {
563         .l3 = {
564                 .gpio_clk = S3C2410_GPB(4),
565                 .gpio_data = S3C2410_GPB(3),
566                 .gpio_mode = S3C2410_GPB(2),
567                 .use_gpios = 1,
568                 .data_hold = 1,
569                 .data_setup = 1,
570                 .clock_high = 1,
571                 .mode_hold = 1,
572                 .mode = 1,
573                 .mode_setup = 1,
574         },
575         .model = UDA134X_UDA1341,
576 };
577
578 static struct platform_device uda1340_codec = {
579                 .name = "uda134x-codec",
580                 .id = -1,
581                 .dev = {
582                         .platform_data  = &s3c24xx_uda134x,
583                 },
584 };
585
586 static struct platform_device *mini2440_devices[] __initdata = {
587         &s3c_device_ohci,
588         &s3c_device_wdt,
589         &s3c_device_i2c0,
590         &s3c_device_rtc,
591         &s3c_device_usbgadget,
592         &mini2440_device_eth,
593         &mini2440_led1,
594         &mini2440_led2,
595         &mini2440_led3,
596         &mini2440_led4,
597         &mini2440_button_device,
598         &s3c_device_nand,
599         &s3c_device_sdi,
600         &s3c2440_device_dma,
601         &s3c_device_iis,
602         &uda1340_codec,
603         &mini2440_audio,
604 };
605
606 static void __init mini2440_map_io(void)
607 {
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);
611 }
612
613 static void __init mini2440_init_time(void)
614 {
615         s3c2440_init_clocks(12000000);
616         s3c24xx_timer_init();
617 }
618
619 /*
620  * mini2440_features string
621  *
622  * t = Touchscreen present
623  * b = backlight control
624  * c = camera [TODO]
625  * 0-9 LCD configuration
626  *
627  */
628 static char mini2440_features_str[12] __initdata = "0tb";
629
630 static int __init mini2440_features_setup(char *str)
631 {
632         if (str)
633                 strscpy(mini2440_features_str, str,
634                         sizeof(mini2440_features_str));
635         return 1;
636 }
637
638 __setup("mini2440=", mini2440_features_setup);
639
640 #define FEATURE_SCREEN (1 << 0)
641 #define FEATURE_BACKLIGHT (1 << 1)
642 #define FEATURE_TOUCH (1 << 2)
643 #define FEATURE_CAMERA (1 << 3)
644
645 struct mini2440_features_t {
646         int count;
647         int done;
648         int lcd_index;
649         struct platform_device *optional[8];
650 };
651
652 static void __init mini2440_parse_features(
653                 struct mini2440_features_t *features,
654                 const char *features_str)
655 {
656         const char *fp = features_str;
657
658         features->count = 0;
659         features->done = 0;
660         features->lcd_index = -1;
661
662         while (*fp) {
663                 char f = *fp++;
664
665                 switch (f) {
666                 case '0'...'9': /* tft screen */
667                         if (features->done & FEATURE_SCREEN) {
668                                 pr_info("MINI2440: '%c' ignored, screen type already set\n",
669                                         f);
670                         } else {
671                                 int li = f - '0';
672
673                                 if (li >= ARRAY_SIZE(mini2440_lcd_cfg))
674                                         pr_info("MINI2440: '%c' out of range LCD mode\n",
675                                                 f);
676                                 else {
677                                         features->optional[features->count++] =
678                                                         &s3c_device_lcd;
679                                         features->lcd_index = li;
680                                 }
681                         }
682                         features->done |= FEATURE_SCREEN;
683                         break;
684                 case 'b':
685                         if (features->done & FEATURE_BACKLIGHT)
686                                 pr_info("MINI2440: '%c' ignored, backlight already set\n",
687                                         f);
688                         else {
689                                 features->optional[features->count++] =
690                                                 &mini2440_led_backlight;
691                         }
692                         features->done |= FEATURE_BACKLIGHT;
693                         break;
694                 case 't':
695                         pr_info("MINI2440: '%c' ignored, touchscreen not compiled in\n",
696                                 f);
697                         break;
698                 case 'c':
699                         if (features->done & FEATURE_CAMERA)
700                                 pr_info("MINI2440: '%c' ignored, camera already registered\n",
701                                         f);
702                         else
703                                 features->optional[features->count++] =
704                                         &s3c_device_camif;
705                         features->done |= FEATURE_CAMERA;
706                         break;
707                 }
708         }
709 }
710
711 static void __init mini2440_init(void)
712 {
713         struct mini2440_features_t features = { 0 };
714         int i;
715
716         pr_info("MINI2440: Option string mini2440=%s\n",
717                         mini2440_features_str);
718
719         /* Parse the feature string */
720         mini2440_parse_features(&features, mini2440_features_str);
721
722         /* turn LCD on */
723         s3c_gpio_cfgpin(S3C2410_GPC(0), S3C2410_GPC0_LEND);
724
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));
728
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));
733
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);
738         }
739
740         /* Configure the I2S pins (GPE0...GPE4) in correct mode */
741         s3c_gpio_cfgall_range(S3C2410_GPE(0), 5, S3C_GPIO_SFN(2),
742                               S3C_GPIO_PULL_NONE);
743
744         if (features.lcd_index != -1) {
745                 int li;
746
747                 mini2440_fb_info.displays =
748                         &mini2440_lcd_cfg[features.lcd_index];
749
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);
756                         else
757                                 pr_cont(" %d:%dx%d", li,
758                                         mini2440_lcd_cfg[li].width,
759                                         mini2440_lcd_cfg[li].height);
760                 pr_cont("\n");
761                 s3c24xx_fb_set_platdata(&mini2440_fb_info);
762         }
763
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);
770
771         i2c_register_board_info(0, mini2440_i2c_devs,
772                                 ARRAY_SIZE(mini2440_i2c_devs));
773
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);
780
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);
787
788         platform_add_devices(mini2440_devices, ARRAY_SIZE(mini2440_devices));
789
790         if (features.count)     /* the optional features */
791                 platform_add_devices(features.optional, features.count);
792
793 }
794
795
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,
804 MACHINE_END