mirror of
https://github.com/torvalds/linux
synced 2024-09-06 09:51:23 +00:00
i2c: scmi: Convert to be a platform driver
ACPI core in conjunction with platform driver core provides an infrastructure to enumerate ACPI devices. Use it in order to remove a lot of boilerplate code. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Tested-by: Josef Johansson <josef@oderland.se> Signed-off-by: Wolfram Sang <wsa@kernel.org>
This commit is contained in:
parent
d819524d31
commit
03d4287add
|
@ -6,15 +6,13 @@
|
|||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/stddef.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/acpi.h>
|
||||
|
||||
#define ACPI_SMBUS_HC_CLASS "smbus"
|
||||
#define ACPI_SMBUS_HC_DEVICE_NAME "cmi"
|
||||
|
||||
/* SMBUS HID definition as supported by Microsoft Windows */
|
||||
#define ACPI_SMBUS_MS_HID "SMB0001"
|
||||
|
||||
|
@ -30,7 +28,7 @@ struct acpi_smbus_cmi {
|
|||
u8 cap_info:1;
|
||||
u8 cap_read:1;
|
||||
u8 cap_write:1;
|
||||
struct smbus_methods_t *methods;
|
||||
const struct smbus_methods_t *methods;
|
||||
};
|
||||
|
||||
static const struct smbus_methods_t smbus_methods = {
|
||||
|
@ -358,29 +356,25 @@ static acpi_status acpi_smbus_cmi_query_methods(acpi_handle handle, u32 level,
|
|||
return AE_OK;
|
||||
}
|
||||
|
||||
static int acpi_smbus_cmi_add(struct acpi_device *device)
|
||||
static int smbus_cmi_probe(struct platform_device *device)
|
||||
{
|
||||
struct device *dev = &device->dev;
|
||||
struct acpi_smbus_cmi *smbus_cmi;
|
||||
const struct acpi_device_id *id;
|
||||
int ret;
|
||||
|
||||
smbus_cmi = kzalloc(sizeof(struct acpi_smbus_cmi), GFP_KERNEL);
|
||||
if (!smbus_cmi)
|
||||
return -ENOMEM;
|
||||
|
||||
smbus_cmi->handle = device->handle;
|
||||
strcpy(acpi_device_name(device), ACPI_SMBUS_HC_DEVICE_NAME);
|
||||
strcpy(acpi_device_class(device), ACPI_SMBUS_HC_CLASS);
|
||||
device->driver_data = smbus_cmi;
|
||||
smbus_cmi->handle = ACPI_HANDLE(dev);
|
||||
smbus_cmi->methods = device_get_match_data(dev);
|
||||
|
||||
platform_set_drvdata(device, smbus_cmi);
|
||||
|
||||
smbus_cmi->cap_info = 0;
|
||||
smbus_cmi->cap_read = 0;
|
||||
smbus_cmi->cap_write = 0;
|
||||
|
||||
for (id = acpi_smbus_cmi_ids; id->id[0]; id++)
|
||||
if (!strcmp(id->id, acpi_device_hid(device)))
|
||||
smbus_cmi->methods =
|
||||
(struct smbus_methods_t *) id->driver_data;
|
||||
|
||||
acpi_walk_namespace(ACPI_TYPE_METHOD, smbus_cmi->handle, 1,
|
||||
acpi_smbus_cmi_query_methods, NULL, smbus_cmi, NULL);
|
||||
|
||||
|
@ -390,8 +384,7 @@ static int acpi_smbus_cmi_add(struct acpi_device *device)
|
|||
}
|
||||
|
||||
snprintf(smbus_cmi->adapter.name, sizeof(smbus_cmi->adapter.name),
|
||||
"SMBus CMI adapter %s",
|
||||
acpi_device_name(device));
|
||||
"SMBus CMI adapter %s", dev_name(dev));
|
||||
smbus_cmi->adapter.owner = THIS_MODULE;
|
||||
smbus_cmi->adapter.algo = &acpi_smbus_cmi_algorithm;
|
||||
smbus_cmi->adapter.algo_data = smbus_cmi;
|
||||
|
@ -408,31 +401,28 @@ static int acpi_smbus_cmi_add(struct acpi_device *device)
|
|||
|
||||
err:
|
||||
kfree(smbus_cmi);
|
||||
device->driver_data = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int acpi_smbus_cmi_remove(struct acpi_device *device)
|
||||
static int smbus_cmi_remove(struct platform_device *device)
|
||||
{
|
||||
struct acpi_smbus_cmi *smbus_cmi = acpi_driver_data(device);
|
||||
struct acpi_smbus_cmi *smbus_cmi = platform_get_drvdata(device);
|
||||
|
||||
i2c_del_adapter(&smbus_cmi->adapter);
|
||||
kfree(smbus_cmi);
|
||||
device->driver_data = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct acpi_driver acpi_smbus_cmi_driver = {
|
||||
.name = ACPI_SMBUS_HC_DEVICE_NAME,
|
||||
.class = ACPI_SMBUS_HC_CLASS,
|
||||
.ids = acpi_smbus_cmi_ids,
|
||||
.ops = {
|
||||
.add = acpi_smbus_cmi_add,
|
||||
.remove = acpi_smbus_cmi_remove,
|
||||
static struct platform_driver smbus_cmi_driver = {
|
||||
.probe = smbus_cmi_probe,
|
||||
.remove = smbus_cmi_remove,
|
||||
.driver = {
|
||||
.name = "smbus_cmi",
|
||||
.acpi_match_table = acpi_smbus_cmi_ids,
|
||||
},
|
||||
};
|
||||
module_acpi_driver(acpi_smbus_cmi_driver);
|
||||
module_platform_driver(smbus_cmi_driver);
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("Crane Cai <crane.cai@amd.com>");
|
||||
|
|
Loading…
Reference in a new issue