From patchwork Sun Oct 15 15:16:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Angel Iglesias X-Patchwork-Id: 13422274 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA466CDB47E for ; Sun, 15 Oct 2023 15:17:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229522AbjJOPRy (ORCPT ); Sun, 15 Oct 2023 11:17:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230026AbjJOPRy (ORCPT ); Sun, 15 Oct 2023 11:17:54 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63D6DAB; Sun, 15 Oct 2023 08:17:52 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-4075c58ac39so37847475e9.3; Sun, 15 Oct 2023 08:17:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697383070; x=1697987870; 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=bqQVd6iN7ettmPvcpD+SNx5dxlU6xrnXDXy31g/k6O4=; b=mFESidvugez4PIQf+EWQ1UdutKqMqZdMhAJaYnfxRjmwODBuzJb/Tvp9S08mlUVmPm OdqEa/XwhbhkmOqs4w5O61njeMVGeVYRSTxNL9We6BvdSF/WFsU5IOiPglqw9EBQfMDh 5GnVi1y9RQvvIk9zNYLmIqUQTT7ME8Iwmf1l+xFOwe0XcnIUuTcRSyUJEgv8gQsyyEn1 wwcKHfSoOXk0rpBrOsniX3b47FE+CB7moDslsiZZx4UjpDY49WKnf/t7CGc0a0pvhQvp c16b2vM52UCqYV3s4Bk4GUEAnkD+TVklFFRz9XGOt5Wzi6M4U90+Haifs7g7CTHd4WzF ycEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697383070; x=1697987870; 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=bqQVd6iN7ettmPvcpD+SNx5dxlU6xrnXDXy31g/k6O4=; b=sIQS/ep9jFxsgD3HbQSRhYs0uCZZThLUy39qdgDBaXzycPEqscV3Uc17KTpY93QzIi zRb/b1Qe4sAfkp7mH3RMtpmDK8TkL1DoZgepEDB7lBf/mE4+yDsjcUZurwmswhpi3iJr ZlenD4RrxzhSSUyEnqSJ/R6dH0KxKn+af5TGc8W9CtrKaz4N3zo38sO5kNGmYqk+FgP3 J/t5zs1kMLOcmr38BUhVcN/8U+R73Qs3Vak2CW3MtXddKaLHJrAzCS89xUfsD4gNzjfj KrjbyClqcIYWG/9Rh37SvQdLnt3ud/sPuJ0WomNq/xvz763zERkg8MID0OaLMb0iFZA6 aowQ== X-Gm-Message-State: AOJu0YxDOVOLqUyNNDg0fdkSSaJaAEzH3CJrYN4KB3aL+YAeidfGUJb4 DVSNhwGZ81SiOt1gsv+w5qcRhhnT1M8= X-Google-Smtp-Source: AGHT+IEkH5/TqzpKkZK9Q9e+yg4joEJk2m4PawTWrRtcQEe1RUF8HHqNHkK84aVcercLivKQy1UlrQ== X-Received: by 2002:a05:600c:2054:b0:402:906:1e87 with SMTP id p20-20020a05600c205400b0040209061e87mr26952161wmg.31.1697383070442; Sun, 15 Oct 2023 08:17:50 -0700 (PDT) Received: from localhost.localdomain (13.red-83-35-58.dynamicip.rima-tde.net. [83.35.58.13]) by smtp.gmail.com with ESMTPSA id n35-20020a05600c3ba300b003fc16ee2864sm4712455wms.48.2023.10.15.08.17.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 08:17:50 -0700 (PDT) From: Angel Iglesias To: linux-iio@vger.kernel.org Cc: Biju Das , linux-kernel@vger.kernel.org, Jonathan Cameron , Lars-Peter Clausen , Angel Iglesias , Andy Shevchenko , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?q?=C3=B6nig?= Subject: [PATCH 1/5] iio: pressure: bmp280: Use i2c_get_match_data() Date: Sun, 15 Oct 2023 17:16:23 +0200 Message-ID: X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Biju Das Replace device_get_match_data() and id lookup for retrieving match data by i2c_get_match_data(). Signed-off-by: Biju Das diff --git a/drivers/iio/pressure/bmp280-i2c.c b/drivers/iio/pressure/bmp280-i2c.c index dbe630ad05b5..b3e069730f97 100644 --- a/drivers/iio/pressure/bmp280-i2c.c +++ b/drivers/iio/pressure/bmp280-i2c.c @@ -11,9 +11,7 @@ static int bmp280_i2c_probe(struct i2c_client *client) const struct bmp280_chip_info *chip_info; const struct i2c_device_id *id = i2c_client_get_device_id(client); - chip_info = device_get_match_data(&client->dev); - if (!chip_info) - chip_info = (const struct bmp280_chip_info *) id->driver_data; + chip_info = i2c_get_match_data(client); regmap = devm_regmap_init_i2c(client, chip_info->regmap_config); if (IS_ERR(regmap)) { From patchwork Sun Oct 15 15:16:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Angel Iglesias X-Patchwork-Id: 13422275 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A12EDCDB47E for ; Sun, 15 Oct 2023 15:18:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230037AbjJOPSB (ORCPT ); Sun, 15 Oct 2023 11:18:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230049AbjJOPR7 (ORCPT ); Sun, 15 Oct 2023 11:17:59 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49CD2AB; Sun, 15 Oct 2023 08:17:58 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-40572aeb73cso37434485e9.3; Sun, 15 Oct 2023 08:17:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697383076; x=1697987876; 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=VeqxvK0uzWzz37Q8uuFTlmCXM4qg5qnRs/tMuLh55uE=; b=CNxaX3FUbbNckzulXhmeasF4Q7mw2Bu4c7cHTauiPAaG9T6NiLuoRwdTk1HTM6IHh3 mdVuAUQfx7KtzoVShokBEqOqWLZz1rwMHKcW64w/FlzZ+dwaQb5E0qJX/YL5SJsNsadS CEQ4Zulg8WCieAU8W7kjHRvHV02BdEpXmmDroTSYhDSc+j3MSyoTRNcQCN+EHrAiqGNH 8NRL7nrU4yfSDHkMHtjZwA2EyaAlHGd30cbfGdpbwFRlYaLsxKg6AfThsmLOpC6znzEG tlQ3h5RJDkkyk7z9Ko5qs+TAZ0kcTu58sjxzjMGuIK8pQ1Ggv11OhZGl67shjwfRB69O jzDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697383076; x=1697987876; 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=VeqxvK0uzWzz37Q8uuFTlmCXM4qg5qnRs/tMuLh55uE=; b=M29AJosP7ERYPJuSi1r+/jVsRAa6P612pkKxg3+OFEtNsT6ajlacEdgGXtb3cpTqM6 njMH+mBji4IVpIXYlCe/Th6a9Y8hsvSAsvQGc93JJ64KmWpW3mUBQy8chaqXEJzbdL9A nVC7lbPWXjCj7/CD6Q33lBTXJLtwSzez/nk3bl5iLbI/7wHxPl1F5RkwafT5mNPwNa2G NyofRB7Ih5p60yjtofD7ZBN9Xl6ra4mURTfIwnfJoOcWYoqxzU1EaGWVD+oW8g3J2biN X3JNpIEVCDmTVbBl3ux3HmkCcts6QtaavFfbOTA9WcqpRHxgQP1VZsUTf/e89ynol2pW 1FMA== X-Gm-Message-State: AOJu0Yw4mo846f/kvApbjCAk+lqFYCsjeptCUei2aZSAk7eFsk5qf+aS FwSy/+HS52178wDKoGMP1niRNepMqIs= X-Google-Smtp-Source: AGHT+IGgCeGEK/lYbOLRjUeDidJ1lvIUgMMm8ayU1vK1oeSgFTuGMdGygsWpxdLfZJ01peRIeDpC0w== X-Received: by 2002:a1c:6a0d:0:b0:3fc:1a6:7764 with SMTP id f13-20020a1c6a0d000000b003fc01a67764mr27721664wmc.16.1697383076236; Sun, 15 Oct 2023 08:17:56 -0700 (PDT) Received: from localhost.localdomain (13.red-83-35-58.dynamicip.rima-tde.net. [83.35.58.13]) by smtp.gmail.com with ESMTPSA id n35-20020a05600c3ba300b003fc16ee2864sm4712455wms.48.2023.10.15.08.17.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 08:17:56 -0700 (PDT) From: Angel Iglesias To: linux-iio@vger.kernel.org Cc: Biju Das , linux-kernel@vger.kernel.org, Angel Iglesias , Jonathan Cameron , Lars-Peter Clausen , Andy Shevchenko , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?q?=C3=B6nig?= Subject: [PATCH 2/5] iio: pressure: bmp280: Use spi_get_device_match_data() Date: Sun, 15 Oct 2023 17:16:24 +0200 Message-ID: <553d1e9187fac10094116d3a1688b66bebd60cd2.1697381932.git.ang.iglesiasg@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Use the spi_get_device_match_data() helper instead of device_get_match_data() and the fallback match_id logic. Signed-off-by: Angel Iglesias diff --git a/drivers/iio/pressure/bmp280-spi.c b/drivers/iio/pressure/bmp280-spi.c index 1dff9bb7c4e9..2eed483a8cc4 100644 --- a/drivers/iio/pressure/bmp280-spi.c +++ b/drivers/iio/pressure/bmp280-spi.c @@ -58,9 +58,7 @@ static int bmp280_spi_probe(struct spi_device *spi) return ret; } - chip_info = device_get_match_data(&spi->dev); - if (!chip_info) - chip_info = (const struct bmp280_chip_info *) id->driver_data; + chip_info = spi_get_device_match_data(spi); regmap = devm_regmap_init(&spi->dev, &bmp280_regmap_bus, From patchwork Sun Oct 15 15:16:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Angel Iglesias X-Patchwork-Id: 13422276 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2E74CDB47E for ; Sun, 15 Oct 2023 15:18:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230026AbjJOPSL (ORCPT ); Sun, 15 Oct 2023 11:18:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230142AbjJOPSK (ORCPT ); Sun, 15 Oct 2023 11:18:10 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B529106; Sun, 15 Oct 2023 08:18:04 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-40684f53bfcso34445945e9.0; Sun, 15 Oct 2023 08:18:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697383082; x=1697987882; 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=bGL0YH1al5bgYEOMpJxA3ocj/opSXqoY++n/reNrEe0=; b=m1w304aMx90BQVokAicwtTBiENyzY7q8VNXoCLJEqAF/+Z2keC6vZ7GB6TFcsoN/T5 e+hx5Lznnzq7rB9pxFi0ImdP2rxZXdc9Zu4iOMcrROAJj1zyJSZIn1v9WJnZMqepMZvZ 0fh7n+CriQ3d7VovZ48K8V1/mKeHXVOZsYq3YJig+0KhBysdRT1UGLZExecM6ChXuhC8 WL3TMEOlvkjMRVxDzLTuIfeMOOGzwNKptik1Xl4N5UGzw4h39oqMVNS5SQy5Ba4GxwoH 6aZB+K1DGQDoq2mBG04jHaor9td4iQb1mrYeLpgSzkByXEczzf03qTcq489jFE1u62rJ KCdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697383082; x=1697987882; 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=bGL0YH1al5bgYEOMpJxA3ocj/opSXqoY++n/reNrEe0=; b=rT1kigJS3Tng7haArCBTNjmoz2QNkradwaFdTtlhFHnpc8x0E4eUp3r5APa+vPtcNa wZ3x3jd6cOHAjnbFrlA8RRUMl6/UAd6hqJq9cept9iggumcglIVl4yAHjuljE5h5LQUJ zS130VujncmrRu/X46/gHnjs5qza/Hx2wIwVzTgxqFsqyP9mpSU0qHrXRIXjRXPCnH4F o7ePRLB6FT4JfNA8xvFoKyUOeeK8/l8UaZZyIQXNxpELuzXQOYTys+8gB0r4pvXtQQgy A/au58C1Hlfcc/wjQSNiGTsuMs1VDFbrTBf87MySjj08yz9tk8RVzYjRS719Ve9OrGdS FbzA== X-Gm-Message-State: AOJu0YxqllE4wzyo+iYtBxEhaBM8lK6PHFc9JXIOyfhO7qtb8qv2I5FB wJlH4Z47maSyU1Pc3r9t6uQrlKZNGB0= X-Google-Smtp-Source: AGHT+IHbKiw2KshL5xnnoHRY/OyeIGCE+QyRr3scTeOYIQmiUnEQOdlTCGm3ZO7AXNAzyTirIR5TNg== X-Received: by 2002:a05:600c:214f:b0:405:3251:47a1 with SMTP id v15-20020a05600c214f00b00405325147a1mr27399649wml.40.1697383082133; Sun, 15 Oct 2023 08:18:02 -0700 (PDT) Received: from localhost.localdomain (13.red-83-35-58.dynamicip.rima-tde.net. [83.35.58.13]) by smtp.gmail.com with ESMTPSA id n35-20020a05600c3ba300b003fc16ee2864sm4712455wms.48.2023.10.15.08.18.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 08:18:01 -0700 (PDT) From: Angel Iglesias To: linux-iio@vger.kernel.org Cc: Biju Das , linux-kernel@vger.kernel.org, Angel Iglesias , Jonathan Cameron , Lars-Peter Clausen , Andy Shevchenko , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?q?=C3=B6nig?= Subject: [PATCH 3/5] iio: pressure: bmp280: Rearrange vars in reverse xmas tree order Date: Sun, 15 Oct 2023 17:16:25 +0200 Message-ID: <7db5fe65a78513137206ae6b33abb1e48d356fbf.1697381932.git.ang.iglesiasg@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Small cleanup reordering local variable declarations following reverse christmas tree convention. Signed-off-by: Angel Iglesias diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index 6089f3f9d8f4..ea02a623bb58 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -766,8 +766,8 @@ static const struct iio_info bmp280_info = { static int bmp280_chip_config(struct bmp280_data *data) { - u8 osrs = FIELD_PREP(BMP280_OSRS_TEMP_MASK, data->oversampling_temp + 1) | - FIELD_PREP(BMP280_OSRS_PRESS_MASK, data->oversampling_press + 1); + u8 osrs = FIELD_PREP(BMP280_OSRS_PRESS_MASK, data->oversampling_press + 1) | + FIELD_PREP(BMP280_OSRS_TEMP_MASK, data->oversampling_temp + 1); int ret; ret = regmap_write_bits(data->regmap, BMP280_REG_CTRL_MEAS, diff --git a/drivers/iio/pressure/bmp280-i2c.c b/drivers/iio/pressure/bmp280-i2c.c index b3e069730f97..34e3bc758493 100644 --- a/drivers/iio/pressure/bmp280-i2c.c +++ b/drivers/iio/pressure/bmp280-i2c.c @@ -7,9 +7,9 @@ static int bmp280_i2c_probe(struct i2c_client *client) { - struct regmap *regmap; - const struct bmp280_chip_info *chip_info; const struct i2c_device_id *id = i2c_client_get_device_id(client); + const struct bmp280_chip_info *chip_info; + struct regmap *regmap; chip_info = i2c_get_match_data(client); diff --git a/drivers/iio/pressure/bmp280-spi.c b/drivers/iio/pressure/bmp280-spi.c index 2eed483a8cc4..433d6fac83c4 100644 --- a/drivers/iio/pressure/bmp280-spi.c +++ b/drivers/iio/pressure/bmp280-spi.c @@ -14,8 +14,7 @@ static int bmp280_regmap_spi_write(void *context, const void *data, size_t count) { - struct device *dev = context; - struct spi_device *spi = to_spi_device(dev); + struct spi_device *spi = to_spi_device(context); u8 buf[2]; memcpy(buf, data, 2); @@ -31,8 +30,7 @@ static int bmp280_regmap_spi_write(void *context, const void *data, static int bmp280_regmap_spi_read(void *context, const void *reg, size_t reg_size, void *val, size_t val_size) { - struct device *dev = context; - struct spi_device *spi = to_spi_device(dev); + struct spi_device *spi = to_spi_device(context); return spi_write_then_read(spi, reg, reg_size, val, val_size); } From patchwork Sun Oct 15 15:16:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Angel Iglesias X-Patchwork-Id: 13422277 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9AF6ACDB47E for ; Sun, 15 Oct 2023 15:18:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230222AbjJOPSS (ORCPT ); Sun, 15 Oct 2023 11:18:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230142AbjJOPSO (ORCPT ); Sun, 15 Oct 2023 11:18:14 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6AF1FB; Sun, 15 Oct 2023 08:18:10 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-40776b200e5so16255555e9.2; Sun, 15 Oct 2023 08:18:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697383089; x=1697987889; 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=NMdJnM8oHQ7eHl+UF9y/ARFxYpaLioFllg8ThKJYIfg=; b=M+UtqsvAtnViL34/Rjoh/Riubp27o6OMLkaELkSqKabmDk9Hx6aytZdkFYZ3PsvhIg 07Rwaa7mu5YW5gDPLiqrPUZlG1ukUVz4JyldU8WprJWVNRknYHDxzn4+9v6LI5k7XaKK sU6wLuc9aK6sENiCTdIEd1P+4bmSCOUoQDThmS0PnVq0W0rkQoFXVOqUKLp8Bt22QCOW 3w4/dUJgizxT09s0HDUUOtN8VzUowkNDvzvbH0jmdEH+GFDO/9RJEl7X2T0W5tFN0Y3+ IY6C7z/9yClKXyoFezHjbPqDVcnfsMqiQ4rrknNnWqAHT2YTcokQ9bXPZi/e7828oq+F TcBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697383089; x=1697987889; 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=NMdJnM8oHQ7eHl+UF9y/ARFxYpaLioFllg8ThKJYIfg=; b=CTuaJA3Lao6Dk6fmeeoR4mS3pp+0bvl7Aysn64zOgl82bigFiFFZySiZQeb/0p2T94 G4cueCf+T+jBm2l+tKRr0pdk3Oufl4d16mcuPQH2nwwDgueITvE34Xx7qh01ywLXJ0uz 6cTmxq4F0amYPJM/i7glGY6wzCtTbobruLCveNoDfGctOXEhSl3sWl+xliHDe9azIbop j96YeeJq3yJ5dEkZkr64yYbrTNR3eMwFeYP7h0lIjnMD09yNZtO9QkYnJAswAgP4p95T JoX8eiZEx8UftagCfIPifpjG027TB/yZvxrihV5jXdVcmvfeD3WavMkFq5Hbtf0pydKd 3SHA== X-Gm-Message-State: AOJu0Yx4gMlPsKsoS/2qRBcOFM1NgTByt7JXJJEbUjm3KOGatfZZO1eG TwLmyORjTEAocIu5ycG5hjxRWa1r2Zk= X-Google-Smtp-Source: AGHT+IEHmVYTABMP6Rxh9SuqXGxC1tzOfrC1ZjC7nUsGzMqE3KM8pSLzVxxYQow+zZinwWWmWuP8zg== X-Received: by 2002:a05:600c:3586:b0:406:849c:52c3 with SMTP id p6-20020a05600c358600b00406849c52c3mr26286281wmq.22.1697383088044; Sun, 15 Oct 2023 08:18:08 -0700 (PDT) Received: from localhost.localdomain (13.red-83-35-58.dynamicip.rima-tde.net. [83.35.58.13]) by smtp.gmail.com with ESMTPSA id n35-20020a05600c3ba300b003fc16ee2864sm4712455wms.48.2023.10.15.08.18.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 08:18:07 -0700 (PDT) From: Angel Iglesias To: linux-iio@vger.kernel.org Cc: Biju Das , linux-kernel@vger.kernel.org, Angel Iglesias , Jonathan Cameron , Lars-Peter Clausen , Andy Shevchenko , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?q?=C3=B6nig?= Subject: [PATCH 4/5] iio: pressure: bmp280: Allow multiple chips id per family of devices Date: Sun, 15 Oct 2023 17:16:26 +0200 Message-ID: <9f8489d82325b2dfb5c8c71c3d558d509b2b01bf.1697381932.git.ang.iglesiasg@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Improve device detection in certain chip families known to have various chip ids. Signed-off-by: Angel Iglesias diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index ea02a623bb58..e3bb4d7906a9 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -38,6 +38,7 @@ #include #include /* For irq_get_irq_data() */ #include +#include #include #include @@ -794,10 +795,12 @@ static int bmp280_chip_config(struct bmp280_data *data) } static const int bmp280_oversampling_avail[] = { 1, 2, 4, 8, 16 }; +static const u8 bmp280_chip_ids[] = { BMP280_CHIP_ID }; const struct bmp280_chip_info bmp280_chip_info = { .id_reg = BMP280_REG_ID, - .chip_id = BMP280_CHIP_ID, + .chip_id = bmp280_chip_ids, + .num_chip_id = ARRAY_SIZE(bmp280_chip_ids), .regmap_config = &bmp280_regmap_config, .start_up_time = 2000, .channels = bmp280_channels, @@ -846,9 +849,12 @@ static int bme280_chip_config(struct bmp280_data *data) return bmp280_chip_config(data); } +static const u8 bme280_chip_ids[] = { BME280_CHIP_ID }; + const struct bmp280_chip_info bme280_chip_info = { .id_reg = BMP280_REG_ID, - .chip_id = BME280_CHIP_ID, + .chip_id = bme280_chip_ids, + .num_chip_id = ARRAY_SIZE(bme280_chip_ids), .regmap_config = &bmp280_regmap_config, .start_up_time = 2000, .channels = bmp280_channels, @@ -1220,10 +1226,12 @@ static int bmp380_chip_config(struct bmp280_data *data) static const int bmp380_oversampling_avail[] = { 1, 2, 4, 8, 16, 32 }; static const int bmp380_iir_filter_coeffs_avail[] = { 1, 2, 4, 8, 16, 32, 64, 128}; +static const u8 bmp380_chip_ids[] = { BMP380_CHIP_ID }; const struct bmp280_chip_info bmp380_chip_info = { .id_reg = BMP380_REG_ID, - .chip_id = BMP380_CHIP_ID, + .chip_id = bmp380_chip_ids, + .num_chip_id = ARRAY_SIZE(bmp380_chip_ids), .regmap_config = &bmp380_regmap_config, .start_up_time = 2000, .channels = bmp380_channels, @@ -1720,10 +1728,12 @@ static int bmp580_chip_config(struct bmp280_data *data) } static const int bmp580_oversampling_avail[] = { 1, 2, 4, 8, 16, 32, 64, 128 }; +static const u8 bmp580_chip_ids[] = { BMP580_CHIP_ID, BMP580_CHIP_ID_ALT }; const struct bmp280_chip_info bmp580_chip_info = { .id_reg = BMP580_REG_CHIP_ID, - .chip_id = BMP580_CHIP_ID, + .chip_id = bmp580_chip_ids, + .num_chip_id = ARRAY_SIZE(bmp580_chip_ids), .regmap_config = &bmp580_regmap_config, .start_up_time = 2000, .channels = bmp380_channels, @@ -1983,10 +1993,12 @@ static int bmp180_chip_config(struct bmp280_data *data) static const int bmp180_oversampling_temp_avail[] = { 1 }; static const int bmp180_oversampling_press_avail[] = { 1, 2, 4, 8 }; +static const u8 bmp180_chip_ids[] = { BMP180_CHIP_ID }; const struct bmp280_chip_info bmp180_chip_info = { .id_reg = BMP280_REG_ID, - .chip_id = BMP180_CHIP_ID, + .chip_id = bmp180_chip_ids, + .num_chip_id = ARRAY_SIZE(bmp180_chip_ids), .regmap_config = &bmp180_regmap_config, .start_up_time = 2000, .channels = bmp280_channels, @@ -2077,6 +2089,7 @@ int bmp280_common_probe(struct device *dev, struct bmp280_data *data; struct gpio_desc *gpiod; unsigned int chip_id; + unsigned int i; int ret; indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); @@ -2142,10 +2155,30 @@ int bmp280_common_probe(struct device *dev, ret = regmap_read(regmap, data->chip_info->id_reg, &chip_id); if (ret < 0) return ret; - if (chip_id != data->chip_info->chip_id) { - dev_err(dev, "bad chip id: expected %x got %x\n", - data->chip_info->chip_id, chip_id); - return -EINVAL; + + for (i = 0; i < data->chip_info->num_chip_id; i++) { + if (chip_id == data->chip_info->chip_id[i]) + break; + } + + if (i == data->chip_info->num_chip_id) { + size_t nbuf; + char *buf; + + // 0x, so four chars per number plus one space + ENDL + if (check_mul_overflow(data->chip_info->num_chip_id, 5, &nbuf)) + return ret; + + buf = kmalloc_array(data->chip_info->num_chip_id, 5, GFP_KERNEL); + if (!buf) + return ret; + + for (i = 0; i < data->chip_info->num_chip_id; i++) + snprintf(&buf[i*5], nbuf - i*5, "0x%x ", data->chip_info->chip_id[i]); + + dev_err(dev, "bad chip id: expected one of [ %s ] got 0x%x\n", buf, chip_id); + kfree(buf); + return ret; } if (data->chip_info->preinit) { diff --git a/drivers/iio/pressure/bmp280.h b/drivers/iio/pressure/bmp280.h index 5c0563ce7572..a230fcfc4a85 100644 --- a/drivers/iio/pressure/bmp280.h +++ b/drivers/iio/pressure/bmp280.h @@ -418,7 +418,8 @@ struct bmp280_data { struct bmp280_chip_info { unsigned int id_reg; - const unsigned int chip_id; + const u8 *chip_id; + int num_chip_id; const struct regmap_config *regmap_config; From patchwork Sun Oct 15 15:16:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Angel Iglesias X-Patchwork-Id: 13422278 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D65BCDB47E for ; Sun, 15 Oct 2023 15:18:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229772AbjJOPSW (ORCPT ); Sun, 15 Oct 2023 11:18:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229779AbjJOPSU (ORCPT ); Sun, 15 Oct 2023 11:18:20 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68F19F5; Sun, 15 Oct 2023 08:18:15 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-40684f53ef3so40329875e9.3; Sun, 15 Oct 2023 08:18:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697383094; x=1697987894; 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=2no0yowA3lGSRYKd2XnR+vjmcZErrr5k9KrUOlR237s=; b=YEz+0dVCd98HgxT5Fm++IXCiCGydtCQjxYQR9jAi/OmjcXfEa/VNmnV7RQaEbLIYz5 VZzYddcLgDa98hNLHimYSOyBwrfVonWzxJoQXgMocJplkKzrUJuQcwnzQiREQr7rp/Xk ELBcDb0iKk7y7OPxtTL4lCg2HbncQetLeNGrFTlcIHinuo8RAdJN2oRdVE6WFVZv8Pfn kLtXz5/H0g4wqBTpjSoqoomW9zPYDcg9WLekYAluBmXhj2o9f8uPygNCigwZuuwAGPcq J4GFK7+Ys3I4bpjHtHgFqGLdojrlSAXnCpFsBGcwuBPfGimRRg09r+2kUf/Y/B8BM5f7 u6iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697383094; x=1697987894; 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=2no0yowA3lGSRYKd2XnR+vjmcZErrr5k9KrUOlR237s=; b=UT8XptV5YltIAjPwo5VSwrRdD5/ag7EGSZz9d2Kn3fNUUKyCQiDDfgL3y/YFaCH6+e jzTZZ+XWvzJPzupc5fQVNL14fJ5IjezizMV1NzfOD304ngYVIR/c0mvpdvT9ZqT728LJ bWI6vNs+4yFvu+GSJFtE0DoQEFGRu5b31bvNn6f2aMJUDR56tGxCSw9Gsa2AZ8fARMw+ HzxaD/YtWuGP6gtj4rftr2VWMU5F/HwNDKTq3awIeuVcvdxOkbZki7RwmT1ZJfeNtAY/ QC9RHu3FtrrzFNUwWMySmSy2c50QJyRt8mwL9JaTFSrP02f+pvnxfzhK6Vc1wK/L/NOE d0eA== X-Gm-Message-State: AOJu0YynmWRLMWY+fiK+6DD8bwzxC7DWgWKWH6V6gHVn9XiYSnwCS9iG 6vI6PFZLkXmoX2BMrax9JSKoBGYw6OA= X-Google-Smtp-Source: AGHT+IH51KFZBCDp8L+Fmb1DEJVofovwBikpQNVLxXIdZSEJ/sC9YckYnbwPbbQ4k0eJkqfLG3lFyA== X-Received: by 2002:a05:600c:259:b0:403:b64:ad0a with SMTP id 25-20020a05600c025900b004030b64ad0amr25954953wmj.26.1697383093909; Sun, 15 Oct 2023 08:18:13 -0700 (PDT) Received: from localhost.localdomain (13.red-83-35-58.dynamicip.rima-tde.net. [83.35.58.13]) by smtp.gmail.com with ESMTPSA id n35-20020a05600c3ba300b003fc16ee2864sm4712455wms.48.2023.10.15.08.18.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 08:18:13 -0700 (PDT) From: Angel Iglesias To: linux-iio@vger.kernel.org Cc: Biju Das , linux-kernel@vger.kernel.org, Angel Iglesias , Jonathan Cameron , Lars-Peter Clausen , Andy Shevchenko , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?q?=C3=B6nig?= Subject: [PATCH 5/5] iio: pressure: bmp280: Add support for BMP390 Date: Sun, 15 Oct 2023 17:16:27 +0200 Message-ID: X-Mailer: git-send-email 2.42.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add BMP390 device ID to the supported IDs on bmp380 sensor family Signed-off-by: Angel Iglesias diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c index e3bb4d7906a9..d2345956ebc8 100644 --- a/drivers/iio/pressure/bmp280-core.c +++ b/drivers/iio/pressure/bmp280-core.c @@ -13,6 +13,7 @@ * https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp280-ds001.pdf * https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bme280-ds002.pdf * https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp388-ds001.pdf + * https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp390-ds002.pdf * https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp581-ds004.pdf * * Notice: @@ -1226,7 +1227,7 @@ static int bmp380_chip_config(struct bmp280_data *data) static const int bmp380_oversampling_avail[] = { 1, 2, 4, 8, 16, 32 }; static const int bmp380_iir_filter_coeffs_avail[] = { 1, 2, 4, 8, 16, 32, 64, 128}; -static const u8 bmp380_chip_ids[] = { BMP380_CHIP_ID }; +static const u8 bmp380_chip_ids[] = { BMP380_CHIP_ID, BMP390_CHIP_ID }; const struct bmp280_chip_info bmp380_chip_info = { .id_reg = BMP380_REG_ID, diff --git a/drivers/iio/pressure/bmp280.h b/drivers/iio/pressure/bmp280.h index a230fcfc4a85..2971bf58f802 100644 --- a/drivers/iio/pressure/bmp280.h +++ b/drivers/iio/pressure/bmp280.h @@ -292,6 +292,7 @@ #define BMP580_CHIP_ID_ALT 0x51 #define BMP180_CHIP_ID 0x55 #define BMP280_CHIP_ID 0x58 +#define BMP390_CHIP_ID 0x60 #define BME280_CHIP_ID 0x60 #define BMP280_SOFT_RESET_VAL 0xB6