pm9g45/pm9253/pm9261: add 1-wire support
cover pm9g45/pm9253/pm9261: add 1-wire support
Hi,
add 1-wire support for:
- pm9g45
- pm9263
- pm9261
use the 1-wire uniq id to generate a local mac address The OUI will be 'ron' => 72:6F:6E
The patch series go on the top of the 1-wire support
The following changes since commit 91413767b35d5f9f66d14376c925386a42d1db0e:
1-wire: add ds2433 support (2012-10-27 12:47:20 +0800)
are available in the git repository at:
git://git.jcrosoft.org/barebox.git delivery/ronetix_w1
for you to fetch changes up to 32c1cc8c210614799454e63cd2728470ab8732b5:
pm9261: use w1 serial number to generate local mac address (2012-10-27 17:08:03 +0800)
----------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARD (8):
arm: at91: add gpio_is_valid support
w1: introduce helper to generate mac address from 1-wire id
pm9g45: add 1-wire support
pm9g45: use w1 serial number to generate local mac address
pm9263: add 1-wire support
pm9263: use w1 serial number to generate local mac address
pm9261: add 1-wire support
pm9261: use w1 serial number to generate local mac address
arch/arm/boards/pm9261/init.c | 10 ++++++++++ arch/arm/boards/pm9263/init.c | 38 ++++++++++++++++++++++++++++++-------- arch/arm/boards/pm9g45/init.c | 22 +++++++++++++++++++--- arch/arm/configs/pm9261_defconfig | 2 ++ arch/arm/configs/pm9263_defconfig | 2 ++ arch/arm/configs/pm9g45_defconfig | 2 ++ arch/arm/mach-at91/include/mach/gpio.h | 11 +++++++++++ include/w1_mac_address.h | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 140 insertions(+), 11 deletions(-) create mode 100644 include/w1_mac_address.h
Best Regards,
J.
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
PATCH 1/8 arm: at91: add gpio_is_valid support
--- arch/arm/mach-at91/include/mach/gpio.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
arch/arm/mach-at91/include/mach/gpio.h +11 -0
@@ -22,6 +22,17 @@/* these pin numbers double as IRQ numbers, like AT91xxx_ID_* values */ +#define ARCH_NR_GPIOS 256 + +static inline int gpio_is_valid (int gpio) +{ +if (gpio <0 ) +return 0 ; +if (gpio <ARCH_NR_GPIOS ) +return 1 ; +return 0 ; +} +#define AT91_PIN_PA0 (PIN_BASE + 0x00 + 0)#define AT91_PIN_PA1 (PIN_BASE + 0x00 + 1)#define AT91_PIN_PA2 (PIN_BASE + 0x00 + 2)
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 2/8 w1: introduce helper to generate mac address from 1-wire id
--- include/w1_mac_address.h | 64 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 include/w1_mac_address.h
include/w1_mac_address.h new file +64 -0
@@ -0,0 +1,64 @@ +/* +* Copyright (C) 2012 Jean-Christophe PLAGNIOL-VILLARD <[email protected]> +* +* Under GPLv2 only +*/ + +#ifndef __W1_MAC_ADDRESS_H__ +#define __W1_MAC_ADDRESS_H__ + +static inline int w1_mac_address_register (int eth_num,bool local, +char * oui,char *w1_dev) +{ +char buf[6 ]; +const char *val; +u64 id; +int nb_oui =0 ; +int i, shift; +char *tmp =NULL ; +int ret =0 ; + +if (!local && !oui) +return -EINVAL ; + +if (oui) { + nb_oui =strlen (oui); +if (!local && nb_oui !=3 ) +return -EINVAL ; + + nb_oui =min (nb_oui,3 ); + +for (i =0 ; i < nb_oui; i++) + buf[i] = oui[i]; + } + + tmp =asprintf ("%s.id" , w1_dev); +if (!tmp) +return -ENOMEM ; + + val =getenv ("w1-1-0.id" ); +if (!val) { + ret = -EINVAL ; + goto err; + } + + id =simple_strtoull (val,NULL ,16 ); +if (!id) { + ret = -EINVAL ; + goto err; + } + +for (i = nb_oui, shift =40 ; i <6 ; i++, shift -=8 ) + buf[i] = (id >> shift) &0xff ; + +if (local) + buf[0 ] |=0x2 ; + +eth_register_ethaddr (eth_num, buf); + +err: +free (tmp); +return ret; +} + +#endif /* __W1_MAC_ADDRESS_H__ */
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 2/8] w1: introduce helper to generate mac address from 1-wire id
Quoted 13 lines · Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>--- include/w1_mac_address.h | 64 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 include/w1_mac_address.hinclude/w1_mac_address.h new file +1
-0@@ -0,0 +1,64 @@ +/*
include/w1_mac_address.h line 11
Quoted 10 lines
include/w1_mac_address.h new file +10
-0+* Copyright (C) 2012 Jean-Christophe PLAGNIOL-VILLARD <[email protected]> +* +* Under GPLv2 only +*/ + +#ifndef __W1_MAC_ADDRESS_H__ +#define __W1_MAC_ADDRESS_H__ + +static inline int w1_mac_address_register (int eth_num,bool local, +char * oui,char *w1_dev)
This function really deserves a comment what it does. From the name I assume that it turns something w1 related into a MAC address, but I have no clue what.
Also I think the 'local' parameter should not exist and be unconditional true. I don't think any vendor with a real ieee registered oui will match their mac addresses with ids from a w1 eeprom.
Quoted 4 lines
include/w1_mac_address.h new file +4
-0+{ +char buf[6 ]; +const char *val; +u64 id;
include/w1_mac_address.h line 25
Quoted 10 lines
include/w1_mac_address.h new file +10
-0+int nb_oui =0 ; +int i, shift; +char *tmp =NULL ; +int ret =0 ; + +if (!local && !oui) +return -EINVAL ; + +if (oui) { + nb_oui =strlen (oui);
A oui always has three bytes. You can't use strlen here as for example Freescale has the oui 00-04-9f
Quoted 4 lines
include/w1_mac_address.h new file +4
-0+if (!local && nb_oui !=3 ) +return -EINVAL ; + + nb_oui =min (nb_oui,3 );
include/w1_mac_address.h line 39
Quoted 10 lines
include/w1_mac_address.h new file +10
-0+ +for (i =0 ; i < nb_oui; i++) + buf[i] = oui[i]; + } + + tmp =asprintf ("%s.id" , w1_dev); +if (!tmp) +return -ENOMEM ; + + val =getenv ("w1-1-0.id" );
tmp is never used. I assume it should be used here, right?
Quoted 34 lines
include/w1_mac_address.h new file +25
-0+if (!val) { + ret = -EINVAL ; + goto err; + } + + id =simple_strtoull (val,NULL ,16 ); +if (!id) { + ret = -EINVAL ; + goto err; + } + +for (i = nb_oui, shift =40 ; i <6 ; i++, shift -=8 ) + buf[i] = (id >> shift) &0xff ; + +if (local) + buf[0 ] |=0x2 ; + +eth_register_ethaddr (eth_num, buf); + +err: +free (tmp); + return ret; +} + +#endif /* __W1_MAC_ADDRESS_H__ */ Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 2/8] w1: introduce helper to generate mac address from 1-wire id
Quoted 29 lines · Sascha Hauer
Quoted 13 lines · Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>--- include/w1_mac_address.h | 64 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 include/w1_mac_address.hinclude/w1_mac_address.h new file +1
-0@@ -0,0 +1,64 @@ +/* include/w1_mac_address.h line 11
Quoted 10 lines
include/w1_mac_address.h new file +10
-0+* Copyright (C) 2012 Jean-Christophe PLAGNIOL-VILLARD <[email protected]> +* +* Under GPLv2 only +*/ + +#ifndef __W1_MAC_ADDRESS_H__ +#define __W1_MAC_ADDRESS_H__ + +static inline int w1_mac_address_register (int eth_num,bool local, +char * oui,char *w1_dev)This function really deserves a comment what it does. From the name I assume that it turns something w1 related into a MAC address, but I have no clue what.
Quoted 3 lines
Also I think the 'local' parameter should not exist and be unconditional true. I don't think any vendor with a real ieee registered oui will match their mac addresses with ids from a w1 eeprom.
as you can request specific id format for the serial number 1-wire (smem)
you can use it for real OUI
with this way you can prouve than you manage your OUI correctly if you need to request an other one
Best Regards,
J.
Quoted 65 lines
Quoted 5 lines
include/w1_mac_address.h new file +4
-0+{ +char buf[6 ]; +const char *val; +u64 id;include/w1_mac_address.h line 25
Quoted 10 lines
include/w1_mac_address.h new file +10
-0+int nb_oui =0 ; +int i, shift; +char *tmp =NULL ; +int ret =0 ; + +if (!local && !oui) +return -EINVAL ; + +if (oui) { + nb_oui =strlen (oui);A oui always has three bytes. You can't use strlen here as for example Freescale has the oui 00-04-9f
Quoted 4 lines
include/w1_mac_address.h new file +4
-0+if (!local && nb_oui !=3 ) +return -EINVAL ; + + nb_oui =min (nb_oui,3 );include/w1_mac_address.h line 39
Quoted 10 lines
include/w1_mac_address.h new file +10
-0+ +for (i =0 ; i < nb_oui; i++) + buf[i] = oui[i]; + } + + tmp =asprintf ("%s.id" , w1_dev); +if (!tmp) +return -ENOMEM ; + + val =getenv ("w1-1-0.id" );tmp is never used. I assume it should be used here, right?
Quoted 29 lines
include/w1_mac_address.h new file +25
-0+if (!val) { + ret = -EINVAL ; + goto err; + } + + id =simple_strtoull (val,NULL ,16 ); +if (!id) { + ret = -EINVAL ; + goto err; + } + +for (i = nb_oui, shift =40 ; i <6 ; i++, shift -=8 ) + buf[i] = (id >> shift) &0xff ; + +if (local) + buf[0 ] |=0x2 ; + +eth_register_ethaddr (eth_num, buf); + +err: +free (tmp); + return ret; +} + +#endif /* __W1_MAC_ADDRESS_H__ */ Signature · 1 line
1.7.10.4
Quoted 11 lines
Quoted 5 lines
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/bareboxSignature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
PATCH 3/8 pm9g45: add 1-wire support
In reply to Jean-Christophe PLAGNIOL-VILLARD--- arch/arm/boards/pm9g45/init.c | 11 ++++++++++- arch/arm/configs/pm9g45_defconfig | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-)
arch/arm/boards/pm9g45/init.c +10 -1
@@ -1,5 +1,5 @@/* -* Copyright (C) 2009 Jean-Christophe PLAGNIOL-VILLARD <[email protected]> +* Copyright (C) 2009-2012 Jean-Christophe PLAGNIOL-VILLARD <[email protected]> * * Copyright (C) 2007 Sascha Hauer, Pengutronix *
@@ -35,6 +35,12 @@#include <mach/io.h> #include <mach/at91sam9_smc.h> #include <mach/sam9_smc.h> +#include <linux/w1-gpio.h> + +struct w1_gpio_platform_data w1_pdata = { + .pin =AT91_PIN_PA31 , + .is_open_drain =0 , +};static struct atmel_nand_data nand_pdata = { .ale =21 ,
@@ -132,6 +138,9 @@ mem_initcall(pm9g45_mem_init);static int pm9g45_devices_init (void ) { +at91_set_gpio_input (w1_pdata.pin,0 ); +add_generic_device_res ("w1-gpio" ,DEVICE_ID_SINGLE ,NULL ,0 , &w1_pdata); +pm_add_device_nand ();pm9g45_add_device_mci ();pm9g45_phy_init ();
arch/arm/configs/pm9g45_defconfig +2 -0
@@ -56,6 +56,8 @@ CONFIG_USB_OHCI_AT91=y CONFIG_USB_STORAGE=y CONFIG_MCI=y CONFIG_MCI_ATMEL=y +CONFIG_W1=y +CONFIG_W1_MASTER_GPIO=y CONFIG_FS_TFTP=y CONFIG_FS_FAT=y CONFIG_FS_FAT_WRITE=y
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 4/8 pm9g45: use w1 serial number to generate local mac address
In reply to Jean-Christophe PLAGNIOL-VILLARDThe OUI will be 'ron' => 72:6F:6E
--- arch/arm/boards/pm9g45/init.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
arch/arm/boards/pm9g45/init.c +9 -2
@@ -36,6 +36,7 @@#include <mach/at91sam9_smc.h> #include <mach/sam9_smc.h> #include <linux/w1-gpio.h> +#include <w1_mac_address.h> struct w1_gpio_platform_data w1_pdata = { .pin =AT91_PIN_PA31 ,
@@ -128,6 +129,13 @@ static void pm9g45_phy_init(void)at91_set_gpio_value (AT91_PIN_PD2 ,1 ); } +static void pm9g45_add_device_eth (void ) +{ +w1_mac_address_register (0 , true,"ron" ,"w1-1-0" ); +pm9g45_phy_init (); +at91_add_device_eth (0 , &macb_pdata); +} +static int pm9g45_mem_init (void ) {at91_add_device_sdram (128 *1024 *1024 );
@@ -143,8 +151,7 @@ static int pm9g45_devices_init(void)pm_add_device_nand ();pm9g45_add_device_mci (); -pm9g45_phy_init (); -at91_add_device_eth (0 , &macb_pdata); +pm9g45_add_device_eth ();pm9g45_add_device_usbh ();devfs_add_partition ("nand0" ,0x00000 ,SZ_128K ,DEVFS_PARTITION_FIXED ,"at91bootstrap_raw" );
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 5/8 pm9263: add 1-wire support
In reply to Jean-Christophe PLAGNIOL-VILLARD--- arch/arm/boards/pm9263/init.c | 11 +++++++++++ arch/arm/configs/pm9263_defconfig | 2 ++ 2 files changed, 13 insertions(+)
arch/arm/boards/pm9263/init.c +11 -0
@@ -1,4 +1,6 @@/* +* Copyright (C) 2009-2012 Jean-Christophe PLAGNIOL-VILLARD <[email protected]> +* * Copyright (C) 2007 Sascha Hauer, Pengutronix * * This program is free software; you can redistribute it and/or
@@ -34,6 +36,12 @@#include <mach/io.h> #include <mach/at91sam9_smc.h> #include <mach/sam9_smc.h> +#include <linux/w1-gpio.h> + +struct w1_gpio_platform_data w1_pdata = { + .pin =AT91_PIN_PB31 , + .is_open_drain =0 , +};static struct atmel_nand_data nand_pdata = { .ale =21 ,
@@ -95,6 +103,9 @@ mem_initcall(pm9263_mem_init);static int pm9263_devices_init (void ) { +at91_set_gpio_input (w1_pdata.pin,0 ); +add_generic_device_res ("w1-gpio" ,DEVICE_ID_SINGLE ,NULL ,0 , &w1_pdata); +/* * PB27 enables the 50MHz oscillator for Ethernet PHY * 1 - enable
arch/arm/configs/pm9263_defconfig +2 -0
@@ -35,3 +35,5 @@ CONFIG_DRIVER_NET_MACB=y # CONFIG_SPI is not set CONFIG_DRIVER_CFI=y CONFIG_CFI_BUFFER_WRITE=y +CONFIG_W1=y +CONFIG_W1_MASTER_GPIO=y
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 6/8 pm9263: use w1 serial number to generate local mac address
In reply to Jean-Christophe PLAGNIOL-VILLARDThe OUI will be 'ron' => 72:6F:6E
--- arch/arm/boards/pm9263/init.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-)
arch/arm/boards/pm9263/init.c +20 -9
@@ -37,6 +37,7 @@#include <mach/at91sam9_smc.h> #include <mach/sam9_smc.h> #include <linux/w1-gpio.h> +#include <w1_mac_address.h> struct w1_gpio_platform_data w1_pdata = { .pin =AT91_PIN_PB31 ,
@@ -93,6 +94,24 @@ static struct at91_ether_platform_data macb_pdata = { .phy_addr = 0, }; +static void pm9263_phy_init (void ) +{ +/* +* PB27 enables the 50MHz oscillator for Ethernet PHY +* 1 - enable +* 0 - disable +*/ +at91_set_gpio_output (AT91_PIN_PB27 ,1 ); +at91_set_gpio_value (AT91_PIN_PB27 ,1 );/* 1- enable, 0 - disable */ +} + +static void pm9263_add_device_eth (void ) +{ +w1_mac_address_register (0 , true,"ron" ,"w1-1-0" ); +pm9263_phy_init (); +at91_add_device_eth (0 , &macb_pdata); +} +static int pm9263_mem_init (void ) {at91_add_device_sdram (64 *1024 *1024 );
@@ -106,16 +125,8 @@ static int pm9263_devices_init(void)at91_set_gpio_input (w1_pdata.pin,0 );add_generic_device_res ("w1-gpio" ,DEVICE_ID_SINGLE ,NULL ,0 , &w1_pdata); -/* -* PB27 enables the 50MHz oscillator for Ethernet PHY -* 1 - enable -* 0 - disable -*/ -at91_set_gpio_output (AT91_PIN_PB27 ,1 ); -at91_set_gpio_value (AT91_PIN_PB27 ,1 );/* 1- enable, 0 - disable */ -pm_add_device_nand (); -at91_add_device_eth (0 , &macb_pdata); +pm9263_add_device_eth ();add_cfi_flash_device (0 ,AT91_CHIPSELECT_0 ,4 *1024 *1024 ,0 );devfs_add_partition ("nor0" ,0x00000 ,0x40000 ,DEVFS_PARTITION_FIXED ,"self0" );
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 7/8 pm9261: add 1-wire support
In reply to Jean-Christophe PLAGNIOL-VILLARD--- arch/arm/boards/pm9261/init.c | 8 ++++++++ arch/arm/configs/pm9261_defconfig | 2 ++ 2 files changed, 10 insertions(+)
arch/arm/boards/pm9261/init.c +8 -0
@@ -1,4 +1,6 @@/* +* Copyright (C) 2009-2012 Jean-Christophe PLAGNIOL-VILLARD <[email protected]> +* * Copyright (C) 2007 Sascha Hauer, Pengutronix * * This program is free software; you can redistribute it and/or
@@ -34,6 +36,12 @@#include <mach/at91sam9_smc.h> #include <mach/sam9_smc.h> #include <dm9000.h> +#include <linux/w1-gpio.h> + +struct w1_gpio_platform_data w1_pdata = { + .pin =AT91_PIN_PA7 , + .is_open_drain =0 , +};static struct atmel_nand_data nand_pdata = { .ale =22 ,
arch/arm/configs/pm9261_defconfig +2 -0
@@ -50,3 +50,5 @@ CONFIG_MTD=y CONFIG_NAND=y CONFIG_NAND_ATMEL=y CONFIG_UBI=y +CONFIG_W1=y +CONFIG_W1_MASTER_GPIO=y
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 8/8 pm9261: use w1 serial number to generate local mac address
In reply to Jean-Christophe PLAGNIOL-VILLARDThe OUI will be 'ron' => 72:6F:6E
--- arch/arm/boards/pm9261/init.c | 2 ++ 1 file changed, 2 insertions(+)
arch/arm/boards/pm9261/init.c +2 -0
@@ -37,6 +37,7 @@#include <mach/sam9_smc.h> #include <dm9000.h> #include <linux/w1-gpio.h> +#include <w1_mac_address.h> struct w1_gpio_platform_data w1_pdata = { .pin =AT91_PIN_PA7 ,
@@ -120,6 +121,7 @@ static struct sam9_smc_config __initdata dm9000_smc_config = {static void __init pm_add_device_dm9000 (void ) { +w1_mac_address_register (0 , true,"ron" ,"w1-1-0" );/* Configure chip-select 2 (DM9000) */ sam9_smc_configure (2 , &dm9000_smc_config);
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox