net: introduce helpers to get PHY interface mode from a device/ofnode
[platform/kernel/u-boot.git] / drivers / core / read.c
index ce78f09..c73508d 100644 (file)
@@ -4,12 +4,14 @@
  * Written by Simon Glass <sjg@chromium.org>
  */
 
-#include <asm/types.h>
-#include <asm/io.h>
 #include <common.h>
 #include <dm.h>
-#include <mapmem.h>
 #include <dm/of_access.h>
+#include <mapmem.h>
+#include <asm/global_data.h>
+#include <asm/types.h>
+#include <asm/io.h>
+#include <linux/ioport.h>
 
 int dev_read_u32(const struct udevice *dev, const char *propname, u32 *outp)
 {
@@ -167,7 +169,7 @@ void *dev_read_addr_ptr(const struct udevice *dev)
 {
        fdt_addr_t addr = dev_read_addr(dev);
 
-       return (addr == FDT_ADDR_T_NONE) ? NULL : map_sysmem(addr, 0);
+       return (addr == FDT_ADDR_T_NONE) ? NULL : (void *)(uintptr_t)addr;
 }
 
 void *dev_remap_addr(const struct udevice *dev)
@@ -203,6 +205,12 @@ int dev_read_string_count(const struct udevice *dev, const char *propname)
        return ofnode_read_string_count(dev_ofnode(dev), propname);
 }
 
+int dev_read_string_list(const struct udevice *dev, const char *propname,
+                        const char ***listp)
+{
+       return ofnode_read_string_list(dev_ofnode(dev), propname, listp);
+}
+
 int dev_read_phandle_with_args(const struct udevice *dev, const char *list_name,
                               const char *cells_name, int cell_count,
                               int index, struct ofnode_phandle_args *out_args)
@@ -213,10 +221,11 @@ int dev_read_phandle_with_args(const struct udevice *dev, const char *list_name,
 }
 
 int dev_count_phandle_with_args(const struct udevice *dev,
-                               const char *list_name, const char *cells_name)
+                               const char *list_name, const char *cells_name,
+                               int cell_count)
 {
        return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name,
-                                             cells_name);
+                                             cells_name, cell_count);
 }
 
 int dev_read_addr_cells(const struct udevice *dev)
@@ -255,19 +264,39 @@ const void *dev_read_prop(const struct udevice *dev, const char *propname,
        return ofnode_get_property(dev_ofnode(dev), propname, lenp);
 }
 
+int dev_read_first_prop(const struct udevice *dev, struct ofprop *prop)
+{
+       return ofnode_get_first_property(dev_ofnode(dev), prop);
+}
+
+int dev_read_next_prop(struct ofprop *prop)
+{
+       return ofnode_get_next_property(prop);
+}
+
+const void *dev_read_prop_by_prop(struct ofprop *prop,
+                                 const char **propname, int *lenp)
+{
+       return ofnode_get_property_by_prop(prop, propname, lenp);
+}
+
 int dev_read_alias_seq(const struct udevice *dev, int *devnump)
 {
        ofnode node = dev_ofnode(dev);
        const char *uc_name = dev->uclass->uc_drv->name;
-       int ret;
+       int ret = -ENOTSUPP;
 
        if (ofnode_is_np(node)) {
                ret = of_alias_get_id(ofnode_to_np(node), uc_name);
-               if (ret >= 0)
+               if (ret >= 0) {
                        *devnump = ret;
+                       ret = 0;
+               }
        } else {
+#if CONFIG_IS_ENABLED(OF_CONTROL)
                ret = fdtdec_get_alias_seq(gd->fdt_blob, uc_name,
                                           ofnode_to_offset(node), devnump);
+#endif
        }
 
        return ret;
@@ -318,6 +347,12 @@ u64 dev_translate_dma_address(const struct udevice *dev, const fdt32_t *in_addr)
        return ofnode_translate_dma_address(dev_ofnode(dev), in_addr);
 }
 
+int dev_get_dma_range(const struct udevice *dev, phys_addr_t *cpu,
+                     dma_addr_t *bus, u64 *size)
+{
+       return ofnode_get_dma_range(dev_ofnode(dev), cpu, bus, size);
+}
+
 int dev_read_alias_highest_id(const char *stem)
 {
        if (of_live_active())
@@ -336,3 +371,40 @@ fdt_addr_t dev_read_addr_pci(const struct udevice *dev)
 
        return addr;
 }
+
+int dev_get_child_count(const struct udevice *dev)
+{
+       return ofnode_get_child_count(dev_ofnode(dev));
+}
+
+int dev_read_pci_bus_range(const struct udevice *dev,
+                          struct resource *res)
+{
+       const u32 *values;
+       int len;
+
+       values = dev_read_prop(dev, "bus-range", &len);
+       if (!values || len < sizeof(*values) * 2)
+               return -EINVAL;
+
+       res->start = *values++;
+       res->end = *values;
+
+       return 0;
+}
+
+int dev_decode_display_timing(const struct udevice *dev, int index,
+                             struct display_timing *config)
+{
+       return ofnode_decode_display_timing(dev_ofnode(dev), index, config);
+}
+
+ofnode dev_get_phy_node(const struct udevice *dev)
+{
+       return ofnode_get_phy_node(dev_ofnode(dev));
+}
+
+phy_interface_t dev_read_phy_mode(const struct udevice *dev)
+{
+       return ofnode_read_phy_mode(dev_ofnode(dev));
+}