blob: 36b24b0658cb789ba2471298bb16bb55352845a5 [file] [log] [blame]
Thomas Gleixner55716d22019-06-01 10:08:42 +02001// SPDX-License-Identifier: GPL-2.0-only
David Shaohua Li4e10d122005-03-18 18:45:35 -05002/*
3 * Link physical devices with ACPI devices support
4 *
5 * Copyright (c) 2005 David Shaohua Li <shaohua.li@intel.com>
6 * Copyright (c) 2005 Intel Corp.
David Shaohua Li4e10d122005-03-18 18:45:35 -05007 */
Hanjun Guod4f54a12017-03-07 20:40:06 +08008
9#include <linux/acpi_iort.h>
Paul Gortmaker214f2c92011-10-26 16:22:14 -040010#include <linux/export.h>
David Shaohua Li4e10d122005-03-18 18:45:35 -050011#include <linux/init.h>
12#include <linux/list.h>
13#include <linux/device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090014#include <linux/slab.h>
David Shaohua Li4e10d122005-03-18 18:45:35 -050015#include <linux/rwsem.h>
16#include <linux/acpi.h>
Suthikulpanit, Suraveed0562672015-06-10 11:08:52 -050017#include <linux/dma-mapping.h>
Hanjun Guod4f54a12017-03-07 20:40:06 +080018#include <linux/platform_device.h>
David Shaohua Li4e10d122005-03-18 18:45:35 -050019
Len Browna192a952009-07-28 16:45:54 -040020#include "internal.h"
21
David Shaohua Li4e10d122005-03-18 18:45:35 -050022#define ACPI_GLUE_DEBUG 0
23#if ACPI_GLUE_DEBUG
Joe Perches23415eb2012-12-18 06:31:30 +000024#define DBG(fmt, ...) \
25 printk(KERN_DEBUG PREFIX fmt, ##__VA_ARGS__)
David Shaohua Li4e10d122005-03-18 18:45:35 -050026#else
Joe Perches23415eb2012-12-18 06:31:30 +000027#define DBG(fmt, ...) \
28do { \
29 if (0) \
30 printk(KERN_DEBUG PREFIX fmt, ##__VA_ARGS__); \
31} while (0)
David Shaohua Li4e10d122005-03-18 18:45:35 -050032#endif
33static LIST_HEAD(bus_type_list);
34static DECLARE_RWSEM(bus_type_sem);
35
Lan Tianyu1033f902012-08-17 14:44:09 +080036#define PHYSICAL_NODE_STRING "physical_node"
Rafael J. Wysocki007ccfc2013-08-06 14:32:54 +020037#define PHYSICAL_NODE_NAME_SIZE (sizeof(PHYSICAL_NODE_STRING) + 10)
Lan Tianyu1033f902012-08-17 14:44:09 +080038
David Shaohua Li4e10d122005-03-18 18:45:35 -050039int register_acpi_bus_type(struct acpi_bus_type *type)
40{
41 if (acpi_disabled)
42 return -ENODEV;
Rafael J. Wysockie3f02c52013-11-29 16:27:34 +010043 if (type && type->match && type->find_companion) {
David Shaohua Li4e10d122005-03-18 18:45:35 -050044 down_write(&bus_type_sem);
45 list_add_tail(&type->list, &bus_type_list);
46 up_write(&bus_type_sem);
Rafael J. Wysocki53540092013-03-03 22:35:20 +010047 printk(KERN_INFO PREFIX "bus type %s registered\n", type->name);
David Shaohua Li4e10d122005-03-18 18:45:35 -050048 return 0;
49 }
50 return -ENODEV;
51}
Jeff Garzik91e4d5a2012-07-25 14:24:13 -040052EXPORT_SYMBOL_GPL(register_acpi_bus_type);
David Shaohua Li4e10d122005-03-18 18:45:35 -050053
David Shaohua Li4e10d122005-03-18 18:45:35 -050054int unregister_acpi_bus_type(struct acpi_bus_type *type)
55{
56 if (acpi_disabled)
57 return 0;
58 if (type) {
59 down_write(&bus_type_sem);
60 list_del_init(&type->list);
61 up_write(&bus_type_sem);
Rafael J. Wysocki53540092013-03-03 22:35:20 +010062 printk(KERN_INFO PREFIX "bus type %s unregistered\n",
63 type->name);
David Shaohua Li4e10d122005-03-18 18:45:35 -050064 return 0;
65 }
66 return -ENODEV;
67}
Jeff Garzik91e4d5a2012-07-25 14:24:13 -040068EXPORT_SYMBOL_GPL(unregister_acpi_bus_type);
David Shaohua Li4e10d122005-03-18 18:45:35 -050069
Rafael J. Wysocki53540092013-03-03 22:35:20 +010070static struct acpi_bus_type *acpi_get_bus_type(struct device *dev)
David Shaohua Li4e10d122005-03-18 18:45:35 -050071{
72 struct acpi_bus_type *tmp, *ret = NULL;
73
74 down_read(&bus_type_sem);
75 list_for_each_entry(tmp, &bus_type_list, list) {
Rafael J. Wysocki53540092013-03-03 22:35:20 +010076 if (tmp->match(dev)) {
David Shaohua Li4e10d122005-03-18 18:45:35 -050077 ret = tmp;
78 break;
79 }
80 }
81 up_read(&bus_type_sem);
82 return ret;
83}
84
Rafael J. Wysocki11b88ee2013-09-09 23:07:47 +020085#define FIND_CHILD_MIN_SCORE 1
86#define FIND_CHILD_MAX_SCORE 2
87
Rafael J. Wysockid9fef0c2013-11-28 23:57:58 +010088static int find_child_checks(struct acpi_device *adev, bool check_children)
David Shaohua Li4e10d122005-03-18 18:45:35 -050089{
Rafael J. Wysocki11b88ee2013-09-09 23:07:47 +020090 bool sta_present = true;
Rafael J. Wysocki60f75b82013-08-07 22:55:00 +020091 unsigned long long sta;
92 acpi_status status;
David Shaohua Li4e10d122005-03-18 18:45:35 -050093
Rafael J. Wysockid9fef0c2013-11-28 23:57:58 +010094 status = acpi_evaluate_integer(adev->handle, "_STA", NULL, &sta);
Rafael J. Wysocki11b88ee2013-09-09 23:07:47 +020095 if (status == AE_NOT_FOUND)
96 sta_present = false;
97 else if (ACPI_FAILURE(status) || !(sta & ACPI_STA_DEVICE_ENABLED))
98 return -ENODEV;
David Shaohua Li4e10d122005-03-18 18:45:35 -050099
Rafael J. Wysockid9fef0c2013-11-28 23:57:58 +0100100 if (check_children && list_empty(&adev->children))
101 return -ENODEV;
Rafael J. Wysocki60f75b82013-08-07 22:55:00 +0200102
Rafael J. Wysockic2a6bba2016-12-30 02:27:31 +0100103 /*
Rafael J. Wysockifdad4e72017-04-01 00:45:52 +0200104 * If the device has a _HID returning a valid ACPI/PNP device ID, it is
105 * better to make it look less attractive here, so that the other device
106 * with the same _ADR value (that may not have a valid device ID) can be
107 * matched going forward. [This means a second spec violation in a row,
108 * so whatever we do here is best effort anyway.]
Rafael J. Wysockic2a6bba2016-12-30 02:27:31 +0100109 */
Rafael J. Wysockifdad4e72017-04-01 00:45:52 +0200110 return sta_present && !adev->pnp.type.platform_id ?
Rafael J. Wysockic2a6bba2016-12-30 02:27:31 +0100111 FIND_CHILD_MAX_SCORE : FIND_CHILD_MIN_SCORE;
Rafael J. Wysocki33f767d2013-01-10 13:13:49 +0100112}
Rafael J. Wysocki60f75b82013-08-07 22:55:00 +0200113
Rafael J. Wysockid9fef0c2013-11-28 23:57:58 +0100114struct acpi_device *acpi_find_child_device(struct acpi_device *parent,
115 u64 address, bool check_children)
Rafael J. Wysocki60f75b82013-08-07 22:55:00 +0200116{
Rafael J. Wysockid9fef0c2013-11-28 23:57:58 +0100117 struct acpi_device *adev, *ret = NULL;
118 int ret_score = 0;
Rafael J. Wysocki60f75b82013-08-07 22:55:00 +0200119
Rafael J. Wysocki5ce79d22013-11-28 23:58:08 +0100120 if (!parent)
121 return NULL;
122
Rafael J. Wysockid9fef0c2013-11-28 23:57:58 +0100123 list_for_each_entry(adev, &parent->children, node) {
124 unsigned long long addr;
125 acpi_status status;
126 int score;
Rafael J. Wysocki60f75b82013-08-07 22:55:00 +0200127
Rafael J. Wysockid9fef0c2013-11-28 23:57:58 +0100128 status = acpi_evaluate_integer(adev->handle, METHOD_NAME__ADR,
129 NULL, &addr);
130 if (ACPI_FAILURE(status) || addr != address)
131 continue;
132
133 if (!ret) {
134 /* This is the first matching object. Save it. */
135 ret = adev;
136 continue;
137 }
138 /*
139 * There is more than one matching device object with the same
140 * _ADR value. That really is unexpected, so we are kind of
141 * beyond the scope of the spec here. We have to choose which
142 * one to return, though.
143 *
144 * First, check if the previously found object is good enough
145 * and return it if so. Second, do the same for the object that
146 * we've just found.
147 */
148 if (!ret_score) {
149 ret_score = find_child_checks(ret, check_children);
150 if (ret_score == FIND_CHILD_MAX_SCORE)
151 return ret;
152 }
153 score = find_child_checks(adev, check_children);
154 if (score == FIND_CHILD_MAX_SCORE) {
155 return adev;
156 } else if (score > ret_score) {
157 ret = adev;
158 ret_score = score;
159 }
Rafael J. Wysocki60f75b82013-08-07 22:55:00 +0200160 }
Rafael J. Wysockid9fef0c2013-11-28 23:57:58 +0100161 return ret;
Rafael J. Wysocki60f75b82013-08-07 22:55:00 +0200162}
Rafael J. Wysocki9c5ad362013-11-28 23:58:28 +0100163EXPORT_SYMBOL_GPL(acpi_find_child_device);
Rafael J. Wysocki60f75b82013-08-07 22:55:00 +0200164
Rafael J. Wysockibdbdbf92013-08-07 01:19:23 +0200165static void acpi_physnode_link_name(char *buf, unsigned int node_id)
166{
167 if (node_id > 0)
168 snprintf(buf, PHYSICAL_NODE_NAME_SIZE,
169 PHYSICAL_NODE_STRING "%u", node_id);
170 else
171 strcpy(buf, PHYSICAL_NODE_STRING);
172}
173
Rafael J. Wysocki24dee1f2013-11-29 16:27:43 +0100174int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev)
David Shaohua Li4e10d122005-03-18 18:45:35 -0500175{
Rafael J. Wysockif3fd0c82012-11-21 00:21:39 +0100176 struct acpi_device_physical_node *physical_node, *pn;
Rafael J. Wysocki007ccfc2013-08-06 14:32:54 +0200177 char physical_node_name[PHYSICAL_NODE_NAME_SIZE];
178 struct list_head *physnode_list;
179 unsigned int node_id;
Lan Tianyu1033f902012-08-17 14:44:09 +0800180 int retval = -EINVAL;
David Shaohua Li4e10d122005-03-18 18:45:35 -0500181
Rafael J. Wysockica5b74d2015-03-16 23:49:08 +0100182 if (has_acpi_companion(dev)) {
Rafael J. Wysocki24dee1f2013-11-29 16:27:43 +0100183 if (acpi_dev) {
Rafael J. Wysocki7b199812013-11-11 22:41:56 +0100184 dev_warn(dev, "ACPI companion already set\n");
Rafael J. Wysockif3fd0c82012-11-21 00:21:39 +0100185 return -EINVAL;
186 } else {
Rafael J. Wysocki7b199812013-11-11 22:41:56 +0100187 acpi_dev = ACPI_COMPANION(dev);
Rafael J. Wysockif3fd0c82012-11-21 00:21:39 +0100188 }
David Shaohua Li4e10d122005-03-18 18:45:35 -0500189 }
Rafael J. Wysocki7b199812013-11-11 22:41:56 +0100190 if (!acpi_dev)
Rafael J. Wysockif3fd0c82012-11-21 00:21:39 +0100191 return -EINVAL;
Lan Tianyu1033f902012-08-17 14:44:09 +0800192
Rafael J. Wysockia104b4d2013-11-14 23:18:32 +0100193 get_device(&acpi_dev->dev);
David Shaohua Li4e10d122005-03-18 18:45:35 -0500194 get_device(dev);
Rafael J. Wysockif3fd0c82012-11-21 00:21:39 +0100195 physical_node = kzalloc(sizeof(*physical_node), GFP_KERNEL);
Lan Tianyu1033f902012-08-17 14:44:09 +0800196 if (!physical_node) {
197 retval = -ENOMEM;
198 goto err;
David Shaohua Li4e10d122005-03-18 18:45:35 -0500199 }
Lan Tianyu1033f902012-08-17 14:44:09 +0800200
201 mutex_lock(&acpi_dev->physical_node_lock);
Rafael J. Wysockif3fd0c82012-11-21 00:21:39 +0100202
Rafael J. Wysocki007ccfc2013-08-06 14:32:54 +0200203 /*
204 * Keep the list sorted by node_id so that the IDs of removed nodes can
205 * be recycled easily.
206 */
207 physnode_list = &acpi_dev->physical_node_list;
208 node_id = 0;
209 list_for_each_entry(pn, &acpi_dev->physical_node_list, node) {
210 /* Sanity check. */
Rafael J. Wysockif3fd0c82012-11-21 00:21:39 +0100211 if (pn->dev == dev) {
Rafael J. Wysocki3342c752013-08-08 16:19:10 +0200212 mutex_unlock(&acpi_dev->physical_node_lock);
Rafael J. Wysocki3fe444a2013-08-07 01:15:25 +0200213
Rafael J. Wysocki3342c752013-08-08 16:19:10 +0200214 dev_warn(dev, "Already associated with ACPI node\n");
215 kfree(physical_node);
Rafael J. Wysocki7b199812013-11-11 22:41:56 +0100216 if (ACPI_COMPANION(dev) != acpi_dev)
Rafael J. Wysocki3342c752013-08-08 16:19:10 +0200217 goto err;
218
219 put_device(dev);
Rafael J. Wysockia104b4d2013-11-14 23:18:32 +0100220 put_device(&acpi_dev->dev);
Rafael J. Wysocki3342c752013-08-08 16:19:10 +0200221 return 0;
Rafael J. Wysockif3fd0c82012-11-21 00:21:39 +0100222 }
Rafael J. Wysocki007ccfc2013-08-06 14:32:54 +0200223 if (pn->node_id == node_id) {
224 physnode_list = &pn->node;
225 node_id++;
226 }
Lan Tianyu1033f902012-08-17 14:44:09 +0800227 }
228
Rafael J. Wysocki007ccfc2013-08-06 14:32:54 +0200229 physical_node->node_id = node_id;
Lan Tianyu1033f902012-08-17 14:44:09 +0800230 physical_node->dev = dev;
Rafael J. Wysocki007ccfc2013-08-06 14:32:54 +0200231 list_add(&physical_node->node, physnode_list);
Lan Tianyu1033f902012-08-17 14:44:09 +0800232 acpi_dev->physical_node_count++;
Rafael J. Wysockif3fd0c82012-11-21 00:21:39 +0100233
Rafael J. Wysockica5b74d2015-03-16 23:49:08 +0100234 if (!has_acpi_companion(dev))
Rafael J. Wysocki7b199812013-11-11 22:41:56 +0100235 ACPI_COMPANION_SET(dev, acpi_dev);
David Shaohua Li4e10d122005-03-18 18:45:35 -0500236
Rafael J. Wysockibdbdbf92013-08-07 01:19:23 +0200237 acpi_physnode_link_name(physical_node_name, node_id);
Lan Tianyu1033f902012-08-17 14:44:09 +0800238 retval = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj,
Rafael J. Wysockif501b6e2013-08-07 01:19:52 +0200239 physical_node_name);
Rafael J. Wysocki464c1142013-08-08 16:19:19 +0200240 if (retval)
241 dev_err(&acpi_dev->dev, "Failed to create link %s (%d)\n",
242 physical_node_name, retval);
243
Lan Tianyu1033f902012-08-17 14:44:09 +0800244 retval = sysfs_create_link(&dev->kobj, &acpi_dev->dev.kobj,
Rafael J. Wysockif501b6e2013-08-07 01:19:52 +0200245 "firmware_node");
Rafael J. Wysocki464c1142013-08-08 16:19:19 +0200246 if (retval)
247 dev_err(dev, "Failed to create link firmware_node (%d)\n",
248 retval);
David Brownell10716952008-02-22 21:54:24 -0800249
Rafael J. Wysocki40055202013-08-07 01:19:37 +0200250 mutex_unlock(&acpi_dev->physical_node_lock);
251
Lan Tianyu1033f902012-08-17 14:44:09 +0800252 if (acpi_dev->wakeup.flags.valid)
253 device_set_wakeup_capable(dev, true);
David Brownell10716952008-02-22 21:54:24 -0800254
David Shaohua Li4e10d122005-03-18 18:45:35 -0500255 return 0;
Lan Tianyu1033f902012-08-17 14:44:09 +0800256
257 err:
Rafael J. Wysocki7b199812013-11-11 22:41:56 +0100258 ACPI_COMPANION_SET(dev, NULL);
Lan Tianyu1033f902012-08-17 14:44:09 +0800259 put_device(dev);
Rafael J. Wysockia104b4d2013-11-14 23:18:32 +0100260 put_device(&acpi_dev->dev);
Lan Tianyu1033f902012-08-17 14:44:09 +0800261 return retval;
David Shaohua Li4e10d122005-03-18 18:45:35 -0500262}
Rafael J. Wysockiac212b62013-05-03 00:26:22 +0200263EXPORT_SYMBOL_GPL(acpi_bind_one);
David Shaohua Li4e10d122005-03-18 18:45:35 -0500264
Rafael J. Wysockiac212b62013-05-03 00:26:22 +0200265int acpi_unbind_one(struct device *dev)
David Shaohua Li4e10d122005-03-18 18:45:35 -0500266{
Rafael J. Wysocki7b199812013-11-11 22:41:56 +0100267 struct acpi_device *acpi_dev = ACPI_COMPANION(dev);
Lan Tianyu1033f902012-08-17 14:44:09 +0800268 struct acpi_device_physical_node *entry;
Lan Tianyu1033f902012-08-17 14:44:09 +0800269
Rafael J. Wysocki7b199812013-11-11 22:41:56 +0100270 if (!acpi_dev)
David Shaohua Li4e10d122005-03-18 18:45:35 -0500271 return 0;
David Brownell10716952008-02-22 21:54:24 -0800272
Lan Tianyu1033f902012-08-17 14:44:09 +0800273 mutex_lock(&acpi_dev->physical_node_lock);
David Brownell10716952008-02-22 21:54:24 -0800274
Rafael J. Wysocki3e332782013-08-07 01:22:08 +0200275 list_for_each_entry(entry, &acpi_dev->physical_node_list, node)
276 if (entry->dev == dev) {
277 char physnode_name[PHYSICAL_NODE_NAME_SIZE];
Lan Tianyu1033f902012-08-17 14:44:09 +0800278
Rafael J. Wysocki3e332782013-08-07 01:22:08 +0200279 list_del(&entry->node);
280 acpi_dev->physical_node_count--;
Lan Tianyu1033f902012-08-17 14:44:09 +0800281
Rafael J. Wysocki3e332782013-08-07 01:22:08 +0200282 acpi_physnode_link_name(physnode_name, entry->node_id);
283 sysfs_remove_link(&acpi_dev->dev.kobj, physnode_name);
284 sysfs_remove_link(&dev->kobj, "firmware_node");
Rafael J. Wysocki7b199812013-11-11 22:41:56 +0100285 ACPI_COMPANION_SET(dev, NULL);
Rafael J. Wysockia104b4d2013-11-14 23:18:32 +0100286 /* Drop references taken by acpi_bind_one(). */
Rafael J. Wysocki3e332782013-08-07 01:22:08 +0200287 put_device(dev);
Rafael J. Wysockia104b4d2013-11-14 23:18:32 +0100288 put_device(&acpi_dev->dev);
Rafael J. Wysocki3e332782013-08-07 01:22:08 +0200289 kfree(entry);
290 break;
291 }
292
Lan Tianyu1033f902012-08-17 14:44:09 +0800293 mutex_unlock(&acpi_dev->physical_node_lock);
David Shaohua Li4e10d122005-03-18 18:45:35 -0500294 return 0;
295}
Rafael J. Wysockiac212b62013-05-03 00:26:22 +0200296EXPORT_SYMBOL_GPL(acpi_unbind_one);
David Shaohua Li4e10d122005-03-18 18:45:35 -0500297
Heikki Krogerus7847a142018-11-09 17:21:35 +0300298static int acpi_device_notify(struct device *dev)
David Shaohua Li4e10d122005-03-18 18:45:35 -0500299{
Rafael J. Wysocki53540092013-03-03 22:35:20 +0100300 struct acpi_bus_type *type = acpi_get_bus_type(dev);
Rafael J. Wysocki9cb32ac2014-02-11 00:35:46 +0100301 struct acpi_device *adev;
Rafael J. Wysocki11909ca2012-12-23 00:02:13 +0100302 int ret;
David Shaohua Li4e10d122005-03-18 18:45:35 -0500303
Rafael J. Wysockif3fd0c82012-11-21 00:21:39 +0100304 ret = acpi_bind_one(dev, NULL);
Rafael J. Wysocki92414482013-03-03 22:35:44 +0100305 if (ret && type) {
Rafael J. Wysockie3f02c52013-11-29 16:27:34 +0100306 struct acpi_device *adev;
307
308 adev = type->find_companion(dev);
309 if (!adev) {
Rafael J. Wysocki11909ca2012-12-23 00:02:13 +0100310 DBG("Unable to get handle for %s\n", dev_name(dev));
Rafael J. Wysockie3f02c52013-11-29 16:27:34 +0100311 ret = -ENODEV;
Rafael J. Wysocki11909ca2012-12-23 00:02:13 +0100312 goto out;
313 }
Rafael J. Wysocki24dee1f2013-11-29 16:27:43 +0100314 ret = acpi_bind_one(dev, adev);
Rafael J. Wysocki11909ca2012-12-23 00:02:13 +0100315 if (ret)
316 goto out;
David Shaohua Li4e10d122005-03-18 18:45:35 -0500317 }
Rafael J. Wysocki9cb32ac2014-02-11 00:35:46 +0100318 adev = ACPI_COMPANION(dev);
319 if (!adev)
320 goto out;
Rafael J. Wysocki11909ca2012-12-23 00:02:13 +0100321
Andy Shevchenko719cf712018-08-20 16:45:41 +0300322 if (dev_is_platform(dev))
Hanjun Guod4f54a12017-03-07 20:40:06 +0800323 acpi_configure_pmsi_domain(dev);
324
Rafael J. Wysocki11909ca2012-12-23 00:02:13 +0100325 if (type && type->setup)
326 type->setup(dev);
Rafael J. Wysocki9cb32ac2014-02-11 00:35:46 +0100327 else if (adev->handler && adev->handler->bind)
328 adev->handler->bind(dev);
David Shaohua Li4e10d122005-03-18 18:45:35 -0500329
Rafael J. Wysockif3fd0c82012-11-21 00:21:39 +0100330 out:
David Shaohua Li4e10d122005-03-18 18:45:35 -0500331#if ACPI_GLUE_DEBUG
332 if (!ret) {
333 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
334
Yinghai Lua412a112013-01-12 14:00:06 +0100335 acpi_get_name(ACPI_HANDLE(dev), ACPI_FULL_PATHNAME, &buffer);
Kay Sieversdb1461a2009-01-25 23:40:56 +0100336 DBG("Device %s -> %s\n", dev_name(dev), (char *)buffer.pointer);
Len Brown02438d82006-06-30 03:19:10 -0400337 kfree(buffer.pointer);
David Shaohua Li4e10d122005-03-18 18:45:35 -0500338 } else
Kay Sieversdb1461a2009-01-25 23:40:56 +0100339 DBG("Device %s -> No ACPI support\n", dev_name(dev));
David Shaohua Li4e10d122005-03-18 18:45:35 -0500340#endif
341
342 return ret;
343}
344
Heikki Krogerus7847a142018-11-09 17:21:35 +0300345static int acpi_device_notify_remove(struct device *dev)
David Shaohua Li4e10d122005-03-18 18:45:35 -0500346{
Rafael J. Wysocki9cb32ac2014-02-11 00:35:46 +0100347 struct acpi_device *adev = ACPI_COMPANION(dev);
Rafael J. Wysocki11909ca2012-12-23 00:02:13 +0100348 struct acpi_bus_type *type;
349
Rafael J. Wysocki9cb32ac2014-02-11 00:35:46 +0100350 if (!adev)
351 return 0;
352
Rafael J. Wysocki53540092013-03-03 22:35:20 +0100353 type = acpi_get_bus_type(dev);
Rafael J. Wysocki11909ca2012-12-23 00:02:13 +0100354 if (type && type->cleanup)
355 type->cleanup(dev);
Rafael J. Wysocki9cb32ac2014-02-11 00:35:46 +0100356 else if (adev->handler && adev->handler->unbind)
357 adev->handler->unbind(dev);
Rafael J. Wysocki11909ca2012-12-23 00:02:13 +0100358
David Shaohua Li4e10d122005-03-18 18:45:35 -0500359 acpi_unbind_one(dev);
360 return 0;
361}
362
Heikki Krogerus7847a142018-11-09 17:21:35 +0300363int acpi_platform_notify(struct device *dev, enum kobject_action action)
David Shaohua Li4e10d122005-03-18 18:45:35 -0500364{
Heikki Krogerus7847a142018-11-09 17:21:35 +0300365 switch (action) {
366 case KOBJ_ADD:
367 acpi_device_notify(dev);
368 break;
369 case KOBJ_REMOVE:
370 acpi_device_notify_remove(dev);
371 break;
372 default:
373 break;
David Shaohua Li4e10d122005-03-18 18:45:35 -0500374 }
Heikki Krogerus7847a142018-11-09 17:21:35 +0300375 return 0;
David Shaohua Li4e10d122005-03-18 18:45:35 -0500376}