summaryrefslogtreecommitdiffstats
path: root/target/linux/bcm27xx/patches-6.1/950-0840-gpio-fsm-Sort-functions-into-a-more-logical-order.patch
blob: 873077f51c6fe9c602b6d5f18fccd011b3f4b2b5 (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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
From cee471c3ada3215d6dfc53fb0f1b97548444dea7 Mon Sep 17 00:00:00 2001
From: Phil Elwell <phil@raspberrypi.com>
Date: Tue, 5 Sep 2023 11:56:19 +0100
Subject: [PATCH] gpio-fsm: Sort functions into a more logical order

Move some functions into a more logical ordering. This change causes
no functional change and is essentially cosmetic.

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
---
 drivers/gpio/gpio-fsm.c | 245 ++++++++++++++++++++--------------------
 1 file changed, 125 insertions(+), 120 deletions(-)

--- a/drivers/gpio/gpio-fsm.c
+++ b/drivers/gpio/gpio-fsm.c
@@ -193,131 +193,14 @@ static void free_symbols(struct symtab_e
 	}
 }
 
-static int gpio_fsm_get_direction(struct gpio_chip *gc, unsigned int off)
-{
-	struct gpio_fsm *gf = gpiochip_get_data(gc);
-	struct soft_gpio *sg;
-
-	if (off >= gf->num_soft_gpios)
-		return -EINVAL;
-	sg = &gf->soft_gpios[off];
-
-	return sg->dir;
-}
-
-static int gpio_fsm_get(struct gpio_chip *gc, unsigned int off)
-{
-	struct gpio_fsm *gf = gpiochip_get_data(gc);
-	struct soft_gpio *sg;
-
-	if (off >= gf->num_soft_gpios)
-		return -EINVAL;
-	sg = &gf->soft_gpios[off];
-
-	return sg->value;
-}
-
 static void gpio_fsm_go_to_state(struct gpio_fsm *gf,
-				   struct fsm_state *new_state)
-{
-	struct input_gpio_state *inp_state;
-	struct gpio_event *gp_ev;
-	struct fsm_state *state;
-	int i;
-
-	dev_dbg(gf->dev, "go_to_state(%s)\n",
-		  new_state ? new_state->name : "<unset>");
-
-	spin_lock(&gf->spinlock);
-
-	if (gf->next_state) {
-		/* Something else has already requested a transition */
-		spin_unlock(&gf->spinlock);
-		return;
-	}
-
-	gf->next_state = new_state;
-	state = gf->current_state;
-	gf->delay_target_state = NULL;
-
-	if (state) {
-		/* Disarm any GPIO IRQs */
-		for (i = 0; i < state->num_gpio_events; i++) {
-			gp_ev = &state->gpio_events[i];
-			inp_state = &gf->input_gpio_states[gp_ev->index];
-			inp_state->target = NULL;
-		}
-	}
-
-	spin_unlock(&gf->spinlock);
-
-	if (new_state)
-		schedule_work(&gf->work);
-}
+				 struct fsm_state *new_state);
 
 static void gpio_fsm_set_soft(struct gpio_fsm *gf,
-				unsigned int off, int val)
-{
-	struct soft_gpio *sg = &gf->soft_gpios[off];
-	struct gpio_event *gp_ev;
-	struct fsm_state *state;
-	int i;
-
-	dev_dbg(gf->dev, "set(%d,%d)\n", off, val);
-	state = gf->current_state;
-	sg->value = val;
-	for (i = 0; i < state->num_soft_events; i++) {
-		gp_ev = &state->soft_events[i];
-		if (gp_ev->index == off && gp_ev->value == val) {
-			if (gf->debug)
-				dev_info(gf->dev,
-					 "GF_SOFT %d->%d -> %s\n", gp_ev->index,
-					 gp_ev->value, gp_ev->target->name);
-			gpio_fsm_go_to_state(gf, gp_ev->target);
-			break;
-		}
-	}
-}
-
-static int gpio_fsm_direction_input(struct gpio_chip *gc, unsigned int off)
-{
-	struct gpio_fsm *gf = gpiochip_get_data(gc);
-	struct soft_gpio *sg;
-
-	if (off >= gf->num_soft_gpios)
-		return -EINVAL;
-	sg = &gf->soft_gpios[off];
-	sg->dir = GPIOF_DIR_IN;
-
-	return 0;
-}
-
-static int gpio_fsm_direction_output(struct gpio_chip *gc, unsigned int off,
-				       int value)
-{
-	struct gpio_fsm *gf = gpiochip_get_data(gc);
-	struct soft_gpio *sg;
-
-	if (off >= gf->num_soft_gpios)
-		return -EINVAL;
-	sg = &gf->soft_gpios[off];
-	sg->dir = GPIOF_DIR_OUT;
-	gpio_fsm_set_soft(gf, off, value);
-
-	return 0;
-}
-
-static void gpio_fsm_set(struct gpio_chip *gc, unsigned int off, int val)
-{
-	struct gpio_fsm *gf;
-
-	gf = gpiochip_get_data(gc);
-	if (off < gf->num_soft_gpios)
-		gpio_fsm_set_soft(gf, off, val);
-}
+			      unsigned int off, int val);
 
 static void gpio_fsm_enter_state(struct gpio_fsm *gf,
-				   struct fsm_state *state)
+				 struct fsm_state *state)
 {
 	struct input_gpio_state *inp_state;
 	struct output_signal *signal;
@@ -431,6 +314,44 @@ static void gpio_fsm_enter_state(struct
 	}
 }
 
