Lines Matching +full:invert +full:- +full:enable

1 // SPDX-License-Identifier: GPL-2.0-or-later
23 #include <media/drv-intf/tea575x.h>
30 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
32 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
34 * Enable TEA575x tuner
35 * 1 = MediaForte 256-PCS
36 * 2 = MediaForte 256-PCP
37 * 3 = MediaForte 64-PCR
38 * 16 = setup tuner only (this is additional bit), i.e. SF64-PCR FM card
39 * High 16-bits are video (radio) device number + 1
42 static int radio_nr[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -1};
48 module_param_array(enable, bool, NULL, 0444);
49 MODULE_PARM_DESC(enable, "Enable FM801 soundcard.");
51 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).");
64 #define fm801_writew(chip,reg,value) outw((value), chip->port + FM801_##reg)
65 #define fm801_readw(chip,reg) inw(chip->port + FM801_##reg)
67 #define fm801_writel(chip,reg,value) outl((value), chip->port + FM801_##reg)
144 * struct fm801 - describes FM801 chip
234 outw(value, chip->port + offset);
239 return inw(chip->port + offset);
284 guard(spinlock_irqsave)(&chip->reg_lock);
297 struct fm801 *chip = ac97->private_data;
303 dev_err(chip->card->dev, "AC'97 interface is busy (1)\n");
309 fm801_writew(chip, AC97_CMD, reg | (ac97->addr << FM801_AC97_ADDR_SHIFT));
314 dev_err(chip->card->dev, "AC'97 interface #%d is busy (2)\n",
315 ac97->num);
320 struct fm801 *chip = ac97->private_data;
326 dev_err(chip->card->dev, "AC'97 interface is busy (1)\n");
332 reg | (ac97->addr << FM801_AC97_ADDR_SHIFT) | FM801_AC97_READ);
334 dev_err(chip->card->dev, "AC'97 interface #%d is busy (2)\n",
335 ac97->num);
340 dev_err(chip->card->dev,
341 "AC'97 interface #%d is not valid (2)\n", ac97->num);
382 return ARRAY_SIZE(rates) - 1;
394 guard(spinlock)(&chip->reg_lock);
397 chip->ply_ctrl &= ~(FM801_BUF1_LAST |
400 chip->ply_ctrl |= FM801_START |
404 chip->ply_ctrl &= ~(FM801_START | FM801_PAUSE);
408 chip->ply_ctrl |= FM801_PAUSE;
412 chip->ply_ctrl &= ~FM801_PAUSE;
416 return -EINVAL;
418 fm801_writew(chip, PLY_CTRL, chip->ply_ctrl);
427 guard(spinlock)(&chip->reg_lock);
430 chip->cap_ctrl &= ~(FM801_BUF1_LAST |
433 chip->cap_ctrl |= FM801_START |
437 chip->cap_ctrl &= ~(FM801_START | FM801_PAUSE);
441 chip->cap_ctrl |= FM801_PAUSE;
445 chip->cap_ctrl &= ~FM801_PAUSE;
449 return -EINVAL;
451 fm801_writew(chip, CAP_CTRL, chip->cap_ctrl);
458 struct snd_pcm_runtime *runtime = substream->runtime;
460 chip->ply_size = snd_pcm_lib_buffer_bytes(substream);
461 chip->ply_count = snd_pcm_lib_period_bytes(substream);
462 guard(spinlock_irq)(&chip->reg_lock);
463 chip->ply_ctrl &= ~(FM801_START | FM801_16BIT |
466 if (snd_pcm_format_width(runtime->format) == 16)
467 chip->ply_ctrl |= FM801_16BIT;
468 if (runtime->channels > 1) {
469 chip->ply_ctrl |= FM801_STEREO;
470 if (runtime->channels == 4)
471 chip->ply_ctrl |= FM801_CHANNELS_4;
472 else if (runtime->channels == 6)
473 chip->ply_ctrl |= FM801_CHANNELS_6;
475 chip->ply_ctrl |= snd_fm801_rate_bits(runtime->rate) << FM801_RATE_SHIFT;
476 chip->ply_buf = 0;
477 fm801_writew(chip, PLY_CTRL, chip->ply_ctrl);
478 fm801_writew(chip, PLY_COUNT, chip->ply_count - 1);
479 chip->ply_buffer = runtime->dma_addr;
480 chip->ply_pos = 0;
481 fm801_writel(chip, PLY_BUF1, chip->ply_buffer);
483 chip->ply_buffer + (chip->ply_count % chip->ply_size));
490 struct snd_pcm_runtime *runtime = substream->runtime;
492 chip->cap_size = snd_pcm_lib_buffer_bytes(substream);
493 chip->cap_count = snd_pcm_lib_period_bytes(substream);
494 guard(spinlock_irq)(&chip->reg_lock);
495 chip->cap_ctrl &= ~(FM801_START | FM801_16BIT |
497 if (snd_pcm_format_width(runtime->format) == 16)
498 chip->cap_ctrl |= FM801_16BIT;
499 if (runtime->channels > 1)
500 chip->cap_ctrl |= FM801_STEREO;
501 chip->cap_ctrl |= snd_fm801_rate_bits(runtime->rate) << FM801_RATE_SHIFT;
502 chip->cap_buf = 0;
503 fm801_writew(chip, CAP_CTRL, chip->cap_ctrl);
504 fm801_writew(chip, CAP_COUNT, chip->cap_count - 1);
505 chip->cap_buffer = runtime->dma_addr;
506 chip->cap_pos = 0;
507 fm801_writel(chip, CAP_BUF1, chip->cap_buffer);
509 chip->cap_buffer + (chip->cap_count % chip->cap_size));
518 if (!(chip->ply_ctrl & FM801_START))
520 guard(spinlock)(&chip->reg_lock);
521 ptr = chip->ply_pos + (chip->ply_count - 1) - fm801_readw(chip, PLY_COUNT);
523 ptr += chip->ply_count;
524 ptr %= chip->ply_size;
526 return bytes_to_frames(substream->runtime, ptr);
534 if (!(chip->cap_ctrl & FM801_START))
536 guard(spinlock)(&chip->reg_lock);
537 ptr = chip->cap_pos + (chip->cap_count - 1) - fm801_readw(chip, CAP_COUNT);
539 ptr += chip->cap_count;
540 ptr %= chip->cap_size;
542 return bytes_to_frames(substream->runtime, ptr);
557 if (chip->pcm && (status & FM801_IRQ_PLAYBACK) && chip->playback_substream) {
558 scoped_guard(spinlock, &chip->reg_lock) {
559 chip->ply_buf++;
560 chip->ply_pos += chip->ply_count;
561 chip->ply_pos %= chip->ply_size;
562 tmp = chip->ply_pos + chip->ply_count;
563 tmp %= chip->ply_size;
564 if (chip->ply_buf & 1)
565 fm801_writel(chip, PLY_BUF1, chip->ply_buffer + tmp);
567 fm801_writel(chip, PLY_BUF2, chip->ply_buffer + tmp);
569 snd_pcm_period_elapsed(chip->playback_substream);
571 if (chip->pcm && (status & FM801_IRQ_CAPTURE) && chip->capture_substream) {
572 scoped_guard(spinlock, &chip->reg_lock) {
573 chip->cap_buf++;
574 chip->cap_pos += chip->cap_count;
575 chip->cap_pos %= chip->cap_size;
576 tmp = chip->cap_pos + chip->cap_count;
577 tmp %= chip->cap_size;
578 if (chip->cap_buf & 1)
579 fm801_writel(chip, CAP_BUF1, chip->cap_buffer + tmp);
581 fm801_writel(chip, CAP_BUF2, chip->cap_buffer + tmp);
583 snd_pcm_period_elapsed(chip->capture_substream);
585 if (chip->rmidi && (status & FM801_IRQ_MPU))
586 snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data);
637 struct snd_pcm_runtime *runtime = substream->runtime;
640 chip->playback_substream = substream;
641 runtime->hw = snd_fm801_playback;
644 if (chip->multichannel) {
645 runtime->hw.channels_max = 6;
659 struct snd_pcm_runtime *runtime = substream->runtime;
662 chip->capture_substream = substream;
663 runtime->hw = snd_fm801_capture;
676 chip->playback_substream = NULL;
684 chip->capture_substream = NULL;
706 struct pci_dev *pdev = to_pci_dev(chip->dev);
710 err = snd_pcm_new(chip->card, "FM801", device, 1, 1, &pcm);
717 pcm->private_data = chip;
718 pcm->info_flags = 0;
719 strscpy(pcm->name, "FM801");
720 chip->pcm = pcm;
722 snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, &pdev->dev,
723 chip->multichannel ? 128*1024 : 64*1024, 128*1024);
727 chip->multichannel ? 6 : 2, 0,
744 { .data = 1, .clk = 3, .wren = 2, .most = 0, .name = "SF256-PCS" },
745 { .data = 1, .clk = 0, .wren = 2, .most = 3, .name = "SF256-PCP" },
746 { .data = 2, .clk = 0, .wren = 1, .most = 3, .name = "SF64-PCR" },
750 (&snd_fm801_tea575x_gpios[((chip)->tea575x_tuner & TUNER_TYPE_MASK) - 1])
754 struct fm801 *chip = tea->private_data;
772 struct fm801 *chip = tea->private_data;
787 struct fm801 *chip = tea->private_data;
791 /* use GPIO lines and set write enable bit */
813 /* clear data, write enable and clock lines */
833 #define FM801_SINGLE(xname, reg, shift, mask, invert) \
836 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
841 int mask = (kcontrol->private_value >> 16) & 0xff;
843 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
844 uinfo->count = 1;
845 uinfo->value.integer.min = 0;
846 uinfo->value.integer.max = mask;
854 int reg = kcontrol->private_value & 0xff;
855 int shift = (kcontrol->private_value >> 8) & 0xff;
856 int mask = (kcontrol->private_value >> 16) & 0xff;
857 int invert = (kcontrol->private_value >> 24) & 0xff;
858 long *value = ucontrol->value.integer.value;
861 if (invert)
862 value[0] = mask - value[0];
870 int reg = kcontrol->private_value & 0xff;
871 int shift = (kcontrol->private_value >> 8) & 0xff;
872 int mask = (kcontrol->private_value >> 16) & 0xff;
873 int invert = (kcontrol->private_value >> 24) & 0xff;
876 val = (ucontrol->value.integer.value[0] & mask);
877 if (invert)
878 val = mask - val;
882 #define FM801_DOUBLE(xname, reg, shift_left, shift_right, mask, invert) \
885 .private_value = reg | (shift_left << 8) | (shift_right << 12) | (mask << 16) | (invert << 24) }
886 #define FM801_DOUBLE_TLV(xname, reg, shift_left, shift_right, mask, invert, xtlv) \
891 .private_value = reg | (shift_left << 8) | (shift_right << 12) | (mask << 16) | (invert << 24), \
897 int mask = (kcontrol->private_value >> 16) & 0xff;
899 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
900 uinfo->count = 2;
901 uinfo->value.integer.min = 0;
902 uinfo->value.integer.max = mask;
910 int reg = kcontrol->private_value & 0xff;
911 int shift_left = (kcontrol->private_value >> 8) & 0x0f;
912 int shift_right = (kcontrol->private_value >> 12) & 0x0f;
913 int mask = (kcontrol->private_value >> 16) & 0xff;
914 int invert = (kcontrol->private_value >> 24) & 0xff;
915 long *value = ucontrol->value.integer.value;
917 guard(spinlock_irq)(&chip->reg_lock);
920 if (invert) {
921 value[0] = mask - value[0];
922 value[1] = mask - value[1];
931 int reg = kcontrol->private_value & 0xff;
932 int shift_left = (kcontrol->private_value >> 8) & 0x0f;
933 int shift_right = (kcontrol->private_value >> 12) & 0x0f;
934 int mask = (kcontrol->private_value >> 16) & 0xff;
935 int invert = (kcontrol->private_value >> 24) & 0xff;
938 val1 = ucontrol->value.integer.value[0] & mask;
939 val2 = ucontrol->value.integer.value[1] & mask;
940 if (invert) {
941 val1 = mask - val1;
942 val2 = mask - val2;
968 ucontrol->value.enumerated.item[0] = val;
978 val = ucontrol->value.enumerated.item[0];
980 return -EINVAL;
984 static const DECLARE_TLV_DB_SCALE(db_scale_dsp, -3450, 150, 0);
1010 FM801_SINGLE("AC97 2ch->4ch Copy Switch", FM801_CODEC_CTRL, 7, 1, 0),
1011 FM801_SINGLE("AC97 18-bit Switch", FM801_CODEC_CTRL, 10, 1, 0),
1028 err = snd_ac97_bus(chip->card, 0, &ops, chip, &chip->ac97_bus);
1034 err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97);
1037 if (chip->secondary) {
1039 ac97.addr = chip->secondary_addr;
1040 err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97_sec);
1045 err = snd_ctl_add(chip->card,
1050 if (chip->multichannel) {
1052 err = snd_ctl_add(chip->card,
1079 return -EIO;
1097 if (chip->multichannel) {
1098 if (chip->secondary_addr) {
1099 wait_for_codec(chip, chip->secondary_addr,
1105 for (i = 3; i > 0; i--) {
1110 chip->secondary = 1;
1111 chip->secondary_addr = i;
1118 /* the recovery phase, it seems that probing for non-existing codec might */
1133 /* I2S control - I2S mode */
1138 if (chip->irq < 0)
1151 struct fm801 *chip = card->private_data;
1154 /* interrupt setup - mask everything */
1160 if (!(chip->tea575x_tuner & TUNER_DISABLED)) {
1161 snd_tea575x_exit(&chip->tea);
1162 v4l2_device_unregister(&chip->v4l2_dev);
1172 struct fm801 *chip = card->private_data;
1178 spin_lock_init(&chip->reg_lock);
1179 chip->card = card;
1180 chip->dev = &pci->dev;
1181 chip->irq = -1;
1182 chip->tea575x_tuner = tea575x_tuner;
1186 chip->port = pci_resource_start(pci, 0);
1188 if (pci->revision >= 0xb1) /* FM801-AU */
1189 chip->multichannel = 1;
1191 if (!(chip->tea575x_tuner & TUNER_ONLY)) {
1193 dev_info(chip->card->dev,
1194 "Primary AC'97 codec not found, assume SF64-PCR (tuner-only)\n");
1195 chip->tea575x_tuner = 3 | TUNER_ONLY;
1201 if ((chip->tea575x_tuner & TUNER_ONLY) == 0) {
1202 if (devm_request_irq(&pci->dev, pci->irq, snd_fm801_interrupt,
1204 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
1205 return -EBUSY;
1207 chip->irq = pci->irq;
1208 card->sync_irq = chip->irq;
1212 card->private_free = snd_fm801_free;
1216 err = v4l2_device_register(&pci->dev, &chip->v4l2_dev);
1219 chip->tea.v4l2_dev = &chip->v4l2_dev;
1220 chip->tea.radio_nr = radio_nr;
1221 chip->tea.private_data = chip;
1222 chip->tea.ops = &snd_fm801_tea_ops;
1223 sprintf(chip->tea.bus_info, "PCI:%s", pci_name(pci));
1224 if ((chip->tea575x_tuner & TUNER_TYPE_MASK) > 0 &&
1225 (chip->tea575x_tuner & TUNER_TYPE_MASK) < 4) {
1226 if (snd_tea575x_init(&chip->tea, THIS_MODULE)) {
1227 dev_err(card->dev, "TEA575x radio not found\n");
1228 return -ENODEV;
1230 } else if ((chip->tea575x_tuner & TUNER_TYPE_MASK) == 0) {
1231 unsigned int tuner_only = chip->tea575x_tuner & TUNER_ONLY;
1235 chip->tea575x_tuner = tea575x_tuner;
1236 if (!snd_tea575x_init(&chip->tea, THIS_MODULE)) {
1237 dev_info(card->dev,
1239 get_tea575x_gpio(chip)->name);
1244 dev_err(card->dev, "TEA575x radio not found\n");
1245 chip->tea575x_tuner = TUNER_DISABLED;
1248 chip->tea575x_tuner |= tuner_only;
1250 if (!(chip->tea575x_tuner & TUNER_DISABLED)) {
1251 strscpy(chip->tea.card, get_tea575x_gpio(chip)->name,
1252 sizeof(chip->tea.card));
1268 return -ENODEV;
1269 if (!enable[dev]) {
1271 return -ENOENT;
1274 err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
1278 chip = card->private_data;
1283 strscpy(card->driver, "FM801");
1284 strscpy(card->shortname, "ForteMedia FM801-");
1285 strcat(card->shortname, chip->multichannel ? "AU" : "AS");
1286 sprintf(card->longname, "%s at 0x%lx, irq %i",
1287 card->shortname, chip->port, chip->irq);
1289 if (chip->tea575x_tuner & TUNER_ONLY)
1299 chip->port + FM801_MPU401_DATA,
1302 -1, &chip->rmidi);
1305 err = snd_opl3_create(card, chip->port + FM801_OPL3_BANK0,
1306 chip->port + FM801_OPL3_BANK1,
1326 return snd_card_free_on_error(&pci->dev, __snd_card_fm801_probe(pci, pci_id));
1339 struct fm801 *chip = card->private_data;
1345 chip->saved_regs[i] = fm801_ioread16(chip, saved_regs[i]);
1347 if (chip->tea575x_tuner & TUNER_ONLY) {
1350 snd_ac97_suspend(chip->ac97);
1351 snd_ac97_suspend(chip->ac97_sec);
1360 struct fm801 *chip = card->private_data;
1363 if (chip->tea575x_tuner & TUNER_ONLY) {
1369 snd_ac97_resume(chip->ac97);
1370 snd_ac97_resume(chip->ac97_sec);
1374 fm801_iowrite16(chip, saved_regs[i], chip->saved_regs[i]);
1377 if (!(chip->tea575x_tuner & TUNER_DISABLED))
1378 snd_tea575x_set_freq(&chip->tea);