Commit 86e98743 authored by Anatolij Gustschin's avatar Anatolij Gustschin Committed by Mark Brown

spi: spi-mpc512x-psc: add support for gpio chip selects

Currently the driver only uses one internal chip select.
Add support for gpio chip selects configured by cs-gpios
DT binding.
Signed-off-by: default avatarAnatolij Gustschin <agust@denx.de>
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent ab300d18
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#include <linux/fsl_devices.h> #include <linux/fsl_devices.h>
#include <linux/gpio.h>
#include <asm/mpc52xx_psc.h> #include <asm/mpc52xx_psc.h>
struct mpc512x_psc_spi { struct mpc512x_psc_spi {
...@@ -113,7 +114,7 @@ static void mpc512x_psc_spi_activate_cs(struct spi_device *spi) ...@@ -113,7 +114,7 @@ static void mpc512x_psc_spi_activate_cs(struct spi_device *spi)
out_be32(&psc->ccr, ccr); out_be32(&psc->ccr, ccr);
mps->bits_per_word = cs->bits_per_word; mps->bits_per_word = cs->bits_per_word;
if (mps->cs_control) if (mps->cs_control && gpio_is_valid(spi->cs_gpio))
mps->cs_control(spi, (spi->mode & SPI_CS_HIGH) ? 1 : 0); mps->cs_control(spi, (spi->mode & SPI_CS_HIGH) ? 1 : 0);
} }
...@@ -121,7 +122,7 @@ static void mpc512x_psc_spi_deactivate_cs(struct spi_device *spi) ...@@ -121,7 +122,7 @@ static void mpc512x_psc_spi_deactivate_cs(struct spi_device *spi)
{ {
struct mpc512x_psc_spi *mps = spi_master_get_devdata(spi->master); struct mpc512x_psc_spi *mps = spi_master_get_devdata(spi->master);
if (mps->cs_control) if (mps->cs_control && gpio_is_valid(spi->cs_gpio))
mps->cs_control(spi, (spi->mode & SPI_CS_HIGH) ? 0 : 1); mps->cs_control(spi, (spi->mode & SPI_CS_HIGH) ? 0 : 1);
} }
...@@ -278,6 +279,7 @@ static int mpc512x_psc_spi_setup(struct spi_device *spi) ...@@ -278,6 +279,7 @@ static int mpc512x_psc_spi_setup(struct spi_device *spi)
struct mpc512x_psc_spi *mps = spi_master_get_devdata(spi->master); struct mpc512x_psc_spi *mps = spi_master_get_devdata(spi->master);
struct mpc512x_psc_spi_cs *cs = spi->controller_state; struct mpc512x_psc_spi_cs *cs = spi->controller_state;
unsigned long flags; unsigned long flags;
int ret;
if (spi->bits_per_word % 8) if (spi->bits_per_word % 8)
return -EINVAL; return -EINVAL;
...@@ -286,6 +288,19 @@ static int mpc512x_psc_spi_setup(struct spi_device *spi) ...@@ -286,6 +288,19 @@ static int mpc512x_psc_spi_setup(struct spi_device *spi)
cs = kzalloc(sizeof *cs, GFP_KERNEL); cs = kzalloc(sizeof *cs, GFP_KERNEL);
if (!cs) if (!cs)
return -ENOMEM; return -ENOMEM;
if (gpio_is_valid(spi->cs_gpio)) {
ret = gpio_request(spi->cs_gpio, dev_name(&spi->dev));
if (ret) {
dev_err(&spi->dev, "can't get CS gpio: %d\n",
ret);
kfree(cs);
return ret;
}
gpio_direction_output(spi->cs_gpio,
spi->mode & SPI_CS_HIGH ? 0 : 1);
}
spi->controller_state = cs; spi->controller_state = cs;
} }
...@@ -319,6 +334,8 @@ static int mpc512x_psc_spi_transfer(struct spi_device *spi, ...@@ -319,6 +334,8 @@ static int mpc512x_psc_spi_transfer(struct spi_device *spi,
static void mpc512x_psc_spi_cleanup(struct spi_device *spi) static void mpc512x_psc_spi_cleanup(struct spi_device *spi)
{ {
if (gpio_is_valid(spi->cs_gpio))
gpio_free(spi->cs_gpio);
kfree(spi->controller_state); kfree(spi->controller_state);
} }
...@@ -405,6 +422,11 @@ static irqreturn_t mpc512x_psc_spi_isr(int irq, void *dev_id) ...@@ -405,6 +422,11 @@ static irqreturn_t mpc512x_psc_spi_isr(int irq, void *dev_id)
return IRQ_NONE; return IRQ_NONE;
} }
static void mpc512x_spi_cs_control(struct spi_device *spi, bool onoff)
{
gpio_set_value(spi->cs_gpio, onoff);
}
/* bus_num is used only for the case dev->platform_data == NULL */ /* bus_num is used only for the case dev->platform_data == NULL */
static int mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr, static int mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr,
u32 size, unsigned int irq, u32 size, unsigned int irq,
...@@ -425,12 +447,9 @@ static int mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr, ...@@ -425,12 +447,9 @@ static int mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr,
mps->irq = irq; mps->irq = irq;
if (pdata == NULL) { if (pdata == NULL) {
dev_err(dev, "probe called without platform data, no " mps->cs_control = mpc512x_spi_cs_control;
"cs_control function will be called\n");
mps->cs_control = NULL;
mps->sysclk = 0; mps->sysclk = 0;
master->bus_num = bus_num; master->bus_num = bus_num;
master->num_chipselect = 255;
} else { } else {
mps->cs_control = pdata->cs_control; mps->cs_control = pdata->cs_control;
mps->sysclk = pdata->sysclk; mps->sysclk = pdata->sysclk;
......
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