Thomas Gleixner | 2b27bdc | 2019-05-29 16:57:50 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 2 | /* |
| 3 | * osk5912.c -- SoC audio for OSK 5912 |
| 4 | * |
| 5 | * Copyright (C) 2008 Mistral Solutions |
| 6 | * |
| 7 | * Contact: Arun KS <arunks@mistralsolutions.com> |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/clk.h> |
| 11 | #include <linux/platform_device.h> |
| 12 | #include <sound/core.h> |
| 13 | #include <sound/pcm.h> |
| 14 | #include <sound/soc.h> |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 15 | |
| 16 | #include <asm/mach-types.h> |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 17 | #include <linux/gpio.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 18 | #include <linux/module.h> |
Arnd Bergmann | 2203747 | 2012-08-24 15:21:06 +0200 | [diff] [blame] | 19 | #include <linux/platform_data/asoc-ti-mcbsp.h> |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 20 | |
| 21 | #include "omap-mcbsp.h" |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 22 | #include "../codecs/tlv320aic23.h" |
| 23 | |
| 24 | #define CODEC_CLOCK 12000000 |
| 25 | |
| 26 | static struct clk *tlv320aic23_mclk; |
| 27 | |
| 28 | static int osk_startup(struct snd_pcm_substream *substream) |
| 29 | { |
| 30 | return clk_enable(tlv320aic23_mclk); |
| 31 | } |
| 32 | |
| 33 | static void osk_shutdown(struct snd_pcm_substream *substream) |
| 34 | { |
| 35 | clk_disable(tlv320aic23_mclk); |
| 36 | } |
| 37 | |
| 38 | static int osk_hw_params(struct snd_pcm_substream *substream, |
| 39 | struct snd_pcm_hw_params *params) |
| 40 | { |
Kuninori Morimoto | 02cde14 | 2020-07-20 10:17:48 +0900 | [diff] [blame] | 41 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
Kuninori Morimoto | 2842b87 | 2020-03-23 14:21:14 +0900 | [diff] [blame] | 42 | struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 43 | int err; |
| 44 | |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 45 | /* Set the codec system clock for DAC and ADC */ |
| 46 | err = |
| 47 | snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_CLOCK, SND_SOC_CLOCK_IN); |
| 48 | |
| 49 | if (err < 0) { |
| 50 | printk(KERN_ERR "can't set codec system clock\n"); |
| 51 | return err; |
| 52 | } |
| 53 | |
| 54 | return err; |
| 55 | } |
| 56 | |
Bhumika Goyal | 2261cf1 | 2017-03-18 19:34:11 +0530 | [diff] [blame] | 57 | static const struct snd_soc_ops osk_ops = { |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 58 | .startup = osk_startup, |
| 59 | .hw_params = osk_hw_params, |
| 60 | .shutdown = osk_shutdown, |
| 61 | }; |
| 62 | |
| 63 | static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = { |
| 64 | SND_SOC_DAPM_HP("Headphone Jack", NULL), |
| 65 | SND_SOC_DAPM_LINE("Line In", NULL), |
| 66 | SND_SOC_DAPM_MIC("Mic Jack", NULL), |
| 67 | }; |
| 68 | |
| 69 | static const struct snd_soc_dapm_route audio_map[] = { |
| 70 | {"Headphone Jack", NULL, "LHPOUT"}, |
| 71 | {"Headphone Jack", NULL, "RHPOUT"}, |
| 72 | |
| 73 | {"LLINEIN", NULL, "Line In"}, |
| 74 | {"RLINEIN", NULL, "Line In"}, |
| 75 | |
| 76 | {"MICIN", NULL, "Mic Jack"}, |
| 77 | }; |
| 78 | |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 79 | /* Digital audio interface glue - connects codec <--> CPU */ |
Kuninori Morimoto | 5cffc23 | 2019-06-06 13:12:43 +0900 | [diff] [blame] | 80 | SND_SOC_DAILINK_DEFS(aic23, |
| 81 | DAILINK_COMP_ARRAY(COMP_CPU("omap-mcbsp.1")), |
| 82 | DAILINK_COMP_ARRAY(COMP_CODEC("tlv320aic23-codec", |
| 83 | "tlv320aic23-hifi")), |
| 84 | DAILINK_COMP_ARRAY(COMP_PLATFORM("omap-mcbsp.1"))); |
| 85 | |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 86 | static struct snd_soc_dai_link osk_dai = { |
| 87 | .name = "TLV320AIC23", |
| 88 | .stream_name = "AIC23", |
Jarkko Nikula | cf9feff | 2011-09-30 16:07:45 +0300 | [diff] [blame] | 89 | .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_NB_NF | |
| 90 | SND_SOC_DAIFMT_CBM_CFM, |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 91 | .ops = &osk_ops, |
Kuninori Morimoto | 5cffc23 | 2019-06-06 13:12:43 +0900 | [diff] [blame] | 92 | SND_SOC_DAILINK_REG(aic23), |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | /* Audio machine driver */ |
Mark Brown | 8750654 | 2008-11-18 20:50:34 +0000 | [diff] [blame] | 96 | static struct snd_soc_card snd_soc_card_osk = { |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 97 | .name = "OSK5912", |
Axel Lin | b425b88 | 2011-12-22 11:08:59 +0800 | [diff] [blame] | 98 | .owner = THIS_MODULE, |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 99 | .dai_link = &osk_dai, |
| 100 | .num_links = 1, |
Peter Ujfalusi | 93b4d79 | 2011-10-10 15:34:11 +0300 | [diff] [blame] | 101 | |
| 102 | .dapm_widgets = tlv320aic23_dapm_widgets, |
| 103 | .num_dapm_widgets = ARRAY_SIZE(tlv320aic23_dapm_widgets), |
| 104 | .dapm_routes = audio_map, |
| 105 | .num_dapm_routes = ARRAY_SIZE(audio_map), |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 106 | }; |
| 107 | |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 108 | static struct platform_device *osk_snd_device; |
| 109 | |
| 110 | static int __init osk_soc_init(void) |
| 111 | { |
| 112 | int err; |
| 113 | u32 curRate; |
| 114 | struct device *dev; |
| 115 | |
| 116 | if (!(machine_is_omap_osk())) |
| 117 | return -ENODEV; |
| 118 | |
| 119 | osk_snd_device = platform_device_alloc("soc-audio", -1); |
| 120 | if (!osk_snd_device) |
| 121 | return -ENOMEM; |
| 122 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 123 | platform_set_drvdata(osk_snd_device, &snd_soc_card_osk); |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 124 | err = platform_device_add(osk_snd_device); |
| 125 | if (err) |
| 126 | goto err1; |
| 127 | |
| 128 | dev = &osk_snd_device->dev; |
| 129 | |
| 130 | tlv320aic23_mclk = clk_get(dev, "mclk"); |
| 131 | if (IS_ERR(tlv320aic23_mclk)) { |
| 132 | printk(KERN_ERR "Could not get mclk clock\n"); |
Axel Lin | 2543618 | 2010-11-24 22:24:01 +0800 | [diff] [blame] | 133 | err = PTR_ERR(tlv320aic23_mclk); |
| 134 | goto err2; |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 135 | } |
| 136 | |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 137 | /* |
| 138 | * Configure 12 MHz output on MCLK. |
| 139 | */ |
| 140 | curRate = (uint) clk_get_rate(tlv320aic23_mclk); |
| 141 | if (curRate != CODEC_CLOCK) { |
| 142 | if (clk_set_rate(tlv320aic23_mclk, CODEC_CLOCK)) { |
| 143 | printk(KERN_ERR "Cannot set MCLK for AIC23 CODEC\n"); |
| 144 | err = -ECANCELED; |
Axel Lin | 2543618 | 2010-11-24 22:24:01 +0800 | [diff] [blame] | 145 | goto err3; |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | |
David Brownell | 5706d50 | 2009-03-11 02:37:25 -0800 | [diff] [blame] | 149 | printk(KERN_INFO "MCLK = %d [%d]\n", |
| 150 | (uint) clk_get_rate(tlv320aic23_mclk), CODEC_CLOCK); |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 151 | |
| 152 | return 0; |
Axel Lin | 2543618 | 2010-11-24 22:24:01 +0800 | [diff] [blame] | 153 | |
| 154 | err3: |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 155 | clk_put(tlv320aic23_mclk); |
Axel Lin | 2543618 | 2010-11-24 22:24:01 +0800 | [diff] [blame] | 156 | err2: |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 157 | platform_device_del(osk_snd_device); |
Axel Lin | 2543618 | 2010-11-24 22:24:01 +0800 | [diff] [blame] | 158 | err1: |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 159 | platform_device_put(osk_snd_device); |
| 160 | |
| 161 | return err; |
| 162 | |
| 163 | } |
| 164 | |
| 165 | static void __exit osk_soc_exit(void) |
| 166 | { |
Axel Lin | 2543618 | 2010-11-24 22:24:01 +0800 | [diff] [blame] | 167 | clk_put(tlv320aic23_mclk); |
Arun KS | 17f9ecf | 2008-10-02 15:02:45 +0530 | [diff] [blame] | 168 | platform_device_unregister(osk_snd_device); |
| 169 | } |
| 170 | |
| 171 | module_init(osk_soc_init); |
| 172 | module_exit(osk_soc_exit); |
| 173 | |
| 174 | MODULE_AUTHOR("Arun KS <arunks@mistralsolutions.com>"); |
| 175 | MODULE_DESCRIPTION("ALSA SoC OSK 5912"); |
| 176 | MODULE_LICENSE("GPL"); |