* [RFC bluetooth-next 0/2] ieee802154: add usual way to get extended address via device tree
@ 2015-03-08 8:17 Alexander Aring
2015-03-08 8:17 ` [RFC bluetooth-next 1/2] of: net: add support for extended address Alexander Aring
2015-03-08 8:17 ` [RFC bluetooth-next 2/2] at86rf230: add support for dt or pdata extended addr Alexander Aring
0 siblings, 2 replies; 6+ messages in thread
From: Alexander Aring @ 2015-03-08 8:17 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, mkl, Alexander Aring
Hi,
this patch introduce an usual way to getting extended address from device tree.
I added the properties "extended-address" and "local-extended-address". The
ethernet framework has "mac-address", "local-mac-address" and "address", where
"address" is according the comment an obsolete property.
An example how you could add a extended address would be:
&spi1 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&spi1_pins>;
at86rf231@0 {
compatible = "atmel,at86rf231";
spi-max-frequency = <7500000>;
reg = <0>;
interrupts = <19 4>;
interrupt-parent = <&gpio3>;
xtal-trim = /bits/ 8 <0x03>;
extended-address = [ DE AD BE EF CA FE FA CE ];
};
};
This is actually a RFC only. I want to be sure that we can use this naming
convention and I need also add a cc in Patch 1/1 ("of: net: add support for
extended address") to the device tree mailinglist, then wait for an acked-by
and marcel can apply it on bluetooth-next and we have it mainline.
- Alex
Alexander Aring (2):
of: net: add support for extended address
at86rf230: add support for dt or pdata extended addr
drivers/net/ieee802154/at86rf230.c | 15 ++++++++++++---
drivers/of/of_net.c | 34 ++++++++++++++++++++++++++++++++++
include/linux/of_net.h | 6 ++++++
include/linux/spi/at86rf230.h | 1 +
4 files changed, 53 insertions(+), 3 deletions(-)
--
2.3.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [RFC bluetooth-next 1/2] of: net: add support for extended address
2015-03-08 8:17 [RFC bluetooth-next 0/2] ieee802154: add usual way to get extended address via device tree Alexander Aring
@ 2015-03-08 8:17 ` Alexander Aring
2015-03-09 9:33 ` Alexander Aring
2015-03-08 8:17 ` [RFC bluetooth-next 2/2] at86rf230: add support for dt or pdata extended addr Alexander Aring
1 sibling, 1 reply; 6+ messages in thread
From: Alexander Aring @ 2015-03-08 8:17 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, mkl, Alexander Aring
This patch adds a general of_get_extended_address function. The idea is
that 802.15.4 transceivers contains an "extended-address" property like
"mac-address" property. In driver layer each driver can request such address
via calling the of_get_extended_address function and set the
perm_extended_addr attribute of a 802.15.4 phy. This is the default used
extended address of a 802.15.4 interface.
The of_get_extended_address function returns an invalid address on
error. The sense is to validate the extended afterwards by calling
ieee802154_is_valid_extended_addr then the driver can choose an other
source for default extended address like reading firmware or a random
one.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
drivers/of/of_net.c | 34 ++++++++++++++++++++++++++++++++++
include/linux/of_net.h | 6 ++++++
2 files changed, 40 insertions(+)
diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c
index 73e1418..316048e 100644
--- a/drivers/of/of_net.c
+++ b/drivers/of/of_net.c
@@ -6,11 +6,14 @@
* Initially copied out of arch/powerpc/kernel/prom_parse.c
*/
#include <linux/etherdevice.h>
+#include <linux/ieee802154.h>
#include <linux/kernel.h>
#include <linux/of_net.h>
#include <linux/phy.h>
#include <linux/export.h>
+#include <net/mac802154.h>
+
/**
* of_get_phy_mode - Get phy mode for given device_node
* @np: Pointer to the given device_node
@@ -75,3 +78,34 @@ const void *of_get_mac_address(struct device_node *np)
return NULL;
}
EXPORT_SYMBOL(of_get_mac_address);
+
+/**
+ * Search the device tree for the best extended address to use.
+ * 'extended-address' is checked first, because that is supposed to contain
+ * to "most recent" extended address. If that isn't set, then
+ * 'local-extended-address' is checked next, because that is the default
+ * address.
+ *
+ * Returns a valid extended address on success, otherwise an invalid extended
+ * address.
+*/
+__le64 of_get_extended_address(struct device_node *np)
+{
+ struct property *pp;
+ __le64 extended_addr = cpu_to_le64(0x0000000000000000ULL);
+
+ pp = of_find_property(np, "extended-address", NULL);
+ if (pp && (pp->length == IEEE802154_EXTENDED_ADDR_LEN)) {
+ ieee802154_be64_to_le64(&extended_addr, pp->value);
+
+ if (ieee802154_is_valid_extended_addr(extended_addr))
+ return extended_addr;
+ }
+
+ pp = of_find_property(np, "local-extended-address", NULL);
+ if (pp && (pp->length == IEEE802154_EXTENDED_ADDR_LEN))
+ ieee802154_be64_to_le64(&extended_addr, pp->value);
+
+ return extended_addr;
+}
+EXPORT_SYMBOL(of_get_extended_address);
diff --git a/include/linux/of_net.h b/include/linux/of_net.h
index 34597c8..6e677ab 100644
--- a/include/linux/of_net.h
+++ b/include/linux/of_net.h
@@ -11,6 +11,7 @@
#include <linux/of.h>
extern int of_get_phy_mode(struct device_node *np);
extern const void *of_get_mac_address(struct device_node *np);
+extern __le64 of_get_extended_address(struct device_node *np);
#else
static inline int of_get_phy_mode(struct device_node *np)
{
@@ -21,6 +22,11 @@ static inline const void *of_get_mac_address(struct device_node *np)
{
return NULL;
}
+
+static inline __le64 of_get_extended_address(struct device_node *np)
+{
+ return cpu_to_le64(0x0000000000000000ULL);
+}
#endif
#endif /* __LINUX_OF_NET_H */
--
2.3.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [RFC bluetooth-next 2/2] at86rf230: add support for dt or pdata extended addr
2015-03-08 8:17 [RFC bluetooth-next 0/2] ieee802154: add usual way to get extended address via device tree Alexander Aring
2015-03-08 8:17 ` [RFC bluetooth-next 1/2] of: net: add support for extended address Alexander Aring
@ 2015-03-08 8:17 ` Alexander Aring
2015-03-09 9:36 ` Alexander Aring
1 sibling, 1 reply; 6+ messages in thread
From: Alexander Aring @ 2015-03-08 8:17 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, mkl, Alexander Aring
This patch adds support for setting the extended address over devicetree
or platform data.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
drivers/net/ieee802154/at86rf230.c | 15 ++++++++++++---
include/linux/spi/at86rf230.h | 1 +
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c
index edf575c..fc06d83 100644
--- a/drivers/net/ieee802154/at86rf230.c
+++ b/drivers/net/ieee802154/at86rf230.c
@@ -29,6 +29,7 @@
#include <linux/regmap.h>
#include <linux/skbuff.h>
#include <linux/of_gpio.h>
+#include <linux/of_net.h>
#include <linux/ieee802154.h>
#include <net/mac802154.h>
@@ -1434,7 +1435,7 @@ static int at86rf230_hw_init(struct at86rf230_local *lp, u8 xtal_trim)
static int
at86rf230_get_pdata(struct spi_device *spi, int *rstn, int *slp_tr,
- u8 *xtal_trim)
+ u8 *xtal_trim, __le64 *extended_addr)
{
struct at86rf230_platform_data *pdata = spi->dev.platform_data;
int ret;
@@ -1446,6 +1447,7 @@ at86rf230_get_pdata(struct spi_device *spi, int *rstn, int *slp_tr,
*rstn = pdata->rstn;
*slp_tr = pdata->slp_tr;
*xtal_trim = pdata->xtal_trim;
+ *extended_addr = cpu_to_le64(pdata->extended_addr);
return 0;
}
@@ -1455,6 +1457,7 @@ at86rf230_get_pdata(struct spi_device *spi, int *rstn, int *slp_tr,
if (ret < 0 && ret != -EINVAL)
return ret;
+ *extended_addr = of_get_extended_address(spi->dev.of_node);
return 0;
}
@@ -1572,6 +1575,7 @@ static int at86rf230_probe(struct spi_device *spi)
struct at86rf230_local *lp;
unsigned int status;
int rc, irq_type, rstn, slp_tr;
+ __le64 extended_addr;
u8 xtal_trim = 0;
if (!spi->irq) {
@@ -1579,7 +1583,8 @@ static int at86rf230_probe(struct spi_device *spi)
return -EINVAL;
}
- rc = at86rf230_get_pdata(spi, &rstn, &slp_tr, &xtal_trim);
+ rc = at86rf230_get_pdata(spi, &rstn, &slp_tr, &xtal_trim,
+ &extended_addr);
if (rc < 0) {
dev_err(&spi->dev, "failed to parse platform_data: %d\n", rc);
return rc;
@@ -1617,7 +1622,11 @@ static int at86rf230_probe(struct spi_device *spi)
lp->spi = spi;
hw->parent = &spi->dev;
hw->vif_data_size = sizeof(*lp);
- ieee802154_random_extended_addr(&hw->phy->perm_extended_addr);
+
+ if (ieee802154_is_valid_extended_addr(extended_addr))
+ hw->phy->perm_extended_addr = extended_addr;
+ else
+ ieee802154_random_extended_addr(&hw->phy->perm_extended_addr);
lp->regmap = devm_regmap_init_spi(spi, &at86rf230_regmap_spi_config);
if (IS_ERR(lp->regmap)) {
diff --git a/include/linux/spi/at86rf230.h b/include/linux/spi/at86rf230.h
index b63fe6f..094b8b2 100644
--- a/include/linux/spi/at86rf230.h
+++ b/include/linux/spi/at86rf230.h
@@ -23,6 +23,7 @@ struct at86rf230_platform_data {
int slp_tr;
int dig2;
u8 xtal_trim;
+ u64 extended_addr;
};
#endif
--
2.3.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [RFC bluetooth-next 1/2] of: net: add support for extended address
2015-03-08 8:17 ` [RFC bluetooth-next 1/2] of: net: add support for extended address Alexander Aring
@ 2015-03-09 9:33 ` Alexander Aring
0 siblings, 0 replies; 6+ messages in thread
From: Alexander Aring @ 2015-03-09 9:33 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, mkl
Hi,
some notes from me which I figured out for reviewing right now.
On Sun, Mar 08, 2015 at 09:17:22AM +0100, Alexander Aring wrote:
...
> +}
> +EXPORT_SYMBOL(of_get_extended_address);
> diff --git a/include/linux/of_net.h b/include/linux/of_net.h
> index 34597c8..6e677ab 100644
> --- a/include/linux/of_net.h
> +++ b/include/linux/of_net.h
> @@ -11,6 +11,7 @@
> #include <linux/of.h>
> extern int of_get_phy_mode(struct device_node *np);
> extern const void *of_get_mac_address(struct device_node *np);
> +extern __le64 of_get_extended_address(struct device_node *np);
> #else
> static inline int of_get_phy_mode(struct device_node *np)
> {
> @@ -21,6 +22,11 @@ static inline const void *of_get_mac_address(struct device_node *np)
> {
> return NULL;
> }
> +
> +static inline __le64 of_get_extended_address(struct device_node *np)
> +{
> + return cpu_to_le64(0x0000000000000000ULL);
> +}
> #endif
>
I need to be sure that __le64 is definied here from include of
<linux/of.h>. I didn't check that right now.
- Alex
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC bluetooth-next 2/2] at86rf230: add support for dt or pdata extended addr
2015-03-08 8:17 ` [RFC bluetooth-next 2/2] at86rf230: add support for dt or pdata extended addr Alexander Aring
@ 2015-03-09 9:36 ` Alexander Aring
2015-03-09 9:39 ` Alexander Aring
0 siblings, 1 reply; 6+ messages in thread
From: Alexander Aring @ 2015-03-09 9:36 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, mkl
Hi,
On Sun, Mar 08, 2015 at 09:17:23AM +0100, Alexander Aring wrote:
> This patch adds support for setting the extended address over devicetree
> or platform data.
I should also add some notes in:
Documentation/devicetree/bindings/net/ieee802154/at86rf230.txt
about the extended-addr definition or should I add some generic 802.15.4
specific file where I describe the common way to add an extended.
If yes where should it be placed. Something like:
Documentation/devicetree/bindings/net/ieee802154/general.txt
Or should I define it driver specific. When setting "extended-addr" via
the dt property "extended-addr" then because the driver doesn't support
the handling.
- Alex
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC bluetooth-next 2/2] at86rf230: add support for dt or pdata extended addr
2015-03-09 9:36 ` Alexander Aring
@ 2015-03-09 9:39 ` Alexander Aring
0 siblings, 0 replies; 6+ messages in thread
From: Alexander Aring @ 2015-03-09 9:39 UTC (permalink / raw)
To: linux-wpan; +Cc: kernel, mkl
> Or should I define it driver specific. When setting "extended-addr" via
> the dt property "extended-addr" then because the driver doesn't support
> the handling.
s/dt property "extended-addr"/dt property "extended-addr" doesn't work/
sorry, I hope now it's clear what I meant here.
- Alex
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-03-09 9:39 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-08 8:17 [RFC bluetooth-next 0/2] ieee802154: add usual way to get extended address via device tree Alexander Aring
2015-03-08 8:17 ` [RFC bluetooth-next 1/2] of: net: add support for extended address Alexander Aring
2015-03-09 9:33 ` Alexander Aring
2015-03-08 8:17 ` [RFC bluetooth-next 2/2] at86rf230: add support for dt or pdata extended addr Alexander Aring
2015-03-09 9:36 ` Alexander Aring
2015-03-09 9:39 ` Alexander Aring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox