Skip to content

Commit 033c9cf

Browse files
jprakash-qcRaj Aryan
authored andcommitted
iio: adc: qcom-spmi-adc5-gen3: Share SDAM0 IRQ with ADC_TM auxiliary driver
The SDAM0 IRQ can be triggered for both EOC (end of conversion) events for immediate ADC reads done in this driver and for threshold violation events, based on ADC_TM thresholds configured from the auxiliary ADC_TM driver on TM channels on the first SDAM. At present, this interrupt is handled only in the ISR in the main ADC driver. When the ISR is triggered for an ADC_TM event, this driver notifies the ADC_TM driver by calling a notifier callback exposed from it for this purpose. To simplify the interrupt handling in both drivers, share the interrupt between the drivers. With this, ADC_TM interrupts on SDAM0 will be handled directly in the ADC_TM driver, so remove the notifier callback and all TM interrupt handling in the main ADC ISR. Link: https://lore.kernel.org/all/20260526-gen3_adc_tm-v2-1-702fbac919ac@oss.qualcomm.com/ Signed-off-by: Jishnu Prakash <jishnu.prakash@oss.qualcomm.com> Reviewed-by: Jonathan Cameron <jic23@kernel.org>
1 parent 5426fd9 commit 033c9cf

2 files changed

Lines changed: 19 additions & 49 deletions

File tree

drivers/iio/adc/qcom-spmi-adc5-gen3.c

