1
0
mirror of https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git synced 2026-10-28 13:55:08 +03:00
Commit Graph

170 Commits

Author SHA1 Message Date
Bartosz Golaszewski
9b6e6d2686 ctxless: drop all context-less interfaces
The context-less family of functions seems to be largely unused.
Drop this part of the codebase and convert tools to using the regular
low-level API.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-11-18 09:25:49 +01:00
Bartosz Golaszewski
e4643104b7 core: provide gpiod_line_bulk_reset()
Provide a helper function that allows to reset an existing bulk object.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-11-18 09:22:06 +01:00
Bartosz Golaszewski
2b02d7ae1a treewide: rework struct gpiod_line_bulk
Current implementation of struct gpiod_line_bulk uses stack memory
excessively. The structure is big: it's an array 64 pointers + 4 bytes
size. That amounts to 260 bytes on 32-bit and 516 bytes on 64-bit
architectures respectively. It's also used everywhere as all functions
dealing with single lines eventually end up calling bulk counterparts.

The rework addresses it by making the bulk structure opaque and
providing appropriate interfaces for library users while retaining a way
for internal users to allocate single line bulks on the stack.

The macro-based loop has been removed. In its place we provide a function
iterating over all lines held by a bulk and calling the provided callback
function for each line.

Since bulk operations can now fail, a bunch of test-cases has been added
to cover the relevant code.

While at it: using the word offset both when referring to line's HW
offset in a chip as well as the offset in a bulk leads to confusion.
This patch renames the bulk offset to index.

Some additional improvements to the patch by:
  Kent Gibson <warthog618@gmail.com>

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-11-04 16:39:09 +01:00
Bartosz Golaszewski
aefe16f598 Merge branch 'for-linux-v5.10-rc1' 2020-10-26 11:08:29 +01:00
Marc Ferland
1c47ee5ec2 doc: fix typo in gpiod_line_request_bulk() documentation
Remove the stray 'the' from the doc.

Signed-off-by: Marc Ferland <marc.ferland@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-10-16 11:27:19 +02:00
Kent Gibson
9bf94b8d48 doc: fix typo in gpiod_line_request_bulk() documentation
Replace 'prodivided' with 'provided'.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-10-16 11:25:27 +02:00
Kent Gibson
37f33cce6f core: Basic port to uAPI v2
Port existing implementation from GPIO uAPI v1 to v2.
The libgpiod external interface remains unchanged, only the internal
implementation switches from uAPI v1 to v2.

This is a minimal port - uAPI v2 features are not used, only the
uAPI v1 calls are switched to the v2 equivalent.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-10-14 15:15:53 +02:00
Bartosz Golaszewski
74f6646103 core: remove deprecated functions
Drop all deprecated interfaces now that we're allowed to change the API
for libgpiod v2.0.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-10-14 10:26:54 +02:00
Bartosz Golaszewski
1bdb669467 doc: improve the part about non-unique line names
The current comments for functions related to line lookups state that
"lines are not unique" but they're really supposed to say "line names
are not unqiue".

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-09-15 17:31:44 +02:00
Alexander Stein
fc61e740fc doc: add @file to headers
It's necessary to have a file reference linked in the file list.
Also: strip the top_srcdir from paths

Signed-off-by: Alexander Stein <alexander.stein@mailbox.org>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-08-13 21:06:52 +02:00
Alexander Stein
61c1557aa1 doc: fix doxygen warnings
Apparently __<name>__ is not supported for @defgroup commands anymore in
doxygen v1.8.19 (and possibly earlier versions). This results in the
following warning (printed multiple times):

gpiod.h:79: warning: group strong: ignoring title ">high_level</strong> High-level
API" that does not match old title ">common</strong> Common helper macros"

Also the module list is broken.

Fix this my removing the underscores.

Signed-off-by: Alexander Stein <alexander.stein@mailbox.org>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-08-13 20:29:16 +02:00
Bartosz Golaszewski
a5cc6cc041 doc: document the reasons for deprecating interfaces
Use the @deprecated doxygen tag to mark deprecated functions and explain
why their usage is discouraged.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-08-06 22:02:55 +02:00
Bartosz Golaszewski
9ffa2afd8c doc: document the caveat concerning line lookups
GPIO line names in the kernel aren't unique - neither globally nor
within a single chip. The current API doesn't take this into
consideration and simply returns the first matching line in
gpiod_line_find() and co.

