Skip to content

Commit 9f2ad95

Browse files
Revert "at86rf230: convert to gpio descriptors"
This reverts commit 622bd6e. Dmitry Torokhov points out that this conversion leaves an existing board in reset state due to not properly handled polarity. Additionally, the GPIO name inadvertenly changes from "reset-gpio" to "rstn-gpios". Revert to avoid these regressions. Follow up patches for a better conversion are applied as well. Signed-off-by: Stefan Schmidt <[email protected]>
1 parent 6755dee commit 9f2ad95

File tree

2 files changed

+77
-25
lines changed

2 files changed

+77
-25
lines changed

drivers/net/ieee802154/at86rf230.c

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
#include <linux/jiffies.h>
1616
#include <linux/interrupt.h>
1717
#include <linux/irq.h>
18+
#include <linux/gpio.h>
1819
#include <linux/delay.h>
19-
#include <linux/gpio/consumer.h>
2020
#include <linux/spi/spi.h>
21-
#include <linux/property.h>
21+
#include <linux/spi/at86rf230.h>
2222
#include <linux/regmap.h>
2323
#include <linux/skbuff.h>
24+
#include <linux/of_gpio.h>
2425
#include <linux/ieee802154.h>
2526

2627
#include <net/mac802154.h>
@@ -81,7 +82,7 @@ struct at86rf230_local {
8182
struct ieee802154_hw *hw;
8283
struct at86rf2xx_chip_data *data;
8384
struct regmap *regmap;
84-
struct gpio_desc *slp_tr;
85+
int slp_tr;
8586
bool sleep;
8687

8788
struct completion state_complete;
@@ -106,8 +107,8 @@ at86rf230_async_state_change(struct at86rf230_local *lp,
106107
static inline void
107108
at86rf230_sleep(struct at86rf230_local *lp)
108109
{
109-
if (lp->slp_tr) {
110-
gpiod_set_value(lp->slp_tr, 1);
110+
if (gpio_is_valid(lp->slp_tr)) {
111+
gpio_set_value(lp->slp_tr, 1);
111112
usleep_range(lp->data->t_off_to_sleep,
112113
lp->data->t_off_to_sleep + 10);
113114
lp->sleep = true;
@@ -117,8 +118,8 @@ at86rf230_sleep(struct at86rf230_local *lp)
117118
static inline void
118119
at86rf230_awake(struct at86rf230_local *lp)
119120
{
120-
if (lp->slp_tr) {
121-
gpiod_set_value(lp->slp_tr, 0);
121+
if (gpio_is_valid(lp->slp_tr)) {
122+
gpio_set_value(lp->slp_tr, 0);
122123
usleep_range(lp->data->t_sleep_to_off,
123124
lp->data->t_sleep_to_off + 100);
124125
lp->sleep = false;
@@ -203,9 +204,9 @@ at86rf230_write_subreg(struct at86rf230_local *lp,
203204
static inline void
204205
at86rf230_slp_tr_rising_edge(struct at86rf230_local *lp)
205206
{
206-
gpiod_set_value(lp->slp_tr, 1);
207+
gpio_set_value(lp->slp_tr, 1);
207208
udelay(1);
208-
gpiod_set_value(lp->slp_tr, 0);
209+
gpio_set_value(lp->slp_tr, 0);
209210
}
210211

211212
static bool
@@ -818,7 +819,7 @@ at86rf230_write_frame_complete(void *context)
818819

819820
ctx->trx.len = 2;
820821

821-
if (lp->slp_tr)
822+
if (gpio_is_valid(lp->slp_tr))
822823
at86rf230_slp_tr_rising_edge(lp);
823824
else
824825
at86rf230_async_write_reg(lp, RG_TRX_STATE, STATE_BUSY_TX, ctx,
@@ -1414,6 +1415,32 @@ static int at86rf230_hw_init(struct at86rf230_local *lp, u8 xtal_trim)
14141415
return at86rf230_write_subreg(lp, SR_SLOTTED_OPERATION, 0);
14151416
}
14161417

1418+
static int
1419+
at86rf230_get_pdata(struct spi_device *spi, int *rstn, int *slp_tr,
1420+
u8 *xtal_trim)
1421+
{
1422+
struct at86rf230_platform_data *pdata = spi->dev.platform_data;
1423+
int ret;
1424+
1425+
if (!IS_ENABLED(CONFIG_OF) || !spi->dev.of_node) {
1426+
if (!pdata)
1427+
return -ENOENT;
1428+
1429+
*rstn = pdata->rstn;
1430+
*slp_tr = pdata->slp_tr;
1431+
*xtal_trim = pdata->xtal_trim;
1432+
return 0;
1433+
}
1434+
1435+
*rstn = of_get_named_gpio(spi->dev.of_node, "reset-gpio", 0);
1436+
*slp_tr = of_get_named_gpio(spi->dev.of_node, "sleep-gpio", 0);
1437+
ret = of_property_read_u8(spi->dev.of_node, "xtal-trim", xtal_trim);
1438+
if (ret < 0 && ret != -EINVAL)
1439+
return ret;
1440+
1441+
return 0;
1442+
}
1443+
14171444
static int
14181445
at86rf230_detect_device(struct at86rf230_local *lp)
14191446
{
@@ -1520,35 +1547,40 @@ static int at86rf230_probe(struct spi_device *spi)
15201547
struct ieee802154_hw *hw;
15211548
struct at86rf230_local *lp;
15221549
unsigned int status;
1523-
int rc, irq_type;
1524-
struct gpio_desc *rstn, *slp_tr;
1550+
int rc, irq_type, rstn, slp_tr;
15251551
u8 xtal_trim = 0;
15261552

15271553
if (!spi->irq) {
15281554
dev_err(&spi->dev, "no IRQ specified\n");
15291555
return -EINVAL;
15301556
}
15311557

1532-
rc = device_property_read_u8(&spi->dev, "xtal-trim", &xtal_trim);
1533-
if (rc < 0 && rc != -EINVAL) {
1534-
dev_err(&spi->dev, "failed to parse xtal-trim: %d\n", rc);
1558+
rc = at86rf230_get_pdata(spi, &rstn, &slp_tr, &xtal_trim);
1559+
if (rc < 0) {
1560+
dev_err(&spi->dev, "failed to parse platform_data: %d\n", rc);
15351561
return rc;
15361562
}
15371563

1538-
rstn = devm_gpiod_get_optional(&spi->dev, "rstn", GPIOD_OUT_HIGH);
1539-
if (IS_ERR(rstn))
1540-
return PTR_ERR(rstn);
1564+
if (gpio_is_valid(rstn)) {
1565+
rc = devm_gpio_request_one(&spi->dev, rstn,
1566+
GPIOF_OUT_INIT_HIGH, "rstn");
1567+
if (rc)
1568+
return rc;
1569+
}
15411570

1542-
slp_tr = devm_gpiod_get_optional(&spi->dev, "slp_tr", GPIOD_OUT_LOW);
1543-
if (IS_ERR(slp_tr))
1544-
return PTR_ERR(slp_tr);
1571+
if (gpio_is_valid(slp_tr)) {
1572+
rc = devm_gpio_request_one(&spi->dev, slp_tr,
1573+
GPIOF_OUT_INIT_LOW, "slp_tr");
1574+
if (rc)
1575+
return rc;
1576+
}
15451577

15461578
/* Reset */
1547-
if (rstn) {
1579+
if (gpio_is_valid(rstn)) {
15481580
udelay(1);
1549-
gpiod_set_value_cansleep(rstn, 0);
1581+
gpio_set_value_cansleep(rstn, 0);
15501582
udelay(1);
1551-
gpiod_set_value_cansleep(rstn, 1);
1583+
gpio_set_value_cansleep(rstn, 1);
15521584
usleep_range(120, 240);
15531585
}
15541586

@@ -1650,7 +1682,7 @@ MODULE_DEVICE_TABLE(spi, at86rf230_device_id);
16501682
static struct spi_driver at86rf230_driver = {
16511683
.id_table = at86rf230_device_id,
16521684
.driver = {
1653-
.of_match_table = at86rf230_of_match,
1685+
.of_match_table = of_match_ptr(at86rf230_of_match),
16541686
.name = "at86rf230",
16551687
},
16561688
.probe = at86rf230_probe,

include/linux/spi/at86rf230.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* AT86RF230/RF231 driver
4+
*
5+
* Copyright (C) 2009-2012 Siemens AG
6+
*
7+
* Written by:
8+
* Dmitry Eremin-Solenikov <[email protected]>
9+
*/
10+
#ifndef AT86RF230_H
11+
#define AT86RF230_H
12+
13+
struct at86rf230_platform_data {
14+
int rstn;
15+
int slp_tr;
16+
int dig2;
17+
u8 xtal_trim;
18+
};
19+
20+
#endif

0 commit comments

Comments
 (0)