Lines Matching +full:poll +full:- +full:retry +full:- +full:count

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
94 * struct iadc_chip - IADC Current ADC device structure.
99 * @poll_eoc: Poll for end of conversion instead of waiting for IRQ.
122 ret = regmap_read(iadc->regmap, iadc->base + offset, &val); in iadc_read()
132 return regmap_write(iadc->regmap, iadc->base + offset, data); in iadc_write()
191 dev_err(iadc->dev, in iadc_status_show()
235 if (!iadc->poll_eoc) in iadc_configure()
236 reinit_completion(&iadc->complete); in iadc_configure()
248 unsigned int count, retry; in iadc_poll_wait_eoc() local
252 retry = interval_us / IADC_CONV_TIME_MIN_US; in iadc_poll_wait_eoc()
254 for (count = 0; count < retry; count++) { in iadc_poll_wait_eoc()
268 return -ETIMEDOUT; in iadc_poll_wait_eoc()
273 return regmap_bulk_read(iadc->regmap, iadc->base + IADC_DATA, data, 2); in iadc_read_result()
287 if (iadc->poll_eoc) { in iadc_do_conversion()
290 ret = wait_for_completion_timeout(&iadc->complete, in iadc_do_conversion()
293 ret = -ETIMEDOUT; in iadc_do_conversion()
304 dev_err(iadc->dev, "conversion failed\n"); in iadc_do_conversion()
320 mutex_lock(&iadc->lock); in iadc_read_raw()
321 ret = iadc_do_conversion(iadc, chan->channel, &adc_raw); in iadc_read_raw()
322 mutex_unlock(&iadc->lock); in iadc_read_raw()
326 vsense_raw = adc_raw - iadc->offset[chan->channel]; in iadc_read_raw()
329 vsense_uv /= (s32)iadc->gain - iadc->offset[chan->channel]; in iadc_read_raw()
331 isense_ua = vsense_uv / iadc->rsense[chan->channel]; in iadc_read_raw()
333 dev_dbg(iadc->dev, "off %d gain %d adc %d %duV I %duA\n", in iadc_read_raw()
334 iadc->offset[chan->channel], iadc->gain, in iadc_read_raw()
345 return -EINVAL; in iadc_read_raw()
356 complete(&iadc->complete); in iadc_isr()
365 ret = iadc_do_conversion(iadc, IADC_GAIN_17P857MV, &iadc->gain); in iadc_update_offset()
370 &iadc->offset[IADC_INT_RSENSE]); in iadc_update_offset()
374 if (iadc->gain == iadc->offset[IADC_INT_RSENSE]) { in iadc_update_offset()
375 dev_err(iadc->dev, "error: internal offset == gain %d\n", in iadc_update_offset()
376 iadc->gain); in iadc_update_offset()
377 return -EINVAL; in iadc_update_offset()
381 &iadc->offset[IADC_EXT_RSENSE]); in iadc_update_offset()
385 if (iadc->gain == iadc->offset[IADC_EXT_RSENSE]) { in iadc_update_offset()
386 dev_err(iadc->dev, "error: external offset == gain %d\n", in iadc_update_offset()
387 iadc->gain); in iadc_update_offset()
388 return -EINVAL; in iadc_update_offset()
404 dev_err(iadc->dev, "%d is not ADC\n", val); in iadc_version_check()
405 return -EINVAL; in iadc_version_check()
413 dev_err(iadc->dev, "%d is not IADC\n", val); in iadc_version_check()
414 return -EINVAL; in iadc_version_check()
422 dev_err(iadc->dev, "revision %d not supported\n", val); in iadc_version_check()
423 return -EINVAL; in iadc_version_check()
434 ret = of_property_read_u32(node, "qcom,external-resistor-micro-ohms", in iadc_rsense_read()
435 &iadc->rsense[IADC_EXT_RSENSE]); in iadc_rsense_read()
437 iadc->rsense[IADC_EXT_RSENSE] = IADC_INT_RSENSE_IDEAL_VALUE; in iadc_rsense_read()
439 if (!iadc->rsense[IADC_EXT_RSENSE]) { in iadc_rsense_read()
440 dev_err(iadc->dev, "external resistor can't be zero Ohms"); in iadc_rsense_read()
441 return -EINVAL; in iadc_rsense_read()
452 sign = (deviation & IADC_NOMINAL_RSENSE_SIGN_MASK) ? -1 : 1; in iadc_rsense_read()
461 iadc->rsense[IADC_INT_RSENSE] = int_sense; in iadc_rsense_read()
486 struct device_node *node = pdev->dev.of_node; in iadc_probe()
487 struct device *dev = &pdev->dev; in iadc_probe()
495 return -ENOMEM; in iadc_probe()
498 iadc->dev = dev; in iadc_probe()
500 iadc->regmap = dev_get_regmap(dev->parent, NULL); in iadc_probe()
501 if (!iadc->regmap) in iadc_probe()
502 return -ENODEV; in iadc_probe()
504 init_completion(&iadc->complete); in iadc_probe()
505 mutex_init(&iadc->lock); in iadc_probe()
509 return -ENODEV; in iadc_probe()
511 iadc->base = res; in iadc_probe()
515 return -ENODEV; in iadc_probe()
519 return -ENODEV; in iadc_probe()
521 dev_dbg(iadc->dev, "sense resistors %d and %d micro Ohm\n", in iadc_probe()
522 iadc->rsense[IADC_INT_RSENSE], in iadc_probe()
523 iadc->rsense[IADC_EXT_RSENSE]); in iadc_probe()
526 if (irq_eoc == -EPROBE_DEFER) in iadc_probe()
530 iadc->poll_eoc = true; in iadc_probe()
538 if (!iadc->poll_eoc) { in iadc_probe()
540 "spmi-iadc", iadc); in iadc_probe()
546 device_init_wakeup(iadc->dev, 1); in iadc_probe()
555 indio_dev->name = pdev->name; in iadc_probe()
556 indio_dev->modes = INDIO_DIRECT_MODE; in iadc_probe()
557 indio_dev->info = &iadc_info; in iadc_probe()
558 indio_dev->channels = iadc_channels; in iadc_probe()
559 indio_dev->num_channels = ARRAY_SIZE(iadc_channels); in iadc_probe()
565 { .compatible = "qcom,spmi-iadc" },
573 .name = "qcom-spmi-iadc",
581 MODULE_ALIAS("platform:qcom-spmi-iadc");
584 MODULE_AUTHOR("Ivan T. Ivanov <iivanov@mm-sol.com>");