]> git.karo-electronics.de Git - mv-sheeva.git/blob - arch/arm/mach-omap2/board-n8x0.c
ASoC: multi-component - ASoC Multi-Component Support
[mv-sheeva.git] / arch / arm / mach-omap2 / board-n8x0.c
1 /*
2  * linux/arch/arm/mach-omap2/board-n8x0.c
3  *
4  * Copyright (C) 2005-2009 Nokia Corporation
5  * Author: Juha Yrjola <juha.yrjola@nokia.com>
6  *
7  * Modified from mach-omap2/board-generic.c
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  */
13
14 #include <linux/clk.h>
15 #include <linux/delay.h>
16 #include <linux/gpio.h>
17 #include <linux/init.h>
18 #include <linux/io.h>
19 #include <linux/stddef.h>
20 #include <linux/i2c.h>
21 #include <linux/spi/spi.h>
22 #include <linux/usb/musb.h>
23 #include <sound/tlv320aic3x.h>
24
25 #include <asm/mach/arch.h>
26 #include <asm/mach-types.h>
27
28 #include <plat/board.h>
29 #include <plat/common.h>
30 #include <plat/menelaus.h>
31 #include <mach/irqs.h>
32 #include <plat/mcspi.h>
33 #include <plat/onenand.h>
34 #include <plat/mmc.h>
35 #include <plat/serial.h>
36
37 static int slot1_cover_open;
38 static int slot2_cover_open;
39 static struct device *mmc_device;
40
41 #define TUSB6010_ASYNC_CS       1
42 #define TUSB6010_SYNC_CS        4
43 #define TUSB6010_GPIO_INT       58
44 #define TUSB6010_GPIO_ENABLE    0
45 #define TUSB6010_DMACHAN        0x3f
46
47 #if defined(CONFIG_USB_TUSB6010) || \
48         defined(CONFIG_USB_TUSB6010_MODULE)
49 /*
50  * Enable or disable power to TUSB6010. When enabling, turn on 3.3 V and
51  * 1.5 V voltage regulators of PM companion chip. Companion chip will then
52  * provide then PGOOD signal to TUSB6010 which will release it from reset.
53  */
54 static int tusb_set_power(int state)
55 {
56         int i, retval = 0;
57
58         if (state) {
59                 gpio_set_value(TUSB6010_GPIO_ENABLE, 1);
60                 msleep(1);
61
62                 /* Wait until TUSB6010 pulls INT pin down */
63                 i = 100;
64                 while (i && gpio_get_value(TUSB6010_GPIO_INT)) {
65                         msleep(1);
66                         i--;
67                 }
68
69                 if (!i) {
70                         printk(KERN_ERR "tusb: powerup failed\n");
71                         retval = -ENODEV;
72                 }
73         } else {
74                 gpio_set_value(TUSB6010_GPIO_ENABLE, 0);
75                 msleep(10);
76         }
77
78         return retval;
79 }
80
81 static struct musb_hdrc_config musb_config = {
82         .multipoint     = 1,
83         .dyn_fifo       = 1,
84         .num_eps        = 16,
85         .ram_bits       = 12,
86 };
87
88 static struct musb_hdrc_platform_data tusb_data = {
89 #if defined(CONFIG_USB_MUSB_OTG)
90         .mode           = MUSB_OTG,
91 #elif defined(CONFIG_USB_MUSB_PERIPHERAL)
92         .mode           = MUSB_PERIPHERAL,
93 #else /* defined(CONFIG_USB_MUSB_HOST) */
94         .mode           = MUSB_HOST,
95 #endif
96         .set_power      = tusb_set_power,
97         .min_power      = 25,   /* x2 = 50 mA drawn from VBUS as peripheral */
98         .power          = 100,  /* Max 100 mA VBUS for host mode */
99         .config         = &musb_config,
100 };
101
102 static void __init n8x0_usb_init(void)
103 {
104         int ret = 0;
105         static char     announce[] __initdata = KERN_INFO "TUSB 6010\n";
106
107         /* PM companion chip power control pin */
108         ret = gpio_request(TUSB6010_GPIO_ENABLE, "TUSB6010 enable");
109         if (ret != 0) {
110                 printk(KERN_ERR "Could not get TUSB power GPIO%i\n",
111                        TUSB6010_GPIO_ENABLE);
112                 return;
113         }
114         gpio_direction_output(TUSB6010_GPIO_ENABLE, 0);
115
116         tusb_set_power(0);
117
118         ret = tusb6010_setup_interface(&tusb_data, TUSB6010_REFCLK_19, 2,
119                                         TUSB6010_ASYNC_CS, TUSB6010_SYNC_CS,
120                                         TUSB6010_GPIO_INT, TUSB6010_DMACHAN);
121         if (ret != 0)
122                 goto err;
123
124         printk(announce);
125
126         return;
127
128 err:
129         gpio_free(TUSB6010_GPIO_ENABLE);
130 }
131 #else
132
133 static void __init n8x0_usb_init(void) {}
134
135 #endif /*CONFIG_USB_TUSB6010 */
136
137
138 static struct omap2_mcspi_device_config p54spi_mcspi_config = {
139         .turbo_mode     = 0,
140         .single_channel = 1,
141 };
142
143 static struct spi_board_info n800_spi_board_info[] __initdata = {
144         {
145                 .modalias       = "p54spi",
146                 .bus_num        = 2,
147                 .chip_select    = 0,
148                 .max_speed_hz   = 48000000,
149                 .controller_data = &p54spi_mcspi_config,
150         },
151 };
152
153 #if defined(CONFIG_MTD_ONENAND_OMAP2) || \
154         defined(CONFIG_MTD_ONENAND_OMAP2_MODULE)
155
156 static struct mtd_partition onenand_partitions[] = {
157         {
158                 .name           = "bootloader",
159                 .offset         = 0,
160                 .size           = 0x20000,
161                 .mask_flags     = MTD_WRITEABLE,        /* Force read-only */
162         },
163         {
164                 .name           = "config",
165                 .offset         = MTDPART_OFS_APPEND,
166                 .size           = 0x60000,
167         },
168         {
169                 .name           = "kernel",
170                 .offset         = MTDPART_OFS_APPEND,
171                 .size           = 0x200000,
172         },
173         {
174                 .name           = "initfs",
175                 .offset         = MTDPART_OFS_APPEND,
176                 .size           = 0x400000,
177         },
178         {
179                 .name           = "rootfs",
180                 .offset         = MTDPART_OFS_APPEND,
181                 .size           = MTDPART_SIZ_FULL,
182         },
183 };
184
185 static struct omap_onenand_platform_data board_onenand_data = {
186         .cs             = 0,
187         .gpio_irq       = 26,
188         .parts          = onenand_partitions,
189         .nr_parts       = ARRAY_SIZE(onenand_partitions),
190         .flags          = ONENAND_SYNC_READ,
191 };
192
193 static void __init n8x0_onenand_init(void)
194 {
195         gpmc_onenand_init(&board_onenand_data);
196 }
197
198 #else
199
200 static void __init n8x0_onenand_init(void) {}
201
202 #endif
203
204 #if defined(CONFIG_MENELAUS) &&                                         \
205         (defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE))
206
207 /*
208  * On both N800 and N810, only the first of the two MMC controllers is in use.
209  * The two MMC slots are multiplexed via Menelaus companion chip over I2C.
210  * On N800, both slots are powered via Menelaus. On N810, only one of the
211  * slots is powered via Menelaus. The N810 EMMC is powered via GPIO.
212  *
213  * VMMC                         slot 1 on both N800 and N810
214  * VDCDC3_APE and VMCS2_APE     slot 2 on N800
215  * GPIO23 and GPIO9             slot 2 EMMC on N810
216  *
217  */
218 #define N8X0_SLOT_SWITCH_GPIO   96
219 #define N810_EMMC_VSD_GPIO      23
220 #define N810_EMMC_VIO_GPIO      9
221
222 static int n8x0_mmc_switch_slot(struct device *dev, int slot)
223 {
224 #ifdef CONFIG_MMC_DEBUG
225         dev_dbg(dev, "Choose slot %d\n", slot + 1);
226 #endif
227         gpio_set_value(N8X0_SLOT_SWITCH_GPIO, slot);
228         return 0;
229 }
230
231 static int n8x0_mmc_set_power_menelaus(struct device *dev, int slot,
232                                         int power_on, int vdd)
233 {
234         int mV;
235
236 #ifdef CONFIG_MMC_DEBUG
237         dev_dbg(dev, "Set slot %d power: %s (vdd %d)\n", slot + 1,
238                 power_on ? "on" : "off", vdd);
239 #endif
240         if (slot == 0) {
241                 if (!power_on)
242                         return menelaus_set_vmmc(0);
243                 switch (1 << vdd) {
244                 case MMC_VDD_33_34:
245                 case MMC_VDD_32_33:
246                 case MMC_VDD_31_32:
247                         mV = 3100;
248                         break;
249                 case MMC_VDD_30_31:
250                         mV = 3000;
251                         break;
252                 case MMC_VDD_28_29:
253                         mV = 2800;
254                         break;
255                 case MMC_VDD_165_195:
256                         mV = 1850;
257                         break;
258                 default:
259                         BUG();
260                 }
261                 return menelaus_set_vmmc(mV);
262         } else {
263                 if (!power_on)
264                         return menelaus_set_vdcdc(3, 0);
265                 switch (1 << vdd) {
266                 case MMC_VDD_33_34:
267                 case MMC_VDD_32_33:
268                         mV = 3300;
269                         break;
270                 case MMC_VDD_30_31:
271                 case MMC_VDD_29_30:
272                         mV = 3000;
273                         break;
274                 case MMC_VDD_28_29:
275                 case MMC_VDD_27_28:
276                         mV = 2800;
277                         break;
278                 case MMC_VDD_24_25:
279                 case MMC_VDD_23_24:
280                         mV = 2400;
281                         break;
282                 case MMC_VDD_22_23:
283                 case MMC_VDD_21_22:
284                         mV = 2200;
285                         break;
286                 case MMC_VDD_20_21:
287                         mV = 2000;
288                         break;
289                 case MMC_VDD_165_195:
290                         mV = 1800;
291                         break;
292                 default:
293                         BUG();
294                 }
295                 return menelaus_set_vdcdc(3, mV);
296         }
297         return 0;
298 }
299
300 static void n810_set_power_emmc(struct device *dev,
301                                          int power_on)
302 {
303         dev_dbg(dev, "Set EMMC power %s\n", power_on ? "on" : "off");
304
305         if (power_on) {
306                 gpio_set_value(N810_EMMC_VSD_GPIO, 1);
307                 msleep(1);
308                 gpio_set_value(N810_EMMC_VIO_GPIO, 1);
309                 msleep(1);
310         } else {
311                 gpio_set_value(N810_EMMC_VIO_GPIO, 0);
312                 msleep(50);
313                 gpio_set_value(N810_EMMC_VSD_GPIO, 0);
314                 msleep(50);
315         }
316 }
317
318 static int n8x0_mmc_set_power(struct device *dev, int slot, int power_on,
319                               int vdd)
320 {
321         if (machine_is_nokia_n800() || slot == 0)
322                 return n8x0_mmc_set_power_menelaus(dev, slot, power_on, vdd);
323
324         n810_set_power_emmc(dev, power_on);
325
326         return 0;
327 }
328
329 static int n8x0_mmc_set_bus_mode(struct device *dev, int slot, int bus_mode)
330 {
331         int r;
332
333         dev_dbg(dev, "Set slot %d bus mode %s\n", slot + 1,
334                 bus_mode == MMC_BUSMODE_OPENDRAIN ? "open-drain" : "push-pull");
335         BUG_ON(slot != 0 && slot != 1);
336         slot++;
337         switch (bus_mode) {
338         case MMC_BUSMODE_OPENDRAIN:
339                 r = menelaus_set_mmc_opendrain(slot, 1);
340                 break;
341         case MMC_BUSMODE_PUSHPULL:
342                 r = menelaus_set_mmc_opendrain(slot, 0);
343                 break;
344         default:
345                 BUG();
346         }
347         if (r != 0 && printk_ratelimit())
348                 dev_err(dev, "MMC: unable to set bus mode for slot %d\n",
349                         slot);
350         return r;
351 }
352
353 static int n8x0_mmc_get_cover_state(struct device *dev, int slot)
354 {
355         slot++;
356         BUG_ON(slot != 1 && slot != 2);
357         if (slot == 1)
358                 return slot1_cover_open;
359         else
360                 return slot2_cover_open;
361 }
362
363 static void n8x0_mmc_callback(void *data, u8 card_mask)
364 {
365         int bit, *openp, index;
366
367         if (machine_is_nokia_n800()) {
368                 bit = 1 << 1;
369                 openp = &slot2_cover_open;
370                 index = 1;
371         } else {
372                 bit = 1;
373                 openp = &slot1_cover_open;
374                 index = 0;
375         }
376
377         if (card_mask & bit)
378                 *openp = 1;
379         else
380                 *openp = 0;
381
382         omap_mmc_notify_cover_event(mmc_device, index, *openp);
383 }
384
385 void n8x0_mmc_slot1_cover_handler(void *arg, int closed_state)
386 {
387         if (mmc_device == NULL)
388                 return;
389
390         slot1_cover_open = !closed_state;
391         omap_mmc_notify_cover_event(mmc_device, 0, closed_state);
392 }
393
394 static int n8x0_mmc_late_init(struct device *dev)
395 {
396         int r, bit, *openp;
397         int vs2sel;
398
399         mmc_device = dev;
400
401         r = menelaus_set_slot_sel(1);
402         if (r < 0)
403                 return r;
404
405         if (machine_is_nokia_n800())
406                 vs2sel = 0;
407         else
408                 vs2sel = 2;
409
410         r = menelaus_set_mmc_slot(2, 0, vs2sel, 1);
411         if (r < 0)
412                 return r;
413
414         n8x0_mmc_set_power(dev, 0, MMC_POWER_ON, 16); /* MMC_VDD_28_29 */
415         n8x0_mmc_set_power(dev, 1, MMC_POWER_ON, 16);
416
417         r = menelaus_set_mmc_slot(1, 1, 0, 1);
418         if (r < 0)
419                 return r;
420         r = menelaus_set_mmc_slot(2, 1, vs2sel, 1);
421         if (r < 0)
422                 return r;
423
424         r = menelaus_get_slot_pin_states();
425         if (r < 0)
426                 return r;
427
428         if (machine_is_nokia_n800()) {
429                 bit = 1 << 1;
430                 openp = &slot2_cover_open;
431         } else {
432                 bit = 1;
433                 openp = &slot1_cover_open;
434                 slot2_cover_open = 0;
435         }
436
437         /* All slot pin bits seem to be inversed until first switch change */
438         if (r == 0xf || r == (0xf & ~bit))
439                 r = ~r;
440
441         if (r & bit)
442                 *openp = 1;
443         else
444                 *openp = 0;
445
446         r = menelaus_register_mmc_callback(n8x0_mmc_callback, NULL);
447
448         return r;
449 }
450
451 static void n8x0_mmc_shutdown(struct device *dev)
452 {
453         int vs2sel;
454
455         if (machine_is_nokia_n800())
456                 vs2sel = 0;
457         else
458                 vs2sel = 2;
459
460         menelaus_set_mmc_slot(1, 0, 0, 0);
461         menelaus_set_mmc_slot(2, 0, vs2sel, 0);
462 }
463
464 static void n8x0_mmc_cleanup(struct device *dev)
465 {
466         menelaus_unregister_mmc_callback();
467
468         gpio_free(N8X0_SLOT_SWITCH_GPIO);
469
470         if (machine_is_nokia_n810()) {
471                 gpio_free(N810_EMMC_VSD_GPIO);
472                 gpio_free(N810_EMMC_VIO_GPIO);
473         }
474 }
475
476 /*
477  * MMC controller1 has two slots that are multiplexed via I2C.
478  * MMC controller2 is not in use.
479  */
480 static struct omap_mmc_platform_data mmc1_data = {
481         .nr_slots                       = 2,
482         .switch_slot                    = n8x0_mmc_switch_slot,
483         .init                           = n8x0_mmc_late_init,
484         .cleanup                        = n8x0_mmc_cleanup,
485         .shutdown                       = n8x0_mmc_shutdown,
486         .max_freq                       = 24000000,
487         .dma_mask                       = 0xffffffff,
488         .slots[0] = {
489                 .wires                  = 4,
490                 .set_power              = n8x0_mmc_set_power,
491                 .set_bus_mode           = n8x0_mmc_set_bus_mode,
492                 .get_cover_state        = n8x0_mmc_get_cover_state,
493                 .ocr_mask               = MMC_VDD_165_195 | MMC_VDD_30_31 |
494                                                 MMC_VDD_32_33   | MMC_VDD_33_34,
495                 .name                   = "internal",
496         },
497         .slots[1] = {
498                 .set_power              = n8x0_mmc_set_power,
499                 .set_bus_mode           = n8x0_mmc_set_bus_mode,
500                 .get_cover_state        = n8x0_mmc_get_cover_state,
501                 .ocr_mask               = MMC_VDD_165_195 | MMC_VDD_20_21 |
502                                                 MMC_VDD_21_22 | MMC_VDD_22_23 |
503                                                 MMC_VDD_23_24 | MMC_VDD_24_25 |
504                                                 MMC_VDD_27_28 | MMC_VDD_28_29 |
505                                                 MMC_VDD_29_30 | MMC_VDD_30_31 |
506                                                 MMC_VDD_32_33 | MMC_VDD_33_34,
507                 .name                   = "external",
508         },
509 };
510
511 static struct omap_mmc_platform_data *mmc_data[OMAP24XX_NR_MMC];
512
513 void __init n8x0_mmc_init(void)
514
515 {
516         int err;
517
518         if (machine_is_nokia_n810()) {
519                 mmc1_data.slots[0].name = "external";
520
521                 /*
522                  * Some Samsung Movinand chips do not like open-ended
523                  * multi-block reads and fall to braind-dead state
524                  * while doing so. Reducing the number of blocks in
525                  * the transfer or delays in clock disable do not help
526                  */
527                 mmc1_data.slots[1].name = "internal";
528                 mmc1_data.slots[1].ban_openended = 1;
529         }
530
531         err = gpio_request(N8X0_SLOT_SWITCH_GPIO, "MMC slot switch");
532         if (err)
533                 return;
534
535         gpio_direction_output(N8X0_SLOT_SWITCH_GPIO, 0);
536
537         if (machine_is_nokia_n810()) {
538                 err = gpio_request(N810_EMMC_VSD_GPIO, "MMC slot 2 Vddf");
539                 if (err) {
540                         gpio_free(N8X0_SLOT_SWITCH_GPIO);
541                         return;
542                 }
543                 gpio_direction_output(N810_EMMC_VSD_GPIO, 0);
544
545                 err = gpio_request(N810_EMMC_VIO_GPIO, "MMC slot 2 Vdd");
546                 if (err) {
547                         gpio_free(N8X0_SLOT_SWITCH_GPIO);
548                         gpio_free(N810_EMMC_VSD_GPIO);
549                         return;
550                 }
551                 gpio_direction_output(N810_EMMC_VIO_GPIO, 0);
552         }
553
554         mmc_data[0] = &mmc1_data;
555         omap2_init_mmc(mmc_data, OMAP24XX_NR_MMC);
556 }
557 #else
558
559 void __init n8x0_mmc_init(void)
560 {
561 }
562
563 void n8x0_mmc_slot1_cover_handler(void *arg, int state)
564 {
565 }
566
567 #endif  /* CONFIG_MMC_OMAP */
568
569 #ifdef CONFIG_MENELAUS
570
571 static int n8x0_auto_sleep_regulators(void)
572 {
573         u32 val;
574         int ret;
575
576         val = EN_VPLL_SLEEP | EN_VMMC_SLEEP    \
577                 | EN_VAUX_SLEEP | EN_VIO_SLEEP \
578                 | EN_VMEM_SLEEP | EN_DC3_SLEEP \
579                 | EN_VC_SLEEP | EN_DC2_SLEEP;
580
581         ret = menelaus_set_regulator_sleep(1, val);
582         if (ret < 0) {
583                 printk(KERN_ERR "Could not set regulators to sleep on "
584                         "menelaus: %u\n", ret);
585                 return ret;
586         }
587         return 0;
588 }
589
590 static int n8x0_auto_voltage_scale(void)
591 {
592         int ret;
593
594         ret = menelaus_set_vcore_hw(1400, 1050);
595         if (ret < 0) {
596                 printk(KERN_ERR "Could not set VCORE voltage on "
597                         "menelaus: %u\n", ret);
598                 return ret;
599         }
600         return 0;
601 }
602
603 static int n8x0_menelaus_late_init(struct device *dev)
604 {
605         int ret;
606
607         ret = n8x0_auto_voltage_scale();
608         if (ret < 0)
609                 return ret;
610         ret = n8x0_auto_sleep_regulators();
611         if (ret < 0)
612                 return ret;
613         return 0;
614 }
615
616 static struct aic3x_setup_data n810_aic33_setup = {
617         .gpio_func[0] = AIC3X_GPIO1_FUNC_DISABLED,
618         .gpio_func[1] = AIC3X_GPIO2_FUNC_DIGITAL_MIC_INPUT,
619 };
620
621 static struct aic3x_pdata n810_aic33_data = {
622         .setup = &n810_aic33_setup,
623         .gpio_reset = -1,
624 };
625
626 static struct i2c_board_info __initdata n8x0_i2c_board_info_1[] = {
627         {
628                 I2C_BOARD_INFO("menelaus", 0x72),
629                 .irq = INT_24XX_SYS_NIRQ,
630         },
631         {
632                 I2C_BOARD_INFO("tlv320aic3x", 0x1b),
633                 .platform_data = &n810_aic33_data,
634         },
635 };
636
637 static struct menelaus_platform_data n8x0_menelaus_platform_data = {
638         .late_init = n8x0_menelaus_late_init,
639 };
640
641 static void __init n8x0_menelaus_init(void)
642 {
643         n8x0_i2c_board_info_1[0].platform_data = &n8x0_menelaus_platform_data;
644         omap_register_i2c_bus(1, 400, n8x0_i2c_board_info_1,
645                               ARRAY_SIZE(n8x0_i2c_board_info_1));
646 }
647
648 #else
649 static inline void __init n8x0_menelaus_init(void)
650 {
651 }
652 #endif
653
654 static void __init n8x0_map_io(void)
655 {
656         omap2_set_globals_242x();
657         omap242x_map_common_io();
658 }
659
660 static void __init n8x0_init_irq(void)
661 {
662         omap2_init_common_hw(NULL, NULL);
663         omap_init_irq();
664         omap_gpio_init();
665 }
666
667 static void __init n8x0_init_machine(void)
668 {
669         /* FIXME: add n810 spi devices */
670         spi_register_board_info(n800_spi_board_info,
671                                 ARRAY_SIZE(n800_spi_board_info));
672
673         omap_serial_init();
674         n8x0_menelaus_init();
675         n8x0_onenand_init();
676         n8x0_mmc_init();
677         n8x0_usb_init();
678 }
679
680 MACHINE_START(NOKIA_N800, "Nokia N800")
681         .phys_io        = 0x48000000,
682         .io_pg_offst    = ((0xfa000000) >> 18) & 0xfffc,
683         .boot_params    = 0x80000100,
684         .map_io         = n8x0_map_io,
685         .init_irq       = n8x0_init_irq,
686         .init_machine   = n8x0_init_machine,
687         .timer          = &omap_timer,
688 MACHINE_END
689
690 MACHINE_START(NOKIA_N810, "Nokia N810")
691         .phys_io        = 0x48000000,
692         .io_pg_offst    = ((0xfa000000) >> 18) & 0xfffc,
693         .boot_params    = 0x80000100,
694         .map_io         = n8x0_map_io,
695         .init_irq       = n8x0_init_irq,
696         .init_machine   = n8x0_init_machine,
697         .timer          = &omap_timer,
698 MACHINE_END
699
700 MACHINE_START(NOKIA_N810_WIMAX, "Nokia N810 WiMAX")
701         .phys_io        = 0x48000000,
702         .io_pg_offst    = ((0xfa000000) >> 18) & 0xfffc,
703         .boot_params    = 0x80000100,
704         .map_io         = n8x0_map_io,
705         .init_irq       = n8x0_init_irq,
706         .init_machine   = n8x0_init_machine,
707         .timer          = &omap_timer,
708 MACHINE_END