1 // SPDX-License-Identifier: GPL-2.0-only
3 * Universal power supply monitor class
5 * Copyright © 2007 Anton Vorontsov <cbou@mail.ru>
6 * Copyright © 2004 Szabolcs Gyurko
7 * Copyright © 2003 Ian Molton <spyro@f2s.com>
9 * Modified: 2004, Oct Szabolcs Gyurko
12 #include <linux/module.h>
13 #include <linux/types.h>
14 #include <linux/init.h>
15 #include <linux/slab.h>
16 #include <linux/delay.h>
17 #include <linux/device.h>
18 #include <linux/notifier.h>
19 #include <linux/err.h>
21 #include <linux/power_supply.h>
22 #include <linux/property.h>
23 #include <linux/thermal.h>
24 #include <linux/fixp-arith.h>
25 #include "power_supply.h"
26 #include "samsung-sdi-battery.h"
28 static const struct class power_supply_class = {
29 .name = "power_supply",
30 .dev_uevent = power_supply_uevent,
33 static BLOCKING_NOTIFIER_HEAD(power_supply_notifier);
35 static const struct device_type power_supply_dev_type = {
36 .name = "power_supply",
37 .groups = power_supply_attr_groups,
40 #define POWER_SUPPLY_DEFERRED_REGISTER_TIME msecs_to_jiffies(10)
42 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
43 struct power_supply *supply)
47 if (!supply->supplied_from && !supplier->supplied_to)
50 /* Support both supplied_to and supplied_from modes */
51 if (supply->supplied_from) {
52 if (!supplier->desc->name)
54 for (i = 0; i < supply->num_supplies; i++)
55 if (!strcmp(supplier->desc->name, supply->supplied_from[i]))
58 if (!supply->desc->name)
60 for (i = 0; i < supplier->num_supplicants; i++)
61 if (!strcmp(supplier->supplied_to[i], supply->desc->name))
68 static int __power_supply_changed_work(struct device *dev, void *data)
70 struct power_supply *psy = data;
71 struct power_supply *pst = dev_get_drvdata(dev);
73 if (__power_supply_is_supplied_by(psy, pst)) {
74 if (pst->desc->external_power_changed)
75 pst->desc->external_power_changed(pst);
81 static void power_supply_changed_work(struct work_struct *work)
84 struct power_supply *psy = container_of(work, struct power_supply,
87 dev_dbg(&psy->dev, "%s\n", __func__);
89 spin_lock_irqsave(&psy->changed_lock, flags);
91 * Check 'changed' here to avoid issues due to race between
92 * power_supply_changed() and this routine. In worst case
93 * power_supply_changed() can be called again just before we take above
94 * lock. During the first call of this routine we will mark 'changed' as
95 * false and it will stay false for the next call as well.
97 if (likely(psy->changed)) {
99 spin_unlock_irqrestore(&psy->changed_lock, flags);
100 power_supply_for_each_device(psy, __power_supply_changed_work);
101 power_supply_update_leds(psy);
102 blocking_notifier_call_chain(&power_supply_notifier,
103 PSY_EVENT_PROP_CHANGED, psy);
104 kobject_uevent(&psy->dev.kobj, KOBJ_CHANGE);
105 spin_lock_irqsave(&psy->changed_lock, flags);
109 * Hold the wakeup_source until all events are processed.
110 * power_supply_changed() might have called again and have set 'changed'
113 if (likely(!psy->changed))
115 spin_unlock_irqrestore(&psy->changed_lock, flags);
118 int power_supply_for_each_device(void *data, int (*fn)(struct device *dev, void *data))
120 return class_for_each_device(&power_supply_class, NULL, data, fn);
122 EXPORT_SYMBOL_GPL(power_supply_for_each_device);
124 void power_supply_changed(struct power_supply *psy)
128 dev_dbg(&psy->dev, "%s\n", __func__);
130 spin_lock_irqsave(&psy->changed_lock, flags);
132 pm_stay_awake(&psy->dev);
133 spin_unlock_irqrestore(&psy->changed_lock, flags);
134 schedule_work(&psy->changed_work);
136 EXPORT_SYMBOL_GPL(power_supply_changed);
139 * Notify that power supply was registered after parent finished the probing.
141 * Often power supply is registered from driver's probe function. However
142 * calling power_supply_changed() directly from power_supply_register()
143 * would lead to execution of get_property() function provided by the driver
144 * too early - before the probe ends.
146 * Avoid that by waiting on parent's mutex.
148 static void power_supply_deferred_register_work(struct work_struct *work)
150 struct power_supply *psy = container_of(work, struct power_supply,
151 deferred_register_work.work);
153 if (psy->dev.parent) {
154 while (!mutex_trylock(&psy->dev.parent->mutex)) {
161 power_supply_changed(psy);
164 mutex_unlock(&psy->dev.parent->mutex);
168 static int __power_supply_populate_supplied_from(struct device *dev,
171 struct power_supply *psy = data;
172 struct power_supply *epsy = dev_get_drvdata(dev);
173 struct device_node *np;
177 np = of_parse_phandle(psy->of_node, "power-supplies", i++);
181 if (np == epsy->of_node) {
182 dev_dbg(&psy->dev, "%s: Found supply : %s\n",
183 psy->desc->name, epsy->desc->name);
184 psy->supplied_from[i-1] = (char *)epsy->desc->name;
195 static int power_supply_populate_supplied_from(struct power_supply *psy)
199 error = power_supply_for_each_device(psy, __power_supply_populate_supplied_from);
201 dev_dbg(&psy->dev, "%s %d\n", __func__, error);
206 static int __power_supply_find_supply_from_node(struct device *dev,
209 struct device_node *np = data;
210 struct power_supply *epsy = dev_get_drvdata(dev);
212 /* returning non-zero breaks out of power_supply_for_each_device loop */
213 if (epsy->of_node == np)
219 static int power_supply_find_supply_from_node(struct device_node *supply_node)
224 * power_supply_for_each_device() either returns its own errors or values
225 * returned by __power_supply_find_supply_from_node().
227 * __power_supply_find_supply_from_node() will return 0 (no match)
230 * We return 0 if power_supply_for_each_device() returned 1, -EPROBE_DEFER if
231 * it returned 0, or error as returned by it.
233 error = power_supply_for_each_device(supply_node, __power_supply_find_supply_from_node);
235 return error ? (error == 1 ? 0 : error) : -EPROBE_DEFER;
238 static int power_supply_check_supplies(struct power_supply *psy)
240 struct device_node *np;
243 /* If there is already a list honor it */
244 if (psy->supplied_from && psy->num_supplies > 0)
247 /* No device node found, nothing to do */
254 np = of_parse_phandle(psy->of_node, "power-supplies", cnt++);
258 ret = power_supply_find_supply_from_node(np);
262 dev_dbg(&psy->dev, "Failed to find supply!\n");
267 /* Missing valid "power-supplies" entries */
271 /* All supplies found, allocate char ** array for filling */
272 psy->supplied_from = devm_kzalloc(&psy->dev, sizeof(*psy->supplied_from),
274 if (!psy->supplied_from)
277 *psy->supplied_from = devm_kcalloc(&psy->dev,
278 cnt - 1, sizeof(**psy->supplied_from),
280 if (!*psy->supplied_from)
283 return power_supply_populate_supplied_from(psy);
286 static int power_supply_check_supplies(struct power_supply *psy)
290 if (!psy->dev.parent)
293 nval = device_property_string_array_count(psy->dev.parent, "supplied-from");
297 psy->supplied_from = devm_kmalloc_array(&psy->dev, nval,
298 sizeof(char *), GFP_KERNEL);
299 if (!psy->supplied_from)
302 ret = device_property_read_string_array(psy->dev.parent,
303 "supplied-from", (const char **)psy->supplied_from, nval);
307 psy->num_supplies = nval;
313 struct psy_am_i_supplied_data {
314 struct power_supply *psy;
318 static int __power_supply_am_i_supplied(struct device *dev, void *_data)
320 union power_supply_propval ret = {0,};
321 struct power_supply *epsy = dev_get_drvdata(dev);
322 struct psy_am_i_supplied_data *data = _data;
324 if (__power_supply_is_supplied_by(epsy, data->psy)) {
326 if (!epsy->desc->get_property(epsy, POWER_SUPPLY_PROP_ONLINE,
334 int power_supply_am_i_supplied(struct power_supply *psy)
336 struct psy_am_i_supplied_data data = { psy, 0 };
339 error = power_supply_for_each_device(&data, __power_supply_am_i_supplied);
341 dev_dbg(&psy->dev, "%s count %u err %d\n", __func__, data.count, error);
348 EXPORT_SYMBOL_GPL(power_supply_am_i_supplied);
350 static int __power_supply_is_system_supplied(struct device *dev, void *data)
352 union power_supply_propval ret = {0,};
353 struct power_supply *psy = dev_get_drvdata(dev);
354 unsigned int *count = data;
356 if (!psy->desc->get_property(psy, POWER_SUPPLY_PROP_SCOPE, &ret))
357 if (ret.intval == POWER_SUPPLY_SCOPE_DEVICE)
361 if (psy->desc->type != POWER_SUPPLY_TYPE_BATTERY)
362 if (!psy->desc->get_property(psy, POWER_SUPPLY_PROP_ONLINE,
369 int power_supply_is_system_supplied(void)
372 unsigned int count = 0;
374 error = power_supply_for_each_device(&count, __power_supply_is_system_supplied);
377 * If no system scope power class device was found at all, most probably we
378 * are running on a desktop system, so assume we are on mains power.
385 EXPORT_SYMBOL_GPL(power_supply_is_system_supplied);
387 struct psy_get_supplier_prop_data {
388 struct power_supply *psy;
389 enum power_supply_property psp;
390 union power_supply_propval *val;
393 static int __power_supply_get_supplier_property(struct device *dev, void *_data)
395 struct power_supply *epsy = dev_get_drvdata(dev);
396 struct psy_get_supplier_prop_data *data = _data;
398 if (__power_supply_is_supplied_by(epsy, data->psy))
399 if (!power_supply_get_property(epsy, data->psp, data->val))
400 return 1; /* Success */
402 return 0; /* Continue iterating */
405 int power_supply_get_property_from_supplier(struct power_supply *psy,
406 enum power_supply_property psp,
407 union power_supply_propval *val)
409 struct psy_get_supplier_prop_data data = {
417 * This function is not intended for use with a supply with multiple
418 * suppliers, we simply pick the first supply to report the psp.
420 ret = power_supply_for_each_device(&data, __power_supply_get_supplier_property);
428 EXPORT_SYMBOL_GPL(power_supply_get_property_from_supplier);
430 int power_supply_set_battery_charged(struct power_supply *psy)
432 if (atomic_read(&psy->use_cnt) >= 0 &&
433 psy->desc->type == POWER_SUPPLY_TYPE_BATTERY &&
434 psy->desc->set_charged) {
435 psy->desc->set_charged(psy);
441 EXPORT_SYMBOL_GPL(power_supply_set_battery_charged);
443 static int power_supply_match_device_by_name(struct device *dev, const void *data)
445 const char *name = data;
446 struct power_supply *psy = dev_get_drvdata(dev);
448 return strcmp(psy->desc->name, name) == 0;
452 * power_supply_get_by_name() - Search for a power supply and returns its ref
453 * @name: Power supply name to fetch
455 * If power supply was found, it increases reference count for the
456 * internal power supply's device. The user should power_supply_put()
459 * Return: On success returns a reference to a power supply with
460 * matching name equals to @name, a NULL otherwise.
462 struct power_supply *power_supply_get_by_name(const char *name)
464 struct power_supply *psy = NULL;
465 struct device *dev = class_find_device(&power_supply_class, NULL, name,
466 power_supply_match_device_by_name);
469 psy = dev_get_drvdata(dev);
470 atomic_inc(&psy->use_cnt);
475 EXPORT_SYMBOL_GPL(power_supply_get_by_name);
478 * power_supply_put() - Drop reference obtained with power_supply_get_by_name
479 * @psy: Reference to put
481 * The reference to power supply should be put before unregistering
484 void power_supply_put(struct power_supply *psy)
488 atomic_dec(&psy->use_cnt);
489 put_device(&psy->dev);
491 EXPORT_SYMBOL_GPL(power_supply_put);
494 static int power_supply_match_device_node(struct device *dev, const void *data)
496 return dev->parent && dev->parent->of_node == data;
500 * power_supply_get_by_phandle() - Search for a power supply and returns its ref
501 * @np: Pointer to device node holding phandle property
502 * @property: Name of property holding a power supply name
504 * If power supply was found, it increases reference count for the
505 * internal power supply's device. The user should power_supply_put()
508 * Return: On success returns a reference to a power supply with
509 * matching name equals to value under @property, NULL or ERR_PTR otherwise.
511 struct power_supply *power_supply_get_by_phandle(struct device_node *np,
512 const char *property)
514 struct device_node *power_supply_np;
515 struct power_supply *psy = NULL;
518 power_supply_np = of_parse_phandle(np, property, 0);
519 if (!power_supply_np)
520 return ERR_PTR(-ENODEV);
522 dev = class_find_device(&power_supply_class, NULL, power_supply_np,
523 power_supply_match_device_node);
525 of_node_put(power_supply_np);
528 psy = dev_get_drvdata(dev);
529 atomic_inc(&psy->use_cnt);
534 EXPORT_SYMBOL_GPL(power_supply_get_by_phandle);
536 static void devm_power_supply_put(struct device *dev, void *res)
538 struct power_supply **psy = res;
540 power_supply_put(*psy);
544 * devm_power_supply_get_by_phandle() - Resource managed version of
545 * power_supply_get_by_phandle()
546 * @dev: Pointer to device holding phandle property
547 * @property: Name of property holding a power supply phandle
549 * Return: On success returns a reference to a power supply with
550 * matching name equals to value under @property, NULL or ERR_PTR otherwise.
552 struct power_supply *devm_power_supply_get_by_phandle(struct device *dev,
553 const char *property)
555 struct power_supply **ptr, *psy;
558 return ERR_PTR(-ENODEV);
560 ptr = devres_alloc(devm_power_supply_put, sizeof(*ptr), GFP_KERNEL);
562 return ERR_PTR(-ENOMEM);
564 psy = power_supply_get_by_phandle(dev->of_node, property);
565 if (IS_ERR_OR_NULL(psy)) {
569 devres_add(dev, ptr);
573 EXPORT_SYMBOL_GPL(devm_power_supply_get_by_phandle);
574 #endif /* CONFIG_OF */
576 int power_supply_get_battery_info(struct power_supply *psy,
577 struct power_supply_battery_info **info_out)
579 struct power_supply_resistance_temp_table *resist_table;
580 struct power_supply_battery_info *info;
581 struct device_node *battery_np = NULL;
582 struct fwnode_reference_args args;
583 struct fwnode_handle *fwnode = NULL;
590 battery_np = of_parse_phandle(psy->of_node, "monitored-battery", 0);
594 fwnode = fwnode_handle_get(of_fwnode_handle(battery_np));
595 } else if (psy->dev.parent) {
596 err = fwnode_property_get_reference_args(
597 dev_fwnode(psy->dev.parent),
598 "monitored-battery", NULL, 0, 0, &args);
602 fwnode = args.fwnode;
608 err = fwnode_property_read_string(fwnode, "compatible", &value);
613 /* Try static batteries first */
614 err = samsung_sdi_battery_get_info(&psy->dev, value, &info);
616 goto out_ret_pointer;
617 else if (err == -ENODEV)
619 * Device does not have a static battery.
620 * Proceed to look for a simple battery.
624 if (strcmp("simple-battery", value)) {
629 info = devm_kzalloc(&psy->dev, sizeof(*info), GFP_KERNEL);
635 info->technology = POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
636 info->energy_full_design_uwh = -EINVAL;
637 info->charge_full_design_uah = -EINVAL;
638 info->voltage_min_design_uv = -EINVAL;
639 info->voltage_max_design_uv = -EINVAL;
640 info->precharge_current_ua = -EINVAL;
641 info->charge_term_current_ua = -EINVAL;
642 info->constant_charge_current_max_ua = -EINVAL;
643 info->constant_charge_voltage_max_uv = -EINVAL;
644 info->tricklecharge_current_ua = -EINVAL;
645 info->precharge_voltage_max_uv = -EINVAL;
646 info->charge_restart_voltage_uv = -EINVAL;
647 info->overvoltage_limit_uv = -EINVAL;
648 info->maintenance_charge = NULL;
649 info->alert_low_temp_charge_current_ua = -EINVAL;
650 info->alert_low_temp_charge_voltage_uv = -EINVAL;
651 info->alert_high_temp_charge_current_ua = -EINVAL;
652 info->alert_high_temp_charge_voltage_uv = -EINVAL;
653 info->temp_ambient_alert_min = INT_MIN;
654 info->temp_ambient_alert_max = INT_MAX;
655 info->temp_alert_min = INT_MIN;
656 info->temp_alert_max = INT_MAX;
657 info->temp_min = INT_MIN;
658 info->temp_max = INT_MAX;
659 info->factory_internal_resistance_uohm = -EINVAL;
660 info->resist_table = NULL;
661 info->bti_resistance_ohm = -EINVAL;
662 info->bti_resistance_tolerance = -EINVAL;
664 for (index = 0; index < POWER_SUPPLY_OCV_TEMP_MAX; index++) {
665 info->ocv_table[index] = NULL;
666 info->ocv_temp[index] = -EINVAL;
667 info->ocv_table_size[index] = -EINVAL;
670 /* The property and field names below must correspond to elements
671 * in enum power_supply_property. For reasoning, see
672 * Documentation/power/power_supply_class.rst.
675 if (!fwnode_property_read_string(fwnode, "device-chemistry", &value)) {
676 if (!strcmp("nickel-cadmium", value))
677 info->technology = POWER_SUPPLY_TECHNOLOGY_NiCd;
678 else if (!strcmp("nickel-metal-hydride", value))
679 info->technology = POWER_SUPPLY_TECHNOLOGY_NiMH;
680 else if (!strcmp("lithium-ion", value))
681 /* Imprecise lithium-ion type */
682 info->technology = POWER_SUPPLY_TECHNOLOGY_LION;
683 else if (!strcmp("lithium-ion-polymer", value))
684 info->technology = POWER_SUPPLY_TECHNOLOGY_LIPO;
685 else if (!strcmp("lithium-ion-iron-phosphate", value))
686 info->technology = POWER_SUPPLY_TECHNOLOGY_LiFe;
687 else if (!strcmp("lithium-ion-manganese-oxide", value))
688 info->technology = POWER_SUPPLY_TECHNOLOGY_LiMn;
690 dev_warn(&psy->dev, "%s unknown battery type\n", value);
693 fwnode_property_read_u32(fwnode, "energy-full-design-microwatt-hours",
694 &info->energy_full_design_uwh);
695 fwnode_property_read_u32(fwnode, "charge-full-design-microamp-hours",
696 &info->charge_full_design_uah);
697 fwnode_property_read_u32(fwnode, "voltage-min-design-microvolt",
698 &info->voltage_min_design_uv);
699 fwnode_property_read_u32(fwnode, "voltage-max-design-microvolt",
700 &info->voltage_max_design_uv);
701 fwnode_property_read_u32(fwnode, "trickle-charge-current-microamp",
702 &info->tricklecharge_current_ua);
703 fwnode_property_read_u32(fwnode, "precharge-current-microamp",
704 &info->precharge_current_ua);
705 fwnode_property_read_u32(fwnode, "precharge-upper-limit-microvolt",
706 &info->precharge_voltage_max_uv);
707 fwnode_property_read_u32(fwnode, "charge-term-current-microamp",
708 &info->charge_term_current_ua);
709 fwnode_property_read_u32(fwnode, "re-charge-voltage-microvolt",
710 &info->charge_restart_voltage_uv);
711 fwnode_property_read_u32(fwnode, "over-voltage-threshold-microvolt",
712 &info->overvoltage_limit_uv);
713 fwnode_property_read_u32(fwnode, "constant-charge-current-max-microamp",
714 &info->constant_charge_current_max_ua);
715 fwnode_property_read_u32(fwnode, "constant-charge-voltage-max-microvolt",
716 &info->constant_charge_voltage_max_uv);
717 fwnode_property_read_u32(fwnode, "factory-internal-resistance-micro-ohms",
718 &info->factory_internal_resistance_uohm);
720 if (!fwnode_property_read_u32_array(fwnode, "ambient-celsius",
721 min_max, ARRAY_SIZE(min_max))) {
722 info->temp_ambient_alert_min = min_max[0];
723 info->temp_ambient_alert_max = min_max[1];
725 if (!fwnode_property_read_u32_array(fwnode, "alert-celsius",
726 min_max, ARRAY_SIZE(min_max))) {
727 info->temp_alert_min = min_max[0];
728 info->temp_alert_max = min_max[1];
730 if (!fwnode_property_read_u32_array(fwnode, "operating-range-celsius",
731 min_max, ARRAY_SIZE(min_max))) {
732 info->temp_min = min_max[0];
733 info->temp_max = min_max[1];
737 * The below code uses raw of-data parsing to parse
738 * /schemas/types.yaml#/definitions/uint32-matrix
739 * data, so for now this is only support with of.
742 goto out_ret_pointer;
744 len = of_property_count_u32_elems(battery_np, "ocv-capacity-celsius");
745 if (len < 0 && len != -EINVAL) {
748 } else if (len > POWER_SUPPLY_OCV_TEMP_MAX) {
749 dev_err(&psy->dev, "Too many temperature values\n");
752 } else if (len > 0) {
753 of_property_read_u32_array(battery_np, "ocv-capacity-celsius",
754 info->ocv_temp, len);
757 for (index = 0; index < len; index++) {
758 struct power_supply_battery_ocv_table *table;
760 int i, tab_len, size;
762 propname = kasprintf(GFP_KERNEL, "ocv-capacity-table-%d", index);
764 power_supply_put_battery_info(psy, info);
768 list = of_get_property(battery_np, propname, &size);
769 if (!list || !size) {
770 dev_err(&psy->dev, "failed to get %s\n", propname);
772 power_supply_put_battery_info(psy, info);
778 tab_len = size / (2 * sizeof(__be32));
779 info->ocv_table_size[index] = tab_len;
781 table = info->ocv_table[index] =
782 devm_kcalloc(&psy->dev, tab_len, sizeof(*table), GFP_KERNEL);
783 if (!info->ocv_table[index]) {
784 power_supply_put_battery_info(psy, info);
789 for (i = 0; i < tab_len; i++) {
790 table[i].ocv = be32_to_cpu(*list);
792 table[i].capacity = be32_to_cpu(*list);
797 list = of_get_property(battery_np, "resistance-temp-table", &len);
799 goto out_ret_pointer;
801 info->resist_table_size = len / (2 * sizeof(__be32));
802 resist_table = info->resist_table = devm_kcalloc(&psy->dev,
803 info->resist_table_size,
804 sizeof(*resist_table),
806 if (!info->resist_table) {
807 power_supply_put_battery_info(psy, info);
812 for (index = 0; index < info->resist_table_size; index++) {
813 resist_table[index].temp = be32_to_cpu(*list++);
814 resist_table[index].resistance = be32_to_cpu(*list++);
818 /* Finally return the whole thing */
822 fwnode_handle_put(fwnode);
823 of_node_put(battery_np);
826 EXPORT_SYMBOL_GPL(power_supply_get_battery_info);
828 void power_supply_put_battery_info(struct power_supply *psy,
829 struct power_supply_battery_info *info)
833 for (i = 0; i < POWER_SUPPLY_OCV_TEMP_MAX; i++) {
834 if (info->ocv_table[i])
835 devm_kfree(&psy->dev, info->ocv_table[i]);
838 if (info->resist_table)
839 devm_kfree(&psy->dev, info->resist_table);
841 devm_kfree(&psy->dev, info);
843 EXPORT_SYMBOL_GPL(power_supply_put_battery_info);
845 const enum power_supply_property power_supply_battery_info_properties[] = {
846 POWER_SUPPLY_PROP_TECHNOLOGY,
847 POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
848 POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
849 POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
850 POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
851 POWER_SUPPLY_PROP_PRECHARGE_CURRENT,
852 POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
853 POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX,
854 POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
855 POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MIN,
856 POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MAX,
857 POWER_SUPPLY_PROP_TEMP_ALERT_MIN,
858 POWER_SUPPLY_PROP_TEMP_ALERT_MAX,
859 POWER_SUPPLY_PROP_TEMP_MIN,
860 POWER_SUPPLY_PROP_TEMP_MAX,
862 EXPORT_SYMBOL_GPL(power_supply_battery_info_properties);
864 const size_t power_supply_battery_info_properties_size = ARRAY_SIZE(power_supply_battery_info_properties);
865 EXPORT_SYMBOL_GPL(power_supply_battery_info_properties_size);
867 bool power_supply_battery_info_has_prop(struct power_supply_battery_info *info,
868 enum power_supply_property psp)
874 case POWER_SUPPLY_PROP_TECHNOLOGY:
875 return info->technology != POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
876 case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN:
877 return info->energy_full_design_uwh >= 0;
878 case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
879 return info->charge_full_design_uah >= 0;
880 case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
881 return info->voltage_min_design_uv >= 0;
882 case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
883 return info->voltage_max_design_uv >= 0;
884 case POWER_SUPPLY_PROP_PRECHARGE_CURRENT:
885 return info->precharge_current_ua >= 0;
886 case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
887 return info->charge_term_current_ua >= 0;
888 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
889 return info->constant_charge_current_max_ua >= 0;
890 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX:
891 return info->constant_charge_voltage_max_uv >= 0;
892 case POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MIN:
893 return info->temp_ambient_alert_min > INT_MIN;
894 case POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MAX:
895 return info->temp_ambient_alert_max < INT_MAX;
896 case POWER_SUPPLY_PROP_TEMP_ALERT_MIN:
897 return info->temp_alert_min > INT_MIN;
898 case POWER_SUPPLY_PROP_TEMP_ALERT_MAX:
899 return info->temp_alert_max < INT_MAX;
900 case POWER_SUPPLY_PROP_TEMP_MIN:
901 return info->temp_min > INT_MIN;
902 case POWER_SUPPLY_PROP_TEMP_MAX:
903 return info->temp_max < INT_MAX;
908 EXPORT_SYMBOL_GPL(power_supply_battery_info_has_prop);
910 int power_supply_battery_info_get_prop(struct power_supply_battery_info *info,
911 enum power_supply_property psp,
912 union power_supply_propval *val)
917 if (!power_supply_battery_info_has_prop(info, psp))
921 case POWER_SUPPLY_PROP_TECHNOLOGY:
922 val->intval = info->technology;
924 case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN:
925 val->intval = info->energy_full_design_uwh;
927 case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
928 val->intval = info->charge_full_design_uah;
930 case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
931 val->intval = info->voltage_min_design_uv;
933 case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
934 val->intval = info->voltage_max_design_uv;
936 case POWER_SUPPLY_PROP_PRECHARGE_CURRENT:
937 val->intval = info->precharge_current_ua;
939 case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
940 val->intval = info->charge_term_current_ua;
942 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
943 val->intval = info->constant_charge_current_max_ua;
945 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX:
946 val->intval = info->constant_charge_voltage_max_uv;
948 case POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MIN:
949 val->intval = info->temp_ambient_alert_min;
951 case POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MAX:
952 val->intval = info->temp_ambient_alert_max;
954 case POWER_SUPPLY_PROP_TEMP_ALERT_MIN:
955 val->intval = info->temp_alert_min;
957 case POWER_SUPPLY_PROP_TEMP_ALERT_MAX:
958 val->intval = info->temp_alert_max;
960 case POWER_SUPPLY_PROP_TEMP_MIN:
961 val->intval = info->temp_min;
963 case POWER_SUPPLY_PROP_TEMP_MAX:
964 val->intval = info->temp_max;
970 EXPORT_SYMBOL_GPL(power_supply_battery_info_get_prop);
973 * power_supply_temp2resist_simple() - find the battery internal resistance
974 * percent from temperature
975 * @table: Pointer to battery resistance temperature table
976 * @table_len: The table length
977 * @temp: Current temperature
979 * This helper function is used to look up battery internal resistance percent
980 * according to current temperature value from the resistance temperature table,
981 * and the table must be ordered descending. Then the actual battery internal
982 * resistance = the ideal battery internal resistance * percent / 100.
984 * Return: the battery internal resistance percent
986 int power_supply_temp2resist_simple(struct power_supply_resistance_temp_table *table,
987 int table_len, int temp)
991 for (i = 0; i < table_len; i++)
992 if (temp > table[i].temp)
995 /* The library function will deal with high == low */
998 else if (i == table_len)
1001 high = (low = i) - 1;
1003 return fixp_linear_interpolate(table[low].temp,
1004 table[low].resistance,
1006 table[high].resistance,
1009 EXPORT_SYMBOL_GPL(power_supply_temp2resist_simple);
1012 * power_supply_vbat2ri() - find the battery internal resistance
1013 * from the battery voltage
1014 * @info: The battery information container
1015 * @vbat_uv: The battery voltage in microvolt
1016 * @charging: If we are charging (true) or not (false)
1018 * This helper function is used to look up battery internal resistance
1019 * according to current battery voltage. Depending on whether the battery
1020 * is currently charging or not, different resistance will be returned.
1022 * Returns the internal resistance in microohm or negative error code.
1024 int power_supply_vbat2ri(struct power_supply_battery_info *info,
1025 int vbat_uv, bool charging)
1027 struct power_supply_vbat_ri_table *vbat2ri;
1032 * If we are charging, and the battery supplies a separate table
1033 * for this state, we use that in order to compensate for the
1034 * charging voltage. Otherwise we use the main table.
1036 if (charging && info->vbat2ri_charging) {
1037 vbat2ri = info->vbat2ri_charging;
1038 table_len = info->vbat2ri_charging_size;
1040 vbat2ri = info->vbat2ri_discharging;
1041 table_len = info->vbat2ri_discharging_size;
1045 * If no tables are specified, or if we are above the highest voltage in
1046 * the voltage table, just return the factory specified internal resistance.
1048 if (!vbat2ri || (table_len <= 0) || (vbat_uv > vbat2ri[0].vbat_uv)) {
1049 if (charging && (info->factory_internal_resistance_charging_uohm > 0))
1050 return info->factory_internal_resistance_charging_uohm;
1052 return info->factory_internal_resistance_uohm;
1055 /* Break loop at table_len - 1 because that is the highest index */
1056 for (i = 0; i < table_len - 1; i++)
1057 if (vbat_uv > vbat2ri[i].vbat_uv)
1060 /* The library function will deal with high == low */
1061 if ((i == 0) || (i == (table_len - 1)))
1067 return fixp_linear_interpolate(vbat2ri[low].vbat_uv,
1068 vbat2ri[low].ri_uohm,
1069 vbat2ri[high].vbat_uv,
1070 vbat2ri[high].ri_uohm,
1073 EXPORT_SYMBOL_GPL(power_supply_vbat2ri);
1075 struct power_supply_maintenance_charge_table *
1076 power_supply_get_maintenance_charging_setting(struct power_supply_battery_info *info,
1079 if (index >= info->maintenance_charge_size)
1081 return &info->maintenance_charge[index];
1083 EXPORT_SYMBOL_GPL(power_supply_get_maintenance_charging_setting);
1086 * power_supply_ocv2cap_simple() - find the battery capacity
1087 * @table: Pointer to battery OCV lookup table
1088 * @table_len: OCV table length
1089 * @ocv: Current OCV value
1091 * This helper function is used to look up battery capacity according to
1092 * current OCV value from one OCV table, and the OCV table must be ordered
1095 * Return: the battery capacity.
1097 int power_supply_ocv2cap_simple(struct power_supply_battery_ocv_table *table,
1098 int table_len, int ocv)
1102 for (i = 0; i < table_len; i++)
1103 if (ocv > table[i].ocv)
1106 /* The library function will deal with high == low */
1109 else if (i == table_len)
1112 high = (low = i) - 1;
1114 return fixp_linear_interpolate(table[low].ocv,
1115 table[low].capacity,
1117 table[high].capacity,
1120 EXPORT_SYMBOL_GPL(power_supply_ocv2cap_simple);
1122 struct power_supply_battery_ocv_table *
1123 power_supply_find_ocv2cap_table(struct power_supply_battery_info *info,
1124 int temp, int *table_len)
1126 int best_temp_diff = INT_MAX, temp_diff;
1127 u8 i, best_index = 0;
1129 if (!info->ocv_table[0])
1132 for (i = 0; i < POWER_SUPPLY_OCV_TEMP_MAX; i++) {
1133 /* Out of capacity tables */
1134 if (!info->ocv_table[i])
1137 temp_diff = abs(info->ocv_temp[i] - temp);
1139 if (temp_diff < best_temp_diff) {
1140 best_temp_diff = temp_diff;
1145 *table_len = info->ocv_table_size[best_index];
1146 return info->ocv_table[best_index];
1148 EXPORT_SYMBOL_GPL(power_supply_find_ocv2cap_table);
1150 int power_supply_batinfo_ocv2cap(struct power_supply_battery_info *info,
1153 struct power_supply_battery_ocv_table *table;
1156 table = power_supply_find_ocv2cap_table(info, temp, &table_len);
1160 return power_supply_ocv2cap_simple(table, table_len, ocv);
1162 EXPORT_SYMBOL_GPL(power_supply_batinfo_ocv2cap);
1164 bool power_supply_battery_bti_in_range(struct power_supply_battery_info *info,
1169 /* Nothing like this can be checked */
1170 if (info->bti_resistance_ohm <= 0)
1173 /* This will be extremely strict and unlikely to work */
1174 if (info->bti_resistance_tolerance <= 0)
1175 return (info->bti_resistance_ohm == resistance);
1177 low = info->bti_resistance_ohm -
1178 (info->bti_resistance_ohm * info->bti_resistance_tolerance) / 100;
1179 high = info->bti_resistance_ohm +
1180 (info->bti_resistance_ohm * info->bti_resistance_tolerance) / 100;
1182 return ((resistance >= low) && (resistance <= high));
1184 EXPORT_SYMBOL_GPL(power_supply_battery_bti_in_range);
1186 static bool psy_has_property(const struct power_supply_desc *psy_desc,
1187 enum power_supply_property psp)
1192 for (i = 0; i < psy_desc->num_properties; i++) {
1193 if (psy_desc->properties[i] == psp) {
1202 int power_supply_get_property(struct power_supply *psy,
1203 enum power_supply_property psp,
1204 union power_supply_propval *val)
1206 if (atomic_read(&psy->use_cnt) <= 0) {
1207 if (!psy->initialized)
1212 if (psy_has_property(psy->desc, psp))
1213 return psy->desc->get_property(psy, psp, val);
1214 else if (power_supply_battery_info_has_prop(psy->battery_info, psp))
1215 return power_supply_battery_info_get_prop(psy->battery_info, psp, val);
1219 EXPORT_SYMBOL_GPL(power_supply_get_property);
1221 int power_supply_set_property(struct power_supply *psy,
1222 enum power_supply_property psp,
1223 const union power_supply_propval *val)
1225 if (atomic_read(&psy->use_cnt) <= 0 || !psy->desc->set_property)
1228 return psy->desc->set_property(psy, psp, val);
1230 EXPORT_SYMBOL_GPL(power_supply_set_property);
1232 int power_supply_property_is_writeable(struct power_supply *psy,
1233 enum power_supply_property psp)
1235 if (atomic_read(&psy->use_cnt) <= 0 ||
1236 !psy->desc->property_is_writeable)
1239 return psy->desc->property_is_writeable(psy, psp);
1241 EXPORT_SYMBOL_GPL(power_supply_property_is_writeable);
1243 void power_supply_external_power_changed(struct power_supply *psy)
1245 if (atomic_read(&psy->use_cnt) <= 0 ||
1246 !psy->desc->external_power_changed)
1249 psy->desc->external_power_changed(psy);
1251 EXPORT_SYMBOL_GPL(power_supply_external_power_changed);
1253 int power_supply_powers(struct power_supply *psy, struct device *dev)
1255 return sysfs_create_link(&psy->dev.kobj, &dev->kobj, "powers");
1257 EXPORT_SYMBOL_GPL(power_supply_powers);
1259 static void power_supply_dev_release(struct device *dev)
1261 struct power_supply *psy = to_power_supply(dev);
1263 dev_dbg(dev, "%s\n", __func__);
1267 int power_supply_reg_notifier(struct notifier_block *nb)
1269 return blocking_notifier_chain_register(&power_supply_notifier, nb);
1271 EXPORT_SYMBOL_GPL(power_supply_reg_notifier);
1273 void power_supply_unreg_notifier(struct notifier_block *nb)
1275 blocking_notifier_chain_unregister(&power_supply_notifier, nb);
1277 EXPORT_SYMBOL_GPL(power_supply_unreg_notifier);
1279 #ifdef CONFIG_THERMAL
1280 static int power_supply_read_temp(struct thermal_zone_device *tzd,
1283 struct power_supply *psy;
1284 union power_supply_propval val;
1287 WARN_ON(tzd == NULL);
1288 psy = thermal_zone_device_priv(tzd);
1289 ret = power_supply_get_property(psy, POWER_SUPPLY_PROP_TEMP, &val);
1293 /* Convert tenths of degree Celsius to milli degree Celsius. */
1294 *temp = val.intval * 100;
1299 static struct thermal_zone_device_ops psy_tzd_ops = {
1300 .get_temp = power_supply_read_temp,
1303 static int psy_register_thermal(struct power_supply *psy)
1307 if (psy->desc->no_thermal)
1310 /* Register battery zone device psy reports temperature */
1311 if (psy_has_property(psy->desc, POWER_SUPPLY_PROP_TEMP)) {
1312 /* Prefer our hwmon device and avoid duplicates */
1313 struct thermal_zone_params tzp = {
1314 .no_hwmon = IS_ENABLED(CONFIG_POWER_SUPPLY_HWMON)
1316 psy->tzd = thermal_tripless_zone_device_register(psy->desc->name,
1317 psy, &psy_tzd_ops, &tzp);
1318 if (IS_ERR(psy->tzd))
1319 return PTR_ERR(psy->tzd);
1320 ret = thermal_zone_device_enable(psy->tzd);
1322 thermal_zone_device_unregister(psy->tzd);
1329 static void psy_unregister_thermal(struct power_supply *psy)
1331 if (IS_ERR_OR_NULL(psy->tzd))
1333 thermal_zone_device_unregister(psy->tzd);
1337 static int psy_register_thermal(struct power_supply *psy)
1342 static void psy_unregister_thermal(struct power_supply *psy)
1347 static struct power_supply *__must_check
1348 __power_supply_register(struct device *parent,
1349 const struct power_supply_desc *desc,
1350 const struct power_supply_config *cfg,
1354 struct power_supply *psy;
1357 if (!desc || !desc->name || !desc->properties || !desc->num_properties)
1358 return ERR_PTR(-EINVAL);
1361 pr_warn("%s: Expected proper parent device for '%s'\n",
1362 __func__, desc->name);
1364 if (psy_has_property(desc, POWER_SUPPLY_PROP_USB_TYPE) &&
1365 (!desc->usb_types || !desc->num_usb_types))
1366 return ERR_PTR(-EINVAL);
1368 psy = kzalloc(sizeof(*psy), GFP_KERNEL);
1370 return ERR_PTR(-ENOMEM);
1374 device_initialize(dev);
1376 dev->class = &power_supply_class;
1377 dev->type = &power_supply_dev_type;
1378 dev->parent = parent;
1379 dev->release = power_supply_dev_release;
1380 dev_set_drvdata(dev, psy);
1383 dev->groups = cfg->attr_grp;
1384 psy->drv_data = cfg->drv_data;
1386 cfg->fwnode ? to_of_node(cfg->fwnode) : cfg->of_node;
1387 dev->of_node = psy->of_node;
1388 psy->supplied_to = cfg->supplied_to;
1389 psy->num_supplicants = cfg->num_supplicants;
1392 rc = dev_set_name(dev, "%s", desc->name);
1394 goto dev_set_name_failed;
1396 INIT_WORK(&psy->changed_work, power_supply_changed_work);
1397 INIT_DELAYED_WORK(&psy->deferred_register_work,
1398 power_supply_deferred_register_work);
1400 rc = power_supply_check_supplies(psy);
1402 dev_dbg(dev, "Not all required supplies found, defer probe\n");
1403 goto check_supplies_failed;
1407 * Expose constant battery info, if it is available. While there are
1408 * some chargers accessing constant battery data, we only want to
1409 * expose battery data to userspace for battery devices.
1411 if (desc->type == POWER_SUPPLY_TYPE_BATTERY) {
1412 rc = power_supply_get_battery_info(psy, &psy->battery_info);
1413 if (rc && rc != -ENODEV && rc != -ENOENT)
1414 goto check_supplies_failed;
1417 spin_lock_init(&psy->changed_lock);
1418 rc = device_add(dev);
1420 goto device_add_failed;
1422 rc = device_init_wakeup(dev, ws);
1424 goto wakeup_init_failed;
1426 rc = psy_register_thermal(psy);
1428 goto register_thermal_failed;
1430 rc = power_supply_create_triggers(psy);
1432 goto create_triggers_failed;
1434 rc = power_supply_add_hwmon_sysfs(psy);
1436 goto add_hwmon_sysfs_failed;
1439 * Update use_cnt after any uevents (most notably from device_add()).
1440 * We are here still during driver's probe but
1441 * the power_supply_uevent() calls back driver's get_property
1443 * 1. Driver did not assigned the returned struct power_supply,
1444 * 2. Driver could not finish initialization (anything in its probe
1445 * after calling power_supply_register()).
1447 atomic_inc(&psy->use_cnt);
1448 psy->initialized = true;
1450 queue_delayed_work(system_power_efficient_wq,
1451 &psy->deferred_register_work,
1452 POWER_SUPPLY_DEFERRED_REGISTER_TIME);
1456 add_hwmon_sysfs_failed:
1457 power_supply_remove_triggers(psy);
1458 create_triggers_failed:
1459 psy_unregister_thermal(psy);
1460 register_thermal_failed:
1464 check_supplies_failed:
1465 dev_set_name_failed:
1471 * power_supply_register() - Register new power supply
1472 * @parent: Device to be a parent of power supply's device, usually
1473 * the device which probe function calls this
1474 * @desc: Description of power supply, must be valid through whole
1475 * lifetime of this power supply
1476 * @cfg: Run-time specific configuration accessed during registering,
1479 * Return: A pointer to newly allocated power_supply on success
1480 * or ERR_PTR otherwise.
1481 * Use power_supply_unregister() on returned power_supply pointer to release
1484 struct power_supply *__must_check power_supply_register(struct device *parent,
1485 const struct power_supply_desc *desc,
1486 const struct power_supply_config *cfg)
1488 return __power_supply_register(parent, desc, cfg, true);
1490 EXPORT_SYMBOL_GPL(power_supply_register);
1493 * power_supply_register_no_ws() - Register new non-waking-source power supply
1494 * @parent: Device to be a parent of power supply's device, usually
1495 * the device which probe function calls this
1496 * @desc: Description of power supply, must be valid through whole
1497 * lifetime of this power supply
1498 * @cfg: Run-time specific configuration accessed during registering,
1501 * Return: A pointer to newly allocated power_supply on success
1502 * or ERR_PTR otherwise.
1503 * Use power_supply_unregister() on returned power_supply pointer to release
1506 struct power_supply *__must_check
1507 power_supply_register_no_ws(struct device *parent,
1508 const struct power_supply_desc *desc,
1509 const struct power_supply_config *cfg)
1511 return __power_supply_register(parent, desc, cfg, false);
1513 EXPORT_SYMBOL_GPL(power_supply_register_no_ws);
1515 static void devm_power_supply_release(struct device *dev, void *res)
1517 struct power_supply **psy = res;
1519 power_supply_unregister(*psy);
1523 * devm_power_supply_register() - Register managed power supply
1524 * @parent: Device to be a parent of power supply's device, usually
1525 * the device which probe function calls this
1526 * @desc: Description of power supply, must be valid through whole
1527 * lifetime of this power supply
1528 * @cfg: Run-time specific configuration accessed during registering,
1531 * Return: A pointer to newly allocated power_supply on success
1532 * or ERR_PTR otherwise.
1533 * The returned power_supply pointer will be automatically unregistered
1536 struct power_supply *__must_check
1537 devm_power_supply_register(struct device *parent,
1538 const struct power_supply_desc *desc,
1539 const struct power_supply_config *cfg)
1541 struct power_supply **ptr, *psy;
1543 ptr = devres_alloc(devm_power_supply_release, sizeof(*ptr), GFP_KERNEL);
1546 return ERR_PTR(-ENOMEM);
1547 psy = __power_supply_register(parent, desc, cfg, true);
1552 devres_add(parent, ptr);
1556 EXPORT_SYMBOL_GPL(devm_power_supply_register);
1559 * devm_power_supply_register_no_ws() - Register managed non-waking-source power supply
1560 * @parent: Device to be a parent of power supply's device, usually
1561 * the device which probe function calls this
1562 * @desc: Description of power supply, must be valid through whole
1563 * lifetime of this power supply
1564 * @cfg: Run-time specific configuration accessed during registering,
1567 * Return: A pointer to newly allocated power_supply on success
1568 * or ERR_PTR otherwise.
1569 * The returned power_supply pointer will be automatically unregistered
1572 struct power_supply *__must_check
1573 devm_power_supply_register_no_ws(struct device *parent,
1574 const struct power_supply_desc *desc,
1575 const struct power_supply_config *cfg)
1577 struct power_supply **ptr, *psy;
1579 ptr = devres_alloc(devm_power_supply_release, sizeof(*ptr), GFP_KERNEL);
1582 return ERR_PTR(-ENOMEM);
1583 psy = __power_supply_register(parent, desc, cfg, false);
1588 devres_add(parent, ptr);
1592 EXPORT_SYMBOL_GPL(devm_power_supply_register_no_ws);
1595 * power_supply_unregister() - Remove this power supply from system
1596 * @psy: Pointer to power supply to unregister
1598 * Remove this power supply from the system. The resources of power supply
1599 * will be freed here or on last power_supply_put() call.
1601 void power_supply_unregister(struct power_supply *psy)
1603 WARN_ON(atomic_dec_return(&psy->use_cnt));
1604 psy->removing = true;
1605 cancel_work_sync(&psy->changed_work);
1606 cancel_delayed_work_sync(&psy->deferred_register_work);
1607 sysfs_remove_link(&psy->dev.kobj, "powers");
1608 power_supply_remove_hwmon_sysfs(psy);
1609 power_supply_remove_triggers(psy);
1610 psy_unregister_thermal(psy);
1611 device_init_wakeup(&psy->dev, false);
1612 device_unregister(&psy->dev);
1614 EXPORT_SYMBOL_GPL(power_supply_unregister);
1616 void *power_supply_get_drvdata(struct power_supply *psy)
1618 return psy->drv_data;
1620 EXPORT_SYMBOL_GPL(power_supply_get_drvdata);
1622 static int __init power_supply_class_init(void)
1624 power_supply_init_attrs();
1625 return class_register(&power_supply_class);
1628 static void __exit power_supply_class_exit(void)
1630 class_unregister(&power_supply_class);
1633 subsys_initcall(power_supply_class_init);
1634 module_exit(power_supply_class_exit);
1636 MODULE_DESCRIPTION("Universal power supply monitor class");
1637 MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
1638 MODULE_AUTHOR("Szabolcs Gyurko");
1639 MODULE_AUTHOR("Anton Vorontsov <cbou@mail.ru>");