blob: a699b01210ee116c585b20d2727cd9bbcfeb1a44 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 <linux/version.h>
26#include <sound/control.h>
27#include <sound/pcm.h>
28#include "awacs.h"
29
30#include <linux/adb.h>
31#ifdef CONFIG_ADB_CUDA
32#include <linux/cuda.h>
33#endif
34#ifdef CONFIG_ADB_PMU
35#include <linux/pmu.h>
36#endif
37#include <linux/nvram.h>
38#include <linux/tty.h>
39#include <linux/vt_kern.h>
40#include <asm/dbdma.h>
41#include <asm/prom.h>
42#include <asm/machdep.h>
43
44/* maximum number of fragments */
45#define PMAC_MAX_FRAGS 32
46
47
48#define PMAC_SUPPORT_AUTOMUTE
49
50/*
51 * typedefs
52 */
53typedef struct snd_pmac pmac_t;
54typedef struct snd_pmac_stream pmac_stream_t;
55typedef struct snd_pmac_beep pmac_beep_t;
56typedef struct snd_pmac_dbdma pmac_dbdma_t;
57
58
59/*
60 * DBDMA space
61 */
62struct snd_pmac_dbdma {
63 unsigned long addr;
64 struct dbdma_cmd __iomem *cmds;
65 void *space;
66 int size;
67};
68
69/*
70 * playback/capture stream
71 */
72struct 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
95enum snd_pmac_model {
96 PMAC_AWACS, PMAC_SCREAMER, PMAC_BURGUNDY, PMAC_DACA, PMAC_TUMBLER, PMAC_SNAPPER
97};
98
99struct snd_pmac {
100 snd_card_t *card;
101
102 /* h/w info */
103 struct device_node *node;
104 unsigned int revision;
105 unsigned int manufacturer;
106 unsigned int subframe;
107 unsigned int device_id;
108 enum snd_pmac_model model;
109
110 unsigned int has_iic : 1;
111 unsigned int is_pbook_3400 : 1;
112 unsigned int is_pbook_G3 : 1;
113
114 unsigned int can_byte_swap : 1;
115 unsigned int can_duplex : 1;
116 unsigned int can_capture : 1;
117
118 unsigned int auto_mute : 1;
119 unsigned int initialized : 1;
120 unsigned int feature_is_set : 1;
121
122 unsigned int of_requested;
123
124 int num_freqs;
125 int *freq_table;
126 unsigned int freqs_ok; /* bit flags */
127 unsigned int formats_ok; /* pcm hwinfo */
128 int active;
129 int rate_index;
130 int format; /* current format */
131
132 spinlock_t reg_lock;
133 volatile struct awacs_regs __iomem *awacs;
134 int awacs_reg[8]; /* register cache */
135 unsigned int hp_stat_mask;
136
137 unsigned char __iomem *latch_base;
138 unsigned char __iomem *macio_base;
139
140 pmac_stream_t playback;
141 pmac_stream_t capture;
142
143 pmac_dbdma_t extra_dma;
144
145 int irq, tx_irq, rx_irq;
146
147 snd_pcm_t *pcm;
148
149 pmac_beep_t *beep;
150
151 unsigned int control_mask; /* control mask */
152
153 /* mixer stuffs */
154 void *mixer_data;
155 void (*mixer_free)(pmac_t *);
156 snd_kcontrol_t *master_sw_ctl;
157 snd_kcontrol_t *speaker_sw_ctl;
158 snd_kcontrol_t *drc_sw_ctl; /* only used for tumbler -ReneR */
159 snd_kcontrol_t *hp_detect_ctl;
160
161 /* lowlevel callbacks */
162 void (*set_format)(pmac_t *chip);
163 void (*update_automute)(pmac_t *chip, int do_notify);
164 int (*detect_headphone)(pmac_t *chip);
165#ifdef CONFIG_PMAC_PBOOK
166 void (*suspend)(pmac_t *chip);
167 void (*resume)(pmac_t *chip);
168#endif
169
170};
171
172
173/* exported functions */
174int snd_pmac_new(snd_card_t *card, pmac_t **chip_return);
175int snd_pmac_pcm_new(pmac_t *chip);
176int snd_pmac_attach_beep(pmac_t *chip);
177void snd_pmac_detach_beep(pmac_t *chip);
178void snd_pmac_beep_stop(pmac_t *chip);
179unsigned int snd_pmac_rate_index(pmac_t *chip, pmac_stream_t *rec, unsigned int rate);
180
181void snd_pmac_beep_dma_start(pmac_t *chip, int bytes, unsigned long addr, int speed);
182void snd_pmac_beep_dma_stop(pmac_t *chip);
183
184/* initialize mixer */
185int snd_pmac_awacs_init(pmac_t *chip);
186int snd_pmac_burgundy_init(pmac_t *chip);
187int snd_pmac_daca_init(pmac_t *chip);
188int snd_pmac_tumbler_init(pmac_t *chip);
189int snd_pmac_tumbler_post_init(void);
190
191/* i2c functions */
192typedef struct snd_pmac_keywest {
193 int addr;
194 struct i2c_client *client;
195 int id;
196 int (*init_client)(struct snd_pmac_keywest *i2c);
197 char *name;
198} pmac_keywest_t;
199
200int snd_pmac_keywest_init(pmac_keywest_t *i2c);
201void snd_pmac_keywest_cleanup(pmac_keywest_t *i2c);
202
203/* misc */
204int snd_pmac_boolean_stereo_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo);
205int snd_pmac_boolean_mono_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo);
206
207int snd_pmac_add_automute(pmac_t *chip);
208
209#define big_mdelay(msec) do {\
210 set_current_state(TASK_UNINTERRUPTIBLE);\
211 schedule_timeout(((msec) * HZ + 999) / 1000);\
212} while (0)
213
214#endif /* __PMAC_H */