shengshixiang
Posts: 10
Joined: Wed Sep 09, 2020 2:13 am

Why does the function of the pin change after the screen sleeps?

Fri May 28, 2021 3:37 am

Hello everyone, I add the following code to the dt-blob.bin file:

Code: Select all

pin@p44 { function = "i2c0"; termination = "pull_up"; }; 
pin@p45 { function = "i2c0"; termination = "pull_up"; }; 
After restarting, execute raspi-gpio get and find that gpio44 and gpio45 have been configured successfully.

Code: Select all

GPIO 44: level=1 fsel=5 alt=1 func=SDA0 pull=NONE
GPIO 45: level=1 fsel=5 alt=1 func=SCL0 pull=NONE
But when the screen sleeps, the function of the pin changes:

Code: Select all

GPIO 44: level=1 fsel=0 func=INPUT pull=NONE
GPIO 45: level=1 fsel=0 func=INPUT pull=NONE
For comparison, I tried to map i2c1 to gpio2 and gpio3, and found that after the screen sleeps, gpio2 and gpio3 are still pins of i2c1.

Why is the function configuration of the gpio44 and gpio45 pins changed? Is the GPU program changing the function of the pins?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 11447
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Why does the function of the pin change after the screen sleeps?

Fri May 28, 2021 8:06 am

The firmware automatically manages the GPIO muxing for the I2C buses that it controls.
You should never change the pinmuxing for i2c0 from Linux on firmware owned resources.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

shengshixiang
Posts: 10
Joined: Wed Sep 09, 2020 2:13 am

Re: Why does the function of the pin change after the screen sleeps?

Fri May 28, 2021 8:16 am

6by9 wrote:
Fri May 28, 2021 8:06 am
The firmware automatically manages the GPIO muxing for the I2C buses that it controls.
You should never change the pinmuxing for i2c0 from Linux on firmware owned resources.
Very happy to get your reply. I want to know the function of the firmware configuration gpio44 and gpio45, is it only configured at startup, or can the alternative function be changed after entering the system?

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

Re: Why does the function of the pin change after the screen sleeps?

Fri May 28, 2021 8:44 am

As it says in the Compute Module Attaching and Enabling Peripherals Guide:
For example, the Raspberry Pi Camera peripheral is managed by the GPU, and the GPU needs exclusive access to an I2C interface to talk to it, as well as a couple of control pins. I2C0 on most Pi Boards and Compute Modules is nominally reserved for exclusive GPU use.
On Compute Module 3 (and 3+), I2C0 is used to drive the SMPS and GPIO expander using GPIOs 46 and 47. It isn't possible to have the same I2C interface mapped in multiple places - none of them will work - so the firmware has to forcibly unmap I2C0 from any other pins that might be using it. If the other user is also the firmware, e.g. for camera use, then it can switch back again as needed, but the kernel is unaware of the change which leads to the situation you have encountered.

Using an I2C multiplexer can help to work around the problem by getting the kernel to change the pin mapping on demand - see viewtopic.php?t=293632 - but contention is always a possibility.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 11447
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Why does the function of the pin change after the screen sleeps?

Fri May 28, 2021 2:43 pm

PhilE wrote:
Fri May 28, 2021 8:44 am
As it says in the Compute Module Attaching and Enabling Peripherals Guide:
For example, the Raspberry Pi Camera peripheral is managed by the GPU, and the GPU needs exclusive access to an I2C interface to talk to it, as well as a couple of control pins. I2C0 on most Pi Boards and Compute Modules is nominally reserved for exclusive GPU use.
On Compute Module 3 (and 3+), I2C0 is used to drive the SMPS and GPIO expander using GPIOs 46 and 47.
I thought we'd reverted to bitbashing the I2C for SMPS and GPIO expander on all platforms. Only Pi4/400 and CM4 use a hardware I2C block (not one shared with the ARM).
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

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

Re: Why does the function of the pin change after the screen sleeps?

Fri May 28, 2021 3:30 pm

That's true, for any even vaguely recent firmware, and yet it must be that mechanism which is causing the interference. Which usage of I2C0 by the firmware do you think is problematic?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 11447
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Why does the function of the pin change after the screen sleeps?

Fri May 28, 2021 4:35 pm

PhilE wrote:
Fri May 28, 2021 3:30 pm
That's true, for any even vaguely recent firmware, and yet it must be that mechanism which is causing the interference. Which usage of I2C0 by the firmware do you think is problematic?
My next question to the OP is which touchscreen are you using?

Pi 7" DSI display uses I2C on GPIOs 44&45, and if it closes the I2C interface it will restore the original state of the pins. There is no need to do any config of the pin muxing from dt-blob.bin, only define which GPIOs are to be used via DISPLAY_SDA and DISPLAY_SCL.

If an alternate panel being driven from the Linux kernel, then setting pinmux modes from config.txt or dt-blob.bin is the wrong approach, and the kernel will take care of the muxing for accesses to i2c-10 (44&45) and i2c-0 (0&1). Does something make an access to i2c-0 when your screen blanks?

Full output from "raspi-gpio get" needed to see whether alternate pins are muxed to SDA0/SCL0, and a bit more information needed.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Return to “Compute Module”