Blame view
drivers/macintosh/windfarm_max6690_sensor.c
4.73 KB
ac171c466 [PATCH] powerpc: ... |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
/* * Windfarm PowerMac thermal control. MAX6690 sensor. * * Copyright (C) 2005 Paul Mackerras, IBM Corp. <paulus@samba.org> * * Use and redistribute under the terms of the GNU GPL v2. */ #include <linux/types.h> #include <linux/errno.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/i2c.h> |
ac171c466 [PATCH] powerpc: ... |
14 15 16 17 |
#include <asm/prom.h> #include <asm/pmac_low_i2c.h> #include "windfarm.h" |
b55fafc5a [PATCH] powerpc: ... |
18 |
#define VERSION "0.2" |
ac171c466 [PATCH] powerpc: ... |
19 20 21 22 23 24 25 26 27 |
/* This currently only exports the external temperature sensor, since that's all the control loops need. */ /* Some MAX6690 register numbers */ #define MAX6690_INTERNAL_TEMP 0 #define MAX6690_EXTERNAL_TEMP 1 struct wf_6690_sensor { |
351ca3e31 windfarm: Convert... |
28 |
struct i2c_client *i2c; |
ac171c466 [PATCH] powerpc: ... |
29 30 31 32 |
struct wf_sensor sens; }; #define wf_to_6690(x) container_of((x), struct wf_6690_sensor, sens) |
ac171c466 [PATCH] powerpc: ... |
33 34 35 36 37 |
static int wf_max6690_get(struct wf_sensor *sr, s32 *value) { struct wf_6690_sensor *max = wf_to_6690(sr); s32 data; |
351ca3e31 windfarm: Convert... |
38 |
if (max->i2c == NULL) |
ac171c466 [PATCH] powerpc: ... |
39 40 41 |
return -ENODEV; /* chip gets initialized by firmware */ |
351ca3e31 windfarm: Convert... |
42 |
data = i2c_smbus_read_byte_data(max->i2c, MAX6690_EXTERNAL_TEMP); |
ac171c466 [PATCH] powerpc: ... |
43 44 45 46 47 48 49 50 51 |
if (data < 0) return data; *value = data << 16; return 0; } static void wf_max6690_release(struct wf_sensor *sr) { struct wf_6690_sensor *max = wf_to_6690(sr); |
ac171c466 [PATCH] powerpc: ... |
52 53 54 55 56 57 58 59 |
kfree(max); } static struct wf_sensor_ops wf_max6690_ops = { .get_value = wf_max6690_get, .release = wf_max6690_release, .owner = THIS_MODULE, }; |
351ca3e31 windfarm: Convert... |
60 61 |
static int wf_max6690_probe(struct i2c_client *client, const struct i2c_device_id *id) |
ac171c466 [PATCH] powerpc: ... |
62 63 |
{ struct wf_6690_sensor *max; |
351ca3e31 windfarm: Convert... |
64 |
int rc; |
ac171c466 [PATCH] powerpc: ... |
65 66 67 |
max = kzalloc(sizeof(struct wf_6690_sensor), GFP_KERNEL); if (max == NULL) { |
351ca3e31 windfarm: Convert... |
68 69 70 71 72 73 74 75 76 77 78 79 80 |
printk(KERN_ERR "windfarm: Couldn't create MAX6690 sensor: " "no memory "); return -ENOMEM; } max->i2c = client; max->sens.name = client->dev.platform_data; max->sens.ops = &wf_max6690_ops; i2c_set_clientdata(client, max); rc = wf_register_sensor(&max->sens); if (rc) { |
351ca3e31 windfarm: Convert... |
81 |
kfree(max); |
ac171c466 [PATCH] powerpc: ... |
82 |
} |
351ca3e31 windfarm: Convert... |
83 84 |
return rc; } |
6f6b35e13 macintosh: Don't ... |
85 |
static struct i2c_driver wf_max6690_driver; |
351ca3e31 windfarm: Convert... |
86 87 88 89 90 91 |
static struct i2c_client *wf_max6690_create(struct i2c_adapter *adapter, u8 addr, const char *loc) { struct i2c_board_info info; struct i2c_client *client; char *name; |
80ff974db [POWERPC] windfar... |
92 93 94 95 96 97 98 99 |
if (!strcmp(loc, "BACKSIDE")) name = "backside-temp"; else if (!strcmp(loc, "NB Ambient")) name = "north-bridge-temp"; else if (!strcmp(loc, "GPU Ambient")) name = "gpu-temp"; else goto fail; |
351ca3e31 windfarm: Convert... |
100 101 102 103 |
memset(&info, 0, sizeof(struct i2c_board_info)); info.addr = addr >> 1; info.platform_data = name; strlcpy(info.type, "wf_max6690", I2C_NAME_SIZE); |
ac171c466 [PATCH] powerpc: ... |
104 |
|
351ca3e31 windfarm: Convert... |
105 106 |
client = i2c_new_device(adapter, &info); if (client == NULL) { |
ac171c466 [PATCH] powerpc: ... |
107 108 109 110 |
printk(KERN_ERR "windfarm: failed to attach MAX6690 sensor "); goto fail; } |
351ca3e31 windfarm: Convert... |
111 112 113 114 |
/* * Let i2c-core delete that device on driver removal. * This is safe because i2c-core holds the core_lock mutex for us. */ |
6f6b35e13 macintosh: Don't ... |
115 |
list_add_tail(&client->detected, &wf_max6690_driver.clients); |
351ca3e31 windfarm: Convert... |
116 |
return client; |
ac171c466 [PATCH] powerpc: ... |
117 118 |
fail: |
351ca3e31 windfarm: Convert... |
119 |
return NULL; |
ac171c466 [PATCH] powerpc: ... |
120 121 122 123 124 125 126 |
} static int wf_max6690_attach(struct i2c_adapter *adapter) { struct device_node *busnode, *dev = NULL; struct pmac_i2c_bus *bus; const char *loc; |
ac171c466 [PATCH] powerpc: ... |
127 128 129 130 131 132 133 |
bus = pmac_i2c_adapter_to_bus(adapter); if (bus == NULL) return -ENODEV; busnode = pmac_i2c_get_bus_node(bus); while ((dev = of_get_next_child(busnode, dev)) != NULL) { |
b55fafc5a [PATCH] powerpc: ... |
134 135 136 137 138 139 140 |
u8 addr; /* We must re-match the adapter in order to properly check * the channel on multibus setups */ if (!pmac_i2c_match_adapter(dev, adapter)) continue; |
55b61fec2 [POWERPC] Rename ... |
141 |
if (!of_device_is_compatible(dev, "max6690")) |
ac171c466 [PATCH] powerpc: ... |
142 |
continue; |
b55fafc5a [PATCH] powerpc: ... |
143 |
addr = pmac_i2c_get_dev_addr(dev); |
01b2726dd [POWERPC] Rename ... |
144 |
loc = of_get_property(dev, "hwsensor-location", NULL); |
b55fafc5a [PATCH] powerpc: ... |
145 |
if (loc == NULL || addr == 0) |
ac171c466 [PATCH] powerpc: ... |
146 |
continue; |
b55fafc5a [PATCH] powerpc: ... |
147 148 |
printk("found max6690, loc=%s addr=0x%02x ", loc, addr); |
80ff974db [POWERPC] windfar... |
149 |
wf_max6690_create(adapter, addr, loc); |
ac171c466 [PATCH] powerpc: ... |
150 151 152 153 |
} return 0; } |
351ca3e31 windfarm: Convert... |
154 |
static int wf_max6690_remove(struct i2c_client *client) |
ac171c466 [PATCH] powerpc: ... |
155 |
{ |
351ca3e31 windfarm: Convert... |
156 |
struct wf_6690_sensor *max = i2c_get_clientdata(client); |
ac171c466 [PATCH] powerpc: ... |
157 |
|
351ca3e31 windfarm: Convert... |
158 |
max->i2c = NULL; |
ac171c466 [PATCH] powerpc: ... |
159 160 161 162 |
wf_unregister_sensor(&max->sens); return 0; } |
351ca3e31 windfarm: Convert... |
163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
static const struct i2c_device_id wf_max6690_id[] = { { "wf_max6690", 0 }, { } }; static struct i2c_driver wf_max6690_driver = { .driver = { .name = "wf_max6690", }, .attach_adapter = wf_max6690_attach, .probe = wf_max6690_probe, .remove = wf_max6690_remove, .id_table = wf_max6690_id, }; |
ac171c466 [PATCH] powerpc: ... |
177 178 |
static int __init wf_max6690_sensor_init(void) { |
b55fafc5a [PATCH] powerpc: ... |
179 |
/* Don't register on old machines that use therm_pm72 for now */ |
71a157e8e of: add 'of_' pre... |
180 181 182 |
if (of_machine_is_compatible("PowerMac7,2") || of_machine_is_compatible("PowerMac7,3") || of_machine_is_compatible("RackMac3,1")) |
b55fafc5a [PATCH] powerpc: ... |
183 |
return -ENODEV; |
ac171c466 [PATCH] powerpc: ... |
184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
return i2c_add_driver(&wf_max6690_driver); } static void __exit wf_max6690_sensor_exit(void) { i2c_del_driver(&wf_max6690_driver); } module_init(wf_max6690_sensor_init); module_exit(wf_max6690_sensor_exit); MODULE_AUTHOR("Paul Mackerras <paulus@samba.org>"); MODULE_DESCRIPTION("MAX6690 sensor objects for PowerMac thermal control"); MODULE_LICENSE("GPL"); |