xref: /openbmc/linux/sound/ppc/pmac.h (revision 65b29f5039b38a5854b5e12238b0688a33e235cc)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * Driver for PowerMac onboard soundchips
31da177e4SLinus Torvalds  * Copyright (c) 2001 by Takashi Iwai <tiwai@suse.de>
41da177e4SLinus Torvalds  *   based on dmasound.c.
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  *   This program is free software; you can redistribute it and/or modify
71da177e4SLinus Torvalds  *   it under the terms of the GNU General Public License as published by
81da177e4SLinus Torvalds  *   the Free Software Foundation; either version 2 of the License, or
91da177e4SLinus Torvalds  *   (at your option) any later version.
101da177e4SLinus Torvalds  *
111da177e4SLinus Torvalds  *   This program is distributed in the hope that it will be useful,
121da177e4SLinus Torvalds  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
131da177e4SLinus Torvalds  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
141da177e4SLinus Torvalds  *   GNU General Public License for more details.
151da177e4SLinus Torvalds  *
161da177e4SLinus Torvalds  *   You should have received a copy of the GNU General Public License
171da177e4SLinus Torvalds  *   along with this program; if not, write to the Free Software
181da177e4SLinus Torvalds  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
191da177e4SLinus Torvalds  */
201da177e4SLinus Torvalds 
211da177e4SLinus Torvalds 
221da177e4SLinus Torvalds #ifndef __PMAC_H
231da177e4SLinus Torvalds #define __PMAC_H
241da177e4SLinus Torvalds 
251da177e4SLinus Torvalds #include <sound/control.h>
261da177e4SLinus Torvalds #include <sound/pcm.h>
271da177e4SLinus Torvalds #include "awacs.h"
281da177e4SLinus Torvalds 
291da177e4SLinus Torvalds #include <linux/adb.h>
301da177e4SLinus Torvalds #ifdef CONFIG_ADB_CUDA
311da177e4SLinus Torvalds #include <linux/cuda.h>
321da177e4SLinus Torvalds #endif
331da177e4SLinus Torvalds #ifdef CONFIG_ADB_PMU
341da177e4SLinus Torvalds #include <linux/pmu.h>
351da177e4SLinus Torvalds #endif
361da177e4SLinus Torvalds #include <linux/nvram.h>
371da177e4SLinus Torvalds #include <linux/tty.h>
381da177e4SLinus Torvalds #include <linux/vt_kern.h>
391da177e4SLinus Torvalds #include <asm/dbdma.h>
401da177e4SLinus Torvalds #include <asm/prom.h>
411da177e4SLinus Torvalds #include <asm/machdep.h>
421da177e4SLinus Torvalds 
431da177e4SLinus Torvalds /* maximum number of fragments */
441da177e4SLinus Torvalds #define PMAC_MAX_FRAGS		32
451da177e4SLinus Torvalds 
461da177e4SLinus Torvalds 
471da177e4SLinus Torvalds #define PMAC_SUPPORT_AUTOMUTE
481da177e4SLinus Torvalds 
491da177e4SLinus Torvalds /*
501da177e4SLinus Torvalds  * DBDMA space
511da177e4SLinus Torvalds  */
52*65b29f50STakashi Iwai struct pmac_dbdma {
537bbd8277SBenjamin Herrenschmidt 	dma_addr_t dma_base;
547bbd8277SBenjamin Herrenschmidt 	dma_addr_t addr;
551da177e4SLinus Torvalds 	struct dbdma_cmd __iomem *cmds;
561da177e4SLinus Torvalds 	void *space;
571da177e4SLinus Torvalds 	int size;
581da177e4SLinus Torvalds };
591da177e4SLinus Torvalds 
601da177e4SLinus Torvalds /*
611da177e4SLinus Torvalds  * playback/capture stream
621da177e4SLinus Torvalds  */
63*65b29f50STakashi Iwai struct pmac_stream {
641da177e4SLinus Torvalds 	int running;	/* boolean */
651da177e4SLinus Torvalds 
661da177e4SLinus Torvalds 	int stream;	/* PLAYBACK/CAPTURE */
671da177e4SLinus Torvalds 
681da177e4SLinus Torvalds 	int dma_size; /* in bytes */
691da177e4SLinus Torvalds 	int period_size; /* in bytes */
701da177e4SLinus Torvalds 	int buffer_size; /* in kbytes */
711da177e4SLinus Torvalds 	int nperiods, cur_period;
721da177e4SLinus Torvalds 
73*65b29f50STakashi Iwai 	struct pmac_dbdma cmd;
741da177e4SLinus Torvalds 	volatile struct dbdma_regs __iomem *dma;
751da177e4SLinus Torvalds 
76*65b29f50STakashi Iwai 	struct snd_pcm_substream *substream;
771da177e4SLinus Torvalds 
781da177e4SLinus Torvalds 	unsigned int cur_freqs;		/* currently available frequencies */
791da177e4SLinus Torvalds 	unsigned int cur_formats;	/* currently available formats */
801da177e4SLinus Torvalds };
811da177e4SLinus Torvalds 
821da177e4SLinus Torvalds 
831da177e4SLinus Torvalds /*
841da177e4SLinus Torvalds  */
851da177e4SLinus Torvalds 
861da177e4SLinus Torvalds enum snd_pmac_model {
871f7b49d0SBenjamin Herrenschmidt 	PMAC_AWACS, PMAC_SCREAMER, PMAC_BURGUNDY, PMAC_DACA, PMAC_TUMBLER,
881f7b49d0SBenjamin Herrenschmidt 	PMAC_SNAPPER, PMAC_TOONIE
891da177e4SLinus Torvalds };
901da177e4SLinus Torvalds 
911da177e4SLinus Torvalds struct snd_pmac {
92*65b29f50STakashi Iwai 	struct snd_card *card;
931da177e4SLinus Torvalds 
941da177e4SLinus Torvalds 	/* h/w info */
951da177e4SLinus Torvalds 	struct device_node *node;
967bbd8277SBenjamin Herrenschmidt 	struct pci_dev *pdev;
971da177e4SLinus Torvalds 	unsigned int revision;
981da177e4SLinus Torvalds 	unsigned int manufacturer;
991da177e4SLinus Torvalds 	unsigned int subframe;
1001da177e4SLinus Torvalds 	unsigned int device_id;
1011da177e4SLinus Torvalds 	enum snd_pmac_model model;
1021da177e4SLinus Torvalds 
1031da177e4SLinus Torvalds 	unsigned int has_iic : 1;
1041da177e4SLinus Torvalds 	unsigned int is_pbook_3400 : 1;
1051da177e4SLinus Torvalds 	unsigned int is_pbook_G3 : 1;
1067bbd8277SBenjamin Herrenschmidt 	unsigned int is_k2 : 1;
1071da177e4SLinus Torvalds 
1081da177e4SLinus Torvalds 	unsigned int can_byte_swap : 1;
1091da177e4SLinus Torvalds 	unsigned int can_duplex : 1;
1101da177e4SLinus Torvalds 	unsigned int can_capture : 1;
1111da177e4SLinus Torvalds 
1121da177e4SLinus Torvalds 	unsigned int auto_mute : 1;
1131da177e4SLinus Torvalds 	unsigned int initialized : 1;
1141da177e4SLinus Torvalds 	unsigned int feature_is_set : 1;
1151da177e4SLinus Torvalds 
1161da177e4SLinus Torvalds 	unsigned int of_requested;
1171da177e4SLinus Torvalds 
1181da177e4SLinus Torvalds 	int num_freqs;
1191da177e4SLinus Torvalds 	int *freq_table;
1201da177e4SLinus Torvalds 	unsigned int freqs_ok;		/* bit flags */
1211da177e4SLinus Torvalds 	unsigned int formats_ok;	/* pcm hwinfo */
1221da177e4SLinus Torvalds 	int active;
1231da177e4SLinus Torvalds 	int rate_index;
1241da177e4SLinus Torvalds 	int format;			/* current format */
1251da177e4SLinus Torvalds 
1261da177e4SLinus Torvalds 	spinlock_t reg_lock;
1271da177e4SLinus Torvalds 	volatile struct awacs_regs __iomem *awacs;
1281da177e4SLinus Torvalds 	int awacs_reg[8]; /* register cache */
1291da177e4SLinus Torvalds 	unsigned int hp_stat_mask;
1301da177e4SLinus Torvalds 
1311da177e4SLinus Torvalds 	unsigned char __iomem *latch_base;
1321da177e4SLinus Torvalds 	unsigned char __iomem *macio_base;
1331da177e4SLinus Torvalds 
134*65b29f50STakashi Iwai 	struct pmac_stream playback;
135*65b29f50STakashi Iwai 	struct pmac_stream capture;
1361da177e4SLinus Torvalds 
137*65b29f50STakashi Iwai 	struct pmac_dbdma extra_dma;
1381da177e4SLinus Torvalds 
1391da177e4SLinus Torvalds 	int irq, tx_irq, rx_irq;
1401da177e4SLinus Torvalds 
141*65b29f50STakashi Iwai 	struct snd_pcm *pcm;
1421da177e4SLinus Torvalds 
143*65b29f50STakashi Iwai 	struct pmac_beep *beep;
1441da177e4SLinus Torvalds 
1451da177e4SLinus Torvalds 	unsigned int control_mask;	/* control mask */
1461da177e4SLinus Torvalds 
1471da177e4SLinus Torvalds 	/* mixer stuffs */
1481da177e4SLinus Torvalds 	void *mixer_data;
149*65b29f50STakashi Iwai 	void (*mixer_free)(struct snd_pmac *);
150*65b29f50STakashi Iwai 	struct snd_kcontrol *master_sw_ctl;
151*65b29f50STakashi Iwai 	struct snd_kcontrol *speaker_sw_ctl;
152*65b29f50STakashi Iwai 	struct snd_kcontrol *drc_sw_ctl;	/* only used for tumbler -ReneR */
153*65b29f50STakashi Iwai 	struct snd_kcontrol *hp_detect_ctl;
154*65b29f50STakashi Iwai 	struct snd_kcontrol *lineout_sw_ctl;
1551da177e4SLinus Torvalds 
1561da177e4SLinus Torvalds 	/* lowlevel callbacks */
157*65b29f50STakashi Iwai 	void (*set_format)(struct snd_pmac *chip);
158*65b29f50STakashi Iwai 	void (*update_automute)(struct snd_pmac *chip, int do_notify);
159*65b29f50STakashi Iwai 	int (*detect_headphone)(struct snd_pmac *chip);
1608c870933SBenjamin Herrenschmidt #ifdef CONFIG_PM
161*65b29f50STakashi Iwai 	void (*suspend)(struct snd_pmac *chip);
162*65b29f50STakashi Iwai 	void (*resume)(struct snd_pmac *chip);
1631da177e4SLinus Torvalds #endif
1641da177e4SLinus Torvalds 
1651da177e4SLinus Torvalds };
1661da177e4SLinus Torvalds 
1671da177e4SLinus Torvalds 
1681da177e4SLinus Torvalds /* exported functions */
169*65b29f50STakashi Iwai int snd_pmac_new(struct snd_card *card, struct snd_pmac **chip_return);
170*65b29f50STakashi Iwai int snd_pmac_pcm_new(struct snd_pmac *chip);
171*65b29f50STakashi Iwai int snd_pmac_attach_beep(struct snd_pmac *chip);
172*65b29f50STakashi Iwai void snd_pmac_detach_beep(struct snd_pmac *chip);
173*65b29f50STakashi Iwai void snd_pmac_beep_stop(struct snd_pmac *chip);
174*65b29f50STakashi Iwai unsigned int snd_pmac_rate_index(struct snd_pmac *chip, struct pmac_stream *rec, unsigned int rate);
1751da177e4SLinus Torvalds 
176*65b29f50STakashi Iwai void snd_pmac_beep_dma_start(struct snd_pmac *chip, int bytes, unsigned long addr, int speed);
177*65b29f50STakashi Iwai void snd_pmac_beep_dma_stop(struct snd_pmac *chip);
1781da177e4SLinus Torvalds 
1791da177e4SLinus Torvalds /* initialize mixer */
180*65b29f50STakashi Iwai int snd_pmac_awacs_init(struct snd_pmac *chip);
181*65b29f50STakashi Iwai int snd_pmac_burgundy_init(struct snd_pmac *chip);
182*65b29f50STakashi Iwai int snd_pmac_daca_init(struct snd_pmac *chip);
183*65b29f50STakashi Iwai int snd_pmac_tumbler_init(struct snd_pmac *chip);
1841da177e4SLinus Torvalds int snd_pmac_tumbler_post_init(void);
185*65b29f50STakashi Iwai int snd_pmac_toonie_init(struct snd_pmac *chip);
1861da177e4SLinus Torvalds 
1871da177e4SLinus Torvalds /* i2c functions */
188*65b29f50STakashi Iwai struct pmac_keywest {
1891da177e4SLinus Torvalds 	int addr;
1901da177e4SLinus Torvalds 	struct i2c_client *client;
1911da177e4SLinus Torvalds 	int id;
192*65b29f50STakashi Iwai 	int (*init_client)(struct pmac_keywest *i2c);
1931da177e4SLinus Torvalds 	char *name;
194*65b29f50STakashi Iwai };
1951da177e4SLinus Torvalds 
196*65b29f50STakashi Iwai int snd_pmac_keywest_init(struct pmac_keywest *i2c);
197*65b29f50STakashi Iwai void snd_pmac_keywest_cleanup(struct pmac_keywest *i2c);
1981da177e4SLinus Torvalds 
1991da177e4SLinus Torvalds /* misc */
200*65b29f50STakashi Iwai int snd_pmac_boolean_stereo_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo);
201*65b29f50STakashi Iwai int snd_pmac_boolean_mono_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo);
2021da177e4SLinus Torvalds 
203*65b29f50STakashi Iwai int snd_pmac_add_automute(struct snd_pmac *chip);
2041da177e4SLinus Torvalds 
2051da177e4SLinus Torvalds #endif /* __PMAC_H */
206