From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_2 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56F41C4361B for ; Sun, 13 Dec 2020 17:13:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2C1602313B for ; Sun, 13 Dec 2020 17:13:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2395023AbgLMRNW (ORCPT ); Sun, 13 Dec 2020 12:13:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:36330 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726472AbgLMRNW (ORCPT ); Sun, 13 Dec 2020 12:13:22 -0500 Received: from archlinux (cpc108967-cmbg20-2-0-cust86.5-4.cable.virginm.net [81.101.6.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7E3D52313B; Sun, 13 Dec 2020 17:12:40 +0000 (UTC) Date: Sun, 13 Dec 2020 17:12:37 +0000 From: Jonathan Cameron To: Alexandre Belloni Cc: Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/6] iio:pressure:ms5637: introduce hardware differentiation Message-ID: <20201213171237.4dfe58f5@archlinux> In-Reply-To: <20201209234857.1521453-3-alexandre.belloni@bootlin.com> References: <20201209234857.1521453-1-alexandre.belloni@bootlin.com> <20201209234857.1521453-3-alexandre.belloni@bootlin.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 10 Dec 2020 00:48:53 +0100 Alexandre Belloni wrote: > Some sensors in the ms58xx family have a different PROM length and a > different number of available resolution. introduce struct ms_tp_hw_data to Introduce > handle those differences. > > Signed-off-by: Alexandre Belloni > --- > .../iio/common/ms_sensors/ms_sensors_i2c.h | 11 ++++++ > drivers/iio/pressure/ms5637.c | 35 +++++++++++++++---- > 2 files changed, 40 insertions(+), 6 deletions(-) > > diff --git a/drivers/iio/common/ms_sensors/ms_sensors_i2c.h b/drivers/iio/common/ms_sensors/ms_sensors_i2c.h > index bad09c80e47a..f4a88148c113 100644 > --- a/drivers/iio/common/ms_sensors/ms_sensors_i2c.h > +++ b/drivers/iio/common/ms_sensors/ms_sensors_i2c.h > @@ -25,6 +25,16 @@ struct ms_ht_dev { > u8 res_index; > }; > > +/** > + * struct ms_hw_data - Temperature/Pressure sensor hardware data > + * @prom_len: number of words in the PROM > + * @max_res_index: maximum sensor resolution index > + */ > +struct ms_tp_hw_data { > + u8 prom_len; > + u8 max_res_index; > +}; > + > /** > * struct ms_tp_dev - Temperature/Pressure sensor device structure > * @client: i2c client > @@ -36,6 +46,7 @@ struct ms_ht_dev { > struct ms_tp_dev { > struct i2c_client *client; > struct mutex lock; > + const struct ms_tp_hw_data *hw; > u16 prom[MS_SENSORS_TP_PROM_WORDS_NB + 1]; > u8 res_index; > }; > diff --git a/drivers/iio/pressure/ms5637.c b/drivers/iio/pressure/ms5637.c > index 7c3f0ccd917c..351bfdb24fb4 100644 > --- a/drivers/iio/pressure/ms5637.c > +++ b/drivers/iio/pressure/ms5637.c > @@ -30,6 +30,11 @@ > > #include "../common/ms_sensors/ms_sensors_i2c.h" > > +struct ms_tp_data { > + const char *name; > + const struct ms_tp_hw_data *hw; > +}; > + > static const int ms5637_samp_freq[6] = { 960, 480, 240, 120, 60, 30 }; > /* String copy of the above const for readability purpose */ > static const char ms5637_show_samp_freq[] = "960 480 240 120 60 30"; > @@ -128,6 +133,7 @@ static const struct iio_info ms5637_info = { > > static int ms5637_probe(struct i2c_client *client) > { > + const struct ms_tp_data *data = device_get_match_data(&client->dev); As a follow up to the earlier fun with greybus etc, have to jump through some hoops to have a fallback here if we have a firmware type that can't do get_match_data driver/base/sw_node.c is the one greybus is using. We have drivers that don't do this because frankly I didn't know about it until a month or two ago. However, I'm not keen to introduce any more. Thanks, Jonathan > struct ms_tp_dev *dev_data; > struct iio_dev *indio_dev; > int ret; > @@ -147,11 +153,12 @@ static int ms5637_probe(struct i2c_client *client) > > dev_data = iio_priv(indio_dev); > dev_data->client = client; > - dev_data->res_index = 5; > + dev_data->res_index = data->hw->max_res_index; > + dev_data->hw = data->hw; > mutex_init(&dev_data->lock); > > indio_dev->info = &ms5637_info; > - indio_dev->name = device_get_match_data(&client->dev); > + indio_dev->name = data->name; > indio_dev->modes = INDIO_DIRECT_MODE; > indio_dev->channels = ms5637_channels; > indio_dev->num_channels = ARRAY_SIZE(ms5637_channels); > @@ -169,11 +176,27 @@ static int ms5637_probe(struct i2c_client *client) > return devm_iio_device_register(&client->dev, indio_dev); > } > > +static const struct ms_tp_hw_data ms5637_hw_data = { > + .prom_len = 7, > + .max_res_index = 5 > +}; > + > +static const struct ms_tp_data ms5637_data = { .name = "ms5637", .hw = &ms5637_hw_data }; > + > +static const struct ms_tp_data ms5805_data = { .name = "ms5805", .hw = &ms5637_hw_data }; > + > +static const struct ms_tp_data ms5837_data = { .name = "ms5837", .hw = &ms5637_hw_data }; > + > +static const struct ms_tp_data ms8607_data = { > + .name = "ms8607-temppressure", > + .hw = &ms5637_hw_data, > +}; > + > static const struct of_device_id ms5637_of_match[] = { > - { .compatible = "meas,ms5637", .data = "ms5637" }, > - { .compatible = "meas,ms5805", .data = "ms5805" }, > - { .compatible = "meas,ms5837", .data = "ms5837" }, > - { .compatible = "meas,ms8607-temppressure", .data = "ms8607-temppressure" }, > + { .compatible = "meas,ms5637", .data = &ms5637_data }, > + { .compatible = "meas,ms5805", .data = &ms5805_data }, > + { .compatible = "meas,ms5837", .data = &ms5837_data }, > + { .compatible = "meas,ms8607-temppressure", .data = &ms8607_data }, > { }, > }; > MODULE_DEVICE_TABLE(of, ms5637_of_match); From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_2 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A0CEC433FE for ; Sun, 13 Dec 2020 17:14:01 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 12E822184D for ; Sun, 13 Dec 2020 17:14:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 12E822184D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=dO0NX1o/CJTOmdG5GA6irSI+JDfLLkFXBoGKFYQkuyk=; b=hePpfKz/vrNMr00POsyDm9bY+ bc4+4hL5HVze2Azyfof8Uzeut1gnV0KwoDZ0tllpa2nGyAsapQ7qZ+5ZsbcD/BGtvxxfbAK8wky6C aS1G8nWoHf+7C7yvFocl/BRpo77YgX1C+dN6GBbwZgF0PZ2ibCyduBxv+zvkqPNRzJiAmpVuxFG7g iMsf4WUd2Vyq+3m0Oy6dWkPPPbI9lGKYt1PwH+Qt/MUdO0zQj/KUebkUhx9vLQLIt+mXWqKH37tDU WzcP1Op1XqrHPa0Fez5lppAwRtdWmjuQ2FmbseY05XSbU3Howx8D0VJ7wEk5a1yQtnXByVzaXwG65 DCJ7Q6SIQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1koUvO-0004U0-1A; Sun, 13 Dec 2020 17:12:46 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1koUvK-0004TT-SG for linux-arm-kernel@lists.infradead.org; Sun, 13 Dec 2020 17:12:43 +0000 Received: from archlinux (cpc108967-cmbg20-2-0-cust86.5-4.cable.virginm.net [81.101.6.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7E3D52313B; Sun, 13 Dec 2020 17:12:40 +0000 (UTC) Date: Sun, 13 Dec 2020 17:12:37 +0000 From: Jonathan Cameron To: Alexandre Belloni Subject: Re: [PATCH 2/6] iio:pressure:ms5637: introduce hardware differentiation Message-ID: <20201213171237.4dfe58f5@archlinux> In-Reply-To: <20201209234857.1521453-3-alexandre.belloni@bootlin.com> References: <20201209234857.1521453-1-alexandre.belloni@bootlin.com> <20201209234857.1521453-3-alexandre.belloni@bootlin.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201213_121243_269885_CE4BA73B X-CRM114-Status: GOOD ( 22.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Lars-Peter Clausen , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Meerwald-Stadler , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, 10 Dec 2020 00:48:53 +0100 Alexandre Belloni wrote: > Some sensors in the ms58xx family have a different PROM length and a > different number of available resolution. introduce struct ms_tp_hw_data to Introduce > handle those differences. > > Signed-off-by: Alexandre Belloni > --- > .../iio/common/ms_sensors/ms_sensors_i2c.h | 11 ++++++ > drivers/iio/pressure/ms5637.c | 35 +++++++++++++++---- > 2 files changed, 40 insertions(+), 6 deletions(-) > > diff --git a/drivers/iio/common/ms_sensors/ms_sensors_i2c.h b/drivers/iio/common/ms_sensors/ms_sensors_i2c.h > index bad09c80e47a..f4a88148c113 100644 > --- a/drivers/iio/common/ms_sensors/ms_sensors_i2c.h > +++ b/drivers/iio/common/ms_sensors/ms_sensors_i2c.h > @@ -25,6 +25,16 @@ struct ms_ht_dev { > u8 res_index; > }; > > +/** > + * struct ms_hw_data - Temperature/Pressure sensor hardware data > + * @prom_len: number of words in the PROM > + * @max_res_index: maximum sensor resolution index > + */ > +struct ms_tp_hw_data { > + u8 prom_len; > + u8 max_res_index; > +}; > + > /** > * struct ms_tp_dev - Temperature/Pressure sensor device structure > * @client: i2c client > @@ -36,6 +46,7 @@ struct ms_ht_dev { > struct ms_tp_dev { > struct i2c_client *client; > struct mutex lock; > + const struct ms_tp_hw_data *hw; > u16 prom[MS_SENSORS_TP_PROM_WORDS_NB + 1]; > u8 res_index; > }; > diff --git a/drivers/iio/pressure/ms5637.c b/drivers/iio/pressure/ms5637.c > index 7c3f0ccd917c..351bfdb24fb4 100644 > --- a/drivers/iio/pressure/ms5637.c > +++ b/drivers/iio/pressure/ms5637.c > @@ -30,6 +30,11 @@ > > #include "../common/ms_sensors/ms_sensors_i2c.h" > > +struct ms_tp_data { > + const char *name; > + const struct ms_tp_hw_data *hw; > +}; > + > static const int ms5637_samp_freq[6] = { 960, 480, 240, 120, 60, 30 }; > /* String copy of the above const for readability purpose */ > static const char ms5637_show_samp_freq[] = "960 480 240 120 60 30"; > @@ -128,6 +133,7 @@ static const struct iio_info ms5637_info = { > > static int ms5637_probe(struct i2c_client *client) > { > + const struct ms_tp_data *data = device_get_match_data(&client->dev); As a follow up to the earlier fun with greybus etc, have to jump through some hoops to have a fallback here if we have a firmware type that can't do get_match_data driver/base/sw_node.c is the one greybus is using. We have drivers that don't do this because frankly I didn't know about it until a month or two ago. However, I'm not keen to introduce any more. Thanks, Jonathan > struct ms_tp_dev *dev_data; > struct iio_dev *indio_dev; > int ret; > @@ -147,11 +153,12 @@ static int ms5637_probe(struct i2c_client *client) > > dev_data = iio_priv(indio_dev); > dev_data->client = client; > - dev_data->res_index = 5; > + dev_data->res_index = data->hw->max_res_index; > + dev_data->hw = data->hw; > mutex_init(&dev_data->lock); > > indio_dev->info = &ms5637_info; > - indio_dev->name = device_get_match_data(&client->dev); > + indio_dev->name = data->name; > indio_dev->modes = INDIO_DIRECT_MODE; > indio_dev->channels = ms5637_channels; > indio_dev->num_channels = ARRAY_SIZE(ms5637_channels); > @@ -169,11 +176,27 @@ static int ms5637_probe(struct i2c_client *client) > return devm_iio_device_register(&client->dev, indio_dev); > } > > +static const struct ms_tp_hw_data ms5637_hw_data = { > + .prom_len = 7, > + .max_res_index = 5 > +}; > + > +static const struct ms_tp_data ms5637_data = { .name = "ms5637", .hw = &ms5637_hw_data }; > + > +static const struct ms_tp_data ms5805_data = { .name = "ms5805", .hw = &ms5637_hw_data }; > + > +static const struct ms_tp_data ms5837_data = { .name = "ms5837", .hw = &ms5637_hw_data }; > + > +static const struct ms_tp_data ms8607_data = { > + .name = "ms8607-temppressure", > + .hw = &ms5637_hw_data, > +}; > + > static const struct of_device_id ms5637_of_match[] = { > - { .compatible = "meas,ms5637", .data = "ms5637" }, > - { .compatible = "meas,ms5805", .data = "ms5805" }, > - { .compatible = "meas,ms5837", .data = "ms5837" }, > - { .compatible = "meas,ms8607-temppressure", .data = "ms8607-temppressure" }, > + { .compatible = "meas,ms5637", .data = &ms5637_data }, > + { .compatible = "meas,ms5805", .data = &ms5805_data }, > + { .compatible = "meas,ms5837", .data = &ms5837_data }, > + { .compatible = "meas,ms8607-temppressure", .data = &ms8607_data }, > { }, > }; > MODULE_DEVICE_TABLE(of, ms5637_of_match); _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel