11a59d1b8SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 21da177e4SLinus Torvalds /* 31da177e4SLinus Torvalds * Driver for PowerMac onboard soundchips 41da177e4SLinus Torvalds * Copyright (c) 2001 by Takashi Iwai <tiwai@suse.de> 51da177e4SLinus Torvalds * based on dmasound.c. 61da177e4SLinus Torvalds */ 71da177e4SLinus Torvalds 81da177e4SLinus Torvalds 91da177e4SLinus Torvalds #ifndef __PMAC_H 101da177e4SLinus Torvalds #define __PMAC_H 111da177e4SLinus Torvalds 121da177e4SLinus Torvalds #include <sound/control.h> 131da177e4SLinus Torvalds #include <sound/pcm.h> 141da177e4SLinus Torvalds #include "awacs.h" 151da177e4SLinus Torvalds 161da177e4SLinus Torvalds #include <linux/adb.h> 171da177e4SLinus Torvalds #ifdef CONFIG_ADB_CUDA 181da177e4SLinus Torvalds #include <linux/cuda.h> 191da177e4SLinus Torvalds #endif 201da177e4SLinus Torvalds #ifdef CONFIG_ADB_PMU 211da177e4SLinus Torvalds #include <linux/pmu.h> 221da177e4SLinus Torvalds #endif 231da177e4SLinus Torvalds #include <linux/nvram.h> 241da177e4SLinus Torvalds #include <linux/tty.h> 251da177e4SLinus Torvalds #include <linux/vt_kern.h> 261da177e4SLinus Torvalds #include <asm/dbdma.h> 271da177e4SLinus Torvalds #include <asm/prom.h> 281da177e4SLinus Torvalds #include <asm/machdep.h> 29*e6d03ac1SChristophe Leroy #include <asm/pmac_feature.h> 301da177e4SLinus Torvalds 311da177e4SLinus Torvalds /* maximum number of fragments */ 321da177e4SLinus Torvalds #define PMAC_MAX_FRAGS 32 331da177e4SLinus Torvalds 341da177e4SLinus Torvalds 351da177e4SLinus Torvalds #define PMAC_SUPPORT_AUTOMUTE 361da177e4SLinus Torvalds 371da177e4SLinus Torvalds /* 381da177e4SLinus Torvalds * DBDMA space 391da177e4SLinus Torvalds */ 4065b29f50STakashi Iwai struct pmac_dbdma { 417bbd8277SBenjamin Herrenschmidt dma_addr_t dma_base; 427bbd8277SBenjamin Herrenschmidt dma_addr_t addr; 431da177e4SLinus Torvalds struct dbdma_cmd __iomem *cmds; 441da177e4SLinus Torvalds void *space; 451da177e4SLinus Torvalds int size; 461da177e4SLinus Torvalds }; 471da177e4SLinus Torvalds 481da177e4SLinus Torvalds /* 491da177e4SLinus Torvalds * playback/capture stream 501da177e4SLinus Torvalds */ 5165b29f50STakashi Iwai struct pmac_stream { 521da177e4SLinus Torvalds int running; /* boolean */ 531da177e4SLinus Torvalds 541da177e4SLinus Torvalds int stream; /* PLAYBACK/CAPTURE */ 551da177e4SLinus Torvalds 561da177e4SLinus Torvalds int dma_size; /* in bytes */ 571da177e4SLinus Torvalds int period_size; /* in bytes */ 581da177e4SLinus Torvalds int buffer_size; /* in kbytes */ 591da177e4SLinus Torvalds int nperiods, cur_period; 601da177e4SLinus Torvalds 6165b29f50STakashi Iwai struct pmac_dbdma cmd; 621da177e4SLinus Torvalds volatile struct dbdma_regs __iomem *dma; 631da177e4SLinus Torvalds 6465b29f50STakashi Iwai struct snd_pcm_substream *substream; 651da177e4SLinus Torvalds 661da177e4SLinus Torvalds unsigned int cur_freqs; /* currently available frequencies */ 671da177e4SLinus Torvalds unsigned int cur_formats; /* currently available formats */ 681da177e4SLinus Torvalds }; 691da177e4SLinus Torvalds 701da177e4SLinus Torvalds 711da177e4SLinus Torvalds /* 721da177e4SLinus Torvalds */ 731da177e4SLinus Torvalds 741da177e4SLinus Torvalds enum snd_pmac_model { 751f7b49d0SBenjamin Herrenschmidt PMAC_AWACS, PMAC_SCREAMER, PMAC_BURGUNDY, PMAC_DACA, PMAC_TUMBLER, 7655c385adSJohannes Berg PMAC_SNAPPER 771da177e4SLinus Torvalds }; 781da177e4SLinus Torvalds 791da177e4SLinus Torvalds struct snd_pmac { 8065b29f50STakashi Iwai struct snd_card *card; 811da177e4SLinus Torvalds 821da177e4SLinus Torvalds /* h/w info */ 831da177e4SLinus Torvalds struct device_node *node; 847bbd8277SBenjamin Herrenschmidt struct pci_dev *pdev; 851da177e4SLinus Torvalds unsigned int revision; 861da177e4SLinus Torvalds unsigned int manufacturer; 871da177e4SLinus Torvalds unsigned int subframe; 881da177e4SLinus Torvalds unsigned int device_id; 891da177e4SLinus Torvalds enum snd_pmac_model model; 901da177e4SLinus Torvalds 911da177e4SLinus Torvalds unsigned int has_iic : 1; 921da177e4SLinus Torvalds unsigned int is_pbook_3400 : 1; 931da177e4SLinus Torvalds unsigned int is_pbook_G3 : 1; 947bbd8277SBenjamin Herrenschmidt unsigned int is_k2 : 1; 951da177e4SLinus Torvalds 961da177e4SLinus Torvalds unsigned int can_byte_swap : 1; 971da177e4SLinus Torvalds unsigned int can_duplex : 1; 981da177e4SLinus Torvalds unsigned int can_capture : 1; 991da177e4SLinus Torvalds 1001da177e4SLinus Torvalds unsigned int auto_mute : 1; 1011da177e4SLinus Torvalds unsigned int initialized : 1; 1021da177e4SLinus Torvalds unsigned int feature_is_set : 1; 1031da177e4SLinus Torvalds 104cc5d0189SBenjamin Herrenschmidt unsigned int requested; 105cc5d0189SBenjamin Herrenschmidt struct resource rsrc[3]; 1061da177e4SLinus Torvalds 1071da177e4SLinus Torvalds int num_freqs; 1086e9ef32fSTakashi Iwai const int *freq_table; 1091da177e4SLinus Torvalds unsigned int freqs_ok; /* bit flags */ 1101da177e4SLinus Torvalds unsigned int formats_ok; /* pcm hwinfo */ 1111da177e4SLinus Torvalds int active; 1121da177e4SLinus Torvalds int rate_index; 1131da177e4SLinus Torvalds int format; /* current format */ 1141da177e4SLinus Torvalds 1151da177e4SLinus Torvalds spinlock_t reg_lock; 1161da177e4SLinus Torvalds volatile struct awacs_regs __iomem *awacs; 1171da177e4SLinus Torvalds int awacs_reg[8]; /* register cache */ 1181da177e4SLinus Torvalds unsigned int hp_stat_mask; 1191da177e4SLinus Torvalds 1201da177e4SLinus Torvalds unsigned char __iomem *latch_base; 1211da177e4SLinus Torvalds unsigned char __iomem *macio_base; 1221da177e4SLinus Torvalds 12365b29f50STakashi Iwai struct pmac_stream playback; 12465b29f50STakashi Iwai struct pmac_stream capture; 1251da177e4SLinus Torvalds 12665b29f50STakashi Iwai struct pmac_dbdma extra_dma; 1271da177e4SLinus Torvalds 1281da177e4SLinus Torvalds int irq, tx_irq, rx_irq; 1291da177e4SLinus Torvalds 13065b29f50STakashi Iwai struct snd_pcm *pcm; 1311da177e4SLinus Torvalds 13265b29f50STakashi Iwai struct pmac_beep *beep; 1331da177e4SLinus Torvalds 1341da177e4SLinus Torvalds unsigned int control_mask; /* control mask */ 1351da177e4SLinus Torvalds 1361da177e4SLinus Torvalds /* mixer stuffs */ 1371da177e4SLinus Torvalds void *mixer_data; 13865b29f50STakashi Iwai void (*mixer_free)(struct snd_pmac *); 13965b29f50STakashi Iwai struct snd_kcontrol *master_sw_ctl; 14065b29f50STakashi Iwai struct snd_kcontrol *speaker_sw_ctl; 14165b29f50STakashi Iwai struct snd_kcontrol *drc_sw_ctl; /* only used for tumbler -ReneR */ 14265b29f50STakashi Iwai struct snd_kcontrol *hp_detect_ctl; 14365b29f50STakashi Iwai struct snd_kcontrol *lineout_sw_ctl; 1441da177e4SLinus Torvalds 1451da177e4SLinus Torvalds /* lowlevel callbacks */ 14665b29f50STakashi Iwai void (*set_format)(struct snd_pmac *chip); 14765b29f50STakashi Iwai void (*update_automute)(struct snd_pmac *chip, int do_notify); 14865b29f50STakashi Iwai int (*detect_headphone)(struct snd_pmac *chip); 1498c870933SBenjamin Herrenschmidt #ifdef CONFIG_PM 15065b29f50STakashi Iwai void (*suspend)(struct snd_pmac *chip); 15165b29f50STakashi Iwai void (*resume)(struct snd_pmac *chip); 1521da177e4SLinus Torvalds #endif 1531da177e4SLinus Torvalds 1541da177e4SLinus Torvalds }; 1551da177e4SLinus Torvalds 1561da177e4SLinus Torvalds 1571da177e4SLinus Torvalds /* exported functions */ 15865b29f50STakashi Iwai int snd_pmac_new(struct snd_card *card, struct snd_pmac **chip_return); 15965b29f50STakashi Iwai int snd_pmac_pcm_new(struct snd_pmac *chip); 16065b29f50STakashi Iwai int snd_pmac_attach_beep(struct snd_pmac *chip); 16165b29f50STakashi Iwai void snd_pmac_detach_beep(struct snd_pmac *chip); 16265b29f50STakashi Iwai void snd_pmac_beep_stop(struct snd_pmac *chip); 16365b29f50STakashi Iwai unsigned int snd_pmac_rate_index(struct snd_pmac *chip, struct pmac_stream *rec, unsigned int rate); 1641da177e4SLinus Torvalds 16565b29f50STakashi Iwai void snd_pmac_beep_dma_start(struct snd_pmac *chip, int bytes, unsigned long addr, int speed); 16665b29f50STakashi Iwai void snd_pmac_beep_dma_stop(struct snd_pmac *chip); 1671da177e4SLinus Torvalds 1685e12bea0STakashi Iwai #ifdef CONFIG_PM 1695e12bea0STakashi Iwai void snd_pmac_suspend(struct snd_pmac *chip); 1705e12bea0STakashi Iwai void snd_pmac_resume(struct snd_pmac *chip); 1715e12bea0STakashi Iwai #endif 1725e12bea0STakashi Iwai 1731da177e4SLinus Torvalds /* initialize mixer */ 17465b29f50STakashi Iwai int snd_pmac_awacs_init(struct snd_pmac *chip); 17565b29f50STakashi Iwai int snd_pmac_burgundy_init(struct snd_pmac *chip); 17665b29f50STakashi Iwai int snd_pmac_daca_init(struct snd_pmac *chip); 17765b29f50STakashi Iwai int snd_pmac_tumbler_init(struct snd_pmac *chip); 1781da177e4SLinus Torvalds int snd_pmac_tumbler_post_init(void); 1791da177e4SLinus Torvalds 1801da177e4SLinus Torvalds /* i2c functions */ 18165b29f50STakashi Iwai struct pmac_keywest { 1821da177e4SLinus Torvalds int addr; 1831da177e4SLinus Torvalds struct i2c_client *client; 1841da177e4SLinus Torvalds int id; 18565b29f50STakashi Iwai int (*init_client)(struct pmac_keywest *i2c); 1861da177e4SLinus Torvalds char *name; 18765b29f50STakashi Iwai }; 1881da177e4SLinus Torvalds 18965b29f50STakashi Iwai int snd_pmac_keywest_init(struct pmac_keywest *i2c); 19065b29f50STakashi Iwai void snd_pmac_keywest_cleanup(struct pmac_keywest *i2c); 1911da177e4SLinus Torvalds 1921da177e4SLinus Torvalds /* misc */ 193a5ce8890STakashi Iwai #define snd_pmac_boolean_stereo_info snd_ctl_boolean_stereo_info 194a5ce8890STakashi Iwai #define snd_pmac_boolean_mono_info snd_ctl_boolean_mono_info 1951da177e4SLinus Torvalds 19665b29f50STakashi Iwai int snd_pmac_add_automute(struct snd_pmac *chip); 1971da177e4SLinus Torvalds 1981da177e4SLinus Torvalds #endif /* __PMAC_H */ 199