Lines Matching +full:hw +full:- +full:settle +full:- +full:time
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
95 * struct iadc_chip - IADC Current ADC device structure.
123 ret = regmap_read(iadc->regmap, iadc->base + offset, &val); in iadc_read()
133 return regmap_write(iadc->regmap, iadc->base + offset, data); in iadc_write()
192 dev_err(iadc->dev, in iadc_status_show()
219 /* HW settle time delay */ in iadc_configure()
236 if (!iadc->poll_eoc) in iadc_configure()
237 reinit_completion(&iadc->complete); in iadc_configure()
269 return -ETIMEDOUT; in iadc_poll_wait_eoc()
274 return regmap_bulk_read(iadc->regmap, iadc->base + IADC_DATA, data, 2); in iadc_read_result()
288 if (iadc->poll_eoc) { in iadc_do_conversion()
291 ret = wait_for_completion_timeout(&iadc->complete, in iadc_do_conversion()
294 ret = -ETIMEDOUT; in iadc_do_conversion()
305 dev_err(iadc->dev, "conversion failed\n"); in iadc_do_conversion()
321 mutex_lock(&iadc->lock); in iadc_read_raw()
322 ret = iadc_do_conversion(iadc, chan->channel, &adc_raw); in iadc_read_raw()
323 mutex_unlock(&iadc->lock); in iadc_read_raw()
327 vsense_raw = adc_raw - iadc->offset[chan->channel]; in iadc_read_raw()
330 vsense_uv /= (s32)iadc->gain - iadc->offset[chan->channel]; in iadc_read_raw()
332 isense_ua = vsense_uv / iadc->rsense[chan->channel]; in iadc_read_raw()
334 dev_dbg(iadc->dev, "off %d gain %d adc %d %duV I %duA\n", in iadc_read_raw()
335 iadc->offset[chan->channel], iadc->gain, in iadc_read_raw()
346 return -EINVAL; in iadc_read_raw()
357 complete(&iadc->complete); in iadc_isr()
366 ret = iadc_do_conversion(iadc, IADC_GAIN_17P857MV, &iadc->gain); in iadc_update_offset()
371 &iadc->offset[IADC_INT_RSENSE]); in iadc_update_offset()
375 if (iadc->gain == iadc->offset[IADC_INT_RSENSE]) { in iadc_update_offset()
376 dev_err(iadc->dev, "error: internal offset == gain %d\n", in iadc_update_offset()
377 iadc->gain); in iadc_update_offset()
378 return -EINVAL; in iadc_update_offset()
382 &iadc->offset[IADC_EXT_RSENSE]); in iadc_update_offset()
386 if (iadc->gain == iadc->offset[IADC_EXT_RSENSE]) { in iadc_update_offset()
387 dev_err(iadc->dev, "error: external offset == gain %d\n", in iadc_update_offset()
388 iadc->gain); in iadc_update_offset()
389 return -EINVAL; in iadc_update_offset()
405 dev_err(iadc->dev, "%d is not ADC\n", val); in iadc_version_check()
406 return -EINVAL; in iadc_version_check()
414 dev_err(iadc->dev, "%d is not IADC\n", val); in iadc_version_check()
415 return -EINVAL; in iadc_version_check()
423 dev_err(iadc->dev, "revision %d not supported\n", val); in iadc_version_check()
424 return -EINVAL; in iadc_version_check()
435 ret = of_property_read_u32(node, "qcom,external-resistor-micro-ohms", in iadc_rsense_read()
436 &iadc->rsense[IADC_EXT_RSENSE]); in iadc_rsense_read()
438 iadc->rsense[IADC_EXT_RSENSE] = IADC_INT_RSENSE_IDEAL_VALUE; in iadc_rsense_read()
440 if (!iadc->rsense[IADC_EXT_RSENSE]) { in iadc_rsense_read()
441 dev_err(iadc->dev, "external resistor can't be zero Ohms"); in iadc_rsense_read()
442 return -EINVAL; in iadc_rsense_read()
453 sign = (deviation & IADC_NOMINAL_RSENSE_SIGN_MASK) ? -1 : 1; in iadc_rsense_read()
462 iadc->rsense[IADC_INT_RSENSE] = int_sense; in iadc_rsense_read()
487 struct device_node *node = pdev->dev.of_node; in iadc_probe()
488 struct device *dev = &pdev->dev; in iadc_probe()
496 return -ENOMEM; in iadc_probe()
499 iadc->dev = dev; in iadc_probe()
501 iadc->regmap = dev_get_regmap(dev->parent, NULL); in iadc_probe()
502 if (!iadc->regmap) in iadc_probe()
503 return -ENODEV; in iadc_probe()
505 init_completion(&iadc->complete); in iadc_probe()
506 mutex_init(&iadc->lock); in iadc_probe()
510 return -ENODEV; in iadc_probe()
512 iadc->base = res; in iadc_probe()
516 return -ENODEV; in iadc_probe()
520 return -ENODEV; in iadc_probe()
522 dev_dbg(iadc->dev, "sense resistors %d and %d micro Ohm\n", in iadc_probe()
523 iadc->rsense[IADC_INT_RSENSE], in iadc_probe()
524 iadc->rsense[IADC_EXT_RSENSE]); in iadc_probe()
527 if (irq_eoc == -EPROBE_DEFER) in iadc_probe()
531 iadc->poll_eoc = true; in iadc_probe()
539 if (!iadc->poll_eoc) { in iadc_probe()
541 "spmi-iadc", iadc); in iadc_probe()
547 device_init_wakeup(iadc->dev, 1); in iadc_probe()
556 indio_dev->name = pdev->name; in iadc_probe()
557 indio_dev->modes = INDIO_DIRECT_MODE; in iadc_probe()
558 indio_dev->info = &iadc_info; in iadc_probe()
559 indio_dev->channels = iadc_channels; in iadc_probe()
560 indio_dev->num_channels = ARRAY_SIZE(iadc_channels); in iadc_probe()
566 { .compatible = "qcom,spmi-iadc" },
574 .name = "qcom-spmi-iadc",
582 MODULE_ALIAS("platform:qcom-spmi-iadc");
585 MODULE_AUTHOR("Ivan T. Ivanov <iivanov@mm-sol.com>");