blob: 4c163454bbf8410570e2f8e43cf06da224cae66e [file] [log] [blame]
Cliff Cai8c9c1982008-09-05 18:21:35 +08001/*
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
38struct sport_register {
39 u16 tcr1; u16 reserved0;
40 u16 tcr2; u16 reserved1;
41 u16 tclkdiv; u16 reserved2;
42 u16 tfsdiv; u16 reserved3;
43 u32 tx;
44 u32 reserved_l0;
45 u32 rx;
46 u32 reserved_l1;
47 u16 rcr1; u16 reserved4;
48 u16 rcr2; u16 reserved5;
49 u16 rclkdiv; u16 reserved6;
50 u16 rfsdiv; u16 reserved7;
51 u16 stat; u16 reserved8;
52 u16 chnl; u16 reserved9;
53 u16 mcmc1; u16 reserved10;
54 u16 mcmc2; u16 reserved11;
55 u32 mtcs0;
56 u32 mtcs1;
57 u32 mtcs2;
58 u32 mtcs3;
59 u32 mrcs0;
60 u32 mrcs1;
61 u32 mrcs2;
62 u32 mrcs3;
63};
64
65#define DESC_ELEMENT_COUNT 9
66
67struct sport_device {
68 int dma_rx_chan;
69 int dma_tx_chan;
70 int err_irq;
71 struct sport_register *regs;
72
73 unsigned char *rx_buf;
74 unsigned char *tx_buf;
75 unsigned int rx_fragsize;
76 unsigned int tx_fragsize;
77 unsigned int rx_frags;
78 unsigned int tx_frags;
79 unsigned int wdsize;
80
81 /* for dummy dma transfer */
82 void *dummy_buf;
83 unsigned int dummy_count;
84
85 /* DMA descriptor ring head of current audio stream*/
86 struct dmasg *dma_rx_desc;
87 struct dmasg *dma_tx_desc;
88 unsigned int rx_desc_bytes;
89 unsigned int tx_desc_bytes;
90
91 unsigned int rx_run:1; /* rx is running */
92 unsigned int tx_run:1; /* tx is running */
93
94 struct dmasg *dummy_rx_desc;
95 struct dmasg *dummy_tx_desc;
96
97 struct dmasg *curr_rx_desc;
98 struct dmasg *curr_tx_desc;
99
100 int rx_curr_frag;
101 int tx_curr_frag;
102
103 unsigned int rcr1;
104 unsigned int rcr2;
105 int rx_tdm_count;
106
107 unsigned int tcr1;
108 unsigned int tcr2;
109 int tx_tdm_count;
110
111 void (*rx_callback)(void *data);
112 void *rx_data;
113 void (*tx_callback)(void *data);
114 void *tx_data;
115 void (*err_callback)(void *data);
116 void *err_data;
117 unsigned char *tx_dma_buf;
118 unsigned char *rx_dma_buf;
119#ifdef CONFIG_SND_MMAP_SUPPORT
120 dma_addr_t tx_dma_phy;
121 dma_addr_t rx_dma_phy;
122 int tx_pos;/*pcm sample count*/
123 int rx_pos;
124 unsigned int tx_buffer_size;
125 unsigned int rx_buffer_size;
126#endif
127 void *private_data;
128};
129
130extern struct sport_device *sport_handle;
131
132struct sport_param {
133 int dma_rx_chan;
134 int dma_tx_chan;
135 int err_irq;
136 struct sport_register *regs;
137};
138
139struct sport_device *sport_init(struct sport_param *param, unsigned wdsize,
140 unsigned dummy_count, void *private_data);
141
142void sport_done(struct sport_device *sport);
143
144/* first use these ...*/
145
146/* note: multichannel is in units of 8 channels, tdm_count is number of channels
147 * NOT / 8 ! all channels are enabled by default */
148int sport_set_multichannel(struct sport_device *sport, int tdm_count,
149 u32 mask, int packed);
150
151int sport_config_rx(struct sport_device *sport,
152 unsigned int rcr1, unsigned int rcr2,
153 unsigned int clkdiv, unsigned int fsdiv);
154
155int sport_config_tx(struct sport_device *sport,
156 unsigned int tcr1, unsigned int tcr2,
157 unsigned int clkdiv, unsigned int fsdiv);
158
159/* ... then these: */
160
161/* buffer size (in bytes) == fragcount * fragsize_bytes */
162
163/* this is not a very general api, it sets the dma to 2d autobuffer mode */
164
165int sport_config_rx_dma(struct sport_device *sport, void *buf,
166 int fragcount, size_t fragsize_bytes);
167
168int sport_config_tx_dma(struct sport_device *sport, void *buf,
169 int fragcount, size_t fragsize_bytes);
170
171int sport_tx_start(struct sport_device *sport);
172int sport_tx_stop(struct sport_device *sport);
173int sport_rx_start(struct sport_device *sport);
174int sport_rx_stop(struct sport_device *sport);
175
176/* for use in interrupt handler */
177unsigned long sport_curr_offset_rx(struct sport_device *sport);
178unsigned long sport_curr_offset_tx(struct sport_device *sport);
179
180void sport_incfrag(struct sport_device *sport, int *frag, int tx);
181void sport_decfrag(struct sport_device *sport, int *frag, int tx);
182
183int sport_set_rx_callback(struct sport_device *sport,
184 void (*rx_callback)(void *), void *rx_data);
185int sport_set_tx_callback(struct sport_device *sport,
186 void (*tx_callback)(void *), void *tx_data);
187int sport_set_err_callback(struct sport_device *sport,
188 void (*err_callback)(void *), void *err_data);
189
190int sport_send_and_recv(struct sport_device *sport, u8 *out_data, \
191 u8 *in_data, int len);
192#endif /* BF53X_SPORT_H */