diff options
author | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2012-04-18 18:16:45 -0400 |
---|---|---|
committer | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2012-04-30 01:37:18 -0400 |
commit | 22b6d2ea355449fc2a9a4dc5c346615af86b876e (patch) | |
tree | d622b6d8ce1323ac5e1c298070c312baccfd6a32 /drivers/macintosh | |
parent | 5400480f5411aab31939747371c6690a02ee7780 (diff) |
powerpc/pmac: Convert windfarm_max6690 to new i2c probing
This simplifies the driver to stop using the deprecated attach interface
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'drivers/macintosh')
-rw-r--r-- | drivers/macintosh/windfarm_max6690_sensor.c | 100 |
1 files changed, 21 insertions, 79 deletions
diff --git a/drivers/macintosh/windfarm_max6690_sensor.c b/drivers/macintosh/windfarm_max6690_sensor.c index 8204113268f4..f4902f4cf8cb 100644 --- a/drivers/macintosh/windfarm_max6690_sensor.c +++ b/drivers/macintosh/windfarm_max6690_sensor.c | |||
@@ -16,7 +16,7 @@ | |||
16 | 16 | ||
17 | #include "windfarm.h" | 17 | #include "windfarm.h" |
18 | 18 | ||
19 | #define VERSION "0.2" | 19 | #define VERSION "1.0" |
20 | 20 | ||
21 | /* This currently only exports the external temperature sensor, | 21 | /* This currently only exports the external temperature sensor, |
22 | since that's all the control loops need. */ | 22 | since that's all the control loops need. */ |
@@ -64,9 +64,25 @@ static struct wf_sensor_ops wf_max6690_ops = { | |||
64 | static int wf_max6690_probe(struct i2c_client *client, | 64 | static int wf_max6690_probe(struct i2c_client *client, |
65 | const struct i2c_device_id *id) | 65 | const struct i2c_device_id *id) |
66 | { | 66 | { |
67 | const char *name, *loc; | ||
67 | struct wf_6690_sensor *max; | 68 | struct wf_6690_sensor *max; |
68 | int rc; | 69 | int rc; |
69 | 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 | if (!strcmp(loc, "BACKSIDE")) | ||
78 | name = "backside-temp"; | ||
79 | else if (!strcmp(loc, "NB Ambient")) | ||
80 | name = "north-bridge-temp"; | ||
81 | else if (!strcmp(loc, "GPU Ambient")) | ||
82 | name = "gpu-temp"; | ||
83 | else | ||
84 | return -ENXIO; | ||
85 | |||
70 | max = kzalloc(sizeof(struct wf_6690_sensor), GFP_KERNEL); | 86 | max = kzalloc(sizeof(struct wf_6690_sensor), GFP_KERNEL); |
71 | if (max == NULL) { | 87 | if (max == NULL) { |
72 | printk(KERN_ERR "windfarm: Couldn't create MAX6690 sensor: " | 88 | printk(KERN_ERR "windfarm: Couldn't create MAX6690 sensor: " |
@@ -75,90 +91,16 @@ static int wf_max6690_probe(struct i2c_client *client, | |||
75 | } | 91 | } |
76 | 92 | ||
77 | max->i2c = client; | 93 | max->i2c = client; |
78 | max->sens.name = client->dev.platform_data; | 94 | max->sens.name = (char *)name; /* XXX fix constness in structure */ |
79 | max->sens.ops = &wf_max6690_ops; | 95 | max->sens.ops = &wf_max6690_ops; |
80 | i2c_set_clientdata(client, max); | 96 | i2c_set_clientdata(client, max); |
81 | 97 | ||
82 | rc = wf_register_sensor(&max->sens); | 98 | rc = wf_register_sensor(&max->sens); |
83 | if (rc) { | 99 | if (rc) |
84 | kfree(max); | 100 | kfree(max); |
85 | } | ||
86 | |||
87 | return rc; | 101 | return rc; |
88 | } | 102 | } |
89 | 103 | ||
90 | static struct i2c_driver wf_max6690_driver; | ||
91 | |||
92 | static struct i2c_client *wf_max6690_create(struct i2c_adapter *adapter, | ||
93 | u8 addr, const char *loc) | ||
94 | { | ||
95 | struct i2c_board_info info; | ||
96 | struct i2c_client *client; | ||
97 | char *name; | ||
98 | |||
99 | if (!strcmp(loc, "BACKSIDE")) | ||
100 | name = "backside-temp"; | ||
101 | else if (!strcmp(loc, "NB Ambient")) | ||
102 | name = "north-bridge-temp"; | ||
103 | else if (!strcmp(loc, "GPU Ambient")) | ||
104 | name = "gpu-temp"; | ||
105 | else | ||
106 | goto fail; | ||
107 | |||
108 | memset(&info, 0, sizeof(struct i2c_board_info)); | ||
109 | info.addr = addr >> 1; | ||
110 | info.platform_data = name; | ||
111 | strlcpy(info.type, "wf_max6690", I2C_NAME_SIZE); | ||
112 | |||
113 | client = i2c_new_device(adapter, &info); | ||
114 | if (client == NULL) { | ||
115 | printk(KERN_ERR "windfarm: failed to attach MAX6690 sensor\n"); | ||
116 | goto fail; | ||
117 | } | ||
118 | |||
119 | /* | ||
120 | * Let i2c-core delete that device on driver removal. | ||
121 | * This is safe because i2c-core holds the core_lock mutex for us. | ||
122 | */ | ||
123 | list_add_tail(&client->detected, &wf_max6690_driver.clients); | ||
124 | return client; | ||
125 | |||
126 | fail: | ||
127 | return NULL; | ||
128 | } | ||
129 | |||
130 | static int wf_max6690_attach(struct i2c_adapter *adapter) | ||
131 | { | ||
132 | struct device_node *busnode, *dev = NULL; | ||
133 | struct pmac_i2c_bus *bus; | ||
134 | const char *loc; | ||
135 | |||
136 | bus = pmac_i2c_adapter_to_bus(adapter); | ||
137 | if (bus == NULL) | ||
138 | return -ENODEV; | ||
139 | busnode = pmac_i2c_get_bus_node(bus); | ||
140 | |||
141 | while ((dev = of_get_next_child(busnode, dev)) != NULL) { | ||
142 | u8 addr; | ||
143 | |||
144 | /* We must re-match the adapter in order to properly check | ||
145 | * the channel on multibus setups | ||
146 | */ | ||
147 | if (!pmac_i2c_match_adapter(dev, adapter)) | ||
148 | continue; | ||
149 | if (!of_device_is_compatible(dev, "max6690")) | ||
150 | continue; | ||
151 | addr = pmac_i2c_get_dev_addr(dev); | ||
152 | loc = of_get_property(dev, "hwsensor-location", NULL); | ||
153 | if (loc == NULL || addr == 0) | ||
154 | continue; | ||
155 | printk("found max6690, loc=%s addr=0x%02x\n", loc, addr); | ||
156 | wf_max6690_create(adapter, addr, loc); | ||
157 | } | ||
158 | |||
159 | return 0; | ||
160 | } | ||
161 | |||
162 | static int wf_max6690_remove(struct i2c_client *client) | 104 | static int wf_max6690_remove(struct i2c_client *client) |
163 | { | 105 | { |
164 | struct wf_6690_sensor *max = i2c_get_clientdata(client); | 106 | struct wf_6690_sensor *max = i2c_get_clientdata(client); |
@@ -170,15 +112,15 @@ static int wf_max6690_remove(struct i2c_client *client) | |||
170 | } | 112 | } |
171 | 113 | ||
172 | static const struct i2c_device_id wf_max6690_id[] = { | 114 | static const struct i2c_device_id wf_max6690_id[] = { |
173 | { "wf_max6690", 0 }, | 115 | { "MAC,max6690", 0 }, |
174 | { } | 116 | { } |
175 | }; | 117 | }; |
118 | MODULE_DEVICE_TABLE(i2c, wf_max6690_id); | ||
176 | 119 | ||
177 | static struct i2c_driver wf_max6690_driver = { | 120 | static struct i2c_driver wf_max6690_driver = { |
178 | .driver = { | 121 | .driver = { |
179 | .name = "wf_max6690", | 122 | .name = "wf_max6690", |
180 | }, | 123 | }, |
181 | .attach_adapter = wf_max6690_attach, | ||
182 | .probe = wf_max6690_probe, | 124 | .probe = wf_max6690_probe, |
183 | .remove = wf_max6690_remove, | 125 | .remove = wf_max6690_remove, |
184 | .id_table = wf_max6690_id, | 126 | .id_table = wf_max6690_id, |