return ret;
}
- ret = kmx61_set_mode(data, mode, KMX61_ACC | KMX61_MAG, true);
- if (ret)
- return ret;
-
- return 0;
+ return kmx61_set_mode(data, mode, KMX61_ACC | KMX61_MAG, true);
}
static int kmx61_chip_update_thresholds(struct kmx61_data *data)
ret = i2c_smbus_write_byte_data(data->client,
KMX61_REG_WUF_THRESH,
data->wake_thresh);
- if (ret < 0) {
+ if (ret < 0)
dev_err(&data->client->dev, "Error writing reg_wuf_thresh\n");
- return ret;
- }
- return 0;
+ return ret;
}
static int kmx61_setup_any_motion_interrupt(struct kmx61_data *data,
return ret;
}
mode |= KMX61_ACT_STBY_BIT;
- ret = kmx61_set_mode(data, mode, KMX61_ACC | KMX61_MAG, true);
- if (ret)
- return ret;
-
- return 0;
+ return kmx61_set_mode(data, mode, KMX61_ACC | KMX61_MAG, true);
}
/**
switch (info) {
case IIO_EV_INFO_VALUE:
*val = data->wake_thresh;
- break;
+ return IIO_VAL_INT;
case IIO_EV_INFO_PERIOD:
*val = data->wake_duration;
- break;
+ return IIO_VAL_INT;
default:
return -EINVAL;
}
-
- return IIO_VAL_INT;
}
static int kmx61_write_event(struct iio_dev *indio_dev,
switch (info) {
case IIO_EV_INFO_VALUE:
data->wake_thresh = val;
- break;
+ return IIO_VAL_INT;
case IIO_EV_INFO_PERIOD:
data->wake_duration = val;
- break;
+ return IIO_VAL_INT;
default:
return -EINVAL;
}
-
- return IIO_VAL_INT;
}
static int kmx61_read_event_config(struct iio_dev *indio_dev,
int state)
{
struct kmx61_data *data = kmx61_get_data(indio_dev);
- int ret;
+ int ret = 0;
if (state && data->ev_enable_state)
return 0;
if (!state && data->motion_trig_on) {
data->ev_enable_state = 0;
- mutex_unlock(&data->lock);
- return 0;
+ goto err_unlock;
}
ret = kmx61_set_power_state(data, state, KMX61_ACC);
- if (ret < 0) {
- mutex_unlock(&data->lock);
- return ret;
- }
+ if (ret < 0)
+ goto err_unlock;
ret = kmx61_setup_any_motion_interrupt(data, state, KMX61_ACC);
if (ret < 0) {
kmx61_set_power_state(data, false, KMX61_ACC);
- mutex_unlock(&data->lock);
- return ret;
+ goto err_unlock;
}
data->ev_enable_state = state;
+
+err_unlock:
mutex_unlock(&data->lock);
- return 0;
+ return ret;
}
static int kmx61_acc_validate_trigger(struct iio_dev *indio_dev,
if (!state && data->ev_enable_state && data->motion_trig_on) {
data->motion_trig_on = false;
- mutex_unlock(&data->lock);
- return 0;
+ goto err_unlock;
}
device = KMX61_MAG;
ret = kmx61_set_power_state(data, state, device);
- if (ret < 0) {
- mutex_unlock(&data->lock);
- return ret;
- }
+ if (ret < 0)
+ goto err_unlock;
if (data->acc_dready_trig == trig || data->mag_dready_trig == trig)
ret = kmx61_setup_new_data_interrupt(data, state, device);
ret = kmx61_setup_any_motion_interrupt(data, state, KMX61_ACC);
if (ret < 0) {
kmx61_set_power_state(data, false, device);
- mutex_unlock(&data->lock);
- return ret;
+ goto err_unlock;
}
if (data->acc_dready_trig == trig)
data->mag_dready_trig_on = state;
else
data->motion_trig_on = state;
-
+err_unlock:
mutex_unlock(&data->lock);
- return 0;
+ return ret;
}
static int kmx61_trig_try_reenable(struct iio_trigger *trig)
ret |= KMX61_REG_CTRL1_BIT_RES;
ret = i2c_smbus_write_byte_data(data->client, KMX61_REG_CTRL1, ret);
if (ret < 0)
- dev_err(&data->client->dev, "Error reading reg_ctrl1\n");
+ dev_err(&data->client->dev, "Error writing reg_ctrl1\n");
ret = i2c_smbus_read_byte_data(data->client, KMX61_REG_INL);
if (ret < 0)
data->acc_dready_trig =
kmx61_trigger_setup(data, data->acc_indio_dev,
"dready");
- if (IS_ERR(data->acc_dready_trig))
- return PTR_ERR(data->acc_dready_trig);
+ if (IS_ERR(data->acc_dready_trig)) {
+ ret = PTR_ERR(data->acc_dready_trig);
+ goto err_chip_uninit;
+ }
data->mag_dready_trig =
kmx61_trigger_setup(data, data->mag_indio_dev,
"dready");
if (IS_ERR(data->mag_dready_trig)) {
ret = PTR_ERR(data->mag_dready_trig);
- goto err_trigger_unregister;
+ goto err_trigger_unregister_acc_dready;
}
data->motion_trig =
"any-motion");
if (IS_ERR(data->motion_trig)) {
ret = PTR_ERR(data->motion_trig);
- goto err_trigger_unregister;
+ goto err_trigger_unregister_mag_dready;
}
ret = iio_triggered_buffer_setup(data->acc_indio_dev,
if (ret < 0) {
dev_err(&data->client->dev,
"Failed to setup acc triggered buffer\n");
- goto err_trigger_unregister;
+ goto err_trigger_unregister_motion;
}
ret = iio_triggered_buffer_setup(data->mag_indio_dev,
if (ret < 0) {
dev_err(&data->client->dev,
"Failed to setup mag triggered buffer\n");
- goto err_trigger_unregister;
+ goto err_buffer_cleanup_acc;
}
}
ret = iio_device_register(data->acc_indio_dev);
if (ret < 0) {
dev_err(&client->dev, "Failed to register acc iio device\n");
- goto err_buffer_cleanup;
+ goto err_buffer_cleanup_mag;
}
ret = iio_device_register(data->mag_indio_dev);
iio_device_unregister(data->mag_indio_dev);
err_iio_unregister_acc:
iio_device_unregister(data->acc_indio_dev);
-err_buffer_cleanup:
- if (client->irq >= 0) {
- iio_triggered_buffer_cleanup(data->acc_indio_dev);
+err_buffer_cleanup_mag:
+ if (client->irq >= 0)
iio_triggered_buffer_cleanup(data->mag_indio_dev);
- }
-err_trigger_unregister:
- if (data->acc_dready_trig)
- iio_trigger_unregister(data->acc_dready_trig);
- if (data->mag_dready_trig)
- iio_trigger_unregister(data->mag_dready_trig);
- if (data->motion_trig)
- iio_trigger_unregister(data->motion_trig);
+err_buffer_cleanup_acc:
+ if (client->irq >= 0)
+ iio_triggered_buffer_cleanup(data->acc_indio_dev);
+err_trigger_unregister_motion:
+ iio_trigger_unregister(data->motion_trig);
+err_trigger_unregister_mag_dready:
+ iio_trigger_unregister(data->mag_dready_trig);
+err_trigger_unregister_acc_dready:
+ iio_trigger_unregister(data->acc_dready_trig);
err_chip_uninit:
kmx61_set_mode(data, KMX61_ALL_STBY, KMX61_ACC | KMX61_MAG, true);
return ret;