blob: f6ab91e6ff5576ebbc8e2ba8bae17595f8ac742a [file] [log] [blame]
Hugo Villeneuve20eca7e2008-07-08 11:02:05 -04001/*
2 * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
3 *
4 * Copyright (C) 2008 Lyrtech <www.lyrtech.com>
5 * Copyright (C) 2008 Philip Balister, OpenSDR <philip@opensdr.com>
6 *
7 * Parts are shamelessly stolen from various TI sources, original copyright
8 * follows:
9 *
10 * Copyright (C) 2004 Texas Instruments.
11 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +020012 * SPDX-License-Identifier: GPL-2.0+
Hugo Villeneuve20eca7e2008-07-08 11:02:05 -040013 */
14
15#include <common.h>
16#include <i2c.h>
17#include <asm/arch/hardware.h>
Sughosh Ganu80995f92010-11-28 20:21:27 -050018#include <asm/arch/davinci_misc.h>
Hugo Villeneuve20eca7e2008-07-08 11:02:05 -040019
20#define DAVINCI_A3CR (0x01E00014) /* EMIF-A CS3 config register. */
21#define DAVINCI_A3CR_VAL (0x3FFFFFFD) /* EMIF-A CS3 value for FPGA. */
22
23#define INTEGRITY_SYSCFG_OFFSET 0x7E8
24#define INTEGRITY_CHECKWORD_OFFSET 0x7F8
25#define INTEGRITY_CHECKWORD_VALUE 0x10ADBEEF
26
27DECLARE_GLOBAL_DATA_PTR;
28
Hugo Villeneuve20eca7e2008-07-08 11:02:05 -040029int board_init(void)
30{
31 /* arch number of the board */
32 gd->bd->bi_arch_number = MACH_TYPE_SFFSDR;
33
34 /* address of boot parameters */
35 gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR;
36
Hugo Villeneuvec9a21372008-11-21 14:35:56 -050037 davinci_errata_workarounds();
Hugo Villeneuve20eca7e2008-07-08 11:02:05 -040038
39 /* Power on required peripherals */
Hugo Villeneuve20eca7e2008-07-08 11:02:05 -040040 lpsc_on(DAVINCI_LPSC_GPIO);
41
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020042#if !defined(CONFIG_SYS_USE_DSPLINK)
Hugo Villeneuve20eca7e2008-07-08 11:02:05 -040043 /* Powerup the DSP */
44 dsp_on();
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020045#endif /* CONFIG_SYS_USE_DSPLINK */
Hugo Villeneuve20eca7e2008-07-08 11:02:05 -040046
Hugo Villeneuvec9a21372008-11-21 14:35:56 -050047 davinci_enable_uart0();
48 davinci_enable_emac();
49 davinci_enable_i2c();
Hugo Villeneuve20eca7e2008-07-08 11:02:05 -040050
Hugo Villeneuvec9a21372008-11-21 14:35:56 -050051 lpsc_on(DAVINCI_LPSC_TIMER1);
Hugo Villeneuve20eca7e2008-07-08 11:02:05 -040052 timer_init();
53
54 return(0);
55}
56
Hugo Villeneuve4e352ef2008-07-11 15:10:13 -040057/* Read ethernet MAC address from Integrity data structure inside EEPROM.
58 * Returns 1 if found, 0 otherwise.
59 */
60static int sffsdr_read_mac_address(uint8_t *buf)
Hugo Villeneuve20eca7e2008-07-08 11:02:05 -040061{
62 u_int32_t value, mac[2], address;
63
64 /* Read Integrity data structure checkword. */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020065 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, INTEGRITY_CHECKWORD_OFFSET,
66 CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &value, 4))
Hugo Villeneuve20eca7e2008-07-08 11:02:05 -040067 goto err;
68 if (value != INTEGRITY_CHECKWORD_VALUE)
Hugo Villeneuve4e352ef2008-07-11 15:10:13 -040069 return 0;
Hugo Villeneuve20eca7e2008-07-08 11:02:05 -040070
71 /* Read SYSCFG structure offset. */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020072 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, INTEGRITY_SYSCFG_OFFSET,
73 CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &value, 4))
Hugo Villeneuve20eca7e2008-07-08 11:02:05 -040074 goto err;
75 address = 0x800 + (int) value; /* Address of SYSCFG structure. */
76
77 /* Read NET CONFIG structure offset. */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020078 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, address,
79 CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &value, 4))
Hugo Villeneuve20eca7e2008-07-08 11:02:05 -040080 goto err;
81 address = 0x800 + (int) value; /* Address of NET CONFIG structure. */
82 address += 12; /* Address of NET INTERFACE CONFIG structure. */
83
84 /* Read NET INTERFACE CONFIG 2 structure offset. */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020085 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, address,
86 CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &value, 4))
Hugo Villeneuve20eca7e2008-07-08 11:02:05 -040087 goto err;
88 address = 0x800 + 16 + (int) value; /* Address of NET INTERFACE
89 * CONFIG 2 structure. */
90
91 /* Read MAC address. */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020092 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, address,
93 CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &mac[0], 8))
Hugo Villeneuve20eca7e2008-07-08 11:02:05 -040094 goto err;
95
96 buf[0] = mac[0] >> 24;
97 buf[1] = mac[0] >> 16;
98 buf[2] = mac[0] >> 8;
99 buf[3] = mac[0];
100 buf[4] = mac[1] >> 24;
101 buf[5] = mac[1] >> 16;
102
Hugo Villeneuve4e352ef2008-07-11 15:10:13 -0400103 return 1; /* Found */
Hugo Villeneuve20eca7e2008-07-08 11:02:05 -0400104
105err:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200106 printf("Read from EEPROM @ 0x%02x failed\n", CONFIG_SYS_I2C_EEPROM_ADDR);
Hugo Villeneuve4e352ef2008-07-11 15:10:13 -0400107 return 0;
Hugo Villeneuve20eca7e2008-07-08 11:02:05 -0400108}
109
110/* Platform dependent initialisation. */
111int misc_init_r(void)
112{
Hugo Villeneuve4e352ef2008-07-11 15:10:13 -0400113 uint8_t i2cbuf;
114 uint8_t eeprom_enetaddr[6];
Hugo Villeneuve20eca7e2008-07-08 11:02:05 -0400115
116 /* EMIF-A CS3 configuration for FPGA. */
117 REG(DAVINCI_A3CR) = DAVINCI_A3CR_VAL;
118
Hugo Villeneuve20eca7e2008-07-08 11:02:05 -0400119 /* Configure I2C switch (PCA9543) to enable channel 0. */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200120 i2cbuf = CONFIG_SYS_I2C_PCA9543_ENABLE_CH0;
121 if (i2c_write(CONFIG_SYS_I2C_PCA9543_ADDR, 0,
122 CONFIG_SYS_I2C_PCA9543_ADDR_LEN, &i2cbuf, 1)) {
123 printf("Write to MUX @ 0x%02x failed\n", CONFIG_SYS_I2C_PCA9543_ADDR);
Hugo Villeneuve20eca7e2008-07-08 11:02:05 -0400124 return 1;
125 }
126
Hugo Villeneuve4e352ef2008-07-11 15:10:13 -0400127 /* Read Ethernet MAC address from EEPROM if available. */
128 if (sffsdr_read_mac_address(eeprom_enetaddr))
Ben Gardiner1fb49e32010-09-23 09:58:43 -0400129 davinci_sync_env_enetaddr(eeprom_enetaddr);
Hugo Villeneuve20eca7e2008-07-08 11:02:05 -0400130
Hugo Villeneuve20eca7e2008-07-08 11:02:05 -0400131 return(0);
132}