xref: /illumos-gate/usr/src/man/man8/gpioadm.8 (revision fd71220ba0fafcc9cf5ea0785db206f3f31336e7)
1.\"
2.\" This file and its contents are supplied under the terms of the
3.\" Common Development and Distribution License ("CDDL"), version 1.0.
4.\" You may only use this file in accordance with the terms of version
5.\" 1.0 of the CDDL.
6.\"
7.\" A full copy of the text of the CDDL should have accompanied this
8.\" source.  A copy of the CDDL is also available via the Internet at
9.\" http://www.illumos.org/license/CDDL.
10.\"
11.\"
12.\" Copyright 2022 Oxide Computer Company
13.\"
14.Dd September 17, 2022
15.Dt GPIOADM 8
16.Os
17.Sh NAME
18.Nm gpioadm
19.Nd gpio and dpio administration
20.Sh SYNOPSIS
21.Nm
22.Cm controller
23.Cm list
24.Op Fl H
25.Op Fl o Ar field Ns [,...] Op Fl p
26.Op Ar filter Ns ...
27.Nm
28.Cm gpio
29.Cm list
30.Op Fl H
31.Op Fl 1
32.Op Fl o Ar field Ns [,...] Op Fl p
33.Op Ar filter Ns ...
34.Nm
35.Cm gpio
36.Cm attr
37.Cm get
38.Op Fl H
39.Op Fl o Ar field Ns [,...] Op Fl p
40.Ar controller/gpio
41.Op Ar filter Ns ...
42.Nm
43.Cm gpio
44.Cm attr
45.Cm set
46.Ar controller/gpio
47.Ar attr=value
48.Op Ar attr=value Ns ...
49.Nm
50.Cm dpio
51.Cm list
52.Op Fl H
53.Op Fl o Ar field Ns [,...] Op Fl p
54.Op Ar filter Ns ...
55.Nm
56.Cm dpio
57.Cm define
58.Op Fl r
59.Op Fl w
60.Op Fl K
61.Ar controller/gpio
62.Ar name
63.Nm
64.Cm dpio
65.Cm undefine
66.Ar controller/gpio
67.Sh DESCRIPTION
68The
69.Nm
70utility is used to enumerate and manipulate the general purpose and
71dedicated purpose I/Os
72.Pq GPIO and DPIO
73and their controllers that are present in the system.
74For more background on the GPIO and DPIO subsystem, please see
75.Xr gpio 7 .
76.Pp
77There are three top-level objects in
78.Nm :
79.Bl -tag -width Ds
80.It GPIOs
81General Purpose I/Os are software controllable pins that exist on
82various hardware devices.
83GPIOs are identified by a human-readable name and a controller-specific
84numeric ID
85.Po
86which has no relation to the hardware or datasheet's numbering of GPIOs,
87these are used by the kernel to identify GPIOs
88.Pc .
89All
90.Nm
91operations allow a GPIO to be named either by its human-readable name
92or its controller-specific ID.
93.Nm
94will always attempt to resolve a string as a GPIO's name first and will
95only attempt to parse it as a GPIO's ID if there is no GPIO with that
96name.
97.Pp
98GPIOs themselves contain a series of attributes which vary based on the
99controller.
100An attribute itself may be read-only or read-write and controls one
101aspect of the GPIO.
102For example, there are attributes for things such as the name of the
103device, which pin it corresponds to on the package, what the current
104input and output values are, whether there are pull-up or pull-down
105resistors enabled, and much more.
106.Pp
107GPIOs support the discovery and manipulation of their attributes through
108the
109.Cm attr
110.Cm get
111and
112.Cm attr
113.Cm set
114subcommands.
115Manipulating attributes can
116.Sy potentially damage
117your system.
118Documentation of specific attributes, may potentially be found in
119provider-specific driver manual pages in section 4D.
120.It Controllers
121These are hardware devices that provide access to GPIOs.
122.Nm
123provides the ability to list and get basic information about these
124controllers.
125Controllers are not manipulated directly but are indirectly used when
126getting information about and manipulating GPIOs and DPIOs.
127.It DPIOs
128Dedicated Purpose I/Os are devices which wrap up and constrain a GPIO
129while allowing one to indicate that there are particular semantics.
130Unlike a GPIO which has a full series of attributes, a DPIO provides
131generic access to reading the current input value and setting the output
132value, while freezing all other attributes of the underlying GPIO.
133For more background on DPIOs, how they work, and why the exist, please
134see
135.Xr dpio 7 .
136.Pp
137Specifically,
138.Nm
139supports the creation of DPIOs from a GPIO using the
140.Cm dpio
141.Cm define
142subcommand and release a GPIO from being a DPIO through the
143.Cm dpio
144.Cm undefine
145subcommand.
146.El
147.Pp
148All listing operations leverage the standard illumos output format
149library
150.Po
151.Xr ofmt 3OFMT
152.Pc
153allowing the selection of specific output fields, the omission of the
154header
155.Pq Fl H ,
156and a parsable mode intended for programmatic consumption
157.Pq Fl p .
158When requesting parsable output, the colon
159.Po
160.Do
161:
162.Dc
163.Pc
164character is used as a delimiter between fields and any delimiters that
165would appear in an output field will be escaped with a backslash
166character
167.Po
168.Do
169\e
170.Dc
171.Pc .
172.Pp
173Getting information about GPIOs, DPIOs, and controllers currently
174requires that a process have the
175.Brq Dv PRIV_SYS_DEVICES
176privilege.
177.Ss Persistence
178Currently there is no persistence across reboots of any changes that are
179made to GPIO attributes.
180Similarly, any DPIOs that are created and manipulated only last until
181the next reboot of the system.
182.Sh SUBCOMMANDS
183The following commands are supported by
184.Nm :
185.Bl -tag -width ""
186.It Xo
187.Nm
188.Cm controller
189.Cm list
190.Op Fl H
191.Op Fl o Ar field Ns [,...] Op Fl p
192.Op Ar filter Ns ...
193.Xc
194List all of the GPIO controllers in the system and basic information
195about them.
196.Pp
197The following fields are supported:
198.Bl -tag -width CONTROLLER
199.It Sy CONTROLLER
200This is the name of the GPIO controller in the system.
201.It Sy NGPIOS
202The number of GPIOs that the controller supports.
203This value will not change unless the controller driver changes somehow.
204.It Sy NDPIOS
205The number of DPIOs that the controller currently actively has.
206This value will change over time depending on the creation and removal
207of DPIOs.
208.It Sy PROVIDER
209The
210.Pa /devices
211path to the kernel provider for this GPIO controller.
212.It Sy PATH
213The
214.Pa /devices
215path to the GPIO controller minor node.
216.El
217.Pp
218The following options are supported:
219.Bl -tag -width Fl
220.It Fl H
221Omit the column header when printing output.
222.It Fl o Ar field Ns [,...]
223A comma-delineated list of fields to output, selected from the ones
224above.
225.It Fl p
226Displays the output in a machine-parsable format.
227When requesting parsable output, the
228.Fl o
229option is required to specifically control which fields are included.
230.El
231.Pp
232The following operands are supported:
233.Bl -tag -width Ar
234.It Ar filter
235One or more filters may be specified that are used to constrain the list
236of GPIO controllers that are printed.
237Each
238.Ar filter
239is the name of a GPIO controller that matches the aforementioned
240.Sy CONTROLLER
241field.
242.Pp
243If any filter is specified and does not match, then that is treated as
244an error.
245.Pp
246Because these are filters, they do not control the order that items are
247printed out, only what is printed out.
248.El
249.It Xo
250.Nm
251.Cm gpio
252.Cm list
253.Op Fl H
254.Op Fl 1
255.Op Fl o Ar field Ns [,...] Op Fl p
256.Op Ar filter Ns ...
257.Xc
258List all of the GPIOs in the system across all controllers.
259.Pp
260The following fields are supported:
261.Bl -tag -width CONTROLLER
262.It Sy CONTROLLER
263This is the name of the GPIO controller in the system.
264.It Sy GPIO
265This is the name of the GPIO provided by its controller.
266GPIO names are not unique in the system and are scoped to their
267controller.
268.It Sy ID
269The numeric ID of the GPIO.
270This is used as part of getting and setting attributes as well as when
271defining and undefining DPIOs.
272.El
273.Pp
274The following options are supported:
275.Bl -tag -width Fl
276.It Fl 1
277Exit non-zero if the list operation outputs more than one item.
278This is generally used in conjunction with a specific
279.Ar filter
280that would include both a controller and a GPIO name.
281.It Fl H
282Omit the column header when printing output.
283.It Fl o Ar field Ns [,...]
284A comma-delineated list of fields to output, selected from the ones
285above.
286.It Fl p
287Displays the output in a machine-parsable format.
288When requesting parsable output, the
289.Fl o
290option is required to specifically control which fields are included.
291.El
292The following operands are supported:
293.Bl -tag -width Ar
294.It Ar filter
295One or more filters that are used to constrain the list of GPIOs that
296are printed.
297Each filter may combine a GPIO controller and a GPIO name.
298There are three general forms:
299.Bl -tag -width Ar
300.It Ar controller
301This filter matches all GPIOs that are present under the controller
302named by
303.Ar controller .
304.It Ar */gpio
305This filter matches all controllers, but only prints GPIOs with the
306specified name
307.Ar gpio .
308.It Ar controller/gpio
309This is the intersection of the prior two filters.
310This filter will only print if both a GPIO's controller and its name
311match the specified values.
312.El
313.Pp
314Like with other filters, this does not control the order that matches
315are printed in and
316.Nm
317will error if not all filters are used.
318The filters can be combined with the
319.Fl 1
320option to guarantee that only a single GPIO is matched.
321.El
322.It Xo
323.Nm
324.Cm gpio
325.Cm attr
326.Cm get
327.Op Fl H
328.Op Fl o Ar field Ns [,...] Op Fl p
329.Ar controller/gpio
330.Op Ar filter Ns ...
331.Xc
332The
333.Cm gpio
334.Cm attr
335.Cm get
336subcommand is used to display all of the attributes of a single GPIO
337that is specified by
338.Ar controller/gpio .
339The
340.Ar controller
341part of that is the name of the controller.
342The
343.Ar gpio
344part is either the name or ID of the GPIO.
345.Pp
346For each of a single GPIO's attributes, the name of the attribute, its
347current value, what permissions exist for its value, and then what
348values are possible to st for it are displayed.
349Filters can be used to limit which attributes are displayed.
350.Pp
351The following fields are supported:
352.Bl -tag -width POSSIBLE
353.It Sy ATTR
354This is the name of the attribute.
355It is split into a provider name and then a specific attribute name as
356all attributes are generally scoped to their provider.
357.It Sy PERM
358This indicates the current permissions for manipulating this attribute.
359This is treated as a two character field with
360.Sq r
361standing for reading the value and
362.Sq w
363standing for writing the value.
364.It Sy VALUE
365This is the current value of the attribute.
366It will generally be rendered as a human-readable string when
367appropriate so that way the value can be understood and does not require
368understanding the underlying provider's specific values.
369.It Sy POSSIBLE
370A list of all possible values that are supported for this field.
371This allows one to know what they can possibly set for this attribute.
372For some read-only attributes this field may not have a value.
373.It Sy RAW
374This provides the underlying provider's value for this attribute.
375For string based attributes, this is the same as the
376.Sy VALUE
377field.
378For other attributes, such as those which are uint32 values under the
379hood, these are the hexadecimal form of the integer.
380.El
381.Pp
382The following options are supported:
383.Bl -tag -width Fl
384.It Fl H
385Omit the column header when printing output.
386.It Fl o Ar field Ns [,...]
387A comma-delineated list of fields to output, selected from the ones
388above.
389.It Fl p
390Displays the output in a machine-parsable format.
391When requesting parsable output, the
392.Fl o
393option is required to specifically control which fields are included.
394.El
395The following operands are supported:
396.Bl -tag -width Ar
397.It Ar filter
398One or more filters may be specified that are used to constrain the list
399of GPIO attributes that are printed.
400Each
401.Ar filter
402is the name of a GPIO attributes that matches the aforementioned
403.Sy ATTR
404field.
405.El
406.It Xo
407.Nm
408.Cm gpio
409.Cm attr
410.Cm set
411.Ar controller/gpio
412.Ar attr=value
413.Op Ar attr=value Ns ...
414.Xc
415The
416.Cm gpio
417.Cm attr
418.Cm set
419subcommand is used to set one or more attributes of the GPIO that is
420named by
421.Ar controller/gpio .
422The
423.Ar controller
424part of that is the name of the controller.
425The
426.Ar gpio
427part is either the name or ID of the GPIO.
428.Pp
429All attributes that are specified are given to the hardware to apply at
430once which generally means that either all of them should be applied or
431none of them will be.
432This allows a change from one atomic state to another without worrying
433about how to construct an attribute by attribute path from one state to
434the next, which may not be safe.
435.Pp
436Attributes and values are separated with the equals character
437.Po
438.Do
439=
440.Dc
441.Pc .
442.Ar attr
443should be the full name of an attribute.
444.Ar value
445is the value to set.
446.Nm
447will automatically convert the human-readable strings that describe
448values into the appropriate underlying provider-specific form.
449To see which values are valid, look at the
450.Sy POSSIBLE
451column when getting the attributes.
452.It Xo
453.Nm
454.Cm dpio
455.Cm list
456.Op Fl H
457.Op Fl o Ar field Ns [,...] Op Fl p
458.Op Ar filter Ns ...
459.Xc
460The
461.Cm dpio
462.Cm list
463subcommand lists all the DPIOs that have been created from GPIOs in the
464system.
465.Pp
466The following fields are supported:
467.Bl -tag -width CONTROLLER
468.It Sy DPIO
469This is the name of a DPIO.
470DPIO names are unique in the system and a DPIO can be found in the
471filesystem at
472.Pa /dev/dpio/<name> .
473.It Sy CAPS
474This is a list of capabilities that a DPIO supports, which is a
475combination of what the underlying provider supports and what a user
476requested when creating the DPIO.
477The following are the current capabilities, though this list may expand
478in the future:
479.Bl -tag -width write
480.It read
481Indicates that the DPIO supports the various
482.Xr read 2
483family of functions.
484Reading a DPIO returns the current value the DPIO sees on its pin in the
485form of a 4 byte
486.Vt dpio_input_t .
487See
488.Xr dpio 7
489for more information.
490.It write
491Indicates that the DPIO supports the various
492.Xr write 2
493family of functions.
494Writing a DPIO changes the value that it is outputting on its pin.
495Writes must always be a 4 byte
496.Vt dpio_output_t
497value.
498See
499.Xr dpio 7
500for more information.
501.It poll
502This indicates that the DPIO can be polled for changes to its input
503value via the
504.Dv POLLIN
505event with functions such as
506.Xr poll 2 ,
507.Xr port_create 3C ,
508and others.
509In addition, the timestamp of when the last change was detected can be
510retrieved via a device-specific
511.Xr ioctl 2 .
512This capability will not show up if the read capability is not present.
513See
514.Xr dpio 7
515for more information.
516.El
517.It Sy FLAGS
518This is a series of different flags that describe different aspects of
519the DPIOs behavior.
520The flags are organized and printed a series of letters where a
521.Sq -
522character denotes that a flag is not set and a letter indicates that a
523flag is set.
524The currently defined flags are:
525.Bl -tag -width K
526.It K
527Indicates that the DPIO may only be used by the kernel in a layered
528fashion
529.Po
530e.g. it must be opened by
531.Xr ldi_open_by_name 9F
532or a similar LDI call
533.Pc .
534.Pp
535Users of this field should not assume that the number of flags is fixed.
536When additional flag are added, they will be appended to the current
537set, ensuring that the order does not change.
538The appearance of additional characters in the string is what allows
539callers to know that a new flag is present and gives software and humans
540the ability to distinguish changes.
541.El
542.It Sy CONTROLLER
543This is the name of the GPIO controller that the DPIO is leveraging.
544When combined with the
545.Sy GPIONUM
546field, this uniquely identifies the GPIO that powers the DPIO.
547This name is the same as would show up in the
548.Cm controller
549.Cm list
550subcommand.
551.It Sy GPIONUM
552This is the ID of the GPIO on the specified controller that the DPIO has
553wrapped up and constrained.
554.El
555.It Xo
556.Nm
557.Cm dpio
558.Cm define
559.Op Fl r
560.Op Fl w
561.Op Fl K
562.Ar controller/gpio
563.Ar name
564.Xc
565The
566.Cm dpio
567.Cm define
568subcommand creates a new DPIO named
569.Ar name
570from the specified GPIO
571.Ar controller/gpio .
572A DPIO's name may be up to 31 characters.
573The first character must be alphanumeric, after which, hyphens,
574underscores, periods, and plus signs are also allowed
575.Po
576.Sq - ,
577.Sq _ ,
578.Sq \&. ,
579.Sq +
580.Pc .
581Once created, a new character device will be present at
582.Pa /dev/dpio/<name>
583and the GPIOs attributes will be frozen other than those that are
584allowed for the DPIO to operate.
585After that point, the
586.Cm gpio
587.Cm attr
588.Cm set
589command will always fail until the DPIO is removed.
590.Pp
591The following options are supported, which modify the behavior of what the
592DPIO is allowed to do:
593.Bl -tag -width Fl
594.It Fl K
595The DPIO will be constrained such that only the kernel can open it.
596See the description of the
597.Dq K
598flag above.
599.It Fl r
600This allows the DPIO to be read and return the current logical value
601that the pin sees.
602See the description of the read capability above for more information.
603.It Fl w
604This allows the DPIO's logical output value to be set or disabled.
605See the description of the write capability above for more information.
606.El
607.Pp
608While it may seem weird, it is allowed to create a DPIO and not specify
609either of
610.Fl r
611or
612.Fl w .
613Such a DPIO will simply remain in its fixed state.
614For example, if its attributes have it set up to drive a particular
615output value
616.Pq or none at all for an open-drain based pin
617then that will remain constant throughout the life of the DPIO.
618.It Xo
619.Nm
620.Cm dpio
621.Cm undefine
622.Ar controller/gpio
623.Xc
624The
625.Cm dpio
626.Cm undefine
627subcommand releases the corresponding DPIO that was named by its GPIO
628controller and specific GPIO.
629If the DPIO is currently in use, this will fail.
630Once successfully completed, the
631.Pa /dev
632entry
633.Pa /dev/dpio/<name>
634will be removed and the GPIOs attributes will be unfrozen, allowing them
635to be manipulated again with the
636.Cm gpio
637.Cm attr
638.Cm set
639subcommand.
640.El
641.Sh EXIT STATUS
642The
643.Nm
644utility exits 0 on success.
645If an error occurs, it exits 1, and provides additional details about
646the underlying cause of the error.
647If there was an invalid or missing command line options, then
648.Nm
649exits 2.
650.Pp
651When listing controllers, GPIOs, DPIOs, or attributes, if none are
652listed or if a filter is specified but is not matched, then these
653conditions are all treated as errors and
654.Nm
655exits 1.
656.Sh EXAMPLES
657.Sy Example 1
658Discovering Controllers
659.Pp
660This example shows how you discover what controllers exist.
661.Bd -literal -offset indent
662# gpioadm controller list
663CONTROLLER      NGPIOS  NDPIOS  PROVIDER
664gpio_sim0       6       0       /pseudo/gpio_sim@0
665gpio_sim1       6       0       /pseudo/gpio_sim@1
666gpio_sim2       6       0       /pseudo/gpio_sim@2
667.Ed
668.Pp
669The controller information can be changed by changing the fields or
670adding a filter.
671For example:
672.Bd -literal -offset indent
673# gpioadm controller list -o controller,ngpios,path gpio_sim2
674CONTROLLER      NGPIOS  PATH
675gpio_sim2       6       /pseudo/kgpio@0:gpio_sim2
676.Ed
677.Pp
678.Sy Example 2
679Listing GPIOs avialable on the system.
680.Pp
681This example allows you to discover which GPIOs exist on the system and
682which controllers that they belong to.
683First this shows listing all the GPIOs and then limiting the request to
684GPIOs on a specific controller.
685.Bd -literal -offset indent
686# gpioadm gpio list
687CONTROLLER      GPIO                ID
688gpio_sim0       1v8                 0
689gpio_sim0       3v3                 1
690gpio_sim0       12V                 2
691gpio_sim0       54V                 3
692gpio_sim0       periodic-500ms      4
693gpio_sim0       open-drain          5
694gpio_sim1       1v8                 0
695gpio_sim1       3v3                 1
696gpio_sim1       12V                 2
697gpio_sim1       54V                 3
698gpio_sim1       periodic-500ms      4
699gpio_sim1       open-drain          5
700gpio_sim2       1v8                 0
701gpio_sim2       3v3                 1
702gpio_sim2       12V                 2
703gpio_sim2       54V                 3
704gpio_sim2       periodic-500ms      4
705gpio_sim2       open-drain          5
706.Ed
707.Pp
708Next, to limit them, additional arguments may be passed as filters.
709This will specify everything on the controller gpio_sim1 and a specific
710GPIO on gpio_sim2.
711A reminder that the filters are based on names.
712.Bd -literal -offset indent
713# gpioadm gpio list gpio_sim1 gpio_sim2/periodic-500ms
714CONTROLLER      GPIO                ID
715gpio_sim1       1v8                 0
716gpio_sim1       3v3                 1
717gpio_sim1       12V                 2
718gpio_sim1       54V                 3
719gpio_sim1       periodic-500ms      4
720gpio_sim1       open-drain          5
721gpio_sim2       periodic-500ms      4
722.Ed
723.Pp
724.Sy Example 3
725Looking up a single GPIO by name and getting its attributes.
726.Pp
727These two commands could also be chained together through the use of a
728subshell.
729.Bd -literal -offset indent
730# gpioadm gpio list -1 -p -o id gpio_sim1/3v3
7311
732# gpioadm gpio attr get gpio_sim1/1
733ATTR                  PERM  VALUE                   POSSIBLE
734name                  r-    3v3                     --
735sim:output            rw    disabled                disabled,low,high
736sim:input             r-    low                     low,high
737sim:pull              rw    down
738disabled,down,up,up|down
739sim:voltage           r-    3.3V                    3.3V
740sim:speed             rw    low                     low,medium,high,
741                                                    very-high
742.Ed
743.Pp
744.Sy Example 4
745Setting GPIO attributes
746.Pp
747Multiple GPIO attributes can be set at the same time.
748They all will take effect at the same time.
749This example shows setting and then getting those same properties:
750.Bd -literal -offset indent
751# gpioadm gpio attr set gpio_sim1/1 sim:pull=up sim:speed=high
752# gpioadm gpio attr get gpio_sim1/1 sim:pull sim:speed
753ATTR                  PERM  VALUE                   POSSIBLE
754sim:pull              rw    up
755disabled,down,up,up|down
756sim:speed             rw    high                    low,medium,high,
757                                                    very-high
758.Ed
759.Pp
760.Sy Example 5
761Creating a DPIO
762.Pp
763This example shows the creation of a DPIO from a GPIO.
764.Bd -literal -offset indent
765# gpioadm dpio define -r -w gpio_sim2/2 example5
766# $ ls /dev/dpio/example5
767/dev/dpio/example5
768# gpioadm dpio list
769DPIO            CAPS            FLAGS   CONTROLLER      GPIONUM
770example5        read,write      -       gpio_sim2       2
771.Ed
772.Pp
773.Sy Example 6
774Removing a DPIO
775.Pp
776This example removes the DPIO that we created in the prior example.
777If the system has other DPIOs than the output of the final command will
778be different.
779.Bd -literal -offset indent
780# gpioadm dpio undefine gpio_sim2/2
781# ls /dev/dpio/example5
782/dev/dpio/example5: No such file or directory
783# gpioadm dpio list
784gpioadm: no DPIOs found
785.Ed
786.Sh INTERFACE STABILITY
787The command line interface of
788.Nm
789is
790.Sy Evolving .
791The output of
792.Nm
793is
794.Sy Not-An-Interface
795and may change at any time.
796.Sh SEE ALSO
797.Xr poll 2 ,
798.Xr read 2 ,
799.Xr write 2 ,
800.Xr port_get 3 C
801.Xr ofmt 3OFMT ,
802.Xr dpio 7 ,
803.Xr gpio 7 ,
804.Xr ldi_open_by_name 9F
805