You've already forked linux-apfs
mirror of
https://github.com/linux-apfs/linux-apfs.git
synced 2026-05-01 15:00:59 -07:00
Merge tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging into next
Pull hwmon updates from Guenter Roeck:
"New driver for NCT6683D
New chip support to existing drivers:
- add support for STTS2004 and AT30TSE004 to jc42 driver
- add support for EMC1402/EMC1412/EMC1422 to emc1403 driver
Other notable changes:
- document hwmon kernel API
- convert jc42, lm70, lm75, lm77, lm83, lm92, max1619, tmp421, and
tmp102 drivers to use new hwmon API functions
- replace function macros in lm80, lm92, and jc42 drivers with real
code
- convert emc1403 driver to use regmap, add support for additional
attributes, and add device IDs for EMC1412, EMC1413, and EMC1414
- various additional cleanup and minor bug fixes in several drivers"
* tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging: (60 commits)
hwmon: (nct6775) Fix probe unwind paths to properly unregister platform devices
hwmon: (nct6683) Fix probe unwind paths to properly unregister platform devices
hwmon: (ultra45_env) Introduce managed version of kzalloc
hwmon: Driver for NCT6683D
hwmon: (lm80) Rearrange code to avoid forward declarations
hwmon: (lm80) Convert fan display function macros into functions
hwmon: (lm80) Convert voltage display function macros into functions
hwmon: (lm80) Convert temperature display function macros into functions
hwmon: (lm80) Normalize all temperature values to 16 bit
hwmon: (lm80) Simplify TEMP_FROM_REG
hwmon: (lm83) Convert to use devm_hwmon_device_register_with_groups
hwmon: (lm83) Rearange code to avoid forward declarations
hwmon: (lm83) Drop FSF address
hwmon: (max1619) Convert to use devm_hwmon_device_register_with_groups
hwmon: (max1619) Drop function macros
hwmon: (max1619) Rearrange code to avoid forward declarations
hwmon: (max1619) Drop FSF address
hwmon: (max1619) Fix critical alarm display
hwmon: (jc42) Add support for STTS2004 and AT30TSE004
hwmon: (jc42) Convert function macros into functions
...
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
Kernel driver emc1403
|
||||
=====================
|
||||
|
||||
Supported chips:
|
||||
* SMSC / Microchip EMC1402, EMC1412
|
||||
Addresses scanned: I2C 0x18, 0x1c, 0x29, 0x4c, 0x4d, 0x5c
|
||||
Prefix: 'emc1402'
|
||||
Datasheets:
|
||||
http://ww1.microchip.com/downloads/en/DeviceDoc/1412.pdf
|
||||
http://ww1.microchip.com/downloads/en/DeviceDoc/1402.pdf
|
||||
* SMSC / Microchip EMC1403, EMC1404, EMC1413, EMC1414
|
||||
Addresses scanned: I2C 0x18, 0x29, 0x4c, 0x4d
|
||||
Prefix: 'emc1403', 'emc1404'
|
||||
Datasheets:
|
||||
http://ww1.microchip.com/downloads/en/DeviceDoc/1403_1404.pdf
|
||||
http://ww1.microchip.com/downloads/en/DeviceDoc/1413_1414.pdf
|
||||
* SMSC / Microchip EMC1422
|
||||
Addresses scanned: I2C 0x4c
|
||||
Prefix: 'emc1422'
|
||||
Datasheet:
|
||||
http://ww1.microchip.com/downloads/en/DeviceDoc/1422.pdf
|
||||
* SMSC / Microchip EMC1423, EMC1424
|
||||
Addresses scanned: I2C 0x4c
|
||||
Prefix: 'emc1423', 'emc1424'
|
||||
Datasheet:
|
||||
http://ww1.microchip.com/downloads/en/DeviceDoc/1423_1424.pdf
|
||||
|
||||
Author:
|
||||
Kalhan Trisal <kalhan.trisal@intel.com
|
||||
|
||||
|
||||
Description
|
||||
-----------
|
||||
|
||||
The Standard Microsystems Corporation (SMSC) / Microchip EMC14xx chips
|
||||
contain up to four temperature sensors. EMC14x2 support two sensors
|
||||
(one internal, one external). EMC14x3 support three sensors (one internal,
|
||||
two external), and EMC14x4 support four sensors (one internal, three
|
||||
external).
|
||||
|
||||
The chips implement three limits for each sensor: low (tempX_min), high
|
||||
(tempX_max) and critical (tempX_crit.) The chips also implement an
|
||||
hysteresis mechanism which applies to all limits. The relative difference
|
||||
is stored in a single register on the chip, which means that the relative
|
||||
difference between the limit and its hysteresis is always the same for
|
||||
all three limits.
|
||||
|
||||
This implementation detail implies the following:
|
||||
* When setting a limit, its hysteresis will automatically follow, the
|
||||
difference staying unchanged. For example, if the old critical limit
|
||||
was 80 degrees C, and the hysteresis was 75 degrees C, and you change
|
||||
the critical limit to 90 degrees C, then the hysteresis will
|
||||
automatically change to 85 degrees C.
|
||||
* The hysteresis values can't be set independently. We decided to make
|
||||
only temp1_crit_hyst writable, while all other hysteresis attributes
|
||||
are read-only. Setting temp1_crit_hyst writes the difference between
|
||||
temp1_crit_hyst and temp1_crit into the chip, and the same relative
|
||||
hysteresis applies automatically to all other limits.
|
||||
* The limits should be set before the hysteresis.
|
||||
@@ -0,0 +1,107 @@
|
||||
The Linux Hardware Monitoring kernel API.
|
||||
=========================================
|
||||
|
||||
Guenter Roeck
|
||||
|
||||
Introduction
|
||||
------------
|
||||
|
||||
This document describes the API that can be used by hardware monitoring
|
||||
drivers that want to use the hardware monitoring framework.
|
||||
|
||||
This document does not describe what a hardware monitoring (hwmon) Driver or
|
||||
Device is. It also does not describe the API which can be used by user space
|
||||
to communicate with a hardware monitoring device. If you want to know this
|
||||
then please read the following file: Documentation/hwmon/sysfs-interface.
|
||||
|
||||
For additional guidelines on how to write and improve hwmon drivers, please
|
||||
also read Documentation/hwmon/submitting-patches.
|
||||
|
||||
The API
|
||||
-------
|
||||
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,
|
||||
const struct attribute_group **groups);
|
||||
|
||||
struct device *
|
||||
devm_hwmon_device_register_with_groups(struct device *dev,
|
||||
const char *name, void *drvdata,
|
||||
const struct attribute_group **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
|
||||
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.
|
||||
|
||||
devm_hwmon_device_register_with_groups is similar to
|
||||
hwmon_device_register_with_groups. However, it is device managed, meaning the
|
||||
hwmon device does not have to be removed explicitly by the removal function.
|
||||
|
||||
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 or with hwmon_device_register_with_groups.
|
||||
|
||||
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.
|
||||
|
||||
The header file linux/hwmon-sysfs.h provides a number of useful macros to
|
||||
declare and use hardware monitoring sysfs attributes.
|
||||
|
||||
In many cases, you can use the exsting define DEVICE_ATTR to declare such
|
||||
attributes. This is feasible if an attribute has no additional context. However,
|
||||
in many cases there will be additional information such as a sensor index which
|
||||
will need to be passed to the sysfs attribute handling function.
|
||||
|
||||
SENSOR_DEVICE_ATTR and SENSOR_DEVICE_ATTR_2 can be used to define attributes
|
||||
which need such additional context information. SENSOR_DEVICE_ATTR requires
|
||||
one additional argument, SENSOR_DEVICE_ATTR_2 requires two.
|
||||
|
||||
SENSOR_DEVICE_ATTR defines a struct sensor_device_attribute variable.
|
||||
This structure has the following fields.
|
||||
|
||||
struct sensor_device_attribute {
|
||||
struct device_attribute dev_attr;
|
||||
int index;
|
||||
};
|
||||
|
||||
You can use to_sensor_dev_attr to get the pointer to this structure from the
|
||||
attribute read or write function. Its parameter is the device to which the
|
||||
attribute is attached.
|
||||
|
||||
SENSOR_DEVICE_ATTR_2 defines a struct sensor_device_attribute_2 variable,
|
||||
which is defined as follows.
|
||||
|
||||
struct sensor_device_attribute_2 {
|
||||
struct device_attribute dev_attr;
|
||||
u8 index;
|
||||
u8 nr;
|
||||
};
|
||||
|
||||
Use to_sensor_dev_attr_2 to get the pointer to this structure. Its parameter
|
||||
is the device to which the attribute is attached.
|
||||
@@ -5,9 +5,12 @@ Supported chips:
|
||||
* Analog Devices ADT7408
|
||||
Datasheets:
|
||||
http://www.analog.com/static/imported-files/data_sheets/ADT7408.pdf
|
||||
* Atmel AT30TS00
|
||||
* Atmel AT30TS00, AT30TS002A/B, AT30TSE004A
|
||||
Datasheets:
|
||||
http://www.atmel.com/Images/doc8585.pdf
|
||||
http://www.atmel.com/Images/doc8711.pdf
|
||||
http://www.atmel.com/Images/Atmel-8852-SEEPROM-AT30TSE002A-Datasheet.pdf
|
||||
http://www.atmel.com/Images/Atmel-8868-DTS-AT30TSE004A-Datasheet.pdf
|
||||
* IDT TSE2002B3, TSE2002GB2, TS3000B3, TS3000GB2
|
||||
Datasheets:
|
||||
http://www.idt.com/sites/default/files/documents/IDT_TSE2002B3C_DST_20100512_120303152056.pdf
|
||||
@@ -34,12 +37,13 @@ Supported chips:
|
||||
Datasheet:
|
||||
http://www.onsemi.com/pub_link/Collateral/CAT34TS02-D.PDF
|
||||
http://www.onsemi.com/pub/Collateral/CAT6095-D.PDF
|
||||
* ST Microelectronics STTS424, STTS424E02, STTS2002, STTS3000
|
||||
* ST Microelectronics STTS424, STTS424E02, STTS2002, STTS2004, STTS3000
|
||||
Datasheets:
|
||||
http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATASHEET/CD00157556.pdf
|
||||
http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATASHEET/CD00157558.pdf
|
||||
http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATASHEET/CD00225278.pdf
|
||||
http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATA_BRIEF/CD00270920.pdf
|
||||
http://www.st.com/web/en/resource/technical/document/datasheet/CD00157556.pdf
|
||||
http://www.st.com/web/en/resource/technical/document/datasheet/CD00157558.pdf
|
||||
http://www.st.com/web/en/resource/technical/document/datasheet/CD00266638.pdf
|
||||
http://www.st.com/web/en/resource/technical/document/datasheet/CD00225278.pdf
|
||||
http://www.st.com/web/en/resource/technical/document/datasheet/DM00076709.pdf
|
||||
* JEDEC JC 42.4 compliant temperature sensor chips
|
||||
Datasheet:
|
||||
http://www.jedec.org/sites/default/files/docs/4_01_04R19.pdf
|
||||
|
||||
@@ -18,5 +18,21 @@ sensor incorporates a band-gap type temperature sensor,
|
||||
10-bit ADC, and a digital comparator with user-programmable upper
|
||||
and lower limit values.
|
||||
|
||||
Limits can be set through the Overtemperature Shutdown register and
|
||||
Hysteresis register.
|
||||
The LM77 implements 3 limits: low (temp1_min), high (temp1_max) and
|
||||
critical (temp1_crit.) It also implements an hysteresis mechanism which
|
||||
applies to all 3 limits. The relative difference is stored in a single
|
||||
register on the chip, which means that the relative difference between
|
||||
the limit and its hysteresis is always the same for all 3 limits.
|
||||
|
||||
This implementation detail implies the following:
|
||||
* When setting a limit, its hysteresis will automatically follow, the
|
||||
difference staying unchanged. For example, if the old critical limit
|
||||
was 80 degrees C, and the hysteresis was 75 degrees C, and you change
|
||||
the critical limit to 90 degrees C, then the hysteresis will
|
||||
automatically change to 85 degrees C.
|
||||
* All 3 hysteresis can't be set independently. We decided to make
|
||||
temp1_crit_hyst writable, while temp1_min_hyst and temp1_max_hyst are
|
||||
read-only. Setting temp1_crit_hyst writes the difference between
|
||||
temp1_crit_hyst and temp1_crit into the chip, and the same relative
|
||||
hysteresis applies automatically to the low and high limits.
|
||||
* The limits should be set before the hysteresis.
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
Kernel driver nct6683
|
||||
=====================
|
||||
|
||||
Supported chips:
|
||||
* Nuvoton NCT6683D
|
||||
Prefix: 'nct6683'
|
||||
Addresses scanned: ISA address retrieved from Super I/O registers
|
||||
Datasheet: Available from Nuvoton upon request
|
||||
|
||||
Authors:
|
||||
Guenter Roeck <linux@roeck-us.net>
|
||||
|
||||
Description
|
||||
-----------
|
||||
|
||||
This driver implements support for the Nuvoton NCT6683D eSIO chip.
|
||||
|
||||
The chips implement up to shared 32 temperature and voltage sensors.
|
||||
It supports up to 16 fan rotation sensors and up to 8 fan control engines.
|
||||
|
||||
Temperatures are measured in degrees Celsius. Measurement resolution is
|
||||
0.5 degrees C.
|
||||
|
||||
Voltage sensors (also known as IN sensors) report their values in millivolts.
|
||||
|
||||
Fan rotation speeds are reported in RPM (rotations per minute).
|
||||
|
||||
Usage Note
|
||||
----------
|
||||
|
||||
Limit register locations on Intel boards with EC firmware version 1.0
|
||||
build date 04/03/13 do not match the register locations in the Nuvoton
|
||||
datasheet. Nuvoton confirms that Intel uses a special firmware version
|
||||
with different register addresses. The specification describing the Intel
|
||||
firmware is held under NDA by Nuvoton and Intel and not available
|
||||
to the public.
|
||||
|
||||
Some of the register locations can be reverse engineered; others are too
|
||||
well hidden. Given this, writing any values from the operating system is
|
||||
considered too risky with this firmware and has been disabled. All limits
|
||||
must all be written from the BIOS.
|
||||
|
||||
The driver has only been tested with the Intel firmware, and by default
|
||||
only instantiates on Intel boards. To enable it on non-Intel boards,
|
||||
set the 'force' module parameter to 1.
|
||||
|
||||
Tested Boards and Firmware Versions
|
||||
-----------------------------------
|
||||
|
||||
The driver has been reported to work with the following boards and
|
||||
firmware versions.
|
||||
|
||||
Board Firmware version
|
||||
---------------------------------------------------------------
|
||||
Intel DH87RL NCT6683D EC firmware version 1.0 build 04/03/13
|
||||
Intel DH87MC NCT6683D EC firmware version 1.0 build 04/03/13
|
||||
Intel DB85FL NCT6683D EC firmware version 1.0 build 04/03/13
|
||||
+1
-1
@@ -355,7 +355,7 @@ F: Documentation/hwmon/adm1025
|
||||
F: drivers/hwmon/adm1025.c
|
||||
|
||||
ADM1029 HARDWARE MONITOR DRIVER
|
||||
M: Corentin Labbe <corentin.labbe@geomatys.fr>
|
||||
M: Corentin Labbe <clabbe.montjoie@gmail.com>
|
||||
L: lm-sensors@lm-sensors.org
|
||||
S: Maintained
|
||||
F: drivers/hwmon/adm1029.c
|
||||
|
||||
@@ -1065,6 +1065,16 @@ config SENSORS_NTC_THERMISTOR
|
||||
This driver can also be built as a module. If so, the module
|
||||
will be called ntc-thermistor.
|
||||
|
||||
config SENSORS_NCT6683
|
||||
tristate "Nuvoton NCT6683D"
|
||||
depends on !PPC
|
||||
help
|
||||
If you say yes here you get support for the hardware monitoring
|
||||
functionality of the Nuvoton NCT6683D eSIO chip.
|
||||
|
||||
This driver can also be built as a module. If so, the module
|
||||
will be called nct6683.
|
||||
|
||||
config SENSORS_NCT6775
|
||||
tristate "Nuvoton NCT6775F and compatibles"
|
||||
depends on !PPC
|
||||
|
||||
@@ -114,6 +114,7 @@ obj-$(CONFIG_SENSORS_MAX6650) += max6650.o
|
||||
obj-$(CONFIG_SENSORS_MAX6697) += max6697.o
|
||||
obj-$(CONFIG_SENSORS_MC13783_ADC)+= mc13783-adc.o
|
||||
obj-$(CONFIG_SENSORS_MCP3021) += mcp3021.o
|
||||
obj-$(CONFIG_SENSORS_NCT6683) += nct6683.o
|
||||
obj-$(CONFIG_SENSORS_NCT6775) += nct6775.o
|
||||
obj-$(CONFIG_SENSORS_NTC_THERMISTOR) += ntc_thermistor.o
|
||||
obj-$(CONFIG_SENSORS_PC87360) += pc87360.o
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* adm1029.c - Part of lm_sensors, Linux kernel modules for hardware monitoring
|
||||
*
|
||||
* Copyright (C) 2006 Corentin LABBE <corentin.labbe@geomatys.fr>
|
||||
* Copyright (C) 2006 Corentin LABBE <clabbe.montjoie@gmail.com>
|
||||
*
|
||||
* Based on LM83 Driver by Jean Delvare <jdelvare@suse.de>
|
||||
*
|
||||
@@ -449,6 +449,6 @@ static struct adm1029_data *adm1029_update_device(struct device *dev)
|
||||
|
||||
module_i2c_driver(adm1029_driver);
|
||||
|
||||
MODULE_AUTHOR("Corentin LABBE <corentin.labbe@geomatys.fr>");
|
||||
MODULE_AUTHOR("Corentin LABBE <clabbe.montjoie@gmail.com>");
|
||||
MODULE_DESCRIPTION("adm1029 driver");
|
||||
MODULE_LICENSE("GPL v2");
|
||||
|
||||
+186
-83
@@ -18,9 +18,6 @@
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
*
|
||||
* TODO
|
||||
* - cache alarm and critical limit registers
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
@@ -32,22 +29,18 @@
|
||||
#include <linux/err.h>
|
||||
#include <linux/sysfs.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/jiffies.h>
|
||||
#include <linux/regmap.h>
|
||||
|
||||
#define THERMAL_PID_REG 0xfd
|
||||
#define THERMAL_SMSC_ID_REG 0xfe
|
||||
#define THERMAL_REVISION_REG 0xff
|
||||
|
||||
enum emc1403_chip { emc1402, emc1403, emc1404 };
|
||||
|
||||
struct thermal_data {
|
||||
struct i2c_client *client;
|
||||
const struct attribute_group *groups[3];
|
||||
struct regmap *regmap;
|
||||
struct mutex mutex;
|
||||
/*
|
||||
* Cache the hyst value so we don't keep re-reading it. In theory
|
||||
* we could cache it forever as nobody else should be writing it.
|
||||
*/
|
||||
u8 cached_hyst;
|
||||
unsigned long hyst_valid;
|
||||
const struct attribute_group *groups[4];
|
||||
};
|
||||
|
||||
static ssize_t show_temp(struct device *dev,
|
||||
@@ -55,12 +48,13 @@ static ssize_t show_temp(struct device *dev,
|
||||
{
|
||||
struct sensor_device_attribute *sda = to_sensor_dev_attr(attr);
|
||||
struct thermal_data *data = dev_get_drvdata(dev);
|
||||
unsigned int val;
|
||||
int retval;
|
||||
|
||||
retval = i2c_smbus_read_byte_data(data->client, sda->index);
|
||||
retval = regmap_read(data->regmap, sda->index, &val);
|
||||
if (retval < 0)
|
||||
return retval;
|
||||
return sprintf(buf, "%d000\n", retval);
|
||||
return sprintf(buf, "%d000\n", val);
|
||||
}
|
||||
|
||||
static ssize_t show_bit(struct device *dev,
|
||||
@@ -68,12 +62,13 @@ static ssize_t show_bit(struct device *dev,
|
||||
{
|
||||
struct sensor_device_attribute_2 *sda = to_sensor_dev_attr_2(attr);
|
||||
struct thermal_data *data = dev_get_drvdata(dev);
|
||||
unsigned int val;
|
||||
int retval;
|
||||
|
||||
retval = i2c_smbus_read_byte_data(data->client, sda->nr);
|
||||
retval = regmap_read(data->regmap, sda->nr, &val);
|
||||
if (retval < 0)
|
||||
return retval;
|
||||
return sprintf(buf, "%d\n", !!(retval & sda->index));
|
||||
return sprintf(buf, "%d\n", !!(val & sda->index));
|
||||
}
|
||||
|
||||
static ssize_t store_temp(struct device *dev,
|
||||
@@ -86,8 +81,8 @@ static ssize_t store_temp(struct device *dev,
|
||||
|
||||
if (kstrtoul(buf, 10, &val))
|
||||
return -EINVAL;
|
||||
retval = i2c_smbus_write_byte_data(data->client, sda->index,
|
||||
DIV_ROUND_CLOSEST(val, 1000));
|
||||
retval = regmap_write(data->regmap, sda->index,
|
||||
DIV_ROUND_CLOSEST(val, 1000));
|
||||
if (retval < 0)
|
||||
return retval;
|
||||
return count;
|
||||
@@ -98,51 +93,51 @@ static ssize_t store_bit(struct device *dev,
|
||||
{
|
||||
struct sensor_device_attribute_2 *sda = to_sensor_dev_attr_2(attr);
|
||||
struct thermal_data *data = dev_get_drvdata(dev);
|
||||
struct i2c_client *client = data->client;
|
||||
unsigned long val;
|
||||
int retval;
|
||||
|
||||
if (kstrtoul(buf, 10, &val))
|
||||
return -EINVAL;
|
||||
|
||||
mutex_lock(&data->mutex);
|
||||
retval = i2c_smbus_read_byte_data(client, sda->nr);
|
||||
retval = regmap_update_bits(data->regmap, sda->nr, sda->index,
|
||||
val ? sda->index : 0);
|
||||
if (retval < 0)
|
||||
goto fail;
|
||||
|
||||
retval &= ~sda->index;
|
||||
if (val)
|
||||
retval |= sda->index;
|
||||
|
||||
retval = i2c_smbus_write_byte_data(client, sda->index, retval);
|
||||
if (retval == 0)
|
||||
retval = count;
|
||||
fail:
|
||||
mutex_unlock(&data->mutex);
|
||||
return retval;
|
||||
return retval;
|
||||
return count;
|
||||
}
|
||||
|
||||
static ssize_t show_hyst(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
static ssize_t show_hyst_common(struct device *dev,
|
||||
struct device_attribute *attr, char *buf,
|
||||
bool is_min)
|
||||
{
|
||||
struct sensor_device_attribute *sda = to_sensor_dev_attr(attr);
|
||||
struct thermal_data *data = dev_get_drvdata(dev);
|
||||
struct i2c_client *client = data->client;
|
||||
struct regmap *regmap = data->regmap;
|
||||
unsigned int limit;
|
||||
unsigned int hyst;
|
||||
int retval;
|
||||
int hyst;
|
||||
|
||||
retval = i2c_smbus_read_byte_data(client, sda->index);
|
||||
retval = regmap_read(regmap, sda->index, &limit);
|
||||
if (retval < 0)
|
||||
return retval;
|
||||
|
||||
if (time_after(jiffies, data->hyst_valid)) {
|
||||
hyst = i2c_smbus_read_byte_data(client, 0x21);
|
||||
if (hyst < 0)
|
||||
return retval;
|
||||
data->cached_hyst = hyst;
|
||||
data->hyst_valid = jiffies + HZ;
|
||||
}
|
||||
return sprintf(buf, "%d000\n", retval - data->cached_hyst);
|
||||
retval = regmap_read(regmap, 0x21, &hyst);
|
||||
if (retval < 0)
|
||||
return retval;
|
||||
|
||||
return sprintf(buf, "%d000\n", is_min ? limit + hyst : limit - hyst);
|
||||
}
|
||||
|
||||
static ssize_t show_hyst(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
return show_hyst_common(dev, attr, buf, false);
|
||||
}
|
||||
|
||||
static ssize_t show_min_hyst(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
return show_hyst_common(dev, attr, buf, true);
|
||||
}
|
||||
|
||||
static ssize_t store_hyst(struct device *dev,
|
||||
@@ -150,7 +145,8 @@ static ssize_t store_hyst(struct device *dev,
|
||||
{
|
||||
struct sensor_device_attribute *sda = to_sensor_dev_attr(attr);
|
||||
struct thermal_data *data = dev_get_drvdata(dev);
|
||||
struct i2c_client *client = data->client;
|
||||
struct regmap *regmap = data->regmap;
|
||||
unsigned int limit;
|
||||
int retval;
|
||||
int hyst;
|
||||
unsigned long val;
|
||||
@@ -159,23 +155,15 @@ static ssize_t store_hyst(struct device *dev,
|
||||
return -EINVAL;
|
||||
|
||||
mutex_lock(&data->mutex);
|
||||
retval = i2c_smbus_read_byte_data(client, sda->index);
|
||||
retval = regmap_read(regmap, sda->index, &limit);
|
||||
if (retval < 0)
|
||||
goto fail;
|
||||
|
||||
hyst = retval * 1000 - val;
|
||||
hyst = DIV_ROUND_CLOSEST(hyst, 1000);
|
||||
if (hyst < 0 || hyst > 255) {
|
||||
retval = -ERANGE;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
retval = i2c_smbus_write_byte_data(client, 0x21, hyst);
|
||||
if (retval == 0) {
|
||||
hyst = limit * 1000 - val;
|
||||
hyst = clamp_val(DIV_ROUND_CLOSEST(hyst, 1000), 0, 255);
|
||||
retval = regmap_write(regmap, 0x21, hyst);
|
||||
if (retval == 0)
|
||||
retval = count;
|
||||
data->cached_hyst = hyst;
|
||||
data->hyst_valid = jiffies + HZ;
|
||||
}
|
||||
fail:
|
||||
mutex_unlock(&data->mutex);
|
||||
return retval;
|
||||
@@ -198,6 +186,8 @@ static SENSOR_DEVICE_ATTR_2(temp1_max_alarm, S_IRUGO,
|
||||
show_bit, NULL, 0x35, 0x01);
|
||||
static SENSOR_DEVICE_ATTR_2(temp1_crit_alarm, S_IRUGO,
|
||||
show_bit, NULL, 0x37, 0x01);
|
||||
static SENSOR_DEVICE_ATTR(temp1_min_hyst, S_IRUGO, show_min_hyst, NULL, 0x06);
|
||||
static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO, show_hyst, NULL, 0x05);
|
||||
static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IRUGO | S_IWUSR,
|
||||
show_hyst, store_hyst, 0x20);
|
||||
|
||||
@@ -208,14 +198,16 @@ static SENSOR_DEVICE_ATTR(temp2_max, S_IRUGO | S_IWUSR,
|
||||
static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO | S_IWUSR,
|
||||
show_temp, store_temp, 0x19);
|
||||
static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 0x01);
|
||||
static SENSOR_DEVICE_ATTR_2(temp2_fault, S_IRUGO, show_bit, NULL, 0x1b, 0x02);
|
||||
static SENSOR_DEVICE_ATTR_2(temp2_min_alarm, S_IRUGO,
|
||||
show_bit, NULL, 0x36, 0x02);
|
||||
static SENSOR_DEVICE_ATTR_2(temp2_max_alarm, S_IRUGO,
|
||||
show_bit, NULL, 0x35, 0x02);
|
||||
static SENSOR_DEVICE_ATTR_2(temp2_crit_alarm, S_IRUGO,
|
||||
show_bit, NULL, 0x37, 0x02);
|
||||
static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO | S_IWUSR,
|
||||
show_hyst, store_hyst, 0x19);
|
||||
static SENSOR_DEVICE_ATTR(temp2_min_hyst, S_IRUGO, show_min_hyst, NULL, 0x08);
|
||||
static SENSOR_DEVICE_ATTR(temp2_max_hyst, S_IRUGO, show_hyst, NULL, 0x07);
|
||||
static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_hyst, NULL, 0x19);
|
||||
|
||||
static SENSOR_DEVICE_ATTR(temp3_min, S_IRUGO | S_IWUSR,
|
||||
show_temp, store_temp, 0x16);
|
||||
@@ -224,14 +216,16 @@ static SENSOR_DEVICE_ATTR(temp3_max, S_IRUGO | S_IWUSR,
|
||||
static SENSOR_DEVICE_ATTR(temp3_crit, S_IRUGO | S_IWUSR,
|
||||
show_temp, store_temp, 0x1A);
|
||||
static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 0x23);
|
||||
static SENSOR_DEVICE_ATTR_2(temp3_fault, S_IRUGO, show_bit, NULL, 0x1b, 0x04);
|
||||
static SENSOR_DEVICE_ATTR_2(temp3_min_alarm, S_IRUGO,
|
||||
show_bit, NULL, 0x36, 0x04);
|
||||
static SENSOR_DEVICE_ATTR_2(temp3_max_alarm, S_IRUGO,
|
||||
show_bit, NULL, 0x35, 0x04);
|
||||
static SENSOR_DEVICE_ATTR_2(temp3_crit_alarm, S_IRUGO,
|
||||
show_bit, NULL, 0x37, 0x04);
|
||||
static SENSOR_DEVICE_ATTR(temp3_crit_hyst, S_IRUGO | S_IWUSR,
|
||||
show_hyst, store_hyst, 0x1A);
|
||||
static SENSOR_DEVICE_ATTR(temp3_min_hyst, S_IRUGO, show_min_hyst, NULL, 0x16);
|
||||
static SENSOR_DEVICE_ATTR(temp3_max_hyst, S_IRUGO, show_hyst, NULL, 0x15);
|
||||
static SENSOR_DEVICE_ATTR(temp3_crit_hyst, S_IRUGO, show_hyst, NULL, 0x1A);
|
||||
|
||||
static SENSOR_DEVICE_ATTR(temp4_min, S_IRUGO | S_IWUSR,
|
||||
show_temp, store_temp, 0x2D);
|
||||
@@ -240,44 +234,66 @@ static SENSOR_DEVICE_ATTR(temp4_max, S_IRUGO | S_IWUSR,
|
||||
static SENSOR_DEVICE_ATTR(temp4_crit, S_IRUGO | S_IWUSR,
|
||||
show_temp, store_temp, 0x30);
|
||||
static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_temp, NULL, 0x2A);
|
||||
static SENSOR_DEVICE_ATTR_2(temp4_fault, S_IRUGO, show_bit, NULL, 0x1b, 0x08);
|
||||
static SENSOR_DEVICE_ATTR_2(temp4_min_alarm, S_IRUGO,
|
||||
show_bit, NULL, 0x36, 0x08);
|
||||
static SENSOR_DEVICE_ATTR_2(temp4_max_alarm, S_IRUGO,
|
||||
show_bit, NULL, 0x35, 0x08);
|
||||
static SENSOR_DEVICE_ATTR_2(temp4_crit_alarm, S_IRUGO,
|
||||
show_bit, NULL, 0x37, 0x08);
|
||||
static SENSOR_DEVICE_ATTR(temp4_crit_hyst, S_IRUGO | S_IWUSR,
|
||||
show_hyst, store_hyst, 0x30);
|
||||
static SENSOR_DEVICE_ATTR(temp4_min_hyst, S_IRUGO, show_min_hyst, NULL, 0x2D);
|
||||
static SENSOR_DEVICE_ATTR(temp4_max_hyst, S_IRUGO, show_hyst, NULL, 0x2C);
|
||||
static SENSOR_DEVICE_ATTR(temp4_crit_hyst, S_IRUGO, show_hyst, NULL, 0x30);
|
||||
|
||||
static SENSOR_DEVICE_ATTR_2(power_state, S_IRUGO | S_IWUSR,
|
||||
show_bit, store_bit, 0x03, 0x40);
|
||||
|
||||
static struct attribute *emc1403_attrs[] = {
|
||||
static struct attribute *emc1402_attrs[] = {
|
||||
&sensor_dev_attr_temp1_min.dev_attr.attr,
|
||||
&sensor_dev_attr_temp1_max.dev_attr.attr,
|
||||
&sensor_dev_attr_temp1_crit.dev_attr.attr,
|
||||
&sensor_dev_attr_temp1_input.dev_attr.attr,
|
||||
&sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
|
||||
&sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
|
||||
&sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
|
||||
&sensor_dev_attr_temp1_min_hyst.dev_attr.attr,
|
||||
&sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
|
||||
&sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
|
||||
|
||||
&sensor_dev_attr_temp2_min.dev_attr.attr,
|
||||
&sensor_dev_attr_temp2_max.dev_attr.attr,
|
||||
&sensor_dev_attr_temp2_crit.dev_attr.attr,
|
||||
&sensor_dev_attr_temp2_input.dev_attr.attr,
|
||||
&sensor_dev_attr_temp2_min_hyst.dev_attr.attr,
|
||||
&sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
|
||||
&sensor_dev_attr_temp2_crit_hyst.dev_attr.attr,
|
||||
|
||||
&sensor_dev_attr_power_state.dev_attr.attr,
|
||||
NULL
|
||||
};
|
||||
|
||||
static const struct attribute_group emc1402_group = {
|
||||
.attrs = emc1402_attrs,
|
||||
};
|
||||
|
||||
static struct attribute *emc1403_attrs[] = {
|
||||
&sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
|
||||
&sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
|
||||
&sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
|
||||
|
||||
&sensor_dev_attr_temp2_fault.dev_attr.attr,
|
||||
&sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
|
||||
&sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
|
||||
&sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
|
||||
&sensor_dev_attr_temp2_crit_hyst.dev_attr.attr,
|
||||
|
||||
&sensor_dev_attr_temp3_min.dev_attr.attr,
|
||||
&sensor_dev_attr_temp3_max.dev_attr.attr,
|
||||
&sensor_dev_attr_temp3_crit.dev_attr.attr,
|
||||
&sensor_dev_attr_temp3_input.dev_attr.attr,
|
||||
&sensor_dev_attr_temp3_fault.dev_attr.attr,
|
||||
&sensor_dev_attr_temp3_min_alarm.dev_attr.attr,
|
||||
&sensor_dev_attr_temp3_max_alarm.dev_attr.attr,
|
||||
&sensor_dev_attr_temp3_crit_alarm.dev_attr.attr,
|
||||
&sensor_dev_attr_temp3_min_hyst.dev_attr.attr,
|
||||
&sensor_dev_attr_temp3_max_hyst.dev_attr.attr,
|
||||
&sensor_dev_attr_temp3_crit_hyst.dev_attr.attr,
|
||||
&sensor_dev_attr_power_state.dev_attr.attr,
|
||||
NULL
|
||||
};
|
||||
|
||||
@@ -290,9 +306,12 @@ static struct attribute *emc1404_attrs[] = {
|
||||
&sensor_dev_attr_temp4_max.dev_attr.attr,
|
||||
&sensor_dev_attr_temp4_crit.dev_attr.attr,
|
||||
&sensor_dev_attr_temp4_input.dev_attr.attr,
|
||||
&sensor_dev_attr_temp4_fault.dev_attr.attr,
|
||||
&sensor_dev_attr_temp4_min_alarm.dev_attr.attr,
|
||||
&sensor_dev_attr_temp4_max_alarm.dev_attr.attr,
|
||||
&sensor_dev_attr_temp4_crit_alarm.dev_attr.attr,
|
||||
&sensor_dev_attr_temp4_min_hyst.dev_attr.attr,
|
||||
&sensor_dev_attr_temp4_max_hyst.dev_attr.attr,
|
||||
&sensor_dev_attr_temp4_crit_hyst.dev_attr.attr,
|
||||
NULL
|
||||
};
|
||||
@@ -301,6 +320,39 @@ static const struct attribute_group emc1404_group = {
|
||||
.attrs = emc1404_attrs,
|
||||
};
|
||||
|
||||
/*
|
||||
* EMC14x2 uses a different register and different bits to report alarm and
|
||||
* fault status. For simplicity, provide a separate attribute group for this
|
||||
* chip series.
|
||||
* Since we can not re-use the same attribute names, create a separate attribute
|
||||
* array.
|
||||
*/
|
||||
static struct sensor_device_attribute_2 emc1402_alarms[] = {
|
||||
SENSOR_ATTR_2(temp1_min_alarm, S_IRUGO, show_bit, NULL, 0x02, 0x20),
|
||||
SENSOR_ATTR_2(temp1_max_alarm, S_IRUGO, show_bit, NULL, 0x02, 0x40),
|
||||
SENSOR_ATTR_2(temp1_crit_alarm, S_IRUGO, show_bit, NULL, 0x02, 0x01),
|
||||
|
||||
SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_bit, NULL, 0x02, 0x04),
|
||||
SENSOR_ATTR_2(temp2_min_alarm, S_IRUGO, show_bit, NULL, 0x02, 0x08),
|
||||
SENSOR_ATTR_2(temp2_max_alarm, S_IRUGO, show_bit, NULL, 0x02, 0x10),
|
||||
SENSOR_ATTR_2(temp2_crit_alarm, S_IRUGO, show_bit, NULL, 0x02, 0x02),
|
||||
};
|
||||
|
||||
static struct attribute *emc1402_alarm_attrs[] = {
|
||||
&emc1402_alarms[0].dev_attr.attr,
|
||||
&emc1402_alarms[1].dev_attr.attr,
|
||||
&emc1402_alarms[2].dev_attr.attr,
|
||||
&emc1402_alarms[3].dev_attr.attr,
|
||||
&emc1402_alarms[4].dev_attr.attr,
|
||||
&emc1402_alarms[5].dev_attr.attr,
|
||||
&emc1402_alarms[6].dev_attr.attr,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static const struct attribute_group emc1402_alarm_group = {
|
||||
.attrs = emc1402_alarm_attrs,
|
||||
};
|
||||
|
||||
static int emc1403_detect(struct i2c_client *client,
|
||||
struct i2c_board_info *info)
|
||||
{
|
||||
@@ -313,9 +365,15 @@ static int emc1403_detect(struct i2c_client *client,
|
||||
|
||||
id = i2c_smbus_read_byte_data(client, THERMAL_PID_REG);
|
||||
switch (id) {
|
||||
case 0x20:
|
||||
strlcpy(info->type, "emc1402", I2C_NAME_SIZE);
|
||||
break;
|
||||
case 0x21:
|
||||
strlcpy(info->type, "emc1403", I2C_NAME_SIZE);
|
||||
break;
|
||||
case 0x22:
|
||||
strlcpy(info->type, "emc1422", I2C_NAME_SIZE);
|
||||
break;
|
||||
case 0x23:
|
||||
strlcpy(info->type, "emc1423", I2C_NAME_SIZE);
|
||||
break;
|
||||
@@ -336,6 +394,35 @@ static int emc1403_detect(struct i2c_client *client,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool emc1403_regmap_is_volatile(struct device *dev, unsigned int reg)
|
||||
{
|
||||
switch (reg) {
|
||||
case 0x00: /* internal diode high byte */
|
||||
case 0x01: /* external diode 1 high byte */
|
||||
case 0x02: /* status */
|
||||
case 0x10: /* external diode 1 low byte */
|
||||
case 0x1b: /* external diode fault */
|
||||
case 0x23: /* external diode 2 high byte */
|
||||
case 0x24: /* external diode 2 low byte */
|
||||
case 0x29: /* internal diode low byte */
|
||||
case 0x2a: /* externl diode 3 high byte */
|
||||
case 0x2b: /* external diode 3 low byte */
|
||||
case 0x35: /* high limit status */
|
||||
case 0x36: /* low limit status */
|
||||
case 0x37: /* therm limit status */
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static struct regmap_config emc1403_regmap_config = {
|
||||
.reg_bits = 8,
|
||||
.val_bits = 8,
|
||||
.cache_type = REGCACHE_RBTREE,
|
||||
.volatile_reg = emc1403_regmap_is_volatile,
|
||||
};
|
||||
|
||||
static int emc1403_probe(struct i2c_client *client,
|
||||
const struct i2c_device_id *id)
|
||||
{
|
||||
@@ -347,13 +434,23 @@ static int emc1403_probe(struct i2c_client *client,
|
||||
if (data == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
data->client = client;
|
||||
mutex_init(&data->mutex);
|
||||
data->hyst_valid = jiffies - 1; /* Expired */
|
||||
data->regmap = devm_regmap_init_i2c(client, &emc1403_regmap_config);
|
||||
if (IS_ERR(data->regmap))
|
||||
return PTR_ERR(data->regmap);
|
||||
|
||||
data->groups[0] = &emc1403_group;
|
||||
if (id->driver_data)
|
||||
data->groups[1] = &emc1404_group;
|
||||
mutex_init(&data->mutex);
|
||||
|
||||
switch (id->driver_data) {
|
||||
case emc1404:
|
||||
data->groups[2] = &emc1404_group;
|
||||
case emc1403:
|
||||
data->groups[1] = &emc1403_group;
|
||||
case emc1402:
|
||||
data->groups[0] = &emc1402_group;
|
||||
}
|
||||
|
||||
if (id->driver_data == emc1402)
|
||||
data->groups[1] = &emc1402_alarm_group;
|
||||
|
||||
hwmon_dev = devm_hwmon_device_register_with_groups(&client->dev,
|
||||
client->name, data,
|
||||
@@ -366,14 +463,20 @@ static int emc1403_probe(struct i2c_client *client,
|
||||
}
|
||||
|
||||
static const unsigned short emc1403_address_list[] = {
|
||||
0x18, 0x29, 0x4c, 0x4d, I2C_CLIENT_END
|
||||
0x18, 0x1c, 0x29, 0x4c, 0x4d, 0x5c, I2C_CLIENT_END
|
||||
};
|
||||
|
||||
/* Last digit of chip name indicates number of channels */
|
||||
static const struct i2c_device_id emc1403_idtable[] = {
|
||||
{ "emc1403", 0 },
|
||||
{ "emc1404", 1 },
|
||||
{ "emc1423", 0 },
|
||||
{ "emc1424", 1 },
|
||||
{ "emc1402", emc1402 },
|
||||
{ "emc1403", emc1403 },
|
||||
{ "emc1404", emc1404 },
|
||||
{ "emc1412", emc1402 },
|
||||
{ "emc1413", emc1403 },
|
||||
{ "emc1414", emc1404 },
|
||||
{ "emc1422", emc1402 },
|
||||
{ "emc1423", emc1403 },
|
||||
{ "emc1424", emc1404 },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, emc1403_idtable);
|
||||
|
||||
@@ -1387,10 +1387,8 @@ static int f71805f_probe(struct platform_device *pdev)
|
||||
|
||||
data = devm_kzalloc(&pdev->dev, sizeof(struct f71805f_data),
|
||||
GFP_KERNEL);
|
||||
if (!data) {
|
||||
pr_err("Out of memory\n");
|
||||
if (!data)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
res = platform_get_resource(pdev, IORESOURCE_IO, 0);
|
||||
if (!devm_request_region(&pdev->dev, res->start + ADDR_REG_OFFSET, 2,
|
||||
|
||||
@@ -586,7 +586,7 @@ static int do_set_fan_startv(struct device *dev, unsigned long val)
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_OF
|
||||
static struct of_device_id g762_dt_match[] = {
|
||||
static const struct of_device_id g762_dt_match[] = {
|
||||
{ .compatible = "gmt,g762" },
|
||||
{ .compatible = "gmt,g763" },
|
||||
{ },
|
||||
|
||||
@@ -482,7 +482,7 @@ static int gpio_fan_get_of_pdata(struct device *dev,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct of_device_id of_gpio_fan_match[] = {
|
||||
static const struct of_device_id of_gpio_fan_match[] = {
|
||||
{ .compatible = "gpio-fan", },
|
||||
{},
|
||||
};
|
||||
|
||||
@@ -463,10 +463,8 @@ static void ibmpex_register_bmc(int iface, struct device *dev)
|
||||
int err;
|
||||
|
||||
data = kzalloc(sizeof(*data), GFP_KERNEL);
|
||||
if (!data) {
|
||||
dev_err(dev, "Insufficient memory for BMC interface.\n");
|
||||
if (!data)
|
||||
return;
|
||||
}
|
||||
|
||||
data->address.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
|
||||
data->address.channel = IPMI_BMC_CHANNEL;
|
||||
|
||||
@@ -163,7 +163,7 @@ static int iio_hwmon_remove(struct platform_device *pdev)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct of_device_id iio_hwmon_of_match[] = {
|
||||
static const struct of_device_id iio_hwmon_of_match[] = {
|
||||
{ .compatible = "iio-hwmon", },
|
||||
{ }
|
||||
};
|
||||
|
||||
+146
-183
@@ -65,6 +65,7 @@ static const unsigned short normal_i2c[] = {
|
||||
/* Manufacturer IDs */
|
||||
#define ADT_MANID 0x11d4 /* Analog Devices */
|
||||
#define ATMEL_MANID 0x001f /* Atmel */
|
||||
#define ATMEL_MANID2 0x1114 /* Atmel */
|
||||
#define MAX_MANID 0x004d /* Maxim */
|
||||
#define IDT_MANID 0x00b3 /* IDT */
|
||||
#define MCP_MANID 0x0054 /* Microchip */
|
||||
@@ -82,6 +83,9 @@ static const unsigned short normal_i2c[] = {
|
||||
#define AT30TS00_DEVID 0x8201
|
||||
#define AT30TS00_DEVID_MASK 0xffff
|
||||
|
||||
#define AT30TSE004_DEVID 0x2200
|
||||
#define AT30TSE004_DEVID_MASK 0xffff
|
||||
|
||||
/* IDT */
|
||||
#define TS3000B3_DEVID 0x2903 /* Also matches TSE2002B3 */
|
||||
#define TS3000B3_DEVID_MASK 0xffff
|
||||
@@ -130,6 +134,9 @@ static const unsigned short normal_i2c[] = {
|
||||
#define STTS2002_DEVID 0x0300
|
||||
#define STTS2002_DEVID_MASK 0xffff
|
||||
|
||||
#define STTS2004_DEVID 0x2201
|
||||
#define STTS2004_DEVID_MASK 0xffff
|
||||
|
||||
#define STTS3000_DEVID 0x0200
|
||||
#define STTS3000_DEVID_MASK 0xffff
|
||||
|
||||
@@ -144,6 +151,7 @@ struct jc42_chips {
|
||||
static struct jc42_chips jc42_chips[] = {
|
||||
{ ADT_MANID, ADT7408_DEVID, ADT7408_DEVID_MASK },
|
||||
{ ATMEL_MANID, AT30TS00_DEVID, AT30TS00_DEVID_MASK },
|
||||
{ ATMEL_MANID2, AT30TSE004_DEVID, AT30TSE004_DEVID_MASK },
|
||||
{ IDT_MANID, TS3000B3_DEVID, TS3000B3_DEVID_MASK },
|
||||
{ IDT_MANID, TS3000GB2_DEVID, TS3000GB2_DEVID_MASK },
|
||||
{ MAX_MANID, MAX6604_DEVID, MAX6604_DEVID_MASK },
|
||||
@@ -158,9 +166,25 @@ static struct jc42_chips jc42_chips[] = {
|
||||
{ STM_MANID, STTS424_DEVID, STTS424_DEVID_MASK },
|
||||
{ STM_MANID, STTS424E_DEVID, STTS424E_DEVID_MASK },
|
||||
{ STM_MANID, STTS2002_DEVID, STTS2002_DEVID_MASK },
|
||||
{ STM_MANID, STTS2004_DEVID, STTS2004_DEVID_MASK },
|
||||
{ STM_MANID, STTS3000_DEVID, STTS3000_DEVID_MASK },
|
||||
};
|
||||
|
||||
enum temp_index {
|
||||
t_input = 0,
|
||||
t_crit,
|
||||
t_min,
|
||||
t_max,
|
||||
t_num_temp
|
||||
};
|
||||
|
||||
static const u8 temp_regs[t_num_temp] = {
|
||||
[t_input] = JC42_REG_TEMP,
|
||||
[t_crit] = JC42_REG_TEMP_CRITICAL,
|
||||
[t_min] = JC42_REG_TEMP_LOWER,
|
||||
[t_max] = JC42_REG_TEMP_UPPER,
|
||||
};
|
||||
|
||||
/* Each client has this additional data */
|
||||
struct jc42_data {
|
||||
struct i2c_client *client;
|
||||
@@ -170,69 +194,7 @@ struct jc42_data {
|
||||
unsigned long last_updated; /* In jiffies */
|
||||
u16 orig_config; /* original configuration */
|
||||
u16 config; /* current configuration */
|
||||
u16 temp_input; /* Temperatures */
|
||||
u16 temp_crit;
|
||||
u16 temp_min;
|
||||
u16 temp_max;
|
||||
};
|
||||
|
||||
static int jc42_probe(struct i2c_client *client,
|
||||
const struct i2c_device_id *id);
|
||||
static int jc42_detect(struct i2c_client *client, struct i2c_board_info *info);
|
||||
static int jc42_remove(struct i2c_client *client);
|
||||
|
||||
static struct jc42_data *jc42_update_device(struct device *dev);
|
||||
|
||||
static const struct i2c_device_id jc42_id[] = {
|
||||
{ "jc42", 0 },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, jc42_id);
|
||||
|
||||
#ifdef CONFIG_PM
|
||||
|
||||
static int jc42_suspend(struct device *dev)
|
||||
{
|
||||
struct jc42_data *data = dev_get_drvdata(dev);
|
||||
|
||||
data->config |= JC42_CFG_SHUTDOWN;
|
||||
i2c_smbus_write_word_swapped(data->client, JC42_REG_CONFIG,
|
||||
data->config);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int jc42_resume(struct device *dev)
|
||||
{
|
||||
struct jc42_data *data = dev_get_drvdata(dev);
|
||||
|
||||
data->config &= ~JC42_CFG_SHUTDOWN;
|
||||
i2c_smbus_write_word_swapped(data->client, JC42_REG_CONFIG,
|
||||
data->config);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct dev_pm_ops jc42_dev_pm_ops = {
|
||||
.suspend = jc42_suspend,
|
||||
.resume = jc42_resume,
|
||||
};
|
||||
|
||||
#define JC42_DEV_PM_OPS (&jc42_dev_pm_ops)
|
||||
#else
|
||||
#define JC42_DEV_PM_OPS NULL
|
||||
#endif /* CONFIG_PM */
|
||||
|
||||
/* This is the driver that will be inserted */
|
||||
static struct i2c_driver jc42_driver = {
|
||||
.class = I2C_CLASS_SPD,
|
||||
.driver = {
|
||||
.name = "jc42",
|
||||
.pm = JC42_DEV_PM_OPS,
|
||||
},
|
||||
.probe = jc42_probe,
|
||||
.remove = jc42_remove,
|
||||
.id_table = jc42_id,
|
||||
.detect = jc42_detect,
|
||||
.address_list = normal_i2c,
|
||||
u16 temp[t_num_temp];/* Temperatures */
|
||||
};
|
||||
|
||||
#define JC42_TEMP_MIN_EXTENDED (-40000)
|
||||
@@ -261,80 +223,82 @@ static int jc42_temp_from_reg(s16 reg)
|
||||
return reg * 125 / 2;
|
||||
}
|
||||
|
||||
/* sysfs stuff */
|
||||
static struct jc42_data *jc42_update_device(struct device *dev)
|
||||
{
|
||||
struct jc42_data *data = dev_get_drvdata(dev);
|
||||
struct i2c_client *client = data->client;
|
||||
struct jc42_data *ret = data;
|
||||
int i, val;
|
||||
|
||||
/* read routines for temperature limits */
|
||||
#define show(value) \
|
||||
static ssize_t show_##value(struct device *dev, \
|
||||
struct device_attribute *attr, \
|
||||
char *buf) \
|
||||
{ \
|
||||
struct jc42_data *data = jc42_update_device(dev); \
|
||||
if (IS_ERR(data)) \
|
||||
return PTR_ERR(data); \
|
||||
return sprintf(buf, "%d\n", jc42_temp_from_reg(data->value)); \
|
||||
mutex_lock(&data->update_lock);
|
||||
|
||||
if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
|
||||
for (i = 0; i < t_num_temp; i++) {
|
||||
val = i2c_smbus_read_word_swapped(client, temp_regs[i]);
|
||||
if (val < 0) {
|
||||
ret = ERR_PTR(val);
|
||||
goto abort;
|
||||
}
|
||||
data->temp[i] = val;
|
||||
}
|
||||
data->last_updated = jiffies;
|
||||
data->valid = true;
|
||||
}
|
||||
abort:
|
||||
mutex_unlock(&data->update_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
show(temp_input);
|
||||
show(temp_crit);
|
||||
show(temp_min);
|
||||
show(temp_max);
|
||||
/* sysfs functions */
|
||||
|
||||
/* read routines for hysteresis values */
|
||||
static ssize_t show_temp_crit_hyst(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
|
||||
char *buf)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
|
||||
struct jc42_data *data = jc42_update_device(dev);
|
||||
if (IS_ERR(data))
|
||||
return PTR_ERR(data);
|
||||
return sprintf(buf, "%d\n",
|
||||
jc42_temp_from_reg(data->temp[attr->index]));
|
||||
}
|
||||
|
||||
static ssize_t show_temp_hyst(struct device *dev,
|
||||
struct device_attribute *devattr, char *buf)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
|
||||
struct jc42_data *data = jc42_update_device(dev);
|
||||
int temp, hyst;
|
||||
|
||||
if (IS_ERR(data))
|
||||
return PTR_ERR(data);
|
||||
|
||||
temp = jc42_temp_from_reg(data->temp_crit);
|
||||
temp = jc42_temp_from_reg(data->temp[attr->index]);
|
||||
hyst = jc42_hysteresis[(data->config & JC42_CFG_HYST_MASK)
|
||||
>> JC42_CFG_HYST_SHIFT];
|
||||
return sprintf(buf, "%d\n", temp - hyst);
|
||||
}
|
||||
|
||||
static ssize_t show_temp_max_hyst(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
static ssize_t set_temp(struct device *dev, struct device_attribute *devattr,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
struct jc42_data *data = jc42_update_device(dev);
|
||||
int temp, hyst;
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
|
||||
struct jc42_data *data = dev_get_drvdata(dev);
|
||||
int err, ret = count;
|
||||
int nr = attr->index;
|
||||
long val;
|
||||
|
||||
if (IS_ERR(data))
|
||||
return PTR_ERR(data);
|
||||
|
||||
temp = jc42_temp_from_reg(data->temp_max);
|
||||
hyst = jc42_hysteresis[(data->config & JC42_CFG_HYST_MASK)
|
||||
>> JC42_CFG_HYST_SHIFT];
|
||||
return sprintf(buf, "%d\n", temp - hyst);
|
||||
if (kstrtol(buf, 10, &val) < 0)
|
||||
return -EINVAL;
|
||||
mutex_lock(&data->update_lock);
|
||||
data->temp[nr] = jc42_temp_to_reg(val, data->extended);
|
||||
err = i2c_smbus_write_word_swapped(data->client, temp_regs[nr],
|
||||
data->temp[nr]);
|
||||
if (err < 0)
|
||||
ret = err;
|
||||
mutex_unlock(&data->update_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* write routines */
|
||||
#define set(value, reg) \
|
||||
static ssize_t set_##value(struct device *dev, \
|
||||
struct device_attribute *attr, \
|
||||
const char *buf, size_t count) \
|
||||
{ \
|
||||
struct jc42_data *data = dev_get_drvdata(dev); \
|
||||
int err, ret = count; \
|
||||
long val; \
|
||||
if (kstrtol(buf, 10, &val) < 0) \
|
||||
return -EINVAL; \
|
||||
mutex_lock(&data->update_lock); \
|
||||
data->value = jc42_temp_to_reg(val, data->extended); \
|
||||
err = i2c_smbus_write_word_swapped(data->client, reg, data->value); \
|
||||
if (err < 0) \
|
||||
ret = err; \
|
||||
mutex_unlock(&data->update_lock); \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
set(temp_min, JC42_REG_TEMP_LOWER);
|
||||
set(temp_max, JC42_REG_TEMP_UPPER);
|
||||
set(temp_crit, JC42_REG_TEMP_CRITICAL);
|
||||
|
||||
/*
|
||||
* JC42.4 compliant chips only support four hysteresis values.
|
||||
* Pick best choice and go from there.
|
||||
@@ -352,7 +316,7 @@ static ssize_t set_temp_crit_hyst(struct device *dev,
|
||||
if (kstrtoul(buf, 10, &val) < 0)
|
||||
return -EINVAL;
|
||||
|
||||
diff = jc42_temp_from_reg(data->temp_crit) - val;
|
||||
diff = jc42_temp_from_reg(data->temp[t_crit]) - val;
|
||||
hyst = 0;
|
||||
if (diff > 0) {
|
||||
if (diff < 2250)
|
||||
@@ -384,25 +348,20 @@ static ssize_t show_alarm(struct device *dev,
|
||||
if (IS_ERR(data))
|
||||
return PTR_ERR(data);
|
||||
|
||||
val = data->temp_input;
|
||||
val = data->temp[t_input];
|
||||
if (bit != JC42_ALARM_CRIT_BIT && (data->config & JC42_CFG_CRIT_ONLY))
|
||||
val = 0;
|
||||
return sprintf(buf, "%u\n", (val >> bit) & 1);
|
||||
}
|
||||
|
||||
static DEVICE_ATTR(temp1_input, S_IRUGO,
|
||||
show_temp_input, NULL);
|
||||
static DEVICE_ATTR(temp1_crit, S_IRUGO,
|
||||
show_temp_crit, set_temp_crit);
|
||||
static DEVICE_ATTR(temp1_min, S_IRUGO,
|
||||
show_temp_min, set_temp_min);
|
||||
static DEVICE_ATTR(temp1_max, S_IRUGO,
|
||||
show_temp_max, set_temp_max);
|
||||
static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, t_input);
|
||||
static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, show_temp, set_temp, t_crit);
|
||||
static SENSOR_DEVICE_ATTR(temp1_min, S_IRUGO, show_temp, set_temp, t_min);
|
||||
static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO, show_temp, set_temp, t_max);
|
||||
|
||||
static DEVICE_ATTR(temp1_crit_hyst, S_IRUGO,
|
||||
show_temp_crit_hyst, set_temp_crit_hyst);
|
||||
static DEVICE_ATTR(temp1_max_hyst, S_IRUGO,
|
||||
show_temp_max_hyst, NULL);
|
||||
static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IRUGO, show_temp_hyst,
|
||||
set_temp_crit_hyst, t_crit);
|
||||
static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO, show_temp_hyst, NULL, t_max);
|
||||
|
||||
static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL,
|
||||
JC42_ALARM_CRIT_BIT);
|
||||
@@ -412,12 +371,12 @@ static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL,
|
||||
JC42_ALARM_MAX_BIT);
|
||||
|
||||
static struct attribute *jc42_attributes[] = {
|
||||
&dev_attr_temp1_input.attr,
|
||||
&dev_attr_temp1_crit.attr,
|
||||
&dev_attr_temp1_min.attr,
|
||||
&dev_attr_temp1_max.attr,
|
||||
&dev_attr_temp1_crit_hyst.attr,
|
||||
&dev_attr_temp1_max_hyst.attr,
|
||||
&sensor_dev_attr_temp1_input.dev_attr.attr,
|
||||
&sensor_dev_attr_temp1_crit.dev_attr.attr,
|
||||
&sensor_dev_attr_temp1_min.dev_attr.attr,
|
||||
&sensor_dev_attr_temp1_max.dev_attr.attr,
|
||||
&sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
|
||||
&sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
|
||||
&sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
|
||||
&sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
|
||||
&sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
|
||||
@@ -432,12 +391,12 @@ static umode_t jc42_attribute_mode(struct kobject *kobj,
|
||||
unsigned int config = data->config;
|
||||
bool readonly;
|
||||
|
||||
if (attr == &dev_attr_temp1_crit.attr)
|
||||
if (attr == &sensor_dev_attr_temp1_crit.dev_attr.attr)
|
||||
readonly = config & JC42_CFG_TCRIT_LOCK;
|
||||
else if (attr == &dev_attr_temp1_min.attr ||
|
||||
attr == &dev_attr_temp1_max.attr)
|
||||
else if (attr == &sensor_dev_attr_temp1_min.dev_attr.attr ||
|
||||
attr == &sensor_dev_attr_temp1_max.dev_attr.attr)
|
||||
readonly = config & JC42_CFG_EVENT_LOCK;
|
||||
else if (attr == &dev_attr_temp1_crit_hyst.attr)
|
||||
else if (attr == &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr)
|
||||
readonly = config & (JC42_CFG_EVENT_LOCK | JC42_CFG_TCRIT_LOCK);
|
||||
else
|
||||
readonly = true;
|
||||
@@ -537,53 +496,57 @@ static int jc42_remove(struct i2c_client *client)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct jc42_data *jc42_update_device(struct device *dev)
|
||||
#ifdef CONFIG_PM
|
||||
|
||||
static int jc42_suspend(struct device *dev)
|
||||
{
|
||||
struct jc42_data *data = dev_get_drvdata(dev);
|
||||
struct i2c_client *client = data->client;
|
||||
struct jc42_data *ret = data;
|
||||
int val;
|
||||
|
||||
mutex_lock(&data->update_lock);
|
||||
|
||||
if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
|
||||
val = i2c_smbus_read_word_swapped(client, JC42_REG_TEMP);
|
||||
if (val < 0) {
|
||||
ret = ERR_PTR(val);
|
||||
goto abort;
|
||||
}
|
||||
data->temp_input = val;
|
||||
|
||||
val = i2c_smbus_read_word_swapped(client,
|
||||
JC42_REG_TEMP_CRITICAL);
|
||||
if (val < 0) {
|
||||
ret = ERR_PTR(val);
|
||||
goto abort;
|
||||
}
|
||||
data->temp_crit = val;
|
||||
|
||||
val = i2c_smbus_read_word_swapped(client, JC42_REG_TEMP_LOWER);
|
||||
if (val < 0) {
|
||||
ret = ERR_PTR(val);
|
||||
goto abort;
|
||||
}
|
||||
data->temp_min = val;
|
||||
|
||||
val = i2c_smbus_read_word_swapped(client, JC42_REG_TEMP_UPPER);
|
||||
if (val < 0) {
|
||||
ret = ERR_PTR(val);
|
||||
goto abort;
|
||||
}
|
||||
data->temp_max = val;
|
||||
|
||||
data->last_updated = jiffies;
|
||||
data->valid = true;
|
||||
}
|
||||
abort:
|
||||
mutex_unlock(&data->update_lock);
|
||||
return ret;
|
||||
data->config |= JC42_CFG_SHUTDOWN;
|
||||
i2c_smbus_write_word_swapped(data->client, JC42_REG_CONFIG,
|
||||
data->config);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int jc42_resume(struct device *dev)
|
||||
{
|
||||
struct jc42_data *data = dev_get_drvdata(dev);
|
||||
|
||||
data->config &= ~JC42_CFG_SHUTDOWN;
|
||||
i2c_smbus_write_word_swapped(data->client, JC42_REG_CONFIG,
|
||||
data->config);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct dev_pm_ops jc42_dev_pm_ops = {
|
||||
.suspend = jc42_suspend,
|
||||
.resume = jc42_resume,
|
||||
};
|
||||
|
||||
#define JC42_DEV_PM_OPS (&jc42_dev_pm_ops)
|
||||
#else
|
||||
#define JC42_DEV_PM_OPS NULL
|
||||
#endif /* CONFIG_PM */
|
||||
|
||||
static const struct i2c_device_id jc42_id[] = {
|
||||
{ "jc42", 0 },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, jc42_id);
|
||||
|
||||
static struct i2c_driver jc42_driver = {
|
||||
.class = I2C_CLASS_SPD,
|
||||
.driver = {
|
||||
.name = "jc42",
|
||||
.pm = JC42_DEV_PM_OPS,
|
||||
},
|
||||
.probe = jc42_probe,
|
||||
.remove = jc42_remove,
|
||||
.id_table = jc42_id,
|
||||
.detect = jc42_detect,
|
||||
.address_list = normal_i2c,
|
||||
};
|
||||
|
||||
module_i2c_driver(jc42_driver);
|
||||
|
||||
MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>");
|
||||
|
||||
+14
-48
@@ -47,7 +47,7 @@
|
||||
#define LM70_CHIP_LM74 3 /* NS LM74 */
|
||||
|
||||
struct lm70 {
|
||||
struct device *hwmon_dev;
|
||||
struct spi_device *spi;
|
||||
struct mutex lock;
|
||||
unsigned int chip;
|
||||
};
|
||||
@@ -56,11 +56,11 @@ struct lm70 {
|
||||
static ssize_t lm70_sense_temp(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct spi_device *spi = to_spi_device(dev);
|
||||
struct lm70 *p_lm70 = dev_get_drvdata(dev);
|
||||
struct spi_device *spi = p_lm70->spi;
|
||||
int status, val = 0;
|
||||
u8 rxbuf[2];
|
||||
s16 raw = 0;
|
||||
struct lm70 *p_lm70 = spi_get_drvdata(spi);
|
||||
|
||||
if (mutex_lock_interruptible(&p_lm70->lock))
|
||||
return -ERESTARTSYS;
|
||||
@@ -121,21 +121,20 @@ out:
|
||||
|
||||
static DEVICE_ATTR(temp1_input, S_IRUGO, lm70_sense_temp, NULL);
|
||||
|
||||
static ssize_t lm70_show_name(struct device *dev, struct device_attribute
|
||||
*devattr, char *buf)
|
||||
{
|
||||
return sprintf(buf, "%s\n", to_spi_device(dev)->modalias);
|
||||
}
|
||||
static struct attribute *lm70_attrs[] = {
|
||||
&dev_attr_temp1_input.attr,
|
||||
NULL
|
||||
};
|
||||
|
||||
static DEVICE_ATTR(name, S_IRUGO, lm70_show_name, NULL);
|
||||
ATTRIBUTE_GROUPS(lm70);
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
static int lm70_probe(struct spi_device *spi)
|
||||
{
|
||||
int chip = spi_get_device_id(spi)->driver_data;
|
||||
struct device *hwmon_dev;
|
||||
struct lm70 *p_lm70;
|
||||
int status;
|
||||
|
||||
/* signaling is SPI_MODE_0 */
|
||||
if (spi->mode & (SPI_CPOL | SPI_CPHA))
|
||||
@@ -149,46 +148,14 @@ static int lm70_probe(struct spi_device *spi)
|
||||
|
||||
mutex_init(&p_lm70->lock);
|
||||
p_lm70->chip = chip;
|
||||
p_lm70->spi = spi;
|
||||
|
||||
spi_set_drvdata(spi, p_lm70);
|
||||
|
||||
status = device_create_file(&spi->dev, &dev_attr_temp1_input);
|
||||
if (status)
|
||||
goto out_dev_create_temp_file_failed;
|
||||
status = device_create_file(&spi->dev, &dev_attr_name);
|
||||
if (status)
|
||||
goto out_dev_create_file_failed;
|
||||
|
||||
/* sysfs hook */
|
||||
p_lm70->hwmon_dev = hwmon_device_register(&spi->dev);
|
||||
if (IS_ERR(p_lm70->hwmon_dev)) {
|
||||
dev_dbg(&spi->dev, "hwmon_device_register failed.\n");
|
||||
status = PTR_ERR(p_lm70->hwmon_dev);
|
||||
goto out_dev_reg_failed;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
out_dev_reg_failed:
|
||||
device_remove_file(&spi->dev, &dev_attr_name);
|
||||
out_dev_create_file_failed:
|
||||
device_remove_file(&spi->dev, &dev_attr_temp1_input);
|
||||
out_dev_create_temp_file_failed:
|
||||
return status;
|
||||
hwmon_dev = devm_hwmon_device_register_with_groups(&spi->dev,
|
||||
spi->modalias,
|
||||
p_lm70, lm70_groups);
|
||||
return PTR_ERR_OR_ZERO(hwmon_dev);
|
||||
}
|
||||
|
||||
static int lm70_remove(struct spi_device *spi)
|
||||
{
|
||||
struct lm70 *p_lm70 = spi_get_drvdata(spi);
|
||||
|
||||
hwmon_device_unregister(p_lm70->hwmon_dev);
|
||||
device_remove_file(&spi->dev, &dev_attr_temp1_input);
|
||||
device_remove_file(&spi->dev, &dev_attr_name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static const struct spi_device_id lm70_ids[] = {
|
||||
{ "lm70", LM70_CHIP_LM70 },
|
||||
{ "tmp121", LM70_CHIP_TMP121 },
|
||||
@@ -205,7 +172,6 @@ static struct spi_driver lm70_driver = {
|
||||
},
|
||||
.id_table = lm70_ids,
|
||||
.probe = lm70_probe,
|
||||
.remove = lm70_remove,
|
||||
};
|
||||
|
||||
module_spi_driver(lm70_driver);
|
||||
|
||||
+20
-31
@@ -72,6 +72,7 @@ static const u8 LM75_REG_TEMP[3] = {
|
||||
|
||||
/* Each client has this additional data */
|
||||
struct lm75_data {
|
||||
struct i2c_client *client;
|
||||
struct device *hwmon_dev;
|
||||
struct thermal_zone_device *tz;
|
||||
struct mutex update_lock;
|
||||
@@ -130,8 +131,8 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct lm75_data *data = i2c_get_clientdata(client);
|
||||
struct lm75_data *data = dev_get_drvdata(dev);
|
||||
struct i2c_client *client = data->client;
|
||||
int nr = attr->index;
|
||||
long temp;
|
||||
int error;
|
||||
@@ -165,17 +166,14 @@ static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO,
|
||||
show_temp, set_temp, 2);
|
||||
static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
|
||||
|
||||
static struct attribute *lm75_attributes[] = {
|
||||
static struct attribute *lm75_attrs[] = {
|
||||
&sensor_dev_attr_temp1_input.dev_attr.attr,
|
||||
&sensor_dev_attr_temp1_max.dev_attr.attr,
|
||||
&sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
|
||||
|
||||
NULL
|
||||
};
|
||||
|
||||
static const struct attribute_group lm75_group = {
|
||||
.attrs = lm75_attributes,
|
||||
};
|
||||
ATTRIBUTE_GROUPS(lm75);
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
@@ -184,6 +182,7 @@ static const struct attribute_group lm75_group = {
|
||||
static int
|
||||
lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)
|
||||
{
|
||||
struct device *dev = &client->dev;
|
||||
struct lm75_data *data;
|
||||
int status;
|
||||
u8 set_mask, clr_mask;
|
||||
@@ -194,10 +193,11 @@ lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)
|
||||
I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA))
|
||||
return -EIO;
|
||||
|
||||
data = devm_kzalloc(&client->dev, sizeof(struct lm75_data), GFP_KERNEL);
|
||||
data = devm_kzalloc(dev, sizeof(struct lm75_data), GFP_KERNEL);
|
||||
if (!data)
|
||||
return -ENOMEM;
|
||||
|
||||
data->client = client;
|
||||
i2c_set_clientdata(client, data);
|
||||
mutex_init(&data->update_lock);
|
||||
|
||||
@@ -269,7 +269,7 @@ lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)
|
||||
/* configure as specified */
|
||||
status = lm75_read_value(client, LM75_REG_CONF);
|
||||
if (status < 0) {
|
||||
dev_dbg(&client->dev, "Can't read config? %d\n", status);
|
||||
dev_dbg(dev, "Can't read config? %d\n", status);
|
||||
return status;
|
||||
}
|
||||
data->orig_conf = status;
|
||||
@@ -277,43 +277,32 @@ lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)
|
||||
new |= set_mask;
|
||||
if (status != new)
|
||||
lm75_write_value(client, LM75_REG_CONF, new);
|
||||
dev_dbg(&client->dev, "Config %02x\n", new);
|
||||
dev_dbg(dev, "Config %02x\n", new);
|
||||
|
||||
/* Register sysfs hooks */
|
||||
status = sysfs_create_group(&client->dev.kobj, &lm75_group);
|
||||
if (status)
|
||||
return status;
|
||||
data->hwmon_dev = hwmon_device_register_with_groups(dev, client->name,
|
||||
data, lm75_groups);
|
||||
if (IS_ERR(data->hwmon_dev))
|
||||
return PTR_ERR(data->hwmon_dev);
|
||||
|
||||
data->hwmon_dev = hwmon_device_register(&client->dev);
|
||||
if (IS_ERR(data->hwmon_dev)) {
|
||||
status = PTR_ERR(data->hwmon_dev);
|
||||
goto exit_remove;
|
||||
}
|
||||
|
||||
data->tz = thermal_zone_of_sensor_register(&client->dev,
|
||||
data->tz = thermal_zone_of_sensor_register(data->hwmon_dev,
|
||||
0,
|
||||
&client->dev,
|
||||
data->hwmon_dev,
|
||||
lm75_read_temp, NULL);
|
||||
if (IS_ERR(data->tz))
|
||||
data->tz = NULL;
|
||||
|
||||
dev_info(&client->dev, "%s: sensor '%s'\n",
|
||||
dev_info(dev, "%s: sensor '%s'\n",
|
||||
dev_name(data->hwmon_dev), client->name);
|
||||
|
||||
return 0;
|
||||
|
||||
exit_remove:
|
||||
sysfs_remove_group(&client->dev.kobj, &lm75_group);
|
||||
return status;
|
||||
}
|
||||
|
||||
static int lm75_remove(struct i2c_client *client)
|
||||
{
|
||||
struct lm75_data *data = i2c_get_clientdata(client);
|
||||
|
||||
thermal_zone_of_sensor_unregister(&client->dev, data->tz);
|
||||
thermal_zone_of_sensor_unregister(data->hwmon_dev, data->tz);
|
||||
hwmon_device_unregister(data->hwmon_dev);
|
||||
sysfs_remove_group(&client->dev.kobj, &lm75_group);
|
||||
lm75_write_value(client, LM75_REG_CONF, data->orig_conf);
|
||||
return 0;
|
||||
}
|
||||
@@ -507,8 +496,8 @@ static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value)
|
||||
|
||||
static struct lm75_data *lm75_update_device(struct device *dev)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct lm75_data *data = i2c_get_clientdata(client);
|
||||
struct lm75_data *data = dev_get_drvdata(dev);
|
||||
struct i2c_client *client = data->client;
|
||||
struct lm75_data *ret = data;
|
||||
|
||||
mutex_lock(&data->update_lock);
|
||||
|
||||
+155
-233
@@ -19,10 +19,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.
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
@@ -47,50 +43,33 @@ static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b,
|
||||
#define LM77_REG_TEMP_MIN 0x04
|
||||
#define LM77_REG_TEMP_MAX 0x05
|
||||
|
||||
enum temp_index {
|
||||
t_input = 0,
|
||||
t_crit,
|
||||
t_min,
|
||||
t_max,
|
||||
t_hyst,
|
||||
t_num_temp
|
||||
};
|
||||
|
||||
static const u8 temp_regs[t_num_temp] = {
|
||||
[t_input] = LM77_REG_TEMP,
|
||||
[t_min] = LM77_REG_TEMP_MIN,
|
||||
[t_max] = LM77_REG_TEMP_MAX,
|
||||
[t_crit] = LM77_REG_TEMP_CRIT,
|
||||
[t_hyst] = LM77_REG_TEMP_HYST,
|
||||
};
|
||||
|
||||
/* Each client has this additional data */
|
||||
struct lm77_data {
|
||||
struct device *hwmon_dev;
|
||||
struct i2c_client *client;
|
||||
struct mutex update_lock;
|
||||
char valid;
|
||||
unsigned long last_updated; /* In jiffies */
|
||||
int temp_input; /* Temperatures */
|
||||
int temp_crit;
|
||||
int temp_min;
|
||||
int temp_max;
|
||||
int temp_hyst;
|
||||
int temp[t_num_temp]; /* index using temp_index */
|
||||
u8 alarms;
|
||||
};
|
||||
|
||||
static int lm77_probe(struct i2c_client *client,
|
||||
const struct i2c_device_id *id);
|
||||
static int lm77_detect(struct i2c_client *client, struct i2c_board_info *info);
|
||||
static void lm77_init_client(struct i2c_client *client);
|
||||
static int lm77_remove(struct i2c_client *client);
|
||||
static u16 lm77_read_value(struct i2c_client *client, u8 reg);
|
||||
static int lm77_write_value(struct i2c_client *client, u8 reg, u16 value);
|
||||
|
||||
static struct lm77_data *lm77_update_device(struct device *dev);
|
||||
|
||||
|
||||
static const struct i2c_device_id lm77_id[] = {
|
||||
{ "lm77", 0 },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, lm77_id);
|
||||
|
||||
/* This is the driver that will be inserted */
|
||||
static struct i2c_driver lm77_driver = {
|
||||
.class = I2C_CLASS_HWMON,
|
||||
.driver = {
|
||||
.name = "lm77",
|
||||
},
|
||||
.probe = lm77_probe,
|
||||
.remove = lm77_remove,
|
||||
.id_table = lm77_id,
|
||||
.detect = lm77_detect,
|
||||
.address_list = normal_i2c,
|
||||
};
|
||||
|
||||
/* straight from the datasheet */
|
||||
#define LM77_TEMP_MIN (-55000)
|
||||
#define LM77_TEMP_MAX 125000
|
||||
@@ -110,97 +89,109 @@ static inline int LM77_TEMP_FROM_REG(s16 reg)
|
||||
return (reg / 8) * 500;
|
||||
}
|
||||
|
||||
/*
|
||||
* All registers are word-sized, except for the configuration register.
|
||||
* The LM77 uses the high-byte first convention.
|
||||
*/
|
||||
static u16 lm77_read_value(struct i2c_client *client, u8 reg)
|
||||
{
|
||||
if (reg == LM77_REG_CONF)
|
||||
return i2c_smbus_read_byte_data(client, reg);
|
||||
else
|
||||
return i2c_smbus_read_word_swapped(client, reg);
|
||||
}
|
||||
|
||||
static int lm77_write_value(struct i2c_client *client, u8 reg, u16 value)
|
||||
{
|
||||
if (reg == LM77_REG_CONF)
|
||||
return i2c_smbus_write_byte_data(client, reg, value);
|
||||
else
|
||||
return i2c_smbus_write_word_swapped(client, reg, value);
|
||||
}
|
||||
|
||||
static struct lm77_data *lm77_update_device(struct device *dev)
|
||||
{
|
||||
struct lm77_data *data = dev_get_drvdata(dev);
|
||||
struct i2c_client *client = data->client;
|
||||
int i;
|
||||
|
||||
mutex_lock(&data->update_lock);
|
||||
|
||||
if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
|
||||
|| !data->valid) {
|
||||
dev_dbg(&client->dev, "Starting lm77 update\n");
|
||||
for (i = 0; i < t_num_temp; i++) {
|
||||
data->temp[i] =
|
||||
LM77_TEMP_FROM_REG(lm77_read_value(client,
|
||||
temp_regs[i]));
|
||||
}
|
||||
data->alarms =
|
||||
lm77_read_value(client, LM77_REG_TEMP) & 0x0007;
|
||||
data->last_updated = jiffies;
|
||||
data->valid = 1;
|
||||
}
|
||||
|
||||
mutex_unlock(&data->update_lock);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/* sysfs stuff */
|
||||
|
||||
/* read routines for temperature limits */
|
||||
#define show(value) \
|
||||
static ssize_t show_##value(struct device *dev, \
|
||||
struct device_attribute *attr, \
|
||||
char *buf) \
|
||||
{ \
|
||||
struct lm77_data *data = lm77_update_device(dev); \
|
||||
return sprintf(buf, "%d\n", data->value); \
|
||||
}
|
||||
|
||||
show(temp_input);
|
||||
show(temp_crit);
|
||||
show(temp_min);
|
||||
show(temp_max);
|
||||
|
||||
/* read routines for hysteresis values */
|
||||
static ssize_t show_temp_crit_hyst(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
|
||||
char *buf)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
|
||||
struct lm77_data *data = lm77_update_device(dev);
|
||||
return sprintf(buf, "%d\n", data->temp_crit - data->temp_hyst);
|
||||
|
||||
return sprintf(buf, "%d\n", data->temp[attr->index]);
|
||||
}
|
||||
static ssize_t show_temp_min_hyst(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
|
||||
static ssize_t show_temp_hyst(struct device *dev,
|
||||
struct device_attribute *devattr, char *buf)
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
|
||||
struct lm77_data *data = lm77_update_device(dev);
|
||||
return sprintf(buf, "%d\n", data->temp_min + data->temp_hyst);
|
||||
int nr = attr->index;
|
||||
int temp;
|
||||
|
||||
temp = nr == t_min ? data->temp[nr] + data->temp[t_hyst] :
|
||||
data->temp[nr] - data->temp[t_hyst];
|
||||
|
||||
return sprintf(buf, "%d\n", temp);
|
||||
}
|
||||
static ssize_t show_temp_max_hyst(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
|
||||
static ssize_t set_temp(struct device *dev, struct device_attribute *devattr,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
struct lm77_data *data = lm77_update_device(dev);
|
||||
return sprintf(buf, "%d\n", data->temp_max - data->temp_hyst);
|
||||
}
|
||||
|
||||
/* write routines */
|
||||
#define set(value, reg) \
|
||||
static ssize_t set_##value(struct device *dev, struct device_attribute *attr, \
|
||||
const char *buf, size_t count) \
|
||||
{ \
|
||||
struct i2c_client *client = to_i2c_client(dev); \
|
||||
struct lm77_data *data = i2c_get_clientdata(client); \
|
||||
long val; \
|
||||
int err = kstrtol(buf, 10, &val); \
|
||||
if (err) \
|
||||
return err; \
|
||||
\
|
||||
mutex_lock(&data->update_lock); \
|
||||
data->value = val; \
|
||||
lm77_write_value(client, reg, LM77_TEMP_TO_REG(data->value)); \
|
||||
mutex_unlock(&data->update_lock); \
|
||||
return count; \
|
||||
}
|
||||
|
||||
set(temp_min, LM77_REG_TEMP_MIN);
|
||||
set(temp_max, LM77_REG_TEMP_MAX);
|
||||
|
||||
/*
|
||||
* hysteresis is stored as a relative value on the chip, so it has to be
|
||||
* converted first
|
||||
*/
|
||||
static ssize_t set_temp_crit_hyst(struct device *dev,
|
||||
struct device_attribute *attr,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct lm77_data *data = i2c_get_clientdata(client);
|
||||
unsigned long val;
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
|
||||
struct lm77_data *data = dev_get_drvdata(dev);
|
||||
struct i2c_client *client = data->client;
|
||||
int nr = attr->index;
|
||||
long val;
|
||||
int err;
|
||||
|
||||
err = kstrtoul(buf, 10, &val);
|
||||
err = kstrtol(buf, 10, &val);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
mutex_lock(&data->update_lock);
|
||||
data->temp_hyst = data->temp_crit - val;
|
||||
lm77_write_value(client, LM77_REG_TEMP_HYST,
|
||||
LM77_TEMP_TO_REG(data->temp_hyst));
|
||||
data->temp[nr] = val;
|
||||
lm77_write_value(client, temp_regs[nr], LM77_TEMP_TO_REG(val));
|
||||
mutex_unlock(&data->update_lock);
|
||||
return count;
|
||||
}
|
||||
|
||||
/* preserve hysteresis when setting T_crit */
|
||||
static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr,
|
||||
/*
|
||||
* hysteresis is stored as a relative value on the chip, so it has to be
|
||||
* converted first.
|
||||
*/
|
||||
static ssize_t set_temp_hyst(struct device *dev,
|
||||
struct device_attribute *devattr,
|
||||
const char *buf, size_t count)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct lm77_data *data = i2c_get_clientdata(client);
|
||||
int oldcrithyst;
|
||||
struct lm77_data *data = dev_get_drvdata(dev);
|
||||
struct i2c_client *client = data->client;
|
||||
unsigned long val;
|
||||
int err;
|
||||
|
||||
@@ -209,13 +200,9 @@ static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr,
|
||||
return err;
|
||||
|
||||
mutex_lock(&data->update_lock);
|
||||
oldcrithyst = data->temp_crit - data->temp_hyst;
|
||||
data->temp_crit = val;
|
||||
data->temp_hyst = data->temp_crit - oldcrithyst;
|
||||
lm77_write_value(client, LM77_REG_TEMP_CRIT,
|
||||
LM77_TEMP_TO_REG(data->temp_crit));
|
||||
data->temp[t_hyst] = data->temp[t_crit] - val;
|
||||
lm77_write_value(client, LM77_REG_TEMP_HYST,
|
||||
LM77_TEMP_TO_REG(data->temp_hyst));
|
||||
LM77_TEMP_TO_REG(data->temp[t_hyst]));
|
||||
mutex_unlock(&data->update_lock);
|
||||
return count;
|
||||
}
|
||||
@@ -228,43 +215,37 @@ static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
|
||||
return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
|
||||
}
|
||||
|
||||
static DEVICE_ATTR(temp1_input, S_IRUGO,
|
||||
show_temp_input, NULL);
|
||||
static DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO,
|
||||
show_temp_crit, set_temp_crit);
|
||||
static DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO,
|
||||
show_temp_min, set_temp_min);
|
||||
static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO,
|
||||
show_temp_max, set_temp_max);
|
||||
static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, t_input);
|
||||
static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp, set_temp,
|
||||
t_crit);
|
||||
static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp, set_temp,
|
||||
t_min);
|
||||
static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp, set_temp,
|
||||
t_max);
|
||||
|
||||
static DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO,
|
||||
show_temp_crit_hyst, set_temp_crit_hyst);
|
||||
static DEVICE_ATTR(temp1_min_hyst, S_IRUGO,
|
||||
show_temp_min_hyst, NULL);
|
||||
static DEVICE_ATTR(temp1_max_hyst, S_IRUGO,
|
||||
show_temp_max_hyst, NULL);
|
||||
static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temp_hyst,
|
||||
set_temp_hyst, t_crit);
|
||||
static SENSOR_DEVICE_ATTR(temp1_min_hyst, S_IRUGO, show_temp_hyst, NULL, t_min);
|
||||
static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO, show_temp_hyst, NULL, t_max);
|
||||
|
||||
static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 2);
|
||||
static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 0);
|
||||
static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 1);
|
||||
|
||||
static struct attribute *lm77_attributes[] = {
|
||||
&dev_attr_temp1_input.attr,
|
||||
&dev_attr_temp1_crit.attr,
|
||||
&dev_attr_temp1_min.attr,
|
||||
&dev_attr_temp1_max.attr,
|
||||
&dev_attr_temp1_crit_hyst.attr,
|
||||
&dev_attr_temp1_min_hyst.attr,
|
||||
&dev_attr_temp1_max_hyst.attr,
|
||||
static struct attribute *lm77_attrs[] = {
|
||||
&sensor_dev_attr_temp1_input.dev_attr.attr,
|
||||
&sensor_dev_attr_temp1_crit.dev_attr.attr,
|
||||
&sensor_dev_attr_temp1_min.dev_attr.attr,
|
||||
&sensor_dev_attr_temp1_max.dev_attr.attr,
|
||||
&sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
|
||||
&sensor_dev_attr_temp1_min_hyst.dev_attr.attr,
|
||||
&sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
|
||||
&sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
|
||||
&sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
|
||||
&sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
|
||||
NULL
|
||||
};
|
||||
|
||||
static const struct attribute_group lm77_group = {
|
||||
.attrs = lm77_attributes,
|
||||
};
|
||||
ATTRIBUTE_GROUPS(lm77);
|
||||
|
||||
/* Return 0 if detection is successful, -ENODEV otherwise */
|
||||
static int lm77_detect(struct i2c_client *client, struct i2c_board_info *info)
|
||||
@@ -337,68 +318,6 @@ static int lm77_detect(struct i2c_client *client, struct i2c_board_info *info)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int lm77_probe(struct i2c_client *client, const struct i2c_device_id *id)
|
||||
{
|
||||
struct device *dev = &client->dev;
|
||||
struct lm77_data *data;
|
||||
int err;
|
||||
|
||||
data = devm_kzalloc(dev, sizeof(struct lm77_data), GFP_KERNEL);
|
||||
if (!data)
|
||||
return -ENOMEM;
|
||||
|
||||
i2c_set_clientdata(client, data);
|
||||
mutex_init(&data->update_lock);
|
||||
|
||||
/* Initialize the LM77 chip */
|
||||
lm77_init_client(client);
|
||||
|
||||
/* Register sysfs hooks */
|
||||
err = sysfs_create_group(&dev->kobj, &lm77_group);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
data->hwmon_dev = hwmon_device_register(dev);
|
||||
if (IS_ERR(data->hwmon_dev)) {
|
||||
err = PTR_ERR(data->hwmon_dev);
|
||||
goto exit_remove;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
exit_remove:
|
||||
sysfs_remove_group(&dev->kobj, &lm77_group);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int lm77_remove(struct i2c_client *client)
|
||||
{
|
||||
struct lm77_data *data = i2c_get_clientdata(client);
|
||||
hwmon_device_unregister(data->hwmon_dev);
|
||||
sysfs_remove_group(&client->dev.kobj, &lm77_group);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* All registers are word-sized, except for the configuration register.
|
||||
* The LM77 uses the high-byte first convention.
|
||||
*/
|
||||
static u16 lm77_read_value(struct i2c_client *client, u8 reg)
|
||||
{
|
||||
if (reg == LM77_REG_CONF)
|
||||
return i2c_smbus_read_byte_data(client, reg);
|
||||
else
|
||||
return i2c_smbus_read_word_swapped(client, reg);
|
||||
}
|
||||
|
||||
static int lm77_write_value(struct i2c_client *client, u8 reg, u16 value)
|
||||
{
|
||||
if (reg == LM77_REG_CONF)
|
||||
return i2c_smbus_write_byte_data(client, reg, value);
|
||||
else
|
||||
return i2c_smbus_write_word_swapped(client, reg, value);
|
||||
}
|
||||
|
||||
static void lm77_init_client(struct i2c_client *client)
|
||||
{
|
||||
/* Initialize the LM77 chip - turn off shutdown mode */
|
||||
@@ -407,42 +326,45 @@ static void lm77_init_client(struct i2c_client *client)
|
||||
lm77_write_value(client, LM77_REG_CONF, conf & 0xfe);
|
||||
}
|
||||
|
||||
static struct lm77_data *lm77_update_device(struct device *dev)
|
||||
static int lm77_probe(struct i2c_client *client, const struct i2c_device_id *id)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct lm77_data *data = i2c_get_clientdata(client);
|
||||
struct device *dev = &client->dev;
|
||||
struct device *hwmon_dev;
|
||||
struct lm77_data *data;
|
||||
|
||||
mutex_lock(&data->update_lock);
|
||||
data = devm_kzalloc(dev, sizeof(struct lm77_data), GFP_KERNEL);
|
||||
if (!data)
|
||||
return -ENOMEM;
|
||||
|
||||
if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
|
||||
|| !data->valid) {
|
||||
dev_dbg(&client->dev, "Starting lm77 update\n");
|
||||
data->temp_input =
|
||||
LM77_TEMP_FROM_REG(lm77_read_value(client,
|
||||
LM77_REG_TEMP));
|
||||
data->temp_hyst =
|
||||
LM77_TEMP_FROM_REG(lm77_read_value(client,
|
||||
LM77_REG_TEMP_HYST));
|
||||
data->temp_crit =
|
||||
LM77_TEMP_FROM_REG(lm77_read_value(client,
|
||||
LM77_REG_TEMP_CRIT));
|
||||
data->temp_min =
|
||||
LM77_TEMP_FROM_REG(lm77_read_value(client,
|
||||
LM77_REG_TEMP_MIN));
|
||||
data->temp_max =
|
||||
LM77_TEMP_FROM_REG(lm77_read_value(client,
|
||||
LM77_REG_TEMP_MAX));
|
||||
data->alarms =
|
||||
lm77_read_value(client, LM77_REG_TEMP) & 0x0007;
|
||||
data->last_updated = jiffies;
|
||||
data->valid = 1;
|
||||
}
|
||||
data->client = client;
|
||||
mutex_init(&data->update_lock);
|
||||
|
||||
mutex_unlock(&data->update_lock);
|
||||
/* Initialize the LM77 chip */
|
||||
lm77_init_client(client);
|
||||
|
||||
return data;
|
||||
hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
|
||||
data, lm77_groups);
|
||||
return PTR_ERR_OR_ZERO(hwmon_dev);
|
||||
}
|
||||
|
||||
static const struct i2c_device_id lm77_id[] = {
|
||||
{ "lm77", 0 },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, lm77_id);
|
||||
|
||||
/* This is the driver that will be inserted */
|
||||
static struct i2c_driver lm77_driver = {
|
||||
.class = I2C_CLASS_HWMON,
|
||||
.driver = {
|
||||
.name = "lm77",
|
||||
},
|
||||
.probe = lm77_probe,
|
||||
.id_table = lm77_id,
|
||||
.detect = lm77_detect,
|
||||
.address_list = normal_i2c,
|
||||
};
|
||||
|
||||
module_i2c_driver(lm77_driver);
|
||||
|
||||
MODULE_AUTHOR("Andras BALI <drewie@freemail.hu>");
|
||||
|
||||
+305
-337
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user