b604ee951b4b8b38efe41bc8814b19f68abcf062
[platform/kernel/u-boot.git] / board / technexion / tao3530 / tao3530.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Maintainer :
4  *      Tapani Utriainen <linuxfae@technexion.com>
5  */
6 #include <common.h>
7 #include <bootstage.h>
8 #include <malloc.h>
9 #include <netdev.h>
10 #include <twl4030.h>
11 #include <asm/io.h>
12 #include <asm/arch/mmc_host_def.h>
13 #include <asm/arch/mem.h>
14 #include <asm/arch/mux.h>
15 #include <asm/arch/sys_proto.h>
16 #include <asm/arch/gpio.h>
17 #include <asm/gpio.h>
18 #include <asm/mach-types.h>
19
20 #include <usb.h>
21 #include <asm/ehci-omap.h>
22
23 #include "tao3530.h"
24
25 DECLARE_GLOBAL_DATA_PTR;
26
27 int tao3530_revision(void)
28 {
29         int ret = 0;
30
31         /* char *label argument is unused in gpio_request() */
32         ret = gpio_request(65, "");
33         if (ret) {
34                 puts("Error: GPIO 65 not available\n");
35                 goto out;
36         }
37         MUX_VAL(CP(GPMC_WAIT3), (IEN  | PTU | EN  | M4));
38
39         ret = gpio_request(1, "");
40         if (ret) {
41                 puts("Error: GPIO 1 not available\n");
42                 goto out2;
43         }
44         MUX_VAL(CP(SYS_CLKREQ), (IEN  | PTU | EN | M4));
45
46         ret = gpio_direction_input(65);
47         if (ret) {
48                 puts("Error: GPIO 65 not available for input\n");
49                 goto out3;
50         }
51
52         ret =  gpio_direction_input(1);
53         if (ret) {
54                 puts("Error: GPIO 1 not available for input\n");
55                 goto out3;
56         }
57
58         ret = gpio_get_value(65) << 1 | gpio_get_value(1);
59
60 out3:
61         MUX_VAL(CP(SYS_CLKREQ), (IEN  | PTU | EN | M0));
62         gpio_free(1);
63 out2:
64         MUX_VAL(CP(GPMC_WAIT3), (IEN  | PTU | EN  | M0));
65         gpio_free(65);
66 out:
67
68         return ret;
69 }
70
71 #ifdef CONFIG_SPL_BUILD
72 /*
73  * Routine: get_board_mem_timings
74  * Description: If we use SPL then there is no x-loader nor config header
75  * so we have to setup the DDR timings ourself on both banks.
76  */
77 void get_board_mem_timings(struct board_sdrc_timings *timings)
78 {
79 #if defined(CONFIG_SYS_BOARD_OMAP3_HA)
80         /*
81          * Switch baseboard LED to red upon power-on
82          */
83         MUX_OMAP3_HA();
84
85         /* Request a gpio before using it */
86         gpio_request(111, "");
87         /* Sets the gpio as output and its value to 1, switch LED to red */
88         gpio_direction_output(111, 1);
89 #endif
90
91         if (tao3530_revision() < 3) {
92                 /* 256MB / Bank */
93                 timings->mcfg = MCFG(256 << 20, 14);    /* RAS-width 14 */
94                 timings->ctrla = HYNIX_V_ACTIMA_165;
95                 timings->ctrlb = HYNIX_V_ACTIMB_165;
96         } else {
97                 /* 128MB / Bank */
98                 timings->mcfg = MCFG(128 << 20, 13);    /* RAS-width 13 */
99                 timings->ctrla = MICRON_V_ACTIMA_165;
100                 timings->ctrlb = MICRON_V_ACTIMB_165;
101         }
102
103         timings->mr = MICRON_V_MR_165;
104         timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
105 }
106 #endif
107
108 /*
109  * Routine: board_init
110  * Description: Early hardware init.
111  */
112 int board_init(void)
113 {
114         gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
115         /* board id for Linux */
116         gd->bd->bi_arch_number = MACH_TYPE_OMAP3_TAO3530;
117         /* boot param addr */
118         gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
119
120         return 0;
121 }
122
123 /*
124  * Routine: misc_init_r
125  * Description: Configure board specific parts
126  */
127 int misc_init_r(void)
128 {
129         struct gpio *gpio5_base = (struct gpio *)OMAP34XX_GPIO5_BASE;
130         struct gpio *gpio6_base = (struct gpio *)OMAP34XX_GPIO6_BASE;
131
132         twl4030_power_init();
133         twl4030_led_init(TWL4030_LED_LEDEN_LEDAON | TWL4030_LED_LEDEN_LEDBON);
134
135         /* Configure GPIOs to output */
136         /* GPIO23 */
137         writel(~(GPIO10 | GPIO8 | GPIO2 | GPIO1), &gpio6_base->oe);
138         writel(~(GPIO31 | GPIO30 | GPIO22 | GPIO21 |
139                  GPIO15 | GPIO14 | GPIO13 | GPIO12), &gpio5_base->oe);
140
141         /* Set GPIOs */
142         writel(GPIO10 | GPIO8 | GPIO2 | GPIO1,
143                &gpio6_base->setdataout);
144         writel(GPIO31 | GPIO30 | GPIO29 | GPIO28 | GPIO22 | GPIO21 |
145                GPIO15 | GPIO14 | GPIO13 | GPIO12, &gpio5_base->setdataout);
146
147         switch (tao3530_revision()) {
148         case 0:
149                 puts("TAO-3530 REV Reserve 1\n");
150                 break;
151         case 1:
152                 puts("TAO-3530 REV Reserve 2\n");
153                 break;
154         case 2:
155                 puts("TAO-3530 REV Cx\n");
156                 break;
157         case 3:
158                 puts("TAO-3530 REV Ax/Bx\n");
159                 break;
160         default:
161                 puts("Unknown board revision\n");
162         }
163
164         omap_die_id_display();
165
166         return 0;
167 }
168
169 /*
170  * Routine: set_muxconf_regs
171  * Description: Setting up the configuration Mux registers specific to the
172  *              hardware. Many pins need to be moved from protect to primary
173  *              mode.
174  */
175 void set_muxconf_regs(void)
176 {
177         MUX_TAO3530();
178 #if defined(CONFIG_SYS_BOARD_OMAP3_HA)
179         MUX_OMAP3_HA();
180 #endif
181 }
182
183 #if defined(CONFIG_MMC)
184 int board_mmc_init(bd_t *bis)
185 {
186         omap_mmc_init(0, 0, 0, -1, -1);
187
188         return 0;
189 }
190 #endif
191
192 #if defined(CONFIG_MMC)
193 void board_mmc_power_init(void)
194 {
195         twl4030_power_mmc_init(0);
196 }
197 #endif
198
199 #if defined(CONFIG_USB_EHCI_HCD) && !defined(CONFIG_SPL_BUILD)
200 /* Call usb_stop() before starting the kernel */
201 void show_boot_progress(int val)
202 {
203         if (val == BOOTSTAGE_ID_RUN_OS)
204                 usb_stop();
205 }
206
207 static struct omap_usbhs_board_data usbhs_bdata = {
208         .port_mode[0] = OMAP_USBHS_PORT_MODE_UNUSED,
209         .port_mode[1] = OMAP_EHCI_PORT_MODE_PHY,
210         .port_mode[2] = OMAP_USBHS_PORT_MODE_UNUSED
211 };
212
213 int ehci_hcd_init(int index, enum usb_init_type init,
214                   struct ehci_hccr **hccr, struct ehci_hcor **hcor)
215 {
216         return omap_ehci_hcd_init(index, &usbhs_bdata, hccr, hcor);
217 }
218
219 int ehci_hcd_stop(int index)
220 {
221         return omap_ehci_hcd_stop();
222 }
223 #endif /* CONFIG_USB_EHCI_HCD */