aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power/max8998_charger.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/power/max8998_charger.c')
-rw-r--r--drivers/power/max8998_charger.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/drivers/power/max8998_charger.c b/drivers/power/max8998_charger.c
index 08694c7a9f38..47448d4bc6cd 100644
--- a/drivers/power/max8998_charger.c
+++ b/drivers/power/max8998_charger.c
@@ -30,7 +30,7 @@
30struct max8998_battery_data { 30struct max8998_battery_data {
31 struct device *dev; 31 struct device *dev;
32 struct max8998_dev *iodev; 32 struct max8998_dev *iodev;
33 struct power_supply battery; 33 struct power_supply *battery;
34}; 34};
35 35
36static enum power_supply_property max8998_battery_props[] = { 36static enum power_supply_property max8998_battery_props[] = {
@@ -43,8 +43,7 @@ static int max8998_battery_get_property(struct power_supply *psy,
43 enum power_supply_property psp, 43 enum power_supply_property psp,
44 union power_supply_propval *val) 44 union power_supply_propval *val)
45{ 45{
46 struct max8998_battery_data *max8998 = container_of(psy, 46 struct max8998_battery_data *max8998 = power_supply_get_drvdata(psy);
47 struct max8998_battery_data, battery);
48 struct i2c_client *i2c = max8998->iodev->i2c; 47 struct i2c_client *i2c = max8998->iodev->i2c;
49 int ret; 48 int ret;
50 u8 reg; 49 u8 reg;
@@ -75,10 +74,19 @@ static int max8998_battery_get_property(struct power_supply *psy,
75 return 0; 74 return 0;
76} 75}
77 76
77static const struct power_supply_desc max8998_battery_desc = {
78 .name = "max8998_pmic",
79 .type = POWER_SUPPLY_TYPE_BATTERY,
80 .get_property = max8998_battery_get_property,
81 .properties = max8998_battery_props,
82 .num_properties = ARRAY_SIZE(max8998_battery_props),
83};
84
78static int max8998_battery_probe(struct platform_device *pdev) 85static int max8998_battery_probe(struct platform_device *pdev)
79{ 86{
80 struct max8998_dev *iodev = dev_get_drvdata(pdev->dev.parent); 87 struct max8998_dev *iodev = dev_get_drvdata(pdev->dev.parent);
81 struct max8998_platform_data *pdata = dev_get_platdata(iodev->dev); 88 struct max8998_platform_data *pdata = dev_get_platdata(iodev->dev);
89 struct power_supply_config psy_cfg = {};
82 struct max8998_battery_data *max8998; 90 struct max8998_battery_data *max8998;
83 struct i2c_client *i2c; 91 struct i2c_client *i2c;
84 int ret = 0; 92 int ret = 0;
@@ -161,15 +169,15 @@ static int max8998_battery_probe(struct platform_device *pdev)
161 goto err; 169 goto err;
162 } 170 }
163 171
164 max8998->battery.name = "max8998_pmic"; 172 psy_cfg.drv_data = max8998;
165 max8998->battery.type = POWER_SUPPLY_TYPE_BATTERY;
166 max8998->battery.get_property = max8998_battery_get_property;
167 max8998->battery.properties = max8998_battery_props;
168 max8998->battery.num_properties = ARRAY_SIZE(max8998_battery_props);
169 173
170 ret = power_supply_register(max8998->dev, &max8998->battery); 174 max8998->battery = power_supply_register(max8998->dev,
171 if (ret) { 175 &max8998_battery_desc,
172 dev_err(max8998->dev, "failed: power supply register\n"); 176 &psy_cfg);
177 if (IS_ERR(max8998->battery)) {
178 ret = PTR_ERR(max8998->battery);
179 dev_err(max8998->dev, "failed: power supply register: %d\n",
180 ret);
173 goto err; 181 goto err;
174 } 182 }
175 183
@@ -182,7 +190,7 @@ static int max8998_battery_remove(struct platform_device *pdev)
182{ 190{
183 struct max8998_battery_data *max8998 = platform_get_drvdata(pdev); 191 struct max8998_battery_data *max8998 = platform_get_drvdata(pdev);
184 192
185 power_supply_unregister(&max8998->battery); 193 power_supply_unregister(max8998->battery);
186 194
187 return 0; 195 return 0;
188} 196}