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


[U-Boot] [PATCH 1/3 v2] blackfin: rename bfin-twi_i2c driver to adi_i2c

2014-11-12 Thread Scott Jiang
Signed-off-by: Scott Jiang scott.jiang.li...@gmail.com
---
 drivers/i2c/Makefile  |2 +-
 drivers/i2c/{bfin-twi_i2c.c = adi_i2c.c} |7 +++
 include/configs/bct-brettl2.h |2 +-
 include/configs/bf518f-ezbrd.h|2 +-
 include/configs/bf526-ezbrd.h |2 +-
 include/configs/bf527-ad7160-eval.h   |2 +-
 include/configs/bf527-ezkit.h |2 +-
 include/configs/bf527-sdp.h   |2 +-
 include/configs/bf537-minotaur.h  |2 +-
 include/configs/bf537-pnav.h  |2 +-
 include/configs/bf537-srv1.h  |2 +-
 include/configs/bf537-stamp.h |2 +-
 include/configs/bf538f-ezkit.h|2 +-
 include/configs/bf548-ezkit.h |2 +-
 include/configs/bf609-ezkit.h |2 +-
 include/configs/br4.h |2 +-
 include/configs/cm-bf527.h|2 +-
 include/configs/cm-bf537e.h   |2 +-
 include/configs/cm-bf537u.h   |2 +-
 include/configs/cm-bf548.h|2 +-
 include/configs/pr1.h |2 +-
 include/configs/tcm-bf518.h   |2 +-
 include/configs/tcm-bf537.h   |2 +-
 23 files changed, 25 insertions(+), 26 deletions(-)
 rename drivers/i2c/{bfin-twi_i2c.c = adi_i2c.c} (98%)

diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
index d067897..dae3d71 100644
--- a/drivers/i2c/Makefile
+++ b/drivers/i2c/Makefile
@@ -5,7 +5,7 @@
 # SPDX-License-Identifier: GPL-2.0+
 #
 
-obj-$(CONFIG_BFIN_TWI_I2C) += bfin-twi_i2c.o
+obj-$(CONFIG_SYS_I2C_ADI) += adi_i2c.o
 obj-$(CONFIG_I2C_MV) += mv_i2c.o
 obj-$(CONFIG_PCA9564_I2C) += pca9564_i2c.o
 obj-$(CONFIG_TSI108_I2C) += tsi108_i2c.o
diff --git a/drivers/i2c/bfin-twi_i2c.c b/drivers/i2c/adi_i2c.c
similarity index 98%
rename from drivers/i2c/bfin-twi_i2c.c
rename to drivers/i2c/adi_i2c.c
index cfab064..cb74062 100644
--- a/drivers/i2c/bfin-twi_i2c.c
+++ b/drivers/i2c/adi_i2c.c
@@ -1,7 +1,7 @@
 /*
- * i2c.c - driver for Blackfin on-chip TWI/I2C
+ * i2c.c - driver for ADI TWI/I2C
  *
- * Copyright (c) 2006-2010 Analog Devices Inc.
+ * Copyright (c) 2006-2014 Analog Devices Inc.
  *
  * Licensed under the GPL-2 or later.
  */
@@ -9,9 +9,8 @@
 #include common.h
 #include i2c.h
 
-#include asm/blackfin.h
 #include asm/clock.h
-#include asm/mach-common/bits/twi.h
+#include asm/twi.h
 
 /* Every register is 32bit aligned, but only 16bits in size */
 #define ureg(name) u16 name; u16 __pad_##name;
diff --git a/include/configs/bct-brettl2.h b/include/configs/bct-brettl2.h
index d0828d5..f0b74d8 100644
--- a/include/configs/bct-brettl2.h
+++ b/include/configs/bct-brettl2.h
@@ -122,7 +122,7 @@
 /*
  * I2C Settings
  */
-#define CONFIG_BFIN_TWI_I2C1
+#define CONFIG_SYS_I2C_ADI
 #define CONFIG_HARD_I2C1
 
 
diff --git a/include/configs/bf518f-ezbrd.h b/include/configs/bf518f-ezbrd.h
index 20f6ed1..4df51b9 100644
--- a/include/configs/bf518f-ezbrd.h
+++ b/include/configs/bf518f-ezbrd.h
@@ -134,7 +134,7 @@
 /*
  * I2C Settings
  */
-#define CONFIG_BFIN_TWI_I2C1
+#define CONFIG_SYS_I2C_ADI
 #define CONFIG_HARD_I2C1
 
 
