mt7621 GPIO mapping mystery

Arınç ÜNAL arinc.unal at arinc9.com
Sat Jan 21 13:19:59 PST 2023


On 21.01.2023 21:32, Daniel Santos wrote:
> Hello all,
> 
> I saw this a few days ago, but was too busy to answer then -- sorry 
> about that. I've dug into this code a bit, but for the mt7620.
> 
> On 1/21/23 08:51, Sergio Paracuellos wrote:
>> Hi,
>>
>> [+cc John Crispin]
>>
>> On Sat, Jan 21, 2023 at 2:45 PM Arınç ÜNAL <arinc.unal at arinc9.com> wrote:
>>> On 21.01.2023 10:56, Sergio Paracuellos wrote:
>>>> Hi,
>>>>
>>>> On Sat, Jan 21, 2023 at 7:03 AM Arınç ÜNAL <arinc.unal at arinc9.com> 
>>>> wrote:
>>>>> Pins from 22 to 33 are on the rgmii2 pin group. They don't function as
>>>>> GPIO by default. Requesting a gpio by either from devicetree or `echo
>>>>> 203 >  /sys/class/gpio/export` won't change anything. You have to 
>>>>> claim
>>>>> the pin group as gpio on the devicetree.
>>>> Yes, you have to claim the pin group as gpio on the device tree to
>>>> make this work. Ralink has the concept of "GPIO mode" but actually is
>>>> just an electrical configuration for a certain device. So if the mode
>>>> (function) is not requested as a real GPIO nothing is going to work.
>>>> So in your board's dts file you have to add something like the
>>>> following with the groups you want to claim as real gpio function:
>>>>
>>>> #include "mt7621.dtsi"
>>>> ...
>>>>
>>>> &state_default {
>>>>       gpio {
>>>>           groups = "jtag", "uart3", "wdt";
>>>>           function = "gpio";
>>>>       };
>>>> };
> 
> First of all, to better understand what you're working with I highly 
> recommend you download the mt7621 Data Sheet and took at §2.4 Pin 
> Sharing Schemes. Here's a link to one I've found: 
> https://www.t-firefly.com/download/FireWRT/hardware/MT7621.pdf . 
> Microcontrollers come with a lot of nifty hardware -- more than they 
> have external pins for.  So if you don't need a piece of hardware, you 
> can option to use that pin as a GPIO instead.
> 
> The kernel code for the other end of this device tree snippet that 
> Sergio gave you is in arch/mips/ralink/mt7621.c, which you'll probably 
> find in your OpenWRT build tree under 
> build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/linux-5.4.143/. 
> The various struct rt2880_pmx_func variables contain the valid values 
> for each of these sets of pins except for "gpio" -- which is implicit 
> for each one (not my favorite design choice, but oh well). Finally, each 
> of those are glued together with the struct rt2880_pmx_group 
> mt7621_pinmux_data[] array on line 96. You can use this to see what the 
> valid values are for each group, because until this all goes yaml, 
> there's nothing to tell you if you've used an invalid value.

Speaking of which:

https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl.git/commit/?h=for-next&id=4e5410668af5475681793df2bb8c7d8dc6f9c327

https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl.git/commit/?h=for-next&id=0c9a567651c3b5d433429da2c7d8e8406ddf1076

https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl.git/commit/?h=for-next&id=b4ac84395820eaa0b99ec56816e53c9386ca8b38

https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl.git/commit/?h=for-next&id=d648fd64e10d9d1609146d0c4e47b0f5988e2a2b

https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl.git/commit/?h=for-next&id=844bca60927f3aae6baafafb1edd218b624254a1

Arınç



More information about the openwrt-devel mailing list