From 622bd6ea90086beb98ac439edd7d57de73d1d6f9 Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Thu, 26 Jan 2023 17:22:59 +0100 Subject: at86rf230: convert to gpio descriptors There are no remaining in-tree users of the platform_data, so this driver can be converted to using the simpler gpiod interfaces. Any out-of-tree users that rely on the platform data can provide the data using the device_property and gpio_lookup interfaces instead. Reviewed-by: Miquel Raynal Reviewed-by: Andy Shevchenko Signed-off-by: Arnd Bergmann Link: https://lore.kernel.org/r/20230126162323.2986682-1-arnd@kernel.org Signed-off-by: Stefan Schmidt --- drivers/net/ieee802154/at86rf230.c | 82 ++++++++++++-------------------------- 1 file changed, 25 insertions(+), 57 deletions(-) (limited to 'drivers/net/ieee802154') diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c index 15f283b26721..a4a6b7490fdc 100644 --- a/drivers/net/ieee802154/at86rf230.c +++ b/drivers/net/ieee802154/at86rf230.c @@ -15,13 +15,12 @@ #include #include #include -#include #include +#include #include -#include +#include #include #include -#include #include #include @@ -82,7 +81,7 @@ struct at86rf230_local { struct ieee802154_hw *hw; struct at86rf2xx_chip_data *data; struct regmap *regmap; - int slp_tr; + struct gpio_desc *slp_tr; bool sleep; struct completion state_complete; @@ -107,8 +106,8 @@ at86rf230_async_state_change(struct at86rf230_local *lp, static inline void at86rf230_sleep(struct at86rf230_local *lp) { - if (gpio_is_valid(lp->slp_tr)) { - gpio_set_value(lp->slp_tr, 1); + if (lp->slp_tr) { + gpiod_set_value(lp->slp_tr, 1); usleep_range(lp->data->t_off_to_sleep, lp->data->t_off_to_sleep + 10); lp->sleep = true; @@ -118,8 +117,8 @@ at86rf230_sleep(struct at86rf230_local *lp) static inline void at86rf230_awake(struct at86rf230_local *lp) { - if (gpio_is_valid(lp->slp_tr)) { - gpio_set_value(lp->slp_tr, 0); + if (lp->slp_tr) { + gpiod_set_value(lp->slp_tr, 0); usleep_range(lp->data->t_sleep_to_off, lp->data->t_sleep_to_off + 100); lp->sleep = false; @@ -204,9 +203,9 @@ at86rf230_write_subreg(struct at86rf230_local *lp, static inline void at86rf230_slp_tr_rising_edge(struct at86rf230_local *lp) { - gpio_set_value(lp->slp_tr, 1); + gpiod_set_value(lp->slp_tr, 1); udelay(1); - gpio_set_value(lp->slp_tr, 0); + gpiod_set_value(lp->slp_tr, 0); } static bool @@ -819,7 +818,7 @@ at86rf230_write_frame_complete(void *context) ctx->trx.len = 2; - if (gpio_is_valid(lp->slp_tr)) + if (lp->slp_tr) at86rf230_slp_tr_rising_edge(lp); else at86rf230_async_write_reg(lp, RG_TRX_STATE, STATE_BUSY_TX, ctx, @@ -1415,32 +1414,6 @@ static int at86rf230_hw_init(struct at86rf230_local *lp, u8 xtal_trim) return at86rf230_write_subreg(lp, SR_SLOTTED_OPERATION, 0); } -static int -at86rf230_get_pdata(struct spi_device *spi, int *rstn, int *slp_tr, - u8 *xtal_trim) -{ - struct at86rf230_platform_data *pdata = spi->dev.platform_data; - int ret; - - if (!IS_ENABLED(CONFIG_OF) || !spi->dev.of_node) { - if (!pdata) - return -ENOENT; - - *rstn = pdata->rstn; - *slp_tr = pdata->slp_tr; - *xtal_trim = pdata->xtal_trim; - return 0; - } - - *rstn = of_get_named_gpio(spi->dev.of_node, "reset-gpio", 0); - *slp_tr = of_get_named_gpio(spi->dev.of_node, "sleep-gpio", 0); - ret = of_property_read_u8(spi->dev.of_node, "xtal-trim", xtal_trim); - if (ret < 0 && ret != -EINVAL) - return ret; - - return 0; -} - static int at86rf230_detect_device(struct at86rf230_local *lp) { @@ -1547,7 +1520,8 @@ static int at86rf230_probe(struct spi_device *spi) struct ieee802154_hw *hw; struct at86rf230_local *lp; unsigned int status; - int rc, irq_type, rstn, slp_tr; + int rc, irq_type; + struct gpio_desc *rstn, *slp_tr; u8 xtal_trim = 0; if (!spi->irq) { @@ -1555,32 +1529,26 @@ static int at86rf230_probe(struct spi_device *spi) return -EINVAL; } - rc = at86rf230_get_pdata(spi, &rstn, &slp_tr, &xtal_trim); - if (rc < 0) { - dev_err(&spi->dev, "failed to parse platform_data: %d\n", rc); + rc = device_property_read_u8(&spi->dev, "xtal-trim", &xtal_trim); + if (rc < 0 && rc != -EINVAL) { + dev_err(&spi->dev, "failed to parse xtal-trim: %d\n", rc); return rc; } - if (gpio_is_valid(rstn)) { - rc = devm_gpio_request_one(&spi->dev, rstn, - GPIOF_OUT_INIT_HIGH, "rstn"); - if (rc) - return rc; - } + rstn = devm_gpiod_get_optional(&spi->dev, "rstn", GPIOD_OUT_HIGH); + if (IS_ERR(rstn)) + return PTR_ERR(rstn); - if (gpio_is_valid(slp_tr)) { - rc = devm_gpio_request_one(&spi->dev, slp_tr, - GPIOF_OUT_INIT_LOW, "slp_tr"); - if (rc) - return rc; - } + slp_tr = devm_gpiod_get_optional(&spi->dev, "slp_tr", GPIOD_OUT_LOW); + if (IS_ERR(slp_tr)) + return PTR_ERR(slp_tr); /* Reset */ - if (gpio_is_valid(rstn)) { + if (rstn) { udelay(1); - gpio_set_value_cansleep(rstn, 0); + gpiod_set_value_cansleep(rstn, 0); udelay(1); - gpio_set_value_cansleep(rstn, 1); + gpiod_set_value_cansleep(rstn, 1); usleep_range(120, 240); } @@ -1682,7 +1650,7 @@ MODULE_DEVICE_TABLE(spi, at86rf230_device_id); static struct spi_driver at86rf230_driver = { .id_table = at86rf230_device_id, .driver = { - .of_match_table = of_match_ptr(at86rf230_of_match), + .of_match_table = at86rf230_of_match, .name = "at86rf230", }, .probe = at86rf230_probe, -- cgit v1.2.3 From 6755dee8343cbc4af45e001d904c9a857a451bec Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Thu, 26 Jan 2023 17:15:59 +0100 Subject: cc2520: move to gpio descriptors cc2520 supports both probing from static platform_data and from devicetree, but there have never been any definitions of the platform data in the mainline kernel, so it's safe to assume that only the DT path is used. After folding cc2520_platform_data into the driver itself, the GPIO handling can be simplified by moving to the modern gpiod interface. Signed-off-by: Arnd Bergmann Link: https://lore.kernel.org/r/20230126161658.2983292-1-arnd@kernel.org Signed-off-by: Stefan Schmidt --- MAINTAINERS | 1 - drivers/net/ieee802154/cc2520.c | 136 +++++++++++----------------------------- include/linux/spi/cc2520.h | 21 ------- 3 files changed, 37 insertions(+), 121 deletions(-) delete mode 100644 include/linux/spi/cc2520.h (limited to 'drivers/net/ieee802154') diff --git a/MAINTAINERS b/MAINTAINERS index 955c1be1efb2..6fc990f36d63 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -4743,7 +4743,6 @@ L: linux-wpan@vger.kernel.org S: Maintained F: Documentation/devicetree/bindings/net/ieee802154/cc2520.txt F: drivers/net/ieee802154/cc2520.c -F: include/linux/spi/cc2520.h CCREE ARM TRUSTZONE CRYPTOCELL REE DRIVER M: Gilad Ben-Yossef diff --git a/drivers/net/ieee802154/cc2520.c b/drivers/net/ieee802154/cc2520.c index c69b87d3837d..7272fba55fe8 100644 --- a/drivers/net/ieee802154/cc2520.c +++ b/drivers/net/ieee802154/cc2520.c @@ -7,14 +7,13 @@ */ #include #include -#include +#include #include #include -#include +#include #include #include #include -#include #include #include #include @@ -206,7 +205,7 @@ struct cc2520_private { struct mutex buffer_mutex; /* SPI buffer mutex */ bool is_tx; /* Flag for sync b/w Tx and Rx */ bool amplified; /* Flag for CC2591 */ - int fifo_pin; /* FIFO GPIO pin number */ + struct gpio_desc *fifo_pin; /* FIFO GPIO pin number */ struct work_struct fifop_irqwork;/* Workqueue for FIFOP */ spinlock_t lock; /* Lock for is_tx*/ struct completion tx_complete; /* Work completion for Tx */ @@ -875,7 +874,7 @@ static void cc2520_fifop_irqwork(struct work_struct *work) dev_dbg(&priv->spi->dev, "fifop interrupt received\n"); - if (gpio_get_value(priv->fifo_pin)) + if (gpiod_get_value(priv->fifo_pin)) cc2520_rx(priv); else dev_dbg(&priv->spi->dev, "rxfifo overflow\n"); @@ -912,49 +911,11 @@ static irqreturn_t cc2520_sfd_isr(int irq, void *data) return IRQ_HANDLED; } -static int cc2520_get_platform_data(struct spi_device *spi, - struct cc2520_platform_data *pdata) -{ - struct device_node *np = spi->dev.of_node; - struct cc2520_private *priv = spi_get_drvdata(spi); - - if (!np) { - struct cc2520_platform_data *spi_pdata = spi->dev.platform_data; - - if (!spi_pdata) - return -ENOENT; - *pdata = *spi_pdata; - priv->fifo_pin = pdata->fifo; - return 0; - } - - pdata->fifo = of_get_named_gpio(np, "fifo-gpio", 0); - priv->fifo_pin = pdata->fifo; - - pdata->fifop = of_get_named_gpio(np, "fifop-gpio", 0); - - pdata->sfd = of_get_named_gpio(np, "sfd-gpio", 0); - pdata->cca = of_get_named_gpio(np, "cca-gpio", 0); - pdata->vreg = of_get_named_gpio(np, "vreg-gpio", 0); - pdata->reset = of_get_named_gpio(np, "reset-gpio", 0); - - /* CC2591 front end for CC2520 */ - if (of_property_read_bool(np, "amplified")) - priv->amplified = true; - - return 0; -} - static int cc2520_hw_init(struct cc2520_private *priv) { u8 status = 0, state = 0xff; int ret; int timeout = 100; - struct cc2520_platform_data pdata; - - ret = cc2520_get_platform_data(priv->spi, &pdata); - if (ret) - goto err_ret; ret = cc2520_read_register(priv, CC2520_FSMSTAT1, &state); if (ret) @@ -1071,7 +1032,11 @@ err_ret: static int cc2520_probe(struct spi_device *spi) { struct cc2520_private *priv; - struct cc2520_platform_data pdata; + struct gpio_desc *fifop; + struct gpio_desc *cca; + struct gpio_desc *sfd; + struct gpio_desc *reset; + struct gpio_desc *vreg; int ret; priv = devm_kzalloc(&spi->dev, sizeof(*priv), GFP_KERNEL); @@ -1080,11 +1045,11 @@ static int cc2520_probe(struct spi_device *spi) spi_set_drvdata(spi, priv); - ret = cc2520_get_platform_data(spi, &pdata); - if (ret < 0) { - dev_err(&spi->dev, "no platform data\n"); - return -EINVAL; - } + /* CC2591 front end for CC2520 */ + /* Assumption that CC2591 is not connected */ + priv->amplified = false; + if (device_property_read_bool(&spi->dev, "amplified")) + priv->amplified = true; priv->spi = spi; @@ -1098,80 +1063,53 @@ static int cc2520_probe(struct spi_device *spi) spin_lock_init(&priv->lock); init_completion(&priv->tx_complete); - /* Assumption that CC2591 is not connected */ - priv->amplified = false; - /* Request all the gpio's */ - if (!gpio_is_valid(pdata.fifo)) { + priv->fifo_pin = devm_gpiod_get(&spi->dev, "fifo", GPIOD_IN); + if (IS_ERR(priv->fifo_pin)) { dev_err(&spi->dev, "fifo gpio is not valid\n"); - ret = -EINVAL; + ret = PTR_ERR(priv->fifo_pin); goto err_hw_init; } - ret = devm_gpio_request_one(&spi->dev, pdata.fifo, - GPIOF_IN, "fifo"); - if (ret) - goto err_hw_init; - - if (!gpio_is_valid(pdata.cca)) { + cca = devm_gpiod_get(&spi->dev, "cca", GPIOD_IN); + if (IS_ERR(cca)) { dev_err(&spi->dev, "cca gpio is not valid\n"); - ret = -EINVAL; + ret = PTR_ERR(cca); goto err_hw_init; } - ret = devm_gpio_request_one(&spi->dev, pdata.cca, - GPIOF_IN, "cca"); - if (ret) - goto err_hw_init; - - if (!gpio_is_valid(pdata.fifop)) { + fifop = devm_gpiod_get(&spi->dev, "fifop", GPIOD_IN); + if (IS_ERR(fifop)) { dev_err(&spi->dev, "fifop gpio is not valid\n"); - ret = -EINVAL; + ret = PTR_ERR(fifop); goto err_hw_init; } - ret = devm_gpio_request_one(&spi->dev, pdata.fifop, - GPIOF_IN, "fifop"); - if (ret) - goto err_hw_init; - - if (!gpio_is_valid(pdata.sfd)) { + sfd = devm_gpiod_get(&spi->dev, "sfd", GPIOD_IN); + if (IS_ERR(sfd)) { dev_err(&spi->dev, "sfd gpio is not valid\n"); - ret = -EINVAL; + ret = PTR_ERR(sfd); goto err_hw_init; } - ret = devm_gpio_request_one(&spi->dev, pdata.sfd, - GPIOF_IN, "sfd"); - if (ret) - goto err_hw_init; - - if (!gpio_is_valid(pdata.reset)) { + reset = devm_gpiod_get(&spi->dev, "reset", GPIOD_OUT_LOW); + if (IS_ERR(reset)) { dev_err(&spi->dev, "reset gpio is not valid\n"); - ret = -EINVAL; + ret = PTR_ERR(reset); goto err_hw_init; } - ret = devm_gpio_request_one(&spi->dev, pdata.reset, - GPIOF_OUT_INIT_LOW, "reset"); - if (ret) - goto err_hw_init; - - if (!gpio_is_valid(pdata.vreg)) { + vreg = devm_gpiod_get(&spi->dev, "vreg", GPIOD_OUT_LOW); + if (IS_ERR(vreg)) { dev_err(&spi->dev, "vreg gpio is not valid\n"); - ret = -EINVAL; + ret = PTR_ERR(vreg); goto err_hw_init; } - ret = devm_gpio_request_one(&spi->dev, pdata.vreg, - GPIOF_OUT_INIT_LOW, "vreg"); - if (ret) - goto err_hw_init; - - gpio_set_value(pdata.vreg, HIGH); + gpiod_set_value(vreg, HIGH); usleep_range(100, 150); - gpio_set_value(pdata.reset, HIGH); + gpiod_set_value(reset, HIGH); usleep_range(200, 250); ret = cc2520_hw_init(priv); @@ -1180,7 +1118,7 @@ static int cc2520_probe(struct spi_device *spi) /* Set up fifop interrupt */ ret = devm_request_irq(&spi->dev, - gpio_to_irq(pdata.fifop), + gpiod_to_irq(fifop), cc2520_fifop_isr, IRQF_TRIGGER_RISING, dev_name(&spi->dev), @@ -1192,7 +1130,7 @@ static int cc2520_probe(struct spi_device *spi) /* Set up sfd interrupt */ ret = devm_request_irq(&spi->dev, - gpio_to_irq(pdata.sfd), + gpiod_to_irq(sfd), cc2520_sfd_isr, IRQF_TRIGGER_FALLING, dev_name(&spi->dev), @@ -1241,7 +1179,7 @@ MODULE_DEVICE_TABLE(of, cc2520_of_ids); static struct spi_driver cc2520_driver = { .driver = { .name = "cc2520", - .of_match_table = of_match_ptr(cc2520_of_ids), + .of_match_table = cc2520_of_ids, }, .id_table = cc2520_ids, .probe = cc2520_probe, diff --git a/include/linux/spi/cc2520.h b/include/linux/spi/cc2520.h deleted file mode 100644 index 449bacf10700..000000000000 --- a/include/linux/spi/cc2520.h +++ /dev/null @@ -1,21 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* Header file for cc2520 radio driver - * - * Copyright (C) 2014 Varka Bhadram - * Md.Jamal Mohiuddin - * P Sowjanya - */ - -#ifndef __CC2520_H -#define __CC2520_H - -struct cc2520_platform_data { - int fifo; - int fifop; - int cca; - int sfd; - int reset; - int vreg; -}; - -#endif -- cgit v1.2.3 From 9f2ad955f98366003e887e32bdd4ea98ef2a04f4 Mon Sep 17 00:00:00 2001 From: Stefan Schmidt Date: Wed, 1 Feb 2023 21:10:26 +0100 Subject: Revert "at86rf230: convert to gpio descriptors" This reverts commit 622bd6ea90086beb98ac439edd7d57de73d1d6f9. 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 --- drivers/net/ieee802154/at86rf230.c | 82 ++++++++++++++++++++++++++------------ include/linux/spi/at86rf230.h | 20 ++++++++++ 2 files changed, 77 insertions(+), 25 deletions(-) create mode 100644 include/linux/spi/at86rf230.h (limited to 'drivers/net/ieee802154') diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c index a4a6b7490fdc..15f283b26721 100644 --- a/drivers/net/ieee802154/at86rf230.c +++ b/drivers/net/ieee802154/at86rf230.c @@ -15,12 +15,13 @@ #include #include #include +#include #include -#include #include -#include +#include #include #include +#include #include #include @@ -81,7 +82,7 @@ struct at86rf230_local { struct ieee802154_hw *hw; struct at86rf2xx_chip_data *data; struct regmap *regmap; - struct gpio_desc *slp_tr; + int slp_tr; bool sleep; struct completion state_complete; @@ -106,8 +107,8 @@ at86rf230_async_state_change(struct at86rf230_local *lp, static inline void at86rf230_sleep(struct at86rf230_local *lp) { - if (lp->slp_tr) { - gpiod_set_value(lp->slp_tr, 1); + if (gpio_is_valid(lp->slp_tr)) { + gpio_set_value(lp->slp_tr, 1); usleep_range(lp->data->t_off_to_sleep, lp->data->t_off_to_sleep + 10); lp->sleep = true; @@ -117,8 +118,8 @@ at86rf230_sleep(struct at86rf230_local *lp) static inline void at86rf230_awake(struct at86rf230_local *lp) { - if (lp->slp_tr) { - gpiod_set_value(lp->slp_tr, 0); + if (gpio_is_valid(lp->slp_tr)) { + gpio_set_value(lp->slp_tr, 0); usleep_range(lp->data->t_sleep_to_off, lp->data->t_sleep_to_off + 100); lp->sleep = false; @@ -203,9 +204,9 @@ at86rf230_write_subreg(struct at86rf230_local *lp, static inline void at86rf230_slp_tr_rising_edge(struct at86rf230_local *lp) { - gpiod_set_value(lp->slp_tr, 1); + gpio_set_value(lp->slp_tr, 1); udelay(1); - gpiod_set_value(lp->slp_tr, 0); + gpio_set_value(lp->slp_tr, 0); } static bool @@ -818,7 +819,7 @@ at86rf230_write_frame_complete(void *context) ctx->trx.len = 2; - if (lp->slp_tr) + if (gpio_is_valid(lp->slp_tr)) at86rf230_slp_tr_rising_edge(lp); else 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) return at86rf230_write_subreg(lp, SR_SLOTTED_OPERATION, 0); } +static int +at86rf230_get_pdata(struct spi_device *spi, int *rstn, int *slp_tr, + u8 *xtal_trim) +{ + struct at86rf230_platform_data *pdata = spi->dev.platform_data; + int ret; + + if (!IS_ENABLED(CONFIG_OF) || !spi->dev.of_node) { + if (!pdata) + return -ENOENT; + + *rstn = pdata->rstn; + *slp_tr = pdata->slp_tr; + *xtal_trim = pdata->xtal_trim; + return 0; + } + + *rstn = of_get_named_gpio(spi->dev.of_node, "reset-gpio", 0); + *slp_tr = of_get_named_gpio(spi->dev.of_node, "sleep-gpio", 0); + ret = of_property_read_u8(spi->dev.of_node, "xtal-trim", xtal_trim); + if (ret < 0 && ret != -EINVAL) + return ret; + + return 0; +} + static int at86rf230_detect_device(struct at86rf230_local *lp) { @@ -1520,8 +1547,7 @@ static int at86rf230_probe(struct spi_device *spi) struct ieee802154_hw *hw; struct at86rf230_local *lp; unsigned int status; - int rc, irq_type; - struct gpio_desc *rstn, *slp_tr; + int rc, irq_type, rstn, slp_tr; u8 xtal_trim = 0; if (!spi->irq) { @@ -1529,26 +1555,32 @@ static int at86rf230_probe(struct spi_device *spi) return -EINVAL; } - rc = device_property_read_u8(&spi->dev, "xtal-trim", &xtal_trim); - if (rc < 0 && rc != -EINVAL) { - dev_err(&spi->dev, "failed to parse xtal-trim: %d\n", rc); + rc = at86rf230_get_pdata(spi, &rstn, &slp_tr, &xtal_trim); + if (rc < 0) { + dev_err(&spi->dev, "failed to parse platform_data: %d\n", rc); return rc; } - rstn = devm_gpiod_get_optional(&spi->dev, "rstn", GPIOD_OUT_HIGH); - if (IS_ERR(rstn)) - return PTR_ERR(rstn); + if (gpio_is_valid(rstn)) { + rc = devm_gpio_request_one(&spi->dev, rstn, + GPIOF_OUT_INIT_HIGH, "rstn"); + if (rc) + return rc; + } - slp_tr = devm_gpiod_get_optional(&spi->dev, "slp_tr", GPIOD_OUT_LOW); - if (IS_ERR(slp_tr)) - return PTR_ERR(slp_tr); + if (gpio_is_valid(slp_tr)) { + rc = devm_gpio_request_one(&spi->dev, slp_tr, + GPIOF_OUT_INIT_LOW, "slp_tr"); + if (rc) + return rc; + } /* Reset */ - if (rstn) { + if (gpio_is_valid(rstn)) { udelay(1); - gpiod_set_value_cansleep(rstn, 0); + gpio_set_value_cansleep(rstn, 0); udelay(1); - gpiod_set_value_cansleep(rstn, 1); + gpio_set_value_cansleep(rstn, 1); usleep_range(120, 240); } @@ -1650,7 +1682,7 @@ MODULE_DEVICE_TABLE(spi, at86rf230_device_id); static struct spi_driver at86rf230_driver = { .id_table = at86rf230_device_id, .driver = { - .of_match_table = at86rf230_of_match, + .of_match_table = of_match_ptr(at86rf230_of_match), .name = "at86rf230", }, .probe = at86rf230_probe, diff --git a/include/linux/spi/at86rf230.h b/include/linux/spi/at86rf230.h new file mode 100644 index 000000000000..d278576ab692 --- /dev/null +++ b/include/linux/spi/at86rf230.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * AT86RF230/RF231 driver + * + * Copyright (C) 2009-2012 Siemens AG + * + * Written by: + * Dmitry Eremin-Solenikov + */ +#ifndef AT86RF230_H +#define AT86RF230_H + +struct at86rf230_platform_data { + int rstn; + int slp_tr; + int dig2; + u8 xtal_trim; +}; + +#endif -- cgit v1.2.3 From 9b26ed18545056794bf9d3f3defd9e09719ff4f5 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Tue, 31 Jan 2023 21:34:46 -0800 Subject: ieee802154: at86rf230: drop support for platform data There are no users of platform data in the mainline tree, and new boards should use either ACPI or device tree, so let's stop supporting it. This will help with converting the driver to gpiod API. Signed-off-by: Dmitry Torokhov Link: https://lore.kernel.org/r/20230201053447.4098486-1-dmitry.torokhov@gmail.com Signed-off-by: Stefan Schmidt --- drivers/net/ieee802154/at86rf230.c | 42 ++++++++++---------------------------- include/linux/spi/at86rf230.h | 20 ------------------ 2 files changed, 11 insertions(+), 51 deletions(-) delete mode 100644 include/linux/spi/at86rf230.h (limited to 'drivers/net/ieee802154') diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c index 15f283b26721..d6b6b355348b 100644 --- a/drivers/net/ieee802154/at86rf230.c +++ b/drivers/net/ieee802154/at86rf230.c @@ -17,8 +17,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -1415,32 +1415,6 @@ static int at86rf230_hw_init(struct at86rf230_local *lp, u8 xtal_trim) return at86rf230_write_subreg(lp, SR_SLOTTED_OPERATION, 0); } -static int -at86rf230_get_pdata(struct spi_device *spi, int *rstn, int *slp_tr, - u8 *xtal_trim) -{ - struct at86rf230_platform_data *pdata = spi->dev.platform_data; - int ret; - - if (!IS_ENABLED(CONFIG_OF) || !spi->dev.of_node) { - if (!pdata) - return -ENOENT; - - *rstn = pdata->rstn; - *slp_tr = pdata->slp_tr; - *xtal_trim = pdata->xtal_trim; - return 0; - } - - *rstn = of_get_named_gpio(spi->dev.of_node, "reset-gpio", 0); - *slp_tr = of_get_named_gpio(spi->dev.of_node, "sleep-gpio", 0); - ret = of_property_read_u8(spi->dev.of_node, "xtal-trim", xtal_trim); - if (ret < 0 && ret != -EINVAL) - return ret; - - return 0; -} - static int at86rf230_detect_device(struct at86rf230_local *lp) { @@ -1548,19 +1522,24 @@ static int at86rf230_probe(struct spi_device *spi) struct at86rf230_local *lp; unsigned int status; int rc, irq_type, rstn, slp_tr; - u8 xtal_trim = 0; + u8 xtal_trim; if (!spi->irq) { dev_err(&spi->dev, "no IRQ specified\n"); return -EINVAL; } - rc = at86rf230_get_pdata(spi, &rstn, &slp_tr, &xtal_trim); + rc = device_property_read_u8(&spi->dev, "xtal-trim", &xtal_trim); if (rc < 0) { - dev_err(&spi->dev, "failed to parse platform_data: %d\n", rc); - return rc; + if (rc != -EINVAL) { + dev_err(&spi->dev, + "failed to parse xtal-trim: %d\n", rc); + return rc; + } + xtal_trim = 0; } + rstn = of_get_named_gpio(spi->dev.of_node, "reset-gpio", 0); if (gpio_is_valid(rstn)) { rc = devm_gpio_request_one(&spi->dev, rstn, GPIOF_OUT_INIT_HIGH, "rstn"); @@ -1568,6 +1547,7 @@ static int at86rf230_probe(struct spi_device *spi) return rc; } + slp_tr = of_get_named_gpio(spi->dev.of_node, "sleep-gpio", 0); if (gpio_is_valid(slp_tr)) { rc = devm_gpio_request_one(&spi->dev, slp_tr, GPIOF_OUT_INIT_LOW, "slp_tr"); diff --git a/include/linux/spi/at86rf230.h b/include/linux/spi/at86rf230.h deleted file mode 100644 index d278576ab692..000000000000 --- a/include/linux/spi/at86rf230.h +++ /dev/null @@ -1,20 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * AT86RF230/RF231 driver - * - * Copyright (C) 2009-2012 Siemens AG - * - * Written by: - * Dmitry Eremin-Solenikov - */ -#ifndef AT86RF230_H -#define AT86RF230_H - -struct at86rf230_platform_data { - int rstn; - int slp_tr; - int dig2; - u8 xtal_trim; -}; - -#endif -- cgit v1.2.3 From 6130543654e0e5a79485ed8538c0bf2259fe7431 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Tue, 31 Jan 2023 21:34:47 -0800 Subject: ieee802154: at86rf230: switch to using gpiod API Switch the driver from legacy gpio API that is deprecated to the newer gpiod API that respects line polarities described in ACPI/DT. Signed-off-by: Dmitry Torokhov Link: https://lore.kernel.org/r/20230201053447.4098486-2-dmitry.torokhov@gmail.com Signed-off-by: Stefan Schmidt --- drivers/net/ieee802154/at86rf230.c | 52 +++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'drivers/net/ieee802154') diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c index d6b6b355348b..62b984f84d9f 100644 --- a/drivers/net/ieee802154/at86rf230.c +++ b/drivers/net/ieee802154/at86rf230.c @@ -82,7 +82,7 @@ struct at86rf230_local { struct ieee802154_hw *hw; struct at86rf2xx_chip_data *data; struct regmap *regmap; - int slp_tr; + struct gpio_desc *slp_tr; bool sleep; struct completion state_complete; @@ -107,8 +107,8 @@ at86rf230_async_state_change(struct at86rf230_local *lp, static inline void at86rf230_sleep(struct at86rf230_local *lp) { - if (gpio_is_valid(lp->slp_tr)) { - gpio_set_value(lp->slp_tr, 1); + if (lp->slp_tr) { + gpiod_set_value(lp->slp_tr, 1); usleep_range(lp->data->t_off_to_sleep, lp->data->t_off_to_sleep + 10); lp->sleep = true; @@ -118,8 +118,8 @@ at86rf230_sleep(struct at86rf230_local *lp) static inline void at86rf230_awake(struct at86rf230_local *lp) { - if (gpio_is_valid(lp->slp_tr)) { - gpio_set_value(lp->slp_tr, 0); + if (lp->slp_tr) { + gpiod_set_value(lp->slp_tr, 0); usleep_range(lp->data->t_sleep_to_off, lp->data->t_sleep_to_off + 100); lp->sleep = false; @@ -204,9 +204,9 @@ at86rf230_write_subreg(struct at86rf230_local *lp, static inline void at86rf230_slp_tr_rising_edge(struct at86rf230_local *lp) { - gpio_set_value(lp->slp_tr, 1); + gpiod_set_value(lp->slp_tr, 1); udelay(1); - gpio_set_value(lp->slp_tr, 0); + gpiod_set_value(lp->slp_tr, 0); } static bool @@ -819,7 +819,7 @@ at86rf230_write_frame_complete(void *context) ctx->trx.len = 2; - if (gpio_is_valid(lp->slp_tr)) + if (lp->slp_tr) at86rf230_slp_tr_rising_edge(lp); else at86rf230_async_write_reg(lp, RG_TRX_STATE, STATE_BUSY_TX, ctx, @@ -1520,8 +1520,10 @@ static int at86rf230_probe(struct spi_device *spi) { struct ieee802154_hw *hw; struct at86rf230_local *lp; + struct gpio_desc *slp_tr; + struct gpio_desc *rstn; unsigned int status; - int rc, irq_type, rstn, slp_tr; + int rc, irq_type; u8 xtal_trim; if (!spi->irq) { @@ -1539,28 +1541,26 @@ static int at86rf230_probe(struct spi_device *spi) xtal_trim = 0; } - rstn = of_get_named_gpio(spi->dev.of_node, "reset-gpio", 0); - if (gpio_is_valid(rstn)) { - rc = devm_gpio_request_one(&spi->dev, rstn, - GPIOF_OUT_INIT_HIGH, "rstn"); - if (rc) - return rc; - } + rstn = devm_gpiod_get_optional(&spi->dev, "reset", GPIOD_OUT_LOW); + rc = PTR_ERR_OR_ZERO(rstn); + if (rc) + return rc; - slp_tr = of_get_named_gpio(spi->dev.of_node, "sleep-gpio", 0); - if (gpio_is_valid(slp_tr)) { - rc = devm_gpio_request_one(&spi->dev, slp_tr, - GPIOF_OUT_INIT_LOW, "slp_tr"); - if (rc) - return rc; - } + gpiod_set_consumer_name(rstn, "rstn"); + + slp_tr = devm_gpiod_get_optional(&spi->dev, "sleep", GPIOD_OUT_LOW); + rc = PTR_ERR_OR_ZERO(slp_tr); + if (rc) + return rc; + + gpiod_set_consumer_name(slp_tr, "slp_tr"); /* Reset */ - if (gpio_is_valid(rstn)) { + if (rstn) { udelay(1); - gpio_set_value_cansleep(rstn, 0); + gpiod_set_value_cansleep(rstn, 1); udelay(1); - gpio_set_value_cansleep(rstn, 1); + gpiod_set_value_cansleep(rstn, 0); usleep_range(120, 240); } -- cgit v1.2.3