9 #include <linux/types.h>
10 #include <linux/errno.h>
11 #include <linux/kernel.h>
12 #include <linux/slab.h>
14 #include <linux/wait.h>
15 #include <linux/i2c.h>
28 #define DBG(args...) printk(args)
30 #define DBG(args...) do { } while(0)
34 #define MAX_AGE msecs_to_jiffies(800)
47 static struct wf_sat *sats[2];
58 #define wf_to_sat(c) container_of(c, struct wf_sat_sensor, sens)
71 if (sat_id > 1 || (sat = sats[sat_id]) ==
NULL)
97 for (i = 0; i < len; i += 4) {
111 for (i = 0; i < len; ++
i)
127 static int wf_sat_read_cache(
struct wf_sat *
sat)
139 for (i = 0; i < 16; ++
i)
159 err = wf_sat_read_cache(sat);
169 val = (val * ((sat->
cache[
i] << 8) + sat->
cache[i+1])) >> 4;
180 static void wf_sat_release(
struct kref *
ref)
189 static void wf_sat_sensor_release(
struct wf_sensor *sr)
195 kref_put(&sat->
ref, wf_sat_release);
199 .get_value = wf_sat_sensor_get,
200 .release = wf_sat_sensor_release,
216 int vsens[2], isens[2];
222 sat->
node = of_node_get(dev);
223 kref_init(&sat->
ref);
227 i2c_set_clientdata(client, sat);
229 vsens[0] = vsens[1] = -1;
230 isens[0] = isens[1] = -1;
245 if (
strncmp(loc,
"CPU ", 4) != 0)
249 if (chip > 1 || core > 1) {
251 "location %s for %s\n", loc, child->
full_name);
254 cpu = 2 * chip +
core;
257 else if (sat->
nr != chip) {
259 "multiple CPU chips on one SAT (%s)\n", loc);
263 if (
strcmp(type,
"voltage-sensor") == 0) {
264 name =
"cpu-voltage";
267 }
else if (
strcmp(type,
"current-sensor") == 0) {
268 name =
"cpu-current";
271 }
else if (
strcmp(type,
"temp-sensor") == 0) {
281 "%s sensor %d (no memory)\n", name, cpu);
288 sens->
sens.ops = &wf_sat_ops;
289 sens->
sens.name = (
char *) (sens + 1);
290 snprintf((
char *)sens->
sens.name, 16,
"%s-%d", name, cpu);
301 for (core = 0; core < 2; ++
core) {
302 if (vsens[core] < 0 || isens[core] < 0)
308 "sensor %d (no memory)\n", cpu);
315 sens->
sens.ops = &wf_sat_ops;
316 sens->
sens.name = (
char *) (sens + 1);
317 snprintf((
char *)sens->
sens.name, 16,
"cpu-power-%d", cpu);
333 static int wf_sat_remove(
struct i2c_client *client)
335 struct wf_sat *sat = i2c_get_clientdata(client);
339 while(!list_empty(&sat->
sensors)) {
346 i2c_set_clientdata(client,
NULL);
347 kref_put(&sat->
ref, wf_sat_release);
353 {
"MAC,smu-sat", 0 },
360 .name =
"wf_smu_sat",
362 .probe = wf_sat_probe,
363 .remove = wf_sat_remove,
364 .id_table = wf_sat_id,
367 static int __init sat_sensors_init(
void)
369 return i2c_add_driver(&wf_sat_driver);
372 static void __exit sat_sensors_exit(
void)