Commit 6755dee8 authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Stefan Schmidt

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: default avatarArnd Bergmann <arnd@arndb.de>
Link: https://lore.kernel.org/r/20230126161658.2983292-1-arnd@kernel.orgSigned-off-by: default avatarStefan Schmidt <stefan@datenfreihafen.org>
parent 8338304c
...@@ -4743,7 +4743,6 @@ L: linux-wpan@vger.kernel.org ...@@ -4743,7 +4743,6 @@ L: linux-wpan@vger.kernel.org
S: Maintained S: Maintained
F: Documentation/devicetree/bindings/net/ieee802154/cc2520.txt F: Documentation/devicetree/bindings/net/ieee802154/cc2520.txt
F: drivers/net/ieee802154/cc2520.c F: drivers/net/ieee802154/cc2520.c
F: include/linux/spi/cc2520.h
CCREE ARM TRUSTZONE CRYPTOCELL REE DRIVER CCREE ARM TRUSTZONE CRYPTOCELL REE DRIVER
M: Gilad Ben-Yossef <gilad@benyossef.com> M: Gilad Ben-Yossef <gilad@benyossef.com>
......
...@@ -7,14 +7,13 @@ ...@@ -7,14 +7,13 @@
*/ */
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/gpio.h> #include <linux/gpio/consumer.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#include <linux/spi/cc2520.h> #include <linux/property.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <linux/of_gpio.h>
#include <linux/ieee802154.h> #include <linux/ieee802154.h>
#include <linux/crc-ccitt.h> #include <linux/crc-ccitt.h>
#include <asm/unaligned.h> #include <asm/unaligned.h>
...@@ -206,7 +205,7 @@ struct cc2520_private { ...@@ -206,7 +205,7 @@ struct cc2520_private {
struct mutex buffer_mutex; /* SPI buffer mutex */ struct mutex buffer_mutex; /* SPI buffer mutex */
bool is_tx; /* Flag for sync b/w Tx and Rx */ bool is_tx; /* Flag for sync b/w Tx and Rx */
bool amplified; /* Flag for CC2591 */ 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 */ struct work_struct fifop_irqwork;/* Workqueue for FIFOP */
spinlock_t lock; /* Lock for is_tx*/ spinlock_t lock; /* Lock for is_tx*/
struct completion tx_complete; /* Work completion for Tx */ struct completion tx_complete; /* Work completion for Tx */
...@@ -875,7 +874,7 @@ static void cc2520_fifop_irqwork(struct work_struct *work) ...@@ -875,7 +874,7 @@ static void cc2520_fifop_irqwork(struct work_struct *work)
dev_dbg(&priv->spi->dev, "fifop interrupt received\n"); 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); cc2520_rx(priv);
else else
dev_dbg(&priv->spi->dev, "rxfifo overflow\n"); dev_dbg(&priv->spi->dev, "rxfifo overflow\n");
...@@ -912,49 +911,11 @@ static irqreturn_t cc2520_sfd_isr(int irq, void *data) ...@@ -912,49 +911,11 @@ static irqreturn_t cc2520_sfd_isr(int irq, void *data)
return IRQ_HANDLED; 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) static int cc2520_hw_init(struct cc2520_private *priv)
{ {
u8 status = 0, state = 0xff; u8 status = 0, state = 0xff;
int ret; int ret;
int timeout = 100; 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); ret = cc2520_read_register(priv, CC2520_FSMSTAT1, &state);
if (ret) if (ret)
...@@ -1071,7 +1032,11 @@ static int cc2520_hw_init(struct cc2520_private *priv) ...@@ -1071,7 +1032,11 @@ static int cc2520_hw_init(struct cc2520_private *priv)
static int cc2520_probe(struct spi_device *spi) static int cc2520_probe(struct spi_device *spi)
{ {
struct cc2520_private *priv; 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; int ret;
priv = devm_kzalloc(&spi->dev, sizeof(*priv), GFP_KERNEL); priv = devm_kzalloc(&spi->dev, sizeof(*priv), GFP_KERNEL);
...@@ -1080,11 +1045,11 @@ static int cc2520_probe(struct spi_device *spi) ...@@ -1080,11 +1045,11 @@ static int cc2520_probe(struct spi_device *spi)
spi_set_drvdata(spi, priv); spi_set_drvdata(spi, priv);
ret = cc2520_get_platform_data(spi, &pdata); /* CC2591 front end for CC2520 */
if (ret < 0) { /* Assumption that CC2591 is not connected */
dev_err(&spi->dev, "no platform data\n"); priv->amplified = false;
return -EINVAL; if (device_property_read_bool(&spi->dev, "amplified"))
} priv->amplified = true;
priv->spi = spi; priv->spi = spi;
...@@ -1098,80 +1063,53 @@ static int cc2520_probe(struct spi_device *spi) ...@@ -1098,80 +1063,53 @@ static int cc2520_probe(struct spi_device *spi)
spin_lock_init(&priv->lock); spin_lock_init(&priv->lock);
init_completion(&priv->tx_complete); init_completion(&priv->tx_complete);
/* Assumption that CC2591 is not connected */
priv->amplified = false;
/* Request all the gpio's */ /* 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"); dev_err(&spi->dev, "fifo gpio is not valid\n");
ret = -EINVAL; ret = PTR_ERR(priv->fifo_pin);
goto err_hw_init; goto err_hw_init;
} }
ret = devm_gpio_request_one(&spi->dev, pdata.fifo, cca = devm_gpiod_get(&spi->dev, "cca", GPIOD_IN);
GPIOF_IN, "fifo"); if (IS_ERR(cca)) {
if (ret)
goto err_hw_init;
if (!gpio_is_valid(pdata.cca)) {
dev_err(&spi->dev, "cca gpio is not valid\n"); dev_err(&spi->dev, "cca gpio is not valid\n");
ret = -EINVAL; ret = PTR_ERR(cca);
goto err_hw_init; goto err_hw_init;
} }
ret = devm_gpio_request_one(&spi->dev, pdata.cca, fifop = devm_gpiod_get(&spi->dev, "fifop", GPIOD_IN);
GPIOF_IN, "cca"); if (IS_ERR(fifop)) {
if (ret)
goto err_hw_init;
if (!gpio_is_valid(pdata.fifop)) {
dev_err(&spi->dev, "fifop gpio is not valid\n"); dev_err(&spi->dev, "fifop gpio is not valid\n");
ret = -EINVAL; ret = PTR_ERR(fifop);
goto err_hw_init; goto err_hw_init;
} }
ret = devm_gpio_request_one(&spi->dev, pdata.fifop, sfd = devm_gpiod_get(&spi->dev, "sfd", GPIOD_IN);
GPIOF_IN, "fifop"); if (IS_ERR(sfd)) {
if (ret)
goto err_hw_init;
if (!gpio_is_valid(pdata.sfd)) {
dev_err(&spi->dev, "sfd gpio is not valid\n"); dev_err(&spi->dev, "sfd gpio is not valid\n");
ret = -EINVAL; ret = PTR_ERR(sfd);
goto err_hw_init; goto err_hw_init;
} }
ret = devm_gpio_request_one(&spi->dev, pdata.sfd, reset = devm_gpiod_get(&spi->dev, "reset", GPIOD_OUT_LOW);
GPIOF_IN, "sfd"); if (IS_ERR(reset)) {
if (ret)
goto err_hw_init;
if (!gpio_is_valid(pdata.reset)) {
dev_err(&spi->dev, "reset gpio is not valid\n"); dev_err(&spi->dev, "reset gpio is not valid\n");
ret = -EINVAL; ret = PTR_ERR(reset);
goto err_hw_init; goto err_hw_init;
} }
ret = devm_gpio_request_one(&spi->dev, pdata.reset, vreg = devm_gpiod_get(&spi->dev, "vreg", GPIOD_OUT_LOW);
GPIOF_OUT_INIT_LOW, "reset"); if (IS_ERR(vreg)) {
if (ret)
goto err_hw_init;
if (!gpio_is_valid(pdata.vreg)) {
dev_err(&spi->dev, "vreg gpio is not valid\n"); dev_err(&spi->dev, "vreg gpio is not valid\n");
ret = -EINVAL; ret = PTR_ERR(vreg);
goto err_hw_init; goto err_hw_init;
} }
ret = devm_gpio_request_one(&spi->dev, pdata.vreg, gpiod_set_value(vreg, HIGH);
GPIOF_OUT_INIT_LOW, "vreg");
if (ret)
goto err_hw_init;
gpio_set_value(pdata.vreg, HIGH);
usleep_range(100, 150); usleep_range(100, 150);
gpio_set_value(pdata.reset, HIGH); gpiod_set_value(reset, HIGH);
usleep_range(200, 250); usleep_range(200, 250);
ret = cc2520_hw_init(priv); ret = cc2520_hw_init(priv);
...@@ -1180,7 +1118,7 @@ static int cc2520_probe(struct spi_device *spi) ...@@ -1180,7 +1118,7 @@ static int cc2520_probe(struct spi_device *spi)
/* Set up fifop interrupt */ /* Set up fifop interrupt */
ret = devm_request_irq(&spi->dev, ret = devm_request_irq(&spi->dev,
gpio_to_irq(pdata.fifop), gpiod_to_irq(fifop),
cc2520_fifop_isr, cc2520_fifop_isr,
IRQF_TRIGGER_RISING, IRQF_TRIGGER_RISING,
dev_name(&spi->dev), dev_name(&spi->dev),
...@@ -1192,7 +1130,7 @@ static int cc2520_probe(struct spi_device *spi) ...@@ -1192,7 +1130,7 @@ static int cc2520_probe(struct spi_device *spi)
/* Set up sfd interrupt */ /* Set up sfd interrupt */
ret = devm_request_irq(&spi->dev, ret = devm_request_irq(&spi->dev,
gpio_to_irq(pdata.sfd), gpiod_to_irq(sfd),
cc2520_sfd_isr, cc2520_sfd_isr,
IRQF_TRIGGER_FALLING, IRQF_TRIGGER_FALLING,
dev_name(&spi->dev), dev_name(&spi->dev),
...@@ -1241,7 +1179,7 @@ MODULE_DEVICE_TABLE(of, cc2520_of_ids); ...@@ -1241,7 +1179,7 @@ MODULE_DEVICE_TABLE(of, cc2520_of_ids);
static struct spi_driver cc2520_driver = { static struct spi_driver cc2520_driver = {
.driver = { .driver = {
.name = "cc2520", .name = "cc2520",
.of_match_table = of_match_ptr(cc2520_of_ids), .of_match_table = cc2520_of_ids,
}, },
.id_table = cc2520_ids, .id_table = cc2520_ids,
.probe = cc2520_probe, .probe = cc2520_probe,
......
/* SPDX-License-Identifier: GPL-2.0-or-later */
/* Header file for cc2520 radio driver
*
* Copyright (C) 2014 Varka Bhadram <varkab@cdac.in>
* Md.Jamal Mohiuddin <mjmohiuddin@cdac.in>
* P Sowjanya <sowjanyap@cdac.in>
*/
#ifndef __CC2520_H
#define __CC2520_H
struct cc2520_platform_data {
int fifo;
int fifop;
int cca;
int sfd;
int reset;
int vreg;
};
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment