17
17
#include <linux/delay.h>
18
18
#include <linux/platform_device.h>
19
19
#include <linux/power_supply.h>
20
+ #include <linux/string_choices.h>
20
21
#include <linux/acpi.h>
21
22
#include <acpi/battery.h>
22
23
@@ -32,8 +33,9 @@ MODULE_AUTHOR("Paul Diefenbaugh");
32
33
MODULE_DESCRIPTION ("ACPI AC Adapter Driver" );
33
34
MODULE_LICENSE ("GPL" );
34
35
35
- static int acpi_ac_add (struct acpi_device * device );
36
- static void acpi_ac_remove (struct acpi_device * device );
36
+ static int acpi_ac_probe (struct platform_device * pdev );
37
+ static void acpi_ac_remove (struct platform_device * pdev );
38
+
37
39
static void acpi_ac_notify (acpi_handle handle , u32 event , void * data );
38
40
39
41
static const struct acpi_device_id ac_device_ids [] = {
@@ -50,17 +52,6 @@ static SIMPLE_DEV_PM_OPS(acpi_ac_pm, NULL, acpi_ac_resume);
50
52
static int ac_sleep_before_get_state_ms ;
51
53
static int ac_only ;
52
54
53
- static struct acpi_driver acpi_ac_driver = {
54
- .name = "ac" ,
55
- .class = ACPI_AC_CLASS ,
56
- .ids = ac_device_ids ,
57
- .ops = {
58
- .add = acpi_ac_add ,
59
- .remove = acpi_ac_remove ,
60
- },
61
- .drv .pm = & acpi_ac_pm ,
62
- };
63
-
64
55
struct acpi_ac {
65
56
struct power_supply * charger ;
66
57
struct power_supply_desc charger_desc ;
@@ -128,15 +119,12 @@ static enum power_supply_property ac_props[] = {
128
119
/* Driver Model */
129
120
static void acpi_ac_notify (acpi_handle handle , u32 event , void * data )
130
121
{
131
- struct acpi_device * device = data ;
132
- struct acpi_ac * ac = acpi_driver_data (device );
133
-
134
- if (!ac )
135
- return ;
122
+ struct acpi_ac * ac = data ;
123
+ struct acpi_device * adev = ac -> device ;
136
124
137
125
switch (event ) {
138
126
default :
139
- acpi_handle_debug (device -> handle , "Unsupported event [0x%x]\n" ,
127
+ acpi_handle_debug (adev -> handle , "Unsupported event [0x%x]\n" ,
140
128
event );
141
129
fallthrough ;
142
130
case ACPI_AC_NOTIFY_STATUS :
@@ -153,10 +141,10 @@ static void acpi_ac_notify(acpi_handle handle, u32 event, void *data)
153
141
msleep (ac_sleep_before_get_state_ms );
154
142
155
143
acpi_ac_get_state (ac );
156
- acpi_bus_generate_netlink_event (device -> pnp .device_class ,
157
- dev_name (& device -> dev ), event ,
144
+ acpi_bus_generate_netlink_event (adev -> pnp .device_class ,
145
+ dev_name (& adev -> dev ), event ,
158
146
(u32 ) ac -> state );
159
- acpi_notifier_call_chain (device , event , (u32 ) ac -> state );
147
+ acpi_notifier_call_chain (adev , event , (u32 ) ac -> state );
160
148
kobject_uevent (& ac -> charger -> dev .kobj , KOBJ_CHANGE );
161
149
}
162
150
}
@@ -213,51 +201,49 @@ static const struct dmi_system_id ac_dmi_table[] __initconst = {
213
201
{},
214
202
};
215
203
216
- static int acpi_ac_add (struct acpi_device * device )
204
+ static int acpi_ac_probe (struct platform_device * pdev )
217
205
{
206
+ struct acpi_device * adev = ACPI_COMPANION (& pdev -> dev );
218
207
struct power_supply_config psy_cfg = {};
219
- int result = 0 ;
220
- struct acpi_ac * ac = NULL ;
221
-
222
-
223
- if (!device )
224
- return - EINVAL ;
208
+ struct acpi_ac * ac ;
209
+ int result ;
225
210
226
211
ac = kzalloc (sizeof (struct acpi_ac ), GFP_KERNEL );
227
212
if (!ac )
228
213
return - ENOMEM ;
229
214
230
- ac -> device = device ;
231
- strcpy (acpi_device_name (device ), ACPI_AC_DEVICE_NAME );
232
- strcpy (acpi_device_class (device ), ACPI_AC_CLASS );
233
- device -> driver_data = ac ;
215
+ ac -> device = adev ;
216
+ strcpy (acpi_device_name (adev ), ACPI_AC_DEVICE_NAME );
217
+ strcpy (acpi_device_class (adev ), ACPI_AC_CLASS );
218
+
219
+ platform_set_drvdata (pdev , ac );
234
220
235
221
result = acpi_ac_get_state (ac );
236
222
if (result )
237
223
goto err_release_ac ;
238
224
239
225
psy_cfg .drv_data = ac ;
240
226
241
- ac -> charger_desc .name = acpi_device_bid (device );
227
+ ac -> charger_desc .name = acpi_device_bid (adev );
242
228
ac -> charger_desc .type = POWER_SUPPLY_TYPE_MAINS ;
243
229
ac -> charger_desc .properties = ac_props ;
244
230
ac -> charger_desc .num_properties = ARRAY_SIZE (ac_props );
245
231
ac -> charger_desc .get_property = get_ac_property ;
246
- ac -> charger = power_supply_register (& ac -> device -> dev ,
232
+ ac -> charger = power_supply_register (& pdev -> dev ,
247
233
& ac -> charger_desc , & psy_cfg );
248
234
if (IS_ERR (ac -> charger )) {
249
235
result = PTR_ERR (ac -> charger );
250
236
goto err_release_ac ;
251
237
}
252
238
253
- pr_info ("%s [%s] (%s)\n" , acpi_device_name (device ),
254
- acpi_device_bid (device ), ac -> state ? "on-line" : "off-line" );
239
+ pr_info ("%s [%s] (%s-line )\n" , acpi_device_name (adev ),
240
+ acpi_device_bid (adev ), str_on_off ( ac -> state ) );
255
241
256
242
ac -> battery_nb .notifier_call = acpi_ac_battery_notify ;
257
243
register_acpi_notifier (& ac -> battery_nb );
258
244
259
- result = acpi_dev_install_notify_handler (device , ACPI_ALL_NOTIFY ,
260
- acpi_ac_notify , device );
245
+ result = acpi_dev_install_notify_handler (adev , ACPI_ALL_NOTIFY ,
246
+ acpi_ac_notify , ac );
261
247
if (result )
262
248
goto err_unregister ;
263
249
@@ -275,16 +261,9 @@ static int acpi_ac_add(struct acpi_device *device)
275
261
#ifdef CONFIG_PM_SLEEP
276
262
static int acpi_ac_resume (struct device * dev )
277
263
{
278
- struct acpi_ac * ac ;
264
+ struct acpi_ac * ac = dev_get_drvdata ( dev ) ;
279
265
unsigned int old_state ;
280
266
281
- if (!dev )
282
- return - EINVAL ;
283
-
284
- ac = acpi_driver_data (to_acpi_device (dev ));
285
- if (!ac )
286
- return - EINVAL ;
287
-
288
267
old_state = ac -> state ;
289
268
if (acpi_ac_get_state (ac ))
290
269
return 0 ;
@@ -297,23 +276,28 @@ static int acpi_ac_resume(struct device *dev)
297
276
#define acpi_ac_resume NULL
298
277
#endif
299
278
300
- static void acpi_ac_remove (struct acpi_device * device )
279
+ static void acpi_ac_remove (struct platform_device * pdev )
301
280
{
302
- struct acpi_ac * ac = NULL ;
281
+ struct acpi_ac * ac = platform_get_drvdata ( pdev ) ;
303
282
304
- if (!device || !acpi_driver_data (device ))
305
- return ;
306
-
307
- ac = acpi_driver_data (device );
308
-
309
- acpi_dev_remove_notify_handler (device , ACPI_ALL_NOTIFY ,
283
+ acpi_dev_remove_notify_handler (ac -> device , ACPI_ALL_NOTIFY ,
310
284
acpi_ac_notify );
311
285
power_supply_unregister (ac -> charger );
312
286
unregister_acpi_notifier (& ac -> battery_nb );
313
287
314
288
kfree (ac );
315
289
}
316
290
291
+ static struct platform_driver acpi_ac_driver = {
292
+ .probe = acpi_ac_probe ,
293
+ .remove_new = acpi_ac_remove ,
294
+ .driver = {
295
+ .name = "ac" ,
296
+ .acpi_match_table = ac_device_ids ,
297
+ .pm = & acpi_ac_pm ,
298
+ },
299
+ };
300
+
317
301
static int __init acpi_ac_init (void )
318
302
{
319
303
int result ;
@@ -326,7 +310,7 @@ static int __init acpi_ac_init(void)
326
310
327
311
dmi_check_system (ac_dmi_table );
328
312
329
- result = acpi_bus_register_driver (& acpi_ac_driver );
313
+ result = platform_driver_register (& acpi_ac_driver );
330
314
if (result < 0 )
331
315
return - ENODEV ;
332
316
@@ -335,7 +319,7 @@ static int __init acpi_ac_init(void)
335
319
336
320
static void __exit acpi_ac_exit (void )
337
321
{
338
- acpi_bus_unregister_driver (& acpi_ac_driver );
322
+ platform_driver_unregister (& acpi_ac_driver );
339
323
}
340
324
module_init (acpi_ac_init );
341
325
module_exit (acpi_ac_exit );
0 commit comments