Alexander Sverdlin | 86c3304 | 2011-01-23 04:01:15 +0300 | [diff] [blame] | 1 | /* |
| 2 | * SoC audio for EDB93xx |
| 3 | * |
| 4 | * Copyright (c) 2010 Alexander Sverdlin <subaparts@yandex.ru> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version 2 |
| 9 | * of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * This driver support CS4271 codec being master or slave, working |
| 17 | * in control port mode, connected either via SPI or I2C. |
| 18 | * The data format accepted is I2S or left-justified. |
| 19 | * DAPM support not implemented. |
| 20 | */ |
| 21 | |
| 22 | #include <linux/platform_device.h> |
| 23 | #include <linux/gpio.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 24 | #include <linux/module.h> |
Alexander Sverdlin | 86c3304 | 2011-01-23 04:01:15 +0300 | [diff] [blame] | 25 | #include <sound/core.h> |
| 26 | #include <sound/pcm.h> |
| 27 | #include <sound/soc.h> |
| 28 | #include <asm/mach-types.h> |
| 29 | #include <mach/hardware.h> |
Alexander Sverdlin | 86c3304 | 2011-01-23 04:01:15 +0300 | [diff] [blame] | 30 | |
Alexander Sverdlin | 86c3304 | 2011-01-23 04:01:15 +0300 | [diff] [blame] | 31 | static int edb93xx_hw_params(struct snd_pcm_substream *substream, |
| 32 | struct snd_pcm_hw_params *params) |
| 33 | { |
| 34 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 35 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 36 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
| 37 | int err; |
Alexander Sverdlin | 6d33cd7 | 2011-03-07 20:29:53 +0300 | [diff] [blame] | 38 | unsigned int mclk_rate; |
Alexander Sverdlin | 86c3304 | 2011-01-23 04:01:15 +0300 | [diff] [blame] | 39 | unsigned int rate = params_rate(params); |
Alexander Sverdlin | 6d33cd7 | 2011-03-07 20:29:53 +0300 | [diff] [blame] | 40 | |
Alexander Sverdlin | 86c3304 | 2011-01-23 04:01:15 +0300 | [diff] [blame] | 41 | /* |
Alexander Sverdlin | 6d33cd7 | 2011-03-07 20:29:53 +0300 | [diff] [blame] | 42 | * According to CS4271 datasheet we use MCLK/LRCK=256 for |
| 43 | * rates below 50kHz and 128 for higher sample rates |
Alexander Sverdlin | 86c3304 | 2011-01-23 04:01:15 +0300 | [diff] [blame] | 44 | */ |
Alexander Sverdlin | 6d33cd7 | 2011-03-07 20:29:53 +0300 | [diff] [blame] | 45 | if (rate < 50000) |
| 46 | mclk_rate = rate * 64 * 4; |
| 47 | else |
| 48 | mclk_rate = rate * 64 * 2; |
Alexander Sverdlin | 86c3304 | 2011-01-23 04:01:15 +0300 | [diff] [blame] | 49 | |
Alexander Sverdlin | 86c3304 | 2011-01-23 04:01:15 +0300 | [diff] [blame] | 50 | err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk_rate, |
| 51 | SND_SOC_CLOCK_IN); |
| 52 | if (err) |
| 53 | return err; |
| 54 | |
| 55 | return snd_soc_dai_set_sysclk(cpu_dai, 0, mclk_rate, |
| 56 | SND_SOC_CLOCK_OUT); |
| 57 | } |
| 58 | |
| 59 | static struct snd_soc_ops edb93xx_ops = { |
| 60 | .hw_params = edb93xx_hw_params, |
| 61 | }; |
| 62 | |
| 63 | static struct snd_soc_dai_link edb93xx_dai = { |
| 64 | .name = "CS4271", |
| 65 | .stream_name = "CS4271 HiFi", |
| 66 | .platform_name = "ep93xx-pcm-audio", |
| 67 | .cpu_dai_name = "ep93xx-i2s", |
| 68 | .codec_name = "spi0.0", |
| 69 | .codec_dai_name = "cs4271-hifi", |
Axel Lin | f521812 | 2011-12-17 15:36:52 +0800 | [diff] [blame] | 70 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_IF | |
| 71 | SND_SOC_DAIFMT_CBS_CFS, |
Alexander Sverdlin | 86c3304 | 2011-01-23 04:01:15 +0300 | [diff] [blame] | 72 | .ops = &edb93xx_ops, |
| 73 | }; |
| 74 | |
| 75 | static struct snd_soc_card snd_soc_edb93xx = { |
| 76 | .name = "EDB93XX", |
Axel Lin | a76a702 | 2011-12-22 21:21:37 +0800 | [diff] [blame] | 77 | .owner = THIS_MODULE, |
Alexander Sverdlin | 86c3304 | 2011-01-23 04:01:15 +0300 | [diff] [blame] | 78 | .dai_link = &edb93xx_dai, |
| 79 | .num_links = 1, |
| 80 | }; |
| 81 | |
Bill Pemberton | 145e287 | 2012-12-07 09:26:23 -0500 | [diff] [blame] | 82 | static int edb93xx_probe(struct platform_device *pdev) |
Alexander Sverdlin | 86c3304 | 2011-01-23 04:01:15 +0300 | [diff] [blame] | 83 | { |
Mika Westerberg | 8a386ca | 2011-09-11 12:28:51 +0300 | [diff] [blame] | 84 | struct snd_soc_card *card = &snd_soc_edb93xx; |
Alexander Sverdlin | 86c3304 | 2011-01-23 04:01:15 +0300 | [diff] [blame] | 85 | int ret; |
| 86 | |
Ryan Mallon | 44fb864 | 2012-01-11 14:14:31 +1100 | [diff] [blame] | 87 | ret = ep93xx_i2s_acquire(); |
Alexander Sverdlin | 86c3304 | 2011-01-23 04:01:15 +0300 | [diff] [blame] | 88 | if (ret) |
| 89 | return ret; |
| 90 | |
Mika Westerberg | 8a386ca | 2011-09-11 12:28:51 +0300 | [diff] [blame] | 91 | card->dev = &pdev->dev; |
| 92 | |
| 93 | ret = snd_soc_register_card(card); |
| 94 | if (ret) { |
| 95 | dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", |
| 96 | ret); |
| 97 | ep93xx_i2s_release(); |
Alexander Sverdlin | 86c3304 | 2011-01-23 04:01:15 +0300 | [diff] [blame] | 98 | } |
| 99 | |
Mika Westerberg | 8a386ca | 2011-09-11 12:28:51 +0300 | [diff] [blame] | 100 | return ret; |
| 101 | } |
| 102 | |
Bill Pemberton | 145e287 | 2012-12-07 09:26:23 -0500 | [diff] [blame] | 103 | static int edb93xx_remove(struct platform_device *pdev) |
Mika Westerberg | 8a386ca | 2011-09-11 12:28:51 +0300 | [diff] [blame] | 104 | { |
| 105 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
| 106 | |
| 107 | snd_soc_unregister_card(card); |
| 108 | ep93xx_i2s_release(); |
Alexander Sverdlin | 86c3304 | 2011-01-23 04:01:15 +0300 | [diff] [blame] | 109 | |
| 110 | return 0; |
Mika Westerberg | 8a386ca | 2011-09-11 12:28:51 +0300 | [diff] [blame] | 111 | } |
Alexander Sverdlin | 86c3304 | 2011-01-23 04:01:15 +0300 | [diff] [blame] | 112 | |
Mika Westerberg | 8a386ca | 2011-09-11 12:28:51 +0300 | [diff] [blame] | 113 | static struct platform_driver edb93xx_driver = { |
| 114 | .driver = { |
| 115 | .name = "edb93xx-audio", |
| 116 | .owner = THIS_MODULE, |
| 117 | }, |
| 118 | .probe = edb93xx_probe, |
Bill Pemberton | 145e287 | 2012-12-07 09:26:23 -0500 | [diff] [blame] | 119 | .remove = edb93xx_remove, |
Mika Westerberg | 8a386ca | 2011-09-11 12:28:51 +0300 | [diff] [blame] | 120 | }; |
| 121 | |
Axel Lin | ee18f63 | 2011-11-24 12:07:55 +0800 | [diff] [blame] | 122 | module_platform_driver(edb93xx_driver); |
Alexander Sverdlin | 86c3304 | 2011-01-23 04:01:15 +0300 | [diff] [blame] | 123 | |
| 124 | MODULE_AUTHOR("Alexander Sverdlin <subaparts@yandex.ru>"); |
| 125 | MODULE_DESCRIPTION("ALSA SoC EDB93xx"); |
| 126 | MODULE_LICENSE("GPL"); |
Mika Westerberg | 8a386ca | 2011-09-11 12:28:51 +0300 | [diff] [blame] | 127 | MODULE_ALIAS("platform:edb93xx-audio"); |