Skip to content

Commit

Permalink
Merge tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/ker…
Browse files Browse the repository at this point in the history
…nel/git/groeck/linux-staging

Pull hwmon updates from Guenter Roeck:
 - new driver for Sensirion SHTC1 humidity / temperature sensor
 - convert ltc4151 and vexpress drivers to use devm functions
 - drop generic chip detection from lm85 driver
 - avoid forward declarations in atxp1 driver
 - fix sign extensions in ina2xx driver

* tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging:
  hwmon: vexpress: Use devm helper for hwmon device registration
  hwmon: (atxp1) Avoid forward declaration
  hwmon: add support for Sensirion SHTC1 sensor
  hwmon: (ltc4151) Convert to devm_hwmon_device_register_with_groups
  hwmon: (lm85) Drop generic detection
  hwmon: (ina2xx) Cast to s16 on shunt and current regs
  • Loading branch information
torvalds committed Jun 14, 2014
2 parents 6391f34 + 78cebd0 commit 503698e
Show file tree
Hide file tree
Showing 10 changed files with 401 additions and 142 deletions.
43 changes: 43 additions & 0 deletions Documentation/hwmon/shtc1
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Kernel driver shtc1
===================

Supported chips:
* Sensirion SHTC1
Prefix: 'shtc1'
Addresses scanned: none
Datasheet: http://www.sensirion.com/file/datasheet_shtc1

* Sensirion SHTW1
Prefix: 'shtw1'
Addresses scanned: none
Datasheet: Not publicly available

Author:
Johannes Winkelmann <[email protected]>

Description
-----------

This driver implements support for the Sensirion SHTC1 chip, a humidity and
temperature sensor. Temperature is measured in degrees celsius, relative
humidity is expressed as a percentage. Driver can be used as well for SHTW1
chip, which has the same electrical interface.

The device communicates with the I2C protocol. All sensors are set to I2C
address 0x70. See Documentation/i2c/instantiating-devices for methods to
instantiate the device.

There are two options configurable by means of shtc1_platform_data:
1. blocking (pull the I2C clock line down while performing the measurement) or
non-blocking mode. Blocking mode will guarantee the fastest result but
the I2C bus will be busy during that time. By default, non-blocking mode
is used. Make sure clock-stretching works properly on your device if you
want to use blocking mode.
2. high or low accuracy. High accuracy is used by default and using it is
strongly recommended.

sysfs-Interface
---------------

temp1_input - temperature input
humidity1_input - humidity input
10 changes: 10 additions & 0 deletions drivers/hwmon/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,16 @@ config SENSORS_SHT21
This driver can also be built as a module. If so, the module
will be called sht21.

config SENSORS_SHTC1
tristate "Sensiron humidity and temperature sensors. SHTC1 and compat."
depends on I2C
help
If you say yes here you get support for the Sensiron SHTC1 and SHTW1
humidity and temperature sensors.

This driver can also be built as a module. If so, the module
will be called shtc1.

config SENSORS_S3C
tristate "Samsung built-in ADC"
depends on S3C_ADC
Expand Down
1 change: 1 addition & 0 deletions drivers/hwmon/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ obj-$(CONFIG_SENSORS_SCH5627) += sch5627.o
obj-$(CONFIG_SENSORS_SCH5636) += sch5636.o
obj-$(CONFIG_SENSORS_SHT15) += sht15.o
obj-$(CONFIG_SENSORS_SHT21) += sht21.o
obj-$(CONFIG_SENSORS_SHTC1) += shtc1.o
obj-$(CONFIG_SENSORS_SIS5595) += sis5595.o
obj-$(CONFIG_SENSORS_SMM665) += smm665.o
obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.o
Expand Down
42 changes: 18 additions & 24 deletions drivers/hwmon/atxp1.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,6 @@ MODULE_AUTHOR("Sebastian Witt <[email protected]>");

static const unsigned short normal_i2c[] = { 0x37, 0x4e, I2C_CLIENT_END };

static int atxp1_probe(struct i2c_client *client,
const struct i2c_device_id *id);
static int atxp1_remove(struct i2c_client *client);
static struct atxp1_data *atxp1_update_device(struct device *dev);
static int atxp1_detect(struct i2c_client *client, struct i2c_board_info *info);

static const struct i2c_device_id atxp1_id[] = {
{ "atxp1", 0 },
{ }
};
MODULE_DEVICE_TABLE(i2c, atxp1_id);

static struct i2c_driver atxp1_driver = {
.class = I2C_CLASS_HWMON,
.driver = {
.name = "atxp1",
},
.probe = atxp1_probe,
.remove = atxp1_remove,
.id_table = atxp1_id,
.detect = atxp1_detect,
.address_list = normal_i2c,
};

struct atxp1_data {
struct device *hwmon_dev;
struct mutex update_lock;
Expand Down Expand Up @@ -386,4 +362,22 @@ static int atxp1_remove(struct i2c_client *client)
return 0;
};

static const struct i2c_device_id atxp1_id[] = {
{ "atxp1", 0 },
{ }
};
MODULE_DEVICE_TABLE(i2c, atxp1_id);

static struct i2c_driver atxp1_driver = {
.class = I2C_CLASS_HWMON,
.driver = {
.name = "atxp1",
},
.probe = atxp1_probe,
.remove = atxp1_remove,
.id_table = atxp1_id,
.detect = atxp1_detect,
.address_list = normal_i2c,
};

module_i2c_driver(atxp1_driver);
7 changes: 4 additions & 3 deletions drivers/hwmon/ina2xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ static int ina2xx_get_value(struct ina2xx_data *data, u8 reg)

