1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2021 Broadcom. All Rights Reserved. The term
4 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
8 * Generic state machine framework.
14 * efc_sm_post_event() - Post an event to a context.
16 * @ctx: State machine context
18 * @data: Event-specific data (if any)
21 efc_sm_post_event(struct efc_sm_ctx *ctx,
22 enum efc_sm_event evt, void *data)
24 if (!ctx->current_state)
27 ctx->current_state(ctx, evt, data);
32 efc_sm_transition(struct efc_sm_ctx *ctx,
33 void (*state)(struct efc_sm_ctx *,
34 enum efc_sm_event, void *), void *data)
37 if (ctx->current_state == state) {
38 efc_sm_post_event(ctx, EFC_EVT_REENTER, data);
40 efc_sm_post_event(ctx, EFC_EVT_EXIT, data);
41 ctx->current_state = state;
42 efc_sm_post_event(ctx, EFC_EVT_ENTER, data);
46 static char *event_name[] = EFC_SM_EVENT_NAME;
48 const char *efc_sm_event_name(enum efc_sm_event evt)
50 if (evt > EFC_EVT_LAST)
53 return event_name[evt];