1 // SPDX-License-Identifier: GPL-2.0-only
3 * Windfarm PowerMac thermal control. MAX6690 sensor.
5 * Copyright (C) 2005 Paul Mackerras, IBM Corp. <paulus@samba.org>
7 #include <linux/types.h>
8 #include <linux/errno.h>
9 #include <linux/kernel.h>
10 #include <linux/init.h>
11 #include <linux/slab.h>
12 #include <linux/i2c.h>
14 #include <asm/pmac_low_i2c.h>
20 /* This currently only exports the external temperature sensor,
21 since that's all the control loops need. */
23 /* Some MAX6690 register numbers */
24 #define MAX6690_INTERNAL_TEMP 0
25 #define MAX6690_EXTERNAL_TEMP 1
27 struct wf_6690_sensor
{
28 struct i2c_client
*i2c
;
29 struct wf_sensor sens
;
32 #define wf_to_6690(x) container_of((x), struct wf_6690_sensor, sens)
34 static int wf_max6690_get(struct wf_sensor
*sr
, s32
*value
)
36 struct wf_6690_sensor
*max
= wf_to_6690(sr
);
42 /* chip gets initialized by firmware */
43 data
= i2c_smbus_read_byte_data(max
->i2c
, MAX6690_EXTERNAL_TEMP
);
50 static void wf_max6690_release(struct wf_sensor
*sr
)
52 struct wf_6690_sensor
*max
= wf_to_6690(sr
);
57 static const struct wf_sensor_ops wf_max6690_ops
= {
58 .get_value
= wf_max6690_get
,
59 .release
= wf_max6690_release
,
63 static int wf_max6690_probe(struct i2c_client
*client
)
65 const char *name
, *loc
;
66 struct wf_6690_sensor
*max
;
69 loc
= of_get_property(client
->dev
.of_node
, "hwsensor-location", NULL
);
71 dev_warn(&client
->dev
, "Missing hwsensor-location property!\n");
76 * We only expose the external temperature register for
77 * now as this is all we need for our control loops
79 if (!strcmp(loc
, "BACKSIDE") || !strcmp(loc
, "SYS CTRLR AMBIENT"))
80 name
= "backside-temp";
81 else if (!strcmp(loc
, "NB Ambient"))
82 name
= "north-bridge-temp";
83 else if (!strcmp(loc
, "GPU Ambient"))
88 max
= kzalloc(sizeof(struct wf_6690_sensor
), GFP_KERNEL
);
90 printk(KERN_ERR
"windfarm: Couldn't create MAX6690 sensor: "
96 max
->sens
.name
= name
;
97 max
->sens
.ops
= &wf_max6690_ops
;
98 i2c_set_clientdata(client
, max
);
100 rc
= wf_register_sensor(&max
->sens
);
106 static void wf_max6690_remove(struct i2c_client
*client
)
108 struct wf_6690_sensor
*max
= i2c_get_clientdata(client
);
111 wf_unregister_sensor(&max
->sens
);
114 static const struct i2c_device_id wf_max6690_id
[] = {
118 MODULE_DEVICE_TABLE(i2c
, wf_max6690_id
);
120 static const struct of_device_id wf_max6690_of_id
[] = {
121 { .compatible
= "max6690", },
124 MODULE_DEVICE_TABLE(of
, wf_max6690_of_id
);
126 static struct i2c_driver wf_max6690_driver
= {
128 .name
= "wf_max6690",
129 .of_match_table
= wf_max6690_of_id
,
131 .probe
= wf_max6690_probe
,
132 .remove
= wf_max6690_remove
,
133 .id_table
= wf_max6690_id
,
136 module_i2c_driver(wf_max6690_driver
);
138 MODULE_AUTHOR("Paul Mackerras <paulus@samba.org>");
139 MODULE_DESCRIPTION("MAX6690 sensor objects for PowerMac thermal control");
140 MODULE_LICENSE("GPL");