authorNathael Pajani <nathael.pajani@ed3l.fr>
Tue, 22 Sep 2015 18:39:51 +0000 (20:39 +0200)
committerNathael Pajani <nathael.pajani@ed3l.fr>
Tue, 22 Sep 2015 18:39:51 +0000 (20:39 +0200)
drivers/i2c.c

index 2d016e4..cdebb0e 100644 (file)
  *           single repeated start or stop/start sequence after given data byte.
  */
 struct i2c_bus {
-       struct lpc_i2c* regs;
+       volatile struct lpc_i2c* regs;
        uint8_t irq;
        uint8_t pclk_bit;
        uint32_t power_bit;
-       uint32_t clock;
+       volatile uint32_t clock;
        volatile uint32_t state;
        volatile uint32_t master_status;
        volatile uint32_t slave_status;
@@ -77,8 +77,7 @@ struct i2c_bus {
 };
 
 
-/* FIXME : Handle multiple I2C busses ! */
-static struct i2c_bus i2c_buses[3] = {
+static struct i2c_bus i2c_buses[NB_I2C_BUSSES] = {
        {
                .regs = (struct lpc_i2c*)LPC_I2C0,
                .irq = I2C0_IRQ,
@@ -457,7 +456,6 @@ int i2c_write(uint8_t bus_num, const void *buf, size_t count, const void* ctrl_b
        /* Clear read information to prevent entering master receiver states */
        i2c->read_length = 0;
        i2c->in_buff = NULL;
-       i2c->state = I2C_BUSY;
        /* Set up mod_i2c for write operation */
        i2c->out_buff = buf;
        i2c->write_length = count;
@@ -544,6 +542,9 @@ void i2c_clock_update(void)
        int i = 0;
 
        for (i = 0; i < NB_I2C_BUSSES; i++) {
+               if (! subsystem_powered(i2c_buses[i].power_bit)) {
+                       continue;
+               }
                if (i2c_buses[i].clock != 0) {
                /* FIXME : we should stop I2C transfers, disable I2C interrupts and stop I2C clock. */
                        i2c_clock_on(&(i2c_buses[i]));