Re: [U-Boot] [PATCH 2/2] spi: add common spi3 controller driver

2014-12-02 Thread Jagan Teki
On 18 November 2014 at 14:28, Scott Jiang scott.jiang.li...@gmail.com wrote:
 2014-11-17 3:23 GMT+08:00 Jagan Teki jagannadh.t...@gmail.com:
 Hi Scott,

 On 25 September 2014 14:55, Scott Jiang scott.jiang.li...@gmail.com wrote:
 SPI3 controller is not only used on BF609 platform. So we add a common 
 controller
 driver and leave machine specific configuration in board drivers.
 Remove obsolete spi6xx.h and select new board driver in configuration file.

 Signed-off-by: Scott Jiang scott.jiang.li...@gmail.com
 ---
  drivers/spi/Makefile   |1 +
  drivers/spi/adi_spi3.c |  222 

 I think adi_spi3.c is a copy of bfin_spi6xx.c with excluded-ed stuff of bf609

 And also the difference is of chipselect and slave setup handling, why can't
 we use same driver my making this difference stuff in particular macro.

 Please try in that sense, It's not looking good to have one driver
 file with only
 having chip selct handing and slave setup.


 Would you mind moving spi_cs_is_valid() to arch/xx/include/asm/mach-xxx/spi.h?
 Because the number of spi controllers and the cs number of each controller 
 might
 be different for different board. It use macros to do this before,
 while it's more difficult
 as boards become more.

IMHO, it's not a good idea to move the driver stuff to arc/xx/include
I do understand that
the this logic is more designed towards specific board.

Solutions on my mind:
- try to use dm
- then make a cs logic and get the attributes from the dts.

thanks!
-- 
Jagan.
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 2/2] spi: add common spi3 controller driver

2014-11-18 Thread Scott Jiang
2014-11-17 3:23 GMT+08:00 Jagan Teki jagannadh.t...@gmail.com:
 Hi Scott,

 On 25 September 2014 14:55, Scott Jiang scott.jiang.li...@gmail.com wrote:
 SPI3 controller is not only used on BF609 platform. So we add a common 
 controller
 driver and leave machine specific configuration in board drivers.
 Remove obsolete spi6xx.h and select new board driver in configuration file.

 Signed-off-by: Scott Jiang scott.jiang.li...@gmail.com
 ---
  drivers/spi/Makefile   |1 +
  drivers/spi/adi_spi3.c |  222 

 I think adi_spi3.c is a copy of bfin_spi6xx.c with excluded-ed stuff of bf609

 And also the difference is of chipselect and slave setup handling, why can't
 we use same driver my making this difference stuff in particular macro.

 Please try in that sense, It's not looking good to have one driver
 file with only
 having chip selct handing and slave setup.


Would you mind moving spi_cs_is_valid() to arch/xx/include/asm/mach-xxx/spi.h?
Because the number of spi controllers and the cs number of each controller might
be different for different board. It use macros to do this before,
while it's more difficult
as boards become more.

Scott
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 2/2] spi: add common spi3 controller driver

2014-11-16 Thread Jagan Teki
Hi Scott,

On 25 September 2014 14:55, Scott Jiang scott.jiang.li...@gmail.com wrote:
 SPI3 controller is not only used on BF609 platform. So we add a common 
 controller
 driver and leave machine specific configuration in board drivers.
 Remove obsolete spi6xx.h and select new board driver in configuration file.

 Signed-off-by: Scott Jiang scott.jiang.li...@gmail.com
 ---
  drivers/spi/Makefile   |1 +
  drivers/spi/adi_spi3.c |  222 

I think adi_spi3.c is a copy of bfin_spi6xx.c with excluded-ed stuff of bf609

And also the difference is of chipselect and slave setup handling, why can't
we use same driver my making this difference stuff in particular macro.

