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