From: Jonathan Cameron <jic23@kernel.org>
To: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Cc: linux-iio@vger.kernel.org
Subject: Re: [PATCH v2 1/2] iio: humidity: hts221: move common code in hts221_core
Date: Mon, 1 Jan 2018 10:07:55 +0000 [thread overview]
Message-ID: <20180101100755.167e793e@archlinux> (raw)
In-Reply-To: <1953687a7f71cbc6a65d51d412c86fa4a5b93f3f.1514588903.git.lorenzo.bianconi@redhat.com>
On Sat, 30 Dec 2017 00:33:04 +0100
Lorenzo Bianconi <lorenzo.bianconi@redhat.com> wrote:
> Move duplicated i2c/spi probe code in hts221_probe()
>
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Sensible clean up.
Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to play with it.
Thanks,
Jonathan
> ---
> drivers/iio/humidity/hts221.h | 3 ++-
> drivers/iio/humidity/hts221_core.c | 18 ++++++++++++++++--
> drivers/iio/humidity/hts221_i2c.c | 18 ++----------------
> drivers/iio/humidity/hts221_spi.c | 18 ++----------------
> 4 files changed, 22 insertions(+), 35 deletions(-)
>
> diff --git a/drivers/iio/humidity/hts221.h b/drivers/iio/humidity/hts221.h
> index 51d021966222..c581af8c0f5d 100644
> --- a/drivers/iio/humidity/hts221.h
> +++ b/drivers/iio/humidity/hts221.h
> @@ -61,7 +61,8 @@ struct hts221_hw {
> extern const struct dev_pm_ops hts221_pm_ops;
>
> int hts221_write_with_mask(struct hts221_hw *hw, u8 addr, u8 mask, u8 val);
> -int hts221_probe(struct iio_dev *iio_dev);
> +int hts221_probe(struct device *dev, int irq, const char *name,
> + const struct hts221_transfer_function *tf_ops);
> int hts221_set_enable(struct hts221_hw *hw, bool enable);
> int hts221_allocate_buffers(struct hts221_hw *hw);
> int hts221_allocate_trigger(struct hts221_hw *hw);
> diff --git a/drivers/iio/humidity/hts221_core.c b/drivers/iio/humidity/hts221_core.c
> index daef177219b6..d3f7904766bd 100644
> --- a/drivers/iio/humidity/hts221_core.c
> +++ b/drivers/iio/humidity/hts221_core.c
> @@ -581,12 +581,26 @@ static const struct iio_info hts221_info = {
>
> static const unsigned long hts221_scan_masks[] = {0x3, 0x0};
>
> -int hts221_probe(struct iio_dev *iio_dev)
> +int hts221_probe(struct device *dev, int irq, const char *name,
> + const struct hts221_transfer_function *tf_ops)
> {
> - struct hts221_hw *hw = iio_priv(iio_dev);
> + struct iio_dev *iio_dev;
> + struct hts221_hw *hw;
> int err;
> u8 data;
>
> + iio_dev = devm_iio_device_alloc(dev, sizeof(*hw));
> + if (!iio_dev)
> + return -ENOMEM;
> +
> + dev_set_drvdata(dev, (void *)iio_dev);
> +
> + hw = iio_priv(iio_dev);
> + hw->name = name;
> + hw->dev = dev;
> + hw->irq = irq;
> + hw->tf = tf_ops;
> +
> mutex_init(&hw->lock);
>
> err = hts221_check_whoami(hw);
> diff --git a/drivers/iio/humidity/hts221_i2c.c b/drivers/iio/humidity/hts221_i2c.c
> index f38e4b7e0160..2c97350a0f76 100644
> --- a/drivers/iio/humidity/hts221_i2c.c
> +++ b/drivers/iio/humidity/hts221_i2c.c
> @@ -66,22 +66,8 @@ static const struct hts221_transfer_function hts221_transfer_fn = {
> static int hts221_i2c_probe(struct i2c_client *client,
> const struct i2c_device_id *id)
> {
> - struct hts221_hw *hw;
> - struct iio_dev *iio_dev;
> -
> - iio_dev = devm_iio_device_alloc(&client->dev, sizeof(*hw));
> - if (!iio_dev)
> - return -ENOMEM;
> -
> - i2c_set_clientdata(client, iio_dev);
> -
> - hw = iio_priv(iio_dev);
> - hw->name = client->name;
> - hw->dev = &client->dev;
> - hw->irq = client->irq;
> - hw->tf = &hts221_transfer_fn;
> -
> - return hts221_probe(iio_dev);
> + return hts221_probe(&client->dev, client->irq,
> + client->name, &hts221_transfer_fn);
> }
>
> static const struct acpi_device_id hts221_acpi_match[] = {
> diff --git a/drivers/iio/humidity/hts221_spi.c b/drivers/iio/humidity/hts221_spi.c
> index 57cbc256771b..55b29b53b9d1 100644
> --- a/drivers/iio/humidity/hts221_spi.c
> +++ b/drivers/iio/humidity/hts221_spi.c
> @@ -80,22 +80,8 @@ static const struct hts221_transfer_function hts221_transfer_fn = {
>
> static int hts221_spi_probe(struct spi_device *spi)
> {
> - struct hts221_hw *hw;
> - struct iio_dev *iio_dev;
> -
> - iio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*hw));
> - if (!iio_dev)
> - return -ENOMEM;
> -
> - spi_set_drvdata(spi, iio_dev);
> -
> - hw = iio_priv(iio_dev);
> - hw->name = spi->modalias;
> - hw->dev = &spi->dev;
> - hw->irq = spi->irq;
> - hw->tf = &hts221_transfer_fn;
> -
> - return hts221_probe(iio_dev);
> + return hts221_probe(&spi->dev, spi->irq,
> + spi->modalias, &hts221_transfer_fn);
> }
>
> static const struct of_device_id hts221_spi_of_match[] = {
next prev parent reply other threads:[~2018-01-01 10:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-29 23:33 [PATCH v2 0/2] add regmap API support to hts221 iio driver Lorenzo Bianconi
2017-12-29 23:33 ` [PATCH v2 1/2] iio: humidity: hts221: move common code in hts221_core Lorenzo Bianconi
2018-01-01 10:07 ` Jonathan Cameron [this message]
2017-12-29 23:33 ` [PATCH v2 2/2] iio: humidity: hts221: add regmap API support Lorenzo Bianconi
2018-01-01 10:07 ` Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180101100755.167e793e@archlinux \
--to=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=lorenzo.bianconi@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox