From patchwork Thu Nov 28 19:32:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13888292 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 6597CAD4B; Thu, 28 Nov 2024 19:32:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732822382; cv=none; b=uOnPIep8/W5jscVg6LwIWTYZGgQiJRx/NQAMSbuskK4isIgrrPENJ1/Q9Af/Jut7P6xVSpMv9EICY5WhjnLKtQ6NuU0wnftZnxUk6SpunG7y417aHLi655qbbwUVvwyl653K/PMRuZUrTXJ4X6oNCF40ain1MuDErl6H7azRlWA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732822382; c=relaxed/simple; bh=n7T92YggRAuP3R5wCfxRp6kzech/Kx6Vgv2R1+J3Bro=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k0Wt3wOcAi24LcJCmsRN9beOIe1qAY/qCUGBY8lTQivgICB3NekIVPei6aNXptoOboRxjQS0RhJ2YJZqWRhY4j+o1Rf5A5uiPkduHC0fX0WCKgbaNqDDu/OeeCzrPPG8abLMfSi/qz8Bg9vZviXrMS5j10GPf+QOoewESdbr8YE= 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=T2INZbYm; arc=none smtp.client-ip=209.85.128.48 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="T2INZbYm" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-434a1fe2b43so10344975e9.2; Thu, 28 Nov 2024 11:32:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732822377; x=1733427177; 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=mINgVsR+9ZHzOoyqP/s/zmpdc0F/7r3SD5kpKvEC3qg=; b=T2INZbYmjGIi965Te6qv0938VFkko8wH8pejQVkDtJMz6Rp9J9B7BxPZiACJR9hXFT RniMeqL9UFuetOdvV1ltL/lou0+LhO7Hik6AMfX6dnh9bGS9fWW1e7M+Ein40Egri0mu cryMyXPeVtTXQLsIBa8JNoLpul3Ss+vk6QOFWYwOweaFt2yKHOp8A/dPiM30o0gs0N3a 8DuYuKqJFTEkAzVd+annzidswuOaZ7DzzhQauYMhKWzD+eL5WIRQSgSVL4w4q49b7xMh 3nx+8V09nH16YNfdhQqiA0LiJAbtrYrqdCzt3eRfY72T4HR8WljMLGtpJaW0aKYUKxzR KUOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732822377; x=1733427177; 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=mINgVsR+9ZHzOoyqP/s/zmpdc0F/7r3SD5kpKvEC3qg=; b=iKUGwYmdiMX1jwFT4kT45zvR2eDkVspHSeYaxT0IbHQMM5mhB//mg6SR57Qw/g+uxl QbeRPZ4D4Bt6skWdgMfYyaNp1X4MmJmSMTu04p2Opy74lgPE5Ccx/J7cYrpyTGSnDmTJ r+XLo4Z2GViB7wg3eNXMsvpEPEHH7wOqLGHgMhHLCU4p0luLeOvjXkjuWTcUiMF0NI4x GnYBXuzo/rWHfwiTR6SYziUvPJ15dZk3AxoZ/nm9rp3dTJwkczLBOWBKT/0fhokzq00z FPlj4UVGoOAK+Td3fNgITvFjfudqwzcp1Bi3ZbWzd69YPP0YJHmS8lMj1PclNDKnVgDX srNQ== X-Forwarded-Encrypted: i=1; AJvYcCU/deWYACgQZy2ab9nRmZAUlV7MF4LAT78KmAG41JsiL20ZuY8Tarl3FsjNiA6NulloqEY0rFcIF3Vv@vger.kernel.org, AJvYcCUWC+5K+TaOjy1ugs8/jll4SBnbRmoSAto8SdvGgrbAq1KJK3RIT15MygdsGqpA/crZXmpLUdn+Rwio@vger.kernel.org, AJvYcCW+7jttB9p/qHBu4kCb8dFpqkHRHAlzS6Ft1pjW+HGJn+fxcrrQG8S42u/33jBHFCTbsO2cK2ENjizeIPHM@vger.kernel.org X-Gm-Message-State: AOJu0YxpZeAz6zxjzLS6lGRpUuUIMHlC21DSSdbM7b9drbZDKRwxNQtA 2PrhvUVorsmmXwXhbcfEAyGe1EiGPnXwwoEj6SmTaK59luTfex1L X-Gm-Gg: ASbGnctBfA0zE+WFMtnTc9mnQjU5iV4JBuQgRHExw+wmqJlNsteNFBgLSc198e05J0l /31i7go7wd1kS7t+ku/ZpLUCG6xw3RY9OTrb/o+EyXhky/1uyVs9i1TpYXJEkoE/5EGpCSCz43/ Vm6eo/1jV9x/uZvsDYx60m8uge1IBUHTPHkaq0kKvKysonkmFvJbSDHkEmmh0peUDa0CvWm53Cd 2pRiHD1ntVJOhj7gHi5ZvYG5jXvN2qdVCokU8tikCxfC4tRWHvK5D73+pQ7o68= X-Google-Smtp-Source: AGHT+IEXvwW6EWyAkvdpW7OvIexEwiKXK++sM1WMw4EDwG1Vplt8P7Ei7sYUwykakHvrh8yFiElJiA== X-Received: by 2002:a05:600c:1ca7:b0:434:9f1e:2c2e with SMTP id 5b1f17b1804b1-434a9dcd8fbmr84720585e9.15.1732822377059; Thu, 28 Nov 2024 11:32:57 -0800 (PST) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:a8c6:c7bb:87d7:66dd]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-434b0dbe40csm30557855e9.10.2024.11.28.11.32.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 11:32:56 -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, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 1/3] dt-bindings: iio: bosch,bme680: Move from trivial-devices and add supplies Date: Thu, 28 Nov 2024 20:32:44 +0100 Message-ID: <20241128193246.24572-2-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241128193246.24572-1-vassilisamir@gmail.com> References: <20241128193246.24572-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. 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..0eac22e465e7 --- /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>; + + bme680@77 { + compatible = "bosch,bme680"; + reg = <0x77>; + vddio-supply = <&vddio>; + vdd-supply = <&vdd>; + }; + }; + - | + spi { + #address-cells = <1>; + #size-cells = <0>; + + bme680@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 Thu Nov 28 19:32:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13888293 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 0131319D06A; Thu, 28 Nov 2024 19:33:00 +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=1732822382; cv=none; b=byFL2BmaKOU/kNQBJ+L2xpj1aQdQFAkSQPIHFJUAsYguy3Y0zQrE6Gpa6mjIAzfUaYrrvBH4K+Akbyn8iYiG3BnLdy7SRdlMxGTHtv9h6cXwRzIQIa7P0X/kuxCaPLlseFB9kvxXfeNpnBPHt6O5E5QmoxQ/2QAsRu4XJFGxTH8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732822382; c=relaxed/simple; bh=Em3eOUCdZSAgYZdSmbQ4yY7NDzuoHHztEdqJMLF/G9k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hsHcsePFvHQSmvhknNfjRlZM6IuA1D8dpwVt5MfH0V0Enud2cPyjzTC4b6d28XzyXvwKFNfXk3xHEAtXbBIEm4mY6SIjZTVUpytI2H1jh8uR5w1VWbR80Kcv1iOlP7pfR7O5l3zmunOcjzeLu7Ek1mzx7olQFj664FqrCn7/xzo= 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=ItLE2QfS; 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="ItLE2QfS" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-382376fcc4fso783314f8f.2; Thu, 28 Nov 2024 11:33:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732822379; x=1733427179; 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=xazBXG9O0RzHhvZuaT6MI9gIc1q0aq5PO0WnsSqCZUY=; b=ItLE2QfSZfYbF3F7LAY95mjE4o2uGSt7/ibMxRZvwSPk7JZpZ0kGTadd/9m3xqK1tZ 6gYLF2ULut8nLUTd3OLdFrmBFZe6hbkgz4nlwhSaKWubf3Z39Hwc2vpTCz2RCwkoaGFI dsjYx5roCJvzvE3uxBTAVyX3Iuop3bMustNQ6f8qrNgoKrTz4t8rfEUeMkS9i0caBxKF cltBQZ4/VA3YRzhUTaRMpev1mC8ZCzhD9F6sZ0bydomB8tA2hk6V/wQr5dxY5DN6osvR 8NY2I0II7PoZDA2EnjQ28ATGK6GzI2JntDhb2pkLW3CLtt+41gUmaH2m5gUFXSSxqCDr +ogg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732822379; x=1733427179; 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=xazBXG9O0RzHhvZuaT6MI9gIc1q0aq5PO0WnsSqCZUY=; b=CjYJu7vgFw5Xbfk9Ej5TqyHDBF5dAHcau8vnH+hvo7Mfptir9FrnIjpNzCV6ADz8B2 ToXyx+c0TS8dVuo/QBzTG5laCCoGfHSsTfuOFZjMlRq3yw+lFOPotHMCb5GmJQ2f9JFE 0ZHR5AaotMtUL8SiOeY3cud6+wXzrd7ARjKPZXYeHXSKdbLvu88L5SZ6cAN0TH12Dcmt gjnsvdbZ0QIcD+ORyFgrrb3iMmLkmV9wIqb14YIOeaxv27aUnkTwi2Q8pmsTiHmoHQAd joklCOgDJELF//UE4P3/rzbh2Nip8K36lL8S8VMLHiLF3ebOweR08Zuw4dgY6UUoZ2N0 Y0dQ== X-Forwarded-Encrypted: i=1; AJvYcCVJ27/0DEW01LcogLmy4IQ448WC51PjwZ75s/ete8MoZFujf31lMy+CJpk2r1O9mPCObPMWHVjeHqZG@vger.kernel.org, AJvYcCWckwfSjPxg+f4P3IIbDi4rjl0Fk9gFea5DqcyjCKk8ZWI2n/Dq9Qk7gNuIWQ2UO/mgWwvH9JG+QUaH@vger.kernel.org, AJvYcCWiWkgxNcZaRwmSMDvO12Rg2cp+95XhbBZC216QUgAZvoeHeskfMN+B2lDurdNV7PTyKncZ/guBYZDNd7o3@vger.kernel.org X-Gm-Message-State: AOJu0YxdHxceiG6MR2wayXclxNo6SqZRIaAoPSm25chNMPNrZkl/qi4K GAbKiz/oQHc3ybMfYyItm/i3KqegUhbbC732nGgmb34lV/Z4NspRgGWFwTz+ X-Gm-Gg: ASbGncs6yEuoXJHxtqoU/TBLMKtt3TxJXpr+g/q8XqW7F87Nj5lu6bMb71i/Lk46kOa vVDEruTkZ5bb9mRgodn9XWlD8lh6f6MI+O4/8OS+/GmbE6hblVknClvKTZHu+nFEwW1/elxZRG+ ijAx0C9847cD6T4VvagkeDxuXPcq+p9t4oB7VaLDh3F2Iw6KAJQg7T1Cd87VgSHhsGWOFeXVnGR mQSUJ/tF6QssMs4U5WQotEgBS8Dt6jKewEKkxC3ClpKo8A0qgMnSAGrcLmFVII= X-Google-Smtp-Source: AGHT+IHr3KYxmbetmJvxOLVRdv7z2jTX64gnhA3Eb1SNKUsOy/5TD09bctTe2y8wBVywyIc3RHdbhw== X-Received: by 2002:a05:6000:186f:b0:382:319f:3abd with SMTP id ffacd0b85a97d-385c6edd338mr7501714f8f.36.1732822379251; Thu, 28 Nov 2024 11:32:59 -0800 (PST) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:a8c6:c7bb:87d7:66dd]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-434b0dbe40csm30557855e9.10.2024.11.28.11.32.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 11:32:58 -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, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 2/3] iio: chemical: bme680: add regulators Date: Thu, 28 Nov 2024 20:32:45 +0100 Message-ID: <20241128193246.24572-3-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241128193246.24572-1-vassilisamir@gmail.com> References: <20241128193246.24572-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. Signed-off-by: Vasileios Amoiridis --- drivers/iio/chemical/bme680_core.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme680_core.c index 9783953e64e0..186e0a6cc2d7 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,10 @@ enum bme680_scan { BME680_GAS, }; +static const char *const bme680_supply_names[] = { "vdd", "vddio" }; + +#define BME680_NUM_SUPPLIES ARRAY_SIZE(bme680_supply_names) + struct bme680_data { struct regmap *regmap; struct bme680_calib bme680; @@ -1114,6 +1119,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, BME680_NUM_SUPPLIES, + 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 Thu Nov 28 19:32:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasileios Amoiridis X-Patchwork-Id: 13888294 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 015841C1F09; Thu, 28 Nov 2024 19:33:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732822383; cv=none; b=jmh8FHaQ0m4euKYaFmpLkaOlyNFZYKlnXA1rTyORDxajMH8WPoRNYv/dRp48X459O7HDl/Mn5nShxvTCiNQDCW0PH+PC+39JqvUECu0ku41qY7n6ldlVr0E5Vkd6wXrx/LETWtwFmwjy05p9z5T3Vec/EVjZqczlSmPz3Qm74PE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732822383; c=relaxed/simple; bh=/m9HeDXiP/oB9/XvTvogLY7ZIwfwYb5+QuxqDX5TU/0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M6sRVRmpStDllXZnvAlP04bAe8FUiVwFAqiVTCAvupdnZ7l9Stfk6Z7tsOzZWMlxKeEZRHiUM4FF9AQxhTQC0260xq0C/56cYHnjCG2FR3Y3qYGBUsm0nJ2qqYYmNvfmFY5WlnP0Oa6kHWD44MgNMRTSjJ2V8wx1cL0rI8gbf0M= 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=Dcw+s2W3; arc=none smtp.client-ip=209.85.128.49 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="Dcw+s2W3" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-434b3e32e9dso6800575e9.2; Thu, 28 Nov 2024 11:33:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732822380; x=1733427180; 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=NAJrfEjJg33vVGYrhY1CVICVyJ/+01G/75xDcBakREo=; b=Dcw+s2W3ghEWOmLjhbcA4MDsAKHKDi+AIs9VWqCAsN6E/ESTIJLZ7oNWYY3VhVczOV ECJxeQSYemzjzOce10oweR+Qj8yiHYo5+WF36AHdsrEHX+aogUfgOoKzXBYkh6OQ8FXX 872LeCjtbdReh7cPiKLdrW+HMLKlpkOAmCW6/KcZQHNtbDy+3C3+kibyhyTqhfperhNf BDtkiwnKxcuuaDB5j7n07xnpgBg7AfAviTMb2lR+tUL7I7QwWyB8KrW2Rfkf7dwJUifN hj+GVPhmEuJpB8cgBlVawMcqD7AXfKZ917iq4/WZcAOa3/0DQfVBP42EQrD4jRgLPz55 GJ8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732822380; x=1733427180; 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=NAJrfEjJg33vVGYrhY1CVICVyJ/+01G/75xDcBakREo=; b=rD/KNAJPtZDhZStQVLd49bOVnlL/kt8uD1JVxiUGFeujLuiNTv97htaGodNnpEqutS h0BoP5j0i0OjHWmUhReZq0noeji0kvxe4pnYrj0hNePtJBUAQndGMmdrW08iw0hQ4Hes hyVd0JFh7ZPjv0nUc0Wf/1ezMk7IdxnMM6p5qs+JYKnPgZYC1VTQ4SVqM9r+v/1PchgX V628q1odDn7gk8MRSeqWO1NhCS/OCBLpxIiqwkTmOXhmNn3BwtB+axnGrEONz1ulbE88 vQqgPQBl/nWyWg/tHYoiCusj7oHhLNmXAhEh5h1GxeL5xuymwkxz1q0aF+bdhfchC0MB YJcQ== X-Forwarded-Encrypted: i=1; AJvYcCUvUqqo/NSHBQtOJIu8ujQy/M/Tuv7yMjbdhzZZ8SwPVGb9Lbwor6FrqgI6RpX/SaMWOf6zhDFjhjTj@vger.kernel.org, AJvYcCWpLBmSnroglacTyP865KgwwDlK6rNjUpuwe9/dBKknMV2l2zobVC1U4VAF/a+y8Hjw33IzxmlXqO5iiIu+@vger.kernel.org, AJvYcCXdRZh2W6iRVxPtXm+PQxMS78bTNgI3XwrLdq8W+jyfHnmZ7zX4Ntn0FiC+u9OayNwkqhAaPdl18vtF@vger.kernel.org X-Gm-Message-State: AOJu0YwXZI3AcOWT2pz5jNfsEUz+t7oetJFTylo58ztJRY0EHFp5yh4m DtpigoZXj1WBDB2UrnEWBxYWJF3cZf/PrQnlG/3Q3jPCJGkdvjLO X-Gm-Gg: ASbGncsgWJvGmq6x97zKnkgEOOYEkb3PUpQIDLcJWaDrBlsa8EHL7RBRt8zTx474dS1 A4vzvxPgdvaoIXRiO80S0Vm2vWndL1oM6B+78UTeOPVBzQamj2ynUPKznDq5kQpRBQvyMSWi5Z9 7K5LejUZwe3qGp7oRuO2JINDi9sU+uiMr+S5yNuLF8P9N+eIhOYP2BxMebVMXCh3K1TLydBDaIi w1UkqB2NIJCfnr3K017yHFvUUjEKzi5H2xJQ4QIDC9/d1vtSDBrlApK/ar4V7I= X-Google-Smtp-Source: AGHT+IGDnOOPuGuYzWM9ViiWDOjr9dB+6Uyu6arbTRdE2B1cf8VrLdo+XAEgOxKIlKQnHuV+1D1Xmg== X-Received: by 2002:a05:600c:3b16:b0:434:a4fe:cd6d with SMTP id 5b1f17b1804b1-434a9dc02c5mr79969465e9.12.1732822380287; Thu, 28 Nov 2024 11:33:00 -0800 (PST) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:a8c6:c7bb:87d7:66dd]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-434b0dbe40csm30557855e9.10.2024.11.28.11.32.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 11:32:59 -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, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 3/3] iio: chemical: bme680: add power management Date: Thu, 28 Nov 2024 20:32:46 +0100 Message-ID: <20241128193246.24572-4-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241128193246.24572-1-vassilisamir@gmail.com> References: <20241128193246.24572-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 | 104 +++++++++++++++++++++++++++-- drivers/iio/chemical/bme680_i2c.c | 1 + drivers/iio/chemical/bme680_spi.c | 1 + 4 files changed, 101 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 186e0a6cc2d7..b7a1896a2f11 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 @@ -822,9 +824,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; @@ -937,14 +939,30 @@ 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; + + pm_runtime_get_sync(dev); + 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); @@ -989,6 +1007,22 @@ 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; + + pm_runtime_get_sync(dev); + 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, @@ -1089,6 +1123,30 @@ 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); + + pm_runtime_get_sync(dev); + 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) { @@ -1162,15 +1220,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,