mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-15 06:55:13 +08:00
wifi: wl1251: switch to using gpiod API
Switch the driver from legacy gpio API to the newer gpiod API. Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Signed-off-by: Kalle Valo <kvalo@kernel.org> Link: https://lore.kernel.org/r/20221109224250.2885119-3-dmitry.torokhov@gmail.com
This commit is contained in:
parent
06463f6e98
commit
a1d0b9535c
@ -5,6 +5,7 @@
|
|||||||
* Copyright (C) 2008 Nokia Corporation
|
* Copyright (C) 2008 Nokia Corporation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <linux/err.h>
|
||||||
#include <linux/interrupt.h>
|
#include <linux/interrupt.h>
|
||||||
#include <linux/irq.h>
|
#include <linux/irq.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
@ -12,15 +13,19 @@
|
|||||||
#include <linux/swab.h>
|
#include <linux/swab.h>
|
||||||
#include <linux/crc7.h>
|
#include <linux/crc7.h>
|
||||||
#include <linux/spi/spi.h>
|
#include <linux/spi/spi.h>
|
||||||
#include <linux/gpio.h>
|
#include <linux/gpio/consumer.h>
|
||||||
#include <linux/of.h>
|
#include <linux/of.h>
|
||||||
#include <linux/of_gpio.h>
|
|
||||||
#include <linux/regulator/consumer.h>
|
#include <linux/regulator/consumer.h>
|
||||||
|
|
||||||
#include "wl1251.h"
|
#include "wl1251.h"
|
||||||
#include "reg.h"
|
#include "reg.h"
|
||||||
#include "spi.h"
|
#include "spi.h"
|
||||||
|
|
||||||
|
struct wl1251_spi {
|
||||||
|
struct spi_device *spi;
|
||||||
|
struct gpio_desc *power_gpio;
|
||||||
|
};
|
||||||
|
|
||||||
static irqreturn_t wl1251_irq(int irq, void *cookie)
|
static irqreturn_t wl1251_irq(int irq, void *cookie)
|
||||||
{
|
{
|
||||||
struct wl1251 *wl;
|
struct wl1251 *wl;
|
||||||
@ -34,13 +39,9 @@ static irqreturn_t wl1251_irq(int irq, void *cookie)
|
|||||||
return IRQ_HANDLED;
|
return IRQ_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct spi_device *wl_to_spi(struct wl1251 *wl)
|
|
||||||
{
|
|
||||||
return wl->if_priv;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void wl1251_spi_reset(struct wl1251 *wl)
|
static void wl1251_spi_reset(struct wl1251 *wl)
|
||||||
{
|
{
|
||||||
|
struct wl1251_spi *wl_spi = wl->if_priv;
|
||||||
u8 *cmd;
|
u8 *cmd;
|
||||||
struct spi_transfer t;
|
struct spi_transfer t;
|
||||||
struct spi_message m;
|
struct spi_message m;
|
||||||
@ -60,7 +61,7 @@ static void wl1251_spi_reset(struct wl1251 *wl)
|
|||||||
t.len = WSPI_INIT_CMD_LEN;
|
t.len = WSPI_INIT_CMD_LEN;
|
||||||
spi_message_add_tail(&t, &m);
|
spi_message_add_tail(&t, &m);
|
||||||
|
|
||||||
spi_sync(wl_to_spi(wl), &m);
|
spi_sync(wl_spi->spi, &m);
|
||||||
|
|
||||||
wl1251_dump(DEBUG_SPI, "spi reset -> ", cmd, WSPI_INIT_CMD_LEN);
|
wl1251_dump(DEBUG_SPI, "spi reset -> ", cmd, WSPI_INIT_CMD_LEN);
|
||||||
|
|
||||||
@ -69,6 +70,7 @@ static void wl1251_spi_reset(struct wl1251 *wl)
|
|||||||
|
|
||||||
static void wl1251_spi_wake(struct wl1251 *wl)
|
static void wl1251_spi_wake(struct wl1251 *wl)
|
||||||
{
|
{
|
||||||
|
struct wl1251_spi *wl_spi = wl->if_priv;
|
||||||
struct spi_transfer t;
|
struct spi_transfer t;
|
||||||
struct spi_message m;
|
struct spi_message m;
|
||||||
u8 *cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL);
|
u8 *cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL);
|
||||||
@ -112,7 +114,7 @@ static void wl1251_spi_wake(struct wl1251 *wl)
|
|||||||
t.len = WSPI_INIT_CMD_LEN;
|
t.len = WSPI_INIT_CMD_LEN;
|
||||||
spi_message_add_tail(&t, &m);
|
spi_message_add_tail(&t, &m);
|
||||||
|
|
||||||
spi_sync(wl_to_spi(wl), &m);
|
spi_sync(wl_spi->spi, &m);
|
||||||
|
|
||||||
wl1251_dump(DEBUG_SPI, "spi init -> ", cmd, WSPI_INIT_CMD_LEN);
|
wl1251_dump(DEBUG_SPI, "spi init -> ", cmd, WSPI_INIT_CMD_LEN);
|
||||||
|
|
||||||
@ -128,6 +130,7 @@ static void wl1251_spi_reset_wake(struct wl1251 *wl)
|
|||||||
static void wl1251_spi_read(struct wl1251 *wl, int addr, void *buf,
|
static void wl1251_spi_read(struct wl1251 *wl, int addr, void *buf,
|
||||||
size_t len)
|
size_t len)
|
||||||
{
|
{
|
||||||
|
struct wl1251_spi *wl_spi = wl->if_priv;
|
||||||
struct spi_transfer t[3];
|
struct spi_transfer t[3];
|
||||||
struct spi_message m;
|
struct spi_message m;
|
||||||
u8 *busy_buf;
|
u8 *busy_buf;
|
||||||
@ -157,7 +160,7 @@ static void wl1251_spi_read(struct wl1251 *wl, int addr, void *buf,
|
|||||||
t[2].len = len;
|
t[2].len = len;
|
||||||
spi_message_add_tail(&t[2], &m);
|
spi_message_add_tail(&t[2], &m);
|
||||||
|
|
||||||
spi_sync(wl_to_spi(wl), &m);
|
spi_sync(wl_spi->spi, &m);
|
||||||
|
|
||||||
/* FIXME: check busy words */
|
/* FIXME: check busy words */
|
||||||
|
|
||||||
@ -168,6 +171,7 @@ static void wl1251_spi_read(struct wl1251 *wl, int addr, void *buf,
|
|||||||
static void wl1251_spi_write(struct wl1251 *wl, int addr, void *buf,
|
static void wl1251_spi_write(struct wl1251 *wl, int addr, void *buf,
|
||||||
size_t len)
|
size_t len)
|
||||||
{
|
{
|
||||||
|
struct wl1251_spi *wl_spi = wl->if_priv;
|
||||||
struct spi_transfer t[2];
|
struct spi_transfer t[2];
|
||||||
struct spi_message m;
|
struct spi_message m;
|
||||||
u32 *cmd;
|
u32 *cmd;
|
||||||
@ -190,7 +194,7 @@ static void wl1251_spi_write(struct wl1251 *wl, int addr, void *buf,
|
|||||||
t[1].len = len;
|
t[1].len = len;
|
||||||
spi_message_add_tail(&t[1], &m);
|
spi_message_add_tail(&t[1], &m);
|
||||||
|
|
||||||
spi_sync(wl_to_spi(wl), &m);
|
spi_sync(wl_spi->spi, &m);
|
||||||
|
|
||||||
wl1251_dump(DEBUG_SPI, "spi_write cmd -> ", cmd, sizeof(*cmd));
|
wl1251_dump(DEBUG_SPI, "spi_write cmd -> ", cmd, sizeof(*cmd));
|
||||||
wl1251_dump(DEBUG_SPI, "spi_write buf -> ", buf, len);
|
wl1251_dump(DEBUG_SPI, "spi_write buf -> ", buf, len);
|
||||||
@ -208,8 +212,10 @@ static void wl1251_spi_disable_irq(struct wl1251 *wl)
|
|||||||
|
|
||||||
static int wl1251_spi_set_power(struct wl1251 *wl, bool enable)
|
static int wl1251_spi_set_power(struct wl1251 *wl, bool enable)
|
||||||
{
|
{
|
||||||
if (gpio_is_valid(wl->power_gpio))
|
struct wl1251_spi *wl_spi = wl->if_priv;
|
||||||
gpio_set_value(wl->power_gpio, enable);
|
|
||||||
|
if (wl_spi->power_gpio)
|
||||||
|
gpiod_set_value_cansleep(wl_spi->power_gpio, enable);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -227,12 +233,19 @@ static int wl1251_spi_probe(struct spi_device *spi)
|
|||||||
{
|
{
|
||||||
struct device_node *np = spi->dev.of_node;
|
struct device_node *np = spi->dev.of_node;
|
||||||
struct ieee80211_hw *hw;
|
struct ieee80211_hw *hw;
|
||||||
|
struct wl1251_spi *wl_spi;
|
||||||
struct wl1251 *wl;
|
struct wl1251 *wl;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!np)
|
if (!np)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
|
wl_spi = devm_kzalloc(&spi->dev, sizeof(*wl_spi), GFP_KERNEL);
|
||||||
|
if (!wl_spi)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
wl_spi->spi = spi;
|
||||||
|
|
||||||
hw = wl1251_alloc_hw();
|
hw = wl1251_alloc_hw();
|
||||||
if (IS_ERR(hw))
|
if (IS_ERR(hw))
|
||||||
return PTR_ERR(hw);
|
return PTR_ERR(hw);
|
||||||
@ -241,7 +254,7 @@ static int wl1251_spi_probe(struct spi_device *spi)
|
|||||||
|
|
||||||
SET_IEEE80211_DEV(hw, &spi->dev);
|
SET_IEEE80211_DEV(hw, &spi->dev);
|
||||||
spi_set_drvdata(spi, wl);
|
spi_set_drvdata(spi, wl);
|
||||||
wl->if_priv = spi;
|
wl->if_priv = wl_spi;
|
||||||
wl->if_ops = &wl1251_spi_ops;
|
wl->if_ops = &wl1251_spi_ops;
|
||||||
|
|
||||||
/* This is the only SPI value that we need to set here, the rest
|
/* This is the only SPI value that we need to set here, the rest
|
||||||
@ -257,24 +270,16 @@ static int wl1251_spi_probe(struct spi_device *spi)
|
|||||||
|
|
||||||
wl->use_eeprom = of_property_read_bool(np, "ti,wl1251-has-eeprom");
|
wl->use_eeprom = of_property_read_bool(np, "ti,wl1251-has-eeprom");
|
||||||
|
|
||||||
wl->power_gpio = of_get_named_gpio(np, "ti,power-gpio", 0);
|
wl_spi->power_gpio = devm_gpiod_get_optional(&spi->dev, "ti,power",
|
||||||
if (wl->power_gpio == -EPROBE_DEFER) {
|
GPIOD_OUT_LOW);
|
||||||
ret = -EPROBE_DEFER;
|
ret = PTR_ERR_OR_ZERO(wl_spi->power_gpio);
|
||||||
|
if (ret) {
|
||||||
|
if (ret != -EPROBE_DEFER)
|
||||||
|
wl1251_error("Failed to request gpio: %d\n", ret);
|
||||||
goto out_free;
|
goto out_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gpio_is_valid(wl->power_gpio)) {
|
gpiod_set_consumer_name(wl_spi->power_gpio, "wl1251 power");
|
||||||
ret = devm_gpio_request_one(&spi->dev, wl->power_gpio,
|
|
||||||
GPIOF_OUT_INIT_LOW, "wl1251 power");
|
|
||||||
if (ret) {
|
|
||||||
wl1251_error("Failed to request gpio: %d\n", ret);
|
|
||||||
goto out_free;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
wl1251_error("set power gpio missing in platform data");
|
|
||||||
ret = -ENODEV;
|
|
||||||
goto out_free;
|
|
||||||
}
|
|
||||||
|
|
||||||
wl->irq = spi->irq;
|
wl->irq = spi->irq;
|
||||||
if (wl->irq < 0) {
|
if (wl->irq < 0) {
|
||||||
|
@ -262,7 +262,6 @@ struct wl1251 {
|
|||||||
void *if_priv;
|
void *if_priv;
|
||||||
const struct wl1251_if_operations *if_ops;
|
const struct wl1251_if_operations *if_ops;
|
||||||
|
|
||||||
int power_gpio;
|
|
||||||
int irq;
|
int irq;
|
||||||
bool use_eeprom;
|
bool use_eeprom;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user