New MIIPHYBB implementation with multi-bus support
Subsystems (2)
v3 cover New MIIPHYBB implementation with multi-bus support
From: Luigi 'Comio' Mantellini <[email protected]>
This patch rewrites the miiphybb ( Bit-banged MII bus driver ) in order to support an arbitrary number of buses. This feature is useful when your board uses different mii buses for different phys and all (or a part) of these buses are implemented via bit-banging mode.
The driver requires that the following macros should be defined into the board configuration file:
CONFIG_BITBANGMII - Enable the miiphybb driverCONFIG_BITBANGMII_MULTI - Enable the multi bus support
If the CONFIG_BITBANGMII_MULTI is not defined, the board's config file needs to define the following macros:
MII_INIT - Generic cod to enable the MII bus (like gpios setup) MDIO_DECLARE - Declaration needed to access to the MDIO pin MDIO_ACTIVE - Activate the MDIO pin as out pin MDIO_TRISTATE - Activate the MDIO pin as input/tristate pin MDIO_READ - Read the MDIO pin MDIO(v) - Write v on the MDIO pin MDC_DECLARE - Declaration needed to access to the MDC pin MDC(v) - Write v on the MDC pin
The previous macros make the driver compatible with the previous version (that didn't support the multi-bus).
When the CONFIG_BITBANGMII_MULTI is defined, the board code needs to fill the bbmiibusses[] array with a record for each required bus.
The record (struct bbmiibus) has the following fields/callbacks (see miiphy.h for details):
char name[] - The symbolic name that must be equal to the MII bus registered
name
int (*init)() - Initialization function called at startup time (just before the
Ethernet initialization)
int (*mdio_active)() - Activate the MDIO pin as output
int (*mdio_tristate)() - Activate the MDIO pin as input/tristate pin
int (*set_mdio)() - Write the MDIO pin int (*get_mdio)() - Read the MDIO pin int (*set_mdc)() - Write the MDC pin int (*delay)() - Delay function void *priv - Private data used by board specific code
The board code will look like:
struct bbmiibus bbmiibusses[] = {
{ .name = "miibus#1", .init = b1_init, .mdio_active = b1_mdio_active, ... }, { .name = "miibus#2", .init = b2_init, .mdio_active = b2_mdio_active, ... },
...
};
Patch Changelog:
v1 -- First (broken) release
v2 -- Fix some typos and disable callbacks pointers relacation (if
CONFIG_RELOC_FIXUP_WORKS is not defined)
v3 -- Do not relocate NULL pointers
Luigi 'Comio' Mantellini (3):
Bit-banged MII driver with multi-bus support.
Add bb_miiphy_init call before any ethernet bring-up code. Update all board to support new bbmiiphy driver (with multibus
support)
drivers/net/phy/miiphybb.c | 324 +++++++++++++++++++++++++++++------------- include/configs/ISPAN.h | 3 + include/configs/MPC8260ADS.h | 2 + include/configs/MPC8266ADS.h | 3 + include/configs/MPC8560ADS.h | 3 + include/configs/Rattler.h | 3 + include/configs/SBC8540.h | 3 + include/configs/TQM8272.h | 2 + include/configs/VoVPN-GW.h | 3 + include/configs/ZPC1900.h | 3 + include/configs/ep8248.h | 3 + include/configs/ep82xxm.h | 3 + include/configs/gw8260.h | 3 + include/configs/hymod.h | 9 ++ include/configs/muas3001.h | 3 + include/configs/ppmc8260.h | 3 + include/configs/sacsng.h | 3 + include/configs/sbc8260.h | 3 + include/configs/sbc8560.h | 3 + include/miiphy.h | 22 +++ lib_arm/board.c | 3 + lib_avr32/board.c | 3 + lib_blackfin/board.c | 3 + lib_i386/board.c | 3 + lib_m68k/board.c | 3 + lib_mips/board.c | 3 + lib_ppc/board.c | 4 +- lib_sh/board.c | 3 + lib_sparc/board.c | 3 + 29 files changed, 335 insertions(+), 97 deletions(-)
PATCH v3 1/3 Bit-banged MII driver with multi-bus support.
From: Luigi 'Comio' Mantellini <[email protected]>
--- drivers/net/phy/miiphybb.c | 324 +++++++++++++++++++++++++++++++------------- include/miiphy.h | 22 +++ 2 files changed, 250 insertions(+), 96 deletions(-)
drivers/net/phy/miiphybb.c +228 -96
@@ -1,4 +1,7 @@/* +* (C) Copyright 2009 Industrie Dial Face S.p.A. +* Luigi 'Comio' Mantellini <[email protected]> +* * (C) Copyright 2001 * Gerald Van Baren, Custom IDEAS, vanbaren at cideas.com. *
@@ -29,18 +32,137 @@#include <common.h> #include <ioports.h> #include <ppc_asm.tmpl> +#include <miiphy.h> + +#define BBMII_RELOATE (v,off) (v += (v?off:0)) + +DECLARE_GLOBAL_DATA_PTR ; + +#ifndef CONFIG_BITBANGMII_MULTI +/* +* If CONFIG_BITBANGMII_MULTI is not defined we use a +* compatibility layer with the previous miiphybb implementation +* based on macros usage. +* +*/ +static int bb_mii_init_wrap (struct bbmiibus *bus) +{ +#ifdef MII_INIT +MII_INIT ; +#endif +return 0 ; +} + +static int bb_mdio_active_wrap (struct bbmiibus *bus) +{ +#ifdef MDIO_DECLARE +MDIO_DECLARE ; +#endif +MDIO_ACTIVE ; +return 0 ; +} + +static int bb_mdio_tristate_wrap (struct bbmiibus *bus) +{ +#ifdef MDIO_DECLARE +MDIO_DECLARE ; +#endif +MDIO_TRISTATE ; +return 0 ; +} + +static int bb_set_mdio_wrap (struct bbmiibus *bus,int v) +{ +#ifdef MDIO_DECLARE +MDIO_DECLARE ; +#endif +MDIO (v); +return 0 ; +} + +static int bb_get_mdio_wrap (struct bbmiibus *bus,int *v) +{ +#ifdef MDIO_DECLARE +MDIO_DECLARE ; +#endif + *v =MDIO_READ ; +return 0 ; +} + +static int bb_set_mdc_wrap (struct bbmiibus *bus,int v) +{ +#ifdef MDC_DECLARE +MDC_DECLARE ; +#endif +MDC (v); +return 0 ; +} + +static int bb_delay_wrap (struct bbmiibus *bus) +{ +MIIDELAY ; +return 0 ; +} + +struct bbmiibus bbmiibusses[] = { + { + .name =BB_MII_DEVNAME , + .init = bb_mii_init_wrap, + .mdio_active = bb_mdio_active_wrap, + .mdio_tristate = bb_mdio_tristate_wrap, + .set_mdio = bb_set_mdio_wrap, + .get_mdio = bb_get_mdio_wrap, + .set_mdc = bb_set_mdc_wrap, + .delay = bb_delay_wrap, + } +}; +#endif + +void bb_miiphy_init (void ) +{ +int i; +for (i =0 ; i <sizeof (bbmiibusses)/sizeof (bbmiibusses[0 ]); i++) { +#if !defined(CONFIG_RELOC_FIXUP_WORKS ) +/* Reloate the hooks pointers*/ +BBMII_RELOATE (bbmiibusses[i].init, gd->reloc_off); +BBMII_RELOATE (bbmiibusses[i].mdio_active, gd->reloc_off); +BBMII_RELOATE (bbmiibusses[i].mdio_tristate, gd->reloc_off); +BBMII_RELOATE (bbmiibusses[i].set_mdio, gd->reloc_off); +BBMII_RELOATE (bbmiibusses[i].get_mdio, gd->reloc_off); +BBMII_RELOATE (bbmiibusses[i].set_mdc, gd->reloc_off); +BBMII_RELOATE (bbmiibusses[i].delay, gd->reloc_off); +#endif + +if (bbmiibusses[i].init !=NULL ) { + bbmiibusses[i].init (&bbmiibusses[i]); + } + } +} + +static inline struct bbmiibus *bb_miiphy_getbus (char *devname) +{ +#ifdef CONFIG_BITBANGMII_MULTI +/* Search the correct bus */ +for (j =0 ; j <sizeof (bbmiibusses)/sizeof (bbmmis[0 ]); j++) { +if (!strcmp (bbmiibusses[i].name, devname)) { +return &bbmiibusses[i]; + } + } +return NULL ; +#else +/* We have just one bitbanging bus */ +return &bbmiibusses[0 ]; +#endif +}/***************************************************************************** * * Utility to send the preamble, address, and register (common to read * and write). */ -static void miiphy_pre (char read,unsigned char addr,unsigned char reg) +static void miiphy_pre (struct bbmiibus *bus,char read,unsigned char addr,unsigned char reg) {int j;/* counter */ -#if !(defined(CONFIG_EP8248 ) || defined(CONFIG_EP82XXM )) -volatile ioport_t *iop =ioport_addr ((immap_t *)CONFIG_SYS_IMMR ,MDIO_PORT ); -#endif /* * Send a 32 bit preamble ('1's) with an extra '1' bit for good measure.
@@ -50,67 +172,66 @@ static void miiphy_pre (char read, unsigned char addr, unsigned char reg)* but it is safer and will be much more robust. */ -MDIO_ACTIVE ; -MDIO (1 ); + bus->mdio_active (bus); + bus->set_mdio (bus,1 );for (j =0 ; j <32 ; j++) { -MDC (0 ); -MIIDELAY ; -MDC (1 ); -MIIDELAY ; + bus->set_mdc (bus,0 ); + bus->delay (bus); + bus->set_mdc (bus,1 ); + bus->delay (bus); }/* send the start bit (01) and the read opcode (10) or write (10) */ -MDC (0 ); -MDIO (0 ); -MIIDELAY ; -MDC (1 ); -MIIDELAY ; -MDC (0 ); -MDIO (1 ); -MIIDELAY ; -MDC (1 ); -MIIDELAY ; -MDC (0 ); -MDIO (read); -MIIDELAY ; -MDC (1 ); -MIIDELAY ; -MDC (0 ); -MDIO (!read); -MIIDELAY ; -MDC (1 ); -MIIDELAY ; + bus->set_mdc (bus,0 ); + bus->set_mdio (bus,0 ); + bus->delay (bus); + bus->set_mdc (bus,1 ); + bus->delay (bus); + bus->set_mdc (bus,0 ); + bus->set_mdio (bus,1 ); + bus->delay (bus); + bus->set_mdc (bus,1 ); + bus->delay (bus); + bus->set_mdc (bus,0 ); + bus->set_mdio (bus, read); + bus->delay (bus); + bus->set_mdc (bus,1 ); + bus->delay (bus); + bus->set_mdc (bus,0 ); + bus->set_mdio (bus, !read); + bus->delay (bus); + bus->set_mdc (bus,1 ); + bus->delay (bus);/* send the PHY address */ for (j =0 ; j <5 ; j++) { -MDC (0 ); + bus->set_mdc (bus,0 );if ((addr &0x10 ) ==0 ) { -MDIO (0 ); + bus->set_mdio (bus,0 ); }else { -MDIO (1 ); + bus->set_mdio (bus,1 ); } -MIIDELAY ; -MDC (1 ); -MIIDELAY ; + bus->delay (bus); + bus->set_mdc (bus,1 ); + bus->delay (bus); addr <<=1 ; }/* send the register address */ for (j =0 ; j <5 ; j++) { -MDC (0 ); + bus->set_mdc (bus,0 );if ((reg &0x10 ) ==0 ) { -MDIO (0 ); + bus->set_mdio (bus,0 ); }else { -MDIO (1 ); + bus->set_mdio (bus,1 ); } -MIIDELAY ; -MDC (1 ); -MIIDELAY ; + bus->delay (bus); + bus->set_mdc (bus,1 ); + bus->delay (bus); reg <<=1 ; } } -/***************************************************************************** * * Read a MII PHY register.
@@ -122,59 +243,66 @@ int bb_miiphy_read (char *devname, unsigned char addr, unsigned char reg, unsigned short *value) { short rdreg; /* register working value */ +int v;int j;/* counter */ -#if !(defined(CONFIG_EP8248 ) || defined(CONFIG_EP82XXM )) -volatile ioport_t *iop =ioport_addr ((immap_t *)CONFIG_SYS_IMMR ,MDIO_PORT ); -#endif +struct bbmiibus *bus; + + bus =bb_miiphy_getbus (devname); +if (bus ==NULL ) { +/* Bus not found! */ +return -1 ; + }if (value ==NULL ) {puts ("NULL value pointer\n" );return (-1 ); } -miiphy_pre (1 , addr, reg); +miiphy_pre (bus,1 , addr, reg);/* tri-state our MDIO I/O pin so we can read */ -MDC (0 ); -MDIO_TRISTATE ; -MIIDELAY ; -MDC (1 ); -MIIDELAY ; + bus->set_mdc (bus,0 ); + bus->mdio_tristate (bus); + bus->delay (bus); + bus->set_mdc (bus,1 ); + bus->delay (bus);/* check the turnaround bit: the PHY should be driving it to zero */ -if (MDIO_READ !=0 ) { + bus->get_mdio (bus, &v); +if (v !=0 ) {/* puts ("PHY didn't drive TA low\n"); */ for (j =0 ; j <32 ; j++) { -MDC (0 ); -MIIDELAY ; -MDC (1 ); -MIIDELAY ; + bus->set_mdc (bus,0 ); + bus->delay (bus); + bus->set_mdc (bus,1 ); + bus->delay (bus); }/* There is no PHY, set value to 0xFFFF and return */ *value =0xFFFF ;return (-1 ); } -MDC (0 ); -MIIDELAY ; + bus->set_mdc (bus,0 ); + bus->delay (bus);/* read 16 bits of register data, MSB first */ rdreg =0 ;for (j =0 ; j <16 ; j++) { -MDC (1 ); -MIIDELAY ; + bus->set_mdc (bus,1 ); + bus->delay (bus); rdreg <<=1 ; - rdreg |=MDIO_READ ; -MDC (0 ); -MIIDELAY ; + bus->get_mdio (bus, &v); + rdreg |= (v &0x1 ); + bus->set_mdc (bus,0 ); + bus->delay (bus); } -MDC (1 ); -MIIDELAY ; -MDC (0 ); -MIIDELAY ; -MDC (1 ); -MIIDELAY ; + bus->set_mdc (bus,1 ); + bus->delay (bus); + bus->set_mdc (bus,0 ); + bus->delay (bus); + bus->set_mdc (bus,1 ); + bus->delay (bus); *value = rdreg;
@@ -196,47 +324,51 @@ int bb_miiphy_read (char *devname, unsigned char addr,int bb_miiphy_write (char *devname,unsigned char addr,unsigned char reg,unsigned short value) { +struct bbmiibus *bus;int j;/* counter */ -#if !(defined(CONFIG_EP8248 ) || defined(CONFIG_EP82XXM )) -volatile ioport_t *iop =ioport_addr ((immap_t *)CONFIG_SYS_IMMR ,MDIO_PORT ); -#endif -miiphy_pre (0 , addr, reg); + bus =bb_miiphy_getbus (devname); +if (bus ==NULL ) { +/* Bus not found! */ +return -1 ; + } + +miiphy_pre (bus,0 , addr, reg);/* send the turnaround (10) */ -MDC (0 ); -MDIO (1 ); -MIIDELAY ; -MDC (1 ); -MIIDELAY ; -MDC (0 ); -MDIO (0 ); -MIIDELAY ; -MDC (1 ); -MIIDELAY ; + bus->set_mdc (bus,0 ); + bus->set_mdio (bus,1 ); + bus->delay (bus); + bus->set_mdc (bus,1 ); + bus->delay (bus); + bus->set_mdc (bus,0 ); + bus->set_mdio (bus,0 ); + bus->delay (bus); + bus->set_mdc (bus,1 ); + bus->delay (bus);/* write 16 bits of register data, MSB first */ for (j =0 ; j <16 ; j++) { -MDC (0 ); + bus->set_mdc (bus,0 );if ((value &0x00008000 ) ==0 ) { -MDIO (0 ); + bus->set_mdio (bus,0 ); }else { -MDIO (1 ); + bus->set_mdio (bus,1 ); } -MIIDELAY ; -MDC (1 ); -MIIDELAY ; + bus->delay (bus); + bus->set_mdc (bus,1 ); + bus->delay (bus); value <<=1 ; }/* * Tri-state the MDIO line. */ -MDIO_TRISTATE ; -MDC (0 ); -MIIDELAY ; -MDC (1 ); -MIIDELAY ; + bus->mdio_tristate (bus); + bus->set_mdc (bus,0 ); + bus->delay (bus); + bus->set_mdc (bus,1 ); + bus->delay (bus);return 0 ; -} +}
include/miiphy.h +22 -0
@@ -19,6 +19,8 @@| | COPYRIGHT I B M CORPORATION 1999 | LICENSED MATERIAL - PROGRAM PROPERTY OF I B M +| +| Additions (C) Copyright 2009 Industrie Dial Face S.p.A. +----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------+ |
@@ -61,12 +63,32 @@ char *miiphy_get_current_dev (void);void miiphy_listdev (void ); +#ifdef CONFIG_BITBANGMII +#define BB_MII_DEVNAME "bbmii" +struct bbmiibus { +char name[NAMESIZE ]; +int (*init)(struct bbmiibus *bus); +int (*mdio_active)(struct bbmiibus *bus); +int (*mdio_tristate)(struct bbmiibus *bus); +int (*set_mdio)(struct bbmiibus *bus,int v); +int (*get_mdio)(struct bbmiibus *bus,int *v); +int (*set_mdc)(struct bbmiibus *bus,int v); +int (*delay)(struct bbmiibus *bus); +#ifdef CONFIG_BITBANGMII_MULTI +void *priv; +#endif +}; + +extern struct bbmiibus bbmiibusses[]; + +void bb_miiphy_init (void );int bb_miiphy_read (char *devname,unsigned char addr,unsigned char reg,unsigned short *value);int bb_miiphy_write (char *devname,unsigned char addr,unsigned char reg,unsigned short value); +#endif /* phy seed setup */ #define AUTO 99
Signature · 1 line
1.6.3.3
PATCH v3 2/3 Add bb_miiphy_init call before any ethernet bring-up code.
From: Luigi 'Comio' Mantellini <[email protected]>
--- lib_arm/board.c | 3 +++ lib_avr32/board.c | 3 +++ lib_blackfin/board.c | 3 +++ lib_i386/board.c | 3 +++ lib_m68k/board.c | 3 +++ lib_mips/board.c | 3 +++ lib_ppc/board.c | 4 +++- lib_sh/board.c | 3 +++ lib_sparc/board.c | 3 +++ 9 files changed, 27 insertions(+), 1 deletions(-)
lib_arm/board.c +3 -0
@@ -417,6 +417,9 @@ extern void davinci_eth_set_mac_addr (const u_int8_t *addr);mmc_initialize (gd->bd);#endif +#ifdef CONFIG_BITBANGMII +bb_miiphy_init (); +#endif #if defined(CONFIG_CMD_NET )#if defined(CONFIG_NET_MULTI )puts ("Net: " );
lib_avr32/board.c +3 -0
@@ -337,6 +337,9 @@ void board_init_r(gd_t *new_gd, ulong dest_addr)if (s) load_addr =simple_strtoul (s,NULL ,16 ); +#ifdef CONFIG_BITBANGMII +bb_miiphy_init (); +#endif #if defined(CONFIG_CMD_NET ) s =getenv ("bootfile" );if (s)
lib_blackfin/board.c +3 -0
@@ -270,6 +270,9 @@ void board_init_f(ulong bootflag)static void board_net_init_r (bd_t *bd) { +#ifdef CONFIG_BITBANGMII +bb_miiphy_init (); +#endif #ifdef CONFIG_CMD_NET uchar enetaddr[6 ];char *s;
lib_i386/board.c +3 -0
@@ -351,6 +351,9 @@ void start_i386boot (void)doc_init ();#endif +#ifdef CONFIG_BITBANGMII +bb_miiphy_init (); +#endif #if defined(CONFIG_CMD_NET )#if defined(CONFIG_NET_MULTI )WATCHDOG_RESET ();
lib_m68k/board.c +3 -0
@@ -630,6 +630,9 @@ void board_init_r (gd_t *id, ulong dest_addr)nand_init ();/* go init the NAND */ #endif +#ifdef CONFIG_BITBANGMII +bb_miiphy_init (); +#endif #if defined(CONFIG_CMD_NET )WATCHDOG_RESET ();#if defined(FEC_ENET )
lib_mips/board.c +3 -0
@@ -407,6 +407,9 @@ void board_init_r (gd_t *id, ulong dest_addr)misc_init_r ();#endif +#ifdef CONFIG_BITBANGMII +bb_miiphy_init (); +#endif #if defined(CONFIG_CMD_NET )#if defined(CONFIG_NET_MULTI )puts ("Net: " );
lib_ppc/board.c +3 -1
@@ -1002,6 +1002,9 @@ void board_init_r (gd_t *id, ulong dest_addr)doc_init ();#endif +#ifdef CONFIG_BITBANGMII +bb_miiphy_init (); +#endif #if defined(CONFIG_CMD_NET )#if defined(CONFIG_NET_MULTI )WATCHDOG_RESET ();
@@ -1009,7 +1012,6 @@ void board_init_r (gd_t *id, ulong dest_addr)#endif eth_initialize (bd);#endif - #if defined(CONFIG_CMD_NET) && ( \ defined(CONFIG_CCM) || \ defined(CONFIG_ELPT860) || \
lib_sh/board.c +3 -0
@@ -178,6 +178,9 @@ void sh_generic_init(void)#endif /* CONFIG_WATCHDOG*/ +#ifdef CONFIG_BITBANGMII +bb_miiphy_init (); +#endif #if defined(CONFIG_CMD_NET ) {char *s;
lib_sparc/board.c +3 -0
@@ -405,6 +405,9 @@ void board_init_f(ulong bootflag)doc_init ();#endif +#ifdef CONFIG_BITBANGMII +bb_miiphy_init (); +#endif #if defined(CONFIG_CMD_NET )#if defined(CONFIG_NET_MULTI )WATCHDOG_RESET ();
Signature · 1 line
1.6.3.3
PATCH v3 3/3 Update all board to support new bbmiiphy driver (with multibus support)
From: Luigi 'Comio' Mantellini <[email protected]>
--- include/configs/ISPAN.h | 3 +++ include/configs/MPC8260ADS.h | 2 ++ include/configs/MPC8266ADS.h | 3 +++ include/configs/MPC8560ADS.h | 3 +++ include/configs/Rattler.h | 3 +++ include/configs/SBC8540.h | 3 +++ include/configs/TQM8272.h | 2 ++ include/configs/VoVPN-GW.h | 3 +++ include/configs/ZPC1900.h | 3 +++ include/configs/ep8248.h | 3 +++ include/configs/ep82xxm.h | 3 +++ include/configs/gw8260.h | 3 +++ include/configs/hymod.h | 9 +++++++++ include/configs/muas3001.h | 3 +++ include/configs/ppmc8260.h | 3 +++ include/configs/sacsng.h | 3 +++ include/configs/sbc8260.h | 3 +++ include/configs/sbc8560.h | 3 +++ 18 files changed, 58 insertions(+), 0 deletions(-)
include/configs/ISPAN.h +3 -0
@@ -84,6 +84,9 @@* GPIO pins used for bit-banged MII communications */ #define MDIO_PORT 3/* Port D */ +#define MDIO_DECLARE volatile ioport_t *iop = ioport_addr ((immap_t *) CONFIG_SYS_IMMR, MDIO_PORT) +#define MDC_DECLARE MDIO_DECLARE +#define CONFIG_SYS_MDIO_PIN 0x00040000/* PD13 */ #define CONFIG_SYS_MDC_PIN 0x00080000/* PD12 */
include/configs/MPC8260ADS.h +2 -0
@@ -149,6 +149,8 @@* GPIO pins used for bit-banged MII communications */ #define MDIO_PORT 2/* Port C */ +#define MDIO_DECLARE volatile ioport_t *iop = ioport_addr ((immap_t *) CONFIG_SYS_IMMR, MDIO_PORT) +#define MDC_DECLARE MDIO_DECLARE#if CONFIG_ADSTYPE ==CONFIG_SYS_8272ADS #define CONFIG_SYS_MDIO_PIN 0x00002000/* PC18 */
include/configs/MPC8266ADS.h +3 -0
@@ -95,6 +95,9 @@* Port pins used for bit-banged MII communictions (if applicable). */ #define MDIO_PORT 2/* Port C */ +#define MDIO_DECLARE volatile ioport_t *iop = ioport_addr ((immap_t *) CONFIG_SYS_IMMR, MDIO_PORT) +#define MDC_DECLARE MDIO_DECLARE +#define MDIO_ACTIVE (iop->pdir |= 0x00400000)#define MDIO_TRISTATE (iop->pdir &= ~0x00400000)#define MDIO_READ ((iop->pdat & 0x00400000) != 0)
include/configs/MPC8560ADS.h +3 -0
@@ -362,6 +362,9 @@* GPIO pins used for bit-banged MII communications */ #define MDIO_PORT 2/* Port C */ +#define MDIO_DECLARE volatile ioport_t *iop = ioport_addr ((immap_t *) CONFIG_SYS_IMMR, MDIO_PORT) +#define MDC_DECLARE MDIO_DECLARE +#define MDIO_ACTIVE (iop->pdir |= 0x00400000)#define MDIO_TRISTATE (iop->pdir &= ~0x00400000)#define MDIO_READ ((iop->pdat & 0x00400000) != 0)
include/configs/Rattler.h +3 -0
@@ -103,6 +103,9 @@* GPIO pins used for bit-banged MII communications */ #define MDIO_PORT 2/* Port C */ +#define MDIO_DECLARE volatile ioport_t *iop = ioport_addr ((immap_t *) CONFIG_SYS_IMMR, MDIO_PORT) +#define MDC_DECLARE MDIO_DECLARE +#define MDIO_ACTIVE (iop->pdir |= 0x00400000)#define MDIO_TRISTATE (iop->pdir &= ~0x00400000)#define MDIO_READ ((iop->pdat & 0x00400000) != 0)
include/configs/SBC8540.h +3 -0
@@ -286,6 +286,9 @@* GPIO pins used for bit-banged MII communications */ #define MDIO_PORT 2/* Port C */ +#define MDIO_DECLARE volatile ioport_t *iop = ioport_addr ((immap_t *) CONFIG_SYS_IMMR, MDIO_PORT) +#define MDC_DECLARE MDIO_DECLARE +#define MDIO_ACTIVE (iop->pdir |= 0x00400000)#define MDIO_TRISTATE (iop->pdir &= ~0x00400000)#define MDIO_READ ((iop->pdat & 0x00400000) != 0)
include/configs/TQM8272.h +2 -0
@@ -219,6 +219,8 @@* GPIO pins used for bit-banged MII communications */ #define MDIO_PORT 2/* Port C */ +#define MDIO_DECLARE volatile ioport_t *iop = ioport_addr ((immap_t *) CONFIG_SYS_IMMR, MDIO_PORT) +#define MDC_DECLARE MDIO_DECLARE#if STK82xx_150#define CONFIG_SYS_MDIO_PIN 0x00008000/* PC16 */
include/configs/VoVPN-GW.h +3 -0
@@ -124,6 +124,9 @@#define CONFIG_BITBANGMII #define MDIO_PORT 1/* Port B */ +#define MDIO_DECLARE volatile ioport_t *iop = ioport_addr ((immap_t *) CONFIG_SYS_IMMR, MDIO_PORT) +#define MDC_DECLARE MDIO_DECLARE +#define CONFIG_SYS_MDIO_PIN 0x00002000/* PB18 */ #define CONFIG_SYS_MDC_PIN 0x00001000/* PB19 */ #define MDIO_ACTIVE (iop->pdir |= CONFIG_SYS_MDIO_PIN)
include/configs/ZPC1900.h +3 -0
@@ -86,6 +86,9 @@* GPIO pins used for bit-banged MII communications */ #define MDIO_PORT 2/* Port C */ +#define MDIO_DECLARE volatile ioport_t *iop = ioport_addr ((immap_t *) CONFIG_SYS_IMMR, MDIO_PORT) +#define MDC_DECLARE MDIO_DECLARE +#define MDIO_ACTIVE (iop->pdir |= 0x00400000)#define MDIO_TRISTATE (iop->pdir &= ~0x00400000)#define MDIO_READ ((iop->pdat & 0x00400000) != 0)
include/configs/ep8248.h +3 -0
@@ -92,6 +92,9 @@* GPIO pins used for bit-banged MII communications */ #define MDIO_PORT 0/* Not used - implemented in BCSR */ +#define MDIO_DECLARE volatile ioport_t *iop = ioport_addr ((immap_t *) CONFIG_SYS_IMMR, MDIO_PORT) +#define MDC_DECLARE MDIO_DECLARE +#define MDIO_ACTIVE (*(vu_char *)(CONFIG_SYS_BCSR + 8) &= 0xFB)#define MDIO_TRISTATE (*(vu_char *)(CONFIG_SYS_BCSR + 8) |= 0x04)#define MDIO_READ (*(vu_char *)(CONFIG_SYS_BCSR + 8) & 1)
include/configs/ep82xxm.h +3 -0
@@ -85,6 +85,9 @@* GPIO pins used for bit-banged MII communications */ #define MDIO_PORT 0/* Not used - implemented in BCSR */ +#define MDIO_DECLARE volatile ioport_t *iop = ioport_addr ((immap_t *) CONFIG_SYS_IMMR, MDIO_PORT) +#define MDC_DECLARE MDIO_DECLARE +#define MDIO_ACTIVE (*(vu_char *)(CONFIG_SYS_BCSR + 8) &= 0xFB)#define MDIO_TRISTATE (*(vu_char *)(CONFIG_SYS_BCSR + 8) |= 0x04)#define MDIO_READ (*(vu_char *)(CONFIG_SYS_BCSR + 8) & 1)
include/configs/gw8260.h +3 -0
@@ -212,6 +212,9 @@* Port pins used for bit-banged MII communictions (if applicable). */ #define MDIO_PORT 2/* Port C */ +#define MDIO_DECLARE volatile ioport_t *iop = ioport_addr ((immap_t *) CONFIG_SYS_IMMR, MDIO_PORT) +#define MDC_DECLARE MDIO_DECLARE +#define MDIO_ACTIVE (iop->pdir |= 0x00400000)#define MDIO_TRISTATE (iop->pdir &= ~0x00400000)#define MDIO_READ ((iop->pdat & 0x00400000) != 0)
include/configs/hymod.h +9 -0
@@ -93,6 +93,9 @@# define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE|FCC_PSMR_LPB)# define MDIO_PORT 0/* Port A */ +# define MDIO_DECLARE volatile ioport_t *iop = ioport_addr ((immap_t *) CONFIG_SYS_IMMR, MDIO_PORT) +# define MDC_DECLARE MDIO_DECLARE +# define MDIO_DATA_PINMASK 0x00040000/* Pin 13 */ # define MDIO_CLCK_PINMASK 0x00080000/* Pin 12 */
@@ -110,6 +113,9 @@# define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE|FCC_PSMR_LPB)# define MDIO_PORT 0/* Port A */ +# define MDIO_DECLARE volatile ioport_t *iop = ioport_addr ((immap_t *) CONFIG_SYS_IMMR, MDIO_PORT) +# define MDC_DECLARE MDIO_DECLARE +# define MDIO_DATA_PINMASK 0x00000040/* Pin 25 */ # define MDIO_CLCK_PINMASK 0x00000080/* Pin 24 */
@@ -127,6 +133,9 @@# define CONFIG_SYS_FCC_PSMR (FCC_PSMR_FDE|FCC_PSMR_LPB)# define MDIO_PORT 0/* Port A */ +# define MDIO_DECLARE volatile ioport_t *iop = ioport_addr ((immap_t *) CONFIG_SYS_IMMR, MDIO_PORT) +# define MDC_DECLARE MDIO_DECLARE +# define MDIO_DATA_PINMASK 0x00000100/* Pin 23 */ # define MDIO_CLCK_PINMASK 0x00000200/* Pin 22 */
include/configs/muas3001.h +3 -0
@@ -101,6 +101,9 @@* GPIO pins used for bit-banged MII communications */ #define MDIO_PORT 0/* Port A */ +#define MDIO_DECLARE volatile ioport_t *iop = ioport_addr ((immap_t *) CONFIG_SYS_IMMR, MDIO_PORT) +#define MDC_DECLARE MDIO_DECLARE +#define CONFIG_SYS_MDIO_PIN 0x00200000/* PA10 */ #define CONFIG_SYS_MDC_PIN 0x00400000/* PA9 */
include/configs/ppmc8260.h +3 -0
@@ -182,6 +182,9 @@* Port pins used for bit-banged MII communictions (if applicable). */ #define MDIO_PORT 2/* Port C */ +#define MDIO_DECLARE volatile ioport_t *iop = ioport_addr ((immap_t *) CONFIG_SYS_IMMR, MDIO_PORT) +#define MDC_DECLARE MDIO_DECLARE +#define MDIO_ACTIVE (iop->pdir |= 0x00400000)#define MDIO_TRISTATE (iop->pdir &= ~0x00400000)#define MDIO_READ ((iop->pdat & 0x00400000) != 0)
include/configs/sacsng.h +3 -0
@@ -179,6 +179,9 @@*/ #define MDIO_PORT 2/* Port A=0, B=1, C=2, D=3 */ +#define MDIO_DECLARE volatile ioport_t *iop = ioport_addr ((immap_t *) CONFIG_SYS_IMMR, MDIO_PORT) +#define MDC_DECLARE MDIO_DECLARE +#define MDIO_ACTIVE (iop->pdir |= 0x40000000)#define MDIO_TRISTATE (iop->pdir &= ~0x40000000)#define MDIO_READ ((iop->pdat & 0x40000000) != 0)
include/configs/sbc8260.h +3 -0
@@ -201,6 +201,9 @@* Port pins used for bit-banged MII communictions (if applicable). */ #define MDIO_PORT 2/* Port C */ +#define MDIO_DECLARE volatile ioport_t *iop = ioport_addr ((immap_t *) CONFIG_SYS_IMMR, MDIO_PORT) +#define MDC_DECLARE MDIO_DECLARE +#define MDIO_ACTIVE (iop->pdir |= 0x00400000)#define MDIO_TRISTATE (iop->pdir &= ~0x00400000)#define MDIO_READ ((iop->pdat & 0x00400000) != 0)
include/configs/sbc8560.h +3 -0
@@ -285,6 +285,9 @@* GPIO pins used for bit-banged MII communications */ #define MDIO_PORT 2/* Port C */ +#define MDIO_DECLARE volatile ioport_t *iop = ioport_addr ((immap_t *) CONFIG_SYS_IMMR, MDIO_PORT) +#define MDC_DECLARE MDIO_DECLARE +#define MDIO_ACTIVE (iop->pdir |= 0x00400000)#define MDIO_TRISTATE (iop->pdir &= ~0x00400000)#define MDIO_READ ((iop->pdat & 0x00400000) != 0)
Signature · 1 line
1.6.3.3
PATCH v3 3/3 Update all board to support new bbmiiphy driver (with multibus support)
Hi Luigi,
Quoted 29 lines · Luigi 'Comio' Mantellini
From: Luigi 'Comio' Mantellini <[email protected]>
Signed-off-by Luigi 'Comio' Mantellini <[email protected]>--- include/configs/ISPAN.h | 3 +++ include/configs/MPC8260ADS.h | 2 ++ include/configs/MPC8266ADS.h | 3 +++ include/configs/MPC8560ADS.h | 3 +++ include/configs/Rattler.h | 3 +++ include/configs/SBC8540.h | 3 +++ include/configs/TQM8272.h | 2 ++ include/configs/VoVPN-GW.h | 3 +++ include/configs/ZPC1900.h | 3 +++ include/configs/ep8248.h | 3 +++ include/configs/ep82xxm.h | 3 +++ include/configs/gw8260.h | 3 +++ include/configs/hymod.h | 9 +++++++++ include/configs/muas3001.h | 3 +++ include/configs/ppmc8260.h | 3 +++ include/configs/sacsng.h | 3 +++ include/configs/sbc8260.h | 3 +++ include/configs/sbc8560.h | 3 +++ 18 files changed, 58 insertions(+), 0 deletions(-)include/configs/ISPAN.h +0
-0
include/configs/ISPAN.h line 88
Quoted 5 lines
include/configs/ISPAN.h +1
-0@@ -84,6 +84,9 @@* GPIO pins used for bit-banged MII communications */ #define MDIO_PORT 3/* Port D */ +#define MDIO_DECLARE volatile ioport_t *iop = ioport_addr ((immap_t *) CONFIG_SYS_IMMR, MDIO_PORT)
Line's too long (as are many in this patch). Please shorten them. The content seems fine...
<snip>
regards,
Ben
PATCH v3 2/3 Add bb_miiphy_init call before any ethernet bring-up code.
In reply to Luigi 'Comio' MantelliniHi Luigi,
Quoted 15 lines · Luigi 'Comio' Mantellini
From: Luigi 'Comio' Mantellini <[email protected]>
Signed-off-by Luigi 'Comio' Mantellini <[email protected]>--- lib_arm/board.c | 3 +++ lib_avr32/board.c | 3 +++ lib_blackfin/board.c | 3 +++ lib_i386/board.c | 3 +++ lib_m68k/board.c | 3 +++ lib_mips/board.c | 3 +++ lib_ppc/board.c | 4 +++- lib_sh/board.c | 3 +++ lib_sparc/board.c | 3 +++ 9 files changed, 27 insertions(+), 1 deletions(-)
I'm not sure about this. Bit-banged MII is very board-specific, and IMHO should be initialized in board_eth_init()
regards,
Ben
PATCH v3 2/3 Add bb_miiphy_init call before any ethernet bring-up code.
The lib_[arch]/board.c code calls the bb_miiphy_init that will do just 2 things:
1) Relocate the bb_mii_buses[i].* hooks (.init, .mdio_active, .delay, ...)
2) Call the board bb_mii_buses[i].init (board specific code).
The board specifc code will be contained into the hook .init filed into the bb_mii_buses vector.
Do you have a better solution?
thanks and best regards,
luigi
Quoted 26 lines · Ben Warren
Hi Luigi,
Quoted 14 lines · Luigi 'Comio' Mantellini
From: Luigi 'Comio' Mantellini <[email protected]>
Signed-off-by Luigi 'Comio' Mantellini <[email protected]>---
?lib_arm/board.c ? ? ?| ? ?3 +++ ?lib_avr32/board.c ? ?| ? ?3 +++ ?lib_blackfin/board.c | ? ?3 +++ ?lib_i386/board.c ? ? | ? ?3 +++ ?lib_m68k/board.c ? ? | ? ?3 +++ ?lib_mips/board.c ? ? | ? ?3 +++ ?lib_ppc/board.c ? ? ?| ? ?4 +++- ?lib_sh/board.c ? ? ? | ? ?3 +++ ?lib_sparc/board.c ? ?| ? ?3 +++Quoted 2 lines
?9 files changed, 27 insertions(+), 1 deletions(-)
I'm not sure about this. ?Bit-banged MII is very board-specific, and IMHO should be initialized in
board_eth_init()regards,
Ben
Signature · 10 lines
Luigi 'Comio' Mantellini R&D - Software Industrie Dial Face S.p.A. Via Canzo, 4 20068 Peschiera Borromeo (MI), Italy Tel.: +39 02 5167 2813 Fax: +39 02 5167 2459 web: www.idf-hit.com mail: luigi.mantellini at idf-hit.com
PATCH v3 2/3 Add bb_miiphy_init call before any ethernet bring-up code.
Quoted 11 lines · Luigi Mantellini
The lib_[arch]/board.c code calls the
bb_miiphy_initthat will do just 2 things:1) Relocate the bb_mii_buses[i].* hooks (.init, .mdio_active, .delay, ...)
2) Call the board bb_mii_buses[i].init (board specific code).The board specifc code will be contained into the hook .init filed into the
bb_mii_busesvector.Do you have a better solution?
In each case, you put the bb_miiphy_init() right before eth_initialize(). One of the first things eth_initialize() does is call board_eth_init(). Moving the call to each board's specific code would therefore not make any difference code-wise, but IMHO is architecturally cleaner. If #ifdef's are necessary (in this case they are), I believe it's better to have them in the more specific code (board) than generic (arch).
regards,
Ben
PATCH v3 2/3 Add bb_miiphy_init call before any ethernet bring-up code.
On Mon, Oct 5, 2009 at 10:18 PM, Ben Warren <[email protected]> wrote:
...
Quoted 8 lines
Quoted 7 lines
The board specifc code will be contained into the hook .init filed into the
bb_mii_busesvector.Do you have a better solution?
Quoted 6 lines
In each case, you put the
bb_miiphy_init()right beforeeth_initialize(). ?One of the first thingseth_initialize()does is callboard_eth_init(). ?Moving the call to each board's specific code would therefore not make any difference code-wise, but IMHO is architecturally cleaner. ?If #ifdef's are necessary (in this case they are), I believe it's better to have them in the more specific code (board) than generic (arch).
I agree your point of view, but there are a lot of network cards that registers the bb_mii bus. Another fact is that the network deivces can access to phy to complete the initialization. From these observation, I think that the bb_mii bus should be ready before the ethernet bring-up code.
Another solution is to modify all board specific bring-up code in order to init the bb_mii... but this solution seems to require a lot of trivial patches.
ciao
luigi
Quoted 4 lines
regards,
Ben
Signature · 10 lines
Luigi 'Comio' Mantellini R&D - Software Industrie Dial Face S.p.A. Via Canzo, 4 20068 Peschiera Borromeo (MI), Italy Tel.: +39 02 5167 2813 Fax: +39 02 5167 2459 web: www.idf-hit.com mail: luigi.mantellini at idf-hit.com
PATCH v3 1/3 Bit-banged MII driver with multi-bus support.
In reply to Luigi 'Comio' Mantellini(autoreview)
Hi Ben,
I make some changes to the patch, but I will post after your review. See my annotation, that will be present into the next patch release.
best regards.
Il mercoled? 23 settembre 2009 15:10:54 Luigi 'Comio' Mantellini ha scritto:
Quoted 13 lines
From: Luigi 'Comio' Mantellini <[email protected]>
Signed-off-by Luigi 'Comio' Mantellini <[email protected]>--- drivers/net/phy/miiphybb.c | 324 +++++++++++++++++++++++++++++++------------- include/miiphy.h | 22 +++ 2 files changed, 250 insertions(+), 96 deletions(-)drivers/net/phy/miiphybb.c +0
-0
...
drivers/net/phy/miiphybb.c
Quoted 2 lines
drivers/net/phy/miiphybb.c +2
-0+ +struct bbmiibus bbmiibusses[] = {
[COMIO] s/busses/buses - Sorry for the typo.
...
drivers/net/phy/miiphybb.c line 124
Quoted 5 lines
drivers/net/phy/miiphybb.c +5
-0+ +void bb_miiphy_init (void ) +{ +int i; +for (i =0 ; i <sizeof (bbmiibusses)/sizeof (bbmiibusses[0 ]); i++) {
[COMIO] Add bbmiibuses_num external variable. The board specific code need to instance it as:
int bbmiibuses_num = sizeof(bbmiibuses)/sizeof(bbmiibuses[0])
I need this because I cannot know the array size at compile time. The other solution may be to use a dummy value@the array end... What do you suggest?
...
drivers/net/phy/miiphybb.c line 146
Quoted 5 lines
drivers/net/phy/miiphybb.c +5
-0+static inline struct bbmiibus *bb_miiphy_getbus (char *devname) +{ +#ifdef CONFIG_BITBANGMII_MULTI +/* Search the correct bus */ +for (j =0 ; j <sizeof (bbmiibusses)/sizeof (bbmmis[0 ]); j++) {
[COMIO] Changed j to i and add i declaration.
include/miiphy.h line 20
Quoted 7 lines
include/miiphy.h +2
-0@@ -19,6 +19,8 @@ + +extern struct bbmiibus bbmiibusses[];
[COMIO] Change bbmiibusses to bbmiibuses and add the following declaration:
extern int bbmiibuses_num
Any comment is welcome
best regards,
luigi
Signature · 27 lines
Luigi 'Comio' Mantellini R&D - Software Industrie Dial Face S.p.A. Via Canzo, 4 20068 Peschiera Borromeo (MI) Italy Tel.: +39 02 5167 2813 Fax: +39 02 5167 2459 E-mail: luigi.mantellini at idf-hit.com Questo messaggio e i suoi allegati sono indirizzati esclusivamente alle persone indicate. La diffusione, copia o qualsiasi altra azione derivante dalla conoscenza di queste informazioni sono rigorosamente vietate. Qualora abbiate ricevuto questo documento per errore siete cortesemente pregati di darne immediata comunicazione al mittente e di provvedere alla sua distruzione, Grazie. Rispetta l'ambiente. Non stampare questa mail se non ? realmente necessario. This e-mail and any attachments is confidential and may contain privileged information intended for the addressee(s) only. Dissemination, copying, printing or use by anybody else is unauthorized. If you are not the intended recipient, please delete this message and any attachments and advise the sender by return e-mail, Thanks. Help the environment. Please do not print this email unless it is absolutely necessary.
PATCH v3 1/3 Bit-banged MII driver with multi-bus support.
Hi Luigi,
Quoted 15 lines · Luigi 'Comio' Mantellini
(autoreview)
Hi Ben,
I make some changes to the patch, but I will post after your review. See my annotation, that will be present into the next patch release.
best regards.
Il mercoled? 23 settembre 2009 15:10:54 Luigi 'Comio' Mantellini ha scritto:
Quoted 5 lines
From: Luigi 'Comio' Mantellini <[email protected]>
Signed-off-by Luigi 'Comio' Mantellini <[email protected]>--- drivers/net/phy/miiphybb.c | 324
[snip]
Quoted 7 lines
drivers/net/phy/miiphybb.c line 146
Quoted 5 lines
drivers/net/phy/miiphybb.c +5
-0+static inline struct bbmiibus *bb_miiphy_getbus (char *devname) +{ +#ifdef CONFIG_BITBANGMII_MULTI +/* Search the correct bus */ +for (j =0 ; j <sizeof (bbmiibusses)/sizeof (bbmmis[0 ]); j++) {[COMIO] Changed j to i and add i declaration.
You may have inherited the "j" loop counter from me. I stopped using "i" in loop counters and started with "j" because most code (variables and keywords) do not use words with the letter "j" or "k" in them. On the other hand, A LOT of variables and keywords have "i" in their names.
The result is that it is a PAIN to find loop variable references for
the loop variable "i" but it is usually trivial to find them for "j" and "k".
Case in point: how many "i"s does your loop have? Just in the for() loop control line, I count five.
Trivia:
* I find I almost never need to nest loops more than 2 deep, so "j" and "k" cover almost all loop variable needs.
* I believe Fortran coding conventions started the "ijk" counter mania.
[snip]
Quoted 5 lines
Any comment is welcome
best regards,
luigi
Best regards,
gvb
PATCH v3 1/3 Bit-banged MII driver with multi-bus support.
In reply to Luigi 'Comio' MantelliniHi Luigi,
Quoted 3 lines · Luigi 'Comio' Mantellini
From: Luigi 'Comio' Mantellini <[email protected]>
Please add some descriptive information here. This is a big patch and deserves a changelong
Quoted 19 lines
Signed-off-by Luigi 'Comio' Mantellini <[email protected]>--- drivers/net/phy/miiphybb.c | 324 +++++++++++++++++++++++++++++++------------- include/miiphy.h | 22 +++ 2 files changed, 250 insertions(+), 96 deletions(-)drivers/net/phy/miiphybb.c +3
-0@@ -1,4 +1,7 @@/* +* (C) Copyright 2009 Industrie Dial Face S.p.A. +* Luigi 'Comio' Mantellini <[email protected]> +* * (C) Copyright 2001 * Gerald Van Baren, Custom IDEAS, vanbaren at cideas.com. *
drivers/net/phy/miiphybb.c line 38
Quoted 7 lines
drivers/net/phy/miiphybb.c +3
-0@@ -29,18 +32,137 @@#include <common.h> #include <ioports.h> #include <ppc_asm.tmpl> +#include <miiphy.h> + +#define BBMII_RELOATE (v,off) (v += (v?off:0))
s/RELOATE/RELOCATE/
Please apply globally
Quoted 61 lines
drivers/net/phy/miiphybb.c +61
-0+ +DECLARE_GLOBAL_DATA_PTR ; + +#ifndef CONFIG_BITBANGMII_MULTI +/* +* If CONFIG_BITBANGMII_MULTI is not defined we use a +* compatibility layer with the previous miiphybb implementation +* based on macros usage. +* +*/ +static int bb_mii_init_wrap (struct bbmiibus *bus) +{ +#ifdef MII_INIT +MII_INIT ; +#endif +return 0 ; +} + +static int bb_mdio_active_wrap (struct bbmiibus *bus) +{ +#ifdef MDIO_DECLARE +MDIO_DECLARE ; +#endif +MDIO_ACTIVE ; +return 0 ; +} + +static int bb_mdio_tristate_wrap (struct bbmiibus *bus) +{ +#ifdef MDIO_DECLARE +MDIO_DECLARE ; +#endif +MDIO_TRISTATE ; +return 0 ; +} + +static int bb_set_mdio_wrap (struct bbmiibus *bus,int v) +{ +#ifdef MDIO_DECLARE +MDIO_DECLARE ; +#endif +MDIO (v); +return 0 ; +} + +static int bb_get_mdio_wrap (struct bbmiibus *bus,int *v) +{ +#ifdef MDIO_DECLARE +MDIO_DECLARE ; +#endif + *v =MDIO_READ ; +return 0 ; +} + +static int bb_set_mdc_wrap (struct bbmiibus *bus,int v) +{ +#ifdef MDC_DECLARE +MDC_DECLARE ; +#endif +MDC (v); +return 0 ;
drivers/net/phy/miiphybb.c line 157
Quoted 10 lines
drivers/net/phy/miiphybb.c +9
-0+} + +static int bb_delay_wrap (struct bbmiibus *bus) +{ +MIIDELAY ; +return 0 ; +} + +struct bbmiibus bbmiibusses[] = {
Elsewhere, you name things 'bb_mii', but here it's 'bbmii'. I personally prefer adding the underscores, but please be consistent.
Quoted 10 lines
drivers/net/phy/miiphybb.c +10
-0+ { + .name = BB_MII_DEVNAME, + .init = bb_mii_init_wrap, + .mdio_active = bb_mdio_active_wrap, + .mdio_tristate = bb_mdio_tristate_wrap, + .set_mdio = bb_set_mdio_wrap, + .get_mdio = bb_get_mdio_wrap, + .set_mdc = bb_set_mdc_wrap, + .delay = bb_delay_wrap, + }
drivers/net/phy/miiphybb.c line 157
Quoted 10 lines
drivers/net/phy/miiphybb.c +9
-0+}; +#endif + +void bb_miiphy_init (void ) +{ +int i; +for (i =0 ; i <sizeof (bbmiibusses)/sizeof (bbmiibusses[0 ]); i++) { +#if !defined(CONFIG_RELOC_FIXUP_WORKS ) +/* Reloate the hooks pointers*/
s/Reloate/Relocate/
s/hooks/hook/
Quoted 29 lines
drivers/net/phy/miiphybb.c +29
-0+BBMII_RELOATE (bbmiibusses[i].init, gd->reloc_off); +BBMII_RELOATE (bbmiibusses[i].mdio_active, gd->reloc_off); +BBMII_RELOATE (bbmiibusses[i].mdio_tristate, gd->reloc_off); +BBMII_RELOATE (bbmiibusses[i].set_mdio, gd->reloc_off); +BBMII_RELOATE (bbmiibusses[i].get_mdio, gd->reloc_off); +BBMII_RELOATE (bbmiibusses[i].set_mdc, gd->reloc_off); +BBMII_RELOATE (bbmiibusses[i].delay, gd->reloc_off); +#endif + +if (bbmiibusses[i].init !=NULL ) { + bbmiibusses[i].init (&bbmiibusses[i]); + } + } +} + +static inline struct bbmiibus *bb_miiphy_getbus (char *devname) +{ +#ifdef CONFIG_BITBANGMII_MULTI +/* Search the correct bus */ +for (j =0 ; j <sizeof (bbmiibusses)/sizeof (bbmmis[0 ]); j++) { +if (!strcmp (bbmiibusses[i].name, devname)) { +return &bbmiibusses[i]; + } + } +return NULL ; +#else +/* We have just one bitbanging bus */ +return &bbmiibusses[0 ]; +#endif
drivers/net/phy/miiphybb.c line 166
Quoted 10 lines
drivers/net/phy/miiphybb.c +2
-1+}/***************************************************************************** * * Utility to send the preamble, address, and register (common to read * and write). */ -static void miiphy_pre (char read,unsigned char addr,unsigned char reg) +static void miiphy_pre (struct bbmiibus *bus,char read,unsigned char addr,unsigned char reg)
This line's too long (please keep < 78 characters). Apply globally
Quoted 42 lines
drivers/net/phy/miiphybb.c +6
-23{int j;/* counter */ -#if !(defined(CONFIG_EP8248 ) || defined(CONFIG_EP82XXM )) -volatile ioport_t *iop =ioport_addr ((immap_t *)CONFIG_SYS_IMMR ,MDIO_PORT ); -#endif /* * Send a 32 bit preamble ('1's) with an extra '1' bit for good measure. @@ -50,67 +172,66 @@ static void miiphy_pre (char read, unsigned char addr, unsigned char reg)* but it is safer and will be much more robust. */ -MDIO_ACTIVE ; -MDIO (1 ); + bus->mdio_active (bus); + bus->set_mdio (bus,1 );for (j =0 ; j <32 ; j++) { -MDC (0 ); -MIIDELAY ; -MDC (1 ); -MIIDELAY ; + bus->set_mdc (bus,0 ); + bus->delay (bus); + bus->set_mdc (bus,1 ); + bus->delay (bus); }/* send the start bit (01) and the read opcode (10) or write (10) */ -MDC (0 ); -MDIO (0 ); -MIIDELAY ; -MDC (1 ); -MIIDELAY ; -MDC (0 ); -MDIO (1 ); -MIIDELAY ; -MDC (1 ); -MIIDELAY ; -MDC (0 ); -MDIO (read); -MIIDELAY ; -MDC (1 );
drivers/net/phy/miiphybb.c static void miiphy_pre (char read, unsigned char addr, unsigned char reg) · line 188
Quoted 10 lines
drivers/net/phy/miiphybb.c +3
-6-MIIDELAY ; -MDC (0 ); -MDIO (!read); -MIIDELAY ; -MDC (1 ); -MIIDELAY ; + bus->set_mdc (bus,0 ); + bus->set_mdio (bus,0 ); + bus->delay (bus);
Please be consistent with whitespace. I prefer no space before the
opening paren, although I think Wolfgang likes that. He's funny that
way. Note that this only relates to function calls. Control logic (if, for, while etc.) should always have a space before the opening paren.
Quoted 68 lines
drivers/net/phy/miiphybb.c +29
-13+ bus->set_mdc (bus,1 ); + bus->delay (bus); + bus->set_mdc (bus,0 ); + bus->set_mdio (bus,1 ); + bus->delay (bus); + bus->set_mdc (bus,1 ); + bus->delay (bus); + bus->set_mdc (bus,0 ); + bus->set_mdio (bus, read); + bus->delay (bus); + bus->set_mdc (bus,1 ); + bus->delay (bus); + bus->set_mdc (bus,0 ); + bus->set_mdio (bus, !read); + bus->delay (bus); + bus->set_mdc (bus,1 ); + bus->delay (bus);/* send the PHY address */ for (j =0 ; j <5 ; j++) { -MDC (0 ); + bus->set_mdc (bus,0 );if ((addr &0x10 ) ==0 ) { -MDIO (0 ); + bus->set_mdio (bus,0 ); }else { -MDIO (1 ); + bus->set_mdio (bus,1 ); } -MIIDELAY ; -MDC (1 ); -MIIDELAY ; + bus->delay (bus); + bus->set_mdc (bus,1 ); + bus->delay (bus); addr <<=1 ; }/* send the register address */ for (j =0 ; j <5 ; j++) { -MDC (0 ); + bus->set_mdc (bus,0 );if ((reg &0x10 ) ==0 ) { -MDIO (0 ); + bus->set_mdio (bus,0 ); }else { -MDIO (1 ); + bus->set_mdio (bus,1 ); } -MIIDELAY ; -MDC (1 ); -MIIDELAY ; + bus->delay (bus); + bus->set_mdc (bus,1 ); + bus->delay (bus); reg <<=1 ; } } -/***************************************************************************** * * Read a MII PHY register.
drivers/net/phy/miiphybb.c +1
-0@@ -122,59 +243,66 @@ int bb_miiphy_read (char *devname, unsigned char addr, unsigned char reg, unsigned short *value) { short rdreg; /* register working value */ +int v;
drivers/net/phy/miiphybb.c int bb_miiphy_read (char *devname, unsigned char addr, · line 253
Quoted 10 lines
drivers/net/phy/miiphybb.c +5
-3int j;/* counter */ -#if !(defined(CONFIG_EP8248 ) || defined(CONFIG_EP82XXM )) -volatile ioport_t *iop =ioport_addr ((immap_t *)CONFIG_SYS_IMMR ,MDIO_PORT ); -#endif +struct bbmiibus *bus; + + bus =bb_miiphy_getbus (devname); +if (bus ==NULL ) { +/* Bus not found! */
Comment's kinda superfluous...
Quoted 196 lines
drivers/net/phy/miiphybb.c +58
-50+return -1 ; + }if (value ==NULL ) {puts ("NULL value pointer\n" );return (-1 ); } -miiphy_pre (1 , addr, reg); +miiphy_pre (bus,1 , addr, reg);/* tri-state our MDIO I/O pin so we can read */ -MDC (0 ); -MDIO_TRISTATE ; -MIIDELAY ; -MDC (1 ); -MIIDELAY ; + bus->set_mdc (bus,0 ); + bus->mdio_tristate (bus); + bus->delay (bus); + bus->set_mdc (bus,1 ); + bus->delay (bus);/* check the turnaround bit: the PHY should be driving it to zero */ -if (MDIO_READ !=0 ) { + bus->get_mdio (bus, &v); +if (v !=0 ) {/* puts ("PHY didn't drive TA low\n"); */ for (j =0 ; j <32 ; j++) { -MDC (0 ); -MIIDELAY ; -MDC (1 ); -MIIDELAY ; + bus->set_mdc (bus,0 ); + bus->delay (bus); + bus->set_mdc (bus,1 ); + bus->delay (bus); }/* There is no PHY, set value to 0xFFFF and return */ *value =0xFFFF ;return (-1 ); } -MDC (0 ); -MIIDELAY ; + bus->set_mdc (bus,0 ); + bus->delay (bus);/* read 16 bits of register data, MSB first */ rdreg =0 ;for (j =0 ; j <16 ; j++) { -MDC (1 ); -MIIDELAY ; + bus->set_mdc (bus,1 ); + bus->delay (bus); rdreg <<=1 ; - rdreg |=MDIO_READ ; -MDC (0 ); -MIIDELAY ; + bus->get_mdio (bus, &v); + rdreg |= (v &0x1 ); + bus->set_mdc (bus,0 ); + bus->delay (bus); } -MDC (1 ); -MIIDELAY ; -MDC (0 ); -MIIDELAY ; -MDC (1 ); -MIIDELAY ; + bus->set_mdc (bus,1 ); + bus->delay (bus); + bus->set_mdc (bus,0 ); + bus->delay (bus); + bus->set_mdc (bus,1 ); + bus->delay (bus); *value = rdreg;@@ -196,47 +324,51 @@ int bb_miiphy_read (char *devname, unsigned char addr,int bb_miiphy_write (char *devname,unsigned char addr,unsigned char reg,unsigned short value) { +struct bbmiibus *bus;int j;/* counter */ -#if !(defined(CONFIG_EP8248 ) || defined(CONFIG_EP82XXM )) -volatile ioport_t *iop =ioport_addr ((immap_t *)CONFIG_SYS_IMMR ,MDIO_PORT ); -#endif -miiphy_pre (0 , addr, reg); + bus =bb_miiphy_getbus (devname); +if (bus ==NULL ) { +/* Bus not found! */ +return -1 ; + } + +miiphy_pre (bus,0 , addr, reg);/* send the turnaround (10) */ -MDC (0 ); -MDIO (1 ); -MIIDELAY ; -MDC (1 ); -MIIDELAY ; -MDC (0 ); -MDIO (0 ); -MIIDELAY ; -MDC (1 ); -MIIDELAY ; + bus->set_mdc (bus,0 ); + bus->set_mdio (bus,1 ); + bus->delay (bus); + bus->set_mdc (bus,1 ); + bus->delay (bus); + bus->set_mdc (bus,0 ); + bus->set_mdio (bus,0 ); + bus->delay (bus); + bus->set_mdc (bus,1 ); + bus->delay (bus);/* write 16 bits of register data, MSB first */ for (j =0 ; j <16 ; j++) { -MDC (0 ); + bus->set_mdc (bus,0 );if ((value &0x00008000 ) ==0 ) { -MDIO (0 ); + bus->set_mdio (bus,0 ); }else { -MDIO (1 ); + bus->set_mdio (bus,1 ); } -MIIDELAY ; -MDC (1 ); -MIIDELAY ; + bus->delay (bus); + bus->set_mdc (bus,1 ); + bus->delay (bus); value <<=1 ; }/* * Tri-state the MDIO line. */ -MDIO_TRISTATE ; -MDC (0 ); -MIIDELAY ; -MDC (1 ); -MIIDELAY ; + bus->mdio_tristate (bus); + bus->set_mdc (bus,0 ); + bus->delay (bus); + bus->set_mdc (bus,1 ); + bus->delay (bus);return 0 ; -} +}include/miiphy.h +19
-0@@ -19,6 +19,8 @@| | COPYRIGHT I B M CORPORATION 1999 | LICENSED MATERIAL - PROGRAM PROPERTY OF I B M +| +| Additions (C) Copyright 2009 Industrie Dial Face S.p.A. +----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------+ | @@ -61,12 +63,32 @@ char *miiphy_get_current_dev (void);void miiphy_listdev (void ); +#ifdef CONFIG_BITBANGMII +#define BB_MII_DEVNAME "bbmii" +struct bbmiibus { +char name[NAMESIZE ]; +int (*init)(struct bbmiibus *bus); +int (*mdio_active)(struct bbmiibus *bus); +int (*mdio_tristate)(struct bbmiibus *bus); +int (*set_mdio)(struct bbmiibus *bus,int v); +int (*get_mdio)(struct bbmiibus *bus,int *v); +int (*set_mdc)(struct bbmiibus *bus,int v); +int (*delay)(struct bbmiibus *bus); +#ifdef CONFIG_BITBANGMII_MULTI +void *priv; +#endif +}; + +extern struct bbmiibus bbmiibusses[];
include/miiphy.h char *miiphy_get_current_dev (void); · line 94
Quoted 10 lines
include/miiphy.h +3
-0+ +void bb_miiphy_init (void );int bb_miiphy_read (char *devname,unsigned char addr,unsigned char reg,unsigned short *value);int bb_miiphy_write (char *devname,unsigned char addr,unsigned char reg,unsigned short value); +#endif /* phy seed setup */ #define AUTO 99
Thanks for this submission. It's a really big improvement.
regards,
Ben
PATCH v3 1/3 Bit-banged MII driver with multi-bus support.
Hi Ben,
thank for your review. Find my inline comments.
Thanks and best regards,
luigi
Quoted 11 lines · Ben Warren
Hi Luigi,
Quoted 4 lines · Luigi 'Comio' Mantellini
From: Luigi 'Comio' Mantellini <[email protected]>
Please add some descriptive information here. ?This is a big patch and deserves a changelong
Quoted 1 line
Quoted 7 lines
drivers/net/phy/miiphybb.c line 37
Quoted 3 lines
drivers/net/phy/miiphybb.c +2
-0+ +#define BBMII_RELOATE (v,off) (v += (v?off:0))s/RELOATE/RELOCATE/
Please apply globally
Ok.
Quoted 6 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ +struct bbmiibus bbmiibusses[] = {Elsewhere, you name things '
bb_mii', but here it's 'bbmii'. ?I personally prefer adding the underscores, but please be consistent.
What do you mean? change bbmiibus -> bb_mii_bus and bbmiibuses -> bb_mii_buses?
Quoted 3 lines
Quoted 3 lines
+ ? ? ? {
+ ? ? ? ? ? ? ? .name =BB_MII_DEVNAME,
BB_MII_DEVNAME will be "bb_mii". is it ok?
Quoted 10 lines
Quoted 9 lines
+ ? ? ? ? ? ? ? .init =
bb_mii_init_wrap,
+ ? ? ? ? ? ? ? .mdio_active =bb_mdio_active_wrap,
+ ? ? ? ? ? ? ? .mdio_tristate =bb_mdio_tristate_wrap,
+ ? ? ? ? ? ? ? .set_mdio =bb_set_mdio_wrap,
+ ? ? ? ? ? ? ? .get_mdio =bb_get_mdio_wrap,
+ ? ? ? ? ? ? ? .set_mdc =bb_set_mdc_wrap,
+ ? ? ? ? ? ? ? .delay =bb_delay_wrap,
+ ? ? ? }
+};
Quoted 6 lines
Quoted 3 lines
+#if !defined(CONFIG_RELOC_FIXUP_WORKS)
+ ? ? ? ? ? ? ? /* Reloate the hooks pointers*/s/Reloate/Relocate/
s/hooks/hook/
ok
Quoted 7 lines
Quoted 5 lines
?*/
(quoted diff) +1
-1-static void miiphy_pre (char read, unsigned char addr, unsigned char reg) +static void miiphy_pre (struct bbmiibus *bus, char read, unsigned charaddr, unsigned char reg)
This line's too long (please keep < 78 characters). ?Apply globally
ok
Quoted 4 lines
Quoted 4 lines
*/
- ? ? ? MDC (0);
- ? ? ? MDIO (0);
- ? ? ? MIIDELAY;
...
Quoted 9 lines
Quoted 4 lines
+ ? ? ?
bus->set_mdc(bus, 0);
+ ? ? ?bus->set_mdio(bus, 0);
+ ? ? ?bus->delay(bus);Please be consistent with whitespace. ?I prefer no space before the opening paren, although I think Wolfgang likes that. ? He's funny that way. ?Note that this only relates to function calls. ?Control logic (if, for, while etc.) should always have a space before the opening paren.
I just replaced MD{C,IO} with bus->set_md{c,io}.
Ok.
Quoted 7 lines
Quoted 5 lines
+
+ ? ? ? bus =bb_miiphy_getbus(devname);
+ ? ? ? if (bus == NULL) {
+ ? ? ? ? ? ? ? /* Bus not found! */Comment's kinda superfluous...
I know that the source code is always sufficiently clear regard what it does. :) ok
Quoted 6 lines
Thanks for this submission. ?It's a really big improvement.
regards,
Ben
I use GPL code on my devices... It obvious that my improvements will be shred with community.
thanks again and best regards,
luigi
Signature · 10 lines
Luigi 'Comio' Mantellini R&D - Software Industrie Dial Face S.p.A. Via Canzo, 4 20068 Peschiera Borromeo (MI), Italy Tel.: +39 02 5167 2813 Fax: +39 02 5167 2459 web: www.idf-hit.com mail: luigi.mantellini at idf-hit.com
PATCH v3 1/3 Bit-banged MII driver with multi-bus support.
Hi Luigi,
Quoted 41 lines · Luigi Mantellini
Hi Ben,
thank for your review. Find my inline comments.
Thanks and best regards,
luigi
Quoted 11 lines · Ben Warren
Hi Luigi,
Quoted 4 lines · Luigi 'Comio' Mantellini
From: Luigi 'Comio' Mantellini <[email protected]>
Please add some descriptive information here. This is a big patch and deserves a changelong
Quoted 8 lines
drivers/net/phy/miiphybb.c line 37
Quoted 4 lines
drivers/net/phy/miiphybb.c +2
-0+ +#define BBMII_RELOATE (v,off) (v += (v?off:0))s/RELOATE/RELOCATE/
Please apply globally
Ok.
Quoted 7 lines
Review
Quoted 4 lines
(quoted diff) +2
-0+ +struct bbmiibus bbmiibusses[] = {Elsewhere, you name things '
bb_mii', but here it's 'bbmii'. I personally prefer adding the underscores, but please be consistent.
Quoted 3 lines
What do you mean? change bbmiibus ->
bb_mii_busand bbmiibuses ->bb_mii_buses?
Sure, that would be fine. Consistency is the key.
Quoted 7 lines
Quoted 3 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ { + .name = BB_MII_DEVNAME,
BB_MII_DEVNAMEwill be "bb_mii". is it ok?
Yes.
Quoted 48 lines
Quoted 12 lines
Quoted 10 lines
drivers/net/phy/miiphybb.c +9
-0+ .init = bb_mii_init_wrap, + .mdio_active = bb_mdio_active_wrap, + .mdio_tristate = bb_mdio_tristate_wrap, + .set_mdio = bb_set_mdio_wrap, + .get_mdio = bb_get_mdio_wrap, + .set_mdc = bb_set_mdc_wrap, + .delay = bb_delay_wrap, + } +};Quoted 7 lines
drivers/net/phy/miiphybb.c line 126
Quoted 4 lines
drivers/net/phy/miiphybb.c +2
-0+#if !defined(CONFIG_RELOC_FIXUP_WORKS ) +/* Reloate the hooks pointers*/ s/Reloate/Relocate/
s/hooks/hook/ok
Quoted 8 lines
Quoted 6 lines
*/
(quoted diff) +1
-1-static void miiphy_pre (char read, unsigned char addr, unsigned char reg) +static void miiphy_pre (struct bbmiibus *bus, char read, unsigned charaddr, unsigned char reg)
This line's too long (please keep < 78 characters). Apply globally
ok
Quoted 5 lines
Quoted 5 lines
*/
drivers/net/phy/miiphybb.c +0
-3-MDC (0 ); -MDIO (0 ); -MIIDELAY ;...
Quoted 5 lines
Quoted 5 lines
drivers/net/phy/miiphybb.c +3
-0+ bus->set_mdc (bus,0 ); + bus->set_mdio (bus,0 ); + bus->delay (bus);
Quoted 10 lines
Quoted 5 lines
Please be consistent with whitespace. I prefer no space before the opening
paren, although I think Wolfgang likes that. He's funny that way. Note
that this only relates to function calls. Control logic (if, for, while etc.) should always have a space before the opening paren.I just replaced MD{C,IO} with bus->set_md{c,io}.
Ok.
I assumed that's what happened, but now's a good time to clean it up. Thanks.
Quoted 21 lines
Quoted 8 lines
drivers/net/phy/miiphybb.c int bb_miiphy_read (char *devname, unsigned char addr, · line 252
Quoted 6 lines
drivers/net/phy/miiphybb.c +4
-0+ + bus =bb_miiphy_getbus (devname); +if (bus ==NULL ) { +/* Bus not found! */ Comment's kinda superfluous...
I know that the source code is always sufficiently clear regard what it does. :) ok
Quoted 6 lines
Thanks for this submission. It's a really big improvement.
regards,
Ben
Quoted 8 lines
I use GPL code on my devices... It obvious that my improvements will be shred with community.
thanks again and best regards,
luigi
regards,
Ben