Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ASoC simple sound card support |
| 3 | * |
| 4 | * Copyright (C) 2012 Renesas Solutions Corp. |
| 5 | * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/platform_device.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <sound/simple_card.h> |
| 15 | |
| 16 | #define asoc_simple_get_card_info(p) \ |
| 17 | container_of(p->dai_link, struct asoc_simple_card_info, snd_link) |
| 18 | |
Kuninori Morimoto | a4a2992 | 2013-01-10 16:49:11 -0800 | [diff] [blame] | 19 | static int __asoc_simple_card_dai_init(struct snd_soc_dai *dai, |
| 20 | struct asoc_simple_dai *set, |
| 21 | unsigned int daifmt) |
| 22 | { |
| 23 | int ret = 0; |
| 24 | |
| 25 | daifmt |= set->fmt; |
| 26 | |
| 27 | if (!ret && daifmt) |
| 28 | ret = snd_soc_dai_set_fmt(dai, daifmt); |
| 29 | |
Kuninori Morimoto | e244bb9 | 2013-10-17 22:46:49 -0700 | [diff] [blame^] | 30 | if (ret == -ENOTSUPP) { |
| 31 | dev_dbg(dai->dev, "ASoC: set_fmt is not supported\n"); |
| 32 | ret = 0; |
| 33 | } |
| 34 | |
Kuninori Morimoto | a4a2992 | 2013-01-10 16:49:11 -0800 | [diff] [blame] | 35 | if (!ret && set->sysclk) |
| 36 | ret = snd_soc_dai_set_sysclk(dai, 0, set->sysclk, 0); |
| 37 | |
| 38 | return ret; |
| 39 | } |
| 40 | |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 41 | static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd) |
| 42 | { |
Kuninori Morimoto | a4a2992 | 2013-01-10 16:49:11 -0800 | [diff] [blame] | 43 | struct asoc_simple_card_info *info = asoc_simple_get_card_info(rtd); |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 44 | struct snd_soc_dai *codec = rtd->codec_dai; |
| 45 | struct snd_soc_dai *cpu = rtd->cpu_dai; |
Kuninori Morimoto | a4a2992 | 2013-01-10 16:49:11 -0800 | [diff] [blame] | 46 | unsigned int daifmt = info->daifmt; |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 47 | int ret; |
| 48 | |
Kuninori Morimoto | a4a2992 | 2013-01-10 16:49:11 -0800 | [diff] [blame] | 49 | ret = __asoc_simple_card_dai_init(codec, &info->codec_dai, daifmt); |
| 50 | if (ret < 0) |
| 51 | return ret; |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 52 | |
Kuninori Morimoto | a4a2992 | 2013-01-10 16:49:11 -0800 | [diff] [blame] | 53 | ret = __asoc_simple_card_dai_init(cpu, &info->cpu_dai, daifmt); |
| 54 | if (ret < 0) |
| 55 | return ret; |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | static int asoc_simple_card_probe(struct platform_device *pdev) |
| 61 | { |
| 62 | struct asoc_simple_card_info *cinfo = pdev->dev.platform_data; |
Kuninori Morimoto | f89983e | 2012-12-25 22:52:33 -0800 | [diff] [blame] | 63 | struct device *dev = &pdev->dev; |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 64 | |
| 65 | if (!cinfo) { |
Kuninori Morimoto | f89983e | 2012-12-25 22:52:33 -0800 | [diff] [blame] | 66 | dev_err(dev, "no info for asoc-simple-card\n"); |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 67 | return -EINVAL; |
| 68 | } |
| 69 | |
| 70 | if (!cinfo->name || |
| 71 | !cinfo->card || |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 72 | !cinfo->codec || |
| 73 | !cinfo->platform || |
Kuninori Morimoto | a4a2992 | 2013-01-10 16:49:11 -0800 | [diff] [blame] | 74 | !cinfo->cpu_dai.name || |
| 75 | !cinfo->codec_dai.name) { |
Kuninori Morimoto | f89983e | 2012-12-25 22:52:33 -0800 | [diff] [blame] | 76 | dev_err(dev, "insufficient asoc_simple_card_info settings\n"); |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 77 | return -EINVAL; |
| 78 | } |
| 79 | |
| 80 | /* |
| 81 | * init snd_soc_dai_link |
| 82 | */ |
| 83 | cinfo->snd_link.name = cinfo->name; |
| 84 | cinfo->snd_link.stream_name = cinfo->name; |
Kuninori Morimoto | a4a2992 | 2013-01-10 16:49:11 -0800 | [diff] [blame] | 85 | cinfo->snd_link.cpu_dai_name = cinfo->cpu_dai.name; |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 86 | cinfo->snd_link.platform_name = cinfo->platform; |
| 87 | cinfo->snd_link.codec_name = cinfo->codec; |
Kuninori Morimoto | a4a2992 | 2013-01-10 16:49:11 -0800 | [diff] [blame] | 88 | cinfo->snd_link.codec_dai_name = cinfo->codec_dai.name; |
| 89 | cinfo->snd_link.init = asoc_simple_card_dai_init; |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 90 | |
| 91 | /* |
| 92 | * init snd_soc_card |
| 93 | */ |
| 94 | cinfo->snd_card.name = cinfo->card; |
| 95 | cinfo->snd_card.owner = THIS_MODULE; |
| 96 | cinfo->snd_card.dai_link = &cinfo->snd_link; |
| 97 | cinfo->snd_card.num_links = 1; |
| 98 | cinfo->snd_card.dev = &pdev->dev; |
| 99 | |
| 100 | return snd_soc_register_card(&cinfo->snd_card); |
| 101 | } |
| 102 | |
| 103 | static int asoc_simple_card_remove(struct platform_device *pdev) |
| 104 | { |
| 105 | struct asoc_simple_card_info *cinfo = pdev->dev.platform_data; |
| 106 | |
| 107 | return snd_soc_unregister_card(&cinfo->snd_card); |
| 108 | } |
| 109 | |
| 110 | static struct platform_driver asoc_simple_card = { |
| 111 | .driver = { |
| 112 | .name = "asoc-simple-card", |
Fabio Estevam | c445be3 | 2013-08-23 14:35:17 -0300 | [diff] [blame] | 113 | .owner = THIS_MODULE, |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 114 | }, |
| 115 | .probe = asoc_simple_card_probe, |
| 116 | .remove = asoc_simple_card_remove, |
| 117 | }; |
| 118 | |
| 119 | module_platform_driver(asoc_simple_card); |
| 120 | |
Fabio Estevam | c445be3 | 2013-08-23 14:35:17 -0300 | [diff] [blame] | 121 | MODULE_ALIAS("platform:asoc-simple-card"); |
Kuninori Morimoto | f239088 | 2012-04-08 21:17:50 -0700 | [diff] [blame] | 122 | MODULE_LICENSE("GPL"); |
| 123 | MODULE_DESCRIPTION("ASoC Simple Sound Card"); |
| 124 | MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>"); |