Merge branch 'master' of git://git.denx.de/u-boot-arm
[platform/kernel/u-boot.git] / board / davinci / dm365evm / dm365evm.c
1 /*
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16  */
17
18 #include <common.h>
19 #include <nand.h>
20 #include <asm/io.h>
21 #include <asm/arch/hardware.h>
22 #include <asm/arch/emif_defs.h>
23 #include <asm/arch/nand_defs.h>
24 #include <asm/arch/gpio_defs.h>
25 #include <netdev.h>
26 #include "../common/misc.h"
27
28 DECLARE_GLOBAL_DATA_PTR;
29
30 int board_init(void)
31 {
32         gd->bd->bi_arch_number = MACH_TYPE_DAVINCI_DM365_EVM;
33         gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
34
35         return 0;
36 }
37
38 #ifdef CONFIG_DRIVER_TI_EMAC
39 int board_eth_init(bd_t *bis)
40 {
41         uint8_t eeprom_enetaddr[6];
42         int i;
43         struct davinci_gpio *gpio1_base =
44                         (struct davinci_gpio *)DAVINCI_GPIO_BANK01;
45
46         /* Configure PINMUX 3 to enable EMAC pins */
47         writel((readl(PINMUX3) | 0x1affff), PINMUX3);
48
49         /* Configure GPIO20 as output */
50         writel((readl(&gpio1_base->dir) & ~(1 << 20)), &gpio1_base->dir);
51
52         /* Toggle GPIO 20 */
53         for (i = 0; i < 20; i++) {
54                 /* GPIO 20 low */
55                 writel((readl(&gpio1_base->out_data) & ~(1 << 20)),
56                                                 &gpio1_base->out_data);
57
58                 udelay(1000);
59
60                 /* GPIO 20 high */
61                 writel((readl(&gpio1_base->out_data) | (1 << 20)),
62                                                 &gpio1_base->out_data);
63         }
64
65         /* Configure I2C pins so that EEPROM can be read */
66         writel((readl(PINMUX3) | 0x01400000), PINMUX3);
67
68         /* Read Ethernet MAC address from EEPROM */
69         if (dvevm_read_mac_address(eeprom_enetaddr))
70                 dv_configure_mac_address(eeprom_enetaddr);
71
72         davinci_emac_initialize();
73
74         return 0;
75 }
76 #endif
77
78 #ifdef CONFIG_NAND_DAVINCI
79 static void nand_dm365evm_select_chip(struct mtd_info *mtd, int chip)
80 {
81         struct nand_chip        *this = mtd->priv;
82         u32                     wbase = (u32) this->IO_ADDR_W;
83         u32                     rbase = (u32) this->IO_ADDR_R;
84
85         if (chip == 1) {
86                 __set_bit(14, &wbase);
87                 __set_bit(14, &rbase);
88         } else {
89                 __clear_bit(14, &wbase);
90                 __clear_bit(14, &rbase);
91         }
92         this->IO_ADDR_W = (void *)wbase;
93         this->IO_ADDR_R = (void *)rbase;
94 }
95
96 int board_nand_init(struct nand_chip *nand)
97 {
98         davinci_nand_init(nand);
99         nand->select_chip = nand_dm365evm_select_chip;
100         return 0;
101 }
102 #endif