dm: core: add functions to get/remap I/O addresses by name
[oweals/u-boot.git] / include / dm / read.h
index f14c7a7ba87c716a6ba0e26f8e343ee8871f47da..efcbee15ecaea90c05d6d80dcfb75f3a34a3b43a 100644 (file)
@@ -1,10 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
 /*
  * Function to read values from the device tree node attached to a udevice.
  *
  * Copyright (c) 2017 Google, Inc
  * Written by Simon Glass <sjg@chromium.org>
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #ifndef _DM_READ_H
@@ -113,6 +112,43 @@ int dev_read_size(struct udevice *dev, const char *propname);
  */
 fdt_addr_t dev_read_addr_index(struct udevice *dev, int index);
 
+/**
+ * dev_remap_addr_index() - Get the indexed reg property of a device
+ *                               as a memory-mapped I/O pointer
+ *
+ * @dev: Device to read from
+ * @index: the 'reg' property can hold a list of <addr, size> pairs
+ *        and @index is used to select which one is required
+ *
+ * @return pointer or NULL if not found
+ */
+void *dev_remap_addr_index(struct udevice *dev, int index);
+
+/**
+ * dev_read_addr_name() - Get the reg property of a device, indexed by name
+ *
+ * @dev: Device to read from
+ * @name: the 'reg' property can hold a list of <addr, size> pairs, with the
+ *       'reg-names' property providing named-based identification. @index
+ *       indicates the value to search for in 'reg-names'.
+ *
+ * @return address or FDT_ADDR_T_NONE if not found
+ */
+fdt_addr_t dev_read_addr_name(struct udevice *dev, const char* name);
+
+/**
+ * dev_remap_addr_name() - Get the reg property of a device, indexed by name,
+ *                         as a memory-mapped I/O pointer
+ *
+ * @dev: Device to read from
+ * @name: the 'reg' property can hold a list of <addr, size> pairs, with the
+ *       'reg-names' property providing named-based identification. @index
+ *       indicates the value to search for in 'reg-names'.
+ *
+ * @return pointer or NULL if not found
+ */
+void *dev_remap_addr_name(struct udevice *dev, const char* name);
+
 /**
  * dev_read_addr() - Get the reg property of a device
  *
@@ -132,6 +168,16 @@ fdt_addr_t dev_read_addr(struct udevice *dev);
  */
 void *dev_read_addr_ptr(struct udevice *dev);
 
+/**
+ * dev_remap_addr() - Get the reg property of a device as a
+ *                         memory-mapped I/O pointer
+ *
+ * @dev: Device to read from
+ *
+ * @return pointer or NULL if not found
+ */
+void *dev_remap_addr(struct udevice *dev);
+
 /**
  * dev_read_addr_size() - get address and size from a device property
  *
@@ -473,6 +519,12 @@ static inline fdt_addr_t dev_read_addr_index(struct udevice *dev, int index)
        return devfdt_get_addr_index(dev, index);
 }
 
+static inline fdt_addr_t dev_read_addr_name(struct udevice *dev,
+                                           const char *name)
+{
+       return devfdt_get_addr_name(dev, name);
+}
+
 static inline fdt_addr_t dev_read_addr(struct udevice *dev)
 {
        return devfdt_get_addr(dev);
@@ -483,6 +535,21 @@ static inline void *dev_read_addr_ptr(struct udevice *dev)
        return devfdt_get_addr_ptr(dev);
 }
 
+static inline void *dev_remap_addr(struct udevice *dev)
+{
+       return devfdt_remap_addr(dev);
+}
+
+static inline void *dev_remap_addr_index(struct udevice *dev, int index)
+{
+       return devfdt_remap_addr_index(dev, index);
+}
+
+static inline void *dev_remap_addr_name(struct udevice *dev, const char *name)
+{
+       return devfdt_remap_addr_name(dev, name);
+}
+
 static inline fdt_addr_t dev_read_addr_size(struct udevice *dev,
                                            const char *propname,
                                            fdt_size_t *sizep)