oxygen.h 6.0 KB
Newer Older
C
Clemens Ladisch 已提交
1 2 3 4 5
#ifndef OXYGEN_H_INCLUDED
#define OXYGEN_H_INCLUDED

#include <linux/mutex.h>
#include <linux/spinlock.h>
6
#include <linux/wait.h>
C
Clemens Ladisch 已提交
7 8 9 10 11 12 13 14 15 16 17 18
#include <linux/workqueue.h>
#include "oxygen_regs.h"

/* 1 << PCM_x == OXYGEN_CHANNEL_x */
#define PCM_A		0
#define PCM_B		1
#define PCM_C		2
#define PCM_SPDIF	3
#define PCM_MULTICH	4
#define PCM_AC97	5
#define PCM_COUNT	6

19 20
#define OXYGEN_IO_SIZE	0x100

21 22 23 24 25 26 27 28 29 30
/* model-specific configuration of outputs/inputs */
#define PLAYBACK_0_TO_I2S	0x001
#define PLAYBACK_1_TO_SPDIF	0x004
#define PLAYBACK_2_TO_AC97_1	0x008
#define CAPTURE_0_FROM_I2S_1	0x010
#define CAPTURE_0_FROM_I2S_2	0x020
#define CAPTURE_1_FROM_SPDIF	0x080
#define CAPTURE_2_FROM_I2S_2	0x100
#define CAPTURE_2_FROM_AC97_1	0x200

31 32 33
enum {
	CONTROL_SPDIF_PCM,
	CONTROL_SPDIF_INPUT_BITS,
34 35 36 37
	CONTROL_MIC_CAPTURE_SWITCH,
	CONTROL_LINE_CAPTURE_SWITCH,
	CONTROL_CD_CAPTURE_SWITCH,
	CONTROL_AUX_CAPTURE_SWITCH,
38 39 40
	CONTROL_COUNT
};

C
Clemens Ladisch 已提交
41 42 43 44 45 46 47 48 49
#define OXYGEN_PCI_SUBID(sv, sd) \
	.vendor = PCI_VENDOR_ID_CMEDIA, \
	.device = 0x8788, \
	.subvendor = sv, \
	.subdevice = sd

struct pci_dev;
struct snd_card;
struct snd_pcm_substream;
50
struct snd_pcm_hardware;
C
Clemens Ladisch 已提交
51
struct snd_pcm_hw_params;
52
struct snd_kcontrol_new;
C
Clemens Ladisch 已提交
53
struct snd_rawmidi;
54
struct oxygen;
C
Clemens Ladisch 已提交
55 56 57 58 59 60

struct oxygen_model {
	const char *shortname;
	const char *longname;
	const char *chip;
	struct module *owner;
61
	int (*probe)(struct oxygen *chip, unsigned long driver_data);
C
Clemens Ladisch 已提交
62
	void (*init)(struct oxygen *chip);
63
	int (*control_filter)(struct snd_kcontrol_new *template);
C
Clemens Ladisch 已提交
64 65
	int (*mixer_init)(struct oxygen *chip);
	void (*cleanup)(struct oxygen *chip);
C
Clemens Ladisch 已提交
66 67
	void (*suspend)(struct oxygen *chip);
	void (*resume)(struct oxygen *chip);
68 69
	void (*pcm_hardware_filter)(unsigned int channel,
				    struct snd_pcm_hardware *hardware);
C
Clemens Ladisch 已提交
70 71 72 73 74 75
	void (*set_dac_params)(struct oxygen *chip,
			       struct snd_pcm_hw_params *params);
	void (*set_adc_params)(struct oxygen *chip,
			       struct snd_pcm_hw_params *params);
	void (*update_dac_volume)(struct oxygen *chip);
	void (*update_dac_mute)(struct oxygen *chip);
76
	void (*gpio_changed)(struct oxygen *chip);
77 78
	void (*ac97_switch)(struct oxygen *chip,
			    unsigned int reg, unsigned int mute);
79
	const unsigned int *dac_tlv;
80
	size_t model_data_size;
81
	unsigned int device_config;
82
	u8 dac_channels;
83 84
	u8 dac_volume_min;
	u8 dac_volume_max;
85
	u8 misc_flags;
86
	u8 function_flags;
87 88
	u16 dac_i2s_format;
	u16 adc_i2s_format;
C
Clemens Ladisch 已提交
89 90
};

91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
struct oxygen {
	unsigned long addr;
	spinlock_t reg_lock;
	struct mutex mutex;
	struct snd_card *card;
	struct pci_dev *pci;
	struct snd_rawmidi *midi;
	int irq;
	void *model_data;
	unsigned int interrupt_mask;
	u8 dac_volume[8];
	u8 dac_mute;
	u8 pcm_active;
	u8 pcm_running;
	u8 dac_routing;
	u8 spdif_playback_enable;
	u8 revision;
	u8 has_ac97_0;
	u8 has_ac97_1;
	u32 spdif_bits;
	u32 spdif_pcm_bits;
	struct snd_pcm_substream *streams[PCM_COUNT];
	struct snd_kcontrol *controls[CONTROL_COUNT];
	struct work_struct spdif_input_bits_work;
	struct work_struct gpio_work;
	wait_queue_head_t ac97_waitqueue;
	union {
		u8 _8[OXYGEN_IO_SIZE];
		__le16 _16[OXYGEN_IO_SIZE / 2];
		__le32 _32[OXYGEN_IO_SIZE / 4];
	} saved_registers;
	u16 saved_ac97_registers[2][0x40];
	struct oxygen_model model;
};

C
Clemens Ladisch 已提交
126 127
/* oxygen_lib.c */

128
int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
129 130
		     const struct oxygen_model *model,
		     unsigned long driver_data);
C
Clemens Ladisch 已提交
131
void oxygen_pci_remove(struct pci_dev *pci);
C
Clemens Ladisch 已提交
132 133 134 135
#ifdef CONFIG_PM
int oxygen_pci_suspend(struct pci_dev *pci, pm_message_t state);
int oxygen_pci_resume(struct pci_dev *pci);
#endif
C
Clemens Ladisch 已提交
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169

/* oxygen_mixer.c */

int oxygen_mixer_init(struct oxygen *chip);
void oxygen_update_dac_routing(struct oxygen *chip);
void oxygen_update_spdif_source(struct oxygen *chip);

/* oxygen_pcm.c */

int oxygen_pcm_init(struct oxygen *chip);

/* oxygen_io.c */

u8 oxygen_read8(struct oxygen *chip, unsigned int reg);
u16 oxygen_read16(struct oxygen *chip, unsigned int reg);
u32 oxygen_read32(struct oxygen *chip, unsigned int reg);
void oxygen_write8(struct oxygen *chip, unsigned int reg, u8 value);
void oxygen_write16(struct oxygen *chip, unsigned int reg, u16 value);
void oxygen_write32(struct oxygen *chip, unsigned int reg, u32 value);
void oxygen_write8_masked(struct oxygen *chip, unsigned int reg,
			  u8 value, u8 mask);
void oxygen_write16_masked(struct oxygen *chip, unsigned int reg,
			   u16 value, u16 mask);
void oxygen_write32_masked(struct oxygen *chip, unsigned int reg,
			   u32 value, u32 mask);

u16 oxygen_read_ac97(struct oxygen *chip, unsigned int codec,
		     unsigned int index);
void oxygen_write_ac97(struct oxygen *chip, unsigned int codec,
		       unsigned int index, u16 data);
void oxygen_write_ac97_masked(struct oxygen *chip, unsigned int codec,
			      unsigned int index, u16 data, u16 mask);

void oxygen_write_spi(struct oxygen *chip, u8 control, unsigned int data);
C
Clemens Ladisch 已提交
170
void oxygen_write_i2c(struct oxygen *chip, u8 device, u8 map, u8 data);
C
Clemens Ladisch 已提交
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221

static inline void oxygen_set_bits8(struct oxygen *chip,
				    unsigned int reg, u8 value)
{
	oxygen_write8_masked(chip, reg, value, value);
}

static inline void oxygen_set_bits16(struct oxygen *chip,
				     unsigned int reg, u16 value)
{
	oxygen_write16_masked(chip, reg, value, value);
}

static inline void oxygen_set_bits32(struct oxygen *chip,
				     unsigned int reg, u32 value)
{
	oxygen_write32_masked(chip, reg, value, value);
}

static inline void oxygen_clear_bits8(struct oxygen *chip,
				      unsigned int reg, u8 value)
{
	oxygen_write8_masked(chip, reg, 0, value);
}

static inline void oxygen_clear_bits16(struct oxygen *chip,
				       unsigned int reg, u16 value)
{
	oxygen_write16_masked(chip, reg, 0, value);
}

static inline void oxygen_clear_bits32(struct oxygen *chip,
				       unsigned int reg, u32 value)
{
	oxygen_write32_masked(chip, reg, 0, value);
}

static inline void oxygen_ac97_set_bits(struct oxygen *chip, unsigned int codec,
					unsigned int index, u16 value)
{
	oxygen_write_ac97_masked(chip, codec, index, value, value);
}

static inline void oxygen_ac97_clear_bits(struct oxygen *chip,
					  unsigned int codec,
					  unsigned int index, u16 value)
{
	oxygen_write_ac97_masked(chip, codec, index, 0, value);
}

#endif