+
+static int pmbus_get_flags(struct pmbus_data *data, u8 page, unsigned int *error,
+ bool notify)
{
- int i, status;
const struct pmbus_regulator_status_category *cat;
const struct pmbus_regulator_status_assoc *bit;
- struct device *dev = rdev_get_dev(rdev);
- struct i2c_client *client = to_i2c_client(dev->parent);
- struct pmbus_data *data = i2c_get_clientdata(client);
- u8 page = rdev_get_id(rdev);
+ struct i2c_client *client = to_i2c_client(data->dev);
int func = data->info->func[page];
+ int i, status, ret;
- *flags = 0;
+ *error = 0;
mutex_lock(&data->update_lock);
@@ -2803,14 +2828,17 @@ static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsigned
status = _pmbus_read_byte_data(client, page, cat->reg);
if (status < 0) {
- mutex_unlock(&data->update_lock);
- return status;
+ ret = status;
+ goto unlock;
}
for (bit = cat->bits; bit->pflag; bit++) {
if (status & bit->pflag)
- *flags |= bit->rflag;
+ *error |= bit->rflag;
}
+
+ if (notify && status)
+ pmbus_notify(data, page, cat->reg, status);
}
/*
@@ -2823,36 +2851,53 @@ static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsigned
* REGULATOR_ERROR_<foo>_WARN.
*/
status = pmbus_get_status(client, page, PMBUS_STATUS_WORD);
- mutex_unlock(&data->update_lock);
- if (status < 0)
- return status;
- if (pmbus_regulator_is_enabled(rdev)) {
+ if (status < 0) {
+ ret = status;
+ goto unlock;
+ }
+
+ ret = _pmbus_read_byte_data(client, page, PMBUS_OPERATION);
+ if (ret < 0)
+ goto unlock;
+
+ if (ret & PB_OPERATION_CONTROL_ON) {
if (status & PB_STATUS_OFF)
- *flags |= REGULATOR_ERROR_FAIL;
+ *error |= REGULATOR_ERROR_FAIL;
if (status & PB_STATUS_POWER_GOOD_N)
- *flags |= REGULATOR_ERROR_REGULATION_OUT;
+ *error |= REGULATOR_ERROR_REGULATION_OUT;
}
/*
* Unlike most other status bits, PB_STATUS_{IOUT_OC,VOUT_OV} are
* defined strictly as fault indicators (not warnings).
*/
if (status & PB_STATUS_IOUT_OC)
- *flags |= REGULATOR_ERROR_OVER_CURRENT;
+ *error |= REGULATOR_ERROR_OVER_CURRENT;
if (status & PB_STATUS_VOUT_OV)
- *flags |= REGULATOR_ERROR_REGULATION_OUT;
+ *error |= REGULATOR_ERROR_REGULATION_OUT;
/*
* If we haven't discovered any thermal faults or warnings via
* PMBUS_STATUS_TEMPERATURE, map PB_STATUS_TEMPERATURE to a warning as
* a (conservative) best-effort interpretation.
*/
- if (!(*flags & (REGULATOR_ERROR_OVER_TEMP | REGULATOR_ERROR_OVER_TEMP_WARN)) &&
+ if (!(*error & (REGULATOR_ERROR_OVER_TEMP | REGULATOR_ERROR_OVER_TEMP_WARN)) &&
(status & PB_STATUS_TEMPERATURE))
- *flags |= REGULATOR_ERROR_OVER_TEMP_WARN;
+ *error |= REGULATOR_ERROR_OVER_TEMP_WARN;
- return 0;
+unlock:
+ mutex_unlock(&data->update_lock);
+ return ret;
+}
+
+static int pmbus_regulator_get_error_flags(struct regulator_dev *rdev, unsigned int *flags)
+{
+ struct device *dev = rdev_get_dev(rdev);
+ struct i2c_client *client = to_i2c_client(dev->parent);
+ struct pmbus_data *data = i2c_get_clientdata(client);
+
+ return pmbus_get_flags(data, rdev_get_id(rdev), flags, false);
}
static int pmbus_regulator_get_status(struct regulator_dev *rdev)
@@ -3082,10 +3127,14 @@ static irqreturn_t pmbus_fault_handler(int irq, void *pdata)
{
struct pmbus_data *data = pdata;
struct i2c_client *client = to_i2c_client(data->dev);
- int i, status;
+ int i, status, ret;
for (i = 0; i < data->info->pages; i++) {
+ ret = pmbus_get_flags(data, i, &status, true);
+ if (ret)
+ return ret;
+
mutex_lock(&data->update_lock);
status = pmbus_read_status_word(client, i);
if (status < 0) {
@@ -3099,7 +3148,7 @@ static irqreturn_t pmbus_fault_handler(int irq, void *pdata)
mutex_unlock(&data->update_lock);
}
- return IRQ_HANDLED;
+ return ret;
}
static int pmbus_irq_setup(struct i2c_client *client, struct pmbus_data *data)