aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/macintosh/windfarm_max6690_sensor.c
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2009-06-15 12:01:51 -0400
committerJean Delvare <khali@linux-fr.org>2009-06-15 12:01:51 -0400
commit351ca3e31197929535418f5affc761cd9fb07428 (patch)
treee8602108fa3402081f2fd4210dee62c141ed7fab /drivers/macintosh/windfarm_max6690_sensor.c
parent1b9f37d488f09342610b29ac1c8e734e540932ab (diff)
windfarm: Convert to new-style i2c drivers
The legacy i2c binding model is going away soon, so convert the macintosh windfarm drivers to the new model or they will break. Signed-off-by: Jean Delvare <khali@linux-fr.org> Tested-by: Johannes Berg <johannes@sipsolutions.net> Tested-by: Paul Mackerras <paulus@samba.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'drivers/macintosh/windfarm_max6690_sensor.c')
-rw-r--r--drivers/macintosh/windfarm_max6690_sensor.c103
1 files changed, 61 insertions, 42 deletions
diff --git a/drivers/macintosh/windfarm_max6690_sensor.c b/drivers/macintosh/windfarm_max6690_sensor.c
index e207a90d6b27..e2a55ecda2b2 100644
--- a/drivers/macintosh/windfarm_max6690_sensor.c
+++ b/drivers/macintosh/windfarm_max6690_sensor.c
@@ -26,34 +26,22 @@
26#define MAX6690_EXTERNAL_TEMP 1 26#define MAX6690_EXTERNAL_TEMP 1
27 27
28struct wf_6690_sensor { 28struct wf_6690_sensor {
29 struct i2c_client i2c; 29 struct i2c_client *i2c;
30 struct wf_sensor sens; 30 struct wf_sensor sens;
31}; 31};
32 32
33#define wf_to_6690(x) container_of((x), struct wf_6690_sensor, sens) 33#define wf_to_6690(x) container_of((x), struct wf_6690_sensor, sens)
34#define i2c_to_6690(x) container_of((x), struct wf_6690_sensor, i2c)
35
36static int wf_max6690_attach(struct i2c_adapter *adapter);
37static int wf_max6690_detach(struct i2c_client *client);
38
39static struct i2c_driver wf_max6690_driver = {
40 .driver = {
41 .name = "wf_max6690",
42 },
43 .attach_adapter = wf_max6690_attach,
44 .detach_client = wf_max6690_detach,
45};
46 34
47static int wf_max6690_get(struct wf_sensor *sr, s32 *value) 35static int wf_max6690_get(struct wf_sensor *sr, s32 *value)
48{ 36{
49 struct wf_6690_sensor *max = wf_to_6690(sr); 37 struct wf_6690_sensor *max = wf_to_6690(sr);
50 s32 data; 38 s32 data;
51 39
52 if (max->i2c.adapter == NULL) 40 if (max->i2c == NULL)
53 return -ENODEV; 41 return -ENODEV;
54 42
55 /* chip gets initialized by firmware */ 43 /* chip gets initialized by firmware */
56 data = i2c_smbus_read_byte_data(&max->i2c, MAX6690_EXTERNAL_TEMP); 44 data = i2c_smbus_read_byte_data(max->i2c, MAX6690_EXTERNAL_TEMP);
57 if (data < 0) 45 if (data < 0)
58 return data; 46 return data;
59 *value = data << 16; 47 *value = data << 16;
@@ -64,10 +52,6 @@ static void wf_max6690_release(struct wf_sensor *sr)
64{ 52{
65 struct wf_6690_sensor *max = wf_to_6690(sr); 53 struct wf_6690_sensor *max = wf_to_6690(sr);
66 54
67 if (max->i2c.adapter) {
68 i2c_detach_client(&max->i2c);
69 max->i2c.adapter = NULL;
70 }
71 kfree(max); 55 kfree(max);
72} 56}
73 57
@@ -77,19 +61,40 @@ static struct wf_sensor_ops wf_max6690_ops = {
77 .owner = THIS_MODULE, 61 .owner = THIS_MODULE,
78}; 62};
79 63
80static void wf_max6690_create(struct i2c_adapter *adapter, u8 addr, 64static int wf_max6690_probe(struct i2c_client *client,
81 const char *loc) 65 const struct i2c_device_id *id)
82{ 66{
83 struct wf_6690_sensor *max; 67 struct wf_6690_sensor *max;
84 char *name; 68 int rc;
85 69
86 max = kzalloc(sizeof(struct wf_6690_sensor), GFP_KERNEL); 70 max = kzalloc(sizeof(struct wf_6690_sensor), GFP_KERNEL);
87 if (max == NULL) { 71 if (max == NULL) {
88 printk(KERN_ERR "windfarm: Couldn't create MAX6690 sensor %s: " 72 printk(KERN_ERR "windfarm: Couldn't create MAX6690 sensor: "
89 "no memory\n", loc); 73 "no memory\n");
90 return; 74 return -ENOMEM;
75 }
76
77 max->i2c = client;
78 max->sens.name = client->dev.platform_data;
79 max->sens.ops = &wf_max6690_ops;
80 i2c_set_clientdata(client, max);
81
82 rc = wf_register_sensor(&max->sens);
83 if (rc) {
84 i2c_set_clientdata(client, NULL);
85 kfree(max);
91 } 86 }
92 87
88 return rc;
89}
90
91static struct i2c_client *wf_max6690_create(struct i2c_adapter *adapter,
92 u8 addr, const char *loc)
93{
94 struct i2c_board_info info;
95 struct i2c_client *client;
96 char *name;
97
93 if (!strcmp(loc, "BACKSIDE")) 98 if (!strcmp(loc, "BACKSIDE"))
94 name = "backside-temp"; 99 name = "backside-temp";
95 else if (!strcmp(loc, "NB Ambient")) 100 else if (!strcmp(loc, "NB Ambient"))
@@ -99,27 +104,26 @@ static void wf_max6690_create(struct i2c_adapter *adapter, u8 addr,
99 else 104 else
100 goto fail; 105 goto fail;
101 106
102 max->sens.ops = &wf_max6690_ops; 107 memset(&info, 0, sizeof(struct i2c_board_info));
103 max->sens.name = name; 108 info.addr = addr >> 1;
104 max->i2c.addr = addr >> 1; 109 info.platform_data = name;
105 max->i2c.adapter = adapter; 110 strlcpy(info.type, "wf_max6690", I2C_NAME_SIZE);
106 max->i2c.driver = &wf_max6690_driver;
107 strncpy(max->i2c.name, name, I2C_NAME_SIZE-1);
108 111
109 if (i2c_attach_client(&max->i2c)) { 112 client = i2c_new_device(adapter, &info);
113 if (client == NULL) {
110 printk(KERN_ERR "windfarm: failed to attach MAX6690 sensor\n"); 114 printk(KERN_ERR "windfarm: failed to attach MAX6690 sensor\n");
111 goto fail; 115 goto fail;
112 } 116 }
113 117
114 if (wf_register_sensor(&max->sens)) { 118 /*
115 i2c_detach_client(&max->i2c); 119 * Let i2c-core delete that device on driver removal.
116 goto fail; 120 * This is safe because i2c-core holds the core_lock mutex for us.
117 } 121 */
118 122 list_add_tail(&client->detected, &client->driver->clients);
119 return; 123 return client;
120 124
121 fail: 125 fail:
122 kfree(max); 126 return NULL;
123} 127}
124 128
125static int wf_max6690_attach(struct i2c_adapter *adapter) 129static int wf_max6690_attach(struct i2c_adapter *adapter)
@@ -154,16 +158,31 @@ static int wf_max6690_attach(struct i2c_adapter *adapter)
154 return 0; 158 return 0;
155} 159}
156 160
157static int wf_max6690_detach(struct i2c_client *client) 161static int wf_max6690_remove(struct i2c_client *client)
158{ 162{
159 struct wf_6690_sensor *max = i2c_to_6690(client); 163 struct wf_6690_sensor *max = i2c_get_clientdata(client);
160 164
161 max->i2c.adapter = NULL; 165 max->i2c = NULL;
162 wf_unregister_sensor(&max->sens); 166 wf_unregister_sensor(&max->sens);
163 167
164 return 0; 168 return 0;
165} 169}
166 170
171static const struct i2c_device_id wf_max6690_id[] = {
172 { "wf_max6690", 0 },
173 { }
174};
175
176static struct i2c_driver wf_max6690_driver = {
177 .driver = {
178 .name = "wf_max6690",
179 },
180 .attach_adapter = wf_max6690_attach,
181 .probe = wf_max6690_probe,
182 .remove = wf_max6690_remove,
183 .id_table = wf_max6690_id,
184};
185
167static int __init wf_max6690_sensor_init(void) 186static int __init wf_max6690_sensor_init(void)
168{ 187{
169 /* Don't register on old machines that use therm_pm72 for now */ 188 /* Don't register on old machines that use therm_pm72 for now */