]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/bcm2835-audio/bcm2835.h
staging: bcm2835-audio: initial staging submission
[karo-tx-linux.git] / drivers / staging / bcm2835-audio / bcm2835.h
1 /*****************************************************************************
2  * Copyright 2011 Broadcom Corporation.  All rights reserved.
3  *
4  * Unless you and Broadcom execute a separate written software license
5  * agreement governing use of this software, this software is licensed to you
6  * under the terms of the GNU General Public License version 2, available at
7  * http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
8  *
9  * Notwithstanding the above, under no circumstances may you combine this
10  * software in any way with any other Broadcom software provided under a
11  * license other than the GPL, without Broadcom's express prior written
12  * consent.
13  *****************************************************************************/
14
15 #ifndef __SOUND_ARM_BCM2835_H
16 #define __SOUND_ARM_BCM2835_H
17
18 #include <linux/device.h>
19 #include <linux/list.h>
20 #include <linux/interrupt.h>
21 #include <linux/wait.h>
22 #include <sound/core.h>
23 #include <sound/initval.h>
24 #include <sound/pcm.h>
25 #include <sound/pcm_params.h>
26 #include <sound/pcm-indirect.h>
27 #include <linux/workqueue.h>
28
29 /*
30 #define AUDIO_DEBUG_ENABLE
31 #define AUDIO_VERBOSE_DEBUG_ENABLE
32  */
33
34 /* Debug macros */
35
36 #ifdef AUDIO_DEBUG_ENABLE
37 #ifdef AUDIO_VERBOSE_DEBUG_ENABLE
38
39 #define audio_debug(fmt, arg...) \
40         printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
41
42 #define audio_info(fmt, arg...) \
43         printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
44
45 #else
46
47 #define audio_debug(fmt, arg...)
48
49 #define audio_info(fmt, arg...)
50
51 #endif /* AUDIO_VERBOSE_DEBUG_ENABLE */
52
53 #else
54
55 #define audio_debug(fmt, arg...)
56
57 #define audio_info(fmt, arg...)
58
59 #endif /* AUDIO_DEBUG_ENABLE */
60
61 #define audio_error(fmt, arg...) \
62         printk(KERN_ERR"%s:%d " fmt, __func__, __LINE__, ##arg)
63
64 #define audio_warning(fmt, arg...) \
65         printk(KERN_WARNING"%s:%d " fmt, __func__, __LINE__, ##arg)
66
67 #define audio_alert(fmt, arg...) \
68         printk(KERN_ALERT"%s:%d " fmt, __func__, __LINE__, ##arg)
69
70 #define MAX_SUBSTREAMS   (8)
71 #define AVAIL_SUBSTREAMS_MASK  (0xff)
72
73 enum {
74         CTRL_VOL_MUTE,
75         CTRL_VOL_UNMUTE
76 };
77
78 /* macros for alsa2chip and chip2alsa, instead of functions */
79
80 #define alsa2chip(vol) (uint)(-((vol << 8) / 100)) /* convert alsa to chip volume (defined as macro rather than function call) */
81 #define chip2alsa(vol) -((vol * 100) >> 8)   /* convert chip to alsa volume */
82
83 /* Some constants for values .. */
84 enum snd_bcm2835_route {
85         AUDIO_DEST_AUTO = 0,
86         AUDIO_DEST_HEADPHONES = 1,
87         AUDIO_DEST_HDMI = 2,
88         AUDIO_DEST_MAX,
89 };
90
91 enum snd_bcm2835_ctrl {
92         PCM_PLAYBACK_VOLUME,
93         PCM_PLAYBACK_MUTE,
94         PCM_PLAYBACK_DEVICE,
95 };
96
97 /* definition of the chip-specific record */
98 struct bcm2835_chip {
99         struct snd_card *card;
100         struct snd_pcm *pcm;
101         struct snd_pcm *pcm_spdif;
102         /* Bitmat for valid reg_base and irq numbers */
103         unsigned int avail_substreams;
104         struct platform_device *pdev[MAX_SUBSTREAMS];
105         struct bcm2835_alsa_stream *alsa_stream[MAX_SUBSTREAMS];
106
107         int volume;
108         int old_volume; /* stores the volume value whist muted */
109         int dest;
110         int mute;
111
112         unsigned int opened;
113         unsigned int spdif_status;
114         struct mutex audio_mutex;
115 };
116
117 struct bcm2835_alsa_stream {
118         struct bcm2835_chip *chip;
119         struct snd_pcm_substream *substream;
120         struct snd_pcm_indirect pcm_indirect;
121
122         struct semaphore buffers_update_sem;
123         struct semaphore control_sem;
124         spinlock_t lock;
125         volatile unsigned int control;
126         volatile unsigned int status;
127
128         int open;
129         int running;
130         int draining;
131
132         int channels;
133         int params_rate;
134         int pcm_format_width;
135
136         unsigned int pos;
137         unsigned int buffer_size;
138         unsigned int period_size;
139
140         unsigned int enable_fifo_irq;
141         irq_handler_t fifo_irq_handler;
142
143         atomic_t retrieved;
144         struct bcm2835_audio_instance *instance;
145         struct workqueue_struct *my_wq;
146         int idx;
147 };
148
149 int snd_bcm2835_new_ctl(struct bcm2835_chip *chip);
150 int snd_bcm2835_new_pcm(struct bcm2835_chip *chip);
151 int snd_bcm2835_new_spdif_pcm(struct bcm2835_chip *chip);
152
153 int bcm2835_audio_open(struct bcm2835_alsa_stream *alsa_stream);
154 int bcm2835_audio_close(struct bcm2835_alsa_stream *alsa_stream);
155 int bcm2835_audio_set_params(struct bcm2835_alsa_stream *alsa_stream,
156                              unsigned int channels, unsigned int samplerate,
157                              unsigned int bps);
158 int bcm2835_audio_setup(struct bcm2835_alsa_stream *alsa_stream);
159 int bcm2835_audio_start(struct bcm2835_alsa_stream *alsa_stream);
160 int bcm2835_audio_stop(struct bcm2835_alsa_stream *alsa_stream);
161 int bcm2835_audio_set_ctls(struct bcm2835_chip *chip);
162 int bcm2835_audio_write(struct bcm2835_alsa_stream *alsa_stream,
163                         unsigned int count,
164                         void *src);
165 unsigned int bcm2835_audio_retrieve_buffers(struct bcm2835_alsa_stream *alsa_stream);
166 void bcm2835_audio_flush_buffers(struct bcm2835_alsa_stream *alsa_stream);
167 void bcm2835_audio_flush_playback_buffers(struct bcm2835_alsa_stream *alsa_stream);
168
169 #endif /* __SOUND_ARM_BCM2835_H */