Lines Matching +full:sensor +full:- +full:gain
5 * slave devices using accelerometer sensor as trigger for i2c
61 .gain = 1500,
120 .gain = 146,
124 .gain = 292,
128 .gain = 438,
132 .gain = 584,
158 struct st_lsm6dsx_sensor *sensor; in st_lsm6dsx_shub_wait_complete() local
161 sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_ACC]); in st_lsm6dsx_shub_wait_complete()
162 odr = (hw->enable_mask & BIT(ST_LSM6DSX_ID_ACC)) ? sensor->odr : 12500; in st_lsm6dsx_shub_wait_complete()
169 * st_lsm6dsx_shub_read_output - read i2c controller register
178 mutex_lock(&hw->page_lock); in st_lsm6dsx_shub_read_output()
180 hub_settings = &hw->settings->shub_settings; in st_lsm6dsx_shub_read_output()
181 if (hub_settings->shub_out.sec_page) { in st_lsm6dsx_shub_read_output()
187 err = regmap_bulk_read(hw->regmap, hub_settings->shub_out.addr, in st_lsm6dsx_shub_read_output()
190 if (hub_settings->shub_out.sec_page) in st_lsm6dsx_shub_read_output()
193 mutex_unlock(&hw->page_lock); in st_lsm6dsx_shub_read_output()
199 * st_lsm6dsx_shub_write_reg - write i2c controller register
208 mutex_lock(&hw->page_lock); in st_lsm6dsx_shub_write_reg()
213 err = regmap_bulk_write(hw->regmap, addr, data, len); in st_lsm6dsx_shub_write_reg()
217 mutex_unlock(&hw->page_lock); in st_lsm6dsx_shub_write_reg()
228 mutex_lock(&hw->page_lock); in st_lsm6dsx_shub_write_reg_with_mask()
233 err = regmap_update_bits(hw->regmap, addr, mask, val); in st_lsm6dsx_shub_write_reg_with_mask()
237 mutex_unlock(&hw->page_lock); in st_lsm6dsx_shub_write_reg_with_mask()
242 static int st_lsm6dsx_shub_master_enable(struct st_lsm6dsx_sensor *sensor, in st_lsm6dsx_shub_master_enable() argument
246 struct st_lsm6dsx_hw *hw = sensor->hw; in st_lsm6dsx_shub_master_enable()
250 /* enable acc sensor as trigger */ in st_lsm6dsx_shub_master_enable()
251 err = st_lsm6dsx_sensor_set_enable(sensor, enable); in st_lsm6dsx_shub_master_enable()
255 mutex_lock(&hw->page_lock); in st_lsm6dsx_shub_master_enable()
257 hub_settings = &hw->settings->shub_settings; in st_lsm6dsx_shub_master_enable()
258 if (hub_settings->master_en.sec_page) { in st_lsm6dsx_shub_master_enable()
264 data = ST_LSM6DSX_SHIFT_VAL(enable, hub_settings->master_en.mask); in st_lsm6dsx_shub_master_enable()
265 err = regmap_update_bits(hw->regmap, hub_settings->master_en.addr, in st_lsm6dsx_shub_master_enable()
266 hub_settings->master_en.mask, data); in st_lsm6dsx_shub_master_enable()
268 if (hub_settings->master_en.sec_page) in st_lsm6dsx_shub_master_enable()
271 mutex_unlock(&hw->page_lock); in st_lsm6dsx_shub_master_enable()
277 * st_lsm6dsx_shub_read - read data from slave device register
280 * one-shot read operation
283 st_lsm6dsx_shub_read(struct st_lsm6dsx_sensor *sensor, u8 addr, in st_lsm6dsx_shub_read() argument
288 struct st_lsm6dsx_hw *hw = sensor->hw; in st_lsm6dsx_shub_read()
292 hub_settings = &hw->settings->shub_settings; in st_lsm6dsx_shub_read()
293 slv_addr = ST_LSM6DSX_SLV_ADDR(0, hub_settings->slv0_addr); in st_lsm6dsx_shub_read()
294 aux_sens = &hw->settings->shub_settings.aux_sens; in st_lsm6dsx_shub_read()
296 if (slv_addr + 2 == aux_sens->addr) in st_lsm6dsx_shub_read()
297 slv_config = ST_LSM6DSX_SHIFT_VAL(3, aux_sens->mask); in st_lsm6dsx_shub_read()
299 config[0] = (sensor->ext_info.addr << 1) | 1; in st_lsm6dsx_shub_read()
308 err = st_lsm6dsx_shub_master_enable(sensor, true); in st_lsm6dsx_shub_read()
319 st_lsm6dsx_shub_master_enable(sensor, false); in st_lsm6dsx_shub_read()
321 config[0] = hub_settings->pause; in st_lsm6dsx_shub_read()
329 * st_lsm6dsx_shub_write - write data to slave device register
332 * one-shot write operation
335 st_lsm6dsx_shub_write(struct st_lsm6dsx_sensor *sensor, u8 addr, in st_lsm6dsx_shub_write() argument
339 struct st_lsm6dsx_hw *hw = sensor->hw; in st_lsm6dsx_shub_write()
343 hub_settings = &hw->settings->shub_settings; in st_lsm6dsx_shub_write()
344 if (hub_settings->wr_once.addr) { in st_lsm6dsx_shub_write()
347 data = ST_LSM6DSX_SHIFT_VAL(1, hub_settings->wr_once.mask); in st_lsm6dsx_shub_write()
349 hub_settings->wr_once.addr, in st_lsm6dsx_shub_write()
350 hub_settings->wr_once.mask, in st_lsm6dsx_shub_write()
356 slv_addr = ST_LSM6DSX_SLV_ADDR(0, hub_settings->slv0_addr); in st_lsm6dsx_shub_write()
357 config[0] = sensor->ext_info.addr << 1; in st_lsm6dsx_shub_write()
366 err = st_lsm6dsx_shub_write_reg(hw, hub_settings->dw_slv0_addr, in st_lsm6dsx_shub_write()
371 err = st_lsm6dsx_shub_master_enable(sensor, true); in st_lsm6dsx_shub_write()
377 st_lsm6dsx_shub_master_enable(sensor, false); in st_lsm6dsx_shub_write()
380 config[0] = hub_settings->pause; in st_lsm6dsx_shub_write()
386 st_lsm6dsx_shub_write_with_mask(struct st_lsm6dsx_sensor *sensor, in st_lsm6dsx_shub_write_with_mask() argument
392 err = st_lsm6dsx_shub_read(sensor, addr, &data, sizeof(data)); in st_lsm6dsx_shub_write_with_mask()
398 return st_lsm6dsx_shub_write(sensor, addr, &data, sizeof(data)); in st_lsm6dsx_shub_write_with_mask()
402 st_lsm6dsx_shub_get_odr_val(struct st_lsm6dsx_sensor *sensor, in st_lsm6dsx_shub_get_odr_val() argument
408 settings = sensor->ext_info.settings; in st_lsm6dsx_shub_get_odr_val()
409 for (i = 0; i < settings->odr_table.odr_len; i++) { in st_lsm6dsx_shub_get_odr_val()
410 if (settings->odr_table.odr_avl[i].milli_hz == odr) in st_lsm6dsx_shub_get_odr_val()
414 if (i == settings->odr_table.odr_len) in st_lsm6dsx_shub_get_odr_val()
415 return -EINVAL; in st_lsm6dsx_shub_get_odr_val()
417 *val = settings->odr_table.odr_avl[i].val; in st_lsm6dsx_shub_get_odr_val()
422 st_lsm6dsx_shub_set_odr(struct st_lsm6dsx_sensor *sensor, u32 odr) in st_lsm6dsx_shub_set_odr() argument
428 err = st_lsm6dsx_shub_get_odr_val(sensor, odr, &val); in st_lsm6dsx_shub_set_odr()
432 settings = sensor->ext_info.settings; in st_lsm6dsx_shub_set_odr()
433 return st_lsm6dsx_shub_write_with_mask(sensor, in st_lsm6dsx_shub_set_odr()
434 settings->odr_table.reg.addr, in st_lsm6dsx_shub_set_odr()
435 settings->odr_table.reg.mask, in st_lsm6dsx_shub_set_odr()
441 st_lsm6dsx_shub_config_channels(struct st_lsm6dsx_sensor *sensor, in st_lsm6dsx_shub_config_channels() argument
447 struct st_lsm6dsx_hw *hw = sensor->hw; in st_lsm6dsx_shub_config_channels()
451 hub_settings = &hw->settings->shub_settings; in st_lsm6dsx_shub_config_channels()
453 enable_mask = hw->enable_mask | BIT(sensor->id); in st_lsm6dsx_shub_config_channels()
455 enable_mask = hw->enable_mask & ~BIT(sensor->id); in st_lsm6dsx_shub_config_channels()
458 if (!hw->iio_devs[i]) in st_lsm6dsx_shub_config_channels()
461 cur_sensor = iio_priv(hw->iio_devs[i]); in st_lsm6dsx_shub_config_channels()
462 if (!(enable_mask & BIT(cur_sensor->id))) in st_lsm6dsx_shub_config_channels()
465 settings = cur_sensor->ext_info.settings; in st_lsm6dsx_shub_config_channels()
466 config[j] = (sensor->ext_info.addr << 1) | 1; in st_lsm6dsx_shub_config_channels()
467 config[j + 1] = settings->out.addr; in st_lsm6dsx_shub_config_channels()
468 config[j + 2] = (settings->out.len & ST_LS6DSX_READ_OP_MASK) | in st_lsm6dsx_shub_config_channels()
469 hub_settings->batch_en; in st_lsm6dsx_shub_config_channels()
473 slv_addr = ST_LSM6DSX_SLV_ADDR(1, hub_settings->slv0_addr); in st_lsm6dsx_shub_config_channels()
478 int st_lsm6dsx_shub_set_enable(struct st_lsm6dsx_sensor *sensor, bool enable) in st_lsm6dsx_shub_set_enable() argument
483 err = st_lsm6dsx_shub_config_channels(sensor, enable); in st_lsm6dsx_shub_set_enable()
487 settings = sensor->ext_info.settings; in st_lsm6dsx_shub_set_enable()
489 err = st_lsm6dsx_shub_set_odr(sensor, in st_lsm6dsx_shub_set_enable()
490 sensor->ext_info.slv_odr); in st_lsm6dsx_shub_set_enable()
494 err = st_lsm6dsx_shub_write_with_mask(sensor, in st_lsm6dsx_shub_set_enable()
495 settings->odr_table.reg.addr, in st_lsm6dsx_shub_set_enable()
496 settings->odr_table.reg.mask, 0); in st_lsm6dsx_shub_set_enable()
501 if (settings->pwr_table.reg.addr) { in st_lsm6dsx_shub_set_enable()
504 val = enable ? settings->pwr_table.on_val in st_lsm6dsx_shub_set_enable()
505 : settings->pwr_table.off_val; in st_lsm6dsx_shub_set_enable()
506 err = st_lsm6dsx_shub_write_with_mask(sensor, in st_lsm6dsx_shub_set_enable()
507 settings->pwr_table.reg.addr, in st_lsm6dsx_shub_set_enable()
508 settings->pwr_table.reg.mask, val); in st_lsm6dsx_shub_set_enable()
513 return st_lsm6dsx_shub_master_enable(sensor, enable); in st_lsm6dsx_shub_set_enable()
517 st_lsm6dsx_shub_read_oneshot(struct st_lsm6dsx_sensor *sensor, in st_lsm6dsx_shub_read_oneshot() argument
524 err = st_lsm6dsx_shub_set_enable(sensor, true); in st_lsm6dsx_shub_read_oneshot()
528 delay = 1000000000 / sensor->ext_info.slv_odr; in st_lsm6dsx_shub_read_oneshot()
531 len = min_t(int, sizeof(data), ch->scan_type.realbits >> 3); in st_lsm6dsx_shub_read_oneshot()
532 err = st_lsm6dsx_shub_read(sensor, ch->address, data, len); in st_lsm6dsx_shub_read_oneshot()
536 err = st_lsm6dsx_shub_set_enable(sensor, false); in st_lsm6dsx_shub_read_oneshot()
545 return -EINVAL; in st_lsm6dsx_shub_read_oneshot()
556 struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev); in st_lsm6dsx_shub_read_raw() local
565 ret = st_lsm6dsx_shub_read_oneshot(sensor, ch, val); in st_lsm6dsx_shub_read_raw()
569 *val = sensor->ext_info.slv_odr / 1000; in st_lsm6dsx_shub_read_raw()
570 *val2 = (sensor->ext_info.slv_odr % 1000) * 1000; in st_lsm6dsx_shub_read_raw()
575 *val2 = sensor->gain; in st_lsm6dsx_shub_read_raw()
579 ret = -EINVAL; in st_lsm6dsx_shub_read_raw()
587 st_lsm6dsx_shub_set_full_scale(struct st_lsm6dsx_sensor *sensor, in st_lsm6dsx_shub_set_full_scale() argument
588 u32 gain) in st_lsm6dsx_shub_set_full_scale() argument
593 fs_table = &sensor->ext_info.settings->fs_table; in st_lsm6dsx_shub_set_full_scale()
594 if (!fs_table->reg.addr) in st_lsm6dsx_shub_set_full_scale()
595 return -ENOTSUPP; in st_lsm6dsx_shub_set_full_scale()
597 for (i = 0; i < fs_table->fs_len; i++) { in st_lsm6dsx_shub_set_full_scale()
598 if (fs_table->fs_avl[i].gain == gain) in st_lsm6dsx_shub_set_full_scale()
602 if (i == fs_table->fs_len) in st_lsm6dsx_shub_set_full_scale()
603 return -EINVAL; in st_lsm6dsx_shub_set_full_scale()
605 err = st_lsm6dsx_shub_write_with_mask(sensor, fs_table->reg.addr, in st_lsm6dsx_shub_set_full_scale()
606 fs_table->reg.mask, in st_lsm6dsx_shub_set_full_scale()
607 fs_table->fs_avl[i].val); in st_lsm6dsx_shub_set_full_scale()
611 sensor->gain = gain; in st_lsm6dsx_shub_set_full_scale()
621 struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev); in st_lsm6dsx_shub_write_raw() local
633 err = st_lsm6dsx_shub_get_odr_val(sensor, val, &data); in st_lsm6dsx_shub_write_raw()
635 struct st_lsm6dsx_hw *hw = sensor->hw; in st_lsm6dsx_shub_write_raw()
640 ref_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_ACC]); in st_lsm6dsx_shub_write_raw()
647 sensor->ext_info.slv_odr = val; in st_lsm6dsx_shub_write_raw()
648 sensor->odr = odr; in st_lsm6dsx_shub_write_raw()
653 err = st_lsm6dsx_shub_set_full_scale(sensor, val2); in st_lsm6dsx_shub_write_raw()
656 err = -EINVAL; in st_lsm6dsx_shub_write_raw()
671 struct st_lsm6dsx_sensor *sensor = iio_priv(dev_get_drvdata(dev)); in st_lsm6dsx_shub_sampling_freq_avail() local
675 settings = sensor->ext_info.settings; in st_lsm6dsx_shub_sampling_freq_avail()
676 for (i = 0; i < settings->odr_table.odr_len; i++) { in st_lsm6dsx_shub_sampling_freq_avail()
677 u32 val = settings->odr_table.odr_avl[i].milli_hz; in st_lsm6dsx_shub_sampling_freq_avail()
679 len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%03d ", in st_lsm6dsx_shub_sampling_freq_avail()
682 buf[len - 1] = '\n'; in st_lsm6dsx_shub_sampling_freq_avail()
691 struct st_lsm6dsx_sensor *sensor = iio_priv(dev_get_drvdata(dev)); in st_lsm6dsx_shub_scale_avail() local
695 settings = sensor->ext_info.settings; in st_lsm6dsx_shub_scale_avail()
696 for (i = 0; i < settings->fs_table.fs_len; i++) in st_lsm6dsx_shub_scale_avail()
697 len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ", in st_lsm6dsx_shub_scale_avail()
698 settings->fs_table.fs_avl[i].gain); in st_lsm6dsx_shub_scale_avail()
699 buf[len - 1] = '\n'; in st_lsm6dsx_shub_scale_avail()
732 struct st_lsm6dsx_sensor *sensor; in st_lsm6dsx_shub_alloc_iiodev() local
735 iio_dev = devm_iio_device_alloc(hw->dev, sizeof(*sensor)); in st_lsm6dsx_shub_alloc_iiodev()
739 iio_dev->modes = INDIO_DIRECT_MODE; in st_lsm6dsx_shub_alloc_iiodev()
740 iio_dev->info = &st_lsm6dsx_shub_info; in st_lsm6dsx_shub_alloc_iiodev()
742 sensor = iio_priv(iio_dev); in st_lsm6dsx_shub_alloc_iiodev()
743 sensor->id = id; in st_lsm6dsx_shub_alloc_iiodev()
744 sensor->hw = hw; in st_lsm6dsx_shub_alloc_iiodev()
745 sensor->odr = hw->settings->odr_table[ref_id].odr_avl[0].milli_hz; in st_lsm6dsx_shub_alloc_iiodev()
746 sensor->ext_info.slv_odr = info->odr_table.odr_avl[0].milli_hz; in st_lsm6dsx_shub_alloc_iiodev()
747 sensor->gain = info->fs_table.fs_avl[0].gain; in st_lsm6dsx_shub_alloc_iiodev()
748 sensor->ext_info.settings = info; in st_lsm6dsx_shub_alloc_iiodev()
749 sensor->ext_info.addr = i2c_addr; in st_lsm6dsx_shub_alloc_iiodev()
750 sensor->watermark = 1; in st_lsm6dsx_shub_alloc_iiodev()
752 switch (info->id) { in st_lsm6dsx_shub_alloc_iiodev()
755 ST_LSM6DSX_CHANNEL(IIO_MAGN, info->out.addr, in st_lsm6dsx_shub_alloc_iiodev()
757 ST_LSM6DSX_CHANNEL(IIO_MAGN, info->out.addr + 2, in st_lsm6dsx_shub_alloc_iiodev()
759 ST_LSM6DSX_CHANNEL(IIO_MAGN, info->out.addr + 4, in st_lsm6dsx_shub_alloc_iiodev()
764 ext_channels = devm_kzalloc(hw->dev, sizeof(magn_channels), in st_lsm6dsx_shub_alloc_iiodev()
770 iio_dev->available_scan_masks = st_lsm6dsx_available_scan_masks; in st_lsm6dsx_shub_alloc_iiodev()
771 iio_dev->channels = ext_channels; in st_lsm6dsx_shub_alloc_iiodev()
772 iio_dev->num_channels = ARRAY_SIZE(magn_channels); in st_lsm6dsx_shub_alloc_iiodev()
774 scnprintf(sensor->name, sizeof(sensor->name), "%s_magn", in st_lsm6dsx_shub_alloc_iiodev()
781 iio_dev->name = sensor->name; in st_lsm6dsx_shub_alloc_iiodev()
786 static int st_lsm6dsx_shub_init_device(struct st_lsm6dsx_sensor *sensor) in st_lsm6dsx_shub_init_device() argument
791 settings = sensor->ext_info.settings; in st_lsm6dsx_shub_init_device()
792 if (settings->bdu.addr) { in st_lsm6dsx_shub_init_device()
793 err = st_lsm6dsx_shub_write_with_mask(sensor, in st_lsm6dsx_shub_init_device()
794 settings->bdu.addr, in st_lsm6dsx_shub_init_device()
795 settings->bdu.mask, 1); in st_lsm6dsx_shub_init_device()
800 if (settings->temp_comp.addr) { in st_lsm6dsx_shub_init_device()
801 err = st_lsm6dsx_shub_write_with_mask(sensor, in st_lsm6dsx_shub_init_device()
802 settings->temp_comp.addr, in st_lsm6dsx_shub_init_device()
803 settings->temp_comp.mask, 1); in st_lsm6dsx_shub_init_device()
808 if (settings->off_canc.addr) { in st_lsm6dsx_shub_init_device()
809 err = st_lsm6dsx_shub_write_with_mask(sensor, in st_lsm6dsx_shub_init_device()
810 settings->off_canc.addr, in st_lsm6dsx_shub_init_device()
811 settings->off_canc.mask, 1); in st_lsm6dsx_shub_init_device()
826 struct st_lsm6dsx_sensor *sensor; in st_lsm6dsx_shub_check_wai() local
830 sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_ACC]); in st_lsm6dsx_shub_check_wai()
831 hub_settings = &hw->settings->shub_settings; in st_lsm6dsx_shub_check_wai()
832 aux_sens = &hw->settings->shub_settings.aux_sens; in st_lsm6dsx_shub_check_wai()
833 slv_addr = ST_LSM6DSX_SLV_ADDR(0, hub_settings->slv0_addr); in st_lsm6dsx_shub_check_wai()
835 if (slv_addr + 2 == aux_sens->addr) in st_lsm6dsx_shub_check_wai()
836 slv_config = ST_LSM6DSX_SHIFT_VAL(3, aux_sens->mask); in st_lsm6dsx_shub_check_wai()
838 for (i = 0; i < ARRAY_SIZE(settings->i2c_addr); i++) { in st_lsm6dsx_shub_check_wai()
839 if (!settings->i2c_addr[i]) in st_lsm6dsx_shub_check_wai()
843 config[0] = (settings->i2c_addr[i] << 1) | 0x1; in st_lsm6dsx_shub_check_wai()
844 config[1] = settings->wai.addr; in st_lsm6dsx_shub_check_wai()
852 err = st_lsm6dsx_shub_master_enable(sensor, true); in st_lsm6dsx_shub_check_wai()
860 st_lsm6dsx_shub_master_enable(sensor, false); in st_lsm6dsx_shub_check_wai()
865 if (data != settings->wai.val) in st_lsm6dsx_shub_check_wai()
868 *i2c_addr = settings->i2c_addr[i]; in st_lsm6dsx_shub_check_wai()
874 config[0] = hub_settings->pause; in st_lsm6dsx_shub_check_wai()
882 return found ? 0 : -ENODEV; in st_lsm6dsx_shub_check_wai()
888 struct st_lsm6dsx_sensor *sensor; in st_lsm6dsx_shub_probe() local
895 if (err == -ENODEV) in st_lsm6dsx_shub_probe()
900 hw->iio_devs[id] = st_lsm6dsx_shub_alloc_iiodev(hw, id, in st_lsm6dsx_shub_probe()
903 if (!hw->iio_devs[id]) in st_lsm6dsx_shub_probe()
904 return -ENOMEM; in st_lsm6dsx_shub_probe()
906 sensor = iio_priv(hw->iio_devs[id]); in st_lsm6dsx_shub_probe()
907 err = st_lsm6dsx_shub_init_device(sensor); in st_lsm6dsx_shub_probe()
911 if (++num_ext_dev >= hw->settings->shub_settings.num_ext_dev) in st_lsm6dsx_shub_probe()