gta02: Use pcf50633 backlight driver instead of platform backlight driver.
[sfrench/cifs-2.6.git] / arch / arm / mach-s3c2440 / mach-gta02.c
1 /*
2  * linux/arch/arm/mach-s3c2442/mach-gta02.c
3  *
4  * S3C2442 Machine Support for Openmoko GTA02 / FreeRunner.
5  *
6  * Copyright (C) 2006-2009 by Openmoko, Inc.
7  * Authors: Harald Welte <laforge@openmoko.org>
8  *          Andy Green <andy@openmoko.org>
9  *          Werner Almesberger <werner@openmoko.org>
10  * All rights reserved.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License as
14  * published by the Free Software Foundation; either version 2 of
15  * the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25  * MA 02111-1307 USA
26  *
27  */
28
29 #include <linux/kernel.h>
30 #include <linux/types.h>
31 #include <linux/interrupt.h>
32 #include <linux/list.h>
33 #include <linux/delay.h>
34 #include <linux/timer.h>
35 #include <linux/init.h>
36 #include <linux/gpio.h>
37 #include <linux/workqueue.h>
38 #include <linux/platform_device.h>
39 #include <linux/serial_core.h>
40 #include <linux/spi/spi.h>
41
42 #include <linux/mmc/host.h>
43
44 #include <linux/mtd/mtd.h>
45 #include <linux/mtd/nand.h>
46 #include <linux/mtd/nand_ecc.h>
47 #include <linux/mtd/partitions.h>
48 #include <linux/mtd/physmap.h>
49 #include <linux/io.h>
50
51 #include <linux/i2c.h>
52 #include <linux/regulator/machine.h>
53
54 #include <linux/mfd/pcf50633/core.h>
55 #include <linux/mfd/pcf50633/mbc.h>
56 #include <linux/mfd/pcf50633/adc.h>
57 #include <linux/mfd/pcf50633/gpio.h>
58 #include <linux/mfd/pcf50633/pmic.h>
59 #include <linux/mfd/pcf50633/backlight.h>
60
61 #include <asm/mach/arch.h>
62 #include <asm/mach/map.h>
63 #include <asm/mach/irq.h>
64
65 #include <asm/irq.h>
66 #include <asm/mach-types.h>
67
68 #include <mach/regs-irq.h>
69 #include <mach/regs-gpio.h>
70 #include <mach/regs-gpioj.h>
71 #include <mach/fb.h>
72
73 #include <mach/spi.h>
74 #include <mach/spi-gpio.h>
75 #include <plat/usb-control.h>
76 #include <mach/regs-mem.h>
77 #include <mach/hardware.h>
78
79 #include <mach/gta02.h>
80
81 #include <plat/regs-serial.h>
82 #include <plat/nand.h>
83 #include <plat/devs.h>
84 #include <plat/cpu.h>
85 #include <plat/pm.h>
86 #include <plat/udc.h>
87 #include <plat/gpio-cfg.h>
88 #include <plat/iic.h>
89
90 static struct pcf50633 *gta02_pcf;
91
92 /*
93  * This gets called every 1ms when we paniced.
94  */
95
96 static long gta02_panic_blink(long count)
97 {
98         long delay = 0;
99         static long last_blink;
100         static char led;
101
102         /* Fast blink: 200ms period. */
103         if (count - last_blink < 100)
104                 return 0;
105
106         led ^= 1;
107         gpio_direction_output(GTA02_GPIO_AUX_LED, led);
108
109         last_blink = count;
110
111         return delay;
112 }
113
114
115 static struct map_desc gta02_iodesc[] __initdata = {
116         {
117                 .virtual        = 0xe0000000,
118                 .pfn            = __phys_to_pfn(S3C2410_CS3 + 0x01000000),
119                 .length         = SZ_1M,
120                 .type           = MT_DEVICE
121         },
122 };
123
124 #define UCON (S3C2410_UCON_DEFAULT | S3C2443_UCON_RXERR_IRQEN)
125 #define ULCON (S3C2410_LCON_CS8 | S3C2410_LCON_PNONE | S3C2410_LCON_STOPB)
126 #define UFCON (S3C2410_UFCON_RXTRIG8 | S3C2410_UFCON_FIFOMODE)
127
128 static struct s3c2410_uartcfg gta02_uartcfgs[] = {
129         [0] = {
130                 .hwport         = 0,
131                 .flags          = 0,
132                 .ucon           = UCON,
133                 .ulcon          = ULCON,
134                 .ufcon          = UFCON,
135         },
136         [1] = {
137                 .hwport         = 1,
138                 .flags          = 0,
139                 .ucon           = UCON,
140                 .ulcon          = ULCON,
141                 .ufcon          = UFCON,
142         },
143         [2] = {
144                 .hwport         = 2,
145                 .flags          = 0,
146                 .ucon           = UCON,
147                 .ulcon          = ULCON,
148                 .ufcon          = UFCON,
149         },
150 };
151
152 #ifdef CONFIG_CHARGER_PCF50633
153 /*
154  * On GTA02 the 1A charger features a 48K resistor to 0V on the ID pin.
155  * We use this to recognize that we can pull 1A from the USB socket.
156  *
157  * These constants are the measured pcf50633 ADC levels with the 1A
158  * charger / 48K resistor, and with no pulldown resistor.
159  */
160
161 #define ADC_NOM_CHG_DETECT_1A 6
162 #define ADC_NOM_CHG_DETECT_USB 43
163
164 static void
165 gta02_configure_pmu_for_charger(struct pcf50633 *pcf, void *unused, int res)
166 {
167         int  ma;
168
169         /* Interpret charger type */
170         if (res < ((ADC_NOM_CHG_DETECT_USB + ADC_NOM_CHG_DETECT_1A) / 2)) {
171
172                 /*
173                  * Sanity - stop GPO driving out now that we have a 1A charger
174                  * GPO controls USB Host power generation on GTA02
175                  */
176                 pcf50633_gpio_set(pcf, PCF50633_GPO, 0);
177
178                 ma = 1000;
179         } else
180                 ma = 100;
181
182         pcf50633_mbc_usb_curlim_set(pcf, ma);
183 }
184
185 static struct delayed_work gta02_charger_work;
186 static int gta02_usb_vbus_draw;
187
188 static void gta02_charger_worker(struct work_struct *work)
189 {
190         if (gta02_usb_vbus_draw) {
191                 pcf50633_mbc_usb_curlim_set(gta02_pcf, gta02_usb_vbus_draw);
192                 return;
193         }
194
195 #ifdef CONFIG_PCF50633_ADC
196         pcf50633_adc_async_read(gta02_pcf,
197                                 PCF50633_ADCC1_MUX_ADCIN1,
198                                 PCF50633_ADCC1_AVERAGE_16,
199                                 gta02_configure_pmu_for_charger,
200                                 NULL);
201 #else
202         /*
203          * If the PCF50633 ADC is disabled we fallback to a
204          * 100mA limit for safety.
205          */
206         pcf50633_mbc_usb_curlim_set(pcf, 100);
207 #endif
208 }
209
210 #define GTA02_CHARGER_CONFIGURE_TIMEOUT ((3000 * HZ) / 1000)
211
212 static void gta02_pmu_event_callback(struct pcf50633 *pcf, int irq)
213 {
214         if (irq == PCF50633_IRQ_USBINS) {
215                 schedule_delayed_work(&gta02_charger_work,
216                                       GTA02_CHARGER_CONFIGURE_TIMEOUT);
217
218                 return;
219         }
220
221         if (irq == PCF50633_IRQ_USBREM) {
222                 cancel_delayed_work_sync(&gta02_charger_work);
223                 gta02_usb_vbus_draw = 0;
224         }
225 }
226
227 static void gta02_udc_vbus_draw(unsigned int ma)
228 {
229         if (!gta02_pcf)
230                 return;
231
232         gta02_usb_vbus_draw = ma;
233
234         schedule_delayed_work(&gta02_charger_work,
235                               GTA02_CHARGER_CONFIGURE_TIMEOUT);
236 }
237 #else /* !CONFIG_CHARGER_PCF50633 */
238 #define gta02_pmu_event_callback        NULL
239 #define gta02_udc_vbus_draw             NULL
240 #endif
241
242 /*
243  * This is called when pc50633 is probed, unfortunately quite late in the
244  * day since it is an I2C bus device. Here we can belatedly define some
245  * platform devices with the advantage that we can mark the pcf50633 as the
246  * parent. This makes them get suspended and resumed with their parent
247  * the pcf50633 still around.
248  */
249
250 static void gta02_pmu_attach_child_devices(struct pcf50633 *pcf);
251
252
253 static char *gta02_batteries[] = {
254         "battery",
255 };
256
257 static struct pcf50633_bl_platform_data gta02_backlight_data = {
258         .default_brightness = 0x3f,
259         .default_brightness_limit = 0,
260         .ramp_time = 5,
261 };
262
263 struct pcf50633_platform_data gta02_pcf_pdata = {
264         .resumers = {
265                 [0] =   PCF50633_INT1_USBINS |
266                         PCF50633_INT1_USBREM |
267                         PCF50633_INT1_ALARM,
268                 [1] =   PCF50633_INT2_ONKEYF,
269                 [2] =   PCF50633_INT3_ONKEY1S,
270                 [3] =   PCF50633_INT4_LOWSYS |
271                         PCF50633_INT4_LOWBAT |
272                         PCF50633_INT4_HIGHTMP,
273         },
274
275         .batteries = gta02_batteries,
276         .num_batteries = ARRAY_SIZE(gta02_batteries),
277
278         .charger_reference_current_ma = 1000,
279
280         .backlight_data = &gta02_backlight_data,
281
282         .reg_init_data = {
283                 [PCF50633_REGULATOR_AUTO] = {
284                         .constraints = {
285                                 .min_uV = 3300000,
286                                 .max_uV = 3300000,
287                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
288                                 .always_on = 1,
289                                 .apply_uV = 1,
290                                 .state_mem = {
291                                         .enabled = 1,
292                                 },
293                         },
294                 },
295                 [PCF50633_REGULATOR_DOWN1] = {
296                         .constraints = {
297                                 .min_uV = 1300000,
298                                 .max_uV = 1600000,
299                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
300                                 .always_on = 1,
301                                 .apply_uV = 1,
302                         },
303                 },
304                 [PCF50633_REGULATOR_DOWN2] = {
305                         .constraints = {
306                                 .min_uV = 1800000,
307                                 .max_uV = 1800000,
308                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
309                                 .apply_uV = 1,
310                                 .always_on = 1,
311                                 .state_mem = {
312                                         .enabled = 1,
313                                 },
314                         },
315                 },
316                 [PCF50633_REGULATOR_HCLDO] = {
317                         .constraints = {
318                                 .min_uV = 2000000,
319                                 .max_uV = 3300000,
320                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
321                                 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
322                                 .always_on = 1,
323                         },
324                 },
325                 [PCF50633_REGULATOR_LDO1] = {
326                         .constraints = {
327                                 .min_uV = 3300000,
328                                 .max_uV = 3300000,
329                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
330                                 .apply_uV = 1,
331                                 .state_mem = {
332                                         .enabled = 0,
333                                 },
334                         },
335                 },
336                 [PCF50633_REGULATOR_LDO2] = {
337                         .constraints = {
338                                 .min_uV = 3300000,
339                                 .max_uV = 3300000,
340                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
341                                 .apply_uV = 1,
342                         },
343                 },
344                 [PCF50633_REGULATOR_LDO3] = {
345                         .constraints = {
346                                 .min_uV = 3000000,
347                                 .max_uV = 3000000,
348                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
349                                 .apply_uV = 1,
350                         },
351                 },
352                 [PCF50633_REGULATOR_LDO4] = {
353                         .constraints = {
354                                 .min_uV = 3200000,
355                                 .max_uV = 3200000,
356                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
357                                 .apply_uV = 1,
358                         },
359                 },
360                 [PCF50633_REGULATOR_LDO5] = {
361                         .constraints = {
362                                 .min_uV = 3000000,
363                                 .max_uV = 3000000,
364                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
365                                 .apply_uV = 1,
366                                 .state_mem = {
367                                         .enabled = 1,
368                                 },
369                         },
370                 },
371                 [PCF50633_REGULATOR_LDO6] = {
372                         .constraints = {
373                                 .min_uV = 3000000,
374                                 .max_uV = 3000000,
375                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
376                         },
377                 },
378                 [PCF50633_REGULATOR_MEMLDO] = {
379                         .constraints = {
380                                 .min_uV = 1800000,
381                                 .max_uV = 1800000,
382                                 .valid_modes_mask = REGULATOR_MODE_NORMAL,
383                                 .state_mem = {
384                                         .enabled = 1,
385                                 },
386                         },
387                 },
388
389         },
390         .probe_done = gta02_pmu_attach_child_devices,
391         .mbc_event_callback = gta02_pmu_event_callback,
392 };
393
394
395 /* NOR Flash. */
396
397 #define GTA02_FLASH_BASE        0x18000000 /* GCS3 */
398 #define GTA02_FLASH_SIZE        0x200000 /* 2MBytes */
399
400 static struct physmap_flash_data gta02_nor_flash_data = {
401         .width          = 2,
402 };
403
404 static struct resource gta02_nor_flash_resource = {
405         .start          = GTA02_FLASH_BASE,
406         .end            = GTA02_FLASH_BASE + GTA02_FLASH_SIZE - 1,
407         .flags          = IORESOURCE_MEM,
408 };
409
410 static struct platform_device gta02_nor_flash = {
411         .name           = "physmap-flash",
412         .id             = 0,
413         .dev            = {
414                 .platform_data  = &gta02_nor_flash_data,
415         },
416         .resource       = &gta02_nor_flash_resource,
417         .num_resources  = 1,
418 };
419
420
421 struct platform_device s3c24xx_pwm_device = {
422         .name           = "s3c24xx_pwm",
423         .num_resources  = 0,
424 };
425
426 static struct i2c_board_info gta02_i2c_devs[] __initdata = {
427         {
428                 I2C_BOARD_INFO("pcf50633", 0x73),
429                 .irq = GTA02_IRQ_PCF50633,
430                 .platform_data = &gta02_pcf_pdata,
431         },
432         {
433                 I2C_BOARD_INFO("wm8753", 0x1a),
434         },
435 };
436
437 static struct s3c2410_nand_set __initdata gta02_nand_sets[] = {
438         [0] = {
439                 /*
440                  * This name is also hard-coded in the boot loaders, so
441                  * changing it would would require all users to upgrade
442                  * their boot loaders, some of which are stored in a NOR
443                  * that is considered to be immutable.
444                  */
445                 .name           = "neo1973-nand",
446                 .nr_chips       = 1,
447                 .flash_bbt      = 1,
448         },
449 };
450
451 /*
452  * Choose a set of timings derived from S3C@2442B MCP54
453  * data sheet (K5D2G13ACM-D075 MCP Memory).
454  */
455
456 static struct s3c2410_platform_nand __initdata gta02_nand_info = {
457         .tacls          = 0,
458         .twrph0         = 25,
459         .twrph1         = 15,
460         .nr_sets        = ARRAY_SIZE(gta02_nand_sets),
461         .sets           = gta02_nand_sets,
462 };
463
464
465 static void gta02_udc_command(enum s3c2410_udc_cmd_e cmd)
466 {
467         switch (cmd) {
468         case S3C2410_UDC_P_ENABLE:
469                 pr_debug("%s S3C2410_UDC_P_ENABLE\n", __func__);
470                 gpio_direction_output(GTA02_GPIO_USB_PULLUP, 1);
471                 break;
472         case S3C2410_UDC_P_DISABLE:
473                 pr_debug("%s S3C2410_UDC_P_DISABLE\n", __func__);
474                 gpio_direction_output(GTA02_GPIO_USB_PULLUP, 0);
475                 break;
476         case S3C2410_UDC_P_RESET:
477                 pr_debug("%s S3C2410_UDC_P_RESET\n", __func__);
478                 /* FIXME: Do something here. */
479         }
480 }
481
482 /* Get PMU to set USB current limit accordingly. */
483 static struct s3c2410_udc_mach_info gta02_udc_cfg = {
484         .vbus_draw      = gta02_udc_vbus_draw,
485         .udc_command    = gta02_udc_command,
486
487 };
488
489 /* USB */
490 static struct s3c2410_hcd_info gta02_usb_info __initdata = {
491         .port[0]        = {
492                 .flags  = S3C_HCDFLG_USED,
493         },
494         .port[1]        = {
495                 .flags  = 0,
496         },
497 };
498
499
500 static void __init gta02_map_io(void)
501 {
502         s3c24xx_init_io(gta02_iodesc, ARRAY_SIZE(gta02_iodesc));
503         s3c24xx_init_clocks(12000000);
504         s3c24xx_init_uarts(gta02_uartcfgs, ARRAY_SIZE(gta02_uartcfgs));
505 }
506
507
508 /* These are the guys that don't need to be children of PMU. */
509
510 static struct platform_device *gta02_devices[] __initdata = {
511         &s3c_device_ohci,
512         &s3c_device_wdt,
513         &s3c_device_sdi,
514         &s3c_device_usbgadget,
515         &s3c_device_nand,
516         &gta02_nor_flash,
517         &s3c24xx_pwm_device,
518         &s3c_device_iis,
519         &s3c_device_i2c0,
520 };
521
522 /* These guys DO need to be children of PMU. */
523
524 static struct platform_device *gta02_devices_pmu_children[] = {
525 };
526
527
528 /*
529  * This is called when pc50633 is probed, quite late in the day since it is an
530  * I2C bus device.  Here we can define platform devices with the advantage that
531  * we can mark the pcf50633 as the parent.  This makes them get suspended and
532  * resumed with their parent the pcf50633 still around.  All devices whose
533  * operation depends on something from pcf50633 must have this relationship
534  * made explicit like this, or suspend and resume will become an unreliable
535  * hellworld.
536  */
537
538 static void gta02_pmu_attach_child_devices(struct pcf50633 *pcf)
539 {
540         int n;
541
542         /* Grab a copy of the now probed PMU pointer. */
543         gta02_pcf = pcf;
544
545         for (n = 0; n < ARRAY_SIZE(gta02_devices_pmu_children); n++)
546                 gta02_devices_pmu_children[n]->dev.parent = pcf->dev;
547
548         platform_add_devices(gta02_devices_pmu_children,
549                              ARRAY_SIZE(gta02_devices_pmu_children));
550 }
551
552 static void gta02_poweroff(void)
553 {
554         pcf50633_reg_set_bit_mask(gta02_pcf, PCF50633_REG_OOCSHDWN, 1, 1);
555 }
556
557 static void __init gta02_machine_init(void)
558 {
559         /* Set the panic callback to make AUX LED blink at ~5Hz. */
560         panic_blink = gta02_panic_blink;
561
562         s3c_pm_init();
563
564 #ifdef CONFIG_CHARGER_PCF50633
565         INIT_DELAYED_WORK(&gta02_charger_work, gta02_charger_worker);
566 #endif
567
568         s3c24xx_udc_set_platdata(&gta02_udc_cfg);
569         s3c_ohci_set_platdata(&gta02_usb_info);
570         s3c_nand_set_platdata(&gta02_nand_info);
571         s3c_i2c0_set_platdata(NULL);
572
573         i2c_register_board_info(0, gta02_i2c_devs, ARRAY_SIZE(gta02_i2c_devs));
574
575         platform_add_devices(gta02_devices, ARRAY_SIZE(gta02_devices));
576         pm_power_off = gta02_poweroff;
577 }
578
579
580 MACHINE_START(NEO1973_GTA02, "GTA02")
581         /* Maintainer: Nelson Castillo <arhuaco@freaks-unidos.net> */
582         .phys_io        = S3C2410_PA_UART,
583         .io_pg_offst    = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
584         .boot_params    = S3C2410_SDRAM_PA + 0x100,
585         .map_io         = gta02_map_io,
586         .init_irq       = s3c24xx_init_irq,
587         .init_machine   = gta02_machine_init,
588         .timer          = &s3c24xx_timer,
589 MACHINE_END