Commit f08a1508 authored by sayli karnik's avatar sayli karnik Committed by Jonathan Cameron

staging: iio: cdc: ad7152: Replace mlock with a local mutex lock

mlock is intended to protect only switches between modes.
Given this driver doesn't support more than one mode (sysfs polled reads
only), replace mlock with a local mutex lock.
Signed-off-by: default avatarsayli karnik <karniksayli1995@gmail.com>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 2296c062
...@@ -89,6 +89,7 @@ struct ad7152_chip_info { ...@@ -89,6 +89,7 @@ struct ad7152_chip_info {
*/ */
u8 filter_rate_setup; u8 filter_rate_setup;
u8 setup[2]; u8 setup[2];
struct mutex state_lock; /* protect hardware state */
}; };
static inline ssize_t ad7152_start_calib(struct device *dev, static inline ssize_t ad7152_start_calib(struct device *dev,
...@@ -115,10 +116,10 @@ static inline ssize_t ad7152_start_calib(struct device *dev, ...@@ -115,10 +116,10 @@ static inline ssize_t ad7152_start_calib(struct device *dev,
else else
regval |= AD7152_CONF_CH2EN; regval |= AD7152_CONF_CH2EN;
mutex_lock(&indio_dev->mlock); mutex_lock(&chip->state_lock);
ret = i2c_smbus_write_byte_data(chip->client, AD7152_REG_CFG, regval); ret = i2c_smbus_write_byte_data(chip->client, AD7152_REG_CFG, regval);
if (ret < 0) { if (ret < 0) {
mutex_unlock(&indio_dev->mlock); mutex_unlock(&chip->state_lock);
return ret; return ret;
} }
...@@ -126,12 +127,12 @@ static inline ssize_t ad7152_start_calib(struct device *dev, ...@@ -126,12 +127,12 @@ static inline ssize_t ad7152_start_calib(struct device *dev,
mdelay(20); mdelay(20);
ret = i2c_smbus_read_byte_data(chip->client, AD7152_REG_CFG); ret = i2c_smbus_read_byte_data(chip->client, AD7152_REG_CFG);
if (ret < 0) { if (ret < 0) {
mutex_unlock(&indio_dev->mlock); mutex_unlock(&chip->state_lock);
return ret; return ret;
} }
} while ((ret == regval) && timeout--); } while ((ret == regval) && timeout--);
mutex_unlock(&indio_dev->mlock); mutex_unlock(&chip->state_lock);
return len; return len;
} }
...@@ -230,16 +231,16 @@ static int ad7152_write_raw_samp_freq(struct device *dev, int val) ...@@ -230,16 +231,16 @@ static int ad7152_write_raw_samp_freq(struct device *dev, int val)
if (i >= ARRAY_SIZE(ad7152_filter_rate_table)) if (i >= ARRAY_SIZE(ad7152_filter_rate_table))
i = ARRAY_SIZE(ad7152_filter_rate_table) - 1; i = ARRAY_SIZE(ad7152_filter_rate_table) - 1;
mutex_lock(&indio_dev->mlock); mutex_lock(&chip->state_lock);
ret = i2c_smbus_write_byte_data(chip->client, ret = i2c_smbus_write_byte_data(chip->client,
AD7152_REG_CFG2, AD7152_CFG2_OSR(i)); AD7152_REG_CFG2, AD7152_CFG2_OSR(i));
if (ret < 0) { if (ret < 0) {
mutex_unlock(&indio_dev->mlock); mutex_unlock(&chip->state_lock);
return ret; return ret;
} }
chip->filter_rate_setup = i; chip->filter_rate_setup = i;
mutex_unlock(&indio_dev->mlock); mutex_unlock(&chip->state_lock);
return ret; return ret;
} }
...@@ -252,7 +253,7 @@ static int ad7152_write_raw(struct iio_dev *indio_dev, ...@@ -252,7 +253,7 @@ static int ad7152_write_raw(struct iio_dev *indio_dev,
struct ad7152_chip_info *chip = iio_priv(indio_dev); struct ad7152_chip_info *chip = iio_priv(indio_dev);
int ret, i; int ret, i;
mutex_lock(&indio_dev->mlock); mutex_lock(&chip->state_lock);
switch (mask) { switch (mask) {
case IIO_CHAN_INFO_CALIBSCALE: case IIO_CHAN_INFO_CALIBSCALE:
...@@ -321,7 +322,7 @@ static int ad7152_write_raw(struct iio_dev *indio_dev, ...@@ -321,7 +322,7 @@ static int ad7152_write_raw(struct iio_dev *indio_dev,
} }
out: out:
mutex_unlock(&indio_dev->mlock); mutex_unlock(&chip->state_lock);
return ret; return ret;
} }
...@@ -334,7 +335,7 @@ static int ad7152_read_raw(struct iio_dev *indio_dev, ...@@ -334,7 +335,7 @@ static int ad7152_read_raw(struct iio_dev *indio_dev,
int ret; int ret;
u8 regval = 0; u8 regval = 0;
mutex_lock(&indio_dev->mlock); mutex_lock(&chip->state_lock);
switch (mask) { switch (mask) {
case IIO_CHAN_INFO_RAW: case IIO_CHAN_INFO_RAW:
...@@ -422,7 +423,7 @@ static int ad7152_read_raw(struct iio_dev *indio_dev, ...@@ -422,7 +423,7 @@ static int ad7152_read_raw(struct iio_dev *indio_dev,
ret = -EINVAL; ret = -EINVAL;
} }
out: out:
mutex_unlock(&indio_dev->mlock); mutex_unlock(&chip->state_lock);
return ret; return ret;
} }
...@@ -509,6 +510,7 @@ static int ad7152_probe(struct i2c_client *client, ...@@ -509,6 +510,7 @@ static int ad7152_probe(struct i2c_client *client,
i2c_set_clientdata(client, indio_dev); i2c_set_clientdata(client, indio_dev);
chip->client = client; chip->client = client;
mutex_init(&chip->state_lock);
/* Establish that the iio_dev is a child of the i2c device */ /* Establish that the iio_dev is a child of the i2c device */
indio_dev->name = id->name; indio_dev->name = id->name;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment