-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Expander GPIO: Initial state not set correctly when configuring as output and low active #5107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If you declare the GPIO as ACTIVE_LOW then "off" gives a high logic level. Change one or the other to get an initial low logic level. |
Yes, that is the theory. Unfortunately, it doesn't work that way. When ACTIVE_LOW and "off" is given, the logic level is low (which is wrong). This leads to the LED to be on (since the GPIO is connected on the cathode side of the LED). |
FWIW, the polarity is ACTIVE_LOW by default for the power LED. So using the following should turn off both LEDs.
But that is not the case: It does turn off the activity LED, but the power LED stays on. I first thought that Side note: Most guides suggest to also set
For the activity LED, this has no effect as it is high active by default. However, for the power LED this changes the GPIO setting to be
Currently, this makes the power LED to be off. But it is wrong, the PWR LED is not a high active GPIO. But setting power LED low active should cause the LED to be on! |
Those two statements are contradictory. Explain. |
I expect it to be off, but when I do this, the LED is on (means logic level high). I think we are in agreement what we expect:
"gives a high logic level." -> LED off. I don't see the contradiction? We agree that
Correct? You said:
I assume with "then off" you meant So, That is not the case. |
The firmware does have a notion of polarity for itself. https://github.com/raspberrypi/firmware/blob/master/extra/dt-blob.dts#L1768
So Memory says that the set/get state calls were meant to pass through directly though, and the polarity was only to retain the state (as was required by the older gpio API). Testing for myself: Checking with a multimeter, The datasheet of the 74LVC1G07 fig 3 shows an inverter before the open-drain output, therefore 1 / 3V3 / (inactive with ACTIVE_LOW) will be inverted to drive the FETs gate at 0V, and hence the LED is off. As you say, the kernel for CM4 is configured with
and using /sys/class/leds/led1/brightness, 0 turns the LED off, and 1 turns it on, so it is doing the appropriate inversion based on that ACTIVE_LOW flag. So that largely confirms to me that whilst the firmware does have a notion of polarity, it is bypassed when driven by Linux, and that is behaving as it should. The only difference I can see with your DT snippet is that you're setting it to |
Ah, it looks to be the firmware on that initial set. It passes through all the parameters via a different path, and that does apply a polarity correction which we don't want. |
That very much looks like what I am observing indeed. It is confusing as subsequent GPIO sets/clears seem to work.
Very much appreciated, thank you! |
Test firmware for 2711 based boards (Pi4/CM4/Pi400) that should solve this at https://drive.google.com/file/d/1CI2wzuYDSWa4ewSm8Spw4ztI2xp5HL0r/view?usp=sharing The same fix will apply to the other boards as well, but that will come with the full release. |
@6by9 thanks, just copied the firmware on my board and I can confirm the power LED is now behaving as expected! I am a bit hesitant to deploy this firmware in production. I'll wait until it makes it into stable and gets a bit wider testing. I use a kernel level work around meanwhile. From my side, this issue can be closed. Thanks! |
Firmware change has been merged internally, so should be in the next rpi-update release. |
See: https://forums.raspberrypi.com/viewtopic.php?t=338429 firmware: arm_loader: Correct GPIO expander initial state via SET_GPIO_CONFIG See: raspberrypi/linux#5107
See: https://forums.raspberrypi.com/viewtopic.php?t=338429 firmware: arm_loader: Correct GPIO expander initial state via SET_GPIO_CONFIG See: raspberrypi/linux#5107
- firmware: board_info: Handle misprogrammed 3B rev 1.2s - firmware: mmal: Add mapping for IL OMX_IndexParamBrcmEnableIJGTableScaling param - firmware: Handle overlay parameters embedded in overlay_map.dtb See: raspberrypi/linux#4860 - firmware: firmware: Add HDMI_PORTS trait - firmware: arm_dt: Fix rpi-poe overlay parameters See: #1689 - firmware: jpeghw: Skip APP0 AVI1 headers, regardless of length See: https://forums.raspberrypi.com/viewtopic.php?p=1975448 - firmware: camera_subsystem: Report ignored interfaces due to libcamera - See: #1679 - firmware: Export os_prefix, overlay_prefix, rsts and boot-mode on all models - firmware: vcfw/hdmi_i2c: Initialise all instances from hdmi_i2c_init - firmware: dtoverlay: Add support for string escape sequences See: https://forums.raspberrypi.com/viewtopic.php?t=330792 - firmware: isp: R and B order must be swapped when reading VC_IMAGE_RGBA32 into the ISP See: http://git/vc4/vc4/-/merge_requests/1430 - firmware: dtoverlay: Fix path rebasing and exports - firmware: dtoverlay: Fix clang warnings - firmware: arm_loader_dvfs: Make arm only see its own boosts, fixed and min clocks - firmware: arm_loader: Support longer file paths See: #1720 - firmware: arm_loader_dvfs: Support CLOCK_HDMI as boostable clock See: raspberrypi/linux#5016 - firmware: dtblob: Use a cached alias to reduce boot time - firmware: hdmi: Reduce the number of EDID retries if hotplug is not detected - firmware: variants: Add mjpg_encode to the standard firmware image - firmware: vcgencmd display_power and camera_auto_detect fixes - firmware: arm_loader_dvfs: Only add clocks to boostable list when they have been boosted See: #1726 - firmware: arm_dt: Try upstream DTB files if downstream absent - firmware: arm_loader: Delay the USB controller switchover - firmware: Fix for vc_image YUYV family to YUV422 planar conversion function - firmware: arm_loader_dvfs: Only add clocks to boostable list when they have been boosted See: #1726 - firmware: arm_dt: Try upstream DTB files if downstream absent - firmware: arm_loader: Delay the USB controller switchover - firmware: Fix for vc_image YUYV family to YUV422 planar conversion function - firmware: arm_dt: camera_auto_detect cam0 flag needs to look at Unicam instance, not port - firmware: platform: over-voltage Zero 2 W by two pips See: #1723 - firmware: hello_pi: Fix some build issues See: #1728 - firmware: video_decode: Stop decode on a colourspace change See: raspberrypi/linux#5059 - firmware: video_encode: Fix subsample image alignment assert - firmware: tc358762_DSI: Don't start the PV and DSI before the HVS - firmware: arm-dt: Export log buffer addresses to /proc/chosen/log - firmware: arm_loader: Fix GET_CLOCKS to not overwrite client buffer See: #1688 - firmware: arm_loader: Declare program_sdhost_use_dma - firmware: arm_loader: initramfs over NVME fix See: #1731 - firmware: Disable BT flow control pins for Pi3 rev1.3 - firmware: power: Fix failover to secondary PMIC interface functions See: https://forums.raspberrypi.com/viewtopic.php?t=338429 - firmware: arm_loader: Correct GPIO expander initial state via SET_GPIO_CONFIG See: raspberrypi/linux#5107 - firmware: platform: Set min_frequency for HDMI SM clock on Pi0-3 - firmware: arm_loader: Never set warranty bit See: #1741 - firmware: vcfw: camera_subsystem: Fix loop counter for powering up devices See: https://forums.raspberrypi.com/viewtopic.php?t=338917 - firmware: ldconfig: Add [cm4s] conditional - firmware: Fix USB boot See: #1744 - firmware: video decode/MJPEG fixes See: http://git/vc4/vc4/-/merge_requests/1548 - firmware: power: Restore VEC and PIXEL clocks after HDMI domain power cycle See: raspberrypi/linux#4962 - firmware: isp: Workaround for very unpleasant artifacts in the sharpening block - firmware: arm_loader: Raise maximum gzipped kernel size - firmware: arm-loader: Indicate tryboot status via /proc/device-tree/chosen/bootloader/tryboot - firmware: arm_loader: Increase TFTP block size to 1468 bytes See: raspberrypi/rpi-eeprom#375 - firmware: Add kernel= logging - firmware: camera_auto_detect changes See: #1750 - firmware: board_info: Fix Pi 400 PHY addresses See: #1754 - firmware: il: isp: Correct order buffers were returned in - firmware: isp: Run ISP without hi-res output buffer - firmware: arm_dt: Export the bootloader EEPROM RSA public key via device-tree - firmware: Add tryboot A_B mode - firmware: ldconfig: Add all, none, tryboot section support to autoboot.txt for start.elf - firmware: arm-dt: bootloader: Pass the original partition number when booting a ramdisk - firmware: arm_loader: HAT EEPROM support for GPIO bank 1 See: #1756 - firmware: arm_loader: Add vcmailbox support for 256bit OTP customer device key See: raspberrypi/usbboot#163 - firmware: il: video_encode: MJPEG is not conditional on being RASPBERRYPI_FULL - firmware: arm_loader: Improvements to Compute Module audio See: https://forums.raspberrypi.com/viewtopic.php?p=2052680 - firmware: arm_loader: Fix GPIO bank 1 support See: #1756 - firmware: arm_loader: PWM1 is not available on GPIO 45 - firmware: power: Always read the uncached voltage for AIN and USB_PD See: https://forums.raspberrypi.com/viewtopic.php?p=2059832#p2059832 - firmware: Use new SDHCI controller instead of legacy arasan See: #1763 - firmware: Add D flag to video= cmdline option when hotplug is forced - firmware: Actually rebuild firmware described in previous commit - firmware: hdmi_2711: Make some clock setup unconditional so booting without hdmi setup is possible - firmware: arm_dispmanx: Correct support for NV21, and add support for YV16 See: #1767 - firmware: arm_dispmanx: Fix FKMS to adopt pre-multiplied alpha See: #1773 - firmware: il isp: Correct histogram masks for updated group 2 regions - firmware: video_decode: Convert the active lines, not the padded buffer - firmware: bootloader: Raise CMA cap to 512MB on a 64-bit Pi4 - firmware: bootloader: Prefer 64-bit kernels on Pi 4s See: https://forums.raspberrypi.com/viewtopic.php?p=2088935#p2088935 - firmware: platform: clocks: Replace m2mc with hdmi for state machine clock on 2711 - firmware: bootloader: Fix automatic 64bit selection on Pi3s See: https://forums.raspberrypi.com/viewtopic.php?p=2089764#p2089764 - firmware: Handle 64-bitness of named kernels See: #1792 - firmware: gencmd: Add a fallback to mailbox interface if vchiq is not available - firmware: arm_loader: Set local-bd-address if 6 zeroes found - firmware: arm_loader: Really check for a zero local-bd-address See: raspberrypi/linux#5437 - firmware: arm_dt: Don't overwrite existing i2c aliases See: raspberrypi/linux#5428 - firmware: arm_loader: Reduce CMA warning severity See: #1807
Describe the bug
It seems that external GPIOs (controlled through firmware) do not apply the initial state correctly.
I am using the following device tree snippet
The expectation is that this makes the LED to be off by default.
The
leds-gpio
driver uses the gpiod API to initialize the GPIO correctly:https://elixir.bootlin.com/linux/v5.15/source/drivers/leds/leds-gpio.c#L109
The
gpiod_direction_output
API takes care of the polarity flag, and requests a high output from the GPIO driver:https://elixir.bootlin.com/linux/v5.15/source/drivers/gpio/gpiolib.c#L2324
Currently, the value (1) is directly passed to the firmware in
gpio-raspberrypi-exp.c
. The state of the GPIO however is not changed.It seems that the firmware is aware of the polarity configuration on its own, and does not wrongly applies the new value?
This change fixes the problem for that particular use case, but I am not sure if that is correct:
What is interesting to me is that reading back the GPIO seems to return the level "unaltered":
Steps to reproduce the behaviour
Apply the following device tree change:
Observe that the red LED remains on.
Device (s)
Raspberry Pi CM4
System
This is on Home Assistant OS. We are using the latest 5.15 downstream kernel from this repository. As this is a pure kernel issue, this should be the very same on a regular Raspberry Pi.
Logs
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: