aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-03-18 00:05:32 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-03-18 00:05:32 -0400
commit1a46712aa99594eabe1e9aeedf115dfff0db1dfd (patch)
tree61240865e6b55e2f2b2c174b333c2a097bd4f31e /tools
parent82b666eee71618b7ca812ee529af116582617dec (diff)
parentccbd805aa934dd1b863ef115a9c55f119b2388cf (diff)
Merge tag 'gpio-v4.6-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio
Pull GPIO updates from Linus Walleij: "This is the bulk of GPIO changes for kernel v4.6. There is quite a lot of interesting stuff going on. The patches to other subsystems and arch-wide are ACKed as far as possible, though I consider things like per-arch <asm/gpio.h> as essentially a part of the GPIO subsystem so it should not be needed. Core changes: - The gpio_chip is now a *real device*. Until now the gpio chips were just piggybacking the parent device or (gasp) floating in space outside of the device model. We now finally make GPIO chips devices. The gpio_chip will create a gpio_device which contains a struct device, and this gpio_device struct is kept private. Anything that needs to be kept private from the rest of the kernel will gradually be moved over to the gpio_device. - As a result of making the gpio_device a real device, we have added resource management, so devm_gpiochip_add_data() will cut down on overhead and reduce code lines. A huge slew of patches convert almost all drivers in the subsystem to use this. - Building on making the GPIO a real device, we add the first step of a new userspace ABI: the GPIO character device. We take small steps here, so we first add a pure *information* ABI and the tool "lsgpio" that will list all GPIO devices on the system and all lines on these devices. We can now discover GPIOs properly from userspace. We still have not come up with a way to actually *use* GPIOs from userspace. - To encourage people to use the character device for the future, we have it always-enabled when using GPIO. The old sysfs ABI is still opt-in (and can be used in parallel), but is marked as deprecated. We will keep it around for the foreseeable future, but it will not be extended to cover ever more use cases. Cleanup: - Bjorn Helgaas removed a whole slew of per-architecture <asm/gpio.h> includes. This dates back to when GPIO was an opt-in feature and no shared library even existed: just a header file with proper prototypes was provided and all semantics were up to the arch to implement. These patches make the GPIO chip even more a proper device and cleans out leftovers of the old in-kernel API here and there. Still some cruft is left but it's very little now. - There is still some clamping of return values for .get() going on, but we now return sane values in the vast majority of drivers and the errorpath is sanitized. Some patches for powerpc, blackfin and unicore still drop in. - We continue to switch the ARM, MIPS, blackfin, m68k local GPIO implementations to use gpiochip_add_data() and cut down on code lines. - MPC8xxx is converted to use the generic GPIO helpers. - ATH79 is converted to use the generic GPIO helpers. New drivers: - WinSystems WS16C48 - Acces 104-DIO-48E - F81866 (a F7188x variant) - Qoric (a MPC8xxx variant) - TS-4800 - SPI serializers (pisosr): simple 74xx shift registers connected to SPI to obtain a dirt-cheap output-only GPIO expander. - Texas Instruments TPIC2810 - Texas Instruments TPS65218 - Texas Instruments TPS65912 - X-Gene (ARM64) standby GPIO controller" * tag 'gpio-v4.6-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (194 commits) Revert "Share upstreaming patches" gpio: mcp23s08: Fix clearing of interrupt. gpiolib: Fix comment referring to gpio_*() in gpiod_*() gpio: pca953x: Fix pca953x_gpio_set_multiple() on 64-bit gpio: xgene: Fix kconfig for standby GIPO contoller gpio: Add generic serializer DT binding gpio: uapi: use 0xB4 as ioctl() major gpio: tps65912: fix bad merge Revert "gpio: lp3943: Drop pin_used and lp3943_gpio_request/lp3943_gpio_free" gpio: omap: drop dev field from gpio_bank structure gpio: mpc8xxx: Slightly update the code for better readability gpio: mpc8xxx: Remove *read_reg and *write_reg from struct mpc8xxx_gpio_chip gpio: mpc8xxx: Fixup setting gpio direction output gpio: mcp23s08: Add support for mcp23s18 dt-bindings: gpio: altera: Fix altr,interrupt-type property gpio: add driver for MEN 16Z127 GPIO controller gpio: lp3943: Drop pin_used and lp3943_gpio_request/lp3943_gpio_free gpio: timberdale: Switch to devm_ioremap_resource() gpio: ts4800: Add IMX51 dependency gpiolib: rewrite gpiodev_add_to_list ...
Diffstat (limited to 'tools')
-rw-r--r--tools/Makefile8
-rw-r--r--tools/gpio/Makefile12
-rw-r--r--tools/gpio/gpio-utils.c11
-rw-r--r--tools/gpio/gpio-utils.h27
-rw-r--r--tools/gpio/lsgpio.c195
5 files changed, 250 insertions, 3 deletions
diff --git a/tools/Makefile b/tools/Makefile
index 6339f6ac3ccb..f41e7c6ea23e 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -13,6 +13,7 @@ help:
13 @echo ' cpupower - a tool for all things x86 CPU power' 13 @echo ' cpupower - a tool for all things x86 CPU power'
14 @echo ' firewire - the userspace part of nosy, an IEEE-1394 traffic sniffer' 14 @echo ' firewire - the userspace part of nosy, an IEEE-1394 traffic sniffer'
15 @echo ' freefall - laptop accelerometer program for disk protection' 15 @echo ' freefall - laptop accelerometer program for disk protection'
16 @echo ' gpio - GPIO tools'
16 @echo ' hv - tools used when in Hyper-V clients' 17 @echo ' hv - tools used when in Hyper-V clients'
17 @echo ' iio - IIO tools' 18 @echo ' iio - IIO tools'
18 @echo ' lguest - a minimal 32-bit x86 hypervisor' 19 @echo ' lguest - a minimal 32-bit x86 hypervisor'
@@ -53,7 +54,7 @@ acpi: FORCE
53cpupower: FORCE 54cpupower: FORCE
54 $(call descend,power/$@) 55 $(call descend,power/$@)
55 56
56cgroup firewire hv guest spi usb virtio vm net iio: FORCE 57cgroup firewire hv guest spi usb virtio vm net iio gpio: FORCE
57 $(call descend,$@) 58 $(call descend,$@)
58 59
59liblockdep: FORCE 60liblockdep: FORCE
@@ -119,7 +120,7 @@ acpi_clean:
119cpupower_clean: 120cpupower_clean:
120 $(call descend,power/cpupower,clean) 121 $(call descend,power/cpupower,clean)
121 122
122cgroup_clean hv_clean firewire_clean lguest_clean spi_clean usb_clean virtio_clean vm_clean net_clean iio_clean: 123cgroup_clean hv_clean firewire_clean lguest_clean spi_clean usb_clean virtio_clean vm_clean net_clean iio_clean gpio_clean:
123 $(call descend,$(@:_clean=),clean) 124 $(call descend,$(@:_clean=),clean)
124 125
125liblockdep_clean: 126liblockdep_clean:
@@ -155,6 +156,7 @@ build_clean:
155clean: acpi_clean cgroup_clean cpupower_clean hv_clean firewire_clean lguest_clean \ 156clean: acpi_clean cgroup_clean cpupower_clean hv_clean firewire_clean lguest_clean \
156 perf_clean selftests_clean turbostat_clean spi_clean usb_clean virtio_clean \ 157 perf_clean selftests_clean turbostat_clean spi_clean usb_clean virtio_clean \
157 vm_clean net_clean iio_clean x86_energy_perf_policy_clean tmon_clean \ 158 vm_clean net_clean iio_clean x86_energy_perf_policy_clean tmon_clean \
158 freefall_clean build_clean libbpf_clean libsubcmd_clean liblockdep_clean 159 freefall_clean build_clean libbpf_clean libsubcmd_clean liblockdep_clean \
160 gpio_clean
159 161
160.PHONY: FORCE 162.PHONY: FORCE
diff --git a/tools/gpio/Makefile b/tools/gpio/Makefile
new file mode 100644
index 000000000000..4d198d5c4203
--- /dev/null
+++ b/tools/gpio/Makefile
@@ -0,0 +1,12 @@
1CC = $(CROSS_COMPILE)gcc
2CFLAGS += -Wall -g -D_GNU_SOURCE
3
4all: lsgpio
5
6lsgpio: lsgpio.o gpio-utils.o
7
8%.o: %.c gpio-utils.h
9
10.PHONY: clean
11clean:
12 rm -f *.o lsgpio
diff --git a/tools/gpio/gpio-utils.c b/tools/gpio/gpio-utils.c
new file mode 100644
index 000000000000..8208718f2c99
--- /dev/null
+++ b/tools/gpio/gpio-utils.c
@@ -0,0 +1,11 @@
1/*
2 * GPIO tools - helpers library for the GPIO tools
3 *
4 * Copyright (C) 2015 Linus Walleij
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
9 */
10
11#include "gpio-utils.h"
diff --git a/tools/gpio/gpio-utils.h b/tools/gpio/gpio-utils.h
new file mode 100644
index 000000000000..5f57133b8c04
--- /dev/null
+++ b/tools/gpio/gpio-utils.h
@@ -0,0 +1,27 @@
1/*
2 * GPIO tools - utility helpers library for the GPIO tools
3 *
4 * Copyright (C) 2015 Linus Walleij
5 *
6 * Portions copied from iio_utils and lssio:
7 * Copyright (c) 2010 Manuel Stahl <manuel.stahl@iis.fraunhofer.de>
8 * Copyright (c) 2008 Jonathan Cameron
9 * *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
13 */
14#ifndef _GPIO_UTILS_H_
15#define _GPIO_UTILS_H_
16
17#include <string.h>
18
19#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
20
21static inline int check_prefix(const char *str, const char *prefix)
22{
23 return strlen(str) > strlen(prefix) &&
24 strncmp(str, prefix, strlen(prefix)) == 0;
25}
26
27#endif /* _GPIO_UTILS_H_ */
diff --git a/tools/gpio/lsgpio.c b/tools/gpio/lsgpio.c
new file mode 100644
index 000000000000..1124da375942
--- /dev/null
+++ b/tools/gpio/lsgpio.c
@@ -0,0 +1,195 @@
1/*
2 * lsgpio - example on how to list the GPIO lines on a system
3 *
4 * Copyright (C) 2015 Linus Walleij
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
9 *
10 * Usage:
11 * lsgpio <-n device-name>
12 */
13
14#include <unistd.h>
15#include <stdlib.h>
16#include <stdbool.h>
17#include <stdio.h>
18#include <dirent.h>
19#include <errno.h>
20#include <string.h>
21#include <poll.h>
22#include <fcntl.h>
23#include <getopt.h>
24#include <sys/ioctl.h>
25#include <linux/gpio.h>
26
27#include "gpio-utils.h"
28
29struct gpio_flag {
30 char *name;
31 unsigned long mask;
32};
33
34struct gpio_flag flagnames[] = {
35 {
36 .name = "kernel",
37 .mask = GPIOLINE_FLAG_KERNEL,
38 },
39 {
40 .name = "output",
41 .mask = GPIOLINE_FLAG_IS_OUT,
42 },
43 {
44 .name = "active-low",
45 .mask = GPIOLINE_FLAG_ACTIVE_LOW,
46 },
47 {
48 .name = "open-drain",
49 .mask = GPIOLINE_FLAG_OPEN_DRAIN,
50 },
51 {
52 .name = "open-source",
53 .mask = GPIOLINE_FLAG_OPEN_SOURCE,
54 },
55};
56
57void print_flags(unsigned long flags)
58{
59 int i;
60 int printed = 0;
61
62 for (i = 0; i < ARRAY_SIZE(flagnames); i++) {
63 if (flags & flagnames[i].mask) {
64 if (printed)
65 fprintf(stdout, " ");
66 fprintf(stdout, "%s", flagnames[i].name);
67 printed++;
68 }
69 }
70}
71
72int list_device(const char *device_name)
73{
74 struct gpiochip_info cinfo;
75 char *chrdev_name;
76 int fd;
77 int ret;
78 int i;
79
80 ret = asprintf(&chrdev_name, "/dev/%s", device_name);
81 if (ret < 0)
82 return -ENOMEM;
83
84 fd = open(chrdev_name, 0);
85 if (fd == -1) {
86 ret = -errno;
87 fprintf(stderr, "Failed to open %s\n", chrdev_name);
88 goto exit_close_error;
89 }
90
91 /* Inspect this GPIO chip */
92 ret = ioctl(fd, GPIO_GET_CHIPINFO_IOCTL, &cinfo);
93 if (ret == -1) {
94 ret = -errno;
95 perror("Failed to issue CHIPINFO IOCTL\n");
96 goto exit_close_error;
97 }
98 fprintf(stdout, "GPIO chip: %s, \"%s\", %u GPIO lines\n",
99 cinfo.name, cinfo.label, cinfo.lines);
100
101 /* Loop over the lines and print info */
102 for (i = 0; i < cinfo.lines; i++) {
103 struct gpioline_info linfo;
104
105 memset(&linfo, 0, sizeof(linfo));
106 linfo.line_offset = i;
107
108 ret = ioctl(fd, GPIO_GET_LINEINFO_IOCTL, &linfo);
109 if (ret == -1) {
110 ret = -errno;
111 perror("Failed to issue LINEINFO IOCTL\n");
112 goto exit_close_error;
113 }
114 fprintf(stdout, "\tline %2d:", linfo.line_offset);
115 if (linfo.name[0])
116 fprintf(stdout, " \"%s\"", linfo.name);
117 else
118 fprintf(stdout, " unnamed");
119 if (linfo.consumer[0])
120 fprintf(stdout, " \"%s\"", linfo.consumer);
121 else
122 fprintf(stdout, " unused");
123 if (linfo.flags) {
124 fprintf(stdout, " [");
125 print_flags(linfo.flags);
126 fprintf(stdout, "]");
127 }
128 fprintf(stdout, "\n");
129
130 }
131
132exit_close_error:
133 if (close(fd) == -1)
134 perror("Failed to close GPIO character device file");
135 free(chrdev_name);
136 return ret;
137}
138
139void print_usage(void)
140{
141 fprintf(stderr, "Usage: lsgpio [options]...\n"
142 "List GPIO chips, lines and states\n"
143 " -n <name> List GPIOs on a named device\n"
144 " -? This helptext\n"
145 );
146}
147
148int main(int argc, char **argv)
149{
150 const char *device_name;
151 int ret;
152 int c;
153
154 while ((c = getopt(argc, argv, "n:")) != -1) {
155 switch (c) {
156 case 'n':
157 device_name = optarg;
158 break;
159 case '?':
160 print_usage();
161 return -1;
162 }
163 }
164
165 if (device_name)
166 ret = list_device(device_name);
167 else {
168 const struct dirent *ent;
169 DIR *dp;
170
171 /* List all GPIO devices one at a time */
172 dp = opendir("/dev");
173 if (!dp) {
174 ret = -errno;
175 goto error_out;
176 }
177
178 ret = -ENOENT;
179 while (ent = readdir(dp), ent) {
180 if (check_prefix(ent->d_name, "gpiochip")) {
181 ret = list_device(ent->d_name);
182 if (ret)
183 break;
184 }
185 }
186
187 ret = 0;
188 if (closedir(dp) == -1) {
189 perror("scanning devices: Failed to close directory");
190 ret = -errno;
191 }
192 }
193error_out:
194 return ret;
195}