xref: /openbmc/linux/drivers/hwmon/atxp1.c (revision 71163c7c36fa76bb5a72feca7fb685677444070a)
18d5d45fbSJean Delvare /*
28d5d45fbSJean Delvare     atxp1.c - kernel module for setting CPU VID and general purpose
38d5d45fbSJean Delvare                      I/Os using the Attansic ATXP1 chip.
48d5d45fbSJean Delvare 
58d5d45fbSJean Delvare     This program is free software; you can redistribute it and/or modify
68d5d45fbSJean Delvare     it under the terms of the GNU General Public License as published by
78d5d45fbSJean Delvare     the Free Software Foundation; either version 2 of the License, or
88d5d45fbSJean Delvare     (at your option) any later version.
98d5d45fbSJean Delvare 
108d5d45fbSJean Delvare     This program is distributed in the hope that it will be useful,
118d5d45fbSJean Delvare     but WITHOUT ANY WARRANTY; without even the implied warranty of
128d5d45fbSJean Delvare     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
138d5d45fbSJean Delvare     GNU General Public License for more details.
148d5d45fbSJean Delvare 
158d5d45fbSJean Delvare     You should have received a copy of the GNU General Public License
168d5d45fbSJean Delvare     along with this program; if not, write to the Free Software
178d5d45fbSJean Delvare     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
188d5d45fbSJean Delvare 
198d5d45fbSJean Delvare */
208d5d45fbSJean Delvare 
218d5d45fbSJean Delvare #include <linux/kernel.h>
228d5d45fbSJean Delvare #include <linux/init.h>
238d5d45fbSJean Delvare #include <linux/module.h>
240cacdf29SJean Delvare #include <linux/jiffies.h>
258d5d45fbSJean Delvare #include <linux/i2c.h>
26943b0830SMark M. Hoffman #include <linux/hwmon.h>
27303760b4SJean Delvare #include <linux/hwmon-vid.h>
28943b0830SMark M. Hoffman #include <linux/err.h>
299a61bf63SIngo Molnar #include <linux/mutex.h>
30a5ebe668SJean Delvare #include <linux/sysfs.h>
318d5d45fbSJean Delvare 
328d5d45fbSJean Delvare MODULE_LICENSE("GPL");
338d5d45fbSJean Delvare MODULE_DESCRIPTION("System voltages control via Attansic ATXP1");
348d5d45fbSJean Delvare MODULE_VERSION("0.6.2");
358d5d45fbSJean Delvare MODULE_AUTHOR("Sebastian Witt <se.witt@gmx.net>");
368d5d45fbSJean Delvare 
378d5d45fbSJean Delvare #define ATXP1_VID	0x00
388d5d45fbSJean Delvare #define ATXP1_CVID	0x01
398d5d45fbSJean Delvare #define ATXP1_GPIO1	0x06
408d5d45fbSJean Delvare #define ATXP1_GPIO2	0x0a
418d5d45fbSJean Delvare #define ATXP1_VIDENA	0x20
428d5d45fbSJean Delvare #define ATXP1_VIDMASK	0x1f
438d5d45fbSJean Delvare #define ATXP1_GPIO1MASK	0x0f
448d5d45fbSJean Delvare 
4525e9c86dSMark M. Hoffman static const unsigned short normal_i2c[] = { 0x37, 0x4e, I2C_CLIENT_END };
468d5d45fbSJean Delvare 
47f4b50261SJean Delvare I2C_CLIENT_INSMOD_1(atxp1);
488d5d45fbSJean Delvare 
49*71163c7cSJean Delvare static int atxp1_probe(struct i2c_client *client,
50*71163c7cSJean Delvare 		       const struct i2c_device_id *id);
51*71163c7cSJean Delvare static int atxp1_remove(struct i2c_client *client);
528d5d45fbSJean Delvare static struct atxp1_data * atxp1_update_device(struct device *dev);
53*71163c7cSJean Delvare static int atxp1_detect(struct i2c_client *client, int kind,
54*71163c7cSJean Delvare 			struct i2c_board_info *info);
55*71163c7cSJean Delvare 
56*71163c7cSJean Delvare static const struct i2c_device_id atxp1_id[] = {
57*71163c7cSJean Delvare 	{ "atxp1", atxp1 },
58*71163c7cSJean Delvare 	{ }
59*71163c7cSJean Delvare };
60*71163c7cSJean Delvare MODULE_DEVICE_TABLE(i2c, atxp1_id);
618d5d45fbSJean Delvare 
628d5d45fbSJean Delvare static struct i2c_driver atxp1_driver = {
63*71163c7cSJean Delvare 	.class		= I2C_CLASS_HWMON,
64cdaf7934SLaurent Riffard 	.driver = {
658d5d45fbSJean Delvare 		.name	= "atxp1",
66cdaf7934SLaurent Riffard 	},
67*71163c7cSJean Delvare 	.probe		= atxp1_probe,
68*71163c7cSJean Delvare 	.remove		= atxp1_remove,
69*71163c7cSJean Delvare 	.id_table	= atxp1_id,
70*71163c7cSJean Delvare 	.detect		= atxp1_detect,
71*71163c7cSJean Delvare 	.address_data	= &addr_data,
728d5d45fbSJean Delvare };
738d5d45fbSJean Delvare 
748d5d45fbSJean Delvare struct atxp1_data {
751beeffe4STony Jones 	struct device *hwmon_dev;
769a61bf63SIngo Molnar 	struct mutex update_lock;
778d5d45fbSJean Delvare 	unsigned long last_updated;
788d5d45fbSJean Delvare 	u8 valid;
798d5d45fbSJean Delvare 	struct {
808d5d45fbSJean Delvare 		u8 vid;		/* VID output register */
818d5d45fbSJean Delvare 		u8 cpu_vid; /* VID input from CPU */
828d5d45fbSJean Delvare 		u8 gpio1;   /* General purpose I/O register 1 */
838d5d45fbSJean Delvare 		u8 gpio2;   /* General purpose I/O register 2 */
848d5d45fbSJean Delvare 	} reg;
858d5d45fbSJean Delvare 	u8 vrm;			/* Detected CPU VRM */
868d5d45fbSJean Delvare };
878d5d45fbSJean Delvare 
888d5d45fbSJean Delvare static struct atxp1_data * atxp1_update_device(struct device *dev)
898d5d45fbSJean Delvare {
908d5d45fbSJean Delvare 	struct i2c_client *client;
918d5d45fbSJean Delvare 	struct atxp1_data *data;
928d5d45fbSJean Delvare 
938d5d45fbSJean Delvare 	client = to_i2c_client(dev);
948d5d45fbSJean Delvare 	data = i2c_get_clientdata(client);
958d5d45fbSJean Delvare 
969a61bf63SIngo Molnar 	mutex_lock(&data->update_lock);
978d5d45fbSJean Delvare 
980cacdf29SJean Delvare 	if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
998d5d45fbSJean Delvare 
1008d5d45fbSJean Delvare 		/* Update local register data */
1018d5d45fbSJean Delvare 		data->reg.vid = i2c_smbus_read_byte_data(client, ATXP1_VID);
1028d5d45fbSJean Delvare 		data->reg.cpu_vid = i2c_smbus_read_byte_data(client, ATXP1_CVID);
1038d5d45fbSJean Delvare 		data->reg.gpio1 = i2c_smbus_read_byte_data(client, ATXP1_GPIO1);
1048d5d45fbSJean Delvare 		data->reg.gpio2 = i2c_smbus_read_byte_data(client, ATXP1_GPIO2);
1058d5d45fbSJean Delvare 
1068d5d45fbSJean Delvare 		data->valid = 1;
1078d5d45fbSJean Delvare 	}
1088d5d45fbSJean Delvare 
1099a61bf63SIngo Molnar 	mutex_unlock(&data->update_lock);
1108d5d45fbSJean Delvare 
1118d5d45fbSJean Delvare 	return(data);
1128d5d45fbSJean Delvare }
1138d5d45fbSJean Delvare 
1148d5d45fbSJean Delvare /* sys file functions for cpu0_vid */
1158d5d45fbSJean Delvare static ssize_t atxp1_showvcore(struct device *dev, struct device_attribute *attr, char *buf)
1168d5d45fbSJean Delvare {
1178d5d45fbSJean Delvare 	int size;
1188d5d45fbSJean Delvare 	struct atxp1_data *data;
1198d5d45fbSJean Delvare 
1208d5d45fbSJean Delvare 	data = atxp1_update_device(dev);
1218d5d45fbSJean Delvare 
1228d5d45fbSJean Delvare 	size = sprintf(buf, "%d\n", vid_from_reg(data->reg.vid & ATXP1_VIDMASK, data->vrm));
1238d5d45fbSJean Delvare 
1248d5d45fbSJean Delvare 	return size;
1258d5d45fbSJean Delvare }
1268d5d45fbSJean Delvare 
1278d5d45fbSJean Delvare static ssize_t atxp1_storevcore(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1288d5d45fbSJean Delvare {
1298d5d45fbSJean Delvare 	struct atxp1_data *data;
1308d5d45fbSJean Delvare 	struct i2c_client *client;
131c41bdb52SAlexey Dobriyan 	int vid, cvid;
1328d5d45fbSJean Delvare 	unsigned int vcore;
1338d5d45fbSJean Delvare 
1348d5d45fbSJean Delvare 	client = to_i2c_client(dev);
1358d5d45fbSJean Delvare 	data = atxp1_update_device(dev);
1368d5d45fbSJean Delvare 
1378d5d45fbSJean Delvare 	vcore = simple_strtoul(buf, NULL, 10);
1388d5d45fbSJean Delvare 	vcore /= 25;
1398d5d45fbSJean Delvare 	vcore *= 25;
1408d5d45fbSJean Delvare 
1418d5d45fbSJean Delvare 	/* Calculate VID */
1428d5d45fbSJean Delvare 	vid = vid_to_reg(vcore, data->vrm);
1438d5d45fbSJean Delvare 
1448d5d45fbSJean Delvare 	if (vid < 0) {
1458d5d45fbSJean Delvare 		dev_err(dev, "VID calculation failed.\n");
1468d5d45fbSJean Delvare 		return -1;
1478d5d45fbSJean Delvare 	}
1488d5d45fbSJean Delvare 
1498d5d45fbSJean Delvare 	/* If output enabled, use control register value. Otherwise original CPU VID */
1508d5d45fbSJean Delvare 	if (data->reg.vid & ATXP1_VIDENA)
1518d5d45fbSJean Delvare 		cvid = data->reg.vid & ATXP1_VIDMASK;
1528d5d45fbSJean Delvare 	else
1538d5d45fbSJean Delvare 		cvid = data->reg.cpu_vid;
1548d5d45fbSJean Delvare 
1558d5d45fbSJean Delvare 	/* Nothing changed, aborting */
1568d5d45fbSJean Delvare 	if (vid == cvid)
1578d5d45fbSJean Delvare 		return count;
1588d5d45fbSJean Delvare 
1598d5d45fbSJean Delvare 	dev_dbg(dev, "Setting VCore to %d mV (0x%02x)\n", vcore, vid);
1608d5d45fbSJean Delvare 
1618d5d45fbSJean Delvare 	/* Write every 25 mV step to increase stability */
1628d5d45fbSJean Delvare 	if (cvid > vid) {
1638d5d45fbSJean Delvare 		for (; cvid >= vid; cvid--) {
1648d5d45fbSJean Delvare         		i2c_smbus_write_byte_data(client, ATXP1_VID, cvid | ATXP1_VIDENA);
1658d5d45fbSJean Delvare 		}
1668d5d45fbSJean Delvare 	}
1678d5d45fbSJean Delvare 	else {
1688d5d45fbSJean Delvare 		for (; cvid <= vid; cvid++) {
1698d5d45fbSJean Delvare         		i2c_smbus_write_byte_data(client, ATXP1_VID, cvid | ATXP1_VIDENA);
1708d5d45fbSJean Delvare 		}
1718d5d45fbSJean Delvare 	}
1728d5d45fbSJean Delvare 
1738d5d45fbSJean Delvare 	data->valid = 0;
1748d5d45fbSJean Delvare 
1758d5d45fbSJean Delvare 	return count;
1768d5d45fbSJean Delvare }
1778d5d45fbSJean Delvare 
1788d5d45fbSJean Delvare /* CPU core reference voltage
1798d5d45fbSJean Delvare     unit: millivolt
1808d5d45fbSJean Delvare */
1818d5d45fbSJean Delvare static DEVICE_ATTR(cpu0_vid, S_IRUGO | S_IWUSR, atxp1_showvcore, atxp1_storevcore);
1828d5d45fbSJean Delvare 
1838d5d45fbSJean Delvare /* sys file functions for GPIO1 */
1848d5d45fbSJean Delvare static ssize_t atxp1_showgpio1(struct device *dev, struct device_attribute *attr, char *buf)
1858d5d45fbSJean Delvare {
1868d5d45fbSJean Delvare 	int size;
1878d5d45fbSJean Delvare 	struct atxp1_data *data;
1888d5d45fbSJean Delvare 
1898d5d45fbSJean Delvare 	data = atxp1_update_device(dev);
1908d5d45fbSJean Delvare 
1918d5d45fbSJean Delvare 	size = sprintf(buf, "0x%02x\n", data->reg.gpio1 & ATXP1_GPIO1MASK);
1928d5d45fbSJean Delvare 
1938d5d45fbSJean Delvare 	return size;
1948d5d45fbSJean Delvare }
1958d5d45fbSJean Delvare 
1968d5d45fbSJean Delvare static ssize_t atxp1_storegpio1(struct device *dev, struct device_attribute *attr, const char*buf, size_t count)
1978d5d45fbSJean Delvare {
1988d5d45fbSJean Delvare 	struct atxp1_data *data;
1998d5d45fbSJean Delvare 	struct i2c_client *client;
2008d5d45fbSJean Delvare 	unsigned int value;
2018d5d45fbSJean Delvare 
2028d5d45fbSJean Delvare 	client = to_i2c_client(dev);
2038d5d45fbSJean Delvare 	data = atxp1_update_device(dev);
2048d5d45fbSJean Delvare 
2058d5d45fbSJean Delvare 	value = simple_strtoul(buf, NULL, 16);
2068d5d45fbSJean Delvare 
2078d5d45fbSJean Delvare 	value &= ATXP1_GPIO1MASK;
2088d5d45fbSJean Delvare 
2098d5d45fbSJean Delvare 	if (value != (data->reg.gpio1 & ATXP1_GPIO1MASK)) {
2108d5d45fbSJean Delvare 		dev_info(dev, "Writing 0x%x to GPIO1.\n", value);
2118d5d45fbSJean Delvare 
2128d5d45fbSJean Delvare 		i2c_smbus_write_byte_data(client, ATXP1_GPIO1, value);
2138d5d45fbSJean Delvare 
2148d5d45fbSJean Delvare 		data->valid = 0;
2158d5d45fbSJean Delvare 	}
2168d5d45fbSJean Delvare 
2178d5d45fbSJean Delvare 	return count;
2188d5d45fbSJean Delvare }
2198d5d45fbSJean Delvare 
2208d5d45fbSJean Delvare /* GPIO1 data register
2218d5d45fbSJean Delvare     unit: Four bit as hex (e.g. 0x0f)
2228d5d45fbSJean Delvare */
2238d5d45fbSJean Delvare static DEVICE_ATTR(gpio1, S_IRUGO | S_IWUSR, atxp1_showgpio1, atxp1_storegpio1);
2248d5d45fbSJean Delvare 
2258d5d45fbSJean Delvare /* sys file functions for GPIO2 */
2268d5d45fbSJean Delvare static ssize_t atxp1_showgpio2(struct device *dev, struct device_attribute *attr, char *buf)
2278d5d45fbSJean Delvare {
2288d5d45fbSJean Delvare 	int size;
2298d5d45fbSJean Delvare 	struct atxp1_data *data;
2308d5d45fbSJean Delvare 
2318d5d45fbSJean Delvare 	data = atxp1_update_device(dev);
2328d5d45fbSJean Delvare 
2338d5d45fbSJean Delvare 	size = sprintf(buf, "0x%02x\n", data->reg.gpio2);
2348d5d45fbSJean Delvare 
2358d5d45fbSJean Delvare 	return size;
2368d5d45fbSJean Delvare }
2378d5d45fbSJean Delvare 
2388d5d45fbSJean Delvare static ssize_t atxp1_storegpio2(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
2398d5d45fbSJean Delvare {
2408d5d45fbSJean Delvare 	struct atxp1_data *data;
2418d5d45fbSJean Delvare 	struct i2c_client *client;
2428d5d45fbSJean Delvare 	unsigned int value;
2438d5d45fbSJean Delvare 
2448d5d45fbSJean Delvare 	client = to_i2c_client(dev);
2458d5d45fbSJean Delvare 	data = atxp1_update_device(dev);
2468d5d45fbSJean Delvare 
2478d5d45fbSJean Delvare 	value = simple_strtoul(buf, NULL, 16) & 0xff;
2488d5d45fbSJean Delvare 
2498d5d45fbSJean Delvare 	if (value != data->reg.gpio2) {
2508d5d45fbSJean Delvare 		dev_info(dev, "Writing 0x%x to GPIO1.\n", value);
2518d5d45fbSJean Delvare 
2528d5d45fbSJean Delvare 		i2c_smbus_write_byte_data(client, ATXP1_GPIO2, value);
2538d5d45fbSJean Delvare 
2548d5d45fbSJean Delvare 		data->valid = 0;
2558d5d45fbSJean Delvare 	}
2568d5d45fbSJean Delvare 
2578d5d45fbSJean Delvare 	return count;
2588d5d45fbSJean Delvare }
2598d5d45fbSJean Delvare 
2608d5d45fbSJean Delvare /* GPIO2 data register
2618d5d45fbSJean Delvare     unit: Eight bit as hex (e.g. 0xff)
2628d5d45fbSJean Delvare */
2638d5d45fbSJean Delvare static DEVICE_ATTR(gpio2, S_IRUGO | S_IWUSR, atxp1_showgpio2, atxp1_storegpio2);
2648d5d45fbSJean Delvare 
265a5ebe668SJean Delvare static struct attribute *atxp1_attributes[] = {
266a5ebe668SJean Delvare 	&dev_attr_gpio1.attr,
267a5ebe668SJean Delvare 	&dev_attr_gpio2.attr,
268a5ebe668SJean Delvare 	&dev_attr_cpu0_vid.attr,
269a5ebe668SJean Delvare 	NULL
270a5ebe668SJean Delvare };
271a5ebe668SJean Delvare 
272a5ebe668SJean Delvare static const struct attribute_group atxp1_group = {
273a5ebe668SJean Delvare 	.attrs = atxp1_attributes,
274a5ebe668SJean Delvare };
275a5ebe668SJean Delvare 
2768d5d45fbSJean Delvare 
277*71163c7cSJean Delvare /* Return 0 if detection is successful, -ENODEV otherwise */
278*71163c7cSJean Delvare static int atxp1_detect(struct i2c_client *new_client, int kind,
279*71163c7cSJean Delvare 			struct i2c_board_info *info)
2808d5d45fbSJean Delvare {
281*71163c7cSJean Delvare 	struct i2c_adapter *adapter = new_client->adapter;
2828d5d45fbSJean Delvare 
2838d5d45fbSJean Delvare 	u8 temp;
2848d5d45fbSJean Delvare 
2858d5d45fbSJean Delvare 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
286*71163c7cSJean Delvare 		return -ENODEV;
2878d5d45fbSJean Delvare 
2888d5d45fbSJean Delvare 	/* Detect ATXP1, checking if vendor ID registers are all zero */
2898d5d45fbSJean Delvare 	if (!((i2c_smbus_read_byte_data(new_client, 0x3e) == 0) &&
2908d5d45fbSJean Delvare 	     (i2c_smbus_read_byte_data(new_client, 0x3f) == 0) &&
2918d5d45fbSJean Delvare 	     (i2c_smbus_read_byte_data(new_client, 0xfe) == 0) &&
2928d5d45fbSJean Delvare 	     (i2c_smbus_read_byte_data(new_client, 0xff) == 0) )) {
2938d5d45fbSJean Delvare 
2948d5d45fbSJean Delvare 		/* No vendor ID, now checking if registers 0x10,0x11 (non-existent)
2958d5d45fbSJean Delvare 		 * showing the same as register 0x00 */
2968d5d45fbSJean Delvare 		temp = i2c_smbus_read_byte_data(new_client, 0x00);
2978d5d45fbSJean Delvare 
2988d5d45fbSJean Delvare 		if (!((i2c_smbus_read_byte_data(new_client, 0x10) == temp) &&
2998d5d45fbSJean Delvare 			 (i2c_smbus_read_byte_data(new_client, 0x11) == temp) ))
300*71163c7cSJean Delvare 			return -ENODEV;
301*71163c7cSJean Delvare 	}
302*71163c7cSJean Delvare 
303*71163c7cSJean Delvare 	/* Get VRM */
304*71163c7cSJean Delvare 	temp = vid_which_vrm();
305*71163c7cSJean Delvare 
306*71163c7cSJean Delvare 	if ((temp != 90) && (temp != 91)) {
307*71163c7cSJean Delvare 		dev_err(&adapter->dev, "atxp1: Not supporting VRM %d.%d\n",
308*71163c7cSJean Delvare 				temp / 10, temp % 10);
309*71163c7cSJean Delvare 		return -ENODEV;
310*71163c7cSJean Delvare 	}
311*71163c7cSJean Delvare 
312*71163c7cSJean Delvare 	strlcpy(info->type, "atxp1", I2C_NAME_SIZE);
313*71163c7cSJean Delvare 
314*71163c7cSJean Delvare 	return 0;
315*71163c7cSJean Delvare }
316*71163c7cSJean Delvare 
317*71163c7cSJean Delvare static int atxp1_probe(struct i2c_client *new_client,
318*71163c7cSJean Delvare 		       const struct i2c_device_id *id)
319*71163c7cSJean Delvare {
320*71163c7cSJean Delvare 	struct atxp1_data *data;
321*71163c7cSJean Delvare 	int err;
322*71163c7cSJean Delvare 
323*71163c7cSJean Delvare 	data = kzalloc(sizeof(struct atxp1_data), GFP_KERNEL);
324*71163c7cSJean Delvare 	if (!data) {
325*71163c7cSJean Delvare 		err = -ENOMEM;
326*71163c7cSJean Delvare 		goto exit;
3278d5d45fbSJean Delvare 	}
3288d5d45fbSJean Delvare 
3298d5d45fbSJean Delvare 	/* Get VRM */
330303760b4SJean Delvare 	data->vrm = vid_which_vrm();
3318d5d45fbSJean Delvare 
332*71163c7cSJean Delvare 	i2c_set_clientdata(new_client, data);
3338d5d45fbSJean Delvare 	data->valid = 0;
3348d5d45fbSJean Delvare 
3359a61bf63SIngo Molnar 	mutex_init(&data->update_lock);
3368d5d45fbSJean Delvare 
337a5ebe668SJean Delvare 	/* Register sysfs hooks */
338a5ebe668SJean Delvare 	if ((err = sysfs_create_group(&new_client->dev.kobj, &atxp1_group)))
339*71163c7cSJean Delvare 		goto exit_free;
340a5ebe668SJean Delvare 
3411beeffe4STony Jones 	data->hwmon_dev = hwmon_device_register(&new_client->dev);
3421beeffe4STony Jones 	if (IS_ERR(data->hwmon_dev)) {
3431beeffe4STony Jones 		err = PTR_ERR(data->hwmon_dev);
344a5ebe668SJean Delvare 		goto exit_remove_files;
345943b0830SMark M. Hoffman 	}
346943b0830SMark M. Hoffman 
3478d5d45fbSJean Delvare 	dev_info(&new_client->dev, "Using VRM: %d.%d\n",
3488d5d45fbSJean Delvare 			 data->vrm / 10, data->vrm % 10);
3498d5d45fbSJean Delvare 
3508d5d45fbSJean Delvare 	return 0;
3518d5d45fbSJean Delvare 
352a5ebe668SJean Delvare exit_remove_files:
353a5ebe668SJean Delvare 	sysfs_remove_group(&new_client->dev.kobj, &atxp1_group);
3548d5d45fbSJean Delvare exit_free:
3558d5d45fbSJean Delvare 	kfree(data);
3568d5d45fbSJean Delvare exit:
3578d5d45fbSJean Delvare 	return err;
3588d5d45fbSJean Delvare };
3598d5d45fbSJean Delvare 
360*71163c7cSJean Delvare static int atxp1_remove(struct i2c_client *client)
3618d5d45fbSJean Delvare {
362943b0830SMark M. Hoffman 	struct atxp1_data * data = i2c_get_clientdata(client);
3638d5d45fbSJean Delvare 
3641beeffe4STony Jones 	hwmon_device_unregister(data->hwmon_dev);
365a5ebe668SJean Delvare 	sysfs_remove_group(&client->dev.kobj, &atxp1_group);
366943b0830SMark M. Hoffman 
367943b0830SMark M. Hoffman 	kfree(data);
3688d5d45fbSJean Delvare 
369*71163c7cSJean Delvare 	return 0;
3708d5d45fbSJean Delvare };
3718d5d45fbSJean Delvare 
3728d5d45fbSJean Delvare static int __init atxp1_init(void)
3738d5d45fbSJean Delvare {
3748d5d45fbSJean Delvare 	return i2c_add_driver(&atxp1_driver);
3758d5d45fbSJean Delvare };
3768d5d45fbSJean Delvare 
3778d5d45fbSJean Delvare static void __exit atxp1_exit(void)
3788d5d45fbSJean Delvare {
3798d5d45fbSJean Delvare 	i2c_del_driver(&atxp1_driver);
3808d5d45fbSJean Delvare };
3818d5d45fbSJean Delvare 
3828d5d45fbSJean Delvare module_init(atxp1_init);
3838d5d45fbSJean Delvare module_exit(atxp1_exit);
384