blob: 864df2616e109ae4e2bb70793e6231abe58fd1bc [file] [log] [blame]
Barry Songdce944d2009-09-01 12:45:14 +08001/*
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 Songdce944d2009-09-01 12:45:14 +080023#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 Songdce944d2009-09-01 12:45:14 +080032
Barry Songdce944d2009-09-01 12:45:14 +080033static struct snd_soc_card bf5xx_ad1836;
34
Lars-Peter Clausen34f40952013-05-28 19:22:16 +020035static int bf5xx_ad1836_init(struct snd_soc_pcm_runtime *rtd)
Barry Songdce944d2009-09-01 12:45:14 +080036{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000037 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Barry Song08db48f2009-09-15 11:24:52 +080038 unsigned int channel_map[] = {0, 4, 1, 5, 2, 6, 3, 7};
Barry Songdce944d2009-09-01 12:45:14 +080039 int ret = 0;
Barry Songdce944d2009-09-01 12:45:14 +080040
Barry Song08db48f2009-09-15 11:24:52 +080041 /* set cpu DAI channel mapping */
42 ret = snd_soc_dai_set_channel_map(cpu_dai, ARRAY_SIZE(channel_map),
43 channel_map, ARRAY_SIZE(channel_map), channel_map);
44 if (ret < 0)
45 return ret;
46
Lars-Peter Clausen34f40952013-05-28 19:22:16 +020047 ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0xFF, 0xFF, 8, 32);
48 if (ret < 0)
49 return ret;
50
Barry Songdce944d2009-09-01 12:45:14 +080051 return 0;
52}
53
Lars-Peter Clausen980b0bc2012-02-01 19:24:21 +010054#define BF5XX_AD1836_DAIFMT (SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_IF | \
55 SND_SOC_DAIFMT_CBM_CFM)
56
Scott Jiangd14a13d2012-08-10 18:06:08 -040057static struct snd_soc_dai_link bf5xx_ad1836_dai = {
58 .name = "ad1836",
59 .stream_name = "AD1836",
60 .codec_dai_name = "ad1836-hifi",
Lars-Peter Clausen34f40952013-05-28 19:22:16 +020061 .platform_name = "bfin-i2s-pcm-audio",
Scott Jiangd14a13d2012-08-10 18:06:08 -040062 .dai_fmt = BF5XX_AD1836_DAIFMT,
Lars-Peter Clausen34f40952013-05-28 19:22:16 +020063 .init = bf5xx_ad1836_init,
Barry Songdce944d2009-09-01 12:45:14 +080064};
65
66static struct snd_soc_card bf5xx_ad1836 = {
Mike Frysingerbfe4ee02011-03-28 01:45:09 -040067 .name = "bfin-ad1836",
Axel Lin30e49532011-12-22 21:17:22 +080068 .owner = THIS_MODULE,
Scott Jiangd14a13d2012-08-10 18:06:08 -040069 .dai_link = &bf5xx_ad1836_dai,
Barry Songdce944d2009-09-01 12:45:14 +080070 .num_links = 1,
71};
72
Bill Pembertondca66da2012-12-07 09:26:13 -050073static int bf5xx_ad1836_driver_probe(struct platform_device *pdev)
Barry Songdce944d2009-09-01 12:45:14 +080074{
Scott Jiangd14a13d2012-08-10 18:06:08 -040075 struct snd_soc_card *card = &bf5xx_ad1836;
76 const char **link_name;
Barry Songdce944d2009-09-01 12:45:14 +080077 int ret;
78
Scott Jiangd14a13d2012-08-10 18:06:08 -040079 link_name = pdev->dev.platform_data;
80 if (!link_name) {
81 dev_err(&pdev->dev, "No platform data supplied\n");
82 return -EINVAL;
83 }
84 bf5xx_ad1836_dai.cpu_dai_name = link_name[0];
85 bf5xx_ad1836_dai.codec_name = link_name[1];
Barry Songdce944d2009-09-01 12:45:14 +080086
Scott Jiangd14a13d2012-08-10 18:06:08 -040087 card->dev = &pdev->dev;
88 platform_set_drvdata(pdev, card);
Barry Songdce944d2009-09-01 12:45:14 +080089
Axel Lin76b0d1f2015-08-30 17:17:44 +080090 ret = devm_snd_soc_register_card(&pdev->dev, card);
Barry Songdce944d2009-09-01 12:45:14 +080091 if (ret)
Scott Jiangd14a13d2012-08-10 18:06:08 -040092 dev_err(&pdev->dev, "Failed to register card\n");
Barry Songdce944d2009-09-01 12:45:14 +080093 return ret;
94}
95
Scott Jiangd14a13d2012-08-10 18:06:08 -040096static struct platform_driver bf5xx_ad1836_driver = {
97 .driver = {
98 .name = "bfin-snd-ad1836",
Scott Jiangd14a13d2012-08-10 18:06:08 -040099 .pm = &snd_soc_pm_ops,
100 },
101 .probe = bf5xx_ad1836_driver_probe,
Scott Jiangd14a13d2012-08-10 18:06:08 -0400102};
103module_platform_driver(bf5xx_ad1836_driver);
Barry Songdce944d2009-09-01 12:45:14 +0800104
105/* Module information */
106MODULE_AUTHOR("Barry Song");
107MODULE_DESCRIPTION("ALSA SoC AD1836 board driver");
108MODULE_LICENSE("GPL");
109