Please try in that sense, It's not looking good to have one driver
file with only
having chip selct handing and slave setup.

  .../bits/spi6xx.h = drivers/spi/adi_spi3.h|   27 +-
  drivers/spi/bfin_spi6xx.c  |  279 
 ++--
  include/configs/bf609-ezkit.h  |1 +
  5 files changed, 262 insertions(+), 268 deletions(-)
  create mode 100644 drivers/spi/adi_spi3.c
  rename arch/blackfin/include/asm/mach-common/bits/spi6xx.h = 
 drivers/spi/adi_spi3.h (95%)

 diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
 index f02c35a..e0c82e6 100644
 --- a/drivers/spi/Makefile
 +++ b/drivers/spi/Makefile
 @@ -16,6 +16,7 @@ obj-$(CONFIG_ATMEL_DATAFLASH_SPI) += atmel_dataflash_spi.o
  obj-$(CONFIG_ATMEL_SPI) += atmel_spi.o
  obj-$(CONFIG_BFIN_SPI) += bfin_spi.o
  obj-$(CONFIG_BFIN_SPI6XX) += bfin_spi6xx.o
 +obj-$(CONFIG_ADI_SPI3) += adi_spi3.o
  obj-$(CONFIG_CF_SPI) += cf_spi.o
  obj-$(CONFIG_CF_QSPI) += cf_qspi.o
  obj-$(CONFIG_DAVINCI_SPI) += davinci_spi.o
 diff --git a/drivers/spi/adi_spi3.c b/drivers/spi/adi_spi3.c
 new file mode 100644
 index 000..89c914a
 --- /dev/null
 +++ b/drivers/spi/adi_spi3.c
 @@ -0,0 +1,222 @@
 +/*
 + * Analog Devices SPI3 controller driver
 + *
 + * Copyright (c) 2014 Analog Devices Inc.
 + *
 + * This program is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License version 2 as
 + * published by the Free Software Foundation.
 + *
 + * This program is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + * GNU General Public License for more details.
 + */
 +
 +#include common.h
 +#include malloc.h
 +#include spi.h
 +#include asm/io.h
 +#include asm/gpio.h
 +#include asm/clock.h
 +#include adi_spi3.h
 +
 +#define to_adi_spi_slave(s) container_of(s, struct adi_spi_slave, slave)
 +
 +int spi_cs_is_valid(unsigned int bus, unsigned int cs)
 +{
 +   if (is_gpio_cs(cs))
 +   return gpio_is_valid(gpio_cs(cs));
 +   else
 +   return adi_spi_cs_valid(bus, cs);
 +}
 +
 +void spi_cs_activate(struct spi_slave *slave)
 +{
 +   struct adi_spi_slave *sdev = to_adi_spi_slave(slave);
 +
 +   if (is_gpio_cs(slave-cs)) {
 +   unsigned int cs = gpio_cs(slave-cs);
 +   gpio_set_value(cs, sdev-cs_pol);
 +   } else {
 +   u32 ssel;
 +   ssel = readl(sdev-regs-ssel);
 +   ssel |= BIT_SSEL_EN(slave-cs);
 +   if (sdev-cs_pol)
 +   ssel |= BIT_SSEL_VAL(slave-cs);
 +   else
 +   ssel = ~BIT_SSEL_VAL(slave-cs);
 +   writel(ssel, sdev-regs-ssel);
 +   }
 +}
 +
 +void spi_cs_deactivate(struct spi_slave *slave)
 +{
 +   struct adi_spi_slave *sdev = to_adi_spi_slave(slave);
 +
 +   if (is_gpio_cs(slave-cs)) {
 +   unsigned int cs = gpio_cs(slave-cs);
 +   gpio_set_value(cs, !sdev-cs_pol);
 +   gpio_set_value(cs, 1);
 +   } else {
 +   u32 ssel;
 +   ssel = readl(sdev-regs-ssel);
 +   if (sdev-cs_pol)
 +   ssel = ~BIT_SSEL_VAL(slave-cs);
 +   else
 +   ssel |= BIT_SSEL_VAL(slave-cs);
 +   /* deassert cs */
 +   writel(ssel, sdev-regs-ssel);
 +   /* disable cs */
 +   ssel = ~BIT_SSEL_EN(slave-cs);
 +   writel(ssel, sdev-regs-ssel);
 +   }
 +}
 +
 +void spi_init()
 +{
 +}
 +
 +void spi_set_speed(struct spi_slave *slave, uint hz)
 +{
 +   struct adi_spi_slave *sdev = to_adi_spi_slave(slave);
 +   u32 clock;
 +
 +   clock = get_spi_clk() / hz;
 +   if (clock)
 +   clock--;
 +   sdev-clock = clock;
 +}
 +
 +struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 +   unsigned int max_hz, unsigned int mode)
 +{
 +   struct adi_spi_slave *sdev;
 +
 +   if (!spi_cs_is_valid(bus, cs))
 +   return NULL;
 +
 +   if (max_hz  get_spi_clk())
 +   return NULL;
 +
 +   sdev 

Re: [U-Boot] [PATCH 2/2] spi: add common spi3 controller driver

2014-11-12 Thread Jagan Teki
Hi Scott,

Sorry for the late response, Can you add the driver to dm-spi.

Please see any info to doc/driver-model/spi-howto.txt

Let me know for any inputs/questions.

On 25 September 2014 14:55, Scott Jiang scott.jiang.li...@gmail.com wrote:
 SPI3 controller is not only used on BF609 platform. So we add a common 
 controller
 driver and leave machine specific configuration in board drivers.
 Remove obsolete spi6xx.h and select new board driver in configuration file.

 Signed-off-by: Scott Jiang scott.jiang.li...@gmail.com
 ---
  drivers/spi/Makefile   |1 +
  drivers/spi/adi_spi3.c |  222 
  .../bits/spi6xx.h = drivers/spi/adi_spi3.h|   27 +-
  drivers/spi/bfin_spi6xx.c  |  279 
 ++--
  include/configs/bf609-ezkit.h  |1 +
  5 files changed, 262 insertions(+), 268 deletions(-)
  create mode 100644 drivers/spi/adi_spi3.c
  rename arch/blackfin/include/asm/mach-common/bits/spi6xx.h = 
 drivers/spi/adi_spi3.h (95%)

 diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
 index f02c35a..e0c82e6 100644
 --- a/drivers/spi/Makefile
 +++ b/drivers/spi/Makefile
 @@ -16,6 +16,7 @@ obj-$(CONFIG_ATMEL_DATAFLASH_SPI) += atmel_dataflash_spi.o
  obj-$(CONFIG_ATMEL_SPI) += atmel_spi.o
  obj-$(CONFIG_BFIN_SPI) += bfin_spi.o
  obj-$(CONFIG_BFIN_SPI6XX) += bfin_spi6xx.o
 +obj-$(CONFIG_ADI_SPI3) += adi_spi3.o
  obj-$(CONFIG_CF_SPI) += cf_spi.o
  obj-$(CONFIG_CF_QSPI) += cf_qspi.o
  obj-$(CONFIG_DAVINCI_SPI) += davinci_spi.o
 diff --git a/drivers/spi/adi_spi3.c b/drivers/spi/adi_spi3.c
 new file mode 100644
 index 000..89c914a
 --- /dev/null
 +++ b/drivers/spi/adi_spi3.c
 @@ -0,0 +1,222 @@
 +/*
 + * Analog Devices SPI3 controller driver
 + *
 + * Copyright (c) 2014 Analog Devices Inc.
 + *
 + * This program is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License version 2 as
 + * published by the Free Software Foundation.
 + *
 + * This program is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + * GNU General Public License for more details.
 + */
 +
 +#include common.h
 +#include malloc.h
 +#include spi.h
 +#include asm/io.h
 +#include asm/gpio.h
 +#include asm/clock.h
 +#include adi_spi3.h
 +
 +#define to_adi_spi_slave(s) container_of(s, struct adi_spi_slave, slave)
 +
 +int spi_cs_is_valid(unsigned int bus, unsigned int cs)
 +{
 +   if (is_gpio_cs(cs))
 +   return gpio_is_valid(gpio_cs(cs));
 +   else
 +   return adi_spi_cs_valid(bus, cs);
 +}
 +
 +void spi_cs_activate(struct spi_slave *slave)
 +{
 +   struct adi_spi_slave *sdev = to_adi_spi_slave(slave);
 +
 +   if (is_gpio_cs(slave-cs)) {
 +   unsigned int cs = gpio_cs(slave-cs);
 +   gpio_set_value(cs, sdev-cs_pol);
 +   } else {
 +   u32 ssel;
 +   ssel = readl(sdev-regs-ssel);
 +   ssel |= BIT_SSEL_EN(slave-cs);
 +   if (sdev-cs_pol)
 +   ssel |= BIT_SSEL_VAL(slave-cs);
 +   else
 +   ssel = ~BIT_SSEL_VAL(slave-cs);
 +   writel(ssel, sdev-regs-ssel);
 +   }
 +}
 +
 +void spi_cs_deactivate(struct spi_slave *slave)
 +{
 +   struct adi_spi_slave *sdev = to_adi_spi_slave(slave);
 +
 +   if (is_gpio_cs(slave-cs)) {
 +   unsigned int cs = gpio_cs(slave-cs);
 +   gpio_set_value(cs, !sdev-cs_pol);
 +   gpio_set_value(cs, 1);
 +   } else {
 +   u32 ssel;
 +   ssel = readl(sdev-regs-ssel);
 +   if (sdev-cs_pol)
 +   ssel = ~BIT_SSEL_VAL(slave-cs);
 +   else
 +   ssel |= BIT_SSEL_VAL(slave-cs);
 +   /* deassert cs */
 +   writel(ssel, sdev-regs-ssel);
 +   /* disable cs */
 +   ssel = ~BIT_SSEL_EN(slave-cs);
 +   writel(ssel, sdev-regs-ssel);
 +   }
 +}
 +
 +void spi_init()
 +{
 +}
 +
 +void spi_set_speed(struct spi_slave *slave, uint hz)
 +{
 +   struct adi_spi_slave *sdev = to_adi_spi_slave(slave);
 +   u32 clock;
 +
 +   clock = get_spi_clk() / hz;
 +   if (clock)
 +   clock--;
 +   sdev-clock = clock;
 +}
 +
 +struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 +   unsigned int max_hz, unsigned int mode)
 +{
 +   struct adi_spi_slave *sdev;
 +
 +   if (!spi_cs_is_valid(bus, cs))
 +   return NULL;
 +
 +   if (max_hz  get_spi_clk())
 +   return NULL;
 +
 +   sdev = adi_spi_setup(bus, cs);
 +   if (!sdev)
 +   return NULL;
 +
 +   sdev-control = SPI_CTL_EN | SPI_CTL_MSTR;
 +   if (mode  SPI_CPHA)
 +   sdev-control |= 

Re: [U-Boot] [PATCH 2/2] spi: add common spi3 controller driver

2014-11-12 Thread Scott Jiang
Hi Jagan,

Could you merge these two patches first? Then I'll send a patch like
adi_spi:convert to use dm spi.
Because these patches are for different task.

Regards,
Scott

2014-11-13 5:50 GMT+08:00 Jagan Teki jagannadh.t...@gmail.com:
 Hi Scott,

 Sorry for the late response, Can you add the driver to dm-spi.

 Please see any info to doc/driver-model/spi-howto.txt

 Let me know for any inputs/questions.

 On 25 September 2014 14:55, Scott Jiang scott.jiang.li...@gmail.com wrote:
 SPI3 controller is not only used on BF609 platform. So we add a common 
 controller
 driver and leave machine specific configuration in board drivers.
 Remove obsolete spi6xx.h and select new board driver in configuration file.

 Signed-off-by: Scott Jiang scott.jiang.li...@gmail.com
 ---
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 2/2] spi: add common spi3 controller driver

