Skip to contentSkip to conversation

drivers: Add hwmon OCC version specific functions

PATCH New [email protected] 1 participant 1 message Nov 7, 2016 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

PATCH v5 4/5 drivers: Add hwmon OCC version specific functions

From: "Edward A. James" <[email protected]>

Added functions for the P8 OCC and P9 OCC, as well as interfacing to hook into common code.

---
 drivers/hwmon/occ/occ.c |  69 +++++++++++++++-
 drivers/hwmon/occ/occ.h |  30 ++++++-
 drivers/hwmon/occ/p8.c  | 185 ++++++++++++++++++++++++++++++++++++++++-
 drivers/hwmon/occ/p9.c  | 216 +++++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 494 insertions(+), 6 deletions(-)
drivers/hwmon/occ/occ.c +66 -3
index 733b935c..b0443ea 100644
@@ -33,9 +33,64 @@
 struct occ_driver {
 	void *bus;
 	struct occ_bus_ops bus_ops;
+	struct occ_protocol_ops ops;
+	struct occ_protocol protocol;
+	struct device *dev;
+	bool occ_online;
 };
 
-int occ_start(struct device *dev, void *bus, struct occ_bus_ops bus_ops)
+void * occ_get_sensor(struct occ_driver *driver, int sensor_type)
+{
+	return NULL;
+}
+
+static ssize_t show_occ_online(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	struct occ_driver *driver = dev_get_drvdata(dev);
+
+	return snprintf(buf, PAGE_SIZE - 1, "%u\n", driver->occ_online);
+}
+
+static ssize_t store_occ_online(struct device *dev,
+				struct device_attribute *attr,
+				const char *buf, size_t count)
+{
+	struct occ_driver *driver = dev_get_drvdata(dev);
+	unsigned long val;
+	int rc;
+
+	rc = kstrtoul(buf, 10, &val);
+	if (rc)
+		return rc;
+
+	if (val == 1) {
+		if (driver->occ_online)
+			return count;
+
+		driver->dev = hwmon_device_register(dev);
+		if (IS_ERR(driver->dev))
+			return PTR_ERR(driver->dev);
+
+		dev_set_drvdata(driver->dev, driver);
+	} else if (val == 0) {
+		if (!driver->occ_online)
+			return count;
+
+		hwmon_device_unregister(driver->dev);
+		driver->dev = NULL;
+	} else
+		return -EINVAL;
+
+	driver->occ_online = val;
+	return count;
+}
+
+static DEVICE_ATTR(online, S_IWUSR | S_IRUGO, show_occ_online,
+		   store_occ_online);
+
+int occ_start(struct device *dev, void *bus, struct occ_bus_ops bus_ops,
+	      struct occ_protocol_ops ops, struct occ_protocol protocol)
 {
 	struct occ_driver *driver = devm_kzalloc(dev,
 						 sizeof(struct occ_driver),
@@ -47,16 +102,24 @@ int occ_start(struct device *dev, void *bus, struct occ_bus_ops bus_ops)
 
 	driver->bus = bus;
 	driver->bus_ops = bus_ops;
+	driver->ops = ops;
+	driver->protocol = protocol;
 
-	return 0;
+	return device_create_file(dev, &dev_attr_online);
 }
 
 int occ_stop(struct device *dev)
 {
 	struct occ_driver *driver = dev_get_drvdata(dev);
 
-	if (driver)
+	device_remove_file(dev, &dev_attr_online);
+
+	if (driver) {
+		if (driver->dev)
+			hwmon_device_unregister(driver->dev);
+
 		devm_kfree(dev, driver);
+	}
 
 	return 0;
 }
drivers/hwmon/occ/occ.h +29 -1
index 3232251..1d6f130 100644
@@ -23,8 +23,36 @@
 #include "scom.h"
 
 struct device;
+struct occ_driver;
 
-int occ_start(struct device *dev, void *bus, struct occ_bus_ops bus_ops);
+enum sensor_type {
+	FREQ = 0,
+	TEMP,
+	POWER,
+	CAPS,
+	MAX_OCC_SENSOR_TYPE
+};
+
+struct occ_protocol_ops {
+	void (*parse_sensor)(u8 *data, void *sensor, int sensor_type, int off,
+			     int snum);
+	void *(*alloc_sensor)(int sensor_type, int num_sensors);
+	int (*get_sensor_value)(void *driver, int sensor_type, int snum);
+	int (*get_sensor_id)(void *driver, int sensor_type, int snum);
+	int (*get_caps_value)(void *sensor, int snum, int caps_field);
+};
+
+struct occ_protocol {
+	unsigned int num_caps_fields;
+	char **caps_names;
+	u32 command_addr;
+	u32 response_addr;
+};
+
+int occ_start(struct device *dev, void *bus, struct occ_bus_ops bus_ops,
+	      struct occ_protocol_ops ops, struct occ_protocol protocol);
 int occ_stop(struct device *dev);
 
+void *occ_get_sensor(struct occ_driver *driver, int sensor_type);
+
 #endif /* __OCC_H__ */
drivers/hwmon/occ/p8.c +184 -1

193 lines not on this page · raw message

drivers/hwmon/occ/p9.c +215 -1

224 lines not on this page · raw message

Signature · 1 line
1.9.1