Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
power_supply.h
Go to the documentation of this file.
1 /*
2  * Universal power supply monitor class
3  *
4  * Copyright © 2007 Anton Vorontsov <[email protected]>
5  * Copyright © 2004 Szabolcs Gyurko
6  * Copyright © 2003 Ian Molton <[email protected]>
7  *
8  * Modified: 2004, Oct Szabolcs Gyurko
9  *
10  * You may use this code as per GPL version 2
11  */
12 
13 #ifndef __LINUX_POWER_SUPPLY_H__
14 #define __LINUX_POWER_SUPPLY_H__
15 
16 #include <linux/workqueue.h>
17 #include <linux/leds.h>
18 
19 struct device;
20 
21 /*
22  * All voltages, currents, charges, energies, time and temperatures in uV,
23  * µA, µAh, µWh, seconds and tenths of degree Celsius unless otherwise
24  * stated. It's driver's job to convert its raw values to units in which
25  * this class operates.
26  */
27 
28 /*
29  * For systems where the charger determines the maximum battery capacity
30  * the min and max fields should be used to present these values to user
31  * space. Unused/unknown fields will not appear in sysfs.
32  */
33 
34 enum {
40 };
41 
42 enum {
47 };
48 
49 enum {
57 };
58 
59 enum {
67 };
68 
69 enum {
76 };
77 
78 enum {
82 };
83 
85  /* Properties of type `int' */
123  POWER_SUPPLY_PROP_CAPACITY, /* in percents! */
137  POWER_SUPPLY_PROP_TYPE, /* use power_supply.type instead */
139  /* Properties of type `const char *' */
143 };
144 
150  POWER_SUPPLY_TYPE_USB, /* Standard Downstream Port */
151  POWER_SUPPLY_TYPE_USB_DCP, /* Dedicated Charging Port */
152  POWER_SUPPLY_TYPE_USB_CDP, /* Charging Downstream Port */
153  POWER_SUPPLY_TYPE_USB_ACA, /* Accessory Charger Adapters */
154 };
155 
157  int intval;
158  const char *strval;
159 };
160 
161 struct power_supply {
162  const char *name;
166 
167  char **supplied_to;
169 
170  int (*get_property)(struct power_supply *psy,
171  enum power_supply_property psp,
172  union power_supply_propval *val);
173  int (*set_property)(struct power_supply *psy,
174  enum power_supply_property psp,
175  const union power_supply_propval *val);
177  enum power_supply_property psp);
179  void (*set_charged)(struct power_supply *psy);
180 
181  /* For APM emulation, think legacy userspace. */
183 
184  /* private */
185  struct device *dev;
187 #ifdef CONFIG_THERMAL
188  struct thermal_zone_device *tzd;
189 #endif
190 
191 #ifdef CONFIG_LEDS_TRIGGERS
192  struct led_trigger *charging_full_trig;
193  char *charging_full_trig_name;
194  struct led_trigger *charging_trig;
195  char *charging_trig_name;
196  struct led_trigger *full_trig;
197  char *full_trig_name;
198  struct led_trigger *online_trig;
199  char *online_trig_name;
200  struct led_trigger *charging_blink_full_solid_trig;
201  char *charging_blink_full_solid_trig_name;
202 #endif
203 };
204 
205 /*
206  * This is recommended structure to specify static power supply parameters.
207  * Generic one, parametrizable for different power supplies. Power supply
208  * class itself does not use it, but that's what implementing most platform
209  * drivers, should try reuse for consistency.
210  */
211 
213  const char *name;
222 };
223 
224 extern struct power_supply *power_supply_get_by_name(char *name);
225 extern void power_supply_changed(struct power_supply *psy);
226 extern int power_supply_am_i_supplied(struct power_supply *psy);
227 extern int power_supply_set_battery_charged(struct power_supply *psy);
228 
229 #ifdef CONFIG_POWER_SUPPLY
230 extern int power_supply_is_system_supplied(void);
231 #else
232 static inline int power_supply_is_system_supplied(void) { return -ENOSYS; }
233 #endif
234 
235 extern int power_supply_register(struct device *parent,
236  struct power_supply *psy);
237 extern void power_supply_unregister(struct power_supply *psy);
238 extern int power_supply_powers(struct power_supply *psy, struct device *dev);
239 
240 /* For APM emulation, think legacy userspace. */
241 extern struct class *power_supply_class;
242 
243 static inline bool power_supply_is_amp_property(enum power_supply_property psp)
244 {
245  switch (psp) {
258  return 1;
259  default:
260  break;
261  }
262 
263  return 0;
264 }
265 
266 static inline bool power_supply_is_watt_property(enum power_supply_property psp)
267 {
268  switch (psp) {
285  return 1;
286  default:
287  break;
288  }
289 
290  return 0;
291 }
292 
293 #endif /* __LINUX_POWER_SUPPLY_H__ */