Skip to content

Commit 503698e

Browse files
committed
Merge tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/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
2 parents 6391f34 + 78cebd0 commit 503698e

File tree

10 files changed

+401
-142
lines changed

10 files changed

+401
-142
lines changed

Documentation/hwmon/shtc1

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Kernel driver shtc1
2+
===================
3+
4+
Supported chips:
5+
* Sensirion SHTC1
6+
Prefix: 'shtc1'
7+
Addresses scanned: none
8+
Datasheet: http://www.sensirion.com/file/datasheet_shtc1
9+
10+
* Sensirion SHTW1
11+
Prefix: 'shtw1'
12+
Addresses scanned: none
13+
Datasheet: Not publicly available
14+
15+
Author:
16+
Johannes Winkelmann <johannes.winkelmann@sensirion.com>
17+
18+
Description
19+
-----------
20+
21+
This driver implements support for the Sensirion SHTC1 chip, a humidity and
22+
temperature sensor. Temperature is measured in degrees celsius, relative
23+
humidity is expressed as a percentage. Driver can be used as well for SHTW1
24+
chip, which has the same electrical interface.
25+
26+
The device communicates with the I2C protocol. All sensors are set to I2C
27+
address 0x70. See Documentation/i2c/instantiating-devices for methods to
28+
instantiate the device.
29+
30+
There are two options configurable by means of shtc1_platform_data:
31+
1. blocking (pull the I2C clock line down while performing the measurement) or
32+
non-blocking mode. Blocking mode will guarantee the fastest result but
33+
the I2C bus will be busy during that time. By default, non-blocking mode
34+
is used. Make sure clock-stretching works properly on your device if you
35+
want to use blocking mode.
36+
2. high or low accuracy. High accuracy is used by default and using it is
37+
strongly recommended.
38+
39+
sysfs-Interface
40+
---------------
41+
42+
temp1_input - temperature input
43+
humidity1_input - humidity input

drivers/hwmon/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,16 @@ config SENSORS_SHT21
11241124
This driver can also be built as a module. If so, the module
11251125
will be called sht21.
11261126

1127+
config SENSORS_SHTC1
1128+
tristate "Sensiron humidity and temperature sensors. SHTC1 and compat."
1129+
depends on I2C
1130+
help
1131+
If you say yes here you get support for the Sensiron SHTC1 and SHTW1
1132+
humidity and temperature sensors.
1133+
1134+
This driver can also be built as a module. If so, the module
1135+
will be called shtc1.
1136+
11271137
config SENSORS_S3C
11281138
tristate "Samsung built-in ADC"
11291139
depends on S3C_ADC

drivers/hwmon/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ obj-$(CONFIG_SENSORS_SCH5627) += sch5627.o
126126
obj-$(CONFIG_SENSORS_SCH5636) += sch5636.o
127127
obj-$(CONFIG_SENSORS_SHT15) += sht15.o
128128
obj-$(CONFIG_SENSORS_SHT21) += sht21.o
129+
obj-$(CONFIG_SENSORS_SHTC1) += shtc1.o
129130
obj-$(CONFIG_SENSORS_SIS5595) += sis5595.o
130131
obj-$(CONFIG_SENSORS_SMM665) += smm665.o
131132
obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.o

drivers/hwmon/atxp1.c

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,30 +45,6 @@ MODULE_AUTHOR("Sebastian Witt <se.witt@gmx.net>");
4545

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

48-
static int atxp1_probe(struct i2c_client *client,
49-
const struct i2c_device_id *id);
50-
static int atxp1_remove(struct i2c_client *client);
51-
static struct atxp1_data *atxp1_update_device(struct device *dev);
52-
static int atxp1_detect(struct i2c_client *client, struct i2c_board_info *info);
53-
54-
static const struct i2c_device_id atxp1_id[] = {
55-
{ "atxp1", 0 },
56-
{ }
57-
};
58-
MODULE_DEVICE_TABLE(i2c, atxp1_id);
59-
60-
static struct i2c_driver atxp1_driver = {
61-
.class = I2C_CLASS_HWMON,
62-
.driver = {
63-
.name = "atxp1",
64-
},
65-
.probe = atxp1_probe,
66-
.remove = atxp1_remove,
67-
.id_table = atxp1_id,
68-
.detect = atxp1_detect,
69-
.address_list = normal_i2c,
70-
};
71-
7248
struct atxp1_data {
7349
struct device *hwmon_dev;
7450
struct mutex update_lock;
@@ -386,4 +362,22 @@ static int atxp1_remove(struct i2c_client *client)
386362
return 0;
387363
};
388364

