raw/cnxk_gpio: add standard GPIO operations
[dpdk.git] / doc / guides / rawdevs / cnxk_gpio.rst
1 ..  SPDX-License-Identifier: BSD-3-Clause
2     Copyright(c) 2021 Marvell.
3
4 Marvell CNXK GPIO Driver
5 ========================
6
7 CNXK GPIO PMD configures and manages GPIOs available on the system using
8 standard enqueue/dequeue mechanism offered by raw device abstraction. PMD relies
9 both on standard sysfs GPIO interface provided by the Linux kernel and GPIO
10 kernel driver custom interface allowing one to install userspace interrupt
11 handlers.
12
13 Features
14 --------
15
16 Following features are available:
17
18 - export/unexport a GPIO
19 - read/write specific value from/to exported GPIO
20 - set GPIO direction
21 - set GPIO edge that triggers interrupt
22 - set GPIO active low
23 - register interrupt handler for specific GPIO
24
25 Requirements
26 ------------
27
28 PMD relies on modified kernel GPIO driver which exposes ``ioctl()`` interface
29 for installing interrupt handlers for low latency signal processing.
30
31 Driver is shipped with Marvell SDK.
32
33 Device Setup
34 ------------
35
36 CNXK GPIO PMD binds to virtual device which gets created by passing
37 `--vdev=cnxk_gpio,gpiochip=<number>` command line to EAL. `gpiochip` parameter
38 tells PMD which GPIO controller should be used. Available controllers are
39 available under `/sys/class/gpio`. For further details on how Linux represents
40 GPIOs in userspace please refer to
41 `sysfs.txt <https://www.kernel.org/doc/Documentation/gpio/sysfs.txt>`_.
42
43 If `gpiochip=<number>` was omitted then first gpiochip from the alphabetically
44 sort list of available gpiochips is used.
45
46 .. code-block:: console
47
48    $ ls /sys/class/gpio
49    export gpiochip448 unexport
50
51 In above scenario only one GPIO controller is present hence
52 `--vdev=cnxk_gpio,gpiochip=448` should be passed to EAL.
53
54 Before performing actual data transfer one needs to call
55 ``rte_rawdev_queue_count()`` followed by ``rte_rawdev_queue_conf_get()``. The
56 former returns number GPIOs available in the system irrespective of GPIOs
57 being controllable or not. Thus it is user responsibility to pick the proper
58 ones. The latter call simply returns queue capacity.
59
60 Respective queue needs to be configured with ``rte_rawdev_queue_setup()``. This
61 call barely exports GPIO to userspace.
62
63 To perform actual data transfer use standard ``rte_rawdev_enqueue_buffers()``
64 and ``rte_rawdev_dequeue_buffers()`` APIs. Not all messages produce sensible
65 responses hence dequeueing is not always necessary.
66
67 CNXK GPIO PMD
68 -------------
69
70 PMD accepts ``struct cnxk_gpio_msg`` messages which differ by type and payload.
71 Message types along with description are listed below. As for the usage examples
72 please refer to ``cnxk_gpio_selftest()``. There's a set of convenient wrappers
73 available, one for each existing command.
74
75 Set GPIO value
76 ~~~~~~~~~~~~~~
77
78 Message is used to set output to low or high. This does not work for GPIOs
79 configured as input.
80
81 Message must have type set to ``CNXK_GPIO_MSG_TYPE_SET_PIN_VALUE``.
82
83 Payload must be an integer set to 0 (low) or 1 (high).
84
85 Consider using ``rte_pmd_gpio_set_pin_value()`` wrapper.
86
87 Set GPIO edge
88 ~~~~~~~~~~~~~
89
90 Message is used to set edge that triggers interrupt.
91
92 Message must have type set to ``CNXK_GPIO_MSG_TYPE_SET_PIN_EDGE``.
93
94 Payload must be `enum cnxk_gpio_pin_edge`.
95
96 Consider using ``rte_pmd_gpio_set_pin_edge()`` wrapper.
97
98 Set GPIO direction
99 ~~~~~~~~~~~~~~~~~~
100
101 Message is used to change GPIO direction to either input or output.
102
103 Message must have type set to ``CNXK_GPIO_MSG_TYPE_SET_PIN_DIR``.
104
105 Payload must be `enum cnxk_gpio_pin_dir`.
106
107 Consider using ``rte_pmd_gpio_set_pin_dir()`` wrapper.
108
109 Set GPIO active low
110 ~~~~~~~~~~~~~~~~~~~
111
112 Message is used to set whether pin is active low.
113
114 Message must have type set to ``CNXK_GPIO_MSG_TYPE_SET_PIN_ACTIVE_LOW``.
115
116 Payload must be an integer set to 0 or 1. The latter activates inversion.
117
118 Consider using ``rte_pmd_gpio_set_pin_active_low()`` wrapper.
119
120 Get GPIO value
121 ~~~~~~~~~~~~~~
122
123 Message is used to read GPIO value. Value can be 0 (low) or 1 (high).
124
125 Message must have type set to ``CNXK_GPIO_MSG_TYPE_GET_PIN_VALUE``.
126
127 Payload contains integer set to either 0 or 1.
128
129 Consider using ``rte_pmd_gpio_get_pin_value()`` wrapper.
130
131 Get GPIO edge
132 ~~~~~~~~~~~~~
133
134 Message is used to read GPIO edge.
135
136 Message must have type set to ``CNXK_GPIO_MSG_TYPE_GET_PIN_EDGE``.
137
138 Payload contains `enum cnxk_gpio_pin_edge`.
139
140 Consider using ``rte_pmd_gpio_get_pin_edge()`` wrapper.
141
142 Get GPIO direction
143 ~~~~~~~~~~~~~~~~~~
144
145 Message is used to read GPIO direction.
146
147 Message must have type set to ``CNXK_GPIO_MSG_TYPE_GET_PIN_DIR``.
148
149 Payload contains `enum cnxk_gpio_pin_dir`.
150
151 Consider using ``rte_pmd_gpio_get_pin_dir()`` wrapper.
152
153 Get GPIO active low
154 ~~~~~~~~~~~~~~~~~~~
155
156 Message is used check whether inverted logic is active.
157
158 Message must have type set to ``CNXK_GPIO_MSG_TYPE_GET_PIN_ACTIVE_LOW``.
159
160 Payload contains an integer set to 0 or 1. The latter means inverted logic
161 is turned on.
162
163 Consider using ``rte_pmd_gpio_get_pin_active_low()`` wrapper.