Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] arm64: dts: rockchip: Add CD GPIO to Orange Pi 5/5B/5Pro
@ 2026-11-21  7:03 Dang Huynh
  2026-11-26  9:56 ` Quentin Schulz
  0 siblings, 1 reply; 5+ messages in thread
From: Dang Huynh @ 2026-11-21  7:03 UTC (permalink / raw)
  To: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Heiko Stuebner
  Cc: devicetree, linux-arm-kernel, linux-rockchip, Dang Huynh

CD GPIO is currently not defined in Orange Pi 5, this breaks
SD card hotplugging.

The SDMMC_DET_L pin is connected to GPIO0_A4 on both OPi 5[0],
OPi 5B[1] and OPi 5 Pro[2].

[0]: https://drive.google.com/file/d/1Wsp-Q7IyG0Ky_W-z1n5oXcFG4oqIbtOb/view?usp=sharing
[1]: https://drive.google.com/file/d/19iPdpAXhA1vFkVOgG5Sz7L6cV8BB6004/view?usp=sharing
[2]: https://drive.google.com/file/d/1qs1DratHuh7C6J6MEtQIwUsiSrg8qgTi/view?usp=sharing

Signed-off-by: Dang Huynh <dang.huynh@mainlining.org>
---
 arch/arm64/boot/dts/rockchip/rk3588s-orangepi-5.dtsi | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm64/boot/dts/rockchip/rk3588s-orangepi-5.dtsi b/arch/arm64/boot/dts/rockchip/rk3588s-orangepi-5.dtsi
index 2db6ee95e504..8fbb0ba19b74 100644
--- a/arch/arm64/boot/dts/rockchip/rk3588s-orangepi-5.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3588s-orangepi-5.dtsi
@@ -282,6 +282,7 @@ &sdhci {
 &sdmmc {
 	bus-width = <4>;
 	cap-sd-highspeed;
+	cd-gpios = <&gpio0 RK_PA4 GPIO_ACTIVE_LOW>;
 	disable-wp;
 	max-frequency = <150000000>;
 	no-mmc;

---
base-commit: 909ef7a9a30fa139e69e555e3606680f5cca7726
change-id: 20261121-orange-pi-5-sdcard-98cbfa3c12e7

Best regards,
--  
Dang Huynh <dang.huynh@mainlining.org>


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] arm64: dts: rockchip: Add CD GPIO to Orange Pi 5/5B/5Pro
  2026-11-21  7:03 [PATCH] arm64: dts: rockchip: Add CD GPIO to Orange Pi 5/5B/5Pro Dang Huynh
@ 2026-11-26  9:56 ` Quentin Schulz
  2026-11-28  6:18   ` Dang Huynh
  2026-12-01 11:32   ` Alexey Charkov
  0 siblings, 2 replies; 5+ messages in thread
From: Quentin Schulz @ 2026-11-26  9:56 UTC (permalink / raw)
  To: Dang Huynh, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Heiko Stuebner
  Cc: devicetree, linux-arm-kernel, linux-rockchip

Hi Dang,

On 11/21/26 8:03 AM, Dang Huynh wrote:
> CD GPIO is currently not defined in Orange Pi 5, this breaks
> SD card hotplugging.

That's not the issue. The issue is that the card detect signal is muxed 
in the SDMMC_DET function (c.f. sdmmc_det in rk3588-base.dtsi) and that 
relies on the SDMMC controller being powered on to detect such an event. 
This cannot work when the controller is in runtime suspend, so we have a 
chicken and the egg problem. The card detect should resume the 
controller, but it can only work when the controller is running. Hence 
why we now go for the gpio function (via cd-gpios) instead. See
c7a9549ce46e ("arm64: dts: rockchip: Switch microSD card detect to gpio 
on Radxa ROCK 5 ITX/5C") for an example.> > The SDMMC_DET_L pin is 
connected to GPIO0_A4 on both OPi 5[0],
> OPi 5B[1] and OPi 5 Pro[2].
> 
> [0]: https://drive.google.com/file/d/1Wsp-Q7IyG0Ky_W-z1n5oXcFG4oqIbtOb/view?usp=sharing
> [1]: https://drive.google.com/file/d/19iPdpAXhA1vFkVOgG5Sz7L6cV8BB6004/view?usp=sharing
> [2]: https://drive.google.com/file/d/1qs1DratHuh7C6J6MEtQIwUsiSrg8qgTi/view?usp=sharing
> 
> Signed-off-by: Dang Huynh <dang.huynh@mainlining.org>
> ---
>   arch/arm64/boot/dts/rockchip/rk3588s-orangepi-5.dtsi | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/arch/arm64/boot/dts/rockchip/rk3588s-orangepi-5.dtsi b/arch/arm64/boot/dts/rockchip/rk3588s-orangepi-5.dtsi
> index 2db6ee95e504..8fbb0ba19b74 100644
> --- a/arch/arm64/boot/dts/rockchip/rk3588s-orangepi-5.dtsi
> +++ b/arch/arm64/boot/dts/rockchip/rk3588s-orangepi-5.dtsi
> @@ -282,6 +282,7 @@ &sdhci {
>   &sdmmc {
>   	bus-width = <4>;
>   	cap-sd-highspeed;
> +	cd-gpios = <&gpio0 RK_PA4 GPIO_ACTIVE_LOW>;

issue: missing pinmuxing

You need to configure the pinmux and pinconf for this pin (via pinctrl-0 
and we require repeating pinctrl-names wherever pinctrl-0 is modified).

Cheers,
Quentin


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] arm64: dts: rockchip: Add CD GPIO to Orange Pi 5/5B/5Pro
  2026-11-26  9:56 ` Quentin Schulz
@ 2026-11-28  6:18   ` Dang Huynh
  2026-12-02 10:40     ` Quentin Schulz
  2026-12-01 11:32   ` Alexey Charkov
  1 sibling, 1 reply; 5+ messages in thread
From: Dang Huynh @ 2026-11-28  6:18 UTC (permalink / raw)
  To: Quentin Schulz
  Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Heiko Stuebner,
	devicetree, linux-arm-kernel, linux-rockchip

Hi Quentin,

On Thu, Nov 26, 2026 at 10:56:12AM +0100, Quentin Schulz wrote:
> Hi Dang,
> 
> On 11/21/26 8:03 AM, Dang Huynh wrote:
> > CD GPIO is currently not defined in Orange Pi 5, this breaks
> > SD card hotplugging.
> 
> That's not the issue. The issue is that the card detect signal is muxed in
> the SDMMC_DET function (c.f. sdmmc_det in rk3588-base.dtsi) and that relies
> on the SDMMC controller being powered on to detect such an event. This
> cannot work when the controller is in runtime suspend, so we have a chicken
> and the egg problem. The card detect should resume the controller, but it
> can only work when the controller is running. Hence why we now go for the
> gpio function (via cd-gpios) instead. See
> c7a9549ce46e ("arm64: dts: rockchip: Switch microSD card detect to gpio on
> Radxa ROCK 5 ITX/5C") for an example.
Interesting, I didn't know that the controller could do that. You learn
something new every day I guess.

> > diff --git a/arch/arm64/boot/dts/rockchip/rk3588s-orangepi-5.dtsi b/arch/arm64/boot/dts/rockchip/rk3588s-orangepi-5.dtsi
> > index 2db6ee95e504..8fbb0ba19b74 100644
> > --- a/arch/arm64/boot/dts/rockchip/rk3588s-orangepi-5.dtsi
> > +++ b/arch/arm64/boot/dts/rockchip/rk3588s-orangepi-5.dtsi
> > @@ -282,6 +282,7 @@ &sdhci {
> >   &sdmmc {
> >   	bus-width = <4>;
> >   	cap-sd-highspeed;
> > +	cd-gpios = <&gpio0 RK_PA4 GPIO_ACTIVE_LOW>;
> 
> issue: missing pinmuxing
> 
> You need to configure the pinmux and pinconf for this pin (via pinctrl-0 and
> we require repeating pinctrl-names wherever pinctrl-0 is modified).
pinmux/pinconf is already defined in rk3588-base-pinctrl.dtsi for this
exact GPIO. I guess this is in case when controller's card detect works?

> 
> Cheers,
> Quentin

Best regards,
Dang


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] arm64: dts: rockchip: Add CD GPIO to Orange Pi 5/5B/5Pro
  2026-11-26  9:56 ` Quentin Schulz
  2026-11-28  6:18   ` Dang Huynh
@ 2026-12-01 11:32   ` Alexey Charkov
  1 sibling, 0 replies; 5+ messages in thread
From: Alexey Charkov @ 2026-12-01 11:32 UTC (permalink / raw)
  To: Quentin Schulz
  Cc: Dang Huynh, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Heiko Stuebner, devicetree, linux-arm-kernel, linux-rockchip

On Thu, Nov 26, 2026 at 1:56 PM Quentin Schulz <quentin.schulz@cherry.de> wrote:
>
> Hi Dang,
>
> On 11/21/26 8:03 AM, Dang Huynh wrote:
> > CD GPIO is currently not defined in Orange Pi 5, this breaks
> > SD card hotplugging.
>
> That's not the issue. The issue is that the card detect signal is muxed
> in the SDMMC_DET function (c.f. sdmmc_det in rk3588-base.dtsi) and that
> relies on the SDMMC controller being powered on to detect such an event.
> This cannot work when the controller is in runtime suspend, so we have a
> chicken and the egg problem. The card detect should resume the
> controller, but it can only work when the controller is running. Hence
> why we now go for the gpio function (via cd-gpios) instead. See
> c7a9549ce46e ("arm64: dts: rockchip: Switch microSD card detect to gpio
> on Radxa ROCK 5 ITX/5C") for an example.> > The SDMMC_DET_L pin is
> connected to GPIO0_A4 on both OPi 5[0],

FWIW, I've done some testing on RK3576, which I believe uses the same
IP block for the SDMMC controller. Long story short:

- Native card detection via the controller itself works only as long
as the PD_SDGMAC power domain is on (on RK3576 either of the two GMACs
keep it on, so it only can go off if both of them are disabled and the
SDMMC controller is runtime suspended)
- To have the controller enumerate the card after detection, I needed
to add `card-detect-delay` of 200ms, in line with what cd-gpios does
on Linux. Without it the detection bit is latched but the card doesn't
show up in the system
- If the power domain is off, the controller doesn't get CD events,
and after PD_SDGMAC is powered back on its INTMASK, CTRL and PWEN come
back as all zeros
- The TRM specifies another card detection mechanism ("method 3") via
the always-on PMU1_GRF (SD_DETECT_CON/STS/CLR/CNT at 0x26026110–0x11c,
IRQ 282 irq_sdmmc_detectn_grf), and it latches just fine when the
controller is suspended with its power domain off. But frankly I don't
see any benefit in using this method over cd-gpios, given that at
least on RK3576 the pin in question is part of the GPIO0 domain, which
is always-on just as well.

So cd-gpios with matching pinctrl sounds like the right way to go for
all boards.

Best regards,
Alexey


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] arm64: dts: rockchip: Add CD GPIO to Orange Pi 5/5B/5Pro
  2026-11-28  6:18   ` Dang Huynh
@ 2026-12-02 10:40     ` Quentin Schulz
  0 siblings, 0 replies; 5+ messages in thread
From: Quentin Schulz @ 2026-12-02 10:40 UTC (permalink / raw)
  To: Dang Huynh
  Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Heiko Stuebner,
	devicetree, linux-arm-kernel, linux-rockchip

Hi Dang,

On 11/28/26 7:18 AM, Dang Huynh wrote:
> Hi Quentin,
> 
> On Thu, Nov 26, 2026 at 10:56:12AM +0100, Quentin Schulz wrote:
>> Hi Dang,
>>
>> On 11/21/26 8:03 AM, Dang Huynh wrote:
>>> CD GPIO is currently not defined in Orange Pi 5, this breaks
>>> SD card hotplugging.
>>
>> That's not the issue. The issue is that the card detect signal is muxed in
>> the SDMMC_DET function (c.f. sdmmc_det in rk3588-base.dtsi) and that relies
>> on the SDMMC controller being powered on to detect such an event. This
>> cannot work when the controller is in runtime suspend, so we have a chicken
>> and the egg problem. The card detect should resume the controller, but it
>> can only work when the controller is running. Hence why we now go for the
>> gpio function (via cd-gpios) instead. See
>> c7a9549ce46e ("arm64: dts: rockchip: Switch microSD card detect to gpio on
>> Radxa ROCK 5 ITX/5C") for an example.
> Interesting, I didn't know that the controller could do that. You learn
> something new every day I guess.
> 
>>> diff --git a/arch/arm64/boot/dts/rockchip/rk3588s-orangepi-5.dtsi b/arch/arm64/boot/dts/rockchip/rk3588s-orangepi-5.dtsi
>>> index 2db6ee95e504..8fbb0ba19b74 100644
>>> --- a/arch/arm64/boot/dts/rockchip/rk3588s-orangepi-5.dtsi
>>> +++ b/arch/arm64/boot/dts/rockchip/rk3588s-orangepi-5.dtsi
>>> @@ -282,6 +282,7 @@ &sdhci {
>>>    &sdmmc {
>>>    	bus-width = <4>;
>>>    	cap-sd-highspeed;
>>> +	cd-gpios = <&gpio0 RK_PA4 GPIO_ACTIVE_LOW>;
>>
>> issue: missing pinmuxing
>>
>> You need to configure the pinmux and pinconf for this pin (via pinctrl-0 and
>> we require repeating pinctrl-names wherever pinctrl-0 is modified).
> pinmux/pinconf is already defined in rk3588-base-pinctrl.dtsi for this
> exact GPIO. I guess this is in case when controller's card detect works?
> 

The default pinconf is incorrect as it muxes the pin in function 1 
instead of RK_FUNC_GPIO (function 0). What you need is something along 
the lines of:

&sdmmc {
     pinctrl-0 = <&sdmmc_clk &sdmmc_cmd &sdmmc_det_gpio &sdmmc_bus4>;
     pinctrl-names = "default";
     cd-gpios = <&gpio0 RK_PA4 GPIO_ACTIVE_LOW>;
};

&pinctrl {
     sdmmc {
         sdmmc_det_gpio: sdmmc-det-gpio-pin {
             rockchip,pins = <0 RK_PA4 RK_FUNC_GPIO &pcfg_pull_up>;
         };
     };
};

Cheers,
Quentin


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-12-02 10:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-21  7:03 [PATCH] arm64: dts: rockchip: Add CD GPIO to Orange Pi 5/5B/5Pro Dang Huynh
2026-11-26  9:56 ` Quentin Schulz
2026-11-28  6:18   ` Dang Huynh
2026-12-02 10:40     ` Quentin Schulz
2026-12-01 11:32   ` Alexey Charkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox