1 #include <minix/audio_fw.h>
3 /* State management variables. */
4 EXTERN
int is_status_msg_expected
;
8 * EXTERN sub_dev_t sub_dev[];
11 /* State management helpers */
12 static int is_read_pending
;
13 static int is_write_pending
;
14 static void load_state_info(void)
16 int i
, dma_mode
, found_pending
;
18 /* Check if reads or writes are pending. */
19 is_read_pending
= FALSE
;
20 is_write_pending
= FALSE
;
21 found_pending
= FALSE
;
22 for (i
= 0; i
< drv
.NrOfSubDevices
&& !found_pending
; i
++) {
23 if(sub_dev
[i
].RevivePending
) {
24 dma_mode
= sub_dev
[i
].DmaMode
;
26 if(dma_mode
== DEV_READ_S
) {
27 is_read_pending
= TRUE
;
29 else if (dma_mode
== DEV_WRITE_S
){
30 is_write_pending
= TRUE
;
34 found_pending
= (is_read_pending
&& is_write_pending
);
38 /* Custom states definition. */
39 #define AUDIO_STATE_READ_REQUEST_FREE (SEF_LU_STATE_CUSTOM_BASE + 0)
40 #define AUDIO_STATE_WRITE_REQUEST_FREE (SEF_LU_STATE_CUSTOM_BASE + 1)
41 #define AUDIO_STATE_IS_CUSTOM(s) \
42 ((s) >= AUDIO_STATE_READ_REQUEST_FREE && (s) <=AUDIO_STATE_WRITE_REQUEST_FREE)
44 /*===========================================================================*
46 *===========================================================================*/
47 int sef_cb_lu_prepare(int state
)
51 /* Load state information. */
54 /* Check if we are ready for the target state. */
57 /* Standard states. */
58 case SEF_LU_STATE_REQUEST_FREE
:
59 is_ready
= (!is_read_pending
&& !is_write_pending
);
62 case SEF_LU_STATE_PROTOCOL_FREE
:
63 is_ready
= (!is_read_pending
&& !is_write_pending
64 && !is_status_msg_expected
);
68 case AUDIO_STATE_READ_REQUEST_FREE
:
69 is_ready
= (!is_read_pending
);
72 case AUDIO_STATE_WRITE_REQUEST_FREE
:
73 is_ready
= (!is_write_pending
);
77 /* Tell SEF if we are ready. */
78 return is_ready
? OK
: ENOTREADY
;
81 /*===========================================================================*
82 * sef_cb_lu_state_isvalid *
83 *===========================================================================*/
84 int sef_cb_lu_state_isvalid(int state
)
86 return SEF_LU_STATE_IS_STANDARD(state
) || AUDIO_STATE_IS_CUSTOM(state
);
89 /*===========================================================================*
90 * sef_cb_lu_state_dump *
91 *===========================================================================*/
92 void sef_cb_lu_state_dump(int state
)
94 /* Load state information. */
97 sef_lu_dprint("audio: live update state = %d\n", state
);
98 sef_lu_dprint("audio: is_status_msg_expected = %d\n",
99 is_status_msg_expected
);
100 sef_lu_dprint("audio: is_read_pending = %d\n", is_read_pending
);
101 sef_lu_dprint("audio: is_write_pending = %d\n", is_write_pending
);
103 sef_lu_dprint("audio: SEF_LU_STATE_WORK_FREE(%d) reached = %d\n",
104 SEF_LU_STATE_WORK_FREE
, TRUE
);
105 sef_lu_dprint("audio: SEF_LU_STATE_REQUEST_FREE(%d) reached = %d\n",
106 SEF_LU_STATE_REQUEST_FREE
, (!is_read_pending
&& !is_write_pending
));
107 sef_lu_dprint("audio: SEF_LU_STATE_PROTOCOL_FREE(%d) reached = %d\n",
108 SEF_LU_STATE_PROTOCOL_FREE
, (!is_read_pending
&& !is_write_pending
109 && !is_status_msg_expected
));
110 sef_lu_dprint("audio: AUDIO_STATE_READ_REQUEST_FREE(%d) reached = %d\n",
111 AUDIO_STATE_READ_REQUEST_FREE
, (!is_read_pending
));
112 sef_lu_dprint("audio: AUDIO_STATE_WRITE_REQUEST_FREE(%d) reached = %d\n",
113 AUDIO_STATE_WRITE_REQUEST_FREE
, (!is_write_pending
));