Commit bcd90cb6928414e14942c01af374863d4049a25d

Authored by Simon Glass
1 parent 04e19ffded

dm: core: Export a new function to read platdata

Add a new internal function, device_ofdata_to_platdata() to handle
allocating private space associated with each device and reading the
platform data from the device tree.

Call this new function from device_probe().

Signed-off-by: Simon Glass <sjg@chromium.org>

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

drivers/core/device.c
... ... @@ -311,12 +311,11 @@
311 311 return priv;
312 312 }
313 313  
314   -int device_probe(struct udevice *dev)
  314 +int device_ofdata_to_platdata(struct udevice *dev)
315 315 {
316 316 const struct driver *drv;
317 317 int size = 0;
318 318 int ret;
319   - int seq;
320 319  
321 320 if (!dev)
322 321 return -EINVAL;
... ... @@ -368,6 +367,32 @@
368 367 if (ret)
369 368 goto fail;
370 369 }
  370 +
  371 + return 0;
  372 +fail:
  373 + device_free(dev);
  374 +
  375 + return ret;
  376 +}
  377 +
  378 +int device_probe(struct udevice *dev)
  379 +{
  380 + const struct driver *drv;
  381 + int ret;
  382 + int seq;
  383 +
  384 + if (!dev)
  385 + return -EINVAL;
  386 +
  387 + if (dev->flags & DM_FLAG_ACTIVATED)
  388 + return 0;
  389 +
  390 + drv = dev->driver;
  391 + assert(drv);
  392 +
  393 + ret = device_ofdata_to_platdata(dev);
  394 + if (ret)
  395 + goto fail;
371 396  
372 397 /* Ensure all parents are probed */
373 398 if (dev->parent) {
include/dm/device-internal.h
... ... @@ -84,6 +84,22 @@
84 84 const struct driver_info *info, struct udevice **devp);
85 85  
86 86 /**
  87 + * device_ofdata_to_platdata() - Read platform data for a device
  88 + *
  89 + * Read platform data for a device (typically from the device tree) so that
  90 + * the information needed to probe the device is present.
  91 + *
  92 + * This may cause some others devices to be probed if this one depends on them,
  93 + * e.g. a GPIO line will cause a GPIO device to be probed.
  94 + *
  95 + * All private data associated with the device is allocated.
  96 + *
  97 + * @dev: Pointer to device to process
  98 + * @return 0 if OK, -ve on error
  99 + */
  100 +int device_ofdata_to_platdata(struct udevice *dev);
  101 +
  102 +/**
87 103 * device_probe() - Probe a device, activating it
88 104 *
89 105 * Activate a device so that it is ready for use. All its parents are probed