Skip to content

Commit

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

Pull hwmon updates from Guenter Roeck:

 - new drivers for TMP108 and TC654

 - hwmon core code cleanup

 - coretemp driver cleanup

 - fix overflow issues in several drivers

 - minor fixes, cleanups and enhancements in various drivers

* tag 'hwmon-for-linus-v4.10' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging: (41 commits)
  hwmon: (g762) Fix overflows and crash seen when writing limit attributes
  hwmon: (emcw201) Fix overflows seen when writing into limit attributes
  hwmon: (emc2103) Fix overflows seen when temperature limit attributes
  hwmon: (lm85) Fix overflows seen when writing voltage limit attributes
  hwmon: (lm87) Fix overflow seen when writing voltage limit attributes
  hwmon: (nct7802) Fix overflows seen when writing into limit attributes
  hwmon: (adt7470) Fix overflows seen when writing into limit attributes
  hwmon: (adt7462) Fix overflows seen when writing into limit attributes
  hwmon: (adm1026) Fix overflows seen when writing into limit attributes
  hwmon: (adm1025) Fix overflows seen when writing voltage limits
  hwmon: (via-cputemp) Convert to hotplug state machine
  devicetree: hwmon: Add documentation for TMP108 driver.
  hwmon: Add Texas Instruments TMP108 temperature sensor driver.
  hwmon: (core) Simplify sysfs attribute name allocation
  hwmon: (core) Rename groups parameter in API to extra_groups
  hwmon: (core) Explain why at least two attribute groups are allocated
  hwmon: (core) Make is_visible callback truly mandatory
  hwmon: (core) Deprecate hwmon_device_register()
  hwmon: (core) Clarify use of chip attributes
  hwmon: (core) Add support for string attributes to new API
  ...
  • Loading branch information
torvalds committed Dec 13, 2016
2 parents bb3dd05 + 4fccd4a commit 1c59e1e
Show file tree
Hide file tree
Showing 32 changed files with 1,695 additions and 594 deletions.
21 changes: 21 additions & 0 deletions Documentation/devicetree/bindings/hwmon/mcp3021.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
mcp3021 properties

Required properties:
- compatible: Must be one of the following:
- "microchip,mcp3021" for mcp3021
- "microchip,mcp3221" for mcp3221
- reg: I2C address

Optional properties:

- reference-voltage-microvolt
Reference voltage in microvolt (uV)

Example:

mcp3021@4d {
compatible = "microchip,mcp3021";
reg = <0x4d>;

reference-voltage-microvolt = <4500000>; /* 4.5 V */
};
14 changes: 14 additions & 0 deletions Documentation/devicetree/bindings/hwmon/tmp108.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
TMP108 temperature sensor
-------------------------

This device supports I2C only.

Requires node properties:
- compatible : "ti,tmp108"
- reg : the I2C address of the device. This is 0x48, 0x49, 0x4a, or 0x4b.

Example:
tmp108@48 {
compatible = "ti,tmp108";
reg = <0x48>;
};
2 changes: 2 additions & 0 deletions Documentation/devicetree/bindings/i2c/trivial-devices.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ microchip,mcp4662-502 Microchip 8-bit Dual I2C Digital Potentiometer with NV Mem
microchip,mcp4662-103 Microchip 8-bit Dual I2C Digital Potentiometer with NV Memory (10k)
microchip,mcp4662-503 Microchip 8-bit Dual I2C Digital Potentiometer with NV Memory (50k)
microchip,mcp4662-104 Microchip 8-bit Dual I2C Digital Potentiometer with NV Memory (100k)
microchip,tc654 PWM Fan Speed Controller With Fan Fault Detection
microchip,tc655 PWM Fan Speed Controller With Fan Fault Detection
miramems,da226 MiraMEMS DA226 2-axis 14-bit digital accelerometer
miramems,da280 MiraMEMS DA280 3-axis 14-bit digital accelerometer
miramems,da311 MiraMEMS DA311 3-axis 12-bit digital accelerometer
Expand Down
58 changes: 26 additions & 32 deletions Documentation/hwmon/hwmon-kernel-api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Each hardware monitoring driver must #include <linux/hwmon.h> and, in most
cases, <linux/hwmon-sysfs.h>. linux/hwmon.h declares the following
register/unregister functions:

