2 * This file is part of OMAP DSP driver (DSP Gateway version 3.3.1)
4 * Copyright (C) 2002-2006 Nokia Corporation. All rights reserved.
6 * Contact: Toshihiro Kobayashi <toshihiro.kobayashi@nokia.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 #ifndef __PLAT_OMAP_DSP_FIFO_H
25 #define __PLAT_OMAP_DSP_FIFO_H
35 static inline int alloc_fifo(struct fifo_struct *fifo, size_t sz)
37 if ((fifo->buf = kmalloc(sz, GFP_KERNEL)) == NULL) {
47 static inline int init_fifo(struct fifo_struct *fifo, size_t sz)
49 spin_lock_init(&fifo->lock);
50 return alloc_fifo(fifo, sz);
53 static inline void free_fifo(struct fifo_struct *fifo)
55 spin_lock(&fifo->lock);
56 if (fifo->buf == NULL) {
57 spin_unlock(&fifo->lock);
64 spin_unlock(&fifo->lock);
67 static inline void flush_fifo(struct fifo_struct *fifo)
69 spin_lock(&fifo->lock);
72 spin_unlock(&fifo->lock);
75 #define fifo_empty(fifo) ((fifo)->cnt == 0)
77 static inline int realloc_fifo(struct fifo_struct *fifo, size_t sz)
81 spin_lock(&fifo->lock);
82 if (!fifo_empty(fifo)) {
92 ret = alloc_fifo(fifo, sz);
95 spin_unlock(&fifo->lock);
99 static inline void write_word_to_fifo(struct fifo_struct *fifo, u16 word)
101 spin_lock(&fifo->lock);
102 *(u16 *)&fifo->buf[fifo->wp] = word;
103 if ((fifo->wp += 2) == fifo->sz)
105 if ((fifo->cnt += 2) > fifo->sz)
106 fifo->cnt = fifo->sz;
107 spin_unlock(&fifo->lock);
113 * [*******----------*************]
115 * <----------------------------> sz = 30
116 * <-----> <-----------> cnt = 20
119 * <-> <-----------> count = 16
120 * <-----------> cnt1 = 13
124 * [---****-----------------------]
127 static inline ssize_t copy_to_user_fm_fifo(char *dst, struct fifo_struct *fifo,
133 /* fifo size can be zero */
137 spin_lock(&fifo->lock);
138 if (count > fifo->cnt)
141 if ((rp = fifo->wp - fifo->cnt) >= 0) {
142 /* valid area is straight */
143 if (copy_to_user(dst, &fifo->buf[rp], count)) {
151 /* requested area is straight */
152 if (copy_to_user(dst, &fifo->buf[rp], count)) {
157 if (copy_to_user(dst, &fifo->buf[rp], cnt1)) {
161 if (copy_to_user(dst+cnt1, fifo->buf, count-cnt1)) {
171 spin_unlock(&fifo->lock);
175 #endif /* __PLAT_OMAP_DSP_FIFO_H */