Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | * DBDMA space |
| 51 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 52 | struct pmac_dbdma { |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 53 | dma_addr_t dma_base; |
| 54 | dma_addr_t addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | struct dbdma_cmd __iomem *cmds; |
| 56 | void *space; |
| 57 | int size; |
| 58 | }; |
| 59 | |
| 60 | /* |
| 61 | * playback/capture stream |
| 62 | */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 63 | struct pmac_stream { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | int running; /* boolean */ |
| 65 | |
| 66 | int stream; /* PLAYBACK/CAPTURE */ |
| 67 | |
| 68 | int dma_size; /* in bytes */ |
| 69 | int period_size; /* in bytes */ |
| 70 | int buffer_size; /* in kbytes */ |
| 71 | int nperiods, cur_period; |
| 72 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 73 | struct pmac_dbdma cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | volatile struct dbdma_regs __iomem *dma; |
| 75 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 76 | struct snd_pcm_substream *substream; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
| 78 | unsigned int cur_freqs; /* currently available frequencies */ |
| 79 | unsigned int cur_formats; /* currently available formats */ |
| 80 | }; |
| 81 | |
| 82 | |
| 83 | /* |
| 84 | */ |
| 85 | |
| 86 | enum snd_pmac_model { |
Benjamin Herrenschmidt | 1f7b49d | 2005-05-01 08:58:43 -0700 | [diff] [blame] | 87 | PMAC_AWACS, PMAC_SCREAMER, PMAC_BURGUNDY, PMAC_DACA, PMAC_TUMBLER, |
Johannes Berg | 55c385a | 2006-06-21 15:43:44 +0200 | [diff] [blame] | 88 | PMAC_SNAPPER |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | struct snd_pmac { |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 92 | struct snd_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
| 94 | /* h/w info */ |
| 95 | struct device_node *node; |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 96 | struct pci_dev *pdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | unsigned int revision; |
| 98 | unsigned int manufacturer; |
| 99 | unsigned int subframe; |
| 100 | unsigned int device_id; |
| 101 | enum snd_pmac_model model; |
| 102 | |
| 103 | unsigned int has_iic : 1; |
| 104 | unsigned int is_pbook_3400 : 1; |
| 105 | unsigned int is_pbook_G3 : 1; |
Benjamin Herrenschmidt | 7bbd827 | 2005-04-16 15:24:32 -0700 | [diff] [blame] | 106 | unsigned int is_k2 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
| 108 | unsigned int can_byte_swap : 1; |
| 109 | unsigned int can_duplex : 1; |
| 110 | unsigned int can_capture : 1; |
| 111 | |
| 112 | unsigned int auto_mute : 1; |
| 113 | unsigned int initialized : 1; |
| 114 | unsigned int feature_is_set : 1; |
| 115 | |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 116 | unsigned int requested; |
| 117 | struct resource rsrc[3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
| 119 | int num_freqs; |
| 120 | int *freq_table; |
| 121 | unsigned int freqs_ok; /* bit flags */ |
| 122 | unsigned int formats_ok; /* pcm hwinfo */ |
| 123 | int active; |
| 124 | int rate_index; |
| 125 | int format; /* current format */ |
| 126 | |
| 127 | spinlock_t reg_lock; |
| 128 | volatile struct awacs_regs __iomem *awacs; |
| 129 | int awacs_reg[8]; /* register cache */ |
| 130 | unsigned int hp_stat_mask; |
| 131 | |
| 132 | unsigned char __iomem *latch_base; |
| 133 | unsigned char __iomem *macio_base; |
| 134 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 135 | struct pmac_stream playback; |
| 136 | struct pmac_stream capture; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 138 | struct pmac_dbdma extra_dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
| 140 | int irq, tx_irq, rx_irq; |
| 141 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 142 | struct snd_pcm *pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 144 | struct pmac_beep *beep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
| 146 | unsigned int control_mask; /* control mask */ |
| 147 | |
| 148 | /* mixer stuffs */ |
| 149 | void *mixer_data; |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 150 | void (*mixer_free)(struct snd_pmac *); |
| 151 | struct snd_kcontrol *master_sw_ctl; |
| 152 | struct snd_kcontrol *speaker_sw_ctl; |
| 153 | struct snd_kcontrol *drc_sw_ctl; /* only used for tumbler -ReneR */ |
| 154 | struct snd_kcontrol *hp_detect_ctl; |
| 155 | struct snd_kcontrol *lineout_sw_ctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
| 157 | /* lowlevel callbacks */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 158 | void (*set_format)(struct snd_pmac *chip); |
| 159 | void (*update_automute)(struct snd_pmac *chip, int do_notify); |
| 160 | int (*detect_headphone)(struct snd_pmac *chip); |
Benjamin Herrenschmidt | 8c87093 | 2005-06-27 14:36:34 -0700 | [diff] [blame] | 161 | #ifdef CONFIG_PM |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 162 | void (*suspend)(struct snd_pmac *chip); |
| 163 | void (*resume)(struct snd_pmac *chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | #endif |
| 165 | |
| 166 | }; |
| 167 | |
| 168 | |
| 169 | /* exported functions */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 170 | int snd_pmac_new(struct snd_card *card, struct snd_pmac **chip_return); |
| 171 | int snd_pmac_pcm_new(struct snd_pmac *chip); |
| 172 | int snd_pmac_attach_beep(struct snd_pmac *chip); |
| 173 | void snd_pmac_detach_beep(struct snd_pmac *chip); |
| 174 | void snd_pmac_beep_stop(struct snd_pmac *chip); |
| 175 | unsigned int snd_pmac_rate_index(struct snd_pmac *chip, struct pmac_stream *rec, unsigned int rate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 177 | void snd_pmac_beep_dma_start(struct snd_pmac *chip, int bytes, unsigned long addr, int speed); |
| 178 | void snd_pmac_beep_dma_stop(struct snd_pmac *chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
Takashi Iwai | 5e12bea | 2005-11-17 17:17:08 +0100 | [diff] [blame] | 180 | #ifdef CONFIG_PM |
| 181 | void snd_pmac_suspend(struct snd_pmac *chip); |
| 182 | void snd_pmac_resume(struct snd_pmac *chip); |
| 183 | #endif |
| 184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | /* initialize mixer */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 186 | int snd_pmac_awacs_init(struct snd_pmac *chip); |
| 187 | int snd_pmac_burgundy_init(struct snd_pmac *chip); |
| 188 | int snd_pmac_daca_init(struct snd_pmac *chip); |
| 189 | int snd_pmac_tumbler_init(struct snd_pmac *chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | int snd_pmac_tumbler_post_init(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | |
| 192 | /* i2c functions */ |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 193 | struct pmac_keywest { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | int addr; |
| 195 | struct i2c_client *client; |
| 196 | int id; |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 197 | int (*init_client)(struct pmac_keywest *i2c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | char *name; |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 199 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 201 | int snd_pmac_keywest_init(struct pmac_keywest *i2c); |
| 202 | void snd_pmac_keywest_cleanup(struct pmac_keywest *i2c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
| 204 | /* misc */ |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 205 | #define snd_pmac_boolean_stereo_info snd_ctl_boolean_stereo_info |
| 206 | #define snd_pmac_boolean_mono_info snd_ctl_boolean_mono_info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
Takashi Iwai | 65b29f5 | 2005-11-17 15:09:46 +0100 | [diff] [blame] | 208 | int snd_pmac_add_automute(struct snd_pmac *chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | #endif /* __PMAC_H */ |