]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
i2c: merge all i2c_reg_read() and i2c_reg_write() into inline functions
authorTimur Tabi <timur@freescale.com>
Wed, 3 Dec 2008 17:28:30 +0000 (11:28 -0600)
committerWolfgang Denk <wd@denx.de>
Mon, 15 Dec 2008 22:46:21 +0000 (23:46 +0100)
All implementations of the functions i2c_reg_read() and
i2c_reg_write() are identical. We can save space and simplify the
code by converting these functions into inlines and putting them in
i2c.h.

Signed-off-by: Timur Tabi <timur@freescale.com>
Acked-By: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
14 files changed:
cpu/arm920t/at91rm9200/i2c.c
cpu/arm926ejs/davinci/i2c.c
cpu/blackfin/i2c.c
cpu/mpc512x/i2c.c
cpu/mpc5xxx/i2c.c
cpu/mpc8220/i2c.c
cpu/mpc824x/drivers/i2c/i2c.c
cpu/mpc8260/i2c.c
cpu/mpc8xx/i2c.c
cpu/ppc4xx/i2c.c
cpu/pxa/i2c.c
drivers/i2c/fsl_i2c.c
drivers/i2c/soft_i2c.c
include/i2c.h

index b68c5dd8263d77fb018b41e19bd10477c100bea5..9fd72d3977b3bf363825e8ef47f4086b8d1c47d1 100644 (file)
@@ -189,20 +189,6 @@ i2c_init(int speed, int slaveaddr)
        return;
 }
 
-uchar i2c_reg_read(uchar i2c_addr, uchar reg)
-{
-       unsigned char buf;
-
-       i2c_read(i2c_addr, reg, 1, &buf, 1);
-
-       return(buf);
-}
-
-void i2c_reg_write(uchar i2c_addr, uchar reg, uchar val)
-{
-       i2c_write(i2c_addr, reg, 1, &val, 1);
-}
-
 int i2c_set_bus_speed(unsigned int speed)
 {
        return -1;
index d220a4c728eb48fc83ba64d84505a9e0f1e55286..3ba20ef18699754a9aa6f2afde9d5fe8b356adec 100644 (file)
@@ -331,21 +331,4 @@ int i2c_write(u_int8_t chip, u_int32_t addr, int alen, u_int8_t *buf, int len)
        return(0);
 }
 
-
-u_int8_t i2c_reg_read(u_int8_t chip, u_int8_t reg)
-{
-       u_int8_t        tmp;
-
-       i2c_read(chip, reg, 1, &tmp, 1);
-       return(tmp);
-}
-
-
-void i2c_reg_write(u_int8_t chip, u_int8_t reg, u_int8_t val)
-{
-       u_int8_t        tmp;
-
-       i2c_write(chip, reg, 1, &tmp, 1);
-}
-
 #endif /* CONFIG_DRIVER_DAVINCI_I2C */
index 60f03d47a154f712585f99f9a0fc58a55d81454a..2a3e2238c3665dc65bc428771309c3b3948518e0 100644 (file)
@@ -425,20 +425,4 @@ int i2c_write(uchar chip, uint addr, int alen, uchar * buffer, int len)
 
 }
 
-uchar i2c_reg_read(uchar chip, uchar reg)
-{
-       uchar buf;
-
-       PRINTD("i2c_reg_read: chip=0x%02x, reg=0x%02x\n", chip, reg);
-       i2c_read(chip, reg, 0, &buf, 1);
-       return (buf);
-}
-
-void i2c_reg_write(uchar chip, uchar reg, uchar val)
-{
-       PRINTD("i2c_reg_write: chip=0x%02x, reg=0x%02x, val=0x%02x\n", chip,
-                       reg, val);
-       i2c_write(chip, reg, 0, &val, 1);
-}
-
 #endif /* CONFIG_HARD_I2C */
index 77a6f0dc48fc8bd2af3d40de284e763c7b6ad174..4f6bc864048d7ac84a7ca9de61f937e587d1d3f7 100644 (file)
@@ -382,23 +382,6 @@ Done:
        return ret;
 }
 
