Merge tag 'mtd/for-5.10' of git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux
[platform/kernel/linux-starfive.git] / arch / arm / mach-s3c24xx / mach-gta02.c
1 // SPDX-License-Identifier: GPL-2.0+
2 //
3 // S3C2442 Machine Support for Openmoko GTA02 / FreeRunner.
4 //
5 // Copyright (C) 2006-2009 by Openmoko, Inc.
6 // Authors: Harald Welte <laforge@openmoko.org>
7 //          Andy Green <andy@openmoko.org>
8 //          Werner Almesberger <werner@openmoko.org>
9 // All rights reserved.
10
11 #include <linux/kernel.h>
12 #include <linux/types.h>
13 #include <linux/interrupt.h>
14 #include <linux/list.h>
15 #include <linux/delay.h>
16 #include <linux/timer.h>
17 #include <linux/init.h>
18 #include <linux/gpio/machine.h>
19 #include <linux/gpio.h>
20 #include <linux/gpio_keys.h>
21 #include <linux/workqueue.h>
22 #include <linux/platform_device.h>
23 #include <linux/serial_core.h>
24 #include <linux/serial_s3c.h>
25 #include <linux/input.h>
26 #include <linux/io.h>
27 #include <linux/i2c.h>
28
29 #include <linux/mmc/host.h>
30
31 #include <linux/mfd/pcf50633/adc.h>
32 #include <linux/mfd/pcf50633/backlight.h>
33 #include <linux/mfd/pcf50633/core.h>
34 #include <linux/mfd/pcf50633/gpio.h>
35 #include <linux/mfd/pcf50633/mbc.h>
36 #include <linux/mfd/pcf50633/pmic.h>
37
38 #include <linux/mtd/mtd.h>
39 #include <linux/mtd/rawnand.h>
40 #include <linux/mtd/nand_ecc.h>
41 #include <linux/mtd/partitions.h>
42 #include <linux/mtd/physmap.h>
43
44 #include <linux/regulator/machine.h>
45
46 #include <linux/spi/spi.h>
47 #include <linux/spi/s3c24xx.h>
48
49 #include <asm/irq.h>
50 #include <asm/mach-types.h>
51 #include <asm/mach/arch.h>
52 #include <asm/mach/map.h>
53 #include <asm/mach/irq.h>
54
55 #include <linux/platform_data/i2c-s3c2410.h>
56 #include <linux/platform_data/mtd-nand-s3c2410.h>
57 #include <linux/platform_data/touchscreen-s3c2410.h>
58 #include <linux/platform_data/usb-ohci-s3c2410.h>
59 #include <linux/platform_data/usb-s3c2410_udc.h>
60
61 #include <mach/fb.h>
62 #include <mach/hardware.h>
63 #include <mach/regs-gpio.h>
64 #include <mach/regs-irq.h>
65 #include <mach/gpio-samsung.h>
66
67 #include <plat/cpu.h>
68 #include <plat/devs.h>
69 #include <plat/gpio-cfg.h>
70 #include <plat/pm.h>
71 #include <plat/samsung-time.h>
72
73 #include "common.h"
74 #include "gta02.h"
75
76 static struct pcf50633 *gta02_pcf;
77
78 /*
79  * This gets called frequently when we paniced.
80  */
81
82 static long gta02_panic_blink(int state)
83 {
84         long delay = 0;
85         char led;
86
87         led = (state) ? 1 : 0;
88         gpio_direction_output(GTA02_GPIO_AUX_LED, led);
89
90         return delay;
91 }
92
93
94 static struct map_desc gta02_iodesc[] __initdata = {
95         {
96                 .virtual        = 0xe0000000,
97                 .pfn            = __phys_to_pfn(S3C2410_CS3 + 0x01000000),
98                 .length         = SZ_1M,
99                 .type           = MT_DEVICE
100         },
101 };
102
103 #define UCON (S3C2410_UCON_DEFAULT | S3C2443_UCON_RXERR_IRQEN)
104 #define ULCON (S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB)
105 #define UFCON (S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE)
106
107 static struct s3c2410_uartcfg gta02_uartcfgs[] = {
108         [0] = {
109                 .hwport         = 0,
110                 .flags          = 0,
111                 .ucon           = UCON,
112                 .ulcon          = ULCON,
113                 .ufcon          = UFCON,
114         },
115         [1] = {
116                 .hwport         = 1,
117                 .flags          = 0,
118                 .ucon           = UCON,
119                 .ulcon          = ULCON,
120                 .ufcon          = UFCON,
121         },
122         [2] = {
123                 .hwport         = 2,
124                 .flags          = 0,
125                 .ucon           = UCON,
126                 .ulcon          = ULCON,
127                 .ufcon          = UFCON,
128         },
129 };
130
131 #ifdef CONFIG_CHARGER_PCF50633
132 /*
133  * On GTA02 the 1A charger features a 48K resistor to 0V on the ID pin.
134  * We use this to recognize that we can pull 1A from the USB socket.
135  *
136  * These constants are the measured pcf50633 ADC levels with the 1A
137  * charger / 48K resistor, and with no pulldown resistor.
138  */
139
140 #define ADC_NOM_CHG_DETECT_1A 6
141 #define ADC_NOM_CHG_DETECT_USB 43
142
143 #ifdef CONFIG_PCF50633_ADC
144 static void
145 gta02_configure_pmu_for_charger(struct pcf50633 *pcf, void *unused, int res)
146 {
147         int  ma;
148
149         /* Interpret charger type */
150         if (res < ((ADC_NOM_CHG_DETECT_USB + ADC_NOM_CHG_DETECT_1A) / 2)) {
151
152                 /*
153                  * Sanity - stop GPO driving out now that we have a 1A charger
154                  * GPO controls USB Host power generation on GTA02
155                  */
156                 pcf50633_gpio_set(pcf, PCF50633_GPO, 0);
157
158                 ma = 1000;
159         } else
160                 ma = 100;
161
162         pcf50633_mbc_usb_curlim_set(pcf, ma);
163 }
164 #endif
165
166 static struct delayed_work gta02_charger_work;
167 static int gta02_usb_vbus_draw;
168
169 static void gta02_charger_worker(struct work_struct *work)
170 {
171         if (gta02_usb_vbus_draw) {
172                 pcf50633_mbc_usb_curlim_set(gta02_pcf, gta02_usb_vbus_draw);
173                 return;
174         }
175
176 #ifdef CONFIG_PCF50633_ADC
177         pcf50633_adc_async_read(gta02_pcf,
178                                 PCF50633_ADCC1_MUX_ADCIN1,
179                                 PCF50633_ADCC1_AVERAGE_16,
180                                 gta02_configure_pmu_for_charger,
181                                 NULL);
182 #else
183         /*
184          * If the PCF50633 ADC is disabled we fallback to a
185          * 100mA limit for safety.
186          */
187         pcf50633_mbc_usb_curlim_set(gta02_pcf, 100);
188 #endif
189 }
190
191 #define GTA02_CHARGER_CONFIGURE_TIMEOUT ((3000 * HZ) / 1000)
192
193 static void gta02_pmu_event_callback(struct pcf50633 *pcf, int irq)
194 {
195         if (irq == PCF50633_IRQ_USBINS) {
196                 schedule_delayed_work(&gta02_charger_work,
197                                       GTA02_CHARGER_CONFIGURE_TIMEOUT);
198
199                 return;
200         }
201
202         if (irq == PCF50633_IRQ_USBREM) {
203                 cancel_delayed_work_sync(&gta02_charger_work);
204                 gta02_usb_vbus_draw = 0;
205         }
206 }
207
208 static void gta02_udc_vbus_draw(unsigned int ma)
209 {
210         if (!gta02_pcf)
211                 return;
212
213         gta02_usb_vbus_draw = ma;
214
215         schedule_delayed_work(&gta02_charger_work,
216                               GTA02_CHARGER_CONFIGURE_TIMEOUT);
217 }
218 #else /* !CONFIG_CHARGER_PCF50633 */
219 #define gta02_pmu_event_callback        NULL
220 #define gta02_udc_vbus_draw             NULL
221 #endif
222
223 static char *gta02_batteries[] = {
224         "battery",
225 };
226
227 static struct pcf50633_bl_platform_data gta02_backlight_data = {
228         .default_brightness = 0x3f,
229         .default_brightness_limit = 0,
230         .ramp_time = 5,
231 };
232
233 static struct pcf50633_platform_data gta02_pcf_pdata = {
234         .resumers = {
235                 [0] =   PCF50633_INT1_USBINS |
236                         PCF50633_INT1_USBREM |
237                         PCF50633_INT1_ALARM,
238                 [1] =   PCF50633_INT2_ONKEYF,
239                 [2] =   PCF50633_INT3_ONKEY1S,
240                 [3] =   PCF50633_INT4_LOWSYS |
241                         PCF50633_INT4_LOWBAT |
242                         PCF50633_INT4_HIGHTMP,
243         },
244
245         .batteries = gta02_batteries,
246         .num_batteries = ARRAY_SIZE(gta02_batteries),
247
248         .charger_reference_current_ma = 1000,
249
250         .backlight_data = &gta02_backlight_data,
251
252         .reg_init_data = {
253                 [PCF50633_REGULATOR_AUTO] = {
254                         .constraints = {
255                                 .min_uV = 3300000,
256                                 .max_uV = 3300000,
257                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
258                                 .always_on = 1,
259                                 .apply_uV = 1,
260                         },
261                 },
262                 [PCF50633_REGULATOR_DOWN1] = {
263                         .constraints = {
264                                 .min_uV = 1300000,
265                                 .max_uV = 1600000,
266                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
267                                 .always_on = 1,
268                                 .apply_uV = 1,
269                         },
270                 },
271                 [PCF50633_REGULATOR_DOWN2] = {
272                         .constraints = {
273                                 .min_uV = 1800000,
274                                 .max_uV = 1800000,
275                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
276                                 .apply_uV = 1,
277                                 .always_on = 1,
278                         },
279                 },
280                 [PCF50633_REGULATOR_HCLDO] = {
281                         .constraints = {
282                                 .min_uV = 2000000,
283                                 .max_uV = 3300000,
284                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
285                                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
286                                                 REGULATOR_CHANGE_STATUS,
287                         },
288                 },
289                 [PCF50633_REGULATOR_LDO1] = {
290                         .constraints = {
291                                 .min_uV = 3300000,
292                                 .max_uV = 3300000,
293                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
294                                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
295                                 .apply_uV = 1,
296                         },
297                 },
298                 [PCF50633_REGULATOR_LDO2] = {
299                         .constraints = {
300                                 .min_uV = 3300000,
301                                 .max_uV = 3300000,
302                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
303                                 .apply_uV = 1,
304                         },
305                 },
306                 [PCF50633_REGULATOR_LDO3] = {
307                         .constraints = {
308                                 .min_uV = 3000000,
309                                 .max_uV = 3000000,
310                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
311                                 .apply_uV = 1,
312                         },
313                 },
314                 [PCF50633_REGULATOR_LDO4] = {
315                         .constraints = {
316                                 .min_uV = 3200000,
317                                 .max_uV = 3200000,
318                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
319                                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
320                                 .apply_uV = 1,
321                         },
322                 },
323                 [PCF50633_REGULATOR_LDO5] = {
324                         .constraints = {
325                                 .min_uV = 3000000,
326                                 .max_uV = 3000000,
327                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
328                                 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
329                                 .apply_uV = 1,
330                         },
331                 },
332                 [PCF50633_REGULATOR_LDO6] = {
333                         .constraints = {
334                                 .min_uV = 3000000,
335                                 .max_uV = 3000000,
336                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
337                         },
338                 },
339                 [PCF50633_REGULATOR_MEMLDO] = {
340                         .constraints = {
341                                 .min_uV = 1800000,
342                                 .max_uV = 1800000,
343                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
344                         },
345                 },
346
347         },
348         .mbc_event_callback = gta02_pmu_event_callback,
349 };
350
351
352 /* NOR Flash. */
353
354 #define GTA02_FLASH_BASE        0x18000000 /* GCS3 */
355 #define GTA02_FLASH_SIZE        0x200000 /* 2MBytes */
356
357 static struct physmap_flash_data gta02_nor_flash_data = {
358         .width          = 2,
359 };
360
361 static struct resource gta02_nor_flash_resource =
362         DEFINE_RES_MEM(GTA02_FLASH_BASE, GTA02_FLASH_SIZE);
363
364 static struct platform_device gta02_nor_flash = {
365         .name           = "physmap-flash",
366         .id             = 0,
367         .dev            = {
368                 .platform_data  = &gta02_nor_flash_data,
369         },
370         .resource       = &gta02_nor_flash_resource,
371         .num_resources  = 1,
372 };
373
374
375 static struct platform_device s3c24xx_pwm_device = {
376         .name           = "s3c24xx_pwm",
377         .num_resources  = 0,
378 };
379
380 static struct platform_device gta02_dfbmcs320_device = {
381         .name = "dfbmcs320",
382 };
383
384 static struct i2c_board_info gta02_i2c_devs[] __initdata = {
385         {
386                 I2C_BOARD_INFO("pcf50633", 0x73),
387                 .irq = GTA02_IRQ_PCF50633,
388                 .platform_data = &gta02_pcf_pdata,
389         },
390         {
391                 I2C_BOARD_INFO("wm8753", 0x1a),
392         },
393 };
394
395 static struct s3c2410_nand_set __initdata gta02_nand_sets[] = {
396         [0] = {
397                 /*
398                  * This name is also hard-coded in the boot loaders, so
399                  * changing it would would require all users to upgrade
400                  * their boot loaders, some of which are stored in a NOR
401                  * that is considered to be immutable.
402                  */
403                 .name           = "neo1973-nand",
404                 .nr_chips       = 1,
405                 .flash_bbt      = 1,
406         },
407 };
408
409 /*
410  * Choose a set of timings derived from S3C@2442B MCP54
411  * data sheet (K5D2G13ACM-D075 MCP Memory).
412  */
413
414 static struct s3c2410_platform_nand __initdata gta02_nand_info = {
415         .tacls          = 0,
416         .twrph0         = 25,
417         .twrph1         = 15,
418         .nr_sets        = ARRAY_SIZE(gta02_nand_sets),
419         .sets           = gta02_nand_sets,
420         .engine_type    = NAND_ECC_ENGINE_TYPE_SOFT,
421 };
422
423
424 /* Get PMU to set USB current limit accordingly. */
425 static struct s3c2410_udc_mach_info gta02_udc_cfg __initdata = {
426         .vbus_draw      = gta02_udc_vbus_draw,
427         .pullup_pin = GTA02_GPIO_USB_PULLUP,
428 };
429
430 /* USB */
431 static struct s3c2410_hcd_info gta02_usb_info __initdata = {
432         .port[0]        = {
433                 .flags  = S3C_HCDFLG_USED,
434         },
435         .port[1]        = {
436                 .flags  = 0,
437         },
438 };
439
440 /* Touchscreen */
441 static struct s3c2410_ts_mach_info gta02_ts_info = {
442         .delay                  = 10000,
443         .presc                  = 0xff, /* slow as we can go */
444         .oversampling_shift     = 2,
445 };
446
447 /* Buttons */
448 static struct gpio_keys_button gta02_buttons[] = {
449         {
450                 .gpio = GTA02_GPIO_AUX_KEY,
451                 .code = KEY_PHONE,
452                 .desc = "Aux",
453                 .type = EV_KEY,
454                 .debounce_interval = 100,
455         },
456         {
457                 .gpio = GTA02_GPIO_HOLD_KEY,
458                 .code = KEY_PAUSE,
459                 .desc = "Hold",
460                 .type = EV_KEY,
461                 .debounce_interval = 100,
462         },
463 };
464
465 static struct gpio_keys_platform_data gta02_buttons_pdata = {
466         .buttons = gta02_buttons,
467         .nbuttons = ARRAY_SIZE(gta02_buttons),
468 };
469
470 static struct platform_device gta02_buttons_device = {
471         .name = "gpio-keys",
472         .id = -1,
473         .dev = {
474                 .platform_data = &gta02_buttons_pdata,
475         },
476 };
477
478 static struct gpiod_lookup_table gta02_audio_gpio_table = {
479         .dev_id = "neo1973-audio",
480         .table = {
481                 GPIO_LOOKUP("GPIOJ", 2, "amp-shut", GPIO_ACTIVE_HIGH),
482                 GPIO_LOOKUP("GPIOJ", 1, "hp", GPIO_ACTIVE_HIGH),
483                 { },
484         },
485 };
486
487 static struct platform_device gta02_audio = {
488         .name = "neo1973-audio",
489         .id = -1,
490 };
491
492 static void __init gta02_map_io(void)
493 {
494         s3c24xx_init_io(gta02_iodesc, ARRAY_SIZE(gta02_iodesc));
495         s3c24xx_init_uarts(gta02_uartcfgs, ARRAY_SIZE(gta02_uartcfgs));
496         samsung_set_timer_source(SAMSUNG_PWM3, SAMSUNG_PWM4);
497 }
498
499
500 /* These are the guys that don't need to be children of PMU. */
501
502 static struct platform_device *gta02_devices[] __initdata = {
503         &s3c_device_ohci,
504         &s3c_device_wdt,
505         &s3c_device_sdi,
506         &s3c_device_usbgadget,
507         &s3c_device_nand,
508         &gta02_nor_flash,
509         &s3c24xx_pwm_device,
510         &s3c_device_iis,
511         &s3c_device_i2c0,
512         &gta02_dfbmcs320_device,
513         &gta02_buttons_device,
514         &s3c_device_adc,
515         &s3c_device_ts,
516         &gta02_audio,
517 };
518
519 static void gta02_poweroff(void)
520 {
521         pcf50633_reg_set_bit_mask(gta02_pcf, PCF50633_REG_OOCSHDWN, 1, 1);
522 }
523
524 static void __init gta02_machine_init(void)
525 {
526         /* Set the panic callback to turn AUX LED on or off. */
527         panic_blink = gta02_panic_blink;
528
529         s3c_pm_init();
530
531 #ifdef CONFIG_CHARGER_PCF50633
532         INIT_DELAYED_WORK(&gta02_charger_work, gta02_charger_worker);
533 #endif
534
535         s3c24xx_udc_set_platdata(&gta02_udc_cfg);
536         s3c24xx_ts_set_platdata(&gta02_ts_info);
537         s3c_ohci_set_platdata(&gta02_usb_info);
538         s3c_nand_set_platdata(&gta02_nand_info);
539         s3c_i2c0_set_platdata(NULL);
540
541         i2c_register_board_info(0, gta02_i2c_devs, ARRAY_SIZE(gta02_i2c_devs));
542
543         gpiod_add_lookup_table(&gta02_audio_gpio_table);
544         platform_add_devices(gta02_devices, ARRAY_SIZE(gta02_devices));
545         pm_power_off = gta02_poweroff;
546
547         regulator_has_full_constraints();
548 }
549
550 static void __init gta02_init_time(void)
551 {
552         s3c2442_init_clocks(12000000);
553         samsung_timer_init();
554 }
555
556 MACHINE_START(NEO1973_GTA02, "GTA02")
557         /* Maintainer: Nelson Castillo <arhuaco@freaks-unidos.net> */
558         .atag_offset    = 0x100,
559         .map_io         = gta02_map_io,
560         .init_irq       = s3c2442_init_irq,
561         .init_machine   = gta02_machine_init,
562         .init_time      = gta02_init_time,
563 MACHINE_END