]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/samsung/common/board.c
board:samsung:common: move max77686 init function
[karo-tx-uboot.git] / board / samsung / common / board.c
1 /*
2  * (C) Copyright 2013 SAMSUNG Electronics
3  * Rajeshwari Shinde <rajeshwari.s@samsung.com>
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7
8 #include <common.h>
9 #include <cros_ec.h>
10 #include <errno.h>
11 #include <fdtdec.h>
12 #include <spi.h>
13 #include <tmu.h>
14 #include <netdev.h>
15 #include <asm/io.h>
16 #include <asm/arch/board.h>
17 #include <asm/arch/cpu.h>
18 #include <asm/arch/dwmmc.h>
19 #include <asm/arch/gpio.h>
20 #include <asm/arch/mmc.h>
21 #include <asm/arch/pinmux.h>
22 #include <asm/arch/power.h>
23 #include <power/pmic.h>
24 #include <asm/arch/sromc.h>
25
26 DECLARE_GLOBAL_DATA_PTR;
27
28 struct local_info {
29         struct cros_ec_dev *cros_ec_dev;        /* Pointer to cros_ec device */
30         int cros_ec_err;                        /* Error for cros_ec, 0 if ok */
31 };
32
33 static struct local_info local;
34
35 int __exynos_early_init_f(void)
36 {
37         return 0;
38 }
39 int exynos_early_init_f(void)
40         __attribute__((weak, alias("__exynos_early_init_f")));
41
42 int __exynos_power_init(void)
43 {
44         return 0;
45 }
46 int exynos_power_init(void)
47         __attribute__((weak, alias("__exynos_power_init")));
48
49 #if defined CONFIG_EXYNOS_TMU
50 /* Boot Time Thermal Analysis for SoC temperature threshold breach */
51 static void boot_temp_check(void)
52 {
53         int temp;
54
55         switch (tmu_monitor(&temp)) {
56         case TMU_STATUS_NORMAL:
57                 break;
58         case TMU_STATUS_TRIPPED:
59                 /*
60                  * Status TRIPPED ans WARNING means corresponding threshold
61                  * breach
62                  */
63                 puts("EXYNOS_TMU: TRIPPING! Device power going down ...\n");
64                 set_ps_hold_ctrl();
65                 hang();
66                 break;
67         case TMU_STATUS_WARNING:
68                 puts("EXYNOS_TMU: WARNING! Temperature very high\n");
69                 break;
70         case TMU_STATUS_INIT:
71                 /*
72                  * TMU_STATUS_INIT means something is wrong with temperature
73                  * sensing and TMU status was changed back from NORMAL to INIT.
74                  */
75                 puts("EXYNOS_TMU: WARNING! Temperature sensing not done\n");
76                 break;
77         default:
78                 debug("EXYNOS_TMU: Unknown TMU state\n");
79         }
80 }
81 #endif
82
83 int board_init(void)
84 {
85         gd->bd->bi_boot_params = (PHYS_SDRAM_1 + 0x100UL);
86 #if defined CONFIG_EXYNOS_TMU
87         if (tmu_init(gd->fdt_blob) != TMU_STATUS_NORMAL) {
88                 debug("%s: Failed to init TMU\n", __func__);
89                 return -1;
90         }
91         boot_temp_check();
92 #endif
93
94 #ifdef CONFIG_EXYNOS_SPI
95         spi_init();
96 #endif
97         return exynos_init();
98 }
99
100 int dram_init(void)
101 {
102         int i;
103         u32 addr;
104
105         for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
106                 addr = CONFIG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE);
107                 gd->ram_size += get_ram_size((long *)addr, SDRAM_BANK_SIZE);
108         }
109         return 0;
110 }
111
112 void dram_init_banksize(void)
113 {
114         int i;
115         u32 addr, size;
116
117         for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
118                 addr = CONFIG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE);
119                 size = get_ram_size((long *)addr, SDRAM_BANK_SIZE);
120
121                 gd->bd->bi_dram[i].start = addr;
122                 gd->bd->bi_dram[i].size = size;
123         }
124 }
125
126 static int board_uart_init(void)
127 {
128         int err, uart_id, ret = 0;
129
130         for (uart_id = PERIPH_ID_UART0; uart_id <= PERIPH_ID_UART3; uart_id++) {
131                 err = exynos_pinmux_config(uart_id, PINMUX_FLAG_NONE);
132                 if (err) {
133                         debug("UART%d not configured\n",
134                               (uart_id - PERIPH_ID_UART0));
135                         ret |= err;
136                 }
137         }
138         return ret;
139 }
140
141 #ifdef CONFIG_BOARD_EARLY_INIT_F
142 int board_early_init_f(void)
143 {
144         int err;
145
146         err = board_uart_init();
147         if (err) {
148                 debug("UART init failed\n");
149                 return err;
150         }
151
152 #ifdef CONFIG_SYS_I2C_INIT_BOARD
153         board_i2c_init(gd->fdt_blob);
154 #endif
155
156         return exynos_early_init_f();
157 }
158 #endif
159
160 struct cros_ec_dev *board_get_cros_ec_dev(void)
161 {
162         return local.cros_ec_dev;
163 }
164
165 #ifdef CONFIG_CROS_EC
166 static int board_init_cros_ec_devices(const void *blob)
167 {
168         local.cros_ec_err = cros_ec_init(blob, &local.cros_ec_dev);
169         if (local.cros_ec_err)
170                 return -1;  /* Will report in board_late_init() */
171
172         return 0;
173 }
174 #endif
175
176 #if defined(CONFIG_POWER)
177 int power_init_board(void)
178 {
179         set_ps_hold_ctrl();
180
181         return exynos_power_init();
182 }
183 #endif
184
185 #ifdef CONFIG_OF_CONTROL
186 static int decode_sromc(const void *blob, struct fdt_sromc *config)
187 {
188         int err;
189         int node;
190
191         node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS5_SROMC);
192         if (node < 0) {
193                 debug("Could not find SROMC node\n");
194                 return node;
195         }
196
197         config->bank = fdtdec_get_int(blob, node, "bank", 0);
198         config->width = fdtdec_get_int(blob, node, "width", 2);
199
200         err = fdtdec_get_int_array(blob, node, "srom-timing", config->timing,
201                         FDT_SROM_TIMING_COUNT);
202         if (err < 0) {
203                 debug("Could not decode SROMC configuration Error: %s\n",
204                       fdt_strerror(err));
205                 return -FDT_ERR_NOTFOUND;
206         }
207         return 0;
208 }
209
210 int board_eth_init(bd_t *bis)
211 {
212 #ifdef CONFIG_SMC911X
213         u32 smc_bw_conf, smc_bc_conf;
214         struct fdt_sromc config;
215         fdt_addr_t base_addr;
216         int node;
217
218         node = decode_sromc(gd->fdt_blob, &config);
219         if (node < 0) {
220                 debug("%s: Could not find sromc configuration\n", __func__);
221                 return 0;
222         }
223         node = fdtdec_next_compatible(gd->fdt_blob, node, COMPAT_SMSC_LAN9215);
224         if (node < 0) {
225                 debug("%s: Could not find lan9215 configuration\n", __func__);
226                 return 0;
227         }
228
229         /* We now have a node, so any problems from now on are errors */
230         base_addr = fdtdec_get_addr(gd->fdt_blob, node, "reg");
231         if (base_addr == FDT_ADDR_T_NONE) {
232                 debug("%s: Could not find lan9215 address\n", __func__);
233                 return -1;
234         }
235
236         /* Ethernet needs data bus width of 16 bits */
237         if (config.width != 2) {
238                 debug("%s: Unsupported bus width %d\n", __func__,
239                       config.width);
240                 return -1;
241         }
242         smc_bw_conf = SROMC_DATA16_WIDTH(config.bank)
243                         | SROMC_BYTE_ENABLE(config.bank);
244
245         smc_bc_conf = SROMC_BC_TACS(config.timing[FDT_SROM_TACS])   |
246                         SROMC_BC_TCOS(config.timing[FDT_SROM_TCOS]) |
247                         SROMC_BC_TACC(config.timing[FDT_SROM_TACC]) |
248                         SROMC_BC_TCOH(config.timing[FDT_SROM_TCOH]) |
249                         SROMC_BC_TAH(config.timing[FDT_SROM_TAH])   |
250                         SROMC_BC_TACP(config.timing[FDT_SROM_TACP]) |
251                         SROMC_BC_PMC(config.timing[FDT_SROM_PMC]);
252
253         /* Select and configure the SROMC bank */
254         exynos_pinmux_config(PERIPH_ID_SROMC, config.bank);
255         s5p_config_sromc(config.bank, smc_bw_conf, smc_bc_conf);
256         return smc911x_initialize(0, base_addr);
257 #endif
258         return 0;
259 }
260
261 #ifdef CONFIG_GENERIC_MMC
262 int board_mmc_init(bd_t *bis)
263 {
264         int ret;
265
266         /* dwmmc initializattion for available channels */
267         ret = exynos_dwmmc_init(gd->fdt_blob);
268         if (ret)
269                 debug("dwmmc init failed\n");
270
271         return ret;
272 }
273 #endif
274
275 #ifdef CONFIG_DISPLAY_BOARDINFO
276 int checkboard(void)
277 {
278         const char *board_name;
279
280         board_name = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
281         printf("Board: %s\n", board_name ? board_name : "unknown");
282
283         return 0;
284 }
285 #endif
286 #endif /* CONFIG_OF_CONTROL */
287
288 #ifdef CONFIG_BOARD_LATE_INIT
289 int board_late_init(void)
290 {
291         stdio_print_current_devices();
292
293         if (local.cros_ec_err) {
294                 /* Force console on */
295                 gd->flags &= ~GD_FLG_SILENT;
296
297                 printf("cros-ec communications failure %d\n",
298                        local.cros_ec_err);
299                 puts("\nPlease reset with Power+Refresh\n\n");
300                 panic("Cannot init cros-ec device");
301                 return -1;
302         }
303         return 0;
304 }
305 #endif
306
307 int arch_early_init_r(void)
308 {
309 #ifdef CONFIG_CROS_EC
310         if (board_init_cros_ec_devices(gd->fdt_blob)) {
311                 printf("%s: Failed to init EC\n", __func__);
312                 return 0;
313         }
314 #endif
315
316         return 0;
317 }