Lines Matching +full:power +full:- +full:monitor
1 // SPDX-License-Identifier: GPL-2.0-only
6 * VT - The implementation is to support Sun Microelectronics (SME) platform
8 * controller to access pcf8591 (8-bit A/D and D/A converter) and
9 * pcf8571 (256 x 8-bit static low-voltage RAM with I2C-bus interface).
11 * http://www-eu2.semiconductors.com/pip/PCF8584P
12 * http://www-eu2.semiconductors.com/pip/PCF8574AP
13 * http://www-eu2.semiconductors.com/pip/PCF8591P
15 * EB - Added support for CP1500 Global Address and PS/Voltage monitoring.
18 * DB - Audit every copy_to_user in envctrl_read.
77 /* Monitor type of i2c child device.
81 #define PCF8584_GLOBALADDR_TYPE 6 /* global address monitor */
82 #define PCF8584_FANSTAT_TYPE 3 /* fan status monitor */
83 #define PCF8584_VOLTAGE_TYPE 2 /* voltage monitor */
84 #define PCF8584_TEMP_TYPE 1 /* temperature monitor*/
86 /* Monitor type of i2c child device.
90 #define ENVCTRL_CPUTEMP_MON 1 /* cpu temperature monitor */
91 #define ENVCTRL_CPUVOLTAGE_MON 2 /* voltage monitor */
92 #define ENVCTRL_FANSTAT_MON 3 /* fan status monitor */
94 /* monitor */
95 #define ENVCTRL_VOLTAGESTAT_MON 5 /* voltage status monitor */
160 unsigned int total_chnls; /* Number of monitor channels. */
165 /* Properties of all monitor channels. */
166 unsigned int total_tbls; /* Number of monitor tables. */
190 while (--limit > 0) { in envtrl_i2c_test_pin()
207 while (--limit > 0) { in envctrl_i2c_test_bb()
348 bufdata[len - 1] = bufdata[len - 2]; in envctrl_i2c_data_translate()
349 bufdata[len - 2] = '.'; in envctrl_i2c_data_translate()
359 /* Function Description: Read cpu-related data such as cpu temperature, voltage.
366 int i, j = -1; in envctrl_read_cpu_info()
369 /* Find the right monitor type and channel. */ in envctrl_read_cpu_info()
371 if (pchild->mon_type[i] == mon_type) { in envctrl_read_cpu_info()
382 data = envctrl_i2c_read_8591((unsigned char)pchild->addr, in envctrl_read_cpu_info()
383 (unsigned char)pchild->chnl_array[i].chnl_no); in envctrl_read_cpu_info()
386 tbl = pchild->tables + pchild->tblprop_array[i].offset; in envctrl_read_cpu_info()
388 return envctrl_i2c_data_translate(data, pchild->tblprop_array[i].type, in envctrl_read_cpu_info()
389 pchild->tblprop_array[i].scale, in envctrl_read_cpu_info()
393 /* Function Description: Read noncpu-related data such as motherboard
405 if (pchild->mon_type[i] == mon_type) in envctrl_read_noncpu_info()
413 data = envctrl_i2c_read_8591((unsigned char)pchild->addr, in envctrl_read_noncpu_info()
414 (unsigned char)pchild->chnl_array[i].chnl_no); in envctrl_read_noncpu_info()
417 tbl = pchild->tables + pchild->tblprop_array[i].offset; in envctrl_read_noncpu_info()
419 return envctrl_i2c_data_translate(data, pchild->tblprop_array[i].type, in envctrl_read_noncpu_info()
420 pchild->tblprop_array[i].scale, in envctrl_read_noncpu_info()
434 tmp = data & pchild->fan_mask; in envctrl_i2c_fan_status()
436 if (tmp == pchild->fan_mask) { in envctrl_i2c_fan_status()
446 * monitor 4 fans at channels 0,1,2,4, the return mask in envctrl_i2c_fan_status()
450 if (pchild->fan_mask & chnls_mask[i]) { in envctrl_i2c_fan_status()
475 * ----------------------------------------------- in envctrl_i2c_globaladdr()
477 * ----------------------------------------------- in envctrl_i2c_globaladdr()
478 * GA0 - GA4 integer value of Global Address (backplane slot#) in envctrl_i2c_globaladdr()
479 * DEG 0 = cPCI Power supply output is starting to degrade in envctrl_i2c_globaladdr()
480 * 1 = cPCI Power supply output is OK in envctrl_i2c_globaladdr()
481 * FAL 0 = cPCI Power supply has failed in envctrl_i2c_globaladdr()
482 * 1 = cPCI Power supply output is OK in envctrl_i2c_globaladdr()
488 /* Function Description: Read standard voltage and power supply status.
498 tmp = data & pchild->voltage_mask; in envctrl_i2c_voltage_status()
500 /* Two channels are used to monitor voltage and power supply. */ in envctrl_i2c_voltage_status()
501 if (tmp == pchild->voltage_mask) { in envctrl_i2c_voltage_status()
502 /* All bits are on. Voltage and power supply are okay. */ in envctrl_i2c_voltage_status()
505 /* All bits are off. Voltage and power supply are bad */ in envctrl_i2c_voltage_status()
508 /* Either voltage or power supply has problem. */ in envctrl_i2c_voltage_status()
510 if (pchild->voltage_mask & chnls_mask[i]) { in envctrl_i2c_voltage_status()
521 * power supply. in envctrl_i2c_voltage_status()
548 switch ((int)(long)file->private_data) { in envctrl_read()
556 ret = -EFAULT; in envctrl_read()
566 ret = -EFAULT; in envctrl_read()
574 ret = -EFAULT; in envctrl_read()
584 ret = -EFAULT; in envctrl_read()
594 ret = -EFAULT; in envctrl_read()
602 ret = -EFAULT; in envctrl_read()
610 ret = -EFAULT; in envctrl_read()
616 data[0] = envctrl_i2c_read_8574(pchild->addr); in envctrl_read()
619 ret = -EFAULT; in envctrl_read()
625 data[0] = envctrl_i2c_read_8574(pchild->addr); in envctrl_read()
628 ret = -EFAULT; in envctrl_read()
633 /* If voltage monitor not present, check for CPCI equivalent */ in envctrl_read()
636 data[0] = envctrl_i2c_read_8574(pchild->addr); in envctrl_read()
639 ret = -EFAULT; in envctrl_read()
651 * Return: Gives 0 for implemented commands, -EINVAL otherwise.
667 file->private_data = (void *)(long)cmd; in envctrl_ioctl()
683 file->private_data = (void *)(long)cmd; in envctrl_ioctl()
687 return -EINVAL; in envctrl_ioctl()
699 file->private_data = NULL; in envctrl_open()
728 /* Function Description: Set monitor type based on firmware description.
744 pchild->mon_type[chnl_no] = ENVCTRL_CPUTEMP_MON; in envctrl_set_mon()
750 pchild->mon_type[chnl_no] = ENVCTRL_CPUVOLTAGE_MON; in envctrl_set_mon()
753 pchild->mon_type[chnl_no] = ENVCTRL_MTHRBDTEMP_MON; in envctrl_set_mon()
756 pchild->mon_type[chnl_no] = ENVCTRL_SCSITEMP_MON; in envctrl_set_mon()
759 pchild->mon_type[chnl_no] = ENVCTRL_ETHERTEMP_MON; in envctrl_set_mon()
762 /* Function Description: Initialize monitor channel with channel desc,
763 * decoding tables, monitor type, optional properties.
773 pos = of_get_property(dp, "channels-description", &len); in envctrl_init_adc()
778 len -= l; in envctrl_init_adc()
783 pval = of_get_property(dp, "warning-temp", NULL); in envctrl_init_adc()
787 pval = of_get_property(dp, "shutdown-temp", NULL); in envctrl_init_adc()
800 for (i = 0; i < pchild->total_chnls; i++) in envctrl_init_fanstat()
801 pchild->fan_mask |= chnls_mask[(pchild->chnl_array[i]).chnl_no]; in envctrl_init_fanstat()
806 pchild->mon_type[0] = ENVCTRL_FANSTAT_MON; in envctrl_init_fanstat()
829 for (i = 0; i < pchild->total_chnls; i++) { in envctrl_init_globaladdr()
830 if (PCF8584_VOLTAGE_TYPE == pchild->chnl_array[i].type) { in envctrl_init_globaladdr()
831 pchild->voltage_mask |= chnls_mask[i]; in envctrl_init_globaladdr()
839 pchild->mon_type[0] = ENVCTRL_GLOBALADDR_MON; in envctrl_init_globaladdr()
848 for (i = 0; i < pchild->total_chnls; i++) in envctrl_init_voltage_status()
849 pchild->voltage_mask |= chnls_mask[(pchild->chnl_array[i]).chnl_no]; in envctrl_init_voltage_status()
854 pchild->mon_type[0] = ENVCTRL_VOLTAGESTAT_MON; in envctrl_init_voltage_status()
868 memcpy(&pchild->addr, pval, len); in envctrl_init_i2c_child()
873 memcpy(pchild->tblprop_array, pval, len); in envctrl_init_i2c_child()
874 pchild->total_tbls = len / sizeof(struct pcf8584_tblprop); in envctrl_init_i2c_child()
875 for (i = 0; i < pchild->total_tbls; i++) { in envctrl_init_i2c_child()
876 if ((pchild->tblprop_array[i].size + pchild->tblprop_array[i].offset) > tbls_size) { in envctrl_init_i2c_child()
877 tbls_size = pchild->tblprop_array[i].size + pchild->tblprop_array[i].offset; in envctrl_init_i2c_child()
881 pchild->tables = kmalloc(tbls_size, GFP_KERNEL); in envctrl_init_i2c_child()
882 if (pchild->tables == NULL){ in envctrl_init_i2c_child()
891 memcpy(pchild->tables, pval, len); in envctrl_init_i2c_child()
894 /* SPARCengine ASM Reference Manual (ref. SMI doc 805-7581-04) in envctrl_init_i2c_child()
899 * 'NULL' monitor type. in envctrl_init_i2c_child()
901 if (ENVCTRL_CPCI_IGNORED_NODE == pchild->addr) { in envctrl_init_i2c_child()
906 if (of_node_name_eq(root_node, "SUNW,UltraSPARC-IIi-cEngine")) { in envctrl_init_i2c_child()
908 pchild->mon_type[len] = ENVCTRL_NOMON; in envctrl_init_i2c_child()
916 /* Get the monitor channels. */ in envctrl_init_i2c_child()
917 pval = of_get_property(dp, "channels-in-use", &len); in envctrl_init_i2c_child()
918 memcpy(pchild->chnl_array, pval, len); in envctrl_init_i2c_child()
919 pchild->total_chnls = len / sizeof(struct pcf8584_channel); in envctrl_init_i2c_child()
921 for (i = 0; i < pchild->total_chnls; i++) { in envctrl_init_i2c_child()
922 switch (pchild->chnl_array[i].type) { in envctrl_init_i2c_child()
929 i = pchild->total_chnls; in envctrl_init_i2c_child()
934 i = pchild->total_chnls; in envctrl_init_i2c_child()
938 if (pchild->i2ctype == I2C_ADC) { in envctrl_init_i2c_child()
943 i = pchild->total_chnls; in envctrl_init_i2c_child()
992 "kenvctrld unable to monitor CPU temp-- exiting\n"); in kenvctrld()
993 return -ENODEV; in kenvctrld()
998 printk(KERN_INFO PFX "%s starting...\n", current->comm); in kenvctrld()
1013 current->comm, whichcpu, in kenvctrld()
1020 printk(KERN_INFO PFX "%s exiting...\n", current->comm); in kenvctrld()
1030 return -EINVAL; in envctrl_probe()
1032 i2c = of_ioremap(&op->resource[0], 0, 0x2, DRIVER_NAME); in envctrl_probe()
1034 return -ENOMEM; in envctrl_probe()
1037 dp = op->dev.of_node->child; in envctrl_probe()
1047 dp = dp->sibling; in envctrl_probe()
1070 /* Note above traversal routine post-incremented 'i' to accommodate in envctrl_probe()
1071 * a next child device, so we decrement before reverse-traversal of in envctrl_probe()
1075 for (--index; index >= 0; --index) { in envctrl_probe()
1093 of_iounmap(&op->resource[0], i2c, 0x2); in envctrl_probe()
1106 of_iounmap(&op->resource[0], i2c, 0x2); in envctrl_remove()