[PATCH 2/2] power: supply: ucs1002: Add HWMON interface

From: Andrey Smirnov
Date: Wed May 29 2019 - 03:14:56 EST


Expose current sensors found on UCS1002 via HWMON.

Signed-off-by: Andrey Smirnov <andrew.smirnov@xxxxxxxxx>
Cc: Chris Healy <cphealy@xxxxxxxxx>
Cc: Lucas Stach <l.stach@xxxxxxxxxxxxxx>
Cc: Fabio Estevam <fabio.estevam@xxxxxxx>
Cc: Guenter Roeck <linux@xxxxxxxxxxxx>
Cc: Sebastian Reichel <sre@xxxxxxxxxx>
Cc: linux-kernel@xxxxxxxxxxxxxxx
Cc: linux-pm@xxxxxxxxxxxxxxx
---
drivers/power/supply/ucs1002_power.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/power/supply/ucs1002_power.c b/drivers/power/supply/ucs1002_power.c
index 1c89d030c045..1faf2ef7d3f0 100644
--- a/drivers/power/supply/ucs1002_power.c
+++ b/drivers/power/supply/ucs1002_power.c
@@ -491,7 +491,7 @@ static const struct regulator_desc ucs1002_regulator_descriptor = {
static int ucs1002_probe(struct i2c_client *client,
const struct i2c_device_id *dev_id)
{
- struct device *dev = &client->dev;
+ struct device *hwmon, *dev = &client->dev;
struct power_supply_config charger_config = {};
const struct regmap_config regmap_config = {
.reg_bits = 8,
@@ -571,6 +571,13 @@ static int ucs1002_probe(struct i2c_client *client,
return ret;
}

+ hwmon = devm_power_supply_add_hwmon_sysfs(info->charger);
+ ret = PTR_ERR_OR_ZERO(hwmon);
+ if (ret) {
+ dev_err(dev, "Failed to add hmwon attributes: %d\n", ret);
+ return ret;
+ }
+
ret = regmap_read(info->regmap, UCS1002_REG_PIN_STATUS, &regval);
if (ret) {
dev_err(dev, "Failed to read pin status: %d\n", ret);
--
2.21.0