blob: 648d191523bde00b199d3edf798b1b2d0e2dec55 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Christian Riesch3d908862012-02-02 00:44:42 +00002/*
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>
Christian Riesch3d908862012-02-02 00:44:42 +000010 */
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>
Khoronzhuk, Ivan753a00a2014-06-07 04:22:52 +030020#include <asm/ti-common/davinci_nand.h>
Christian Riesch3d908862012-02-02 00:44:42 +000021#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
26DECLARE_GLOBAL_DATA_PTR;
27
28#define CALIMAIN_HWVERSION_MASK 0x7f000000
29#define CALIMAIN_HWVERSION_SHIFT 24
30
31/* Hardware version pinmux settings */
32const struct pinmux_config hwversion_pins[] = {
33 { pinmux(16), 8, 2 }, /* GP7[15] */
34 { pinmux(16), 8, 3 }, /* GP7[14] */
35 { pinmux(16), 8, 4 }, /* GP7[13] */
36 { pinmux(16), 8, 5 }, /* GP7[12] */
37 { pinmux(16), 8, 6 }, /* GP7[11] */
38 { pinmux(16), 8, 7 }, /* GP7[10] */
39 { pinmux(17), 8, 0 }, /* GP7[9] */
40 { pinmux(17), 8, 1 } /* GP7[8] */
41};
42
43const struct pinmux_resource pinmuxes[] = {
44 PINMUX_ITEM(uart2_pins_txrx),
45 PINMUX_ITEM(emac_pins_mii),
46 PINMUX_ITEM(emac_pins_mdio),
47 PINMUX_ITEM(emifa_pins_nor),
48 PINMUX_ITEM(emifa_pins_cs2),
49 PINMUX_ITEM(emifa_pins_cs3),
50};
51
52const int pinmuxes_size = ARRAY_SIZE(pinmuxes);
53
54const struct lpsc_resource lpsc[] = {
55 { DAVINCI_LPSC_AEMIF }, /* NAND, NOR */
56 { DAVINCI_LPSC_EMAC }, /* image download */
57 { DAVINCI_LPSC_UART2 }, /* console */
58 { DAVINCI_LPSC_GPIO },
59};
60
61const int lpsc_size = ARRAY_SIZE(lpsc);
62
63/* read board revision from GPIO7[8..14] */
64u32 get_board_rev(void)
65{
66 lpsc_on(DAVINCI_LPSC_GPIO);
67 if (davinci_configure_pin_mux(hwversion_pins,
68 ARRAY_SIZE(hwversion_pins)) != 0)
69 return 0xffffffff;
70
71 return (davinci_gpio_bank67->in_data & CALIMAIN_HWVERSION_MASK)
72 >> CALIMAIN_HWVERSION_SHIFT;
73}
74
75/*
76 * determine the oscillator frequency depending on the board revision
77 *
78 * rev 0x00 ... 25 MHz oscillator
79 * rev 0x01 ... 24 MHz oscillator
80 */
81int calimain_get_osc_freq(void)
82{
83 u32 rev;
84 int freq;
85
86 rev = get_board_rev();
87 switch (rev) {
88 case 0x00:
89 freq = 25000000;
90 break;
91 default:
92 freq = 24000000;
93 break;
94 }
95 return freq;
96}
97
98int board_init(void)
99{
100 int val;
101
Christian Riesch3d908862012-02-02 00:44:42 +0000102 irq_init();
Christian Riesch3d908862012-02-02 00:44:42 +0000103
104 /* address of boot parameters */
105 gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
106
107#ifdef CONFIG_DRIVER_TI_EMAC
108 /* select emac MII mode */
109 val = readl(&davinci_syscfg_regs->cfgchip3);
110 val &= ~(1 << 8);
111 writel(val, &davinci_syscfg_regs->cfgchip3);
112#endif /* CONFIG_DRIVER_TI_EMAC */
113
114#ifdef CONFIG_HW_WATCHDOG
115 davinci_hw_watchdog_enable();
116#endif
117
118 printf("Input clock frequency: %d Hz\n", calimain_get_osc_freq());
119 printf("Board revision: %d\n", get_board_rev());
120
121 return 0;
122}
123
124#ifdef CONFIG_DRIVER_TI_EMAC
125/*
126 * Initializes on-board ethernet controllers.
127 */
128int board_eth_init(bd_t *bis)
129{
130 if (!davinci_emac_initialize()) {
131 printf("Error: Ethernet init failed!\n");
132 return -1;
133 }
134
135 return 0;
136}
137#endif /* CONFIG_DRIVER_TI_EMAC */
138
139#ifdef CONFIG_HW_WATCHDOG
140void hw_watchdog_reset(void)
141{
142 davinci_hw_watchdog_reset();
143}
144#endif