User avatar
procount
Posts: 1601
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Devicetree duplicate labels

Tue Mar 05, 2019 12:06 pm

I want to use a dtparam to switch between 2 fragments in an overlay for 2 alternative forms of the same definitions. Only 1 fragment will be active at a time. As they both include the same label, dtc complains.
Do I have to use different labels in each fragment? I think this will mean duplicating all other fragments that reference these alternatives. Or is there a better way?
Here is an extract of my dts file:

Code: Select all

    /* Define a group of pins to be configured by the GPIO driver as function 6 = ALT2 = DPI mode */
    [email protected] {
        target = <&gpio>;
        __overlay__ {
            dpi18_pins: dpi18_pins {		// <--- original label
                brcm,pins = <0 1 2 3 4 5 6 7 8 9 12 13 14 15 16 17 20 21 22 23 24 25>;
                brcm,function = <6>;
                brcm,pull = <0>;
            };
        };
    };

    /* Define a group of pins to be configured by the GPIO driver as function 6 = ALT2 = DPI mode */
    /* THIS IS AN ALTERNATIVE GROUP WHERE ARGON FAN IS FITTED, REMOVING GPIO 0&1 from GROUP */
    [email protected] {
        target = <&gpio>;
        __dormant__ {
            dpi18_pins: dpi18_pins {		// <--- duplicate label
                brcm,pins = <2 3 4 5 6 7 8 9 12 13 14 15 16 17 20 21 22 23 24 25>;
                brcm,function = <6>;
                brcm,pull = <0>;
            };
        };
    };
    
    /* Add the device under i2c_gpio */
    [email protected] {
        target = <&i2c_gpio>;
        __overlay__ {
 		/* ... */
                pinctrl-names = "default";
                pinctrl-0 = <&dpi18_pins>;	  //   <---The problem reference
 		/* ... */
        };

	__overrides__ {
            argon =    <0>,"-0+1";		// <--- Switch to alternative fragment
	};

PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2148
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Devicetree duplicate labels

Tue Mar 05, 2019 12:18 pm

You are correct that labels do have to be unique within a translation unit (a base DTB or an overlay) (but they are lost during compilation so don't have to be globally unique).

One option would be to have multiple instances of the i2c_gpio fragment, each referencing a different pinctrl fragment, but we can do better. All that is changing between the different dpi_pins fragments is the "brcm,pins" property (*). If you create the dpi18_pins node in one fragment you get a single, constant label. Then multiple conditional follow-up fragments can target that node and populate it with different contents. You can decide whether to put default content in the initial dpi18_pins node or to rely on one of the followups being enabled.

(*) The same logic applies if multiple properties are changed - the point is that we can factor out the constant parent node.

User avatar
procount
Posts: 1601
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: Devicetree duplicate labels

Tue Mar 05, 2019 12:27 pm

So easy when you know how!
Thanks!
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

Return to “Device Tree”