static void sht15_bh_read_data(struct work_struct *work_s) { int i; uint16_t val = 0; struct sht15_data *data = container_of(work_s, struct sht15_data, read_work); /* Firstly, verify the line is low */ if (gpio_get_value(data->pdata->gpio_data)) { /* If not, then start the interrupt again - care here as could have gone low in meantime so verify it hasn't! */ atomic_set_unchecked(&data->interrupt_handled, 0); enable_irq(gpio_to_irq(data->pdata->gpio_data)); /* If still not occurred or another handler has been scheduled */ if (gpio_get_value(data->pdata->gpio_data) || atomic_read_unchecked(&data->interrupt_handled)) return; } /* Read the data back from the device */ for (i = 0; i < 16; ++i) { val <<= 1; gpio_set_value(data->pdata->gpio_sck, 1); ndelay(SHT15_TSCKH); val |= !!gpio_get_value(data->pdata->gpio_data); gpio_set_value(data->pdata->gpio_sck, 0); ndelay(SHT15_TSCKL); if (i == 7) sht15_ack(data); } /* Tell the device we are done */ sht15_end_transmission(data); switch (data->flag) { case SHT15_READING_TEMP: data->val_temp = val; break; case SHT15_READING_HUMID: data->val_humid = val; break; } data->flag = SHT15_READING_NOTHING; wake_up(&data->wait_queue); }
static void sht15_bh_read_data(struct work_struct *work_s) { int i; uint16_t val = 0; struct sht15_data *data = container_of(work_s, struct sht15_data, read_work); if (gpio_get_value(data->pdata->gpio_data)) { atomic_set(&data->interrupt_handled, 0); enable_irq(gpio_to_irq(data->pdata->gpio_data)); if (gpio_get_value(data->pdata->gpio_data) || atomic_read(&data->interrupt_handled)) return; } for (i = 0; i < 16; ++i) { val <<= 1; gpio_set_value(data->pdata->gpio_sck, 1); ndelay(SHT15_TSCKH); val |= !!gpio_get_value(data->pdata->gpio_data); gpio_set_value(data->pdata->gpio_sck, 0); ndelay(SHT15_TSCKL); if (i == 7) sht15_ack(data); } sht15_end_transmission(data); switch (data->flag) { case SHT15_READING_TEMP: data->val_temp = val; break; case SHT15_READING_HUMID: data->val_humid = val; break; } data->flag = SHT15_READING_NOTHING; wake_up(&data->wait_queue); }