bb310d9e681437b3d3815bce9edb01d0d7390899
[oweals/u-boot.git] / board / pandora / pandora.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2008
4  * Grazvydas Ignotas <notasas@gmail.com>
5  *
6  * Derived from Beagle Board, 3430 SDP, and OMAP3EVM code by
7  *      Richard Woodruff <r-woodruff2@ti.com>
8  *      Syed Mohammed Khasim <khasim@ti.com>
9  *      Sunil Kumar <sunilsaini05@gmail.com>
10  *      Shashi Ranjan <shashiranjanmca05@gmail.com>
11  *
12  * (C) Copyright 2004-2008
13  * Texas Instruments, <www.ti.com>
14  */
15 #include <common.h>
16 #include <dm.h>
17 #include <init.h>
18 #include <ns16550.h>
19 #include <twl4030.h>
20 #include <asm/io.h>
21 #include <asm/gpio.h>
22 #include <asm/arch/mmc_host_def.h>
23 #include <asm/arch/mux.h>
24 #include <asm/arch/gpio.h>
25 #include <asm/arch/sys_proto.h>
26 #include <asm/mach-types.h>
27 #include "pandora.h"
28
29 DECLARE_GLOBAL_DATA_PTR;
30
31 #define TWL4030_BB_CFG_BBCHEN           (1 << 4)
32 #define TWL4030_BB_CFG_BBSEL_3200MV     (3 << 2)
33 #define TWL4030_BB_CFG_BBISEL_500UA     2
34
35 #define CONTROL_WKUP_CTRL               0x48002a5c
36 #define GPIO_IO_PWRDNZ                  (1 << 6)
37 #define PBIASLITEVMODE1                 (1 << 8)
38
39 static const struct ns16550_platdata pandora_serial = {
40         .base = OMAP34XX_UART3,
41         .reg_shift = 2,
42         .clock = V_NS16550_CLK,
43         .fcr = UART_FCR_DEFVAL,
44 };
45
46 U_BOOT_DEVICE(pandora_uart) = {
47         "ns16550_serial",
48         &pandora_serial
49 };
50
51 /*
52  * Routine: board_init
53  * Description: Early hardware init.
54  */
55 int board_init(void)
56 {
57         gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
58         /* board id for Linux */
59         gd->bd->bi_arch_number = MACH_TYPE_OMAP3_PANDORA;
60         /* boot param addr */
61         gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
62
63         return 0;
64 }
65
66 static void set_output_gpio(unsigned int gpio, int value)
67 {
68         int ret;
69
70         ret = gpio_request(gpio, "");
71         if (ret != 0) {
72                 printf("could not request GPIO %u\n", gpio);
73                 return;
74         }
75         ret = gpio_direction_output(gpio, value);
76         if (ret != 0)
77                 printf("could not set GPIO %u to %d\n", gpio, value);
78 }
79
80 /*
81  * Routine: misc_init_r
82  * Description: Configure board specific parts
83  */
84 int misc_init_r(void)
85 {
86         t2_t *t2_base = (t2_t *)T2_BASE;
87         u32 pbias_lite;
88
89         twl4030_led_init(TWL4030_LED_LEDEN_LEDBON);
90
91         /* set up dual-voltage GPIOs to 1.8V */
92         pbias_lite = readl(&t2_base->pbias_lite);
93         pbias_lite &= ~PBIASLITEVMODE1;
94         pbias_lite |= PBIASLITEPWRDNZ1;
95         writel(pbias_lite, &t2_base->pbias_lite);
96         if (get_cpu_family() == CPU_OMAP36XX)
97                 writel(readl(CONTROL_WKUP_CTRL) | GPIO_IO_PWRDNZ,
98                         CONTROL_WKUP_CTRL);
99
100         /* make sure audio and BT chips are in powerdown state */
101         set_output_gpio(14, 0);
102         set_output_gpio(15, 0);
103         set_output_gpio(118, 0);
104
105         /* enable USB supply */
106         set_output_gpio(164, 1);
107
108         /* wifi needs a short pulse to enter powersave state */
109         set_output_gpio(23, 1);
110         udelay(5000);
111         gpio_direction_output(23, 0);
112
113         /* Enable battery backup capacitor (3.2V, 0.5mA charge current) */
114         twl4030_i2c_write_u8(TWL4030_CHIP_PM_RECEIVER,
115                 TWL4030_PM_RECEIVER_BB_CFG,
116                 TWL4030_BB_CFG_BBCHEN | TWL4030_BB_CFG_BBSEL_3200MV |
117                 TWL4030_BB_CFG_BBISEL_500UA);
118
119         omap_die_id_display();
120
121         return 0;
122 }
123
124 /*
125  * Routine: set_muxconf_regs
126  * Description: Setting up the configuration Mux registers specific to the
127  *              hardware. Many pins need to be moved from protect to primary
128  *              mode.
129  */
130 void set_muxconf_regs(void)
131 {
132         MUX_PANDORA();
133         if (get_cpu_family() == CPU_OMAP36XX) {
134                 MUX_PANDORA_3730();
135         }
136 }
137
138 #ifdef CONFIG_MMC
139 int board_mmc_init(bd_t *bis)
140 {
141         return omap_mmc_init(0, 0, 0, -1, -1);
142 }
143
144 void board_mmc_power_init(void)
145 {
146         twl4030_power_mmc_init(0);
147 }
148 #endif