Lines Matching +full:adc +full:- +full:dev
1 // SPDX-License-Identifier: GPL-2.0-only
3 * palmas-adc.c -- TI PALMAS GPADC.
26 #define MOD_NAME "palmas-gpadc"
29 #define PALMAS_GPADC_TRIMINVALID -1
90 * struct palmas_gpadc - the palmas_gpadc structure
110 * This is the palmas_gpadc structure to store run-time information
114 struct device *dev; member
131 static struct palmas_adc_event *palmas_gpadc_get_event(struct palmas_gpadc *adc, in palmas_gpadc_get_event() argument
135 if (adc_chan == adc->event0.channel && dir == adc->event0.direction) in palmas_gpadc_get_event()
136 return &adc->event0; in palmas_gpadc_get_event()
138 if (adc_chan == adc->event1.channel && dir == adc->event1.direction) in palmas_gpadc_get_event()
139 return &adc->event1; in palmas_gpadc_get_event()
144 static bool palmas_gpadc_channel_is_freerunning(struct palmas_gpadc *adc, 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()
175 static int palmas_disable_auto_conversion(struct palmas_gpadc *adc) in palmas_disable_auto_conversion() argument
179 ret = palmas_update_bits(adc->palmas, PALMAS_GPADC_BASE, in palmas_disable_auto_conversion()
184 dev_err(adc->dev, "GPADC_CTRL1 update failed: %d\n", ret); in palmas_disable_auto_conversion()
188 ret = palmas_update_bits(adc->palmas, PALMAS_GPADC_BASE, in palmas_disable_auto_conversion()
194 dev_err(adc->dev, "AUTO_CTRL update failed: %d\n", ret); in palmas_disable_auto_conversion()
200 ret = palmas_update_bits(adc->palmas, PALMAS_GPADC_BASE, in palmas_disable_auto_conversion()
204 dev_err(adc->dev, "GPADC_CTRL1 update failed: %d\n", ret); in palmas_disable_auto_conversion()
211 struct palmas_gpadc *adc = data; in palmas_gpadc_irq() local
213 complete(&adc->conv_completion); in palmas_gpadc_irq()
221 struct palmas_gpadc *adc = iio_priv(indio_dev); in palmas_gpadc_irq_auto() local
224 dev_dbg(adc->dev, "Threshold interrupt %d occurs\n", irq); in palmas_gpadc_irq_auto()
225 palmas_disable_auto_conversion(adc); in palmas_gpadc_irq_auto()
227 ev = (irq == adc->irq_auto_0) ? &adc->event0 : &adc->event1; in palmas_gpadc_irq_auto()
228 if (ev->channel != -1) { in palmas_gpadc_irq_auto()
232 dir = ev->direction; in palmas_gpadc_irq_auto()
233 code = IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, ev->channel, in palmas_gpadc_irq_auto()
241 static int palmas_gpadc_start_mask_interrupt(struct palmas_gpadc *adc, in palmas_gpadc_start_mask_interrupt() argument
247 ret = palmas_update_bits(adc->palmas, PALMAS_INTERRUPT_BASE, in palmas_gpadc_start_mask_interrupt()
251 ret = palmas_update_bits(adc->palmas, PALMAS_INTERRUPT_BASE, in palmas_gpadc_start_mask_interrupt()
256 dev_err(adc->dev, "GPADC INT MASK update failed: %d\n", ret); in palmas_gpadc_start_mask_interrupt()
261 static int palmas_gpadc_enable(struct palmas_gpadc *adc, int adc_chan, in palmas_gpadc_enable() argument
268 val = (adc->extended_delay in palmas_gpadc_enable()
270 ret = palmas_update_bits(adc->palmas, PALMAS_GPADC_BASE, in palmas_gpadc_enable()
274 dev_err(adc->dev, "RT_CTRL update failed: %d\n", ret); in palmas_gpadc_enable()
281 val = (adc->ch0_current in palmas_gpadc_enable()
283 val |= (adc->ch3_current in palmas_gpadc_enable()
286 ret = palmas_update_bits(adc->palmas, PALMAS_GPADC_BASE, in palmas_gpadc_enable()
289 dev_err(adc->dev, in palmas_gpadc_enable()
297 ret = palmas_update_bits(adc->palmas, PALMAS_GPADC_BASE, in palmas_gpadc_enable()
300 dev_err(adc->dev, "SW_SELECT update failed: %d\n", ret); in palmas_gpadc_enable()
304 ret = palmas_write(adc->palmas, PALMAS_GPADC_BASE, in palmas_gpadc_enable()
307 dev_err(adc->dev, "SW_SELECT write failed: %d\n", ret); in palmas_gpadc_enable()
309 ret = palmas_update_bits(adc->palmas, PALMAS_GPADC_BASE, in palmas_gpadc_enable()
313 dev_err(adc->dev, "CTRL1 update failed: %d\n", ret); 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()
326 return 0; /* ADC already running */ in palmas_gpadc_read_prepare()
328 ret = palmas_gpadc_enable(adc, adc_chan, true); in palmas_gpadc_read_prepare()
332 return palmas_gpadc_start_mask_interrupt(adc, 0); 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
337 palmas_gpadc_start_mask_interrupt(adc, 1); in palmas_gpadc_read_done()
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()
353 ret = palmas_read(adc->palmas, PALMAS_TRIM_GPADC_BASE, in palmas_gpadc_calibrate()
354 adc->adc_info[adc_chan].trim1_reg, &d1); in palmas_gpadc_calibrate()
356 dev_err(adc->dev, "TRIM read failed: %d\n", ret); in palmas_gpadc_calibrate()
360 ret = palmas_read(adc->palmas, PALMAS_TRIM_GPADC_BASE, in palmas_gpadc_calibrate()
361 adc->adc_info[adc_chan].trim2_reg, &d2); in palmas_gpadc_calibrate()
363 dev_err(adc->dev, "TRIM read failed: %d\n", ret); in palmas_gpadc_calibrate()
368 k = (1000 + (1000 * (d2 - d1)) / (x2 - x1)); in palmas_gpadc_calibrate()
371 gain = ((v2 - v1) * 1000) / (x2 - x1); 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()
393 ret = palmas_bulk_read(adc->palmas, PALMAS_GPADC_BASE, in palmas_gpadc_start_conversion()
396 dev_err(adc->dev, "AUTO_CONV%x_LSB read failed: %d\n", in palmas_gpadc_start_conversion()
401 init_completion(&adc->conv_completion); in palmas_gpadc_start_conversion()
402 ret = palmas_update_bits(adc->palmas, PALMAS_GPADC_BASE, in palmas_gpadc_start_conversion()
407 dev_err(adc->dev, "SELECT_SW_START write failed: %d\n", ret); in palmas_gpadc_start_conversion()
411 ret = wait_for_completion_timeout(&adc->conv_completion, in palmas_gpadc_start_conversion()
414 dev_err(adc->dev, "conversion not completed\n"); in palmas_gpadc_start_conversion()
415 return -ETIMEDOUT; in palmas_gpadc_start_conversion()
418 ret = palmas_bulk_read(adc->palmas, PALMAS_GPADC_BASE, in palmas_gpadc_start_conversion()
421 dev_err(adc->dev, "SW_CONV0_LSB read failed: %d\n", ret); in palmas_gpadc_start_conversion()
431 static int palmas_gpadc_get_calibrated_code(struct palmas_gpadc *adc, 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()
439 if (val < -10) in palmas_gpadc_get_calibrated_code()
440 dev_err(adc->dev, "Mismatch with calibration var = %d\n", val); in palmas_gpadc_get_calibrated_code()
444 val = (val * adc->adc_info[adc_chan].gain) / 1000; in palmas_gpadc_get_calibrated_code()
452 * TPS65917-Q1, TPS65919-Q1, and TPS65916 Devices". This document recommend
453 * taking ADC tolerances into account and is based on the device integral non-
475 static int palmas_gpadc_get_high_threshold_raw(struct palmas_gpadc *adc, in palmas_gpadc_get_high_threshold_raw() argument
478 const int adc_chan = ev->channel; in palmas_gpadc_get_high_threshold_raw()
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()
510 static int palmas_gpadc_get_low_threshold_raw(struct palmas_gpadc *adc, in palmas_gpadc_get_low_threshold_raw() argument
513 const int adc_chan = ev->channel; in palmas_gpadc_get_low_threshold_raw()
514 int val = adc->thresholds[adc_chan].low; in palmas_gpadc_get_low_threshold_raw()
516 const int min_INL = -2; in palmas_gpadc_get_low_threshold_raw()
519 /* -0.6% when calibrated */ in palmas_gpadc_get_low_threshold_raw()
520 int min_gain_error = -6; 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()
526 min_gain_error -= 20; in palmas_gpadc_get_low_threshold_raw()
527 min_offset_error = -36; 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()
532 min_offset_error = -2; in palmas_gpadc_get_low_threshold_raw()
544 struct palmas_gpadc *adc = iio_priv(indio_dev); in palmas_gpadc_read_raw() local
545 int adc_chan = chan->channel; in palmas_gpadc_read_raw()
549 return -EINVAL; in palmas_gpadc_read_raw()
551 mutex_lock(&adc->lock); 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()
562 dev_err(adc->dev, in palmas_gpadc_read_raw()
563 "ADC start conversion failed\n"); in palmas_gpadc_read_raw()
569 adc, adc_chan, ret); in palmas_gpadc_read_raw()
577 mutex_unlock(&adc->lock); in palmas_gpadc_read_raw()
581 palmas_gpadc_read_done(adc, adc_chan); in palmas_gpadc_read_raw()
582 mutex_unlock(&adc->lock); in palmas_gpadc_read_raw()
592 struct palmas_gpadc *adc = iio_priv(indio_dev); in palmas_gpadc_read_event_config() local
593 int adc_chan = chan->channel; in palmas_gpadc_read_event_config()
597 return -EINVAL; in palmas_gpadc_read_event_config()
599 mutex_lock(&adc->lock); in palmas_gpadc_read_event_config()
601 if (palmas_gpadc_get_event(adc, adc_chan, dir)) in palmas_gpadc_read_event_config()
604 mutex_unlock(&adc->lock); in palmas_gpadc_read_event_config()
609 static int palmas_adc_configure_events(struct palmas_gpadc *adc);
610 static int palmas_adc_reset_events(struct palmas_gpadc *adc);
612 static int palmas_gpadc_reconfigure_event_channels(struct palmas_gpadc *adc) in palmas_gpadc_reconfigure_event_channels() argument
614 return (adc->event0.enabled || adc->event1.enabled) ? in palmas_gpadc_reconfigure_event_channels()
615 palmas_adc_configure_events(adc) : in palmas_gpadc_reconfigure_event_channels()
616 palmas_adc_reset_events(adc); in palmas_gpadc_reconfigure_event_channels()
619 static int palmas_gpadc_enable_event_config(struct palmas_gpadc *adc, in palmas_gpadc_enable_event_config() argument
624 int adc_chan = chan->channel; in palmas_gpadc_enable_event_config()
626 if (palmas_gpadc_get_event(adc, adc_chan, dir)) in palmas_gpadc_enable_event_config()
630 if (adc->event0.channel == -1) { in palmas_gpadc_enable_event_config()
631 ev = &adc->event0; in palmas_gpadc_enable_event_config()
632 } else if (adc->event1.channel == -1) { in palmas_gpadc_enable_event_config()
634 if (adc_chan < adc->event0.channel) { in palmas_gpadc_enable_event_config()
635 adc->event1 = adc->event0; in palmas_gpadc_enable_event_config()
636 ev = &adc->event0; in palmas_gpadc_enable_event_config()
638 ev = &adc->event1; in palmas_gpadc_enable_event_config()
641 dev_warn(adc->dev, "event0 - %d, event1 - %d\n", in palmas_gpadc_enable_event_config()
642 adc->event0.channel, adc->event1.channel); in palmas_gpadc_enable_event_config()
643 return -EBUSY; in palmas_gpadc_enable_event_config()
646 ev->enabled = true; in palmas_gpadc_enable_event_config()
647 ev->channel = adc_chan; in palmas_gpadc_enable_event_config()
648 ev->direction = dir; in palmas_gpadc_enable_event_config()
650 return palmas_gpadc_reconfigure_event_channels(adc); in palmas_gpadc_enable_event_config()
653 static int palmas_gpadc_disable_event_config(struct palmas_gpadc *adc, in palmas_gpadc_disable_event_config() argument
657 int adc_chan = chan->channel; in palmas_gpadc_disable_event_config()
658 struct palmas_adc_event *ev = palmas_gpadc_get_event(adc, adc_chan, dir); in palmas_gpadc_disable_event_config()
663 if (ev == &adc->event0) { in palmas_gpadc_disable_event_config()
664 adc->event0 = adc->event1; in palmas_gpadc_disable_event_config()
665 ev = &adc->event1; in palmas_gpadc_disable_event_config()
668 ev->enabled = false; in palmas_gpadc_disable_event_config()
669 ev->channel = -1; in palmas_gpadc_disable_event_config()
670 ev->direction = IIO_EV_DIR_NONE; in palmas_gpadc_disable_event_config()
672 return palmas_gpadc_reconfigure_event_channels(adc); in palmas_gpadc_disable_event_config()
681 struct palmas_gpadc *adc = iio_priv(indio_dev); in palmas_gpadc_write_event_config() local
682 int adc_chan = chan->channel; in palmas_gpadc_write_event_config()
686 return -EINVAL; in palmas_gpadc_write_event_config()
688 mutex_lock(&adc->lock); in palmas_gpadc_write_event_config()
691 ret = palmas_gpadc_enable_event_config(adc, chan, dir); in palmas_gpadc_write_event_config()
693 ret = palmas_gpadc_disable_event_config(adc, chan, dir); in palmas_gpadc_write_event_config()
695 mutex_unlock(&adc->lock); in palmas_gpadc_write_event_config()
707 struct palmas_gpadc *adc = iio_priv(indio_dev); in palmas_gpadc_read_event_value() local
708 int adc_chan = chan->channel; in palmas_gpadc_read_event_value()
712 return -EINVAL; in palmas_gpadc_read_event_value()
714 mutex_lock(&adc->lock); 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()
724 ret = -EINVAL; in palmas_gpadc_read_event_value()
728 mutex_unlock(&adc->lock); in palmas_gpadc_read_event_value()
740 struct palmas_gpadc *adc = iio_priv(indio_dev); in palmas_gpadc_write_event_value() local
741 int adc_chan = chan->channel; in palmas_gpadc_write_event_value()
746 return -EINVAL; in palmas_gpadc_write_event_value()
748 mutex_lock(&adc->lock); in palmas_gpadc_write_event_value()
752 ret = -EINVAL; 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()
765 ret = -EINVAL; in palmas_gpadc_write_event_value()
769 if (val != old && palmas_gpadc_get_event(adc, adc_chan, dir)) in palmas_gpadc_write_event_value()
770 ret = palmas_gpadc_reconfigure_event_channels(adc); in palmas_gpadc_write_event_value()
773 mutex_unlock(&adc->lock); in palmas_gpadc_write_event_value()
834 struct device_node *np = pdev->dev.of_node; in palmas_gpadc_get_adc_dt_data()
839 gp_data = devm_kzalloc(&pdev->dev, sizeof(*gp_data), GFP_KERNEL); in palmas_gpadc_get_adc_dt_data()
841 return -ENOMEM; in palmas_gpadc_get_adc_dt_data()
843 ret = of_property_read_u32(np, "ti,channel0-current-microamp", &pval); in palmas_gpadc_get_adc_dt_data()
845 gp_data->ch0_current = pval; in palmas_gpadc_get_adc_dt_data()
847 ret = of_property_read_u32(np, "ti,channel3-current-microamp", &pval); in palmas_gpadc_get_adc_dt_data()
849 gp_data->ch3_current = pval; in palmas_gpadc_get_adc_dt_data()
851 gp_data->extended_delay = of_property_read_bool(np, in palmas_gpadc_get_adc_dt_data()
852 "ti,enable-extended-delay"); in palmas_gpadc_get_adc_dt_data()
861 struct palmas_gpadc *adc = data; in palmas_gpadc_reset() local
862 if (adc->event0.enabled || adc->event1.enabled) in palmas_gpadc_reset()
863 palmas_adc_reset_events(adc); in palmas_gpadc_reset()
868 struct palmas_gpadc *adc; in palmas_gpadc_probe() local
874 pdata = dev_get_platdata(pdev->dev.parent); in palmas_gpadc_probe()
876 if (pdata && pdata->gpadc_pdata) in palmas_gpadc_probe()
877 gpadc_pdata = pdata->gpadc_pdata; in palmas_gpadc_probe()
879 if (!gpadc_pdata && pdev->dev.of_node) { in palmas_gpadc_probe()
885 return -EINVAL; in palmas_gpadc_probe()
887 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*adc)); in palmas_gpadc_probe()
889 dev_err(&pdev->dev, "iio_device_alloc failed\n"); in palmas_gpadc_probe()
890 return -ENOMEM; in palmas_gpadc_probe()
893 adc = iio_priv(indio_dev); in palmas_gpadc_probe()
894 adc->dev = &pdev->dev; in palmas_gpadc_probe()
895 adc->palmas = dev_get_drvdata(pdev->dev.parent); in palmas_gpadc_probe()
896 adc->adc_info = palmas_gpadc_info; in palmas_gpadc_probe()
898 mutex_init(&adc->lock); in palmas_gpadc_probe()
900 init_completion(&adc->conv_completion); in palmas_gpadc_probe()
903 adc->auto_conversion_period = gpadc_pdata->auto_conversion_period_ms; in palmas_gpadc_probe()
904 adc->irq = palmas_irq_get_virq(adc->palmas, PALMAS_GPADC_EOC_SW_IRQ); in palmas_gpadc_probe()
905 if (adc->irq < 0) in palmas_gpadc_probe()
906 return dev_err_probe(adc->dev, adc->irq, "get virq failed\n"); in palmas_gpadc_probe()
908 ret = devm_request_threaded_irq(&pdev->dev, adc->irq, NULL, in palmas_gpadc_probe()
910 IRQF_ONESHOT, dev_name(adc->dev), in palmas_gpadc_probe()
911 adc); in palmas_gpadc_probe()
913 return dev_err_probe(adc->dev, ret, in palmas_gpadc_probe()
914 "request irq %d failed\n", adc->irq); in palmas_gpadc_probe()
916 adc->irq_auto_0 = platform_get_irq(pdev, 1); in palmas_gpadc_probe()
917 if (adc->irq_auto_0 < 0) in palmas_gpadc_probe()
918 return adc->irq_auto_0; in palmas_gpadc_probe()
920 ret = devm_request_threaded_irq(&pdev->dev, adc->irq_auto_0, NULL, in palmas_gpadc_probe()
922 "palmas-adc-auto-0", indio_dev); in palmas_gpadc_probe()
924 return dev_err_probe(adc->dev, ret, in palmas_gpadc_probe()
926 adc->irq_auto_0); in palmas_gpadc_probe()
928 adc->irq_auto_1 = platform_get_irq(pdev, 2); in palmas_gpadc_probe()
929 if (adc->irq_auto_1 < 0) in palmas_gpadc_probe()
930 return adc->irq_auto_1; in palmas_gpadc_probe()
932 ret = devm_request_threaded_irq(&pdev->dev, adc->irq_auto_1, NULL, in palmas_gpadc_probe()
934 "palmas-adc-auto-1", indio_dev); in palmas_gpadc_probe()
936 return dev_err_probe(adc->dev, ret, in palmas_gpadc_probe()
938 adc->irq_auto_1); in palmas_gpadc_probe()
940 adc->event0.enabled = false; in palmas_gpadc_probe()
941 adc->event0.channel = -1; in palmas_gpadc_probe()
942 adc->event0.direction = IIO_EV_DIR_NONE; in palmas_gpadc_probe()
943 adc->event1.enabled = false; in palmas_gpadc_probe()
944 adc->event1.channel = -1; in palmas_gpadc_probe()
945 adc->event1.direction = IIO_EV_DIR_NONE; in palmas_gpadc_probe()
948 if (gpadc_pdata->ch0_current <= 1) in palmas_gpadc_probe()
949 adc->ch0_current = PALMAS_ADC_CH0_CURRENT_SRC_0; in palmas_gpadc_probe()
950 else if (gpadc_pdata->ch0_current <= 5) in palmas_gpadc_probe()
951 adc->ch0_current = PALMAS_ADC_CH0_CURRENT_SRC_5; in palmas_gpadc_probe()
952 else if (gpadc_pdata->ch0_current <= 15) in palmas_gpadc_probe()
953 adc->ch0_current = PALMAS_ADC_CH0_CURRENT_SRC_15; in palmas_gpadc_probe()
955 adc->ch0_current = PALMAS_ADC_CH0_CURRENT_SRC_20; in palmas_gpadc_probe()
958 if (gpadc_pdata->ch3_current <= 1) in palmas_gpadc_probe()
959 adc->ch3_current = PALMAS_ADC_CH3_CURRENT_SRC_0; in palmas_gpadc_probe()
960 else if (gpadc_pdata->ch3_current <= 10) in palmas_gpadc_probe()
961 adc->ch3_current = PALMAS_ADC_CH3_CURRENT_SRC_10; in palmas_gpadc_probe()
962 else if (gpadc_pdata->ch3_current <= 400) in palmas_gpadc_probe()
963 adc->ch3_current = PALMAS_ADC_CH3_CURRENT_SRC_400; in palmas_gpadc_probe()
965 adc->ch3_current = PALMAS_ADC_CH3_CURRENT_SRC_800; in palmas_gpadc_probe()
967 adc->extended_delay = gpadc_pdata->extended_delay; in palmas_gpadc_probe()
969 indio_dev->name = MOD_NAME; in palmas_gpadc_probe()
970 indio_dev->info = &palmas_gpadc_iio_info; in palmas_gpadc_probe()
971 indio_dev->modes = INDIO_DIRECT_MODE; in palmas_gpadc_probe()
972 indio_dev->channels = palmas_gpadc_iio_channel; in palmas_gpadc_probe()
973 indio_dev->num_channels = ARRAY_SIZE(palmas_gpadc_iio_channel); in palmas_gpadc_probe()
975 ret = devm_iio_device_register(&pdev->dev, indio_dev); in palmas_gpadc_probe()
977 return dev_err_probe(adc->dev, ret, in palmas_gpadc_probe()
980 device_set_wakeup_capable(&pdev->dev, 1); in palmas_gpadc_probe()
982 if (!(adc->adc_info[i].is_uncalibrated)) in palmas_gpadc_probe()
983 palmas_gpadc_calibrate(adc, i); in palmas_gpadc_probe()
986 ret = devm_add_action(&pdev->dev, palmas_gpadc_reset, adc); in palmas_gpadc_probe()
993 static int palmas_adc_configure_events(struct palmas_gpadc *adc) in palmas_adc_configure_events() argument
1001 adc_period = adc->auto_conversion_period; in palmas_adc_configure_events()
1007 i--; in palmas_adc_configure_events()
1009 ret = palmas_update_bits(adc->palmas, PALMAS_GPADC_BASE, in palmas_adc_configure_events()
1014 dev_err(adc->dev, "AUTO_CTRL write failed: %d\n", ret); in palmas_adc_configure_events()
1019 if (adc->event0.enabled) { in palmas_adc_configure_events()
1020 struct palmas_adc_event *ev = &adc->event0; in palmas_adc_configure_events()
1023 ch0 = ev->channel; in palmas_adc_configure_events()
1025 switch (ev->direction) { in palmas_adc_configure_events()
1027 thres = palmas_gpadc_get_high_threshold_raw(adc, ev); in palmas_adc_configure_events()
1031 thres = palmas_gpadc_get_low_threshold_raw(adc, ev); in palmas_adc_configure_events()
1035 return -EINVAL; in palmas_adc_configure_events()
1038 ret = palmas_write(adc->palmas, PALMAS_GPADC_BASE, in palmas_adc_configure_events()
1041 dev_err(adc->dev, in palmas_adc_configure_events()
1046 ret = palmas_write(adc->palmas, PALMAS_GPADC_BASE, in palmas_adc_configure_events()
1050 dev_err(adc->dev, in palmas_adc_configure_events()
1056 if (adc->event1.enabled) { in palmas_adc_configure_events()
1057 struct palmas_adc_event *ev = &adc->event1; in palmas_adc_configure_events()
1060 ch1 = ev->channel; in palmas_adc_configure_events()
1062 switch (ev->direction) { in palmas_adc_configure_events()
1064 thres = palmas_gpadc_get_high_threshold_raw(adc, ev); in palmas_adc_configure_events()
1068 thres = palmas_gpadc_get_low_threshold_raw(adc, ev); in palmas_adc_configure_events()
1072 return -EINVAL; in palmas_adc_configure_events()
1075 ret = palmas_write(adc->palmas, PALMAS_GPADC_BASE, in palmas_adc_configure_events()
1078 dev_err(adc->dev, in palmas_adc_configure_events()
1083 ret = palmas_write(adc->palmas, PALMAS_GPADC_BASE, in palmas_adc_configure_events()
1087 dev_err(adc->dev, in palmas_adc_configure_events()
1093 ret = palmas_write(adc->palmas, PALMAS_GPADC_BASE, in palmas_adc_configure_events()
1096 dev_err(adc->dev, "AUTO_SELECT write failed: %d\n", ret); in palmas_adc_configure_events()
1100 ret = palmas_update_bits(adc->palmas, PALMAS_GPADC_BASE, in palmas_adc_configure_events()
1105 dev_err(adc->dev, "AUTO_CTRL write failed: %d\n", ret); in palmas_adc_configure_events()
1110 static int palmas_adc_reset_events(struct palmas_gpadc *adc) in palmas_adc_reset_events() argument
1114 ret = palmas_write(adc->palmas, PALMAS_GPADC_BASE, in palmas_adc_reset_events()
1117 dev_err(adc->dev, "AUTO_SELECT write failed: %d\n", ret); in palmas_adc_reset_events()
1121 ret = palmas_disable_auto_conversion(adc); in palmas_adc_reset_events()
1123 dev_err(adc->dev, "Disable auto conversion failed: %d\n", ret); in palmas_adc_reset_events()
1128 static int palmas_gpadc_suspend(struct device *dev) in palmas_gpadc_suspend() argument
1130 struct iio_dev *indio_dev = dev_get_drvdata(dev); in palmas_gpadc_suspend()
1131 struct palmas_gpadc *adc = iio_priv(indio_dev); in palmas_gpadc_suspend() local
1133 if (!device_may_wakeup(dev)) in palmas_gpadc_suspend()
1136 if (adc->event0.enabled) in palmas_gpadc_suspend()
1137 enable_irq_wake(adc->irq_auto_0); in palmas_gpadc_suspend()
1139 if (adc->event1.enabled) in palmas_gpadc_suspend()
1140 enable_irq_wake(adc->irq_auto_1); in palmas_gpadc_suspend()
1145 static int palmas_gpadc_resume(struct device *dev) in palmas_gpadc_resume() argument
1147 struct iio_dev *indio_dev = dev_get_drvdata(dev); in palmas_gpadc_resume()
1148 struct palmas_gpadc *adc = iio_priv(indio_dev); in palmas_gpadc_resume() local
1150 if (!device_may_wakeup(dev)) in palmas_gpadc_resume()
1153 if (adc->event0.enabled) in palmas_gpadc_resume()
1154 disable_irq_wake(adc->irq_auto_0); in palmas_gpadc_resume()
1156 if (adc->event1.enabled) in palmas_gpadc_resume()
1157 disable_irq_wake(adc->irq_auto_1); in palmas_gpadc_resume()
1166 { .compatible = "ti,palmas-gpadc", },
1183 MODULE_ALIAS("platform:palmas-gpadc");