summaryrefslogtreecommitdiff
path: root/include/i2c.h
diff options
context:
space:
mode:
authorKim Phillips <kim.phillips@freescale.com>2009-01-21 18:38:51 -0600
committerKim Phillips <kim.phillips@freescale.com>2009-01-21 18:38:51 -0600
commitbe4880ebe4355e8782be4af4b337a1b98dffcbe3 (patch)
tree8b699181073305221b95f338a2d9107ab1bbfa3f /include/i2c.h
parent633639587e3596f0dbf5e6247dd3faf80b1d9063 (diff)
parent72d15e705bc3983884105cb7755c7ba80e74a0a5 (diff)
downloadu-boot-imx-be4880ebe4355e8782be4af4b337a1b98dffcbe3.zip
u-boot-imx-be4880ebe4355e8782be4af4b337a1b98dffcbe3.tar.gz
u-boot-imx-be4880ebe4355e8782be4af4b337a1b98dffcbe3.tar.bz2
Merge branch 'master' into next
Diffstat (limited to 'include/i2c.h')
-rw-r--r--include/i2c.h62
1 files changed, 60 insertions, 2 deletions
diff --git a/include/i2c.h b/include/i2c.h
index 8d6f867..fad2d57 100644
--- a/include/i2c.h
+++ b/include/i2c.h
@@ -76,6 +76,20 @@
# define I2C_SOFT_DECLARATIONS
# endif
#endif
+
+#ifdef CONFIG_8xx
+/* Set default values for the I2C bus speed and slave address on 8xx. In the
+ * future, we'll define these in all 8xx board config files.
+ */
+#ifndef CONFIG_SYS_I2C_SPEED
+#define CONFIG_SYS_I2C_SPEED 50000
+#endif
+
+#ifndef CONFIG_SYS_I2C_SLAVE
+#define CONFIG_SYS_I2C_SLAVE 0xFE
+#endif
+#endif
+
/*
* Initialization, must be called once on start up, may be called
* repeatedly to change the speed and slave addresses.
@@ -132,8 +146,52 @@ int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len);
/*
* Utility routines to read/write registers.
*/
-uchar i2c_reg_read (uchar chip, uchar reg);
-void i2c_reg_write(uchar chip, uchar reg, uchar val);
+static inline u8 i2c_reg_read(u8 addr, u8 reg)
+{
+ u8 buf;
+
+#ifdef CONFIG_8xx
+ /* MPC8xx needs this. Maybe one day we can get rid of it. */
+ i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
+#endif
+
+#ifdef DEBUG
+ printf("%s: addr=0x%02x, reg=0x%02x\n", __func__, addr, reg);
+#endif
+
+#ifdef CONFIG_BLACKFIN
+ /* This ifdef will become unneccessary in a future version of the
+ * blackfin I2C driver.
+ */
+ i2c_read(addr, reg, 0, &buf, 1);
+#else
+ i2c_read(addr, reg, 1, &buf, 1);
+#endif
+
+ return buf;
+}
+
+static inline void i2c_reg_write(u8 addr, u8 reg, u8 val)
+{
+#ifdef CONFIG_8xx
+ /* MPC8xx needs this. Maybe one day we can get rid of it. */
+ i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
+#endif
+
+#ifdef DEBUG
+ printf("%s: addr=0x%02x, reg=0x%02x, val=0x%02x\n",
+ __func__, addr, reg, val);
+#endif
+
+#ifdef CONFIG_BLACKFIN
+ /* This ifdef will become unneccessary in a future version of the
+ * blackfin I2C driver.
+ */
+ i2c_write(addr, reg, 0, &val, 1);
+#else
+ i2c_write(addr, reg, 1, &val, 1);
+#endif
+}
/*
* Functions for setting the current I2C bus and its speed