Hi,

i was looking at unifying something before "adding on" again, and
was thinking i would like to do something like in the example below:

const char *com_fdt_compat[] = {
        "brcm,bcm2835-aux-uart",
        "snps,dw-apb-uart",
#ifdef __armv7__
        "ti,omap3-uart",
        "ti,omap4-uart",
#endif
}

int
com_fdt_match(struct device *parent, void *match, void *aux)
{
        int node = ((struct fdt_attach_args *)aux)->fa_node;

        return OF_is_ncompatible(node, com_fdt_compat, nitems(com_fdt_compat));
}

similarly, while this is shorter:
        if ((node = fdt_find_cons("brcm,bcm2835-aux-uart")) == NULL &&
            (node = fdt_find_cons("snps,dw-apb-uart")) == NULL &&
            (node = fdt_find_cons("ti,omap3-uart")) == NULL &&
            (node = fdt_find_cons("ti,omap4-uart")) == NULL)
                        return;

i don't think this is much worse:
        int i;

        for (i = 0; i < nitems(com_fdt_compat); i++) {
                node = fdt_find_cons(com_fdt_compat[i]);
                if (node != NULL)
                        break;
        }
        if (node == NULL)
                return;

atleast it would make adding new compatible possibly an
+       "one,liner",

any comments? or why nothing like this?
sry for noise, if i've asked about this before.:)

-Artturi


diff --git sys/dev/ofw/fdt.c sys/dev/ofw/fdt.c
index a45f1066e9e..ee911f61726 100644
--- sys/dev/ofw/fdt.c
+++ sys/dev/ofw/fdt.c
@@ -916,6 +916,18 @@ OF_is_compatible(int handle, const char *name)
        return (fdt_is_compatible(node, name));
 }
 
+int
+OF_is_ncompatible(int handle, const char *name, int nelem)
+{
+       void *node = (char *)tree.header + handle;
+       int i;
+
+       for (i = 0; i < nelem; i++)
+               if (fdt_is_compatible(node, name++))
+                       return 1;
+       return 0;
+}
+
 int
 OF_getindex(int handle, const char *entry, const char *prop)
 {
diff --git sys/dev/ofw/openfirm.h sys/dev/ofw/openfirm.h
index 45f8086d047..68ceeac8205 100644
--- sys/dev/ofw/openfirm.h
+++ sys/dev/ofw/openfirm.h
@@ -55,6 +55,7 @@ int OF_setprop(int, char *, const void *, int);
 int OF_nextprop(int, char *, void *);
 int OF_finddevice(char *name);
 int OF_is_compatible(int, const char *);
+int OF_is_ncompatible(int, const char *, int);
 int OF_instance_to_path(int ihandle, char *buf, int buflen);
 int OF_package_to_path(int phandle, char *buf, int buflen);
 int OF_call_method_1(char *method, int ihandle, int nargs, ...);

Reply via email to