blob: b6f454130463877d376d06d2f72f5d8c036e426e [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Driver for PowerMac onboard soundchips
4 * Copyright (c) 2001 by Takashi Iwai <tiwai@suse.de>
5 * based on dmasound.c.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7
8
9#ifndef __PMAC_H
10#define __PMAC_H
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#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>
Christophe Leroye6d03ac2021-09-03 11:18:40 +000029#include <asm/pmac_feature.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31/* maximum number of fragments */
32#define PMAC_MAX_FRAGS 32
33
34
35#define PMAC_SUPPORT_AUTOMUTE
36
37/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 * DBDMA space
39 */
Takashi Iwai65b29f52005-11-17 15:09:46 +010040struct pmac_dbdma {
Benjamin Herrenschmidt7bbd8272005-04-16 15:24:32 -070041 dma_addr_t dma_base;
42 dma_addr_t addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 struct dbdma_cmd __iomem *cmds;
44 void *space;
45 int size;
46};
47
48/*
49 * playback/capture stream
50 */
Takashi Iwai65b29f52005-11-17 15:09:46 +010051struct pmac_stream {
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 int running; /* boolean */
53
54 int stream; /* PLAYBACK/CAPTURE */
55
56 int dma_size; /* in bytes */
57 int period_size; /* in bytes */
58 int buffer_size; /* in kbytes */
59 int nperiods, cur_period;
60
Takashi Iwai65b29f52005-11-17 15:09:46 +010061 struct pmac_dbdma cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 volatile struct dbdma_regs __iomem *dma;
63
Takashi Iwai65b29f52005-11-17 15:09:46 +010064 struct snd_pcm_substream *substream;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66 unsigned int cur_freqs; /* currently available frequencies */
67 unsigned int cur_formats; /* currently available formats */
68};
69
70
71/*
72 */
73
74enum snd_pmac_model {
Benjamin Herrenschmidt1f7b49d2005-05-01 08:58:43 -070075 PMAC_AWACS, PMAC_SCREAMER, PMAC_BURGUNDY, PMAC_DACA, PMAC_TUMBLER,
Johannes Berg55c385a2006-06-21 15:43:44 +020076 PMAC_SNAPPER
Linus Torvalds1da177e2005-04-16 15:20:36 -070077};
78
79struct snd_pmac {
Takashi Iwai65b29f52005-11-17 15:09:46 +010080 struct snd_card *card;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82 /* h/w info */
83 struct device_node *node;
Benjamin Herrenschmidt7bbd8272005-04-16 15:24:32 -070084 struct pci_dev *pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 unsigned int revision;
86 unsigned int manufacturer;
87 unsigned int subframe;
88 unsigned int device_id;
89 enum snd_pmac_model model;
90
91 unsigned int has_iic : 1;
92 unsigned int is_pbook_3400 : 1;
93 unsigned int is_pbook_G3 : 1;
Benjamin Herrenschmidt7bbd8272005-04-16 15:24:32 -070094 unsigned int is_k2 : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96 unsigned int can_byte_swap : 1;
97 unsigned int can_duplex : 1;
98 unsigned int can_capture : 1;
99
100 unsigned int auto_mute : 1;
101 unsigned int initialized : 1;
102 unsigned int feature_is_set : 1;
103
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100104 unsigned int requested;
105 struct resource rsrc[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107 int num_freqs;
Takashi Iwai6e9ef322020-01-05 15:47:32 +0100108 const int *freq_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 unsigned int freqs_ok; /* bit flags */
110 unsigned int formats_ok; /* pcm hwinfo */
111 int active;
112 int rate_index;
113 int format; /* current format */
114
115 spinlock_t reg_lock;
116 volatile struct awacs_regs __iomem *awacs;
117 int awacs_reg[8]; /* register cache */
118 unsigned int hp_stat_mask;
119
120 unsigned char __iomem *latch_base;
121 unsigned char __iomem *macio_base;
122
Takashi Iwai65b29f52005-11-17 15:09:46 +0100123 struct pmac_stream playback;
124 struct pmac_stream capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Takashi Iwai65b29f52005-11-17 15:09:46 +0100126 struct pmac_dbdma extra_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128 int irq, tx_irq, rx_irq;
129
Takashi Iwai65b29f52005-11-17 15:09:46 +0100130 struct snd_pcm *pcm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Takashi Iwai65b29f52005-11-17 15:09:46 +0100132 struct pmac_beep *beep;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134 unsigned int control_mask; /* control mask */
135
136 /* mixer stuffs */
137 void *mixer_data;
Takashi Iwai65b29f52005-11-17 15:09:46 +0100138 void (*mixer_free)(struct snd_pmac *);
139 struct snd_kcontrol *master_sw_ctl;
140 struct snd_kcontrol *speaker_sw_ctl;
141 struct snd_kcontrol *drc_sw_ctl; /* only used for tumbler -ReneR */
142 struct snd_kcontrol *hp_detect_ctl;
143 struct snd_kcontrol *lineout_sw_ctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145 /* lowlevel callbacks */
Takashi Iwai65b29f52005-11-17 15:09:46 +0100146 void (*set_format)(struct snd_pmac *chip);
147 void (*update_automute)(struct snd_pmac *chip, int do_notify);
148 int (*detect_headphone)(struct snd_pmac *chip);
Benjamin Herrenschmidt8c870932005-06-27 14:36:34 -0700149#ifdef CONFIG_PM
Takashi Iwai65b29f52005-11-17 15:09:46 +0100150 void (*suspend)(struct snd_pmac *chip);
151 void (*resume)(struct snd_pmac *chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152#endif
153
154};
155
156
157/* exported functions */
Takashi Iwai65b29f52005-11-17 15:09:46 +0100158int snd_pmac_new(struct snd_card *card, struct snd_pmac **chip_return);
159int snd_pmac_pcm_new(struct snd_pmac *chip);
160int snd_pmac_attach_beep(struct snd_pmac *chip);
161void snd_pmac_detach_beep(struct snd_pmac *chip);
162void snd_pmac_beep_stop(struct snd_pmac *chip);
163unsigned int snd_pmac_rate_index(struct snd_pmac *chip, struct pmac_stream *rec, unsigned int rate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
Takashi Iwai65b29f52005-11-17 15:09:46 +0100165void snd_pmac_beep_dma_start(struct snd_pmac *chip, int bytes, unsigned long addr, int speed);
166void snd_pmac_beep_dma_stop(struct snd_pmac *chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
Takashi Iwai5e12bea2005-11-17 17:17:08 +0100168#ifdef CONFIG_PM
169void snd_pmac_suspend(struct snd_pmac *chip);
170void snd_pmac_resume(struct snd_pmac *chip);
171#endif
172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173/* initialize mixer */
Takashi Iwai65b29f52005-11-17 15:09:46 +0100174int snd_pmac_awacs_init(struct snd_pmac *chip);
175int snd_pmac_burgundy_init(struct snd_pmac *chip);
176int snd_pmac_daca_init(struct snd_pmac *chip);
177int snd_pmac_tumbler_init(struct snd_pmac *chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178int snd_pmac_tumbler_post_init(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180/* i2c functions */
Takashi Iwai65b29f52005-11-17 15:09:46 +0100181struct pmac_keywest {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 int addr;
183 struct i2c_client *client;
184 int id;
Takashi Iwai65b29f52005-11-17 15:09:46 +0100185 int (*init_client)(struct pmac_keywest *i2c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 char *name;
Takashi Iwai65b29f52005-11-17 15:09:46 +0100187};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
Takashi Iwai65b29f52005-11-17 15:09:46 +0100189int snd_pmac_keywest_init(struct pmac_keywest *i2c);
190void snd_pmac_keywest_cleanup(struct pmac_keywest *i2c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192/* misc */
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200193#define snd_pmac_boolean_stereo_info snd_ctl_boolean_stereo_info
194#define snd_pmac_boolean_mono_info snd_ctl_boolean_mono_info
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
Takashi Iwai65b29f52005-11-17 15:09:46 +0100196int snd_pmac_add_automute(struct snd_pmac *chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198#endif /* __PMAC_H */