iio: humidity: hts221: move common code in hts221_core
authorLorenzo Bianconi <lorenzo.bianconi@redhat.com>
Fri, 29 Dec 2017 23:33:04 +0000 (00:33 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 8 Jan 2018 15:03:43 +0000 (16:03 +0100)
Move duplicated i2c/spi probe code in hts221_probe()

Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/iio/humidity/hts221.h
drivers/iio/humidity/hts221_core.c
drivers/iio/humidity/hts221_i2c.c
drivers/iio/humidity/hts221_spi.c

index 51d021966222f572dd4300a1f77c3ea0d5385d50..c581af8c0f5d3f78cd0dd4461faee79404d3b99b 100644 (file)
@@ -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);
index daef177219b60be6623b4e96ca203deff172f7b6..d3f7904766bd3f477343c91d45d3280e8c23ac1c 100644 (file)
@@ -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);
index f38e4b7e0160746ee2bbe094c9dddb712a3834f1..2c97350a0f760dd46f3586a1fa124d65515b18cd 100644 (file)
@@ -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[] = {
index 57cbc256771bce39ebab42475b420f1ac535ce2f..55b29b53b9d1b97861ab21b99f064561300b91ac 100644 (file)
@@ -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[] = {