Cliff Cai | 8c9c198 | 2008-09-05 18:21:35 +0800 | [diff] [blame] | 1 | /* |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 2 | * File: bf5xx_sport.h |
Cliff Cai | 8c9c198 | 2008-09-05 18:21:35 +0800 | [diff] [blame] | 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> |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 36 | #include <linux/platform_device.h> |
Cliff Cai | 8c9c198 | 2008-09-05 18:21:35 +0800 | [diff] [blame] | 37 | #include <asm/dma.h> |
Barry Song | f0d10f5 | 2010-03-09 12:58:14 -0500 | [diff] [blame] | 38 | #include <asm/bfin_sport.h> |
Cliff Cai | 8c9c198 | 2008-09-05 18:21:35 +0800 | [diff] [blame] | 39 | |
| 40 | #define DESC_ELEMENT_COUNT 9 |
| 41 | |
| 42 | struct sport_device { |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 43 | int num; |
Cliff Cai | 8c9c198 | 2008-09-05 18:21:35 +0800 | [diff] [blame] | 44 | int dma_rx_chan; |
| 45 | int dma_tx_chan; |
| 46 | int err_irq; |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 47 | const unsigned short *pin_req; |
Cliff Cai | 8c9c198 | 2008-09-05 18:21:35 +0800 | [diff] [blame] | 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; |
Cliff Cai | 67f854b | 2008-11-18 16:18:17 +0800 | [diff] [blame] | 96 | #ifdef CONFIG_SND_BF5XX_MMAP_SUPPORT |
Cliff Cai | 8c9c198 | 2008-09-05 18:21:35 +0800 | [diff] [blame] | 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; |
Cliff Cai | 6b58a82 | 2008-09-27 22:32:20 +0800 | [diff] [blame] | 103 | int tx_delay_pos; |
| 104 | int once; |
Cliff Cai | 8c9c198 | 2008-09-05 18:21:35 +0800 | [diff] [blame] | 105 | #endif |
| 106 | void *private_data; |
| 107 | }; |
| 108 | |
Cliff Cai | 8c9c198 | 2008-09-05 18:21:35 +0800 | [diff] [blame] | 109 | struct sport_param { |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 110 | int num; |
Cliff Cai | 8c9c198 | 2008-09-05 18:21:35 +0800 | [diff] [blame] | 111 | int dma_rx_chan; |
| 112 | int dma_tx_chan; |
| 113 | int err_irq; |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 114 | const unsigned short *pin_req; |
Cliff Cai | 8c9c198 | 2008-09-05 18:21:35 +0800 | [diff] [blame] | 115 | struct sport_register *regs; |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 116 | unsigned int wdsize; |
| 117 | unsigned int dummy_count; |
| 118 | void *private_data; |
Cliff Cai | 8c9c198 | 2008-09-05 18:21:35 +0800 | [diff] [blame] | 119 | }; |
| 120 | |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 121 | struct sport_device *sport_init(struct platform_device *pdev, |
| 122 | unsigned int wdsize, unsigned int dummy_count, size_t priv_size); |
Cliff Cai | 8c9c198 | 2008-09-05 18:21:35 +0800 | [diff] [blame] | 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 */ |