2019-05-29 01:10:21 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2007-05-04 04:27:45 +08:00
|
|
|
/*
|
|
|
|
* Sysfs interface for the universal power supply monitor class
|
|
|
|
*
|
|
|
|
* Copyright © 2007 David Woodhouse <dwmw2@infradead.org>
|
|
|
|
* Copyright © 2007 Anton Vorontsov <cbou@mail.ru>
|
|
|
|
* Copyright © 2004 Szabolcs Gyurko
|
|
|
|
* Copyright © 2003 Ian Molton <spyro@f2s.com>
|
|
|
|
*
|
|
|
|
* Modified: 2004, Oct Szabolcs Gyurko
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/ctype.h>
|
2012-01-23 00:23:42 +08:00
|
|
|
#include <linux/device.h>
|
2007-05-04 04:27:45 +08:00
|
|
|
#include <linux/power_supply.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2011-05-27 22:22:46 +08:00
|
|
|
#include <linux/stat.h>
|
2007-05-04 04:27:45 +08:00
|
|
|
|
2007-11-26 05:25:45 +08:00
|
|
|
#include "power_supply.h"
|
|
|
|
|
2020-05-05 04:29:27 +08:00
|
|
|
#define MAX_PROP_NAME_LEN 30
|
2007-05-04 04:27:45 +08:00
|
|
|
|
2020-05-05 04:29:27 +08:00
|
|
|
struct power_supply_attr {
|
|
|
|
const char *prop_name;
|
|
|
|
char attr_name[MAX_PROP_NAME_LEN + 1];
|
|
|
|
struct device_attribute dev_attr;
|
2020-05-05 04:29:29 +08:00
|
|
|
const char * const *text_values;
|
|
|
|
int text_values_len;
|
2020-05-05 04:29:27 +08:00
|
|
|
};
|
2007-05-04 04:27:45 +08:00
|
|
|
|
2020-05-05 04:29:29 +08:00
|
|
|
#define _POWER_SUPPLY_ATTR(_name, _text, _len) \
|
|
|
|
[POWER_SUPPLY_PROP_ ## _name] = \
|
|
|
|
{ \
|
|
|
|
.prop_name = #_name, \
|
|
|
|
.attr_name = #_name "\0", \
|
|
|
|
.text_values = _text, \
|
|
|
|
.text_values_len = _len, \
|
2020-05-05 04:29:27 +08:00
|
|
|
}
|
2007-05-04 04:27:45 +08:00
|
|
|
|
2020-05-05 04:29:29 +08:00
|
|
|
#define POWER_SUPPLY_ATTR(_name) _POWER_SUPPLY_ATTR(_name, NULL, 0)
|
|
|
|
#define _POWER_SUPPLY_ENUM_ATTR(_name, _text) \
|
|
|
|
_POWER_SUPPLY_ATTR(_name, _text, ARRAY_SIZE(_text))
|
|
|
|
#define POWER_SUPPLY_ENUM_ATTR(_name) \
|
|
|
|
_POWER_SUPPLY_ENUM_ATTR(_name, POWER_SUPPLY_ ## _name ## _TEXT)
|
|
|
|
|
|
|
|
static const char * const POWER_SUPPLY_TYPE_TEXT[] = {
|
2020-05-05 04:29:28 +08:00
|
|
|
[POWER_SUPPLY_TYPE_UNKNOWN] = "Unknown",
|
|
|
|
[POWER_SUPPLY_TYPE_BATTERY] = "Battery",
|
|
|
|
[POWER_SUPPLY_TYPE_UPS] = "UPS",
|
|
|
|
[POWER_SUPPLY_TYPE_MAINS] = "Mains",
|
|
|
|
[POWER_SUPPLY_TYPE_USB] = "USB",
|
|
|
|
[POWER_SUPPLY_TYPE_USB_DCP] = "USB_DCP",
|
|
|
|
[POWER_SUPPLY_TYPE_USB_CDP] = "USB_CDP",
|
|
|
|
[POWER_SUPPLY_TYPE_USB_ACA] = "USB_ACA",
|
|
|
|
[POWER_SUPPLY_TYPE_USB_TYPE_C] = "USB_C",
|
|
|
|
[POWER_SUPPLY_TYPE_USB_PD] = "USB_PD",
|
|
|
|
[POWER_SUPPLY_TYPE_USB_PD_DRP] = "USB_PD_DRP",
|
|
|
|
[POWER_SUPPLY_TYPE_APPLE_BRICK_ID] = "BrickID",
|
2020-08-14 02:34:08 +08:00
|
|
|
[POWER_SUPPLY_TYPE_WIRELESS] = "Wireless",
|
2017-05-16 05:21:15 +08:00
|
|
|
};
|
|
|
|
|
2020-05-05 04:29:29 +08:00
|
|
|
static const char * const POWER_SUPPLY_USB_TYPE_TEXT[] = {
|
2020-05-05 04:29:28 +08:00
|
|
|
[POWER_SUPPLY_USB_TYPE_UNKNOWN] = "Unknown",
|
|
|
|
[POWER_SUPPLY_USB_TYPE_SDP] = "SDP",
|
|
|
|
[POWER_SUPPLY_USB_TYPE_DCP] = "DCP",
|
|
|
|
[POWER_SUPPLY_USB_TYPE_CDP] = "CDP",
|
|
|
|
[POWER_SUPPLY_USB_TYPE_ACA] = "ACA",
|
|
|
|
[POWER_SUPPLY_USB_TYPE_C] = "C",
|
|
|
|
[POWER_SUPPLY_USB_TYPE_PD] = "PD",
|
|
|
|
[POWER_SUPPLY_USB_TYPE_PD_DRP] = "PD_DRP",
|
|
|
|
[POWER_SUPPLY_USB_TYPE_PD_PPS] = "PD_PPS",
|
|
|
|
[POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID] = "BrickID",
|
power: supply: Add 'usb_type' property and supporting code
This commit adds the 'usb_type' property to represent USB supplies
which can report a number of different types based on a connection
event.
Examples of this already exist in drivers whereby the existing 'type'
property is updated, based on an event, to represent what was
connected (e.g. USB, USB_DCP, USB_ACA, ...). Current implementations
however don't show all supported connectable types, so this knowledge
has to be exlicitly known for each driver that supports this.
The 'usb_type' property is intended to fill this void and show users
all possible USB types supported by a driver. The property, when read,
shows all available types for the driver, and the one currently chosen
is highlighted/bracketed. It is expected that the 'type' property
would then just show the top-level type 'USB', and this would be
static.
Currently the 'usb_type' enum contains all of the USB variant types
that exist for the 'type' enum at this time, and in addition has
SDP and PPS types. The mirroring is intentional so as to not impact
existing usage of the 'type' property.
Signed-off-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-04-23 22:10:59 +08:00
|
|
|
};
|
|
|
|
|
2020-05-05 04:29:29 +08:00
|
|
|
static const char * const POWER_SUPPLY_STATUS_TEXT[] = {
|
2020-05-05 04:29:28 +08:00
|
|
|
[POWER_SUPPLY_STATUS_UNKNOWN] = "Unknown",
|
|
|
|
[POWER_SUPPLY_STATUS_CHARGING] = "Charging",
|
|
|
|
[POWER_SUPPLY_STATUS_DISCHARGING] = "Discharging",
|
|
|
|
[POWER_SUPPLY_STATUS_NOT_CHARGING] = "Not charging",
|
|
|
|
[POWER_SUPPLY_STATUS_FULL] = "Full",
|
2017-05-16 05:21:15 +08:00
|
|
|
};
|
|
|
|
|
2020-05-05 04:29:29 +08:00
|
|
|
static const char * const POWER_SUPPLY_CHARGE_TYPE_TEXT[] = {
|
2020-05-05 04:29:28 +08:00
|
|
|
[POWER_SUPPLY_CHARGE_TYPE_UNKNOWN] = "Unknown",
|
|
|
|
[POWER_SUPPLY_CHARGE_TYPE_NONE] = "N/A",
|
|
|
|
[POWER_SUPPLY_CHARGE_TYPE_TRICKLE] = "Trickle",
|
|
|
|
[POWER_SUPPLY_CHARGE_TYPE_FAST] = "Fast",
|
|
|
|
[POWER_SUPPLY_CHARGE_TYPE_STANDARD] = "Standard",
|
|
|
|
[POWER_SUPPLY_CHARGE_TYPE_ADAPTIVE] = "Adaptive",
|
|
|
|
[POWER_SUPPLY_CHARGE_TYPE_CUSTOM] = "Custom",
|
2020-07-30 11:26:09 +08:00
|
|
|
[POWER_SUPPLY_CHARGE_TYPE_LONGLIFE] = "Long Life",
|
2017-05-16 05:21:15 +08:00
|
|
|
};
|
|
|
|
|
2020-05-05 04:29:29 +08:00
|
|
|
static const char * const POWER_SUPPLY_HEALTH_TEXT[] = {
|
2020-05-05 04:29:28 +08:00
|
|
|
[POWER_SUPPLY_HEALTH_UNKNOWN] = "Unknown",
|
|
|
|
[POWER_SUPPLY_HEALTH_GOOD] = "Good",
|
|
|
|
[POWER_SUPPLY_HEALTH_OVERHEAT] = "Overheat",
|
|
|
|
[POWER_SUPPLY_HEALTH_DEAD] = "Dead",
|
|
|
|
[POWER_SUPPLY_HEALTH_OVERVOLTAGE] = "Over voltage",
|
|
|
|
[POWER_SUPPLY_HEALTH_UNSPEC_FAILURE] = "Unspecified failure",
|
|
|
|
[POWER_SUPPLY_HEALTH_COLD] = "Cold",
|
|
|
|
[POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE] = "Watchdog timer expire",
|
|
|
|
[POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE] = "Safety timer expire",
|
|
|
|
[POWER_SUPPLY_HEALTH_OVERCURRENT] = "Over current",
|
2020-05-14 02:56:00 +08:00
|
|
|
[POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED] = "Calibration required",
|
2020-07-21 04:43:57 +08:00
|
|
|
[POWER_SUPPLY_HEALTH_WARM] = "Warm",
|
|
|
|
[POWER_SUPPLY_HEALTH_COOL] = "Cool",
|
|
|
|
[POWER_SUPPLY_HEALTH_HOT] = "Hot",
|
2017-05-16 05:21:15 +08:00
|
|
|
};
|
|
|
|
|
2020-05-05 04:29:29 +08:00
|
|
|
static const char * const POWER_SUPPLY_TECHNOLOGY_TEXT[] = {
|
2020-05-05 04:29:28 +08:00
|
|
|
[POWER_SUPPLY_TECHNOLOGY_UNKNOWN] = "Unknown",
|
|
|
|
[POWER_SUPPLY_TECHNOLOGY_NiMH] = "NiMH",
|
|
|
|
[POWER_SUPPLY_TECHNOLOGY_LION] = "Li-ion",
|
|
|
|
[POWER_SUPPLY_TECHNOLOGY_LIPO] = "Li-poly",
|
|
|
|
[POWER_SUPPLY_TECHNOLOGY_LiFe] = "LiFe",
|
|
|
|
[POWER_SUPPLY_TECHNOLOGY_NiCd] = "NiCd",
|
|
|
|
[POWER_SUPPLY_TECHNOLOGY_LiMn] = "LiMn",
|
2017-05-16 05:21:15 +08:00
|
|
|
};
|
|
|
|
|
2020-05-05 04:29:29 +08:00
|
|
|
static const char * const POWER_SUPPLY_CAPACITY_LEVEL_TEXT[] = {
|
2020-05-05 04:29:28 +08:00
|
|
|
[POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN] = "Unknown",
|
|
|
|
[POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL] = "Critical",
|
|
|
|
[POWER_SUPPLY_CAPACITY_LEVEL_LOW] = "Low",
|
|
|
|
[POWER_SUPPLY_CAPACITY_LEVEL_NORMAL] = "Normal",
|
|
|
|
[POWER_SUPPLY_CAPACITY_LEVEL_HIGH] = "High",
|
|
|
|
[POWER_SUPPLY_CAPACITY_LEVEL_FULL] = "Full",
|
2017-05-16 05:21:15 +08:00
|
|
|
};
|
|
|
|
|
2020-05-05 04:29:29 +08:00
|
|
|
static const char * const POWER_SUPPLY_SCOPE_TEXT[] = {
|
2020-05-05 04:29:28 +08:00
|
|
|
[POWER_SUPPLY_SCOPE_UNKNOWN] = "Unknown",
|
|
|
|
[POWER_SUPPLY_SCOPE_SYSTEM] = "System",
|
|
|
|
[POWER_SUPPLY_SCOPE_DEVICE] = "Device",
|
2017-05-16 05:21:15 +08:00
|
|
|
};
|
|
|
|
|
2020-05-05 04:29:27 +08:00
|
|
|
static struct power_supply_attr power_supply_attrs[] = {
|
|
|
|
/* Properties of type `int' */
|
2020-05-05 04:29:29 +08:00
|
|
|
POWER_SUPPLY_ENUM_ATTR(STATUS),
|
|
|
|
POWER_SUPPLY_ENUM_ATTR(CHARGE_TYPE),
|
|
|
|
POWER_SUPPLY_ENUM_ATTR(HEALTH),
|
2020-05-05 04:29:27 +08:00
|
|
|
POWER_SUPPLY_ATTR(PRESENT),
|
|
|
|
POWER_SUPPLY_ATTR(ONLINE),
|
|
|
|
POWER_SUPPLY_ATTR(AUTHENTIC),
|
2020-05-05 04:29:29 +08:00
|
|
|
POWER_SUPPLY_ENUM_ATTR(TECHNOLOGY),
|
2020-05-05 04:29:27 +08:00
|
|
|
POWER_SUPPLY_ATTR(CYCLE_COUNT),
|
|
|
|
POWER_SUPPLY_ATTR(VOLTAGE_MAX),
|
|
|
|
POWER_SUPPLY_ATTR(VOLTAGE_MIN),
|
|
|
|
POWER_SUPPLY_ATTR(VOLTAGE_MAX_DESIGN),
|
|
|
|
POWER_SUPPLY_ATTR(VOLTAGE_MIN_DESIGN),
|
|
|
|
POWER_SUPPLY_ATTR(VOLTAGE_NOW),
|
|
|
|
POWER_SUPPLY_ATTR(VOLTAGE_AVG),
|
|
|
|
POWER_SUPPLY_ATTR(VOLTAGE_OCV),
|
|
|
|
POWER_SUPPLY_ATTR(VOLTAGE_BOOT),
|
|
|
|
POWER_SUPPLY_ATTR(CURRENT_MAX),
|
|
|
|
POWER_SUPPLY_ATTR(CURRENT_NOW),
|
|
|
|
POWER_SUPPLY_ATTR(CURRENT_AVG),
|
|
|
|
POWER_SUPPLY_ATTR(CURRENT_BOOT),
|
|
|
|
POWER_SUPPLY_ATTR(POWER_NOW),
|
|
|
|
POWER_SUPPLY_ATTR(POWER_AVG),
|
|
|
|
POWER_SUPPLY_ATTR(CHARGE_FULL_DESIGN),
|
|
|
|
POWER_SUPPLY_ATTR(CHARGE_EMPTY_DESIGN),
|
|
|
|
POWER_SUPPLY_ATTR(CHARGE_FULL),
|
|
|
|
POWER_SUPPLY_ATTR(CHARGE_EMPTY),
|
|
|
|
POWER_SUPPLY_ATTR(CHARGE_NOW),
|
|
|
|
POWER_SUPPLY_ATTR(CHARGE_AVG),
|
|
|
|
POWER_SUPPLY_ATTR(CHARGE_COUNTER),
|
|
|
|
POWER_SUPPLY_ATTR(CONSTANT_CHARGE_CURRENT),
|
|
|
|
POWER_SUPPLY_ATTR(CONSTANT_CHARGE_CURRENT_MAX),
|
|
|
|
POWER_SUPPLY_ATTR(CONSTANT_CHARGE_VOLTAGE),
|
|
|
|
POWER_SUPPLY_ATTR(CONSTANT_CHARGE_VOLTAGE_MAX),
|
|
|
|
POWER_SUPPLY_ATTR(CHARGE_CONTROL_LIMIT),
|
|
|
|
POWER_SUPPLY_ATTR(CHARGE_CONTROL_LIMIT_MAX),
|
|
|
|
POWER_SUPPLY_ATTR(CHARGE_CONTROL_START_THRESHOLD),
|
|
|
|
POWER_SUPPLY_ATTR(CHARGE_CONTROL_END_THRESHOLD),
|
|
|
|
POWER_SUPPLY_ATTR(INPUT_CURRENT_LIMIT),
|
|
|
|
POWER_SUPPLY_ATTR(INPUT_VOLTAGE_LIMIT),
|
|
|
|
POWER_SUPPLY_ATTR(INPUT_POWER_LIMIT),
|
|
|
|
POWER_SUPPLY_ATTR(ENERGY_FULL_DESIGN),
|
|
|
|
POWER_SUPPLY_ATTR(ENERGY_EMPTY_DESIGN),
|
|
|
|
POWER_SUPPLY_ATTR(ENERGY_FULL),
|
|
|
|
POWER_SUPPLY_ATTR(ENERGY_EMPTY),
|
|
|
|
POWER_SUPPLY_ATTR(ENERGY_NOW),
|
|
|
|
POWER_SUPPLY_ATTR(ENERGY_AVG),
|
|
|
|
POWER_SUPPLY_ATTR(CAPACITY),
|
|
|
|
POWER_SUPPLY_ATTR(CAPACITY_ALERT_MIN),
|
|
|
|
POWER_SUPPLY_ATTR(CAPACITY_ALERT_MAX),
|
2020-05-14 02:55:58 +08:00
|
|
|
POWER_SUPPLY_ATTR(CAPACITY_ERROR_MARGIN),
|
2020-05-05 04:29:29 +08:00
|
|
|
POWER_SUPPLY_ENUM_ATTR(CAPACITY_LEVEL),
|
2020-05-05 04:29:27 +08:00
|
|
|
POWER_SUPPLY_ATTR(TEMP),
|
|
|
|
POWER_SUPPLY_ATTR(TEMP_MAX),
|
|
|
|
POWER_SUPPLY_ATTR(TEMP_MIN),
|
|
|
|
POWER_SUPPLY_ATTR(TEMP_ALERT_MIN),
|
|
|
|
POWER_SUPPLY_ATTR(TEMP_ALERT_MAX),
|
|
|
|
POWER_SUPPLY_ATTR(TEMP_AMBIENT),
|
|
|
|
POWER_SUPPLY_ATTR(TEMP_AMBIENT_ALERT_MIN),
|
|
|
|
POWER_SUPPLY_ATTR(TEMP_AMBIENT_ALERT_MAX),
|
|
|
|
POWER_SUPPLY_ATTR(TIME_TO_EMPTY_NOW),
|
|
|
|
POWER_SUPPLY_ATTR(TIME_TO_EMPTY_AVG),
|
|
|
|
POWER_SUPPLY_ATTR(TIME_TO_FULL_NOW),
|
|
|
|
POWER_SUPPLY_ATTR(TIME_TO_FULL_AVG),
|
2020-05-05 04:29:29 +08:00
|
|
|
POWER_SUPPLY_ENUM_ATTR(TYPE),
|
2020-05-05 04:29:27 +08:00
|
|
|
POWER_SUPPLY_ATTR(USB_TYPE),
|
2020-05-05 04:29:29 +08:00
|
|
|
POWER_SUPPLY_ENUM_ATTR(SCOPE),
|
2020-05-05 04:29:27 +08:00
|
|
|
POWER_SUPPLY_ATTR(PRECHARGE_CURRENT),
|
|
|
|
POWER_SUPPLY_ATTR(CHARGE_TERM_CURRENT),
|
|
|
|
POWER_SUPPLY_ATTR(CALIBRATE),
|
2020-05-14 02:55:59 +08:00
|
|
|
POWER_SUPPLY_ATTR(MANUFACTURE_YEAR),
|
|
|
|
POWER_SUPPLY_ATTR(MANUFACTURE_MONTH),
|
|
|
|
POWER_SUPPLY_ATTR(MANUFACTURE_DAY),
|
2020-05-05 04:29:27 +08:00
|
|
|
/* Properties of type `const char *' */
|
|
|
|
POWER_SUPPLY_ATTR(MODEL_NAME),
|
|
|
|
POWER_SUPPLY_ATTR(MANUFACTURER),
|
|
|
|
POWER_SUPPLY_ATTR(SERIAL_NUMBER),
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct attribute *
|
|
|
|
__power_supply_attrs[ARRAY_SIZE(power_supply_attrs) + 1];
|
|
|
|
|
2020-05-05 04:29:29 +08:00
|
|
|
static struct power_supply_attr *to_ps_attr(struct device_attribute *attr)
|
|
|
|
{
|
|
|
|
return container_of(attr, struct power_supply_attr, dev_attr);
|
|
|
|
}
|
|
|
|
|
2020-05-05 04:29:27 +08:00
|
|
|
static enum power_supply_property dev_attr_psp(struct device_attribute *attr)
|
|
|
|
{
|
2020-05-05 04:29:29 +08:00
|
|
|
return to_ps_attr(attr) - power_supply_attrs;
|
2020-05-05 04:29:27 +08:00
|
|
|
}
|
|
|
|
|
power: supply: Add 'usb_type' property and supporting code
This commit adds the 'usb_type' property to represent USB supplies
which can report a number of different types based on a connection
event.
Examples of this already exist in drivers whereby the existing 'type'
property is updated, based on an event, to represent what was
connected (e.g. USB, USB_DCP, USB_ACA, ...). Current implementations
however don't show all supported connectable types, so this knowledge
has to be exlicitly known for each driver that supports this.
The 'usb_type' property is intended to fill this void and show users
all possible USB types supported by a driver. The property, when read,
shows all available types for the driver, and the one currently chosen
is highlighted/bracketed. It is expected that the 'type' property
would then just show the top-level type 'USB', and this would be
static.
Currently the 'usb_type' enum contains all of the USB variant types
that exist for the 'type' enum at this time, and in addition has
SDP and PPS types. The mirroring is intentional so as to not impact
existing usage of the 'type' property.
Signed-off-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-04-23 22:10:59 +08:00
|
|
|
static ssize_t power_supply_show_usb_type(struct device *dev,
|
2020-04-04 04:20:32 +08:00
|
|
|
const struct power_supply_desc *desc,
|
power: supply: Add 'usb_type' property and supporting code
This commit adds the 'usb_type' property to represent USB supplies
which can report a number of different types based on a connection
event.
Examples of this already exist in drivers whereby the existing 'type'
property is updated, based on an event, to represent what was
connected (e.g. USB, USB_DCP, USB_ACA, ...). Current implementations
however don't show all supported connectable types, so this knowledge
has to be exlicitly known for each driver that supports this.
The 'usb_type' property is intended to fill this void and show users
all possible USB types supported by a driver. The property, when read,
shows all available types for the driver, and the one currently chosen
is highlighted/bracketed. It is expected that the 'type' property
would then just show the top-level type 'USB', and this would be
static.
Currently the 'usb_type' enum contains all of the USB variant types
that exist for the 'type' enum at this time, and in addition has
SDP and PPS types. The mirroring is intentional so as to not impact
existing usage of the 'type' property.
Signed-off-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-04-23 22:10:59 +08:00
|
|
|
union power_supply_propval *value,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
enum power_supply_usb_type usb_type;
|
|
|
|
ssize_t count = 0;
|
|
|
|
bool match = false;
|
|
|
|
int i;
|
|
|
|
|
2020-04-04 04:20:32 +08:00
|
|
|
for (i = 0; i < desc->num_usb_types; ++i) {
|
|
|
|
usb_type = desc->usb_types[i];
|
power: supply: Add 'usb_type' property and supporting code
This commit adds the 'usb_type' property to represent USB supplies
which can report a number of different types based on a connection
event.
Examples of this already exist in drivers whereby the existing 'type'
property is updated, based on an event, to represent what was
connected (e.g. USB, USB_DCP, USB_ACA, ...). Current implementations
however don't show all supported connectable types, so this knowledge
has to be exlicitly known for each driver that supports this.
The 'usb_type' property is intended to fill this void and show users
all possible USB types supported by a driver. The property, when read,
shows all available types for the driver, and the one currently chosen
is highlighted/bracketed. It is expected that the 'type' property
would then just show the top-level type 'USB', and this would be
static.
Currently the 'usb_type' enum contains all of the USB variant types
that exist for the 'type' enum at this time, and in addition has
SDP and PPS types. The mirroring is intentional so as to not impact
existing usage of the 'type' property.
Signed-off-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-04-23 22:10:59 +08:00
|
|
|
|
|
|
|
if (value->intval == usb_type) {
|
|
|
|
count += sprintf(buf + count, "[%s] ",
|
2020-05-05 04:29:29 +08:00
|
|
|
POWER_SUPPLY_USB_TYPE_TEXT[usb_type]);
|
power: supply: Add 'usb_type' property and supporting code
This commit adds the 'usb_type' property to represent USB supplies
which can report a number of different types based on a connection
event.
Examples of this already exist in drivers whereby the existing 'type'
property is updated, based on an event, to represent what was
connected (e.g. USB, USB_DCP, USB_ACA, ...). Current implementations
however don't show all supported connectable types, so this knowledge
has to be exlicitly known for each driver that supports this.
The 'usb_type' property is intended to fill this void and show users
all possible USB types supported by a driver. The property, when read,
shows all available types for the driver, and the one currently chosen
is highlighted/bracketed. It is expected that the 'type' property
would then just show the top-level type 'USB', and this would be
static.
Currently the 'usb_type' enum contains all of the USB variant types
that exist for the 'type' enum at this time, and in addition has
SDP and PPS types. The mirroring is intentional so as to not impact
existing usage of the 'type' property.
Signed-off-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-04-23 22:10:59 +08:00
|
|
|
match = true;
|
|
|
|
} else {
|
|
|
|
count += sprintf(buf + count, "%s ",
|
2020-05-05 04:29:29 +08:00
|
|
|
POWER_SUPPLY_USB_TYPE_TEXT[usb_type]);
|
power: supply: Add 'usb_type' property and supporting code
This commit adds the 'usb_type' property to represent USB supplies
which can report a number of different types based on a connection
event.
Examples of this already exist in drivers whereby the existing 'type'
property is updated, based on an event, to represent what was
connected (e.g. USB, USB_DCP, USB_ACA, ...). Current implementations
however don't show all supported connectable types, so this knowledge
has to be exlicitly known for each driver that supports this.
The 'usb_type' property is intended to fill this void and show users
all possible USB types supported by a driver. The property, when read,
shows all available types for the driver, and the one currently chosen
is highlighted/bracketed. It is expected that the 'type' property
would then just show the top-level type 'USB', and this would be
static.
Currently the 'usb_type' enum contains all of the USB variant types
that exist for the 'type' enum at this time, and in addition has
SDP and PPS types. The mirroring is intentional so as to not impact
existing usage of the 'type' property.
Signed-off-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-04-23 22:10:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!match) {
|
|
|
|
dev_warn(dev, "driver reporting unsupported connected type\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count)
|
|
|
|
buf[count - 1] = '\n';
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2007-05-04 04:27:45 +08:00
|
|
|
static ssize_t power_supply_show_property(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf) {
|
2018-03-21 23:54:53 +08:00
|
|
|
ssize_t ret;
|
2007-05-04 04:27:45 +08:00
|
|
|
struct power_supply *psy = dev_get_drvdata(dev);
|
2020-05-05 04:29:29 +08:00
|
|
|
struct power_supply_attr *ps_attr = to_ps_attr(attr);
|
2020-05-05 04:29:27 +08:00
|
|
|
enum power_supply_property psp = dev_attr_psp(attr);
|
2007-05-04 04:27:45 +08:00
|
|
|
union power_supply_propval value;
|
|
|
|
|
2018-03-21 23:54:53 +08:00
|
|
|
if (psp == POWER_SUPPLY_PROP_TYPE) {
|
2015-03-12 15:44:11 +08:00
|
|
|
value.intval = psy->desc->type;
|
2014-09-04 20:01:34 +08:00
|
|
|
} else {
|
2018-03-21 23:54:53 +08:00
|
|
|
ret = power_supply_get_property(psy, psp, &value);
|
2007-05-04 04:27:45 +08:00
|
|
|
|
2014-09-04 20:01:34 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
if (ret == -ENODATA)
|
|
|
|
dev_dbg(dev, "driver has no data for `%s' property\n",
|
|
|
|
attr->attr.name);
|
2016-06-22 23:45:52 +08:00
|
|
|
else if (ret != -ENODEV && ret != -EAGAIN)
|
2018-09-13 08:48:30 +08:00
|
|
|
dev_err_ratelimited(dev,
|
|
|
|
"driver failed to report `%s' property: %zd\n",
|
2014-09-04 20:01:34 +08:00
|
|
|
attr->attr.name, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2007-05-04 04:27:45 +08:00
|
|
|
}
|
|
|
|
|
2020-05-05 04:29:29 +08:00
|
|
|
if (ps_attr->text_values_len > 0 &&
|
|
|
|
value.intval < ps_attr->text_values_len && value.intval >= 0) {
|
|
|
|
return sprintf(buf, "%s\n", ps_attr->text_values[value.intval]);
|
|
|
|
}
|
|
|
|
|
2018-03-21 23:54:53 +08:00
|
|
|
switch (psp) {
|
2018-04-26 18:18:30 +08:00
|
|
|
case POWER_SUPPLY_PROP_USB_TYPE:
|
2020-04-04 04:20:32 +08:00
|
|
|
ret = power_supply_show_usb_type(dev, psy->desc,
|
2020-05-05 04:29:29 +08:00
|
|
|
&value, buf);
|
2018-03-21 23:54:53 +08:00
|
|
|
break;
|
|
|
|
case POWER_SUPPLY_PROP_MODEL_NAME ... POWER_SUPPLY_PROP_SERIAL_NUMBER:
|
|
|
|
ret = sprintf(buf, "%s\n", value.strval);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = sprintf(buf, "%d\n", value.intval);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2007-05-04 04:27:45 +08:00
|
|
|
}
|
|
|
|
|
2010-05-19 03:49:52 +08:00
|
|
|
static ssize_t power_supply_store_property(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count) {
|
|
|
|
ssize_t ret;
|
|
|
|
struct power_supply *psy = dev_get_drvdata(dev);
|
2020-05-05 04:29:29 +08:00
|
|
|
struct power_supply_attr *ps_attr = to_ps_attr(attr);
|
2020-05-05 04:29:27 +08:00
|
|
|
enum power_supply_property psp = dev_attr_psp(attr);
|
2010-05-19 03:49:52 +08:00
|
|
|
union power_supply_propval value;
|
|
|
|
|
2020-05-05 04:29:29 +08:00
|
|
|
ret = -EINVAL;
|
|
|
|
if (ps_attr->text_values_len > 0) {
|
|
|
|
ret = __sysfs_match_string(ps_attr->text_values,
|
|
|
|
ps_attr->text_values_len, buf);
|
2017-05-16 05:21:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If no match was found, then check to see if it is an integer.
|
|
|
|
* Integer values are valid for enums in addition to the text value.
|
|
|
|
*/
|
|
|
|
if (ret < 0) {
|
|
|
|
long long_val;
|
|
|
|
|
|
|
|
ret = kstrtol(buf, 10, &long_val);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = long_val;
|
|
|
|
}
|
2010-05-19 03:49:52 +08:00
|
|
|
|
2017-05-16 05:21:15 +08:00
|
|
|
value.intval = ret;
|
2010-05-19 03:49:52 +08:00
|
|
|
|
2018-03-21 23:54:53 +08:00
|
|
|
ret = power_supply_set_property(psy, psp, &value);
|
2010-05-19 03:49:52 +08:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2011-07-24 11:11:19 +08:00
|
|
|
static umode_t power_supply_attr_is_visible(struct kobject *kobj,
|
2010-05-19 03:49:51 +08:00
|
|
|
struct attribute *attr,
|
|
|
|
int attrno)
|
2007-05-04 04:27:45 +08:00
|
|
|
{
|
2020-06-12 14:55:54 +08:00
|
|
|
struct device *dev = kobj_to_dev(kobj);
|
2010-05-19 03:49:51 +08:00
|
|
|
struct power_supply *psy = dev_get_drvdata(dev);
|
2011-07-24 11:11:19 +08:00
|
|
|
umode_t mode = S_IRUSR | S_IRGRP | S_IROTH;
|
2010-05-19 03:49:51 +08:00
|
|
|
int i;
|
2007-05-04 04:27:45 +08:00
|
|
|
|
2020-05-05 04:29:27 +08:00
|
|
|
if (!power_supply_attrs[attrno].prop_name)
|
|
|
|
return 0;
|
|
|
|
|
2010-05-25 08:39:45 +08:00
|
|
|
if (attrno == POWER_SUPPLY_PROP_TYPE)
|
|
|
|
return mode;
|
|
|
|
|
2015-03-12 15:44:11 +08:00
|
|
|
for (i = 0; i < psy->desc->num_properties; i++) {
|
|
|
|
int property = psy->desc->properties[i];
|
2010-05-19 03:49:52 +08:00
|
|
|
|
|
|
|
if (property == attrno) {
|
2015-03-12 15:44:11 +08:00
|
|
|
if (psy->desc->property_is_writeable &&
|
2015-06-08 09:09:48 +08:00
|
|
|
psy->desc->property_is_writeable(psy, property) > 0)
|
2010-05-19 03:49:52 +08:00
|
|
|
mode |= S_IWUSR;
|
|
|
|
|
|
|
|
return mode;
|
|
|
|
}
|
2007-05-04 04:27:45 +08:00
|
|
|
}
|
|
|
|
|
2010-05-19 03:49:51 +08:00
|
|
|
return 0;
|
2007-05-04 04:27:45 +08:00
|
|
|
}
|
|
|
|
|
2021-01-14 04:32:43 +08:00
|
|
|
static const struct attribute_group power_supply_attr_group = {
|
2010-05-19 03:49:51 +08:00
|
|
|
.attrs = __power_supply_attrs,
|
|
|
|
.is_visible = power_supply_attr_is_visible,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct attribute_group *power_supply_attr_groups[] = {
|
|
|
|
&power_supply_attr_group,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2020-05-05 04:29:27 +08:00
|
|
|
static void str_to_lower(char *str)
|
2007-05-04 04:27:45 +08:00
|
|
|
{
|
2020-05-05 04:29:27 +08:00
|
|
|
while (*str) {
|
|
|
|
*str = tolower(*str);
|
|
|
|
str++;
|
|
|
|
}
|
2007-05-04 04:27:45 +08:00
|
|
|
}
|
|
|
|
|
2020-05-05 04:29:27 +08:00
|
|
|
void power_supply_init_attrs(struct device_type *dev_type)
|
2007-05-04 04:27:45 +08:00
|
|
|
{
|
2020-05-05 04:29:27 +08:00
|
|
|
int i;
|
2007-05-04 04:27:45 +08:00
|
|
|
|
2020-05-05 04:29:27 +08:00
|
|
|
dev_type->groups = power_supply_attr_groups;
|
2007-05-04 04:27:45 +08:00
|
|
|
|
2020-05-05 04:29:27 +08:00
|
|
|
for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++) {
|
|
|
|
struct device_attribute *attr;
|
2007-05-04 04:27:45 +08:00
|
|
|
|
2020-05-05 04:29:27 +08:00
|
|
|
if (!power_supply_attrs[i].prop_name) {
|
2020-12-05 09:25:32 +08:00
|
|
|
pr_warn("%s: Property %d skipped because it is missing from power_supply_attrs\n",
|
2020-05-05 04:29:27 +08:00
|
|
|
__func__, i);
|
|
|
|
sprintf(power_supply_attrs[i].attr_name, "_err_%d", i);
|
|
|
|
} else {
|
|
|
|
str_to_lower(power_supply_attrs[i].attr_name);
|
|
|
|
}
|
2007-05-04 04:27:45 +08:00
|
|
|
|
2020-05-05 04:29:27 +08:00
|
|
|
attr = &power_supply_attrs[i].dev_attr;
|
2007-05-04 04:27:45 +08:00
|
|
|
|
2020-05-05 04:29:27 +08:00
|
|
|
attr->attr.name = power_supply_attrs[i].attr_name;
|
|
|
|
attr->show = power_supply_show_property;
|
|
|
|
attr->store = power_supply_store_property;
|
|
|
|
__power_supply_attrs[i] = &attr->attr;
|
|
|
|
}
|
2007-05-04 04:27:45 +08:00
|
|
|
}
|
|
|
|
|
2020-05-05 04:29:30 +08:00
|
|
|
static int add_prop_uevent(struct device *dev, struct kobj_uevent_env *env,
|
|
|
|
enum power_supply_property prop, char *prop_buf)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
struct power_supply_attr *pwr_attr;
|
|
|
|
struct device_attribute *dev_attr;
|
|
|
|
char *line;
|
|
|
|
|
|
|
|
pwr_attr = &power_supply_attrs[prop];
|
|
|
|
dev_attr = &pwr_attr->dev_attr;
|
|
|
|
|
|
|
|
ret = power_supply_show_property(dev, dev_attr, prop_buf);
|
|
|
|
if (ret == -ENODEV || ret == -ENODATA) {
|
|
|
|
/*
|
|
|
|
* When a battery is absent, we expect -ENODEV. Don't abort;
|
|
|
|
* send the uevent with at least the the PRESENT=0 property
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
line = strchr(prop_buf, '\n');
|
|
|
|
if (line)
|
|
|
|
*line = 0;
|
|
|
|
|
|
|
|
return add_uevent_var(env, "POWER_SUPPLY_%s=%s",
|
|
|
|
pwr_attr->prop_name, prop_buf);
|
|
|
|
}
|
|
|
|
|
2007-08-14 21:15:12 +08:00
|
|
|
int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env)
|
2007-05-04 04:27:45 +08:00
|
|
|
{
|
|
|
|
struct power_supply *psy = dev_get_drvdata(dev);
|
2007-08-14 21:15:12 +08:00
|
|
|
int ret = 0, j;
|
2007-05-04 04:27:45 +08:00
|
|
|
char *prop_buf;
|
|
|
|
|
2015-03-12 15:44:11 +08:00
|
|
|
if (!psy || !psy->desc) {
|
2007-05-04 04:27:45 +08:00
|
|
|
dev_dbg(dev, "No power supply yet\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-03-12 15:44:11 +08:00
|
|
|
ret = add_uevent_var(env, "POWER_SUPPLY_NAME=%s", psy->desc->name);
|
2007-05-04 04:27:45 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
prop_buf = (char *)get_zeroed_page(GFP_KERNEL);
|
|
|
|
if (!prop_buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2020-05-05 04:29:30 +08:00
|
|
|
ret = add_prop_uevent(dev, env, POWER_SUPPLY_PROP_TYPE, prop_buf);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
2007-05-04 04:27:45 +08:00
|
|
|
|
2020-05-05 04:29:30 +08:00
|
|
|
for (j = 0; j < psy->desc->num_properties; j++) {
|
|
|
|
ret = add_prop_uevent(dev, env, psy->desc->properties[j],
|
|
|
|
prop_buf);
|
2007-05-04 04:27:45 +08:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
free_page((unsigned long)prop_buf);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|