upload tizen1.0 source
[kernel/linux-2.6.36.git] / sound / soc / blackfin / bf5xx-sport.h
1 /*
2  * File:         bf5xx_ac97_sport.h
3  * Based on:
4  * Author:       Roy Huang <roy.huang@analog.com>
5  *
6  * Created:
7  * Description:
8  *
9  *               Copyright 2004-2007 Analog Devices Inc.
10  *
11  * Bugs:         Enter bugs at http://blackfin.uclinux.org/
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, see the file COPYING, or write
25  * to the Free Software Foundation, Inc.,
26  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
27  */
28
29
30 #ifndef __BF5XX_SPORT_H__
31 #define __BF5XX_SPORT_H__
32
33 #include <linux/types.h>
34 #include <linux/wait.h>
35 #include <linux/workqueue.h>
36 #include <asm/dma.h>
37 #include <asm/bfin_sport.h>
38
39 #define DESC_ELEMENT_COUNT 9
40
41 struct sport_device {
42         int dma_rx_chan;
43         int dma_tx_chan;
44         int err_irq;
45         struct sport_register *regs;
46
47         unsigned char *rx_buf;
48         unsigned char *tx_buf;
49         unsigned int rx_fragsize;
50         unsigned int tx_fragsize;
51         unsigned int rx_frags;
52         unsigned int tx_frags;
53         unsigned int wdsize;
54
55         /* for dummy dma transfer */
56         void *dummy_buf;
57         unsigned int dummy_count;
58
59         /* DMA descriptor ring head of current audio stream*/
60         struct dmasg *dma_rx_desc;
61         struct dmasg *dma_tx_desc;
62         unsigned int rx_desc_bytes;
63         unsigned int tx_desc_bytes;
64
65         unsigned int rx_run:1; /* rx is running */
66         unsigned int tx_run:1; /* tx is running */
67
68         struct dmasg *dummy_rx_desc;
69         struct dmasg *dummy_tx_desc;
70
71         struct dmasg *curr_rx_desc;
72         struct dmasg *curr_tx_desc;
73
74         int rx_curr_frag;
75         int tx_curr_frag;
76
77         unsigned int rcr1;
78         unsigned int rcr2;
79         int rx_tdm_count;
80
81         unsigned int tcr1;
82         unsigned int tcr2;
83         int tx_tdm_count;
84
85         void (*rx_callback)(void *data);
86         void *rx_data;
87         void (*tx_callback)(void *data);
88         void *tx_data;
89         void (*err_callback)(void *data);
90         void *err_data;
91         unsigned char *tx_dma_buf;
92         unsigned char *rx_dma_buf;
93 #ifdef CONFIG_SND_BF5XX_MMAP_SUPPORT
94         dma_addr_t tx_dma_phy;
95         dma_addr_t rx_dma_phy;
96         int tx_pos;/*pcm sample count*/
97         int rx_pos;
98         unsigned int tx_buffer_size;
99         unsigned int rx_buffer_size;
100         int tx_delay_pos;
101         int once;
102 #endif
103         void *private_data;
104 };
105
106 extern struct sport_device *sport_handle;
107
108 struct sport_param {
109         int dma_rx_chan;
110         int dma_tx_chan;
111         int err_irq;
112         struct sport_register *regs;
113 };
114
115 struct sport_device *sport_init(struct sport_param *param, unsigned wdsize,
116                 unsigned dummy_count, void *private_data);
117
118 void sport_done(struct sport_device *sport);
119
120 /* first use these ...*/
121
122 /* note: multichannel is in units of 8 channels, tdm_count is number of channels
123  *  NOT / 8 ! all channels are enabled by default */
124 int sport_set_multichannel(struct sport_device *sport, int tdm_count,
125                 u32 mask, int packed);
126
127 int sport_config_rx(struct sport_device *sport,
128                 unsigned int rcr1, unsigned int rcr2,
129                 unsigned int clkdiv, unsigned int fsdiv);
130
131 int sport_config_tx(struct sport_device *sport,
132                 unsigned int tcr1, unsigned int tcr2,
133                 unsigned int clkdiv, unsigned int fsdiv);
134
135 /* ... then these: */
136
137 /* buffer size (in bytes) == fragcount * fragsize_bytes */
138
139 /* this is not a very general api, it sets the dma to 2d autobuffer mode */
140
141 int sport_config_rx_dma(struct sport_device *sport, void *buf,
142                 int fragcount, size_t fragsize_bytes);
143
144 int sport_config_tx_dma(struct sport_device *sport, void *buf,
145                 int fragcount, size_t fragsize_bytes);
146
147 int sport_tx_start(struct sport_device *sport);
148 int sport_tx_stop(struct sport_device *sport);
149 int sport_rx_start(struct sport_device *sport);
150 int sport_rx_stop(struct sport_device *sport);
151
152 /* for use in interrupt handler */
153 unsigned long sport_curr_offset_rx(struct sport_device *sport);
154 unsigned long sport_curr_offset_tx(struct sport_device *sport);
155
156 void sport_incfrag(struct sport_device *sport, int *frag, int tx);
157 void sport_decfrag(struct sport_device *sport, int *frag, int tx);
158
159 int sport_set_rx_callback(struct sport_device *sport,
160                        void (*rx_callback)(void *), void *rx_data);
161 int sport_set_tx_callback(struct sport_device *sport,
162                        void (*tx_callback)(void *), void *tx_data);
163 int sport_set_err_callback(struct sport_device *sport,
164                        void (*err_callback)(void *), void *err_data);
165
166 int sport_send_and_recv(struct sport_device *sport, u8 *out_data, \
167                 u8 *in_data, int len);
168 #endif /* BF53X_SPORT_H */