aboutsummaryrefslogtreecommitdiffstats
path: root/sound/sparc/dbri.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/sparc/dbri.c')
-rw-r--r--sound/sparc/dbri.c106
1 files changed, 55 insertions, 51 deletions
diff --git a/sound/sparc/dbri.c b/sound/sparc/dbri.c
index ee2e1b4f3551..c257ad8bdfbc 100644
--- a/sound/sparc/dbri.c
+++ b/sound/sparc/dbri.c
@@ -57,6 +57,7 @@
57#include <linux/delay.h> 57#include <linux/delay.h>
58#include <linux/irq.h> 58#include <linux/irq.h>
59#include <linux/io.h> 59#include <linux/io.h>
60#include <linux/dma-mapping.h>
60 61
61#include <sound/core.h> 62#include <sound/core.h>
62#include <sound/pcm.h> 63#include <sound/pcm.h>
@@ -66,7 +67,7 @@
66#include <sound/initval.h> 67#include <sound/initval.h>
67 68
68#include <linux/of.h> 69#include <linux/of.h>
69#include <asm/sbus.h> 70#include <linux/of_device.h>
70#include <asm/atomic.h> 71#include <asm/atomic.h>
71 72
72MODULE_AUTHOR("Rudolf Koenig, Brent Baccala and Martin Habets"); 73MODULE_AUTHOR("Rudolf Koenig, Brent Baccala and Martin Habets");
@@ -297,7 +298,7 @@ struct dbri_streaminfo {
297/* This structure holds the information for both chips (DBRI & CS4215) */ 298/* This structure holds the information for both chips (DBRI & CS4215) */
298struct snd_dbri { 299struct snd_dbri {
299 int regs_size, irq; /* Needed for unload */ 300 int regs_size, irq; /* Needed for unload */
300 struct sbus_dev *sdev; /* SBUS device info */ 301 struct of_device *op; /* OF device info */
301 spinlock_t lock; 302 spinlock_t lock;
302 303
303 struct dbri_dma *dma; /* Pointer to our DMA block */ 304 struct dbri_dma *dma; /* Pointer to our DMA block */
@@ -2093,14 +2094,15 @@ static int snd_dbri_hw_params(struct snd_pcm_substream *substream,
2093 */ 2094 */
2094 if (info->dvma_buffer == 0) { 2095 if (info->dvma_buffer == 0) {
2095 if (DBRI_STREAMNO(substream) == DBRI_PLAY) 2096 if (DBRI_STREAMNO(substream) == DBRI_PLAY)
2096 direction = SBUS_DMA_TODEVICE; 2097 direction = DMA_TO_DEVICE;
2097 else 2098 else
2098 direction = SBUS_DMA_FROMDEVICE; 2099 direction = DMA_FROM_DEVICE;
2099 2100
2100 info->dvma_buffer = sbus_map_single(dbri->sdev, 2101 info->dvma_buffer =
2101 runtime->dma_area, 2102 dma_map_single(&dbri->op->dev,
2102 params_buffer_bytes(hw_params), 2103 runtime->dma_area,
2103 direction); 2104 params_buffer_bytes(hw_params),
2105 direction);
2104 } 2106 }
2105 2107
2106 direction = params_buffer_bytes(hw_params); 2108 direction = params_buffer_bytes(hw_params);
@@ -2121,12 +2123,12 @@ static int snd_dbri_hw_free(struct snd_pcm_substream *substream)
2121 */ 2123 */
2122 if (info->dvma_buffer) { 2124 if (info->dvma_buffer) {
2123 if (DBRI_STREAMNO(substream) == DBRI_PLAY) 2125 if (DBRI_STREAMNO(substream) == DBRI_PLAY)
2124 direction = SBUS_DMA_TODEVICE; 2126 direction = DMA_TO_DEVICE;
2125 else 2127 else
2126 direction = SBUS_DMA_FROMDEVICE; 2128 direction = DMA_FROM_DEVICE;
2127 2129
2128 sbus_unmap_single(dbri->sdev, info->dvma_buffer, 2130 dma_unmap_single(&dbri->op->dev, info->dvma_buffer,
2129 substream->runtime->buffer_size, direction); 2131 substream->runtime->buffer_size, direction);
2130 info->dvma_buffer = 0; 2132 info->dvma_buffer = 0;
2131 } 2133 }
2132 if (info->pipe != -1) { 2134 if (info->pipe != -1) {
@@ -2223,7 +2225,6 @@ static int __devinit snd_dbri_pcm(struct snd_card *card)
2223 /* playback count */ 1, 2225 /* playback count */ 1,
2224 /* capture count */ 1, &pcm)) < 0) 2226 /* capture count */ 1, &pcm)) < 0)
2225 return err; 2227 return err;
2226 snd_assert(pcm != NULL, return -EINVAL);
2227 2228
2228 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_dbri_ops); 2229 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_dbri_ops);
2229 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_dbri_ops); 2230 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_dbri_ops);
@@ -2263,9 +2264,10 @@ static int snd_cs4215_get_volume(struct snd_kcontrol *kcontrol,
2263{ 2264{
2264 struct snd_dbri *dbri = snd_kcontrol_chip(kcontrol); 2265 struct snd_dbri *dbri = snd_kcontrol_chip(kcontrol);
2265 struct dbri_streaminfo *info; 2266 struct dbri_streaminfo *info;
2266 snd_assert(dbri != NULL, return -EINVAL); 2267
2268 if (snd_BUG_ON(!dbri))
2269 return -EINVAL;
2267 info = &dbri->stream_info[kcontrol->private_value]; 2270 info = &dbri->stream_info[kcontrol->private_value];
2268 snd_assert(info != NULL, return -EINVAL);
2269 2271
2270 ucontrol->value.integer.value[0] = info->left_gain; 2272 ucontrol->value.integer.value[0] = info->left_gain;
2271 ucontrol->value.integer.value[1] = info->right_gain; 2273 ucontrol->value.integer.value[1] = info->right_gain;
@@ -2331,7 +2333,9 @@ static int snd_cs4215_get_single(struct snd_kcontrol *kcontrol,
2331 int shift = (kcontrol->private_value >> 8) & 0xff; 2333 int shift = (kcontrol->private_value >> 8) & 0xff;
2332 int mask = (kcontrol->private_value >> 16) & 0xff; 2334 int mask = (kcontrol->private_value >> 16) & 0xff;
2333 int invert = (kcontrol->private_value >> 24) & 1; 2335 int invert = (kcontrol->private_value >> 24) & 1;
2334 snd_assert(dbri != NULL, return -EINVAL); 2336
2337 if (snd_BUG_ON(!dbri))
2338 return -EINVAL;
2335 2339
2336 if (elem < 4) 2340 if (elem < 4)
2337 ucontrol->value.integer.value[0] = 2341 ucontrol->value.integer.value[0] =
@@ -2356,7 +2360,9 @@ static int snd_cs4215_put_single(struct snd_kcontrol *kcontrol,
2356 int invert = (kcontrol->private_value >> 24) & 1; 2360 int invert = (kcontrol->private_value >> 24) & 1;
2357 int changed = 0; 2361 int changed = 0;
2358 unsigned short val; 2362 unsigned short val;
2359 snd_assert(dbri != NULL, return -EINVAL); 2363
2364 if (snd_BUG_ON(!dbri))
2365 return -EINVAL;
2360 2366
2361 val = (ucontrol->value.integer.value[0] & mask); 2367 val = (ucontrol->value.integer.value[0] & mask);
2362 if (invert == 1) 2368 if (invert == 1)
@@ -2432,7 +2438,8 @@ static int __devinit snd_dbri_mixer(struct snd_card *card)
2432 int idx, err; 2438 int idx, err;
2433 struct snd_dbri *dbri; 2439 struct snd_dbri *dbri;
2434 2440
2435 snd_assert(card != NULL && card->private_data != NULL, return -EINVAL); 2441 if (snd_BUG_ON(!card || !card->private_data))
2442 return -EINVAL;
2436 dbri = card->private_data; 2443 dbri = card->private_data;
2437 2444
2438 strcpy(card->mixername, card->shortname); 2445 strcpy(card->mixername, card->shortname);
@@ -2514,31 +2521,32 @@ static void __devinit snd_dbri_proc(struct snd_card *card)
2514static void snd_dbri_free(struct snd_dbri *dbri); 2521static void snd_dbri_free(struct snd_dbri *dbri);
2515 2522
2516static int __devinit snd_dbri_create(struct snd_card *card, 2523static int __devinit snd_dbri_create(struct snd_card *card,
2517 struct sbus_dev *sdev, 2524 struct of_device *op,
2518 int irq, int dev) 2525 int irq, int dev)
2519{ 2526{
2520 struct snd_dbri *dbri = card->private_data; 2527 struct snd_dbri *dbri = card->private_data;
2521 int err; 2528 int err;
2522 2529
2523 spin_lock_init(&dbri->lock); 2530 spin_lock_init(&dbri->lock);
2524 dbri->sdev = sdev; 2531 dbri->op = op;
2525 dbri->irq = irq; 2532 dbri->irq = irq;
2526 2533
2527 dbri->dma = sbus_alloc_consistent(sdev, sizeof(struct dbri_dma), 2534 dbri->dma = dma_alloc_coherent(&op->dev,
2528 &dbri->dma_dvma); 2535 sizeof(struct dbri_dma),
2536 &dbri->dma_dvma, GFP_ATOMIC);
2529 memset((void *)dbri->dma, 0, sizeof(struct dbri_dma)); 2537 memset((void *)dbri->dma, 0, sizeof(struct dbri_dma));
2530 2538
2531 dprintk(D_GEN, "DMA Cmd Block 0x%p (0x%08x)\n", 2539 dprintk(D_GEN, "DMA Cmd Block 0x%p (0x%08x)\n",
2532 dbri->dma, dbri->dma_dvma); 2540 dbri->dma, dbri->dma_dvma);
2533 2541
2534 /* Map the registers into memory. */ 2542 /* Map the registers into memory. */
2535 dbri->regs_size = sdev->reg_addrs[0].reg_size; 2543 dbri->regs_size = resource_size(&op->resource[0]);
2536 dbri->regs = sbus_ioremap(&sdev->resource[0], 0, 2544 dbri->regs = of_ioremap(&op->resource[0], 0,
2537 dbri->regs_size, "DBRI Registers"); 2545 dbri->regs_size, "DBRI Registers");
2538 if (!dbri->regs) { 2546 if (!dbri->regs) {
2539 printk(KERN_ERR "DBRI: could not allocate registers\n"); 2547 printk(KERN_ERR "DBRI: could not allocate registers\n");
2540 sbus_free_consistent(sdev, sizeof(struct dbri_dma), 2548 dma_free_coherent(&op->dev, sizeof(struct dbri_dma),
2541 (void *)dbri->dma, dbri->dma_dvma); 2549 (void *)dbri->dma, dbri->dma_dvma);
2542 return -EIO; 2550 return -EIO;
2543 } 2551 }
2544 2552
@@ -2546,9 +2554,9 @@ static int __devinit snd_dbri_create(struct snd_card *card,
2546 "DBRI audio", dbri); 2554 "DBRI audio", dbri);
2547 if (err) { 2555 if (err) {
2548 printk(KERN_ERR "DBRI: Can't get irq %d\n", dbri->irq); 2556 printk(KERN_ERR "DBRI: Can't get irq %d\n", dbri->irq);
2549 sbus_iounmap(dbri->regs, dbri->regs_size); 2557 of_iounmap(&op->resource[0], dbri->regs, dbri->regs_size);
2550 sbus_free_consistent(sdev, sizeof(struct dbri_dma), 2558 dma_free_coherent(&op->dev, sizeof(struct dbri_dma),
2551 (void *)dbri->dma, dbri->dma_dvma); 2559 (void *)dbri->dma, dbri->dma_dvma);
2552 return err; 2560 return err;
2553 } 2561 }
2554 2562
@@ -2572,27 +2580,23 @@ static void snd_dbri_free(struct snd_dbri *dbri)
2572 free_irq(dbri->irq, dbri); 2580 free_irq(dbri->irq, dbri);
2573 2581
2574 if (dbri->regs) 2582 if (dbri->regs)
2575 sbus_iounmap(dbri->regs, dbri->regs_size); 2583 of_iounmap(&dbri->op->resource[0], dbri->regs, dbri->regs_size);
2576 2584
2577 if (dbri->dma) 2585 if (dbri->dma)
2578 sbus_free_consistent(dbri->sdev, sizeof(struct dbri_dma), 2586 dma_free_coherent(&dbri->op->dev,
2579 (void *)dbri->dma, dbri->dma_dvma); 2587 sizeof(struct dbri_dma),
2588 (void *)dbri->dma, dbri->dma_dvma);
2580} 2589}
2581 2590
2582static int __devinit dbri_probe(struct of_device *of_dev, 2591static int __devinit dbri_probe(struct of_device *op, const struct of_device_id *match)
2583 const struct of_device_id *match)
2584{ 2592{
2585 struct sbus_dev *sdev = to_sbus_device(&of_dev->dev);
2586 struct snd_dbri *dbri; 2593 struct snd_dbri *dbri;
2587 int irq;
2588 struct resource *rp; 2594 struct resource *rp;
2589 struct snd_card *card; 2595 struct snd_card *card;
2590 static int dev = 0; 2596 static int dev = 0;
2597 int irq;
2591 int err; 2598 int err;
2592 2599
2593 dprintk(D_GEN, "DBRI: Found %s in SBUS slot %d\n",
2594 sdev->prom_name, sdev->slot);
2595
2596 if (dev >= SNDRV_CARDS) 2600 if (dev >= SNDRV_CARDS)
2597 return -ENODEV; 2601 return -ENODEV;
2598 if (!enable[dev]) { 2602 if (!enable[dev]) {
@@ -2600,7 +2604,7 @@ static int __devinit dbri_probe(struct of_device *of_dev,
2600 return -ENOENT; 2604 return -ENOENT;
2601 } 2605 }
2602 2606
2603 irq = sdev->irqs[0]; 2607 irq = op->irqs[0];
2604 if (irq <= 0) { 2608 if (irq <= 0) {
2605 printk(KERN_ERR "DBRI-%d: No IRQ.\n", dev); 2609 printk(KERN_ERR "DBRI-%d: No IRQ.\n", dev);
2606 return -ENODEV; 2610 return -ENODEV;
@@ -2613,12 +2617,12 @@ static int __devinit dbri_probe(struct of_device *of_dev,
2613 2617
2614 strcpy(card->driver, "DBRI"); 2618 strcpy(card->driver, "DBRI");
2615 strcpy(card->shortname, "Sun DBRI"); 2619 strcpy(card->shortname, "Sun DBRI");
2616 rp = &sdev->resource[0]; 2620 rp = &op->resource[0];
2617 sprintf(card->longname, "%s at 0x%02lx:0x%016Lx, irq %d", 2621 sprintf(card->longname, "%s at 0x%02lx:0x%016Lx, irq %d",
2618 card->shortname, 2622 card->shortname,
2619 rp->flags & 0xffL, (unsigned long long)rp->start, irq); 2623 rp->flags & 0xffL, (unsigned long long)rp->start, irq);
2620 2624
2621 err = snd_dbri_create(card, sdev, irq, dev); 2625 err = snd_dbri_create(card, op, irq, dev);
2622 if (err < 0) { 2626 if (err < 0) {
2623 snd_card_free(card); 2627 snd_card_free(card);
2624 return err; 2628 return err;
@@ -2635,7 +2639,7 @@ static int __devinit dbri_probe(struct of_device *of_dev,
2635 2639
2636 /* /proc file handling */ 2640 /* /proc file handling */
2637 snd_dbri_proc(card); 2641 snd_dbri_proc(card);
2638 dev_set_drvdata(&of_dev->dev, card); 2642 dev_set_drvdata(&op->dev, card);
2639 2643
2640 err = snd_card_register(card); 2644 err = snd_card_register(card);
2641 if (err < 0) 2645 if (err < 0)
@@ -2643,7 +2647,7 @@ static int __devinit dbri_probe(struct of_device *of_dev,
2643 2647
2644 printk(KERN_INFO "audio%d at %p (irq %d) is DBRI(%c)+CS4215(%d)\n", 2648 printk(KERN_INFO "audio%d at %p (irq %d) is DBRI(%c)+CS4215(%d)\n",
2645 dev, dbri->regs, 2649 dev, dbri->regs,
2646 dbri->irq, sdev->prom_name[9], dbri->mm.version); 2650 dbri->irq, op->node->name[9], dbri->mm.version);
2647 dev++; 2651 dev++;
2648 2652
2649 return 0; 2653 return 0;
@@ -2654,19 +2658,19 @@ _err:
2654 return err; 2658 return err;
2655} 2659}
2656 2660
2657static int __devexit dbri_remove(struct of_device *dev) 2661static int __devexit dbri_remove(struct of_device *op)
2658{ 2662{
2659 struct snd_card *card = dev_get_drvdata(&dev->dev); 2663 struct snd_card *card = dev_get_drvdata(&op->dev);
2660 2664
2661 snd_dbri_free(card->private_data); 2665 snd_dbri_free(card->private_data);
2662 snd_card_free(card); 2666 snd_card_free(card);
2663 2667
2664 dev_set_drvdata(&dev->dev, NULL); 2668 dev_set_drvdata(&op->dev, NULL);
2665 2669
2666 return 0; 2670 return 0;
2667} 2671}
2668 2672
2669static struct of_device_id dbri_match[] = { 2673static const struct of_device_id dbri_match[] = {
2670 { 2674 {
2671 .name = "SUNW,DBRIe", 2675 .name = "SUNW,DBRIe",
2672 }, 2676 },
@@ -2688,7 +2692,7 @@ static struct of_platform_driver dbri_sbus_driver = {
2688/* Probe for the dbri chip and then attach the driver. */ 2692/* Probe for the dbri chip and then attach the driver. */
2689static int __init dbri_init(void) 2693static int __init dbri_init(void)
2690{ 2694{
2691 return of_register_driver(&dbri_sbus_driver, &sbus_bus_type); 2695 return of_register_driver(&dbri_sbus_driver, &of_bus_type);
2692} 2696}
2693 2697
2694static void __exit dbri_exit(void) 2698static void __exit dbri_exit(void)