Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 Google, Inc |
| 3 | * |
| 4 | * (C) Copyright 2012 |
| 5 | * Pavel Herrmann <morpheus.ibis@gmail.com> |
| 6 | * |
| 7 | * SPDX-License-Identifier: GPL-2.0+ |
| 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <errno.h> |
| 12 | #include <malloc.h> |
| 13 | #include <dm/device.h> |
| 14 | #include <dm/device-internal.h> |
| 15 | #include <dm/lists.h> |
| 16 | #include <dm/uclass.h> |
| 17 | #include <dm/uclass-internal.h> |
| 18 | #include <dm/util.h> |
| 19 | |
| 20 | DECLARE_GLOBAL_DATA_PTR; |
| 21 | |
| 22 | struct uclass *uclass_find(enum uclass_id key) |
| 23 | { |
| 24 | struct uclass *uc; |
| 25 | |
Simon Glass | c910e2e | 2014-07-23 06:55:15 -0600 | [diff] [blame] | 26 | if (!gd->dm_root) |
| 27 | return NULL; |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 28 | /* |
| 29 | * TODO(sjg@chromium.org): Optimise this, perhaps moving the found |
| 30 | * node to the start of the list, or creating a linear array mapping |
| 31 | * id to node. |
| 32 | */ |
| 33 | list_for_each_entry(uc, &gd->uclass_root, sibling_node) { |
| 34 | if (uc->uc_drv->id == key) |
| 35 | return uc; |
| 36 | } |
| 37 | |
| 38 | return NULL; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * uclass_add() - Create new uclass in list |
| 43 | * @id: Id number to create |
| 44 | * @ucp: Returns pointer to uclass, or NULL on error |
| 45 | * @return 0 on success, -ve on error |
| 46 | * |
| 47 | * The new uclass is added to the list. There must be only one uclass for |
| 48 | * each id. |
| 49 | */ |
| 50 | static int uclass_add(enum uclass_id id, struct uclass **ucp) |
| 51 | { |
| 52 | struct uclass_driver *uc_drv; |
| 53 | struct uclass *uc; |
| 54 | int ret; |
| 55 | |
| 56 | *ucp = NULL; |
| 57 | uc_drv = lists_uclass_lookup(id); |
| 58 | if (!uc_drv) { |
| 59 | dm_warn("Cannot find uclass for id %d: please add the UCLASS_DRIVER() declaration for this UCLASS_... id\n", |
| 60 | id); |
| 61 | return -ENOENT; |
| 62 | } |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 63 | uc = calloc(1, sizeof(*uc)); |
| 64 | if (!uc) |
| 65 | return -ENOMEM; |
| 66 | if (uc_drv->priv_auto_alloc_size) { |
| 67 | uc->priv = calloc(1, uc_drv->priv_auto_alloc_size); |
| 68 | if (!uc->priv) { |
| 69 | ret = -ENOMEM; |
| 70 | goto fail_mem; |
| 71 | } |
| 72 | } |
| 73 | uc->uc_drv = uc_drv; |
| 74 | INIT_LIST_HEAD(&uc->sibling_node); |
| 75 | INIT_LIST_HEAD(&uc->dev_head); |
Simon Glass | 89876a5 | 2014-06-11 23:29:49 -0600 | [diff] [blame] | 76 | list_add(&uc->sibling_node, &DM_UCLASS_ROOT_NON_CONST); |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 77 | |
| 78 | if (uc_drv->init) { |
| 79 | ret = uc_drv->init(uc); |
| 80 | if (ret) |
| 81 | goto fail; |
| 82 | } |
| 83 | |
| 84 | *ucp = uc; |
| 85 | |
| 86 | return 0; |
| 87 | fail: |
| 88 | if (uc_drv->priv_auto_alloc_size) { |
| 89 | free(uc->priv); |
| 90 | uc->priv = NULL; |
| 91 | } |
| 92 | list_del(&uc->sibling_node); |
| 93 | fail_mem: |
| 94 | free(uc); |
| 95 | |
| 96 | return ret; |
| 97 | } |
| 98 | |
| 99 | int uclass_destroy(struct uclass *uc) |
| 100 | { |
| 101 | struct uclass_driver *uc_drv; |
Simon Glass | 07d260e | 2015-04-19 07:20:58 -0600 | [diff] [blame] | 102 | struct udevice *dev; |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 103 | int ret; |
| 104 | |
Simon Glass | 07d260e | 2015-04-19 07:20:58 -0600 | [diff] [blame] | 105 | /* |
| 106 | * We cannot use list_for_each_entry_safe() here. If a device in this |
| 107 | * uclass has a child device also in this uclass, it will be also be |
| 108 | * unbound (by the recursion in the call to device_unbind() below). |
| 109 | * We can loop until the list is empty. |
| 110 | */ |
| 111 | while (!list_empty(&uc->dev_head)) { |
| 112 | dev = list_first_entry(&uc->dev_head, struct udevice, |
| 113 | uclass_node); |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 114 | ret = device_remove(dev); |
| 115 | if (ret) |
| 116 | return ret; |
| 117 | ret = device_unbind(dev); |
| 118 | if (ret) |
| 119 | return ret; |
| 120 | } |
| 121 | |
| 122 | uc_drv = uc->uc_drv; |
| 123 | if (uc_drv->destroy) |
| 124 | uc_drv->destroy(uc); |
| 125 | list_del(&uc->sibling_node); |
| 126 | if (uc_drv->priv_auto_alloc_size) |
| 127 | free(uc->priv); |
| 128 | free(uc); |
| 129 | |
| 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | int uclass_get(enum uclass_id id, struct uclass **ucp) |
| 134 | { |
| 135 | struct uclass *uc; |
| 136 | |
| 137 | *ucp = NULL; |
| 138 | uc = uclass_find(id); |
| 139 | if (!uc) |
| 140 | return uclass_add(id, ucp); |
| 141 | *ucp = uc; |
| 142 | |
| 143 | return 0; |
| 144 | } |
| 145 | |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 146 | int uclass_find_device(enum uclass_id id, int index, struct udevice **devp) |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 147 | { |
| 148 | struct uclass *uc; |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 149 | struct udevice *dev; |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 150 | int ret; |
| 151 | |
| 152 | *devp = NULL; |
| 153 | ret = uclass_get(id, &uc); |
| 154 | if (ret) |
| 155 | return ret; |
| 156 | |
| 157 | list_for_each_entry(dev, &uc->dev_head, uclass_node) { |
| 158 | if (!index--) { |
| 159 | *devp = dev; |
| 160 | return 0; |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | return -ENODEV; |
| 165 | } |
| 166 | |
Przemyslaw Marczak | c1d6f91 | 2015-04-15 13:07:17 +0200 | [diff] [blame] | 167 | int uclass_find_first_device(enum uclass_id id, struct udevice **devp) |
| 168 | { |
| 169 | struct uclass *uc; |
| 170 | int ret; |
| 171 | |
| 172 | *devp = NULL; |
| 173 | ret = uclass_get(id, &uc); |
| 174 | if (ret) |
| 175 | return ret; |
| 176 | if (list_empty(&uc->dev_head)) |
| 177 | return 0; |
| 178 | |
| 179 | *devp = list_first_entry(&uc->dev_head, struct udevice, uclass_node); |
| 180 | |
| 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | int uclass_find_next_device(struct udevice **devp) |
| 185 | { |
| 186 | struct udevice *dev = *devp; |
| 187 | |
| 188 | *devp = NULL; |
| 189 | if (list_is_last(&dev->uclass_node, &dev->uclass->dev_head)) |
| 190 | return 0; |
| 191 | |
| 192 | *devp = list_entry(dev->uclass_node.next, struct udevice, uclass_node); |
| 193 | |
| 194 | return 0; |
| 195 | } |
| 196 | |
Przemyslaw Marczak | e0735a4 | 2015-04-15 13:07:22 +0200 | [diff] [blame] | 197 | int uclass_find_device_by_name(enum uclass_id id, const char *name, |
| 198 | struct udevice **devp) |
| 199 | { |
| 200 | struct uclass *uc; |
| 201 | struct udevice *dev; |
| 202 | int ret; |
| 203 | |
| 204 | *devp = NULL; |
| 205 | if (!name) |
| 206 | return -EINVAL; |
| 207 | ret = uclass_get(id, &uc); |
| 208 | if (ret) |
| 209 | return ret; |
| 210 | |
| 211 | list_for_each_entry(dev, &uc->dev_head, uclass_node) { |
| 212 | if (!strncmp(dev->name, name, strlen(name))) { |
| 213 | *devp = dev; |
| 214 | return 0; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | return -ENODEV; |
| 219 | } |
| 220 | |
Simon Glass | 5a66a8f | 2014-07-23 06:55:12 -0600 | [diff] [blame] | 221 | int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq, |
| 222 | bool find_req_seq, struct udevice **devp) |
| 223 | { |
| 224 | struct uclass *uc; |
| 225 | struct udevice *dev; |
| 226 | int ret; |
| 227 | |
| 228 | *devp = NULL; |
| 229 | debug("%s: %d %d\n", __func__, find_req_seq, seq_or_req_seq); |
| 230 | if (seq_or_req_seq == -1) |
| 231 | return -ENODEV; |
| 232 | ret = uclass_get(id, &uc); |
| 233 | if (ret) |
| 234 | return ret; |
| 235 | |
| 236 | list_for_each_entry(dev, &uc->dev_head, uclass_node) { |
| 237 | debug(" - %d %d\n", dev->req_seq, dev->seq); |
| 238 | if ((find_req_seq ? dev->req_seq : dev->seq) == |
| 239 | seq_or_req_seq) { |
| 240 | *devp = dev; |
| 241 | debug(" - found\n"); |
| 242 | return 0; |
| 243 | } |
| 244 | } |
| 245 | debug(" - not found\n"); |
| 246 | |
| 247 | return -ENODEV; |
| 248 | } |
| 249 | |
Simon Glass | f4cdead | 2014-07-23 06:55:14 -0600 | [diff] [blame] | 250 | static int uclass_find_device_by_of_offset(enum uclass_id id, int node, |
| 251 | struct udevice **devp) |
| 252 | { |
| 253 | struct uclass *uc; |
| 254 | struct udevice *dev; |
| 255 | int ret; |
| 256 | |
| 257 | *devp = NULL; |
| 258 | if (node < 0) |
| 259 | return -ENODEV; |
| 260 | ret = uclass_get(id, &uc); |
| 261 | if (ret) |
| 262 | return ret; |
| 263 | |
| 264 | list_for_each_entry(dev, &uc->dev_head, uclass_node) { |
| 265 | if (dev->of_offset == node) { |
| 266 | *devp = dev; |
| 267 | return 0; |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | return -ENODEV; |
| 272 | } |
| 273 | |
Przemyslaw Marczak | 794d521 | 2015-04-20 13:32:32 +0200 | [diff] [blame] | 274 | int uclass_get_device_tail(struct udevice *dev, int ret, |
Simon Glass | 9ca296a | 2014-07-23 06:55:08 -0600 | [diff] [blame] | 275 | struct udevice **devp) |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 276 | { |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 277 | if (ret) |
| 278 | return ret; |
| 279 | |
Simon Glass | f66529f | 2015-04-24 22:33:07 -0600 | [diff] [blame] | 280 | assert(dev); |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 281 | ret = device_probe(dev); |
| 282 | if (ret) |
| 283 | return ret; |
| 284 | |
| 285 | *devp = dev; |
| 286 | |
| 287 | return 0; |
| 288 | } |
| 289 | |
Simon Glass | 9ca296a | 2014-07-23 06:55:08 -0600 | [diff] [blame] | 290 | int uclass_get_device(enum uclass_id id, int index, struct udevice **devp) |
| 291 | { |
| 292 | struct udevice *dev; |
| 293 | int ret; |
| 294 | |
| 295 | *devp = NULL; |
| 296 | ret = uclass_find_device(id, index, &dev); |
| 297 | return uclass_get_device_tail(dev, ret, devp); |
| 298 | } |
| 299 | |
Przemyslaw Marczak | b7af1a2 | 2015-04-15 13:07:23 +0200 | [diff] [blame] | 300 | int uclass_get_device_by_name(enum uclass_id id, const char *name, |
| 301 | struct udevice **devp) |
| 302 | { |
| 303 | struct udevice *dev; |
| 304 | int ret; |
| 305 | |
| 306 | *devp = NULL; |
| 307 | ret = uclass_find_device_by_name(id, name, &dev); |
| 308 | return uclass_get_device_tail(dev, ret, devp); |
| 309 | } |
| 310 | |
Simon Glass | 5a66a8f | 2014-07-23 06:55:12 -0600 | [diff] [blame] | 311 | int uclass_get_device_by_seq(enum uclass_id id, int seq, struct udevice **devp) |
| 312 | { |
| 313 | struct udevice *dev; |
| 314 | int ret; |
| 315 | |
| 316 | *devp = NULL; |
| 317 | ret = uclass_find_device_by_seq(id, seq, false, &dev); |
| 318 | if (ret == -ENODEV) { |
| 319 | /* |
| 320 | * We didn't find it in probed devices. See if there is one |
| 321 | * that will request this seq if probed. |
| 322 | */ |
| 323 | ret = uclass_find_device_by_seq(id, seq, true, &dev); |
| 324 | } |
| 325 | return uclass_get_device_tail(dev, ret, devp); |
| 326 | } |
| 327 | |
Simon Glass | f4cdead | 2014-07-23 06:55:14 -0600 | [diff] [blame] | 328 | int uclass_get_device_by_of_offset(enum uclass_id id, int node, |
| 329 | struct udevice **devp) |
| 330 | { |
| 331 | struct udevice *dev; |
| 332 | int ret; |
| 333 | |
| 334 | *devp = NULL; |
| 335 | ret = uclass_find_device_by_of_offset(id, node, &dev); |
| 336 | return uclass_get_device_tail(dev, ret, devp); |
| 337 | } |
| 338 | |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 339 | int uclass_first_device(enum uclass_id id, struct udevice **devp) |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 340 | { |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 341 | struct udevice *dev; |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 342 | int ret; |
| 343 | |
| 344 | *devp = NULL; |
Przemyslaw Marczak | c1d6f91 | 2015-04-15 13:07:17 +0200 | [diff] [blame] | 345 | ret = uclass_find_first_device(id, &dev); |
Simon Glass | f66529f | 2015-04-24 22:33:07 -0600 | [diff] [blame] | 346 | if (!dev) |
| 347 | return 0; |
Przemyslaw Marczak | c1d6f91 | 2015-04-15 13:07:17 +0200 | [diff] [blame] | 348 | return uclass_get_device_tail(dev, ret, devp); |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 349 | } |
| 350 | |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 351 | int uclass_next_device(struct udevice **devp) |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 352 | { |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 353 | struct udevice *dev = *devp; |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 354 | int ret; |
| 355 | |
| 356 | *devp = NULL; |
Przemyslaw Marczak | c1d6f91 | 2015-04-15 13:07:17 +0200 | [diff] [blame] | 357 | ret = uclass_find_next_device(&dev); |
Simon Glass | f66529f | 2015-04-24 22:33:07 -0600 | [diff] [blame] | 358 | if (!dev) |
| 359 | return 0; |
Przemyslaw Marczak | c1d6f91 | 2015-04-15 13:07:17 +0200 | [diff] [blame] | 360 | return uclass_get_device_tail(dev, ret, devp); |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 363 | int uclass_bind_device(struct udevice *dev) |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 364 | { |
| 365 | struct uclass *uc; |
| 366 | int ret; |
| 367 | |
| 368 | uc = dev->uclass; |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 369 | list_add_tail(&dev->uclass_node, &uc->dev_head); |
| 370 | |
Simon Glass | 081f2fc | 2015-01-25 08:27:08 -0700 | [diff] [blame] | 371 | if (dev->parent) { |
| 372 | struct uclass_driver *uc_drv = dev->parent->uclass->uc_drv; |
| 373 | |
| 374 | if (uc_drv->child_post_bind) { |
| 375 | ret = uc_drv->child_post_bind(dev); |
| 376 | if (ret) |
| 377 | goto err; |
| 378 | } |
| 379 | } |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 380 | if (uc->uc_drv->post_bind) { |
| 381 | ret = uc->uc_drv->post_bind(dev); |
Simon Glass | 081f2fc | 2015-01-25 08:27:08 -0700 | [diff] [blame] | 382 | if (ret) |
| 383 | goto err; |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | return 0; |
Simon Glass | 081f2fc | 2015-01-25 08:27:08 -0700 | [diff] [blame] | 387 | err: |
| 388 | /* There is no need to undo the parent's post_bind call */ |
| 389 | list_del(&dev->uclass_node); |
| 390 | |
| 391 | return ret; |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 392 | } |
| 393 | |
Simon Glass | 7f9875e | 2015-02-27 22:06:31 -0700 | [diff] [blame] | 394 | #ifdef CONFIG_DM_DEVICE_REMOVE |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 395 | int uclass_unbind_device(struct udevice *dev) |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 396 | { |
| 397 | struct uclass *uc; |
| 398 | int ret; |
| 399 | |
| 400 | uc = dev->uclass; |
| 401 | if (uc->uc_drv->pre_unbind) { |
| 402 | ret = uc->uc_drv->pre_unbind(dev); |
| 403 | if (ret) |
| 404 | return ret; |
| 405 | } |
| 406 | |
| 407 | list_del(&dev->uclass_node); |
| 408 | return 0; |
| 409 | } |
Simon Glass | 7f9875e | 2015-02-27 22:06:31 -0700 | [diff] [blame] | 410 | #endif |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 411 | |
Simon Glass | 5a66a8f | 2014-07-23 06:55:12 -0600 | [diff] [blame] | 412 | int uclass_resolve_seq(struct udevice *dev) |
| 413 | { |
| 414 | struct udevice *dup; |
| 415 | int seq; |
| 416 | int ret; |
| 417 | |
| 418 | assert(dev->seq == -1); |
| 419 | ret = uclass_find_device_by_seq(dev->uclass->uc_drv->id, dev->req_seq, |
| 420 | false, &dup); |
| 421 | if (!ret) { |
| 422 | dm_warn("Device '%s': seq %d is in use by '%s'\n", |
| 423 | dev->name, dev->req_seq, dup->name); |
| 424 | } else if (ret == -ENODEV) { |
| 425 | /* Our requested sequence number is available */ |
| 426 | if (dev->req_seq != -1) |
| 427 | return dev->req_seq; |
| 428 | } else { |
| 429 | return ret; |
| 430 | } |
| 431 | |
| 432 | for (seq = 0; seq < DM_MAX_SEQ; seq++) { |
| 433 | ret = uclass_find_device_by_seq(dev->uclass->uc_drv->id, seq, |
| 434 | false, &dup); |
| 435 | if (ret == -ENODEV) |
| 436 | break; |
| 437 | if (ret) |
| 438 | return ret; |
| 439 | } |
| 440 | return seq; |
| 441 | } |
| 442 | |
Simon Glass | 02c07b3 | 2015-03-05 12:25:22 -0700 | [diff] [blame] | 443 | int uclass_pre_probe_device(struct udevice *dev) |
Simon Glass | 83c7e43 | 2015-01-25 08:27:10 -0700 | [diff] [blame] | 444 | { |
| 445 | struct uclass_driver *uc_drv; |
Simon Glass | 02c07b3 | 2015-03-05 12:25:22 -0700 | [diff] [blame] | 446 | int ret; |
| 447 | |
| 448 | uc_drv = dev->uclass->uc_drv; |
| 449 | if (uc_drv->pre_probe) { |
| 450 | ret = uc_drv->pre_probe(dev); |
| 451 | if (ret) |
| 452 | return ret; |
| 453 | } |
Simon Glass | 83c7e43 | 2015-01-25 08:27:10 -0700 | [diff] [blame] | 454 | |
| 455 | if (!dev->parent) |
| 456 | return 0; |
| 457 | uc_drv = dev->parent->uclass->uc_drv; |
| 458 | if (uc_drv->child_pre_probe) |
| 459 | return uc_drv->child_pre_probe(dev); |
| 460 | |
| 461 | return 0; |
| 462 | } |
| 463 | |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 464 | int uclass_post_probe_device(struct udevice *dev) |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 465 | { |
| 466 | struct uclass_driver *uc_drv = dev->uclass->uc_drv; |
| 467 | |
| 468 | if (uc_drv->post_probe) |
| 469 | return uc_drv->post_probe(dev); |
| 470 | |
| 471 | return 0; |
| 472 | } |
| 473 | |
Simon Glass | 7f9875e | 2015-02-27 22:06:31 -0700 | [diff] [blame] | 474 | #ifdef CONFIG_DM_DEVICE_REMOVE |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 475 | int uclass_pre_remove_device(struct udevice *dev) |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 476 | { |
| 477 | struct uclass_driver *uc_drv; |
| 478 | struct uclass *uc; |
| 479 | int ret; |
| 480 | |
| 481 | uc = dev->uclass; |
| 482 | uc_drv = uc->uc_drv; |
| 483 | if (uc->uc_drv->pre_remove) { |
| 484 | ret = uc->uc_drv->pre_remove(dev); |
| 485 | if (ret) |
| 486 | return ret; |
| 487 | } |
| 488 | if (uc_drv->per_device_auto_alloc_size) { |
| 489 | free(dev->uclass_priv); |
| 490 | dev->uclass_priv = NULL; |
| 491 | } |
Simon Glass | 5a66a8f | 2014-07-23 06:55:12 -0600 | [diff] [blame] | 492 | dev->seq = -1; |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 493 | |
| 494 | return 0; |
| 495 | } |
Simon Glass | 7f9875e | 2015-02-27 22:06:31 -0700 | [diff] [blame] | 496 | #endif |