1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (C) 2011 OMICRON electronics GmbH
4 *
5 * Based on da850evm.c. Original Copyrights follow:
6 *
7 * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
8 * Copyright (C) 2009 Nick Thompson, GE Fanuc, Ltd. <nick.thompson@gefanuc.com>
9 * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
10 */
11
12 #include <common.h>
13 #include <i2c.h>
14 #include <net.h>
15 #include <netdev.h>
16 #include <watchdog.h>
17 #include <asm/io.h>
18 #include <asm/arch/hardware.h>
19 #include <asm/arch/gpio.h>
20 #include <asm/ti-common/davinci_nand.h>
21 #include <asm/arch/emac_defs.h>
22 #include <asm/arch/pinmux_defs.h>
23 #include <asm/arch/davinci_misc.h>
24 #include <asm/arch/timer_defs.h>
25 #include "../../../drivers/gpio/da8xx_gpio.h"
26
27 DECLARE_GLOBAL_DATA_PTR;
28
29 #define CALIMAIN_HWVERSION_MASK 0x7f000000
30 #define CALIMAIN_HWVERSION_SHIFT 24
31
32 /* Hardware version pinmux settings */
33 const struct pinmux_config hwversion_pins[] = {
34 { pinmux(16), 8, 2 }, /* GP7[15] */
35 { pinmux(16), 8, 3 }, /* GP7[14] */
36 { pinmux(16), 8, 4 }, /* GP7[13] */
37 { pinmux(16), 8, 5 }, /* GP7[12] */
38 { pinmux(16), 8, 6 }, /* GP7[11] */
39 { pinmux(16), 8, 7 }, /* GP7[10] */
40 { pinmux(17), 8, 0 }, /* GP7[9] */
41 { pinmux(17), 8, 1 } /* GP7[8] */
42 };
43
44 const struct pinmux_resource pinmuxes[] = {
45 PINMUX_ITEM(uart2_pins_txrx),
46 PINMUX_ITEM(emac_pins_mii),
47 PINMUX_ITEM(emac_pins_mdio),
48 PINMUX_ITEM(emifa_pins_nor),
49 PINMUX_ITEM(emifa_pins_cs2),
50 PINMUX_ITEM(emifa_pins_cs3),
51 };
52
53 const int pinmuxes_size = ARRAY_SIZE(pinmuxes);
54
55 const struct lpsc_resource lpsc[] = {
56 { DAVINCI_LPSC_AEMIF }, /* NAND, NOR */
57 { DAVINCI_LPSC_EMAC }, /* image download */
58 { DAVINCI_LPSC_UART2 }, /* console */
59 { DAVINCI_LPSC_GPIO },
60 };
61
62 const int lpsc_size = ARRAY_SIZE(lpsc);
63
64 /* read board revision from GPIO7[8..14] */
get_board_rev(void)65 u32 get_board_rev(void)
66 {
67 lpsc_on(DAVINCI_LPSC_GPIO);
68 if (davinci_configure_pin_mux(hwversion_pins,
69 ARRAY_SIZE(hwversion_pins)) != 0)
70 return 0xffffffff;
71
72 return (davinci_gpio_bank67->in_data & CALIMAIN_HWVERSION_MASK)
73 >> CALIMAIN_HWVERSION_SHIFT;
74 }
75
76 /*
77 * determine the oscillator frequency depending on the board revision
78 *
79 * rev 0x00 ... 25 MHz oscillator
80 * rev 0x01 ... 24 MHz oscillator
81 */
calimain_get_osc_freq(void)82 int calimain_get_osc_freq(void)
83 {
84 u32 rev;
85 int freq;
86
87 rev = get_board_rev();
88 switch (rev) {
89 case 0x00:
90 freq = 25000000;
91 break;
92 default:
93 freq = 24000000;
94 break;
95 }
96 return freq;
97 }
98
board_init(void)99 int board_init(void)
100 {
101 int val;
102
103 irq_init();
104
105 /* address of boot parameters */
106 gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
107
108 #ifdef CONFIG_DRIVER_TI_EMAC
109 /* select emac MII mode */
110 val = readl(&davinci_syscfg_regs->cfgchip3);
111 val &= ~(1 << 8);
112 writel(val, &davinci_syscfg_regs->cfgchip3);
113 #endif /* CONFIG_DRIVER_TI_EMAC */
114
115 #ifdef CONFIG_HW_WATCHDOG
116 davinci_hw_watchdog_enable();
117 #endif
118
119 printf("Input clock frequency: %d Hz\n", calimain_get_osc_freq());
120 printf("Board revision: %d\n", get_board_rev());
121
122 return 0;
123 }
124
125 #ifdef CONFIG_DRIVER_TI_EMAC
126 /*
127 * Initializes on-board ethernet controllers.
128 */
board_eth_init(bd_t * bis)129 int board_eth_init(bd_t *bis)
130 {
131 if (!davinci_emac_initialize()) {
132 printf("Error: Ethernet init failed!\n");
133 return -1;
134 }
135
136 return 0;
137 }
138 #endif /* CONFIG_DRIVER_TI_EMAC */
139
140 #ifdef CONFIG_HW_WATCHDOG
hw_watchdog_reset(void)141 void hw_watchdog_reset(void)
142 {
143 davinci_hw_watchdog_reset();
144 }
145 #endif
146