summaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/atxp1.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2026-08-30 09:22:00 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2026-08-30 09:22:00 -0700
commit034dd340b08be1f2f0477ad16131d609f9dbd53c (patch)
tree2536f4b2d7893ccd916b5abdf3c454ad6edc03c2 /drivers/hwmon/atxp1.c
downloadlinux-stable-034dd340b08be1f2f0477ad16131d609f9dbd53c.tar.gz
linux-stable-034dd340b08be1f2f0477ad16131d609f9dbd53c.zip
Merge tag 'trace-v7.3-2' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-tracegrafted
Pull tracing fixes from Steven Rostedt: - Fix error output of boot instance creation failure Currently if a boot instance creation fails, instead of printing out the name of the instance that failed, it prints "(null)". That is because it prints "cur_str" that had already been processed by strsep(). Print the saved name instead. While at it, print the error code of the failure. - Fix use-after-free for same named historgrams Histograms can be named so that they can be used in multiple events. But if the named histogram has a variable attached, the second event that uses the named histogram which duplicates it and needs to free the original after duplication leaves the old variable in place and still visible. If another histogram uses than variable, it will use the stale one which will try to reference the freed duplicate histogram and crash the kernel. Free the duplicate variables along with the duplicated histogram data. - Check return value of kthread_run() in event self test The events self tests uses a kthread for testing but does not check if it succeeded in creating a kthread. If the kthread creation were to fail, the code will still try to call kthread_stop() on the error returned. - Fix race between reading trace_pipe and updating subbuffer size If a user is reading the trace_pipe file at the same time they update the ring buffer sub-buffer size, can cause the trace_pipe read to read stale data. Add trace_access_lock() around updating the ring buffer sub-buffer size. - Fix eventfs_inode on failure path in creation of the events directory In the creation of the "events" directory, if after allocating the eventfs_inode a failure is detected, it calls cleanup_ei() which calls free_ei(). The free_ei() will test if eventfs_inode being freed has no children. It is a bug if it does. But on the failure case of the creation of the "events" directory, the children lists have not yet been initialized and the free will trigger a warning because list_empty() on an uninitialized list returns false. Move the initialization into init_ei() where it makes more sense and makes sure that a created eventfs_inode has its lists initialized upon creation. - Check return value of kthread_run() in ftrace direct sample code The sample code that shows how to use the ftrace direct calls does not test the return of kthread_run() to see if it succeeds. Return a failure if the kthread_run() doesn't succeed. - Clear user events state on fork in case of alloc failure On fork, the child gets a pointer to the parent's user events state. It makes a copy of it then updates the child's pointer to it. But if the allocation fails, the duplication function leaves the child with a pointer to its parent's descriptor. When the child cleans up its data, it will free the parent's descriptor while the parent is still using it. In the duplication function, set the child's user_event_mm to NULL before testing if the allocation succeeded, and when it exits it will not free the parent's descriptor. - Fix retry exhaustion in simple ring buffer reader swap simple_ring_buffer_swap_reader_page() starts with retry set to 8 and post-decrements it only after a failed link replacement. On the final attempt, a successful replacement leaves retry at zero, while a failed replacement leaves it at -1. But the check for success expects the retry value to be non-zero and exits with an error on zero. This is the opposite result. Fix it. - Fail nicely when the remote swap_reader_page() returns an error Currently, if the swap_reader_page() of a remote buffer fails, it triggers a WARN_ON_ONCE() and continues normally. Instead, have it exit with an error and a pr_warn() print instead of a full WARNING. * tag 'trace-v7.3-2' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: ring-buffer: Stop remote reader update when page swap fails tracing: Fix retry exhaustion in simple ring buffer reader swap tracing/user_events: Clear copied tracing state before fork duplication samples/ftrace: Fix kthread_stop() on ERR_PTR in ftrace-direct-multi-modify samples/ftrace: Fix kthread_stop() on ERR_PTR in ftrace-direct-modify eventfs: Initialize ei->children and ei->list in init_ei() tracing: Fix use-after-free in trace_pipe read on sub-buffer order change tracing: Fix crash passing ERR_PTR to kthread_stop() tracing: Fix use-after-free with same-name named triggers tracing: Fix logged instance name on creation failure
Diffstat (limited to 'drivers/hwmon/atxp1.c')
-rw-r--r--drivers/hwmon/atxp1.c295
1 files changed, 295 insertions, 0 deletions
diff --git a/drivers/hwmon/atxp1.c b/drivers/hwmon/atxp1.c
new file mode 100644
index 000000000..f5de4894f
--- /dev/null
+++ b/drivers/hwmon/atxp1.c
@@ -0,0 +1,295 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * atxp1.c - kernel module for setting CPU VID and general purpose
+ * I/Os using the Attansic ATXP1 chip.
+ *
+ * The ATXP1 can reside on I2C addresses 0x37 or 0x4e. The chip is
+ * not auto-detected by the driver and must be instantiated explicitly.
+ * See Documentation/i2c/instantiating-devices.rst for more information.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/jiffies.h>
+#include <linux/i2c.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-vid.h>
+#include <linux/err.h>
+#include <linux/kstrtox.h>
+#include <linux/mutex.h>
+#include <linux/sysfs.h>
+#include <linux/slab.h>
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("System voltages control via Attansic ATXP1");
+MODULE_VERSION("0.6.3");
+MODULE_AUTHOR("Sebastian Witt <se.witt@gmx.net>");
+
+#define ATXP1_VID 0x00
+#define ATXP1_CVID 0x01
+#define ATXP1_GPIO1 0x06
+#define ATXP1_GPIO2 0x0a
+#define ATXP1_VIDENA 0x20
+#define ATXP1_VIDMASK 0x1f
+#define ATXP1_GPIO1MASK 0x0f
+
+struct atxp1_data {
+ struct i2c_client *client;
+ struct mutex update_lock;
+ unsigned long last_updated;
+ bool valid;
+ struct {
+ u8 vid; /* VID output register */
+ u8 cpu_vid; /* VID input from CPU */
+ u8 gpio1; /* General purpose I/O register 1 */
+ u8 gpio2; /* General purpose I/O register 2 */
+ } reg;
+ u8 vrm; /* Detected CPU VRM */
+};
+
+static struct atxp1_data *atxp1_update_device(struct device *dev)
+{
+ struct atxp1_data *data = dev_get_drvdata(dev);
+ struct i2c_client *client = data->client;
+
+ mutex_lock(&data->update_lock);
+
+ if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
+
+ /* Update local register data */
+ data->reg.vid = i2c_smbus_read_byte_data(client, ATXP1_VID);
+ data->reg.cpu_vid = i2c_smbus_read_byte_data(client,
+ ATXP1_CVID);
+ data->reg.gpio1 = i2c_smbus_read_byte_data(client, ATXP1_GPIO1);
+ data->reg.gpio2 = i2c_smbus_read_byte_data(client, ATXP1_GPIO2);
+
+ data->valid = true;
+ }
+
+ mutex_unlock(&data->update_lock);
+
+ return data;
+}
+
+/* sys file functions for cpu0_vid */
+static ssize_t cpu0_vid_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ int size;
+ struct atxp1_data *data;
+
+ data = atxp1_update_device(dev);
+
+ size = sprintf(buf, "%d\n", vid_from_reg(data->reg.vid & ATXP1_VIDMASK,
+ data->vrm));
+
+ return size;
+}
+
+static ssize_t cpu0_vid_store(struct device *dev,
+ struct device_attribute *attr, const char *buf,
+ size_t count)
+{
+ struct atxp1_data *data = atxp1_update_device(dev);
+ struct i2c_client *client = data->client;
+ int vid, cvid;
+ unsigned long vcore;
+ int err;
+
+ err = kstrtoul(buf, 10, &vcore);
+ if (err)
+ return err;
+
+ vcore /= 25;
+ vcore *= 25;
+
+ /* Calculate VID */
+ vid = vid_to_reg(vcore, data->vrm);
+ if (vid < 0) {
+ dev_err(dev, "VID calculation failed.\n");
+ return vid;
+ }
+
+ /*
+ * If output enabled, use control register value.
+ * Otherwise original CPU VID
+ */
+ if (data->reg.vid & ATXP1_VIDENA)
+ cvid = data->reg.vid & ATXP1_VIDMASK;
+ else
+ cvid = data->reg.cpu_vid;
+
+ /* Nothing changed, aborting */
+ if (vid == cvid)
+ return count;
+
+ dev_dbg(dev, "Setting VCore to %d mV (0x%02x)\n", (int)vcore, vid);
+
+ /* Write every 25 mV step to increase stability */
+ if (cvid > vid) {
+ for (; cvid >= vid; cvid--)
+ i2c_smbus_write_byte_data(client,
+ ATXP1_VID, cvid | ATXP1_VIDENA);
+ } else {
+ for (; cvid <= vid; cvid++)
+ i2c_smbus_write_byte_data(client,
+ ATXP1_VID, cvid | ATXP1_VIDENA);
+ }
+
+ data->valid = false;
+
+ return count;
+}
+
+/*
+ * CPU core reference voltage
+ * unit: millivolt
+ */
+static DEVICE_ATTR_RW(cpu0_vid);
+
+/* sys file functions for GPIO1 */
+static ssize_t gpio1_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ int size;
+ struct atxp1_data *data;
+
+ data = atxp1_update_device(dev);
+
+ size = sprintf(buf, "0x%02x\n", data->reg.gpio1 & ATXP1_GPIO1MASK);
+
+ return size;
+}
+
+static ssize_t gpio1_store(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct atxp1_data *data = atxp1_update_device(dev);
+ struct i2c_client *client = data->client;
+ unsigned long value;
+ int err;
+
+ err = kstrtoul(buf, 16, &value);
+ if (err)
+ return err;
+
+ value &= ATXP1_GPIO1MASK;
+
+ if (value != (data->reg.gpio1 & ATXP1_GPIO1MASK)) {
+ dev_info(dev, "Writing 0x%x to GPIO1.\n", (unsigned int)value);
+
+ i2c_smbus_write_byte_data(client, ATXP1_GPIO1, value);
+
+ data->valid = false;
+ }
+
+ return count;
+}
+
+/*
+ * GPIO1 data register
+ * unit: Four bit as hex (e.g. 0x0f)
+ */
+static DEVICE_ATTR_RW(gpio1);
+
+/* sys file functions for GPIO2 */
+static ssize_t gpio2_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ int size;
+ struct atxp1_data *data;
+
+ data = atxp1_update_device(dev);
+
+ size = sprintf(buf, "0x%02x\n", data->reg.gpio2);
+
+ return size;
+}
+
+static ssize_t gpio2_store(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct atxp1_data *data = atxp1_update_device(dev);
+ struct i2c_client *client = data->client;
+ unsigned long value;
+ int err;
+
+ err = kstrtoul(buf, 16, &value);
+ if (err)
+ return err;
+ value &= 0xff;
+
+ if (value != data->reg.gpio2) {
+ dev_info(dev, "Writing 0x%x to GPIO1.\n", (unsigned int)value);
+
+ i2c_smbus_write_byte_data(client, ATXP1_GPIO2, value);
+
+ data->valid = false;
+ }
+
+ return count;
+}
+
+/*
+ * GPIO2 data register
+ * unit: Eight bit as hex (e.g. 0xff)
+ */
+static DEVICE_ATTR_RW(gpio2);
+
+static struct attribute *atxp1_attrs[] = {
+ &dev_attr_gpio1.attr,
+ &dev_attr_gpio2.attr,
+ &dev_attr_cpu0_vid.attr,
+ NULL
+};
+ATTRIBUTE_GROUPS(atxp1);
+
+static int atxp1_probe(struct i2c_client *client)
+{
+ struct device *dev = &client->dev;
+ struct atxp1_data *data;
+ struct device *hwmon_dev;
+
+ data = devm_kzalloc(dev, sizeof(struct atxp1_data), GFP_KERNEL);
+ if (!data)
+ return -ENOMEM;
+
+ /* Get VRM */
+ data->vrm = vid_which_vrm();
+ if (data->vrm != 90 && data->vrm != 91) {
+ dev_err(dev, "atxp1: Not supporting VRM %d.%d\n",
+ data->vrm / 10, data->vrm % 10);
+ return -ENODEV;
+ }
+
+ data->client = client;
+ mutex_init(&data->update_lock);
+
+ hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
+ data,
+ atxp1_groups);
+ if (IS_ERR(hwmon_dev))
+ return PTR_ERR(hwmon_dev);
+
+ dev_info(dev, "Using VRM: %d.%d\n", data->vrm / 10, data->vrm % 10);
+
+ return 0;
+};
+
+static const struct i2c_device_id atxp1_id[] = {
+ { .name = "atxp1" },
+ { }
+};
+MODULE_DEVICE_TABLE(i2c, atxp1_id);
+
+static struct i2c_driver atxp1_driver = {
+ .class = I2C_CLASS_HWMON,
+ .driver = {
+ .name = "atxp1",
+ },
+ .probe = atxp1_probe,
+ .id_table = atxp1_id,
+};
+
+module_i2c_driver(atxp1_driver);