23 #include <linux/pci.h>
24 #include <linux/slab.h>
25 #include <linux/module.h>
39 #define DRIVER "oxygen"
41 static inline int oxygen_uart_input_ready(
struct oxygen *
chip)
46 static void oxygen_read_uart(
struct oxygen *
chip)
48 if (
unlikely(!oxygen_uart_input_ready(chip))) {
60 }
while (oxygen_uart_input_ready(chip));
61 if (chip->
model.uart_input)
62 chip->
model.uart_input(chip);
99 if ((elapsed_streams & (1 << i)) && chip->
streams[i])
121 oxygen_read_uart(chip);
167 reg &= ~OXYGEN_SPDIF_IN_CLOCK_MASK;
191 static void oxygen_gpio_changed(
struct work_struct *work)
195 if (chip->
model.gpio_changed)
196 chip->
model.gpio_changed(chip);
199 #ifdef CONFIG_PROC_FS
210 default: i =
'?';
break;
212 snd_iprintf(buffer,
"CMI878%c:\n", i);
214 snd_iprintf(buffer,
"%02x:", i);
215 for (j = 0; j < 0x10; ++
j)
216 snd_iprintf(buffer,
" %02x",
oxygen_read8(chip, i + j));
217 snd_iprintf(buffer,
"\n");
222 snd_iprintf(buffer,
"\nAC97:\n");
223 for (i = 0; i < 0x80; i += 0x10) {
224 snd_iprintf(buffer,
"%02x:", i);
225 for (j = 0; j < 0x10; j += 2)
226 snd_iprintf(buffer,
" %04x",
228 snd_iprintf(buffer,
"\n");
232 snd_iprintf(buffer,
"\nAC97 2:\n");
233 for (i = 0; i < 0x80; i += 0x10) {
234 snd_iprintf(buffer,
"%02x:", i);
235 for (j = 0; j < 0x10; j += 2)
236 snd_iprintf(buffer,
" %04x",
238 snd_iprintf(buffer,
"\n");
242 if (chip->
model.dump_registers)
243 chip->
model.dump_registers(chip, buffer);
250 if (!snd_card_proc_new(chip->
card,
"oxygen", &entry))
251 snd_info_set_text_ops(entry, chip, oxygen_proc_read);
254 #define oxygen_proc_init(chip)
281 for (; ids->
vendor; ++ids)
288 static void oxygen_restore_eeprom(
struct oxygen *chip,
295 (eeprom_id != 0xffff || id->
subdevice != 0x8788)) {
320 static void configure_pcie_bridge(
struct pci_dev *pci)
322 enum { PEX811X, PI7C9X110 };
324 {
PCI_VDEVICE(PLX, 0x8111), .driver_data = PEX811X },
325 {
PCI_VDEVICE(PLX, 0x8112), .driver_data = PEX811X },
326 {
PCI_DEVICE(0x12d8, 0xe110), .driver_data = PI7C9X110 },
333 if (!pci->
bus || !pci->
bus->self)
335 bridge = pci->
bus->self;
343 pci_read_config_dword(bridge, 0x48, &tmp);
346 pci_write_config_dword(bridge, 0x48, tmp);
348 pci_write_config_dword(bridge, 0x84, 0x0c);
349 pci_read_config_dword(bridge, 0x88, &tmp);
352 pci_write_config_dword(bridge, 0x88, tmp);
356 pci_read_config_dword(bridge, 0x40, &tmp);
358 pci_write_config_dword(bridge, 0x40, tmp);
363 static void oxygen_init(
struct oxygen *chip)
368 for (i = 0; i < 8; ++
i)
386 chip->
model.function_flags,
398 chip->
model.misc_flags,
414 chip->
model.dac_i2s_format |
422 chip->
model.adc_i2s_format |
435 chip->
model.adc_i2s_format |
555 oxygen_ac97_set_bits(chip, 1, 0x6a, 0x0040);
559 static void oxygen_shutdown(
struct oxygen *chip)
573 oxygen_shutdown(chip);
578 chip->
model.cleanup(chip);
588 int (*get_model)(
struct oxygen *chip,
609 oxygen_spdif_input_bits_changed);
627 goto err_pci_regions;
631 pci_id = oxygen_search_pci_id(chip, ids);
634 goto err_pci_regions;
636 oxygen_restore_eeprom(chip, pci_id);
637 err = get_model(chip, pci_id);
639 goto err_pci_regions;
641 if (chip->
model.model_data_size) {
646 goto err_pci_regions;
654 configure_pcie_bridge(pci);
656 chip->
model.init(chip);
659 KBUILD_MODNAME, chip);
690 info_flags, -1, &chip->
midi);
709 pci_set_drvdata(pci, card);
725 pci_set_drvdata(pci,
NULL);
729 #ifdef CONFIG_PM_SLEEP
730 static int oxygen_pci_suspend(
struct device *
dev)
735 unsigned int i, saved_interrupt_mask;
741 snd_pcm_suspend(chip->
streams[i]);
743 if (chip->
model.suspend)
744 chip->
model.suspend(chip);
764 static const u32 registers_to_restore[OXYGEN_IO_SIZE / 32] = {
765 0xffffffff, 0x00ff077f, 0x00011d08, 0x007f00ff,
766 0x00300000, 0x00000fe4, 0x0ff7001f, 0x00000000
768 static const u32 ac97_registers_to_restore[2][0x40 / 32] = {
769 { 0x18284fa2, 0x03060000 },
770 { 0x00007fa6, 0x00200000 }
773 static inline int is_bit_set(
const u32 *
bitmap,
unsigned int bit)
775 return bitmap[bit / 32] & (1 << (bit & 31));
778 static void oxygen_restore_ac97(
struct oxygen *chip,
unsigned int codec)
784 for (i = 1; i < 0x40; ++
i)
785 if (is_bit_set(ac97_registers_to_restore[codec], i))
790 static int oxygen_pci_resume(
struct device *dev)
809 if (is_bit_set(registers_to_restore, i))
812 oxygen_restore_ac97(chip, 0);
814 oxygen_restore_ac97(chip, 1);
816 if (chip->
model.resume)
817 chip->
model.resume(chip);
831 struct snd_card *card = pci_get_drvdata(pci);
834 oxygen_shutdown(chip);
835 chip->
model.cleanup(chip);