Barry Song | dce944d | 2009-09-01 12:45:14 +0800 | [diff] [blame] | 1 | /* |
| 2 | * File: sound/soc/blackfin/bf5xx-ad1836.c |
| 3 | * Author: Barry Song <Barry.Song@analog.com> |
| 4 | * |
| 5 | * Created: Aug 4 2009 |
| 6 | * Description: Board driver for ad1836 sound chip |
| 7 | * |
| 8 | * Bugs: Enter bugs at http://blackfin.uclinux.org/ |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | */ |
| 16 | |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/moduleparam.h> |
| 19 | #include <linux/device.h> |
| 20 | #include <sound/core.h> |
| 21 | #include <sound/pcm.h> |
| 22 | #include <sound/soc.h> |
Barry Song | dce944d | 2009-09-01 12:45:14 +0800 | [diff] [blame] | 23 | #include <sound/pcm_params.h> |
| 24 | |
| 25 | #include <asm/blackfin.h> |
| 26 | #include <asm/cacheflush.h> |
| 27 | #include <asm/irq.h> |
| 28 | #include <asm/dma.h> |
| 29 | #include <asm/portmux.h> |
| 30 | |
| 31 | #include "../codecs/ad1836.h" |
Barry Song | dce944d | 2009-09-01 12:45:14 +0800 | [diff] [blame] | 32 | |
| 33 | #include "bf5xx-tdm-pcm.h" |
| 34 | #include "bf5xx-tdm.h" |
| 35 | |
| 36 | static struct snd_soc_card bf5xx_ad1836; |
| 37 | |
Barry Song | dce944d | 2009-09-01 12:45:14 +0800 | [diff] [blame] | 38 | static int bf5xx_ad1836_hw_params(struct snd_pcm_substream *substream, |
| 39 | struct snd_pcm_hw_params *params) |
| 40 | { |
| 41 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 42 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Barry Song | 08db48f | 2009-09-15 11:24:52 +0800 | [diff] [blame] | 43 | unsigned int channel_map[] = {0, 4, 1, 5, 2, 6, 3, 7}; |
Barry Song | dce944d | 2009-09-01 12:45:14 +0800 | [diff] [blame] | 44 | int ret = 0; |
Barry Song | dce944d | 2009-09-01 12:45:14 +0800 | [diff] [blame] | 45 | |
Barry Song | 08db48f | 2009-09-15 11:24:52 +0800 | [diff] [blame] | 46 | /* set cpu DAI channel mapping */ |
| 47 | ret = snd_soc_dai_set_channel_map(cpu_dai, ARRAY_SIZE(channel_map), |
| 48 | channel_map, ARRAY_SIZE(channel_map), channel_map); |
| 49 | if (ret < 0) |
| 50 | return ret; |
| 51 | |
Barry Song | dce944d | 2009-09-01 12:45:14 +0800 | [diff] [blame] | 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | static struct snd_soc_ops bf5xx_ad1836_ops = { |
Barry Song | dce944d | 2009-09-01 12:45:14 +0800 | [diff] [blame] | 56 | .hw_params = bf5xx_ad1836_hw_params, |
| 57 | }; |
| 58 | |
Lars-Peter Clausen | 980b0bc | 2012-02-01 19:24:21 +0100 | [diff] [blame] | 59 | #define BF5XX_AD1836_DAIFMT (SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_IF | \ |
| 60 | SND_SOC_DAIFMT_CBM_CFM) |
| 61 | |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 62 | static struct snd_soc_dai_link bf5xx_ad1836_dai[] = { |
| 63 | { |
| 64 | .name = "ad1836", |
| 65 | .stream_name = "AD1836", |
| 66 | .cpu_dai_name = "bfin-tdm.0", |
| 67 | .codec_dai_name = "ad1836-hifi", |
| 68 | .platform_name = "bfin-tdm-pcm-audio", |
Lars-Peter Clausen | 064d58e | 2011-06-07 10:24:46 +0200 | [diff] [blame] | 69 | .codec_name = "spi0.4", |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 70 | .ops = &bf5xx_ad1836_ops, |
Lars-Peter Clausen | 980b0bc | 2012-02-01 19:24:21 +0100 | [diff] [blame] | 71 | .dai_fmt = BF5XX_AD1836_DAIFMT, |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 72 | }, |
| 73 | { |
| 74 | .name = "ad1836", |
| 75 | .stream_name = "AD1836", |
| 76 | .cpu_dai_name = "bfin-tdm.1", |
| 77 | .codec_dai_name = "ad1836-hifi", |
| 78 | .platform_name = "bfin-tdm-pcm-audio", |
Lars-Peter Clausen | 064d58e | 2011-06-07 10:24:46 +0200 | [diff] [blame] | 79 | .codec_name = "spi0.4", |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 80 | .ops = &bf5xx_ad1836_ops, |
Lars-Peter Clausen | 980b0bc | 2012-02-01 19:24:21 +0100 | [diff] [blame] | 81 | .dai_fmt = BF5XX_AD1836_DAIFMT, |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 82 | }, |
Barry Song | dce944d | 2009-09-01 12:45:14 +0800 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | static struct snd_soc_card bf5xx_ad1836 = { |
Mike Frysinger | bfe4ee0 | 2011-03-28 01:45:09 -0400 | [diff] [blame] | 86 | .name = "bfin-ad1836", |
Axel Lin | 30e4953 | 2011-12-22 21:17:22 +0800 | [diff] [blame] | 87 | .owner = THIS_MODULE, |
Barry Song | 2c66cb9 | 2011-03-28 01:45:10 -0400 | [diff] [blame] | 88 | .dai_link = &bf5xx_ad1836_dai[CONFIG_SND_BF5XX_SPORT_NUM], |
Barry Song | dce944d | 2009-09-01 12:45:14 +0800 | [diff] [blame] | 89 | .num_links = 1, |
| 90 | }; |
| 91 | |
Barry Song | dce944d | 2009-09-01 12:45:14 +0800 | [diff] [blame] | 92 | static struct platform_device *bfxx_ad1836_snd_device; |
| 93 | |
| 94 | static int __init bf5xx_ad1836_init(void) |
| 95 | { |
| 96 | int ret; |
| 97 | |
| 98 | bfxx_ad1836_snd_device = platform_device_alloc("soc-audio", -1); |
| 99 | if (!bfxx_ad1836_snd_device) |
| 100 | return -ENOMEM; |
| 101 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 102 | platform_set_drvdata(bfxx_ad1836_snd_device, &bf5xx_ad1836); |
Barry Song | dce944d | 2009-09-01 12:45:14 +0800 | [diff] [blame] | 103 | ret = platform_device_add(bfxx_ad1836_snd_device); |
| 104 | |
| 105 | if (ret) |
| 106 | platform_device_put(bfxx_ad1836_snd_device); |
| 107 | |
| 108 | return ret; |
| 109 | } |
| 110 | |
| 111 | static void __exit bf5xx_ad1836_exit(void) |
| 112 | { |
| 113 | platform_device_unregister(bfxx_ad1836_snd_device); |
| 114 | } |
| 115 | |
| 116 | module_init(bf5xx_ad1836_init); |
| 117 | module_exit(bf5xx_ad1836_exit); |
| 118 | |
| 119 | /* Module information */ |
| 120 | MODULE_AUTHOR("Barry Song"); |
| 121 | MODULE_DESCRIPTION("ALSA SoC AD1836 board driver"); |
| 122 | MODULE_LICENSE("GPL"); |
| 123 | |