mbox series

[v1,00/22] iio: use dev_get_platdata() to access platform_data

Message ID 20240902222824.1145571-1-andy.shevchenko@gmail.com
Headers show
Series iio: use dev_get_platdata() to access platform_data | expand

Message

Andy Shevchenko Sept. 2, 2024, 10:16 p.m. UTC
Unify how IIO drivers access platform_data field of struct device.
In simple and straightforward cases constify the local variables.

(Not tested)

Andy Shevchenko (22):
  iio: accel: hid-sensor-accel-3d: Get platform data via
    dev_get_platdata()
  iio: adc: ad7266: Get platform data via dev_get_platdata()
  iio: adc: ad7791: Get platform data via dev_get_platdata()
  iio: adc: ad7887: Get platform data via dev_get_platdata()
  iio: adc: ad7793: Get platform data via dev_get_platdata()
  iio: adc: ltc2497: Get platform data via dev_get_platdata()
  iio: dac: ad5504: Get platform data via dev_get_platdata()
  iio: dac: ad5791: Get platform data via dev_get_platdata()
  iio: dac: m62332: Get platform data via dev_get_platdata()
  iio: dac: max517: Get platform data via dev_get_platdata()
  iio: frequency: ad9523: Get platform data via dev_get_platdata()
  iio: frequency: adf4350: Get platform data via dev_get_platdata()
  iio: gyro: hid-sensor-gyro-3d: Get platform data via
    dev_get_platdata()
  iio: imu: st_lsm6dsx: Get platform data via dev_get_platdata()
  iio: light: hid-sensor-als: Get platform data via dev_get_platdata()
  iio: light: hid-sensor-prox: Get platform data via dev_get_platdata()
  iio: light: lm3533-als: Get platform data via dev_get_platdata()
  iio: magnetometer: hid-sensor-magn-3d: Get platform data via
    dev_get_platdata()
  iio: orientation: hid-sensor-incl-3d: Get platform data via
    dev_get_platdata()
  iio: orientation: hid-sensor-rotation: Get platform data via
    dev_get_platdata()
  iio: position: hid-sensor-custom-intel-hinge: Get platform data via
    dev_get_platdata()
  iio: pressure: hid-sensor-press: Get platform data via
    dev_get_platdata()

 drivers/iio/accel/hid-sensor-accel-3d.c           |  5 ++---
 drivers/iio/adc/ad7266.c                          |  2 +-
 drivers/iio/adc/ad7791.c                          |  4 ++--
 drivers/iio/adc/ad7793.c                          |  2 +-
 drivers/iio/adc/ad7887.c                          |  2 +-
 drivers/iio/adc/ltc2497-core.c                    | 15 +++++----------
 drivers/iio/dac/ad5504.c                          |  2 +-
 drivers/iio/dac/ad5791.c                          |  2 +-
 drivers/iio/dac/m62332.c                          |  2 +-
 drivers/iio/dac/max517.c                          |  4 ++--
 drivers/iio/frequency/ad9523.c                    |  2 +-
 drivers/iio/frequency/adf4350.c                   |  2 +-
 drivers/iio/gyro/hid-sensor-gyro-3d.c             |  4 ++--
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c      | 15 +++++----------
 drivers/iio/light/hid-sensor-als.c                |  4 ++--
 drivers/iio/light/hid-sensor-prox.c               |  4 ++--
 drivers/iio/light/lm3533-als.c                    |  6 +++---
 drivers/iio/magnetometer/hid-sensor-magn-3d.c     |  4 ++--
 drivers/iio/orientation/hid-sensor-incl-3d.c      |  4 ++--
 drivers/iio/orientation/hid-sensor-rotation.c     |  4 ++--
 .../iio/position/hid-sensor-custom-intel-hinge.c  |  4 ++--
 drivers/iio/pressure/hid-sensor-press.c           |  4 ++--
 22 files changed, 43 insertions(+), 54 deletions(-)

Comments

