summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTiberiu Breana <tiberiu.a.breana@intel.com>2016-03-30 12:16:24 -0400
committerGuenter Roeck <linux@roeck-us.net>2016-04-19 09:32:34 -0400
commit04e1e70afec6bb2940aea0ac2e9cbaf7d643d5f4 (patch)
tree8c7c6eabae4767c8d32338d4061f7972a8766a31
parent7a18afe8097731b8ffb6cb5b2b3b418ded77c105 (diff)
hwmon: (max31722) Add support for MAX31722/MAX31723 temperature sensors
Add basic support for the Maxim Integrated MAX31722/MAX31723 SPI temperature sensors / thermostats. Includes: - ACPI support; - raw temperature readings; - power management Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX31722-MAX31723.pdf Signed-off-by: Tiberiu Breana <tiberiu.a.breana@intel.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r--Documentation/hwmon/max3172234
-rw-r--r--drivers/hwmon/Kconfig10
-rw-r--r--drivers/hwmon/Makefile1
-rw-r--r--drivers/hwmon/max31722.c165
4 files changed, 210 insertions, 0 deletions
diff --git a/Documentation/hwmon/max31722 b/Documentation/hwmon/max31722
new file mode 100644
index 000000000000..090da84538c8
--- /dev/null
+++ b/Documentation/hwmon/max31722
@@ -0,0 +1,34 @@
1Kernel driver max31722
2======================
3
4Supported chips:
5 * Maxim Integrated MAX31722
6 Prefix: 'max31722'
7 ACPI ID: MAX31722
8 Addresses scanned: -
9 Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX31722-MAX31723.pdf
10 * Maxim Integrated MAX31723
11 Prefix: 'max31723'
12 ACPI ID: MAX31723
13 Addresses scanned: -
14 Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX31722-MAX31723.pdf
15
16Author: Tiberiu Breana <tiberiu.a.breana@intel.com>
17
18Description
19-----------
20
21This driver adds support for the Maxim Integrated MAX31722/MAX31723 thermometers
22and thermostats running over an SPI interface.
23
24Usage Notes
25-----------
26
27This driver uses ACPI to auto-detect devices. See ACPI IDs in the above section.
28
29Sysfs entries
30-------------
31
32The following attribute is supported:
33
34temp1_input Measured temperature. Read-only.
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 5c2d13a687aa..bdfa39408996 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -821,6 +821,16 @@ config SENSORS_MAX197
821 This driver can also be built as a module. If so, the module 821 This driver can also be built as a module. If so, the module
822 will be called max197. 822 will be called max197.
823 823
824config SENSORS_MAX31722
825tristate "MAX31722 temperature sensor"
826 depends on SPI
827 help
828 Support for the Maxim Integrated MAX31722/MAX31723 digital
829 thermometers/thermostats operating over an SPI interface.
830
831 This driver can also be built as a module. If so, the module
832 will be called max31722.
833
824config SENSORS_MAX6639 834config SENSORS_MAX6639
825 tristate "Maxim MAX6639 sensor chip" 835 tristate "Maxim MAX6639 sensor chip"
826 depends on I2C 836 depends on I2C
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 58cc3acba7e7..2ef5b7c4c54f 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -112,6 +112,7 @@ obj-$(CONFIG_SENSORS_MAX16065) += max16065.o
112obj-$(CONFIG_SENSORS_MAX1619) += max1619.o 112obj-$(CONFIG_SENSORS_MAX1619) += max1619.o
113obj-$(CONFIG_SENSORS_MAX1668) += max1668.o 113obj-$(CONFIG_SENSORS_MAX1668) += max1668.o
114obj-$(CONFIG_SENSORS_MAX197) += max197.o 114obj-$(CONFIG_SENSORS_MAX197) += max197.o
115obj-$(CONFIG_SENSORS_MAX31722) += max31722.o
115obj-$(CONFIG_SENSORS_MAX6639) += max6639.o 116obj-$(CONFIG_SENSORS_MAX6639) += max6639.o
116obj-$(CONFIG_SENSORS_MAX6642) += max6642.o 117obj-$(CONFIG_SENSORS_MAX6642) += max6642.o
117obj-$(CONFIG_SENSORS_MAX6650) += max6650.o 118obj-$(CONFIG_SENSORS_MAX6650) += max6650.o
diff --git a/drivers/hwmon/max31722.c b/drivers/hwmon/max31722.c
new file mode 100644
index 000000000000..30a100e70a0d
--- /dev/null
+++ b/drivers/hwmon/max31722.c
@@ -0,0 +1,165 @@
1/*
2 * max31722 - hwmon driver for Maxim Integrated MAX31722/MAX31723 SPI
3 * digital thermometer and thermostats.
4 *
5 * Copyright (c) 2016, Intel Corporation.
6 *
7 * This file is subject to the terms and conditions of version 2 of
8 * the GNU General Public License. See the file COPYING in the main
9 * directory of this archive for more details.
10 */
11
12#include <linux/acpi.h>
13#include <linux/hwmon.h>
14#include <linux/hwmon-sysfs.h>
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/spi/spi.h>
18
19#define MAX31722_REG_CFG 0x00
20#define MAX31722_REG_TEMP_LSB 0x01
21
22#define MAX31722_MODE_CONTINUOUS 0x00
23#define MAX31722_MODE_STANDBY 0x01
24#define MAX31722_MODE_MASK 0xFE
25#define MAX31722_RESOLUTION_12BIT 0x06
26#define MAX31722_WRITE_MASK 0x80
27
28struct max31722_data {
29 struct device *hwmon_dev;
30 struct spi_device *spi_device;
31 u8 mode;
32};
33
34static int max31722_set_mode(struct max31722_data *data, u8 mode)
35{
36 int ret;
37 struct spi_device *spi = data->spi_device;
38 u8 buf[2] = {
39 MAX31722_REG_CFG | MAX31722_WRITE_MASK,
40 (data->mode & MAX31722_MODE_MASK) | mode
41 };
42
43 ret = spi_write(spi, &buf, sizeof(buf));
44 if (ret < 0) {
45 dev_err(&spi->dev, "failed to set sensor mode.\n");
46 return ret;
47 }
48 data->mode = (data->mode & MAX31722_MODE_MASK) | mode;
49
50 return 0;
51}
52
53static ssize_t max31722_show_temp(struct device *dev,
54 struct device_attribute *attr,
55 char *buf)
56{
57 ssize_t ret;
58 struct max31722_data *data = dev_get_drvdata(dev);
59
60 ret = spi_w8r16(data->spi_device, MAX31722_REG_TEMP_LSB);
61 if (ret < 0)
62 return ret;
63 /* Keep 12 bits and multiply by the scale of 62.5 millidegrees/bit. */
64 return sprintf(buf, "%d\n", (s16)le16_to_cpu(ret) * 125 / 32);
65}
66
67static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO,
68 max31722_show_temp, NULL, 0);
69
70static struct attribute *max31722_attrs[] = {
71 &sensor_dev_attr_temp1_input.dev_attr.attr,
72 NULL,
73};
74
75ATTRIBUTE_GROUPS(max31722);
76
77static int max31722_probe(struct spi_device *spi)
78{
79 int ret;
80 struct max31722_data *data;
81
82 data = devm_kzalloc(&spi->dev, sizeof(*data), GFP_KERNEL);
83 if (!data)
84 return -ENOMEM;
85
86 spi_set_drvdata(spi, data);
87 data->spi_device = spi;
88 /*
89 * Set SD bit to 0 so we can have continuous measurements.
90 * Set resolution to 12 bits for maximum precision.
91 */
92 data->mode = MAX31722_MODE_CONTINUOUS | MAX31722_RESOLUTION_12BIT;
93 ret = max31722_set_mode(data, MAX31722_MODE_CONTINUOUS);
94 if (ret < 0)
95 return ret;
96
97 data->hwmon_dev = hwmon_device_register_with_groups(&spi->dev,
98 spi->modalias,
99 data,
100 max31722_groups);
101 if (IS_ERR(data->hwmon_dev)) {
102 max31722_set_mode(data, MAX31722_MODE_STANDBY);
103 return PTR_ERR(data->hwmon_dev);
104 }
105
106 return 0;
107}
108
109static int max31722_remove(struct spi_device *spi)
110{
111 struct max31722_data *data = spi_get_drvdata(spi);
112
113 hwmon_device_unregister(data->hwmon_dev);
114
115 return max31722_set_mode(data, MAX31722_MODE_STANDBY);
116}
117
118static int __maybe_unused max31722_suspend(struct device *dev)
119{
120 struct spi_device *spi_device = to_spi_device(dev);
121 struct max31722_data *data = spi_get_drvdata(spi_device);
122
123 return max31722_set_mode(data, MAX31722_MODE_STANDBY);
124}
125
126static int __maybe_unused max31722_resume(struct device *dev)
127{
128 struct spi_device *spi_device = to_spi_device(dev);
129 struct max31722_data *data = spi_get_drvdata(spi_device);
130
131 return max31722_set_mode(data, MAX31722_MODE_CONTINUOUS);
132}
133
134static SIMPLE_DEV_PM_OPS(max31722_pm_ops, max31722_suspend, max31722_resume);
135
136static const struct spi_device_id max31722_spi_id[] = {
137 {"max31722", 0},
138 {"max31723", 0},
139 {}
140};
141
142static const struct acpi_device_id __maybe_unused max31722_acpi_id[] = {
143 {"MAX31722", 0},
144 {"MAX31723", 0},
145 {}
146};
147
148MODULE_DEVICE_TABLE(spi, max31722_spi_id);
149
150static struct spi_driver max31722_driver = {
151 .driver = {
152 .name = "max31722",
153 .pm = &max31722_pm_ops,
154 .acpi_match_table = ACPI_PTR(max31722_acpi_id),
155 },
156 .probe = max31722_probe,
157 .remove = max31722_remove,
158 .id_table = max31722_spi_id,
159};
160
161module_spi_driver(max31722_driver);
162
163MODULE_AUTHOR("Tiberiu Breana <tiberiu.a.breana@intel.com>");
164MODULE_DESCRIPTION("max31722 sensor driver");
165MODULE_LICENSE("GPL v2");