]> git.karo-electronics.de Git - karo-tx-uboot.git/blobdiff - include/dm/device.h
ARM: at91: sama5: move the nandflash env config to at91-sama5_common.h
[karo-tx-uboot.git] / include / dm / device.h
index c474f2dabba3f35ae4f72ae8766799e5b43255d6..a239be64691ad774ce380782a08eea6e73e10ad4 100644 (file)
@@ -98,7 +98,9 @@ struct udevice {
        uint32_t flags;
        int req_seq;
        int seq;
+#ifdef CONFIG_DEVRES
        struct list_head devres_head;
+#endif
 };
 
 /* Maximum sequence number supported */
@@ -120,11 +122,11 @@ struct udevice_id {
        ulong data;
 };
 
-#ifdef CONFIG_OF_CONTROL
+#if CONFIG_IS_ENABLED(OF_CONTROL)
 #define of_match_ptr(_ptr)     (_ptr)
 #else
 #define of_match_ptr(_ptr)     NULL
-#endif /* CONFIG_OF_CONTROL */
+#endif /* CONFIG_IS_ENABLED(OF_CONTROL) */
 
 /**
  * struct driver - A driver for a feature or peripheral
@@ -468,10 +470,27 @@ bool device_has_active_children(struct udevice *dev);
  */
 bool device_is_last_sibling(struct udevice *dev);
 
+/**
+ * device_set_name() - set the name of a device
+ *
+ * This must be called in the device's bind() method and no later. Normally
+ * this is unnecessary but for probed devices which don't get a useful name
+ * this function can be helpful.
+ *
+ * @dev:       Device to update
+ * @name:      New name (this string is allocated new memory and attached to
+ *             the device)
+ * @return 0 if OK, -ENOMEM if there is not enough memory to allocate the
+ * string
+ */
+int device_set_name(struct udevice *dev, const char *name);
+
 /* device resource management */
 typedef void (*dr_release_t)(struct udevice *dev, void *res);
 typedef int (*dr_match_t)(struct udevice *dev, void *res, void *match_data);
 
+#ifdef CONFIG_DEVRES
+
 #ifdef CONFIG_DEBUG_DEVRES
 void *__devres_alloc(dr_release_t release, size_t size, gfp_t gfp,
                     const char *name);
@@ -648,5 +667,83 @@ static inline void *devm_kcalloc(struct udevice *dev,
  */
 void devm_kfree(struct udevice *dev, void *p);
 
+#else /* ! CONFIG_DEVRES */
+
+static inline void *devres_alloc(dr_release_t release, size_t size, gfp_t gfp)
+{
+       return kzalloc(size, gfp);
+}
+
+static inline void devres_free(void *res)
+{
+       kfree(res);
+}
+
+static inline void devres_add(struct udevice *dev, void *res)
+{
+}
+
+static inline void *devres_find(struct udevice *dev, dr_release_t release,
+                               dr_match_t match, void *match_data)
+{
+       return NULL;
+}
+
+static inline void *devres_get(struct udevice *dev, void *new_res,
+                              dr_match_t match, void *match_data)
+{
+       return NULL;
+}
+
+static inline void *devres_remove(struct udevice *dev, dr_release_t release,
+                                 dr_match_t match, void *match_data)
+{
+       return NULL;
+}
+
+static inline int devres_destroy(struct udevice *dev, dr_release_t release,
+                                dr_match_t match, void *match_data)
+{
+       return 0;
+}
+
+static inline int devres_release(struct udevice *dev, dr_release_t release,
+                                dr_match_t match, void *match_data)
+{
+       return 0;
+}
+
+static inline void *devm_kmalloc(struct udevice *dev, size_t size, gfp_t gfp)
+{
+       return kmalloc(size, gfp);
+}
+
+static inline void *devm_kzalloc(struct udevice *dev, size_t size, gfp_t gfp)
+{
+       return kzalloc(size, gfp);
+}
+
+static inline void *devm_kmaloc_array(struct udevice *dev,
+                                     size_t n, size_t size, gfp_t flags)
+{
+       /* TODO: add kmalloc_array() to linux/compat.h */
+       if (size != 0 && n > SIZE_MAX / size)
+               return NULL;
+       return kmalloc(n * size, flags);
+}
+
+static inline void *devm_kcalloc(struct udevice *dev,
+                                size_t n, size_t size, gfp_t flags)
+{
+       /* TODO: add kcalloc() to linux/compat.h */
+       return kmalloc(n * size, flags | __GFP_ZERO);
+}
+
+static inline void devm_kfree(struct udevice *dev, void *p)
+{
+       kfree(p);
+}
+
+#endif /* ! CONFIG_DEVRES */
 
 #endif