struct device *hwmon_device_register(struct device *dev);
struct device *
hwmon_device_register_with_groups(struct device *dev, const char *name,
void *drvdata,
Expand All @@ -38,36 +37,31 @@ struct device *
hwmon_device_register_with_info(struct device *dev,
const char *name, void *drvdata,
const struct hwmon_chip_info *info,
const struct attribute_group **groups);
const struct attribute_group **extra_groups);

struct device *
devm_hwmon_device_register_with_info(struct device *dev,
const char *name,
void *drvdata,
const struct hwmon_chip_info *info,
const struct attribute_group **groups);
const char *name,
void *drvdata,
const struct hwmon_chip_info *info,
const struct attribute_group **extra_groups);

void hwmon_device_unregister(struct device *dev);
void devm_hwmon_device_unregister(struct device *dev);

hwmon_device_register registers a hardware monitoring device. The parameter
of this function is a pointer to the parent device.
This function returns a pointer to the newly created hardware monitoring device
or PTR_ERR for failure. If this registration function is used, hardware
monitoring sysfs attributes are expected to have been created and attached to
the parent device prior to calling hwmon_device_register. A name attribute must
have been created by the caller.

hwmon_device_register_with_groups is similar to hwmon_device_register. However,
it has additional parameters. The name parameter is a pointer to the hwmon
device name. The registration function wil create a name sysfs attribute
pointing to this name. The drvdata parameter is the pointer to the local
driver data. hwmon_device_register_with_groups will attach this pointer
to the newly allocated hwmon device. The pointer can be retrieved by the driver
using dev_get_drvdata() on the hwmon device pointer. The groups parameter is
hwmon_device_register_with_groups registers a hardware monitoring device.
The first parameter of this function is a pointer to the parent device.
The name parameter is a pointer to the hwmon device name. The registration
function wil create a name sysfs attribute pointing to this name.
The drvdata parameter is the pointer to the local driver data.
hwmon_device_register_with_groups will attach this pointer to the newly
allocated hwmon device. The pointer can be retrieved by the driver using
dev_get_drvdata() on the hwmon device pointer. The groups parameter is
a pointer to a list of sysfs attribute groups. The list must be NULL terminated.
hwmon_device_register_with_groups creates the hwmon device with name attribute
as well as all sysfs attributes attached to the hwmon device.
This function returns a pointer to the newly created hardware monitoring device
or PTR_ERR for failure.

devm_hwmon_device_register_with_groups is similar to
hwmon_device_register_with_groups. However, it is device managed, meaning the
Expand All @@ -87,13 +81,13 @@ hwmon_device_unregister deregisters a registered hardware monitoring device.
The parameter of this function is the pointer to the registered hardware
monitoring device structure. This function must be called from the driver
remove function if the hardware monitoring device was registered with
hwmon_device_register, hwmon_device_register_with_groups, or
hwmon_device_register_with_info.
hwmon_device_register_with_groups or hwmon_device_register_with_info.

devm_hwmon_device_unregister does not normally have to be called. It is only
needed for error handling, and only needed if the driver probe fails after
the call to devm_hwmon_device_register_with_groups and if the automatic
(device managed) removal would be too late.
the call to devm_hwmon_device_register_with_groups or
hwmon_device_register_with_info and if the automatic (device managed)
removal would be too late.

Using devm_hwmon_device_register_with_info()
--------------------------------------------
Expand All @@ -106,9 +100,9 @@ const char *name Device name
void *drvdata Driver private data
const struct hwmon_chip_info *info
Pointer to chip description.
const struct attribute_group **groups
Null-terminated list of additional sysfs attribute
groups.
const struct attribute_group **extra_groups
Null-terminated list of additional non-standard
sysfs attribute groups.

This function returns a pointer to the created hardware monitoring device
on success and a negative error code for failure.
Expand Down Expand Up @@ -160,7 +154,7 @@ It contains following fields:
* type: The hardware monitoring sensor type.
Supported sensor types are
* hwmon_chip A virtual sensor type, used to describe attributes
which apply to the entire chip.
* which are not bound to a specific input or output
* hwmon_temp Temperature sensor
* hwmon_in Voltage sensor
* hwmon_curr Current sensor
Expand Down Expand Up @@ -293,9 +287,9 @@ Driver-provided sysfs attributes

If the hardware monitoring device is registered with
hwmon_device_register_with_info or devm_hwmon_device_register_with_info,
it is most likely not necessary to provide sysfs attributes. Only non-standard
sysfs attributes need to be provided when one of those registration functions
is used.
it is most likely not necessary to provide sysfs attributes. Only additional
non-standard sysfs attributes need to be provided when one of those registration
functions is used.

The header file linux/hwmon-sysfs.h provides a number of useful macros to
declare and use hardware monitoring sysfs attributes.
Expand Down
31 changes: 31 additions & 0 deletions Documentation/hwmon/tc654
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Kernel driver tc654
===================

Supported chips:
* Microship TC654 and TC655
Prefix: 'tc654'
Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/20001734C.pdf

Authors:
Chris Packham <[email protected]>
Masahiko Iwamoto <[email protected]>

Description
-----------
This driver implements support for the Microchip TC654 and TC655.

The TC654 uses the 2-wire interface compatible with the SMBUS 2.0
specification. The TC654 has two (2) inputs for measuring fan RPM and
one (1) PWM output which can be used for fan control.

Configuration Notes
-------------------
Ordinarily the pwm1_mode ABI is used for controlling the pwm output
mode. However, for this chip the output is always pwm, and the
pwm1_mode determines if the pwm output is controlled via the pwm1 value
or via the Vin analog input.


Setting pwm1_mode to 1 will cause the pwm output to be driven based on
the pwm1 value. Setting pwm1_mode to 0 will cause the pwm output to be
driven based on the Vin input.
36 changes: 36 additions & 0 deletions Documentation/hwmon/tmp108
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Kernel driver tmp108
====================

Supported chips:
* Texas Instruments TMP108
Prefix: 'tmp108'
Addresses scanned: none
Datasheet: http://www.ti.com/product/tmp108

Author:
John Muir <[email protected]>

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

The Texas Instruments TMP108 implements one temperature sensor. An alert pin
can be set when temperatures exceed minimum or maximum values plus or minus a
hysteresis value. (This driver does not support interrupts for the alert pin,
and the device runs in comparator mode.)

The sensor is accurate to 0.75C over the range of -25 to +85 C, and to 1.0
degree from -40 to +125 C. Resolution of the sensor is 0.0625 degree. The
operating temperature has a minimum of -55 C and a maximum of +150 C.
Hysteresis values can be set to 0, 1, 2, or 4C.

The TMP108 has a programmable update rate that can select between 8, 4, 1, and
0.5 Hz.

By default the TMP108 reads the temperature continuously. To conserve power,
the TMP108 has a one-shot mode where the device is normally shut-down. When a
one shot is requested the temperature is read, the result can be retrieved,
and then the device is shut down automatically. (This driver only supports
continuous mode.)

The driver provides the common sysfs-interface for temperatures (see
Documentation/hwmon/sysfs-interface under Temperatures).
26 changes: 24 additions & 2 deletions drivers/hwmon/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,17 @@ config SENSORS_MCP3021
This driver can also be built as a module. If so, the module
will be called mcp3021.

config SENSORS_TC654
tristate "Microchip TC654/TC655 and compatibles"
depends on I2C
help
If you say yes here you get support for TC654 and TC655.
The TC654 and TC655 are PWM mode fan speed controllers with
FanSense technology for use with brushless DC fans.

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

config SENSORS_MENF21BMC_HWMON
tristate "MEN 14F021P00 BMC Hardware Monitoring"
depends on MFD_MENF21BMC
Expand Down Expand Up @@ -1068,8 +1079,8 @@ config SENSORS_LM90
LM86, LM89 and LM99, Analog Devices ADM1032, ADT7461, and ADT7461A,
Maxim MAX6646, MAX6647, MAX6648, MAX6649, MAX6657, MAX6658, MAX6659,
MAX6680, MAX6681, MAX6692, MAX6695, MAX6696, ON Semiconductor NCT1008,
Winbond/Nuvoton W83L771W/G/AWG/ASG, Philips SA56004, and GMT G781
sensor chips.
Winbond/Nuvoton W83L771W/G/AWG/ASG, Philips SA56004, GMT G781, and
Texas Instruments TMP451 sensor chips.

This driver can also be built as a module. If so, the module
will be called lm90.
Expand Down Expand Up @@ -1591,6 +1602,17 @@ config SENSORS_TMP103
This driver can also be built as a module. If so, the module
will be called tmp103.

config SENSORS_TMP108
tristate "Texas Instruments TMP108"
depends on I2C
select REGMAP_I2C
help
If you say yes here you get support for Texas Instruments TMP108
sensor chips.

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

config SENSORS_TMP401
tristate "Texas Instruments TMP401 and compatibles"
depends on I2C
Expand Down
2 changes: 2 additions & 0 deletions drivers/hwmon/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ obj-$(CONFIG_SENSORS_MAX6697) += max6697.o
obj-$(CONFIG_SENSORS_MAX31790) += max31790.o
obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o
obj-$(CONFIG_SENSORS_MCP3021) += mcp3021.o
obj-$(CONFIG_SENSORS_TC654) += tc654.o
obj-$(CONFIG_SENSORS_MENF21BMC_HWMON) += menf21bmc_hwmon.o
obj-$(CONFIG_SENSORS_NCT6683) += nct6683.o
obj-$(CONFIG_SENSORS_NCT6775) += nct6775.o
Expand Down Expand Up @@ -152,6 +153,7 @@ obj-$(CONFIG_SENSORS_TC74) += tc74.o
obj-$(CONFIG_SENSORS_THMC50) += thmc50.o
obj-$(CONFIG_SENSORS_TMP102) += tmp102.o
obj-$(CONFIG_SENSORS_TMP103) += tmp103.o
obj-$(CONFIG_SENSORS_TMP108) += tmp108.o
obj-$(CONFIG_SENSORS_TMP401) += tmp401.o
obj-$(CONFIG_SENSORS_TMP421) += tmp421.o
obj-$(CONFIG_SENSORS_TWL4030_MADC)+= twl4030-madc-hwmon.o
Expand Down
2 changes: 1 addition & 1 deletion drivers/hwmon/adm1025.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static const int in_scale[6] = { 2500, 2250, 3300, 5000, 12000, 3300 };

#define IN_FROM_REG(reg, scale) (((reg) * (scale) + 96) / 192)
#define IN_TO_REG(val, scale) ((val) <= 0 ? 0 : \
(val) * 192 >= (scale) * 255 ? 255 : \
(val) >= (scale) * 255 / 192 ? 255 : \
((val) * 192 + (scale) / 2) / (scale))

#define TEMP_FROM_REG(reg) ((reg) * 1000)
Expand Down
26 changes: 17 additions & 9 deletions drivers/hwmon/adm1026.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,9 @@ static int adm1026_scaling[] = { /* .001 Volts */
};
#define NEG12_OFFSET 16000
#define SCALE(val, from, to) (((val)*(to) + ((from)/2))/(from))
#define INS_TO_REG(n, val) (clamp_val(SCALE(val, adm1026_scaling[n], 192),\
0, 255))
#define INS_TO_REG(n, val) \
SCALE(clamp_val(val, 0, 255 * adm1026_scaling[n] / 192), \
adm1026_scaling[n], 192)
#define INS_FROM_REG(n, val) (SCALE(val, 192, adm1026_scaling[n]))

/*
Expand All @@ -215,11 +216,11 @@ static int adm1026_scaling[] = { /* .001 Volts */
#define DIV_TO_REG(val) ((val) >= 8 ? 3 : (val) >= 4 ? 2 : (val) >= 2 ? 1 : 0)

