26 #include <linux/pci.h>
27 #include <linux/slab.h>
28 #include <linux/module.h>
39 #ifdef CONFIG_SND_FM801_TEA575X_BOOL
47 "{Genius,SoundMaker Live 5.1}}");
70 MODULE_PARM_DESC(tea575x_tuner,
"TEA575x tuner access method (0 = auto, 1 = SF256-PCS, 2=SF256-PCP, 3=SF64-PCR, 8=disable, +16=tuner-only).");
75 #define TUNER_DISABLED (1<<3)
76 #define TUNER_ONLY (1<<4)
77 #define TUNER_TYPE_MASK (~TUNER_ONLY & 0xFFFF)
83 #define FM801_REG(chip, reg) (chip->port + FM801_##reg)
85 #define FM801_PCM_VOL 0x00
86 #define FM801_FM_VOL 0x02
87 #define FM801_I2S_VOL 0x04
88 #define FM801_REC_SRC 0x06
89 #define FM801_PLY_CTRL 0x08
90 #define FM801_PLY_COUNT 0x0a
91 #define FM801_PLY_BUF1 0x0c
92 #define FM801_PLY_BUF2 0x10
93 #define FM801_CAP_CTRL 0x14
94 #define FM801_CAP_COUNT 0x16
95 #define FM801_CAP_BUF1 0x18
96 #define FM801_CAP_BUF2 0x1c
97 #define FM801_CODEC_CTRL 0x22
98 #define FM801_I2S_MODE 0x24
99 #define FM801_VOLUME 0x26
100 #define FM801_I2C_CTRL 0x29
101 #define FM801_AC97_CMD 0x2a
102 #define FM801_AC97_DATA 0x2c
103 #define FM801_MPU401_DATA 0x30
104 #define FM801_MPU401_CMD 0x31
105 #define FM801_GPIO_CTRL 0x52
106 #define FM801_GEN_CTRL 0x54
107 #define FM801_IRQ_MASK 0x56
108 #define FM801_IRQ_STATUS 0x5a
109 #define FM801_OPL3_BANK0 0x68
110 #define FM801_OPL3_DATA0 0x69
111 #define FM801_OPL3_BANK1 0x6a
112 #define FM801_OPL3_DATA1 0x6b
113 #define FM801_POWERDOWN 0x70
116 #define FM801_AC97_READ (1<<7)
117 #define FM801_AC97_VALID (1<<8)
118 #define FM801_AC97_BUSY (1<<9)
119 #define FM801_AC97_ADDR_SHIFT 10
122 #define FM801_BUF1_LAST (1<<1)
123 #define FM801_BUF2_LAST (1<<2)
124 #define FM801_START (1<<5)
125 #define FM801_PAUSE (1<<6)
126 #define FM801_IMMED_STOP (1<<7)
127 #define FM801_RATE_SHIFT 8
128 #define FM801_RATE_MASK (15 << FM801_RATE_SHIFT)
129 #define FM801_CHANNELS_4 (1<<12)
130 #define FM801_CHANNELS_6 (2<<12)
131 #define FM801_CHANNELS_6MS (3<<12)
132 #define FM801_CHANNELS_MASK (3<<12)
133 #define FM801_16BIT (1<<14)
134 #define FM801_STEREO (1<<15)
137 #define FM801_IRQ_PLAYBACK (1<<8)
138 #define FM801_IRQ_CAPTURE (1<<9)
139 #define FM801_IRQ_VOLUME (1<<14)
140 #define FM801_IRQ_MPU (1<<15)
143 #define FM801_GPIO_GP0 (1<<0)
144 #define FM801_GPIO_GP1 (1<<1)
145 #define FM801_GPIO_GP2 (1<<2)
146 #define FM801_GPIO_GP3 (1<<3)
147 #define FM801_GPIO_GP(x) (1<<(0+(x)))
148 #define FM801_GPIO_GD0 (1<<8)
149 #define FM801_GPIO_GD1 (1<<9)
150 #define FM801_GPIO_GD2 (1<<10)
151 #define FM801_GPIO_GD3 (1<<11)
152 #define FM801_GPIO_GD(x) (1<<(8+(x)))
153 #define FM801_GPIO_GS0 (1<<12)
154 #define FM801_GPIO_GS1 (1<<13)
155 #define FM801_GPIO_GS2 (1<<14)
156 #define FM801_GPIO_GS3 (1<<15)
157 #define FM801_GPIO_GS(x) (1<<(12+(x)))
203 #ifdef CONFIG_SND_FM801_TEA575X_BOOL
208 #ifdef CONFIG_PM_SLEEP
225 static int snd_fm801_update_bits(
struct fm801 *
chip,
unsigned short reg,
226 unsigned short mask,
unsigned short value)
230 unsigned short old,
new;
234 new = (old & ~mask) | value;
238 spin_unlock_irqrestore(&chip->
reg_lock, flags);
242 static void snd_fm801_codec_write(
struct snd_ac97 *ac97,
252 for (idx = 0; idx < 100; idx++) {
267 for (idx = 0; idx < 1000; idx++) {
275 static unsigned short snd_fm801_codec_read(
struct snd_ac97 *ac97,
unsigned short reg)
283 for (idx = 0; idx < 100; idx++) {
295 for (idx = 0; idx < 100; idx++) {
304 for (idx = 0; idx < 1000; idx++) {
316 static unsigned int rates[] = {
317 5500, 8000, 9600, 11025,
318 16000, 19200, 22050, 32000,
342 static unsigned short snd_fm801_rate_bits(
unsigned int rate)
347 if (rates[idx] == rate)
443 chip->
ply_size = snd_pcm_lib_buffer_bytes(substream);
444 chip->
ply_count = snd_pcm_lib_period_bytes(substream);
475 chip->
cap_size = snd_pcm_lib_buffer_bytes(substream);
476 chip->
cap_count = snd_pcm_lib_period_bytes(substream);
510 return bytes_to_frames(substream->
runtime, ptr);
527 return bytes_to_frames(substream->
runtime, ptr);
591 .period_bytes_min = 64,
592 .period_bytes_max = (128*1024),
611 .period_bytes_min = 64,
612 .period_bytes_max = (128*1024),
625 runtime->
hw = snd_fm801_playback;
627 &hw_constraints_rates);
629 runtime->
hw.channels_max = 6;
632 &hw_constraints_channels);
646 runtime->
hw = snd_fm801_capture;
648 &hw_constraints_rates);
670 static struct snd_pcm_ops snd_fm801_playback_ops = {
671 .open = snd_fm801_playback_open,
672 .close = snd_fm801_playback_close,
674 .hw_params = snd_fm801_hw_params,
675 .hw_free = snd_fm801_hw_free,
676 .prepare = snd_fm801_playback_prepare,
677 .trigger = snd_fm801_playback_trigger,
678 .pointer = snd_fm801_playback_pointer,
681 static struct snd_pcm_ops snd_fm801_capture_ops = {
682 .open = snd_fm801_capture_open,
683 .close = snd_fm801_capture_close,
685 .hw_params = snd_fm801_hw_params,
686 .hw_free = snd_fm801_hw_free,
687 .prepare = snd_fm801_capture_prepare,
688 .trigger = snd_fm801_capture_trigger,
689 .pointer = snd_fm801_capture_pointer,
730 #ifdef CONFIG_SND_FM801_TEA575X_BOOL
733 struct snd_fm801_tea575x_gpio {
738 static struct snd_fm801_tea575x_gpio snd_fm801_tea575x_gpios[] = {
739 { .data = 1, .clk = 3, .wren = 2, .most = 0, .name =
"SF256-PCS" },
740 { .data = 1, .clk = 0, .wren = 2, .most = 3, .name =
"SF256-PCP" },
741 { .data = 2, .clk = 0, .wren = 1, .most = 3, .name =
"SF64-PCR" },
744 #define get_tea575x_gpio(chip) \
745 (&snd_fm801_tea575x_gpios[((chip)->tea575x_tuner & TUNER_TYPE_MASK) - 1])
751 struct snd_fm801_tea575x_gpio
gpio = *get_tea575x_gpio(chip);
765 static u8 snd_fm801_tea575x_get_pins(
struct snd_tea575x *tea)
769 struct snd_fm801_tea575x_gpio gpio = *get_tea575x_gpio(chip);
780 static void snd_fm801_tea575x_set_direction(
struct snd_tea575x *tea,
bool output)
784 struct snd_fm801_tea575x_gpio gpio = *get_tea575x_gpio(chip);
818 .
set_pins = snd_fm801_tea575x_set_pins,
819 .get_pins = snd_fm801_tea575x_get_pins,
820 .set_direction = snd_fm801_tea575x_set_direction,
828 #define FM801_SINGLE(xname, reg, shift, mask, invert) \
829 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_fm801_info_single, \
830 .get = snd_fm801_get_single, .put = snd_fm801_put_single, \
831 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
833 static int snd_fm801_info_single(
struct snd_kcontrol *kcontrol,
845 static int snd_fm801_get_single(
struct snd_kcontrol *kcontrol,
854 ucontrol->
value.integer.value[0] = (
inw(chip->
port + reg) >> shift) & mask;
856 ucontrol->
value.integer.value[0] = mask - ucontrol->
value.integer.value[0];
860 static int snd_fm801_put_single(
struct snd_kcontrol *kcontrol,
870 val = (ucontrol->
value.integer.value[0] &
mask);
873 return snd_fm801_update_bits(chip, reg, mask << shift, val << shift);
876 #define FM801_DOUBLE(xname, reg, shift_left, shift_right, mask, invert) \
877 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_fm801_info_double, \
878 .get = snd_fm801_get_double, .put = snd_fm801_put_double, \
879 .private_value = reg | (shift_left << 8) | (shift_right << 12) | (mask << 16) | (invert << 24) }
880 #define FM801_DOUBLE_TLV(xname, reg, shift_left, shift_right, mask, invert, xtlv) \
881 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
882 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
883 .name = xname, .info = snd_fm801_info_double, \
884 .get = snd_fm801_get_double, .put = snd_fm801_put_double, \
885 .private_value = reg | (shift_left << 8) | (shift_right << 12) | (mask << 16) | (invert << 24), \
886 .tlv = { .p = (xtlv) } }
888 static int snd_fm801_info_double(
struct snd_kcontrol *kcontrol,
900 static int snd_fm801_get_double(
struct snd_kcontrol *kcontrol,
911 ucontrol->
value.integer.value[0] = (
inw(chip->
port + reg) >> shift_left) & mask;
915 ucontrol->
value.integer.value[0] = mask - ucontrol->
value.integer.value[0];
916 ucontrol->
value.integer.value[1] = mask - ucontrol->
value.integer.value[1];
921 static int snd_fm801_put_double(
struct snd_kcontrol *kcontrol,
930 unsigned short val1, val2;
932 val1 = ucontrol->
value.integer.value[0] &
mask;
933 val2 = ucontrol->
value.integer.value[1] &
mask;
938 return snd_fm801_update_bits(chip, reg,
939 (mask << shift_left) | (mask << shift_right),
940 (val1 << shift_left ) | (val2 << shift_right));
943 static int snd_fm801_info_mux(
struct snd_kcontrol *kcontrol,
946 static char *texts[5] = {
947 "AC97 Primary",
"FM",
"I2S",
"PCM",
"AC97 Secondary"
959 static int snd_fm801_get_mux(
struct snd_kcontrol *kcontrol,
968 ucontrol->
value.enumerated.item[0] =
val;
972 static int snd_fm801_put_mux(
struct snd_kcontrol *kcontrol,
978 if ((val = ucontrol->
value.enumerated.item[0]) > 4)
985 #define FM801_CONTROLS ARRAY_SIZE(snd_fm801_controls)
999 .name =
"Digital Capture Source",
1000 .info = snd_fm801_info_mux,
1001 .get = snd_fm801_get_mux,
1002 .put = snd_fm801_put_mux,
1006 #define FM801_CONTROLS_MULTI ARRAY_SIZE(snd_fm801_controls_multi)
1008 static struct snd_kcontrol_new snd_fm801_controls_multi[] __devinitdata = {
1023 static void snd_fm801_mixer_free_ac97(
struct snd_ac97 *ac97)
1026 if (ac97->
num == 0) {
1039 .write = snd_fm801_codec_write,
1040 .read = snd_fm801_codec_read,
1045 chip->
ac97_bus->private_free = snd_fm801_mixer_free_ac97_bus;
1047 memset(&ac97, 0,
sizeof(ac97));
1071 static int wait_for_codec(
struct fm801 *chip,
unsigned int codec_id,
1072 unsigned short reg,
unsigned long waits)
1088 static int snd_fm801_chip_init(
struct fm801 *chip,
int resume)
1090 unsigned short cmdw;
1104 "assume SF64-PCR (tuner-only)\n");
1117 for (i = 3; i > 0; i--) {
1121 if (cmdw != 0xffff && cmdw != 0) {
1160 static int snd_fm801_free(
struct fm801 *chip)
1162 unsigned short cmdw;
1173 #ifdef CONFIG_SND_FM801_TEA575X_BOOL
1188 static int snd_fm801_dev_free(
struct snd_device *device)
1191 return snd_fm801_free(chip);
1198 struct fm801 ** rchip)
1203 .dev_free = snd_fm801_dev_free,
1227 KBUILD_MODNAME, chip)) {
1229 snd_fm801_free(chip);
1239 snd_fm801_chip_init(chip, 0);
1243 if (chip->
irq >= 0 && (tea575x_tuner & TUNER_ONLY)) {
1250 snd_fm801_free(chip);
1256 #ifdef CONFIG_SND_FM801_TEA575X_BOOL
1259 snd_fm801_free(chip);
1262 chip->tea.v4l2_dev = &chip->v4l2_dev;
1263 chip->tea.radio_nr = radio_nr;
1264 chip->tea.private_data =
chip;
1265 chip->tea.ops = &snd_fm801_tea_ops;
1266 sprintf(chip->tea.bus_info,
"PCI:%s", pci_name(pci));
1268 (tea575x_tuner & TUNER_TYPE_MASK) < 4) {
1271 snd_fm801_free(chip);
1274 }
else if ((tea575x_tuner & TUNER_TYPE_MASK) == 0) {
1276 for (tea575x_tuner = 1; tea575x_tuner <= 3; tea575x_tuner++) {
1280 get_tea575x_gpio(chip)->
name);
1284 if (tea575x_tuner == 4) {
1291 sizeof(chip->tea.
card));
1318 if ((err = snd_fm801_create(card, pci, tea575x_tuner[dev], radio_nr[dev], &chip)) < 0) {
1331 goto __fm801_tuner_only;
1333 if ((err = snd_fm801_pcm(chip, 0,
NULL)) < 0) {
1337 if ((err = snd_fm801_mixer(chip)) < 0) {
1345 -1, &chip->
rmidi)) < 0) {
1365 pci_set_drvdata(pci, card);
1373 pci_set_drvdata(pci,
NULL);
1376 #ifdef CONFIG_PM_SLEEP
1384 static int snd_fm801_suspend(
struct device *dev)
1392 snd_pcm_suspend_all(chip->
pcm);
1393 snd_ac97_suspend(chip->
ac97);
1396 chip->saved_regs[i] =
inw(chip->
port + saved_regs[i]);
1405 static int snd_fm801_resume(
struct device *dev)
1416 "disabling device\n");
1422 snd_fm801_chip_init(chip, 1);
1423 snd_ac97_resume(chip->
ac97);
1426 outw(chip->saved_regs[i], chip->
port + saved_regs[i]);
1433 #define SND_FM801_PM_OPS &snd_fm801_pm
1435 #define SND_FM801_PM_OPS NULL
1439 .name = KBUILD_MODNAME,
1440 .id_table = snd_fm801_ids,
1441 .probe = snd_card_fm801_probe,