This will be addressed in v2.0 but we can't fix it in v1.x without
introducing new interfaces and deprecating the ones that already exist.

Let's document this behavior in doxygen comments for all affected
routines.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-08-06 21:55:37 +02:00
Kent Gibson
2efb0075a7 doc: fix comment mix up in gpiod.h
A couple of the doc comments for GPIOD_LINE_REQUEST_XX values document
the wrong value. Switch them so that they document the appropriate value.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-05-27 14:05:59 +02:00
Bartosz Golaszewski
5f6d42a56d doc: improve the description of gpiod_line_event_read()
The description of gpiod_line_event_read() states that it reads the last
event that occurred for this line. This is not true: the kernel stores
the events in a FIFO and this function reads the next event from it.

Fix the confusing statement.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-04-28 13:54:09 +02:00
Bartosz Golaszewski
ff4f2b965e doc: add descriptions for doxygen sub-sections
Add additional descriptions fox doxygen sub-sections under the line
section.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2020-04-09 12:19:22 +02:00
Bartosz Golaszewski
44921ecc9a core: provide functions for reading multiple line events at once
The kernel allows us to read multiple (up to 16) line events with
a single read() call, but up to this point libgpiod only supported
reading one event at a time. Add two new functions that allow users
to read more events at the same time.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-12-18 15:09:30 +01:00
Kent Gibson
da25df40dc doc: document gpiod_line_set_value_bulk NULL values behaviour
The handling of NULL values by gpiod_line_set_value_bulk has been changed
to interpret NULL as low values for all lines. This patch updates the
documentation of the function to describe that.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-12-10 16:41:46 +01:00
Kent Gibson
12b73c7420 core: add support for SET_CONFIG
Extend the libgpiod API to support the setting line configuration using the
GPIO GPIOHANDLE_SET_CONFIG_IOCTL uAPI ioctl.

The core change is the addition of gpiod_line_set_config, which provides a
low level wrapper around the ioctl.

Additionally, higher level helper functions, gpiod_line_set_flags,
gpiod_line_set_direction_input, and gpiod_line_set_direction_output provide
slightly simplified APIs for common use cases.

Bulk forms of all functions are also provided.

Documented the fields of gpiod_line to better identify the purpose of
each where the field name alone is not sufficiently clear, and to
indicate which flags are applicable to each field.

Implementation includes a few helper functions that serve to keep the
code tidier and are consistent with similar helper functions already
present.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-12-10 11:45:52 +01:00
Kent Gibson
26d8d8f0b7 core: add support for bias flags
Extend the libgpiod API to support the bias flags recently added to the
kernel GPIO uAPI.  The core change is the addition of
GPIOD_LINE_REQUEST_FLAG_BIAS_DISABLE, GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_UP
and GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_DOWN flags to be passed into
line_request functions, and the addition of gpiod_line_bias to return the
bias state of lines.

Variants of the ctxless functions that accept an active_low flag
are added to also accept other flags. The variant names add a "_ext"
suffix to the name of the original function.

Based on initial work by Drew Fustini <drew@pdp7.com>.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-12-09 17:45:41 +01:00
Bartosz Golaszewski
296444104b core: deprecate gpiod_needs_update()
This function and the logic behind have been introduced in an early
version of libgpiod for reasons that have been long forgotten.

When updating the line info after a line request fails, just propagate
the error out of the request function instead of setting the internal
needs_update variable. Drop the entire logic behind gpiod_needs_update(),
make this routine always return false and mark it as deprecated in the
header.

