1989d42e8SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
22a41e607SRussell King /*
32a41e607SRussell King * Componentized device handling.
42a41e607SRussell King */
52a41e607SRussell King #include <linux/component.h>
62a41e607SRussell King #include <linux/device.h>
72a41e607SRussell King #include <linux/list.h>
82a41e607SRussell King #include <linux/mutex.h>
92502960fSYong Wu #include <linux/of.h>
102a41e607SRussell King #include <linux/slab.h>
1159e73854SMaciej Purski #include <linux/debugfs.h>
122a41e607SRussell King
134d69c80eSDaniel Vetter /**
144d69c80eSDaniel Vetter * DOC: overview
154d69c80eSDaniel Vetter *
164d69c80eSDaniel Vetter * The component helper allows drivers to collect a pile of sub-devices,
174d69c80eSDaniel Vetter * including their bound drivers, into an aggregate driver. Various subsystems
184d69c80eSDaniel Vetter * already provide functions to get hold of such components, e.g.
194d69c80eSDaniel Vetter * of_clk_get_by_name(). The component helper can be used when such a
204d69c80eSDaniel Vetter * subsystem-specific way to find a device is not available: The component
214d69c80eSDaniel Vetter * helper fills the niche of aggregate drivers for specific hardware, where
224d69c80eSDaniel Vetter * further standardization into a subsystem would not be practical. The common
234d69c80eSDaniel Vetter * example is when a logical device (e.g. a DRM display driver) is spread around
24e4246b05SDaniel Vetter * the SoC on various components (scanout engines, blending blocks, transcoders
254d69c80eSDaniel Vetter * for various outputs and so on).
264d69c80eSDaniel Vetter *
274d69c80eSDaniel Vetter * The component helper also doesn't solve runtime dependencies, e.g. for system
284d69c80eSDaniel Vetter * suspend and resume operations. See also :ref:`device links<device_link>`.
294d69c80eSDaniel Vetter *
304d69c80eSDaniel Vetter * Components are registered using component_add() and unregistered with
314d69c80eSDaniel Vetter * component_del(), usually from the driver's probe and disconnect functions.
324d69c80eSDaniel Vetter *
334d69c80eSDaniel Vetter * Aggregate drivers first assemble a component match list of what they need
344d69c80eSDaniel Vetter * using component_match_add(). This is then registered as an aggregate driver
354d69c80eSDaniel Vetter * using component_master_add_with_match(), and unregistered using
364d69c80eSDaniel Vetter * component_master_del().
374d69c80eSDaniel Vetter */
384d69c80eSDaniel Vetter
39ffc30b74SRussell King struct component;
40ffc30b74SRussell King
41ce657b1cSRussell King struct component_match_array {
42ce657b1cSRussell King void *data;
43ce657b1cSRussell King int (*compare)(struct device *, void *);
443521ee99SDaniel Vetter int (*compare_typed)(struct device *, int, void *);
45ce657b1cSRussell King void (*release)(struct device *, void *);
46ce657b1cSRussell King struct component *component;
47ce657b1cSRussell King bool duplicate;
48ce657b1cSRussell King };
49ce657b1cSRussell King
506955b582SRussell King struct component_match {
516955b582SRussell King size_t alloc;
526955b582SRussell King size_t num;
53ce657b1cSRussell King struct component_match_array *compare;
546955b582SRussell King };
556955b582SRussell King
5613e906e5SStephen Boyd struct aggregate_device {
572a41e607SRussell King struct list_head node;
582a41e607SRussell King bool bound;
592a41e607SRussell King
602a41e607SRussell King const struct component_master_ops *ops;
61d52ff34eSStephen Boyd struct device *parent;
626955b582SRussell King struct component_match *match;
632a41e607SRussell King };
642a41e607SRussell King
652a41e607SRussell King struct component {
662a41e607SRussell King struct list_head node;
6713e906e5SStephen Boyd struct aggregate_device *adev;
682a41e607SRussell King bool bound;
692a41e607SRussell King
702a41e607SRussell King const struct component_ops *ops;
713521ee99SDaniel Vetter int subcomponent;
722a41e607SRussell King struct device *dev;
732a41e607SRussell King };
742a41e607SRussell King
752a41e607SRussell King static DEFINE_MUTEX(component_mutex);
762a41e607SRussell King static LIST_HEAD(component_list);
7713e906e5SStephen Boyd static LIST_HEAD(aggregate_devices);
782a41e607SRussell King
7959e73854SMaciej Purski #ifdef CONFIG_DEBUG_FS
8059e73854SMaciej Purski
8159e73854SMaciej Purski static struct dentry *component_debugfs_dir;
8259e73854SMaciej Purski
component_devices_show(struct seq_file * s,void * data)8359e73854SMaciej Purski static int component_devices_show(struct seq_file *s, void *data)
8459e73854SMaciej Purski {
8513e906e5SStephen Boyd struct aggregate_device *m = s->private;
8659e73854SMaciej Purski struct component_match *match = m->match;
8759e73854SMaciej Purski size_t i;
8859e73854SMaciej Purski
8959e73854SMaciej Purski mutex_lock(&component_mutex);
9013e906e5SStephen Boyd seq_printf(s, "%-50s %20s\n", "aggregate_device name", "status");
9159e73854SMaciej Purski seq_puts(s, "-----------------------------------------------------------------------\n");
9259e73854SMaciej Purski seq_printf(s, "%-50s %20s\n\n",
93d52ff34eSStephen Boyd dev_name(m->parent), m->bound ? "bound" : "not bound");
9459e73854SMaciej Purski
9559e73854SMaciej Purski seq_printf(s, "%-50s %20s\n", "device name", "status");
9659e73854SMaciej Purski seq_puts(s, "-----------------------------------------------------------------------\n");
9759e73854SMaciej Purski for (i = 0; i < match->num; i++) {
98ef9ffc1eSLubomir Rintel struct component *component = match->compare[i].component;
9959e73854SMaciej Purski
100ef9ffc1eSLubomir Rintel seq_printf(s, "%-50s %20s\n",
101ef9ffc1eSLubomir Rintel component ? dev_name(component->dev) : "(unknown)",
102ef9ffc1eSLubomir Rintel component ? (component->bound ? "bound" : "not bound") : "not registered");
10359e73854SMaciej Purski }
10459e73854SMaciej Purski mutex_unlock(&component_mutex);
10559e73854SMaciej Purski
10659e73854SMaciej Purski return 0;
10759e73854SMaciej Purski }
10859e73854SMaciej Purski
109c0b8a870SYangtao Li DEFINE_SHOW_ATTRIBUTE(component_devices);
11059e73854SMaciej Purski
component_debug_init(void)11159e73854SMaciej Purski static int __init component_debug_init(void)
11259e73854SMaciej Purski {
11359e73854SMaciej Purski component_debugfs_dir = debugfs_create_dir("device_component", NULL);
11459e73854SMaciej Purski
11559e73854SMaciej Purski return 0;
11659e73854SMaciej Purski }
11759e73854SMaciej Purski
11859e73854SMaciej Purski core_initcall(component_debug_init);
11959e73854SMaciej Purski
component_debugfs_add(struct aggregate_device * m)12013e906e5SStephen Boyd static void component_debugfs_add(struct aggregate_device *m)
12159e73854SMaciej Purski {
122d52ff34eSStephen Boyd debugfs_create_file(dev_name(m->parent), 0444, component_debugfs_dir, m,
123c654cea5SGreg Kroah-Hartman &component_devices_fops);
12459e73854SMaciej Purski }
12559e73854SMaciej Purski
component_debugfs_del(struct aggregate_device * m)12613e906e5SStephen Boyd static void component_debugfs_del(struct aggregate_device *m)
12759e73854SMaciej Purski {
1288deb87b1SGreg Kroah-Hartman debugfs_lookup_and_remove(dev_name(m->parent), component_debugfs_dir);
12959e73854SMaciej Purski }
13059e73854SMaciej Purski
13159e73854SMaciej Purski #else
13259e73854SMaciej Purski
component_debugfs_add(struct aggregate_device * m)13313e906e5SStephen Boyd static void component_debugfs_add(struct aggregate_device *m)
13459e73854SMaciej Purski { }
13559e73854SMaciej Purski
component_debugfs_del(struct aggregate_device * m)13613e906e5SStephen Boyd static void component_debugfs_del(struct aggregate_device *m)
13759e73854SMaciej Purski { }
13859e73854SMaciej Purski
13959e73854SMaciej Purski #endif
14059e73854SMaciej Purski
__aggregate_find(struct device * parent,const struct component_master_ops * ops)14113e906e5SStephen Boyd static struct aggregate_device *__aggregate_find(struct device *parent,
1422a41e607SRussell King const struct component_master_ops *ops)
1432a41e607SRussell King {
14413e906e5SStephen Boyd struct aggregate_device *m;
1452a41e607SRussell King
14613e906e5SStephen Boyd list_for_each_entry(m, &aggregate_devices, node)
147d52ff34eSStephen Boyd if (m->parent == parent && (!ops || m->ops == ops))
1482a41e607SRussell King return m;
1492a41e607SRussell King
1502a41e607SRussell King return NULL;
1512a41e607SRussell King }
1522a41e607SRussell King
find_component(struct aggregate_device * adev,struct component_match_array * mc)15313e906e5SStephen Boyd static struct component *find_component(struct aggregate_device *adev,
1543521ee99SDaniel Vetter struct component_match_array *mc)
1552a41e607SRussell King {
1562a41e607SRussell King struct component *c;
1572a41e607SRussell King
1582a41e607SRussell King list_for_each_entry(c, &component_list, node) {
15913e906e5SStephen Boyd if (c->adev && c->adev != adev)
1602a41e607SRussell King continue;
1612a41e607SRussell King
1623521ee99SDaniel Vetter if (mc->compare && mc->compare(c->dev, mc->data))
1633521ee99SDaniel Vetter return c;
1643521ee99SDaniel Vetter
1653521ee99SDaniel Vetter if (mc->compare_typed &&
1663521ee99SDaniel Vetter mc->compare_typed(c->dev, c->subcomponent, mc->data))
167ffc30b74SRussell King return c;
1682a41e607SRussell King }
1692a41e607SRussell King
170ffc30b74SRussell King return NULL;
1712a41e607SRussell King }
1722a41e607SRussell King
find_components(struct aggregate_device * adev)17313e906e5SStephen Boyd static int find_components(struct aggregate_device *adev)
1746955b582SRussell King {
17513e906e5SStephen Boyd struct component_match *match = adev->match;
1766955b582SRussell King size_t i;
1776955b582SRussell King int ret = 0;
1786955b582SRussell King
1796955b582SRussell King /*
1806955b582SRussell King * Scan the array of match functions and attach
18113e906e5SStephen Boyd * any components which are found to this adev.
1826955b582SRussell King */
1836955b582SRussell King for (i = 0; i < match->num; i++) {
184ce657b1cSRussell King struct component_match_array *mc = &match->compare[i];
185ffc30b74SRussell King struct component *c;
186ffc30b74SRussell King
18713e906e5SStephen Boyd dev_dbg(adev->parent, "Looking for component %zu\n", i);
188ffc30b74SRussell King
189ffc30b74SRussell King if (match->compare[i].component)
190ffc30b74SRussell King continue;
191ffc30b74SRussell King
19213e906e5SStephen Boyd c = find_component(adev, mc);
193ffc30b74SRussell King if (!c) {
194ffc30b74SRussell King ret = -ENXIO;
1956955b582SRussell King break;
1966955b582SRussell King }
197ffc30b74SRussell King
19813e906e5SStephen Boyd dev_dbg(adev->parent, "found component %s, duplicate %u\n",
19913e906e5SStephen Boyd dev_name(c->dev), !!c->adev);
200ffc30b74SRussell King
20113e906e5SStephen Boyd /* Attach this component to the adev */
20213e906e5SStephen Boyd match->compare[i].duplicate = !!c->adev;
203ffc30b74SRussell King match->compare[i].component = c;
20413e906e5SStephen Boyd c->adev = adev;
205ffc30b74SRussell King }
2066955b582SRussell King return ret;
2076955b582SRussell King }
2086955b582SRussell King
20913e906e5SStephen Boyd /* Detach component from associated aggregate_device */
remove_component(struct aggregate_device * adev,struct component * c)21013e906e5SStephen Boyd static void remove_component(struct aggregate_device *adev, struct component *c)
2112a41e607SRussell King {
212ffc30b74SRussell King size_t i;
2132a41e607SRussell King
21413e906e5SStephen Boyd /* Detach the component from this adev. */
21513e906e5SStephen Boyd for (i = 0; i < adev->match->num; i++)
21613e906e5SStephen Boyd if (adev->match->compare[i].component == c)
21713e906e5SStephen Boyd adev->match->compare[i].component = NULL;
2182a41e607SRussell King }
2192a41e607SRussell King
2202a41e607SRussell King /*
22113e906e5SStephen Boyd * Try to bring up an aggregate device. If component is NULL, we're interested
22213e906e5SStephen Boyd * in this aggregate device, otherwise it's a component which must be present
22313e906e5SStephen Boyd * to try and bring up the aggregate device.
2242a41e607SRussell King *
2252a41e607SRussell King * Returns 1 for successful bringup, 0 if not ready, or -ve errno.
2262a41e607SRussell King */
try_to_bring_up_aggregate_device(struct aggregate_device * adev,struct component * component)22713e906e5SStephen Boyd static int try_to_bring_up_aggregate_device(struct aggregate_device *adev,
2282a41e607SRussell King struct component *component)
2292a41e607SRussell King {
230c334940eSRussell King int ret;
2312a41e607SRussell King
23213e906e5SStephen Boyd dev_dbg(adev->parent, "trying to bring up adev\n");
233ffc30b74SRussell King
23413e906e5SStephen Boyd if (find_components(adev)) {
23513e906e5SStephen Boyd dev_dbg(adev->parent, "master has incomplete components\n");
236ffc30b74SRussell King return 0;
2372a41e607SRussell King }
2382a41e607SRussell King
23913e906e5SStephen Boyd if (component && component->adev != adev) {
24013e906e5SStephen Boyd dev_dbg(adev->parent, "master is not for this component (%s)\n",
241ffc30b74SRussell King dev_name(component->dev));
242ffc30b74SRussell King return 0;
2432a41e607SRussell King }
2442a41e607SRussell King
24513e906e5SStephen Boyd if (!devres_open_group(adev->parent, adev, GFP_KERNEL))
246ffc30b74SRussell King return -ENOMEM;
2479e1ccb4aSRussell King
2482a41e607SRussell King /* Found all components */
24913e906e5SStephen Boyd ret = adev->ops->bind(adev->parent);
2502a41e607SRussell King if (ret < 0) {
25113e906e5SStephen Boyd devres_release_group(adev->parent, NULL);
2527706b0a7SJames Hilliard if (ret != -EPROBE_DEFER)
25313e906e5SStephen Boyd dev_info(adev->parent, "adev bind failed: %d\n", ret);
254ffc30b74SRussell King return ret;
2552a41e607SRussell King }
2562a41e607SRussell King
25713e906e5SStephen Boyd devres_close_group(adev->parent, NULL);
25813e906e5SStephen Boyd adev->bound = true;
259c334940eSRussell King return 1;
2602a41e607SRussell King }
2612a41e607SRussell King
try_to_bring_up_masters(struct component * component)2622a41e607SRussell King static int try_to_bring_up_masters(struct component *component)
2632a41e607SRussell King {
26413e906e5SStephen Boyd struct aggregate_device *adev;
2652a41e607SRussell King int ret = 0;
2662a41e607SRussell King
26713e906e5SStephen Boyd list_for_each_entry(adev, &aggregate_devices, node) {
26813e906e5SStephen Boyd if (!adev->bound) {
26913e906e5SStephen Boyd ret = try_to_bring_up_aggregate_device(adev, component);
2702a41e607SRussell King if (ret != 0)
2712a41e607SRussell King break;
2722a41e607SRussell King }
27329f1c7fdSRussell King }
2742a41e607SRussell King
2752a41e607SRussell King return ret;
2762a41e607SRussell King }
2772a41e607SRussell King
take_down_aggregate_device(struct aggregate_device * adev)27813e906e5SStephen Boyd static void take_down_aggregate_device(struct aggregate_device *adev)
2792a41e607SRussell King {
28013e906e5SStephen Boyd if (adev->bound) {
28113e906e5SStephen Boyd adev->ops->unbind(adev->parent);
28213e906e5SStephen Boyd devres_release_group(adev->parent, adev);
28313e906e5SStephen Boyd adev->bound = false;
2842a41e607SRussell King }
2852a41e607SRussell King }
2862a41e607SRussell King
2872502960fSYong Wu /**
2882502960fSYong Wu * component_compare_of - A common component compare function for of_node
2892502960fSYong Wu * @dev: component device
2902502960fSYong Wu * @data: @compare_data from component_match_add_release()
2912502960fSYong Wu *
2922502960fSYong Wu * A common compare function when compare_data is device of_node. e.g.
2932502960fSYong Wu * component_match_add_release(masterdev, &match, component_release_of,
2942502960fSYong Wu * component_compare_of, component_dev_of_node)
2952502960fSYong Wu */
component_compare_of(struct device * dev,void * data)2962502960fSYong Wu int component_compare_of(struct device *dev, void *data)
2972502960fSYong Wu {
2982502960fSYong Wu return device_match_of_node(dev, data);
2992502960fSYong Wu }
3002502960fSYong Wu EXPORT_SYMBOL_GPL(component_compare_of);
3012502960fSYong Wu
3022502960fSYong Wu /**
3032502960fSYong Wu * component_release_of - A common component release function for of_node
3042502960fSYong Wu * @dev: component device
3052502960fSYong Wu * @data: @compare_data from component_match_add_release()
3062502960fSYong Wu *
3072502960fSYong Wu * About the example, Please see component_compare_of().
3082502960fSYong Wu */
component_release_of(struct device * dev,void * data)3092502960fSYong Wu void component_release_of(struct device *dev, void *data)
3102502960fSYong Wu {
3112502960fSYong Wu of_node_put(data);
3122502960fSYong Wu }
3132502960fSYong Wu EXPORT_SYMBOL_GPL(component_release_of);
3142502960fSYong Wu
3152502960fSYong Wu /**
3162502960fSYong Wu * component_compare_dev - A common component compare function for dev
3172502960fSYong Wu * @dev: component device
3182502960fSYong Wu * @data: @compare_data from component_match_add_release()
3192502960fSYong Wu *
3202502960fSYong Wu * A common compare function when compare_data is struce device. e.g.
3212502960fSYong Wu * component_match_add(masterdev, &match, component_compare_dev, component_dev)
3222502960fSYong Wu */
component_compare_dev(struct device * dev,void * data)3232502960fSYong Wu int component_compare_dev(struct device *dev, void *data)
3242502960fSYong Wu {
3252502960fSYong Wu return dev == data;
3262502960fSYong Wu }
3272502960fSYong Wu EXPORT_SYMBOL_GPL(component_compare_dev);
3282502960fSYong Wu
3292502960fSYong Wu /**
3302502960fSYong Wu * component_compare_dev_name - A common component compare function for device name
3312502960fSYong Wu * @dev: component device
3322502960fSYong Wu * @data: @compare_data from component_match_add_release()
3332502960fSYong Wu *
3342502960fSYong Wu * A common compare function when compare_data is device name string. e.g.
3352502960fSYong Wu * component_match_add(masterdev, &match, component_compare_dev_name,
3362502960fSYong Wu * "component_dev_name")
3372502960fSYong Wu */
component_compare_dev_name(struct device * dev,void * data)3382502960fSYong Wu int component_compare_dev_name(struct device *dev, void *data)
3392502960fSYong Wu {
3402502960fSYong Wu return device_match_name(dev, data);
3412502960fSYong Wu }
3422502960fSYong Wu EXPORT_SYMBOL_GPL(component_compare_dev_name);
3432502960fSYong Wu
devm_component_match_release(struct device * parent,void * res)344d52ff34eSStephen Boyd static void devm_component_match_release(struct device *parent, void *res)
3456955b582SRussell King {
346d52ff34eSStephen Boyd struct component_match *match = res;
347ce657b1cSRussell King unsigned int i;
348ce657b1cSRussell King
349ce657b1cSRussell King for (i = 0; i < match->num; i++) {
350ce657b1cSRussell King struct component_match_array *mc = &match->compare[i];
351ce657b1cSRussell King
352ce657b1cSRussell King if (mc->release)
353d52ff34eSStephen Boyd mc->release(parent, mc->data);
354ce657b1cSRussell King }
3559a4e7849SRussell King
3569a4e7849SRussell King kfree(match->compare);
3576955b582SRussell King }
3586955b582SRussell King
component_match_realloc(struct component_match * match,size_t num)35982769cc6SStephen Boyd static int component_match_realloc(struct component_match *match, size_t num)
3606955b582SRussell King {
361ce657b1cSRussell King struct component_match_array *new;
3626955b582SRussell King
363ce657b1cSRussell King if (match->alloc == num)
364ce657b1cSRussell King return 0;
3656955b582SRussell King
3669a4e7849SRussell King new = kmalloc_array(num, sizeof(*new), GFP_KERNEL);
3676955b582SRussell King if (!new)
368ce657b1cSRussell King return -ENOMEM;
3696955b582SRussell King
370ce657b1cSRussell King if (match->compare) {
371ce657b1cSRussell King memcpy(new, match->compare, sizeof(*new) *
372ce657b1cSRussell King min(match->num, num));
3739a4e7849SRussell King kfree(match->compare);
3746955b582SRussell King }
375ce657b1cSRussell King match->compare = new;
376ce657b1cSRussell King match->alloc = num;
3776955b582SRussell King
378ce657b1cSRussell King return 0;
3796955b582SRussell King }
3806955b582SRussell King
__component_match_add(struct device * parent,struct component_match ** matchptr,void (* release)(struct device *,void *),int (* compare)(struct device *,void *),int (* compare_typed)(struct device *,int,void *),void * compare_data)38113e906e5SStephen Boyd static void __component_match_add(struct device *parent,
382ce657b1cSRussell King struct component_match **matchptr,
383ce657b1cSRussell King void (*release)(struct device *, void *),
3843521ee99SDaniel Vetter int (*compare)(struct device *, void *),
3853521ee99SDaniel Vetter int (*compare_typed)(struct device *, int, void *),
3863521ee99SDaniel Vetter void *compare_data)
3876955b582SRussell King {
3886955b582SRussell King struct component_match *match = *matchptr;
3896955b582SRussell King
3906955b582SRussell King if (IS_ERR(match))
3916955b582SRussell King return;
3926955b582SRussell King
393ce657b1cSRussell King if (!match) {
394ce657b1cSRussell King match = devres_alloc(devm_component_match_release,
395ce657b1cSRussell King sizeof(*match), GFP_KERNEL);
396ce657b1cSRussell King if (!match) {
397ce657b1cSRussell King *matchptr = ERR_PTR(-ENOMEM);
3986955b582SRussell King return;
3996955b582SRussell King }
4006955b582SRussell King
40113e906e5SStephen Boyd devres_add(parent, match);
402ce657b1cSRussell King
403ce657b1cSRussell King *matchptr = match;
404ce657b1cSRussell King }
405ce657b1cSRussell King
406ce657b1cSRussell King if (match->num == match->alloc) {
4074877bb91SSudip Mukherjee size_t new_size = match->alloc + 16;
408ce657b1cSRussell King int ret;
409ce657b1cSRussell King
41082769cc6SStephen Boyd ret = component_match_realloc(match, new_size);
411ce657b1cSRussell King if (ret) {
412ce657b1cSRussell King *matchptr = ERR_PTR(ret);
413ce657b1cSRussell King return;
414ce657b1cSRussell King }
415ce657b1cSRussell King }
416ce657b1cSRussell King
417ce657b1cSRussell King match->compare[match->num].compare = compare;
4183521ee99SDaniel Vetter match->compare[match->num].compare_typed = compare_typed;
419ce657b1cSRussell King match->compare[match->num].release = release;
4206955b582SRussell King match->compare[match->num].data = compare_data;
421ffc30b74SRussell King match->compare[match->num].component = NULL;
4226955b582SRussell King match->num++;
4236955b582SRussell King }
4243521ee99SDaniel Vetter
4253521ee99SDaniel Vetter /**
426e4246b05SDaniel Vetter * component_match_add_release - add a component match entry with release callback
42713e906e5SStephen Boyd * @parent: parent device of the aggregate driver
4283521ee99SDaniel Vetter * @matchptr: pointer to the list of component matches
4293521ee99SDaniel Vetter * @release: release function for @compare_data
4303521ee99SDaniel Vetter * @compare: compare function to match against all components
4313521ee99SDaniel Vetter * @compare_data: opaque pointer passed to the @compare function
4323521ee99SDaniel Vetter *
43313e906e5SStephen Boyd * Adds a new component match to the list stored in @matchptr, which the
4343521ee99SDaniel Vetter * aggregate driver needs to function. The list of component matches pointed to
4353521ee99SDaniel Vetter * by @matchptr must be initialized to NULL before adding the first match. This
4363521ee99SDaniel Vetter * only matches against components added with component_add().
4373521ee99SDaniel Vetter *
4383521ee99SDaniel Vetter * The allocated match list in @matchptr is automatically released using devm
4393521ee99SDaniel Vetter * actions, where upon @release will be called to free any references held by
4403521ee99SDaniel Vetter * @compare_data, e.g. when @compare_data is a &device_node that must be
4413521ee99SDaniel Vetter * released with of_node_put().
4423521ee99SDaniel Vetter *
4433521ee99SDaniel Vetter * See also component_match_add() and component_match_add_typed().
4443521ee99SDaniel Vetter */
component_match_add_release(struct device * parent,struct component_match ** matchptr,void (* release)(struct device *,void *),int (* compare)(struct device *,void *),void * compare_data)44513e906e5SStephen Boyd void component_match_add_release(struct device *parent,
4463521ee99SDaniel Vetter struct component_match **matchptr,
4473521ee99SDaniel Vetter void (*release)(struct device *, void *),
4483521ee99SDaniel Vetter int (*compare)(struct device *, void *), void *compare_data)
4493521ee99SDaniel Vetter {
45013e906e5SStephen Boyd __component_match_add(parent, matchptr, release, compare, NULL,
4513521ee99SDaniel Vetter compare_data);
4523521ee99SDaniel Vetter }
453ce657b1cSRussell King EXPORT_SYMBOL(component_match_add_release);
4546955b582SRussell King
4553521ee99SDaniel Vetter /**
456e4246b05SDaniel Vetter * component_match_add_typed - add a component match entry for a typed component
45713e906e5SStephen Boyd * @parent: parent device of the aggregate driver
4583521ee99SDaniel Vetter * @matchptr: pointer to the list of component matches
4593521ee99SDaniel Vetter * @compare_typed: compare function to match against all typed components
4603521ee99SDaniel Vetter * @compare_data: opaque pointer passed to the @compare function
4613521ee99SDaniel Vetter *
46213e906e5SStephen Boyd * Adds a new component match to the list stored in @matchptr, which the
4633521ee99SDaniel Vetter * aggregate driver needs to function. The list of component matches pointed to
4643521ee99SDaniel Vetter * by @matchptr must be initialized to NULL before adding the first match. This
4653521ee99SDaniel Vetter * only matches against components added with component_add_typed().
4663521ee99SDaniel Vetter *
4673521ee99SDaniel Vetter * The allocated match list in @matchptr is automatically released using devm
4683521ee99SDaniel Vetter * actions.
4693521ee99SDaniel Vetter *
4703521ee99SDaniel Vetter * See also component_match_add_release() and component_match_add_typed().
4713521ee99SDaniel Vetter */
component_match_add_typed(struct device * parent,struct component_match ** matchptr,int (* compare_typed)(struct device *,int,void *),void * compare_data)47213e906e5SStephen Boyd void component_match_add_typed(struct device *parent,
4733521ee99SDaniel Vetter struct component_match **matchptr,
4743521ee99SDaniel Vetter int (*compare_typed)(struct device *, int, void *), void *compare_data)
4753521ee99SDaniel Vetter {
47613e906e5SStephen Boyd __component_match_add(parent, matchptr, NULL, NULL, compare_typed,
4773521ee99SDaniel Vetter compare_data);
4783521ee99SDaniel Vetter }
4793521ee99SDaniel Vetter EXPORT_SYMBOL(component_match_add_typed);
4803521ee99SDaniel Vetter
free_aggregate_device(struct aggregate_device * adev)48113e906e5SStephen Boyd static void free_aggregate_device(struct aggregate_device *adev)
48257480484SJon Medhurst (Tixy) {
48313e906e5SStephen Boyd struct component_match *match = adev->match;
48457480484SJon Medhurst (Tixy) int i;
48557480484SJon Medhurst (Tixy)
48613e906e5SStephen Boyd component_debugfs_del(adev);
48713e906e5SStephen Boyd list_del(&adev->node);
48857480484SJon Medhurst (Tixy)
48957480484SJon Medhurst (Tixy) if (match) {
49057480484SJon Medhurst (Tixy) for (i = 0; i < match->num; i++) {
49157480484SJon Medhurst (Tixy) struct component *c = match->compare[i].component;
49257480484SJon Medhurst (Tixy) if (c)
49313e906e5SStephen Boyd c->adev = NULL;
49457480484SJon Medhurst (Tixy) }
49557480484SJon Medhurst (Tixy) }
49657480484SJon Medhurst (Tixy)
49713e906e5SStephen Boyd kfree(adev);
49857480484SJon Medhurst (Tixy) }
49957480484SJon Medhurst (Tixy)
5004d69c80eSDaniel Vetter /**
5014d69c80eSDaniel Vetter * component_master_add_with_match - register an aggregate driver
502d52ff34eSStephen Boyd * @parent: parent device of the aggregate driver
5034d69c80eSDaniel Vetter * @ops: callbacks for the aggregate driver
5044d69c80eSDaniel Vetter * @match: component match list for the aggregate driver
5054d69c80eSDaniel Vetter *
5064d69c80eSDaniel Vetter * Registers a new aggregate driver consisting of the components added to @match
5074d69c80eSDaniel Vetter * by calling one of the component_match_add() functions. Once all components in
5084d69c80eSDaniel Vetter * @match are available, it will be assembled by calling
5094d69c80eSDaniel Vetter * &component_master_ops.bind from @ops. Must be unregistered by calling
5104d69c80eSDaniel Vetter * component_master_del().
5114d69c80eSDaniel Vetter */
component_master_add_with_match(struct device * parent,const struct component_master_ops * ops,struct component_match * match)512d52ff34eSStephen Boyd int component_master_add_with_match(struct device *parent,
5136955b582SRussell King const struct component_master_ops *ops,
5146955b582SRussell King struct component_match *match)
5152a41e607SRussell King {
51613e906e5SStephen Boyd struct aggregate_device *adev;
5172a41e607SRussell King int ret;
5182a41e607SRussell King
5196955b582SRussell King /* Reallocate the match array for its true size */
52082769cc6SStephen Boyd ret = component_match_realloc(match, match->num);
521ce657b1cSRussell King if (ret)
522ce657b1cSRussell King return ret;
5236955b582SRussell King
52413e906e5SStephen Boyd adev = kzalloc(sizeof(*adev), GFP_KERNEL);
52513e906e5SStephen Boyd if (!adev)
5262a41e607SRussell King return -ENOMEM;
5272a41e607SRussell King
52813e906e5SStephen Boyd adev->parent = parent;
52913e906e5SStephen Boyd adev->ops = ops;
53013e906e5SStephen Boyd adev->match = match;
5312a41e607SRussell King
53213e906e5SStephen Boyd component_debugfs_add(adev);
53313e906e5SStephen Boyd /* Add to the list of available aggregate devices. */
5342a41e607SRussell King mutex_lock(&component_mutex);
53513e906e5SStephen Boyd list_add(&adev->node, &aggregate_devices);
5362a41e607SRussell King
53713e906e5SStephen Boyd ret = try_to_bring_up_aggregate_device(adev, NULL);
5382a41e607SRussell King
53957480484SJon Medhurst (Tixy) if (ret < 0)
54013e906e5SStephen Boyd free_aggregate_device(adev);
54157480484SJon Medhurst (Tixy)
5422a41e607SRussell King mutex_unlock(&component_mutex);
5432a41e607SRussell King
5442a41e607SRussell King return ret < 0 ? ret : 0;
5452a41e607SRussell King }
5466955b582SRussell King EXPORT_SYMBOL_GPL(component_master_add_with_match);
5476955b582SRussell King
5484d69c80eSDaniel Vetter /**
5494d69c80eSDaniel Vetter * component_master_del - unregister an aggregate driver
550d52ff34eSStephen Boyd * @parent: parent device of the aggregate driver
5514d69c80eSDaniel Vetter * @ops: callbacks for the aggregate driver
5524d69c80eSDaniel Vetter *
5534d69c80eSDaniel Vetter * Unregisters an aggregate driver registered with
5544d69c80eSDaniel Vetter * component_master_add_with_match(). If necessary the aggregate driver is first
5554d69c80eSDaniel Vetter * disassembled by calling &component_master_ops.unbind from @ops.
5564d69c80eSDaniel Vetter */
component_master_del(struct device * parent,const struct component_master_ops * ops)557d52ff34eSStephen Boyd void component_master_del(struct device *parent,
5582a41e607SRussell King const struct component_master_ops *ops)
5592a41e607SRussell King {
56013e906e5SStephen Boyd struct aggregate_device *adev;
5612a41e607SRussell King
5622a41e607SRussell King mutex_lock(&component_mutex);
56313e906e5SStephen Boyd adev = __aggregate_find(parent, ops);
56413e906e5SStephen Boyd if (adev) {
56513e906e5SStephen Boyd take_down_aggregate_device(adev);
56613e906e5SStephen Boyd free_aggregate_device(adev);
5672a41e607SRussell King }
5682a41e607SRussell King mutex_unlock(&component_mutex);
5692a41e607SRussell King }
5702a41e607SRussell King EXPORT_SYMBOL_GPL(component_master_del);
5712a41e607SRussell King
component_master_is_bound(struct device * parent,const struct component_master_ops * ops)572*a6ba2dadSHeiko Stuebner bool component_master_is_bound(struct device *parent,
573*a6ba2dadSHeiko Stuebner const struct component_master_ops *ops)
574*a6ba2dadSHeiko Stuebner {
575*a6ba2dadSHeiko Stuebner struct aggregate_device *adev;
576*a6ba2dadSHeiko Stuebner
577*a6ba2dadSHeiko Stuebner guard(mutex)(&component_mutex);
578*a6ba2dadSHeiko Stuebner adev = __aggregate_find(parent, ops);
579*a6ba2dadSHeiko Stuebner if (!adev)
580*a6ba2dadSHeiko Stuebner return 0;
581*a6ba2dadSHeiko Stuebner
582*a6ba2dadSHeiko Stuebner return adev->bound;
583*a6ba2dadSHeiko Stuebner }
584*a6ba2dadSHeiko Stuebner EXPORT_SYMBOL_GPL(component_master_is_bound);
585*a6ba2dadSHeiko Stuebner
component_unbind(struct component * component,struct aggregate_device * adev,void * data)5862a41e607SRussell King static void component_unbind(struct component *component,
58713e906e5SStephen Boyd struct aggregate_device *adev, void *data)
5882a41e607SRussell King {
5892a41e607SRussell King WARN_ON(!component->bound);
5902a41e607SRussell King
59114422f14SMarco Felsch dev_dbg(adev->parent, "unbinding %s component %p (ops %ps)\n",
59213e906e5SStephen Boyd dev_name(component->dev), component, component->ops);
5932a41e607SRussell King
5942a41e607SRussell King if (component->ops && component->ops->unbind)
5952a41e607SRussell King component->ops->unbind(component->dev, adev->parent, data);
5962a41e607SRussell King component->bound = false;
5972a41e607SRussell King
5982a41e607SRussell King /* Release all resources claimed in the binding of this component */
5994d69c80eSDaniel Vetter devres_release_group(component->dev, component);
600e4246b05SDaniel Vetter }
601d52ff34eSStephen Boyd
6024d69c80eSDaniel Vetter /**
6034d69c80eSDaniel Vetter * component_unbind_all - unbind all components of an aggregate driver
604d52ff34eSStephen Boyd * @parent: parent device of the aggregate driver
6054d69c80eSDaniel Vetter * @data: opaque pointer, passed to all components
6064d69c80eSDaniel Vetter *
6074d69c80eSDaniel Vetter * Unbinds all components of the aggregate device by passing @data to their
608d52ff34eSStephen Boyd * &component_ops.unbind functions. Should be called from
6092a41e607SRussell King * &component_master_ops.unbind.
61013e906e5SStephen Boyd */
component_unbind_all(struct device * parent,void * data)6112a41e607SRussell King void component_unbind_all(struct device *parent, void *data)
612ffc30b74SRussell King {
6132a41e607SRussell King struct aggregate_device *adev;
6142a41e607SRussell King struct component *c;
6152a41e607SRussell King size_t i;
61613e906e5SStephen Boyd
61713e906e5SStephen Boyd WARN_ON(!mutex_is_locked(&component_mutex));
6182a41e607SRussell King
6192a41e607SRussell King adev = __aggregate_find(parent, NULL);
620ffc30b74SRussell King if (!adev)
62113e906e5SStephen Boyd return;
62213e906e5SStephen Boyd
62313e906e5SStephen Boyd /* Unbind components in reverse order */
62413e906e5SStephen Boyd for (i = adev->match->num; i--; )
6252a41e607SRussell King if (!adev->match->compare[i].duplicate) {
626ffc30b74SRussell King c = adev->match->compare[i].component;
6272a41e607SRussell King component_unbind(c, adev, data);
6282a41e607SRussell King }
62913e906e5SStephen Boyd }
6302a41e607SRussell King EXPORT_SYMBOL_GPL(component_unbind_all);
6312a41e607SRussell King
component_bind(struct component * component,struct aggregate_device * adev,void * data)6322a41e607SRussell King static int component_bind(struct component *component, struct aggregate_device *adev,
6332a41e607SRussell King void *data)
6342a41e607SRussell King {
6352a41e607SRussell King int ret;
6362a41e607SRussell King
6372a41e607SRussell King /*
6382a41e607SRussell King * Each component initialises inside its own devres group.
63913e906e5SStephen Boyd * This allows us to roll-back a failed component without
6402a41e607SRussell King * affecting anything else.
6412a41e607SRussell King */
6422a41e607SRussell King if (!devres_open_group(adev->parent, NULL, GFP_KERNEL))
6432a41e607SRussell King return -ENOMEM;
6442a41e607SRussell King
6452a41e607SRussell King /*
6462a41e607SRussell King * Also open a group for the device itself: this allows us
6472a41e607SRussell King * to release the resources claimed against the sub-device
64813e906e5SStephen Boyd * at the appropriate moment.
6492a41e607SRussell King */
6502a41e607SRussell King if (!devres_open_group(component->dev, component, GFP_KERNEL)) {
6512a41e607SRussell King devres_release_group(adev->parent, NULL);
65213e906e5SStephen Boyd return -ENOMEM;
6532a41e607SRussell King }
6542a41e607SRussell King
65513e906e5SStephen Boyd dev_dbg(adev->parent, "binding %s (ops %ps)\n",
6562a41e607SRussell King dev_name(component->dev), component->ops);
6572a41e607SRussell King
6582a41e607SRussell King ret = component->ops->bind(component->dev, adev->parent, data);
6592a41e607SRussell King if (!ret) {
6602a41e607SRussell King component->bound = true;
6612a41e607SRussell King
6622a41e607SRussell King /*
6632a41e607SRussell King * Close the component device's group so that resources
6642a41e607SRussell King * allocated in the binding are encapsulated for removal
6652a41e607SRussell King * at unbind. Remove the group on the DRM device as we
66613e906e5SStephen Boyd * can clean those resources up independently.
6672a41e607SRussell King */
66813e906e5SStephen Boyd devres_close_group(component->dev, NULL);
6692a41e607SRussell King devres_remove_group(adev->parent, NULL);
6702a41e607SRussell King
6712a41e607SRussell King dev_info(adev->parent, "bound %s (ops %ps)\n",
67213e906e5SStephen Boyd dev_name(component->dev), component->ops);
6732a41e607SRussell King } else {
6747706b0a7SJames Hilliard devres_release_group(component->dev, NULL);
67513e906e5SStephen Boyd devres_release_group(adev->parent, NULL);
6762a41e607SRussell King
6772a41e607SRussell King if (ret != -EPROBE_DEFER)
6782a41e607SRussell King dev_err(adev->parent, "failed to bind %s (ops %ps): %d\n",
6792a41e607SRussell King dev_name(component->dev), component->ops, ret);
6802a41e607SRussell King }
6812a41e607SRussell King
6824d69c80eSDaniel Vetter return ret;
683e4246b05SDaniel Vetter }
684d52ff34eSStephen Boyd
6854d69c80eSDaniel Vetter /**
6864d69c80eSDaniel Vetter * component_bind_all - bind all components of an aggregate driver
687e4246b05SDaniel Vetter * @parent: parent device of the aggregate driver
6884d69c80eSDaniel Vetter * @data: opaque pointer, passed to all components
6894d69c80eSDaniel Vetter *
6904d69c80eSDaniel Vetter * Binds all components of the aggregate @dev by passing @data to their
691d52ff34eSStephen Boyd * &component_ops.bind functions. Should be called from
6922a41e607SRussell King * &component_master_ops.bind.
69313e906e5SStephen Boyd */
component_bind_all(struct device * parent,void * data)6942a41e607SRussell King int component_bind_all(struct device *parent, void *data)
695ffc30b74SRussell King {
6962a41e607SRussell King struct aggregate_device *adev;
6972a41e607SRussell King struct component *c;
6982a41e607SRussell King size_t i;
6992a41e607SRussell King int ret = 0;
70013e906e5SStephen Boyd
70113e906e5SStephen Boyd WARN_ON(!mutex_is_locked(&component_mutex));
7022a41e607SRussell King
7032a41e607SRussell King adev = __aggregate_find(parent, NULL);
704ffc30b74SRussell King if (!adev)
70513e906e5SStephen Boyd return -EINVAL;
70613e906e5SStephen Boyd
70713e906e5SStephen Boyd /* Bind components in match order */
70813e906e5SStephen Boyd for (i = 0; i < adev->match->num; i++)
7092a41e607SRussell King if (!adev->match->compare[i].duplicate) {
7102a41e607SRussell King c = adev->match->compare[i].component;
7112a41e607SRussell King ret = component_bind(c, adev, data);
7122a41e607SRussell King if (ret)
7132a41e607SRussell King break;
714bdae566dSBanajit Goswami }
71513e906e5SStephen Boyd
71613e906e5SStephen Boyd if (ret != 0) {
71713e906e5SStephen Boyd for (; i > 0; i--)
7182a41e607SRussell King if (!adev->match->compare[i - 1].duplicate) {
719ffc30b74SRussell King c = adev->match->compare[i - 1].component;
7202a41e607SRussell King component_unbind(c, adev, data);
7212a41e607SRussell King }
7222a41e607SRussell King }
7232a41e607SRussell King
7242a41e607SRussell King return ret;
7253521ee99SDaniel Vetter }
7263521ee99SDaniel Vetter EXPORT_SYMBOL_GPL(component_bind_all);
7272a41e607SRussell King
__component_add(struct device * dev,const struct component_ops * ops,int subcomponent)7282a41e607SRussell King static int __component_add(struct device *dev, const struct component_ops *ops,
7292a41e607SRussell King int subcomponent)
7302a41e607SRussell King {
7312a41e607SRussell King struct component *component;
7322a41e607SRussell King int ret;
7332a41e607SRussell King
7342a41e607SRussell King component = kzalloc(sizeof(*component), GFP_KERNEL);
7352a41e607SRussell King if (!component)
7362a41e607SRussell King return -ENOMEM;
7373521ee99SDaniel Vetter
7382a41e607SRussell King component->ops = ops;
7392a41e607SRussell King component->dev = dev;
7402a41e607SRussell King component->subcomponent = subcomponent;
7412a41e607SRussell King
7422a41e607SRussell King dev_dbg(dev, "adding component (ops %ps)\n", ops);
7432a41e607SRussell King
7442a41e607SRussell King mutex_lock(&component_mutex);
7452a41e607SRussell King list_add_tail(&component->node, &component_list);
74613e906e5SStephen Boyd
74713e906e5SStephen Boyd ret = try_to_bring_up_masters(component);
7482a41e607SRussell King if (ret < 0) {
7492a41e607SRussell King if (component->adev)
7502a41e607SRussell King remove_component(component->adev, component);
7512a41e607SRussell King list_del(&component->node);
7522a41e607SRussell King
7532a41e607SRussell King kfree(component);
7542a41e607SRussell King }
7552a41e607SRussell King mutex_unlock(&component_mutex);
7563521ee99SDaniel Vetter
7573521ee99SDaniel Vetter return ret < 0 ? ret : 0;
7583521ee99SDaniel Vetter }
7593521ee99SDaniel Vetter
7603521ee99SDaniel Vetter /**
7613521ee99SDaniel Vetter * component_add_typed - register a component
7623521ee99SDaniel Vetter * @dev: component device
7633521ee99SDaniel Vetter * @ops: component callbacks
7643521ee99SDaniel Vetter * @subcomponent: nonzero identifier for subcomponents
7653521ee99SDaniel Vetter *
7663521ee99SDaniel Vetter * Register a new component for @dev. Functions in @ops will be call when the
7673521ee99SDaniel Vetter * aggregate driver is ready to bind the overall driver by calling
768f297a384SRandy Dunlap * component_bind_all(). See also &struct component_ops.
7693521ee99SDaniel Vetter *
7703521ee99SDaniel Vetter * @subcomponent must be nonzero and is used to differentiate between multiple
7713521ee99SDaniel Vetter * components registered on the same device @dev. These components are match
7723521ee99SDaniel Vetter * using component_match_add_typed().
7733521ee99SDaniel Vetter *
7743521ee99SDaniel Vetter * The component needs to be unregistered at driver unload/disconnect by
7753521ee99SDaniel Vetter * calling component_del().
7763521ee99SDaniel Vetter *
7773521ee99SDaniel Vetter * See also component_add().
7783521ee99SDaniel Vetter */
component_add_typed(struct device * dev,const struct component_ops * ops,int subcomponent)7793521ee99SDaniel Vetter int component_add_typed(struct device *dev, const struct component_ops *ops,
7803521ee99SDaniel Vetter int subcomponent)
7813521ee99SDaniel Vetter {
7823521ee99SDaniel Vetter if (WARN_ON(subcomponent == 0))
7833521ee99SDaniel Vetter return -EINVAL;
7843521ee99SDaniel Vetter
7853521ee99SDaniel Vetter return __component_add(dev, ops, subcomponent);
7863521ee99SDaniel Vetter }
7873521ee99SDaniel Vetter EXPORT_SYMBOL_GPL(component_add_typed);
7883521ee99SDaniel Vetter
7893521ee99SDaniel Vetter /**
7903521ee99SDaniel Vetter * component_add - register a component
7913521ee99SDaniel Vetter * @dev: component device
7923521ee99SDaniel Vetter * @ops: component callbacks
7933521ee99SDaniel Vetter *
7943521ee99SDaniel Vetter * Register a new component for @dev. Functions in @ops will be called when the
7953521ee99SDaniel Vetter * aggregate driver is ready to bind the overall driver by calling
7963521ee99SDaniel Vetter * component_bind_all(). See also &struct component_ops.
7973521ee99SDaniel Vetter *
798f297a384SRandy Dunlap * The component needs to be unregistered at driver unload/disconnect by
7993521ee99SDaniel Vetter * calling component_del().
8003521ee99SDaniel Vetter *
8013521ee99SDaniel Vetter * See also component_add_typed() for a variant that allows multiple different
8023521ee99SDaniel Vetter * components on the same device.
8033521ee99SDaniel Vetter */
component_add(struct device * dev,const struct component_ops * ops)8043521ee99SDaniel Vetter int component_add(struct device *dev, const struct component_ops *ops)
8052a41e607SRussell King {
8062a41e607SRussell King return __component_add(dev, ops, 0);
8074d69c80eSDaniel Vetter }
8084d69c80eSDaniel Vetter EXPORT_SYMBOL_GPL(component_add);
8094d69c80eSDaniel Vetter
8104d69c80eSDaniel Vetter /**
8114d69c80eSDaniel Vetter * component_del - unregister a component
8124d69c80eSDaniel Vetter * @dev: component device
8134d69c80eSDaniel Vetter * @ops: component callbacks
8144d69c80eSDaniel Vetter *
8154d69c80eSDaniel Vetter * Unregister a component added with component_add(). If the component is bound
8162a41e607SRussell King * into an aggregate driver, this will force the entire aggregate driver, including
8172a41e607SRussell King * all its components, to be unbound.
8182a41e607SRussell King */
component_del(struct device * dev,const struct component_ops * ops)8192a41e607SRussell King void component_del(struct device *dev, const struct component_ops *ops)
8202a41e607SRussell King {
8212a41e607SRussell King struct component *c, *component = NULL;
8222a41e607SRussell King
8232a41e607SRussell King mutex_lock(&component_mutex);
8242a41e607SRussell King list_for_each_entry(c, &component_list, node)
8252a41e607SRussell King if (c->dev == dev && c->ops == ops) {
8262a41e607SRussell King list_del(&c->node);
8272a41e607SRussell King component = c;
82813e906e5SStephen Boyd break;
82913e906e5SStephen Boyd }
83013e906e5SStephen Boyd
831ffc30b74SRussell King if (component && component->adev) {
8322a41e607SRussell King take_down_aggregate_device(component->adev);
8332a41e607SRussell King remove_component(component->adev, component);
8342a41e607SRussell King }
8352a41e607SRussell King
8362a41e607SRussell King mutex_unlock(&component_mutex);
8372a41e607SRussell King
8382a41e607SRussell King WARN_ON(!component);
839 kfree(component);
840 }
841 EXPORT_SYMBOL_GPL(component_del);
842