diff options
Diffstat (limited to 'drivers/iio/magnetometer')
-rw-r--r-- | drivers/iio/magnetometer/ak8974.c | 8 | ||||
-rw-r--r-- | drivers/iio/magnetometer/ak8975.c | 16 | ||||
-rw-r--r-- | drivers/iio/magnetometer/hid-sensor-magn-3d.c | 147 | ||||
-rw-r--r-- | drivers/iio/magnetometer/st_magn_core.c | 376 |
4 files changed, 250 insertions, 297 deletions
diff --git a/drivers/iio/magnetometer/ak8974.c b/drivers/iio/magnetometer/ak8974.c index 217353145676..ce09d771c1fb 100644 --- a/drivers/iio/magnetometer/ak8974.c +++ b/drivers/iio/magnetometer/ak8974.c @@ -287,7 +287,7 @@ static int ak8974_await_drdy(struct ak8974 *ak8974) return 0; } -static int ak8974_getresult(struct ak8974 *ak8974, s16 *result) +static int ak8974_getresult(struct ak8974 *ak8974, __le16 *result) { unsigned int src; int ret; @@ -395,7 +395,7 @@ static int ak8974_selftest(struct ak8974 *ak8974) static int ak8974_get_u16_val(struct ak8974 *ak8974, u8 reg, u16 *val) { int ret; - u16 bulk; + __le16 bulk; ret = regmap_bulk_read(ak8974->map, reg, &bulk, 2); if (ret) @@ -453,7 +453,7 @@ static int ak8974_read_raw(struct iio_dev *indio_dev, long mask) { struct ak8974 *ak8974 = iio_priv(indio_dev); - s16 hw_values[3]; + __le16 hw_values[3]; int ret = -EINVAL; pm_runtime_get_sync(&ak8974->i2c->dev); @@ -494,7 +494,7 @@ static void ak8974_fill_buffer(struct iio_dev *indio_dev) { struct ak8974 *ak8974 = iio_priv(indio_dev); int ret; - s16 hw_values[8]; /* Three axes + 64bit padding */ + __le16 hw_values[8]; /* Three axes + 64bit padding */ pm_runtime_get_sync(&ak8974->i2c->dev); mutex_lock(&ak8974->lock); diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c index af8606cc7812..825369fb1c57 100644 --- a/drivers/iio/magnetometer/ak8975.c +++ b/drivers/iio/magnetometer/ak8975.c @@ -690,6 +690,7 @@ static int ak8975_read_axis(struct iio_dev *indio_dev, int index, int *val) struct ak8975_data *data = iio_priv(indio_dev); const struct i2c_client *client = data->client; const struct ak_def *def = data->def; + __le16 rval; u16 buff; int ret; @@ -703,7 +704,7 @@ static int ak8975_read_axis(struct iio_dev *indio_dev, int index, int *val) ret = i2c_smbus_read_i2c_block_data_or_emulated( client, def->data_regs[index], - sizeof(buff), (u8*)&buff); + sizeof(rval), (u8*)&rval); if (ret < 0) goto exit; @@ -713,7 +714,7 @@ static int ak8975_read_axis(struct iio_dev *indio_dev, int index, int *val) pm_runtime_put_autosuspend(&data->client->dev); /* Swap bytes and convert to valid range. */ - buff = le16_to_cpu(buff); + buff = le16_to_cpu(rval); *val = clamp_t(s16, buff, -def->range, def->range); return IIO_VAL_INT; @@ -813,6 +814,7 @@ static void ak8975_fill_buffer(struct iio_dev *indio_dev) const struct ak_def *def = data->def; int ret; s16 buff[8]; /* 3 x 16 bits axis values + 1 aligned 64 bits timestamp */ + __le16 fval[3]; mutex_lock(&data->lock); @@ -826,17 +828,17 @@ static void ak8975_fill_buffer(struct iio_dev *indio_dev) */ ret = i2c_smbus_read_i2c_block_data_or_emulated(client, def->data_regs[0], - 3 * sizeof(buff[0]), - (u8 *)buff); + 3 * sizeof(fval[0]), + (u8 *)fval); if (ret < 0) goto unlock; mutex_unlock(&data->lock); /* Clamp to valid range. */ - buff[0] = clamp_t(s16, le16_to_cpu(buff[0]), -def->range, def->range); - buff[1] = clamp_t(s16, le16_to_cpu(buff[1]), -def->range, def->range); - buff[2] = clamp_t(s16, le16_to_cpu(buff[2]), -def->range, def->range); + buff[0] = clamp_t(s16, le16_to_cpu(fval[0]), -def->range, def->range); + buff[1] = clamp_t(s16, le16_to_cpu(fval[1]), -def->range, def->range); + buff[2] = clamp_t(s16, le16_to_cpu(fval[2]), -def->range, def->range); iio_push_to_buffers_with_timestamp(indio_dev, buff, iio_get_time_ns(indio_dev)); diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c index d8a0c8da8db0..0e791b02ed4a 100644 --- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c +++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c @@ -42,9 +42,17 @@ enum magn_3d_channel { MAGN_3D_CHANNEL_MAX, }; +struct common_attributes { + int scale_pre_decml; + int scale_post_decml; + int scale_precision; + int value_offset; +}; + struct magn_3d_state { struct hid_sensor_hub_callbacks callbacks; - struct hid_sensor_common common_attributes; + struct hid_sensor_common magn_flux_attributes; + struct hid_sensor_common rot_attributes; struct hid_sensor_hub_attribute_info magn[MAGN_3D_CHANNEL_MAX]; /* dynamically sized array to hold sensor values */ @@ -52,10 +60,8 @@ struct magn_3d_state { /* array of pointers to sensor value */ u32 *magn_val_addr[MAGN_3D_CHANNEL_MAX]; - int scale_pre_decml; - int scale_post_decml; - int scale_precision; - int value_offset; + struct common_attributes magn_flux_attr; + struct common_attributes rot_attr; }; static const u32 magn_3d_addresses[MAGN_3D_CHANNEL_MAX] = { @@ -162,41 +168,74 @@ static int magn_3d_read_raw(struct iio_dev *indio_dev, *val2 = 0; switch (mask) { case 0: - hid_sensor_power_state(&magn_state->common_attributes, true); + hid_sensor_power_state(&magn_state->magn_flux_attributes, true); report_id = magn_state->magn[chan->address].report_id; address = magn_3d_addresses[chan->address]; if (report_id >= 0) *val = sensor_hub_input_attr_get_raw_value( - magn_state->common_attributes.hsdev, + magn_state->magn_flux_attributes.hsdev, HID_USAGE_SENSOR_COMPASS_3D, address, report_id, SENSOR_HUB_SYNC); else { *val = 0; - hid_sensor_power_state(&magn_state->common_attributes, - false); + hid_sensor_power_state( + &magn_state->magn_flux_attributes, + false); return -EINVAL; } - hid_sensor_power_state(&magn_state->common_attributes, false); + hid_sensor_power_state(&magn_state->magn_flux_attributes, + false); ret_type = IIO_VAL_INT; break; case IIO_CHAN_INFO_SCALE: - *val = magn_state->scale_pre_decml; - *val2 = magn_state->scale_post_decml; - ret_type = magn_state->scale_precision; + switch (chan->type) { + case IIO_MAGN: + *val = magn_state->magn_flux_attr.scale_pre_decml; + *val2 = magn_state->magn_flux_attr.scale_post_decml; + ret_type = magn_state->magn_flux_attr.scale_precision; + break; + case IIO_ROT: + *val = magn_state->rot_attr.scale_pre_decml; + *val2 = magn_state->rot_attr.scale_post_decml; + ret_type = magn_state->rot_attr.scale_precision; + break; + default: + ret_type = -EINVAL; + } break; case IIO_CHAN_INFO_OFFSET: - *val = magn_state->value_offset; - ret_type = IIO_VAL_INT; + switch (chan->type) { + case IIO_MAGN: + *val = magn_state->magn_flux_attr.value_offset; + ret_type = IIO_VAL_INT; + break; + case IIO_ROT: + *val = magn_state->rot_attr.value_offset; + ret_type = IIO_VAL_INT; + break; + default: + ret_type = -EINVAL; + } break; case IIO_CHAN_INFO_SAMP_FREQ: ret_type = hid_sensor_read_samp_freq_value( - &magn_state->common_attributes, val, val2); + &magn_state->magn_flux_attributes, val, val2); break; case IIO_CHAN_INFO_HYSTERESIS: - ret_type = hid_sensor_read_raw_hyst_value( - &magn_state->common_attributes, val, val2); + switch (chan->type) { + case IIO_MAGN: + ret_type = hid_sensor_read_raw_hyst_value( + &magn_state->magn_flux_attributes, val, val2); + break; + case IIO_ROT: + ret_type = hid_sensor_read_raw_hyst_value( + &magn_state->rot_attributes, val, val2); + break; + default: + ret_type = -EINVAL; + } break; default: ret_type = -EINVAL; @@ -219,11 +258,21 @@ static int magn_3d_write_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_SAMP_FREQ: ret = hid_sensor_write_samp_freq_value( - &magn_state->common_attributes, val, val2); + &magn_state->magn_flux_attributes, val, val2); break; case IIO_CHAN_INFO_HYSTERESIS: - ret = hid_sensor_write_raw_hyst_value( - &magn_state->common_attributes, val, val2); + switch (chan->type) { + case IIO_MAGN: + ret = hid_sensor_write_raw_hyst_value( + &magn_state->magn_flux_attributes, val, val2); + break; + case IIO_ROT: + ret = hid_sensor_write_raw_hyst_value( + &magn_state->rot_attributes, val, val2); + break; + default: + ret = -EINVAL; + } break; default: ret = -EINVAL; @@ -254,7 +303,7 @@ static int magn_3d_proc_event(struct hid_sensor_hub_device *hsdev, struct magn_3d_state *magn_state = iio_priv(indio_dev); dev_dbg(&indio_dev->dev, "magn_3d_proc_event\n"); - if (atomic_read(&magn_state->common_attributes.data_ready)) + if (atomic_read(&magn_state->magn_flux_attributes.data_ready)) hid_sensor_push_data(indio_dev, magn_state->iio_vals); return 0; @@ -389,21 +438,48 @@ static int magn_3d_parse_report(struct platform_device *pdev, dev_dbg(&pdev->dev, "magn_3d Setup %d IIO channels\n", *chan_count); - st->scale_precision = hid_sensor_format_scale( + st->magn_flux_attr.scale_precision = hid_sensor_format_scale( HID_USAGE_SENSOR_COMPASS_3D, &st->magn[CHANNEL_SCAN_INDEX_X], - &st->scale_pre_decml, &st->scale_post_decml); + &st->magn_flux_attr.scale_pre_decml, + &st->magn_flux_attr.scale_post_decml); + st->rot_attr.scale_precision + = hid_sensor_format_scale( + HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH, + &st->magn[CHANNEL_SCAN_INDEX_NORTH_MAGN_TILT_COMP], + &st->rot_attr.scale_pre_decml, + &st->rot_attr.scale_post_decml); /* Set Sensitivity field ids, when there is no individual modifier */ - if (st->common_attributes.sensitivity.index < 0) { + if (st->magn_flux_attributes.sensitivity.index < 0) { sensor_hub_input_get_attribute_info(hsdev, HID_FEATURE_REPORT, usage_id, HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS | HID_USAGE_SENSOR_DATA_ORIENTATION, - &st->common_attributes.sensitivity); + &st->magn_flux_attributes.sensitivity); + dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n", + st->magn_flux_attributes.sensitivity.index, + st->magn_flux_attributes.sensitivity.report_id); + } + if (st->magn_flux_attributes.sensitivity.index < 0) { + sensor_hub_input_get_attribute_info(hsdev, + HID_FEATURE_REPORT, usage_id, + HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS | + HID_USAGE_SENSOR_ORIENT_MAGN_FLUX, + &st->magn_flux_attributes.sensitivity); + dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n", + st->magn_flux_attributes.sensitivity.index, + st->magn_flux_attributes.sensitivity.report_id); + } + if (st->rot_attributes.sensitivity.index < 0) { + sensor_hub_input_get_attribute_info(hsdev, + HID_FEATURE_REPORT, usage_id, + HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS | + HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH, + &st->rot_attributes.sensitivity); dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n", - st->common_attributes.sensitivity.index, - st->common_attributes.sensitivity.report_id); + st->rot_attributes.sensitivity.index, + st->rot_attributes.sensitivity.report_id); } return 0; @@ -428,16 +504,17 @@ static int hid_magn_3d_probe(struct platform_device *pdev) platform_set_drvdata(pdev, indio_dev); magn_state = iio_priv(indio_dev); - magn_state->common_attributes.hsdev = hsdev; - magn_state->common_attributes.pdev = pdev; + magn_state->magn_flux_attributes.hsdev = hsdev; + magn_state->magn_flux_attributes.pdev = pdev; ret = hid_sensor_parse_common_attributes(hsdev, HID_USAGE_SENSOR_COMPASS_3D, - &magn_state->common_attributes); + &magn_state->magn_flux_attributes); if (ret) { dev_err(&pdev->dev, "failed to setup common attributes\n"); return ret; } + magn_state->rot_attributes = magn_state->magn_flux_attributes; ret = magn_3d_parse_report(pdev, hsdev, &channels, &chan_count, @@ -460,9 +537,9 @@ static int hid_magn_3d_probe(struct platform_device *pdev) dev_err(&pdev->dev, "failed to initialize trigger buffer\n"); return ret; } - atomic_set(&magn_state->common_attributes.data_ready, 0); + atomic_set(&magn_state->magn_flux_attributes.data_ready, 0); ret = hid_sensor_setup_trigger(indio_dev, name, - &magn_state->common_attributes); + &magn_state->magn_flux_attributes); if (ret < 0) { dev_err(&pdev->dev, "trigger setup failed\n"); goto error_unreg_buffer_funcs; @@ -489,7 +566,7 @@ static int hid_magn_3d_probe(struct platform_device *pdev) error_iio_unreg: iio_device_unregister(indio_dev); error_remove_trigger: - hid_sensor_remove_trigger(&magn_state->common_attributes); + hid_sensor_remove_trigger(&magn_state->magn_flux_attributes); error_unreg_buffer_funcs: iio_triggered_buffer_cleanup(indio_dev); return ret; @@ -504,7 +581,7 @@ static int hid_magn_3d_remove(struct platform_device *pdev) sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_COMPASS_3D); iio_device_unregister(indio_dev); - hid_sensor_remove_trigger(&magn_state->common_attributes); + hid_sensor_remove_trigger(&magn_state->magn_flux_attributes); iio_triggered_buffer_cleanup(indio_dev); return 0; diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c index 3e1f06b2224c..8e1b0861fbe4 100644 --- a/drivers/iio/magnetometer/st_magn_core.c +++ b/drivers/iio/magnetometer/st_magn_core.c @@ -46,139 +46,12 @@ #define ST_MAGN_FS_AVL_15000MG 15000 #define ST_MAGN_FS_AVL_16000MG 16000 -/* CUSTOM VALUES FOR SENSOR 0 */ -#define ST_MAGN_0_ODR_ADDR 0x00 -#define ST_MAGN_0_ODR_MASK 0x1c -#define ST_MAGN_0_ODR_AVL_1HZ_VAL 0x00 -#define ST_MAGN_0_ODR_AVL_2HZ_VAL 0x01 -#define ST_MAGN_0_ODR_AVL_3HZ_VAL 0x02 -#define ST_MAGN_0_ODR_AVL_8HZ_VAL 0x03 -#define ST_MAGN_0_ODR_AVL_15HZ_VAL 0x04 -#define ST_MAGN_0_ODR_AVL_30HZ_VAL 0x05 -#define ST_MAGN_0_ODR_AVL_75HZ_VAL 0x06 -#define ST_MAGN_0_ODR_AVL_220HZ_VAL 0x07 -#define ST_MAGN_0_PW_ADDR 0x02 -#define ST_MAGN_0_PW_MASK 0x03 -#define ST_MAGN_0_PW_ON 0x00 -#define ST_MAGN_0_PW_OFF 0x03 -#define ST_MAGN_0_FS_ADDR 0x01 -#define ST_MAGN_0_FS_MASK 0xe0 -#define ST_MAGN_0_FS_AVL_1300_VAL 0x01 -#define ST_MAGN_0_FS_AVL_1900_VAL 0x02 -#define ST_MAGN_0_FS_AVL_2500_VAL 0x03 -#define ST_MAGN_0_FS_AVL_4000_VAL 0x04 -#define ST_MAGN_0_FS_AVL_4700_VAL 0x05 -#define ST_MAGN_0_FS_AVL_5600_VAL 0x06 -#define ST_MAGN_0_FS_AVL_8100_VAL 0x07 -#define ST_MAGN_0_FS_AVL_1300_GAIN_XY 1100 -#define ST_MAGN_0_FS_AVL_1900_GAIN_XY 855 -#define ST_MAGN_0_FS_AVL_2500_GAIN_XY 670 -#define ST_MAGN_0_FS_AVL_4000_GAIN_XY 450 -#define ST_MAGN_0_FS_AVL_4700_GAIN_XY 400 -#define ST_MAGN_0_FS_AVL_5600_GAIN_XY 330 -#define ST_MAGN_0_FS_AVL_8100_GAIN_XY 230 -#define ST_MAGN_0_FS_AVL_1300_GAIN_Z 980 -#define ST_MAGN_0_FS_AVL_1900_GAIN_Z 760 -#define ST_MAGN_0_FS_AVL_2500_GAIN_Z 600 -#define ST_MAGN_0_FS_AVL_4000_GAIN_Z 400 -#define ST_MAGN_0_FS_AVL_4700_GAIN_Z 355 -#define ST_MAGN_0_FS_AVL_5600_GAIN_Z 295 -#define ST_MAGN_0_FS_AVL_8100_GAIN_Z 205 -#define ST_MAGN_0_MULTIREAD_BIT false - -/* CUSTOM VALUES FOR SENSOR 1 */ -#define ST_MAGN_1_WAI_EXP 0x3c -#define ST_MAGN_1_ODR_ADDR 0x00 -#define ST_MAGN_1_ODR_MASK 0x1c -#define ST_MAGN_1_ODR_AVL_1HZ_VAL 0x00 -#define ST_MAGN_1_ODR_AVL_2HZ_VAL 0x01 -#define ST_MAGN_1_ODR_AVL_3HZ_VAL 0x02 -#define ST_MAGN_1_ODR_AVL_8HZ_VAL 0x03 -#define ST_MAGN_1_ODR_AVL_15HZ_VAL 0x04 -#define ST_MAGN_1_ODR_AVL_30HZ_VAL 0x05 -#define ST_MAGN_1_ODR_AVL_75HZ_VAL 0x06 -#define ST_MAGN_1_ODR_AVL_220HZ_VAL 0x07 -#define ST_MAGN_1_PW_ADDR 0x02 -#define ST_MAGN_1_PW_MASK 0x03 -#define ST_MAGN_1_PW_ON 0x00 -#define ST_MAGN_1_PW_OFF 0x03 -#define ST_MAGN_1_FS_ADDR 0x01 -#define ST_MAGN_1_FS_MASK 0xe0 -#define ST_MAGN_1_FS_AVL_1300_VAL 0x01 -#define ST_MAGN_1_FS_AVL_1900_VAL 0x02 -#define ST_MAGN_1_FS_AVL_2500_VAL 0x03 -#define ST_MAGN_1_FS_AVL_4000_VAL 0x04 -#define ST_MAGN_1_FS_AVL_4700_VAL 0x05 -#define ST_MAGN_1_FS_AVL_5600_VAL 0x06 -#define ST_MAGN_1_FS_AVL_8100_VAL 0x07 -#define ST_MAGN_1_FS_AVL_1300_GAIN_XY 909 -#define ST_MAGN_1_FS_AVL_1900_GAIN_XY 1169 -#define ST_MAGN_1_FS_AVL_2500_GAIN_XY 1492 -#define ST_MAGN_1_FS_AVL_4000_GAIN_XY 2222 -#define ST_MAGN_1_FS_AVL_4700_GAIN_XY 2500 -#define ST_MAGN_1_FS_AVL_5600_GAIN_XY 3030 -#define ST_MAGN_1_FS_AVL_8100_GAIN_XY 4347 -#define ST_MAGN_1_FS_AVL_1300_GAIN_Z 1020 -#define ST_MAGN_1_FS_AVL_1900_GAIN_Z 1315 -#define ST_MAGN_1_FS_AVL_2500_GAIN_Z 1666 -#define ST_MAGN_1_FS_AVL_4000_GAIN_Z 2500 -#define ST_MAGN_1_FS_AVL_4700_GAIN_Z 2816 -#define ST_MAGN_1_FS_AVL_5600_GAIN_Z 3389 -#define ST_MAGN_1_FS_AVL_8100_GAIN_Z 4878 -#define ST_MAGN_1_MULTIREAD_BIT false - -/* CUSTOM VALUES FOR SENSOR 2 */ -#define ST_MAGN_2_WAI_EXP 0x3d -#define ST_MAGN_2_ODR_ADDR 0x20 -#define ST_MAGN_2_ODR_MASK 0x1c -#define ST_MAGN_2_ODR_AVL_1HZ_VAL 0x00 -#define ST_MAGN_2_ODR_AVL_2HZ_VAL 0x01 -#define ST_MAGN_2_ODR_AVL_3HZ_VAL 0x02 -#define ST_MAGN_2_ODR_AVL_5HZ_VAL 0x03 -#define ST_MAGN_2_ODR_AVL_10HZ_VAL 0x04 -#define ST_MAGN_2_ODR_AVL_20HZ_VAL 0x05 -#define ST_MAGN_2_ODR_AVL_40HZ_VAL 0x06 -#define ST_MAGN_2_ODR_AVL_80HZ_VAL 0x07 -#define ST_MAGN_2_PW_ADDR 0x22 -#define ST_MAGN_2_PW_MASK 0x03 -#define ST_MAGN_2_PW_ON 0x00 -#define ST_MAGN_2_PW_OFF 0x03 -#define ST_MAGN_2_FS_ADDR 0x21 -#define ST_MAGN_2_FS_MASK 0x60 -#define ST_MAGN_2_FS_AVL_4000_VAL 0x00 -#define ST_MAGN_2_FS_AVL_8000_VAL 0x01 -#define ST_MAGN_2_FS_AVL_12000_VAL 0x02 -#define ST_MAGN_2_FS_AVL_16000_VAL 0x03 -#define ST_MAGN_2_FS_AVL_4000_GAIN 146 -#define ST_MAGN_2_FS_AVL_8000_GAIN 292 -#define ST_MAGN_2_FS_AVL_12000_GAIN 438 -#define ST_MAGN_2_FS_AVL_16000_GAIN 584 -#define ST_MAGN_2_MULTIREAD_BIT false +/* Special L addresses for Sensor 2 */ #define ST_MAGN_2_OUT_X_L_ADDR 0x28 #define ST_MAGN_2_OUT_Y_L_ADDR 0x2a #define ST_MAGN_2_OUT_Z_L_ADDR 0x2c -/* CUSTOM VALUES FOR SENSOR 3 */ -#define ST_MAGN_3_WAI_ADDR 0x4f -#define ST_MAGN_3_WAI_EXP 0x40 -#define ST_MAGN_3_ODR_ADDR 0x60 -#define ST_MAGN_3_ODR_MASK 0x0c -#define ST_MAGN_3_ODR_AVL_10HZ_VAL 0x00 -#define ST_MAGN_3_ODR_AVL_20HZ_VAL 0x01 -#define ST_MAGN_3_ODR_AVL_50HZ_VAL 0x02 -#define ST_MAGN_3_ODR_AVL_100HZ_VAL 0x03 -#define ST_MAGN_3_PW_ADDR 0x60 -#define ST_MAGN_3_PW_MASK 0x03 -#define ST_MAGN_3_PW_ON 0x00 -#define ST_MAGN_3_PW_OFF 0x03 -#define ST_MAGN_3_BDU_ADDR 0x62 -#define ST_MAGN_3_BDU_MASK 0x10 -#define ST_MAGN_3_DRDY_IRQ_ADDR 0x62 -#define ST_MAGN_3_DRDY_INT_MASK 0x01 -#define ST_MAGN_3_IHL_IRQ_ADDR 0x63 -#define ST_MAGN_3_IHL_IRQ_MASK 0x04 -#define ST_MAGN_3_FS_AVL_15000_GAIN 1500 -#define ST_MAGN_3_MULTIREAD_BIT false +/* Special L addresses for sensor 3 */ #define ST_MAGN_3_OUT_X_L_ADDR 0x68 #define ST_MAGN_3_OUT_Y_L_ADDR 0x6a #define ST_MAGN_3_OUT_Z_L_ADDR 0x6c @@ -240,77 +113,78 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = { }, .ch = (struct iio_chan_spec *)st_magn_16bit_channels, .odr = { - .addr = ST_MAGN_0_ODR_ADDR, - .mask = ST_MAGN_0_ODR_MASK, + .addr = 0x00, + .mask = 0x1c, .odr_avl = { - { 1, ST_MAGN_0_ODR_AVL_1HZ_VAL, }, - { 2, ST_MAGN_0_ODR_AVL_2HZ_VAL, }, - { 3, ST_MAGN_0_ODR_AVL_3HZ_VAL, }, - { 8, ST_MAGN_0_ODR_AVL_8HZ_VAL, }, - { 15, ST_MAGN_0_ODR_AVL_15HZ_VAL, }, - { 30, ST_MAGN_0_ODR_AVL_30HZ_VAL, }, - { 75, ST_MAGN_0_ODR_AVL_75HZ_VAL, }, + { .hz = 1, .value = 0x00 }, + { .hz = 2, .value = 0x01 }, + { .hz = 3, .value = 0x02 }, + { .hz = 8, .value = 0x03 }, + { .hz = 15, .value = 0x04 }, + { .hz = 30, .value = 0x05 }, + { .hz = 75, .value = 0x06 }, + /* 220 Hz, 0x07 reportedly exist */ }, }, .pw = { - .addr = ST_MAGN_0_PW_ADDR, - .mask = ST_MAGN_0_PW_MASK, - .value_on = ST_MAGN_0_PW_ON, - .value_off = ST_MAGN_0_PW_OFF, + .addr = 0x02, + .mask = 0x03, + .value_on = 0x00, + .value_off = 0x03, }, .fs = { - .addr = ST_MAGN_0_FS_ADDR, - .mask = ST_MAGN_0_FS_MASK, + .addr = 0x01, + .mask = 0xe0, .fs_avl = { [0] = { .num = ST_MAGN_FS_AVL_1300MG, - .value = ST_MAGN_0_FS_AVL_1300_VAL, - .gain = ST_MAGN_0_FS_AVL_1300_GAIN_XY, - .gain2 = ST_MAGN_0_FS_AVL_1300_GAIN_Z, + .value = 0x01, + .gain = 1100, + .gain2 = 980, }, [1] = { .num = ST_MAGN_FS_AVL_1900MG, - .value = ST_MAGN_0_FS_AVL_1900_VAL, - .gain = ST_MAGN_0_FS_AVL_1900_GAIN_XY, - .gain2 = ST_MAGN_0_FS_AVL_1900_GAIN_Z, + .value = 0x02, + .gain = 855, + .gain2 = 760, }, [2] = { .num = ST_MAGN_FS_AVL_2500MG, - .value = ST_MAGN_0_FS_AVL_2500_VAL, - .gain = ST_MAGN_0_FS_AVL_2500_GAIN_XY, - .gain2 = ST_MAGN_0_FS_AVL_2500_GAIN_Z, + .value = 0x03, + .gain = 670, + .gain2 = 600, }, [3] = { .num = ST_MAGN_FS_AVL_4000MG, - .value = ST_MAGN_0_FS_AVL_4000_VAL, - .gain = ST_MAGN_0_FS_AVL_4000_GAIN_XY, - .gain2 = ST_MAGN_0_FS_AVL_4000_GAIN_Z, + .value = 0x04, + .gain = 450, + .gain2 = 400, }, [4] = { .num = ST_MAGN_FS_AVL_4700MG, - .value = ST_MAGN_0_FS_AVL_4700_VAL, - .gain = ST_MAGN_0_FS_AVL_4700_GAIN_XY, - .gain2 = ST_MAGN_0_FS_AVL_4700_GAIN_Z, + .value = 0x05, + .gain = 400, + .gain2 = 355, }, [5] = { .num = ST_MAGN_FS_AVL_5600MG, - .value = ST_MAGN_0_FS_AVL_5600_VAL, - .gain = ST_MAGN_0_FS_AVL_5600_GAIN_XY, - .gain2 = ST_MAGN_0_FS_AVL_5600_GAIN_Z, + .value = 0x06, + .gain = 330, + .gain2 = 295, }, [6] = { .num = ST_MAGN_FS_AVL_8100MG, - .value = ST_MAGN_0_FS_AVL_8100_VAL, - .gain = ST_MAGN_0_FS_AVL_8100_GAIN_XY, - .gain2 = ST_MAGN_0_FS_AVL_8100_GAIN_Z, + .value = 0x07, + .gain = 230, + .gain2 = 205, }, }, }, - .multi_read_bit = ST_MAGN_0_MULTIREAD_BIT, + .multi_read_bit = false, .bootime = 2, }, { - .wai = ST_MAGN_1_WAI_EXP, + .wai = 0x3c, .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS, .sensors_supported = { [0] = LSM303DLHC_MAGN_DEV_NAME, @@ -318,175 +192,175 @@ static const struct st_sensor_settings st_magn_sensors_settings[] = { }, .ch = (struct iio_chan_spec *)st_magn_16bit_channels, .odr = { - .addr = ST_MAGN_1_ODR_ADDR, - .mask = ST_MAGN_1_ODR_MASK, + .addr = 0x00, + .mask = 0x1c, .odr_avl = { - { 1, ST_MAGN_1_ODR_AVL_1HZ_VAL, }, - { 2, ST_MAGN_1_ODR_AVL_2HZ_VAL, }, - { 3, ST_MAGN_1_ODR_AVL_3HZ_VAL, }, - { 8, ST_MAGN_1_ODR_AVL_8HZ_VAL, }, - { 15, ST_MAGN_1_ODR_AVL_15HZ_VAL, }, - { 30, ST_MAGN_1_ODR_AVL_30HZ_VAL, }, - { 75, ST_MAGN_1_ODR_AVL_75HZ_VAL, }, - { 220, ST_MAGN_1_ODR_AVL_220HZ_VAL, }, + { .hz = 1, .value = 0x00 }, + { .hz = 2, .value = 0x01 }, + { .hz = 3, .value = 0x02 }, + { .hz = 8, .value = 0x03 }, + { .hz = 15, .value = 0x04 }, + { .hz = 30, .value = 0x05 }, + { .hz = 75, .value = 0x06 }, + { .hz = 220, .value = 0x07 }, }, }, .pw = { - .addr = ST_MAGN_1_PW_ADDR, - .mask = ST_MAGN_1_PW_MASK, - .value_on = ST_MAGN_1_PW_ON, - .value_off = ST_MAGN_1_PW_OFF, + .addr = 0x02, + .mask = 0x03, + .value_on = 0x00, + .value_off = 0x03, }, .fs = { - .addr = ST_MAGN_1_FS_ADDR, - .mask = ST_MAGN_1_FS_MASK, + .addr = 0x01, + .mask = 0xe0, .fs_avl = { [0] = { .num = ST_MAGN_FS_AVL_1300MG, - .value = ST_MAGN_1_FS_AVL_1300_VAL, - .gain = ST_MAGN_1_FS_AVL_1300_GAIN_XY, - .gain2 = ST_MAGN_1_FS_AVL_1300_GAIN_Z, + .value = 0x01, + .gain = 909, + .gain2 = 1020, }, [1] = { .num = ST_MAGN_FS_AVL_1900MG, - .value = ST_MAGN_1_FS_AVL_1900_VAL, - .gain = ST_MAGN_1_FS_AVL_1900_GAIN_XY, - .gain2 = ST_MAGN_1_FS_AVL_1900_GAIN_Z, + .value = 0x02, + .gain = 1169, + .gain2 = 1315, }, [2] = { .num = ST_MAGN_FS_AVL_2500MG, - .value = ST_MAGN_1_FS_AVL_2500_VAL, - .gain = ST_MAGN_1_FS_AVL_2500_GAIN_XY, - .gain2 = ST_MAGN_1_FS_AVL_2500_GAIN_Z, + .value = 0x03, + .gain = 1492, + .gain2 = 1666, }, [3] = { .num = ST_MAGN_FS_AVL_4000MG, - .value = ST_MAGN_1_FS_AVL_4000_VAL, - .gain = ST_MAGN_1_FS_AVL_4000_GAIN_XY, - .gain2 = ST_MAGN_1_FS_AVL_4000_GAIN_Z, + .value = 0x04, + .gain = 2222, + .gain2 = 2500, }, [4] = { .num = ST_MAGN_FS_AVL_4700MG, - .value = ST_MAGN_1_FS_AVL_4700_VAL, - .gain = ST_MAGN_1_FS_AVL_4700_GAIN_XY, - .gain2 = ST_MAGN_1_FS_AVL_4700_GAIN_Z, + .value = 0x05, + .gain = 2500, + .gain2 = 2816, }, [5] = { .num = ST_MAGN_FS_AVL_5600MG, - .value = ST_MAGN_1_FS_AVL_5600_VAL, - .gain = ST_MAGN_1_FS_AVL_5600_GAIN_XY, - .gain2 = ST_MAGN_1_FS_AVL_5600_GAIN_Z, + .value = 0x06, + .gain = 3030, + .gain2 = 3389, }, [6] = { .num = ST_MAGN_FS_AVL_8100MG, - .value = ST_MAGN_1_FS_AVL_8100_VAL, - .gain = ST_MAGN_1_FS_AVL_8100_GAIN_XY, - .gain2 = ST_MAGN_1_FS_AVL_8100_GAIN_Z, + .value = 0x07, + .gain = 4347, + .gain2 = 4878, }, }, }, - .multi_read_bit = ST_MAGN_1_MULTIREAD_BIT, + .multi_read_bit = false, .bootime = 2, }, { - .wai = ST_MAGN_2_WAI_EXP, + .wai = 0x3d, .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS, .sensors_supported = { [0] = LIS3MDL_MAGN_DEV_NAME, }, .ch = (struct iio_chan_spec *)st_magn_2_16bit_channels, .odr = { - .addr = ST_MAGN_2_ODR_ADDR, - .mask = ST_MAGN_2_ODR_MASK, + .addr = 0x20, + .mask = 0x1c, .odr_avl = { - { 1, ST_MAGN_2_ODR_AVL_1HZ_VAL, }, - { 2, ST_MAGN_2_ODR_AVL_2HZ_VAL, }, - { 3, ST_MAGN_2_ODR_AVL_3HZ_VAL, }, - { 5, ST_MAGN_2_ODR_AVL_5HZ_VAL, }, - { 10, ST_MAGN_2_ODR_AVL_10HZ_VAL, }, - { 20, ST_MAGN_2_ODR_AVL_20HZ_VAL, }, - { 40, ST_MAGN_2_ODR_AVL_40HZ_VAL, }, - { 80, ST_MAGN_2_ODR_AVL_80HZ_VAL, }, + { .hz = 1, .value = 0x00 }, + { .hz = 2, .value = 0x01 }, + { .hz = 3, .value = 0x02 }, + { .hz = 5, .value = 0x03 }, + { .hz = 10, .value = 0x04 }, + { .hz = 20, .value = 0x05 }, + { .hz = 40, .value = 0x06 }, + { .hz = 80, .value = 0x07 }, }, }, .pw = { - .addr = ST_MAGN_2_PW_ADDR, - .mask = ST_MAGN_2_PW_MASK, - .value_on = ST_MAGN_2_PW_ON, - .value_off = ST_MAGN_2_PW_OFF, + .addr = 0x22, + .mask = 0x03, + .value_on = 0x00, + .value_off = 0x03, }, .fs = { - .addr = ST_MAGN_2_FS_ADDR, - .mask = ST_MAGN_2_FS_MASK, + .addr = 0x21, + .mask = 0x60, .fs_avl = { [0] = { .num = ST_MAGN_FS_AVL_4000MG, - .value = ST_MAGN_2_FS_AVL_4000_VAL, - .gain = ST_MAGN_2_FS_AVL_4000_GAIN, + .value = 0x00, + .gain = 146, }, [1] = { .num = ST_MAGN_FS_AVL_8000MG, - .value = ST_MAGN_2_FS_AVL_8000_VAL, - .gain = ST_MAGN_2_FS_AVL_8000_GAIN, + .value = 0x01, + .gain = 292, }, [2] = { .num = ST_MAGN_FS_AVL_12000MG, - .value = ST_MAGN_2_FS_AVL_12000_VAL, - .gain = ST_MAGN_2_FS_AVL_12000_GAIN, + .value = 0x02, + .gain = 438, }, [3] = { .num = ST_MAGN_FS_AVL_16000MG, - .value = ST_MAGN_2_FS_AVL_16000_VAL, - .gain = ST_MAGN_2_FS_AVL_16000_GAIN, + .value = 0x03, + .gain = 584, }, }, }, - .multi_read_bit = ST_MAGN_2_MULTIREAD_BIT, + .multi_read_bit = false, .bootime = 2, }, { - .wai = ST_MAGN_3_WAI_EXP, - .wai_addr = ST_MAGN_3_WAI_ADDR, + .wai = 0x40, + .wai_addr = 0x4f, .sensors_supported = { [0] = LSM303AGR_MAGN_DEV_NAME, }, .ch = (struct iio_chan_spec *)st_magn_3_16bit_channels, .odr = { - .addr = ST_MAGN_3_ODR_ADDR, - .mask = ST_MAGN_3_ODR_MASK, + .addr = 0x60, + .mask = 0x0c, .odr_avl = { - { 10, ST_MAGN_3_ODR_AVL_10HZ_VAL, }, - { 20, ST_MAGN_3_ODR_AVL_20HZ_VAL, }, - { 50, ST_MAGN_3_ODR_AVL_50HZ_VAL, }, - { 100, ST_MAGN_3_ODR_AVL_100HZ_VAL, }, + { .hz = 10, .value = 0x00 }, + { .hz = 20, .value = 0x01 }, + { .hz = 50, .value = 0x02 }, + { .hz = 100, .value = 0x03 }, }, }, .pw = { - .addr = ST_MAGN_3_PW_ADDR, - .mask = ST_MAGN_3_PW_MASK, - .value_on = ST_MAGN_3_PW_ON, - .value_off = ST_MAGN_3_PW_OFF, + .addr = 0x60, + .mask = 0x03, + .value_on = 0x00, + .value_off = 0x03, }, .fs = { .fs_avl = { [0] = { .num = ST_MAGN_FS_AVL_15000MG, - .gain = ST_MAGN_3_FS_AVL_15000_GAIN, + .gain = 1500, }, }, }, .bdu = { - .addr = ST_MAGN_3_BDU_ADDR, - .mask = ST_MAGN_3_BDU_MASK, + .addr = 0x62, + .mask = 0x10, }, .drdy_irq = { - .addr = ST_MAGN_3_DRDY_IRQ_ADDR, - .mask_int1 = ST_MAGN_3_DRDY_INT_MASK, - .addr_ihl = ST_MAGN_3_IHL_IRQ_ADDR, - .mask_ihl = ST_MAGN_3_IHL_IRQ_MASK, + .addr = 0x62, + .mask_int1 = 0x01, + .addr_ihl = 0x63, + .mask_ihl = 0x04, .addr_stat_drdy = ST_SENSORS_DEFAULT_STAT_ADDR, }, - .multi_read_bit = ST_MAGN_3_MULTIREAD_BIT, + .multi_read_bit = false, .bootime = 2, }, }; |