Support for CPSW switch
Subsystems (3)
cover Support for CPSW switch
These patches add CPSW switch driver and enable support for it on TI AM335x based boards. We need to detect the board type to configure pins correctly so these patches also include small fix to OMAP I2C driver.
Cyril Chemparathy (1):
cpsw: add driver for cpsw ethernet device
Ilya Yanok (5):
omap24xx_i2c: add 2-byte address support
am33xx: CPSW init and definitions
am33xx: pin mux defintions for CPSW switch
am335x_evm: read the on-board EEPROM
am335x_evm: CPSW support
arch/arm/cpu/armv7/am33xx/clock.c | 8 +- arch/arm/include/asm/arch-am33xx/common_def.h | 2 + arch/arm/include/asm/arch-am33xx/cpu.h | 12 + arch/arm/include/asm/arch-am33xx/hardware.h | 5 + board/ti/am335x/evm.c | 158 +++- board/ti/am335x/mux.c | 47 ++ drivers/i2c/omap24xx_i2c.c | 58 +- drivers/net/Makefile | 1 + drivers/net/cpsw.c | 994 +++++++++++++++++++++++++ include/configs/am335x_evm.h | 20 +- include/cpsw.h | 51 ++ 11 files changed, 1320 insertions(+), 36 deletions(-) create mode 100644 drivers/net/cpsw.c create mode 100644 include/cpsw.h
Signature · 1 line
1.7.9.5
PATCH 1/6 omap24xx_i2c: add 2-byte address support
Various devices like EEPROMs require 2-byte address support to be properly accessed. This patch adds this support for OMAP2/3/4 I2C controller driver.
I've tested it with EEPROM (16 bit address) and TPS65217 chip (8 bit address) on TI Beaglebone board.
Unfortunately I don't have access to any compatible hardware with 16bit data register so I can't test if those #ifdef clauses really work.
--- drivers/i2c/omap24xx_i2c.c | 58 ++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 32 deletions(-)
drivers/i2c/omap24xx_i2c.c +26 -32
@@ -150,16 +150,19 @@ void i2c_init(int speed, int slaveadd) bus_initialized[current_bus] =1 ; } -static int i2c_read_byte (u8 devaddr,u8 regoffset,u8 *value) +static int i2c_read_byte (u8 devaddr,u16 regoffset,u8 alen,u8 *value) {int i2c_error =0 ;u16 status; +int i =2 - alen; +u8 tmpbuf[2 ] = {(regoffset) >>8 , regoffset &0xff }; +u16 w;/* wait until bus not busy */ wait_for_bb ();/* one byte only */ -writew (1 , &i2c_base->cnt); +writew (alen, &i2c_base->cnt);/* set slave address */ writew (devaddr, &i2c_base->sa);/* no stop bit needed here */
@@ -174,8 +177,12 @@ static int i2c_read_byte(u8 devaddr, u8 regoffset, u8 *value) goto read_exit; }if (status &I2C_STAT_XRDY ) { -/* Important: have to use byte access */ -writeb (regoffset, &i2c_base->data); + w = tmpbuf[i++]; +#if !(defined(CONFIG_OMAP243X ) || defined(CONFIG_OMAP34XX ) || \ + defined(CONFIG_OMAP44XX ) || defined(CONFIG_AM33XX )) + w |= tmpbuf[i++] <<8 ; +#endif +writew (w, &i2c_base->data);writew (I2C_STAT_XRDY , &i2c_base->stat); }if (status &I2C_STAT_ARDY ) {
@@ -303,18 +310,18 @@ int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len) {int i; -if (alen >1 ) { +if (alen >2 ) {printf ("I2C read: addr len %d not supported\n" , alen);return 1 ; } -if (addr + len >256 ) { +if (addr + len > (1 <<16 )) {puts ("I2C read: address out of range\n" );return 1 ; }for (i =0 ; i < len; i++) { -if (i2c_read_byte (chip, addr + i, &buffer[i])) { +if (i2c_read_byte (chip, addr + i, alen, &buffer[i])) {puts ("I2C read: I/O error\n" );i2c_init (CONFIG_SYS_I2C_SPEED ,CONFIG_SYS_I2C_SLAVE );return 1 ;
@@ -329,13 +336,15 @@ int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len)int i;u16 status;int i2c_error =0 ; +u16 w; +u8 tmpbuf[2 ] = {addr >>8 , addr &0xff }; -if (alen >1 ) { +if (alen >2 ) {printf ("I2C write: addr len %d not supported\n" , alen);return 1 ; } -if (addr + len >256 ) { +if (addr + len > (1 <<16 )) {printf ("I2C write: address 0x%x + 0x%x out of range\n" , addr, len);return 1 ;
@@ -353,28 +362,8 @@ int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len)writew (I2C_CON_EN |I2C_CON_MST |I2C_CON_STT |I2C_CON_TRX |I2C_CON_STP , &i2c_base->con); -/* Send address byte */ - status =wait_for_pin (); - -if (status ==0 || status &I2C_STAT_NACK ) { - i2c_error =1 ; -printf ("error waiting for i2c address ACK (status=0x%x)\n" , - status); - goto write_exit; - } - -if (status &I2C_STAT_XRDY ) { -writeb (addr &0xFF , &i2c_base->data); -writew (I2C_STAT_XRDY , &i2c_base->stat); - }else { - i2c_error =1 ; -printf ("i2c bus not ready for transmit (status=0x%x)\n" , - status); - goto write_exit; - } - -/* address phase is over, now write data */ -for (i =0 ; i < len; i++) { +/* Send address and data */ +for (i = -alen; i < len; i++) { status =wait_for_pin ();if (status ==0 || status &I2C_STAT_NACK ) {
@@ -385,7 +374,12 @@ int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len) }if (status &I2C_STAT_XRDY ) { -writeb (buffer[i], &i2c_base->data); + w = (i <0 ) ? tmpbuf[2 +i] : buffer[i]; +#if !(defined(CONFIG_OMAP243X ) || defined(CONFIG_OMAP34XX ) || \ + defined(CONFIG_OMAP44XX ) || defined(CONFIG_AM33XX )) + w |= ((++i <0 ) ? tmpbuf[2 +i] : buffer[i]) <<8 ; +#endif +writew (w, &i2c_base->data);writew (I2C_STAT_XRDY , &i2c_base->stat); }else { i2c_error =1 ;
Signature · 1 line
1.7.9.5
PATCH 1/6 omap24xx_i2c: add 2-byte address support
Quoted 9 lines · Ilya Yanok
Various devices like EEPROMs require 2-byte address support to be properly accessed. This patch adds this support for OMAP2/3/4 I2C controller driver.
I've tested it with EEPROM (16 bit address) and TPS65217 chip (8 bit address) on TI Beaglebone board.Unfortunately I don't have access to any compatible hardware with 16bit data register so I can't test if those #ifdef clauses really work.
For now, just this part pushed to u-boot-ti/next, thanks!
Signature · 1 line
Tom
PATCH 2/6 cpsw: add driver for cpsw ethernet device
In reply to Ilya YanokFrom: Cyril Chemparathy <[email protected]>
CPSW is an on-chip ethernet switch that is found on various SoCs from Texas Instruments. This patch adds a simple driver (based on the Linux driver) for this hardware module.
This patch also adds support to clean and flush dcache during packet send and receive.
Changes by Sandhya: Added support to clean and flush dcache during packet
send/receive and added timeouts.
Changes by Ilya: Cleaner cache handling, some style cleanup
--- drivers/net/Makefile | 1 + drivers/net/cpsw.c | 994 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/cpsw.h | 51 +++ 3 files changed, 1046 insertions(+) create mode 100644 drivers/net/cpsw.c create mode 100644 include/cpsw.h
drivers/net/Makefile +1 -0
@@ -71,6 +71,7 @@ COBJS-$(CONFIG_SMC91111) += smc91111.o COBJS-$(CONFIG_SMC911X) += smc911x.o COBJS-$(CONFIG_DRIVER_TI_EMAC) += davinci_emac.o COBJS-$(CONFIG_TSEC_ENET) += tsec.o fsl_mdio.o +COBJS-$(CONFIG_DRIVER_TI_CPSW) += cpsw.o COBJS-$(CONFIG_FMAN_ENET) += fsl_mdio.o COBJS-$(CONFIG_TSI108_ETH) += tsi108_eth.o COBJS-$(CONFIG_ULI526X) += uli526x.o
drivers/net/cpsw.c new file +994 -0
994 lines not on this page · raw message
include/cpsw.h new file +51 -0
51 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH 2/6 cpsw: add driver for cpsw ethernet device
Tom, guys,
I've just found that I forgot to mention that this version requires my patch [1] to work with enabled D-Cache correctly.
Hope to get some comments on it soon.
[1] http://thread.gmane.org/gmane.comp.boot-loaders.u-boot/132464
Regards, Ilya.
Quoted 16 lines · Ilya Yanok
From: Cyril Chemparathy <[email protected]>
CPSW is an on-chip ethernet switch that is found on various SoCs from Texas Instruments. This patch adds a simple driver (based on the Linux driver) for
this hardware module.This patch also adds support to clean and flush dcache during packet send and receive.
Changes by Sandhya: Added support to clean and flush dcache during packet
send/receive and added timeouts.Changes by Ilya: Cleaner cache handling, some style cleanup
PATCH 3/6 am33xx: CPSW init and definitions
In reply to Ilya YanokThis patch adds platform-specific initialization for CPSW switch on TI AM33XX SoCs.
--- arch/arm/cpu/armv7/am33xx/clock.c | 8 +++++++- arch/arm/include/asm/arch-am33xx/cpu.h | 12 ++++++++++++ arch/arm/include/asm/arch-am33xx/hardware.h | 5 +++++ 3 files changed, 24 insertions(+), 1 deletion(-)
arch/arm/cpu/armv7/am33xx/clock.c +7 -1
@@ -24,6 +24,7 @@#define PRCM_MOD_EN 0x2#define PRCM_FORCE_WAKEUP 0x2 +#define PRCM_FUNCTL 0x0#define PRCM_EMIF_CLK_ACTIVITY BIT(2)#define PRCM_L3_GCLK_ACTIVITY BIT(4)
@@ -38,7 +39,7 @@#define CLK_MODE_SEL 0x7#define CLK_MODE_MASK 0xfffffff8#define CLK_DIV_SEL 0xFFFFFFE0 - +#define CPGMAC0_IDLE 0x30000const struct cm_perpll *cmper = (struct cm_perpll *)CM_PER ;const struct cm_wkuppll *cmwkup = (struct cm_wkuppll *)CM_WKUP ;
@@ -118,6 +119,11 @@ static void enable_per_clocks(void)writel (PRCM_MOD_EN , &cmwkup->wkup_i2c0ctrl);while (readl (&cmwkup->wkup_i2c0ctrl) !=PRCM_MOD_EN ) ; + +/* Ethernet */ +writel (PRCM_MOD_EN , &cmper->cpgmac0clkctrl); +while ((readl (&cmper->cpgmac0clkctrl) &CPGMAC0_IDLE ) !=PRCM_FUNCTL ) + ; }static void mpu_pll_config (void )
arch/arm/include/asm/arch-am33xx/cpu.h +12 -0
@@ -233,6 +233,18 @@ struct ctrl_stat {unsigned int resv1[16 ];unsigned int statusreg;/* ofset 0x40 */ }; + +/* Control Device Register */ +struct ctrl_dev { +unsigned int deviceid;/* offset 0x00 */ +unsigned int resv1[11 ]; +unsigned int macid0l;/* offset 0x30 */ +unsigned int macid0h;/* offset 0x34 */ +unsigned int macid1l;/* offset 0x38 */ +unsigned int macid1h;/* offset 0x3c */ +unsigned int resv2[4 ]; +unsigned int miisel;/* offset 0x50 */ +};#endif /* __ASSEMBLY__ */ #endif /* __KERNEL_STRICT_NAMES */
arch/arm/include/asm/arch-am33xx/hardware.h +5 -0
@@ -46,6 +46,7 @@/* Control Module Base Address */ #define CTRL_BASE 0x44E10000 +#define CTRL_DEVICE_BASE 0x44E10600/* PRCM Base Address */ #define PRCM_BASE 0x44E00000
@@ -78,4 +79,8 @@#define DDRPHY_0_CONFIG_BASE (CTRL_BASE + 0x1400)#define DDRPHY_CONFIG_BASE DDRPHY_0_CONFIG_BASE +/* CPSW Config space */ +#define AM335X_CPSW_BASE 0x4A100000 +#define AM335X_CPSW_MDIO_BASE 0x4A101000 +#endif /* __AM33XX_HARDWARE_H */
Signature · 1 line
1.7.9.5
PATCH 4/6 am33xx: pin mux defintions for CPSW switch
In reply to Ilya YanokThis patch adds pin mux settings for CPSW switch found on TI AM335X based boards (MII and RGMII modes).
--- arch/arm/include/asm/arch-am33xx/common_def.h | 2 ++ board/ti/am335x/mux.c | 47 +++++++++++++++++++++++++ 2 files changed, 49 insertions(+)
arch/arm/include/asm/arch-am33xx/common_def.h +2 -0
@@ -19,5 +19,7 @@extern void enable_uart0_pin_mux (void );extern void enable_mmc0_pin_mux (void );extern void enable_i2c0_pin_mux (void ); +extern void enable_mii1_pin_mux (void ); +extern void enable_rgmii1_pin_mux (void );#endif /*__COMMON_DEF_H__ */
board/ti/am335x/mux.c +47 -0
56 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH 5/6 am335x_evm: read the on-board EEPROM
In reply to Ilya YanokRead the on-board EEPROM during startup to detect the version of the board we are running on (as for now only BeagleBone vs EVM detection is supported).
--- board/ti/am335x/evm.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-)
board/ti/am335x/evm.c +70 -2
@@ -14,6 +14,7 @@*/ #include <common.h> +#include <errno.h> #include <asm/arch/cpu.h> #include <asm/arch/hardware.h> #include <asm/arch/common_def.h>
@@ -27,16 +28,83 @@ DECLARE_GLOBAL_DATA_PTR;#define UART_SMART_IDLE_EN (0x1 << 0x3)/* +* I2C Address of on-board EEPROM +*/ +#define I2C_BASE_BOARD_ADDR 0x50 + +#define NO_OF_MAC_ADDR 3 +#define ETH_ALEN 6 + +#define NAME_LEN 8 + +struct am335x_baseboard_id { +unsigned int magic; +char name[NAME_LEN ]; +char version[4 ]; +char serial[12 ]; +char config[32 ]; +char mac_addr[NO_OF_MAC_ADDR ][ETH_ALEN ]; +}; + +static struct am335x_baseboard_id header; + +static inline int board_is_bone (void ) +{ +return !strncmp (header.name,"A335BONE" ,NAME_LEN ); +} + +/* +* Read header information from EEPROM into global structure. +*/ +int read_eeprom (void ) +{ +/* Check if baseboard eeprom is available */ +if (i2c_probe (I2C_BASE_BOARD_ADDR )) { +printf ("Could not probe the EEPROM; something fundamentally " +"wrong on the I2C bus.\n" ); +return -ENODEV ; + } + +/* read the eeprom using i2c */ +if (i2c_read (I2C_BASE_BOARD_ADDR ,0 ,2 , (uchar *)&header, +sizeof (header))) { +printf ("Could not read the EEPROM; something fundamentally" +" wrong on the I2C bus.\n" ); +return -EIO ; + } + +if (header.magic !=0xEE3355AA ) { +/* +* read the eeprom using i2c again, +* but use only a 1 byte address +*/ +if (i2c_read (I2C_BASE_BOARD_ADDR ,0 ,1 , (uchar *)&header, +sizeof (header))) { +printf ("Could not read the EEPROM; something " +"fundamentally wrong on the I2C bus.\n" ); +return -EIO ; + } + +if (header.magic !=0xEE3355AA ) { +printf ("Incorrect magic number in EEPROM\n" ); +return -EINVAL ; + } + } + +return 0 ; +} + +/* * Basic board specific setup */ int board_init (void ) {enable_uart0_pin_mux (); -#ifdef CONFIG_I2C enable_i2c0_pin_mux ();i2c_init (CONFIG_SYS_I2C_SPEED ,CONFIG_SYS_I2C_SLAVE ); -#endif +if (read_eeprom () <0 ) +printf ("Could not get board ID.\n" ); gd->bd->bi_boot_params =PHYS_DRAM_1 +0x100 ;
Signature · 1 line
1.7.9.5
PATCH 6/6 am335x_evm: CPSW support
In reply to Ilya YanokThis patch adds board-specific initialization for CPSW on TI AM335X based boards. Tested on BeagleBone.
--- board/ti/am335x/evm.c | 86 ++++++++++++++++++++++++++++++++++++++++++ include/configs/am335x_evm.h | 20 +++++++++- 2 files changed, 105 insertions(+), 1 deletion(-)
board/ti/am335x/evm.c +86 -0
@@ -20,6 +20,8 @@#include <asm/arch/common_def.h> #include <serial.h> #include <i2c.h> +#include <miiphy.h> +#include <cpsw.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -27,6 +29,12 @@ DECLARE_GLOBAL_DATA_PTR;#define UART_CLK_RUNNING_MASK 0x1#define UART_SMART_IDLE_EN (0x1 << 0x3) +/* MII mode defines */ +#define MII_MODE_ENABLE 0x0 +#define RGMII_MODE_ENABLE 0xA + +struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE ; +/* * I2C Address of on-board EEPROM */
@@ -110,3 +118,81 @@ int board_init(void)return 0 ; } + +#ifdef CONFIG_DRIVER_TI_CPSW +static void cpsw_control (int enabled) +{ +/* VTP can be added here */ + +return ; +} + +static struct cpsw_slave_data cpsw_slaves[] = { + { + .slave_reg_ofs =0x208 , + .sliver_reg_ofs =0xd80 , + .phy_id =0 , + }, + { + .slave_reg_ofs =0x308 , + .sliver_reg_ofs =0xdc0 , + .phy_id =1 , + }, +}; + +static struct cpsw_platform_data cpsw_data = { + .mdio_base =AM335X_CPSW_MDIO_BASE , + .cpsw_base =AM335X_CPSW_BASE , + .mdio_div =0xff , + .channels =8 , + .cpdma_reg_ofs =0x800 , + .slaves =1 , + .slave_data = cpsw_slaves, + .ale_reg_ofs =0xd00 , + .ale_entries =1024 , + .host_port_reg_ofs =0x108 , + .hw_stats_reg_ofs =0x900 , + .mac_control = (1 <<5 ), + .control = cpsw_control, + .host_port_num =0 , + .version =CPSW_CTRL_VERSION_2 , +}; + +int board_eth_init (bd_t *bis) +{ +uint8_t mac_addr[6 ]; +uint32_t mac_hi, mac_lo; + +if (!eth_getenv_enetaddr ("ethaddr" , mac_addr)) { +debug ("<ethaddr> not set. Reading from E-fuse\n" ); +/* try reading mac address from efuse */ + mac_lo =readl (&cdev->macid0l); + mac_hi =readl (&cdev->macid0h); + mac_addr[0 ] = mac_hi &0xFF ; + mac_addr[1 ] = (mac_hi &0xFF00 ) >>8 ; + mac_addr[2 ] = (mac_hi &0xFF0000 ) >>16 ; + mac_addr[3 ] = (mac_hi &0xFF000000 ) >>24 ; + mac_addr[4 ] = mac_lo &0xFF ; + mac_addr[5 ] = (mac_lo &0xFF00 ) >>8 ; + +if (is_valid_ether_addr (mac_addr)) +eth_setenv_enetaddr ("ethaddr" , mac_addr); +else +return -1 ; + } + +if (board_is_bone ()) { +enable_mii1_pin_mux (); +writel (MII_MODE_ENABLE , &cdev->miisel); + cpsw_slaves[0 ].phy_if = cpsw_slaves[1 ].phy_if = +PHY_INTERFACE_MODE_MII ; + }else { +enable_rgmii1_pin_mux (); +writel (RGMII_MODE_ENABLE , &cdev->miisel); + cpsw_slaves[0 ].phy_if = cpsw_slaves[1 ].phy_if = +PHY_INTERFACE_MODE_RGMII ; + } + +return cpsw_register (&cpsw_data); +} +#endif
include/configs/am335x_evm.h +19 -1
@@ -21,11 +21,13 @@#undef CONFIG_GZIP#undef CONFIG_ZLIB#undef CONFIG_SYS_HUSH_PARSER -#undef CONFIG_CMD_NET#include <asm/arch/cpu.h> #include <asm/arch/hardware.h> +#define CONFIG_DMA_COHERENT +#define CONFIG_DMA_COHERENT_SIZE (1 << 20) +#define CONFIG_ENV_SIZE 0x400#define CONFIG_SYS_MALLOC_LEN (CONFIG_ENV_SIZE + (8 * 1024))#define CONFIG_SYS_PROMPT "U-Boot# "
@@ -168,4 +170,20 @@/* Unsupported features */ #undef CONFIG_USE_IRQ +#define CONFIG_CMD_NET +#define CONFIG_CMD_DHCP +#define CONFIG_CMD_PING +#define CONFIG_DRIVER_TI_CPSW +#define CONFIG_MII +#define CONFIG_BOOTP_DEFAULT +#define CONFIG_BOOTP_DNS +#define CONFIG_BOOTP_DNS2 +#define CONFIG_BOOTP_SEND_HOSTNAME +#define CONFIG_BOOTP_GATEWAY +#define CONFIG_BOOTP_SUBNETMASK +#define CONFIG_NET_RETRY_COUNT 10 +#define CONFIG_NET_MULTI +#define CONFIG_PHY_GIGE +#define CONFIG_PHYLIB +#endif /* ! __CONFIG_AM335X_EVM_H */
Signature · 1 line
1.7.9.5