Lines Matching +full:vref +full:- +full:mv
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2014-2015 Pengutronix, Markus Pargmann <mpa@pengutronix.de>
9 #include <dt-bindings/iio/adc/fsl-imx25-gcq.h>
13 #include <linux/mfd/imx25-tsadc.h>
23 static const char * const driver_name = "mx25-gcq";
42 struct regulator *vref[4]; member
87 regmap_read(priv->regs, MX25_ADCQ_SR, &stats); in mx25_gcq_irq()
90 regmap_set_bits(priv->regs, MX25_ADCQ_MR, in mx25_gcq_irq()
92 complete(&priv->completed); in mx25_gcq_irq()
96 regmap_clear_bits(priv->regs, MX25_ADCQ_CR, MX25_ADCQ_CR_FQS); in mx25_gcq_irq()
99 regmap_write(priv->regs, MX25_ADCQ_SR, MX25_ADCQ_SR_FRR | in mx25_gcq_irq()
115 regmap_write(priv->regs, MX25_ADCQ_ITEM_7_0, in mx25_gcq_get_raw_value()
116 MX25_ADCQ_ITEM(0, chan->channel)); in mx25_gcq_get_raw_value()
118 regmap_clear_bits(priv->regs, MX25_ADCQ_MR, MX25_ADCQ_MR_EOQ_IRQ); in mx25_gcq_get_raw_value()
121 regmap_set_bits(priv->regs, MX25_ADCQ_CR, MX25_ADCQ_CR_FQS); in mx25_gcq_get_raw_value()
124 &priv->completed, MX25_GCQ_TIMEOUT); in mx25_gcq_get_raw_value()
130 return -ETIMEDOUT; in mx25_gcq_get_raw_value()
133 regmap_read(priv->regs, MX25_ADCQ_FIFO, &data); in mx25_gcq_get_raw_value()
149 mutex_lock(&priv->lock); in mx25_gcq_read_raw()
150 ret = mx25_gcq_get_raw_value(&indio_dev->dev, chan, priv, val); in mx25_gcq_read_raw()
151 mutex_unlock(&priv->lock); in mx25_gcq_read_raw()
155 *val = priv->channel_vref_mv[chan->channel]; in mx25_gcq_read_raw()
160 return -EINVAL; in mx25_gcq_read_raw()
181 if (priv->vref[refp]) in mx25_gcq_ext_regulator_setup()
184 ret = snprintf(reg_name, sizeof(reg_name), "vref-%s", in mx25_gcq_ext_regulator_setup()
189 priv->vref[refp] = devm_regulator_get_optional(dev, reg_name); in mx25_gcq_ext_regulator_setup()
190 if (IS_ERR(priv->vref[refp])) in mx25_gcq_ext_regulator_setup()
191 return dev_err_probe(dev, PTR_ERR(priv->vref[refp]), in mx25_gcq_ext_regulator_setup()
201 struct device *dev = &pdev->dev; in mx25_gcq_setup_cfgs()
209 regmap_write(priv->regs, MX25_ADCQ_CFG(i), in mx25_gcq_setup_cfgs()
228 return dev_err_probe(dev, -EINVAL, in mx25_gcq_setup_cfgs()
231 fwnode_property_read_u32(child, "fsl,adc-refp", &refp); in mx25_gcq_setup_cfgs()
232 fwnode_property_read_u32(child, "fsl,adc-refn", &refn); in mx25_gcq_setup_cfgs()
238 ret = mx25_gcq_ext_regulator_setup(&pdev->dev, priv, refp); in mx25_gcq_setup_cfgs()
241 priv->channel_vref_mv[reg] = in mx25_gcq_setup_cfgs()
242 regulator_get_voltage(priv->vref[refp]); in mx25_gcq_setup_cfgs()
243 /* Conversion from uV to mV */ in mx25_gcq_setup_cfgs()
244 priv->channel_vref_mv[reg] /= 1000; in mx25_gcq_setup_cfgs()
247 priv->channel_vref_mv[reg] = 2500; in mx25_gcq_setup_cfgs()
250 return dev_err_probe(dev, -EINVAL, in mx25_gcq_setup_cfgs()
262 return dev_err_probe(dev, -EINVAL, in mx25_gcq_setup_cfgs()
263 "Invalid fsl,adc-refp property value\n"); in mx25_gcq_setup_cfgs()
266 return dev_err_probe(dev, -EINVAL, in mx25_gcq_setup_cfgs()
267 "Invalid fsl,adc-refn property value\n"); in mx25_gcq_setup_cfgs()
269 regmap_update_bits(priv->regs, MX25_ADCQ_CFG(reg), in mx25_gcq_setup_cfgs()
274 regmap_set_bits(priv->regs, MX25_ADCQ_CR, in mx25_gcq_setup_cfgs()
277 regmap_write(priv->regs, MX25_ADCQ_CR, in mx25_gcq_setup_cfgs()
298 struct mx25_tsadc *tsadc = dev_get_drvdata(pdev->dev.parent); in mx25_gcq_probe()
299 struct device *dev = &pdev->dev; in mx25_gcq_probe()
306 return -ENOMEM; in mx25_gcq_probe()
314 priv->regs = devm_regmap_init_mmio(dev, mem, &mx25_gcq_regconfig); in mx25_gcq_probe()
315 if (IS_ERR(priv->regs)) in mx25_gcq_probe()
316 return dev_err_probe(dev, PTR_ERR(priv->regs), in mx25_gcq_probe()
319 mutex_init(&priv->lock); in mx25_gcq_probe()
321 init_completion(&priv->completed); in mx25_gcq_probe()
328 if (!priv->vref[i]) in mx25_gcq_probe()
331 ret = regulator_enable(priv->vref[i]); in mx25_gcq_probe()
336 priv->vref[i]); in mx25_gcq_probe()
341 priv->clk = tsadc->clk; in mx25_gcq_probe()
342 ret = clk_prepare_enable(priv->clk); in mx25_gcq_probe()
347 priv->clk); in mx25_gcq_probe()
355 priv->irq = ret; in mx25_gcq_probe()
356 ret = devm_request_irq(dev, priv->irq, mx25_gcq_irq, 0, pdev->name, in mx25_gcq_probe()
361 indio_dev->channels = mx25_gcq_channels; in mx25_gcq_probe()
362 indio_dev->num_channels = ARRAY_SIZE(mx25_gcq_channels); in mx25_gcq_probe()
363 indio_dev->info = &mx25_gcq_iio_info; in mx25_gcq_probe()
364 indio_dev->name = driver_name; in mx25_gcq_probe()
374 { .compatible = "fsl,imx25-gcq", },
381 .name = "mx25-gcq",