Release 4.14 drivers/acpi/ac.c
/*
* acpi_ac.c - ACPI AC Adapter Driver ($Revision: 27 $)
*
* Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
* Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/dmi.h>
#include <linux/delay.h>
#ifdef CONFIG_ACPI_PROCFS_POWER
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#endif
#include <linux/platform_device.h>
#include <linux/power_supply.h>
#include <linux/acpi.h>
#include "battery.h"
#define PREFIX "ACPI: "
#define ACPI_AC_CLASS "ac_adapter"
#define ACPI_AC_DEVICE_NAME "AC Adapter"
#define ACPI_AC_FILE_STATE "state"
#define ACPI_AC_NOTIFY_STATUS 0x80
#define ACPI_AC_STATUS_OFFLINE 0x00
#define ACPI_AC_STATUS_ONLINE 0x01
#define ACPI_AC_STATUS_UNKNOWN 0xFF
#define _COMPONENT ACPI_AC_COMPONENT
ACPI_MODULE_NAME("ac");
MODULE_AUTHOR("Paul Diefenbaugh");
MODULE_DESCRIPTION("ACPI AC Adapter Driver");
MODULE_LICENSE("GPL");
static int acpi_ac_add(struct acpi_device *device);
static int acpi_ac_remove(struct acpi_device *device);
static void acpi_ac_notify(struct acpi_device *device, u32 event);
struct acpi_ac_bl {
const char *hid;
int hrv;
};
static const struct acpi_device_id ac_device_ids[] = {
{"ACPI0003", 0},
{"", 0},
};
MODULE_DEVICE_TABLE(acpi, ac_device_ids);
/* Lists of PMIC ACPI HIDs with an (often better) native charger driver */
static const struct acpi_ac_bl acpi_ac_blacklist[] = {
{ "INT33F4", -1 }, /* X-Powers AXP288 PMIC */
{ "INT34D3", 3 }, /* Intel Cherrytrail Whiskey Cove PMIC */
};
#ifdef CONFIG_PM_SLEEP
static int acpi_ac_resume(struct device *dev);
#endif
static SIMPLE_DEV_PM_OPS(acpi_ac_pm, NULL, acpi_ac_resume);
#ifdef CONFIG_ACPI_PROCFS_POWER
extern struct proc_dir_entry *acpi_lock_ac_dir(void);
extern void *acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir);
static int acpi_ac_open_fs(struct inode *inode, struct file *file);
#endif
static int ac_sleep_before_get_state_ms;
static struct acpi_driver acpi_ac_driver = {
.name = "ac",
.class = ACPI_AC_CLASS,
.ids = ac_device_ids,
.flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
.ops = {
.add = acpi_ac_add,
.remove = acpi_ac_remove,
.notify = acpi_ac_notify,
},
.drv.pm = &acpi_ac_pm,
};
struct acpi_ac {
struct power_supply *charger;
struct power_supply_desc charger_desc;
struct acpi_device * device;
unsigned long long state;
struct notifier_block battery_nb;
};
#define to_acpi_ac(x) power_supply_get_drvdata(x)
#ifdef CONFIG_ACPI_PROCFS_POWER
static const struct file_operations acpi_ac_fops = {
.owner = THIS_MODULE,
.open = acpi_ac_open_fs,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
#endif
/* --------------------------------------------------------------------------
AC Adapter Management
-------------------------------------------------------------------------- */
static int acpi_ac_get_state(struct acpi_ac *ac)
{
acpi_status status = AE_OK;
if (!ac)
return -EINVAL;
status = acpi_evaluate_integer(ac->device->handle, "_PSR", NULL,
&ac->state);
if (ACPI_FAILURE(status)) {
ACPI_EXCEPTION((AE_INFO, status,
"Error reading AC Adapter state"));
ac->state = ACPI_AC_STATUS_UNKNOWN;
return -ENODEV;
}
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Andy Grover | 49 | 62.82% | 1 | 20.00% |
Guenter Roeck | 14 | 17.95% | 1 | 20.00% |
Lan Tianyu | 6 | 7.69% | 1 | 20.00% |
Thomas Renninger | 5 | 6.41% | 1 | 20.00% |
Patrick Mochel | 4 | 5.13% | 1 | 20.00% |
Total | 78 | 100.00% | 5 | 100.00% |
/* --------------------------------------------------------------------------
sysfs I/F
-------------------------------------------------------------------------- */
static int get_ac_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct acpi_ac *ac = to_acpi_ac(psy);
if (!ac)
return -ENODEV;
if (acpi_ac_get_state(ac))
return -ENODEV;
switch (psp) {
case POWER_SUPPLY_PROP_ONLINE:
val->intval = ac->state;
break;
default:
return -EINVAL;
}
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Rui Zhang | 76 | 100.00% | 1 | 100.00% |
Total | 76 | 100.00% | 1 | 100.00% |
static enum power_supply_property ac_props[] = {
POWER_SUPPLY_PROP_ONLINE,
};
#ifdef CONFIG_ACPI_PROCFS_POWER
/* --------------------------------------------------------------------------
FS Interface (/proc)
-------------------------------------------------------------------------- */
static struct proc_dir_entry *acpi_ac_dir;
static int acpi_ac_seq_show(struct seq_file *seq, void *offset)
{
struct acpi_ac *ac = seq->private;
if (!ac)
return 0;
if (acpi_ac_get_state(ac)) {
seq_puts(seq, "ERROR: Unable to read AC Adapter state\n");
return 0;
}
seq_puts(seq, "state: ");
switch (ac->state) {
case ACPI_AC_STATUS_OFFLINE:
seq_puts(seq, "off-line\n");
break;
case ACPI_AC_STATUS_ONLINE:
seq_puts(seq, "on-line\n");
break;
default:
seq_puts(seq, "unknown\n");
break;
}
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Lan Tianyu | 100 | 100.00% | 1 | 100.00% |
Total | 100 | 100.00% | 1 | 100.00% |
static int acpi_ac_open_fs(struct inode *inode, struct file *file)
{
return single_open(file, acpi_ac_seq_show, PDE_DATA(inode));
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Lan Tianyu | 29 | 100.00% | 1 | 100.00% |
Total | 29 | 100.00% | 1 | 100.00% |
static int acpi_ac_add_fs(struct acpi_ac *ac)
{
struct proc_dir_entry *entry = NULL;
printk(KERN_WARNING PREFIX "Deprecated procfs I/F for AC is loaded,"
" please retry with CONFIG_ACPI_PROCFS_POWER cleared\n");
if (!acpi_device_dir(ac->device)) {
acpi_device_dir(ac->device) =
proc_mkdir(acpi_device_bid(ac->device), acpi_ac_dir);
if (!acpi_device_dir(ac->device))
return -ENODEV;
}
/* 'state' [R] */
entry = proc_create_data(ACPI_AC_FILE_STATE,
S_IRUGO, acpi_device_dir(ac->device),
&acpi_ac_fops, ac);
if (!entry)
return -ENODEV;
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Lan Tianyu | 104 | 100.00% | 1 | 100.00% |
Total | 104 | 100.00% | 1 | 100.00% |
static int acpi_ac_remove_fs(struct acpi_ac *ac)
{
if (acpi_device_dir(ac->device)) {
remove_proc_entry(ACPI_AC_FILE_STATE,
acpi_device_dir(ac->device));
remove_proc_entry(acpi_device_bid(ac->device), acpi_ac_dir);
acpi_device_dir(ac->device) = NULL;
}
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Lan Tianyu | 58 | 100.00% | 1 | 100.00% |
Total | 58 | 100.00% | 1 | 100.00% |
#endif
/* --------------------------------------------------------------------------
Driver Model
-------------------------------------------------------------------------- */
static void acpi_ac_notify(struct acpi_device *device, u32 event)
{
struct acpi_ac *ac = acpi_driver_data(device);
if (!ac)
return;
switch (event) {
default:
ACPI_DEBUG_PRINT((ACPI_DB_INFO,
"Unsupported event [0x%x]\n", event));
case ACPI_AC_NOTIFY_STATUS:
case ACPI_NOTIFY_BUS_CHECK:
case ACPI_NOTIFY_DEVICE_CHECK:
/*
* A buggy BIOS may notify AC first and then sleep for
* a specific time before doing actual operations in the
* EC event handler (_Qxx). This will cause the AC state
* reported by the ACPI event to be incorrect, so wait for a
* specific time for the EC event handler to make progress.
*/
if (ac_sleep_before_get_state_ms > 0)
msleep(ac_sleep_before_get_state_ms);
acpi_ac_get_state(ac);
acpi_bus_generate_netlink_event(device->pnp.device_class,
dev_name(&device->dev), event,
(u32) ac->state);
acpi_notifier_call_chain(device, event, (u32) ac->state);
kobject_uevent(&ac->charger->dev.kobj, KOBJ_CHANGE);
}
return;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Andy Grover | 32 | 24.81% | 1 | 7.69% |
Rui Zhang | 18 | 13.95% | 1 | 7.69% |
Lan Tianyu | 15 | 11.63% | 2 | 15.38% |
Len Brown | 13 | 10.08% | 2 | 15.38% |
Langsdorf, Mark | 13 | 10.08% | 1 | 7.69% |
Guenter Roeck | 12 | 9.30% | 1 | 7.69% |
Alexey Y. Starikovskiy | 12 | 9.30% | 1 | 7.69% |
Christian Lupien | 6 | 4.65% | 1 | 7.69% |
Kay Sievers | 4 | 3.10% | 1 | 7.69% |
Patrick Mochel | 2 | 1.55% | 1 | 7.69% |
Krzysztof Kozlowski | 2 | 1.55% | 1 | 7.69% |
Total | 129 | 100.00% | 13 | 100.00% |
static int acpi_ac_battery_notify(struct notifier_block *nb,
unsigned long action, void *data)
{
struct acpi_ac *ac = container_of(nb, struct acpi_ac, battery_nb);
struct acpi_bus_event *event = (struct acpi_bus_event *)data;
/*
* On HP Pavilion dv6-6179er AC status notifications aren't triggered
* when adapter is plugged/unplugged. However, battery status
* notifcations are triggered when battery starts charging or
* discharging. Re-reading AC status triggers lost AC notifications,
* if AC status has changed.
*/
if (strcmp(event->device_class, ACPI_BATTERY_CLASS) == 0 &&
event->type == ACPI_BATTERY_NOTIFY_STATUS)
acpi_ac_get_state(ac);
return NOTIFY_OK;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Alexander Mezin | 74 | 100.00% | 1 | 100.00% |
Total | 74 | 100.00% | 1 | 100.00% |
static int thinkpad_e530_quirk(const struct dmi_system_id *d)
{
ac_sleep_before_get_state_ms = 1000;
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Lan Tianyu | 19 | 100.00% | 1 | 100.00% |
Total | 19 | 100.00% | 1 | 100.00% |
static const struct dmi_system_id ac_dmi_table[] = {
{
.callback = thinkpad_e530_quirk,
.ident = "thinkpad e530",
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
DMI_MATCH(DMI_PRODUCT_NAME, "32597CG"),
},
},
{},
};
static int acpi_ac_add(struct acpi_device *device)
{
struct power_supply_config psy_cfg = {};
int result = 0;
struct acpi_ac *ac = NULL;
if (!device)
return -EINVAL;
ac = kzalloc(sizeof(struct acpi_ac), GFP_KERNEL);
if (!ac)
return -ENOMEM;
ac->device = device;
strcpy(acpi_device_name(device), ACPI_AC_DEVICE_NAME);
strcpy(acpi_device_class(device), ACPI_AC_CLASS);
device->driver_data = ac;
result = acpi_ac_get_state(ac);
if (result)
goto end;
psy_cfg.drv_data = ac;
ac->charger_desc.name = acpi_device_bid(device);
#ifdef CONFIG_ACPI_PROCFS_POWER
result = acpi_ac_add_fs(ac);
if (result)
goto end;
#endif
ac->charger_desc.type = POWER_SUPPLY_TYPE_MAINS;
ac->charger_desc.properties = ac_props;
ac->charger_desc.num_properties = ARRAY_SIZE(ac_props);
ac->charger_desc.get_property = get_ac_property;
ac->charger = power_supply_register(&ac->device->dev,
&ac->charger_desc, &psy_cfg);
if (IS_ERR(ac->charger)) {
result = PTR_ERR(ac->charger);
goto end;
}
printk(KERN_INFO PREFIX "%s [%s] (%s)\n",
acpi_device_name(device), acpi_device_bid(device),
ac->state ? "on-line" : "off-line");
ac->battery_nb.notifier_call = acpi_ac_battery_notify;
register_acpi_notifier(&ac->battery_nb);
end:
if (result) {
#ifdef CONFIG_ACPI_PROCFS_POWER
acpi_ac_remove_fs(ac);
#endif
kfree(ac);
}
dmi_check_system(ac_dmi_table);
return result;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Andy Grover | 100 | 35.21% | 1 | 6.25% |
Alexey Y. Starikovskiy | 52 | 18.31% | 2 | 12.50% |
Lan Tianyu | 43 | 15.14% | 3 | 18.75% |
Krzysztof Kozlowski | 41 | 14.44% | 2 | 12.50% |
Guenter Roeck | 20 | 7.04% | 1 | 6.25% |
Alexander Mezin | 16 | 5.63% | 1 | 6.25% |
Patrick Mochel | 6 | 2.11% | 1 | 6.25% |
Len Brown | 2 | 0.70% | 2 | 12.50% |
Andrew Morton | 2 | 0.70% | 1 | 6.25% |
Rui Zhang | 1 | 0.35% | 1 | 6.25% |
Burman Yan | 1 | 0.35% | 1 | 6.25% |
Total | 284 | 100.00% | 16 | 100.00% |
#ifdef CONFIG_PM_SLEEP
static int acpi_ac_resume(struct device *dev)
{
struct acpi_ac *ac;
unsigned old_state;
if (!dev)
return -EINVAL;
ac = acpi_driver_data(to_acpi_device(dev));
if (!ac)
return -EINVAL;
old_state = ac->state;
if (acpi_ac_get_state(ac))
return 0;
if (old_state != ac->state)
kobject_uevent(&ac->charger->dev.kobj, KOBJ_CHANGE);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Alexey Y. Starikovskiy | 68 | 77.27% | 1 | 20.00% |
Rafael J. Wysocki | 15 | 17.05% | 1 | 20.00% |
Guenter Roeck | 2 | 2.27% | 1 | 20.00% |
Krzysztof Kozlowski | 2 | 2.27% | 1 | 20.00% |
Andy Grover | 1 | 1.14% | 1 | 20.00% |
Total | 88 | 100.00% | 5 | 100.00% |
#else
#define acpi_ac_resume NULL
#endif
static int acpi_ac_remove(struct acpi_device *device)
{
struct acpi_ac *ac = NULL;
if (!device || !acpi_driver_data(device))
return -EINVAL;
ac = acpi_driver_data(device);
power_supply_unregister(ac->charger);
unregister_acpi_notifier(&ac->battery_nb);
#ifdef CONFIG_ACPI_PROCFS_POWER
acpi_ac_remove_fs(ac);
#endif
kfree(ac);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Andy Grover | 30 | 41.10% | 1 | 14.29% |
Guenter Roeck | 13 | 17.81% | 1 | 14.29% |
Lan Tianyu | 10 | 13.70% | 1 | 14.29% |
Alexander Mezin | 8 | 10.96% | 1 | 14.29% |
Alexey Y. Starikovskiy | 7 | 9.59% | 1 | 14.29% |
Patrick Mochel | 4 | 5.48% | 1 | 14.29% |
Len Brown | 1 | 1.37% | 1 | 14.29% |
Total | 73 | 100.00% | 7 | 100.00% |
static int __init acpi_ac_init(void)
{
unsigned int i;
int result;
if (acpi_disabled)
return -ENODEV;
for (i = 0; i < ARRAY_SIZE(acpi_ac_blacklist); i++)
if (acpi_dev_present(acpi_ac_blacklist[i].hid, "1",
acpi_ac_blacklist[i].hrv)) {
pr_info(PREFIX "AC: found native %s PMIC, not loading\n",
acpi_ac_blacklist[i].hid);
return -ENODEV;
}
#ifdef CONFIG_ACPI_PROCFS_POWER
acpi_ac_dir = acpi_lock_ac_dir();
if (!acpi_ac_dir)
return -ENODEV;
#endif
result = acpi_bus_register_driver(&acpi_ac_driver);
if (result < 0) {
#ifdef CONFIG_ACPI_PROCFS_POWER
acpi_unlock_ac_dir(acpi_ac_dir);
#endif
return -ENODEV;
}
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Hans de Goede | 60 | 45.45% | 1 | 12.50% |
Lan Tianyu | 31 | 23.48% | 1 | 12.50% |
Andy Grover | 27 | 20.45% | 2 | 25.00% |
Pavel Machek | 8 | 6.06% | 1 | 12.50% |
Patrick Mochel | 4 | 3.03% | 1 | 12.50% |
Len Brown | 1 | 0.76% | 1 | 12.50% |
Guenter Roeck | 1 | 0.76% | 1 | 12.50% |
Total | 132 | 100.00% | 8 | 100.00% |
static void __exit acpi_ac_exit(void)
{
acpi_bus_unregister_driver(&acpi_ac_driver);
#ifdef CONFIG_ACPI_PROCFS_POWER
acpi_unlock_ac_dir(acpi_ac_dir);
#endif
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Andy Grover | 13 | 52.00% | 1 | 25.00% |
Lan Tianyu | 10 | 40.00% | 1 | 25.00% |
Len Brown | 1 | 4.00% | 1 | 25.00% |
Guenter Roeck | 1 | 4.00% | 1 | 25.00% |
Total | 25 | 100.00% | 4 | 100.00% |
module_init(acpi_ac_init);
module_exit(acpi_ac_exit);
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Lan Tianyu | 577 | 32.88% | 4 | 9.52% |
Andy Grover | 306 | 17.44% | 3 | 7.14% |
Guenter Roeck | 206 | 11.74% | 1 | 2.38% |
Alexey Y. Starikovskiy | 152 | 8.66% | 2 | 4.76% |
Rui Zhang | 111 | 6.32% | 3 | 7.14% |
Alexander Mezin | 105 | 5.98% | 1 | 2.38% |
Hans de Goede | 99 | 5.64% | 1 | 2.38% |
Krzysztof Kozlowski | 51 | 2.91% | 2 | 4.76% |
Patrick Mochel | 49 | 2.79% | 3 | 7.14% |
Len Brown | 25 | 1.42% | 6 | 14.29% |
Rafael J. Wysocki | 20 | 1.14% | 2 | 4.76% |
Langsdorf, Mark | 13 | 0.74% | 1 | 2.38% |
Pavel Machek | 8 | 0.46% | 1 | 2.38% |
Shuah Khan | 6 | 0.34% | 1 | 2.38% |
Christian Lupien | 6 | 0.34% | 1 | 2.38% |
Thomas Renninger | 5 | 0.28% | 1 | 2.38% |
Kay Sievers | 4 | 0.23% | 1 | 2.38% |
Tejun Heo | 3 | 0.17% | 1 | 2.38% |
Aristeu Sergio Rozanski Filho | 2 | 0.11% | 1 | 2.38% |
Andrew Morton | 2 | 0.11% | 1 | 2.38% |
Lv Zheng | 1 | 0.06% | 1 | 2.38% |
Jarkko Nikula | 1 | 0.06% | 1 | 2.38% |
Burman Yan | 1 | 0.06% | 1 | 2.38% |
Matthew Wilcox | 1 | 0.06% | 1 | 2.38% |
Mathias Krause | 1 | 0.06% | 1 | 2.38% |
Total | 1755 | 100.00% | 42 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.