2 * Copyright (C) 2010 Motorola, Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 #include <linux/err.h>
20 #include <linux/errno.h>
21 #include <linux/delay.h>
23 #include <linux/i2c.h>
24 #include <linux/input.h>
25 #include <linux/input-polldev.h>
26 #include <linux/interrupt.h>
27 #include <linux/irq.h>
28 #include <linux/miscdevice.h>
29 #include <linux/slab.h>
30 #include <linux/regulator/consumer.h>
31 #include <linux/uaccess.h>
32 #include <linux/workqueue.h>
34 #include <linux/moto_bmp085.h>
40 #define PRESSURE_CYCLE 2
42 /* Register definitions */
43 #define BMP085_TAKE_MEAS_REG 0xf4
44 #define BMP085_READ_MEAS_REG_U 0xf6
45 #define BMP085_READ_MEAS_REG_L 0xf7
46 #define BMP085_READ_MEAS_REG_XL 0xf8
48 /* Bytes defined by the spec to take measurements
49 Temperature will take 4.5ms before EOC */
50 #define BMP085_MEAS_TEMP 0x2e
51 /* 4.5ms wait for measurement */
52 #define BMP085_MEAS_PRESS_OVERSAMP_0 0x34
53 /* 7.5ms wait for measurement */
54 #define BMP085_MEAS_PRESS_OVERSAMP_1 0x74
55 /* 13.5ms wait for measurement */
56 #define BMP085_MEAS_PRESS_OVERSAMP_2 0xb4
57 /* 25.5ms wait for measurement */
58 #define BMP085_MEAS_PRESS_OVERSAMP_3 0xf4
61 /* EEPROM registers each is a two byte value so there is
62 an upper byte and a lower byte */
63 #define BMP085_EEPROM_AC1_U 0xaa
64 #define BMP085_EEPROM_AC1_L 0xab
65 #define BMP085_EEPROM_AC2_U 0xac
66 #define BMP085_EEPROM_AC2_L 0xad
67 #define BMP085_EEPROM_AC3_U 0xae
68 #define BMP085_EEPROM_AC3_L 0xaf
69 #define BMP085_EEPROM_AC4_U 0xb0
70 #define BMP085_EEPROM_AC4_L 0xb1
71 #define BMP085_EEPROM_AC5_U 0xb2
72 #define BMP085_EEPROM_AC5_L 0xb3
73 #define BMP085_EEPROM_AC6_U 0xb4
74 #define BMP085_EEPROM_AC6_L 0xb5
75 #define BMP085_EEPROM_B1_U 0xb6
76 #define BMP085_EEPROM_B1_L 0xb7
77 #define BMP085_EEPROM_B2_U 0xb8
78 #define BMP085_EEPROM_B2_L 0xb9
79 #define BMP085_EEPROM_MB_U 0xba
80 #define BMP085_EEPROM_MB_L 0xbb
81 #define BMP085_EEPROM_MC_U 0xbc
82 #define BMP085_EEPROM_MC_L 0xbd
83 #define BMP085_EEPROM_MD_U 0xbe
84 #define BMP085_EEPROM_MD_L 0xbf
91 {"MEASURE_REG", BMP085_TAKE_MEAS_REG},
92 {"CNTRL_1", BMP085_READ_MEAS_REG_U},
93 {"CNTRL_2", BMP085_READ_MEAS_REG_L},
94 {"CNTRL_3", BMP085_READ_MEAS_REG_XL},
95 {"EE_AC1_U", BMP085_EEPROM_AC1_U},
96 {"EE_AC1_U", BMP085_EEPROM_AC1_L},
97 {"EE_AC2_U", BMP085_EEPROM_AC2_U},
98 {"EE_AC2_L", BMP085_EEPROM_AC2_L},
99 {"EE_AC3_U", BMP085_EEPROM_AC3_U},
100 {"EE_AC3_L", BMP085_EEPROM_AC3_L},
101 {"EE_AC4_U", BMP085_EEPROM_AC4_U},
102 {"EE_AC4_L", BMP085_EEPROM_AC4_L},
103 {"EE_AC5_U", BMP085_EEPROM_AC5_U},
104 {"EE_AC5_L", BMP085_EEPROM_AC5_L},
105 {"EE_AC6_U", BMP085_EEPROM_AC6_U},
106 {"EE_AC6_L", BMP085_EEPROM_AC6_L},
107 {"EE_B1_U", BMP085_EEPROM_B1_U},
108 {"EE_B1_L", BMP085_EEPROM_B1_L},
109 {"EE_B2_U", BMP085_EEPROM_B2_U},
110 {"EE_B2_L", BMP085_EEPROM_B2_L},
111 {"EE_MB_U", BMP085_EEPROM_MB_U},
112 {"EE_MB_L", BMP085_EEPROM_MB_L},
113 {"EE_MC_U", BMP085_EEPROM_MC_U},
114 {"EE_MC_L", BMP085_EEPROM_MC_L},
115 {"EE_MD_U", BMP085_EEPROM_MD_U},
116 {"EE_MD_L", BMP085_EEPROM_MD_L},
119 static uint32_t bmp085_debug = 0x00;
120 module_param_named(baro_debug, bmp085_debug, uint, 0664);
122 #define I2C_RETRY_DELAY 5
123 #define I2C_RETRIES 5
124 #define AUTO_INCREMENT 0x80
126 static struct workqueue_struct *barom_wq;
128 struct bmp085_eeprom_data {
136 struct i2c_client *client;
137 struct bmp085_platform_data *pdata;
139 struct delayed_work input_work;
140 struct work_struct wq;
141 struct workqueue_struct *working_queue;
142 struct input_dev *input_dev;
144 u8 oversampling_rate;
145 u8 measurement_cycle;
147 int uncalib_temperature;
148 int uncalib_pressure;
149 int calib_temperature;
151 long b5; /* Needed for pressure calculation */
153 struct bmp085_eeprom_data bmp085_eeprom_vals;
156 int on_before_suspend;
157 struct regulator *regulator;
158 struct regulator *io_regulator;
163 * Because misc devices can not carry a pointer from driver register to
164 * open, we keep this global. This limits the driver to a single instance.
166 struct bmp085_data *bmp085_misc_data;
168 static int bmp085_i2c_read(struct bmp085_data *barom, u8 * buf, int len)
172 struct i2c_msg msgs[] = {
174 .addr = barom->client->addr,
175 .flags = barom->client->flags & I2C_M_TEN,
180 .addr = barom->client->addr,
181 .flags = (barom->client->flags & I2C_M_TEN) | I2C_M_RD,
188 err = i2c_transfer(barom->client->adapter, msgs, 2);
190 msleep_interruptible(I2C_RETRY_DELAY);
191 } while ((err != 2) && (++tries < I2C_RETRIES));
194 pr_err("%s:read transfer error\n", __func__);
203 static int bmp085_i2c_write(struct bmp085_data *barom, u8 * buf, int len)
207 struct i2c_msg msgs[] = {
209 .addr = barom->client->addr,
210 .flags = barom->client->flags & I2C_M_TEN,
217 err = i2c_transfer(barom->client->adapter, msgs, 1);
219 msleep_interruptible(I2C_RETRY_DELAY);
220 } while ((err != 1) && (++tries < I2C_RETRIES));
223 pr_err("%s:write transfer error\n", __func__);
232 static int bmp085_update_measurement_accuracy(struct bmp085_data *barom,
237 barom->oversampling_rate = accuracy;
242 static void bmp085_schedule_work(struct bmp085_data *barom)
244 schedule_delayed_work(&barom->input_work,
245 msecs_to_jiffies(barom->pdata->poll_interval));
248 static int bmp085_enable(struct bmp085_data *barom)
252 if (!atomic_cmpxchg(&barom->enabled, 0, 1)) {
253 if (barom->regulator)
254 err = regulator_enable(barom->regulator);
255 err = regulator_enable(barom->io_regulator);
257 atomic_set(&barom->enabled, 0);
260 schedule_delayed_work(&barom->input_work,
261 msecs_to_jiffies(barom->pdata->
268 static int bmp085_disable(struct bmp085_data *barom)
270 if (atomic_cmpxchg(&barom->enabled, 1, 0)) {
271 cancel_delayed_work_sync(&barom->input_work);
272 if (barom->regulator)
273 regulator_disable(barom->regulator);
274 regulator_disable(barom->io_regulator);
276 barom->measurement_cycle = NO_CYCLE;
281 static int bmp085_misc_open(struct inode *inode, struct file *file)
284 err = nonseekable_open(inode, file);
288 file->private_data = bmp085_misc_data;
293 static long bmp085_misc_ioctl(struct file *file,
294 unsigned int cmd, unsigned long arg)
296 void __user *argp = (void __user *)arg;
300 struct bmp085_data *barom = file->private_data;
303 case BMP085_IOCTL_GET_DELAY:
304 interval = barom->pdata->poll_interval;
305 if (copy_to_user(argp, &interval, sizeof(interval)))
309 case BMP085_IOCTL_SET_DELAY:
310 if (copy_from_user(&interval, argp, sizeof(interval)))
312 if (interval < 0 || interval > 200)
315 barom->pdata->poll_interval =
316 max(interval, barom->pdata->min_interval);
319 case BMP085_IOCTL_SET_ENABLE:
320 if (copy_from_user(&interval, argp, sizeof(interval)))
326 bmp085_enable(barom);
328 bmp085_disable(barom);
332 case BMP085_IOCTL_GET_ENABLE:
333 interval = atomic_read(&barom->enabled);
334 if (copy_to_user(argp, &interval, sizeof(interval)))
339 case BMP085_IOCTL_ACCURACY:
340 if (copy_from_user(&buf, argp, 1))
342 err = bmp085_update_measurement_accuracy(barom, arg);
355 static const struct file_operations bmp085_misc_fops = {
356 .owner = THIS_MODULE,
357 .open = bmp085_misc_open,
358 .unlocked_ioctl = bmp085_misc_ioctl,
361 static struct miscdevice bmp085_misc_device = {
362 .minor = MISC_DYNAMIC_MINOR,
364 .fops = &bmp085_misc_fops,
367 #ifdef BMP085_OPEN_ENABLE
368 int bmp085_input_open(struct input_dev *input)
370 struct bmp085_data *barom = input_get_drvdata(input);
372 return bmp085_enable(barom);
375 void bmp085_input_close(struct input_dev *dev)
377 struct bmp085_data *barom = input_get_drvdata(dev);
379 bmp085_disable(barom);
383 static ssize_t bmp085_registers_show(struct device *dev,
384 struct device_attribute *attr, char *buf)
386 struct i2c_client *client = container_of(dev, struct i2c_client,
388 struct bmp085_data *barom_data = i2c_get_clientdata(client);
390 unsigned i, n, reg_count;
392 reg_count = sizeof(bmp085_regs) / sizeof(bmp085_regs[0]);
393 for (i = 0, n = 0; i < reg_count; i++) {
394 barom_reg[0] = (AUTO_INCREMENT | bmp085_regs[i].reg);
395 bmp085_i2c_read(barom_data, barom_reg, 1);
396 n += scnprintf(buf + n, PAGE_SIZE - n,
398 bmp085_regs[i].name, barom_reg[0]);
403 static ssize_t bmp085_registers_store(struct device *dev,
404 struct device_attribute *attr,
405 const char *buf, size_t count)
407 struct i2c_client *client = container_of(dev, struct i2c_client,
409 struct bmp085_data *barom_data = i2c_get_clientdata(client);
410 unsigned i, reg_count, value;
416 pr_err("%s:input too long\n", __func__);
420 if (sscanf(buf, "%s %x", name, &value) != 2) {
421 pr_err("%s:unable to parse input\n", __func__);
425 reg_count = sizeof(bmp085_regs) / sizeof(bmp085_regs[0]);
426 for (i = 0; i < reg_count; i++) {
427 if (!strcmp(name, bmp085_regs[i].name)) {
428 barom_reg[0] = (AUTO_INCREMENT | bmp085_regs[i].reg);
429 barom_reg[1] = value;
430 error = bmp085_i2c_write(barom_data, barom_reg, 2);
432 pr_err("%s:Failed to write register %s\n",
439 if (!strcmp("Go", name)) {
441 bmp085_enable(barom_data);
443 bmp085_disable(barom_data);
447 if (!strcmp("acc", name)) {
448 barom_data->oversampling_rate = value;
452 pr_err("%s:no such register %s\n", __func__, name);
456 static DEVICE_ATTR(registers, 0644, bmp085_registers_show,
457 bmp085_registers_store);
459 static int bmp085_get_temperature_data(struct bmp085_data *barom)
462 u8 buf[2] = { BMP085_READ_MEAS_REG_U, 0 };
466 err = bmp085_i2c_read(barom, buf, 2);
468 pr_err("%s:Cannot read pressure measurement\n", __func__);
471 if (bmp085_debug & 2)
472 pr_err("%s:Read Temp 0x%X 0x%X\n", __func__, buf[0], buf[1]);
474 barom->uncalib_temperature = (buf[0] << 8) + buf[1];
476 /* The math is derived from the data sheet. */
477 x1 = ((barom->uncalib_temperature - barom->bmp085_eeprom_vals.AC6) *
478 barom->bmp085_eeprom_vals.AC5) >> 15;
479 x2 = (barom->bmp085_eeprom_vals.MC << 11) /
480 (x1 + barom->bmp085_eeprom_vals.MD);
482 barom->calib_temperature = (barom->b5 + 8) >> 4;
483 if (bmp085_debug & 1)
484 pr_err("%s:Calibrated Temp %d\n",
485 __func__, barom->calib_temperature);
490 static int bmp085_get_barometer_data(struct bmp085_data *barom)
493 long x1, x2, x3, b3, b6;
494 unsigned long b4, b7;
496 u8 buf[3] = { BMP085_READ_MEAS_REG_U, 0, 0 };
498 err = bmp085_i2c_read(barom, buf, 3);
500 pr_err("%s:Cannot read pressure measurement\n", __func__);
504 /* Raw data to uncalibrate pressure. Conversion compliments of the
506 barom->uncalib_pressure = ((buf[0] << 16) | (buf[1] << 8) | buf[2]) >>
507 (8 - barom->oversampling_rate);
508 if (bmp085_debug & 2)
509 pr_err("%s:Uncalibrated pressure %d\n", __func__,
510 barom->uncalib_pressure);
512 /* Complicated math compliments of the data sheet */
513 b6 = (barom->b5 - 4000);
514 x1 = (barom->bmp085_eeprom_vals.B2 * ((b6 * b6) >> 12)) >> 11;
515 x2 = (barom->bmp085_eeprom_vals.AC2 * b6) >> 11;
517 b3 = (((((long)barom->bmp085_eeprom_vals.AC1) * 4 +
518 x3) << barom->oversampling_rate) + 2) >> 2;
519 x1 = (barom->bmp085_eeprom_vals.AC3 * b6) >> 13;
520 x2 = (barom->bmp085_eeprom_vals.B1 * (b6 * b6 >> 12)) >> 16;
521 x3 = ((x1 + x2) + 2) >> 2;
522 b4 = (barom->bmp085_eeprom_vals.AC4 *
523 (unsigned long)(x3 + 32768)) >> 15;
524 b7 = ((unsigned long)barom->uncalib_pressure -
525 b3) * (50000 >> barom->oversampling_rate);
530 x1 = (p >> 8) * (p >> 8);
531 x1 = (x1 * 3038) >> 16;
532 x2 = (-7357 * p) >> 16;
533 barom->calib_pressure = p + ((x1 + x2 + 3791) >> 4);
534 if (bmp085_debug & 1)
535 pr_info("%s:Calibrated Pressure is %li\n",
536 __func__, barom->calib_pressure);
541 static void bmp085_input_work_func(struct work_struct *work)
543 struct bmp085_data *barom = container_of((struct delayed_work *)work,
549 buf[0] = (AUTO_INCREMENT | BMP085_TAKE_MEAS_REG);
550 buf[1] = BMP085_MEAS_TEMP;
552 if ((barom->measurement_cycle == TEMP_CYCLE) ||
553 (barom->measurement_cycle == PRESSURE_CYCLE)) {
554 /* One of the measurements took to long so
555 reset the state machine */
556 barom->measurement_cycle = NO_CYCLE;
558 barom->measurement_cycle = TEMP_CYCLE;
559 err = bmp085_i2c_write(barom, buf, 2);
561 pr_err("%s:Cannot start temp measurement\n", __func__);
562 barom->measurement_cycle = NO_CYCLE;
566 bmp085_schedule_work(barom);
570 void bmp085_work_queue(struct work_struct *work)
573 struct bmp085_data *barom_data =
574 container_of(work, struct bmp085_data, wq);
577 if (barom_data->measurement_cycle == NO_CYCLE) {
578 pr_err("%s:No cycle defined\n", __func__);
579 } else if (barom_data->measurement_cycle == TEMP_CYCLE) {
581 if (bmp085_debug & 1)
582 pr_err("%s:Temp cycle\n", __func__);
584 err = bmp085_get_temperature_data(barom_data);
586 pr_err("%s:Cannot read temp measurement\n", __func__);
589 /* Setup for a pressure measurement */
590 buf[0] = (AUTO_INCREMENT | BMP085_TAKE_MEAS_REG);
591 buf[1] = BMP085_MEAS_PRESS_OVERSAMP_0 |
592 (barom_data->oversampling_rate << 6);
594 barom_data->measurement_cycle = PRESSURE_CYCLE;
596 err = bmp085_i2c_write(barom_data, buf, 2);
598 pr_err("%s:Cannot start temp measurement\n", __func__);
599 barom_data->measurement_cycle = NO_CYCLE;
603 /* Get and report the pressure */
604 if (bmp085_debug & 1)
605 pr_err("%s:Pressure cycle\n", __func__);
607 err = bmp085_get_barometer_data(barom_data);
609 pr_err("%s:Pressure measurement failed\n", __func__);
613 input_report_abs(barom_data->input_dev, ABS_PRESSURE,
614 barom_data->calib_pressure);
615 input_sync(barom_data->input_dev);
617 barom_data->measurement_cycle = NO_CYCLE;
619 enable_irq(barom_data->client->irq);
623 irqreturn_t bmp085_irq_handler(int irq, void *dev)
625 struct bmp085_data *barom_data = dev;
626 disable_irq_nosync(barom_data->client->irq);
627 queue_work(barom_wq, &barom_data->wq);
632 static int bmp085_validate_pdata(struct bmp085_data *barom)
634 barom->pdata->poll_interval = max(barom->pdata->poll_interval,
635 barom->pdata->min_interval);
637 /* Enforce minimum polling interval */
638 if (barom->pdata->poll_interval < barom->pdata->min_interval) {
639 pr_err("%s:minimum poll interval violated\n", __func__);
646 static int bmp085_input_init(struct bmp085_data *barom)
650 INIT_DELAYED_WORK(&barom->input_work, bmp085_input_work_func);
652 barom->input_dev = input_allocate_device();
653 if (!barom->input_dev) {
655 dev_err(&barom->client->dev, "input device allocate failed\n");
658 #ifdef BMP085_OPEN_ENABLE
659 barom->input_dev->open = bmp085_input_open;
660 barom->input_dev->close = bmp085_input_close;
663 input_set_drvdata(barom->input_dev, barom);
665 set_bit(EV_ABS, barom->input_dev->evbit);
667 /* Need to define the correct min and max */
668 input_set_abs_params(barom->input_dev, ABS_PRESSURE,
669 barom->pdata->min_p, barom->pdata->max_p,
670 barom->pdata->fuzz, barom->pdata->flat);
672 barom->input_dev->name = "barometer";
674 err = input_register_device(barom->input_dev);
676 dev_err(&barom->client->dev,
677 "unable to register input polled device %s\n",
678 barom->input_dev->name);
685 input_free_device(barom->input_dev);
690 static void bmp085_input_cleanup(struct bmp085_data *barom)
692 input_unregister_device(barom->input_dev);
693 input_free_device(barom->input_dev);
696 static int bmp085_read_store_eeprom_val(struct bmp085_data *barom)
701 buf[0] = BMP085_EEPROM_AC1_U;
702 err = bmp085_i2c_read(barom, buf, 22);
704 pr_err("%s:Cannot read EEPROM values\n", __func__);
708 barom->bmp085_eeprom_vals.AC1 = (buf[0] << 8) | buf[1];
709 barom->bmp085_eeprom_vals.AC2 = (buf[2] << 8) | buf[3];
710 barom->bmp085_eeprom_vals.AC3 = (buf[4] << 8) | buf[5];
711 barom->bmp085_eeprom_vals.AC4 = (buf[6] << 8) | buf[7];
712 barom->bmp085_eeprom_vals.AC5 = (buf[8] << 8) | buf[9];
713 barom->bmp085_eeprom_vals.AC6 = (buf[10] << 8) | buf[11];
714 barom->bmp085_eeprom_vals.B1 = (buf[12] << 8) | buf[13];
715 barom->bmp085_eeprom_vals.B2 = (buf[14] << 8) | buf[15];
716 barom->bmp085_eeprom_vals.MB = (buf[16] << 8) | buf[17];
717 barom->bmp085_eeprom_vals.MC = (buf[18] << 8) | buf[19];
718 barom->bmp085_eeprom_vals.MD = (buf[20] << 8) | buf[21];
723 static int bmp085_probe(struct i2c_client *client,
724 const struct i2c_device_id *id)
726 struct bmp085_data *barom;
729 if (client->dev.platform_data == NULL) {
730 pr_err("%s:platform data is NULL. exiting.\n", __func__);
735 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
736 pr_err("%s:client not i2c capable\n", __func__);
741 barom = kzalloc(sizeof(*barom), GFP_KERNEL);
743 pr_err("%s:failed to allocate memory for module data\n",
748 mutex_init(&barom->lock);
749 mutex_lock(&barom->lock);
750 barom->client = client;
751 barom->oversampling_rate = 0;
754 barom->pdata = kzalloc(sizeof(*barom->pdata), GFP_KERNEL);
755 if (barom->pdata == NULL)
758 memcpy(barom->pdata, client->dev.platform_data, sizeof(*barom->pdata));
760 err = bmp085_validate_pdata(barom);
762 pr_err("%s:failed to validate platform data\n", __func__);
766 i2c_set_clientdata(client, barom);
768 err = bmp085_read_store_eeprom_val(barom);
770 pr_err("%s: Reading the EEPROM failed\n", __func__);
772 goto err_req_irq_failed;
775 INIT_WORK(&barom->wq, bmp085_work_queue);
777 err = request_irq(barom->client->irq, bmp085_irq_handler,
778 IRQF_TRIGGER_RISING, BMP085_NAME, barom);
780 pr_err("%s: irq request failed: %d\n", __func__, err);
782 goto err_req_irq_failed;
785 barom->regulator = regulator_get(&client->dev, "vcc");
786 if (IS_ERR_OR_NULL(barom->regulator)) {
787 dev_err(&client->dev, "unable to get regulator\n");
788 barom->regulator = NULL;
790 barom->io_regulator = regulator_get(&client->dev, "vio");
791 if (IS_ERR(barom->io_regulator))
792 barom->io_regulator = NULL;
794 err = bmp085_input_init(barom);
798 bmp085_misc_data = barom;
800 err = misc_register(&bmp085_misc_device);
802 dev_err(&client->dev, "barom_device register failed\n");
806 err = device_create_file(&client->dev, &dev_attr_registers);
808 pr_err("%s:File device creation failed: %d\n", __func__, err);
811 /* As default, do not report information */
812 atomic_set(&barom->enabled, 0);
814 mutex_unlock(&barom->lock);
819 bmp085_input_cleanup(barom);
821 if (barom->regulator)
822 regulator_put(barom->regulator);
823 if (barom->io_regulator)
824 regulator_put(barom->io_regulator);
827 mutex_unlock(&barom->lock);
835 static int __devexit bmp085_remove(struct i2c_client *client)
837 /* TO DO: revisit ordering here once _probe order is finalized */
838 struct bmp085_data *barom = i2c_get_clientdata(client);
840 misc_deregister(&bmp085_misc_device);
841 bmp085_input_cleanup(barom);
842 bmp085_disable(barom);
843 if (barom->regulator)
844 regulator_put(barom->regulator);
845 if (barom->io_regulator)
846 regulator_put(barom->io_regulator);
848 device_remove_file(&client->dev, &dev_attr_registers);
850 destroy_workqueue(barom_wq);
858 static int bmp085_resume(struct i2c_client *client)
860 struct bmp085_data *barom = i2c_get_clientdata(client);
862 if (barom->on_before_suspend)
863 return bmp085_enable(barom);
867 static int bmp085_suspend(struct i2c_client *client, pm_message_t mesg)
869 struct bmp085_data *barom = i2c_get_clientdata(client);
871 barom->on_before_suspend = atomic_read(&barom->enabled);
872 return bmp085_disable(barom);
875 static const struct i2c_device_id bmp085_id[] = {
880 MODULE_DEVICE_TABLE(i2c, bmp085_id);
882 static struct i2c_driver bmp085_driver = {
886 .probe = bmp085_probe,
887 .remove = __devexit_p(bmp085_remove),
888 .resume = bmp085_resume,
889 .suspend = bmp085_suspend,
890 .id_table = bmp085_id,
893 static int __init bmp085_init(void)
895 barom_wq = create_singlethread_workqueue("barometer_wq");
897 pr_err("%s: Cannot create work queue\n", __func__);
900 pr_info("BMP085 barometer driver\n");
901 return i2c_add_driver(&bmp085_driver);
904 static void __exit bmp085_exit(void)
906 i2c_del_driver(&bmp085_driver);
910 module_init(bmp085_init);
911 module_exit(bmp085_exit);
913 MODULE_DESCRIPTION("bmp085 barometer driver");
914 MODULE_AUTHOR("Dan Murphy D.Murphy@Motorola.com");
915 MODULE_LICENSE("GPL");