Skip to contentSkip to conversation

pm9g45/pm9253/pm9261: add 1-wire support

PATCH In review Jean-Christophe PLAGNIOL-VILLARD 2 participants 12 messages Oct 29, 2012 – Oct 30, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover pm9g45/pm9253/pm9261: add 1-wire support

Hi,

v2: fixup and add comment

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 v2

The following changes since commit acaa716bce8cd1373cb5dabff54332fb1da7355b:

1-wire: add ds2433 support (2012-10-29 04:46:21 +0800)

are available in the git repository at:

git://git.jcrosoft.org/barebox.git delivery/ronetix_w1

for you to fetch changes up to f64064f91ca518f538c5f9e92d4d4a80c75acdf4:

pm9261: use w1 serial number to generate local mac address (2012-10-29 05:19:04 +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               |   72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 148 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

#1 lore raw

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
index 3533bf9..fa695a6 100644
@@ -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 < 1)
+		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
#2 lore raw

PATCH 2/8 w1: introduce helper to generate mac address from 1-wire id

use the first 3 byte of the id of a 1-wire
or 6 if no OUI provided device to provide an Ethernet address

---
 include/w1_mac_address.h |   72 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 72 insertions(+)
 create mode 100644 include/w1_mac_address.h
include/w1_mac_address.h new file +72 -0
new file mode 100644
index 0000000..78348be
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2012 Jean-Christophe PLAGNIOL-VILLARD <[email protected]>
+ *
+ * Under GPLv2 only
+ */
+
+#ifndef __W1_MAC_ADDRESS_H__
+#define __W1_MAC_ADDRESS_H__
+
+/**
+ * w1_mac_address_register - use the first 3 byte of the id of a 1-wire
+ * or 6 if no OUI provided device to provide an Ethernet address
+ * @ethid: ethernet device id
+ * @local: generate a local Ethernet address
+ * @oui: Ethernet OUI (3 bytes
+ * @w1_dev: 1-wire device name
+ *
+ * Generate a Ethernet address (MAC) that is not multicast using a 1-wire id.
+ */
+static inline int w1_mac_address_register(int ethid, bool local,
+					 char * oui, char *w1_dev)
+{
+	char addr[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 = 3;
+
+		for (i = 0; i < nb_oui; i++)
+			addr[i] = oui[i];
+	}
+
+	tmp = asprintf("%s.id", w1_dev);
+	if (!tmp)
+		return -ENOMEM;
+
+	val = getenv(tmp);
+	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)
+		addr[i] = (id >> shift) & 0xff;
+
+	if (local) {
+		addr[0] &= 0xfe;	/* clear multicast bit */
+		addr[0] |= 0x02;	/* set local assignment bit (IEEE802) */
+	}
+
+	eth_register_ethaddr(ethid, addr);
+
+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
#3 lore raw

Re: [PATCH 2/8] w1: introduce helper to generate mac address from 1-wire id

include/w1_mac_address.h line 21

Quoted 13 lines · Jean-Christophe PLAGNIOL-VILLARD

use the first 3 byte of the id of a 1-wire
or 6 if no OUI provided device to provide an Ethernet address

---
 include/w1_mac_address.h |   72 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 72 insertions(+)
 create mode 100644 include/w1_mac_address.h

+ *
+ * Generate a Ethernet address (MAC) that is not multicast using a 1-wire id.
+ */

include/w1_mac_address.h new file +2 -0
+static inline int w1_mac_address_register(int ethid, bool local,
+					 char * oui, char *w1_dev)

Please drop the local parameter. I believe that it may have a valid use, but really until someone proves he has such a usecase I do not want to have this in the tree. This only increases the risk that some users slip through the review which do not make valid use of this flag.

