devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Mehdi Djait <mehdi.djait.k@gmail.com>
Cc: jic23@kernel.org, mazziesaccount@gmail.com,
	krzysztof.kozlowski+dt@linaro.org, robh+dt@kernel.org,
	lars@metafoo.de, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v4 5/7] iio: accel: kionix-kx022a: Refactor driver and add chip_info structure
Date: Sat, 27 May 2023 16:39:46 +0300	[thread overview]
Message-ID: <ZHIIIhtOAQRw4F40@smile.fi.intel.com> (raw)
In-Reply-To: <de588a5a3ca311f6dc3a543bfa5cea7b590ae44c.1685109507.git.mehdi.djait.k@gmail.com>

On Fri, May 26, 2023 at 04:30:46PM +0200, Mehdi Djait wrote:
> Add the chip_info structure to the driver's private data to hold all
> the device specific infos.
> Refactor the kx022a driver implementation to make it more generic and
> extensible.

...

> -	regmap = devm_regmap_init_i2c(i2c, &kx022a_regmap);
> +	chip_info = device_get_match_data(&i2c->dev);
> +	if (!chip_info) {
> +		const struct i2c_device_id *id = i2c_client_get_device_id(i2c);
> +		chip_info = (const struct kx022a_chip_info *)id->driver_data;
> +	}

And if still no chip_info available?..

> +	regmap = devm_regmap_init_i2c(i2c, chip_info->regmap_config);
>  	if (IS_ERR(regmap))
>  		return dev_err_probe(dev, PTR_ERR(regmap),
>  				     "Failed to initialize Regmap\n");

...

> -	if (val > KX022A_FIFO_LENGTH)
> -		val = KX022A_FIFO_LENGTH;
> +	if (val > data->chip_info->fifo_length)
> +		val = data->chip_info->fifo_length;

min()/min_t() ?

...

> +	ret = regmap_noinc_read(data->regmap, data->chip_info->buf_read,
> +				&data->fifo_buffer[0], fifo_bytes);

data->fifo_buffer will suffice.


>  	if (ret)
>  		goto renable_out;

...

> +	data->fifo_buffer = kmalloc(data->chip_info->fifo_length *
> +				    KX022A_FIFO_SAMPLES_SIZE_BYTES, GFP_KERNEL);

> +

Redundant blank line.

> +	if (!data->fifo_buffer)
> +		return -ENOMEM;

...

> +struct kx022a_chip_info {
> +	const char *name;
> +	const struct regmap_config *regmap_config;
> +	const struct iio_chan_spec *channels;
> +	unsigned int num_channels;
> +	unsigned int fifo_length;
> +	u8 who;
> +	u8 id;
> +	u8 cntl;
> +	u8 cntl2;
> +	u8 odcntl;
> +	u8 buf_cntl1;
> +	u8 buf_cntl2;
> +	u8 buf_clear;
> +	u8 buf_status1;

Here is the gap since it's not a packed structure. Can we avoid it?

> +	u16 buf_smp_lvl_mask;
> +	u8 buf_read;
> +	u8 inc1;
> +	u8 inc4;
> +	u8 inc5;
> +	u8 inc6;
> +	u8 xout_l;
> +};

-- 
With Best Regards,
Andy Shevchenko



  parent reply	other threads:[~2023-05-27 13:40 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-26 14:30 [PATCH v4 0/7] iio: accel: Add support for Kionix/ROHM KX132-1211 accelerometer Mehdi Djait
2023-05-26 14:30 ` [PATCH v4 1/7] dt-bindings: iio: Add " Mehdi Djait
2023-05-26 14:30 ` [PATCH v4 2/7] iio: accel: kionix-kx022a: Remove blank lines Mehdi Djait
2023-05-26 14:30 ` [PATCH v4 3/7] iio: accel: kionix-kx022a: Warn on failed matches and assume compatibility Mehdi Djait
2023-05-26 14:30 ` [PATCH v4 4/7] iio: accel: kionix-kx022a: Add an i2c_device_id table Mehdi Djait
2023-05-26 16:35   ` Matti Vaittinen
2023-05-26 14:30 ` [PATCH v4 5/7] iio: accel: kionix-kx022a: Refactor driver and add chip_info structure Mehdi Djait
2023-05-26 17:04   ` Matti Vaittinen
2023-05-28 16:49     ` Jonathan Cameron
2023-05-27 13:39   ` Andy Shevchenko [this message]
2023-05-28 16:55   ` Jonathan Cameron
2023-05-26 14:30 ` [PATCH v4 6/7] iio: accel: kionix-kx022a: Add a function to retrieve number of bytes in buffer Mehdi Djait
     [not found] <cover.1685111274.git.mehdi.djait.k@gmail.com>
2023-05-26 14:30 ` [PATCH v4 7/7] iio: accel: Add support for Kionix/ROHM KX132-1211 accelerometer Mehdi Djait
2023-05-26 14:42   ` Mehdi Djait
2023-05-26 17:13   ` Matti Vaittinen
2023-05-27  8:24   ` Andy Shevchenko
2023-05-28 16:59   ` 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=ZHIIIhtOAQRw4F40@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mazziesaccount@gmail.com \
    --cc=mehdi.djait.k@gmail.com \
    --cc=robh+dt@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;
as well as URLs for NNTP newsgroup(s).