#include <linux/interrupt.h>
 #include <linux/irq.h>
-#include <linux/gpio.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/hwmon.h>
 #include <linux/hwmon-sysfs.h>
 #include <linux/mutex.h>
-#include <linux/platform_data/sht15.h>
 #include <linux/platform_device.h>
 #include <linux/sched.h>
 #include <linux/delay.h>
 #include <linux/slab.h>
 #include <linux/atomic.h>
 #include <linux/bitrev.h>
-#include <linux/of_gpio.h>
+#include <linux/gpio/consumer.h>
+#include <linux/of.h>
 
 /* Commands */
 #define SHT15_MEASURE_TEMP             0x03
 
 /**
  * struct sht15_data - device instance specific data
- * @pdata:             platform data (gpio's etc).
+ * @sck:               clock GPIO line
+ * @data:              data GPIO line
  * @read_work:         bh of interrupt handler.
  * @wait_queue:                wait queue for getting values from device.
  * @val_temp:          last temperature value read from device.
  * @interrupt_handled: flag used to indicate a handler has been scheduled.
  */
 struct sht15_data {
-       struct sht15_platform_data      *pdata;
+       struct gpio_desc                *sck;
+       struct gpio_desc                *data;
        struct work_struct              read_work;
        wait_queue_head_t               wait_queue;
        uint16_t                        val_temp;
 {
        int i, err;
 
-       err = gpio_direction_output(data->pdata->gpio_data, 1);
+       err = gpiod_direction_output(data->data, 1);
        if (err)
                return err;
        ndelay(SHT15_TSCKL);
-       gpio_set_value(data->pdata->gpio_sck, 0);
+       gpiod_set_value(data->sck, 0);
        ndelay(SHT15_TSCKL);
        for (i = 0; i < 9; ++i) {
-               gpio_set_value(data->pdata->gpio_sck, 1);
+               gpiod_set_value(data->sck, 1);
                ndelay(SHT15_TSCKH);
-               gpio_set_value(data->pdata->gpio_sck, 0);
+               gpiod_set_value(data->sck, 0);
                ndelay(SHT15_TSCKL);
        }
        return 0;
  */
 static inline void sht15_send_bit(struct sht15_data *data, int val)
 {
-       gpio_set_value(data->pdata->gpio_data, val);
+       gpiod_set_value(data->data, val);
        ndelay(SHT15_TSU);
-       gpio_set_value(data->pdata->gpio_sck, 1);
+       gpiod_set_value(data->sck, 1);
        ndelay(SHT15_TSCKH);
-       gpio_set_value(data->pdata->gpio_sck, 0);
+       gpiod_set_value(data->sck, 0);
        ndelay(SHT15_TSCKL); /* clock low time */
 }
 
        int err;
 
        /* ensure data is high and output */
-       err = gpio_direction_output(data->pdata->gpio_data, 1);
+       err = gpiod_direction_output(data->data, 1);
        if (err)
                return err;
        ndelay(SHT15_TSU);
-       gpio_set_value(data->pdata->gpio_sck, 0);
+       gpiod_set_value(data->sck, 0);
        ndelay(SHT15_TSCKL);
-       gpio_set_value(data->pdata->gpio_sck, 1);
+       gpiod_set_value(data->sck, 1);
        ndelay(SHT15_TSCKH);
-       gpio_set_value(data->pdata->gpio_data, 0);
+       gpiod_set_value(data->data, 0);
        ndelay(SHT15_TSU);
-       gpio_set_value(data->pdata->gpio_sck, 0);
+       gpiod_set_value(data->sck, 0);
        ndelay(SHT15_TSCKL);
-       gpio_set_value(data->pdata->gpio_sck, 1);
+       gpiod_set_value(data->sck, 1);
        ndelay(SHT15_TSCKH);
-       gpio_set_value(data->pdata->gpio_data, 1);
+       gpiod_set_value(data->data, 1);
        ndelay(SHT15_TSU);
-       gpio_set_value(data->pdata->gpio_sck, 0);
+       gpiod_set_value(data->sck, 0);
        ndelay(SHT15_TSCKL);
        return 0;
 }
 {
        int err;
 
-       err = gpio_direction_input(data->pdata->gpio_data);
+       err = gpiod_direction_input(data->data);
        if (err)
                return err;
-       gpio_set_value(data->pdata->gpio_sck, 1);
+       gpiod_set_value(data->sck, 1);
        ndelay(SHT15_TSCKH);
-       if (gpio_get_value(data->pdata->gpio_data)) {
-               gpio_set_value(data->pdata->gpio_sck, 0);
+       if (gpiod_get_value(data->data)) {
+               gpiod_set_value(data->sck, 0);
                dev_err(data->dev, "Command not acknowledged\n");
                err = sht15_connection_reset(data);
                if (err)
                        return err;
                return -EIO;
        }
-       gpio_set_value(data->pdata->gpio_sck, 0);
+       gpiod_set_value(data->sck, 0);
        ndelay(SHT15_TSCKL);
        return 0;
 }
 {
        int err;
 
-       err = gpio_direction_output(data->pdata->gpio_data, 0);
+       err = gpiod_direction_output(data->data, 0);
        if (err)
                return err;
        ndelay(SHT15_TSU);
-       gpio_set_value(data->pdata->gpio_sck, 1);
+       gpiod_set_value(data->sck, 1);
        ndelay(SHT15_TSU);
-       gpio_set_value(data->pdata->gpio_sck, 0);
+       gpiod_set_value(data->sck, 0);
        ndelay(SHT15_TSU);
-       gpio_set_value(data->pdata->gpio_data, 1);
+       gpiod_set_value(data->data, 1);
 
-       return gpio_direction_input(data->pdata->gpio_data);
+       return gpiod_direction_input(data->data);
 }
 
 /**
 {
        int err;
 
-       err = gpio_direction_output(data->pdata->gpio_data, 1);
+       err = gpiod_direction_output(data->data, 1);
        if (err)
                return err;
        ndelay(SHT15_TSU);
-       gpio_set_value(data->pdata->gpio_sck, 1);
+       gpiod_set_value(data->sck, 1);
        ndelay(SHT15_TSCKH);
-       gpio_set_value(data->pdata->gpio_sck, 0);
+       gpiod_set_value(data->sck, 0);
        ndelay(SHT15_TSCKL);
        return 0;
 }
 
        for (i = 0; i < 8; ++i) {
                byte <<= 1;
-               gpio_set_value(data->pdata->gpio_sck, 1);
+               gpiod_set_value(data->sck, 1);
                ndelay(SHT15_TSCKH);
-               byte |= !!gpio_get_value(data->pdata->gpio_data);
-               gpio_set_value(data->pdata->gpio_sck, 0);
+               byte |= !!gpiod_get_value(data->data);
+               gpiod_set_value(data->sck, 0);
                ndelay(SHT15_TSCKL);
        }
        return byte;
        err = sht15_send_cmd(data, SHT15_WRITE_STATUS);
        if (err)
                return err;
-       err = gpio_direction_output(data->pdata->gpio_data, 1);
+       err = gpiod_direction_output(data->data, 1);
        if (err)
                return err;
        ndelay(SHT15_TSU);
        if (ret)
                return ret;
 
-       ret = gpio_direction_input(data->pdata->gpio_data);
+       ret = gpiod_direction_input(data->data);
        if (ret)
                return ret;
        atomic_set(&data->interrupt_handled, 0);
 
-       enable_irq(gpio_to_irq(data->pdata->gpio_data));
-       if (gpio_get_value(data->pdata->gpio_data) == 0) {
-               disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
+       enable_irq(gpiod_to_irq(data->data));
+       if (gpiod_get_value(data->data) == 0) {
+               disable_irq_nosync(gpiod_to_irq(data->data));
                /* Only relevant if the interrupt hasn't occurred. */
                if (!atomic_read(&data->interrupt_handled))
                        schedule_work(&data->read_work);
                data->state = SHT15_READING_NOTHING;
                return -EIO;
        } else if (ret == 0) { /* timeout occurred */
-               disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
+               disable_irq_nosync(gpiod_to_irq(data->data));
                ret = sht15_connection_reset(data);
                if (ret)
                        return ret;
                               read_work);
 
        /* Firstly, verify the line is low */
-       if (gpio_get_value(data->pdata->gpio_data)) {
+       if (gpiod_get_value(data->data)) {
                /*
                 * If not, then start the interrupt again - care here as could
                 * have gone low in meantime so verify it hasn't!
                 */
                atomic_set(&data->interrupt_handled, 0);
-               enable_irq(gpio_to_irq(data->pdata->gpio_data));
+               enable_irq(gpiod_to_irq(data->data));
                /* If still not occurred or another handler was scheduled */
-               if (gpio_get_value(data->pdata->gpio_data)
+               if (gpiod_get_value(data->data)
                    || atomic_read(&data->interrupt_handled))
                        return;
        }
        { },
 };
 MODULE_DEVICE_TABLE(of, sht15_dt_match);
-
-/*
- * This function returns NULL if pdev isn't a device instatiated by dt,
- * a pointer to pdata if it could successfully get all information
- * from dt or a negative ERR_PTR() on error.
- */
-static struct sht15_platform_data *sht15_probe_dt(struct device *dev)
-{
-       struct device_node *np = dev->of_node;
-       struct sht15_platform_data *pdata;
-
-       /* no device tree device */
-       if (!np)
-               return NULL;
-
-       pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
-       if (!pdata)
-               return ERR_PTR(-ENOMEM);
-
-       pdata->gpio_data = of_get_named_gpio(np, "data-gpios", 0);
-       if (pdata->gpio_data < 0) {
-               if (pdata->gpio_data != -EPROBE_DEFER)
-                       dev_err(dev, "data-gpios not found\n");
-               return ERR_PTR(pdata->gpio_data);
-       }
-
-       pdata->gpio_sck = of_get_named_gpio(np, "clk-gpios", 0);
-       if (pdata->gpio_sck < 0) {
-               if (pdata->gpio_sck != -EPROBE_DEFER)
-                       dev_err(dev, "clk-gpios not found\n");
-               return ERR_PTR(pdata->gpio_sck);
-       }
-
-       return pdata;
-}
-#else
-static inline struct sht15_platform_data *sht15_probe_dt(struct device *dev)
-{
-       return NULL;
-}
 #endif
 
 static int sht15_probe(struct platform_device *pdev)
        data->dev = &pdev->dev;
        init_waitqueue_head(&data->wait_queue);
 
-       data->pdata = sht15_probe_dt(&pdev->dev);
-       if (IS_ERR(data->pdata))
-               return PTR_ERR(data->pdata);
-       if (data->pdata == NULL) {
-               data->pdata = dev_get_platdata(&pdev->dev);
-               if (data->pdata == NULL) {
-                       dev_err(&pdev->dev, "no platform data supplied\n");
-                       return -EINVAL;
-               }
-       }
-
-       data->supply_uv = data->pdata->supply_mv * 1000;
-       if (data->pdata->checksum)
-               data->checksumming = true;
-       if (data->pdata->no_otp_reload)
-               status |= SHT15_STATUS_NO_OTP_RELOAD;
-       if (data->pdata->low_resolution)
-               status |= SHT15_STATUS_LOW_RESOLUTION;
-
        /*
         * If a regulator is available,
         * query what the supply voltage actually is!
        }
 
        /* Try requesting the GPIOs */
-       ret = devm_gpio_request_one(&pdev->dev, data->pdata->gpio_sck,
-                       GPIOF_OUT_INIT_LOW, "SHT15 sck");
-       if (ret) {
+       data->sck = devm_gpiod_get(&pdev->dev, "clk", GPIOD_OUT_LOW);
+       if (IS_ERR(data->sck)) {
+               ret = PTR_ERR(data->sck);
                dev_err(&pdev->dev, "clock line GPIO request failed\n");
                goto err_release_reg;
        }
-
-       ret = devm_gpio_request(&pdev->dev, data->pdata->gpio_data,
-                               "SHT15 data");
-       if (ret) {
+       data->data = devm_gpiod_get(&pdev->dev, "data", GPIOD_IN);
+       if (IS_ERR(data->data)) {
+               ret = PTR_ERR(data->data);
                dev_err(&pdev->dev, "data line GPIO request failed\n");
                goto err_release_reg;
        }
 
-       ret = devm_request_irq(&pdev->dev, gpio_to_irq(data->pdata->gpio_data),
+       ret = devm_request_irq(&pdev->dev, gpiod_to_irq(data->data),
                               sht15_interrupt_fired,
                               IRQF_TRIGGER_FALLING,
                               "sht15 data",
                dev_err(&pdev->dev, "failed to get irq for data line\n");
                goto err_release_reg;
        }
-       disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
+       disable_irq_nosync(gpiod_to_irq(data->data));
        ret = sht15_connection_reset(data);
        if (ret)
                goto err_release_reg;