ar71xx: Add kernel 4.9 support
[openwrt/staging/mkresin.git] / target / linux / ar71xx / files / drivers / spi / spi-rb4xx-cpld.c
index 4e8ce310500ab0f707a8bebef2cf55184ff1a554..18af83b67c85892d5f0dc1a47b1cc95bdac1dc72 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/spi/spi.h>
 #include <linux/gpio.h>
 #include <linux/slab.h>
+#include <linux/version.h>
 
 #include <asm/mach-ath79/rb4xx_cpld.h>
 
@@ -131,73 +132,7 @@ int rb4xx_cpld_change_cfg(unsigned mask, unsigned value)
 }
 EXPORT_SYMBOL_GPL(rb4xx_cpld_change_cfg);
 
-int rb4xx_cpld_read_from(unsigned addr, unsigned char *rx_buf,
-                        const unsigned char *verify_buf, unsigned count)
-{
-       const unsigned char cmd[5] = {
-               CPLD_CMD_READ_FAST,
-               (addr >> 16) & 0xff,
-               (addr >> 8) & 0xff,
-                addr & 0xff,
-                0
-       };
-       struct spi_transfer t[2] = {
-               {
-                       .tx_buf = &cmd,
-                       .len = 5,
-               },
-               {
-                       .tx_buf = verify_buf,
-                       .rx_buf = rx_buf,
-                       .len = count,
-                       .verify = (verify_buf != NULL),
-               },
-       };
-       struct spi_message m;
-
-       if (rb4xx_cpld == NULL)
-               return -ENODEV;
-
-       spi_message_init(&m);
-       m.fast_read = 1;
-       spi_message_add_tail(&t[0], &m);
-       spi_message_add_tail(&t[1], &m);
-       return spi_sync(rb4xx_cpld->spi, &m);
-}
-EXPORT_SYMBOL_GPL(rb4xx_cpld_read_from);
-
-#if 0
-int rb4xx_cpld_read(unsigned char *buf, unsigned char *verify_buf,
-                   unsigned count)
-{
-       struct spi_transfer t[2];
-       struct spi_message m;
-       unsigned char cmd[2];
-
-       if (rb4xx_cpld == NULL)
-               return -ENODEV;
-
-       spi_message_init(&m);
-       memset(&t, 0, sizeof(t));
-
-       /* send command */
-       t[0].tx_buf = cmd;
-       t[0].len = sizeof(cmd);
-       spi_message_add_tail(&t[0], &m);
-
-       cmd[0] = CPLD_CMD_READ_NAND;
-       cmd[1] = 0;
-
-       /* read data */
-       t[1].rx_buf = buf;
-       t[1].len = count;
-       spi_message_add_tail(&t[1], &m);
-
-       return spi_sync(rb4xx_cpld->spi, &m);
-}
-#else
-int rb4xx_cpld_read(unsigned char *rx_buf, const unsigned char *verify_buf,
-                   unsigned count)
+int rb4xx_cpld_read(unsigned char *rx_buf, unsigned count)
 {
        static const unsigned char cmd[2] = { CPLD_CMD_READ_NAND, 0 };
        struct spi_transfer t[2] = {
@@ -205,10 +140,8 @@ int rb4xx_cpld_read(unsigned char *rx_buf, const unsigned char *verify_buf,
                        .tx_buf = &cmd,
                        .len = 2,
                }, {
-                       .tx_buf = verify_buf,
                        .rx_buf = rx_buf,
                        .len = count,
-                       .verify = (verify_buf != NULL),
                },
        };
        struct spi_message m;
@@ -221,40 +154,10 @@ int rb4xx_cpld_read(unsigned char *rx_buf, const unsigned char *verify_buf,
        spi_message_add_tail(&t[1], &m);
        return spi_sync(rb4xx_cpld->spi, &m);
 }
-#endif
 EXPORT_SYMBOL_GPL(rb4xx_cpld_read);
 
 int rb4xx_cpld_write(const unsigned char *buf, unsigned count)
 {
-#if 0
-       struct spi_transfer t[3];
-       struct spi_message m;
-       unsigned char cmd[1];
-
-       if (rb4xx_cpld == NULL)
-               return -ENODEV;
-
-       memset(&t, 0, sizeof(t));
-       spi_message_init(&m);
-
-       /* send command */
-       t[0].tx_buf = cmd;
-       t[0].len = sizeof(cmd);
-       spi_message_add_tail(&t[0], &m);
-
-       cmd[0] = CPLD_CMD_WRITE_NAND;
-
-       /* write data */
-       t[1].tx_buf = buf;
-       t[1].len = count;
-       spi_message_add_tail(&t[1], &m);
-
-       /* send idle */
-       t[2].len = 1;
-       spi_message_add_tail(&t[2], &m);
-
-       return spi_sync(rb4xx_cpld->spi, &m);
-#else
        static const unsigned char cmd = CPLD_CMD_WRITE_NAND;
        struct spi_transfer t[3] = {
                {
@@ -263,10 +166,10 @@ int rb4xx_cpld_write(const unsigned char *buf, unsigned count)
                }, {
                        .tx_buf = buf,
                        .len = count,
-                       .fast_write = 1,
+                       .tx_nbits = SPI_NBITS_DUAL,
                }, {
                        .len = 1,
-                       .fast_write = 1,
+                       .tx_nbits = SPI_NBITS_DUAL,
                },
        };
        struct spi_message m;
@@ -279,7 +182,6 @@ int rb4xx_cpld_write(const unsigned char *buf, unsigned count)
        spi_message_add_tail(&t[1], &m);
        spi_message_add_tail(&t[2], &m);
        return spi_sync(rb4xx_cpld->spi, &m);
-#endif
 }
 EXPORT_SYMBOL_GPL(rb4xx_cpld_write);
 
@@ -345,7 +247,11 @@ static int rb4xx_cpld_gpio_init(struct rb4xx_cpld *cpld, unsigned int base)
        cpld->chip.base = base;
        cpld->chip.ngpio = CPLD_NUM_GPIOS;
        cpld->chip.can_sleep = 1;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,5,0)
        cpld->chip.dev = &cpld->spi->dev;
