Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

misc: bmp085: Clean up and enable use of interrupt for completion.

- pass IRQ to driver and have it initialize
- finish waiting early if interrupt fires

Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>
Signed-off-by: Marek Belisko <marek@goldelico.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Marek Belisko and committed by
Greg Kroah-Hartman
c07f85c5 612340b1

+37 -8
+1 -1
drivers/misc/bmp085-i2c.c
··· 49 49 return err; 50 50 } 51 51 52 - return bmp085_probe(&client->dev, regmap); 52 + return bmp085_probe(&client->dev, regmap, client->irq); 53 53 } 54 54 55 55 static int bmp085_i2c_remove(struct i2c_client *client)
+1 -1
drivers/misc/bmp085-spi.c
··· 41 41 return err; 42 42 } 43 43 44 - return bmp085_probe(&client->dev, regmap); 44 + return bmp085_probe(&client->dev, regmap, client->irq); 45 45 } 46 46 47 47 static int bmp085_spi_remove(struct spi_device *client)
+34 -5
drivers/misc/bmp085.c
··· 49 49 #include <linux/device.h> 50 50 #include <linux/init.h> 51 51 #include <linux/slab.h> 52 - #include <linux/delay.h> 53 52 #include <linux/of.h> 54 53 #include "bmp085.h" 54 + #include <linux/interrupt.h> 55 + #include <linux/completion.h> 56 + #include <linux/gpio.h> 55 57 56 58 #define BMP085_CHIP_ID 0x55 57 59 #define BMP085_CALIBRATION_DATA_START 0xAA ··· 86 84 unsigned long last_temp_measurement; 87 85 u8 chip_id; 88 86 s32 b6; /* calculated temperature correction coefficient */ 87 + int irq; 88 + struct completion done; 89 89 }; 90 + 91 + static irqreturn_t bmp085_eoc_isr(int irq, void *devid) 92 + { 93 + struct bmp085_data *data = devid; 94 + 95 + complete(&data->done); 96 + 97 + return IRQ_HANDLED; 98 + } 90 99 91 100 static s32 bmp085_read_calibration_data(struct bmp085_data *data) 92 101 { ··· 129 116 s32 status; 130 117 131 118 mutex_lock(&data->lock); 119 + 120 + init_completion(&data->done); 121 + 132 122 status = regmap_write(data->regmap, BMP085_CTRL_REG, 133 123 BMP085_TEMP_MEASUREMENT); 134 124 if (status < 0) { ··· 139 123 "Error while requesting temperature measurement.\n"); 140 124 goto exit; 141 125 } 142 - msleep(BMP085_TEMP_CONVERSION_TIME); 126 + wait_for_completion_timeout(&data->done, 1 + msecs_to_jiffies( 127 + BMP085_TEMP_CONVERSION_TIME)); 143 128 144 129 status = regmap_bulk_read(data->regmap, BMP085_CONVERSION_REGISTER_MSB, 145 130 &tmp, sizeof(tmp)); ··· 164 147 s32 status; 165 148 166 149 mutex_lock(&data->lock); 150 + 151 + init_completion(&data->done); 152 + 167 153 status = regmap_write(data->regmap, BMP085_CTRL_REG, 168 154 BMP085_PRESSURE_MEASUREMENT + 169 155 (data->oversampling_setting << 6)); ··· 177 157 } 178 158 179 159 /* wait for the end of conversion */ 180 - msleep(2+(3 << data->oversampling_setting)); 181 - 160 + wait_for_completion_timeout(&data->done, 1 + msecs_to_jiffies( 161 + 2+(3 << data->oversampling_setting))); 182 162 /* copy data into a u32 (4 bytes), but skip the first byte. */ 183 163 status = regmap_bulk_read(data->regmap, BMP085_CONVERSION_REGISTER_MSB, 184 164 ((u8 *)&tmp)+1, 3); ··· 440 420 }; 441 421 EXPORT_SYMBOL_GPL(bmp085_regmap_config); 442 422 443 - int bmp085_probe(struct device *dev, struct regmap *regmap) 423 + int bmp085_probe(struct device *dev, struct regmap *regmap, int irq) 444 424 { 445 425 struct bmp085_data *data; 446 426 int err = 0; ··· 454 434 dev_set_drvdata(dev, data); 455 435 data->dev = dev; 456 436 data->regmap = regmap; 437 + data->irq = irq; 438 + 439 + if (data->irq > 0) { 440 + err = devm_request_irq(dev, data->irq, bmp085_eoc_isr, 441 + IRQF_TRIGGER_RISING, "bmp085", 442 + data); 443 + if (err < 0) 444 + goto exit_free; 445 + } 457 446 458 447 /* Initialize the BMP085 chip */ 459 448 err = bmp085_init_client(data);
+1 -1
drivers/misc/bmp085.h
··· 26 26 27 27 extern struct regmap_config bmp085_regmap_config; 28 28 29 - int bmp085_probe(struct device *dev, struct regmap *regmap); 29 + int bmp085_probe(struct device *dev, struct regmap *regmap, int irq); 30 30 int bmp085_remove(struct device *dev); 31 31 int bmp085_detect(struct device *dev); 32 32