From patchwork Mon Dec 2 19:23:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13891231 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.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 ACFE21DE3D6; Mon, 2 Dec 2024 19:23:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733167428; cv=none; b=kWkRIKIOfDR6CjxNXKK+inylKCSmufqhSnZkyWeK8901mDkFJxKSVb2Ipz4MrDkfESJFX9XB6vpPztp5zjAsI4t1SyT1ufOv3+mVIuPquyo2B7Z2Z75wXt3nMdBnSCWWaSf5qxo9nPcd9YEPC2/iHuzhR8jdM5IhIhliCjjDXeE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733167428; c=relaxed/simple; bh=D4miNLrdUjNpvgsWdNtGYLIqx0AWqeHKGicEGM4bmIk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=elzEWZ3q9G+ghcGEP7TYbxJr9TBfcf7T7Hu1v2Dd0+0+1FlSeJqzxw0mCYO4g7THqqa9UlrW3VW9Ax2b4MhJPNf+/OC99867NulPY2ErTbEhHhISwsEgx2E2uBI2QSKnAsG6AwSGFupxVzjav2PpY4m51ITWo8nyaItFw6PFlrE= 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=JuJywA/T; arc=none smtp.client-ip=209.85.221.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="JuJywA/T" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-385e1721716so1597521f8f.3; Mon, 02 Dec 2024 11:23:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733167425; x=1733772225; 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=e0lwKiEACMAPvcW411fJIEGRcVHX/+cvcSO0BF6RzuA=; b=JuJywA/TREbHKdSuCYz+pBABhV2ShhhWRBv754qtN6zwSbea6cLxXcmi1qdlqLFnxw qBVGbHIar/zZM126XdsCxUS+BBnIl+SFY1t3eEvE8NMyGOMDKaGyC4IxfSyhuTF0kCiX d4iCTZ0WgxXTLeyELz565cmSEFIEY4W2LMZetuwgGVOdZvz8IgjvlbzeGud58NKdo+o1 j7M2RCtiX0UPig6tgNGH90JaVhmlKezrjCQVL7UYGHv/SLz5Sww4N7d7WYttOUvQywze 2iOqJ/hO7888Avk1+ggaOwPZAdXkNMEKfapf7uVu6JGn3a2Mzsffzu9P+GQ6FK8ROxI8 NJew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733167425; x=1733772225; 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=e0lwKiEACMAPvcW411fJIEGRcVHX/+cvcSO0BF6RzuA=; b=oeoveW9ws2Cf6rE8xcuFeW+L7z8gQ3odgCRmpKqf3CEjPH7Uif0JfhdYFkHFnJy3qQ FXazYcRjMfB58kAmtIcuYXhn0MzK2w49ULoWcJyBsrJGktr8spigm2qYECJE9DQa/2qW ehCJ9MJXDn3/f9E5tHXp4+sXluR8P2PnLH2ooKeY4TJq5c23gmKf6ph3MIqxidVUWAZ6 GBsbX11SOASOnGYQmdqIbLHmHR118b3YtWko+e7tmpE0t6DY7LSfv7sSax+VIaTlhPWe mwMeSXHGZ0RvusZUsAbI259D343aMYcgnmw03II3IXIlN0bcB0Jxr7+5FIY7SlzXmKYl jadw== X-Forwarded-Encrypted: i=1; AJvYcCUh1O+RWMmXkZk3qNZtqMJB6haMWFJ6wSk5i7i5L9KH/9/+dTV5wrVXNIevRk/lmdNJoHgAd5h3oSPR3YnY@vger.kernel.org, AJvYcCVGYyBxkE3juvhm1X5wR1fLf9nPPZ90U64037EwFFZdSNkvyTFsxvdOiR04TawdHNO7OVhN5IYg016l@vger.kernel.org, AJvYcCVIRTeJYpMmWwigcZIF+aOGYf8gz6VzEBdmNKJOvE3eidvVHtiQXLao6wsC57EsxfqTWmjlE47oJvQn@vger.kernel.org X-Gm-Message-State: AOJu0YxRhOOgknLsn5RzakIhay+/4J4/16sn3uDPRngQaLceJkWYtiVr ugBczeGK2mx2KipXuRgz+sfiD6WJiriKoXPx5v1fhgf0ewiBrhkv X-Gm-Gg: ASbGncsjadbgq7gjb6lbWJG3atzcN/Rjo88CcMwfYol4xyqz5ztNCVMiNAFbpO2YWHE SiGDVRPs0XTrorhxRejri4uOCRSekCakRkLIkJ4TbxBGcjVHvlc8uuoVuF3s7FvzPtQtOlDHFXO xHpJyCzp9vKtSgEbO8LMCMDgv/egOkMz6rZSvDMejTB2HTt7yOutdGIY5Xtt4nFpldEcw9YBLFV eJTWXvje63Fg/81Y1KahUu7WF6KsRLLsrhQ/1rYRJRt/PDW/Gl71uioOc2ZGoI= X-Google-Smtp-Source: AGHT+IGjsW2s6N2IJOHUo2u3n7scFirGUdP5Jk+yn96iAt82GqGZtL9W1ftePbKjOi0WRMNhr+gJWw== X-Received: by 2002:a05:6000:71b:b0:385:df59:1141 with SMTP id ffacd0b85a97d-385df5912ddmr12418155f8f.5.1733167424856; Mon, 02 Dec 2024 11:23:44 -0800 (PST) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:ea8a:93ec:a066:eb25]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-385faec0c9dsm832609f8f.20.2024.12.02.11.23.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2024 11:23:44 -0800 (PST) From: Vasileios Amoiridis To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andriy.shevchenko@linux.intel.com Cc: vassilisamir@gmail.com, u.kleine-koenig@pengutronix.de, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Krzysztof Kozlowski Subject: [PATCH v5 1/3] dt-bindings: iio: bosch,bme680: Move from trivial-devices and add supplies Date: Mon, 2 Dec 2024 20:23:39 +0100 Message-ID: <20241202192341.33187-2-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241202192341.33187-1-vassilisamir@gmail.com> References: <20241202192341.33187-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Move dt-binding for BME680 out of trivial-devices.yaml and extend it by adding the missing supplies. Reviewed-by: Krzysztof Kozlowski Signed-off-by: Vasileios Amoiridis --- .../bindings/iio/chemical/bosch,bme680.yaml | 62 +++++++++++++++++++ .../devicetree/bindings/trivial-devices.yaml | 2 - 2 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 Documentation/devicetree/bindings/iio/chemical/bosch,bme680.yaml diff --git a/Documentation/devicetree/bindings/iio/chemical/bosch,bme680.yaml b/Documentation/devicetree/bindings/iio/chemical/bosch,bme680.yaml new file mode 100644 index 000000000000..fe98ec44f081 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/chemical/bosch,bme680.yaml @@ -0,0 +1,62 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/chemical/bosch,bme680.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Bosch BME680 Gas sensor + +maintainers: + - Vasileios Amoiridis + +description: > + BME680 is a gas sensor which combines relative humidity, barometric pressure, + ambient temperature and gas (VOC - Volatile Organic Compounds) measurements. + + https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bme680-ds001.pdf + +properties: + compatible: + const: bosch,bme680 + + reg: + maxItems: 1 + + vdd-supply: true + vddio-supply: true + +required: + - compatible + - reg + +allOf: + - $ref: /schemas/spi/spi-peripheral-props.yaml# + +unevaluatedProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + co2-sensor@77 { + compatible = "bosch,bme680"; + reg = <0x77>; + vddio-supply = <&vddio>; + vdd-supply = <&vdd>; + }; + }; + - | + spi { + #address-cells = <1>; + #size-cells = <0>; + + co2-sensor@0 { + compatible = "bosch,bme680"; + reg = <0>; + spi-max-frequency = <500000>; + vddio-supply = <&vddio>; + vdd-supply = <&vdd>; + }; + }; diff --git a/Documentation/devicetree/bindings/trivial-devices.yaml b/Documentation/devicetree/bindings/trivial-devices.yaml index 9bf0fb17a05e..b651826e2d21 100644 --- a/Documentation/devicetree/bindings/trivial-devices.yaml +++ b/Documentation/devicetree/bindings/trivial-devices.yaml @@ -55,8 +55,6 @@ properties: - atmel,atsha204a # BPA-RS600: Power Supply - blutek,bpa-rs600 - # Bosch Sensortec pressure, temperature, humididty and VOC sensor - - bosch,bme680 # CM32181: Ambient Light Sensor - capella,cm32181 # CM3232: Ambient Light Sensor From patchwork Mon Dec 2 19:23:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13891232 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.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 C20BD1DE4DB; Mon, 2 Dec 2024 19:23:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733167429; cv=none; b=tfJx8Fjii7vmP4rAzJ+fg7fHD9mSwg00rGdJspa6j9oEHxbwQ9MNqKoNqf8gvQUeyFRhiHQerD8jyb/NQ8yDLh6lNQXp/FPkKJ+VbmGsOtEQ9RQHtbskO+Qv0WGs0qlgA0Viqr5YJlrN4QLGc1MXrHrXbJFBFS5ep5zvzO6V+fU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733167429; c=relaxed/simple; bh=LGpOYwn/A6DItljnyHwEHtZ8L2kk+buAoFuZMTNJ7+c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P25KLxX9ucxzfhrfUuTw5/njaLBn1sF4D5ehUuO6PFMdT3+kbeQsBBkOnekjCjRvWXAO5VyQyfySS9ojwwlqAM5YTRSjxqLVFS5ImK5mHVELZMNxHNTolsKoZ7S3D5C2Dokd8c+UAcuZ4bNwTZYZ1DrMOWmCK+8iRIRWTZga7pY= 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=fUHBn+EM; arc=none smtp.client-ip=209.85.221.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="fUHBn+EM" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-385eed29d17so1108670f8f.0; Mon, 02 Dec 2024 11:23:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733167426; x=1733772226; 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=YQmnrJMqai/D1JfzNaB/OfDbbM4m/TnF3WL4Zhy+n3U=; b=fUHBn+EMAsH5PtEornSzicO4jGEaWQH4KYRBWm1L86ALhyoiHuLtqqPzRKanumPRxt wmm1QecS5yyO2IG36UqxoPZKwqyxNDdd02DZTppiuhJtwDvtTFjQ8QZm3LhzPHt1lMPQ 0hpI67FI3juZo3n0u08G9N3Pi4cP97+87/nEaH+scSpaH52WYV4V0kbUoIOhaXXqExRe TaLoKTrFU2+uD4bWb5SCrm2UGYoJS0gc9Jrd6vuEhl5HHQmaDaUQPmqSD81QdaGSI2I7 FjxoK1f7j6rBwHY7fH0TIGQulrRXRFxHbgVrYzb4QHtUMVpDn6zmAM/T/Z+EzvjFRRuu R4Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733167426; x=1733772226; 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=YQmnrJMqai/D1JfzNaB/OfDbbM4m/TnF3WL4Zhy+n3U=; b=ntCeRaxVR1709sS61it5IEvdNDk93UOwpU4JMJhRRZu/I8j56w1jqfg2iwoexmZULt oTHA9PdBCcV2Bxqji9BmktTxcHbVH8wM8j2uEwg7U1yyeSXU3Chva7/sQq26fZu6kN/b 2Eq47nIo7i9t4fpC+qsYB8q4gBf71LByvNzGn764qzvaR0xWQfHm7hXOFwtZ7bDBpeMP xim9yG1noZKUwPDPIpRYphgXlNRQ0cm71x65rf+n8EvIHglCMQmBncrbDopD+Ze8naQj Ud8CeH+UiYRkqg+HbJ3JvgjJitZVZpCnI/0pEjjgMwnBR1nvQ5rmQEM3Cq0mK9UP4et8 J4PA== X-Forwarded-Encrypted: i=1; AJvYcCVZ4Q01uTEEzXmMdkVRrFs3dv6wBPnLB6wDZPzrquMfsnUH5QvnIb8V5ufbGAZqUZL780rXCJZB9p2k@vger.kernel.org, AJvYcCXH+pTwG8chd1cEqLL6N5pin9lcpaMA+mpEfrP0LCCAI96Dub4PBJe+qYaJj3KlfzWAEMX7rDk0EN95@vger.kernel.org, AJvYcCXQJZchUHst9zrWasfowScjZukQ13y7RMdZx4uNAxEPZfDkJEQfQniXjrGFWbbO0Dgf9nyQFJrDT3BkAU9F@vger.kernel.org X-Gm-Message-State: AOJu0YxBaUZ/JLKdqyDKoqKfmpUlSQYYrU3NqzD7rSQMkTirSJZW6gp6 kCy8ngFbiPyvjX/FGJj6Nsnw5U8u4+m2RHeZhm/4AM/5r54nn8Wk X-Gm-Gg: ASbGncvmag7e7cY6ZyOvF5oNR40S1DS/KFCg4etJUf+yV477egEEomzMY2mPN/ciRh7 XIm0W3htCiB0kewL4fDgskBcjxWb36jzZv7JzSiafme/gEl5xnwbFcE79lCRjydX/Gb8rQSTz/u cR2l8JdNWTeFd/Ub4Q7cJzcDwj4dZ/PKX2l3jYsstA+WnYdIcFcohzeNQb2GaVi3WjMqCQJZDc0 hAo42c0gVgvd/tgY1SsKrIqJUPmXcw6WiQhJjav/Zv9xgZpIb0j4omL7bAM8MI= X-Google-Smtp-Source: AGHT+IG+Cj1JhF/m9hEu1dFvEehljL8+YQo8VLZ7DyQr5N+ReMpTQns9gyqtXESxtxLGjNbc/HWXNA== X-Received: by 2002:a5d:64ee:0:b0:385:f677:859b with SMTP id ffacd0b85a97d-385f67789a8mr2801759f8f.10.1733167425952; Mon, 02 Dec 2024 11:23:45 -0800 (PST) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:ea8a:93ec:a066:eb25]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-385faec0c9dsm832609f8f.20.2024.12.02.11.23.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2024 11:23:45 -0800 (PST) From: Vasileios Amoiridis To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andriy.shevchenko@linux.intel.com Cc: vassilisamir@gmail.com, u.kleine-koenig@pengutronix.de, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 2/3] iio: chemical: bme680: add regulators Date: Mon, 2 Dec 2024 20:23:40 +0100 Message-ID: <20241202192341.33187-3-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241202192341.33187-1-vassilisamir@gmail.com> References: <20241202192341.33187-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add support for the regulators described in the dt-binding. Reviewed-by: Andy Shevchenko Signed-off-by: Vasileios Amoiridis --- drivers/iio/chemical/bme680_core.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme680_core.c index 9783953e64e0..bcf84c0a1a59 100644 --- a/drivers/iio/chemical/bme680_core.c +++ b/drivers/iio/chemical/bme680_core.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -111,6 +112,8 @@ enum bme680_scan { BME680_GAS, }; +static const char *const bme680_supply_names[] = { "vdd", "vddio" }; + struct bme680_data { struct regmap *regmap; struct bme680_calib bme680; @@ -1114,6 +1117,14 @@ int bme680_core_probe(struct device *dev, struct regmap *regmap, data->heater_dur = 150; /* milliseconds */ data->preheat_curr_mA = 0; + ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(bme680_supply_names), + bme680_supply_names); + if (ret) + return dev_err_probe(dev, ret, + "failed to get and enable supplies.\n"); + + fsleep(BME680_STARTUP_TIME_US); + ret = regmap_write(regmap, BME680_REG_SOFT_RESET, BME680_CMD_SOFTRESET); if (ret < 0) return dev_err_probe(dev, ret, "Failed to reset chip\n"); From patchwork Mon Dec 2 19:23:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13891233 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (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 B997A1DE882; Mon, 2 Dec 2024 19:23:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733167430; cv=none; b=WSs/MPXrZc+HaO60fXML1JPjODA++YulpB0+D5enALEOEZ8PvPa4AjzNEeTtDXmipr8LJVYy5QDzhBW6DcRT28rSEgzPhj1EFpw42aM6lvtgCcIe2/db+xv+6JT7iInHY1I7fyOwkg67Q9gv0DCOHSImUSEIjNWMZ3l9+jfUsw4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733167430; c=relaxed/simple; bh=bY/vG50WctqTDmTpVFD7dslkumbhjAiWmYZ0wXQJnEI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t1T2ubXrLaZZPjRWTa62nQHJ1OK6q4yMBaYnatnlWajUgd17wiJLW7aUYZpY7o/Qnq5lPt3D+vF4ozS4IGj8IQb8kM0TRlHSSe6iN2Iu/c3408ZJmfMppd+y9PN+TdRniKp6jEQHHMOFDIYezO7bSmOOEcA90HNG2nfpVcnv4MU= 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=Cb4KHrce; arc=none smtp.client-ip=209.85.221.50 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="Cb4KHrce" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-385e2880606so2863855f8f.3; Mon, 02 Dec 2024 11:23:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733167427; x=1733772227; 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=laYRgFy7BwtjSJ4ddK5TZ+HdOeiOWp/2L5sL/4prUhk=; b=Cb4KHrceSdafL8F8C95Tu2+TwQtSwMGqScVNUzyR4rRnwlatkPGMDrRj8Dt7BhXgdR 2PCom6ggo4ct408zK0SHUBGETJd4vt1y0xKgXRSt1Bum1Gl7Tw+vjBKPBiNGru4yndT0 cRljIF9gjzuewm0Qrkq2hdaQhZQm/PBWjNg07JLCS3Q8NgjdaeU997hBNOE1OCBUJXMs qeXtzL0FUaaEE7r5EPHSeqXs8w/+5LkYRUMQrIkNwPju2n41LxgkMDjGzxcw1zh9zz4N SvOBK2M43eb3WqaGm9HcF6KbWwcyPvjxb2CsBEXmuzpxnzvWWIJeLTRk0w/1J4vexwES J2eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733167427; x=1733772227; 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=laYRgFy7BwtjSJ4ddK5TZ+HdOeiOWp/2L5sL/4prUhk=; b=Mh3MOwO76m2y2AXRYqkLKJPTlhqoQJLkqkTE2Zexko3t4WGr+9AaSEuj2LsmV2VG3N bNEMDoaLcJxXCJGxhNcbML42ZCA8JEDYxAT4rOHVOHlqNEHWTiQE02j6Y5mBnN+0mxrw 1o4dD1bjPIKlxiuLjLT7MOL3cfK9CaMQmP++wNMkbtoaa5Jct971l2kw68R7zZMBywCB GkY8G5ahO4l1ejaykMUBs2DlhArCSDgSDVWc8NhMxtvHna9WxPUVQViv1N7AujdvL6xu MwKk2Q7elPW2I7VB7sxz23KPCHs3LxV39zAHNDgB1hpjcEFPEgvfNxVnSUR/dR765EyM EbVw== X-Forwarded-Encrypted: i=1; AJvYcCU/Q6mHes5F/t5mHRfhuJaYNDuPmeHHY3KQgtaJgEywJKNVDDEH3B4qik1X7ZJl8If/M512GMzbHaUt@vger.kernel.org, AJvYcCWfelvlcs83i9/1U2MQO4IBg5vmzlImNrVAfbqtcR1SVDK1EskpbaWMKEAgAbBc/O37zQZzFnYQsZhk@vger.kernel.org, AJvYcCXbozq0m3uJRV04jA+McjiaBh9VGhxskTWLmNAXnsNZ+fHdcZC10fI+ghoHAy9J1a7lgsVs4Q5KLWeZYg2k@vger.kernel.org X-Gm-Message-State: AOJu0YxigEpSIX2IzWDG9bJgxGG7BXyWuU78mbmyhXrYhXRQkWEiPFiD vuTQvFDRYzp4pydz0GdA5j18GhsnZG1C0MU+gyq0ee2uXjvKPOWd X-Gm-Gg: ASbGncuhIxDZbkfwpUiKwZERBzRfA60Eu3SeK+ehGhdg8PAcuI/xr15Zl39GlNDIsLF B8CredhjStj/W+A6lXn3r3eAXA3rnwtOWTOF6Cx8zvi1DoVuNEJEx7tc2pHk5wySvsuzBnOHCk1 69LQibjcIT7NdFxyGpZ6FifE3cKx836zwC3CZXIwk/36GiFtdqP61SFvRWvADr9FOSaZFn3WVfh rh6+mT+ga0gLqlf4nXUyYulxRPFn7MBult97PGaTCneWr/F3+BZ3fNLR5xyNow= X-Google-Smtp-Source: AGHT+IHyM3Jh4m2wvzkhhpLMW3hCPU12pVl9WUsQNg/aQ6BQhxzMtjFbmnHJIc23Rzouhb865LYcaw== X-Received: by 2002:a05:6000:1a87:b0:385:f6f4:f8e with SMTP id ffacd0b85a97d-385f6f4143dmr4174921f8f.50.1733167427015; Mon, 02 Dec 2024 11:23:47 -0800 (PST) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:ea8a:93ec:a066:eb25]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-385faec0c9dsm832609f8f.20.2024.12.02.11.23.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2024 11:23:46 -0800 (PST) From: Vasileios Amoiridis To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, andriy.shevchenko@linux.intel.com Cc: vassilisamir@gmail.com, u.kleine-koenig@pengutronix.de, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 3/3] iio: chemical: bme680: add power management Date: Mon, 2 Dec 2024 20:23:41 +0100 Message-ID: <20241202192341.33187-4-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241202192341.33187-1-vassilisamir@gmail.com> References: <20241202192341.33187-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add runtime power management to the device. Signed-off-by: Vasileios Amoiridis --- drivers/iio/chemical/bme680.h | 2 + drivers/iio/chemical/bme680_core.c | 114 +++++++++++++++++++++++++++-- drivers/iio/chemical/bme680_i2c.c | 1 + drivers/iio/chemical/bme680_spi.c | 1 + 4 files changed, 111 insertions(+), 7 deletions(-) diff --git a/drivers/iio/chemical/bme680.h b/drivers/iio/chemical/bme680.h index 00ab89b3138b..7d86ed8b02e6 100644 --- a/drivers/iio/chemical/bme680.h +++ b/drivers/iio/chemical/bme680.h @@ -2,6 +2,7 @@ #ifndef BME680_H_ #define BME680_H_ +#include #include #define BME680_REG_CHIP_ID 0xD0 @@ -80,6 +81,7 @@ #define BME680_CALIB_RANGE_3_LEN 5 extern const struct regmap_config bme680_regmap_config; +extern const struct dev_pm_ops bme680_dev_pm_ops; int bme680_core_probe(struct device *dev, struct regmap *regmap, const char *name); diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme680_core.c index bcf84c0a1a59..f5f22a83ad5b 100644 --- a/drivers/iio/chemical/bme680_core.c +++ b/drivers/iio/chemical/bme680_core.c @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include #include @@ -820,9 +822,9 @@ static int bme680_read_gas(struct bme680_data *data, int *comp_gas_res) return 0; } -static int bme680_read_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int *val, int *val2, long mask) +static int __bme680_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) { struct bme680_data *data = iio_priv(indio_dev); int chan_val, ret; @@ -935,14 +937,33 @@ static int bme680_read_raw(struct iio_dev *indio_dev, } } +static int bme680_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + struct bme680_data *data = iio_priv(indio_dev); + struct device *dev = regmap_get_device(data->regmap); + int ret; + + ret = pm_runtime_resume_and_get(dev); + if (ret) + return ret; + + ret = __bme680_read_raw(indio_dev, chan, val, val2, mask); + pm_runtime_mark_last_busy(dev); + pm_runtime_put_autosuspend(dev); + + return ret; +} + static bool bme680_is_valid_oversampling(int rate) { return (rate > 0 && rate <= 16 && is_power_of_2(rate)); } -static int bme680_write_raw(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - int val, int val2, long mask) +static int __bme680_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) { struct bme680_data *data = iio_priv(indio_dev); @@ -987,6 +1008,25 @@ static int bme680_write_raw(struct iio_dev *indio_dev, } } +static int bme680_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + struct bme680_data *data = iio_priv(indio_dev); + struct device *dev = regmap_get_device(data->regmap); + int ret; + + ret = pm_runtime_resume_and_get(dev); + if (ret) + return ret; + + ret = __bme680_write_raw(indio_dev, chan, val, val2, mask); + pm_runtime_mark_last_busy(dev); + pm_runtime_put_autosuspend(dev); + + return ret; +} + static const char bme680_oversampling_ratio_show[] = "1 2 4 8 16"; static IIO_CONST_ATTR(oversampling_ratio_available, @@ -1087,6 +1127,34 @@ static irqreturn_t bme680_trigger_handler(int irq, void *p) return IRQ_HANDLED; } +static int bme680_buffer_preenable(struct iio_dev *indio_dev) +{ + struct bme680_data *data = iio_priv(indio_dev); + struct device *dev = regmap_get_device(data->regmap); + int ret; + + ret = pm_runtime_resume_and_get(dev); + if (ret) + return ret; + + return 0; +} + +static int bme680_buffer_postdisable(struct iio_dev *indio_dev) +{ + struct bme680_data *data = iio_priv(indio_dev); + struct device *dev = regmap_get_device(data->regmap); + + pm_runtime_mark_last_busy(dev); + pm_runtime_put_autosuspend(dev); + return 0; +} + +static const struct iio_buffer_setup_ops bme680_buffer_setup_ops = { + .preenable = bme680_buffer_preenable, + .postdisable = bme680_buffer_postdisable, +}; + int bme680_core_probe(struct device *dev, struct regmap *regmap, const char *name) { @@ -1160,15 +1228,47 @@ int bme680_core_probe(struct device *dev, struct regmap *regmap, ret = devm_iio_triggered_buffer_setup(dev, indio_dev, iio_pollfunc_store_time, bme680_trigger_handler, - NULL); + &bme680_buffer_setup_ops); if (ret) return dev_err_probe(dev, ret, "iio triggered buffer setup failed\n"); + /* Enable runtime PM */ + pm_runtime_set_autosuspend_delay(dev, BME680_STARTUP_TIME_US); + pm_runtime_use_autosuspend(dev); + pm_runtime_set_active(dev); + ret = devm_pm_runtime_enable(dev); + if (ret) + return ret; + return devm_iio_device_register(dev, indio_dev); } EXPORT_SYMBOL_NS_GPL(bme680_core_probe, IIO_BME680); +static int bme680_runtime_suspend(struct device *dev) +{ + struct iio_dev *indio_dev = dev_get_drvdata(dev); + struct bme680_data *data = iio_priv(indio_dev); + + return bme680_set_mode(data, BME680_MODE_SLEEP); +} + +static int bme680_runtime_resume(struct device *dev) +{ + struct iio_dev *indio_dev = dev_get_drvdata(dev); + struct bme680_data *data = iio_priv(indio_dev); + int ret; + + ret = bme680_chip_config(data); + if (ret) + return ret; + + return bme680_gas_config(data); +} + +EXPORT_RUNTIME_DEV_PM_OPS(bme680_dev_pm_ops, bme680_runtime_suspend, + bme680_runtime_resume, NULL); + MODULE_AUTHOR("Himanshu Jha "); MODULE_DESCRIPTION("Bosch BME680 Driver"); MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/chemical/bme680_i2c.c b/drivers/iio/chemical/bme680_i2c.c index 7c4224d75955..9998d7fa3e98 100644 --- a/drivers/iio/chemical/bme680_i2c.c +++ b/drivers/iio/chemical/bme680_i2c.c @@ -51,6 +51,7 @@ static struct i2c_driver bme680_i2c_driver = { .driver = { .name = "bme680_i2c", .of_match_table = bme680_of_i2c_match, + .pm = pm_ptr(&bme680_dev_pm_ops), }, .probe = bme680_i2c_probe, .id_table = bme680_i2c_id, diff --git a/drivers/iio/chemical/bme680_spi.c b/drivers/iio/chemical/bme680_spi.c index 7c54bd17d4b0..43d59544d903 100644 --- a/drivers/iio/chemical/bme680_spi.c +++ b/drivers/iio/chemical/bme680_spi.c @@ -154,6 +154,7 @@ static struct spi_driver bme680_spi_driver = { .driver = { .name = "bme680_spi", .of_match_table = bme680_of_spi_match, + .pm = pm_ptr(&bme680_dev_pm_ops), }, .probe = bme680_spi_probe, .id_table = bme680_spi_id,