Lines Matching +full:int +full:- +full:comp +full:- +full:resistor
1 // SPDX-License-Identifier: GPL-2.0
182 unsigned int val; in sx9324_phase_configuration_show()
183 int i, ret, pin_idx; in sx9324_phase_configuration_show()
186 ret = regmap_read(data->regmap, SX9324_REG_AFE_PH0 + chan->channel, &val); in sx9324_phase_configuration_show()
195 buf[len - 1] = '\n'; in sx9324_phase_configuration_show()
246 int val;
247 int val2;
283 static const unsigned int sx9324_scan_period_table[] = {
315 regmap_reg_range(SX9324_REG_IRQ_CFG2 + 1, SX9324_REG_GNRL_CTRL0 - 1),
316 regmap_reg_range(SX9324_REG_GNRL_CTRL1 + 1, SX9324_REG_AFE_CTRL0 - 1),
317 regmap_reg_range(SX9324_REG_AFE_CTRL9 + 1, SX9324_REG_PROX_CTRL0 - 1),
318 regmap_reg_range(SX9324_REG_PROX_CTRL7 + 1, SX9324_REG_ADV_CTRL0 - 1),
319 regmap_reg_range(SX9324_REG_ADV_CTRL20 + 1, SX9324_REG_PHASE_SEL - 1),
320 regmap_reg_range(SX9324_REG_SAR_LSB + 1, SX9324_REG_RESET - 1),
321 regmap_reg_range(SX9324_REG_RESET + 1, SX9324_REG_WHOAMI - 1),
322 regmap_reg_range(SX9324_REG_WHOAMI + 1, SX9324_REG_REVISION - 1),
355 static int sx9324_read_prox_data(struct sx_common_data *data, in sx9324_read_prox_data()
359 int ret; in sx9324_read_prox_data()
361 ret = regmap_write(data->regmap, SX9324_REG_PHASE_SEL, chan->channel); in sx9324_read_prox_data()
365 return regmap_bulk_read(data->regmap, chan->address, val, sizeof(*val)); in sx9324_read_prox_data()
372 static int sx9324_wait_for_sample(struct sx_common_data *data) in sx9324_wait_for_sample()
374 int ret; in sx9324_wait_for_sample()
375 unsigned int val; in sx9324_wait_for_sample()
377 ret = regmap_read(data->regmap, SX9324_REG_GNRL_CTRL0, &val); in sx9324_wait_for_sample()
387 static int sx9324_read_gain(struct sx_common_data *data, in sx9324_read_gain()
388 const struct iio_chan_spec *chan, int *val) in sx9324_read_gain()
390 unsigned int reg, regval; in sx9324_read_gain()
391 int ret; in sx9324_read_gain()
393 reg = SX9324_REG_PROX_CTRL0 + chan->channel / 2; in sx9324_read_gain()
394 ret = regmap_read(data->regmap, reg, ®val); in sx9324_read_gain()
400 regval--; in sx9324_read_gain()
403 return -EINVAL; in sx9324_read_gain()
410 static int sx9324_read_samp_freq(struct sx_common_data *data, in sx9324_read_samp_freq()
411 int *val, int *val2) in sx9324_read_samp_freq()
413 int ret; in sx9324_read_samp_freq()
414 unsigned int regval; in sx9324_read_samp_freq()
416 ret = regmap_read(data->regmap, SX9324_REG_GNRL_CTRL0, ®val); in sx9324_read_samp_freq()
427 static int sx9324_read_raw(struct iio_dev *indio_dev, in sx9324_read_raw()
429 int *val, int *val2, long mask) in sx9324_read_raw()
435 iio_device_claim_direct_scoped(return -EBUSY, indio_dev) in sx9324_read_raw()
439 iio_device_claim_direct_scoped(return -EBUSY, indio_dev) in sx9324_read_raw()
445 return -EINVAL; in sx9324_read_raw()
449 static const int sx9324_gain_vals[] = { 1, 2, 4, 8 };
451 static int sx9324_read_avail(struct iio_dev *indio_dev, in sx9324_read_avail()
453 const int **vals, int *type, int *length, in sx9324_read_avail()
456 if (chan->type != IIO_PROXIMITY) in sx9324_read_avail()
457 return -EINVAL; in sx9324_read_avail()
468 *vals = (int *)sx9324_samp_freq_table; in sx9324_read_avail()
471 return -EINVAL; in sx9324_read_avail()
475 static int sx9324_set_samp_freq(struct sx_common_data *data, in sx9324_set_samp_freq()
476 int val, int val2) in sx9324_set_samp_freq()
478 int i; in sx9324_set_samp_freq()
486 return -EINVAL; in sx9324_set_samp_freq()
488 guard(mutex)(&data->mutex); in sx9324_set_samp_freq()
490 return regmap_update_bits(data->regmap, in sx9324_set_samp_freq()
495 static int sx9324_read_thresh(struct sx_common_data *data, in sx9324_read_thresh()
496 const struct iio_chan_spec *chan, int *val) in sx9324_read_thresh()
498 unsigned int regval; in sx9324_read_thresh()
499 unsigned int reg; in sx9324_read_thresh()
500 int ret; in sx9324_read_thresh()
507 reg = SX9324_REG_PROX_CTRL6 + chan->channel / 2; in sx9324_read_thresh()
508 ret = regmap_read(data->regmap, reg, ®val); in sx9324_read_thresh()
520 static int sx9324_read_hysteresis(struct sx_common_data *data, in sx9324_read_hysteresis()
521 const struct iio_chan_spec *chan, int *val) in sx9324_read_hysteresis()
523 unsigned int regval, pthresh; in sx9324_read_hysteresis()
524 int ret; in sx9324_read_hysteresis()
530 ret = regmap_read(data->regmap, SX9324_REG_PROX_CTRL5, ®val); in sx9324_read_hysteresis()
538 *val = pthresh >> (5 - regval); in sx9324_read_hysteresis()
543 static int sx9324_read_far_debounce(struct sx_common_data *data, int *val) in sx9324_read_far_debounce()
545 unsigned int regval; in sx9324_read_far_debounce()
546 int ret; in sx9324_read_far_debounce()
548 ret = regmap_read(data->regmap, SX9324_REG_PROX_CTRL5, ®val); in sx9324_read_far_debounce()
561 static int sx9324_read_close_debounce(struct sx_common_data *data, int *val) in sx9324_read_close_debounce()
563 unsigned int regval; in sx9324_read_close_debounce()
564 int ret; in sx9324_read_close_debounce()
566 ret = regmap_read(data->regmap, SX9324_REG_PROX_CTRL5, ®val); in sx9324_read_close_debounce()
579 static int sx9324_read_event_val(struct iio_dev *indio_dev, in sx9324_read_event_val()
583 enum iio_event_info info, int *val, int *val2) in sx9324_read_event_val()
587 if (chan->type != IIO_PROXIMITY) in sx9324_read_event_val()
588 return -EINVAL; in sx9324_read_event_val()
600 return -EINVAL; in sx9324_read_event_val()
605 return -EINVAL; in sx9324_read_event_val()
609 static int sx9324_write_thresh(struct sx_common_data *data, in sx9324_write_thresh()
610 const struct iio_chan_spec *chan, int _val) in sx9324_write_thresh()
612 unsigned int reg, val = _val; in sx9324_write_thresh()
614 reg = SX9324_REG_PROX_CTRL6 + chan->channel / 2; in sx9324_write_thresh()
620 return -EINVAL; in sx9324_write_thresh()
622 guard(mutex)(&data->mutex); in sx9324_write_thresh()
624 return regmap_write(data->regmap, reg, val); in sx9324_write_thresh()
627 static int sx9324_write_hysteresis(struct sx_common_data *data, in sx9324_write_hysteresis()
628 const struct iio_chan_spec *chan, int _val) in sx9324_write_hysteresis()
630 unsigned int hyst, val = _val; in sx9324_write_hysteresis()
631 int ret, pthresh; in sx9324_write_hysteresis()
646 return -EINVAL; in sx9324_write_hysteresis()
649 guard(mutex)(&data->mutex); in sx9324_write_hysteresis()
651 return regmap_update_bits(data->regmap, SX9324_REG_PROX_CTRL5, in sx9324_write_hysteresis()
655 static int sx9324_write_far_debounce(struct sx_common_data *data, int _val) in sx9324_write_far_debounce()
657 unsigned int regval, val = _val; in sx9324_write_far_debounce()
662 return -EINVAL; in sx9324_write_far_debounce()
666 guard(mutex)(&data->mutex); in sx9324_write_far_debounce()
668 return regmap_update_bits(data->regmap, SX9324_REG_PROX_CTRL5, in sx9324_write_far_debounce()
673 static int sx9324_write_close_debounce(struct sx_common_data *data, int _val) in sx9324_write_close_debounce()
675 unsigned int regval, val = _val; in sx9324_write_close_debounce()
680 return -EINVAL; in sx9324_write_close_debounce()
684 guard(mutex)(&data->mutex); in sx9324_write_close_debounce()
686 return regmap_update_bits(data->regmap, SX9324_REG_PROX_CTRL5, in sx9324_write_close_debounce()
691 static int sx9324_write_event_val(struct iio_dev *indio_dev, in sx9324_write_event_val()
695 enum iio_event_info info, int val, int val2) in sx9324_write_event_val()
699 if (chan->type != IIO_PROXIMITY) in sx9324_write_event_val()
700 return -EINVAL; in sx9324_write_event_val()
712 return -EINVAL; in sx9324_write_event_val()
717 return -EINVAL; in sx9324_write_event_val()
721 static int sx9324_write_gain(struct sx_common_data *data, in sx9324_write_gain()
722 const struct iio_chan_spec *chan, int val) in sx9324_write_gain()
724 unsigned int gain, reg; in sx9324_write_gain()
726 reg = SX9324_REG_PROX_CTRL0 + chan->channel / 2; in sx9324_write_gain()
730 return -EINVAL; in sx9324_write_gain()
734 guard(mutex)(&data->mutex); in sx9324_write_gain()
736 return regmap_update_bits(data->regmap, reg, in sx9324_write_gain()
741 static int sx9324_write_raw(struct iio_dev *indio_dev, in sx9324_write_raw()
742 const struct iio_chan_spec *chan, int val, int val2, in sx9324_write_raw()
753 return -EINVAL; in sx9324_write_raw()
831 static int sx9324_init_compensation(struct iio_dev *indio_dev) in sx9324_init_compensation()
834 unsigned int val; in sx9324_init_compensation()
835 int ret; in sx9324_init_compensation()
838 ret = regmap_set_bits(data->regmap, SX9324_REG_STAT2, in sx9324_init_compensation()
843 return regmap_read_poll_timeout(data->regmap, SX9324_REG_STAT2, val, in sx9324_init_compensation()
852 unsigned int pin_defs[SX9324_NUM_PINS]; in sx9324_parse_phase_prop()
853 int count, ret, pin; in sx9324_parse_phase_prop()
858 return reg_def->def; in sx9324_parse_phase_prop()
862 return reg_def->def; in sx9324_parse_phase_prop()
872 sx9324_get_default_reg(struct device *dev, int idx, in sx9324_get_default_reg()
877 static const char * const sx9324_csidle[] = { "hi-z", "hi-z", "gnd", in sx9324_get_default_reg()
881 int ret; in sx9324_get_default_reg()
886 switch (reg_def->reg) { in sx9324_get_default_reg()
888 reg_def->def = sx9324_parse_phase_prop(dev, reg_def, in sx9324_get_default_reg()
889 "semtech,ph0-pin"); in sx9324_get_default_reg()
892 reg_def->def = sx9324_parse_phase_prop(dev, reg_def, in sx9324_get_default_reg()
893 "semtech,ph1-pin"); in sx9324_get_default_reg()
896 reg_def->def = sx9324_parse_phase_prop(dev, reg_def, in sx9324_get_default_reg()
897 "semtech,ph2-pin"); in sx9324_get_default_reg()
900 reg_def->def = sx9324_parse_phase_prop(dev, reg_def, in sx9324_get_default_reg()
901 "semtech,ph3-pin"); in sx9324_get_default_reg()
904 ret = device_property_match_property_string(dev, "semtech,cs-idle-sleep", in sx9324_get_default_reg()
908 reg_def->def &= ~SX9324_REG_AFE_CTRL0_CSIDLE_MASK; in sx9324_get_default_reg()
909 reg_def->def |= ret << SX9324_REG_AFE_CTRL0_CSIDLE_SHIFT; in sx9324_get_default_reg()
912 ret = device_property_match_property_string(dev, "semtech,int-comp-resistor", in sx9324_get_default_reg()
916 reg_def->def &= ~SX9324_REG_AFE_CTRL0_RINT_MASK; in sx9324_get_default_reg()
917 reg_def->def |= ret << SX9324_REG_AFE_CTRL0_RINT_SHIFT; in sx9324_get_default_reg()
922 if (reg_def->reg == SX9324_REG_AFE_CTRL4) in sx9324_get_default_reg()
923 prop = "semtech,ph01-resolution"; in sx9324_get_default_reg()
925 prop = "semtech,ph23-resolution"; in sx9324_get_default_reg()
931 raw = ilog2(raw) - 3; in sx9324_get_default_reg()
933 reg_def->def &= ~SX9324_REG_AFE_CTRL4_RESOLUTION_MASK; in sx9324_get_default_reg()
934 reg_def->def |= FIELD_PREP(SX9324_REG_AFE_CTRL4_RESOLUTION_MASK, in sx9324_get_default_reg()
939 "semtech,input-precharge-resistor-ohms", in sx9324_get_default_reg()
944 reg_def->def &= ~SX9324_REG_AFE_CTRL8_RESFILTIN_MASK; in sx9324_get_default_reg()
945 reg_def->def |= FIELD_PREP(SX9324_REG_AFE_CTRL8_RESFILTIN_MASK, in sx9324_get_default_reg()
951 "semtech,input-analog-gain", &raw); in sx9324_get_default_reg()
956 * +---------+----------------+----------------+ in sx9324_get_default_reg()
958 * +---------+----------------+----------------+ in sx9324_get_default_reg()
963 * +---------+----------------+----------------+ in sx9324_get_default_reg()
965 reg_def->def &= ~SX9324_REG_AFE_CTRL9_AGAIN_MASK; in sx9324_get_default_reg()
966 reg_def->def |= FIELD_PREP(SX9324_REG_AFE_CTRL9_AGAIN_MASK, in sx9324_get_default_reg()
971 ret = device_property_read_u32(dev, "semtech,startup-sensor", in sx9324_get_default_reg()
976 reg_def->def &= ~SX9324_REG_ADV_CTRL5_STARTUPSENS_MASK; in sx9324_get_default_reg()
977 reg_def->def |= FIELD_PREP(SX9324_REG_ADV_CTRL5_STARTUPSENS_MASK, in sx9324_get_default_reg()
981 ret = device_property_read_u32(dev, "semtech,avg-pos-strength", in sx9324_get_default_reg()
987 raw = clamp(ilog2(pos), 3, 11) - (pos >= 32 ? 4 : 3); in sx9324_get_default_reg()
989 reg_def->def &= ~SX9324_REG_PROX_CTRL4_AVGPOSFILT_MASK; in sx9324_get_default_reg()
990 reg_def->def |= FIELD_PREP(SX9324_REG_PROX_CTRL4_AVGPOSFILT_MASK, in sx9324_get_default_reg()
995 if (reg_def->reg == SX9324_REG_PROX_CTRL0) in sx9324_get_default_reg()
996 prop = "semtech,ph01-proxraw-strength"; in sx9324_get_default_reg()
998 prop = "semtech,ph23-proxraw-strength"; in sx9324_get_default_reg()
1003 reg_def->def &= ~SX9324_REG_PROX_CTRL0_RAWFILT_MASK; in sx9324_get_default_reg()
1004 reg_def->def |= FIELD_PREP(SX9324_REG_PROX_CTRL0_RAWFILT_MASK, in sx9324_get_default_reg()
1011 static int sx9324_check_whoami(struct device *dev, in sx9324_check_whoami()
1018 indio_dev->name = "sx9324"; in sx9324_check_whoami()
1054 static int sx9324_probe(struct i2c_client *client) in sx9324_probe()
1059 static int sx9324_suspend(struct device *dev) in sx9324_suspend()
1062 unsigned int regval; in sx9324_suspend()
1063 int ret; in sx9324_suspend()
1065 disable_irq_nosync(data->client->irq); in sx9324_suspend()
1067 guard(mutex)(&data->mutex); in sx9324_suspend()
1068 ret = regmap_read(data->regmap, SX9324_REG_GNRL_CTRL1, ®val); in sx9324_suspend()
1072 data->suspend_ctrl = in sx9324_suspend()
1077 return regmap_write(data->regmap, SX9324_REG_GNRL_CTRL1, 0); in sx9324_suspend()
1080 static int sx9324_resume(struct device *dev) in sx9324_resume()
1084 scoped_guard(mutex, &data->mutex) { in sx9324_resume()
1085 int ret = regmap_write(data->regmap, SX9324_REG_GNRL_CTRL1, in sx9324_resume()
1086 data->suspend_ctrl | in sx9324_resume()
1092 enable_irq(data->client->irq); in sx9324_resume()