+static void gpio_fsm_go_to_state(struct gpio_fsm *gf,
+				 struct fsm_state *new_state)
+{
+	struct input_gpio_state *inp_state;
+	struct gpio_event *gp_ev;
+	struct fsm_state *state;
+	int i;
+
+	dev_dbg(gf->dev, "go_to_state(%s)\n",
+		  new_state ? new_state->name : "<unset>");
+
+	spin_lock(&gf->spinlock);
+
+	if (gf->next_state) {
+		/* Something else has already requested a transition */
+		spin_unlock(&gf->spinlock);
+		return;
+	}
+
+	gf->next_state = new_state;
+	state = gf->current_state;
+	gf->delay_target_state = NULL;
+
+	if (state) {
+		/* Disarm any GPIO IRQs */
+		for (i = 0; i < state->num_gpio_events; i++) {
+			gp_ev = &state->gpio_events[i];
+			inp_state = &gf->input_gpio_states[gp_ev->index];
+			inp_state->target = NULL;
+		}
+	}
+
+	spin_unlock(&gf->spinlock);
+
+	if (new_state)
+		schedule_work(&gf->work);
+}
+
 static void gpio_fsm_work(struct work_struct *work)
 {
 	struct input_gpio_state *inp_state;
@@ -851,6 +772,90 @@ static int resolve_sym_to_state(struct g
 	return 0;
 }
 
+static void gpio_fsm_set_soft(struct gpio_fsm *gf,
+			      unsigned int off, int val)
+{
+	struct soft_gpio *sg = &gf->soft_gpios[off];
+	struct gpio_event *gp_ev;
+	struct fsm_state *state;
+	int i;
+
+	dev_dbg(gf->dev, "set(%d,%d)\n", off, val);
+	state = gf->current_state;
+	sg->value = val;
+	for (i = 0; i < state->num_soft_events; i++) {
+		gp_ev = &state->soft_events[i];
+		if (gp_ev->index == off && gp_ev->value == val) {
+			if (gf->debug)
+				dev_info(gf->dev,
+					 "GF_SOFT %d->%d -> %s\n", gp_ev->index,
+					 gp_ev->value, gp_ev->target->name);
+			gpio_fsm_go_to_state(gf, gp_ev->target);
+			break;
+		}
+	}
+}
+
+static int gpio_fsm_get(struct gpio_chip *gc, unsigned int off)
+{
+	struct gpio_fsm *gf = gpiochip_get_data(gc);
+	struct soft_gpio *sg;
+
+	if (off >= gf->num_soft_gpios)
+		return -EINVAL;
+	sg = &gf->soft_gpios[off];
+
+	return sg->value;
+}
+
+static void gpio_fsm_set(struct gpio_chip *gc, unsigned int off, int val)
+{
+	struct gpio_fsm *gf;
+
+	gf = gpiochip_get_data(gc);
+	if (off < gf->num_soft_gpios)
+		gpio_fsm_set_soft(gf, off, val);
+}
+
+static int gpio_fsm_get_direction(struct gpio_chip *gc, unsigned int off)
+{
+	struct gpio_fsm *gf = gpiochip_get_data(gc);
+	struct soft_gpio *sg;
+
+	if (off >= gf->num_soft_gpios)
+		return -EINVAL;
+	sg = &gf->soft_gpios[off];
+
+	return sg->dir;
+}
+
+static int gpio_fsm_direction_input(struct gpio_chip *gc, unsigned int off)
+{
+	struct gpio_fsm *gf = gpiochip_get_data(gc);
+	struct soft_gpio *sg;
+
+	if (off >= gf->num_soft_gpios)
+		return -EINVAL;
+	sg = &gf->soft_gpios[off];
+	sg->dir = GPIOF_DIR_IN;
+
+	return 0;
+}
+
+static int gpio_fsm_direction_output(struct gpio_chip *gc, unsigned int off,
+				       int value)
+{
+	struct gpio_fsm *gf = gpiochip_get_data(gc);
+	struct soft_gpio *sg;
+
+	if (off >= gf->num_soft_gpios)
+		return -EINVAL;
+	sg = &gf->soft_gpios[off];
+	sg->dir = GPIOF_DIR_OUT;
+	gpio_fsm_set_soft(gf, off, value);
+
+	return 0;
+}
 
 /*
  * /sys/class/gpio-fsm/<fsm-name>/