Add support for bmp18x to bmp085
v2 cover Add support for bmp18x to bmp085
Hi,
This is version 2 of the patch-set that adds support for Bosch Sensortec's bmp18x pressure sensors.
The patches have been restructured some to incremently expand the existing bmp085 driver. The last patch renames the bmp085 driver to bmp18x simply because the bmp18x series obsoletes the old bmp085 chips.
--
Best regards,
Eric
Eric Andersson (3):
misc: clean up bmp085 driver
misc: add support for bmp18x chips in bmp085 driver
misc: rename bmp085 to bmp18x
drivers/misc/Kconfig | 38 +++- drivers/misc/Makefile | 4 +- drivers/misc/bmp085-i2c.c | 133 ++++++++++++ drivers/misc/bmp085.c | 483 ----------------------------------------- drivers/misc/bmp18x-i2c.c | 133 ++++++++++++ drivers/misc/bmp18x-spi.c | 139 ++++++++++++ drivers/misc/bmp18x.c | 510 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/i2c/bmp18x.h | 62 ++++++ 8 files changed, 1009 insertions(+), 493 deletions(-) create mode 100644 drivers/misc/bmp085-i2c.c delete mode 100644 drivers/misc/bmp085.c create mode 100644 drivers/misc/bmp18x-i2c.c create mode 100644 drivers/misc/bmp18x-spi.c create mode 100644 drivers/misc/bmp18x.c create mode 100644 include/linux/i2c/bmp18x.h
Signature · 1 line
1.7.3.4
PATCH v2 1/3 misc: clean up bmp085 driver
This patch includes various cleaning of the bmp085 driver including:
- Addition of platform_data and header file
- Implement pm functions
- Whitespaces and alignment fixes
- Minor typos
- Consistency fixes
--- drivers/misc/bmp085.c | 178 ++++++++++++++++++++++++++++---------------- include/linux/i2c/bmp085.h | 43 +++++++++++ 2 files changed, 158 insertions(+), 63 deletions(-) create mode 100644 include/linux/i2c/bmp085.h
drivers/misc/bmp085.c +115 -63
@@ -1,4 +1,6 @@/* Copyright (c) 2010 Christoph Mair <[email protected]> +Copyright (c) 2012 Bosch Sensortec GmbH +Copyright (c) 2012 Unixphere AB This driver supports the bmp085 digital barometric pressure and temperature sensor from Bosch Sensortec. The datasheet
@@ -42,13 +44,13 @@Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include <linux/module.h> +#include <linux/device.h> #include <linux/init.h> #include <linux/i2c.h> #include <linux/slab.h> #include <linux/delay.h> - +#include <linux/i2c/bmp085.h> #define BMP085_I2C_ADDRESS 0x77#define BMP085_CHIP_ID 0x55
@@ -56,7 +58,6 @@#define BMP085_CALIBRATION_DATA_START 0xAA#define BMP085_CALIBRATION_DATA_LENGTH 11/* 16 bit values */ #define BMP085_CHIP_ID_REG 0xD0 -#define BMP085_VERSION_REG 0xD1#define BMP085_CTRL_REG 0xF4#define BMP085_TEMP_MEASUREMENT 0x2E#define BMP085_PRESSURE_MEASUREMENT 0x34
@@ -65,9 +66,6 @@#define BMP085_CONVERSION_REGISTER_XLSB 0xF8#define BMP085_TEMP_CONVERSION_TIME 5 -#define BMP085_CLIENT_NAME "bmp085" - -static const unsigned short normal_i2c[] = {BMP085_I2C_ADDRESS ,I2C_CLIENT_END };
@@ -78,20 +76,18 @@ struct bmp085_calibration_data {s16 MB ,MC ,MD ; }; - -/* Each client has this additional data */ struct bmp085_data { -struct i2c_client *client; -struct mutex lock; -struct bmp085_calibration_data calibration; -u32 raw_temperature; -u32 raw_pressure; -unsigned char oversampling_setting; -u32 last_temp_measurement; -s32 b6;/* calculated temperature correction coefficient */ +struct i2c_client *client; +struct mutex lock; +struct bmp085_calibration_data calibration; +u8 oversampling_setting; +u32 raw_temperature; +u32 raw_pressure; +u32 temp_measurement_period; +u32 last_temp_measurement; +s32 b6;/* calculated temperature correction coefficient */ }; -static s32 bmp085_read_calibration_data (struct i2c_client *client) {u16 tmp[BMP085_CALIBRATION_DATA_LENGTH ];
@@ -99,12 +95,12 @@ static s32 bmp085_read_calibration_data(struct i2c_client *client)struct bmp085_calibration_data *cali = &(data->calibration);s32 status =i2c_smbus_read_i2c_block_data (client,BMP085_CALIBRATION_DATA_START , -BMP085_CALIBRATION_DATA_LENGTH *sizeof (u16), + (BMP085_CALIBRATION_DATA_LENGTH <<1 ), (u8 *)tmp);if (status <0 )return status; -if (status !=BMP085_CALIBRATION_DATA_LENGTH *sizeof (u16)) +if (status != (BMP085_CALIBRATION_DATA_LENGTH <<1 ))return -EIO ; cali->AC1 =be16_to_cpu (tmp[0 ]);
@@ -121,7 +117,6 @@ static s32 bmp085_read_calibration_data(struct i2c_client *client)return 0 ; } -static s32 bmp085_update_raw_temperature (struct bmp085_data *data) {u16 tmp;
@@ -129,8 +124,8 @@ static s32 bmp085_update_raw_temperature(struct bmp085_data *data)mutex_lock (&data->lock); status =i2c_smbus_write_byte_data (data->client,BMP085_CTRL_REG , -BMP085_TEMP_MEASUREMENT ); -if (status !=0 ) { +BMP085_TEMP_MEASUREMENT ); +if (status <0 ) {dev_err (&data->client->dev,"Error while requesting temperature measurement.\n" ); goto exit;
@@ -163,8 +158,9 @@ static s32 bmp085_update_raw_pressure(struct bmp085_data *data)mutex_lock (&data->lock); status =i2c_smbus_write_byte_data (data->client,BMP085_CTRL_REG , -BMP085_PRESSURE_MEASUREMENT + (data->oversampling_setting<<6 )); -if (status !=0 ) { +BMP085_PRESSURE_MEASUREMENT + + (data->oversampling_setting <<6 )); +if (status <0 ) {dev_err (&data->client->dev,"Error while requesting pressure measurement.\n" ); goto exit;
@@ -193,7 +189,6 @@ exit:return status; } -/* * This function starts the temperature measurement and returns the value * in tenth of a degree celsius.
@@ -205,7 +200,7 @@ static s32 bmp085_get_temperature(struct bmp085_data *data, int *temperature)int status; status =bmp085_update_raw_temperature (data); -if (status !=0 ) +if (status <0 ) goto exit; x1 = ((data->raw_temperature - cali->AC6) * cali->AC5) >>15 ;
@@ -222,8 +217,10 @@ exit:/* * This function starts the pressure measurement and returns the value * in millibar. Since the pressure depends on the ambient temperature, -* a temperature measurement is executed if the last known value is older -* than one second. +* a temperature measurement is executed according to the given temperature +* measurememt period (default is 1 sec boundary). This period could vary +* and needs to be adjusted according to the sensor environment, i.e. if big +* temperature variations then the temperature needs to be read out often. */ static s32 bmp085_get_pressure (struct bmp085_data *data,int *pressure) {
@@ -233,16 +230,17 @@ static s32 bmp085_get_pressure(struct bmp085_data *data, int *pressure)s32 p;int status; -/* alt least every second force an update of the ambient temperature */ -if (data->last_temp_measurement +1 *HZ < jiffies) { +/* update the ambient temperature according to the given meas. period */ +if (data->last_temp_measurement + + data->temp_measurement_period < jiffies) { status =bmp085_get_temperature (data,NULL ); -if (status !=0 ) - goto exit; +if (status <0 ) +return status; } status =bmp085_update_raw_pressure (data); -if (status !=0 ) - goto exit; +if (status <0 ) +return status; x1 = (data->b6 * data->b6) >>12 ; x1 *= cali->B2;
@@ -273,15 +271,14 @@ static s32 bmp085_get_pressure(struct bmp085_data *data, int *pressure) *pressure = p; -exit: -return status; +return 0 ; }/* * This function sets the chip-internal oversampling. Valid values are 0..3. * The chip will use 2^oversampling samples for internal averaging. * This influences the measurement time and the accuracy; larger values -* increase both. The datasheet gives on overview on how measurement time, +* increase both. The datasheet gives an overview on how measurement time, * accuracy and noise correlate. */ static void bmp085_set_oversampling(struct bmp085_data *data,
@@ -308,12 +305,16 @@ static ssize_t set_oversampling(struct device *dev,struct i2c_client *client =to_i2c_client (dev);struct bmp085_data *data =i2c_get_clientdata (client);unsigned long oversampling; -int success =strict_strtoul (buf,10 , &oversampling); -if (success ==0 ) { +int err =kstrtoul (buf,10 , &oversampling); + +if (err ==0 ) { +mutex_lock (&data->lock);bmp085_set_oversampling (data, oversampling); +mutex_unlock (&data->lock);return count; } -return success; + +return err; } static ssize_t show_oversampling(struct device *dev,
@@ -321,6 +322,7 @@ static ssize_t show_oversampling(struct device *dev, {struct i2c_client *client =to_i2c_client (dev);struct bmp085_data *data =i2c_get_clientdata (client); +return sprintf (buf,"%u\n" ,bmp085_get_oversampling (data)); } static DEVICE_ATTR(oversampling, S_IWUSR | S_IRUGO,
@@ -336,7 +338,7 @@ static ssize_t show_temperature(struct device *dev,struct bmp085_data *data =i2c_get_clientdata (client); status =bmp085_get_temperature (data, &temperature); -if (status !=0 ) +if (status <0 )return status;else return sprintf (buf,"%d\n" , temperature);
@@ -353,7 +355,7 @@ static ssize_t show_pressure(struct device *dev,struct bmp085_data *data =i2c_get_clientdata (client); status =bmp085_get_pressure (data, &pressure); -if (status !=0 ) +if (status <0 )return status;else return sprintf (buf,"%d\n" , pressure);
@@ -385,43 +387,58 @@ static int bmp085_detect(struct i2c_client *client, struct i2c_board_info *info)static int bmp085_init_client (struct i2c_client *client) { -unsigned char version; -int status;struct bmp085_data *data =i2c_get_clientdata (client); +struct bmp085_platform_data *pdata = client->dev.platform_data; +int status =bmp085_read_calibration_data (client); + +if (status <0 ) +return status; + data->client = client; - status =bmp085_read_calibration_data (client); -if (status !=0 ) - goto exit; - version =i2c_smbus_read_byte_data (client,BMP085_VERSION_REG ); data->last_temp_measurement =0 ; - data->oversampling_setting =3 ; + data->temp_measurement_period = + pdata ? (pdata->temp_measurement_period/1000 )*HZ :1 *HZ ; + data->oversampling_setting = pdata ? pdata->default_oversampling :3 ;mutex_init (&data->lock); -dev_info (&data->client->dev,"BMP085 ver. %d.%d found.\n" , - (version &0x0F ), (version &0xF0 ) >>4 ); -exit: -return status; + +return 0 ; }static int __devinit bmp085_probe (struct i2c_client *client, -const struct i2c_device_id *id) +const struct i2c_device_id *id) {struct bmp085_data *data; +struct bmp085_platform_data *pdata = client->dev.platform_data; +u8 chip_id = (pdata && pdata->chip_id) ? pdata->chip_id : +BMP085_CHIP_ID ;int err =0 ; +if (pdata && pdata->init_hw) { + err = pdata->init_hw (&client->dev); +if (err) { +dev_err (&client->dev,"%s: init_hw failed!\n" , +BMP085_NAME ); +return err; + } + } + data =kzalloc (sizeof (struct bmp085_data ),GFP_KERNEL );if (!data) { err = -ENOMEM ; goto exit; } -/* default settings after POR */ - data->oversampling_setting =0x00 ; -i2c_set_clientdata (client, data); +if (i2c_smbus_read_byte_data (client,BMP085_CHIP_ID_REG ) != chip_id) { +dev_err (&client->dev,"%s: chip_id failed!\n" ,BMP085_NAME ); + err = -ENODEV ; + goto exit_free; + } +/* Initialize the BMP085 chip */ err =bmp085_init_client (client); -if (err !=0 ) +if (err <0 ) goto exit_free;/* Register sysfs hooks */
@@ -429,22 +446,57 @@ static int __devinit bmp085_probe(struct i2c_client *client,if (err) goto exit_free; -dev_info (&data->client->dev,"Successfully initialized bmp085!\n" ); - goto exit; +dev_info (&client->dev,"Succesfully initialized bmp085!\n" ); +return 0 ; exit_free:kfree (data); exit: +if (pdata && pdata->deinit_hw) + pdata->deinit_hw (&client->dev);return err; } static int __devexit bmp085_remove(struct i2c_client *client) { +struct bmp085_data *data =i2c_get_clientdata (client); +struct bmp085_platform_data *pdata = client->dev.platform_data; +sysfs_remove_group (&client->dev.kobj, &bmp085_attr_group); -kfree (i2c_get_clientdata (client)); + +if (pdata && pdata->deinit_hw) + pdata->deinit_hw (&client->dev); + +kfree (data); +return 0 ; } +#ifdef CONFIG_PM +static int bmp085_suspend (struct device *dev) +{ +struct bmp085_platform_data *pdata = dev->platform_data; + +if (pdata && pdata->deinit_hw) + pdata->deinit_hw (dev); + +return 0 ; +} + +static int bmp085_resume (struct device *dev) +{ +struct bmp085_platform_data *pdata = dev->platform_data; + +if (pdata && pdata->init_hw) +return pdata->init_hw (dev); + +return 0 ; +} +#endif + +static SIMPLE_DEV_PM_OPS(bmp085_pm_ops, bmp085_suspend, + bmp085_resume); +static const struct i2c_device_id bmp085_id[] = { {"bmp085" ,0 }, { }
@@ -454,7 +506,8 @@ MODULE_DEVICE_TABLE(i2c, bmp085_id);static struct i2c_driver bmp085_driver = { .driver = { .owner =THIS_MODULE , - .name ="bmp085" + .name ="bmp085" , + .pm = &bmp085_pm_ops, }, .id_table = bmp085_id, .probe = bmp085_probe,
@@ -474,7 +527,6 @@ static void __exit bmp085_exit(void)i2c_del_driver (&bmp085_driver); } -MODULE_AUTHOR ("Christoph Mair <[email protected]" );MODULE_DESCRIPTION ("BMP085 driver" );MODULE_LICENSE ("GPL" );
include/linux/i2c/bmp085.h new file +43 -0
43 lines not on this page · raw message
Signature · 1 line
1.7.3.4
Arnd Bergmann
maintainerRe: [PATCHv2 1/3] misc: clean up bmp085 driver
Quoted 9 lines · Eric Andersson
This patch includes various cleaning of the bmp085 driver including:
- Addition ofplatform_dataand header file
- Implement pm functions
- Whitespaces and alignment fixes
- Minor typos
- Consistency fixesReviewed-by Stefan Nilsson <[email protected]>Signed-off-by Eric Andersson <[email protected]>
Most of the cleanups look good, just a few things that stick out:
Quoted 9 lines
static int
__devinitbmp085_probe(structi2c_client*client,drivers/misc/bmp085.c +4
-1- const struct i2c_device_id *id) + const struct i2c_device_id *id) {struct bmp085_data *data; +struct bmp085_platform_data *pdata = client->dev.platform_data; +u8 chip_id = (pdata && pdata->chip_id) ? pdata->chip_id : +BMP085_CHIP_ID ;int err =0 ;
drivers/misc/bmp085.c static int bmp085_detect(struct i2c_client *client, struct i2c_board_info *info) · line 424
Quoted 10 lines
drivers/misc/bmp085.c +9
-0+if (pdata && pdata->init_hw) { + err = pdata->init_hw (&client->dev); +if (err) { +dev_err (&client->dev,"%s: init_hw failed!\n" , +BMP085_NAME ); +return err; + } + } +
The addition of platform_data does not look like a cleanup to me, it's a significant change in the interface to the platform, so I would put it into a separate patch.
drivers/misc/bmp085.c static int bmp085_detect(struct i2c_client *client, struct i2c_board_info *info) · line 438
Quoted 6 lines
drivers/misc/bmp085.c +6
-0+if (i2c_smbus_read_byte_data (client,BMP085_CHIP_ID_REG ) != chip_id) { +dev_err (&client->dev,"%s: chip_id failed!\n" ,BMP085_NAME ); + err = -ENODEV ; + goto exit_free; + } +
This part looks like it belongs into the second patch where you add support for more than one chip id.
include/linux/i2c/bmp085.h
Quoted 5 lines
include/linux/i2c/bmp085.h new file +0
-0
Since this file only adds platform_data, I think it should go into include/linux/platform_data/, not include/linux/i2c, and it should be in the same patch as the change to use the platform data when you split that out.
Also, which platforms are actually using this driver? I could not find any platform that defines a bmp085 platform_device. If this is for new ARM platforms, I would rather not add platform_data at all because those platforms will have to use device tree properties rather than platform_data to pass initialization data.
Arnd
Re: [PATCHv2 1/3] misc: clean up bmp085 driver
Quoted 23 lines · Arnd Bergmann
Quoted 9 lines · Eric Andersson
This patch includes various cleaning of the bmp085 driver including:
- Addition ofplatform_dataand header file
- Implement pm functions
- Whitespaces and alignment fixes
- Minor typos
- Consistency fixesReviewed-by Stefan Nilsson <[email protected]>Signed-off-by Eric Andersson <[email protected]>Most of the cleanups look good, just a few things that stick out:
Quoted 10 lines
static int
__devinitbmp085_probe(structi2c_client*client,drivers/misc/bmp085.c +4
-1- const struct i2c_device_id *id) + const struct i2c_device_id *id) {struct bmp085_data *data; +struct bmp085_platform_data *pdata = client->dev.platform_data; +u8 chip_id = (pdata && pdata->chip_id) ? pdata->chip_id : +BMP085_CHIP_ID ;int err =0 ;
Quoted 13 lines
drivers/misc/bmp085.c static int bmp085_detect(struct i2c_client *client, struct i2c_board_info *info) · line 424
Quoted 9 lines
drivers/misc/bmp085.c +9
-0+if (pdata && pdata->init_hw) { + err = pdata->init_hw (&client->dev); +if (err) { +dev_err (&client->dev,"%s: init_hw failed!\n" , +BMP085_NAME ); +return err; + } + } +The addition of
platform_datadoes not look like a cleanup to me, it's a significant change in the interface to the platform, so I would put it into a separate patch.
Yes, I agree.
Quoted 21 lines
drivers/misc/bmp085.c static int bmp085_detect(struct i2c_client *client, struct i2c_board_info *info) · line 438
Quoted 6 lines
drivers/misc/bmp085.c +6
-0+if (i2c_smbus_read_byte_data (client,BMP085_CHIP_ID_REG ) != chip_id) { +dev_err (&client->dev,"%s: chip_id failed!\n" ,BMP085_NAME ); + err = -ENODEV ; + goto exit_free; + } +This part looks like it belongs into the second patch where you add support for more than one chip id.
include/linux/i2c/bmp085.h
Quoted 5 lines
include/linux/i2c/bmp085.h new file +0
-0Since this file only adds
platform_data, I think it should go intoinclude/linux/platform_data/, notinclude/linux/i2c, and it should be in the same patch as the change to use the platform data when you split that out.
Quoted 5 lines
Also, which platforms are actually using this driver? I could not find any platform that defines a bmp085
platform_device. If this is for new ARM platforms, I would rather not addplatform_dataat all because those platforms will have to use device tree properties rather thanplatform_datato pass initialization data.
Platform device? This is a pressure sensor connected as a peripheral device to the i2c bus. I don't think you will find any platform that uses this "by default" in the tree.
Of course I can add of_get_property() calls, but what is actually the long-term plan here for peripheral devices? Should they all abandon their platform data in favor of devicetree? How should the callbacks in platform data be handled, in my case pdata->init_hw()?
Signature · 4 lines
Best regards, Eric http://www.unixphere.com
Arnd Bergmann
maintainerRe: [PATCHv2 1/3] misc: clean up bmp085 driver
Quoted 17 lines · Eric Andersson
Quoted 11 lines
include/linux/i2c/bmp085.h
Quoted 5 lines
include/linux/i2c/bmp085.h new file +0
-0Since this file only adds
platform_data, I think it should go intoinclude/linux/platform_data/, notinclude/linux/i2c, and it should be in the same patch as the change to use the platform data when you split that out.Quoted 5 lines
Also, which platforms are actually using this driver? I could not find any platform that defines a bmp085
platform_device. If this is for new ARM platforms, I would rather not addplatform_dataat all because those platforms will have to use device tree properties rather thanplatform_datato pass initialization data.
Quoted 7 lines
Platform device? This is a pressure sensor connected as a peripheral device to the i2c bus. I don't think you will find any platform that uses this "by default" in the tree.
Of course I can add
of_get_property()calls, but what is actually the long-term plan here for peripheral devices? Should they all abandon their platform data in favor of devicetree?
Yes, that is definitely the plan. The current method does not scale, because right now you have to modify the kernel sources any time you have a slightly different combination of devices in the system, which especially in cases of user-pluggable i2c devices is not a good design.
Quoted 2 lines
How should the callbacks in platform data be handled, in my case
pdata->init_hw()?
This depends a lot on what the individual callback does. In my experience, 90% of these callbacks can and should just get removed because they are not necessary and the same functionality can be expressed by generalizing the setup procedure, e.g. by calling into the regulator, gpio, clock or pinmux frameworks from the device probe() function.
In the few cases where this is not possible, some of the approaches I can think of (again, case by case) include:
* educate the hardware designers so they do things in a more maintainable way in the future, hope that the current design goes away.
* add a special case in the driver using something like if (machine_is_compatible("something,weird"))
do_weird_setup(dev);
* use auxdata for the machine to supply a platform_data structure in addition to the device tree.
* Don't support the board in the mainline kernel, but require the user to keep using a private patch (this is the status quo, because right now they need a private patch to add the board file).
Arnd
PATCH v2 2/3 misc: add support for bmp18x chips to the bmp085 driver
In reply to Eric AnderssonThe bmp18x chip family comes in an I2C respectively SPI variant. Hence, the bmp085 driver was split to support both buses.
--- drivers/misc/Kconfig | 26 ++++++- drivers/misc/Makefile | 2 + drivers/misc/bmp085-i2c.c | 132 ++++++++++++++++++++++++++++++++++ drivers/misc/bmp085-spi.c | 140 +++++++++++++++++++++++++++++++++++++ drivers/misc/bmp085.c | 167 +++++++++++++++++++------------------------- include/linux/i2c/bmp085.h | 22 ++++++- 6 files changed, 391 insertions(+), 98 deletions(-) create mode 100644 drivers/misc/bmp085-i2c.c create mode 100644 drivers/misc/bmp085-spi.c
drivers/misc/Kconfig +23 -3
@@ -453,14 +453,34 @@ config ARM_CHARLCD config BMP085 tristate "BMP085 digital pressure sensor" - depends on I2C && SYSFS + depends on (I2C || SPI_MASTER) && SYSFS help - If you say yes here you get support for the Bosch Sensortec - BMP085 digital pressure sensor. + Say Y here if you want support for Bosch Sensortec's digital + pressure sensors BMP085 and BMP18x. To compile this driver as a module, choose M here: the module will be called bmp085. +config BMP085_I2C + tristate "support I2C bus connection" + depends on BMP085 && I2C + help + Say Y here if you want to support Bosch Sensortec's digital pressure + sensor hooked to an I2C bus. + + To compile this driver as a module, choose M here: the + module will be called bmp085-i2c. + +config BMP085_SPI + tristate "support SPI bus connection" + depends on BMP085 && SPI_MASTER + help + Say Y here if you want to support Bosch Sensortec's digital pressure + sensor hooked to an SPI bus. + + To compile this driver as a module, choose M here: the + module will be called bmp085-spi. + config PCH_PHUB tristate "Intel EG20T PCH/LAPIS Semicon IOH(ML7213/ML7223/ML7831) PHUB" depends on PCI
drivers/misc/Makefile +2 -0
@@ -11,6 +11,8 @@ obj-$(CONFIG_ATMEL_PWM) += atmel_pwm.o obj-$(CONFIG_ATMEL_SSC) += atmel-ssc.o obj-$(CONFIG_ATMEL_TCLIB) += atmel_tclib.o obj-$(CONFIG_BMP085) += bmp085.o +obj-$(CONFIG_BMP085_I2C) += bmp085-i2c.o +obj-$(CONFIG_BMP085_SPI) += bmp085-spi.o obj-$(CONFIG_ICS932S401) += ics932s401.o obj-$(CONFIG_LKDTM) += lkdtm.o obj-$(CONFIG_TIFM_CORE) += tifm_core.o
drivers/misc/bmp085-i2c.c new file +132 -0
132 lines not on this page · raw message
drivers/misc/bmp085-spi.c new file +140 -0
140 lines not on this page · raw message
drivers/misc/bmp085.c +73 -94
349 lines not on this page · raw message
include/linux/i2c/bmp085.h +21 -1
@@ -20,7 +20,8 @@#ifndef _BMP085_H#define _BMP085_H -#define BMP085_NAME "bmp085" +#define BMP085_NAME "bmp085" +#define BMP085_I2C_ADDRESS 0x77/** * struct bmp085_platform_data - represents platform data for the bmp085 driver
@@ -40,4 +41,23 @@ struct bmp085_platform_data {void (*deinit_hw)(struct device *dev); }; +struct bmp085_bus_ops { +int (*read_block)(void *client,u8 reg,int len,char *buf); +int (*read_byte)(void *client,u8 reg); +int (*write_byte)(void *client,u8 reg,u8 value); +}; + +struct bmp085_data_bus { +const struct bmp085_bus_ops *bops; +void *client; +}; + +int bmp085_probe (struct device *dev,struct bmp085_data_bus *data_bus); +int bmp085_remove (struct device *dev); +int bmp085_detect (struct device *dev); +#ifdef CONFIG_PM +int bmp085_enable (struct device *dev); +int bmp085_disable (struct device *dev); +#endif +#endif
Signature · 1 line
1.7.3.4
Arnd Bergmann
maintainerRe: [PATCHv2 2/3] misc: add support for bmp18x chips to the bmp085 driver
Quoted 6 lines · Eric Andersson
The bmp18x chip family comes in an I2C respectively SPI variant. Hence, the bmp085 driver was split to support both buses.
Tested-by Zhengguang Guo <[email protected]>Reviewed-by Stefan Nilsson <[email protected]>Signed-off-by Eric Andersson <[email protected]>
(adding Mark Brown to Cc)
I don't know much about regmap, but your description sounds like you should be using it here, to simplify the differences between i2c and spi in your driver instead of implementing your own abstraction layer.
Quoted 23 lines
config BMP085
drivers/misc/Kconfig +13
-3tristate "BMP085 digital pressure sensor" - depends on I2C && SYSFS + depends on (I2C || SPI_MASTER) && SYSFS help - If you say yes here you get support for the Bosch Sensortec - BMP085 digital pressure sensor. + Say Y here if you want support for Bosch Sensortec's digital + pressure sensors BMP085 and BMP18x. To compile this driver as a module, choose M here: the module will be called bmp085. +config BMP085_I2C + tristate "support I2C bus connection" + depends on BMP085 && I2C + help + Say Y here if you want to support Bosch Sensortec's digital pressure + sensor hooked to an I2C bus. + + To compile this driver as a module, choose M here: the + module will be called bmp085-i2c. +
drivers/misc/Kconfig config ARM_CHARLCD · line 483
Quoted 10 lines
drivers/misc/Kconfig +10
-0+config BMP085_SPI + tristate "support SPI bus connection" + depends on BMP085 && SPI_MASTER + help + Say Y here if you want to support Bosch Sensortec's digital pressure + sensor hooked to an SPI bus. + + To compile this driver as a module, choose M here: the + module will be called bmp085-spi. +
IMHO this would be better expressed if you make CONFIG_BMP085 a hidden option that is selected when either BMP085_I2C or BMP085_SPI are enabled. Otherwise you make it possible to build just the base driver but neither of the front-ends, which is a bit pointless.
Quoted 3 lines
}
+EXPORT_SYMBOL(bmp085_probe);
When you add internal symbols inside of your driver, best always use EXPORT_SYMBOL_GPL. There is little practical difference here, but it helps to get used to just always pick that as a default.
Arnd
Re: [PATCHv2 2/3] misc: add support for bmp18x chips to the bmp085 driver
Quoted 45 lines · Arnd Bergmann
Quoted 6 lines · Eric Andersson
The bmp18x chip family comes in an I2C respectively SPI variant. Hence, the bmp085 driver was split to support both buses.
Tested-by Zhengguang Guo <[email protected]>Reviewed-by Stefan Nilsson <[email protected]>Signed-off-by Eric Andersson <[email protected]>(adding Mark Brown to Cc)
I don't know much about regmap, but your description sounds like you should be using it here, to simplify the differences between i2c and spi in your driver instead of implementing your own abstraction layer.
Quoted 30 lines
config BMP085
drivers/misc/Kconfig +20
-3tristate "BMP085 digital pressure sensor" - depends on I2C && SYSFS + depends on (I2C || SPI_MASTER) && SYSFS help - If you say yes here you get support for the Bosch Sensortec - BMP085 digital pressure sensor. + Say Y here if you want support for Bosch Sensortec's digital + pressure sensors BMP085 and BMP18x. To compile this driver as a module, choose M here: the module will be called bmp085. +config BMP085_I2C + tristate "support I2C bus connection" + depends on BMP085 && I2C + help + Say Y here if you want to support Bosch Sensortec's digital pressure + sensor hooked to an I2C bus. + + To compile this driver as a module, choose M here: the + module will be called bmp085-i2c. + +config BMP085_SPI + tristate "support SPI bus connection" + depends on BMP085 && SPI_MASTER + help + Say Y here if you want to support Bosch Sensortec's digital pressure + sensor hooked to an SPI bus. +
Quoted 8 lines
drivers/misc/Kconfig config ARM_CHARLCD · line 483
Quoted 3 lines
drivers/misc/Kconfig +3
-0+ To compile this driver as a module, choose M here: the + module will be called bmp085-spi. +IMHO this would be better expressed if you make
CONFIG_BMP085a hidden option that is selected when eitherBMP085_I2CorBMP085_SPIare enabled. Otherwise you make it possible to build just the base driver but neither of the front-ends, which is a bit pointless.
This setup is inspired from other drivers such as ad525x_dpot.c and ad714x.c, which also have their own bus abstraction. If regmap is a more generic way of solving this I am all for it!
Signature · 4 lines
Best regards, Eric http://www.unixphere.com
Re: [PATCHv2 2/3] misc: add support for bmp18x chips to the bmp085 driver
Quoted 6 lines · Eric Andersson
Quoted 4 lines · Arnd Bergmann
I don't know much about regmap, but your description sounds like you should be using it here, to simplify the differences between i2c and spi in your driver instead of implementing your own abstraction layer.
regmap provides I2C and SPI register I/O for most devices using those buses (and will do more buses in future I expect) and also provides diagnostic (things like register I/O logging and register map dumps) and optional cache infrastructure on top of that very cheaply (so you can easily do things like avoid the read part of read/modify/write cycles or restore the register state on resume). The win is partly getting the infrastructure and partly the fact that all the code for formatting the data for the bus is factored out from the individual driver, usually there's a substantial code saving.
Quoted 8 lines
Quoted 4 lines
IMHO this would be better expressed if you make
CONFIG_BMP085a hidden option that is selected when eitherBMP085_I2CorBMP085_SPIare enabled. Otherwise you make it possible to build just the base driver but neither of the front-ends, which is a bit pointless.This setup is inspired from other drivers such as
ad525x_dpot.candad714x.c, which also have their own bus abstraction. If regmap is a more generic way of solving this I am all for it!
The idiom Arnd describes is the more normal one for the reasons he mentions - see for example what most MFDs that have this problem do.
You'll need the same setup even with regmap since you'll need to register I2C and SPI drivers. What you save is all the register I/O code - often the I2C and SPI specific code gets reduced to just calling regmap_init_X(). The regmap subsystem only appeared in 3.1 so lots of drivers predate it and could benefit from using it, we're starting to see conversions happening in some subsystems.
PATCH v2 3/3 misc: rename bmp085 to bmp18x
In reply to Eric AnderssonThe bmp085 chip has been deprecated by the newer bmp18x chip family from Bosch Sensortec.
--- drivers/misc/Kconfig | 18 +- drivers/misc/Makefile | 6 +- drivers/misc/bmp085.c | 514 -------------------------------------------- drivers/misc/bmp18x-i2c.c | 132 +++++++++++ drivers/misc/bmp18x-spi.c | 140 ++++++++++++ drivers/misc/bmp18x.c | 512 +++++++++++++++++++++++++++++++++++++++++++ include/linux/i2c/bmp085.h | 63 ------ include/linux/i2c/bmp18x.h | 63 ++++++ 8 files changed, 859 insertions(+), 589 deletions(-) delete mode 100644 drivers/misc/bmp085.c create mode 100644 drivers/misc/bmp18x-i2c.c create mode 100644 drivers/misc/bmp18x-spi.c create mode 100644 drivers/misc/bmp18x.c delete mode 100644 include/linux/i2c/bmp085.h create mode 100644 include/linux/i2c/bmp18x.h
drivers/misc/Kconfig +9 -9
@@ -451,35 +451,35 @@ config ARM_CHARLCD line and the Linux version on the second line, but that's still useful. -config BMP085 - tristate "BMP085 digital pressure sensor" +config BMP18X + tristate "BMP18X digital pressure sensor" depends on (I2C || SPI_MASTER) && SYSFS help Say Y here if you want support for Bosch Sensortec's digital pressure sensors BMP085 and BMP18x. To compile this driver as a module, choose M here: the - module will be called bmp085. + module will be called bmp18x. -config BMP085_I2C +config BMP18X_I2C tristate "support I2C bus connection" - depends on BMP085 && I2C + depends on BMP18X && I2C help Say Y here if you want to support Bosch Sensortec's digital pressure sensor hooked to an I2C bus. To compile this driver as a module, choose M here: the - module will be called bmp085-i2c. + module will be called bmp18x-i2c. -config BMP085_SPI +config BMP18X_SPI tristate "support SPI bus connection" - depends on BMP085 && SPI_MASTER + depends on BMP18X && SPI_MASTER help Say Y here if you want to support Bosch Sensortec's digital pressure sensor hooked to an SPI bus. To compile this driver as a module, choose M here: the - module will be called bmp085-spi. + module will be called bmp18x-spi. config PCH_PHUB tristate "Intel EG20T PCH/LAPIS Semicon IOH(ML7213/ML7223/ML7831) PHUB"
drivers/misc/Makefile +3 -3
@@ -10,9 +10,9 @@ obj-$(CONFIG_INTEL_MID_PTI) += pti.o obj-$(CONFIG_ATMEL_PWM) += atmel_pwm.o obj-$(CONFIG_ATMEL_SSC) += atmel-ssc.o obj-$(CONFIG_ATMEL_TCLIB) += atmel_tclib.o -obj-$(CONFIG_BMP085) += bmp085.o -obj-$(CONFIG_BMP085_I2C) += bmp085-i2c.o -obj-$(CONFIG_BMP085_SPI) += bmp085-spi.o +obj-$(CONFIG_BMP18X) += bmp18x.o +obj-$(CONFIG_BMP18X_I2C) += bmp18x-i2c.o +obj-$(CONFIG_BMP18X_SPI) += bmp18x-spi.o obj-$(CONFIG_ICS932S401) += ics932s401.o obj-$(CONFIG_LKDTM) += lkdtm.o obj-$(CONFIG_TIFM_CORE) += tifm_core.o
drivers/misc/bmp085.c deleted +0 -514
514 lines not on this page · raw message
drivers/misc/bmp18x-i2c.c new file +132 -0
132 lines not on this page · raw message
drivers/misc/bmp18x-spi.c new file +140 -0
140 lines not on this page · raw message
drivers/misc/bmp18x.c new file +512 -0
512 lines not on this page · raw message
include/linux/i2c/bmp085.h deleted +0 -63
63 lines not on this page · raw message
include/linux/i2c/bmp18x.h new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
1.7.3.4
Arnd Bergmann
maintainerRe: [PATCHv2 3/3] misc: rename bmp085 to bmp18x
Quoted 5 lines · Eric Andersson
The bmp085 chip has been deprecated by the newer bmp18x chip family from Bosch Sensortec.
Reviewed-by Stefan Nilsson <[email protected]>Signed-off-by Eric Andersson <[email protected]>
Quoted 10 lines
--- drivers/misc/Kconfig | 18 +- drivers/misc/Makefile | 6 +- drivers/misc/bmp085.c | 514 -------------------------------------------- drivers/misc/bmp18x-i2c.c | 132 +++++++++++ drivers/misc/bmp18x-spi.c | 140 ++++++++++++ drivers/misc/bmp18x.c | 512 +++++++++++++++++++++++++++++++++++++++++++ include/linux/i2c/bmp085.h | 63 ------ include/linux/i2c/bmp18x.h | 63 ++++++ 8 files changed, 859 insertions(+), 589 deletions(-)
Please use 'git format-patch -M' when sending a rename patch, to make it obvious that there are no code changes in the rename. It's a bit suspicous that the files are different size and that you remove one .c file but add three other ones.
You should also try give a better explanation why the rename is actually a good idea. Simply listing the old model as deprecated does not sound like a strong enough reason, given that some people might rely on the existing name in user space interfaces.
Arnd
Re: [PATCHv2 3/3] misc: rename bmp085 to bmp18x
In reply to Eric AnderssonQuoted 2 lines · On Tue, 6 Mar 2012 22:08:04 +0100 Eric Andersson…
The bmp085 chip has been deprecated by the newer bmp18x chip family from Bosch Sensortec.
And yo risk breaking existing systems by renaming it. Are you going to rename it again when the 285, 385, 485 come out ?
By all means change the description but leave the Kconfig and module name alone. It's gratuitious breakage and config file frobbing otherwise.
Alan