]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
iio: dac: ad5592r-base: Replace indio_dev->mlock with own device lock
authorSergiu Cuciurean <sergiu.cuciurean@analog.com>
Wed, 20 May 2020 12:02:01 +0000 (15:02 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 5 Jul 2024 07:08:25 +0000 (09:08 +0200)
[ Upstream commit 33c53cbf8f7bc8d62f6146a19da97c8594376ff0 ]

As part of the general cleanup of indio_dev->mlock, this change replaces
it with a local lock on the device's state structure.
This also removes unused iio_dev pointers.

Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Stable-dep-of: 279428df8883 ("iio: dac: ad5592r: fix temperature channel scaling value")
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/iio/dac/ad5592r-base.c
drivers/iio/dac/ad5592r-base.h

index 87a51a85a642d1e6394ad9a5c4cc9b82a1aa47ad..d9c1242db99f199a481d44f210450f1c150ec8a2 100644 (file)
@@ -157,7 +157,6 @@ static void ad5592r_gpio_cleanup(struct ad5592r_state *st)
 static int ad5592r_reset(struct ad5592r_state *st)
 {
        struct gpio_desc *gpio;
-       struct iio_dev *iio_dev = iio_priv_to_dev(st);
 
        gpio = devm_gpiod_get_optional(st->dev, "reset", GPIOD_OUT_LOW);
        if (IS_ERR(gpio))
@@ -167,10 +166,10 @@ static int ad5592r_reset(struct ad5592r_state *st)
                udelay(1);
                gpiod_set_value(gpio, 1);
        } else {
-               mutex_lock(&iio_dev->mlock);
+               mutex_lock(&st->lock);
                /* Writing this magic value resets the device */
                st->ops->reg_write(st, AD5592R_REG_RESET, 0xdac);
-               mutex_unlock(&iio_dev->mlock);
+               mutex_unlock(&st->lock);
        }
 
        udelay(250);
@@ -198,7 +197,6 @@ static int ad5592r_set_channel_modes(struct ad5592r_state *st)
        const struct ad5592r_rw_ops *ops = st->ops;
        int ret;
        unsigned i;
-       struct iio_dev *iio_dev = iio_priv_to_dev(st);
        u8 pulldown = 0, tristate = 0, dac = 0, adc = 0;
        u16 read_back;
 
@@ -248,7 +246,7 @@ static int ad5592r_set_channel_modes(struct ad5592r_state *st)
                }
        }
 
-       mutex_lock(&iio_dev->mlock);
+       mutex_lock(&st->lock);
 
        /* Pull down unused pins to GND */
        ret = ops->reg_write(st, AD5592R_REG_PULLDOWN, pulldown);
@@ -286,7 +284,7 @@ static int ad5592r_set_channel_modes(struct ad5592r_state *st)
                ret = -EIO;
 
 err_unlock:
-       mutex_unlock(&iio_dev->mlock);
+       mutex_unlock(&st->lock);
        return ret;
 }
 
@@ -315,11 +313,11 @@ static int ad5592r_write_raw(struct iio_dev *iio_dev,
                if (!chan->output)
                        return -EINVAL;
 
-               mutex_lock(&iio_dev->mlock);
+               mutex_lock(&st->lock);
                ret = st->ops->write_dac(st, chan->channel, val);
                if (!ret)
                        st->cached_dac[chan->channel] = val;
-               mutex_unlock(&iio_dev->mlock);
+               mutex_unlock(&st->lock);
                return ret;
        case IIO_CHAN_INFO_SCALE:
                if (chan->type == IIO_VOLTAGE) {
@@ -334,12 +332,12 @@ static int ad5592r_write_raw(struct iio_dev *iio_dev,
                        else
                                return -EINVAL;
 
-                       mutex_lock(&iio_dev->mlock);
+                       mutex_lock(&st->lock);
 
                        ret = st->ops->reg_read(st, AD5592R_REG_CTRL,
                                                &st->cached_gp_ctrl);
                        if (ret < 0) {
-                               mutex_unlock(&iio_dev->mlock);
+                               mutex_unlock(&st->lock);
                                return ret;
                        }
 
@@ -361,7 +359,7 @@ static int ad5592r_write_raw(struct iio_dev *iio_dev,
 
                        ret = st->ops->reg_write(st, AD5592R_REG_CTRL,
                                                 st->cached_gp_ctrl);
-                       mutex_unlock(&iio_dev->mlock);
+                       mutex_unlock(&st->lock);
 
                        return ret;
                }
@@ -383,7 +381,7 @@ static int ad5592r_read_raw(struct iio_dev *iio_dev,
 
        switch (m) {
        case IIO_CHAN_INFO_RAW:
-               mutex_lock(&iio_dev->mlock);
+               mutex_lock(&st->lock);
 
                if (!chan->output) {
                        ret = st->ops->read_adc(st, chan->channel, &read_val);
@@ -420,7 +418,7 @@ static int ad5592r_read_raw(struct iio_dev *iio_dev,
                } else {
                        int mult;
 
-                       mutex_lock(&iio_dev->mlock);
+                       mutex_lock(&st->lock);
 
                        if (chan->output)
                                mult = !!(st->cached_gp_ctrl &
@@ -438,7 +436,7 @@ static int ad5592r_read_raw(struct iio_dev *iio_dev,
        case IIO_CHAN_INFO_OFFSET:
                ret = ad5592r_get_vref(st);
 
-               mutex_lock(&iio_dev->mlock);
+               mutex_lock(&st->lock);
 
                if (st->cached_gp_ctrl & AD5592R_REG_CTRL_ADC_RANGE)
                        *val = (-34365 * 25) / ret;
@@ -451,7 +449,7 @@ static int ad5592r_read_raw(struct iio_dev *iio_dev,
        }
 
 unlock:
-       mutex_unlock(&iio_dev->mlock);
+       mutex_unlock(&st->lock);
        return ret;
 }
 
@@ -626,6 +624,8 @@ int ad5592r_probe(struct device *dev, const char *name,
        iio_dev->info = &ad5592r_info;
        iio_dev->modes = INDIO_DIRECT_MODE;
 
+       mutex_init(&st->lock);
+
        ad5592r_init_scales(st, ad5592r_get_vref(st));
 
        ret = ad5592r_reset(st);
index 4774e4cd9c114ddf5abb934bd7bcef2cfa0bf367..23dac2f1ff8a106d3701c41ff2b1c0eae2f8e9dd 100644 (file)
@@ -52,6 +52,7 @@ struct ad5592r_state {
        struct regulator *reg;
        struct gpio_chip gpiochip;
        struct mutex gpio_lock; /* Protect cached gpio_out, gpio_val, etc. */
+       struct mutex lock;
        unsigned int num_channels;
        const struct ad5592r_rw_ops *ops;
        int scale_avail[2][2];