365+
static const struct i2c_device_id atxp1_id[] = {
366+
{ "atxp1", 0 },
367+
{ }
368+
};
369+
MODULE_DEVICE_TABLE(i2c, atxp1_id);
370+
371+
static struct i2c_driver atxp1_driver = {
372+
.class = I2C_CLASS_HWMON,
373+
.driver = {
374+
.name = "atxp1",
375+
},
376+
.probe = atxp1_probe,
377+
.remove = atxp1_remove,
378+
.id_table = atxp1_id,
379+
.detect = atxp1_detect,
380+
.address_list = normal_i2c,
381+
};
382+
389383
module_i2c_driver(atxp1_driver);

drivers/hwmon/ina2xx.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ static int ina2xx_get_value(struct ina2xx_data *data, u8 reg)
148148

149149
switch (reg) {
150150
case INA2XX_SHUNT_VOLTAGE:
151-
val = DIV_ROUND_CLOSEST(data->regs[reg],
151+
/* signed register */
152+
val = DIV_ROUND_CLOSEST((s16)data->regs[reg],
152153
data->config->shunt_div);
153154
break;
154155
case INA2XX_BUS_VOLTAGE:
@@ -160,8 +161,8 @@ static int ina2xx_get_value(struct ina2xx_data *data, u8 reg)
160161
val = data->regs[reg] * data->config->power_lsb;
161162
break;
162163
case INA2XX_CURRENT:
163-
/* LSB=1mA (selected). Is in mA */
164-
val = data->regs[reg];
164+
/* signed register, LSB=1mA (selected), in mA */
165+
val = (s16)data->regs[reg];
165166
break;
166167
default:
167168
/* programmer goofed */

drivers/hwmon/lm85.c

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
66
* Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de>
77
* Copyright (c) 2004 Justin Thiessen <jthiessen@penguincomputing.com>
8-
* Copyright (C) 2007--2009 Jean Delvare <jdelvare@suse.de>
8+
* Copyright (C) 2007--2014 Jean Delvare <jdelvare@suse.de>
99
*
1010
* Chip details at <http://www.national.com/ds/LM/LM85.pdf>
1111
*
@@ -39,7 +39,7 @@
3939
static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
4040

4141
enum chips {
42-
any_chip, lm85b, lm85c,
42+
lm85,
4343
adm1027, adt7463, adt7468,
4444
emc6d100, emc6d102, emc6d103, emc6d103s
4545
};
@@ -75,9 +75,6 @@ enum chips {
7575
#define LM85_COMPANY_NATIONAL 0x01
7676
#define LM85_COMPANY_ANALOG_DEV 0x41
7777
#define LM85_COMPANY_SMSC 0x5c
78-
#define LM85_VERSTEP_VMASK 0xf0
79-
#define LM85_VERSTEP_GENERIC 0x60
80-
#define LM85_VERSTEP_GENERIC2 0x70
8178
#define LM85_VERSTEP_LM85C 0x60
8279
#define LM85_VERSTEP_LM85B 0x62
8380
#define LM85_VERSTEP_LM96000_1 0x68
@@ -351,9 +348,9 @@ static const struct i2c_device_id lm85_id[] = {
351348
{ "adm1027", adm1027 },
352349
{ "adt7463", adt7463 },
353350
{ "adt7468", adt7468 },
354-
{ "lm85", any_chip },
355-
{ "lm85b", lm85b },
356-
{ "lm85c", lm85c },
351+
{ "lm85", lm85 },
352+
{ "lm85b", lm85 },
353+
{ "lm85c", lm85 },
357354
{ "emc6d100", emc6d100 },
358355
{ "emc6d101", emc6d100 },
359356
{ "emc6d102", emc6d102 },
@@ -1281,7 +1278,7 @@ static int lm85_detect(struct i2c_client *client, struct i2c_board_info *info)
12811278
{
12821279
struct i2c_adapter *adapter = client->adapter;
12831280
int address = client->addr;
1284-
const char *type_name;
1281+
const char *type_name = NULL;
12851282
int company, verstep;
12861283

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

1300-
/* All supported chips have the version in common */
1301-
if ((verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC &&
1302-
(verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC2) {
1303-
dev_dbg(&adapter->dev,
1304-
"Autodetection failed: unsupported version\n");
1305-
return -ENODEV;
1306-
}
1307-
type_name = "lm85";
1308-
1309-
/* Now, refine the detection */
13101297
if (company == LM85_COMPANY_NATIONAL) {
13111298
switch (verstep) {
13121299
case LM85_VERSTEP_LM85C:
@@ -1323,6 +1310,7 @@ static int lm85_detect(struct i2c_client *client, struct i2c_board_info *info)
13231310
"Found Winbond WPCD377I, ignoring\n");
13241311
return -ENODEV;
13251312
}
1313+
type_name = "lm85";
13261314
break;
13271315
}
13281316
} else if (company == LM85_COMPANY_ANALOG_DEV) {
@@ -1357,12 +1345,11 @@ static int lm85_detect(struct i2c_client *client, struct i2c_board_info *info)
13571345
type_name = "emc6d103s";
13581346
break;
13591347
}
1360-
} else {
1361-
dev_dbg(&adapter->dev,
1362-
"Autodetection failed: unknown vendor\n");
1363-
return -ENODEV;
13641348
}
13651349

1350+
if (!type_name)
1351+
return -ENODEV;
1352+
13661353
strlcpy(info->type, type_name, I2C_NAME_SIZE);
13671354

13681355
return 0;

drivers/hwmon/ltc4151.c

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
#define LTC4151_ADIN_L 0x05
4848

4949
struct ltc4151_data {
50-
struct device *hwmon_dev;
50+
struct i2c_client *client;
5151

5252
struct mutex update_lock;
5353
bool valid;
@@ -59,8 +59,8 @@ struct ltc4151_data {
5959

6060
static struct ltc4151_data *ltc4151_update_device(struct device *dev)
6161
{
62-
struct i2c_client *client = to_i2c_client(dev);
63-
struct ltc4151_data *data = i2c_get_clientdata(client);
62+
struct ltc4151_data *data = dev_get_drvdata(dev);
63+
struct i2c_client *client = data->client;
6464
struct ltc4151_data *ret = data;
6565

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

166166
&sensor_dev_attr_curr1_input.dev_attr.attr,
167167

168168
NULL,
169169
};
170-
171-
static const struct attribute_group ltc4151_group = {
172-
.attrs = ltc4151_attributes,
173-
};
170+
ATTRIBUTE_GROUPS(ltc4151);
174171

175172
static int ltc4151_probe(struct i2c_client *client,
176173
const struct i2c_device_id *id)
177174
{
178175
struct i2c_adapter *adapter = client->adapter;
176+
struct device *dev = &client->dev;
179177
struct ltc4151_data *data;
180-
int ret;
178+
struct device *hwmon_dev;
181179

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

185-
data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
183+
data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
186184
if (!data)
187185
return -ENOMEM;
188186

189-
i2c_set_clientdata(client, data);
187+
data->client = client;
190188
mutex_init(&data->update_lock);
191189

192-
/* Register sysfs hooks */
193-
ret = sysfs_create_group(&client->dev.kobj, &ltc4151_group);
194-
if (ret)
195-
return ret;
196-
197-
data->hwmon_dev = hwmon_device_register(&client->dev);
198-
if (IS_ERR(data->hwmon_dev)) {
199-
ret = PTR_ERR(data->hwmon_dev);
200-
goto out_hwmon_device_register;
201-
}
202-
203-
return 0;
204-
205-
out_hwmon_device_register:
206-
sysfs_remove_group(&client->dev.kobj, &ltc4151_group);
207-
return ret;
208-
}
209-
210-
static int ltc4151_remove(struct i2c_client *client)
211-
{
212-
struct ltc4151_data *data = i2c_get_clientdata(client);
213-
214-
hwmon_device_unregister(data->hwmon_dev);
215-
sysfs_remove_group(&client->dev.kobj, &ltc4151_group);
216-
217-
return 0;
190+
hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
191+
data,
192+
ltc4151_groups);
193+
return PTR_ERR_OR_ZERO(hwmon_dev);
218194
}
219195

220196
static const struct i2c_device_id ltc4151_id[] = {
@@ -229,7 +205,6 @@ static struct i2c_driver ltc4151_driver = {
229205
.name = "ltc4151",
230206
},
231207
.probe = ltc4151_probe,
232-
.remove = ltc4151_remove,
233208
.id_table = ltc4151_id,
234209
};
235210

0 commit comments

Comments
 (0)