ar71xx: build ALFA AP96 images with default profile as well
[openwrt.git] / target / linux / ar71xx / files / drivers / spi / pb44_spi.c
index ee52099..556c771 100644 (file)
@@ -86,10 +86,8 @@ static void pb44_spi_chipselect(struct spi_device *spi, int is_active)
 
 }
 
-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);
 
@@ -97,8 +95,20 @@ static int pb44_spi_setup_cs(struct spi_device *spi)
        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;
@@ -126,17 +136,10 @@ static int pb44_spi_setup_cs(struct spi_device *spi)
 
 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)
@@ -247,10 +250,13 @@ static int pb44_spi_probe(struct platform_device *pdev)
                goto err1;
        }
 
+       pb44_spi_enable(sp);
+
        ret = spi_bitbang_start(&sp->bitbang);
        if (!ret)
                return 0;
 
+       pb44_spi_disable(sp);
        iounmap(sp->base);
 err1:
        platform_set_drvdata(pdev, NULL);
@@ -264,6 +270,7 @@ static int pb44_spi_remove(struct platform_device *pdev)
        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);
@@ -271,9 +278,19 @@ static int pb44_spi_remove(struct platform_device *pdev)
        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,