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 printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
42 #define audio_info(fmt, arg...) \
43 printk(KERN_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 printk(KERN_ERR"%s:%d " fmt, __func__, __LINE__, ##arg)
64 #define audio_warning(fmt, arg...) \
65 printk(KERN_WARNING"%s:%d " fmt, __func__, __LINE__, ##arg)
67 #define audio_alert(fmt, arg...) \
68 printk(KERN_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 #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 */
83 /* Some constants for values .. */
84 enum snd_bcm2835_route
{
86 AUDIO_DEST_HEADPHONES
= 1,
91 enum snd_bcm2835_ctrl
{
97 /* definition of the chip-specific record */
99 struct snd_card
*card
;
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
];
108 int old_volume
; /* stores the volume value whist muted */
113 unsigned int spdif_status
;
114 struct mutex audio_mutex
;
117 struct bcm2835_alsa_stream
{
118 struct bcm2835_chip
*chip
;
119 struct snd_pcm_substream
*substream
;
120 struct snd_pcm_indirect pcm_indirect
;
122 struct semaphore buffers_update_sem
;
123 struct semaphore control_sem
;
125 volatile unsigned int control
;
126 volatile unsigned int status
;
134 int pcm_format_width
;
137 unsigned int buffer_size
;
138 unsigned int period_size
;
141 struct bcm2835_audio_instance
*instance
;
142 struct workqueue_struct
*my_wq
;
146 int snd_bcm2835_new_ctl(struct bcm2835_chip
*chip
);
147 int snd_bcm2835_new_pcm(struct bcm2835_chip
*chip
);
148 int snd_bcm2835_new_spdif_pcm(struct bcm2835_chip
*chip
);
150 int bcm2835_audio_open(struct bcm2835_alsa_stream
*alsa_stream
);
151 int bcm2835_audio_close(struct bcm2835_alsa_stream
*alsa_stream
);
152 int bcm2835_audio_set_params(struct bcm2835_alsa_stream
*alsa_stream
,
153 unsigned int channels
, unsigned int samplerate
,
155 int bcm2835_audio_setup(struct bcm2835_alsa_stream
*alsa_stream
);
156 int bcm2835_audio_start(struct bcm2835_alsa_stream
*alsa_stream
);
157 int bcm2835_audio_stop(struct bcm2835_alsa_stream
*alsa_stream
);
158 int bcm2835_audio_set_ctls(struct bcm2835_chip
*chip
);
159 int bcm2835_audio_write(struct bcm2835_alsa_stream
*alsa_stream
,
162 void bcm2835_playback_fifo(struct bcm2835_alsa_stream
*alsa_stream
);
163 unsigned int bcm2835_audio_retrieve_buffers(struct bcm2835_alsa_stream
*alsa_stream
);
164 void bcm2835_audio_flush_buffers(struct bcm2835_alsa_stream
*alsa_stream
);
165 void bcm2835_audio_flush_playback_buffers(struct bcm2835_alsa_stream
*alsa_stream
);
167 #endif /* __SOUND_ARM_BCM2835_H */