Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 1 | /* |
| 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 | * |
| 12 | * See file CREDITS for list of people who contributed to this |
| 13 | * project. |
| 14 | * |
| 15 | * This program is free software; you can redistribute it and/or modify |
| 16 | * it under the terms of the GNU General Public License as published by |
| 17 | * the Free Software Foundation; either version 2 of the License, or |
| 18 | * (at your option) any later version. |
| 19 | * |
| 20 | * This program is distributed in the hope that it will be useful, |
| 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 | * GNU General Public License for more details. |
| 24 | * |
| 25 | * You should have received a copy of the GNU General Public License |
| 26 | * along with this program; if not, write to the Free Software |
| 27 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 28 | */ |
| 29 | |
| 30 | #include <common.h> |
| 31 | #include <i2c.h> |
| 32 | #include <asm/arch/hardware.h> |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 33 | #include "../common/psc.h" |
| 34 | #include "../common/misc.h" |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 35 | |
| 36 | #define DAVINCI_A3CR (0x01E00014) /* EMIF-A CS3 config register. */ |
| 37 | #define DAVINCI_A3CR_VAL (0x3FFFFFFD) /* EMIF-A CS3 value for FPGA. */ |
| 38 | |
| 39 | #define INTEGRITY_SYSCFG_OFFSET 0x7E8 |
| 40 | #define INTEGRITY_CHECKWORD_OFFSET 0x7F8 |
| 41 | #define INTEGRITY_CHECKWORD_VALUE 0x10ADBEEF |
| 42 | |
| 43 | DECLARE_GLOBAL_DATA_PTR; |
| 44 | |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 45 | int board_init(void) |
| 46 | { |
| 47 | /* arch number of the board */ |
| 48 | gd->bd->bi_arch_number = MACH_TYPE_SFFSDR; |
| 49 | |
| 50 | /* address of boot parameters */ |
| 51 | gd->bd->bi_boot_params = LINUX_BOOT_PARAM_ADDR; |
| 52 | |
Hugo Villeneuve | c9a2137 | 2008-11-21 14:35:56 -0500 | [diff] [blame] | 53 | davinci_errata_workarounds(); |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 54 | |
| 55 | /* Power on required peripherals */ |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 56 | lpsc_on(DAVINCI_LPSC_GPIO); |
| 57 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 58 | #if !defined(CONFIG_SYS_USE_DSPLINK) |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 59 | /* Powerup the DSP */ |
| 60 | dsp_on(); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 61 | #endif /* CONFIG_SYS_USE_DSPLINK */ |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 62 | |
Hugo Villeneuve | c9a2137 | 2008-11-21 14:35:56 -0500 | [diff] [blame] | 63 | davinci_enable_uart0(); |
| 64 | davinci_enable_emac(); |
| 65 | davinci_enable_i2c(); |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 66 | |
Hugo Villeneuve | c9a2137 | 2008-11-21 14:35:56 -0500 | [diff] [blame] | 67 | lpsc_on(DAVINCI_LPSC_TIMER1); |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 68 | timer_init(); |
| 69 | |
| 70 | return(0); |
| 71 | } |
| 72 | |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 73 | /* Read ethernet MAC address from Integrity data structure inside EEPROM. |
| 74 | * Returns 1 if found, 0 otherwise. |
| 75 | */ |
| 76 | static int sffsdr_read_mac_address(uint8_t *buf) |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 77 | { |
| 78 | u_int32_t value, mac[2], address; |
| 79 | |
| 80 | /* Read Integrity data structure checkword. */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 81 | if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, INTEGRITY_CHECKWORD_OFFSET, |
| 82 | CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &value, 4)) |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 83 | goto err; |
| 84 | if (value != INTEGRITY_CHECKWORD_VALUE) |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 85 | return 0; |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 86 | |
| 87 | /* Read SYSCFG structure offset. */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 88 | if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, INTEGRITY_SYSCFG_OFFSET, |
| 89 | CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &value, 4)) |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 90 | goto err; |
| 91 | address = 0x800 + (int) value; /* Address of SYSCFG structure. */ |
| 92 | |
| 93 | /* Read NET CONFIG structure offset. */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 94 | if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, address, |
| 95 | CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &value, 4)) |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 96 | goto err; |
| 97 | address = 0x800 + (int) value; /* Address of NET CONFIG structure. */ |
| 98 | address += 12; /* Address of NET INTERFACE CONFIG structure. */ |
| 99 | |
| 100 | /* Read NET INTERFACE CONFIG 2 structure offset. */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 101 | if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, address, |
| 102 | CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &value, 4)) |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 103 | goto err; |
| 104 | address = 0x800 + 16 + (int) value; /* Address of NET INTERFACE |
| 105 | * CONFIG 2 structure. */ |
| 106 | |
| 107 | /* Read MAC address. */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 108 | if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, address, |
| 109 | CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &mac[0], 8)) |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 110 | goto err; |
| 111 | |
| 112 | buf[0] = mac[0] >> 24; |
| 113 | buf[1] = mac[0] >> 16; |
| 114 | buf[2] = mac[0] >> 8; |
| 115 | buf[3] = mac[0]; |
| 116 | buf[4] = mac[1] >> 24; |
| 117 | buf[5] = mac[1] >> 16; |
| 118 | |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 119 | return 1; /* Found */ |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 120 | |
| 121 | err: |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 122 | printf("Read from EEPROM @ 0x%02x failed\n", CONFIG_SYS_I2C_EEPROM_ADDR); |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 123 | return 0; |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | /* Platform dependent initialisation. */ |
| 127 | int misc_init_r(void) |
| 128 | { |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 129 | uint8_t i2cbuf; |
| 130 | uint8_t eeprom_enetaddr[6]; |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 131 | |
| 132 | /* EMIF-A CS3 configuration for FPGA. */ |
| 133 | REG(DAVINCI_A3CR) = DAVINCI_A3CR_VAL; |
| 134 | |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 135 | dv_display_clk_infos(); |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 136 | |
| 137 | /* Configure I2C switch (PCA9543) to enable channel 0. */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 138 | i2cbuf = CONFIG_SYS_I2C_PCA9543_ENABLE_CH0; |
| 139 | if (i2c_write(CONFIG_SYS_I2C_PCA9543_ADDR, 0, |
| 140 | CONFIG_SYS_I2C_PCA9543_ADDR_LEN, &i2cbuf, 1)) { |
| 141 | printf("Write to MUX @ 0x%02x failed\n", CONFIG_SYS_I2C_PCA9543_ADDR); |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 142 | return 1; |
| 143 | } |
| 144 | |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 145 | /* Read Ethernet MAC address from EEPROM if available. */ |
| 146 | if (sffsdr_read_mac_address(eeprom_enetaddr)) |
| 147 | dv_configure_mac_address(eeprom_enetaddr); |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 148 | |
Hugo Villeneuve | 15e55e0 | 2008-07-11 15:10:11 -0400 | [diff] [blame] | 149 | if (!eth_hw_init()) |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 150 | printf("Ethernet init failed\n"); |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 151 | |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 152 | return(0); |
| 153 | } |