From nobody Wed Nov 27 08:38:16 2024 Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.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 03E8E198E99; Thu, 10 Oct 2024 21:00:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728594044; cv=none; b=KVpHVXq1QKs0FaEx0kylhHau8RXGkQegOrSmDf0PekLWJ9psZ8AlL/CH/9vOoSzJP4Lxto1YmLD+1KuUX/CcZGw5lhPCSHfhuIZ8F1TWsH9WhatIzbQtL17INdxh35gZi4f/exVpOVmJO/tGqafuW0463hTq1mXEKSJ/7cuL3Ys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728594044; c=relaxed/simple; bh=PcDsXuaDHFvvIWrdoWi3vPz31G5jOSTAdjECd3pMCf8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=m5FdhC0vQVTWeq6v++nBRjHBCN8Oo7r0wPPU/ITTGYo57RDamYCr0fG35ooVcQIF1WM05TO14UB/mc7M7l7EQxgIEL+RlX/HO6hpWzzjQAx0hvV8SYZNkka5I8ODx9ln09BbPoKbMLEH2U+dKCQvV0B92HM93hrV68K5VFMbUTA= 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=X9fUfsKt; arc=none smtp.client-ip=209.85.218.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="X9fUfsKt" Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-a993302fa02so216736366b.0; Thu, 10 Oct 2024 14:00:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728594041; x=1729198841; 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=iDfuWT3KuSpR/j9jD4F3+URq4vBzo64UPX30bJI27k4=; b=X9fUfsKtJbnwDIwGRmW8fRMkl/NXbDa7W7kuamSo7X3H3gZYmySFSF1a7qgZYq306f dIH00gK74VFKxGwtFjuLfsvGltKVY3XiKXrsUXmOS1LH5UX/v2+YfC108KG526VZ3kMu 8IKv6IT6GrUXSp3yYBp7rsdpj/354//xQ8H+ChvWQEKUBgl/z1ipPOOrvKXI/eX/DlOo CwPuF0p3hBXTcObz3lmg+trIhjwXJAcc0B0Vyk+/GxX841pE7d9P/YLbH6S4ROgL4Xsv d/Sjf10GZVgoeSRYQgCvI3bKFgbYCrxfvUp4Ty7/tZsltfm0Mb1usRe4nftGvH2wqM9q KIFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728594041; x=1729198841; 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=iDfuWT3KuSpR/j9jD4F3+URq4vBzo64UPX30bJI27k4=; b=Ic+p1pNpLMuBNwE8fO/XGZxqQJ4dH9QACYw/J2qWVyBuxhZGu44AVX1pmuE2sx7GzB pfHtuOB09CmKvjvOrZ77DbboBVEn0ALf5PQWJYZJ9l5yT3TCCqDDL71K1Dr0byqNWKQ7 4FxMiwUZmSh69OpF9S/Ksl3td01NonhG5hddPEeg9heUsxZOKTtd7O4/KBoftbUgX2xB tJY9pir3eS2fbrL9/1THZKvbMoevWzsFfE0j++XtRwgUef8uwGwKTJKHeoGpDLWgyx+2 VA/uPqIoGxve4AAdBW6uzhpXobrB7e2k3n0PQSPVPuIp6UMjp7JMg+sDDx2GAYWO3PIb OHYA== X-Forwarded-Encrypted: i=1; AJvYcCUCX/y+/lF1C6t5z6evb2T3IcikzIYHlO8ebU5UV/ewOkgRw5bzyTWHApp/YaCRUAJEeYAbfS5JLauD@vger.kernel.org, AJvYcCWmVQ7KZ6UJkmh+F1zT7xVgw9ErQoEI5CUdpK2nS1LiFTtJxsCu0NdNI2F3EMETXhWFXFqC1LVJkFqUaIy4@vger.kernel.org, AJvYcCXt7UEGVDDqQe04zIRCzlieni9zoFI8fDx29/wnyJrEB6KUcc85kM2L2dWHtl5utPRBhp/MWDKb7d+v@vger.kernel.org X-Gm-Message-State: AOJu0Yy2e2CO6psPfptuQ7khEj1M9qPGjDubqwr274T4AlbCI9WDNCYG Pp0VPscfuNf2d8g6qX/kU5OKQOAI809bWLsiYQc+MP0uBu0b2/TsfdeCVwfF X-Google-Smtp-Source: AGHT+IEOBugJZVxAAB70AO/HZqDfhHLexouLS4frx+Bu0kyOUCGEfddPd5eMYCno3hP2yYylfWFMRA== X-Received: by 2002:a17:907:c14:b0:a99:7539:2458 with SMTP id a640c23a62f3a-a99b95ee9f8mr18638466b.65.1728594041058; Thu, 10 Oct 2024 14:00:41 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:7eab:ec9d:62da:64f5]) by smtp.googlemail.com with ESMTPSA id a640c23a62f3a-a99a7f25f4dsm135692566b.68.2024.10.10.14.00.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 14:00:40 -0700 (PDT) From: vamoirid To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: vassilisamir@gmail.com, anshulusr@gmail.com, gustavograzs@gmail.com, andriy.shevchenko@linux.intel.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 01/13] iio: chemical: bme680: Fix indentation and unnecessary spaces Date: Thu, 10 Oct 2024 23:00:18 +0200 Message-ID: <20241010210030.33309-2-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241010210030.33309-1-vassilisamir@gmail.com> References: <20241010210030.33309-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Vasileios Amoiridis Fix indentation issues, line breaking and unnecessary spaces reported by checkpatch.pl. Signed-off-by: Vasileios Amoiridis --- drivers/iio/chemical/bme680_core.c | 33 ++++++++++++------------------ 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme6= 80_core.c index 5d2e750ca2b9..95a667d56527 100644 --- a/drivers/iio/chemical/bme680_core.c +++ b/drivers/iio/chemical/bme680_core.c @@ -224,7 +224,7 @@ static int bme680_read_calib(struct bme680_data *data, calib->res_heat_val =3D data->bme680_cal_buf_3[RES_HEAT_VAL]; =20 calib->res_heat_range =3D FIELD_GET(BME680_RHRANGE_MASK, - data->bme680_cal_buf_3[RES_HEAT_RANGE]); + data->bme680_cal_buf_3[RES_HEAT_RANGE]); =20 calib->range_sw_err =3D FIELD_GET(BME680_RSERROR_MASK, data->bme680_cal_buf_3[RANGE_SW_ERR]); @@ -294,8 +294,7 @@ static int bme680_get_t_fine(struct bme680_data *data, = s32 *t_fine) return 0; } =20 -static s16 bme680_compensate_temp(struct bme680_data *data, - u32 adc_temp) +static s16 bme680_compensate_temp(struct bme680_data *data, u32 adc_temp) { return (bme680_calc_t_fine(data, adc_temp) * 5 + 128) / 256; } @@ -445,12 +444,12 @@ static u32 bme680_compensate_gas(struct bme680_data *= data, u16 gas_res_adc, 2136746228u, 2147483647u, 2126008810u, 2147483647u, 2147483647u}; =20 - var1 =3D ((1340 + (5 * (s64) calib->range_sw_err)) * - ((s64) lookupTable[gas_range])) >> 16; + var1 =3D ((1340 + (5 * (s64)calib->range_sw_err)) * + ((s64)lookupTable[gas_range])) >> 16; var2 =3D ((gas_res_adc << 15) - 16777216) + var1; var3 =3D ((125000 << (15 - gas_range)) * var1) >> 9; var3 +=3D (var2 >> 1); - calc_gas_res =3D div64_s64(var3, (s64) var2); + calc_gas_res =3D div64_s64(var3, (s64)var2); =20 return calc_gas_res; } @@ -468,7 +467,7 @@ static u8 bme680_calc_heater_res(struct bme680_data *da= ta, u16 temp) if (temp > 400) /* Cap temperature */ temp =3D 400; =20 - var1 =3D (((s32) BME680_AMB_TEMP * calib->par_gh3) / 1000) * 256; + var1 =3D (((s32)BME680_AMB_TEMP * calib->par_gh3) / 1000) * 256; var2 =3D (calib->par_gh1 + 784) * (((((calib->par_gh2 + 154009) * temp * 5) / 100) + 3276800) / 10); @@ -571,9 +570,8 @@ static int bme680_chip_config(struct bme680_data *data) int ret; u8 osrs; =20 - osrs =3D FIELD_PREP( - BME680_OSRS_HUMIDITY_MASK, - bme680_oversampling_to_reg(data->oversampling_humid)); + osrs =3D FIELD_PREP(BME680_OSRS_HUMIDITY_MASK, + bme680_oversampling_to_reg(data->oversampling_humid)); /* * Highly recommended to set oversampling of humidity before * temperature/pressure oversampling. @@ -587,8 +585,7 @@ static int bme680_chip_config(struct bme680_data *data) =20 /* IIR filter settings */ ret =3D regmap_update_bits(data->regmap, BME680_REG_CONFIG, - BME680_FILTER_MASK, - BME680_FILTER_COEFF_VAL); + BME680_FILTER_MASK, BME680_FILTER_COEFF_VAL); if (ret < 0) { dev_err(dev, "failed to write config register\n"); return ret; @@ -664,8 +661,7 @@ static int bme680_read_temp(struct bme680_data *data, i= nt *val) return IIO_VAL_INT; } =20 -static int bme680_read_press(struct bme680_data *data, - int *val, int *val2) +static int bme680_read_press(struct bme680_data *data, int *val, int *val2) { int ret; u32 adc_press; @@ -684,8 +680,7 @@ static int bme680_read_press(struct bme680_data *data, return IIO_VAL_FRACTIONAL; } =20 -static int bme680_read_humid(struct bme680_data *data, - int *val, int *val2) +static int bme680_read_humid(struct bme680_data *data, int *val, int *val2) { int ret; u32 adc_humidity, comp_humidity; @@ -706,8 +701,7 @@ static int bme680_read_humid(struct bme680_data *data, return IIO_VAL_FRACTIONAL; } =20 -static int bme680_read_gas(struct bme680_data *data, - int *val) +static int bme680_read_gas(struct bme680_data *data, int *val) { struct device *dev =3D regmap_get_device(data->regmap); int ret; @@ -889,8 +883,7 @@ int bme680_core_probe(struct device *dev, struct regmap= *regmap, data->heater_temp =3D 320; /* degree Celsius */ data->heater_dur =3D 150; /* milliseconds */ =20 - ret =3D regmap_write(regmap, BME680_REG_SOFT_RESET, - BME680_CMD_SOFTRESET); + ret =3D regmap_write(regmap, BME680_REG_SOFT_RESET, BME680_CMD_SOFTRESET); if (ret < 0) return dev_err_probe(dev, ret, "Failed to reset chip\n"); =20 --=20 2.43.0 From nobody Wed Nov 27 08:38:16 2024 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (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 C92ED1E32C5; Thu, 10 Oct 2024 21:00:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728594045; cv=none; b=UcMubBfS0wayQ/wbiVos7939BszwHlay3+dRAUKGURUzEKzTXosZS9BAtCEmXso4dYQMN1BQh5qmEuWbgmXtdUPKnNudTCigoqbQkwrKbxFj1aRxYygvaqHk9rs3L9F+auQmK42relB9+4ujAfqC4R3d2hLlXp+jeBH56xJkcq8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728594045; c=relaxed/simple; bh=iKTRy0aDM408uDEmw7iLMEgjvmH3/uZ18u6w+pTuA74=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YLvCguMOcZa9m53Wx/VupM/7J1FURE/2/rmErU+braDCx8XuHBWwzGAnQ7din1rqcO8UyKHCHjyLD3tcRGbmDuvn7M0T8bJ56Mr+IPAPZ3ufS/+iZYuPMEBIioNlZh/oMdxu95BA9jceKeIewi/yyJu26ClTF6U5hI+ewOpu8UU= 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=An+87Pix; arc=none smtp.client-ip=209.85.218.53 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="An+87Pix" Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a7aa086b077so191636866b.0; Thu, 10 Oct 2024 14:00:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728594042; x=1729198842; 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=oj9FEguQeIhPDoauA44sn2NVEjEECXnJNgAQD1U0eNc=; b=An+87Pixt9xoDu9pnHlMtGqjEPvEE9XEL2XzXAJKMdvjty88ZHpMGgxr7y9aVf1KX5 KBRrYKAV49pps418EwAS5pH0I17srlkJciCCg+Ga/fX1aBfLD8xhmOTX3ejmllpmvXWe eUXAxTj0O3un8rXJHVx7qhvQPcdtDJsJfdaj4J6e4R29VIYqIdjsGdKmZjyo5YAt2EFW wvLCQRR+FlQcsPY5GhyZMIFZlFX0MwIgEiFZwp14EEQNoP+zKVLy6cI1lqb73WK/c5ep bHRbrmPj02TOt9rIj6qZAP19hy78EDluHS6TTFEJCHpgZYCK444HoC2gGZ2vVBVvtU8W CzbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728594042; x=1729198842; 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=oj9FEguQeIhPDoauA44sn2NVEjEECXnJNgAQD1U0eNc=; b=lXj5Ewrj79Yu9+/+UdLYohThAQ3vz8HCKA8tAOTuC1uJXm32ZbnH7MJeaatBXGrUzX Zh3n4GjjHssoCS/ySYYZsfKcdPWmSv9vJApbdkCzayS/Fx8NPueiQ3HVFeadima32PMl jUsS9LiGiTUhPl2iWaPEc1u1EDCd7EzUJwjiLxCE/wMGNgqkvu1nxY9PS5qDJO7l7LMJ 1NhSCoK9xgNeGrV2Ur85dp6uQ96Yrqf6Y83m2xga8YLD6MXETEI130j0qsZNZ9QNkvlt Qy1qfISHJCQltQod7yaHFyYBCgF+KnX2/EkpHjHW+/xu+ErYpuuSupb2K8NGBaPHBTis nhlA== X-Forwarded-Encrypted: i=1; AJvYcCUoBkpO0aILGbEyfY5VkZWHedM5DqzQ0TnsrNR26xOC3UYpEko6AmKh874ZBLSYgAtAcfcvLkNDC2o5C0lH@vger.kernel.org, AJvYcCW5hR2r2DK65m6H3FEdgEZ/MvEZlg7SHUrf2PAKX6I9mg/Wq+uVwoWgG0RAWyZ4u2vqExNqsgful7/3@vger.kernel.org, AJvYcCXyPViBfM1uaRYTwZsbcTsIJu3uLMLnapMlr6lENeGwsBJF8A5c6mixWcyYyFmb0lMa9KciIjZn8uJz@vger.kernel.org X-Gm-Message-State: AOJu0YwzHJdMO2dFeSAOSObTcDQS3OFiiVUY9ed9D/hfY6tbjPpnpD5H OGG3h4WkiGr/TKPov3DDV+psSI8bAQu1beW7vZyguJi8F6UKYLqm X-Google-Smtp-Source: AGHT+IHhc3zwF7g4i1T1QHEyvjDNcxiXcznQTAy1FhhK0dZOSLvzXSBukZcPWKZeGYK0IHISNFvntg== X-Received: by 2002:a17:907:7ea1:b0:a99:7959:8137 with SMTP id a640c23a62f3a-a99b93071acmr29628066b.2.1728594041986; Thu, 10 Oct 2024 14:00:41 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:7eab:ec9d:62da:64f5]) by smtp.googlemail.com with ESMTPSA id a640c23a62f3a-a99a7f25f4dsm135692566b.68.2024.10.10.14.00.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 14:00:41 -0700 (PDT) From: vamoirid To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: vassilisamir@gmail.com, anshulusr@gmail.com, gustavograzs@gmail.com, andriy.shevchenko@linux.intel.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 02/13] iio: chemical: bme680: avoid using camel case Date: Thu, 10 Oct 2024 23:00:19 +0200 Message-ID: <20241010210030.33309-3-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241010210030.33309-1-vassilisamir@gmail.com> References: <20241010210030.33309-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Vasileios Amoiridis Rename camel case variable, as checkpatch.pl complains. Signed-off-by: Vasileios Amoiridis --- drivers/iio/chemical/bme680_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme6= 80_core.c index 95a667d56527..3b4431998ca4 100644 --- a/drivers/iio/chemical/bme680_core.c +++ b/drivers/iio/chemical/bme680_core.c @@ -437,7 +437,7 @@ static u32 bme680_compensate_gas(struct bme680_data *da= ta, u16 gas_res_adc, u32 calc_gas_res; =20 /* Look up table for the possible gas range values */ - static const u32 lookupTable[16] =3D {2147483647u, 2147483647u, + static const u32 lookup_table[16] =3D {2147483647u, 2147483647u, 2147483647u, 2147483647u, 2147483647u, 2126008810u, 2147483647u, 2130303777u, 2147483647u, 2147483647u, 2143188679u, @@ -445,7 +445,7 @@ static u32 bme680_compensate_gas(struct bme680_data *da= ta, u16 gas_res_adc, 2147483647u, 2147483647u}; =20 var1 =3D ((1340 + (5 * (s64)calib->range_sw_err)) * - ((s64)lookupTable[gas_range])) >> 16; + ((s64)lookup_table[gas_range])) >> 16; var2 =3D ((gas_res_adc << 15) - 16777216) + var1; var3 =3D ((125000 << (15 - gas_range)) * var1) >> 9; var3 +=3D (var2 >> 1); --=20 2.43.0 From nobody Wed Nov 27 08:38:16 2024 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (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 335911E47B0; Thu, 10 Oct 2024 21:00:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728594046; cv=none; b=FAslpjeyhozNeahYqksqftGQkLIq3Tqzor4aHYWCYjyuPNR+2+XQHJfVOOCSEXryCu5MhaCnfjIPforSBA2uHx5HRFKR7R7UiOzF+5XydOWfb4frpyedPBUsjjJZBhGEsK94KjJZKSOAV7DNl1GndRhoJeUVXC19F08oyPDdt5g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728594046; c=relaxed/simple; bh=Atvk271s1uf9rHfU9zdJgtPZZlF+DI0XgO+2rmYv/Wo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LicPy3mN2sQRucQtnVdVAIpnmAc2mof2HKVA38Indy4XMXIJb5Id235N4dJ0U6u4tp9EJh4yEPIcQht+KSe3CojYcEx3b6G3lcySZ7msPgTBhEKgZuV1RHmQt7dG6qiIuOBeSCILJam1sfCVxwdgzlpljtCt3siflEUq/qZduqc= 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=fUtByDHX; arc=none smtp.client-ip=209.85.218.43 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="fUtByDHX" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a999521d0c3so229807266b.1; Thu, 10 Oct 2024 14:00:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728594043; x=1729198843; 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=QQCESS3HWEnQ/klZmdeVKbDR/Rh9U3qG2a1+qMswy3M=; b=fUtByDHX9aq5YUOT/fDaZZ8voRSjYAMeNnGFMgtQQAVFB08eWMJGN5iVE90ZR5ar3e JmG3KgKIwvItclYOQ6onYdgPoJUKcZQAIAT4c4UcExGdZYqRg2PtLM+5DAOr5Pm7k11r 7Y2Dv9MZAL8qxhAzABn4NyjKFx9wfWo4I3s4lXBPmNuOQhNABdlVHYhzbTbK9gnPBBLq 0x6Ue4dLPOxYNdsDda1K8UDhm7oH7gjPcRDg8nPfRKK6IHWveImqY7LuwOk7SKv14CtM fCqeZz/s8ClLPhnDzenvUI4wK6OotcCxKXku++uiLVuiZ1ITjZOuzJuGjpzVsIZSnOen S/8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728594043; x=1729198843; 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=QQCESS3HWEnQ/klZmdeVKbDR/Rh9U3qG2a1+qMswy3M=; b=U26++8xUY7OyKoYXU4AocnWllrmzS0Sr9Lebyv18zSOsjtZy+XzgHu6DHTnlrqBIlq 5ofbPe60qGsbxOFF+mATUOjQHip+sHMT19eIDp5JDrfF/bwrKXoEgvvQxqMza68Zod5u EW35ko5C/jkPHTBPIGMeWSL486MRvzzaS3vWtPGCCW0DZfshRVHlvyVQCM9KgE3TBNyS pzJyohfKUds0VqiqD5LJfMsBr24PxRQMlLrlX/mrKXLcKrwvdk9O0lFKZULCAh0X90W5 yuvhrbUOSHAF36VxKDvQdJGHQRgSt3frNfrJJKBpDAcb2PzMJHmmGhR0NRUbTPtcznpx 4tyA== X-Forwarded-Encrypted: i=1; AJvYcCU6tqR+re/5U+B1U9o56+d+HKX/pfG34XDgBTMY/m5eymzR1QRU+KO9FyTKMAo0LZvszqZcxuKnU4qV@vger.kernel.org, AJvYcCULgEzT8fQPGPpowV9fCN8j5Wxtk36M9UcMDCYk2H8ewd621i62LeART8X0yhCT+c65Ih3I9FtT3dsu@vger.kernel.org, AJvYcCXCLdH3SzjvpkbQbELgNDSlh8h86rUWb3eXoTo/szoI+Yvw+05xj/LFK9HVnqMk1hUyyzjrznZtuOfcNeV9@vger.kernel.org X-Gm-Message-State: AOJu0YxJqV9SEGcg7UIlC4kEisnEMj/wbORKe3JYXQfIFyHOlWy4axQJ jxJsP2hwib2Qy1Ule6DNXeX5k1dIpPOU4xwd86akXgnQSoJHZnWW X-Google-Smtp-Source: AGHT+IGVF4ZA39rktwlsytewTYF4NDwOe2BprbzFbGpjmIRgWI0oVPdbNeSa3zkwu4n8w4YnTQZ3+Q== X-Received: by 2002:a17:907:9484:b0:a99:59c6:3265 with SMTP id a640c23a62f3a-a99b93697cbmr23156666b.9.1728594043225; Thu, 10 Oct 2024 14:00:43 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:7eab:ec9d:62da:64f5]) by smtp.googlemail.com with ESMTPSA id a640c23a62f3a-a99a7f25f4dsm135692566b.68.2024.10.10.14.00.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 14:00:42 -0700 (PDT) From: vamoirid To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: vassilisamir@gmail.com, anshulusr@gmail.com, gustavograzs@gmail.com, andriy.shevchenko@linux.intel.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 03/13] iio: chemical: bme680: fix startup time Date: Thu, 10 Oct 2024 23:00:20 +0200 Message-ID: <20241010210030.33309-4-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241010210030.33309-1-vassilisamir@gmail.com> References: <20241010210030.33309-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Vasileios Amoiridis According to datasheet's Section 1.1, Table 1, the startup time for the device is 2ms and not 5ms. Signed-off-by: Vasileios Amoiridis --- drivers/iio/chemical/bme680.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/chemical/bme680.h b/drivers/iio/chemical/bme680.h index b2c547ac8d34..e55a48982b3e 100644 --- a/drivers/iio/chemical/bme680.h +++ b/drivers/iio/chemical/bme680.h @@ -63,7 +63,7 @@ =20 #define BME680_MEAS_TRIM_MASK GENMASK(24, 4) =20 -#define BME680_STARTUP_TIME_US 5000 +#define BME680_STARTUP_TIME_US 2000 =20 /* Calibration Parameters */ #define BME680_T2_LSB_REG 0x8A --=20 2.43.0 From nobody Wed Nov 27 08:38:16 2024 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.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 170901E5707; Thu, 10 Oct 2024 21:00:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728594047; cv=none; b=snOw5TjbrwXyDDDKYAzrvYFnWUFemEm9t1SS1i5PqwDi0n+FuJkGdfe/4vHyOR+idtK2I4U4A12DSRwzwAkrfRch/PjveLmb8XW7A5TiCqTY2GB6+99+aRArP9rEAAZjDWd+HcznNE721C4hft9IrYPjPv75adn9u0z+hQGhA+w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728594047; c=relaxed/simple; bh=AuaAMGazf6D8nta5WHF12q2hhimpf8Onr02Dd4mTI1Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bYMIzv/69Wv2WxNF3ENUv8tfLFsnX1vsLq4tWgC5QaDOJlFzdxVQs2YvWBFwAkO7oAX/xwiyDO6WviKGvX+j0E9hpGS6DKMgkA7tmopfAECyEWsb2IQkPVziX5APwjJx1VO3m9uqatTekIZ5xDSuCVgeFr/HglboXRPZE9BIiiI= 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=FVfpJYoD; arc=none smtp.client-ip=209.85.218.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="FVfpJYoD" Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a9944c4d5d4so196126166b.0; Thu, 10 Oct 2024 14:00:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728594044; x=1729198844; 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=LtAYLbt/L++y5ER8m5fhu82PiDUM06VjetwOClPVgAc=; b=FVfpJYoD/V7NW//lrL4ApWI4OmRzD2lQrPFR8tRhP7o83i4JN0MsgEZCuhwsVcYxDj MxYceDX2H0X4CdPh8eVBi0hzE3B3ZBZTtl0FzUnvZyRV/uDabPl/fXQBnRlMaB0V7P1e kG6xpWqXj4KzzAQDKjeJ3EOoSM/dYEDdxa5FW6n3BFzH1WhuEZkSJ4oVT8VENe+/6oz7 9qc5I6n5uxR9EPyNqwxxYWcURsLv9llcrdyRhGlHdpQFtq7Zu3lBpP2IX58XG+Rh6A4R CKsUq0CZGIhCXbb4QzF27g0EELcCdl8MpIVb6eJYsnFWegFoPdMk17apGEF/kdY0tZ8g DN4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728594044; x=1729198844; 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=LtAYLbt/L++y5ER8m5fhu82PiDUM06VjetwOClPVgAc=; b=gyoLFIasn64TacoLqdv/V3XLod3sUI+X3QRAt25KzBAZUnZhhKQOLYKZoeXhocXZYI YNHcbrvYhqhgIqjJa0ureZ1s/ZE1kDAgKxAutHeY7Z6ZAqj6qRpgJkei0DoITpiWuQy0 oDuOHaged88Ao5r88XzgEvXo6rrjGE7UafDlXftIT1DmtFdI308P661ESM/wSGnUF76o 5EeFPhN+bNnLzchu+dQ5nXNFNDG+prndKxmteOnHTjje4PMexYJRyDuUEHSDYWcH40tR DJAJpptZHXQyaSHLY/4c40kTSj/eJd8JFFpq3lcVoY4R6OeNqCzn3bCdoEqc/odEilKK a/tQ== X-Forwarded-Encrypted: i=1; AJvYcCU/+5WMB8yHiaxDQOGSlNYRz/NExdaHg27Ry2z0lMtpP+qgf7Ds5Y7ASEa0YrISPs1fakugpwBhihiZ@vger.kernel.org, AJvYcCWllxAHDVn+g0qE/9FI3kJwRXlg3JDB5fjwjs/AX1vfmcYPYKK0fwL6AAoJLGFEwoHniA1ARpP2POGI@vger.kernel.org, AJvYcCXsmiFhogq4RGlJ2Jk+U9ftQVBYyMQcFJ7Sh4rmQywkcjqS/dLLRjisap/GFiYSTWT0Ivyk+d+Ezs6HkSAr@vger.kernel.org X-Gm-Message-State: AOJu0YyhpRsAjhSa4oh0SQDvrvhpX+DB21dUYqQaSjMivr3XUNBX1XAG UrdicFg3GmFqZtzOwGs6r0GihB2RT5cJTcUmGFG91ADnx119TYr2 X-Google-Smtp-Source: AGHT+IFPqxYDkOvQOMMOFfLVz6YCBx3ZxfqLb+syFcib5ZBg4/3pNi67Fy8B699KHaXfe+dD8Ky7ow== X-Received: by 2002:a17:907:7b8e:b0:a99:537d:5d10 with SMTP id a640c23a62f3a-a99b8e935e4mr27511866b.0.1728594044105; Thu, 10 Oct 2024 14:00:44 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:7eab:ec9d:62da:64f5]) by smtp.googlemail.com with ESMTPSA id a640c23a62f3a-a99a7f25f4dsm135692566b.68.2024.10.10.14.00.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 14:00:43 -0700 (PDT) From: vamoirid To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: vassilisamir@gmail.com, anshulusr@gmail.com, gustavograzs@gmail.com, andriy.shevchenko@linux.intel.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 04/13] iio: chemical: bme680: move to fsleep() Date: Thu, 10 Oct 2024 23:00:21 +0200 Message-ID: <20241010210030.33309-5-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241010210030.33309-1-vassilisamir@gmail.com> References: <20241010210030.33309-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Vasileios Amoiridis Use the new fsleep() function in the remaining driver instances. Signed-off-by: Vasileios Amoiridis --- drivers/iio/chemical/bme680_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme6= 80_core.c index 3b4431998ca4..9e843e463502 100644 --- a/drivers/iio/chemical/bme680_core.c +++ b/drivers/iio/chemical/bme680_core.c @@ -545,7 +545,7 @@ static int bme680_wait_for_eoc(struct bme680_data *data) data->oversampling_humid) * 1936) + (477 * 4) + (477 * 5) + 1000 + (data->heater_dur * 1000); =20 - usleep_range(wait_eoc_us, wait_eoc_us + 100); + fsleep(wait_eoc_us); =20 ret =3D regmap_read(data->regmap, BME680_REG_MEAS_STAT_0, &data->check); if (ret) { @@ -887,7 +887,7 @@ int bme680_core_probe(struct device *dev, struct regmap= *regmap, if (ret < 0) return dev_err_probe(dev, ret, "Failed to reset chip\n"); =20 - usleep_range(BME680_STARTUP_TIME_US, BME680_STARTUP_TIME_US + 1000); + fsleep(BME680_STARTUP_TIME_US); =20 ret =3D regmap_read(regmap, BME680_REG_CHIP_ID, &data->check); if (ret < 0) --=20 2.43.0 From nobody Wed Nov 27 08:38:16 2024 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (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 AD8591E7C1A; Thu, 10 Oct 2024 21:00:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728594049; cv=none; b=bBFw+MDtorXuZdpTA/Qt/CZtTnMpdKy+vBSWNRIKzoQSeP3yuPE3Wr8IxggeqrMKWlDZEWv098lAL2eYplKyZEPweEuIMtenBxF+Nk0RecBSBXiujK317KKFADr+aBh3WmkDUy+t8VfHfwwrY+FHJO9y8NYrI7Q3uM3N0C2iZ6w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728594049; c=relaxed/simple; bh=Wa3EYI791Z6QvQ8LVPrmstMIWkKWiIKJHhi8ABqUJd4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rC14ODC0fwi0Qn1OR9NQCsZeErMUqhfOwuLy4SdSwslruSquf9QDKBeiEoGNq7H7aiFZ+7c1p0h74viwkoNxD9Onjo8ZQoCEgvWpwuATehuKWN3x5pDxO11HOB2Nl49Wfiok7jA+psFQYKpEHkX8+EyfPI8m1ZvY2+XqCVzCCes= 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=mCTdCR7Q; arc=none smtp.client-ip=209.85.218.43 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="mCTdCR7Q" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-a7aa086b077so191647066b.0; Thu, 10 Oct 2024 14:00:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728594046; x=1729198846; 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=a+jQJSYyyk24bPlVarRgFu0Ib7+Yu24U/ZAJcxgJYmk=; b=mCTdCR7QV6XZUsTcGRuUb7yrN36wov/QJyk0O4lc3uo+/xR6vuNYhb0GhXowbxtSAp zJtQDSBRVBgSEcchcxzVtJ0IOfL7xDQLF73uy5s2vDkcAdBHNa5vVs5HqqftiZty3+0S MxQx8dZVAwCZZtJ8jtcA1Tqx9g085E3m9wg4HyZhrxZVxH1EsKKNjxdVSrtC2EhI8nX2 afPbGkHl4a1BaOZ0jugSyxysAUn62yk6rtNdUNhsa4zTo4JFbMqNrYanWvcl4mZG5AL4 i2CpfgNbZ8ujpSLGzqi69djZDRA9xnHRvBCLMSTyx6Epr+n9VbP1mv3YewBlMeb/Sq4m ExCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728594046; x=1729198846; 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=a+jQJSYyyk24bPlVarRgFu0Ib7+Yu24U/ZAJcxgJYmk=; b=CjjLC8qtgvOADk8GomUwLytpFbG7XB7LTiaM1n3z19lCkEmx8mo8cqtYUKxghh4Kca Rr9vja0w5M+TnKoSkpJllYZUXLMfH1hnTqDeKT2t16dbw289ujEurDSU41+PyPC7wk3f dU1IJxg2gRmecdT5YpGEzYDHMlFFZIhMz1RuY709KTzUbD8DbKqHIUSQdVg4Ie+d2Pow 7x/U3YEKXGu4EkWx8rGpPvJ6+GjdEkMHV68OKEO85oooalJi2F4E32TT5kiL9A1AcGfv uuZK82qmN8i8r5G61zRlcqc3gVaQrTOeOSEPl0ZM4WoJjoYgZF/VgHDChMqoz5PYHF+j vQNw== X-Forwarded-Encrypted: i=1; AJvYcCXFzeyjmIVBztOCbiDGgCn78Vm9/kKpJ/Wm3L5rZDes5knakqpcJDruHDRJIOYzS3Y6Rxv/NDvRa6gh@vger.kernel.org, AJvYcCXMlI1nN1znnIX6ypNd0v/NGRX6qUxgeCk3MaIQGXi/PN/AkNSwoyLnXfXpfRThy7oRP6ovCrgZe5zBQ4w1@vger.kernel.org, AJvYcCXhguyt2Y2FrEu6jM9zfRsmqtDbdWWJemG+OP3Zn/Rp46i7YL0WHWnNpNjM8CQTWkw9W02hxOxFbWec@vger.kernel.org X-Gm-Message-State: AOJu0Yw4x9LffuGURNx4xYYOCYgwAjFmcgtXDufQf3p8CXpOBP3nYmGG 39/tnJuEkdkL/OyTaySf3D1HM09ideJXMKVDfpquyXDICLyFlJYAqSCacF73 X-Google-Smtp-Source: AGHT+IGvQ/rgjjoxIz3BxKyQtThZ405yt7y5MZUKMBCCdCpKeEwq4EJRK+REY2FLNqRk86IEBfWOoQ== X-Received: by 2002:a17:907:3f28:b0:a99:3802:1c37 with SMTP id a640c23a62f3a-a99b937a670mr22344666b.20.1728594045848; Thu, 10 Oct 2024 14:00:45 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:7eab:ec9d:62da:64f5]) by smtp.googlemail.com with ESMTPSA id a640c23a62f3a-a99a7f25f4dsm135692566b.68.2024.10.10.14.00.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 14:00:44 -0700 (PDT) From: vamoirid To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: vassilisamir@gmail.com, anshulusr@gmail.com, gustavograzs@gmail.com, andriy.shevchenko@linux.intel.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 05/13] iio: chemical: bme680: refactorize set_mode() mode Date: Thu, 10 Oct 2024 23:00:22 +0200 Message-ID: <20241010210030.33309-6-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241010210030.33309-1-vassilisamir@gmail.com> References: <20241010210030.33309-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Vasileios Amoiridis Refactorize the set_mode() function to use an external enum that describes the possible modes of the BME680 device instead of using true/false variables for selecting SLEEPING/FORCED mode. Signed-off-by: Vasileios Amoiridis --- drivers/iio/chemical/bme680_core.c | 36 ++++++++++++++++-------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme6= 80_core.c index 9e843e463502..dedb7edaf43d 100644 --- a/drivers/iio/chemical/bme680_core.c +++ b/drivers/iio/chemical/bme680_core.c @@ -95,6 +95,11 @@ struct bme680_calib { s8 range_sw_err; }; =20 +enum bme680_op_mode { + BME680_SLEEP, + BME680_FORCED, +}; + struct bme680_data { struct regmap *regmap; struct bme680_calib bme680; @@ -501,25 +506,24 @@ static u8 bme680_calc_heater_dur(u16 dur) return durval; } =20 -static int bme680_set_mode(struct bme680_data *data, bool mode) +static int bme680_set_mode(struct bme680_data *data, enum bme680_op_mode m= ode) { struct device *dev =3D regmap_get_device(data->regmap); int ret; =20 - if (mode) { - ret =3D regmap_write_bits(data->regmap, BME680_REG_CTRL_MEAS, - BME680_MODE_MASK, BME680_MODE_FORCED); - if (ret < 0) - dev_err(dev, "failed to set forced mode\n"); - - } else { - ret =3D regmap_write_bits(data->regmap, BME680_REG_CTRL_MEAS, - BME680_MODE_MASK, BME680_MODE_SLEEP); - if (ret < 0) - dev_err(dev, "failed to set sleep mode\n"); - + switch (mode) { + case BME680_SLEEP: + case BME680_FORCED: + break; + default: + return -EINVAL; } =20 + ret =3D regmap_write_bits(data->regmap, BME680_REG_CTRL_MEAS, + BME680_MODE_MASK, mode); + if (ret < 0) + dev_err(dev, "failed to set ctrl_meas register\n"); + return ret; } =20 @@ -612,8 +616,7 @@ static int bme680_gas_config(struct bme680_data *data) int ret; u8 heatr_res, heatr_dur; =20 - /* Go to sleep */ - ret =3D bme680_set_mode(data, false); + ret =3D bme680_set_mode(data, BME680_SLEEP); if (ret < 0) return ret; =20 @@ -750,8 +753,7 @@ static int bme680_read_raw(struct iio_dev *indio_dev, =20 guard(mutex)(&data->lock); =20 - /* set forced mode to trigger measurement */ - ret =3D bme680_set_mode(data, true); + ret =3D bme680_set_mode(data, BME680_FORCED); if (ret < 0) return ret; =20 --=20 2.43.0 From nobody Wed Nov 27 08:38:16 2024 Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.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 060C01E885C; Thu, 10 Oct 2024 21:00:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728594050; cv=none; b=TPGq6NBmu+YM3bsNIbGG0W4Lt/dj5iEX5RnOKM5AWQKBbuMlZ3M8g2qRzglc9lb2CA6ntOaELhSOfQQWKXSjPwKjHuda/nGeov7KaxaehUXCLWrU0hJ3mA/3Z5ekJ/ZDsGHC10klUXTGhmxzYx5zM4+YeODQ/rStEsxbRZDNNeQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728594050; c=relaxed/simple; bh=H/Oh3NFQCKsLBwWTyouem7Lo9ZCIqcLfvcnpwANSZIo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k1/YzNkadiQlhl1xY9tC430N3R7Xp2rBk8S1EWUTw0VWWgH5Wc9zOEAzos7koQb4ceYQ825eEmxIxS86dK032fwt0+A2wvCKB8vs0HEAWsKH8JLmJofwIUrwROtdfHpopB7USrOkBHPlxm+loFHcplJe3jIKne2bYHgBlVzuBaY= 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=QEmucd58; arc=none smtp.client-ip=209.85.167.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="QEmucd58" Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-53997328633so2275075e87.3; Thu, 10 Oct 2024 14:00:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728594047; x=1729198847; 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=DSdbgLR24cpkLSskWjqR+dewrFXV8LMYuCQdNklHO0Q=; b=QEmucd58RKwihdMOUAMDtjLjUKIkaJUuGTS+dUEtQv2bnSjyl4T7x1eMXoFzzC8lZd +BeSQEQguwQo7hF9uxl9Ehgk6qvOJ4AdBTZ+bdAfSxzN7FlS/9HglbCfOZZ7NBJmwcck kvvS1zeRTiowP2IHcNguOQwWJTptM/y0p0y3pD6T7mlRzb4dRfJV6G5WmAcFJhaG5t33 C7ciC9UzjfA/UM9S2Zz4x1La8ZZyvKMaX799MUtCvim8KSvaPh0ALi1UUYp23S7S1PdE qYHLTd8qywESLnyQzUq1p8oFmjDvY7Z6/5D9OBw2Bmxzx21vxYLmFdXN7yrUj9Svdj76 0wfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728594047; x=1729198847; 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=DSdbgLR24cpkLSskWjqR+dewrFXV8LMYuCQdNklHO0Q=; b=sa7gsD3XvdRl9ImsuixEH0Hhj/RCGT05IoacsTiWJmud6dPFYfNWBylArVKvWBK4Th ec4u9GkC6dBXpBubUbcb34qCDo6JfkZJn78OfJ8JMlnqXhMLa6aMkrvobcAyf/uCIn8N oVt8fQNcxUM/tT0EhQu+3aN/LNbHwRuXreDnrfuqHHgyoLf+OiCtV7dOgCVJG0kKDqk3 1DzrIG3Gg6F9DHdsc7+Ibe1fOkghMSwaokmXxeHTg5l+cDmn424woLyUBqQldZVbidEJ kTzuSlDqO8qNuQN3jcSi3zrZleXbvhtcGdZYbcdr6Qy7Iu8eaXGV7v2i5R/oSMD44Fdk TcHA== X-Forwarded-Encrypted: i=1; AJvYcCUKrAfGtAY92NF0rnhyRWX/KcED5GJ9+oUxbZrURjNr0DBPUmQ7zJjYhOoDOz3kc4yzeNh4Zcxv29Qx@vger.kernel.org, AJvYcCUpvSMlmX5Af6PaeTpfchaHvWHF7asZB5R++kKEEw67v+11PZySnFhxZM8oY3GP5MOn76g6y/OeJ069@vger.kernel.org, AJvYcCV30fFj2WfvwJLZKUhgQd2AKTtAkcv6zF1UxV0uRD45w2yeZz6Xc/13ndKgO8Rcpw/1hUwS1/1EJdBPjEdL@vger.kernel.org X-Gm-Message-State: AOJu0YwUV+mbs8qFp5c1okVLLajPdR9EumydIDuROkiuJVCevAocHUbW 0fcMzeUqrpzuKSFHy+3sDQHmKwm844mL0gUS+99YPYn6Ciuhs5lf X-Google-Smtp-Source: AGHT+IGhdis3wyOKJ+ndw5mOYpSKkBD3jsMxZnwSv1fyhvFpI3trQbf1Z/e5f+NT8pNSbAru0E2b5g== X-Received: by 2002:a05:6512:3c9f:b0:536:a4f1:d214 with SMTP id 2adb3069b0e04-539da3c4ba5mr112324e87.19.1728594047042; Thu, 10 Oct 2024 14:00:47 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:7eab:ec9d:62da:64f5]) by smtp.googlemail.com with ESMTPSA id a640c23a62f3a-a99a7f25f4dsm135692566b.68.2024.10.10.14.00.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 14:00:46 -0700 (PDT) From: vamoirid To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: vassilisamir@gmail.com, anshulusr@gmail.com, gustavograzs@gmail.com, andriy.shevchenko@linux.intel.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 06/13] dt-bindings: iio: add binding for BME680 driver Date: Thu, 10 Oct 2024 23:00:23 +0200 Message-ID: <20241010210030.33309-7-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241010210030.33309-1-vassilisamir@gmail.com> References: <20241010210030.33309-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Vasileios Amoiridis Add dt-binding for BME680 gas sensor device. The device incorporates as well temperature, pressure and relative humidity sensors. Signed-off-by: Vasileios Amoiridis --- .../bindings/iio/chemical/bosch,bme680.yaml | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/chemical/bosch,bm= e680.yaml diff --git a/Documentation/devicetree/bindings/iio/chemical/bosch,bme680.ya= ml b/Documentation/devicetree/bindings/iio/chemical/bosch,bme680.yaml new file mode 100644 index 000000000000..e54df3afa7b2 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/chemical/bosch,bme680.yaml @@ -0,0 +1,64 @@ +# 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 pres= sure, + ambient temperature and gas (VOC - Volatile Organic Compounds) measureme= nts. + + https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheet= s/bst-bme680-ds001.pdf + +properties: + compatible: + const: bosch,bme680 + + reg: + maxItems: 1 + + vdd-supply: true + vddio-supply: true + +required: + - compatible + - reg + - vdd-supply + - vddio-supply + +allOf: + - $ref: /schemas/spi/spi-peripheral-props.yaml# + +unevaluatedProperties: false + +examples: + - | + i2c { + #address-cells =3D <1>; + #size-cells =3D <0>; + + bme680@77 { + compatible =3D "bosch,bme680"; + reg =3D <0x77>; + vddio-supply =3D <&vddio>; + vdd-supply =3D <&vdd>; + }; + }; + - | + spi { + #address-cells =3D <1>; + #size-cells =3D <0>; + + bme680@0 { + compatible =3D "bosch,bme680"; + reg =3D <0>; + spi-max-frequency =3D <500000>; + vddio-supply =3D <&vddio>; + vdd-supply =3D <&vdd>; + }; + }; --=20 2.43.0 From nobody Wed Nov 27 08:38:16 2024 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 F22EC1E9088; Thu, 10 Oct 2024 21:00:49 +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=1728594051; cv=none; b=hSXM+Iou5yE+sybq/CsywpZqGDTTCS0bflT1ZjPEt1YHoJkQJMBv0HYNlwoWCXD5WcE3Ji/N8gD/G6K1QDTwGBrYZkwi1RZDT1dl3SbruQo7iID9obnMYAEq3WttQcVnuKrqEZN5zSZBVzMUB4Ox+2oV3jJWDHBVDwMh9qaCCzY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728594051; c=relaxed/simple; bh=/QcZtdu0B5tC/4wrcWlkpa4Yk5YtewNe0aUFngHHM5w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LAXy70nXahpru7SWTagQ2mQUQBP6BS9WLvU7neitZZVxsF34UljGJghOL/a7WgJqp5xduLqdCVX02NMuS5myhLDWW9XkhnavvDpXpUTaINL95jEaE5HfGjq/PTDOSNbHEjMmx65TF0Wu9fuLhnNJdDcfwpvaEApPK3PKLjkyD7o= 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=DJ2WLATE; 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="DJ2WLATE" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-5c941623a5aso1418752a12.0; Thu, 10 Oct 2024 14:00:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728594048; x=1729198848; 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=17TNCJpfLHjZg4gW7h+TPW4DXAtGpJiZu8iIf6mJ2M0=; b=DJ2WLATEZ/uhAnnOaRuMO2aKQxMXW3+QRE7zbYrC2bVBeQjvdvsP3Vrfgwd36UiMlL RAiES7EHlgPGPpKMvg3s8O1xd1Zh6WgtqtCBMOLUuUkLQnwiNwOszPS3avzueTpNG8kk TGD7K7fqz1z6y2xOESdHc+FxIymY1yihGs5PFkfYXRk2VmJzHXTe+meo4g6g4ZKdf0FS +EaaDXFTd8vsldHrp3yWLPPNzlQ1O5w0RMTuhWU9mhYfG6Dt0k3Dnr009WOlgfzZ0wb1 nGIOrqVB7S2Q7oa1ptADSDP7in6n8MsmZFw92xvj+xx+8vGPHuNmMEv1l6TF28s4abRH +JOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728594048; x=1729198848; 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=17TNCJpfLHjZg4gW7h+TPW4DXAtGpJiZu8iIf6mJ2M0=; b=NqxO4mvQdq6NeJQn/7/wVsC3syzPfvo5RNTuqeHkXBexwZEE+Cyhr8kYPAfFHKDUPo SJF8RfuY/PYpFHeJtXyZrYs/zVi7tWSABj6Q8mGOEsk3zaep2Cem9ViM45cJ0Cu19+Y4 NnpHl/PzDgz4HbJIxblQWu4tMhPc/Dq9eWlkiOYZJuIcy5x0DA1hxqVCK3oEImx2bTK5 7GtZEdl/qZBPcoIELuxVi9V174z2P/vwzF7dt5rTt77aLLhkKRTesiAh7f1wR2eWCrZ1 +dd4WKXb3qxmKB8aTAHeV2aug8ESCRt184/4q8bHfYlTXTG/4VKo+RJVPs6NuPUBvIDb yJ3A== X-Forwarded-Encrypted: i=1; AJvYcCUumAONpRMYOEnLFkzJSqSYnNj08vEeVOrlPxtFCFFZW5tA2volD9559JGIs25uIOcSVxGQrOegyTH7@vger.kernel.org, AJvYcCWwuVffjxacdK02K/qDldqctFBS3wweTzim56/HPCf+4P7mbTlfN5m2gdHfxgcJhOEkX09TPu3Hgz0x@vger.kernel.org, AJvYcCXDGhUk/1yZ4Qjom3NWRrVloYUcAjYcAt7NVi0WS0qNYVCcP4fQxII9dUqpIjuW6NksUUOPp6J9a9kUIgMb@vger.kernel.org X-Gm-Message-State: AOJu0YxiR+xKg+s+EWpeDLqAKvSot+55HUL2ki4JnM3W/9xQPqJ/QjXO +XUF3y1e5JirqMjXQgfjJ7LyG2W8qXislVUhwZ66+431fm68SRJd X-Google-Smtp-Source: AGHT+IGbHawTCqdN6NOMErufah9hSa6SJzwiswtAFtT2XrVu/3U9FN6Y3CJRXid66ABX/frGJtJ0DA== X-Received: by 2002:a17:907:6e9f:b0:a99:5171:7a44 with SMTP id a640c23a62f3a-a99a13e32b2mr289544566b.31.1728594048280; Thu, 10 Oct 2024 14:00:48 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:7eab:ec9d:62da:64f5]) by smtp.googlemail.com with ESMTPSA id a640c23a62f3a-a99a7f25f4dsm135692566b.68.2024.10.10.14.00.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 14:00:47 -0700 (PDT) From: vamoirid To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: vassilisamir@gmail.com, anshulusr@gmail.com, gustavograzs@gmail.com, andriy.shevchenko@linux.intel.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 07/13] iio: chemical: bme680: add regulators Date: Thu, 10 Oct 2024 23:00:24 +0200 Message-ID: <20241010210030.33309-8-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241010210030.33309-1-vassilisamir@gmail.com> References: <20241010210030.33309-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Vasileios Amoiridis Add support for the regulators described in the dt-binding. Signed-off-by: Vasileios Amoiridis --- drivers/iio/chemical/bme680_core.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme6= 80_core.c index dedb7edaf43d..a2039b966f20 100644 --- a/drivers/iio/chemical/bme680_core.c +++ b/drivers/iio/chemical/bme680_core.c @@ -15,6 +15,7 @@ #include #include #include +#include =20 #include #include @@ -100,6 +101,12 @@ enum bme680_op_mode { BME680_FORCED, }; =20 +static const char *const bme680_supply_names[] =3D { + "vdd", "vddio" +}; + +#define BME680_NUM_SUPPLIES ARRAY_SIZE(bme680_supply_names) + struct bme680_data { struct regmap *regmap; struct bme680_calib bme680; @@ -110,6 +117,8 @@ struct bme680_data { u16 heater_dur; u16 heater_temp; =20 + struct regulator_bulk_data supplies[BME680_NUM_SUPPLIES]; + union { u8 buf[3]; unsigned int check; @@ -857,6 +866,13 @@ static const struct iio_info bme680_info =3D { .attrs =3D &bme680_attribute_group, }; =20 +static void bme680_regulators_disable(void *data) +{ + struct regulator_bulk_data *supplies =3D data; + + regulator_bulk_disable(BME680_NUM_SUPPLIES, supplies); +} + int bme680_core_probe(struct device *dev, struct regmap *regmap, const char *name) { @@ -885,6 +901,20 @@ int bme680_core_probe(struct device *dev, struct regma= p *regmap, data->heater_temp =3D 320; /* degree Celsius */ data->heater_dur =3D 150; /* milliseconds */ =20 + regulator_bulk_set_supply_names(data->supplies, bme680_supply_names, + BME680_NUM_SUPPLIES); + ret =3D devm_regulator_bulk_get(dev, BME680_NUM_SUPPLIES, data->supplies); + if (ret) + return dev_err_probe(dev, ret, "failed to get regulators\n"); + + ret =3D regulator_bulk_enable(BME680_NUM_SUPPLIES, data->supplies); + if (ret) + return dev_err_probe(dev, ret, "failed to enable regulators\n"); + + devm_add_action_or_reset(dev, bme680_regulators_disable, data->supplies); + + fsleep(BME680_STARTUP_TIME_US); + ret =3D regmap_write(regmap, BME680_REG_SOFT_RESET, BME680_CMD_SOFTRESET); if (ret < 0) return dev_err_probe(dev, ret, "Failed to reset chip\n"); --=20 2.43.0 From nobody Wed Nov 27 08:38:16 2024 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (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 4BE4B1EABBD; Thu, 10 Oct 2024 21:00:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728594053; cv=none; b=Yowrce51JWdTWjDDO01UydCyu6nB85fXO8ekRkadQ/TaKtYxTeWx2VQzxI0TuNZok/5EjYl8Y3zsI7ex/HjZlSReq/nFTPKkb/JusvgbFp/Fd8gY6CItr40Z8ZttV0hayV3R00LUMFw+hFavWGlhX+0FrVjx9dHdQuRC9nXM6nU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728594053; c=relaxed/simple; bh=uGwAGY5iqtreG1Rl2Q91IZhfZ4uzMS1tFym9aD9lrZc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Tc3EpHLfu2lpqmMeJH2kHPNyUeyv2AAVP5LyGlnvfVLmxbwRryKCs1QWzcEM7Oj9XKHyeslLRjwKgtr7lgvcyOt4rlfisFcP4p/YuGgWZeAagkiQPMj2TwFkfjVGZZe9j8Sdhb52tqUa/PGpxMqAHyyBGDL99yfMQNaQalx5nnM= 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=jGNpw4Tw; arc=none smtp.client-ip=209.85.218.42 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="jGNpw4Tw" Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-a994ecf79e7so223231366b.0; Thu, 10 Oct 2024 14:00:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728594049; x=1729198849; 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=aaXqSuLsFI5WdaDUrYSVDsiRhV/evheqKshVzEAvGPw=; b=jGNpw4Twpmxg6629bD3Q/9kPzvVyBam3abI4y5ZQpTd8cYgWa05m9hbbW7HoscMK3I g6puV4QCXRkZE2tf9al/bKg2D8YifOtdvl+PFByeb1Kqy0tAJnGZzHjIgrU73NLTqV7i zwfClLhCHcbop3vvbdh64WrGr/8vi9Hs1iPtS7X4OW+o/NE80HDIRhFTfY8VHNASqNjw 1MIrLjXtVvQeIgvsg3iBHsDboi9d5x1QBGtDrHNHSbPGIsVsK+oNQG+xzPZEmVtRw0oN zOrkRO/ZSxXMldtr+65nvKBWxjAIPiDAnoIMr8iG/BP8YZ+R0Mwpp9NJ4wTqNXzoZNWg M5Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728594049; x=1729198849; 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=aaXqSuLsFI5WdaDUrYSVDsiRhV/evheqKshVzEAvGPw=; b=Tejd9bH0uaMXvpw1mQuGpBedx/59Soxn607RYd7dxdhsZ2bQZXtRKVeeHeTCLR8a3G ZSS9Iuhq48OY/T/vLFKu+enCfgZnVrD9ahN3R4BdY6kq/+N9apT0H5ZUlVt392pa7Zok twcHmb/aSXDEgkzCEIBHij6cxxc69LV0jUd6LaG8UfyFD0C69UFsrVtv+of7XzG9cJTF IFc4CkzaxDipr4JXKe711nIAK6h/GWODLdrnJGGSOwzGBB+HBcaU3rHiVDGmuw0lgG+7 09nu+pI3YXK4E1RXTwL5npUqJwV5OVRwszKaximMDW7UC2wzDst9zqbWM/FdgXlL3xYT o0GA== X-Forwarded-Encrypted: i=1; AJvYcCVh7XECYTsHWwAZkqqGbgkhIcAOUObM+EN4sBA2QSqr57Q29dTHaT3gtVnkMFfWb8oJ0mKI/dNfC50+@vger.kernel.org, AJvYcCX95H1cEsxdHUZQstjOxZ1tOBDdBGzY9ylSj686eQyhIwxuZN3lUb2oKaOGJNhX40gn6dvfjnFZsWzJIwLl@vger.kernel.org, AJvYcCXwYdAVT8y65N6LT0jbhn1s1k4Tk4c4ZAvZTRMAgRxLfNi8ZP5/19Js9YWp0/VbMb5m8wMWithj7crr@vger.kernel.org X-Gm-Message-State: AOJu0YxEXqdU0G9VXK8WBWDF0hHtBaLQJY3QYphOqsgwY1jMMpJ2mByk BgNQ9evp1NR0NsrfHOClSHPSnzNxEoa5wgmvAcwMndlEVmoxd4Z+ X-Google-Smtp-Source: AGHT+IGDsfwzeqAdM57791o3FOb4sGtnBah0MtDXYgkYPGoPAhOaix3Z0ep25ZNxWyEP+xHGsEPKJg== X-Received: by 2002:a17:907:86ab:b0:a8b:ddf4:46f1 with SMTP id a640c23a62f3a-a99b9678822mr23747066b.63.1728594049459; Thu, 10 Oct 2024 14:00:49 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:7eab:ec9d:62da:64f5]) by smtp.googlemail.com with ESMTPSA id a640c23a62f3a-a99a7f25f4dsm135692566b.68.2024.10.10.14.00.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 14:00:48 -0700 (PDT) From: vamoirid To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: vassilisamir@gmail.com, anshulusr@gmail.com, gustavograzs@gmail.com, andriy.shevchenko@linux.intel.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 08/13] iio: chemical: bme680: add power management Date: Thu, 10 Oct 2024 23:00:25 +0200 Message-ID: <20241010210030.33309-9-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241010210030.33309-1-vassilisamir@gmail.com> References: <20241010210030.33309-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Vasileios Amoiridis Add runtime power management to the device. To facilitate this, add also a struct dev * inside the bme680_data structure to have the device accesible from the data structure. Signed-off-by: Vasileios Amoiridis --- drivers/iio/chemical/bme680.h | 1 + drivers/iio/chemical/bme680_core.c | 100 +++++++++++++++++++++++++++-- 2 files changed, 95 insertions(+), 6 deletions(-) diff --git a/drivers/iio/chemical/bme680.h b/drivers/iio/chemical/bme680.h index e55a48982b3e..e9e3e08fa366 100644 --- a/drivers/iio/chemical/bme680.h +++ b/drivers/iio/chemical/bme680.h @@ -75,6 +75,7 @@ #define BME680_CALIB_RANGE_3_LEN 5 =20 extern const struct regmap_config bme680_regmap_config; +extern const struct dev_pm_ops bmp280_dev_pm_ops; =20 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/bme6= 80_core.c index a2039b966f20..5fd5740bb7fe 100644 --- a/drivers/iio/chemical/bme680_core.c +++ b/drivers/iio/chemical/bme680_core.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include =20 @@ -111,6 +112,7 @@ struct bme680_data { struct regmap *regmap; struct bme680_calib bme680; struct mutex lock; /* Protect multiple serial R/W ops to device. */ + struct device *dev; u8 oversampling_temp; u8 oversampling_press; u8 oversampling_humid; @@ -753,9 +755,9 @@ static int bme680_read_gas(struct bme680_data *data, in= t *val) return IIO_VAL_INT; } =20 -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 =3D iio_priv(indio_dev); int ret; @@ -803,14 +805,29 @@ static int bme680_read_raw(struct iio_dev *indio_dev, } } =20 +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 =3D iio_priv(indio_dev); + int ret; + + pm_runtime_get_sync(data->dev); + ret =3D __bme680_read_raw(indio_dev, chan, val, val2, mask); + pm_runtime_mark_last_busy(data->dev); + pm_runtime_put_autosuspend(data->dev); + + return ret; +} + static bool bme680_is_valid_oversampling(int rate) { return (rate > 0 && rate <=3D 16 && is_power_of_2(rate)); } =20 -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 =3D iio_priv(indio_dev); =20 @@ -846,6 +863,21 @@ static int bme680_write_raw(struct iio_dev *indio_dev, } } =20 +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 =3D iio_priv(indio_dev); + int ret; + + pm_runtime_get_sync(data->dev); + ret =3D __bme680_write_raw(indio_dev, chan, val, val2, mask); + pm_runtime_mark_last_busy(data->dev); + pm_runtime_put_autosuspend(data->dev); + + return ret; +} + static const char bme680_oversampling_ratio_show[] =3D "1 2 4 8 16"; =20 static IIO_CONST_ATTR(oversampling_ratio_available, @@ -873,6 +905,15 @@ static void bme680_regulators_disable(void *data) regulator_bulk_disable(BME680_NUM_SUPPLIES, supplies); } =20 +static void bme680_pm_disable(void *data) +{ + struct device *dev =3D data; + + pm_runtime_get_sync(dev); + pm_runtime_put_noidle(dev); + pm_runtime_disable(dev); +} + int bme680_core_probe(struct device *dev, struct regmap *regmap, const char *name) { @@ -887,6 +928,7 @@ int bme680_core_probe(struct device *dev, struct regmap= *regmap, data =3D iio_priv(indio_dev); mutex_init(&data->lock); dev_set_drvdata(dev, indio_dev); + data->dev =3D dev; data->regmap =3D regmap; indio_dev->name =3D name; indio_dev->channels =3D bme680_channels; @@ -947,10 +989,56 @@ int bme680_core_probe(struct device *dev, struct regm= ap *regmap, return dev_err_probe(dev, ret, "failed to set gas config data\n"); =20 + /* Enable runtime PM */ + pm_runtime_get_noresume(dev); + pm_runtime_set_active(dev); + pm_runtime_enable(dev); + pm_runtime_set_autosuspend_delay(dev, BME680_STARTUP_TIME_US * 100); + pm_runtime_use_autosuspend(dev); + pm_runtime_put(dev); + + ret =3D devm_add_action_or_reset(dev, bme680_pm_disable, dev); + if (ret) + return ret; + return devm_iio_device_register(dev, indio_dev); } EXPORT_SYMBOL_NS_GPL(bme680_core_probe, IIO_BME680); =20 +static int bme680_runtime_suspend(struct device *dev) +{ + struct iio_dev *indio_dev =3D dev_get_drvdata(dev); + struct bme680_data *data =3D iio_priv(indio_dev); + + return regulator_bulk_disable(BME680_NUM_SUPPLIES, data->supplies); +} + +static int bme680_runtime_resume(struct device *dev) +{ + struct iio_dev *indio_dev =3D dev_get_drvdata(dev); + struct bme680_data *data =3D iio_priv(indio_dev); + int ret; + + ret =3D regulator_bulk_enable(BME680_NUM_SUPPLIES, data->supplies); + if (ret) + return ret; + + fsleep(BME680_STARTUP_TIME_US); + + ret =3D bme680_chip_config(data); + if (ret) + return ret; + + ret =3D bme680_gas_config(data); + if (ret) + return ret; + + return 0; +} + +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"); --=20 2.43.0 From nobody Wed Nov 27 08:38:16 2024 Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (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 CCCF91EB9F8; Thu, 10 Oct 2024 21:00:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728594054; cv=none; b=kCZ5MjlPwMABN8ZrDqe2KUm4YCmFsGsA7zwBIrdjT6rxM6yQmvdJv83CMujk1Z/qAcQ/RxEM5ONwx7lpWSd9JX8UpmYR+LFY7DclU26BqOZdeDybh+DpLBRZKVYLLC6LjV8PpJpVl5hfkuORfBDNdAoeLrTsLHxVAFrjBJnd5uc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728594054; c=relaxed/simple; bh=uh8NVnp9Ihq+FgmzA1DwT2r7T+ZgJqDWYmeKPcCtfUI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JxPzvesqJ5CPSmHyuFSs8Ui0f85z4N033nw0QzaTV9BKjBL7aYwhs/5zxihD5p/tmuum2L+OBaYEs1Q2VN/NnIGQClvREf0Xk/7OfMDFxGa+Bw5/4CPotvSVqm/7LGSXkgwcutvihgmz32LwgfjDGGCxPA8fP/jCK6a6PYHWYM8= 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=S4TCImyp; arc=none smtp.client-ip=209.85.208.43 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="S4TCImyp" Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-5c941623a5aso1418817a12.0; Thu, 10 Oct 2024 14:00:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728594051; x=1729198851; 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=1N9aizlh41CXZ4byNCDj3AnGL9jqT8nuJlmW3/5gIfU=; b=S4TCImypkWgoM0HSKNEl6KJDEYLMrsJJl2MRImR5Jz9P5x35IEsXkiNrxIGSxYxH0x d3VEalJsJpm9FdYn2cmj7scVabxWzi4A3nSK5bsnUanWIu0BZcWbZO52uwpTY3m69eql GkqwA1YSVxVGM9S7MS/tk+qu7REF0A3QTP1uLrOqeEog1tKM3yXIjybWBtqRY4QJeb8z 05t4WMq2AGCpvXkJDH+jR6hGMpDBZ/BMLZILNpTtwQLxg4EGqdVw+xjFeg4ImdEtkGjO oqL5BhSIhuT4UVfrQVWTArkZm27AdKsyzZ/MeCVklZaHM20Kng8kla92n3M5E/9jyEfY GI5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728594051; x=1729198851; 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=1N9aizlh41CXZ4byNCDj3AnGL9jqT8nuJlmW3/5gIfU=; b=jls5nDn+6P5O7t/7CCk3L1yf15R1UMwnBAEm9cZ5sMTw5PRdM+tDLEk+xFA2O4m3tL yXTjQ+Mt2Nb/DLwKe8JGWyDkQpkkXtg8+MwJAQDxAEQfCvoOeEzIZPaiqysi7VzvBBY6 /PCw4sSyBMcSEyLIeudVHpWPhdIzZnoUn74YR8gRBmNznZhAYsTnjufJeBPfaPZMVh27 p/U/+XAMLZ/HGNlOQ/mARWqazQXY7Ur95h/Tb9c6qAnKnT8kXlch3rmgY1w/hT+QGyNN ebic+vr59MS2AApeH7nqusaBoTl48Thj+7EiEG9cCBYYmolsAZ6ZIWdEXMRipnVtyTQ8 wVhA== X-Forwarded-Encrypted: i=1; AJvYcCUOJoYJE8Obwh8mqywetgNG3PysMFTlC3pS5C2YRSyw65t6s4zGD0tOGzffzvcJ+qMZPQLfrDLFItVCJAsF@vger.kernel.org, AJvYcCVc6A47Mx0YVJD/2OAoazQIdzb97AE06rl9TWyXYGzr1XPqa0GU4u77evioYXnNIVqENDtDPVs1+0wM@vger.kernel.org, AJvYcCVwFH4+XL3xgtEAoPPcXzdiNB0qGvNxB/Ayg4XT2dp22iNEPLP9+J91HSaxOIsEHDIvNlQMPvrreLzt@vger.kernel.org X-Gm-Message-State: AOJu0YyttOJ58Gp2yQrsPT1+92skao69Rls9GojBCUuzn3mitxKeqJLD FdO7MBUv9rJndE/ODDe2Jx/5xSdB9twne/ACENyQi9IaPNwsc5F+ X-Google-Smtp-Source: AGHT+IFchXI6GpNj3shGEtlnTjxkiGv7lzRcgDZUxwca9Xsl9OIuZ2W3a/v8iPADiYiFAC314TOYvA== X-Received: by 2002:a17:907:7e87:b0:a99:57c3:1fbb with SMTP id a640c23a62f3a-a99a10ed84dmr450015766b.9.1728594051159; Thu, 10 Oct 2024 14:00:51 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:7eab:ec9d:62da:64f5]) by smtp.googlemail.com with ESMTPSA id a640c23a62f3a-a99a7f25f4dsm135692566b.68.2024.10.10.14.00.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 14:00:50 -0700 (PDT) From: vamoirid To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: vassilisamir@gmail.com, anshulusr@gmail.com, gustavograzs@gmail.com, andriy.shevchenko@linux.intel.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 09/13] iio: chemical: bme680: Move ambient temperature to attributes Date: Thu, 10 Oct 2024 23:00:26 +0200 Message-ID: <20241010210030.33309-10-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241010210030.33309-1-vassilisamir@gmail.com> References: <20241010210030.33309-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Vasileios Amoiridis Remove the ambient temperature from being a macro and implement it as an attribute. This way, it is possible to dynamically configure the ambient temperature of the environment to improve the accuracy of the measurements. Signed-off-by: Vasileios Amoiridis --- drivers/iio/chemical/bme680.h | 1 - drivers/iio/chemical/bme680_core.c | 35 +++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/drivers/iio/chemical/bme680.h b/drivers/iio/chemical/bme680.h index e9e3e08fa366..95d39c154d59 100644 --- a/drivers/iio/chemical/bme680.h +++ b/drivers/iio/chemical/bme680.h @@ -45,7 +45,6 @@ #define BME680_REG_RES_HEAT_0 0x5A #define BME680_REG_GAS_WAIT_0 0x64 #define BME680_ADC_GAS_RES GENMASK(15, 6) -#define BME680_AMB_TEMP 25 =20 #define BME680_REG_CTRL_GAS_1 0x71 #define BME680_RUN_GAS_MASK BIT(4) diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme6= 80_core.c index 5fd5740bb7fe..0979c8f0afcf 100644 --- a/drivers/iio/chemical/bme680_core.c +++ b/drivers/iio/chemical/bme680_core.c @@ -120,6 +120,7 @@ struct bme680_data { u16 heater_temp; =20 struct regulator_bulk_data supplies[BME680_NUM_SUPPLIES]; + int ambient_temp; =20 union { u8 buf[3]; @@ -483,7 +484,7 @@ static u8 bme680_calc_heater_res(struct bme680_data *da= ta, u16 temp) if (temp > 400) /* Cap temperature */ temp =3D 400; =20 - var1 =3D (((s32)BME680_AMB_TEMP * calib->par_gh3) / 1000) * 256; + var1 =3D (((s32)data->ambient_temp * calib->par_gh3) / 1000) * 256; var2 =3D (calib->par_gh1 + 784) * (((((calib->par_gh2 + 154009) * temp * 5) / 100) + 3276800) / 10); @@ -878,6 +879,37 @@ static int bme680_write_raw(struct iio_dev *indio_dev, return ret; } =20 +static ssize_t ambient_temp_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct iio_dev *indio_dev =3D dev_to_iio_dev(dev); + struct bme680_data *data =3D iio_priv(indio_dev); + int vals[2]; + + vals[0] =3D data->ambient_temp; + vals[1] =3D 1; + + return iio_format_value(buf, IIO_VAL_INT, 1, vals); +} + +static ssize_t ambient_temp_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct iio_dev *indio_dev =3D dev_to_iio_dev(dev); + struct bme680_data *data =3D iio_priv(indio_dev); + int ret, val_int, val_fract; + + ret =3D iio_str_to_fixpoint(buf, 1, &val_int, &val_fract); + if (ret) + return ret; + + data->ambient_temp =3D val_int; + return len; +} + +static IIO_DEVICE_ATTR_RW(ambient_temp, 0); + static const char bme680_oversampling_ratio_show[] =3D "1 2 4 8 16"; =20 static IIO_CONST_ATTR(oversampling_ratio_available, @@ -885,6 +917,7 @@ static IIO_CONST_ATTR(oversampling_ratio_available, =20 static struct attribute *bme680_attributes[] =3D { &iio_const_attr_oversampling_ratio_available.dev_attr.attr, + &iio_dev_attr_ambient_temp.dev_attr.attr, NULL, }; =20 --=20 2.43.0 From nobody Wed Nov 27 08:38:16 2024 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (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 2C80C1EBA1F; Thu, 10 Oct 2024 21:00:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728594056; cv=none; b=gAa8ikynoQxKNYlfej0h0A7rLcrJyAu+DXI3eLoE0noHSbyfbSaML1L7DoWZskUif8/fC0U2pwvt896KirqCo72k5tvecYf5zIyT+NuSnv3b+xJZ+/CVgcQJeR9XeTrMMYfWZlFE/fuEk2q0T1SHgp1zymAeACZO6uTlq0vN8V4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728594056; c=relaxed/simple; bh=Ro3vKVwG9OrFe7D9KeNbV4BcFPOnK3BB+dJZIDGABNM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UGTk4qpG5QPPdnQ1NAaBCTnuJbkfDqLN4LHxzVpnTyjwedk7D/PYhjGoJDibVAB04HxpVkU1S7v9g9JygQTR1M7W5cXODSaiVrEft8OYAN/sR/zZHqRuhx0MiZzfRtxTwK8aMMIwDUEa1jvdY70zJDQ4lLVpckipjePaewD3Q0Q= 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=YsggJZEV; arc=none smtp.client-ip=209.85.167.52 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="YsggJZEV" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-53991d05416so1802772e87.2; Thu, 10 Oct 2024 14:00:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728594052; x=1729198852; 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=2CdvgLs5EyJHbZgt0XAtnGGoYU5wfKc655jog4d69Is=; b=YsggJZEVSeiDAjAZ58NAVlKT7ZaVsPZa5yTsgIerTvx7ZcasnIyfPSDil/+5afR60F nJGGwTwXvmMjGDvhCMd1SeTQod/LAMjdb/ziOqNRH62fIpYo0TWwdQUIEWXx2eZIM2PR KpSC/gfA5Fxzl0qshHQDII5n31BuRxr8/n/x82+GfRXB4dhJRz2oZbzzJxkoUSrZ8oYZ /8RLbB9qL4zLRdDDTCLqFkgoqmrwp/BKJWbVcFAadQZsjrDQup8prUHxR6oHx05fbLEB 1PauQ6K0yw6J2hfpjrDnlS5uI92ybsBY1sXXdyS88AOQpdtB1nQoSRj+d9Yct/JzeuAP G0og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728594052; x=1729198852; 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=2CdvgLs5EyJHbZgt0XAtnGGoYU5wfKc655jog4d69Is=; b=L99rBsbdwzhNjXcBd3xS7qsN/YMENSBtSnElBZ12+hJYyiaB8N1o901ahap+8dj4Up 4okeGo6Azf46oDmBrFT78+EbSxlXuXraBNjvZMmp7yetFnNW+JZ7EId0ddzprujMlELE 9vtyL7O5epZhrkGeqOnFfju5sKpyVRv+oKFf5KG+QmtMzUqTIspF2UJR5CuMuHJfjWg/ UB5HiShw1wU1MVWRPcTtAVcXtS5X5QiKGl1drUzBQZUPnHzMlf5vaEe7voIeTyT53S9t 9XAWXgisEaeBCv2n4xCNNJZ8q1R/sjpjRbyZu3Ef4/yGgo3DvrBPdW0dUhmenQmECA8O 0pCA== X-Forwarded-Encrypted: i=1; AJvYcCVTXwqNULTiEDFddqGLoWekMshLFzIIf5Nz61v6Yf506bbuPq5NxK4ehyyh6qca77sh1oUhYVjtYIWp@vger.kernel.org, AJvYcCX0M2L2J+p3UJolg8b6IWQ/JMa5p82lXEdTRUKXbbacF12osKKaxrwhCpamXVQoUIOTmhsdrOe4+nWR@vger.kernel.org, AJvYcCXeSTI2JFwnh9VGf0Nik2+QFYiFkIiNbd+OLSo4M9jfOMoedp1vGoIsXpkAiokI8MepNmU9FF+pZzyatoiK@vger.kernel.org X-Gm-Message-State: AOJu0YwjwxYnc8k8+oR2+MphPxVn9925aIcFk5IX/gWnkhqw5ayWTzFM rZibOsq2Zq/ukVHKDRib0WmI4y6Av5i5xoJArMikUF3SNCVAFrN5ZPUbG07t X-Google-Smtp-Source: AGHT+IH4L2gJ42cSXuloYs3N4M3zCvTDsJLBQzoH7Qk61ueY6LwVwLS83bEg0pvjJXN8c6IFzkQL3Q== X-Received: by 2002:a05:6512:1083:b0:539:8d9b:b61c with SMTP id 2adb3069b0e04-539da592814mr99256e87.51.1728594052062; Thu, 10 Oct 2024 14:00:52 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:7eab:ec9d:62da:64f5]) by smtp.googlemail.com with ESMTPSA id a640c23a62f3a-a99a7f25f4dsm135692566b.68.2024.10.10.14.00.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 14:00:51 -0700 (PDT) From: vamoirid To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: vassilisamir@gmail.com, anshulusr@gmail.com, gustavograzs@gmail.com, andriy.shevchenko@linux.intel.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 10/13] iio: chemical: bme680: generalize read_*() functions Date: Thu, 10 Oct 2024 23:00:27 +0200 Message-ID: <20241010210030.33309-11-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241010210030.33309-1-vassilisamir@gmail.com> References: <20241010210030.33309-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Vasileios Amoiridis Remove the IIO specific scaling measurement units from the read functions and add them inside the ->read_raw() function to keep the read_*() generic. This way they can be used in other parts of the driver. Signed-off-by: Vasileios Amoiridis --- drivers/iio/chemical/bme680_core.c | 65 ++++++++++++++++++------------ 1 file changed, 40 insertions(+), 25 deletions(-) diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme6= 80_core.c index 0979c8f0afcf..4669338ec2e5 100644 --- a/drivers/iio/chemical/bme680_core.c +++ b/drivers/iio/chemical/bme680_core.c @@ -661,22 +661,20 @@ static int bme680_gas_config(struct bme680_data *data) return ret; } =20 -static int bme680_read_temp(struct bme680_data *data, int *val) +static int bme680_read_temp(struct bme680_data *data, s16 *comp_temp) { int ret; u32 adc_temp; - s16 comp_temp; =20 ret =3D bme680_read_temp_adc(data, &adc_temp); if (ret) return ret; =20 - comp_temp =3D bme680_compensate_temp(data, adc_temp); - *val =3D comp_temp * 10; /* Centidegrees to millidegrees */ - return IIO_VAL_INT; + *comp_temp =3D bme680_compensate_temp(data, adc_temp); + return 0; } =20 -static int bme680_read_press(struct bme680_data *data, int *val, int *val2) +static int bme680_read_press(struct bme680_data *data, u32 *comp_press) { int ret; u32 adc_press; @@ -690,15 +688,14 @@ static int bme680_read_press(struct bme680_data *data= , int *val, int *val2) if (ret) return ret; =20 - *val =3D bme680_compensate_press(data, adc_press, t_fine); - *val2 =3D 1000; - return IIO_VAL_FRACTIONAL; + *comp_press =3D bme680_compensate_press(data, adc_press, t_fine); + return 0; } =20 -static int bme680_read_humid(struct bme680_data *data, int *val, int *val2) +static int bme680_read_humid(struct bme680_data *data, u32 *comp_humidity) { int ret; - u32 adc_humidity, comp_humidity; + u32 adc_humidity; s32 t_fine; =20 ret =3D bme680_get_t_fine(data, &t_fine); @@ -709,14 +706,11 @@ static int bme680_read_humid(struct bme680_data *data= , int *val, int *val2) if (ret) return ret; =20 - comp_humidity =3D bme680_compensate_humid(data, adc_humidity, t_fine); - - *val =3D comp_humidity; - *val2 =3D 1000; - return IIO_VAL_FRACTIONAL; + *comp_humidity =3D bme680_compensate_humid(data, adc_humidity, t_fine); + return 0; } =20 -static int bme680_read_gas(struct bme680_data *data, int *val) +static int bme680_read_gas(struct bme680_data *data, int *comp_gas_res) { struct device *dev =3D regmap_get_device(data->regmap); int ret; @@ -751,9 +745,8 @@ static int bme680_read_gas(struct bme680_data *data, in= t *val) } =20 gas_range =3D FIELD_GET(BME680_GAS_RANGE_MASK, gas_regs_val); - - *val =3D bme680_compensate_gas(data, adc_gas_res, gas_range); - return IIO_VAL_INT; + *comp_gas_res =3D bme680_compensate_gas(data, adc_gas_res, gas_range); + return 0; } =20 static int __bme680_read_raw(struct iio_dev *indio_dev, @@ -761,7 +754,7 @@ static int __bme680_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long mask) { struct bme680_data *data =3D iio_priv(indio_dev); - int ret; + int chan_val, ret; =20 guard(mutex)(&data->lock); =20 @@ -777,13 +770,35 @@ static int __bme680_read_raw(struct iio_dev *indio_de= v, case IIO_CHAN_INFO_PROCESSED: switch (chan->type) { case IIO_TEMP: - return bme680_read_temp(data, val); + ret =3D bme680_read_temp(data, (s16 *)&chan_val); + if (ret) + return ret; + + *val =3D chan_val * 10; + return IIO_VAL_INT; case IIO_PRESSURE: - return bme680_read_press(data, val, val2); + ret =3D bme680_read_press(data, &chan_val); + if (ret) + return ret; + + *val =3D chan_val; + *val2 =3D 1000; + return IIO_VAL_FRACTIONAL; case IIO_HUMIDITYRELATIVE: - return bme680_read_humid(data, val, val2); + ret =3D bme680_read_humid(data, &chan_val); + if (ret) + return ret; + + *val =3D chan_val; + *val2 =3D 1000; + return IIO_VAL_FRACTIONAL; case IIO_RESISTANCE: - return bme680_read_gas(data, val); + ret =3D bme680_read_gas(data, &chan_val); + if (ret) + return ret; + + *val =3D chan_val; + return IIO_VAL_INT; default: return -EINVAL; } --=20 2.43.0 From nobody Wed Nov 27 08:38:16 2024 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.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 CBFE11EBFF8; Thu, 10 Oct 2024 21:00:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728594056; cv=none; b=mtEp0Lef0JrdFp2PqteHVN7jdeK2Fv8HQh3w7NYJmA4K8Z4Jl8bboAojDj1ZXtmLY13XU0o7xBWPcW9hKxV8PceDAM5pXehO3lIW5CNNYoxnVEfN9fENZZtZyNlpjNYYjztxwlf1HR4emcEvHZ8fC9cXcuKqYlxBr962A/GjVQI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728594056; c=relaxed/simple; bh=bmhA3SsOWnIZbrU89s1sQYvFCSZk/tlwnESgmddNpJ4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IltG2xdWJMlEpAGrm67KZTudgE5iQzyrFvB6i44p6j9Cm+1KWx04DUdyuKb3OqKtfUiLfVkP5xDmZ1wm5h5oFNXWnre0tmg7KhRtDLMWBkAPclCD66mSgov3+BT6nHJjpcHUH9BD37CQYjs3BNyNoF4CDGAGCBdIe00BwUdEdeo= 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=d+9uvBZP; arc=none smtp.client-ip=209.85.208.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="d+9uvBZP" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-5c9362c26d8so1957701a12.1; Thu, 10 Oct 2024 14:00:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728594053; x=1729198853; 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=OIki3gH9gwohrIiKjOvxS4lxdekFzOTu2gTcUdwnifU=; b=d+9uvBZP4cUEibarnhgY7g77i+2V/g7Ird09dSC3IWRi2PuC0NjKhnsFs7+DjB+14I tETDHCDBFKSFwdfiuVkv8hReJfhkwotbUGUwYsJ1GM2bLFm++YCo0ngBJ7hMS30f0uVX n/uY23lk+WCK5coEw5t4MBq+Kvko4oYH27yTIYhaaSlmsQ2Vet/wBrohz00PGGmJqZSG TFTSFzmQJVnvqDho/qIk8+NyfjYSeJsiPgkx5HDIDp1zRdPYDd9f02LuaeUbXSykDYMH 86kqoQDcic+5XasqgVCjl+lY8TNmuJDpKZm9HU6P/Fl+oG9yMTL1EGjbMuWbmKPEdr9Q 7KOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728594053; x=1729198853; 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=OIki3gH9gwohrIiKjOvxS4lxdekFzOTu2gTcUdwnifU=; b=F1i9KvXQTEdXYLXbWr+sQIyhhJNRwFvLsNS47TlnkWYNK9KPItcfmuUelQ706MyeSK jLPlxfvbiGRTaHktvdU6fLcxc7BzZTe2KssBjpL8lm45m0rDFFvEibPK3+lkfoUYKBQv Bko51fS7xQcHR4Zfan40RqxtoyaYyKyNIwmAlqGtdPMf8x1g+VNnuvSlZ9hEB0BzaO1v cii2l5nvU33c2UkUs4FwV0M2TtU1ae/b0zw9UmzUWNLCBmvMBGsvSr8jSFpJT7J2Egj8 UEQdTHqb0C1yNewYn1usGiPsS73GhqBBA621++ziWASrdWrPeEY/iVZsSpOFG57lCu0K fz1w== X-Forwarded-Encrypted: i=1; AJvYcCUYcKx7ahjerUhIVqoA0LxOjurW10I1RkSFQpSEgMu/Hd+rsEUjgD5Lp0tTEk1ZevaaRNGAtONtZtNi@vger.kernel.org, AJvYcCVXYaC+Vcn4T+Elu97ZOG8xdQvt0CLruG+qoM5Su2ysy1adzyBpoZb1Ad1nQv3aH91CSM1fbTax1Z6k@vger.kernel.org, AJvYcCXqEBs6YoIzpF9+D3prGLsK2G3PlFj9Nub8XHTcOWyHr3+JF0cslqpAUZBPk7ecmXILueN0AvKd8LRJAIGw@vger.kernel.org X-Gm-Message-State: AOJu0YzHUGj6189ldxdkdgreUqqWiEMMBUNF5bbu8wlOy4paC3U4B4It tNLTL/0xknJOZREG1cEjmDl7Lvm85m9VEHhBfIUmNyXApzlBlk2q X-Google-Smtp-Source: AGHT+IFmPTUR8VwYFGLVeZSiu+c3uz/wO9gGgR2hjdMGttdYSCSrr9HirJGcZFQN8MhqQflNK+eA0A== X-Received: by 2002:a17:907:9495:b0:a8d:4e69:4030 with SMTP id a640c23a62f3a-a99a11092a0mr427547066b.19.1728594053039; Thu, 10 Oct 2024 14:00:53 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:7eab:ec9d:62da:64f5]) by smtp.googlemail.com with ESMTPSA id a640c23a62f3a-a99a7f25f4dsm135692566b.68.2024.10.10.14.00.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 14:00:52 -0700 (PDT) From: vamoirid To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: vassilisamir@gmail.com, anshulusr@gmail.com, gustavograzs@gmail.com, andriy.shevchenko@linux.intel.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 11/13] iio: chemical: bme680: Add SCALE and RAW channels Date: Thu, 10 Oct 2024 23:00:28 +0200 Message-ID: <20241010210030.33309-12-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241010210030.33309-1-vassilisamir@gmail.com> References: <20241010210030.33309-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Vasileios Amoiridis Add SCALE,RAW channels to the device. Even though PROCESSED should be kept for backwards compatibility add comment to avoid using it if the value is not actually reported in IIO values. Signed-off-by: Vasileios Amoiridis --- drivers/iio/chemical/bme680_core.c | 51 ++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme6= 80_core.c index 4669338ec2e5..7d6f4d8c5fe4 100644 --- a/drivers/iio/chemical/bme680_core.c +++ b/drivers/iio/chemical/bme680_core.c @@ -155,17 +155,26 @@ EXPORT_SYMBOL_NS(bme680_regmap_config, IIO_BME680); static const struct iio_chan_spec bme680_channels[] =3D { { .type =3D IIO_TEMP, + /* PROCESSED maintained for ABI backwards compatibility */ .info_mask_separate =3D BIT(IIO_CHAN_INFO_PROCESSED) | + BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), }, { .type =3D IIO_PRESSURE, + /* PROCESSED maintained for ABI backwards compatibility */ .info_mask_separate =3D BIT(IIO_CHAN_INFO_PROCESSED) | + BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), }, { .type =3D IIO_HUMIDITYRELATIVE, + /* PROCESSED maintained for ABI backwards compatibility */ .info_mask_separate =3D BIT(IIO_CHAN_INFO_PROCESSED) | + BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), }, { @@ -802,6 +811,48 @@ static int __bme680_read_raw(struct iio_dev *indio_dev, default: return -EINVAL; } + case IIO_CHAN_INFO_RAW: + switch (chan->type) { + case IIO_TEMP: + ret =3D bme680_read_temp(data, (s16 *)&chan_val); + if (ret) + return ret; + + *val =3D chan_val; + return IIO_VAL_INT; + case IIO_PRESSURE: + ret =3D bme680_read_press(data, &chan_val); + if (ret) + return ret; + + *val =3D chan_val; + return IIO_VAL_INT; + case IIO_HUMIDITYRELATIVE: + ret =3D bme680_read_humid(data, &chan_val); + if (ret) + return ret; + + *val =3D chan_val; + return IIO_VAL_INT; + default: + return -EINVAL; + } + case IIO_CHAN_INFO_SCALE: + switch (chan->type) { + case IIO_TEMP: + *val =3D 10; + return IIO_VAL_INT; + case IIO_PRESSURE: + *val =3D 1; + *val2 =3D 1000; + return IIO_VAL_FRACTIONAL; + case IIO_HUMIDITYRELATIVE: + *val =3D 1; + *val2 =3D 1000; + return IIO_VAL_FRACTIONAL; + default: + return -EINVAL; + } case IIO_CHAN_INFO_OVERSAMPLING_RATIO: switch (chan->type) { case IIO_TEMP: --=20 2.43.0 From nobody Wed Nov 27 08:38:16 2024 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.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 205071EF09F; Thu, 10 Oct 2024 21:00:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728594058; cv=none; b=ZV+34c9uZDANDasAOX8+57xNjtPfWs20kOD8npic+uAXugPCZZvKxRHSLfrhIxeuSZKn0WPHxogJ24/W8rnWcrCChYSMv/N2pD3ovCnafD+E6YsydXseYtWqy3U7oaYrPiBJ6KHap41OjYd8+3MKCNW0u01wt+DlHsAXsLRDvoo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728594058; c=relaxed/simple; bh=a99UhmFiaPZvfh7b6Ml438pv7HVRosc6MoqVxm76lbw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JqKd5tq5k2+KG8qryHo8jdZlzHir+7ozAROBtbSQh4Ln+hFm2MbCo+IMXl5imayeolEGfiY5XqaHy4h2m4+5jQr72WX4E3FRqhWFSdwDrxWcXprvEzKYrSR/fx4saxf7c9TqYQaBvZy/H1lpYYHrFJaXM3thsyWSzKxa8+kktg0= 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=MXbOclej; arc=none smtp.client-ip=209.85.218.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="MXbOclej" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a9953bdc341so102594766b.2; Thu, 10 Oct 2024 14:00:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728594054; x=1729198854; 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=rlyfHq2NNG9opqGozCAzEdrmjUAChMJmuDDHTJycLws=; b=MXbOclejpWclA+E/0609qcOHjV5rXmzfMyi6dHIDpQL7ll/hNN6j/WY8MvO0Qdq6yJ wEfoQ5MJ9QOIDBv5DlQthLf4sujg0xlfXMPp58hrpHg8jassRNovTTBE52UsKKCySrYb s+jEnN9xulqL0WpqAD0G9/E7lyyHx7k0vOLkXQpiz5mmk/HupvL98eZzQl93RJ+0re5J WbsZ0zJDifYSW+jgORDRcDqrWEMovRojs1t1IG/4GdDdtAJJ79+jZbin/b1YmBPRbtaL tA3HwO0T/5d93CnLLVYrw5Ym2ezrI4GMErp+5SgTfWW2jmRVo3sm2Udl3p+QKVAKoJfa F1pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728594054; x=1729198854; 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=rlyfHq2NNG9opqGozCAzEdrmjUAChMJmuDDHTJycLws=; b=xQtm/fFu1yZ7HTjwdpIXl02SdxBNzQw76FJgoXs8mTh0dytkIS43HuvUQEqh0C9MlA liDKnHKTx14LtEUUPL722xW/+T5UOhIsGewCqKd1+bAC34gSvhk3CeC5BTthuzfi91O+ tMowYng3wnYtmP/2OcfyMrUIEBbaCdcCSVnwuQlmPuQ+pNTdup1X885Y9QrvJww6tMnh iwzBAxzh8U7sN3CzS4pHYpZ13m82280wb2pgZPB3dmAL9/GU/Lk/QUGRYVfzx5+Z6vnv 9/vYhpF0aVXrSnB+QZJRbaDFsNlUmYG3+w5Nf37eGXhiwCBafGylhYS55PiVkO8K/cuU HZyg== X-Forwarded-Encrypted: i=1; AJvYcCUEr4dbFsf/CjFMk5D+UQCz0430xl09Z2/1FQIUCbN0nYdtp/0SGrxBWZGl5nfkI3ueYLSJjS+v1aXn@vger.kernel.org, AJvYcCUTYrrZGjuFwedXzdybBqNMJWdNMYpgbUElcnAK6BjAlRTE7HvLT14UDZ4Hr2fMOrVIEGFPU7nBV+IMq4nv@vger.kernel.org, AJvYcCWhg4WzlmBR2pdy4izMdqpWnTUO6YN/4J0gB7BO95hh8Ak9kKEmfo+AgMTON9OxubJrmEShh6lizjVW@vger.kernel.org X-Gm-Message-State: AOJu0YzqZBpIMoRN1Y1yhNGG6R0i3gn0bdQ3YNSKvuJt5RdMP7adJleY 7XvbNeXdu0aMDBFOjjhLnVvvDVTZDckMRJNZdP2K+M3As5hOZO37 X-Google-Smtp-Source: AGHT+IEpv5+bOXaCpTptpUwXlX7KKWV6Qzehza4URQJ2BfSrICFm4+6FUJ4Px3hdQ/xQ5jDU8HblEA== X-Received: by 2002:a17:907:940e:b0:a99:4152:1cb4 with SMTP id a640c23a62f3a-a99b9585801mr18808566b.42.1728594054162; Thu, 10 Oct 2024 14:00:54 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:7eab:ec9d:62da:64f5]) by smtp.googlemail.com with ESMTPSA id a640c23a62f3a-a99a7f25f4dsm135692566b.68.2024.10.10.14.00.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 14:00:53 -0700 (PDT) From: vamoirid To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: vassilisamir@gmail.com, anshulusr@gmail.com, gustavograzs@gmail.com, andriy.shevchenko@linux.intel.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 12/13] iio: chemical: bme680: Add triggered buffer support Date: Thu, 10 Oct 2024 23:00:29 +0200 Message-ID: <20241010210030.33309-13-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241010210030.33309-1-vassilisamir@gmail.com> References: <20241010210030.33309-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Vasileios Amoiridis Add triggered buffer and soft timestamp support. The available scan mask enables all the channels of the sensor in order to follow the operation of the sensor. The sensor basically starts to capture from all channels as long as it enters into FORCED mode. Signed-off-by: Vasileios Amoiridis --- drivers/iio/chemical/Kconfig | 2 + drivers/iio/chemical/bme680.h | 2 + drivers/iio/chemical/bme680_core.c | 168 ++++++++++++++++++++++++++++- 3 files changed, 171 insertions(+), 1 deletion(-) diff --git a/drivers/iio/chemical/Kconfig b/drivers/iio/chemical/Kconfig index 678a6adb9a75..447b205f57bd 100644 --- a/drivers/iio/chemical/Kconfig +++ b/drivers/iio/chemical/Kconfig @@ -50,6 +50,8 @@ config BME680 select REGMAP select BME680_I2C if I2C select BME680_SPI if SPI + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER help Say yes here to build support for Bosch Sensortec BME680 sensor with temperature, pressure, humidity and gas sensing capability. diff --git a/drivers/iio/chemical/bme680.h b/drivers/iio/chemical/bme680.h index 95d39c154d59..e7eed2962baa 100644 --- a/drivers/iio/chemical/bme680.h +++ b/drivers/iio/chemical/bme680.h @@ -64,6 +64,8 @@ =20 #define BME680_STARTUP_TIME_US 2000 =20 +#define BME680_NUM_CHANNELS 4 + /* Calibration Parameters */ #define BME680_T2_LSB_REG 0x8A #define BME680_H2_MSB_REG 0xE1 diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme6= 80_core.c index 7d6f4d8c5fe4..df6ae4355902 100644 --- a/drivers/iio/chemical/bme680_core.c +++ b/drivers/iio/chemical/bme680_core.c @@ -18,8 +18,11 @@ #include #include =20 +#include #include #include +#include +#include =20 #include =20 @@ -108,6 +111,13 @@ static const char *const bme680_supply_names[] =3D { =20 #define BME680_NUM_SUPPLIES ARRAY_SIZE(bme680_supply_names) =20 +enum bme680_scan { + BME680_TEMP, + BME680_PRESS, + BME680_HUMID, + BME680_GAS, +}; + struct bme680_data { struct regmap *regmap; struct bme680_calib bme680; @@ -122,8 +132,11 @@ struct bme680_data { struct regulator_bulk_data supplies[BME680_NUM_SUPPLIES]; int ambient_temp; =20 + u8 buffer[ALIGN(sizeof(s32) * BME680_NUM_CHANNELS, sizeof(s64)) + + sizeof(s64)] __aligned(sizeof(s64)); + union { - u8 buf[3]; + u8 buf[15]; unsigned int check; __be16 be16; u8 bme680_cal_buf_1[BME680_CALIB_RANGE_1_LEN]; @@ -160,6 +173,13 @@ static const struct iio_chan_spec bme680_channels[] = =3D { BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), + .scan_index =3D 0, + .scan_type =3D { + .sign =3D 's', + .realbits =3D 16, + .storagebits =3D 16, + .endianness =3D IIO_CPU, + }, }, { .type =3D IIO_PRESSURE, @@ -168,6 +188,13 @@ static const struct iio_chan_spec bme680_channels[] = =3D { BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), + .scan_index =3D 1, + .scan_type =3D { + .sign =3D 'u', + .realbits =3D 32, + .storagebits =3D 32, + .endianness =3D IIO_CPU, + }, }, { .type =3D IIO_HUMIDITYRELATIVE, @@ -176,11 +203,26 @@ static const struct iio_chan_spec bme680_channels[] = =3D { BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), + .scan_index =3D 2, + .scan_type =3D { + .sign =3D 'u', + .realbits =3D 32, + .storagebits =3D 32, + .endianness =3D IIO_CPU, + }, }, { .type =3D IIO_RESISTANCE, .info_mask_separate =3D BIT(IIO_CHAN_INFO_PROCESSED), + .scan_index =3D 3, + .scan_type =3D { + .sign =3D 'u', + .realbits =3D 32, + .storagebits =3D 32, + .endianness =3D IIO_CPU, + }, }, + IIO_CHAN_SOFT_TIMESTAMP(4), }; =20 static int bme680_read_calib(struct bme680_data *data, @@ -997,6 +1039,121 @@ static const struct iio_info bme680_info =3D { .attrs =3D &bme680_attribute_group, }; =20 +static const unsigned long bme680_avail_scan_masks[] =3D { + BIT(BME680_GAS) | BIT(BME680_HUMID) | BIT(BME680_PRESS) | BIT(BME680_TEMP= ), + 0 +}; + +static irqreturn_t bme680_trigger_handler(int irq, void *p) +{ + struct iio_poll_func *pf =3D p; + struct iio_dev *indio_dev =3D pf->indio_dev; + struct bme680_data *data =3D iio_priv(indio_dev); + u32 adc_temp, adc_press, adc_humid, comp_press, comp_humid; + s32 *chans =3D (s32 *)data->buffer; + u16 adc_gas_res, gas_regs_val; + s32 t_fine, comp_gas_res; + s16 comp_temp; + u8 gas_range; + int ret; + + guard(mutex)(&data->lock); + + ret =3D bme680_set_mode(data, BME680_FORCED); + if (ret < 0) + goto out; + + ret =3D bme680_wait_for_eoc(data); + if (ret) + goto out; + + /* Burst read data regs */ + ret =3D regmap_bulk_read(data->regmap, BME680_REG_MEAS_STAT_0, + data->buf, sizeof(data->buf)); + if (ret) { + dev_err(data->dev, "failed to burst read sensor data\n"); + goto out; + } + if (data->buf[0] & BME680_GAS_MEAS_BIT) { + dev_err(data->dev, "gas measurement incomplete\n"); + goto out; + } + + /* Temperature calculations */ + adc_temp =3D FIELD_GET(BME680_MEAS_TRIM_MASK, get_unaligned_be24(&data->b= uf[5])); + if (adc_temp =3D=3D BME680_MEAS_SKIPPED) { + dev_err(data->dev, "reading temperature skipped\n"); + goto out; + } + comp_temp =3D bme680_compensate_temp(data, adc_temp); + t_fine =3D bme680_calc_t_fine(data, adc_temp); + + /* Pressure calculations */ + adc_press =3D FIELD_GET(BME680_MEAS_TRIM_MASK, get_unaligned_be24(&data->= buf[2])); + if (adc_press =3D=3D BME680_MEAS_SKIPPED) { + dev_err(data->dev, "reading pressure skipped\n"); + goto out; + } + comp_press =3D bme680_compensate_press(data, adc_press, t_fine); + pr_info("comp_press: %d\n", comp_press); + + /* Humidity calculations */ + adc_humid =3D get_unaligned_be16(&data->buf[8]); + if (adc_humid =3D=3D BME680_MEAS_SKIPPED) { + dev_err(data->dev, "reading humidity skipped\n"); + goto out; + } + comp_humid =3D bme680_compensate_humid(data, adc_humid, t_fine); + pr_info("comp_humid: %d\n", comp_humid); + + /* Gas calculations */ + gas_regs_val =3D get_unaligned_be16(&data->buf[13]); + adc_gas_res =3D FIELD_GET(BME680_ADC_GAS_RES, gas_regs_val); + if ((gas_regs_val & BME680_GAS_STAB_BIT) =3D=3D 0) { + dev_err(data->dev, "heater failed to reach the target temperature\n"); + goto out; + } + gas_range =3D FIELD_GET(BME680_GAS_RANGE_MASK, gas_regs_val); + comp_gas_res =3D bme680_compensate_gas(data, adc_gas_res, gas_range); + pr_info("comp_gas_res: %d\n", comp_gas_res); + + chans[0] =3D comp_temp; + chans[1] =3D comp_press; + chans[2] =3D comp_humid; + chans[3] =3D comp_gas_res; + + /* Push to buffer */ + iio_push_to_buffers_with_timestamp(indio_dev, &data->buffer, + iio_get_time_ns(indio_dev)); +out: + iio_trigger_notify_done(indio_dev->trig); + return IRQ_HANDLED; +} + +static int bme680_buffer_preenable(struct iio_dev *indio_dev) +{ + struct bme680_data *data =3D iio_priv(indio_dev); + + pm_runtime_get_sync(data->dev); + + return 0; +} + +static int bme680_buffer_postdisable(struct iio_dev *indio_dev) +{ + struct bme680_data *data =3D iio_priv(indio_dev); + + pm_runtime_mark_last_busy(data->dev); + pm_runtime_put_autosuspend(data->dev); + + return 0; +} + +static const struct iio_buffer_setup_ops bme680_buffer_setup_ops =3D { + .preenable =3D bme680_buffer_preenable, + .postdisable =3D bme680_buffer_postdisable, +}; + static void bme680_regulators_disable(void *data) { struct regulator_bulk_data *supplies =3D data; @@ -1032,6 +1189,7 @@ int bme680_core_probe(struct device *dev, struct regm= ap *regmap, indio_dev->name =3D name; indio_dev->channels =3D bme680_channels; indio_dev->num_channels =3D ARRAY_SIZE(bme680_channels); + indio_dev->available_scan_masks =3D bme680_avail_scan_masks; indio_dev->info =3D &bme680_info; indio_dev->modes =3D INDIO_DIRECT_MODE; =20 @@ -1088,6 +1246,14 @@ int bme680_core_probe(struct device *dev, struct reg= map *regmap, return dev_err_probe(dev, ret, "failed to set gas config data\n"); =20 + ret =3D devm_iio_triggered_buffer_setup(data->dev, indio_dev, + iio_pollfunc_store_time, + bme680_trigger_handler, + &bme680_buffer_setup_ops); + if (ret) + return dev_err_probe(data->dev, ret, + "iio triggered buffer setup failed\n"); + /* Enable runtime PM */ pm_runtime_get_noresume(dev); pm_runtime_set_active(dev); --=20 2.43.0 From nobody Wed Nov 27 08:38:17 2024 Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.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 9B21A1EF93F; Thu, 10 Oct 2024 21:00:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728594059; cv=none; b=IS9MXIy1bsjEyRxP2mIJ2Jg91H2wOH0qBYG5S75kzEIhu48cQxPTGL7PsW12h+VGfWvkIz4tK8bmMS8EsZj3fM7Oork3ESMWoCdyowgb0juH8TfjBFfSwtx2jmobLQqh6CZCXbig5GYckXJd9ddmiwC121q3SgeYCNPmFK/evuY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728594059; c=relaxed/simple; bh=htghE5bfd+kQ4viLBkQpuFbt4H05U95ieqRgBCY1ekg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mHo18/fln8ciKUIHXYny0elq5+zzGeqTeDYZUkcDlQg51BvQR/X2qqnLU9+eZ5S6xAyfpMk+EkUomlRFeOtztDBCyNEYdoDzVcn3Xw0StbN1bzgzJ9iw++MAJzDtf9qhqUbD/jrXZYyoeQftdBgkBW1XplN/VJCeaxtSO+5PYic= 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=WD+NH7PG; arc=none smtp.client-ip=209.85.167.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="WD+NH7PG" Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-5398b589032so2384441e87.1; Thu, 10 Oct 2024 14:00:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728594056; x=1729198856; 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=hFZcG4G/nDJlbBxKx5ip52fFFHl5Oj4RpUgHu+Xf+xI=; b=WD+NH7PGwIghdl550yLg+Ylq/8yxC+g/pSmuMnNnsWN+VnIAkY9qC0sw04HVjSeSaq 5QsLrz5XaYrX7Gpgoxx4B/brRBxvt5Hv7deBQbuCmi9UZvSIXMWISIbHiOeol/v1Gx5T GMYI2cnX5YhiYF4qHqC5YCs829k5wIlMXq+6IlW4QZatTE/wkJmwv4Fsku9n5LSTUkLF 7rLqEmKtWnZGdNL6XyYJMz+aB1yDk+IJ3aqE38udIBvasPeR66dlPELAJVXAdeXKC9J+ QmzGxpKZDHG+smSowW9Et0YeCfofRA0HUZPv0t+iEh3b+jhPOoqSh9UltOwa/mUpqLHY 2lVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728594056; x=1729198856; 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=hFZcG4G/nDJlbBxKx5ip52fFFHl5Oj4RpUgHu+Xf+xI=; b=Cy7WVBOV5gvGbVa6PxNc484YpeWkEK+LaMGZB0ngkXDPdDrQqgUg1qcsyepJUlhbFc LM3RPfMcIS539fTd9rbcm7+eQQWC38yBhrURq8ScFoELF49l5qafmy8f1O/M3KcOrlSx LS3JTJk4yiPdnwFDnsK7A/0NnD2U90f3Zo3lFoVnXxhrT2dOzWSbe0J/+VTPSAvopebW +XkeE8UK6oVOxdE9lx/kMP1dQGV44zYpHulgZxFiKAi81AWEOqoiM+jJflsGLbxiaWf2 T4vUC2xlQFKWhPY576tD5UHKKkYprKHjROwm1xoQJN8VGxM7shs/gdeTSrS5YxLRjWLt VmYw== X-Forwarded-Encrypted: i=1; AJvYcCVFnaLR/sct0eTj8jIfqcB7R+9zyJ26OwLt8Z37xglorwHRyiBzYQ9WnNyaZ2caE4nFNys6Czzv7q/s@vger.kernel.org, AJvYcCWGoexOU+QX1lsj6mHIlDvvtsZ/mcIRBvpQ7FbHt2ITEfXA0Lw+a+coxj+AetzOZ+xxgh7p1FZe/fa3@vger.kernel.org, AJvYcCWfRJSxIE3OM4khWShJyUNVwbydObHNdhEHR/o4tO/hzwECzNNPp56Llz4l4ifUTeAqaVt8DVCTFBlLveuS@vger.kernel.org X-Gm-Message-State: AOJu0YyUh6dfT6yb5Q245u/pfgd78xmKPUA9TUwVelU0TPlPjPH4imJ+ zHGlPEiiUR0mfjPt4pZzpS1p/pLwvypJ6ZqoKzrot6xQP0KeoQXD X-Google-Smtp-Source: AGHT+IHUHptKoHrqPPCbXGaA3a+T1isiiRkGcpjAvzUotIy4gQ6iWdZtolCvWzro8Oe+sONYrOIMQQ== X-Received: by 2002:a05:6512:108a:b0:539:901c:e2e with SMTP id 2adb3069b0e04-539da598edcmr68580e87.58.1728594055542; Thu, 10 Oct 2024 14:00:55 -0700 (PDT) Received: from vamoirid-laptop.. ([2a04:ee41:82:7577:7eab:ec9d:62da:64f5]) by smtp.googlemail.com with ESMTPSA id a640c23a62f3a-a99a7f25f4dsm135692566b.68.2024.10.10.14.00.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 14:00:54 -0700 (PDT) From: vamoirid To: jic23@kernel.org, lars@metafoo.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org Cc: vassilisamir@gmail.com, anshulusr@gmail.com, gustavograzs@gmail.com, andriy.shevchenko@linux.intel.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 13/13] iio: chemical: bme680: Add support for preheat current Date: Thu, 10 Oct 2024 23:00:30 +0200 Message-ID: <20241010210030.33309-14-vassilisamir@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241010210030.33309-1-vassilisamir@gmail.com> References: <20241010210030.33309-1-vassilisamir@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Vasileios Amoiridis Add functionality to inject a specified amount of current to the heating plate before the start of the gas measurement to allow the sensor to reach faster to the requested temperature. Signed-off-by: Vasileios Amoiridis --- drivers/iio/chemical/bme680.h | 1 + drivers/iio/chemical/bme680_core.c | 38 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/drivers/iio/chemical/bme680.h b/drivers/iio/chemical/bme680.h index e7eed2962baa..c658cb631b52 100644 --- a/drivers/iio/chemical/bme680.h +++ b/drivers/iio/chemical/bme680.h @@ -42,6 +42,7 @@ #define BME680_RHRANGE_MASK GENMASK(5, 4) #define BME680_REG_RES_HEAT_VAL 0x00 #define BME680_RSERROR_MASK GENMASK(7, 4) +#define BME680_REG_IDAC_HEAT_0 0x50 #define BME680_REG_RES_HEAT_0 0x5A #define BME680_REG_GAS_WAIT_0 0x64 #define BME680_ADC_GAS_RES GENMASK(15, 6) diff --git a/drivers/iio/chemical/bme680_core.c b/drivers/iio/chemical/bme6= 80_core.c index df6ae4355902..6cdf8b9dbf2b 100644 --- a/drivers/iio/chemical/bme680_core.c +++ b/drivers/iio/chemical/bme680_core.c @@ -126,6 +126,7 @@ struct bme680_data { u8 oversampling_temp; u8 oversampling_press; u8 oversampling_humid; + u8 preheat_curr; u16 heater_dur; u16 heater_temp; =20 @@ -223,6 +224,12 @@ static const struct iio_chan_spec bme680_channels[] = =3D { }, }, IIO_CHAN_SOFT_TIMESTAMP(4), + { + .type =3D IIO_CURRENT, + .info_mask_separate =3D BIT(IIO_CHAN_INFO_RAW), + .output =3D 1, + .scan_index =3D 5, + }, }; =20 static int bme680_read_calib(struct bme680_data *data, @@ -569,6 +576,12 @@ static u8 bme680_calc_heater_dur(u16 dur) return durval; } =20 +/* Taken from datasheet, section 5.3.3 */ +static u8 bme680_calc_heater_preheat_current(u8 curr) +{ + return 8 * curr - 1; +} + static int bme680_set_mode(struct bme680_data *data, enum bme680_op_mode m= ode) { struct device *dev =3D regmap_get_device(data->regmap); @@ -673,6 +686,19 @@ static int bme680_chip_config(struct bme680_data *data) return 0; } =20 +static int bme680_preheat_curr_config(struct bme680_data *data, u8 val) +{ + u8 heatr_curr; + int ret; + + heatr_curr =3D bme680_calc_heater_preheat_current(val); + ret =3D regmap_write(data->regmap, BME680_REG_IDAC_HEAT_0, heatr_curr); + if (ret < 0) + dev_err(data->dev, "failed to write idac_heat_0 register\n"); + + return ret; +} + static int bme680_gas_config(struct bme680_data *data) { struct device *dev =3D regmap_get_device(data->regmap); @@ -701,6 +727,10 @@ static int bme680_gas_config(struct bme680_data *data) return ret; } =20 + ret =3D bme680_preheat_curr_config(data, data->preheat_curr); + if (ret) + return ret; + /* Enable the gas sensor and select heater profile set-point 0 */ ret =3D regmap_update_bits(data->regmap, BME680_REG_CTRL_GAS_1, BME680_RUN_GAS_MASK | BME680_NB_CONV_MASK, @@ -967,6 +997,13 @@ static int __bme680_write_raw(struct iio_dev *indio_de= v, =20 return bme680_chip_config(data); } + case IIO_CHAN_INFO_RAW: + { + if (chan->type !=3D IIO_CURRENT) + return -EINVAL; + + return bme680_preheat_curr_config(data, (u8)val); + } default: return -EINVAL; } @@ -1199,6 +1236,7 @@ int bme680_core_probe(struct device *dev, struct regm= ap *regmap, data->oversampling_temp =3D 8; /* 8X oversampling rate */ data->heater_temp =3D 320; /* degree Celsius */ data->heater_dur =3D 150; /* milliseconds */ + data->preheat_curr =3D 0; /* milliamps */ =20 regulator_bulk_set_supply_names(data->supplies, bme680_supply_names, BME680_NUM_SUPPLIES); --=20 2.43.0