Lines Matching +full:adc +full:- +full:dev

1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* NXP PCF50633 ADC Driver
4 * (C) 2006-2008 by Openmoko, Inc.
11 * NOTE: This driver does not yet support subtractive ADC mode, which means
23 #include <linux/mfd/pcf50633/adc.h>
51 return platform_get_drvdata(pcf->adc_pdev); in __to_adc()
62 /* start ADC conversion on selected channel */ in adc_setup()
69 struct pcf50633_adc *adc = __to_adc(pcf); in trigger_next_adc_job_if_any() local
72 head = adc->queue_head; in trigger_next_adc_job_if_any()
74 if (!adc->queue[head]) in trigger_next_adc_job_if_any()
77 adc_setup(pcf, adc->queue[head]->mux, adc->queue[head]->avg); in trigger_next_adc_job_if_any()
83 struct pcf50633_adc *adc = __to_adc(pcf); in adc_enqueue_request() local
86 mutex_lock(&adc->queue_mutex); in adc_enqueue_request()
88 head = adc->queue_head; in adc_enqueue_request()
89 tail = adc->queue_tail; in adc_enqueue_request()
91 if (adc->queue[tail]) { in adc_enqueue_request()
92 mutex_unlock(&adc->queue_mutex); in adc_enqueue_request()
93 dev_err(pcf->dev, "ADC queue is full, dropping request\n"); in adc_enqueue_request()
94 return -EBUSY; in adc_enqueue_request()
97 adc->queue[tail] = req; in adc_enqueue_request()
100 adc->queue_tail = (tail + 1) & (PCF50633_MAX_ADC_FIFO_DEPTH - 1); in adc_enqueue_request()
102 mutex_unlock(&adc->queue_mutex); in adc_enqueue_request()
112 req->result = result; in pcf50633_adc_sync_read_callback()
113 complete(&req->completion); in pcf50633_adc_sync_read_callback()
144 return -ENOMEM; in pcf50633_adc_async_read()
146 req->mux = mux; in pcf50633_adc_async_read()
147 req->avg = avg; in pcf50633_adc_async_read()
148 req->callback = callback; in pcf50633_adc_async_read()
149 req->callback_param = callback_param; in pcf50633_adc_async_read()
168 dev_dbg(pcf->dev, "adc result = %d\n", result); in adc_result()
175 struct pcf50633_adc *adc = data; in pcf50633_adc_irq() local
176 struct pcf50633 *pcf = adc->pcf; in pcf50633_adc_irq()
180 mutex_lock(&adc->queue_mutex); in pcf50633_adc_irq()
181 head = adc->queue_head; in pcf50633_adc_irq()
183 req = adc->queue[head]; in pcf50633_adc_irq()
185 dev_err(pcf->dev, "pcf50633-adc irq: ADC queue empty!\n"); in pcf50633_adc_irq()
186 mutex_unlock(&adc->queue_mutex); in pcf50633_adc_irq()
189 adc->queue[head] = NULL; in pcf50633_adc_irq()
190 adc->queue_head = (head + 1) & in pcf50633_adc_irq()
191 (PCF50633_MAX_ADC_FIFO_DEPTH - 1); in pcf50633_adc_irq()
196 mutex_unlock(&adc->queue_mutex); in pcf50633_adc_irq()
198 req->callback(pcf, req->callback_param, res); in pcf50633_adc_irq()
204 struct pcf50633_adc *adc; in pcf50633_adc_probe() local
206 adc = devm_kzalloc(&pdev->dev, sizeof(*adc), GFP_KERNEL); in pcf50633_adc_probe()
207 if (!adc) in pcf50633_adc_probe()
208 return -ENOMEM; in pcf50633_adc_probe()
210 adc->pcf = dev_to_pcf50633(pdev->dev.parent); in pcf50633_adc_probe()
211 platform_set_drvdata(pdev, adc); in pcf50633_adc_probe()
213 pcf50633_register_irq(adc->pcf, PCF50633_IRQ_ADCRDY, in pcf50633_adc_probe()
214 pcf50633_adc_irq, adc); in pcf50633_adc_probe()
216 mutex_init(&adc->queue_mutex); in pcf50633_adc_probe()
223 struct pcf50633_adc *adc = platform_get_drvdata(pdev); in pcf50633_adc_remove() local
226 pcf50633_free_irq(adc->pcf, PCF50633_IRQ_ADCRDY); in pcf50633_adc_remove()
228 mutex_lock(&adc->queue_mutex); in pcf50633_adc_remove()
229 head = adc->queue_head; in pcf50633_adc_remove()
231 if (WARN_ON(adc->queue[head])) in pcf50633_adc_remove()
232 dev_err(adc->pcf->dev, in pcf50633_adc_remove()
233 "adc driver removed with request pending\n"); in pcf50633_adc_remove()
236 kfree(adc->queue[i]); in pcf50633_adc_remove()
238 mutex_unlock(&adc->queue_mutex); in pcf50633_adc_remove()
243 .name = "pcf50633-adc",
252 MODULE_DESCRIPTION("PCF50633 adc driver");
254 MODULE_ALIAS("platform:pcf50633-adc");