Loading drivers/iio/accel/mma9553.c +33 −68 Original line number Diff line number Diff line Loading @@ -441,78 +441,64 @@ static int mma9553_init(struct mma9553_data *data) return mma9551_set_device_state(data->client, true); } static int mma9553_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) static int mma9553_read_status_word(struct mma9553_data *data, u16 reg, u16 *tmp) { struct mma9553_data *data = iio_priv(indio_dev); int ret; u16 tmp; u8 activity; bool powered_on; int ret; switch (mask) { case IIO_CHAN_INFO_PROCESSED: switch (chan->type) { case IIO_STEPS: /* * The HW only counts steps and other dependent * parameters (speed, distance, calories, activity) * if power is on (from enabling an event or the * step counter). */ powered_on = mma9553_is_any_event_enabled(data, false, 0) || powered_on = mma9553_is_any_event_enabled(data, false, 0) || data->stepcnt_enabled; if (!powered_on) { dev_err(&data->client->dev, "No channels enabled\n"); dev_err(&data->client->dev, "No channels enabled\n"); return -EINVAL; } mutex_lock(&data->mutex); ret = mma9551_read_status_word(data->client, MMA9551_APPID_PEDOMETER, ret = mma9551_read_status_word(data->client, MMA9551_APPID_PEDOMETER, reg, tmp); mutex_unlock(&data->mutex); return ret; } static int mma9553_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) { struct mma9553_data *data = iio_priv(indio_dev); int ret; u16 tmp; u8 activity; switch (mask) { case IIO_CHAN_INFO_PROCESSED: switch (chan->type) { case IIO_STEPS: ret = mma9553_read_status_word(data, MMA9553_REG_STEPCNT, &tmp); mutex_unlock(&data->mutex); if (ret < 0) return ret; *val = tmp; return IIO_VAL_INT; case IIO_DISTANCE: powered_on = mma9553_is_any_event_enabled(data, false, 0) || data->stepcnt_enabled; if (!powered_on) { dev_err(&data->client->dev, "No channels enabled\n"); return -EINVAL; } mutex_lock(&data->mutex); ret = mma9551_read_status_word(data->client, MMA9551_APPID_PEDOMETER, ret = mma9553_read_status_word(data, MMA9553_REG_DISTANCE, &tmp); mutex_unlock(&data->mutex); if (ret < 0) return ret; *val = tmp; return IIO_VAL_INT; case IIO_ACTIVITY: powered_on = mma9553_is_any_event_enabled(data, false, 0) || data->stepcnt_enabled; if (!powered_on) { dev_err(&data->client->dev, "No channels enabled\n"); return -EINVAL; } mutex_lock(&data->mutex); ret = mma9551_read_status_word(data->client, MMA9551_APPID_PEDOMETER, ret = mma9553_read_status_word(data, MMA9553_REG_STATUS, &tmp); mutex_unlock(&data->mutex); if (ret < 0) return ret; Loading @@ -537,38 +523,17 @@ static int mma9553_read_raw(struct iio_dev *indio_dev, case IIO_VELOCITY: /* m/h */ if (chan->channel2 != IIO_MOD_ROOT_SUM_SQUARED_X_Y_Z) return -EINVAL; powered_on = mma9553_is_any_event_enabled(data, false, 0) || data->stepcnt_enabled; if (!powered_on) { dev_err(&data->client->dev, "No channels enabled\n"); return -EINVAL; } mutex_lock(&data->mutex); ret = mma9551_read_status_word(data->client, MMA9551_APPID_PEDOMETER, MMA9553_REG_SPEED, &tmp); mutex_unlock(&data->mutex); ret = mma9553_read_status_word(data, MMA9553_REG_SPEED, &tmp); if (ret < 0) return ret; *val = tmp; return IIO_VAL_INT; case IIO_ENERGY: /* Cal or kcal */ powered_on = mma9553_is_any_event_enabled(data, false, 0) || data->stepcnt_enabled; if (!powered_on) { dev_err(&data->client->dev, "No channels enabled\n"); return -EINVAL; } mutex_lock(&data->mutex); ret = mma9551_read_status_word(data->client, MMA9551_APPID_PEDOMETER, ret = mma9553_read_status_word(data, MMA9553_REG_CALORIES, &tmp); mutex_unlock(&data->mutex); if (ret < 0) return ret; *val = tmp; Loading Loading
drivers/iio/accel/mma9553.c +33 −68 Original line number Diff line number Diff line Loading @@ -441,78 +441,64 @@ static int mma9553_init(struct mma9553_data *data) return mma9551_set_device_state(data->client, true); } static int mma9553_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) static int mma9553_read_status_word(struct mma9553_data *data, u16 reg, u16 *tmp) { struct mma9553_data *data = iio_priv(indio_dev); int ret; u16 tmp; u8 activity; bool powered_on; int ret; switch (mask) { case IIO_CHAN_INFO_PROCESSED: switch (chan->type) { case IIO_STEPS: /* * The HW only counts steps and other dependent * parameters (speed, distance, calories, activity) * if power is on (from enabling an event or the * step counter). */ powered_on = mma9553_is_any_event_enabled(data, false, 0) || powered_on = mma9553_is_any_event_enabled(data, false, 0) || data->stepcnt_enabled; if (!powered_on) { dev_err(&data->client->dev, "No channels enabled\n"); dev_err(&data->client->dev, "No channels enabled\n"); return -EINVAL; } mutex_lock(&data->mutex); ret = mma9551_read_status_word(data->client, MMA9551_APPID_PEDOMETER, ret = mma9551_read_status_word(data->client, MMA9551_APPID_PEDOMETER, reg, tmp); mutex_unlock(&data->mutex); return ret; } static int mma9553_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) { struct mma9553_data *data = iio_priv(indio_dev); int ret; u16 tmp; u8 activity; switch (mask) { case IIO_CHAN_INFO_PROCESSED: switch (chan->type) { case IIO_STEPS: ret = mma9553_read_status_word(data, MMA9553_REG_STEPCNT, &tmp); mutex_unlock(&data->mutex); if (ret < 0) return ret; *val = tmp; return IIO_VAL_INT; case IIO_DISTANCE: powered_on = mma9553_is_any_event_enabled(data, false, 0) || data->stepcnt_enabled; if (!powered_on) { dev_err(&data->client->dev, "No channels enabled\n"); return -EINVAL; } mutex_lock(&data->mutex); ret = mma9551_read_status_word(data->client, MMA9551_APPID_PEDOMETER, ret = mma9553_read_status_word(data, MMA9553_REG_DISTANCE, &tmp); mutex_unlock(&data->mutex); if (ret < 0) return ret; *val = tmp; return IIO_VAL_INT; case IIO_ACTIVITY: powered_on = mma9553_is_any_event_enabled(data, false, 0) || data->stepcnt_enabled; if (!powered_on) { dev_err(&data->client->dev, "No channels enabled\n"); return -EINVAL; } mutex_lock(&data->mutex); ret = mma9551_read_status_word(data->client, MMA9551_APPID_PEDOMETER, ret = mma9553_read_status_word(data, MMA9553_REG_STATUS, &tmp); mutex_unlock(&data->mutex); if (ret < 0) return ret; Loading @@ -537,38 +523,17 @@ static int mma9553_read_raw(struct iio_dev *indio_dev, case IIO_VELOCITY: /* m/h */ if (chan->channel2 != IIO_MOD_ROOT_SUM_SQUARED_X_Y_Z) return -EINVAL; powered_on = mma9553_is_any_event_enabled(data, false, 0) || data->stepcnt_enabled; if (!powered_on) { dev_err(&data->client->dev, "No channels enabled\n"); return -EINVAL; } mutex_lock(&data->mutex); ret = mma9551_read_status_word(data->client, MMA9551_APPID_PEDOMETER, MMA9553_REG_SPEED, &tmp); mutex_unlock(&data->mutex); ret = mma9553_read_status_word(data, MMA9553_REG_SPEED, &tmp); if (ret < 0) return ret; *val = tmp; return IIO_VAL_INT; case IIO_ENERGY: /* Cal or kcal */ powered_on = mma9553_is_any_event_enabled(data, false, 0) || data->stepcnt_enabled; if (!powered_on) { dev_err(&data->client->dev, "No channels enabled\n"); return -EINVAL; } mutex_lock(&data->mutex); ret = mma9551_read_status_word(data->client, MMA9551_APPID_PEDOMETER, ret = mma9553_read_status_word(data, MMA9553_REG_CALORIES, &tmp); mutex_unlock(&data->mutex); if (ret < 0) return ret; *val = tmp; Loading