From patchwork Sat Jul 27 12:30:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Benato X-Patchwork-Id: 13743727 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5AB880034; Sat, 27 Jul 2024 12:31:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722083462; cv=none; b=eQjVPFz+1MDlFCth1FKdajeWAVz1gVw7PXhkVN60aL7/oQHkEq0jTSi5fZxbXCWmJex1q41eAgvH5tJx0eSlmrL5DIcjSNcCcRoYKQA5DWl5CDuSIFipvjJKsy37PnpIzqz3zHGmH6qRfQeYZLxt8+1OHrzN+CmQG4hUDG6THpg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722083462; c=relaxed/simple; bh=xAwBVFQH8e7up7GuYAZk9EruzSQd6n3+Gr1ceCR/51E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XTONjNO2k0Q7V0YjVHXowJTdnp+6Q3JXmAw+1eXokcT1iWX/ON7UrgPDW9nh5hbBW85nPj9w3mwZkcSGGITryo4Nine6nidXg7f1twjPA2NL2L+CmQnU/f9MSt1XQkUo2GjhDj9vS17rc48/QqSbjWXAlDDgi4hi5gYDIBR4rK0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lXfzCEy0; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lXfzCEy0" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4280bca3960so4018125e9.3; Sat, 27 Jul 2024 05:31:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722083459; x=1722688259; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1yxi8euCEWjpLf30egLarY0olD/MdHwC3K0RnPeARFg=; b=lXfzCEy0q2geTDy2YwawVYsvW5YTkwFPHkA/8HMBlMvaCYwST5e2iINsB5E6tfEEDC cD6EMDd8At+//U9bx+K3mW6lWmJrObJSimVDCbQ1KvOAp6A0lPteLDiXSWGxXU6Ove+X +h3Cdam4+1mR0BujI8NBkoOBrGTscdn7bsoKLd49mH1xSQbUfmBbWH+N0Ly6cjujIrSi lNcqJK0TIaBw9vZfYR4Xj465Ft4rD0PhJm5c5faBta5ZHvE+Jgt7vKaCyDetZ6lb+ssl z3Z5I47FjHlNtgmWtdV9qC15sO1rcXdOwOw5/zj/g0E1Doz1MUoPGiKxFwqnTDp9sHzz KU0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722083459; x=1722688259; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1yxi8euCEWjpLf30egLarY0olD/MdHwC3K0RnPeARFg=; b=NvIkTefwPViT1r6eiWxJK/+BxWlOEetc0O0+lqoM161bUlZYi2kHbpF4gPqFLmwDNH SrIRUBgM3RQc3N/gAmCTF6Dhmtjg7Ng4SL3SVzPFSNOS1UpPiqa2GqtuWV6CCp4+e07C /rPR7t/uwX2NNzxQo7dKYPySKm270uwCyaPoSgLFs3YoNadgTWqZt/RI9HtBVaDB+p/3 3Fa57JWrssOr8imPINa88xtgAP8xXr3yR3Xax4Od7f38LkXtJyxiwEjpKXYp0j8aAqnv c715IH0/8Pbo5zBybtM7v7XCO8WqVfdQvrwozIuDYfozQMUDv8jU9LbKkHAcqFKQ8F8O C+kg== X-Forwarded-Encrypted: i=1; AJvYcCWApXbYGpT/YAXRBIcODGwH9qT3C8ZQJQhTLEcsHJgf7P3WExRcYZHDg4x7p9wJBeLo8crK2G/V0/lQ7p07h4lls85s2/aZL/ceotddjLxA6rdNyqNeEOqRoMU3OXUWTq8OXctYPPWA X-Gm-Message-State: AOJu0YztL1nboP1PjAXGigxEImtlvaTt1zqGeQ9vTOV7GREDFL7PuZY/ boWFY+MbssIvHXw7O9afUONqIceaUXlrBU3tC8MFVeD32RGwcfzN X-Google-Smtp-Source: AGHT+IEGnr1xJZ+KYcBxak1Z1KruyWJkuGviM2Au54R7HVVS4+fJerANjY8EBFWVIEW6/Q6ueOr0nA== X-Received: by 2002:a05:600c:5492:b0:426:5b3a:96c with SMTP id 5b1f17b1804b1-42811dcd245mr13661565e9.28.1722083458814; Sat, 27 Jul 2024 05:30:58 -0700 (PDT) Received: from localhost.localdomain ([176.206.92.195]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-428057a6368sm114913215e9.38.2024.07.27.05.30.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Jul 2024 05:30:58 -0700 (PDT) From: Denis Benato To: Jonathan Cameron Cc: Lars-Peter Clausen , Jagath Jog J , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Denis Benato , "Luke D . Jones" , Jonathan LoBue Subject: [PATCH v2 1/2] iio: trigger: allow devices to suspend/resume theirs associated trigger Date: Sat, 27 Jul 2024 14:30:33 +0200 Message-ID: <20240727123034.5541-2-benato.denis96@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240727123034.5541-1-benato.denis96@gmail.com> References: <20240727123034.5541-1-benato.denis96@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- drivers/iio/industrialio-trigger.c | 26 ++++++++++++++++++++++++++ include/linux/iio/iio.h | 17 +++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c index 2e84776f4fbd..2e92283fad0f 100644 --- a/drivers/iio/industrialio-trigger.c +++ b/drivers/iio/industrialio-trigger.c @@ -770,3 +770,29 @@ void iio_device_unregister_trigger_consumer(struct iio_dev *indio_dev) if (indio_dev->trig) iio_trigger_put(indio_dev->trig); } + +int iio_device_suspend_triggering(struct iio_dev *indio_dev) +{ + struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); + + guard(mutex)(&iio_dev_opaque->mlock); + + if ((indio_dev->pollfunc) && (indio_dev->pollfunc->irq > 0)) + disable_irq(indio_dev->pollfunc->irq); + + return 0; +} +EXPORT_SYMBOL(iio_device_suspend_triggering); + +int iio_device_resume_triggering(struct iio_dev *indio_dev) +{ + struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); + + guard(mutex)(&iio_dev_opaque->mlock); + + if ((indio_dev->pollfunc) && (indio_dev->pollfunc->irq > 0)) + enable_irq(indio_dev->pollfunc->irq); + + return 0; +} +EXPORT_SYMBOL(iio_device_resume_triggering); diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h index 894309294182..c87dfda54681 100644 --- a/include/linux/iio/iio.h +++ b/include/linux/iio/iio.h @@ -810,6 +810,23 @@ static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev) } #endif +/** + * iio_device_suspend_triggering() - suspend trigger attached to an iio_dev + * @indio_dev: iio_dev associated with the device that will have triggers suspended + * + * Return 0 if successful, negative otherwise + **/ +int iio_device_suspend_triggering(struct iio_dev *indio_dev); + +/** + * iio_device_resume_triggering() - resume trigger attached to an iio_dev + * that was previously suspended with iio_device_suspend_triggering() + * @indio_dev: iio_dev associated with the device that will have triggers resumed + * + * Return 0 if successful, negative otherwise + **/ +int iio_device_resume_triggering(struct iio_dev *indio_dev); + #ifdef CONFIG_ACPI bool iio_read_acpi_mount_matrix(struct device *dev, struct iio_mount_matrix *orientation, From patchwork Sat Jul 27 12:30:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Benato X-Patchwork-Id: 13743728 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A0688062A; Sat, 27 Jul 2024 12:31:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722083463; cv=none; b=QJH1Agjw1fT2ENrbYYTkbHyBDcqiw+EX6nWwO9CsHr+IJnqDlN0zsg+7BZqfrY9YD1nAqeivVd/YGGW4PPbuxxfJe5hRRHlFMpVntM6S2XSa1w6xePe6mg9B1SgmkAnTv6AuZ5ybFj1yWDdbyyv1b8T3u8aND7oFoh291HNo/B0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722083463; c=relaxed/simple; bh=yLUM8AXqlF1x4Tyxs2XWbhqMlveOggFhgxkLX0meD+g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mMx2pH8vv88Eg4MeeYPIG2aquINfwwMLQzVJYrVP3nF2ySdnrfPC/fjX/BoPMI/vsAPMxUMkkgyq4RVqUfR1D+MDAGMMnZHEOVl5RFUmb9YGqTaSNUmUIQjB92NyB7adCKs9MSTS767tBNjrJAPNWqZLteTLEX2Dz/JRoB/mpcI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Q8gBJkfv; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Q8gBJkfv" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4257d5fc9b7so5319085e9.2; Sat, 27 Jul 2024 05:31:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722083460; x=1722688260; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=d+OBHIG3D8KPMwZH7IuhBbwzoU/QaG9OLelyWCTryvA=; b=Q8gBJkfvUkurxS+8xCc7J9l9gUncakxZIAo6TysQwB1Q/IToQaA4yemm1KrDb4/cpx 1ukRbFaPNzghXzE3CkMEcL0kzNaEWbOhM+PLjVdIWhiJkC3lW9zfcqq/vygJ4yqM9zJ5 sVzQrS+erMhRfNZ+6/zvLn38kshuWYfTfMwoUH8hakzXjqH6tPcD77obE622QhgXFAxp VAuq7ktu2LJzqvWpwsQ/noGY2hlZ3Rm0M5lvuutOquvEC3asQ1AJChOZWR/Rn3yHl7xh tdBi1TlgiHbeOYL5tKprbekklCq9m/94Z4/oFlYcTK44u9geB3bZthYhKJlGx41qUAXM RbnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722083460; x=1722688260; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=d+OBHIG3D8KPMwZH7IuhBbwzoU/QaG9OLelyWCTryvA=; b=fFrZLPTziHFsE1ifBH/X/r4mv41FC288Qi5bTdE9YkdNkjHtVBS8jVY5x4lhJzdYjB m1hfE+UZQCnBRh/LuCEH3eVpOI60R3Lm2l1sK2eVxH/LNzDRDewdgOfab7ic8UN9rTxW JwPH+IMbuQ3impqH/KWG6F1SdlLqVKdFrm7f8HVBvQ4ODgnkKMrSj/NnMp/KlLONplWL FlJVM6EwJcjip+VFtyiSDhrPDKzybJtqbE0CuoOO1Dp8gZk84gcAQ5NCBuLWvv/JKIWG G8Z0BeB63NrQvIZ1oJBZN54aIJxaDksUYHsXGtmA4Z5yum8JAq6M2J4FO0UcQruREgZ0 1VKA== X-Forwarded-Encrypted: i=1; AJvYcCUMSGcZ3fO6SmhD4fq1Oi/KZuF3sbI16JCVw3ceeIsczBx6kdk5LQP3Nwj8WcfeNgKsR76ZFdZX2ZNmt6wz+5K7GE9J5L28Kr3qg/Bfu/6j8ILio6VReeWcihiI+mqI3sSjDUdX0yQr X-Gm-Message-State: AOJu0Yzbk8ITW4Ty7erE9p+O9ZUnhE3oP6UC6n3ssjqXy2yFeqnyNXa9 lhycGjIEp8DRfQm0P8Ya93VGMiOEM4t5z/+Jy8Foz6aD/0z6r7IO X-Google-Smtp-Source: AGHT+IEEI8+Shh3rxg3Mp87iw84iJ065h6GF2sXmUFhxAHfriaFy7KjKI13ONAzzGnir82E7yGV+JA== X-Received: by 2002:a05:600c:138f:b0:426:5b44:2be7 with SMTP id 5b1f17b1804b1-42811d8bb34mr20090225e9.10.1722083460544; Sat, 27 Jul 2024 05:31:00 -0700 (PDT) Received: from localhost.localdomain ([176.206.92.195]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-428057a6368sm114913215e9.38.2024.07.27.05.30.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Jul 2024 05:31:00 -0700 (PDT) From: Denis Benato To: Jonathan Cameron Cc: Lars-Peter Clausen , Jagath Jog J , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Denis Benato , "Luke D . Jones" , Jonathan LoBue Subject: [PATCH v2 2/2] iio: bmi323: suspend and resume triggering on relevant pm operations Date: Sat, 27 Jul 2024 14:30:34 +0200 Message-ID: <20240727123034.5541-3-benato.denis96@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240727123034.5541-1-benato.denis96@gmail.com> References: <20240727123034.5541-1-benato.denis96@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Prevent triggers from stop working after the device has entered sleep: use iio_device_suspend_triggering and iio_device_resume_triggering helpers. Signed-off-by: Denis Benato --- drivers/iio/imu/bmi323/bmi323.h | 1 + drivers/iio/imu/bmi323/bmi323_core.c | 23 +++++++++++++++++++++++ drivers/iio/imu/bmi323/bmi323_i2c.c | 1 + drivers/iio/imu/bmi323/bmi323_spi.c | 1 + 4 files changed, 26 insertions(+) diff --git a/drivers/iio/imu/bmi323/bmi323.h b/drivers/iio/imu/bmi323/bmi323.h index dff126d41658..209bccb1f335 100644 --- a/drivers/iio/imu/bmi323/bmi323.h +++ b/drivers/iio/imu/bmi323/bmi323.h @@ -205,5 +205,6 @@ struct device; int bmi323_core_probe(struct device *dev); extern const struct regmap_config bmi323_regmap_config; +extern const struct dev_pm_ops bmi323_core_pm_ops; #endif diff --git a/drivers/iio/imu/bmi323/bmi323_core.c b/drivers/iio/imu/bmi323/bmi323_core.c index d708d1fe3e42..4b2b211a3e88 100644 --- a/drivers/iio/imu/bmi323/bmi323_core.c +++ b/drivers/iio/imu/bmi323/bmi323_core.c @@ -2121,6 +2121,29 @@ int bmi323_core_probe(struct device *dev) } EXPORT_SYMBOL_NS_GPL(bmi323_core_probe, IIO_BMI323); +#if defined(CONFIG_PM) +static int bmi323_core_runtime_suspend(struct device *dev) +{ + struct iio_dev *indio_dev = dev_get_drvdata(dev); + + return iio_device_suspend_triggering(indio_dev); +} + +static int bmi323_core_runtime_resume(struct device *dev) +{ + struct iio_dev *indio_dev = dev_get_drvdata(dev); + + return iio_device_resume_triggering(indio_dev); +} + +#endif + +const struct dev_pm_ops bmi323_core_pm_ops = { + SET_RUNTIME_PM_OPS(bmi323_core_runtime_suspend, + bmi323_core_runtime_resume, NULL) +}; +EXPORT_SYMBOL_NS_GPL(bmi323_core_pm_ops, IIO_BMI323); + MODULE_DESCRIPTION("Bosch BMI323 IMU driver"); MODULE_AUTHOR("Jagath Jog J "); MODULE_LICENSE("GPL"); diff --git a/drivers/iio/imu/bmi323/bmi323_i2c.c b/drivers/iio/imu/bmi323/bmi323_i2c.c index 52140bf05765..057342f4f816 100644 --- a/drivers/iio/imu/bmi323/bmi323_i2c.c +++ b/drivers/iio/imu/bmi323/bmi323_i2c.c @@ -128,6 +128,7 @@ MODULE_DEVICE_TABLE(of, bmi323_of_i2c_match); static struct i2c_driver bmi323_i2c_driver = { .driver = { .name = "bmi323", + .pm = pm_ptr(&bmi323_core_pm_ops), .of_match_table = bmi323_of_i2c_match, .acpi_match_table = bmi323_acpi_match, }, diff --git a/drivers/iio/imu/bmi323/bmi323_spi.c b/drivers/iio/imu/bmi323/bmi323_spi.c index 7b1e8127d0dd..487d4ee05246 100644 --- a/drivers/iio/imu/bmi323/bmi323_spi.c +++ b/drivers/iio/imu/bmi323/bmi323_spi.c @@ -79,6 +79,7 @@ MODULE_DEVICE_TABLE(of, bmi323_of_spi_match); static struct spi_driver bmi323_spi_driver = { .driver = { .name = "bmi323", + .pm = pm_ptr(&bmi323_core_pm_ops), .of_match_table = bmi323_of_spi_match, }, .probe = bmi323_spi_probe,