Lines Matching +full:micro +full:- +full:watts

1 // SPDX-License-Identifier: GPL-2.0-or-later
14 #include <linux/hwmon-sysfs.h>
46 #define INVALID_INDEX (-1U)
53 "ibm,opal-sensor-cooling-fan",
54 "ibm,opal-sensor-amb-temp",
55 "ibm,opal-sensor-power-supply",
56 "ibm,opal-sensor-power"
60 const char *name; /* matches property 'sensor-type' */
105 if (sdata->sgrp_data && !sdata->sgrp_data->enable) in show_sensor()
106 return -ENODATA; in show_sensor()
108 ret = opal_get_sensor_data_u64(sdata->id, &x); in show_sensor()
113 /* Convert temperature to milli-degrees */ in show_sensor()
114 if (sdata->type == TEMP) in show_sensor()
116 /* Convert power to micro-watts */ in show_sensor()
117 else if (sdata->type == POWER_INPUT) in show_sensor()
129 return sprintf(buf, "%u\n", sdata->sgrp_data->enable); in show_enable()
138 struct sensor_group_data *sgrp_data = sdata->sgrp_data; in store_enable()
146 ret = mutex_lock_interruptible(&sgrp_data->mutex); in store_enable()
150 if (data != sgrp_data->enable) { in store_enable()
151 ret = sensor_group_enable(sgrp_data->gid, data); in store_enable()
153 sgrp_data->enable = data; in store_enable()
159 mutex_unlock(&sgrp_data->mutex); in store_enable()
169 return sprintf(buf, "%s\n", sdata->label); in show_label()
180 return -ENOENT; in get_logical_cpu()
189 n = scnprintf(sdata->label, sizeof(sdata->label), "%s", label); in make_sensor_label()
202 n += scnprintf(sdata->label + n, in make_sensor_label()
203 sizeof(sdata->label) - n, " %d", in make_sensor_label()
206 n += scnprintf(sdata->label + n, in make_sensor_label()
207 sizeof(sdata->label) - n, " phy%d", id); in make_sensor_label()
213 if (!of_property_read_u32(np, "ibm,chip-id", &id)) in make_sensor_label()
214 n += scnprintf(sdata->label + n, sizeof(sdata->label) - n, in make_sensor_label()
227 return -EINVAL; in get_sensor_index_attr()
229 dash_pos = strchr(hash_pos, '-'); in get_sensor_index_attr()
231 return -EINVAL; in get_sensor_index_attr()
233 copy_len = dash_pos - hash_pos - 1; in get_sensor_index_attr()
235 return -EINVAL; in get_sensor_index_attr()
269 * IBMPOWERNV device node appear like cooling-fan#2-data, amb-temp#1-thrs etc.
286 return ERR_PTR(-ENOENT); in parse_opal_node_name()
304 if (!of_device_is_compatible(np, "ibm,opal-sensor")) in get_sensor_type()
307 if (of_property_read_string(np, "sensor-type", &str)) in get_sensor_type()
325 if (sdata->opal_index != INVALID_INDEX) { in get_sensor_hwmon_index()
327 if (sdata_table[i].opal_index == sdata->opal_index && in get_sensor_hwmon_index()
328 sdata_table[i].type == sdata->type) in get_sensor_hwmon_index()
331 return ++sensor_groups[sdata->type].hwmon_index; in get_sensor_hwmon_index()
342 groups = of_find_compatible_node(NULL, NULL, "ibm,opal-sensor-group"); in init_sensor_group_data()
349 pdata->nr_sensor_groups++; in init_sensor_group_data()
352 if (!pdata->nr_sensor_groups) in init_sensor_group_data()
355 sgrp_data = devm_kcalloc(&pdev->dev, pdata->nr_sensor_groups, in init_sensor_group_data()
358 ret = -ENOMEM; in init_sensor_group_data()
369 if (of_property_read_u32(sgrp, "sensor-group-id", &gid)) in init_sensor_group_data()
381 pdata->sgrp_data = sgrp_data; in init_sensor_group_data()
391 struct sensor_group_data *sgrp_data = pdata->sgrp_data; in get_sensor_group()
394 groups = of_find_compatible_node(NULL, NULL, "ibm,opal-sensor-group"); in get_sensor_group()
408 if (of_property_read_u32(sgrp, "sensor-group-id", &gid)) in get_sensor_group()
412 if (it.phandle == node->phandle) { in get_sensor_group()
420 for (i = 0; i < pdata->nr_sensor_groups; i++) in get_sensor_group()
435 const struct attribute_group **pgroups = pdata->attr_groups; in populate_attr_groups()
459 if (of_property_present(np, "sensor-data-min")) in populate_attr_groups()
461 if (of_property_present(np, "sensor-data-max")) in populate_attr_groups()
468 sensor_groups[type].group.attrs = devm_kcalloc(&pdev->dev, in populate_attr_groups()
473 return -ENOMEM; in populate_attr_groups()
476 pdata->sensors_count += sensor_groups[type].attr_count; in populate_attr_groups()
491 snprintf(sdata->name, MAX_ATTR_LEN, "%s%d_%s", in create_hwmon_attr()
492 sensor_groups[sdata->type].name, sdata->hwmon_index, in create_hwmon_attr()
495 sysfs_attr_init(&sdata->dev_attr.attr); in create_hwmon_attr()
496 sdata->dev_attr.attr.name = sdata->name; in create_hwmon_attr()
497 sdata->dev_attr.show = show; in create_hwmon_attr()
499 sdata->dev_attr.store = store; in create_hwmon_attr()
500 sdata->dev_attr.attr.mode = 0664; in create_hwmon_attr()
502 sdata->dev_attr.attr.mode = 0444; in create_hwmon_attr()
517 sdata->id = sid; in populate_sensor()
518 sdata->type = type; in populate_sensor()
519 sdata->opal_index = od; in populate_sensor()
520 sdata->hwmon_index = hd; in populate_sensor()
522 pgroup->attrs[sensor_groups[type].attr_count++] = &sdata->dev_attr.attr; in populate_sensor()
523 sdata->sgrp_data = sgrp_data; in populate_sensor()
555 const struct attribute_group **pgroups = pdata->attr_groups; in create_device_attrs()
561 sdata = devm_kcalloc(&pdev->dev, in create_device_attrs()
562 pdata->sensors_count, sizeof(*sdata), in create_device_attrs()
565 return -ENOMEM; in create_device_attrs()
581 * Newer device trees use a "sensor-data" property in create_device_attrs()
584 if (of_property_read_u32(np, "sensor-id", &sensor_id) && in create_device_attrs()
585 of_property_read_u32(np, "sensor-data", &sensor_id)) { in create_device_attrs()
586 dev_info(&pdev->dev, in create_device_attrs()
587 "'sensor-id' missing in the node '%pOFn'\n", in create_device_attrs()
601 attr_name = parse_opal_node_name(np->name, type, &opal_index); in create_device_attrs()
629 if (!of_property_read_u32(np, "sensor-data-max", &sensor_id)) { in create_device_attrs()
638 if (!of_property_read_u32(np, "sensor-data-min", &sensor_id)) { in create_device_attrs()
647 if (sgrp_data && !sgrp_data->enable) { in create_device_attrs()
648 sgrp_data->enable = true; in create_device_attrs()
651 sgrp_data->gid, "enable", type, in create_device_attrs()
668 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); in ibmpowernv_probe()
670 return -ENOMEM; in ibmpowernv_probe()
673 pdata->sensors_count = 0; in ibmpowernv_probe()
674 pdata->nr_sensor_groups = 0; in ibmpowernv_probe()
685 hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev, DRVNAME, in ibmpowernv_probe()
687 pdata->attr_groups); in ibmpowernv_probe()
694 .name = "opal-sensor",
701 { .compatible = "ibm,opal-sensor" },