mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 10:09:10 +02:00
platform/chrome: wilco_ec: event: Convert to a platform driver
In all cases in which a struct acpi_driver is used for binding a driver to an ACPI device object, a corresponding platform device is created by the ACPI core and that device is regarded as a proper representation of underlying hardware. Accordingly, a struct platform_driver should be used by driver code to bind to that device. There are multiple reasons why drivers should not bind directly to ACPI device objects [1]. Overall, it is better to bind drivers to platform devices than to their ACPI companions, so convert the ChromeOS Wilco Embedded Controller event ACPI driver to a platform one. While this is not expected to alter functionality, it changes sysfs layout and so it will be visible to user space. Link: https://lore.kernel.org/all/2396510.ElGaqSPkdT@rafael.j.wysocki/ [1] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Link: https://lore.kernel.org/r/9600287.CDJkKcVGEf@rafael.j.wysocki Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
This commit is contained in:
parent
25a06b7a32
commit
27d58498f6
|
|
@ -38,6 +38,7 @@
|
||||||
#include <linux/io.h>
|
#include <linux/io.h>
|
||||||
#include <linux/list.h>
|
#include <linux/list.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
|
#include <linux/platform_device.h>
|
||||||
#include <linux/poll.h>
|
#include <linux/poll.h>
|
||||||
#include <linux/spinlock.h>
|
#include <linux/spinlock.h>
|
||||||
#include <linux/uaccess.h>
|
#include <linux/uaccess.h>
|
||||||
|
|
@ -198,7 +199,7 @@ struct event_device_data {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* enqueue_events() - Place EC events in queue to be read by userspace.
|
* enqueue_events() - Place EC events in queue to be read by userspace.
|
||||||
* @adev: Device the events came from.
|
* @dev: Device the events came from.
|
||||||
* @buf: Buffer of event data.
|
* @buf: Buffer of event data.
|
||||||
* @length: Length of event data buffer.
|
* @length: Length of event data buffer.
|
||||||
*
|
*
|
||||||
|
|
@ -209,9 +210,9 @@ struct event_device_data {
|
||||||
*
|
*
|
||||||
* Return: 0 on success or negative error code on failure.
|
* Return: 0 on success or negative error code on failure.
|
||||||
*/
|
*/
|
||||||
static int enqueue_events(struct acpi_device *adev, const u8 *buf, u32 length)
|
static int enqueue_events(struct device *dev, const u8 *buf, u32 length)
|
||||||
{
|
{
|
||||||
struct event_device_data *dev_data = adev->driver_data;
|
struct event_device_data *dev_data = dev_get_drvdata(dev);
|
||||||
struct ec_event *event, *queue_event, *old_event;
|
struct ec_event *event, *queue_event, *old_event;
|
||||||
size_t num_words, event_size;
|
size_t num_words, event_size;
|
||||||
u32 offset = 0;
|
u32 offset = 0;
|
||||||
|
|
@ -222,14 +223,14 @@ static int enqueue_events(struct acpi_device *adev, const u8 *buf, u32 length)
|
||||||
num_words = ec_event_num_words(event);
|
num_words = ec_event_num_words(event);
|
||||||
event_size = ec_event_size(event);
|
event_size = ec_event_size(event);
|
||||||
if (num_words > EC_ACPI_MAX_EVENT_WORDS) {
|
if (num_words > EC_ACPI_MAX_EVENT_WORDS) {
|
||||||
dev_err(&adev->dev, "Too many event words: %zu > %d\n",
|
dev_err(dev, "Too many event words: %zu > %d\n",
|
||||||
num_words, EC_ACPI_MAX_EVENT_WORDS);
|
num_words, EC_ACPI_MAX_EVENT_WORDS);
|
||||||
return -EOVERFLOW;
|
return -EOVERFLOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Ensure event does not overflow the available buffer */
|
/* Ensure event does not overflow the available buffer */
|
||||||
if ((offset + event_size) > length) {
|
if ((offset + event_size) > length) {
|
||||||
dev_err(&adev->dev, "Event exceeds buffer: %zu > %d\n",
|
dev_err(dev, "Event exceeds buffer: %zu > %d\n",
|
||||||
offset + event_size, length);
|
offset + event_size, length);
|
||||||
return -EOVERFLOW;
|
return -EOVERFLOW;
|
||||||
}
|
}
|
||||||
|
|
@ -262,12 +263,13 @@ static int enqueue_events(struct acpi_device *adev, const u8 *buf, u32 length)
|
||||||
static void event_device_notify(acpi_handle handle, u32 value, void *data)
|
static void event_device_notify(acpi_handle handle, u32 value, void *data)
|
||||||
{
|
{
|
||||||
struct acpi_buffer event_buffer = { ACPI_ALLOCATE_BUFFER, NULL };
|
struct acpi_buffer event_buffer = { ACPI_ALLOCATE_BUFFER, NULL };
|
||||||
struct acpi_device *adev = data;
|
struct device *dev = data;
|
||||||
|
struct acpi_device *adev = ACPI_COMPANION(dev);
|
||||||
union acpi_object *obj;
|
union acpi_object *obj;
|
||||||
acpi_status status;
|
acpi_status status;
|
||||||
|
|
||||||
if (value != EC_ACPI_NOTIFY_EVENT) {
|
if (value != EC_ACPI_NOTIFY_EVENT) {
|
||||||
dev_err(&adev->dev, "Invalid event: 0x%08x\n", value);
|
dev_err(dev, "Invalid event: 0x%08x\n", value);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -275,31 +277,31 @@ static void event_device_notify(acpi_handle handle, u32 value, void *data)
|
||||||
status = acpi_evaluate_object(adev->handle, EC_ACPI_GET_EVENT,
|
status = acpi_evaluate_object(adev->handle, EC_ACPI_GET_EVENT,
|
||||||
NULL, &event_buffer);
|
NULL, &event_buffer);
|
||||||
if (ACPI_FAILURE(status)) {
|
if (ACPI_FAILURE(status)) {
|
||||||
dev_err(&adev->dev, "Error executing ACPI method %s()\n",
|
dev_err(dev, "Error executing ACPI method %s()\n",
|
||||||
EC_ACPI_GET_EVENT);
|
EC_ACPI_GET_EVENT);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
obj = (union acpi_object *)event_buffer.pointer;
|
obj = (union acpi_object *)event_buffer.pointer;
|
||||||
if (!obj) {
|
if (!obj) {
|
||||||
dev_err(&adev->dev, "Nothing returned from %s()\n",
|
dev_err(dev, "Nothing returned from %s()\n",
|
||||||
EC_ACPI_GET_EVENT);
|
EC_ACPI_GET_EVENT);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (obj->type != ACPI_TYPE_BUFFER) {
|
if (obj->type != ACPI_TYPE_BUFFER) {
|
||||||
dev_err(&adev->dev, "Invalid object returned from %s()\n",
|
dev_err(dev, "Invalid object returned from %s()\n",
|
||||||
EC_ACPI_GET_EVENT);
|
EC_ACPI_GET_EVENT);
|
||||||
kfree(obj);
|
kfree(obj);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (obj->buffer.length < sizeof(struct ec_event)) {
|
if (obj->buffer.length < sizeof(struct ec_event)) {
|
||||||
dev_err(&adev->dev, "Invalid buffer length %d from %s()\n",
|
dev_err(dev, "Invalid buffer length %d from %s()\n",
|
||||||
obj->buffer.length, EC_ACPI_GET_EVENT);
|
obj->buffer.length, EC_ACPI_GET_EVENT);
|
||||||
kfree(obj);
|
kfree(obj);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
enqueue_events(adev, obj->buffer.pointer, obj->buffer.length);
|
enqueue_events(dev, obj->buffer.pointer, obj->buffer.length);
|
||||||
kfree(obj);
|
kfree(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -434,8 +436,8 @@ static void hangup_device(struct event_device_data *dev_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* event_device_add() - Callback when creating a new device.
|
* event_device_probe() - Callback when creating a new device.
|
||||||
* @adev: ACPI device that we will be receiving events from.
|
* @pdev: Platform device that we will be receiving events from.
|
||||||
*
|
*
|
||||||
* This finds a free minor number for the device, allocates and initializes
|
* This finds a free minor number for the device, allocates and initializes
|
||||||
* some device data, and creates a new device and char dev node.
|
* some device data, and creates a new device and char dev node.
|
||||||
|
|
@ -447,7 +449,7 @@ static void hangup_device(struct event_device_data *dev_data)
|
||||||
*
|
*
|
||||||
* Return: 0 on success, negative error code on failure.
|
* Return: 0 on success, negative error code on failure.
|
||||||
*/
|
*/
|
||||||
static int event_device_add(struct acpi_device *adev)
|
static int event_device_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct event_device_data *dev_data;
|
struct event_device_data *dev_data;
|
||||||
int error, minor;
|
int error, minor;
|
||||||
|
|
@ -455,7 +457,7 @@ static int event_device_add(struct acpi_device *adev)
|
||||||
minor = ida_alloc_max(&event_ida, EVENT_MAX_DEV-1, GFP_KERNEL);
|
minor = ida_alloc_max(&event_ida, EVENT_MAX_DEV-1, GFP_KERNEL);
|
||||||
if (minor < 0) {
|
if (minor < 0) {
|
||||||
error = minor;
|
error = minor;
|
||||||
dev_err(&adev->dev, "Failed to find minor number: %d\n", error);
|
dev_err(&pdev->dev, "Failed to find minor number: %d\n", error);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -466,7 +468,7 @@ static int event_device_add(struct acpi_device *adev)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize the device data. */
|
/* Initialize the device data. */
|
||||||
adev->driver_data = dev_data;
|
platform_set_drvdata(pdev, dev_data);
|
||||||
dev_data->events = event_queue_new(queue_size);
|
dev_data->events = event_queue_new(queue_size);
|
||||||
if (!dev_data->events) {
|
if (!dev_data->events) {
|
||||||
kfree(dev_data);
|
kfree(dev_data);
|
||||||
|
|
@ -492,8 +494,9 @@ static int event_device_add(struct acpi_device *adev)
|
||||||
goto free_dev_data;
|
goto free_dev_data;
|
||||||
|
|
||||||
/* Install an ACPI notify handler. */
|
/* Install an ACPI notify handler. */
|
||||||
error = acpi_dev_install_notify_handler(adev, ACPI_DEVICE_NOTIFY,
|
error = acpi_dev_install_notify_handler(ACPI_COMPANION(&pdev->dev),
|
||||||
event_device_notify, adev);
|
ACPI_DEVICE_NOTIFY,
|
||||||
|
event_device_notify, &pdev->dev);
|
||||||
if (error)
|
if (error)
|
||||||
goto free_cdev;
|
goto free_cdev;
|
||||||
|
|
||||||
|
|
@ -508,12 +511,12 @@ static int event_device_add(struct acpi_device *adev)
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void event_device_remove(struct acpi_device *adev)
|
static void event_device_remove(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct event_device_data *dev_data = adev->driver_data;
|
struct event_device_data *dev_data = platform_get_drvdata(pdev);
|
||||||
|
|
||||||
acpi_dev_remove_notify_handler(adev, ACPI_DEVICE_NOTIFY,
|
acpi_dev_remove_notify_handler(ACPI_COMPANION(&pdev->dev),
|
||||||
event_device_notify);
|
ACPI_DEVICE_NOTIFY, event_device_notify);
|
||||||
cdev_device_del(&dev_data->cdev, &dev_data->dev);
|
cdev_device_del(&dev_data->cdev, &dev_data->dev);
|
||||||
ida_free(&event_ida, MINOR(dev_data->dev.devt));
|
ida_free(&event_ida, MINOR(dev_data->dev.devt));
|
||||||
hangup_device(dev_data);
|
hangup_device(dev_data);
|
||||||
|
|
@ -525,13 +528,12 @@ static const struct acpi_device_id event_acpi_ids[] = {
|
||||||
};
|
};
|
||||||
MODULE_DEVICE_TABLE(acpi, event_acpi_ids);
|
MODULE_DEVICE_TABLE(acpi, event_acpi_ids);
|
||||||
|
|
||||||
static struct acpi_driver event_driver = {
|
static struct platform_driver event_driver = {
|
||||||
.name = DRV_NAME,
|
.probe = event_device_probe,
|
||||||
.class = DRV_NAME,
|
.remove = event_device_remove,
|
||||||
.ids = event_acpi_ids,
|
.driver = {
|
||||||
.ops = {
|
.name = DRV_NAME,
|
||||||
.add = event_device_add,
|
.acpi_match_table = event_acpi_ids,
|
||||||
.remove = event_device_remove,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -554,7 +556,7 @@ static int __init event_module_init(void)
|
||||||
}
|
}
|
||||||
event_major = MAJOR(dev_num);
|
event_major = MAJOR(dev_num);
|
||||||
|
|
||||||
ret = acpi_bus_register_driver(&event_driver);
|
ret = platform_driver_register(&event_driver);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
pr_err(DRV_NAME ": Failed registering driver: %d\n", ret);
|
pr_err(DRV_NAME ": Failed registering driver: %d\n", ret);
|
||||||
goto unregister_region;
|
goto unregister_region;
|
||||||
|
|
@ -572,7 +574,7 @@ static int __init event_module_init(void)
|
||||||
|
|
||||||
static void __exit event_module_exit(void)
|
static void __exit event_module_exit(void)
|
||||||
{
|
{
|
||||||
acpi_bus_unregister_driver(&event_driver);
|
platform_driver_unregister(&event_driver);
|
||||||
unregister_chrdev_region(MKDEV(event_major, 0), EVENT_MAX_DEV);
|
unregister_chrdev_region(MKDEV(event_major, 0), EVENT_MAX_DEV);
|
||||||
class_unregister(&event_class);
|
class_unregister(&event_class);
|
||||||
ida_destroy(&event_ida);
|
ida_destroy(&event_ida);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user