Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1563221rwb; Sun, 14 Aug 2022 06:50:13 -0700 (PDT) X-Google-Smtp-Source: AA6agR5uwBd0fSMf9kNZFOiGmaUvNNEdvhkjrsDutQEYbiQ1R6CzHOrOh3MlNqQYIJZI/9i4nodN X-Received: by 2002:a17:907:b04:b0:730:b0d7:eeea with SMTP id h4-20020a1709070b0400b00730b0d7eeeamr8002129ejl.173.1660485013576; Sun, 14 Aug 2022 06:50:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660485013; cv=none; d=google.com; s=arc-20160816; b=IhhiuqGHvjWFaHdlDBam2D078WWfeIcVEoRVTe2UnDta19xOz/dmJT1bD/v4J89cX0 1+f+lraXlUFIINYKEXvGdSVhLQ8pQlJDWrUG2uiFMCB3lYpUPM/HuUH49dbJBUPwnNIz /+os+sWhIvukGa6KEzbTIfC7crr7JMvGuYJT6rowEOORcrv2rdS7LIY6gi02ZLSaMFh5 rAeD8wJdGIYbOYpIAn+J08/cM47Z6klHZuHL9Dp/NEDiAHZ8IDVXapw0LQw3VEP0irtA o2O3+6kGcZBx4uv21nXHyFUqAmRFFcD0yiC0lyF5Sms1ilqcNu8GdwbtrUqBL+tMDcOq TDLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=i19AIu058bTVtO4iK7x2tfSt19XzkTeN92qzqTYOjXg=; b=wUGMLssbZjU8S7JEUAFoWv+WQPma72A/spJsxKJ7OmuTUtHEWtnzI1njhGXO0CsrYA XUFZLdPm5h282SZByrPAB0Q7u8nsqKeBwAK4lIeEA61HK0wE7ylwvB3udzNJ2OvmO0XG AqG46WV2vduetQpOP1kaWGiCXazuoitoHhwmXQ2sWdTEe2VB2XF2yB+0IrkYk3VLROX6 jdvuUGNo0H1fSPAhxSNgUKGn+y9Hi+kBIw9z5nrd+wSDCFnuO35BtK+a9DCBpOqh4cll O39rf3B6s9qDVs0ORDtVLzDX1MgooCsVA6uMZ2nPm6r8lWlA9gmHwzGrNMQU8CzEp8kj qhTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=P5o05DPb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id js22-20020a17090797d600b00731646d634esi6340093ejc.802.2022.08.14.06.49.43; Sun, 14 Aug 2022 06:50:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=P5o05DPb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231403AbiHNNd1 (ORCPT + 99 others); Sun, 14 Aug 2022 09:33:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229379AbiHNNdZ (ORCPT ); Sun, 14 Aug 2022 09:33:25 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 530581759E; Sun, 14 Aug 2022 06:33:24 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 090FEB80AEE; Sun, 14 Aug 2022 13:33:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BFFF0C433D6; Sun, 14 Aug 2022 13:33:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660484001; bh=cXQdMAxMMUixvPWaJ3r9QcDJ3wViHH+mep8Gcae419Y=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=P5o05DPbrLAsxKagWvkNIPOOjaTB4sPKlYcOwxc0NFeKQkvpb9UnCX/OXhaDklARp Zfo7t2f0YA8AjIbdtOWhsJPMmPe6A1n19kOVlrUpTjdiFbK2SKv2MxBSy5zGakCYoa 9a1z62vZOIjInVMDp2qR1i/mzuY3tUZcTMhqmF2esDh8xojw9Wkz1UlMGGQiDG16WU JzRLfJgi7xHj/jVLNYNpBepzYQrH2e9VDdv23S1T+YU3WURAYpkZ0r50r2DCpmYecH aNkspgkQF+6NrkaEMyRWvrmWC18WymC32xd04YPnqX7lM60W/+c3EUVfd6hFqqVb8B GzBl+6u3Oyt/A== Date: Sun, 14 Aug 2022 14:43:50 +0100 From: Jonathan Cameron To: Angel Iglesias , Lars-Peter Clausen Cc: linux-iio , Ulf Hansson , "Rafael J. Wysocki" , Paul Cercueil , linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 1/5] iio: pressure: bmp280: simplify driver initialization logic Message-ID: <20220814144350.7d0282e6@jic23-huawei> In-Reply-To: <602f032955b56eb367177d1de7536f18ad94bc87.1659872590.git.ang.iglesiasg@gmail.com> References: <602f032955b56eb367177d1de7536f18ad94bc87.1659872590.git.ang.iglesiasg@gmail.com> X-Mailer: Claws Mail 4.1.0 (GTK 3.24.34; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 7 Aug 2022 13:54:40 +0200 Angel Iglesias wrote: > Simplified common initialization logic of different sensor types > unifying calibration and initial configuration recovery. > > Default config param values of each sensor type are stored inside > chip_info structure and used to initialize sensor data struct instance. > > The helper functions for read each sensor type calibration are converted > to a callback available on the chip_info struct. > > Revised BMP180 and BMP280 definitions and code functions to use GENMASK > and FIELD_PREP/FIELD_GET utilities to homogenize structure with more > recent drivers, in preparation for the patches adding support for the > BMP380 sensors. > > Suggested-by: Jonathan Cameron > Signed-off-by: Angel Iglesias Hi Angel, not sure if I commented on this before, but this patch is doing several different things, so in the ideal case it would be split into 1: FIELD_PREP/FIELD_GET/GENMASK changes. 2: Chipinfo related changes 3: Maybe the the reordering of defintions of local variables that Andy indirectly referered to. However, this is short enough to be fairly reviewable as it stands so from my point of view I'll accept leaving 1 and 2 combined if it is going to be a lot of work to separate them. Doesn't look like it will be hard but without trying I'm not totally sure! One question inline on what the chip parameter to the calibration functions is there for as it appears unused. Thanks, Jonathan > --- > drivers/iio/pressure/bmp280-core.c | 120 ++++++++++++++++++----------- > drivers/iio/pressure/bmp280.h | 73 +++++++++--------- > 2 files changed, 113 insertions(+), 80 deletions(-) > > diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c > index fe7aa81e7cc9..a109c2609896 100644 > --- a/drivers/iio/pressure/bmp280-core.c > +++ b/drivers/iio/pressure/bmp280-core.c > @@ -16,6 +16,8 @@ > > #define pr_fmt(fmt) "bmp280: " fmt > > +#include > +#include > #include > #include > #include > @@ -107,19 +109,28 @@ struct bmp280_data { > }; > > struct bmp280_chip_info { > + unsigned int id_reg; > + > + int num_channels; > + unsigned int start_up_time; > + > const int *oversampling_temp_avail; > int num_oversampling_temp_avail; > + int oversampling_temp_default; > > const int *oversampling_press_avail; > int num_oversampling_press_avail; > + int oversampling_press_default; > > const int *oversampling_humid_avail; > int num_oversampling_humid_avail; > + int oversampling_humid_default; > > int (*chip_config)(struct bmp280_data *); > int (*read_temp)(struct bmp280_data *, int *); > int (*read_press)(struct bmp280_data *, int *, int *); > int (*read_humid)(struct bmp280_data *, int *, int *); > + int (*read_calib)(struct bmp280_data *, unsigned int); > }; > > /* > @@ -147,15 +158,14 @@ static const struct iio_chan_spec bmp280_channels[] = { > }, > }; > > -static int bmp280_read_calib(struct bmp280_data *data, > - struct bmp280_calib *calib, > - unsigned int chip) > +static int bmp280_read_calib(struct bmp280_data *data, unsigned int chip) > { > int ret; > unsigned int tmp; > __le16 l16; > __be16 b16; > struct device *dev = data->dev; > + struct bmp280_calib *calib = &data->calib.bmp280; > __le16 t_buf[BMP280_COMP_TEMP_REG_COUNT / 2]; > __le16 p_buf[BMP280_COMP_PRESS_REG_COUNT / 2]; > > @@ -611,8 +621,8 @@ static const struct iio_info bmp280_info = { > static int bmp280_chip_config(struct bmp280_data *data) > { > int ret; > - u8 osrs = BMP280_OSRS_TEMP_X(data->oversampling_temp + 1) | > - BMP280_OSRS_PRESS_X(data->oversampling_press + 1); > + u8 osrs = FIELD_PREP(BMP280_OSRS_TEMP_MASK, data->oversampling_temp + 1) | > + FIELD_PREP(BMP280_OSRS_PRESS_MASK, data->oversampling_press + 1); > > ret = regmap_write_bits(data->regmap, BMP280_REG_CTRL_MEAS, > BMP280_OSRS_TEMP_MASK | > @@ -640,21 +650,38 @@ static int bmp280_chip_config(struct bmp280_data *data) > static const int bmp280_oversampling_avail[] = { 1, 2, 4, 8, 16 }; > > static const struct bmp280_chip_info bmp280_chip_info = { > + .id_reg = BMP280_REG_ID, > + .start_up_time = 2000, > + .num_channels = 2, > + > .oversampling_temp_avail = bmp280_oversampling_avail, > .num_oversampling_temp_avail = ARRAY_SIZE(bmp280_oversampling_avail), > + /* > + * Oversampling config values on BMx280 have one additional setting > + * that other generations of the family don't: > + * The value 0 means the measurement is bypassed instead of > + * oversampling set to x1. > + * > + * To account for this difference, and preserve the same common > + * config logic, this is handled later on chip_config callback > + * incrementing one unit the oversampling setting. > + */ > + .oversampling_temp_default = BMP280_OSRS_TEMP_2X - 1, > > .oversampling_press_avail = bmp280_oversampling_avail, > .num_oversampling_press_avail = ARRAY_SIZE(bmp280_oversampling_avail), > + .oversampling_press_default = BMP280_OSRS_PRESS_16X - 1, > > .chip_config = bmp280_chip_config, > .read_temp = bmp280_read_temp, > .read_press = bmp280_read_press, > + .read_calib = bmp280_read_calib, > }; > > static int bme280_chip_config(struct bmp280_data *data) > { > int ret; > - u8 osrs = BMP280_OSRS_HUMIDITIY_X(data->oversampling_humid + 1); > + u8 osrs = FIELD_PREP(BMP280_OSRS_HUMIDITY_MASK, data->oversampling_humid + 1); > > /* > * Oversampling of humidity must be set before oversampling of > @@ -670,19 +697,27 @@ static int bme280_chip_config(struct bmp280_data *data) > } > > static const struct bmp280_chip_info bme280_chip_info = { > + .id_reg = BMP280_REG_ID, > + .start_up_time = 2000, > + .num_channels = 3, > + > .oversampling_temp_avail = bmp280_oversampling_avail, > .num_oversampling_temp_avail = ARRAY_SIZE(bmp280_oversampling_avail), > + .oversampling_temp_default = BMP280_OSRS_TEMP_2X - 1, > > .oversampling_press_avail = bmp280_oversampling_avail, > .num_oversampling_press_avail = ARRAY_SIZE(bmp280_oversampling_avail), > + .oversampling_press_default = BMP280_OSRS_PRESS_16X - 1, > > .oversampling_humid_avail = bmp280_oversampling_avail, > .num_oversampling_humid_avail = ARRAY_SIZE(bmp280_oversampling_avail), > + .oversampling_humid_default = BMP280_OSRS_HUMIDITY_16X - 1, > > .chip_config = bme280_chip_config, > .read_temp = bmp280_read_temp, > .read_press = bmp280_read_press, > .read_humid = bmp280_read_humid, > + .read_calib = bmp280_read_calib, > }; > > static int bmp180_measure(struct bmp280_data *data, u8 ctrl_meas) > @@ -710,7 +745,7 @@ static int bmp180_measure(struct bmp280_data *data, u8 ctrl_meas) > if (!ret) > dev_err(data->dev, "timeout waiting for completion\n"); > } else { > - if (ctrl_meas == BMP180_MEAS_TEMP) > + if (FIELD_GET(BMP180_MEAS_CTRL_MASK, ctrl_meas) == BMP180_MEAS_TEMP) > delay_us = 4500; > else > delay_us = > @@ -735,7 +770,9 @@ static int bmp180_read_adc_temp(struct bmp280_data *data, int *val) > __be16 tmp; > int ret; > > - ret = bmp180_measure(data, BMP180_MEAS_TEMP); > + ret = bmp180_measure(data, > + FIELD_PREP(BMP180_MEAS_CTRL_MASK, BMP180_MEAS_TEMP) | > + BMP180_MEAS_SCO); > if (ret) > return ret; > > @@ -748,11 +785,11 @@ static int bmp180_read_adc_temp(struct bmp280_data *data, int *val) > return 0; > } > > -static int bmp180_read_calib(struct bmp280_data *data, > - struct bmp180_calib *calib) > +static int bmp180_read_calib(struct bmp280_data *data, unsigned int chip) What is chip used for? If there will be a need for it in later patches, then it's fine to add the additional parameter now but please say why in the patch description. > { > int ret; > int i; > + struct bmp180_calib *calib = &data->calib.bmp180; > __be16 buf[BMP180_REG_CALIB_COUNT / 2]; > > ret = regmap_bulk_read(data->regmap, BMP180_REG_CALIB_START, buf, > @@ -832,7 +869,10 @@ static int bmp180_read_adc_press(struct bmp280_data *data, int *val) > __be32 tmp = 0; > u8 oss = data->oversampling_press; > > - ret = bmp180_measure(data, BMP180_MEAS_PRESS_X(oss)); > + ret = bmp180_measure(data, > + FIELD_PREP(BMP180_MEAS_CTRL_MASK, BMP180_MEAS_PRESS) | > + FIELD_PREP(BMP180_OSRS_PRESS_MASK, oss) | > + BMP180_MEAS_SCO); > if (ret) > return ret; >