From patchwork Wed Aug 7 18:56:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Benato X-Patchwork-Id: 13756636 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (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 D34331422DD; Wed, 7 Aug 2024 18:56:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723056997; cv=none; b=V5J0R3WjVBoJBUzXuB/FFbyQryHKdc5rLkXCM/oT00Ze4m7V5erGIHUAlbG1hsY9hjkKfq2oWSLN+ikjgN+4jF6Ezdghhy1/rXz2QAaxIFP2GIw5rmjVG94PolpYhYR61a5ktwF/9VANJXyLgXXcZfFlAYH7G32X3q2tjxLHNAI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723056997; c=relaxed/simple; bh=Xl0XNH6P8xVYikz4LRhMTvCzbnm4U8FecR5gPlsQ2vg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QECFqlJk0YvFbOEqd6od2Xs4aXpsDJ+u9ld3XHxR1eZBTrGU9oajjd3oQ2688w7KshfNmBb2QpACu5NNi+qhOFjrSFwIfE1r+BN2eQBPp9NVIwhPJT2/cdLeX8n3hpFFN39N/KSK1X4FR25mDmzeks74pCEr8aCyfiuglG1g4iU= 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=ga6O7jan; arc=none smtp.client-ip=209.85.167.45 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="ga6O7jan" Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-530e22878cfso120079e87.2; Wed, 07 Aug 2024 11:56:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723056994; x=1723661794; 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=I8FeMbjLUWFRJmxjbVI7sz0MVMw/j8BJ1tQjl57/nuQ=; b=ga6O7janw4yPEEL9hOvoOdOhdHUojSpMOXHVz7IZ1A5H7pRs2HcVDDhaiE7bZr2mqk OIiEfXJXDV/dB/TD+MyfaJufv/+c0RrDgWnHHaBkKd5KNjnleuASG/Iwom5myQEcJqh+ e1gW6oGCePEgffp0NDXS/xBGJY+3QQ/f4kyTsyjd3j/6xHPNWMf77ZYDea2O+3R9++Xf UvH/55MiGg9hhmGAHr58btLiJXX/gnrdWTxiYu/p6nSdWpqrjmHAv14lLiWVpwQxfJNx ye/Vdm0rN5wCbu/kccLO2Y6rB9dRN3ASZkGFjsxw0O3JyRNmL4rI7oD1Bm6S1lvLPVLv UGNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723056994; x=1723661794; 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=I8FeMbjLUWFRJmxjbVI7sz0MVMw/j8BJ1tQjl57/nuQ=; b=IjUWBxiIHaLfA6naX3bJY5WHL6BUtkh9m6I4RJ0tsQtoALKJGAlccu7OMHCNEO+iBs Qm+gmZmNzGQhOdoztzXqA2ZCRzuRtQuDHogrfTZcLVuPJPsbDZR0VpmEVCMr61zVzI7C 3xqhp62MVJoXbl6aWO4+2xAB+LmSnQ0MAge6AtbaWOweBbYnjBqZtxfH8rURAwMQ1X2v J/lSRlheyZREzbrnMLHpH3t2VtfZHOn9KNRL6FY0qnU0/q+mt9j72rIXW4RuZmZDdmZN I5kNMtbnovQwej6MoX4HHjGTzzzWCDQxVcg/W5tPXWhyX7b+ykY0DqyMdvPSUesGV1bj NE6Q== X-Forwarded-Encrypted: i=1; AJvYcCWtuWSsM1S5htB+/+4RpjqAxZ1Ju/9/kzp0m2v+YjsD0vkvpe4+U6wpfZkRcaAi+6RjBKVF/rWDWlL4l43skKal13e+IlWiXhbfL2arxn/slhxRBXykYP3tmCToRYpSD6wFlqNdVlN5 X-Gm-Message-State: AOJu0YzPHNEdrEUrRxeYkeNiEmkArzHkShF2ZDReJXs/rN3WVomt6gND TTwiUoWH/W9wBcnIAJJFeofgQUgClPpDaj/c373sUmvxF443lAMQ X-Google-Smtp-Source: AGHT+IHXMiDEkYJmCtdL3jvSpvOWsC5iylXuVF5Mc7yRRcr1uljgelESNO/weCNyWt8Tti3Hkw799w== X-Received: by 2002:a05:6512:118a:b0:52c:dc57:868b with SMTP id 2adb3069b0e04-530bb3b150cmr13185067e87.13.1723056993491; Wed, 07 Aug 2024 11:56:33 -0700 (PDT) Received: from localhost.localdomain ([151.49.208.23]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5ba51da9c41sm5482270a12.36.2024.08.07.11.56.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Aug 2024 11:56:33 -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 v3 1/2] iio: trigger: allow devices to suspend/resume theirs associated trigger Date: Wed, 7 Aug 2024 20:56:18 +0200 Message-ID: <20240807185619.7261-2-benato.denis96@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240807185619.7261-1-benato.denis96@gmail.com> References: <20240807185619.7261-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 | 27 +++++++++++++++++++++++++++ include/linux/iio/iio.h | 17 +++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c index 2e84776f4fbd..54416a384232 100644 --- a/drivers/iio/industrialio-trigger.c +++ b/drivers/iio/industrialio-trigger.c @@ -347,6 +347,7 @@ int iio_trigger_detach_poll_func(struct iio_trigger *trig, iio_trigger_put_irq(trig, pf->irq); free_irq(pf->irq, pf); module_put(iio_dev_opaque->driver_module); + pf->irq = 0; return ret; } @@ -770,3 +771,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 f6c0499853bb..c66c784d31e4 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 Wed Aug 7 18:56:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Benato X-Patchwork-Id: 13756637 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.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 DDD21143891; Wed, 7 Aug 2024 18:56:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723057001; cv=none; b=KtnnD96jG5+uOxWyHv7swKCrDLUuH1rij/bJ4RVdTmmF+wc294SO+nS3kJzNsnMSwfuhxzLDPwpsuluRM7mV+G5drnw0K77qeqH+aY4Sk6eMItL++xO8y6+UB3qRbdSlDmlJVLhW2hzN6dGoFf5o4t7ueTDoiLRcVDtVYgZXP8E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723057001; c=relaxed/simple; bh=+F0WyewUnXT3w09NXRtI/LrPLq7JvuykbRUqBvCNccQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qpvpVMluDU6x1gO/r+3TgwWP5oc6xE9CbejHymmNKz9hFgOyr7x3cpqReu4E17+51OO87QYltwbsfsP0zz9r7pmBeCOwZ3Az7mWnZ+7XF7BK9V8ql1fmcR3WQQQAnUGT37h65o09FDxodve3Hcn7e6e8TXBKP5zDp0W8e8Eai5c= 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=dvH6apEM; arc=none smtp.client-ip=209.85.208.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="dvH6apEM" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-5b3fff87e6bso134244a12.0; Wed, 07 Aug 2024 11:56:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723056998; x=1723661798; 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=NBRg56Ji8N26DNOeCY4BDLeRmt9MaxXXPicaugfdq7A=; b=dvH6apEMR2C7ZofT6GqdmxI9gzNpI7aWm+BEtQA5+f0gQV+0lm9Mii73RzvLP6KicQ ybNS1cbIb8WQVr1XcXq6Ec028RvqXjAYoZZtOnvHsi13mLsBP+zVthxVY/QqO94PoKWZ CjALbiOGSH8164DhIzXytQ9thWdC1KJIY8ySNqiic3DiGpyhz6T/04bXNc37vIKSIGzH CgopRuV2AHUFAA8xlp0Npe4EUYRclU7/IQwcp42OYWBISowcLFrvjGaucPnDP11xRtfF 25eWHi2xLmTMNbmndCS712T19cWFJ7JNsVS6snQ4ygm2da1N+rja6KVCLe7hfKS8mAug b/Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723056998; x=1723661798; 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=NBRg56Ji8N26DNOeCY4BDLeRmt9MaxXXPicaugfdq7A=; b=eNVakvlGAPHP0MvOGsGiQVgCN19D91NmjMk2FVcJL52jPUCQOsY51QdLtU9ixEANki zDfVncc6uhJVLNeVk7yoveXfwxoB72g6OxB8oqiMK+G7B6w05OAWnWnLxLB1Zu7vxwf3 /zavSAU/0oppNyo/xk/re7B2HFE5EG5BvXYUAou3iws3hmWHR1+hfjTcPl9YFMcAoi0i p3jNwtQAt2AEJE0l38zpn715Z8NMEjT0jASRligEexxFdxwEVFWV0pxPQ2YBLu7fF3iB Qdf24T2b06lEBoWmLNwuLxhr+g51288Xe5jBP0sMjyMD0lAcD53Hqd7ZWqv3y5hkv8AX R3gg== X-Forwarded-Encrypted: i=1; AJvYcCWoCw3Qzi2tRTyvgR5e3vTqLHCjPZ+XK/h/P+TcrrM2FDMzrkwKhyULNLZKyhBoe1UNYX0Jl/UHkfK1tvT3vvbJOgfGLV4yMzzq9pqxLNATWOyfy+coLMgBEtd5AFvTa6DMaJWeJ88W X-Gm-Message-State: AOJu0YzH7HmZ0PnECtr31eI0tPl38t5PV3jjm64DsiAV7w+EX9Zsplmu DnIPgb5OCl1LWtHS04oXmuIodpbqqW0jUqnjOuSiP94gZbAwmEYQ X-Google-Smtp-Source: AGHT+IFJwH9jY0f24gTaNavYSe9oAVD+14UOMj/NbGzr/8u5IBuA0yozlZuC4OJNQJfkfpUkF/WkcQ== X-Received: by 2002:aa7:df97:0:b0:5a2:ff64:1218 with SMTP id 4fb4d7f45d1cf-5b7f0dd33bdmr13490495a12.0.1723056998020; Wed, 07 Aug 2024 11:56:38 -0700 (PDT) Received: from localhost.localdomain ([151.49.208.23]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5ba51da9c41sm5482270a12.36.2024.08.07.11.56.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Aug 2024 11:56:37 -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 v3 2/2] iio: bmi323: suspend and resume triggering on relevant pm operations Date: Wed, 7 Aug 2024 20:56:19 +0200 Message-ID: <20240807185619.7261-3-benato.denis96@gmail.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240807185619.7261-1-benato.denis96@gmail.com> References: <20240807185619.7261-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 3298e027c97e..0ba5d69d8329 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 571e1cd7ce72..9de3ade78d71 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,