From: "Jérôme Carretero" <cJ-uboot@zougloub.eu>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC] [PATCH] DaVinci/i2c: allow multiple buses
Date: Thu, 22 Dec 2011 00:36:52 -0500 [thread overview]
Message-ID: <20111222003652.69df8888@zougloub.eu> (raw)
Hi Tom,
I'm requesting comments on the following (untested) patch.
It adds support for multiple i2c buses on davinci_i2c, without altering one line of code.
What I don't like is that I'm doing a bit of macro black magic to transform constants into variables.
But I don't know whether refactoring the code would be accepted, so this is a first shot.
Regards,
--
cJ
commit 53d99d331dc7fc4bf3384a59bbca564bf1b85f6b
Author: Jerome Carretero <cJ-uboot@zougloub.eu>
Date: Thu Dec 22 00:26:13 2011 -0500
DaVinci/i2c: Support for multiple buses
diff --git a/arch/arm/include/asm/arch-davinci/i2c_defs.h b/arch/arm/include/asm/arch-davinci/i2c_defs.h
index 24cd268..1d24fbf 100644
--- a/arch/arm/include/asm/arch-davinci/i2c_defs.h
+++ b/arch/arm/include/asm/arch-davinci/i2c_defs.h
@@ -25,13 +25,18 @@
#ifndef _DAVINCI_I2C_H_
#define _DAVINCI_I2C_H_
+#include <asm/arch/hardware.h>
+
#define I2C_WRITE 0
#define I2C_READ 1
#ifndef CONFIG_SOC_DA8XX
-#define I2C_BASE 0x01c21000
+# define I2C_BASE DAVINCI_I2C_BASE
+# define I2C_DEFAULT_BASE I2C_BASE
#else
-#define I2C_BASE 0x01c22000
+# define I2C_BASE0 DAVINCI_I2C0_BASE
+# define I2C_BASE1 DAVINCI_I2C1_BASE
+# define I2C_DEFAULT_BASE I2C_BASE0
#endif
#define I2C_OA (I2C_BASE + 0x00)
diff --git a/drivers/i2c/davinci_i2c.c b/drivers/i2c/davinci_i2c.c
index 2abddfb..be7fb7a 100644
--- a/drivers/i2c/davinci_i2c.c
+++ b/drivers/i2c/davinci_i2c.c
@@ -29,6 +29,44 @@
#include <asm/arch/hardware.h>
#include <asm/arch/i2c_defs.h>
+#if defined(CONFIG_I2C_MULTI_BUS)
+
+static unsigned int bus_initialized[I2C_BUS_MAX];
+static unsigned int current_bus;
+static unsigned long i2c_base = I2C_DEFAULT_BASE;
+
+#ifndef I2C_BASE
+# define I2C_BASE i2c_base
+#else
+# error CONFIG_I2C_MULTI_BUS *and* I2C_BASE defined !
+#endif
+
+int i2c_set_bus_num(unsigned int bus)
+{
+ if ((bus < 0) || (bus >= I2C_BUS_MAX)) { // TODO where to put I2C_BUS_MAX ?
+ printf("Bad bus: %d\n", bus);
+ return -1;
+ }
+
+ if (bus == 1)
+ i2c_base = I2C_BASE1;
+ else
+ i2c_base = I2C_BASE0;
+
+ current_bus = bus;
+
+ if (!bus_initialized[current_bus])
+ i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
+ return 0;
+}
+
+unsigned int i2c_get_bus_num(void)
+{
+ return current_bus;
+}
+
+#endif
+
#define CHECK_NACK() \
do {\
if (tmp & (I2C_TIMEOUT | I2C_STAT_NACK)) {\
next reply other threads:[~2011-12-22 5:36 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-22 5:36 Jérôme Carretero [this message]
2012-01-05 19:46 ` [U-Boot] [RFC] [PATCH] DaVinci/i2c: allow multiple buses Tom Rini
2012-01-11 6:52 ` Heiko Schocher
2012-01-11 13:30 ` Jérôme Carretero
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111222003652.69df8888@zougloub.eu \
--to=cj-uboot@zougloub.eu \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox