Commit 686027fb authored by Hartmut Knaack's avatar Hartmut Knaack Committed by Jonathan Cameron

iio:accel:mma8452: coding style cleanup

Some coding style cleanups, mainly indicated by checkpatch.pl, which
includes indentation changes, drop spaces after casts and befor tabs.
Also insert empty lines after logical blocks and before unconditional
returns.
Signed-off-by: default avatarHartmut Knaack <knaack.h@gmx.de>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 69abff81
...@@ -87,30 +87,34 @@ static int mma8452_drdy(struct mma8452_data *data) ...@@ -87,30 +87,34 @@ static int mma8452_drdy(struct mma8452_data *data)
return ret; return ret;
if ((ret & MMA8452_STATUS_DRDY) == MMA8452_STATUS_DRDY) if ((ret & MMA8452_STATUS_DRDY) == MMA8452_STATUS_DRDY)
return 0; return 0;
msleep(20); msleep(20);
} }
dev_err(&data->client->dev, "data not ready\n"); dev_err(&data->client->dev, "data not ready\n");
return -EIO; return -EIO;
} }
static int mma8452_read(struct mma8452_data *data, __be16 buf[3]) static int mma8452_read(struct mma8452_data *data, __be16 buf[3])
{ {
int ret = mma8452_drdy(data); int ret = mma8452_drdy(data);
if (ret < 0) if (ret < 0)
return ret; return ret;
return i2c_smbus_read_i2c_block_data(data->client,
MMA8452_OUT_X, 3 * sizeof(__be16), (u8 *) buf); return i2c_smbus_read_i2c_block_data(data->client, MMA8452_OUT_X,
3 * sizeof(__be16), (u8 *)buf);
} }
static ssize_t mma8452_show_int_plus_micros(char *buf, static ssize_t mma8452_show_int_plus_micros(char *buf, const int (*vals)[2],
const int (*vals)[2], int n) int n)
{ {
size_t len = 0; size_t len = 0;
while (n-- > 0) while (n-- > 0)
len += scnprintf(buf + len, PAGE_SIZE - len, len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%06d ",
"%d.%06d ", vals[n][0], vals[n][1]); vals[n][0], vals[n][1]);
/* replace trailing space by newline */ /* replace trailing space by newline */
buf[len - 1] = '\n'; buf[len - 1] = '\n';
...@@ -143,7 +147,7 @@ static const int mma8452_samp_freq[8][2] = { ...@@ -143,7 +147,7 @@ static const int mma8452_samp_freq[8][2] = {
* Hardware has fullscale of -2G, -4G, -8G corresponding to raw value -2048 * Hardware has fullscale of -2G, -4G, -8G corresponding to raw value -2048
* The userspace interface uses m/s^2 and we declare micro units * The userspace interface uses m/s^2 and we declare micro units
* So scale factor is given by: * So scale factor is given by:
* g * N * 1000000 / 2048 for N = 2, 4, 8 and g=9.80665 * g * N * 1000000 / 2048 for N = 2, 4, 8 and g = 9.80665
*/ */
static const int mma8452_scales[3][2] = { static const int mma8452_scales[3][2] = {
{0, 9577}, {0, 19154}, {0, 38307} {0, 9577}, {0, 19154}, {0, 38307}
...@@ -174,14 +178,16 @@ static const int mma8452_hp_filter_cutoff[8][4][2] = { ...@@ -174,14 +178,16 @@ static const int mma8452_hp_filter_cutoff[8][4][2] = {
}; };
static ssize_t mma8452_show_samp_freq_avail(struct device *dev, static ssize_t mma8452_show_samp_freq_avail(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr,
char *buf)
{ {
return mma8452_show_int_plus_micros(buf, mma8452_samp_freq, return mma8452_show_int_plus_micros(buf, mma8452_samp_freq,
ARRAY_SIZE(mma8452_samp_freq)); ARRAY_SIZE(mma8452_samp_freq));
} }
static ssize_t mma8452_show_scale_avail(struct device *dev, static ssize_t mma8452_show_scale_avail(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr,
char *buf)
{ {
return mma8452_show_int_plus_micros(buf, mma8452_scales, return mma8452_show_int_plus_micros(buf, mma8452_scales,
ARRAY_SIZE(mma8452_scales)); ARRAY_SIZE(mma8452_scales));
...@@ -209,14 +215,15 @@ static int mma8452_get_samp_freq_index(struct mma8452_data *data, ...@@ -209,14 +215,15 @@ static int mma8452_get_samp_freq_index(struct mma8452_data *data,
int val, int val2) int val, int val2)
{ {
return mma8452_get_int_plus_micros_index(mma8452_samp_freq, return mma8452_get_int_plus_micros_index(mma8452_samp_freq,
ARRAY_SIZE(mma8452_samp_freq), val, val2); ARRAY_SIZE(mma8452_samp_freq),
val, val2);
} }
static int mma8452_get_scale_index(struct mma8452_data *data, static int mma8452_get_scale_index(struct mma8452_data *data, int val, int val2)
int val, int val2)
{ {
return mma8452_get_int_plus_micros_index(mma8452_scales, return mma8452_get_int_plus_micros_index(mma8452_scales,
ARRAY_SIZE(mma8452_scales), val, val2); ARRAY_SIZE(mma8452_scales),
val, val2);
} }
static int mma8452_get_hp_filter_index(struct mma8452_data *data, static int mma8452_get_hp_filter_index(struct mma8452_data *data,
...@@ -262,25 +269,31 @@ static int mma8452_read_raw(struct iio_dev *indio_dev, ...@@ -262,25 +269,31 @@ static int mma8452_read_raw(struct iio_dev *indio_dev,
mutex_unlock(&data->lock); mutex_unlock(&data->lock);
if (ret < 0) if (ret < 0)
return ret; return ret;
*val = sign_extend32(
be16_to_cpu(buffer[chan->scan_index]) >> 4, 11); *val = sign_extend32(be16_to_cpu(buffer[chan->scan_index]) >> 4,
11);
return IIO_VAL_INT; return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
i = data->data_cfg & MMA8452_DATA_CFG_FS_MASK; i = data->data_cfg & MMA8452_DATA_CFG_FS_MASK;
*val = mma8452_scales[i][0]; *val = mma8452_scales[i][0];
*val2 = mma8452_scales[i][1]; *val2 = mma8452_scales[i][1];
return IIO_VAL_INT_PLUS_MICRO; return IIO_VAL_INT_PLUS_MICRO;
case IIO_CHAN_INFO_SAMP_FREQ: case IIO_CHAN_INFO_SAMP_FREQ:
i = mma8452_get_odr_index(data); i = mma8452_get_odr_index(data);
*val = mma8452_samp_freq[i][0]; *val = mma8452_samp_freq[i][0];
*val2 = mma8452_samp_freq[i][1]; *val2 = mma8452_samp_freq[i][1];
return IIO_VAL_INT_PLUS_MICRO; return IIO_VAL_INT_PLUS_MICRO;
case IIO_CHAN_INFO_CALIBBIAS: case IIO_CHAN_INFO_CALIBBIAS:
ret = i2c_smbus_read_byte_data(data->client, MMA8452_OFF_X + ret = i2c_smbus_read_byte_data(data->client,
chan->scan_index); MMA8452_OFF_X + chan->scan_index);
if (ret < 0) if (ret < 0)
return ret; return ret;
*val = sign_extend32(ret, 7); *val = sign_extend32(ret, 7);
return IIO_VAL_INT; return IIO_VAL_INT;
case IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY: case IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY:
if (data->data_cfg & MMA8452_DATA_CFG_HPF_MASK) { if (data->data_cfg & MMA8452_DATA_CFG_HPF_MASK) {
...@@ -291,8 +304,10 @@ static int mma8452_read_raw(struct iio_dev *indio_dev, ...@@ -291,8 +304,10 @@ static int mma8452_read_raw(struct iio_dev *indio_dev,
*val = 0; *val = 0;
*val2 = 0; *val2 = 0;
} }
return IIO_VAL_INT_PLUS_MICRO; return IIO_VAL_INT_PLUS_MICRO;
} }
return -EINVAL; return -EINVAL;
} }
...@@ -330,6 +345,7 @@ static int mma8452_change_config(struct mma8452_data *data, u8 reg, u8 val) ...@@ -330,6 +345,7 @@ static int mma8452_change_config(struct mma8452_data *data, u8 reg, u8 val)
ret = 0; ret = 0;
fail: fail:
mutex_unlock(&data->lock); mutex_unlock(&data->lock);
return ret; return ret;
} }
...@@ -346,6 +362,7 @@ static int mma8452_set_hp_filter_frequency(struct mma8452_data *data, ...@@ -346,6 +362,7 @@ static int mma8452_set_hp_filter_frequency(struct mma8452_data *data,
MMA8452_HP_FILTER_CUTOFF); MMA8452_HP_FILTER_CUTOFF);
if (reg < 0) if (reg < 0)
return reg; return reg;
reg &= ~MMA8452_HP_FILTER_CUTOFF_SEL_MASK; reg &= ~MMA8452_HP_FILTER_CUTOFF_SEL_MASK;
reg |= i; reg |= i;
...@@ -370,21 +387,26 @@ static int mma8452_write_raw(struct iio_dev *indio_dev, ...@@ -370,21 +387,26 @@ static int mma8452_write_raw(struct iio_dev *indio_dev,
data->ctrl_reg1 &= ~MMA8452_CTRL_DR_MASK; data->ctrl_reg1 &= ~MMA8452_CTRL_DR_MASK;
data->ctrl_reg1 |= i << MMA8452_CTRL_DR_SHIFT; data->ctrl_reg1 |= i << MMA8452_CTRL_DR_SHIFT;
return mma8452_change_config(data, MMA8452_CTRL_REG1, return mma8452_change_config(data, MMA8452_CTRL_REG1,
data->ctrl_reg1); data->ctrl_reg1);
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
i = mma8452_get_scale_index(data, val, val2); i = mma8452_get_scale_index(data, val, val2);
if (i < 0) if (i < 0)
return i; return i;
data->data_cfg &= ~MMA8452_DATA_CFG_FS_MASK; data->data_cfg &= ~MMA8452_DATA_CFG_FS_MASK;
data->data_cfg |= i; data->data_cfg |= i;
return mma8452_change_config(data, MMA8452_DATA_CFG, return mma8452_change_config(data, MMA8452_DATA_CFG,
data->data_cfg); data->data_cfg);
case IIO_CHAN_INFO_CALIBBIAS: case IIO_CHAN_INFO_CALIBBIAS:
if (val < -128 || val > 127) if (val < -128 || val > 127)
return -EINVAL; return -EINVAL;
return mma8452_change_config(data, MMA8452_OFF_X +
chan->scan_index, val); return mma8452_change_config(data,
MMA8452_OFF_X + chan->scan_index,
val);
case IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY: case IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY:
if (val == 0 && val2 == 0) { if (val == 0 && val2 == 0) {
...@@ -395,6 +417,7 @@ static int mma8452_write_raw(struct iio_dev *indio_dev, ...@@ -395,6 +417,7 @@ static int mma8452_write_raw(struct iio_dev *indio_dev,
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
return mma8452_change_config(data, MMA8452_DATA_CFG, return mma8452_change_config(data, MMA8452_DATA_CFG,
data->data_cfg); data->data_cfg);
...@@ -421,6 +444,7 @@ static int mma8452_read_thresh(struct iio_dev *indio_dev, ...@@ -421,6 +444,7 @@ static int mma8452_read_thresh(struct iio_dev *indio_dev,
return ret; return ret;
*val = ret & MMA8452_TRANSIENT_THS_MASK; *val = ret & MMA8452_TRANSIENT_THS_MASK;
return IIO_VAL_INT; return IIO_VAL_INT;
case IIO_EV_INFO_PERIOD: case IIO_EV_INFO_PERIOD:
...@@ -433,6 +457,7 @@ static int mma8452_read_thresh(struct iio_dev *indio_dev, ...@@ -433,6 +457,7 @@ static int mma8452_read_thresh(struct iio_dev *indio_dev,
mma8452_get_odr_index(data)]; mma8452_get_odr_index(data)];
*val = us / USEC_PER_SEC; *val = us / USEC_PER_SEC;
*val2 = us % USEC_PER_SEC; *val2 = us % USEC_PER_SEC;
return IIO_VAL_INT_PLUS_MICRO; return IIO_VAL_INT_PLUS_MICRO;
case IIO_EV_INFO_HIGH_PASS_FILTER_3DB: case IIO_EV_INFO_HIGH_PASS_FILTER_3DB:
...@@ -449,6 +474,7 @@ static int mma8452_read_thresh(struct iio_dev *indio_dev, ...@@ -449,6 +474,7 @@ static int mma8452_read_thresh(struct iio_dev *indio_dev,
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
return IIO_VAL_INT_PLUS_MICRO; return IIO_VAL_INT_PLUS_MICRO;
default: default:
...@@ -483,6 +509,7 @@ static int mma8452_write_thresh(struct iio_dev *indio_dev, ...@@ -483,6 +509,7 @@ static int mma8452_write_thresh(struct iio_dev *indio_dev,
return mma8452_change_config(data, MMA8452_TRANSIENT_COUNT, return mma8452_change_config(data, MMA8452_TRANSIENT_COUNT,
steps); steps);
case IIO_EV_INFO_HIGH_PASS_FILTER_3DB: case IIO_EV_INFO_HIGH_PASS_FILTER_3DB:
reg = i2c_smbus_read_byte_data(data->client, reg = i2c_smbus_read_byte_data(data->client,
MMA8452_TRANSIENT_CFG); MMA8452_TRANSIENT_CFG);
...@@ -497,6 +524,7 @@ static int mma8452_write_thresh(struct iio_dev *indio_dev, ...@@ -497,6 +524,7 @@ static int mma8452_write_thresh(struct iio_dev *indio_dev,
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
return mma8452_change_config(data, MMA8452_TRANSIENT_CFG, reg); return mma8452_change_config(data, MMA8452_TRANSIENT_CFG, reg);
default: default:
...@@ -606,7 +634,7 @@ static irqreturn_t mma8452_trigger_handler(int irq, void *p) ...@@ -606,7 +634,7 @@ static irqreturn_t mma8452_trigger_handler(int irq, void *p)
u8 buffer[16]; /* 3 16-bit channels + padding + ts */ u8 buffer[16]; /* 3 16-bit channels + padding + ts */
int ret; int ret;
ret = mma8452_read(data, (__be16 *) buffer); ret = mma8452_read(data, (__be16 *)buffer);
if (ret < 0) if (ret < 0)
goto done; goto done;
...@@ -615,6 +643,7 @@ static irqreturn_t mma8452_trigger_handler(int irq, void *p) ...@@ -615,6 +643,7 @@ static irqreturn_t mma8452_trigger_handler(int irq, void *p)
done: done:
iio_trigger_notify_done(indio_dev->trig); iio_trigger_notify_done(indio_dev->trig);
return IRQ_HANDLED; return IRQ_HANDLED;
} }
...@@ -778,6 +807,7 @@ static int mma8452_trigger_setup(struct iio_dev *indio_dev) ...@@ -778,6 +807,7 @@ static int mma8452_trigger_setup(struct iio_dev *indio_dev)
return ret; return ret;
indio_dev->trig = trig; indio_dev->trig = trig;
return 0; return 0;
} }
......
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