[OpenWrt-Devel] gpio-export,output and GPIO_ACTIVE_*

Piotr Dymacz pepe2k at gmail.com
Mon Feb 24 08:17:15 EST 2020

Hi Adrian,

On 23.02.2020 20:51, mail at adrianschmutzler.de wrote:
> Hi,
> when defining gpio-export nodes, I'm never really sure about how the
> values for "gpio-export,output" and GPIO_ACTIVE_HIGH/LOW in gpios
> have to be set up correctly in relation to each other.
> I also was not able to retrieve a particular system in how this is
> set up currently (for different devices).
> It would be nice if somebody could elaborate this to me (I've found
> several shorter explanations in the PR comments throughout GitHub,
> but they unfortunately were never comprehensive.)
> (And I assume the same logic will apply to gpio-hogs with
> output-low/high and gpios parameter?)

I think it's more about semantics, relationship between value in 
user-space (0, 1) and actual value output by hardware (some voltage vs. 
no voltage, for this discussion purposed, forget about open drain, etc.) 
and (inverted) binary logic.

Assume we have a GPIO line which controls some kind of reset line (for 
example, PCIe PERSTn signal, used by WiFi cards, GSM/GPS modules, etc.):

- if GPIO is set to 0 (0 V), the card is in reset state
- if GPIO is set to 1 (3.3 V), the card is in operational state

Sounds simple until you start considering user-space name for it. If we 
use 'pcie-reset' then 'GPIO_ACTIVE_LOW' should be used (if line is set 
to '1' in user-space it will means '0 V' in hardware, putting the card 
in reset state -> so logic is inverted here).
On the other hand, we can also name the line as 'pcie-enable', which 
with '1' in user-space gives also '1' in hardware (3.3 V) - in this case 
the line should use 'GPIO_ACTIVE_HIGH'.

I don't think there is a general accepted approach here, at least for 
the naming. Maybe only in case of GPIO lines which controls some power 
we usually try to match user-space value with actual voltage/power ('1' 
in system should mean controlled power/voltage is enabled). But this 
also means that the contributor has to check what GPIO value gives the 
'active' state in hardware.

Regarding the upstream 'output-{high,low}' property - it's used to set 
line as output with initial, default value (low/high).

In our case, the 'gpio-export,output = <X>' property is used for that 
and sets selected line as output (with default value '1' or '0'). If 
this property is missing, then the line will be used as input, see [0].

Hope this helps.



openwrt-devel mailing list
openwrt-devel at lists.openwrt.org

More information about the openwrt-devel mailing list