sht15.c 19.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
/*
 * sht15.c - support for the SHT15 Temperature and Humidity Sensor
 *
 * Copyright (c) 2009 Jonathan Cameron
 *
 * Copyright (c) 2007 Wouter Horre
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
12
 * For further information, see the Documentation/hwmon/sht15 file.
13 14 15 16 17 18 19 20 21 22 23
 */

#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_device.h>
24
#include <linux/sched.h>
25 26 27 28 29
#include <linux/delay.h>
#include <linux/jiffies.h>
#include <linux/err.h>
#include <linux/sht15.h>
#include <linux/regulator/consumer.h>
30
#include <linux/slab.h>
31 32
#include <asm/atomic.h>

33 34 35
/* Commands */
#define SHT15_MEASURE_TEMP		0x03
#define SHT15_MEASURE_RH		0x05
36

37 38 39 40
/* Min timings */
#define SHT15_TSCKL			100	/* (nsecs) clock low */
#define SHT15_TSCKH			100	/* (nsecs) clock high */
#define SHT15_TSU			150	/* (nsecs) data setup time */
41

42 43 44 45 46 47
/* Actions the driver may be doing */
enum sht15_state {
	SHT15_READING_NOTHING,
	SHT15_READING_TEMP,
	SHT15_READING_HUMID
};
48 49

/**
L
Lucas De Marchi 已提交
50
 * struct sht15_temppair - elements of voltage dependent temp calc
51 52 53 54 55 56 57 58
 * @vdd:	supply voltage in microvolts
 * @d1:		see data sheet
 */
struct sht15_temppair {
	int vdd; /* microvolts */
	int d1;
};

59
/* Table 9 from datasheet - relates temperature calculation to supply voltage */
60 61 62 63 64 65 66 67 68 69
static const struct sht15_temppair temppoints[] = {
	{ 2500000, -39400 },
	{ 3000000, -39600 },
	{ 3500000, -39700 },
	{ 4000000, -39800 },
	{ 5000000, -40100 },
};

/**
 * struct sht15_data - device instance specific data
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
 * @pdata:		platform data (gpio's etc).
 * @read_work:		bh of interrupt handler.
 * @wait_queue:		wait queue for getting values from device.
 * @val_temp:		last temperature value read from device.
 * @val_humid:		last humidity value read from device.
 * @state:		state identifying the action the driver is doing.
 * @measurements_valid:	are the current stored measures valid (start condition).
 * @last_measurement:	time of last measure.
 * @read_lock:		mutex to ensure only one read in progress at a time.
 * @dev:		associate device structure.
 * @hwmon_dev:		device associated with hwmon subsystem.
 * @reg:		associated regulator (if specified).
 * @nb:			notifier block to handle notifications of voltage
 *                      changes.
 * @supply_uV:		local copy of supply voltage used to allow use of
 *                      regulator consumer if available.
 * @supply_uV_valid:	indicates that an updated value has not yet been
 *			obtained from the regulator and so any calculations
 *			based upon it will be invalid.
 * @update_supply_work:	work struct that is used to update the supply_uV.
 * @interrupt_handled:	flag used to indicate a handler has been scheduled.
91 92 93 94 95 96 97
 */
struct sht15_data {
	struct sht15_platform_data	*pdata;
	struct work_struct		read_work;
	wait_queue_head_t		wait_queue;
	uint16_t			val_temp;
	uint16_t			val_humid;
98 99 100
	enum sht15_state		state;
	bool				measurements_valid;
	unsigned long			last_measurement;
101 102 103 104 105 106
	struct mutex			read_lock;
	struct device			*dev;
	struct device			*hwmon_dev;
	struct regulator		*reg;
	struct notifier_block		nb;
	int				supply_uV;
107
	bool				supply_uV_valid;
108 109 110 111 112 113 114 115 116 117 118 119 120
	struct work_struct		update_supply_work;
	atomic_t			interrupt_handled;
};

/**
 * sht15_connection_reset() - reset the comms interface
 * @data:	sht15 specific data
 *
 * This implements section 3.4 of the data sheet
 */
static void sht15_connection_reset(struct sht15_data *data)
{
	int i;
121

122 123 124 125 126 127 128 129 130 131 132
	gpio_direction_output(data->pdata->gpio_data, 1);
	ndelay(SHT15_TSCKL);
	gpio_set_value(data->pdata->gpio_sck, 0);
	ndelay(SHT15_TSCKL);
	for (i = 0; i < 9; ++i) {
		gpio_set_value(data->pdata->gpio_sck, 1);
		ndelay(SHT15_TSCKH);
		gpio_set_value(data->pdata->gpio_sck, 0);
		ndelay(SHT15_TSCKL);
	}
}
133

134 135 136 137
/**
 * sht15_send_bit() - send an individual bit to the device
 * @data:	device state data
 * @val:	value of bit to be sent
138
 */
139 140 141 142 143 144 145 146 147 148 149 150 151
static inline void sht15_send_bit(struct sht15_data *data, int val)
{
	gpio_set_value(data->pdata->gpio_data, val);
	ndelay(SHT15_TSU);
	gpio_set_value(data->pdata->gpio_sck, 1);
	ndelay(SHT15_TSCKH);
	gpio_set_value(data->pdata->gpio_sck, 0);
	ndelay(SHT15_TSCKL); /* clock low time */
}

/**
 * sht15_transmission_start() - specific sequence for new transmission
 * @data:	device state data
152
 *
153 154 155
 * Timings for this are not documented on the data sheet, so very
 * conservative ones used in implementation. This implements
 * figure 12 on the data sheet.
156
 */
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
static void sht15_transmission_start(struct sht15_data *data)
{
	/* ensure data is high and output */
	gpio_direction_output(data->pdata->gpio_data, 1);
	ndelay(SHT15_TSU);
	gpio_set_value(data->pdata->gpio_sck, 0);
	ndelay(SHT15_TSCKL);
	gpio_set_value(data->pdata->gpio_sck, 1);
	ndelay(SHT15_TSCKH);
	gpio_set_value(data->pdata->gpio_data, 0);
	ndelay(SHT15_TSU);
	gpio_set_value(data->pdata->gpio_sck, 0);
	ndelay(SHT15_TSCKL);
	gpio_set_value(data->pdata->gpio_sck, 1);
	ndelay(SHT15_TSCKH);
	gpio_set_value(data->pdata->gpio_data, 1);
	ndelay(SHT15_TSU);
	gpio_set_value(data->pdata->gpio_sck, 0);
	ndelay(SHT15_TSCKL);
}
177

178 179 180 181
/**
 * sht15_send_byte() - send a single byte to the device
 * @data:	device state
 * @byte:	value to be sent
182
 */
183 184 185
static void sht15_send_byte(struct sht15_data *data, u8 byte)
{
	int i;
186

187 188 189 190 191
	for (i = 0; i < 8; i++) {
		sht15_send_bit(data, !!(byte & 0x80));
		byte <<= 1;
	}
}
192

193 194 195
/**
 * sht15_wait_for_response() - checks for ack from device
 * @data:	device state
196
 */
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
static int sht15_wait_for_response(struct sht15_data *data)
{
	gpio_direction_input(data->pdata->gpio_data);
	gpio_set_value(data->pdata->gpio_sck, 1);
	ndelay(SHT15_TSCKH);
	if (gpio_get_value(data->pdata->gpio_data)) {
		gpio_set_value(data->pdata->gpio_sck, 0);
		dev_err(data->dev, "Command not acknowledged\n");
		sht15_connection_reset(data);
		return -EIO;
	}
	gpio_set_value(data->pdata->gpio_sck, 0);
	ndelay(SHT15_TSCKL);
	return 0;
}

/**
 * sht15_send_cmd() - Sends a command to the device.
 * @data:	device state
 * @cmd:	command byte to be sent
 *
 * On entry, sck is output low, data is output pull high
 * and the interrupt disabled.
220
 */
221 222 223
static int sht15_send_cmd(struct sht15_data *data, u8 cmd)
{
	int ret = 0;
224

225 226 227 228 229
	sht15_transmission_start(data);
	sht15_send_byte(data, cmd);
	ret = sht15_wait_for_response(data);
	return ret;
}
230

231
/**
232
 * sht15_measurement() - get a new value from device
233 234 235 236
 * @data:		device instance specific data
 * @command:		command sent to request value
 * @timeout_msecs:	timeout after which comms are assumed
 *			to have failed are reset.
237 238 239 240
 */
static int sht15_measurement(struct sht15_data *data,
			     int command,
			     int timeout_msecs)
241 242
{
	int ret;
243

244 245 246 247 248 249 250 251 252 253
	ret = sht15_send_cmd(data, command);
	if (ret)
		return ret;

	gpio_direction_input(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) == 0) {
		disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
L
Lucas De Marchi 已提交
254
		/* Only relevant if the interrupt hasn't occurred. */
255 256 257 258
		if (!atomic_read(&data->interrupt_handled))
			schedule_work(&data->read_work);
	}
	ret = wait_event_timeout(data->wait_queue,
259
				 (data->state == SHT15_READING_NOTHING),
260 261
				 msecs_to_jiffies(timeout_msecs));
	if (ret == 0) {/* timeout occurred */
262
		disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
263 264 265 266 267 268 269
		sht15_connection_reset(data);
		return -ETIME;
	}
	return 0;
}

/**
270
 * sht15_update_measurements() - get updated measures from device if too old
271
 * @data:	device state
272 273
 */
static int sht15_update_measurements(struct sht15_data *data)
274 275 276 277 278
{
	int ret = 0;
	int timeout = HZ;

	mutex_lock(&data->read_lock);
279 280 281 282
	if (time_after(jiffies, data->last_measurement + timeout)
	    || !data->measurements_valid) {
		data->state = SHT15_READING_HUMID;
		ret = sht15_measurement(data, SHT15_MEASURE_RH, 160);
283 284
		if (ret)
			goto error_ret;
285 286
		data->state = SHT15_READING_TEMP;
		ret = sht15_measurement(data, SHT15_MEASURE_TEMP, 400);
287 288
		if (ret)
			goto error_ret;
289 290
		data->measurements_valid = true;
		data->last_measurement = jiffies;
291 292 293 294 295 296 297 298 299 300 301 302
	}
error_ret:
	mutex_unlock(&data->read_lock);

	return ret;
}

/**
 * sht15_calc_temp() - convert the raw reading to a temperature
 * @data:	device state
 *
 * As per section 4.3 of the data sheet.
303
 */
304 305
static inline int sht15_calc_temp(struct sht15_data *data)
{
306
	int d1 = temppoints[0].d1;
307 308
	int i;

309
	for (i = ARRAY_SIZE(temppoints) - 1; i > 0; i--)
310 311
		/* Find pointer to interpolate */
		if (data->supply_uV > temppoints[i - 1].vdd) {
312
			d1 = (data->supply_uV - temppoints[i - 1].vdd)
313 314 315 316 317 318
				* (temppoints[i].d1 - temppoints[i - 1].d1)
				/ (temppoints[i].vdd - temppoints[i - 1].vdd)
				+ temppoints[i - 1].d1;
			break;
		}

319
	return data->val_temp * 10 + d1;
320 321 322 323 324 325 326 327
}

/**
 * sht15_calc_humid() - using last temperature convert raw to humid
 * @data:	device state
 *
 * This is the temperature compensated version as per section 4.2 of
 * the data sheet.
328 329 330 331
 *
 * The sensor is assumed to be V3, which is compatible with V4.
 * Humidity conversion coefficients are shown in table 7 of the datasheet.
 */
332 333
static inline int sht15_calc_humid(struct sht15_data *data)
{
334
	int rh_linear; /* milli percent */
335 336 337 338
	int temp = sht15_calc_temp(data);

	const int c1 = -4;
	const int c2 = 40500; /* x 10 ^ -6 */
339
	const int c3 = -28;   /* x 10 ^ -7 */
340

341 342
	rh_linear = c1 * 1000
		+ c2 * data->val_humid / 1000
343
		+ (data->val_humid * data->val_humid * c3) / 10000;
344
	return (temp - 25000) * (10000 + 80 * data->val_humid)
345
		/ 1000000 + rh_linear;
346 347
}

348 349 350 351 352 353 354 355 356
/**
 * sht15_show_temp() - show temperature measurement value in sysfs
 * @dev:	device.
 * @attr:	device attribute.
 * @buf:	sysfs buffer where measurement values are written to.
 *
 * Will be called on read access to temp1_input sysfs attribute.
 * Returns number of bytes written into buffer, negative errno on error.
 */
357 358 359 360 361 362 363 364
static ssize_t sht15_show_temp(struct device *dev,
			       struct device_attribute *attr,
			       char *buf)
{
	int ret;
	struct sht15_data *data = dev_get_drvdata(dev);

	/* Technically no need to read humidity as well */
365
	ret = sht15_update_measurements(data);
366 367 368 369 370

	return ret ? ret : sprintf(buf, "%d\n",
				   sht15_calc_temp(data));
}

371 372 373 374 375 376 377 378 379
/**
 * sht15_show_humidity() - show humidity measurement value in sysfs
 * @dev:	device.
 * @attr:	device attribute.
 * @buf:	sysfs buffer where measurement values are written to.
 *
 * Will be called on read access to humidity1_input sysfs attribute.
 * Returns number of bytes written into buffer, negative errno on error.
 */
380 381 382 383 384 385 386
static ssize_t sht15_show_humidity(struct device *dev,
				   struct device_attribute *attr,
				   char *buf)
{
	int ret;
	struct sht15_data *data = dev_get_drvdata(dev);

387
	ret = sht15_update_measurements(data);
388 389 390

	return ret ? ret : sprintf(buf, "%d\n", sht15_calc_humid(data));

391 392
}

393 394 395 396 397 398 399 400
static ssize_t show_name(struct device *dev,
			 struct device_attribute *attr,
			 char *buf)
{
	struct platform_device *pdev = to_platform_device(dev);
	return sprintf(buf, "%s\n", pdev->name);
}

401 402 403 404
static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO,
			  sht15_show_temp, NULL, 0);
static SENSOR_DEVICE_ATTR(humidity1_input, S_IRUGO,
			  sht15_show_humidity, NULL, 0);
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419
static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
static struct attribute *sht15_attrs[] = {
	&sensor_dev_attr_temp1_input.dev_attr.attr,
	&sensor_dev_attr_humidity1_input.dev_attr.attr,
	&dev_attr_name.attr,
	NULL,
};

static const struct attribute_group sht15_attr_group = {
	.attrs = sht15_attrs,
};

static irqreturn_t sht15_interrupt_fired(int irq, void *d)
{
	struct sht15_data *data = d;
420

421 422 423 424
	/* First disable the interrupt */
	disable_irq_nosync(irq);
	atomic_inc(&data->interrupt_handled);
	/* Then schedule a reading work struct */
425
	if (data->state != SHT15_READING_NOTHING)
426 427 428 429
		schedule_work(&data->read_work);
	return IRQ_HANDLED;
}

430 431 432 433
/**
 * sht15_ack() - Send an ack to the device
 *
 * Each byte of data is acknowledged by pulling the data line
434 435 436 437 438 439 440 441 442 443 444 445 446 447
 * low for one clock pulse.
 */
static void sht15_ack(struct sht15_data *data)
{
	gpio_direction_output(data->pdata->gpio_data, 0);
	ndelay(SHT15_TSU);
	gpio_set_value(data->pdata->gpio_sck, 1);
	ndelay(SHT15_TSU);
	gpio_set_value(data->pdata->gpio_sck, 0);
	ndelay(SHT15_TSU);
	gpio_set_value(data->pdata->gpio_data, 1);

	gpio_direction_input(data->pdata->gpio_data);
}
448

449 450 451 452 453
/**
 * sht15_end_transmission() - notify device of end of transmission
 * @data:	device state
 *
 * This is basically a NAK. (single clock pulse, data high)
454
 */
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
static void sht15_end_transmission(struct sht15_data *data)
{
	gpio_direction_output(data->pdata->gpio_data, 1);
	ndelay(SHT15_TSU);
	gpio_set_value(data->pdata->gpio_sck, 1);
	ndelay(SHT15_TSCKH);
	gpio_set_value(data->pdata->gpio_sck, 0);
	ndelay(SHT15_TSCKL);
}

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);
472

473 474
	/* Firstly, verify the line is low */
	if (gpio_get_value(data->pdata->gpio_data)) {
475 476 477 478
		/*
		 * If not, then start the interrupt again - care here as could
		 * have gone low in meantime so verify it hasn't!
		 */
479 480
		atomic_set(&data->interrupt_handled, 0);
		enable_irq(gpio_to_irq(data->pdata->gpio_data));
L
Lucas De Marchi 已提交
481
		/* If still not occurred or another handler has been scheduled */
482 483 484 485
		if (gpio_get_value(data->pdata->gpio_data)
		    || atomic_read(&data->interrupt_handled))
			return;
	}
