aboutsummaryrefslogtreecommitdiffstats
path: root/sound/isa
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2005-11-17 11:13:59 -0500
committerJaroslav Kysela <perex@suse.cz>2006-01-03 06:28:37 -0500
commit99a0b7687ef991a577506a1974be146f02f18d74 (patch)
treeef92d7b1898b8a017decf6fd8c20fc6e1ffce6b2 /sound/isa
parent654aa661779703d3b22ba04a83ddeb1a0dd7a09a (diff)
[ALSA] opti9xx - Use platform_device
Modules: Opti9xx drivers Rewrite the probe/remove with platform_device. Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/isa')
-rw-r--r--sound/isa/opti9xx/opti92x-ad1848.c507
1 files changed, 209 insertions, 298 deletions
diff --git a/sound/isa/opti9xx/opti92x-ad1848.c b/sound/isa/opti9xx/opti92x-ad1848.c
index fddf7b9549ba..39211e58cd68 100644
--- a/sound/isa/opti9xx/opti92x-ad1848.c
+++ b/sound/isa/opti9xx/opti92x-ad1848.c
@@ -24,13 +24,15 @@
24 24
25 25
26#include <sound/driver.h> 26#include <sound/driver.h>
27#include <asm/io.h>
28#include <asm/dma.h>
29#include <linux/delay.h>
30#include <linux/init.h> 27#include <linux/init.h>
28#include <linux/err.h>
29#include <linux/platform_device.h>
30#include <linux/delay.h>
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/pnp.h> 32#include <linux/pnp.h>
33#include <linux/moduleparam.h> 33#include <linux/moduleparam.h>
34#include <asm/io.h>
35#include <asm/dma.h>
34#include <sound/core.h> 36#include <sound/core.h>
35#ifdef CS4231 37#ifdef CS4231
36#include <sound/cs4231.h> 38#include <sound/cs4231.h>
@@ -256,8 +258,7 @@ struct snd_opti9xx {
256#endif /* CONFIG_PNP */ 258#endif /* CONFIG_PNP */
257}; 259};
258 260
259static int snd_opti9xx_first_hit = 1; 261static int snd_opti9xx_pnp_is_probed;
260static struct snd_card *snd_opti9xx_legacy = SNDRV_DEFAULT_PTR1;
261 262
262#ifdef CONFIG_PNP 263#ifdef CONFIG_PNP
263 264
@@ -292,7 +293,7 @@ static char * snd_opti9xx_names[] = {
292}; 293};
293 294
294 295
295static long snd_legacy_find_free_ioport(long *port_table, long size) 296static long __init snd_legacy_find_free_ioport(long *port_table, long size)
296{ 297{
297 while (*port_table != -1) { 298 while (*port_table != -1) {
298 if (request_region(*port_table, size, "ALSA test")) { 299 if (request_region(*port_table, size, "ALSA test")) {
@@ -304,7 +305,7 @@ static long snd_legacy_find_free_ioport(long *port_table, long size)
304 return -1; 305 return -1;
305} 306}
306 307
307static int __devinit snd_opti9xx_init(struct snd_opti9xx *chip, unsigned short hardware) 308static int __init snd_opti9xx_init(struct snd_opti9xx *chip, unsigned short hardware)
308{ 309{
309 static int opti9xx_mc_size[] = {7, 7, 10, 10, 2, 2, 2}; 310 static int opti9xx_mc_size[] = {7, 7, 10, 10, 2, 2, 2};
310 311
@@ -449,7 +450,7 @@ static void snd_opti9xx_write(struct snd_opti9xx *chip, unsigned char reg,
449 (snd_opti9xx_read(chip, reg) & ~(mask)) | ((value) & (mask))) 450 (snd_opti9xx_read(chip, reg) & ~(mask)) | ((value) & (mask)))
450 451
451 452
452static int __devinit snd_opti9xx_configure(struct snd_opti9xx *chip) 453static int __init snd_opti9xx_configure(struct snd_opti9xx *chip)
453{ 454{
454 unsigned char wss_base_bits; 455 unsigned char wss_base_bits;
455 unsigned char irq_bits; 456 unsigned char irq_bits;
@@ -1620,7 +1621,7 @@ static int snd_opti93x_mixer(struct snd_opti93x *chip)
1620 1621
1621#endif /* OPTi93X */ 1622#endif /* OPTi93X */
1622 1623
1623static int __devinit snd_card_opti9xx_detect(struct snd_card *card, struct snd_opti9xx *chip) 1624static int __init snd_card_opti9xx_detect(struct snd_card *card, struct snd_opti9xx *chip)
1624{ 1625{
1625 int i, err; 1626 int i, err;
1626 1627
@@ -1674,8 +1675,8 @@ static int __devinit snd_card_opti9xx_detect(struct snd_card *card, struct snd_o
1674} 1675}
1675 1676
1676#ifdef CONFIG_PNP 1677#ifdef CONFIG_PNP
1677static int __devinit snd_card_opti9xx_pnp(struct snd_opti9xx *chip, struct pnp_card_link *card, 1678static int __init snd_card_opti9xx_pnp(struct snd_opti9xx *chip, struct pnp_card_link *card,
1678 const struct pnp_card_device_id *pid) 1679 const struct pnp_card_device_id *pid)
1679{ 1680{
1680 struct pnp_dev *pdev; 1681 struct pnp_dev *pdev;
1681 struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL); 1682 struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
@@ -1766,128 +1767,19 @@ static int __devinit snd_card_opti9xx_pnp(struct snd_opti9xx *chip, struct pnp_c
1766} 1767}
1767#endif /* CONFIG_PNP */ 1768#endif /* CONFIG_PNP */
1768 1769
1769#if 0
1770static int __devinit snd_card_opti9xx_resources(struct snd_card_opti9xx *chip,
1771 struct snd_card *card)
1772{
1773 int error, i, pnp = 0;
1774
1775#ifdef CONFIG_PNP
1776 pnp = chip->dev != NULL;
1777#endif /* CONFIG_PNP */
1778
1779#ifndef OPTi93X
1780 if (chip->chip->hardware == OPTi9XX_HW_82C928)
1781 mpu_port = -1;
1782#endif /* OPTi93X */
1783 error = 0;
1784 if (!pnp && (mpu_port == SNDRV_DEFAULT_PORT1)) {
1785 for (i = 0; possible_mpu_ports[i] != -1; i++)
1786 if (!snd_register_ioport(card, possible_mpu_ports[i], 2,
1787 DRIVER_NAME" - MPU-401", NULL)) {
1788 mpu_port = possible_mpu_ports[i];
1789 break;
1790 }
1791 if (mpu_port == SNDRV_DEFAULT_PORT1)
1792 error = -EBUSY;
1793 }
1794 else
1795 error = (mpu_port == -1) ? -ENODEV :
1796 snd_register_ioport(card, mpu_port, 2,
1797 DRIVER_NAME" - MPU-401", NULL);
1798 if (error)
1799 chip->chip->mpu_port = -1;
1800 else if (pnp && (irq == mpu_irq))
1801 chip->chip->mpu_irq = mpu_irq;
1802 else if (!snd_register_interrupt(card,
1803 DRIVER_NAME" - MPU-401",
1804 mpu_irq, SNDRV_IRQ_TYPE_ISA,
1805 snd_card_opti9xx_mpu_interrupt, chip,
1806 pnp ? no_alternatives : possible_mpu_irqs,
1807 &chip->mpuirqptr)) {
1808 chip->chip->mpu_port = mpu_port;
1809 chip->chip->mpu_irq = chip->mpuirqptr->irq;
1810 }
1811 else
1812 chip->chip->mpu_port = -1;
1813
1814 if (!pnp && (port == SNDRV_DEFAULT_PORT1)) {
1815 for (i = 0; possible_ports[i] != -1; i++)
1816 if (!snd_register_ioport(card, possible_ports[i], 8,
1817 DRIVER_NAME" - WSS", NULL)) {
1818 port = possible_ports[i];
1819 break;
1820 }
1821 if (port == SNDRV_DEFAULT_PORT1)
1822 return -EBUSY;
1823 }
1824 else if ((error = snd_register_ioport(card, port, 8,
1825 DRIVER_NAME" - WSS", NULL)) < 0)
1826 return error;
1827 chip->chip->wss_base = port;
1828 if ((error = snd_register_interrupt(card, DRIVER_NAME" - WSS",
1829 irq, SNDRV_IRQ_TYPE_ISA,
1830 snd_card_opti9xx_interrupt, chip,
1831 pnp ? no_alternatives : possible_irqs,
1832 &chip->irqptr)) < 0)
1833 return error;
1834 chip->chip->irq = chip->irqptr->irq;
1835 if ((error = snd_register_dma_channel(card,
1836#if defined(CS4231) || defined(OPTi93X)
1837 DRIVER_NAME" - WSS playback",
1838#else
1839 DRIVER_NAME" - WSS",
1840#endif /* CS4231 || OPTi93X */
1841 dma1, SNDRV_DMA_TYPE_ISA, dma1_size,
1842 pnp ? no_alternatives : possible_dma1s,
1843 &chip->dma1ptr)) < 0)
1844 return error;
1845 chip->chip->dma1 = chip->dma1ptr->dma;
1846#if defined(CS4231) || defined(OPTi93X)
1847 if ((error = snd_register_dma_channel(card, DRIVER_NAME" - WSS capture",
1848 dma2, SNDRV_DMA_TYPE_ISA, dma2_size,
1849 pnp ? no_alternatives :
1850 possible_dma2s[chip->dma1ptr->dma],
1851 &chip->dma2ptr)) < 0)
1852 return error;
1853 chip->chip->dma2 = chip->dma2ptr->dma;
1854#endif /* CS4231 || OPTi93X */
1855
1856 if (snd_register_ioport(card,
1857 pnp ? fm_port : fm_port = 0x388, 4,
1858 DRIVER_NAME" - OPL", NULL) < 0)
1859 fm_port = -1;
1860 chip->chip->fm_port = fm_port;
1861
1862 return 0;
1863}
1864#endif
1865
1866static void snd_card_opti9xx_free(struct snd_card *card) 1770static void snd_card_opti9xx_free(struct snd_card *card)
1867{ 1771{
1868 struct snd_opti9xx *chip = (struct snd_opti9xx *)card->private_data; 1772 struct snd_opti9xx *chip = card->private_data;
1869 1773
1870 if (chip) 1774 if (chip)
1871 release_and_free_resource(chip->res_mc_base); 1775 release_and_free_resource(chip->res_mc_base);
1872} 1776}
1873 1777
1874static int snd_card_opti9xx_probe(struct pnp_card_link *pcard, 1778static int __init snd_opti9xx_probe(struct snd_card *card)
1875 const struct pnp_card_device_id *pid)
1876{ 1779{
1877 static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1}; 1780 static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
1878 static long possible_mpu_ports[] = {0x300, 0x310, 0x320, 0x330, -1};
1879#ifdef OPTi93X
1880 static int possible_irqs[] = {5, 9, 10, 11, 7, -1};
1881#else
1882 static int possible_irqs[] = {9, 10, 11, 7, -1};
1883#endif /* OPTi93X */
1884 static int possible_mpu_irqs[] = {5, 9, 10, 7, -1};
1885 static int possible_dma1s[] = {3, 1, 0, -1};
1886#if defined(CS4231) || defined(OPTi93X)
1887 static int possible_dma2s[][2] = {{1,-1}, {0,-1}, {-1,-1}, {0,-1}};
1888#endif /* CS4231 || OPTi93X */
1889 int error; 1781 int error;
1890 struct snd_opti9xx *chip; 1782 struct snd_opti9xx *chip = card->private_data;
1891#if defined(OPTi93X) 1783#if defined(OPTi93X)
1892 struct snd_opti93x *codec; 1784 struct snd_opti93x *codec;
1893#elif defined(CS4231) 1785#elif defined(CS4231)
@@ -1896,65 +1788,14 @@ static int snd_card_opti9xx_probe(struct pnp_card_link *pcard,
1896#else 1788#else
1897 struct snd_ad1848 *codec; 1789 struct snd_ad1848 *codec;
1898#endif 1790#endif
1899 struct snd_card *card;
1900 struct snd_pcm *pcm; 1791 struct snd_pcm *pcm;
1901 struct snd_rawmidi *rmidi; 1792 struct snd_rawmidi *rmidi;
1902 struct snd_hwdep *synth; 1793 struct snd_hwdep *synth;
1903#ifdef CONFIG_PNP
1904 int hw;
1905#endif /* CONFIG_PNP */
1906
1907 if (pcard && !snd_opti9xx_first_hit)
1908 return -EBUSY;
1909 if (!(card = snd_card_new(index, id, THIS_MODULE,
1910 sizeof(struct snd_opti9xx))))
1911 return -ENOMEM;
1912 card->private_free = snd_card_opti9xx_free;
1913 chip = (struct snd_opti9xx *)card->private_data;
1914
1915#ifdef CONFIG_PNP
1916 if (isapnp && pcard && (hw = snd_card_opti9xx_pnp(chip, pcard, pid)) > 0) {
1917 switch (hw) {
1918 case 0x0924:
1919 hw = OPTi9XX_HW_82C924;
1920 break;
1921 case 0x0925:
1922 hw = OPTi9XX_HW_82C925;
1923 break;
1924 case 0x0931:
1925 hw = OPTi9XX_HW_82C931;
1926 break;
1927 default:
1928 snd_card_free(card);
1929 return -ENODEV;
1930 }
1931
1932 if ((error = snd_opti9xx_init(chip, hw))) {
1933 snd_card_free(card);
1934 return error;
1935 }
1936 if (hw <= OPTi9XX_HW_82C930)
1937 chip->mc_base -= 0x80;
1938 snd_card_set_dev(card, &pcard->card->dev);
1939 } else {
1940#endif /* CONFIG_PNP */
1941 if ((error = snd_card_opti9xx_detect(card, chip)) < 0) {
1942 snd_card_free(card);
1943 return error;
1944 }
1945 if ((error = snd_card_set_generic_dev(card)) < 0) {
1946 snd_card_free(card);
1947 return error;
1948 }
1949#ifdef CONFIG_PNP
1950 }
1951#endif /* CONFIG_PNP */
1952 1794
1953 if (! chip->res_mc_base && 1795 if (! chip->res_mc_base &&
1954 (chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL) { 1796 (chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size,
1955 snd_card_free(card); 1797 "OPTi9xx MC")) == NULL)
1956 return -ENOMEM; 1798 return -ENOMEM;
1957 }
1958 1799
1959 chip->wss_base = port; 1800 chip->wss_base = port;
1960 chip->fm_port = fm_port; 1801 chip->fm_port = fm_port;
@@ -1968,110 +1809,42 @@ static int snd_card_opti9xx_probe(struct pnp_card_link *pcard,
1968 1809
1969 if (chip->wss_base == SNDRV_AUTO_PORT) { 1810 if (chip->wss_base == SNDRV_AUTO_PORT) {
1970 if ((chip->wss_base = snd_legacy_find_free_ioport(possible_ports, 4)) < 0) { 1811 if ((chip->wss_base = snd_legacy_find_free_ioport(possible_ports, 4)) < 0) {
1971 snd_card_free(card);
1972 snd_printk("unable to find a free WSS port\n"); 1812 snd_printk("unable to find a free WSS port\n");
1973 return -EBUSY; 1813 return -EBUSY;
1974 } 1814 }
1975 } 1815 }
1976#ifdef CONFIG_PNP 1816 if ((error = snd_opti9xx_configure(chip)))
1977 if (!isapnp) {
1978#endif
1979 if (chip->mpu_port == SNDRV_AUTO_PORT) {
1980 if ((chip->mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2)) < 0) {
1981 snd_card_free(card);
1982 snd_printk("unable to find a free MPU401 port\n");
1983 return -EBUSY;
1984 }
1985 }
1986 if (chip->irq == SNDRV_AUTO_IRQ) {
1987 if ((chip->irq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
1988 snd_card_free(card);
1989 snd_printk("unable to find a free IRQ\n");
1990 return -EBUSY;
1991 }
1992 }
1993 if (chip->mpu_irq == SNDRV_AUTO_IRQ) {
1994 if ((chip->mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs)) < 0) {
1995 snd_card_free(card);
1996 snd_printk("unable to find a free MPU401 IRQ\n");
1997 return -EBUSY;
1998 }
1999 }
2000 if (chip->dma1 == SNDRV_AUTO_DMA) {
2001 if ((chip->dma1 = snd_legacy_find_free_dma(possible_dma1s)) < 0) {
2002 snd_card_free(card);
2003 snd_printk("unable to find a free DMA1\n");
2004 return -EBUSY;
2005 }
2006 }
2007#if defined(CS4231) || defined(OPTi93X)
2008 if (chip->dma2 == SNDRV_AUTO_DMA) {
2009 if ((chip->dma2 = snd_legacy_find_free_dma(possible_dma2s[chip->dma1 % 4])) < 0) {
2010 snd_card_free(card);
2011 snd_printk("unable to find a free DMA2\n");
2012 return -EBUSY;
2013 }
2014 }
2015#endif
2016
2017#ifdef CONFIG_PNP
2018 }
2019#endif
2020
2021 if ((error = snd_opti9xx_configure(chip))) {
2022 snd_card_free(card);
2023 return error; 1817 return error;
2024 }
2025 1818
2026#if defined(OPTi93X) 1819#if defined(OPTi93X)
2027 if ((error = snd_opti93x_create(card, chip, chip->dma1, chip->dma2, &codec))) { 1820 if ((error = snd_opti93x_create(card, chip, chip->dma1, chip->dma2, &codec)))
2028 snd_card_free(card);
2029 return error; 1821 return error;
2030 } 1822 if ((error = snd_opti93x_pcm(codec, 0, &pcm)) < 0)
2031 if ((error = snd_opti93x_pcm(codec, 0, &pcm)) < 0) {
2032 snd_card_free(card);
2033 return error; 1823 return error;
2034 } 1824 if ((error = snd_opti93x_mixer(codec)) < 0)
2035 if ((error = snd_opti93x_mixer(codec)) < 0) {
2036 snd_card_free(card);
2037 return error; 1825 return error;
2038 }
2039#elif defined(CS4231) 1826#elif defined(CS4231)
2040 if ((error = snd_cs4231_create(card, chip->wss_base + 4, -1, 1827 if ((error = snd_cs4231_create(card, chip->wss_base + 4, -1,
2041 chip->irq, chip->dma1, chip->dma2, 1828 chip->irq, chip->dma1, chip->dma2,
2042 CS4231_HW_DETECT, 1829 CS4231_HW_DETECT,
2043 0, 1830 0,
2044 &codec)) < 0) { 1831 &codec)) < 0)
2045 snd_card_free(card);
2046 return error; 1832 return error;
2047 } 1833 if ((error = snd_cs4231_pcm(codec, 0, &pcm)) < 0)
2048 if ((error = snd_cs4231_pcm(codec, 0, &pcm)) < 0) {
2049 snd_card_free(card);
2050 return error; 1834 return error;
2051 } 1835 if ((error = snd_cs4231_mixer(codec)) < 0)
2052 if ((error = snd_cs4231_mixer(codec)) < 0) {
2053 snd_card_free(card);
2054 return error; 1836 return error;
2055 } 1837 if ((error = snd_cs4231_timer(codec, 0, &timer)) < 0)
2056 if ((error = snd_cs4231_timer(codec, 0, &timer)) < 0) {
2057 snd_card_free(card);
2058 return error; 1838 return error;
2059 }
2060#else 1839#else
2061 if ((error = snd_ad1848_create(card, chip->wss_base + 4, 1840 if ((error = snd_ad1848_create(card, chip->wss_base + 4,
2062 chip->irq, chip->dma1, 1841 chip->irq, chip->dma1,
2063 AD1848_HW_DETECT, &codec)) < 0) { 1842 AD1848_HW_DETECT, &codec)) < 0)
2064 snd_card_free(card);
2065 return error; 1843 return error;
2066 } 1844 if ((error = snd_ad1848_pcm(codec, 0, &pcm)) < 0)
2067 if ((error = snd_ad1848_pcm(codec, 0, &pcm)) < 0) {
2068 snd_card_free(card);
2069 return error; 1845 return error;
2070 } 1846 if ((error = snd_ad1848_mixer(codec)) < 0)
2071 if ((error = snd_ad1848_mixer(codec)) < 0) {
2072 snd_card_free(card);
2073 return error; 1847 return error;
2074 }
2075#endif 1848#endif
2076 strcpy(card->driver, chip->name); 1849 strcpy(card->driver, chip->name);
2077 sprintf(card->shortname, "OPTi %s", card->driver); 1850 sprintf(card->shortname, "OPTi %s", card->driver);
@@ -2091,7 +1864,8 @@ static int snd_card_opti9xx_probe(struct pnp_card_link *pcard,
2091 if ((error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, 1864 if ((error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
2092 chip->mpu_port, 0, chip->mpu_irq, SA_INTERRUPT, 1865 chip->mpu_port, 0, chip->mpu_irq, SA_INTERRUPT,
2093 &rmidi))) 1866 &rmidi)))
2094 snd_printk("no MPU-401 device at 0x%lx?\n", chip->mpu_port); 1867 snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n",
1868 chip->mpu_port);
2095 1869
2096 if (chip->fm_port > 0 && chip->fm_port != SNDRV_AUTO_PORT) { 1870 if (chip->fm_port > 0 && chip->fm_port != SNDRV_AUTO_PORT) {
2097 struct snd_opl3 *opl3 = NULL; 1871 struct snd_opl3 *opl3 = NULL;
@@ -2117,89 +1891,226 @@ static int snd_card_opti9xx_probe(struct pnp_card_link *pcard,
2117 chip->fm_port, 1891 chip->fm_port,
2118 chip->fm_port + 2, 1892 chip->fm_port + 2,
2119 OPL3_HW_AUTO, 0, &opl3) < 0) { 1893 OPL3_HW_AUTO, 0, &opl3) < 0) {
2120 snd_printk("no OPL device at 0x%lx-0x%lx\n", 1894 snd_printk(KERN_WARNING "no OPL device at 0x%lx-0x%lx\n",
2121 chip->fm_port, chip->fm_port + 4 - 1); 1895 chip->fm_port, chip->fm_port + 4 - 1);
2122 } 1896 }
2123 if (opl3) { 1897 if (opl3) {
2124 if ((error = snd_opl3_timer_new(opl3,
2125#ifdef CS4231 1898#ifdef CS4231
2126 1, 2)) < 0) { 1899 const int t1dev = 1;
2127#else 1900#else
2128 0, 1)) < 0) { 1901 const int t1dev = 0;
2129#endif /* CS4231 */ 1902#endif
2130 snd_card_free(card); 1903 if ((error = snd_opl3_timer_new(opl3, t1dev, t1dev+1)) < 0)
2131 return error; 1904 return error;
2132 } 1905 if ((error = snd_opl3_hwdep_new(opl3, 0, 1, &synth)) < 0)
2133 if ((error = snd_opl3_hwdep_new(opl3, 0, 1, &synth)) < 0) {
2134 snd_card_free(card);
2135 return error; 1906 return error;
2136 }
2137 } 1907 }
2138 } 1908 }
2139 1909
2140 if ((error = snd_card_register(card))) { 1910 return snd_card_register(card);
1911}
1912
1913static struct snd_card *snd_opti9xx_card_new(void)
1914{
1915 struct snd_card *card;
1916
1917 card = snd_card_new(index, id, THIS_MODULE, sizeof(struct snd_opti9xx));
1918 if (! card)
1919 return NULL;
1920 card->private_free = snd_card_opti9xx_free;
1921 return card;
1922}
1923
1924static int __init snd_opti9xx_nonpnp_probe(struct platform_device *devptr)
1925{
1926 struct snd_card *card;
1927 int error;
1928 static long possible_mpu_ports[] = {0x300, 0x310, 0x320, 0x330, -1};
1929#ifdef OPTi93X
1930 static int possible_irqs[] = {5, 9, 10, 11, 7, -1};
1931#else
1932 static int possible_irqs[] = {9, 10, 11, 7, -1};
1933#endif /* OPTi93X */
1934 static int possible_mpu_irqs[] = {5, 9, 10, 7, -1};
1935 static int possible_dma1s[] = {3, 1, 0, -1};
1936#if defined(CS4231) || defined(OPTi93X)
1937 static int possible_dma2s[][2] = {{1,-1}, {0,-1}, {-1,-1}, {0,-1}};
1938#endif /* CS4231 || OPTi93X */
1939
1940 if (snd_opti9xx_pnp_is_probed)
1941 return -EBUSY;
1942
1943 if (mpu_port == SNDRV_AUTO_PORT) {
1944 if ((mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2)) < 0) {
1945 snd_printk(KERN_ERR "unable to find a free MPU401 port\n");
1946 return -EBUSY;
1947 }
1948 }
1949 if (irq == SNDRV_AUTO_IRQ) {
1950 if ((irq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
1951 snd_printk(KERN_ERR "unable to find a free IRQ\n");
1952 return -EBUSY;
1953 }
1954 }
1955 if (mpu_irq == SNDRV_AUTO_IRQ) {
1956 if ((mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs)) < 0) {
1957 snd_printk(KERN_ERR "unable to find a free MPU401 IRQ\n");
1958 return -EBUSY;
1959 }
1960 }
1961 if (dma1 == SNDRV_AUTO_DMA) {
1962 if ((dma1 = snd_legacy_find_free_dma(possible_dma1s)) < 0) {
1963 snd_printk(KERN_ERR "unable to find a free DMA1\n");
1964 return -EBUSY;
1965 }
1966 }
1967#if defined(CS4231) || defined(OPTi93X)
1968 if (dma2 == SNDRV_AUTO_DMA) {
1969 if ((dma2 = snd_legacy_find_free_dma(possible_dma2s[dma1 % 4])) < 0) {
1970 snd_printk("unable to find a free DMA2\n");
1971 return -EBUSY;
1972 }
1973 }
1974#endif
1975
1976 card = snd_opti9xx_card_new();
1977 if (! card)
1978 return -ENOMEM;
1979
1980 if ((error = snd_card_opti9xx_detect(card, card->private_data)) < 0) {
2141 snd_card_free(card); 1981 snd_card_free(card);
2142 return error; 1982 return error;
2143 } 1983 }
2144 snd_opti9xx_first_hit = 0; 1984 snd_card_set_dev(card, &devptr->dev);
2145 if (pcard) 1985 if ((error = snd_opti9xx_probe(card)) < 0) {
2146 pnp_set_card_drvdata(pcard, card); 1986 snd_card_free(card);
2147 else 1987 return error;
2148 snd_opti9xx_legacy = card; 1988 }
1989 platform_set_drvdata(devptr, card);
1990 return 0;
1991}
1992
1993static int __devexit snd_opti9xx_nonpnp_remove(struct platform_device *devptr)
1994{
1995 snd_card_free(platform_get_drvdata(devptr));
1996 platform_set_drvdata(devptr, NULL);
2149 return 0; 1997 return 0;
2150} 1998}
2151 1999
2000static struct platform_driver snd_opti9xx_driver = {
2001 .probe = snd_opti9xx_nonpnp_probe,
2002 .remove = __devexit_p(snd_opti9xx_nonpnp_remove),
2003 /* FIXME: suspend/resume */
2004 .driver = {
2005 .name = DRIVER_NAME
2006 },
2007};
2008
2152#ifdef CONFIG_PNP 2009#ifdef CONFIG_PNP
2153static void __devexit snd_opti9xx_pnp_remove(struct pnp_card_link * pcard) 2010static int __init snd_opti9xx_pnp_probe(struct pnp_card_link *pcard,
2011 const struct pnp_card_device_id *pid)
2154{ 2012{
2155 struct snd_card *card = (struct snd_card *) pnp_get_card_drvdata(pcard); 2013 struct snd_card *card;
2014 int error, hw;
2015 struct snd_opti9xx *chip;
2016
2017 if (snd_opti9xx_pnp_is_probed)
2018 return -EBUSY;
2019 if (! isapnp)
2020 return -ENODEV;
2021 card = snd_opti9xx_card_new();
2022 if (! card)
2023 return -ENOMEM;
2024 chip = card->private_data;
2156 2025
2157 snd_card_disconnect(card); 2026 hw = snd_card_opti9xx_pnp(chip, pcard, pid);
2158 snd_card_free_in_thread(card); 2027 switch (hw) {
2159 snd_opti9xx_first_hit = 0; 2028 case 0x0924:
2029 hw = OPTi9XX_HW_82C924;
2030 break;
2031 case 0x0925:
2032 hw = OPTi9XX_HW_82C925;
2033 break;
2034 case 0x0931:
2035 hw = OPTi9XX_HW_82C931;
2036 break;
2037 default:
2038 snd_card_free(card);
2039 return -ENODEV;
2040 }
2041
2042 if ((error = snd_opti9xx_init(chip, hw))) {
2043 snd_card_free(card);
2044 return error;
2045 }
2046 if (hw <= OPTi9XX_HW_82C930)
2047 chip->mc_base -= 0x80;
2048 snd_card_set_dev(card, &pcard->card->dev);
2049 if ((error = snd_opti9xx_probe(card)) < 0) {
2050 snd_card_free(card);
2051 return error;
2052 }
2053 pnp_set_card_drvdata(pcard, card);
2054 snd_opti9xx_pnp_is_probed = 1;
2055 return 0;
2056}
2057
2058static void __devexit snd_opti9xx_pnp_remove(struct pnp_card_link * pcard)
2059{
2060 snd_card_free(pnp_get_card_drvdata(pcard));
2061 pnp_set_card_drvdata(pcard, NULL);
2062 snd_opti9xx_pnp_is_probed = 0;
2160} 2063}
2161 2064
2162static struct pnp_card_driver opti9xx_pnpc_driver = { 2065static struct pnp_card_driver opti9xx_pnpc_driver = {
2163 .flags = PNP_DRIVER_RES_DISABLE, 2066 .flags = PNP_DRIVER_RES_DISABLE,
2164 .name = "opti9xx", 2067 .name = "opti9xx",
2165 .id_table = snd_opti9xx_pnpids, 2068 .id_table = snd_opti9xx_pnpids,
2166 .probe = snd_card_opti9xx_probe, 2069 .probe = snd_opti9xx_pnp_probe,
2167 .remove = __devexit_p(snd_opti9xx_pnp_remove), 2070 .remove = __devexit_p(snd_opti9xx_pnp_remove),
2168}; 2071};
2169#endif 2072#endif
2170 2073
2171static int __init alsa_card_opti9xx_init(void)
2172{
2173 int cards, error;
2174
2175#ifdef CONFIG_PNP 2074#ifdef CONFIG_PNP
2176 cards = pnp_register_card_driver(&opti9xx_pnpc_driver); 2075#define is_isapnp_selected() isapnp
2177#else 2076#else
2178 cards = 0; 2077#define is_isapnp_selected() 0
2179#endif
2180 if (cards == 0 && (error = snd_card_opti9xx_probe(NULL, NULL)) < 0) {
2181#ifdef CONFIG_PNP
2182 pnp_unregister_card_driver(&opti9xx_pnpc_driver);
2183#endif 2078#endif
2184#ifdef MODULE
2185#ifdef OPTi93X 2079#ifdef OPTi93X
2186 printk(KERN_ERR "no OPTi 82C93x soundcard found\n"); 2080#define CHIP_NAME "82C93x"
2187#else 2081#else
2188 printk(KERN_ERR "no OPTi 82C92x soundcard found\n"); 2082#define CHIP_NAME "82C92x"
2189#endif /* OPTi93X */
2190#endif 2083#endif
2191 return error; 2084
2085static int __init alsa_card_opti9xx_init(void)
2086{
2087 int error;
2088 struct platform_device *device;
2089
2090 pnp_register_card_driver(&opti9xx_pnpc_driver);
2091 if (snd_opti9xx_pnp_is_probed)
2092 return 0;
2093 if (! is_isapnp_selected()) {
2094 error = platform_driver_register(&snd_opti9xx_driver);
2095 if (error < 0)
2096 return error;
2097 device = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0);
2098 if (! IS_ERR(device))
2099 return 0;
2100 platform_driver_unregister(&snd_opti9xx_driver);
2192 } 2101 }
2193 return 0; 2102 pnp_unregister_card_driver(&opti9xx_pnpc_driver);
2103#ifdef MODULE
2104 printk(KERN_ERR "no OPTi " CHIP_NAME " soundcard found\n");
2105#endif
2106 return -ENODEV;
2194} 2107}
2195 2108
2196static void __exit alsa_card_opti9xx_exit(void) 2109static void __exit alsa_card_opti9xx_exit(void)
2197{ 2110{
2198#ifdef CONFIG_PNP 2111 if (! snd_opti9xx_pnp_is_probed)
2112 platform_driver_unregister(&snd_opti9xx_driver);
2199 pnp_unregister_card_driver(&opti9xx_pnpc_driver); 2113 pnp_unregister_card_driver(&opti9xx_pnpc_driver);
2200#endif
2201 if (snd_opti9xx_legacy)
2202 snd_card_free(snd_opti9xx_legacy);
2203} 2114}
2204 2115
2205module_init(alsa_card_opti9xx_init) 2116module_init(alsa_card_opti9xx_init)