-uchar i2c_reg_read (uchar chip, uchar reg)
-{
-       uchar buf;
-
-       i2c_read (chip, reg, 1, &buf, 1);
-
-       return buf;
-}
-
-void i2c_reg_write (uchar chip, uchar reg, uchar val)
-{
-       i2c_write (chip, reg, 1, &val, 1);
-
-       return;
-}
-
-
 int i2c_set_bus_num (unsigned int bus)
 {
        if (bus >= I2C_BUS_CNT) {
index 4d16bbe77416b84814e8ccf83f702d63a47494ab..7d76274ad331ca1aa3480a93eac6bdc0b180ac51 100644 (file)
@@ -380,20 +380,4 @@ Done:
        return ret;
 }
 
-uchar i2c_reg_read(uchar chip, uchar reg)
-{
-       uchar buf;
-
-       i2c_read(chip, reg, 1, &buf, 1);
-
-       return buf;
-}
-
-void i2c_reg_write(uchar chip, uchar reg, uchar val)
-{
-       i2c_write(chip, reg, 1, &val, 1);
-
-       return;
-}
-
 #endif /* CONFIG_HARD_I2C */
index d67936dc31c2f3b7a11242f506823015d134115b..76ecdf11e214e3e539c67535f140cffec33c3c5d 100644 (file)
@@ -387,20 +387,4 @@ int i2c_write (uchar chip, uint addr, int alen, uchar * buf, int len)
        return ret;
 }
 
-uchar i2c_reg_read (uchar chip, uchar reg)
-{
-       uchar buf;
-
-       i2c_read (chip, reg, 1, &buf, 1);
-
-       return buf;
-}
-
-void i2c_reg_write (uchar chip, uchar reg, uchar val)
-{
-       i2c_write (chip, reg, 1, &val, 1);
-
-       return;
-}
-
 #endif /* CONFIG_HARD_I2C */
index 854345e146eea7d46e82e9c502f5a27916bae6f4..637ae4c1b104707f5c90664687511096788fbe96 100644 (file)
@@ -267,18 +267,4 @@ int i2c_probe (uchar chip)
        return i2c_read (chip, 0, 1, (uchar *) &tmp, 1);
 }
 
-uchar i2c_reg_read (uchar i2c_addr, uchar reg)
-{
-       uchar buf[1];
-
-       i2c_read (i2c_addr, reg, 1, buf, 1);
-
-       return (buf[0]);
-}
-
-void i2c_reg_write (uchar i2c_addr, uchar reg, uchar val)
-{
-       i2c_write (i2c_addr, reg, 1, &val, 1);
-}
-
 #endif /* CONFIG_HARD_I2C */
index c12463994fd2800fc437d080b343689749accb7f..35cf8f1434660dc4ce3e23cc80af85eb14543198 100644 (file)
@@ -753,22 +753,6 @@ i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len)
        return 0;
 }
 
-uchar
-i2c_reg_read(uchar chip, uchar reg)
-{
-       uchar buf;
-
-       i2c_read(chip, reg, 1, &buf, 1);
-
-       return (buf);
-}
-
-void
-i2c_reg_write(uchar chip, uchar reg, uchar val)
-{
-       i2c_write(chip, reg, 1, &val, 1);
-}
-
 #if defined(CONFIG_I2C_MULTI_BUS)
 /*
  * Functions for multiple I2C bus handling
index 29c7c71bbc4bea23de9ade337950ef733e1987ec..338cababe89a368623e92241f00e53979a513a0c 100644 (file)
@@ -42,19 +42,6 @@ DECLARE_GLOBAL_DATA_PTR;
 /* define to enable debug messages */
 #undef DEBUG_I2C
 
-/*-----------------------------------------------------------------------
- * Set default values
- */
-#ifndef        CONFIG_SYS_I2C_SPEED
-#define        CONFIG_SYS_I2C_SPEED    50000
-#endif
-
-#ifndef        CONFIG_SYS_I2C_SLAVE
-#define        CONFIG_SYS_I2C_SLAVE    0xFE
-#endif
-/*-----------------------------------------------------------------------
- */
-
 /* tx/rx timeout (we need the i2c early, so we don't use get_timer()) */
 #define TOUT_LOOP 1000000
 
@@ -717,24 +704,4 @@ int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len)
        return 0;
 }
 
