public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/4] blackfin: the sclk MHz in i2c driver should be divided by 1000 other than 1024
@ 2014-01-28  5:53 Sonic Zhang
  2014-01-28  5:53 ` [U-Boot] [PATCH 2/4] blackfin: add spi and i2c specific get clock functions Sonic Zhang
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Sonic Zhang @ 2014-01-28  5:53 UTC (permalink / raw)
  To: u-boot

From: Sonic Zhang <sonic.zhang@analog.com>

Signed-off-by: Sonic Zhang <sonic.zhang@analog.com>
---
 drivers/i2c/bfin-twi_i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i2c/bfin-twi_i2c.c b/drivers/i2c/bfin-twi_i2c.c
index b3a04d3..5c37280 100644
--- a/drivers/i2c/bfin-twi_i2c.c
+++ b/drivers/i2c/bfin-twi_i2c.c
@@ -274,7 +274,7 @@ unsigned int i2c_get_bus_speed(void)
  */
 void i2c_init(int speed, int slaveaddr)
 {
-	uint8_t prescale = ((get_sclk() / 1024 / 1024 + 5) / 10) & 0x7F;
+	uint8_t prescale = ((get_sclk() / 1000 / 1000 + 5) / 10) & 0x7F;
 
 	/* Set TWI internal clock as 10MHz */
 	twi->control = prescale;
-- 
1.8.2.3

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [U-Boot] [PATCH 2/4] blackfin: add spi and i2c specific get clock functions
  2014-01-28  5:53 [U-Boot] [PATCH 1/4] blackfin: the sclk MHz in i2c driver should be divided by 1000 other than 1024 Sonic Zhang
@ 2014-01-28  5:53 ` Sonic Zhang
  2014-01-30  5:27   ` Heiko Schocher
  2014-01-28  5:53 ` [U-Boot] [PATCH 3/4] blackfin: rename bfin-twi_i2c driver to adi_i2c Sonic Zhang
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Sonic Zhang @ 2014-01-28  5:53 UTC (permalink / raw)
  To: u-boot

From: Sonic Zhang <sonic.zhang@analog.com>

Signed-off-by: Sonic Zhang <sonic.zhang@analog.com>
---
 arch/blackfin/include/asm/blackfin_local.h |  7 -------
 arch/blackfin/include/asm/clock.h          | 11 +++++++++++
 drivers/i2c/bfin-twi_i2c.c                 |  3 ++-
 drivers/spi/bfin_spi.c                     |  7 ++++---
 drivers/spi/bfin_spi6xx.c                  |  7 ++++---
 5 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/arch/blackfin/include/asm/blackfin_local.h b/arch/blackfin/include/asm/blackfin_local.h
index 4d6eeab..868c82e 100644
--- a/arch/blackfin/include/asm/blackfin_local.h
+++ b/arch/blackfin/include/asm/blackfin_local.h
@@ -42,13 +42,6 @@
 
 # include <linux/types.h>
 
-extern u_long get_vco(void);
-extern u_long get_cclk(void);
-extern u_long get_sclk(void);
-extern u_long get_sclk0(void);
-extern u_long get_sclk1(void);
-extern u_long get_dclk(void);
-
 # define bfin_revid() (bfin_read_CHIPID() >> 28)
 
 extern int bfin_os_log_check(void);
diff --git a/arch/blackfin/include/asm/clock.h b/arch/blackfin/include/asm/clock.h
index fc84fe4..59d3faa 100644
--- a/arch/blackfin/include/asm/clock.h
+++ b/arch/blackfin/include/asm/clock.h
@@ -68,10 +68,21 @@ static inline uint32_t early_get_uart_clk(void)
 	return uclk;
 }
 
+extern u_long get_vco(void);
+extern u_long get_cclk(void);
+extern u_long get_sclk(void);
+
 #ifdef CGU_DIV
+extern u_long get_sclk0(void);
+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
 #else
 # define get_uart_clk get_sclk
+# define get_i2c_clk get_sclk
+# define get_spi_clk get_sclk
 #endif
 
 #endif
diff --git a/drivers/i2c/bfin-twi_i2c.c b/drivers/i2c/bfin-twi_i2c.c
index 5c37280..cfab064 100644
--- a/drivers/i2c/bfin-twi_i2c.c
+++ b/drivers/i2c/bfin-twi_i2c.c
@@ -10,6 +10,7 @@
 #include <i2c.h>
 
 #include <asm/blackfin.h>
+#include <asm/clock.h>
 #include <asm/mach-common/bits/twi.h>
 
 /* Every register is 32bit aligned, but only 16bits in size */
