^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * IBM PowerNV platform sensors for temperature/fan/voltage/power
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2014 IBM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #define DRVNAME "ibmpowernv"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define pr_fmt(fmt) DRVNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/hwmon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/hwmon-sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <asm/opal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <asm/cputhreads.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <asm/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define MAX_ATTR_LEN 32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define MAX_LABEL_LEN 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) /* Sensor suffix name from DT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define DT_FAULT_ATTR_SUFFIX "faulted"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define DT_DATA_ATTR_SUFFIX "data"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define DT_THRESHOLD_ATTR_SUFFIX "thrs"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * Enumerates all the types of sensors in the POWERNV platform and does index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * into 'struct sensor_group'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) enum sensors {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) FAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) TEMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) POWER_SUPPLY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) POWER_INPUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) CURRENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) ENERGY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) MAX_SENSOR_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define INVALID_INDEX (-1U)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * 'compatible' string properties for sensor types as defined in old
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * PowerNV firmware (skiboot). These are ordered as 'enum sensors'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static const char * const legacy_compatibles[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) "ibm,opal-sensor-cooling-fan",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) "ibm,opal-sensor-amb-temp",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) "ibm,opal-sensor-power-supply",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) "ibm,opal-sensor-power"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) static struct sensor_group {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) const char *name; /* matches property 'sensor-type' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct attribute_group group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) u32 attr_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) u32 hwmon_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) } sensor_groups[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) { "fan" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) { "temp" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) { "in" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) { "power" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) { "curr" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) { "energy" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct sensor_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) u32 id; /* An opaque id of the firmware for each sensor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) u32 hwmon_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) u32 opal_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) enum sensors type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) char label[MAX_LABEL_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) char name[MAX_ATTR_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) struct device_attribute dev_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct sensor_group_data *sgrp_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct sensor_group_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct mutex mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) u32 gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) bool enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct platform_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) const struct attribute_group *attr_groups[MAX_SENSOR_TYPE + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct sensor_group_data *sgrp_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) u32 sensors_count; /* Total count of sensors from each group */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) u32 nr_sensor_groups; /* Total number of sensor groups */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) static ssize_t show_sensor(struct device *dev, struct device_attribute *devattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct sensor_data *sdata = container_of(devattr, struct sensor_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) dev_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) ssize_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) u64 x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (sdata->sgrp_data && !sdata->sgrp_data->enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) ret = opal_get_sensor_data_u64(sdata->id, &x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /* Convert temperature to milli-degrees */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) if (sdata->type == TEMP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) x *= 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) /* Convert power to micro-watts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) else if (sdata->type == POWER_INPUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) x *= 1000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return sprintf(buf, "%llu\n", x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static ssize_t show_enable(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct device_attribute *devattr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct sensor_data *sdata = container_of(devattr, struct sensor_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) dev_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) return sprintf(buf, "%u\n", sdata->sgrp_data->enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static ssize_t store_enable(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct device_attribute *devattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) struct sensor_data *sdata = container_of(devattr, struct sensor_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) dev_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct sensor_group_data *sgrp_data = sdata->sgrp_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) bool data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) ret = kstrtobool(buf, &data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) ret = mutex_lock_interruptible(&sgrp_data->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (data != sgrp_data->enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) ret = sensor_group_enable(sgrp_data->gid, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) sgrp_data->enable = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) ret = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) mutex_unlock(&sgrp_data->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) static ssize_t show_label(struct device *dev, struct device_attribute *devattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) struct sensor_data *sdata = container_of(devattr, struct sensor_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) dev_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) return sprintf(buf, "%s\n", sdata->label);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) static int get_logical_cpu(int hwcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) for_each_possible_cpu(cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) if (get_hard_smp_processor_id(cpu) == hwcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) return cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) static void make_sensor_label(struct device_node *np,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) struct sensor_data *sdata, const char *label)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) u32 id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) size_t n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) n = scnprintf(sdata->label, sizeof(sdata->label), "%s", label);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) * Core temp pretty print
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) if (!of_property_read_u32(np, "ibm,pir", &id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) int cpuid = get_logical_cpu(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (cpuid >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) * The digital thermal sensors are associated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * with a core.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) n += scnprintf(sdata->label + n,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) sizeof(sdata->label) - n, " %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) cpuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) n += scnprintf(sdata->label + n,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) sizeof(sdata->label) - n, " phy%d", id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) * Membuffer pretty print
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (!of_property_read_u32(np, "ibm,chip-id", &id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) n += scnprintf(sdata->label + n, sizeof(sdata->label) - n,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) " %d", id & 0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) static int get_sensor_index_attr(const char *name, u32 *index, char *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) char *hash_pos = strchr(name, '#');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) char buf[8] = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) char *dash_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) u32 copy_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (!hash_pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) dash_pos = strchr(hash_pos, '-');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if (!dash_pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) copy_len = dash_pos - hash_pos - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) if (copy_len >= sizeof(buf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) strncpy(buf, hash_pos + 1, copy_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) err = kstrtou32(buf, 10, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) strncpy(attr, dash_pos + 1, MAX_ATTR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) static const char *convert_opal_attr_name(enum sensors type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) const char *opal_attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) const char *attr_name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (!strcmp(opal_attr, DT_FAULT_ATTR_SUFFIX)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) attr_name = "fault";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) } else if (!strcmp(opal_attr, DT_DATA_ATTR_SUFFIX)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) attr_name = "input";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) } else if (!strcmp(opal_attr, DT_THRESHOLD_ATTR_SUFFIX)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) if (type == TEMP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) attr_name = "max";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) else if (type == FAN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) attr_name = "min";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) return attr_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) * This function translates the DT node name into the 'hwmon' attribute name.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) * IBMPOWERNV device node appear like cooling-fan#2-data, amb-temp#1-thrs etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) * which need to be mapped as fan2_input, temp1_max respectively before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * populating them inside hwmon device class.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) static const char *parse_opal_node_name(const char *node_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) enum sensors type, u32 *index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) char attr_suffix[MAX_ATTR_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) const char *attr_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) err = get_sensor_index_attr(node_name, index, attr_suffix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) attr_name = convert_opal_attr_name(type, attr_suffix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) if (!attr_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) return ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) return attr_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) static int get_sensor_type(struct device_node *np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) enum sensors type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) const char *str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) for (type = 0; type < ARRAY_SIZE(legacy_compatibles); type++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (of_device_is_compatible(np, legacy_compatibles[type]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) return type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) * Let's check if we have a newer device tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) if (!of_device_is_compatible(np, "ibm,opal-sensor"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) return MAX_SENSOR_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) if (of_property_read_string(np, "sensor-type", &str))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) return MAX_SENSOR_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) for (type = 0; type < MAX_SENSOR_TYPE; type++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) if (!strcmp(str, sensor_groups[type].name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) return type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) return MAX_SENSOR_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) static u32 get_sensor_hwmon_index(struct sensor_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) struct sensor_data *sdata_table, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) * We don't use the OPAL index on newer device trees
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) if (sdata->opal_index != INVALID_INDEX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) for (i = 0; i < count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if (sdata_table[i].opal_index == sdata->opal_index &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) sdata_table[i].type == sdata->type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) return sdata_table[i].hwmon_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) return ++sensor_groups[sdata->type].hwmon_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) static int init_sensor_group_data(struct platform_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) struct platform_data *pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) struct sensor_group_data *sgrp_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) struct device_node *groups, *sgrp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) int count = 0, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) enum sensors type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) groups = of_find_compatible_node(NULL, NULL, "ibm,opal-sensor-group");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) if (!groups)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) for_each_child_of_node(groups, sgrp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) type = get_sensor_type(sgrp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) if (type != MAX_SENSOR_TYPE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) pdata->nr_sensor_groups++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) if (!pdata->nr_sensor_groups)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) sgrp_data = devm_kcalloc(&pdev->dev, pdata->nr_sensor_groups,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) sizeof(*sgrp_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) if (!sgrp_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) for_each_child_of_node(groups, sgrp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) u32 gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) type = get_sensor_type(sgrp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) if (type == MAX_SENSOR_TYPE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) if (of_property_read_u32(sgrp, "sensor-group-id", &gid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) if (of_count_phandle_with_args(sgrp, "sensors", NULL) <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) sensor_groups[type].attr_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) sgrp_data[count].gid = gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) mutex_init(&sgrp_data[count].mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) sgrp_data[count++].enable = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) pdata->sgrp_data = sgrp_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) of_node_put(groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) static struct sensor_group_data *get_sensor_group(struct platform_data *pdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) struct device_node *node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) enum sensors gtype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) struct sensor_group_data *sgrp_data = pdata->sgrp_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) struct device_node *groups, *sgrp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) groups = of_find_compatible_node(NULL, NULL, "ibm,opal-sensor-group");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) if (!groups)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) for_each_child_of_node(groups, sgrp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) struct of_phandle_iterator it;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) u32 gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) int rc, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) enum sensors type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) type = get_sensor_type(sgrp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) if (type != gtype)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) if (of_property_read_u32(sgrp, "sensor-group-id", &gid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) of_for_each_phandle(&it, rc, sgrp, "sensors", NULL, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) if (it.phandle == node->phandle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) of_node_put(it.node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) for (i = 0; i < pdata->nr_sensor_groups; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) if (gid == sgrp_data[i].gid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) of_node_put(sgrp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) of_node_put(groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) return &sgrp_data[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) of_node_put(groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) static int populate_attr_groups(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) struct platform_data *pdata = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) const struct attribute_group **pgroups = pdata->attr_groups;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) struct device_node *opal, *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) enum sensors type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) ret = init_sensor_group_data(pdev, pdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) opal = of_find_node_by_path("/ibm,opal/sensors");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) for_each_child_of_node(opal, np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) const char *label;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) type = get_sensor_type(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) if (type == MAX_SENSOR_TYPE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) sensor_groups[type].attr_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) * add attributes for labels, min and max
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) if (!of_property_read_string(np, "label", &label))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) sensor_groups[type].attr_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) if (of_find_property(np, "sensor-data-min", NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) sensor_groups[type].attr_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) if (of_find_property(np, "sensor-data-max", NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) sensor_groups[type].attr_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) of_node_put(opal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) for (type = 0; type < MAX_SENSOR_TYPE; type++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) sensor_groups[type].group.attrs = devm_kcalloc(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) sensor_groups[type].attr_count + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) sizeof(struct attribute *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) if (!sensor_groups[type].group.attrs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) pgroups[type] = &sensor_groups[type].group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) pdata->sensors_count += sensor_groups[type].attr_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) sensor_groups[type].attr_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) static void create_hwmon_attr(struct sensor_data *sdata, const char *attr_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) ssize_t (*show)(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) char *buf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) ssize_t (*store)(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) const char *buf, size_t count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) snprintf(sdata->name, MAX_ATTR_LEN, "%s%d_%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) sensor_groups[sdata->type].name, sdata->hwmon_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) attr_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) sysfs_attr_init(&sdata->dev_attr.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) sdata->dev_attr.attr.name = sdata->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) sdata->dev_attr.show = show;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) if (store) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) sdata->dev_attr.store = store;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) sdata->dev_attr.attr.mode = 0664;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) sdata->dev_attr.attr.mode = 0444;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) static void populate_sensor(struct sensor_data *sdata, int od, int hd, int sid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) const char *attr_name, enum sensors type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) const struct attribute_group *pgroup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) struct sensor_group_data *sgrp_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) ssize_t (*show)(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) char *buf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) ssize_t (*store)(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) const char *buf, size_t count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) sdata->id = sid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) sdata->type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) sdata->opal_index = od;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) sdata->hwmon_index = hd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) create_hwmon_attr(sdata, attr_name, show, store);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) pgroup->attrs[sensor_groups[type].attr_count++] = &sdata->dev_attr.attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) sdata->sgrp_data = sgrp_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) static char *get_max_attr(enum sensors type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) case POWER_INPUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) return "input_highest";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) return "highest";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) static char *get_min_attr(enum sensors type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) case POWER_INPUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) return "input_lowest";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) return "lowest";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) * Iterate through the device tree for each child of 'sensors' node, create
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) * a sysfs attribute file, the file is named by translating the DT node name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) * to the name required by the higher 'hwmon' driver like fan1_input, temp1_max
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) * etc..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) static int create_device_attrs(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) struct platform_data *pdata = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) const struct attribute_group **pgroups = pdata->attr_groups;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) struct device_node *opal, *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) struct sensor_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) u32 count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) u32 group_attr_id[MAX_SENSOR_TYPE] = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) sdata = devm_kcalloc(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) pdata->sensors_count, sizeof(*sdata),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) if (!sdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) opal = of_find_node_by_path("/ibm,opal/sensors");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) for_each_child_of_node(opal, np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) struct sensor_group_data *sgrp_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) const char *attr_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) u32 opal_index, hw_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) u32 sensor_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) const char *label;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) enum sensors type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) type = get_sensor_type(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) if (type == MAX_SENSOR_TYPE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) * Newer device trees use a "sensor-data" property
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) * name for input.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) if (of_property_read_u32(np, "sensor-id", &sensor_id) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) of_property_read_u32(np, "sensor-data", &sensor_id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) dev_info(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) "'sensor-id' missing in the node '%pOFn'\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) sdata[count].id = sensor_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) sdata[count].type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) * If we can not parse the node name, it means we are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) * running on a newer device tree. We can just forget
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) * about the OPAL index and use a defaut value for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) * hwmon attribute name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) attr_name = parse_opal_node_name(np->name, type, &opal_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) if (IS_ERR(attr_name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) attr_name = "input";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) opal_index = INVALID_INDEX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) hw_id = get_sensor_hwmon_index(&sdata[count], sdata, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) sgrp_data = get_sensor_group(pdata, np, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) populate_sensor(&sdata[count], opal_index, hw_id, sensor_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) attr_name, type, pgroups[type], sgrp_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) show_sensor, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) if (!of_property_read_string(np, "label", &label)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) * For the label attribute, we can reuse the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) * "properties" of the previous "input"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) * attribute. They are related to the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) * sensor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) make_sensor_label(np, &sdata[count], label);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) populate_sensor(&sdata[count], opal_index, hw_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) sensor_id, "label", type, pgroups[type],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) NULL, show_label, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) if (!of_property_read_u32(np, "sensor-data-max", &sensor_id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) attr_name = get_max_attr(type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) populate_sensor(&sdata[count], opal_index, hw_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) sensor_id, attr_name, type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) pgroups[type], sgrp_data, show_sensor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) if (!of_property_read_u32(np, "sensor-data-min", &sensor_id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) attr_name = get_min_attr(type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) populate_sensor(&sdata[count], opal_index, hw_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) sensor_id, attr_name, type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) pgroups[type], sgrp_data, show_sensor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) if (sgrp_data && !sgrp_data->enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) sgrp_data->enable = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) hw_id = ++group_attr_id[type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) populate_sensor(&sdata[count], opal_index, hw_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) sgrp_data->gid, "enable", type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) pgroups[type], sgrp_data, show_enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) store_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) of_node_put(opal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) static int ibmpowernv_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) struct platform_data *pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) struct device *hwmon_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) if (!pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) platform_set_drvdata(pdev, pdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) pdata->sensors_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) pdata->nr_sensor_groups = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) err = populate_attr_groups(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) /* Create sysfs attribute data for each sensor found in the DT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) err = create_device_attrs(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) /* Finally, register with hwmon */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) hwmon_dev = devm_hwmon_device_register_with_groups(&pdev->dev, DRVNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) pdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) pdata->attr_groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) return PTR_ERR_OR_ZERO(hwmon_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) static const struct platform_device_id opal_sensor_driver_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) .name = "opal-sensor",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) MODULE_DEVICE_TABLE(platform, opal_sensor_driver_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) static const struct of_device_id opal_sensor_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) { .compatible = "ibm,opal-sensor" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) { },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) MODULE_DEVICE_TABLE(of, opal_sensor_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) static struct platform_driver ibmpowernv_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) .probe = ibmpowernv_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) .id_table = opal_sensor_driver_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) .name = DRVNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) .of_match_table = opal_sensor_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) module_platform_driver(ibmpowernv_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) MODULE_AUTHOR("Neelesh Gupta <neelegup@linux.vnet.ibm.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) MODULE_DESCRIPTION("IBM POWERNV platform sensors");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) MODULE_LICENSE("GPL");