Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: trigger: allow devices to suspend/resume theirs associated trigger

When a machine enters a sleep state while a trigger is associated to
an iio device that trigger is not resumed after exiting the sleep state:
provide iio device drivers a way to suspend and resume
the associated trigger to solve the aforementioned bug.

Each iio driver supporting external triggers is expected to call
iio_device_suspend_triggering before suspending,
and iio_device_resume_triggering upon resuming.

Signed-off-by: Denis Benato <benato.denis96@gmail.com>
Link: https://patch.msgid.link/20240807185619.7261-2-benato.denis96@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Denis Benato and committed by
Jonathan Cameron
2837efdc b4b4817b

+44
+27
drivers/iio/industrialio-trigger.c
··· 347 347 iio_trigger_put_irq(trig, pf->irq); 348 348 free_irq(pf->irq, pf); 349 349 module_put(iio_dev_opaque->driver_module); 350 + pf->irq = 0; 350 351 351 352 return ret; 352 353 } ··· 771 770 if (indio_dev->trig) 772 771 iio_trigger_put(indio_dev->trig); 773 772 } 773 + 774 + int iio_device_suspend_triggering(struct iio_dev *indio_dev) 775 + { 776 + struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); 777 + 778 + guard(mutex)(&iio_dev_opaque->mlock); 779 + 780 + if ((indio_dev->pollfunc) && (indio_dev->pollfunc->irq > 0)) 781 + disable_irq(indio_dev->pollfunc->irq); 782 + 783 + return 0; 784 + } 785 + EXPORT_SYMBOL(iio_device_suspend_triggering); 786 + 787 + int iio_device_resume_triggering(struct iio_dev *indio_dev) 788 + { 789 + struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); 790 + 791 + guard(mutex)(&iio_dev_opaque->mlock); 792 + 793 + if ((indio_dev->pollfunc) && (indio_dev->pollfunc->irq > 0)) 794 + enable_irq(indio_dev->pollfunc->irq); 795 + 796 + return 0; 797 + } 798 + EXPORT_SYMBOL(iio_device_resume_triggering);
+17
include/linux/iio/iio.h
··· 810 810 } 811 811 #endif 812 812 813 + /** 814 + * iio_device_suspend_triggering() - suspend trigger attached to an iio_dev 815 + * @indio_dev: iio_dev associated with the device that will have triggers suspended 816 + * 817 + * Return 0 if successful, negative otherwise 818 + **/ 819 + int iio_device_suspend_triggering(struct iio_dev *indio_dev); 820 + 821 + /** 822 + * iio_device_resume_triggering() - resume trigger attached to an iio_dev 823 + * that was previously suspended with iio_device_suspend_triggering() 824 + * @indio_dev: iio_dev associated with the device that will have triggers resumed 825 + * 826 + * Return 0 if successful, negative otherwise 827 + **/ 828 + int iio_device_resume_triggering(struct iio_dev *indio_dev); 829 + 813 830 #ifdef CONFIG_ACPI 814 831 bool iio_read_acpi_mount_matrix(struct device *dev, 815 832 struct iio_mount_matrix *orientation,