diff options
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/Kconfig | 14 | ||||
-rw-r--r-- | drivers/hwmon/Makefile | 1 | ||||
-rw-r--r-- | drivers/hwmon/abituguru3.c | 18 | ||||
-rw-r--r-- | drivers/hwmon/adt7473.c | 3 | ||||
-rw-r--r-- | drivers/hwmon/hdaps.c | 8 | ||||
-rw-r--r-- | drivers/hwmon/i5k_amb.c | 39 | ||||
-rw-r--r-- | drivers/hwmon/ibmaem.c | 1111 | ||||
-rw-r--r-- | drivers/hwmon/lm75.c | 20 | ||||
-rw-r--r-- | drivers/hwmon/lm85.c | 25 |
9 files changed, 1212 insertions, 27 deletions
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 4dc76bc45c9d..00ff53348491 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig | |||
@@ -330,6 +330,20 @@ config SENSORS_CORETEMP | |||
330 | sensor inside your CPU. Supported all are all known variants | 330 | sensor inside your CPU. Supported all are all known variants |
331 | of Intel Core family. | 331 | of Intel Core family. |
332 | 332 | ||
333 | config SENSORS_IBMAEM | ||
334 | tristate "IBM Active Energy Manager temperature/power sensors and control" | ||
335 | select IPMI_SI | ||
336 | depends on IPMI_HANDLER | ||
337 | help | ||
338 | If you say yes here you get support for the temperature and | ||
339 | power sensors and capping hardware in various IBM System X | ||
340 | servers that support Active Energy Manager. This includes | ||
341 | the x3350, x3550, x3650, x3655, x3755, x3850 M2, x3950 M2, | ||
342 | and certain HS2x/LS2x/QS2x blades. | ||
343 | |||
344 | This driver can also be built as a module. If so, the module | ||
345 | will be called ibmaem. | ||
346 | |||
333 | config SENSORS_IBMPEX | 347 | config SENSORS_IBMPEX |
334 | tristate "IBM PowerExecutive temperature/power sensors" | 348 | tristate "IBM PowerExecutive temperature/power sensors" |
335 | select IPMI_SI | 349 | select IPMI_SI |
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index 3bdb05a5cbd7..d098677e08de 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile | |||
@@ -41,6 +41,7 @@ obj-$(CONFIG_SENSORS_GL518SM) += gl518sm.o | |||
41 | obj-$(CONFIG_SENSORS_GL520SM) += gl520sm.o | 41 | obj-$(CONFIG_SENSORS_GL520SM) += gl520sm.o |
42 | obj-$(CONFIG_SENSORS_HDAPS) += hdaps.o | 42 | obj-$(CONFIG_SENSORS_HDAPS) += hdaps.o |
43 | obj-$(CONFIG_SENSORS_I5K_AMB) += i5k_amb.o | 43 | obj-$(CONFIG_SENSORS_I5K_AMB) += i5k_amb.o |
44 | obj-$(CONFIG_SENSORS_IBMAEM) += ibmaem.o | ||
44 | obj-$(CONFIG_SENSORS_IBMPEX) += ibmpex.o | 45 | obj-$(CONFIG_SENSORS_IBMPEX) += ibmpex.o |
45 | obj-$(CONFIG_SENSORS_IT87) += it87.o | 46 | obj-$(CONFIG_SENSORS_IT87) += it87.o |
46 | obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o | 47 | obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o |
diff --git a/drivers/hwmon/abituguru3.c b/drivers/hwmon/abituguru3.c index ed33fddc4dee..f00f497b9ca9 100644 --- a/drivers/hwmon/abituguru3.c +++ b/drivers/hwmon/abituguru3.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <linux/platform_device.h> | 30 | #include <linux/platform_device.h> |
31 | #include <linux/hwmon.h> | 31 | #include <linux/hwmon.h> |
32 | #include <linux/hwmon-sysfs.h> | 32 | #include <linux/hwmon-sysfs.h> |
33 | #include <linux/dmi.h> | ||
33 | #include <asm/io.h> | 34 | #include <asm/io.h> |
34 | 35 | ||
35 | /* uGuru3 bank addresses */ | 36 | /* uGuru3 bank addresses */ |
@@ -323,7 +324,7 @@ static const struct abituguru3_motherboard_info abituguru3_motherboards[] = { | |||
323 | { "AUX1 Fan", 36, 2, 60, 1, 0 }, | 324 | { "AUX1 Fan", 36, 2, 60, 1, 0 }, |
324 | { NULL, 0, 0, 0, 0, 0 } } | 325 | { NULL, 0, 0, 0, 0, 0 } } |
325 | }, | 326 | }, |
326 | { 0x0013, "unknown", { | 327 | { 0x0013, "Abit AW8D", { |
327 | { "CPU Core", 0, 0, 10, 1, 0 }, | 328 | { "CPU Core", 0, 0, 10, 1, 0 }, |
328 | { "DDR", 1, 0, 10, 1, 0 }, | 329 | { "DDR", 1, 0, 10, 1, 0 }, |
329 | { "DDR VTT", 2, 0, 10, 1, 0 }, | 330 | { "DDR VTT", 2, 0, 10, 1, 0 }, |
@@ -349,6 +350,7 @@ static const struct abituguru3_motherboard_info abituguru3_motherboards[] = { | |||
349 | { "AUX2 Fan", 36, 2, 60, 1, 0 }, | 350 | { "AUX2 Fan", 36, 2, 60, 1, 0 }, |
350 | { "AUX3 Fan", 37, 2, 60, 1, 0 }, | 351 | { "AUX3 Fan", 37, 2, 60, 1, 0 }, |
351 | { "AUX4 Fan", 38, 2, 60, 1, 0 }, | 352 | { "AUX4 Fan", 38, 2, 60, 1, 0 }, |
353 | { "AUX5 Fan", 39, 2, 60, 1, 0 }, | ||
352 | { NULL, 0, 0, 0, 0, 0 } } | 354 | { NULL, 0, 0, 0, 0, 0 } } |
353 | }, | 355 | }, |
354 | { 0x0014, "Abit AB9 Pro", { | 356 | { 0x0014, "Abit AB9 Pro", { |
@@ -1111,11 +1113,12 @@ static int __init abituguru3_detect(void) | |||
1111 | { | 1113 | { |
1112 | /* See if there is an uguru3 there. An idle uGuru3 will hold 0x00 or | 1114 | /* See if there is an uguru3 there. An idle uGuru3 will hold 0x00 or |
1113 | 0x08 at DATA and 0xAC at CMD. Sometimes the uGuru3 will hold 0x05 | 1115 | 0x08 at DATA and 0xAC at CMD. Sometimes the uGuru3 will hold 0x05 |
1114 | at CMD instead, why is unknown. So we test for 0x05 too. */ | 1116 | or 0x55 at CMD instead, why is unknown. */ |
1115 | u8 data_val = inb_p(ABIT_UGURU3_BASE + ABIT_UGURU3_DATA); | 1117 | u8 data_val = inb_p(ABIT_UGURU3_BASE + ABIT_UGURU3_DATA); |
1116 | u8 cmd_val = inb_p(ABIT_UGURU3_BASE + ABIT_UGURU3_CMD); | 1118 | u8 cmd_val = inb_p(ABIT_UGURU3_BASE + ABIT_UGURU3_CMD); |
1117 | if (((data_val == 0x00) || (data_val == 0x08)) && | 1119 | if (((data_val == 0x00) || (data_val == 0x08)) && |
1118 | ((cmd_val == 0xAC) || (cmd_val == 0x05))) | 1120 | ((cmd_val == 0xAC) || (cmd_val == 0x05) || |
1121 | (cmd_val == 0x55))) | ||
1119 | return ABIT_UGURU3_BASE; | 1122 | return ABIT_UGURU3_BASE; |
1120 | 1123 | ||
1121 | ABIT_UGURU3_DEBUG("no Abit uGuru3 found, data = 0x%02X, cmd = " | 1124 | ABIT_UGURU3_DEBUG("no Abit uGuru3 found, data = 0x%02X, cmd = " |
@@ -1138,6 +1141,15 @@ static int __init abituguru3_init(void) | |||
1138 | int address, err; | 1141 | int address, err; |
1139 | struct resource res = { .flags = IORESOURCE_IO }; | 1142 | struct resource res = { .flags = IORESOURCE_IO }; |
1140 | 1143 | ||
1144 | #ifdef CONFIG_DMI | ||
1145 | const char *board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR); | ||
1146 | |||
1147 | /* safety check, refuse to load on non Abit motherboards */ | ||
1148 | if (!force && (!board_vendor || | ||
1149 | strcmp(board_vendor, "http://www.abit.com.tw/"))) | ||
1150 | return -ENODEV; | ||
1151 | #endif | ||
1152 | |||
1141 | address = abituguru3_detect(); | 1153 | address = abituguru3_detect(); |
1142 | if (address < 0) | 1154 | if (address < 0) |
1143 | return address; | 1155 | return address; |
diff --git a/drivers/hwmon/adt7473.c b/drivers/hwmon/adt7473.c index c1009d6f9796..93dbf5e7ff8a 100644 --- a/drivers/hwmon/adt7473.c +++ b/drivers/hwmon/adt7473.c | |||
@@ -309,6 +309,9 @@ no_sensor_update: | |||
309 | ADT7473_REG_PWM_BHVR(i)); | 309 | ADT7473_REG_PWM_BHVR(i)); |
310 | } | 310 | } |
311 | 311 | ||
312 | i = i2c_smbus_read_byte_data(client, ADT7473_REG_CFG4); | ||
313 | data->max_duty_at_overheat = !!(i & ADT7473_CFG4_MAX_DUTY_AT_OVT); | ||
314 | |||
312 | data->limits_last_updated = local_jiffies; | 315 | data->limits_last_updated = local_jiffies; |
313 | data->limits_valid = 1; | 316 | data->limits_valid = 1; |
314 | 317 | ||
diff --git a/drivers/hwmon/hdaps.c b/drivers/hwmon/hdaps.c index bab5fd2e4dfd..50f22690d611 100644 --- a/drivers/hwmon/hdaps.c +++ b/drivers/hwmon/hdaps.c | |||
@@ -515,16 +515,24 @@ static struct dmi_system_id __initdata hdaps_whitelist[] = { | |||
515 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad R50"), | 515 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad R50"), |
516 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad R51"), | 516 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad R51"), |
517 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad R52"), | 517 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad R52"), |
518 | HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad R61i"), | ||
519 | HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad R61"), | ||
518 | HDAPS_DMI_MATCH_INVERT("IBM", "ThinkPad T41p"), | 520 | HDAPS_DMI_MATCH_INVERT("IBM", "ThinkPad T41p"), |
519 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T41"), | 521 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T41"), |
520 | HDAPS_DMI_MATCH_INVERT("IBM", "ThinkPad T42p"), | 522 | HDAPS_DMI_MATCH_INVERT("IBM", "ThinkPad T42p"), |
521 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T42"), | 523 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T42"), |
522 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T43"), | 524 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad T43"), |
523 | HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad T60"), | 525 | HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad T60"), |
526 | HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad T61p"), | ||
527 | HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad T61"), | ||
524 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad X40"), | 528 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad X40"), |
525 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad X41"), | 529 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad X41"), |
526 | HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad X60"), | 530 | HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad X60"), |
531 | HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad X61s"), | ||
532 | HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad X61"), | ||
527 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad Z60m"), | 533 | HDAPS_DMI_MATCH_NORMAL("IBM", "ThinkPad Z60m"), |
534 | HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad Z61m"), | ||
535 | HDAPS_DMI_MATCH_INVERT("LENOVO", "ThinkPad Z61p"), | ||
528 | { .ident = NULL } | 536 | { .ident = NULL } |
529 | }; | 537 | }; |
530 | 538 | ||
diff --git a/drivers/hwmon/i5k_amb.c b/drivers/hwmon/i5k_amb.c index 6ac5c6f53585..f9e2ed621f7b 100644 --- a/drivers/hwmon/i5k_amb.c +++ b/drivers/hwmon/i5k_amb.c | |||
@@ -111,6 +111,7 @@ struct i5k_amb_data { | |||
111 | void __iomem *amb_mmio; | 111 | void __iomem *amb_mmio; |
112 | struct i5k_device_attribute *attrs; | 112 | struct i5k_device_attribute *attrs; |
113 | unsigned int num_attrs; | 113 | unsigned int num_attrs; |
114 | unsigned long chipset_id; | ||
114 | }; | 115 | }; |
115 | 116 | ||
116 | static ssize_t show_name(struct device *dev, struct device_attribute *devattr, | 117 | static ssize_t show_name(struct device *dev, struct device_attribute *devattr, |
@@ -382,7 +383,8 @@ err: | |||
382 | return res; | 383 | return res; |
383 | } | 384 | } |
384 | 385 | ||
385 | static int __devinit i5k_find_amb_registers(struct i5k_amb_data *data) | 386 | static int __devinit i5k_find_amb_registers(struct i5k_amb_data *data, |
387 | unsigned long devid) | ||
386 | { | 388 | { |
387 | struct pci_dev *pcidev; | 389 | struct pci_dev *pcidev; |
388 | u32 val32; | 390 | u32 val32; |
@@ -390,7 +392,7 @@ static int __devinit i5k_find_amb_registers(struct i5k_amb_data *data) | |||
390 | 392 | ||
391 | /* Find AMB register memory space */ | 393 | /* Find AMB register memory space */ |
392 | pcidev = pci_get_device(PCI_VENDOR_ID_INTEL, | 394 | pcidev = pci_get_device(PCI_VENDOR_ID_INTEL, |
393 | PCI_DEVICE_ID_INTEL_5000_ERR, | 395 | devid, |
394 | NULL); | 396 | NULL); |
395 | if (!pcidev) | 397 | if (!pcidev) |
396 | return -ENODEV; | 398 | return -ENODEV; |
@@ -409,6 +411,8 @@ static int __devinit i5k_find_amb_registers(struct i5k_amb_data *data) | |||
409 | goto out; | 411 | goto out; |
410 | } | 412 | } |
411 | 413 | ||
414 | data->chipset_id = devid; | ||
415 | |||
412 | res = 0; | 416 | res = 0; |
413 | out: | 417 | out: |
414 | pci_dev_put(pcidev); | 418 | pci_dev_put(pcidev); |
@@ -441,10 +445,30 @@ out: | |||
441 | return res; | 445 | return res; |
442 | } | 446 | } |
443 | 447 | ||
448 | static unsigned long i5k_channel_pci_id(struct i5k_amb_data *data, | ||
449 | unsigned long channel) | ||
450 | { | ||
451 | switch (data->chipset_id) { | ||
452 | case PCI_DEVICE_ID_INTEL_5000_ERR: | ||
453 | return PCI_DEVICE_ID_INTEL_5000_FBD0 + channel; | ||
454 | case PCI_DEVICE_ID_INTEL_5400_ERR: | ||
455 | return PCI_DEVICE_ID_INTEL_5400_FBD0 + channel; | ||
456 | default: | ||
457 | BUG(); | ||
458 | } | ||
459 | } | ||
460 | |||
461 | static unsigned long chipset_ids[] = { | ||
462 | PCI_DEVICE_ID_INTEL_5000_ERR, | ||
463 | PCI_DEVICE_ID_INTEL_5400_ERR, | ||
464 | 0 | ||
465 | }; | ||
466 | |||
444 | static int __devinit i5k_amb_probe(struct platform_device *pdev) | 467 | static int __devinit i5k_amb_probe(struct platform_device *pdev) |
445 | { | 468 | { |
446 | struct i5k_amb_data *data; | 469 | struct i5k_amb_data *data; |
447 | struct resource *reso; | 470 | struct resource *reso; |
471 | int i; | ||
448 | int res = -ENODEV; | 472 | int res = -ENODEV; |
449 | 473 | ||
450 | data = kzalloc(sizeof(*data), GFP_KERNEL); | 474 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
@@ -452,19 +476,24 @@ static int __devinit i5k_amb_probe(struct platform_device *pdev) | |||
452 | return -ENOMEM; | 476 | return -ENOMEM; |
453 | 477 | ||
454 | /* Figure out where the AMB registers live */ | 478 | /* Figure out where the AMB registers live */ |
455 | res = i5k_find_amb_registers(data); | 479 | i = 0; |
480 | do { | ||
481 | res = i5k_find_amb_registers(data, chipset_ids[i]); | ||
482 | i++; | ||
483 | } while (res && chipset_ids[i]); | ||
484 | |||
456 | if (res) | 485 | if (res) |
457 | goto err; | 486 | goto err; |
458 | 487 | ||
459 | /* Copy the DIMM presence map for the first two channels */ | 488 | /* Copy the DIMM presence map for the first two channels */ |
460 | res = i5k_channel_probe(&data->amb_present[0], | 489 | res = i5k_channel_probe(&data->amb_present[0], |
461 | PCI_DEVICE_ID_INTEL_5000_FBD0); | 490 | i5k_channel_pci_id(data, 0)); |
462 | if (res) | 491 | if (res) |
463 | goto err; | 492 | goto err; |
464 | 493 | ||
465 | /* Copy the DIMM presence map for the optional second two channels */ | 494 | /* Copy the DIMM presence map for the optional second two channels */ |
466 | i5k_channel_probe(&data->amb_present[2], | 495 | i5k_channel_probe(&data->amb_present[2], |
467 | PCI_DEVICE_ID_INTEL_5000_FBD1); | 496 | i5k_channel_pci_id(data, 1)); |
468 | 497 | ||
469 | /* Set up resource regions */ | 498 | /* Set up resource regions */ |
470 | reso = request_mem_region(data->amb_base, data->amb_len, DRVNAME); | 499 | reso = request_mem_region(data->amb_base, data->amb_len, DRVNAME); |
diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c new file mode 100644 index 000000000000..c9416e657487 --- /dev/null +++ b/drivers/hwmon/ibmaem.c | |||
@@ -0,0 +1,1111 @@ | |||
1 | /* | ||
2 | * A hwmon driver for the IBM Active Energy Manager temperature/power sensors | ||
3 | * and capping functionality. | ||
4 | * Copyright (C) 2008 IBM | ||
5 | * | ||
6 | * Author: Darrick J. Wong <djwong@us.ibm.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | */ | ||
22 | |||
23 | #include <linux/ipmi.h> | ||
24 | #include <linux/module.h> | ||
25 | #include <linux/hwmon.h> | ||
26 | #include <linux/hwmon-sysfs.h> | ||
27 | #include <linux/jiffies.h> | ||
28 | #include <linux/mutex.h> | ||
29 | #include <linux/kdev_t.h> | ||
30 | #include <linux/spinlock.h> | ||
31 | #include <linux/idr.h> | ||
32 | #include <linux/sched.h> | ||
33 | #include <linux/platform_device.h> | ||
34 | #include <linux/math64.h> | ||
35 | #include <linux/time.h> | ||
36 | |||
37 | #define REFRESH_INTERVAL (HZ) | ||
38 | #define IPMI_TIMEOUT (30 * HZ) | ||
39 | #define DRVNAME "aem" | ||
40 | |||
41 | #define AEM_NETFN 0x2E | ||
42 | |||
43 | #define AEM_FIND_FW_CMD 0x80 | ||
44 | #define AEM_ELEMENT_CMD 0x81 | ||
45 | #define AEM_FW_INSTANCE_CMD 0x82 | ||
46 | |||
47 | #define AEM_READ_ELEMENT_CFG 0x80 | ||
48 | #define AEM_READ_BUFFER 0x81 | ||
49 | #define AEM_READ_REGISTER 0x82 | ||
50 | #define AEM_WRITE_REGISTER 0x83 | ||
51 | #define AEM_SET_REG_MASK 0x84 | ||
52 | #define AEM_CLEAR_REG_MASK 0x85 | ||
53 | #define AEM_READ_ELEMENT_CFG2 0x86 | ||
54 | |||
55 | #define AEM_CONTROL_ELEMENT 0 | ||
56 | #define AEM_ENERGY_ELEMENT 1 | ||
57 | #define AEM_CLOCK_ELEMENT 4 | ||
58 | #define AEM_POWER_CAP_ELEMENT 7 | ||
59 | #define AEM_EXHAUST_ELEMENT 9 | ||
60 | #define AEM_POWER_ELEMENT 10 | ||
61 | |||
62 | #define AEM_MODULE_TYPE_ID 0x0001 | ||
63 | |||
64 | #define AEM2_NUM_ENERGY_REGS 2 | ||
65 | #define AEM2_NUM_PCAP_REGS 6 | ||
66 | #define AEM2_NUM_TEMP_REGS 2 | ||
67 | #define AEM2_NUM_SENSORS 14 | ||
68 | |||
69 | #define AEM1_NUM_ENERGY_REGS 1 | ||
70 | #define AEM1_NUM_SENSORS 3 | ||
71 | |||
72 | /* AEM 2.x has more energy registers */ | ||
73 | #define AEM_NUM_ENERGY_REGS AEM2_NUM_ENERGY_REGS | ||
74 | /* AEM 2.x needs more sensor files */ | ||
75 | #define AEM_NUM_SENSORS AEM2_NUM_SENSORS | ||
76 | |||
77 | #define POWER_CAP 0 | ||
78 | #define POWER_CAP_MAX_HOTPLUG 1 | ||
79 | #define POWER_CAP_MAX 2 | ||
80 | #define POWER_CAP_MIN_WARNING 3 | ||
81 | #define POWER_CAP_MIN 4 | ||
82 | #define POWER_AUX 5 | ||
83 | |||
84 | #define AEM_DEFAULT_POWER_INTERVAL 1000 | ||
85 | #define AEM_MIN_POWER_INTERVAL 200 | ||
86 | #define UJ_PER_MJ 1000L | ||
87 | |||
88 | static DEFINE_IDR(aem_idr); | ||
89 | static DEFINE_SPINLOCK(aem_idr_lock); | ||
90 | |||
91 | static struct device_driver aem_driver = { | ||
92 | .name = DRVNAME, | ||
93 | .bus = &platform_bus_type, | ||
94 | }; | ||
95 | |||
96 | struct aem_ipmi_data { | ||
97 | struct completion read_complete; | ||
98 | struct ipmi_addr address; | ||
99 | ipmi_user_t user; | ||
100 | int interface; | ||
101 | |||
102 | struct kernel_ipmi_msg tx_message; | ||
103 | long tx_msgid; | ||
104 | |||
105 | void *rx_msg_data; | ||
106 | unsigned short rx_msg_len; | ||
107 | unsigned char rx_result; | ||
108 | int rx_recv_type; | ||
109 | |||
110 | struct device *bmc_device; | ||
111 | }; | ||
112 | |||
113 | struct aem_ro_sensor_template { | ||
114 | char *label; | ||
115 | ssize_t (*show)(struct device *dev, | ||
116 | struct device_attribute *devattr, | ||
117 | char *buf); | ||
118 | int index; | ||
119 | }; | ||
120 | |||
121 | struct aem_rw_sensor_template { | ||
122 | char *label; | ||
123 | ssize_t (*show)(struct device *dev, | ||
124 | struct device_attribute *devattr, | ||
125 | char *buf); | ||
126 | ssize_t (*set)(struct device *dev, | ||
127 | struct device_attribute *devattr, | ||
128 | const char *buf, size_t count); | ||
129 | int index; | ||
130 | }; | ||
131 | |||
132 | struct aem_data { | ||
133 | struct list_head list; | ||
134 | |||
135 | struct device *hwmon_dev; | ||
136 | struct platform_device *pdev; | ||
137 | struct mutex lock; | ||
138 | char valid; | ||
139 | unsigned long last_updated; /* In jiffies */ | ||
140 | u8 ver_major; | ||
141 | u8 ver_minor; | ||
142 | u8 module_handle; | ||
143 | int id; | ||
144 | struct aem_ipmi_data ipmi; | ||
145 | |||
146 | /* Function to update sensors */ | ||
147 | void (*update)(struct aem_data *data); | ||
148 | |||
149 | /* | ||
150 | * AEM 1.x sensors: | ||
151 | * Available sensors: | ||
152 | * Energy meter | ||
153 | * Power meter | ||
154 | * | ||
155 | * AEM 2.x sensors: | ||
156 | * Two energy meters | ||
157 | * Two power meters | ||
158 | * Two temperature sensors | ||
159 | * Six power cap registers | ||
160 | */ | ||
161 | |||
162 | /* sysfs attrs */ | ||
163 | struct sensor_device_attribute sensors[AEM_NUM_SENSORS]; | ||
164 | |||
165 | /* energy use in mJ */ | ||
166 | u64 energy[AEM_NUM_ENERGY_REGS]; | ||
167 | |||
168 | /* power sampling interval in ms */ | ||
169 | unsigned long power_period[AEM_NUM_ENERGY_REGS]; | ||
170 | |||
171 | /* Everything past here is for AEM2 only */ | ||
172 | |||
173 | /* power caps in dW */ | ||
174 | u16 pcap[AEM2_NUM_PCAP_REGS]; | ||
175 | |||
176 | /* exhaust temperature in C */ | ||
177 | u8 temp[AEM2_NUM_TEMP_REGS]; | ||
178 | }; | ||
179 | |||
180 | /* Data structures returned by the AEM firmware */ | ||
181 | struct aem_iana_id { | ||
182 | u8 bytes[3]; | ||
183 | }; | ||
184 | static struct aem_iana_id system_x_id = { | ||
185 | .bytes = {0x4D, 0x4F, 0x00} | ||
186 | }; | ||
187 | |||
188 | /* These are used to find AEM1 instances */ | ||
189 | struct aem_find_firmware_req { | ||
190 | struct aem_iana_id id; | ||
191 | u8 rsvd; | ||
192 | __be16 index; | ||
193 | __be16 module_type_id; | ||
194 | } __packed; | ||
195 | |||
196 | struct aem_find_firmware_resp { | ||
197 | struct aem_iana_id id; | ||
198 | u8 num_instances; | ||
199 | } __packed; | ||
200 | |||
201 | /* These are used to find AEM2 instances */ | ||
202 | struct aem_find_instance_req { | ||
203 | struct aem_iana_id id; | ||
204 | u8 instance_number; | ||
205 | __be16 module_type_id; | ||
206 | } __packed; | ||
207 | |||
208 | struct aem_find_instance_resp { | ||
209 | struct aem_iana_id id; | ||
210 | u8 num_instances; | ||
211 | u8 major; | ||
212 | u8 minor; | ||
213 | u8 module_handle; | ||
214 | u16 record_id; | ||
215 | } __packed; | ||
216 | |||
217 | /* These are used to query sensors */ | ||
218 | struct aem_read_sensor_req { | ||
219 | struct aem_iana_id id; | ||
220 | u8 module_handle; | ||
221 | u8 element; | ||
222 | u8 subcommand; | ||
223 | u8 reg; | ||
224 | u8 rx_buf_size; | ||
225 | } __packed; | ||
226 | |||
227 | struct aem_read_sensor_resp { | ||
228 | struct aem_iana_id id; | ||
229 | u8 bytes[0]; | ||
230 | } __packed; | ||
231 | |||
232 | /* Data structures to talk to the IPMI layer */ | ||
233 | struct aem_driver_data { | ||
234 | struct list_head aem_devices; | ||
235 | struct ipmi_smi_watcher bmc_events; | ||
236 | struct ipmi_user_hndl ipmi_hndlrs; | ||
237 | }; | ||
238 | |||
239 | static void aem_register_bmc(int iface, struct device *dev); | ||
240 | static void aem_bmc_gone(int iface); | ||
241 | static void aem_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data); | ||
242 | |||
243 | static void aem_remove_sensors(struct aem_data *data); | ||
244 | static int aem_init_aem1(struct aem_ipmi_data *probe); | ||
245 | static int aem_init_aem2(struct aem_ipmi_data *probe); | ||
246 | static int aem1_find_sensors(struct aem_data *data); | ||
247 | static int aem2_find_sensors(struct aem_data *data); | ||
248 | static void update_aem1_sensors(struct aem_data *data); | ||
249 | static void update_aem2_sensors(struct aem_data *data); | ||
250 | |||
251 | static struct aem_driver_data driver_data = { | ||
252 | .aem_devices = LIST_HEAD_INIT(driver_data.aem_devices), | ||
253 | .bmc_events = { | ||
254 | .owner = THIS_MODULE, | ||
255 | .new_smi = aem_register_bmc, | ||
256 | .smi_gone = aem_bmc_gone, | ||
257 | }, | ||
258 | .ipmi_hndlrs = { | ||
259 | .ipmi_recv_hndl = aem_msg_handler, | ||
260 | }, | ||
261 | }; | ||
262 | |||
263 | /* Functions to talk to the IPMI layer */ | ||
264 | |||
265 | /* Initialize IPMI address, message buffers and user data */ | ||
266 | static int aem_init_ipmi_data(struct aem_ipmi_data *data, int iface, | ||
267 | struct device *bmc) | ||
268 | { | ||
269 | int err; | ||
270 | |||
271 | init_completion(&data->read_complete); | ||
272 | data->bmc_device = bmc; | ||
273 | |||
274 | /* Initialize IPMI address */ | ||
275 | data->address.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE; | ||
276 | data->address.channel = IPMI_BMC_CHANNEL; | ||
277 | data->address.data[0] = 0; | ||
278 | data->interface = iface; | ||
279 | |||
280 | /* Initialize message buffers */ | ||
281 | data->tx_msgid = 0; | ||
282 | data->tx_message.netfn = AEM_NETFN; | ||
283 | |||
284 | /* Create IPMI messaging interface user */ | ||
285 | err = ipmi_create_user(data->interface, &driver_data.ipmi_hndlrs, | ||
286 | data, &data->user); | ||
287 | if (err < 0) { | ||
288 | dev_err(bmc, "Unable to register user with IPMI " | ||
289 | "interface %d\n", data->interface); | ||
290 | return -EACCES; | ||
291 | } | ||
292 | |||
293 | return 0; | ||
294 | } | ||
295 | |||
296 | /* Send an IPMI command */ | ||
297 | static int aem_send_message(struct aem_ipmi_data *data) | ||
298 | { | ||
299 | int err; | ||
300 | |||
301 | err = ipmi_validate_addr(&data->address, sizeof(data->address)); | ||
302 | if (err) | ||
303 | goto out; | ||
304 | |||
305 | data->tx_msgid++; | ||
306 | err = ipmi_request_settime(data->user, &data->address, data->tx_msgid, | ||
307 | &data->tx_message, data, 0, 0, 0); | ||
308 | if (err) | ||
309 | goto out1; | ||
310 | |||
311 | return 0; | ||
312 | out1: | ||
313 | dev_err(data->bmc_device, "request_settime=%x\n", err); | ||
314 | return err; | ||
315 | out: | ||
316 | dev_err(data->bmc_device, "validate_addr=%x\n", err); | ||
317 | return err; | ||
318 | } | ||
319 | |||
320 | /* Dispatch IPMI messages to callers */ | ||
321 | static void aem_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data) | ||
322 | { | ||
323 | unsigned short rx_len; | ||
324 | struct aem_ipmi_data *data = user_msg_data; | ||
325 | |||
326 | if (msg->msgid != data->tx_msgid) { | ||
327 | dev_err(data->bmc_device, "Mismatch between received msgid " | ||
328 | "(%02x) and transmitted msgid (%02x)!\n", | ||
329 | (int)msg->msgid, | ||
330 | (int)data->tx_msgid); | ||
331 | ipmi_free_recv_msg(msg); | ||
332 | return; | ||
333 | } | ||
334 | |||
335 | data->rx_recv_type = msg->recv_type; | ||
336 | if (msg->msg.data_len > 0) | ||
337 | data->rx_result = msg->msg.data[0]; | ||
338 | else | ||
339 | data->rx_result = IPMI_UNKNOWN_ERR_COMPLETION_CODE; | ||
340 | |||
341 | if (msg->msg.data_len > 1) { | ||
342 | rx_len = msg->msg.data_len - 1; | ||
343 | if (data->rx_msg_len < rx_len) | ||
344 | rx_len = data->rx_msg_len; | ||
345 | data->rx_msg_len = rx_len; | ||
346 | memcpy(data->rx_msg_data, msg->msg.data + 1, data->rx_msg_len); | ||
347 | } else | ||
348 | data->rx_msg_len = 0; | ||
349 | |||
350 | ipmi_free_recv_msg(msg); | ||
351 | complete(&data->read_complete); | ||
352 | } | ||
353 | |||
354 | /* ID functions */ | ||
355 | |||
356 | /* Obtain an id */ | ||
357 | static int aem_idr_get(int *id) | ||
358 | { | ||
359 | int i, err; | ||
360 | |||
361 | again: | ||
362 | if (unlikely(!idr_pre_get(&aem_idr, GFP_KERNEL))) | ||
363 | return -ENOMEM; | ||
364 | |||
365 | spin_lock(&aem_idr_lock); | ||
366 | err = idr_get_new(&aem_idr, NULL, &i); | ||
367 | spin_unlock(&aem_idr_lock); | ||
368 | |||
369 | if (unlikely(err == -EAGAIN)) | ||
370 | goto again; | ||
371 | else if (unlikely(err)) | ||
372 | return err; | ||
373 | |||
374 | *id = i & MAX_ID_MASK; | ||
375 | return 0; | ||
376 | } | ||
377 | |||
378 | /* Release an object ID */ | ||
379 | static void aem_idr_put(int id) | ||
380 | { | ||
381 | spin_lock(&aem_idr_lock); | ||
382 | idr_remove(&aem_idr, id); | ||
383 | spin_unlock(&aem_idr_lock); | ||
384 | } | ||
385 | |||
386 | /* Sensor support functions */ | ||
387 | |||
388 | /* Read a sensor value */ | ||
389 | static int aem_read_sensor(struct aem_data *data, u8 elt, u8 reg, | ||
390 | void *buf, size_t size) | ||
391 | { | ||
392 | int rs_size, res; | ||
393 | struct aem_read_sensor_req rs_req; | ||
394 | struct aem_read_sensor_resp *rs_resp; | ||
395 | struct aem_ipmi_data *ipmi = &data->ipmi; | ||
396 | |||
397 | /* AEM registers are 1, 2, 4 or 8 bytes */ | ||
398 | switch (size) { | ||
399 | case 1: | ||
400 | case 2: | ||
401 | case 4: | ||
402 | case 8: | ||
403 | break; | ||
404 | default: | ||
405 | return -EINVAL; | ||
406 | } | ||
407 | |||
408 | rs_req.id = system_x_id; | ||
409 | rs_req.module_handle = data->module_handle; | ||
410 | rs_req.element = elt; | ||
411 | rs_req.subcommand = AEM_READ_REGISTER; | ||
412 | rs_req.reg = reg; | ||
413 | rs_req.rx_buf_size = size; | ||
414 | |||
415 | ipmi->tx_message.cmd = AEM_ELEMENT_CMD; | ||
416 | ipmi->tx_message.data = (char *)&rs_req; | ||
417 | ipmi->tx_message.data_len = sizeof(rs_req); | ||
418 | |||
419 | rs_size = sizeof(*rs_resp) + size; | ||
420 | rs_resp = kzalloc(rs_size, GFP_KERNEL); | ||
421 | if (!rs_resp) | ||
422 | return -ENOMEM; | ||
423 | |||
424 | ipmi->rx_msg_data = rs_resp; | ||
425 | ipmi->rx_msg_len = rs_size; | ||
426 | |||
427 | aem_send_message(ipmi); | ||
428 | |||
429 | res = wait_for_completion_timeout(&ipmi->read_complete, IPMI_TIMEOUT); | ||
430 | if (!res) | ||
431 | return -ETIMEDOUT; | ||
432 | |||
433 | if (ipmi->rx_result || ipmi->rx_msg_len != rs_size || | ||
434 | memcmp(&rs_resp->id, &system_x_id, sizeof(system_x_id))) { | ||
435 | kfree(rs_resp); | ||
436 | return -ENOENT; | ||
437 | } | ||
438 | |||
439 | switch (size) { | ||
440 | case 1: { | ||
441 | u8 *x = buf; | ||
442 | *x = rs_resp->bytes[0]; | ||
443 | break; | ||
444 | } | ||
445 | case 2: { | ||
446 | u16 *x = buf; | ||
447 | *x = be16_to_cpup((__be16 *)rs_resp->bytes); | ||
448 | break; | ||
449 | } | ||
450 | case 4: { | ||
451 | u32 *x = buf; | ||
452 | *x = be32_to_cpup((__be32 *)rs_resp->bytes); | ||
453 | break; | ||
454 | } | ||
455 | case 8: { | ||
456 | u64 *x = buf; | ||
457 | *x = be64_to_cpup((__be64 *)rs_resp->bytes); | ||
458 | break; | ||
459 | } | ||
460 | } | ||
461 | |||
462 | return 0; | ||
463 | } | ||
464 | |||
465 | /* Update AEM energy registers */ | ||
466 | static void update_aem_energy(struct aem_data *data) | ||
467 | { | ||
468 | aem_read_sensor(data, AEM_ENERGY_ELEMENT, 0, &data->energy[0], 8); | ||
469 | if (data->ver_major < 2) | ||
470 | return; | ||
471 | aem_read_sensor(data, AEM_ENERGY_ELEMENT, 1, &data->energy[1], 8); | ||
472 | } | ||
473 | |||
474 | /* Update all AEM1 sensors */ | ||
475 | static void update_aem1_sensors(struct aem_data *data) | ||
476 | { | ||
477 | mutex_lock(&data->lock); | ||
478 | if (time_before(jiffies, data->last_updated + REFRESH_INTERVAL) && | ||
479 | data->valid) | ||
480 | goto out; | ||
481 | |||
482 | update_aem_energy(data); | ||
483 | out: | ||
484 | mutex_unlock(&data->lock); | ||
485 | } | ||
486 | |||
487 | /* Update all AEM2 sensors */ | ||
488 | static void update_aem2_sensors(struct aem_data *data) | ||
489 | { | ||
490 | int i; | ||
491 | |||
492 | mutex_lock(&data->lock); | ||
493 | if (time_before(jiffies, data->last_updated + REFRESH_INTERVAL) && | ||
494 | data->valid) | ||
495 | goto out; | ||
496 | |||
497 | update_aem_energy(data); | ||
498 | aem_read_sensor(data, AEM_EXHAUST_ELEMENT, 0, &data->temp[0], 1); | ||
499 | aem_read_sensor(data, AEM_EXHAUST_ELEMENT, 1, &data->temp[1], 1); | ||
500 | |||
501 | for (i = POWER_CAP; i <= POWER_AUX; i++) | ||
502 | aem_read_sensor(data, AEM_POWER_CAP_ELEMENT, i, | ||
503 | &data->pcap[i], 2); | ||
504 | out: | ||
505 | mutex_unlock(&data->lock); | ||
506 | } | ||
507 | |||
508 | /* Delete an AEM instance */ | ||
509 | static void aem_delete(struct aem_data *data) | ||
510 | { | ||
511 | list_del(&data->list); | ||
512 | aem_remove_sensors(data); | ||
513 | hwmon_device_unregister(data->hwmon_dev); | ||
514 | ipmi_destroy_user(data->ipmi.user); | ||
515 | dev_set_drvdata(&data->pdev->dev, NULL); | ||
516 | platform_device_unregister(data->pdev); | ||
517 | aem_idr_put(data->id); | ||
518 | kfree(data); | ||
519 | } | ||
520 | |||
521 | /* Probe functions for AEM1 devices */ | ||
522 | |||
523 | /* Retrieve version and module handle for an AEM1 instance */ | ||
524 | static int aem_find_aem1_count(struct aem_ipmi_data *data) | ||
525 | { | ||
526 | int res; | ||
527 | struct aem_find_firmware_req ff_req; | ||
528 | struct aem_find_firmware_resp ff_resp; | ||
529 | |||
530 | ff_req.id = system_x_id; | ||
531 | ff_req.index = 0; | ||
532 | ff_req.module_type_id = cpu_to_be16(AEM_MODULE_TYPE_ID); | ||
533 | |||
534 | data->tx_message.cmd = AEM_FIND_FW_CMD; | ||
535 | data->tx_message.data = (char *)&ff_req; | ||
536 | data->tx_message.data_len = sizeof(ff_req); | ||
537 | |||
538 | data->rx_msg_data = &ff_resp; | ||
539 | data->rx_msg_len = sizeof(ff_resp); | ||
540 | |||
541 | aem_send_message(data); | ||
542 | |||
543 | res = wait_for_completion_timeout(&data->read_complete, IPMI_TIMEOUT); | ||
544 | if (!res) | ||
545 | return -ETIMEDOUT; | ||
546 | |||
547 | if (data->rx_result || data->rx_msg_len != sizeof(ff_resp) || | ||
548 | memcmp(&ff_resp.id, &system_x_id, sizeof(system_x_id))) | ||
549 | return -ENOENT; | ||
550 | |||
551 | return ff_resp.num_instances; | ||
552 | } | ||
553 | |||
554 | /* Find and initialize one AEM1 instance */ | ||
555 | static int aem_init_aem1_inst(struct aem_ipmi_data *probe, u8 module_handle) | ||
556 | { | ||
557 | struct aem_data *data; | ||
558 | int i; | ||
559 | int res = -ENOMEM; | ||
560 | |||
561 | data = kzalloc(sizeof(*data), GFP_KERNEL); | ||
562 | if (!data) | ||
563 | return res; | ||
564 | mutex_init(&data->lock); | ||
565 | |||
566 | /* Copy instance data */ | ||
567 | data->ver_major = 1; | ||
568 | data->ver_minor = 0; | ||
569 | data->module_handle = module_handle; | ||
570 | for (i = 0; i < AEM1_NUM_ENERGY_REGS; i++) | ||
571 | data->power_period[i] = AEM_DEFAULT_POWER_INTERVAL; | ||
572 | |||
573 | /* Create sub-device for this fw instance */ | ||
574 | if (aem_idr_get(&data->id)) | ||
575 | goto id_err; | ||
576 | |||
577 | data->pdev = platform_device_alloc(DRVNAME, data->id); | ||
578 | if (!data->pdev) | ||
579 | goto dev_err; | ||
580 | data->pdev->dev.driver = &aem_driver; | ||
581 | |||
582 | res = platform_device_add(data->pdev); | ||
583 | if (res) | ||
584 | goto ipmi_err; | ||
585 | |||
586 | dev_set_drvdata(&data->pdev->dev, data); | ||
587 | |||
588 | /* Set up IPMI interface */ | ||
589 | if (aem_init_ipmi_data(&data->ipmi, probe->interface, | ||
590 | probe->bmc_device)) | ||
591 | goto ipmi_err; | ||
592 | |||
593 | /* Register with hwmon */ | ||
594 | data->hwmon_dev = hwmon_device_register(&data->pdev->dev); | ||
595 | |||
596 | if (IS_ERR(data->hwmon_dev)) { | ||
597 | dev_err(&data->pdev->dev, "Unable to register hwmon " | ||
598 | "device for IPMI interface %d\n", | ||
599 | probe->interface); | ||
600 | goto hwmon_reg_err; | ||
601 | } | ||
602 | |||
603 | data->update = update_aem1_sensors; | ||
604 | |||
605 | /* Find sensors */ | ||
606 | if (aem1_find_sensors(data)) | ||
607 | goto sensor_err; | ||
608 | |||
609 | /* Add to our list of AEM devices */ | ||
610 | list_add_tail(&data->list, &driver_data.aem_devices); | ||
611 | |||
612 | dev_info(data->ipmi.bmc_device, "Found AEM v%d.%d at 0x%X\n", | ||
613 | data->ver_major, data->ver_minor, | ||
614 | data->module_handle); | ||
615 | return 0; | ||
616 | |||
617 | sensor_err: | ||
618 | hwmon_device_unregister(data->hwmon_dev); | ||
619 | hwmon_reg_err: | ||
620 | ipmi_destroy_user(data->ipmi.user); | ||
621 | ipmi_err: | ||
622 | dev_set_drvdata(&data->pdev->dev, NULL); | ||
623 | platform_device_unregister(data->pdev); | ||
624 | dev_err: | ||
625 | aem_idr_put(data->id); | ||
626 | id_err: | ||
627 | kfree(data); | ||
628 | |||
629 | return res; | ||
630 | } | ||
631 | |||
632 | /* Find and initialize all AEM1 instances */ | ||
633 | static int aem_init_aem1(struct aem_ipmi_data *probe) | ||
634 | { | ||
635 | int num, i, err; | ||
636 | |||
637 | num = aem_find_aem1_count(probe); | ||
638 | for (i = 0; i < num; i++) { | ||
639 | err = aem_init_aem1_inst(probe, i); | ||
640 | if (err) { | ||
641 | dev_err(probe->bmc_device, | ||
642 | "Error %d initializing AEM1 0x%X\n", | ||
643 | err, i); | ||
644 | return err; | ||
645 | } | ||
646 | } | ||
647 | |||
648 | return 0; | ||
649 | } | ||
650 | |||
651 | /* Probe functions for AEM2 devices */ | ||
652 | |||
653 | /* Retrieve version and module handle for an AEM2 instance */ | ||
654 | static int aem_find_aem2(struct aem_ipmi_data *data, | ||
655 | struct aem_find_instance_resp *fi_resp, | ||
656 | int instance_num) | ||
657 | { | ||
658 | int res; | ||
659 | struct aem_find_instance_req fi_req; | ||
660 | |||
661 | fi_req.id = system_x_id; | ||
662 | fi_req.instance_number = instance_num; | ||
663 | fi_req.module_type_id = cpu_to_be16(AEM_MODULE_TYPE_ID); | ||
664 | |||
665 | data->tx_message.cmd = AEM_FW_INSTANCE_CMD; | ||
666 | data->tx_message.data = (char *)&fi_req; | ||
667 | data->tx_message.data_len = sizeof(fi_req); | ||
668 | |||
669 | data->rx_msg_data = fi_resp; | ||
670 | data->rx_msg_len = sizeof(*fi_resp); | ||
671 | |||
672 | aem_send_message(data); | ||
673 | |||
674 | res = wait_for_completion_timeout(&data->read_complete, IPMI_TIMEOUT); | ||
675 | if (!res) | ||
676 | return -ETIMEDOUT; | ||
677 | |||
678 | if (data->rx_result || data->rx_msg_len != sizeof(*fi_resp) || | ||
679 | memcmp(&fi_resp->id, &system_x_id, sizeof(system_x_id))) | ||
680 | return -ENOENT; | ||
681 | |||
682 | return 0; | ||
683 | } | ||
684 | |||
685 | /* Find and initialize one AEM2 instance */ | ||
686 | static int aem_init_aem2_inst(struct aem_ipmi_data *probe, | ||
687 | struct aem_find_instance_resp *fi_resp) | ||
688 | { | ||
689 | struct aem_data *data; | ||
690 | int i; | ||
691 | int res = -ENOMEM; | ||
692 | |||
693 | data = kzalloc(sizeof(*data), GFP_KERNEL); | ||
694 | if (!data) | ||
695 | return res; | ||
696 | mutex_init(&data->lock); | ||
697 | |||
698 | /* Copy instance data */ | ||
699 | data->ver_major = fi_resp->major; | ||
700 | data->ver_minor = fi_resp->minor; | ||
701 | data->module_handle = fi_resp->module_handle; | ||
702 | for (i = 0; i < AEM2_NUM_ENERGY_REGS; i++) | ||
703 | data->power_period[i] = AEM_DEFAULT_POWER_INTERVAL; | ||
704 | |||
705 | /* Create sub-device for this fw instance */ | ||
706 | if (aem_idr_get(&data->id)) | ||
707 | goto id_err; | ||
708 | |||
709 | data->pdev = platform_device_alloc(DRVNAME, data->id); | ||
710 | if (!data->pdev) | ||
711 | goto dev_err; | ||
712 | data->pdev->dev.driver = &aem_driver; | ||
713 | |||
714 | res = platform_device_add(data->pdev); | ||
715 | if (res) | ||
716 | goto ipmi_err; | ||
717 | |||
718 | dev_set_drvdata(&data->pdev->dev, data); | ||
719 | |||
720 | /* Set up IPMI interface */ | ||
721 | if (aem_init_ipmi_data(&data->ipmi, probe->interface, | ||
722 | probe->bmc_device)) | ||
723 | goto ipmi_err; | ||
724 | |||
725 | /* Register with hwmon */ | ||
726 | data->hwmon_dev = hwmon_device_register(&data->pdev->dev); | ||
727 | |||
728 | if (IS_ERR(data->hwmon_dev)) { | ||
729 | dev_err(&data->pdev->dev, "Unable to register hwmon " | ||
730 | "device for IPMI interface %d\n", | ||
731 | probe->interface); | ||
732 | goto hwmon_reg_err; | ||
733 | } | ||
734 | |||
735 | data->update = update_aem2_sensors; | ||
736 | |||
737 | /* Find sensors */ | ||
738 | if (aem2_find_sensors(data)) | ||
739 | goto sensor_err; | ||
740 | |||
741 | /* Add to our list of AEM devices */ | ||
742 | list_add_tail(&data->list, &driver_data.aem_devices); | ||
743 | |||
744 | dev_info(data->ipmi.bmc_device, "Found AEM v%d.%d at 0x%X\n", | ||
745 | data->ver_major, data->ver_minor, | ||
746 | data->module_handle); | ||
747 | return 0; | ||
748 | |||
749 | sensor_err: | ||
750 | hwmon_device_unregister(data->hwmon_dev); | ||
751 | hwmon_reg_err: | ||
752 | ipmi_destroy_user(data->ipmi.user); | ||
753 | ipmi_err: | ||
754 | dev_set_drvdata(&data->pdev->dev, NULL); | ||
755 | platform_device_unregister(data->pdev); | ||
756 | dev_err: | ||
757 | aem_idr_put(data->id); | ||
758 | id_err: | ||
759 | kfree(data); | ||
760 | |||
761 | return res; | ||
762 | } | ||
763 | |||
764 | /* Find and initialize all AEM2 instances */ | ||
765 | static int aem_init_aem2(struct aem_ipmi_data *probe) | ||
766 | { | ||
767 | struct aem_find_instance_resp fi_resp; | ||
768 | int err; | ||
769 | int i = 0; | ||
770 | |||
771 | while (!aem_find_aem2(probe, &fi_resp, i)) { | ||
772 | if (fi_resp.major != 2) { | ||
773 | dev_err(probe->bmc_device, "Unknown AEM v%d; please " | ||
774 | "report this to the maintainer.\n", | ||
775 | fi_resp.major); | ||
776 | i++; | ||
777 | continue; | ||
778 | } | ||
779 | err = aem_init_aem2_inst(probe, &fi_resp); | ||
780 | if (err) { | ||
781 | dev_err(probe->bmc_device, | ||
782 | "Error %d initializing AEM2 0x%X\n", | ||
783 | err, fi_resp.module_handle); | ||
784 | return err; | ||
785 | } | ||
786 | i++; | ||
787 | } | ||
788 | |||
789 | return 0; | ||
790 | } | ||
791 | |||
792 | /* Probe a BMC for AEM firmware instances */ | ||
793 | static void aem_register_bmc(int iface, struct device *dev) | ||
794 | { | ||
795 | struct aem_ipmi_data probe; | ||
796 | |||
797 | if (aem_init_ipmi_data(&probe, iface, dev)) | ||
798 | return; | ||
799 | |||
800 | /* Ignore probe errors; they won't cause problems */ | ||
801 | aem_init_aem1(&probe); | ||
802 | aem_init_aem2(&probe); | ||
803 | |||
804 | ipmi_destroy_user(probe.user); | ||
805 | } | ||
806 | |||
807 | /* Handle BMC deletion */ | ||
808 | static void aem_bmc_gone(int iface) | ||
809 | { | ||
810 | struct aem_data *p1, *next1; | ||
811 | |||
812 | list_for_each_entry_safe(p1, next1, &driver_data.aem_devices, list) | ||
813 | if (p1->ipmi.interface == iface) | ||
814 | aem_delete(p1); | ||
815 | } | ||
816 | |||
817 | /* sysfs support functions */ | ||
818 | |||
819 | /* AEM device name */ | ||
820 | static ssize_t show_name(struct device *dev, struct device_attribute *devattr, | ||
821 | char *buf) | ||
822 | { | ||
823 | struct aem_data *data = dev_get_drvdata(dev); | ||
824 | |||
825 | return sprintf(buf, "%s%d\n", DRVNAME, data->ver_major); | ||
826 | } | ||
827 | static SENSOR_DEVICE_ATTR(name, S_IRUGO, show_name, NULL, 0); | ||
828 | |||
829 | /* AEM device version */ | ||
830 | static ssize_t show_version(struct device *dev, | ||
831 | struct device_attribute *devattr, | ||
832 | char *buf) | ||
833 | { | ||
834 | struct aem_data *data = dev_get_drvdata(dev); | ||
835 | |||
836 | return sprintf(buf, "%d.%d\n", data->ver_major, data->ver_minor); | ||
837 | } | ||
838 | static SENSOR_DEVICE_ATTR(version, S_IRUGO, show_version, NULL, 0); | ||
839 | |||
840 | /* Display power use */ | ||
841 | static ssize_t aem_show_power(struct device *dev, | ||
842 | struct device_attribute *devattr, | ||
843 | char *buf) | ||
844 | { | ||
845 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
846 | struct aem_data *data = dev_get_drvdata(dev); | ||
847 | u64 before, after, delta, time; | ||
848 | signed long leftover; | ||
849 | struct timespec b, a; | ||
850 | |||
851 | mutex_lock(&data->lock); | ||
852 | update_aem_energy(data); | ||
853 | getnstimeofday(&b); | ||
854 | before = data->energy[attr->index]; | ||
855 | |||
856 | leftover = schedule_timeout_interruptible( | ||
857 | msecs_to_jiffies(data->power_period[attr->index]) | ||
858 | ); | ||
859 | if (leftover) { | ||
860 | mutex_unlock(&data->lock); | ||
861 | return 0; | ||
862 | } | ||
863 | |||
864 | update_aem_energy(data); | ||
865 | getnstimeofday(&a); | ||
866 | after = data->energy[attr->index]; | ||
867 | mutex_unlock(&data->lock); | ||
868 | |||
869 | time = timespec_to_ns(&a) - timespec_to_ns(&b); | ||
870 | delta = (after - before) * UJ_PER_MJ; | ||
871 | |||
872 | return sprintf(buf, "%llu\n", | ||
873 | (unsigned long long)div64_u64(delta * NSEC_PER_SEC, time)); | ||
874 | } | ||
875 | |||
876 | /* Display energy use */ | ||
877 | static ssize_t aem_show_energy(struct device *dev, | ||
878 | struct device_attribute *devattr, | ||
879 | char *buf) | ||
880 | { | ||
881 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
882 | struct aem_data *a = dev_get_drvdata(dev); | ||
883 | a->update(a); | ||
884 | |||
885 | return sprintf(buf, "%llu\n", | ||
886 | (unsigned long long)a->energy[attr->index] * 1000); | ||
887 | } | ||
888 | |||
889 | /* Display power interval registers */ | ||
890 | static ssize_t aem_show_power_period(struct device *dev, | ||
891 | struct device_attribute *devattr, | ||
892 | char *buf) | ||
893 | { | ||
894 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
895 | struct aem_data *a = dev_get_drvdata(dev); | ||
896 | a->update(a); | ||
897 | |||
898 | return sprintf(buf, "%lu\n", a->power_period[attr->index]); | ||
899 | } | ||
900 | |||
901 | /* Set power interval registers */ | ||
902 | static ssize_t aem_set_power_period(struct device *dev, | ||
903 | struct device_attribute *devattr, | ||
904 | const char *buf, size_t count) | ||
905 | { | ||
906 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
907 | struct aem_data *a = dev_get_drvdata(dev); | ||
908 | unsigned long temp; | ||
909 | int res; | ||
910 | |||
911 | res = strict_strtoul(buf, 10, &temp); | ||
912 | if (res) | ||
913 | return res; | ||
914 | |||
915 | if (temp < AEM_MIN_POWER_INTERVAL) | ||
916 | return -EINVAL; | ||
917 | |||
918 | mutex_lock(&a->lock); | ||
919 | a->power_period[attr->index] = temp; | ||
920 | mutex_unlock(&a->lock); | ||
921 | |||
922 | return count; | ||
923 | } | ||
924 | |||
925 | /* Discover sensors on an AEM device */ | ||
926 | static int aem_register_sensors(struct aem_data *data, | ||
927 | struct aem_ro_sensor_template *ro, | ||
928 | struct aem_rw_sensor_template *rw) | ||
929 | { | ||
930 | struct device *dev = &data->pdev->dev; | ||
931 | struct sensor_device_attribute *sensors = data->sensors; | ||
932 | int err; | ||
933 | |||
934 | /* Set up read-only sensors */ | ||
935 | while (ro->label) { | ||
936 | sensors->dev_attr.attr.name = ro->label; | ||
937 | sensors->dev_attr.attr.mode = S_IRUGO; | ||
938 | sensors->dev_attr.show = ro->show; | ||
939 | sensors->index = ro->index; | ||
940 | |||
941 | err = device_create_file(dev, &sensors->dev_attr); | ||
942 | if (err) { | ||
943 | sensors->dev_attr.attr.name = NULL; | ||
944 | goto error; | ||
945 | } | ||
946 | sensors++; | ||
947 | ro++; | ||
948 | } | ||
949 | |||
950 | /* Set up read-write sensors */ | ||
951 | while (rw->label) { | ||
952 | sensors->dev_attr.attr.name = rw->label; | ||
953 | sensors->dev_attr.attr.mode = S_IRUGO | S_IWUSR; | ||
954 | sensors->dev_attr.show = rw->show; | ||
955 | sensors->dev_attr.store = rw->set; | ||
956 | sensors->index = rw->index; | ||
957 | |||
958 | err = device_create_file(dev, &sensors->dev_attr); | ||
959 | if (err) { | ||
960 | sensors->dev_attr.attr.name = NULL; | ||
961 | goto error; | ||
962 | } | ||
963 | sensors++; | ||
964 | rw++; | ||
965 | } | ||
966 | |||
967 | err = device_create_file(dev, &sensor_dev_attr_name.dev_attr); | ||
968 | if (err) | ||
969 | goto error; | ||
970 | err = device_create_file(dev, &sensor_dev_attr_version.dev_attr); | ||
971 | return err; | ||
972 | |||
973 | error: | ||
974 | aem_remove_sensors(data); | ||
975 | return err; | ||
976 | } | ||
977 | |||
978 | /* sysfs support functions for AEM2 sensors */ | ||
979 | |||
980 | /* Display temperature use */ | ||
981 | static ssize_t aem2_show_temp(struct device *dev, | ||
982 | struct device_attribute *devattr, | ||
983 | char *buf) | ||
984 | { | ||
985 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
986 | struct aem_data *a = dev_get_drvdata(dev); | ||
987 | a->update(a); | ||
988 | |||
989 | return sprintf(buf, "%u\n", a->temp[attr->index] * 1000); | ||
990 | } | ||
991 | |||
992 | /* Display power-capping registers */ | ||
993 | static ssize_t aem2_show_pcap_value(struct device *dev, | ||
994 | struct device_attribute *devattr, | ||
995 | char *buf) | ||
996 | { | ||
997 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
998 | struct aem_data *a = dev_get_drvdata(dev); | ||
999 | a->update(a); | ||
1000 | |||
1001 | return sprintf(buf, "%u\n", a->pcap[attr->index] * 100000); | ||
1002 | } | ||
1003 | |||
1004 | /* Remove sensors attached to an AEM device */ | ||
1005 | static void aem_remove_sensors(struct aem_data *data) | ||
1006 | { | ||
1007 | int i; | ||
1008 | |||
1009 | for (i = 0; i < AEM_NUM_SENSORS; i++) { | ||
1010 | if (!data->sensors[i].dev_attr.attr.name) | ||
1011 | continue; | ||
1012 | device_remove_file(&data->pdev->dev, | ||
1013 | &data->sensors[i].dev_attr); | ||
1014 | } | ||
1015 | |||
1016 | device_remove_file(&data->pdev->dev, | ||
1017 | &sensor_dev_attr_name.dev_attr); | ||
1018 | device_remove_file(&data->pdev->dev, | ||
1019 | &sensor_dev_attr_version.dev_attr); | ||
1020 | } | ||
1021 | |||
1022 | /* Sensor probe functions */ | ||
1023 | |||
1024 | /* Description of AEM1 sensors */ | ||
1025 | static struct aem_ro_sensor_template aem1_ro_sensors[] = { | ||
1026 | {"energy1_input", aem_show_energy, 0}, | ||
1027 | {"power1_average", aem_show_power, 0}, | ||
1028 | {NULL, NULL, 0}, | ||
1029 | }; | ||
1030 | |||
1031 | static struct aem_rw_sensor_template aem1_rw_sensors[] = { | ||
1032 | {"power1_average_interval", aem_show_power_period, aem_set_power_period, 0}, | ||
1033 | {NULL, NULL, NULL, 0}, | ||
1034 | }; | ||
1035 | |||
1036 | /* Description of AEM2 sensors */ | ||
1037 | static struct aem_ro_sensor_template aem2_ro_sensors[] = { | ||
1038 | {"energy1_input", aem_show_energy, 0}, | ||
1039 | {"energy2_input", aem_show_energy, 1}, | ||
1040 | {"power1_average", aem_show_power, 0}, | ||
1041 | {"power2_average", aem_show_power, 1}, | ||
1042 | {"temp1_input", aem2_show_temp, 0}, | ||
1043 | {"temp2_input", aem2_show_temp, 1}, | ||
1044 | |||
1045 | {"power4_average", aem2_show_pcap_value, POWER_CAP_MAX_HOTPLUG}, | ||
1046 | {"power5_average", aem2_show_pcap_value, POWER_CAP_MAX}, | ||
1047 | {"power6_average", aem2_show_pcap_value, POWER_CAP_MIN_WARNING}, | ||
1048 | {"power7_average", aem2_show_pcap_value, POWER_CAP_MIN}, | ||
1049 | |||
1050 | {"power3_average", aem2_show_pcap_value, POWER_AUX}, | ||
1051 | {"power_cap", aem2_show_pcap_value, POWER_CAP}, | ||
1052 | {NULL, NULL, 0}, | ||
1053 | }; | ||
1054 | |||
1055 | static struct aem_rw_sensor_template aem2_rw_sensors[] = { | ||
1056 | {"power1_average_interval", aem_show_power_period, aem_set_power_period, 0}, | ||
1057 | {"power2_average_interval", aem_show_power_period, aem_set_power_period, 1}, | ||
1058 | {NULL, NULL, NULL, 0}, | ||
1059 | }; | ||
1060 | |||
1061 | /* Set up AEM1 sensor attrs */ | ||
1062 | static int aem1_find_sensors(struct aem_data *data) | ||
1063 | { | ||
1064 | return aem_register_sensors(data, aem1_ro_sensors, aem1_rw_sensors); | ||
1065 | } | ||
1066 | |||
1067 | /* Set up AEM2 sensor attrs */ | ||
1068 | static int aem2_find_sensors(struct aem_data *data) | ||
1069 | { | ||
1070 | return aem_register_sensors(data, aem2_ro_sensors, aem2_rw_sensors); | ||
1071 | } | ||
1072 | |||
1073 | /* Module init/exit routines */ | ||
1074 | |||
1075 | static int __init aem_init(void) | ||
1076 | { | ||
1077 | int res; | ||
1078 | |||
1079 | res = driver_register(&aem_driver); | ||
1080 | if (res) { | ||
1081 | printk(KERN_ERR "Can't register aem driver\n"); | ||
1082 | return res; | ||
1083 | } | ||
1084 | |||
1085 | res = ipmi_smi_watcher_register(&driver_data.bmc_events); | ||
1086 | if (res) | ||
1087 | goto ipmi_reg_err; | ||
1088 | return 0; | ||
1089 | |||
1090 | ipmi_reg_err: | ||
1091 | driver_unregister(&aem_driver); | ||
1092 | return res; | ||
1093 | |||
1094 | } | ||
1095 | |||
1096 | static void __exit aem_exit(void) | ||
1097 | { | ||
1098 | struct aem_data *p1, *next1; | ||
1099 | |||
1100 | ipmi_smi_watcher_unregister(&driver_data.bmc_events); | ||
1101 | driver_unregister(&aem_driver); | ||
1102 | list_for_each_entry_safe(p1, next1, &driver_data.aem_devices, list) | ||
1103 | aem_delete(p1); | ||
1104 | } | ||
1105 | |||
1106 | MODULE_AUTHOR("Darrick J. Wong <djwong@us.ibm.com>"); | ||
1107 | MODULE_DESCRIPTION("IBM Active Energy Manager power/temp sensor driver"); | ||
1108 | MODULE_LICENSE("GPL"); | ||
1109 | |||
1110 | module_init(aem_init); | ||
1111 | module_exit(aem_exit); | ||
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c index fa7696905154..de698dc73020 100644 --- a/drivers/hwmon/lm75.c +++ b/drivers/hwmon/lm75.c | |||
@@ -251,10 +251,13 @@ static int lm75_detach_client(struct i2c_client *client) | |||
251 | the SMBus standard. */ | 251 | the SMBus standard. */ |
252 | static int lm75_read_value(struct i2c_client *client, u8 reg) | 252 | static int lm75_read_value(struct i2c_client *client, u8 reg) |
253 | { | 253 | { |
254 | int value; | ||
255 | |||
254 | if (reg == LM75_REG_CONF) | 256 | if (reg == LM75_REG_CONF) |
255 | return i2c_smbus_read_byte_data(client, reg); | 257 | return i2c_smbus_read_byte_data(client, reg); |
256 | else | 258 | |
257 | return swab16(i2c_smbus_read_word_data(client, reg)); | 259 | value = i2c_smbus_read_word_data(client, reg); |
260 | return (value < 0) ? value : swab16(value); | ||
258 | } | 261 | } |
259 | 262 | ||
260 | static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value) | 263 | static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value) |
@@ -287,9 +290,16 @@ static struct lm75_data *lm75_update_device(struct device *dev) | |||
287 | int i; | 290 | int i; |
288 | dev_dbg(&client->dev, "Starting lm75 update\n"); | 291 | dev_dbg(&client->dev, "Starting lm75 update\n"); |
289 | 292 | ||
290 | for (i = 0; i < ARRAY_SIZE(data->temp); i++) | 293 | for (i = 0; i < ARRAY_SIZE(data->temp); i++) { |
291 | data->temp[i] = lm75_read_value(client, | 294 | int status; |
292 | LM75_REG_TEMP[i]); | 295 | |
296 | status = lm75_read_value(client, LM75_REG_TEMP[i]); | ||
297 | if (status < 0) | ||
298 | dev_dbg(&client->dev, "reg %d, err %d\n", | ||
299 | LM75_REG_TEMP[i], status); | ||
300 | else | ||
301 | data->temp[i] = status; | ||
302 | } | ||
293 | data->last_updated = jiffies; | 303 | data->last_updated = jiffies; |
294 | data->valid = 1; | 304 | data->valid = 1; |
295 | } | 305 | } |
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c index 182fe6a5605f..ee5eca1c1921 100644 --- a/drivers/hwmon/lm85.c +++ b/drivers/hwmon/lm85.c | |||
@@ -192,23 +192,20 @@ static int RANGE_TO_REG( int range ) | |||
192 | { | 192 | { |
193 | int i; | 193 | int i; |
194 | 194 | ||
195 | if ( range < lm85_range_map[0] ) { | 195 | if (range >= lm85_range_map[15]) |
196 | return 0 ; | ||
197 | } else if ( range > lm85_range_map[15] ) { | ||
198 | return 15 ; | 196 | return 15 ; |
199 | } else { /* find closest match */ | 197 | |
200 | for ( i = 14 ; i >= 0 ; --i ) { | 198 | /* Find the closest match */ |
201 | if ( range > lm85_range_map[i] ) { /* range bracketed */ | 199 | for (i = 14; i >= 0; --i) { |
202 | if ((lm85_range_map[i+1] - range) < | 200 | if (range >= lm85_range_map[i]) { |
203 | (range - lm85_range_map[i])) { | 201 | if ((lm85_range_map[i + 1] - range) < |
204 | i++; | 202 | (range - lm85_range_map[i])) |
205 | break; | 203 | return i + 1; |
206 | } | 204 | return i; |
207 | break; | ||
208 | } | ||
209 | } | 205 | } |
210 | } | 206 | } |
211 | return( i & 0x0f ); | 207 | |
208 | return 0; | ||
212 | } | 209 | } |
213 | #define RANGE_FROM_REG(val) (lm85_range_map[(val)&0x0f]) | 210 | #define RANGE_FROM_REG(val) (lm85_range_map[(val)&0x0f]) |
214 | 211 | ||