hwmon:Add EC Chip driver for Lenovo ThinkStation motherboards
Subsystems (2)
PATCH v4 1/1 hwmon:Add EC Chip driver for Lenovo ThinkStation motherboards
This addition adds in the ability for the system to scan the EC chip in the Lenovo ThinkStation systems to get the current fan RPM speeds the Maximum speed value for each fan also provides the CPU, DIMM other thermal statuses
---
Changes in V4
removed internal name references and checks
added in DMI checks to verify the device is a on supported system added in IO memory region protection
---
--- drivers/hwmon/Kconfig | 10 + drivers/hwmon/Makefile | 1 + drivers/hwmon/lenovo-ec-sensors.c | 615 ++++++++++++++++++++++++++++++ 3 files changed, 626 insertions(+) create mode 100644 drivers/hwmon/lenovo-ec-sensors.c
drivers/hwmon/Kconfig +10 -0
@@ -862,6 +862,16 @@ config SENSORS_LAN966X This driver can also be built as a module. If so, the module will be called lan966x-hwmon. +config SENSORS_LENOVO_EC + tristate "Sensor reader for Lenovo ThinkStations" + depends on X86 + help + If you say yes here you get support for LENOVO + EC Sensor data on newer ThinkStation systems + + This driver can also be built as a module. If so, the module + will be called lenovo_ec_sensors. + config SENSORS_LINEAGE tristate "Lineage Compact Power Line Power Entry Module" depends on I2C
drivers/hwmon/Makefile +1 -0
@@ -104,6 +104,7 @@ obj-$(CONFIG_SENSORS_JC42) += jc42.o obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o obj-$(CONFIG_SENSORS_K10TEMP) += k10temp.o obj-$(CONFIG_SENSORS_LAN966X) += lan966x-hwmon.o +obj-$(CONFIG_SENSORS_LENOVO_EC) += lenovo-ec-sensors.o obj-$(CONFIG_SENSORS_LINEAGE) += lineage-pem.o obj-$(CONFIG_SENSORS_LOCHNAGAR) += lochnagar-hwmon.o obj-$(CONFIG_SENSORS_LM63) += lm63.o
drivers/hwmon/lenovo-ec-sensors.c new file +615 -0
615 lines not on this page · raw message
Signature · 1 line
2.34.1
Quoted 7 lines · David Ober
This addition adds in the ability for the system to scan the EC chip in the Lenovo ThinkStation systems to get the current fan RPM speeds the Maximum speed value for each fan also provides the CPU, DIMM other thermal statuses
Signed-off-by David Ober <[email protected]>Signed-off-by David Ober <[email protected]>
Applied to hwmon-next.
Please note that I'll push the branch after the commit window closed.
Thanks,
Guenter
Quoted 6 lines · Guenter Roeck
Quoted 5 lines · David Ober
This addition adds in the ability for the system to scan the EC chip in the Lenovo ThinkStation systems to get the current fan RPM speeds the Maximum speed value for each fan also provides the CPU, DIMM other thermal statuses
Quoted 6 lines
Quoted 2 lines
Signed-off-by David Ober <[email protected]>Signed-off-by David Ober <[email protected]>Applied to hwmon-next.
Please note that I'll push the branch after the commit window closed.
Hmm... Was it even compiled?
lenovo-ec-sensors.c:154:31: error: expected '}'
static int p8_fan_map[] = {0. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14};
^
lenovo-ec-sensors.c:154:27: note: to match this '{'
static int p8_fan_map[] = {0. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14};
^Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 4 lines · David Ober
This addition adds in the ability for the system to scan the EC chip in the Lenovo ThinkStation systems to get the current fan RPM speeds the Maximum speed value for each fan also provides the CPU, DIMM other thermal statuses
Besides the compilation error, see other remarks below.
...
Quoted 2 lines
Signed-off-by David Ober <[email protected]>Signed-off-by David Ober <[email protected]>
Can you leave only one of these?
Quoted 9 lines
drivers/hwmon/Kconfig +9
-0+config SENSORS_LENOVO_EC + tristate "Sensor reader for Lenovo ThinkStations" + depends on X86 + help + If you say yes here you get support for LENOVO + EC Sensor data on newer ThinkStation systems + + This driver can also be built as a module. If so, the module + will be called lenovo_ec_sensors.
...
Quoted 1 line
+ * Copyright (C) 2023 David Ober (Lenovo) <[email protected]>
2024?
...
Use IWYU principle (include what you use). See below what I have noticed (may not be the full list of missing inclusions).
drivers/hwmon/lenovo-ec-sensors.c line 17
Quoted 2 lines
drivers/hwmon/lenovo-ec-sensors.c new file +2
-0+#include <linux/acpi.h> +#include <linux/delay.h>
+ device.h
Quoted 1 line
+#include <
linux/dmi.h>
+ err.h
drivers/hwmon/lenovo-ec-sensors.c line 22
Quoted 5 lines
drivers/hwmon/lenovo-ec-sensors.c new file +4
-0+#include <linux/hwmon.h> +#include <linux/io.h> +#include <linux/ioport.h> +#include <linux/kernel.h>
How is this one being used, please?
Quoted 1 line
+#include <
linux/module.h>
+ mutex.h
Quoted 1 line
+#include <
linux/platform_device.h>
+ types.h
Quoted 1 line
+#include <
linux/units.h>
...
drivers/hwmon/lenovo-ec-sensors.c line 39
Quoted 2 lines
drivers/hwmon/lenovo-ec-sensors.c new file +2
-0+#define io_write8 (a, b) outb_p(b, a) +#define io_read8 (a) inb_p(a)
First of all, these are too generic, second, what's the point? If you wish to make useful macros, put a pointer to the private data, for example, from which you can get the address.
...
Quoted 1 line
+static inline
uint8_t
uint8_t...
drivers/hwmon/lenovo-ec-sensors.c line 44
Quoted 3 lines
drivers/hwmon/lenovo-ec-sensors.c new file +3
-0+get_ec_reg(unsigned char page, unsigned char index) +{ +u8 onebyte;
u8... Just in a few closer lines :-(
Can you be consistent with a kernel types?
drivers/hwmon/lenovo-ec-sensors.c line 50
Quoted 6 lines
drivers/hwmon/lenovo-ec-sensors.c new file +6
-0+unsigned short m_index; +unsigned short phy_index = page *256 + index; + +io_write8 (MCHP_EMI0_APPLICATION_ID ,0x01 ); + + m_index = phy_index &0x7FFC ;
GENMASK() (you will need bits.h for this)
drivers/hwmon/lenovo-ec-sensors.c line 52
Quoted 2 lines
drivers/hwmon/lenovo-ec-sensors.c new file +2
-0+io_write8 (MCHP_EMI0_EC_ADDRESS_LSB , m_index); +io_write8 (MCHP_EMI0_EC_ADDRESS_MSB , m_index >>8 );
Can the 16-bit write suffice?
drivers/hwmon/lenovo-ec-sensors.c line 54
Quoted 1 line
drivers/hwmon/lenovo-ec-sensors.c new file +1
-0+ onebyte =io_read8 (MCHP_EMI0_EC_DATA_BYTE0 + (phy_index &3 ));
GENMASK()
Quoted 3 lines
drivers/hwmon/lenovo-ec-sensors.c new file +3
-0+io_write8 (MCHP_EMI0_APPLICATION_ID ,0x01 );/* write 0x01 again to clean */ +return onebyte; +}
...
drivers/hwmon/lenovo-ec-sensors.c line 175
Quoted 3 lines
drivers/hwmon/lenovo-ec-sensors.c new file +3
-0+struct ec_sensors_data { +struct mutex mec_mutex;/* lock for sensor data access */ +/*int platform_id;*/
Huh?! Please remove, if no use for it.
Quoted 5 lines
drivers/hwmon/lenovo-ec-sensors.c new file +5
-0+const char *const *fan_labels; +const char *const *temp_labels; +const int *fan_map; +const int *temp_map; +};
...
Quoted 19 lines
drivers/hwmon/lenovo-ec-sensors.c new file +19
-0+static int +lenovo_ec_do_read_fan (struct ec_sensors_data *data,u32 attr,int channel,long *val) +{ +u8 lsb, msb; + + channel *=2 ; +switch (attr) { +case hwmon_fan_input: +mutex_lock (&data->mec_mutex); + lsb =get_ec_reg (4 ,0x20 + channel); + msb =get_ec_reg (4 ,0x21 + channel); +mutex_unlock (&data->mec_mutex); + *val = (msb <<8 ) + lsb; +return 0 ; +case hwmon_fan_max: +mutex_lock (&data->mec_mutex); + lsb =get_ec_reg (4 ,0x40 + channel); + msb =get_ec_reg (4 ,0x41 + channel); +mutex_unlock (&data->mec_mutex);
drivers/hwmon/lenovo-ec-sensors.c line 230
Quoted 10 lines
drivers/hwmon/lenovo-ec-sensors.c new file +10
-0+ *val = (msb <<8 ) + lsb; +return 0 ; +case hwmon_fan_min: +case hwmon_fan_div: +case hwmon_fan_alarm: +break ; +default : +break ; + } +return -EOPNOTSUPP ;
Combine with the above and return only once this from the default case.
Quoted 1 line
+}
...
drivers/hwmon/lenovo-ec-sensors.c line 242
Quoted 10 lines
drivers/hwmon/lenovo-ec-sensors.c new file +10
-0+static int +lenovo_ec_hwmon_read_string (struct device *dev,enum hwmon_sensor_types type, +u32 attr,int channel,const char **str) +{ +struct ec_sensors_data *state =dev_get_drvdata (dev); + +switch (type) { +case hwmon_temp: + *str = state->temp_labels[channel]; +break ;
In the other function you returned directly. Keep the style consistent, please.
Quoted 8 lines
drivers/hwmon/lenovo-ec-sensors.c new file +8
-0+case hwmon_fan: + *str = state->fan_labels[channel]; +break ; +default : +return -EOPNOTSUPP ; + } +return 0 ; +}
...
Quoted 6 lines
drivers/hwmon/lenovo-ec-sensors.c new file +6
-0+static int +lenovo_ec_hwmon_read (struct device *dev,enum hwmon_sensor_types type, +u32 attr,int channel,long *val) +{ +struct ec_sensors_data *data =dev_get_drvdata (dev); +
drivers/hwmon/lenovo-ec-sensors.c line 267
Quoted 10 lines
drivers/hwmon/lenovo-ec-sensors.c new file +9
-0+switch (type) { +case hwmon_temp: +return lenovo_ec_do_read_temp (data, attr, data->temp_map[channel], val); +case hwmon_fan: +return lenovo_ec_do_read_fan (data, attr, data->fan_map[channel], val); +default : +return -EOPNOTSUPP ; + } +return 0 ;
Dead code.
Quoted 1 line
+}
...
Quoted 7 lines
drivers/hwmon/lenovo-ec-sensors.c new file +7
-0+static umode_t +lenovo_ec_hwmon_is_visible (const void *data,enum hwmon_sensor_types type, +u32 attr,int channel) +{ +switch (type) { +case hwmon_temp: +if (attr == hwmon_temp_input || attr == hwmon_temp_label)
drivers/hwmon/lenovo-ec-sensors.c line 286
Quoted 10 lines
drivers/hwmon/lenovo-ec-sensors.c new file +10
-0+return 0444 ; +break ; +case hwmon_fan: +if (attr == hwmon_fan_input || attr == hwmon_fan_max || attr == hwmon_fan_label) +return 0444 ; +break ; +default : +return 0 ; + } +return 0 ;
Same comment about the style.
Quoted 1 line
+}
...
drivers/hwmon/lenovo-ec-sensors.c line 503
Quoted 13 lines
drivers/hwmon/lenovo-ec-sensors.c new file +12
-0+static int lenovo_ec_probe (struct platform_device *pdev) +{ +struct device *hwdev; +struct ec_sensors_data *ec_data; +const struct hwmon_chip_info *chip_info; +struct device *dev = &pdev->dev; +const struct dmi_system_id *dmi_id; +int app_id; + + ec_data =devm_kzalloc (dev,sizeof (struct ec_sensors_data ),GFP_KERNEL ); +if (!ec_data) { +release_region (IO_REGION_START ,IO_REGION_LENGTH );
This is weird. Please, either move request region to the probe, or drop these calls here. Obviously you haven't checked the bind-unbind-bind cycle with error injection.
Quoted 67 lines
drivers/hwmon/lenovo-ec-sensors.c new file +67
-0+return -ENOMEM ; + } + +dev_set_drvdata (dev, ec_data); + + chip_info = &lenovo_ec_chip_info; + +mutex_init (&ec_data->mec_mutex); + +mutex_lock (&ec_data->mec_mutex); + app_id =io_read8 (MCHP_EMI0_APPLICATION_ID ); +if (app_id)/* check EMI Application ID Value */ +io_write8 (MCHP_EMI0_APPLICATION_ID , app_id);/* set EMI Application ID to 0 */ +io_write8 (MCHP_EMI0_EC_ADDRESS_LSB ,MCHP_SING_IDX ); +io_write8 (MCHP_EMI0_EC_ADDRESS_MSB ,MCHP_SING_IDX >>8 ); +mutex_unlock (&ec_data->mec_mutex); + +if ((io_read8 (MCHP_EMI0_EC_DATA_BYTE0 ) !='M' ) && + (io_read8 (MCHP_EMI0_EC_DATA_BYTE1 ) !='C' ) && + (io_read8 (MCHP_EMI0_EC_DATA_BYTE2 ) !='H' ) && + (io_read8 (MCHP_EMI0_EC_DATA_BYTE3 ) !='P' )) { +release_region (IO_REGION_START ,IO_REGION_LENGTH ); +return -ENODEV ; + } + + dmi_id =dmi_first_match (thinkstation_dmi_table); + +switch ((long )dmi_id->driver_data) { +case 0 : + ec_data->fan_labels = px_ec_fan_label; + ec_data->temp_labels = lenovo_px_ec_temp_label; + ec_data->fan_map = px_fan_map; + ec_data->temp_map = px_temp_map; + lenovo_ec_chip_info.info = lenovo_ec_hwmon_info_px; +break ; +case 1 : + ec_data->fan_labels = p7_ec_fan_label; + ec_data->temp_labels = lenovo_gen_ec_temp_label; + ec_data->fan_map = p7_fan_map; + ec_data->temp_map = gen_temp_map; + lenovo_ec_chip_info.info = lenovo_ec_hwmon_info_p7; +break ; +case 2 : + ec_data->fan_labels = p5_ec_fan_label; + ec_data->temp_labels = lenovo_gen_ec_temp_label; + ec_data->fan_map = p5_fan_map; + ec_data->temp_map = gen_temp_map; + lenovo_ec_chip_info.info = lenovo_ec_hwmon_info_p5; +break ; +case 3 : + ec_data->fan_labels = p8_ec_fan_label; + ec_data->temp_labels = lenovo_gen_ec_temp_label; + ec_data->fan_map = p8_fan_map; + ec_data->temp_map = gen_temp_map; + lenovo_ec_chip_info.info = lenovo_ec_hwmon_info_p8; +break ; +default : +release_region (IO_REGION_START ,IO_REGION_LENGTH ); +return -ENODEV ; + } + + hwdev =devm_hwmon_device_register_with_info (dev,"lenovo_ec" , + ec_data, + chip_info,NULL ); + +return PTR_ERR_OR_ZERO (hwdev); +}
...
drivers/hwmon/lenovo-ec-sensors.c line 587
Quoted 2 lines
drivers/hwmon/lenovo-ec-sensors.c new file +2
-0+if (!request_region (IO_REGION_START ,IO_REGION_LENGTH ,"LNV-WKS" )) { +pr_err (":request fail\n" );
I haven't noticed pr_fmt(). How can the user distinguish this from something similar from another place?
Quoted 2 lines
(quoted diff) +2
-0+ return -EIO; + }
...
drivers/hwmon/lenovo-ec-sensors.c line 609
Quoted 8 lines
drivers/hwmon/lenovo-ec-sensors.c new file +7
-0+static void __exit lenovo_ec_exit(void) +{ +release_region (IO_REGION_START ,IO_REGION_LENGTH ); +platform_device_unregister (lenovo_ec_sensors_platform_device); +platform_driver_unregister (&lenovo_ec_sensors_platform_driver); +} +
Unneeded blank line (see also below).
drivers/hwmon/lenovo-ec-sensors.c line 611
Quoted 2 lines
drivers/hwmon/lenovo-ec-sensors.c new file +2
-0+module_init (lenovo_ec_init); +module_exit (lenovo_ec_exit);
Move each of them closer to the respective callback implementation.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Guenter Roeck
maintainerQuoted 8 lines · Andy Shevchenko
Quoted 4 lines · David Ober
This addition adds in the ability for the system to scan the EC chip in the Lenovo ThinkStation systems to get the current fan RPM speeds the Maximum speed value for each fan also provides the CPU, DIMM other thermal statuses
Besides the compilation error, see other remarks below.
Thanks a lot for the detailed review. Dropped the driver for now.
Guenter
Andy
Sorry about the compile break comma got changed to period when I was adding in the spaces checkpatch forced me to put in between the values and since I was only adding spaces did not think to check compile
Thanks for the comments I will fix these and resubmit soon.
David
-----Original Message-----
From: Andy Shevchenko <[email protected]>
Sent: Monday, March 25, 2024 8:30 AM
To: David Ober <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; David Ober <[email protected]>; Mark Pearson <[email protected]>
Subject: [External] Re: [PATCH v4] hwmon:Add EC Chip driver for Lenovo ThinkStation motherboards
Quoted 4 lines · David Ober
This addition adds in the ability for the system to scan the EC chip in the Lenovo ThinkStation systems to get the current fan RPM speeds the Maximum speed value for each fan also provides the CPU, DIMM other thermal statuses
Besides the compilation error, see other remarks below.
...
Quoted 2 lines
Signed-off-by David Ober <[email protected]>Signed-off-by David Ober <[email protected]>
Can you leave only one of these?
Quoted 9 lines
drivers/hwmon/Kconfig +9
-0+config SENSORS_LENOVO_EC + tristate "Sensor reader for Lenovo ThinkStations" + depends on X86 + help + If you say yes here you get support for LENOVO + EC Sensor data on newer ThinkStation systems + + This driver can also be built as a module. If so, the module + will be called lenovo_ec_sensors.
...
Quoted 1 line
+ * Copyright (C) 2023 David Ober (Lenovo) <[email protected]>
2024?
...
Use IWYU principle (include what you use). See below what I have noticed (may not be the full list of missing inclusions).
drivers/hwmon/lenovo-ec-sensors.c line 17
Quoted 2 lines
drivers/hwmon/lenovo-ec-sensors.c new file +2
-0+#include <linux/acpi.h> +#include <linux/delay.h>
+ device.h
Quoted 1 line
+#include <
linux/dmi.h>
+ err.h
drivers/hwmon/lenovo-ec-sensors.c line 22
Quoted 5 lines
drivers/hwmon/lenovo-ec-sensors.c new file +4
-0+#include <linux/hwmon.h> +#include <linux/io.h> +#include <linux/ioport.h> +#include <linux/kernel.h>
How is this one being used, please?
Quoted 1 line
+#include <
linux/module.h>
+ mutex.h
Quoted 1 line
+#include <
linux/platform_device.h>
+ types.h
Quoted 1 line
+#include <
linux/units.h>
...
drivers/hwmon/lenovo-ec-sensors.c line 39
Quoted 2 lines
drivers/hwmon/lenovo-ec-sensors.c new file +2
-0+#define io_write8 (a, b) outb_p(b, a) +#define io_read8 (a) inb_p(a)
First of all, these are too generic, second, what's the point? If you wish to make useful macros, put a pointer to the private data, for example, from which you can get the address.
...
Quoted 1 line
+static inline
uint8_t
uint8_t...
Review
Quoted 2 lines
(quoted diff) +2
-0+get_ec_reg(unsigned char page, unsigned char index) { + u8 onebyte;
u8... Just in a few closer lines :-(
Can you be consistent with a kernel types?
drivers/hwmon/lenovo-ec-sensors.c line 50
Quoted 6 lines
drivers/hwmon/lenovo-ec-sensors.c new file +6
-0+unsigned short m_index; +unsigned short phy_index = page *256 + index; + +io_write8 (MCHP_EMI0_APPLICATION_ID ,0x01 ); + + m_index = phy_index &0x7FFC ;
GENMASK() (you will need bits.h for this)
drivers/hwmon/lenovo-ec-sensors.c line 52
Quoted 2 lines
drivers/hwmon/lenovo-ec-sensors.c new file +2
-0+io_write8 (MCHP_EMI0_EC_ADDRESS_LSB , m_index); +io_write8 (MCHP_EMI0_EC_ADDRESS_MSB , m_index >>8 );
Can the 16-bit write suffice?
drivers/hwmon/lenovo-ec-sensors.c line 54
Quoted 1 line
drivers/hwmon/lenovo-ec-sensors.c new file +1
-0+ onebyte =io_read8 (MCHP_EMI0_EC_DATA_BYTE0 + (phy_index &3 ));
GENMASK()
Quoted 3 lines
drivers/hwmon/lenovo-ec-sensors.c new file +3
-0+io_write8 (MCHP_EMI0_APPLICATION_ID ,0x01 );/* write 0x01 again to clean */ +return onebyte; +}
...
drivers/hwmon/lenovo-ec-sensors.c line 175
Quoted 3 lines
drivers/hwmon/lenovo-ec-sensors.c new file +3
-0+struct ec_sensors_data { +struct mutex mec_mutex;/* lock for sensor data access */ +/*int platform_id;*/
Huh?! Please remove, if no use for it.
Quoted 5 lines
drivers/hwmon/lenovo-ec-sensors.c new file +5
-0+const char *const *fan_labels; +const char *const *temp_labels; +const int *fan_map; +const int *temp_map; +};
...
Quoted 19 lines
drivers/hwmon/lenovo-ec-sensors.c new file +19
-0+static int +lenovo_ec_do_read_fan (struct ec_sensors_data *data,u32 attr,int +channel,long *val) { +u8 lsb, msb; + + channel *=2 ; +switch (attr) { +case hwmon_fan_input: +mutex_lock (&data->mec_mutex); + lsb =get_ec_reg (4 ,0x20 + channel); + msb =get_ec_reg (4 ,0x21 + channel); +mutex_unlock (&data->mec_mutex); + *val = (msb <<8 ) + lsb; +return 0 ; +case hwmon_fan_max: +mutex_lock (&data->mec_mutex); + lsb =get_ec_reg (4 ,0x40 + channel); + msb =get_ec_reg (4 ,0x41 + channel); +mutex_unlock (&data->mec_mutex);
drivers/hwmon/lenovo-ec-sensors.c line 230
Quoted 10 lines
drivers/hwmon/lenovo-ec-sensors.c new file +10
-0+ *val = (msb <<8 ) + lsb; +return 0 ; +case hwmon_fan_min: +case hwmon_fan_div: +case hwmon_fan_alarm: +break ; +default : +break ; + } +return -EOPNOTSUPP ;
Combine with the above and return only once this from the default case.
Quoted 1 line
+}
...
drivers/hwmon/lenovo-ec-sensors.c line 242
Quoted 9 lines
drivers/hwmon/lenovo-ec-sensors.c new file +9
-0+static int +lenovo_ec_hwmon_read_string (struct device *dev,enum hwmon_sensor_types type, +u32 attr,int channel,const char **str) { +struct ec_sensors_data *state =dev_get_drvdata (dev); + +switch (type) { +case hwmon_temp: + *str = state->temp_labels[channel]; +break ;
In the other function you returned directly. Keep the style consistent, please.
Quoted 8 lines
drivers/hwmon/lenovo-ec-sensors.c new file +8
-0+case hwmon_fan: + *str = state->fan_labels[channel]; +break ; +default : +return -EOPNOTSUPP ; + } +return 0 ; +}
...
Quoted 5 lines
drivers/hwmon/lenovo-ec-sensors.c new file +5
-0+static int +lenovo_ec_hwmon_read (struct device *dev,enum hwmon_sensor_types type, +u32 attr,int channel,long *val) { +struct ec_sensors_data *data =dev_get_drvdata (dev); +
drivers/hwmon/lenovo-ec-sensors.c line 267
Quoted 10 lines
drivers/hwmon/lenovo-ec-sensors.c new file +9
-0+switch (type) { +case hwmon_temp: +return lenovo_ec_do_read_temp (data, attr, data->temp_map[channel], val); +case hwmon_fan: +return lenovo_ec_do_read_fan (data, attr, data->fan_map[channel], val); +default : +return -EOPNOTSUPP ; + } +return 0 ;
Dead code.
Quoted 1 line
+}
...
Quoted 7 lines
drivers/hwmon/lenovo-ec-sensors.c new file +7
-0+static umode_t +lenovo_ec_hwmon_is_visible (const void *data,enum hwmon_sensor_types type, +u32 attr,int channel) +{ +switch (type) { +case hwmon_temp: +if (attr == hwmon_temp_input || attr == hwmon_temp_label)
drivers/hwmon/lenovo-ec-sensors.c line 286
Quoted 10 lines
drivers/hwmon/lenovo-ec-sensors.c new file +10
-0+return 0444 ; +break ; +case hwmon_fan: +if (attr == hwmon_fan_input || attr == hwmon_fan_max || attr == hwmon_fan_label) +return 0444 ; +break ; +default : +return 0 ; + } +return 0 ;
Same comment about the style.
Quoted 1 line
+}
...
drivers/hwmon/lenovo-ec-sensors.c line 503
Quoted 12 lines
drivers/hwmon/lenovo-ec-sensors.c new file +11
-0+static int lenovo_ec_probe (struct platform_device *pdev) { +struct device *hwdev; +struct ec_sensors_data *ec_data; +const struct hwmon_chip_info *chip_info; +struct device *dev = &pdev->dev; +const struct dmi_system_id *dmi_id; +int app_id; + + ec_data =devm_kzalloc (dev,sizeof (struct ec_sensors_data ),GFP_KERNEL ); +if (!ec_data) { +release_region (IO_REGION_START ,IO_REGION_LENGTH );
This is weird. Please, either move request region to the probe, or drop these calls here. Obviously you haven't checked the bind-unbind-bind cycle with error injection.
Quoted 67 lines
drivers/hwmon/lenovo-ec-sensors.c new file +67
-0+return -ENOMEM ; + } + +dev_set_drvdata (dev, ec_data); + + chip_info = &lenovo_ec_chip_info; + +mutex_init (&ec_data->mec_mutex); + +mutex_lock (&ec_data->mec_mutex); + app_id =io_read8 (MCHP_EMI0_APPLICATION_ID ); +if (app_id)/* check EMI Application ID Value */ +io_write8 (MCHP_EMI0_APPLICATION_ID , app_id);/* set EMI Application ID to 0 */ +io_write8 (MCHP_EMI0_EC_ADDRESS_LSB ,MCHP_SING_IDX ); +io_write8 (MCHP_EMI0_EC_ADDRESS_MSB ,MCHP_SING_IDX >>8 ); +mutex_unlock (&ec_data->mec_mutex); + +if ((io_read8 (MCHP_EMI0_EC_DATA_BYTE0 ) !='M' ) && + (io_read8 (MCHP_EMI0_EC_DATA_BYTE1 ) !='C' ) && + (io_read8 (MCHP_EMI0_EC_DATA_BYTE2 ) !='H' ) && + (io_read8 (MCHP_EMI0_EC_DATA_BYTE3 ) !='P' )) { +release_region (IO_REGION_START ,IO_REGION_LENGTH ); +return -ENODEV ; + } + + dmi_id =dmi_first_match (thinkstation_dmi_table); + +switch ((long )dmi_id->driver_data) { +case 0 : + ec_data->fan_labels = px_ec_fan_label; + ec_data->temp_labels = lenovo_px_ec_temp_label; + ec_data->fan_map = px_fan_map; + ec_data->temp_map = px_temp_map; + lenovo_ec_chip_info.info = lenovo_ec_hwmon_info_px; +break ; +case 1 : + ec_data->fan_labels = p7_ec_fan_label; + ec_data->temp_labels = lenovo_gen_ec_temp_label; + ec_data->fan_map = p7_fan_map; + ec_data->temp_map = gen_temp_map; + lenovo_ec_chip_info.info = lenovo_ec_hwmon_info_p7; +break ; +case 2 : + ec_data->fan_labels = p5_ec_fan_label; + ec_data->temp_labels = lenovo_gen_ec_temp_label; + ec_data->fan_map = p5_fan_map; + ec_data->temp_map = gen_temp_map; + lenovo_ec_chip_info.info = lenovo_ec_hwmon_info_p5; +break ; +case 3 : + ec_data->fan_labels = p8_ec_fan_label; + ec_data->temp_labels = lenovo_gen_ec_temp_label; + ec_data->fan_map = p8_fan_map; + ec_data->temp_map = gen_temp_map; + lenovo_ec_chip_info.info = lenovo_ec_hwmon_info_p8; +break ; +default : +release_region (IO_REGION_START ,IO_REGION_LENGTH ); +return -ENODEV ; + } + + hwdev =devm_hwmon_device_register_with_info (dev,"lenovo_ec" , + ec_data, + chip_info,NULL ); + +return PTR_ERR_OR_ZERO (hwdev); +}
...
drivers/hwmon/lenovo-ec-sensors.c line 587
Quoted 2 lines
drivers/hwmon/lenovo-ec-sensors.c new file +2
-0+if (!request_region (IO_REGION_START ,IO_REGION_LENGTH ,"LNV-WKS" )) { +pr_err (":request fail\n" );
I haven't noticed pr_fmt(). How can the user distinguish this from something similar from another place?
Quoted 2 lines
(quoted diff) +2
-0+ return -EIO; + }
...
drivers/hwmon/lenovo-ec-sensors.c line 609
Quoted 7 lines
drivers/hwmon/lenovo-ec-sensors.c new file +6
-0+static void __exit lenovo_ec_exit(void) { +release_region (IO_REGION_START ,IO_REGION_LENGTH ); +platform_device_unregister (lenovo_ec_sensors_platform_device); +platform_driver_unregister (&lenovo_ec_sensors_platform_driver); +} +
Unneeded blank line (see also below).
drivers/hwmon/lenovo-ec-sensors.c line 611
Quoted 2 lines
drivers/hwmon/lenovo-ec-sensors.c new file +2
-0+module_init (lenovo_ec_init); +module_exit (lenovo_ec_exit);
Move each of them closer to the respective callback implementation.
--
With Best Regards,
Andy Shevchenko