1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
250752790SStefan Roese /*
350752790SStefan Roese  * (C) Copyright 2008 Stefan Roese <sr@denx.de>, DENX Software Engineering
450752790SStefan Roese  */
550752790SStefan Roese 
650752790SStefan Roese #include <common.h>
7736fead8SBen Warren #include <netdev.h>
850752790SStefan Roese #include <asm/io.h>
950752790SStefan Roese #include "vct.h"
1050752790SStefan Roese 
1150752790SStefan Roese /*
1250752790SStefan Roese  * EBI initialization for SMC911x access
1350752790SStefan Roese  */
ebi_init_smc911x(void)1450752790SStefan Roese int ebi_init_smc911x(void)
1550752790SStefan Roese {
1650752790SStefan Roese 	reg_write(EBI_DEV1_CONFIG1(EBI_BASE), 0x00003020);
1750752790SStefan Roese 	reg_write(EBI_DEV1_CONFIG2(EBI_BASE), 0x0000004F);
1850752790SStefan Roese 
1950752790SStefan Roese 	reg_write(EBI_DEV1_TIM1_RD1(EBI_BASE), 0x00501100);
2050752790SStefan Roese 	reg_write(EBI_DEV1_TIM1_RD2(EBI_BASE), 0x0FF02111);
2150752790SStefan Roese 
2250752790SStefan Roese 	reg_write(EBI_DEV1_TIM_EXT(EBI_BASE), 0xFFF00000);
2350752790SStefan Roese 	reg_write(EBI_DEV1_EXT_ACC(EBI_BASE), 0x0FFFFFFF);
2450752790SStefan Roese 
2550752790SStefan Roese 	reg_write(EBI_DEV1_TIM1_WR1(EBI_BASE), 0x05001100);
2650752790SStefan Roese 	reg_write(EBI_DEV1_TIM1_WR2(EBI_BASE), 0x3FC21110);
2750752790SStefan Roese 
2850752790SStefan Roese 	return 0;
2950752790SStefan Roese }
3050752790SStefan Roese 
3150752790SStefan Roese /*
3250752790SStefan Roese  * Accessor functions replacing the "weak" functions in
3350752790SStefan Roese  * drivers/net/smc911x.c
3450752790SStefan Roese  */
smc911x_reg_read(struct eth_device * dev,u32 addr)35736fead8SBen Warren u32 smc911x_reg_read(struct eth_device *dev, u32 addr)
3650752790SStefan Roese {
3750752790SStefan Roese 	volatile u32 data;
3850752790SStefan Roese 
39736fead8SBen Warren 	addr += dev->iobase;
4050752790SStefan Roese 	reg_write(EBI_DEV1_CONFIG2(EBI_BASE), 0x0000004F);
4150752790SStefan Roese 	ebi_wait();
4250752790SStefan Roese 	reg_write(EBI_CPU_IO_ACCS(EBI_BASE), (EXT_DEVICE_CHANNEL_1 | addr));
4350752790SStefan Roese 	ebi_wait();
4450752790SStefan Roese 	data = reg_read(EBI_IO_ACCS_DATA(EBI_BASE));
4550752790SStefan Roese 
4650752790SStefan Roese 	return (data);
4750752790SStefan Roese }
4850752790SStefan Roese 
smc911x_reg_write(struct eth_device * dev,u32 addr,u32 data)49736fead8SBen Warren void smc911x_reg_write(struct eth_device *dev, u32 addr, u32 data)
5050752790SStefan Roese {
51736fead8SBen Warren 	addr += dev->iobase;
5250752790SStefan Roese 	reg_write(EBI_DEV1_CONFIG2(EBI_BASE), 0x0000004F);
5350752790SStefan Roese 	ebi_wait();
5450752790SStefan Roese 	reg_write(EBI_IO_ACCS_DATA(EBI_BASE), data);
5550752790SStefan Roese 	reg_write(EBI_CPU_IO_ACCS(EBI_BASE),
5650752790SStefan Roese 		  EXT_DEVICE_CHANNEL_1 | EBI_CPU_WRITE | addr);
5750752790SStefan Roese 	ebi_wait();
5850752790SStefan Roese }
5950752790SStefan Roese 
pkt_data_push(struct eth_device * dev,u32 addr,u32 data)60736fead8SBen Warren void pkt_data_push(struct eth_device *dev, u32 addr, u32 data)
6150752790SStefan Roese {
62736fead8SBen Warren 	addr += dev->iobase;
6350752790SStefan Roese 	reg_write(EBI_DEV1_CONFIG2(EBI_BASE), 0x0000004A);
6450752790SStefan Roese 	ebi_wait();
6550752790SStefan Roese 	reg_write(EBI_IO_ACCS_DATA(EBI_BASE), data);
6650752790SStefan Roese 	reg_write(EBI_CPU_IO_ACCS(EBI_BASE),
6750752790SStefan Roese 		  EXT_DEVICE_CHANNEL_1 | EBI_CPU_WRITE | addr);
6850752790SStefan Roese 	ebi_wait();
6950752790SStefan Roese 
7050752790SStefan Roese 	return;
7150752790SStefan Roese }
7250752790SStefan Roese 
pkt_data_pull(struct eth_device * dev,u32 addr)73736fead8SBen Warren u32 pkt_data_pull(struct eth_device *dev, u32 addr)
7450752790SStefan Roese {
7550752790SStefan Roese 	volatile u32 data;
7650752790SStefan Roese 
77736fead8SBen Warren 	addr += dev->iobase;
7850752790SStefan Roese 	reg_write(EBI_DEV1_CONFIG2(EBI_BASE), 0x0000004A);
7950752790SStefan Roese 	ebi_wait();
8050752790SStefan Roese 	reg_write(EBI_CPU_IO_ACCS(EBI_BASE), (EXT_DEVICE_CHANNEL_1 | addr));
8150752790SStefan Roese 	ebi_wait();
8250752790SStefan Roese 	data = reg_read(EBI_IO_ACCS_DATA(EBI_BASE));
8350752790SStefan Roese 
8450752790SStefan Roese 	return data;
8550752790SStefan Roese }
86736fead8SBen Warren 
board_eth_init(bd_t * bis)87736fead8SBen Warren int board_eth_init(bd_t *bis)
88736fead8SBen Warren {
89736fead8SBen Warren 	int rc = 0;
90736fead8SBen Warren #ifdef CONFIG_SMC911X
91736fead8SBen Warren 	rc = smc911x_initialize(0, CONFIG_DRIVER_SMC911X_BASE);
92736fead8SBen Warren #endif
93736fead8SBen Warren 	return rc;
94736fead8SBen Warren }
95