Message ID | 1212fde5edcf360231282c9d2487712fc5b4d6f8.1530599660.git.nikolaus.voss@loewensteinmedical.de (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Tue, Jul 3, 2018 at 8:41 AM, Nikolaus Voss <nikolaus.voss@loewensteinmedical.de> wrote: > Use device_get_match_data API to simplify access to driver data. ..._data() But. You actually don't use it below. > Let acpi_device_id table entries point to the same driver data as > of_device_id table entries and uniquify access to driver data by using > device_get_match_data API. > #include <linux/acpi.h> > #include <linux/i2c.h> > #include <linux/iio/iio.h> > +#include <linux/of_device.h> (linux/property.h) > + match = of_device_get_match_data(&client->dev); > + if (!match) > + match = acpi_device_get_match_data(&client->dev); What I meant is to simply call match = device_get_match_data(...); > + if (match) > + strlcpy(client->name, match, sizeof(client->name));
On Wed, 4 Jul 2018, Andy Shevchenko wrote: > On Tue, Jul 3, 2018 at 8:41 AM, Nikolaus Voss > <nikolaus.voss@loewensteinmedical.de> wrote: >> Use device_get_match_data API to simplify access to driver data. > > ..._data() > > But. You actually don't use it below. It is used, see below. > >> Let acpi_device_id table entries point to the same driver data as >> of_device_id table entries and uniquify access to driver data by using >> device_get_match_data API. > >> #include <linux/acpi.h> >> #include <linux/i2c.h> >> #include <linux/iio/iio.h> > >> +#include <linux/of_device.h> > > (linux/property.h) > >> + match = of_device_get_match_data(&client->dev); >> + if (!match) >> + match = acpi_device_get_match_data(&client->dev); > > What I meant is to simply call > > match = device_get_match_data(...); Ok, this works, thank you. I will prepare a new patch version. This is where the match data is used: > >> + if (match) >> + strlcpy(client->name, match, sizeof(client->name)); > > In this driver, match data is used to map DT compatible strings/ ACPI CIDs to the key strings (.._ACCEL_DEV_NAME) which are used to identify the actual device (and are also used in i2c_device_id table). Niko -- To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wed, Jul 4, 2018 at 9:56 AM, Nikolaus Voss <nikolaus.voss@loewensteinmedical.de> wrote: > On Wed, 4 Jul 2018, Andy Shevchenko wrote: >> >> On Tue, Jul 3, 2018 at 8:41 AM, Nikolaus Voss >> <nikolaus.voss@loewensteinmedical.de> wrote: >>> >>> Use device_get_match_data API to simplify access to driver data. >> >> >> ..._data() >> >> But. You actually don't use it below. > It is used, see below. I meant the API call you mentioned in the commit message is not used in this version and below you agree to use it eventually. >>> Let acpi_device_id table entries point to the same driver data as >>> of_device_id table entries and uniquify access to driver data by using >>> device_get_match_data API. >> >> >>> #include <linux/acpi.h> >>> #include <linux/i2c.h> >>> #include <linux/iio/iio.h> >> >> >>> +#include <linux/of_device.h> >> >> >> (linux/property.h) >> >>> + match = of_device_get_match_data(&client->dev); >>> + if (!match) >>> + match = acpi_device_get_match_data(&client->dev); >> >> >> What I meant is to simply call >> >> match = device_get_match_data(...); > > > Ok, this works, thank you. I will prepare a new patch version. > > This is where the match data is used: > >> >>> + if (match) >>> + strlcpy(client->name, match, sizeof(client->name)); > In this driver, match data is used to map DT compatible strings/ ACPI CIDs > to the key strings (.._ACCEL_DEV_NAME) which are used to identify the actual > device (and are also used in i2c_device_id table).
diff --git a/drivers/iio/accel/st_accel_i2c.c b/drivers/iio/accel/st_accel_i2c.c index 6bdec8c451e0..163f7ec189b0 100644 --- a/drivers/iio/accel/st_accel_i2c.c +++ b/drivers/iio/accel/st_accel_i2c.c @@ -14,8 +14,8 @@ #include <linux/acpi.h> #include <linux/i2c.h> #include <linux/iio/iio.h> +#include <linux/of_device.h> -#include <linux/iio/common/st_sensors.h> #include <linux/iio/common/st_sensors_i2c.h> #include "st_accel.h" @@ -107,7 +107,7 @@ MODULE_DEVICE_TABLE(of, st_accel_of_match); #ifdef CONFIG_ACPI static const struct acpi_device_id st_accel_acpi_match[] = { - {"SMO8A90", LNG2DM}, + {"SMO8A90", (kernel_ulong_t)LNG2DM_ACCEL_DEV_NAME}, { }, }; MODULE_DEVICE_TABLE(acpi, st_accel_acpi_match); @@ -143,6 +143,7 @@ static int st_accel_i2c_probe(struct i2c_client *client, { struct iio_dev *indio_dev; struct st_sensor_data *adata; + const char *match; int ret; indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*adata)); @@ -151,19 +152,13 @@ static int st_accel_i2c_probe(struct i2c_client *client, adata = iio_priv(indio_dev); - if (client->dev.of_node) { - st_sensors_of_name_probe(&client->dev, st_accel_of_match, - client->name, sizeof(client->name)); - } else if (ACPI_HANDLE(&client->dev)) { - ret = st_sensors_match_acpi_device(&client->dev); - if ((ret < 0) || (ret >= ST_ACCEL_MAX)) - return -ENODEV; + match = of_device_get_match_data(&client->dev); - strlcpy(client->name, st_accel_id_table[ret].name, - sizeof(client->name)); - } else if (!id) - return -ENODEV; + if (!match) + match = acpi_device_get_match_data(&client->dev); + if (match) + strlcpy(client->name, match, sizeof(client->name)); st_sensors_i2c_configure(indio_dev, client, adata);
Use device_get_match_data API to simplify access to driver data. Let acpi_device_id table entries point to the same driver data as of_device_id table entries and uniquify access to driver data by using device_get_match_data API. Signed-off-by: Nikolaus Voss <nikolaus.voss@loewensteinmedical.de> --- drivers/iio/accel/st_accel_i2c.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-)