Difference between revisions of "EBC Exercise 51 GPIO aggregator"

From eLinux.org
Jump to: navigation, search
m (Install: Switched to group gpio)
m (Test it)
 
(One intermediate revision by the same user not shown)
Line 29: Line 29:
 
  bone$ '''ls -ls'''
 
  bone$ '''ls -ls'''
 
  total 0
 
  total 0
  0 --w--w---- 1 root debian 4096 Jul 29 11:09 bind
+
  0 --w--w---- 1 root gpio 4096 Jul 29 11:09 bind
  0 --w--w---- 1 root debian 4096 Jul 29 11:09 delete_device
+
  0 --w--w---- 1 root gpio 4096 Jul 29 11:09 delete_device
  0 lrwxrwxrwx 1 root root     0 Jul 29 10:57 module -> ../../../../module/gpio_aggregator
+
  0 lrwxrwxrwx 1 root root   0 Jul 29 10:57 module -> ../../../../module/gpio_aggregator
  0 --w--w---- 1 root debian 4096 Jul 29 11:09 new_device
+
  0 --w--w---- 1 root gpio 4096 Jul 29 11:09 new_device
  0 --w--w---- 1 root debian 4096 Jul 29 11:09 uevent
+
  0 --w--w---- 1 root gpio 4096 Jul 29 11:09 uevent
  0 --w--w---- 1 root debian 4096 Jul 29 11:09 unbind
+
  0 --w--w---- 1 root gpio 4096 Jul 29 11:09 unbind
 
  bone$ '''gpiodetect'''  
 
  bone$ '''gpiodetect'''  
 
  gpiochip0 [gpio-0-31] (32 lines)
 
  gpiochip0 [gpio-0-31] (32 lines)
Line 40: Line 40:
 
  gpiochip2 [gpio-64-95] (32 lines)
 
  gpiochip2 [gpio-64-95] (32 lines)
 
  gpiochip3 [gpio-96-127] (32 lines)
 
  gpiochip3 [gpio-96-127] (32 lines)
  bone$ '''echo "gpio-0-31 0,2 gpio-32-63 1" > new_device '''
+
 
 +
== Map pins ==
 +
Let's map P9_14, P9_16, P9_18 and P9_22 to lines 0-3 on a new gpiochip.
 +
 
 +
  bone$ '''gpioinfo | grep -e chip -e P9_1[468] -e P9_22'''
 +
gpiochip0 - 32 lines:
 +
line  2: "P9_22 [spi0_sclk]" "gpio-aggregator.0" input active-high [used]
 +
line  4: "P9_18 [spi0_d1]" "gpio-aggregator.0" output active-high [used]
 +
gpiochip1 - 32 lines:
 +
line  18: "P9_14 [ehrpwm1a]" "gpio-aggregator.0" output active-high [used]
 +
line  19: "P9_16 [ehrpwm1b]" "gpio-aggregator.0" input active-high [used]
 +
gpiochip2 - 32 lines:
 +
gpiochip3 - 32 lines:
 +
{| class="wikitable"
 +
|-
 +
! Header !! gpiochip || line
 +
|-
 +
| P9_14 || 1 || 18
 +
|-
 +
| P9_16 || 1 || 19
 +
|-
 +
| P9_18 || 0 || 4
 +
|-
 +
| P9_22 || 0 || 2
 +
|}
 +
bone$ '''echo "gpio-32-63 18,19 gpio-0-31 4,2" > new_device'''
 
  bone$ '''ls'''
 
  bone$ '''ls'''
 
  bind  delete_device  gpio-aggregator.0  module  new_device  uevent  unbind
 
  bind  delete_device  gpio-aggregator.0  module  new_device  uevent  unbind
Line 46: Line 71:
 
  driver  driver_override  gpio  gpiochip4  modalias  power  subsystem  uevent
 
  driver  driver_override  gpio  gpiochip4  modalias  power  subsystem  uevent
 
  bone$ '''gpioinfo | tail -6'''
 
  bone$ '''gpioinfo | tail -6'''
line  30:        "NC"      unused  input  active-high 
 
 
  line  31:        "NC"      unused  input  active-high  
 
  line  31:        "NC"      unused  input  active-high  
  gpiochip4 - 3 lines:
+
  gpiochip4 - 4 lines:
  line  0:      unnamed      unused   input active-high  
+
  line  0:      unnamed      unused output active-high  
 
  line  1:      unnamed      unused  input  active-high  
 
  line  1:      unnamed      unused  input  active-high  
  line  2:      unnamed      unused  input  active-high
+
  line  2:      unnamed      unused  input  active-high  
 +
line  3:      unnamed      unused  output  active-high
 +
 
 
  bone$ '''gpiodetect '''
 
  bone$ '''gpiodetect '''
 
  gpiochip0 [gpio-0-31] (32 lines)
 
  gpiochip0 [gpio-0-31] (32 lines)
Line 57: Line 83:
 
  gpiochip2 [gpio-64-95] (32 lines)
 
  gpiochip2 [gpio-64-95] (32 lines)
 
  gpiochip3 [gpio-96-127] (32 lines)
 
  gpiochip3 [gpio-96-127] (32 lines)
  gpiochip4 [gpio-aggregator.0] (3 lines)
+
  gpiochip4 [gpio-aggregator.0] (4 lines)
 +
There's a new gpiochip, '''gpiochip4'''
 +
 
 +
== Test it ==
 +
The new mappings are:
 +
{| class="wikitable"
 +
|-
 +
! Header !! gpiochip || line
 +
|-
 +
| P9_14 || 4 || 0
 +
|-
 +
| P9_16 || 4 || 1
 +
|-
 +
| P9_18 || 4 || 2
 +
|-
 +
| P9_22 || 4 || 3
 +
|}
 +
 
 +
Turn them all on, then off.  Since they are all now on the same chip, one command can be used.
 +
bone$ '''gpioset gpiochip4 0=1 1=1 2=1 3=1'''
 +
bone$ '''gpioset gpiochip4 0=0 1=0 2=0 3=0'''
 +
 
 +
It's interesting the LEDs stay on, even after the command exits.  Normally gpioset returns to it's original state.
 +
 
 +
== Delete it ==
 
  bone$ '''echo gpio-aggregator.0 > delete_device '''
 
  bone$ '''echo gpio-aggregator.0 > delete_device '''
  
 
{{YoderFoot}}
 
{{YoderFoot}}

Latest revision as of 11:03, 29 July 2022

thumb‎ Embedded Linux Class by Mark A. Yoder


Here are some quick notes on the GPIO aggregator which allows one to group a number of GPIOs into a virtual GPIO chip, visible as an additional /dev/gpiochip*. Its documentation can be found in Documentation/admin-guide/gpio/gpio-aggregator.rst.

My info comes from:

https://bootlin.com/blog/gpio-aggregator-a-virtual-gpio-chip/

https://elixir.bootlin.com/linux/v5.12/source/Documentation/admin-guide/gpio/gpio-aggregator.rst

https://elinux.org/images/c/cb/Linux_GPIO-Evolution_and_Current_State_of_the_User_API.pdf

Install

bone$ grep -i gpio_agg /boot/config-5.10.120-ti-r48 
CONFIG_GPIO_AGGREGATOR=m
bone$ sudo modprobe gpio-aggregator
bone$ cd /sys/bus/platform/drivers/gpio-aggregator
bone$ ls -ls
total 0
0 --w------- 1 root root 4096 Jul 29 10:57 bind
0 --w------- 1 root root 4096 Jul 29 10:57 delete_device
0 lrwxrwxrwx 1 root root    0 Jul 29 10:57 module -> ../../../../module/gpio_aggregator
0 --w------- 1 root root 4096 Jul 29 10:57 new_device
0 --w------- 1 root root 4096 Jul 29 10:56 uevent
0 --w------- 1 root root 4096 Jul 29 10:57 unbind
bone$ sudo chgrp gpio *
bone$ sudo chmod g+w *
bone$ ls -ls
total 0
0 --w--w---- 1 root gpio 4096 Jul 29 11:09 bind
0 --w--w---- 1 root gpio 4096 Jul 29 11:09 delete_device
0 lrwxrwxrwx 1 root root    0 Jul 29 10:57 module -> ../../../../module/gpio_aggregator
0 --w--w---- 1 root gpio 4096 Jul 29 11:09 new_device
0 --w--w---- 1 root gpio 4096 Jul 29 11:09 uevent
0 --w--w---- 1 root gpio 4096 Jul 29 11:09 unbind
bone$ gpiodetect 
gpiochip0 [gpio-0-31] (32 lines)
gpiochip1 [gpio-32-63] (32 lines)
gpiochip2 [gpio-64-95] (32 lines)
gpiochip3 [gpio-96-127] (32 lines)

Map pins

Let's map P9_14, P9_16, P9_18 and P9_22 to lines 0-3 on a new gpiochip.

bone$ gpioinfo | grep -e chip -e P9_1[468] -e P9_22
gpiochip0 - 32 lines: 
	line   2: "P9_22 [spi0_sclk]" "gpio-aggregator.0" input active-high [used]
	line   4: "P9_18 [spi0_d1]" "gpio-aggregator.0" output active-high [used]
gpiochip1 - 32 lines:
	line  18: "P9_14 [ehrpwm1a]" "gpio-aggregator.0" output active-high [used]
	line  19: "P9_16 [ehrpwm1b]" "gpio-aggregator.0" input active-high [used]
gpiochip2 - 32 lines:
gpiochip3 - 32 lines:
Header gpiochip line
P9_14 1 18
P9_16 1 19
P9_18 0 4
P9_22 0 2
bone$ echo "gpio-32-63 18,19 gpio-0-31 4,2" > new_device
bone$ ls
bind  delete_device  gpio-aggregator.0  module  new_device  uevent  unbind
bone$ ls gpio-aggregator.0
driver  driver_override  gpio  gpiochip4  modalias  power  subsystem  uevent
bone$ gpioinfo | tail -6
	line  31:         "NC"       unused   input  active-high 
gpiochip4 - 4 lines:
	line   0:      unnamed       unused  output  active-high 
	line   1:      unnamed       unused   input  active-high 
	line   2:      unnamed       unused   input  active-high 
	line   3:      unnamed       unused  output  active-high 
bone$ gpiodetect 
gpiochip0 [gpio-0-31] (32 lines)
gpiochip1 [gpio-32-63] (32 lines)
gpiochip2 [gpio-64-95] (32 lines)
gpiochip3 [gpio-96-127] (32 lines)
gpiochip4 [gpio-aggregator.0] (4 lines)

There's a new gpiochip, gpiochip4

Test it

The new mappings are:

Header gpiochip line
P9_14 4 0
P9_16 4 1
P9_18 4 2
P9_22 4 3

Turn them all on, then off. Since they are all now on the same chip, one command can be used.

bone$ gpioset gpiochip4 0=1 1=1 2=1 3=1
bone$ gpioset gpiochip4 0=0 1=0 2=0 3=0

It's interesting the LEDs stay on, even after the command exits. Normally gpioset returns to it's original state.

Delete it

bone$ echo gpio-aggregator.0 > delete_device 




thumb‎ Embedded Linux Class by Mark A. Yoder