opti92x-ad1848.c (611ac726f9ebbb12f2113e5345ef109660954eeb) opti92x-ad1848.c (2973ee4a5b5495090af6b24d9adbb765bca04aaf)
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 card-opti92x-ad1848.c - driver for OPTi 82c92x based soundcards.
4 Copyright (C) 1998-2000 by Massimo Piccioni <dafastidio@libero.it>
5
6 Part of this code was developed at the Italian Ministry of Air Defence,
7 Sixth Division (oh, che pace ...), Rome.
8

--- 640 unchanged lines hidden (view full) ---

649 snd_pcm_period_elapsed(codec->capture_substream);
650 }
651 outb(0x00, OPTi93X_PORT(codec, STATUS));
652 return IRQ_HANDLED;
653}
654
655#endif /* OPTi93X */
656
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 card-opti92x-ad1848.c - driver for OPTi 82c92x based soundcards.
4 Copyright (C) 1998-2000 by Massimo Piccioni <dafastidio@libero.it>
5
6 Part of this code was developed at the Italian Ministry of Air Defence,
7 Sixth Division (oh, che pace ...), Rome.
8

--- 640 unchanged lines hidden (view full) ---

649 snd_pcm_period_elapsed(codec->capture_substream);
650 }
651 outb(0x00, OPTi93X_PORT(codec, STATUS));
652 return IRQ_HANDLED;
653}
654
655#endif /* OPTi93X */
656
657static int snd_opti9xx_read_check(struct snd_opti9xx *chip)
657static int snd_opti9xx_read_check(struct snd_card *card,
658 struct snd_opti9xx *chip)
658{
659 unsigned char value;
660#ifdef OPTi93X
661 unsigned long flags;
662#endif
663
659{
660 unsigned char value;
661#ifdef OPTi93X
662 unsigned long flags;
663#endif
664
664 chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size,
665 "OPTi9xx MC");
666 if (chip->res_mc_base == NULL)
665 chip->res_mc_base =
666 devm_request_region(card->dev, chip->mc_base,
667 chip->mc_base_size, "OPTi9xx MC");
668 if (!chip->res_mc_base)
667 return -EBUSY;
668#ifndef OPTi93X
669 value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(1));
670 if (value != 0xff && value != inb(chip->mc_base + OPTi9XX_MC_REG(1)))
671 if (value == snd_opti9xx_read(chip, OPTi9XX_MC_REG(1)))
672 return 0;
673#else /* OPTi93X */
669 return -EBUSY;
670#ifndef OPTi93X
671 value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(1));
672 if (value != 0xff && value != inb(chip->mc_base + OPTi9XX_MC_REG(1)))
673 if (value == snd_opti9xx_read(chip, OPTi9XX_MC_REG(1)))
674 return 0;
675#else /* OPTi93X */
674 chip->res_mc_indir = request_region(chip->mc_indir_index, 2,
675 "OPTi93x MC");
676 if (chip->res_mc_indir == NULL)
676 chip->res_mc_indir =
677 devm_request_region(card->dev, chip->mc_indir_index, 2,
678 "OPTi93x MC");
679 if (!chip->res_mc_indir)
677 return -EBUSY;
678
679 spin_lock_irqsave(&chip->lock, flags);
680 outb(chip->password, chip->mc_base + chip->pwd_reg);
681 outb(((chip->mc_indir_index & 0x1f0) >> 4), chip->mc_base);
682 spin_unlock_irqrestore(&chip->lock, flags);
683
684 value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(7));
685 snd_opti9xx_write(chip, OPTi9XX_MC_REG(7), 0xff - value);
686 if (snd_opti9xx_read(chip, OPTi9XX_MC_REG(7)) == 0xff - value)
687 return 0;
688
680 return -EBUSY;
681
682 spin_lock_irqsave(&chip->lock, flags);
683 outb(chip->password, chip->mc_base + chip->pwd_reg);
684 outb(((chip->mc_indir_index & 0x1f0) >> 4), chip->mc_base);
685 spin_unlock_irqrestore(&chip->lock, flags);
686
687 value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(7));
688 snd_opti9xx_write(chip, OPTi9XX_MC_REG(7), 0xff - value);
689 if (snd_opti9xx_read(chip, OPTi9XX_MC_REG(7)) == 0xff - value)
690 return 0;
691
689 release_and_free_resource(chip->res_mc_indir);
692 devm_release_resource(card->dev, chip->res_mc_indir);
690 chip->res_mc_indir = NULL;
691#endif /* OPTi93X */
693 chip->res_mc_indir = NULL;
694#endif /* OPTi93X */
692 release_and_free_resource(chip->res_mc_base);
695 devm_release_resource(card->dev, chip->res_mc_base);
693 chip->res_mc_base = NULL;
694
695 return -ENODEV;
696}
697
698static int snd_card_opti9xx_detect(struct snd_card *card,
699 struct snd_opti9xx *chip)
700{
701 int i, err;
702
703#ifndef OPTi93X
704 for (i = OPTi9XX_HW_82C928; i < OPTi9XX_HW_82C930; i++) {
705#else
706 for (i = OPTi9XX_HW_82C931; i >= OPTi9XX_HW_82C930; i--) {
707#endif
708 err = snd_opti9xx_init(chip, i);
709 if (err < 0)
710 return err;
711
696 chip->res_mc_base = NULL;
697
698 return -ENODEV;
699}
700
701static int snd_card_opti9xx_detect(struct snd_card *card,
702 struct snd_opti9xx *chip)
703{
704 int i, err;
705
706#ifndef OPTi93X
707 for (i = OPTi9XX_HW_82C928; i < OPTi9XX_HW_82C930; i++) {
708#else
709 for (i = OPTi9XX_HW_82C931; i >= OPTi9XX_HW_82C930; i--) {
710#endif
711 err = snd_opti9xx_init(chip, i);
712 if (err < 0)
713 return err;
714
712 err = snd_opti9xx_read_check(chip);
715 err = snd_opti9xx_read_check(card, chip);
713 if (err == 0)
714 return 1;
715#ifdef OPTi93X
716 chip->mc_indir_index = 0;
717#endif
718 }
719 return -ENODEV;
720}

--- 63 unchanged lines hidden (view full) ---

784 mpu_port = pnp_port_start(devmpu, 0);
785 mpu_irq = pnp_irq(devmpu, 0);
786 }
787 }
788 return pid->driver_data;
789}
790#endif /* CONFIG_PNP */
791
716 if (err == 0)
717 return 1;
718#ifdef OPTi93X
719 chip->mc_indir_index = 0;
720#endif
721 }
722 return -ENODEV;
723}

--- 63 unchanged lines hidden (view full) ---

787 mpu_port = pnp_port_start(devmpu, 0);
788 mpu_irq = pnp_irq(devmpu, 0);
789 }
790 }
791 return pid->driver_data;
792}
793#endif /* CONFIG_PNP */
794
792static void snd_card_opti9xx_free(struct snd_card *card)
793{
794 struct snd_opti9xx *chip = card->private_data;
795
796 if (chip) {
797#ifdef OPTi93X
798 if (chip->irq > 0) {
799 disable_irq(chip->irq);
800 free_irq(chip->irq, chip);
801 }
802 release_and_free_resource(chip->res_mc_indir);
803#endif
804 release_and_free_resource(chip->res_mc_base);
805 }
806}
807
808static int snd_opti9xx_probe(struct snd_card *card)
809{
810 static const long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
811 int error;
812 int xdma2;
813 struct snd_opti9xx *chip = card->private_data;
814 struct snd_wss *codec;
815 struct snd_rawmidi *rmidi;

--- 39 unchanged lines hidden (view full) ---

855 return error;
856#endif
857#ifdef CS4231
858 error = snd_wss_timer(codec, 0);
859 if (error < 0)
860 return error;
861#endif
862#ifdef OPTi93X
795static int snd_opti9xx_probe(struct snd_card *card)
796{
797 static const long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
798 int error;
799 int xdma2;
800 struct snd_opti9xx *chip = card->private_data;
801 struct snd_wss *codec;
802 struct snd_rawmidi *rmidi;

--- 39 unchanged lines hidden (view full) ---

842 return error;
843#endif
844#ifdef CS4231
845 error = snd_wss_timer(codec, 0);
846 if (error < 0)
847 return error;
848#endif
849#ifdef OPTi93X
863 error = request_irq(irq, snd_opti93x_interrupt,
864 0, DEV_NAME" - WSS", chip);
850 error = devm_request_irq(card->dev, irq, snd_opti93x_interrupt,
851 0, DEV_NAME" - WSS", chip);
865 if (error < 0) {
866 snd_printk(KERN_ERR "opti9xx: can't grab IRQ %d\n", irq);
867 return error;
868 }
869#endif
870 chip->irq = irq;
871 card->sync_irq = chip->irq;
872 strcpy(card->driver, chip->name);

--- 53 unchanged lines hidden (view full) ---

926 return snd_card_register(card);
927}
928
929static int snd_opti9xx_card_new(struct device *pdev, struct snd_card **cardp)
930{
931 struct snd_card *card;
932 int err;
933
852 if (error < 0) {
853 snd_printk(KERN_ERR "opti9xx: can't grab IRQ %d\n", irq);
854 return error;
855 }
856#endif
857 chip->irq = irq;
858 card->sync_irq = chip->irq;
859 strcpy(card->driver, chip->name);

--- 53 unchanged lines hidden (view full) ---

913 return snd_card_register(card);
914}
915
916static int snd_opti9xx_card_new(struct device *pdev, struct snd_card **cardp)
917{
918 struct snd_card *card;
919 int err;
920
934 err = snd_card_new(pdev, index, id, THIS_MODULE,
935 sizeof(struct snd_opti9xx), &card);
921 err = snd_devm_card_new(pdev, index, id, THIS_MODULE,
922 sizeof(struct snd_opti9xx), &card);
936 if (err < 0)
937 return err;
923 if (err < 0)
924 return err;
938 card->private_free = snd_card_opti9xx_free;
939 *cardp = card;
940 return 0;
941}
942
943static int snd_opti9xx_isa_match(struct device *devptr,
944 unsigned int dev)
945{
946#ifdef CONFIG_PNP

--- 60 unchanged lines hidden (view full) ---

1007 }
1008#endif
1009
1010 error = snd_opti9xx_card_new(devptr, &card);
1011 if (error < 0)
1012 return error;
1013
1014 error = snd_card_opti9xx_detect(card, card->private_data);
925 *cardp = card;
926 return 0;
927}
928
929static int snd_opti9xx_isa_match(struct device *devptr,
930 unsigned int dev)
931{
932#ifdef CONFIG_PNP

--- 60 unchanged lines hidden (view full) ---

993 }
994#endif
995
996 error = snd_opti9xx_card_new(devptr, &card);
997 if (error < 0)
998 return error;
999
1000 error = snd_card_opti9xx_detect(card, card->private_data);
1015 if (error < 0) {
1016 snd_card_free(card);
1001 if (error < 0)
1017 return error;
1002 return error;
1018 }
1019 error = snd_opti9xx_probe(card);
1003 error = snd_opti9xx_probe(card);
1020 if (error < 0) {
1021 snd_card_free(card);
1004 if (error < 0)
1022 return error;
1005 return error;
1023 }
1024 dev_set_drvdata(devptr, card);
1025 return 0;
1026}
1027
1006 dev_set_drvdata(devptr, card);
1007 return 0;
1008}
1009
1028static void snd_opti9xx_isa_remove(struct device *devptr,
1029 unsigned int dev)
1030{
1031 snd_card_free(dev_get_drvdata(devptr));
1032}
1033
1034#ifdef CONFIG_PM
1035static int snd_opti9xx_suspend(struct snd_card *card)
1036{
1037 struct snd_opti9xx *chip = card->private_data;
1038
1039 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
1040 chip->codec->suspend(chip->codec);
1041 return 0;

--- 28 unchanged lines hidden (view full) ---

1070{
1071 return snd_opti9xx_resume(dev_get_drvdata(dev));
1072}
1073#endif
1074
1075static struct isa_driver snd_opti9xx_driver = {
1076 .match = snd_opti9xx_isa_match,
1077 .probe = snd_opti9xx_isa_probe,
1010#ifdef CONFIG_PM
1011static int snd_opti9xx_suspend(struct snd_card *card)
1012{
1013 struct snd_opti9xx *chip = card->private_data;
1014
1015 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
1016 chip->codec->suspend(chip->codec);
1017 return 0;

--- 28 unchanged lines hidden (view full) ---

1046{
1047 return snd_opti9xx_resume(dev_get_drvdata(dev));
1048}
1049#endif
1050
1051static struct isa_driver snd_opti9xx_driver = {
1052 .match = snd_opti9xx_isa_match,
1053 .probe = snd_opti9xx_isa_probe,
1078 .remove = snd_opti9xx_isa_remove,
1079#ifdef CONFIG_PM
1080 .suspend = snd_opti9xx_isa_suspend,
1081 .resume = snd_opti9xx_isa_resume,
1082#endif
1083 .driver = {
1084 .name = DEV_NAME
1085 },
1086};

--- 22 unchanged lines hidden (view full) ---

1109 break;
1110 case 0x0925:
1111 hw = OPTi9XX_HW_82C925;
1112 break;
1113 case 0x0931:
1114 hw = OPTi9XX_HW_82C931;
1115 break;
1116 default:
1054#ifdef CONFIG_PM
1055 .suspend = snd_opti9xx_isa_suspend,
1056 .resume = snd_opti9xx_isa_resume,
1057#endif
1058 .driver = {
1059 .name = DEV_NAME
1060 },
1061};

--- 22 unchanged lines hidden (view full) ---

1084 break;
1085 case 0x0925:
1086 hw = OPTi9XX_HW_82C925;
1087 break;
1088 case 0x0931:
1089 hw = OPTi9XX_HW_82C931;
1090 break;
1091 default:
1117 snd_card_free(card);
1118 return -ENODEV;
1119 }
1120
1121 error = snd_opti9xx_init(chip, hw);
1092 return -ENODEV;
1093 }
1094
1095 error = snd_opti9xx_init(chip, hw);
1122 if (error) {
1123 snd_card_free(card);
1096 if (error)
1124 return error;
1097 return error;
1125 }
1126 error = snd_opti9xx_read_check(chip);
1127 if (error) {
1098 error = snd_opti9xx_read_check(card, chip);
1099 if (error)
1128 snd_printk(KERN_ERR "OPTI chip not found\n");
1100 snd_printk(KERN_ERR "OPTI chip not found\n");
1129 snd_card_free(card);
1130 return error;
1101 return error;
1131 }
1132 error = snd_opti9xx_probe(card);
1102 error = snd_opti9xx_probe(card);
1133 if (error < 0) {
1134 snd_card_free(card);
1103 if (error < 0)
1135 return error;
1104 return error;
1136 }
1137 pnp_set_card_drvdata(pcard, card);
1138 snd_opti9xx_pnp_is_probed = 1;
1139 return 0;
1140}
1141
1142static void snd_opti9xx_pnp_remove(struct pnp_card_link *pcard)
1143{
1105 pnp_set_card_drvdata(pcard, card);
1106 snd_opti9xx_pnp_is_probed = 1;
1107 return 0;
1108}
1109
1110static void snd_opti9xx_pnp_remove(struct pnp_card_link *pcard)
1111{
1144 snd_card_free(pnp_get_card_drvdata(pcard));
1145 pnp_set_card_drvdata(pcard, NULL);
1146 snd_opti9xx_pnp_is_probed = 0;
1147}
1148
1149#ifdef CONFIG_PM
1150static int snd_opti9xx_pnp_suspend(struct pnp_card_link *pcard,
1151 pm_message_t state)
1152{
1153 return snd_opti9xx_suspend(pnp_get_card_drvdata(pcard));

--- 51 unchanged lines hidden ---
1112 snd_opti9xx_pnp_is_probed = 0;
1113}
1114
1115#ifdef CONFIG_PM
1116static int snd_opti9xx_pnp_suspend(struct pnp_card_link *pcard,
1117 pm_message_t state)
1118{
1119 return snd_opti9xx_suspend(pnp_get_card_drvdata(pcard));

--- 51 unchanged lines hidden ---