aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-10-17 12:33:39 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-10-17 12:33:39 -0400
commitbdbf0ac7e187b2b757216e653e64f8b808b9077e (patch)
tree54acb0bd3696249618a16a448c956e63ac6a3806 /drivers
parent8eb88c80d444fd249edaa7d895666cde79e7b3b8 (diff)
parenta0cf354a71bd2969b2f1868530d3fecaebd6dc3d (diff)
Merge branch 'hwmon-for-linus' of git://jdelvare.pck.nerim.net/jdelvare-2.6
* 'hwmon-for-linus' of git://jdelvare.pck.nerim.net/jdelvare-2.6: (47 commits) hwmon: (adm1026) Prevent log spamming hwmon: (adm1026) Fix debug messages hwmon: (adm1029) Use mask for fan_div value hwmon: (adt7470) Add documentation hwmon: (ibmaem) Automatically load on IBM systems via DMI hwmon: (ibmpex) Automatically load on IBM systems via DMI hwmon: (w83781d) Use new style driver binding hwmon: (w83781d) Stop abusing struct i2c_client for ISA devices hwmon: (w83781d) Make ISA interface depend on CONFIG_ISA hwmon: (w83781d) Additional information about AS99127F PWM hwmon: (w83781d) Detect alias chips hwmon: (w83781d) Refactor beep enable handling hwmon: Drop dead links to old National Semiconductor chip datasheets hwmon: (w83791d) add support for thermal cruise mode hwmon: (w83791d) add pwm_enable support hwmon: (w83791d) add manual PWM support hwmon: (w83791d) fan 4/5 pins can also be used for gpio hwmon: (max1619) Use inline functions instead of macros hwmon: (it87) Fix thermal sensor type values hwmon: (lm78) Convert to a new-style i2c driver ...
Diffstat (limited to 'drivers')
-rw-r--r--drivers/hwmon/Kconfig8
-rw-r--r--drivers/hwmon/adm1026.c17
-rw-r--r--drivers/hwmon/adm1029.c5
-rw-r--r--drivers/hwmon/ams/ams-core.c82
-rw-r--r--drivers/hwmon/ams/ams-i2c.c60
-rw-r--r--drivers/hwmon/ams/ams-input.c63
-rw-r--r--drivers/hwmon/ams/ams-pmu.c18
-rw-r--r--drivers/hwmon/ams/ams.h4
-rw-r--r--drivers/hwmon/ibmaem.c7
-rw-r--r--drivers/hwmon/ibmpex.c6
-rw-r--r--drivers/hwmon/it87.c11
-rw-r--r--drivers/hwmon/lm78.c270
-rw-r--r--drivers/hwmon/lm85.c352
-rw-r--r--drivers/hwmon/lm87.c33
-rw-r--r--drivers/hwmon/lm90.c444
-rw-r--r--drivers/hwmon/max1619.c17
-rw-r--r--drivers/hwmon/w83781d.c976
-rw-r--r--drivers/hwmon/w83791d.c324
-rw-r--r--drivers/i2c/busses/i2c-powermac.c29
19 files changed, 1683 insertions, 1043 deletions
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index ebacc0af40fe..6de1e0ffd391 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -510,11 +510,9 @@ config SENSORS_LM90
510 depends on I2C 510 depends on I2C
511 help 511 help
512 If you say yes here you get support for National Semiconductor LM90, 512 If you say yes here you get support for National Semiconductor LM90,
513 LM86, LM89 and LM99, Analog Devices ADM1032 and Maxim MAX6657, 513 LM86, LM89 and LM99, Analog Devices ADM1032 and ADT7461, and Maxim
514 MAX6658, MAX6659, MAX6680 and MAX6681 sensor chips. 514 MAX6646, MAX6647, MAX6649, MAX6657, MAX6658, MAX6659, MAX6680 and
515 515 MAX6681 sensor chips.
516 The Analog Devices ADT7461 sensor chip is also supported, but only
517 if found in ADM1032 compatibility mode.
518 516
519 This driver can also be built as a module. If so, the module 517 This driver can also be built as a module. If so, the module
520 will be called lm90. 518 will be called lm90.
diff --git a/drivers/hwmon/adm1026.c b/drivers/hwmon/adm1026.c
index 7fe2441fc845..ff7de40b6e35 100644
--- a/drivers/hwmon/adm1026.c
+++ b/drivers/hwmon/adm1026.c
@@ -279,7 +279,6 @@ struct adm1026_data {
279 u8 fan_min[8]; /* Register value */ 279 u8 fan_min[8]; /* Register value */
280 u8 fan_div[8]; /* Decoded value */ 280 u8 fan_div[8]; /* Decoded value */
281 struct pwm_data pwm1; /* Pwm control values */ 281 struct pwm_data pwm1; /* Pwm control values */
282 int vid; /* Decoded value */
283 u8 vrm; /* VRM version */ 282 u8 vrm; /* VRM version */
284 u8 analog_out; /* Register value (DAC) */ 283 u8 analog_out; /* Register value (DAC) */
285 long alarms; /* Register encoding, combined */ 284 long alarms; /* Register encoding, combined */
@@ -455,7 +454,7 @@ static void adm1026_print_gpio(struct i2c_client *client)
455 struct adm1026_data *data = i2c_get_clientdata(client); 454 struct adm1026_data *data = i2c_get_clientdata(client);
456 int i; 455 int i;
457 456
458 dev_dbg(&client->dev, "GPIO config is:"); 457 dev_dbg(&client->dev, "GPIO config is:\n");
459 for (i = 0;i <= 7;++i) { 458 for (i = 0;i <= 7;++i) {
460 if (data->config2 & (1 << i)) { 459 if (data->config2 & (1 << i)) {
461 dev_dbg(&client->dev, "\t%sGP%s%d\n", 460 dev_dbg(&client->dev, "\t%sGP%s%d\n",
@@ -697,8 +696,6 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
697 data->last_config = jiffies; 696 data->last_config = jiffies;
698 }; /* last_config */ 697 }; /* last_config */
699 698
700 dev_dbg(&client->dev, "Setting VID from GPIO11-15.\n");
701 data->vid = (data->gpio >> 11) & 0x1f;
702 data->valid = 1; 699 data->valid = 1;
703 mutex_unlock(&data->update_lock); 700 mutex_unlock(&data->update_lock);
704 return data; 701 return data;
@@ -1215,7 +1212,10 @@ static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg,
1215static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf) 1212static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
1216{ 1213{
1217 struct adm1026_data *data = adm1026_update_device(dev); 1214 struct adm1026_data *data = adm1026_update_device(dev);
1218 return sprintf(buf, "%d\n", vid_from_reg(data->vid & 0x3f, data->vrm)); 1215 int vid = (data->gpio >> 11) & 0x1f;
1216
1217 dev_dbg(dev, "Setting VID from GPIO11-15.\n");
1218 return sprintf(buf, "%d\n", vid_from_reg(vid, data->vrm));
1219} 1219}
1220static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); 1220static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
1221 1221
@@ -1681,17 +1681,16 @@ static int adm1026_detect(struct i2c_client *client, int kind,
1681 kind = adm1026; 1681 kind = adm1026;
1682 } else if (company == ADM1026_COMPANY_ANALOG_DEV 1682 } else if (company == ADM1026_COMPANY_ANALOG_DEV
1683 && (verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) { 1683 && (verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) {
1684 dev_err(&adapter->dev, ": Unrecognized stepping " 1684 dev_err(&adapter->dev, "Unrecognized stepping "
1685 "0x%02x. Defaulting to ADM1026.\n", verstep); 1685 "0x%02x. Defaulting to ADM1026.\n", verstep);
1686 kind = adm1026; 1686 kind = adm1026;
1687 } else if ((verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) { 1687 } else if ((verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) {
1688 dev_err(&adapter->dev, ": Found version/stepping " 1688 dev_err(&adapter->dev, "Found version/stepping "
1689 "0x%02x. Assuming generic ADM1026.\n", 1689 "0x%02x. Assuming generic ADM1026.\n",
1690 verstep); 1690 verstep);
1691 kind = any_chip; 1691 kind = any_chip;
1692 } else { 1692 } else {
1693 dev_dbg(&adapter->dev, ": Autodetection " 1693 dev_dbg(&adapter->dev, "Autodetection failed\n");
1694 "failed\n");
1695 /* Not an ADM1026 ... */ 1694 /* Not an ADM1026 ... */
1696 if (kind == 0) { /* User used force=x,y */ 1695 if (kind == 0) { /* User used force=x,y */
1697 dev_err(&adapter->dev, "Generic ADM1026 not " 1696 dev_err(&adapter->dev, "Generic ADM1026 not "
diff --git a/drivers/hwmon/adm1029.c b/drivers/hwmon/adm1029.c
index ba84ca5923f9..36718150b475 100644
--- a/drivers/hwmon/adm1029.c
+++ b/drivers/hwmon/adm1029.c
@@ -179,7 +179,8 @@ show_fan(struct device *dev, struct device_attribute *devattr, char *buf)
179 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 179 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
180 struct adm1029_data *data = adm1029_update_device(dev); 180 struct adm1029_data *data = adm1029_update_device(dev);
181 u16 val; 181 u16 val;
182 if (data->fan[attr->index] == 0 || data->fan_div[attr->index] == 0 182 if (data->fan[attr->index] == 0
183 || (data->fan_div[attr->index] & 0xC0) == 0
183 || data->fan[attr->index] == 255) { 184 || data->fan[attr->index] == 255) {
184 return sprintf(buf, "0\n"); 185 return sprintf(buf, "0\n");
185 } 186 }
@@ -194,7 +195,7 @@ show_fan_div(struct device *dev, struct device_attribute *devattr, char *buf)
194{ 195{
195 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 196 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
196 struct adm1029_data *data = adm1029_update_device(dev); 197 struct adm1029_data *data = adm1029_update_device(dev);
197 if (data->fan_div[attr->index] == 0) 198 if ((data->fan_div[attr->index] & 0xC0) == 0)
198 return sprintf(buf, "0\n"); 199 return sprintf(buf, "0\n");
199 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[attr->index])); 200 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[attr->index]));
200} 201}
diff --git a/drivers/hwmon/ams/ams-core.c b/drivers/hwmon/ams/ams-core.c
index fbefa82a015c..6c9ace1b76f6 100644
--- a/drivers/hwmon/ams/ams-core.c
+++ b/drivers/hwmon/ams/ams-core.c
@@ -99,39 +99,31 @@ static struct pmf_irq_client ams_shock_client = {
99 */ 99 */
100static void ams_worker(struct work_struct *work) 100static void ams_worker(struct work_struct *work)
101{ 101{
102 mutex_lock(&ams_info.lock); 102 unsigned long flags;
103 103 u8 irqs_to_clear;
104 if (ams_info.has_device) {
105 unsigned long flags;
106 104
107 spin_lock_irqsave(&ams_info.irq_lock, flags); 105 mutex_lock(&ams_info.lock);
108 106
109 if (ams_info.worker_irqs & AMS_IRQ_FREEFALL) { 107 spin_lock_irqsave(&ams_info.irq_lock, flags);
110 if (verbose) 108 irqs_to_clear = ams_info.worker_irqs;
111 printk(KERN_INFO "ams: freefall detected!\n");
112 109
113 ams_info.worker_irqs &= ~AMS_IRQ_FREEFALL; 110 if (ams_info.worker_irqs & AMS_IRQ_FREEFALL) {
111 if (verbose)
112 printk(KERN_INFO "ams: freefall detected!\n");
114 113
115 /* we must call this with interrupts enabled */ 114 ams_info.worker_irqs &= ~AMS_IRQ_FREEFALL;
116 spin_unlock_irqrestore(&ams_info.irq_lock, flags); 115 }
117 ams_info.clear_irq(AMS_IRQ_FREEFALL);
118 spin_lock_irqsave(&ams_info.irq_lock, flags);
119 }
120 116
121 if (ams_info.worker_irqs & AMS_IRQ_SHOCK) { 117 if (ams_info.worker_irqs & AMS_IRQ_SHOCK) {
122 if (verbose) 118 if (verbose)
123 printk(KERN_INFO "ams: shock detected!\n"); 119 printk(KERN_INFO "ams: shock detected!\n");
124 120
125 ams_info.worker_irqs &= ~AMS_IRQ_SHOCK; 121 ams_info.worker_irqs &= ~AMS_IRQ_SHOCK;
122 }
126 123
127 /* we must call this with interrupts enabled */ 124 spin_unlock_irqrestore(&ams_info.irq_lock, flags);
128 spin_unlock_irqrestore(&ams_info.irq_lock, flags);
129 ams_info.clear_irq(AMS_IRQ_SHOCK);
130 spin_lock_irqsave(&ams_info.irq_lock, flags);
131 }
132 125
133 spin_unlock_irqrestore(&ams_info.irq_lock, flags); 126 ams_info.clear_irq(irqs_to_clear);
134 }
135 127
136 mutex_unlock(&ams_info.lock); 128 mutex_unlock(&ams_info.lock);
137} 129}
@@ -223,34 +215,28 @@ int __init ams_init(void)
223 215
224void ams_exit(void) 216void ams_exit(void)
225{ 217{
226 mutex_lock(&ams_info.lock); 218 /* Remove input device */
227 219 ams_input_exit();
228 if (ams_info.has_device) {
229 /* Remove input device */
230 ams_input_exit();
231 220
232 /* Shut down implementation */ 221 /* Remove attributes */
233 ams_info.exit(); 222 device_remove_file(&ams_info.of_dev->dev, &dev_attr_current);
234
235 /* Flush interrupt worker
236 *
237 * We do this after ams_info.exit(), because an interrupt might
238 * have arrived before disabling them.
239 */
240 flush_scheduled_work();
241 223
242 /* Remove attributes */ 224 /* Shut down implementation */
243 device_remove_file(&ams_info.of_dev->dev, &dev_attr_current); 225 ams_info.exit();
244 226
245 /* Remove device */ 227 /* Flush interrupt worker
246 of_device_unregister(ams_info.of_dev); 228 *
229 * We do this after ams_info.exit(), because an interrupt might
230 * have arrived before disabling them.
231 */
232 flush_scheduled_work();
247 233
248 /* Remove handler */ 234 /* Remove device */
249 pmf_unregister_irq_client(&ams_shock_client); 235 of_device_unregister(ams_info.of_dev);
250 pmf_unregister_irq_client(&ams_freefall_client);
251 }
252 236
253 mutex_unlock(&ams_info.lock); 237 /* Remove handler */
238 pmf_unregister_irq_client(&ams_shock_client);
239 pmf_unregister_irq_client(&ams_freefall_client);
254} 240}
255 241
256MODULE_AUTHOR("Stelian Pop, Michael Hanselmann"); 242MODULE_AUTHOR("Stelian Pop, Michael Hanselmann");
diff --git a/drivers/hwmon/ams/ams-i2c.c b/drivers/hwmon/ams/ams-i2c.c
index 957760536a4c..2cbf8a6506c7 100644
--- a/drivers/hwmon/ams/ams-i2c.c
+++ b/drivers/hwmon/ams/ams-i2c.c
@@ -60,26 +60,34 @@ enum ams_i2c_cmd {
60 AMS_CMD_START, 60 AMS_CMD_START,
61}; 61};
62 62
63static int ams_i2c_attach(struct i2c_adapter *adapter); 63static int ams_i2c_probe(struct i2c_client *client,
64static int ams_i2c_detach(struct i2c_adapter *adapter); 64 const struct i2c_device_id *id);
65static int ams_i2c_remove(struct i2c_client *client);
66
67static const struct i2c_device_id ams_id[] = {
68 { "ams", 0 },
69 { }
70};
71MODULE_DEVICE_TABLE(i2c, ams_id);
65 72
66static struct i2c_driver ams_i2c_driver = { 73static struct i2c_driver ams_i2c_driver = {
67 .driver = { 74 .driver = {
68 .name = "ams", 75 .name = "ams",
69 .owner = THIS_MODULE, 76 .owner = THIS_MODULE,
70 }, 77 },
71 .attach_adapter = ams_i2c_attach, 78 .probe = ams_i2c_probe,
72 .detach_adapter = ams_i2c_detach, 79 .remove = ams_i2c_remove,
80 .id_table = ams_id,
73}; 81};
74 82
75static s32 ams_i2c_read(u8 reg) 83static s32 ams_i2c_read(u8 reg)
76{ 84{
77 return i2c_smbus_read_byte_data(&ams_info.i2c_client, reg); 85 return i2c_smbus_read_byte_data(ams_info.i2c_client, reg);
78} 86}
79 87
80static int ams_i2c_write(u8 reg, u8 value) 88static int ams_i2c_write(u8 reg, u8 value)
81{ 89{
82 return i2c_smbus_write_byte_data(&ams_info.i2c_client, reg, value); 90 return i2c_smbus_write_byte_data(ams_info.i2c_client, reg, value);
83} 91}
84 92
85static int ams_i2c_cmd(enum ams_i2c_cmd cmd) 93static int ams_i2c_cmd(enum ams_i2c_cmd cmd)
@@ -152,9 +160,9 @@ static void ams_i2c_get_xyz(s8 *x, s8 *y, s8 *z)
152 *z = ams_i2c_read(AMS_DATAZ); 160 *z = ams_i2c_read(AMS_DATAZ);
153} 161}
154 162
155static int ams_i2c_attach(struct i2c_adapter *adapter) 163static int ams_i2c_probe(struct i2c_client *client,
164 const struct i2c_device_id *id)
156{ 165{
157 unsigned long bus;
158 int vmaj, vmin; 166 int vmaj, vmin;
159 int result; 167 int result;
160 168
@@ -162,17 +170,7 @@ static int ams_i2c_attach(struct i2c_adapter *adapter)
162 if (unlikely(ams_info.has_device)) 170 if (unlikely(ams_info.has_device))
163 return -ENODEV; 171 return -ENODEV;
164 172
165 if (strncmp(adapter->name, "uni-n", 5)) 173 ams_info.i2c_client = client;
166 return -ENODEV;
167
168 bus = simple_strtoul(adapter->name + 6, NULL, 10);
169 if (bus != ams_info.i2c_bus)
170 return -ENODEV;
171
172 ams_info.i2c_client.addr = ams_info.i2c_address;
173 ams_info.i2c_client.adapter = adapter;
174 ams_info.i2c_client.driver = &ams_i2c_driver;
175 strcpy(ams_info.i2c_client.name, "Apple Motion Sensor");
176 174
177 if (ams_i2c_cmd(AMS_CMD_RESET)) { 175 if (ams_i2c_cmd(AMS_CMD_RESET)) {
178 printk(KERN_INFO "ams: Failed to reset the device\n"); 176 printk(KERN_INFO "ams: Failed to reset the device\n");
@@ -237,7 +235,7 @@ static int ams_i2c_attach(struct i2c_adapter *adapter)
237 return 0; 235 return 0;
238} 236}
239 237
240static int ams_i2c_detach(struct i2c_adapter *adapter) 238static int ams_i2c_remove(struct i2c_client *client)
241{ 239{
242 if (ams_info.has_device) { 240 if (ams_info.has_device) {
243 /* Disable interrupts */ 241 /* Disable interrupts */
@@ -261,11 +259,7 @@ static void ams_i2c_exit(void)
261 259
262int __init ams_i2c_init(struct device_node *np) 260int __init ams_i2c_init(struct device_node *np)
263{ 261{
264 char *tmp_bus;
265 int result; 262 int result;
266 const u32 *prop;
267
268 mutex_lock(&ams_info.lock);
269 263
270 /* Set implementation stuff */ 264 /* Set implementation stuff */
271 ams_info.of_node = np; 265 ams_info.of_node = np;
@@ -275,25 +269,7 @@ int __init ams_i2c_init(struct device_node *np)
275 ams_info.clear_irq = ams_i2c_clear_irq; 269 ams_info.clear_irq = ams_i2c_clear_irq;
276 ams_info.bustype = BUS_I2C; 270 ams_info.bustype = BUS_I2C;
277 271
278 /* look for bus either using "reg" or by path */
279 prop = of_get_property(ams_info.of_node, "reg", NULL);
280 if (!prop) {
281 result = -ENODEV;
282
283 goto exit;
284 }
285
286 tmp_bus = strstr(ams_info.of_node->full_name, "/i2c-bus@");
287 if (tmp_bus)
288 ams_info.i2c_bus = *(tmp_bus + 9) - '0';
289 else
290 ams_info.i2c_bus = ((*prop) >> 8) & 0x0f;
291 ams_info.i2c_address = ((*prop) & 0xff) >> 1;
292
293 result = i2c_add_driver(&ams_i2c_driver); 272 result = i2c_add_driver(&ams_i2c_driver);
294 273
295exit:
296 mutex_unlock(&ams_info.lock);
297
298 return result; 274 return result;
299} 275}
diff --git a/drivers/hwmon/ams/ams-input.c b/drivers/hwmon/ams/ams-input.c
index 7b81e0c2c2d9..8a712392cd38 100644
--- a/drivers/hwmon/ams/ams-input.c
+++ b/drivers/hwmon/ams/ams-input.c
@@ -20,13 +20,15 @@
20#include "ams.h" 20#include "ams.h"
21 21
22static unsigned int joystick; 22static unsigned int joystick;
23module_param(joystick, bool, 0644); 23module_param(joystick, bool, S_IRUGO);
24MODULE_PARM_DESC(joystick, "Enable the input class device on module load"); 24MODULE_PARM_DESC(joystick, "Enable the input class device on module load");
25 25
26static unsigned int invert; 26static unsigned int invert;
27module_param(invert, bool, 0644); 27module_param(invert, bool, S_IWUSR | S_IRUGO);
28MODULE_PARM_DESC(invert, "Invert input data on X and Y axis"); 28MODULE_PARM_DESC(invert, "Invert input data on X and Y axis");
29 29
30static DEFINE_MUTEX(ams_input_mutex);
31
30static void ams_idev_poll(struct input_polled_dev *dev) 32static void ams_idev_poll(struct input_polled_dev *dev)
31{ 33{
32 struct input_dev *idev = dev->input; 34 struct input_dev *idev = dev->input;
@@ -50,13 +52,11 @@ static void ams_idev_poll(struct input_polled_dev *dev)
50} 52}
51 53
52/* Call with ams_info.lock held! */ 54/* Call with ams_info.lock held! */
53static void ams_input_enable(void) 55static int ams_input_enable(void)
54{ 56{
55 struct input_dev *input; 57 struct input_dev *input;
56 s8 x, y, z; 58 s8 x, y, z;
57 59 int error;
58 if (ams_info.idev)
59 return;
60 60
61 ams_sensors(&x, &y, &z); 61 ams_sensors(&x, &y, &z);
62 ams_info.xcalib = x; 62 ams_info.xcalib = x;
@@ -65,7 +65,7 @@ static void ams_input_enable(void)
65 65
66 ams_info.idev = input_allocate_polled_device(); 66 ams_info.idev = input_allocate_polled_device();
67 if (!ams_info.idev) 67 if (!ams_info.idev)
68 return; 68 return -ENOMEM;
69 69
70 ams_info.idev->poll = ams_idev_poll; 70 ams_info.idev->poll = ams_idev_poll;
71 ams_info.idev->poll_interval = 25; 71 ams_info.idev->poll_interval = 25;
@@ -84,14 +84,18 @@ static void ams_input_enable(void)
84 set_bit(EV_KEY, input->evbit); 84 set_bit(EV_KEY, input->evbit);
85 set_bit(BTN_TOUCH, input->keybit); 85 set_bit(BTN_TOUCH, input->keybit);
86 86
87 if (input_register_polled_device(ams_info.idev)) { 87 error = input_register_polled_device(ams_info.idev);
88 if (error) {
88 input_free_polled_device(ams_info.idev); 89 input_free_polled_device(ams_info.idev);
89 ams_info.idev = NULL; 90 ams_info.idev = NULL;
90 return; 91 return error;
91 } 92 }
93
94 joystick = 1;
95
96 return 0;
92} 97}
93 98
94/* Call with ams_info.lock held! */
95static void ams_input_disable(void) 99static void ams_input_disable(void)
96{ 100{
97 if (ams_info.idev) { 101 if (ams_info.idev) {
@@ -99,6 +103,8 @@ static void ams_input_disable(void)
99 input_free_polled_device(ams_info.idev); 103 input_free_polled_device(ams_info.idev);
100 ams_info.idev = NULL; 104 ams_info.idev = NULL;
101 } 105 }
106
107 joystick = 0;
102} 108}
103 109
104static ssize_t ams_input_show_joystick(struct device *dev, 110static ssize_t ams_input_show_joystick(struct device *dev,
@@ -110,39 +116,42 @@ static ssize_t ams_input_show_joystick(struct device *dev,
110static ssize_t ams_input_store_joystick(struct device *dev, 116static ssize_t ams_input_store_joystick(struct device *dev,
111 struct device_attribute *attr, const char *buf, size_t count) 117 struct device_attribute *attr, const char *buf, size_t count)
112{ 118{
113 if (sscanf(buf, "%d\n", &joystick) != 1) 119 unsigned long enable;
120 int error = 0;
121
122 if (strict_strtoul(buf, 0, &enable) || enable > 1)
114 return -EINVAL; 123 return -EINVAL;
115 124
116 mutex_lock(&ams_info.lock); 125 mutex_lock(&ams_input_mutex);
117 126
118 if (joystick) 127 if (enable != joystick) {
119 ams_input_enable(); 128 if (enable)
120 else 129 error = ams_input_enable();
121 ams_input_disable(); 130 else
131 ams_input_disable();
132 }
122 133
123 mutex_unlock(&ams_info.lock); 134 mutex_unlock(&ams_input_mutex);
124 135
125 return count; 136 return error ? error : count;
126} 137}
127 138
128static DEVICE_ATTR(joystick, S_IRUGO | S_IWUSR, 139static DEVICE_ATTR(joystick, S_IRUGO | S_IWUSR,
129 ams_input_show_joystick, ams_input_store_joystick); 140 ams_input_show_joystick, ams_input_store_joystick);
130 141
131/* Call with ams_info.lock held! */
132int ams_input_init(void) 142int ams_input_init(void)
133{ 143{
134 int result; 144 if (joystick)
135
136 result = device_create_file(&ams_info.of_dev->dev, &dev_attr_joystick);
137
138 if (!result && joystick)
139 ams_input_enable(); 145 ams_input_enable();
140 return result; 146
147 return device_create_file(&ams_info.of_dev->dev, &dev_attr_joystick);
141} 148}
142 149
143/* Call with ams_info.lock held! */
144void ams_input_exit(void) 150void ams_input_exit(void)
145{ 151{
146 ams_input_disable();
147 device_remove_file(&ams_info.of_dev->dev, &dev_attr_joystick); 152 device_remove_file(&ams_info.of_dev->dev, &dev_attr_joystick);
153
154 mutex_lock(&ams_input_mutex);
155 ams_input_disable();
156 mutex_unlock(&ams_input_mutex);
148} 157}
diff --git a/drivers/hwmon/ams/ams-pmu.c b/drivers/hwmon/ams/ams-pmu.c
index 9463e9768f6f..fb18b3d3162b 100644
--- a/drivers/hwmon/ams/ams-pmu.c
+++ b/drivers/hwmon/ams/ams-pmu.c
@@ -149,8 +149,6 @@ int __init ams_pmu_init(struct device_node *np)
149 const u32 *prop; 149 const u32 *prop;
150 int result; 150 int result;
151 151
152 mutex_lock(&ams_info.lock);
153
154 /* Set implementation stuff */ 152 /* Set implementation stuff */
155 ams_info.of_node = np; 153 ams_info.of_node = np;
156 ams_info.exit = ams_pmu_exit; 154 ams_info.exit = ams_pmu_exit;
@@ -161,10 +159,9 @@ int __init ams_pmu_init(struct device_node *np)
161 159
162 /* Get PMU command, should be 0x4e, but we can never know */ 160 /* Get PMU command, should be 0x4e, but we can never know */
163 prop = of_get_property(ams_info.of_node, "reg", NULL); 161 prop = of_get_property(ams_info.of_node, "reg", NULL);
164 if (!prop) { 162 if (!prop)
165 result = -ENODEV; 163 return -ENODEV;
166 goto exit; 164
167 }
168 ams_pmu_cmd = ((*prop) >> 8) & 0xff; 165 ams_pmu_cmd = ((*prop) >> 8) & 0xff;
169 166
170 /* Disable interrupts */ 167 /* Disable interrupts */
@@ -175,7 +172,7 @@ int __init ams_pmu_init(struct device_node *np)
175 172
176 result = ams_sensor_attach(); 173 result = ams_sensor_attach();
177 if (result < 0) 174 if (result < 0)
178 goto exit; 175 return result;
179 176
180 /* Set default values */ 177 /* Set default values */
181 ams_pmu_set_register(AMS_FF_LOW_LIMIT, 0x15); 178 ams_pmu_set_register(AMS_FF_LOW_LIMIT, 0x15);
@@ -198,10 +195,5 @@ int __init ams_pmu_init(struct device_node *np)
198 195
199 printk(KERN_INFO "ams: Found PMU based motion sensor\n"); 196 printk(KERN_INFO "ams: Found PMU based motion sensor\n");
200 197
201 result = 0; 198 return 0;
202
203exit:
204 mutex_unlock(&ams_info.lock);
205
206 return result;
207} 199}
diff --git a/drivers/hwmon/ams/ams.h b/drivers/hwmon/ams/ams.h
index 221ef6915a5f..5ed387b0bd9a 100644
--- a/drivers/hwmon/ams/ams.h
+++ b/drivers/hwmon/ams/ams.h
@@ -46,9 +46,7 @@ struct ams {
46 46
47#ifdef CONFIG_SENSORS_AMS_I2C 47#ifdef CONFIG_SENSORS_AMS_I2C
48 /* I2C properties */ 48 /* I2C properties */
49 int i2c_bus; 49 struct i2c_client *i2c_client;
50 int i2c_address;
51 struct i2c_client i2c_client;
52#endif 50#endif
53 51
54 /* Joystick emulation */ 52 /* Joystick emulation */
diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
index 0f70dc204105..7b0ed5dea399 100644
--- a/drivers/hwmon/ibmaem.c
+++ b/drivers/hwmon/ibmaem.c
@@ -1118,3 +1118,10 @@ MODULE_LICENSE("GPL");
1118 1118
1119module_init(aem_init); 1119module_init(aem_init);
1120module_exit(aem_exit); 1120module_exit(aem_exit);
1121
1122MODULE_ALIAS("dmi:bvnIBM:*:pnIBMSystemx3350-*");
1123MODULE_ALIAS("dmi:bvnIBM:*:pnIBMSystemx3550-*");
1124MODULE_ALIAS("dmi:bvnIBM:*:pnIBMSystemx3650-*");
1125MODULE_ALIAS("dmi:bvnIBM:*:pnIBMSystemx3655-*");
1126MODULE_ALIAS("dmi:bvnIBM:*:pnIBMSystemx3755-*");
1127MODULE_ALIAS("dmi:bvnIBM:*:pnIBM3850M2/x3950M2-*");
diff --git a/drivers/hwmon/ibmpex.c b/drivers/hwmon/ibmpex.c
index 4e9b19c6732f..537d9fb2ff88 100644
--- a/drivers/hwmon/ibmpex.c
+++ b/drivers/hwmon/ibmpex.c
@@ -608,3 +608,9 @@ MODULE_LICENSE("GPL");
608 608
609module_init(ibmpex_init); 609module_init(ibmpex_init);
610module_exit(ibmpex_exit); 610module_exit(ibmpex_exit);
611
612MODULE_ALIAS("dmi:bvnIBM:*:pnIBMSystemx3350-*");
613MODULE_ALIAS("dmi:bvnIBM:*:pnIBMSystemx3550-*");
614MODULE_ALIAS("dmi:bvnIBM:*:pnIBMSystemx3650-*");
615MODULE_ALIAS("dmi:bvnIBM:*:pnIBMSystemx3655-*");
616MODULE_ALIAS("dmi:bvnIBM:*:pnIBMSystemx3755-*");
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index d793cc011990..b74c95735f95 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -477,7 +477,7 @@ static ssize_t show_sensor(struct device *dev, struct device_attribute *attr,
477 if (reg & (1 << nr)) 477 if (reg & (1 << nr))
478 return sprintf(buf, "3\n"); /* thermal diode */ 478 return sprintf(buf, "3\n"); /* thermal diode */
479 if (reg & (8 << nr)) 479 if (reg & (8 << nr))
480 return sprintf(buf, "2\n"); /* thermistor */ 480 return sprintf(buf, "4\n"); /* thermistor */
481 return sprintf(buf, "0\n"); /* disabled */ 481 return sprintf(buf, "0\n"); /* disabled */
482} 482}
483static ssize_t set_sensor(struct device *dev, struct device_attribute *attr, 483static ssize_t set_sensor(struct device *dev, struct device_attribute *attr,
@@ -493,10 +493,15 @@ static ssize_t set_sensor(struct device *dev, struct device_attribute *attr,
493 493
494 data->sensor &= ~(1 << nr); 494 data->sensor &= ~(1 << nr);
495 data->sensor &= ~(8 << nr); 495 data->sensor &= ~(8 << nr);
496 /* 3 = thermal diode; 2 = thermistor; 0 = disabled */ 496 if (val == 2) { /* backwards compatibility */
497 dev_warn(dev, "Sensor type 2 is deprecated, please use 4 "
498 "instead\n");
499 val = 4;
500 }
501 /* 3 = thermal diode; 4 = thermistor; 0 = disabled */
497 if (val == 3) 502 if (val == 3)
498 data->sensor |= 1 << nr; 503 data->sensor |= 1 << nr;
499 else if (val == 2) 504 else if (val == 4)
500 data->sensor |= 8 << nr; 505 data->sensor |= 8 << nr;
501 else if (val != 0) { 506 else if (val != 0) {
502 mutex_unlock(&data->update_lock); 507 mutex_unlock(&data->update_lock);
diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c
index ed7859f0e16a..b5e3b2851698 100644
--- a/drivers/hwmon/lm78.c
+++ b/drivers/hwmon/lm78.c
@@ -114,25 +114,16 @@ static inline int TEMP_FROM_REG(s8 val)
114 114
115#define DIV_FROM_REG(val) (1 << (val)) 115#define DIV_FROM_REG(val) (1 << (val))
116 116
117/* There are some complications in a module like this. First off, LM78 chips
118 may be both present on the SMBus and the ISA bus, and we have to handle
119 those cases separately at some places. Second, there might be several
120 LM78 chips available (well, actually, that is probably never done; but
121 it is a clean illustration of how to handle a case like that). Finally,
122 a specific chip may be attached to *both* ISA and SMBus, and we would
123 not like to detect it double. Fortunately, in the case of the LM78 at
124 least, a register tells us what SMBus address we are on, so that helps
125 a bit - except if there could be more than one SMBus. Groan. No solution
126 for this yet. */
127
128/* For ISA chips, we abuse the i2c_client addr and name fields. We also use
129 the driver field to differentiate between I2C and ISA chips. */
130struct lm78_data { 117struct lm78_data {
131 struct i2c_client client; 118 struct i2c_client *client;
132 struct device *hwmon_dev; 119 struct device *hwmon_dev;
133 struct mutex lock; 120 struct mutex lock;
134 enum chips type; 121 enum chips type;
135 122
123 /* For ISA device only */
124 const char *name;
125 int isa_addr;
126
136 struct mutex update_lock; 127 struct mutex update_lock;
137 char valid; /* !=0 if following fields are valid */ 128 char valid; /* !=0 if following fields are valid */
138 unsigned long last_updated; /* In jiffies */ 129 unsigned long last_updated; /* In jiffies */
@@ -151,9 +142,11 @@ struct lm78_data {
151}; 142};
152 143
153 144
154static int lm78_attach_adapter(struct i2c_adapter *adapter); 145static int lm78_i2c_detect(struct i2c_client *client, int kind,
155static int lm78_detect(struct i2c_adapter *adapter, int address, int kind); 146 struct i2c_board_info *info);
156static int lm78_detach_client(struct i2c_client *client); 147static int lm78_i2c_probe(struct i2c_client *client,
148 const struct i2c_device_id *id);
149static int lm78_i2c_remove(struct i2c_client *client);
157 150
158static int __devinit lm78_isa_probe(struct platform_device *pdev); 151static int __devinit lm78_isa_probe(struct platform_device *pdev);
159static int __devexit lm78_isa_remove(struct platform_device *pdev); 152static int __devexit lm78_isa_remove(struct platform_device *pdev);
@@ -164,12 +157,23 @@ static struct lm78_data *lm78_update_device(struct device *dev);
164static void lm78_init_device(struct lm78_data *data); 157static void lm78_init_device(struct lm78_data *data);
165 158
166 159
160static const struct i2c_device_id lm78_i2c_id[] = {
161 { "lm78", lm78 },
162 { "lm79", lm79 },
163 { }
164};
165MODULE_DEVICE_TABLE(i2c, lm78_i2c_id);
166
167static struct i2c_driver lm78_driver = { 167static struct i2c_driver lm78_driver = {
168 .class = I2C_CLASS_HWMON,
168 .driver = { 169 .driver = {
169 .name = "lm78", 170 .name = "lm78",
170 }, 171 },
171 .attach_adapter = lm78_attach_adapter, 172 .probe = lm78_i2c_probe,
172 .detach_client = lm78_detach_client, 173 .remove = lm78_i2c_remove,
174 .id_table = lm78_i2c_id,
175 .detect = lm78_i2c_detect,
176 .address_data = &addr_data,
173}; 177};
174 178
175static struct platform_driver lm78_isa_driver = { 179static struct platform_driver lm78_isa_driver = {
@@ -454,17 +458,6 @@ static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7);
454static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 11); 458static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 11);
455static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4); 459static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4);
456 460
457/* This function is called when:
458 * lm78_driver is inserted (when this module is loaded), for each
459 available adapter
460 * when a new adapter is inserted (and lm78_driver is still present) */
461static int lm78_attach_adapter(struct i2c_adapter *adapter)
462{
463 if (!(adapter->class & I2C_CLASS_HWMON))
464 return 0;
465 return i2c_probe(adapter, &addr_data, lm78_detect);
466}
467
468static struct attribute *lm78_attributes[] = { 461static struct attribute *lm78_attributes[] = {
469 &sensor_dev_attr_in0_input.dev_attr.attr, 462 &sensor_dev_attr_in0_input.dev_attr.attr,
470 &sensor_dev_attr_in0_min.dev_attr.attr, 463 &sensor_dev_attr_in0_min.dev_attr.attr,
@@ -527,54 +520,77 @@ static ssize_t show_name(struct device *dev, struct device_attribute
527{ 520{
528 struct lm78_data *data = dev_get_drvdata(dev); 521 struct lm78_data *data = dev_get_drvdata(dev);
529 522
530 return sprintf(buf, "%s\n", data->client.name); 523 return sprintf(buf, "%s\n", data->name);
531} 524}
532static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); 525static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
533 526
534/* This function is called by i2c_probe */ 527/* Returns 1 if the I2C chip appears to be an alias of the ISA chip */
535static int lm78_detect(struct i2c_adapter *adapter, int address, int kind) 528static int lm78_alias_detect(struct i2c_client *client, u8 chipid)
536{ 529{
537 int i, err; 530 struct lm78_data *isa;
538 struct i2c_client *new_client; 531 int i;
539 struct lm78_data *data;
540 const char *client_name = "";
541 532
542 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 533 if (!pdev) /* No ISA chip */
543 err = -ENODEV; 534 return 0;
544 goto ERROR1; 535 isa = platform_get_drvdata(pdev);
536
537 if (lm78_read_value(isa, LM78_REG_I2C_ADDR) != client->addr)
538 return 0; /* Address doesn't match */
539 if ((lm78_read_value(isa, LM78_REG_CHIPID) & 0xfe) != (chipid & 0xfe))
540 return 0; /* Chip type doesn't match */
541
542 /* We compare all the limit registers, the config register and the
543 * interrupt mask registers */
544 for (i = 0x2b; i <= 0x3d; i++) {
545 if (lm78_read_value(isa, i) !=
546 i2c_smbus_read_byte_data(client, i))
547 return 0;
545 } 548 }
549 if (lm78_read_value(isa, LM78_REG_CONFIG) !=
550 i2c_smbus_read_byte_data(client, LM78_REG_CONFIG))
551 return 0;
552 for (i = 0x43; i <= 0x46; i++) {
553 if (lm78_read_value(isa, i) !=
554 i2c_smbus_read_byte_data(client, i))
555 return 0;
556 }
557
558 return 1;
559}
546 560
547 /* OK. For now, we presume we have a valid client. We now create the 561static int lm78_i2c_detect(struct i2c_client *client, int kind,
548 client structure, even though we cannot fill it completely yet. 562 struct i2c_board_info *info)
549 But it allows us to access lm78_{read,write}_value. */ 563{
564 int i;
565 struct lm78_data *isa = pdev ? platform_get_drvdata(pdev) : NULL;
566 const char *client_name;
567 struct i2c_adapter *adapter = client->adapter;
568 int address = client->addr;
550 569
551 if (!(data = kzalloc(sizeof(struct lm78_data), GFP_KERNEL))) { 570 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
552 err = -ENOMEM; 571 return -ENODEV;
553 goto ERROR1;
554 }
555 572
556 new_client = &data->client; 573 /* We block updates of the ISA device to minimize the risk of
557 i2c_set_clientdata(new_client, data); 574 concurrent access to the same LM78 chip through different
558 new_client->addr = address; 575 interfaces. */
559 new_client->adapter = adapter; 576 if (isa)
560 new_client->driver = &lm78_driver; 577 mutex_lock(&isa->update_lock);
561 578
562 /* Now, we do the remaining detection. */
563 if (kind < 0) { 579 if (kind < 0) {
564 if (lm78_read_value(data, LM78_REG_CONFIG) & 0x80) { 580 if ((i2c_smbus_read_byte_data(client, LM78_REG_CONFIG) & 0x80)
565 err = -ENODEV; 581 || i2c_smbus_read_byte_data(client, LM78_REG_I2C_ADDR)
566 goto ERROR2; 582 != address)
567 } 583 goto err_nodev;
568 if (lm78_read_value(data, LM78_REG_I2C_ADDR) != 584
569 address) { 585 /* Explicitly prevent the misdetection of Winbond chips */
570 err = -ENODEV; 586 i = i2c_smbus_read_byte_data(client, 0x4f);
571 goto ERROR2; 587 if (i == 0xa3 || i == 0x5c)
572 } 588 goto err_nodev;
573 } 589 }
574 590
575 /* Determine the chip type. */ 591 /* Determine the chip type. */
576 if (kind <= 0) { 592 if (kind <= 0) {
577 i = lm78_read_value(data, LM78_REG_CHIPID); 593 i = i2c_smbus_read_byte_data(client, LM78_REG_CHIPID);
578 if (i == 0x00 || i == 0x20 /* LM78 */ 594 if (i == 0x00 || i == 0x20 /* LM78 */
579 || i == 0x40) /* LM78-J */ 595 || i == 0x40) /* LM78-J */
580 kind = lm78; 596 kind = lm78;
@@ -586,33 +602,59 @@ static int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
586 "parameter for unknown chip at " 602 "parameter for unknown chip at "
587 "adapter %d, address 0x%02x\n", 603 "adapter %d, address 0x%02x\n",
588 i2c_adapter_id(adapter), address); 604 i2c_adapter_id(adapter), address);
589 err = -ENODEV; 605 goto err_nodev;
590 goto ERROR2; 606 }
607
608 if (lm78_alias_detect(client, i)) {
609 dev_dbg(&adapter->dev, "Device at 0x%02x appears to "
610 "be the same as ISA device\n", address);
611 goto err_nodev;
591 } 612 }
592 } 613 }
593 614
594 if (kind == lm78) { 615 if (isa)
595 client_name = "lm78"; 616 mutex_unlock(&isa->update_lock);
596 } else if (kind == lm79) { 617
618 switch (kind) {
619 case lm79:
597 client_name = "lm79"; 620 client_name = "lm79";
621 break;
622 default:
623 client_name = "lm78";
598 } 624 }
625 strlcpy(info->type, client_name, I2C_NAME_SIZE);
626
627 return 0;
628
629 err_nodev:
630 if (isa)
631 mutex_unlock(&isa->update_lock);
632 return -ENODEV;
633}
634
635static int lm78_i2c_probe(struct i2c_client *client,
636 const struct i2c_device_id *id)
637{
638 struct lm78_data *data;
639 int err;
599 640
600 /* Fill in the remaining client fields and put into the global list */ 641 data = kzalloc(sizeof(struct lm78_data), GFP_KERNEL);
601 strlcpy(new_client->name, client_name, I2C_NAME_SIZE); 642 if (!data)
602 data->type = kind; 643 return -ENOMEM;
603 644
604 /* Tell the I2C layer a new client has arrived */ 645 i2c_set_clientdata(client, data);
605 if ((err = i2c_attach_client(new_client))) 646 data->client = client;
606 goto ERROR2; 647 data->type = id->driver_data;
607 648
608 /* Initialize the LM78 chip */ 649 /* Initialize the LM78 chip */
609 lm78_init_device(data); 650 lm78_init_device(data);
610 651
611 /* Register sysfs hooks */ 652 /* Register sysfs hooks */
612 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm78_group))) 653 err = sysfs_create_group(&client->dev.kobj, &lm78_group);
654 if (err)
613 goto ERROR3; 655 goto ERROR3;
614 656
615 data->hwmon_dev = hwmon_device_register(&new_client->dev); 657 data->hwmon_dev = hwmon_device_register(&client->dev);
616 if (IS_ERR(data->hwmon_dev)) { 658 if (IS_ERR(data->hwmon_dev)) {
617 err = PTR_ERR(data->hwmon_dev); 659 err = PTR_ERR(data->hwmon_dev);
618 goto ERROR4; 660 goto ERROR4;
@@ -621,26 +663,18 @@ static int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
621 return 0; 663 return 0;
622 664
623ERROR4: 665ERROR4:
624 sysfs_remove_group(&new_client->dev.kobj, &lm78_group); 666 sysfs_remove_group(&client->dev.kobj, &lm78_group);
625ERROR3: 667ERROR3:
626 i2c_detach_client(new_client);
627ERROR2:
628 kfree(data); 668 kfree(data);
629ERROR1:
630 return err; 669 return err;
631} 670}
632 671
633static int lm78_detach_client(struct i2c_client *client) 672static int lm78_i2c_remove(struct i2c_client *client)
634{ 673{
635 struct lm78_data *data = i2c_get_clientdata(client); 674 struct lm78_data *data = i2c_get_clientdata(client);
636 int err;
637 675
638 hwmon_device_unregister(data->hwmon_dev); 676 hwmon_device_unregister(data->hwmon_dev);
639 sysfs_remove_group(&client->dev.kobj, &lm78_group); 677 sysfs_remove_group(&client->dev.kobj, &lm78_group);
640
641 if ((err = i2c_detach_client(client)))
642 return err;
643
644 kfree(data); 678 kfree(data);
645 679
646 return 0; 680 return 0;
@@ -651,11 +685,10 @@ static int __devinit lm78_isa_probe(struct platform_device *pdev)
651 int err; 685 int err;
652 struct lm78_data *data; 686 struct lm78_data *data;
653 struct resource *res; 687 struct resource *res;
654 const char *name;
655 688
656 /* Reserve the ISA region */ 689 /* Reserve the ISA region */
657 res = platform_get_resource(pdev, IORESOURCE_IO, 0); 690 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
658 if (!request_region(res->start, LM78_EXTENT, "lm78")) { 691 if (!request_region(res->start + LM78_ADDR_REG_OFFSET, 2, "lm78")) {
659 err = -EBUSY; 692 err = -EBUSY;
660 goto exit; 693 goto exit;
661 } 694 }
@@ -665,18 +698,16 @@ static int __devinit lm78_isa_probe(struct platform_device *pdev)
665 goto exit_release_region; 698 goto exit_release_region;
666 } 699 }
667 mutex_init(&data->lock); 700 mutex_init(&data->lock);
668 data->client.addr = res->start; 701 data->isa_addr = res->start;
669 i2c_set_clientdata(&data->client, data);
670 platform_set_drvdata(pdev, data); 702 platform_set_drvdata(pdev, data);
671 703
672 if (lm78_read_value(data, LM78_REG_CHIPID) & 0x80) { 704 if (lm78_read_value(data, LM78_REG_CHIPID) & 0x80) {
673 data->type = lm79; 705 data->type = lm79;
674 name = "lm79"; 706 data->name = "lm79";
675 } else { 707 } else {
676 data->type = lm78; 708 data->type = lm78;
677 name = "lm78"; 709 data->name = "lm78";
678 } 710 }
679 strlcpy(data->client.name, name, I2C_NAME_SIZE);
680 711
681 /* Initialize the LM78 chip */ 712 /* Initialize the LM78 chip */
682 lm78_init_device(data); 713 lm78_init_device(data);
@@ -699,7 +730,7 @@ static int __devinit lm78_isa_probe(struct platform_device *pdev)
699 device_remove_file(&pdev->dev, &dev_attr_name); 730 device_remove_file(&pdev->dev, &dev_attr_name);
700 kfree(data); 731 kfree(data);
701 exit_release_region: 732 exit_release_region:
702 release_region(res->start, LM78_EXTENT); 733 release_region(res->start + LM78_ADDR_REG_OFFSET, 2);
703 exit: 734 exit:
704 return err; 735 return err;
705} 736}
@@ -707,13 +738,16 @@ static int __devinit lm78_isa_probe(struct platform_device *pdev)
707static int __devexit lm78_isa_remove(struct platform_device *pdev) 738static int __devexit lm78_isa_remove(struct platform_device *pdev)
708{ 739{
709 struct lm78_data *data = platform_get_drvdata(pdev); 740 struct lm78_data *data = platform_get_drvdata(pdev);
741 struct resource *res;
710 742
711 hwmon_device_unregister(data->hwmon_dev); 743 hwmon_device_unregister(data->hwmon_dev);
712 sysfs_remove_group(&pdev->dev.kobj, &lm78_group); 744 sysfs_remove_group(&pdev->dev.kobj, &lm78_group);
713 device_remove_file(&pdev->dev, &dev_attr_name); 745 device_remove_file(&pdev->dev, &dev_attr_name);
714 release_region(data->client.addr, LM78_EXTENT);
715 kfree(data); 746 kfree(data);
716 747
748 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
749 release_region(res->start + LM78_ADDR_REG_OFFSET, 2);
750
717 return 0; 751 return 0;
718} 752}
719 753
@@ -724,13 +758,13 @@ static int __devexit lm78_isa_remove(struct platform_device *pdev)
724 would slow down the LM78 access and should not be necessary. */ 758 would slow down the LM78 access and should not be necessary. */
725static int lm78_read_value(struct lm78_data *data, u8 reg) 759static int lm78_read_value(struct lm78_data *data, u8 reg)
726{ 760{
727 struct i2c_client *client = &data->client; 761 struct i2c_client *client = data->client;
728 762
729 if (!client->driver) { /* ISA device */ 763 if (!client) { /* ISA device */
730 int res; 764 int res;
731 mutex_lock(&data->lock); 765 mutex_lock(&data->lock);
732 outb_p(reg, client->addr + LM78_ADDR_REG_OFFSET); 766 outb_p(reg, data->isa_addr + LM78_ADDR_REG_OFFSET);
733 res = inb_p(client->addr + LM78_DATA_REG_OFFSET); 767 res = inb_p(data->isa_addr + LM78_DATA_REG_OFFSET);
734 mutex_unlock(&data->lock); 768 mutex_unlock(&data->lock);
735 return res; 769 return res;
736 } else 770 } else
@@ -746,12 +780,12 @@ static int lm78_read_value(struct lm78_data *data, u8 reg)
746 nowhere else be necessary! */ 780 nowhere else be necessary! */
747static int lm78_write_value(struct lm78_data *data, u8 reg, u8 value) 781static int lm78_write_value(struct lm78_data *data, u8 reg, u8 value)
748{ 782{
749 struct i2c_client *client = &data->client; 783 struct i2c_client *client = data->client;
750 784
751 if (!client->driver) { /* ISA device */ 785 if (!client) { /* ISA device */
752 mutex_lock(&data->lock); 786 mutex_lock(&data->lock);
753 outb_p(reg, client->addr + LM78_ADDR_REG_OFFSET); 787 outb_p(reg, data->isa_addr + LM78_ADDR_REG_OFFSET);
754 outb_p(value, client->addr + LM78_DATA_REG_OFFSET); 788 outb_p(value, data->isa_addr + LM78_DATA_REG_OFFSET);
755 mutex_unlock(&data->lock); 789 mutex_unlock(&data->lock);
756 return 0; 790 return 0;
757 } else 791 } else
@@ -837,8 +871,17 @@ static int __init lm78_isa_found(unsigned short address)
837{ 871{
838 int val, save, found = 0; 872 int val, save, found = 0;
839 873
840 if (!request_region(address, LM78_EXTENT, "lm78")) 874 /* We have to request the region in two parts because some
875 boards declare base+4 to base+7 as a PNP device */
876 if (!request_region(address, 4, "lm78")) {
877 pr_debug("lm78: Failed to request low part of region\n");
841 return 0; 878 return 0;
879 }
880 if (!request_region(address + 4, 4, "lm78")) {
881 pr_debug("lm78: Failed to request high part of region\n");
882 release_region(address, 4);
883 return 0;
884 }
842 885
843#define REALLY_SLOW_IO 886#define REALLY_SLOW_IO
844 /* We need the timeouts for at least some LM78-like 887 /* We need the timeouts for at least some LM78-like
@@ -901,7 +944,8 @@ static int __init lm78_isa_found(unsigned short address)
901 val & 0x80 ? "LM79" : "LM78", (int)address); 944 val & 0x80 ? "LM79" : "LM78", (int)address);
902 945
903 release: 946 release:
904 release_region(address, LM78_EXTENT); 947 release_region(address + 4, 4);
948 release_region(address, 4);
905 return found; 949 return found;
906} 950}
907 951
@@ -949,14 +993,12 @@ static int __init sm_lm78_init(void)
949{ 993{
950 int res; 994 int res;
951 995
952 res = i2c_add_driver(&lm78_driver); 996 /* We register the ISA device first, so that we can skip the
953 if (res) 997 * registration of an I2C interface to the same device. */
954 goto exit;
955
956 if (lm78_isa_found(isa_address)) { 998 if (lm78_isa_found(isa_address)) {
957 res = platform_driver_register(&lm78_isa_driver); 999 res = platform_driver_register(&lm78_isa_driver);
958 if (res) 1000 if (res)
959 goto exit_unreg_i2c_driver; 1001 goto exit;
960 1002
961 /* Sets global pdev as a side effect */ 1003 /* Sets global pdev as a side effect */
962 res = lm78_isa_device_add(isa_address); 1004 res = lm78_isa_device_add(isa_address);
@@ -964,12 +1006,16 @@ static int __init sm_lm78_init(void)
964 goto exit_unreg_isa_driver; 1006 goto exit_unreg_isa_driver;
965 } 1007 }
966 1008
1009 res = i2c_add_driver(&lm78_driver);
1010 if (res)
1011 goto exit_unreg_isa_device;
1012
967 return 0; 1013 return 0;
968 1014
1015 exit_unreg_isa_device:
1016 platform_device_unregister(pdev);
969 exit_unreg_isa_driver: 1017 exit_unreg_isa_driver:
970 platform_driver_unregister(&lm78_isa_driver); 1018 platform_driver_unregister(&lm78_isa_driver);
971 exit_unreg_i2c_driver:
972 i2c_del_driver(&lm78_driver);
973 exit: 1019 exit:
974 return res; 1020 return res;
975} 1021}
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c
index 12d446f54f97..3ff0285396fa 100644
--- a/drivers/hwmon/lm85.c
+++ b/drivers/hwmon/lm85.c
@@ -5,6 +5,7 @@
5 Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com> 5 Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
6 Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de> 6 Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de>
7 Copyright (c) 2004 Justin Thiessen <jthiessen@penguincomputing.com> 7 Copyright (c) 2004 Justin Thiessen <jthiessen@penguincomputing.com>
8 Copyright (C) 2007, 2008 Jean Delvare <khali@linux-fr.org>
8 9
9 Chip details at <http://www.national.com/ds/LM/LM85.pdf> 10 Chip details at <http://www.national.com/ds/LM/LM85.pdf>
10 11
@@ -173,40 +174,39 @@ static int RANGE_TO_REG(int range)
173{ 174{
174 int i; 175 int i;
175 176
176 if (range >= lm85_range_map[15])
177 return 15;
178
179 /* Find the closest match */ 177 /* Find the closest match */
180 for (i = 14; i >= 0; --i) { 178 for (i = 0; i < 15; ++i) {
181 if (range >= lm85_range_map[i]) { 179 if (range <= (lm85_range_map[i] + lm85_range_map[i + 1]) / 2)
182 if ((lm85_range_map[i + 1] - range) < 180 break;
183 (range - lm85_range_map[i]))
184 return i + 1;
185 return i;
186 }
187 } 181 }
188 182
189 return 0; 183 return i;
190} 184}
191#define RANGE_FROM_REG(val) lm85_range_map[(val) & 0x0f] 185#define RANGE_FROM_REG(val) lm85_range_map[(val) & 0x0f]
192 186
193/* These are the PWM frequency encodings */ 187/* These are the PWM frequency encodings */
194static const int lm85_freq_map[] = { /* .1 Hz */ 188static const int lm85_freq_map[8] = { /* 1 Hz */
195 100, 150, 230, 300, 380, 470, 620, 940 189 10, 15, 23, 30, 38, 47, 61, 94
190};
191static const int adm1027_freq_map[8] = { /* 1 Hz */
192 11, 15, 22, 29, 35, 44, 59, 88
196}; 193};
197 194
198static int FREQ_TO_REG(int freq) 195static int FREQ_TO_REG(const int *map, int freq)
199{ 196{
200 int i; 197 int i;
201 198
202 if (freq >= lm85_freq_map[7]) 199 /* Find the closest match */
203 return 7;
204 for (i = 0; i < 7; ++i) 200 for (i = 0; i < 7; ++i)
205 if (freq <= lm85_freq_map[i]) 201 if (freq <= (map[i] + map[i + 1]) / 2)
206 break; 202 break;
207 return i; 203 return i;
208} 204}
209#define FREQ_FROM_REG(val) lm85_freq_map[(val) & 0x07] 205
206static int FREQ_FROM_REG(const int *map, u8 reg)
207{
208 return map[reg & 0x07];
209}
210 210
211/* Since we can't use strings, I'm abusing these numbers 211/* Since we can't use strings, I'm abusing these numbers
212 * to stand in for the following meanings: 212 * to stand in for the following meanings:
@@ -275,7 +275,6 @@ struct lm85_zone {
275 275
276struct lm85_autofan { 276struct lm85_autofan {
277 u8 config; /* Register value */ 277 u8 config; /* Register value */
278 u8 freq; /* PWM frequency, encoded */
279 u8 min_pwm; /* Minimum PWM value, encoded */ 278 u8 min_pwm; /* Minimum PWM value, encoded */
280 u8 min_off; /* Min PWM or OFF below "limit", flag */ 279 u8 min_off; /* Min PWM or OFF below "limit", flag */
281}; 280};
@@ -283,8 +282,8 @@ struct lm85_autofan {
283/* For each registered chip, we need to keep some data in memory. 282/* For each registered chip, we need to keep some data in memory.
284 The structure is dynamically allocated. */ 283 The structure is dynamically allocated. */
285struct lm85_data { 284struct lm85_data {
286 struct i2c_client client;
287 struct device *hwmon_dev; 285 struct device *hwmon_dev;
286 const int *freq_map;
288 enum chips type; 287 enum chips type;
289 288
290 struct mutex update_lock; 289 struct mutex update_lock;
@@ -301,6 +300,7 @@ struct lm85_data {
301 u16 fan[4]; /* Register value */ 300 u16 fan[4]; /* Register value */
302 u16 fan_min[4]; /* Register value */ 301 u16 fan_min[4]; /* Register value */
303 u8 pwm[3]; /* Register value */ 302 u8 pwm[3]; /* Register value */
303 u8 pwm_freq[3]; /* Register encoding */
304 u8 temp_ext[3]; /* Decoded values */ 304 u8 temp_ext[3]; /* Decoded values */
305 u8 in_ext[8]; /* Decoded values */ 305 u8 in_ext[8]; /* Decoded values */
306 u8 vid; /* Register value */ 306 u8 vid; /* Register value */
@@ -310,22 +310,40 @@ struct lm85_data {
310 struct lm85_zone zone[3]; 310 struct lm85_zone zone[3];
311}; 311};
312 312
313static int lm85_attach_adapter(struct i2c_adapter *adapter); 313static int lm85_detect(struct i2c_client *client, int kind,
314static int lm85_detect(struct i2c_adapter *adapter, int address, 314 struct i2c_board_info *info);
315 int kind); 315static int lm85_probe(struct i2c_client *client,
316static int lm85_detach_client(struct i2c_client *client); 316 const struct i2c_device_id *id);
317static int lm85_remove(struct i2c_client *client);
317 318
318static int lm85_read_value(struct i2c_client *client, u8 reg); 319static int lm85_read_value(struct i2c_client *client, u8 reg);
319static void lm85_write_value(struct i2c_client *client, u8 reg, int value); 320static void lm85_write_value(struct i2c_client *client, u8 reg, int value);
320static struct lm85_data *lm85_update_device(struct device *dev); 321static struct lm85_data *lm85_update_device(struct device *dev);
321 322
322 323
324static const struct i2c_device_id lm85_id[] = {
325 { "adm1027", adm1027 },
326 { "adt7463", adt7463 },
327 { "lm85", any_chip },
328 { "lm85b", lm85b },
329 { "lm85c", lm85c },
330 { "emc6d100", emc6d100 },
331 { "emc6d101", emc6d100 },
332 { "emc6d102", emc6d102 },
333 { }
334};
335MODULE_DEVICE_TABLE(i2c, lm85_id);
336
323static struct i2c_driver lm85_driver = { 337static struct i2c_driver lm85_driver = {
338 .class = I2C_CLASS_HWMON,
324 .driver = { 339 .driver = {
325 .name = "lm85", 340 .name = "lm85",
326 }, 341 },
327 .attach_adapter = lm85_attach_adapter, 342 .probe = lm85_probe,
328 .detach_client = lm85_detach_client, 343 .remove = lm85_remove,
344 .id_table = lm85_id,
345 .detect = lm85_detect,
346 .address_data = &addr_data,
329}; 347};
330 348
331 349
@@ -528,11 +546,39 @@ static ssize_t set_pwm_enable(struct device *dev, struct device_attribute
528 return count; 546 return count;
529} 547}
530 548
549static ssize_t show_pwm_freq(struct device *dev,
550 struct device_attribute *attr, char *buf)
551{
552 int nr = to_sensor_dev_attr(attr)->index;
553 struct lm85_data *data = lm85_update_device(dev);
554 return sprintf(buf, "%d\n", FREQ_FROM_REG(data->freq_map,
555 data->pwm_freq[nr]));
556}
557
558static ssize_t set_pwm_freq(struct device *dev,
559 struct device_attribute *attr, const char *buf, size_t count)
560{
561 int nr = to_sensor_dev_attr(attr)->index;
562 struct i2c_client *client = to_i2c_client(dev);
563 struct lm85_data *data = i2c_get_clientdata(client);
564 long val = simple_strtol(buf, NULL, 10);
565
566 mutex_lock(&data->update_lock);
567 data->pwm_freq[nr] = FREQ_TO_REG(data->freq_map, val);
568 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
569 (data->zone[nr].range << 4)
570 | data->pwm_freq[nr]);
571 mutex_unlock(&data->update_lock);
572 return count;
573}
574
531#define show_pwm_reg(offset) \ 575#define show_pwm_reg(offset) \
532static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \ 576static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
533 show_pwm, set_pwm, offset - 1); \ 577 show_pwm, set_pwm, offset - 1); \
534static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \ 578static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
535 show_pwm_enable, set_pwm_enable, offset - 1) 579 show_pwm_enable, set_pwm_enable, offset - 1); \
580static SENSOR_DEVICE_ATTR(pwm##offset##_freq, S_IRUGO | S_IWUSR, \
581 show_pwm_freq, set_pwm_freq, offset - 1)
536 582
537show_pwm_reg(1); 583show_pwm_reg(1);
538show_pwm_reg(2); 584show_pwm_reg(2);
@@ -761,31 +807,6 @@ static ssize_t set_pwm_auto_pwm_minctl(struct device *dev,
761 return count; 807 return count;
762} 808}
763 809
764static ssize_t show_pwm_auto_pwm_freq(struct device *dev,
765 struct device_attribute *attr, char *buf)
766{
767 int nr = to_sensor_dev_attr(attr)->index;
768 struct lm85_data *data = lm85_update_device(dev);
769 return sprintf(buf, "%d\n", FREQ_FROM_REG(data->autofan[nr].freq));
770}
771
772static ssize_t set_pwm_auto_pwm_freq(struct device *dev,
773 struct device_attribute *attr, const char *buf, size_t count)
774{
775 int nr = to_sensor_dev_attr(attr)->index;
776 struct i2c_client *client = to_i2c_client(dev);
777 struct lm85_data *data = i2c_get_clientdata(client);
778 long val = simple_strtol(buf, NULL, 10);
779
780 mutex_lock(&data->update_lock);
781 data->autofan[nr].freq = FREQ_TO_REG(val);
782 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
783 (data->zone[nr].range << 4)
784 | data->autofan[nr].freq);
785 mutex_unlock(&data->update_lock);
786 return count;
787}
788
789#define pwm_auto(offset) \ 810#define pwm_auto(offset) \
790static SENSOR_DEVICE_ATTR(pwm##offset##_auto_channels, \ 811static SENSOR_DEVICE_ATTR(pwm##offset##_auto_channels, \
791 S_IRUGO | S_IWUSR, show_pwm_auto_channels, \ 812 S_IRUGO | S_IWUSR, show_pwm_auto_channels, \
@@ -795,10 +816,7 @@ static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_min, \
795 set_pwm_auto_pwm_min, offset - 1); \ 816 set_pwm_auto_pwm_min, offset - 1); \
796static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_minctl, \ 817static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_minctl, \
797 S_IRUGO | S_IWUSR, show_pwm_auto_pwm_minctl, \ 818 S_IRUGO | S_IWUSR, show_pwm_auto_pwm_minctl, \
798 set_pwm_auto_pwm_minctl, offset - 1); \ 819 set_pwm_auto_pwm_minctl, offset - 1)
799static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_freq, \
800 S_IRUGO | S_IWUSR, show_pwm_auto_pwm_freq, \
801 set_pwm_auto_pwm_freq, offset - 1);
802 820
803pwm_auto(1); 821pwm_auto(1);
804pwm_auto(2); 822pwm_auto(2);
@@ -867,7 +885,7 @@ static ssize_t set_temp_auto_temp_min(struct device *dev,
867 TEMP_FROM_REG(data->zone[nr].limit)); 885 TEMP_FROM_REG(data->zone[nr].limit));
868 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), 886 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
869 ((data->zone[nr].range & 0x0f) << 4) 887 ((data->zone[nr].range & 0x0f) << 4)
870 | (data->autofan[nr].freq & 0x07)); 888 | (data->pwm_freq[nr] & 0x07));
871 889
872/* Update temp_auto_hyst and temp_auto_off */ 890/* Update temp_auto_hyst and temp_auto_off */
873 data->zone[nr].hyst = HYST_TO_REG(TEMP_FROM_REG( 891 data->zone[nr].hyst = HYST_TO_REG(TEMP_FROM_REG(
@@ -910,7 +928,7 @@ static ssize_t set_temp_auto_temp_max(struct device *dev,
910 val - min); 928 val - min);
911 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), 929 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
912 ((data->zone[nr].range & 0x0f) << 4) 930 ((data->zone[nr].range & 0x0f) << 4)
913 | (data->autofan[nr].freq & 0x07)); 931 | (data->pwm_freq[nr] & 0x07));
914 mutex_unlock(&data->update_lock); 932 mutex_unlock(&data->update_lock);
915 return count; 933 return count;
916} 934}
@@ -957,13 +975,6 @@ temp_auto(1);
957temp_auto(2); 975temp_auto(2);
958temp_auto(3); 976temp_auto(3);
959 977
960static int lm85_attach_adapter(struct i2c_adapter *adapter)
961{
962 if (!(adapter->class & I2C_CLASS_HWMON))
963 return 0;
964 return i2c_probe(adapter, &addr_data, lm85_detect);
965}
966
967static struct attribute *lm85_attributes[] = { 978static struct attribute *lm85_attributes[] = {
968 &sensor_dev_attr_fan1_input.dev_attr.attr, 979 &sensor_dev_attr_fan1_input.dev_attr.attr,
969 &sensor_dev_attr_fan2_input.dev_attr.attr, 980 &sensor_dev_attr_fan2_input.dev_attr.attr,
@@ -984,6 +995,9 @@ static struct attribute *lm85_attributes[] = {
984 &sensor_dev_attr_pwm1_enable.dev_attr.attr, 995 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
985 &sensor_dev_attr_pwm2_enable.dev_attr.attr, 996 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
986 &sensor_dev_attr_pwm3_enable.dev_attr.attr, 997 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
998 &sensor_dev_attr_pwm1_freq.dev_attr.attr,
999 &sensor_dev_attr_pwm2_freq.dev_attr.attr,
1000 &sensor_dev_attr_pwm3_freq.dev_attr.attr,
987 1001
988 &sensor_dev_attr_in0_input.dev_attr.attr, 1002 &sensor_dev_attr_in0_input.dev_attr.attr,
989 &sensor_dev_attr_in1_input.dev_attr.attr, 1003 &sensor_dev_attr_in1_input.dev_attr.attr,
@@ -1026,9 +1040,6 @@ static struct attribute *lm85_attributes[] = {
1026 &sensor_dev_attr_pwm1_auto_pwm_minctl.dev_attr.attr, 1040 &sensor_dev_attr_pwm1_auto_pwm_minctl.dev_attr.attr,
1027 &sensor_dev_attr_pwm2_auto_pwm_minctl.dev_attr.attr, 1041 &sensor_dev_attr_pwm2_auto_pwm_minctl.dev_attr.attr,
1028 &sensor_dev_attr_pwm3_auto_pwm_minctl.dev_attr.attr, 1042 &sensor_dev_attr_pwm3_auto_pwm_minctl.dev_attr.attr,
1029 &sensor_dev_attr_pwm1_auto_pwm_freq.dev_attr.attr,
1030 &sensor_dev_attr_pwm2_auto_pwm_freq.dev_attr.attr,
1031 &sensor_dev_attr_pwm3_auto_pwm_freq.dev_attr.attr,
1032 1043
1033 &sensor_dev_attr_temp1_auto_temp_off.dev_attr.attr, 1044 &sensor_dev_attr_temp1_auto_temp_off.dev_attr.attr,
1034 &sensor_dev_attr_temp2_auto_temp_off.dev_attr.attr, 1045 &sensor_dev_attr_temp2_auto_temp_off.dev_attr.attr,
@@ -1103,109 +1114,74 @@ static void lm85_init_client(struct i2c_client *client)
1103 dev_warn(&client->dev, "Device is not ready\n"); 1114 dev_warn(&client->dev, "Device is not ready\n");
1104} 1115}
1105 1116
1106static int lm85_detect(struct i2c_adapter *adapter, int address, 1117/* Return 0 if detection is successful, -ENODEV otherwise */
1107 int kind) 1118static int lm85_detect(struct i2c_client *client, int kind,
1119 struct i2c_board_info *info)
1108{ 1120{
1109 int company, verstep; 1121 struct i2c_adapter *adapter = client->adapter;
1110 struct i2c_client *client; 1122 int address = client->addr;
1111 struct lm85_data *data;
1112 int err = 0;
1113 const char *type_name; 1123 const char *type_name;
1114 1124
1115 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 1125 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
1116 /* We need to be able to do byte I/O */ 1126 /* We need to be able to do byte I/O */
1117 goto ERROR0; 1127 return -ENODEV;
1118 } 1128 }
1119 1129
1120 /* OK. For now, we presume we have a valid client. We now create the 1130 /* If auto-detecting, determine the chip type */
1121 client structure, even though we cannot fill it completely yet. 1131 if (kind < 0) {
1122 But it allows us to access lm85_{read,write}_value. */ 1132 int company = lm85_read_value(client, LM85_REG_COMPANY);
1133 int verstep = lm85_read_value(client, LM85_REG_VERSTEP);
1123 1134
1124 if (!(data = kzalloc(sizeof(struct lm85_data), GFP_KERNEL))) { 1135 dev_dbg(&adapter->dev, "Detecting device at 0x%02x with "
1125 err = -ENOMEM; 1136 "COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
1126 goto ERROR0; 1137 address, company, verstep);
1127 }
1128 1138
1129 client = &data->client; 1139 /* All supported chips have the version in common */
1130 i2c_set_clientdata(client, data); 1140 if ((verstep & LM85_VERSTEP_VMASK) != LM85_VERSTEP_GENERIC) {
1131 client->addr = address; 1141 dev_dbg(&adapter->dev, "Autodetection failed: "
1132 client->adapter = adapter; 1142 "unsupported version\n");
1133 client->driver = &lm85_driver; 1143 return -ENODEV;
1134 1144 }
1135 /* Now, we do the remaining detection. */ 1145 kind = any_chip;
1136 1146
1137 company = lm85_read_value(client, LM85_REG_COMPANY); 1147 /* Now, refine the detection */
1138 verstep = lm85_read_value(client, LM85_REG_VERSTEP); 1148 if (company == LM85_COMPANY_NATIONAL) {
1139 1149 switch (verstep) {
1140 dev_dbg(&adapter->dev, "Detecting device at %d,0x%02x with" 1150 case LM85_VERSTEP_LM85C:
1141 " COMPANY: 0x%02x and VERSTEP: 0x%02x\n", 1151 kind = lm85c;
1142 i2c_adapter_id(client->adapter), client->addr, 1152 break;
1143 company, verstep); 1153 case LM85_VERSTEP_LM85B:
1144 1154 kind = lm85b;
1145 /* If auto-detecting, Determine the chip type. */ 1155 break;
1146 if (kind <= 0) { 1156 }
1147 dev_dbg(&adapter->dev, "Autodetecting device at %d,0x%02x ...\n", 1157 } else if (company == LM85_COMPANY_ANALOG_DEV) {
1148 i2c_adapter_id(adapter), address); 1158 switch (verstep) {
1149 if (company == LM85_COMPANY_NATIONAL 1159 case LM85_VERSTEP_ADM1027:
1150 && verstep == LM85_VERSTEP_LM85C) { 1160 kind = adm1027;
1151 kind = lm85c; 1161 break;
1152 } else if (company == LM85_COMPANY_NATIONAL 1162 case LM85_VERSTEP_ADT7463:
1153 && verstep == LM85_VERSTEP_LM85B) { 1163 case LM85_VERSTEP_ADT7463C:
1154 kind = lm85b; 1164 kind = adt7463;
1155 } else if (company == LM85_COMPANY_NATIONAL 1165 break;
1156 && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) { 1166 }
1157 dev_err(&adapter->dev, "Unrecognized version/stepping 0x%02x" 1167 } else if (company == LM85_COMPANY_SMSC) {
1158 " Defaulting to LM85.\n", verstep); 1168 switch (verstep) {
1159 kind = any_chip; 1169 case LM85_VERSTEP_EMC6D100_A0:
1160 } else if (company == LM85_COMPANY_ANALOG_DEV 1170 case LM85_VERSTEP_EMC6D100_A1:
1161 && verstep == LM85_VERSTEP_ADM1027) { 1171 /* Note: we can't tell a '100 from a '101 */
1162 kind = adm1027; 1172 kind = emc6d100;
1163 } else if (company == LM85_COMPANY_ANALOG_DEV 1173 break;
1164 && (verstep == LM85_VERSTEP_ADT7463 1174 case LM85_VERSTEP_EMC6D102:
1165 || verstep == LM85_VERSTEP_ADT7463C)) { 1175 kind = emc6d102;
1166 kind = adt7463; 1176 break;
1167 } else if (company == LM85_COMPANY_ANALOG_DEV
1168 && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) {
1169 dev_err(&adapter->dev, "Unrecognized version/stepping 0x%02x"
1170 " Defaulting to Generic LM85.\n", verstep);
1171 kind = any_chip;
1172 } else if (company == LM85_COMPANY_SMSC
1173 && (verstep == LM85_VERSTEP_EMC6D100_A0
1174 || verstep == LM85_VERSTEP_EMC6D100_A1)) {
1175 /* Unfortunately, we can't tell a '100 from a '101
1176 * from the registers. Since a '101 is a '100
1177 * in a package with fewer pins and therefore no
1178 * 3.3V, 1.5V or 1.8V inputs, perhaps if those
1179 * inputs read 0, then it's a '101.
1180 */
1181 kind = emc6d100;
1182 } else if (company == LM85_COMPANY_SMSC
1183 && verstep == LM85_VERSTEP_EMC6D102) {
1184 kind = emc6d102;
1185 } else if (company == LM85_COMPANY_SMSC
1186 && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) {
1187 dev_err(&adapter->dev, "lm85: Detected SMSC chip\n");
1188 dev_err(&adapter->dev, "lm85: Unrecognized version/stepping 0x%02x"
1189 " Defaulting to Generic LM85.\n", verstep);
1190 kind = any_chip;
1191 } else if (kind == any_chip
1192 && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) {
1193 dev_err(&adapter->dev, "Generic LM85 Version 6 detected\n");
1194 /* Leave kind as "any_chip" */
1195 } else {
1196 dev_dbg(&adapter->dev, "Autodetection failed\n");
1197 /* Not an LM85... */
1198 if (kind == any_chip) { /* User used force=x,y */
1199 dev_err(&adapter->dev, "Generic LM85 Version 6 not"
1200 " found at %d,0x%02x. Try force_lm85c.\n",
1201 i2c_adapter_id(adapter), address);
1202 } 1177 }
1203 err = 0; 1178 } else {
1204 goto ERROR1; 1179 dev_dbg(&adapter->dev, "Autodetection failed: "
1180 "unknown vendor\n");
1181 return -ENODEV;
1205 } 1182 }
1206 } 1183 }
1207 1184
1208 /* Fill in the chip specific driver values */
1209 switch (kind) { 1185 switch (kind) {
1210 case lm85b: 1186 case lm85b:
1211 type_name = "lm85b"; 1187 type_name = "lm85b";
@@ -1228,16 +1204,36 @@ static int lm85_detect(struct i2c_adapter *adapter, int address,
1228 default: 1204 default:
1229 type_name = "lm85"; 1205 type_name = "lm85";
1230 } 1206 }
1231 strlcpy(client->name, type_name, I2C_NAME_SIZE); 1207 strlcpy(info->type, type_name, I2C_NAME_SIZE);
1208
1209 return 0;
1210}
1232 1211
1233 /* Fill in the remaining client fields */ 1212static int lm85_probe(struct i2c_client *client,
1234 data->type = kind; 1213 const struct i2c_device_id *id)
1214{
1215 struct lm85_data *data;
1216 int err;
1217
1218 data = kzalloc(sizeof(struct lm85_data), GFP_KERNEL);
1219 if (!data)
1220 return -ENOMEM;
1221
1222 i2c_set_clientdata(client, data);
1223 data->type = id->driver_data;
1235 mutex_init(&data->update_lock); 1224 mutex_init(&data->update_lock);
1236 1225
1237 /* Tell the I2C layer a new client has arrived */ 1226 /* Fill in the chip specific driver values */
1238 err = i2c_attach_client(client); 1227 switch (data->type) {
1239 if (err) 1228 case adm1027:
1240 goto ERROR1; 1229 case adt7463:
1230 case emc6d100:
1231 case emc6d102:
1232 data->freq_map = adm1027_freq_map;
1233 break;
1234 default:
1235 data->freq_map = lm85_freq_map;
1236 }
1241 1237
1242 /* Set the VRM version */ 1238 /* Set the VRM version */
1243 data->vrm = vid_which_vrm(); 1239 data->vrm = vid_which_vrm();
@@ -1248,45 +1244,42 @@ static int lm85_detect(struct i2c_adapter *adapter, int address,
1248 /* Register sysfs hooks */ 1244 /* Register sysfs hooks */
1249 err = sysfs_create_group(&client->dev.kobj, &lm85_group); 1245 err = sysfs_create_group(&client->dev.kobj, &lm85_group);
1250 if (err) 1246 if (err)
1251 goto ERROR2; 1247 goto err_kfree;
1252 1248
1253 /* The ADT7463 has an optional VRM 10 mode where pin 21 is used 1249 /* The ADT7463 has an optional VRM 10 mode where pin 21 is used
1254 as a sixth digital VID input rather than an analog input. */ 1250 as a sixth digital VID input rather than an analog input. */
1255 data->vid = lm85_read_value(client, LM85_REG_VID); 1251 data->vid = lm85_read_value(client, LM85_REG_VID);
1256 if (!(kind == adt7463 && (data->vid & 0x80))) 1252 if (!(data->type == adt7463 && (data->vid & 0x80)))
1257 if ((err = sysfs_create_group(&client->dev.kobj, 1253 if ((err = sysfs_create_group(&client->dev.kobj,
1258 &lm85_group_in4))) 1254 &lm85_group_in4)))
1259 goto ERROR3; 1255 goto err_remove_files;
1260 1256
1261 /* The EMC6D100 has 3 additional voltage inputs */ 1257 /* The EMC6D100 has 3 additional voltage inputs */
1262 if (kind == emc6d100) 1258 if (data->type == emc6d100)
1263 if ((err = sysfs_create_group(&client->dev.kobj, 1259 if ((err = sysfs_create_group(&client->dev.kobj,
1264 &lm85_group_in567))) 1260 &lm85_group_in567)))
1265 goto ERROR3; 1261 goto err_remove_files;
1266 1262
1267 data->hwmon_dev = hwmon_device_register(&client->dev); 1263 data->hwmon_dev = hwmon_device_register(&client->dev);
1268 if (IS_ERR(data->hwmon_dev)) { 1264 if (IS_ERR(data->hwmon_dev)) {
1269 err = PTR_ERR(data->hwmon_dev); 1265 err = PTR_ERR(data->hwmon_dev);
1270 goto ERROR3; 1266 goto err_remove_files;
1271 } 1267 }
1272 1268
1273 return 0; 1269 return 0;
1274 1270
1275 /* Error out and cleanup code */ 1271 /* Error out and cleanup code */
1276 ERROR3: 1272 err_remove_files:
1277 sysfs_remove_group(&client->dev.kobj, &lm85_group); 1273 sysfs_remove_group(&client->dev.kobj, &lm85_group);
1278 sysfs_remove_group(&client->dev.kobj, &lm85_group_in4); 1274 sysfs_remove_group(&client->dev.kobj, &lm85_group_in4);
1279 if (kind == emc6d100) 1275 if (data->type == emc6d100)
1280 sysfs_remove_group(&client->dev.kobj, &lm85_group_in567); 1276 sysfs_remove_group(&client->dev.kobj, &lm85_group_in567);
1281 ERROR2: 1277 err_kfree:
1282 i2c_detach_client(client);
1283 ERROR1:
1284 kfree(data); 1278 kfree(data);
1285 ERROR0:
1286 return err; 1279 return err;
1287} 1280}
1288 1281
1289static int lm85_detach_client(struct i2c_client *client) 1282static int lm85_remove(struct i2c_client *client)
1290{ 1283{
1291 struct lm85_data *data = i2c_get_clientdata(client); 1284 struct lm85_data *data = i2c_get_clientdata(client);
1292 hwmon_device_unregister(data->hwmon_dev); 1285 hwmon_device_unregister(data->hwmon_dev);
@@ -1294,7 +1287,6 @@ static int lm85_detach_client(struct i2c_client *client)
1294 sysfs_remove_group(&client->dev.kobj, &lm85_group_in4); 1287 sysfs_remove_group(&client->dev.kobj, &lm85_group_in4);
1295 if (data->type == emc6d100) 1288 if (data->type == emc6d100)
1296 sysfs_remove_group(&client->dev.kobj, &lm85_group_in567); 1289 sysfs_remove_group(&client->dev.kobj, &lm85_group_in567);
1297 i2c_detach_client(client);
1298 kfree(data); 1290 kfree(data);
1299 return 0; 1291 return 0;
1300} 1292}
@@ -1481,7 +1473,7 @@ static struct lm85_data *lm85_update_device(struct device *dev)
1481 data->autofan[i].config = 1473 data->autofan[i].config =
1482 lm85_read_value(client, LM85_REG_AFAN_CONFIG(i)); 1474 lm85_read_value(client, LM85_REG_AFAN_CONFIG(i));
1483 val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i)); 1475 val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i));
1484 data->autofan[i].freq = val & 0x07; 1476 data->pwm_freq[i] = val & 0x07;
1485 data->zone[i].range = val >> 4; 1477 data->zone[i].range = val >> 4;
1486 data->autofan[i].min_pwm = 1478 data->autofan[i].min_pwm =
1487 lm85_read_value(client, LM85_REG_AFAN_MINPWM(i)); 1479 lm85_read_value(client, LM85_REG_AFAN_MINPWM(i));
diff --git a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c
index 21970f0d53a1..2e4a3cea95f7 100644
--- a/drivers/hwmon/lm87.c
+++ b/drivers/hwmon/lm87.c
@@ -21,11 +21,10 @@
21 * http://www.national.com/pf/LM/LM87.html 21 * http://www.national.com/pf/LM/LM87.html
22 * 22 *
23 * Some functions share pins, so not all functions are available at the same 23 * Some functions share pins, so not all functions are available at the same
24 * time. Which are depends on the hardware setup. This driver assumes that 24 * time. Which are depends on the hardware setup. This driver normally
25 * the BIOS configured the chip correctly. In that respect, it differs from 25 * assumes that firmware configured the chip correctly. Where this is not
26 * the original driver (from lm_sensors for Linux 2.4), which would force the 26 * the case, platform code must set the I2C client's platform_data to point
27 * LM87 to an arbitrary, compile-time chosen mode, regardless of the actual 27 * to a u8 value to be written to the channel register.
28 * chipset wiring.
29 * For reference, here is the list of exclusive functions: 28 * For reference, here is the list of exclusive functions:
30 * - in0+in5 (default) or temp3 29 * - in0+in5 (default) or temp3
31 * - fan1 (default) or in6 30 * - fan1 (default) or in6
@@ -199,6 +198,7 @@ struct lm87_data {
199 unsigned long last_updated; /* In jiffies */ 198 unsigned long last_updated; /* In jiffies */
200 199
201 u8 channel; /* register value */ 200 u8 channel; /* register value */
201 u8 config; /* original register value */
202 202
203 u8 in[8]; /* register value */ 203 u8 in[8]; /* register value */
204 u8 in_max[8]; /* register value */ 204 u8 in_max[8]; /* register value */
@@ -832,6 +832,7 @@ exit_remove:
832 sysfs_remove_group(&new_client->dev.kobj, &lm87_group); 832 sysfs_remove_group(&new_client->dev.kobj, &lm87_group);
833 sysfs_remove_group(&new_client->dev.kobj, &lm87_group_opt); 833 sysfs_remove_group(&new_client->dev.kobj, &lm87_group_opt);
834exit_free: 834exit_free:
835 lm87_write_value(new_client, LM87_REG_CONFIG, data->config);
835 kfree(data); 836 kfree(data);
836exit: 837exit:
837 return err; 838 return err;
@@ -840,12 +841,17 @@ exit:
840static void lm87_init_client(struct i2c_client *client) 841static void lm87_init_client(struct i2c_client *client)
841{ 842{
842 struct lm87_data *data = i2c_get_clientdata(client); 843 struct lm87_data *data = i2c_get_clientdata(client);
843 u8 config;
844 844
845 data->channel = lm87_read_value(client, LM87_REG_CHANNEL_MODE); 845 if (client->dev.platform_data) {
846 data->channel = *(u8 *)client->dev.platform_data;
847 lm87_write_value(client,
848 LM87_REG_CHANNEL_MODE, data->channel);
849 } else {
850 data->channel = lm87_read_value(client, LM87_REG_CHANNEL_MODE);
851 }
852 data->config = lm87_read_value(client, LM87_REG_CONFIG) & 0x6F;
846 853
847 config = lm87_read_value(client, LM87_REG_CONFIG); 854 if (!(data->config & 0x01)) {
848 if (!(config & 0x01)) {
849 int i; 855 int i;
850 856
851 /* Limits are left uninitialized after power-up */ 857 /* Limits are left uninitialized after power-up */
@@ -867,11 +873,11 @@ static void lm87_init_client(struct i2c_client *client)
867 lm87_write_value(client, LM87_REG_IN_MAX(0), 0xFF); 873 lm87_write_value(client, LM87_REG_IN_MAX(0), 0xFF);
868 } 874 }
869 } 875 }
870 if ((config & 0x81) != 0x01) { 876
871 /* Start monitoring */ 877 /* Make sure Start is set and INT#_Clear is clear */
878 if ((data->config & 0x09) != 0x01)
872 lm87_write_value(client, LM87_REG_CONFIG, 879 lm87_write_value(client, LM87_REG_CONFIG,
873 (config & 0xF7) | 0x01); 880 (data->config & 0x77) | 0x01);
874 }
875} 881}
876 882
877static int lm87_remove(struct i2c_client *client) 883static int lm87_remove(struct i2c_client *client)
@@ -882,6 +888,7 @@ static int lm87_remove(struct i2c_client *client)
882 sysfs_remove_group(&client->dev.kobj, &lm87_group); 888 sysfs_remove_group(&client->dev.kobj, &lm87_group);
883 sysfs_remove_group(&client->dev.kobj, &lm87_group_opt); 889 sysfs_remove_group(&client->dev.kobj, &lm87_group_opt);
884 890
891 lm87_write_value(client, LM87_REG_CONFIG, data->config);
885 kfree(data); 892 kfree(data);
886 return 0; 893 return 0;
887} 894}
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
index c24fe36ac787..3edeebc0b835 100644
--- a/drivers/hwmon/lm90.c
+++ b/drivers/hwmon/lm90.c
@@ -1,14 +1,12 @@
1/* 1/*
2 * lm90.c - Part of lm_sensors, Linux kernel modules for hardware 2 * lm90.c - Part of lm_sensors, Linux kernel modules for hardware
3 * monitoring 3 * monitoring
4 * Copyright (C) 2003-2006 Jean Delvare <khali@linux-fr.org> 4 * Copyright (C) 2003-2008 Jean Delvare <khali@linux-fr.org>
5 * 5 *
6 * Based on the lm83 driver. The LM90 is a sensor chip made by National 6 * Based on the lm83 driver. The LM90 is a sensor chip made by National
7 * Semiconductor. It reports up to two temperatures (its own plus up to 7 * Semiconductor. It reports up to two temperatures (its own plus up to
8 * one external one) with a 0.125 deg resolution (1 deg for local 8 * one external one) with a 0.125 deg resolution (1 deg for local
9 * temperature) and a 3-4 deg accuracy. Complete datasheet can be 9 * temperature) and a 3-4 deg accuracy.
10 * obtained from National's website at:
11 * http://www.national.com/pf/LM/LM90.html
12 * 10 *
13 * This driver also supports the LM89 and LM99, two other sensor chips 11 * This driver also supports the LM89 and LM99, two other sensor chips
14 * made by National Semiconductor. Both have an increased remote 12 * made by National Semiconductor. Both have an increased remote
@@ -16,48 +14,38 @@
16 * additionally shifts remote temperatures (measured and limits) by 16 14 * additionally shifts remote temperatures (measured and limits) by 16
17 * degrees, which allows for higher temperatures measurement. The 15 * degrees, which allows for higher temperatures measurement. The
18 * driver doesn't handle it since it can be done easily in user-space. 16 * driver doesn't handle it since it can be done easily in user-space.
19 * Complete datasheets can be obtained from National's website at:
20 * http://www.national.com/pf/LM/LM89.html
21 * http://www.national.com/pf/LM/LM99.html
22 * Note that there is no way to differentiate between both chips. 17 * Note that there is no way to differentiate between both chips.
23 * 18 *
24 * This driver also supports the LM86, another sensor chip made by 19 * This driver also supports the LM86, another sensor chip made by
25 * National Semiconductor. It is exactly similar to the LM90 except it 20 * National Semiconductor. It is exactly similar to the LM90 except it
26 * has a higher accuracy. 21 * has a higher accuracy.
27 * Complete datasheet can be obtained from National's website at:
28 * http://www.national.com/pf/LM/LM86.html
29 * 22 *
30 * This driver also supports the ADM1032, a sensor chip made by Analog 23 * This driver also supports the ADM1032, a sensor chip made by Analog
31 * Devices. That chip is similar to the LM90, with a few differences 24 * Devices. That chip is similar to the LM90, with a few differences
32 * that are not handled by this driver. Complete datasheet can be 25 * that are not handled by this driver. Among others, it has a higher
33 * obtained from Analog's website at: 26 * accuracy than the LM90, much like the LM86 does.
34 * http://www.analog.com/en/prod/0,2877,ADM1032,00.html
35 * Among others, it has a higher accuracy than the LM90, much like the
36 * LM86 does.
37 * 27 *
38 * This driver also supports the MAX6657, MAX6658 and MAX6659 sensor 28 * This driver also supports the MAX6657, MAX6658 and MAX6659 sensor
39 * chips made by Maxim. These chips are similar to the LM86. Complete 29 * chips made by Maxim. These chips are similar to the LM86.
40 * datasheet can be obtained at Maxim's website at:
41 * http://www.maxim-ic.com/quick_view2.cfm/qv_pk/2578
42 * Note that there is no easy way to differentiate between the three 30 * Note that there is no easy way to differentiate between the three
43 * variants. The extra address and features of the MAX6659 are not 31 * variants. The extra address and features of the MAX6659 are not
44 * supported by this driver. These chips lack the remote temperature 32 * supported by this driver. These chips lack the remote temperature
45 * offset feature. 33 * offset feature.
46 * 34 *
35 * This driver also supports the MAX6646, MAX6647 and MAX6649 chips
36 * made by Maxim. These are again similar to the LM86, but they use
37 * unsigned temperature values and can report temperatures from 0 to
38 * 145 degrees.
39 *
47 * This driver also supports the MAX6680 and MAX6681, two other sensor 40 * This driver also supports the MAX6680 and MAX6681, two other sensor
48 * chips made by Maxim. These are quite similar to the other Maxim 41 * chips made by Maxim. These are quite similar to the other Maxim
49 * chips. Complete datasheet can be obtained at: 42 * chips. The MAX6680 and MAX6681 only differ in the pinout so they can
50 * http://www.maxim-ic.com/quick_view2.cfm/qv_pk/3370 43 * be treated identically.
51 * The MAX6680 and MAX6681 only differ in the pinout so they can be
52 * treated identically.
53 * 44 *
54 * This driver also supports the ADT7461 chip from Analog Devices but 45 * This driver also supports the ADT7461 chip from Analog Devices.
55 * only in its "compatability mode". If an ADT7461 chip is found but 46 * It's supported in both compatibility and extended mode. It is mostly
56 * is configured in non-compatible mode (where its temperature 47 * compatible with LM90 except for a data format difference for the
57 * register values are decoded differently) it is ignored by this 48 * temperature value registers.
58 * driver. Complete datasheet can be obtained from Analog's website
59 * at:
60 * http://www.analog.com/en/prod/0,2877,ADT7461,00.html
61 * 49 *
62 * Since the LM90 was the first chipset supported by this driver, most 50 * Since the LM90 was the first chipset supported by this driver, most
63 * comments will refer to this chipset, but are actually general and 51 * comments will refer to this chipset, but are actually general and
@@ -93,9 +81,10 @@
93 * Addresses to scan 81 * Addresses to scan
94 * Address is fully defined internally and cannot be changed except for 82 * Address is fully defined internally and cannot be changed except for
95 * MAX6659, MAX6680 and MAX6681. 83 * MAX6659, MAX6680 and MAX6681.
96 * LM86, LM89, LM90, LM99, ADM1032, ADM1032-1, ADT7461, MAX6657 and MAX6658 84 * LM86, LM89, LM90, LM99, ADM1032, ADM1032-1, ADT7461, MAX6649, MAX6657
97 * have address 0x4c. 85 * and MAX6658 have address 0x4c.
98 * ADM1032-2, ADT7461-2, LM89-1, and LM99-1 have address 0x4d. 86 * ADM1032-2, ADT7461-2, LM89-1, LM99-1 and MAX6646 have address 0x4d.
87 * MAX6647 has address 0x4e.
99 * MAX6659 can have address 0x4c, 0x4d or 0x4e (unsupported). 88 * MAX6659 can have address 0x4c, 0x4d or 0x4e (unsupported).
100 * MAX6680 and MAX6681 can have address 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 89 * MAX6680 and MAX6681 can have address 0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b,
101 * 0x4c, 0x4d or 0x4e. 90 * 0x4c, 0x4d or 0x4e.
@@ -108,7 +97,8 @@ static const unsigned short normal_i2c[] = {
108 * Insmod parameters 97 * Insmod parameters
109 */ 98 */
110 99
111I2C_CLIENT_INSMOD_7(lm90, adm1032, lm99, lm86, max6657, adt7461, max6680); 100I2C_CLIENT_INSMOD_8(lm90, adm1032, lm99, lm86, max6657, adt7461, max6680,
101 max6646);
112 102
113/* 103/*
114 * The LM90 registers 104 * The LM90 registers
@@ -149,39 +139,14 @@ I2C_CLIENT_INSMOD_7(lm90, adm1032, lm99, lm86, max6657, adt7461, max6680);
149#define LM90_REG_R_TCRIT_HYST 0x21 139#define LM90_REG_R_TCRIT_HYST 0x21
150#define LM90_REG_W_TCRIT_HYST 0x21 140#define LM90_REG_W_TCRIT_HYST 0x21
151 141
152/* 142/* MAX6646/6647/6649/6657/6658/6659 registers */
153 * Conversions and various macros
154 * For local temperatures and limits, critical limits and the hysteresis
155 * value, the LM90 uses signed 8-bit values with LSB = 1 degree Celsius.
156 * For remote temperatures and limits, it uses signed 11-bit values with
157 * LSB = 0.125 degree Celsius, left-justified in 16-bit registers.
158 */
159 143
160#define TEMP1_FROM_REG(val) ((val) * 1000) 144#define MAX6657_REG_R_LOCAL_TEMPL 0x11
161#define TEMP1_TO_REG(val) ((val) <= -128000 ? -128 : \
162 (val) >= 127000 ? 127 : \
163 (val) < 0 ? ((val) - 500) / 1000 : \
164 ((val) + 500) / 1000)
165#define TEMP2_FROM_REG(val) ((val) / 32 * 125)
166#define TEMP2_TO_REG(val) ((val) <= -128000 ? 0x8000 : \
167 (val) >= 127875 ? 0x7FE0 : \
168 (val) < 0 ? ((val) - 62) / 125 * 32 : \
169 ((val) + 62) / 125 * 32)
170#define HYST_TO_REG(val) ((val) <= 0 ? 0 : (val) >= 30500 ? 31 : \
171 ((val) + 500) / 1000)
172
173/*
174 * ADT7461 is almost identical to LM90 except that attempts to write
175 * values that are outside the range 0 < temp < 127 are treated as
176 * the boundary value.
177 */
178 145
179#define TEMP1_TO_REG_ADT7461(val) ((val) <= 0 ? 0 : \ 146/*
180 (val) >= 127000 ? 127 : \ 147 * Device flags
181 ((val) + 500) / 1000) 148 */
182#define TEMP2_TO_REG_ADT7461(val) ((val) <= 0 ? 0 : \ 149#define LM90_FLAG_ADT7461_EXT 0x01 /* ADT7461 extended mode */
183 (val) >= 127750 ? 0x7FC0 : \
184 ((val) + 125) / 250 * 64)
185 150
186/* 151/*
187 * Functions declaration 152 * Functions declaration
@@ -206,6 +171,9 @@ static const struct i2c_device_id lm90_id[] = {
206 { "lm86", lm86 }, 171 { "lm86", lm86 },
207 { "lm89", lm99 }, 172 { "lm89", lm99 },
208 { "lm99", lm99 }, /* Missing temperature offset */ 173 { "lm99", lm99 }, /* Missing temperature offset */
174 { "max6646", max6646 },
175 { "max6647", max6646 },
176 { "max6649", max6646 },
209 { "max6657", max6657 }, 177 { "max6657", max6657 },
210 { "max6658", max6657 }, 178 { "max6658", max6657 },
211 { "max6659", max6657 }, 179 { "max6659", max6657 },
@@ -237,22 +205,150 @@ struct lm90_data {
237 char valid; /* zero until following fields are valid */ 205 char valid; /* zero until following fields are valid */
238 unsigned long last_updated; /* in jiffies */ 206 unsigned long last_updated; /* in jiffies */
239 int kind; 207 int kind;
208 int flags;
240 209
241 /* registers values */ 210 /* registers values */
242 s8 temp8[5]; /* 0: local input 211 s8 temp8[4]; /* 0: local low limit
243 1: local low limit 212 1: local high limit
244 2: local high limit 213 2: local critical limit
245 3: local critical limit 214 3: remote critical limit */
246 4: remote critical limit */ 215 s16 temp11[5]; /* 0: remote input
247 s16 temp11[4]; /* 0: remote input
248 1: remote low limit 216 1: remote low limit
249 2: remote high limit 217 2: remote high limit
250 3: remote offset (except max6657) */ 218 3: remote offset (except max6646 and max6657)
219 4: local input */
251 u8 temp_hyst; 220 u8 temp_hyst;
252 u8 alarms; /* bitvector */ 221 u8 alarms; /* bitvector */
253}; 222};
254 223
255/* 224/*
225 * Conversions
226 * For local temperatures and limits, critical limits and the hysteresis
227 * value, the LM90 uses signed 8-bit values with LSB = 1 degree Celsius.
228 * For remote temperatures and limits, it uses signed 11-bit values with
229 * LSB = 0.125 degree Celsius, left-justified in 16-bit registers. Some
230 * Maxim chips use unsigned values.
231 */
232
233static inline int temp_from_s8(s8 val)
234{
235 return val * 1000;
236}
237
238static inline int temp_from_u8(u8 val)
239{
240 return val * 1000;
241}
242
243static inline int temp_from_s16(s16 val)
244{
245 return val / 32 * 125;
246}
247
248static inline int temp_from_u16(u16 val)
249{
250 return val / 32 * 125;
251}
252
253static s8 temp_to_s8(long val)
254{
255 if (val <= -128000)
256 return -128;
257 if (val >= 127000)
258 return 127;
259 if (val < 0)
260 return (val - 500) / 1000;
261 return (val + 500) / 1000;
262}
263
264static u8 temp_to_u8(long val)
265{
266 if (val <= 0)
267 return 0;
268 if (val >= 255000)
269 return 255;
270 return (val + 500) / 1000;
271}
272
273static s16 temp_to_s16(long val)
274{
275 if (val <= -128000)
276 return 0x8000;
277 if (val >= 127875)
278 return 0x7FE0;
279 if (val < 0)
280 return (val - 62) / 125 * 32;
281 return (val + 62) / 125 * 32;
282}
283
284static u8 hyst_to_reg(long val)
285{
286 if (val <= 0)
287 return 0;
288 if (val >= 30500)
289 return 31;
290 return (val + 500) / 1000;
291}
292
293/*
294 * ADT7461 in compatibility mode is almost identical to LM90 except that
295 * attempts to write values that are outside the range 0 < temp < 127 are
296 * treated as the boundary value.
297 *
298 * ADT7461 in "extended mode" operation uses unsigned integers offset by
299 * 64 (e.g., 0 -> -64 degC). The range is restricted to -64..191 degC.
300 */
301static inline int temp_from_u8_adt7461(struct lm90_data *data, u8 val)
302{
303 if (data->flags & LM90_FLAG_ADT7461_EXT)
304 return (val - 64) * 1000;
305 else
306 return temp_from_s8(val);
307}
308
309static inline int temp_from_u16_adt7461(struct lm90_data *data, u16 val)
310{
311 if (data->flags & LM90_FLAG_ADT7461_EXT)
312 return (val - 0x4000) / 64 * 250;
313 else
314 return temp_from_s16(val);
315}
316
317static u8 temp_to_u8_adt7461(struct lm90_data *data, long val)
318{
319 if (data->flags & LM90_FLAG_ADT7461_EXT) {
320 if (val <= -64000)
321 return 0;
322 if (val >= 191000)
323 return 0xFF;
324 return (val + 500 + 64000) / 1000;
325 } else {
326 if (val <= 0)
327 return 0;
328 if (val >= 127000)
329 return 127;
330 return (val + 500) / 1000;
331 }
332}
333
334static u16 temp_to_u16_adt7461(struct lm90_data *data, long val)
335{
336 if (data->flags & LM90_FLAG_ADT7461_EXT) {
337 if (val <= -64000)
338 return 0;
339 if (val >= 191750)
340 return 0xFFC0;
341 return (val + 64000 + 125) / 250 * 64;
342 } else {
343 if (val <= 0)
344 return 0;
345 if (val >= 127750)
346 return 0x7FC0;
347 return (val + 125) / 250 * 64;
348 }
349}
350
351/*
256 * Sysfs stuff 352 * Sysfs stuff
257 */ 353 */
258 354
@@ -261,7 +357,16 @@ static ssize_t show_temp8(struct device *dev, struct device_attribute *devattr,
261{ 357{
262 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 358 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
263 struct lm90_data *data = lm90_update_device(dev); 359 struct lm90_data *data = lm90_update_device(dev);
264 return sprintf(buf, "%d\n", TEMP1_FROM_REG(data->temp8[attr->index])); 360 int temp;
361
362 if (data->kind == adt7461)
363 temp = temp_from_u8_adt7461(data, data->temp8[attr->index]);
364 else if (data->kind == max6646)
365 temp = temp_from_u8(data->temp8[attr->index]);
366 else
367 temp = temp_from_s8(data->temp8[attr->index]);
368
369 return sprintf(buf, "%d\n", temp);
265} 370}
266 371
267static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr, 372static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
@@ -282,10 +387,12 @@ static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
282 387
283 mutex_lock(&data->update_lock); 388 mutex_lock(&data->update_lock);
284 if (data->kind == adt7461) 389 if (data->kind == adt7461)
285 data->temp8[nr] = TEMP1_TO_REG_ADT7461(val); 390 data->temp8[nr] = temp_to_u8_adt7461(data, val);
391 else if (data->kind == max6646)
392 data->temp8[nr] = temp_to_u8(val);
286 else 393 else
287 data->temp8[nr] = TEMP1_TO_REG(val); 394 data->temp8[nr] = temp_to_s8(val);
288 i2c_smbus_write_byte_data(client, reg[nr - 1], data->temp8[nr]); 395 i2c_smbus_write_byte_data(client, reg[nr], data->temp8[nr]);
289 mutex_unlock(&data->update_lock); 396 mutex_unlock(&data->update_lock);
290 return count; 397 return count;
291} 398}
@@ -295,7 +402,16 @@ static ssize_t show_temp11(struct device *dev, struct device_attribute *devattr,
295{ 402{
296 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 403 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
297 struct lm90_data *data = lm90_update_device(dev); 404 struct lm90_data *data = lm90_update_device(dev);
298 return sprintf(buf, "%d\n", TEMP2_FROM_REG(data->temp11[attr->index])); 405 int temp;
406
407 if (data->kind == adt7461)
408 temp = temp_from_u16_adt7461(data, data->temp11[attr->index]);
409 else if (data->kind == max6646)
410 temp = temp_from_u16(data->temp11[attr->index]);
411 else
412 temp = temp_from_s16(data->temp11[attr->index]);
413
414 return sprintf(buf, "%d\n", temp);
299} 415}
300 416
301static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr, 417static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
@@ -318,13 +434,20 @@ static ssize_t set_temp11(struct device *dev, struct device_attribute *devattr,
318 434
319 mutex_lock(&data->update_lock); 435 mutex_lock(&data->update_lock);
320 if (data->kind == adt7461) 436 if (data->kind == adt7461)
321 data->temp11[nr] = TEMP2_TO_REG_ADT7461(val); 437 data->temp11[nr] = temp_to_u16_adt7461(data, val);
438 else if (data->kind == max6657 || data->kind == max6680)
439 data->temp11[nr] = temp_to_s8(val) << 8;
440 else if (data->kind == max6646)
441 data->temp11[nr] = temp_to_u8(val) << 8;
322 else 442 else
323 data->temp11[nr] = TEMP2_TO_REG(val); 443 data->temp11[nr] = temp_to_s16(val);
444
324 i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2], 445 i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2],
325 data->temp11[nr] >> 8); 446 data->temp11[nr] >> 8);
326 i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1], 447 if (data->kind != max6657 && data->kind != max6680
327 data->temp11[nr] & 0xff); 448 && data->kind != max6646)
449 i2c_smbus_write_byte_data(client, reg[(nr - 1) * 2 + 1],
450 data->temp11[nr] & 0xff);
328 mutex_unlock(&data->update_lock); 451 mutex_unlock(&data->update_lock);
329 return count; 452 return count;
330} 453}
@@ -334,8 +457,14 @@ static ssize_t show_temphyst(struct device *dev, struct device_attribute *devatt
334{ 457{
335 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 458 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
336 struct lm90_data *data = lm90_update_device(dev); 459 struct lm90_data *data = lm90_update_device(dev);
337 return sprintf(buf, "%d\n", TEMP1_FROM_REG(data->temp8[attr->index]) 460 int temp;
338 - TEMP1_FROM_REG(data->temp_hyst)); 461
462 if (data->kind == adt7461)
463 temp = temp_from_u8_adt7461(data, data->temp8[attr->index]);
464 else
465 temp = temp_from_s8(data->temp8[attr->index]);
466
467 return sprintf(buf, "%d\n", temp - temp_from_s8(data->temp_hyst));
339} 468}
340 469
341static ssize_t set_temphyst(struct device *dev, struct device_attribute *dummy, 470static ssize_t set_temphyst(struct device *dev, struct device_attribute *dummy,
@@ -347,9 +476,9 @@ static ssize_t set_temphyst(struct device *dev, struct device_attribute *dummy,
347 long hyst; 476 long hyst;
348 477
349 mutex_lock(&data->update_lock); 478 mutex_lock(&data->update_lock);
350 hyst = TEMP1_FROM_REG(data->temp8[3]) - val; 479 hyst = temp_from_s8(data->temp8[2]) - val;
351 i2c_smbus_write_byte_data(client, LM90_REG_W_TCRIT_HYST, 480 i2c_smbus_write_byte_data(client, LM90_REG_W_TCRIT_HYST,
352 HYST_TO_REG(hyst)); 481 hyst_to_reg(hyst));
353 mutex_unlock(&data->update_lock); 482 mutex_unlock(&data->update_lock);
354 return count; 483 return count;
355} 484}
@@ -371,23 +500,23 @@ static ssize_t show_alarm(struct device *dev, struct device_attribute
371 return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1); 500 return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1);
372} 501}
373 502
374static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp8, NULL, 0); 503static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp11, NULL, 4);
375static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp11, NULL, 0); 504static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp11, NULL, 0);
376static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp8, 505static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp8,
377 set_temp8, 1); 506 set_temp8, 0);
378static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp11, 507static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp11,
379 set_temp11, 1); 508 set_temp11, 1);
380static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp8, 509static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp8,
381 set_temp8, 2); 510 set_temp8, 1);
382static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp11, 511static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp11,
383 set_temp11, 2); 512 set_temp11, 2);
384static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp8, 513static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp8,
385 set_temp8, 3); 514 set_temp8, 2);
386static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_temp8, 515static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_temp8,
387 set_temp8, 4); 516 set_temp8, 3);
388static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temphyst, 517static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temphyst,
389 set_temphyst, 3); 518 set_temphyst, 2);
390static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temphyst, NULL, 4); 519static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temphyst, NULL, 3);
391static SENSOR_DEVICE_ATTR(temp2_offset, S_IWUSR | S_IRUGO, show_temp11, 520static SENSOR_DEVICE_ATTR(temp2_offset, S_IWUSR | S_IRUGO, show_temp11,
392 set_temp11, 3); 521 set_temp11, 3);
393 522
@@ -568,7 +697,7 @@ static int lm90_detect(struct i2c_client *new_client, int kind,
568 kind = adm1032; 697 kind = adm1032;
569 } else 698 } else
570 if (chip_id == 0x51 /* ADT7461 */ 699 if (chip_id == 0x51 /* ADT7461 */
571 && (reg_config1 & 0x1F) == 0x00 /* check compat mode */ 700 && (reg_config1 & 0x1B) == 0x00
572 && reg_convrate <= 0x0A) { 701 && reg_convrate <= 0x0A) {
573 kind = adt7461; 702 kind = adt7461;
574 } 703 }
@@ -599,13 +728,23 @@ static int lm90_detect(struct i2c_client *new_client, int kind,
599 && (reg_config1 & 0x03) == 0x00 728 && (reg_config1 & 0x03) == 0x00
600 && reg_convrate <= 0x07) { 729 && reg_convrate <= 0x07) {
601 kind = max6680; 730 kind = max6680;
731 } else
732 /* The chip_id register of the MAX6646/6647/6649
733 * holds the revision of the chip.
734 * The lowest 6 bits of the config1 register are
735 * unused and should return zero when read.
736 */
737 if (chip_id == 0x59
738 && (reg_config1 & 0x3f) == 0x00
739 && reg_convrate <= 0x07) {
740 kind = max6646;
602 } 741 }
603 } 742 }
604 743
605 if (kind <= 0) { /* identification failed */ 744 if (kind <= 0) { /* identification failed */
606 dev_info(&adapter->dev, 745 dev_dbg(&adapter->dev,
607 "Unsupported chip (man_id=0x%02X, " 746 "Unsupported chip at 0x%02x (man_id=0x%02X, "
608 "chip_id=0x%02X).\n", man_id, chip_id); 747 "chip_id=0x%02X)\n", address, man_id, chip_id);
609 return -ENODEV; 748 return -ENODEV;
610 } 749 }
611 } 750 }
@@ -629,6 +768,8 @@ static int lm90_detect(struct i2c_client *new_client, int kind,
629 name = "max6680"; 768 name = "max6680";
630 } else if (kind == adt7461) { 769 } else if (kind == adt7461) {
631 name = "adt7461"; 770 name = "adt7461";
771 } else if (kind == max6646) {
772 name = "max6646";
632 } 773 }
633 strlcpy(info->type, name, I2C_NAME_SIZE); 774 strlcpy(info->type, name, I2C_NAME_SIZE);
634 775
@@ -668,7 +809,7 @@ static int lm90_probe(struct i2c_client *new_client,
668 &dev_attr_pec))) 809 &dev_attr_pec)))
669 goto exit_remove_files; 810 goto exit_remove_files;
670 } 811 }
671 if (data->kind != max6657) { 812 if (data->kind != max6657 && data->kind != max6646) {
672 if ((err = device_create_file(&new_client->dev, 813 if ((err = device_create_file(&new_client->dev,
673 &sensor_dev_attr_temp2_offset.dev_attr))) 814 &sensor_dev_attr_temp2_offset.dev_attr)))
674 goto exit_remove_files; 815 goto exit_remove_files;
@@ -707,6 +848,12 @@ static void lm90_init_client(struct i2c_client *client)
707 } 848 }
708 config_orig = config; 849 config_orig = config;
709 850
851 /* Check Temperature Range Select */
852 if (data->kind == adt7461) {
853 if (config & 0x04)
854 data->flags |= LM90_FLAG_ADT7461_EXT;
855 }
856
710 /* 857 /*
711 * Put MAX6680/MAX8881 into extended resolution (bit 0x10, 858 * Put MAX6680/MAX8881 into extended resolution (bit 0x10,
712 * 0.125 degree resolution) and range (0x08, extend range 859 * 0.125 degree resolution) and range (0x08, extend range
@@ -728,7 +875,7 @@ static int lm90_remove(struct i2c_client *client)
728 hwmon_device_unregister(data->hwmon_dev); 875 hwmon_device_unregister(data->hwmon_dev);
729 sysfs_remove_group(&client->dev.kobj, &lm90_group); 876 sysfs_remove_group(&client->dev.kobj, &lm90_group);
730 device_remove_file(&client->dev, &dev_attr_pec); 877 device_remove_file(&client->dev, &dev_attr_pec);
731 if (data->kind != max6657) 878 if (data->kind != max6657 && data->kind != max6646)
732 device_remove_file(&client->dev, 879 device_remove_file(&client->dev,
733 &sensor_dev_attr_temp2_offset.dev_attr); 880 &sensor_dev_attr_temp2_offset.dev_attr);
734 881
@@ -736,6 +883,38 @@ static int lm90_remove(struct i2c_client *client)
736 return 0; 883 return 0;
737} 884}
738 885
886static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value)
887{
888 int err;
889 u8 oldh, newh, l;
890
891 /*
892 * There is a trick here. We have to read two registers to have the
893 * sensor temperature, but we have to beware a conversion could occur
894 * inbetween the readings. The datasheet says we should either use
895 * the one-shot conversion register, which we don't want to do
896 * (disables hardware monitoring) or monitor the busy bit, which is
897 * impossible (we can't read the values and monitor that bit at the
898 * exact same time). So the solution used here is to read the high
899 * byte once, then the low byte, then the high byte again. If the new
900 * high byte matches the old one, then we have a valid reading. Else
901 * we have to read the low byte again, and now we believe we have a
902 * correct reading.
903 */
904 if ((err = lm90_read_reg(client, regh, &oldh))
905 || (err = lm90_read_reg(client, regl, &l))
906 || (err = lm90_read_reg(client, regh, &newh)))
907 return err;
908 if (oldh != newh) {
909 err = lm90_read_reg(client, regl, &l);
910 if (err)
911 return err;
912 }
913 *value = (newh << 8) | l;
914
915 return 0;
916}
917
739static struct lm90_data *lm90_update_device(struct device *dev) 918static struct lm90_data *lm90_update_device(struct device *dev)
740{ 919{
741 struct i2c_client *client = to_i2c_client(dev); 920 struct i2c_client *client = to_i2c_client(dev);
@@ -744,49 +923,50 @@ static struct lm90_data *lm90_update_device(struct device *dev)
744 mutex_lock(&data->update_lock); 923 mutex_lock(&data->update_lock);
745 924
746 if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { 925 if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) {
747 u8 oldh, newh, l; 926 u8 h, l;
748 927
749 dev_dbg(&client->dev, "Updating lm90 data.\n"); 928 dev_dbg(&client->dev, "Updating lm90 data.\n");
750 lm90_read_reg(client, LM90_REG_R_LOCAL_TEMP, &data->temp8[0]); 929 lm90_read_reg(client, LM90_REG_R_LOCAL_LOW, &data->temp8[0]);
751 lm90_read_reg(client, LM90_REG_R_LOCAL_LOW, &data->temp8[1]); 930 lm90_read_reg(client, LM90_REG_R_LOCAL_HIGH, &data->temp8[1]);
752 lm90_read_reg(client, LM90_REG_R_LOCAL_HIGH, &data->temp8[2]); 931 lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT, &data->temp8[2]);
753 lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT, &data->temp8[3]); 932 lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT, &data->temp8[3]);
754 lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT, &data->temp8[4]);
755 lm90_read_reg(client, LM90_REG_R_TCRIT_HYST, &data->temp_hyst); 933 lm90_read_reg(client, LM90_REG_R_TCRIT_HYST, &data->temp_hyst);
756 934
757 /* 935 if (data->kind == max6657 || data->kind == max6646) {
758 * There is a trick here. We have to read two registers to 936 lm90_read16(client, LM90_REG_R_LOCAL_TEMP,
759 * have the remote sensor temperature, but we have to beware 937 MAX6657_REG_R_LOCAL_TEMPL,
760 * a conversion could occur inbetween the readings. The 938 &data->temp11[4]);
761 * datasheet says we should either use the one-shot 939 } else {
762 * conversion register, which we don't want to do (disables 940 if (lm90_read_reg(client, LM90_REG_R_LOCAL_TEMP,
763 * hardware monitoring) or monitor the busy bit, which is 941 &h) == 0)
764 * impossible (we can't read the values and monitor that bit 942 data->temp11[4] = h << 8;
765 * at the exact same time). So the solution used here is to 943 }
766 * read the high byte once, then the low byte, then the high 944 lm90_read16(client, LM90_REG_R_REMOTE_TEMPH,
767 * byte again. If the new high byte matches the old one, 945 LM90_REG_R_REMOTE_TEMPL, &data->temp11[0]);
768 * then we have a valid reading. Else we have to read the low 946
769 * byte again, and now we believe we have a correct reading. 947 if (lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &h) == 0) {
770 */ 948 data->temp11[1] = h << 8;
771 if (lm90_read_reg(client, LM90_REG_R_REMOTE_TEMPH, &oldh) == 0 949 if (data->kind != max6657 && data->kind != max6680
772 && lm90_read_reg(client, LM90_REG_R_REMOTE_TEMPL, &l) == 0 950 && data->kind != max6646
773 && lm90_read_reg(client, LM90_REG_R_REMOTE_TEMPH, &newh) == 0 951 && lm90_read_reg(client, LM90_REG_R_REMOTE_LOWL,
774 && (newh == oldh 952 &l) == 0)
775 || lm90_read_reg(client, LM90_REG_R_REMOTE_TEMPL, &l) == 0)) 953 data->temp11[1] |= l;
776 data->temp11[0] = (newh << 8) | l; 954 }
777 955 if (lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &h) == 0) {
778 if (lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &newh) == 0 956 data->temp11[2] = h << 8;
779 && lm90_read_reg(client, LM90_REG_R_REMOTE_LOWL, &l) == 0) 957 if (data->kind != max6657 && data->kind != max6680
780 data->temp11[1] = (newh << 8) | l; 958 && data->kind != max6646
781 if (lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &newh) == 0 959 && lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHL,
782 && lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHL, &l) == 0) 960 &l) == 0)
783 data->temp11[2] = (newh << 8) | l; 961 data->temp11[2] |= l;
784 if (data->kind != max6657) { 962 }
963
964 if (data->kind != max6657 && data->kind != max6646) {
785 if (lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSH, 965 if (lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSH,
786 &newh) == 0 966 &h) == 0
787 && lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSL, 967 && lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSL,
788 &l) == 0) 968 &l) == 0)
789 data->temp11[3] = (newh << 8) | l; 969 data->temp11[3] = (h << 8) | l;
790 } 970 }
791 lm90_read_reg(client, LM90_REG_R_STATUS, &data->alarms); 971 lm90_read_reg(client, LM90_REG_R_STATUS, &data->alarms);
792 972
diff --git a/drivers/hwmon/max1619.c b/drivers/hwmon/max1619.c
index 1ab1cacad598..7897754f3a5c 100644
--- a/drivers/hwmon/max1619.c
+++ b/drivers/hwmon/max1619.c
@@ -69,11 +69,18 @@ I2C_CLIENT_INSMOD_1(max1619);
69#define MAX1619_REG_W_TCRIT_HYST 0x13 69#define MAX1619_REG_W_TCRIT_HYST 0x13
70 70
71/* 71/*
72 * Conversions and various macros 72 * Conversions
73 */ 73 */
74 74
75#define TEMP_FROM_REG(val) ((val & 0x80 ? val-0x100 : val) * 1000) 75static int temp_from_reg(int val)
76#define TEMP_TO_REG(val) ((val < 0 ? val+0x100*1000 : val) / 1000) 76{
77 return (val & 0x80 ? val-0x100 : val) * 1000;
78}
79
80static int temp_to_reg(int val)
81{
82 return (val < 0 ? val+0x100*1000 : val) / 1000;
83}
77 84
78/* 85/*
79 * Functions declaration 86 * Functions declaration
@@ -135,7 +142,7 @@ struct max1619_data {
135static ssize_t show_##value(struct device *dev, struct device_attribute *attr, char *buf) \ 142static ssize_t show_##value(struct device *dev, struct device_attribute *attr, char *buf) \
136{ \ 143{ \
137 struct max1619_data *data = max1619_update_device(dev); \ 144 struct max1619_data *data = max1619_update_device(dev); \
138 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->value)); \ 145 return sprintf(buf, "%d\n", temp_from_reg(data->value)); \
139} 146}
140show_temp(temp_input1); 147show_temp(temp_input1);
141show_temp(temp_input2); 148show_temp(temp_input2);
@@ -153,7 +160,7 @@ static ssize_t set_##value(struct device *dev, struct device_attribute *attr, co
153 long val = simple_strtol(buf, NULL, 10); \ 160 long val = simple_strtol(buf, NULL, 10); \
154 \ 161 \
155 mutex_lock(&data->update_lock); \ 162 mutex_lock(&data->update_lock); \
156 data->value = TEMP_TO_REG(val); \ 163 data->value = temp_to_reg(val); \
157 i2c_smbus_write_byte_data(client, reg, data->value); \ 164 i2c_smbus_write_byte_data(client, reg, data->value); \
158 mutex_unlock(&data->update_lock); \ 165 mutex_unlock(&data->update_lock); \
159 return count; \ 166 return count; \
diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c
index f942ecdd47c8..d4d1b859d4f1 100644
--- a/drivers/hwmon/w83781d.c
+++ b/drivers/hwmon/w83781d.c
@@ -4,7 +4,7 @@
4 Copyright (c) 1998 - 2001 Frodo Looijaard <frodol@dds.nl>, 4 Copyright (c) 1998 - 2001 Frodo Looijaard <frodol@dds.nl>,
5 Philip Edelbrock <phil@netroedge.com>, 5 Philip Edelbrock <phil@netroedge.com>,
6 and Mark Studebaker <mdsxyz123@yahoo.com> 6 and Mark Studebaker <mdsxyz123@yahoo.com>
7 Copyright (c) 2007 Jean Delvare <khali@linux-fr.org> 7 Copyright (c) 2007 - 2008 Jean Delvare <khali@linux-fr.org>
8 8
9 This program is free software; you can redistribute it and/or modify 9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by 10 it under the terms of the GNU General Public License as published by
@@ -38,25 +38,24 @@
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/jiffies.h> 39#include <linux/jiffies.h>
40#include <linux/i2c.h> 40#include <linux/i2c.h>
41#include <linux/platform_device.h>
42#include <linux/ioport.h>
43#include <linux/hwmon.h> 41#include <linux/hwmon.h>
44#include <linux/hwmon-vid.h> 42#include <linux/hwmon-vid.h>
45#include <linux/hwmon-sysfs.h> 43#include <linux/hwmon-sysfs.h>
46#include <linux/sysfs.h> 44#include <linux/sysfs.h>
47#include <linux/err.h> 45#include <linux/err.h>
48#include <linux/mutex.h> 46#include <linux/mutex.h>
47
48#ifdef CONFIG_ISA
49#include <linux/platform_device.h>
50#include <linux/ioport.h>
49#include <asm/io.h> 51#include <asm/io.h>
50#include "lm75.h" 52#endif
51 53
52/* ISA device, if found */ 54#include "lm75.h"
53static struct platform_device *pdev;
54 55
55/* Addresses to scan */ 56/* Addresses to scan */
56static const unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 57static const unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
57 0x2e, 0x2f, I2C_CLIENT_END }; 58 0x2e, 0x2f, I2C_CLIENT_END };
58static unsigned short isa_address = 0x290;
59
60/* Insmod parameters */ 59/* Insmod parameters */
61I2C_CLIENT_INSMOD_4(w83781d, w83782d, w83783s, as99127f); 60I2C_CLIENT_INSMOD_4(w83781d, w83782d, w83783s, as99127f);
62I2C_CLIENT_MODULE_PARM(force_subclients, "List of subclient addresses: " 61I2C_CLIENT_MODULE_PARM(force_subclients, "List of subclient addresses: "
@@ -178,9 +177,9 @@ FAN_FROM_REG(u8 val, int div)
178#define TEMP_FROM_REG(val) ((val) * 1000) 177#define TEMP_FROM_REG(val) ((val) * 1000)
179 178
180#define BEEP_MASK_FROM_REG(val,type) ((type) == as99127f ? \ 179#define BEEP_MASK_FROM_REG(val,type) ((type) == as99127f ? \
181 (val) ^ 0x7fff : (val)) 180 (~(val)) & 0x7fff : (val) & 0xff7fff)
182#define BEEP_MASK_TO_REG(val,type) ((type) == as99127f ? \ 181#define BEEP_MASK_TO_REG(val,type) ((type) == as99127f ? \
183 (~(val)) & 0x7fff : (val) & 0xffffff) 182 (~(val)) & 0x7fff : (val) & 0xff7fff)
184 183
185#define DIV_FROM_REG(val) (1 << (val)) 184#define DIV_FROM_REG(val) (1 << (val))
186 185
@@ -199,25 +198,16 @@ DIV_TO_REG(long val, enum chips type)
199 return i; 198 return i;
200} 199}
201 200
202/* There are some complications in a module like this. First off, W83781D chips
203 may be both present on the SMBus and the ISA bus, and we have to handle
204 those cases separately at some places. Second, there might be several
205 W83781D chips available (well, actually, that is probably never done; but
206 it is a clean illustration of how to handle a case like that). Finally,
207 a specific chip may be attached to *both* ISA and SMBus, and we would
208 not like to detect it double. Fortunately, in the case of the W83781D at
209 least, a register tells us what SMBus address we are on, so that helps
210 a bit - except if there could be more than one SMBus. Groan. No solution
211 for this yet. */
212
213/* For ISA chips, we abuse the i2c_client addr and name fields. We also use
214 the driver field to differentiate between I2C and ISA chips. */
215struct w83781d_data { 201struct w83781d_data {
216 struct i2c_client client; 202 struct i2c_client *client;
217 struct device *hwmon_dev; 203 struct device *hwmon_dev;
218 struct mutex lock; 204 struct mutex lock;
219 enum chips type; 205 enum chips type;
220 206
207 /* For ISA device only */
208 const char *name;
209 int isa_addr;
210
221 struct mutex update_lock; 211 struct mutex update_lock;
222 char valid; /* !=0 if following fields are valid */ 212 char valid; /* !=0 if following fields are valid */
223 unsigned long last_updated; /* In jiffies */ 213 unsigned long last_updated; /* In jiffies */
@@ -240,7 +230,6 @@ struct w83781d_data {
240 u8 vid; /* Register encoding, combined */ 230 u8 vid; /* Register encoding, combined */
241 u32 alarms; /* Register encoding, combined */ 231 u32 alarms; /* Register encoding, combined */
242 u32 beep_mask; /* Register encoding, combined */ 232 u32 beep_mask; /* Register encoding, combined */
243 u8 beep_enable; /* Boolean */
244 u8 pwm[4]; /* Register value */ 233 u8 pwm[4]; /* Register value */
245 u8 pwm2_enable; /* Boolean */ 234 u8 pwm2_enable; /* Boolean */
246 u16 sens[3]; /* 782D/783S only. 235 u16 sens[3]; /* 782D/783S only.
@@ -249,36 +238,14 @@ struct w83781d_data {
249 u8 vrm; 238 u8 vrm;
250}; 239};
251 240
252static int w83781d_attach_adapter(struct i2c_adapter *adapter); 241static struct w83781d_data *w83781d_data_if_isa(void);
253static int w83781d_detect(struct i2c_adapter *adapter, int address, int kind); 242static int w83781d_alias_detect(struct i2c_client *client, u8 chipid);
254static int w83781d_detach_client(struct i2c_client *client);
255
256static int __devinit w83781d_isa_probe(struct platform_device *pdev);
257static int __devexit w83781d_isa_remove(struct platform_device *pdev);
258 243
259static int w83781d_read_value(struct w83781d_data *data, u16 reg); 244static int w83781d_read_value(struct w83781d_data *data, u16 reg);
260static int w83781d_write_value(struct w83781d_data *data, u16 reg, u16 value); 245static int w83781d_write_value(struct w83781d_data *data, u16 reg, u16 value);
261static struct w83781d_data *w83781d_update_device(struct device *dev); 246static struct w83781d_data *w83781d_update_device(struct device *dev);
262static void w83781d_init_device(struct device *dev); 247static void w83781d_init_device(struct device *dev);
263 248
264static struct i2c_driver w83781d_driver = {
265 .driver = {
266 .name = "w83781d",
267 },
268 .attach_adapter = w83781d_attach_adapter,
269 .detach_client = w83781d_detach_client,
270};
271
272static struct platform_driver w83781d_isa_driver = {
273 .driver = {
274 .owner = THIS_MODULE,
275 .name = "w83781d",
276 },
277 .probe = w83781d_isa_probe,
278 .remove = w83781d_isa_remove,
279};
280
281
282/* following are the sysfs callback functions */ 249/* following are the sysfs callback functions */
283#define show_in_reg(reg) \ 250#define show_in_reg(reg) \
284static ssize_t show_##reg (struct device *dev, struct device_attribute *da, \ 251static ssize_t show_##reg (struct device *dev, struct device_attribute *da, \
@@ -513,11 +480,6 @@ static ssize_t show_beep_mask (struct device *dev, struct device_attribute *attr
513 return sprintf(buf, "%ld\n", 480 return sprintf(buf, "%ld\n",
514 (long)BEEP_MASK_FROM_REG(data->beep_mask, data->type)); 481 (long)BEEP_MASK_FROM_REG(data->beep_mask, data->type));
515} 482}
516static ssize_t show_beep_enable (struct device *dev, struct device_attribute *attr, char *buf)
517{
518 struct w83781d_data *data = w83781d_update_device(dev);
519 return sprintf(buf, "%ld\n", (long)data->beep_enable);
520}
521 483
522static ssize_t 484static ssize_t
523store_beep_mask(struct device *dev, struct device_attribute *attr, 485store_beep_mask(struct device *dev, struct device_attribute *attr,
@@ -529,12 +491,12 @@ store_beep_mask(struct device *dev, struct device_attribute *attr,
529 val = simple_strtoul(buf, NULL, 10); 491 val = simple_strtoul(buf, NULL, 10);
530 492
531 mutex_lock(&data->update_lock); 493 mutex_lock(&data->update_lock);
532 data->beep_mask = BEEP_MASK_TO_REG(val, data->type); 494 data->beep_mask &= 0x8000; /* preserve beep enable */
495 data->beep_mask |= BEEP_MASK_TO_REG(val, data->type);
533 w83781d_write_value(data, W83781D_REG_BEEP_INTS1, 496 w83781d_write_value(data, W83781D_REG_BEEP_INTS1,
534 data->beep_mask & 0xff); 497 data->beep_mask & 0xff);
535 w83781d_write_value(data, W83781D_REG_BEEP_INTS2, 498 w83781d_write_value(data, W83781D_REG_BEEP_INTS2,
536 ((data->beep_mask >> 8) & 0x7f) 499 (data->beep_mask >> 8) & 0xff);
537 | data->beep_enable << 7);
538 if (data->type != w83781d && data->type != as99127f) { 500 if (data->type != w83781d && data->type != as99127f) {
539 w83781d_write_value(data, W83781D_REG_BEEP_INTS3, 501 w83781d_write_value(data, W83781D_REG_BEEP_INTS3,
540 ((data->beep_mask) >> 16) & 0xff); 502 ((data->beep_mask) >> 16) & 0xff);
@@ -544,31 +506,8 @@ store_beep_mask(struct device *dev, struct device_attribute *attr,
544 return count; 506 return count;
545} 507}
546 508
547static ssize_t
548store_beep_enable(struct device *dev, struct device_attribute *attr,
549 const char *buf, size_t count)
550{
551 struct w83781d_data *data = dev_get_drvdata(dev);
552 u32 val;
553
554 val = simple_strtoul(buf, NULL, 10);
555 if (val != 0 && val != 1)
556 return -EINVAL;
557
558 mutex_lock(&data->update_lock);
559 data->beep_enable = val;
560 val = w83781d_read_value(data, W83781D_REG_BEEP_INTS2) & 0x7f;
561 val |= data->beep_enable << 7;
562 w83781d_write_value(data, W83781D_REG_BEEP_INTS2, val);
563 mutex_unlock(&data->update_lock);
564
565 return count;
566}
567
568static DEVICE_ATTR(beep_mask, S_IRUGO | S_IWUSR, 509static DEVICE_ATTR(beep_mask, S_IRUGO | S_IWUSR,
569 show_beep_mask, store_beep_mask); 510 show_beep_mask, store_beep_mask);
570static DEVICE_ATTR(beep_enable, S_IRUGO | S_IWUSR,
571 show_beep_enable, store_beep_enable);
572 511
573static ssize_t show_beep(struct device *dev, struct device_attribute *attr, 512static ssize_t show_beep(struct device *dev, struct device_attribute *attr,
574 char *buf) 513 char *buf)
@@ -663,6 +602,8 @@ static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO | S_IWUSR,
663 show_beep, store_beep, 5); 602 show_beep, store_beep, 5);
664static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO, 603static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO,
665 show_temp3_beep, store_beep, 13); 604 show_temp3_beep, store_beep, 13);
605static SENSOR_DEVICE_ATTR(beep_enable, S_IRUGO | S_IWUSR,
606 show_beep, store_beep, 15);
666 607
667static ssize_t 608static ssize_t
668show_fan_div(struct device *dev, struct device_attribute *da, char *buf) 609show_fan_div(struct device *dev, struct device_attribute *da, char *buf)
@@ -866,45 +807,19 @@ static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR,
866static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR, 807static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR,
867 show_sensor, store_sensor, 2); 808 show_sensor, store_sensor, 2);
868 809
869/* I2C devices get this name attribute automatically, but for ISA devices
870 we must create it by ourselves. */
871static ssize_t
872show_name(struct device *dev, struct device_attribute *devattr, char *buf)
873{
874 struct w83781d_data *data = dev_get_drvdata(dev);
875 return sprintf(buf, "%s\n", data->client.name);
876}
877static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
878
879/* This function is called when:
880 * w83781d_driver is inserted (when this module is loaded), for each
881 available adapter
882 * when a new adapter is inserted (and w83781d_driver is still present) */
883static int
884w83781d_attach_adapter(struct i2c_adapter *adapter)
885{
886 if (!(adapter->class & I2C_CLASS_HWMON))
887 return 0;
888 return i2c_probe(adapter, &addr_data, w83781d_detect);
889}
890
891/* Assumes that adapter is of I2C, not ISA variety. 810/* Assumes that adapter is of I2C, not ISA variety.
892 * OTHERWISE DON'T CALL THIS 811 * OTHERWISE DON'T CALL THIS
893 */ 812 */
894static int 813static int
895w83781d_detect_subclients(struct i2c_adapter *adapter, int address, int kind, 814w83781d_detect_subclients(struct i2c_client *new_client)
896 struct i2c_client *new_client)
897{ 815{
898 int i, val1 = 0, id; 816 int i, val1 = 0, id;
899 int err; 817 int err;
900 const char *client_name = ""; 818 int address = new_client->addr;
819 unsigned short sc_addr[2];
820 struct i2c_adapter *adapter = new_client->adapter;
901 struct w83781d_data *data = i2c_get_clientdata(new_client); 821 struct w83781d_data *data = i2c_get_clientdata(new_client);
902 822 enum chips kind = data->type;
903 data->lm75[0] = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
904 if (!(data->lm75[0])) {
905 err = -ENOMEM;
906 goto ERROR_SC_0;
907 }
908 823
909 id = i2c_adapter_id(adapter); 824 id = i2c_adapter_id(adapter);
910 825
@@ -922,55 +837,35 @@ w83781d_detect_subclients(struct i2c_adapter *adapter, int address, int kind,
922 w83781d_write_value(data, W83781D_REG_I2C_SUBADDR, 837 w83781d_write_value(data, W83781D_REG_I2C_SUBADDR,
923 (force_subclients[2] & 0x07) | 838 (force_subclients[2] & 0x07) |
924 ((force_subclients[3] & 0x07) << 4)); 839 ((force_subclients[3] & 0x07) << 4));
925 data->lm75[0]->addr = force_subclients[2]; 840 sc_addr[0] = force_subclients[2];
926 } else { 841 } else {
927 val1 = w83781d_read_value(data, W83781D_REG_I2C_SUBADDR); 842 val1 = w83781d_read_value(data, W83781D_REG_I2C_SUBADDR);
928 data->lm75[0]->addr = 0x48 + (val1 & 0x07); 843 sc_addr[0] = 0x48 + (val1 & 0x07);
929 } 844 }
930 845
931 if (kind != w83783s) { 846 if (kind != w83783s) {
932 data->lm75[1] = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
933 if (!(data->lm75[1])) {
934 err = -ENOMEM;
935 goto ERROR_SC_1;
936 }
937
938 if (force_subclients[0] == id && 847 if (force_subclients[0] == id &&
939 force_subclients[1] == address) { 848 force_subclients[1] == address) {
940 data->lm75[1]->addr = force_subclients[3]; 849 sc_addr[1] = force_subclients[3];
941 } else { 850 } else {
942 data->lm75[1]->addr = 0x48 + ((val1 >> 4) & 0x07); 851 sc_addr[1] = 0x48 + ((val1 >> 4) & 0x07);
943 } 852 }
944 if (data->lm75[0]->addr == data->lm75[1]->addr) { 853 if (sc_addr[0] == sc_addr[1]) {
945 dev_err(&new_client->dev, 854 dev_err(&new_client->dev,
946 "Duplicate addresses 0x%x for subclients.\n", 855 "Duplicate addresses 0x%x for subclients.\n",
947 data->lm75[0]->addr); 856 sc_addr[0]);
948 err = -EBUSY; 857 err = -EBUSY;
949 goto ERROR_SC_2; 858 goto ERROR_SC_2;
950 } 859 }
951 } 860 }
952 861
953 if (kind == w83781d)
954 client_name = "w83781d subclient";
955 else if (kind == w83782d)
956 client_name = "w83782d subclient";
957 else if (kind == w83783s)
958 client_name = "w83783s subclient";
959 else if (kind == as99127f)
960 client_name = "as99127f subclient";
961
962 for (i = 0; i <= 1; i++) { 862 for (i = 0; i <= 1; i++) {
963 /* store all data in w83781d */ 863 data->lm75[i] = i2c_new_dummy(adapter, sc_addr[i]);
964 i2c_set_clientdata(data->lm75[i], NULL); 864 if (!data->lm75[i]) {
965 data->lm75[i]->adapter = adapter;
966 data->lm75[i]->driver = &w83781d_driver;
967 data->lm75[i]->flags = 0;
968 strlcpy(data->lm75[i]->name, client_name,
969 I2C_NAME_SIZE);
970 if ((err = i2c_attach_client(data->lm75[i]))) {
971 dev_err(&new_client->dev, "Subclient %d " 865 dev_err(&new_client->dev, "Subclient %d "
972 "registration at address 0x%x " 866 "registration at address 0x%x "
973 "failed.\n", i, data->lm75[i]->addr); 867 "failed.\n", i, sc_addr[i]);
868 err = -ENOMEM;
974 if (i == 1) 869 if (i == 1)
975 goto ERROR_SC_3; 870 goto ERROR_SC_3;
976 goto ERROR_SC_2; 871 goto ERROR_SC_2;
@@ -983,12 +878,9 @@ w83781d_detect_subclients(struct i2c_adapter *adapter, int address, int kind,
983 878
984/* Undo inits in case of errors */ 879/* Undo inits in case of errors */
985ERROR_SC_3: 880ERROR_SC_3:
986 i2c_detach_client(data->lm75[0]); 881 i2c_unregister_device(data->lm75[0]);
987ERROR_SC_2: 882ERROR_SC_2:
988 kfree(data->lm75[1]);
989ERROR_SC_1: 883ERROR_SC_1:
990 kfree(data->lm75[0]);
991ERROR_SC_0:
992 return err; 884 return err;
993} 885}
994 886
@@ -1029,7 +921,7 @@ static struct attribute* w83781d_attributes[] = {
1029 &dev_attr_vrm.attr, 921 &dev_attr_vrm.attr,
1030 &dev_attr_alarms.attr, 922 &dev_attr_alarms.attr,
1031 &dev_attr_beep_mask.attr, 923 &dev_attr_beep_mask.attr,
1032 &dev_attr_beep_enable.attr, 924 &sensor_dev_attr_beep_enable.dev_attr.attr,
1033 NULL 925 NULL
1034}; 926};
1035static const struct attribute_group w83781d_group = { 927static const struct attribute_group w83781d_group = {
@@ -1151,96 +1043,74 @@ w83781d_create_files(struct device *dev, int kind, int is_isa)
1151 } 1043 }
1152 } 1044 }
1153 1045
1154 if (is_isa) {
1155 err = device_create_file(&pdev->dev, &dev_attr_name);
1156 if (err)
1157 return err;
1158 }
1159
1160 return 0; 1046 return 0;
1161} 1047}
1162 1048
1049/* Return 0 if detection is successful, -ENODEV otherwise */
1163static int 1050static int
1164w83781d_detect(struct i2c_adapter *adapter, int address, int kind) 1051w83781d_detect(struct i2c_client *client, int kind,
1052 struct i2c_board_info *info)
1165{ 1053{
1166 int val1 = 0, val2; 1054 int val1 = 0, val2;
1167 struct i2c_client *client; 1055 struct w83781d_data *isa = w83781d_data_if_isa();
1168 struct device *dev; 1056 struct i2c_adapter *adapter = client->adapter;
1169 struct w83781d_data *data; 1057 int address = client->addr;
1170 int err;
1171 const char *client_name = ""; 1058 const char *client_name = "";
1172 enum vendor { winbond, asus } vendid; 1059 enum vendor { winbond, asus } vendid;
1173 1060
1174 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 1061 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1175 err = -EINVAL; 1062 return -ENODEV;
1176 goto ERROR1;
1177 }
1178
1179 /* OK. For now, we presume we have a valid client. We now create the
1180 client structure, even though we cannot fill it completely yet.
1181 But it allows us to access w83781d_{read,write}_value. */
1182
1183 if (!(data = kzalloc(sizeof(struct w83781d_data), GFP_KERNEL))) {
1184 err = -ENOMEM;
1185 goto ERROR1;
1186 }
1187
1188 client = &data->client;
1189 i2c_set_clientdata(client, data);
1190 client->addr = address;
1191 mutex_init(&data->lock);
1192 client->adapter = adapter;
1193 client->driver = &w83781d_driver;
1194 dev = &client->dev;
1195 1063
1196 /* Now, we do the remaining detection. */ 1064 /* We block updates of the ISA device to minimize the risk of
1065 concurrent access to the same W83781D chip through different
1066 interfaces. */
1067 if (isa)
1068 mutex_lock(&isa->update_lock);
1197 1069
1198 /* The w8378?d may be stuck in some other bank than bank 0. This may 1070 /* The w8378?d may be stuck in some other bank than bank 0. This may
1199 make reading other information impossible. Specify a force=... or 1071 make reading other information impossible. Specify a force=... or
1200 force_*=... parameter, and the Winbond will be reset to the right 1072 force_*=... parameter, and the Winbond will be reset to the right
1201 bank. */ 1073 bank. */
1202 if (kind < 0) { 1074 if (kind < 0) {
1203 if (w83781d_read_value(data, W83781D_REG_CONFIG) & 0x80) { 1075 if (i2c_smbus_read_byte_data
1076 (client, W83781D_REG_CONFIG) & 0x80) {
1204 dev_dbg(&adapter->dev, "Detection of w83781d chip " 1077 dev_dbg(&adapter->dev, "Detection of w83781d chip "
1205 "failed at step 3\n"); 1078 "failed at step 3\n");
1206 err = -ENODEV; 1079 goto err_nodev;
1207 goto ERROR2;
1208 } 1080 }
1209 val1 = w83781d_read_value(data, W83781D_REG_BANK); 1081 val1 = i2c_smbus_read_byte_data(client, W83781D_REG_BANK);
1210 val2 = w83781d_read_value(data, W83781D_REG_CHIPMAN); 1082 val2 = i2c_smbus_read_byte_data(client, W83781D_REG_CHIPMAN);
1211 /* Check for Winbond or Asus ID if in bank 0 */ 1083 /* Check for Winbond or Asus ID if in bank 0 */
1212 if ((!(val1 & 0x07)) && 1084 if ((!(val1 & 0x07)) &&
1213 (((!(val1 & 0x80)) && (val2 != 0xa3) && (val2 != 0xc3)) 1085 (((!(val1 & 0x80)) && (val2 != 0xa3) && (val2 != 0xc3))
1214 || ((val1 & 0x80) && (val2 != 0x5c) && (val2 != 0x12)))) { 1086 || ((val1 & 0x80) && (val2 != 0x5c) && (val2 != 0x12)))) {
1215 dev_dbg(&adapter->dev, "Detection of w83781d chip " 1087 dev_dbg(&adapter->dev, "Detection of w83781d chip "
1216 "failed at step 4\n"); 1088 "failed at step 4\n");
1217 err = -ENODEV; 1089 goto err_nodev;
1218 goto ERROR2;
1219 } 1090 }
1220 /* If Winbond SMBus, check address at 0x48. 1091 /* If Winbond SMBus, check address at 0x48.
1221 Asus doesn't support, except for as99127f rev.2 */ 1092 Asus doesn't support, except for as99127f rev.2 */
1222 if ((!(val1 & 0x80) && (val2 == 0xa3)) || 1093 if ((!(val1 & 0x80) && (val2 == 0xa3)) ||
1223 ((val1 & 0x80) && (val2 == 0x5c))) { 1094 ((val1 & 0x80) && (val2 == 0x5c))) {
1224 if (w83781d_read_value 1095 if (i2c_smbus_read_byte_data
1225 (data, W83781D_REG_I2C_ADDR) != address) { 1096 (client, W83781D_REG_I2C_ADDR) != address) {
1226 dev_dbg(&adapter->dev, "Detection of w83781d " 1097 dev_dbg(&adapter->dev, "Detection of w83781d "
1227 "chip failed at step 5\n"); 1098 "chip failed at step 5\n");
1228 err = -ENODEV; 1099 goto err_nodev;
1229 goto ERROR2;
1230 } 1100 }
1231 } 1101 }
1232 } 1102 }
1233 1103
1234 /* We have either had a force parameter, or we have already detected the 1104 /* We have either had a force parameter, or we have already detected the
1235 Winbond. Put it now into bank 0 and Vendor ID High Byte */ 1105 Winbond. Put it now into bank 0 and Vendor ID High Byte */
1236 w83781d_write_value(data, W83781D_REG_BANK, 1106 i2c_smbus_write_byte_data(client, W83781D_REG_BANK,
1237 (w83781d_read_value(data, W83781D_REG_BANK) 1107 (i2c_smbus_read_byte_data(client, W83781D_REG_BANK)
1238 & 0x78) | 0x80); 1108 & 0x78) | 0x80);
1239 1109
1240 /* Determine the chip type. */ 1110 /* Determine the chip type. */
1241 if (kind <= 0) { 1111 if (kind <= 0) {
1242 /* get vendor ID */ 1112 /* get vendor ID */
1243 val2 = w83781d_read_value(data, W83781D_REG_CHIPMAN); 1113 val2 = i2c_smbus_read_byte_data(client, W83781D_REG_CHIPMAN);
1244 if (val2 == 0x5c) 1114 if (val2 == 0x5c)
1245 vendid = winbond; 1115 vendid = winbond;
1246 else if (val2 == 0x12) 1116 else if (val2 == 0x12)
@@ -1248,11 +1118,10 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1248 else { 1118 else {
1249 dev_dbg(&adapter->dev, "w83781d chip vendor is " 1119 dev_dbg(&adapter->dev, "w83781d chip vendor is "
1250 "neither Winbond nor Asus\n"); 1120 "neither Winbond nor Asus\n");
1251 err = -ENODEV; 1121 goto err_nodev;
1252 goto ERROR2;
1253 } 1122 }
1254 1123
1255 val1 = w83781d_read_value(data, W83781D_REG_WCHIPID); 1124 val1 = i2c_smbus_read_byte_data(client, W83781D_REG_WCHIPID);
1256 if ((val1 == 0x10 || val1 == 0x11) && vendid == winbond) 1125 if ((val1 == 0x10 || val1 == 0x11) && vendid == winbond)
1257 kind = w83781d; 1126 kind = w83781d;
1258 else if (val1 == 0x30 && vendid == winbond) 1127 else if (val1 == 0x30 && vendid == winbond)
@@ -1266,11 +1135,20 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1266 dev_warn(&adapter->dev, "Ignoring 'force' " 1135 dev_warn(&adapter->dev, "Ignoring 'force' "
1267 "parameter for unknown chip at " 1136 "parameter for unknown chip at "
1268 "address 0x%02x\n", address); 1137 "address 0x%02x\n", address);
1269 err = -EINVAL; 1138 goto err_nodev;
1270 goto ERROR2; 1139 }
1140
1141 if ((kind == w83781d || kind == w83782d)
1142 && w83781d_alias_detect(client, val1)) {
1143 dev_dbg(&adapter->dev, "Device at 0x%02x appears to "
1144 "be the same as ISA device\n", address);
1145 goto err_nodev;
1271 } 1146 }
1272 } 1147 }
1273 1148
1149 if (isa)
1150 mutex_unlock(&isa->update_lock);
1151
1274 if (kind == w83781d) { 1152 if (kind == w83781d) {
1275 client_name = "w83781d"; 1153 client_name = "w83781d";
1276 } else if (kind == w83782d) { 1154 } else if (kind == w83782d) {
@@ -1281,24 +1159,46 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1281 client_name = "as99127f"; 1159 client_name = "as99127f";
1282 } 1160 }
1283 1161
1284 /* Fill in the remaining client fields and put into the global list */ 1162 strlcpy(info->type, client_name, I2C_NAME_SIZE);
1285 strlcpy(client->name, client_name, I2C_NAME_SIZE); 1163
1286 data->type = kind; 1164 return 0;
1165
1166 err_nodev:
1167 if (isa)
1168 mutex_unlock(&isa->update_lock);
1169 return -ENODEV;
1170}
1171
1172static int
1173w83781d_probe(struct i2c_client *client, const struct i2c_device_id *id)
1174{
1175 struct device *dev = &client->dev;
1176 struct w83781d_data *data;
1177 int err;
1178
1179 data = kzalloc(sizeof(struct w83781d_data), GFP_KERNEL);
1180 if (!data) {
1181 err = -ENOMEM;
1182 goto ERROR1;
1183 }
1184
1185 i2c_set_clientdata(client, data);
1186 mutex_init(&data->lock);
1187 mutex_init(&data->update_lock);
1287 1188
1288 /* Tell the I2C layer a new client has arrived */ 1189 data->type = id->driver_data;
1289 if ((err = i2c_attach_client(client))) 1190 data->client = client;
1290 goto ERROR2;
1291 1191
1292 /* attach secondary i2c lm75-like clients */ 1192 /* attach secondary i2c lm75-like clients */
1293 if ((err = w83781d_detect_subclients(adapter, address, 1193 err = w83781d_detect_subclients(client);
1294 kind, client))) 1194 if (err)
1295 goto ERROR3; 1195 goto ERROR3;
1296 1196
1297 /* Initialize the chip */ 1197 /* Initialize the chip */
1298 w83781d_init_device(dev); 1198 w83781d_init_device(dev);
1299 1199
1300 /* Register sysfs hooks */ 1200 /* Register sysfs hooks */
1301 err = w83781d_create_files(dev, kind, 0); 1201 err = w83781d_create_files(dev, data->type, 0);
1302 if (err) 1202 if (err)
1303 goto ERROR4; 1203 goto ERROR4;
1304 1204
@@ -1314,264 +1214,113 @@ ERROR4:
1314 sysfs_remove_group(&dev->kobj, &w83781d_group); 1214 sysfs_remove_group(&dev->kobj, &w83781d_group);
1315 sysfs_remove_group(&dev->kobj, &w83781d_group_opt); 1215 sysfs_remove_group(&dev->kobj, &w83781d_group_opt);
1316 1216
1317 if (data->lm75[1]) { 1217 if (data->lm75[0])
1318 i2c_detach_client(data->lm75[1]); 1218 i2c_unregister_device(data->lm75[0]);
1319 kfree(data->lm75[1]); 1219 if (data->lm75[1])
1320 } 1220 i2c_unregister_device(data->lm75[1]);
1321 if (data->lm75[0]) {
1322 i2c_detach_client(data->lm75[0]);
1323 kfree(data->lm75[0]);
1324 }
1325ERROR3: 1221ERROR3:
1326 i2c_detach_client(client); 1222 i2c_set_clientdata(client, NULL);
1327ERROR2:
1328 kfree(data); 1223 kfree(data);
1329ERROR1: 1224ERROR1:
1330 return err; 1225 return err;
1331} 1226}
1332 1227
1333static int 1228static int
1334w83781d_detach_client(struct i2c_client *client) 1229w83781d_remove(struct i2c_client *client)
1335{ 1230{
1336 struct w83781d_data *data = i2c_get_clientdata(client); 1231 struct w83781d_data *data = i2c_get_clientdata(client);
1337 int err; 1232 struct device *dev = &client->dev;
1338
1339 /* main client */
1340 if (data) {
1341 hwmon_device_unregister(data->hwmon_dev);
1342 sysfs_remove_group(&client->dev.kobj, &w83781d_group);
1343 sysfs_remove_group(&client->dev.kobj, &w83781d_group_opt);
1344 }
1345
1346 if ((err = i2c_detach_client(client)))
1347 return err;
1348 1233
1349 /* main client */ 1234 hwmon_device_unregister(data->hwmon_dev);
1350 if (data)
1351 kfree(data);
1352
1353 /* subclient */
1354 else
1355 kfree(client);
1356
1357 return 0;
1358}
1359
1360static int __devinit
1361w83781d_isa_probe(struct platform_device *pdev)
1362{
1363 int err, reg;
1364 struct w83781d_data *data;
1365 struct resource *res;
1366 const char *name;
1367
1368 /* Reserve the ISA region */
1369 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
1370 if (!request_region(res->start + W83781D_ADDR_REG_OFFSET, 2,
1371 "w83781d")) {
1372 err = -EBUSY;
1373 goto exit;
1374 }
1375
1376 if (!(data = kzalloc(sizeof(struct w83781d_data), GFP_KERNEL))) {
1377 err = -ENOMEM;
1378 goto exit_release_region;
1379 }
1380 mutex_init(&data->lock);
1381 data->client.addr = res->start;
1382 i2c_set_clientdata(&data->client, data);
1383 platform_set_drvdata(pdev, data);
1384
1385 reg = w83781d_read_value(data, W83781D_REG_WCHIPID);
1386 switch (reg) {
1387 case 0x30:
1388 data->type = w83782d;
1389 name = "w83782d";
1390 break;
1391 default:
1392 data->type = w83781d;
1393 name = "w83781d";
1394 }
1395 strlcpy(data->client.name, name, I2C_NAME_SIZE);
1396
1397 /* Initialize the W83781D chip */
1398 w83781d_init_device(&pdev->dev);
1399
1400 /* Register sysfs hooks */
1401 err = w83781d_create_files(&pdev->dev, data->type, 1);
1402 if (err)
1403 goto exit_remove_files;
1404
1405 data->hwmon_dev = hwmon_device_register(&pdev->dev);
1406 if (IS_ERR(data->hwmon_dev)) {
1407 err = PTR_ERR(data->hwmon_dev);
1408 goto exit_remove_files;
1409 }
1410
1411 return 0;
1412 1235
1413 exit_remove_files: 1236 sysfs_remove_group(&dev->kobj, &w83781d_group);
1414 sysfs_remove_group(&pdev->dev.kobj, &w83781d_group); 1237 sysfs_remove_group(&dev->kobj, &w83781d_group_opt);
1415 sysfs_remove_group(&pdev->dev.kobj, &w83781d_group_opt);
1416 device_remove_file(&pdev->dev, &dev_attr_name);
1417 kfree(data);
1418 exit_release_region:
1419 release_region(res->start + W83781D_ADDR_REG_OFFSET, 2);
1420 exit:
1421 return err;
1422}
1423 1238
1424static int __devexit 1239 if (data->lm75[0])
1425w83781d_isa_remove(struct platform_device *pdev) 1240 i2c_unregister_device(data->lm75[0]);
1426{ 1241 if (data->lm75[1])
1427 struct w83781d_data *data = platform_get_drvdata(pdev); 1242 i2c_unregister_device(data->lm75[1]);
1428 1243
1429 hwmon_device_unregister(data->hwmon_dev); 1244 i2c_set_clientdata(client, NULL);
1430 sysfs_remove_group(&pdev->dev.kobj, &w83781d_group);
1431 sysfs_remove_group(&pdev->dev.kobj, &w83781d_group_opt);
1432 device_remove_file(&pdev->dev, &dev_attr_name);
1433 release_region(data->client.addr + W83781D_ADDR_REG_OFFSET, 2);
1434 kfree(data); 1245 kfree(data);
1435 1246
1436 return 0; 1247 return 0;
1437} 1248}
1438 1249
1439/* The SMBus locks itself, usually, but nothing may access the Winbond between
1440 bank switches. ISA access must always be locked explicitly!
1441 We ignore the W83781D BUSY flag at this moment - it could lead to deadlocks,
1442 would slow down the W83781D access and should not be necessary.
1443 There are some ugly typecasts here, but the good news is - they should
1444 nowhere else be necessary! */
1445static int 1250static int
1446w83781d_read_value(struct w83781d_data *data, u16 reg) 1251w83781d_read_value_i2c(struct w83781d_data *data, u16 reg)
1447{ 1252{
1448 struct i2c_client *client = &data->client; 1253 struct i2c_client *client = data->client;
1449 int res, word_sized, bank; 1254 int res, bank;
1450 struct i2c_client *cl; 1255 struct i2c_client *cl;
1451 1256
1452 mutex_lock(&data->lock); 1257 bank = (reg >> 8) & 0x0f;
1453 if (!client->driver) { /* ISA device */ 1258 if (bank > 2)
1454 word_sized = (((reg & 0xff00) == 0x100) 1259 /* switch banks */
1455 || ((reg & 0xff00) == 0x200)) 1260 i2c_smbus_write_byte_data(client, W83781D_REG_BANK,
1456 && (((reg & 0x00ff) == 0x50) 1261 bank);
1457 || ((reg & 0x00ff) == 0x53) 1262 if (bank == 0 || bank > 2) {
1458 || ((reg & 0x00ff) == 0x55)); 1263 res = i2c_smbus_read_byte_data(client, reg & 0xff);
1459 if (reg & 0xff00) {
1460 outb_p(W83781D_REG_BANK,
1461 client->addr + W83781D_ADDR_REG_OFFSET);
1462 outb_p(reg >> 8,
1463 client->addr + W83781D_DATA_REG_OFFSET);
1464 }
1465 outb_p(reg & 0xff, client->addr + W83781D_ADDR_REG_OFFSET);
1466 res = inb_p(client->addr + W83781D_DATA_REG_OFFSET);
1467 if (word_sized) {
1468 outb_p((reg & 0xff) + 1,
1469 client->addr + W83781D_ADDR_REG_OFFSET);
1470 res =
1471 (res << 8) + inb_p(client->addr +
1472 W83781D_DATA_REG_OFFSET);
1473 }
1474 if (reg & 0xff00) {
1475 outb_p(W83781D_REG_BANK,
1476 client->addr + W83781D_ADDR_REG_OFFSET);
1477 outb_p(0, client->addr + W83781D_DATA_REG_OFFSET);
1478 }
1479 } else { 1264 } else {
1480 bank = (reg >> 8) & 0x0f; 1265 /* switch to subclient */
1481 if (bank > 2) 1266 cl = data->lm75[bank - 1];
1482 /* switch banks */ 1267 /* convert from ISA to LM75 I2C addresses */
1483 i2c_smbus_write_byte_data(client, W83781D_REG_BANK, 1268 switch (reg & 0xff) {
1484 bank); 1269 case 0x50: /* TEMP */
1485 if (bank == 0 || bank > 2) { 1270 res = swab16(i2c_smbus_read_word_data(cl, 0));
1486 res = i2c_smbus_read_byte_data(client, reg & 0xff); 1271 break;
1487 } else { 1272 case 0x52: /* CONFIG */
1488 /* switch to subclient */ 1273 res = i2c_smbus_read_byte_data(cl, 1);
1489 cl = data->lm75[bank - 1]; 1274 break;
1490 /* convert from ISA to LM75 I2C addresses */ 1275 case 0x53: /* HYST */
1491 switch (reg & 0xff) { 1276 res = swab16(i2c_smbus_read_word_data(cl, 2));
1492 case 0x50: /* TEMP */ 1277 break;
1493 res = swab16(i2c_smbus_read_word_data(cl, 0)); 1278 case 0x55: /* OVER */
1494 break; 1279 default:
1495 case 0x52: /* CONFIG */ 1280 res = swab16(i2c_smbus_read_word_data(cl, 3));
1496 res = i2c_smbus_read_byte_data(cl, 1); 1281 break;
1497 break;
1498 case 0x53: /* HYST */
1499 res = swab16(i2c_smbus_read_word_data(cl, 2));
1500 break;
1501 case 0x55: /* OVER */
1502 default:
1503 res = swab16(i2c_smbus_read_word_data(cl, 3));
1504 break;
1505 }
1506 } 1282 }
1507 if (bank > 2)
1508 i2c_smbus_write_byte_data(client, W83781D_REG_BANK, 0);
1509 } 1283 }
1510 mutex_unlock(&data->lock); 1284 if (bank > 2)
1285 i2c_smbus_write_byte_data(client, W83781D_REG_BANK, 0);
1286
1511 return res; 1287 return res;
1512} 1288}
1513 1289
1514static int 1290static int
1515w83781d_write_value(struct w83781d_data *data, u16 reg, u16 value) 1291w83781d_write_value_i2c(struct w83781d_data *data, u16 reg, u16 value)
1516{ 1292{
1517 struct i2c_client *client = &data->client; 1293 struct i2c_client *client = data->client;
1518 int word_sized, bank; 1294 int bank;
1519 struct i2c_client *cl; 1295 struct i2c_client *cl;
1520 1296
1521 mutex_lock(&data->lock); 1297 bank = (reg >> 8) & 0x0f;
1522 if (!client->driver) { /* ISA device */ 1298 if (bank > 2)
1523 word_sized = (((reg & 0xff00) == 0x100) 1299 /* switch banks */
1524 || ((reg & 0xff00) == 0x200)) 1300 i2c_smbus_write_byte_data(client, W83781D_REG_BANK,
1525 && (((reg & 0x00ff) == 0x53) 1301 bank);
1526 || ((reg & 0x00ff) == 0x55)); 1302 if (bank == 0 || bank > 2) {
1527 if (reg & 0xff00) { 1303 i2c_smbus_write_byte_data(client, reg & 0xff,
1528 outb_p(W83781D_REG_BANK, 1304 value & 0xff);
1529 client->addr + W83781D_ADDR_REG_OFFSET);
1530 outb_p(reg >> 8,
1531 client->addr + W83781D_DATA_REG_OFFSET);
1532 }
1533 outb_p(reg & 0xff, client->addr + W83781D_ADDR_REG_OFFSET);
1534 if (word_sized) {
1535 outb_p(value >> 8,
1536 client->addr + W83781D_DATA_REG_OFFSET);
1537 outb_p((reg & 0xff) + 1,
1538 client->addr + W83781D_ADDR_REG_OFFSET);
1539 }
1540 outb_p(value & 0xff, client->addr + W83781D_DATA_REG_OFFSET);
1541 if (reg & 0xff00) {
1542 outb_p(W83781D_REG_BANK,
1543 client->addr + W83781D_ADDR_REG_OFFSET);
1544 outb_p(0, client->addr + W83781D_DATA_REG_OFFSET);
1545 }
1546 } else { 1305 } else {
1547 bank = (reg >> 8) & 0x0f; 1306 /* switch to subclient */
1548 if (bank > 2) 1307 cl = data->lm75[bank - 1];
1549 /* switch banks */ 1308 /* convert from ISA to LM75 I2C addresses */
1550 i2c_smbus_write_byte_data(client, W83781D_REG_BANK, 1309 switch (reg & 0xff) {
1551 bank); 1310 case 0x52: /* CONFIG */
1552 if (bank == 0 || bank > 2) { 1311 i2c_smbus_write_byte_data(cl, 1, value & 0xff);
1553 i2c_smbus_write_byte_data(client, reg & 0xff, 1312 break;
1554 value & 0xff); 1313 case 0x53: /* HYST */
1555 } else { 1314 i2c_smbus_write_word_data(cl, 2, swab16(value));
1556 /* switch to subclient */ 1315 break;
1557 cl = data->lm75[bank - 1]; 1316 case 0x55: /* OVER */
1558 /* convert from ISA to LM75 I2C addresses */ 1317 i2c_smbus_write_word_data(cl, 3, swab16(value));
1559 switch (reg & 0xff) { 1318 break;
1560 case 0x52: /* CONFIG */
1561 i2c_smbus_write_byte_data(cl, 1, value & 0xff);
1562 break;
1563 case 0x53: /* HYST */
1564 i2c_smbus_write_word_data(cl, 2, swab16(value));
1565 break;
1566 case 0x55: /* OVER */
1567 i2c_smbus_write_word_data(cl, 3, swab16(value));
1568 break;
1569 }
1570 } 1319 }
1571 if (bank > 2)
1572 i2c_smbus_write_byte_data(client, W83781D_REG_BANK, 0);
1573 } 1320 }
1574 mutex_unlock(&data->lock); 1321 if (bank > 2)
1322 i2c_smbus_write_byte_data(client, W83781D_REG_BANK, 0);
1323
1575 return 0; 1324 return 0;
1576} 1325}
1577 1326
@@ -1678,7 +1427,7 @@ w83781d_init_device(struct device *dev)
1678static struct w83781d_data *w83781d_update_device(struct device *dev) 1427static struct w83781d_data *w83781d_update_device(struct device *dev)
1679{ 1428{
1680 struct w83781d_data *data = dev_get_drvdata(dev); 1429 struct w83781d_data *data = dev_get_drvdata(dev);
1681 struct i2c_client *client = &data->client; 1430 struct i2c_client *client = data->client;
1682 int i; 1431 int i;
1683 1432
1684 mutex_lock(&data->update_lock); 1433 mutex_lock(&data->update_lock);
@@ -1775,8 +1524,7 @@ static struct w83781d_data *w83781d_update_device(struct device *dev)
1775 W83781D_REG_ALARM2) << 8); 1524 W83781D_REG_ALARM2) << 8);
1776 } 1525 }
1777 i = w83781d_read_value(data, W83781D_REG_BEEP_INTS2); 1526 i = w83781d_read_value(data, W83781D_REG_BEEP_INTS2);
1778 data->beep_enable = i >> 7; 1527 data->beep_mask = (i << 8) +
1779 data->beep_mask = ((i & 0x7f) << 8) +
1780 w83781d_read_value(data, W83781D_REG_BEEP_INTS1); 1528 w83781d_read_value(data, W83781D_REG_BEEP_INTS1);
1781 if ((data->type != w83781d) && (data->type != as99127f)) { 1529 if ((data->type != w83781d) && (data->type != as99127f)) {
1782 data->beep_mask |= 1530 data->beep_mask |=
@@ -1792,6 +1540,275 @@ static struct w83781d_data *w83781d_update_device(struct device *dev)
1792 return data; 1540 return data;
1793} 1541}
1794 1542
1543static const struct i2c_device_id w83781d_ids[] = {
1544 { "w83781d", w83781d, },
1545 { "w83782d", w83782d, },
1546 { "w83783s", w83783s, },
1547 { "as99127f", as99127f },
1548 { /* LIST END */ }
1549};
1550MODULE_DEVICE_TABLE(i2c, w83781d_ids);
1551
1552static struct i2c_driver w83781d_driver = {
1553 .class = I2C_CLASS_HWMON,
1554 .driver = {
1555 .name = "w83781d",
1556 },
1557 .probe = w83781d_probe,
1558 .remove = w83781d_remove,
1559 .id_table = w83781d_ids,
1560 .detect = w83781d_detect,
1561 .address_data = &addr_data,
1562};
1563
1564/*
1565 * ISA related code
1566 */
1567#ifdef CONFIG_ISA
1568
1569/* ISA device, if found */
1570static struct platform_device *pdev;
1571
1572static unsigned short isa_address = 0x290;
1573
1574/* I2C devices get this name attribute automatically, but for ISA devices
1575 we must create it by ourselves. */
1576static ssize_t
1577show_name(struct device *dev, struct device_attribute *devattr, char *buf)
1578{
1579 struct w83781d_data *data = dev_get_drvdata(dev);
1580 return sprintf(buf, "%s\n", data->name);
1581}
1582static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
1583
1584static struct w83781d_data *w83781d_data_if_isa(void)
1585{
1586 return pdev ? platform_get_drvdata(pdev) : NULL;
1587}
1588
1589/* Returns 1 if the I2C chip appears to be an alias of the ISA chip */
1590static int w83781d_alias_detect(struct i2c_client *client, u8 chipid)
1591{
1592 struct w83781d_data *isa;
1593 int i;
1594
1595 if (!pdev) /* No ISA chip */
1596 return 0;
1597
1598 isa = platform_get_drvdata(pdev);
1599
1600 if (w83781d_read_value(isa, W83781D_REG_I2C_ADDR) != client->addr)
1601 return 0; /* Address doesn't match */
1602 if (w83781d_read_value(isa, W83781D_REG_WCHIPID) != chipid)
1603 return 0; /* Chip type doesn't match */
1604
1605 /* We compare all the limit registers, the config register and the
1606 * interrupt mask registers */
1607 for (i = 0x2b; i <= 0x3d; i++) {
1608 if (w83781d_read_value(isa, i) !=
1609 i2c_smbus_read_byte_data(client, i))
1610 return 0;
1611 }
1612 if (w83781d_read_value(isa, W83781D_REG_CONFIG) !=
1613 i2c_smbus_read_byte_data(client, W83781D_REG_CONFIG))
1614 return 0;
1615 for (i = 0x43; i <= 0x46; i++) {
1616 if (w83781d_read_value(isa, i) !=
1617 i2c_smbus_read_byte_data(client, i))
1618 return 0;
1619 }
1620
1621 return 1;
1622}
1623
1624static int
1625w83781d_read_value_isa(struct w83781d_data *data, u16 reg)
1626{
1627 int word_sized, res;
1628
1629 word_sized = (((reg & 0xff00) == 0x100)
1630 || ((reg & 0xff00) == 0x200))
1631 && (((reg & 0x00ff) == 0x50)
1632 || ((reg & 0x00ff) == 0x53)
1633 || ((reg & 0x00ff) == 0x55));
1634 if (reg & 0xff00) {
1635 outb_p(W83781D_REG_BANK,
1636 data->isa_addr + W83781D_ADDR_REG_OFFSET);
1637 outb_p(reg >> 8,
1638 data->isa_addr + W83781D_DATA_REG_OFFSET);
1639 }
1640 outb_p(reg & 0xff, data->isa_addr + W83781D_ADDR_REG_OFFSET);
1641 res = inb_p(data->isa_addr + W83781D_DATA_REG_OFFSET);
1642 if (word_sized) {
1643 outb_p((reg & 0xff) + 1,
1644 data->isa_addr + W83781D_ADDR_REG_OFFSET);
1645 res =
1646 (res << 8) + inb_p(data->isa_addr +
1647 W83781D_DATA_REG_OFFSET);
1648 }
1649 if (reg & 0xff00) {
1650 outb_p(W83781D_REG_BANK,
1651 data->isa_addr + W83781D_ADDR_REG_OFFSET);
1652 outb_p(0, data->isa_addr + W83781D_DATA_REG_OFFSET);
1653 }
1654 return res;
1655}
1656
1657static void
1658w83781d_write_value_isa(struct w83781d_data *data, u16 reg, u16 value)
1659{
1660 int word_sized;
1661
1662 word_sized = (((reg & 0xff00) == 0x100)
1663 || ((reg & 0xff00) == 0x200))
1664 && (((reg & 0x00ff) == 0x53)
1665 || ((reg & 0x00ff) == 0x55));
1666 if (reg & 0xff00) {
1667 outb_p(W83781D_REG_BANK,
1668 data->isa_addr + W83781D_ADDR_REG_OFFSET);
1669 outb_p(reg >> 8,
1670 data->isa_addr + W83781D_DATA_REG_OFFSET);
1671 }
1672 outb_p(reg & 0xff, data->isa_addr + W83781D_ADDR_REG_OFFSET);
1673 if (word_sized) {
1674 outb_p(value >> 8,
1675 data->isa_addr + W83781D_DATA_REG_OFFSET);
1676 outb_p((reg & 0xff) + 1,
1677 data->isa_addr + W83781D_ADDR_REG_OFFSET);
1678 }
1679 outb_p(value & 0xff, data->isa_addr + W83781D_DATA_REG_OFFSET);
1680 if (reg & 0xff00) {
1681 outb_p(W83781D_REG_BANK,
1682 data->isa_addr + W83781D_ADDR_REG_OFFSET);
1683 outb_p(0, data->isa_addr + W83781D_DATA_REG_OFFSET);
1684 }
1685}
1686
1687/* The SMBus locks itself, usually, but nothing may access the Winbond between
1688 bank switches. ISA access must always be locked explicitly!
1689 We ignore the W83781D BUSY flag at this moment - it could lead to deadlocks,
1690 would slow down the W83781D access and should not be necessary.
1691 There are some ugly typecasts here, but the good news is - they should
1692 nowhere else be necessary! */
1693static int
1694w83781d_read_value(struct w83781d_data *data, u16 reg)
1695{
1696 struct i2c_client *client = data->client;
1697 int res;
1698
1699 mutex_lock(&data->lock);
1700 if (client)
1701 res = w83781d_read_value_i2c(data, reg);
1702 else
1703 res = w83781d_read_value_isa(data, reg);
1704 mutex_unlock(&data->lock);
1705 return res;
1706}
1707
1708static int
1709w83781d_write_value(struct w83781d_data *data, u16 reg, u16 value)
1710{
1711 struct i2c_client *client = data->client;
1712
1713 mutex_lock(&data->lock);
1714 if (client)
1715 w83781d_write_value_i2c(data, reg, value);
1716 else
1717 w83781d_write_value_isa(data, reg, value);
1718 mutex_unlock(&data->lock);
1719 return 0;
1720}
1721
1722static int __devinit
1723w83781d_isa_probe(struct platform_device *pdev)
1724{
1725 int err, reg;
1726 struct w83781d_data *data;
1727 struct resource *res;
1728
1729 /* Reserve the ISA region */
1730 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
1731 if (!request_region(res->start + W83781D_ADDR_REG_OFFSET, 2,
1732 "w83781d")) {
1733 err = -EBUSY;
1734 goto exit;
1735 }
1736
1737 data = kzalloc(sizeof(struct w83781d_data), GFP_KERNEL);
1738 if (!data) {
1739 err = -ENOMEM;
1740 goto exit_release_region;
1741 }
1742 mutex_init(&data->lock);
1743 data->isa_addr = res->start;
1744 platform_set_drvdata(pdev, data);
1745
1746 reg = w83781d_read_value(data, W83781D_REG_WCHIPID);
1747 switch (reg) {
1748 case 0x30:
1749 data->type = w83782d;
1750 data->name = "w83782d";
1751 break;
1752 default:
1753 data->type = w83781d;
1754 data->name = "w83781d";
1755 }
1756
1757 /* Initialize the W83781D chip */
1758 w83781d_init_device(&pdev->dev);
1759
1760 /* Register sysfs hooks */
1761 err = w83781d_create_files(&pdev->dev, data->type, 1);
1762 if (err)
1763 goto exit_remove_files;
1764
1765 err = device_create_file(&pdev->dev, &dev_attr_name);
1766 if (err)
1767 goto exit_remove_files;
1768
1769 data->hwmon_dev = hwmon_device_register(&pdev->dev);
1770 if (IS_ERR(data->hwmon_dev)) {
1771 err = PTR_ERR(data->hwmon_dev);
1772 goto exit_remove_files;
1773 }
1774
1775 return 0;
1776
1777 exit_remove_files:
1778 sysfs_remove_group(&pdev->dev.kobj, &w83781d_group);
1779 sysfs_remove_group(&pdev->dev.kobj, &w83781d_group_opt);
1780 device_remove_file(&pdev->dev, &dev_attr_name);
1781 kfree(data);
1782 exit_release_region:
1783 release_region(res->start + W83781D_ADDR_REG_OFFSET, 2);
1784 exit:
1785 return err;
1786}
1787
1788static int __devexit
1789w83781d_isa_remove(struct platform_device *pdev)
1790{
1791 struct w83781d_data *data = platform_get_drvdata(pdev);
1792
1793 hwmon_device_unregister(data->hwmon_dev);
1794 sysfs_remove_group(&pdev->dev.kobj, &w83781d_group);
1795 sysfs_remove_group(&pdev->dev.kobj, &w83781d_group_opt);
1796 device_remove_file(&pdev->dev, &dev_attr_name);
1797 release_region(data->isa_addr + W83781D_ADDR_REG_OFFSET, 2);
1798 kfree(data);
1799
1800 return 0;
1801}
1802
1803static struct platform_driver w83781d_isa_driver = {
1804 .driver = {
1805 .owner = THIS_MODULE,
1806 .name = "w83781d",
1807 },
1808 .probe = w83781d_isa_probe,
1809 .remove = __devexit_p(w83781d_isa_remove),
1810};
1811
1795/* return 1 if a supported chip is found, 0 otherwise */ 1812/* return 1 if a supported chip is found, 0 otherwise */
1796static int __init 1813static int __init
1797w83781d_isa_found(unsigned short address) 1814w83781d_isa_found(unsigned short address)
@@ -1928,18 +1945,14 @@ w83781d_isa_device_add(unsigned short address)
1928} 1945}
1929 1946
1930static int __init 1947static int __init
1931sensors_w83781d_init(void) 1948w83781d_isa_register(void)
1932{ 1949{
1933 int res; 1950 int res;
1934 1951
1935 res = i2c_add_driver(&w83781d_driver);
1936 if (res)
1937 goto exit;
1938
1939 if (w83781d_isa_found(isa_address)) { 1952 if (w83781d_isa_found(isa_address)) {
1940 res = platform_driver_register(&w83781d_isa_driver); 1953 res = platform_driver_register(&w83781d_isa_driver);
1941 if (res) 1954 if (res)
1942 goto exit_unreg_i2c_driver; 1955 goto exit;
1943 1956
1944 /* Sets global pdev as a side effect */ 1957 /* Sets global pdev as a side effect */
1945 res = w83781d_isa_device_add(isa_address); 1958 res = w83781d_isa_device_add(isa_address);
@@ -1949,21 +1962,94 @@ sensors_w83781d_init(void)
1949 1962
1950 return 0; 1963 return 0;
1951 1964
1952 exit_unreg_isa_driver: 1965exit_unreg_isa_driver:
1953 platform_driver_unregister(&w83781d_isa_driver); 1966 platform_driver_unregister(&w83781d_isa_driver);
1954 exit_unreg_i2c_driver: 1967exit:
1955 i2c_del_driver(&w83781d_driver);
1956 exit:
1957 return res; 1968 return res;
1958} 1969}
1959 1970
1960static void __exit 1971static void __exit
1961sensors_w83781d_exit(void) 1972w83781d_isa_unregister(void)
1962{ 1973{
1963 if (pdev) { 1974 if (pdev) {
1964 platform_device_unregister(pdev); 1975 platform_device_unregister(pdev);
1965 platform_driver_unregister(&w83781d_isa_driver); 1976 platform_driver_unregister(&w83781d_isa_driver);
1966 } 1977 }
1978}
1979#else /* !CONFIG_ISA */
1980
1981static struct w83781d_data *w83781d_data_if_isa(void)
1982{
1983 return NULL;
1984}
1985
1986static int
1987w83781d_alias_detect(struct i2c_client *client, u8 chipid)
1988{
1989 return 0;
1990}
1991
1992static int
1993w83781d_read_value(struct w83781d_data *data, u16 reg)
1994{
1995 int res;
1996
1997 mutex_lock(&data->lock);
1998 res = w83781d_read_value_i2c(data, reg);
1999 mutex_unlock(&data->lock);
2000
2001 return res;
2002}
2003
2004static int
2005w83781d_write_value(struct w83781d_data *data, u16 reg, u16 value)
2006{
2007 mutex_lock(&data->lock);
2008 w83781d_write_value_i2c(data, reg, value);
2009 mutex_unlock(&data->lock);
2010
2011 return 0;
2012}
2013
2014static int __init
2015w83781d_isa_register(void)
2016{
2017 return 0;
2018}
2019
2020static void __exit
2021w83781d_isa_unregister(void)
2022{
2023}
2024#endif /* CONFIG_ISA */
2025
2026static int __init
2027sensors_w83781d_init(void)
2028{
2029 int res;
2030
2031 /* We register the ISA device first, so that we can skip the
2032 * registration of an I2C interface to the same device. */
2033 res = w83781d_isa_register();
2034 if (res)
2035 goto exit;
2036
2037 res = i2c_add_driver(&w83781d_driver);
2038 if (res)
2039 goto exit_unreg_isa;
2040
2041 return 0;
2042
2043 exit_unreg_isa:
2044 w83781d_isa_unregister();
2045 exit:
2046 return res;
2047}
2048
2049static void __exit
2050sensors_w83781d_exit(void)
2051{
2052 w83781d_isa_unregister();
1967 i2c_del_driver(&w83781d_driver); 2053 i2c_del_driver(&w83781d_driver);
1968} 2054}
1969 2055
diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c
index de21142d106c..5768def8a4f2 100644
--- a/drivers/hwmon/w83791d.c
+++ b/drivers/hwmon/w83791d.c
@@ -23,7 +23,7 @@
23 Supports following chips: 23 Supports following chips:
24 24
25 Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA 25 Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA
26 w83791d 10 5 3 3 0x71 0x5ca3 yes no 26 w83791d 10 5 5 3 0x71 0x5ca3 yes no
27 27
28 The w83791d chip appears to be part way between the 83781d and the 28 The w83791d chip appears to be part way between the 83781d and the
29 83792d. Thus, this file is derived from both the w83792d.c and 29 83792d. Thus, this file is derived from both the w83792d.c and
@@ -45,6 +45,7 @@
45#define NUMBER_OF_VIN 10 45#define NUMBER_OF_VIN 10
46#define NUMBER_OF_FANIN 5 46#define NUMBER_OF_FANIN 5
47#define NUMBER_OF_TEMPIN 3 47#define NUMBER_OF_TEMPIN 3
48#define NUMBER_OF_PWM 5
48 49
49/* Addresses to scan */ 50/* Addresses to scan */
50static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, 51static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f,
@@ -116,6 +117,25 @@ static const u8 W83791D_REG_FAN_MIN[NUMBER_OF_FANIN] = {
116 0xBD, /* FAN 5 Count Low Limit in DataSheet */ 117 0xBD, /* FAN 5 Count Low Limit in DataSheet */
117}; 118};
118 119
120static const u8 W83791D_REG_PWM[NUMBER_OF_PWM] = {
121 0x81, /* PWM 1 duty cycle register in DataSheet */
122 0x83, /* PWM 2 duty cycle register in DataSheet */
123 0x94, /* PWM 3 duty cycle register in DataSheet */
124 0xA0, /* PWM 4 duty cycle register in DataSheet */
125 0xA1, /* PWM 5 duty cycle register in DataSheet */
126};
127
128static const u8 W83791D_REG_TEMP_TARGET[3] = {
129 0x85, /* PWM 1 target temperature for temp 1 */
130 0x86, /* PWM 2 target temperature for temp 2 */
131 0x96, /* PWM 3 target temperature for temp 3 */
132};
133
134static const u8 W83791D_REG_TEMP_TOL[2] = {
135 0x87, /* PWM 1/2 temperature tolerance */
136 0x97, /* PWM 3 temperature tolerance */
137};
138
119static const u8 W83791D_REG_FAN_CFG[2] = { 139static const u8 W83791D_REG_FAN_CFG[2] = {
120 0x84, /* FAN 1/2 configuration */ 140 0x84, /* FAN 1/2 configuration */
121 0x95, /* FAN 3 configuration */ 141 0x95, /* FAN 3 configuration */
@@ -160,6 +180,7 @@ static const u8 W83791D_REG_BEEP_CTRL[3] = {
160 0xA3, /* BEEP Control Register 3 */ 180 0xA3, /* BEEP Control Register 3 */
161}; 181};
162 182
183#define W83791D_REG_GPIO 0x15
163#define W83791D_REG_CONFIG 0x40 184#define W83791D_REG_CONFIG 0x40
164#define W83791D_REG_VID_FANDIV 0x47 185#define W83791D_REG_VID_FANDIV 0x47
165#define W83791D_REG_DID_VID4 0x49 186#define W83791D_REG_DID_VID4 0x49
@@ -224,6 +245,15 @@ static u8 fan_to_reg(long rpm, int div)
224 (val) < 0 ? ((val) - 250) / 500 * 128 : \ 245 (val) < 0 ? ((val) - 250) / 500 * 128 : \
225 ((val) + 250) / 500 * 128) 246 ((val) + 250) / 500 * 128)
226 247
248/* for thermal cruise target temp, 7-bits, LSB = 1 degree Celsius */
249#define TARGET_TEMP_TO_REG(val) ((val) < 0 ? 0 : \
250 (val) >= 127000 ? 127 : \
251 ((val) + 500) / 1000)
252
253/* for thermal cruise temp tolerance, 4-bits, LSB = 1 degree Celsius */
254#define TOL_TEMP_TO_REG(val) ((val) < 0 ? 0 : \
255 (val) >= 15000 ? 15 : \
256 ((val) + 500) / 1000)
227 257
228#define BEEP_MASK_TO_REG(val) ((val) & 0xffffff) 258#define BEEP_MASK_TO_REG(val) ((val) & 0xffffff)
229#define BEEP_MASK_FROM_REG(val) ((val) & 0xffffff) 259#define BEEP_MASK_FROM_REG(val) ((val) & 0xffffff)
@@ -275,6 +305,14 @@ struct w83791d_data {
275 two sensors with three values 305 two sensors with three values
276 (cur, over, hyst) */ 306 (cur, over, hyst) */
277 307
308 /* PWMs */
309 u8 pwm[5]; /* pwm duty cycle */
310 u8 pwm_enable[3]; /* pwm enable status for fan 1-3
311 (fan 4-5 only support manual mode) */
312
313 u8 temp_target[3]; /* pwm 1-3 target temperature */
314 u8 temp_tolerance[3]; /* pwm 1-3 temperature tolerance */
315
278 /* Misc */ 316 /* Misc */
279 u32 alarms; /* realtime status register encoding,combined */ 317 u32 alarms; /* realtime status register encoding,combined */
280 u8 beep_enable; /* Global beep enable */ 318 u8 beep_enable; /* Global beep enable */
@@ -652,6 +690,217 @@ static struct sensor_device_attribute sda_fan_alarm[] = {
652 SENSOR_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 22), 690 SENSOR_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 22),
653}; 691};
654 692
693/* read/write PWMs */
694static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
695 char *buf)
696{
697 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
698 int nr = sensor_attr->index;
699 struct w83791d_data *data = w83791d_update_device(dev);
700 return sprintf(buf, "%u\n", data->pwm[nr]);
701}
702
703static ssize_t store_pwm(struct device *dev, struct device_attribute *attr,
704 const char *buf, size_t count)
705{
706 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
707 struct i2c_client *client = to_i2c_client(dev);
708 struct w83791d_data *data = i2c_get_clientdata(client);
709 int nr = sensor_attr->index;
710 unsigned long val;
711
712 if (strict_strtoul(buf, 10, &val))
713 return -EINVAL;
714
715 mutex_lock(&data->update_lock);
716 data->pwm[nr] = SENSORS_LIMIT(val, 0, 255);
717 w83791d_write(client, W83791D_REG_PWM[nr], data->pwm[nr]);
718 mutex_unlock(&data->update_lock);
719 return count;
720}
721
722static struct sensor_device_attribute sda_pwm[] = {
723 SENSOR_ATTR(pwm1, S_IWUSR | S_IRUGO,
724 show_pwm, store_pwm, 0),
725 SENSOR_ATTR(pwm2, S_IWUSR | S_IRUGO,
726 show_pwm, store_pwm, 1),
727 SENSOR_ATTR(pwm3, S_IWUSR | S_IRUGO,
728 show_pwm, store_pwm, 2),
729 SENSOR_ATTR(pwm4, S_IWUSR | S_IRUGO,
730 show_pwm, store_pwm, 3),
731 SENSOR_ATTR(pwm5, S_IWUSR | S_IRUGO,
732 show_pwm, store_pwm, 4),
733};
734
735static ssize_t show_pwmenable(struct device *dev, struct device_attribute *attr,
736 char *buf)
737{
738 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
739 int nr = sensor_attr->index;
740 struct w83791d_data *data = w83791d_update_device(dev);
741 return sprintf(buf, "%u\n", data->pwm_enable[nr] + 1);
742}
743
744static ssize_t store_pwmenable(struct device *dev,
745 struct device_attribute *attr, const char *buf, size_t count)
746{
747 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
748 struct i2c_client *client = to_i2c_client(dev);
749 struct w83791d_data *data = i2c_get_clientdata(client);
750 int nr = sensor_attr->index;
751 unsigned long val;
752 u8 reg_cfg_tmp;
753 u8 reg_idx = 0;
754 u8 val_shift = 0;
755 u8 keep_mask = 0;
756
757 int ret = strict_strtoul(buf, 10, &val);
758
759 if (ret || val < 1 || val > 3)
760 return -EINVAL;
761
762 mutex_lock(&data->update_lock);
763 data->pwm_enable[nr] = val - 1;
764 switch (nr) {
765 case 0:
766 reg_idx = 0;
767 val_shift = 2;
768 keep_mask = 0xf3;
769 break;
770 case 1:
771 reg_idx = 0;
772 val_shift = 4;
773 keep_mask = 0xcf;
774 break;
775 case 2:
776 reg_idx = 1;
777 val_shift = 2;
778 keep_mask = 0xf3;
779 break;
780 }
781
782 reg_cfg_tmp = w83791d_read(client, W83791D_REG_FAN_CFG[reg_idx]);
783 reg_cfg_tmp = (reg_cfg_tmp & keep_mask) |
784 data->pwm_enable[nr] << val_shift;
785
786 w83791d_write(client, W83791D_REG_FAN_CFG[reg_idx], reg_cfg_tmp);
787 mutex_unlock(&data->update_lock);
788
789 return count;
790}
791static struct sensor_device_attribute sda_pwmenable[] = {
792 SENSOR_ATTR(pwm1_enable, S_IWUSR | S_IRUGO,
793 show_pwmenable, store_pwmenable, 0),
794 SENSOR_ATTR(pwm2_enable, S_IWUSR | S_IRUGO,
795 show_pwmenable, store_pwmenable, 1),
796 SENSOR_ATTR(pwm3_enable, S_IWUSR | S_IRUGO,
797 show_pwmenable, store_pwmenable, 2),
798};
799
800/* For Smart Fan I / Thermal Cruise */
801static ssize_t show_temp_target(struct device *dev,
802 struct device_attribute *attr, char *buf)
803{
804 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
805 struct w83791d_data *data = w83791d_update_device(dev);
806 int nr = sensor_attr->index;
807 return sprintf(buf, "%d\n", TEMP1_FROM_REG(data->temp_target[nr]));
808}
809
810static ssize_t store_temp_target(struct device *dev,
811 struct device_attribute *attr, const char *buf, size_t count)
812{
813 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
814 struct i2c_client *client = to_i2c_client(dev);
815 struct w83791d_data *data = i2c_get_clientdata(client);
816 int nr = sensor_attr->index;
817 unsigned long val;
818 u8 target_mask;
819
820 if (strict_strtoul(buf, 10, &val))
821 return -EINVAL;
822
823 mutex_lock(&data->update_lock);
824 data->temp_target[nr] = TARGET_TEMP_TO_REG(val);
825 target_mask = w83791d_read(client,
826 W83791D_REG_TEMP_TARGET[nr]) & 0x80;
827 w83791d_write(client, W83791D_REG_TEMP_TARGET[nr],
828 data->temp_target[nr] | target_mask);
829 mutex_unlock(&data->update_lock);
830 return count;
831}
832
833static struct sensor_device_attribute sda_temp_target[] = {
834 SENSOR_ATTR(temp1_target, S_IWUSR | S_IRUGO,
835 show_temp_target, store_temp_target, 0),
836 SENSOR_ATTR(temp2_target, S_IWUSR | S_IRUGO,
837 show_temp_target, store_temp_target, 1),
838 SENSOR_ATTR(temp3_target, S_IWUSR | S_IRUGO,
839 show_temp_target, store_temp_target, 2),
840};
841
842static ssize_t show_temp_tolerance(struct device *dev,
843 struct device_attribute *attr, char *buf)
844{
845 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
846 struct w83791d_data *data = w83791d_update_device(dev);
847 int nr = sensor_attr->index;
848 return sprintf(buf, "%d\n", TEMP1_FROM_REG(data->temp_tolerance[nr]));
849}
850
851static ssize_t store_temp_tolerance(struct device *dev,
852 struct device_attribute *attr, const char *buf, size_t count)
853{
854 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
855 struct i2c_client *client = to_i2c_client(dev);
856 struct w83791d_data *data = i2c_get_clientdata(client);
857 int nr = sensor_attr->index;
858 unsigned long val;
859 u8 target_mask;
860 u8 reg_idx = 0;
861 u8 val_shift = 0;
862 u8 keep_mask = 0;
863
864 if (strict_strtoul(buf, 10, &val))
865 return -EINVAL;
866
867 switch (nr) {
868 case 0:
869 reg_idx = 0;
870 val_shift = 0;
871 keep_mask = 0xf0;
872 break;
873 case 1:
874 reg_idx = 0;
875 val_shift = 4;
876 keep_mask = 0x0f;
877 break;
878 case 2:
879 reg_idx = 1;
880 val_shift = 0;
881 keep_mask = 0xf0;
882 break;
883 }
884
885 mutex_lock(&data->update_lock);
886 data->temp_tolerance[nr] = TOL_TEMP_TO_REG(val);
887 target_mask = w83791d_read(client,
888 W83791D_REG_TEMP_TOL[reg_idx]) & keep_mask;
889 w83791d_write(client, W83791D_REG_TEMP_TOL[reg_idx],
890 (data->temp_tolerance[nr] << val_shift) | target_mask);
891 mutex_unlock(&data->update_lock);
892 return count;
893}
894
895static struct sensor_device_attribute sda_temp_tolerance[] = {
896 SENSOR_ATTR(temp1_tolerance, S_IWUSR | S_IRUGO,
897 show_temp_tolerance, store_temp_tolerance, 0),
898 SENSOR_ATTR(temp2_tolerance, S_IWUSR | S_IRUGO,
899 show_temp_tolerance, store_temp_tolerance, 1),
900 SENSOR_ATTR(temp3_tolerance, S_IWUSR | S_IRUGO,
901 show_temp_tolerance, store_temp_tolerance, 2),
902};
903
655/* read/write the temperature1, includes measured value and limits */ 904/* read/write the temperature1, includes measured value and limits */
656static ssize_t show_temp1(struct device *dev, struct device_attribute *devattr, 905static ssize_t show_temp1(struct device *dev, struct device_attribute *devattr,
657 char *buf) 906 char *buf)
@@ -908,8 +1157,6 @@ static struct attribute *w83791d_attributes[] = {
908 FAN_UNIT_ATTRS(0), 1157 FAN_UNIT_ATTRS(0),
909 FAN_UNIT_ATTRS(1), 1158 FAN_UNIT_ATTRS(1),
910 FAN_UNIT_ATTRS(2), 1159 FAN_UNIT_ATTRS(2),
911 FAN_UNIT_ATTRS(3),
912 FAN_UNIT_ATTRS(4),
913 TEMP_UNIT_ATTRS(0), 1160 TEMP_UNIT_ATTRS(0),
914 TEMP_UNIT_ATTRS(1), 1161 TEMP_UNIT_ATTRS(1),
915 TEMP_UNIT_ATTRS(2), 1162 TEMP_UNIT_ATTRS(2),
@@ -918,6 +1165,18 @@ static struct attribute *w83791d_attributes[] = {
918 &sda_beep_ctrl[1].dev_attr.attr, 1165 &sda_beep_ctrl[1].dev_attr.attr,
919 &dev_attr_cpu0_vid.attr, 1166 &dev_attr_cpu0_vid.attr,
920 &dev_attr_vrm.attr, 1167 &dev_attr_vrm.attr,
1168 &sda_pwm[0].dev_attr.attr,
1169 &sda_pwm[1].dev_attr.attr,
1170 &sda_pwm[2].dev_attr.attr,
1171 &sda_pwmenable[0].dev_attr.attr,
1172 &sda_pwmenable[1].dev_attr.attr,
1173 &sda_pwmenable[2].dev_attr.attr,
1174 &sda_temp_target[0].dev_attr.attr,
1175 &sda_temp_target[1].dev_attr.attr,
1176 &sda_temp_target[2].dev_attr.attr,
1177 &sda_temp_tolerance[0].dev_attr.attr,
1178 &sda_temp_tolerance[1].dev_attr.attr,
1179 &sda_temp_tolerance[2].dev_attr.attr,
921 NULL 1180 NULL
922}; 1181};
923 1182
@@ -925,6 +1184,20 @@ static const struct attribute_group w83791d_group = {
925 .attrs = w83791d_attributes, 1184 .attrs = w83791d_attributes,
926}; 1185};
927 1186
1187/* Separate group of attributes for fan/pwm 4-5. Their pins can also be
1188 in use for GPIO in which case their sysfs-interface should not be made
1189 available */
1190static struct attribute *w83791d_attributes_fanpwm45[] = {
1191 FAN_UNIT_ATTRS(3),
1192 FAN_UNIT_ATTRS(4),
1193 &sda_pwm[3].dev_attr.attr,
1194 &sda_pwm[4].dev_attr.attr,
1195 NULL
1196};
1197
1198static const struct attribute_group w83791d_group_fanpwm45 = {
1199 .attrs = w83791d_attributes_fanpwm45,
1200};
928 1201
929static int w83791d_detect_subclients(struct i2c_client *client) 1202static int w83791d_detect_subclients(struct i2c_client *client)
930{ 1203{
@@ -1056,6 +1329,7 @@ static int w83791d_probe(struct i2c_client *client,
1056 struct w83791d_data *data; 1329 struct w83791d_data *data;
1057 struct device *dev = &client->dev; 1330 struct device *dev = &client->dev;
1058 int i, err; 1331 int i, err;
1332 u8 has_fanpwm45;
1059 1333
1060#ifdef DEBUG 1334#ifdef DEBUG
1061 int val1; 1335 int val1;
@@ -1090,15 +1364,27 @@ static int w83791d_probe(struct i2c_client *client,
1090 if ((err = sysfs_create_group(&client->dev.kobj, &w83791d_group))) 1364 if ((err = sysfs_create_group(&client->dev.kobj, &w83791d_group)))
1091 goto error3; 1365 goto error3;
1092 1366
1367 /* Check if pins of fan/pwm 4-5 are in use as GPIO */
1368 has_fanpwm45 = w83791d_read(client, W83791D_REG_GPIO) & 0x10;
1369 if (has_fanpwm45) {
1370 err = sysfs_create_group(&client->dev.kobj,
1371 &w83791d_group_fanpwm45);
1372 if (err)
1373 goto error4;
1374 }
1375
1093 /* Everything is ready, now register the working device */ 1376 /* Everything is ready, now register the working device */
1094 data->hwmon_dev = hwmon_device_register(dev); 1377 data->hwmon_dev = hwmon_device_register(dev);
1095 if (IS_ERR(data->hwmon_dev)) { 1378 if (IS_ERR(data->hwmon_dev)) {
1096 err = PTR_ERR(data->hwmon_dev); 1379 err = PTR_ERR(data->hwmon_dev);
1097 goto error4; 1380 goto error5;
1098 } 1381 }
1099 1382
1100 return 0; 1383 return 0;
1101 1384
1385error5:
1386 if (has_fanpwm45)
1387 sysfs_remove_group(&client->dev.kobj, &w83791d_group_fanpwm45);
1102error4: 1388error4:
1103 sysfs_remove_group(&client->dev.kobj, &w83791d_group); 1389 sysfs_remove_group(&client->dev.kobj, &w83791d_group);
1104error3: 1390error3:
@@ -1236,6 +1522,36 @@ static struct w83791d_data *w83791d_update_device(struct device *dev)
1236 for (i = 0; i < 3; i++) 1522 for (i = 0; i < 3; i++)
1237 data->fan_div[i] |= (vbat_reg >> (3 + i)) & 0x04; 1523 data->fan_div[i] |= (vbat_reg >> (3 + i)) & 0x04;
1238 1524
1525 /* Update PWM duty cycle */
1526 for (i = 0; i < NUMBER_OF_PWM; i++) {
1527 data->pwm[i] = w83791d_read(client,
1528 W83791D_REG_PWM[i]);
1529 }
1530
1531 /* Update PWM enable status */
1532 for (i = 0; i < 2; i++) {
1533 reg_array_tmp[i] = w83791d_read(client,
1534 W83791D_REG_FAN_CFG[i]);
1535 }
1536 data->pwm_enable[0] = (reg_array_tmp[0] >> 2) & 0x03;
1537 data->pwm_enable[1] = (reg_array_tmp[0] >> 4) & 0x03;
1538 data->pwm_enable[2] = (reg_array_tmp[1] >> 2) & 0x03;
1539
1540 /* Update PWM target temperature */
1541 for (i = 0; i < 3; i++) {
1542 data->temp_target[i] = w83791d_read(client,
1543 W83791D_REG_TEMP_TARGET[i]) & 0x7f;
1544 }
1545
1546 /* Update PWM temperature tolerance */
1547 for (i = 0; i < 2; i++) {
1548 reg_array_tmp[i] = w83791d_read(client,
1549 W83791D_REG_TEMP_TOL[i]);
1550 }
1551 data->temp_tolerance[0] = reg_array_tmp[0] & 0x0f;
1552 data->temp_tolerance[1] = (reg_array_tmp[0] >> 4) & 0x0f;
1553 data->temp_tolerance[2] = reg_array_tmp[1] & 0x0f;
1554
1239 /* Update the first temperature sensor */ 1555 /* Update the first temperature sensor */
1240 for (i = 0; i < 3; i++) { 1556 for (i = 0; i < 3; i++) {
1241 data->temp1[i] = w83791d_read(client, 1557 data->temp1[i] = w83791d_read(client,
diff --git a/drivers/i2c/busses/i2c-powermac.c b/drivers/i2c/busses/i2c-powermac.c
index 0e7b1c6724aa..60ca91745e55 100644
--- a/drivers/i2c/busses/i2c-powermac.c
+++ b/drivers/i2c/busses/i2c-powermac.c
@@ -259,6 +259,35 @@ static int __devinit i2c_powermac_probe(struct platform_device *dev)
259 } 259 }
260 260
261 printk(KERN_INFO "PowerMac i2c bus %s registered\n", name); 261 printk(KERN_INFO "PowerMac i2c bus %s registered\n", name);
262
263 if (!strncmp(basename, "uni-n", 5)) {
264 struct device_node *np;
265 const u32 *prop;
266 struct i2c_board_info info;
267
268 /* Instantiate I2C motion sensor if present */
269 np = of_find_node_by_name(NULL, "accelerometer");
270 if (np && of_device_is_compatible(np, "AAPL,accelerometer_1") &&
271 (prop = of_get_property(np, "reg", NULL))) {
272 int i2c_bus;
273 const char *tmp_bus;
274
275 /* look for bus either using "reg" or by path */
276 tmp_bus = strstr(np->full_name, "/i2c-bus@");
277 if (tmp_bus)
278 i2c_bus = *(tmp_bus + 9) - '0';
279 else
280 i2c_bus = ((*prop) >> 8) & 0x0f;
281
282 if (pmac_i2c_get_channel(bus) == i2c_bus) {
283 memset(&info, 0, sizeof(struct i2c_board_info));
284 info.addr = ((*prop) & 0xff) >> 1;
285 strlcpy(info.type, "ams", I2C_NAME_SIZE);
286 i2c_new_device(adapter, &info);
287 }
288 }
289 }
290
262 return rc; 291 return rc;
263} 292}
264 293