aboutsummaryrefslogtreecommitdiffstats
path: root/sound/isa/es18xx.c
diff options
context:
space:
mode:
authorAndrea Bastoni <bastoni@cs.unc.edu>2010-05-30 19:16:45 -0400
committerAndrea Bastoni <bastoni@cs.unc.edu>2010-05-30 19:16:45 -0400
commitada47b5fe13d89735805b566185f4885f5a3f750 (patch)
tree644b88f8a71896307d71438e9b3af49126ffb22b /sound/isa/es18xx.c
parent43e98717ad40a4ae64545b5ba047c7b86aa44f4f (diff)
parent3280f21d43ee541f97f8cda5792150d2dbec20d5 (diff)
Merge branch 'wip-2.6.34' into old-private-masterarchived-private-master
Diffstat (limited to 'sound/isa/es18xx.c')
-rw-r--r--sound/isa/es18xx.c222
1 files changed, 102 insertions, 120 deletions
diff --git a/sound/isa/es18xx.c b/sound/isa/es18xx.c
index 8cfbff73a835..fb4d6b34bbca 100644
--- a/sound/isa/es18xx.c
+++ b/sound/isa/es18xx.c
@@ -80,7 +80,6 @@
80#include <linux/init.h> 80#include <linux/init.h>
81#include <linux/err.h> 81#include <linux/err.h>
82#include <linux/isa.h> 82#include <linux/isa.h>
83#include <linux/slab.h>
84#include <linux/pnp.h> 83#include <linux/pnp.h>
85#include <linux/isapnp.h> 84#include <linux/isapnp.h>
86#include <linux/moduleparam.h> 85#include <linux/moduleparam.h>
@@ -102,8 +101,6 @@
102 101
103struct snd_es18xx { 102struct snd_es18xx {
104 unsigned long port; /* port of ESS chip */ 103 unsigned long port; /* port of ESS chip */
105 unsigned long mpu_port; /* MPU-401 port of ESS chip */
106 unsigned long fm_port; /* FM port */
107 unsigned long ctrl_port; /* Control port of ESS chip */ 104 unsigned long ctrl_port; /* Control port of ESS chip */
108 struct resource *res_port; 105 struct resource *res_port;
109 struct resource *res_mpu_port; 106 struct resource *res_mpu_port;
@@ -116,12 +113,9 @@ struct snd_es18xx {
116 unsigned short audio2_vol; /* volume level of audio2 */ 113 unsigned short audio2_vol; /* volume level of audio2 */
117 114
118 unsigned short active; /* active channel mask */ 115 unsigned short active; /* active channel mask */
119 unsigned int dma1_size;
120 unsigned int dma2_size;
121 unsigned int dma1_shift; 116 unsigned int dma1_shift;
122 unsigned int dma2_shift; 117 unsigned int dma2_shift;
123 118
124 struct snd_card *card;
125 struct snd_pcm *pcm; 119 struct snd_pcm *pcm;
126 struct snd_pcm_substream *playback_a_substream; 120 struct snd_pcm_substream *playback_a_substream;
127 struct snd_pcm_substream *capture_a_substream; 121 struct snd_pcm_substream *capture_a_substream;
@@ -136,14 +130,9 @@ struct snd_es18xx {
136 130
137 spinlock_t reg_lock; 131 spinlock_t reg_lock;
138 spinlock_t mixer_lock; 132 spinlock_t mixer_lock;
139 spinlock_t ctrl_lock;
140#ifdef CONFIG_PM 133#ifdef CONFIG_PM
141 unsigned char pm_reg; 134 unsigned char pm_reg;
142#endif 135#endif
143};
144
145struct snd_audiodrive {
146 struct snd_es18xx *chip;
147#ifdef CONFIG_PNP 136#ifdef CONFIG_PNP
148 struct pnp_dev *dev; 137 struct pnp_dev *dev;
149 struct pnp_dev *devc; 138 struct pnp_dev *devc;
@@ -359,7 +348,7 @@ static inline int snd_es18xx_mixer_writable(struct snd_es18xx *chip, unsigned ch
359} 348}
360 349
361 350
362static int snd_es18xx_reset(struct snd_es18xx *chip) 351static int __devinit snd_es18xx_reset(struct snd_es18xx *chip)
363{ 352{
364 int i; 353 int i;
365 outb(0x03, chip->port + 0x06); 354 outb(0x03, chip->port + 0x06);
@@ -495,8 +484,6 @@ static int snd_es18xx_playback1_prepare(struct snd_es18xx *chip,
495 unsigned int size = snd_pcm_lib_buffer_bytes(substream); 484 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
496 unsigned int count = snd_pcm_lib_period_bytes(substream); 485 unsigned int count = snd_pcm_lib_period_bytes(substream);
497 486
498 chip->dma2_size = size;
499
500 snd_es18xx_rate_set(chip, substream, DAC2); 487 snd_es18xx_rate_set(chip, substream, DAC2);
501 488
502 /* Transfer Count Reload */ 489 /* Transfer Count Reload */
@@ -596,8 +583,6 @@ static int snd_es18xx_capture_prepare(struct snd_pcm_substream *substream)
596 unsigned int size = snd_pcm_lib_buffer_bytes(substream); 583 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
597 unsigned int count = snd_pcm_lib_period_bytes(substream); 584 unsigned int count = snd_pcm_lib_period_bytes(substream);
598 585
599 chip->dma1_size = size;
600
601 snd_es18xx_reset_fifo(chip); 586 snd_es18xx_reset_fifo(chip);
602 587
603 /* Set stereo/mono */ 588 /* Set stereo/mono */
@@ -664,8 +649,6 @@ static int snd_es18xx_playback2_prepare(struct snd_es18xx *chip,
664 unsigned int size = snd_pcm_lib_buffer_bytes(substream); 649 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
665 unsigned int count = snd_pcm_lib_period_bytes(substream); 650 unsigned int count = snd_pcm_lib_period_bytes(substream);
666 651
667 chip->dma1_size = size;
668
669 snd_es18xx_reset_fifo(chip); 652 snd_es18xx_reset_fifo(chip);
670 653
671 /* Set stereo/mono */ 654 /* Set stereo/mono */
@@ -755,7 +738,8 @@ static int snd_es18xx_playback_trigger(struct snd_pcm_substream *substream,
755 738
756static irqreturn_t snd_es18xx_interrupt(int irq, void *dev_id) 739static irqreturn_t snd_es18xx_interrupt(int irq, void *dev_id)
757{ 740{
758 struct snd_es18xx *chip = dev_id; 741 struct snd_card *card = dev_id;
742 struct snd_es18xx *chip = card->private_data;
759 unsigned char status; 743 unsigned char status;
760 744
761 if (chip->caps & ES18XX_CONTROL) { 745 if (chip->caps & ES18XX_CONTROL) {
@@ -805,12 +789,16 @@ static irqreturn_t snd_es18xx_interrupt(int irq, void *dev_id)
805 int split = 0; 789 int split = 0;
806 if (chip->caps & ES18XX_HWV) { 790 if (chip->caps & ES18XX_HWV) {
807 split = snd_es18xx_mixer_read(chip, 0x64) & 0x80; 791 split = snd_es18xx_mixer_read(chip, 0x64) & 0x80;
808 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->hw_switch->id); 792 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
809 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->hw_volume->id); 793 &chip->hw_switch->id);
794 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
795 &chip->hw_volume->id);
810 } 796 }
811 if (!split) { 797 if (!split) {
812 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->master_switch->id); 798 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
813 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->master_volume->id); 799 &chip->master_switch->id);
800 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
801 &chip->master_volume->id);
814 } 802 }
815 /* ack interrupt */ 803 /* ack interrupt */
816 snd_es18xx_mixer_write(chip, 0x66, 0x00); 804 snd_es18xx_mixer_write(chip, 0x66, 0x00);
@@ -821,17 +809,18 @@ static irqreturn_t snd_es18xx_interrupt(int irq, void *dev_id)
821static snd_pcm_uframes_t snd_es18xx_playback_pointer(struct snd_pcm_substream *substream) 809static snd_pcm_uframes_t snd_es18xx_playback_pointer(struct snd_pcm_substream *substream)
822{ 810{
823 struct snd_es18xx *chip = snd_pcm_substream_chip(substream); 811 struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
812 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
824 int pos; 813 int pos;
825 814
826 if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) { 815 if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) {
827 if (!(chip->active & DAC2)) 816 if (!(chip->active & DAC2))
828 return 0; 817 return 0;
829 pos = snd_dma_pointer(chip->dma2, chip->dma2_size); 818 pos = snd_dma_pointer(chip->dma2, size);
830 return pos >> chip->dma2_shift; 819 return pos >> chip->dma2_shift;
831 } else { 820 } else {
832 if (!(chip->active & DAC1)) 821 if (!(chip->active & DAC1))
833 return 0; 822 return 0;
834 pos = snd_dma_pointer(chip->dma1, chip->dma1_size); 823 pos = snd_dma_pointer(chip->dma1, size);
835 return pos >> chip->dma1_shift; 824 return pos >> chip->dma1_shift;
836 } 825 }
837} 826}
@@ -839,11 +828,12 @@ static snd_pcm_uframes_t snd_es18xx_playback_pointer(struct snd_pcm_substream *s
839static snd_pcm_uframes_t snd_es18xx_capture_pointer(struct snd_pcm_substream *substream) 828static snd_pcm_uframes_t snd_es18xx_capture_pointer(struct snd_pcm_substream *substream)
840{ 829{
841 struct snd_es18xx *chip = snd_pcm_substream_chip(substream); 830 struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
831 unsigned int size = snd_pcm_lib_buffer_bytes(substream);
842 int pos; 832 int pos;
843 833
844 if (!(chip->active & ADC1)) 834 if (!(chip->active & ADC1))
845 return 0; 835 return 0;
846 pos = snd_dma_pointer(chip->dma1, chip->dma1_size); 836 pos = snd_dma_pointer(chip->dma1, size);
847 return pos >> chip->dma1_shift; 837 return pos >> chip->dma1_shift;
848} 838}
849 839
@@ -974,9 +964,6 @@ static int snd_es18xx_capture_close(struct snd_pcm_substream *substream)
974 964
975static int snd_es18xx_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 965static int snd_es18xx_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
976{ 966{
977 static char *texts4Source[4] = {
978 "Mic", "CD", "Line", "Master"
979 };
980 static char *texts5Source[5] = { 967 static char *texts5Source[5] = {
981 "Mic", "CD", "Line", "Master", "Mix" 968 "Mic", "CD", "Line", "Master", "Mix"
982 }; 969 };
@@ -994,7 +981,8 @@ static int snd_es18xx_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_ele
994 uinfo->value.enumerated.items = 4; 981 uinfo->value.enumerated.items = 4;
995 if (uinfo->value.enumerated.item > 3) 982 if (uinfo->value.enumerated.item > 3)
996 uinfo->value.enumerated.item = 3; 983 uinfo->value.enumerated.item = 3;
997 strcpy(uinfo->value.enumerated.name, texts4Source[uinfo->value.enumerated.item]); 984 strcpy(uinfo->value.enumerated.name,
985 texts5Source[uinfo->value.enumerated.item]);
998 break; 986 break;
999 case 0x1887: 987 case 0x1887:
1000 case 0x1888: 988 case 0x1888:
@@ -1313,7 +1301,7 @@ ES18XX_DOUBLE("Aux Capture Volume", 0, 0x6c, 0x6c, 4, 0, 15, 0)
1313 * The chipset specific mixer controls 1301 * The chipset specific mixer controls
1314 */ 1302 */
1315static struct snd_kcontrol_new snd_es18xx_opt_speaker = 1303static struct snd_kcontrol_new snd_es18xx_opt_speaker =
1316 ES18XX_SINGLE("PC Speaker Playback Volume", 0, 0x3c, 0, 7, 0); 1304 ES18XX_SINGLE("Beep Playback Volume", 0, 0x3c, 0, 7, 0);
1317 1305
1318static struct snd_kcontrol_new snd_es18xx_opt_1869[] = { 1306static struct snd_kcontrol_new snd_es18xx_opt_1869[] = {
1319ES18XX_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1), 1307ES18XX_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1),
@@ -1378,11 +1366,9 @@ ES18XX_SINGLE("Hardware Master Volume Split", 0, 0x64, 7, 1, 0),
1378static int __devinit snd_es18xx_config_read(struct snd_es18xx *chip, unsigned char reg) 1366static int __devinit snd_es18xx_config_read(struct snd_es18xx *chip, unsigned char reg)
1379{ 1367{
1380 int data; 1368 int data;
1381 unsigned long flags; 1369
1382 spin_lock_irqsave(&chip->ctrl_lock, flags);
1383 outb(reg, chip->ctrl_port); 1370 outb(reg, chip->ctrl_port);
1384 data = inb(chip->ctrl_port + 1); 1371 data = inb(chip->ctrl_port + 1);
1385 spin_unlock_irqrestore(&chip->ctrl_lock, flags);
1386 return data; 1372 return data;
1387} 1373}
1388 1374
@@ -1398,7 +1384,9 @@ static void __devinit snd_es18xx_config_write(struct snd_es18xx *chip,
1398#endif 1384#endif
1399} 1385}
1400 1386
1401static int __devinit snd_es18xx_initialize(struct snd_es18xx *chip) 1387static int __devinit snd_es18xx_initialize(struct snd_es18xx *chip,
1388 unsigned long mpu_port,
1389 unsigned long fm_port)
1402{ 1390{
1403 int mask = 0; 1391 int mask = 0;
1404 1392
@@ -1412,15 +1400,15 @@ static int __devinit snd_es18xx_initialize(struct snd_es18xx *chip)
1412 if (chip->caps & ES18XX_CONTROL) { 1400 if (chip->caps & ES18XX_CONTROL) {
1413 /* Hardware volume IRQ */ 1401 /* Hardware volume IRQ */
1414 snd_es18xx_config_write(chip, 0x27, chip->irq); 1402 snd_es18xx_config_write(chip, 0x27, chip->irq);
1415 if (chip->fm_port > 0 && chip->fm_port != SNDRV_AUTO_PORT) { 1403 if (fm_port > 0 && fm_port != SNDRV_AUTO_PORT) {
1416 /* FM I/O */ 1404 /* FM I/O */
1417 snd_es18xx_config_write(chip, 0x62, chip->fm_port >> 8); 1405 snd_es18xx_config_write(chip, 0x62, fm_port >> 8);
1418 snd_es18xx_config_write(chip, 0x63, chip->fm_port & 0xff); 1406 snd_es18xx_config_write(chip, 0x63, fm_port & 0xff);
1419 } 1407 }
1420 if (chip->mpu_port > 0 && chip->mpu_port != SNDRV_AUTO_PORT) { 1408 if (mpu_port > 0 && mpu_port != SNDRV_AUTO_PORT) {
1421 /* MPU-401 I/O */ 1409 /* MPU-401 I/O */
1422 snd_es18xx_config_write(chip, 0x64, chip->mpu_port >> 8); 1410 snd_es18xx_config_write(chip, 0x64, mpu_port >> 8);
1423 snd_es18xx_config_write(chip, 0x65, chip->mpu_port & 0xff); 1411 snd_es18xx_config_write(chip, 0x65, mpu_port & 0xff);
1424 /* MPU-401 IRQ */ 1412 /* MPU-401 IRQ */
1425 snd_es18xx_config_write(chip, 0x28, chip->irq); 1413 snd_es18xx_config_write(chip, 0x28, chip->irq);
1426 } 1414 }
@@ -1507,11 +1495,12 @@ static int __devinit snd_es18xx_initialize(struct snd_es18xx *chip)
1507 snd_es18xx_mixer_write(chip, 0x7A, 0x68); 1495 snd_es18xx_mixer_write(chip, 0x7A, 0x68);
1508 /* Enable and set hardware volume interrupt */ 1496 /* Enable and set hardware volume interrupt */
1509 snd_es18xx_mixer_write(chip, 0x64, 0x06); 1497 snd_es18xx_mixer_write(chip, 0x64, 0x06);
1510 if (chip->mpu_port > 0 && chip->mpu_port != SNDRV_AUTO_PORT) { 1498 if (mpu_port > 0 && mpu_port != SNDRV_AUTO_PORT) {
1511 /* MPU401 share irq with audio 1499 /* MPU401 share irq with audio
1512 Joystick enabled 1500 Joystick enabled
1513 FM enabled */ 1501 FM enabled */
1514 snd_es18xx_mixer_write(chip, 0x40, 0x43 | (chip->mpu_port & 0xf0) >> 1); 1502 snd_es18xx_mixer_write(chip, 0x40,
1503 0x43 | (mpu_port & 0xf0) >> 1);
1515 } 1504 }
1516 snd_es18xx_mixer_write(chip, 0x7f, ((irqmask + 1) << 1) | 0x01); 1505 snd_es18xx_mixer_write(chip, 0x7f, ((irqmask + 1) << 1) | 0x01);
1517 } 1506 }
@@ -1629,7 +1618,9 @@ static int __devinit snd_es18xx_identify(struct snd_es18xx *chip)
1629 return 0; 1618 return 0;
1630} 1619}
1631 1620
1632static int __devinit snd_es18xx_probe(struct snd_es18xx *chip) 1621static int __devinit snd_es18xx_probe(struct snd_es18xx *chip,
1622 unsigned long mpu_port,
1623 unsigned long fm_port)
1633{ 1624{
1634 if (snd_es18xx_identify(chip) < 0) { 1625 if (snd_es18xx_identify(chip) < 0) {
1635 snd_printk(KERN_ERR PFX "[0x%lx] ESS chip not found\n", chip->port); 1626 snd_printk(KERN_ERR PFX "[0x%lx] ESS chip not found\n", chip->port);
@@ -1650,8 +1641,6 @@ static int __devinit snd_es18xx_probe(struct snd_es18xx *chip)
1650 chip->caps = ES18XX_PCM2 | ES18XX_SPATIALIZER | ES18XX_RECMIX | ES18XX_NEW_RATE | ES18XX_AUXB | ES18XX_I2S | ES18XX_CONTROL | ES18XX_HWV; 1641 chip->caps = ES18XX_PCM2 | ES18XX_SPATIALIZER | ES18XX_RECMIX | ES18XX_NEW_RATE | ES18XX_AUXB | ES18XX_I2S | ES18XX_CONTROL | ES18XX_HWV;
1651 break; 1642 break;
1652 case 0x1887: 1643 case 0x1887:
1653 chip->caps = ES18XX_PCM2 | ES18XX_RECMIX | ES18XX_AUXB | ES18XX_DUPLEX_SAME;
1654 break;
1655 case 0x1888: 1644 case 0x1888:
1656 chip->caps = ES18XX_PCM2 | ES18XX_RECMIX | ES18XX_AUXB | ES18XX_DUPLEX_SAME; 1645 chip->caps = ES18XX_PCM2 | ES18XX_RECMIX | ES18XX_AUXB | ES18XX_DUPLEX_SAME;
1657 break; 1646 break;
@@ -1666,7 +1655,7 @@ static int __devinit snd_es18xx_probe(struct snd_es18xx *chip)
1666 if (chip->dma1 == chip->dma2) 1655 if (chip->dma1 == chip->dma2)
1667 chip->caps &= ~(ES18XX_PCM2 | ES18XX_DUPLEX_SAME); 1656 chip->caps &= ~(ES18XX_PCM2 | ES18XX_DUPLEX_SAME);
1668 1657
1669 return snd_es18xx_initialize(chip); 1658 return snd_es18xx_initialize(chip, mpu_port, fm_port);
1670} 1659}
1671 1660
1672static struct snd_pcm_ops snd_es18xx_playback_ops = { 1661static struct snd_pcm_ops snd_es18xx_playback_ops = {
@@ -1691,8 +1680,10 @@ static struct snd_pcm_ops snd_es18xx_capture_ops = {
1691 .pointer = snd_es18xx_capture_pointer, 1680 .pointer = snd_es18xx_capture_pointer,
1692}; 1681};
1693 1682
1694static int __devinit snd_es18xx_pcm(struct snd_es18xx *chip, int device, struct snd_pcm ** rpcm) 1683static int __devinit snd_es18xx_pcm(struct snd_card *card, int device,
1684 struct snd_pcm **rpcm)
1695{ 1685{
1686 struct snd_es18xx *chip = card->private_data;
1696 struct snd_pcm *pcm; 1687 struct snd_pcm *pcm;
1697 char str[16]; 1688 char str[16];
1698 int err; 1689 int err;
@@ -1701,9 +1692,9 @@ static int __devinit snd_es18xx_pcm(struct snd_es18xx *chip, int device, struct
1701 *rpcm = NULL; 1692 *rpcm = NULL;
1702 sprintf(str, "ES%x", chip->version); 1693 sprintf(str, "ES%x", chip->version);
1703 if (chip->caps & ES18XX_PCM2) 1694 if (chip->caps & ES18XX_PCM2)
1704 err = snd_pcm_new(chip->card, str, device, 2, 1, &pcm); 1695 err = snd_pcm_new(card, str, device, 2, 1, &pcm);
1705 else 1696 else
1706 err = snd_pcm_new(chip->card, str, device, 1, 1, &pcm); 1697 err = snd_pcm_new(card, str, device, 1, 1, &pcm);
1707 if (err < 0) 1698 if (err < 0)
1708 return err; 1699 return err;
1709 1700
@@ -1734,10 +1725,9 @@ static int __devinit snd_es18xx_pcm(struct snd_es18xx *chip, int device, struct
1734#ifdef CONFIG_PM 1725#ifdef CONFIG_PM
1735static int snd_es18xx_suspend(struct snd_card *card, pm_message_t state) 1726static int snd_es18xx_suspend(struct snd_card *card, pm_message_t state)
1736{ 1727{
1737 struct snd_audiodrive *acard = card->private_data; 1728 struct snd_es18xx *chip = card->private_data;
1738 struct snd_es18xx *chip = acard->chip;
1739 1729
1740 snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot); 1730 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
1741 1731
1742 snd_pcm_suspend_all(chip->pcm); 1732 snd_pcm_suspend_all(chip->pcm);
1743 1733
@@ -1752,24 +1742,25 @@ static int snd_es18xx_suspend(struct snd_card *card, pm_message_t state)
1752 1742
1753static int snd_es18xx_resume(struct snd_card *card) 1743static int snd_es18xx_resume(struct snd_card *card)
1754{ 1744{
1755 struct snd_audiodrive *acard = card->private_data; 1745 struct snd_es18xx *chip = card->private_data;
1756 struct snd_es18xx *chip = acard->chip;
1757 1746
1758 /* restore PM register, we won't wake till (not 0x07) i/o activity though */ 1747 /* restore PM register, we won't wake till (not 0x07) i/o activity though */
1759 snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg ^= ES18XX_PM_FM); 1748 snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg ^= ES18XX_PM_FM);
1760 1749
1761 snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0); 1750 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
1762 return 0; 1751 return 0;
1763} 1752}
1764#endif /* CONFIG_PM */ 1753#endif /* CONFIG_PM */
1765 1754
1766static int snd_es18xx_free(struct snd_es18xx *chip) 1755static int snd_es18xx_free(struct snd_card *card)
1767{ 1756{
1757 struct snd_es18xx *chip = card->private_data;
1758
1768 release_and_free_resource(chip->res_port); 1759 release_and_free_resource(chip->res_port);
1769 release_and_free_resource(chip->res_ctrl_port); 1760 release_and_free_resource(chip->res_ctrl_port);
1770 release_and_free_resource(chip->res_mpu_port); 1761 release_and_free_resource(chip->res_mpu_port);
1771 if (chip->irq >= 0) 1762 if (chip->irq >= 0)
1772 free_irq(chip->irq, (void *) chip); 1763 free_irq(chip->irq, (void *) card);
1773 if (chip->dma1 >= 0) { 1764 if (chip->dma1 >= 0) {
1774 disable_dma(chip->dma1); 1765 disable_dma(chip->dma1);
1775 free_dma(chip->dma1); 1766 free_dma(chip->dma1);
@@ -1778,93 +1769,82 @@ static int snd_es18xx_free(struct snd_es18xx *chip)
1778 disable_dma(chip->dma2); 1769 disable_dma(chip->dma2);
1779 free_dma(chip->dma2); 1770 free_dma(chip->dma2);
1780 } 1771 }
1781 kfree(chip);
1782 return 0; 1772 return 0;
1783} 1773}
1784 1774
1785static int snd_es18xx_dev_free(struct snd_device *device) 1775static int snd_es18xx_dev_free(struct snd_device *device)
1786{ 1776{
1787 struct snd_es18xx *chip = device->device_data; 1777 return snd_es18xx_free(device->card);
1788 return snd_es18xx_free(chip);
1789} 1778}
1790 1779
1791static int __devinit snd_es18xx_new_device(struct snd_card *card, 1780static int __devinit snd_es18xx_new_device(struct snd_card *card,
1792 unsigned long port, 1781 unsigned long port,
1793 unsigned long mpu_port, 1782 unsigned long mpu_port,
1794 unsigned long fm_port, 1783 unsigned long fm_port,
1795 int irq, int dma1, int dma2, 1784 int irq, int dma1, int dma2)
1796 struct snd_es18xx ** rchip)
1797{ 1785{
1798 struct snd_es18xx *chip; 1786 struct snd_es18xx *chip = card->private_data;
1799 static struct snd_device_ops ops = { 1787 static struct snd_device_ops ops = {
1800 .dev_free = snd_es18xx_dev_free, 1788 .dev_free = snd_es18xx_dev_free,
1801 }; 1789 };
1802 int err; 1790 int err;
1803 1791
1804 *rchip = NULL;
1805 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1806 if (chip == NULL)
1807 return -ENOMEM;
1808 spin_lock_init(&chip->reg_lock); 1792 spin_lock_init(&chip->reg_lock);
1809 spin_lock_init(&chip->mixer_lock); 1793 spin_lock_init(&chip->mixer_lock);
1810 spin_lock_init(&chip->ctrl_lock);
1811 chip->card = card;
1812 chip->port = port; 1794 chip->port = port;
1813 chip->mpu_port = mpu_port;
1814 chip->fm_port = fm_port;
1815 chip->irq = -1; 1795 chip->irq = -1;
1816 chip->dma1 = -1; 1796 chip->dma1 = -1;
1817 chip->dma2 = -1; 1797 chip->dma2 = -1;
1818 chip->audio2_vol = 0x00; 1798 chip->audio2_vol = 0x00;
1819 chip->active = 0; 1799 chip->active = 0;
1820 1800
1821 if ((chip->res_port = request_region(port, 16, "ES18xx")) == NULL) { 1801 chip->res_port = request_region(port, 16, "ES18xx");
1822 snd_es18xx_free(chip); 1802 if (chip->res_port == NULL) {
1803 snd_es18xx_free(card);
1823 snd_printk(KERN_ERR PFX "unable to grap ports 0x%lx-0x%lx\n", port, port + 16 - 1); 1804 snd_printk(KERN_ERR PFX "unable to grap ports 0x%lx-0x%lx\n", port, port + 16 - 1);
1824 return -EBUSY; 1805 return -EBUSY;
1825 } 1806 }
1826 1807
1827 if (request_irq(irq, snd_es18xx_interrupt, IRQF_DISABLED, "ES18xx", (void *) chip)) { 1808 if (request_irq(irq, snd_es18xx_interrupt, IRQF_DISABLED, "ES18xx",
1828 snd_es18xx_free(chip); 1809 (void *) card)) {
1810 snd_es18xx_free(card);
1829 snd_printk(KERN_ERR PFX "unable to grap IRQ %d\n", irq); 1811 snd_printk(KERN_ERR PFX "unable to grap IRQ %d\n", irq);
1830 return -EBUSY; 1812 return -EBUSY;
1831 } 1813 }
1832 chip->irq = irq; 1814 chip->irq = irq;
1833 1815
1834 if (request_dma(dma1, "ES18xx DMA 1")) { 1816 if (request_dma(dma1, "ES18xx DMA 1")) {
1835 snd_es18xx_free(chip); 1817 snd_es18xx_free(card);
1836 snd_printk(KERN_ERR PFX "unable to grap DMA1 %d\n", dma1); 1818 snd_printk(KERN_ERR PFX "unable to grap DMA1 %d\n", dma1);
1837 return -EBUSY; 1819 return -EBUSY;
1838 } 1820 }
1839 chip->dma1 = dma1; 1821 chip->dma1 = dma1;
1840 1822
1841 if (dma2 != dma1 && request_dma(dma2, "ES18xx DMA 2")) { 1823 if (dma2 != dma1 && request_dma(dma2, "ES18xx DMA 2")) {
1842 snd_es18xx_free(chip); 1824 snd_es18xx_free(card);
1843 snd_printk(KERN_ERR PFX "unable to grap DMA2 %d\n", dma2); 1825 snd_printk(KERN_ERR PFX "unable to grap DMA2 %d\n", dma2);
1844 return -EBUSY; 1826 return -EBUSY;
1845 } 1827 }
1846 chip->dma2 = dma2; 1828 chip->dma2 = dma2;
1847 1829
1848 if (snd_es18xx_probe(chip) < 0) { 1830 if (snd_es18xx_probe(chip, mpu_port, fm_port) < 0) {
1849 snd_es18xx_free(chip); 1831 snd_es18xx_free(card);
1850 return -ENODEV; 1832 return -ENODEV;
1851 } 1833 }
1852 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { 1834 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
1853 snd_es18xx_free(chip); 1835 if (err < 0) {
1836 snd_es18xx_free(card);
1854 return err; 1837 return err;
1855 } 1838 }
1856 *rchip = chip;
1857 return 0; 1839 return 0;
1858} 1840}
1859 1841
1860static int __devinit snd_es18xx_mixer(struct snd_es18xx *chip) 1842static int __devinit snd_es18xx_mixer(struct snd_card *card)
1861{ 1843{
1862 struct snd_card *card; 1844 struct snd_es18xx *chip = card->private_data;
1863 int err; 1845 int err;
1864 unsigned int idx; 1846 unsigned int idx;
1865 1847
1866 card = chip->card;
1867
1868 strcpy(card->mixername, chip->pcm->name); 1848 strcpy(card->mixername, chip->pcm->name);
1869 1849
1870 for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_base_controls); idx++) { 1850 for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_base_controls); idx++) {
@@ -1986,7 +1966,7 @@ static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
1986static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 1966static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
1987static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */ 1967static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
1988#ifdef CONFIG_PNP 1968#ifdef CONFIG_PNP
1989static int isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; 1969static int isapnp[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP;
1990#endif 1970#endif
1991static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260,0x280 */ 1971static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260,0x280 */
1992#ifndef CONFIG_PNP 1972#ifndef CONFIG_PNP
@@ -2063,11 +2043,11 @@ static int __devinit snd_audiodrive_pnp_init_main(int dev, struct pnp_dev *pdev)
2063 return 0; 2043 return 0;
2064} 2044}
2065 2045
2066static int __devinit snd_audiodrive_pnp(int dev, struct snd_audiodrive *acard, 2046static int __devinit snd_audiodrive_pnp(int dev, struct snd_es18xx *chip,
2067 struct pnp_dev *pdev) 2047 struct pnp_dev *pdev)
2068{ 2048{
2069 acard->dev = pdev; 2049 chip->dev = pdev;
2070 if (snd_audiodrive_pnp_init_main(dev, acard->dev) < 0) 2050 if (snd_audiodrive_pnp_init_main(dev, chip->dev) < 0)
2071 return -EBUSY; 2051 return -EBUSY;
2072 return 0; 2052 return 0;
2073} 2053}
@@ -2093,26 +2073,26 @@ static struct pnp_card_device_id snd_audiodrive_pnpids[] = {
2093 2073
2094MODULE_DEVICE_TABLE(pnp_card, snd_audiodrive_pnpids); 2074MODULE_DEVICE_TABLE(pnp_card, snd_audiodrive_pnpids);
2095 2075
2096static int __devinit snd_audiodrive_pnpc(int dev, struct snd_audiodrive *acard, 2076static int __devinit snd_audiodrive_pnpc(int dev, struct snd_es18xx *chip,
2097 struct pnp_card_link *card, 2077 struct pnp_card_link *card,
2098 const struct pnp_card_device_id *id) 2078 const struct pnp_card_device_id *id)
2099{ 2079{
2100 acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL); 2080 chip->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
2101 if (acard->dev == NULL) 2081 if (chip->dev == NULL)
2102 return -EBUSY; 2082 return -EBUSY;
2103 2083
2104 acard->devc = pnp_request_card_device(card, id->devs[1].id, NULL); 2084 chip->devc = pnp_request_card_device(card, id->devs[1].id, NULL);
2105 if (acard->devc == NULL) 2085 if (chip->devc == NULL)
2106 return -EBUSY; 2086 return -EBUSY;
2107 2087
2108 /* Control port initialization */ 2088 /* Control port initialization */
2109 if (pnp_activate_dev(acard->devc) < 0) { 2089 if (pnp_activate_dev(chip->devc) < 0) {
2110 snd_printk(KERN_ERR PFX "PnP control configure failure (out of resources?)\n"); 2090 snd_printk(KERN_ERR PFX "PnP control configure failure (out of resources?)\n");
2111 return -EAGAIN; 2091 return -EAGAIN;
2112 } 2092 }
2113 snd_printdd("pnp: port=0x%llx\n", 2093 snd_printdd("pnp: port=0x%llx\n",
2114 (unsigned long long)pnp_port_start(acard->devc, 0)); 2094 (unsigned long long)pnp_port_start(chip->devc, 0));
2115 if (snd_audiodrive_pnp_init_main(dev, acard->dev) < 0) 2095 if (snd_audiodrive_pnp_init_main(dev, chip->dev) < 0)
2116 return -EBUSY; 2096 return -EBUSY;
2117 2097
2118 return 0; 2098 return 0;
@@ -2128,24 +2108,20 @@ static int __devinit snd_audiodrive_pnpc(int dev, struct snd_audiodrive *acard,
2128static int snd_es18xx_card_new(int dev, struct snd_card **cardp) 2108static int snd_es18xx_card_new(int dev, struct snd_card **cardp)
2129{ 2109{
2130 return snd_card_create(index[dev], id[dev], THIS_MODULE, 2110 return snd_card_create(index[dev], id[dev], THIS_MODULE,
2131 sizeof(struct snd_audiodrive), cardp); 2111 sizeof(struct snd_es18xx), cardp);
2132} 2112}
2133 2113
2134static int __devinit snd_audiodrive_probe(struct snd_card *card, int dev) 2114static int __devinit snd_audiodrive_probe(struct snd_card *card, int dev)
2135{ 2115{
2136 struct snd_audiodrive *acard = card->private_data; 2116 struct snd_es18xx *chip = card->private_data;
2137 struct snd_es18xx *chip;
2138 struct snd_opl3 *opl3; 2117 struct snd_opl3 *opl3;
2139 int err; 2118 int err;
2140 2119
2141 if ((err = snd_es18xx_new_device(card, 2120 err = snd_es18xx_new_device(card,
2142 port[dev], 2121 port[dev], mpu_port[dev], fm_port[dev],
2143 mpu_port[dev], 2122 irq[dev], dma1[dev], dma2[dev]);
2144 fm_port[dev], 2123 if (err < 0)
2145 irq[dev], dma1[dev], dma2[dev],
2146 &chip)) < 0)
2147 return err; 2124 return err;
2148 acard->chip = chip;
2149 2125
2150 sprintf(card->driver, "ES%x", chip->version); 2126 sprintf(card->driver, "ES%x", chip->version);
2151 2127
@@ -2161,26 +2137,32 @@ static int __devinit snd_audiodrive_probe(struct snd_card *card, int dev)
2161 chip->port, 2137 chip->port,
2162 irq[dev], dma1[dev]); 2138 irq[dev], dma1[dev]);
2163 2139
2164 if ((err = snd_es18xx_pcm(chip, 0, NULL)) < 0) 2140 err = snd_es18xx_pcm(card, 0, NULL);
2141 if (err < 0)
2165 return err; 2142 return err;
2166 2143
2167 if ((err = snd_es18xx_mixer(chip)) < 0) 2144 err = snd_es18xx_mixer(card);
2145 if (err < 0)
2168 return err; 2146 return err;
2169 2147
2170 if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) { 2148 if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
2171 if (snd_opl3_create(card, chip->fm_port, chip->fm_port + 2, OPL3_HW_OPL3, 0, &opl3) < 0) { 2149 if (snd_opl3_create(card, fm_port[dev], fm_port[dev] + 2,
2172 snd_printk(KERN_WARNING PFX "opl3 not detected at 0x%lx\n", chip->fm_port); 2150 OPL3_HW_OPL3, 0, &opl3) < 0) {
2151 snd_printk(KERN_WARNING PFX
2152 "opl3 not detected at 0x%lx\n",
2153 fm_port[dev]);
2173 } else { 2154 } else {
2174 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) 2155 err = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
2156 if (err < 0)
2175 return err; 2157 return err;
2176 } 2158 }
2177 } 2159 }
2178 2160
2179 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) { 2161 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
2180 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ES18XX, 2162 err = snd_mpu401_uart_new(card, 0, MPU401_HW_ES18XX,
2181 chip->mpu_port, 0, 2163 mpu_port[dev], 0,
2182 irq[dev], 0, 2164 irq[dev], 0, &chip->rmidi);
2183 &chip->rmidi)) < 0) 2165 if (err < 0)
2184 return err; 2166 return err;
2185 } 2167 }
2186 2168