Skip to content

Commit 46b8d32

Browse files
committed
pinctrl: Add initial revision
pinctrl is a more flexible replacement for raspi-gpio. It gets its configuration information from Device Tree, and can display and accept GPIO names and header pin numbers. Signed-off-by: Phil Elwell <[email protected]>
1 parent 79ff2c4 commit 46b8d32

File tree

11 files changed

+2234
-0
lines changed

11 files changed

+2234
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ add_subdirectory(dtmerge)
77
add_subdirectory(otpset)
88
add_subdirectory(overlaycheck)
99
add_subdirectory(ovmerge)
10+
add_subdirectory(pinctrl)
1011
add_subdirectory(raspinfo)
1112
add_subdirectory(vclog)

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ A collection of scripts and simple applications
1010
* [ovmerge](ovmerge/) - A tool for merging DT overlay source files (`*-overlay.dts`),
1111
flattening and sorting `.dts` files for easy comparison, displaying
1212
the include tree, etc.
13+
* [pinctrl](pinctrl/) - A more powerful replacement for raspi-gpio, a tool for
14+
displaying and modifying the GPIO and pin muxing state of a system, bypassing
15+
the kernel.
1316
* [raspinfo](raspinfo/) - A short script to dump information about the Pi. Intended for
1417
the submission of bug reports.
1518
* [vclog](vclog/) - A tool to get VideoCore 'assert' or 'msg' logs

pinctrl/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
3+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -pedantic")
4+
5+
#set project name
6+
project(pinctrl)
7+
8+
#add executables
9+
add_executable(pinctrl pinctrl.c gpiolib.c util.c gpiochip_bcm2835.c)
10+
install(TARGETS pinctrl RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

pinctrl/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
# pinctrl
3+
4+
pinctrl is a more powerful replacement for raspi-gpio, a tool for displaying
5+
and modifying the GPIO and pin muxing state of a system. It accesses the
6+
hardware directly, bypassing the kernel drivers, and as such requires root
7+
privilege (run with "sudo").
8+
9+
The improvements over raspi-gpio include:
10+
11+
* GPIO controllers are detected at runtime from Device Tree.
12+
* GPIOs can be referred to by name or number.
13+
* Pin mode (-p) switches the UI to be in terms of 40-way header pin numbers.
14+
* The "poll" command causes it to constantly monitor the specified pins,
15+
displaying any level changes it see. For slow signals (up to a few hundred
16+
kHz) it can act as a basic logic analyser.
17+
* The "get" and "set" keywords are optional in most cases.
18+
* Splitting into a general gpiolib library and a separate client application
19+
allows new applications to be added easily.
20+
21+
**Build Instructions**
22+
23+
Install the prerequisites with "sudo apt install cmake" - you need at least version 3.10 of cmake. Run the following commands, either here or in the top-level directory to build and install everything:
24+
25+
- *cmake .*
26+
- *make*
27+
- *sudo make install*
28+
29+
**Usage**
30+
31+
* `sudo pinctrl` (Display the state of all recognised GPIOs)
32+
* `sudo pinctrl -p` (Show the state of the 40-way header pins)
33+
* `sudo pinctrl 4,6 op dl` (Make GPIOs 4 and 6 outputs, driving low)
34+
* `sudo pinctrl poll BT_CTS,BT_RTS` (Monitor the levels of the Bluetooth flow control signals)
35+
* `pinctrl funcs 9-11` (List the available alternate functions on GPIOs 9, 10 and 11)
36+
* `pinctrl help` (Show the full usage guide)

pinctrl/gpiochip.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#ifndef GPIOCHIP_H
2+
#define GPIOCHIP_H
3+
4+
#include "gpiolib.h"
5+
6+
#define DECLARE_GPIO_CHIP(name, compatible, iface, size, data) \
7+
GPIO_CHIP_T name ## _chip __attribute__ ((section ("gpiochips"))) = \
8+
{ #name, compatible, iface, size, data }
9+
10+
typedef struct GPIO_CHIP_INTERFACE_ GPIO_CHIP_INTERFACE_T;
11+
12+
typedef struct GPIO_CHIP_
13+
{
14+
const char *name;
15+
const char *compatible;
16+
const GPIO_CHIP_INTERFACE_T *interface;
17+
int size;
18+
uintptr_t data;
19+
} GPIO_CHIP_T;
20+
21+
struct GPIO_CHIP_INTERFACE_
22+
{
23+
void * (*gpio_create_instance)(const GPIO_CHIP_T *chip, const char *dtnode);
24+
int (*gpio_count)(void *priv);
25+
void * (*gpio_probe_instance)(void *priv, volatile uint32_t *base);
26+
GPIO_FSEL_T (*gpio_get_fsel)(void *priv, uint32_t gpio);
27+
void (*gpio_set_fsel)(void *priv, uint32_t gpio, const GPIO_FSEL_T func);
28+
void (*gpio_set_drive)(void *priv, uint32_t gpio, GPIO_DRIVE_T drv);
29+
void (*gpio_set_dir)(void *priv, uint32_t gpio, GPIO_DIR_T dir);
30+
GPIO_DIR_T (*gpio_get_dir)(void *priv, uint32_t gpio);
31+
int (*gpio_get_level)(void *priv, uint32_t gpio); /* The actual level observed */
32+
GPIO_DRIVE_T (*gpio_get_drive)(void *priv, uint32_t gpio); /* What it is being driven as */
33+
GPIO_PULL_T (*gpio_get_pull)(void *priv, uint32_t gpio);
34+
void (*gpio_set_pull)(void *priv, uint32_t gpio, GPIO_PULL_T pull);
35+
const char * (*gpio_get_name)(void *priv, uint32_t gpio);
36+
const char * (*gpio_get_fsel_name)(void *priv, uint32_t gpio, GPIO_FSEL_T fsel);
37+
};
38+
39+
extern const GPIO_CHIP_T __start_gpiochips;
40+
extern const GPIO_CHIP_T __stop_gpiochips;
41+
42+
#endif

pinctrl/gpiochip_bcm2835.c

Lines changed: 462 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)