Lines Matching +full:ac +full:- +full:charger

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * acpi_ac.c - ACPI AC Adapter Driver (Revision: 27)
9 #define pr_fmt(fmt) "ACPI: AC: " fmt
25 #define ACPI_AC_DEVICE_NAME "AC Adapter"
33 MODULE_DESCRIPTION("ACPI AC Adapter Driver");
56 struct power_supply *charger; member
65 /* AC Adapter Management */
66 static int acpi_ac_get_state(struct acpi_ac *ac) in acpi_ac_get_state() argument
70 if (!ac) in acpi_ac_get_state()
71 return -EINVAL; in acpi_ac_get_state()
74 ac->state = 1; in acpi_ac_get_state()
78 status = acpi_evaluate_integer(ac->device->handle, "_PSR", NULL, in acpi_ac_get_state()
79 &ac->state); in acpi_ac_get_state()
81 acpi_handle_info(ac->device->handle, in acpi_ac_get_state()
82 "Error reading AC Adapter state: %s\n", in acpi_ac_get_state()
84 ac->state = ACPI_AC_STATUS_UNKNOWN; in acpi_ac_get_state()
85 return -ENODEV; in acpi_ac_get_state()
96 struct acpi_ac *ac = to_acpi_ac(psy); in get_ac_property() local
98 if (!ac) in get_ac_property()
99 return -ENODEV; in get_ac_property()
101 if (acpi_ac_get_state(ac)) in get_ac_property()
102 return -ENODEV; in get_ac_property()
106 val->intval = ac->state; in get_ac_property()
109 return -EINVAL; in get_ac_property()
122 struct acpi_ac *ac = data; in acpi_ac_notify() local
123 struct acpi_device *adev = ac->device; in acpi_ac_notify()
127 acpi_handle_debug(adev->handle, "Unsupported event [0x%x]\n", in acpi_ac_notify()
134 * A buggy BIOS may notify AC first and then sleep for in acpi_ac_notify()
136 * EC event handler (_Qxx). This will cause the AC state in acpi_ac_notify()
143 acpi_ac_get_state(ac); in acpi_ac_notify()
144 acpi_bus_generate_netlink_event(adev->pnp.device_class, in acpi_ac_notify()
145 dev_name(&adev->dev), event, in acpi_ac_notify()
146 (u32) ac->state); in acpi_ac_notify()
147 acpi_notifier_call_chain(adev, event, (u32) ac->state); in acpi_ac_notify()
148 power_supply_changed(ac->charger); in acpi_ac_notify()
155 struct acpi_ac *ac = container_of(nb, struct acpi_ac, battery_nb); in acpi_ac_battery_notify() local
159 * On HP Pavilion dv6-6179er AC status notifications aren't triggered in acpi_ac_battery_notify()
162 * discharging. Re-reading AC status triggers lost AC notifications, in acpi_ac_battery_notify()
163 * if AC status has changed. in acpi_ac_battery_notify()
165 if (strcmp(event->device_class, ACPI_BATTERY_CLASS) == 0 && in acpi_ac_battery_notify()
166 event->type == ACPI_BATTERY_NOTIFY_STATUS) in acpi_ac_battery_notify()
167 acpi_ac_get_state(ac); in acpi_ac_battery_notify()
206 struct acpi_device *adev = ACPI_COMPANION(&pdev->dev); in acpi_ac_probe()
208 struct acpi_ac *ac; in acpi_ac_probe() local
211 ac = kzalloc(sizeof(struct acpi_ac), GFP_KERNEL); in acpi_ac_probe()
212 if (!ac) in acpi_ac_probe()
213 return -ENOMEM; in acpi_ac_probe()
215 ac->device = adev; in acpi_ac_probe()
219 platform_set_drvdata(pdev, ac); in acpi_ac_probe()
221 result = acpi_ac_get_state(ac); in acpi_ac_probe()
225 psy_cfg.drv_data = ac; in acpi_ac_probe()
227 ac->charger_desc.name = acpi_device_bid(adev); in acpi_ac_probe()
228 ac->charger_desc.type = POWER_SUPPLY_TYPE_MAINS; in acpi_ac_probe()
229 ac->charger_desc.properties = ac_props; in acpi_ac_probe()
230 ac->charger_desc.num_properties = ARRAY_SIZE(ac_props); in acpi_ac_probe()
231 ac->charger_desc.get_property = get_ac_property; in acpi_ac_probe()
232 ac->charger = power_supply_register(&pdev->dev, in acpi_ac_probe()
233 &ac->charger_desc, &psy_cfg); in acpi_ac_probe()
234 if (IS_ERR(ac->charger)) { in acpi_ac_probe()
235 result = PTR_ERR(ac->charger); in acpi_ac_probe()
239 pr_info("%s [%s] (%s-line)\n", acpi_device_name(adev), in acpi_ac_probe()
240 acpi_device_bid(adev), str_on_off(ac->state)); in acpi_ac_probe()
242 ac->battery_nb.notifier_call = acpi_ac_battery_notify; in acpi_ac_probe()
243 register_acpi_notifier(&ac->battery_nb); in acpi_ac_probe()
246 acpi_ac_notify, ac); in acpi_ac_probe()
253 power_supply_unregister(ac->charger); in acpi_ac_probe()
254 unregister_acpi_notifier(&ac->battery_nb); in acpi_ac_probe()
256 kfree(ac); in acpi_ac_probe()
264 struct acpi_ac *ac = dev_get_drvdata(dev); in acpi_ac_resume() local
267 old_state = ac->state; in acpi_ac_resume()
268 if (acpi_ac_get_state(ac)) in acpi_ac_resume()
270 if (old_state != ac->state) in acpi_ac_resume()
271 power_supply_changed(ac->charger); in acpi_ac_resume()
281 struct acpi_ac *ac = platform_get_drvdata(pdev); in acpi_ac_remove() local
283 acpi_dev_remove_notify_handler(ac->device, ACPI_ALL_NOTIFY, in acpi_ac_remove()
285 power_supply_unregister(ac->charger); in acpi_ac_remove()
286 unregister_acpi_notifier(&ac->battery_nb); in acpi_ac_remove()
288 kfree(ac); in acpi_ac_remove()
295 .name = "ac",
306 return -ENODEV; in acpi_ac_init()
309 return -ENODEV; in acpi_ac_init()
315 return -ENODEV; in acpi_ac_init()