Lines Matching +full:iio +full:- +full:aux
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2014-2015 Imagination Technologies Ltd.
16 #include <linux/iio/buffer.h>
17 #include <linux/iio/iio.h>
18 #include <linux/iio/sysfs.h>
19 #include <linux/iio/trigger.h>
20 #include <linux/iio/trigger_consumer.h>
21 #include <linux/iio/triggered_buffer.h>
47 * As per device specification, wait six clock cycles after power-up to
69 writel(val, adc_dev->reg_base + reg); in cc10001_adc_write_reg()
75 return readl(adc_dev->reg_base + reg); in cc10001_adc_read_reg()
81 ndelay(adc_dev->start_delay_ns); in cc10001_adc_power_up()
146 indio_dev = pf->indio_dev; in cc10001_adc_trigger_h()
148 data = adc_dev->buf; in cc10001_adc_trigger_h()
150 mutex_lock(&adc_dev->lock); in cc10001_adc_trigger_h()
152 if (!adc_dev->shared) in cc10001_adc_trigger_h()
156 delay_ns = adc_dev->eoc_delay_ns / CC10001_MAX_POLL_COUNT; in cc10001_adc_trigger_h()
161 channel = indio_dev->channels[scan_idx].channel; in cc10001_adc_trigger_h()
166 dev_warn(&indio_dev->dev, in cc10001_adc_trigger_h()
175 if (!adc_dev->shared) in cc10001_adc_trigger_h()
178 mutex_unlock(&adc_dev->lock); in cc10001_adc_trigger_h()
183 iio_trigger_notify_done(indio_dev->trig); in cc10001_adc_trigger_h()
195 if (!adc_dev->shared) in cc10001_adc_read_raw_voltage()
199 delay_ns = adc_dev->eoc_delay_ns / CC10001_MAX_POLL_COUNT; in cc10001_adc_read_raw_voltage()
201 cc10001_adc_start(adc_dev, chan->channel); in cc10001_adc_read_raw_voltage()
203 val = cc10001_adc_poll_done(indio_dev, chan->channel, delay_ns); in cc10001_adc_read_raw_voltage()
205 if (!adc_dev->shared) in cc10001_adc_read_raw_voltage()
221 return -EBUSY; in cc10001_adc_read_raw()
222 mutex_lock(&adc_dev->lock); in cc10001_adc_read_raw()
224 mutex_unlock(&adc_dev->lock); in cc10001_adc_read_raw()
227 return -EIO; in cc10001_adc_read_raw()
231 ret = regulator_get_voltage(adc_dev->reg); in cc10001_adc_read_raw()
236 *val2 = chan->scan_type.realbits; in cc10001_adc_read_raw()
240 return -EINVAL; in cc10001_adc_read_raw()
249 kfree(adc_dev->buf); in cc10001_update_scan_mode()
250 adc_dev->buf = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); in cc10001_update_scan_mode()
251 if (!adc_dev->buf) in cc10001_update_scan_mode()
252 return -ENOMEM; in cc10001_update_scan_mode()
268 indio_dev->num_channels = bitmap_weight(&channel_map, in cc10001_adc_channel_init()
271 chan_array = devm_kcalloc(&indio_dev->dev, indio_dev->num_channels, in cc10001_adc_channel_init()
275 return -ENOMEM; in cc10001_adc_channel_init()
280 chan->type = IIO_VOLTAGE; in cc10001_adc_channel_init()
281 chan->indexed = 1; in cc10001_adc_channel_init()
282 chan->channel = bit; in cc10001_adc_channel_init()
283 chan->scan_index = idx; in cc10001_adc_channel_init()
284 chan->scan_type.sign = 'u'; in cc10001_adc_channel_init()
285 chan->scan_type.realbits = 10; in cc10001_adc_channel_init()
286 chan->scan_type.storagebits = 16; in cc10001_adc_channel_init()
287 chan->info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE); in cc10001_adc_channel_init()
288 chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW); in cc10001_adc_channel_init()
293 timestamp->type = IIO_TIMESTAMP; in cc10001_adc_channel_init()
294 timestamp->channel = -1; in cc10001_adc_channel_init()
295 timestamp->scan_index = idx; in cc10001_adc_channel_init()
296 timestamp->scan_type.sign = 's'; in cc10001_adc_channel_init()
297 timestamp->scan_type.realbits = 64; in cc10001_adc_channel_init()
298 timestamp->scan_type.storagebits = 64; in cc10001_adc_channel_init()
300 indio_dev->channels = chan_array; in cc10001_adc_channel_init()
317 struct device *dev = &pdev->dev; in cc10001_adc_probe()
318 struct device_node *node = dev->of_node; in cc10001_adc_probe()
327 return -ENOMEM; in cc10001_adc_probe()
331 channel_map = GENMASK(CC10001_ADC_NUM_CHANNELS - 1, 0); in cc10001_adc_probe()
332 if (!of_property_read_u32(node, "adc-reserved-channels", &ret)) { in cc10001_adc_probe()
333 adc_dev->shared = true; in cc10001_adc_probe()
337 adc_dev->reg = devm_regulator_get(dev, "vref"); in cc10001_adc_probe()
338 if (IS_ERR(adc_dev->reg)) in cc10001_adc_probe()
339 return PTR_ERR(adc_dev->reg); in cc10001_adc_probe()
341 ret = regulator_enable(adc_dev->reg); in cc10001_adc_probe()
345 ret = devm_add_action_or_reset(dev, cc10001_reg_disable, adc_dev->reg); in cc10001_adc_probe()
349 indio_dev->name = dev_name(dev); in cc10001_adc_probe()
350 indio_dev->info = &cc10001_adc_info; in cc10001_adc_probe()
351 indio_dev->modes = INDIO_DIRECT_MODE; in cc10001_adc_probe()
353 adc_dev->reg_base = devm_platform_ioremap_resource(pdev, 0); in cc10001_adc_probe()
354 if (IS_ERR(adc_dev->reg_base)) in cc10001_adc_probe()
355 return PTR_ERR(adc_dev->reg_base); in cc10001_adc_probe()
357 adc_dev->adc_clk = devm_clk_get_enabled(dev, "adc"); in cc10001_adc_probe()
358 if (IS_ERR(adc_dev->adc_clk)) { in cc10001_adc_probe()
360 return PTR_ERR(adc_dev->adc_clk); in cc10001_adc_probe()
363 adc_clk_rate = clk_get_rate(adc_dev->adc_clk); in cc10001_adc_probe()
366 return -EINVAL; in cc10001_adc_probe()
369 adc_dev->eoc_delay_ns = NSEC_PER_SEC / adc_clk_rate; in cc10001_adc_probe()
370 adc_dev->start_delay_ns = adc_dev->eoc_delay_ns * CC10001_WAIT_CYCLES; in cc10001_adc_probe()
373 * There is only one register to power-up/power-down the AUX ADC. in cc10001_adc_probe()
375 * If the ADC is used only by the MIPS, power-up/power-down at runtime. in cc10001_adc_probe()
377 if (adc_dev->shared) in cc10001_adc_probe()
388 mutex_init(&adc_dev->lock); in cc10001_adc_probe()
399 { .compatible = "cosmic,10001-adc", },
406 .name = "cc10001-adc",