diff options
Diffstat (limited to 'sound/sparc/cs4231.c')
-rw-r--r-- | sound/sparc/cs4231.c | 199 |
1 files changed, 79 insertions, 120 deletions
diff --git a/sound/sparc/cs4231.c b/sound/sparc/cs4231.c index 791d2fb821d1..d44bf98e965e 100644 --- a/sound/sparc/cs4231.c +++ b/sound/sparc/cs4231.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * Driver for CS4231 sound chips found on Sparcs. | 2 | * Driver for CS4231 sound chips found on Sparcs. |
3 | * Copyright (C) 2002 David S. Miller <davem@redhat.com> | 3 | * Copyright (C) 2002, 2008 David S. Miller <davem@davemloft.net> |
4 | * | 4 | * |
5 | * Based entirely upon drivers/sbus/audio/cs4231.c which is: | 5 | * Based entirely upon drivers/sbus/audio/cs4231.c which is: |
6 | * Copyright (C) 1996, 1997, 1998 Derrick J Brashear (shadow@andrew.cmu.edu) | 6 | * Copyright (C) 1996, 1997, 1998 Derrick J Brashear (shadow@andrew.cmu.edu) |
@@ -17,7 +17,8 @@ | |||
17 | #include <linux/moduleparam.h> | 17 | #include <linux/moduleparam.h> |
18 | #include <linux/irq.h> | 18 | #include <linux/irq.h> |
19 | #include <linux/io.h> | 19 | #include <linux/io.h> |
20 | 20 | #include <linux/of.h> | |
21 | #include <linux/of_device.h> | ||
21 | 22 | ||
22 | #include <sound/core.h> | 23 | #include <sound/core.h> |
23 | #include <sound/pcm.h> | 24 | #include <sound/pcm.h> |
@@ -29,13 +30,12 @@ | |||
29 | 30 | ||
30 | #ifdef CONFIG_SBUS | 31 | #ifdef CONFIG_SBUS |
31 | #define SBUS_SUPPORT | 32 | #define SBUS_SUPPORT |
32 | #include <asm/sbus.h> | ||
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | #if defined(CONFIG_PCI) && defined(CONFIG_SPARC64) | 35 | #if defined(CONFIG_PCI) && defined(CONFIG_SPARC64) |
36 | #define EBUS_SUPPORT | 36 | #define EBUS_SUPPORT |
37 | #include <linux/pci.h> | 37 | #include <linux/pci.h> |
38 | #include <asm/ebus.h> | 38 | #include <asm/ebus_dma.h> |
39 | #endif | 39 | #endif |
40 | 40 | ||
41 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ | 41 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
@@ -70,8 +70,6 @@ struct cs4231_dma_control { | |||
70 | int (*request)(struct cs4231_dma_control *dma_cont, | 70 | int (*request)(struct cs4231_dma_control *dma_cont, |
71 | dma_addr_t bus_addr, size_t len); | 71 | dma_addr_t bus_addr, size_t len); |
72 | unsigned int (*address)(struct cs4231_dma_control *dma_cont); | 72 | unsigned int (*address)(struct cs4231_dma_control *dma_cont); |
73 | void (*preallocate)(struct snd_cs4231 *chip, | ||
74 | struct snd_pcm *pcm); | ||
75 | #ifdef EBUS_SUPPORT | 73 | #ifdef EBUS_SUPPORT |
76 | struct ebus_dma_info ebus_info; | 74 | struct ebus_dma_info ebus_info; |
77 | #endif | 75 | #endif |
@@ -114,21 +112,12 @@ struct snd_cs4231 { | |||
114 | struct mutex mce_mutex; /* mutex for mce register */ | 112 | struct mutex mce_mutex; /* mutex for mce register */ |
115 | struct mutex open_mutex; /* mutex for ALSA open/close */ | 113 | struct mutex open_mutex; /* mutex for ALSA open/close */ |
116 | 114 | ||
117 | union { | 115 | struct of_device *op; |
118 | #ifdef SBUS_SUPPORT | ||
119 | struct sbus_dev *sdev; | ||
120 | #endif | ||
121 | #ifdef EBUS_SUPPORT | ||
122 | struct pci_dev *pdev; | ||
123 | #endif | ||
124 | } dev_u; | ||
125 | unsigned int irq[2]; | 116 | unsigned int irq[2]; |
126 | unsigned int regs_size; | 117 | unsigned int regs_size; |
127 | struct snd_cs4231 *next; | 118 | struct snd_cs4231 *next; |
128 | }; | 119 | }; |
129 | 120 | ||
130 | static struct snd_cs4231 *cs4231_list; | ||
131 | |||
132 | /* Eventually we can use sound/isa/cs423x/cs4231_lib.c directly, but for | 121 | /* Eventually we can use sound/isa/cs423x/cs4231_lib.c directly, but for |
133 | * now.... -DaveM | 122 | * now.... -DaveM |
134 | */ | 123 | */ |
@@ -267,27 +256,19 @@ static unsigned char snd_cs4231_original_image[32] = | |||
267 | 256 | ||
268 | static u8 __cs4231_readb(struct snd_cs4231 *cp, void __iomem *reg_addr) | 257 | static u8 __cs4231_readb(struct snd_cs4231 *cp, void __iomem *reg_addr) |
269 | { | 258 | { |
270 | #ifdef EBUS_SUPPORT | ||
271 | if (cp->flags & CS4231_FLAG_EBUS) | 259 | if (cp->flags & CS4231_FLAG_EBUS) |
272 | return readb(reg_addr); | 260 | return readb(reg_addr); |
273 | else | 261 | else |
274 | #endif | ||
275 | #ifdef SBUS_SUPPORT | ||
276 | return sbus_readb(reg_addr); | 262 | return sbus_readb(reg_addr); |
277 | #endif | ||
278 | } | 263 | } |
279 | 264 | ||
280 | static void __cs4231_writeb(struct snd_cs4231 *cp, u8 val, | 265 | static void __cs4231_writeb(struct snd_cs4231 *cp, u8 val, |
281 | void __iomem *reg_addr) | 266 | void __iomem *reg_addr) |
282 | { | 267 | { |
283 | #ifdef EBUS_SUPPORT | ||
284 | if (cp->flags & CS4231_FLAG_EBUS) | 268 | if (cp->flags & CS4231_FLAG_EBUS) |
285 | return writeb(val, reg_addr); | 269 | return writeb(val, reg_addr); |
286 | else | 270 | else |
287 | #endif | ||
288 | #ifdef SBUS_SUPPORT | ||
289 | return sbus_writeb(val, reg_addr); | 271 | return sbus_writeb(val, reg_addr); |
290 | #endif | ||
291 | } | 272 | } |
292 | 273 | ||
293 | /* | 274 | /* |
@@ -1258,7 +1239,9 @@ static int __init snd_cs4231_pcm(struct snd_card *card) | |||
1258 | pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; | 1239 | pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; |
1259 | strcpy(pcm->name, "CS4231"); | 1240 | strcpy(pcm->name, "CS4231"); |
1260 | 1241 | ||
1261 | chip->p_dma.preallocate(chip, pcm); | 1242 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
1243 | &chip->op->dev, | ||
1244 | 64 * 1024, 128 * 1024); | ||
1262 | 1245 | ||
1263 | chip->pcm = pcm; | 1246 | chip->pcm = pcm; |
1264 | 1247 | ||
@@ -1627,8 +1610,7 @@ static int __init cs4231_attach_finish(struct snd_card *card) | |||
1627 | if (err < 0) | 1610 | if (err < 0) |
1628 | goto out_err; | 1611 | goto out_err; |
1629 | 1612 | ||
1630 | chip->next = cs4231_list; | 1613 | dev_set_drvdata(&chip->op->dev, chip); |
1631 | cs4231_list = chip; | ||
1632 | 1614 | ||
1633 | dev++; | 1615 | dev++; |
1634 | return 0; | 1616 | return 0; |
@@ -1783,24 +1765,19 @@ static unsigned int sbus_dma_addr(struct cs4231_dma_control *dma_cont) | |||
1783 | return sbus_readl(base->regs + base->dir + APCVA); | 1765 | return sbus_readl(base->regs + base->dir + APCVA); |
1784 | } | 1766 | } |
1785 | 1767 | ||
1786 | static void sbus_dma_preallocate(struct snd_cs4231 *chip, struct snd_pcm *pcm) | ||
1787 | { | ||
1788 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_SBUS, | ||
1789 | snd_dma_sbus_data(chip->dev_u.sdev), | ||
1790 | 64 * 1024, 128 * 1024); | ||
1791 | } | ||
1792 | |||
1793 | /* | 1768 | /* |
1794 | * Init and exit routines | 1769 | * Init and exit routines |
1795 | */ | 1770 | */ |
1796 | 1771 | ||
1797 | static int snd_cs4231_sbus_free(struct snd_cs4231 *chip) | 1772 | static int snd_cs4231_sbus_free(struct snd_cs4231 *chip) |
1798 | { | 1773 | { |
1774 | struct of_device *op = chip->op; | ||
1775 | |||
1799 | if (chip->irq[0]) | 1776 | if (chip->irq[0]) |
1800 | free_irq(chip->irq[0], chip); | 1777 | free_irq(chip->irq[0], chip); |
1801 | 1778 | ||
1802 | if (chip->port) | 1779 | if (chip->port) |
1803 | sbus_iounmap(chip->port, chip->regs_size); | 1780 | of_iounmap(&op->resource[0], chip->port, chip->regs_size); |
1804 | 1781 | ||
1805 | return 0; | 1782 | return 0; |
1806 | } | 1783 | } |
@@ -1817,7 +1794,7 @@ static struct snd_device_ops snd_cs4231_sbus_dev_ops = { | |||
1817 | }; | 1794 | }; |
1818 | 1795 | ||
1819 | static int __init snd_cs4231_sbus_create(struct snd_card *card, | 1796 | static int __init snd_cs4231_sbus_create(struct snd_card *card, |
1820 | struct sbus_dev *sdev, | 1797 | struct of_device *op, |
1821 | int dev) | 1798 | int dev) |
1822 | { | 1799 | { |
1823 | struct snd_cs4231 *chip = card->private_data; | 1800 | struct snd_cs4231 *chip = card->private_data; |
@@ -1828,13 +1805,13 @@ static int __init snd_cs4231_sbus_create(struct snd_card *card, | |||
1828 | spin_lock_init(&chip->p_dma.sbus_info.lock); | 1805 | spin_lock_init(&chip->p_dma.sbus_info.lock); |
1829 | mutex_init(&chip->mce_mutex); | 1806 | mutex_init(&chip->mce_mutex); |
1830 | mutex_init(&chip->open_mutex); | 1807 | mutex_init(&chip->open_mutex); |
1831 | chip->dev_u.sdev = sdev; | 1808 | chip->op = op; |
1832 | chip->regs_size = sdev->reg_addrs[0].reg_size; | 1809 | chip->regs_size = resource_size(&op->resource[0]); |
1833 | memcpy(&chip->image, &snd_cs4231_original_image, | 1810 | memcpy(&chip->image, &snd_cs4231_original_image, |
1834 | sizeof(snd_cs4231_original_image)); | 1811 | sizeof(snd_cs4231_original_image)); |
1835 | 1812 | ||
1836 | chip->port = sbus_ioremap(&sdev->resource[0], 0, | 1813 | chip->port = of_ioremap(&op->resource[0], 0, |
1837 | chip->regs_size, "cs4231"); | 1814 | chip->regs_size, "cs4231"); |
1838 | if (!chip->port) { | 1815 | if (!chip->port) { |
1839 | snd_printdd("cs4231-%d: Unable to map chip registers.\n", dev); | 1816 | snd_printdd("cs4231-%d: Unable to map chip registers.\n", dev); |
1840 | return -EIO; | 1817 | return -EIO; |
@@ -1849,22 +1826,20 @@ static int __init snd_cs4231_sbus_create(struct snd_card *card, | |||
1849 | chip->p_dma.enable = sbus_dma_enable; | 1826 | chip->p_dma.enable = sbus_dma_enable; |
1850 | chip->p_dma.request = sbus_dma_request; | 1827 | chip->p_dma.request = sbus_dma_request; |
1851 | chip->p_dma.address = sbus_dma_addr; | 1828 | chip->p_dma.address = sbus_dma_addr; |
1852 | chip->p_dma.preallocate = sbus_dma_preallocate; | ||
1853 | 1829 | ||
1854 | chip->c_dma.prepare = sbus_dma_prepare; | 1830 | chip->c_dma.prepare = sbus_dma_prepare; |
1855 | chip->c_dma.enable = sbus_dma_enable; | 1831 | chip->c_dma.enable = sbus_dma_enable; |
1856 | chip->c_dma.request = sbus_dma_request; | 1832 | chip->c_dma.request = sbus_dma_request; |
1857 | chip->c_dma.address = sbus_dma_addr; | 1833 | chip->c_dma.address = sbus_dma_addr; |
1858 | chip->c_dma.preallocate = sbus_dma_preallocate; | ||
1859 | 1834 | ||
1860 | if (request_irq(sdev->irqs[0], snd_cs4231_sbus_interrupt, | 1835 | if (request_irq(op->irqs[0], snd_cs4231_sbus_interrupt, |
1861 | IRQF_SHARED, "cs4231", chip)) { | 1836 | IRQF_SHARED, "cs4231", chip)) { |
1862 | snd_printdd("cs4231-%d: Unable to grab SBUS IRQ %d\n", | 1837 | snd_printdd("cs4231-%d: Unable to grab SBUS IRQ %d\n", |
1863 | dev, sdev->irqs[0]); | 1838 | dev, op->irqs[0]); |
1864 | snd_cs4231_sbus_free(chip); | 1839 | snd_cs4231_sbus_free(chip); |
1865 | return -EBUSY; | 1840 | return -EBUSY; |
1866 | } | 1841 | } |
1867 | chip->irq[0] = sdev->irqs[0]; | 1842 | chip->irq[0] = op->irqs[0]; |
1868 | 1843 | ||
1869 | if (snd_cs4231_probe(chip) < 0) { | 1844 | if (snd_cs4231_probe(chip) < 0) { |
1870 | snd_cs4231_sbus_free(chip); | 1845 | snd_cs4231_sbus_free(chip); |
@@ -1881,9 +1856,9 @@ static int __init snd_cs4231_sbus_create(struct snd_card *card, | |||
1881 | return 0; | 1856 | return 0; |
1882 | } | 1857 | } |
1883 | 1858 | ||
1884 | static int __init cs4231_sbus_attach(struct sbus_dev *sdev) | 1859 | static int __devinit cs4231_sbus_probe(struct of_device *op, const struct of_device_id *match) |
1885 | { | 1860 | { |
1886 | struct resource *rp = &sdev->resource[0]; | 1861 | struct resource *rp = &op->resource[0]; |
1887 | struct snd_card *card; | 1862 | struct snd_card *card; |
1888 | int err; | 1863 | int err; |
1889 | 1864 | ||
@@ -1895,9 +1870,9 @@ static int __init cs4231_sbus_attach(struct sbus_dev *sdev) | |||
1895 | card->shortname, | 1870 | card->shortname, |
1896 | rp->flags & 0xffL, | 1871 | rp->flags & 0xffL, |
1897 | (unsigned long long)rp->start, | 1872 | (unsigned long long)rp->start, |
1898 | sdev->irqs[0]); | 1873 | op->irqs[0]); |
1899 | 1874 | ||
1900 | err = snd_cs4231_sbus_create(card, sdev, dev); | 1875 | err = snd_cs4231_sbus_create(card, op, dev); |
1901 | if (err < 0) { | 1876 | if (err < 0) { |
1902 | snd_card_free(card); | 1877 | snd_card_free(card); |
1903 | return err; | 1878 | return err; |
@@ -1950,30 +1925,25 @@ static unsigned int _ebus_dma_addr(struct cs4231_dma_control *dma_cont) | |||
1950 | return ebus_dma_addr(&dma_cont->ebus_info); | 1925 | return ebus_dma_addr(&dma_cont->ebus_info); |
1951 | } | 1926 | } |
1952 | 1927 | ||
1953 | static void _ebus_dma_preallocate(struct snd_cs4231 *chip, struct snd_pcm *pcm) | ||
1954 | { | ||
1955 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, | ||
1956 | snd_dma_pci_data(chip->dev_u.pdev), | ||
1957 | 64*1024, 128*1024); | ||
1958 | } | ||
1959 | |||
1960 | /* | 1928 | /* |
1961 | * Init and exit routines | 1929 | * Init and exit routines |
1962 | */ | 1930 | */ |
1963 | 1931 | ||
1964 | static int snd_cs4231_ebus_free(struct snd_cs4231 *chip) | 1932 | static int snd_cs4231_ebus_free(struct snd_cs4231 *chip) |
1965 | { | 1933 | { |
1934 | struct of_device *op = chip->op; | ||
1935 | |||
1966 | if (chip->c_dma.ebus_info.regs) { | 1936 | if (chip->c_dma.ebus_info.regs) { |
1967 | ebus_dma_unregister(&chip->c_dma.ebus_info); | 1937 | ebus_dma_unregister(&chip->c_dma.ebus_info); |
1968 | iounmap(chip->c_dma.ebus_info.regs); | 1938 | of_iounmap(&op->resource[2], chip->c_dma.ebus_info.regs, 0x10); |
1969 | } | 1939 | } |
1970 | if (chip->p_dma.ebus_info.regs) { | 1940 | if (chip->p_dma.ebus_info.regs) { |
1971 | ebus_dma_unregister(&chip->p_dma.ebus_info); | 1941 | ebus_dma_unregister(&chip->p_dma.ebus_info); |
1972 | iounmap(chip->p_dma.ebus_info.regs); | 1942 | of_iounmap(&op->resource[1], chip->p_dma.ebus_info.regs, 0x10); |
1973 | } | 1943 | } |
1974 | 1944 | ||
1975 | if (chip->port) | 1945 | if (chip->port) |
1976 | iounmap(chip->port); | 1946 | of_iounmap(&op->resource[0], chip->port, 0x10); |
1977 | 1947 | ||
1978 | return 0; | 1948 | return 0; |
1979 | } | 1949 | } |
@@ -1990,7 +1960,7 @@ static struct snd_device_ops snd_cs4231_ebus_dev_ops = { | |||
1990 | }; | 1960 | }; |
1991 | 1961 | ||
1992 | static int __init snd_cs4231_ebus_create(struct snd_card *card, | 1962 | static int __init snd_cs4231_ebus_create(struct snd_card *card, |
1993 | struct linux_ebus_device *edev, | 1963 | struct of_device *op, |
1994 | int dev) | 1964 | int dev) |
1995 | { | 1965 | { |
1996 | struct snd_cs4231 *chip = card->private_data; | 1966 | struct snd_cs4231 *chip = card->private_data; |
@@ -2002,35 +1972,35 @@ static int __init snd_cs4231_ebus_create(struct snd_card *card, | |||
2002 | mutex_init(&chip->mce_mutex); | 1972 | mutex_init(&chip->mce_mutex); |
2003 | mutex_init(&chip->open_mutex); | 1973 | mutex_init(&chip->open_mutex); |
2004 | chip->flags |= CS4231_FLAG_EBUS; | 1974 | chip->flags |= CS4231_FLAG_EBUS; |
2005 | chip->dev_u.pdev = edev->bus->self; | 1975 | chip->op = op; |
2006 | memcpy(&chip->image, &snd_cs4231_original_image, | 1976 | memcpy(&chip->image, &snd_cs4231_original_image, |
2007 | sizeof(snd_cs4231_original_image)); | 1977 | sizeof(snd_cs4231_original_image)); |
2008 | strcpy(chip->c_dma.ebus_info.name, "cs4231(capture)"); | 1978 | strcpy(chip->c_dma.ebus_info.name, "cs4231(capture)"); |
2009 | chip->c_dma.ebus_info.flags = EBUS_DMA_FLAG_USE_EBDMA_HANDLER; | 1979 | chip->c_dma.ebus_info.flags = EBUS_DMA_FLAG_USE_EBDMA_HANDLER; |
2010 | chip->c_dma.ebus_info.callback = snd_cs4231_ebus_capture_callback; | 1980 | chip->c_dma.ebus_info.callback = snd_cs4231_ebus_capture_callback; |
2011 | chip->c_dma.ebus_info.client_cookie = chip; | 1981 | chip->c_dma.ebus_info.client_cookie = chip; |
2012 | chip->c_dma.ebus_info.irq = edev->irqs[0]; | 1982 | chip->c_dma.ebus_info.irq = op->irqs[0]; |
2013 | strcpy(chip->p_dma.ebus_info.name, "cs4231(play)"); | 1983 | strcpy(chip->p_dma.ebus_info.name, "cs4231(play)"); |
2014 | chip->p_dma.ebus_info.flags = EBUS_DMA_FLAG_USE_EBDMA_HANDLER; | 1984 | chip->p_dma.ebus_info.flags = EBUS_DMA_FLAG_USE_EBDMA_HANDLER; |
2015 | chip->p_dma.ebus_info.callback = snd_cs4231_ebus_play_callback; | 1985 | chip->p_dma.ebus_info.callback = snd_cs4231_ebus_play_callback; |
2016 | chip->p_dma.ebus_info.client_cookie = chip; | 1986 | chip->p_dma.ebus_info.client_cookie = chip; |
2017 | chip->p_dma.ebus_info.irq = edev->irqs[1]; | 1987 | chip->p_dma.ebus_info.irq = op->irqs[1]; |
2018 | 1988 | ||
2019 | chip->p_dma.prepare = _ebus_dma_prepare; | 1989 | chip->p_dma.prepare = _ebus_dma_prepare; |
2020 | chip->p_dma.enable = _ebus_dma_enable; | 1990 | chip->p_dma.enable = _ebus_dma_enable; |
2021 | chip->p_dma.request = _ebus_dma_request; | 1991 | chip->p_dma.request = _ebus_dma_request; |
2022 | chip->p_dma.address = _ebus_dma_addr; | 1992 | chip->p_dma.address = _ebus_dma_addr; |
2023 | chip->p_dma.preallocate = _ebus_dma_preallocate; | ||
2024 | 1993 | ||
2025 | chip->c_dma.prepare = _ebus_dma_prepare; | 1994 | chip->c_dma.prepare = _ebus_dma_prepare; |
2026 | chip->c_dma.enable = _ebus_dma_enable; | 1995 | chip->c_dma.enable = _ebus_dma_enable; |
2027 | chip->c_dma.request = _ebus_dma_request; | 1996 | chip->c_dma.request = _ebus_dma_request; |
2028 | chip->c_dma.address = _ebus_dma_addr; | 1997 | chip->c_dma.address = _ebus_dma_addr; |
2029 | chip->c_dma.preallocate = _ebus_dma_preallocate; | ||
2030 | 1998 | ||
2031 | chip->port = ioremap(edev->resource[0].start, 0x10); | 1999 | chip->port = of_ioremap(&op->resource[0], 0, 0x10, "cs4231"); |
2032 | chip->p_dma.ebus_info.regs = ioremap(edev->resource[1].start, 0x10); | 2000 | chip->p_dma.ebus_info.regs = |
2033 | chip->c_dma.ebus_info.regs = ioremap(edev->resource[2].start, 0x10); | 2001 | of_ioremap(&op->resource[1], 0, 0x10, "cs4231_pdma"); |
2002 | chip->c_dma.ebus_info.regs = | ||
2003 | of_ioremap(&op->resource[2], 0, 0x10, "cs4231_cdma"); | ||
2034 | if (!chip->port || !chip->p_dma.ebus_info.regs || | 2004 | if (!chip->port || !chip->p_dma.ebus_info.regs || |
2035 | !chip->c_dma.ebus_info.regs) { | 2005 | !chip->c_dma.ebus_info.regs) { |
2036 | snd_cs4231_ebus_free(chip); | 2006 | snd_cs4231_ebus_free(chip); |
@@ -2078,7 +2048,7 @@ static int __init snd_cs4231_ebus_create(struct snd_card *card, | |||
2078 | return 0; | 2048 | return 0; |
2079 | } | 2049 | } |
2080 | 2050 | ||
2081 | static int __init cs4231_ebus_attach(struct linux_ebus_device *edev) | 2051 | static int __devinit cs4231_ebus_probe(struct of_device *op, const struct of_device_id *match) |
2082 | { | 2052 | { |
2083 | struct snd_card *card; | 2053 | struct snd_card *card; |
2084 | int err; | 2054 | int err; |
@@ -2089,10 +2059,10 @@ static int __init cs4231_ebus_attach(struct linux_ebus_device *edev) | |||
2089 | 2059 | ||
2090 | sprintf(card->longname, "%s at 0x%lx, irq %d", | 2060 | sprintf(card->longname, "%s at 0x%lx, irq %d", |
2091 | card->shortname, | 2061 | card->shortname, |
2092 | edev->resource[0].start, | 2062 | op->resource[0].start, |
2093 | edev->irqs[0]); | 2063 | op->irqs[0]); |
2094 | 2064 | ||
2095 | err = snd_cs4231_ebus_create(card, edev, dev); | 2065 | err = snd_cs4231_ebus_create(card, op, dev); |
2096 | if (err < 0) { | 2066 | if (err < 0) { |
2097 | snd_card_free(card); | 2067 | snd_card_free(card); |
2098 | return err; | 2068 | return err; |
@@ -2102,68 +2072,57 @@ static int __init cs4231_ebus_attach(struct linux_ebus_device *edev) | |||
2102 | } | 2072 | } |
2103 | #endif | 2073 | #endif |
2104 | 2074 | ||
2105 | static int __init cs4231_init(void) | 2075 | static int __devinit cs4231_probe(struct of_device *op, const struct of_device_id *match) |
2106 | { | 2076 | { |
2107 | #ifdef SBUS_SUPPORT | ||
2108 | struct sbus_bus *sbus; | ||
2109 | struct sbus_dev *sdev; | ||
2110 | #endif | ||
2111 | #ifdef EBUS_SUPPORT | 2077 | #ifdef EBUS_SUPPORT |
2112 | struct linux_ebus *ebus; | 2078 | if (!strcmp(op->node->parent->name, "ebus")) |
2113 | struct linux_ebus_device *edev; | 2079 | return cs4231_ebus_probe(op, match); |
2114 | #endif | 2080 | #endif |
2115 | int found; | ||
2116 | |||
2117 | found = 0; | ||
2118 | |||
2119 | #ifdef SBUS_SUPPORT | 2081 | #ifdef SBUS_SUPPORT |
2120 | for_all_sbusdev(sdev, sbus) { | 2082 | if (!strcmp(op->node->parent->name, "sbus") || |
2121 | if (!strcmp(sdev->prom_name, "SUNW,CS4231")) { | 2083 | !strcmp(op->node->parent->name, "sbi")) |
2122 | if (cs4231_sbus_attach(sdev) == 0) | 2084 | return cs4231_sbus_probe(op, match); |
2123 | found++; | ||
2124 | } | ||
2125 | } | ||
2126 | #endif | 2085 | #endif |
2127 | #ifdef EBUS_SUPPORT | 2086 | return -ENODEV; |
2128 | for_each_ebus(ebus) { | 2087 | } |
2129 | for_each_ebusdev(edev, ebus) { | ||
2130 | int match = 0; | ||
2131 | |||
2132 | if (!strcmp(edev->prom_node->name, "SUNW,CS4231")) { | ||
2133 | match = 1; | ||
2134 | } else if (!strcmp(edev->prom_node->name, "audio")) { | ||
2135 | const char *compat; | ||
2136 | |||
2137 | compat = of_get_property(edev->prom_node, | ||
2138 | "compatible", NULL); | ||
2139 | if (compat && !strcmp(compat, "SUNW,CS4231")) | ||
2140 | match = 1; | ||
2141 | } | ||
2142 | 2088 | ||
2143 | if (match && | 2089 | static int __devexit cs4231_remove(struct of_device *op) |
2144 | cs4231_ebus_attach(edev) == 0) | 2090 | { |
2145 | found++; | 2091 | struct snd_cs4231 *chip = dev_get_drvdata(&op->dev); |
2146 | } | ||
2147 | } | ||
2148 | #endif | ||
2149 | 2092 | ||
2093 | snd_card_free(chip->card); | ||
2150 | 2094 | ||
2151 | return (found > 0) ? 0 : -EIO; | 2095 | return 0; |
2152 | } | 2096 | } |
2153 | 2097 | ||
2154 | static void __exit cs4231_exit(void) | 2098 | static const struct of_device_id cs4231_match[] = { |
2155 | { | 2099 | { |
2156 | struct snd_cs4231 *p = cs4231_list; | 2100 | .name = "SUNW,CS4231", |
2101 | }, | ||
2102 | { | ||
2103 | .name = "audio", | ||
2104 | .compatible = "SUNW,CS4231", | ||
2105 | }, | ||
2106 | {}, | ||
2107 | }; | ||
2157 | 2108 | ||
2158 | while (p != NULL) { | 2109 | MODULE_DEVICE_TABLE(of, cs4231_match); |
2159 | struct snd_cs4231 *next = p->next; | ||
2160 | 2110 | ||
2161 | snd_card_free(p->card); | 2111 | static struct of_platform_driver cs4231_driver = { |
2112 | .name = "audio", | ||
2113 | .match_table = cs4231_match, | ||
2114 | .probe = cs4231_probe, | ||
2115 | .remove = __devexit_p(cs4231_remove), | ||
2116 | }; | ||
2162 | 2117 | ||
2163 | p = next; | 2118 | static int __init cs4231_init(void) |
2164 | } | 2119 | { |
2120 | return of_register_driver(&cs4231_driver, &of_bus_type); | ||
2121 | } | ||
2165 | 2122 | ||
2166 | cs4231_list = NULL; | 2123 | static void __exit cs4231_exit(void) |
2124 | { | ||
2125 | of_unregister_driver(&cs4231_driver); | ||
2167 | } | 2126 | } |
2168 | 2127 | ||
2169 | module_init(cs4231_init); | 2128 | module_init(cs4231_init); |