Commit 006534ec authored by Dmitry Torokhov's avatar Dmitry Torokhov Committed by Paolo Abeni

net: phy: spi_ks8895: switch to using gpiod API

This patch switches the driver away from legacy gpio/of_gpio API to
gpiod API, and removes use of of_get_named_gpio_flags() which I want to
make private to gpiolib.
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20220906204922.3789922-3-dmitry.torokhov@gmail.comSigned-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent 7b77bb5c
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include <linux/device.h> #include <linux/device.h>
#include <linux/gpio/consumer.h> #include <linux/gpio/consumer.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_gpio.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
...@@ -137,15 +136,10 @@ static const struct ks8995_chip_params ks8995_chip[] = { ...@@ -137,15 +136,10 @@ static const struct ks8995_chip_params ks8995_chip[] = {
}, },
}; };
struct ks8995_pdata {
int reset_gpio;
enum of_gpio_flags reset_gpio_flags;
};
struct ks8995_switch { struct ks8995_switch {
struct spi_device *spi; struct spi_device *spi;
struct mutex lock; struct mutex lock;
struct ks8995_pdata *pdata; struct gpio_desc *reset_gpio;
struct bin_attribute regs_attr; struct bin_attribute regs_attr;
const struct ks8995_chip_params *chip; const struct ks8995_chip_params *chip;
int revision_id; int revision_id;
...@@ -401,24 +395,6 @@ static int ks8995_get_revision(struct ks8995_switch *ks) ...@@ -401,24 +395,6 @@ static int ks8995_get_revision(struct ks8995_switch *ks)
return err; return err;
} }
/* ks8995_parse_dt - setup platform data from devicetree
* @ks: pointer to switch instance
*
* Parses supported DT properties and sets up platform data
* accordingly.
*/
static void ks8995_parse_dt(struct ks8995_switch *ks)
{
struct device_node *np = ks->spi->dev.of_node;
struct ks8995_pdata *pdata = ks->pdata;
if (!np)
return;
pdata->reset_gpio = of_get_named_gpio_flags(np, "reset-gpios", 0,
&pdata->reset_gpio_flags);
}
static const struct bin_attribute ks8995_registers_attr = { static const struct bin_attribute ks8995_registers_attr = {
.attr = { .attr = {
.name = "registers", .name = "registers",
...@@ -449,38 +425,22 @@ static int ks8995_probe(struct spi_device *spi) ...@@ -449,38 +425,22 @@ static int ks8995_probe(struct spi_device *spi)
ks->spi = spi; ks->spi = spi;
ks->chip = &ks8995_chip[variant]; ks->chip = &ks8995_chip[variant];
if (ks->spi->dev.of_node) { ks->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset",
ks->pdata = devm_kzalloc(&spi->dev, sizeof(*ks->pdata), GPIOD_OUT_HIGH);
GFP_KERNEL); err = PTR_ERR_OR_ZERO(ks->reset_gpio);
if (!ks->pdata) if (err) {
return -ENOMEM; dev_err(&spi->dev,
"failed to get reset gpio: %d\n", err);
ks->pdata->reset_gpio = -1; return err;
ks8995_parse_dt(ks);
} }
if (!ks->pdata) err = gpiod_set_consumer_name(ks->reset_gpio, "switch-reset");
ks->pdata = spi->dev.platform_data; if (err)
return err;
/* de-assert switch reset */ /* de-assert switch reset */
if (ks->pdata && gpio_is_valid(ks->pdata->reset_gpio)) { /* FIXME: this likely requires a delay */
unsigned long flags; gpiod_set_value_cansleep(ks->reset_gpio, 0);
flags = (ks->pdata->reset_gpio_flags == OF_GPIO_ACTIVE_LOW ?
GPIOF_ACTIVE_LOW : 0);
err = devm_gpio_request_one(&spi->dev,
ks->pdata->reset_gpio,
flags, "switch-reset");
if (err) {
dev_err(&spi->dev,
"failed to get reset-gpios: %d\n", err);
return -EIO;
}
gpiod_set_value(gpio_to_desc(ks->pdata->reset_gpio), 0);
}
spi_set_drvdata(spi, ks); spi_set_drvdata(spi, ks);
...@@ -524,8 +484,7 @@ static void ks8995_remove(struct spi_device *spi) ...@@ -524,8 +484,7 @@ static void ks8995_remove(struct spi_device *spi)
sysfs_remove_bin_file(&spi->dev.kobj, &ks->regs_attr); sysfs_remove_bin_file(&spi->dev.kobj, &ks->regs_attr);
/* assert reset */ /* assert reset */
if (ks->pdata && gpio_is_valid(ks->pdata->reset_gpio)) gpiod_set_value_cansleep(ks->reset_gpio, 1);
gpiod_set_value(gpio_to_desc(ks->pdata->reset_gpio), 1);
} }
/* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */
......
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