Commit | Line | Data |
---|---|---|
8c9c1983 | 1 | /* |
2c66cb99 | 2 | * File: bf5xx_sport.h |
8c9c1983 CC |
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> | |
2c66cb99 | 36 | #include <linux/platform_device.h> |
8c9c1983 | 37 | #include <asm/dma.h> |
f0d10f5a | 38 | #include <asm/bfin_sport.h> |
8c9c1983 CC |
39 | |
40 | #define DESC_ELEMENT_COUNT 9 | |
41 | ||
42 | struct sport_device { | |
2c66cb99 | 43 | int num; |
8c9c1983 CC |
44 | int dma_rx_chan; |
45 | int dma_tx_chan; | |
46 | int err_irq; | |
2c66cb99 | 47 | const unsigned short *pin_req; |
8c9c1983 CC |
48 | struct sport_register *regs; |
49 | ||
50 | unsigned char *rx_buf; | |
51 | unsigned char *tx_buf; | |
52 | unsigned int rx_fragsize; | |
53 | unsigned int tx_fragsize; | |
54 | unsigned int rx_frags; | |
55 | unsigned int tx_frags; | |
56 | unsigned int wdsize; | |
57 | ||
58 | /* for dummy dma transfer */ | |
59 | void *dummy_buf; | |
60 | unsigned int dummy_count; | |
61 | ||
62 | /* DMA descriptor ring head of current audio stream*/ | |
63 | struct dmasg *dma_rx_desc; | |
64 | struct dmasg *dma_tx_desc; | |
65 | unsigned int rx_desc_bytes; | |
66 | unsigned int tx_desc_bytes; | |
67 | ||
68 | unsigned int rx_run:1; /* rx is running */ | |
69 | unsigned int tx_run:1; /* tx is running */ | |
70 | ||
71 | struct dmasg *dummy_rx_desc; | |
72 | struct dmasg *dummy_tx_desc; | |
73 | ||
74 | struct dmasg *curr_rx_desc; | |
75 | struct dmasg *curr_tx_desc; | |
76 | ||
77 | int rx_curr_frag; | |
78 | int tx_curr_frag; | |
79 | ||
80 | unsigned int rcr1; | |
81 | unsigned int rcr2; | |
82 | int rx_tdm_count; | |
83 | ||
84 | unsigned int tcr1; | |
85 | unsigned int tcr2; | |
86 | int tx_tdm_count; | |
87 | ||
88 | void (*rx_callback)(void *data); | |
89 | void *rx_data; | |
90 | void (*tx_callback)(void *data); | |
91 | void *tx_data; | |
92 | void (*err_callback)(void *data); | |
93 | void *err_data; | |
94 | unsigned char *tx_dma_buf; | |
95 | unsigned char *rx_dma_buf; | |
67f854b9 | 96 | #ifdef CONFIG_SND_BF5XX_MMAP_SUPPORT |
8c9c1983 CC |
97 | dma_addr_t tx_dma_phy; |
98 | dma_addr_t rx_dma_phy; | |
99 | int tx_pos;/*pcm sample count*/ | |
100 | int rx_pos; | |
101 | unsigned int tx_buffer_size; | |
102 | unsigned int rx_buffer_size; | |
6b58a821 CC |
103 | int tx_delay_pos; |
104 | int once; | |
8c9c1983 CC |
105 | #endif |
106 | void *private_data; | |
107 | }; | |
108 | ||
8c9c1983 | 109 | struct sport_param { |
2c66cb99 | 110 | int num; |
8c9c1983 CC |
111 | int dma_rx_chan; |
112 | int dma_tx_chan; | |
113 | int err_irq; | |
2c66cb99 | 114 | const unsigned short *pin_req; |
8c9c1983 | 115 | struct sport_register *regs; |
2c66cb99 BS |
116 | unsigned int wdsize; |
117 | unsigned int dummy_count; | |
118 | void *private_data; | |
8c9c1983 CC |
119 | }; |
120 | ||
2c66cb99 BS |
121 | struct sport_device *sport_init(struct platform_device *pdev, |
122 | unsigned int wdsize, unsigned int dummy_count, size_t priv_size); | |
8c9c1983 CC |
123 | |
124 | void sport_done(struct sport_device *sport); | |
125 | ||
126 | /* first use these ...*/ | |
127 | ||
128 | /* note: multichannel is in units of 8 channels, tdm_count is number of channels | |
129 | * NOT / 8 ! all channels are enabled by default */ | |
130 | int sport_set_multichannel(struct sport_device *sport, int tdm_count, | |
131 | u32 mask, int packed); | |
132 | ||
133 | int sport_config_rx(struct sport_device *sport, | |
134 | unsigned int rcr1, unsigned int rcr2, | |
135 | unsigned int clkdiv, unsigned int fsdiv); | |
136 | ||
137 | int sport_config_tx(struct sport_device *sport, | |
138 | unsigned int tcr1, unsigned int tcr2, | |
139 | unsigned int clkdiv, unsigned int fsdiv); | |
140 | ||
141 | /* ... then these: */ | |
142 | ||
143 | /* buffer size (in bytes) == fragcount * fragsize_bytes */ | |
144 | ||
145 | /* this is not a very general api, it sets the dma to 2d autobuffer mode */ | |
146 | ||
147 | int sport_config_rx_dma(struct sport_device *sport, void *buf, | |
148 | int fragcount, size_t fragsize_bytes); | |
149 | ||
150 | int sport_config_tx_dma(struct sport_device *sport, void *buf, | |
151 | int fragcount, size_t fragsize_bytes); | |
152 | ||
153 | int sport_tx_start(struct sport_device *sport); | |
154 | int sport_tx_stop(struct sport_device *sport); | |
155 | int sport_rx_start(struct sport_device *sport); | |
156 | int sport_rx_stop(struct sport_device *sport); | |
157 | ||
158 | /* for use in interrupt handler */ | |
159 | unsigned long sport_curr_offset_rx(struct sport_device *sport); | |
160 | unsigned long sport_curr_offset_tx(struct sport_device *sport); | |
161 | ||
162 | void sport_incfrag(struct sport_device *sport, int *frag, int tx); | |
163 | void sport_decfrag(struct sport_device *sport, int *frag, int tx); | |
164 | ||
165 | int sport_set_rx_callback(struct sport_device *sport, | |
166 | void (*rx_callback)(void *), void *rx_data); | |
167 | int sport_set_tx_callback(struct sport_device *sport, | |
168 | void (*tx_callback)(void *), void *tx_data); | |
169 | int sport_set_err_callback(struct sport_device *sport, | |
170 | void (*err_callback)(void *), void *err_data); | |
171 | ||
172 | int sport_send_and_recv(struct sport_device *sport, u8 *out_data, \ | |
173 | u8 *in_data, int len); | |
174 | #endif /* BF53X_SPORT_H */ |