ARM: legoev3: disable networking
[oweals/u-boot.git] / board / lego / ev3 / legoev3.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2016 David Lechner <david@lechnology.com>
4  *
5  * Based on da850evm.c
6  *
7  * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
8  *
9  * Based on da830evm.c. Original Copyrights follow:
10  *
11  * Copyright (C) 2009 Nick Thompson, GE Fanuc, Ltd. <nick.thompson@gefanuc.com>
12  * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
13  */
14
15 #include <common.h>
16 #include <i2c.h>
17 #include <spi.h>
18 #include <spi_flash.h>
19 #include <asm/arch/hardware.h>
20 #include <asm/arch/pinmux_defs.h>
21 #include <asm/io.h>
22 #include <asm/arch/davinci_misc.h>
23 #include <linux/errno.h>
24 #include <hwconfig.h>
25 #include <asm/mach-types.h>
26 #include <asm/setup.h>
27
28 #ifdef CONFIG_MMC_DAVINCI
29 #include <mmc.h>
30 #include <asm/arch/sdmmc_defs.h>
31 #endif
32
33 DECLARE_GLOBAL_DATA_PTR;
34
35 u8 board_rev;
36
37 #define EEPROM_I2C_ADDR         0x50
38 #define EEPROM_REV_OFFSET       0x3F00
39 #define EEPROM_MAC_OFFSET       0x3F06
40
41 #ifdef CONFIG_MMC_DAVINCI
42 static struct davinci_mmc mmc_sd0 = {
43         .reg_base = (struct davinci_mmc_regs *)DAVINCI_MMC_SD0_BASE,
44         .host_caps = MMC_MODE_4BIT,     /* DA850 supports only 4-bit SD/MMC */
45         .voltages = MMC_VDD_32_33 | MMC_VDD_33_34,
46         .version = MMC_CTLR_VERSION_2,
47 };
48
49 int board_mmc_init(bd_t *bis)
50 {
51         mmc_sd0.input_clk = clk_get(DAVINCI_MMCSD_CLKID);
52
53         /* Add slot-0 to mmc subsystem */
54         return davinci_mmc_init(bis, &mmc_sd0);
55 }
56 #endif
57
58 const struct pinmux_resource pinmuxes[] = {
59         PINMUX_ITEM(spi0_pins_base),
60         PINMUX_ITEM(spi0_pins_scs0),
61         PINMUX_ITEM(uart1_pins_txrx),
62         PINMUX_ITEM(i2c0_pins),
63         PINMUX_ITEM(mmc0_pins),
64 };
65
66 const int pinmuxes_size = ARRAY_SIZE(pinmuxes);
67
68 const struct lpsc_resource lpsc[] = {
69         { DAVINCI_LPSC_SPI0 },  /* Serial Flash */
70         { DAVINCI_LPSC_UART1 }, /* console */
71         { DAVINCI_LPSC_MMC_SD },
72 };
73
74 const int lpsc_size = ARRAY_SIZE(lpsc);
75
76 u32 get_board_rev(void)
77 {
78         u8 buf[2];
79
80         if (!board_rev) {
81                 if (i2c_read(EEPROM_I2C_ADDR, EEPROM_REV_OFFSET, 2, buf, 2)) {
82                         printf("\nBoard revision read failed!\n");
83                 } else {
84                         /*
85                          * Board rev 3 has MAC address at EEPROM_REV_OFFSET.
86                          * Other revisions have checksum at EEPROM_REV_OFFSET+1
87                          * to detect this.
88                          */
89                         if ((buf[0] ^ buf[1]) == 0xFF)
90                                 board_rev = buf[0];
91                         else
92                                 board_rev = 3;
93                 }
94         }
95
96         return board_rev;
97 }
98
99 /*
100  * The Bluetooth MAC address serves as the board serial number.
101  */
102 void get_board_serial(struct tag_serialnr *serialnr)
103 {
104         u32 offset;
105         u8 buf[6];
106
107         if (!board_rev)
108                 board_rev = get_board_rev();
109
110         /* Board rev 3 has MAC address where rev should be */
111         offset = (board_rev == 3) ? EEPROM_REV_OFFSET : EEPROM_MAC_OFFSET;
112
113         if (i2c_read(EEPROM_I2C_ADDR, offset, 2, buf, 6)) {
114                 printf("\nBoard serial read failed!\n");
115         } else {
116                 u8 *nr;
117
118                 nr = (u8 *)&serialnr->low;
119                 nr[0] = buf[5];
120                 nr[1] = buf[4];
121                 nr[2] = buf[3];
122                 nr[3] = buf[2];
123                 nr = (u8 *)&serialnr->high;
124                 nr[0] = buf[1];
125                 nr[1] = buf[0];
126                 nr[2] = 0;
127                 nr[3] = 0;
128         }
129 }
130
131 int board_early_init_f(void)
132 {
133         /* enable the console UART */
134         writel((DAVINCI_UART_PWREMU_MGMT_FREE | DAVINCI_UART_PWREMU_MGMT_URRST |
135                 DAVINCI_UART_PWREMU_MGMT_UTRST),
136                &davinci_uart1_ctrl_regs->pwremu_mgmt);
137
138         /*
139          * Power on required peripherals
140          * ARM does not have access by default to PSC0 and PSC1
141          * assuming here that the DSP bootloader has set the IOPU
142          * such that PSC access is available to ARM
143          */
144         if (da8xx_configure_lpsc_items(lpsc, ARRAY_SIZE(lpsc)))
145                 return 1;
146
147         return 0;
148 }
149
150 int board_init(void)
151 {
152         irq_init();
153
154         /* arch number of the board */
155         /* LEGO didn't register for a unique number and uses da850evm */
156         gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DA850_EVM;
157
158         /* address of boot parameters */
159         gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
160
161         /* setup the SUSPSRC for ARM to control emulation suspend */
162         writel(readl(&davinci_syscfg_regs->suspsrc) &
163                ~(DAVINCI_SYSCFG_SUSPSRC_I2C |
164                  DAVINCI_SYSCFG_SUSPSRC_SPI0 | DAVINCI_SYSCFG_SUSPSRC_TIMER0 |
165                  DAVINCI_SYSCFG_SUSPSRC_UART1),
166                &davinci_syscfg_regs->suspsrc);
167
168         /* configure pinmux settings */
169         if (davinci_configure_pin_mux_items(pinmuxes, ARRAY_SIZE(pinmuxes)))
170                 return 1;
171
172         return 0;
173 }