2 * Public header for the MPC52xx processor BestComm driver
5 * Copyright (C) 2006 Sylvain Munaut <tnt@246tNt.com>
6 * Copyright (C) 2005 Varma Electronics Oy,
7 * ( by Andrey Volkov <avolkov@varma-el.com> )
8 * Copyright (C) 2003-2004 MontaVista, Software, Inc.
9 * ( by Dale Farnsworth <dfarnsworth@mvista.com> )
11 * This file is licensed under the terms of the GNU General Public License
12 * version 2. This program is licensed "as is" without any warranty of any
13 * kind, whether express or implied.
16 #ifndef __BESTCOMM_H__
17 #define __BESTCOMM_H__
19 struct bcom_bd
; /* defined later on ... */
22 /* ======================================================================== */
23 /* Generic task managment */
24 /* ======================================================================== */
27 * struct bcom_task - Structure describing a loaded BestComm task
29 * This structure is never built by the driver it self. It's built and
30 * filled the intermediate layer of the BestComm API, the task dependent
33 * Most likely you don't need to poke around inside this structure. The
34 * fields are exposed in the header just for the sake of inline functions
45 unsigned short outdex
;
52 #define BCOM_FLAGS_NONE 0x00000000ul
53 #define BCOM_FLAGS_ENABLE_TASK (1ul << 0)
56 * bcom_enable - Enable a BestComm task
57 * @tsk: The BestComm task structure
59 * This function makes sure the given task is enabled and can be run
60 * by the BestComm engine as needed
62 extern void bcom_enable(struct bcom_task
*tsk
);
65 * bcom_disable - Disable a BestComm task
66 * @tsk: The BestComm task structure
68 * This function disable a given task, making sure it's not executed
69 * by the BestComm engine.
71 extern void bcom_disable(struct bcom_task
*tsk
);
75 * bcom_get_task_irq - Returns the irq number of a BestComm task
76 * @tsk: The BestComm task structure
79 bcom_get_task_irq(struct bcom_task
*tsk
) {
83 /* ======================================================================== */
84 /* BD based tasks helpers */
85 /* ======================================================================== */
88 * struct bcom_bd - Structure describing a generic BestComm buffer descriptor
89 * @status: The current status of this buffer. Exact meaning depends on the
91 * @data: An array of u32 whose meaning depends on the task type.
95 u32 data
[1]; /* variable, but at least 1 */
98 #define BCOM_BD_READY 0x40000000ul
100 /** _bcom_next_index - Get next input index.
101 * @tsk: pointer to task structure
103 * Support function; Device drivers should not call this
106 _bcom_next_index(struct bcom_task
*tsk
)
108 return ((tsk
->index
+ 1) == tsk
->num_bd
) ? 0 : tsk
->index
+ 1;
111 /** _bcom_next_outdex - Get next output index.
112 * @tsk: pointer to task structure
114 * Support function; Device drivers should not call this
117 _bcom_next_outdex(struct bcom_task
*tsk
)
119 return ((tsk
->outdex
+ 1) == tsk
->num_bd
) ? 0 : tsk
->outdex
+ 1;
123 * bcom_queue_empty - Checks if a BestComm task BD queue is empty
124 * @tsk: The BestComm task structure
127 bcom_queue_empty(struct bcom_task
*tsk
)
129 return tsk
->index
== tsk
->outdex
;
133 * bcom_queue_full - Checks if a BestComm task BD queue is full
134 * @tsk: The BestComm task structure
137 bcom_queue_full(struct bcom_task
*tsk
)
139 return tsk
->outdex
== _bcom_next_index(tsk
);
143 * bcom_buffer_done - Checks if a BestComm
144 * @tsk: The BestComm task structure
147 bcom_buffer_done(struct bcom_task
*tsk
)
149 if (bcom_queue_empty(tsk
))
151 return !(tsk
->bd
[tsk
->outdex
].status
& BCOM_BD_READY
);
155 * bcom_prepare_next_buffer - clear status of next available buffer.
156 * @tsk: The BestComm task structure
158 * Returns pointer to next buffer descriptor
160 static inline struct bcom_bd
*
161 bcom_prepare_next_buffer(struct bcom_task
*tsk
)
163 tsk
->bd
[tsk
->index
].status
= 0; /* cleanup last status */
164 return &tsk
->bd
[tsk
->index
];
168 bcom_submit_next_buffer(struct bcom_task
*tsk
, void *cookie
)
170 tsk
->cookie
[tsk
->index
] = cookie
;
171 mb(); /* ensure the bd is really up-to-date */
172 tsk
->bd
[tsk
->index
].status
|= BCOM_BD_READY
;
173 tsk
->index
= _bcom_next_index(tsk
);
174 if (tsk
->flags
& BCOM_FLAGS_ENABLE_TASK
)
179 bcom_retrieve_buffer(struct bcom_task
*tsk
, u32
*p_status
, struct bcom_bd
**p_bd
)
181 void *cookie
= tsk
->cookie
[tsk
->outdex
];
183 *p_status
= tsk
->bd
[tsk
->outdex
].status
;
185 *p_bd
= &tsk
->bd
[tsk
->outdex
];
186 tsk
->outdex
= _bcom_next_outdex(tsk
);
190 #endif /* __BESTCOMM_H__ */