hwmon.c (68c0d69dee594e1488aebe12aa50fd79a3e5e5b5) | hwmon.c (61b8ab2c5481dc48e8df9a13c297636c1d369554) |
---|---|
1/* 2 * hwmon.c - part of lm_sensors, Linux kernel modules for hardware monitoring 3 * 4 * This file defines the sysfs class "hwmon", for use by sensors drivers. 5 * 6 * Copyright (C) 2005 Mark M. Hoffman <mhoffman@lightlink.com> 7 * 8 * This program is free software; you can redistribute it and/or modify --- 10 unchanged lines hidden (view full) --- 19#include <linux/hwmon.h> 20#include <linux/idr.h> 21#include <linux/module.h> 22#include <linux/pci.h> 23#include <linux/slab.h> 24#include <linux/string.h> 25#include <linux/thermal.h> 26 | 1/* 2 * hwmon.c - part of lm_sensors, Linux kernel modules for hardware monitoring 3 * 4 * This file defines the sysfs class "hwmon", for use by sensors drivers. 5 * 6 * Copyright (C) 2005 Mark M. Hoffman <mhoffman@lightlink.com> 7 * 8 * This program is free software; you can redistribute it and/or modify --- 10 unchanged lines hidden (view full) --- 19#include <linux/hwmon.h> 20#include <linux/idr.h> 21#include <linux/module.h> 22#include <linux/pci.h> 23#include <linux/slab.h> 24#include <linux/string.h> 25#include <linux/thermal.h> 26 |
27#define CREATE_TRACE_POINTS 28#include <trace/events/hwmon.h> 29 |
|
27#define HWMON_ID_PREFIX "hwmon" 28#define HWMON_ID_FORMAT HWMON_ID_PREFIX "%d" 29 30struct hwmon_device { 31 const char *name; 32 struct device dev; 33 const struct hwmon_chip_info *chip; 34 --- 131 unchanged lines hidden (view full) --- 166#else 167static int hwmon_thermal_add_sensor(struct device *dev, 168 struct hwmon_device *hwdev, int index) 169{ 170 return 0; 171} 172#endif /* IS_REACHABLE(CONFIG_THERMAL) && ... */ 173 | 30#define HWMON_ID_PREFIX "hwmon" 31#define HWMON_ID_FORMAT HWMON_ID_PREFIX "%d" 32 33struct hwmon_device { 34 const char *name; 35 struct device dev; 36 const struct hwmon_chip_info *chip; 37 --- 131 unchanged lines hidden (view full) --- 169#else 170static int hwmon_thermal_add_sensor(struct device *dev, 171 struct hwmon_device *hwdev, int index) 172{ 173 return 0; 174} 175#endif /* IS_REACHABLE(CONFIG_THERMAL) && ... */ 176 |
177static int hwmon_attr_base(enum hwmon_sensor_types type) 178{ 179 if (type == hwmon_in) 180 return 0; 181 return 1; 182} 183 |
|
174/* sysfs attribute management */ 175 176static ssize_t hwmon_attr_show(struct device *dev, 177 struct device_attribute *devattr, char *buf) 178{ 179 struct hwmon_device_attribute *hattr = to_hwmon_attr(devattr); 180 long val; 181 int ret; 182 183 ret = hattr->ops->read(dev, hattr->type, hattr->attr, hattr->index, 184 &val); 185 if (ret < 0) 186 return ret; 187 | 184/* sysfs attribute management */ 185 186static ssize_t hwmon_attr_show(struct device *dev, 187 struct device_attribute *devattr, char *buf) 188{ 189 struct hwmon_device_attribute *hattr = to_hwmon_attr(devattr); 190 long val; 191 int ret; 192 193 ret = hattr->ops->read(dev, hattr->type, hattr->attr, hattr->index, 194 &val); 195 if (ret < 0) 196 return ret; 197 |
198 trace_hwmon_attr_show(hattr->index + hwmon_attr_base(hattr->type), 199 hattr->name, val); 200 |
|
188 return sprintf(buf, "%ld\n", val); 189} 190 191static ssize_t hwmon_attr_show_string(struct device *dev, 192 struct device_attribute *devattr, 193 char *buf) 194{ 195 struct hwmon_device_attribute *hattr = to_hwmon_attr(devattr); | 201 return sprintf(buf, "%ld\n", val); 202} 203 204static ssize_t hwmon_attr_show_string(struct device *dev, 205 struct device_attribute *devattr, 206 char *buf) 207{ 208 struct hwmon_device_attribute *hattr = to_hwmon_attr(devattr); |
209 enum hwmon_sensor_types type = hattr->type; |
|
196 const char *s; 197 int ret; 198 199 ret = hattr->ops->read_string(dev, hattr->type, hattr->attr, 200 hattr->index, &s); 201 if (ret < 0) 202 return ret; 203 | 210 const char *s; 211 int ret; 212 213 ret = hattr->ops->read_string(dev, hattr->type, hattr->attr, 214 hattr->index, &s); 215 if (ret < 0) 216 return ret; 217 |
218 trace_hwmon_attr_show_string(hattr->index + hwmon_attr_base(type), 219 hattr->name, s); 220 |
|
204 return sprintf(buf, "%s\n", s); 205} 206 207static ssize_t hwmon_attr_store(struct device *dev, 208 struct device_attribute *devattr, 209 const char *buf, size_t count) 210{ 211 struct hwmon_device_attribute *hattr = to_hwmon_attr(devattr); --- 4 unchanged lines hidden (view full) --- 216 if (ret < 0) 217 return ret; 218 219 ret = hattr->ops->write(dev, hattr->type, hattr->attr, hattr->index, 220 val); 221 if (ret < 0) 222 return ret; 223 | 221 return sprintf(buf, "%s\n", s); 222} 223 224static ssize_t hwmon_attr_store(struct device *dev, 225 struct device_attribute *devattr, 226 const char *buf, size_t count) 227{ 228 struct hwmon_device_attribute *hattr = to_hwmon_attr(devattr); --- 4 unchanged lines hidden (view full) --- 233 if (ret < 0) 234 return ret; 235 236 ret = hattr->ops->write(dev, hattr->type, hattr->attr, hattr->index, 237 val); 238 if (ret < 0) 239 return ret; 240 |
241 trace_hwmon_attr_store(hattr->index + hwmon_attr_base(hattr->type), 242 hattr->name, val); 243 |
|
224 return count; 225} 226 | 244 return count; 245} 246 |
227static int hwmon_attr_base(enum hwmon_sensor_types type) 228{ 229 if (type == hwmon_in) 230 return 0; 231 return 1; 232} 233 | |
234static bool is_string_attr(enum hwmon_sensor_types type, u32 attr) 235{ 236 return (type == hwmon_temp && attr == hwmon_temp_label) || 237 (type == hwmon_in && attr == hwmon_in_label) || 238 (type == hwmon_curr && attr == hwmon_curr_label) || 239 (type == hwmon_power && attr == hwmon_power_label) || 240 (type == hwmon_energy && attr == hwmon_energy_label) || 241 (type == hwmon_humidity && attr == hwmon_humidity_label) || --- 666 unchanged lines hidden --- | 247static bool is_string_attr(enum hwmon_sensor_types type, u32 attr) 248{ 249 return (type == hwmon_temp && attr == hwmon_temp_label) || 250 (type == hwmon_in && attr == hwmon_in_label) || 251 (type == hwmon_curr && attr == hwmon_curr_label) || 252 (type == hwmon_power && attr == hwmon_power_label) || 253 (type == hwmon_energy && attr == hwmon_energy_label) || 254 (type == hwmon_humidity && attr == hwmon_humidity_label) || --- 666 unchanged lines hidden --- |