Merge branch 'i2c/for-4.8' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 27 Jul 2016 21:19:25 +0000 (14:19 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 27 Jul 2016 21:19:25 +0000 (14:19 -0700)
Pull i2c updates from Wolfram Sang:
 "Here is the I2C pull request for 4.8:

   - the core and i801 driver gained support for SMBus Host Notify

   - core support for more than one address in DT

   - i2c_add_adapter() has now better error messages.  We can remove all
     error messages from drivers calling it as a next step.

   - bigger updates to rk3x driver to support rk3399 SoC

   - the at24 eeprom driver got refactored and can now read special
     variants with unique serials or fixed MAC addresses.

  The rest is regular driver updates and bugfixes"

* 'i2c/for-4.8' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (66 commits)
  i2c: i801: use IS_ENABLED() instead of checking for built-in or module
  Documentation: i2c: slave: give proper example for pm usage
  Documentation: i2c: slave: describe buffer problems a bit better
  i2c: bcm2835: Don't complain on -EPROBE_DEFER from getting our clock
  i2c: i2c-smbus: drop useless stubs
  i2c: efm32: fix a failure path in efm32_i2c_probe()
  Revert "i2c: core: Cleanup I2C ACPI namespace"
  Revert "i2c: core: Add function for finding the bus speed from ACPI"
  i2c: Update the description of I2C_SMBUS
  i2c: i2c-smbus: fix i2c_handle_smbus_host_notify documentation
  eeprom: at24: tweak the loop_until_timeout() macro
  eeprom: at24: add support for at24mac series
  eeprom: at24: support reading the serial number for 24csxx
  eeprom: at24: platform_data: use BIT() macro
  eeprom: at24: split at24_eeprom_write() into specialized functions
  eeprom: at24: split at24_eeprom_read() into specialized functions
  eeprom: at24: hide the read/write loop behind a macro
  eeprom: at24: call read/write functions via function pointers
  eeprom: at24: coding style fixes
  eeprom: at24: move at24_read() below at24_eeprom_write()
  ...

1  2 
drivers/hwmon/lm90.c
drivers/i2c/busses/i2c-qup.c
drivers/i2c/i2c-core.c

diff --combined drivers/hwmon/lm90.c
index f51e758ba5298c1d05f5c5301ea57dc95204b85c,5b62c57e8bfc669eed03e7439053419a253cad3a..1e8237478b2f1467f18aec07c3596f14e8351e0d
@@@ -171,6 -171,7 +171,6 @@@ enum chips { lm90, adm1032, lm99, lm86
  
  #define SA56004_REG_R_LOCAL_TEMPL 0x22
  
 -#define LM90_DEF_CONVRATE_RVAL        6       /* Def conversion rate register value */
  #define LM90_MAX_CONVRATE_MS  16000   /* Maximum conversion rate in ms */
  
  /* TMP451 registers */
@@@ -365,9 -366,11 +365,9 @@@ enum lm90_temp11_reg_index 
  
  struct lm90_data {
        struct i2c_client *client;
 -      struct device *hwmon_dev;
        const struct attribute_group *groups[6];
        struct mutex update_lock;
 -      struct regulator *regulator;
 -      char valid; /* zero until following fields are valid */
 +      bool valid;             /* true if register values are valid */
        unsigned long last_updated; /* in jiffies */
        int kind;
        u32 flags;
@@@ -409,7 -412,7 +409,7 @@@ static inline s32 adm1032_write_byte(st
   * because we don't want the address pointer to change between the write
   * byte and the read byte transactions.
   */
 -static int lm90_read_reg(struct i2c_client *client, u8 reg, u8 *value)
 +static int lm90_read_reg(struct i2c_client *client, u8 reg)
  {
        int err;
  
        } else
                err = i2c_smbus_read_byte_data(client, reg);
  
 -      if (err < 0) {
 -              dev_warn(&client->dev, "Register %#02x read failed (%d)\n",
 -                       reg, err);
 -              return err;
 -      }
 -      *value = err;
 -
 -      return 0;
 +      return err;
  }
  
 -static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value)
 +static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl)
  {
 -      int err;
 -      u8 oldh, newh, l;
 +      int oldh, newh, l;
  
        /*
         * There is a trick here. We have to read two registers to have the
         * we have to read the low byte again, and now we believe we have a
         * correct reading.
         */
 -      if ((err = lm90_read_reg(client, regh, &oldh))
 -       || (err = lm90_read_reg(client, regl, &l))
 -       || (err = lm90_read_reg(client, regh, &newh)))
 -              return err;
 +      oldh = lm90_read_reg(client, regh);
 +      if (oldh < 0)
 +              return oldh;
 +      l = lm90_read_reg(client, regl);
 +      if (l < 0)
 +              return l;
 +      newh = lm90_read_reg(client, regh);
 +      if (newh < 0)
 +              return newh;
        if (oldh != newh) {
 -              err = lm90_read_reg(client, regl, &l);
 -              if (err)
 -                      return err;
 +              l = lm90_read_reg(client, regl);
 +              if (l < 0)
 +                      return l;
        }
 -      *value = (newh << 8) | l;
 -
 -      return 0;
 +      return (newh << 8) | l;
  }
  
  /*
   * various registers have different meanings as a result of selecting a
   * non-default remote channel.
   */
 -static inline void lm90_select_remote_channel(struct i2c_client *client,
 -                                            struct lm90_data *data,
 -                                            int channel)
 +static inline int lm90_select_remote_channel(struct i2c_client *client,
 +                                           struct lm90_data *data,
 +                                           int channel)
  {
 -      u8 config;
 +      int config;
  
        if (data->kind == max6696) {
 -              lm90_read_reg(client, LM90_REG_R_CONFIG1, &config);
 +              config = lm90_read_reg(client, LM90_REG_R_CONFIG1);
 +              if (config < 0)
 +                      return config;
                config &= ~0x08;
                if (channel)
                        config |= 0x08;
                i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
                                          config);
        }
 +      return 0;
  }
  
  /*
@@@ -508,204 -513,118 +508,204 @@@ static void lm90_set_convrate(struct i2
        data->update_interval = DIV_ROUND_CLOSEST(update_interval, 64);
  }
  
 +static int lm90_update_limits(struct device *dev)
 +{
 +      struct lm90_data *data = dev_get_drvdata(dev);
 +      struct i2c_client *client = data->client;
 +      int val;
 +
 +      val = lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT);
 +      if (val < 0)
 +              return val;
 +      data->temp8[LOCAL_CRIT] = val;
 +
 +      val = lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT);
 +      if (val < 0)
 +              return val;
 +      data->temp8[REMOTE_CRIT] = val;
 +
 +      val = lm90_read_reg(client, LM90_REG_R_TCRIT_HYST);
 +      if (val < 0)
 +              return val;
 +      data->temp_hyst = val;
 +
 +      lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH);
 +      if (val < 0)
 +              return val;
 +      data->temp11[REMOTE_LOW] = val << 8;
 +
 +      if (data->flags & LM90_HAVE_REM_LIMIT_EXT) {
 +              val = lm90_read_reg(client, LM90_REG_R_REMOTE_LOWL);
 +              if (val < 0)
 +                      return val;
 +              data->temp11[REMOTE_LOW] |= val;
 +      }
 +
 +      val = lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH);
 +      if (val < 0)
 +              return val;
 +      data->temp11[REMOTE_HIGH] = val << 8;
 +
 +      if (data->flags & LM90_HAVE_REM_LIMIT_EXT) {
 +              val = lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHL);
 +              if (val < 0)
 +                      return val;
 +              data->temp11[REMOTE_HIGH] |= val;
 +      }
 +
 +      if (data->flags & LM90_HAVE_OFFSET) {
 +              val = lm90_read16(client, LM90_REG_R_REMOTE_OFFSH,
 +                                LM90_REG_R_REMOTE_OFFSL);
 +              if (val < 0)
 +                      return val;
 +              data->temp11[REMOTE_OFFSET] = val;
 +      }
 +
 +      if (data->flags & LM90_HAVE_EMERGENCY) {
 +              val = lm90_read_reg(client, MAX6659_REG_R_LOCAL_EMERG);
 +              if (val < 0)
 +                      return val;
 +              data->temp8[LOCAL_EMERG] = val;
 +
 +              val = lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG);
 +              if (val < 0)
 +                      return val;
 +              data->temp8[REMOTE_EMERG] = val;
 +      }
 +
 +      if (data->kind == max6696) {
 +              val = lm90_select_remote_channel(client, data, 1);
 +              if (val < 0)
 +                      return val;
 +
 +              val = lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT);
 +              if (val < 0)
 +                      return val;
 +              data->temp8[REMOTE2_CRIT] = val;
 +
 +              val = lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG);
 +              if (val < 0)
 +                      return val;
 +              data->temp8[REMOTE2_EMERG] = val;
 +
 +              val = lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH);
 +              if (val < 0)
 +                      return val;
 +              data->temp11[REMOTE2_LOW] = val << 8;
 +
 +              val = lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH);
 +              if (val < 0)
 +                      return val;
 +              data->temp11[REMOTE2_HIGH] = val << 8;
 +
 +              lm90_select_remote_channel(client, data, 0);
 +      }
 +
 +      return 0;
 +}
 +
  static struct lm90_data *lm90_update_device(struct device *dev)
  {
        struct lm90_data *data = dev_get_drvdata(dev);
        struct i2c_client *client = data->client;
        unsigned long next_update;
 +      int val = 0;
  
        mutex_lock(&data->update_lock);
  
 +      if (!data->valid) {
 +              val = lm90_update_limits(dev);
 +              if (val < 0)
 +                      goto error;
 +      }
 +
        next_update = data->last_updated +
                      msecs_to_jiffies(data->update_interval);
        if (time_after(jiffies, next_update) || !data->valid) {
 -              u8 h, l;
 -              u8 alarms;
 -
                dev_dbg(&client->dev, "Updating lm90 data.\n");
 -              lm90_read_reg(client, LM90_REG_R_LOCAL_LOW,
 -                            &data->temp8[LOCAL_LOW]);
 -              lm90_read_reg(client, LM90_REG_R_LOCAL_HIGH,
 -                            &data->temp8[LOCAL_HIGH]);
 -              lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT,
 -                            &data->temp8[LOCAL_CRIT]);
 -              lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT,
 -                            &data->temp8[REMOTE_CRIT]);
 -              lm90_read_reg(client, LM90_REG_R_TCRIT_HYST, &data->temp_hyst);
 +
 +              data->valid = false;
 +
 +              val = lm90_read_reg(client, LM90_REG_R_LOCAL_LOW);
 +              if (val < 0)
 +                      goto error;
 +              data->temp8[LOCAL_LOW] = val;
 +
 +              val = lm90_read_reg(client, LM90_REG_R_LOCAL_HIGH);
 +              if (val < 0)
 +                      goto error;
 +              data->temp8[LOCAL_HIGH] = val;
  
                if (data->reg_local_ext) {
 -                      lm90_read16(client, LM90_REG_R_LOCAL_TEMP,
 -                                  data->reg_local_ext,
 -                                  &data->temp11[LOCAL_TEMP]);
 +                      val = lm90_read16(client, LM90_REG_R_LOCAL_TEMP,
 +                                        data->reg_local_ext);
 +                      if (val < 0)
 +                              goto error;
 +                      data->temp11[LOCAL_TEMP] = val;
                } else {
 -                      if (lm90_read_reg(client, LM90_REG_R_LOCAL_TEMP,
 -                                        &h) == 0)
 -                              data->temp11[LOCAL_TEMP] = h << 8;
 -              }
 -              lm90_read16(client, LM90_REG_R_REMOTE_TEMPH,
 -                          LM90_REG_R_REMOTE_TEMPL,
 -                          &data->temp11[REMOTE_TEMP]);
 -
 -              if (lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &h) == 0) {
 -                      data->temp11[REMOTE_LOW] = h << 8;
 -                      if ((data->flags & LM90_HAVE_REM_LIMIT_EXT)
 -                       && lm90_read_reg(client, LM90_REG_R_REMOTE_LOWL,
 -                                        &l) == 0)
 -                              data->temp11[REMOTE_LOW] |= l;
 -              }
 -              if (lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &h) == 0) {
 -                      data->temp11[REMOTE_HIGH] = h << 8;
 -                      if ((data->flags & LM90_HAVE_REM_LIMIT_EXT)
 -                       && lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHL,
 -                                        &l) == 0)
 -                              data->temp11[REMOTE_HIGH] |= l;
 +                      val = lm90_read_reg(client, LM90_REG_R_LOCAL_TEMP);
 +                      if (val < 0)
 +                              goto error;
 +                      data->temp11[LOCAL_TEMP] = val << 8;
                }
 +              val = lm90_read16(client, LM90_REG_R_REMOTE_TEMPH,
 +                                LM90_REG_R_REMOTE_TEMPL);
 +              if (val < 0)
 +                      goto error;
 +              data->temp11[REMOTE_TEMP] = val;
  
 -              if (data->flags & LM90_HAVE_OFFSET) {
 -                      if (lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSH,
 -                                        &h) == 0
 -                       && lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSL,
 -                                        &l) == 0)
 -                              data->temp11[REMOTE_OFFSET] = (h << 8) | l;
 -              }
 -              if (data->flags & LM90_HAVE_EMERGENCY) {
 -                      lm90_read_reg(client, MAX6659_REG_R_LOCAL_EMERG,
 -                                    &data->temp8[LOCAL_EMERG]);
 -                      lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG,
 -                                    &data->temp8[REMOTE_EMERG]);
 -              }
 -              lm90_read_reg(client, LM90_REG_R_STATUS, &alarms);
 -              data->alarms = alarms;  /* save as 16 bit value */
 +              val = lm90_read_reg(client, LM90_REG_R_STATUS);
 +              if (val < 0)
 +                      goto error;
 +              data->alarms = val;     /* lower 8 bit of alarms */
  
                if (data->kind == max6696) {
 -                      lm90_select_remote_channel(client, data, 1);
 -                      lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT,
 -                                    &data->temp8[REMOTE2_CRIT]);
 -                      lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG,
 -                                    &data->temp8[REMOTE2_EMERG]);
 -                      lm90_read16(client, LM90_REG_R_REMOTE_TEMPH,
 -                                  LM90_REG_R_REMOTE_TEMPL,
 -                                  &data->temp11[REMOTE2_TEMP]);
 -                      if (!lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &h))
 -                              data->temp11[REMOTE2_LOW] = h << 8;
 -                      if (!lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &h))
 -                              data->temp11[REMOTE2_HIGH] = h << 8;
 +                      val = lm90_select_remote_channel(client, data, 1);
 +                      if (val < 0)
 +                              goto error;
 +
 +                      val = lm90_read16(client, LM90_REG_R_REMOTE_TEMPH,
 +                                        LM90_REG_R_REMOTE_TEMPL);
 +                      if (val < 0)
 +                              goto error;
 +                      data->temp11[REMOTE2_TEMP] = val;
 +
                        lm90_select_remote_channel(client, data, 0);
  
 -                      if (!lm90_read_reg(client, MAX6696_REG_R_STATUS2,
 -                                         &alarms))
 -                              data->alarms |= alarms << 8;
 +                      val = lm90_read_reg(client, MAX6696_REG_R_STATUS2);
 +                      if (val < 0)
 +                              goto error;
 +                      data->alarms |= val << 8;
                }
  
                /*
                 * Re-enable ALERT# output if it was originally enabled and
                 * relevant alarms are all clear
                 */
 -              if ((data->config_orig & 0x80) == 0
 -               && (data->alarms & data->alert_alarms) == 0) {
 -                      u8 config;
 +              if (!(data->config_orig & 0x80) &&
 +                  !(data->alarms & data->alert_alarms)) {
 +                      val = lm90_read_reg(client, LM90_REG_R_CONFIG1);
 +                      if (val < 0)
 +                              goto error;
  
 -                      lm90_read_reg(client, LM90_REG_R_CONFIG1, &config);
 -                      if (config & 0x80) {
 +                      if (val & 0x80) {
                                dev_dbg(&client->dev, "Re-enabling ALERT#\n");
                                i2c_smbus_write_byte_data(client,
                                                          LM90_REG_W_CONFIG1,
 -                                                        config & ~0x80);
 +                                                        val & ~0x80);
                        }
                }
  
                data->last_updated = jiffies;
 -              data->valid = 1;
 +              data->valid = true;
        }
  
 +error:
        mutex_unlock(&data->update_lock);
  
 +      if (val < 0)
 +              return ERR_PTR(val);
 +
        return data;
  }
  
@@@ -790,14 -709,16 +790,14 @@@ static inline int temp_from_u8_adt7461(
  {
        if (data->flags & LM90_FLAG_ADT7461_EXT)
                return (val - 64) * 1000;
 -      else
 -              return temp_from_s8(val);
 +      return temp_from_s8(val);
  }
  
  static inline int temp_from_u16_adt7461(struct lm90_data *data, u16 val)
  {
        if (data->flags & LM90_FLAG_ADT7461_EXT)
                return (val - 0x4000) / 64 * 250;
 -      else
 -              return temp_from_s16(val);
 +      return temp_from_s16(val);
  }
  
  static u8 temp_to_u8_adt7461(struct lm90_data *data, long val)
                if (val >= 191000)
                        return 0xFF;
                return (val + 500 + 64000) / 1000;
 -      } else {
 -              if (val <= 0)
 -                      return 0;
 -              if (val >= 127000)
 -                      return 127;
 -              return (val + 500) / 1000;
        }
 +      if (val <= 0)
 +              return 0;
 +      if (val >= 127000)
 +              return 127;
 +      return (val + 500) / 1000;
  }
  
  static u16 temp_to_u16_adt7461(struct lm90_data *data, long val)
                if (val >= 191750)
                        return 0xFFC0;
                return (val + 64000 + 125) / 250 * 64;
 -      } else {
 -              if (val <= 0)
 -                      return 0;
 -              if (val >= 127750)
 -                      return 0x7FC0;
 -              return (val + 125) / 250 * 64;
        }
 +      if (val <= 0)
 +              return 0;
 +      if (val >= 127750)
 +              return 0x7FC0;
 +      return (val + 125) / 250 * 64;
  }
  
  /*
@@@ -843,9 -766,6 +843,9 @@@ static ssize_t show_temp8(struct devic
        struct lm90_data *data = lm90_update_device(dev);
        int temp;
  
 +      if (IS_ERR(data))
 +              return PTR_ERR(data);
 +
        if (data->kind == adt7461 || data->kind == tmp451)
                temp = temp_from_u8_adt7461(data, data->temp8[attr->index]);
        else if (data->kind == max6646)
@@@ -912,9 -832,6 +912,9 @@@ static ssize_t show_temp11(struct devic
        struct lm90_data *data = lm90_update_device(dev);
        int temp;
  
 +      if (IS_ERR(data))
 +              return PTR_ERR(data);
 +
        if (data->kind == adt7461 || data->kind == tmp451)
                temp = temp_from_u16_adt7461(data, data->temp11[attr->index]);
        else if (data->kind == max6646)
@@@ -990,9 -907,6 +990,9 @@@ static ssize_t show_temphyst(struct dev
        struct lm90_data *data = lm90_update_device(dev);
        int temp;
  
 +      if (IS_ERR(data))
 +              return PTR_ERR(data);
 +
        if (data->kind == adt7461 || data->kind == tmp451)
                temp = temp_from_u8_adt7461(data, data->temp8[attr->index]);
        else if (data->kind == max6646)
@@@ -1039,10 -953,6 +1039,10 @@@ static ssize_t show_alarms(struct devic
                           char *buf)
  {
        struct lm90_data *data = lm90_update_device(dev);
 +
 +      if (IS_ERR(data))
 +              return PTR_ERR(data);
 +
        return sprintf(buf, "%d\n", data->alarms);
  }
  
@@@ -1053,9 -963,6 +1053,9 @@@ static ssize_t show_alarm(struct devic
        struct lm90_data *data = lm90_update_device(dev);
        int bitnr = attr->index;
  
 +      if (IS_ERR(data))
 +              return PTR_ERR(data);
 +
        return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1);
  }
  
@@@ -1497,11 -1404,8 +1497,11 @@@ static int lm90_detect(struct i2c_clien
        return 0;
  }
  
 -static void lm90_restore_conf(struct i2c_client *client, struct lm90_data *data)
 +static void lm90_restore_conf(void *_data)
  {
 +      struct lm90_data *data = _data;
 +      struct i2c_client *client = data->client;
 +
        /* Restore initial configuration */
        i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE,
                                  data->convrate_orig);
                                  data->config_orig);
  }
  
 -static void lm90_init_client(struct i2c_client *client, struct lm90_data *data)
 +static int lm90_init_client(struct i2c_client *client, struct lm90_data *data)
  {
 -      u8 config, convrate;
 +      int config, convrate;
  
 -      if (lm90_read_reg(client, LM90_REG_R_CONVRATE, &convrate) < 0) {
 -              dev_warn(&client->dev, "Failed to read convrate register!\n");
 -              convrate = LM90_DEF_CONVRATE_RVAL;
 -      }
 +      convrate = lm90_read_reg(client, LM90_REG_R_CONVRATE);
 +      if (convrate < 0)
 +              return convrate;
        data->convrate_orig = convrate;
  
        /*
         * Start the conversions.
         */
        lm90_set_convrate(client, data, 500);   /* 500ms; 2Hz conversion rate */
 -      if (lm90_read_reg(client, LM90_REG_R_CONFIG1, &config) < 0) {
 -              dev_warn(&client->dev, "Initialization failed!\n");
 -              return;
 -      }
 +      config = lm90_read_reg(client, LM90_REG_R_CONFIG1);
 +      if (config < 0)
 +              return config;
        data->config_orig = config;
  
        /* Check Temperature Range Select */
        config &= 0xBF; /* run */
        if (config != data->config_orig) /* Only write if changed */
                i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config);
 +
 +      devm_add_action(&client->dev, lm90_restore_conf, data);
 +
 +      return 0;
  }
  
  static bool lm90_is_tripped(struct i2c_client *client, u16 *status)
  {
        struct lm90_data *data = i2c_get_clientdata(client);
 -      u8 st, st2 = 0;
 +      int st, st2 = 0;
  
 -      lm90_read_reg(client, LM90_REG_R_STATUS, &st);
 +      st = lm90_read_reg(client, LM90_REG_R_STATUS);
 +      if (st < 0)
 +              return false;
  
 -      if (data->kind == max6696)
 -              lm90_read_reg(client, MAX6696_REG_R_STATUS2, &st2);
 +      if (data->kind == max6696) {
 +              st2 = lm90_read_reg(client, MAX6696_REG_R_STATUS2);
 +              if (st2 < 0)
 +                      return false;
 +      }
  
        *status = st | (st2 << 8);
  
@@@ -1609,16 -1506,6 +1609,16 @@@ static irqreturn_t lm90_irq_thread(int 
                return IRQ_NONE;
  }
  
 +static void lm90_remove_pec(void *dev)
 +{
 +      device_remove_file(dev, &dev_attr_pec);
 +}
 +
 +static void lm90_regulator_disable(void *regulator)
 +{
 +      regulator_disable(regulator);
 +}
 +
  static int lm90_probe(struct i2c_client *client,
                      const struct i2c_device_id *id)
  {
        struct i2c_adapter *adapter = to_i2c_adapter(dev->parent);
        struct lm90_data *data;
        struct regulator *regulator;
 +      struct device *hwmon_dev;
        int groups = 0;
        int err;
  
                return err;
        }
  
 +      devm_add_action(dev, lm90_regulator_disable, regulator);
 +
        data = devm_kzalloc(dev, sizeof(struct lm90_data), GFP_KERNEL);
        if (!data)
                return -ENOMEM;
        i2c_set_clientdata(client, data);
        mutex_init(&data->update_lock);
  
 -      data->regulator = regulator;
 -
        /* Set the device type */
        data->kind = id->driver_data;
        if (data->kind == adm1032) {
        data->max_convrate = lm90_params[data->kind].max_convrate;
  
        /* Initialize the LM90 chip */
 -      lm90_init_client(client, data);
 +      err = lm90_init_client(client, data);
 +      if (err < 0) {
 +              dev_err(dev, "Failed to initialize device\n");
 +              return err;
 +      }
  
        /* Register sysfs hooks */
        data->groups[groups++] = &lm90_group;
        if (client->flags & I2C_CLIENT_PEC) {
                err = device_create_file(dev, &dev_attr_pec);
                if (err)
 -                      goto exit_restore;
 +                      return err;
 +              devm_add_action(dev, lm90_remove_pec, dev);
        }
  
 -      data->hwmon_dev = hwmon_device_register_with_groups(dev, client->name,
 -                                                          data, data->groups);
 -      if (IS_ERR(data->hwmon_dev)) {
 -              err = PTR_ERR(data->hwmon_dev);
 -              goto exit_remove_pec;
 -      }
 +      hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
 +                                                         data, data->groups);
 +      if (IS_ERR(hwmon_dev))
 +              return PTR_ERR(hwmon_dev);
  
        if (client->irq) {
                dev_dbg(dev, "IRQ: %d\n", client->irq);
                                                "lm90", client);
                if (err < 0) {
                        dev_err(dev, "cannot request IRQ %d\n", client->irq);
 -                      goto exit_unregister;
 +                      return err;
                }
        }
  
 -      return 0;
 -
 -exit_unregister:
 -      hwmon_device_unregister(data->hwmon_dev);
 -exit_remove_pec:
 -      device_remove_file(dev, &dev_attr_pec);
 -exit_restore:
 -      lm90_restore_conf(client, data);
 -      regulator_disable(data->regulator);
 -
 -      return err;
 -}
 -
 -static int lm90_remove(struct i2c_client *client)
 -{
 -      struct lm90_data *data = i2c_get_clientdata(client);
 -
 -      hwmon_device_unregister(data->hwmon_dev);
 -      device_remove_file(&client->dev, &dev_attr_pec);
 -      lm90_restore_conf(client, data);
 -      regulator_disable(data->regulator);
 -
        return 0;
  }
  