Lines changed: 19 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ struct adc5_channel_prop {
5656
* requests from multiple clients.
5757
* @data: software configuration data.
5858
* @n_tm_channels: number of ADC channels used for TM measurements.
59-
* @handler: TM callback to be called for threshold violation interrupt
60-
* on first SDAM.
61-
* @tm_aux: pointer to auxiliary TM device.
6259
*/
6360
struct adc5_chip {
6461
struct device *dev;
@@ -70,8 +67,6 @@ struct adc5_chip {
7067
struct mutex lock;
7168
const struct adc5_data *data;
7269
unsigned int n_tm_channels;
73-
void (*handler)(struct auxiliary_device *tm_aux);
74-
struct auxiliary_device *tm_aux;
7570
};
7671

7772
int adc5_gen3_read(struct adc5_device_data *adc, unsigned int sdam_index,
@@ -287,23 +282,21 @@ static irqreturn_t adc5_gen3_isr(int irq, void *dev_id)
287282
{
288283
struct adc5_chip *adc = dev_id;
289284
struct device *dev = adc->dev;
290-
struct auxiliary_device *adev;
291285
u8 status, eoc_status, val;
292-
u8 tm_status[2];
293286
int ret;
294287

295288
ret = adc5_gen3_read(&adc->dev_data, ADC5_GEN3_VADC_SDAM,
296289
ADC5_GEN3_STATUS1, &status, sizeof(status));
297290
if (ret) {
298291
dev_err(dev, "adc read status1 failed with %d\n", ret);
299-
return IRQ_HANDLED;
292+
return IRQ_NONE;
300293
}
301294

302295
ret = adc5_gen3_read(&adc->dev_data, ADC5_GEN3_VADC_SDAM,
303296
ADC5_GEN3_EOC_STS, &eoc_status, sizeof(eoc_status));
304297
if (ret) {
305298
dev_err(dev, "adc read eoc status failed with %d\n", ret);
306-
return IRQ_HANDLED;
299+
return IRQ_NONE;
307300
}
308301

309302
if (status & ADC5_GEN3_STATUS1_CONV_FAULT) {
@@ -316,30 +309,13 @@ static irqreturn_t adc5_gen3_isr(int irq, void *dev_id)
316309
return IRQ_HANDLED;
317310
}
318311

319-
/* CHAN0 is the preconfigured channel for immediate conversion */
320-
if (eoc_status & ADC5_GEN3_EOC_CHAN_0)
321-
complete(&adc->complete);
322-
323-
ret = adc5_gen3_read(&adc->dev_data, ADC5_GEN3_VADC_SDAM,
324-
ADC5_GEN3_TM_HIGH_STS, tm_status, sizeof(tm_status));
325-
if (ret) {
326-
dev_err(dev, "adc read TM status failed with %d\n", ret);
327-
return IRQ_HANDLED;
328-
}
329-
330-
dev_dbg(dev, "Interrupt status:%#x, EOC status:%#x, high:%#x, low:%#x\n",
331-
status, eoc_status, tm_status[0], tm_status[1]);
312+
dev_dbg(dev, "Interrupt status:%#x, EOC status:%#x\n", status, eoc_status);
332313

333-
if (tm_status[0] || tm_status[1]) {
334-
adev = adc->tm_aux;
335-
if (!adev || !adev->dev.driver) {
336-
dev_err(dev, "adc_tm auxiliary device not initialized\n");
337-
return IRQ_HANDLED;
338-
}
339-
340-
adc->handler(adev);
341-
}
314+
/* CHAN0 is the preconfigured channel for immediate conversion */
315+
if (!(eoc_status & ADC5_GEN3_EOC_CHAN_0))
316+
return IRQ_NONE;
342317

318+
complete(&adc->complete);
343319
return IRQ_HANDLED;
344320
}
345321

@@ -684,8 +660,6 @@ static int adc5_gen3_add_aux_tm_device(struct adc5_chip *adc)
684660
if (ret)
685661
return ret;
686662

687-
adc->tm_aux = &aux_device->aux_dev;
688-
689663
return 0;
690664
}
691665

@@ -741,16 +715,6 @@ int adc5_gen3_therm_code_to_temp(struct device *dev,
741715
}
742716
EXPORT_SYMBOL_NS_GPL(adc5_gen3_therm_code_to_temp, "QCOM_SPMI_ADC5_GEN3");
743717

744-
void adc5_gen3_register_tm_event_notifier(struct device *dev,
745-
void (*handler)(struct auxiliary_device *))
746-
{
747-
struct iio_dev *indio_dev = dev_get_drvdata(dev->parent);
748-
struct adc5_chip *adc = iio_priv(indio_dev);
749-
750-
adc->handler = handler;
751-
}
752-
EXPORT_SYMBOL_NS_GPL(adc5_gen3_register_tm_event_notifier, "QCOM_SPMI_ADC5_GEN3");
753-
754718
static int adc5_gen3_probe(struct platform_device *pdev)
755719
{
756720
struct device *dev = &pdev->dev;
@@ -817,10 +781,18 @@ static int adc5_gen3_probe(struct platform_device *pdev)
817781
return -ENOMEM;
818782
}
819783

820-
ret = devm_request_irq(dev, adc->dev_data.base[ADC5_GEN3_VADC_SDAM].irq,
821-
adc5_gen3_isr, 0,
822-
adc->dev_data.base[ADC5_GEN3_VADC_SDAM].irq_name,
823-
adc);
784+
/*
785+
* This interrupt is shared with the ADC_TM auxiliary driver, which
786+
* is threaded and uses IRQF_ONESHOT. Since shared interrupts need
787+
* to agree on IRQF_ONESHOT configuration and there is a kernel
788+
* warning for using IRQF_ONESHOT with non-threaded interrupts,
789+
* make this also a threaded IRQ.
790+
*/
791+
792+
ret = devm_request_threaded_irq(dev, adc->dev_data.base[ADC5_GEN3_VADC_SDAM].irq,
793+
NULL, adc5_gen3_isr, IRQF_ONESHOT | IRQF_SHARED,
794+
adc->dev_data.base[ADC5_GEN3_VADC_SDAM].irq_name,
795+
adc);
824796
if (ret)
825797
return dev_err_probe(dev, ret,
826798
"Failed to request SDAM%d irq\n",

include/linux/iio/adc/qcom-adc5-gen3-common.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,5 @@ int adc5_gen3_get_scaled_reading(struct device *dev,
205205
int adc5_gen3_therm_code_to_temp(struct device *dev,
206206
struct adc5_channel_common_prop *common_props,
207207
u16 code, int *val);
208-
void adc5_gen3_register_tm_event_notifier(struct device *dev,
209-
void (*handler)(struct auxiliary_device *));
210208

211209
#endif /* QCOM_ADC5_GEN3_COMMON_H */

0 commit comments

Comments
 (0)