Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef OXYGEN_H_INCLUDED
0003 #define OXYGEN_H_INCLUDED
0004 
0005 #include <linux/mutex.h>
0006 #include <linux/spinlock.h>
0007 #include <linux/wait.h>
0008 #include <linux/workqueue.h>
0009 #include "oxygen_regs.h"
0010 
0011 /* 1 << PCM_x == OXYGEN_CHANNEL_x */
0012 #define PCM_A       0
0013 #define PCM_B       1
0014 #define PCM_C       2
0015 #define PCM_SPDIF   3
0016 #define PCM_MULTICH 4
0017 #define PCM_AC97    5
0018 #define PCM_COUNT   6
0019 
0020 #define OXYGEN_MCLKS(f_single, f_double, f_quad) ((MCLK_##f_single << 0) | \
0021                           (MCLK_##f_double << 2) | \
0022                           (MCLK_##f_quad   << 4))
0023 
0024 #define OXYGEN_IO_SIZE  0x100
0025 
0026 #define OXYGEN_EEPROM_ID    0x434d  /* "CM" */
0027 
0028 /* model-specific configuration of outputs/inputs */
0029 #define PLAYBACK_0_TO_I2S   0x0001
0030      /* PLAYBACK_0_TO_AC97_0        not implemented */
0031 #define PLAYBACK_1_TO_SPDIF 0x0004
0032 #define PLAYBACK_2_TO_AC97_1    0x0008
0033 #define CAPTURE_0_FROM_I2S_1    0x0010
0034 #define CAPTURE_0_FROM_I2S_2    0x0020
0035      /* CAPTURE_0_FROM_AC97_0       not implemented */
0036 #define CAPTURE_1_FROM_SPDIF    0x0080
0037 #define CAPTURE_2_FROM_I2S_2    0x0100
0038 #define CAPTURE_2_FROM_AC97_1   0x0200
0039 #define CAPTURE_3_FROM_I2S_3    0x0400
0040 #define MIDI_OUTPUT     0x0800
0041 #define MIDI_INPUT      0x1000
0042 #define AC97_CD_INPUT       0x2000
0043 #define AC97_FMIC_SWITCH    0x4000
0044 
0045 enum {
0046     CONTROL_SPDIF_PCM,
0047     CONTROL_SPDIF_INPUT_BITS,
0048     CONTROL_MIC_CAPTURE_SWITCH,
0049     CONTROL_LINE_CAPTURE_SWITCH,
0050     CONTROL_CD_CAPTURE_SWITCH,
0051     CONTROL_AUX_CAPTURE_SWITCH,
0052     CONTROL_COUNT
0053 };
0054 
0055 #define OXYGEN_PCI_SUBID(sv, sd) \
0056     .vendor = PCI_VENDOR_ID_CMEDIA, \
0057     .device = 0x8788, \
0058     .subvendor = sv, \
0059     .subdevice = sd
0060 
0061 #define BROKEN_EEPROM_DRIVER_DATA ((unsigned long)-1)
0062 #define OXYGEN_PCI_SUBID_BROKEN_EEPROM \
0063     OXYGEN_PCI_SUBID(PCI_VENDOR_ID_CMEDIA, 0x8788), \
0064     .driver_data = BROKEN_EEPROM_DRIVER_DATA
0065 
0066 struct pci_dev;
0067 struct pci_device_id;
0068 struct snd_card;
0069 struct snd_pcm_substream;
0070 struct snd_pcm_hardware;
0071 struct snd_pcm_hw_params;
0072 struct snd_kcontrol_new;
0073 struct snd_rawmidi;
0074 struct snd_info_buffer;
0075 struct oxygen;
0076 
0077 struct oxygen_model {
0078     const char *shortname;
0079     const char *longname;
0080     const char *chip;
0081     void (*init)(struct oxygen *chip);
0082     int (*control_filter)(struct snd_kcontrol_new *template);
0083     int (*mixer_init)(struct oxygen *chip);
0084     void (*cleanup)(struct oxygen *chip);
0085     void (*suspend)(struct oxygen *chip);
0086     void (*resume)(struct oxygen *chip);
0087     void (*pcm_hardware_filter)(unsigned int channel,
0088                     struct snd_pcm_hardware *hardware);
0089     void (*set_dac_params)(struct oxygen *chip,
0090                    struct snd_pcm_hw_params *params);
0091     void (*set_adc_params)(struct oxygen *chip,
0092                    struct snd_pcm_hw_params *params);
0093     void (*update_dac_volume)(struct oxygen *chip);
0094     void (*update_dac_mute)(struct oxygen *chip);
0095     void (*update_center_lfe_mix)(struct oxygen *chip, bool mixed);
0096     unsigned int (*adjust_dac_routing)(struct oxygen *chip,
0097                        unsigned int play_routing);
0098     void (*gpio_changed)(struct oxygen *chip);
0099     void (*uart_input)(struct oxygen *chip);
0100     void (*ac97_switch)(struct oxygen *chip,
0101                 unsigned int reg, unsigned int mute);
0102     void (*dump_registers)(struct oxygen *chip,
0103                    struct snd_info_buffer *buffer);
0104     const unsigned int *dac_tlv;
0105     size_t model_data_size;
0106     unsigned int device_config;
0107     u8 dac_channels_pcm;
0108     u8 dac_channels_mixer;
0109     u8 dac_volume_min;
0110     u8 dac_volume_max;
0111     u8 misc_flags;
0112     u8 function_flags;
0113     u8 dac_mclks;
0114     u8 adc_mclks;
0115     u16 dac_i2s_format;
0116     u16 adc_i2s_format;
0117 };
0118 
0119 struct oxygen {
0120     unsigned long addr;
0121     spinlock_t reg_lock;
0122     struct mutex mutex;
0123     struct snd_card *card;
0124     struct pci_dev *pci;
0125     struct snd_rawmidi *midi;
0126     int irq;
0127     void *model_data;
0128     unsigned int interrupt_mask;
0129     u8 dac_volume[8];
0130     u8 dac_mute;
0131     u8 pcm_active;
0132     u8 pcm_running;
0133     u8 dac_routing;
0134     u8 spdif_playback_enable;
0135     u8 has_ac97_0;
0136     u8 has_ac97_1;
0137     u32 spdif_bits;
0138     u32 spdif_pcm_bits;
0139     struct snd_pcm_substream *streams[PCM_COUNT];
0140     struct snd_kcontrol *controls[CONTROL_COUNT];
0141     struct work_struct spdif_input_bits_work;
0142     struct work_struct gpio_work;
0143     wait_queue_head_t ac97_waitqueue;
0144     union {
0145         u8 _8[OXYGEN_IO_SIZE];
0146         __le16 _16[OXYGEN_IO_SIZE / 2];
0147         __le32 _32[OXYGEN_IO_SIZE / 4];
0148     } saved_registers;
0149     u16 saved_ac97_registers[2][0x40];
0150     unsigned int uart_input_count;
0151     u8 uart_input[32];
0152     struct oxygen_model model;
0153 };
0154 
0155 /* oxygen_lib.c */
0156 
0157 int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
0158              struct module *owner,
0159              const struct pci_device_id *ids,
0160              int (*get_model)(struct oxygen *chip,
0161                       const struct pci_device_id *id
0162                      )
0163             );
0164 #ifdef CONFIG_PM_SLEEP
0165 extern const struct dev_pm_ops oxygen_pci_pm;
0166 #endif
0167 void oxygen_pci_shutdown(struct pci_dev *pci);
0168 
0169 /* oxygen_mixer.c */
0170 
0171 int oxygen_mixer_init(struct oxygen *chip);
0172 void oxygen_update_dac_routing(struct oxygen *chip);
0173 void oxygen_update_spdif_source(struct oxygen *chip);
0174 
0175 /* oxygen_pcm.c */
0176 
0177 int oxygen_pcm_init(struct oxygen *chip);
0178 
0179 /* oxygen_io.c */
0180 
0181 u8 oxygen_read8(struct oxygen *chip, unsigned int reg);
0182 u16 oxygen_read16(struct oxygen *chip, unsigned int reg);
0183 u32 oxygen_read32(struct oxygen *chip, unsigned int reg);
0184 void oxygen_write8(struct oxygen *chip, unsigned int reg, u8 value);
0185 void oxygen_write16(struct oxygen *chip, unsigned int reg, u16 value);
0186 void oxygen_write32(struct oxygen *chip, unsigned int reg, u32 value);
0187 void oxygen_write8_masked(struct oxygen *chip, unsigned int reg,
0188               u8 value, u8 mask);
0189 void oxygen_write16_masked(struct oxygen *chip, unsigned int reg,
0190                u16 value, u16 mask);
0191 void oxygen_write32_masked(struct oxygen *chip, unsigned int reg,
0192                u32 value, u32 mask);
0193 
0194 u16 oxygen_read_ac97(struct oxygen *chip, unsigned int codec,
0195              unsigned int index);
0196 void oxygen_write_ac97(struct oxygen *chip, unsigned int codec,
0197                unsigned int index, u16 data);
0198 void oxygen_write_ac97_masked(struct oxygen *chip, unsigned int codec,
0199                   unsigned int index, u16 data, u16 mask);
0200 
0201 int oxygen_write_spi(struct oxygen *chip, u8 control, unsigned int data);
0202 void oxygen_write_i2c(struct oxygen *chip, u8 device, u8 map, u8 data);
0203 
0204 void oxygen_reset_uart(struct oxygen *chip);
0205 void oxygen_write_uart(struct oxygen *chip, u8 data);
0206 
0207 u16 oxygen_read_eeprom(struct oxygen *chip, unsigned int index);
0208 void oxygen_write_eeprom(struct oxygen *chip, unsigned int index, u16 value);
0209 
0210 static inline void oxygen_set_bits8(struct oxygen *chip,
0211                     unsigned int reg, u8 value)
0212 {
0213     oxygen_write8_masked(chip, reg, value, value);
0214 }
0215 
0216 static inline void oxygen_set_bits16(struct oxygen *chip,
0217                      unsigned int reg, u16 value)
0218 {
0219     oxygen_write16_masked(chip, reg, value, value);
0220 }
0221 
0222 static inline void oxygen_set_bits32(struct oxygen *chip,
0223                      unsigned int reg, u32 value)
0224 {
0225     oxygen_write32_masked(chip, reg, value, value);
0226 }
0227 
0228 static inline void oxygen_clear_bits8(struct oxygen *chip,
0229                       unsigned int reg, u8 value)
0230 {
0231     oxygen_write8_masked(chip, reg, 0, value);
0232 }
0233 
0234 static inline void oxygen_clear_bits16(struct oxygen *chip,
0235                        unsigned int reg, u16 value)
0236 {
0237     oxygen_write16_masked(chip, reg, 0, value);
0238 }
0239 
0240 static inline void oxygen_clear_bits32(struct oxygen *chip,
0241                        unsigned int reg, u32 value)
0242 {
0243     oxygen_write32_masked(chip, reg, 0, value);
0244 }
0245 
0246 static inline void oxygen_ac97_set_bits(struct oxygen *chip, unsigned int codec,
0247                     unsigned int index, u16 value)
0248 {
0249     oxygen_write_ac97_masked(chip, codec, index, value, value);
0250 }
0251 
0252 static inline void oxygen_ac97_clear_bits(struct oxygen *chip,
0253                       unsigned int codec,
0254                       unsigned int index, u16 value)
0255 {
0256     oxygen_write_ac97_masked(chip, codec, index, 0, value);
0257 }
0258 
0259 #endif