hwmon: Driver for TI TMP103 temperature sensor
PATCH v3 1/1 hwmon: Driver for TI TMP103 temperature sensor
Driver for the TI TMP103.
The TI TMP103 is similar to the TMP102. It differs from the TMP102 by having only 8 bit registers.
---
- change for v2:
- add comments from GuenterRoeck:
- remove Cc from commit subject
- add devicetree maintainer
- move Documentation to Documentation/hwmon/tmp103
- remove devicetree bindings from Documentation
- add compatible string to "Documentation/devicetree/bindings/i2c/trivial-devices.txt"
- remove CamelCase
- fix Codingstyle issues
- use ATTRIBUTE_GROUPS and devm_hwmon_device_register_with_groups()
- remove unsused define TMP103_CONFIG_RD_ONLY
- restore config register when exit()
- use regmap
- changes for v3:
again a lot of fantastic tips how to use regmap efficiently from Guenter Roeck:
- get rid of "struct tmp103"
- get rid of "static const u8 tmp103_reg[]"
- get rid of mutex lock
- drop config_orig entirely
- use regmap_update_bits()
.../devicetree/bindings/i2c/trivial-devices.txt | 1 + Documentation/hwmon/tmp103 | 28 +++ drivers/hwmon/Kconfig | 10 + drivers/hwmon/Makefile | 1 + drivers/hwmon/tmp103.c | 203 +++++++++++++++++++++ 5 files changed, 243 insertions(+) create mode 100644 Documentation/hwmon/tmp103 create mode 100644 drivers/hwmon/tmp103.c
Documentation/devicetree/bindings/i2c/trivial-devices.txt +1 -0
@@ -83,5 +83,6 @@ stm,m41t80 M41T80 - SERIAL ACCESS RTC WITH ALARMS taos,tsl2550 Ambient Light Sensor with SMBUS/Two Wire Serial Interface ti,tsc2003 I2C Touch-Screen Controller ti,tmp102 Low Power Digital Temperature Sensor with SMBUS/Two Wire Serial Interface +ti,tmp103 Low Power Digital Temperature Sensor with SMBUS/Two Wire Serial Interface ti,tmp275 Digital Temperature Sensor winbond,wpct301 i2c trusted platform module (TPM)
Documentation/hwmon/tmp103 new file +28 -0
@@ -0,0 +1,28 @@ +Kernel driver tmp103 +==================== + +Supported chips: + * Texas Instruments TMP103 + Prefix: 'tmp103' + Addresses scanned: none + Product info and datasheet: http://www.ti.com/product/tmp103 + +Author: + Heiko Schocher <[email protected]> + +Description +----------- + +The TMP103 is a digital output temperature sensor in a four-ball +wafer chip-scale package (WCSP). The TMP103 is capable of reading +temperatures to a resolution of 1°C. The TMP103 is specified for +operation over a temperature range of –40°C to +125°C. + +Resolution: 8 Bits +Accuracy: ±1°C Typ (–10°C to +100°C) + +The driver provides the common sysfs-interface for temperatures (see +Documentation/hwmon/sysfs-interface under Temperatures). + +Please refer how to instantiate this driver: +Documentation/i2c/instantiating-devices
drivers/hwmon/Kconfig +10 -0
@@ -1391,6 +1391,16 @@ config SENSORS_TMP102 This driver can also be built as a module. If so, the module will be called tmp102. +config SENSORS_TMP103 + tristate "Texas Instruments TMP103" + depends on I2C + help + If you say yes here you get support for Texas Instruments TMP103 + sensor chips. + + This driver can also be built as a module. If so, the module + will be called tmp103. + config SENSORS_TMP401 tristate "Texas Instruments TMP401 and compatibles" depends on I2C
drivers/hwmon/Makefile +1 -0
@@ -135,6 +135,7 @@ obj-$(CONFIG_SENSORS_SMSC47M192)+= smsc47m192.o obj-$(CONFIG_SENSORS_AMC6821) += amc6821.o obj-$(CONFIG_SENSORS_THMC50) += thmc50.o obj-$(CONFIG_SENSORS_TMP102) += tmp102.o +obj-$(CONFIG_SENSORS_TMP103) += tmp103.o obj-$(CONFIG_SENSORS_TMP401) += tmp401.o obj-$(CONFIG_SENSORS_TMP421) += tmp421.o obj-$(CONFIG_SENSORS_TWL4030_MADC)+= twl4030-madc-hwmon.o
drivers/hwmon/tmp103.c new file +203 -0
203 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Guenter Roeck
maintainerQuoted 7 lines · Heiko Schocher
Driver for the TI TMP103.
The TI TMP103 is similar to the TMP102. It differs from the TMP102 by having only 8 bit registers.
Signed-off-by Heiko Schocher <[email protected]>
Hello Heiko,
Almost there.
Quoted 15 lines
---
drivers/hwmon/tmp103.c new file +13
-0+static int tmp103_probe (struct i2c_client *client, +const struct i2c_device_id *id) +{ +struct device *dev = &client->dev; +struct device *hwmon_dev; +struct regmap *regmap; +int ret; + +if (!i2c_check_functionality (client->adapter, +I2C_FUNC_SMBUS_BYTE_DATA )) { +dev_err (&client->dev, +"adapter doesn't support SMBus byte transactions\n" ); +return -ENODEV ;
drivers/hwmon/tmp103.c line 147
Quoted 10 lines
drivers/hwmon/tmp103.c new file +10
-0+ } + + regmap =devm_regmap_init_i2c (client, &tmp103_regmap_config); +if (IS_ERR (regmap)) { +dev_err (dev,"failed to allocate register map\n" ); +return PTR_ERR (regmap); + } + + ret =regmap_update_bits (regmap,TMP103_CONF_REG ,TMP103_CONFIG , +TMP103_CONFIG );
You actually want to mask out CR0, CR1, M0, and M1 here.
Quoted 14 lines
drivers/hwmon/tmp103.c new file +14
-0+if (ret <0 ) { +dev_err (&client->dev,"error writing config register\n" ); +return ret; + } + + hwmon_dev =hwmon_device_register_with_groups (dev, client->name, + regmap, tmp103_groups); +return PTR_ERR_OR_ZERO (hwmon_dev); +} + +#ifdef CONFIG_PM +static int tmp103_suspend (struct device *dev) +{ +struct regmap *regmap =dev_get_drvdata (dev);
drivers/hwmon/tmp103.c line 171
Quoted 10 lines
drivers/hwmon/tmp103.c new file +10
-0+ +return regmap_update_bits (regmap,TMP103_CONF_REG ,TMP103_CONF_SD ,0 ); +} + +static int tmp103_resume (struct device *dev) +{ +struct regmap *regmap =dev_get_drvdata (dev); + +return regmap_update_bits (regmap,TMP103_CONF_REG ,TMP103_CONF_SD , +TMP103_CONF_SD );
That changes {M0, M1} to {1, 1}, but you really want {0, 1} to restore the pre-suspend configuration.
One solution for both would be to define TMP103_CONFIG_MASK and TMP103_CONF_SD_MASK separately to ensure you catch all the to-be-cleared bits.
Guenter