From a63ee9d83b960199ae111ff4e2413fbe328d32fe Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Tue, 22 Apr 2014 16:13:17 -0700 Subject: hwmon: (tmp421) Strengthen detect function Not all supported chips support the entire I2C address range. Only accept specific chips at the addresses supported by that chip. Check for invalid values in conversion rate and status registers. Signed-off-by: Guenter Roeck Reviewed-by: Jean Delvare --- drivers/hwmon/tmp421.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'drivers/hwmon/tmp421.c') diff --git a/drivers/hwmon/tmp421.c b/drivers/hwmon/tmp421.c index 7bab7a9bedc..9438c1bd5d5 100644 --- a/drivers/hwmon/tmp421.c +++ b/drivers/hwmon/tmp421.c @@ -42,6 +42,7 @@ static const unsigned short normal_i2c[] = { 0x2a, 0x4c, 0x4d, 0x4e, 0x4f, enum chips { tmp421, tmp422, tmp423 }; /* The TMP421 registers */ +#define TMP421_STATUS_REG 0x08 #define TMP421_CONFIG_REG_1 0x09 #define TMP421_CONVERSION_RATE_REG 0x0B #define TMP421_MANUFACTURER_ID_REG 0xFE @@ -235,6 +236,7 @@ static int tmp421_detect(struct i2c_client *client, enum chips kind; struct i2c_adapter *adapter = client->adapter; const char *names[] = { "TMP421", "TMP422", "TMP423" }; + int addr = client->addr; u8 reg; if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) @@ -244,15 +246,27 @@ static int tmp421_detect(struct i2c_client *client, if (reg != TMP421_MANUFACTURER_ID) return -ENODEV; + reg = i2c_smbus_read_byte_data(client, TMP421_CONVERSION_RATE_REG); + if (reg & 0xf8) + return -ENODEV; + + reg = i2c_smbus_read_byte_data(client, TMP421_STATUS_REG); + if (reg & 0x7f) + return -ENODEV; + reg = i2c_smbus_read_byte_data(client, TMP421_DEVICE_ID_REG); switch (reg) { case TMP421_DEVICE_ID: kind = tmp421; break; case TMP422_DEVICE_ID: + if (addr == 0x2a) + return -ENODEV; kind = tmp422; break; case TMP423_DEVICE_ID: + if (addr != 0x4c && addr != 0x4d) + return -ENODEV; kind = tmp423; break; default: -- cgit v1.2.3-70-g09d2 From 05c77ab240fdcba3886913235e37b43e3223e9ee Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Sat, 12 Apr 2014 16:12:06 -0700 Subject: hwmon: (tmp421) Add support for TMP441 and TMP442 TMP441 and TMP442 are compatible to TMP421 and TMP422. Signed-off-by: Guenter Roeck Reviewed-by: Jean Delvare --- Documentation/hwmon/tmp421 | 22 +++++++++++++++------- drivers/hwmon/Kconfig | 2 +- drivers/hwmon/tmp421.c | 21 +++++++++++++++++---- 3 files changed, 33 insertions(+), 12 deletions(-) (limited to 'drivers/hwmon/tmp421.c') diff --git a/Documentation/hwmon/tmp421 b/Documentation/hwmon/tmp421 index d0e77143077..9e6fe5549ca 100644 --- a/Documentation/hwmon/tmp421 +++ b/Documentation/hwmon/tmp421 @@ -14,6 +14,14 @@ Supported chips: Prefix: 'tmp423' Addresses scanned: I2C 0x4c and 0x4d Datasheet: http://focus.ti.com/docs/prod/folders/print/tmp421.html + * Texas Instruments TMP441 + Prefix: 'tmp441' + Addresses scanned: I2C 0x2a, 0x4c, 0x4d, 0x4e and 0x4f + Datasheet: http://www.ti.com/product/tmp441 + * Texas Instruments TMP442 + Prefix: 'tmp442' + Addresses scanned: I2C 0x4c and 0x4d + Datasheet: http://www.ti.com/product/tmp442 Authors: Andre Prendel @@ -21,13 +29,13 @@ Authors: Description ----------- -This driver implements support for Texas Instruments TMP421, TMP422 -and TMP423 temperature sensor chips. These chips implement one local -and up to one (TMP421), up to two (TMP422) or up to three (TMP423) -remote sensors. Temperature is measured in degrees Celsius. The chips -are wired over I2C/SMBus and specified over a temperature range of -40 -to +125 degrees Celsius. Resolution for both the local and remote -channels is 0.0625 degree C. +This driver implements support for Texas Instruments TMP421, TMP422, +TMP423, TMP441, and TMP442 temperature sensor chips. These chips +implement one local and up to one (TMP421, TMP441), up to two (TMP422, +TMP442) or up to three (TMP423) remote sensors. Temperature is measured +in degrees Celsius. The chips are wired over I2C/SMBus and specified +over a temperature range of -40 to +125 degrees Celsius. Resolution +for both the local and remote channels is 0.0625 degree C. The chips support only temperature measurement. The driver exports the temperature values via the following sysfs files: diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index ae1e2160c1b..37908ff8f7f 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -1431,7 +1431,7 @@ config SENSORS_TMP421 depends on I2C help If you say yes here you get support for Texas Instruments TMP421, - TMP422 and TMP423 temperature sensor chips. + TMP422, TMP423, TMP441, and TMP442 temperature sensor chips. This driver can also be built as a module. If so, the module will be called tmp421. diff --git a/drivers/hwmon/tmp421.c b/drivers/hwmon/tmp421.c index 9438c1bd5d5..2ae383f737b 100644 --- a/drivers/hwmon/tmp421.c +++ b/drivers/hwmon/tmp421.c @@ -21,7 +21,7 @@ /* * Driver for the Texas Instruments TMP421 SMBus temperature sensor IC. - * Supported models: TMP421, TMP422, TMP423 + * Supported models: TMP421, TMP422, TMP423, TMP441, TMP442 */ #include @@ -39,7 +39,7 @@ static const unsigned short normal_i2c[] = { 0x2a, 0x4c, 0x4d, 0x4e, 0x4f, I2C_CLIENT_END }; -enum chips { tmp421, tmp422, tmp423 }; +enum chips { tmp421, tmp422, tmp423, tmp441, tmp442 }; /* The TMP421 registers */ #define TMP421_STATUS_REG 0x08 @@ -60,11 +60,15 @@ static const u8 TMP421_TEMP_LSB[4] = { 0x10, 0x11, 0x12, 0x13 }; #define TMP421_DEVICE_ID 0x21 #define TMP422_DEVICE_ID 0x22 #define TMP423_DEVICE_ID 0x23 +#define TMP441_DEVICE_ID 0x41 +#define TMP442_DEVICE_ID 0x42 static const struct i2c_device_id tmp421_id[] = { { "tmp421", 2 }, { "tmp422", 3 }, { "tmp423", 4 }, + { "tmp441", 2 }, + { "tmp442", 3 }, { } }; MODULE_DEVICE_TABLE(i2c, tmp421_id); @@ -235,7 +239,8 @@ static int tmp421_detect(struct i2c_client *client, { enum chips kind; struct i2c_adapter *adapter = client->adapter; - const char *names[] = { "TMP421", "TMP422", "TMP423" }; + const char * const names[] = { "TMP421", "TMP422", "TMP423", + "TMP441", "TMP442" }; int addr = client->addr; u8 reg; @@ -269,6 +274,14 @@ static int tmp421_detect(struct i2c_client *client, return -ENODEV; kind = tmp423; break; + case TMP441_DEVICE_ID: + kind = tmp441; + break; + case TMP442_DEVICE_ID: + if (addr != 0x4c && addr != 0x4d) + return -ENODEV; + kind = tmp442; + break; default: return -ENODEV; } @@ -319,5 +332,5 @@ static struct i2c_driver tmp421_driver = { module_i2c_driver(tmp421_driver); MODULE_AUTHOR("Andre Prendel "); -MODULE_DESCRIPTION("Texas Instruments TMP421/422/423 temperature sensor driver"); +MODULE_DESCRIPTION("Texas Instruments TMP421/422/423/441/442 temperature sensor driver"); MODULE_LICENSE("GPL"); -- cgit v1.2.3-70-g09d2 From 012cb5e257dcce524ee6207e50ca494d8a2b6013 Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Tue, 22 Apr 2014 22:16:33 -0700 Subject: hwmon: (tmp421) Drop FSF mailing address The FSF mailing address can and will change over time, so drop it. Signed-off-by: Guenter Roeck Reviewed-by: Jean Delvare --- drivers/hwmon/tmp421.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'drivers/hwmon/tmp421.c') diff --git a/drivers/hwmon/tmp421.c b/drivers/hwmon/tmp421.c index 2ae383f737b..85d48d80822 100644 --- a/drivers/hwmon/tmp421.c +++ b/drivers/hwmon/tmp421.c @@ -13,10 +13,6 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* -- cgit v1.2.3-70-g09d2