Quoted 30 lines
include/w1_mac_address.h new file +30 -0
+{
+	char addr[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 = 3;
+
+		for (i = 0; i < nb_oui; i++)
+			addr[i] = oui[i];
+	}
+
+	tmp = asprintf("%s.id", w1_dev);
+	if (!tmp)
+		return -ENOMEM;
+
+	val = getenv(tmp);
+	if (!val) {
+		ret = -EINVAL;
+		goto err;
+	}
+
+	id = simple_strtoull(val, NULL, 16);

include/w1_mac_address.h line 61

Quoted 10 lines
include/w1_mac_address.h new file +10 -0
+	if (!id) {
+		ret = -EINVAL;
+		goto err;
+	}
+
+	for (i = nb_oui, shift = 40; i < 6; i++, shift -= 8)
+		addr[i] = (id >> shift) & 0xff;
+
+	if (local) {
+		addr[0] &= 0xfe;	/* clear multicast bit */

Shouldn't this bit always be cleared?

Sascha

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
#4 lore raw

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
index a12896b..907c6bb 100644
@@ -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
index 958301d..d242bdc 100644
@@ -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
#5 lore raw

PATCH 4/8 pm9g45: use w1 serial number to generate local mac address

In reply to Jean-Christophe PLAGNIOL-VILLARD

The 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
index 907c6bb..f3764bb 100644
@@ -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
#6 lore raw

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
index b17a90a..1d13e03 100644
@@ -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
index 8c92894..e223e77 100644
@@ -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
#7 lore raw

PATCH 6/8 pm9263: use w1 serial number to generate local mac address

In reply to Jean-Christophe PLAGNIOL-VILLARD

The 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
index 1d13e03..7ba804a 100644
@@ -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
#8 lore raw

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
index 5214394..2c3615f 100644
@@ -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
index 1db16d5..0aea2c9 100644
@@ -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
#9 lore raw

PATCH 8/8 pm9261: use w1 serial number to generate local mac address

In reply to Jean-Christophe PLAGNIOL-VILLARD

The 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
index 2c3615f..72fdb0e 100644
@@ -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
#10 lore raw

Re: [PATCH 1/8] arm: at91: add gpio_is_valid support

In reply to Jean-Christophe PLAGNIOL-VILLARD
Quoted 13 lines · Jean-Christophe PLAGNIOL-VILLARD
---
 arch/arm/mach-at91/include/mach/gpio.h |   11 +++++++++++
 1 file changed, 11 insertions(+)
arch/arm/mach-at91/include/mach/gpio.h +0 -0
index 3533bf9..fa695a6 100644
@@ -22,6 +22,17 @@
 
 /* these pin numbers double as IRQ numbers, like AT91xxx_ID_* values */
 

arch/arm/mach-at91/include/mach/gpio.h line 34

Quoted 10 lines
arch/arm/mach-at91/include/mach/gpio.h +10 -0
+#define ARCH_NR_GPIOS 256
+
+static inline int gpio_is_valid(int gpio)
+{
+	if (gpio < 1)
+		return 0;
+	if (gpio < ARCH_NR_GPIOS)
+		return 1;
+	return 0;
+}

Why is this patch in this series? It is unused and wrong. 0 is a valid gpio.

Sascha

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
#11 lore raw

Re: [PATCH 1/8] arm: at91: add gpio_is_valid support

Quoted 14 lines · Sascha Hauer
Quoted 13 lines · Jean-Christophe PLAGNIOL-VILLARD
---
 arch/arm/mach-at91/include/mach/gpio.h |   11 +++++++++++
 1 file changed, 11 insertions(+)
arch/arm/mach-at91/include/mach/gpio.h +0 -0
index 3533bf9..fa695a6 100644
@@ -22,6 +22,17 @@
 
 /* these pin numbers double as IRQ numbers, like AT91xxx_ID_* values */
 
Quoted 13 lines

arch/arm/mach-at91/include/mach/gpio.h line 34

Quoted 10 lines
arch/arm/mach-at91/include/mach/gpio.h +10 -0
+#define ARCH_NR_GPIOS 256
+
+static inline int gpio_is_valid(int gpio)
+{
+	if (gpio < 1)
+		return 0;
+	if (gpio < ARCH_NR_GPIOS)
+		return 1;
+	return 0;
+}

Why is this patch in this series? It is unused and wrong. 0 is a valid gpio.

not on at91

0 means invalid

It ws the case on the kernel too before I wrok on the pinctrl

I'll clenaup it too whe I swtich to gpiolib buta bit later

Best Regards,
J.

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox