From 60c1f31fc5dfdbef388f47739e14c3cd85ad17e2 Mon Sep 17 00:00:00 2001 From: Evgeniy Dushistov Date: Thu, 1 Aug 2013 23:23:48 +0400 Subject: hwmon: (ads1015) Add support for ADS1115 This patch adds support for ads1115 device to ads1015 driver. Based on work of Emiliano Carnati . Tested on ARM CPU based board. Signed-off-by: Evgeniy A. Dushistov Signed-off-by: Guenter Roeck --- Documentation/hwmon/ads1015 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'Documentation') diff --git a/Documentation/hwmon/ads1015 b/Documentation/hwmon/ads1015 index f6fe9c203733..063b80d857b1 100644 --- a/Documentation/hwmon/ads1015 +++ b/Documentation/hwmon/ads1015 @@ -6,6 +6,10 @@ Supported chips: Prefix: 'ads1015' Datasheet: Publicly available at the Texas Instruments website : http://focus.ti.com/lit/ds/symlink/ads1015.pdf + * Texas Instruments ADS1115 + Prefix: 'ads1115' + Datasheet: Publicly available at the Texas Instruments website : + http://focus.ti.com/lit/ds/symlink/ads1115.pdf Authors: Dirk Eibach, Guntermann & Drunck GmbH @@ -13,9 +17,9 @@ Authors: Description ----------- -This driver implements support for the Texas Instruments ADS1015. +This driver implements support for the Texas Instruments ADS1015/ADS1115. -This device is a 12-bit A-D converter with 4 inputs. +This device is a 12/16-bit A-D converter with 4 inputs. The inputs can be used single ended or in certain differential combinations. -- cgit v1.2.3 From 30b146d1cb5e7560192057098eb705118bd5511f Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Fri, 23 Aug 2013 13:14:03 -0700 Subject: hwmon: (k10temp) Add support for Fam16h (Kabini) The temperature reporting interface stays the same, so we just add the PCI-ID to the list. Verified on AMD Olive Hill. Signed-off-by: Wei Hu Acked-by: Clemens Ladisch Cc: stable@vger.kernel.org # 3.10+ Signed-off-by: Guenter Roeck --- Documentation/hwmon/k10temp | 1 + drivers/hwmon/Kconfig | 4 ++-- drivers/hwmon/k10temp.c | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) (limited to 'Documentation') diff --git a/Documentation/hwmon/k10temp b/Documentation/hwmon/k10temp index 90956b618025..4dfdc8f83633 100644 --- a/Documentation/hwmon/k10temp +++ b/Documentation/hwmon/k10temp @@ -12,6 +12,7 @@ Supported chips: * AMD Family 12h processors: "Llano" (E2/A4/A6/A8-Series) * AMD Family 14h processors: "Brazos" (C/E/G/Z-Series) * AMD Family 15h processors: "Bulldozer" (FX-Series), "Trinity" +* AMD Family 16h processors: "Kabini" Prefix: 'k10temp' Addresses scanned: PCI space diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 47b3e5821cb8..0ff09d8d987b 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -296,8 +296,8 @@ config SENSORS_K10TEMP If you say yes here you get support for the temperature sensor(s) inside your CPU. Supported are later revisions of the AMD Family 10h and all revisions of the AMD Family 11h, - 12h (Llano), 14h (Brazos) and 15h (Bulldozer/Trinity) - microarchitectures. + 12h (Llano), 14h (Brazos), 15h (Bulldozer/Trinity) and + 16h (Kabini) microarchitectures. This driver can also be built as a module. If so, the module will be called k10temp. diff --git a/drivers/hwmon/k10temp.c b/drivers/hwmon/k10temp.c index e3b037c73a7e..e633856370cf 100644 --- a/drivers/hwmon/k10temp.c +++ b/drivers/hwmon/k10temp.c @@ -1,5 +1,5 @@ /* - * k10temp.c - AMD Family 10h/11h/12h/14h/15h processor hardware monitoring + * k10temp.c - AMD Family 10h/11h/12h/14h/15h/16h processor hardware monitoring * * Copyright (c) 2009 Clemens Ladisch * @@ -211,6 +211,7 @@ static DEFINE_PCI_DEVICE_TABLE(k10temp_id_table) = { { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_CNB17H_F3) }, { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_NB_F3) }, { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_M10H_F3) }, + { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_16H_NB_F3) }, {} }; MODULE_DEVICE_TABLE(pci, k10temp_id_table); -- cgit v1.2.3 From f060c658b820141f18abd7b71586d628464a03ea Mon Sep 17 00:00:00 2001 From: William Markezana Date: Thu, 29 Aug 2013 13:51:42 +0200 Subject: hwmon: (htu21) Add Measurement Specialties HTU21D support Signed-off-by: William Markezana [Guenter Roeck - minor formatting changes] Signed-off-by: Guenter Roeck --- Documentation/hwmon/htu21 | 46 +++++++++++ drivers/hwmon/Kconfig | 10 +++ drivers/hwmon/Makefile | 1 + drivers/hwmon/htu21.c | 199 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 256 insertions(+) create mode 100644 Documentation/hwmon/htu21 create mode 100644 drivers/hwmon/htu21.c (limited to 'Documentation') diff --git a/Documentation/hwmon/htu21 b/Documentation/hwmon/htu21 new file mode 100644 index 000000000000..f39a215fb6ae --- /dev/null +++ b/Documentation/hwmon/htu21 @@ -0,0 +1,46 @@ +Kernel driver htu21 +=================== + +Supported chips: + * Measurement Specialties HTU21D + Prefix: 'htu21' + Addresses scanned: none + Datasheet: Publicly available at the Measurement Specialties website + http://www.meas-spec.com/downloads/HTU21D.pdf + + +Author: + William Markezana + +Description +----------- + +The HTU21D is a humidity and temperature sensor in a DFN package of +only 3 x 3 mm footprint and 0.9 mm height. + +The devices communicate with the I2C protocol. All sensors are set to the +same I2C address 0x40, so an entry with I2C_BOARD_INFO("htu21", 0x40) can +be used in the board setup code. + +This driver does not auto-detect devices. You will have to instantiate the +devices explicitly. Please see Documentation/i2c/instantiating-devices +for details. + +sysfs-Interface +--------------- + +temp1_input - temperature input +humidity1_input - humidity input + +Notes +----- + +The driver uses the default resolution settings of 12 bit for humidity and 14 +bit for temperature, which results in typical measurement times of 11 ms for +humidity and 44 ms for temperature. To keep self heating below 0.1 degree +Celsius, the device should not be active for more than 10% of the time. For +this reason, the driver performs no more than two measurements per second and +reports cached information if polled more frequently. + +Different resolutions, the on-chip heater, using the CRC checksum and reading +the serial number are not supported yet. diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 0ff09d8d987b..b3ab9d43bb3e 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -511,6 +511,16 @@ config SENSORS_HIH6130 This driver can also be built as a module. If so, the module will be called hih6130. +config SENSORS_HTU21 + tristate "Measurement Specialties HTU21D humidity/temperature sensors" + depends on I2C + help + If you say yes here you get support for the Measurement Specialties + HTU21D humidity and temperature sensors. + + This driver can also be built as a module. If so, the module + will be called htu21. + config SENSORS_CORETEMP tristate "Intel Core/Core2/Atom temperature sensor" depends on X86 diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index 4f0fb5235f42..ec7cde06eb52 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile @@ -65,6 +65,7 @@ obj-$(CONFIG_SENSORS_GL518SM) += gl518sm.o obj-$(CONFIG_SENSORS_GL520SM) += gl520sm.o obj-$(CONFIG_SENSORS_GPIO_FAN) += gpio-fan.o obj-$(CONFIG_SENSORS_HIH6130) += hih6130.o +obj-$(CONFIG_SENSORS_HTU21) += htu21.o obj-$(CONFIG_SENSORS_ULTRA45) += ultra45_env.o obj-$(CONFIG_SENSORS_I5K_AMB) += i5k_amb.o obj-$(CONFIG_SENSORS_IBMAEM) += ibmaem.o diff --git a/drivers/hwmon/htu21.c b/drivers/hwmon/htu21.c new file mode 100644 index 000000000000..839086e0e951 --- /dev/null +++ b/drivers/hwmon/htu21.c @@ -0,0 +1,199 @@ +/* + * Measurement Specialties HTU21D humidity and temperature sensor driver + * + * Copyright (C) 2013 William Markezana + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * 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. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* HTU21 Commands */ +#define HTU21_T_MEASUREMENT_HM 0xE3 +#define HTU21_RH_MEASUREMENT_HM 0xE5 + +struct htu21 { + struct device *hwmon_dev; + struct mutex lock; + bool valid; + unsigned long last_update; + int temperature; + int humidity; +}; + +static inline int htu21_temp_ticks_to_millicelsius(int ticks) +{ + ticks &= ~0x0003; /* clear status bits */ + /* + * Formula T = -46.85 + 175.72 * ST / 2^16 from datasheet p14, + * optimized for integer fixed point (3 digits) arithmetic + */ + return ((21965 * ticks) >> 13) - 46850; +} + +static inline int htu21_rh_ticks_to_per_cent_mille(int ticks) +{ + ticks &= ~0x0003; /* clear status bits */ + /* + * Formula RH = -6 + 125 * SRH / 2^16 from datasheet p14, + * optimized for integer fixed point (3 digits) arithmetic + */ + return ((15625 * ticks) >> 13) - 6000; +} + +static int htu21_update_measurements(struct i2c_client *client) +{ + int ret = 0; + struct htu21 *htu21 = i2c_get_clientdata(client); + + mutex_lock(&htu21->lock); + + if (time_after(jiffies, htu21->last_update + HZ / 2) || + !htu21->valid) { + ret = i2c_smbus_read_word_swapped(client, + HTU21_T_MEASUREMENT_HM); + if (ret < 0) + goto out; + htu21->temperature = htu21_temp_ticks_to_millicelsius(ret); + ret = i2c_smbus_read_word_swapped(client, + HTU21_RH_MEASUREMENT_HM); + if (ret < 0) + goto out; + htu21->humidity = htu21_rh_ticks_to_per_cent_mille(ret); + htu21->last_update = jiffies; + htu21->valid = true; + } +out: + mutex_unlock(&htu21->lock); + + return ret >= 0 ? 0 : ret; +} + +static ssize_t htu21_show_temperature(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct i2c_client *client = to_i2c_client(dev); + struct htu21 *htu21 = i2c_get_clientdata(client); + int ret = htu21_update_measurements(client); + if (ret < 0) + return ret; + return sprintf(buf, "%d\n", htu21->temperature); +} + +static ssize_t htu21_show_humidity(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct i2c_client *client = to_i2c_client(dev); + struct htu21 *htu21 = i2c_get_clientdata(client); + int ret = htu21_update_measurements(client); + if (ret < 0) + return ret; + return sprintf(buf, "%d\n", htu21->humidity); +} + +static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, + htu21_show_temperature, NULL, 0); +static SENSOR_DEVICE_ATTR(humidity1_input, S_IRUGO, + htu21_show_humidity, NULL, 0); + +static struct attribute *htu21_attributes[] = { + &sensor_dev_attr_temp1_input.dev_attr.attr, + &sensor_dev_attr_humidity1_input.dev_attr.attr, + NULL +}; + +static const struct attribute_group htu21_group = { + .attrs = htu21_attributes, +}; + +static int htu21_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct htu21 *htu21; + int err; + + if (!i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_READ_WORD_DATA)) { + dev_err(&client->dev, + "adapter does not support SMBus word transactions\n"); + return -ENODEV; + } + + htu21 = devm_kzalloc(&client->dev, sizeof(*htu21), GFP_KERNEL); + if (!htu21) + return -ENOMEM; + + i2c_set_clientdata(client, htu21); + + mutex_init(&htu21->lock); + + err = sysfs_create_group(&client->dev.kobj, &htu21_group); + if (err) { + dev_dbg(&client->dev, "could not create sysfs files\n"); + return err; + } + htu21->hwmon_dev = hwmon_device_register(&client->dev); + if (IS_ERR(htu21->hwmon_dev)) { + dev_dbg(&client->dev, "unable to register hwmon device\n"); + err = PTR_ERR(htu21->hwmon_dev); + goto error; + } + + dev_info(&client->dev, "initialized\n"); + + return 0; + +error: + sysfs_remove_group(&client->dev.kobj, &htu21_group); + return err; +} + +static int htu21_remove(struct i2c_client *client) +{ + struct htu21 *htu21 = i2c_get_clientdata(client); + + hwmon_device_unregister(htu21->hwmon_dev); + sysfs_remove_group(&client->dev.kobj, &htu21_group); + + return 0; +} + +static const struct i2c_device_id htu21_id[] = { + { "htu21", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, htu21_id); + +static struct i2c_driver htu21_driver = { + .class = I2C_CLASS_HWMON, + .driver = { + .name = "htu21", + }, + .probe = htu21_probe, + .remove = htu21_remove, + .id_table = htu21_id, +}; + +module_i2c_driver(htu21_driver); + +MODULE_AUTHOR("William Markezana "); +MODULE_DESCRIPTION("MEAS HTU21D humidity and temperature sensor driver"); +MODULE_LICENSE("GPL"); -- cgit v1.2.3