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 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame^] | 12 | * SPDX-License-Identifier: GPL-2.0+ |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #include <common.h> |
| 16 | #include <i2c.h> |
| 17 | #include <asm/arch/hardware.h> |
Sughosh Ganu | 80995f9 | 2010-11-28 20:21:27 -0500 | [diff] [blame] | 18 | #include <asm/arch/davinci_misc.h> |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 19 | |
| 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 | |
| 27 | DECLARE_GLOBAL_DATA_PTR; |
| 28 | |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 29 | int 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 Villeneuve | c9a2137 | 2008-11-21 14:35:56 -0500 | [diff] [blame] | 37 | davinci_errata_workarounds(); |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 38 | |
| 39 | /* Power on required peripherals */ |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 40 | lpsc_on(DAVINCI_LPSC_GPIO); |
| 41 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 42 | #if !defined(CONFIG_SYS_USE_DSPLINK) |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 43 | /* Powerup the DSP */ |
| 44 | dsp_on(); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 45 | #endif /* CONFIG_SYS_USE_DSPLINK */ |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 46 | |
Hugo Villeneuve | c9a2137 | 2008-11-21 14:35:56 -0500 | [diff] [blame] | 47 | davinci_enable_uart0(); |
| 48 | davinci_enable_emac(); |
| 49 | davinci_enable_i2c(); |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 50 | |
Hugo Villeneuve | c9a2137 | 2008-11-21 14:35:56 -0500 | [diff] [blame] | 51 | lpsc_on(DAVINCI_LPSC_TIMER1); |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 52 | timer_init(); |
| 53 | |
| 54 | return(0); |
| 55 | } |
| 56 | |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 57 | /* Read ethernet MAC address from Integrity data structure inside EEPROM. |
| 58 | * Returns 1 if found, 0 otherwise. |
| 59 | */ |
| 60 | static int sffsdr_read_mac_address(uint8_t *buf) |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 61 | { |
| 62 | u_int32_t value, mac[2], address; |
| 63 | |
| 64 | /* Read Integrity data structure checkword. */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 65 | if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, INTEGRITY_CHECKWORD_OFFSET, |
| 66 | CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &value, 4)) |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 67 | goto err; |
| 68 | if (value != INTEGRITY_CHECKWORD_VALUE) |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 69 | return 0; |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 70 | |
| 71 | /* Read SYSCFG structure offset. */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 72 | if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, INTEGRITY_SYSCFG_OFFSET, |
| 73 | CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &value, 4)) |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 74 | goto err; |
| 75 | address = 0x800 + (int) value; /* Address of SYSCFG structure. */ |
| 76 | |
| 77 | /* Read NET CONFIG structure offset. */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 78 | if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, address, |
| 79 | CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &value, 4)) |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 80 | 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-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 85 | if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, address, |
| 86 | CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &value, 4)) |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 87 | goto err; |
| 88 | address = 0x800 + 16 + (int) value; /* Address of NET INTERFACE |
| 89 | * CONFIG 2 structure. */ |
| 90 | |
| 91 | /* Read MAC address. */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 92 | if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, address, |
| 93 | CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &mac[0], 8)) |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 94 | 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 Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 103 | return 1; /* Found */ |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 104 | |
| 105 | err: |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 106 | 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] | 107 | return 0; |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | /* Platform dependent initialisation. */ |
| 111 | int misc_init_r(void) |
| 112 | { |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 113 | uint8_t i2cbuf; |
| 114 | uint8_t eeprom_enetaddr[6]; |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 115 | |
| 116 | /* EMIF-A CS3 configuration for FPGA. */ |
| 117 | REG(DAVINCI_A3CR) = DAVINCI_A3CR_VAL; |
| 118 | |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 119 | /* Configure I2C switch (PCA9543) to enable channel 0. */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 120 | 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 Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 124 | return 1; |
| 125 | } |
| 126 | |
Hugo Villeneuve | 4e352ef | 2008-07-11 15:10:13 -0400 | [diff] [blame] | 127 | /* Read Ethernet MAC address from EEPROM if available. */ |
| 128 | if (sffsdr_read_mac_address(eeprom_enetaddr)) |
Ben Gardiner | 1fb49e3 | 2010-09-23 09:58:43 -0400 | [diff] [blame] | 129 | davinci_sync_env_enetaddr(eeprom_enetaddr); |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 130 | |
Hugo Villeneuve | 20eca7e | 2008-07-08 11:02:05 -0400 | [diff] [blame] | 131 | return(0); |
| 132 | } |