- static void lm90_alert(struct i2c_client *client, unsigned int flag)
+ static void lm90_alert(struct i2c_client *client, enum i2c_alert_protocol type,
+                      unsigned int flag)
  {
        u16 alarms;
  
+       if (type != I2C_PROTOCOL_SMBUS_ALERT)
+               return;
        if (lm90_is_tripped(client, &alarms)) {
                /*
                 * Disable ALERT# output, because these chips don't implement
                 */
                struct lm90_data *data = i2c_get_clientdata(client);
  
 -              if ((data->flags & LM90_HAVE_BROKEN_ALERT)
 -               && (alarms & data->alert_alarms)) {
 -                      u8 config;
 +              if ((data->flags & LM90_HAVE_BROKEN_ALERT) &&
 +                  (alarms & data->alert_alarms)) {
 +                      int config;
 +
                        dev_dbg(&client->dev, "Disabling ALERT#\n");
 -                      lm90_read_reg(client, LM90_REG_R_CONFIG1, &config);
 -                      i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
 -                                                config | 0x80);
 +                      config = lm90_read_reg(client, LM90_REG_R_CONFIG1);
 +                      if (config >= 0)
 +                              i2c_smbus_write_byte_data(client,
 +                                                        LM90_REG_W_CONFIG1,
 +                                                        config | 0x80);
                }
        } else {
                dev_info(&client->dev, "Everything OK\n");
@@@ -1753,6 -1659,7 +1757,6 @@@ static struct i2c_driver lm90_driver = 
                .name   = "lm90",
        },
        .probe          = lm90_probe,
 -      .remove         = lm90_remove,
        .alert          = lm90_alert,
        .id_table       = lm90_id,
        .detect         = lm90_detect,
index 041050edd80991713d9bb5a776c9a1d402f23bf5,29139bbe8f85f31f982e309e47e56f144abc75a5..501bd15cb78e0eddab711efcb3ea6cd86515f5bb
@@@ -213,14 -213,16 +213,16 @@@ static irqreturn_t qup_i2c_interrupt(in
        bus_err &= I2C_STATUS_ERROR_MASK;
        qup_err &= QUP_STATUS_ERROR_FLAGS;
  
-       if (qup_err) {
-               /* Clear Error interrupt */
+       /* Clear the error bits in QUP_ERROR_FLAGS */
+       if (qup_err)
                writel(qup_err, qup->base + QUP_ERROR_FLAGS);
-               goto done;
-       }
  
-       if (bus_err) {
-               /* Clear Error interrupt */
+       /* Clear the error bits in QUP_I2C_STATUS */
+       if (bus_err)
+               writel(bus_err, qup->base + QUP_I2C_STATUS);
+       /* Reset the QUP State in case of error */
+       if (qup_err || bus_err) {
                writel(QUP_RESET_STATE, qup->base + QUP_STATE);
                goto done;
        }
@@@ -310,6 -312,7 +312,7 @@@ static int qup_i2c_wait_ready(struct qu
        u32 opflags;
        u32 status;
        u32 shift = __ffs(op);
+       int ret = 0;
  
        len *= qup->one_byte_t;
        /* timeout after a wait of twice the max time */
  
                if (((opflags & op) >> shift) == val) {
                        if ((op == QUP_OUT_NOT_EMPTY) && qup->is_last) {
-                               if (!(status & I2C_STATUS_BUS_ACTIVE))
-                                       return 0;
+                               if (!(status & I2C_STATUS_BUS_ACTIVE)) {
+                                       ret = 0;
+                                       goto done;
+                               }
                        } else {
-                               return 0;
+                               ret = 0;
+                               goto done;
                        }
                }
  
-               if (time_after(jiffies, timeout))
-                       return -ETIMEDOUT;
+               if (time_after(jiffies, timeout)) {
+                       ret = -ETIMEDOUT;
+                       goto done;
+               }
                usleep_range(len, len * 2);
        }
+ done:
+       if (qup->bus_err || qup->qup_err)
+               ret =  (qup->bus_err & QUP_I2C_NACK_FLAG) ? -ENXIO : -EIO;
+       return ret;
  }
  
  static void qup_i2c_set_write_mode_v2(struct qup_i2c_dev *qup,
@@@ -585,8 -598,8 +598,8 @@@ static void qup_i2c_bam_cb(void *data
  }
  
  static int qup_sg_set_buf(struct scatterlist *sg, void *buf,
-                         struct qup_i2c_tag *tg, unsigned int buflen,
-                         struct qup_i2c_dev *qup, int map, int dir)
+                         unsigned int buflen, struct qup_i2c_dev *qup,
+                         int dir)
  {
        int ret;
  
        if (!ret)
                return -EINVAL;
  
-       if (!map)
-               sg_dma_address(sg) = tg->addr + ((u8 *)buf - tg->start);
        return 0;
  }
  
@@@ -649,37 -659,37 +659,37 @@@ static int qup_i2c_bam_do_xfer(struct q
        u8 *tags;
  
        while (idx < num) {
-               blocks = (msg->len + limit) / limit;
-               rem = msg->len % limit;
                tx_len = 0, len = 0, i = 0;
  
                qup->is_last = (idx == (num - 1));
  
                qup_i2c_set_blk_data(qup, msg);
  
+               blocks = qup->blk.count;
+               rem = msg->len - (blocks - 1) * limit;
                if (msg->flags & I2C_M_RD) {
                        rx_nents += (blocks * 2) + 1;
                        tx_nents += 1;
  
                        while (qup->blk.pos < blocks) {
-                               /* length set to '0' implies 256 bytes */
-                               tlen = (i == (blocks - 1)) ? rem : 0;
+                               tlen = (i == (blocks - 1)) ? rem : limit;
                                tags = &qup->start_tag.start[off + len];
                                len += qup_i2c_set_tags(tags, qup, msg, 1);
+                               qup->blk.data_len -= tlen;
  
                                /* scratch buf to read the start and len tags */
                                ret = qup_sg_set_buf(&qup->brx.sg[rx_buf++],
                                                     &qup->brx.tag.start[0],
-                                                    &qup->brx.tag,
-                                                    2, qup, 0, 0);
+                                                    2, qup, DMA_FROM_DEVICE);
  
                                if (ret)
                                        return ret;
  
                                ret = qup_sg_set_buf(&qup->brx.sg[rx_buf++],
                                                     &msg->buf[limit * i],
-                                                    NULL, tlen, qup,
-                                                    1, DMA_FROM_DEVICE);
+                                                    tlen, qup,
+                                                    DMA_FROM_DEVICE);
                                if (ret)
                                        return ret;
  
                        }
                        ret = qup_sg_set_buf(&qup->btx.sg[tx_buf++],
                                             &qup->start_tag.start[off],
-                                            &qup->start_tag, len, qup, 0, 0);
+                                            len, qup, DMA_TO_DEVICE);
                        if (ret)
                                return ret;
  
                        /* scratch buf to read the BAM EOT and FLUSH tags */
                        ret = qup_sg_set_buf(&qup->brx.sg[rx_buf++],
                                             &qup->brx.tag.start[0],
-                                            &qup->brx.tag, 2,
-                                            qup, 0, 0);
+                                            2, qup, DMA_FROM_DEVICE);
                        if (ret)
                                return ret;
                } else {
                        tx_nents += (blocks * 2);
  
                        while (qup->blk.pos < blocks) {
-                               tlen = (i == (blocks - 1)) ? rem : 0;
+                               tlen = (i == (blocks - 1)) ? rem : limit;
                                tags = &qup->start_tag.start[off + tx_len];
                                len = qup_i2c_set_tags(tags, qup, msg, 1);
+                               qup->blk.data_len -= tlen;
  
                                ret = qup_sg_set_buf(&qup->btx.sg[tx_buf++],
-                                                    tags,
-                                                    &qup->start_tag, len,
-                                                    qup, 0, 0);
+                                                    tags, len,
+                                                    qup, DMA_TO_DEVICE);
                                if (ret)
                                        return ret;
  
                                tx_len += len;
                                ret = qup_sg_set_buf(&qup->btx.sg[tx_buf++],
                                                     &msg->buf[limit * i],
-                                                    NULL, tlen, qup, 1,
-                                                    DMA_TO_DEVICE);
+                                                    tlen, qup, DMA_TO_DEVICE);
                                if (ret)
                                        return ret;
                                i++;
                                                        QUP_BAM_FLUSH_STOP;
                                ret = qup_sg_set_buf(&qup->btx.sg[tx_buf++],
                                                     &qup->btx.tag.start[0],
-                                                    &qup->btx.tag, len,
-                                                    qup, 0, 0);
+                                                    len, qup, DMA_TO_DEVICE);
                                if (ret)
                                        return ret;
                                tx_nents += 1;
        }
  
        if (ret || qup->bus_err || qup->qup_err) {
-               if (qup->bus_err & QUP_I2C_NACK_FLAG) {
-                       msg--;
-                       dev_err(qup->dev, "NACK from %x\n", msg->addr);
-                       ret = -EIO;
+               if (qup_i2c_change_state(qup, QUP_RUN_STATE)) {
+                       dev_err(qup->dev, "change to run state timed out");
+                       goto desc_err;
+               }
  
-                       if (qup_i2c_change_state(qup, QUP_RUN_STATE)) {
-                               dev_err(qup->dev, "change to run state timed out");
-                               return ret;
-                       }
+               if (rx_nents)
+                       writel(QUP_BAM_INPUT_EOT,
+                              qup->base + QUP_OUT_FIFO_BASE);
  
-                       if (rx_nents)
-                               writel(QUP_BAM_INPUT_EOT,
-                                      qup->base + QUP_OUT_FIFO_BASE);
+               writel(QUP_BAM_FLUSH_STOP, qup->base + QUP_OUT_FIFO_BASE);
  
-                       writel(QUP_BAM_FLUSH_STOP,
-                              qup->base + QUP_OUT_FIFO_BASE);
+               qup_i2c_flush(qup);
  
-                       qup_i2c_flush(qup);
+               /* wait for remaining interrupts to occur */
+               if (!wait_for_completion_timeout(&qup->xfer, HZ))
+                       dev_err(qup->dev, "flush timed out\n");
  
-                       /* wait for remaining interrupts to occur */
-                       if (!wait_for_completion_timeout(&qup->xfer, HZ))
-                               dev_err(qup->dev, "flush timed out\n");
+               qup_i2c_rel_dma(qup);
  
-                       qup_i2c_rel_dma(qup);
-               }
+               ret =  (qup->bus_err & QUP_I2C_NACK_FLAG) ? -ENXIO : -EIO;
        }
  
