sht15.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. /*
  2. * sht15.c - support for the SHT15 Temperature and Humidity Sensor
  3. *
  4. * Copyright (c) 2009 Jonathan Cameron
  5. *
  6. * Copyright (c) 2007 Wouter Horre
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * Currently ignoring checksum on readings.
  13. * Default resolution only (14bit temp, 12bit humidity)
  14. * Ignoring battery status.
  15. * Heater not enabled.
  16. * Timings are all conservative.
  17. *
  18. * Data sheet available (1/2009) at
  19. * http://www.sensirion.ch/en/pdf/product_information/Datasheet-humidity-sensor-SHT1x.pdf
  20. *
  21. * Regulator supply name = vcc
  22. */
  23. #include <linux/interrupt.h>
  24. #include <linux/irq.h>
  25. #include <linux/gpio.h>
  26. #include <linux/module.h>
  27. #include <linux/init.h>
  28. #include <linux/hwmon.h>
  29. #include <linux/hwmon-sysfs.h>
  30. #include <linux/mutex.h>
  31. #include <linux/platform_device.h>
  32. #include <linux/delay.h>
  33. #include <linux/jiffies.h>
  34. #include <linux/err.h>
  35. #include <linux/sht15.h>
  36. #include <linux/regulator/consumer.h>
  37. #include <asm/atomic.h>
  38. #define SHT15_MEASURE_TEMP 3
  39. #define SHT15_MEASURE_RH 5
  40. #define SHT15_READING_NOTHING 0
  41. #define SHT15_READING_TEMP 1
  42. #define SHT15_READING_HUMID 2
  43. /* Min timings in nsecs */
  44. #define SHT15_TSCKL 100 /* clock low */
  45. #define SHT15_TSCKH 100 /* clock high */
  46. #define SHT15_TSU 150 /* data setup time */
  47. /**
  48. * struct sht15_temppair - elements of voltage dependant temp calc
  49. * @vdd: supply voltage in microvolts
  50. * @d1: see data sheet
  51. */
  52. struct sht15_temppair {
  53. int vdd; /* microvolts */
  54. int d1;
  55. };
  56. /* Table 9 from data sheet - relates temperature calculation
  57. * to supply voltage.
  58. */
  59. static const struct sht15_temppair temppoints[] = {
  60. { 2500000, -39400 },
  61. { 3000000, -39600 },
  62. { 3500000, -39700 },
  63. { 4000000, -39800 },
  64. { 5000000, -40100 },
  65. };
  66. /**
  67. * struct sht15_data - device instance specific data
  68. * @pdata: platform data (gpio's etc)
  69. * @read_work: bh of interrupt handler
  70. * @wait_queue: wait queue for getting values from device
  71. * @val_temp: last temperature value read from device
  72. * @val_humid: last humidity value read from device
  73. * @flag: status flag used to identify what the last request was
  74. * @valid: are the current stored values valid (start condition)
  75. * @last_updat: time of last update
  76. * @read_lock: mutex to ensure only one read in progress
  77. * at a time.
  78. * @dev: associate device structure
  79. * @hwmon_dev: device associated with hwmon subsystem
  80. * @reg: associated regulator (if specified)
  81. * @nb: notifier block to handle notifications of voltage changes
  82. * @supply_uV: local copy of supply voltage used to allow
  83. * use of regulator consumer if available
  84. * @supply_uV_valid: indicates that an updated value has not yet
  85. * been obtained from the regulator and so any calculations
  86. * based upon it will be invalid.
  87. * @update_supply_work: work struct that is used to update the supply_uV
  88. * @interrupt_handled: flag used to indicate a hander has been scheduled
  89. */
  90. struct sht15_data {
  91. struct sht15_platform_data *pdata;
  92. struct work_struct read_work;
  93. wait_queue_head_t wait_queue;
  94. uint16_t val_temp;
  95. uint16_t val_humid;
  96. u8 flag;
  97. u8 valid;
  98. unsigned long last_updat;
  99. struct mutex read_lock;
  100. struct device *dev;
  101. struct device *hwmon_dev;
  102. struct regulator *reg;
  103. struct notifier_block nb;
  104. int supply_uV;
  105. int supply_uV_valid;
  106. struct work_struct update_supply_work;
  107. atomic_t interrupt_handled;
  108. };
  109. /**
  110. * sht15_connection_reset() - reset the comms interface
  111. * @data: sht15 specific data
  112. *
  113. * This implements section 3.4 of the data sheet
  114. */
  115. static void sht15_connection_reset(struct sht15_data *data)
  116. {
  117. int i;
  118. gpio_direction_output(data->pdata->gpio_data, 1);
  119. ndelay(SHT15_TSCKL);
  120. gpio_set_value(data->pdata->gpio_sck, 0);
  121. ndelay(SHT15_TSCKL);
  122. for (i = 0; i < 9; ++i) {
  123. gpio_set_value(data->pdata->gpio_sck, 1);
  124. ndelay(SHT15_TSCKH);
  125. gpio_set_value(data->pdata->gpio_sck, 0);
  126. ndelay(SHT15_TSCKL);
  127. }
  128. }
  129. /**
  130. * sht15_send_bit() - send an individual bit to the device
  131. * @data: device state data
  132. * @val: value of bit to be sent
  133. **/
  134. static inline void sht15_send_bit(struct sht15_data *data, int val)
  135. {
  136. gpio_set_value(data->pdata->gpio_data, val);
  137. ndelay(SHT15_TSU);
  138. gpio_set_value(data->pdata->gpio_sck, 1);
  139. ndelay(SHT15_TSCKH);
  140. gpio_set_value(data->pdata->gpio_sck, 0);
  141. ndelay(SHT15_TSCKL); /* clock low time */
  142. }
  143. /**
  144. * sht15_transmission_start() - specific sequence for new transmission
  145. *
  146. * @data: device state data
  147. * Timings for this are not documented on the data sheet, so very
  148. * conservative ones used in implementation. This implements
  149. * figure 12 on the data sheet.
  150. **/
  151. static void sht15_transmission_start(struct sht15_data *data)
  152. {
  153. /* ensure data is high and output */
  154. gpio_direction_output(data->pdata->gpio_data, 1);
  155. ndelay(SHT15_TSU);
  156. gpio_set_value(data->pdata->gpio_sck, 0);
  157. ndelay(SHT15_TSCKL);
  158. gpio_set_value(data->pdata->gpio_sck, 1);
  159. ndelay(SHT15_TSCKH);
  160. gpio_set_value(data->pdata->gpio_data, 0);
  161. ndelay(SHT15_TSU);
  162. gpio_set_value(data->pdata->gpio_sck, 0);
  163. ndelay(SHT15_TSCKL);
  164. gpio_set_value(data->pdata->gpio_sck, 1);
  165. ndelay(SHT15_TSCKH);
  166. gpio_set_value(data->pdata->gpio_data, 1);
  167. ndelay(SHT15_TSU);
  168. gpio_set_value(data->pdata->gpio_sck, 0);
  169. ndelay(SHT15_TSCKL);
  170. }
  171. /**
  172. * sht15_send_byte() - send a single byte to the device
  173. * @data: device state
  174. * @byte: value to be sent
  175. **/
  176. static void sht15_send_byte(struct sht15_data *data, u8 byte)
  177. {
  178. int i;
  179. for (i = 0; i < 8; i++) {
  180. sht15_send_bit(data, !!(byte & 0x80));
  181. byte <<= 1;
  182. }
  183. }
  184. /**
  185. * sht15_wait_for_response() - checks for ack from device
  186. * @data: device state
  187. **/
  188. static int sht15_wait_for_response(struct sht15_data *data)
  189. {
  190. gpio_direction_input(data->pdata->gpio_data);
  191. gpio_set_value(data->pdata->gpio_sck, 1);
  192. ndelay(SHT15_TSCKH);
  193. if (gpio_get_value(data->pdata->gpio_data)) {
  194. gpio_set_value(data->pdata->gpio_sck, 0);
  195. dev_err(data->dev, "Command not acknowledged\n");
  196. sht15_connection_reset(data);
  197. return -EIO;
  198. }
  199. gpio_set_value(data->pdata->gpio_sck, 0);
  200. ndelay(SHT15_TSCKL);
  201. return 0;
  202. }
  203. /**
  204. * sht15_send_cmd() - Sends a command to the device.
  205. * @data: device state
  206. * @cmd: command byte to be sent
  207. *
  208. * On entry, sck is output low, data is output pull high
  209. * and the interrupt disabled.
  210. **/
  211. static int sht15_send_cmd(struct sht15_data *data, u8 cmd)
  212. {
  213. int ret = 0;
  214. sht15_transmission_start(data);
  215. sht15_send_byte(data, cmd);
  216. ret = sht15_wait_for_response(data);
  217. return ret;
  218. }
  219. /**
  220. * sht15_update_single_val() - get a new value from device
  221. * @data: device instance specific data
  222. * @command: command sent to request value
  223. * @timeout_msecs: timeout after which comms are assumed
  224. * to have failed are reset.
  225. **/
  226. static inline int sht15_update_single_val(struct sht15_data *data,
  227. int command,
  228. int timeout_msecs)
  229. {
  230. int ret;
  231. ret = sht15_send_cmd(data, command);
  232. if (ret)
  233. return ret;
  234. gpio_direction_input(data->pdata->gpio_data);
  235. atomic_set(&data->interrupt_handled, 0);
  236. enable_irq(gpio_to_irq(data->pdata->gpio_data));
  237. if (gpio_get_value(data->pdata->gpio_data) == 0) {
  238. disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
  239. /* Only relevant if the interrupt hasn't occured. */
  240. if (!atomic_read(&data->interrupt_handled))
  241. schedule_work(&data->read_work);
  242. }
  243. ret = wait_event_timeout(data->wait_queue,
  244. (data->flag == SHT15_READING_NOTHING),
  245. msecs_to_jiffies(timeout_msecs));
  246. if (ret == 0) {/* timeout occurred */
  247. disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));;
  248. sht15_connection_reset(data);
  249. return -ETIME;
  250. }
  251. return 0;
  252. }
  253. /**
  254. * sht15_update_vals() - get updated readings from device if too old
  255. * @data: device state
  256. **/
  257. static int sht15_update_vals(struct sht15_data *data)
  258. {
  259. int ret = 0;
  260. int timeout = HZ;
  261. mutex_lock(&data->read_lock);
  262. if (time_after(jiffies, data->last_updat + timeout)
  263. || !data->valid) {
  264. data->flag = SHT15_READING_HUMID;
  265. ret = sht15_update_single_val(data, SHT15_MEASURE_RH, 160);
  266. if (ret)
  267. goto error_ret;
  268. data->flag = SHT15_READING_TEMP;
  269. ret = sht15_update_single_val(data, SHT15_MEASURE_TEMP, 400);
  270. if (ret)
  271. goto error_ret;
  272. data->valid = 1;
  273. data->last_updat = jiffies;
  274. }
  275. error_ret:
  276. mutex_unlock(&data->read_lock);
  277. return ret;
  278. }
  279. /**
  280. * sht15_calc_temp() - convert the raw reading to a temperature
  281. * @data: device state
  282. *
  283. * As per section 4.3 of the data sheet.
  284. **/
  285. static inline int sht15_calc_temp(struct sht15_data *data)
  286. {
  287. int d1 = 0;
  288. int i;
  289. for (i = 1; i < ARRAY_SIZE(temppoints) - 1; i++)
  290. /* Find pointer to interpolate */
  291. if (data->supply_uV > temppoints[i - 1].vdd) {
  292. d1 = (data->supply_uV/1000 - temppoints[i - 1].vdd)
  293. * (temppoints[i].d1 - temppoints[i - 1].d1)
  294. / (temppoints[i].vdd - temppoints[i - 1].vdd)
  295. + temppoints[i - 1].d1;
  296. break;
  297. }
  298. return data->val_temp*10 + d1;
  299. }
  300. /**
  301. * sht15_calc_humid() - using last temperature convert raw to humid
  302. * @data: device state
  303. *
  304. * This is the temperature compensated version as per section 4.2 of
  305. * the data sheet.
  306. **/
  307. static inline int sht15_calc_humid(struct sht15_data *data)
  308. {
  309. int RHlinear; /* milli percent */
  310. int temp = sht15_calc_temp(data);
  311. const int c1 = -4;
  312. const int c2 = 40500; /* x 10 ^ -6 */
  313. const int c3 = 2800; /* x10 ^ -9 */
  314. RHlinear = c1*1000
  315. + c2 * data->val_humid/1000
  316. + (data->val_humid * data->val_humid * c3)/1000000;
  317. return (temp - 25000) * (10000 + 800 * data->val_humid)
  318. / 1000000 + RHlinear;
  319. }
  320. static ssize_t sht15_show_temp(struct device *dev,
  321. struct device_attribute *attr,
  322. char *buf)
  323. {
  324. int ret;
  325. struct sht15_data *data = dev_get_drvdata(dev);
  326. /* Technically no need to read humidity as well */
  327. ret = sht15_update_vals(data);
  328. return ret ? ret : sprintf(buf, "%d\n",
  329. sht15_calc_temp(data));
  330. }
  331. static ssize_t sht15_show_humidity(struct device *dev,
  332. struct device_attribute *attr,
  333. char *buf)
  334. {
  335. int ret;
  336. struct sht15_data *data = dev_get_drvdata(dev);
  337. ret = sht15_update_vals(data);
  338. return ret ? ret : sprintf(buf, "%d\n", sht15_calc_humid(data));
  339. };
  340. static ssize_t show_name(struct device *dev,
  341. struct device_attribute *attr,
  342. char *buf)
  343. {
  344. struct platform_device *pdev = to_platform_device(dev);
  345. return sprintf(buf, "%s\n", pdev->name);
  346. }
  347. static SENSOR_DEVICE_ATTR(temp1_input,
  348. S_IRUGO, sht15_show_temp,
  349. NULL, 0);
  350. static SENSOR_DEVICE_ATTR(humidity1_input,
  351. S_IRUGO, sht15_show_humidity,
  352. NULL, 0);
  353. static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
  354. static struct attribute *sht15_attrs[] = {
  355. &sensor_dev_attr_temp1_input.dev_attr.attr,
  356. &sensor_dev_attr_humidity1_input.dev_attr.attr,
  357. &dev_attr_name.attr,
  358. NULL,
  359. };
  360. static const struct attribute_group sht15_attr_group = {
  361. .attrs = sht15_attrs,
  362. };
  363. static irqreturn_t sht15_interrupt_fired(int irq, void *d)
  364. {
  365. struct sht15_data *data = d;
  366. /* First disable the interrupt */
  367. disable_irq_nosync(irq);
  368. atomic_inc(&data->interrupt_handled);
  369. /* Then schedule a reading work struct */
  370. if (data->flag != SHT15_READING_NOTHING)
  371. schedule_work(&data->read_work);
  372. return IRQ_HANDLED;
  373. }
  374. /* Each byte of data is acknowledged by pulling the data line
  375. * low for one clock pulse.
  376. */
  377. static void sht15_ack(struct sht15_data *data)
  378. {
  379. gpio_direction_output(data->pdata->gpio_data, 0);
  380. ndelay(SHT15_TSU);
  381. gpio_set_value(data->pdata->gpio_sck, 1);
  382. ndelay(SHT15_TSU);
  383. gpio_set_value(data->pdata->gpio_sck, 0);
  384. ndelay(SHT15_TSU);
  385. gpio_set_value(data->pdata->gpio_data, 1);
  386. gpio_direction_input(data->pdata->gpio_data);
  387. }
  388. /**
  389. * sht15_end_transmission() - notify device of end of transmission
  390. * @data: device state
  391. *
  392. * This is basically a NAK. (single clock pulse, data high)
  393. **/
  394. static void sht15_end_transmission(struct sht15_data *data)
  395. {
  396. gpio_direction_output(data->pdata->gpio_data, 1);
  397. ndelay(SHT15_TSU);
  398. gpio_set_value(data->pdata->gpio_sck, 1);
  399. ndelay(SHT15_TSCKH);
  400. gpio_set_value(data->pdata->gpio_sck, 0);
  401. ndelay(SHT15_TSCKL);
  402. }
  403. static void sht15_bh_read_data(struct work_struct *work_s)
  404. {
  405. int i;
  406. uint16_t val = 0;
  407. struct sht15_data *data
  408. = container_of(work_s, struct sht15_data,
  409. read_work);
  410. /* Firstly, verify the line is low */
  411. if (gpio_get_value(data->pdata->gpio_data)) {
  412. /* If not, then start the interrupt again - care
  413. here as could have gone low in meantime so verify
  414. it hasn't!
  415. */
  416. atomic_set(&data->interrupt_handled, 0);
  417. enable_irq(gpio_to_irq(data->pdata->gpio_data));
  418. /* If still not occured or another handler has been scheduled */
  419. if (gpio_get_value(data->pdata->gpio_data)
  420. || atomic_read(&data->interrupt_handled))
  421. return;
  422. }
  423. /* Read the data back from the device */
  424. for (i = 0; i < 16; ++i) {
  425. val <<= 1;
  426. gpio_set_value(data->pdata->gpio_sck, 1);
  427. ndelay(SHT15_TSCKH);
  428. val |= !!gpio_get_value(data->pdata->gpio_data);
  429. gpio_set_value(data->pdata->gpio_sck, 0);
  430. ndelay(SHT15_TSCKL);
  431. if (i == 7)
  432. sht15_ack(data);
  433. }
  434. /* Tell the device we are done */
  435. sht15_end_transmission(data);
  436. switch (data->flag) {
  437. case SHT15_READING_TEMP:
  438. data->val_temp = val;
  439. break;
  440. case SHT15_READING_HUMID:
  441. data->val_humid = val;
  442. break;
  443. }
  444. data->flag = SHT15_READING_NOTHING;
  445. wake_up(&data->wait_queue);
  446. }
  447. static void sht15_update_voltage(struct work_struct *work_s)
  448. {
  449. struct sht15_data *data
  450. = container_of(work_s, struct sht15_data,
  451. update_supply_work);
  452. data->supply_uV = regulator_get_voltage(data->reg);
  453. }
  454. /**
  455. * sht15_invalidate_voltage() - mark supply voltage invalid when notified by reg
  456. * @nb: associated notification structure
  457. * @event: voltage regulator state change event code
  458. * @ignored: function parameter - ignored here
  459. *
  460. * Note that as the notification code holds the regulator lock, we have
  461. * to schedule an update of the supply voltage rather than getting it directly.
  462. **/
  463. static int sht15_invalidate_voltage(struct notifier_block *nb,
  464. unsigned long event,
  465. void *ignored)
  466. {
  467. struct sht15_data *data = container_of(nb, struct sht15_data, nb);
  468. if (event == REGULATOR_EVENT_VOLTAGE_CHANGE)
  469. data->supply_uV_valid = false;
  470. schedule_work(&data->update_supply_work);
  471. return NOTIFY_OK;
  472. }
  473. static int __devinit sht15_probe(struct platform_device *pdev)
  474. {
  475. int ret = 0;
  476. struct sht15_data *data = kzalloc(sizeof(*data), GFP_KERNEL);
  477. if (!data) {
  478. ret = -ENOMEM;
  479. dev_err(&pdev->dev, "kzalloc failed");
  480. goto error_ret;
  481. }
  482. INIT_WORK(&data->read_work, sht15_bh_read_data);
  483. INIT_WORK(&data->update_supply_work, sht15_update_voltage);
  484. platform_set_drvdata(pdev, data);
  485. mutex_init(&data->read_lock);
  486. data->dev = &pdev->dev;
  487. init_waitqueue_head(&data->wait_queue);
  488. if (pdev->dev.platform_data == NULL) {
  489. dev_err(&pdev->dev, "no platform data supplied");
  490. goto err_free_data;
  491. }
  492. data->pdata = pdev->dev.platform_data;
  493. data->supply_uV = data->pdata->supply_mv*1000;
  494. /* If a regulator is available, query what the supply voltage actually is!*/
  495. data->reg = regulator_get(data->dev, "vcc");
  496. if (!IS_ERR(data->reg)) {
  497. data->supply_uV = regulator_get_voltage(data->reg);
  498. regulator_enable(data->reg);
  499. /* setup a notifier block to update this if another device
  500. * causes the voltage to change */
  501. data->nb.notifier_call = &sht15_invalidate_voltage;
  502. ret = regulator_register_notifier(data->reg, &data->nb);
  503. }
  504. /* Try requesting the GPIOs */
  505. ret = gpio_request(data->pdata->gpio_sck, "SHT15 sck");
  506. if (ret) {
  507. dev_err(&pdev->dev, "gpio request failed");
  508. goto err_free_data;
  509. }
  510. gpio_direction_output(data->pdata->gpio_sck, 0);
  511. ret = gpio_request(data->pdata->gpio_data, "SHT15 data");
  512. if (ret) {
  513. dev_err(&pdev->dev, "gpio request failed");
  514. goto err_release_gpio_sck;
  515. }
  516. ret = sysfs_create_group(&pdev->dev.kobj, &sht15_attr_group);
  517. if (ret) {
  518. dev_err(&pdev->dev, "sysfs create failed");
  519. goto err_free_data;
  520. }
  521. ret = request_irq(gpio_to_irq(data->pdata->gpio_data),
  522. sht15_interrupt_fired,
  523. IRQF_TRIGGER_FALLING,
  524. "sht15 data",
  525. data);
  526. if (ret) {
  527. dev_err(&pdev->dev, "failed to get irq for data line");
  528. goto err_release_gpio_data;
  529. }
  530. disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
  531. sht15_connection_reset(data);
  532. sht15_send_cmd(data, 0x1E);
  533. data->hwmon_dev = hwmon_device_register(data->dev);
  534. if (IS_ERR(data->hwmon_dev)) {
  535. ret = PTR_ERR(data->hwmon_dev);
  536. goto err_release_gpio_data;
  537. }
  538. return 0;
  539. err_release_gpio_data:
  540. gpio_free(data->pdata->gpio_data);
  541. err_release_gpio_sck:
  542. gpio_free(data->pdata->gpio_sck);
  543. err_free_data:
  544. kfree(data);
  545. error_ret:
  546. return ret;
  547. }
  548. static int __devexit sht15_remove(struct platform_device *pdev)
  549. {
  550. struct sht15_data *data = platform_get_drvdata(pdev);
  551. /* Make sure any reads from the device are done and
  552. * prevent new ones beginnning */
  553. mutex_lock(&data->read_lock);
  554. hwmon_device_unregister(data->hwmon_dev);
  555. sysfs_remove_group(&pdev->dev.kobj, &sht15_attr_group);
  556. if (!IS_ERR(data->reg)) {
  557. regulator_unregister_notifier(data->reg, &data->nb);
  558. regulator_disable(data->reg);
  559. regulator_put(data->reg);
  560. }
  561. free_irq(gpio_to_irq(data->pdata->gpio_data), data);
  562. gpio_free(data->pdata->gpio_data);
  563. gpio_free(data->pdata->gpio_sck);
  564. mutex_unlock(&data->read_lock);
  565. kfree(data);
  566. return 0;
  567. }
  568. static struct platform_driver sht_drivers[] = {
  569. {
  570. .driver = {
  571. .name = "sht10",
  572. .owner = THIS_MODULE,
  573. },
  574. .probe = sht15_probe,
  575. .remove = sht15_remove,
  576. }, {
  577. .driver = {
  578. .name = "sht11",
  579. .owner = THIS_MODULE,
  580. },
  581. .probe = sht15_probe,
  582. .remove = sht15_remove,
  583. }, {
  584. .driver = {
  585. .name = "sht15",
  586. .owner = THIS_MODULE,
  587. },
  588. .probe = sht15_probe,
  589. .remove = sht15_remove,
  590. }, {
  591. .driver = {
  592. .name = "sht71",
  593. .owner = THIS_MODULE,
  594. },
  595. .probe = sht15_probe,
  596. .remove = sht15_remove,
  597. }, {
  598. .driver = {
  599. .name = "sht75",
  600. .owner = THIS_MODULE,
  601. },
  602. .probe = sht15_probe,
  603. .remove = sht15_remove,
  604. },
  605. };
  606. static int __init sht15_init(void)
  607. {
  608. int ret;
  609. int i;
  610. for (i = 0; i < ARRAY_SIZE(sht_drivers); i++) {
  611. ret = platform_driver_register(&sht_drivers[i]);
  612. if (ret)
  613. goto error_unreg;
  614. }
  615. return 0;
  616. error_unreg:
  617. while (--i >= 0)
  618. platform_driver_unregister(&sht_drivers[i]);
  619. return ret;
  620. }
  621. module_init(sht15_init);
  622. static void __exit sht15_exit(void)
  623. {
  624. int i;
  625. for (i = ARRAY_SIZE(sht_drivers) - 1; i >= 0; i--)
  626. platform_driver_unregister(&sht_drivers[i]);
  627. }
  628. module_exit(sht15_exit);
  629. MODULE_LICENSE("GPL");