Suggested-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-11-23 15:48:56 +01:00
Kent Gibson
bb3dc9eb2e treewide: change "correspond with" to "correspond to"
Trivial grammar fix. "correspond with" can mean either being in agreement
with, happening at the same time, or communication between parties.
"correspond to" is used to mean equivalance, which is the intended use
throughout the documentation.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-11-18 15:46:12 +01:00
Kent Gibson
065c2a8b45 core: fix misspelling of parameter
Trivial fix to bring gpiod_ctxless_event_monitor_multiple() documentation
into line with gpiod_ctxless_event_monitor_multiple_ext().

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-11-18 15:25:36 +01:00
Bartosz Golaszewski
9462caf743 core: rename up_to_date to needs_update in struct gpiod_line
This variable is called up_to_date which can lead readers to the wrong
conclusion that libgpiod can somehow know when external actors (such as
a different process or a kernel driver) change the state of a GPIO line.

This is not the case and libgpiod only ever knows if a line needs info
update when a previous internal call to gpiod_line_update() fails.

The kernel does not provide any notification mechanism currently.

For that reason: rename the variable to needs_update.

While at it: clarify the documentation for gpiod_line_needs_update().

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-09-10 10:43:24 +02:00
Bartosz Golaszewski
937ded4dbc treewide: order includes alphabetically
Unify the header includes by ordering them alphabetically and always
having local headers in a second group below the global ones (separated
by a newline).

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
2019-02-21 09:38:57 +01:00
Gasper Zejn
3599d34aee doc: C API documentation fixes
Fix a couple problems in doxygen documentation of the C API.

(Unfortunately no Signed-off-by tag from the submitter...)
[Bartosz: added a proper commit message]
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-11-13 18:41:04 +01:00
Bartosz Golaszewski
5095bdd01a API: mark context-less event loop functions as deprecated
Mark gpiod_ctxless_event_loop() and gpiod_ctxless_event_loop_multiple()
as deprecated. Those functions suffer from an issue where HW may not
allow setting up both rising and falling egde interrupts. All users
have been converted to using the new event monitor helpers.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-10-07 11:00:15 +02:00
Bartosz Golaszewski
99bc2260bd API: add a macro for marking deprecated functions
We want to deprecate the badly designed event loop functions. Introduce
a macro that allows marking API routines as deprecated.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-10-07 10:59:48 +02:00
Bartosz Golaszewski
61498a0ee5 ctxless: provide new event monitor
Current implementation of gpiod_ctxless_event_loop() (and its variant
for multiple lines) always requests GPIO lines for listening for both
rising and falling edge events. This causes a problem when the
underlying hardware doesn't allow this.

It can e.g. result in the following error raised by the interrupt
controller:

  genirq: Setting trigger mode 3 for irq 107 failed (kempld_irq_set_type+0x0/0x130 [gpio_kempld])

