0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef __LINUX_POWER_SUPPLY_H__
0013 #define __LINUX_POWER_SUPPLY_H__
0014
0015 #include <linux/device.h>
0016 #include <linux/workqueue.h>
0017 #include <linux/leds.h>
0018 #include <linux/spinlock.h>
0019 #include <linux/notifier.h>
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 enum {
0035 POWER_SUPPLY_STATUS_UNKNOWN = 0,
0036 POWER_SUPPLY_STATUS_CHARGING,
0037 POWER_SUPPLY_STATUS_DISCHARGING,
0038 POWER_SUPPLY_STATUS_NOT_CHARGING,
0039 POWER_SUPPLY_STATUS_FULL,
0040 };
0041
0042
0043 enum {
0044 POWER_SUPPLY_CHARGE_TYPE_UNKNOWN = 0,
0045 POWER_SUPPLY_CHARGE_TYPE_NONE,
0046 POWER_SUPPLY_CHARGE_TYPE_TRICKLE,
0047 POWER_SUPPLY_CHARGE_TYPE_FAST,
0048 POWER_SUPPLY_CHARGE_TYPE_STANDARD,
0049 POWER_SUPPLY_CHARGE_TYPE_ADAPTIVE,
0050 POWER_SUPPLY_CHARGE_TYPE_CUSTOM,
0051 POWER_SUPPLY_CHARGE_TYPE_LONGLIFE,
0052 POWER_SUPPLY_CHARGE_TYPE_BYPASS,
0053 };
0054
0055 enum {
0056 POWER_SUPPLY_HEALTH_UNKNOWN = 0,
0057 POWER_SUPPLY_HEALTH_GOOD,
0058 POWER_SUPPLY_HEALTH_OVERHEAT,
0059 POWER_SUPPLY_HEALTH_DEAD,
0060 POWER_SUPPLY_HEALTH_OVERVOLTAGE,
0061 POWER_SUPPLY_HEALTH_UNSPEC_FAILURE,
0062 POWER_SUPPLY_HEALTH_COLD,
0063 POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE,
0064 POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE,
0065 POWER_SUPPLY_HEALTH_OVERCURRENT,
0066 POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED,
0067 POWER_SUPPLY_HEALTH_WARM,
0068 POWER_SUPPLY_HEALTH_COOL,
0069 POWER_SUPPLY_HEALTH_HOT,
0070 POWER_SUPPLY_HEALTH_NO_BATTERY,
0071 };
0072
0073 enum {
0074 POWER_SUPPLY_TECHNOLOGY_UNKNOWN = 0,
0075 POWER_SUPPLY_TECHNOLOGY_NiMH,
0076 POWER_SUPPLY_TECHNOLOGY_LION,
0077 POWER_SUPPLY_TECHNOLOGY_LIPO,
0078 POWER_SUPPLY_TECHNOLOGY_LiFe,
0079 POWER_SUPPLY_TECHNOLOGY_NiCd,
0080 POWER_SUPPLY_TECHNOLOGY_LiMn,
0081 };
0082
0083 enum {
0084 POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN = 0,
0085 POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL,
0086 POWER_SUPPLY_CAPACITY_LEVEL_LOW,
0087 POWER_SUPPLY_CAPACITY_LEVEL_NORMAL,
0088 POWER_SUPPLY_CAPACITY_LEVEL_HIGH,
0089 POWER_SUPPLY_CAPACITY_LEVEL_FULL,
0090 };
0091
0092 enum {
0093 POWER_SUPPLY_SCOPE_UNKNOWN = 0,
0094 POWER_SUPPLY_SCOPE_SYSTEM,
0095 POWER_SUPPLY_SCOPE_DEVICE,
0096 };
0097
0098 enum power_supply_property {
0099
0100 POWER_SUPPLY_PROP_STATUS = 0,
0101 POWER_SUPPLY_PROP_CHARGE_TYPE,
0102 POWER_SUPPLY_PROP_HEALTH,
0103 POWER_SUPPLY_PROP_PRESENT,
0104 POWER_SUPPLY_PROP_ONLINE,
0105 POWER_SUPPLY_PROP_AUTHENTIC,
0106 POWER_SUPPLY_PROP_TECHNOLOGY,
0107 POWER_SUPPLY_PROP_CYCLE_COUNT,
0108 POWER_SUPPLY_PROP_VOLTAGE_MAX,
0109 POWER_SUPPLY_PROP_VOLTAGE_MIN,
0110 POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
0111 POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
0112 POWER_SUPPLY_PROP_VOLTAGE_NOW,
0113 POWER_SUPPLY_PROP_VOLTAGE_AVG,
0114 POWER_SUPPLY_PROP_VOLTAGE_OCV,
0115 POWER_SUPPLY_PROP_VOLTAGE_BOOT,
0116 POWER_SUPPLY_PROP_CURRENT_MAX,
0117 POWER_SUPPLY_PROP_CURRENT_NOW,
0118 POWER_SUPPLY_PROP_CURRENT_AVG,
0119 POWER_SUPPLY_PROP_CURRENT_BOOT,
0120 POWER_SUPPLY_PROP_POWER_NOW,
0121 POWER_SUPPLY_PROP_POWER_AVG,
0122 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
0123 POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN,
0124 POWER_SUPPLY_PROP_CHARGE_FULL,
0125 POWER_SUPPLY_PROP_CHARGE_EMPTY,
0126 POWER_SUPPLY_PROP_CHARGE_NOW,
0127 POWER_SUPPLY_PROP_CHARGE_AVG,
0128 POWER_SUPPLY_PROP_CHARGE_COUNTER,
0129 POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT,
0130 POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX,
0131 POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE,
0132 POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
0133 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT,
0134 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX,
0135 POWER_SUPPLY_PROP_CHARGE_CONTROL_START_THRESHOLD,
0136 POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD,
0137 POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR,
0138 POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
0139 POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT,
0140 POWER_SUPPLY_PROP_INPUT_POWER_LIMIT,
0141 POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
0142 POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN,
0143 POWER_SUPPLY_PROP_ENERGY_FULL,
0144 POWER_SUPPLY_PROP_ENERGY_EMPTY,
0145 POWER_SUPPLY_PROP_ENERGY_NOW,
0146 POWER_SUPPLY_PROP_ENERGY_AVG,
0147 POWER_SUPPLY_PROP_CAPACITY,
0148 POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN,
0149 POWER_SUPPLY_PROP_CAPACITY_ALERT_MAX,
0150 POWER_SUPPLY_PROP_CAPACITY_ERROR_MARGIN,
0151 POWER_SUPPLY_PROP_CAPACITY_LEVEL,
0152 POWER_SUPPLY_PROP_TEMP,
0153 POWER_SUPPLY_PROP_TEMP_MAX,
0154 POWER_SUPPLY_PROP_TEMP_MIN,
0155 POWER_SUPPLY_PROP_TEMP_ALERT_MIN,
0156 POWER_SUPPLY_PROP_TEMP_ALERT_MAX,
0157 POWER_SUPPLY_PROP_TEMP_AMBIENT,
0158 POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MIN,
0159 POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MAX,
0160 POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
0161 POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG,
0162 POWER_SUPPLY_PROP_TIME_TO_FULL_NOW,
0163 POWER_SUPPLY_PROP_TIME_TO_FULL_AVG,
0164 POWER_SUPPLY_PROP_TYPE,
0165 POWER_SUPPLY_PROP_USB_TYPE,
0166 POWER_SUPPLY_PROP_SCOPE,
0167 POWER_SUPPLY_PROP_PRECHARGE_CURRENT,
0168 POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
0169 POWER_SUPPLY_PROP_CALIBRATE,
0170 POWER_SUPPLY_PROP_MANUFACTURE_YEAR,
0171 POWER_SUPPLY_PROP_MANUFACTURE_MONTH,
0172 POWER_SUPPLY_PROP_MANUFACTURE_DAY,
0173
0174 POWER_SUPPLY_PROP_MODEL_NAME,
0175 POWER_SUPPLY_PROP_MANUFACTURER,
0176 POWER_SUPPLY_PROP_SERIAL_NUMBER,
0177 };
0178
0179 enum power_supply_type {
0180 POWER_SUPPLY_TYPE_UNKNOWN = 0,
0181 POWER_SUPPLY_TYPE_BATTERY,
0182 POWER_SUPPLY_TYPE_UPS,
0183 POWER_SUPPLY_TYPE_MAINS,
0184 POWER_SUPPLY_TYPE_USB,
0185 POWER_SUPPLY_TYPE_USB_DCP,
0186 POWER_SUPPLY_TYPE_USB_CDP,
0187 POWER_SUPPLY_TYPE_USB_ACA,
0188 POWER_SUPPLY_TYPE_USB_TYPE_C,
0189 POWER_SUPPLY_TYPE_USB_PD,
0190 POWER_SUPPLY_TYPE_USB_PD_DRP,
0191 POWER_SUPPLY_TYPE_APPLE_BRICK_ID,
0192 POWER_SUPPLY_TYPE_WIRELESS,
0193 };
0194
0195 enum power_supply_usb_type {
0196 POWER_SUPPLY_USB_TYPE_UNKNOWN = 0,
0197 POWER_SUPPLY_USB_TYPE_SDP,
0198 POWER_SUPPLY_USB_TYPE_DCP,
0199 POWER_SUPPLY_USB_TYPE_CDP,
0200 POWER_SUPPLY_USB_TYPE_ACA,
0201 POWER_SUPPLY_USB_TYPE_C,
0202 POWER_SUPPLY_USB_TYPE_PD,
0203 POWER_SUPPLY_USB_TYPE_PD_DRP,
0204 POWER_SUPPLY_USB_TYPE_PD_PPS,
0205 POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID,
0206 };
0207
0208 enum power_supply_charge_behaviour {
0209 POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO = 0,
0210 POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE,
0211 POWER_SUPPLY_CHARGE_BEHAVIOUR_FORCE_DISCHARGE,
0212 };
0213
0214 enum power_supply_notifier_events {
0215 PSY_EVENT_PROP_CHANGED,
0216 };
0217
0218 union power_supply_propval {
0219 int intval;
0220 const char *strval;
0221 };
0222
0223 struct device_node;
0224 struct power_supply;
0225
0226
0227 struct power_supply_config {
0228 struct device_node *of_node;
0229 struct fwnode_handle *fwnode;
0230
0231
0232 void *drv_data;
0233
0234
0235 const struct attribute_group **attr_grp;
0236
0237 char **supplied_to;
0238 size_t num_supplicants;
0239 };
0240
0241
0242 struct power_supply_desc {
0243 const char *name;
0244 enum power_supply_type type;
0245 const enum power_supply_usb_type *usb_types;
0246 size_t num_usb_types;
0247 const enum power_supply_property *properties;
0248 size_t num_properties;
0249
0250
0251
0252
0253
0254
0255
0256 int (*get_property)(struct power_supply *psy,
0257 enum power_supply_property psp,
0258 union power_supply_propval *val);
0259 int (*set_property)(struct power_supply *psy,
0260 enum power_supply_property psp,
0261 const union power_supply_propval *val);
0262
0263
0264
0265
0266
0267 int (*property_is_writeable)(struct power_supply *psy,
0268 enum power_supply_property psp);
0269 void (*external_power_changed)(struct power_supply *psy);
0270 void (*set_charged)(struct power_supply *psy);
0271
0272
0273
0274
0275
0276
0277 bool no_thermal;
0278
0279 int use_for_apm;
0280 };
0281
0282 struct power_supply {
0283 const struct power_supply_desc *desc;
0284
0285 char **supplied_to;
0286 size_t num_supplicants;
0287
0288 char **supplied_from;
0289 size_t num_supplies;
0290 struct device_node *of_node;
0291
0292
0293 void *drv_data;
0294
0295
0296 struct device dev;
0297 struct work_struct changed_work;
0298 struct delayed_work deferred_register_work;
0299 spinlock_t changed_lock;
0300 bool changed;
0301 bool initialized;
0302 bool removing;
0303 atomic_t use_cnt;
0304 #ifdef CONFIG_THERMAL
0305 struct thermal_zone_device *tzd;
0306 struct thermal_cooling_device *tcd;
0307 #endif
0308
0309 #ifdef CONFIG_LEDS_TRIGGERS
0310 struct led_trigger *charging_full_trig;
0311 char *charging_full_trig_name;
0312 struct led_trigger *charging_trig;
0313 char *charging_trig_name;
0314 struct led_trigger *full_trig;
0315 char *full_trig_name;
0316 struct led_trigger *online_trig;
0317 char *online_trig_name;
0318 struct led_trigger *charging_blink_full_solid_trig;
0319 char *charging_blink_full_solid_trig_name;
0320 #endif
0321 };
0322
0323
0324
0325
0326
0327
0328
0329
0330 struct power_supply_info {
0331 const char *name;
0332 int technology;
0333 int voltage_max_design;
0334 int voltage_min_design;
0335 int charge_full_design;
0336 int charge_empty_design;
0337 int energy_full_design;
0338 int energy_empty_design;
0339 int use_for_apm;
0340 };
0341
0342 struct power_supply_battery_ocv_table {
0343 int ocv;
0344 int capacity;
0345 };
0346
0347 struct power_supply_resistance_temp_table {
0348 int temp;
0349 int resistance;
0350 };
0351
0352 struct power_supply_vbat_ri_table {
0353 int vbat_uv;
0354 int ri_uohm;
0355 };
0356
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378
0379
0380
0381
0382
0383
0384
0385
0386
0387
0388
0389
0390
0391
0392
0393
0394
0395
0396
0397 struct power_supply_maintenance_charge_table {
0398 int charge_current_max_ua;
0399 int charge_voltage_max_uv;
0400 int charge_safety_timer_minutes;
0401 };
0402
0403 #define POWER_SUPPLY_OCV_TEMP_MAX 20
0404
0405
0406
0407
0408
0409
0410
0411
0412
0413
0414
0415
0416
0417
0418
0419
0420
0421
0422
0423
0424
0425
0426
0427
0428
0429
0430
0431
0432
0433
0434
0435
0436
0437
0438
0439
0440
0441
0442
0443
0444
0445
0446
0447
0448
0449
0450
0451
0452
0453
0454
0455
0456
0457
0458
0459
0460
0461
0462
0463
0464
0465
0466
0467
0468
0469
0470
0471
0472
0473
0474
0475
0476
0477
0478
0479
0480
0481
0482
0483
0484
0485
0486
0487
0488
0489
0490
0491
0492
0493
0494
0495
0496
0497
0498
0499
0500
0501
0502
0503
0504
0505
0506
0507
0508
0509
0510
0511
0512
0513
0514
0515
0516
0517
0518
0519
0520
0521
0522
0523
0524
0525
0526
0527
0528
0529
0530
0531
0532
0533
0534
0535
0536
0537
0538
0539
0540
0541
0542
0543
0544
0545
0546
0547
0548
0549
0550
0551
0552
0553
0554
0555
0556
0557
0558
0559
0560
0561
0562
0563
0564
0565
0566
0567
0568
0569
0570
0571
0572
0573
0574
0575
0576
0577
0578
0579
0580
0581
0582
0583
0584
0585
0586
0587
0588
0589
0590
0591
0592
0593
0594
0595
0596
0597
0598
0599
0600
0601
0602
0603
0604
0605
0606
0607
0608
0609
0610
0611
0612
0613
0614
0615
0616
0617
0618
0619
0620
0621
0622
0623
0624
0625
0626
0627
0628
0629
0630
0631
0632
0633
0634
0635
0636
0637
0638
0639
0640
0641
0642
0643
0644
0645
0646
0647
0648
0649
0650
0651
0652
0653
0654
0655
0656
0657
0658
0659
0660
0661
0662
0663
0664
0665
0666
0667
0668
0669
0670
0671
0672
0673
0674
0675
0676
0677
0678
0679
0680
0681
0682
0683
0684
0685
0686
0687
0688
0689
0690
0691
0692 struct power_supply_battery_info {
0693 unsigned int technology;
0694 int energy_full_design_uwh;
0695 int charge_full_design_uah;
0696 int voltage_min_design_uv;
0697 int voltage_max_design_uv;
0698 int tricklecharge_current_ua;
0699 int precharge_current_ua;
0700 int precharge_voltage_max_uv;
0701 int charge_term_current_ua;
0702 int charge_restart_voltage_uv;
0703 int overvoltage_limit_uv;
0704 int constant_charge_current_max_ua;
0705 int constant_charge_voltage_max_uv;
0706 struct power_supply_maintenance_charge_table *maintenance_charge;
0707 int maintenance_charge_size;
0708 int alert_low_temp_charge_current_ua;
0709 int alert_low_temp_charge_voltage_uv;
0710 int alert_high_temp_charge_current_ua;
0711 int alert_high_temp_charge_voltage_uv;
0712 int factory_internal_resistance_uohm;
0713 int factory_internal_resistance_charging_uohm;
0714 int ocv_temp[POWER_SUPPLY_OCV_TEMP_MAX];
0715 int temp_ambient_alert_min;
0716 int temp_ambient_alert_max;
0717 int temp_alert_min;
0718 int temp_alert_max;
0719 int temp_min;
0720 int temp_max;
0721 struct power_supply_battery_ocv_table *ocv_table[POWER_SUPPLY_OCV_TEMP_MAX];
0722 int ocv_table_size[POWER_SUPPLY_OCV_TEMP_MAX];
0723 struct power_supply_resistance_temp_table *resist_table;
0724 int resist_table_size;
0725 struct power_supply_vbat_ri_table *vbat2ri_discharging;
0726 int vbat2ri_discharging_size;
0727 struct power_supply_vbat_ri_table *vbat2ri_charging;
0728 int vbat2ri_charging_size;
0729 int bti_resistance_ohm;
0730 int bti_resistance_tolerance;
0731 };
0732
0733 extern struct atomic_notifier_head power_supply_notifier;
0734 extern int power_supply_reg_notifier(struct notifier_block *nb);
0735 extern void power_supply_unreg_notifier(struct notifier_block *nb);
0736 #if IS_ENABLED(CONFIG_POWER_SUPPLY)
0737 extern struct power_supply *power_supply_get_by_name(const char *name);
0738 extern void power_supply_put(struct power_supply *psy);
0739 #else
0740 static inline void power_supply_put(struct power_supply *psy) {}
0741 static inline struct power_supply *power_supply_get_by_name(const char *name)
0742 { return NULL; }
0743 #endif
0744 #ifdef CONFIG_OF
0745 extern struct power_supply *power_supply_get_by_phandle(struct device_node *np,
0746 const char *property);
0747 extern struct power_supply *devm_power_supply_get_by_phandle(
0748 struct device *dev, const char *property);
0749 #else
0750 static inline struct power_supply *
0751 power_supply_get_by_phandle(struct device_node *np, const char *property)
0752 { return NULL; }
0753 static inline struct power_supply *
0754 devm_power_supply_get_by_phandle(struct device *dev, const char *property)
0755 { return NULL; }
0756 #endif
0757
0758 extern int power_supply_get_battery_info(struct power_supply *psy,
0759 struct power_supply_battery_info **info_out);
0760 extern void power_supply_put_battery_info(struct power_supply *psy,
0761 struct power_supply_battery_info *info);
0762 extern int power_supply_ocv2cap_simple(struct power_supply_battery_ocv_table *table,
0763 int table_len, int ocv);
0764 extern struct power_supply_battery_ocv_table *
0765 power_supply_find_ocv2cap_table(struct power_supply_battery_info *info,
0766 int temp, int *table_len);
0767 extern int power_supply_batinfo_ocv2cap(struct power_supply_battery_info *info,
0768 int ocv, int temp);
0769 extern int
0770 power_supply_temp2resist_simple(struct power_supply_resistance_temp_table *table,
0771 int table_len, int temp);
0772 extern int power_supply_vbat2ri(struct power_supply_battery_info *info,
0773 int vbat_uv, bool charging);
0774 extern struct power_supply_maintenance_charge_table *
0775 power_supply_get_maintenance_charging_setting(struct power_supply_battery_info *info, int index);
0776 extern bool power_supply_battery_bti_in_range(struct power_supply_battery_info *info,
0777 int resistance);
0778 extern void power_supply_changed(struct power_supply *psy);
0779 extern int power_supply_am_i_supplied(struct power_supply *psy);
0780 int power_supply_get_property_from_supplier(struct power_supply *psy,
0781 enum power_supply_property psp,
0782 union power_supply_propval *val);
0783 extern int power_supply_set_battery_charged(struct power_supply *psy);
0784
0785 static inline bool
0786 power_supply_supports_maintenance_charging(struct power_supply_battery_info *info)
0787 {
0788 struct power_supply_maintenance_charge_table *mt;
0789
0790 mt = power_supply_get_maintenance_charging_setting(info, 0);
0791
0792 return (mt != NULL);
0793 }
0794
0795 static inline bool
0796 power_supply_supports_vbat2ri(struct power_supply_battery_info *info)
0797 {
0798 return ((info->vbat2ri_discharging != NULL) &&
0799 info->vbat2ri_discharging_size > 0);
0800 }
0801
0802 static inline bool
0803 power_supply_supports_temp2ri(struct power_supply_battery_info *info)
0804 {
0805 return ((info->resist_table != NULL) &&
0806 info->resist_table_size > 0);
0807 }
0808
0809 #ifdef CONFIG_POWER_SUPPLY
0810 extern int power_supply_is_system_supplied(void);
0811 #else
0812 static inline int power_supply_is_system_supplied(void) { return -ENOSYS; }
0813 #endif
0814
0815 extern int power_supply_get_property(struct power_supply *psy,
0816 enum power_supply_property psp,
0817 union power_supply_propval *val);
0818 #if IS_ENABLED(CONFIG_POWER_SUPPLY)
0819 extern int power_supply_set_property(struct power_supply *psy,
0820 enum power_supply_property psp,
0821 const union power_supply_propval *val);
0822 #else
0823 static inline int power_supply_set_property(struct power_supply *psy,
0824 enum power_supply_property psp,
0825 const union power_supply_propval *val)
0826 { return 0; }
0827 #endif
0828 extern int power_supply_property_is_writeable(struct power_supply *psy,
0829 enum power_supply_property psp);
0830 extern void power_supply_external_power_changed(struct power_supply *psy);
0831
0832 extern struct power_supply *__must_check
0833 power_supply_register(struct device *parent,
0834 const struct power_supply_desc *desc,
0835 const struct power_supply_config *cfg);
0836 extern struct power_supply *__must_check
0837 power_supply_register_no_ws(struct device *parent,
0838 const struct power_supply_desc *desc,
0839 const struct power_supply_config *cfg);
0840 extern struct power_supply *__must_check
0841 devm_power_supply_register(struct device *parent,
0842 const struct power_supply_desc *desc,
0843 const struct power_supply_config *cfg);
0844 extern struct power_supply *__must_check
0845 devm_power_supply_register_no_ws(struct device *parent,
0846 const struct power_supply_desc *desc,
0847 const struct power_supply_config *cfg);
0848 extern void power_supply_unregister(struct power_supply *psy);
0849 extern int power_supply_powers(struct power_supply *psy, struct device *dev);
0850
0851 #define to_power_supply(device) container_of(device, struct power_supply, dev)
0852
0853 extern void *power_supply_get_drvdata(struct power_supply *psy);
0854
0855 extern struct class *power_supply_class;
0856
0857 static inline bool power_supply_is_amp_property(enum power_supply_property psp)
0858 {
0859 switch (psp) {
0860 case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
0861 case POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN:
0862 case POWER_SUPPLY_PROP_CHARGE_FULL:
0863 case POWER_SUPPLY_PROP_CHARGE_EMPTY:
0864 case POWER_SUPPLY_PROP_CHARGE_NOW:
0865 case POWER_SUPPLY_PROP_CHARGE_AVG:
0866 case POWER_SUPPLY_PROP_CHARGE_COUNTER:
0867 case POWER_SUPPLY_PROP_PRECHARGE_CURRENT:
0868 case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
0869 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
0870 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
0871 case POWER_SUPPLY_PROP_CURRENT_MAX:
0872 case POWER_SUPPLY_PROP_CURRENT_NOW:
0873 case POWER_SUPPLY_PROP_CURRENT_AVG:
0874 case POWER_SUPPLY_PROP_CURRENT_BOOT:
0875 return true;
0876 default:
0877 break;
0878 }
0879
0880 return false;
0881 }
0882
0883 static inline bool power_supply_is_watt_property(enum power_supply_property psp)
0884 {
0885 switch (psp) {
0886 case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN:
0887 case POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN:
0888 case POWER_SUPPLY_PROP_ENERGY_FULL:
0889 case POWER_SUPPLY_PROP_ENERGY_EMPTY:
0890 case POWER_SUPPLY_PROP_ENERGY_NOW:
0891 case POWER_SUPPLY_PROP_ENERGY_AVG:
0892 case POWER_SUPPLY_PROP_VOLTAGE_MAX:
0893 case POWER_SUPPLY_PROP_VOLTAGE_MIN:
0894 case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
0895 case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
0896 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
0897 case POWER_SUPPLY_PROP_VOLTAGE_AVG:
0898 case POWER_SUPPLY_PROP_VOLTAGE_OCV:
0899 case POWER_SUPPLY_PROP_VOLTAGE_BOOT:
0900 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:
0901 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX:
0902 case POWER_SUPPLY_PROP_POWER_NOW:
0903 return true;
0904 default:
0905 break;
0906 }
0907
0908 return false;
0909 }
0910
0911 #ifdef CONFIG_POWER_SUPPLY_HWMON
0912 int power_supply_add_hwmon_sysfs(struct power_supply *psy);
0913 void power_supply_remove_hwmon_sysfs(struct power_supply *psy);
0914 #else
0915 static inline int power_supply_add_hwmon_sysfs(struct power_supply *psy)
0916 {
0917 return 0;
0918 }
0919
0920 static inline
0921 void power_supply_remove_hwmon_sysfs(struct power_supply *psy) {}
0922 #endif
0923
0924 #ifdef CONFIG_SYSFS
0925 ssize_t power_supply_charge_behaviour_show(struct device *dev,
0926 unsigned int available_behaviours,
0927 enum power_supply_charge_behaviour behaviour,
0928 char *buf);
0929
0930 int power_supply_charge_behaviour_parse(unsigned int available_behaviours, const char *buf);
0931 #else
0932 static inline
0933 ssize_t power_supply_charge_behaviour_show(struct device *dev,
0934 unsigned int available_behaviours,
0935 enum power_supply_charge_behaviour behaviour,
0936 char *buf)
0937 {
0938 return -EOPNOTSUPP;
0939 }
0940
0941 static inline int power_supply_charge_behaviour_parse(unsigned int available_behaviours,
0942 const char *buf)
0943 {
0944 return -EOPNOTSUPP;
0945 }
0946 #endif
0947
0948 #endif