+ desc_err:
        dma_unmap_sg(qup->dev, qup->btx.sg, tx_nents, DMA_TO_DEVICE);
  
        if (rx_nents)
                dma_unmap_sg(qup->dev, qup->brx.sg, rx_nents,
                             DMA_FROM_DEVICE);
- desc_err:
        return ret;
  }
  
@@@ -849,9 -852,6 +852,6 @@@ static int qup_i2c_bam_xfer(struct i2c_
        if (ret)
                goto out;
  
-       qup->bus_err = 0;
-       qup->qup_err = 0;
        writel(0, qup->base + QUP_MX_INPUT_CNT);
        writel(0, qup->base + QUP_MX_OUTPUT_CNT);
  
@@@ -889,12 -889,8 +889,8 @@@ static int qup_i2c_wait_for_complete(st
                ret = -ETIMEDOUT;
        }
  
-       if (qup->bus_err || qup->qup_err) {
-               if (qup->bus_err & QUP_I2C_NACK_FLAG) {
-                       dev_err(qup->dev, "NACK from %x\n", msg->addr);
-                       ret = -EIO;
-               }
-       }
+       if (qup->bus_err || qup->qup_err)
+               ret =  (qup->bus_err & QUP_I2C_NACK_FLAG) ? -ENXIO : -EIO;
  
        return ret;
  }
