board: stm32mp1: gt9147 IRQ before reset on EV1
[oweals/u-boot.git] / board / corscience / tricorder / tricorder.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2012
4  * Corscience GmbH & Co. KG, <www.corscience.de>
5  * Thomas Weber <weber@corscience.de>
6  * Sunil Kumar <sunilsaini05@gmail.com>
7  * Shashi Ranjan <shashiranjanmca05@gmail.com>
8  *
9  * Derived from Devkit8000 code by
10  * Frederik Kriewitz <frederik@kriewitz.eu>
11  */
12 #include <common.h>
13 #include <malloc.h>
14 #include <twl4030.h>
15 #include <status_led.h>
16 #include <asm/io.h>
17 #include <asm/gpio.h>
18 #include <asm/arch/mmc_host_def.h>
19 #include <asm/arch/mux.h>
20 #include <asm/arch/sys_proto.h>
21 #include <asm/arch/mem.h>
22 #include "tricorder.h"
23 #include "tricorder-eeprom.h"
24
25 DECLARE_GLOBAL_DATA_PTR;
26
27 /*
28  * Routine: board_init
29  * Description: Early hardware init.
30  */
31 int board_init(void)
32 {
33         gpmc_init(); /* in SRAM or SDRAM, finish GPMC */
34         /* boot param addr */
35         gd->bd->bi_boot_params = (OMAP34XX_SDRC_CS0 + 0x100);
36
37         return 0;
38 }
39
40 /**
41  * get_eeprom - read the eeprom
42  *
43  * @eeprom - pointer to a eeprom struct to fill
44  *
45  * This function will panic() on wrong EEPROM content
46  */
47 static void get_eeprom(struct tricorder_eeprom *eeprom)
48 {
49         int ret;
50
51         if (!eeprom)
52                 panic("No eeprom given!\n");
53
54         ret = gpio_request(7, "BMS");
55         if (ret)
56                 panic("gpio: requesting BMS pin failed\n");
57
58         ret = gpio_direction_input(7);
59         if (ret)
60                 panic("gpio: set BMS as input failed\n");
61
62         ret = gpio_get_value(7);
63         if (ret < 0)
64                 panic("gpio: get BMS pin state failed\n");
65
66         gpio_free(7);
67
68         if (ret == 0) {
69                 /* BMS is _not_ set, do the EEPROM check */
70                 ret = tricorder_get_eeprom(0x51, eeprom);
71                 if (!ret) {
72                         if (strncmp(eeprom->board_name, "CS10411", 7) != 0)
73                                 panic("Wrong board name '%.*s'\n",
74                                       sizeof(eeprom->board_name),
75                                                 eeprom->board_name);
76                         if (eeprom->board_version[0] < 'D')
77                                 panic("Wrong board version '%.*s'\n",
78                                       sizeof(eeprom->board_version),
79                                                 eeprom->board_version);
80                 } else {
81                         panic("Could not get board revision\n");
82                 }
83         } else {
84                 memset(eeprom, 0, TRICORDER_EEPROM_SIZE);
85         }
86 }
87
88 /**
89  * print_hwversion - print out a HW version string
90  *
91  * @eeprom - pointer to the eeprom
92  */
93 static void print_hwversion(struct tricorder_eeprom *eeprom)
94 {
95         size_t len;
96         if (!eeprom)
97                 panic("No eeprom given!");
98
99         printf("Board %.*s:%.*s serial %.*s",
100                sizeof(eeprom->board_name), eeprom->board_name,
101                sizeof(eeprom->board_version), eeprom->board_version,
102                sizeof(eeprom->board_serial), eeprom->board_serial);
103
104         len = strnlen(eeprom->interface_version,
105                       sizeof(eeprom->interface_version));
106         if (len > 0)
107                 printf(" HW interface version %.*s",
108                        sizeof(eeprom->interface_version),
109                        eeprom->interface_version);
110         puts("\n");
111 }
112
113 /*
114  * Routine: misc_init_r
115  * Description: Configure board specific parts
116  */
117 int misc_init_r(void)
118 {
119         struct tricorder_eeprom eeprom;
120         get_eeprom(&eeprom);
121         print_hwversion(&eeprom);
122
123         twl4030_power_init();
124         status_led_set(0, CONFIG_LED_STATUS_ON);
125         status_led_set(1, CONFIG_LED_STATUS_ON);
126         status_led_set(2, CONFIG_LED_STATUS_ON);
127
128         omap_die_id_display();
129
130         return 0;
131 }
132
133 /*
134  * Routine: set_muxconf_regs
135  * Description: Setting up the configuration Mux registers specific to the
136  *              hardware. Many pins need to be moved from protect to primary
137  *              mode.
138  */
139 void set_muxconf_regs(void)
140 {
141         MUX_TRICORDER();
142 }
143
144 #if defined(CONFIG_MMC)
145 int board_mmc_init(bd_t *bis)
146 {
147         return omap_mmc_init(0, 0, 0, -1, -1);
148 }
149 #endif
150
151 #if defined(CONFIG_MMC)
152 void board_mmc_power_init(void)
153 {
154         twl4030_power_mmc_init(0);
155 }
156 #endif
157
158 /*
159  * Routine: get_board_mem_timings
160  * Description: If we use SPL then there is no x-loader nor config header
161  * so we have to setup the DDR timings ourself on the first bank.  This
162  * provides the timing values back to the function that configures
163  * the memory.  We have either one or two banks of 128MB DDR.
164  */
165 void get_board_mem_timings(struct board_sdrc_timings *timings)
166 {
167         struct tricorder_eeprom eeprom;
168         get_eeprom(&eeprom);
169
170         /* General SDRC config */
171         if (eeprom.board_version[0] > 'D') {
172                 /* use optimized timings for our SDRAM device */
173                 timings->mcfg = MCFG((256 << 20), 14);
174 #define MT46H64M32_TDAL  6      /* Twr/Tck + Trp/tck            */
175                                 /* 15/6 + 18/6 = 5.5 -> 6       */
176 #define MT46H64M32_TDPL  3      /* 15/6 = 2.5 -> 3 (Twr)        */
177 #define MT46H64M32_TRRD  2      /* 12/6 = 2                     */
178 #define MT46H64M32_TRCD  3      /* 18/6 = 3                     */
179 #define MT46H64M32_TRP   3      /* 18/6 = 3                     */
180 #define MT46H64M32_TRAS  7      /* 42/6 = 7                     */
181 #define MT46H64M32_TRC  10      /* 60/6 = 10                    */
182 #define MT46H64M32_TRFC 12      /* 72/6 = 12                    */
183                 timings->ctrla = ACTIM_CTRLA(MT46H64M32_TRFC, MT46H64M32_TRC,
184                                              MT46H64M32_TRAS, MT46H64M32_TRP,
185                                              MT46H64M32_TRCD, MT46H64M32_TRRD,
186                                              MT46H64M32_TDPL,
187                                              MT46H64M32_TDAL);
188
189 #define MT46H64M32_TWTR 1
190 #define MT46H64M32_TCKE 1
191 #define MT46H64M32_XSR 19       /* 112.5/6 = 18.75 => ~19       */
192 #define MT46H64M32_TXP 1
193                 timings->ctrlb = ACTIM_CTRLB(MT46H64M32_TWTR, MT46H64M32_TCKE,
194                                              MT46H64M32_TXP, MT46H64M32_XSR);
195
196                 timings->mr = MICRON_V_MR_165;
197                 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
198         } else {
199                 /* use conservative beagleboard timings as default */
200                 timings->mcfg = MICRON_V_MCFG_165(128 << 20);
201                 timings->ctrla = MICRON_V_ACTIMA_165;
202                 timings->ctrlb = MICRON_V_ACTIMB_165;
203                 timings->mr = MICRON_V_MR_165;
204                 timings->rfr_ctrl = SDP_3430_SDRC_RFR_CTRL_165MHz;
205         }
206 }