/* Temperature is reported in 1 degC increments */
#define TEMP_TO_REG(val) (clamp_val(((val) + ((val) < 0 ? -500 : 500)) \
/ 1000, -127, 127))
#define TEMP_TO_REG(val) DIV_ROUND_CLOSEST(clamp_val(val, -128000, 127000), \
1000)
#define TEMP_FROM_REG(val) ((val) * 1000)
#define OFFSET_TO_REG(val) (clamp_val(((val) + ((val) < 0 ? -500 : 500)) \
/ 1000, -127, 127))
#define OFFSET_TO_REG(val) DIV_ROUND_CLOSEST(clamp_val(val, -128000, 127000), \
1000)
#define OFFSET_FROM_REG(val) ((val) * 1000)

#define PWM_TO_REG(val) (clamp_val(val, 0, 255))
Expand All @@ -233,7 +234,8 @@ static int adm1026_scaling[] = { /* .001 Volts */
* indicates that the DAC could be used to drive the fans, but in our
* example board (Arima HDAMA) it isn't connected to the fans at all.
*/
#define DAC_TO_REG(val) (clamp_val(((((val) * 255) + 500) / 2500), 0, 255))
#define DAC_TO_REG(val) DIV_ROUND_CLOSEST(clamp_val(val, 0, 2500) * 255, \
2500)
#define DAC_FROM_REG(val) (((val) * 2500) / 255)

/*
Expand Down Expand Up @@ -593,7 +595,10 @@ static ssize_t set_in16_min(struct device *dev, struct device_attribute *attr,
return err;

mutex_lock(&data->update_lock);
data->in_min[16] = INS_TO_REG(16, val + NEG12_OFFSET);
data->in_min[16] = INS_TO_REG(16,
clamp_val(val, INT_MIN,
INT_MAX - NEG12_OFFSET) +
NEG12_OFFSET);
adm1026_write_value(client, ADM1026_REG_IN_MIN[16], data->in_min[16]);
mutex_unlock(&data->update_lock);
return count;
Expand All @@ -618,7 +623,10 @@ static ssize_t set_in16_max(struct device *dev, struct device_attribute *attr,
return err;

mutex_lock(&data->update_lock);
data->in_max[16] = INS_TO_REG(16, val+NEG12_OFFSET);
data->in_max[16] = INS_TO_REG(16,
clamp_val(val, INT_MIN,
INT_MAX - NEG12_OFFSET) +
NEG12_OFFSET);
adm1026_write_value(client, ADM1026_REG_IN_MAX[16], data->in_max[16]);
mutex_unlock(&data->update_lock);
return count;
Expand Down
9 changes: 6 additions & 3 deletions drivers/hwmon/adm9240.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,15 @@ static inline unsigned int IN_FROM_REG(u8 reg, int n)

static inline u8 IN_TO_REG(unsigned long val, int n)
{
return clamp_val(SCALE(val, 192, nom_mv[n]), 0, 255);
val = clamp_val(val, 0, nom_mv[n] * 255 / 192);
return SCALE(val, 192, nom_mv[n]);
}

/* temperature range: -40..125, 127 disables temperature alarm */
static inline s8 TEMP_TO_REG(long val)
{
return clamp_val(SCALE(val, 1, 1000), -40, 127);
val = clamp_val(val, -40000, 127000);
return SCALE(val, 1, 1000);
}

/* two fans, each with low fan speed limit */
Expand All @@ -122,7 +124,8 @@ static inline unsigned int FAN_FROM_REG(u8 reg, u8 div)
/* analog out 0..1250mV */
static inline u8 AOUT_TO_REG(unsigned long val)
{
return clamp_val(SCALE(val, 255, 1250), 0, 255);
val = clamp_val(val, 0, 1250);
return SCALE(val, 255, 1250);
}

static inline unsigned int AOUT_FROM_REG(u8 reg)
Expand Down
Loading

0 comments on commit 1c59e1e

Please sign in to comment.