Commit 426f99fa98c3725fe0ca1eb8438d1215a2c6bd6b

Authored by Stefan Roese
Committed by Bin Meng
1 parent e98856fcff

dm: core: Add DM_FLAG_OS_PREPARE flag

This new flag can be added to DM device drivers, which need to do some
final configuration before U-Boot exits and the OS (e.g. Linux) is
started. The remove functions of those drivers will get called at
this stage to do these last-stage configuration steps.

Signed-off-by: Stefan Roese <sr@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>

Showing 2 changed files with 21 additions and 6 deletions Side-by-side Diff

drivers/core/device-remove.c
... ... @@ -152,6 +152,15 @@
152 152 devres_release_probe(dev);
153 153 }
154 154  
  155 +static bool flags_remove(uint flags, uint drv_flags)
  156 +{
  157 + if ((flags & DM_REMOVE_NORMAL) ||
  158 + (flags & (drv_flags & (DM_FLAG_ACTIVE_DMA | DM_FLAG_OS_PREPARE))))
  159 + return true;
  160 +
  161 + return false;
  162 +}
  163 +
155 164 int device_remove(struct udevice *dev, uint flags)
156 165 {
157 166 const struct driver *drv;
... ... @@ -178,9 +187,7 @@
178 187 * Remove the device if called with the "normal" remove flag set,
179 188 * or if the remove flag matches any of the drivers remove flags
180 189 */
181   - if (drv->remove &&
182   - ((flags & DM_REMOVE_NORMAL) ||
183   - (flags & (drv->flags & DM_FLAG_ACTIVE_DMA)))) {
  190 + if (drv->remove && flags_remove(flags, drv->flags)) {
184 191 ret = drv->remove(dev);
185 192 if (ret)
186 193 goto err_remove;
... ... @@ -194,8 +201,7 @@
194 201 }
195 202 }
196 203  
197   - if ((flags & DM_REMOVE_NORMAL) ||
198   - (flags & (drv->flags & DM_FLAG_ACTIVE_DMA))) {
  204 + if (flags_remove(flags, drv->flags)) {
199 205 device_free(dev);
200 206  
201 207 dev->seq = -1;
... ... @@ -55,6 +55,12 @@
55 55 #define DM_FLAG_ACTIVE_DMA (1 << 9)
56 56  
57 57 /*
  58 + * Call driver remove function to do some final configuration, before
  59 + * U-Boot exits and the OS is started
  60 + */
  61 +#define DM_FLAG_OS_PREPARE (1 << 10)
  62 +
  63 +/*
58 64 * One or multiple of these flags are passed to device_remove() so that
59 65 * a selective device removal as specified by the remove-stage and the
60 66 * driver flags can be done.
61 67  
... ... @@ -66,10 +72,13 @@
66 72 /* Remove devices with active DMA */
67 73 DM_REMOVE_ACTIVE_DMA = DM_FLAG_ACTIVE_DMA,
68 74  
  75 + /* Remove devices which need some final OS preparation steps */
  76 + DM_REMOVE_OS_PREPARE = DM_FLAG_OS_PREPARE,
  77 +
69 78 /* Add more use cases here */
70 79  
71 80 /* Remove devices with any active flag */
72   - DM_REMOVE_ACTIVE_ALL = DM_REMOVE_ACTIVE_DMA,
  81 + DM_REMOVE_ACTIVE_ALL = DM_REMOVE_ACTIVE_DMA | DM_REMOVE_OS_PREPARE,
73 82 };
74 83  
75 84 /**