xref: /linux/Documentation/userspace-api/gpio/gpio-get-lineevent-ioctl.rst (revision 79790b6818e96c58fe2bffee1b418c16e64e7b80)
116b2bb7fSKent Gibson.. SPDX-License-Identifier: GPL-2.0
216b2bb7fSKent Gibson
316b2bb7fSKent Gibson.. _GPIO_GET_LINEEVENT_IOCTL:
416b2bb7fSKent Gibson
516b2bb7fSKent Gibson************************
616b2bb7fSKent GibsonGPIO_GET_LINEEVENT_IOCTL
716b2bb7fSKent Gibson************************
816b2bb7fSKent Gibson
916b2bb7fSKent Gibson.. warning::
1016b2bb7fSKent Gibson    This ioctl is part of chardev_v1.rst and is obsoleted by
1116b2bb7fSKent Gibson    gpio-v2-get-line-ioctl.rst.
1216b2bb7fSKent Gibson
1316b2bb7fSKent GibsonName
1416b2bb7fSKent Gibson====
1516b2bb7fSKent Gibson
1616b2bb7fSKent GibsonGPIO_GET_LINEEVENT_IOCTL - Request a line with edge detection from the kernel.
1716b2bb7fSKent Gibson
1816b2bb7fSKent GibsonSynopsis
1916b2bb7fSKent Gibson========
2016b2bb7fSKent Gibson
2116b2bb7fSKent Gibson.. c:macro:: GPIO_GET_LINEEVENT_IOCTL
2216b2bb7fSKent Gibson
2316b2bb7fSKent Gibson``int ioctl(int chip_fd, GPIO_GET_LINEEVENT_IOCTL, struct gpioevent_request *request)``
2416b2bb7fSKent Gibson
2516b2bb7fSKent GibsonArguments
2616b2bb7fSKent Gibson=========
2716b2bb7fSKent Gibson
2816b2bb7fSKent Gibson``chip_fd``
2916b2bb7fSKent Gibson    The file descriptor of the GPIO character device returned by `open()`.
3016b2bb7fSKent Gibson
3116b2bb7fSKent Gibson``request``
3216b2bb7fSKent Gibson    The :c:type:`event_request<gpioevent_request>` specifying the line
3316b2bb7fSKent Gibson    to request and its configuration.
3416b2bb7fSKent Gibson
3516b2bb7fSKent GibsonDescription
3616b2bb7fSKent Gibson===========
3716b2bb7fSKent Gibson
3816b2bb7fSKent GibsonRequest a line with edge detection from the kernel.
3916b2bb7fSKent Gibson
4016b2bb7fSKent GibsonOn success, the requesting process is granted exclusive access to the line
4116b2bb7fSKent Gibsonvalue and may receive events when edges are detected on the line, as
4216b2bb7fSKent Gibsondescribed in gpio-lineevent-data-read.rst.
4316b2bb7fSKent Gibson
4416b2bb7fSKent GibsonThe state of a line is guaranteed to remain as requested until the returned
4516b2bb7fSKent Gibsonfile descriptor is closed. Once the file descriptor is closed, the state of
4616b2bb7fSKent Gibsonthe line becomes uncontrolled from the userspace perspective, and may revert
4716b2bb7fSKent Gibsonto its default state.
4816b2bb7fSKent Gibson
4916b2bb7fSKent GibsonRequesting a line already in use is an error (**EBUSY**).
5016b2bb7fSKent Gibson
51*42969726SKent GibsonRequesting edge detection on a line that does not support interrupts is an
52*42969726SKent Gibsonerror (**ENXIO**).
53*42969726SKent Gibson
54*42969726SKent GibsonAs with the :ref:`line handle<gpio-get-linehandle-config-support>`, the
55*42969726SKent Gibsonbias configuration is best effort.
56*42969726SKent Gibson
5716b2bb7fSKent GibsonClosing the ``chip_fd`` has no effect on existing line events.
5816b2bb7fSKent Gibson
5916b2bb7fSKent GibsonConfiguration Rules
6016b2bb7fSKent Gibson-------------------
6116b2bb7fSKent Gibson
6216b2bb7fSKent GibsonThe following configuration rules apply:
6316b2bb7fSKent Gibson
6416b2bb7fSKent GibsonThe line event is requested as an input, so no flags specific to output lines,
6516b2bb7fSKent Gibson``GPIOHANDLE_REQUEST_OUTPUT``, ``GPIOHANDLE_REQUEST_OPEN_DRAIN``, or
6616b2bb7fSKent Gibson``GPIOHANDLE_REQUEST_OPEN_SOURCE``, may be set.
6716b2bb7fSKent Gibson
6816b2bb7fSKent GibsonOnly one bias flag, ``GPIOHANDLE_REQUEST_BIAS_xxx``, may be set.
6916b2bb7fSKent GibsonIf no bias flags are set then the bias configuration is not changed.
7016b2bb7fSKent Gibson
7116b2bb7fSKent GibsonThe edge flags, ``GPIOEVENT_REQUEST_RISING_EDGE`` and
7216b2bb7fSKent Gibson``GPIOEVENT_REQUEST_FALLING_EDGE``, may be combined to detect both rising
7316b2bb7fSKent Gibsonand falling edges.
7416b2bb7fSKent Gibson
7516b2bb7fSKent GibsonRequesting an invalid configuration is an error (**EINVAL**).
7616b2bb7fSKent Gibson
7716b2bb7fSKent GibsonReturn Value
7816b2bb7fSKent Gibson============
7916b2bb7fSKent Gibson
8016b2bb7fSKent GibsonOn success 0 and the :c:type:`request.fd<gpioevent_request>` contains the file
8116b2bb7fSKent Gibsondescriptor for the request.
8216b2bb7fSKent Gibson
8316b2bb7fSKent GibsonOn error -1 and the ``errno`` variable is set appropriately.
8416b2bb7fSKent GibsonCommon error codes are described in error-codes.rst.
85