Hi,

i would like to attach sxisyscon(4) on a few more compatibles,
and register the regmap once per child with a phandle.

here is a complete example of the relevant node(s) from sun7i-a20:
        Node 0xda8
            name: 'system-control'
            compatible: 'allwinner,sun7i-a20-system-control' + 
'allwinner,sun4i-a10-system-control'
            reg: 01c00000.00000030
            #address-cells: 00000001
            #size-cells: 00000001
            ranges: 

            Node 0xe58
                name: 'sram'
                compatible: 'mmio-sram'
                reg: 00000000.0000c000
                #address-cells: 00000001
                #size-cells: 00000001
                ranges: 00000000.00000000.0000c000

                Node 0xec8
                    name: 'sram-section'
                    compatible: 'allwinner,sun7i-a20-sram-a3-a4' + 
'allwinner,sun4i-a10-sram-a3-a4'
                    reg: 00008000.00004000
                    status: 'disabled'
                    phandle: 0000000c

            Node 0xf70
                name: 'sram'
                compatible: 'mmio-sram'
                reg: 00010000.00001000
                #address-cells: 00000001
                #size-cells: 00000001
                ranges: 00000000.00010000.00001000

                Node 0xfe4
                    name: 'sram-section'
                    compatible: 'allwinner,sun7i-a20-sram-d' + 
'allwinner,sun4i-a10-sram-d'
                    reg: 00000000.00001000
                    status: 'okay'
                    phandle: 00000018

            Node 0x107c
                name: 'sram'
                compatible: 'mmio-sram'
                reg: 01d00000.000d0000
                #address-cells: 00000001
                #size-cells: 00000001
                ranges: 00000000.01d00000.000d0000

                Node 0x10f4
                    name: 'sram-section'
                    compatible: 'allwinner,sun7i-a20-sram-c1' + 
'allwinner,sun4i-a10-sram-c1'
                    reg: 00000000.00080000
                    phandle: 00000013

and an example node using above is like this:
        Node 0x215c
            name: 'usb'
            compatible: 'allwinner,sun4i-a10-musb'
            reg: 01c13000.00000400
            clocks: 00000002.0000001a
            interrupts: 00000000.00000026.00000004
            interrupt-names: 'mc'
            phys: 00000017.00000000
            phy-names: 'usb'
            extcon: 00000017.00000000
            allwinner,sram: 00000018.00000001
            status: 'okay'
            dr_mode: 'otg'


diff below does allow the use of "allwinner,sram"-property to
reach the regmap without teaching "the user"(=driver) of all
the possible compatibles for 'system-control', nor how the
phandle X is useful only for
  regmap_bynode(OF_parent(OF_parent(OF_getnodebyphandle(X)))) to use.

in short; i want to get rid of the need to hardcode OF_parent(OF_parent()).
any comments?

-Artturi


diff --git a/sys/dev/fdt/sxisyscon.c b/sys/dev/fdt/sxisyscon.c
index 30021d9f6aa..7b0da0d77c4 100644
--- a/sys/dev/fdt/sxisyscon.c
+++ b/sys/dev/fdt/sxisyscon.c
@@ -49,7 +49,11 @@ sxisyscon_match(struct device *parent, void *match, void 
*aux)
        struct fdt_attach_args *faa = aux;
        int node = faa->fa_node;
 
-       if (OF_is_compatible(node, "allwinner,sun8i-h3-system-control") ||
+       if (OF_is_compatible(node, "allwinner,sun4i-a10-system-control") ||
+           OF_is_compatible(node, "allwinner,sun5i-a13-system-control") ||
+           OF_is_compatible(node, "allwinner,sun7i-a20-system-control") ||
+           OF_is_compatible(node, "allwinner,sun8i-a23-system-control") ||
+           OF_is_compatible(node, "allwinner,sun8i-h3-system-control") ||
            OF_is_compatible(node, "allwinner,sun50i-a64-system-control") ||
            OF_is_compatible(node, "allwinner,sun50i-h5-system-control") ||
            OF_is_compatible(node, "allwinner,sun50i-h6-system-control"))
@@ -63,6 +67,7 @@ sxisyscon_attach(struct device *parent, struct device *self, 
void *aux)
 {
        struct sxisyscon_softc *sc = (struct sxisyscon_softc *)self;
        struct fdt_attach_args *faa = aux;
+       int cnode, pnode;
 
        if (faa->fa_nreg < 1) {
                printf(": no registers\n");
@@ -76,8 +81,24 @@ sxisyscon_attach(struct device *parent, struct device *self, 
void *aux)
                return;
        }
 
+       /*
+        * Register us, and all our child nodes with a phandle, to allow
+        * the use of either regmap_bycompatible() or regmap_byphandle().
+        * Other device nodes have "allwinner,sram" property with phandle
+        * to these, also they should know the sram-section they want by
+        * compatible. Which doesn't really matter as they get the same
+        * regmap contents no matter what.. but this gives them both.
+        */
        regmap_register(faa->fa_node, sc->sc_iot, sc->sc_ioh,
            faa->fa_reg[0].size);
+       for (pnode = OF_child(faa->fa_node); pnode; pnode = OF_peer(pnode)) {
+               if (!OF_is_compatible(pnode, "mmio-sram"))
+                       continue;
+               for (cnode = OF_child(pnode); cnode; cnode = OF_peer(cnode))
+                       if (OF_getpropint(cnode, "phandle", 0))
+                               regmap_register(cnode, sc->sc_iot, sc->sc_ioh,
+                                   faa->fa_reg[0].size);
+       }
 
        printf("\n");
 }

Reply via email to