2 * CS4270 ALSA SoC (ASoC) codec driver
4 * Author: Timur Tabi <timur@freescale.com>
6 * Copyright 2007-2009 Freescale Semiconductor, Inc. This file is licensed
7 * under the terms of the GNU General Public License version 2. This
8 * program is licensed "as is" without any warranty of any kind, whether
11 * This is an ASoC device driver for the Cirrus Logic CS4270 codec.
13 * Current features/limitations:
15 * 1) Software mode is supported. Stand-alone mode is not supported.
16 * 2) Only I2C is supported, not SPI
17 * 3) Only Master mode is supported, not Slave.
18 * 4) The machine driver's 'startup' function must call
19 * cs4270_set_dai_sysclk() with the value of MCLK.
20 * 5) Only I2S and left-justified modes are supported
21 * 6) Power management is not supported
22 * 7) The only supported control is volume and hardware mute (if enabled)
25 #include <linux/module.h>
26 #include <linux/platform_device.h>
27 #include <sound/core.h>
28 #include <sound/soc.h>
29 #include <sound/initval.h>
30 #include <linux/i2c.h>
35 * The codec isn't really big-endian or little-endian, since the I2S
36 * interface requires data to be sent serially with the MSbit first.
37 * However, to support BE and LE I2S devices, we specify both here. That
38 * way, ALSA will always match the bit patterns.
40 #define CS4270_FORMATS (SNDRV_PCM_FMTBIT_S8 | \
41 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | \
42 SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE | \
43 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE | \
44 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE | \
45 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE)
47 /* CS4270 registers addresses */
48 #define CS4270_CHIPID 0x01 /* Chip ID */
49 #define CS4270_PWRCTL 0x02 /* Power Control */
50 #define CS4270_MODE 0x03 /* Mode Control */
51 #define CS4270_FORMAT 0x04 /* Serial Format, ADC/DAC Control */
52 #define CS4270_TRANS 0x05 /* Transition Control */
53 #define CS4270_MUTE 0x06 /* Mute Control */
54 #define CS4270_VOLA 0x07 /* DAC Channel A Volume Control */
55 #define CS4270_VOLB 0x08 /* DAC Channel B Volume Control */
57 #define CS4270_FIRSTREG 0x01
58 #define CS4270_LASTREG 0x08
59 #define CS4270_NUMREGS (CS4270_LASTREG - CS4270_FIRSTREG + 1)
61 /* Bit masks for the CS4270 registers */
62 #define CS4270_CHIPID_ID 0xF0
63 #define CS4270_CHIPID_REV 0x0F
64 #define CS4270_PWRCTL_FREEZE 0x80
65 #define CS4270_PWRCTL_PDN_ADC 0x20
66 #define CS4270_PWRCTL_PDN_DAC 0x02
67 #define CS4270_PWRCTL_PDN 0x01
68 #define CS4270_MODE_SPEED_MASK 0x30
69 #define CS4270_MODE_1X 0x00
70 #define CS4270_MODE_2X 0x10
71 #define CS4270_MODE_4X 0x20
72 #define CS4270_MODE_SLAVE 0x30
73 #define CS4270_MODE_DIV_MASK 0x0E
74 #define CS4270_MODE_DIV1 0x00
75 #define CS4270_MODE_DIV15 0x02
76 #define CS4270_MODE_DIV2 0x04
77 #define CS4270_MODE_DIV3 0x06
78 #define CS4270_MODE_DIV4 0x08
79 #define CS4270_MODE_POPGUARD 0x01
80 #define CS4270_FORMAT_FREEZE_A 0x80
81 #define CS4270_FORMAT_FREEZE_B 0x40
82 #define CS4270_FORMAT_LOOPBACK 0x20
83 #define CS4270_FORMAT_DAC_MASK 0x18
84 #define CS4270_FORMAT_DAC_LJ 0x00
85 #define CS4270_FORMAT_DAC_I2S 0x08
86 #define CS4270_FORMAT_DAC_RJ16 0x18
87 #define CS4270_FORMAT_DAC_RJ24 0x10
88 #define CS4270_FORMAT_ADC_MASK 0x01
89 #define CS4270_FORMAT_ADC_LJ 0x00
90 #define CS4270_FORMAT_ADC_I2S 0x01
91 #define CS4270_TRANS_ONE_VOL 0x80
92 #define CS4270_TRANS_SOFT 0x40
93 #define CS4270_TRANS_ZERO 0x20
94 #define CS4270_TRANS_INV_ADC_A 0x08
95 #define CS4270_TRANS_INV_ADC_B 0x10
96 #define CS4270_TRANS_INV_DAC_A 0x02
97 #define CS4270_TRANS_INV_DAC_B 0x04
98 #define CS4270_TRANS_DEEMPH 0x01
99 #define CS4270_MUTE_AUTO 0x20
100 #define CS4270_MUTE_ADC_A 0x08
101 #define CS4270_MUTE_ADC_B 0x10
102 #define CS4270_MUTE_POLARITY 0x04
103 #define CS4270_MUTE_DAC_A 0x01
104 #define CS4270_MUTE_DAC_B 0x02
106 /* Private data for the CS4270 */
107 struct cs4270_private {
108 struct snd_soc_codec codec;
109 u8 reg_cache[CS4270_NUMREGS];
110 unsigned int mclk; /* Input frequency of the MCLK pin */
111 unsigned int mode; /* The mode (I2S or left-justified) */
112 unsigned int slave_mode;
116 * struct cs4270_mode_ratios - clock ratio tables
117 * @ratio: the ratio of MCLK to the sample rate
118 * @speed_mode: the Speed Mode bits to set in the Mode Control register for
120 * @mclk: the Ratio Select bits to set in the Mode Control register for this
123 * The data for this chart is taken from Table 5 of the CS4270 reference
126 * This table is used to determine how to program the Mode Control register.
127 * It is also used by cs4270_set_dai_sysclk() to tell ALSA which sampling
128 * rates the CS4270 currently supports.
130 * @speed_mode is the corresponding bit pattern to be written to the
131 * MODE bits of the Mode Control Register
133 * @mclk is the corresponding bit pattern to be wirten to the MCLK bits of
134 * the Mode Control Register.
136 * In situations where a single ratio is represented by multiple speed
137 * modes, we favor the slowest speed. E.g, for a ratio of 128, we pick
138 * double-speed instead of quad-speed. However, the CS4270 errata states
139 * that divide-By-1.5 can cause failures, so we avoid that mode where
142 * Errata: There is an errata for the CS4270 where divide-by-1.5 does not
143 * work if Vd is 3.3V. If this effects you, select the
144 * CONFIG_SND_SOC_CS4270_VD33_ERRATA Kconfig option, and the driver will
145 * never select any sample rates that require divide-by-1.5.
147 struct cs4270_mode_ratios {
153 static struct cs4270_mode_ratios cs4270_mode_ratios[] = {
154 {64, CS4270_MODE_4X, CS4270_MODE_DIV1},
155 #ifndef CONFIG_SND_SOC_CS4270_VD33_ERRATA
156 {96, CS4270_MODE_4X, CS4270_MODE_DIV15},
158 {128, CS4270_MODE_2X, CS4270_MODE_DIV1},
159 {192, CS4270_MODE_4X, CS4270_MODE_DIV3},
160 {256, CS4270_MODE_1X, CS4270_MODE_DIV1},
161 {384, CS4270_MODE_2X, CS4270_MODE_DIV3},
162 {512, CS4270_MODE_1X, CS4270_MODE_DIV2},
163 {768, CS4270_MODE_1X, CS4270_MODE_DIV3},
164 {1024, CS4270_MODE_1X, CS4270_MODE_DIV4}
167 /* The number of MCLK/LRCK ratios supported by the CS4270 */
168 #define NUM_MCLK_RATIOS ARRAY_SIZE(cs4270_mode_ratios)
171 * cs4270_set_dai_sysclk - determine the CS4270 samples rates.
172 * @codec_dai: the codec DAI
173 * @clk_id: the clock ID (ignored)
174 * @freq: the MCLK input frequency
175 * @dir: the clock direction (ignored)
177 * This function is used to tell the codec driver what the input MCLK
180 * The value of MCLK is used to determine which sample rates are supported
181 * by the CS4270. The ratio of MCLK / Fs must be equal to one of nine
182 * supported values - 64, 96, 128, 192, 256, 384, 512, 768, and 1024.
184 * This function calculates the nine ratios and determines which ones match
185 * a standard sample rate. If there's a match, then it is added to the list
186 * of supported sample rates.
188 * This function must be called by the machine driver's 'startup' function,
189 * otherwise the list of supported sample rates will not be available in
192 static int cs4270_set_dai_sysclk(struct snd_soc_dai *codec_dai,
193 int clk_id, unsigned int freq, int dir)
195 struct snd_soc_codec *codec = codec_dai->codec;
196 struct cs4270_private *cs4270 = codec->private_data;
197 unsigned int rates = 0;
198 unsigned int rate_min = -1;
199 unsigned int rate_max = 0;
204 for (i = 0; i < NUM_MCLK_RATIOS; i++) {
205 unsigned int rate = freq / cs4270_mode_ratios[i].ratio;
206 rates |= snd_pcm_rate_to_rate_bit(rate);
212 /* FIXME: soc should support a rate list */
213 rates &= ~SNDRV_PCM_RATE_KNOT;
216 dev_err(codec->dev, "could not find a valid sample rate\n");
220 codec_dai->playback.rates = rates;
221 codec_dai->playback.rate_min = rate_min;
222 codec_dai->playback.rate_max = rate_max;
224 codec_dai->capture.rates = rates;
225 codec_dai->capture.rate_min = rate_min;
226 codec_dai->capture.rate_max = rate_max;
232 * cs4270_set_dai_fmt - configure the codec for the selected audio format
233 * @codec_dai: the codec DAI
234 * @format: a SND_SOC_DAIFMT_x value indicating the data format
236 * This function takes a bitmask of SND_SOC_DAIFMT_x bits and programs the
239 * Currently, this function only supports SND_SOC_DAIFMT_I2S and
240 * SND_SOC_DAIFMT_LEFT_J. The CS4270 codec also supports right-justified
241 * data for playback only, but ASoC currently does not support different
242 * formats for playback vs. record.
244 static int cs4270_set_dai_fmt(struct snd_soc_dai *codec_dai,
247 struct snd_soc_codec *codec = codec_dai->codec;
248 struct cs4270_private *cs4270 = codec->private_data;
252 switch (format & SND_SOC_DAIFMT_FORMAT_MASK) {
253 case SND_SOC_DAIFMT_I2S:
254 case SND_SOC_DAIFMT_LEFT_J:
255 cs4270->mode = format & SND_SOC_DAIFMT_FORMAT_MASK;
258 dev_err(codec->dev, "invalid dai format\n");
262 /* set master/slave audio interface */
263 switch (format & SND_SOC_DAIFMT_MASTER_MASK) {
264 case SND_SOC_DAIFMT_CBS_CFS:
265 cs4270->slave_mode = 1;
267 case SND_SOC_DAIFMT_CBM_CFM:
268 cs4270->slave_mode = 0;
270 case SND_SOC_DAIFMT_CBM_CFS:
271 /* unsupported - cs4270 can eigther be slave or master to
272 * both the bitclk and the lrclk. */
281 * cs4270_fill_cache - pre-fill the CS4270 register cache.
282 * @codec: the codec for this CS4270
284 * This function fills in the CS4270 register cache by reading the register
285 * values from the hardware.
287 * This CS4270 registers are cached to avoid excessive I2C I/O operations.
288 * After the initial read to pre-fill the cache, the CS4270 never updates
289 * the register values, so we won't have a cache coherency problem.
291 * We use the auto-increment feature of the CS4270 to read all registers in
294 static int cs4270_fill_cache(struct snd_soc_codec *codec)
296 u8 *cache = codec->reg_cache;
297 struct i2c_client *i2c_client = codec->control_data;
300 length = i2c_smbus_read_i2c_block_data(i2c_client,
301 CS4270_FIRSTREG | 0x80, CS4270_NUMREGS, cache);
303 if (length != CS4270_NUMREGS) {
304 dev_err(codec->dev, "i2c read failure, addr=0x%x\n",
313 * cs4270_read_reg_cache - read from the CS4270 register cache.
314 * @codec: the codec for this CS4270
315 * @reg: the register to read
317 * This function returns the value for a given register. It reads only from
318 * the register cache, not the hardware itself.
320 * This CS4270 registers are cached to avoid excessive I2C I/O operations.
321 * After the initial read to pre-fill the cache, the CS4270 never updates
322 * the register values, so we won't have a cache coherency problem.
324 static unsigned int cs4270_read_reg_cache(struct snd_soc_codec *codec,
327 u8 *cache = codec->reg_cache;
329 if ((reg < CS4270_FIRSTREG) || (reg > CS4270_LASTREG))
332 return cache[reg - CS4270_FIRSTREG];
336 * cs4270_i2c_write - write to a CS4270 register via the I2C bus.
337 * @codec: the codec for this CS4270
338 * @reg: the register to write
339 * @value: the value to write to the register
341 * This function writes the given value to the given CS4270 register, and
342 * also updates the register cache.
344 * Note that we don't use the hw_write function pointer of snd_soc_codec.
345 * That's because it's too clunky: the hw_write_t prototype does not match
346 * i2c_smbus_write_byte_data(), and it's just another layer of overhead.
348 static int cs4270_i2c_write(struct snd_soc_codec *codec, unsigned int reg,
351 u8 *cache = codec->reg_cache;
353 if ((reg < CS4270_FIRSTREG) || (reg > CS4270_LASTREG))
356 /* Only perform an I2C operation if the new value is different */
357 if (cache[reg - CS4270_FIRSTREG] != value) {
358 struct i2c_client *client = codec->control_data;
359 if (i2c_smbus_write_byte_data(client, reg, value)) {
360 dev_err(codec->dev, "i2c write failed\n");
364 /* We've written to the hardware, so update the cache */
365 cache[reg - CS4270_FIRSTREG] = value;
372 * cs4270_hw_params - program the CS4270 with the given hardware parameters.
373 * @substream: the audio stream
374 * @params: the hardware parameters to set
375 * @dai: the SOC DAI (ignored)
377 * This function programs the hardware with the values provided.
378 * Specifically, the sample rate and the data format.
380 * The .ops functions are used to provide board-specific data, like input
381 * frequencies, to this driver. This function takes that information,
382 * combines it with the hardware parameters provided, and programs the
383 * hardware accordingly.
385 static int cs4270_hw_params(struct snd_pcm_substream *substream,
386 struct snd_pcm_hw_params *params,
387 struct snd_soc_dai *dai)
389 struct snd_soc_pcm_runtime *rtd = substream->private_data;
390 struct snd_soc_device *socdev = rtd->socdev;
391 struct snd_soc_codec *codec = socdev->card->codec;
392 struct cs4270_private *cs4270 = codec->private_data;
399 /* Figure out which MCLK/LRCK ratio to use */
401 rate = params_rate(params); /* Sampling rate, in Hz */
402 ratio = cs4270->mclk / rate; /* MCLK/LRCK ratio */
404 for (i = 0; i < NUM_MCLK_RATIOS; i++) {
405 if (cs4270_mode_ratios[i].ratio == ratio)
409 if (i == NUM_MCLK_RATIOS) {
410 /* We did not find a matching ratio */
411 dev_err(codec->dev, "could not find matching ratio\n");
415 /* Set the sample rate */
417 reg = snd_soc_read(codec, CS4270_MODE);
418 reg &= ~(CS4270_MODE_SPEED_MASK | CS4270_MODE_DIV_MASK);
419 reg |= cs4270_mode_ratios[i].mclk;
421 if (cs4270->slave_mode)
422 reg |= CS4270_MODE_SLAVE;
424 reg |= cs4270_mode_ratios[i].speed_mode;
426 ret = snd_soc_write(codec, CS4270_MODE, reg);
428 dev_err(codec->dev, "i2c write failed\n");
432 /* Set the DAI format */
434 reg = snd_soc_read(codec, CS4270_FORMAT);
435 reg &= ~(CS4270_FORMAT_DAC_MASK | CS4270_FORMAT_ADC_MASK);
437 switch (cs4270->mode) {
438 case SND_SOC_DAIFMT_I2S:
439 reg |= CS4270_FORMAT_DAC_I2S | CS4270_FORMAT_ADC_I2S;
441 case SND_SOC_DAIFMT_LEFT_J:
442 reg |= CS4270_FORMAT_DAC_LJ | CS4270_FORMAT_ADC_LJ;
445 dev_err(codec->dev, "unknown dai format\n");
449 ret = snd_soc_write(codec, CS4270_FORMAT, reg);
451 dev_err(codec->dev, "i2c write failed\n");
459 * cs4270_mute - enable/disable the CS4270 external mute
461 * @mute: 0 = disable mute, 1 = enable mute
463 * This function toggles the mute bits in the MUTE register. The CS4270's
464 * mute capability is intended for external muting circuitry, so if the
465 * board does not have the MUTEA or MUTEB pins connected to such circuitry,
466 * then this function will do nothing.
468 static int cs4270_mute(struct snd_soc_dai *dai, int mute)
470 struct snd_soc_codec *codec = dai->codec;
473 reg6 = snd_soc_read(codec, CS4270_MUTE);
476 reg6 |= CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B;
478 reg6 &= ~(CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B);
480 return snd_soc_write(codec, CS4270_MUTE, reg6);
483 /* A list of non-DAPM controls that the CS4270 supports */
484 static const struct snd_kcontrol_new cs4270_snd_controls[] = {
485 SOC_DOUBLE_R("Master Playback Volume",
486 CS4270_VOLA, CS4270_VOLB, 0, 0xFF, 1),
487 SOC_SINGLE("Digital Sidetone Switch", CS4270_FORMAT, 5, 1, 0),
488 SOC_SINGLE("Soft Ramp Switch", CS4270_TRANS, 6, 1, 0),
489 SOC_SINGLE("Zero Cross Switch", CS4270_TRANS, 5, 1, 0),
490 SOC_SINGLE("Popguard Switch", CS4270_MODE, 0, 1, 1),
491 SOC_SINGLE("Auto-Mute Switch", CS4270_MUTE, 5, 1, 0),
492 SOC_DOUBLE("Master Capture Switch", CS4270_MUTE, 3, 4, 1, 0)
496 * cs4270_codec - global variable to store codec for the ASoC probe function
498 * If struct i2c_driver had a private_data field, we wouldn't need to use
499 * cs4270_codec. This is the only way to pass the codec structure from
500 * cs4270_i2c_probe() to cs4270_probe(). Unfortunately, there is no good
501 * way to synchronize these two functions. cs4270_i2c_probe() can be called
502 * multiple times before cs4270_probe() is called even once. So for now, we
503 * also only allow cs4270_i2c_probe() to be run once. That means that we do
504 * not support more than one cs4270 device in the system, at least for now.
506 static struct snd_soc_codec *cs4270_codec;
508 struct snd_soc_dai cs4270_dai = {
511 .stream_name = "Playback",
515 .formats = CS4270_FORMATS,
518 .stream_name = "Capture",
522 .formats = CS4270_FORMATS,
525 .hw_params = cs4270_hw_params,
526 .set_sysclk = cs4270_set_dai_sysclk,
527 .set_fmt = cs4270_set_dai_fmt,
528 .digital_mute = cs4270_mute,
531 EXPORT_SYMBOL_GPL(cs4270_dai);
534 * cs4270_probe - ASoC probe function
535 * @pdev: platform device
537 * This function is called when ASoC has all the pieces it needs to
538 * instantiate a sound driver.
540 static int cs4270_probe(struct platform_device *pdev)
542 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
543 struct snd_soc_codec *codec = cs4270_codec;
547 /* Connect the codec to the socdev. snd_soc_new_pcms() needs this. */
548 socdev->card->codec = codec;
551 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
553 dev_err(codec->dev, "failed to create pcms\n");
557 /* Add the non-DAPM controls */
558 for (i = 0; i < ARRAY_SIZE(cs4270_snd_controls); i++) {
559 struct snd_kcontrol *kctrl;
561 kctrl = snd_soc_cnew(&cs4270_snd_controls[i], codec, NULL);
563 dev_err(codec->dev, "error creating control '%s'\n",
564 cs4270_snd_controls[i].name);
566 goto error_free_pcms;
569 ret = snd_ctl_add(codec->card, kctrl);
571 dev_err(codec->dev, "error adding control '%s'\n",
572 cs4270_snd_controls[i].name);
573 goto error_free_pcms;
577 /* And finally, register the socdev */
578 ret = snd_soc_init_card(socdev);
580 dev_err(codec->dev, "failed to register card\n");
581 goto error_free_pcms;
587 snd_soc_free_pcms(socdev);
593 * cs4270_remove - ASoC remove function
594 * @pdev: platform device
596 * This function is the counterpart to cs4270_probe().
598 static int cs4270_remove(struct platform_device *pdev)
600 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
602 snd_soc_free_pcms(socdev);
608 * cs4270_i2c_probe - initialize the I2C interface of the CS4270
609 * @i2c_client: the I2C client object
610 * @id: the I2C device ID (ignored)
612 * This function is called whenever the I2C subsystem finds a device that
613 * matches the device ID given via a prior call to i2c_add_driver().
615 static int cs4270_i2c_probe(struct i2c_client *i2c_client,
616 const struct i2c_device_id *id)
618 struct snd_soc_codec *codec;
619 struct cs4270_private *cs4270;
623 /* For now, we only support one cs4270 device in the system. See the
624 * comment for cs4270_codec.
627 dev_err(&i2c_client->dev, "ignoring CS4270 at addr %X\n",
629 dev_err(&i2c_client->dev, "only one per board allowed\n");
630 /* Should we return something other than ENODEV here? */
634 /* Verify that we have a CS4270 */
636 ret = i2c_smbus_read_byte_data(i2c_client, CS4270_CHIPID);
638 dev_err(&i2c_client->dev, "failed to read i2c at addr %X\n",
642 /* The top four bits of the chip ID should be 1100. */
643 if ((ret & 0xF0) != 0xC0) {
644 dev_err(&i2c_client->dev, "device at addr %X is not a CS4270\n",
649 dev_info(&i2c_client->dev, "found device at i2c address %X\n",
651 dev_info(&i2c_client->dev, "hardware revision %X\n", ret & 0xF);
653 /* Allocate enough space for the snd_soc_codec structure
654 and our private data together. */
655 cs4270 = kzalloc(sizeof(struct cs4270_private), GFP_KERNEL);
657 dev_err(&i2c_client->dev, "could not allocate codec\n");
660 codec = &cs4270->codec;
662 mutex_init(&codec->mutex);
663 INIT_LIST_HEAD(&codec->dapm_widgets);
664 INIT_LIST_HEAD(&codec->dapm_paths);
666 codec->dev = &i2c_client->dev;
667 codec->name = "CS4270";
668 codec->owner = THIS_MODULE;
669 codec->dai = &cs4270_dai;
671 codec->private_data = cs4270;
672 codec->control_data = i2c_client;
673 codec->read = cs4270_read_reg_cache;
674 codec->write = cs4270_i2c_write;
675 codec->reg_cache = cs4270->reg_cache;
676 codec->reg_cache_size = CS4270_NUMREGS;
678 /* The I2C interface is set up, so pre-fill our register cache */
680 ret = cs4270_fill_cache(codec);
682 dev_err(&i2c_client->dev, "failed to fill register cache\n");
683 goto error_free_codec;
686 /* Disable auto-mute. This feature appears to be buggy. In some
687 * situations, auto-mute will not deactivate when it should, so we want
688 * this feature disabled by default. An application (e.g. alsactl) can
689 * re-enabled it by using the controls.
692 reg = cs4270_read_reg_cache(codec, CS4270_MUTE);
693 reg &= ~CS4270_MUTE_AUTO;
694 ret = cs4270_i2c_write(codec, CS4270_MUTE, reg);
696 dev_err(&i2c_client->dev, "i2c write failed\n");
700 /* Disable automatic volume control. The hardware enables, and it
701 * causes volume change commands to be delayed, sometimes until after
702 * playback has started. An application (e.g. alsactl) can
703 * re-enabled it by using the controls.
706 reg = cs4270_read_reg_cache(codec, CS4270_TRANS);
707 reg &= ~(CS4270_TRANS_SOFT | CS4270_TRANS_ZERO);
708 ret = cs4270_i2c_write(codec, CS4270_TRANS, reg);
710 dev_err(&i2c_client->dev, "i2c write failed\n");
714 /* Initialize the DAI. Normally, we'd prefer to have a kmalloc'd DAI
715 * structure for each CS4270 device, but the machine driver needs to
716 * have a pointer to the DAI structure, so for now it must be a global
719 cs4270_dai.dev = &i2c_client->dev;
721 /* Register the DAI. If all the other ASoC driver have already
722 * registered, then this will call our probe function, so
723 * cs4270_codec needs to be ready.
725 cs4270_codec = codec;
726 ret = snd_soc_register_dai(&cs4270_dai);
728 dev_err(&i2c_client->dev, "failed to register DAIe\n");
729 goto error_free_codec;
732 i2c_set_clientdata(i2c_client, cs4270);
739 cs4270_dai.dev = NULL;
745 * cs4270_i2c_remove - remove an I2C device
746 * @i2c_client: the I2C client object
748 * This function is the counterpart to cs4270_i2c_probe().
750 static int cs4270_i2c_remove(struct i2c_client *i2c_client)
752 struct cs4270_private *cs4270 = i2c_get_clientdata(i2c_client);
756 cs4270_dai.dev = NULL;
762 * cs4270_id - I2C device IDs supported by this driver
764 static struct i2c_device_id cs4270_id[] = {
768 MODULE_DEVICE_TABLE(i2c, cs4270_id);
771 * cs4270_i2c_driver - I2C device identification
773 * This structure tells the I2C subsystem how to identify and support a
774 * given I2C device type.
776 static struct i2c_driver cs4270_i2c_driver = {
779 .owner = THIS_MODULE,
781 .id_table = cs4270_id,
782 .probe = cs4270_i2c_probe,
783 .remove = cs4270_i2c_remove,
787 * ASoC codec device structure
789 * Assign this variable to the codec_dev field of the machine driver's
790 * snd_soc_device structure.
792 struct snd_soc_codec_device soc_codec_device_cs4270 = {
793 .probe = cs4270_probe,
794 .remove = cs4270_remove
796 EXPORT_SYMBOL_GPL(soc_codec_device_cs4270);
798 static int __init cs4270_init(void)
800 pr_info("Cirrus Logic CS4270 ALSA SoC Codec Driver\n");
802 return i2c_add_driver(&cs4270_i2c_driver);
804 module_init(cs4270_init);
806 static void __exit cs4270_exit(void)
808 i2c_del_driver(&cs4270_i2c_driver);
810 module_exit(cs4270_exit);
812 MODULE_AUTHOR("Timur Tabi <timur@freescale.com>");
813 MODULE_DESCRIPTION("Cirrus Logic CS4270 ALSA SoC Codec Driver");
814 MODULE_LICENSE("GPL");