bcm27xx: update 6.1 patches to latest version
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-6.1 / 950-0840-gpio-fsm-Sort-functions-into-a-more-logical-order.patch
1 From cee471c3ada3215d6dfc53fb0f1b97548444dea7 Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.com>
3 Date: Tue, 5 Sep 2023 11:56:19 +0100
4 Subject: [PATCH] gpio-fsm: Sort functions into a more logical order
5
6 Move some functions into a more logical ordering. This change causes
7 no functional change and is essentially cosmetic.
8
9 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
10 ---
11 drivers/gpio/gpio-fsm.c | 245 ++++++++++++++++++++--------------------
12 1 file changed, 125 insertions(+), 120 deletions(-)
13
14 --- a/drivers/gpio/gpio-fsm.c
15 +++ b/drivers/gpio/gpio-fsm.c
16 @@ -193,131 +193,14 @@ static void free_symbols(struct symtab_e
17 }
18 }
19
20 -static int gpio_fsm_get_direction(struct gpio_chip *gc, unsigned int off)
21 -{
22 - struct gpio_fsm *gf = gpiochip_get_data(gc);
23 - struct soft_gpio *sg;
24 -
25 - if (off >= gf->num_soft_gpios)
26 - return -EINVAL;
27 - sg = &gf->soft_gpios[off];
28 -
29 - return sg->dir;
30 -}
31 -
32 -static int gpio_fsm_get(struct gpio_chip *gc, unsigned int off)
33 -{
34 - struct gpio_fsm *gf = gpiochip_get_data(gc);
35 - struct soft_gpio *sg;
36 -
37 - if (off >= gf->num_soft_gpios)
38 - return -EINVAL;
39 - sg = &gf->soft_gpios[off];
40 -
41 - return sg->value;
42 -}
43 -
44 static void gpio_fsm_go_to_state(struct gpio_fsm *gf,
45 - struct fsm_state *new_state)
46 -{
47 - struct input_gpio_state *inp_state;
48 - struct gpio_event *gp_ev;
49 - struct fsm_state *state;
50 - int i;
51 -
52 - dev_dbg(gf->dev, "go_to_state(%s)\n",
53 - new_state ? new_state->name : "<unset>");
54 -
55 - spin_lock(&gf->spinlock);
56 -
57 - if (gf->next_state) {
58 - /* Something else has already requested a transition */
59 - spin_unlock(&gf->spinlock);
60 - return;
61 - }
62 -
63 - gf->next_state = new_state;
64 - state = gf->current_state;
65 - gf->delay_target_state = NULL;
66 -
67 - if (state) {
68 - /* Disarm any GPIO IRQs */
69 - for (i = 0; i < state->num_gpio_events; i++) {
70 - gp_ev = &state->gpio_events[i];
71 - inp_state = &gf->input_gpio_states[gp_ev->index];
72 - inp_state->target = NULL;
73 - }
74 - }
75 -
76 - spin_unlock(&gf->spinlock);
77 -
78 - if (new_state)
79 - schedule_work(&gf->work);
80 -}
81 + struct fsm_state *new_state);
82
83 static void gpio_fsm_set_soft(struct gpio_fsm *gf,
84 - unsigned int off, int val)
85 -{
86 - struct soft_gpio *sg = &gf->soft_gpios[off];
87 - struct gpio_event *gp_ev;
88 - struct fsm_state *state;
89 - int i;
90 -
91 - dev_dbg(gf->dev, "set(%d,%d)\n", off, val);
92 - state = gf->current_state;
93 - sg->value = val;
94 - for (i = 0; i < state->num_soft_events; i++) {
95 - gp_ev = &state->soft_events[i];
96 - if (gp_ev->index == off && gp_ev->value == val) {
97 - if (gf->debug)
98 - dev_info(gf->dev,
99 - "GF_SOFT %d->%d -> %s\n", gp_ev->index,
100 - gp_ev->value, gp_ev->target->name);
101 - gpio_fsm_go_to_state(gf, gp_ev->target);
102 - break;
103 - }
104 - }
105 -}
106 -
107 -static int gpio_fsm_direction_input(struct gpio_chip *gc, unsigned int off)
108 -{
109 - struct gpio_fsm *gf = gpiochip_get_data(gc);
110 - struct soft_gpio *sg;
111 -
112 - if (off >= gf->num_soft_gpios)
113 - return -EINVAL;
114 - sg = &gf->soft_gpios[off];
115 - sg->dir = GPIOF_DIR_IN;
116 -
117 - return 0;
118 -}
119 -
120 -static int gpio_fsm_direction_output(struct gpio_chip *gc, unsigned int off,
121 - int value)
122 -{
123 - struct gpio_fsm *gf = gpiochip_get_data(gc);
124 - struct soft_gpio *sg;
125 -
126 - if (off >= gf->num_soft_gpios)
127 - return -EINVAL;
128 - sg = &gf->soft_gpios[off];
129 - sg->dir = GPIOF_DIR_OUT;
130 - gpio_fsm_set_soft(gf, off, value);
131 -
132 - return 0;
133 -}
134 -
135 -static void gpio_fsm_set(struct gpio_chip *gc, unsigned int off, int val)
136 -{
137 - struct gpio_fsm *gf;
138 -
139 - gf = gpiochip_get_data(gc);
140 - if (off < gf->num_soft_gpios)
141 - gpio_fsm_set_soft(gf, off, val);
142 -}
143 + unsigned int off, int val);
144
145 static void gpio_fsm_enter_state(struct gpio_fsm *gf,
146 - struct fsm_state *state)
147 + struct fsm_state *state)
148 {
149 struct input_gpio_state *inp_state;
150 struct output_signal *signal;
151 @@ -431,6 +314,44 @@ static void gpio_fsm_enter_state(struct
152 }
153 }
154
155 +static void gpio_fsm_go_to_state(struct gpio_fsm *gf,
156 + struct fsm_state *new_state)
157 +{
158 + struct input_gpio_state *inp_state;
159 + struct gpio_event *gp_ev;
160 + struct fsm_state *state;
161 + int i;
162 +
163 + dev_dbg(gf->dev, "go_to_state(%s)\n",
164 + new_state ? new_state->name : "<unset>");
165 +
166 + spin_lock(&gf->spinlock);
167 +
168 + if (gf->next_state) {
169 + /* Something else has already requested a transition */
170 + spin_unlock(&gf->spinlock);
171 + return;
172 + }
173 +
174 + gf->next_state = new_state;
175 + state = gf->current_state;
176 + gf->delay_target_state = NULL;
177 +
178 + if (state) {
179 + /* Disarm any GPIO IRQs */
180 + for (i = 0; i < state->num_gpio_events; i++) {
181 + gp_ev = &state->gpio_events[i];
182 + inp_state = &gf->input_gpio_states[gp_ev->index];
183 + inp_state->target = NULL;
184 + }
185 + }
186 +
187 + spin_unlock(&gf->spinlock);
188 +
189 + if (new_state)
190 + schedule_work(&gf->work);
191 +}
192 +
193 static void gpio_fsm_work(struct work_struct *work)
194 {
195 struct input_gpio_state *inp_state;
196 @@ -851,6 +772,90 @@ static int resolve_sym_to_state(struct g
197 return 0;
198 }
199
200 +static void gpio_fsm_set_soft(struct gpio_fsm *gf,
201 + unsigned int off, int val)
202 +{
203 + struct soft_gpio *sg = &gf->soft_gpios[off];
204 + struct gpio_event *gp_ev;
205 + struct fsm_state *state;
206 + int i;
207 +
208 + dev_dbg(gf->dev, "set(%d,%d)\n", off, val);
209 + state = gf->current_state;
210 + sg->value = val;
211 + for (i = 0; i < state->num_soft_events; i++) {
212 + gp_ev = &state->soft_events[i];
213 + if (gp_ev->index == off && gp_ev->value == val) {
214 + if (gf->debug)
215 + dev_info(gf->dev,
216 + "GF_SOFT %d->%d -> %s\n", gp_ev->index,
217 + gp_ev->value, gp_ev->target->name);
218 + gpio_fsm_go_to_state(gf, gp_ev->target);
219 + break;
220 + }
221 + }
222 +}
223 +
224 +static int gpio_fsm_get(struct gpio_chip *gc, unsigned int off)
225 +{
226 + struct gpio_fsm *gf = gpiochip_get_data(gc);
227 + struct soft_gpio *sg;
228 +
229 + if (off >= gf->num_soft_gpios)
230 + return -EINVAL;
231 + sg = &gf->soft_gpios[off];
232 +
233 + return sg->value;
234 +}
235 +
236 +static void gpio_fsm_set(struct gpio_chip *gc, unsigned int off, int val)
237 +{
238 + struct gpio_fsm *gf;
239 +
240 + gf = gpiochip_get_data(gc);
241 + if (off < gf->num_soft_gpios)
242 + gpio_fsm_set_soft(gf, off, val);
243 +}
244 +
245 +static int gpio_fsm_get_direction(struct gpio_chip *gc, unsigned int off)
246 +{
247 + struct gpio_fsm *gf = gpiochip_get_data(gc);
248 + struct soft_gpio *sg;
249 +
250 + if (off >= gf->num_soft_gpios)
251 + return -EINVAL;
252 + sg = &gf->soft_gpios[off];
253 +
254 + return sg->dir;
255 +}
256 +
257 +static int gpio_fsm_direction_input(struct gpio_chip *gc, unsigned int off)
258 +{
259 + struct gpio_fsm *gf = gpiochip_get_data(gc);
260 + struct soft_gpio *sg;
261 +
262 + if (off >= gf->num_soft_gpios)
263 + return -EINVAL;
264 + sg = &gf->soft_gpios[off];
265 + sg->dir = GPIOF_DIR_IN;
266 +
267 + return 0;
268 +}
269 +
270 +static int gpio_fsm_direction_output(struct gpio_chip *gc, unsigned int off,
271 + int value)
272 +{
273 + struct gpio_fsm *gf = gpiochip_get_data(gc);
274 + struct soft_gpio *sg;
275 +
276 + if (off >= gf->num_soft_gpios)
277 + return -EINVAL;
278 + sg = &gf->soft_gpios[off];
279 + sg->dir = GPIOF_DIR_OUT;
280 + gpio_fsm_set_soft(gf, off, value);
281 +
282 + return 0;
283 +}
284
285 /*
286 * /sys/class/gpio-fsm/<fsm-name>/