Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp7555866rwl; Fri, 30 Dec 2022 10:08:56 -0800 (PST) X-Google-Smtp-Source: AMrXdXtWGzCHwNwWBYp6mnV8QUz/6SErIec1s43ciHEARe6p7tN66xj9FumR49iNlw6AIctHLoDW X-Received: by 2002:a62:f20f:0:b0:566:900d:5ae8 with SMTP id m15-20020a62f20f000000b00566900d5ae8mr28727181pfh.24.1672423735903; Fri, 30 Dec 2022 10:08:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672423735; cv=none; d=google.com; s=arc-20160816; b=srPhqoEtH8E+DqkyOlSW8rxZBfzgCd5K3Ntcbx2BXL20t1CoIM8UhzJbzqtYu0agAe 9OTPMUopYdlAbgF34QHlRcUdcBMkjAYKjlko8lB0Mml6wQvMAB4z1wF6mvn3wgm7F1IV h4Cgl5QUQxoPBmgHYTHeCApxUAb9QVjFPGxvLrYOrmyxyZc/X9Ee9nPhOEHSS7t9C+45 tc9D2J4YlVwdXxfHbpXistTYwgN8jGpY7vAufVW6E98nr07M82Rdyho8NYjWUZbJrRfS OmZohtz49moDMOZac46VohoD+ILU/733zNTJsGGgV8+duOHLz/Jy9ogTr6oh7TZfRqVW eF2w== 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=oyYKbrB8EsTBaV4Af5kZbWTYH6l1LoWIgwi41UA+7ec=; b=X+F4lLWPOCRKksDYUHWYpg3Vn4DD7f2GiivbNHyTFXWl0/EhvKS5Nv6nczXTglzgH8 0+PkmMriqdFJVKh/X4gTBC3BdnNdKIV9aDveIqKLKHaMqUG+nkxPym8b4hegF4j+G8lE /KspXsF43mJQu0v7SxPQgTBaUPd2Afc7CUbKoftd8bXcMYMvk2m7+xc5yNRcqUYyRzxK HHYgGGOETe3aWhF7ggaYaeXqrcDwG7uFkf5j260QXxdOZZGjfgmTqTgjYPlsNZAzGEvG XVMT8A8H+UuPk+z91V0mDcjOjtjdPrCw02yukxNO02Z++AcVCpyfO3/Nj0bDNFBJ5ate WYUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Afq9jhn9; 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 h16-20020a62b410000000b0057d6a17b593si20505682pfn.362.2022.12.30.10.08.28; Fri, 30 Dec 2022 10:08:55 -0800 (PST) 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=Afq9jhn9; 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 S231310AbiL3SF1 (ORCPT + 63 others); Fri, 30 Dec 2022 13:05:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230093AbiL3SFY (ORCPT ); Fri, 30 Dec 2022 13:05:24 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47A41178B5; Fri, 30 Dec 2022 10:05:23 -0800 (PST) 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 dfw.source.kernel.org (Postfix) with ESMTPS id DE90261B32; Fri, 30 Dec 2022 18:05:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F615C433D2; Fri, 30 Dec 2022 18:05:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672423522; bh=vaaGlDn5lukU30p0UlEvyAPikiJjlJp1zDhTh2mWxt0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Afq9jhn9Prt460DcO60BOhAV+uPWjtgG1eBHLGYEoPpTSXmpPVfvJm9zmQb7sAOs4 P58zACGP8ffd9K9eabbg4JIMsI1cGqPv0085/iL6f7lEKtqb0yTutVjmaiCxbaW8gC MeCkIxA9HkEbxcr1ep4IBngCza0I2SkBHfKI4tn/VZbJo4vVyz+JCCQsuaSx806rp/ o5EagFMcirteHqIFJRro8XdSVD6deX4dkjFEFKZbY16iPFqNdFxzw6DdqNJEG5HOkb iCOC8TOuwVHgVAnLIOIDkzqm2fvop7Y0ivjVX1K8jbGn5NLQ6z1QK8l6BeqF/NRFwQ z6YMdDIthOXPw== Date: Fri, 30 Dec 2022 18:18:39 +0000 From: Jonathan Cameron To: Angel Iglesias Cc: linux-iio@vger.kernel.org, Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Andy Shevchenko , Nikita Yushchenko , Paul Cercueil , Ulf Hansson , "Rafael J. Wysocki" , Andreas Klinger , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/5] iio: pressure: bmp280: Add preinit callback Message-ID: <20221230181839.43191be2@jic23-huawei> In-Reply-To: <724e92e64e6d91d48d762e804b430c716679bccb.1672062380.git.ang.iglesiasg@gmail.com> References: <724e92e64e6d91d48d762e804b430c716679bccb.1672062380.git.ang.iglesiasg@gmail.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.36; 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.1 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 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 Mon, 26 Dec 2022 15:29:21 +0100 Angel Iglesias wrote: > Adds preinit callback to execute operations on probe before applying > initial configuration. > > Signed-off-by: Angel Iglesias > > diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c > index 46959a91408f..c37cf2caec68 100644 > --- a/drivers/iio/pressure/bmp280-core.c > +++ b/drivers/iio/pressure/bmp280-core.c > @@ -217,6 +217,7 @@ struct bmp280_chip_info { > int (*read_press)(struct bmp280_data *, int *, int *); > int (*read_humid)(struct bmp280_data *, int *, int *); > int (*read_calib)(struct bmp280_data *); > + int (*preinit)(struct bmp280_data *); > }; > > /* > @@ -935,6 +936,7 @@ static const struct bmp280_chip_info bmp280_chip_info = { > .read_temp = bmp280_read_temp, > .read_press = bmp280_read_press, > .read_calib = bmp280_read_calib, > + .preinit = NULL, C standard guarantees those are set to NULL anyway + the default is obvious. Hence don't set them to NULL, just leave the automatic initialization of unspecified structure elements to handle it for you. > }; > > static int bme280_chip_config(struct bmp280_data *data) > @@ -979,6 +981,7 @@ static const struct bmp280_chip_info bme280_chip_info = { > .read_press = bmp280_read_press, > .read_humid = bmp280_read_humid, > .read_calib = bme280_read_calib, > + .preinit = NULL, > }; > > /* > @@ -1220,6 +1223,12 @@ static const int bmp380_odr_table[][2] = { > [BMP380_ODR_0_0015HZ] = {0, 1526}, > }; > > +static int bmp380_preinit(struct bmp280_data *data) > +{ > + /* BMP3xx requires soft-reset as part of initialization */ > + return bmp380_cmd(data, BMP380_CMD_SOFT_RESET); > +} > + > static int bmp380_chip_config(struct bmp280_data *data) > { > bool change = false, aux; > @@ -1349,6 +1358,7 @@ static const struct bmp280_chip_info bmp380_chip_info = { > .read_temp = bmp380_read_temp, > .read_press = bmp380_read_press, > .read_calib = bmp380_read_calib, > + .preinit = bmp380_preinit, > }; > > static int bmp180_measure(struct bmp280_data *data, u8 ctrl_meas) > @@ -1604,6 +1614,7 @@ static const struct bmp280_chip_info bmp180_chip_info = { > .read_temp = bmp180_read_temp, > .read_press = bmp180_read_press, > .read_calib = bmp180_read_calib, > + .preinit = NULL, > }; > > static irqreturn_t bmp085_eoc_irq(int irq, void *d) > @@ -1762,9 +1773,13 @@ int bmp280_common_probe(struct device *dev, > return -EINVAL; > } > > - /* BMP3xx requires soft-reset as part of initialization */ > - if (chip_id == BMP380_CHIP_ID) { > - ret = bmp380_cmd(data, BMP380_CMD_SOFT_RESET); > + /* > + * Some chips like the BMP3xx have preinit tasks to run > + * before applying the initial configuration. > + */ I would drop this comment. It's kind of obvious that some devices need you to call something here - otherwise why have the clearly optional callback? The specific BMP3xx requirements are well commented in your new callback above so don't want to be here as well. > + if (data->chip_info->preinit) { > + ret = data->chip_info->preinit(data); > + dev_err(dev, "error running preinit tasks"); Error message printed on success... > if (ret < 0) > return ret; return dev_err_probe(dev, ret, "error running preinit tasks"); > }