Lorenzo Bianconi Sept. 3, 2024, 7:10 a.m. UTC | #1
> From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 
> Access to platform data via dev_get_platdata() getter to make code cleaner.
> 
> Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> ---
>  drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 15 +++++----------
>  1 file changed, 5 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index ed0267929725..3958b5e1a3f6 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -2132,14 +2132,11 @@ st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw *hw,
>  			const struct st_lsm6dsx_reg **drdy_reg)
>  {
>  	struct device *dev = hw->dev;
> +	const struct st_sensors_platform_data *pdata = dev_get_platdata(dev);

nit: I guess you can move pdata pointer in the 'if' block, since it is just
used there.

Regards,
Lorenzo

>  	int err = 0, drdy_pin;
>  
> -	if (device_property_read_u32(dev, "st,drdy-int-pin", &drdy_pin) < 0) {
> -		struct st_sensors_platform_data *pdata;
> -
> -		pdata = (struct st_sensors_platform_data *)dev->platform_data;
> +	if (device_property_read_u32(dev, "st,drdy-int-pin", &drdy_pin) < 0)
>  		drdy_pin = pdata ? pdata->drdy_int_pin : 1;
> -	}
>  
>  	switch (drdy_pin) {
>  	case 1:
> @@ -2162,14 +2159,13 @@ st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw *hw,
>  static int st_lsm6dsx_init_shub(struct st_lsm6dsx_hw *hw)
>  {
>  	const struct st_lsm6dsx_shub_settings *hub_settings;
> -	struct st_sensors_platform_data *pdata;
>  	struct device *dev = hw->dev;
> +	const struct st_sensors_platform_data *pdata = dev_get_platdata(dev);
>  	unsigned int data;
>  	int err = 0;
>  
>  	hub_settings = &hw->settings->shub_settings;
>  
> -	pdata = (struct st_sensors_platform_data *)dev->platform_data;
>  	if (device_property_read_bool(dev, "st,pullups") ||
>  	    (pdata && pdata->pullups)) {
>  		if (hub_settings->pullup_en.sec_page) {
> @@ -2524,9 +2520,9 @@ static irqreturn_t st_lsm6dsx_sw_trigger_handler_thread(int irq,
>  
>  static int st_lsm6dsx_irq_setup(struct st_lsm6dsx_hw *hw)
>  {
> -	struct st_sensors_platform_data *pdata;
>  	const struct st_lsm6dsx_reg *reg;
>  	struct device *dev = hw->dev;
> +	const struct st_sensors_platform_data *pdata = dev_get_platdata(dev);
>  	unsigned long irq_type;
>  	bool irq_active_low;
>  	int err;
> @@ -2554,7 +2550,6 @@ static int st_lsm6dsx_irq_setup(struct st_lsm6dsx_hw *hw)
>  	if (err < 0)
>  		return err;
>  
> -	pdata = (struct st_sensors_platform_data *)dev->platform_data;
>  	if (device_property_read_bool(dev, "drive-open-drain") ||
>  	    (pdata && pdata->open_drain)) {
>  		reg = &hw->settings->irq_config.od;
> @@ -2639,7 +2634,7 @@ static int st_lsm6dsx_init_regulators(struct device *dev)
>  int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
>  		     struct regmap *regmap)
>  {
> -	struct st_sensors_platform_data *pdata = dev->platform_data;
> +	const struct st_sensors_platform_data *pdata = dev_get_platdata(dev);
>  	const struct st_lsm6dsx_shub_settings *hub_settings;
>  	struct st_lsm6dsx_hw *hw;
>  	const char *name = NULL;
> -- 
> 2.46.0
>
Jonathan Cameron Sept. 3, 2024, 7:47 p.m. UTC | #2
On Tue,  3 Sep 2024 01:16:55 +0300
Andy Shevchenko <andy.shevchenko@gmail.com> wrote:

> From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 
> Access to platform data via dev_get_platdata() getter to make code cleaner.
> 
> Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> ---
>  drivers/iio/dac/max517.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/dac/max517.c b/drivers/iio/dac/max517.c
> index 685980184d3c..96781ae04f9d 100644
> --- a/drivers/iio/dac/max517.c
> +++ b/drivers/iio/dac/max517.c
> @@ -143,10 +143,10 @@ static const struct iio_chan_spec max517_channels[] = {
>  
>  static int max517_probe(struct i2c_client *client)
>  {
> +	const struct max517_platform_data *platform_data = dev_get_platdata(&client->dev);
>  	const struct i2c_device_id *id = i2c_client_get_device_id(client);
>  	struct max517_data *data;
>  	struct iio_dev *indio_dev;
> -	struct max517_platform_data *platform_data = client->dev.platform_data;
>  	int chan;
>  
>  	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
> @@ -176,7 +176,7 @@ static int max517_probe(struct i2c_client *client)
>  
>  	/*
>  	 * Reference voltage on MAX518 and default is 5V, else take vref_mv
> -	 * from platform_data
> +	 * from platform_data.

I guess this is accidental?  

J

>  	 */
>  	for (chan = 0; chan < indio_dev->num_channels; chan++) {
>  		if (id->driver_data == ID_MAX518 || !platform_data)
Jonathan Cameron Sept. 7, 2024, 3:42 p.m. UTC | #3
On Tue, 3 Sep 2024 20:57:27 +0300
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> On Tue, Sep 03, 2024 at 01:16:45AM +0300, Andy Shevchenko wrote:
> > Unify how IIO drivers access platform_data field of struct device.
> > In simple and straightforward cases constify the local variables.
> > 
> > (Not tested)  
> 
> Jonathan, in case you are fine with the series, feel free to squash, e.g.,
> changes against hid-sensor drivers.
I don't follow, but maybe that will become clear once I've looked
at rest of the stuff I haven't read yet.

Anyhow, applied to the togreg branch of iio.git and pushed out as testing
for all the normal reasons.  Another series that will probably be 6.13 material.

Thanks,

Jonathan
>
Andy Shevchenko Sept. 9, 2024, 9:17 a.m. UTC | #4
On Sat, Sep 07, 2024 at 04:42:58PM +0100, Jonathan Cameron wrote:
> On Tue, 3 Sep 2024 20:57:27 +0300
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> > On Tue, Sep 03, 2024 at 01:16:45AM +0300, Andy Shevchenko wrote:
> > > Unify how IIO drivers access platform_data field of struct device.
> > > In simple and straightforward cases constify the local variables.
> > > 
> > > (Not tested)  
> > 
> > Jonathan, in case you are fine with the series, feel free to squash, e.g.,
> > changes against hid-sensor drivers.
> I don't follow, but maybe that will become clear once I've looked
> at rest of the stuff I haven't read yet.

I mean all the patches that starts with "iio: *: hid-sensor-*:" can be squashed
into one with "iio: hid-sensor:"

> Anyhow, applied to the togreg branch of iio.git and pushed out as testing
> for all the normal reasons.  Another series that will probably be 6.13 material.

Thank you!