From patchwork Thu Jul 25 00:26:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Benato X-Patchwork-Id: 13741476 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 E632563D0; Thu, 25 Jul 2024 00:27:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721867250; cv=none; b=i2T2aKx2JyLyGg38PUvvOuniZkFA6WE67aQ3CDsQqf5x37BnbGcZgiiB+IJM9j9nXO19ewD8uu1N+FbqZBzHkJRtqd3jcbGb0CMgIurGqE4tNUXUBzlSuEJ5erNkK+u3VqWA0UhTXJnW9BpieRTTogsJgRvPvpnDBwV/D31/TdI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721867250; c=relaxed/simple; bh=xAwBVFQH8e7up7GuYAZk9EruzSQd6n3+Gr1ceCR/51E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CseDmj+vWkw9PT6tCGfeFoviHPiTunjinE6Qbgbu9s8wrn4ETwnf/CEfDlZjy23GFfnJ7MUjG6KqFWIxT+fflyxLqLDOEgcU4yXKu99o/iVcO0RZWKIHZqe8J6o+jkv0Q+zfYlyVUABu5NCU62CetQjQKI8umAyAIN7DogviNRE= 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=ad3H2iLG; arc=none smtp.client-ip=209.85.128.46 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="ad3H2iLG" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4266f344091so2352045e9.0; Wed, 24 Jul 2024 17:27:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721867247; x=1722472047; 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=ad3H2iLGZCMBjtsESA5iIohYRklMsGHwSS+qYvyRDoMxJAjWKDwacRiQGjEZ4MvouP hIEJ9D7X/AnPEWJmDOjrQ8IX/ORe+h6tZ6WHlowbnxamINhTxVYeKge7S6zlfbSKAEuw B/+SdNVZ/jV0giNTIvwDKgsT67l2KFQMXoCUcwSMEL1pqCSw6smud0MFJp+fk5cPl1ci MRotRKEQ+HERHZYuTqyM+m9BLcRluzf4dUiJR+Y0KGVzfKOQDp7DWcaRT9Eej8EPhlV1 WnnTv8AQx4O2uvZplw+3cOUMeILADK6SmjnUIKlVcuOsQ9Vx8DiXXRyAPSdMRWb13il9 lMfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721867247; x=1722472047; 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=CLNoIJx6IcJisuW9vg3k84bDvVivFZN+kp6EGiF/DVJkbaB9ZV5uROMXINSuGrTfl8 +re88gx29/A4s4U4HM0hL3e5hi2hKaxTz/XnxKxhk4kGk9CfyWF5rGleuA9twIW5qNIy 1pGZaulfZ9lDZ+p49wHmFAIlX0QHhPn8x8+TICF3YwncdNvE8/VGgK/+t3HLN4BPT1DY HaDBGgiBR4GH2GYUjRxmDuL6XYhd84nEezKKuynsY5dTqMND8+Bd81Zp+mz0eFLk2EWJ OeCJpghWxS1eXieo9nrPTeyKV0MesjHoxmOupRRxfjbYXCvHDzADLeHv+ctPECz1qTGq sNWw== X-Forwarded-Encrypted: i=1; AJvYcCWoOaBcE1aUL8oWh+tAUYCzVJwZgDIb2fY0z70t8hFYbu4cGTceeyBGgtgSBad0GMSxV3AsJ88JqiLifBEw6UszXFojvIirlghp+GUk6TLRtJOlJMNa/DwVzmUoE1KjVJ2i9w9FuZcn X-Gm-Message-State: AOJu0YwVg1fdssQwFxfJwYdGb96hkYx4KNEoOgsMxsrtMRKqPBeKmJk0 S0WbG6txcddCWZzRZUAznJ1xw0SquLficc9++9L0kPJqtdvo3OGc X-Google-Smtp-Source: AGHT+IF+G00j39Vy33dYOGjD04m+c1z+Ee1YT6dehvKjdvNSWao0oCNuMGItaf4LqjFKcZVmzL1MZw== X-Received: by 2002:a05:600c:3b21:b0:424:ad14:6b79 with SMTP id 5b1f17b1804b1-42806b5c0b8mr1980455e9.8.1721867247126; Wed, 24 Jul 2024 17:27:27 -0700 (PDT) Received: from localhost.localdomain ([151.49.92.24]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4280574b0e8sm8233605e9.26.2024.07.24.17.27.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jul 2024 17:27:26 -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 1/2] iio: trigger: allow devices to suspend/resume theirs associated trigger Date: Thu, 25 Jul 2024 02:26:40 +0200 Message-ID: <20240725002641.191509-2-benato.denis96@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240725002641.191509-1-benato.denis96@gmail.com> References: <20240725002641.191509-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 Thu Jul 25 00:26:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Benato X-Patchwork-Id: 13741477 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 7F8726FC6; Thu, 25 Jul 2024 00:27:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721867254; cv=none; b=fcXwo7BSVT/9dfYN7gXVz/KI0F5Gn7NvMj6AioVdgVuqkb/JCYluNJZdi6fNAwY4z6KBYG1TNYwBQg2Ava+GZEweO7ds43f8Dhx8BZklWhbIB7YEJi6Sy+EFyYySyAK2KHpZ0KZXkIalULOZRZ5nl4U3fFK8diqzLvzlVUcarn4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721867254; c=relaxed/simple; bh=T9DLii8v4aOaUBaU7hCbTIYyBZYb9oXvlzIku2iOGBM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uMj181Rk1YaaPtnSRZ/OmVfGX2R4Gth/EYpAI/wyGyqUa6S6iW3V83sCbcSE1MN687x+pbdBD8IaFb3nhO8fzZlWvH5v0GWFnHHLqbiGC3HGMVm7Q23Mn+G2rzv3lmMhxwioW7ldqSqCm9q/lDQKZofpUbdvU3f5mACmv8WGusY= 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=VsvnNWj3; arc=none smtp.client-ip=209.85.128.46 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="VsvnNWj3" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4266fd39527so2509835e9.1; Wed, 24 Jul 2024 17:27:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721867251; x=1722472051; 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=sKRmX5Q90wGaZsCyydkQv8Fblb74XnzTuhdZqPGvWi4=; b=VsvnNWj3RVI2JYjVQTHmMK24PX2sa2LkhqDh5uYkcPhVLb4wtti+JrRWDSuRi2newp aLavrzekxCLFZb2VAF4ADW4OvCfkKBcesSnRnEfMHLjoOjB0rgL9TadotjQ/NCRYtl/Q L5VoS8EQx28eODOIaUDIuGIv+Ij3vUt6i4peXvFdqB44dJ9ituQi7ou/W6WpoWwjYhTn QJhwDQVfWgNt7q9xbtaIR+WmMGS98VZm9jEizfjL8wx56hm3BuecHClgs21+Nhh2vhhQ 1laZnXKQ5x/Cu5xK7f5fMbGSf3aOAtspNSmlyxlJExAorDfnCMPX+sSvSvHTeYsfok0I gWZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721867251; x=1722472051; 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=sKRmX5Q90wGaZsCyydkQv8Fblb74XnzTuhdZqPGvWi4=; b=gKwo5DwPn7TDQ7VcM1jh3G08eo+zp57fnFNlGg8w+AhyS9XyK+RmuRj0KTVj7wAS+g b+0byOHQmX3KUiqtj2ZsRcvsk8/sn0emvwNuWbYw8rDZoZrLLRHP0jzIIy29Srg7QYH8 Hjugh2/KKfCsXAPCFy5sryOVhYy0gD48QesDTZj2QJ0oIQ0oe9OLutKiqwfcTflEY647 DEJ6tJEiQCW4Idj8gnmQsBmB4lXdORnkDYovPK1GvlzgrpO2pPNa+2kbyQNgl0AXLQep b0xIK7/YJ/FtUuzV6drfIRkurZRJqI9wQAD9jlsOssi+TVWu/Zd5jg+83lL/veXYHrDg RgtA== X-Forwarded-Encrypted: i=1; AJvYcCXql6+yLi7EQLG8rq+PFlzzo6LgWV9XY/OrQQnsBBNnb6eHV9MMAZ48VsL+I1OVX2W+urFfGWcQoppcXOhXBdVTkqLBgVw4/faCTh2A9JAHj9pmigPSLebmzcT22i9yv1QlyTT8/0Zw X-Gm-Message-State: AOJu0YzvR2bU9+23G5t1LMyWpiKKkVZLeFggrCWS0l7z7//1YnXJTMBG gZHOtuS0IRVVBemukWmydjNniXGUi9rQBn+MBpzjMjuQoE/dKCcA17LMDUX3 X-Google-Smtp-Source: AGHT+IEbH/V1J78wj0w4t7L0lsKvXZ34C8HDFZriiGxjfoioTMkjpZ1CzV/4JpdHFJIkfjsjQvJ+rQ== X-Received: by 2002:a05:600c:154f:b0:426:5b3a:96c with SMTP id 5b1f17b1804b1-4280573c824mr3302895e9.28.1721867251063; Wed, 24 Jul 2024 17:27:31 -0700 (PDT) Received: from localhost.localdomain ([151.49.92.24]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4280574b0e8sm8233605e9.26.2024.07.24.17.27.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jul 2024 17:27:30 -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 2/2] iio: bmi323: suspend and resume triggering on relevant pm operations Date: Thu, 25 Jul 2024 02:26:41 +0200 Message-ID: <20240725002641.191509-3-benato.denis96@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240725002641.191509-1-benato.denis96@gmail.com> References: <20240725002641.191509-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 | 29 ++++++++++++++++++++++++++++ drivers/iio/imu/bmi323/bmi323_i2c.c | 1 + drivers/iio/imu/bmi323/bmi323_spi.c | 1 + 4 files changed, 32 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..b318544957de 100644 --- a/drivers/iio/imu/bmi323/bmi323_core.c +++ b/drivers/iio/imu/bmi323/bmi323_core.c @@ -2121,6 +2121,35 @@ 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); + + int ret = iio_device_suspend_triggering(indio_dev); + + return ret; +} + +static int bmi323_core_runtime_resume(struct device *dev) +{ + struct iio_dev *indio_dev = dev_get_drvdata(dev); + + int ret = iio_device_resume_triggering(indio_dev); + + return ret; +} + +#endif + +const struct dev_pm_ops bmi323_core_pm_ops = { +#if defined(CONFIG_PM) + SET_RUNTIME_PM_OPS(bmi323_core_runtime_suspend, + bmi323_core_runtime_resume, NULL) +#endif +}; +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..79c9b029a209 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 = &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..ec3238d93862 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 = &bmi323_core_pm_ops, .of_match_table = bmi323_of_spi_match, }, .probe = bmi323_spi_probe,