hwmon: (max31722) Add support for MAX31722/MAX31723 temperature sensors
Subsystems (2)
PATCH v2 1/1 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
---
Changes from v1:
- addressed Guenter's comments
- removed regmap
- set resolution to 12 bits
--- Documentation/hwmon/max31722 | 34 ++++++++ drivers/hwmon/Kconfig | 11 +++ drivers/hwmon/Makefile | 1 + drivers/hwmon/max31722.c | 182 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 228 insertions(+) create mode 100644 Documentation/hwmon/max31722 create mode 100644 drivers/hwmon/max31722.c
Documentation/hwmon/max31722 new file +34 -0
@@ -0,0 +1,34 @@ +Kernel driver max31722 +=========== + +Supported chips: + * Maxim Integrated MAX31722 + Prefix: 'max31722' + ACPI ID: MAX31722 + Addresses scanned: - + Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX31722-MAX31723.pdf + * Maxim Integrated MAX31723 + Prefix: 'max31723' + ACPI ID: MAX31723 + Addresses scanned: - + Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX31722-MAX31723.pdf + +Author: Tiberiu Breana <[email protected]> + +Description +----------- + +This driver adds support for the Maxim Integrated MAX31722/MAX31723 thermometers +and thermostats running over an SPI interface. + +Usage Notes +----------- + +This driver uses ACPI to auto-detect devices. See ACPI IDs in the above section. + +Sysfs entries +------------- + +The following attribute is supported: + +temp1_input Measured temperature. Read-only.
drivers/hwmon/Kconfig +11 -0
@@ -807,6 +807,17 @@ config SENSORS_MAX197 This driver can also be built as a module. If so, the module will be called max197. +config SENSORS_MAX31722 +tristate "MAX31722 temperature sensor" + depends on SPI + select REGMAP_SPI + help + Support for the Maxim Integrated MAX31722/MAX31723 digital + thermometers/thermostats operating over an SPI interface. + + This driver can also be built as a module. If so, the module + will be called max31722. + config SENSORS_MAX6639 tristate "Maxim MAX6639 sensor chip" depends on I2C
drivers/hwmon/Makefile +1 -0
@@ -111,6 +111,7 @@ obj-$(CONFIG_SENSORS_MAX16065) += max16065.o obj-$(CONFIG_SENSORS_MAX1619) += max1619.o obj-$(CONFIG_SENSORS_MAX1668) += max1668.o obj-$(CONFIG_SENSORS_MAX197) += max197.o +obj-$(CONFIG_SENSORS_MAX31722) += max31722.o obj-$(CONFIG_SENSORS_MAX6639) += max6639.o obj-$(CONFIG_SENSORS_MAX6642) += max6642.o obj-$(CONFIG_SENSORS_MAX6650) += max6650.o
drivers/hwmon/max31722.c new file +181 -0
181 lines not on this page · raw message
Signature · 7 lines
1.9.1 _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Guenter Roeck
maintainerQuoted 8 lines · Tiberiu Breana
Add basic support for the Maxim Integrated MAX31722/MAX31723 SPI temperature sensors / thermostats.
Includes:
- ACPI support;
- raw temperature readings;
- power management
Quoted 8 lines
Datasheet:
https://datasheets.maximintegrated.com/en/ds/MAX31722-MAX31723.pdfSigned-off-by Tiberiu Breana <[email protected]>---
Changes from v1:
- addressed Guenter's comments
- removed regmap
Why ? Just wondering.
Did you drop patch #2, or is it going to come later ?
More comments below.
Thanks,
Guenter
Quoted 55 lines
- set resolution to 12 bits
--- Documentation/hwmon/max31722 | 34 ++++++++ drivers/hwmon/Kconfig | 11 +++ drivers/hwmon/Makefile | 1 + drivers/hwmon/max31722.c | 182 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 228 insertions(+) create mode 100644 Documentation/hwmon/max31722 create mode 100644 drivers/hwmon/max31722.cDocumentation/hwmon/max31722 new file +34
-0@@ -0,0 +1,34 @@ +Kernel driver max31722 +=========== + +Supported chips: + * Maxim Integrated MAX31722 + Prefix: 'max31722' + ACPI ID: MAX31722 + Addresses scanned: - + Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX31722-MAX31723.pdf + * Maxim Integrated MAX31723 + Prefix: 'max31723' + ACPI ID: MAX31723 + Addresses scanned: - + Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX31722-MAX31723.pdf + +Author: Tiberiu Breana <[email protected]> + +Description +----------- + +This driver adds support for the Maxim Integrated MAX31722/MAX31723 thermometers +and thermostats running over an SPI interface. + +Usage Notes +----------- + +This driver uses ACPI to auto-detect devices. See ACPI IDs in the above section. + +Sysfs entries +------------- + +The following attribute is supported: + +temp1_input Measured temperature. Read-only.drivers/hwmon/Kconfig +0
-0
drivers/hwmon/Kconfig config SENSORS_MAX197 · line 813
Quoted 7 lines
drivers/hwmon/Kconfig +4
-0@@ -807,6 +807,17 @@ config SENSORS_MAX197 This driver can also be built as a module. If so, the module will be called max197. +config SENSORS_MAX31722 +tristate "MAX31722 temperature sensor" + depends on SPI + select REGMAP_SPI
You dropped regmap, so this should no longer be necessary.
Quoted 35 lines
drivers/hwmon/Kconfig +7
-0+ help + Support for the Maxim Integrated MAX31722/MAX31723 digital + thermometers/thermostats operating over an SPI interface. + + This driver can also be built as a module. If so, the module + will be called max31722. + config SENSORS_MAX6639 tristate "Maxim MAX6639 sensor chip" depends on I2Cdrivers/hwmon/Makefile +1
-0@@ -111,6 +111,7 @@ obj-$(CONFIG_SENSORS_MAX16065) += max16065.o obj-$(CONFIG_SENSORS_MAX1619) += max1619.o obj-$(CONFIG_SENSORS_MAX1668) += max1668.o obj-$(CONFIG_SENSORS_MAX197) += max197.o +obj-$(CONFIG_SENSORS_MAX31722) += max31722.o obj-$(CONFIG_SENSORS_MAX6639) += max6639.o obj-$(CONFIG_SENSORS_MAX6642) += max6642.o obj-$(CONFIG_SENSORS_MAX6650) += max6650.odrivers/hwmon/max31722.c new file +7
-0@@ -0,0 +1,182 @@ +/* +* max31722 - hwmon driver for Maxim Integrated MAX31722/MAX31723 SPI +* digital thermometer and thermostats. +* +* Copyright (c) 2016, Intel Corporation. +* +* This file is subject to the terms and conditions of version 2 of
drivers/hwmon/max31722.c line 17
Quoted 10 lines
drivers/hwmon/max31722.c new file +10
-0+* the GNU General Public License. See the file COPYING in the main +* directory of this archive for more details. +*/ + +#include <linux/kernel.h> +#include <linux/acpi.h> +#include <linux/module.h> +#include <linux/spi/spi.h> +#include <linux/hwmon.h> +#include <linux/hwmon-sysfs.h>
Please lust include files in alphabetic order; that makes it easier to make changes later.
Quoted 18 lines
drivers/hwmon/max31722.c new file +18
-0+ +#define MAX31722_REG_CFG 0x00 +#define MAX31722_REG_TEMP_LSB 0x01 + +#define MAX31722_MODE_CONTINUOUS 0x00 +#define MAX31722_MODE_STANDBY 0x01 +#define MAX31722_MODE_MASK 0xFE +#define MAX31722_RESOLUTION_12BIT 0x06 +#define MAX31722_12BIT_STEP 62 +#define MAX31722_WRITE_MASK 0x80 + +struct max31722_data { +struct device *hwmon_dev; +struct spi_device *spi_device; +u8 mode; +}; + +static int max31722_set_mode (struct max31722_data *data,u8 mode)
drivers/hwmon/max31722.c line 45
Quoted 10 lines
drivers/hwmon/max31722.c new file +10
-0+{ +int ret; +struct spi_device *spi = data->spi_device; +u8 buf[2 ] = { +MAX31722_REG_CFG |MAX31722_WRITE_MASK , + (data->mode &MAX31722_MODE_MASK ) | mode + }; + + ret =spi_write (spi, &buf,sizeof (buf)); +
Please drop this empty line.
Quoted 9 lines
drivers/hwmon/max31722.c new file +9
-0+if (ret <0 ) { +dev_err (&spi->dev,"failed to set sensor mode.\n" ); +return ret; + } + data->mode = (data->mode &MAX31722_MODE_MASK ) | mode; + +return 0 ; +} +
drivers/hwmon/max31722.c line 64
Quoted 10 lines
drivers/hwmon/max31722.c new file +10
-0+static ssize_t max31722_show_temp (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +u16 temp; +struct max31722_data *data =dev_get_drvdata (dev); + + temp =spi_w8r16 (data->spi_device,MAX31722_REG_TEMP_LSB ); +if (temp <0 ) +return temp;
temp is u16, so this doesn't work.
drivers/hwmon/max31722.c line 67
Quoted 3 lines
drivers/hwmon/max31722.c new file +3
-0+/* Keep 12 bits and multiply by the scale of 62 millidegrees/bit. */ +return sprintf (buf,"%d\n" , + ((s16 )le16_to_cpu (temp) >>4 ) *MAX31722_12BIT_STEP );
The step width is really 62.5 milli-degrees C, so this introduces an error. Something like
(s16)le16_to_cpu(temp) * 125 / 32
would be more accurate.
Quoted 28 lines
drivers/hwmon/max31722.c new file +28
-0+} + +static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, + max31722_show_temp, NULL, 0); + +static struct attribute *max31722_attrs[] = { + &sensor_dev_attr_temp1_input.dev_attr.attr, +NULL , +}; + +ATTRIBUTE_GROUPS (max31722); + +static int max31722_probe (struct spi_device *spi) +{ +int ret; +struct max31722_data *data; +/* +* Set SD bit to 0 so we can have continuous measurements. +* Set resolution to 12 bits for maximum precision. +*/ +u8 mode =MAX31722_MODE_CONTINUOUS |MAX31722_RESOLUTION_12BIT ; +u8 init_buf[2 ] = { +MAX31722_REG_CFG |MAX31722_WRITE_MASK , + mode + }; + + data =devm_kzalloc (&spi->dev,sizeof (*data),GFP_KERNEL ); +if (!data)
drivers/hwmon/max31722.c line 105
Quoted 10 lines
drivers/hwmon/max31722.c new file +10
-0+return -ENOMEM ; + +spi_set_drvdata (spi, data); + data->spi_device = spi; + ret =spi_write (spi, &init_buf,sizeof (init_buf)); +if (ret <0 ) { +max31722_set_mode (data,MAX31722_MODE_STANDBY ); +return ret; + } + data->mode = mode;
Initializing data->mode with
MAX31722_MODE_CONTINUOUS | MAX31722_RESOLUTION_12BIT
and calling
max31722_set_mode(data, MAX31722_MODE_CONTINUOUS);would accomplish the same with less complexity.
Also, since the write failed, calling max31722_set_mode() on error (especially with the un-initialized data->mode) doesn't make much sense. You might as well just return in that case.
Quoted 9 lines
drivers/hwmon/max31722.c new file +9
-0+ + data->hwmon_dev > +devm_hwmon_device_register_with_groups (&spi->dev, + spi->modalias, + data, + max31722_groups); +if (IS_ERR (data->hwmon_dev)) { +max31722_set_mode (data,MAX31722_MODE_STANDBY ); +return PTR_ERR (data->hwmon_dev); + }
drivers/hwmon/max31722.c line 124
Quoted 10 lines
drivers/hwmon/max31722.c new file +10
-0+ +return 0 ; +} + +static int max31722_remove (struct spi_device *spi) +{ +struct max31722_data *data =spi_get_drvdata (spi); + +hwmon_device_unregister (data->hwmon_dev); +
This defeats the purpose of using devm_hwmon_device_register_with_groups(). Please use hwmon_device_register_with_groups() instead.
Quoted 16 lines
drivers/hwmon/max31722.c new file +16
-0+return max31722_set_mode (data,MAX31722_MODE_STANDBY ); +} + +#ifdef CONFIG_PM_SLEEP +static int max31722_suspend (struct device *dev) +{ +struct spi_device *spi_device =to_spi_device (dev); +struct max31722_data *data =spi_get_drvdata (spi_device); + +return max31722_set_mode (data,MAX31722_MODE_STANDBY ); +} + +static int max31722_resume (struct device *dev) +{ +struct spi_device *spi_device =to_spi_device (dev); +struct max31722_data *data =spi_get_drvdata (spi_device);
drivers/hwmon/max31722.c line 150
Quoted 10 lines
drivers/hwmon/max31722.c new file +10
-0+ +return max31722_set_mode (data,MAX31722_MODE_CONTINUOUS ); +} + +static SIMPLE_DEV_PM_OPS(max31722_pm_ops, max31722_suspend, max31722_resume); + +#define MAX31722_PM_OPS (&max31722_pm_ops) +#else +#define MAX31722_PM_OPS NULL +#endif
Please drop the #ifdef and tag the functions with __maybe_unused. While this causes max31722_pm_ops to be defined in the non-PM case, it ensures that the functions are always compiled. The benefit outweighs the cost.
drivers/hwmon/max31722.c line 162
Quoted 12 lines
drivers/hwmon/max31722.c new file +12
-0+ +static const struct spi_device_id max31722_spi_id[] = { + {"max31722" ,0 }, + {"max31723" ,0 }, + {} +}; + +static const struct acpi_device_id max31722_acpi_id[] = { + {"MAX31722" ,0 }, + {"MAX31723" ,0 }, + {} +};
I think you may need to tag this array with __maybe_unused to avoid an unused warning if ACPI is not configured.
Quoted 22 lines
drivers/hwmon/max31722.c new file +19
-0+ +MODULE_DEVICE_TABLE (spi, max31722_spi_id); + +static struct spi_driver max31722_driver = { + .driver = { + .name ="max31722" , + .pm =MAX31722_PM_OPS , + .acpi_match_table =ACPI_PTR (max31722_acpi_id), + }, + .probe = max31722_probe, + .remove = max31722_remove, + .id_table = max31722_spi_id, +}; + +module_spi_driver (max31722_driver); + +MODULE_AUTHOR ("Tiberiu Breana <[email protected]>" ); +MODULE_DESCRIPTION ("max31722 sensor driver" ); +MODULE_LICENSE ("GPL v2" );Signature · 1 line
1.9.1
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 21 lines
-----Original Message-----
From: Guenter Roeck [mailto:[email protected]]
Sent: Tuesday, March 29, 2016 6:45 PM
To: Breana, Tiberiu A <[email protected]>
Cc: [email protected]; Baluta, Daniel <[email protected]>
Subject: Re: [PATCH v2] hwmon: (max31722) Add support for MAX31722/MAX31723 temperature sensorsQuoted 10 lines · Tiberiu Breana
Add basic support for the Maxim Integrated MAX31722/MAX31723 SPI temperature sensors / thermostats.
Includes:
- ACPI support;
- raw temperature readings;
- power managementDatasheet:
https://datasheets.maximintegrated.com/en/ds/MAX31722-MAX31723.pdf
Quoted 1 line
Quoted 7 lines
Quoted 5 lines
Signed-off-by Tiberiu Breana <[email protected]>---
Changes from v1:
- addressed Guenter's comments
- removed regmapWhy ? Just wondering.
It added a lot of code bloat and not much else.
Quoted 2 lines
Did you drop patch #2, or is it going to come later ?
It's coming later.
Quoted 5 lines
More comments below.
Thanks,
Guenter
All the suggested changes will be applied in v3 soon. Thanks,
Tiberiu
Quoted 307 lines
Quoted 7 lines
- set resolution to 12 bits
--- Documentation/hwmon/max31722 | 34 ++++++++ drivers/hwmon/Kconfig | 11 +++ drivers/hwmon/Makefile | 1 + drivers/hwmon/max31722.c | 182+++++++++++++++++++++++++++++++++++++++++++
Quoted 2 lines
4 files changed, 228 insertions(+) create mode 100644 Documentation/hwmon/max31722 create mode100644
Quoted 8 lines
drivers/hwmon/max31722.c(quoted diff) +0
-0b/Documentation/hwmon/max31722 new file mode 100644 index 0000000..090da845
Documentation/hwmon/max31722 line 10
Quoted 10 lines
Documentation/hwmon/max31722 new file +10
-0@@ -0,0 +1,34 @@ +Kernel driver max31722 +=========== + +Supported chips: + * Maxim Integrated MAX31722 + Prefix: 'max31722' + ACPI ID: MAX31722 + Addresses scanned: - + Datasheet: +https://datasheets.maximintegrated.com/en/ds/MAX31722-MAX31723.pdf
Documentation/hwmon/max31722
Quoted 6 lines
Documentation/hwmon/max31722 new file +6
-0+ * Maxim Integrated MAX31723 + Prefix: 'max31723' + ACPI ID: MAX31723 + Addresses scanned: - + Datasheet: +https://datasheets.maximintegrated.com/en/ds/MAX31722-MAX31723.pdf
Documentation/hwmon/max31722
Quoted 13 lines
Documentation/hwmon/max31722 new file +13
-0+ +Author: Tiberiu Breana <[email protected]> + +Description +----------- + +This driver adds support for the Maxim Integrated MAX31722/MAX31723 +thermometers and thermostats running over an SPI interface. + +Usage Notes +----------- + +This driver uses ACPI to auto-detect devices. See ACPI IDs in the abovesection.
Quoted 12 lines
Documentation/hwmon/max31722 new file +7
-0+ +Sysfs entries +------------- + +The following attribute is supported: + +temp1_input Measured temperature. Read-only.drivers/hwmon/Kconfig index renamed from drivers/hwmon/Kconfig +0
-060fb80b..b819312 100644
drivers/hwmon/Kconfig config SENSORS_MAX197 · line 813
Quoted 7 lines
drivers/hwmon/Kconfig +4
-0@@ -807,6 +807,17 @@ config SENSORS_MAX197 This driver can also be built as a module. If so, the module will be called max197. +config SENSORS_MAX31722 +tristate "MAX31722 temperature sensor" + depends on SPI + select REGMAP_SPIYou dropped regmap, so this should no longer be necessary.
Quoted 27 lines
drivers/hwmon/Kconfig +7
-0+ help + Support for the Maxim Integrated MAX31722/MAX31723 digital + thermometers/thermostats operating over an SPI interface. + + This driver can also be built as a module. If so, the module + will be called max31722. + config SENSORS_MAX6639 tristate "Maxim MAX6639 sensor chip" depends on I2Cdrivers/hwmon/Makefile index renamed from drivers/hwmon/Makefile +0
-030c94df..689afe9 100644
drivers/hwmon/Makefile +1
-0@@ -111,6 +111,7 @@ obj-$(CONFIG_SENSORS_MAX16065) +> max16065.o obj-$(CONFIG_SENSORS_MAX1619) += max1619.o obj-$(CONFIG_SENSORS_MAX1668) += max1668.o obj-$(CONFIG_SENSORS_MAX197) += max197.o +obj-$(CONFIG_SENSORS_MAX31722) += max31722.o obj-$(CONFIG_SENSORS_MAX6639) += max6639.o obj-$(CONFIG_SENSORS_MAX6642) += max6642.o obj-$(CONFIG_SENSORS_MAX6650) += max6650.odrivers/hwmon/max31722.c new renamed from drivers/hwmon/max31722.c +0
-0file mode 100644 index 0000000..b3606d9
drivers/hwmon/max31722.c line 2
Quoted 2 lines
drivers/hwmon/max31722.c new file +2
-0@@ -0,0 +1,182 @@ +/* +* max31722 - hwmon driver for Maxim Integrated MAX31722/MAX31723 SPI
Quoted 5 lines
drivers/hwmon/max31722.c new file +5
-0+* digital thermometer and thermostats. +* +* Copyright (c) 2016, Intel Corporation. +* +* This file is subject to the terms and conditions of version 2 of drivers/hwmon/max31722.c line 17
Quoted 10 lines
drivers/hwmon/max31722.c new file +10
-0+* the GNU General Public License. See the file COPYING in the main +* directory of this archive for more details. +*/ + +#include <linux/kernel.h> +#include <linux/acpi.h> +#include <linux/module.h> +#include <linux/spi/spi.h> +#include <linux/hwmon.h> +#include <linux/hwmon-sysfs.h> Please lust include files in alphabetic order; that makes it easier to make changes later.
Quoted 17 lines
drivers/hwmon/max31722.c new file +17
-0+ +#define MAX31722_REG_CFG 0x00 +#define MAX31722_REG_TEMP_LSB 0x01 + +#define MAX31722_MODE_CONTINUOUS 0x00 +#define MAX31722_MODE_STANDBY 0x01 +#define MAX31722_MODE_MASK 0xFE +#define MAX31722_RESOLUTION_12BIT 0x06 +#define MAX31722_12BIT_STEP 62 +#define MAX31722_WRITE_MASK 0x80 + +struct max31722_data { +struct device *hwmon_dev; +struct spi_device *spi_device; +u8 mode; +}; +drivers/hwmon/max31722.c line 45
Quoted 10 lines
drivers/hwmon/max31722.c new file +10
-0+static int max31722_set_mode (struct max31722_data *data,u8 mode) { +int ret; +struct spi_device *spi = data->spi_device; +u8 buf[2 ] = { +MAX31722_REG_CFG |MAX31722_WRITE_MASK , + (data->mode &MAX31722_MODE_MASK ) | mode + }; + + ret =spi_write (spi, &buf,sizeof (buf)); +Please drop this empty line.
Quoted 9 lines
drivers/hwmon/max31722.c new file +9
-0+if (ret <0 ) { +dev_err (&spi->dev,"failed to set sensor mode.\n" ); +return ret; + } + data->mode = (data->mode &MAX31722_MODE_MASK ) | mode; + +return 0 ; +} +drivers/hwmon/max31722.c line 64
Quoted 10 lines
drivers/hwmon/max31722.c new file +10
-0+static ssize_t max31722_show_temp (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +u16 temp; +struct max31722_data *data =dev_get_drvdata (dev); + + temp =spi_w8r16 (data->spi_device,MAX31722_REG_TEMP_LSB ); +if (temp <0 ) +return temp;temp is u16, so this doesn't work.
drivers/hwmon/max31722.c line 67
Quoted 3 lines
drivers/hwmon/max31722.c new file +3
-0+/* Keep 12 bits and multiply by the scale of 62 millidegrees/bit. */ +return sprintf (buf,"%d\n" , + ((s16 )le16_to_cpu (temp) >>4 ) *MAX31722_12BIT_STEP );The step width is really 62.5 milli-degrees C, so this introduces an error. Something like
(s16)le16_to_cpu(temp) * 125 / 32would be more accurate.
Quoted 10 lines
drivers/hwmon/max31722.c new file +10
-0+} + +static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, + max31722_show_temp, NULL, 0); + +static struct attribute *max31722_attrs[] = { + &sensor_dev_attr_temp1_input.dev_attr.attr, +NULL , +}; +drivers/hwmon/max31722.c
Quoted 10 lines
drivers/hwmon/max31722.c new file +10
-0+ATTRIBUTE_GROUPS (max31722); + +static int max31722_probe (struct spi_device *spi) { +int ret; +struct max31722_data *data; +/* +* Set SD bit to 0 so we can have continuous measurements. +* Set resolution to 12 bits for maximum precision. +*/ + u8 mode = MAX31722_MODE_CONTINUOUS |
MAX31722_RESOLUTION_12BIT;Quoted 7 lines
drivers/hwmon/max31722.c new file +7
-0+u8 init_buf[2 ] = { +MAX31722_REG_CFG |MAX31722_WRITE_MASK , + mode + }; + + data =devm_kzalloc (&spi->dev,sizeof (*data),GFP_KERNEL ); +if (!data)drivers/hwmon/max31722.c line 105
Quoted 10 lines
drivers/hwmon/max31722.c new file +10
-0+return -ENOMEM ; + +spi_set_drvdata (spi, data); + data->spi_device = spi; + ret =spi_write (spi, &init_buf,sizeof (init_buf)); +if (ret <0 ) { +max31722_set_mode (data,MAX31722_MODE_STANDBY ); +return ret; + } + data->mode = mode;Initializing
data->modewithMAX31722_MODE_CONTINUOUS | MAX31722_RESOLUTION_12BIT and calling max31722_set_mode(data, MAX31722_MODE_CONTINUOUS); wouldaccomplish the same with less complexity.
Also, since the write failed, calling
max31722_set_mode()on error (especially with the un-initializeddata->mode) doesn't make much sense. You might as well just return in that case.Quoted 8 lines
drivers/hwmon/max31722.c new file +8
-0+ + data->hwmon_dev > > + devm_hwmon_device_register_with_groups(&spi->dev, + spi->modalias, + data, + max31722_groups); +if (IS_ERR (data->hwmon_dev)) { +max31722_set_mode (data,MAX31722_MODE_STANDBY ); +return PTR_ERR (data->hwmon_dev);drivers/hwmon/max31722.c line 124
Quoted 10 lines
drivers/hwmon/max31722.c new file +10
-0+ } + +return 0 ; +} + +static int max31722_remove (struct spi_device *spi) { +struct max31722_data *data =spi_get_drvdata (spi); + +hwmon_device_unregister (data->hwmon_dev); +This defeats the purpose of using
devm_hwmon_device_register_with_groups(). Please usehwmon_device_register_with_groups()instead.Quoted 4 lines
drivers/hwmon/max31722.c new file +4
-0+return max31722_set_mode (data,MAX31722_MODE_STANDBY ); } + +#ifdef CONFIG_PM_SLEEP +static int max31722_suspend (struct device *dev) {drivers/hwmon/max31722.c
Quoted 10 lines
drivers/hwmon/max31722.c new file +10
-0+struct spi_device *spi_device =to_spi_device (dev); +struct max31722_data *data =spi_get_drvdata (spi_device); + +return max31722_set_mode (data,MAX31722_MODE_STANDBY ); } + +static int max31722_resume (struct device *dev) { +struct spi_device *spi_device =to_spi_device (dev); +struct max31722_data *data =spi_get_drvdata (spi_device); + + return max31722_set_mode(data,
MAX31722_MODE_CONTINUOUS); }drivers/hwmon/max31722.c line 141
Quoted 6 lines
drivers/hwmon/max31722.c new file +6
-0+ +static SIMPLE_DEV_PM_OPS(max31722_pm_ops, max31722_suspend, +max31722_resume); + +#define MAX31722_PM_OPS (&max31722_pm_ops) #else #define +MAX31722_PM_OPS NULL #endifPlease drop the #ifdef and tag the functions with
__maybe_unused. While this causesmax31722_pm_opsto be defined in the non-PM case, it ensures that the functions are always compiled.
The benefit outweighs the cost.drivers/hwmon/max31722.c line 162
Quoted 12 lines
drivers/hwmon/max31722.c new file +12
-0+ +static const struct spi_device_id max31722_spi_id[] = { + {"max31722" ,0 }, + {"max31723" ,0 }, + {} +}; + +static const struct acpi_device_id max31722_acpi_id[] = { + {"MAX31722" ,0 }, + {"MAX31723" ,0 }, + {} +};I think you may need to tag this array with
__maybe_unusedto avoid an unused warning if ACPI is not configured.Quoted 11 lines
drivers/hwmon/max31722.c new file +11
-0+ +MODULE_DEVICE_TABLE (spi, max31722_spi_id); + +static struct spi_driver max31722_driver = { + .driver = { + .name ="max31722" , + .pm =MAX31722_PM_OPS , + .acpi_match_table =ACPI_PTR (max31722_acpi_id), + }, + .probe = max31722_probe, + .remove = max31722_remove,
Quoted 12 lines
drivers/hwmon/max31722.c line 180
Quoted 7 lines
drivers/hwmon/max31722.c new file +7
-0+ .id_table = max31722_spi_id, +}; + +module_spi_driver (max31722_driver); + +MODULE_AUTHOR ("Tiberiu Breana <[email protected]>" ); +MODULE_DESCRIPTION ("max31722 sensor driver" );MODULE_LICENSE("GPL
Quoted 4 lines
drivers/hwmon/max31722.c new file +1
-1+v2"); --1.9.1
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors