diff options
author | David Woodhouse <David.Woodhouse@intel.com> | 2010-08-11 12:59:35 -0400 |
---|---|---|
committer | David Woodhouse <David.Woodhouse@intel.com> | 2010-08-11 13:00:43 -0400 |
commit | ce326329d72238196d61312d1cf1556ebaf94da7 (patch) | |
tree | bc8b7883ea8dbd490d7cb373425dc976a456144e /drivers/platform | |
parent | 58ac7aa0c308d8b7e38e92840de59da7a39834d8 (diff) |
ideapad: Stop using global variables
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Diffstat (limited to 'drivers/platform')
-rw-r--r-- | drivers/platform/x86/ideapad_acpi.c | 92 |
1 files changed, 58 insertions, 34 deletions
diff --git a/drivers/platform/x86/ideapad_acpi.c b/drivers/platform/x86/ideapad_acpi.c index ae744caf4726..8a89902e5d55 100644 --- a/drivers/platform/x86/ideapad_acpi.c +++ b/drivers/platform/x86/ideapad_acpi.c | |||
@@ -34,13 +34,19 @@ | |||
34 | #define IDEAPAD_DEV_3G 3 | 34 | #define IDEAPAD_DEV_3G 3 |
35 | #define IDEAPAD_DEV_KILLSW 4 | 35 | #define IDEAPAD_DEV_KILLSW 4 |
36 | 36 | ||
37 | static struct rfkill *ideapad_rfkill[5]; | 37 | struct ideapad_private { |
38 | 38 | struct rfkill *rfk[5]; | |
39 | static const char *ideapad_rfk_names[] = { | ||
40 | "ideapad_camera", "ideapad_wlan", "ideapad_bluetooth", "ideapad_3g", "ideapad_rfkill" | ||
41 | }; | 39 | }; |
42 | static const int ideapad_rfk_types[] = { | 40 | |
43 | 0, RFKILL_TYPE_WLAN, RFKILL_TYPE_BLUETOOTH, RFKILL_TYPE_WWAN, RFKILL_TYPE_WLAN | 41 | static struct { |
42 | char *name; | ||
43 | int type; | ||
44 | } ideapad_rfk_data[] = { | ||
45 | /* camera has no rfkill */ | ||
46 | { "ideapad_wlan", RFKILL_TYPE_WLAN }, | ||
47 | { "ideapad_bluetooth", RFKILL_TYPE_BLUETOOTH }, | ||
48 | { "ideapad_3g", RFKILL_TYPE_WWAN }, | ||
49 | { "ideapad_killsw", RFKILL_TYPE_WLAN } | ||
44 | }; | 50 | }; |
45 | 51 | ||
46 | static int ideapad_dev_exists(int device) | 52 | static int ideapad_dev_exists(int device) |
@@ -155,48 +161,52 @@ static struct rfkill_ops ideapad_rfk_ops = { | |||
155 | .set_block = ideapad_rfk_set, | 161 | .set_block = ideapad_rfk_set, |
156 | }; | 162 | }; |
157 | 163 | ||
158 | static void ideapad_sync_rfk_state(void) | 164 | static void ideapad_sync_rfk_state(struct acpi_device *adevice) |
159 | { | 165 | { |
166 | struct ideapad_private *priv = dev_get_drvdata(&adevice->dev); | ||
160 | int hw_blocked = !ideapad_dev_get_state(IDEAPAD_DEV_KILLSW); | 167 | int hw_blocked = !ideapad_dev_get_state(IDEAPAD_DEV_KILLSW); |
161 | int i; | 168 | int i; |
162 | 169 | ||
163 | rfkill_set_hw_state(ideapad_rfkill[IDEAPAD_DEV_KILLSW], hw_blocked); | 170 | rfkill_set_hw_state(priv->rfk[IDEAPAD_DEV_KILLSW], hw_blocked); |
164 | for (i = IDEAPAD_DEV_WLAN; i < IDEAPAD_DEV_KILLSW; i++) | 171 | for (i = IDEAPAD_DEV_WLAN; i < IDEAPAD_DEV_KILLSW; i++) |
165 | if (ideapad_rfkill[i]) | 172 | if (priv->rfk[i]) |
166 | rfkill_set_hw_state(ideapad_rfkill[i], hw_blocked); | 173 | rfkill_set_hw_state(priv->rfk[i], hw_blocked); |
167 | if (hw_blocked) | 174 | if (hw_blocked) |
168 | return; | 175 | return; |
169 | 176 | ||
170 | for (i = IDEAPAD_DEV_WLAN; i < IDEAPAD_DEV_KILLSW; i++) | 177 | for (i = IDEAPAD_DEV_WLAN; i < IDEAPAD_DEV_KILLSW; i++) |
171 | if (ideapad_rfkill[i]) | 178 | if (priv->rfk[i]) |
172 | rfkill_set_sw_state(ideapad_rfkill[i], !ideapad_dev_get_state(i)); | 179 | rfkill_set_sw_state(priv->rfk[i], !ideapad_dev_get_state(i)); |
173 | } | 180 | } |
174 | 181 | ||
175 | static int ideapad_register_rfkill(struct acpi_device *device, int dev) | 182 | static int ideapad_register_rfkill(struct acpi_device *adevice, int dev) |
176 | { | 183 | { |
184 | struct ideapad_private *priv = dev_get_drvdata(&adevice->dev); | ||
177 | int ret; | 185 | int ret; |
178 | 186 | ||
179 | ideapad_rfkill[dev] = rfkill_alloc(ideapad_rfk_names[dev], &device->dev, | 187 | priv->rfk[dev] = rfkill_alloc(ideapad_rfk_data[dev-1].name, &adevice->dev, |
180 | ideapad_rfk_types[dev], &ideapad_rfk_ops, | 188 | ideapad_rfk_data[dev-1].type, &ideapad_rfk_ops, |
181 | (void *)(long)dev); | 189 | (void *)(long)dev); |
182 | if (!ideapad_rfkill[dev]) | 190 | if (!priv->rfk[dev]) |
183 | return -ENOMEM; | 191 | return -ENOMEM; |
184 | 192 | ||
185 | ret = rfkill_register(ideapad_rfkill[dev]); | 193 | ret = rfkill_register(priv->rfk[dev]); |
186 | if (ret) { | 194 | if (ret) { |
187 | rfkill_destroy(ideapad_rfkill[dev]); | 195 | rfkill_destroy(priv->rfk[dev]); |
188 | return ret; | 196 | return ret; |
189 | } | 197 | } |
190 | return 0; | 198 | return 0; |
191 | } | 199 | } |
192 | 200 | ||
193 | static void ideapad_unregister_rfkill(int dev) | 201 | static void ideapad_unregister_rfkill(struct acpi_device *adevice, int dev) |
194 | { | 202 | { |
195 | if (!ideapad_rfkill[dev]) | 203 | struct ideapad_private *priv = dev_get_drvdata(&adevice->dev); |
204 | |||
205 | if (!priv->rfk[dev]) | ||
196 | return; | 206 | return; |
197 | 207 | ||
198 | rfkill_unregister(ideapad_rfkill[dev]); | 208 | rfkill_unregister(priv->rfk[dev]); |
199 | rfkill_destroy(ideapad_rfkill[dev]); | 209 | rfkill_destroy(priv->rfk[dev]); |
200 | } | 210 | } |
201 | 211 | ||
202 | static const struct acpi_device_id ideapad_device_ids[] = { | 212 | static const struct acpi_device_id ideapad_device_ids[] = { |
@@ -205,10 +215,11 @@ static const struct acpi_device_id ideapad_device_ids[] = { | |||
205 | }; | 215 | }; |
206 | MODULE_DEVICE_TABLE(acpi, ideapad_device_ids); | 216 | MODULE_DEVICE_TABLE(acpi, ideapad_device_ids); |
207 | 217 | ||
208 | static int ideapad_acpi_add(struct acpi_device *device) | 218 | static int ideapad_acpi_add(struct acpi_device *adevice) |
209 | { | 219 | { |
210 | int i; | 220 | int i; |
211 | int devs_present[5]; | 221 | int devs_present[5]; |
222 | struct ideapad_private *priv; | ||
212 | 223 | ||
213 | for (i = IDEAPAD_DEV_CAMERA; i < IDEAPAD_DEV_KILLSW; i++) { | 224 | for (i = IDEAPAD_DEV_CAMERA; i < IDEAPAD_DEV_KILLSW; i++) { |
214 | devs_present[i] = ideapad_dev_exists(i); | 225 | devs_present[i] = ideapad_dev_exists(i); |
@@ -219,34 +230,47 @@ static int ideapad_acpi_add(struct acpi_device *device) | |||
219 | /* The hardware switch is always present */ | 230 | /* The hardware switch is always present */ |
220 | devs_present[IDEAPAD_DEV_KILLSW] = 1; | 231 | devs_present[IDEAPAD_DEV_KILLSW] = 1; |
221 | 232 | ||
233 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); | ||
234 | if (!priv) | ||
235 | return -ENOMEM; | ||
236 | |||
222 | if (devs_present[IDEAPAD_DEV_CAMERA]) { | 237 | if (devs_present[IDEAPAD_DEV_CAMERA]) { |
223 | int ret = device_create_file(&device->dev, &dev_attr_camera_power); | 238 | int ret = device_create_file(&adevice->dev, &dev_attr_camera_power); |
224 | if (ret) | 239 | if (ret) { |
240 | kfree(priv); | ||
225 | return ret; | 241 | return ret; |
242 | } | ||
226 | } | 243 | } |
227 | 244 | ||
245 | dev_set_drvdata(&adevice->dev, priv); | ||
228 | for (i = IDEAPAD_DEV_WLAN; i <= IDEAPAD_DEV_KILLSW; i++) { | 246 | for (i = IDEAPAD_DEV_WLAN; i <= IDEAPAD_DEV_KILLSW; i++) { |
229 | if (!devs_present[i]) | 247 | if (!devs_present[i]) |
230 | continue; | 248 | continue; |
231 | 249 | ||
232 | ideapad_register_rfkill(device, i); | 250 | ideapad_register_rfkill(adevice, i); |
233 | } | 251 | } |
234 | ideapad_sync_rfk_state(); | 252 | ideapad_sync_rfk_state(adevice); |
235 | return 0; | 253 | return 0; |
236 | } | 254 | } |
237 | 255 | ||
238 | static int ideapad_acpi_remove(struct acpi_device *device, int type) | 256 | static int ideapad_acpi_remove(struct acpi_device *adevice, int type) |
239 | { | 257 | { |
258 | struct ideapad_private *priv = dev_get_drvdata(&adevice->dev); | ||
240 | int i; | 259 | int i; |
241 | device_remove_file(&device->dev, &dev_attr_camera_power); | 260 | |
242 | for (i = 0; i < 5; i++) | 261 | device_remove_file(&adevice->dev, &dev_attr_camera_power); |
243 | ideapad_unregister_rfkill(i); | 262 | |
263 | for (i = IDEAPAD_DEV_WLAN; i <= IDEAPAD_DEV_KILLSW; i++) | ||
264 | ideapad_unregister_rfkill(adevice, i); | ||
265 | |||
266 | dev_set_drvdata(&adevice->dev, NULL); | ||
267 | kfree(priv); | ||
244 | return 0; | 268 | return 0; |
245 | } | 269 | } |
246 | 270 | ||
247 | static void ideapad_acpi_notify(struct acpi_device *device, u32 event) | 271 | static void ideapad_acpi_notify(struct acpi_device *adevice, u32 event) |
248 | { | 272 | { |
249 | ideapad_sync_rfk_state(); | 273 | ideapad_sync_rfk_state(adevice); |
250 | } | 274 | } |
251 | 275 | ||
252 | static struct acpi_driver ideapad_acpi_driver = { | 276 | static struct acpi_driver ideapad_acpi_driver = { |