Loading...
1/*
2 * Windfarm PowerMac thermal control. MAX6690 sensor.
3 *
4 * Copyright (C) 2005 Paul Mackerras, IBM Corp. <paulus@samba.org>
5 *
6 * Use and redistribute under the terms of the GNU GPL v2.
7 */
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>
14#include <asm/prom.h>
15#include <asm/pmac_low_i2c.h>
16
17#include "windfarm.h"
18
19#define VERSION "1.0"
20
21/* This currently only exports the external temperature sensor,
22 since that's all the control loops need. */
23
24/* Some MAX6690 register numbers */
25#define MAX6690_INTERNAL_TEMP 0
26#define MAX6690_EXTERNAL_TEMP 1
27
28struct wf_6690_sensor {
29 struct i2c_client *i2c;
30 struct wf_sensor sens;
31};
32
33#define wf_to_6690(x) container_of((x), struct wf_6690_sensor, sens)
34
35static int wf_max6690_get(struct wf_sensor *sr, s32 *value)
36{
37 struct wf_6690_sensor *max = wf_to_6690(sr);
38 s32 data;
39
40 if (max->i2c == NULL)
41 return -ENODEV;
42
43 /* chip gets initialized by firmware */
44 data = i2c_smbus_read_byte_data(max->i2c, MAX6690_EXTERNAL_TEMP);
45 if (data < 0)
46 return data;
47 *value = data << 16;
48 return 0;
49}
50
51static void wf_max6690_release(struct wf_sensor *sr)
52{
53 struct wf_6690_sensor *max = wf_to_6690(sr);
54
55 kfree(max);
56}
57
58static struct wf_sensor_ops wf_max6690_ops = {
59 .get_value = wf_max6690_get,
60 .release = wf_max6690_release,
61 .owner = THIS_MODULE,
62};
63
64static int wf_max6690_probe(struct i2c_client *client,
65 const struct i2c_device_id *id)
66{
67 const char *name, *loc;
68 struct wf_6690_sensor *max;
69 int rc;
70
71 loc = of_get_property(client->dev.of_node, "hwsensor-location", NULL);
72 if (!loc) {
73 dev_warn(&client->dev, "Missing hwsensor-location property!\n");
74 return -ENXIO;
75 }
76
77 /*
78 * We only expose the external temperature register for
79 * now as this is all we need for our control loops
80 */
81 if (!strcmp(loc, "BACKSIDE") || !strcmp(loc, "SYS CTRLR AMBIENT"))
82 name = "backside-temp";
83 else if (!strcmp(loc, "NB Ambient"))
84 name = "north-bridge-temp";
85 else if (!strcmp(loc, "GPU Ambient"))
86 name = "gpu-temp";
87 else
88 return -ENXIO;
89
90 max = kzalloc(sizeof(struct wf_6690_sensor), GFP_KERNEL);
91 if (max == NULL) {
92 printk(KERN_ERR "windfarm: Couldn't create MAX6690 sensor: "
93 "no memory\n");
94 return -ENOMEM;
95 }
96
97 max->i2c = client;
98 max->sens.name = name;
99 max->sens.ops = &wf_max6690_ops;
100 i2c_set_clientdata(client, max);
101
102 rc = wf_register_sensor(&max->sens);
103 if (rc)
104 kfree(max);
105 return rc;
106}
107
108static int wf_max6690_remove(struct i2c_client *client)
109{
110 struct wf_6690_sensor *max = i2c_get_clientdata(client);
111
112 max->i2c = NULL;
113 wf_unregister_sensor(&max->sens);
114
115 return 0;
116}
117
118static const struct i2c_device_id wf_max6690_id[] = {
119 { "MAC,max6690", 0 },
120 { }
121};
122MODULE_DEVICE_TABLE(i2c, wf_max6690_id);
123
124static struct i2c_driver wf_max6690_driver = {
125 .driver = {
126 .name = "wf_max6690",
127 },
128 .probe = wf_max6690_probe,
129 .remove = wf_max6690_remove,
130 .id_table = wf_max6690_id,
131};
132
133module_i2c_driver(wf_max6690_driver);
134
135MODULE_AUTHOR("Paul Mackerras <paulus@samba.org>");
136MODULE_DESCRIPTION("MAX6690 sensor objects for PowerMac thermal control");
137MODULE_LICENSE("GPL");
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Windfarm PowerMac thermal control. MAX6690 sensor.
4 *
5 * Copyright (C) 2005 Paul Mackerras, IBM Corp. <paulus@samba.org>
6 */
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>
13
14#include <asm/pmac_low_i2c.h>
15
16#include "windfarm.h"
17
18#define VERSION "1.0"
19
20/* This currently only exports the external temperature sensor,
21 since that's all the control loops need. */
22
23/* Some MAX6690 register numbers */
24#define MAX6690_INTERNAL_TEMP 0
25#define MAX6690_EXTERNAL_TEMP 1
26
27struct wf_6690_sensor {
28 struct i2c_client *i2c;
29 struct wf_sensor sens;
30};
31
32#define wf_to_6690(x) container_of((x), struct wf_6690_sensor, sens)
33
34static int wf_max6690_get(struct wf_sensor *sr, s32 *value)
35{
36 struct wf_6690_sensor *max = wf_to_6690(sr);
37 s32 data;
38
39 if (max->i2c == NULL)
40 return -ENODEV;
41
42 /* chip gets initialized by firmware */
43 data = i2c_smbus_read_byte_data(max->i2c, MAX6690_EXTERNAL_TEMP);
44 if (data < 0)
45 return data;
46 *value = data << 16;
47 return 0;
48}
49
50static void wf_max6690_release(struct wf_sensor *sr)
51{
52 struct wf_6690_sensor *max = wf_to_6690(sr);
53
54 kfree(max);
55}
56
57static const struct wf_sensor_ops wf_max6690_ops = {
58 .get_value = wf_max6690_get,
59 .release = wf_max6690_release,
60 .owner = THIS_MODULE,
61};
62
63static int wf_max6690_probe(struct i2c_client *client)
64{
65 const char *name, *loc;
66 struct wf_6690_sensor *max;
67 int rc;
68
69 loc = of_get_property(client->dev.of_node, "hwsensor-location", NULL);
70 if (!loc) {
71 dev_warn(&client->dev, "Missing hwsensor-location property!\n");
72 return -ENXIO;
73 }
74
75 /*
76 * We only expose the external temperature register for
77 * now as this is all we need for our control loops
78 */
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"))
84 name = "gpu-temp";
85 else
86 return -ENXIO;
87
88 max = kzalloc(sizeof(struct wf_6690_sensor), GFP_KERNEL);
89 if (max == NULL) {
90 printk(KERN_ERR "windfarm: Couldn't create MAX6690 sensor: "
91 "no memory\n");
92 return -ENOMEM;
93 }
94
95 max->i2c = client;
96 max->sens.name = name;
97 max->sens.ops = &wf_max6690_ops;
98 i2c_set_clientdata(client, max);
99
100 rc = wf_register_sensor(&max->sens);
101 if (rc)
102 kfree(max);
103 return rc;
104}
105
106static void wf_max6690_remove(struct i2c_client *client)
107{
108 struct wf_6690_sensor *max = i2c_get_clientdata(client);
109
110 max->i2c = NULL;
111 wf_unregister_sensor(&max->sens);
112}
113
114static const struct i2c_device_id wf_max6690_id[] = {
115 { "MAC,max6690", 0 },
116 { }
117};
118MODULE_DEVICE_TABLE(i2c, wf_max6690_id);
119
120static const struct of_device_id wf_max6690_of_id[] = {
121 { .compatible = "max6690", },
122 { }
123};
124MODULE_DEVICE_TABLE(of, wf_max6690_of_id);
125
126static struct i2c_driver wf_max6690_driver = {
127 .driver = {
128 .name = "wf_max6690",
129 .of_match_table = wf_max6690_of_id,
130 },
131 .probe_new = wf_max6690_probe,
132 .remove = wf_max6690_remove,
133 .id_table = wf_max6690_id,
134};
135
136module_i2c_driver(wf_max6690_driver);
137
138MODULE_AUTHOR("Paul Mackerras <paulus@samba.org>");
139MODULE_DESCRIPTION("MAX6690 sensor objects for PowerMac thermal control");
140MODULE_LICENSE("GPL");