Lines Matching +full:adc +full:- +full:clk
1 // SPDX-License-Identifier: GPL-2.0-only
3 * ST SPEAr ADC driver
17 #include <linux/clk.h>
40 #define SPEAR_ADC_MOD_NAME "spear-adc"
51 u32 clk; /* Not avail for 1340 & 1310 */ member
64 u32 clk; member
76 struct clk *clk; member
95 * Functions to access some SPEAr ADC register. Abstracted into
101 __raw_writel(val, &st->adc_base_spear6xx->status); in spear_adc_set_status()
107 u32 apb_clk = clk_get_rate(st->clk); in spear_adc_set_clk()
111 clk_high = count - clk_low; in spear_adc_set_clk()
112 st->current_clk = apb_clk / count; in spear_adc_set_clk()
115 &st->adc_base_spear6xx->clk); in spear_adc_set_clk()
121 __raw_writel(val, &st->adc_base_spear6xx->ch_ctrl[n]); in spear_adc_set_ctrl()
126 if (device_is_compatible(st->dev, "st,spear600-adc")) { in spear_adc_get_average()
127 return __raw_readl(&st->adc_base_spear6xx->average.msb) & in spear_adc_get_average()
130 return __raw_readl(&st->adc_base_spear3xx->average) & in spear_adc_get_average()
137 if (device_is_compatible(st->dev, "st,spear600-adc")) { in spear_adc_set_scanrate()
139 &st->adc_base_spear6xx->scan_rate_lo); in spear_adc_set_scanrate()
141 &st->adc_base_spear6xx->scan_rate_hi); in spear_adc_set_scanrate()
143 __raw_writel(rate, &st->adc_base_spear3xx->scan_rate); in spear_adc_set_scanrate()
158 mutex_lock(&st->lock); in spear_adc_read_raw()
160 status = SPEAR_ADC_STATUS_CHANNEL_NUM(chan->channel) | in spear_adc_read_raw()
161 SPEAR_ADC_STATUS_AVG_SAMPLE(st->avg_samples) | in spear_adc_read_raw()
164 if (st->vref_external == 0) in spear_adc_read_raw()
168 wait_for_completion(&st->completion); /* set by ISR */ in spear_adc_read_raw()
169 *val = st->value; in spear_adc_read_raw()
171 mutex_unlock(&st->lock); in spear_adc_read_raw()
176 *val = st->vref_external; in spear_adc_read_raw()
180 *val = st->current_clk; in spear_adc_read_raw()
184 return -EINVAL; in spear_adc_read_raw()
197 return -EINVAL; in spear_adc_write_raw()
199 mutex_lock(&st->lock); in spear_adc_write_raw()
204 ret = -EINVAL; in spear_adc_write_raw()
211 mutex_unlock(&st->lock); in spear_adc_write_raw()
240 st->value = spear_adc_get_average(st); in spear_adc_isr()
241 complete(&st->completion); in spear_adc_isr()
250 /* Reset ADC core */ in spear_adc_configure()
252 __raw_writel(0, &st->adc_base_spear6xx->clk); in spear_adc_configure()
257 spear_adc_set_clk(st, st->sampling_freq); in spear_adc_configure()
269 struct device *dev = &pdev->dev; in spear_adc_probe()
272 int ret = -ENODEV; in spear_adc_probe()
277 return dev_err_probe(dev, -ENOMEM, in spear_adc_probe()
281 st->dev = dev; in spear_adc_probe()
283 mutex_init(&st->lock); in spear_adc_probe()
288 * to support multi-arch kernels. in spear_adc_probe()
290 st->adc_base_spear6xx = devm_platform_ioremap_resource(pdev, 0); in spear_adc_probe()
291 if (IS_ERR(st->adc_base_spear6xx)) in spear_adc_probe()
292 return PTR_ERR(st->adc_base_spear6xx); in spear_adc_probe()
294 st->adc_base_spear3xx = in spear_adc_probe()
295 (struct adc_regs_spear3xx __iomem *)st->adc_base_spear6xx; in spear_adc_probe()
297 st->clk = devm_clk_get_enabled(dev, NULL); in spear_adc_probe()
298 if (IS_ERR(st->clk)) in spear_adc_probe()
299 return dev_err_probe(dev, PTR_ERR(st->clk), in spear_adc_probe()
311 if (device_property_read_u32(dev, "sampling-frequency", &st->sampling_freq)) in spear_adc_probe()
312 return dev_err_probe(dev, -EINVAL, in spear_adc_probe()
313 "sampling-frequency missing in DT\n"); in spear_adc_probe()
319 device_property_read_u32(dev, "average-samples", &st->avg_samples); in spear_adc_probe()
325 device_property_read_u32(dev, "vref-external", &st->vref_external); in spear_adc_probe()
329 init_completion(&st->completion); in spear_adc_probe()
331 indio_dev->name = SPEAR_ADC_MOD_NAME; in spear_adc_probe()
332 indio_dev->info = &spear_adc_info; in spear_adc_probe()
333 indio_dev->modes = INDIO_DIRECT_MODE; in spear_adc_probe()
334 indio_dev->channels = spear_adc_iio_channels; in spear_adc_probe()
335 indio_dev->num_channels = ARRAY_SIZE(spear_adc_iio_channels); in spear_adc_probe()
341 dev_info(dev, "SPEAR ADC driver loaded, IRQ %d\n", irq); in spear_adc_probe()
347 { .compatible = "st,spear600-adc", },
363 MODULE_DESCRIPTION("SPEAr ADC driver");