Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^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)  * atxp1.c - kernel module for setting CPU VID and general purpose
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *	     I/Os using the Attansic ATXP1 chip.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * The ATXP1 can reside on I2C addresses 0x37 or 0x4e. The chip is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * not auto-detected by the driver and must be instantiated explicitly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * See Documentation/i2c/instantiating-devices.rst for more information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/hwmon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/hwmon-vid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) MODULE_DESCRIPTION("System voltages control via Attansic ATXP1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) MODULE_VERSION("0.6.3");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) MODULE_AUTHOR("Sebastian Witt <se.witt@gmx.net>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define ATXP1_VID	0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define ATXP1_CVID	0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define ATXP1_GPIO1	0x06
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define ATXP1_GPIO2	0x0a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define ATXP1_VIDENA	0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define ATXP1_VIDMASK	0x1f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define ATXP1_GPIO1MASK	0x0f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) struct atxp1_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	struct mutex update_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	unsigned long last_updated;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	u8 valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		u8 vid;		/* VID output register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		u8 cpu_vid; /* VID input from CPU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		u8 gpio1;   /* General purpose I/O register 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		u8 gpio2;   /* General purpose I/O register 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	} reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	u8 vrm;			/* Detected CPU VRM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) static struct atxp1_data *atxp1_update_device(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	struct atxp1_data *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	mutex_lock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		/* Update local register data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		data->reg.vid = i2c_smbus_read_byte_data(client, ATXP1_VID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		data->reg.cpu_vid = i2c_smbus_read_byte_data(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 							     ATXP1_CVID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		data->reg.gpio1 = i2c_smbus_read_byte_data(client, ATXP1_GPIO1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		data->reg.gpio2 = i2c_smbus_read_byte_data(client, ATXP1_GPIO2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		data->valid = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	mutex_unlock(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	return data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) /* sys file functions for cpu0_vid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) static ssize_t cpu0_vid_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 			     struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	struct atxp1_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	data = atxp1_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	size = sprintf(buf, "%d\n", vid_from_reg(data->reg.vid & ATXP1_VIDMASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 						 data->vrm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static ssize_t cpu0_vid_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			      struct device_attribute *attr, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			      size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	struct atxp1_data *data = atxp1_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	int vid, cvid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	unsigned long vcore;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	err = kstrtoul(buf, 10, &vcore);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	vcore /= 25;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	vcore *= 25;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	/* Calculate VID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	vid = vid_to_reg(vcore, data->vrm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	if (vid < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		dev_err(dev, "VID calculation failed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		return vid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	 * If output enabled, use control register value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	 * Otherwise original CPU VID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	if (data->reg.vid & ATXP1_VIDENA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		cvid = data->reg.vid & ATXP1_VIDMASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		cvid = data->reg.cpu_vid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	/* Nothing changed, aborting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	if (vid == cvid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	dev_dbg(dev, "Setting VCore to %d mV (0x%02x)\n", (int)vcore, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	/* Write every 25 mV step to increase stability */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	if (cvid > vid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		for (; cvid >= vid; cvid--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			i2c_smbus_write_byte_data(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 						ATXP1_VID, cvid | ATXP1_VIDENA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		for (; cvid <= vid; cvid++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			i2c_smbus_write_byte_data(client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 						ATXP1_VID, cvid | ATXP1_VIDENA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	data->valid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  * CPU core reference voltage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  * unit: millivolt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static DEVICE_ATTR_RW(cpu0_vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) /* sys file functions for GPIO1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static ssize_t gpio1_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 			  char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	struct atxp1_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	data = atxp1_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	size = sprintf(buf, "0x%02x\n", data->reg.gpio1 & ATXP1_GPIO1MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static ssize_t gpio1_store(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			   const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	struct atxp1_data *data = atxp1_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	unsigned long value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	err = kstrtoul(buf, 16, &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	value &= ATXP1_GPIO1MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	if (value != (data->reg.gpio1 & ATXP1_GPIO1MASK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		dev_info(dev, "Writing 0x%x to GPIO1.\n", (unsigned int)value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		i2c_smbus_write_byte_data(client, ATXP1_GPIO1, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		data->valid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)  * GPIO1 data register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)  * unit: Four bit as hex (e.g. 0x0f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static DEVICE_ATTR_RW(gpio1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) /* sys file functions for GPIO2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static ssize_t gpio2_show(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			  char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	struct atxp1_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	data = atxp1_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	size = sprintf(buf, "0x%02x\n", data->reg.gpio2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static ssize_t gpio2_store(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			   const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	struct atxp1_data *data = atxp1_update_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	struct i2c_client *client = data->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	unsigned long value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	err = kstrtoul(buf, 16, &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	value &= 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	if (value != data->reg.gpio2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		dev_info(dev, "Writing 0x%x to GPIO1.\n", (unsigned int)value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		i2c_smbus_write_byte_data(client, ATXP1_GPIO2, value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		data->valid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  * GPIO2 data register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  * unit: Eight bit as hex (e.g. 0xff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static DEVICE_ATTR_RW(gpio2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) static struct attribute *atxp1_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	&dev_attr_gpio1.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	&dev_attr_gpio2.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	&dev_attr_cpu0_vid.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) ATTRIBUTE_GROUPS(atxp1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) static int atxp1_probe(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	struct device *dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	struct atxp1_data *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	struct device *hwmon_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	data = devm_kzalloc(dev, sizeof(struct atxp1_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	/* Get VRM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	data->vrm = vid_which_vrm();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	if (data->vrm != 90 && data->vrm != 91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		dev_err(dev, "atxp1: Not supporting VRM %d.%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 			data->vrm / 10, data->vrm % 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	data->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	mutex_init(&data->update_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 							   data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 							   atxp1_groups);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	if (IS_ERR(hwmon_dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		return PTR_ERR(hwmon_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	dev_info(dev, "Using VRM: %d.%d\n", data->vrm / 10, data->vrm % 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) static const struct i2c_device_id atxp1_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	{ "atxp1", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) MODULE_DEVICE_TABLE(i2c, atxp1_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) static struct i2c_driver atxp1_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	.class		= I2C_CLASS_HWMON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		.name	= "atxp1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	.probe_new	= atxp1_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	.id_table	= atxp1_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) module_i2c_driver(atxp1_driver);