iwl3945: do not print RFKILL message
[linux/fpc-iii.git] / sound / soc / codecs / pcm1792a.c
blob7146653a8e165c942f7107c5ff305dea785578d9
1 /*
2 * PCM1792A ASoC codec driver
4 * Copyright (c) Amarula Solutions B.V. 2013
6 * Michael Trimarchi <michael@amarulasolutions.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 #include <linux/module.h>
20 #include <linux/slab.h>
21 #include <linux/kernel.h>
22 #include <linux/device.h>
23 #include <linux/spi/spi.h>
25 #include <sound/core.h>
26 #include <sound/pcm.h>
27 #include <sound/pcm_params.h>
28 #include <sound/initval.h>
29 #include <sound/soc.h>
30 #include <sound/tlv.h>
31 #include <linux/of.h>
32 #include <linux/of_device.h>
34 #include "pcm1792a.h"
36 #define PCM1792A_DAC_VOL_LEFT 0x10
37 #define PCM1792A_DAC_VOL_RIGHT 0x11
38 #define PCM1792A_FMT_CONTROL 0x12
39 #define PCM1792A_SOFT_MUTE PCM1792A_FMT_CONTROL
41 #define PCM1792A_FMT_MASK 0x70
42 #define PCM1792A_FMT_SHIFT 4
43 #define PCM1792A_MUTE_MASK 0x01
44 #define PCM1792A_MUTE_SHIFT 0
45 #define PCM1792A_ATLD_ENABLE (1 << 7)
47 static const struct reg_default pcm1792a_reg_defaults[] = {
48 { 0x10, 0xff },
49 { 0x11, 0xff },
50 { 0x12, 0x50 },
51 { 0x13, 0x00 },
52 { 0x14, 0x00 },
53 { 0x15, 0x01 },
54 { 0x16, 0x00 },
55 { 0x17, 0x00 },
58 static bool pcm1792a_accessible_reg(struct device *dev, unsigned int reg)
60 return reg >= 0x10 && reg <= 0x17;
63 static bool pcm1792a_writeable_reg(struct device *dev, unsigned register reg)
65 bool accessible;
67 accessible = pcm1792a_accessible_reg(dev, reg);
69 return accessible && reg != 0x16 && reg != 0x17;
72 struct pcm1792a_private {
73 struct regmap *regmap;
74 unsigned int format;
75 unsigned int rate;
78 static int pcm1792a_set_dai_fmt(struct snd_soc_dai *codec_dai,
79 unsigned int format)
81 struct snd_soc_codec *codec = codec_dai->codec;
82 struct pcm1792a_private *priv = snd_soc_codec_get_drvdata(codec);
84 priv->format = format;
86 return 0;
89 static int pcm1792a_digital_mute(struct snd_soc_dai *dai, int mute)
91 struct snd_soc_codec *codec = dai->codec;
92 struct pcm1792a_private *priv = snd_soc_codec_get_drvdata(codec);
93 int ret;
95 ret = regmap_update_bits(priv->regmap, PCM1792A_SOFT_MUTE,
96 PCM1792A_MUTE_MASK, !!mute);
97 if (ret < 0)
98 return ret;
100 return 0;
103 static int pcm1792a_hw_params(struct snd_pcm_substream *substream,
104 struct snd_pcm_hw_params *params,
105 struct snd_soc_dai *dai)
107 struct snd_soc_codec *codec = dai->codec;
108 struct pcm1792a_private *priv = snd_soc_codec_get_drvdata(codec);
109 int val = 0, ret;
110 int pcm_format = params_format(params);
112 priv->rate = params_rate(params);
114 switch (priv->format & SND_SOC_DAIFMT_FORMAT_MASK) {
115 case SND_SOC_DAIFMT_RIGHT_J:
116 if (pcm_format == SNDRV_PCM_FORMAT_S24_LE ||
117 pcm_format == SNDRV_PCM_FORMAT_S32_LE)
118 val = 0x02;
119 else if (pcm_format == SNDRV_PCM_FORMAT_S16_LE)
120 val = 0x00;
121 break;
122 case SND_SOC_DAIFMT_I2S:
123 if (pcm_format == SNDRV_PCM_FORMAT_S24_LE ||
124 pcm_format == SNDRV_PCM_FORMAT_S32_LE)
125 val = 0x05;
126 else if (pcm_format == SNDRV_PCM_FORMAT_S16_LE)
127 val = 0x04;
128 break;
129 default:
130 dev_err(codec->dev, "Invalid DAI format\n");
131 return -EINVAL;
134 val = val << PCM1792A_FMT_SHIFT | PCM1792A_ATLD_ENABLE;
136 ret = regmap_update_bits(priv->regmap, PCM1792A_FMT_CONTROL,
137 PCM1792A_FMT_MASK | PCM1792A_ATLD_ENABLE, val);
138 if (ret < 0)
139 return ret;
141 return 0;
144 static const struct snd_soc_dai_ops pcm1792a_dai_ops = {
145 .set_fmt = pcm1792a_set_dai_fmt,
146 .hw_params = pcm1792a_hw_params,
147 .digital_mute = pcm1792a_digital_mute,
150 static const DECLARE_TLV_DB_SCALE(pcm1792a_dac_tlv, -12000, 50, 1);
152 static const struct snd_kcontrol_new pcm1792a_controls[] = {
153 SOC_DOUBLE_R_RANGE_TLV("DAC Playback Volume", PCM1792A_DAC_VOL_LEFT,
154 PCM1792A_DAC_VOL_RIGHT, 0, 0xf, 0xff, 0,
155 pcm1792a_dac_tlv),
158 static const struct snd_soc_dapm_widget pcm1792a_dapm_widgets[] = {
159 SND_SOC_DAPM_OUTPUT("IOUTL+"),
160 SND_SOC_DAPM_OUTPUT("IOUTL-"),
161 SND_SOC_DAPM_OUTPUT("IOUTR+"),
162 SND_SOC_DAPM_OUTPUT("IOUTR-"),
165 static const struct snd_soc_dapm_route pcm1792a_dapm_routes[] = {
166 { "IOUTL+", NULL, "Playback" },
167 { "IOUTL-", NULL, "Playback" },
168 { "IOUTR+", NULL, "Playback" },
169 { "IOUTR-", NULL, "Playback" },
172 static struct snd_soc_dai_driver pcm1792a_dai = {
173 .name = "pcm1792a-hifi",
174 .playback = {
175 .stream_name = "Playback",
176 .channels_min = 2,
177 .channels_max = 2,
178 .rates = PCM1792A_RATES,
179 .formats = PCM1792A_FORMATS, },
180 .ops = &pcm1792a_dai_ops,
183 static const struct of_device_id pcm1792a_of_match[] = {
184 { .compatible = "ti,pcm1792a", },
187 MODULE_DEVICE_TABLE(of, pcm1792a_of_match);
189 static const struct regmap_config pcm1792a_regmap = {
190 .reg_bits = 8,
191 .val_bits = 8,
192 .max_register = 23,
193 .reg_defaults = pcm1792a_reg_defaults,
194 .num_reg_defaults = ARRAY_SIZE(pcm1792a_reg_defaults),
195 .writeable_reg = pcm1792a_writeable_reg,
196 .readable_reg = pcm1792a_accessible_reg,
199 static struct snd_soc_codec_driver soc_codec_dev_pcm1792a = {
200 .controls = pcm1792a_controls,
201 .num_controls = ARRAY_SIZE(pcm1792a_controls),
202 .dapm_widgets = pcm1792a_dapm_widgets,
203 .num_dapm_widgets = ARRAY_SIZE(pcm1792a_dapm_widgets),
204 .dapm_routes = pcm1792a_dapm_routes,
205 .num_dapm_routes = ARRAY_SIZE(pcm1792a_dapm_routes),
208 static int pcm1792a_spi_probe(struct spi_device *spi)
210 struct pcm1792a_private *pcm1792a;
211 int ret;
213 pcm1792a = devm_kzalloc(&spi->dev, sizeof(struct pcm1792a_private),
214 GFP_KERNEL);
215 if (!pcm1792a)
216 return -ENOMEM;
218 spi_set_drvdata(spi, pcm1792a);
220 pcm1792a->regmap = devm_regmap_init_spi(spi, &pcm1792a_regmap);
221 if (IS_ERR(pcm1792a->regmap)) {
222 ret = PTR_ERR(pcm1792a->regmap);
223 dev_err(&spi->dev, "Failed to register regmap: %d\n", ret);
224 return ret;
227 return snd_soc_register_codec(&spi->dev,
228 &soc_codec_dev_pcm1792a, &pcm1792a_dai, 1);
231 static int pcm1792a_spi_remove(struct spi_device *spi)
233 snd_soc_unregister_codec(&spi->dev);
234 return 0;
237 static const struct spi_device_id pcm1792a_spi_ids[] = {
238 { "pcm1792a", 0 },
239 { },
241 MODULE_DEVICE_TABLE(spi, pcm1792a_spi_ids);
243 static struct spi_driver pcm1792a_codec_driver = {
244 .driver = {
245 .name = "pcm1792a",
246 .owner = THIS_MODULE,
247 .of_match_table = of_match_ptr(pcm1792a_of_match),
249 .id_table = pcm1792a_spi_ids,
250 .probe = pcm1792a_spi_probe,
251 .remove = pcm1792a_spi_remove,
254 module_spi_driver(pcm1792a_codec_driver);
256 MODULE_DESCRIPTION("ASoC PCM1792A driver");
257 MODULE_AUTHOR("Michael Trimarchi <michael@amarulasolutions.com>");
258 MODULE_LICENSE("GPL");