@@@ -1020,7 -1016,7 +1016,7 @@@ static void qup_i2c_issue_read(struct q
  {
        u32 addr, len, val;
  
-       addr = (msg->addr << 1) | 1;
+       addr = i2c_8bit_addr_from_msg(msg);
  
        /* 0 is used to specify a length 256 (QUP_READ_LIMIT) */
        len = (msg->len == QUP_READ_LIMIT) ? 0 : msg->len;
@@@ -1186,6 -1182,9 +1182,9 @@@ static int qup_i2c_xfer(struct i2c_adap
        if (ret < 0)
                goto out;
  
+       qup->bus_err = 0;
+       qup->qup_err = 0;
        writel(1, qup->base + QUP_SW_RESET);
        ret = qup_i2c_poll_state(qup, QUP_RESET_STATE);
        if (ret)
@@@ -1235,6 -1234,9 +1234,9 @@@ static int qup_i2c_xfer_v2(struct i2c_a
        struct qup_i2c_dev *qup = i2c_get_adapdata(adap);
        int ret, len, idx = 0, use_dma = 0;
  
+       qup->bus_err = 0;
+       qup->qup_err = 0;
        ret = pm_runtime_get_sync(qup->dev);
        if (ret < 0)
                goto out;
                }
        }
  
 +      idx = 0;
 +
        do {
                if (msgs[idx].len == 0) {
                        ret = -EINVAL;
@@@ -1409,27 -1409,21 +1411,21 @@@ static int qup_i2c_probe(struct platfor
  
                /* 2 tag bytes for each block + 5 for start, stop tags */
                size = blocks * 2 + 5;
-               qup->dpool = dma_pool_create("qup_i2c-dma-pool", &pdev->dev,
-                                            size, 4, 0);
  
-               qup->start_tag.start = dma_pool_alloc(qup->dpool, GFP_KERNEL,
-                                                     &qup->start_tag.addr);
+               qup->start_tag.start = devm_kzalloc(&pdev->dev,
+                                                   size, GFP_KERNEL);
                if (!qup->start_tag.start) {
                        ret = -ENOMEM;
                        goto fail_dma;
                }
  
-               qup->brx.tag.start = dma_pool_alloc(qup->dpool,
-                                                   GFP_KERNEL,
-                                                   &qup->brx.tag.addr);
+               qup->brx.tag.start = devm_kzalloc(&pdev->dev, 2, GFP_KERNEL);
                if (!qup->brx.tag.start) {
                        ret = -ENOMEM;
                        goto fail_dma;
                }
  
-               qup->btx.tag.start = dma_pool_alloc(qup->dpool,
-                                                   GFP_KERNEL,
-                                                   &qup->btx.tag.addr);
+               qup->btx.tag.start = devm_kzalloc(&pdev->dev, 2, GFP_KERNEL);
                if (!qup->btx.tag.start) {
                        ret = -ENOMEM;
                        goto fail_dma;
@@@ -1568,13 -1562,6 +1564,6 @@@ static int qup_i2c_remove(struct platfo
        struct qup_i2c_dev *qup = platform_get_drvdata(pdev);
  
        if (qup->is_dma) {
-               dma_pool_free(qup->dpool, qup->start_tag.start,
-                             qup->start_tag.addr);
-               dma_pool_free(qup->dpool, qup->brx.tag.start,
-                             qup->brx.tag.addr);
-               dma_pool_free(qup->dpool, qup->btx.tag.start,
-                             qup->btx.tag.addr);
-               dma_pool_destroy(qup->dpool);
                dma_release_channel(qup->btx.dma);
                dma_release_channel(qup->brx.dma);
        }
diff --combined drivers/i2c/i2c-core.c
index 74e5aeaf84f9910e949c4acff240f24e54ed175b,b2b34a0a35a1dc738d206b22f6bd5ca8cf60c2ee..da3a02ef4a3187e2c97e1a8bcb795c318544c4d1
@@@ -27,6 -27,8 +27,8 @@@
     I2C slave support (c) 2014 by Wolfram Sang <wsa@sang-engineering.com>
   */
  
+ #define pr_fmt(fmt) "i2c-core: " fmt
  #include <dt-bindings/i2c/i2c.h>
  #include <asm/uaccess.h>
  #include <linux/acpi.h>
@@@ -107,11 -109,12 +109,11 @@@ struct acpi_i2c_lookup 
        acpi_handle device_handle;
  };
  
 -static int acpi_i2c_find_address(struct acpi_resource *ares, void *data)
 +static int acpi_i2c_fill_info(struct acpi_resource *ares, void *data)
  {
        struct acpi_i2c_lookup *lookup = data;
        struct i2c_board_info *info = lookup->info;
        struct acpi_resource_i2c_serialbus *sb;
 -      acpi_handle adapter_handle;
        acpi_status status;
  
        if (info->addr || ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS)
        if (sb->type != ACPI_RESOURCE_SERIAL_TYPE_I2C)
                return 1;
  
 -      /*
 -       * Extract the ResourceSource and make sure that the handle matches
 -       * with the I2C adapter handle.
 -       */
        status = acpi_get_handle(lookup->device_handle,
                                 sb->resource_source.string_ptr,
 -                               &adapter_handle);
 -      if (ACPI_SUCCESS(status) && adapter_handle == lookup->adapter_handle) {
 -              info->addr = sb->slave_address;
 -              if (sb->access_mode == ACPI_I2C_10BIT_MODE)
 -                      info->flags |= I2C_CLIENT_TEN;
 -      }
 +                               &lookup->adapter_handle);
 +      if (!ACPI_SUCCESS(status))
 +              return 1;
 +
 +      info->addr = sb->slave_address;
 +      if (sb->access_mode == ACPI_I2C_10BIT_MODE)
 +              info->flags |= I2C_CLIENT_TEN;
  
        return 1;
  }
  
 -static acpi_status acpi_i2c_add_device(acpi_handle handle, u32 level,
 -                                     void *data, void **return_value)
 +static int acpi_i2c_get_info(struct acpi_device *adev,
 +                           struct i2c_board_info *info,
 +                           acpi_handle *adapter_handle)
  {
 -      struct i2c_adapter *adapter = data;
        struct list_head resource_list;
 -      struct acpi_i2c_lookup lookup;
        struct resource_entry *entry;
 -      struct i2c_board_info info;
 -      struct acpi_device *adev;
 +      struct acpi_i2c_lookup lookup;
        int ret;
  
 -      if (acpi_bus_get_device(handle, &adev))
 -              return AE_OK;
 -      if (acpi_bus_get_status(adev) || !adev->status.present)
 -              return AE_OK;
 +      if (acpi_bus_get_status(adev) || !adev->status.present ||
 +          acpi_device_enumerated(adev))
 +              return -EINVAL;
  
 -      memset(&info, 0, sizeof(info));
 -      info.fwnode = acpi_fwnode_handle(adev);
 +      memset(info, 0, sizeof(*info));
 +      info->fwnode = acpi_fwnode_handle(adev);
  
        memset(&lookup, 0, sizeof(lookup));
 -      lookup.adapter_handle = ACPI_HANDLE(&adapter->dev);
 -      lookup.device_handle = handle;
 -      lookup.info = &info;
 +      lookup.device_handle = acpi_device_handle(adev);
 +      lookup.info = info;
  
 -      /*
 -       * Look up for I2cSerialBus resource with ResourceSource that
 -       * matches with this adapter.
 -       */
 +      /* Look up for I2cSerialBus resource */
        INIT_LIST_HEAD(&resource_list);
        ret = acpi_dev_get_resources(adev, &resource_list,
 -                                   acpi_i2c_find_address, &lookup);
 +                                   acpi_i2c_fill_info, &lookup);
        acpi_dev_free_resource_list(&resource_list);
  
 -      if (ret < 0 || !info.addr)
 -              return AE_OK;
 +      if (ret < 0 || !info->addr)
 +              return -EINVAL;
 +
 +      *adapter_handle = lookup.adapter_handle;
  
        /* Then fill IRQ number if any */
        ret = acpi_dev_get_resources(adev, &resource_list, NULL, NULL);
        if (ret < 0)
 -              return AE_OK;
 +              return -EINVAL;
  
        resource_list_for_each_entry(entry, &resource_list) {
                if (resource_type(entry->res) == IORESOURCE_IRQ) {
 -                      info.irq = entry->res->start;
 +                      info->irq = entry->res->start;
                        break;
                }
        }
  
        acpi_dev_free_resource_list(&resource_list);
  
 +      strlcpy(info->type, dev_name(&adev->dev), sizeof(info->type));
 +
 +      return 0;
 +}
 +
 +static void acpi_i2c_register_device(struct i2c_adapter *adapter,
 +                                   struct acpi_device *adev,
 +                                   struct i2c_board_info *info)
 +{
        adev->power.flags.ignore_parent = true;
 -      strlcpy(info.type, dev_name(&adev->dev), sizeof(info.type));
 -      if (!i2c_new_device(adapter, &info)) {
 +      acpi_device_set_enumerated(adev);
 +
 +      if (!i2c_new_device(adapter, info)) {
                adev->power.flags.ignore_parent = false;
                dev_err(&adapter->dev,
                        "failed to add I2C device %s from ACPI\n",
                        dev_name(&adev->dev));
        }
 +}
 +
 +static acpi_status acpi_i2c_add_device(acpi_handle handle, u32 level,
 +                                     void *data, void **return_value)
 +{
 +      struct i2c_adapter *adapter = data;
 +      struct acpi_device *adev;
 +      acpi_handle adapter_handle;
 +      struct i2c_board_info info;
 +
 +      if (acpi_bus_get_device(handle, &adev))
 +              return AE_OK;
 +
 +      if (acpi_i2c_get_info(adev, &info, &adapter_handle))
 +              return AE_OK;
 +
 +      if (adapter_handle != ACPI_HANDLE(&adapter->dev))
 +              return AE_OK;
 +
 +      acpi_i2c_register_device(adapter, adev, &info);
  
        return AE_OK;
  }
@@@ -246,80 -227,8 +248,80 @@@ static void acpi_i2c_register_devices(s
                dev_warn(&adap->dev, "failed to enumerate I2C slaves\n");
  }
  
 +static int acpi_i2c_match_adapter(struct device *dev, void *data)
 +{
 +      struct i2c_adapter *adapter = i2c_verify_adapter(dev);
 +
 +      if (!adapter)
 +              return 0;
 +
 +      return ACPI_HANDLE(dev) == (acpi_handle)data;
 +}
 +
 +static int acpi_i2c_match_device(struct device *dev, void *data)
 +{
 +      return ACPI_COMPANION(dev) == data;
 +}
 +
 +static struct i2c_adapter *acpi_i2c_find_adapter_by_handle(acpi_handle handle)
 +{
 +      struct device *dev;
 +
 +      dev = bus_find_device(&i2c_bus_type, NULL, handle,
 +                            acpi_i2c_match_adapter);
 +      return dev ? i2c_verify_adapter(dev) : NULL;
 +}
 +
 +static struct i2c_client *acpi_i2c_find_client_by_adev(struct acpi_device *adev)
 +{
 +      struct device *dev;
 +
 +      dev = bus_find_device(&i2c_bus_type, NULL, adev, acpi_i2c_match_device);
 +      return dev ? i2c_verify_client(dev) : NULL;
 +}
 +
 +static int acpi_i2c_notify(struct notifier_block *nb, unsigned long value,
 +                         void *arg)
 +{
 +      struct acpi_device *adev = arg;
 +      struct i2c_board_info info;
 +      acpi_handle adapter_handle;
 +      struct i2c_adapter *adapter;
 +      struct i2c_client *client;
 +
 +      switch (value) {
 +      case ACPI_RECONFIG_DEVICE_ADD:
 +              if (acpi_i2c_get_info(adev, &info, &adapter_handle))
 +                      break;
 +
 +              adapter = acpi_i2c_find_adapter_by_handle(adapter_handle);
 +              if (!adapter)
 +                      break;
 +
 +              acpi_i2c_register_device(adapter, adev, &info);
 +              break;
 +      case ACPI_RECONFIG_DEVICE_REMOVE:
 +              if (!acpi_device_enumerated(adev))
 +                      break;
 +
 +              client = acpi_i2c_find_client_by_adev(adev);
 +              if (!client)
 +                      break;
 +
 +              i2c_unregister_device(client);
 +              put_device(&client->dev);
 +              break;
 +      }
 +
 +      return NOTIFY_OK;
 +}
 +
 +static struct notifier_block i2c_acpi_notifier = {
 +      .notifier_call = acpi_i2c_notify,
 +};
  #else /* CONFIG_ACPI */
  static inline void acpi_i2c_register_devices(struct i2c_adapter *adap) { }
 +extern struct notifier_block i2c_acpi_notifier;
  #endif /* CONFIG_ACPI */
  
  #ifdef CONFIG_ACPI_I2C_OPREGION
@@@ -493,7 -402,8 +495,8 @@@ acpi_i2c_space_handler(u32 function, ac
                break;
  
        default:
-               pr_info("protocol(0x%02x) is not supported.\n", accessor_type);
+               dev_warn(&adapter->dev, "protocol 0x%02x not supported for client 0x%02x\n",
+                        accessor_type, client->addr);
                ret = AE_BAD_PARAMETER;
                goto err;
        }
@@@ -759,6 -669,47 +762,47 @@@ int i2c_recover_bus(struct i2c_adapter 
  }
  EXPORT_SYMBOL_GPL(i2c_recover_bus);
  
+ static void i2c_init_recovery(struct i2c_adapter *adap)
+ {
+       struct i2c_bus_recovery_info *bri = adap->bus_recovery_info;
+       char *err_str;
+       if (!bri)
+               return;
+       if (!bri->recover_bus) {
+               err_str = "no recover_bus() found";
+               goto err;
+       }
+       /* Generic GPIO recovery */
+       if (bri->recover_bus == i2c_generic_gpio_recovery) {
+               if (!gpio_is_valid(bri->scl_gpio)) {
+                       err_str = "invalid SCL gpio";
+                       goto err;
+               }
+               if (gpio_is_valid(bri->sda_gpio))
+                       bri->get_sda = get_sda_gpio_value;
+               else
+                       bri->get_sda = NULL;
+               bri->get_scl = get_scl_gpio_value;
+               bri->set_scl = set_scl_gpio_value;
+       } else if (bri->recover_bus == i2c_generic_scl_recovery) {
+               /* Generic SCL recovery */
+               if (!bri->set_scl || !bri->get_scl) {
+                       err_str = "no {get|set}_scl() found";
+                       goto err;
+               }
+       }
+       return;
+  err:
+       dev_err(&adap->dev, "Not using recovery: %s\n", err_str);
+       adap->bus_recovery_info = NULL;
+ }
  static int i2c_device_probe(struct device *dev)
  {
        struct i2c_client       *client = i2c_verify_client(dev);
@@@ -1182,8 -1133,6 +1226,8 @@@ void i2c_unregister_device(struct i2c_c
  {
        if (client->dev.of_node)
                of_node_clear_flag(client->dev.of_node, OF_POPULATED);
 +      if (ACPI_COMPANION(&client->dev))
 +              acpi_device_clear_enumerated(ACPI_COMPANION(&client->dev));
        device_unregister(&client->dev);
  }
  EXPORT_SYMBOL_GPL(i2c_unregister_device);
@@@ -1240,6 -1189,47 +1284,47 @@@ struct i2c_client *i2c_new_dummy(struc
  }
  EXPORT_SYMBOL_GPL(i2c_new_dummy);
  
+ /**
+  * i2c_new_secondary_device - Helper to get the instantiated secondary address
+  * and create the associated device
+  * @client: Handle to the primary client
+  * @name: Handle to specify which secondary address to get
+  * @default_addr: Used as a fallback if no secondary address was specified
+  * Context: can sleep
+  *
+  * I2C clients can be composed of multiple I2C slaves bound together in a single
+  * component. The I2C client driver then binds to the master I2C slave and needs
+  * to create I2C dummy clients to communicate with all the other slaves.
+  *
+  * This function creates and returns an I2C dummy client whose I2C address is
+  * retrieved from the platform firmware based on the given slave name. If no
+  * address is specified by the firmware default_addr is used.
+  *
+  * On DT-based platforms the address is retrieved from the "reg" property entry
+  * cell whose "reg-names" value matches the slave name.
+  *
+  * This returns the new i2c client, which should be saved for later use with
+  * i2c_unregister_device(); or NULL to indicate an error.
+  */
+ struct i2c_client *i2c_new_secondary_device(struct i2c_client *client,
+                                               const char *name,
+                                               u16 default_addr)
+ {
+       struct device_node *np = client->dev.of_node;
+       u32 addr = default_addr;
+       int i;
+       if (np) {
+               i = of_property_match_string(np, "reg-names", name);
+               if (i >= 0)
+                       of_property_read_u32_index(np, "reg", i, &addr);
+       }
+       dev_dbg(&client->adapter->dev, "Address for %s : 0x%x\n", name, addr);
+       return i2c_new_dummy(client->adapter, addr);
+ }
+ EXPORT_SYMBOL_GPL(i2c_new_secondary_device);
  /* ------------------------------------------------------------------------- */
  
  /* I2C bus adapters -- one roots each I2C or SMBUS segment */
@@@ -1608,7 -1598,7 +1693,7 @@@ static int __process_new_adapter(struc
  
  static int i2c_register_adapter(struct i2c_adapter *adap)
  {
-       int res = 0;
+       int res = -EINVAL;
  
        /* Can't register until after driver model init */
        if (WARN_ON(!is_registered)) {
        }
  
        /* Sanity checks */
-       if (unlikely(adap->name[0] == '\0')) {
-               pr_err("i2c-core: Attempt to register an adapter with "
-                      "no name!\n");
-               return -EINVAL;
-       }
-       if (unlikely(!adap->algo)) {
-               pr_err("i2c-core: Attempt to register adapter '%s' with "
-                      "no algo!\n", adap->name);
-               return -EINVAL;
+       if (WARN(!adap->name[0], "i2c adapter has no name"))
+               goto out_list;
+       if (!adap->algo) {
+               pr_err("adapter '%s': no algo supplied!\n", adap->name);
+               goto out_list;
        }
  
        if (!adap->lock_bus) {
        adap->dev.bus = &i2c_bus_type;
        adap->dev.type = &i2c_adapter_type;
        res = device_register(&adap->dev);
-       if (res)
+       if (res) {
+               pr_err("adapter '%s': can't register device (%d)\n", adap->name, res);
                goto out_list;
+       }
  
        dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name);
  
                         "Failed to create compatibility class link\n");
  #endif
  
-       /* bus recovery specific initialization */
-       if (adap->bus_recovery_info) {
-               struct i2c_bus_recovery_info *bri = adap->bus_recovery_info;
-               if (!bri->recover_bus) {
-                       dev_err(&adap->dev, "No recover_bus() found, not using recovery\n");
-                       adap->bus_recovery_info = NULL;
-                       goto exit_recovery;
-               }
-               /* Generic GPIO recovery */
-               if (bri->recover_bus == i2c_generic_gpio_recovery) {
-                       if (!gpio_is_valid(bri->scl_gpio)) {
-                               dev_err(&adap->dev, "Invalid SCL gpio, not using recovery\n");
-                               adap->bus_recovery_info = NULL;
-                               goto exit_recovery;
-                       }
+       i2c_init_recovery(adap);
  
-                       if (gpio_is_valid(bri->sda_gpio))
-                               bri->get_sda = get_sda_gpio_value;
-                       else
-                               bri->get_sda = NULL;
-                       bri->get_scl = get_scl_gpio_value;
-                       bri->set_scl = set_scl_gpio_value;
-               } else if (bri->recover_bus == i2c_generic_scl_recovery) {
-                       /* Generic SCL recovery */
-                       if (!bri->set_scl || !bri->get_scl) {
-                               dev_err(&adap->dev, "No {get|set}_scl() found, not using recovery\n");
-                               adap->bus_recovery_info = NULL;
-                       }
-               }
-       }
- exit_recovery:
        /* create pre-declared device nodes */
        of_i2c_register_devices(adap);
        acpi_i2c_register_devices(adap);
@@@ -1730,13 -1686,12 +1781,12 @@@ out_list
   */
  static int __i2c_add_numbered_adapter(struct i2c_adapter *adap)
  {
-       int     id;
+       int id;
  
        mutex_lock(&core_lock);
-       id = idr_alloc(&i2c_adapter_idr, adap, adap->nr, adap->nr + 1,
-                      GFP_KERNEL);
+       id = idr_alloc(&i2c_adapter_idr, adap, adap->nr, adap->nr + 1, GFP_KERNEL);
        mutex_unlock(&core_lock);
-       if (id < 0)
+       if (WARN(id < 0, "couldn't get idr"))
                return id == -ENOSPC ? -EBUSY : id;
  
        return i2c_register_adapter(adap);
@@@ -1773,7 -1728,7 +1823,7 @@@ int i2c_add_adapter(struct i2c_adapter 
        id = idr_alloc(&i2c_adapter_idr, adapter,
                       __i2c_first_dynamic_bus_num, 0, GFP_KERNEL);
        mutex_unlock(&core_lock);
-       if (id < 0)
+       if (WARN(id < 0, "couldn't get idr"))
                return id;
  
        adapter->nr = id;
@@@ -1871,8 -1826,7 +1921,7 @@@ void i2c_del_adapter(struct i2c_adapte
        found = idr_find(&i2c_adapter_idr, adap->nr);
        mutex_unlock(&core_lock);
        if (found != adap) {
-               pr_debug("i2c-core: attempting to delete unregistered "
-                        "adapter [%s]\n", adap->name);
+               pr_debug("attempting to delete unregistered adapter [%s]\n", adap->name);
                return;
        }
  
@@@ -2032,7 -1986,7 +2081,7 @@@ int i2c_register_driver(struct module *
        if (res)
                return res;
  
-       pr_debug("i2c-core: driver [%s] registered\n", driver->driver.name);
+       pr_debug("driver [%s] registered\n", driver->driver.name);
  
        INIT_LIST_HEAD(&driver->clients);
        /* Walk the adapters that are already present */
@@@ -2059,7 -2013,7 +2108,7 @@@ void i2c_del_driver(struct i2c_driver *
        i2c_for_each_dev(driver, __process_removed_driver);
  
        driver_unregister(&driver->driver);
-       pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name);
+       pr_debug("driver [%s] unregistered\n", driver->driver.name);
  }
  EXPORT_SYMBOL(i2c_del_driver);
  
@@@ -2150,8 -2104,8 +2199,8 @@@ static int of_i2c_notify(struct notifie
                put_device(&adap->dev);
  
                if (IS_ERR(client)) {
-                       pr_err("%s: failed to create for '%s'\n",
-                                       __func__, rd->dn->full_name);
+                       dev_err(&adap->dev, "failed to create client for '%s'\n",
+                                rd->dn->full_name);
                        return notifier_from_errno(PTR_ERR(client));
                }
                break;
@@@ -2212,8 -2166,6 +2261,8 @@@ static int __init i2c_init(void
  
        if (IS_ENABLED(CONFIG_OF_DYNAMIC))
                WARN_ON(of_reconfig_notifier_register(&i2c_of_notifier));
 +      if (IS_ENABLED(CONFIG_ACPI))
 +              WARN_ON(acpi_reconfig_notifier_register(&i2c_acpi_notifier));
  
        return 0;
  
@@@ -2229,8 -2181,6 +2278,8 @@@ bus_err
  
  static void __exit i2c_exit(void)
  {
 +      if (IS_ENABLED(CONFIG_ACPI))
 +              WARN_ON(acpi_reconfig_notifier_unregister(&i2c_acpi_notifier));
        if (IS_ENABLED(CONFIG_OF_DYNAMIC))
                WARN_ON(of_reconfig_notifier_unregister(&i2c_of_notifier));
        i2c_del_driver(&dummy_driver);
@@@ -2772,7 -2722,7 +2821,7 @@@ static int i2c_smbus_check_pec(u8 cpec
        cpec = i2c_smbus_msg_pec(cpec, msg);
  
        if (rpec != cpec) {
-               pr_debug("i2c-core: Bad PEC 0x%02x vs. 0x%02x\n",
+               pr_debug("Bad PEC 0x%02x vs. 0x%02x\n",
                        rpec, cpec);
                return -EBADMSG;
        }