-uchar
-i2c_reg_read(uchar i2c_addr, uchar reg)
-{
-       uchar buf;
-
-       i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
-
-       i2c_read(i2c_addr, reg, 1, &buf, 1);
-
-       return (buf);
-}
-
-void
-i2c_reg_write(uchar i2c_addr, uchar reg, uchar val)
-{
-       i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
-
-       i2c_write(i2c_addr, reg, 1, &val, 1);
-}
-
 #endif /* CONFIG_HARD_I2C */
index 9073ee240bb7f87207b1c68f4676db99d7351290..9d416ca5e8fdab6eac8e376dfdabb302f09f2edd 100644 (file)
@@ -419,26 +419,6 @@ int i2c_write(uchar chip, uint addr, int alen, uchar * buffer, int len)
        return (i2c_transfer(0, chip<<1, &xaddr[4-alen], alen, buffer, len ) != 0);
 }
 
-/*-----------------------------------------------------------------------
- * Read a register
- */
-uchar i2c_reg_read(uchar i2c_addr, uchar reg)
-{
-       uchar buf;
-
-       i2c_read(i2c_addr, reg, 1, &buf, 1);
-
-       return (buf);
-}
-
-/*-----------------------------------------------------------------------
- * Write a register
- */
-void i2c_reg_write(uchar i2c_addr, uchar reg, uchar val)
-{
-       i2c_write(i2c_addr, reg, 1, &val, 1);
-}
-
 #if defined(CONFIG_I2C_MULTI_BUS)
 /*
  * Functions for multiple I2C bus handling
index 08042be1c11ef4718ba8bab6fa9d7e8147e8d2a7..6b72ba13a09e0d8c47bd2e41af67fbdb457800a5 100644 (file)
@@ -455,19 +455,4 @@ int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len)
 
 }
 
-uchar i2c_reg_read (uchar chip, uchar reg)
-{
-       uchar buf;
-
-       PRINTD(("i2c_reg_read(chip=0x%02x, reg=0x%02x)\n",chip,reg));
-       i2c_read(chip, reg, 1, &buf, 1);
-       return (buf);
-}
-
-void  i2c_reg_write(uchar chip, uchar reg, uchar val)
-{
-       PRINTD(("i2c_reg_write(chip=0x%02x, reg=0x%02x, val=0x%02x)\n",chip,reg,val));
-       i2c_write(chip, reg, 1, &val, 1);
-}
-
 #endif /* CONFIG_HARD_I2C */
index 3b5c06ba65fb2b4ee507e53ce7c122ff37cc2590..ce646fd7ed16f66bf208bdc9c6ed9979b77d9861 100644 (file)
@@ -367,22 +367,6 @@ i2c_probe(uchar chip)
        return i2c_read(chip, 0, 0, NULL, 0);
 }
 
-uchar
-i2c_reg_read(uchar i2c_addr, uchar reg)
-{
-       uchar buf[1];
-
-       i2c_read(i2c_addr, reg, 1, buf, 1);
-
-       return buf[0];
-}
-
-void
-i2c_reg_write(uchar i2c_addr, uchar reg, uchar val)
-{
-       i2c_write(i2c_addr, reg, 1, &val, 1);
-}
-
 int i2c_set_bus_num(unsigned int bus)
 {
 #ifdef CONFIG_SYS_I2C2_OFFSET
index d2a51426e99016b914736ad320a4b5c8d573667b..f12dedf89a971b37c21651c73ea505417c159302 100644 (file)
@@ -435,22 +435,3 @@ int  i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len)
        return(failures);
 }
 
-/*-----------------------------------------------------------------------
- * Read a register
- */
-uchar i2c_reg_read(uchar i2c_addr, uchar reg)
-{
-       uchar buf;
-
-       i2c_read(i2c_addr, reg, 1, &buf, 1);
-
-       return(buf);
-}
-
-/*-----------------------------------------------------------------------
- * Write a register
- */
-void i2c_reg_write(uchar i2c_addr, uchar reg, uchar val)
-{
-       i2c_write(i2c_addr, reg, 1, &val, 1);
-}
index 8d6f867422c4bd6165d5954b5d92ad94e536fd79..fad2d571616fcc71ff9f3dbb65b9576aaee714c9 100644 (file)
 #  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