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