at86rf230: various fixes and devicetree support
Subsystems (3)
cover at86rf230: various fixes and devicetree support
Hi,
this patch series fix some bugs with the at86rf231 chip and cleaup some code. Also add devicetree support for the at86rf230 driver.
Regards
Alex
Alexander Aring (5):
at86rf230: fix unexpected state change
at86rf230: move locking state in xmit
at86rf230: change reset timings
at86rf230: make reset pin optionally
at86rf230: add support for devicetree
drivers/net/ieee802154/at86rf230.c | 86 +++++++++++++++++++++++++++++++------- 1 file changed, 70 insertions(+), 16 deletions(-)
Signature · 9 lines
1.9.0 ------------------------------------------------------------------------------ Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. Written by three acclaimed leaders in the field, this first edition is now available. Download your free book today! http://p.sf.net/sfu/13534_NeoTech
A message that is not in the archive (sent off-list or not yet received): 1394872147-3021-1-git-send-email-alex.aring-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
PATCH 1/5 at86rf230: fix unexpected state change
This patch fix a unexpected state change for the at86rf231 chip. We can't change into STATE_FORCE_TX_ON while the chip is in one of SLEEP, P_ON, RESET, TRX_OFF, and all *_NOCLK states.
In this case we are in the TRX_OFF state. See datasheet [1] page 71 for more information.
Without this patch you will get the following message on a at86rf231 device:
[ 20.065218] unexpected state change: 8, asked for 4 [ 20.070527] ------------[ cut here ]------------ [ 20.075414] WARNING: CPU: 0 PID: 160 at net/mac802154/ieee802154_dev.c:43 mac802154_slave_open+0x70/0xb8() [ 20.085594] Modules linked in: autofs4 [ 20.089667] CPU: 0 PID: 160 Comm: ifconfig Not tainted 3.14.0-20140108-1-00993-g905c192 #162 [ 20.098612] [<c00127b8>] (unwind_backtrace) from [<c0010b1c>] (show_stack+0x10/0x14) [ 20.106819] [<c0010b1c>] (show_stack) from [<c0033838>] (warn_slowpath_common+0x60/0x80) [ 20.115311] [<c0033838>] (warn_slowpath_common) from [<c00338e8>] (warn_slowpath_null+0x18/0x20) [ 20.124590] [<c00338e8>] (warn_slowpath_null) from [<c057b7e8>] (mac802154_slave_open+0x70/0xb8) [ 20.133880] [<c057b7e8>] (mac802154_slave_open) from [<c0488a58>] (__dev_open+0xa8/0x108) [ 20.142553] [<c0488a58>] (__dev_open) from [<c0488cb0>] (__dev_change_flags+0x8c/0x148) [ 20.151051] [<c0488cb0>] (__dev_change_flags) from [<c0488d84>] (dev_change_flags+0x18/0x48) [ 20.159968] [<c0488d84>] (dev_change_flags) from [<c04e2e9c>] (devinet_ioctl+0x2b0/0x63c) [ 20.168623] [<c04e2e9c>] (devinet_ioctl) from [<c04712e4>] (sock_ioctl+0x23c/0x29c) [ 20.176727] [<c04712e4>] (sock_ioctl) from [<c00e3cb8>] (do_vfs_ioctl+0x4a8/0x578) [ 20.184671] [<c00e3cb8>] (do_vfs_ioctl) from [<c00e3dd4>] (SyS_ioctl+0x4c/0x78) [ 20.192402] [<c00e3dd4>] (SyS_ioctl) from [<c000da00>] (ret_fast_syscall+0x0/0x48) [ 20.200392] ---[ end trace 9a34542f4ea08e47 ]---
This patch was tested on at86rf231 and at86rf212.
[1] http://www.atmel.com/images/doc8111.pdf
--- drivers/net/ieee802154/at86rf230.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ieee802154/at86rf230.c +1 -1
@@ -574,7 +574,7 @@ at86rf230_start(struct ieee802154_dev *dev)if (rc)return rc; - rc =at86rf230_state (dev,STATE_FORCE_TX_ON ); + rc =at86rf230_state (dev,STATE_TX_ON );if (rc)return rc;
Signature · 9 lines
1.9.0 ------------------------------------------------------------------------------ Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. Written by three acclaimed leaders in the field, this first edition is now available. Download your free book today! http://p.sf.net/sfu/13534_NeoTech
PATCH 2/5 at86rf230: move locking state in xmit
In reply to a message not in the archiveThere is no need to lock the clearing of IRQ_TRX_END in status.
--- drivers/net/ieee802154/at86rf230.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ieee802154/at86rf230.c +1 -1
@@ -914,8 +914,8 @@ static void at86rf230_irqwork(struct work_struct *work) status &= ~IRQ_TRX_UR ;/* FIXME: possibly handle ???*/ if (status &IRQ_TRX_END ) { -spin_lock_irqsave (&lp->lock, flags); status &= ~IRQ_TRX_END ; +spin_lock_irqsave (&lp->lock, flags);if (lp->is_tx) { lp->is_tx =0 ;spin_unlock_irqrestore (&lp->lock, flags);
Signature · 9 lines
1.9.0 ------------------------------------------------------------------------------ Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. Written by three acclaimed leaders in the field, this first edition is now available. Download your free book today! http://p.sf.net/sfu/13534_NeoTech
PATCH 3/5 at86rf230: change reset timings
In reply to a message not in the archiveWhile checkpatch another patch I got a:
"WARNING: msleep < 20ms can sleep for up to 20ms"
The datasheet of at86rf231 and at86rf212 says a minimum delay for reset pulse width and spi access latency after reset is 625 nanoseconds.
This patch removes the 1 milliseconds sleep and replace it with a 1 microseconds udelay which should be also okay for the reset pulse width.
To change the state from RESET -> TRX_OFF the at86rf230 device needs 120 microseconds, this is a worst case of all at86rf* chips.
--- drivers/net/ieee802154/at86rf230.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ieee802154/at86rf230.c +3 -3
@@ -1080,11 +1080,11 @@ static int at86rf230_probe(struct spi_device *spi) }/* Reset */ -msleep (1 ); +udelay (1 );gpio_set_value (pdata->rstn,0 ); -msleep (1 ); +udelay (1 );gpio_set_value (pdata->rstn,1 ); -msleep (1 ); +usleep_range (120 ,240 ); rc =__at86rf230_detect_device (spi, &man_id, &part, &version);if (rc <0 )
Signature · 9 lines
1.9.0 ------------------------------------------------------------------------------ Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. Written by three acclaimed leaders in the field, this first edition is now available. Download your free book today! http://p.sf.net/sfu/13534_NeoTech
PATCH 4/5 at86rf230: make reset pin optionally
In reply to a message not in the archiveThis patch make the reset pin optionally. Some devices like the atben from qi-hardware don't have a reset pin externally. The usually way is to turn power off/on for the atben device to initiate a device reset.
--- drivers/net/ieee802154/at86rf230.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-)
drivers/net/ieee802154/at86rf230.c +21 -13
@@ -1059,9 +1059,11 @@ static int at86rf230_probe(struct spi_device *spi)return -EINVAL ; } - rc =gpio_request (pdata->rstn,"rstn" ); -if (rc) -return rc; +if (gpio_is_valid (pdata->rstn)) { + rc =gpio_request (pdata->rstn,"rstn" ); +if (rc) +return rc; + }if (gpio_is_valid (pdata->slp_tr)) { rc =gpio_request (pdata->slp_tr,"slp_tr" );
@@ -1069,9 +1071,11 @@ static int at86rf230_probe(struct spi_device *spi) goto err_slp_tr; } - rc =gpio_direction_output (pdata->rstn,1 ); -if (rc) - goto err_gpio_dir; +if (gpio_is_valid (pdata->rstn)) { + rc =gpio_direction_output (pdata->rstn,1 ); +if (rc) + goto err_gpio_dir; + }if (gpio_is_valid (pdata->slp_tr)) { rc =gpio_direction_output (pdata->slp_tr,0 );
@@ -1080,11 +1084,13 @@ static int at86rf230_probe(struct spi_device *spi) }/* Reset */ -udelay (1 ); -gpio_set_value (pdata->rstn,0 ); -udelay (1 ); -gpio_set_value (pdata->rstn,1 ); -usleep_range (120 ,240 ); +if (gpio_is_valid (pdata->rstn)) { +udelay (1 ); +gpio_set_value (pdata->rstn,0 ); +udelay (1 ); +gpio_set_value (pdata->rstn,1 ); +usleep_range (120 ,240 ); + } rc =__at86rf230_detect_device (spi, &man_id, &part, &version);if (rc <0 )
@@ -1198,7 +1204,8 @@ err_gpio_dir:if (gpio_is_valid (pdata->slp_tr))gpio_free (pdata->slp_tr); err_slp_tr: -gpio_free (pdata->rstn); +if (gpio_is_valid (pdata->rstn)) +gpio_free (pdata->rstn);return rc; }
@@ -1214,7 +1221,8 @@ static int at86rf230_remove(struct spi_device *spi)if (gpio_is_valid (pdata->slp_tr))gpio_free (pdata->slp_tr); -gpio_free (pdata->rstn); +if (gpio_is_valid (pdata->rstn)) +gpio_free (pdata->rstn);mutex_destroy (&lp->bmux);ieee802154_free_device (lp->dev);
Signature · 9 lines
1.9.0 ------------------------------------------------------------------------------ Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. Written by three acclaimed leaders in the field, this first edition is now available. Download your free book today! http://p.sf.net/sfu/13534_NeoTech
PATCH 5/5 at86rf230: add support for devicetree
In reply to a message not in the archiveThis patch adds devicetree support for the at86rf230 driver.
Possible gpios to configure are "reset-gpio" and "sleep-gpio". Also add support to configure the "irq-type" for the irq polarity register.
--- drivers/net/ieee802154/at86rf230.c | 48 +++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-)
drivers/net/ieee802154/at86rf230.c +47 -1
@@ -31,6 +31,7 @@#include <linux/spi/spi.h> #include <linux/spi/at86rf230.h> #include <linux/skbuff.h> +#include <linux/of_gpio.h> #include <net/mac802154.h> #include <net/wpan-phy.h>
@@ -1035,6 +1036,40 @@ static int at86rf230_hw_init(struct at86rf230_local *lp)return 0 ; } +static struct at86rf230_platform_data * +at86rf230_get_pdata (struct spi_device *spi) +{ +struct at86rf230_platform_data *pdata; +const char *irq_type; + +if (!IS_ENABLED (CONFIG_OF ) || !spi->dev.of_node) +return spi->dev.platform_data; + + pdata =devm_kzalloc (&spi->dev,sizeof (*pdata),GFP_KERNEL ); +if (!pdata) + goto done; + + pdata->rstn =of_get_named_gpio (spi->dev.of_node,"reset-gpio" ,0 ); + pdata->slp_tr =of_get_named_gpio (spi->dev.of_node,"sleep-gpio" ,0 ); + + pdata->irq_type =IRQF_TRIGGER_RISING ; +of_property_read_string (spi->dev.of_node,"irq-type" , &irq_type); +if (!strcmp (irq_type,"level-high" )) + pdata->irq_type =IRQF_TRIGGER_HIGH ; +else if (!strcmp (irq_type,"level-low" )) + pdata->irq_type =IRQF_TRIGGER_LOW ; +else if (!strcmp (irq_type,"edge-rising" )) + pdata->irq_type =IRQF_TRIGGER_RISING ; +else if (!strcmp (irq_type,"edge-falling" )) + pdata->irq_type =IRQF_TRIGGER_FALLING ; +else +dev_warn (&spi->dev,"wrong irq-type specified using edge-rising\n" ); + + spi->dev.platform_data = pdata; +done: +return pdata; +} +static int at86rf230_probe (struct spi_device *spi) {struct at86rf230_platform_data *pdata;
@@ -1053,7 +1088,7 @@ static int at86rf230_probe(struct spi_device *spi)return -EINVAL ; } - pdata = spi->dev.platform_data; + pdata =at86rf230_get_pdata (spi);if (!pdata) {dev_err (&spi->dev,"no platform_data\n" );return -EINVAL ;
@@ -1231,8 +1266,19 @@ static int at86rf230_remove(struct spi_device *spi)return 0 ; } +#if IS_ENABLED (CONFIG_OF ) +static struct of_device_id at86rf230_of_match[] = { + { .compatible ="atmel,at86rf230" , }, + { .compatible ="atmel,at86rf231" , }, + { .compatible ="atmel,at86rf233" , }, + { .compatible ="atmel,at86rf212" , }, + { }, +}; +#endif +static struct spi_driver at86rf230_driver = { .driver = { + .of_match_table =of_match_ptr (at86rf230_of_match), .name ="at86rf230" , .owner =THIS_MODULE , },
Signature · 9 lines
1.9.0 ------------------------------------------------------------------------------ Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. Written by three acclaimed leaders in the field, this first edition is now available. Download your free book today! http://p.sf.net/sfu/13534_NeoTech
David Miller
maintainerFrom: Alexander Aring <[email protected]>
Date: Sat, 15 Mar 2014 09:29:02 +0100
Quoted 2 lines
this patch series fix some bugs with the at86rf231 chip and cleaup some code. Also add devicetree support for the at86rf230 driver.
Series applied, thank you.