Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 1 | /* |
| 2 | * sht15.c - support for the SHT15 Temperature and Humidity Sensor |
| 3 | * |
Vivien Didelot | edec5af | 2012-08-30 21:46:19 -0400 | [diff] [blame] | 4 | * Portions Copyright (c) 2010-2012 Savoir-faire Linux Inc. |
Jerome Oufella | 82c7465 | 2011-04-12 15:34:39 -0400 | [diff] [blame] | 5 | * Jerome Oufella <jerome.oufella@savoirfairelinux.com> |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 6 | * Vivien Didelot <vivien.didelot@savoirfairelinux.com> |
| 7 | * |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 8 | * Copyright (c) 2009 Jonathan Cameron |
| 9 | * |
| 10 | * Copyright (c) 2007 Wouter Horre |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License version 2 as |
| 14 | * published by the Free Software Foundation. |
| 15 | * |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 16 | * For further information, see the Documentation/hwmon/sht15 file. |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | #include <linux/interrupt.h> |
| 20 | #include <linux/irq.h> |
| 21 | #include <linux/gpio.h> |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/init.h> |
| 24 | #include <linux/hwmon.h> |
| 25 | #include <linux/hwmon-sysfs.h> |
| 26 | #include <linux/mutex.h> |
Vivien Didelot | f9b693e | 2012-09-12 12:23:44 -0400 | [diff] [blame] | 27 | #include <linux/platform_data/sht15.h> |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 28 | #include <linux/platform_device.h> |
Alexey Dobriyan | d43c36d | 2009-10-07 17:09:06 +0400 | [diff] [blame] | 29 | #include <linux/sched.h> |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 30 | #include <linux/delay.h> |
| 31 | #include <linux/jiffies.h> |
| 32 | #include <linux/err.h> |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 33 | #include <linux/regulator/consumer.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 34 | #include <linux/slab.h> |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 35 | #include <linux/atomic.h> |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 36 | |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 37 | /* Commands */ |
| 38 | #define SHT15_MEASURE_TEMP 0x03 |
| 39 | #define SHT15_MEASURE_RH 0x05 |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 40 | #define SHT15_WRITE_STATUS 0x06 |
| 41 | #define SHT15_READ_STATUS 0x07 |
Vivien Didelot | 181148a | 2011-04-12 15:34:37 -0400 | [diff] [blame] | 42 | #define SHT15_SOFT_RESET 0x1E |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 43 | |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 44 | /* Min timings */ |
| 45 | #define SHT15_TSCKL 100 /* (nsecs) clock low */ |
| 46 | #define SHT15_TSCKH 100 /* (nsecs) clock high */ |
| 47 | #define SHT15_TSU 150 /* (nsecs) data setup time */ |
Vivien Didelot | 181148a | 2011-04-12 15:34:37 -0400 | [diff] [blame] | 48 | #define SHT15_TSRST 11 /* (msecs) soft reset time */ |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 49 | |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 50 | /* Status Register Bits */ |
| 51 | #define SHT15_STATUS_LOW_RESOLUTION 0x01 |
| 52 | #define SHT15_STATUS_NO_OTP_RELOAD 0x02 |
| 53 | #define SHT15_STATUS_HEATER 0x04 |
| 54 | #define SHT15_STATUS_LOW_BATTERY 0x40 |
| 55 | |
Vivien Didelot | edec5af | 2012-08-30 21:46:19 -0400 | [diff] [blame] | 56 | /* List of supported chips */ |
| 57 | enum sht15_chips { sht10, sht11, sht15, sht71, sht75 }; |
| 58 | |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 59 | /* Actions the driver may be doing */ |
| 60 | enum sht15_state { |
| 61 | SHT15_READING_NOTHING, |
| 62 | SHT15_READING_TEMP, |
| 63 | SHT15_READING_HUMID |
| 64 | }; |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 65 | |
| 66 | /** |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 67 | * struct sht15_temppair - elements of voltage dependent temp calc |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 68 | * @vdd: supply voltage in microvolts |
| 69 | * @d1: see data sheet |
| 70 | */ |
| 71 | struct sht15_temppair { |
| 72 | int vdd; /* microvolts */ |
| 73 | int d1; |
| 74 | }; |
| 75 | |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 76 | /* Table 9 from datasheet - relates temperature calculation to supply voltage */ |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 77 | static const struct sht15_temppair temppoints[] = { |
| 78 | { 2500000, -39400 }, |
| 79 | { 3000000, -39600 }, |
| 80 | { 3500000, -39700 }, |
| 81 | { 4000000, -39800 }, |
| 82 | { 5000000, -40100 }, |
| 83 | }; |
| 84 | |
Jerome Oufella | 82c7465 | 2011-04-12 15:34:39 -0400 | [diff] [blame] | 85 | /* Table from CRC datasheet, section 2.4 */ |
| 86 | static const u8 sht15_crc8_table[] = { |
| 87 | 0, 49, 98, 83, 196, 245, 166, 151, |
| 88 | 185, 136, 219, 234, 125, 76, 31, 46, |
| 89 | 67, 114, 33, 16, 135, 182, 229, 212, |
| 90 | 250, 203, 152, 169, 62, 15, 92, 109, |
| 91 | 134, 183, 228, 213, 66, 115, 32, 17, |
| 92 | 63, 14, 93, 108, 251, 202, 153, 168, |
| 93 | 197, 244, 167, 150, 1, 48, 99, 82, |
| 94 | 124, 77, 30, 47, 184, 137, 218, 235, |
| 95 | 61, 12, 95, 110, 249, 200, 155, 170, |
| 96 | 132, 181, 230, 215, 64, 113, 34, 19, |
| 97 | 126, 79, 28, 45, 186, 139, 216, 233, |
| 98 | 199, 246, 165, 148, 3, 50, 97, 80, |
| 99 | 187, 138, 217, 232, 127, 78, 29, 44, |
| 100 | 2, 51, 96, 81, 198, 247, 164, 149, |
| 101 | 248, 201, 154, 171, 60, 13, 94, 111, |
| 102 | 65, 112, 35, 18, 133, 180, 231, 214, |
| 103 | 122, 75, 24, 41, 190, 143, 220, 237, |
| 104 | 195, 242, 161, 144, 7, 54, 101, 84, |
| 105 | 57, 8, 91, 106, 253, 204, 159, 174, |
| 106 | 128, 177, 226, 211, 68, 117, 38, 23, |
| 107 | 252, 205, 158, 175, 56, 9, 90, 107, |
| 108 | 69, 116, 39, 22, 129, 176, 227, 210, |
| 109 | 191, 142, 221, 236, 123, 74, 25, 40, |
| 110 | 6, 55, 100, 85, 194, 243, 160, 145, |
| 111 | 71, 118, 37, 20, 131, 178, 225, 208, |
| 112 | 254, 207, 156, 173, 58, 11, 88, 105, |
| 113 | 4, 53, 102, 87, 192, 241, 162, 147, |
| 114 | 189, 140, 223, 238, 121, 72, 27, 42, |
| 115 | 193, 240, 163, 146, 5, 52, 103, 86, |
| 116 | 120, 73, 26, 43, 188, 141, 222, 239, |
| 117 | 130, 179, 224, 209, 70, 119, 36, 21, |
| 118 | 59, 10, 89, 104, 255, 206, 157, 172 |
| 119 | }; |
| 120 | |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 121 | /** |
| 122 | * struct sht15_data - device instance specific data |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 123 | * @pdata: platform data (gpio's etc). |
| 124 | * @read_work: bh of interrupt handler. |
| 125 | * @wait_queue: wait queue for getting values from device. |
| 126 | * @val_temp: last temperature value read from device. |
| 127 | * @val_humid: last humidity value read from device. |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 128 | * @val_status: last status register value read from device. |
Jerome Oufella | 82c7465 | 2011-04-12 15:34:39 -0400 | [diff] [blame] | 129 | * @checksum_ok: last value read from the device passed CRC validation. |
| 130 | * @checksumming: flag used to enable the data validation with CRC. |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 131 | * @state: state identifying the action the driver is doing. |
| 132 | * @measurements_valid: are the current stored measures valid (start condition). |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 133 | * @status_valid: is the current stored status valid (start condition). |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 134 | * @last_measurement: time of last measure. |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 135 | * @last_status: time of last status reading. |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 136 | * @read_lock: mutex to ensure only one read in progress at a time. |
| 137 | * @dev: associate device structure. |
| 138 | * @hwmon_dev: device associated with hwmon subsystem. |
| 139 | * @reg: associated regulator (if specified). |
| 140 | * @nb: notifier block to handle notifications of voltage |
| 141 | * changes. |
| 142 | * @supply_uV: local copy of supply voltage used to allow use of |
| 143 | * regulator consumer if available. |
| 144 | * @supply_uV_valid: indicates that an updated value has not yet been |
| 145 | * obtained from the regulator and so any calculations |
| 146 | * based upon it will be invalid. |
| 147 | * @update_supply_work: work struct that is used to update the supply_uV. |
| 148 | * @interrupt_handled: flag used to indicate a handler has been scheduled. |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 149 | */ |
| 150 | struct sht15_data { |
| 151 | struct sht15_platform_data *pdata; |
| 152 | struct work_struct read_work; |
| 153 | wait_queue_head_t wait_queue; |
| 154 | uint16_t val_temp; |
| 155 | uint16_t val_humid; |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 156 | u8 val_status; |
Jerome Oufella | 82c7465 | 2011-04-12 15:34:39 -0400 | [diff] [blame] | 157 | bool checksum_ok; |
| 158 | bool checksumming; |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 159 | enum sht15_state state; |
| 160 | bool measurements_valid; |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 161 | bool status_valid; |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 162 | unsigned long last_measurement; |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 163 | unsigned long last_status; |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 164 | struct mutex read_lock; |
| 165 | struct device *dev; |
| 166 | struct device *hwmon_dev; |
| 167 | struct regulator *reg; |
| 168 | struct notifier_block nb; |
| 169 | int supply_uV; |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 170 | bool supply_uV_valid; |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 171 | struct work_struct update_supply_work; |
| 172 | atomic_t interrupt_handled; |
| 173 | }; |
| 174 | |
| 175 | /** |
Jerome Oufella | 82c7465 | 2011-04-12 15:34:39 -0400 | [diff] [blame] | 176 | * sht15_reverse() - reverse a byte |
| 177 | * @byte: byte to reverse. |
| 178 | */ |
| 179 | static u8 sht15_reverse(u8 byte) |
| 180 | { |
| 181 | u8 i, c; |
| 182 | |
| 183 | for (c = 0, i = 0; i < 8; i++) |
| 184 | c |= (!!(byte & (1 << i))) << (7 - i); |
| 185 | return c; |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * sht15_crc8() - compute crc8 |
| 190 | * @data: sht15 specific data. |
| 191 | * @value: sht15 retrieved data. |
| 192 | * |
| 193 | * This implements section 2 of the CRC datasheet. |
| 194 | */ |
| 195 | static u8 sht15_crc8(struct sht15_data *data, |
| 196 | const u8 *value, |
| 197 | int len) |
| 198 | { |
| 199 | u8 crc = sht15_reverse(data->val_status & 0x0F); |
| 200 | |
| 201 | while (len--) { |
| 202 | crc = sht15_crc8_table[*value ^ crc]; |
| 203 | value++; |
| 204 | } |
| 205 | |
| 206 | return crc; |
| 207 | } |
| 208 | |
| 209 | /** |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 210 | * sht15_connection_reset() - reset the comms interface |
| 211 | * @data: sht15 specific data |
| 212 | * |
| 213 | * This implements section 3.4 of the data sheet |
| 214 | */ |
| 215 | static void sht15_connection_reset(struct sht15_data *data) |
| 216 | { |
| 217 | int i; |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 218 | |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 219 | gpio_direction_output(data->pdata->gpio_data, 1); |
| 220 | ndelay(SHT15_TSCKL); |
| 221 | gpio_set_value(data->pdata->gpio_sck, 0); |
| 222 | ndelay(SHT15_TSCKL); |
| 223 | for (i = 0; i < 9; ++i) { |
| 224 | gpio_set_value(data->pdata->gpio_sck, 1); |
| 225 | ndelay(SHT15_TSCKH); |
| 226 | gpio_set_value(data->pdata->gpio_sck, 0); |
| 227 | ndelay(SHT15_TSCKL); |
| 228 | } |
| 229 | } |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 230 | |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 231 | /** |
| 232 | * sht15_send_bit() - send an individual bit to the device |
| 233 | * @data: device state data |
| 234 | * @val: value of bit to be sent |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 235 | */ |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 236 | static inline void sht15_send_bit(struct sht15_data *data, int val) |
| 237 | { |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 238 | gpio_set_value(data->pdata->gpio_data, val); |
| 239 | ndelay(SHT15_TSU); |
| 240 | gpio_set_value(data->pdata->gpio_sck, 1); |
| 241 | ndelay(SHT15_TSCKH); |
| 242 | gpio_set_value(data->pdata->gpio_sck, 0); |
| 243 | ndelay(SHT15_TSCKL); /* clock low time */ |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * sht15_transmission_start() - specific sequence for new transmission |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 248 | * @data: device state data |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 249 | * |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 250 | * Timings for this are not documented on the data sheet, so very |
| 251 | * conservative ones used in implementation. This implements |
| 252 | * figure 12 on the data sheet. |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 253 | */ |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 254 | static void sht15_transmission_start(struct sht15_data *data) |
| 255 | { |
| 256 | /* ensure data is high and output */ |
| 257 | gpio_direction_output(data->pdata->gpio_data, 1); |
| 258 | ndelay(SHT15_TSU); |
| 259 | gpio_set_value(data->pdata->gpio_sck, 0); |
| 260 | ndelay(SHT15_TSCKL); |
| 261 | gpio_set_value(data->pdata->gpio_sck, 1); |
| 262 | ndelay(SHT15_TSCKH); |
| 263 | gpio_set_value(data->pdata->gpio_data, 0); |
| 264 | ndelay(SHT15_TSU); |
| 265 | gpio_set_value(data->pdata->gpio_sck, 0); |
| 266 | ndelay(SHT15_TSCKL); |
| 267 | gpio_set_value(data->pdata->gpio_sck, 1); |
| 268 | ndelay(SHT15_TSCKH); |
| 269 | gpio_set_value(data->pdata->gpio_data, 1); |
| 270 | ndelay(SHT15_TSU); |
| 271 | gpio_set_value(data->pdata->gpio_sck, 0); |
| 272 | ndelay(SHT15_TSCKL); |
| 273 | } |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 274 | |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 275 | /** |
| 276 | * sht15_send_byte() - send a single byte to the device |
| 277 | * @data: device state |
| 278 | * @byte: value to be sent |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 279 | */ |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 280 | static void sht15_send_byte(struct sht15_data *data, u8 byte) |
| 281 | { |
| 282 | int i; |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 283 | |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 284 | for (i = 0; i < 8; i++) { |
| 285 | sht15_send_bit(data, !!(byte & 0x80)); |
| 286 | byte <<= 1; |
| 287 | } |
| 288 | } |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 289 | |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 290 | /** |
| 291 | * sht15_wait_for_response() - checks for ack from device |
| 292 | * @data: device state |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 293 | */ |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 294 | static int sht15_wait_for_response(struct sht15_data *data) |
| 295 | { |
| 296 | gpio_direction_input(data->pdata->gpio_data); |
| 297 | gpio_set_value(data->pdata->gpio_sck, 1); |
| 298 | ndelay(SHT15_TSCKH); |
| 299 | if (gpio_get_value(data->pdata->gpio_data)) { |
| 300 | gpio_set_value(data->pdata->gpio_sck, 0); |
| 301 | dev_err(data->dev, "Command not acknowledged\n"); |
| 302 | sht15_connection_reset(data); |
| 303 | return -EIO; |
| 304 | } |
| 305 | gpio_set_value(data->pdata->gpio_sck, 0); |
| 306 | ndelay(SHT15_TSCKL); |
| 307 | return 0; |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * sht15_send_cmd() - Sends a command to the device. |
| 312 | * @data: device state |
| 313 | * @cmd: command byte to be sent |
| 314 | * |
| 315 | * On entry, sck is output low, data is output pull high |
| 316 | * and the interrupt disabled. |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 317 | */ |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 318 | static int sht15_send_cmd(struct sht15_data *data, u8 cmd) |
| 319 | { |
| 320 | int ret = 0; |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 321 | |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 322 | sht15_transmission_start(data); |
| 323 | sht15_send_byte(data, cmd); |
| 324 | ret = sht15_wait_for_response(data); |
| 325 | return ret; |
| 326 | } |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 327 | |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 328 | /** |
Vivien Didelot | 181148a | 2011-04-12 15:34:37 -0400 | [diff] [blame] | 329 | * sht15_soft_reset() - send a soft reset command |
| 330 | * @data: sht15 specific data. |
| 331 | * |
| 332 | * As described in section 3.2 of the datasheet. |
| 333 | */ |
| 334 | static int sht15_soft_reset(struct sht15_data *data) |
| 335 | { |
| 336 | int ret; |
| 337 | |
| 338 | ret = sht15_send_cmd(data, SHT15_SOFT_RESET); |
| 339 | if (ret) |
| 340 | return ret; |
| 341 | msleep(SHT15_TSRST); |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 342 | /* device resets default hardware status register value */ |
| 343 | data->val_status = 0; |
Vivien Didelot | 181148a | 2011-04-12 15:34:37 -0400 | [diff] [blame] | 344 | |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 345 | return ret; |
| 346 | } |
| 347 | |
| 348 | /** |
Jerome Oufella | 82c7465 | 2011-04-12 15:34:39 -0400 | [diff] [blame] | 349 | * sht15_ack() - send a ack |
| 350 | * @data: sht15 specific data. |
| 351 | * |
| 352 | * Each byte of data is acknowledged by pulling the data line |
| 353 | * low for one clock pulse. |
| 354 | */ |
| 355 | static void sht15_ack(struct sht15_data *data) |
| 356 | { |
| 357 | gpio_direction_output(data->pdata->gpio_data, 0); |
| 358 | ndelay(SHT15_TSU); |
| 359 | gpio_set_value(data->pdata->gpio_sck, 1); |
| 360 | ndelay(SHT15_TSU); |
| 361 | gpio_set_value(data->pdata->gpio_sck, 0); |
| 362 | ndelay(SHT15_TSU); |
| 363 | gpio_set_value(data->pdata->gpio_data, 1); |
| 364 | |
| 365 | gpio_direction_input(data->pdata->gpio_data); |
| 366 | } |
| 367 | |
| 368 | /** |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 369 | * sht15_end_transmission() - notify device of end of transmission |
| 370 | * @data: device state. |
| 371 | * |
| 372 | * This is basically a NAK (single clock pulse, data high). |
| 373 | */ |
| 374 | static void sht15_end_transmission(struct sht15_data *data) |
| 375 | { |
| 376 | gpio_direction_output(data->pdata->gpio_data, 1); |
| 377 | ndelay(SHT15_TSU); |
| 378 | gpio_set_value(data->pdata->gpio_sck, 1); |
| 379 | ndelay(SHT15_TSCKH); |
| 380 | gpio_set_value(data->pdata->gpio_sck, 0); |
| 381 | ndelay(SHT15_TSCKL); |
| 382 | } |
| 383 | |
| 384 | /** |
| 385 | * sht15_read_byte() - Read a byte back from the device |
| 386 | * @data: device state. |
| 387 | */ |
| 388 | static u8 sht15_read_byte(struct sht15_data *data) |
| 389 | { |
| 390 | int i; |
| 391 | u8 byte = 0; |
| 392 | |
| 393 | for (i = 0; i < 8; ++i) { |
| 394 | byte <<= 1; |
| 395 | gpio_set_value(data->pdata->gpio_sck, 1); |
| 396 | ndelay(SHT15_TSCKH); |
| 397 | byte |= !!gpio_get_value(data->pdata->gpio_data); |
| 398 | gpio_set_value(data->pdata->gpio_sck, 0); |
| 399 | ndelay(SHT15_TSCKL); |
| 400 | } |
| 401 | return byte; |
| 402 | } |
| 403 | |
| 404 | /** |
| 405 | * sht15_send_status() - write the status register byte |
| 406 | * @data: sht15 specific data. |
| 407 | * @status: the byte to set the status register with. |
| 408 | * |
| 409 | * As described in figure 14 and table 5 of the datasheet. |
| 410 | */ |
| 411 | static int sht15_send_status(struct sht15_data *data, u8 status) |
| 412 | { |
| 413 | int ret; |
| 414 | |
| 415 | ret = sht15_send_cmd(data, SHT15_WRITE_STATUS); |
| 416 | if (ret) |
| 417 | return ret; |
| 418 | gpio_direction_output(data->pdata->gpio_data, 1); |
| 419 | ndelay(SHT15_TSU); |
| 420 | sht15_send_byte(data, status); |
| 421 | ret = sht15_wait_for_response(data); |
| 422 | if (ret) |
| 423 | return ret; |
| 424 | |
| 425 | data->val_status = status; |
Vivien Didelot | 181148a | 2011-04-12 15:34:37 -0400 | [diff] [blame] | 426 | return 0; |
| 427 | } |
| 428 | |
| 429 | /** |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 430 | * sht15_update_status() - get updated status register from device if too old |
| 431 | * @data: device instance specific data. |
| 432 | * |
| 433 | * As described in figure 15 and table 5 of the datasheet. |
| 434 | */ |
| 435 | static int sht15_update_status(struct sht15_data *data) |
| 436 | { |
| 437 | int ret = 0; |
| 438 | u8 status; |
Jerome Oufella | 82c7465 | 2011-04-12 15:34:39 -0400 | [diff] [blame] | 439 | u8 previous_config; |
| 440 | u8 dev_checksum = 0; |
| 441 | u8 checksum_vals[2]; |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 442 | int timeout = HZ; |
| 443 | |
| 444 | mutex_lock(&data->read_lock); |
| 445 | if (time_after(jiffies, data->last_status + timeout) |
| 446 | || !data->status_valid) { |
| 447 | ret = sht15_send_cmd(data, SHT15_READ_STATUS); |
| 448 | if (ret) |
| 449 | goto error_ret; |
| 450 | status = sht15_read_byte(data); |
| 451 | |
Jerome Oufella | 82c7465 | 2011-04-12 15:34:39 -0400 | [diff] [blame] | 452 | if (data->checksumming) { |
| 453 | sht15_ack(data); |
| 454 | dev_checksum = sht15_reverse(sht15_read_byte(data)); |
| 455 | checksum_vals[0] = SHT15_READ_STATUS; |
| 456 | checksum_vals[1] = status; |
| 457 | data->checksum_ok = (sht15_crc8(data, checksum_vals, 2) |
| 458 | == dev_checksum); |
| 459 | } |
| 460 | |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 461 | sht15_end_transmission(data); |
| 462 | |
Jerome Oufella | 82c7465 | 2011-04-12 15:34:39 -0400 | [diff] [blame] | 463 | /* |
| 464 | * Perform checksum validation on the received data. |
| 465 | * Specification mentions that in case a checksum verification |
| 466 | * fails, a soft reset command must be sent to the device. |
| 467 | */ |
| 468 | if (data->checksumming && !data->checksum_ok) { |
| 469 | previous_config = data->val_status & 0x07; |
| 470 | ret = sht15_soft_reset(data); |
| 471 | if (ret) |
| 472 | goto error_ret; |
| 473 | if (previous_config) { |
| 474 | ret = sht15_send_status(data, previous_config); |
| 475 | if (ret) { |
| 476 | dev_err(data->dev, |
| 477 | "CRC validation failed, unable " |
| 478 | "to restore device settings\n"); |
| 479 | goto error_ret; |
| 480 | } |
| 481 | } |
| 482 | ret = -EAGAIN; |
| 483 | goto error_ret; |
| 484 | } |
| 485 | |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 486 | data->val_status = status; |
| 487 | data->status_valid = true; |
| 488 | data->last_status = jiffies; |
| 489 | } |
| 490 | error_ret: |
| 491 | mutex_unlock(&data->read_lock); |
| 492 | |
| 493 | return ret; |
| 494 | } |
| 495 | |
| 496 | /** |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 497 | * sht15_measurement() - get a new value from device |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 498 | * @data: device instance specific data |
| 499 | * @command: command sent to request value |
| 500 | * @timeout_msecs: timeout after which comms are assumed |
| 501 | * to have failed are reset. |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 502 | */ |
| 503 | static int sht15_measurement(struct sht15_data *data, |
| 504 | int command, |
| 505 | int timeout_msecs) |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 506 | { |
| 507 | int ret; |
Jerome Oufella | 82c7465 | 2011-04-12 15:34:39 -0400 | [diff] [blame] | 508 | u8 previous_config; |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 509 | |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 510 | ret = sht15_send_cmd(data, command); |
| 511 | if (ret) |
| 512 | return ret; |
| 513 | |
| 514 | gpio_direction_input(data->pdata->gpio_data); |
| 515 | atomic_set(&data->interrupt_handled, 0); |
| 516 | |
| 517 | enable_irq(gpio_to_irq(data->pdata->gpio_data)); |
| 518 | if (gpio_get_value(data->pdata->gpio_data) == 0) { |
| 519 | disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data)); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 520 | /* Only relevant if the interrupt hasn't occurred. */ |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 521 | if (!atomic_read(&data->interrupt_handled)) |
| 522 | schedule_work(&data->read_work); |
| 523 | } |
| 524 | ret = wait_event_timeout(data->wait_queue, |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 525 | (data->state == SHT15_READING_NOTHING), |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 526 | msecs_to_jiffies(timeout_msecs)); |
| 527 | if (ret == 0) {/* timeout occurred */ |
Joe Perches | 24205e0 | 2009-07-11 13:42:37 +0200 | [diff] [blame] | 528 | disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data)); |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 529 | sht15_connection_reset(data); |
| 530 | return -ETIME; |
| 531 | } |
Jerome Oufella | 82c7465 | 2011-04-12 15:34:39 -0400 | [diff] [blame] | 532 | |
| 533 | /* |
| 534 | * Perform checksum validation on the received data. |
| 535 | * Specification mentions that in case a checksum verification fails, |
| 536 | * a soft reset command must be sent to the device. |
| 537 | */ |
| 538 | if (data->checksumming && !data->checksum_ok) { |
| 539 | previous_config = data->val_status & 0x07; |
| 540 | ret = sht15_soft_reset(data); |
| 541 | if (ret) |
| 542 | return ret; |
| 543 | if (previous_config) { |
| 544 | ret = sht15_send_status(data, previous_config); |
| 545 | if (ret) { |
| 546 | dev_err(data->dev, |
| 547 | "CRC validation failed, unable " |
| 548 | "to restore device settings\n"); |
| 549 | return ret; |
| 550 | } |
| 551 | } |
| 552 | return -EAGAIN; |
| 553 | } |
| 554 | |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 555 | return 0; |
| 556 | } |
| 557 | |
| 558 | /** |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 559 | * sht15_update_measurements() - get updated measures from device if too old |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 560 | * @data: device state |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 561 | */ |
| 562 | static int sht15_update_measurements(struct sht15_data *data) |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 563 | { |
| 564 | int ret = 0; |
| 565 | int timeout = HZ; |
| 566 | |
| 567 | mutex_lock(&data->read_lock); |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 568 | if (time_after(jiffies, data->last_measurement + timeout) |
| 569 | || !data->measurements_valid) { |
| 570 | data->state = SHT15_READING_HUMID; |
| 571 | ret = sht15_measurement(data, SHT15_MEASURE_RH, 160); |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 572 | if (ret) |
| 573 | goto error_ret; |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 574 | data->state = SHT15_READING_TEMP; |
| 575 | ret = sht15_measurement(data, SHT15_MEASURE_TEMP, 400); |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 576 | if (ret) |
| 577 | goto error_ret; |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 578 | data->measurements_valid = true; |
| 579 | data->last_measurement = jiffies; |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 580 | } |
| 581 | error_ret: |
| 582 | mutex_unlock(&data->read_lock); |
| 583 | |
| 584 | return ret; |
| 585 | } |
| 586 | |
| 587 | /** |
| 588 | * sht15_calc_temp() - convert the raw reading to a temperature |
| 589 | * @data: device state |
| 590 | * |
| 591 | * As per section 4.3 of the data sheet. |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 592 | */ |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 593 | static inline int sht15_calc_temp(struct sht15_data *data) |
| 594 | { |
Jerome Oufella | 328a2c2 | 2010-04-14 16:14:07 +0200 | [diff] [blame] | 595 | int d1 = temppoints[0].d1; |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 596 | int d2 = (data->val_status & SHT15_STATUS_LOW_RESOLUTION) ? 40 : 10; |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 597 | int i; |
| 598 | |
Jerome Oufella | 328a2c2 | 2010-04-14 16:14:07 +0200 | [diff] [blame] | 599 | for (i = ARRAY_SIZE(temppoints) - 1; i > 0; i--) |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 600 | /* Find pointer to interpolate */ |
| 601 | if (data->supply_uV > temppoints[i - 1].vdd) { |
Jerome Oufella | 328a2c2 | 2010-04-14 16:14:07 +0200 | [diff] [blame] | 602 | d1 = (data->supply_uV - temppoints[i - 1].vdd) |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 603 | * (temppoints[i].d1 - temppoints[i - 1].d1) |
| 604 | / (temppoints[i].vdd - temppoints[i - 1].vdd) |
| 605 | + temppoints[i - 1].d1; |
| 606 | break; |
| 607 | } |
| 608 | |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 609 | return data->val_temp * d2 + d1; |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | /** |
| 613 | * sht15_calc_humid() - using last temperature convert raw to humid |
| 614 | * @data: device state |
| 615 | * |
| 616 | * This is the temperature compensated version as per section 4.2 of |
| 617 | * the data sheet. |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 618 | * |
| 619 | * The sensor is assumed to be V3, which is compatible with V4. |
| 620 | * Humidity conversion coefficients are shown in table 7 of the datasheet. |
| 621 | */ |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 622 | static inline int sht15_calc_humid(struct sht15_data *data) |
| 623 | { |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 624 | int rh_linear; /* milli percent */ |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 625 | int temp = sht15_calc_temp(data); |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 626 | int c2, c3; |
| 627 | int t2; |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 628 | const int c1 = -4; |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 629 | |
| 630 | if (data->val_status & SHT15_STATUS_LOW_RESOLUTION) { |
| 631 | c2 = 648000; /* x 10 ^ -6 */ |
| 632 | c3 = -7200; /* x 10 ^ -7 */ |
| 633 | t2 = 1280; |
| 634 | } else { |
| 635 | c2 = 40500; /* x 10 ^ -6 */ |
| 636 | c3 = -28; /* x 10 ^ -7 */ |
| 637 | t2 = 80; |
| 638 | } |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 639 | |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 640 | rh_linear = c1 * 1000 |
| 641 | + c2 * data->val_humid / 1000 |
Vivien Didelot | ccd32e7 | 2011-03-21 17:59:35 +0100 | [diff] [blame] | 642 | + (data->val_humid * data->val_humid * c3) / 10000; |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 643 | return (temp - 25000) * (10000 + t2 * data->val_humid) |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 644 | / 1000000 + rh_linear; |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 645 | } |
| 646 | |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 647 | /** |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 648 | * sht15_show_status() - show status information in sysfs |
| 649 | * @dev: device. |
| 650 | * @attr: device attribute. |
| 651 | * @buf: sysfs buffer where information is written to. |
| 652 | * |
| 653 | * Will be called on read access to temp1_fault, humidity1_fault |
| 654 | * and heater_enable sysfs attributes. |
| 655 | * Returns number of bytes written into buffer, negative errno on error. |
| 656 | */ |
| 657 | static ssize_t sht15_show_status(struct device *dev, |
| 658 | struct device_attribute *attr, |
| 659 | char *buf) |
| 660 | { |
| 661 | int ret; |
| 662 | struct sht15_data *data = dev_get_drvdata(dev); |
| 663 | u8 bit = to_sensor_dev_attr(attr)->index; |
| 664 | |
| 665 | ret = sht15_update_status(data); |
| 666 | |
| 667 | return ret ? ret : sprintf(buf, "%d\n", !!(data->val_status & bit)); |
| 668 | } |
| 669 | |
| 670 | /** |
| 671 | * sht15_store_heater() - change heater state via sysfs |
| 672 | * @dev: device. |
| 673 | * @attr: device attribute. |
| 674 | * @buf: sysfs buffer to read the new heater state from. |
| 675 | * @count: length of the data. |
| 676 | * |
Vivien Didelot | e9b6e9f | 2011-07-25 21:46:10 +0200 | [diff] [blame] | 677 | * Will be called on write access to heater_enable sysfs attribute. |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 678 | * Returns number of bytes actually decoded, negative errno on error. |
| 679 | */ |
| 680 | static ssize_t sht15_store_heater(struct device *dev, |
| 681 | struct device_attribute *attr, |
| 682 | const char *buf, size_t count) |
| 683 | { |
| 684 | int ret; |
| 685 | struct sht15_data *data = dev_get_drvdata(dev); |
| 686 | long value; |
| 687 | u8 status; |
| 688 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 689 | if (kstrtol(buf, 10, &value)) |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 690 | return -EINVAL; |
| 691 | |
| 692 | mutex_lock(&data->read_lock); |
| 693 | status = data->val_status & 0x07; |
| 694 | if (!!value) |
| 695 | status |= SHT15_STATUS_HEATER; |
| 696 | else |
| 697 | status &= ~SHT15_STATUS_HEATER; |
| 698 | |
| 699 | ret = sht15_send_status(data, status); |
| 700 | mutex_unlock(&data->read_lock); |
| 701 | |
| 702 | return ret ? ret : count; |
| 703 | } |
| 704 | |
| 705 | /** |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 706 | * sht15_show_temp() - show temperature measurement value in sysfs |
| 707 | * @dev: device. |
| 708 | * @attr: device attribute. |
| 709 | * @buf: sysfs buffer where measurement values are written to. |
| 710 | * |
| 711 | * Will be called on read access to temp1_input sysfs attribute. |
| 712 | * Returns number of bytes written into buffer, negative errno on error. |
| 713 | */ |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 714 | static ssize_t sht15_show_temp(struct device *dev, |
| 715 | struct device_attribute *attr, |
| 716 | char *buf) |
| 717 | { |
| 718 | int ret; |
| 719 | struct sht15_data *data = dev_get_drvdata(dev); |
| 720 | |
| 721 | /* Technically no need to read humidity as well */ |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 722 | ret = sht15_update_measurements(data); |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 723 | |
| 724 | return ret ? ret : sprintf(buf, "%d\n", |
| 725 | sht15_calc_temp(data)); |
| 726 | } |
| 727 | |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 728 | /** |
| 729 | * sht15_show_humidity() - show humidity measurement value in sysfs |
| 730 | * @dev: device. |
| 731 | * @attr: device attribute. |
| 732 | * @buf: sysfs buffer where measurement values are written to. |
| 733 | * |
| 734 | * Will be called on read access to humidity1_input sysfs attribute. |
| 735 | * Returns number of bytes written into buffer, negative errno on error. |
| 736 | */ |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 737 | static ssize_t sht15_show_humidity(struct device *dev, |
| 738 | struct device_attribute *attr, |
| 739 | char *buf) |
| 740 | { |
| 741 | int ret; |
| 742 | struct sht15_data *data = dev_get_drvdata(dev); |
| 743 | |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 744 | ret = sht15_update_measurements(data); |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 745 | |
| 746 | return ret ? ret : sprintf(buf, "%d\n", sht15_calc_humid(data)); |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 747 | } |
| 748 | |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 749 | static ssize_t show_name(struct device *dev, |
| 750 | struct device_attribute *attr, |
| 751 | char *buf) |
| 752 | { |
| 753 | struct platform_device *pdev = to_platform_device(dev); |
| 754 | return sprintf(buf, "%s\n", pdev->name); |
| 755 | } |
| 756 | |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 757 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, |
| 758 | sht15_show_temp, NULL, 0); |
| 759 | static SENSOR_DEVICE_ATTR(humidity1_input, S_IRUGO, |
| 760 | sht15_show_humidity, NULL, 0); |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 761 | static SENSOR_DEVICE_ATTR(temp1_fault, S_IRUGO, sht15_show_status, NULL, |
| 762 | SHT15_STATUS_LOW_BATTERY); |
| 763 | static SENSOR_DEVICE_ATTR(humidity1_fault, S_IRUGO, sht15_show_status, NULL, |
| 764 | SHT15_STATUS_LOW_BATTERY); |
| 765 | static SENSOR_DEVICE_ATTR(heater_enable, S_IRUGO | S_IWUSR, sht15_show_status, |
| 766 | sht15_store_heater, SHT15_STATUS_HEATER); |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 767 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); |
| 768 | static struct attribute *sht15_attrs[] = { |
| 769 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
| 770 | &sensor_dev_attr_humidity1_input.dev_attr.attr, |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 771 | &sensor_dev_attr_temp1_fault.dev_attr.attr, |
| 772 | &sensor_dev_attr_humidity1_fault.dev_attr.attr, |
| 773 | &sensor_dev_attr_heater_enable.dev_attr.attr, |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 774 | &dev_attr_name.attr, |
| 775 | NULL, |
| 776 | }; |
| 777 | |
| 778 | static const struct attribute_group sht15_attr_group = { |
| 779 | .attrs = sht15_attrs, |
| 780 | }; |
| 781 | |
| 782 | static irqreturn_t sht15_interrupt_fired(int irq, void *d) |
| 783 | { |
| 784 | struct sht15_data *data = d; |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 785 | |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 786 | /* First disable the interrupt */ |
| 787 | disable_irq_nosync(irq); |
| 788 | atomic_inc(&data->interrupt_handled); |
| 789 | /* Then schedule a reading work struct */ |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 790 | if (data->state != SHT15_READING_NOTHING) |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 791 | schedule_work(&data->read_work); |
| 792 | return IRQ_HANDLED; |
| 793 | } |
| 794 | |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 795 | static void sht15_bh_read_data(struct work_struct *work_s) |
| 796 | { |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 797 | uint16_t val = 0; |
Jerome Oufella | 82c7465 | 2011-04-12 15:34:39 -0400 | [diff] [blame] | 798 | u8 dev_checksum = 0; |
| 799 | u8 checksum_vals[3]; |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 800 | struct sht15_data *data |
| 801 | = container_of(work_s, struct sht15_data, |
| 802 | read_work); |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 803 | |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 804 | /* Firstly, verify the line is low */ |
| 805 | if (gpio_get_value(data->pdata->gpio_data)) { |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 806 | /* |
| 807 | * If not, then start the interrupt again - care here as could |
| 808 | * have gone low in meantime so verify it hasn't! |
| 809 | */ |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 810 | atomic_set(&data->interrupt_handled, 0); |
| 811 | enable_irq(gpio_to_irq(data->pdata->gpio_data)); |
Frans Meulenbroeks | c9e1498 | 2012-01-08 19:34:06 +0100 | [diff] [blame] | 812 | /* If still not occurred or another handler was scheduled */ |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 813 | if (gpio_get_value(data->pdata->gpio_data) |
| 814 | || atomic_read(&data->interrupt_handled)) |
| 815 | return; |
| 816 | } |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 817 | |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 818 | /* Read the data back from the device */ |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 819 | val = sht15_read_byte(data); |
| 820 | val <<= 8; |
| 821 | sht15_ack(data); |
| 822 | val |= sht15_read_byte(data); |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 823 | |
Jerome Oufella | 82c7465 | 2011-04-12 15:34:39 -0400 | [diff] [blame] | 824 | if (data->checksumming) { |
| 825 | /* |
| 826 | * Ask the device for a checksum and read it back. |
| 827 | * Note: the device sends the checksum byte reversed. |
| 828 | */ |
| 829 | sht15_ack(data); |
| 830 | dev_checksum = sht15_reverse(sht15_read_byte(data)); |
| 831 | checksum_vals[0] = (data->state == SHT15_READING_TEMP) ? |
| 832 | SHT15_MEASURE_TEMP : SHT15_MEASURE_RH; |
| 833 | checksum_vals[1] = (u8) (val >> 8); |
| 834 | checksum_vals[2] = (u8) val; |
| 835 | data->checksum_ok |
| 836 | = (sht15_crc8(data, checksum_vals, 3) == dev_checksum); |
| 837 | } |
| 838 | |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 839 | /* Tell the device we are done */ |
| 840 | sht15_end_transmission(data); |
| 841 | |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 842 | switch (data->state) { |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 843 | case SHT15_READING_TEMP: |
| 844 | data->val_temp = val; |
| 845 | break; |
| 846 | case SHT15_READING_HUMID: |
| 847 | data->val_humid = val; |
| 848 | break; |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 849 | default: |
| 850 | break; |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 851 | } |
| 852 | |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 853 | data->state = SHT15_READING_NOTHING; |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 854 | wake_up(&data->wait_queue); |
| 855 | } |
| 856 | |
| 857 | static void sht15_update_voltage(struct work_struct *work_s) |
| 858 | { |
| 859 | struct sht15_data *data |
| 860 | = container_of(work_s, struct sht15_data, |
| 861 | update_supply_work); |
| 862 | data->supply_uV = regulator_get_voltage(data->reg); |
| 863 | } |
| 864 | |
| 865 | /** |
| 866 | * sht15_invalidate_voltage() - mark supply voltage invalid when notified by reg |
| 867 | * @nb: associated notification structure |
| 868 | * @event: voltage regulator state change event code |
| 869 | * @ignored: function parameter - ignored here |
| 870 | * |
| 871 | * Note that as the notification code holds the regulator lock, we have |
| 872 | * to schedule an update of the supply voltage rather than getting it directly. |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 873 | */ |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 874 | static int sht15_invalidate_voltage(struct notifier_block *nb, |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 875 | unsigned long event, |
| 876 | void *ignored) |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 877 | { |
| 878 | struct sht15_data *data = container_of(nb, struct sht15_data, nb); |
| 879 | |
| 880 | if (event == REGULATOR_EVENT_VOLTAGE_CHANGE) |
| 881 | data->supply_uV_valid = false; |
| 882 | schedule_work(&data->update_supply_work); |
| 883 | |
| 884 | return NOTIFY_OK; |
| 885 | } |
| 886 | |
Bill Pemberton | 6c931ae | 2012-11-19 13:22:35 -0500 | [diff] [blame] | 887 | static int sht15_probe(struct platform_device *pdev) |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 888 | { |
Vivien Didelot | 6edf3c3 | 2012-01-26 15:59:00 -0500 | [diff] [blame] | 889 | int ret; |
Guenter Roeck | 38fe756 | 2012-06-02 11:20:22 -0700 | [diff] [blame] | 890 | struct sht15_data *data; |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 891 | u8 status = 0; |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 892 | |
Guenter Roeck | 38fe756 | 2012-06-02 11:20:22 -0700 | [diff] [blame] | 893 | data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); |
| 894 | if (!data) |
| 895 | return -ENOMEM; |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 896 | |
| 897 | INIT_WORK(&data->read_work, sht15_bh_read_data); |
| 898 | INIT_WORK(&data->update_supply_work, sht15_update_voltage); |
| 899 | platform_set_drvdata(pdev, data); |
| 900 | mutex_init(&data->read_lock); |
| 901 | data->dev = &pdev->dev; |
| 902 | init_waitqueue_head(&data->wait_queue); |
| 903 | |
| 904 | if (pdev->dev.platform_data == NULL) { |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 905 | dev_err(&pdev->dev, "no platform data supplied\n"); |
Guenter Roeck | 38fe756 | 2012-06-02 11:20:22 -0700 | [diff] [blame] | 906 | return -EINVAL; |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 907 | } |
| 908 | data->pdata = pdev->dev.platform_data; |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 909 | data->supply_uV = data->pdata->supply_mv * 1000; |
Jerome Oufella | 82c7465 | 2011-04-12 15:34:39 -0400 | [diff] [blame] | 910 | if (data->pdata->checksum) |
| 911 | data->checksumming = true; |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 912 | if (data->pdata->no_otp_reload) |
| 913 | status |= SHT15_STATUS_NO_OTP_RELOAD; |
| 914 | if (data->pdata->low_resolution) |
| 915 | status |= SHT15_STATUS_LOW_RESOLUTION; |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 916 | |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 917 | /* |
| 918 | * If a regulator is available, |
| 919 | * query what the supply voltage actually is! |
| 920 | */ |
Guenter Roeck | 38fe756 | 2012-06-02 11:20:22 -0700 | [diff] [blame] | 921 | data->reg = devm_regulator_get(data->dev, "vcc"); |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 922 | if (!IS_ERR(data->reg)) { |
Jean Delvare | c7a78d2 | 2010-04-14 16:14:08 +0200 | [diff] [blame] | 923 | int voltage; |
| 924 | |
| 925 | voltage = regulator_get_voltage(data->reg); |
| 926 | if (voltage) |
| 927 | data->supply_uV = voltage; |
| 928 | |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 929 | regulator_enable(data->reg); |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 930 | /* |
| 931 | * Setup a notifier block to update this if another device |
| 932 | * causes the voltage to change |
| 933 | */ |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 934 | data->nb.notifier_call = &sht15_invalidate_voltage; |
| 935 | ret = regulator_register_notifier(data->reg, &data->nb); |
Vivien Didelot | 181148a | 2011-04-12 15:34:37 -0400 | [diff] [blame] | 936 | if (ret) { |
| 937 | dev_err(&pdev->dev, |
| 938 | "regulator notifier request failed\n"); |
| 939 | regulator_disable(data->reg); |
Guenter Roeck | 38fe756 | 2012-06-02 11:20:22 -0700 | [diff] [blame] | 940 | return ret; |
Vivien Didelot | 181148a | 2011-04-12 15:34:37 -0400 | [diff] [blame] | 941 | } |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 942 | } |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 943 | |
| 944 | /* Try requesting the GPIOs */ |
Guenter Roeck | 38fe756 | 2012-06-02 11:20:22 -0700 | [diff] [blame] | 945 | ret = devm_gpio_request(&pdev->dev, data->pdata->gpio_sck, "SHT15 sck"); |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 946 | if (ret) { |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 947 | dev_err(&pdev->dev, "gpio request failed\n"); |
Vivien Didelot | 181148a | 2011-04-12 15:34:37 -0400 | [diff] [blame] | 948 | goto err_release_reg; |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 949 | } |
| 950 | gpio_direction_output(data->pdata->gpio_sck, 0); |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 951 | |
Guenter Roeck | 38fe756 | 2012-06-02 11:20:22 -0700 | [diff] [blame] | 952 | ret = devm_gpio_request(&pdev->dev, data->pdata->gpio_data, |
| 953 | "SHT15 data"); |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 954 | if (ret) { |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 955 | dev_err(&pdev->dev, "gpio request failed\n"); |
Guenter Roeck | 38fe756 | 2012-06-02 11:20:22 -0700 | [diff] [blame] | 956 | goto err_release_reg; |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 957 | } |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 958 | |
Guenter Roeck | 38fe756 | 2012-06-02 11:20:22 -0700 | [diff] [blame] | 959 | ret = devm_request_irq(&pdev->dev, gpio_to_irq(data->pdata->gpio_data), |
| 960 | sht15_interrupt_fired, |
| 961 | IRQF_TRIGGER_FALLING, |
| 962 | "sht15 data", |
| 963 | data); |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 964 | if (ret) { |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 965 | dev_err(&pdev->dev, "failed to get irq for data line\n"); |
Guenter Roeck | 38fe756 | 2012-06-02 11:20:22 -0700 | [diff] [blame] | 966 | goto err_release_reg; |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 967 | } |
| 968 | disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data)); |
| 969 | sht15_connection_reset(data); |
Vivien Didelot | 181148a | 2011-04-12 15:34:37 -0400 | [diff] [blame] | 970 | ret = sht15_soft_reset(data); |
| 971 | if (ret) |
Guenter Roeck | 38fe756 | 2012-06-02 11:20:22 -0700 | [diff] [blame] | 972 | goto err_release_reg; |
Vivien Didelot | 181148a | 2011-04-12 15:34:37 -0400 | [diff] [blame] | 973 | |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 974 | /* write status with platform data options */ |
| 975 | if (status) { |
| 976 | ret = sht15_send_status(data, status); |
| 977 | if (ret) |
Guenter Roeck | 38fe756 | 2012-06-02 11:20:22 -0700 | [diff] [blame] | 978 | goto err_release_reg; |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 979 | } |
| 980 | |
Vivien Didelot | 181148a | 2011-04-12 15:34:37 -0400 | [diff] [blame] | 981 | ret = sysfs_create_group(&pdev->dev.kobj, &sht15_attr_group); |
| 982 | if (ret) { |
| 983 | dev_err(&pdev->dev, "sysfs create failed\n"); |
Guenter Roeck | 38fe756 | 2012-06-02 11:20:22 -0700 | [diff] [blame] | 984 | goto err_release_reg; |
Vivien Didelot | 181148a | 2011-04-12 15:34:37 -0400 | [diff] [blame] | 985 | } |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 986 | |
| 987 | data->hwmon_dev = hwmon_device_register(data->dev); |
| 988 | if (IS_ERR(data->hwmon_dev)) { |
| 989 | ret = PTR_ERR(data->hwmon_dev); |
Vivien Didelot | 181148a | 2011-04-12 15:34:37 -0400 | [diff] [blame] | 990 | goto err_release_sysfs_group; |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 991 | } |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 992 | |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 993 | return 0; |
| 994 | |
Vivien Didelot | 181148a | 2011-04-12 15:34:37 -0400 | [diff] [blame] | 995 | err_release_sysfs_group: |
| 996 | sysfs_remove_group(&pdev->dev.kobj, &sht15_attr_group); |
Vivien Didelot | 181148a | 2011-04-12 15:34:37 -0400 | [diff] [blame] | 997 | err_release_reg: |
| 998 | if (!IS_ERR(data->reg)) { |
| 999 | regulator_unregister_notifier(data->reg, &data->nb); |
| 1000 | regulator_disable(data->reg); |
Vivien Didelot | 181148a | 2011-04-12 15:34:37 -0400 | [diff] [blame] | 1001 | } |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 1002 | return ret; |
| 1003 | } |
| 1004 | |
Bill Pemberton | 281dfd0 | 2012-11-19 13:25:51 -0500 | [diff] [blame] | 1005 | static int sht15_remove(struct platform_device *pdev) |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 1006 | { |
| 1007 | struct sht15_data *data = platform_get_drvdata(pdev); |
| 1008 | |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 1009 | /* |
| 1010 | * Make sure any reads from the device are done and |
| 1011 | * prevent new ones beginning |
| 1012 | */ |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 1013 | mutex_lock(&data->read_lock); |
Vivien Didelot | cc15c7e | 2011-04-12 15:34:38 -0400 | [diff] [blame] | 1014 | if (sht15_soft_reset(data)) { |
| 1015 | mutex_unlock(&data->read_lock); |
| 1016 | return -EFAULT; |
| 1017 | } |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 1018 | hwmon_device_unregister(data->hwmon_dev); |
| 1019 | sysfs_remove_group(&pdev->dev.kobj, &sht15_attr_group); |
| 1020 | if (!IS_ERR(data->reg)) { |
| 1021 | regulator_unregister_notifier(data->reg, &data->nb); |
| 1022 | regulator_disable(data->reg); |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 1023 | } |
| 1024 | |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 1025 | mutex_unlock(&data->read_lock); |
Vivien Didelot | 99a0378 | 2011-04-12 15:34:36 -0400 | [diff] [blame] | 1026 | |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 1027 | return 0; |
| 1028 | } |
| 1029 | |
Vivien Didelot | edec5af | 2012-08-30 21:46:19 -0400 | [diff] [blame] | 1030 | static struct platform_device_id sht15_device_ids[] = { |
| 1031 | { "sht10", sht10 }, |
| 1032 | { "sht11", sht11 }, |
| 1033 | { "sht15", sht15 }, |
| 1034 | { "sht71", sht71 }, |
| 1035 | { "sht75", sht75 }, |
| 1036 | { } |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 1037 | }; |
Vivien Didelot | edec5af | 2012-08-30 21:46:19 -0400 | [diff] [blame] | 1038 | MODULE_DEVICE_TABLE(platform, sht15_device_ids); |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 1039 | |
Vivien Didelot | edec5af | 2012-08-30 21:46:19 -0400 | [diff] [blame] | 1040 | static struct platform_driver sht15_driver = { |
| 1041 | .driver = { |
| 1042 | .name = "sht15", |
| 1043 | .owner = THIS_MODULE, |
| 1044 | }, |
| 1045 | .probe = sht15_probe, |
Bill Pemberton | 9e5e9b7 | 2012-11-19 13:21:20 -0500 | [diff] [blame] | 1046 | .remove = sht15_remove, |
Vivien Didelot | edec5af | 2012-08-30 21:46:19 -0400 | [diff] [blame] | 1047 | .id_table = sht15_device_ids, |
| 1048 | }; |
| 1049 | module_platform_driver(sht15_driver); |
Jonathan Cameron | 251eb40 | 2009-04-13 14:39:45 -0700 | [diff] [blame] | 1050 | |
| 1051 | MODULE_LICENSE("GPL"); |
Vivien Didelot | edec5af | 2012-08-30 21:46:19 -0400 | [diff] [blame] | 1052 | MODULE_DESCRIPTION("Sensirion SHT15 temperature and humidity sensor driver"); |