For the sake of backward compatibility we're leaving the old
implementation in place and provide two new routines that that take an
additional parameter allowing users to specify the events libgpiod
should listen for.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-10-07 10:34:26 +02:00
Bartosz Golaszewski
6639fb7709 doc: tweak the comment for gpiod_version_string()
Make it clear that this function returns the API version as we now have
separate API and ABI versions.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-05-16 10:11:57 +02:00
Bartosz Golaszewski
5da2e8d790 helpers: provide gpiod_chip_find_lines()
Implement a new helper that allows to look-up multiple GPIO lines by
their names. Include a set of test cases.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-05-14 12:00:24 +02:00
Bartosz Golaszewski
9616fa5cc9 include: use SPDX license identifier
Use the SPDX license identifier for LGPLv2.1 or later in the public
API header and the corresponding Makefile.am.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-03-04 10:50:11 +01:00
Bartosz Golaszewski
6b6bed27cc API: provide new line accessors
Add two new public functions that allow to retrieve multiple lines from
GPIO chips at once. Include test cases.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-02-22 21:15:43 +01:00
Bartosz Golaszewski
783ff2e3c7 API: start certain enums from 1
For enums describing direction & active state, event types etc. use 1
as the first value as it's easier to debug when all valid values are
different than in a zero-initialized data structure.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-02-19 10:06:07 +01:00
Bartosz Golaszewski
610a8111bc core: constify *values in gpiod_line_set_value_bulk()
The values in the array passed as argument to this routine are never
modified.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-02-03 16:06:47 +01:00
Bartosz Golaszewski
7b493a5019 doc: improve the doxygen description of default_val(s)
Users report being confused by the name 'default_val(s)' for function
parameters. Because it's in line with the kernel uAPI, we'll leave it
like this, but let's improve the documentation a bit by stating
explicitly that this parameter represents the initial values for
requested GPIO lines.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-01-29 17:10:54 +01:00
Bartosz Golaszewski
f27f85f607 doc: consistently break lines in @param's descriptions
When breaking the line in doxygen's @param descriptions, start the
next one after the param's name.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-01-26 11:02:37 +01:00
Bartosz Golaszewski
45c5fbf7c9 doc: explicitly state that the ctxless event poll callback can be NULL
This is mentioned later in the text, but state it in the argument's
description too.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-01-26 10:58:18 +01:00
Bartosz Golaszewski
3eb0c52ad5 doc: clarify that the high-level set value callback is optional
Users have reported it as confusing so make it clear.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-01-26 10:53:23 +01:00
Bartosz Golaszewski
7bddc61ae5 API: use gpiod_ctxless_ as prefix for the high-level API
As suggested by Linus Walleij: the word 'simple' is generally
subjective and the high-level routines provided by libgpiod are not
necessarily simple, but rather contextless, as they don't require any
resource managemend. Use 'gpiod_ctxless_' as prefix for all high-level
symbols.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-01-26 10:36:04 +01:00
Bartosz Golaszewski
7222ec048e all: fix various coding style issues
Make the entire code base more consistent with the linux kernel
coding style.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-01-19 11:40:37 +01:00
Bartosz Golaszewski
0704bcdbbf all: update the copyright notice
All these files have been updated in 2018.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-01-13 23:16:31 +01:00
Bartosz Golaszewski
7df216bf4d all: modify the license preamble in files
This project contains both a library and executables so it's better to
use an umbrella term "This program ..." than "This library ..." in all
the source files.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-01-10 01:50:36 +01:00
Bartosz Golaszewski
65f52d059d doc: minor documentation tweaks
Fix/tweak the in-code API documentation in a couple places.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2018-01-10 01:00:15 +01:00
SZ Lin
7d61309458 all: make license type consistent between source files and COPYING file
The license type of COPYING file is "LGPL-2.1+", but it is declared
as "LGPL-2.1" in the preamble of source files.

This patch fixes license type inconsistency issue in each source file.

Signed-off-by: SZ Lin <sz.lin@moxa.com>
[Bartosz: tweaked the commit message]
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2017-12-01 18:43:54 +01:00
Bartosz Golaszewski
57ecc14c4d core: change the prefix for line request flags
Make it clear that these are flags and that more than one can be used
simultaneously.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2017-11-17 17:51:45 +01:00
Bartosz Golaszewski
48c0caf08a core: coding style tweak
Remove one tab from the GPIOD_LINE_BULK_MAX_LINES definition.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2017-11-17 17:43:15 +01:00
Bartosz Golaszewski
dfe98084e2 iter: rework line iterator API
The changes roughly correspond with what we did for chip iterators.

Only perform operations that can fail in gpiod_line_iter_new(), so
that there's no need to check for errors after every call to
gpiod_line_iter_next().

Make gpiod_line_iter an opaque pointer and provide 'new' and 'free'
functions.

Update all users and relevant test cases. Extend the test API with
a new cleanup function.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2017-11-05 20:57:25 +01:00
Bartosz Golaszewski
1039b1cfb4 doc: update the descriptions for chip iterators
The 'next' routines for chip iterators can no longer fail. Update
the docs accordingly. Also: turn the extended description into a note
for the noclose variant.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2017-11-05 20:34:49 +01:00
Bartosz Golaszewski
230868dcfa iter: rework chip iterators
We can significantly simplify the chip iterators by performing all
actions that can yield an error in gpiod_chip_iter_new(). Instead of
opening each subsequent chip in gpiod_chip_iter_next(), open them all
in the new function and make next just return an active handle.

Fix relevant test cases and macros, remove related routines that are
no longer needed.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
2017-11-04 23:18:26 +01:00