switch (reg) {
case INA2XX_SHUNT_VOLTAGE:
val = DIV_ROUND_CLOSEST(data->regs[reg],
/* signed register */
val = DIV_ROUND_CLOSEST((s16)data->regs[reg],
data->config->shunt_div);
break;
case INA2XX_BUS_VOLTAGE:
Expand All @@ -160,8 +161,8 @@ static int ina2xx_get_value(struct ina2xx_data *data, u8 reg)
val = data->regs[reg] * data->config->power_lsb;
break;
case INA2XX_CURRENT:
/* LSB=1mA (selected). Is in mA */
val = data->regs[reg];
/* signed register, LSB=1mA (selected), in mA */
val = (s16)data->regs[reg];
break;
default:
/* programmer goofed */
Expand Down
33 changes: 10 additions & 23 deletions drivers/hwmon/lm85.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Copyright (c) 2002, 2003 Philip Pokorny <[email protected]>
* Copyright (c) 2003 Margit Schubert-While <[email protected]>
* Copyright (c) 2004 Justin Thiessen <[email protected]>
* Copyright (C) 2007--2009 Jean Delvare <[email protected]>
* Copyright (C) 2007--2014 Jean Delvare <[email protected]>
*
* Chip details at <http://www.national.com/ds/LM/LM85.pdf>
*
Expand Down Expand Up @@ -39,7 +39,7 @@
static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };

enum chips {
any_chip, lm85b, lm85c,
lm85,
adm1027, adt7463, adt7468,
emc6d100, emc6d102, emc6d103, emc6d103s
};
Expand Down Expand Up @@ -75,9 +75,6 @@ enum chips {
#define LM85_COMPANY_NATIONAL 0x01
#define LM85_COMPANY_ANALOG_DEV 0x41
#define LM85_COMPANY_SMSC 0x5c
#define LM85_VERSTEP_VMASK 0xf0
#define LM85_VERSTEP_GENERIC 0x60
#define LM85_VERSTEP_GENERIC2 0x70
#define LM85_VERSTEP_LM85C 0x60
#define LM85_VERSTEP_LM85B 0x62
#define LM85_VERSTEP_LM96000_1 0x68
Expand Down Expand Up @@ -351,9 +348,9 @@ static const struct i2c_device_id lm85_id[] = {
{ "adm1027", adm1027 },
{ "adt7463", adt7463 },
{ "adt7468", adt7468 },
{ "lm85", any_chip },
{ "lm85b", lm85b },
{ "lm85c", lm85c },
{ "lm85", lm85 },
{ "lm85b", lm85 },
{ "lm85c", lm85 },
{ "emc6d100", emc6d100 },
{ "emc6d101", emc6d100 },
{ "emc6d102", emc6d102 },
Expand Down Expand Up @@ -1281,7 +1278,7 @@ static int lm85_detect(struct i2c_client *client, struct i2c_board_info *info)
{
struct i2c_adapter *adapter = client->adapter;
int address = client->addr;
const char *type_name;
const char *type_name = NULL;
int company, verstep;

if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
Expand All @@ -1297,16 +1294,6 @@ static int lm85_detect(struct i2c_client *client, struct i2c_board_info *info)
"Detecting device at 0x%02x with COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
address, company, verstep);

/* All supported chips have the version in common */
if ((verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC &&
(verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC2) {
dev_dbg(&adapter->dev,
"Autodetection failed: unsupported version\n");
return -ENODEV;
}
type_name = "lm85";

/* Now, refine the detection */
if (company == LM85_COMPANY_NATIONAL) {
switch (verstep) {
case LM85_VERSTEP_LM85C:
Expand All @@ -1323,6 +1310,7 @@ static int lm85_detect(struct i2c_client *client, struct i2c_board_info *info)
"Found Winbond WPCD377I, ignoring\n");
return -ENODEV;
}
type_name = "lm85";
break;
}
} else if (company == LM85_COMPANY_ANALOG_DEV) {
Expand Down Expand Up @@ -1357,12 +1345,11 @@ static int lm85_detect(struct i2c_client *client, struct i2c_board_info *info)
type_name = "emc6d103s";
break;
}
} else {
dev_dbg(&adapter->dev,
"Autodetection failed: unknown vendor\n");
return -ENODEV;
}

if (!type_name)
return -ENODEV;

strlcpy(info->type, type_name, I2C_NAME_SIZE);

return 0;
Expand Down
51 changes: 13 additions & 38 deletions drivers/hwmon/ltc4151.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#define LTC4151_ADIN_L 0x05

struct ltc4151_data {
struct device *hwmon_dev;
struct i2c_client *client;

struct mutex update_lock;
bool valid;
Expand All @@ -59,8 +59,8 @@ struct ltc4151_data {

static struct ltc4151_data *ltc4151_update_device(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
struct ltc4151_data *data = i2c_get_clientdata(client);
struct ltc4151_data *data = dev_get_drvdata(dev);
struct i2c_client *client = data->client;
struct ltc4151_data *ret = data;

mutex_lock(&data->update_lock);
Expand Down Expand Up @@ -159,62 +159,38 @@ static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, ltc4151_show_value, NULL,
* Finally, construct an array of pointers to members of the above objects,
* as required for sysfs_create_group()
*/
static struct attribute *ltc4151_attributes[] = {
static struct attribute *ltc4151_attrs[] = {
&sensor_dev_attr_in1_input.dev_attr.attr,
&sensor_dev_attr_in2_input.dev_attr.attr,

&sensor_dev_attr_curr1_input.dev_attr.attr,

NULL,
};

static const struct attribute_group ltc4151_group = {
.attrs = ltc4151_attributes,
};
ATTRIBUTE_GROUPS(ltc4151);

static int ltc4151_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct i2c_adapter *adapter = client->adapter;
struct device *dev = &client->dev;
struct ltc4151_data *data;
int ret;
struct device *hwmon_dev;

if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
return -ENODEV;

data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;

i2c_set_clientdata(client, data);
data->client = client;
mutex_init(&data->update_lock);

/* Register sysfs hooks */
ret = sysfs_create_group(&client->dev.kobj, &ltc4151_group);
if (ret)
return ret;

data->hwmon_dev = hwmon_device_register(&client->dev);
if (IS_ERR(data->hwmon_dev)) {
ret = PTR_ERR(data->hwmon_dev);
goto out_hwmon_device_register;
}

return 0;

out_hwmon_device_register:
sysfs_remove_group(&client->dev.kobj, &ltc4151_group);
return ret;
}

static int ltc4151_remove(struct i2c_client *client)
{
struct ltc4151_data *data = i2c_get_clientdata(client);

hwmon_device_unregister(data->hwmon_dev);
sysfs_remove_group(&client->dev.kobj, &ltc4151_group);

return 0;
hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
data,
ltc4151_groups);
return PTR_ERR_OR_ZERO(hwmon_dev);
}

static const struct i2c_device_id ltc4151_id[] = {
Expand All @@ -229,7 +205,6 @@ static struct i2c_driver ltc4151_driver = {
.name = "ltc4151",
},
.probe = ltc4151_probe,
.remove = ltc4151_remove,
.id_table = ltc4151_id,
};

Expand Down
Loading

0 comments on commit 503698e

Please sign in to comment.