summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-support/libgpiod/libgpiod/0001-Add-pass-through-setting-in-gpioset.patch
blob: b9082468c2cbeb7a28833eb6c26e965c96f2bc83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
From 0c393ec7a71f21506334caa3a321fa013a9723ef Mon Sep 17 00:00:00 2001
From: Ed Tanous <ed.tanous@intel.com>
Date: Mon, 8 Apr 2019 11:46:09 -0700
Subject: [PATCH] [PATCH] Add pass through setting in gpioset

Signed-off-by: Kuiying Wang <kuiying.wang@intel.com>
Signed-off-by: Ed Tanous <ed.tanous@intel.com>
---
 aclocal.m4            |  2 +-
 configure             |  2 +-
 include/gpiod.h       | 10 ++++++++--
 lib/core.c            | 13 +++++++------
 lib/ctxless.c         |  8 +++++---
 lib/helpers.c         |  3 ++-
 tests/tests-ctxless.c |  2 +-
 tools/gpioset.c       | 13 +++++++++----
 8 files changed, 34 insertions(+), 19 deletions(-)

diff --git a/aclocal.m4 b/aclocal.m4
index b0db596..a5e28ad 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -911,7 +911,7 @@ AS_VAR_IF([$1], [""], [$5], [$4])dnl
 # generated from the m4 files accompanying Automake X.Y.
 # (This private macro should not be called outside this file.)
 AC_DEFUN([AM_AUTOMAKE_VERSION],
-[am__api_version='1.15'
+[am__api_version='1.16'
 dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
 dnl require some minimum version.  Point them to the right macro.
 m4_if([$1], [1.15], [],
diff --git a/configure b/configure
index f5a0a23..c0cdbf1 100755
--- a/configure
+++ b/configure
@@ -2484,7 +2484,7 @@ ac_configure="$SHELL $ac_aux_dir/configure"  # Please don't use this var.
 
 
 
-am__api_version='1.15'
+am__api_version='1.16'
 
 # Find a good install program.  We prefer a C program (faster),
 # so one script is as good as another.  But avoid the broken or
diff --git a/include/gpiod.h b/include/gpiod.h
index 2679478..7b5c186 100644
--- a/include/gpiod.h
+++ b/include/gpiod.h
@@ -121,6 +121,7 @@ typedef void (*gpiod_ctxless_set_value_cb)(void *);
  * @param offset The offset of the GPIO line.
  * @param value New value (0 or 1).
  * @param active_low The active state of this line - true if low.
+ * @param pass_through The pass-through state of the lines - true if enabled.
  * @param consumer Name of the consumer.
  * @param cb Optional callback function that will be called right after setting
  *           the value. Users can use this, for example, to pause the execution
@@ -129,7 +130,7 @@ typedef void (*gpiod_ctxless_set_value_cb)(void *);
  * @return 0 if the operation succeeds, -1 on error.
  */
 int gpiod_ctxless_set_value(const char *device, unsigned int offset, int value,
-			    bool active_low, const char *consumer,
+			    bool active_low, bool pass_through, const char *consumer,
 			    gpiod_ctxless_set_value_cb cb,
 			    void *data) GPIOD_API;
 
@@ -140,6 +141,7 @@ int gpiod_ctxless_set_value(const char *device, unsigned int offset, int value,
  * @param values Array of integers containing new values.
  * @param num_lines Number of lines, must be > 0.
  * @param active_low The active state of the lines - true if low.
+ * @param pass_through The pass-through state of the lines - true if enabled.
  * @param consumer Name of the consumer.
  * @param cb Optional callback function that will be called right after setting
  *           all values. Works the same as in ::gpiod_ctxless_set_value.
@@ -149,7 +151,7 @@ int gpiod_ctxless_set_value(const char *device, unsigned int offset, int value,
 int gpiod_ctxless_set_value_multiple(const char *device,
 				     const unsigned int *offsets,
 				     const int *values, unsigned int num_lines,
-				     bool active_low, const char *consumer,
+				     bool active_low, bool pass_through, const char *consumer,
 				     gpiod_ctxless_set_value_cb cb,
 				     void *data) GPIOD_API;
 
@@ -766,6 +768,8 @@ enum {
 	/**< Request the line(s) for reading the GPIO line state. */
 	GPIOD_LINE_REQUEST_DIRECTION_OUTPUT,
 	/**< Request the line(s) for setting the GPIO line state. */
+	GPIOD_LINE_REQUEST_DIRECTION_PASS_THROUGH,
+	/**< Request the line(s) for setting the GPIO line state. */
 	GPIOD_LINE_REQUEST_EVENT_FALLING_EDGE,
 	/**< Monitor both types of events. */
 	GPIOD_LINE_REQUEST_EVENT_RISING_EDGE,
@@ -784,6 +788,8 @@ enum {
 	/**< The line is an open-source port. */
 	GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW	= GPIOD_BIT(2),
 	/**< The active state of the line is low (high is the default). */
+	GPIOD_LINE_REQUEST_FLAG_PASS_THROUGH	= GPIOD_BIT(5),
+	/**< The line is a pass-through port*/
 };
 
 /**
diff --git a/lib/core.c b/lib/core.c
index 05e5a46..635569c 100644
--- a/lib/core.c
+++ b/lib/core.c
@@ -470,7 +470,6 @@ static int line_request_values(struct gpiod_line_bulk *bulk,
 	struct gpiohandle_request req;
 	unsigned int i;
 	int rv, fd;
-
 	if ((config->request_type != GPIOD_LINE_REQUEST_DIRECTION_OUTPUT) &&
 	    (config->flags & (GPIOD_LINE_REQUEST_FLAG_OPEN_DRAIN |
 			      GPIOD_LINE_REQUEST_FLAG_OPEN_SOURCE))) {
@@ -497,14 +496,15 @@ static int line_request_values(struct gpiod_line_bulk *bulk,
 		req.flags |= GPIOHANDLE_REQUEST_INPUT;
 	else if (config->request_type == GPIOD_LINE_REQUEST_DIRECTION_OUTPUT)
 		req.flags |= GPIOHANDLE_REQUEST_OUTPUT;
-
+	else if (config->request_type == GPIOD_LINE_REQUEST_DIRECTION_PASS_THROUGH)
+		req.flags |= GPIOHANDLE_REQUEST_PASS_THROUGH;
 	req.lines = gpiod_line_bulk_num_lines(bulk);
 
 	gpiod_line_bulk_foreach_line_off(bulk, line, i) {
 		req.lineoffsets[i] = gpiod_line_offset(line);
-		if (config->request_type ==
-				GPIOD_LINE_REQUEST_DIRECTION_OUTPUT &&
-		    default_vals)
+		if ((config->request_type == GPIOD_LINE_REQUEST_DIRECTION_OUTPUT ||
+			config->request_type == GPIOD_LINE_REQUEST_DIRECTION_PASS_THROUGH)&&
+				default_vals)
 			req.default_values[i] = !!default_vals[i];
 	}
 
@@ -615,7 +615,8 @@ static bool line_request_is_direction(int request)
 {
 	return request == GPIOD_LINE_REQUEST_DIRECTION_AS_IS ||
 	       request == GPIOD_LINE_REQUEST_DIRECTION_INPUT ||
-	       request == GPIOD_LINE_REQUEST_DIRECTION_OUTPUT;
+	       request == GPIOD_LINE_REQUEST_DIRECTION_OUTPUT ||
+	       request == GPIOD_LINE_REQUEST_DIRECTION_PASS_THROUGH;
 }
 
 static bool line_request_is_events(int request)
diff --git a/lib/ctxless.c b/lib/ctxless.c
index ba85018..88b0388 100644
--- a/lib/ctxless.c
+++ b/lib/ctxless.c
@@ -76,17 +76,17 @@ int gpiod_ctxless_get_value_multiple(const char *device,
 }
 
 int gpiod_ctxless_set_value(const char *device, unsigned int offset, int value,
-			    bool active_low, const char *consumer,
+			    bool active_low, bool pass_through, const char *consumer,
 			    gpiod_ctxless_set_value_cb cb, void *data)
 {
 	return gpiod_ctxless_set_value_multiple(device, &offset, &value, 1,
-						active_low, consumer, cb, data);
+						active_low, pass_through, consumer, cb, data);
 }
 
 int gpiod_ctxless_set_value_multiple(const char *device,
 				     const unsigned int *offsets,
 				     const int *values, unsigned int num_lines,
-				     bool active_low, const char *consumer,
+				     bool active_low, bool pass_through, const char *consumer,
 				     gpiod_ctxless_set_value_cb cb, void *data)
 {
 	struct gpiod_line_bulk bulk;
@@ -118,6 +118,8 @@ int gpiod_ctxless_set_value_multiple(const char *device,
 
 	flags = active_low ? GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW : 0;
 
+	flags |= pass_through ? GPIOD_LINE_REQUEST_FLAG_PASS_THROUGH : 0;
+
 	rv = gpiod_line_request_bulk_output_flags(&bulk, consumer,
 						  flags, values);
 	if (rv < 0) {
diff --git a/lib/helpers.c b/lib/helpers.c
index 479f370..7b2884f 100644
--- a/lib/helpers.c
+++ b/lib/helpers.c
@@ -360,7 +360,8 @@ int gpiod_line_request_bulk_output_flags(struct gpiod_line_bulk *bulk,
 		.request_type = GPIOD_LINE_REQUEST_DIRECTION_OUTPUT,
 		.flags = flags,
 	};
-
+	if (flags & GPIOD_LINE_REQUEST_FLAG_PASS_THROUGH)
+		config.request_type = GPIOD_LINE_REQUEST_DIRECTION_PASS_THROUGH;
 	return gpiod_line_request_bulk(bulk, &config, default_vals);
 }
 
diff --git a/tests/tests-ctxless.c b/tests/tests-ctxless.c
index 638274f..b215f9c 100644
--- a/tests/tests-ctxless.c
+++ b/tests/tests-ctxless.c
@@ -20,7 +20,7 @@ static void ctxless_set_get_value(void)
 	TEST_ASSERT_EQ(rv, 0);
 
 	rv = gpiod_ctxless_set_value(test_chip_name(0), 3, 1,
-				     false, TEST_CONSUMER, NULL, NULL);
+				     false, false, TEST_CONSUMER, NULL, NULL);
 	TEST_ASSERT_RET_OK(rv);
 
 	rv = gpiod_ctxless_get_value(test_chip_name(0), 3,
diff --git a/tools/gpioset.c b/tools/gpioset.c
index d9977a7..094d609 100644
--- a/tools/gpioset.c
+++ b/tools/gpioset.c
@@ -22,7 +22,8 @@
 static const struct option longopts[] = {
 	{ "help",		no_argument,		NULL,	'h' },
 	{ "version",		no_argument,		NULL,	'v' },
-	{ "active-low",		no_argument,		NULL,	'l' },
+	{ "active-low",		no_argument,		NULL,   'l' },
+	{ "pass-through",	no_argument,		NULL,	'p' },
 	{ "mode",		required_argument,	NULL,	'm' },
 	{ "sec",		required_argument,	NULL,	's' },
 	{ "usec",		required_argument,	NULL,	'u' },
@@ -30,7 +31,7 @@ static const struct option longopts[] = {
 	{ GETOPT_NULL_LONGOPT },
 };
 
-static const char *const shortopts = "+hvlm:s:u:b";
+static const char *const shortopts = "+hvlpm:s:u:b";
 
 static void print_help(void)
 {
@@ -40,8 +41,9 @@ static void print_help(void)
 	printf("\n");
 	printf("Options:\n");
 	printf("  -h, --help:\t\tdisplay this message and exit\n");
-	printf("  -v, --version:\tdisplay the version and exit\n");
 	printf("  -l, --active-low:\tset the line active state to low\n");
+	printf("  -v, --version:\tdisplay the version and exit\n");
+	printf("  -p, --pass-through:\tset it to pass through mode\n");
 	printf("  -m, --mode=[exit|wait|time|signal] (defaults to 'exit'):\n");
 	printf("		tell the program what to do after setting values\n");
 	printf("  -s, --sec=SEC:\tspecify the number of seconds to wait (only valid for --mode=time)\n");
@@ -185,6 +187,7 @@ int main(int argc, char **argv)
 	int *values, rv, optc, opti;
 	struct callback_data cbdata;
 	bool active_low = false;
+	bool pass_through = false;
 	char *device, *end;
 
 	memset(&cbdata, 0, sizeof(cbdata));
@@ -203,6 +206,8 @@ int main(int argc, char **argv)
 			return EXIT_SUCCESS;
 		case 'l':
 			active_low = true;
+		case 'p':
+			pass_through = true;
 			break;
 		case 'm':
 			mode = parse_mode(optarg);
@@ -269,7 +274,7 @@ int main(int argc, char **argv)
 	}
 
 	rv = gpiod_ctxless_set_value_multiple(device, offsets, values,
-					      num_lines, active_low, "gpioset",
+					      num_lines, active_low, pass_through, "gpioset",
 					      mode->callback, &cbdata);
 	if (rv < 0)
 		die_perror("error setting the GPIO line values");
-- 
2.17.1