26 #include <linux/pci.h>
27 #include <linux/slab.h>
28 #include <linux/module.h>
29 #include <linux/bitops.h>
41 "{Brooktree,Bt879}}");
62 #define REG_INT_STAT 0x100
63 #define REG_INT_MASK 0x104
64 #define REG_GPIO_DMA_CTL 0x10c
65 #define REG_PACKET_LEN 0x110
66 #define REG_RISC_STRT_ADD 0x114
67 #define REG_RISC_COUNT 0x120
70 #define INT_OFLOW (1 << 3)
71 #define INT_RISCI (1 << 11)
72 #define INT_FBUS (1 << 12)
73 #define INT_FTRGT (1 << 13)
74 #define INT_FDSR (1 << 14)
75 #define INT_PPERR (1 << 15)
76 #define INT_RIPERR (1 << 16)
77 #define INT_PABORT (1 << 17)
78 #define INT_OCERR (1 << 18)
79 #define INT_SCERR (1 << 19)
80 #define INT_RISC_EN (1 << 27)
81 #define INT_RISCS_SHIFT 28
84 #define CTL_FIFO_ENABLE (1 << 0)
85 #define CTL_RISC_ENABLE (1 << 1)
86 #define CTL_PKTP_4 (0 << 2)
87 #define CTL_PKTP_8 (1 << 2)
88 #define CTL_PKTP_16 (2 << 2)
89 #define CTL_ACAP_EN (1 << 4)
90 #define CTL_DA_APP (1 << 5)
91 #define CTL_DA_IOM_AFE (0 << 6)
92 #define CTL_DA_IOM_DA (1 << 6)
93 #define CTL_DA_SDR_SHIFT 8
94 #define CTL_DA_SDR_MASK (0xf<< 8)
95 #define CTL_DA_LMT (1 << 12)
96 #define CTL_DA_ES2 (1 << 13)
97 #define CTL_DA_SBR (1 << 14)
98 #define CTL_DA_DPM (1 << 15)
99 #define CTL_DA_LRD_SHIFT 16
100 #define CTL_DA_MLB (1 << 21)
101 #define CTL_DA_LRI (1 << 22)
102 #define CTL_DA_SCE (1 << 23)
103 #define CTL_A_SEL_STV (0 << 24)
104 #define CTL_A_SEL_SFM (1 << 24)
105 #define CTL_A_SEL_SML (2 << 24)
106 #define CTL_A_SEL_SMXC (3 << 24)
107 #define CTL_A_SEL_SHIFT 24
108 #define CTL_A_SEL_MASK (3 << 24)
109 #define CTL_A_PWRDN (1 << 26)
110 #define CTL_A_G2X (1 << 27)
111 #define CTL_A_GAIN_SHIFT 28
112 #define CTL_A_GAIN_MASK (0xf<<28)
115 #define RISC_WRITE (0x1 << 28)
116 #define RISC_WRITEC (0x5 << 28)
117 #define RISC_SKIP (0x2 << 28)
118 #define RISC_JUMP (0x7 << 28)
119 #define RISC_SYNC (0x8 << 28)
122 #define RISC_BYTES_ENABLE (0xf << 12)
123 #define RISC_RESYNC ( 1 << 15)
124 #define RISC_SET_STATUS_SHIFT 16
125 #define RISC_RESET_STATUS_SHIFT 20
126 #define RISC_IRQ ( 1 << 24)
127 #define RISC_EOL ( 1 << 26)
128 #define RISC_SOL ( 1 << 27)
131 #define RISC_SYNC_FM1 0x6
132 #define RISC_SYNC_VRO 0xc
134 #define ANALOG_CLOCK 1792000
135 #ifdef CONFIG_SND_BT87X_OVERCLOCK
136 #define CLOCK_DIV_MIN 1
138 #define CLOCK_DIV_MIN 4
140 #define CLOCK_DIV_MAX 15
142 #define ERROR_INTERRUPTS (INT_FBUS | INT_FTRGT | INT_PPERR | \
143 INT_RIPERR | INT_PABORT | INT_OCERR)
144 #define MY_INTERRUPTS (INT_RISCI | ERROR_INTERRUPTS)
147 #define MAX_RISC_SIZE ((1 + 255 + (PAGE_ALIGN(255 * 4092) / PAGE_SIZE - 1) + 1 + 1) * 8)
228 unsigned int periods,
unsigned int period_bytes)
242 for (i = 0; i < periods; ++
i) {
254 if (rest == period_bytes) {
263 addr = snd_pcm_sgbuf_get_addr(substream, offset);
274 chip->
lines = periods;
278 static void snd_bt87x_free_risc(
struct snd_bt87x *chip)
286 static void snd_bt87x_pci_error(
struct snd_bt87x *chip,
unsigned int status)
305 snd_printk(
KERN_ERR "This is an error *observed by*, not *generated by*, this card.\n");
316 unsigned int status, irq_status;
330 snd_bt87x_pci_error(chip, irq_status);
333 int current_block, irq_block;
340 if (current_block != irq_block)
358 .buffer_bytes_max = 255 * 4092,
359 .period_bytes_min = 32,
360 .period_bytes_max = 4092,
377 .buffer_bytes_max = 255 * 4092,
378 .period_bytes_min = 32,
379 .period_bytes_max = 4092,
387 runtime->
hw = snd_bt87x_digital_hw;
389 runtime->
hw.rate_min = chip->
board.dig_rate;
390 runtime->
hw.rate_max = chip->
board.dig_rate;
404 .rats = &analog_clock
408 runtime->
hw = snd_bt87x_analog_hw;
423 err = snd_bt87x_set_digital_hw(chip, runtime);
425 err = snd_bt87x_set_analog_hw(chip, runtime);
467 return snd_bt87x_create_risc(chip, substream,
469 params_period_bytes(hw_params));
476 snd_bt87x_free_risc(chip);
498 static int snd_bt87x_start(
struct snd_bt87x *chip)
512 static int snd_bt87x_stop(
struct snd_bt87x *chip)
529 return snd_bt87x_start(chip);
531 return snd_bt87x_stop(chip);
546 .open = snd_bt87x_pcm_open,
547 .close = snd_bt87x_close,
549 .hw_params = snd_bt87x_hw_params,
550 .hw_free = snd_bt87x_hw_free,
551 .prepare = snd_bt87x_prepare,
552 .trigger = snd_bt87x_trigger,
553 .pointer = snd_bt87x_pointer,
557 static int snd_bt87x_capture_volume_info(
struct snd_kcontrol *kcontrol,
567 static int snd_bt87x_capture_volume_get(
struct snd_kcontrol *kcontrol,
576 static int snd_bt87x_capture_volume_put(
struct snd_kcontrol *kcontrol,
595 .name =
"Capture Volume",
596 .info = snd_bt87x_capture_volume_info,
597 .get = snd_bt87x_capture_volume_get,
598 .put = snd_bt87x_capture_volume_put,
601 #define snd_bt87x_capture_boost_info snd_ctl_boolean_mono_info
603 static int snd_bt87x_capture_boost_get(
struct snd_kcontrol *kcontrol,
612 static int snd_bt87x_capture_boost_put(
struct snd_kcontrol *kcontrol,
631 .name =
"Capture Boost",
633 .get = snd_bt87x_capture_boost_get,
634 .put = snd_bt87x_capture_boost_put,
637 static int snd_bt87x_capture_source_info(
struct snd_kcontrol *kcontrol,
640 static const char *
const texts[3] = {
"TV Tuner",
"FM",
"Mic/Line"};
645 static int snd_bt87x_capture_source_get(
struct snd_kcontrol *kcontrol,
654 static int snd_bt87x_capture_source_put(
struct snd_kcontrol *kcontrol,
673 .name =
"Capture Source",
674 .info = snd_bt87x_capture_source_info,
675 .get = snd_bt87x_capture_source_get,
676 .put = snd_bt87x_capture_source_put,
679 static int snd_bt87x_free(
struct snd_bt87x *chip)
682 snd_bt87x_stop(chip);
696 return snd_bt87x_free(chip);
714 ALIGN(255 * 4092, 1024));
724 .dev_free = snd_bt87x_dev_free
763 KBUILD_MODNAME, chip);
781 snd_bt87x_free(chip);
785 #define BT_DEVICE(chip, subvend, subdev, id) \
786 { .vendor = PCI_VENDOR_ID_BROOKTREE, \
788 .subvendor = subvend, .subdevice = subdev, \
789 .driver_data = SND_BT87X_BOARD_ ## id }
860 "if it works, the correct digital_rate option to "
875 err = snd_bt87x_detect_card(pci);
893 err = snd_bt87x_create(card, pci, &chip);
899 if (!chip->
board.no_digital) {
900 if (digital_rate[dev] > 0)
901 chip->
board.dig_rate = digital_rate[
dev];
909 if (!chip->
board.no_analog) {
914 &snd_bt87x_capture_volume, chip));
918 &snd_bt87x_capture_boost, chip));
922 &snd_bt87x_capture_source, chip));
927 "(rate %d Hz)\n", dev, boardid,
928 chip->
board.no_analog ?
"no " :
"",
929 chip->
board.no_digital ?
"no " :
"", chip->
board.dig_rate);
942 pci_set_drvdata(pci, card);
954 pci_set_drvdata(pci,
NULL);
966 .name = KBUILD_MODNAME,
967 .id_table = snd_bt87x_ids,
968 .probe = snd_bt87x_probe,