Commit a9058f28 authored by Hans de Goede's avatar Hans de Goede Committed by Jonathan Cameron

iio: accel: da280: Simplify id-matching

da280_match_acpi_device() is a DIY version of acpi_device_get_match_data(),
so it can be dropped.

And things can be simplified further by using i2c_get_match_data() which
will also check i2c_client_id style ids.
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20240104160152.304100-1-hdegoede@redhat.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 02324a09
...@@ -23,8 +23,6 @@ ...@@ -23,8 +23,6 @@
#define DA280_MODE_ENABLE 0x1e #define DA280_MODE_ENABLE 0x1e
#define DA280_MODE_DISABLE 0x9e #define DA280_MODE_DISABLE 0x9e
enum da280_chipset { da217, da226, da280 };
/* /*
* a value of + or -4096 corresponds to + or - 1G * a value of + or -4096 corresponds to + or - 1G
* scale = 9.81 / 4096 = 0.002395019 * scale = 9.81 / 4096 = 0.002395019
...@@ -47,6 +45,11 @@ static const struct iio_chan_spec da280_channels[] = { ...@@ -47,6 +45,11 @@ static const struct iio_chan_spec da280_channels[] = {
DA280_CHANNEL(DA280_REG_ACC_Z_LSB, Z), DA280_CHANNEL(DA280_REG_ACC_Z_LSB, Z),
}; };
struct da280_match_data {
const char *name;
int num_channels;
};
struct da280_data { struct da280_data {
struct i2c_client *client; struct i2c_client *client;
}; };
...@@ -89,17 +92,6 @@ static const struct iio_info da280_info = { ...@@ -89,17 +92,6 @@ static const struct iio_info da280_info = {
.read_raw = da280_read_raw, .read_raw = da280_read_raw,
}; };
static enum da280_chipset da280_match_acpi_device(struct device *dev)
{
const struct acpi_device_id *id;
id = acpi_match_device(dev->driver->acpi_match_table, dev);
if (!id)
return -EINVAL;
return (enum da280_chipset) id->driver_data;
}
static void da280_disable(void *client) static void da280_disable(void *client)
{ {
da280_enable(client, false); da280_enable(client, false);
...@@ -107,16 +99,21 @@ static void da280_disable(void *client) ...@@ -107,16 +99,21 @@ static void da280_disable(void *client)
static int da280_probe(struct i2c_client *client) static int da280_probe(struct i2c_client *client)
{ {
const struct i2c_device_id *id = i2c_client_get_device_id(client); const struct da280_match_data *match_data;
int ret;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
struct da280_data *data; struct da280_data *data;
enum da280_chipset chip; int ret;
ret = i2c_smbus_read_byte_data(client, DA280_REG_CHIP_ID); ret = i2c_smbus_read_byte_data(client, DA280_REG_CHIP_ID);
if (ret != DA280_CHIP_ID) if (ret != DA280_CHIP_ID)
return (ret < 0) ? ret : -ENODEV; return (ret < 0) ? ret : -ENODEV;
match_data = i2c_get_match_data(client);
if (!match_data) {
dev_err(&client->dev, "Error match-data not set\n");
return -EINVAL;
}
indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
if (!indio_dev) if (!indio_dev)
return -ENOMEM; return -ENOMEM;
...@@ -127,23 +124,8 @@ static int da280_probe(struct i2c_client *client) ...@@ -127,23 +124,8 @@ static int da280_probe(struct i2c_client *client)
indio_dev->info = &da280_info; indio_dev->info = &da280_info;
indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->channels = da280_channels; indio_dev->channels = da280_channels;
indio_dev->num_channels = match_data->num_channels;
if (ACPI_HANDLE(&client->dev)) { indio_dev->name = match_data->name;
chip = da280_match_acpi_device(&client->dev);
} else {
chip = id->driver_data;
}
if (chip == da217) {
indio_dev->name = "da217";
indio_dev->num_channels = 3;
} else if (chip == da226) {
indio_dev->name = "da226";
indio_dev->num_channels = 2;
} else {
indio_dev->name = "da280";
indio_dev->num_channels = 3;
}
ret = da280_enable(client, true); ret = da280_enable(client, true);
if (ret < 0) if (ret < 0)
...@@ -168,17 +150,21 @@ static int da280_resume(struct device *dev) ...@@ -168,17 +150,21 @@ static int da280_resume(struct device *dev)
static DEFINE_SIMPLE_DEV_PM_OPS(da280_pm_ops, da280_suspend, da280_resume); static DEFINE_SIMPLE_DEV_PM_OPS(da280_pm_ops, da280_suspend, da280_resume);
static const struct da280_match_data da217_match_data = { "da217", 3 };
static const struct da280_match_data da226_match_data = { "da226", 2 };
static const struct da280_match_data da280_match_data = { "da280", 3 };
static const struct acpi_device_id da280_acpi_match[] = { static const struct acpi_device_id da280_acpi_match[] = {
{"NSA2513", da217}, { "NSA2513", (kernel_ulong_t)&da217_match_data },
{"MIRAACC", da280}, { "MIRAACC", (kernel_ulong_t)&da280_match_data },
{}, {}
}; };
MODULE_DEVICE_TABLE(acpi, da280_acpi_match); MODULE_DEVICE_TABLE(acpi, da280_acpi_match);
static const struct i2c_device_id da280_i2c_id[] = { static const struct i2c_device_id da280_i2c_id[] = {
{ "da217", da217 }, { "da217", (kernel_ulong_t)&da217_match_data },
{ "da226", da226 }, { "da226", (kernel_ulong_t)&da226_match_data },
{ "da280", da280 }, { "da280", (kernel_ulong_t)&da280_match_data },
{} {}
}; };
MODULE_DEVICE_TABLE(i2c, da280_i2c_id); MODULE_DEVICE_TABLE(i2c, da280_i2c_id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment