Lines Matching +full:da9150 +full:- +full:gpadc

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * DA9150 GPADC Driver
20 #include <linux/mfd/da9150/core.h>
21 #include <linux/mfd/da9150/registers.h>
75 struct da9150 *da9150; member
86 struct da9150_gpadc *gpadc = data; in da9150_gpadc_irq() local
88 complete(&gpadc->complete); in da9150_gpadc_irq()
93 static int da9150_gpadc_read_adc(struct da9150_gpadc *gpadc, int hw_chan) in da9150_gpadc_read_adc() argument
98 mutex_lock(&gpadc->lock); in da9150_gpadc_read_adc()
101 da9150_reg_write(gpadc->da9150, DA9150_GPADC_MAN, in da9150_gpadc_read_adc()
105 /* Consume left-over completion from a previous timeout */ in da9150_gpadc_read_adc()
106 try_wait_for_completion(&gpadc->complete); in da9150_gpadc_read_adc()
109 wait_for_completion_timeout(&gpadc->complete, msecs_to_jiffies(5)); in da9150_gpadc_read_adc()
112 da9150_bulk_read(gpadc->da9150, DA9150_GPADC_RES_A, 2, result_regs); in da9150_gpadc_read_adc()
114 mutex_unlock(&gpadc->lock); in da9150_gpadc_read_adc()
118 dev_err(gpadc->dev, "Timeout on channel %d of GPADC\n", in da9150_gpadc_read_adc()
120 return -ETIMEDOUT; in da9150_gpadc_read_adc()
123 /* LSBs - 2 bits */ in da9150_gpadc_read_adc()
126 /* MSBs - 8 bits */ in da9150_gpadc_read_adc()
156 static int da9150_gpadc_read_processed(struct da9150_gpadc *gpadc, int channel, in da9150_gpadc_read_processed() argument
161 raw_val = da9150_gpadc_read_adc(gpadc, hw_chan); in da9150_gpadc_read_processed()
203 return -EINVAL; in da9150_gpadc_read_scale()
215 *val = -144; in da9150_gpadc_read_offset()
218 return -EINVAL; in da9150_gpadc_read_offset()
226 struct da9150_gpadc *gpadc = iio_priv(indio_dev); in da9150_gpadc_read_raw() local
228 if ((chan->channel < DA9150_GPADC_CHAN_GPIOA) || in da9150_gpadc_read_raw()
229 (chan->channel > DA9150_GPADC_CHAN_TJUNC_OVP)) in da9150_gpadc_read_raw()
230 return -EINVAL; in da9150_gpadc_read_raw()
235 return da9150_gpadc_read_processed(gpadc, chan->channel, in da9150_gpadc_read_raw()
236 chan->address, val); in da9150_gpadc_read_raw()
238 return da9150_gpadc_read_scale(chan->channel, val, val2); in da9150_gpadc_read_raw()
240 return da9150_gpadc_read_offset(chan->channel, val); in da9150_gpadc_read_raw()
242 return -EINVAL; in da9150_gpadc_read_raw()
293 /* Default maps used by da9150-charger */
296 .consumer_dev_name = "da9150-charger",
301 .consumer_dev_name = "da9150-charger",
306 .consumer_dev_name = "da9150-charger",
311 .consumer_dev_name = "da9150-charger",
320 struct device *dev = &pdev->dev; in da9150_gpadc_probe()
321 struct da9150 *da9150 = dev_get_drvdata(dev->parent); in da9150_gpadc_probe() local
322 struct da9150_gpadc *gpadc; in da9150_gpadc_probe() local
326 indio_dev = devm_iio_device_alloc(dev, sizeof(*gpadc)); in da9150_gpadc_probe()
328 dev_err(&pdev->dev, "Failed to allocate IIO device\n"); in da9150_gpadc_probe()
329 return -ENOMEM; in da9150_gpadc_probe()
331 gpadc = iio_priv(indio_dev); in da9150_gpadc_probe()
333 gpadc->da9150 = da9150; in da9150_gpadc_probe()
334 gpadc->dev = dev; in da9150_gpadc_probe()
335 mutex_init(&gpadc->lock); in da9150_gpadc_probe()
336 init_completion(&gpadc->complete); in da9150_gpadc_probe()
338 irq = platform_get_irq_byname(pdev, "GPADC"); in da9150_gpadc_probe()
343 IRQF_ONESHOT, "GPADC", gpadc); in da9150_gpadc_probe()
349 ret = devm_iio_map_array_register(&pdev->dev, indio_dev, da9150_gpadc_default_maps); in da9150_gpadc_probe()
355 indio_dev->name = dev_name(dev); in da9150_gpadc_probe()
356 indio_dev->info = &da9150_gpadc_info; in da9150_gpadc_probe()
357 indio_dev->modes = INDIO_DIRECT_MODE; in da9150_gpadc_probe()
358 indio_dev->channels = da9150_gpadc_channels; in da9150_gpadc_probe()
359 indio_dev->num_channels = ARRAY_SIZE(da9150_gpadc_channels); in da9150_gpadc_probe()
361 return devm_iio_device_register(&pdev->dev, indio_dev); in da9150_gpadc_probe()
366 .name = "da9150-gpadc",
373 MODULE_DESCRIPTION("GPADC Driver for DA9150");