GNU Linux-libre 4.14.294-gnu1
[releases.git] / drivers / staging / vc04_services / 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         pr_info("%s:%d " fmt, __func__, __LINE__, ##arg)
41
42 #define audio_info(fmt, arg...) \
43         pr_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         pr_err("%s:%d " fmt, __func__, __LINE__, ##arg)
63
64 #define audio_warning(fmt, arg...) \
65         pr_warn("%s:%d " fmt, __func__, __LINE__, ##arg)
66
67 #define audio_alert(fmt, arg...) \
68         pr_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 // convert alsa to chip volume (defined as macro rather than function call)
81 #define alsa2chip(vol) (uint)(-(((vol) << 8) / 100))
82
83 // convert chip to alsa volume
84 #define chip2alsa(vol) -(((vol) * 100) >> 8)
85
86 /* Some constants for values .. */
87 enum snd_bcm2835_route {
88         AUDIO_DEST_AUTO = 0,
89         AUDIO_DEST_HEADPHONES = 1,
90         AUDIO_DEST_HDMI = 2,
91         AUDIO_DEST_MAX,
92 };
93
94 enum snd_bcm2835_ctrl {
95         PCM_PLAYBACK_VOLUME,
96         PCM_PLAYBACK_MUTE,
97         PCM_PLAYBACK_DEVICE,
98 };
99
100 /* definition of the chip-specific record */
101 struct bcm2835_chip {
102         struct snd_card *card;
103         struct snd_pcm *pcm;
104         struct snd_pcm *pcm_spdif;
105         /* Bitmat for valid reg_base and irq numbers */
106         unsigned int avail_substreams;
107         struct device *dev;
108         struct bcm2835_alsa_stream *alsa_stream[MAX_SUBSTREAMS];
109
110         int volume;
111         int old_volume; /* stores the volume value whist muted */
112         int dest;
113         int mute;
114
115         unsigned int opened;
116         unsigned int spdif_status;
117         struct mutex audio_mutex;
118 };
119
120 struct bcm2835_alsa_stream {
121         struct bcm2835_chip *chip;
122         struct snd_pcm_substream *substream;
123         struct snd_pcm_indirect pcm_indirect;
124
125         spinlock_t lock;
126         volatile unsigned int control;
127         volatile unsigned int status;
128
129         int open;
130         int running;
131         int draining;
132
133         int channels;
134         int params_rate;
135         int pcm_format_width;
136
137         unsigned int pos;
138         unsigned int buffer_size;
139         unsigned int period_size;
140
141         atomic_t retrieved;
142         struct bcm2835_audio_instance *instance;
143         struct workqueue_struct *my_wq;
144         int idx;
145 };
146
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,
151                                const char *name,
152                                enum snd_bcm2835_route route,
153                                u32 numchannels);
154
155 int snd_bcm2835_new_hdmi_ctl(struct bcm2835_chip *chip);
156 int snd_bcm2835_new_headphones_ctl(struct bcm2835_chip *chip);
157
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,
162                              unsigned int bps);
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,
168                         unsigned int count,
169                         void *src);
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);
174
175 #endif /* __SOUND_ARM_BCM2835_H */