aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sound/sparc/cs4231.c172
1 files changed, 54 insertions, 118 deletions
diff --git a/sound/sparc/cs4231.c b/sound/sparc/cs4231.c
index e6dba4f7169c..cdbfae96bd88 100644
--- a/sound/sparc/cs4231.c
+++ b/sound/sparc/cs4231.c
@@ -35,7 +35,6 @@
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>
39#include <asm/ebus_dma.h> 38#include <asm/ebus_dma.h>
40#endif 39#endif
41 40
@@ -71,8 +70,6 @@ struct cs4231_dma_control {
71 int (*request)(struct cs4231_dma_control *dma_cont, 70 int (*request)(struct cs4231_dma_control *dma_cont,
72 dma_addr_t bus_addr, size_t len); 71 dma_addr_t bus_addr, size_t len);
73 unsigned int (*address)(struct cs4231_dma_control *dma_cont); 72 unsigned int (*address)(struct cs4231_dma_control *dma_cont);
74 void (*preallocate)(struct snd_cs4231 *chip,
75 struct snd_pcm *pcm);
76#ifdef EBUS_SUPPORT 73#ifdef EBUS_SUPPORT
77 struct ebus_dma_info ebus_info; 74 struct ebus_dma_info ebus_info;
78#endif 75#endif
@@ -115,21 +112,12 @@ struct snd_cs4231 {
115 struct mutex mce_mutex; /* mutex for mce register */ 112 struct mutex mce_mutex; /* mutex for mce register */
116 struct mutex open_mutex; /* mutex for ALSA open/close */ 113 struct mutex open_mutex; /* mutex for ALSA open/close */
117 114
118 union { 115 struct of_device *op;
119#ifdef SBUS_SUPPORT
120 struct of_device *op;
121#endif
122#ifdef EBUS_SUPPORT
123 struct pci_dev *pdev;
124#endif
125 } dev_u;
126 unsigned int irq[2]; 116 unsigned int irq[2];
127 unsigned int regs_size; 117 unsigned int regs_size;
128 struct snd_cs4231 *next; 118 struct snd_cs4231 *next;
129}; 119};
130 120
131static struct snd_cs4231 *cs4231_list;
132
133/* 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
134 * now.... -DaveM 122 * now.... -DaveM
135 */ 123 */
@@ -268,27 +256,19 @@ static unsigned char snd_cs4231_original_image[32] =
268 256
269static u8 __cs4231_readb(struct snd_cs4231 *cp, void __iomem *reg_addr) 257static u8 __cs4231_readb(struct snd_cs4231 *cp, void __iomem *reg_addr)
270{ 258{
271#ifdef EBUS_SUPPORT
272 if (cp->flags & CS4231_FLAG_EBUS) 259 if (cp->flags & CS4231_FLAG_EBUS)
273 return readb(reg_addr); 260 return readb(reg_addr);
274 else 261 else
275#endif
276#ifdef SBUS_SUPPORT
277 return sbus_readb(reg_addr); 262 return sbus_readb(reg_addr);
278#endif
279} 263}
280 264
281static void __cs4231_writeb(struct snd_cs4231 *cp, u8 val, 265static void __cs4231_writeb(struct snd_cs4231 *cp, u8 val,
282 void __iomem *reg_addr) 266 void __iomem *reg_addr)
283{ 267{
284#ifdef EBUS_SUPPORT
285 if (cp->flags & CS4231_FLAG_EBUS) 268 if (cp->flags & CS4231_FLAG_EBUS)
286 return writeb(val, reg_addr); 269 return writeb(val, reg_addr);
287 else 270 else
288#endif
289#ifdef SBUS_SUPPORT
290 return sbus_writeb(val, reg_addr); 271 return sbus_writeb(val, reg_addr);
291#endif
292} 272}
293 273
294/* 274/*
@@ -1259,7 +1239,9 @@ static int __init snd_cs4231_pcm(struct snd_card *card)
1259 pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; 1239 pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
1260 strcpy(pcm->name, "CS4231"); 1240 strcpy(pcm->name, "CS4231");
1261 1241
1262 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);
1263 1245
1264 chip->pcm = pcm; 1246 chip->pcm = pcm;
1265 1247
@@ -1627,8 +1609,7 @@ static int __init cs4231_attach_finish(struct snd_card *card)
1627 if (err < 0) 1609 if (err < 0)
1628 goto out_err; 1610 goto out_err;
1629 1611
1630 chip->next = cs4231_list; 1612 dev_set_drvdata(&chip->op->dev, chip);
1631 cs4231_list = chip;
1632 1613
1633 dev++; 1614 dev++;
1634 return 0; 1615 return 0;
@@ -1783,20 +1764,13 @@ static unsigned int sbus_dma_addr(struct cs4231_dma_control *dma_cont)
1783 return sbus_readl(base->regs + base->dir + APCVA); 1764 return sbus_readl(base->regs + base->dir + APCVA);
1784} 1765}
1785 1766
1786static 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_DEV,
1789 &chip->dev_u.op->dev,
1790 64 * 1024, 128 * 1024);
1791}
1792
1793/* 1767/*
1794 * Init and exit routines 1768 * Init and exit routines
1795 */ 1769 */
1796 1770
1797static int snd_cs4231_sbus_free(struct snd_cs4231 *chip) 1771static int snd_cs4231_sbus_free(struct snd_cs4231 *chip)
1798{ 1772{
1799 struct of_device *op = chip->dev_u.op; 1773 struct of_device *op = chip->op;
1800 1774
1801 if (chip->irq[0]) 1775 if (chip->irq[0])
1802 free_irq(chip->irq[0], chip); 1776 free_irq(chip->irq[0], chip);
@@ -1830,7 +1804,7 @@ static int __init snd_cs4231_sbus_create(struct snd_card *card,
1830 spin_lock_init(&chip->p_dma.sbus_info.lock); 1804 spin_lock_init(&chip->p_dma.sbus_info.lock);
1831 mutex_init(&chip->mce_mutex); 1805 mutex_init(&chip->mce_mutex);
1832 mutex_init(&chip->open_mutex); 1806 mutex_init(&chip->open_mutex);
1833 chip->dev_u.op = op; 1807 chip->op = op;
1834 chip->regs_size = resource_size(&op->resource[0]); 1808 chip->regs_size = resource_size(&op->resource[0]);
1835 memcpy(&chip->image, &snd_cs4231_original_image, 1809 memcpy(&chip->image, &snd_cs4231_original_image,
1836 sizeof(snd_cs4231_original_image)); 1810 sizeof(snd_cs4231_original_image));
@@ -1851,13 +1825,11 @@ static int __init snd_cs4231_sbus_create(struct snd_card *card,
1851 chip->p_dma.enable = sbus_dma_enable; 1825 chip->p_dma.enable = sbus_dma_enable;
1852 chip->p_dma.request = sbus_dma_request; 1826 chip->p_dma.request = sbus_dma_request;
1853 chip->p_dma.address = sbus_dma_addr; 1827 chip->p_dma.address = sbus_dma_addr;
1854 chip->p_dma.preallocate = sbus_dma_preallocate;
1855 1828
1856 chip->c_dma.prepare = sbus_dma_prepare; 1829 chip->c_dma.prepare = sbus_dma_prepare;
1857 chip->c_dma.enable = sbus_dma_enable; 1830 chip->c_dma.enable = sbus_dma_enable;
1858 chip->c_dma.request = sbus_dma_request; 1831 chip->c_dma.request = sbus_dma_request;
1859 chip->c_dma.address = sbus_dma_addr; 1832 chip->c_dma.address = sbus_dma_addr;
1860 chip->c_dma.preallocate = sbus_dma_preallocate;
1861 1833
1862 if (request_irq(op->irqs[0], snd_cs4231_sbus_interrupt, 1834 if (request_irq(op->irqs[0], snd_cs4231_sbus_interrupt,
1863 IRQF_SHARED, "cs4231", chip)) { 1835 IRQF_SHARED, "cs4231", chip)) {
@@ -1883,16 +1855,12 @@ static int __init snd_cs4231_sbus_create(struct snd_card *card,
1883 return 0; 1855 return 0;
1884} 1856}
1885 1857
1886static int __devinit cs4231_probe(struct of_device *op, const struct of_device_id *match) 1858static int __devinit cs4231_sbus_probe(struct of_device *op, const struct of_device_id *match)
1887{ 1859{
1888 struct resource *rp = &op->resource[0]; 1860 struct resource *rp = &op->resource[0];
1889 struct snd_card *card; 1861 struct snd_card *card;
1890 int err; 1862 int err;
1891 1863
1892 if (strcmp(op->node->parent->name, "sbus") &&
1893 strcmp(op->node->parent->name, "sbi"))
1894 return -ENODEV;
1895
1896 err = cs4231_attach_begin(&card); 1864 err = cs4231_attach_begin(&card);
1897 if (err) 1865 if (err)
1898 return err; 1866 return err;
@@ -1956,30 +1924,25 @@ static unsigned int _ebus_dma_addr(struct cs4231_dma_control *dma_cont)
1956 return ebus_dma_addr(&dma_cont->ebus_info); 1924 return ebus_dma_addr(&dma_cont->ebus_info);
1957} 1925}
1958 1926
1959static void _ebus_dma_preallocate(struct snd_cs4231 *chip, struct snd_pcm *pcm)
1960{
1961 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1962 snd_dma_pci_data(chip->dev_u.pdev),
1963 64*1024, 128*1024);
1964}
1965
1966/* 1927/*
1967 * Init and exit routines 1928 * Init and exit routines
1968 */ 1929 */
1969 1930
1970static int snd_cs4231_ebus_free(struct snd_cs4231 *chip) 1931static int snd_cs4231_ebus_free(struct snd_cs4231 *chip)
1971{ 1932{
1933 struct of_device *op = chip->op;
1934
1972 if (chip->c_dma.ebus_info.regs) { 1935 if (chip->c_dma.ebus_info.regs) {
1973 ebus_dma_unregister(&chip->c_dma.ebus_info); 1936 ebus_dma_unregister(&chip->c_dma.ebus_info);
1974 iounmap(chip->c_dma.ebus_info.regs); 1937 of_iounmap(&op->resource[2], chip->c_dma.ebus_info.regs, 0x10);
1975 } 1938 }
1976 if (chip->p_dma.ebus_info.regs) { 1939 if (chip->p_dma.ebus_info.regs) {
1977 ebus_dma_unregister(&chip->p_dma.ebus_info); 1940 ebus_dma_unregister(&chip->p_dma.ebus_info);
1978 iounmap(chip->p_dma.ebus_info.regs); 1941 of_iounmap(&op->resource[1], chip->p_dma.ebus_info.regs, 0x10);
1979 } 1942 }
1980 1943
1981 if (chip->port) 1944 if (chip->port)
1982 iounmap(chip->port); 1945 of_iounmap(&op->resource[0], chip->port, 0x10);
1983 1946
1984 return 0; 1947 return 0;
1985} 1948}
@@ -1996,7 +1959,7 @@ static struct snd_device_ops snd_cs4231_ebus_dev_ops = {
1996}; 1959};
1997 1960
1998static int __init snd_cs4231_ebus_create(struct snd_card *card, 1961static int __init snd_cs4231_ebus_create(struct snd_card *card,
1999 struct linux_ebus_device *edev, 1962 struct of_device *op,
2000 int dev) 1963 int dev)
2001{ 1964{
2002 struct snd_cs4231 *chip = card->private_data; 1965 struct snd_cs4231 *chip = card->private_data;
@@ -2008,35 +1971,35 @@ static int __init snd_cs4231_ebus_create(struct snd_card *card,
2008 mutex_init(&chip->mce_mutex); 1971 mutex_init(&chip->mce_mutex);
2009 mutex_init(&chip->open_mutex); 1972 mutex_init(&chip->open_mutex);
2010 chip->flags |= CS4231_FLAG_EBUS; 1973 chip->flags |= CS4231_FLAG_EBUS;
2011 chip->dev_u.pdev = edev->bus->self; 1974 chip->op = op;
2012 memcpy(&chip->image, &snd_cs4231_original_image, 1975 memcpy(&chip->image, &snd_cs4231_original_image,
2013 sizeof(snd_cs4231_original_image)); 1976 sizeof(snd_cs4231_original_image));
2014 strcpy(chip->c_dma.ebus_info.name, "cs4231(capture)"); 1977 strcpy(chip->c_dma.ebus_info.name, "cs4231(capture)");
2015 chip->c_dma.ebus_info.flags = EBUS_DMA_FLAG_USE_EBDMA_HANDLER; 1978 chip->c_dma.ebus_info.flags = EBUS_DMA_FLAG_USE_EBDMA_HANDLER;
2016 chip->c_dma.ebus_info.callback = snd_cs4231_ebus_capture_callback; 1979 chip->c_dma.ebus_info.callback = snd_cs4231_ebus_capture_callback;
2017 chip->c_dma.ebus_info.client_cookie = chip; 1980 chip->c_dma.ebus_info.client_cookie = chip;
2018 chip->c_dma.ebus_info.irq = edev->irqs[0]; 1981 chip->c_dma.ebus_info.irq = op->irqs[0];
2019 strcpy(chip->p_dma.ebus_info.name, "cs4231(play)"); 1982 strcpy(chip->p_dma.ebus_info.name, "cs4231(play)");
2020 chip->p_dma.ebus_info.flags = EBUS_DMA_FLAG_USE_EBDMA_HANDLER; 1983 chip->p_dma.ebus_info.flags = EBUS_DMA_FLAG_USE_EBDMA_HANDLER;
2021 chip->p_dma.ebus_info.callback = snd_cs4231_ebus_play_callback; 1984 chip->p_dma.ebus_info.callback = snd_cs4231_ebus_play_callback;
2022 chip->p_dma.ebus_info.client_cookie = chip; 1985 chip->p_dma.ebus_info.client_cookie = chip;
2023 chip->p_dma.ebus_info.irq = edev->irqs[1]; 1986 chip->p_dma.ebus_info.irq = op->irqs[1];
2024 1987
2025 chip->p_dma.prepare = _ebus_dma_prepare; 1988 chip->p_dma.prepare = _ebus_dma_prepare;
2026 chip->p_dma.enable = _ebus_dma_enable; 1989 chip->p_dma.enable = _ebus_dma_enable;
2027 chip->p_dma.request = _ebus_dma_request; 1990 chip->p_dma.request = _ebus_dma_request;
2028 chip->p_dma.address = _ebus_dma_addr; 1991 chip->p_dma.address = _ebus_dma_addr;
2029 chip->p_dma.preallocate = _ebus_dma_preallocate;
2030 1992
2031 chip->c_dma.prepare = _ebus_dma_prepare; 1993 chip->c_dma.prepare = _ebus_dma_prepare;
2032 chip->c_dma.enable = _ebus_dma_enable; 1994 chip->c_dma.enable = _ebus_dma_enable;
2033 chip->c_dma.request = _ebus_dma_request; 1995 chip->c_dma.request = _ebus_dma_request;
2034 chip->c_dma.address = _ebus_dma_addr; 1996 chip->c_dma.address = _ebus_dma_addr;
2035 chip->c_dma.preallocate = _ebus_dma_preallocate;
2036 1997
2037 chip->port = ioremap(edev->resource[0].start, 0x10); 1998 chip->port = of_ioremap(&op->resource[0], 0, 0x10, "cs4231");
2038 chip->p_dma.ebus_info.regs = ioremap(edev->resource[1].start, 0x10); 1999 chip->p_dma.ebus_info.regs =
2039 chip->c_dma.ebus_info.regs = ioremap(edev->resource[2].start, 0x10); 2000 of_ioremap(&op->resource[1], 0, 0x10, "cs4231_pdma");
2001 chip->c_dma.ebus_info.regs =
2002 of_ioremap(&op->resource[2], 0, 0x10, "cs4231_cdma");
2040 if (!chip->port || !chip->p_dma.ebus_info.regs || 2003 if (!chip->port || !chip->p_dma.ebus_info.regs ||
2041 !chip->c_dma.ebus_info.regs) { 2004 !chip->c_dma.ebus_info.regs) {
2042 snd_cs4231_ebus_free(chip); 2005 snd_cs4231_ebus_free(chip);
@@ -2084,7 +2047,7 @@ static int __init snd_cs4231_ebus_create(struct snd_card *card,
2084 return 0; 2047 return 0;
2085} 2048}
2086 2049
2087static int __init cs4231_ebus_attach(struct linux_ebus_device *edev) 2050static int __devinit cs4231_ebus_probe(struct of_device *op, const struct of_device_id *match)
2088{ 2051{
2089 struct snd_card *card; 2052 struct snd_card *card;
2090 int err; 2053 int err;
@@ -2095,10 +2058,10 @@ static int __init cs4231_ebus_attach(struct linux_ebus_device *edev)
2095 2058
2096 sprintf(card->longname, "%s at 0x%lx, irq %d", 2059 sprintf(card->longname, "%s at 0x%lx, irq %d",
2097 card->shortname, 2060 card->shortname,
2098 edev->resource[0].start, 2061 op->resource[0].start,
2099 edev->irqs[0]); 2062 op->irqs[0]);
2100 2063
2101 err = snd_cs4231_ebus_create(card, edev, dev); 2064 err = snd_cs4231_ebus_create(card, op, dev);
2102 if (err < 0) { 2065 if (err < 0) {
2103 snd_card_free(card); 2066 snd_card_free(card);
2104 return err; 2067 return err;
@@ -2108,11 +2071,37 @@ static int __init cs4231_ebus_attach(struct linux_ebus_device *edev)
2108} 2071}
2109#endif 2072#endif
2110 2073
2074static int __devinit cs4231_probe(struct of_device *op, const struct of_device_id *match)
2075{
2076#ifdef EBUS_SUPPORT
2077 if (!strcmp(op->node->parent->name, "ebus"))
2078 return cs4231_ebus_probe(op, match);
2079#endif
2111#ifdef SBUS_SUPPORT 2080#ifdef SBUS_SUPPORT
2081 if (!strcmp(op->node->parent->name, "sbus") ||
2082 !strcmp(op->node->parent->name, "sbi"))
2083 return cs4231_sbus_probe(op, match);
2084#endif
2085 return -ENODEV;
2086}
2087
2088static int __devexit cs4231_remove(struct of_device *op)
2089{
2090 struct snd_cs4231 *chip = dev_get_drvdata(&op->dev);
2091
2092 snd_card_free(chip->card);
2093
2094 return 0;
2095}
2096
2112static struct of_device_id cs4231_match[] = { 2097static struct of_device_id cs4231_match[] = {
2113 { 2098 {
2114 .name = "SUNW,CS4231", 2099 .name = "SUNW,CS4231",
2115 }, 2100 },
2101 {
2102 .name = "audio",
2103 .compatible = "SUNW,CS4231",
2104 },
2116 {}, 2105 {},
2117}; 2106};
2118 2107
@@ -2122,70 +2111,17 @@ static struct of_platform_driver cs4231_driver = {
2122 .name = "audio", 2111 .name = "audio",
2123 .match_table = cs4231_match, 2112 .match_table = cs4231_match,
2124 .probe = cs4231_probe, 2113 .probe = cs4231_probe,
2114 .remove = __devexit_p(cs4231_remove),
2125}; 2115};
2126#endif
2127 2116
2128static int __init cs4231_init(void) 2117static int __init cs4231_init(void)
2129{ 2118{
2130#ifdef EBUS_SUPPORT 2119 return of_register_driver(&cs4231_driver, &of_bus_type);
2131 struct linux_ebus *ebus;
2132 struct linux_ebus_device *edev;
2133#endif
2134 int found;
2135
2136 found = 0;
2137
2138#ifdef SBUS_SUPPORT
2139 {
2140 int err = of_register_driver(&cs4231_driver, &of_bus_type);
2141 if (err)
2142 return err;
2143 }
2144#endif
2145#ifdef EBUS_SUPPORT
2146 for_each_ebus(ebus) {
2147 for_each_ebusdev(edev, ebus) {
2148 int match = 0;
2149
2150 if (!strcmp(edev->prom_node->name, "SUNW,CS4231")) {
2151 match = 1;
2152 } else if (!strcmp(edev->prom_node->name, "audio")) {
2153 const char *compat;
2154
2155 compat = of_get_property(edev->prom_node,
2156 "compatible", NULL);
2157 if (compat && !strcmp(compat, "SUNW,CS4231"))
2158 match = 1;
2159 }
2160
2161 if (match &&
2162 cs4231_ebus_attach(edev) == 0)
2163 found++;
2164 }
2165 }
2166#endif
2167
2168
2169 return 0;
2170} 2120}
2171 2121
2172static void __exit cs4231_exit(void) 2122static void __exit cs4231_exit(void)
2173{ 2123{
2174 struct snd_cs4231 *p = cs4231_list;
2175
2176#ifdef SBUS_SUPPORT
2177 of_unregister_driver(&cs4231_driver); 2124 of_unregister_driver(&cs4231_driver);
2178#endif
2179
2180 while (p != NULL) {
2181 struct snd_cs4231 *next = p->next;
2182
2183 snd_card_free(p->card);
2184
2185 p = next;
2186 }
2187
2188 cs4231_list = NULL;
2189} 2125}
2190 2126
2191module_init(cs4231_init); 2127module_init(cs4231_init);