xref: /openbmc/u-boot/arch/arm/mach-davinci/misc.c (revision 83d290c56fab2d38cd1ab4c4cc7099559c1d5046)
1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2601fbec7SMasahiro Yamada /*
3601fbec7SMasahiro Yamada  * Miscelaneous DaVinci functions.
4601fbec7SMasahiro Yamada  *
5601fbec7SMasahiro Yamada  * Copyright (C) 2009 Nick Thompson, GE Fanuc Ltd, <nick.thompson@gefanuc.com>
6601fbec7SMasahiro Yamada  * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
7601fbec7SMasahiro Yamada  * Copyright (C) 2008 Lyrtech <www.lyrtech.com>
8601fbec7SMasahiro Yamada  * Copyright (C) 2004 Texas Instruments.
9601fbec7SMasahiro Yamada  */
10601fbec7SMasahiro Yamada 
11601fbec7SMasahiro Yamada #include <common.h>
129925f1dbSAlex Kiernan #include <environment.h>
13601fbec7SMasahiro Yamada #include <i2c.h>
14601fbec7SMasahiro Yamada #include <net.h>
15601fbec7SMasahiro Yamada #include <asm/arch/hardware.h>
16601fbec7SMasahiro Yamada #include <asm/io.h>
17601fbec7SMasahiro Yamada #include <asm/arch/davinci_misc.h>
18601fbec7SMasahiro Yamada 
19601fbec7SMasahiro Yamada DECLARE_GLOBAL_DATA_PTR;
20601fbec7SMasahiro Yamada 
21601fbec7SMasahiro Yamada #ifndef CONFIG_SPL_BUILD
dram_init(void)22601fbec7SMasahiro Yamada int dram_init(void)
23601fbec7SMasahiro Yamada {
24601fbec7SMasahiro Yamada 	/* dram_init must store complete ramsize in gd->ram_size */
25601fbec7SMasahiro Yamada 	gd->ram_size = get_ram_size(
26601fbec7SMasahiro Yamada 			(void *)CONFIG_SYS_SDRAM_BASE,
27601fbec7SMasahiro Yamada 			CONFIG_MAX_RAM_BANK_SIZE);
28601fbec7SMasahiro Yamada 	return 0;
29601fbec7SMasahiro Yamada }
30601fbec7SMasahiro Yamada 
dram_init_banksize(void)3176b00acaSSimon Glass int dram_init_banksize(void)
32601fbec7SMasahiro Yamada {
33601fbec7SMasahiro Yamada 	gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
34601fbec7SMasahiro Yamada 	gd->bd->bi_dram[0].size = gd->ram_size;
3576b00acaSSimon Glass 
3676b00acaSSimon Glass 	return 0;
37601fbec7SMasahiro Yamada }
38601fbec7SMasahiro Yamada #endif
39601fbec7SMasahiro Yamada 
40601fbec7SMasahiro Yamada #ifdef CONFIG_DRIVER_TI_EMAC
41601fbec7SMasahiro Yamada /*
42601fbec7SMasahiro Yamada  * Read ethernet MAC address from EEPROM for DVEVM compatible boards.
43601fbec7SMasahiro Yamada  * Returns 1 if found, 0 otherwise.
44601fbec7SMasahiro Yamada  */
dvevm_read_mac_address(uint8_t * buf)45601fbec7SMasahiro Yamada int dvevm_read_mac_address(uint8_t *buf)
46601fbec7SMasahiro Yamada {
47601fbec7SMasahiro Yamada #ifdef CONFIG_SYS_I2C_EEPROM_ADDR
48601fbec7SMasahiro Yamada 	/* Read MAC address. */
49601fbec7SMasahiro Yamada 	if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0x7F00,
50601fbec7SMasahiro Yamada 		CONFIG_SYS_I2C_EEPROM_ADDR_LEN, (uint8_t *) &buf[0], 6))
51601fbec7SMasahiro Yamada 		goto i2cerr;
52601fbec7SMasahiro Yamada 
53601fbec7SMasahiro Yamada 	/* Check that MAC address is valid. */
540adb5b76SJoe Hershberger 	if (!is_valid_ethaddr(buf))
55601fbec7SMasahiro Yamada 		goto err;
56601fbec7SMasahiro Yamada 
57601fbec7SMasahiro Yamada 	return 1; /* Found */
58601fbec7SMasahiro Yamada 
59601fbec7SMasahiro Yamada i2cerr:
60601fbec7SMasahiro Yamada 	printf("Read from EEPROM @ 0x%02x failed\n",
61601fbec7SMasahiro Yamada 		CONFIG_SYS_I2C_EEPROM_ADDR);
62601fbec7SMasahiro Yamada err:
63601fbec7SMasahiro Yamada #endif /* CONFIG_SYS_I2C_EEPROM_ADDR */
64601fbec7SMasahiro Yamada 
65601fbec7SMasahiro Yamada 	return 0;
66601fbec7SMasahiro Yamada }
67601fbec7SMasahiro Yamada 
68601fbec7SMasahiro Yamada /*
69601fbec7SMasahiro Yamada  * Set the mii mode as MII or RMII
70601fbec7SMasahiro Yamada  */
71601fbec7SMasahiro Yamada #if defined(CONFIG_SOC_DA8XX)
davinci_emac_mii_mode_sel(int mode_sel)72601fbec7SMasahiro Yamada void davinci_emac_mii_mode_sel(int mode_sel)
73601fbec7SMasahiro Yamada {
74601fbec7SMasahiro Yamada 	int val;
75601fbec7SMasahiro Yamada 
76601fbec7SMasahiro Yamada 	val = readl(&davinci_syscfg_regs->cfgchip3);
77601fbec7SMasahiro Yamada 	if (mode_sel == 0)
78601fbec7SMasahiro Yamada 		val &= ~(1 << 8);
79601fbec7SMasahiro Yamada 	else
80601fbec7SMasahiro Yamada 		val |= (1 << 8);
81601fbec7SMasahiro Yamada 	writel(val, &davinci_syscfg_regs->cfgchip3);
82601fbec7SMasahiro Yamada }
83601fbec7SMasahiro Yamada #endif
84601fbec7SMasahiro Yamada /*
85601fbec7SMasahiro Yamada  * If there is no MAC address in the environment, then it will be initialized
86601fbec7SMasahiro Yamada  * (silently) from the value in the EEPROM.
87601fbec7SMasahiro Yamada  */
davinci_sync_env_enetaddr(uint8_t * rom_enetaddr)88601fbec7SMasahiro Yamada void davinci_sync_env_enetaddr(uint8_t *rom_enetaddr)
89601fbec7SMasahiro Yamada {
90601fbec7SMasahiro Yamada 	uint8_t env_enetaddr[6];
91601fbec7SMasahiro Yamada 	int ret;
92601fbec7SMasahiro Yamada 
9335affd7aSSimon Glass 	ret = eth_env_get_enetaddr_by_index("eth", 0, env_enetaddr);
94601fbec7SMasahiro Yamada 	if (!ret) {
95601fbec7SMasahiro Yamada 		/*
96601fbec7SMasahiro Yamada 		 * There is no MAC address in the environment, so we
97601fbec7SMasahiro Yamada 		 * initialize it from the value in the EEPROM.
98601fbec7SMasahiro Yamada 		 */
99601fbec7SMasahiro Yamada 		debug("### Setting environment from EEPROM MAC address = "
100601fbec7SMasahiro Yamada 			"\"%pM\"\n",
101601fbec7SMasahiro Yamada 			env_enetaddr);
102fd1e959eSSimon Glass 		ret = !eth_env_set_enetaddr("ethaddr", rom_enetaddr);
103601fbec7SMasahiro Yamada 	}
104601fbec7SMasahiro Yamada 	if (!ret)
105601fbec7SMasahiro Yamada 		printf("Failed to set mac address from EEPROM: %d\n", ret);
106601fbec7SMasahiro Yamada }
107601fbec7SMasahiro Yamada #endif	/* CONFIG_DRIVER_TI_EMAC */
108601fbec7SMasahiro Yamada 
109601fbec7SMasahiro Yamada #if defined(CONFIG_SOC_DA8XX)
irq_init(void)110601fbec7SMasahiro Yamada void irq_init(void)
111601fbec7SMasahiro Yamada {
112601fbec7SMasahiro Yamada 	/*
113601fbec7SMasahiro Yamada 	 * Mask all IRQs by clearing the global enable and setting
114601fbec7SMasahiro Yamada 	 * the enable clear for all the 90 interrupts.
115601fbec7SMasahiro Yamada 	 */
116601fbec7SMasahiro Yamada 	writel(0, &davinci_aintc_regs->ger);
117601fbec7SMasahiro Yamada 
118601fbec7SMasahiro Yamada 	writel(0, &davinci_aintc_regs->hier);
119601fbec7SMasahiro Yamada 
120601fbec7SMasahiro Yamada 	writel(0xffffffff, &davinci_aintc_regs->ecr1);
121601fbec7SMasahiro Yamada 	writel(0xffffffff, &davinci_aintc_regs->ecr2);
122601fbec7SMasahiro Yamada 	writel(0xffffffff, &davinci_aintc_regs->ecr3);
123601fbec7SMasahiro Yamada }
124601fbec7SMasahiro Yamada 
125601fbec7SMasahiro Yamada /*
126601fbec7SMasahiro Yamada  * Enable PSC for various peripherals.
127601fbec7SMasahiro Yamada  */
da8xx_configure_lpsc_items(const struct lpsc_resource * item,const int n_items)128601fbec7SMasahiro Yamada int da8xx_configure_lpsc_items(const struct lpsc_resource *item,
129601fbec7SMasahiro Yamada 				    const int n_items)
130601fbec7SMasahiro Yamada {
131601fbec7SMasahiro Yamada 	int i;
132601fbec7SMasahiro Yamada 
133601fbec7SMasahiro Yamada 	for (i = 0; i < n_items; i++)
134601fbec7SMasahiro Yamada 		lpsc_on(item[i].lpsc_no);
135601fbec7SMasahiro Yamada 
136601fbec7SMasahiro Yamada 	return 0;
137601fbec7SMasahiro Yamada }
138601fbec7SMasahiro Yamada #endif
139