common: Drop linux/delay.h from common header
[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 <linux/delay.h>
28 #include "pandora.h"
29
30 DECLARE_GLOBAL_DATA_PTR;
31
32 #define TWL4030_BB_CFG_BBCHEN           (1 << 4)
33 #define TWL4030_BB_CFG_BBSEL_3200MV     (3 << 2)
34 #define TWL4030_BB_CFG_BBISEL_500UA     2
35
36 #define CONTROL_WKUP_CTRL               0x48002a5c
37 #define GPIO_IO_PWRDNZ                  (1 << 6)
38 #define PBIASLITEVMODE1                 (1 << 8)
39
40 static const struct ns16550_platdata pandora_serial = {
41         .base = OMAP34XX_UART3,
42         .reg_shift = 2,
43         .clock = V_NS16550_CLK,
44         .fcr = UART_FCR_DEFVAL,
45 };
46
47 U_BOOT_DEVICE(pandora_uart) = {
48         "ns16550_serial",
49         &pandora_serial
50 };
51
52 /*
53  * Routine: board_init
54  * Description: Early hardware init.
55  */
56 int board_init(void)
57 {
58         gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
59         /* board id for Linux */
60         gd->bd->bi_arch_number = MACH_TYPE_OMAP3_PANDORA;
61         /* boot param addr */
62         gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
63
64         return 0;
65 }
66
67 static void set_output_gpio(unsigned int gpio, int value)
68 {
69         int ret;
70
71         ret = gpio_request(gpio, "");
72         if (ret != 0) {
73                 printf("could not request GPIO %u\n", gpio);
74                 return;
75         }
76         ret = gpio_direction_output(gpio, value);
77         if (ret != 0)
78                 printf("could not set GPIO %u to %d\n", gpio, value);
79 }
80
81 /*
82  * Routine: misc_init_r
83  * Description: Configure board specific parts
84  */
85 int misc_init_r(void)
86 {
87         t2_t *t2_base = (t2_t *)T2_BASE;
88         u32 pbias_lite;
89
90         twl4030_led_init(TWL4030_LED_LEDEN_LEDBON);
91
92         /* set up dual-voltage GPIOs to 1.8V */
93         pbias_lite = readl(&t2_base->pbias_lite);
94         pbias_lite &= ~PBIASLITEVMODE1;
95         pbias_lite |= PBIASLITEPWRDNZ1;
96         writel(pbias_lite, &t2_base->pbias_lite);
97         if (get_cpu_family() == CPU_OMAP36XX)
98                 writel(readl(CONTROL_WKUP_CTRL) | GPIO_IO_PWRDNZ,
99                         CONTROL_WKUP_CTRL);
100
101         /* make sure audio and BT chips are in powerdown state */
102         set_output_gpio(14, 0);
103         set_output_gpio(15, 0);
104         set_output_gpio(118, 0);
105
106         /* enable USB supply */
107         set_output_gpio(164, 1);
108
109         /* wifi needs a short pulse to enter powersave state */
110         set_output_gpio(23, 1);
111         udelay(5000);
112         gpio_direction_output(23, 0);
113
114         /* Enable battery backup capacitor (3.2V, 0.5mA charge current) */
115         twl4030_i2c_write_u8(TWL4030_CHIP_PM_RECEIVER,
116                 TWL4030_PM_RECEIVER_BB_CFG,
117                 TWL4030_BB_CFG_BBCHEN | TWL4030_BB_CFG_BBSEL_3200MV |
118                 TWL4030_BB_CFG_BBISEL_500UA);
119
120         omap_die_id_display();
121
122         return 0;
123 }
124
125 /*
126  * Routine: set_muxconf_regs
127  * Description: Setting up the configuration Mux registers specific to the
128  *              hardware. Many pins need to be moved from protect to primary
129  *              mode.
130  */
131 void set_muxconf_regs(void)
132 {
133         MUX_PANDORA();
134         if (get_cpu_family() == CPU_OMAP36XX) {
135                 MUX_PANDORA_3730();
136         }
137 }
138
139 #ifdef CONFIG_MMC
140 int board_mmc_init(bd_t *bis)
141 {
142         return omap_mmc_init(0, 0, 0, -1, -1);
143 }
144
145 void board_mmc_power_init(void)
146 {
147         twl4030_power_mmc_init(0);
148 }
149 #endif