486

487 488 489 490 491 492 493 494 495 496 497
	/* 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);
	}
498

499 500 501
	/* Tell the device we are done */
	sht15_end_transmission(data);

502
	switch (data->state) {
503 504 505 506 507 508
	case SHT15_READING_TEMP:
		data->val_temp = val;
		break;
	case SHT15_READING_HUMID:
		data->val_humid = val;
		break;
509 510
	default:
		break;
511 512
	}

513
	data->state = SHT15_READING_NOTHING;
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532
	wake_up(&data->wait_queue);
}

static void sht15_update_voltage(struct work_struct *work_s)
{
	struct sht15_data *data
		= container_of(work_s, struct sht15_data,
			       update_supply_work);
	data->supply_uV = regulator_get_voltage(data->reg);
}

/**
 * sht15_invalidate_voltage() - mark supply voltage invalid when notified by reg
 * @nb:		associated notification structure
 * @event:	voltage regulator state change event code
 * @ignored:	function parameter - ignored here
 *
 * Note that as the notification code holds the regulator lock, we have
 * to schedule an update of the supply voltage rather than getting it directly.
533
 */
534
static int sht15_invalidate_voltage(struct notifier_block *nb,
535 536
				    unsigned long event,
				    void *ignored)
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553
{
	struct sht15_data *data = container_of(nb, struct sht15_data, nb);

	if (event == REGULATOR_EVENT_VOLTAGE_CHANGE)
		data->supply_uV_valid = false;
	schedule_work(&data->update_supply_work);

	return NOTIFY_OK;
}

static int __devinit sht15_probe(struct platform_device *pdev)
{
	int ret = 0;
	struct sht15_data *data = kzalloc(sizeof(*data), GFP_KERNEL);

	if (!data) {
		ret = -ENOMEM;
554
		dev_err(&pdev->dev, "kzalloc failed\n");
555 556 557 558 559 560 561 562 563 564 565
		goto error_ret;
	}

	INIT_WORK(&data->read_work, sht15_bh_read_data);
	INIT_WORK(&data->update_supply_work, sht15_update_voltage);
	platform_set_drvdata(pdev, data);
	mutex_init(&data->read_lock);
	data->dev = &pdev->dev;
	init_waitqueue_head(&data->wait_queue);

	if (pdev->dev.platform_data == NULL) {
566
		dev_err(&pdev->dev, "no platform data supplied\n");
567 568 569
		goto err_free_data;
	}
	data->pdata = pdev->dev.platform_data;
570
	data->supply_uV = data->pdata->supply_mv * 1000;
571

572 573 574 575
	/*
	 * If a regulator is available,
	 * query what the supply voltage actually is!
	 */
576 577
	data->reg = regulator_get(data->dev, "vcc");
	if (!IS_ERR(data->reg)) {
578 579 580 581 582 583
		int voltage;

		voltage = regulator_get_voltage(data->reg);
		if (voltage)
			data->supply_uV = voltage;

584
		regulator_enable(data->reg);
585 586 587 588
		/*
		 * Setup a notifier block to update this if another device
		 * causes the voltage to change
		 */
589 590 591
		data->nb.notifier_call = &sht15_invalidate_voltage;
		ret = regulator_register_notifier(data->reg, &data->nb);
	}
592 593

	/* Try requesting the GPIOs */
594 595
	ret = gpio_request(data->pdata->gpio_sck, "SHT15 sck");
	if (ret) {
596
		dev_err(&pdev->dev, "gpio request failed\n");
597 598 599
		goto err_free_data;
	}
	gpio_direction_output(data->pdata->gpio_sck, 0);
600

601 602
	ret = gpio_request(data->pdata->gpio_data, "SHT15 data");
	if (ret) {
603
		dev_err(&pdev->dev, "gpio request failed\n");
604 605 606 607 608
		goto err_release_gpio_sck;
	}
	ret = sysfs_create_group(&pdev->dev.kobj, &sht15_attr_group);
	if (ret) {
		dev_err(&pdev->dev, "sysfs create failed");
609
		goto err_release_gpio_data;
610 611 612 613 614 615 616 617
	}

	ret = request_irq(gpio_to_irq(data->pdata->gpio_data),
			  sht15_interrupt_fired,
			  IRQF_TRIGGER_FALLING,
			  "sht15 data",
			  data);
	if (ret) {
618
		dev_err(&pdev->dev, "failed to get irq for data line\n");
619 620 621 622 623 624 625 626 627
		goto err_release_gpio_data;
	}
	disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
	sht15_connection_reset(data);
	sht15_send_cmd(data, 0x1E);

	data->hwmon_dev = hwmon_device_register(data->dev);
	if (IS_ERR(data->hwmon_dev)) {
		ret = PTR_ERR(data->hwmon_dev);
628
		goto err_release_irq;
629
	}
630

631 632
	return 0;

633 634
err_release_irq:
	free_irq(gpio_to_irq(data->pdata->gpio_data), data);
635 636 637 638 639 640 641 642 643 644 645 646 647 648
err_release_gpio_data:
	gpio_free(data->pdata->gpio_data);
err_release_gpio_sck:
	gpio_free(data->pdata->gpio_sck);
err_free_data:
	kfree(data);
error_ret:
	return ret;
}

