Lines Matching +full:sar +full:- +full:threshold

1 // SPDX-License-Identifier: GPL-2.0
195 /* threshold of the offset compensation */
302 return regmap_update_bits(data->regmap, HX9023S_INTERRUPT_CFG, in hx9023s_interrupt_enable()
308 return regmap_update_bits(data->regmap, HX9023S_INTERRUPT_CFG, in hx9023s_interrupt_disable()
315 return regmap_update_bits(data->regmap, in hx9023s_data_lock()
320 return regmap_update_bits(data->regmap, in hx9023s_data_lock()
336 ch_pos[i] = data->ch_data[i].channel_positive == HX9023S_NOT_CONNECTED ? in hx9023s_ch_cfg()
337 HX9023S_NOT_CONNECTED : conn_cs[data->ch_data[i].channel_positive]; in hx9023s_ch_cfg()
338 ch_neg[i] = data->ch_data[i].channel_negative == HX9023S_NOT_CONNECTED ? in hx9023s_ch_cfg()
339 HX9023S_NOT_CONNECTED : conn_cs[data->ch_data[i].channel_negative]; in hx9023s_ch_cfg()
345 return regmap_bulk_write(data->regmap, HX9023S_CH0_CFG_7_0, reg_list, in hx9023s_ch_cfg()
351 guard(mutex)(&data->mutex); in hx9023s_write_far_debounce()
352 return regmap_update_bits(data->regmap, HX9023S_PROX_INT_LOW_CFG, in hx9023s_write_far_debounce()
359 guard(mutex)(&data->mutex); in hx9023s_write_near_debounce()
360 return regmap_update_bits(data->regmap, HX9023S_PROX_INT_HIGH_CFG, in hx9023s_write_near_debounce()
369 ret = regmap_read(data->regmap, HX9023S_PROX_INT_LOW_CFG, val); in hx9023s_read_far_debounce()
382 ret = regmap_read(data->regmap, HX9023S_PROX_INT_HIGH_CFG, val); in hx9023s_read_near_debounce()
400 ret = regmap_bulk_read(data->regmap, reg, &buf, sizeof(buf)); in hx9023s_get_thres_near()
405 data->ch_data[ch].thres.near = tmp; in hx9023s_get_thres_near()
420 ret = regmap_bulk_read(data->regmap, reg, &buf, sizeof(buf)); in hx9023s_get_thres_far()
425 data->ch_data[ch].thres.far = tmp; in hx9023s_get_thres_far()
436 data->ch_data[ch].thres.near = ((val / 32) & GENMASK(9, 0)) * 32; in hx9023s_set_thres_near()
440 return regmap_bulk_write(data->regmap, reg, &val_le16, sizeof(val_le16)); in hx9023s_set_thres_near()
448 data->ch_data[ch].thres.far = ((val / 32) & GENMASK(9, 0)) * 32; in hx9023s_set_thres_far()
452 return regmap_bulk_write(data->regmap, reg, &val_le16, sizeof(val_le16)); in hx9023s_set_thres_far()
457 return regmap_read(data->regmap, HX9023S_PROX_STATUS, &data->prox_state_reg); in hx9023s_get_prox_state()
466 ret = regmap_read(data->regmap, HX9023S_RAW_BL_RD_CFG, &buf); in hx9023s_data_select()
472 data->ch_data[i].sel_diff = test_bit(i, &tmp); in hx9023s_data_select()
473 data->ch_data[i].sel_lp = !data->ch_data[i].sel_diff; in hx9023s_data_select()
474 data->ch_data[i].sel_bl = test_bit(i + 4, &tmp); in hx9023s_data_select()
475 data->ch_data[i].sel_raw = !data->ch_data[i].sel_bl; in hx9023s_data_select()
478 ret = regmap_read(data->regmap, HX9023S_INTERRUPT_CFG1, &buf); in hx9023s_data_select()
483 data->ch_data[4].sel_diff = test_bit(2, &tmp); in hx9023s_data_select()
484 data->ch_data[4].sel_lp = !data->ch_data[4].sel_diff; in hx9023s_data_select()
485 data->ch_data[4].sel_bl = test_bit(3, &tmp); in hx9023s_data_select()
486 data->ch_data[4].sel_raw = !data->ch_data[4].sel_bl; in hx9023s_data_select()
507 ret = regmap_bulk_read(data->regmap, HX9023S_RAW_BL_CH0_0, buf, 12); in hx9023s_sample()
512 ret = regmap_bulk_read(data->regmap, HX9023S_RAW_BL_CH4_0, buf + 12, 3); in hx9023s_sample()
518 data->ch_data[i].raw = 0; in hx9023s_sample()
519 data->ch_data[i].bl = 0; in hx9023s_sample()
520 if (data->ch_data[i].sel_raw) in hx9023s_sample()
521 data->ch_data[i].raw = value; in hx9023s_sample()
522 if (data->ch_data[i].sel_bl) in hx9023s_sample()
523 data->ch_data[i].bl = value; in hx9023s_sample()
527 ret = regmap_bulk_read(data->regmap, HX9023S_LP_DIFF_CH0_0, buf, 12); in hx9023s_sample()
532 ret = regmap_bulk_read(data->regmap, HX9023S_LP_DIFF_CH4_0, buf + 12, 3); in hx9023s_sample()
538 data->ch_data[i].lp = 0; in hx9023s_sample()
539 data->ch_data[i].diff = 0; in hx9023s_sample()
540 if (data->ch_data[i].sel_lp) in hx9023s_sample()
541 data->ch_data[i].lp = value; in hx9023s_sample()
542 if (data->ch_data[i].sel_diff) in hx9023s_sample()
543 data->ch_data[i].diff = value; in hx9023s_sample()
547 if (data->ch_data[i].sel_lp && data->ch_data[i].sel_bl) in hx9023s_sample()
548 data->ch_data[i].diff = data->ch_data[i].lp - data->ch_data[i].bl; in hx9023s_sample()
552 ret = regmap_bulk_read(data->regmap, HX9023S_OFFSET_DAC0_7_0, buf, 10); in hx9023s_sample()
559 data->ch_data[i].dac = value; in hx9023s_sample()
571 ret = regmap_read(data->regmap, HX9023S_CH_NUM_CFG, &buf); in hx9023s_ch_en()
575 data->ch_en_stat = buf; in hx9023s_ch_en()
576 if (en && data->ch_en_stat == 0) in hx9023s_ch_en()
577 data->prox_state_reg = 0; in hx9023s_ch_en()
579 data->ch_data[ch_id].enable = en; in hx9023s_ch_en()
580 __assign_bit(ch_id, &data->ch_en_stat, en); in hx9023s_ch_en()
582 return regmap_write(data->regmap, HX9023S_CH_NUM_CFG, data->ch_en_stat); in hx9023s_ch_en()
587 struct device *dev = regmap_get_device(data->regmap); in hx9023s_property_get()
592 data->chan_in_use = 0; in hx9023s_property_get()
594 data->ch_data[i].channel_positive = HX9023S_NOT_CONNECTED; in hx9023s_property_get()
595 data->ch_data[i].channel_negative = HX9023S_NOT_CONNECTED; in hx9023s_property_get()
601 return dev_err_probe(dev, ret < 0 ? ret : -EINVAL, in hx9023s_property_get()
603 __set_bit(reg, &data->chan_in_use); in hx9023s_property_get()
605 ret = fwnode_property_read_u32(child, "single-channel", &temp); in hx9023s_property_get()
607 data->ch_data[reg].channel_positive = temp; in hx9023s_property_get()
608 data->ch_data[reg].channel_negative = HX9023S_NOT_CONNECTED; in hx9023s_property_get()
610 ret = fwnode_property_read_u32_array(child, "diff-channels", in hx9023s_property_get()
613 data->ch_data[reg].channel_positive = array[0]; in hx9023s_property_get()
614 data->ch_data[reg].channel_negative = array[1]; in hx9023s_property_get()
633 if ((data->chan_read | data->chan_event) != channels) { in hx9023s_update_chan_en()
635 hx9023s_ch_en(data, i, test_bit(i, &data->chan_in_use)); in hx9023s_update_chan_en()
640 data->chan_read = chan_read; in hx9023s_update_chan_en()
641 data->chan_event = chan_event; in hx9023s_update_chan_en()
660 *val = data->ch_data[chan->channel].diff; in hx9023s_get_proximity()
669 ret = regmap_read(data->regmap, HX9023S_PRF_CFG, &index); in hx9023s_get_samp_freq()
687 if (chan->type != IIO_PROXIMITY) in hx9023s_read_raw()
688 return -EINVAL; in hx9023s_read_raw()
702 return -EINVAL; in hx9023s_read_raw()
708 struct device *dev = regmap_get_device(data->regmap); in hx9023s_set_samp_freq()
719 return -EINVAL; in hx9023s_set_samp_freq()
722 return regmap_write(data->regmap, HX9023S_PRF_CFG, i); in hx9023s_set_samp_freq()
731 if (chan->type != IIO_PROXIMITY) in hx9023s_write_raw()
732 return -EINVAL; in hx9023s_write_raw()
735 return -EINVAL; in hx9023s_write_raw()
745 if (data->trigger_enabled) in hx9023s_irq_handler()
746 iio_trigger_poll(data->trig); in hx9023s_irq_handler()
767 prox_changed = (data->chan_prox_stat ^ data->prox_state_reg) & data->chan_event; in hx9023s_push_events()
771 dir = (data->prox_state_reg & BIT(chan)) ? in hx9023s_push_events()
779 data->chan_prox_stat = data->prox_state_reg; in hx9023s_push_events()
787 guard(mutex)(&data->mutex); in hx9023s_irq_thread_handler()
801 if (chan->type != IIO_PROXIMITY) in hx9023s_read_event_val()
802 return -EINVAL; in hx9023s_read_event_val()
808 return hx9023s_get_thres_far(data, chan->channel, val); in hx9023s_read_event_val()
810 return hx9023s_get_thres_near(data, chan->channel, val); in hx9023s_read_event_val()
812 return -EINVAL; in hx9023s_read_event_val()
821 return -EINVAL; in hx9023s_read_event_val()
824 return -EINVAL; in hx9023s_read_event_val()
836 if (chan->type != IIO_PROXIMITY) in hx9023s_write_event_val()
837 return -EINVAL; in hx9023s_write_event_val()
843 return hx9023s_set_thres_far(data, chan->channel, val); in hx9023s_write_event_val()
845 return hx9023s_set_thres_near(data, chan->channel, val); in hx9023s_write_event_val()
847 return -EINVAL; in hx9023s_write_event_val()
856 return -EINVAL; in hx9023s_write_event_val()
859 return -EINVAL; in hx9023s_write_event_val()
870 return test_bit(chan->channel, &data->chan_event); in hx9023s_read_event_config()
881 if (test_bit(chan->channel, &data->chan_in_use)) { in hx9023s_write_event_config()
882 hx9023s_ch_en(data, chan->channel, !!state); in hx9023s_write_event_config()
883 __assign_bit(chan->channel, &data->chan_event, in hx9023s_write_event_config()
884 data->ch_data[chan->channel].enable); in hx9023s_write_event_config()
904 guard(mutex)(&data->mutex); in hx9023s_set_trigger_state()
907 else if (!data->chan_read) in hx9023s_set_trigger_state()
909 data->trigger_enabled = state; in hx9023s_set_trigger_state()
921 struct iio_dev *indio_dev = pf->indio_dev; in hx9023s_trigger_handler()
923 struct device *dev = regmap_get_device(data->regmap); in hx9023s_trigger_handler()
927 guard(mutex)(&data->mutex); in hx9023s_trigger_handler()
941 index = indio_dev->channels[bit].channel; in hx9023s_trigger_handler()
942 data->buffer.channels[i++] = cpu_to_le16(data->ch_data[index].diff); in hx9023s_trigger_handler()
945 iio_push_to_buffers_with_timestamp(indio_dev, &data->buffer, in hx9023s_trigger_handler()
946 pf->timestamp); in hx9023s_trigger_handler()
949 iio_trigger_notify_done(indio_dev->trig); in hx9023s_trigger_handler()
960 guard(mutex)(&data->mutex); in hx9023s_buffer_preenable()
962 __set_bit(indio_dev->channels[bit].channel, &channels); in hx9023s_buffer_preenable()
964 hx9023s_update_chan_en(data, channels, data->chan_event); in hx9023s_buffer_preenable()
973 guard(mutex)(&data->mutex); in hx9023s_buffer_postdisable()
974 hx9023s_update_chan_en(data, 0, data->chan_event); in hx9023s_buffer_postdisable()
987 struct device *dev = regmap_get_device(data->regmap); in hx9023s_id_check()
991 ret = regmap_read(data->regmap, HX9023S_DEVICE_ID, &id); in hx9023s_id_check()
1003 struct device *dev = &client->dev; in hx9023s_probe()
1010 return -ENOMEM; in hx9023s_probe()
1013 mutex_init(&data->mutex); in hx9023s_probe()
1015 data->regmap = devm_regmap_init_i2c(client, &hx9023s_regmap_config); in hx9023s_probe()
1016 if (IS_ERR(data->regmap)) in hx9023s_probe()
1017 return dev_err_probe(dev, PTR_ERR(data->regmap), in hx9023s_probe()
1032 indio_dev->name = "hx9023s"; in hx9023s_probe()
1033 indio_dev->channels = hx9023s_channels; in hx9023s_probe()
1034 indio_dev->num_channels = ARRAY_SIZE(hx9023s_channels); in hx9023s_probe()
1035 indio_dev->info = &hx9023s_info; in hx9023s_probe()
1036 indio_dev->modes = INDIO_DIRECT_MODE; in hx9023s_probe()
1039 ret = regmap_multi_reg_write(data->regmap, hx9023s_reg_init_list, in hx9023s_probe()
1048 ret = regcache_sync(data->regmap); in hx9023s_probe()
1052 if (client->irq) { in hx9023s_probe()
1053 ret = devm_request_threaded_irq(dev, client->irq, in hx9023s_probe()
1061 data->trig = devm_iio_trigger_alloc(dev, "%s-dev%d", in hx9023s_probe()
1062 indio_dev->name, in hx9023s_probe()
1064 if (!data->trig) in hx9023s_probe()
1065 return dev_err_probe(dev, -ENOMEM, in hx9023s_probe()
1068 data->trig->ops = &hx9023s_trigger_ops; in hx9023s_probe()
1069 iio_trigger_set_drvdata(data->trig, indio_dev); in hx9023s_probe()
1071 ret = devm_iio_trigger_register(dev, data->trig); in hx9023s_probe()
1092 guard(mutex)(&data->mutex); in hx9023s_suspend()
1102 guard(mutex)(&data->mutex); in hx9023s_resume()
1103 if (data->trigger_enabled) in hx9023s_resume()
1132 * are time-consuming. Prefer async so we don't delay boot
1143 MODULE_DESCRIPTION("Driver for TYHX HX9023S SAR sensor");