atmel_serial: fix bugs in probe() error path and remove()
[pv_ops_mirror.git] / arch / powerpc / sysdev / bestcomm / bestcomm.h
blobc960a8b4965538a78d92bf7c2469f9f4ffed591d
1 /*
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 management */
24 /* ======================================================================== */
26 /**
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
31 * support code.
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
36 struct bcom_task {
37 unsigned int tasknum;
38 unsigned int flags;
39 int irq;
41 struct bcom_bd *bd;
42 phys_addr_t bd_pa;
43 void **cookie;
44 unsigned short index;
45 unsigned short outdex;
46 unsigned int num_bd;
47 unsigned int bd_size;
49 void* priv;
52 #define BCOM_FLAGS_NONE 0x00000000ul
53 #define BCOM_FLAGS_ENABLE_TASK (1ul << 0)
55 /**
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);
64 /**
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);
74 /**
75 * bcom_get_task_irq - Returns the irq number of a BestComm task
76 * @tsk: The BestComm task structure
78 static inline int
79 bcom_get_task_irq(struct bcom_task *tsk) {
80 return tsk->irq;
83 /* ======================================================================== */
84 /* BD based tasks helpers */
85 /* ======================================================================== */
87 /**
88 * struct bcom_bd - Structure describing a generic BestComm buffer descriptor
89 * @status: The current status of this buffer. Exact meaning depends on the
90 * task type
91 * @data: An array of u32 whose meaning depends on the task type.
93 struct bcom_bd {
94 u32 status;
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
105 static inline int
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
116 static inline int
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
126 static inline int
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
136 static inline int
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
146 static inline int
147 bcom_buffer_done(struct bcom_task *tsk)
149 if (bcom_queue_empty(tsk))
150 return 0;
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];
167 static inline void
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)
175 bcom_enable(tsk);
178 static inline void *
179 bcom_retrieve_buffer(struct bcom_task *tsk, u32 *p_status, struct bcom_bd **p_bd)
181 void *cookie = tsk->cookie[tsk->outdex];
182 if (p_status)
183 *p_status = tsk->bd[tsk->outdex].status;
184 if (p_bd)
185 *p_bd = &tsk->bd[tsk->outdex];
186 tsk->outdex = _bcom_next_outdex(tsk);
187 return cookie;
190 #endif /* __BESTCOMM_H__ */