Lines Matching +full:gpio +full:- +full:lines
1 // SPDX-License-Identifier: GPL-2.0-only
3 * GPIO tools - helpers library for the GPIO tools
17 #include <linux/gpio.h>
18 #include "gpio-utils.h"
20 #define CONSUMER "gpio-utils"
23 * DOC: Operation of gpio
27 * ioctl, including request and release for lines of gpio, read/write
28 * the value of gpio. If the user want to do lots of read and write of
29 * lines of gpio, user should use this type of api.
32 * following api will request gpio lines, do the operation and then
33 * release these lines.
37 * gpiotools_request_line() - request gpio lines in a gpiochip
40 * @lines: An array desired lines, specified by offset
41 * index for the associated GPIO device.
42 * @num_lines: The number of lines to request.
43 * @config: The new config for requested gpio. Reference
44 * "linux/gpio.h" for config details.
49 * Request gpio lines through the ioctl provided by chardev. User
52 * gpiotools_release_line() to release these lines after that.
57 int gpiotools_request_line(const char *device_name, unsigned int *lines, in gpiotools_request_line() argument
70 return -ENOMEM; in gpiotools_request_line()
73 if (fd == -1) { in gpiotools_request_line()
74 ret = -errno; in gpiotools_request_line()
82 req.offsets[i] = lines[i]; in gpiotools_request_line()
89 if (ret == -1) { in gpiotools_request_line()
90 ret = -errno; in gpiotools_request_line()
95 if (close(fd) == -1) in gpiotools_request_line()
96 perror("Failed to close GPIO character device file"); in gpiotools_request_line()
103 * gpiotools_set_values() - Set the value of gpio(s)
116 if (ret == -1) { in gpiotools_set_values()
117 ret = -errno; in gpiotools_set_values()
127 * gpiotools_get_values() - Get the value of gpio(s)
140 if (ret == -1) { in gpiotools_get_values()
141 ret = -errno; in gpiotools_get_values()
151 * gpiotools_release_line() - Release the line(s) of gpiochip
163 if (ret == -1) { in gpiotools_release_line()
164 perror("Failed to close GPIO LINE device file"); in gpiotools_release_line()
165 ret = -errno; in gpiotools_release_line()
172 * gpiotools_get() - Get value from specific line
184 unsigned int lines[] = {line}; in gpiotools_get() local
186 ret = gpiotools_gets(device_name, lines, 1, &value); in gpiotools_get()
194 * gpiotools_gets() - Get values from specific lines.
197 * @lines: An array desired lines, specified by offset
198 * index for the associated GPIO device.
199 * @num_lines: The number of lines to request.
205 int gpiotools_gets(const char *device_name, unsigned int *lines, in gpiotools_gets() argument
216 ret = gpiotools_request_line(device_name, lines, num_lines, in gpiotools_gets()
233 * gpiotools_set() - Set value to specific line
237 * @value: The value of gpio, must be 0(low) or 1(high).
245 unsigned int lines[] = {line}; in gpiotools_set() local
247 return gpiotools_sets(device_name, lines, 1, &value); in gpiotools_set()
251 * gpiotools_sets() - Set values to specific lines.
254 * @lines: An array desired lines, specified by offset
255 * index for the associated GPIO device.
256 * @num_lines: The number of lines to request.
263 int gpiotools_sets(const char *device_name, unsigned int *lines, in gpiotools_sets() argument
278 ret = gpiotools_request_line(device_name, lines, num_lines, in gpiotools_sets()