9 #include <linux/types.h>
10 #include <linux/errno.h>
11 #include <linux/kernel.h>
13 #include <linux/slab.h>
15 #include <linux/wait.h>
16 #include <linux/i2c.h>
18 #include <asm/machdep.h>
20 #include <asm/sections.h>
60 *value = ((
s32)raw) << 8;
76 #define ADC_12V_CURRENT_SCALE 0x0320
77 #define ADC_CPU_VOLTAGE_SCALE 0x00a0
78 #define ADC_CPU_CURRENT_SCALE 0x1f40
85 *value = (raw * (
s32)pv->
mpu->mdiode +
86 ((
s32)pv->
mpu->bdiode << 12)) >> 2;
100 static int wf_ad7417_adc_get(
struct wf_sensor *sr,
s32 *value)
110 for (i = 0; i < 10; i++) {
113 buf[1] = (pv->
config & 0x1f) | (chan << 5);
134 wf_ad7417_adc_convert(pv, chan, raw, value);
137 " raw value: 0x%x, conv to: 0x%08x\n",
138 chan, sr->
name, raw, *value);
145 "Error reading ADC, try %d...\n", i);
153 static void wf_ad7417_release(
struct kref *
ref)
160 static void wf_ad7417_sensor_release(
struct wf_sensor *sr)
165 kref_put(&pv->
ref, wf_ad7417_release);
169 .get_value = wf_ad7417_temp_get,
170 .release = wf_ad7417_sensor_release,
175 .get_value = wf_ad7417_adc_get,
176 .release = wf_ad7417_sensor_release,
217 dev_dbg(&pv->
i2c->dev,
"ADC config reg: %02x\n",
228 dev_err(&pv->
i2c->dev,
"Error reading ADC config\n");
243 dev_warn(&client->
dev,
"Missing hwsensor-location property!\n");
253 else if (!
strncmp(loc,
"CPU B", 5))
256 pr_err(
"wf_ad7417: Can't identify location %s\n", loc);
259 mpu = wf_get_mpu(cpu_nr);
261 dev_err(&client->
dev,
"Failed to retrieve MPU data\n");
277 wf_ad7417_init_chip(pv);
284 wf_ad7417_add_sensor(pv, 0,
"cpu-amb-temp", &wf_ad7417_temp_ops);
285 wf_ad7417_add_sensor(pv, 1,
"cpu-diode-temp", &wf_ad7417_adc_ops);
286 wf_ad7417_add_sensor(pv, 2,
"cpu-12v-current", &wf_ad7417_adc_ops);
287 wf_ad7417_add_sensor(pv, 3,
"cpu-voltage", &wf_ad7417_adc_ops);
288 wf_ad7417_add_sensor(pv, 4,
"cpu-current", &wf_ad7417_adc_ops);
302 for (i = 0; i < 5; i++)
305 kref_put(&pv->
ref, wf_ad7417_release);
320 .probe = wf_ad7417_probe,
321 .remove = wf_ad7417_remove,
322 .id_table = wf_ad7417_id,
325 static int __devinit wf_ad7417_init(
void)
333 return i2c_add_driver(&wf_ad7417_driver);
336 static void __devexit wf_ad7417_exit(
void)