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
6 Move some functions into a more logical ordering. This change causes
7 no functional change and is essentially cosmetic.
9 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
11 drivers/gpio/gpio-fsm.c | 245 ++++++++++++++++++++--------------------
12 1 file changed, 125 insertions(+), 120 deletions(-)
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
20 -static int gpio_fsm_get_direction(struct gpio_chip *gc, unsigned int off)
22 - struct gpio_fsm *gf = gpiochip_get_data(gc);
23 - struct soft_gpio *sg;
25 - if (off >= gf->num_soft_gpios)
27 - sg = &gf->soft_gpios[off];
32 -static int gpio_fsm_get(struct gpio_chip *gc, unsigned int off)
34 - struct gpio_fsm *gf = gpiochip_get_data(gc);
35 - struct soft_gpio *sg;
37 - if (off >= gf->num_soft_gpios)
39 - sg = &gf->soft_gpios[off];
44 static void gpio_fsm_go_to_state(struct gpio_fsm *gf,
45 - struct fsm_state *new_state)
47 - struct input_gpio_state *inp_state;
48 - struct gpio_event *gp_ev;
49 - struct fsm_state *state;
52 - dev_dbg(gf->dev, "go_to_state(%s)\n",
53 - new_state ? new_state->name : "<unset>");
55 - spin_lock(&gf->spinlock);
57 - if (gf->next_state) {
58 - /* Something else has already requested a transition */
59 - spin_unlock(&gf->spinlock);
63 - gf->next_state = new_state;
64 - state = gf->current_state;
65 - gf->delay_target_state = NULL;
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;
76 - spin_unlock(&gf->spinlock);
79 - schedule_work(&gf->work);
81 + struct fsm_state *new_state);
83 static void gpio_fsm_set_soft(struct gpio_fsm *gf,
84 - unsigned int off, int val)
86 - struct soft_gpio *sg = &gf->soft_gpios[off];
87 - struct gpio_event *gp_ev;
88 - struct fsm_state *state;
91 - dev_dbg(gf->dev, "set(%d,%d)\n", off, val);
92 - state = gf->current_state;
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) {
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);
107 -static int gpio_fsm_direction_input(struct gpio_chip *gc, unsigned int off)
109 - struct gpio_fsm *gf = gpiochip_get_data(gc);
110 - struct soft_gpio *sg;
112 - if (off >= gf->num_soft_gpios)
114 - sg = &gf->soft_gpios[off];
115 - sg->dir = GPIOF_DIR_IN;
120 -static int gpio_fsm_direction_output(struct gpio_chip *gc, unsigned int off,
123 - struct gpio_fsm *gf = gpiochip_get_data(gc);
124 - struct soft_gpio *sg;
126 - if (off >= gf->num_soft_gpios)
128 - sg = &gf->soft_gpios[off];
129 - sg->dir = GPIOF_DIR_OUT;
130 - gpio_fsm_set_soft(gf, off, value);
135 -static void gpio_fsm_set(struct gpio_chip *gc, unsigned int off, int val)
137 - struct gpio_fsm *gf;
139 - gf = gpiochip_get_data(gc);
140 - if (off < gf->num_soft_gpios)
141 - gpio_fsm_set_soft(gf, off, val);
143 + unsigned int off, int val);
145 static void gpio_fsm_enter_state(struct gpio_fsm *gf,
146 - struct fsm_state *state)
147 + struct fsm_state *state)
149 struct input_gpio_state *inp_state;
150 struct output_signal *signal;
151 @@ -431,6 +314,44 @@ static void gpio_fsm_enter_state(struct
155 +static void gpio_fsm_go_to_state(struct gpio_fsm *gf,
156 + struct fsm_state *new_state)
158 + struct input_gpio_state *inp_state;
159 + struct gpio_event *gp_ev;
160 + struct fsm_state *state;
163 + dev_dbg(gf->dev, "go_to_state(%s)\n",
164 + new_state ? new_state->name : "<unset>");
166 + spin_lock(&gf->spinlock);
168 + if (gf->next_state) {
169 + /* Something else has already requested a transition */
170 + spin_unlock(&gf->spinlock);
174 + gf->next_state = new_state;
175 + state = gf->current_state;
176 + gf->delay_target_state = NULL;
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;
187 + spin_unlock(&gf->spinlock);
190 + schedule_work(&gf->work);
193 static void gpio_fsm_work(struct work_struct *work)
195 struct input_gpio_state *inp_state;
196 @@ -851,6 +772,90 @@ static int resolve_sym_to_state(struct g
200 +static void gpio_fsm_set_soft(struct gpio_fsm *gf,
201 + unsigned int off, int val)
203 + struct soft_gpio *sg = &gf->soft_gpios[off];
204 + struct gpio_event *gp_ev;
205 + struct fsm_state *state;
208 + dev_dbg(gf->dev, "set(%d,%d)\n", off, val);
209 + state = gf->current_state;
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) {
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);
224 +static int gpio_fsm_get(struct gpio_chip *gc, unsigned int off)
226 + struct gpio_fsm *gf = gpiochip_get_data(gc);
227 + struct soft_gpio *sg;
229 + if (off >= gf->num_soft_gpios)
231 + sg = &gf->soft_gpios[off];
236 +static void gpio_fsm_set(struct gpio_chip *gc, unsigned int off, int val)
238 + struct gpio_fsm *gf;
240 + gf = gpiochip_get_data(gc);
241 + if (off < gf->num_soft_gpios)
242 + gpio_fsm_set_soft(gf, off, val);
245 +static int gpio_fsm_get_direction(struct gpio_chip *gc, unsigned int off)
247 + struct gpio_fsm *gf = gpiochip_get_data(gc);
248 + struct soft_gpio *sg;
250 + if (off >= gf->num_soft_gpios)
252 + sg = &gf->soft_gpios[off];
257 +static int gpio_fsm_direction_input(struct gpio_chip *gc, unsigned int off)
259 + struct gpio_fsm *gf = gpiochip_get_data(gc);
260 + struct soft_gpio *sg;
262 + if (off >= gf->num_soft_gpios)
264 + sg = &gf->soft_gpios[off];
265 + sg->dir = GPIOF_DIR_IN;
270 +static int gpio_fsm_direction_output(struct gpio_chip *gc, unsigned int off,
273 + struct gpio_fsm *gf = gpiochip_get_data(gc);
274 + struct soft_gpio *sg;
276 + if (off >= gf->num_soft_gpios)
278 + sg = &gf->soft_gpios[off];
279 + sg->dir = GPIOF_DIR_OUT;
280 + gpio_fsm_set_soft(gf, off, value);
286 * /sys/class/gpio-fsm/<fsm-name>/