Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Hans de Goede <hdegoede@redhat.com>
Cc: Lars-Peter Clausen <lars@metafoo.de>, linux-iio@vger.kernel.org
Subject: Re: [PATCH] iio: mma8452: Fix probe failing when an i2c_device_id is used
Date: Sun, 9 Jan 2022 15:10:43 +0000	[thread overview]
Message-ID: <20220109151043.54d92a79@jic23-huawei> (raw)
In-Reply-To: <20220106111414.66421-1-hdegoede@redhat.com>

On Thu,  6 Jan 2022 12:14:14 +0100
Hans de Goede <hdegoede@redhat.com> wrote:

> The mma8452_driver declares both of_match_table and i2c_driver.id_table
> match-tables, but its probe() function only checked for of matches.
> 
> Add support for i2c_device_id matches. This fixes the driver not loading
> on some x86 tablets (e.g. the Nextbook Ares 8) where the i2c_client is
> instantiated by platform code using an i2c_device_id.
> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Hi Hans,

At some point we'll want to get rid of the of_ specific stuff in here in
favour of generic firmware properties and I suspect at that time we'll
move the device name into the chip_info_table[] entries so that we
can just use device_get_match_data()

In the meantime this fix looks good to me.  Is there an appropriate
Fixes: tag?

Thanks,

Jonathan


> ---
>  drivers/iio/accel/mma8452.c | 23 +++++++++++++++--------
>  1 file changed, 15 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
> index 09c7f10fefb6..c82841c0a7b3 100644
> --- a/drivers/iio/accel/mma8452.c
> +++ b/drivers/iio/accel/mma8452.c
> @@ -1523,12 +1523,7 @@ static int mma8452_probe(struct i2c_client *client,
>  	struct iio_dev *indio_dev;
>  	int ret;
>  	const struct of_device_id *match;
> -
> -	match = of_match_device(mma8452_dt_ids, &client->dev);
> -	if (!match) {
> -		dev_err(&client->dev, "unknown device model\n");
> -		return -ENODEV;
> -	}
> +	const char *compatible;
>  
>  	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
>  	if (!indio_dev)
> @@ -1537,7 +1532,19 @@ static int mma8452_probe(struct i2c_client *client,
>  	data = iio_priv(indio_dev);
>  	data->client = client;
>  	mutex_init(&data->lock);
> -	data->chip_info = match->data;
> +
> +	if (id) {
> +		compatible = id->name;
> +		data->chip_info = &mma_chip_info_table[id->driver_data];
> +	} else {
> +		match = of_match_device(mma8452_dt_ids, &client->dev);
> +		if (!match) {
> +			dev_err(&client->dev, "unknown device model\n");
> +			return -ENODEV;
> +		}
> +		compatible = match->compatible;
> +		data->chip_info = match->data;
> +	}
>  
>  	data->vdd_reg = devm_regulator_get(&client->dev, "vdd");
>  	if (IS_ERR(data->vdd_reg))
> @@ -1581,7 +1588,7 @@ static int mma8452_probe(struct i2c_client *client,
>  	}
>  
>  	dev_info(&client->dev, "registering %s accelerometer; ID 0x%x\n",
> -		 match->compatible, data->chip_info->chip_id);
> +		 compatible, data->chip_info->chip_id);
>  
>  	i2c_set_clientdata(client, indio_dev);
>  	indio_dev->info = &mma8452_info;


  reply	other threads:[~2022-01-09 15:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-06 11:14 [PATCH] iio: mma8452: Fix probe failing when an i2c_device_id is used Hans de Goede
2022-01-09 15:10 ` Jonathan Cameron [this message]
2022-01-09 15:35   ` Hans de Goede
2022-01-30 14:54     ` 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=20220109151043.54d92a79@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=hdegoede@redhat.com \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    /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