aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power/rt5033_battery.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/power/rt5033_battery.c')
-rw-r--r--drivers/power/rt5033_battery.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/drivers/power/rt5033_battery.c b/drivers/power/rt5033_battery.c
index 7b898f41c595..a7a6877b4e16 100644
--- a/drivers/power/rt5033_battery.c
+++ b/drivers/power/rt5033_battery.c
@@ -72,8 +72,7 @@ static int rt5033_battery_get_property(struct power_supply *psy,
72 enum power_supply_property psp, 72 enum power_supply_property psp,
73 union power_supply_propval *val) 73 union power_supply_propval *val)
74{ 74{
75 struct rt5033_battery *battery = container_of(psy, 75 struct rt5033_battery *battery = power_supply_get_drvdata(psy);
76 struct rt5033_battery, psy);
77 76
78 switch (psp) { 77 switch (psp) {
79 case POWER_SUPPLY_PROP_VOLTAGE_NOW: 78 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
@@ -102,16 +101,25 @@ static enum power_supply_property rt5033_battery_props[] = {
102 POWER_SUPPLY_PROP_CAPACITY, 101 POWER_SUPPLY_PROP_CAPACITY,
103}; 102};
104 103
105static struct regmap_config rt5033_battery_regmap_config = { 104static const struct regmap_config rt5033_battery_regmap_config = {
106 .reg_bits = 8, 105 .reg_bits = 8,
107 .val_bits = 8, 106 .val_bits = 8,
108 .max_register = RT5033_FUEL_REG_END, 107 .max_register = RT5033_FUEL_REG_END,
109}; 108};
110 109
110static const struct power_supply_desc rt5033_battery_desc = {
111 .name = "rt5033-battery",
112 .type = POWER_SUPPLY_TYPE_BATTERY,
113 .get_property = rt5033_battery_get_property,
114 .properties = rt5033_battery_props,
115 .num_properties = ARRAY_SIZE(rt5033_battery_props),
116};
117
111static int rt5033_battery_probe(struct i2c_client *client, 118static int rt5033_battery_probe(struct i2c_client *client,
112 const struct i2c_device_id *id) 119 const struct i2c_device_id *id)
113{ 120{
114 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 121 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
122 struct power_supply_config psy_cfg = {};
115 struct rt5033_battery *battery; 123 struct rt5033_battery *battery;
116 u32 ret; 124 u32 ret;
117 125
@@ -131,16 +139,13 @@ static int rt5033_battery_probe(struct i2c_client *client,
131 } 139 }
132 140
133 i2c_set_clientdata(client, battery); 141 i2c_set_clientdata(client, battery);
142 psy_cfg.drv_data = battery;
134 143
135 battery->psy.name = "rt5033-battery"; 144 battery->psy = power_supply_register(&client->dev,
136 battery->psy.type = POWER_SUPPLY_TYPE_BATTERY; 145 &rt5033_battery_desc, &psy_cfg);
137 battery->psy.get_property = rt5033_battery_get_property; 146 if (IS_ERR(battery->psy)) {
138 battery->psy.properties = rt5033_battery_props;
139 battery->psy.num_properties = ARRAY_SIZE(rt5033_battery_props);
140
141 ret = power_supply_register(&client->dev, &battery->psy);
142 if (ret) {
143 dev_err(&client->dev, "Failed to register power supply\n"); 147 dev_err(&client->dev, "Failed to register power supply\n");
148 ret = PTR_ERR(battery->psy);
144 return ret; 149 return ret;
145 } 150 }
146 151
@@ -151,7 +156,7 @@ static int rt5033_battery_remove(struct i2c_client *client)
151{ 156{
152 struct rt5033_battery *battery = i2c_get_clientdata(client); 157 struct rt5033_battery *battery = i2c_get_clientdata(client);
153 158
154 power_supply_unregister(&battery->psy); 159 power_supply_unregister(battery->psy);
155 160
156 return 0; 161 return 0;
157} 162}