static int __devexit sht15_remove(struct platform_device *pdev)
{
	struct sht15_data *data = platform_get_drvdata(pdev);

649 650 651 652
	/*
	 * Make sure any reads from the device are done and
	 * prevent new ones beginning
	 */
653 654 655 656 657 658 659 660 661 662 663 664 665 666
	mutex_lock(&data->read_lock);
	hwmon_device_unregister(data->hwmon_dev);
	sysfs_remove_group(&pdev->dev.kobj, &sht15_attr_group);
	if (!IS_ERR(data->reg)) {
		regulator_unregister_notifier(data->reg, &data->nb);
		regulator_disable(data->reg);
		regulator_put(data->reg);
	}

	free_irq(gpio_to_irq(data->pdata->gpio_data), data);
	gpio_free(data->pdata->gpio_data);
	gpio_free(data->pdata->gpio_sck);
	mutex_unlock(&data->read_lock);
	kfree(data);
667

668 669 670
	return 0;
}

671 672 673 674 675 676
/*
 * sht_drivers simultaneously refers to __devinit and __devexit function
 * which causes spurious section mismatch warning. So use __refdata to
 * get rid from this.
 */
static struct platform_driver __refdata sht_drivers[] = {
677 678 679 680 681 682
	{
		.driver = {
			.name = "sht10",
			.owner = THIS_MODULE,
		},
		.probe = sht15_probe,
683
		.remove = __devexit_p(sht15_remove),
684 685 686 687 688 689
	}, {
		.driver = {
			.name = "sht11",
			.owner = THIS_MODULE,
		},
		.probe = sht15_probe,
690
		.remove = __devexit_p(sht15_remove),
691 692 693 694 695 696
	}, {
		.driver = {
			.name = "sht15",
			.owner = THIS_MODULE,
		},
		.probe = sht15_probe,
697
		.remove = __devexit_p(sht15_remove),
698 699 700 701 702 703
	}, {
		.driver = {
			.name = "sht71",
			.owner = THIS_MODULE,
		},
		.probe = sht15_probe,
704
		.remove = __devexit_p(sht15_remove),
705 706 707 708 709 710
	}, {
		.driver = {
			.name = "sht75",
			.owner = THIS_MODULE,
		},
		.probe = sht15_probe,
711
		.remove = __devexit_p(sht15_remove),
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744
	},
};

static int __init sht15_init(void)
{
	int ret;
	int i;

	for (i = 0; i < ARRAY_SIZE(sht_drivers); i++) {
		ret = platform_driver_register(&sht_drivers[i]);
		if (ret)
			goto error_unreg;
	}

	return 0;

error_unreg:
	while (--i >= 0)
		platform_driver_unregister(&sht_drivers[i]);

	return ret;
}
module_init(sht15_init);

static void __exit sht15_exit(void)
{
	int i;
	for (i = ARRAY_SIZE(sht_drivers) - 1; i >= 0; i--)
		platform_driver_unregister(&sht_drivers[i]);
}
module_exit(sht15_exit);

MODULE_LICENSE("GPL");