2014-11-06 Thread Scott Jiang
Ping.

Scott

2014-09-25 17:25 GMT+08:00 Scott Jiang scott.jiang.li...@gmail.com:
 SPI3 controller is not only used on BF609 platform. So we add a common 
 controller
 driver and leave machine specific configuration in board drivers.
 Remove obsolete spi6xx.h and select new board driver in configuration file.

 Signed-off-by: Scott Jiang scott.jiang.li...@gmail.com
 ---
  drivers/spi/Makefile   |1 +
  drivers/spi/adi_spi3.c |  222 
  .../bits/spi6xx.h = drivers/spi/adi_spi3.h|   27 +-
  drivers/spi/bfin_spi6xx.c  |  279 
 ++--
  include/configs/bf609-ezkit.h  |1 +
  5 files changed, 262 insertions(+), 268 deletions(-)
  create mode 100644 drivers/spi/adi_spi3.c
  rename arch/blackfin/include/asm/mach-common/bits/spi6xx.h = 
 drivers/spi/adi_spi3.h (95%)

 diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
 index f02c35a..e0c82e6 100644
 --- a/drivers/spi/Makefile
 +++ b/drivers/spi/Makefile
 @@ -16,6 +16,7 @@ obj-$(CONFIG_ATMEL_DATAFLASH_SPI) += atmel_dataflash_spi.o
  obj-$(CONFIG_ATMEL_SPI) += atmel_spi.o
  obj-$(CONFIG_BFIN_SPI) += bfin_spi.o
  obj-$(CONFIG_BFIN_SPI6XX) += bfin_spi6xx.o
 +obj-$(CONFIG_ADI_SPI3) += adi_spi3.o
  obj-$(CONFIG_CF_SPI) += cf_spi.o
  obj-$(CONFIG_CF_QSPI) += cf_qspi.o
  obj-$(CONFIG_DAVINCI_SPI) += davinci_spi.o
 diff --git a/drivers/spi/adi_spi3.c b/drivers/spi/adi_spi3.c
 new file mode 100644
 index 000..89c914a
 --- /dev/null
 +++ b/drivers/spi/adi_spi3.c
 @@ -0,0 +1,222 @@
 +/*
 + * Analog Devices SPI3 controller driver
 + *
 + * Copyright (c) 2014 Analog Devices Inc.
 + *
 + * This program is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License version 2 as
 + * published by the Free Software Foundation.
 + *
 + * This program is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + * GNU General Public License for more details.
 + */
 +
 +#include common.h
 +#include malloc.h
 +#include spi.h
 +#include asm/io.h
 +#include asm/gpio.h
 +#include asm/clock.h
 +#include adi_spi3.h
 +
 +#define to_adi_spi_slave(s) container_of(s, struct adi_spi_slave, slave)
 +
 +int spi_cs_is_valid(unsigned int bus, unsigned int cs)
 +{
 +   if (is_gpio_cs(cs))
 +   return gpio_is_valid(gpio_cs(cs));
 +   else
 +   return adi_spi_cs_valid(bus, cs);
 +}
 +
 +void spi_cs_activate(struct spi_slave *slave)
 +{
 +   struct adi_spi_slave *sdev = to_adi_spi_slave(slave);
 +
 +   if (is_gpio_cs(slave-cs)) {
 +   unsigned int cs = gpio_cs(slave-cs);
 +   gpio_set_value(cs, sdev-cs_pol);
 +   } else {
 +   u32 ssel;
 +   ssel = readl(sdev-regs-ssel);
 +   ssel |= BIT_SSEL_EN(slave-cs);
 +   if (sdev-cs_pol)
 +   ssel |= BIT_SSEL_VAL(slave-cs);
 +   else
 +   ssel = ~BIT_SSEL_VAL(slave-cs);
 +   writel(ssel, sdev-regs-ssel);
 +   }
 +}
 +
 +void spi_cs_deactivate(struct spi_slave *slave)
 +{
 +   struct adi_spi_slave *sdev = to_adi_spi_slave(slave);
 +
 +   if (is_gpio_cs(slave-cs)) {
 +   unsigned int cs = gpio_cs(slave-cs);
 +   gpio_set_value(cs, !sdev-cs_pol);
 +   gpio_set_value(cs, 1);
 +   } else {
 +   u32 ssel;
 +   ssel = readl(sdev-regs-ssel);
 +   if (sdev-cs_pol)
 +   ssel = ~BIT_SSEL_VAL(slave-cs);
 +   else
 +   ssel |= BIT_SSEL_VAL(slave-cs);
 +   /* deassert cs */
 +   writel(ssel, sdev-regs-ssel);
 +   /* disable cs */
 +   ssel = ~BIT_SSEL_EN(slave-cs);
 +   writel(ssel, sdev-regs-ssel);
 +   }
 +}
 +
 +void spi_init()
 +{
 +}
 +
 +void spi_set_speed(struct spi_slave *slave, uint hz)
 +{
 +   struct adi_spi_slave *sdev = to_adi_spi_slave(slave);
 +   u32 clock;
 +
 +   clock = get_spi_clk() / hz;
 +   if (clock)
 +   clock--;
 +   sdev-clock = clock;
 +}
 +
 +struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 +   unsigned int max_hz, unsigned int mode)
 +{
 +   struct adi_spi_slave *sdev;
 +
 +   if (!spi_cs_is_valid(bus, cs))
 +   return NULL;
 +
 +   if (max_hz  get_spi_clk())
 +   return NULL;
 +
 +   sdev = adi_spi_setup(bus, cs);
 +   if (!sdev)
 +   return NULL;
 +
 +   sdev-control = SPI_CTL_EN | SPI_CTL_MSTR;
 +   if (mode  SPI_CPHA)
 +   sdev-control |= SPI_CTL_CPHA;
 +   if (mode  SPI_CPOL)
 +   sdev-control |= SPI_CTL_CPOL;
 +   if (mode  SPI_LSB_FIRST)
 +   sdev-control |= 

[U-Boot] [PATCH 2/2] spi: add common spi3 controller driver

2014-09-24 Thread Scott Jiang
SPI3 controller is not only used on BF609 platform. So we add a common 
controller
driver and leave machine specific configuration in board drivers.
Remove obsolete spi6xx.h and select new board driver in configuration file.

Signed-off-by: Scott Jiang scott.jiang.li...@gmail.com
---
 drivers/spi/Makefile   |1 +
 drivers/spi/adi_spi3.c |  222 
 .../bits/spi6xx.h = drivers/spi/adi_spi3.h|   27 +-
 drivers/spi/bfin_spi6xx.c  |  279 ++--
 include/configs/bf609-ezkit.h  |1 +
 5 files changed, 262 insertions(+), 268 deletions(-)
 create mode 100644 drivers/spi/adi_spi3.c
 rename arch/blackfin/include/asm/mach-common/bits/spi6xx.h = 
drivers/spi/adi_spi3.h (95%)

diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index f02c35a..e0c82e6 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -16,6 +16,7 @@ obj-$(CONFIG_ATMEL_DATAFLASH_SPI) += atmel_dataflash_spi.o
 obj-$(CONFIG_ATMEL_SPI) += atmel_spi.o
 obj-$(CONFIG_BFIN_SPI) += bfin_spi.o
 obj-$(CONFIG_BFIN_SPI6XX) += bfin_spi6xx.o
+obj-$(CONFIG_ADI_SPI3) += adi_spi3.o
 obj-$(CONFIG_CF_SPI) += cf_spi.o
 obj-$(CONFIG_CF_QSPI) += cf_qspi.o
 obj-$(CONFIG_DAVINCI_SPI) += davinci_spi.o
diff --git a/drivers/spi/adi_spi3.c b/drivers/spi/adi_spi3.c
new file mode 100644
index 000..89c914a
--- /dev/null
+++ b/drivers/spi/adi_spi3.c
@@ -0,0 +1,222 @@
+/*
+ * Analog Devices SPI3 controller driver
+ *
+ * Copyright (c) 2014 Analog Devices Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include common.h
+#include malloc.h
+#include spi.h
+#include asm/io.h
+#include asm/gpio.h
+#include asm/clock.h
+#include adi_spi3.h
+
+#define to_adi_spi_slave(s) container_of(s, struct adi_spi_slave, slave)
+
+int spi_cs_is_valid(unsigned int bus, unsigned int cs)
+{
+   if (is_gpio_cs(cs))
+   return gpio_is_valid(gpio_cs(cs));
+   else
+   return adi_spi_cs_valid(bus, cs);
+}
+
+void spi_cs_activate(struct spi_slave *slave)
+{
+   struct adi_spi_slave *sdev = to_adi_spi_slave(slave);
+
+   if (is_gpio_cs(slave-cs)) {
+   unsigned int cs = gpio_cs(slave-cs);
+   gpio_set_value(cs, sdev-cs_pol);
+   } else {
+   u32 ssel;
+   ssel = readl(sdev-regs-ssel);
+   ssel |= BIT_SSEL_EN(slave-cs);
+   if (sdev-cs_pol)
+   ssel |= BIT_SSEL_VAL(slave-cs);
+   else
+   ssel = ~BIT_SSEL_VAL(slave-cs);
+   writel(ssel, sdev-regs-ssel);
+   }
+}
+
+void spi_cs_deactivate(struct spi_slave *slave)
+{
+   struct adi_spi_slave *sdev = to_adi_spi_slave(slave);
+
+   if (is_gpio_cs(slave-cs)) {
+   unsigned int cs = gpio_cs(slave-cs);
+   gpio_set_value(cs, !sdev-cs_pol);
+   gpio_set_value(cs, 1);
+   } else {
+   u32 ssel;
+   ssel = readl(sdev-regs-ssel);
+   if (sdev-cs_pol)
+   ssel = ~BIT_SSEL_VAL(slave-cs);
+   else
+   ssel |= BIT_SSEL_VAL(slave-cs);
+   /* deassert cs */
+   writel(ssel, sdev-regs-ssel);
+   /* disable cs */
+   ssel = ~BIT_SSEL_EN(slave-cs);
+   writel(ssel, sdev-regs-ssel);
+   }
+}
+
+void spi_init()
+{
+}
+
+void spi_set_speed(struct spi_slave *slave, uint hz)
+{
+   struct adi_spi_slave *sdev = to_adi_spi_slave(slave);
+   u32 clock;
+
+   clock = get_spi_clk() / hz;
+   if (clock)
+   clock--;
+   sdev-clock = clock;
+}
+
+struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
+   unsigned int max_hz, unsigned int mode)
+{
+   struct adi_spi_slave *sdev;
+
+   if (!spi_cs_is_valid(bus, cs))
+   return NULL;
+
+   if (max_hz  get_spi_clk())
+   return NULL;
+
+   sdev = adi_spi_setup(bus, cs);
+   if (!sdev)
+   return NULL;
+
+   sdev-control = SPI_CTL_EN | SPI_CTL_MSTR;
+   if (mode  SPI_CPHA)
+   sdev-control |= SPI_CTL_CPHA;
+   if (mode  SPI_CPOL)
+   sdev-control |= SPI_CTL_CPOL;
+   if (mode  SPI_LSB_FIRST)
+   sdev-control |= SPI_CTL_LSBF;
+   sdev-control = ~SPI_CTL_ASSEL;
+   sdev-cs_pol = mode  SPI_CS_HIGH ? 1 : 0;
+   spi_set_speed(sdev-slave, max_hz);
+
+   return sdev-slave;
+}
+
+void spi_free_slave(struct spi_slave *slave)
+{
+