1 /*****************************************************************************
2 * Copyright 2011 Broadcom Corporation. All rights reserved.
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").
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
13 *****************************************************************************/
15 #ifndef __SOUND_ARM_BCM2835_H
16 #define __SOUND_ARM_BCM2835_H
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>
30 * #define AUDIO_DEBUG_ENABLE
31 * #define AUDIO_VERBOSE_DEBUG_ENABLE
36 #ifdef AUDIO_DEBUG_ENABLE
37 #ifdef AUDIO_VERBOSE_DEBUG_ENABLE
39 #define audio_debug(fmt, arg...) \
40 pr_info("%s:%d " fmt, __func__, __LINE__, ##arg)
42 #define audio_info(fmt, arg...) \
43 pr_info("%s:%d " fmt, __func__, __LINE__, ##arg)
47 #define audio_debug(fmt, arg...)
49 #define audio_info(fmt, arg...)
51 #endif /* AUDIO_VERBOSE_DEBUG_ENABLE */
55 #define audio_debug(fmt, arg...)
57 #define audio_info(fmt, arg...)
59 #endif /* AUDIO_DEBUG_ENABLE */
61 #define audio_error(fmt, arg...) \
62 pr_err("%s:%d " fmt, __func__, __LINE__, ##arg)
64 #define audio_warning(fmt, arg...) \
65 pr_warn("%s:%d " fmt, __func__, __LINE__, ##arg)
67 #define audio_alert(fmt, arg...) \
68 pr_alert("%s:%d " fmt, __func__, __LINE__, ##arg)
70 #define MAX_SUBSTREAMS (8)
71 #define AVAIL_SUBSTREAMS_MASK (0xff)
78 /* macros for alsa2chip and chip2alsa, instead of functions */
80 // convert alsa to chip volume (defined as macro rather than function call)
81 #define alsa2chip(vol) (uint)(-(((vol) << 8) / 100))
83 // convert chip to alsa volume
84 #define chip2alsa(vol) -(((vol) * 100) >> 8)
86 /* Some constants for values .. */
87 enum snd_bcm2835_route {
89 AUDIO_DEST_HEADPHONES = 1,
94 enum snd_bcm2835_ctrl {
100 /* definition of the chip-specific record */
101 struct bcm2835_chip {
102 struct snd_card *card;
104 struct snd_pcm *pcm_spdif;
105 /* Bitmat for valid reg_base and irq numbers */
106 unsigned int avail_substreams;
108 struct bcm2835_alsa_stream *alsa_stream[MAX_SUBSTREAMS];
111 int old_volume; /* stores the volume value whist muted */
116 unsigned int spdif_status;
117 struct mutex audio_mutex;
120 struct bcm2835_alsa_stream {
121 struct bcm2835_chip *chip;
122 struct snd_pcm_substream *substream;
123 struct snd_pcm_indirect pcm_indirect;
126 volatile unsigned int control;
127 volatile unsigned int status;
135 int pcm_format_width;
138 unsigned int buffer_size;
139 unsigned int period_size;
142 struct bcm2835_audio_instance *instance;
143 struct workqueue_struct *my_wq;
147 int snd_bcm2835_new_ctl(struct bcm2835_chip *chip);
148 int snd_bcm2835_new_pcm(struct bcm2835_chip *chip, u32 numchannels);
149 int snd_bcm2835_new_spdif_pcm(struct bcm2835_chip *chip);
150 int snd_bcm2835_new_simple_pcm(struct bcm2835_chip *chip,
152 enum snd_bcm2835_route route,
155 int snd_bcm2835_new_hdmi_ctl(struct bcm2835_chip *chip);
156 int snd_bcm2835_new_headphones_ctl(struct bcm2835_chip *chip);
158 int bcm2835_audio_open(struct bcm2835_alsa_stream *alsa_stream);
159 int bcm2835_audio_close(struct bcm2835_alsa_stream *alsa_stream);
160 int bcm2835_audio_set_params(struct bcm2835_alsa_stream *alsa_stream,
161 unsigned int channels, unsigned int samplerate,
163 int bcm2835_audio_setup(struct bcm2835_alsa_stream *alsa_stream);
164 int bcm2835_audio_start(struct bcm2835_alsa_stream *alsa_stream);
165 int bcm2835_audio_stop(struct bcm2835_alsa_stream *alsa_stream);
166 int bcm2835_audio_set_ctls(struct bcm2835_chip *chip);
167 int bcm2835_audio_write(struct bcm2835_alsa_stream *alsa_stream,
170 void bcm2835_playback_fifo(struct bcm2835_alsa_stream *alsa_stream);
171 unsigned int bcm2835_audio_retrieve_buffers(struct bcm2835_alsa_stream *alsa_stream);
172 void bcm2835_audio_flush_buffers(struct bcm2835_alsa_stream *alsa_stream);
173 void bcm2835_audio_flush_playback_buffers(struct bcm2835_alsa_stream *alsa_stream);
175 #endif /* __SOUND_ARM_BCM2835_H */