From 7332fcb82a15730f4b0bfa65db074c505c0ffc1a Mon Sep 17 00:00:00 2001 From: Alexander Aring Date: Sat, 15 Mar 2014 09:29:03 +0100 Subject: 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] [] (unwind_backtrace) from [] (show_stack+0x10/0x14) [ 20.106819] [] (show_stack) from [] (warn_slowpath_common+0x60/0x80) [ 20.115311] [] (warn_slowpath_common) from [] (warn_slowpath_null+0x18/0x20) [ 20.124590] [] (warn_slowpath_null) from [] (mac802154_slave_open+0x70/0xb8) [ 20.133880] [] (mac802154_slave_open) from [] (__dev_open+0xa8/0x108) [ 20.142553] [] (__dev_open) from [] (__dev_change_flags+0x8c/0x148) [ 20.151051] [] (__dev_change_flags) from [] (dev_change_flags+0x18/0x48) [ 20.159968] [] (dev_change_flags) from [] (devinet_ioctl+0x2b0/0x63c) [ 20.168623] [] (devinet_ioctl) from [] (sock_ioctl+0x23c/0x29c) [ 20.176727] [] (sock_ioctl) from [] (do_vfs_ioctl+0x4a8/0x578) [ 20.184671] [] (do_vfs_ioctl) from [] (SyS_ioctl+0x4c/0x78) [ 20.192402] [] (SyS_ioctl) from [] (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 Signed-off-by: Alexander Aring Signed-off-by: David S. Miller --- drivers/net/ieee802154/at86rf230.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c index ae38a98d072e..ad296bc86e69 100644 --- a/drivers/net/ieee802154/at86rf230.c +++ b/drivers/net/ieee802154/at86rf230.c @@ -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; -- cgit v1.2.3 From 7e8146189a6c2ba9445b8d848847f2520c6cb028 Mon Sep 17 00:00:00 2001 From: Alexander Aring Date: Sat, 15 Mar 2014 09:29:04 +0100 Subject: at86rf230: move locking state in xmit There is no need to lock the clearing of IRQ_TRX_END in status. Signed-off-by: Alexander Aring Signed-off-by: David S. Miller --- drivers/net/ieee802154/at86rf230.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c index ad296bc86e69..030bf3995e7e 100644 --- a/drivers/net/ieee802154/at86rf230.c +++ b/drivers/net/ieee802154/at86rf230.c @@ -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); -- cgit v1.2.3 From 56f023fbe8fff04a46b5486288eaa1dc8bfdd5b9 Mon Sep 17 00:00:00 2001 From: Alexander Aring Date: Sat, 15 Mar 2014 09:29:05 +0100 Subject: at86rf230: change reset timings While 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. Signed-off-by: Alexander Aring Signed-off-by: David S. Miller --- drivers/net/ieee802154/at86rf230.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c index 030bf3995e7e..37442407d948 100644 --- a/drivers/net/ieee802154/at86rf230.c +++ b/drivers/net/ieee802154/at86rf230.c @@ -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) -- cgit v1.2.3 From 3fa275712489d31171b612a9a83e7b9840c6364e Mon Sep 17 00:00:00 2001 From: Alexander Aring Date: Sat, 15 Mar 2014 09:29:06 +0100 Subject: at86rf230: make reset pin optionally This 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. Signed-off-by: Alexander Aring Signed-off-by: David S. Miller --- drivers/net/ieee802154/at86rf230.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c index 37442407d948..47677e3f986f 100644 --- a/drivers/net/ieee802154/at86rf230.c +++ b/drivers/net/ieee802154/at86rf230.c @@ -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); -- cgit v1.2.3 From fa2d3e9471b37c2d3cd3cede73065b3b867532ee Mon Sep 17 00:00:00 2001 From: Alexander Aring Date: Sat, 15 Mar 2014 09:29:07 +0100 Subject: at86rf230: add support for devicetree This 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. Signed-off-by: Alexander Aring Signed-off-by: David S. Miller --- drivers/net/ieee802154/at86rf230.c | 48 +++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c index 47677e3f986f..e8004ef73bc1 100644 --- a/drivers/net/ieee802154/at86rf230.c +++ b/drivers/net/ieee802154/at86rf230.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -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, }, -- cgit v1.2.3