Merge git://git.kernel.org/pub/scm/linux/kernel/git/bunk/trivial
[pandora-kernel.git] / sound / ppc / pmac.h
1 /*
2  * Driver for PowerMac onboard soundchips
3  * Copyright (c) 2001 by Takashi Iwai <tiwai@suse.de>
4  *   based on dmasound.c.
5  *
6  *   This program is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation; either version 2 of the License, or
9  *   (at your option) any later version.
10  *
11  *   This program is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU General Public License for more details.
15  *
16  *   You should have received a copy of the GNU General Public License
17  *   along with this program; if not, write to the Free Software
18  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19  */
20
21
22 #ifndef __PMAC_H
23 #define __PMAC_H
24
25 #include <sound/control.h>
26 #include <sound/pcm.h>
27 #include "awacs.h"
28
29 #include <linux/adb.h>
30 #ifdef CONFIG_ADB_CUDA
31 #include <linux/cuda.h>
32 #endif
33 #ifdef CONFIG_ADB_PMU
34 #include <linux/pmu.h>
35 #endif
36 #include <linux/nvram.h>
37 #include <linux/tty.h>
38 #include <linux/vt_kern.h>
39 #include <asm/dbdma.h>
40 #include <asm/prom.h>
41 #include <asm/machdep.h>
42
43 /* maximum number of fragments */
44 #define PMAC_MAX_FRAGS          32
45
46
47 #define PMAC_SUPPORT_AUTOMUTE
48
49 /*
50  * typedefs
51  */
52 typedef struct snd_pmac pmac_t;
53 typedef struct snd_pmac_stream pmac_stream_t;
54 typedef struct snd_pmac_beep pmac_beep_t;
55 typedef struct snd_pmac_dbdma pmac_dbdma_t;
56
57
58 /*
59  * DBDMA space
60  */
61 struct snd_pmac_dbdma {
62         dma_addr_t dma_base;
63         dma_addr_t addr;
64         struct dbdma_cmd __iomem *cmds;
65         void *space;
66         int size;
67 };
68
69 /*
70  * playback/capture stream
71  */
72 struct snd_pmac_stream {
73         int running;    /* boolean */
74
75         int stream;     /* PLAYBACK/CAPTURE */
76
77         int dma_size; /* in bytes */
78         int period_size; /* in bytes */
79         int buffer_size; /* in kbytes */
80         int nperiods, cur_period;
81
82         pmac_dbdma_t cmd;
83         volatile struct dbdma_regs __iomem *dma;
84
85         snd_pcm_substream_t *substream;
86
87         unsigned int cur_freqs;         /* currently available frequencies */
88         unsigned int cur_formats;       /* currently available formats */
89 };
90
91
92 /*
93  */
94
95 enum snd_pmac_model {
96         PMAC_AWACS, PMAC_SCREAMER, PMAC_BURGUNDY, PMAC_DACA, PMAC_TUMBLER,
97         PMAC_SNAPPER, PMAC_TOONIE
98 };
99
100 struct snd_pmac {
101         snd_card_t *card;
102
103         /* h/w info */
104         struct device_node *node;
105         struct pci_dev *pdev;
106         unsigned int revision;
107         unsigned int manufacturer;
108         unsigned int subframe;
109         unsigned int device_id;
110         enum snd_pmac_model model;
111
112         unsigned int has_iic : 1;
113         unsigned int is_pbook_3400 : 1;
114         unsigned int is_pbook_G3 : 1;
115         unsigned int is_k2 : 1;
116
117         unsigned int can_byte_swap : 1;
118         unsigned int can_duplex : 1;
119         unsigned int can_capture : 1;
120
121         unsigned int auto_mute : 1;
122         unsigned int initialized : 1;
123         unsigned int feature_is_set : 1;
124
125         unsigned int of_requested;
126
127         int num_freqs;
128         int *freq_table;
129         unsigned int freqs_ok;          /* bit flags */
130         unsigned int formats_ok;        /* pcm hwinfo */
131         int active;
132         int rate_index;
133         int format;                     /* current format */
134
135         spinlock_t reg_lock;
136         volatile struct awacs_regs __iomem *awacs;
137         int awacs_reg[8]; /* register cache */
138         unsigned int hp_stat_mask;
139
140         unsigned char __iomem *latch_base;
141         unsigned char __iomem *macio_base;
142
143         pmac_stream_t playback;
144         pmac_stream_t capture;
145
146         pmac_dbdma_t extra_dma;
147
148         int irq, tx_irq, rx_irq;
149
150         snd_pcm_t *pcm;
151
152         pmac_beep_t *beep;
153
154         unsigned int control_mask;      /* control mask */
155
156         /* mixer stuffs */
157         void *mixer_data;
158         void (*mixer_free)(pmac_t *);
159         snd_kcontrol_t *master_sw_ctl;
160         snd_kcontrol_t *speaker_sw_ctl;
161         snd_kcontrol_t *drc_sw_ctl;     /* only used for tumbler -ReneR */
162         snd_kcontrol_t *hp_detect_ctl;
163         snd_kcontrol_t *lineout_sw_ctl;
164
165         /* lowlevel callbacks */
166         void (*set_format)(pmac_t *chip);
167         void (*update_automute)(pmac_t *chip, int do_notify);
168         int (*detect_headphone)(pmac_t *chip);
169 #ifdef CONFIG_PM
170         void (*suspend)(pmac_t *chip);
171         void (*resume)(pmac_t *chip);
172 #endif
173
174 };
175
176
177 /* exported functions */
178 int snd_pmac_new(snd_card_t *card, pmac_t **chip_return);
179 int snd_pmac_pcm_new(pmac_t *chip);
180 int snd_pmac_attach_beep(pmac_t *chip);
181 void snd_pmac_detach_beep(pmac_t *chip);
182 void snd_pmac_beep_stop(pmac_t *chip);
183 unsigned int snd_pmac_rate_index(pmac_t *chip, pmac_stream_t *rec, unsigned int rate);
184
185 void snd_pmac_beep_dma_start(pmac_t *chip, int bytes, unsigned long addr, int speed);
186 void snd_pmac_beep_dma_stop(pmac_t *chip);
187
188 /* initialize mixer */
189 int snd_pmac_awacs_init(pmac_t *chip);
190 int snd_pmac_burgundy_init(pmac_t *chip);
191 int snd_pmac_daca_init(pmac_t *chip);
192 int snd_pmac_tumbler_init(pmac_t *chip);
193 int snd_pmac_tumbler_post_init(void);
194 int snd_pmac_toonie_init(pmac_t *chip);
195
196 /* i2c functions */
197 typedef struct snd_pmac_keywest {
198         int addr;
199         struct i2c_client *client;
200         int id;
201         int (*init_client)(struct snd_pmac_keywest *i2c);
202         char *name;
203 } pmac_keywest_t;
204
205 int snd_pmac_keywest_init(pmac_keywest_t *i2c);
206 void snd_pmac_keywest_cleanup(pmac_keywest_t *i2c);
207
208 /* misc */
209 int snd_pmac_boolean_stereo_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo);
210 int snd_pmac_boolean_mono_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo);
211
212 int snd_pmac_add_automute(pmac_t *chip);
213
214 #endif /* __PMAC_H */