xref: /linux/drivers/hwmon/adt7470.c (revision fe03f28cf35bf8dd0d3cba5e0c00a22530b73bfb)
16f9703d0SDarrick J. Wong /*
26f9703d0SDarrick J. Wong  * A hwmon driver for the Analog Devices ADT7470
36f9703d0SDarrick J. Wong  * Copyright (C) 2007 IBM
46f9703d0SDarrick J. Wong  *
56f9703d0SDarrick J. Wong  * Author: Darrick J. Wong <djwong@us.ibm.com>
66f9703d0SDarrick J. Wong  *
76f9703d0SDarrick J. Wong  * This program is free software; you can redistribute it and/or modify
86f9703d0SDarrick J. Wong  * it under the terms of the GNU General Public License as published by
96f9703d0SDarrick J. Wong  * the Free Software Foundation; either version 2 of the License, or
106f9703d0SDarrick J. Wong  * (at your option) any later version.
116f9703d0SDarrick J. Wong  *
126f9703d0SDarrick J. Wong  * This program is distributed in the hope that it will be useful,
136f9703d0SDarrick J. Wong  * but WITHOUT ANY WARRANTY; without even the implied warranty of
146f9703d0SDarrick J. Wong  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
156f9703d0SDarrick J. Wong  * GNU General Public License for more details.
166f9703d0SDarrick J. Wong  *
176f9703d0SDarrick J. Wong  * You should have received a copy of the GNU General Public License
186f9703d0SDarrick J. Wong  * along with this program; if not, write to the Free Software
196f9703d0SDarrick J. Wong  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
206f9703d0SDarrick J. Wong  */
216f9703d0SDarrick J. Wong 
226f9703d0SDarrick J. Wong #include <linux/module.h>
236f9703d0SDarrick J. Wong #include <linux/jiffies.h>
246f9703d0SDarrick J. Wong #include <linux/i2c.h>
256f9703d0SDarrick J. Wong #include <linux/hwmon.h>
266f9703d0SDarrick J. Wong #include <linux/hwmon-sysfs.h>
276f9703d0SDarrick J. Wong #include <linux/err.h>
286f9703d0SDarrick J. Wong #include <linux/mutex.h>
296f9703d0SDarrick J. Wong #include <linux/delay.h>
306f9703d0SDarrick J. Wong #include <linux/log2.h>
316f9703d0SDarrick J. Wong 
326f9703d0SDarrick J. Wong /* Addresses to scan */
336f9703d0SDarrick J. Wong static unsigned short normal_i2c[] = { 0x2C, 0x2E, 0x2F, I2C_CLIENT_END };
346f9703d0SDarrick J. Wong 
356f9703d0SDarrick J. Wong /* Insmod parameters */
366f9703d0SDarrick J. Wong I2C_CLIENT_INSMOD_1(adt7470);
376f9703d0SDarrick J. Wong 
386f9703d0SDarrick J. Wong /* ADT7470 registers */
396f9703d0SDarrick J. Wong #define ADT7470_REG_BASE_ADDR			0x20
406f9703d0SDarrick J. Wong #define ADT7470_REG_TEMP_BASE_ADDR		0x20
416f9703d0SDarrick J. Wong #define ADT7470_REG_TEMP_MAX_ADDR		0x29
426f9703d0SDarrick J. Wong #define ADT7470_REG_FAN_BASE_ADDR		0x2A
436f9703d0SDarrick J. Wong #define ADT7470_REG_FAN_MAX_ADDR		0x31
446f9703d0SDarrick J. Wong #define ADT7470_REG_PWM_BASE_ADDR		0x32
456f9703d0SDarrick J. Wong #define ADT7470_REG_PWM_MAX_ADDR		0x35
466f9703d0SDarrick J. Wong #define ADT7470_REG_PWM_MAX_BASE_ADDR		0x38
476f9703d0SDarrick J. Wong #define ADT7470_REG_PWM_MAX_MAX_ADDR		0x3B
486f9703d0SDarrick J. Wong #define ADT7470_REG_CFG				0x40
496f9703d0SDarrick J. Wong #define		ADT7470_FSPD_MASK		0x04
506f9703d0SDarrick J. Wong #define ADT7470_REG_ALARM1			0x41
51*fe03f28cSDarrick J. Wong #define		ADT7470_R1T_ALARM		0x01
52*fe03f28cSDarrick J. Wong #define		ADT7470_R2T_ALARM		0x02
53*fe03f28cSDarrick J. Wong #define		ADT7470_R3T_ALARM		0x04
54*fe03f28cSDarrick J. Wong #define		ADT7470_R4T_ALARM		0x08
55*fe03f28cSDarrick J. Wong #define		ADT7470_R5T_ALARM		0x10
56*fe03f28cSDarrick J. Wong #define		ADT7470_R6T_ALARM		0x20
57*fe03f28cSDarrick J. Wong #define		ADT7470_R7T_ALARM		0x40
58*fe03f28cSDarrick J. Wong #define		ADT7470_OOL_ALARM		0x80
596f9703d0SDarrick J. Wong #define ADT7470_REG_ALARM2			0x42
60*fe03f28cSDarrick J. Wong #define		ADT7470_R8T_ALARM		0x01
61*fe03f28cSDarrick J. Wong #define		ADT7470_R9T_ALARM		0x02
62*fe03f28cSDarrick J. Wong #define		ADT7470_R10T_ALARM		0x04
63*fe03f28cSDarrick J. Wong #define		ADT7470_FAN1_ALARM		0x10
64*fe03f28cSDarrick J. Wong #define		ADT7470_FAN2_ALARM		0x20
65*fe03f28cSDarrick J. Wong #define		ADT7470_FAN3_ALARM		0x40
66*fe03f28cSDarrick J. Wong #define		ADT7470_FAN4_ALARM		0x80
676f9703d0SDarrick J. Wong #define ADT7470_REG_TEMP_LIMITS_BASE_ADDR	0x44
686f9703d0SDarrick J. Wong #define ADT7470_REG_TEMP_LIMITS_MAX_ADDR	0x57
696f9703d0SDarrick J. Wong #define ADT7470_REG_FAN_MIN_BASE_ADDR		0x58
706f9703d0SDarrick J. Wong #define ADT7470_REG_FAN_MIN_MAX_ADDR		0x5F
716f9703d0SDarrick J. Wong #define ADT7470_REG_FAN_MAX_BASE_ADDR		0x60
726f9703d0SDarrick J. Wong #define ADT7470_REG_FAN_MAX_MAX_ADDR		0x67
736f9703d0SDarrick J. Wong #define ADT7470_REG_PWM_CFG_BASE_ADDR		0x68
746f9703d0SDarrick J. Wong #define ADT7470_REG_PWM12_CFG			0x68
756f9703d0SDarrick J. Wong #define		ADT7470_PWM2_AUTO_MASK		0x40
766f9703d0SDarrick J. Wong #define		ADT7470_PWM1_AUTO_MASK		0x80
776f9703d0SDarrick J. Wong #define ADT7470_REG_PWM34_CFG			0x69
786f9703d0SDarrick J. Wong #define		ADT7470_PWM3_AUTO_MASK		0x40
796f9703d0SDarrick J. Wong #define		ADT7470_PWM4_AUTO_MASK		0x80
806f9703d0SDarrick J. Wong #define	ADT7470_REG_PWM_MIN_BASE_ADDR		0x6A
816f9703d0SDarrick J. Wong #define ADT7470_REG_PWM_MIN_MAX_ADDR		0x6D
826f9703d0SDarrick J. Wong #define ADT7470_REG_PWM_TEMP_MIN_BASE_ADDR	0x6E
836f9703d0SDarrick J. Wong #define ADT7470_REG_PWM_TEMP_MIN_MAX_ADDR	0x71
846f9703d0SDarrick J. Wong #define ADT7470_REG_ACOUSTICS12			0x75
856f9703d0SDarrick J. Wong #define ADT7470_REG_ACOUSTICS34			0x76
866f9703d0SDarrick J. Wong #define ADT7470_REG_DEVICE			0x3D
876f9703d0SDarrick J. Wong #define ADT7470_REG_VENDOR			0x3E
886f9703d0SDarrick J. Wong #define ADT7470_REG_REVISION			0x3F
896f9703d0SDarrick J. Wong #define ADT7470_REG_ALARM1_MASK			0x72
906f9703d0SDarrick J. Wong #define ADT7470_REG_ALARM2_MASK			0x73
916f9703d0SDarrick J. Wong #define ADT7470_REG_PWM_AUTO_TEMP_BASE_ADDR	0x7C
926f9703d0SDarrick J. Wong #define ADT7470_REG_PWM_AUTO_TEMP_MAX_ADDR	0x7D
936f9703d0SDarrick J. Wong #define ADT7470_REG_MAX_ADDR			0x81
946f9703d0SDarrick J. Wong 
956f9703d0SDarrick J. Wong #define ADT7470_TEMP_COUNT	10
966f9703d0SDarrick J. Wong #define ADT7470_TEMP_REG(x)	(ADT7470_REG_TEMP_BASE_ADDR + (x))
976f9703d0SDarrick J. Wong #define ADT7470_TEMP_MIN_REG(x) (ADT7470_REG_TEMP_LIMITS_BASE_ADDR + ((x) * 2))
986f9703d0SDarrick J. Wong #define ADT7470_TEMP_MAX_REG(x) (ADT7470_REG_TEMP_LIMITS_BASE_ADDR + \
996f9703d0SDarrick J. Wong 				((x) * 2) + 1)
1006f9703d0SDarrick J. Wong 
1016f9703d0SDarrick J. Wong #define ADT7470_FAN_COUNT	4
1026f9703d0SDarrick J. Wong #define ADT7470_REG_FAN(x)	(ADT7470_REG_FAN_BASE_ADDR + ((x) * 2))
1036f9703d0SDarrick J. Wong #define ADT7470_REG_FAN_MIN(x)	(ADT7470_REG_FAN_MIN_BASE_ADDR + ((x) * 2))
1046f9703d0SDarrick J. Wong #define ADT7470_REG_FAN_MAX(x)	(ADT7470_REG_FAN_MAX_BASE_ADDR + ((x) * 2))
1056f9703d0SDarrick J. Wong 
1066f9703d0SDarrick J. Wong #define ADT7470_PWM_COUNT	4
1076f9703d0SDarrick J. Wong #define ADT7470_REG_PWM(x)	(ADT7470_REG_PWM_BASE_ADDR + (x))
1086f9703d0SDarrick J. Wong #define ADT7470_REG_PWM_MAX(x)	(ADT7470_REG_PWM_MAX_BASE_ADDR + (x))
1096f9703d0SDarrick J. Wong #define ADT7470_REG_PWM_MIN(x)	(ADT7470_REG_PWM_MIN_BASE_ADDR + (x))
1106f9703d0SDarrick J. Wong #define ADT7470_REG_PWM_TMIN(x)	(ADT7470_REG_PWM_TEMP_MIN_BASE_ADDR + (x))
1116f9703d0SDarrick J. Wong #define ADT7470_REG_PWM_CFG(x)	(ADT7470_REG_PWM_CFG_BASE_ADDR + ((x) / 2))
1126f9703d0SDarrick J. Wong #define ADT7470_REG_PWM_AUTO_TEMP(x)	(ADT7470_REG_PWM_AUTO_TEMP_BASE_ADDR + \
1136f9703d0SDarrick J. Wong 					((x) / 2))
1146f9703d0SDarrick J. Wong 
115*fe03f28cSDarrick J. Wong #define ALARM2(x)		((x) << 8)
116*fe03f28cSDarrick J. Wong 
1176f9703d0SDarrick J. Wong #define ADT7470_VENDOR		0x41
1186f9703d0SDarrick J. Wong #define ADT7470_DEVICE		0x70
1196f9703d0SDarrick J. Wong /* datasheet only mentions a revision 2 */
1206f9703d0SDarrick J. Wong #define ADT7470_REVISION	0x02
1216f9703d0SDarrick J. Wong 
1226f9703d0SDarrick J. Wong /* "all temps" according to hwmon sysfs interface spec */
1236f9703d0SDarrick J. Wong #define ADT7470_PWM_ALL_TEMPS	0x3FF
1246f9703d0SDarrick J. Wong 
1256f9703d0SDarrick J. Wong /* How often do we reread sensors values? (In jiffies) */
1266f9703d0SDarrick J. Wong #define SENSOR_REFRESH_INTERVAL	(5 * HZ)
1276f9703d0SDarrick J. Wong 
1286f9703d0SDarrick J. Wong /* How often do we reread sensor limit values? (In jiffies) */
1296f9703d0SDarrick J. Wong #define LIMIT_REFRESH_INTERVAL	(60 * HZ)
1306f9703d0SDarrick J. Wong 
1316f9703d0SDarrick J. Wong /* sleep 1s while gathering temperature data */
1326f9703d0SDarrick J. Wong #define TEMP_COLLECTION_TIME	1000
1336f9703d0SDarrick J. Wong 
1346f9703d0SDarrick J. Wong /* datasheet says to divide this number by the fan reading to get fan rpm */
1356f9703d0SDarrick J. Wong #define FAN_PERIOD_TO_RPM(x)	((90000 * 60) / (x))
1366f9703d0SDarrick J. Wong #define FAN_RPM_TO_PERIOD	FAN_PERIOD_TO_RPM
1376f9703d0SDarrick J. Wong #define FAN_PERIOD_INVALID	65535
1386f9703d0SDarrick J. Wong #define FAN_DATA_VALID(x)	((x) && (x) != FAN_PERIOD_INVALID)
1396f9703d0SDarrick J. Wong 
1406f9703d0SDarrick J. Wong struct adt7470_data {
1416f9703d0SDarrick J. Wong 	struct i2c_client	client;
1421beeffe4STony Jones 	struct device		*hwmon_dev;
1436f9703d0SDarrick J. Wong 	struct attribute_group	attrs;
1446f9703d0SDarrick J. Wong 	struct mutex		lock;
1456f9703d0SDarrick J. Wong 	char			sensors_valid;
1466f9703d0SDarrick J. Wong 	char			limits_valid;
1476f9703d0SDarrick J. Wong 	unsigned long		sensors_last_updated;	/* In jiffies */
1486f9703d0SDarrick J. Wong 	unsigned long		limits_last_updated;	/* In jiffies */
1496f9703d0SDarrick J. Wong 
1506f9703d0SDarrick J. Wong 	s8			temp[ADT7470_TEMP_COUNT];
1516f9703d0SDarrick J. Wong 	s8			temp_min[ADT7470_TEMP_COUNT];
1526f9703d0SDarrick J. Wong 	s8			temp_max[ADT7470_TEMP_COUNT];
1536f9703d0SDarrick J. Wong 	u16			fan[ADT7470_FAN_COUNT];
1546f9703d0SDarrick J. Wong 	u16			fan_min[ADT7470_FAN_COUNT];
1556f9703d0SDarrick J. Wong 	u16			fan_max[ADT7470_FAN_COUNT];
156*fe03f28cSDarrick J. Wong 	u16			alarm;
157*fe03f28cSDarrick J. Wong 	u16			alarms_mask;
1586f9703d0SDarrick J. Wong 	u8			force_pwm_max;
1596f9703d0SDarrick J. Wong 	u8			pwm[ADT7470_PWM_COUNT];
1606f9703d0SDarrick J. Wong 	u8			pwm_max[ADT7470_PWM_COUNT];
1616f9703d0SDarrick J. Wong 	u8			pwm_automatic[ADT7470_PWM_COUNT];
1626f9703d0SDarrick J. Wong 	u8			pwm_min[ADT7470_PWM_COUNT];
1636f9703d0SDarrick J. Wong 	s8			pwm_tmin[ADT7470_PWM_COUNT];
1646f9703d0SDarrick J. Wong 	u8			pwm_auto_temp[ADT7470_PWM_COUNT];
1656f9703d0SDarrick J. Wong };
1666f9703d0SDarrick J. Wong 
1676f9703d0SDarrick J. Wong static int adt7470_attach_adapter(struct i2c_adapter *adapter);
1686f9703d0SDarrick J. Wong static int adt7470_detect(struct i2c_adapter *adapter, int address, int kind);
1696f9703d0SDarrick J. Wong static int adt7470_detach_client(struct i2c_client *client);
1706f9703d0SDarrick J. Wong 
1716f9703d0SDarrick J. Wong static struct i2c_driver adt7470_driver = {
1726f9703d0SDarrick J. Wong 	.driver = {
1736f9703d0SDarrick J. Wong 		.name	= "adt7470",
1746f9703d0SDarrick J. Wong 	},
1756f9703d0SDarrick J. Wong 	.attach_adapter	= adt7470_attach_adapter,
1766f9703d0SDarrick J. Wong 	.detach_client	= adt7470_detach_client,
1776f9703d0SDarrick J. Wong };
1786f9703d0SDarrick J. Wong 
1796f9703d0SDarrick J. Wong /*
1806f9703d0SDarrick J. Wong  * 16-bit registers on the ADT7470 are low-byte first.  The data sheet says
1816f9703d0SDarrick J. Wong  * that the low byte must be read before the high byte.
1826f9703d0SDarrick J. Wong  */
1836f9703d0SDarrick J. Wong static inline int adt7470_read_word_data(struct i2c_client *client, u8 reg)
1846f9703d0SDarrick J. Wong {
1856f9703d0SDarrick J. Wong 	u16 foo;
1866f9703d0SDarrick J. Wong 	foo = i2c_smbus_read_byte_data(client, reg);
1876f9703d0SDarrick J. Wong 	foo |= ((u16)i2c_smbus_read_byte_data(client, reg + 1) << 8);
1886f9703d0SDarrick J. Wong 	return foo;
1896f9703d0SDarrick J. Wong }
1906f9703d0SDarrick J. Wong 
1916f9703d0SDarrick J. Wong static inline int adt7470_write_word_data(struct i2c_client *client, u8 reg,
1926f9703d0SDarrick J. Wong 					  u16 value)
1936f9703d0SDarrick J. Wong {
1946f9703d0SDarrick J. Wong 	return i2c_smbus_write_byte_data(client, reg, value & 0xFF)
1956f9703d0SDarrick J. Wong 	       && i2c_smbus_write_byte_data(client, reg + 1, value >> 8);
1966f9703d0SDarrick J. Wong }
1976f9703d0SDarrick J. Wong 
1986f9703d0SDarrick J. Wong static void adt7470_init_client(struct i2c_client *client)
1996f9703d0SDarrick J. Wong {
2006f9703d0SDarrick J. Wong 	int reg = i2c_smbus_read_byte_data(client, ADT7470_REG_CFG);
2016f9703d0SDarrick J. Wong 
2026f9703d0SDarrick J. Wong 	if (reg < 0) {
2036f9703d0SDarrick J. Wong 		dev_err(&client->dev, "cannot read configuration register\n");
2046f9703d0SDarrick J. Wong 	} else {
2056f9703d0SDarrick J. Wong 		/* start monitoring (and do a self-test) */
2066f9703d0SDarrick J. Wong 		i2c_smbus_write_byte_data(client, ADT7470_REG_CFG, reg | 3);
2076f9703d0SDarrick J. Wong 	}
2086f9703d0SDarrick J. Wong }
2096f9703d0SDarrick J. Wong 
2106f9703d0SDarrick J. Wong static struct adt7470_data *adt7470_update_device(struct device *dev)
2116f9703d0SDarrick J. Wong {
2126f9703d0SDarrick J. Wong 	struct i2c_client *client = to_i2c_client(dev);
2136f9703d0SDarrick J. Wong 	struct adt7470_data *data = i2c_get_clientdata(client);
2146f9703d0SDarrick J. Wong 	unsigned long local_jiffies = jiffies;
2156f9703d0SDarrick J. Wong 	u8 cfg;
2166f9703d0SDarrick J. Wong 	int i;
2176f9703d0SDarrick J. Wong 
2186f9703d0SDarrick J. Wong 	mutex_lock(&data->lock);
2196f9703d0SDarrick J. Wong 	if (time_before(local_jiffies, data->sensors_last_updated +
2206f9703d0SDarrick J. Wong 		SENSOR_REFRESH_INTERVAL)
2216f9703d0SDarrick J. Wong 		&& data->sensors_valid)
2226f9703d0SDarrick J. Wong 		goto no_sensor_update;
2236f9703d0SDarrick J. Wong 
2246f9703d0SDarrick J. Wong 	/* start reading temperature sensors */
2256f9703d0SDarrick J. Wong 	cfg = i2c_smbus_read_byte_data(client, ADT7470_REG_CFG);
2266f9703d0SDarrick J. Wong 	cfg |= 0x80;
2276f9703d0SDarrick J. Wong 	i2c_smbus_write_byte_data(client, ADT7470_REG_CFG, cfg);
2286f9703d0SDarrick J. Wong 
2296f9703d0SDarrick J. Wong 	/*
2306f9703d0SDarrick J. Wong 	 * Delay is 200ms * number of tmp05 sensors.  Too bad
2316f9703d0SDarrick J. Wong 	 * there's no way to figure out how many are connected.
2326f9703d0SDarrick J. Wong 	 * For now, assume 1s will work.
2336f9703d0SDarrick J. Wong 	 */
2346f9703d0SDarrick J. Wong 	msleep(TEMP_COLLECTION_TIME);
2356f9703d0SDarrick J. Wong 
2366f9703d0SDarrick J. Wong 	/* done reading temperature sensors */
2376f9703d0SDarrick J. Wong 	cfg = i2c_smbus_read_byte_data(client, ADT7470_REG_CFG);
2386f9703d0SDarrick J. Wong 	cfg &= ~0x80;
2396f9703d0SDarrick J. Wong 	i2c_smbus_write_byte_data(client, ADT7470_REG_CFG, cfg);
2406f9703d0SDarrick J. Wong 
2416f9703d0SDarrick J. Wong 	for (i = 0; i < ADT7470_TEMP_COUNT; i++)
2426f9703d0SDarrick J. Wong 		data->temp[i] = i2c_smbus_read_byte_data(client,
2436f9703d0SDarrick J. Wong 						ADT7470_TEMP_REG(i));
2446f9703d0SDarrick J. Wong 
2456f9703d0SDarrick J. Wong 	for (i = 0; i < ADT7470_FAN_COUNT; i++)
2466f9703d0SDarrick J. Wong 		data->fan[i] = adt7470_read_word_data(client,
2476f9703d0SDarrick J. Wong 						ADT7470_REG_FAN(i));
2486f9703d0SDarrick J. Wong 
2496f9703d0SDarrick J. Wong 	for (i = 0; i < ADT7470_PWM_COUNT; i++) {
2506f9703d0SDarrick J. Wong 		int reg;
2516f9703d0SDarrick J. Wong 		int reg_mask;
2526f9703d0SDarrick J. Wong 
2536f9703d0SDarrick J. Wong 		data->pwm[i] = i2c_smbus_read_byte_data(client,
2546f9703d0SDarrick J. Wong 						ADT7470_REG_PWM(i));
2556f9703d0SDarrick J. Wong 
2566f9703d0SDarrick J. Wong 		if (i % 2)
2576f9703d0SDarrick J. Wong 			reg_mask = ADT7470_PWM2_AUTO_MASK;
2586f9703d0SDarrick J. Wong 		else
2596f9703d0SDarrick J. Wong 			reg_mask = ADT7470_PWM1_AUTO_MASK;
2606f9703d0SDarrick J. Wong 
2616f9703d0SDarrick J. Wong 		reg = ADT7470_REG_PWM_CFG(i);
2626f9703d0SDarrick J. Wong 		if (i2c_smbus_read_byte_data(client, reg) & reg_mask)
2636f9703d0SDarrick J. Wong 			data->pwm_automatic[i] = 1;
2646f9703d0SDarrick J. Wong 		else
2656f9703d0SDarrick J. Wong 			data->pwm_automatic[i] = 0;
2666f9703d0SDarrick J. Wong 
2676f9703d0SDarrick J. Wong 		reg = ADT7470_REG_PWM_AUTO_TEMP(i);
2686f9703d0SDarrick J. Wong 		cfg = i2c_smbus_read_byte_data(client, reg);
2696f9703d0SDarrick J. Wong 		if (!(i % 2))
2706f9703d0SDarrick J. Wong 			data->pwm_auto_temp[i] = cfg >> 4;
2716f9703d0SDarrick J. Wong 		else
2726f9703d0SDarrick J. Wong 			data->pwm_auto_temp[i] = cfg & 0xF;
2736f9703d0SDarrick J. Wong 	}
2746f9703d0SDarrick J. Wong 
2756f9703d0SDarrick J. Wong 	if (i2c_smbus_read_byte_data(client, ADT7470_REG_CFG) &
2766f9703d0SDarrick J. Wong 	    ADT7470_FSPD_MASK)
2776f9703d0SDarrick J. Wong 		data->force_pwm_max = 1;
2786f9703d0SDarrick J. Wong 	else
2796f9703d0SDarrick J. Wong 		data->force_pwm_max = 0;
2806f9703d0SDarrick J. Wong 
281*fe03f28cSDarrick J. Wong 	data->alarm = i2c_smbus_read_byte_data(client, ADT7470_REG_ALARM1);
282*fe03f28cSDarrick J. Wong 	if (data->alarm & ADT7470_OOL_ALARM)
283*fe03f28cSDarrick J. Wong 		data->alarm |= ALARM2(i2c_smbus_read_byte_data(client,
284*fe03f28cSDarrick J. Wong 							ADT7470_REG_ALARM2));
2856f9703d0SDarrick J. Wong 	data->alarms_mask = adt7470_read_word_data(client,
2866f9703d0SDarrick J. Wong 						   ADT7470_REG_ALARM1_MASK);
2876f9703d0SDarrick J. Wong 
2886f9703d0SDarrick J. Wong 	data->sensors_last_updated = local_jiffies;
2896f9703d0SDarrick J. Wong 	data->sensors_valid = 1;
2906f9703d0SDarrick J. Wong 
2916f9703d0SDarrick J. Wong no_sensor_update:
2926f9703d0SDarrick J. Wong 	if (time_before(local_jiffies, data->limits_last_updated +
2936f9703d0SDarrick J. Wong 		LIMIT_REFRESH_INTERVAL)
2946f9703d0SDarrick J. Wong 		&& data->limits_valid)
2956f9703d0SDarrick J. Wong 		goto out;
2966f9703d0SDarrick J. Wong 
2976f9703d0SDarrick J. Wong 	for (i = 0; i < ADT7470_TEMP_COUNT; i++) {
2986f9703d0SDarrick J. Wong 		data->temp_min[i] = i2c_smbus_read_byte_data(client,
2996f9703d0SDarrick J. Wong 						ADT7470_TEMP_MIN_REG(i));
3006f9703d0SDarrick J. Wong 		data->temp_max[i] = i2c_smbus_read_byte_data(client,
3016f9703d0SDarrick J. Wong 						ADT7470_TEMP_MAX_REG(i));
3026f9703d0SDarrick J. Wong 	}
3036f9703d0SDarrick J. Wong 
3046f9703d0SDarrick J. Wong 	for (i = 0; i < ADT7470_FAN_COUNT; i++) {
3056f9703d0SDarrick J. Wong 		data->fan_min[i] = adt7470_read_word_data(client,
3066f9703d0SDarrick J. Wong 						ADT7470_REG_FAN_MIN(i));
3076f9703d0SDarrick J. Wong 		data->fan_max[i] = adt7470_read_word_data(client,
3086f9703d0SDarrick J. Wong 						ADT7470_REG_FAN_MAX(i));
3096f9703d0SDarrick J. Wong 	}
3106f9703d0SDarrick J. Wong 
3116f9703d0SDarrick J. Wong 	for (i = 0; i < ADT7470_PWM_COUNT; i++) {
3126f9703d0SDarrick J. Wong 		data->pwm_max[i] = i2c_smbus_read_byte_data(client,
3136f9703d0SDarrick J. Wong 						ADT7470_REG_PWM_MAX(i));
3146f9703d0SDarrick J. Wong 		data->pwm_min[i] = i2c_smbus_read_byte_data(client,
3156f9703d0SDarrick J. Wong 						ADT7470_REG_PWM_MIN(i));
3166f9703d0SDarrick J. Wong 		data->pwm_tmin[i] = i2c_smbus_read_byte_data(client,
3176f9703d0SDarrick J. Wong 						ADT7470_REG_PWM_TMIN(i));
3186f9703d0SDarrick J. Wong 	}
3196f9703d0SDarrick J. Wong 
3206f9703d0SDarrick J. Wong 	data->limits_last_updated = local_jiffies;
3216f9703d0SDarrick J. Wong 	data->limits_valid = 1;
3226f9703d0SDarrick J. Wong 
3236f9703d0SDarrick J. Wong out:
3246f9703d0SDarrick J. Wong 	mutex_unlock(&data->lock);
3256f9703d0SDarrick J. Wong 	return data;
3266f9703d0SDarrick J. Wong }
3276f9703d0SDarrick J. Wong 
3286f9703d0SDarrick J. Wong static ssize_t show_temp_min(struct device *dev,
3296f9703d0SDarrick J. Wong 			     struct device_attribute *devattr,
3306f9703d0SDarrick J. Wong 			     char *buf)
3316f9703d0SDarrick J. Wong {
3326f9703d0SDarrick J. Wong 	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
3336f9703d0SDarrick J. Wong 	struct adt7470_data *data = adt7470_update_device(dev);
3346f9703d0SDarrick J. Wong 	return sprintf(buf, "%d\n", 1000 * data->temp_min[attr->index]);
3356f9703d0SDarrick J. Wong }
3366f9703d0SDarrick J. Wong 
3376f9703d0SDarrick J. Wong static ssize_t set_temp_min(struct device *dev,
3386f9703d0SDarrick J. Wong 			    struct device_attribute *devattr,
3396f9703d0SDarrick J. Wong 			    const char *buf,
3406f9703d0SDarrick J. Wong 			    size_t count)
3416f9703d0SDarrick J. Wong {
3426f9703d0SDarrick J. Wong 	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
3436f9703d0SDarrick J. Wong 	struct i2c_client *client = to_i2c_client(dev);
3446f9703d0SDarrick J. Wong 	struct adt7470_data *data = i2c_get_clientdata(client);
3456f9703d0SDarrick J. Wong 	int temp = simple_strtol(buf, NULL, 10) / 1000;
3466f9703d0SDarrick J. Wong 
3476f9703d0SDarrick J. Wong 	mutex_lock(&data->lock);
3486f9703d0SDarrick J. Wong 	data->temp_min[attr->index] = temp;
3496f9703d0SDarrick J. Wong 	i2c_smbus_write_byte_data(client, ADT7470_TEMP_MIN_REG(attr->index),
3506f9703d0SDarrick J. Wong 				  temp);
3516f9703d0SDarrick J. Wong 	mutex_unlock(&data->lock);
3526f9703d0SDarrick J. Wong 
3536f9703d0SDarrick J. Wong 	return count;
3546f9703d0SDarrick J. Wong }
3556f9703d0SDarrick J. Wong 
3566f9703d0SDarrick J. Wong static ssize_t show_temp_max(struct device *dev,
3576f9703d0SDarrick J. Wong 			     struct device_attribute *devattr,
3586f9703d0SDarrick J. Wong 			     char *buf)
3596f9703d0SDarrick J. Wong {
3606f9703d0SDarrick J. Wong 	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
3616f9703d0SDarrick J. Wong 	struct adt7470_data *data = adt7470_update_device(dev);
3626f9703d0SDarrick J. Wong 	return sprintf(buf, "%d\n", 1000 * data->temp_max[attr->index]);
3636f9703d0SDarrick J. Wong }
3646f9703d0SDarrick J. Wong 
3656f9703d0SDarrick J. Wong static ssize_t set_temp_max(struct device *dev,
3666f9703d0SDarrick J. Wong 			    struct device_attribute *devattr,
3676f9703d0SDarrick J. Wong 			    const char *buf,
3686f9703d0SDarrick J. Wong 			    size_t count)
3696f9703d0SDarrick J. Wong {
3706f9703d0SDarrick J. Wong 	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
3716f9703d0SDarrick J. Wong 	struct i2c_client *client = to_i2c_client(dev);
3726f9703d0SDarrick J. Wong 	struct adt7470_data *data = i2c_get_clientdata(client);
3736f9703d0SDarrick J. Wong 	int temp = simple_strtol(buf, NULL, 10) / 1000;
3746f9703d0SDarrick J. Wong 
3756f9703d0SDarrick J. Wong 	mutex_lock(&data->lock);
3766f9703d0SDarrick J. Wong 	data->temp_max[attr->index] = temp;
3776f9703d0SDarrick J. Wong 	i2c_smbus_write_byte_data(client, ADT7470_TEMP_MAX_REG(attr->index),
3786f9703d0SDarrick J. Wong 				  temp);
3796f9703d0SDarrick J. Wong 	mutex_unlock(&data->lock);
3806f9703d0SDarrick J. Wong 
3816f9703d0SDarrick J. Wong 	return count;
3826f9703d0SDarrick J. Wong }
3836f9703d0SDarrick J. Wong 
3846f9703d0SDarrick J. Wong static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
3856f9703d0SDarrick J. Wong 			 char *buf)
3866f9703d0SDarrick J. Wong {
3876f9703d0SDarrick J. Wong 	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
3886f9703d0SDarrick J. Wong 	struct adt7470_data *data = adt7470_update_device(dev);
3896f9703d0SDarrick J. Wong 	return sprintf(buf, "%d\n", 1000 * data->temp[attr->index]);
3906f9703d0SDarrick J. Wong }
3916f9703d0SDarrick J. Wong 
392*fe03f28cSDarrick J. Wong static ssize_t show_alarm_mask(struct device *dev,
3936f9703d0SDarrick J. Wong 			   struct device_attribute *devattr,
3946f9703d0SDarrick J. Wong 			   char *buf)
3956f9703d0SDarrick J. Wong {
3966f9703d0SDarrick J. Wong 	struct adt7470_data *data = adt7470_update_device(dev);
3976f9703d0SDarrick J. Wong 
3986f9703d0SDarrick J. Wong 	return sprintf(buf, "%x\n", data->alarms_mask);
3996f9703d0SDarrick J. Wong }
4006f9703d0SDarrick J. Wong 
4016f9703d0SDarrick J. Wong static ssize_t show_fan_max(struct device *dev,
4026f9703d0SDarrick J. Wong 			    struct device_attribute *devattr,
4036f9703d0SDarrick J. Wong 			    char *buf)
4046f9703d0SDarrick J. Wong {
4056f9703d0SDarrick J. Wong 	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
4066f9703d0SDarrick J. Wong 	struct adt7470_data *data = adt7470_update_device(dev);
4076f9703d0SDarrick J. Wong 
4086f9703d0SDarrick J. Wong 	if (FAN_DATA_VALID(data->fan_max[attr->index]))
4096f9703d0SDarrick J. Wong 		return sprintf(buf, "%d\n",
4106f9703d0SDarrick J. Wong 			       FAN_PERIOD_TO_RPM(data->fan_max[attr->index]));
4116f9703d0SDarrick J. Wong 	else
4126f9703d0SDarrick J. Wong 		return sprintf(buf, "0\n");
4136f9703d0SDarrick J. Wong }
4146f9703d0SDarrick J. Wong 
4156f9703d0SDarrick J. Wong static ssize_t set_fan_max(struct device *dev,
4166f9703d0SDarrick J. Wong 			   struct device_attribute *devattr,
4176f9703d0SDarrick J. Wong 			   const char *buf, size_t count)
4186f9703d0SDarrick J. Wong {
4196f9703d0SDarrick J. Wong 	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
4206f9703d0SDarrick J. Wong 	struct i2c_client *client = to_i2c_client(dev);
4216f9703d0SDarrick J. Wong 	struct adt7470_data *data = i2c_get_clientdata(client);
4226f9703d0SDarrick J. Wong 	int temp = simple_strtol(buf, NULL, 10);
4236f9703d0SDarrick J. Wong 
4246f9703d0SDarrick J. Wong 	if (!temp)
4256f9703d0SDarrick J. Wong 		return -EINVAL;
4266f9703d0SDarrick J. Wong 	temp = FAN_RPM_TO_PERIOD(temp);
4276f9703d0SDarrick J. Wong 
4286f9703d0SDarrick J. Wong 	mutex_lock(&data->lock);
4296f9703d0SDarrick J. Wong 	data->fan_max[attr->index] = temp;
4306f9703d0SDarrick J. Wong 	adt7470_write_word_data(client, ADT7470_REG_FAN_MAX(attr->index), temp);
4316f9703d0SDarrick J. Wong 	mutex_unlock(&data->lock);
4326f9703d0SDarrick J. Wong 
4336f9703d0SDarrick J. Wong 	return count;
4346f9703d0SDarrick J. Wong }
4356f9703d0SDarrick J. Wong 
4366f9703d0SDarrick J. Wong static ssize_t show_fan_min(struct device *dev,
4376f9703d0SDarrick J. Wong 			    struct device_attribute *devattr,
4386f9703d0SDarrick J. Wong 			    char *buf)
4396f9703d0SDarrick J. Wong {
4406f9703d0SDarrick J. Wong 	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
4416f9703d0SDarrick J. Wong 	struct adt7470_data *data = adt7470_update_device(dev);
4426f9703d0SDarrick J. Wong 
4436f9703d0SDarrick J. Wong 	if (FAN_DATA_VALID(data->fan_min[attr->index]))
4446f9703d0SDarrick J. Wong 		return sprintf(buf, "%d\n",
4456f9703d0SDarrick J. Wong 			       FAN_PERIOD_TO_RPM(data->fan_min[attr->index]));
4466f9703d0SDarrick J. Wong 	else
4476f9703d0SDarrick J. Wong 		return sprintf(buf, "0\n");
4486f9703d0SDarrick J. Wong }
4496f9703d0SDarrick J. Wong 
4506f9703d0SDarrick J. Wong static ssize_t set_fan_min(struct device *dev,
4516f9703d0SDarrick J. Wong 			   struct device_attribute *devattr,
4526f9703d0SDarrick J. Wong 			   const char *buf, size_t count)
4536f9703d0SDarrick J. Wong {
4546f9703d0SDarrick J. Wong 	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
4556f9703d0SDarrick J. Wong 	struct i2c_client *client = to_i2c_client(dev);
4566f9703d0SDarrick J. Wong 	struct adt7470_data *data = i2c_get_clientdata(client);
4576f9703d0SDarrick J. Wong 	int temp = simple_strtol(buf, NULL, 10);
4586f9703d0SDarrick J. Wong 
4596f9703d0SDarrick J. Wong 	if (!temp)
4606f9703d0SDarrick J. Wong 		return -EINVAL;
4616f9703d0SDarrick J. Wong 	temp = FAN_RPM_TO_PERIOD(temp);
4626f9703d0SDarrick J. Wong 
4636f9703d0SDarrick J. Wong 	mutex_lock(&data->lock);
4646f9703d0SDarrick J. Wong 	data->fan_min[attr->index] = temp;
4656f9703d0SDarrick J. Wong 	adt7470_write_word_data(client, ADT7470_REG_FAN_MIN(attr->index), temp);
4666f9703d0SDarrick J. Wong 	mutex_unlock(&data->lock);
4676f9703d0SDarrick J. Wong 
4686f9703d0SDarrick J. Wong 	return count;
4696f9703d0SDarrick J. Wong }
4706f9703d0SDarrick J. Wong 
4716f9703d0SDarrick J. Wong static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
4726f9703d0SDarrick J. Wong 			char *buf)
4736f9703d0SDarrick J. Wong {
4746f9703d0SDarrick J. Wong 	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
4756f9703d0SDarrick J. Wong 	struct adt7470_data *data = adt7470_update_device(dev);
4766f9703d0SDarrick J. Wong 
4776f9703d0SDarrick J. Wong 	if (FAN_DATA_VALID(data->fan[attr->index]))
4786f9703d0SDarrick J. Wong 		return sprintf(buf, "%d\n",
4796f9703d0SDarrick J. Wong 			       FAN_PERIOD_TO_RPM(data->fan[attr->index]));
4806f9703d0SDarrick J. Wong 	else
4816f9703d0SDarrick J. Wong 		return sprintf(buf, "0\n");
4826f9703d0SDarrick J. Wong }
4836f9703d0SDarrick J. Wong 
4846f9703d0SDarrick J. Wong static ssize_t show_force_pwm_max(struct device *dev,
4856f9703d0SDarrick J. Wong 				  struct device_attribute *devattr,
4866f9703d0SDarrick J. Wong 				  char *buf)
4876f9703d0SDarrick J. Wong {
4886f9703d0SDarrick J. Wong 	struct adt7470_data *data = adt7470_update_device(dev);
4896f9703d0SDarrick J. Wong 	return sprintf(buf, "%d\n", data->force_pwm_max);
4906f9703d0SDarrick J. Wong }
4916f9703d0SDarrick J. Wong 
4926f9703d0SDarrick J. Wong static ssize_t set_force_pwm_max(struct device *dev,
4936f9703d0SDarrick J. Wong 				 struct device_attribute *devattr,
4946f9703d0SDarrick J. Wong 				 const char *buf,
4956f9703d0SDarrick J. Wong 				 size_t count)
4966f9703d0SDarrick J. Wong {
4976f9703d0SDarrick J. Wong 	struct i2c_client *client = to_i2c_client(dev);
4986f9703d0SDarrick J. Wong 	struct adt7470_data *data = i2c_get_clientdata(client);
4996f9703d0SDarrick J. Wong 	int temp = simple_strtol(buf, NULL, 10);
5006f9703d0SDarrick J. Wong 	u8 reg;
5016f9703d0SDarrick J. Wong 
5026f9703d0SDarrick J. Wong 	mutex_lock(&data->lock);
5036f9703d0SDarrick J. Wong 	data->force_pwm_max = temp;
5046f9703d0SDarrick J. Wong 	reg = i2c_smbus_read_byte_data(client, ADT7470_REG_CFG);
5056f9703d0SDarrick J. Wong 	if (temp)
5066f9703d0SDarrick J. Wong 		reg |= ADT7470_FSPD_MASK;
5076f9703d0SDarrick J. Wong 	else
5086f9703d0SDarrick J. Wong 		reg &= ~ADT7470_FSPD_MASK;
5096f9703d0SDarrick J. Wong 	i2c_smbus_write_byte_data(client, ADT7470_REG_CFG, reg);
5106f9703d0SDarrick J. Wong 	mutex_unlock(&data->lock);
5116f9703d0SDarrick J. Wong 
5126f9703d0SDarrick J. Wong 	return count;
5136f9703d0SDarrick J. Wong }
5146f9703d0SDarrick J. Wong 
5156f9703d0SDarrick J. Wong static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr,
5166f9703d0SDarrick J. Wong 			char *buf)
5176f9703d0SDarrick J. Wong {
5186f9703d0SDarrick J. Wong 	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
5196f9703d0SDarrick J. Wong 	struct adt7470_data *data = adt7470_update_device(dev);
5206f9703d0SDarrick J. Wong 	return sprintf(buf, "%d\n", data->pwm[attr->index]);
5216f9703d0SDarrick J. Wong }
5226f9703d0SDarrick J. Wong 
5236f9703d0SDarrick J. Wong static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr,
5246f9703d0SDarrick J. Wong 			const char *buf, size_t count)
5256f9703d0SDarrick J. Wong {
5266f9703d0SDarrick J. Wong 	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
5276f9703d0SDarrick J. Wong 	struct i2c_client *client = to_i2c_client(dev);
5286f9703d0SDarrick J. Wong 	struct adt7470_data *data = i2c_get_clientdata(client);
5296f9703d0SDarrick J. Wong 	int temp = simple_strtol(buf, NULL, 10);
5306f9703d0SDarrick J. Wong 
5316f9703d0SDarrick J. Wong 	mutex_lock(&data->lock);
5326f9703d0SDarrick J. Wong 	data->pwm[attr->index] = temp;
5336f9703d0SDarrick J. Wong 	i2c_smbus_write_byte_data(client, ADT7470_REG_PWM(attr->index), temp);
5346f9703d0SDarrick J. Wong 	mutex_unlock(&data->lock);
5356f9703d0SDarrick J. Wong 
5366f9703d0SDarrick J. Wong 	return count;
5376f9703d0SDarrick J. Wong }
5386f9703d0SDarrick J. Wong 
5396f9703d0SDarrick J. Wong static ssize_t show_pwm_max(struct device *dev,
5406f9703d0SDarrick J. Wong 			    struct device_attribute *devattr,
5416f9703d0SDarrick J. Wong 			    char *buf)
5426f9703d0SDarrick J. Wong {
5436f9703d0SDarrick J. Wong 	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
5446f9703d0SDarrick J. Wong 	struct adt7470_data *data = adt7470_update_device(dev);
5456f9703d0SDarrick J. Wong 	return sprintf(buf, "%d\n", data->pwm_max[attr->index]);
5466f9703d0SDarrick J. Wong }
5476f9703d0SDarrick J. Wong 
5486f9703d0SDarrick J. Wong static ssize_t set_pwm_max(struct device *dev,
5496f9703d0SDarrick J. Wong 			   struct device_attribute *devattr,
5506f9703d0SDarrick J. Wong 			   const char *buf,
5516f9703d0SDarrick J. Wong 			   size_t count)
5526f9703d0SDarrick J. Wong {
5536f9703d0SDarrick J. Wong 	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
5546f9703d0SDarrick J. Wong 	struct i2c_client *client = to_i2c_client(dev);
5556f9703d0SDarrick J. Wong 	struct adt7470_data *data = i2c_get_clientdata(client);
5566f9703d0SDarrick J. Wong 	int temp = simple_strtol(buf, NULL, 10);
5576f9703d0SDarrick J. Wong 
5586f9703d0SDarrick J. Wong 	mutex_lock(&data->lock);
5596f9703d0SDarrick J. Wong 	data->pwm_max[attr->index] = temp;
5606f9703d0SDarrick J. Wong 	i2c_smbus_write_byte_data(client, ADT7470_REG_PWM_MAX(attr->index),
5616f9703d0SDarrick J. Wong 				  temp);
5626f9703d0SDarrick J. Wong 	mutex_unlock(&data->lock);
5636f9703d0SDarrick J. Wong 
5646f9703d0SDarrick J. Wong 	return count;
5656f9703d0SDarrick J. Wong }
5666f9703d0SDarrick J. Wong 
5676f9703d0SDarrick J. Wong static ssize_t show_pwm_min(struct device *dev,
5686f9703d0SDarrick J. Wong 			    struct device_attribute *devattr,
5696f9703d0SDarrick J. Wong 			    char *buf)
5706f9703d0SDarrick J. Wong {
5716f9703d0SDarrick J. Wong 	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
5726f9703d0SDarrick J. Wong 	struct adt7470_data *data = adt7470_update_device(dev);
5736f9703d0SDarrick J. Wong 	return sprintf(buf, "%d\n", data->pwm_min[attr->index]);
5746f9703d0SDarrick J. Wong }
5756f9703d0SDarrick J. Wong 
5766f9703d0SDarrick J. Wong static ssize_t set_pwm_min(struct device *dev,
5776f9703d0SDarrick J. Wong 			   struct device_attribute *devattr,
5786f9703d0SDarrick J. Wong 			   const char *buf,
5796f9703d0SDarrick J. Wong 			   size_t count)
5806f9703d0SDarrick J. Wong {
5816f9703d0SDarrick J. Wong 	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
5826f9703d0SDarrick J. Wong 	struct i2c_client *client = to_i2c_client(dev);
5836f9703d0SDarrick J. Wong 	struct adt7470_data *data = i2c_get_clientdata(client);
5846f9703d0SDarrick J. Wong 	int temp = simple_strtol(buf, NULL, 10);
5856f9703d0SDarrick J. Wong 
5866f9703d0SDarrick J. Wong 	mutex_lock(&data->lock);
5876f9703d0SDarrick J. Wong 	data->pwm_min[attr->index] = temp;
5886f9703d0SDarrick J. Wong 	i2c_smbus_write_byte_data(client, ADT7470_REG_PWM_MIN(attr->index),
5896f9703d0SDarrick J. Wong 				  temp);
5906f9703d0SDarrick J. Wong 	mutex_unlock(&data->lock);
5916f9703d0SDarrick J. Wong 
5926f9703d0SDarrick J. Wong 	return count;
5936f9703d0SDarrick J. Wong }
5946f9703d0SDarrick J. Wong 
5956f9703d0SDarrick J. Wong static ssize_t show_pwm_tmax(struct device *dev,
5966f9703d0SDarrick J. Wong 			     struct device_attribute *devattr,
5976f9703d0SDarrick J. Wong 			     char *buf)
5986f9703d0SDarrick J. Wong {
5996f9703d0SDarrick J. Wong 	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
6006f9703d0SDarrick J. Wong 	struct adt7470_data *data = adt7470_update_device(dev);
6016f9703d0SDarrick J. Wong 	/* the datasheet says that tmax = tmin + 20C */
6026f9703d0SDarrick J. Wong 	return sprintf(buf, "%d\n", 1000 * (20 + data->pwm_tmin[attr->index]));
6036f9703d0SDarrick J. Wong }
6046f9703d0SDarrick J. Wong 
6056f9703d0SDarrick J. Wong static ssize_t show_pwm_tmin(struct device *dev,
6066f9703d0SDarrick J. Wong 			     struct device_attribute *devattr,
6076f9703d0SDarrick J. Wong 			     char *buf)
6086f9703d0SDarrick J. Wong {
6096f9703d0SDarrick J. Wong 	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
6106f9703d0SDarrick J. Wong 	struct adt7470_data *data = adt7470_update_device(dev);
6116f9703d0SDarrick J. Wong 	return sprintf(buf, "%d\n", 1000 * data->pwm_tmin[attr->index]);
6126f9703d0SDarrick J. Wong }
6136f9703d0SDarrick J. Wong 
6146f9703d0SDarrick J. Wong static ssize_t set_pwm_tmin(struct device *dev,
6156f9703d0SDarrick J. Wong 			    struct device_attribute *devattr,
6166f9703d0SDarrick J. Wong 			    const char *buf,
6176f9703d0SDarrick J. Wong 			    size_t count)
6186f9703d0SDarrick J. Wong {
6196f9703d0SDarrick J. Wong 	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
6206f9703d0SDarrick J. Wong 	struct i2c_client *client = to_i2c_client(dev);
6216f9703d0SDarrick J. Wong 	struct adt7470_data *data = i2c_get_clientdata(client);
6226f9703d0SDarrick J. Wong 	int temp = simple_strtol(buf, NULL, 10) / 1000;
6236f9703d0SDarrick J. Wong 
6246f9703d0SDarrick J. Wong 	mutex_lock(&data->lock);
6256f9703d0SDarrick J. Wong 	data->pwm_tmin[attr->index] = temp;
6266f9703d0SDarrick J. Wong 	i2c_smbus_write_byte_data(client, ADT7470_REG_PWM_TMIN(attr->index),
6276f9703d0SDarrick J. Wong 				  temp);
6286f9703d0SDarrick J. Wong 	mutex_unlock(&data->lock);
6296f9703d0SDarrick J. Wong 
6306f9703d0SDarrick J. Wong 	return count;
6316f9703d0SDarrick J. Wong }
6326f9703d0SDarrick J. Wong 
6336f9703d0SDarrick J. Wong static ssize_t show_pwm_auto(struct device *dev,
6346f9703d0SDarrick J. Wong 			     struct device_attribute *devattr,
6356f9703d0SDarrick J. Wong 			     char *buf)
6366f9703d0SDarrick J. Wong {
6376f9703d0SDarrick J. Wong 	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
6386f9703d0SDarrick J. Wong 	struct adt7470_data *data = adt7470_update_device(dev);
6396f9703d0SDarrick J. Wong 	return sprintf(buf, "%d\n", 1 + data->pwm_automatic[attr->index]);
6406f9703d0SDarrick J. Wong }
6416f9703d0SDarrick J. Wong 
6426f9703d0SDarrick J. Wong static ssize_t set_pwm_auto(struct device *dev,
6436f9703d0SDarrick J. Wong 			    struct device_attribute *devattr,
6446f9703d0SDarrick J. Wong 			    const char *buf,
6456f9703d0SDarrick J. Wong 			    size_t count)
6466f9703d0SDarrick J. Wong {
6476f9703d0SDarrick J. Wong 	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
6486f9703d0SDarrick J. Wong 	struct i2c_client *client = to_i2c_client(dev);
6496f9703d0SDarrick J. Wong 	struct adt7470_data *data = i2c_get_clientdata(client);
6506f9703d0SDarrick J. Wong 	int temp = simple_strtol(buf, NULL, 10);
6516f9703d0SDarrick J. Wong 	int pwm_auto_reg = ADT7470_REG_PWM_CFG(attr->index);
6526f9703d0SDarrick J. Wong 	int pwm_auto_reg_mask;
6536f9703d0SDarrick J. Wong 	u8 reg;
6546f9703d0SDarrick J. Wong 
6556f9703d0SDarrick J. Wong 	if (attr->index % 2)
6566f9703d0SDarrick J. Wong 		pwm_auto_reg_mask = ADT7470_PWM2_AUTO_MASK;
6576f9703d0SDarrick J. Wong 	else
6586f9703d0SDarrick J. Wong 		pwm_auto_reg_mask = ADT7470_PWM1_AUTO_MASK;
6596f9703d0SDarrick J. Wong 
6606f9703d0SDarrick J. Wong 	if (temp != 2 && temp != 1)
6616f9703d0SDarrick J. Wong 		return -EINVAL;
6626f9703d0SDarrick J. Wong 	temp--;
6636f9703d0SDarrick J. Wong 
6646f9703d0SDarrick J. Wong 	mutex_lock(&data->lock);
6656f9703d0SDarrick J. Wong 	data->pwm_automatic[attr->index] = temp;
6666f9703d0SDarrick J. Wong 	reg = i2c_smbus_read_byte_data(client, pwm_auto_reg);
6676f9703d0SDarrick J. Wong 	if (temp)
6686f9703d0SDarrick J. Wong 		reg |= pwm_auto_reg_mask;
6696f9703d0SDarrick J. Wong 	else
6706f9703d0SDarrick J. Wong 		reg &= ~pwm_auto_reg_mask;
6716f9703d0SDarrick J. Wong 	i2c_smbus_write_byte_data(client, pwm_auto_reg, reg);
6726f9703d0SDarrick J. Wong 	mutex_unlock(&data->lock);
6736f9703d0SDarrick J. Wong 
6746f9703d0SDarrick J. Wong 	return count;
6756f9703d0SDarrick J. Wong }
6766f9703d0SDarrick J. Wong 
6776f9703d0SDarrick J. Wong static ssize_t show_pwm_auto_temp(struct device *dev,
6786f9703d0SDarrick J. Wong 				  struct device_attribute *devattr,
6796f9703d0SDarrick J. Wong 				  char *buf)
6806f9703d0SDarrick J. Wong {
6816f9703d0SDarrick J. Wong 	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
6826f9703d0SDarrick J. Wong 	struct adt7470_data *data = adt7470_update_device(dev);
6836f9703d0SDarrick J. Wong 	u8 ctrl = data->pwm_auto_temp[attr->index];
6846f9703d0SDarrick J. Wong 
6856f9703d0SDarrick J. Wong 	if (ctrl)
6866f9703d0SDarrick J. Wong 		return sprintf(buf, "%d\n", 1 << (ctrl - 1));
6876f9703d0SDarrick J. Wong 	else
6886f9703d0SDarrick J. Wong 		return sprintf(buf, "%d\n", ADT7470_PWM_ALL_TEMPS);
6896f9703d0SDarrick J. Wong }
6906f9703d0SDarrick J. Wong 
6916f9703d0SDarrick J. Wong static int cvt_auto_temp(int input)
6926f9703d0SDarrick J. Wong {
6936f9703d0SDarrick J. Wong 	if (input == ADT7470_PWM_ALL_TEMPS)
6946f9703d0SDarrick J. Wong 		return 0;
695ce9c2f44SRobert P. J. Day 	if (input < 1 || !is_power_of_2(input))
6966f9703d0SDarrick J. Wong 		return -EINVAL;
6976f9703d0SDarrick J. Wong 	return ilog2(input) + 1;
6986f9703d0SDarrick J. Wong }
6996f9703d0SDarrick J. Wong 
7006f9703d0SDarrick J. Wong static ssize_t set_pwm_auto_temp(struct device *dev,
7016f9703d0SDarrick J. Wong 				 struct device_attribute *devattr,
7026f9703d0SDarrick J. Wong 				 const char *buf,
7036f9703d0SDarrick J. Wong 				 size_t count)
7046f9703d0SDarrick J. Wong {
7056f9703d0SDarrick J. Wong 	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
7066f9703d0SDarrick J. Wong 	struct i2c_client *client = to_i2c_client(dev);
7076f9703d0SDarrick J. Wong 	struct adt7470_data *data = i2c_get_clientdata(client);
7086f9703d0SDarrick J. Wong 	int temp = cvt_auto_temp(simple_strtol(buf, NULL, 10));
7096f9703d0SDarrick J. Wong 	int pwm_auto_reg = ADT7470_REG_PWM_AUTO_TEMP(attr->index);
7106f9703d0SDarrick J. Wong 	u8 reg;
7116f9703d0SDarrick J. Wong 
7126f9703d0SDarrick J. Wong 	if (temp < 0)
7136f9703d0SDarrick J. Wong 		return temp;
7146f9703d0SDarrick J. Wong 
7156f9703d0SDarrick J. Wong 	mutex_lock(&data->lock);
7166f9703d0SDarrick J. Wong 	data->pwm_automatic[attr->index] = temp;
7176f9703d0SDarrick J. Wong 	reg = i2c_smbus_read_byte_data(client, pwm_auto_reg);
7186f9703d0SDarrick J. Wong 
7196f9703d0SDarrick J. Wong 	if (!(attr->index % 2)) {
7206f9703d0SDarrick J. Wong 		reg &= 0xF;
7216f9703d0SDarrick J. Wong 		reg |= (temp << 4) & 0xF0;
7226f9703d0SDarrick J. Wong 	} else {
7236f9703d0SDarrick J. Wong 		reg &= 0xF0;
7246f9703d0SDarrick J. Wong 		reg |= temp & 0xF;
7256f9703d0SDarrick J. Wong 	}
7266f9703d0SDarrick J. Wong 
7276f9703d0SDarrick J. Wong 	i2c_smbus_write_byte_data(client, pwm_auto_reg, reg);
7286f9703d0SDarrick J. Wong 	mutex_unlock(&data->lock);
7296f9703d0SDarrick J. Wong 
7306f9703d0SDarrick J. Wong 	return count;
7316f9703d0SDarrick J. Wong }
7326f9703d0SDarrick J. Wong 
733*fe03f28cSDarrick J. Wong static ssize_t show_alarm(struct device *dev,
734*fe03f28cSDarrick J. Wong 			  struct device_attribute *devattr,
735*fe03f28cSDarrick J. Wong 			  char *buf)
736*fe03f28cSDarrick J. Wong {
737*fe03f28cSDarrick J. Wong 	struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
738*fe03f28cSDarrick J. Wong 	struct adt7470_data *data = adt7470_update_device(dev);
739*fe03f28cSDarrick J. Wong 
740*fe03f28cSDarrick J. Wong 	if (data->alarm & attr->index)
741*fe03f28cSDarrick J. Wong 		return sprintf(buf, "1\n");
742*fe03f28cSDarrick J. Wong 	else
743*fe03f28cSDarrick J. Wong 		return sprintf(buf, "0\n");
744*fe03f28cSDarrick J. Wong }
745*fe03f28cSDarrick J. Wong 
746*fe03f28cSDarrick J. Wong static DEVICE_ATTR(alarm_mask, S_IRUGO, show_alarm_mask, NULL);
7476f9703d0SDarrick J. Wong 
7486f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max,
7496f9703d0SDarrick J. Wong 		    set_temp_max, 0);
7506f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp_max,
7516f9703d0SDarrick J. Wong 		    set_temp_max, 1);
7526f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_temp_max,
7536f9703d0SDarrick J. Wong 		    set_temp_max, 2);
7546f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(temp4_max, S_IWUSR | S_IRUGO, show_temp_max,
7556f9703d0SDarrick J. Wong 		    set_temp_max, 3);
7566f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(temp5_max, S_IWUSR | S_IRUGO, show_temp_max,
7576f9703d0SDarrick J. Wong 		    set_temp_max, 4);
7586f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(temp6_max, S_IWUSR | S_IRUGO, show_temp_max,
7596f9703d0SDarrick J. Wong 		    set_temp_max, 5);
7606f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(temp7_max, S_IWUSR | S_IRUGO, show_temp_max,
7616f9703d0SDarrick J. Wong 		    set_temp_max, 6);
7626f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(temp8_max, S_IWUSR | S_IRUGO, show_temp_max,
7636f9703d0SDarrick J. Wong 		    set_temp_max, 7);
7646f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(temp9_max, S_IWUSR | S_IRUGO, show_temp_max,
7656f9703d0SDarrick J. Wong 		    set_temp_max, 8);
7666f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(temp10_max, S_IWUSR | S_IRUGO, show_temp_max,
7676f9703d0SDarrick J. Wong 		    set_temp_max, 9);
7686f9703d0SDarrick J. Wong 
7696f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp_min,
7706f9703d0SDarrick J. Wong 		    set_temp_min, 0);
7716f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp_min,
7726f9703d0SDarrick J. Wong 		    set_temp_min, 1);
7736f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(temp3_min, S_IWUSR | S_IRUGO, show_temp_min,
7746f9703d0SDarrick J. Wong 		    set_temp_min, 2);
7756f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(temp4_min, S_IWUSR | S_IRUGO, show_temp_min,
7766f9703d0SDarrick J. Wong 		    set_temp_min, 3);
7776f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(temp5_min, S_IWUSR | S_IRUGO, show_temp_min,
7786f9703d0SDarrick J. Wong 		    set_temp_min, 4);
7796f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(temp6_min, S_IWUSR | S_IRUGO, show_temp_min,
7806f9703d0SDarrick J. Wong 		    set_temp_min, 5);
7816f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(temp7_min, S_IWUSR | S_IRUGO, show_temp_min,
7826f9703d0SDarrick J. Wong 		    set_temp_min, 6);
7836f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(temp8_min, S_IWUSR | S_IRUGO, show_temp_min,
7846f9703d0SDarrick J. Wong 		    set_temp_min, 7);
7856f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(temp9_min, S_IWUSR | S_IRUGO, show_temp_min,
7866f9703d0SDarrick J. Wong 		    set_temp_min, 8);
7876f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(temp10_min, S_IWUSR | S_IRUGO, show_temp_min,
7886f9703d0SDarrick J. Wong 		    set_temp_min, 9);
7896f9703d0SDarrick J. Wong 
7906f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
7916f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1);
7926f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2);
7936f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_temp, NULL, 3);
7946f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(temp5_input, S_IRUGO, show_temp, NULL, 4);
7956f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(temp6_input, S_IRUGO, show_temp, NULL, 5);
7966f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(temp7_input, S_IRUGO, show_temp, NULL, 6);
7976f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(temp8_input, S_IRUGO, show_temp, NULL, 7);
7986f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(temp9_input, S_IRUGO, show_temp, NULL, 8);
7996f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(temp10_input, S_IRUGO, show_temp, NULL, 9);
8006f9703d0SDarrick J. Wong 
801*fe03f28cSDarrick J. Wong static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL,
802*fe03f28cSDarrick J. Wong 			  ADT7470_R1T_ALARM);
803*fe03f28cSDarrick J. Wong static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL,
804*fe03f28cSDarrick J. Wong 			  ADT7470_R2T_ALARM);
805*fe03f28cSDarrick J. Wong static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL,
806*fe03f28cSDarrick J. Wong 			  ADT7470_R3T_ALARM);
807*fe03f28cSDarrick J. Wong static SENSOR_DEVICE_ATTR(temp4_alarm, S_IRUGO, show_alarm, NULL,
808*fe03f28cSDarrick J. Wong 			  ADT7470_R4T_ALARM);
809*fe03f28cSDarrick J. Wong static SENSOR_DEVICE_ATTR(temp5_alarm, S_IRUGO, show_alarm, NULL,
810*fe03f28cSDarrick J. Wong 			  ADT7470_R5T_ALARM);
811*fe03f28cSDarrick J. Wong static SENSOR_DEVICE_ATTR(temp6_alarm, S_IRUGO, show_alarm, NULL,
812*fe03f28cSDarrick J. Wong 			  ADT7470_R6T_ALARM);
813*fe03f28cSDarrick J. Wong static SENSOR_DEVICE_ATTR(temp7_alarm, S_IRUGO, show_alarm, NULL,
814*fe03f28cSDarrick J. Wong 			  ADT7470_R7T_ALARM);
815*fe03f28cSDarrick J. Wong static SENSOR_DEVICE_ATTR(temp8_alarm, S_IRUGO, show_alarm, NULL,
816*fe03f28cSDarrick J. Wong 			  ALARM2(ADT7470_R8T_ALARM));
817*fe03f28cSDarrick J. Wong static SENSOR_DEVICE_ATTR(temp9_alarm, S_IRUGO, show_alarm, NULL,
818*fe03f28cSDarrick J. Wong 			  ALARM2(ADT7470_R9T_ALARM));
819*fe03f28cSDarrick J. Wong static SENSOR_DEVICE_ATTR(temp10_alarm, S_IRUGO, show_alarm, NULL,
820*fe03f28cSDarrick J. Wong 			  ALARM2(ADT7470_R10T_ALARM));
821*fe03f28cSDarrick J. Wong 
8226f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(fan1_max, S_IWUSR | S_IRUGO, show_fan_max,
8236f9703d0SDarrick J. Wong 		    set_fan_max, 0);
8246f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(fan2_max, S_IWUSR | S_IRUGO, show_fan_max,
8256f9703d0SDarrick J. Wong 		    set_fan_max, 1);
8266f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(fan3_max, S_IWUSR | S_IRUGO, show_fan_max,
8276f9703d0SDarrick J. Wong 		    set_fan_max, 2);
8286f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(fan4_max, S_IWUSR | S_IRUGO, show_fan_max,
8296f9703d0SDarrick J. Wong 		    set_fan_max, 3);
8306f9703d0SDarrick J. Wong 
8316f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min,
8326f9703d0SDarrick J. Wong 		    set_fan_min, 0);
8336f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min,
8346f9703d0SDarrick J. Wong 		    set_fan_min, 1);
8356f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min,
8366f9703d0SDarrick J. Wong 		    set_fan_min, 2);
8376f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(fan4_min, S_IWUSR | S_IRUGO, show_fan_min,
8386f9703d0SDarrick J. Wong 		    set_fan_min, 3);
8396f9703d0SDarrick J. Wong 
8406f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0);
8416f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1);
8426f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2);
8436f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 3);
8446f9703d0SDarrick J. Wong 
845*fe03f28cSDarrick J. Wong static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL,
846*fe03f28cSDarrick J. Wong 			  ALARM2(ADT7470_FAN1_ALARM));
847*fe03f28cSDarrick J. Wong static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL,
848*fe03f28cSDarrick J. Wong 			  ALARM2(ADT7470_FAN2_ALARM));
849*fe03f28cSDarrick J. Wong static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL,
850*fe03f28cSDarrick J. Wong 			  ALARM2(ADT7470_FAN3_ALARM));
851*fe03f28cSDarrick J. Wong static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL,
852*fe03f28cSDarrick J. Wong 			  ALARM2(ADT7470_FAN4_ALARM));
853*fe03f28cSDarrick J. Wong 
8546f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(force_pwm_max, S_IWUSR | S_IRUGO,
8556f9703d0SDarrick J. Wong 		    show_force_pwm_max, set_force_pwm_max, 0);
8566f9703d0SDarrick J. Wong 
8576f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 0);
8586f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 1);
8596f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 2);
8606f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(pwm4, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 3);
8616f9703d0SDarrick J. Wong 
8626f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(pwm1_auto_point1_pwm, S_IWUSR | S_IRUGO,
8636f9703d0SDarrick J. Wong 		    show_pwm_min, set_pwm_min, 0);
8646f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(pwm2_auto_point1_pwm, S_IWUSR | S_IRUGO,
8656f9703d0SDarrick J. Wong 		    show_pwm_min, set_pwm_min, 1);
8666f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(pwm3_auto_point1_pwm, S_IWUSR | S_IRUGO,
8676f9703d0SDarrick J. Wong 		    show_pwm_min, set_pwm_min, 2);
8686f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(pwm4_auto_point1_pwm, S_IWUSR | S_IRUGO,
8696f9703d0SDarrick J. Wong 		    show_pwm_min, set_pwm_min, 3);
8706f9703d0SDarrick J. Wong 
8716f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(pwm1_auto_point2_pwm, S_IWUSR | S_IRUGO,
8726f9703d0SDarrick J. Wong 		    show_pwm_max, set_pwm_max, 0);
8736f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(pwm2_auto_point2_pwm, S_IWUSR | S_IRUGO,
8746f9703d0SDarrick J. Wong 		    show_pwm_max, set_pwm_max, 1);
8756f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(pwm3_auto_point2_pwm, S_IWUSR | S_IRUGO,
8766f9703d0SDarrick J. Wong 		    show_pwm_max, set_pwm_max, 2);
8776f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(pwm4_auto_point2_pwm, S_IWUSR | S_IRUGO,
8786f9703d0SDarrick J. Wong 		    show_pwm_max, set_pwm_max, 3);
8796f9703d0SDarrick J. Wong 
8806f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(pwm1_auto_point1_temp, S_IWUSR | S_IRUGO,
8816f9703d0SDarrick J. Wong 		    show_pwm_tmin, set_pwm_tmin, 0);
8826f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(pwm2_auto_point1_temp, S_IWUSR | S_IRUGO,
8836f9703d0SDarrick J. Wong 		    show_pwm_tmin, set_pwm_tmin, 1);
8846f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(pwm3_auto_point1_temp, S_IWUSR | S_IRUGO,
8856f9703d0SDarrick J. Wong 		    show_pwm_tmin, set_pwm_tmin, 2);
8866f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(pwm4_auto_point1_temp, S_IWUSR | S_IRUGO,
8876f9703d0SDarrick J. Wong 		    show_pwm_tmin, set_pwm_tmin, 3);
8886f9703d0SDarrick J. Wong 
8896f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(pwm1_auto_point2_temp, S_IRUGO, show_pwm_tmax,
8906f9703d0SDarrick J. Wong 		    NULL, 0);
8916f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(pwm2_auto_point2_temp, S_IRUGO, show_pwm_tmax,
8926f9703d0SDarrick J. Wong 		    NULL, 1);
8936f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(pwm3_auto_point2_temp, S_IRUGO, show_pwm_tmax,
8946f9703d0SDarrick J. Wong 		    NULL, 2);
8956f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(pwm4_auto_point2_temp, S_IRUGO, show_pwm_tmax,
8966f9703d0SDarrick J. Wong 		    NULL, 3);
8976f9703d0SDarrick J. Wong 
8986f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO, show_pwm_auto,
8996f9703d0SDarrick J. Wong 		    set_pwm_auto, 0);
9006f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(pwm2_enable, S_IWUSR | S_IRUGO, show_pwm_auto,
9016f9703d0SDarrick J. Wong 		    set_pwm_auto, 1);
9026f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(pwm3_enable, S_IWUSR | S_IRUGO, show_pwm_auto,
9036f9703d0SDarrick J. Wong 		    set_pwm_auto, 2);
9046f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(pwm4_enable, S_IWUSR | S_IRUGO, show_pwm_auto,
9056f9703d0SDarrick J. Wong 		    set_pwm_auto, 3);
9066f9703d0SDarrick J. Wong 
9076f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp, S_IWUSR | S_IRUGO,
9086f9703d0SDarrick J. Wong 		    show_pwm_auto_temp, set_pwm_auto_temp, 0);
9096f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(pwm2_auto_channels_temp, S_IWUSR | S_IRUGO,
9106f9703d0SDarrick J. Wong 		    show_pwm_auto_temp, set_pwm_auto_temp, 1);
9116f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IWUSR | S_IRUGO,
9126f9703d0SDarrick J. Wong 		    show_pwm_auto_temp, set_pwm_auto_temp, 2);
9136f9703d0SDarrick J. Wong static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IWUSR | S_IRUGO,
9146f9703d0SDarrick J. Wong 		    show_pwm_auto_temp, set_pwm_auto_temp, 3);
9156f9703d0SDarrick J. Wong 
9166f9703d0SDarrick J. Wong static struct attribute *adt7470_attr[] =
9176f9703d0SDarrick J. Wong {
918*fe03f28cSDarrick J. Wong 	&dev_attr_alarm_mask.attr,
9196f9703d0SDarrick J. Wong 	&sensor_dev_attr_temp1_max.dev_attr.attr,
9206f9703d0SDarrick J. Wong 	&sensor_dev_attr_temp2_max.dev_attr.attr,
9216f9703d0SDarrick J. Wong 	&sensor_dev_attr_temp3_max.dev_attr.attr,
9226f9703d0SDarrick J. Wong 	&sensor_dev_attr_temp4_max.dev_attr.attr,
9236f9703d0SDarrick J. Wong 	&sensor_dev_attr_temp5_max.dev_attr.attr,
9246f9703d0SDarrick J. Wong 	&sensor_dev_attr_temp6_max.dev_attr.attr,
9256f9703d0SDarrick J. Wong 	&sensor_dev_attr_temp7_max.dev_attr.attr,
9266f9703d0SDarrick J. Wong 	&sensor_dev_attr_temp8_max.dev_attr.attr,
9276f9703d0SDarrick J. Wong 	&sensor_dev_attr_temp9_max.dev_attr.attr,
9286f9703d0SDarrick J. Wong 	&sensor_dev_attr_temp10_max.dev_attr.attr,
9296f9703d0SDarrick J. Wong 	&sensor_dev_attr_temp1_min.dev_attr.attr,
9306f9703d0SDarrick J. Wong 	&sensor_dev_attr_temp2_min.dev_attr.attr,
9316f9703d0SDarrick J. Wong 	&sensor_dev_attr_temp3_min.dev_attr.attr,
9326f9703d0SDarrick J. Wong 	&sensor_dev_attr_temp4_min.dev_attr.attr,
9336f9703d0SDarrick J. Wong 	&sensor_dev_attr_temp5_min.dev_attr.attr,
9346f9703d0SDarrick J. Wong 	&sensor_dev_attr_temp6_min.dev_attr.attr,
9356f9703d0SDarrick J. Wong 	&sensor_dev_attr_temp7_min.dev_attr.attr,
9366f9703d0SDarrick J. Wong 	&sensor_dev_attr_temp8_min.dev_attr.attr,
9376f9703d0SDarrick J. Wong 	&sensor_dev_attr_temp9_min.dev_attr.attr,
9386f9703d0SDarrick J. Wong 	&sensor_dev_attr_temp10_min.dev_attr.attr,
9396f9703d0SDarrick J. Wong 	&sensor_dev_attr_temp1_input.dev_attr.attr,
9406f9703d0SDarrick J. Wong 	&sensor_dev_attr_temp2_input.dev_attr.attr,
9416f9703d0SDarrick J. Wong 	&sensor_dev_attr_temp3_input.dev_attr.attr,
9426f9703d0SDarrick J. Wong 	&sensor_dev_attr_temp4_input.dev_attr.attr,
9436f9703d0SDarrick J. Wong 	&sensor_dev_attr_temp5_input.dev_attr.attr,
9446f9703d0SDarrick J. Wong 	&sensor_dev_attr_temp6_input.dev_attr.attr,
9456f9703d0SDarrick J. Wong 	&sensor_dev_attr_temp7_input.dev_attr.attr,
9466f9703d0SDarrick J. Wong 	&sensor_dev_attr_temp8_input.dev_attr.attr,
9476f9703d0SDarrick J. Wong 	&sensor_dev_attr_temp9_input.dev_attr.attr,
9486f9703d0SDarrick J. Wong 	&sensor_dev_attr_temp10_input.dev_attr.attr,
949*fe03f28cSDarrick J. Wong 	&sensor_dev_attr_temp1_alarm.dev_attr.attr,
950*fe03f28cSDarrick J. Wong 	&sensor_dev_attr_temp2_alarm.dev_attr.attr,
951*fe03f28cSDarrick J. Wong 	&sensor_dev_attr_temp3_alarm.dev_attr.attr,
952*fe03f28cSDarrick J. Wong 	&sensor_dev_attr_temp4_alarm.dev_attr.attr,
953*fe03f28cSDarrick J. Wong 	&sensor_dev_attr_temp5_alarm.dev_attr.attr,
954*fe03f28cSDarrick J. Wong 	&sensor_dev_attr_temp6_alarm.dev_attr.attr,
955*fe03f28cSDarrick J. Wong 	&sensor_dev_attr_temp7_alarm.dev_attr.attr,
956*fe03f28cSDarrick J. Wong 	&sensor_dev_attr_temp8_alarm.dev_attr.attr,
957*fe03f28cSDarrick J. Wong 	&sensor_dev_attr_temp9_alarm.dev_attr.attr,
958*fe03f28cSDarrick J. Wong 	&sensor_dev_attr_temp10_alarm.dev_attr.attr,
9596f9703d0SDarrick J. Wong 	&sensor_dev_attr_fan1_max.dev_attr.attr,
9606f9703d0SDarrick J. Wong 	&sensor_dev_attr_fan2_max.dev_attr.attr,
9616f9703d0SDarrick J. Wong 	&sensor_dev_attr_fan3_max.dev_attr.attr,
9626f9703d0SDarrick J. Wong 	&sensor_dev_attr_fan4_max.dev_attr.attr,
9636f9703d0SDarrick J. Wong 	&sensor_dev_attr_fan1_min.dev_attr.attr,
9646f9703d0SDarrick J. Wong 	&sensor_dev_attr_fan2_min.dev_attr.attr,
9656f9703d0SDarrick J. Wong 	&sensor_dev_attr_fan3_min.dev_attr.attr,
9666f9703d0SDarrick J. Wong 	&sensor_dev_attr_fan4_min.dev_attr.attr,
9676f9703d0SDarrick J. Wong 	&sensor_dev_attr_fan1_input.dev_attr.attr,
9686f9703d0SDarrick J. Wong 	&sensor_dev_attr_fan2_input.dev_attr.attr,
9696f9703d0SDarrick J. Wong 	&sensor_dev_attr_fan3_input.dev_attr.attr,
9706f9703d0SDarrick J. Wong 	&sensor_dev_attr_fan4_input.dev_attr.attr,
971*fe03f28cSDarrick J. Wong 	&sensor_dev_attr_fan1_alarm.dev_attr.attr,
972*fe03f28cSDarrick J. Wong 	&sensor_dev_attr_fan2_alarm.dev_attr.attr,
973*fe03f28cSDarrick J. Wong 	&sensor_dev_attr_fan3_alarm.dev_attr.attr,
974*fe03f28cSDarrick J. Wong 	&sensor_dev_attr_fan4_alarm.dev_attr.attr,
9756f9703d0SDarrick J. Wong 	&sensor_dev_attr_force_pwm_max.dev_attr.attr,
9766f9703d0SDarrick J. Wong 	&sensor_dev_attr_pwm1.dev_attr.attr,
9776f9703d0SDarrick J. Wong 	&sensor_dev_attr_pwm2.dev_attr.attr,
9786f9703d0SDarrick J. Wong 	&sensor_dev_attr_pwm3.dev_attr.attr,
9796f9703d0SDarrick J. Wong 	&sensor_dev_attr_pwm4.dev_attr.attr,
9806f9703d0SDarrick J. Wong 	&sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
9816f9703d0SDarrick J. Wong 	&sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
9826f9703d0SDarrick J. Wong 	&sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr,
9836f9703d0SDarrick J. Wong 	&sensor_dev_attr_pwm4_auto_point1_pwm.dev_attr.attr,
9846f9703d0SDarrick J. Wong 	&sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
9856f9703d0SDarrick J. Wong 	&sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
9866f9703d0SDarrick J. Wong 	&sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
9876f9703d0SDarrick J. Wong 	&sensor_dev_attr_pwm4_auto_point2_pwm.dev_attr.attr,
9886f9703d0SDarrick J. Wong 	&sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr,
9896f9703d0SDarrick J. Wong 	&sensor_dev_attr_pwm2_auto_point1_temp.dev_attr.attr,
9906f9703d0SDarrick J. Wong 	&sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr,
9916f9703d0SDarrick J. Wong 	&sensor_dev_attr_pwm4_auto_point1_temp.dev_attr.attr,
9926f9703d0SDarrick J. Wong 	&sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr,
9936f9703d0SDarrick J. Wong 	&sensor_dev_attr_pwm2_auto_point2_temp.dev_attr.attr,
9946f9703d0SDarrick J. Wong 	&sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr,
9956f9703d0SDarrick J. Wong 	&sensor_dev_attr_pwm4_auto_point2_temp.dev_attr.attr,
9966f9703d0SDarrick J. Wong 	&sensor_dev_attr_pwm1_enable.dev_attr.attr,
9976f9703d0SDarrick J. Wong 	&sensor_dev_attr_pwm2_enable.dev_attr.attr,
9986f9703d0SDarrick J. Wong 	&sensor_dev_attr_pwm3_enable.dev_attr.attr,
9996f9703d0SDarrick J. Wong 	&sensor_dev_attr_pwm4_enable.dev_attr.attr,
10006f9703d0SDarrick J. Wong 	&sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
10016f9703d0SDarrick J. Wong 	&sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
10026f9703d0SDarrick J. Wong 	&sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr,
10036f9703d0SDarrick J. Wong 	&sensor_dev_attr_pwm4_auto_channels_temp.dev_attr.attr,
10046f9703d0SDarrick J. Wong 	NULL
10056f9703d0SDarrick J. Wong };
10066f9703d0SDarrick J. Wong 
10076f9703d0SDarrick J. Wong static int adt7470_attach_adapter(struct i2c_adapter *adapter)
10086f9703d0SDarrick J. Wong {
10096f9703d0SDarrick J. Wong 	if (!(adapter->class & I2C_CLASS_HWMON))
10106f9703d0SDarrick J. Wong 		return 0;
10116f9703d0SDarrick J. Wong 	return i2c_probe(adapter, &addr_data, adt7470_detect);
10126f9703d0SDarrick J. Wong }
10136f9703d0SDarrick J. Wong 
10146f9703d0SDarrick J. Wong static int adt7470_detect(struct i2c_adapter *adapter, int address, int kind)
10156f9703d0SDarrick J. Wong {
10166f9703d0SDarrick J. Wong 	struct i2c_client *client;
10176f9703d0SDarrick J. Wong 	struct adt7470_data *data;
10186f9703d0SDarrick J. Wong 	int err = 0;
10196f9703d0SDarrick J. Wong 
10206f9703d0SDarrick J. Wong 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
10216f9703d0SDarrick J. Wong 		goto exit;
10226f9703d0SDarrick J. Wong 
10236f9703d0SDarrick J. Wong 	if (!(data = kzalloc(sizeof(struct adt7470_data), GFP_KERNEL))) {
10246f9703d0SDarrick J. Wong 		err = -ENOMEM;
10256f9703d0SDarrick J. Wong 		goto exit;
10266f9703d0SDarrick J. Wong 	}
10276f9703d0SDarrick J. Wong 
10286f9703d0SDarrick J. Wong 	client = &data->client;
10296f9703d0SDarrick J. Wong 	client->addr = address;
10306f9703d0SDarrick J. Wong 	client->adapter = adapter;
10316f9703d0SDarrick J. Wong 	client->driver = &adt7470_driver;
10326f9703d0SDarrick J. Wong 
10336f9703d0SDarrick J. Wong 	i2c_set_clientdata(client, data);
10346f9703d0SDarrick J. Wong 
10356f9703d0SDarrick J. Wong 	mutex_init(&data->lock);
10366f9703d0SDarrick J. Wong 
10376f9703d0SDarrick J. Wong 	if (kind <= 0) {
10386f9703d0SDarrick J. Wong 		int vendor, device, revision;
10396f9703d0SDarrick J. Wong 
10406f9703d0SDarrick J. Wong 		vendor = i2c_smbus_read_byte_data(client, ADT7470_REG_VENDOR);
10416f9703d0SDarrick J. Wong 		if (vendor != ADT7470_VENDOR) {
10426f9703d0SDarrick J. Wong 			err = -ENODEV;
10436f9703d0SDarrick J. Wong 			goto exit_free;
10446f9703d0SDarrick J. Wong 		}
10456f9703d0SDarrick J. Wong 
10466f9703d0SDarrick J. Wong 		device = i2c_smbus_read_byte_data(client, ADT7470_REG_DEVICE);
10476f9703d0SDarrick J. Wong 		if (device != ADT7470_DEVICE) {
10486f9703d0SDarrick J. Wong 			err = -ENODEV;
10496f9703d0SDarrick J. Wong 			goto exit_free;
10506f9703d0SDarrick J. Wong 		}
10516f9703d0SDarrick J. Wong 
10526f9703d0SDarrick J. Wong 		revision = i2c_smbus_read_byte_data(client,
10536f9703d0SDarrick J. Wong 						    ADT7470_REG_REVISION);
10546f9703d0SDarrick J. Wong 		if (revision != ADT7470_REVISION) {
10556f9703d0SDarrick J. Wong 			err = -ENODEV;
10566f9703d0SDarrick J. Wong 			goto exit_free;
10576f9703d0SDarrick J. Wong 		}
10586f9703d0SDarrick J. Wong 	} else
10596f9703d0SDarrick J. Wong 		dev_dbg(&adapter->dev, "detection forced\n");
10606f9703d0SDarrick J. Wong 
10616f9703d0SDarrick J. Wong 	strlcpy(client->name, "adt7470", I2C_NAME_SIZE);
10626f9703d0SDarrick J. Wong 
10636f9703d0SDarrick J. Wong 	if ((err = i2c_attach_client(client)))
10646f9703d0SDarrick J. Wong 		goto exit_free;
10656f9703d0SDarrick J. Wong 
10666f9703d0SDarrick J. Wong 	dev_info(&client->dev, "%s chip found\n", client->name);
10676f9703d0SDarrick J. Wong 
10686f9703d0SDarrick J. Wong 	/* Initialize the ADT7470 chip */
10696f9703d0SDarrick J. Wong 	adt7470_init_client(client);
10706f9703d0SDarrick J. Wong 
10716f9703d0SDarrick J. Wong 	/* Register sysfs hooks */
10726f9703d0SDarrick J. Wong 	data->attrs.attrs = adt7470_attr;
10736f9703d0SDarrick J. Wong 	if ((err = sysfs_create_group(&client->dev.kobj, &data->attrs)))
10746f9703d0SDarrick J. Wong 		goto exit_detach;
10756f9703d0SDarrick J. Wong 
10761beeffe4STony Jones 	data->hwmon_dev = hwmon_device_register(&client->dev);
10771beeffe4STony Jones 	if (IS_ERR(data->hwmon_dev)) {
10781beeffe4STony Jones 		err = PTR_ERR(data->hwmon_dev);
10796f9703d0SDarrick J. Wong 		goto exit_remove;
10806f9703d0SDarrick J. Wong 	}
10816f9703d0SDarrick J. Wong 
10826f9703d0SDarrick J. Wong 	return 0;
10836f9703d0SDarrick J. Wong 
10846f9703d0SDarrick J. Wong exit_remove:
10856f9703d0SDarrick J. Wong 	sysfs_remove_group(&client->dev.kobj, &data->attrs);
10866f9703d0SDarrick J. Wong exit_detach:
10876f9703d0SDarrick J. Wong 	i2c_detach_client(client);
10886f9703d0SDarrick J. Wong exit_free:
10896f9703d0SDarrick J. Wong 	kfree(data);
10906f9703d0SDarrick J. Wong exit:
10916f9703d0SDarrick J. Wong 	return err;
10926f9703d0SDarrick J. Wong }
10936f9703d0SDarrick J. Wong 
10946f9703d0SDarrick J. Wong static int adt7470_detach_client(struct i2c_client *client)
10956f9703d0SDarrick J. Wong {
10966f9703d0SDarrick J. Wong 	struct adt7470_data *data = i2c_get_clientdata(client);
10976f9703d0SDarrick J. Wong 
10981beeffe4STony Jones 	hwmon_device_unregister(data->hwmon_dev);
10996f9703d0SDarrick J. Wong 	sysfs_remove_group(&client->dev.kobj, &data->attrs);
11006f9703d0SDarrick J. Wong 	i2c_detach_client(client);
11016f9703d0SDarrick J. Wong 	kfree(data);
11026f9703d0SDarrick J. Wong 	return 0;
11036f9703d0SDarrick J. Wong }
11046f9703d0SDarrick J. Wong 
11056f9703d0SDarrick J. Wong static int __init adt7470_init(void)
11066f9703d0SDarrick J. Wong {
11076f9703d0SDarrick J. Wong 	return i2c_add_driver(&adt7470_driver);
11086f9703d0SDarrick J. Wong }
11096f9703d0SDarrick J. Wong 
11106f9703d0SDarrick J. Wong static void __exit adt7470_exit(void)
11116f9703d0SDarrick J. Wong {
11126f9703d0SDarrick J. Wong 	i2c_del_driver(&adt7470_driver);
11136f9703d0SDarrick J. Wong }
11146f9703d0SDarrick J. Wong 
11156f9703d0SDarrick J. Wong MODULE_AUTHOR("Darrick J. Wong <djwong@us.ibm.com>");
11166f9703d0SDarrick J. Wong MODULE_DESCRIPTION("ADT7470 driver");
11176f9703d0SDarrick J. Wong MODULE_LICENSE("GPL");
11186f9703d0SDarrick J. Wong 
11196f9703d0SDarrick J. Wong module_init(adt7470_init);
11206f9703d0SDarrick J. Wong module_exit(adt7470_exit);
1121