diff --git a/include/configs/bf526-ezbrd.h b/include/configs/bf526-ezbrd.h
index c33d035..55bfbbe 100644
--- a/include/configs/bf526-ezbrd.h
+++ b/include/configs/bf526-ezbrd.h
@@ -131,7 +131,7 @@
 /*
  * I2C Settings
  */
-#define CONFIG_BFIN_TWI_I2C1
+#define CONFIG_SYS_I2C_ADI
 #define CONFIG_HARD_I2C1
 
 
diff --git a/include/configs/bf527-ad7160-eval.h 
b/include/configs/bf527-ad7160-eval.h
index b497f26..589c7a5 100644
--- a/include/configs/bf527-ad7160-eval.h
+++ b/include/configs/bf527-ad7160-eval.h
@@ -119,7 +119,7 @@
 /*
  * I2C Settings
  */
-#define CONFIG_BFIN_TWI_I2C1
+#define CONFIG_SYS_I2C_ADI
 #define CONFIG_HARD_I2C1
 
 
diff --git a/include/configs/bf527-ezkit.h b/include/configs/bf527-ezkit.h
index 0bca53f..0e68952 100644
--- a/include/configs/bf527-ezkit.h
+++ b/include/configs/bf527-ezkit.h
@@ -134,7 +134,7 @@
 /*
  * I2C Settings
  */
-#define CONFIG_BFIN_TWI_I2C1
+#define CONFIG_SYS_I2C_ADI
 #define CONFIG_HARD_I2C1
 
 
diff --git a/include/configs/bf527-sdp.h b/include/configs/bf527-sdp.h
index 9d43b81..a3ad7ae 100644
--- a/include/configs/bf527-sdp.h
+++ b/include/configs/bf527-sdp.h
@@ -103,7 +103,7 @@
 /*
  * I2C Settings
  */
-#define CONFIG_BFIN_TWI_I2C1
+#define CONFIG_SYS_I2C_ADI
 #define CONFIG_HARD_I2C1
 
 
diff --git a/include/configs/bf537-minotaur.h b/include/configs/bf537-minotaur.h
index 3bc364c..d94c2df 100644
--- a/include/configs/bf537-minotaur.h
+++ b/include/configs/bf537-minotaur.h
@@ -121,7 +121,7 @@
 /*
  * I2C settings
  */
-#define CONFIG_BFIN_TWI_I2C1
+#define CONFIG_SYS_I2C_ADI
 #define CONFIG_HARD_I2C1
 #define CONFIG_SYS_I2C_SPEED   5
 #define CONFIG_SYS_I2C_SLAVE

[U-Boot] [PATCH 3/3 v2] blackfin: convert to use CONFIG_SYS_I2C framework

2014-11-12 Thread Scott Jiang
Signed-off-by: Scott Jiang scott.jiang.li...@gmail.com
---
 drivers/i2c/adi_i2c.c   |  202 +++
 include/configs/bct-brettl2.h   |2 +-
 include/configs/bf518f-ezbrd.h  |2 +-
 include/configs/bf526-ezbrd.h   |2 +-
 include/configs/bf527-ad7160-eval.h |2 +-
 include/configs/bf527-ezkit.h   |2 +-
 include/configs/bf527-sdp.h |2 +-
 include/configs/bf537-minotaur.h|2 +-
 include/configs/bf537-pnav.h|2 +-
 include/configs/bf537-srv1.h|2 +-
 include/configs/bf537-stamp.h   |2 +-
 include/configs/bf538f-ezkit.h  |2 +-
 include/configs/bf548-ezkit.h   |2 +-
 include/configs/bf609-ezkit.h   |2 +-
 include/configs/bfin_adi_common.h   |4 +-
 include/configs/br4.h   |2 +-
 include/configs/cm-bf527.h  |2 +-
 include/configs/cm-bf537e.h |2 +-
 include/configs/cm-bf537u.h |2 +-
 include/configs/cm-bf548.h  |2 +-
 include/configs/pr1.h   |2 +-
 include/configs/tcm-bf518.h |2 +-
 include/configs/tcm-bf537.h |2 +-
 23 files changed, 83 insertions(+), 165 deletions(-)

diff --git a/drivers/i2c/adi_i2c.c b/drivers/i2c/adi_i2c.c
index 71077c5..20495b1 100644
--- a/drivers/i2c/adi_i2c.c
+++ b/drivers/i2c/adi_i2c.c
@@ -13,6 +13,8 @@
 #include asm/twi.h
 #include asm/io.h
 
