#undef PER_BIT_READ
struct ar71xx_spi {
- struct spi_bitbang bitbang;
+ struct spi_bitbang bitbang;
u32 ioc_base;
u32 reg_ctrl;
- void __iomem *base;
+ void __iomem *base;
struct platform_device *pdev;
};
}
-static int pb44_spi_setup_cs(struct spi_device *spi)
+static void pb44_spi_enable(struct ar71xx_spi *sp)
{
- struct ar71xx_spi *sp = spidev_to_sp(spi);
-
/* enable GPIO mode */
pb44_spi_wr(sp, SPI_REG_FS, SPI_FS_GPIO);
sp->reg_ctrl = pb44_spi_rr(sp, SPI_REG_CTRL);
sp->ioc_base = pb44_spi_rr(sp, SPI_REG_IOC);
- /* TODO: setup speed? */
pb44_spi_wr(sp, SPI_REG_CTRL, 0x43);
+}
+
+static void pb44_spi_disable(struct ar71xx_spi *sp)
+{
+ /* restore CTRL register */
+ pb44_spi_wr(sp, SPI_REG_CTRL, sp->reg_ctrl);
+ /* disable GPIO mode */
+ pb44_spi_wr(sp, SPI_REG_FS, 0);
+}
+
+static int pb44_spi_setup_cs(struct spi_device *spi)
+{
+ struct ar71xx_spi *sp = spidev_to_sp(spi);
if (spi->chip_select) {
unsigned long gpio = (unsigned long) spi->controller_data;
static void pb44_spi_cleanup_cs(struct spi_device *spi)
{
- struct ar71xx_spi *sp = spidev_to_sp(spi);
-
if (spi->chip_select) {
unsigned long gpio = (unsigned long) spi->controller_data;
gpio_free(gpio);
}
-
- /* restore CTRL register */
- pb44_spi_wr(sp, SPI_REG_CTRL, sp->reg_ctrl);
- /* disable GPIO mode */
- pb44_spi_wr(sp, SPI_REG_FS, 0);
}
static int pb44_spi_setup(struct spi_device *spi)
goto err1;
}
+ pb44_spi_enable(sp);
+
ret = spi_bitbang_start(&sp->bitbang);
if (!ret)
return 0;
+ pb44_spi_disable(sp);
iounmap(sp->base);
- err1:
+err1:
platform_set_drvdata(pdev, NULL);
spi_master_put(sp->bitbang.master);
struct ar71xx_spi *sp = platform_get_drvdata(pdev);
spi_bitbang_stop(&sp->bitbang);
+ pb44_spi_disable(sp);
iounmap(sp->base);
platform_set_drvdata(pdev, NULL);
spi_master_put(sp->bitbang.master);
return 0;
}
+static void pb44_spi_shutdown(struct platform_device *pdev)
+{
+ int ret;
+
+ ret = pb44_spi_remove(pdev);
+ if (ret)
+ dev_err(&pdev->dev, "shutdown failed with %d\n", ret);
+}
+
static struct platform_driver pb44_spi_drv = {
.probe = pb44_spi_probe,
.remove = pb44_spi_remove,
+ .shutdown = pb44_spi_shutdown,
.driver = {
.name = DRV_NAME,
.owner = THIS_MODULE,