blob: 4b3dcb3b379ad4d0ca99c114de0e1cbc7ec9a28c [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassdd6ab882014-02-26 15:59:18 -07002/*
3 * Device manager
4 *
5 * Copyright (c) 2013 Google, Inc
6 *
7 * (C) Copyright 2012
8 * Pavel Herrmann <morpheus.ibis@gmail.com>
Simon Glassdd6ab882014-02-26 15:59:18 -07009 */
10
11#include <common.h>
Simon Glass63334482019-11-14 12:57:39 -070012#include <cpu_func.h>
Simon Glass0f2af882020-05-10 11:40:05 -060013#include <log.h>
Vignesh R0dff3702016-07-06 09:58:55 +053014#include <asm/io.h>
Philipp Tomsich9cf03b02018-01-08 13:59:18 +010015#include <clk.h>
Simon Glassdb6f0202014-07-23 06:55:12 -060016#include <fdtdec.h>
Stefan Roeseadc09052015-09-02 07:41:12 +020017#include <fdt_support.h>
Simon Glassdd6ab882014-02-26 15:59:18 -070018#include <malloc.h>
Simon Glass274e0b02020-05-10 11:39:56 -060019#include <asm/cache.h>
Simon Glassdd6ab882014-02-26 15:59:18 -070020#include <dm/device.h>
21#include <dm/device-internal.h>
22#include <dm/lists.h>
Mario Six1f1c1ec2018-01-15 11:07:20 +010023#include <dm/of_access.h>
Masahiro Yamadaf8efa632015-08-27 12:44:29 +090024#include <dm/pinctrl.h>
Simon Glassdd6ab882014-02-26 15:59:18 -070025#include <dm/platdata.h>
Simon Glass322b2902017-05-18 20:09:05 -060026#include <dm/read.h>
Simon Glassdd6ab882014-02-26 15:59:18 -070027#include <dm/uclass.h>
28#include <dm/uclass-internal.h>
29#include <dm/util.h>
30#include <linux/err.h>
31#include <linux/list.h>
Peng Fan6fba32d2018-07-27 10:20:38 +080032#include <power-domain.h>
Simon Glassdd6ab882014-02-26 15:59:18 -070033
Simon Glassdb6f0202014-07-23 06:55:12 -060034DECLARE_GLOBAL_DATA_PTR;
35
Stephen Warren8c93df12016-05-11 15:26:24 -060036static int device_bind_common(struct udevice *parent, const struct driver *drv,
37 const char *name, void *platdata,
Simon Glassb0cf4b32017-05-17 17:18:11 -060038 ulong driver_data, ofnode node,
Simon Glassafbf9b82016-07-04 11:58:18 -060039 uint of_platdata_size, struct udevice **devp)
Simon Glassdd6ab882014-02-26 15:59:18 -070040{
Heiko Schocherb74fcb42014-05-22 12:43:05 +020041 struct udevice *dev;
Simon Glassdd6ab882014-02-26 15:59:18 -070042 struct uclass *uc;
Przemyslaw Marczakd850e672015-04-15 13:07:18 +020043 int size, ret = 0;
Simon Glassdd6ab882014-02-26 15:59:18 -070044
Masahiro Yamadae1cc1f02015-08-27 12:44:28 +090045 if (devp)
46 *devp = NULL;
Simon Glassdd6ab882014-02-26 15:59:18 -070047 if (!name)
48 return -EINVAL;
49
50 ret = uclass_get(drv->id, &uc);
Simon Glass43313de2015-08-30 16:55:16 -060051 if (ret) {
52 debug("Missing uclass for driver %s\n", drv->name);
Simon Glassdd6ab882014-02-26 15:59:18 -070053 return ret;
Simon Glass43313de2015-08-30 16:55:16 -060054 }
Simon Glassdd6ab882014-02-26 15:59:18 -070055
Heiko Schocherb74fcb42014-05-22 12:43:05 +020056 dev = calloc(1, sizeof(struct udevice));
Simon Glassdd6ab882014-02-26 15:59:18 -070057 if (!dev)
58 return -ENOMEM;
59
60 INIT_LIST_HEAD(&dev->sibling_node);
61 INIT_LIST_HEAD(&dev->child_head);
62 INIT_LIST_HEAD(&dev->uclass_node);
Masahiro Yamada029bfca2015-07-25 21:52:37 +090063#ifdef CONFIG_DEVRES
Masahiro Yamada8b15b162015-07-25 21:52:35 +090064 INIT_LIST_HEAD(&dev->devres_head);
Masahiro Yamada029bfca2015-07-25 21:52:37 +090065#endif
Simon Glassdd6ab882014-02-26 15:59:18 -070066 dev->platdata = platdata;
Stephen Warren8c93df12016-05-11 15:26:24 -060067 dev->driver_data = driver_data;
Simon Glassdd6ab882014-02-26 15:59:18 -070068 dev->name = name;
Simon Glassb0cf4b32017-05-17 17:18:11 -060069 dev->node = node;
Simon Glassdd6ab882014-02-26 15:59:18 -070070 dev->parent = parent;
71 dev->driver = drv;
72 dev->uclass = uc;
Simon Glassdb6f0202014-07-23 06:55:12 -060073
Simon Glassdb6f0202014-07-23 06:55:12 -060074 dev->seq = -1;
Simon Glass0ccb0972015-01-25 08:27:05 -070075 dev->req_seq = -1;
Jean-Jacques Hiblota5da3002018-12-07 14:50:39 +010076 if (CONFIG_IS_ENABLED(DM_SEQ_ALIAS) &&
77 (uc->uc_drv->flags & DM_UC_FLAG_SEQ_ALIAS)) {
Simon Glass1bd3deb2015-02-27 22:06:30 -070078 /*
Stefan Roese9d4ce6b2016-03-16 09:58:01 +010079 * Some devices, such as a SPI bus, I2C bus and serial ports
80 * are numbered using aliases.
81 *
82 * This is just a 'requested' sequence, and will be
83 * resolved (and ->seq updated) when the device is probed.
84 */
Simon Glasse422f8c2020-07-09 18:39:24 -060085 if (CONFIG_IS_ENABLED(OF_CONTROL) &&
86 !CONFIG_IS_ENABLED(OF_PLATDATA)) {
Jean-Jacques Hiblota5da3002018-12-07 14:50:39 +010087 if (uc->uc_drv->name && ofnode_valid(node))
Simon Glass322b2902017-05-18 20:09:05 -060088 dev_read_alias_seq(dev, &dev->req_seq);
Thomas Fitzsimmonsf327ecb2019-09-06 07:51:18 -040089#if CONFIG_IS_ENABLED(OF_PRIOR_STAGE)
90 if (dev->req_seq == -1)
91 dev->req_seq =
92 uclass_find_next_free_req_seq(drv->id);
93#endif
Jean-Jacques Hiblota5da3002018-12-07 14:50:39 +010094 } else {
95 dev->req_seq = uclass_find_next_free_req_seq(drv->id);
Simon Glass0ccb0972015-01-25 08:27:05 -070096 }
Simon Glassdb6f0202014-07-23 06:55:12 -060097 }
Simon Glass1bd3deb2015-02-27 22:06:30 -070098
Simon Glassafbf9b82016-07-04 11:58:18 -060099 if (drv->platdata_auto_alloc_size) {
100 bool alloc = !platdata;
101
102 if (CONFIG_IS_ENABLED(OF_PLATDATA)) {
103 if (of_platdata_size) {
104 dev->flags |= DM_FLAG_OF_PLATDATA;
105 if (of_platdata_size <
106 drv->platdata_auto_alloc_size)
107 alloc = true;
108 }
109 }
110 if (alloc) {
111 dev->flags |= DM_FLAG_ALLOC_PDATA;
112 dev->platdata = calloc(1,
113 drv->platdata_auto_alloc_size);
114 if (!dev->platdata) {
115 ret = -ENOMEM;
116 goto fail_alloc1;
117 }
118 if (CONFIG_IS_ENABLED(OF_PLATDATA) && platdata) {
119 memcpy(dev->platdata, platdata,
120 of_platdata_size);
121 }
Simon Glassba750492015-01-25 08:27:00 -0700122 }
123 }
Przemyslaw Marczakd850e672015-04-15 13:07:18 +0200124
125 size = uc->uc_drv->per_device_platdata_auto_alloc_size;
126 if (size) {
127 dev->flags |= DM_FLAG_ALLOC_UCLASS_PDATA;
128 dev->uclass_platdata = calloc(1, size);
129 if (!dev->uclass_platdata) {
130 ret = -ENOMEM;
131 goto fail_alloc2;
132 }
133 }
Simon Glass11b61732015-01-25 08:27:01 -0700134
Przemyslaw Marczakd850e672015-04-15 13:07:18 +0200135 if (parent) {
136 size = parent->driver->per_child_platdata_auto_alloc_size;
Simon Glass57f95402015-01-25 08:27:02 -0700137 if (!size) {
138 size = parent->uclass->uc_drv->
139 per_child_platdata_auto_alloc_size;
140 }
Simon Glass11b61732015-01-25 08:27:01 -0700141 if (size) {
142 dev->flags |= DM_FLAG_ALLOC_PARENT_PDATA;
143 dev->parent_platdata = calloc(1, size);
144 if (!dev->parent_platdata) {
145 ret = -ENOMEM;
Przemyslaw Marczakd850e672015-04-15 13:07:18 +0200146 goto fail_alloc3;
Simon Glass11b61732015-01-25 08:27:01 -0700147 }
148 }
Heinrich Schuchardt5246b372020-02-15 21:38:48 +0100149 /* put dev into parent's successor list */
Simon Glassdd6ab882014-02-26 15:59:18 -0700150 list_add_tail(&dev->sibling_node, &parent->child_head);
Heinrich Schuchardt5246b372020-02-15 21:38:48 +0100151 }
Simon Glassdd6ab882014-02-26 15:59:18 -0700152
153 ret = uclass_bind_device(dev);
154 if (ret)
Simon Glass4ebe01b2015-01-25 08:26:59 -0700155 goto fail_uclass_bind;
Simon Glassdd6ab882014-02-26 15:59:18 -0700156
157 /* if we fail to bind we remove device from successors and free it */
158 if (drv->bind) {
159 ret = drv->bind(dev);
Simon Glass4ebe01b2015-01-25 08:26:59 -0700160 if (ret)
Simon Glassdd6ab882014-02-26 15:59:18 -0700161 goto fail_bind;
Simon Glassdd6ab882014-02-26 15:59:18 -0700162 }
Simon Glassa4a51a02015-01-25 08:27:03 -0700163 if (parent && parent->driver->child_post_bind) {
164 ret = parent->driver->child_post_bind(dev);
165 if (ret)
166 goto fail_child_post_bind;
167 }
Simon Glass286863d2016-01-05 09:30:59 -0700168 if (uc->uc_drv->post_bind) {
169 ret = uc->uc_drv->post_bind(dev);
170 if (ret)
171 goto fail_uclass_post_bind;
172 }
Simon Glassa4a51a02015-01-25 08:27:03 -0700173
Simon Glassdd6ab882014-02-26 15:59:18 -0700174 if (parent)
Masahiro Yamadaf70f39f2017-09-29 12:31:20 +0900175 pr_debug("Bound device %s to %s\n", dev->name, parent->name);
Masahiro Yamadae1cc1f02015-08-27 12:44:28 +0900176 if (devp)
177 *devp = dev;
Simon Glassdd6ab882014-02-26 15:59:18 -0700178
Masahiro Yamadabdbb5dd2015-07-25 21:52:34 +0900179 dev->flags |= DM_FLAG_BOUND;
180
Simon Glassdd6ab882014-02-26 15:59:18 -0700181 return 0;
182
Simon Glass286863d2016-01-05 09:30:59 -0700183fail_uclass_post_bind:
184 /* There is no child unbind() method, so no clean-up required */
Simon Glassa4a51a02015-01-25 08:27:03 -0700185fail_child_post_bind:
Masahiro Yamada04aa00d2015-08-12 07:31:52 +0900186 if (CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)) {
Simon Glasse70a4f42015-02-27 22:06:33 -0700187 if (drv->unbind && drv->unbind(dev)) {
188 dm_warn("unbind() method failed on dev '%s' on error path\n",
189 dev->name);
190 }
Simon Glassa4a51a02015-01-25 08:27:03 -0700191 }
192
Simon Glassdd6ab882014-02-26 15:59:18 -0700193fail_bind:
Masahiro Yamada04aa00d2015-08-12 07:31:52 +0900194 if (CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)) {
Simon Glasse70a4f42015-02-27 22:06:33 -0700195 if (uclass_unbind_device(dev)) {
196 dm_warn("Failed to unbind dev '%s' on error path\n",
197 dev->name);
198 }
Simon Glass4ebe01b2015-01-25 08:26:59 -0700199 }
200fail_uclass_bind:
Masahiro Yamada04aa00d2015-08-12 07:31:52 +0900201 if (CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)) {
Simon Glasse70a4f42015-02-27 22:06:33 -0700202 list_del(&dev->sibling_node);
203 if (dev->flags & DM_FLAG_ALLOC_PARENT_PDATA) {
204 free(dev->parent_platdata);
205 dev->parent_platdata = NULL;
206 }
Simon Glass11b61732015-01-25 08:27:01 -0700207 }
Przemyslaw Marczakd850e672015-04-15 13:07:18 +0200208fail_alloc3:
209 if (dev->flags & DM_FLAG_ALLOC_UCLASS_PDATA) {
210 free(dev->uclass_platdata);
211 dev->uclass_platdata = NULL;
212 }
Simon Glass11b61732015-01-25 08:27:01 -0700213fail_alloc2:
Simon Glassba750492015-01-25 08:27:00 -0700214 if (dev->flags & DM_FLAG_ALLOC_PDATA) {
215 free(dev->platdata);
216 dev->platdata = NULL;
217 }
218fail_alloc1:
Masahiro Yamada8b15b162015-07-25 21:52:35 +0900219 devres_release_all(dev);
220
Simon Glassdd6ab882014-02-26 15:59:18 -0700221 free(dev);
Simon Glass4ebe01b2015-01-25 08:26:59 -0700222
Simon Glassdd6ab882014-02-26 15:59:18 -0700223 return ret;
224}
225
Stephen Warren8c93df12016-05-11 15:26:24 -0600226int device_bind_with_driver_data(struct udevice *parent,
227 const struct driver *drv, const char *name,
Simon Glass322b2902017-05-18 20:09:05 -0600228 ulong driver_data, ofnode node,
Stephen Warren8c93df12016-05-11 15:26:24 -0600229 struct udevice **devp)
230{
Simon Glass322b2902017-05-18 20:09:05 -0600231 return device_bind_common(parent, drv, name, NULL, driver_data, node,
232 0, devp);
Stephen Warren8c93df12016-05-11 15:26:24 -0600233}
234
235int device_bind(struct udevice *parent, const struct driver *drv,
236 const char *name, void *platdata, int of_offset,
237 struct udevice **devp)
238{
Simon Glassb0cf4b32017-05-17 17:18:11 -0600239 return device_bind_common(parent, drv, name, platdata, 0,
240 offset_to_ofnode(of_offset), 0, devp);
Stephen Warren8c93df12016-05-11 15:26:24 -0600241}
242
Simon Glass9eb151e2018-06-11 13:07:15 -0600243int device_bind_ofnode(struct udevice *parent, const struct driver *drv,
244 const char *name, void *platdata, ofnode node,
245 struct udevice **devp)
246{
247 return device_bind_common(parent, drv, name, platdata, 0, node, 0,
248 devp);
249}
250
Simon Glassfef72b72014-07-23 06:55:03 -0600251int device_bind_by_name(struct udevice *parent, bool pre_reloc_only,
Simon Glasscfd6a002020-10-03 11:31:33 -0600252 const struct driver_info *info, struct udevice **devp)
Simon Glassdd6ab882014-02-26 15:59:18 -0700253{
254 struct driver *drv;
Simon Glassafbf9b82016-07-04 11:58:18 -0600255 uint platdata_size = 0;
Walter Lozanoffc41b02020-06-25 01:10:11 -0300256 int ret;
Simon Glassdd6ab882014-02-26 15:59:18 -0700257
258 drv = lists_driver_lookup_name(info->name);
259 if (!drv)
260 return -ENOENT;
Simon Glassfef72b72014-07-23 06:55:03 -0600261 if (pre_reloc_only && !(drv->flags & DM_FLAG_PRE_RELOC))
262 return -EPERM;
Simon Glassdd6ab882014-02-26 15:59:18 -0700263
Simon Glassafbf9b82016-07-04 11:58:18 -0600264#if CONFIG_IS_ENABLED(OF_PLATDATA)
265 platdata_size = info->platdata_size;
266#endif
Walter Lozanoffc41b02020-06-25 01:10:11 -0300267 ret = device_bind_common(parent, drv, info->name,
268 (void *)info->platdata, 0, ofnode_null(),
269 platdata_size, devp);
270 if (ret)
271 return ret;
Walter Lozanoffc41b02020-06-25 01:10:11 -0300272
273 return ret;
Simon Glassdd6ab882014-02-26 15:59:18 -0700274}
275
Claudiu Bezneabf5b8232020-09-07 17:46:33 +0300276int device_reparent(struct udevice *dev, struct udevice *new_parent)
277{
278 struct udevice *pos, *n;
279
280 assert(dev);
281 assert(new_parent);
282
283 list_for_each_entry_safe(pos, n, &dev->parent->child_head,
284 sibling_node) {
285 if (pos->driver != dev->driver)
286 continue;
287
288 list_del(&dev->sibling_node);
289 list_add_tail(&dev->sibling_node, &new_parent->child_head);
290 dev->parent = new_parent;
291
292 break;
293 }
294
295 return 0;
296}
297
Simon Glass825d3f92015-03-25 12:21:53 -0600298static void *alloc_priv(int size, uint flags)
299{
300 void *priv;
301
302 if (flags & DM_FLAG_ALLOC_PRIV_DMA) {
Faiz Abbas03020a92017-09-19 16:53:50 +0530303 size = ROUND(size, ARCH_DMA_MINALIGN);
Simon Glass825d3f92015-03-25 12:21:53 -0600304 priv = memalign(ARCH_DMA_MINALIGN, size);
Simon Glass27bc9b12017-04-04 13:00:19 -0600305 if (priv) {
Simon Glass825d3f92015-03-25 12:21:53 -0600306 memset(priv, '\0', size);
Simon Glass27bc9b12017-04-04 13:00:19 -0600307
308 /*
309 * Ensure that the zero bytes are flushed to memory.
310 * This prevents problems if the driver uses this as
311 * both an input and an output buffer:
312 *
313 * 1. Zeroes written to buffer (here) and sit in the
314 * cache
315 * 2. Driver issues a read command to DMA
316 * 3. CPU runs out of cache space and evicts some cache
317 * data in the buffer, writing zeroes to RAM from
318 * the memset() above
319 * 4. DMA completes
320 * 5. Buffer now has some DMA data and some zeroes
321 * 6. Data being read is now incorrect
322 *
323 * To prevent this, ensure that the cache is clean
324 * within this range at the start. The driver can then
325 * use normal flush-after-write, invalidate-before-read
326 * procedures.
327 *
328 * TODO(sjg@chromium.org): Drop this microblaze
329 * exception.
330 */
331#ifndef CONFIG_MICROBLAZE
332 flush_dcache_range((ulong)priv, (ulong)priv + size);
333#endif
334 }
Simon Glass825d3f92015-03-25 12:21:53 -0600335 } else {
336 priv = calloc(1, size);
337 }
338
339 return priv;
340}
341
Simon Glass4a263852019-12-29 21:19:20 -0700342int device_ofdata_to_platdata(struct udevice *dev)
Simon Glassdd6ab882014-02-26 15:59:18 -0700343{
Simon Glassa626dff2015-03-25 12:21:54 -0600344 const struct driver *drv;
Simon Glassdd6ab882014-02-26 15:59:18 -0700345 int size = 0;
346 int ret;
347
348 if (!dev)
349 return -EINVAL;
350
Simon Glassd3c9d302019-12-29 21:19:21 -0700351 if (dev->flags & DM_FLAG_PLATDATA_VALID)
Simon Glassdd6ab882014-02-26 15:59:18 -0700352 return 0;
353
Simon Glass44c47892020-04-05 15:38:19 -0600354 /* Ensure all parents have ofdata */
355 if (dev->parent) {
356 ret = device_ofdata_to_platdata(dev->parent);
357 if (ret)
358 goto fail;
359
360 /*
361 * The device might have already been probed during
362 * the call to device_probe() on its parent device
363 * (e.g. PCI bridge devices). Test the flags again
364 * so that we don't mess up the device.
365 */
366 if (dev->flags & DM_FLAG_PLATDATA_VALID)
367 return 0;
368 }
369
Simon Glassdd6ab882014-02-26 15:59:18 -0700370 drv = dev->driver;
371 assert(drv);
372
Bin Meng82cdd782015-08-24 01:14:02 -0700373 /* Allocate private data if requested and not reentered */
374 if (drv->priv_auto_alloc_size && !dev->priv) {
Simon Glass825d3f92015-03-25 12:21:53 -0600375 dev->priv = alloc_priv(drv->priv_auto_alloc_size, drv->flags);
Simon Glassdd6ab882014-02-26 15:59:18 -0700376 if (!dev->priv) {
377 ret = -ENOMEM;
378 goto fail;
379 }
380 }
Bin Meng82cdd782015-08-24 01:14:02 -0700381 /* Allocate private data if requested and not reentered */
Simon Glassdd6ab882014-02-26 15:59:18 -0700382 size = dev->uclass->uc_drv->per_device_auto_alloc_size;
Bin Meng82cdd782015-08-24 01:14:02 -0700383 if (size && !dev->uclass_priv) {
Simon Glass7ebd13d2018-10-01 12:22:05 -0600384 dev->uclass_priv = alloc_priv(size,
385 dev->uclass->uc_drv->flags);
Simon Glassdd6ab882014-02-26 15:59:18 -0700386 if (!dev->uclass_priv) {
387 ret = -ENOMEM;
388 goto fail;
389 }
390 }
391
Simon Glassa8d8f162019-12-29 21:19:18 -0700392 /* Allocate parent data for this child */
Simon Glassdd6ab882014-02-26 15:59:18 -0700393 if (dev->parent) {
Simon Glass60d971b2014-07-23 06:55:20 -0600394 size = dev->parent->driver->per_child_auto_alloc_size;
Simon Glassc23b4282015-01-25 08:27:06 -0700395 if (!size) {
396 size = dev->parent->uclass->uc_drv->
397 per_child_auto_alloc_size;
398 }
Bin Meng82cdd782015-08-24 01:14:02 -0700399 if (size && !dev->parent_priv) {
Simon Glass825d3f92015-03-25 12:21:53 -0600400 dev->parent_priv = alloc_priv(size, drv->flags);
Simon Glass60d971b2014-07-23 06:55:20 -0600401 if (!dev->parent_priv) {
402 ret = -ENOMEM;
403 goto fail;
404 }
405 }
Simon Glassa8d8f162019-12-29 21:19:18 -0700406 }
407
408 if (drv->ofdata_to_platdata &&
409 (CONFIG_IS_ENABLED(OF_PLATDATA) || dev_has_of_node(dev))) {
410 ret = drv->ofdata_to_platdata(dev);
411 if (ret)
412 goto fail;
413 }
Simon Glass60d971b2014-07-23 06:55:20 -0600414
Simon Glassd3c9d302019-12-29 21:19:21 -0700415 dev->flags |= DM_FLAG_PLATDATA_VALID;
416
Simon Glass4a263852019-12-29 21:19:20 -0700417 return 0;
418fail:
419 device_free(dev);
420
421 return ret;
422}
423
424int device_probe(struct udevice *dev)
425{
426 const struct driver *drv;
427 int ret;
428 int seq;
429
430 if (!dev)
431 return -EINVAL;
432
433 if (dev->flags & DM_FLAG_ACTIVATED)
434 return 0;
435
436 drv = dev->driver;
437 assert(drv);
438
439 ret = device_ofdata_to_platdata(dev);
440 if (ret)
441 goto fail;
442
Simon Glassa8d8f162019-12-29 21:19:18 -0700443 /* Ensure all parents are probed */
444 if (dev->parent) {
Simon Glassdd6ab882014-02-26 15:59:18 -0700445 ret = device_probe(dev->parent);
446 if (ret)
447 goto fail;
Bin Meng82cdd782015-08-24 01:14:02 -0700448
449 /*
450 * The device might have already been probed during
451 * the call to device_probe() on its parent device
452 * (e.g. PCI bridge devices). Test the flags again
453 * so that we don't mess up the device.
454 */
455 if (dev->flags & DM_FLAG_ACTIVATED)
456 return 0;
Simon Glassdd6ab882014-02-26 15:59:18 -0700457 }
Simon Glassdb6f0202014-07-23 06:55:12 -0600458
459 seq = uclass_resolve_seq(dev);
460 if (seq < 0) {
461 ret = seq;
462 goto fail;
463 }
464 dev->seq = seq;
Simon Glassdd6ab882014-02-26 15:59:18 -0700465
Simon Glass8b04e732015-03-25 12:21:56 -0600466 dev->flags |= DM_FLAG_ACTIVATED;
467
Simon Glassbb53bda2015-09-12 08:45:19 -0600468 /*
469 * Process pinctrl for everything except the root device, and
Simon Glass27ce9622016-01-21 19:43:25 -0700470 * continue regardless of the result of pinctrl. Don't process pinctrl
471 * settings for pinctrl devices since the device may not yet be
472 * probed.
Simon Glassbb53bda2015-09-12 08:45:19 -0600473 */
Simon Glass27ce9622016-01-21 19:43:25 -0700474 if (dev->parent && device_get_uclass_id(dev) != UCLASS_PINCTRL)
Simon Glassbb53bda2015-09-12 08:45:19 -0600475 pinctrl_select_state(dev, "default");
Masahiro Yamadaf8efa632015-08-27 12:44:29 +0900476
Anatolij Gustschin63a34672019-07-14 21:11:01 +0200477 if (CONFIG_IS_ENABLED(POWER_DOMAIN) && dev->parent &&
Lokesh Vutlac10e52b2019-09-27 13:48:12 +0530478 (device_get_uclass_id(dev) != UCLASS_POWER_DOMAIN) &&
479 !(drv->flags & DM_FLAG_DEFAULT_PD_CTRL_OFF)) {
Peng Fand2201112019-09-17 09:29:22 +0000480 ret = dev_power_domain_on(dev);
481 if (ret)
482 goto fail;
Peng Fan6fba32d2018-07-27 10:20:38 +0800483 }
484
Simon Glass9c1f3822015-03-05 12:25:22 -0700485 ret = uclass_pre_probe_device(dev);
Simon Glass5104b982015-01-25 08:27:10 -0700486 if (ret)
487 goto fail;
488
Simon Glassd45560d2014-07-23 06:55:21 -0600489 if (dev->parent && dev->parent->driver->child_pre_probe) {
490 ret = dev->parent->driver->child_pre_probe(dev);
491 if (ret)
492 goto fail;
493 }
494
Bin Meng513cf402019-07-05 09:23:16 -0700495 /* Only handle devices that have a valid ofnode */
496 if (dev_of_valid(dev)) {
497 /*
498 * Process 'assigned-{clocks/clock-parents/clock-rates}'
499 * properties
500 */
Jean-Jacques Hiblot9601f322019-10-22 14:00:06 +0200501 ret = clk_set_defaults(dev, 0);
Bin Meng513cf402019-07-05 09:23:16 -0700502 if (ret)
503 goto fail;
504 }
Philipp Tomsich9cf03b02018-01-08 13:59:18 +0100505
Simon Glassdd6ab882014-02-26 15:59:18 -0700506 if (drv->probe) {
507 ret = drv->probe(dev);
Simon Glass9046dec2019-12-29 21:19:16 -0700508 if (ret)
Simon Glassdd6ab882014-02-26 15:59:18 -0700509 goto fail;
510 }
511
Simon Glassdd6ab882014-02-26 15:59:18 -0700512 ret = uclass_post_probe_device(dev);
Simon Glass8b04e732015-03-25 12:21:56 -0600513 if (ret)
Simon Glassdd6ab882014-02-26 15:59:18 -0700514 goto fail_uclass;
Simon Glassdd6ab882014-02-26 15:59:18 -0700515
Peng Fan7cf58dd2016-03-12 13:17:38 +0800516 if (dev->parent && device_get_uclass_id(dev) == UCLASS_PINCTRL)
517 pinctrl_select_state(dev, "default");
518
Simon Glassdd6ab882014-02-26 15:59:18 -0700519 return 0;
520fail_uclass:
Stefan Roese80b5bc92017-03-20 12:51:48 +0100521 if (device_remove(dev, DM_REMOVE_NORMAL)) {
Simon Glassdd6ab882014-02-26 15:59:18 -0700522 dm_warn("%s: Device '%s' failed to remove on error path\n",
523 __func__, dev->name);
524 }
525fail:
Simon Glass8b04e732015-03-25 12:21:56 -0600526 dev->flags &= ~DM_FLAG_ACTIVATED;
527
Simon Glassdb6f0202014-07-23 06:55:12 -0600528 dev->seq = -1;
Simon Glassdd6ab882014-02-26 15:59:18 -0700529 device_free(dev);
530
531 return ret;
532}
533
Simon Glass2e5e5ec2018-10-01 12:22:06 -0600534void *dev_get_platdata(const struct udevice *dev)
Simon Glassdd6ab882014-02-26 15:59:18 -0700535{
536 if (!dev) {
Simon Glassdf1e0722014-12-10 08:55:56 -0700537 dm_warn("%s: null device\n", __func__);
Simon Glassdd6ab882014-02-26 15:59:18 -0700538 return NULL;
539 }
540
541 return dev->platdata;
542}
543
Simon Glass2e5e5ec2018-10-01 12:22:06 -0600544void *dev_get_parent_platdata(const struct udevice *dev)
Simon Glass11b61732015-01-25 08:27:01 -0700545{
546 if (!dev) {
Simon Glasscdfc5052015-07-06 16:47:40 -0600547 dm_warn("%s: null device\n", __func__);
Simon Glass11b61732015-01-25 08:27:01 -0700548 return NULL;
549 }
550
551 return dev->parent_platdata;
552}
553
Simon Glass2e5e5ec2018-10-01 12:22:06 -0600554void *dev_get_uclass_platdata(const struct udevice *dev)
Przemyslaw Marczakd850e672015-04-15 13:07:18 +0200555{
556 if (!dev) {
Simon Glasscdfc5052015-07-06 16:47:40 -0600557 dm_warn("%s: null device\n", __func__);
Przemyslaw Marczakd850e672015-04-15 13:07:18 +0200558 return NULL;
559 }
560
561 return dev->uclass_platdata;
562}
563
Simon Glass2e5e5ec2018-10-01 12:22:06 -0600564void *dev_get_priv(const struct udevice *dev)
Simon Glassdd6ab882014-02-26 15:59:18 -0700565{
566 if (!dev) {
Simon Glassdf1e0722014-12-10 08:55:56 -0700567 dm_warn("%s: null device\n", __func__);
Simon Glassdd6ab882014-02-26 15:59:18 -0700568 return NULL;
569 }
570
571 return dev->priv;
572}
Simon Glass48d4e292014-07-23 06:55:19 -0600573
Simon Glass2e5e5ec2018-10-01 12:22:06 -0600574void *dev_get_uclass_priv(const struct udevice *dev)
Simon Glassde0977b2015-03-05 12:25:20 -0700575{
576 if (!dev) {
577 dm_warn("%s: null device\n", __func__);
578 return NULL;
579 }
580
581 return dev->uclass_priv;
582}
583
Simon Glass2e5e5ec2018-10-01 12:22:06 -0600584void *dev_get_parent_priv(const struct udevice *dev)
Simon Glass60d971b2014-07-23 06:55:20 -0600585{
586 if (!dev) {
Simon Glassdf1e0722014-12-10 08:55:56 -0700587 dm_warn("%s: null device\n", __func__);
Simon Glass60d971b2014-07-23 06:55:20 -0600588 return NULL;
589 }
590
591 return dev->parent_priv;
592}
593
Simon Glass48d4e292014-07-23 06:55:19 -0600594static int device_get_device_tail(struct udevice *dev, int ret,
595 struct udevice **devp)
596{
597 if (ret)
598 return ret;
599
600 ret = device_probe(dev);
601 if (ret)
602 return ret;
603
604 *devp = dev;
605
606 return 0;
607}
608
Marek Vasut7f18c342019-08-31 18:03:28 +0200609#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
Mario Six3bedfbe2018-06-26 08:46:50 +0200610/**
611 * device_find_by_ofnode() - Return device associated with given ofnode
612 *
613 * The returned device is *not* activated.
614 *
615 * @node: The ofnode for which a associated device should be looked up
616 * @devp: Pointer to structure to hold the found device
617 * Return: 0 if OK, -ve on error
618 */
619static int device_find_by_ofnode(ofnode node, struct udevice **devp)
620{
621 struct uclass *uc;
622 struct udevice *dev;
623 int ret;
624
625 list_for_each_entry(uc, &gd->uclass_root, sibling_node) {
626 ret = uclass_find_device_by_ofnode(uc->uc_drv->id, node,
627 &dev);
628 if (!ret || dev) {
629 *devp = dev;
630 return 0;
631 }
632 }
633
634 return -ENODEV;
635}
Marek Vasut7f18c342019-08-31 18:03:28 +0200636#endif
Mario Six3bedfbe2018-06-26 08:46:50 +0200637
Simon Glass2a580882020-01-27 08:49:36 -0700638int device_get_child(const struct udevice *parent, int index,
639 struct udevice **devp)
Simon Glass48d4e292014-07-23 06:55:19 -0600640{
641 struct udevice *dev;
642
643 list_for_each_entry(dev, &parent->child_head, sibling_node) {
644 if (!index--)
645 return device_get_device_tail(dev, 0, devp);
646 }
647
648 return -ENODEV;
649}
650
Simon Glass2a580882020-01-27 08:49:36 -0700651int device_get_child_count(const struct udevice *parent)
Lokesh Vutlafa45a082019-09-04 16:01:26 +0530652{
653 struct udevice *dev;
654 int count = 0;
655
656 list_for_each_entry(dev, &parent->child_head, sibling_node)
657 count++;
658
659 return count;
660}
661
Simon Glass2a580882020-01-27 08:49:36 -0700662int device_find_child_by_seq(const struct udevice *parent, int seq_or_req_seq,
Simon Glass48d4e292014-07-23 06:55:19 -0600663 bool find_req_seq, struct udevice **devp)
664{
665 struct udevice *dev;
666
667 *devp = NULL;
668 if (seq_or_req_seq == -1)
669 return -ENODEV;
670
671 list_for_each_entry(dev, &parent->child_head, sibling_node) {
672 if ((find_req_seq ? dev->req_seq : dev->seq) ==
673 seq_or_req_seq) {
674 *devp = dev;
675 return 0;
676 }
677 }
678
679 return -ENODEV;
680}
681
Simon Glass2a580882020-01-27 08:49:36 -0700682int device_get_child_by_seq(const struct udevice *parent, int seq,
Simon Glass48d4e292014-07-23 06:55:19 -0600683 struct udevice **devp)
684{
685 struct udevice *dev;
686 int ret;
687
688 *devp = NULL;
689 ret = device_find_child_by_seq(parent, seq, false, &dev);
690 if (ret == -ENODEV) {
691 /*
692 * We didn't find it in probed devices. See if there is one
693 * that will request this seq if probed.
694 */
695 ret = device_find_child_by_seq(parent, seq, true, &dev);
696 }
697 return device_get_device_tail(dev, ret, devp);
698}
699
Simon Glass2a580882020-01-27 08:49:36 -0700700int device_find_child_by_of_offset(const struct udevice *parent, int of_offset,
Simon Glass48d4e292014-07-23 06:55:19 -0600701 struct udevice **devp)
702{
703 struct udevice *dev;
704
705 *devp = NULL;
706
707 list_for_each_entry(dev, &parent->child_head, sibling_node) {
Simon Glassdd79d6e2017-01-17 16:52:55 -0700708 if (dev_of_offset(dev) == of_offset) {
Simon Glass48d4e292014-07-23 06:55:19 -0600709 *devp = dev;
710 return 0;
711 }
712 }
713
714 return -ENODEV;
715}
716
Simon Glass2a580882020-01-27 08:49:36 -0700717int device_get_child_by_of_offset(const struct udevice *parent, int node,
Simon Glass48d4e292014-07-23 06:55:19 -0600718 struct udevice **devp)
719{
720 struct udevice *dev;
721 int ret;
722
723 *devp = NULL;
Simon Glass861bc9f2015-06-23 15:38:38 -0600724 ret = device_find_child_by_of_offset(parent, node, &dev);
Simon Glass48d4e292014-07-23 06:55:19 -0600725 return device_get_device_tail(dev, ret, devp);
726}
Simon Glass44da7352014-10-13 23:41:49 -0600727
Jean-Jacques Hiblota7b0d6a2018-08-09 16:17:44 +0200728static struct udevice *_device_find_global_by_ofnode(struct udevice *parent,
729 ofnode ofnode)
Simon Glassae2efac2015-06-23 15:38:37 -0600730{
731 struct udevice *dev, *found;
732
Jean-Jacques Hiblota7b0d6a2018-08-09 16:17:44 +0200733 if (ofnode_equal(dev_ofnode(parent), ofnode))
Simon Glassae2efac2015-06-23 15:38:37 -0600734 return parent;
735
736 list_for_each_entry(dev, &parent->child_head, sibling_node) {
Jean-Jacques Hiblota7b0d6a2018-08-09 16:17:44 +0200737 found = _device_find_global_by_ofnode(dev, ofnode);
Simon Glassae2efac2015-06-23 15:38:37 -0600738 if (found)
739 return found;
740 }
741
742 return NULL;
743}
744
Jean-Jacques Hiblota7b0d6a2018-08-09 16:17:44 +0200745int device_find_global_by_ofnode(ofnode ofnode, struct udevice **devp)
746{
747 *devp = _device_find_global_by_ofnode(gd->dm_root, ofnode);
748
749 return *devp ? 0 : -ENOENT;
750}
751
752int device_get_global_by_ofnode(ofnode ofnode, struct udevice **devp)
Simon Glassae2efac2015-06-23 15:38:37 -0600753{
754 struct udevice *dev;
755
Jean-Jacques Hiblota7b0d6a2018-08-09 16:17:44 +0200756 dev = _device_find_global_by_ofnode(gd->dm_root, ofnode);
Simon Glassae2efac2015-06-23 15:38:37 -0600757 return device_get_device_tail(dev, dev ? 0 : -ENOENT, devp);
758}
Walter Lozanoffc41b02020-06-25 01:10:11 -0300759
760#if CONFIG_IS_ENABLED(OF_PLATDATA)
761int device_get_by_driver_info(const struct driver_info *info,
762 struct udevice **devp)
763{
Simon Glasscfd6a002020-10-03 11:31:33 -0600764 struct driver_info *info_base =
765 ll_entry_start(struct driver_info, driver_info);
766 int idx = info - info_base;
767 struct driver_rt *drt = gd_dm_driver_rt() + idx;
Walter Lozanoffc41b02020-06-25 01:10:11 -0300768 struct udevice *dev;
769
Simon Glasscfd6a002020-10-03 11:31:33 -0600770 dev = drt->dev;
Simon Glassd825ea72020-10-03 11:31:31 -0600771 *devp = NULL;
Walter Lozanoffc41b02020-06-25 01:10:11 -0300772
773 return device_get_device_tail(dev, dev ? 0 : -ENOENT, devp);
774}
Simon Glass5792f4b2020-10-03 11:31:40 -0600775
776int device_get_by_driver_info_idx(uint idx, struct udevice **devp)
777{
778 struct driver_rt *drt = gd_dm_driver_rt() + idx;
779 struct udevice *dev;
780
781 dev = drt->dev;
782 *devp = NULL;
783
784 return device_get_device_tail(dev, dev ? 0 : -ENOENT, devp);
785}
Walter Lozanoffc41b02020-06-25 01:10:11 -0300786#endif
Simon Glassae2efac2015-06-23 15:38:37 -0600787
Simon Glass2a580882020-01-27 08:49:36 -0700788int device_find_first_child(const struct udevice *parent, struct udevice **devp)
Simon Glass44da7352014-10-13 23:41:49 -0600789{
790 if (list_empty(&parent->child_head)) {
791 *devp = NULL;
792 } else {
793 *devp = list_first_entry(&parent->child_head, struct udevice,
794 sibling_node);
795 }
796
797 return 0;
798}
799
800int device_find_next_child(struct udevice **devp)
801{
802 struct udevice *dev = *devp;
803 struct udevice *parent = dev->parent;
804
805 if (list_is_last(&dev->sibling_node, &parent->child_head)) {
806 *devp = NULL;
807 } else {
808 *devp = list_entry(dev->sibling_node.next, struct udevice,
809 sibling_node);
810 }
811
812 return 0;
813}
Simon Glass70c3a0e2014-11-11 10:46:18 -0700814
Simon Glass2a580882020-01-27 08:49:36 -0700815int device_find_first_inactive_child(const struct udevice *parent,
Simon Glassb775e872018-10-01 12:22:07 -0600816 enum uclass_id uclass_id,
817 struct udevice **devp)
818{
819 struct udevice *dev;
820
821 *devp = NULL;
822 list_for_each_entry(dev, &parent->child_head, sibling_node) {
823 if (!device_active(dev) &&
824 device_get_uclass_id(dev) == uclass_id) {
825 *devp = dev;
826 return 0;
827 }
828 }
829
830 return -ENODEV;
831}
832
Simon Glass2a580882020-01-27 08:49:36 -0700833int device_find_first_child_by_uclass(const struct udevice *parent,
Simon Glassa11341a2018-11-18 08:14:31 -0700834 enum uclass_id uclass_id,
835 struct udevice **devp)
836{
837 struct udevice *dev;
838
839 *devp = NULL;
840 list_for_each_entry(dev, &parent->child_head, sibling_node) {
841 if (device_get_uclass_id(dev) == uclass_id) {
842 *devp = dev;
843 return 0;
844 }
845 }
846
847 return -ENODEV;
848}
849
Simon Glass2a580882020-01-27 08:49:36 -0700850int device_find_child_by_name(const struct udevice *parent, const char *name,
Simon Glassa11341a2018-11-18 08:14:31 -0700851 struct udevice **devp)
852{
853 struct udevice *dev;
854
855 *devp = NULL;
856
857 list_for_each_entry(dev, &parent->child_head, sibling_node) {
858 if (!strcmp(dev->name, name)) {
859 *devp = dev;
860 return 0;
861 }
862 }
863
864 return -ENODEV;
865}
866
Simon Glass76db9b72020-01-27 08:49:48 -0700867int device_first_child_err(struct udevice *parent, struct udevice **devp)
868{
869 struct udevice *dev;
870
871 device_find_first_child(parent, &dev);
872 if (!dev)
873 return -ENODEV;
874
875 return device_get_device_tail(dev, 0, devp);
876}
877
878int device_next_child_err(struct udevice **devp)
879{
880 struct udevice *dev = *devp;
881
882 device_find_next_child(&dev);
883 if (!dev)
884 return -ENODEV;
885
886 return device_get_device_tail(dev, 0, devp);
887}
888
Simon Glass000676b2020-01-27 08:49:47 -0700889int device_first_child_ofdata_err(struct udevice *parent, struct udevice **devp)
890{
891 struct udevice *dev;
892 int ret;
893
894 device_find_first_child(parent, &dev);
895 if (!dev)
896 return -ENODEV;
897
898 ret = device_ofdata_to_platdata(dev);
899 if (ret)
900 return ret;
901
902 *devp = dev;
903
904 return 0;
905}
906
907int device_next_child_ofdata_err(struct udevice **devp)
908{
909 struct udevice *dev = *devp;
910 int ret;
911
912 device_find_next_child(&dev);
913 if (!dev)
914 return -ENODEV;
915
916 ret = device_ofdata_to_platdata(dev);
917 if (ret)
918 return ret;
919
920 *devp = dev;
921
922 return 0;
923}
924
Simon Glass2e5e5ec2018-10-01 12:22:06 -0600925struct udevice *dev_get_parent(const struct udevice *child)
Simon Glass43f488a2014-11-11 10:46:19 -0700926{
927 return child->parent;
928}
929
Simon Glass2e5e5ec2018-10-01 12:22:06 -0600930ulong dev_get_driver_data(const struct udevice *dev)
Simon Glass70c3a0e2014-11-11 10:46:18 -0700931{
Simon Glass46227bd2015-03-25 12:21:55 -0600932 return dev->driver_data;
Simon Glass70c3a0e2014-11-11 10:46:18 -0700933}
Simon Glass98fd5d12015-01-25 08:27:04 -0700934
Simon Glass2e5e5ec2018-10-01 12:22:06 -0600935const void *dev_get_driver_ops(const struct udevice *dev)
Przemyslaw Marczakd3ef0d72015-04-15 13:07:24 +0200936{
937 if (!dev || !dev->driver->ops)
938 return NULL;
939
940 return dev->driver->ops;
941}
942
Simon Glass2e5e5ec2018-10-01 12:22:06 -0600943enum uclass_id device_get_uclass_id(const struct udevice *dev)
Simon Glass98fd5d12015-01-25 08:27:04 -0700944{
945 return dev->uclass->uc_drv->id;
946}
Peng Fan99b72352015-02-10 14:46:32 +0800947
Simon Glass2e5e5ec2018-10-01 12:22:06 -0600948const char *dev_get_uclass_name(const struct udevice *dev)
Przemyslaw Marczak5ed2e422015-04-15 13:07:25 +0200949{
950 if (!dev)
951 return NULL;
952
953 return dev->uclass->uc_drv->name;
954}
955
Simon Glass2e5e5ec2018-10-01 12:22:06 -0600956bool device_has_children(const struct udevice *dev)
Simon Glass40f829a2015-03-25 12:21:57 -0600957{
958 return !list_empty(&dev->child_head);
959}
960
Simon Glass2a580882020-01-27 08:49:36 -0700961bool device_has_active_children(const struct udevice *dev)
Simon Glass40f829a2015-03-25 12:21:57 -0600962{
963 struct udevice *child;
964
965 for (device_find_first_child(dev, &child);
966 child;
967 device_find_next_child(&child)) {
968 if (device_active(child))
969 return true;
970 }
971
972 return false;
973}
974
Simon Glass2a580882020-01-27 08:49:36 -0700975bool device_is_last_sibling(const struct udevice *dev)
Simon Glass40f829a2015-03-25 12:21:57 -0600976{
977 struct udevice *parent = dev->parent;
978
979 if (!parent)
980 return false;
981 return list_is_last(&dev->sibling_node, &parent->child_head);
982}
Simon Glasse3b23e22015-07-30 13:40:39 -0600983
Simon Glass7760ba22016-05-01 13:52:23 -0600984void device_set_name_alloced(struct udevice *dev)
985{
Simon Glass2d4c7dc2016-07-04 11:58:15 -0600986 dev->flags |= DM_FLAG_NAME_ALLOCED;
Simon Glass7760ba22016-05-01 13:52:23 -0600987}
988
Simon Glasse3b23e22015-07-30 13:40:39 -0600989int device_set_name(struct udevice *dev, const char *name)
990{
991 name = strdup(name);
992 if (!name)
993 return -ENOMEM;
994 dev->name = name;
Simon Glass7760ba22016-05-01 13:52:23 -0600995 device_set_name_alloced(dev);
Simon Glasse3b23e22015-07-30 13:40:39 -0600996
997 return 0;
998}
Mugunthan V N4666bd92016-04-28 15:36:02 +0530999
Marek Vasut7f18c342019-08-31 18:03:28 +02001000#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
Simon Glass2a580882020-01-27 08:49:36 -07001001bool device_is_compatible(const struct udevice *dev, const char *compat)
Mugunthan V N4666bd92016-04-28 15:36:02 +05301002{
Masahiro Yamada9349bcc2018-04-19 12:14:02 +09001003 return ofnode_device_is_compatible(dev_ofnode(dev), compat);
Mugunthan V N4666bd92016-04-28 15:36:02 +05301004}
1005
1006bool of_machine_is_compatible(const char *compat)
1007{
1008 const void *fdt = gd->fdt_blob;
1009
1010 return !fdt_node_check_compatible(fdt, 0, compat);
1011}
Mario Six3bedfbe2018-06-26 08:46:50 +02001012
1013int dev_disable_by_path(const char *path)
1014{
1015 struct uclass *uc;
1016 ofnode node = ofnode_path(path);
1017 struct udevice *dev;
1018 int ret = 1;
1019
1020 if (!of_live_active())
1021 return -ENOSYS;
1022
1023 list_for_each_entry(uc, &gd->uclass_root, sibling_node) {
1024 ret = uclass_find_device_by_ofnode(uc->uc_drv->id, node, &dev);
1025 if (!ret)
1026 break;
1027 }
1028
1029 if (ret)
1030 return ret;
1031
1032 ret = device_remove(dev, DM_REMOVE_NORMAL);
1033 if (ret)
1034 return ret;
1035
1036 ret = device_unbind(dev);
1037 if (ret)
1038 return ret;
1039
1040 return ofnode_set_enabled(node, false);
1041}
1042
1043int dev_enable_by_path(const char *path)
1044{
1045 ofnode node = ofnode_path(path);
1046 ofnode pnode = ofnode_get_parent(node);
1047 struct udevice *parent;
1048 int ret = 1;
1049
1050 if (!of_live_active())
1051 return -ENOSYS;
1052
1053 ret = device_find_by_ofnode(pnode, &parent);
1054 if (ret)
1055 return ret;
1056
1057 ret = ofnode_set_enabled(node, true);
1058 if (ret)
1059 return ret;
1060
Bin Meng9a9b0742018-10-10 22:06:58 -07001061 return lists_bind_fdt(parent, node, NULL, false);
Mario Six3bedfbe2018-06-26 08:46:50 +02001062}
Marek Vasut7f18c342019-08-31 18:03:28 +02001063#endif