cregit-Linux how code gets into the kernel

Release 4.10 drivers/acpi/ac.c

Directory: drivers/acpi
/*
 *  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);


static const struct acpi_device_id ac_device_ids[] = {
	{"ACPI0003", 0},
	{"", 0},
};
MODULE_DEVICE_TABLE(acpi, ac_device_ids);

#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

PersonTokensPropCommitsCommitProp
andy groverandy grover4962.82%120.00%
guenter roeckguenter roeck1417.95%120.00%
lan tianyulan tianyu67.69%120.00%
thomas renningerthomas renninger56.41%120.00%
patrick mochelpatrick mochel45.13%120.00%
Total78100.00%5100.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

PersonTokensPropCommitsCommitProp
rui zhangrui zhang76100.00%1100.00%
Total76100.00%1100.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

PersonTokensPropCommitsCommitProp
lan tianyulan tianyu100100.00%1100.00%
Total100100.00%1100.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

PersonTokensPropCommitsCommitProp
lan tianyulan tianyu29100.00%1100.00%
Total29100.00%1100.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

PersonTokensPropCommitsCommitProp
lan tianyulan tianyu104100.00%1100.00%
Total104100.00%1100.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

PersonTokensPropCommitsCommitProp
lan tianyulan tianyu58100.00%1100.00%
Total58100.00%1100.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

PersonTokensPropCommitsCommitProp
andy groverandy grover3224.81%17.69%
rui zhangrui zhang1813.95%17.69%
lan tianyulan tianyu1511.63%215.38%
len brownlen brown1310.08%215.38%
mark langsdorfmark langsdorf1310.08%17.69%
guenter roeckguenter roeck129.30%17.69%
alexey starikovskiyalexey starikovskiy129.30%17.69%
christian lupienchristian lupien64.65%17.69%
kay sieverskay sievers43.10%17.69%
patrick mochelpatrick mochel21.55%17.69%
krzysztof kozlowskikrzysztof kozlowski21.55%17.69%
Total129100.00%13100.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

PersonTokensPropCommitsCommitProp
alexander mezinalexander mezin74100.00%1100.00%
Total74100.00%1100.00%


static int thinkpad_e530_quirk(const struct dmi_system_id *d) { ac_sleep_before_get_state_ms = 1000; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
lan tianyulan tianyu19100.00%1100.00%
Total19100.00%1100.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

PersonTokensPropCommitsCommitProp
andy groverandy grover9834.51%15.88%
alexey starikovskiyalexey starikovskiy5218.31%211.76%
lan tianyulan tianyu4315.14%317.65%
krzysztof kozlowskikrzysztof kozlowski4114.44%211.76%
guenter roeckguenter roeck207.04%15.88%
alexander mezinalexander mezin165.63%15.88%
patrick mochelpatrick mochel62.11%15.88%
andrew mortonandrew morton20.70%15.88%
len brownlen brown20.70%211.76%
rui zhangrui zhang20.70%15.88%
burman yanburman yan10.35%15.88%
pavel machekpavel machek10.35%15.88%
Total284100.00%17100.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

PersonTokensPropCommitsCommitProp
alexey starikovskiyalexey starikovskiy6877.27%120.00%
rafael j. wysockirafael j. wysocki1517.05%120.00%
guenter roeckguenter roeck22.27%120.00%
krzysztof kozlowskikrzysztof kozlowski22.27%120.00%
andy groverandy grover11.14%120.00%
Total88100.00%5100.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

PersonTokensPropCommitsCommitProp
andy groverandy grover3041.10%114.29%
guenter roeckguenter roeck1317.81%114.29%
lan tianyulan tianyu1013.70%114.29%
alexander mezinalexander mezin810.96%114.29%
alexey starikovskiyalexey starikovskiy79.59%114.29%
patrick mochelpatrick mochel45.48%114.29%
len brownlen brown11.37%114.29%
Total73100.00%7100.00%


static int __init acpi_ac_init(void) { int result; if (acpi_disabled) 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

PersonTokensPropCommitsCommitProp
lan tianyulan tianyu3143.06%114.29%
andy groverandy grover2737.50%228.57%
pavel machekpavel machek811.11%114.29%
patrick mochelpatrick mochel45.56%114.29%
len brownlen brown11.39%114.29%
guenter roeckguenter roeck11.39%114.29%
Total72100.00%7100.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

PersonTokensPropCommitsCommitProp
andy groverandy grover1352.00%125.00%
lan tianyulan tianyu1040.00%125.00%
guenter roeckguenter roeck14.00%125.00%
len brownlen brown14.00%125.00%
Total25100.00%4100.00%

module_init(acpi_ac_init); module_exit(acpi_ac_exit);

Overall Contributors

PersonTokensPropCommitsCommitProp
lan tianyulan tianyu57734.84%49.52%
andy groverandy grover30418.36%37.14%
guenter roeckguenter roeck20612.44%12.38%
alexey starikovskiyalexey starikovskiy1529.18%24.76%
rui zhangrui zhang1126.76%37.14%
alexander mezinalexander mezin1056.34%12.38%
krzysztof kozlowskikrzysztof kozlowski513.08%24.76%
patrick mochelpatrick mochel492.96%37.14%
len brownlen brown251.51%614.29%
rafael j. wysockirafael j. wysocki201.21%24.76%
mark langsdorfmark langsdorf130.79%12.38%
pavel machekpavel machek90.54%24.76%
christian lupienchristian lupien60.36%12.38%
shuah khanshuah khan60.36%12.38%
thomas renningerthomas renninger50.30%12.38%
kay sieverskay sievers40.24%12.38%
tejun heotejun heo30.18%12.38%
aristeu sergio rozanski filhoaristeu sergio rozanski filho20.12%12.38%
andrew mortonandrew morton20.12%12.38%
mathias krausemathias krause10.06%12.38%
burman yanburman yan10.06%12.38%
jarkko nikulajarkko nikula10.06%12.38%
matthew wilcoxmatthew wilcox10.06%12.38%
lv zhenglv zheng10.06%12.38%
Total1656100.00%42100.00%
Directory: drivers/acpi
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.