From: Jonathan Cameron <jic23@kernel.org>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: linux-iio@vger.kernel.org, Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>
Subject: Re: [PATCH v1 2/2] iio: magnetometer: ak8975: Convert to use device_get_match_data()
Date: Sat, 18 Jan 2020 11:41:43 +0000 [thread overview]
Message-ID: <20200118114143.08943791@archlinux> (raw)
In-Reply-To: <20200115174425.70728-2-andriy.shevchenko@linux.intel.com>
On Wed, 15 Jan 2020 19:44:25 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> Convert to use device_get_match_data() instead of open coded variant.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Looks good to me.
Applied to the togreg branch of iio.git and pushed out as testing.
Thanks,
Jonathan
> ---
> drivers/iio/magnetometer/ak8975.c | 39 +++++++++++++------------------
> 1 file changed, 16 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c
> index 8e50e073bcbf..3c881541ae72 100644
> --- a/drivers/iio/magnetometer/ak8975.c
> +++ b/drivers/iio/magnetometer/ak8975.c
> @@ -203,11 +203,11 @@ static long ak09912_raw_to_gauss(u16 data)
>
> /* Compatible Asahi Kasei Compass parts */
> enum asahi_compass_chipset {
> + AKXXXX = 0,
> AK8975,
> AK8963,
> AK09911,
> AK09912,
> - AK_MAX_TYPE
> };
>
> enum ak_ctrl_reg_addr {
> @@ -245,7 +245,7 @@ struct ak_def {
> u8 data_regs[3];
> };
>
> -static const struct ak_def ak_def_array[AK_MAX_TYPE] = {
> +static const struct ak_def ak_def_array[] = {
> {
> .type = AK8975,
> .raw_to_gauss = ak8975_raw_to_gauss,
> @@ -781,19 +781,6 @@ static const struct acpi_device_id ak_acpi_match[] = {
> MODULE_DEVICE_TABLE(acpi, ak_acpi_match);
> #endif
>
> -static const char *ak8975_match_acpi_device(struct device *dev,
> - enum asahi_compass_chipset *chipset)
> -{
> - const struct acpi_device_id *id;
> -
> - id = acpi_match_device(dev->driver->acpi_match_table, dev);
> - if (!id)
> - return NULL;
> - *chipset = (int)id->driver_data;
> -
> - return dev_name(dev);
> -}
> -
> static void ak8975_fill_buffer(struct iio_dev *indio_dev)
> {
> struct ak8975_data *data = iio_priv(indio_dev);
> @@ -852,9 +839,11 @@ static int ak8975_probe(struct i2c_client *client,
> struct ak8975_data *data;
> struct iio_dev *indio_dev;
> struct gpio_desc *eoc_gpiod;
> + const void *match;
> + unsigned int i;
> int err;
> + enum asahi_compass_chipset chipset;
> const char *name = NULL;
> - enum asahi_compass_chipset chipset = AK_MAX_TYPE;
>
> /*
> * Grab and set up the supplied GPIO.
> @@ -884,23 +873,27 @@ static int ak8975_probe(struct i2c_client *client,
> return err;
>
> /* id will be NULL when enumerated via ACPI */
> - if (id) {
> + match = device_get_match_data(&client->dev);
> + if (match) {
> + chipset = (enum asahi_compass_chipset)(match);
> + name = dev_name(&client->dev);
> + } else if (id) {
> chipset = (enum asahi_compass_chipset)(id->driver_data);
> name = id->name;
> - } else if (ACPI_HANDLE(&client->dev)) {
> - name = ak8975_match_acpi_device(&client->dev, &chipset);
> - if (!name)
> - return -ENODEV;
> } else
> return -ENOSYS;
>
> - if (chipset >= AK_MAX_TYPE) {
> + for (i = 0; i < ARRAY_SIZE(ak_def_array); i++)
> + if (ak_def_array[i].type == chipset)
> + break;
> +
> + if (i == ARRAY_SIZE(ak_def_array)) {
> dev_err(&client->dev, "AKM device type unsupported: %d\n",
> chipset);
> return -ENODEV;
> }
>
> - data->def = &ak_def_array[chipset];
> + data->def = &ak_def_array[i];
>
> /* Fetch the regulators */
> data->vdd = devm_regulator_get(&client->dev, "vdd");
next prev parent reply other threads:[~2020-01-18 11:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-15 17:44 [PATCH v1 1/2] iio: magnetometer: ak8975: Get rid of platform data Andy Shevchenko
2020-01-15 17:44 ` [PATCH v1 2/2] iio: magnetometer: ak8975: Convert to use device_get_match_data() Andy Shevchenko
2020-01-18 11:41 ` Jonathan Cameron [this message]
2020-01-18 11:38 ` [PATCH v1 1/2] iio: magnetometer: ak8975: Get rid of platform data Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200118114143.08943791@archlinux \
--to=jic23@kernel.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=pmeerw@pmeerw.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox