i2c: buses: tegra: assign unused address to i2c slave
Nitin Kumbhar [Fri, 1 Apr 2011 14:08:30 +0000 (19:08 +0530)]
New i2c slave should be configured with a non-zero i2c address.
Configure i2c slave with an i2c address assigned by platform
data for an i2c dev.

BUG 788286

Reviewed-on: http://git-master/r/25100
(cherry picked from commit e6e0610c72ffce3b734e079faf88fad3f0468d07)

Original-Change-Id: I440aa2cc72007d2835b2027c0b26089d0aad9263
Reviewed-on: http://git-master/r/25223
Reviewed-by: Bharat Nihalani <bnihalani@nvidia.com>
Tested-by: Bharat Nihalani <bnihalani@nvidia.com>

Rebase-Id: Rfac0b98a3aad6f7df4badd5554a63856212a580d

drivers/i2c/busses/i2c-tegra.c
include/linux/i2c-tegra.h

index f6a4f2c..6f8281e 100644 (file)
 #define I2C_HEADER_MASTER_ADDR_SHIFT           12
 #define I2C_HEADER_SLAVE_ADDR_SHIFT            1
 
+#define SL_ADDR1(addr) (addr & 0xff)
+#define SL_ADDR2(addr) ((addr >> 8) & 0xff)
+
 struct tegra_i2c_dev;
 
 struct tegra_i2c_bus {
@@ -159,6 +162,7 @@ struct tegra_i2c_dev {
        const struct tegra_pingroup_config *last_mux;
        int last_mux_len;
        unsigned long last_bus_clk_rate;
+       u16 slave_addr;
        struct tegra_i2c_bus busses[1];
 };
 
@@ -364,6 +368,13 @@ static void tegra_i2c_slave_init(struct tegra_i2c_dev *i2c_dev)
        u32 val = I2C_SL_CNFG_NEWSL | I2C_SL_CNFG_NACK;
 
        i2c_writel(i2c_dev, val, I2C_SL_CNFG);
+
+       if (i2c_dev->slave_addr) {
+               u16 addr = i2c_dev->slave_addr;
+
+               i2c_writel(i2c_dev, SL_ADDR1(addr), I2C_SL_ADDR1);
+               i2c_writel(i2c_dev, SL_ADDR2(addr), I2C_SL_ADDR2);
+       }
 }
 
 static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev)
@@ -766,6 +777,7 @@ static int tegra_i2c_probe(struct platform_device *pdev)
        i2c_dev->msgs_num = 0;
        rt_mutex_init(&i2c_dev->dev_lock);
 
+       i2c_dev->slave_addr = plat->slave_addr;
        i2c_dev->is_dvc = plat->is_dvc;
        init_completion(&i2c_dev->msg_complete);
 
index f92fe26..b104504 100644 (file)
@@ -31,6 +31,7 @@ struct tegra_i2c_platform_data {
        bool is_dvc;
        int retries;
        int timeout;    /* in jiffies */
+       u16 slave_addr;
 };
 
 #endif /* _LINUX_I2C_TEGRA_H */