Lines Matching refs:adc_chan
132 int adc_chan, in palmas_gpadc_get_event() argument
135 if (adc_chan == adc->event0.channel && dir == adc->event0.direction) in palmas_gpadc_get_event()
138 if (adc_chan == adc->event1.channel && dir == adc->event1.direction) in palmas_gpadc_get_event()
145 int adc_chan) in palmas_gpadc_channel_is_freerunning() argument
147 return palmas_gpadc_get_event(adc, adc_chan, IIO_EV_DIR_RISING) || in palmas_gpadc_channel_is_freerunning()
148 palmas_gpadc_get_event(adc, adc_chan, IIO_EV_DIR_FALLING); in palmas_gpadc_channel_is_freerunning()
261 static int palmas_gpadc_enable(struct palmas_gpadc *adc, int adc_chan, in palmas_gpadc_enable() argument
296 val = (adc_chan | PALMAS_GPADC_SW_SELECT_SW_CONV_EN); in palmas_gpadc_enable()
321 static int palmas_gpadc_read_prepare(struct palmas_gpadc *adc, int adc_chan) in palmas_gpadc_read_prepare() argument
325 if (palmas_gpadc_channel_is_freerunning(adc, adc_chan)) in palmas_gpadc_read_prepare()
328 ret = palmas_gpadc_enable(adc, adc_chan, true); in palmas_gpadc_read_prepare()
335 static void palmas_gpadc_read_done(struct palmas_gpadc *adc, int adc_chan) in palmas_gpadc_read_done() argument
338 palmas_gpadc_enable(adc, adc_chan, false); in palmas_gpadc_read_done()
341 static int palmas_gpadc_calibrate(struct palmas_gpadc *adc, int adc_chan) in palmas_gpadc_calibrate() argument
348 int x1 = adc->adc_info[adc_chan].x1; in palmas_gpadc_calibrate()
349 int x2 = adc->adc_info[adc_chan].x2; in palmas_gpadc_calibrate()
350 int v1 = adc->adc_info[adc_chan].v1; in palmas_gpadc_calibrate()
351 int v2 = adc->adc_info[adc_chan].v2; in palmas_gpadc_calibrate()
354 adc->adc_info[adc_chan].trim1_reg, &d1); in palmas_gpadc_calibrate()
361 adc->adc_info[adc_chan].trim2_reg, &d2); in palmas_gpadc_calibrate()
373 adc->adc_info[adc_chan].gain_error = k; in palmas_gpadc_calibrate()
374 adc->adc_info[adc_chan].gain = gain; in palmas_gpadc_calibrate()
376 adc->adc_info[adc_chan].offset = (d1 * 1000) - ((k - 1000) * x1); in palmas_gpadc_calibrate()
382 static int palmas_gpadc_start_conversion(struct palmas_gpadc *adc, int adc_chan) in palmas_gpadc_start_conversion() argument
387 if (palmas_gpadc_channel_is_freerunning(adc, adc_chan)) { in palmas_gpadc_start_conversion()
388 int event = (adc_chan == adc->event0.channel) ? 0 : 1; in palmas_gpadc_start_conversion()
432 int adc_chan, int val) in palmas_gpadc_get_calibrated_code() argument
434 if (!adc->adc_info[adc_chan].is_uncalibrated) in palmas_gpadc_get_calibrated_code()
435 val = (val*1000 - adc->adc_info[adc_chan].offset) / in palmas_gpadc_get_calibrated_code()
436 adc->adc_info[adc_chan].gain_error; in palmas_gpadc_get_calibrated_code()
444 val = (val * adc->adc_info[adc_chan].gain) / 1000; in palmas_gpadc_get_calibrated_code()
478 const int adc_chan = ev->channel; in palmas_gpadc_get_high_threshold_raw() local
479 int val = adc->thresholds[adc_chan].high; in palmas_gpadc_get_high_threshold_raw()
487 val = (val * 1000) / adc->adc_info[adc_chan].gain; in palmas_gpadc_get_high_threshold_raw()
489 if (adc->adc_info[adc_chan].is_uncalibrated) { in palmas_gpadc_get_high_threshold_raw()
494 val = (val * adc->adc_info[adc_chan].gain_error + in palmas_gpadc_get_high_threshold_raw()
495 adc->adc_info[adc_chan].offset) / in palmas_gpadc_get_high_threshold_raw()
513 const int adc_chan = ev->channel; in palmas_gpadc_get_low_threshold_raw() local
514 int val = adc->thresholds[adc_chan].low; in palmas_gpadc_get_low_threshold_raw()
522 val = (val * 1000) / adc->adc_info[adc_chan].gain; in palmas_gpadc_get_low_threshold_raw()
524 if (adc->adc_info[adc_chan].is_uncalibrated) { in palmas_gpadc_get_low_threshold_raw()
529 val = (val * adc->adc_info[adc_chan].gain_error - in palmas_gpadc_get_low_threshold_raw()
530 adc->adc_info[adc_chan].offset) / in palmas_gpadc_get_low_threshold_raw()
545 int adc_chan = chan->channel; in palmas_gpadc_read_raw() local
548 if (adc_chan >= PALMAS_ADC_CH_MAX) in palmas_gpadc_read_raw()
556 ret = palmas_gpadc_read_prepare(adc, adc_chan); in palmas_gpadc_read_raw()
560 ret = palmas_gpadc_start_conversion(adc, adc_chan); in palmas_gpadc_read_raw()
569 adc, adc_chan, ret); in palmas_gpadc_read_raw()
581 palmas_gpadc_read_done(adc, adc_chan); in palmas_gpadc_read_raw()
593 int adc_chan = chan->channel; in palmas_gpadc_read_event_config() local
596 if (adc_chan >= PALMAS_ADC_CH_MAX || type != IIO_EV_TYPE_THRESH) in palmas_gpadc_read_event_config()
601 if (palmas_gpadc_get_event(adc, adc_chan, dir)) in palmas_gpadc_read_event_config()
624 int adc_chan = chan->channel; in palmas_gpadc_enable_event_config() local
626 if (palmas_gpadc_get_event(adc, adc_chan, dir)) in palmas_gpadc_enable_event_config()
634 if (adc_chan < adc->event0.channel) { in palmas_gpadc_enable_event_config()
647 ev->channel = adc_chan; in palmas_gpadc_enable_event_config()
657 int adc_chan = chan->channel; in palmas_gpadc_disable_event_config() local
658 struct palmas_adc_event *ev = palmas_gpadc_get_event(adc, adc_chan, dir); in palmas_gpadc_disable_event_config()
682 int adc_chan = chan->channel; in palmas_gpadc_write_event_config() local
685 if (adc_chan >= PALMAS_ADC_CH_MAX || type != IIO_EV_TYPE_THRESH) in palmas_gpadc_write_event_config()
708 int adc_chan = chan->channel; in palmas_gpadc_read_event_value() local
711 if (adc_chan >= PALMAS_ADC_CH_MAX || type != IIO_EV_TYPE_THRESH) in palmas_gpadc_read_event_value()
719 adc->thresholds[adc_chan].high : in palmas_gpadc_read_event_value()
720 adc->thresholds[adc_chan].low; in palmas_gpadc_read_event_value()
741 int adc_chan = chan->channel; in palmas_gpadc_write_event_value() local
745 if (adc_chan >= PALMAS_ADC_CH_MAX || type != IIO_EV_TYPE_THRESH) in palmas_gpadc_write_event_value()
756 old = adc->thresholds[adc_chan].high; in palmas_gpadc_write_event_value()
757 adc->thresholds[adc_chan].high = val; in palmas_gpadc_write_event_value()
759 old = adc->thresholds[adc_chan].low; in palmas_gpadc_write_event_value()
760 adc->thresholds[adc_chan].low = val; in palmas_gpadc_write_event_value()
769 if (val != old && palmas_gpadc_get_event(adc, adc_chan, dir)) in palmas_gpadc_write_event_value()