+static struct twi_regs *i2c_get_base(struct i2c_adapter *adap);
+
 /* Every register is 32bit aligned, but only 16bits in size */
 #define ureg(name) u16 name; u16 __pad_##name;
 struct twi_regs {
@@ -36,25 +38,12 @@ struct twi_regs {
 };
 #undef ureg
 
-/* U-Boot I2C framework allows only one active device at a time.  */
 #ifdef TWI_CLKDIV
 #define TWI0_CLKDIV TWI_CLKDIV
-#endif
-static struct twi_regs *twi = (void *)TWI0_CLKDIV;
-
-#ifdef DEBUG
-# define dmemset(s, c, n) memset(s, c, n)
-#else
-# define dmemset(s, c, n)
-#endif
-#define debugi(fmt, args...) \
-   debug( \
-   MSTAT:0x%03x FSTAT:0x%x ISTAT:0x%02x\t%-20s:%-3i:  fmt \n, \
-   twi-master_stat, twi-fifo_stat, twi-int_stat, \
-   __func__, __LINE__, ## args)
-
-#ifdef CONFIG_TWICLK_KHZ
-# error do not define CONFIG_TWICLK_KHZ ... use CONFIG_SYS_I2C_SPEED
+# ifdef CONFIG_SYS_MAX_I2C_BUS
+# undef CONFIG_SYS_MAX_I2C_BUS
+# endif
+#define CONFIG_SYS_MAX_I2C_BUS 1
 #endif
 
 /*
@@ -70,7 +59,7 @@ static struct twi_regs *twi = (void *)TWI0_CLKDIV;
 #define SYS_I2C_DUTY  I2C_SPEED_TO_DUTY(CONFIG_SYS_I2C_SPEED)
 /* Note: duty is inverse of speed, so the comparisons below are correct */
 #if SYS_I2C_DUTY  I2C_DUTY_MAX || SYS_I2C_DUTY  I2C_DUTY_MIN
-# error The Blackfin I2C hardware can only operate 20KHz - 400KHz
+# error The I2C hardware can only operate 20KHz - 400KHz
 #endif
 
 /* All transfers are described by this data structure */
@@ -92,7 +81,7 @@ struct i2c_msg {
  * wait_for_completion - manage the actual i2c transfer
  * @msg: the i2c msg
  */
-static int wait_for_completion(struct i2c_msg *msg)
+static int wait_for_completion(struct twi_regs *twi, struct i2c_msg *msg)
 {
u16 int_stat, ctl;
ulong timebase = get_timer(0);
@@ -101,7 +90,6 @@ static int wait_for_completion(struct i2c_msg *msg)
int_stat = readw(twi-int_stat);
 
if (int_stat  XMTSERV) {
-   debugi(processing XMTSERV);
writew(XMTSERV, twi-int_stat);
if (msg-alen) {
writew(*(msg-abuf++), twi-xmt_data8);
@@ -119,7 +107,6 @@ static int wait_for_completion(struct i2c_msg *msg)
}
}
if (int_stat  RCVSERV) {
-   debugi(processing RCVSERV);
writew(RCVSERV, twi-int_stat);
if (msg-len) {
*(msg-buf++) = readw(twi-rcv_data8);
@@ -130,12 +117,10 @@ static int wait_for_completion(struct i2c_msg *msg)
}
}
if (int_stat  MERR) {
-   debugi(processing MERR);
writew(MERR, twi-int_stat);
return msg-len;
}
if (int_stat  MCOMP) {
-   debugi(processing MCOMP);
writew(MCOMP, twi-int_stat);
if (msg-flags  I2C_M_COMBO  msg-len) {
ctl = readw(twi-master_ctl);
@@ -155,16 +140,10 @@ static int wait_for_completion(struct i2c_msg *msg)
return msg-len;
 }
 
-/**
- * i2c_transfer - setup an i2c transfer
- * @return: 0 if things worked, non-0 if things failed
- *
- * Here we just get the i2c stuff all prepped and ready, and then tail off
- * into wait_for_completion() for all the bits to go.
- */
-static int i2c_transfer(uchar chip, uint addr, int alen, uchar *buffer

[U-Boot] [PATCH 2/3 v2] adi_i2c: convert to use general io accessors.

2014-11-12 Thread Scott Jiang
Signed-off-by: Scott Jiang scott.jiang.li...@gmail.com
---
 drivers/i2c/adi_i2c.c |  145 ++---
 1 file changed, 77 insertions(+), 68 deletions(-)

diff --git a/drivers/i2c/adi_i2c.c b/drivers/i2c/adi_i2c.c
index cb74062..71077c5 100644
--- a/drivers/i2c/adi_i2c.c
+++ b/drivers/i2c/adi_i2c.c
@@ -11,6 +11,7 @@
 
 #include asm/clock.h
 #include asm/twi.h
+#include asm/io.h
 
 /* Every register is 32bit aligned, but only 16bits in size */
 #define ureg(name) u16 name; u16 __pad_##name;
@@ -39,7 +40,7 @@ struct twi_regs {
 #ifdef TWI_CLKDIV
 #define TWI0_CLKDIV TWI_CLKDIV
 #endif
-static volatile struct twi_regs *twi = (void *)TWI0_CLKDIV;
+static struct twi_regs *twi = (void *)TWI0_CLKDIV;
 
 #ifdef DEBUG
 # define dmemset(s, c, n) memset(s, c, n)
@@ -93,53 +94,54 @@ struct i2c_msg {
  */
 static int wait_for_completion(struct i2c_msg *msg)
 {
-   uint16_t int_stat;
+   u16 int_stat, ctl;
ulong timebase = get_timer(0);
 
do {
-   int_stat = twi-int_stat;
+   int_stat = readw(twi-int_stat);
 
if (int_stat  XMTSERV) {
debugi(processing XMTSERV);
-   twi-int_stat = XMTSERV;
-   SSYNC();
+   writew(XMTSERV, twi-int_stat);
if (msg-alen) {
-   twi-xmt_data8 = *(msg-abuf++);
+   writew(*(msg-abuf++), twi-xmt_data8);
--msg-alen;
} else if (!(msg-flags  I2C_M_COMBO)  msg-len) {
-   twi-xmt_data8 = *(msg-buf++);
+   writew(*(msg-buf++), twi-xmt_data8);
--msg-len;
} else {
-   twi-master_ctl |= (msg-flags  I2C_M_COMBO) ? 
RSTART | MDIR : STOP;
-   SSYNC();
+   ctl = readw(twi-master_ctl);
+   if (msg-flags  I2C_M_COMBO)
+   writew(ctl | RSTART | MDIR,
+   twi-master_ctl);
+   else
+   writew(ctl | STOP, twi-master_ctl);
}
}
if (int_stat  RCVSERV) {
debugi(processing RCVSERV);
-   twi-int_stat = RCVSERV;
-   SSYNC();
+   writew(RCVSERV, twi-int_stat);
if (msg-len) {
-   *(msg-buf++) = twi-rcv_data8;
+   *(msg-buf++) = readw(twi-rcv_data8);
--msg-len;
} else if (msg-flags  I2C_M_STOP) {
-   twi-master_ctl |= STOP;
-   SSYNC();
+   ctl = readw(twi-master_ctl);
+   writew(ctl | STOP, twi-master_ctl);
}
}
if (int_stat  MERR) {
debugi(processing MERR);
-   twi-int_stat = MERR;
-   SSYNC();
+   writew(MERR, twi-int_stat);
return msg-len;
}
if (int_stat  MCOMP) {
debugi(processing MCOMP);
-   twi-int_stat = MCOMP;
-   SSYNC();
+   writew(MCOMP, twi-int_stat);
if (msg-flags  I2C_M_COMBO  msg-len) {
-   twi-master_ctl = (twi-master_ctl  ~RSTART) |
+   ctl = readw(twi-master_ctl);
+   ctl = (ctl  ~RSTART) |
(min(msg-len, 0xff)  6) | MEN | MDIR;
-   SSYNC();
+   writew(ctl, twi-master_ctl);
} else
break;
}
@@ -160,8 +162,11 @@ static int wait_for_completion(struct i2c_msg *msg)
  * Here we just get the i2c stuff all prepped and ready, and then tail off
  * into wait_for_completion() for all the bits to go.
  */
-static int i2c_transfer(uchar chip, uint addr, int alen, uchar *buffer, int 
len, u8 flags)
+static int i2c_transfer(uchar chip, uint addr, int alen, uchar *buffer,
+   int len, u8 flags)
 {
+   int ret;
+   u16 ctl;
uchar addr_buffer[] = {
(addr   0),
(addr   8),
@@ -174,62 +179,59 @@ static int i2c_transfer(uchar chip, uint addr, int alen, 
uchar *buffer, int len,
.abuf  = addr_buffer,
.alen  = alen,
};
-   int ret;
 
dmemset(buffer, 0xff, len);
-   debugi(chip=0x%x addr=0x

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 1/2] blackfin: spi: move spi max chip select to spi.h

2014-11-06 Thread Scott Jiang
Ping.

Scott

2014-09-25 17:25 GMT+08:00 Scott Jiang scott.jiang.li...@gmail.com:
 This macro is only related to spi. So it's better to place it in spi.h.

 Signed-off-by: Scott Jiang scott.jiang.li...@gmail.com
 ---
  arch/blackfin/include/asm/config-pre.h   |3 ---
  arch/blackfin/include/asm/mach-common/bits/spi.h |1 +
  2 files changed, 1 insertion(+), 3 deletions(-)

 diff --git a/arch/blackfin/include/asm/config-pre.h 
 b/arch/blackfin/include/asm/config-pre.h
 index 2d8b293..189cb05 100644
 --- a/arch/blackfin/include/asm/config-pre.h
 +++ b/arch/blackfin/include/asm/config-pre.h
 @@ -70,9 +70,6 @@ static inline const char *get_bfin_boot_mode(int bfin_boot)
  # define BFIN_BOOT_SPI_SSEL 1
  #endif

 -/* Define to get a GPIO CS with the Blackfin SPI controller */
 -#define MAX_CTRL_CS 8
 -
  /* There is no Blackfin/NetBSD port */
  #undef CONFIG_BOOTM_NETBSD

 diff --git a/arch/blackfin/include/asm/mach-common/bits/spi.h 
 b/arch/blackfin/include/asm/mach-common/bits/spi.h
 index 869dcb0..180cfaa 100644
 --- a/arch/blackfin/include/asm/mach-common/bits/spi.h
 +++ b/arch/blackfin/include/asm/mach-common/bits/spi.h
 @@ -64,4 +64,5 @@
  #define RXS0x0020  /* SPI_RDBR Data Buffer Status 
 (Full/Empty*) */
  #define TXCOL  0x0040  /* Transmit Collision Error (Corrupt 
 Data May Have Been Sent) */

 +#define MAX_CTRL_CS 7
  #endif
 --
 1.7.9.5

___
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] blackfin: rename blackfin i2c driver to adi

2014-10-31 Thread Scott Jiang
This driver is not only used on blackfin. So it's better to
rename it and access i2c registers by standard io functions.
Fix coding style as well.

Signed-off-by: Scott Jiang scott.jiang.li...@gmail.com
---
 drivers/i2c/Makefile  |2 +-
 drivers/i2c/{bfin-twi_i2c.c = adi_i2c.c} |  154 +++--
 include/configs/bct-brettl2.h |2 +-
 include/configs/bf518f-ezbrd.h|2 +-
 include/configs/bf526-ezbrd.h |2 +-
 include/configs/bf527-ad7160-eval.h   |2 +-
 include/configs/bf527-ezkit.h |2 +-
 include/configs/bf527-sdp.h   |2 +-
 include/configs/bf537-minotaur.h  |2 +-
 include/configs/bf537-pnav.h  |2 +-
 include/configs/bf537-srv1.h  |2 +-
 include/configs/bf537-stamp.h |2 +-
 include/configs/bf538f-ezkit.h|2 +-
 include/configs/bf548-ezkit.h |2 +-
 include/configs/bf609-ezkit.h |2 +-
 include/configs/br4.h |2 +-
 include/configs/cm-bf527.h|2 +-
 include/configs/cm-bf537e.h   |2 +-
 include/configs/cm-bf537u.h   |2 +-
 include/configs/cm-bf548.h|2 +-
 include/configs/pr1.h |2 +-
 include/configs/tcm-bf518.h   |2 +-
 include/configs/tcm-bf537.h   |2 +-
 23 files changed, 103 insertions(+), 95 deletions(-)
 rename drivers/i2c/{bfin-twi_i2c.c = adi_i2c.c} (72%)

diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
index d067897..b7f0098 100644
--- a/drivers/i2c/Makefile
+++ b/drivers/i2c/Makefile
@@ -5,7 +5,7 @@
 # SPDX-License-Identifier: GPL-2.0+
 #
 
-obj-$(CONFIG_BFIN_TWI_I2C) += bfin-twi_i2c.o
+obj-$(CONFIG_ADI_I2C) += adi_i2c.o
 obj-$(CONFIG_I2C_MV) += mv_i2c.o
 obj-$(CONFIG_PCA9564_I2C) += pca9564_i2c.o
 obj-$(CONFIG_TSI108_I2C) += tsi108_i2c.o
diff --git a/drivers/i2c/bfin-twi_i2c.c b/drivers/i2c/adi_i2c.c
similarity index 72%
rename from drivers/i2c/bfin-twi_i2c.c
rename to drivers/i2c/adi_i2c.c
index cfab064..c971f03 100644
--- a/drivers/i2c/bfin-twi_i2c.c
+++ b/drivers/i2c/adi_i2c.c
@@ -1,7 +1,7 @@
 /*
- * i2c.c - driver for Blackfin on-chip TWI/I2C
+ * i2c.c - driver for ADI TWI/I2C
  *
- * Copyright (c) 2006-2010 Analog Devices Inc.
+ * Copyright (c) 2006-2014 Analog Devices Inc.
  *
  * Licensed under the GPL-2 or later.
  */
@@ -9,9 +9,9 @@
 #include common.h
 #include i2c.h
 
-#include asm/blackfin.h
 #include asm/clock.h
-#include asm/mach-common/bits/twi.h
+#include asm/twi.h
+#include asm/io.h
 
 /* Every register is 32bit aligned, but only 16bits in size */
 #define ureg(name) u16 name; u16 __pad_##name;
@@ -40,7 +40,7 @@ struct twi_regs {
 #ifdef TWI_CLKDIV
 #define TWI0_CLKDIV TWI_CLKDIV
 #endif
-static volatile struct twi_regs *twi = (void *)TWI0_CLKDIV;
+static struct twi_regs *twi = (void *)TWI0_CLKDIV;
 
 #ifdef DEBUG
 # define dmemset(s, c, n) memset(s, c, n)
@@ -94,53 +94,54 @@ struct i2c_msg {
  */
 static int wait_for_completion(struct i2c_msg *msg)
 {
-   uint16_t int_stat;
+   u16 int_stat, ctl;
ulong timebase = get_timer(0);
 
do {
-   int_stat = twi-int_stat;
+   int_stat = readw(twi-int_stat);
 
if (int_stat  XMTSERV) {
debugi(processing XMTSERV);
-   twi-int_stat = XMTSERV;
-   SSYNC();
+   writew(XMTSERV, twi-int_stat);
if (msg-alen) {
-   twi-xmt_data8 = *(msg-abuf++);
+   writew(*(msg-abuf++), twi-xmt_data8);
--msg-alen;
} else if (!(msg-flags  I2C_M_COMBO)  msg-len) {
-   twi-xmt_data8 = *(msg-buf++);
+   writew(*(msg-buf++), twi-xmt_data8);
--msg-len;
} else {
-   twi-master_ctl |= (msg-flags  I2C_M_COMBO) ? 
RSTART | MDIR : STOP;
-   SSYNC();
+   ctl = readw(twi-master_ctl);
+   if (msg-flags  I2C_M_COMBO)
+   writew(ctl | RSTART | MDIR,
+   twi-master_ctl);
+   else
+   writew(ctl | STOP, twi-master_ctl);
}
}
if (int_stat  RCVSERV) {
debugi(processing RCVSERV);
-   twi-int_stat = RCVSERV;
-   SSYNC();
+   writew(RCVSERV, twi-int_stat);
if (msg-len) {
-   *(msg-buf++) = twi-rcv_data8;
+   *(msg-buf++) = readw(twi

Re: [U-Boot] [PATCH] blackfin: rename blackfin i2c driver to adi

2014-10-31 Thread Scott Jiang
Hi Heiko,


   static int wait_for_completion(struct i2c_msg *msg)
   {
 -   uint16_t int_stat;
 +   u16 int_stat, ctl;


 This change is not related to the subject of the patch,
 please split this into seperate patches ...

 ulong timebase = get_timer(0);

 do {
 -   int_stat = twi-int_stat;
 +   int_stat = readw(twi-int_stat);


 Here too... please fix globally.


This patch is to modify blackfin specific string or api to generic.
So I use standard io api readl/writel here. I'm not sure what you
mean.

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


[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

[U-Boot] [PATCH 1/2] blackfin: spi: move spi max chip select to spi.h

2014-09-24 Thread Scott Jiang
This macro is only related to spi. So it's better to place it in spi.h.

Signed-off-by: Scott Jiang scott.jiang.li...@gmail.com
---
 arch/blackfin/include/asm/config-pre.h   |3 ---
 arch/blackfin/include/asm/mach-common/bits/spi.h |1 +
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/arch/blackfin/include/asm/config-pre.h 
b/arch/blackfin/include/asm/config-pre.h
index 2d8b293..189cb05 100644
--- a/arch/blackfin/include/asm/config-pre.h
+++ b/arch/blackfin/include/asm/config-pre.h
@@ -70,9 +70,6 @@ static inline const char *get_bfin_boot_mode(int bfin_boot)
 # define BFIN_BOOT_SPI_SSEL 1
 #endif
 
-/* Define to get a GPIO CS with the Blackfin SPI controller */
-#define MAX_CTRL_CS 8
-
 /* There is no Blackfin/NetBSD port */
 #undef CONFIG_BOOTM_NETBSD
 
diff --git a/arch/blackfin/include/asm/mach-common/bits/spi.h 
b/arch/blackfin/include/asm/mach-common/bits/spi.h
index 869dcb0..180cfaa 100644
--- a/arch/blackfin/include/asm/mach-common/bits/spi.h
+++ b/arch/blackfin/include/asm/mach-common/bits/spi.h
@@ -64,4 +64,5 @@
 #define RXS0x0020  /* SPI_RDBR Data Buffer Status 
(Full/Empty*) */
 #define TXCOL  0x0040  /* Transmit Collision Error (Corrupt 
Data May Have Been Sent) */
 
+#define MAX_CTRL_CS 7
 #endif
-- 
1.7.9.5

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


[U-Boot] [PATCH 1/3] blackfin: spi: move spi max chip select to spi.h

2014-06-05 Thread Scott Jiang
Signed-off-by: Scott Jiang scott.jiang.li...@gmail.com
---
 arch/blackfin/include/asm/config-pre.h   |3 ---
 arch/blackfin/include/asm/mach-common/bits/spi.h |1 +
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/arch/blackfin/include/asm/config-pre.h 
b/arch/blackfin/include/asm/config-pre.h
index d0fd537..0ffa44c 100644
--- a/arch/blackfin/include/asm/config-pre.h
+++ b/arch/blackfin/include/asm/config-pre.h
@@ -73,9 +73,6 @@ static inline const char *get_bfin_boot_mode(int bfin_boot)
 # define BFIN_BOOT_SPI_SSEL 1
 #endif
 
-/* Define to get a GPIO CS with the Blackfin SPI controller */
-#define MAX_CTRL_CS 8
-
 /* There is no Blackfin/NetBSD port */
 #undef CONFIG_BOOTM_NETBSD
 
diff --git a/arch/blackfin/include/asm/mach-common/bits/spi.h 
b/arch/blackfin/include/asm/mach-common/bits/spi.h
index 869dcb0..180cfaa 100644
--- a/arch/blackfin/include/asm/mach-common/bits/spi.h
+++ b/arch/blackfin/include/asm/mach-common/bits/spi.h
@@ -64,4 +64,5 @@
 #define RXS0x0020  /* SPI_RDBR Data Buffer Status 
(Full/Empty*) */
 #define TXCOL  0x0040  /* Transmit Collision Error (Corrupt 
Data May Have Been Sent) */
 
+#define MAX_CTRL_CS 7
 #endif
-- 
1.7.9.5


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


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

2014-06-05 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|   25 +-
 drivers/spi/bfin_spi6xx.c  |  279 ++--
 include/configs/bf609-ezkit.h  |1 +
 5 files changed, 260 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 (96%)

diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index 81b6af6..0ce6fc9 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -15,6 +15,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..41cd36c
--- /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 |= 1  slave-cs;
+   if (sdev-cs_pol)
+   ssel |= (1  8)  slave-cs;
+   else
+   ssel = ~((1  8)  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 = ~((1  8)  slave-cs);
+   else
+   ssel |= (1  8)  slave-cs;
+   /* deassert cs */
+   writel(ssel, sdev-regs-ssel);
+   /* disable cs */
+   ssel = ~(1  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)
+{
+   struct adi_spi_slave *sdev

[U-Boot] [PATCH 2/3] blackfin: spi clock is in sysclk1 domain instead of sysclk0

2014-06-05 Thread Scott Jiang
Signed-off-by: Scott Jiang scott.jiang.li...@gmail.com
---
 arch/blackfin/include/asm/clock.h |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/blackfin/include/asm/clock.h 
b/arch/blackfin/include/asm/clock.h
index 59d3faa..05ae03c 100644
--- a/arch/blackfin/include/asm/clock.h
+++ b/arch/blackfin/include/asm/clock.h
@@ -78,7 +78,7 @@ extern u_long get_sclk1(void);
 extern u_long get_dclk(void);
 # define get_uart_clk get_sclk0
 # define get_i2c_clk get_sclk0
-# define get_spi_clk get_sclk0
+# define get_spi_clk get_sclk1
 #else
 # define get_uart_clk get_sclk
 # define get_i2c_clk get_sclk
-- 
1.7.9.5


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


Re: [U-Boot] [PATCH 1/2] spi: bfin_spi: Remove unnecessary test for bus and pins[bus]

2013-12-01 Thread Scott Jiang
2013/11/30 Axel Lin axel@ingics.com:
 For invalid bus number, current code returns NULL in the default case of
 switch-case statements. In additional, pins[bus] is always not NULL because
 it is the address of specific row of the two-dimensional array.
 Thus this patch removes these unnecessary test.

 Signed-off-by: Axel Lin axel@ingics.com
 ---
 Also adjust the code position to avoid checkpatch.pl warning:
 ERROR: trailing statements should be on next line

  drivers/spi/bfin_spi.c | 17 +
  1 file changed, 9 insertions(+), 8 deletions(-)

 diff --git a/drivers/spi/bfin_spi.c b/drivers/spi/bfin_spi.c
 index bb88f30..aa89d89 100644
 --- a/drivers/spi/bfin_spi.c
 +++ b/drivers/spi/bfin_spi.c
 @@ -162,21 +162,22 @@ struct spi_slave *spi_setup_slave(unsigned int bus, 
 unsigned int cs,
 if (!spi_cs_is_valid(bus, cs))
 return NULL;

 -   if (bus = ARRAY_SIZE(pins) || pins[bus] == NULL) {
 -   debug(%s: invalid bus %u\n, __func__, bus);
 -   return NULL;
 -   }
 switch (bus) {
  #ifdef SPI0_CTL
 -   case 0: mmr_base = SPI0_CTL; break;
 +   case 0:
 +   mmr_base = SPI0_CTL; break;
  #endif
  #ifdef SPI1_CTL
 -   case 1: mmr_base = SPI1_CTL; break;
 +   case 1:
 +   mmr_base = SPI1_CTL; break;
  #endif
  #ifdef SPI2_CTL
 -   case 2: mmr_base = SPI2_CTL; break;
 +   case 2:
 +   mmr_base = SPI2_CTL; break;
  #endif
 -   default: return NULL;
 +   default:
 +   debug(%s: invalid bus %u\n, __func__, bus);
 +   return NULL;
 }

 bss = spi_alloc_slave(struct bfin_spi_slave, bus, cs);
 --

Acked-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: bfin_spi6xx: Remove unnecessary test for bus and pins[bus]

2013-12-01 Thread Scott Jiang
2013/11/30 Axel Lin axel@ingics.com:
 For invalid bus number, current code returns NULL in the default case of
 switch-case statements. In additional, pins[bus] is always not NULL because
 it is the address of specific row of the two-dimensional array.
 Thus this patch removes these unnecessary test.

 Signed-off-by: Axel Lin axel@ingics.com
 ---
  drivers/spi/bfin_spi6xx.c | 5 +
  1 file changed, 1 insertion(+), 4 deletions(-)

 diff --git a/drivers/spi/bfin_spi6xx.c b/drivers/spi/bfin_spi6xx.c
 index c25c4a9..07b833d 100644
 --- a/drivers/spi/bfin_spi6xx.c
 +++ b/drivers/spi/bfin_spi6xx.c
 @@ -154,10 +154,6 @@ struct spi_slave *spi_setup_slave(unsigned int bus, 
 unsigned int cs,
 if (!spi_cs_is_valid(bus, cs))
 return NULL;

 -   if (bus = ARRAY_SIZE(pins) || pins[bus] == NULL) {
 -   debug(%s: invalid bus %u\n, __func__, bus);
 -   return NULL;
 -   }
 switch (bus) {
  #ifdef SPI0_REGBASE
 case 0:
 @@ -175,6 +171,7 @@ struct spi_slave *spi_setup_slave(unsigned int bus, 
 unsigned int cs,
 break;
  #endif
 default:
 +   debug(%s: invalid bus %u\n, __func__, bus);
 return NULL;
 }


Acked-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 v1 1/2] bfin: Remove spi dma function in bf5xx.

2013-03-13 Thread Scott Jiang
Mike,

test case is [#6887], if you save data and read out to compare it
sometimes fail.
I agree that we can keep this patch, but it introduces problems to
test engineer.
This is a random error, she is difficult to know which board and which case we
should enable this function.

2013/3/12 Mike Frysinger vap...@gentoo.org:
 On Monday 04 March 2013 02:20:08 Sonic Zhang wrote:
 From: Scott Jiang scott.jiang.li...@gmail.com

 BF5xx rx dma causes spi flash random read error.
 Accually spi controller has problems both on tx and rx dma.
 So remove spi dma support in u-boot.

 this is wrong, and imo, unnecessary.  it's wrong because using DMA gains a lot
 of speed increases, and works for in many cases (i haven't seen cases where it
 didn't work, but i haven't been actively developing in the last year of
 course).  it's unnecessary because there's already a CONFIG_xxx option to
 disable it if your platform is having problems and you can't figure things 
 out,
 and don't need the speed gains.
 -mike
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot