1.\" Copyright (c) 2013, Luiz Otavio O Souza <loos@FreeBSD.org> 2.\" All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23.\" SUCH DAMAGE. 24.\" 25.Dd May 23, 2019 26.Dt GPIOLED 4 27.Os 28.Sh NAME 29.Nm gpioled 30.Nd GPIO LED generic device driver 31.Sh SYNOPSIS 32To compile this driver into the kernel, 33place the following lines in your 34kernel configuration file: 35.Bd -ragged -offset indent 36.Cd "device gpio" 37.Cd "device gpioled" 38.Ed 39.Sh DESCRIPTION 40The 41.Nm 42driver provides glue to attach a 43.Xr led 4 44compatible device to a GPIO pin. 45Each LED in the system has a 46.Pa name 47which is used to export a device as 48.Pa /dev/led/<name> . 49The GPIO pin can then be controlled by writing to this device as described 50in 51.Xr led 4 . 52.Pp 53On a 54.Xr device.hints 5 55based system, like 56.Li MIPS , 57these values are configurable for 58.Nm : 59.Bl -tag -width ".Va hint.gpioiic.%d.atXXX" 60.It Va hint.gpioled.%d.at 61The gpiobus you are attaching to. 62Normally assigned to gpiobus0. 63.It Va hint.gpioled.%d.name 64Arbitrary name of device in 65.Pa /dev/led/ 66to create for 67.Xr led 4 . 68.It Va hint.gpioled.%d.pins 69Which pin on the GPIO interface to map to this instance. 70Please note that this mask should only ever have one bit set 71(any other bits - i.e., pins - will be ignored). 72.It Va hint.gpioled.%d.invert 73Use pin inversion. If set to 1, the pin will be set to 0 to light the LED, and 1 74to clear it. 75.It Va hint.gpioled.%d.invmode 76Whether or not to use hardware support when pin inversion is requested. Must be 77one of: 78.Bl -tag 79.It Va auto 80Use hardware pin inversion if available, else fallback to software pin 81inversion. This is the default. 82.It Va hw 83Use hardware pin inversion. 84.It Va sw 85Use software pin inversion. 86.El 87.It Va hint.gpioled.%d.state 88The initial state of the LED when the driver takes control over it. 89If set to 1 or 0, the LED will be on or off correspondingly. 90If set to -1, the LED will be kept in its original state. 91.El 92.Pp 93On a 94.Xr FDT 4 95based system, like 96.Li ARM , 97the DTS part for a 98.Nm gpioled 99device usually looks like: 100.Bd -literal 101gpio: gpio { 102 103 gpio-controller; 104 ... 105 106 led0 { 107 compatible = "gpioled"; 108 gpios = <&gpio 16 2 0>; /* GPIO pin 16. */ 109 name = "ok"; 110 }; 111 112 led1 { 113 compatible = "gpioled"; 114 gpios = <&gpio 17 2 0>; /* GPIO pin 17. */ 115 name = "user-led1"; 116 }; 117}; 118.Ed 119.Pp 120Optionally, you can choose to combine all the LEDs under a single 121.Dq gpio-leds 122compatible node: 123.Bd -literal 124simplebus0 { 125 126 ... 127 128 leds { 129 compatible = "gpio-leds"; 130 131 led0 { 132 gpios = <&gpio 16 2 0>; 133 name = "ok" 134 }; 135 136 led1 { 137 gpios = <&gpio 17 2 0>; 138 name = "user-led1" 139 }; 140 }; 141}; 142.Ed 143.Pp 144Both methods are equally supported and it is possible to have the LEDs 145defined with any sort of mix between the methods. 146The only restriction is that a GPIO pin cannot be mapped by two different 147(gpio)leds. 148.Pp 149For more details about the 150.Va gpios 151property, please consult 152.Pa /usr/src/sys/dts/bindings-gpio.txt . 153.Pp 154The property 155.Va name 156is the arbitrary name of the device in 157.Pa /dev/led/ 158to create for 159.Xr led 4 . 160.Sh SEE ALSO 161.Xr fdt 4 , 162.Xr gpio 4 , 163.Xr gpioiic 4 , 164.Xr led 4 165.Sh HISTORY 166The 167.Nm 168manual page first appeared in 169.Fx 10.1 . 170.Sh AUTHORS 171This 172manual page was written by 173.An Luiz Otavio O Souza . 174