2 * Windfarm PowerMac thermal control. MAX6690 sensor.
4 * Copyright (C) 2005 Paul Mackerras, IBM Corp. <paulus@samba.org>
6 * Use and redistribute under the terms of the GNU GPL v2.
8 #include <linux/types.h>
9 #include <linux/errno.h>
10 #include <linux/kernel.h>
11 #include <linux/init.h>
12 #include <linux/slab.h>
13 #include <linux/i2c.h>
15 #include <asm/pmac_low_i2c.h>
21 /* This currently only exports the external temperature sensor,
22 since that's all the control loops need. */
24 /* Some MAX6690 register numbers */
25 #define MAX6690_INTERNAL_TEMP 0
26 #define MAX6690_EXTERNAL_TEMP 1
28 struct wf_6690_sensor {
29 struct i2c_client *i2c;
30 struct wf_sensor sens;
33 #define wf_to_6690(x) container_of((x), struct wf_6690_sensor, sens)
35 static int wf_max6690_get(struct wf_sensor *sr, s32 *value)
37 struct wf_6690_sensor *max = wf_to_6690(sr);
43 /* chip gets initialized by firmware */
44 data = i2c_smbus_read_byte_data(max->i2c, MAX6690_EXTERNAL_TEMP);
51 static void wf_max6690_release(struct wf_sensor *sr)
53 struct wf_6690_sensor *max = wf_to_6690(sr);
58 static struct wf_sensor_ops wf_max6690_ops = {
59 .get_value = wf_max6690_get,
60 .release = wf_max6690_release,
64 static int wf_max6690_probe(struct i2c_client *client,
65 const struct i2c_device_id *id)
67 struct wf_6690_sensor *max;
70 max = kzalloc(sizeof(struct wf_6690_sensor), GFP_KERNEL);
72 printk(KERN_ERR "windfarm: Couldn't create MAX6690 sensor: "
78 max->sens.name = client->dev.platform_data;
79 max->sens.ops = &wf_max6690_ops;
80 i2c_set_clientdata(client, max);
82 rc = wf_register_sensor(&max->sens);
84 i2c_set_clientdata(client, NULL);
91 static struct i2c_client *wf_max6690_create(struct i2c_adapter *adapter,
92 u8 addr, const char *loc)
94 struct i2c_board_info info;
95 struct i2c_client *client;
98 if (!strcmp(loc, "BACKSIDE"))
99 name = "backside-temp";
100 else if (!strcmp(loc, "NB Ambient"))
101 name = "north-bridge-temp";
102 else if (!strcmp(loc, "GPU Ambient"))
107 memset(&info, 0, sizeof(struct i2c_board_info));
108 info.addr = addr >> 1;
109 info.platform_data = name;
110 strlcpy(info.type, "wf_max6690", I2C_NAME_SIZE);
112 client = i2c_new_device(adapter, &info);
113 if (client == NULL) {
114 printk(KERN_ERR "windfarm: failed to attach MAX6690 sensor\n");
119 * Let i2c-core delete that device on driver removal.
120 * This is safe because i2c-core holds the core_lock mutex for us.
122 list_add_tail(&client->detected, &client->driver->clients);
129 static int wf_max6690_attach(struct i2c_adapter *adapter)
131 struct device_node *busnode, *dev = NULL;
132 struct pmac_i2c_bus *bus;
135 bus = pmac_i2c_adapter_to_bus(adapter);
138 busnode = pmac_i2c_get_bus_node(bus);
140 while ((dev = of_get_next_child(busnode, dev)) != NULL) {
143 /* We must re-match the adapter in order to properly check
144 * the channel on multibus setups
146 if (!pmac_i2c_match_adapter(dev, adapter))
148 if (!of_device_is_compatible(dev, "max6690"))
150 addr = pmac_i2c_get_dev_addr(dev);
151 loc = of_get_property(dev, "hwsensor-location", NULL);
152 if (loc == NULL || addr == 0)
154 printk("found max6690, loc=%s addr=0x%02x\n", loc, addr);
155 wf_max6690_create(adapter, addr, loc);
161 static int wf_max6690_remove(struct i2c_client *client)
163 struct wf_6690_sensor *max = i2c_get_clientdata(client);
166 wf_unregister_sensor(&max->sens);
171 static const struct i2c_device_id wf_max6690_id[] = {
176 static struct i2c_driver wf_max6690_driver = {
178 .name = "wf_max6690",
180 .attach_adapter = wf_max6690_attach,
181 .probe = wf_max6690_probe,
182 .remove = wf_max6690_remove,
183 .id_table = wf_max6690_id,
186 static int __init wf_max6690_sensor_init(void)
188 /* Don't register on old machines that use therm_pm72 for now */
189 if (machine_is_compatible("PowerMac7,2") ||
190 machine_is_compatible("PowerMac7,3") ||
191 machine_is_compatible("RackMac3,1"))
193 return i2c_add_driver(&wf_max6690_driver);
196 static void __exit wf_max6690_sensor_exit(void)
198 i2c_del_driver(&wf_max6690_driver);
201 module_init(wf_max6690_sensor_init);
202 module_exit(wf_max6690_sensor_exit);
204 MODULE_AUTHOR("Paul Mackerras <paulus@samba.org>");
205 MODULE_DESCRIPTION("MAX6690 sensor objects for PowerMac thermal control");
206 MODULE_LICENSE("GPL");