Lines Matching full:gpadc

43 /* GPADC register offsets and bit definitions */
46 /* GPADC control register 1 bits */
62 * GPADC control register 2 and 3 bits
145 /* GPADC constants from AB8500 spec, UM0836 */
162 /* GPADC constants from AB8540 spec */
207 * struct ab8500_gpadc_chan_info - per-channel GPADC info
230 * struct ab8500_gpadc - AB8500 GPADC device information
236 * the completion of an gpadc conversion cycle
238 * @irq_sw: interrupt number that is used by gpadc for software ADC conversion
239 * @irq_hw: interrupt number that is used by gpadc for hardware ADC conversion
255 ab8500_gpadc_get_channel(struct ab8500_gpadc *gpadc, u8 chan) in ab8500_gpadc_get_channel() argument
260 for (i = 0; i < gpadc->nchans; i++) { in ab8500_gpadc_get_channel()
261 ch = &gpadc->chans[i]; in ab8500_gpadc_get_channel()
265 if (i == gpadc->nchans) in ab8500_gpadc_get_channel()
273 * @gpadc: GPADC instance
277 static int ab8500_gpadc_ad_to_voltage(struct ab8500_gpadc *gpadc, in ab8500_gpadc_ad_to_voltage() argument
286 if (!gpadc->cal_data[AB8500_CAL_VMAIN].gain) { in ab8500_gpadc_ad_to_voltage()
293 res = (int) (ad_value * gpadc->cal_data[AB8500_CAL_VMAIN].gain + in ab8500_gpadc_ad_to_voltage()
294 gpadc->cal_data[AB8500_CAL_VMAIN].offset) / AB8500_GPADC_CALIB_SCALE; in ab8500_gpadc_ad_to_voltage()
304 if (!gpadc->cal_data[AB8500_CAL_BTEMP].gain) { in ab8500_gpadc_ad_to_voltage()
311 res = (int) (ad_value * gpadc->cal_data[AB8500_CAL_BTEMP].gain + in ab8500_gpadc_ad_to_voltage()
312 gpadc->cal_data[AB8500_CAL_BTEMP].offset) / AB8500_GPADC_CALIB_SCALE; in ab8500_gpadc_ad_to_voltage()
318 if (!gpadc->cal_data[AB8500_CAL_VBAT].gain) { in ab8500_gpadc_ad_to_voltage()
325 res = (int) (ad_value * gpadc->cal_data[AB8500_CAL_VBAT].gain + in ab8500_gpadc_ad_to_voltage()
326 gpadc->cal_data[AB8500_CAL_VBAT].offset) / AB8500_GPADC_CALIB_SCALE; in ab8500_gpadc_ad_to_voltage()
362 if (!gpadc->cal_data[AB8500_CAL_IBAT].gain) { in ab8500_gpadc_ad_to_voltage()
369 res = (int) (ad_value * gpadc->cal_data[AB8500_CAL_IBAT].gain + in ab8500_gpadc_ad_to_voltage()
370 gpadc->cal_data[AB8500_CAL_IBAT].offset) in ab8500_gpadc_ad_to_voltage()
375 dev_err(gpadc->dev, in ab8500_gpadc_ad_to_voltage()
386 static int ab8500_gpadc_read(struct ab8500_gpadc *gpadc, in ab8500_gpadc_read() argument
401 if (!gpadc) in ab8500_gpadc_read()
405 if ((gpadc->irq_sw <= 0) && !ch->hardware_control) in ab8500_gpadc_read()
407 if ((gpadc->irq_hw <= 0) && ch->hardware_control) in ab8500_gpadc_read()
411 pm_runtime_get_sync(gpadc->dev); in ab8500_gpadc_read()
415 ret = abx500_get_register_interruptible(gpadc->dev, in ab8500_gpadc_read()
424 dev_err(gpadc->dev, "gpadc_conversion: GPADC busy"); in ab8500_gpadc_read()
429 /* Enable GPADC */ in ab8500_gpadc_read()
449 ret = abx500_set_register_interruptible(gpadc->dev, in ab8500_gpadc_read()
455 ret = abx500_set_register_interruptible(gpadc->dev, in ab8500_gpadc_read()
459 dev_err(gpadc->dev, in ab8500_gpadc_read()
476 if (!is_ab8500_2p0_or_earlier(gpadc->ab8500)) { in ab8500_gpadc_read()
494 ret = abx500_set_register_interruptible(gpadc->dev, in ab8500_gpadc_read()
497 dev_err(gpadc->dev, in ab8500_gpadc_read()
507 ret = abx500_set_register_interruptible(gpadc->dev, in ab8500_gpadc_read()
511 dev_err(gpadc->dev, in ab8500_gpadc_read()
520 ret = abx500_mask_and_set_register_interruptible(gpadc->dev, in ab8500_gpadc_read()
525 dev_err(gpadc->dev, in ab8500_gpadc_read()
535 if (!wait_for_completion_timeout(&gpadc->complete, in ab8500_gpadc_read()
537 dev_err(gpadc->dev, in ab8500_gpadc_read()
538 "timeout didn't receive GPADC conv interrupt\n"); in ab8500_gpadc_read()
544 ret = abx500_get_register_interruptible(gpadc->dev, in ab8500_gpadc_read()
547 dev_err(gpadc->dev, in ab8500_gpadc_read()
552 ret = abx500_get_register_interruptible(gpadc->dev, in ab8500_gpadc_read()
555 dev_err(gpadc->dev, in ab8500_gpadc_read()
569 dev_err(gpadc->dev, in ab8500_gpadc_read()
574 ret = abx500_get_register_interruptible(gpadc->dev, in ab8500_gpadc_read()
578 dev_err(gpadc->dev, in ab8500_gpadc_read()
583 ret = abx500_get_register_interruptible(gpadc->dev, in ab8500_gpadc_read()
587 dev_err(gpadc->dev, in ab8500_gpadc_read()
594 dev_warn(gpadc->dev, in ab8500_gpadc_read()
601 /* Disable GPADC */ in ab8500_gpadc_read()
602 ret = abx500_set_register_interruptible(gpadc->dev, AB8500_GPADC, in ab8500_gpadc_read()
605 dev_err(gpadc->dev, "gpadc_conversion: disable gpadc failed\n"); in ab8500_gpadc_read()
610 pm_runtime_mark_last_busy(gpadc->dev); in ab8500_gpadc_read()
611 pm_runtime_put_autosuspend(gpadc->dev); in ab8500_gpadc_read()
617 * It has shown to be needed to turn off the GPADC if an error occurs, in ab8500_gpadc_read()
619 * GPADC status register to go low. In V1.1 there wait_for_completion in ab8500_gpadc_read()
622 (void) abx500_set_register_interruptible(gpadc->dev, AB8500_GPADC, in ab8500_gpadc_read()
624 pm_runtime_put(gpadc->dev); in ab8500_gpadc_read()
625 dev_err(gpadc->dev, in ab8500_gpadc_read()
632 * ab8500_bm_gpadcconvend_handler() - isr for gpadc conversion completion
636 * This is a interrupt service routine for gpadc conversion completion.
637 * Notifies the gpadc completion is completed and the converted raw value
643 struct ab8500_gpadc *gpadc = data; in ab8500_bm_gpadcconvend_handler() local
645 complete(&gpadc->complete); in ab8500_bm_gpadcconvend_handler()
666 static void ab8500_gpadc_read_calibration_data(struct ab8500_gpadc *gpadc) in ab8500_gpadc_read_calibration_data() argument
681 ret[i] = abx500_get_register_interruptible(gpadc->dev, in ab8500_gpadc_read_calibration_data()
685 dev_err(gpadc->dev, "%s: read otp reg 0x%02x failed\n", in ab8500_gpadc_read_calibration_data()
761 if (is_ab8540(gpadc->ab8500)) { in ab8500_gpadc_read_calibration_data()
768 gpadc->cal_data[AB8500_CAL_VMAIN].otp_calib_hi = in ab8500_gpadc_read_calibration_data()
770 gpadc->cal_data[AB8500_CAL_VMAIN].otp_calib_lo = in ab8500_gpadc_read_calibration_data()
773 gpadc->cal_data[AB8500_CAL_VMAIN].gain = AB8500_GPADC_CALIB_SCALE * in ab8500_gpadc_read_calibration_data()
775 gpadc->cal_data[AB8500_CAL_VMAIN].offset = AB8500_GPADC_CALIB_SCALE * in ab8500_gpadc_read_calibration_data()
779 gpadc->cal_data[AB8500_CAL_VMAIN].gain = 0; in ab8500_gpadc_read_calibration_data()
785 gpadc->dev, AB8500_OTP_EMUL, in ab8500_gpadc_read_calibration_data()
788 dev_err(gpadc->dev, in ab8500_gpadc_read_calibration_data()
800 gpadc->cal_data[AB8500_CAL_IBAT].otp_calib_hi = in ab8500_gpadc_read_calibration_data()
802 gpadc->cal_data[AB8500_CAL_IBAT].otp_calib_lo = in ab8500_gpadc_read_calibration_data()
823 gpadc->cal_data[AB8500_CAL_IBAT].gain = in ab8500_gpadc_read_calibration_data()
825 gpadc->cal_data[AB8500_CAL_IBAT].offset = in ab8500_gpadc_read_calibration_data()
828 gpadc->cal_data[AB8500_CAL_IBAT].gain = 0; in ab8500_gpadc_read_calibration_data()
838 gpadc->cal_data[AB8500_CAL_VMAIN].otp_calib_hi = in ab8500_gpadc_read_calibration_data()
840 gpadc->cal_data[AB8500_CAL_VMAIN].otp_calib_lo = in ab8500_gpadc_read_calibration_data()
843 gpadc->cal_data[AB8500_CAL_VMAIN].gain = AB8500_GPADC_CALIB_SCALE * in ab8500_gpadc_read_calibration_data()
846 gpadc->cal_data[AB8500_CAL_VMAIN].offset = AB8500_GPADC_CALIB_SCALE * in ab8500_gpadc_read_calibration_data()
850 gpadc->cal_data[AB8500_CAL_VMAIN].gain = 0; in ab8500_gpadc_read_calibration_data()
860 gpadc->cal_data[AB8500_CAL_BTEMP].otp_calib_hi = (u16)btemp_high; in ab8500_gpadc_read_calibration_data()
861 gpadc->cal_data[AB8500_CAL_BTEMP].otp_calib_lo = (u16)btemp_low; in ab8500_gpadc_read_calibration_data()
863 gpadc->cal_data[AB8500_CAL_BTEMP].gain = in ab8500_gpadc_read_calibration_data()
865 gpadc->cal_data[AB8500_CAL_BTEMP].offset = AB8500_GPADC_CALIB_SCALE * 1300 - in ab8500_gpadc_read_calibration_data()
869 gpadc->cal_data[AB8500_CAL_BTEMP].gain = 0; in ab8500_gpadc_read_calibration_data()
877 gpadc->cal_data[AB8500_CAL_VBAT].otp_calib_hi = (u16)vbat_high; in ab8500_gpadc_read_calibration_data()
878 gpadc->cal_data[AB8500_CAL_VBAT].otp_calib_lo = (u16)vbat_low; in ab8500_gpadc_read_calibration_data()
880 gpadc->cal_data[AB8500_CAL_VBAT].gain = AB8500_GPADC_CALIB_SCALE * in ab8500_gpadc_read_calibration_data()
882 gpadc->cal_data[AB8500_CAL_VBAT].offset = AB8500_GPADC_CALIB_SCALE * 4700 - in ab8500_gpadc_read_calibration_data()
886 gpadc->cal_data[AB8500_CAL_VBAT].gain = 0; in ab8500_gpadc_read_calibration_data()
894 struct ab8500_gpadc *gpadc = iio_priv(indio_dev); in ab8500_gpadc_read_raw() local
899 ch = ab8500_gpadc_get_channel(gpadc, chan->address); in ab8500_gpadc_read_raw()
901 dev_err(gpadc->dev, "no such channel %lu\n", in ab8500_gpadc_read_raw()
906 raw_val = ab8500_gpadc_read(gpadc, ch, NULL); in ab8500_gpadc_read_raw()
916 processed = ab8500_gpadc_ad_to_voltage(gpadc, ch->id, raw_val); in ab8500_gpadc_read_raw()
948 struct ab8500_gpadc *gpadc = iio_priv(indio_dev); in ab8500_gpadc_runtime_suspend() local
950 regulator_disable(gpadc->vddadc); in ab8500_gpadc_runtime_suspend()
958 struct ab8500_gpadc *gpadc = iio_priv(indio_dev); in ab8500_gpadc_runtime_resume() local
961 ret = regulator_enable(gpadc->vddadc); in ab8500_gpadc_runtime_resume()
976 * and define usage for things like AUX GPADC inputs more precisely.
1022 * ab8500_gpadc_parse_channels() - Parse the GPADC channels from DT
1023 * @gpadc: the GPADC to configure the channels for
1027 static int ab8500_gpadc_parse_channels(struct ab8500_gpadc *gpadc, in ab8500_gpadc_parse_channels() argument
1036 nchans = device_get_child_node_count(gpadc->dev); in ab8500_gpadc_parse_channels()
1038 dev_err(gpadc->dev, "no channel children\n"); in ab8500_gpadc_parse_channels()
1041 dev_info(gpadc->dev, "found %d ADC channels\n", nchans); in ab8500_gpadc_parse_channels()
1043 iio_chans = devm_kcalloc(gpadc->dev, nchans, in ab8500_gpadc_parse_channels()
1048 gpadc->chans = devm_kcalloc(gpadc->dev, nchans, in ab8500_gpadc_parse_channels()
1049 sizeof(*gpadc->chans), GFP_KERNEL); in ab8500_gpadc_parse_channels()
1050 if (!gpadc->chans) in ab8500_gpadc_parse_channels()
1054 device_for_each_child_node_scoped(gpadc->dev, child) { in ab8500_gpadc_parse_channels()
1058 ch = &gpadc->chans[i]; in ab8500_gpadc_parse_channels()
1061 ret = ab8500_gpadc_parse_channel(gpadc->dev, child, ch, in ab8500_gpadc_parse_channels()
1068 gpadc->nchans = nchans; in ab8500_gpadc_parse_channels()
1077 struct ab8500_gpadc *gpadc; in ab8500_gpadc_probe() local
1084 indio_dev = devm_iio_device_alloc(dev, sizeof(*gpadc)); in ab8500_gpadc_probe()
1089 gpadc = iio_priv(indio_dev); in ab8500_gpadc_probe()
1091 gpadc->dev = dev; in ab8500_gpadc_probe()
1092 gpadc->ab8500 = dev_get_drvdata(dev->parent); in ab8500_gpadc_probe()
1094 ret = ab8500_gpadc_parse_channels(gpadc, &iio_chans, &n_iio_chans); in ab8500_gpadc_probe()
1098 gpadc->irq_sw = platform_get_irq_byname(pdev, "SW_CONV_END"); in ab8500_gpadc_probe()
1099 if (gpadc->irq_sw < 0) in ab8500_gpadc_probe()
1100 return gpadc->irq_sw; in ab8500_gpadc_probe()
1102 if (is_ab8500(gpadc->ab8500)) { in ab8500_gpadc_probe()
1103 gpadc->irq_hw = platform_get_irq_byname(pdev, "HW_CONV_END"); in ab8500_gpadc_probe()
1104 if (gpadc->irq_hw < 0) in ab8500_gpadc_probe()
1105 return gpadc->irq_hw; in ab8500_gpadc_probe()
1107 gpadc->irq_hw = 0; in ab8500_gpadc_probe()
1111 init_completion(&gpadc->complete); in ab8500_gpadc_probe()
1114 ret = devm_request_threaded_irq(dev, gpadc->irq_sw, NULL, in ab8500_gpadc_probe()
1116 "ab8500-gpadc-sw", gpadc); in ab8500_gpadc_probe()
1120 gpadc->irq_sw); in ab8500_gpadc_probe()
1124 if (gpadc->irq_hw) { in ab8500_gpadc_probe()
1125 ret = devm_request_threaded_irq(dev, gpadc->irq_hw, NULL, in ab8500_gpadc_probe()
1127 "ab8500-gpadc-hw", gpadc); in ab8500_gpadc_probe()
1131 gpadc->irq_hw); in ab8500_gpadc_probe()
1136 /* The VTVout LDO used to power the AB8500 GPADC */ in ab8500_gpadc_probe()
1137 gpadc->vddadc = devm_regulator_get(dev, "vddadc"); in ab8500_gpadc_probe()
1138 if (IS_ERR(gpadc->vddadc)) in ab8500_gpadc_probe()
1139 return dev_err_probe(dev, PTR_ERR(gpadc->vddadc), in ab8500_gpadc_probe()
1142 ret = regulator_enable(gpadc->vddadc); in ab8500_gpadc_probe()
1155 ab8500_gpadc_read_calibration_data(gpadc); in ab8500_gpadc_probe()
1159 indio_dev->name = "ab8500-gpadc"; in ab8500_gpadc_probe()
1175 regulator_disable(gpadc->vddadc); in ab8500_gpadc_probe()
1183 struct ab8500_gpadc *gpadc = iio_priv(indio_dev); in ab8500_gpadc_remove() local
1185 pm_runtime_get_sync(gpadc->dev); in ab8500_gpadc_remove()
1186 pm_runtime_put_noidle(gpadc->dev); in ab8500_gpadc_remove()
1187 pm_runtime_disable(gpadc->dev); in ab8500_gpadc_remove()
1188 regulator_disable(gpadc->vddadc); in ab8500_gpadc_remove()
1199 .name = "ab8500-gpadc",