@@ -274,7 +275,7 @@ unsigned int i2c_get_bus_speed(void)
  */
 void i2c_init(int speed, int slaveaddr)
 {
-	uint8_t prescale = ((get_sclk() / 1000 / 1000 + 5) / 10) & 0x7F;
+	uint8_t prescale = ((get_i2c_clk() / 1000 / 1000 + 5) / 10) & 0x7F;
 
 	/* Set TWI internal clock as 10MHz */
 	twi->control = prescale;
diff --git a/drivers/spi/bfin_spi.c b/drivers/spi/bfin_spi.c
index aa89d89..71a31d0 100644
--- a/drivers/spi/bfin_spi.c
+++ b/drivers/spi/bfin_spi.c
@@ -13,6 +13,7 @@
 #include <spi.h>
 
 #include <asm/blackfin.h>
+#include <asm/clock.h>
 #include <asm/gpio.h>
 #include <asm/portmux.h>
 #include <asm/mach-common/bits/spi.h>
@@ -140,12 +141,12 @@ static const unsigned short cs_pins[][7] = {
 void spi_set_speed(struct spi_slave *slave, uint hz)
 {
 	struct bfin_spi_slave *bss = to_bfin_spi_slave(slave);
-	ulong sclk;
+	ulong clk;
 	u32 baud;
 
-	sclk = get_sclk();
+	clk = get_spi_clk();
 	/* baud should be rounded up */
-	baud = DIV_ROUND_UP(sclk, 2 * hz);
+	baud = DIV_ROUND_UP(clk, 2 * hz);
 	if (baud < 2)
 		baud = 2;
 	else if (baud > (u16)-1)
diff --git a/drivers/spi/bfin_spi6xx.c b/drivers/spi/bfin_spi6xx.c
index 07b833d..eba01d1 100644
--- a/drivers/spi/bfin_spi6xx.c
+++ b/drivers/spi/bfin_spi6xx.c
@@ -22,6 +22,7 @@
 #include <spi.h>
 
 #include <asm/blackfin.h>
+#include <asm/clock.h>
 #include <asm/gpio.h>
 #include <asm/portmux.h>
 #include <asm/mach-common/bits/spi6xx.h>
@@ -135,11 +136,11 @@ static const unsigned short cs_pins[][7] = {
 void spi_set_speed(struct spi_slave *slave, uint hz)
 {
 	struct bfin_spi_slave *bss = to_bfin_spi_slave(slave);
-	ulong sclk;
+	ulong clk;
 	u32 clock;
 
-	sclk = get_sclk1();
-	clock = sclk / hz;
+	clk = get_spi_clk();
+	clock = clk / hz;
 	if (clock)
 		clock--;
 	bss->clock = clock;
-- 
1.8.2.3

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [U-Boot] [PATCH 3/4] blackfin: rename bfin-twi_i2c driver to adi_i2c
  2014-01-28  5:53 [U-Boot] [PATCH 1/4] blackfin: the sclk MHz in i2c driver should be divided by 1000 other than 1024 Sonic Zhang
  2014-01-28  5:53 ` [U-Boot] [PATCH 2/4] blackfin: add spi and i2c specific get clock functions Sonic Zhang
@ 2014-01-28  5:53 ` Sonic Zhang
  2014-01-30  5:28   ` Heiko Schocher
  2014-01-28  5:53 ` [U-Boot] [PATCH 4/4] blackfin: make i2c driver blackfin independant Sonic Zhang
  2014-01-30  5:27 ` [U-Boot] [PATCH 1/4] blackfin: the sclk MHz in i2c driver should be divided by 1000 other than 1024 Heiko Schocher
  3 siblings, 1 reply; 8+ messages in thread
From: Sonic Zhang @ 2014-01-28  5:53 UTC (permalink / raw)
  To: u-boot

From: Sonic Zhang <sonic.zhang@analog.com>

The ADI twi peripheral is not binding to Blackfin processor only. 
Change to a generic name.

Signed-off-by: Sonic Zhang <sonic.zhang@analog.com>
---
 arch/blackfin/include/asm/twi.h           | 15 +++++++++++++++
 drivers/i2c/Makefile                      |  2 +-
 drivers/i2c/{bfin-twi_i2c.c => adi_i2c.c} |  3 +--
 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 +-
 24 files changed, 38 insertions(+), 24 deletions(-)
 create mode 100644 arch/blackfin/include/asm/twi.h
 rename drivers/i2c/{bfin-twi_i2c.c => adi_i2c.c} (99%)

diff --git a/arch/blackfin/include/asm/twi.h b/arch/blackfin/include/asm/twi.h
new file mode 100644
index 0000000..922cdbd
--- /dev/null
+++ b/arch/blackfin/include/asm/twi.h
@@ -0,0 +1,15 @@
+/*
+ * i2c.c - driver for Blackfin on-chip TWI/I2C
+ *
+ * Copyright (c) 2006-2010 Analog Devices Inc.
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#ifndef __ARCH_TWI_H
+#define __ARCH_TWI_H
+
+#include <asm/blackfin.h>
+#include <asm/mach-common/bits/twi.h>
+
+#endif
diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
index fa3a875..4bf4d2e 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_DRIVER_DAVINCI_I2C) += davinci_i2c.o
 obj-$(CONFIG_DW_I2C) += designware_i2c.o
 obj-$(CONFIG_I2C_MVTWSI) += mvtwsi.o
diff --git a/drivers/i2c/bfin-twi_i2c.c b/drivers/i2c/adi_i2c.c
similarity index 99%
rename from drivers/i2c/bfin-twi_i2c.c
rename to drivers/i2c/adi_i2c.c
index cfab064..743aa25 100644
--- a/drivers/i2c/bfin-twi_i2c.c
+++ b/drivers/i2c/adi_i2c.c
@@ -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 5b09b45..93a713b 100644
--- a/include/configs/bct-brettl2.h
+++ b/include/configs/bct-brettl2.h
@@ -121,7 +121,7 @@
 /*
  * I2C Settings
  */
-#define CONFIG_BFIN_TWI_I2C	1
+#define CONFIG_ADI_I2C		1
 #define CONFIG_HARD_I2C		1
 
 
diff --git a/include/configs/bf518f-ezbrd.h b/include/configs/bf518f-ezbrd.h
index a97972b..4b94ba5 100644
--- a/include/configs/bf518f-ezbrd.h
+++ b/include/configs/bf518f-ezbrd.h
@@ -134,7 +134,7 @@
 /*
  * I2C Settings
  */
-#define CONFIG_BFIN_TWI_I2C	1
+#define CONFIG_ADI_I2C		1
 #define CONFIG_HARD_I2C		1
 
 
diff --git a/include/configs/bf526-ezbrd.h b/include/configs/bf526-ezbrd.h
index 0031093..54f26f4 100644
--- a/include/configs/bf526-ezbrd.h
+++ b/include/configs/bf526-ezbrd.h
@@ -131,7 +131,7 @@
 /*
  * I2C Settings
  */
-#define CONFIG_BFIN_TWI_I2C	1
+#define CONFIG_ADI_I2C		1
 #define CONFIG_HARD_I2C		1
 
 
diff --git a/include/configs/bf527-ad7160-eval.h b/include/configs/bf527-ad7160-eval.h
index fa05103..ca6b0d5 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_I2C	1
+#define CONFIG_ADI_I2C		1
 #define CONFIG_HARD_I2C		1
 
 
diff --git a/include/configs/bf527-ezkit.h b/include/configs/bf527-ezkit.h
index db1b613..7ec5b02 100644
--- a/include/configs/bf527-ezkit.h
+++ b/include/configs/bf527-ezkit.h
@@ -134,7 +134,7 @@
 /*
  * I2C Settings
  */
-#define CONFIG_BFIN_TWI_I2C	1
+#define CONFIG_ADI_I2C		1
 #define CONFIG_HARD_I2C		1
 
 
diff --git a/include/configs/bf527-sdp.h b/include/configs/bf527-sdp.h
index c0e8b5a..96629d4 100644
--- a/include/configs/bf527-sdp.h
+++ b/include/configs/bf527-sdp.h
@@ -103,7 +103,7 @@
 /*
  * I2C Settings
  */
-#define CONFIG_BFIN_TWI_I2C	1
+#define CONFIG_ADI_I2C		1
 #define CONFIG_HARD_I2C		1
 
 
diff --git a/include/configs/bf537-minotaur.h b/include/configs/bf537-minotaur.h
index 156eeab..2b2f79c 100644
--- a/include/configs/bf537-minotaur.h
+++ b/include/configs/bf537-minotaur.h
@@ -120,7 +120,7 @@
 /*
  * I2C settings
  */
-#define CONFIG_BFIN_TWI_I2C	1
+#define CONFIG_ADI_I2C		1
 #define CONFIG_HARD_I2C		1
 #define CONFIG_SYS_I2C_SPEED		50000
 #define CONFIG_SYS_I2C_SLAVE		0
diff --git a/include/configs/bf537-pnav.h b/include/configs/bf537-pnav.h
index 3aa3d50..c81572c 100644
--- a/include/configs/bf537-pnav.h
+++ b/include/configs/bf537-pnav.h
@@ -142,7 +142,7 @@
 /*
  * I2C settings
  */
-#define CONFIG_BFIN_TWI_I2C	1
+#define CONFIG_ADI_I2C		1
 #define CONFIG_HARD_I2C		1
 
 
diff --git a/include/configs/bf537-srv1.h b/include/configs/bf537-srv1.h
index e12d761..08bc030 100644
--- a/include/configs/bf537-srv1.h
+++ b/include/configs/bf537-srv1.h
@@ -120,7 +120,7 @@
 /*
  * I2C settings
  */
-#define CONFIG_BFIN_TWI_I2C	1
+#define CONFIG_ADI_I2C		1
 #define CONFIG_HARD_I2C		1
 #define CONFIG_SYS_I2C_SPEED		50000
 #define CONFIG_SYS_I2C_SLAVE		0
diff --git a/include/configs/bf537-stamp.h b/include/configs/bf537-stamp.h
index 02945be..f32359a 100644
--- a/include/configs/bf537-stamp.h
+++ b/include/configs/bf537-stamp.h
@@ -128,7 +128,7 @@
 /*
  * I2C Settings
  */
-#define CONFIG_BFIN_TWI_I2C	1
+#define CONFIG_ADI_I2C		1
 #define CONFIG_HARD_I2C		1
 
 
diff --git a/include/configs/bf538f-ezkit.h b/include/configs/bf538f-ezkit.h
index ffb0caf..e0bcd40 100644
--- a/include/configs/bf538f-ezkit.h
+++ b/include/configs/bf538f-ezkit.h
@@ -125,7 +125,7 @@
 /*
  * I2C Settings
  */
-#define CONFIG_BFIN_TWI_I2C	1
+#define CONFIG_ADI_I2C		1
 #define CONFIG_HARD_I2C		1
 
 
diff --git a/include/configs/bf548-ezkit.h b/include/configs/bf548-ezkit.h
index da5f029..c54d2fa 100644
--- a/include/configs/bf548-ezkit.h
+++ b/include/configs/bf548-ezkit.h
@@ -134,7 +134,7 @@
 /*
  * I2C Settings
  */
-#define CONFIG_BFIN_TWI_I2C	1
+#define CONFIG_ADI_I2C		1
 #define CONFIG_HARD_I2C		1
 
 
diff --git a/include/configs/bf609-ezkit.h b/include/configs/bf609-ezkit.h
index 1a43e1b..6156ddb 100644
--- a/include/configs/bf609-ezkit.h
+++ b/include/configs/bf609-ezkit.h
@@ -80,7 +80,7 @@
 #define CONFIG_MII
 
 /* i2c Settings */
-#define CONFIG_BFIN_TWI_I2C
+#define CONFIG_ADI_I2C
 #define CONFIG_HARD_I2C
 
 /*
diff --git a/include/configs/br4.h b/include/configs/br4.h
index ef3752d..f220eb5 100644
--- a/include/configs/br4.h
+++ b/include/configs/br4.h
@@ -102,7 +102,7 @@
 /*
  * I2C Settings
  */
-#define CONFIG_BFIN_TWI_I2C
+#define CONFIG_ADI_I2C
 #define CONFIG_HARD_I2C
 
 
diff --git a/include/configs/cm-bf527.h b/include/configs/cm-bf527.h
index b15a1eb..c4f2f1f 100644
--- a/include/configs/cm-bf527.h
+++ b/include/configs/cm-bf527.h
@@ -113,7 +113,7 @@
 /*
  * I2C Settings
  */
-#define CONFIG_BFIN_TWI_I2C	1
+#define CONFIG_ADI_I2C		1
 #define CONFIG_HARD_I2C		1
 
 
diff --git a/include/configs/cm-bf537e.h b/include/configs/cm-bf537e.h
index 2838012..de839c4 100644
--- a/include/configs/cm-bf537e.h
+++ b/include/configs/cm-bf537e.h
@@ -122,7 +122,7 @@
 /*
  * I2C Settings
  */
-#define CONFIG_BFIN_TWI_I2C	1
+#define CONFIG_ADI_I2C		1
 #define CONFIG_HARD_I2C		1
 
 
diff --git a/include/configs/cm-bf537u.h b/include/configs/cm-bf537u.h
index da4cc67..9d65e7b 100644
--- a/include/configs/cm-bf537u.h
+++ b/include/configs/cm-bf537u.h
@@ -120,7 +120,7 @@
 /*
  * I2C Settings
  */
-#define CONFIG_BFIN_TWI_I2C	1
+#define CONFIG_ADI_I2C		1
 #define CONFIG_HARD_I2C		1
 
 
diff --git a/include/configs/cm-bf548.h b/include/configs/cm-bf548.h
index 7f27eda..7c9d1cd 100644
--- a/include/configs/cm-bf548.h
+++ b/include/configs/cm-bf548.h
@@ -104,7 +104,7 @@
 /*
  * I2C Settings
  */
-#define CONFIG_BFIN_TWI_I2C	1
+#define CONFIG_ADI_I2C		1
 #define CONFIG_HARD_I2C		1
 
 
diff --git a/include/configs/pr1.h b/include/configs/pr1.h
index 03d4269..37f3fab 100644
--- a/include/configs/pr1.h
+++ b/include/configs/pr1.h
@@ -102,7 +102,7 @@
 /*
  * I2C Settings
  */
-#define CONFIG_BFIN_TWI_I2C
+#define CONFIG_ADI_I2C
 #define CONFIG_HARD_I2C
 
 
diff --git a/include/configs/tcm-bf518.h b/include/configs/tcm-bf518.h
index 241f210..8d835b4 100644
--- a/include/configs/tcm-bf518.h
+++ b/include/configs/tcm-bf518.h
@@ -103,7 +103,7 @@
 /*
  * I2C Settings
  */
-#define CONFIG_BFIN_TWI_I2C	1
+#define CONFIG_ADI_I2C		1
 #define CONFIG_HARD_I2C		1
 
 
diff --git a/include/configs/tcm-bf537.h b/include/configs/tcm-bf537.h
index 58bcdc8..7d1ee77 100644
--- a/include/configs/tcm-bf537.h
+++ b/include/configs/tcm-bf537.h
@@ -122,7 +122,7 @@
 /*
  * I2C Settings
  */
-#define CONFIG_BFIN_TWI_I2C	1
+#define CONFIG_ADI_I2C		1
 #define CONFIG_HARD_I2C		1
 
 
-- 
1.8.2.3

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [U-Boot] [PATCH 4/4] blackfin: make i2c driver blackfin independant
  2014-01-28  5:53 [U-Boot] [PATCH 1/4] blackfin: the sclk MHz in i2c driver should be divided by 1000 other than 1024 Sonic Zhang
  2014-01-28  5:53 ` [U-Boot] [PATCH 2/4] blackfin: add spi and i2c specific get clock functions Sonic Zhang
  2014-01-28  5:53 ` [U-Boot] [PATCH 3/4] blackfin: rename bfin-twi_i2c driver to adi_i2c Sonic Zhang
@ 2014-01-28  5:53 ` Sonic Zhang
  2014-01-30  5:28   ` Heiko Schocher
  2014-01-30  5:27 ` [U-Boot] [PATCH 1/4] blackfin: the sclk MHz in i2c driver should be divided by 1000 other than 1024 Heiko Schocher
  3 siblings, 1 reply; 8+ messages in thread
From: Sonic Zhang @ 2014-01-28  5:53 UTC (permalink / raw)
  To: u-boot

From: Scott Jiang <scott.jiang.linux@gmail.com>

The ADI twi peripheral is not binding to Blackfin processor only.
Access i2c registers by standard io functions.
Fix coding style.

Signed-off-by: Scott Jiang <scott.jiang.linux@gmail.com>
Signed-off-by: Sonic Zhang <sonic.zhang@analog.com>
---
 drivers/i2c/adi_i2c.c | 151 ++++++++++++++++++++++++++------------------------
 1 file changed, 80 insertions(+), 71 deletions(-)

diff --git a/drivers/i2c/adi_i2c.c b/drivers/i2c/adi_i2c.c
index 743aa25..675f417 100644
--- a/drivers/i2c/adi_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-2013 Analog Devices Inc.
  *
  * Licensed under the GPL-2 or later.
  */
@@ -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%02x alen=%i buf[0]=0x%02x len=%i flags=0x%02x[%s] ",
-		chip, addr, alen, buffer[0], len, flags, (flags & I2C_M_READ ? "rd" : "wr"));
+	debugi("chip=0x%x addr=0x%02x alen=%i buf[0]=0x%02x len=%i ",
+		chip, addr, alen, buffer[0], len);
+	debugi("flags=0x%02x[%s] ", flags,
+		(flags & I2C_M_READ ? "rd" : "wr"));
 
 	/* wait for things to settle */
-	while (twi->master_stat & BUSBUSY)
+	while (readw(&twi->master_stat) & BUSBUSY)
 		if (ctrlc())
 			return 1;
 
 	/* Set Transmit device address */
-	twi->master_addr = chip;
+	writew(chip, &twi->master_addr);
 
 	/* Clear the FIFO before starting things */
-	twi->fifo_ctl = XMTFLUSH | RCVFLUSH;
-	SSYNC();
-	twi->fifo_ctl = 0;
-	SSYNC();
+	writew(XMTFLUSH | RCVFLUSH, &twi->fifo_ctl);
+	writew(0, &twi->fifo_ctl);
 
 	/* prime the pump */
 	if (msg.alen) {
 		len = (msg.flags & I2C_M_COMBO) ? msg.alen : msg.alen + len;
 		debugi("first byte=0x%02x", *msg.abuf);
-		twi->xmt_data8 = *(msg.abuf++);
+		writew(*(msg.abuf++), &twi->xmt_data8);
 		--msg.alen;
 	} else if (!(msg.flags & I2C_M_READ) && msg.len) {
 		debugi("first byte=0x%02x", *msg.buf);
-		twi->xmt_data8 = *(msg.buf++);
+		writew(*(msg.buf++), &twi->xmt_data8);
 		--msg.len;
 	}
 
 	/* clear int stat */
-	twi->master_stat = -1;
-	twi->int_stat = -1;
-	twi->int_mask = 0;
-	SSYNC();
+	writew(-1, &twi->master_stat);
+	writew(-1, &twi->int_stat);
+	writew(0, &twi->int_mask);
 
 	/* Master enable */
-	twi->master_ctl =
-			(twi->master_ctl & FAST) |
-			(min(len, 0xff) << 6) | MEN |
-			((msg.flags & I2C_M_READ) ? MDIR : 0);
-	SSYNC();
-	debugi("CTL=0x%04x", twi->master_ctl);
+	ctl = readw(&twi->master_ctl);
+	ctl = (ctl & FAST) | (min(len, 0xff) << 6) | MEN |
+		((msg.flags & I2C_M_READ) ? MDIR : 0);
+	writew(ctl, &twi->master_ctl);
 
 	/* process the rest */
 	ret = wait_for_completion(&msg);
 	debugi("ret=%d", ret);
 
 	if (ret) {
-		twi->master_ctl &= ~MEN;
-		twi->control &= ~TWI_ENA;
-		SSYNC();
-		twi->control |= TWI_ENA;
-		SSYNC();
+		ctl = readw(&twi->master_ctl) & ~MEN;
+		writew(ctl, &twi->master_ctl);
+		ctl = readw(&twi->control) & ~TWI_ENA;
+		writew(ctl, &twi->control);
+		ctl = readw(&twi->control) | TWI_ENA;
+		writew(ctl, &twi->control);
 	}
 
 	return ret;
@@ -246,10 +248,11 @@ int i2c_set_bus_speed(unsigned int speed)
 	/* Set TWI interface clock */
 	if (clkdiv < I2C_DUTY_MAX || clkdiv > I2C_DUTY_MIN)
 		return -1;
-	twi->clkdiv = (clkdiv << 8) | (clkdiv & 0xff);
+	clkdiv = (clkdiv << 8) | (clkdiv & 0xff);
+	writew(clkdiv, &twi->clkdiv);
 
 	/* Don't turn it on */
-	twi->master_ctl = (speed > 100000 ? FAST : 0);
+	writew(speed > 100000 ? FAST : 0, &twi->master_ctl);
 
 	return 0;
 }
@@ -260,8 +263,9 @@ int i2c_set_bus_speed(unsigned int speed)
  */
 unsigned int i2c_get_bus_speed(void)
 {
+	u16 clkdiv = readw(&twi->clkdiv) & 0xff;
 	/* 10 MHz / (2 * CLKDIV) -> 5 MHz / CLKDIV */
-	return 5000000 / (twi->clkdiv & 0xff);
+	return 5000000 / clkdiv;
 }
 
 /**
@@ -274,27 +278,22 @@ unsigned int i2c_get_bus_speed(void)
  */
 void i2c_init(int speed, int slaveaddr)
 {
-	uint8_t prescale = ((get_i2c_clk() / 1000 / 1000 + 5) / 10) & 0x7F;
+	u16 prescale = ((get_i2c_clk() / 1000 / 1000 + 5) / 10) & 0x7F;
 
 	/* Set TWI internal clock as 10MHz */
-	twi->control = prescale;
+	writew(prescale, &twi->control);
 
 	/* Set TWI interface clock as specified */
 	i2c_set_bus_speed(speed);
 
 	/* Enable it */
-	twi->control = TWI_ENA | prescale;
-	SSYNC();
+	writew(TWI_ENA | prescale, &twi->control);
 
-	debugi("CONTROL:0x%04x CLKDIV:0x%04x", twi->control, twi->clkdiv);
+	debugi("CONTROL:0x%04x CLKDIV:0x%04x", readw(&twi->control),
+		readw(&twi->clkdiv));
 
 #if CONFIG_SYS_I2C_SLAVE
 # error I2C slave support not tested/supported
-	/* If they want us as a slave, do it */
-	if (slaveaddr) {
-		twi->slave_addr = slaveaddr;
-		twi->slave_ctl = SEN;
-	}
 #endif
 }
 
@@ -320,7 +319,8 @@ int i2c_probe(uchar chip)
  */
 int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len)
 {
-	return i2c_transfer(chip, addr, alen, buffer, len, (alen ? I2C_M_COMBO : I2C_M_READ));
+	return i2c_transfer(chip, addr, alen, buffer,
+			len, (alen ? I2C_M_COMBO : I2C_M_READ));
 }
 
 /**
@@ -346,15 +346,21 @@ int i2c_set_bus_num(unsigned int bus)
 {
 	switch (bus) {
 #if CONFIG_SYS_MAX_I2C_BUS > 0
-		case 0: twi = (void *)TWI0_CLKDIV; return 0;
+	case 0:
+		twi = (void *)TWI0_CLKDIV;
+		return 0;
 #endif
 #if CONFIG_SYS_MAX_I2C_BUS > 1
-		case 1: twi = (void *)TWI1_CLKDIV; return 0;
+	case 1:
+		twi = (void *)TWI1_CLKDIV;
+		return 0;
 #endif
 #if CONFIG_SYS_MAX_I2C_BUS > 2
-		case 2: twi = (void *)TWI2_CLKDIV; return 0;
+	case 2:
+		twi = (void *)TWI2_CLKDIV;
+		return 0;
 #endif
-		default: return -1;
+	default: return -1;
 	}
 }
 
@@ -365,14 +371,17 @@ unsigned int i2c_get_bus_num(void)
 {
 	switch ((unsigned long)twi) {
 #if CONFIG_SYS_MAX_I2C_BUS > 0
-		case TWI0_CLKDIV: return 0;
+	case TWI0_CLKDIV:
+		return 0;
 #endif
 #if CONFIG_SYS_MAX_I2C_BUS > 1
-		case TWI1_CLKDIV: return 1;
+	case TWI1_CLKDIV:
+		return 1;
 #endif
 #if CONFIG_SYS_MAX_I2C_BUS > 2
-		case TWI2_CLKDIV: return 2;
+	case TWI2_CLKDIV:
+		return 2;
 #endif
-		default: return -1;
+	default: return -1;
 	}
 }
-- 
1.8.2.3

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [U-Boot] [PATCH 1/4] blackfin: the sclk MHz in i2c driver should be divided by 1000 other than 1024
  2014-01-28  5:53 [U-Boot] [PATCH 1/4] blackfin: the sclk MHz in i2c driver should be divided by 1000 other than 1024 Sonic Zhang
                   ` (2 preceding siblings ...)
  2014-01-28  5:53 ` [U-Boot] [PATCH 4/4] blackfin: make i2c driver blackfin independant Sonic Zhang
@ 2014-01-30  5:27 ` Heiko Schocher
  3 siblings, 0 replies; 8+ messages in thread
From: Heiko Schocher @ 2014-01-30  5:27 UTC (permalink / raw)
  To: u-boot

Hello Sonic,

Am 28.01.2014 06:53, schrieb Sonic Zhang:
> From: Sonic Zhang<sonic.zhang@analog.com>
>
> Signed-off-by: Sonic Zhang<sonic.zhang@analog.com>
> ---
>   drivers/i2c/bfin-twi_i2c.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)


Applied to u-boot-i2c.git, thanks!

bye,
Heiko
-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [U-Boot] [PATCH 2/4] blackfin: add spi and i2c specific get clock functions
  2014-01-28  5:53 ` [U-Boot] [PATCH 2/4] blackfin: add spi and i2c specific get clock functions Sonic Zhang
@ 2014-01-30  5:27   ` Heiko Schocher
  0 siblings, 0 replies; 8+ messages in thread
From: Heiko Schocher @ 2014-01-30  5:27 UTC (permalink / raw)
  To: u-boot

Hello Sonic,

Am 28.01.2014 06:53, schrieb Sonic Zhang:
> From: Sonic Zhang<sonic.zhang@analog.com>
>
> Signed-off-by: Sonic Zhang<sonic.zhang@analog.com>
> ---
>   arch/blackfin/include/asm/blackfin_local.h |  7 -------
>   arch/blackfin/include/asm/clock.h          | 11 +++++++++++
>   drivers/i2c/bfin-twi_i2c.c                 |  3 ++-
>   drivers/spi/bfin_spi.c                     |  7 ++++---
>   drivers/spi/bfin_spi6xx.c                  |  7 ++++---
>   5 files changed, 21 insertions(+), 14 deletions(-)


Applied to u-boot-i2c.git, thanks!

bye,
Heiko
-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [U-Boot] [PATCH 3/4] blackfin: rename bfin-twi_i2c driver to adi_i2c
  2014-01-28  5:53 ` [U-Boot] [PATCH 3/4] blackfin: rename bfin-twi_i2c driver to adi_i2c Sonic Zhang
@ 2014-01-30  5:28   ` Heiko Schocher
  0 siblings, 0 replies; 8+ messages in thread
From: Heiko Schocher @ 2014-01-30  5:28 UTC (permalink / raw)
  To: u-boot

Hello Sonic,

Am 28.01.2014 06:53, schrieb Sonic Zhang:
> From: Sonic Zhang<sonic.zhang@analog.com>
>
> The ADI twi peripheral is not binding to Blackfin processor only.
> Change to a generic name.
>
> Signed-off-by: Sonic Zhang<sonic.zhang@analog.com>
> ---
>   arch/blackfin/include/asm/twi.h           | 15 +++++++++++++++
>   drivers/i2c/Makefile                      |  2 +-
>   drivers/i2c/{bfin-twi_i2c.c =>  adi_i2c.c} |  3 +--
>   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 +-
>   24 files changed, 38 insertions(+), 24 deletions(-)
>   create mode 100644 arch/blackfin/include/asm/twi.h
>   rename drivers/i2c/{bfin-twi_i2c.c =>  adi_i2c.c} (99%)


Applied to u-boot-i2c.git, thanks!

bye,
Heiko
-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [U-Boot] [PATCH 4/4] blackfin: make i2c driver blackfin independant
  2014-01-28  5:53 ` [U-Boot] [PATCH 4/4] blackfin: make i2c driver blackfin independant Sonic Zhang
@ 2014-01-30  5:28   ` Heiko Schocher
  0 siblings, 0 replies; 8+ messages in thread
From: Heiko Schocher @ 2014-01-30  5:28 UTC (permalink / raw)
  To: u-boot

Hello Sonic,

Am 28.01.2014 06:53, schrieb Sonic Zhang:
> From: Scott Jiang<scott.jiang.linux@gmail.com>
>
> The ADI twi peripheral is not binding to Blackfin processor only.
> Access i2c registers by standard io functions.
> Fix coding style.
>
> Signed-off-by: Scott Jiang<scott.jiang.linux@gmail.com>
> Signed-off-by: Sonic Zhang<sonic.zhang@analog.com>
> ---
>   drivers/i2c/adi_i2c.c | 151 ++++++++++++++++++++++++++------------------------
>   1 file changed, 80 insertions(+), 71 deletions(-)


Applied to u-boot-i2c.git, thanks!

bye,
Heiko
-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-01-30  5:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-28  5:53 [U-Boot] [PATCH 1/4] blackfin: the sclk MHz in i2c driver should be divided by 1000 other than 1024 Sonic Zhang
2014-01-28  5:53 ` [U-Boot] [PATCH 2/4] blackfin: add spi and i2c specific get clock functions Sonic Zhang
2014-01-30  5:27   ` Heiko Schocher
2014-01-28  5:53 ` [U-Boot] [PATCH 3/4] blackfin: rename bfin-twi_i2c driver to adi_i2c Sonic Zhang
2014-01-30  5:28   ` Heiko Schocher
2014-01-28  5:53 ` [U-Boot] [PATCH 4/4] blackfin: make i2c driver blackfin independant Sonic Zhang
2014-01-30  5:28   ` Heiko Schocher
2014-01-30  5:27 ` [U-Boot] [PATCH 1/4] blackfin: the sclk MHz in i2c driver should be divided by 1000 other than 1024 Heiko Schocher

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox