Message ID | 1442339914-25843-9-git-send-email-dannenberg@ti.com (mailing list archive) |
---|---|
State | Not Applicable, archived |
Headers | show |
On 16.09.2015 02:58, Andreas Dannenberg wrote: > This patch allows reading (and writing, if the D+/D- USB signal-based > charger type detection is disabled) of the input current limit through > the POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT sysfs property. This allows > userspace to see what charger was detected and to re-configure the > maximum current drawn from the external supply at runtime based on > system-level knowledge or user input. > > Signed-off-by: Andreas Dannenberg <dannenberg@ti.com> > --- > drivers/power/bq24257_charger.c | 67 +++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 67 insertions(+) > Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com> BTW you are exposing more and more sysfs attributes which are userspace interfaces. They should be documented: Documentation/SubmitChecklist - point 19 Documentation/ABI/README Although not all new drivers (and perhaps not all reviewers) follow this rule... Best regards, Krzysztof -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wed, Sep 16, 2015 at 03:31:06PM +0900, Krzysztof Kozlowski wrote: > On 16.09.2015 02:58, Andreas Dannenberg wrote: > > This patch allows reading (and writing, if the D+/D- USB signal-based > > charger type detection is disabled) of the input current limit through > > the POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT sysfs property. This allows > > userspace to see what charger was detected and to re-configure the > > maximum current drawn from the external supply at runtime based on > > system-level knowledge or user input. > > > > Signed-off-by: Andreas Dannenberg <dannenberg@ti.com> > > --- > > drivers/power/bq24257_charger.c | 67 +++++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 67 insertions(+) > > > > Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com> > > BTW you are exposing more and more sysfs attributes which are userspace > interfaces. They should be documented: > Documentation/SubmitChecklist - point 19 > Documentation/ABI/README The patch comment is not 100% accurate. I'm not declaring/exposing a new sysfs property but rather use the power supply framework to expose the sysfs property that's associated with POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT which is actually called "input_current_limit". Will reword the description to make this clearer. Regards, -- Andreas Dannenberg Texas Instruments Inc > > Although not all new drivers (and perhaps not all reviewers) follow this > rule... > > Best regards, > Krzysztof > -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/drivers/power/bq24257_charger.c b/drivers/power/bq24257_charger.c index 84a8945..517a522 100644 --- a/drivers/power/bq24257_charger.c +++ b/drivers/power/bq24257_charger.c @@ -265,6 +265,42 @@ enum bq24257_fault { FAULT_INPUT_LDO_LOW, }; +static int bq24257_get_input_current_limit(struct bq24257_device *bq, + union power_supply_propval *val) +{ + int ret; + + ret = bq24257_field_read(bq, F_IILIMIT); + if (ret < 0) + return ret; + + /* + * The "External ILIM" and "Production & Test" modes are not exposed + * through this driver and not being covered by the lookup table. + * Should such a mode have become active let's return an error rather + * than exceeding the bounds of the lookup table and returning + * garbage. + */ + if (ret >= BQ24257_IILIMIT_MAP_SIZE) + return -ENODATA; + + val->intval = bq24257_iilimit_map[ret]; + + return 0; +} + +static int bq24257_set_input_current_limit(struct bq24257_device *bq, + const union power_supply_propval *val) +{ + if (!bq->in_ilimit_autoset_disable) + return -EPERM; + + return bq24257_field_write(bq, F_IILIMIT, + bq24257_find_idx(val->intval, + bq24257_iilimit_map, + BQ24257_IILIMIT_MAP_SIZE)); +} + static int bq24257_power_supply_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) @@ -349,6 +385,9 @@ static int bq24257_power_supply_get_property(struct power_supply *psy, val->intval = bq24257_iterm_map[bq->init_data.iterm]; break; + case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: + return bq24257_get_input_current_limit(bq, val); + default: return -EINVAL; } @@ -356,6 +395,31 @@ static int bq24257_power_supply_get_property(struct power_supply *psy, return 0; } +static int bq24257_power_supply_set_property(struct power_supply *psy, + enum power_supply_property prop, + const union power_supply_propval *val) +{ + struct bq24257_device *bq = power_supply_get_drvdata(psy); + + switch (prop) { + case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: + return bq24257_set_input_current_limit(bq, val); + default: + return -EINVAL; + } +} + +static int bq24257_power_supply_property_is_writeable(struct power_supply *psy, + enum power_supply_property psp) +{ + switch (psp) { + case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: + return true; + default: + return false; + } +} + static int bq24257_get_chip_state(struct bq24257_device *bq, struct bq24257_state *state) { @@ -691,6 +755,7 @@ static enum power_supply_property bq24257_power_supply_props[] = { POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE, POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX, POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT, + POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, }; static char *bq24257_charger_supplied_to[] = { @@ -703,6 +768,8 @@ static const struct power_supply_desc bq24257_power_supply_desc = { .properties = bq24257_power_supply_props, .num_properties = ARRAY_SIZE(bq24257_power_supply_props), .get_property = bq24257_power_supply_get_property, + .set_property = bq24257_power_supply_set_property, + .property_is_writeable = bq24257_power_supply_property_is_writeable, }; static ssize_t bq24257_show_ovp_voltage(struct device *dev,
This patch allows reading (and writing, if the D+/D- USB signal-based charger type detection is disabled) of the input current limit through the POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT sysfs property. This allows userspace to see what charger was detected and to re-configure the maximum current drawn from the external supply at runtime based on system-level knowledge or user input. Signed-off-by: Andreas Dannenberg <dannenberg@ti.com> --- drivers/power/bq24257_charger.c | 67 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+)