]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/samsung/smdk5250/exynos5-dt.c
Merge branch 'master' of git://git.denx.de/u-boot-74xx-7xx
[karo-tx-uboot.git] / board / samsung / smdk5250 / exynos5-dt.c
1 /*
2  * Copyright (C) 2012 Samsung Electronics
3  *
4  * See file CREDITS for list of people who contributed to this
5  * project.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of
10  * the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20  * MA 02111-1307 USA
21  */
22
23 #include <common.h>
24 #include <cros_ec.h>
25 #include <fdtdec.h>
26 #include <asm/io.h>
27 #include <errno.h>
28 #include <i2c.h>
29 #include <netdev.h>
30 #include <spi.h>
31 #include <asm/arch/cpu.h>
32 #include <asm/arch/dwmmc.h>
33 #include <asm/arch/gpio.h>
34 #include <asm/arch/mmc.h>
35 #include <asm/arch/pinmux.h>
36 #include <asm/arch/power.h>
37 #include <asm/arch/sromc.h>
38 #include <power/pmic.h>
39 #include <power/max77686_pmic.h>
40 #include <tmu.h>
41
42 DECLARE_GLOBAL_DATA_PTR;
43
44 #if defined CONFIG_EXYNOS_TMU
45 /*
46  * Boot Time Thermal Analysis for SoC temperature threshold breach
47  */
48 static void boot_temp_check(void)
49 {
50         int temp;
51
52         switch (tmu_monitor(&temp)) {
53         /* Status TRIPPED ans WARNING means corresponding threshold breach */
54         case TMU_STATUS_TRIPPED:
55                 puts("EXYNOS_TMU: TRIPPING! Device power going down ...\n");
56                 set_ps_hold_ctrl();
57                 hang();
58                 break;
59         case TMU_STATUS_WARNING:
60                 puts("EXYNOS_TMU: WARNING! Temperature very high\n");
61                 break;
62         /*
63          * TMU_STATUS_INIT means something is wrong with temperature sensing
64          * and TMU status was changed back from NORMAL to INIT.
65          */
66         case TMU_STATUS_INIT:
67         default:
68                 debug("EXYNOS_TMU: Unknown TMU state\n");
69         }
70 }
71 #endif
72
73 struct local_info {
74         struct cros_ec_dev *cros_ec_dev;        /* Pointer to cros_ec device */
75         int cros_ec_err;                        /* Error for cros_ec, 0 if ok */
76 };
77
78 static struct local_info local;
79
80 #ifdef CONFIG_USB_EHCI_EXYNOS
81 int board_usb_vbus_init(void)
82 {
83         struct exynos5_gpio_part1 *gpio1 = (struct exynos5_gpio_part1 *)
84                                                 samsung_get_base_gpio_part1();
85
86         /* Enable VBUS power switch */
87         s5p_gpio_direction_output(&gpio1->x2, 6, 1);
88
89         /* VBUS turn ON time */
90         mdelay(3);
91
92         return 0;
93 }
94 #endif
95
96 #ifdef CONFIG_SOUND_MAX98095
97 static void  board_enable_audio_codec(void)
98 {
99         struct exynos5_gpio_part1 *gpio1 = (struct exynos5_gpio_part1 *)
100                                                 samsung_get_base_gpio_part1();
101
102         /* Enable MAX98095 Codec */
103         s5p_gpio_direction_output(&gpio1->x1, 7, 1);
104         s5p_gpio_set_pull(&gpio1->x1, 7, GPIO_PULL_NONE);
105 }
106 #endif
107
108 struct cros_ec_dev *board_get_cros_ec_dev(void)
109 {
110         return local.cros_ec_dev;
111 }
112
113 static int board_init_cros_ec_devices(const void *blob)
114 {
115         local.cros_ec_err = cros_ec_init(blob, &local.cros_ec_dev);
116         if (local.cros_ec_err)
117                 return -1;  /* Will report in board_late_init() */
118
119         return 0;
120 }
121
122 int board_init(void)
123 {
124         gd->bd->bi_boot_params = (PHYS_SDRAM_1 + 0x100UL);
125
126 #if defined CONFIG_EXYNOS_TMU
127         if (tmu_init(gd->fdt_blob) != TMU_STATUS_NORMAL) {
128                 debug("%s: Failed to init TMU\n", __func__);
129                 return -1;
130         }
131         boot_temp_check();
132 #endif
133
134 #ifdef CONFIG_EXYNOS_SPI
135         spi_init();
136 #endif
137
138         if (board_init_cros_ec_devices(gd->fdt_blob))
139                 return -1;
140
141 #ifdef CONFIG_USB_EHCI_EXYNOS
142         board_usb_vbus_init();
143 #endif
144 #ifdef CONFIG_SOUND_MAX98095
145         board_enable_audio_codec();
146 #endif
147         return 0;
148 }
149
150 int dram_init(void)
151 {
152         int i;
153         u32 addr;
154
155         for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
156                 addr = CONFIG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE);
157                 gd->ram_size += get_ram_size((long *)addr, SDRAM_BANK_SIZE);
158         }
159         return 0;
160 }
161
162 #if defined(CONFIG_POWER)
163 static int pmic_reg_update(struct pmic *p, int reg, uint regval)
164 {
165         u32 val;
166         int ret = 0;
167
168         ret = pmic_reg_read(p, reg, &val);
169         if (ret) {
170                 debug("%s: PMIC %d register read failed\n", __func__, reg);
171                 return -1;
172         }
173         val |= regval;
174         ret = pmic_reg_write(p, reg, val);
175         if (ret) {
176                 debug("%s: PMIC %d register write failed\n", __func__, reg);
177                 return -1;
178         }
179         return 0;
180 }
181
182 int power_init_board(void)
183 {
184         struct pmic *p;
185
186         set_ps_hold_ctrl();
187
188         i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
189
190         if (pmic_init(I2C_PMIC))
191                 return -1;
192
193         p = pmic_get("MAX77686_PMIC");
194         if (!p)
195                 return -ENODEV;
196
197         if (pmic_probe(p))
198                 return -1;
199
200         if (pmic_reg_update(p, MAX77686_REG_PMIC_32KHZ, MAX77686_32KHCP_EN))
201                 return -1;
202
203         if (pmic_reg_update(p, MAX77686_REG_PMIC_BBAT,
204                             MAX77686_BBCHOSTEN | MAX77686_BBCVS_3_5V))
205                 return -1;
206
207         /* VDD_MIF */
208         if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK1OUT,
209                            MAX77686_BUCK1OUT_1V)) {
210                 debug("%s: PMIC %d register write failed\n", __func__,
211                       MAX77686_REG_PMIC_BUCK1OUT);
212                 return -1;
213         }
214
215         if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK1CRTL,
216                             MAX77686_BUCK1CTRL_EN))
217                 return -1;
218
219         /* VDD_ARM */
220         if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK2DVS1,
221                            MAX77686_BUCK2DVS1_1_3V)) {
222                 debug("%s: PMIC %d register write failed\n", __func__,
223                       MAX77686_REG_PMIC_BUCK2DVS1);
224                 return -1;
225         }
226
227         if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK2CTRL1,
228                             MAX77686_BUCK2CTRL_ON))
229                 return -1;
230
231         /* VDD_INT */
232         if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK3DVS1,
233                            MAX77686_BUCK3DVS1_1_0125V)) {
234                 debug("%s: PMIC %d register write failed\n", __func__,
235                       MAX77686_REG_PMIC_BUCK3DVS1);
236                 return -1;
237         }
238
239         if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK3CTRL,
240                             MAX77686_BUCK3CTRL_ON))
241                 return -1;
242
243         /* VDD_G3D */
244         if (pmic_reg_write(p, MAX77686_REG_PMIC_BUCK4DVS1,
245                            MAX77686_BUCK4DVS1_1_2V)) {
246                 debug("%s: PMIC %d register write failed\n", __func__,
247                       MAX77686_REG_PMIC_BUCK4DVS1);
248                 return -1;
249         }
250
251         if (pmic_reg_update(p, MAX77686_REG_PMIC_BUCK4CTRL1,
252                             MAX77686_BUCK3CTRL_ON))
253                 return -1;
254
255         /* VDD_LDO2 */
256         if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO2CTRL1,
257                             MAX77686_LD02CTRL1_1_5V | EN_LDO))
258                 return -1;
259
260         /* VDD_LDO3 */
261         if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO3CTRL1,
262                             MAX77686_LD03CTRL1_1_8V | EN_LDO))
263                 return -1;
264
265         /* VDD_LDO5 */
266         if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO5CTRL1,
267                             MAX77686_LD05CTRL1_1_8V | EN_LDO))
268                 return -1;
269
270         /* VDD_LDO10 */
271         if (pmic_reg_update(p, MAX77686_REG_PMIC_LDO10CTRL1,
272                             MAX77686_LD10CTRL1_1_8V | EN_LDO))
273                 return -1;
274
275         return 0;
276 }
277 #endif
278
279 void dram_init_banksize(void)
280 {
281         int i;
282         u32 addr, size;
283
284         for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
285                 addr = CONFIG_SYS_SDRAM_BASE + (i * SDRAM_BANK_SIZE);
286                 size = get_ram_size((long *)addr, SDRAM_BANK_SIZE);
287
288                 gd->bd->bi_dram[i].start = addr;
289                 gd->bd->bi_dram[i].size = size;
290         }
291 }
292
293 static int decode_sromc(const void *blob, struct fdt_sromc *config)
294 {
295         int err;
296         int node;
297
298         node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS5_SROMC);
299         if (node < 0) {
300                 debug("Could not find SROMC node\n");
301                 return node;
302         }
303
304         config->bank = fdtdec_get_int(blob, node, "bank", 0);
305         config->width = fdtdec_get_int(blob, node, "width", 2);
306
307         err = fdtdec_get_int_array(blob, node, "srom-timing", config->timing,
308                         FDT_SROM_TIMING_COUNT);
309         if (err < 0) {
310                 debug("Could not decode SROMC configuration Error: %s\n",
311                       fdt_strerror(err));
312                 return -FDT_ERR_NOTFOUND;
313         }
314         return 0;
315 }
316
317 int board_eth_init(bd_t *bis)
318 {
319 #ifdef CONFIG_SMC911X
320         u32 smc_bw_conf, smc_bc_conf;
321         struct fdt_sromc config;
322         fdt_addr_t base_addr;
323         int node;
324
325         node = decode_sromc(gd->fdt_blob, &config);
326         if (node < 0) {
327                 debug("%s: Could not find sromc configuration\n", __func__);
328                 return 0;
329         }
330         node = fdtdec_next_compatible(gd->fdt_blob, node, COMPAT_SMSC_LAN9215);
331         if (node < 0) {
332                 debug("%s: Could not find lan9215 configuration\n", __func__);
333                 return 0;
334         }
335
336         /* We now have a node, so any problems from now on are errors */
337         base_addr = fdtdec_get_addr(gd->fdt_blob, node, "reg");
338         if (base_addr == FDT_ADDR_T_NONE) {
339                 debug("%s: Could not find lan9215 address\n", __func__);
340                 return -1;
341         }
342
343         /* Ethernet needs data bus width of 16 bits */
344         if (config.width != 2) {
345                 debug("%s: Unsupported bus width %d\n", __func__,
346                       config.width);
347                 return -1;
348         }
349         smc_bw_conf = SROMC_DATA16_WIDTH(config.bank)
350                         | SROMC_BYTE_ENABLE(config.bank);
351
352         smc_bc_conf = SROMC_BC_TACS(config.timing[FDT_SROM_TACS])   |
353                         SROMC_BC_TCOS(config.timing[FDT_SROM_TCOS]) |
354                         SROMC_BC_TACC(config.timing[FDT_SROM_TACC]) |
355                         SROMC_BC_TCOH(config.timing[FDT_SROM_TCOH]) |
356                         SROMC_BC_TAH(config.timing[FDT_SROM_TAH])   |
357                         SROMC_BC_TACP(config.timing[FDT_SROM_TACP]) |
358                         SROMC_BC_PMC(config.timing[FDT_SROM_PMC]);
359
360         /* Select and configure the SROMC bank */
361         exynos_pinmux_config(PERIPH_ID_SROMC, config.bank);
362         s5p_config_sromc(config.bank, smc_bw_conf, smc_bc_conf);
363         return smc911x_initialize(0, base_addr);
364 #endif
365         return 0;
366 }
367
368 #ifdef CONFIG_DISPLAY_BOARDINFO
369 int checkboard(void)
370 {
371         const char *board_name;
372
373         board_name = fdt_getprop(gd->fdt_blob, 0, "model", NULL);
374         if (board_name == NULL)
375                 printf("\nUnknown Board\n");
376         else
377                 printf("\nBoard: %s\n", board_name);
378
379         return 0;
380 }
381 #endif
382
383 #ifdef CONFIG_GENERIC_MMC
384 int board_mmc_init(bd_t *bis)
385 {
386         int ret;
387         /* dwmmc initializattion for available channels */
388         ret = exynos_dwmmc_init(gd->fdt_blob);
389         if (ret)
390                 debug("dwmmc init failed\n");
391
392         return ret;
393 }
394 #endif
395
396 static int board_uart_init(void)
397 {
398         int err, uart_id, ret = 0;
399
400         for (uart_id = PERIPH_ID_UART0; uart_id <= PERIPH_ID_UART3; uart_id++) {
401                 err = exynos_pinmux_config(uart_id, PINMUX_FLAG_NONE);
402                 if (err) {
403                         debug("UART%d not configured\n",
404                               (uart_id - PERIPH_ID_UART0));
405                         ret |= err;
406                 }
407         }
408         return ret;
409 }
410
411 #ifdef CONFIG_BOARD_EARLY_INIT_F
412 int board_early_init_f(void)
413 {
414         int err;
415         err = board_uart_init();
416         if (err) {
417                 debug("UART init failed\n");
418                 return err;
419         }
420 #ifdef CONFIG_SYS_I2C_INIT_BOARD
421         board_i2c_init(gd->fdt_blob);
422 #endif
423         return err;
424 }
425 #endif
426
427 #ifdef CONFIG_LCD
428 void exynos_cfg_lcd_gpio(void)
429 {
430         struct exynos5_gpio_part1 *gpio1 =
431                 (struct exynos5_gpio_part1 *)samsung_get_base_gpio_part1();
432
433         /* For Backlight */
434         s5p_gpio_cfg_pin(&gpio1->b2, 0, GPIO_OUTPUT);
435         s5p_gpio_set_value(&gpio1->b2, 0, 1);
436
437         /* LCD power on */
438         s5p_gpio_cfg_pin(&gpio1->x1, 5, GPIO_OUTPUT);
439         s5p_gpio_set_value(&gpio1->x1, 5, 1);
440
441         /* Set Hotplug detect for DP */
442         s5p_gpio_cfg_pin(&gpio1->x0, 7, GPIO_FUNC(0x3));
443 }
444
445 void exynos_set_dp_phy(unsigned int onoff)
446 {
447         set_dp_phy_ctrl(onoff);
448 }
449 #endif
450
451 #ifdef CONFIG_BOARD_LATE_INIT
452 int board_late_init(void)
453 {
454         stdio_print_current_devices();
455
456         if (local.cros_ec_err) {
457                 /* Force console on */
458                 gd->flags &= ~GD_FLG_SILENT;
459
460                 printf("cros-ec communications failure %d\n",
461                        local.cros_ec_err);
462                 puts("\nPlease reset with Power+Refresh\n\n");
463                 panic("Cannot init cros-ec device");
464                 return -1;
465         }
466         return 0;
467 }
468 #endif