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