Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 1 | /* |
| 2 | * Universal power supply monitor class |
| 3 | * |
| 4 | * Copyright © 2007 Anton Vorontsov <cbou@mail.ru> |
| 5 | * Copyright © 2004 Szabolcs Gyurko |
| 6 | * Copyright © 2003 Ian Molton <spyro@f2s.com> |
| 7 | * |
| 8 | * Modified: 2004, Oct Szabolcs Gyurko |
| 9 | * |
| 10 | * You may use this code as per GPL version 2 |
| 11 | */ |
| 12 | |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/types.h> |
| 15 | #include <linux/init.h> |
Anton Vorontsov | 5f487cd | 2010-05-18 21:49:51 +0200 | [diff] [blame] | 16 | #include <linux/slab.h> |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 17 | #include <linux/device.h> |
| 18 | #include <linux/err.h> |
| 19 | #include <linux/power_supply.h> |
Jenny TC | 3be330b | 2012-05-09 20:36:47 +0530 | [diff] [blame] | 20 | #include <linux/thermal.h> |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 21 | #include "power_supply.h" |
| 22 | |
Daniel Mack | ff3417e | 2009-07-30 17:42:31 +0400 | [diff] [blame] | 23 | /* exported for the APM Power driver, APM emulation */ |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 24 | struct class *power_supply_class; |
Daniel Mack | ff3417e | 2009-07-30 17:42:31 +0400 | [diff] [blame] | 25 | EXPORT_SYMBOL_GPL(power_supply_class); |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 26 | |
Anton Vorontsov | 5f487cd | 2010-05-18 21:49:51 +0200 | [diff] [blame] | 27 | static struct device_type power_supply_dev_type; |
| 28 | |
Dave Young | 443cad9 | 2008-01-22 13:58:22 +0800 | [diff] [blame] | 29 | static int __power_supply_changed_work(struct device *dev, void *data) |
| 30 | { |
| 31 | struct power_supply *psy = (struct power_supply *)data; |
| 32 | struct power_supply *pst = dev_get_drvdata(dev); |
| 33 | int i; |
| 34 | |
| 35 | for (i = 0; i < psy->num_supplicants; i++) |
| 36 | if (!strcmp(psy->supplied_to[i], pst->name)) { |
| 37 | if (pst->external_power_changed) |
| 38 | pst->external_power_changed(pst); |
| 39 | } |
| 40 | return 0; |
| 41 | } |
| 42 | |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 43 | static void power_supply_changed_work(struct work_struct *work) |
| 44 | { |
| 45 | struct power_supply *psy = container_of(work, struct power_supply, |
| 46 | changed_work); |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 47 | |
Harvey Harrison | 0cddc0a | 2008-04-29 00:58:29 -0700 | [diff] [blame] | 48 | dev_dbg(psy->dev, "%s\n", __func__); |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 49 | |
Greg Kroah-Hartman | 93562b5 | 2008-05-22 17:21:08 -0400 | [diff] [blame] | 50 | class_for_each_device(power_supply_class, NULL, psy, |
Dave Young | 443cad9 | 2008-01-22 13:58:22 +0800 | [diff] [blame] | 51 | __power_supply_changed_work); |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 52 | |
| 53 | power_supply_update_leds(psy); |
| 54 | |
| 55 | kobject_uevent(&psy->dev->kobj, KOBJ_CHANGE); |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | void power_supply_changed(struct power_supply *psy) |
| 59 | { |
Harvey Harrison | 0cddc0a | 2008-04-29 00:58:29 -0700 | [diff] [blame] | 60 | dev_dbg(psy->dev, "%s\n", __func__); |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 61 | |
| 62 | schedule_work(&psy->changed_work); |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 63 | } |
Daniel Mack | ff3417e | 2009-07-30 17:42:31 +0400 | [diff] [blame] | 64 | EXPORT_SYMBOL_GPL(power_supply_changed); |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 65 | |
Dave Young | 443cad9 | 2008-01-22 13:58:22 +0800 | [diff] [blame] | 66 | static int __power_supply_am_i_supplied(struct device *dev, void *data) |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 67 | { |
| 68 | union power_supply_propval ret = {0,}; |
Dave Young | 443cad9 | 2008-01-22 13:58:22 +0800 | [diff] [blame] | 69 | struct power_supply *psy = (struct power_supply *)data; |
| 70 | struct power_supply *epsy = dev_get_drvdata(dev); |
| 71 | int i; |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 72 | |
Dave Young | 443cad9 | 2008-01-22 13:58:22 +0800 | [diff] [blame] | 73 | for (i = 0; i < epsy->num_supplicants; i++) { |
| 74 | if (!strcmp(epsy->supplied_to[i], psy->name)) { |
| 75 | if (epsy->get_property(epsy, |
| 76 | POWER_SUPPLY_PROP_ONLINE, &ret)) |
| 77 | continue; |
| 78 | if (ret.intval) |
| 79 | return ret.intval; |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 80 | } |
| 81 | } |
Dave Young | 443cad9 | 2008-01-22 13:58:22 +0800 | [diff] [blame] | 82 | return 0; |
| 83 | } |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 84 | |
Dave Young | 443cad9 | 2008-01-22 13:58:22 +0800 | [diff] [blame] | 85 | int power_supply_am_i_supplied(struct power_supply *psy) |
| 86 | { |
| 87 | int error; |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 88 | |
Greg Kroah-Hartman | 93562b5 | 2008-05-22 17:21:08 -0400 | [diff] [blame] | 89 | error = class_for_each_device(power_supply_class, NULL, psy, |
Dave Young | 443cad9 | 2008-01-22 13:58:22 +0800 | [diff] [blame] | 90 | __power_supply_am_i_supplied); |
| 91 | |
Harvey Harrison | 0cddc0a | 2008-04-29 00:58:29 -0700 | [diff] [blame] | 92 | dev_dbg(psy->dev, "%s %d\n", __func__, error); |
Dave Young | 443cad9 | 2008-01-22 13:58:22 +0800 | [diff] [blame] | 93 | |
| 94 | return error; |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 95 | } |
Daniel Mack | ff3417e | 2009-07-30 17:42:31 +0400 | [diff] [blame] | 96 | EXPORT_SYMBOL_GPL(power_supply_am_i_supplied); |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 97 | |
Matthew Garrett | 942ed16 | 2008-08-26 21:09:59 +0100 | [diff] [blame] | 98 | static int __power_supply_is_system_supplied(struct device *dev, void *data) |
| 99 | { |
| 100 | union power_supply_propval ret = {0,}; |
| 101 | struct power_supply *psy = dev_get_drvdata(dev); |
Jean Delvare | 2530daa | 2011-12-10 22:53:36 +0100 | [diff] [blame] | 102 | unsigned int *count = data; |
Matthew Garrett | 942ed16 | 2008-08-26 21:09:59 +0100 | [diff] [blame] | 103 | |
Jean Delvare | 2530daa | 2011-12-10 22:53:36 +0100 | [diff] [blame] | 104 | (*count)++; |
Matthew Garrett | 942ed16 | 2008-08-26 21:09:59 +0100 | [diff] [blame] | 105 | if (psy->type != POWER_SUPPLY_TYPE_BATTERY) { |
| 106 | if (psy->get_property(psy, POWER_SUPPLY_PROP_ONLINE, &ret)) |
| 107 | return 0; |
| 108 | if (ret.intval) |
| 109 | return ret.intval; |
| 110 | } |
| 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | int power_supply_is_system_supplied(void) |
| 115 | { |
| 116 | int error; |
Jean Delvare | 2530daa | 2011-12-10 22:53:36 +0100 | [diff] [blame] | 117 | unsigned int count = 0; |
Matthew Garrett | 942ed16 | 2008-08-26 21:09:59 +0100 | [diff] [blame] | 118 | |
Jean Delvare | 2530daa | 2011-12-10 22:53:36 +0100 | [diff] [blame] | 119 | error = class_for_each_device(power_supply_class, NULL, &count, |
Matthew Garrett | 942ed16 | 2008-08-26 21:09:59 +0100 | [diff] [blame] | 120 | __power_supply_is_system_supplied); |
| 121 | |
Jean Delvare | 2530daa | 2011-12-10 22:53:36 +0100 | [diff] [blame] | 122 | /* |
| 123 | * If no power class device was found at all, most probably we are |
| 124 | * running on a desktop system, so assume we are on mains power. |
| 125 | */ |
| 126 | if (count == 0) |
| 127 | return 1; |
| 128 | |
Matthew Garrett | 942ed16 | 2008-08-26 21:09:59 +0100 | [diff] [blame] | 129 | return error; |
| 130 | } |
Daniel Mack | ff3417e | 2009-07-30 17:42:31 +0400 | [diff] [blame] | 131 | EXPORT_SYMBOL_GPL(power_supply_is_system_supplied); |
Matthew Garrett | 942ed16 | 2008-08-26 21:09:59 +0100 | [diff] [blame] | 132 | |
Daniel Mack | e5f5ccb | 2009-07-23 20:35:53 +0200 | [diff] [blame] | 133 | int power_supply_set_battery_charged(struct power_supply *psy) |
| 134 | { |
| 135 | if (psy->type == POWER_SUPPLY_TYPE_BATTERY && psy->set_charged) { |
| 136 | psy->set_charged(psy); |
| 137 | return 0; |
| 138 | } |
| 139 | |
| 140 | return -EINVAL; |
| 141 | } |
| 142 | EXPORT_SYMBOL_GPL(power_supply_set_battery_charged); |
| 143 | |
Michał Mirosław | 9f3b795 | 2013-02-01 20:40:17 +0100 | [diff] [blame] | 144 | static int power_supply_match_device_by_name(struct device *dev, const void *data) |
Daniel Mack | e5f5ccb | 2009-07-23 20:35:53 +0200 | [diff] [blame] | 145 | { |
| 146 | const char *name = data; |
| 147 | struct power_supply *psy = dev_get_drvdata(dev); |
| 148 | |
| 149 | return strcmp(psy->name, name) == 0; |
| 150 | } |
| 151 | |
Michał Mirosław | 9f3b795 | 2013-02-01 20:40:17 +0100 | [diff] [blame] | 152 | struct power_supply *power_supply_get_by_name(const char *name) |
Daniel Mack | e5f5ccb | 2009-07-23 20:35:53 +0200 | [diff] [blame] | 153 | { |
| 154 | struct device *dev = class_find_device(power_supply_class, NULL, name, |
| 155 | power_supply_match_device_by_name); |
| 156 | |
| 157 | return dev ? dev_get_drvdata(dev) : NULL; |
| 158 | } |
| 159 | EXPORT_SYMBOL_GPL(power_supply_get_by_name); |
| 160 | |
Jeremy Fitzhardinge | 8351665 | 2011-12-07 09:15:45 -0800 | [diff] [blame] | 161 | int power_supply_powers(struct power_supply *psy, struct device *dev) |
| 162 | { |
Anton Vorontsov | 93278d1 | 2012-01-05 19:17:25 +0400 | [diff] [blame] | 163 | return sysfs_create_link(&psy->dev->kobj, &dev->kobj, "powers"); |
Jeremy Fitzhardinge | 8351665 | 2011-12-07 09:15:45 -0800 | [diff] [blame] | 164 | } |
| 165 | EXPORT_SYMBOL_GPL(power_supply_powers); |
| 166 | |
Anton Vorontsov | 5f487cd | 2010-05-18 21:49:51 +0200 | [diff] [blame] | 167 | static void power_supply_dev_release(struct device *dev) |
| 168 | { |
| 169 | pr_debug("device: '%s': %s\n", dev_name(dev), __func__); |
| 170 | kfree(dev); |
| 171 | } |
| 172 | |
Jenny TC | 3be330b | 2012-05-09 20:36:47 +0530 | [diff] [blame] | 173 | #ifdef CONFIG_THERMAL |
| 174 | static int power_supply_read_temp(struct thermal_zone_device *tzd, |
| 175 | unsigned long *temp) |
| 176 | { |
| 177 | struct power_supply *psy; |
| 178 | union power_supply_propval val; |
| 179 | int ret; |
| 180 | |
| 181 | WARN_ON(tzd == NULL); |
| 182 | psy = tzd->devdata; |
| 183 | ret = psy->get_property(psy, POWER_SUPPLY_PROP_TEMP, &val); |
| 184 | |
| 185 | /* Convert tenths of degree Celsius to milli degree Celsius. */ |
| 186 | if (!ret) |
| 187 | *temp = val.intval * 100; |
| 188 | |
| 189 | return ret; |
| 190 | } |
| 191 | |
| 192 | static struct thermal_zone_device_ops psy_tzd_ops = { |
| 193 | .get_temp = power_supply_read_temp, |
| 194 | }; |
| 195 | |
| 196 | static int psy_register_thermal(struct power_supply *psy) |
| 197 | { |
| 198 | int i; |
| 199 | |
| 200 | /* Register battery zone device psy reports temperature */ |
| 201 | for (i = 0; i < psy->num_properties; i++) { |
| 202 | if (psy->properties[i] == POWER_SUPPLY_PROP_TEMP) { |
Anton Vorontsov | e6db06a | 2012-07-31 04:59:42 -0700 | [diff] [blame] | 203 | psy->tzd = thermal_zone_device_register(psy->name, 0, 0, |
Durgadoss R | 50125a9 | 2012-09-18 11:04:56 +0530 | [diff] [blame] | 204 | psy, &psy_tzd_ops, NULL, 0, 0); |
Jenny TC | 3be330b | 2012-05-09 20:36:47 +0530 | [diff] [blame] | 205 | if (IS_ERR(psy->tzd)) |
| 206 | return PTR_ERR(psy->tzd); |
| 207 | break; |
| 208 | } |
| 209 | } |
| 210 | return 0; |
| 211 | } |
| 212 | |
| 213 | static void psy_unregister_thermal(struct power_supply *psy) |
| 214 | { |
| 215 | if (IS_ERR_OR_NULL(psy->tzd)) |
| 216 | return; |
| 217 | thermal_zone_device_unregister(psy->tzd); |
| 218 | } |
Ramakrishna Pallala | 952aeeb3 | 2012-10-09 22:25:59 +0530 | [diff] [blame] | 219 | |
| 220 | /* thermal cooling device callbacks */ |
| 221 | static int ps_get_max_charge_cntl_limit(struct thermal_cooling_device *tcd, |
| 222 | unsigned long *state) |
| 223 | { |
| 224 | struct power_supply *psy; |
| 225 | union power_supply_propval val; |
| 226 | int ret; |
| 227 | |
| 228 | psy = tcd->devdata; |
| 229 | ret = psy->get_property(psy, |
| 230 | POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX, &val); |
| 231 | if (!ret) |
| 232 | *state = val.intval; |
| 233 | |
| 234 | return ret; |
| 235 | } |
| 236 | |
| 237 | static int ps_get_cur_chrage_cntl_limit(struct thermal_cooling_device *tcd, |
| 238 | unsigned long *state) |
| 239 | { |
| 240 | struct power_supply *psy; |
| 241 | union power_supply_propval val; |
| 242 | int ret; |
| 243 | |
| 244 | psy = tcd->devdata; |
| 245 | ret = psy->get_property(psy, |
| 246 | POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT, &val); |
| 247 | if (!ret) |
| 248 | *state = val.intval; |
| 249 | |
| 250 | return ret; |
| 251 | } |
| 252 | |
| 253 | static int ps_set_cur_charge_cntl_limit(struct thermal_cooling_device *tcd, |
| 254 | unsigned long state) |
| 255 | { |
| 256 | struct power_supply *psy; |
| 257 | union power_supply_propval val; |
| 258 | int ret; |
| 259 | |
| 260 | psy = tcd->devdata; |
| 261 | val.intval = state; |
| 262 | ret = psy->set_property(psy, |
| 263 | POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT, &val); |
| 264 | |
| 265 | return ret; |
| 266 | } |
| 267 | |
| 268 | static struct thermal_cooling_device_ops psy_tcd_ops = { |
| 269 | .get_max_state = ps_get_max_charge_cntl_limit, |
| 270 | .get_cur_state = ps_get_cur_chrage_cntl_limit, |
| 271 | .set_cur_state = ps_set_cur_charge_cntl_limit, |
| 272 | }; |
| 273 | |
| 274 | static int psy_register_cooler(struct power_supply *psy) |
| 275 | { |
| 276 | int i; |
| 277 | |
| 278 | /* Register for cooling device if psy can control charging */ |
| 279 | for (i = 0; i < psy->num_properties; i++) { |
| 280 | if (psy->properties[i] == |
| 281 | POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT) { |
| 282 | psy->tcd = thermal_cooling_device_register( |
| 283 | (char *)psy->name, |
| 284 | psy, &psy_tcd_ops); |
| 285 | if (IS_ERR(psy->tcd)) |
| 286 | return PTR_ERR(psy->tcd); |
| 287 | break; |
| 288 | } |
| 289 | } |
| 290 | return 0; |
| 291 | } |
| 292 | |
| 293 | static void psy_unregister_cooler(struct power_supply *psy) |
| 294 | { |
| 295 | if (IS_ERR_OR_NULL(psy->tcd)) |
| 296 | return; |
| 297 | thermal_cooling_device_unregister(psy->tcd); |
| 298 | } |
Jenny TC | 3be330b | 2012-05-09 20:36:47 +0530 | [diff] [blame] | 299 | #else |
| 300 | static int psy_register_thermal(struct power_supply *psy) |
| 301 | { |
| 302 | return 0; |
| 303 | } |
| 304 | |
| 305 | static void psy_unregister_thermal(struct power_supply *psy) |
| 306 | { |
| 307 | } |
Ramakrishna Pallala | 952aeeb3 | 2012-10-09 22:25:59 +0530 | [diff] [blame] | 308 | |
| 309 | static int psy_register_cooler(struct power_supply *psy) |
| 310 | { |
| 311 | return 0; |
| 312 | } |
| 313 | |
| 314 | static void psy_unregister_cooler(struct power_supply *psy) |
| 315 | { |
| 316 | } |
Jenny TC | 3be330b | 2012-05-09 20:36:47 +0530 | [diff] [blame] | 317 | #endif |
| 318 | |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 319 | int power_supply_register(struct device *parent, struct power_supply *psy) |
| 320 | { |
Anton Vorontsov | 5f487cd | 2010-05-18 21:49:51 +0200 | [diff] [blame] | 321 | struct device *dev; |
| 322 | int rc; |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 323 | |
Anton Vorontsov | 5f487cd | 2010-05-18 21:49:51 +0200 | [diff] [blame] | 324 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
| 325 | if (!dev) |
| 326 | return -ENOMEM; |
| 327 | |
| 328 | device_initialize(dev); |
| 329 | |
| 330 | dev->class = power_supply_class; |
| 331 | dev->type = &power_supply_dev_type; |
| 332 | dev->parent = parent; |
| 333 | dev->release = power_supply_dev_release; |
| 334 | dev_set_drvdata(dev, psy); |
| 335 | psy->dev = dev; |
| 336 | |
Lars-Peter Clausen | 9777467 | 2011-02-21 15:34:19 +0100 | [diff] [blame] | 337 | INIT_WORK(&psy->changed_work, power_supply_changed_work); |
| 338 | |
Anton Vorontsov | 5f487cd | 2010-05-18 21:49:51 +0200 | [diff] [blame] | 339 | rc = kobject_set_name(&dev->kobj, "%s", psy->name); |
| 340 | if (rc) |
| 341 | goto kobject_set_name_failed; |
| 342 | |
| 343 | rc = device_add(dev); |
| 344 | if (rc) |
| 345 | goto device_add_failed; |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 346 | |
Jenny TC | 3be330b | 2012-05-09 20:36:47 +0530 | [diff] [blame] | 347 | rc = psy_register_thermal(psy); |
| 348 | if (rc) |
| 349 | goto register_thermal_failed; |
| 350 | |
Ramakrishna Pallala | 952aeeb3 | 2012-10-09 22:25:59 +0530 | [diff] [blame] | 351 | rc = psy_register_cooler(psy); |
| 352 | if (rc) |
| 353 | goto register_cooler_failed; |
| 354 | |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 355 | rc = power_supply_create_triggers(psy); |
| 356 | if (rc) |
| 357 | goto create_triggers_failed; |
| 358 | |
| 359 | power_supply_changed(psy); |
| 360 | |
| 361 | goto success; |
| 362 | |
| 363 | create_triggers_failed: |
Ramakrishna Pallala | 952aeeb3 | 2012-10-09 22:25:59 +0530 | [diff] [blame] | 364 | psy_unregister_cooler(psy); |
| 365 | register_cooler_failed: |
Jenny TC | 3be330b | 2012-05-09 20:36:47 +0530 | [diff] [blame] | 366 | psy_unregister_thermal(psy); |
| 367 | register_thermal_failed: |
Vasiliy Kulikov | 3a2dbd6 | 2010-11-19 21:41:58 +0300 | [diff] [blame] | 368 | device_del(dev); |
Anton Vorontsov | 5f487cd | 2010-05-18 21:49:51 +0200 | [diff] [blame] | 369 | kobject_set_name_failed: |
| 370 | device_add_failed: |
Vasiliy Kulikov | 3a2dbd6 | 2010-11-19 21:41:58 +0300 | [diff] [blame] | 371 | put_device(dev); |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 372 | success: |
| 373 | return rc; |
| 374 | } |
Daniel Mack | ff3417e | 2009-07-30 17:42:31 +0400 | [diff] [blame] | 375 | EXPORT_SYMBOL_GPL(power_supply_register); |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 376 | |
| 377 | void power_supply_unregister(struct power_supply *psy) |
| 378 | { |
Tejun Heo | bc51e7f | 2010-12-11 17:51:45 +0100 | [diff] [blame] | 379 | cancel_work_sync(&psy->changed_work); |
Jeremy Fitzhardinge | 8351665 | 2011-12-07 09:15:45 -0800 | [diff] [blame] | 380 | sysfs_remove_link(&psy->dev->kobj, "powers"); |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 381 | power_supply_remove_triggers(psy); |
Ramakrishna Pallala | 952aeeb3 | 2012-10-09 22:25:59 +0530 | [diff] [blame] | 382 | psy_unregister_cooler(psy); |
Jenny TC | 3be330b | 2012-05-09 20:36:47 +0530 | [diff] [blame] | 383 | psy_unregister_thermal(psy); |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 384 | device_unregister(psy->dev); |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 385 | } |
Daniel Mack | ff3417e | 2009-07-30 17:42:31 +0400 | [diff] [blame] | 386 | EXPORT_SYMBOL_GPL(power_supply_unregister); |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 387 | |
| 388 | static int __init power_supply_class_init(void) |
| 389 | { |
| 390 | power_supply_class = class_create(THIS_MODULE, "power_supply"); |
| 391 | |
| 392 | if (IS_ERR(power_supply_class)) |
| 393 | return PTR_ERR(power_supply_class); |
| 394 | |
| 395 | power_supply_class->dev_uevent = power_supply_uevent; |
Anton Vorontsov | 5f487cd | 2010-05-18 21:49:51 +0200 | [diff] [blame] | 396 | power_supply_init_attrs(&power_supply_dev_type); |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 397 | |
| 398 | return 0; |
| 399 | } |
| 400 | |
| 401 | static void __exit power_supply_class_exit(void) |
| 402 | { |
| 403 | class_destroy(power_supply_class); |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 404 | } |
| 405 | |
Anton Vorontsov | 4a11b59 | 2007-05-04 00:27:45 +0400 | [diff] [blame] | 406 | subsys_initcall(power_supply_class_init); |
| 407 | module_exit(power_supply_class_exit); |
| 408 | |
| 409 | MODULE_DESCRIPTION("Universal power supply monitor class"); |
| 410 | MODULE_AUTHOR("Ian Molton <spyro@f2s.com>, " |
| 411 | "Szabolcs Gyurko, " |
| 412 | "Anton Vorontsov <cbou@mail.ru>"); |
| 413 | MODULE_LICENSE("GPL"); |