+#else
+       cpld->chip.parent = &cpld->spi->dev;
+#endif
        cpld->chip.owner = THIS_MODULE;
 
        err = gpiochip_add(&cpld->chip);
@@ -356,7 +262,7 @@ static int rb4xx_cpld_gpio_init(struct rb4xx_cpld *cpld, unsigned int base)
        return err;
 }
 
-static int __devinit rb4xx_cpld_probe(struct spi_device *spi)
+static int rb4xx_cpld_probe(struct spi_device *spi)
 {
        struct rb4xx_cpld *cpld;
        struct rb4xx_cpld_platform_data *pdata;
@@ -378,7 +284,7 @@ static int __devinit rb4xx_cpld_probe(struct spi_device *spi)
        cpld->spi = spi_dev_get(spi);
        dev_set_drvdata(&spi->dev, cpld);
 
-       spi->mode = SPI_MODE_0;
+       spi->mode = SPI_MODE_0 | SPI_TX_DUAL;
        spi->bits_per_word = 8;
        err = spi_setup(spi);
        if (err) {
@@ -401,7 +307,7 @@ err_drvdata:
        return err;
 }
 
-static int __devexit rb4xx_cpld_remove(struct spi_device *spi)
+static int rb4xx_cpld_remove(struct spi_device *spi)
 {
        struct rb4xx_cpld *cpld;
 
@@ -420,7 +326,7 @@ static struct spi_driver rb4xx_cpld_driver = {
                .owner          = THIS_MODULE,
        },
        .probe          = rb4xx_cpld_probe,
-       .remove         = __devexit_p(rb4xx_cpld_remove),
+       .remove         = rb4xx_cpld_remove,
 };
 
 static int __init rb4xx_cpld_init(void)