Lines Matching refs:msa311
409 static int msa311_get_odr(struct msa311_priv *msa311, unsigned int *odr) in msa311_get_odr() argument
413 err = regmap_field_read(msa311->fields[F_ODR], odr); in msa311_get_odr()
449 static int msa311_set_odr(struct msa311_priv *msa311, unsigned int odr) in msa311_set_odr() argument
451 struct device *dev = msa311->dev; in msa311_set_odr()
456 err = regmap_field_read(msa311->fields[F_PWR_MODE], &pwr_mode); in msa311_set_odr()
475 return regmap_field_write(msa311->fields[F_ODR], odr); in msa311_set_odr()
485 static int msa311_wait_for_next_data(struct msa311_priv *msa311) in msa311_wait_for_next_data() argument
488 struct device *dev = msa311->dev; in msa311_wait_for_next_data()
494 err = msa311_get_odr(msa311, &odr); in msa311_wait_for_next_data()
530 static int msa311_set_pwr_mode(struct msa311_priv *msa311, unsigned int mode) in msa311_set_pwr_mode() argument
532 struct device *dev = msa311->dev; in msa311_set_pwr_mode()
541 err = regmap_field_read(msa311->fields[F_PWR_MODE], &prev_mode); in msa311_set_pwr_mode()
545 err = regmap_field_write(msa311->fields[F_PWR_MODE], mode); in msa311_set_pwr_mode()
552 return msa311_wait_for_next_data(msa311); in msa311_set_pwr_mode()
568 static int msa311_get_axis(struct msa311_priv *msa311, in msa311_get_axis() argument
572 struct device *dev = msa311->dev; in msa311_get_axis()
584 return regmap_bulk_read(msa311->regs, axis_reg, axis, sizeof(*axis)); in msa311_get_axis()
591 struct msa311_priv *msa311 = iio_priv(indio_dev); in msa311_read_raw_data() local
592 struct device *dev = msa311->dev; in msa311_read_raw_data()
604 mutex_lock(&msa311->lock); in msa311_read_raw_data()
605 err = msa311_get_axis(msa311, chan, &axis); in msa311_read_raw_data()
606 mutex_unlock(&msa311->lock); in msa311_read_raw_data()
631 struct msa311_priv *msa311 = iio_priv(indio_dev); in msa311_read_scale() local
632 struct device *dev = msa311->dev; in msa311_read_scale()
636 mutex_lock(&msa311->lock); in msa311_read_scale()
637 err = regmap_field_read(msa311->fields[F_FS], &fs); in msa311_read_scale()
638 mutex_unlock(&msa311->lock); in msa311_read_scale()
653 struct msa311_priv *msa311 = iio_priv(indio_dev); in msa311_read_samp_freq() local
654 struct device *dev = msa311->dev; in msa311_read_samp_freq()
658 mutex_lock(&msa311->lock); in msa311_read_samp_freq()
659 err = msa311_get_odr(msa311, &odr); in msa311_read_samp_freq()
660 mutex_unlock(&msa311->lock); in msa311_read_samp_freq()
719 struct msa311_priv *msa311 = iio_priv(indio_dev); in msa311_write_scale() local
720 struct device *dev = msa311->dev; in msa311_write_scale()
736 mutex_lock(&msa311->lock); in msa311_write_scale()
737 err = regmap_field_write(msa311->fields[F_FS], fs); in msa311_write_scale()
738 mutex_unlock(&msa311->lock); in msa311_write_scale()
753 struct msa311_priv *msa311 = iio_priv(indio_dev); in msa311_write_samp_freq() local
754 struct device *dev = msa311->dev; in msa311_write_samp_freq()
775 mutex_lock(&msa311->lock); in msa311_write_samp_freq()
776 err = msa311_set_odr(msa311, odr); in msa311_write_samp_freq()
777 mutex_unlock(&msa311->lock); in msa311_write_samp_freq()
812 struct msa311_priv *msa311 = iio_priv(indio_dev); in msa311_debugfs_reg_access() local
813 struct device *dev = msa311->dev; in msa311_debugfs_reg_access()
816 if (reg > regmap_get_max_register(msa311->regs)) in msa311_debugfs_reg_access()
823 mutex_lock(&msa311->lock); in msa311_debugfs_reg_access()
826 err = regmap_read(msa311->regs, reg, readval); in msa311_debugfs_reg_access()
828 err = regmap_write(msa311->regs, reg, writeval); in msa311_debugfs_reg_access()
830 mutex_unlock(&msa311->lock); in msa311_debugfs_reg_access()
844 struct msa311_priv *msa311 = iio_priv(indio_dev); in msa311_buffer_preenable() local
845 struct device *dev = msa311->dev; in msa311_buffer_preenable()
852 struct msa311_priv *msa311 = iio_priv(indio_dev); in msa311_buffer_postdisable() local
853 struct device *dev = msa311->dev; in msa311_buffer_postdisable()
864 struct msa311_priv *msa311 = iio_priv(indio_dev); in msa311_set_new_data_trig_state() local
865 struct device *dev = msa311->dev; in msa311_set_new_data_trig_state()
868 mutex_lock(&msa311->lock); in msa311_set_new_data_trig_state()
869 err = regmap_field_write(msa311->fields[F_NEW_DATA_INT_EN], state); in msa311_set_new_data_trig_state()
870 mutex_unlock(&msa311->lock); in msa311_set_new_data_trig_state()
888 struct msa311_priv *msa311 = iio_priv(pf->indio_dev); in msa311_buffer_thread() local
891 struct device *dev = msa311->dev; in msa311_buffer_thread()
901 mutex_lock(&msa311->lock); in msa311_buffer_thread()
907 err = msa311_get_axis(msa311, chan, &axis); in msa311_buffer_thread()
909 mutex_unlock(&msa311->lock); in msa311_buffer_thread()
918 mutex_unlock(&msa311->lock); in msa311_buffer_thread()
931 struct msa311_priv *msa311 = iio_priv(p); in msa311_irq_thread() local
933 struct device *dev = msa311->dev; in msa311_irq_thread()
936 mutex_lock(&msa311->lock); in msa311_irq_thread()
943 err = regmap_field_read(msa311->fields[F_NEW_DATA_INT_EN], in msa311_irq_thread()
946 mutex_unlock(&msa311->lock); in msa311_irq_thread()
954 iio_trigger_poll_nested(msa311->new_data_trig); in msa311_irq_thread()
976 static int msa311_check_partid(struct msa311_priv *msa311) in msa311_check_partid() argument
978 struct device *dev = msa311->dev; in msa311_check_partid()
982 err = regmap_read(msa311->regs, MSA311_PARTID_REG, &partid); in msa311_check_partid()
990 msa311->chip_name = devm_kasprintf(dev, GFP_KERNEL, in msa311_check_partid()
992 if (!msa311->chip_name) in msa311_check_partid()
998 static int msa311_soft_reset(struct msa311_priv *msa311) in msa311_soft_reset() argument
1000 struct device *dev = msa311->dev; in msa311_soft_reset()
1003 err = regmap_write(msa311->regs, MSA311_SOFT_RESET_REG, in msa311_soft_reset()
1012 static int msa311_chip_init(struct msa311_priv *msa311) in msa311_chip_init() argument
1014 struct device *dev = msa311->dev; in msa311_chip_init()
1018 err = regmap_write(msa311->regs, MSA311_RANGE_REG, MSA311_FS_16G); in msa311_chip_init()
1023 err = regmap_bulk_write(msa311->regs, MSA311_INT_SET_0_REG, in msa311_chip_init()
1030 err = regmap_bulk_write(msa311->regs, MSA311_INT_MAP_0_REG, in msa311_chip_init()
1037 err = regmap_update_bits(msa311->regs, MSA311_ODR_REG, in msa311_chip_init()
1044 err = msa311_set_odr(msa311, MSA311_ODR_125_HZ); in msa311_chip_init()
1052 static int msa311_setup_interrupts(struct msa311_priv *msa311) in msa311_setup_interrupts() argument
1054 struct device *dev = msa311->dev; in msa311_setup_interrupts()
1066 msa311->chip_name, indio_dev); in msa311_setup_interrupts()
1070 trig = devm_iio_trigger_alloc(dev, "%s-new-data", msa311->chip_name); in msa311_setup_interrupts()
1075 msa311->new_data_trig = trig; in msa311_setup_interrupts()
1076 msa311->new_data_trig->ops = &msa311_new_data_trig_ops; in msa311_setup_interrupts()
1077 iio_trigger_set_drvdata(msa311->new_data_trig, indio_dev); in msa311_setup_interrupts()
1079 err = devm_iio_trigger_register(dev, msa311->new_data_trig); in msa311_setup_interrupts()
1084 err = regmap_field_write(msa311->fields[F_INT1_OD], in msa311_setup_interrupts()
1090 err = regmap_field_write(msa311->fields[F_INT1_LVL], in msa311_setup_interrupts()
1096 err = regmap_field_write(msa311->fields[F_LATCH_INT], in msa311_setup_interrupts()
1102 err = regmap_field_write(msa311->fields[F_RESET_INT], 1); in msa311_setup_interrupts()
1107 err = regmap_field_write(msa311->fields[F_INT1_NEW_DATA], 1); in msa311_setup_interrupts()
1115 static int msa311_regmap_init(struct msa311_priv *msa311) in msa311_regmap_init() argument
1117 struct regmap_field **fields = msa311->fields; in msa311_regmap_init()
1118 struct device *dev = msa311->dev; in msa311_regmap_init()
1128 msa311->regs = regmap; in msa311_regmap_init()
1132 msa311->regs, in msa311_regmap_init()
1134 if (IS_ERR(msa311->fields[i])) in msa311_regmap_init()
1135 return dev_err_probe(dev, PTR_ERR(msa311->fields[i]), in msa311_regmap_init()
1142 static void msa311_powerdown(void *msa311) in msa311_powerdown() argument
1144 msa311_set_pwr_mode(msa311, MSA311_PWR_MODE_SUSPEND); in msa311_powerdown()
1150 struct msa311_priv *msa311; in msa311_probe() local
1154 indio_dev = devm_iio_device_alloc(dev, sizeof(*msa311)); in msa311_probe()
1159 msa311 = iio_priv(indio_dev); in msa311_probe()
1160 msa311->dev = dev; in msa311_probe()
1163 err = msa311_regmap_init(msa311); in msa311_probe()
1167 mutex_init(&msa311->lock); in msa311_probe()
1173 err = msa311_check_partid(msa311); in msa311_probe()
1177 err = msa311_soft_reset(msa311); in msa311_probe()
1181 err = msa311_set_pwr_mode(msa311, MSA311_PWR_MODE_NORMAL); in msa311_probe()
1196 err = devm_add_action_or_reset(dev, msa311_powerdown, msa311); in msa311_probe()
1212 err = msa311_chip_init(msa311); in msa311_probe()
1219 indio_dev->name = msa311->chip_name; in msa311_probe()
1230 err = msa311_setup_interrupts(msa311); in msa311_probe()
1247 struct msa311_priv *msa311 = iio_priv(indio_dev); in msa311_runtime_suspend() local
1250 mutex_lock(&msa311->lock); in msa311_runtime_suspend()
1251 err = msa311_set_pwr_mode(msa311, MSA311_PWR_MODE_SUSPEND); in msa311_runtime_suspend()
1252 mutex_unlock(&msa311->lock); in msa311_runtime_suspend()
1263 struct msa311_priv *msa311 = iio_priv(indio_dev); in msa311_runtime_resume() local
1266 mutex_lock(&msa311->lock); in msa311_runtime_resume()
1267 err = msa311_set_pwr_mode(msa311, MSA311_PWR_MODE_NORMAL); in msa311_runtime_resume()
1268 mutex_unlock(&msa311->lock); in msa311_runtime_resume()