@@ -33,8 +33,9 @@ MODULE_AUTHOR("Paul Diefenbaugh");
3333MODULE_DESCRIPTION ("ACPI AC Adapter Driver" );
3434MODULE_LICENSE ("GPL" );
3535
36- static int acpi_ac_add (struct acpi_device * device );
37- 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+
3839static void acpi_ac_notify (acpi_handle handle , u32 event , void * data );
3940
4041static const struct acpi_device_id ac_device_ids [] = {
@@ -51,17 +52,6 @@ static SIMPLE_DEV_PM_OPS(acpi_ac_pm, NULL, acpi_ac_resume);
5152static int ac_sleep_before_get_state_ms ;
5253static int ac_only ;
5354
54- static struct acpi_driver acpi_ac_driver = {
55- .name = "ac" ,
56- .class = ACPI_AC_CLASS ,
57- .ids = ac_device_ids ,
58- .ops = {
59- .add = acpi_ac_add ,
60- .remove = acpi_ac_remove ,
61- },
62- .drv .pm = & acpi_ac_pm ,
63- };
64-
6555struct acpi_ac {
6656 struct power_supply * charger ;
6757 struct power_supply_desc charger_desc ;
@@ -129,12 +119,12 @@ static enum power_supply_property ac_props[] = {
129119/* Driver Model */
130120static void acpi_ac_notify (acpi_handle handle , u32 event , void * data )
131121{
132- struct acpi_device * device = data ;
133- struct acpi_ac * ac = acpi_driver_data ( device ) ;
122+ struct acpi_ac * ac = data ;
123+ struct acpi_device * adev = ac -> device ;
134124
135125 switch (event ) {
136126 default :
137- acpi_handle_debug (device -> handle , "Unsupported event [0x%x]\n" ,
127+ acpi_handle_debug (adev -> handle , "Unsupported event [0x%x]\n" ,
138128 event );
139129 fallthrough ;
140130 case ACPI_AC_NOTIFY_STATUS :
@@ -151,11 +141,11 @@ static void acpi_ac_notify(acpi_handle handle, u32 event, void *data)
151141 msleep (ac_sleep_before_get_state_ms );
152142
153143 acpi_ac_get_state (ac );
154- acpi_bus_generate_netlink_event (device -> pnp .device_class ,
155- dev_name (& device -> dev ), event ,
144+ acpi_bus_generate_netlink_event (adev -> pnp .device_class ,
145+ dev_name (& adev -> dev ), event ,
156146 (u32 ) ac -> state );
157- acpi_notifier_call_chain (device , event , (u32 ) ac -> state );
158- kobject_uevent ( & ac -> charger -> dev . kobj , KOBJ_CHANGE );
147+ acpi_notifier_call_chain (adev , event , (u32 ) ac -> state );
148+ power_supply_changed ( ac -> charger );
159149 }
160150}
161151
@@ -211,8 +201,9 @@ static const struct dmi_system_id ac_dmi_table[] __initconst = {
211201 {},
212202};
213203
214- static int acpi_ac_add (struct acpi_device * device )
204+ static int acpi_ac_probe (struct platform_device * pdev )
215205{
206+ struct acpi_device * adev = ACPI_COMPANION (& pdev -> dev );
216207 struct power_supply_config psy_cfg = {};
217208 struct acpi_ac * ac ;
218209 int result ;
@@ -221,37 +212,38 @@ static int acpi_ac_add(struct acpi_device *device)
221212 if (!ac )
222213 return - ENOMEM ;
223214
224- ac -> device = device ;
225- strcpy (acpi_device_name (device ), ACPI_AC_DEVICE_NAME );
226- strcpy (acpi_device_class (device ), ACPI_AC_CLASS );
227- 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 );
228220
229221 result = acpi_ac_get_state (ac );
230222 if (result )
231223 goto err_release_ac ;
232224
233225 psy_cfg .drv_data = ac ;
234226
235- ac -> charger_desc .name = acpi_device_bid (device );
227+ ac -> charger_desc .name = acpi_device_bid (adev );
236228 ac -> charger_desc .type = POWER_SUPPLY_TYPE_MAINS ;
237229 ac -> charger_desc .properties = ac_props ;
238230 ac -> charger_desc .num_properties = ARRAY_SIZE (ac_props );
239231 ac -> charger_desc .get_property = get_ac_property ;
240- ac -> charger = power_supply_register (& ac -> device -> dev ,
232+ ac -> charger = power_supply_register (& pdev -> dev ,
241233 & ac -> charger_desc , & psy_cfg );
242234 if (IS_ERR (ac -> charger )) {
243235 result = PTR_ERR (ac -> charger );
244236 goto err_release_ac ;
245237 }
246238
247- pr_info ("%s [%s] (%s-line)\n" , acpi_device_name (device ),
248- acpi_device_bid (device ), str_on_off (ac -> state ));
239+ pr_info ("%s [%s] (%s-line)\n" , acpi_device_name (adev ),
240+ acpi_device_bid (adev ), str_on_off (ac -> state ));
249241
250242 ac -> battery_nb .notifier_call = acpi_ac_battery_notify ;
251243 register_acpi_notifier (& ac -> battery_nb );
252244
253- result = acpi_dev_install_notify_handler (device , ACPI_ALL_NOTIFY ,
254- acpi_ac_notify , device );
245+ result = acpi_dev_install_notify_handler (adev , ACPI_ALL_NOTIFY ,
246+ acpi_ac_notify , ac );
255247 if (result )
256248 goto err_unregister ;
257249
@@ -269,33 +261,43 @@ static int acpi_ac_add(struct acpi_device *device)
269261#ifdef CONFIG_PM_SLEEP
270262static int acpi_ac_resume (struct device * dev )
271263{
272- struct acpi_ac * ac = acpi_driver_data ( to_acpi_device ( dev ) );
264+ struct acpi_ac * ac = dev_get_drvdata ( dev );
273265 unsigned int old_state ;
274266
275267 old_state = ac -> state ;
276268 if (acpi_ac_get_state (ac ))
277269 return 0 ;
278270 if (old_state != ac -> state )
279- kobject_uevent ( & ac -> charger -> dev . kobj , KOBJ_CHANGE );
271+ power_supply_changed ( ac -> charger );
280272
281273 return 0 ;
282274}
283275#else
284276#define acpi_ac_resume NULL
285277#endif
286278
287- static void acpi_ac_remove (struct acpi_device * device )
279+ static void acpi_ac_remove (struct platform_device * pdev )
288280{
289- struct acpi_ac * ac = acpi_driver_data ( device );
281+ struct acpi_ac * ac = platform_get_drvdata ( pdev );
290282
291- acpi_dev_remove_notify_handler (device , ACPI_ALL_NOTIFY ,
283+ acpi_dev_remove_notify_handler (ac -> device , ACPI_ALL_NOTIFY ,
292284 acpi_ac_notify );
293285 power_supply_unregister (ac -> charger );
294286 unregister_acpi_notifier (& ac -> battery_nb );
295287
296288 kfree (ac );
297289}
298290
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+
299301static int __init acpi_ac_init (void )
300302{
301303 int result ;
@@ -308,7 +310,7 @@ static int __init acpi_ac_init(void)
308310
309311 dmi_check_system (ac_dmi_table );
310312
311- result = acpi_bus_register_driver (& acpi_ac_driver );
313+ result = platform_driver_register (& acpi_ac_driver );
312314 if (result < 0 )
313315 return - ENODEV ;
314316
@@ -317,7 +319,7 @@ static int __init acpi_ac_init(void)
317319
318320static void __exit acpi_ac_exit (void )
319321{
320- acpi_bus_unregister_driver (& acpi_ac_driver );
322+ platform_driver_unregister (& acpi_ac_driver );
321323}
322324module_init (acpi_ac_init );
323325module_exit (acpi_ac_exit );
0 commit comments