Lines Matching refs:data
52 #define SHT15_TSU 150 /* data setup time */
57 * @d1: see data sheet
64 /* Table 9 from data sheet - relates temperature calculation
76 * struct sht15_data - device instance specific data
77 * @pdata: platform data (gpio's etc)
121 * @data: sht15 specific data
123 * This implements section 3.4 of the data sheet
125 static void sht15_connection_reset(struct sht15_data *data)
128 gpio_direction_output(data->pdata->gpio_data, 1);
130 gpio_set_value(data->pdata->gpio_sck, 0);
133 gpio_set_value(data->pdata->gpio_sck, 1);
135 gpio_set_value(data->pdata->gpio_sck, 0);
141 * @data: device state data
144 static inline void sht15_send_bit(struct sht15_data *data, int val)
147 gpio_set_value(data->pdata->gpio_data, val);
149 gpio_set_value(data->pdata->gpio_sck, 1);
151 gpio_set_value(data->pdata->gpio_sck, 0);
158 * @data: device state data
159 * Timings for this are not documented on the data sheet, so very
161 * figure 12 on the data sheet.
163 static void sht15_transmission_start(struct sht15_data *data)
165 /* ensure data is high and output */
166 gpio_direction_output(data->pdata->gpio_data, 1);
168 gpio_set_value(data->pdata->gpio_sck, 0);
170 gpio_set_value(data->pdata->gpio_sck, 1);
172 gpio_set_value(data->pdata->gpio_data, 0);
174 gpio_set_value(data->pdata->gpio_sck, 0);
176 gpio_set_value(data->pdata->gpio_sck, 1);
178 gpio_set_value(data->pdata->gpio_data, 1);
180 gpio_set_value(data->pdata->gpio_sck, 0);
185 * @data: device state
188 static void sht15_send_byte(struct sht15_data *data, u8 byte)
192 sht15_send_bit(data, !!(byte & 0x80));
198 * @data: device state
200 static int sht15_wait_for_response(struct sht15_data *data)
202 gpio_direction_input(data->pdata->gpio_data);
203 gpio_set_value(data->pdata->gpio_sck, 1);
205 if (gpio_get_value(data->pdata->gpio_data)) {
206 gpio_set_value(data->pdata->gpio_sck, 0);
207 dev_err(data->dev, "Command not acknowledged\n");
208 sht15_connection_reset(data);
211 gpio_set_value(data->pdata->gpio_sck, 0);
218 * @data: device state
221 * On entry, sck is output low, data is output pull high
224 static int sht15_send_cmd(struct sht15_data *data, u8 cmd)
227 sht15_transmission_start(data);
228 sht15_send_byte(data, cmd);
229 ret = sht15_wait_for_response(data);
234 * @data: device instance specific data
239 static inline int sht15_update_single_val(struct sht15_data *data,
244 ret = sht15_send_cmd(data, command);
248 gpio_direction_input(data->pdata->gpio_data);
249 atomic_set(&data->interrupt_handled, 0);
251 enable_irq(gpio_to_irq(data->pdata->gpio_data));
252 if (gpio_get_value(data->pdata->gpio_data) == 0) {
253 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
255 if (!atomic_read(&data->interrupt_handled))
256 schedule_work(&data->read_work);
258 ret = wait_event_timeout(data->wait_queue,
259 (data->flag == SHT15_READING_NOTHING),
262 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
263 sht15_connection_reset(data);
271 * @data: device state
273 static int sht15_update_vals(struct sht15_data *data)
278 mutex_lock(&data->read_lock);
279 if (time_after(jiffies, data->last_updat + timeout)
280 || !data->valid) {
281 data->flag = SHT15_READING_HUMID;
282 ret = sht15_update_single_val(data, SHT15_MEASURE_RH, 160);
285 data->flag = SHT15_READING_TEMP;
286 ret = sht15_update_single_val(data, SHT15_MEASURE_TEMP, 400);
289 data->valid = 1;
290 data->last_updat = jiffies;
293 mutex_unlock(&data->read_lock);
300 * @data: device state
302 * As per section 4.3 of the data sheet.
304 static inline int sht15_calc_temp(struct sht15_data *data)
311 if (data->supply_uV > temppoints[i - 1].vdd) {
312 d1 = (data->supply_uV - temppoints[i - 1].vdd)
319 return data->val_temp*10 + d1;
324 * @data: device state
327 * the data sheet.
329 static inline int sht15_calc_humid(struct sht15_data *data)
332 int temp = sht15_calc_temp(data);
339 + c2 * data->val_humid/1000
340 + (data->val_humid * data->val_humid * c3)/1000000;
341 return (temp - 25000) * (10000 + 80 * data->val_humid)
350 struct sht15_data *data = dev_get_drvdata(dev);
353 ret = sht15_update_vals(data);
356 sht15_calc_temp(data));
364 struct sht15_data *data = dev_get_drvdata(dev);
366 ret = sht15_update_vals(data);
368 return ret ? ret : sprintf(buf, "%d\n", sht15_calc_humid(data));
399 struct sht15_data *data = d;
402 atomic_inc(&data->interrupt_handled);
404 if (data->flag != SHT15_READING_NOTHING)
405 schedule_work(&data->read_work);
409 /* Each byte of data is acknowledged by pulling the data line
412 static void sht15_ack(struct sht15_data *data)
414 gpio_direction_output(data->pdata->gpio_data, 0);
416 gpio_set_value(data->pdata->gpio_sck, 1);
418 gpio_set_value(data->pdata->gpio_sck, 0);
420 gpio_set_value(data->pdata->gpio_data, 1);
422 gpio_direction_input(data->pdata->gpio_data);
426 * @data: device state
428 * This is basically a NAK. (single clock pulse, data high)
430 static void sht15_end_transmission(struct sht15_data *data)
432 gpio_direction_output(data->pdata->gpio_data, 1);
434 gpio_set_value(data->pdata->gpio_sck, 1);
436 gpio_set_value(data->pdata->gpio_sck, 0);
444 struct sht15_data *data
448 if (gpio_get_value(data->pdata->gpio_data)) {
453 atomic_set(&data->interrupt_handled, 0);
454 enable_irq(gpio_to_irq(data->pdata->gpio_data));
456 if (gpio_get_value(data->pdata->gpio_data)
457 || atomic_read(&data->interrupt_handled))
460 /* Read the data back from the device */
463 gpio_set_value(data->pdata->gpio_sck, 1);
465 val |= !!gpio_get_value(data->pdata->gpio_data);
466 gpio_set_value(data->pdata->gpio_sck, 0);
469 sht15_ack(data);
472 sht15_end_transmission(data);
474 switch (data->flag) {
476 data->val_temp = val;
479 data->val_humid = val;
483 data->flag = SHT15_READING_NOTHING;
484 wake_up(&data->wait_queue);
489 struct sht15_data *data
492 data->supply_uV = regulator_get_voltage(data->reg);
508 struct sht15_data *data = container_of(nb, struct sht15_data, nb);
511 data->supply_uV_valid = false;
512 schedule_work(&data->update_supply_work);
520 struct sht15_data *data = kzalloc(sizeof(*data), GFP_KERNEL);
522 if (!data) {
528 INIT_WORK(&data->read_work, sht15_bh_read_data);
529 INIT_WORK(&data->update_supply_work, sht15_update_voltage);
530 platform_set_drvdata(pdev, data);
531 mutex_init(&data->read_lock);
532 data->dev = &pdev->dev;
533 init_waitqueue_head(&data->wait_queue);
536 dev_err(&pdev->dev, "no platform data supplied");
539 data->pdata = pdev->dev.platform_data;
540 data->supply_uV = data->pdata->supply_mv*1000;
543 data->reg = regulator_get(data->dev, "vcc");
544 if (!IS_ERR(data->reg)) {
547 voltage = regulator_get_voltage(data->reg);
549 data->supply_uV = voltage;
551 regulator_enable(data->reg);
554 data->nb.notifier_call = &sht15_invalidate_voltage;
555 ret = regulator_register_notifier(data->reg, &data->nb);
558 ret = gpio_request(data->pdata->gpio_sck, "SHT15 sck");
563 gpio_direction_output(data->pdata->gpio_sck, 0);
564 ret = gpio_request(data->pdata->gpio_data, "SHT15 data");
575 ret = request_irq(gpio_to_irq(data->pdata->gpio_data),
578 "sht15 data",
579 data);
581 dev_err(&pdev->dev, "failed to get irq for data line");
584 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
585 sht15_connection_reset(data);
586 sht15_send_cmd(data, 0x1E);
588 data->hwmon_dev = hwmon_device_register(data->dev);
589 if (IS_ERR(data->hwmon_dev)) {
590 ret = PTR_ERR(data->hwmon_dev);
596 free_irq(gpio_to_irq(data->pdata->gpio_data), data);
598 gpio_free(data->pdata->gpio_data);
600 gpio_free(data->pdata->gpio_sck);
602 kfree(data);
610 struct sht15_data *data = platform_get_drvdata(pdev);
614 mutex_lock(&data->read_lock);
615 hwmon_device_unregister(data->hwmon_dev);
617 if (!IS_ERR(data->reg)) {
618 regulator_unregister_notifier(data->reg, &data->nb);
619 regulator_disable(data->reg);
620 regulator_put(data->reg);
623 free_irq(gpio_to_irq(data->pdata->gpio_data), data);
624 gpio_free(data->pdata->gpio_data);
625 gpio_free(data->pdata->gpio_sck);
626 mutex_unlock(&data->read_lock);
627 kfree(data);