Commit afc88ad6b38797aeec4d635140099ace077df587

Authored by David S. Miller
1 parent 3ae627a19e

cs4231: Convert to EBUS side to pure OF driver.

Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 1 changed file with 54 additions and 118 deletions Side-by-side Diff

sound/sparc/cs4231.c
... ... @@ -35,7 +35,6 @@
35 35 #if defined(CONFIG_PCI) && defined(CONFIG_SPARC64)
36 36 #define EBUS_SUPPORT
37 37 #include <linux/pci.h>
38   -#include <asm/ebus.h>
39 38 #include <asm/ebus_dma.h>
40 39 #endif
41 40  
... ... @@ -71,8 +70,6 @@
71 70 int (*request)(struct cs4231_dma_control *dma_cont,
72 71 dma_addr_t bus_addr, size_t len);
73 72 unsigned int (*address)(struct cs4231_dma_control *dma_cont);
74   - void (*preallocate)(struct snd_cs4231 *chip,
75   - struct snd_pcm *pcm);
76 73 #ifdef EBUS_SUPPORT
77 74 struct ebus_dma_info ebus_info;
78 75 #endif
79 76  
... ... @@ -115,21 +112,12 @@
115 112 struct mutex mce_mutex; /* mutex for mce register */
116 113 struct mutex open_mutex; /* mutex for ALSA open/close */
117 114  
118   - union {
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;
  115 + struct of_device *op;
126 116 unsigned int irq[2];
127 117 unsigned int regs_size;
128 118 struct snd_cs4231 *next;
129 119 };
130 120  
131   -static struct snd_cs4231 *cs4231_list;
132   -
133 121 /* Eventually we can use sound/isa/cs423x/cs4231_lib.c directly, but for
134 122 * now.... -DaveM
135 123 */
136 124  
137 125  
138 126  
139 127  
140 128  
... ... @@ -268,27 +256,19 @@
268 256  
269 257 static u8 __cs4231_readb(struct snd_cs4231 *cp, void __iomem *reg_addr)
270 258 {
271   -#ifdef EBUS_SUPPORT
272 259 if (cp->flags & CS4231_FLAG_EBUS)
273 260 return readb(reg_addr);
274 261 else
275   -#endif
276   -#ifdef SBUS_SUPPORT
277 262 return sbus_readb(reg_addr);
278   -#endif
279 263 }
280 264  
281 265 static void __cs4231_writeb(struct snd_cs4231 *cp, u8 val,
282 266 void __iomem *reg_addr)
283 267 {
284   -#ifdef EBUS_SUPPORT
285 268 if (cp->flags & CS4231_FLAG_EBUS)
286 269 return writeb(val, reg_addr);
287 270 else
288   -#endif
289   -#ifdef SBUS_SUPPORT
290 271 return sbus_writeb(val, reg_addr);
291   -#endif
292 272 }
293 273  
294 274 /*
... ... @@ -1259,7 +1239,9 @@
1259 1239 pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
1260 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 1246 chip->pcm = pcm;
1265 1247  
... ... @@ -1627,8 +1609,7 @@
1627 1609 if (err < 0)
1628 1610 goto out_err;
1629 1611  
1630   - chip->next = cs4231_list;
1631   - cs4231_list = chip;
  1612 + dev_set_drvdata(&chip->op->dev, chip);
1632 1613  
1633 1614 dev++;
1634 1615 return 0;
1635 1616  
... ... @@ -1783,20 +1764,13 @@
1783 1764 return sbus_readl(base->regs + base->dir + APCVA);
1784 1765 }
1785 1766  
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_DEV,
1789   - &chip->dev_u.op->dev,
1790   - 64 * 1024, 128 * 1024);
1791   -}
1792   -
1793 1767 /*
1794 1768 * Init and exit routines
1795 1769 */
1796 1770  
1797 1771 static 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 1775 if (chip->irq[0])
1802 1776 free_irq(chip->irq[0], chip);
... ... @@ -1830,7 +1804,7 @@
1830 1804 spin_lock_init(&chip->p_dma.sbus_info.lock);
1831 1805 mutex_init(&chip->mce_mutex);
1832 1806 mutex_init(&chip->open_mutex);
1833   - chip->dev_u.op = op;
  1807 + chip->op = op;
1834 1808 chip->regs_size = resource_size(&op->resource[0]);
1835 1809 memcpy(&chip->image, &snd_cs4231_original_image,
1836 1810 sizeof(snd_cs4231_original_image));
1837 1811  
... ... @@ -1851,13 +1825,11 @@
1851 1825 chip->p_dma.enable = sbus_dma_enable;
1852 1826 chip->p_dma.request = sbus_dma_request;
1853 1827 chip->p_dma.address = sbus_dma_addr;
1854   - chip->p_dma.preallocate = sbus_dma_preallocate;
1855 1828  
1856 1829 chip->c_dma.prepare = sbus_dma_prepare;
1857 1830 chip->c_dma.enable = sbus_dma_enable;
1858 1831 chip->c_dma.request = sbus_dma_request;
1859 1832 chip->c_dma.address = sbus_dma_addr;
1860   - chip->c_dma.preallocate = sbus_dma_preallocate;
1861 1833  
1862 1834 if (request_irq(op->irqs[0], snd_cs4231_sbus_interrupt,
1863 1835 IRQF_SHARED, "cs4231", chip)) {
1864 1836  
... ... @@ -1883,16 +1855,12 @@
1883 1855 return 0;
1884 1856 }
1885 1857  
1886   -static int __devinit cs4231_probe(struct of_device *op, const struct of_device_id *match)
  1858 +static int __devinit cs4231_sbus_probe(struct of_device *op, const struct of_device_id *match)
1887 1859 {
1888 1860 struct resource *rp = &op->resource[0];
1889 1861 struct snd_card *card;
1890 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 1864 err = cs4231_attach_begin(&card);
1897 1865 if (err)
1898 1866 return err;
1899 1867  
1900 1868  
1901 1869  
1902 1870  
... ... @@ -1956,30 +1924,25 @@
1956 1924 return ebus_dma_addr(&dma_cont->ebus_info);
1957 1925 }
1958 1926  
1959   -static 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 1928 * Init and exit routines
1968 1929 */
1969 1930  
1970 1931 static int snd_cs4231_ebus_free(struct snd_cs4231 *chip)
1971 1932 {
  1933 + struct of_device *op = chip->op;
  1934 +
1972 1935 if (chip->c_dma.ebus_info.regs) {
1973 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 1939 if (chip->p_dma.ebus_info.regs) {
1977 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 1944 if (chip->port)
1982   - iounmap(chip->port);
  1945 + of_iounmap(&op->resource[0], chip->port, 0x10);
1983 1946  
1984 1947 return 0;
1985 1948 }
... ... @@ -1996,7 +1959,7 @@
1996 1959 };
1997 1960  
1998 1961 static int __init snd_cs4231_ebus_create(struct snd_card *card,
1999   - struct linux_ebus_device *edev,
  1962 + struct of_device *op,
2000 1963 int dev)
2001 1964 {
2002 1965 struct snd_cs4231 *chip = card->private_data;
2003 1966  
2004 1967  
2005 1968  
2006 1969  
2007 1970  
... ... @@ -2008,35 +1971,35 @@
2008 1971 mutex_init(&chip->mce_mutex);
2009 1972 mutex_init(&chip->open_mutex);
2010 1973 chip->flags |= CS4231_FLAG_EBUS;
2011   - chip->dev_u.pdev = edev->bus->self;
  1974 + chip->op = op;
2012 1975 memcpy(&chip->image, &snd_cs4231_original_image,
2013 1976 sizeof(snd_cs4231_original_image));
2014 1977 strcpy(chip->c_dma.ebus_info.name, "cs4231(capture)");
2015 1978 chip->c_dma.ebus_info.flags = EBUS_DMA_FLAG_USE_EBDMA_HANDLER;
2016 1979 chip->c_dma.ebus_info.callback = snd_cs4231_ebus_capture_callback;
2017 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 1982 strcpy(chip->p_dma.ebus_info.name, "cs4231(play)");
2020 1983 chip->p_dma.ebus_info.flags = EBUS_DMA_FLAG_USE_EBDMA_HANDLER;
2021 1984 chip->p_dma.ebus_info.callback = snd_cs4231_ebus_play_callback;
2022 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 1988 chip->p_dma.prepare = _ebus_dma_prepare;
2026 1989 chip->p_dma.enable = _ebus_dma_enable;
2027 1990 chip->p_dma.request = _ebus_dma_request;
2028 1991 chip->p_dma.address = _ebus_dma_addr;
2029   - chip->p_dma.preallocate = _ebus_dma_preallocate;
2030 1992  
2031 1993 chip->c_dma.prepare = _ebus_dma_prepare;
2032 1994 chip->c_dma.enable = _ebus_dma_enable;
2033 1995 chip->c_dma.request = _ebus_dma_request;
2034 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);
2038   - chip->p_dma.ebus_info.regs = ioremap(edev->resource[1].start, 0x10);
2039   - chip->c_dma.ebus_info.regs = ioremap(edev->resource[2].start, 0x10);
  1998 + chip->port = of_ioremap(&op->resource[0], 0, 0x10, "cs4231");
  1999 + chip->p_dma.ebus_info.regs =
  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 2003 if (!chip->port || !chip->p_dma.ebus_info.regs ||
2041 2004 !chip->c_dma.ebus_info.regs) {
2042 2005 snd_cs4231_ebus_free(chip);
... ... @@ -2084,7 +2047,7 @@
2084 2047 return 0;
2085 2048 }
2086 2049  
2087   -static int __init cs4231_ebus_attach(struct linux_ebus_device *edev)
  2050 +static int __devinit cs4231_ebus_probe(struct of_device *op, const struct of_device_id *match)
2088 2051 {
2089 2052 struct snd_card *card;
2090 2053 int err;
2091 2054  
... ... @@ -2095,10 +2058,10 @@
2095 2058  
2096 2059 sprintf(card->longname, "%s at 0x%lx, irq %d",
2097 2060 card->shortname,
2098   - edev->resource[0].start,
2099   - edev->irqs[0]);
  2061 + op->resource[0].start,
  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 2065 if (err < 0) {
2103 2066 snd_card_free(card);
2104 2067 return err;
2105 2068  
2106 2069  
... ... @@ -2108,11 +2071,37 @@
2108 2071 }
2109 2072 #endif
2110 2073  
  2074 +static 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 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 +
  2088 +static 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 +
2112 2097 static struct of_device_id cs4231_match[] = {
2113 2098 {
2114 2099 .name = "SUNW,CS4231",
2115 2100 },
  2101 + {
  2102 + .name = "audio",
  2103 + .compatible = "SUNW,CS4231",
  2104 + },
2116 2105 {},
2117 2106 };
2118 2107  
2119 2108  
2120 2109  
2121 2110  
2122 2111  
... ... @@ -2122,70 +2111,17 @@
2122 2111 .name = "audio",
2123 2112 .match_table = cs4231_match,
2124 2113 .probe = cs4231_probe,
  2114 + .remove = __devexit_p(cs4231_remove),
2125 2115 };
2126   -#endif
2127 2116  
2128 2117 static int __init cs4231_init(void)
2129 2118 {
2130   -#ifdef EBUS_SUPPORT
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;
  2119 + return of_register_driver(&cs4231_driver, &of_bus_type);
2170 2120 }
2171 2121  
2172 2122 static void __exit cs4231_exit(void)
2173 2123 {
2174   - struct snd_cs4231 *p = cs4231_list;
2175   -
2176   -#ifdef SBUS_SUPPORT
2177 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  
2191 2127 module_init(cs4231_init);