mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-09-18 22:14:16 +00:00
spi: spi-mpc52xx: switch to using gpiod API
This switches the driver to use gpiod API instead of legacy gpio API, which will brings us close to removing of_get_gpio() and other OF-specific old APIs. No functional change intended beyond some differences in error messages. Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://lore.kernel.org/r/Yy07WbMAG4bPgYNd@google.com Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
9671847f93
commit
2f3a896b0a
1 changed files with 13 additions and 19 deletions
|
@ -11,6 +11,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
|
#include <linux/err.h>
|
||||||
#include <linux/errno.h>
|
#include <linux/errno.h>
|
||||||
#include <linux/of_platform.h>
|
#include <linux/of_platform.h>
|
||||||
#include <linux/interrupt.h>
|
#include <linux/interrupt.h>
|
||||||
|
@ -18,7 +19,6 @@
|
||||||
#include <linux/gpio/consumer.h>
|
#include <linux/gpio/consumer.h>
|
||||||
#include <linux/spi/spi.h>
|
#include <linux/spi/spi.h>
|
||||||
#include <linux/io.h>
|
#include <linux/io.h>
|
||||||
#include <linux/of_gpio.h>
|
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
#include <linux/of_address.h>
|
#include <linux/of_address.h>
|
||||||
#include <linux/of_irq.h>
|
#include <linux/of_irq.h>
|
||||||
|
@ -90,7 +90,7 @@ struct mpc52xx_spi {
|
||||||
const u8 *tx_buf;
|
const u8 *tx_buf;
|
||||||
int cs_change;
|
int cs_change;
|
||||||
int gpio_cs_count;
|
int gpio_cs_count;
|
||||||
unsigned int *gpio_cs;
|
struct gpio_desc **gpio_cs;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -102,10 +102,11 @@ static void mpc52xx_spi_chipsel(struct mpc52xx_spi *ms, int value)
|
||||||
|
|
||||||
if (ms->gpio_cs_count > 0) {
|
if (ms->gpio_cs_count > 0) {
|
||||||
cs = ms->message->spi->chip_select;
|
cs = ms->message->spi->chip_select;
|
||||||
gpio_set_value(ms->gpio_cs[cs], value ? 0 : 1);
|
gpiod_set_value(ms->gpio_cs[cs], value);
|
||||||
} else
|
} else {
|
||||||
out_8(ms->regs + SPI_PORTDATA, value ? 0 : 0x08);
|
out_8(ms->regs + SPI_PORTDATA, value ? 0 : 0x08);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Start a new transfer. This is called both by the idle state
|
* Start a new transfer. This is called both by the idle state
|
||||||
|
@ -386,10 +387,10 @@ static int mpc52xx_spi_probe(struct platform_device *op)
|
||||||
{
|
{
|
||||||
struct spi_master *master;
|
struct spi_master *master;
|
||||||
struct mpc52xx_spi *ms;
|
struct mpc52xx_spi *ms;
|
||||||
|
struct gpio_desc *gpio_cs;
|
||||||
void __iomem *regs;
|
void __iomem *regs;
|
||||||
u8 ctrl1;
|
u8 ctrl1;
|
||||||
int rc, i = 0;
|
int rc, i = 0;
|
||||||
int gpio_cs;
|
|
||||||
|
|
||||||
/* MMIO registers */
|
/* MMIO registers */
|
||||||
dev_dbg(&op->dev, "probing mpc5200 SPI device\n");
|
dev_dbg(&op->dev, "probing mpc5200 SPI device\n");
|
||||||
|
@ -451,23 +452,16 @@ static int mpc52xx_spi_probe(struct platform_device *op)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < ms->gpio_cs_count; i++) {
|
for (i = 0; i < ms->gpio_cs_count; i++) {
|
||||||
gpio_cs = of_get_gpio(op->dev.of_node, i);
|
gpio_cs = gpiod_get_index(&op->dev,
|
||||||
if (!gpio_is_valid(gpio_cs)) {
|
NULL, i, GPIOD_OUT_LOW);
|
||||||
dev_err(&op->dev,
|
rc = PTR_ERR_OR_ZERO(gpio_cs);
|
||||||
"could not parse the gpio field in oftree\n");
|
|
||||||
rc = -ENODEV;
|
|
||||||
goto err_gpio;
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = gpio_request(gpio_cs, dev_name(&op->dev));
|
|
||||||
if (rc) {
|
if (rc) {
|
||||||
dev_err(&op->dev,
|
dev_err(&op->dev,
|
||||||
"can't request spi cs gpio #%d on gpio line %d\n",
|
"failed to get spi cs gpio #%d: %d\n",
|
||||||
i, gpio_cs);
|
i, rc);
|
||||||
goto err_gpio;
|
goto err_gpio;
|
||||||
}
|
}
|
||||||
|
|
||||||
gpio_direction_output(gpio_cs, 1);
|
|
||||||
ms->gpio_cs[i] = gpio_cs;
|
ms->gpio_cs[i] = gpio_cs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -508,7 +502,7 @@ static int mpc52xx_spi_probe(struct platform_device *op)
|
||||||
dev_err(&ms->master->dev, "initialization failed\n");
|
dev_err(&ms->master->dev, "initialization failed\n");
|
||||||
err_gpio:
|
err_gpio:
|
||||||
while (i-- > 0)
|
while (i-- > 0)
|
||||||
gpio_free(ms->gpio_cs[i]);
|
gpiod_put(ms->gpio_cs[i]);
|
||||||
|
|
||||||
kfree(ms->gpio_cs);
|
kfree(ms->gpio_cs);
|
||||||
err_alloc_gpio:
|
err_alloc_gpio:
|
||||||
|
@ -529,7 +523,7 @@ static int mpc52xx_spi_remove(struct platform_device *op)
|
||||||
free_irq(ms->irq1, ms);
|
free_irq(ms->irq1, ms);
|
||||||
|
|
||||||
for (i = 0; i < ms->gpio_cs_count; i++)
|
for (i = 0; i < ms->gpio_cs_count; i++)
|
||||||
gpio_free(ms->gpio_cs[i]);
|
gpiod_put(ms->gpio_cs[i]);
|
||||||
|
|
||||||
kfree(ms->gpio_cs);
|
kfree(ms->gpio_cs);
|
||||||
spi_unregister_master(master);
|
spi_unregister_master(master);
|
||||||
|
|
Loading…
Add table
Reference in a new issue