summaryrefslogtreecommitdiff
path: root/drivers/spi/spi-mpc52xx.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/spi/spi-mpc52xx.c')
-rw-r--r--drivers/spi/spi-mpc52xx.c106
1 files changed, 52 insertions, 54 deletions
diff --git a/drivers/spi/spi-mpc52xx.c b/drivers/spi/spi-mpc52xx.c
index 51041526546d..6d4dde15ac54 100644
--- a/drivers/spi/spi-mpc52xx.c
+++ b/drivers/spi/spi-mpc52xx.c
@@ -11,14 +11,19 @@
*/
#include <linux/module.h>
+#include <linux/err.h>
#include <linux/errno.h>
#include <linux/of_platform.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
+#include <linux/gpio/consumer.h>
#include <linux/spi/spi.h>
#include <linux/io.h>
-#include <linux/of_gpio.h>
#include <linux/slab.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
+#include <linux/platform_device.h>
+
#include <asm/time.h>
#include <asm/mpc52xx.h>
@@ -58,7 +63,7 @@ MODULE_LICENSE("GPL");
/* Driver internal data */
struct mpc52xx_spi {
- struct spi_master *master;
+ struct spi_controller *host;
void __iomem *regs;
int irq0; /* MODF irq */
int irq1; /* SPIF irq */
@@ -86,7 +91,7 @@ struct mpc52xx_spi {
const u8 *tx_buf;
int cs_change;
int gpio_cs_count;
- unsigned int *gpio_cs;
+ struct gpio_desc **gpio_cs;
};
/*
@@ -97,10 +102,11 @@ static void mpc52xx_spi_chipsel(struct mpc52xx_spi *ms, int value)
int cs;
if (ms->gpio_cs_count > 0) {
- cs = ms->message->spi->chip_select;
- gpio_set_value(ms->gpio_cs[cs], value ? 0 : 1);
- } else
+ cs = spi_get_chipselect(ms->message->spi, 0);
+ gpiod_set_value(ms->gpio_cs[cs], value);
+ } else {
out_8(ms->regs + SPI_PORTDATA, value ? 0 : 0x08);
+ }
}
/*
@@ -146,8 +152,8 @@ mpc52xx_spi_fsmstate_idle(int irq, struct mpc52xx_spi *ms, u8 status, u8 data)
int spr, sppr;
u8 ctrl1;
- if (status && (irq != NO_IRQ))
- dev_err(&ms->master->dev, "spurious irq, status=0x%.2x\n",
+ if (status && irq)
+ dev_err(&ms->host->dev, "spurious irq, status=0x%.2x\n",
status);
/* Check if there is another transfer waiting. */
@@ -230,7 +236,7 @@ static int mpc52xx_spi_fsmstate_transfer(int irq, struct mpc52xx_spi *ms,
return FSM_CONTINUE;
} else if (status & SPI_STATUS_MODF) {
ms->modf_count++;
- dev_err(&ms->master->dev, "mode fault\n");
+ dev_err(&ms->host->dev, "mode fault\n");
mpc52xx_spi_chipsel(ms, 0);
ms->message->status = -EIO;
if (ms->message->complete)
@@ -275,7 +281,7 @@ static int
mpc52xx_spi_fsmstate_wait(int irq, struct mpc52xx_spi *ms, u8 status, u8 data)
{
if (status && irq)
- dev_err(&ms->master->dev, "spurious irq, status=0x%.2x\n",
+ dev_err(&ms->host->dev, "spurious irq, status=0x%.2x\n",
status);
if (((int)mftb()) - ms->timestamp < 0)
@@ -356,12 +362,12 @@ static void mpc52xx_spi_wq(struct work_struct *work)
}
/*
- * spi_master ops
+ * spi_controller ops
*/
static int mpc52xx_spi_transfer(struct spi_device *spi, struct spi_message *m)
{
- struct mpc52xx_spi *ms = spi_master_get_devdata(spi->master);
+ struct mpc52xx_spi *ms = spi_controller_get_devdata(spi->controller);
unsigned long flags;
m->actual_length = 0;
@@ -380,12 +386,12 @@ static int mpc52xx_spi_transfer(struct spi_device *spi, struct spi_message *m)
*/
static int mpc52xx_spi_probe(struct platform_device *op)
{
- struct spi_master *master;
+ struct spi_controller *host;
struct mpc52xx_spi *ms;
+ struct gpio_desc *gpio_cs;
void __iomem *regs;
u8 ctrl1;
int rc, i = 0;
- int gpio_cs;
/* MMIO registers */
dev_dbg(&op->dev, "probing mpc5200 SPI device\n");
@@ -401,7 +407,7 @@ static int mpc52xx_spi_probe(struct platform_device *op)
out_8(regs + SPI_PORTDATA, 0x8); /* Deassert /SS signal */
/* Clear the status register and re-read it to check for a MODF
- * failure. This driver cannot currently handle multiple masters
+ * failure. This driver cannot currently handle multiple hosts
* on the SPI bus. This fault will also occur if the SPI signals
* are not connected to any pins (port_config setting) */
in_8(regs + SPI_STATUS);
@@ -414,30 +420,30 @@ static int mpc52xx_spi_probe(struct platform_device *op)
goto err_init;
}
- dev_dbg(&op->dev, "allocating spi_master struct\n");
- master = spi_alloc_master(&op->dev, sizeof(*ms));
- if (!master) {
+ dev_dbg(&op->dev, "allocating spi_controller struct\n");
+ host = spi_alloc_host(&op->dev, sizeof(*ms));
+ if (!host) {
rc = -ENOMEM;
goto err_alloc;
}
- master->transfer = mpc52xx_spi_transfer;
- master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST;
- master->bits_per_word_mask = SPI_BPW_MASK(8);
- master->dev.of_node = op->dev.of_node;
+ host->transfer = mpc52xx_spi_transfer;
+ host->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST;
+ host->bits_per_word_mask = SPI_BPW_MASK(8);
+ host->dev.of_node = op->dev.of_node;
- platform_set_drvdata(op, master);
+ platform_set_drvdata(op, host);
- ms = spi_master_get_devdata(master);
- ms->master = master;
+ ms = spi_controller_get_devdata(host);
+ ms->host = host;
ms->regs = regs;
ms->irq0 = irq_of_parse_and_map(op->dev.of_node, 0);
ms->irq1 = irq_of_parse_and_map(op->dev.of_node, 1);
ms->state = mpc52xx_spi_fsmstate_idle;
- ms->ipb_freq = mpc5xxx_get_bus_frequency(op->dev.of_node);
- ms->gpio_cs_count = of_gpio_count(op->dev.of_node);
+ ms->ipb_freq = mpc5xxx_get_bus_frequency(&op->dev);
+ ms->gpio_cs_count = gpiod_count(&op->dev, NULL);
if (ms->gpio_cs_count > 0) {
- master->num_chipselect = ms->gpio_cs_count;
+ host->num_chipselect = ms->gpio_cs_count;
ms->gpio_cs = kmalloc_array(ms->gpio_cs_count,
sizeof(*ms->gpio_cs),
GFP_KERNEL);
@@ -447,23 +453,16 @@ static int mpc52xx_spi_probe(struct platform_device *op)
}
for (i = 0; i < ms->gpio_cs_count; i++) {
- gpio_cs = of_get_gpio(op->dev.of_node, i);
- if (!gpio_is_valid(gpio_cs)) {
- dev_err(&op->dev,
- "could not parse the gpio field in oftree\n");
- rc = -ENODEV;
- goto err_gpio;
- }
-
- rc = gpio_request(gpio_cs, dev_name(&op->dev));
+ gpio_cs = gpiod_get_index(&op->dev,
+ NULL, i, GPIOD_OUT_LOW);
+ rc = PTR_ERR_OR_ZERO(gpio_cs);
if (rc) {
dev_err(&op->dev,
- "can't request spi cs gpio #%d on gpio line %d\n",
- i, gpio_cs);
+ "failed to get spi cs gpio #%d: %d\n",
+ i, rc);
goto err_gpio;
}
- gpio_direction_output(gpio_cs, 1);
ms->gpio_cs[i] = gpio_cs;
}
}
@@ -491,48 +490,47 @@ static int mpc52xx_spi_probe(struct platform_device *op)
if (!ms->irq0)
dev_info(&op->dev, "using polled mode\n");
- dev_dbg(&op->dev, "registering spi_master struct\n");
- rc = spi_register_master(master);
+ dev_dbg(&op->dev, "registering spi_controller struct\n");
+ rc = spi_register_controller(host);
if (rc)
goto err_register;
- dev_info(&ms->master->dev, "registered MPC5200 SPI bus\n");
+ dev_info(&ms->host->dev, "registered MPC5200 SPI bus\n");
return rc;
err_register:
- dev_err(&ms->master->dev, "initialization failed\n");
+ dev_err(&ms->host->dev, "initialization failed\n");
err_gpio:
while (i-- > 0)
- gpio_free(ms->gpio_cs[i]);
+ gpiod_put(ms->gpio_cs[i]);
kfree(ms->gpio_cs);
err_alloc_gpio:
- spi_master_put(master);
+ spi_controller_put(host);
err_alloc:
err_init:
iounmap(regs);
return rc;
}
-static int mpc52xx_spi_remove(struct platform_device *op)
+static void mpc52xx_spi_remove(struct platform_device *op)
{
- struct spi_master *master = spi_master_get(platform_get_drvdata(op));
- struct mpc52xx_spi *ms = spi_master_get_devdata(master);
+ struct spi_controller *host = spi_controller_get(platform_get_drvdata(op));
+ struct mpc52xx_spi *ms = spi_controller_get_devdata(host);
int i;
+ cancel_work_sync(&ms->work);
free_irq(ms->irq0, ms);
free_irq(ms->irq1, ms);
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);
- spi_unregister_master(master);
+ spi_unregister_controller(host);
iounmap(ms->regs);
- spi_master_put(master);
-
- return 0;
+ spi_controller_put(host);
}
static const struct of_device_id mpc52xx_spi_match[] = {