mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-04-21 21:53:57 +00:00
ACPI / AC: convert ACPI ac driver to platform bus
Signed-off-by: Zhang Rui <rui.zhang@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
parent
4a10c2ac2f
commit
cc8ef52707
2 changed files with 81 additions and 83 deletions
|
@ -34,6 +34,7 @@
|
||||||
#include <linux/proc_fs.h>
|
#include <linux/proc_fs.h>
|
||||||
#include <linux/seq_file.h>
|
#include <linux/seq_file.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <linux/platform_device.h>
|
||||||
#include <linux/power_supply.h>
|
#include <linux/power_supply.h>
|
||||||
#include <acpi/acpi_bus.h>
|
#include <acpi/acpi_bus.h>
|
||||||
#include <acpi/acpi_drivers.h>
|
#include <acpi/acpi_drivers.h>
|
||||||
|
@ -61,39 +62,12 @@ 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);
|
static int acpi_ac_open_fs(struct inode *inode, struct file *file);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
static int ac_sleep_before_get_state_ms;
|
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 acpi_ac {
|
||||||
struct power_supply charger;
|
struct power_supply charger;
|
||||||
struct acpi_device * device;
|
struct acpi_device *adev;
|
||||||
|
struct platform_device *pdev;
|
||||||
unsigned long long state;
|
unsigned long long state;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -115,15 +89,13 @@ static const struct file_operations acpi_ac_fops = {
|
||||||
|
|
||||||
static int acpi_ac_get_state(struct acpi_ac *ac)
|
static int acpi_ac_get_state(struct acpi_ac *ac)
|
||||||
{
|
{
|
||||||
acpi_status status = AE_OK;
|
acpi_status status;
|
||||||
|
|
||||||
|
status = acpi_evaluate_integer(ac->adev->handle, "_PSR", NULL,
|
||||||
if (!ac)
|
&ac->state);
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
status = acpi_evaluate_integer(ac->device->handle, "_PSR", NULL, &ac->state);
|
|
||||||
if (ACPI_FAILURE(status)) {
|
if (ACPI_FAILURE(status)) {
|
||||||
ACPI_EXCEPTION((AE_INFO, status, "Error reading AC Adapter state"));
|
ACPI_EXCEPTION((AE_INFO, status,
|
||||||
|
"Error reading AC Adapter state"));
|
||||||
ac->state = ACPI_AC_STATUS_UNKNOWN;
|
ac->state = ACPI_AC_STATUS_UNKNOWN;
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
@ -201,36 +173,36 @@ static int acpi_ac_open_fs(struct inode *inode, struct file *file)
|
||||||
return single_open(file, acpi_ac_seq_show, PDE_DATA(inode));
|
return single_open(file, acpi_ac_seq_show, PDE_DATA(inode));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int acpi_ac_add_fs(struct acpi_device *device)
|
static int acpi_ac_add_fs(struct acpi_ac *ac)
|
||||||
{
|
{
|
||||||
struct proc_dir_entry *entry = NULL;
|
struct proc_dir_entry *entry = NULL;
|
||||||
|
|
||||||
printk(KERN_WARNING PREFIX "Deprecated procfs I/F for AC is loaded,"
|
printk(KERN_WARNING PREFIX "Deprecated procfs I/F for AC is loaded,"
|
||||||
" please retry with CONFIG_ACPI_PROCFS_POWER cleared\n");
|
" please retry with CONFIG_ACPI_PROCFS_POWER cleared\n");
|
||||||
if (!acpi_device_dir(device)) {
|
if (!acpi_device_dir(ac->adev)) {
|
||||||
acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
|
acpi_device_dir(ac->adev) =
|
||||||
acpi_ac_dir);
|
proc_mkdir(acpi_device_bid(ac->adev), acpi_ac_dir);
|
||||||
if (!acpi_device_dir(device))
|
if (!acpi_device_dir(ac->adev))
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 'state' [R] */
|
/* 'state' [R] */
|
||||||
entry = proc_create_data(ACPI_AC_FILE_STATE,
|
entry = proc_create_data(ACPI_AC_FILE_STATE,
|
||||||
S_IRUGO, acpi_device_dir(device),
|
S_IRUGO, acpi_device_dir(ac->adev),
|
||||||
&acpi_ac_fops, acpi_driver_data(device));
|
&acpi_ac_fops, ac);
|
||||||
if (!entry)
|
if (!entry)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int acpi_ac_remove_fs(struct acpi_device *device)
|
static int acpi_ac_remove_fs(struct acpi_ac *ac)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (acpi_device_dir(device)) {
|
if (acpi_device_dir(ac->adev)) {
|
||||||
remove_proc_entry(ACPI_AC_FILE_STATE, acpi_device_dir(device));
|
remove_proc_entry(ACPI_AC_FILE_STATE,
|
||||||
|
acpi_device_dir(ac->adev));
|
||||||
remove_proc_entry(acpi_device_bid(device), acpi_ac_dir);
|
remove_proc_entry(acpi_device_bid(ac->adev), acpi_ac_dir);
|
||||||
acpi_device_dir(device) = NULL;
|
acpi_device_dir(ac->adev) = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -241,10 +213,9 @@ static int acpi_ac_remove_fs(struct acpi_device *device)
|
||||||
Driver Model
|
Driver Model
|
||||||
-------------------------------------------------------------------------- */
|
-------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void acpi_ac_notify(struct acpi_device *device, u32 event)
|
static void acpi_ac_notify_handler(acpi_handle handle, u32 event, void *data)
|
||||||
{
|
{
|
||||||
struct acpi_ac *ac = acpi_driver_data(device);
|
struct acpi_ac *ac = data;
|
||||||
|
|
||||||
|
|
||||||
if (!ac)
|
if (!ac)
|
||||||
return;
|
return;
|
||||||
|
@ -267,10 +238,10 @@ static void acpi_ac_notify(struct acpi_device *device, u32 event)
|
||||||
msleep(ac_sleep_before_get_state_ms);
|
msleep(ac_sleep_before_get_state_ms);
|
||||||
|
|
||||||
acpi_ac_get_state(ac);
|
acpi_ac_get_state(ac);
|
||||||
acpi_bus_generate_netlink_event(device->pnp.device_class,
|
acpi_bus_generate_netlink_event(ac->adev->pnp.device_class,
|
||||||
dev_name(&device->dev), event,
|
dev_name(&ac->pdev->dev),
|
||||||
(u32) ac->state);
|
event, (u32) ac->state);
|
||||||
acpi_notifier_call_chain(device, event, (u32) ac->state);
|
acpi_notifier_call_chain(ac->adev, event, (u32) ac->state);
|
||||||
kobject_uevent(&ac->charger.dev->kobj, KOBJ_CHANGE);
|
kobject_uevent(&ac->charger.dev->kobj, KOBJ_CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,50 +266,61 @@ static struct dmi_system_id ac_dmi_table[] = {
|
||||||
{},
|
{},
|
||||||
};
|
};
|
||||||
|
|
||||||
static int acpi_ac_add(struct acpi_device *device)
|
static int acpi_ac_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
struct acpi_ac *ac = NULL;
|
struct acpi_ac *ac = NULL;
|
||||||
|
struct acpi_device *adev;
|
||||||
|
|
||||||
|
if (!pdev)
|
||||||
if (!device)
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
result = acpi_bus_get_device(ACPI_HANDLE(&pdev->dev), &adev);
|
||||||
|
if (result)
|
||||||
|
return -ENODEV;
|
||||||
|
|
||||||
ac = kzalloc(sizeof(struct acpi_ac), GFP_KERNEL);
|
ac = kzalloc(sizeof(struct acpi_ac), GFP_KERNEL);
|
||||||
if (!ac)
|
if (!ac)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
ac->device = device;
|
strcpy(acpi_device_name(adev), ACPI_AC_DEVICE_NAME);
|
||||||
strcpy(acpi_device_name(device), ACPI_AC_DEVICE_NAME);
|
strcpy(acpi_device_class(adev), ACPI_AC_CLASS);
|
||||||
strcpy(acpi_device_class(device), ACPI_AC_CLASS);
|
ac->adev = adev;
|
||||||
device->driver_data = ac;
|
ac->pdev = pdev;
|
||||||
|
platform_set_drvdata(pdev, ac);
|
||||||
|
|
||||||
result = acpi_ac_get_state(ac);
|
result = acpi_ac_get_state(ac);
|
||||||
if (result)
|
if (result)
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
#ifdef CONFIG_ACPI_PROCFS_POWER
|
#ifdef CONFIG_ACPI_PROCFS_POWER
|
||||||
result = acpi_ac_add_fs(device);
|
result = acpi_ac_add_fs(ac);
|
||||||
#endif
|
|
||||||
if (result)
|
if (result)
|
||||||
goto end;
|
goto end;
|
||||||
ac->charger.name = acpi_device_bid(device);
|
#endif
|
||||||
|
ac->charger.name = acpi_device_bid(adev);
|
||||||
ac->charger.type = POWER_SUPPLY_TYPE_MAINS;
|
ac->charger.type = POWER_SUPPLY_TYPE_MAINS;
|
||||||
ac->charger.properties = ac_props;
|
ac->charger.properties = ac_props;
|
||||||
ac->charger.num_properties = ARRAY_SIZE(ac_props);
|
ac->charger.num_properties = ARRAY_SIZE(ac_props);
|
||||||
ac->charger.get_property = get_ac_property;
|
ac->charger.get_property = get_ac_property;
|
||||||
result = power_supply_register(&ac->device->dev, &ac->charger);
|
result = power_supply_register(&pdev->dev, &ac->charger);
|
||||||
if (result)
|
if (result)
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
|
result = acpi_install_notify_handler(ACPI_HANDLE(&pdev->dev),
|
||||||
|
ACPI_DEVICE_NOTIFY, acpi_ac_notify_handler, ac);
|
||||||
|
if (result) {
|
||||||
|
power_supply_unregister(&ac->charger);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
printk(KERN_INFO PREFIX "%s [%s] (%s)\n",
|
printk(KERN_INFO PREFIX "%s [%s] (%s)\n",
|
||||||
acpi_device_name(device), acpi_device_bid(device),
|
acpi_device_name(adev), acpi_device_bid(adev),
|
||||||
ac->state ? "on-line" : "off-line");
|
ac->state ? "on-line" : "off-line");
|
||||||
|
|
||||||
end:
|
end:
|
||||||
if (result) {
|
if (result) {
|
||||||
#ifdef CONFIG_ACPI_PROCFS_POWER
|
#ifdef CONFIG_ACPI_PROCFS_POWER
|
||||||
acpi_ac_remove_fs(device);
|
acpi_ac_remove_fs(ac);
|
||||||
#endif
|
#endif
|
||||||
kfree(ac);
|
kfree(ac);
|
||||||
}
|
}
|
||||||
|
@ -356,7 +338,7 @@ static int acpi_ac_resume(struct device *dev)
|
||||||
if (!dev)
|
if (!dev)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
ac = acpi_driver_data(to_acpi_device(dev));
|
ac = platform_get_drvdata(to_platform_device(dev));
|
||||||
if (!ac)
|
if (!ac)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
@ -368,21 +350,24 @@ static int acpi_ac_resume(struct device *dev)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
static SIMPLE_DEV_PM_OPS(acpi_ac_pm_ops, NULL, acpi_ac_resume);
|
||||||
|
|
||||||
static int acpi_ac_remove(struct acpi_device *device)
|
static int acpi_ac_remove(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct acpi_ac *ac = NULL;
|
struct acpi_ac *ac;
|
||||||
|
|
||||||
|
if (!pdev)
|
||||||
if (!device || !acpi_driver_data(device))
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
ac = acpi_driver_data(device);
|
acpi_remove_notify_handler(ACPI_HANDLE(&pdev->dev),
|
||||||
|
ACPI_DEVICE_NOTIFY, acpi_ac_notify_handler);
|
||||||
|
|
||||||
|
ac = platform_get_drvdata(pdev);
|
||||||
if (ac->charger.dev)
|
if (ac->charger.dev)
|
||||||
power_supply_unregister(&ac->charger);
|
power_supply_unregister(&ac->charger);
|
||||||
|
|
||||||
#ifdef CONFIG_ACPI_PROCFS_POWER
|
#ifdef CONFIG_ACPI_PROCFS_POWER
|
||||||
acpi_ac_remove_fs(device);
|
acpi_ac_remove_fs(ac);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
kfree(ac);
|
kfree(ac);
|
||||||
|
@ -390,6 +375,23 @@ static int acpi_ac_remove(struct acpi_device *device)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const struct acpi_device_id acpi_ac_match[] = {
|
||||||
|
{ "ACPI0003", 0 },
|
||||||
|
{ }
|
||||||
|
};
|
||||||
|
MODULE_DEVICE_TABLE(acpi, acpi_ac_match);
|
||||||
|
|
||||||
|
static struct platform_driver acpi_ac_driver = {
|
||||||
|
.probe = acpi_ac_probe,
|
||||||
|
.remove = acpi_ac_remove,
|
||||||
|
.driver = {
|
||||||
|
.name = "acpi-ac",
|
||||||
|
.owner = THIS_MODULE,
|
||||||
|
.pm = &acpi_ac_pm_ops,
|
||||||
|
.acpi_match_table = ACPI_PTR(acpi_ac_match),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
static int __init acpi_ac_init(void)
|
static int __init acpi_ac_init(void)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
@ -403,7 +405,7 @@ static int __init acpi_ac_init(void)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
result = acpi_bus_register_driver(&acpi_ac_driver);
|
result = platform_driver_register(&acpi_ac_driver);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
#ifdef CONFIG_ACPI_PROCFS_POWER
|
#ifdef CONFIG_ACPI_PROCFS_POWER
|
||||||
acpi_unlock_ac_dir(acpi_ac_dir);
|
acpi_unlock_ac_dir(acpi_ac_dir);
|
||||||
|
@ -416,15 +418,10 @@ static int __init acpi_ac_init(void)
|
||||||
|
|
||||||
static void __exit acpi_ac_exit(void)
|
static void __exit acpi_ac_exit(void)
|
||||||
{
|
{
|
||||||
|
platform_driver_unregister(&acpi_ac_driver);
|
||||||
acpi_bus_unregister_driver(&acpi_ac_driver);
|
|
||||||
|
|
||||||
#ifdef CONFIG_ACPI_PROCFS_POWER
|
#ifdef CONFIG_ACPI_PROCFS_POWER
|
||||||
acpi_unlock_ac_dir(acpi_ac_dir);
|
acpi_unlock_ac_dir(acpi_ac_dir);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module_init(acpi_ac_init);
|
module_init(acpi_ac_init);
|
||||||
module_exit(acpi_ac_exit);
|
module_exit(acpi_ac_exit);
|
||||||
|
|
|
@ -29,6 +29,7 @@ ACPI_MODULE_NAME("platform");
|
||||||
static const struct acpi_device_id acpi_platform_device_ids[] = {
|
static const struct acpi_device_id acpi_platform_device_ids[] = {
|
||||||
|
|
||||||
{ "PNP0D40" },
|
{ "PNP0D40" },
|
||||||
|
{ "ACPI0003" },
|
||||||
|
|
||||||
{ }
|
{ }
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue