2 * CS4270 ALSA SoC (ASoC) codec driver
4 * Author: Timur Tabi <timur@freescale.com>
6 * Copyright 2007 Freescale Semiconductor, Inc. This file is licensed under
7 * the terms of the GNU General Public License version 2. This program
8 * is licensed "as is" without any warranty of any kind, whether express
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 automatically
16 * selected if I2C is disabled or if a CS4270 is not found on the I2C
17 * bus. However, stand-alone mode is only partially implemented because
18 * there is no mechanism yet for this driver and the machine driver to
19 * communicate the values of the M0, M1, MCLK1, and MCLK2 pins.
20 * 2) Only I2C is supported, not SPI
21 * 3) Only Master mode is supported, not Slave.
22 * 4) The machine driver's 'startup' function must call
23 * cs4270_set_dai_sysclk() with the value of MCLK.
24 * 5) Only I2S and left-justified modes are supported
25 * 6) Power management is not supported
26 * 7) The only supported control is volume and hardware mute (if enabled)
29 #include <linux/module.h>
30 #include <linux/platform_device.h>
31 #include <sound/driver.h>
32 #include <sound/core.h>
33 #include <sound/soc.h>
34 #include <sound/initval.h>
35 #include <linux/i2c.h>
39 /* If I2C is defined, then we support software mode. However, if we're
40 not compiled as module but I2C is, then we can't use I2C calls. */
41 #if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE))
45 /* Private data for the CS4270 */
46 struct cs4270_private {
47 unsigned int mclk; /* Input frequency of the MCLK pin */
48 unsigned int mode; /* The mode (I2S or left-justified) */
52 * The codec isn't really big-endian or little-endian, since the I2S
53 * interface requires data to be sent serially with the MSbit first.
54 * However, to support BE and LE I2S devices, we specify both here. That
55 * way, ALSA will always match the bit patterns.
57 #define CS4270_FORMATS (SNDRV_PCM_FMTBIT_S8 | \
58 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | \
59 SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE | \
60 SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE | \
61 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE | \
62 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE)
66 /* CS4270 registers addresses */
67 #define CS4270_CHIPID 0x01 /* Chip ID */
68 #define CS4270_PWRCTL 0x02 /* Power Control */
69 #define CS4270_MODE 0x03 /* Mode Control */
70 #define CS4270_FORMAT 0x04 /* Serial Format, ADC/DAC Control */
71 #define CS4270_TRANS 0x05 /* Transition Control */
72 #define CS4270_MUTE 0x06 /* Mute Control */
73 #define CS4270_VOLA 0x07 /* DAC Channel A Volume Control */
74 #define CS4270_VOLB 0x08 /* DAC Channel B Volume Control */
76 #define CS4270_FIRSTREG 0x01
77 #define CS4270_LASTREG 0x08
78 #define CS4270_NUMREGS (CS4270_LASTREG - CS4270_FIRSTREG + 1)
80 /* Bit masks for the CS4270 registers */
81 #define CS4270_CHIPID_ID 0xF0
82 #define CS4270_CHIPID_REV 0x0F
83 #define CS4270_PWRCTL_FREEZE 0x80
84 #define CS4270_PWRCTL_PDN_ADC 0x20
85 #define CS4270_PWRCTL_PDN_DAC 0x02
86 #define CS4270_PWRCTL_PDN 0x01
87 #define CS4270_MODE_SPEED_MASK 0x30
88 #define CS4270_MODE_1X 0x00
89 #define CS4270_MODE_2X 0x10
90 #define CS4270_MODE_4X 0x20
91 #define CS4270_MODE_SLAVE 0x30
92 #define CS4270_MODE_DIV_MASK 0x0E
93 #define CS4270_MODE_DIV1 0x00
94 #define CS4270_MODE_DIV15 0x02
95 #define CS4270_MODE_DIV2 0x04
96 #define CS4270_MODE_DIV3 0x06
97 #define CS4270_MODE_DIV4 0x08
98 #define CS4270_MODE_POPGUARD 0x01
99 #define CS4270_FORMAT_FREEZE_A 0x80
100 #define CS4270_FORMAT_FREEZE_B 0x40
101 #define CS4270_FORMAT_LOOPBACK 0x20
102 #define CS4270_FORMAT_DAC_MASK 0x18
103 #define CS4270_FORMAT_DAC_LJ 0x00
104 #define CS4270_FORMAT_DAC_I2S 0x08
105 #define CS4270_FORMAT_DAC_RJ16 0x18
106 #define CS4270_FORMAT_DAC_RJ24 0x10
107 #define CS4270_FORMAT_ADC_MASK 0x01
108 #define CS4270_FORMAT_ADC_LJ 0x00
109 #define CS4270_FORMAT_ADC_I2S 0x01
110 #define CS4270_TRANS_ONE_VOL 0x80
111 #define CS4270_TRANS_SOFT 0x40
112 #define CS4270_TRANS_ZERO 0x20
113 #define CS4270_TRANS_INV_ADC_A 0x08
114 #define CS4270_TRANS_INV_ADC_B 0x10
115 #define CS4270_TRANS_INV_DAC_A 0x02
116 #define CS4270_TRANS_INV_DAC_B 0x04
117 #define CS4270_TRANS_DEEMPH 0x01
118 #define CS4270_MUTE_AUTO 0x20
119 #define CS4270_MUTE_ADC_A 0x08
120 #define CS4270_MUTE_ADC_B 0x10
121 #define CS4270_MUTE_POLARITY 0x04
122 #define CS4270_MUTE_DAC_A 0x01
123 #define CS4270_MUTE_DAC_B 0x02
126 * Clock Ratio Selection for Master Mode with I2C enabled
128 * The data for this chart is taken from Table 5 of the CS4270 reference
131 * This table is used to determine how to program the Mode Control register.
132 * It is also used by cs4270_set_dai_sysclk() to tell ALSA which sampling
133 * rates the CS4270 currently supports.
135 * Each element in this array corresponds to the ratios in mclk_ratios[].
136 * These two arrays need to be in sync.
138 * 'speed_mode' is the corresponding bit pattern to be written to the
139 * MODE bits of the Mode Control Register
141 * 'mclk' is the corresponding bit pattern to be wirten to the MCLK bits of
142 * the Mode Control Register.
144 * In situations where a single ratio is represented by multiple speed
145 * modes, we favor the slowest speed. E.g, for a ratio of 128, we pick
146 * double-speed instead of quad-speed. However, the CS4270 errata states
147 * that Divide-By-1.5 can cause failures, so we avoid that mode where
150 * ERRATA: There is an errata for the CS4270 where divide-by-1.5 does not
151 * work if VD = 3.3V. If this effects you, select the
152 * CONFIG_SND_SOC_CS4270_VD33_ERRATA Kconfig option, and the driver will
153 * never select any sample rates that require divide-by-1.5.
159 } cs4270_mode_ratios[] = {
160 {64, CS4270_MODE_4X, CS4270_MODE_DIV1},
161 #ifndef CONFIG_SND_SOC_CS4270_VD33_ERRATA
162 {96, CS4270_MODE_4X, CS4270_MODE_DIV15},
164 {128, CS4270_MODE_2X, CS4270_MODE_DIV1},
165 {192, CS4270_MODE_4X, CS4270_MODE_DIV3},
166 {256, CS4270_MODE_1X, CS4270_MODE_DIV1},
167 {384, CS4270_MODE_2X, CS4270_MODE_DIV3},
168 {512, CS4270_MODE_1X, CS4270_MODE_DIV2},
169 {768, CS4270_MODE_1X, CS4270_MODE_DIV3},
170 {1024, CS4270_MODE_1X, CS4270_MODE_DIV4}
173 /* The number of MCLK/LRCK ratios supported by the CS4270 */
174 #define NUM_MCLK_RATIOS ARRAY_SIZE(cs4270_mode_ratios)
177 * Determine the CS4270 samples rates.
179 * 'freq' is the input frequency to MCLK. The other parameters are ignored.
181 * The value of MCLK is used to determine which sample rates are supported
182 * by the CS4270. The ratio of MCLK / Fs must be equal to one of nine
183 * support values: 64, 96, 128, 192, 256, 384, 512, 768, and 1024.
185 * This function calculates the nine ratios and determines which ones match
186 * a standard sample rate. If there's a match, then it is added to the list
187 * of support sample rates.
189 * This function must be called by the machine driver's 'startup' function,
190 * otherwise the list of supported sample rates will not be available in
193 * Note that in stand-alone mode, the sample rate is determined by input
194 * pins M0, M1, MDIV1, and MDIV2. Also in stand-alone mode, divide-by-3
195 * is not a programmable option. However, divide-by-3 is not an available
196 * option in stand-alone mode. This cases two problems: a ratio of 768 is
197 * not available (it requires divide-by-3) and B) ratios 192 and 384 can
198 * only be selected with divide-by-1.5, but there is an errate that make
199 * this selection difficult.
201 * In addition, there is no mechanism for communicating with the machine
202 * driver what the input settings can be. This would need to be implemented
203 * for stand-alone mode to work.
205 static int cs4270_set_dai_sysclk(struct snd_soc_codec_dai *codec_dai,
206 int clk_id, unsigned int freq, int dir)
208 struct snd_soc_codec *codec = codec_dai->codec;
209 struct cs4270_private *cs4270 = codec->private_data;
210 unsigned int rates = 0;
211 unsigned int rate_min = -1;
212 unsigned int rate_max = 0;
217 for (i = 0; i < NUM_MCLK_RATIOS; i++) {
218 unsigned int rate = freq / cs4270_mode_ratios[i].ratio;
219 rates |= snd_pcm_rate_to_rate_bit(rate);
225 /* FIXME: soc should support a rate list */
226 rates &= ~SNDRV_PCM_RATE_KNOT;
229 printk(KERN_ERR "cs4270: could not find a valid sample rate\n");
233 codec_dai->playback.rates = rates;
234 codec_dai->playback.rate_min = rate_min;
235 codec_dai->playback.rate_max = rate_max;
237 codec_dai->capture.rates = rates;
238 codec_dai->capture.rate_min = rate_min;
239 codec_dai->capture.rate_max = rate_max;
245 * Configure the codec for the selected audio format
247 * This function takes a bitmask of SND_SOC_DAIFMT_x bits and programs the
250 * Currently, this function only supports SND_SOC_DAIFMT_I2S and
251 * SND_SOC_DAIFMT_LEFT_J. The CS4270 codec also supports right-justified
252 * data for playback only, but ASoC currently does not support different
253 * formats for playback vs. record.
255 static int cs4270_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
258 struct snd_soc_codec *codec = codec_dai->codec;
259 struct cs4270_private *cs4270 = codec->private_data;
262 switch (format & SND_SOC_DAIFMT_FORMAT_MASK) {
263 case SND_SOC_DAIFMT_I2S:
264 case SND_SOC_DAIFMT_LEFT_J:
265 cs4270->mode = format & SND_SOC_DAIFMT_FORMAT_MASK;
268 printk(KERN_ERR "cs4270: invalid DAI format\n");
276 * A list of addresses on which this CS4270 could use. I2C addresses are
277 * 7 bits. For the CS4270, the upper four bits are always 1001, and the
278 * lower three bits are determined via the AD2, AD1, and AD0 pins
281 static const unsigned short normal_i2c[] = {
282 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, I2C_CLIENT_END
287 * Pre-fill the CS4270 register cache.
289 * We use the auto-increment feature of the CS4270 to read all registers in
292 static int cs4270_fill_cache(struct snd_soc_codec *codec)
294 u8 *cache = codec->reg_cache;
295 struct i2c_client *i2c_client = codec->control_data;
298 length = i2c_smbus_read_i2c_block_data(i2c_client,
299 CS4270_FIRSTREG | 0x80, CS4270_NUMREGS, cache);
301 if (length != CS4270_NUMREGS) {
302 printk(KERN_ERR "cs4270: I2C read failure, addr=0x%x\n",
311 * Read from the CS4270 register cache.
313 * This CS4270 registers are cached to avoid excessive I2C I/O operations.
314 * After the initial read to pre-fill the cache, the CS4270 never updates
315 * the register values, so we won't have a cache coherncy problem.
317 static unsigned int cs4270_read_reg_cache(struct snd_soc_codec *codec,
320 u8 *cache = codec->reg_cache;
322 if ((reg < CS4270_FIRSTREG) || (reg > CS4270_LASTREG))
325 return cache[reg - CS4270_FIRSTREG];
329 * Write to a CS4270 register via the I2C bus.
331 * This function writes the given value to the given CS4270 register, and
332 * also updates the register cache.
334 * Note that we don't use the hw_write function pointer of snd_soc_codec.
335 * That's because it's too clunky: the hw_write_t prototype does not match
336 * i2c_smbus_write_byte_data(), and it's just another layer of overhead.
338 static int cs4270_i2c_write(struct snd_soc_codec *codec, unsigned int reg,
341 u8 *cache = codec->reg_cache;
343 if ((reg < CS4270_FIRSTREG) || (reg > CS4270_LASTREG))
346 /* Only perform an I2C operation if the new value is different */
347 if (cache[reg - CS4270_FIRSTREG] != value) {
348 struct i2c_client *client = codec->control_data;
349 if (i2c_smbus_write_byte_data(client, reg, value)) {
350 printk(KERN_ERR "cs4270: I2C write failed\n");
354 /* We've written to the hardware, so update the cache */
355 cache[reg - CS4270_FIRSTREG] = value;
362 * Program the CS4270 with the given hardware parameters.
364 * The .dai_ops functions are used to provide board-specific data, like
365 * input frequencies, to this driver. This function takes that information,
366 * combines it with the hardware parameters provided, and programs the
367 * hardware accordingly.
369 static int cs4270_hw_params(struct snd_pcm_substream *substream,
370 struct snd_pcm_hw_params *params)
372 struct snd_soc_pcm_runtime *rtd = substream->private_data;
373 struct snd_soc_device *socdev = rtd->socdev;
374 struct snd_soc_codec *codec = socdev->codec;
375 struct cs4270_private *cs4270 = codec->private_data;
376 unsigned int ret = 0;
382 /* Figure out which MCLK/LRCK ratio to use */
384 rate = params_rate(params); /* Sampling rate, in Hz */
385 ratio = cs4270->mclk / rate; /* MCLK/LRCK ratio */
387 for (i = 0; i < NUM_MCLK_RATIOS; i++) {
388 if (cs4270_mode_ratios[i].ratio == ratio)
392 if (i == NUM_MCLK_RATIOS) {
393 /* We did not find a matching ratio */
394 printk(KERN_ERR "cs4270: could not find matching ratio\n");
398 /* Freeze and power-down the codec */
400 ret = snd_soc_write(codec, CS4270_PWRCTL, CS4270_PWRCTL_FREEZE |
401 CS4270_PWRCTL_PDN_ADC | CS4270_PWRCTL_PDN_DAC |
404 printk(KERN_ERR "cs4270: I2C write failed\n");
408 /* Program the mode control register */
410 reg = snd_soc_read(codec, CS4270_MODE);
411 reg &= ~(CS4270_MODE_SPEED_MASK | CS4270_MODE_DIV_MASK);
412 reg |= cs4270_mode_ratios[i].speed_mode | cs4270_mode_ratios[i].mclk;
414 ret = snd_soc_write(codec, CS4270_MODE, reg);
416 printk(KERN_ERR "cs4270: I2C write failed\n");
420 /* Program the format register */
422 reg = snd_soc_read(codec, CS4270_FORMAT);
423 reg &= ~(CS4270_FORMAT_DAC_MASK | CS4270_FORMAT_ADC_MASK);
425 switch (cs4270->mode) {
426 case SND_SOC_DAIFMT_I2S:
427 reg |= CS4270_FORMAT_DAC_I2S | CS4270_FORMAT_ADC_I2S;
429 case SND_SOC_DAIFMT_LEFT_J:
430 reg |= CS4270_FORMAT_DAC_LJ | CS4270_FORMAT_ADC_LJ;
433 printk(KERN_ERR "cs4270: unknown format\n");
437 ret = snd_soc_write(codec, CS4270_FORMAT, reg);
439 printk(KERN_ERR "cs4270: I2C write failed\n");
443 /* Disable auto-mute. This feature appears to be buggy, because in
444 some situations, auto-mute will not deactivate when it should. */
446 reg = snd_soc_read(codec, CS4270_MUTE);
447 reg &= ~CS4270_MUTE_AUTO;
448 ret = snd_soc_write(codec, CS4270_MUTE, reg);
450 printk(KERN_ERR "cs4270: I2C write failed\n");
454 /* Thaw and power-up the codec */
456 ret = snd_soc_write(codec, CS4270_PWRCTL, 0);
458 printk(KERN_ERR "cs4270: I2C write failed\n");
465 #ifdef CONFIG_SND_SOC_CS4270_HWMUTE
468 * Set the CS4270 external mute
470 * This function toggles the mute bits in the MUTE register. The CS4270's
471 * mute capability is intended for external muting circuitry, so if the
472 * board does not have the MUTEA or MUTEB pins connected to such circuitry,
473 * then this function will do nothing.
475 static int cs4270_mute(struct snd_soc_codec_dai *dai, int mute)
477 struct snd_soc_codec *codec = dai->codec;
480 reg6 = snd_soc_read(codec, CS4270_MUTE);
483 reg6 |= CS4270_MUTE_ADC_A | CS4270_MUTE_ADC_B |
484 CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B;
486 reg6 &= ~(CS4270_MUTE_ADC_A | CS4270_MUTE_ADC_B |
487 CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B);
489 return snd_soc_write(codec, CS4270_MUTE, reg6);
494 static int cs4270_i2c_probe(struct i2c_adapter *adap, int addr, int kind);
497 * Notify the driver that a new I2C bus has been found.
499 * This function is called for each I2C bus in the system. The function
500 * then asks the I2C subsystem to probe that bus at the addresses on which
501 * our device (the CS4270) could exist. If a device is found at one of
502 * those addresses, then our probe function (cs4270_i2c_probe) is called.
504 static int cs4270_i2c_attach(struct i2c_adapter *adapter)
506 return i2c_probe(adapter, &addr_data, cs4270_i2c_probe);
509 static int cs4270_i2c_detach(struct i2c_client *client)
511 struct snd_soc_codec *codec = i2c_get_clientdata(client);
513 i2c_detach_client(client);
514 codec->control_data = NULL;
516 kfree(codec->reg_cache);
517 codec->reg_cache = NULL;
523 /* A list of non-DAPM controls that the CS4270 supports */
524 static const struct snd_kcontrol_new cs4270_snd_controls[] = {
525 SOC_DOUBLE_R("Master Playback Volume",
526 CS4270_VOLA, CS4270_VOLB, 0, 0xFF, 1)
529 static struct i2c_driver cs4270_i2c_driver = {
531 .name = "CS4270 I2C",
532 .owner = THIS_MODULE,
534 .id = I2C_DRIVERID_CS4270,
535 .attach_adapter = cs4270_i2c_attach,
536 .detach_client = cs4270_i2c_detach,
540 * Global variable to store socdev for i2c probe function.
542 * If struct i2c_driver had a private_data field, we wouldn't need to use
543 * cs4270_socdec. This is the only way to pass the socdev structure to
544 * cs4270_i2c_probe().
546 * The real solution to cs4270_socdev is to create a mechanism
547 * that maps I2C addresses to snd_soc_device structures. Perhaps the
548 * creation of the snd_soc_device object should be moved out of
549 * cs4270_probe() and into cs4270_i2c_probe(), but that would make this
550 * driver dependent on I2C. The CS4270 supports "stand-alone" mode, whereby
551 * the chip is *not* connected to the I2C bus, but is instead configured via
554 static struct snd_soc_device *cs4270_socdev;
557 * Initialize the I2C interface of the CS4270
559 * This function is called for whenever the I2C subsystem finds a device
560 * at a particular address.
562 * Note: snd_soc_new_pcms() must be called before this function can be called,
563 * because of snd_ctl_add().
565 static int cs4270_i2c_probe(struct i2c_adapter *adapter, int addr, int kind)
567 struct snd_soc_device *socdev = cs4270_socdev;
568 struct snd_soc_codec *codec = socdev->codec;
569 struct i2c_client *i2c_client = NULL;
573 /* Probing all possible addresses has one drawback: if there are
574 multiple CS4270s on the bus, then you cannot specify which
575 socdev is matched with which CS4270. For now, we just reject
576 this I2C device if the socdev already has one attached. */
577 if (codec->control_data)
580 /* Note: codec_dai->codec is NULL here */
582 i2c_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
584 printk(KERN_ERR "cs4270: could not allocate I2C client\n");
588 codec->reg_cache = kzalloc(CS4270_NUMREGS, GFP_KERNEL);
589 if (!codec->reg_cache) {
590 printk(KERN_ERR "cs4270: could not allocate register cache\n");
595 i2c_set_clientdata(i2c_client, codec);
596 strcpy(i2c_client->name, "CS4270");
598 i2c_client->driver = &cs4270_i2c_driver;
599 i2c_client->adapter = adapter;
600 i2c_client->addr = addr;
602 /* Verify that we have a CS4270 */
604 ret = i2c_smbus_read_byte_data(i2c_client, CS4270_CHIPID);
606 printk(KERN_ERR "cs4270: failed to read I2C\n");
609 /* The top four bits of the chip ID should be 1100. */
610 if ((ret & 0xF0) != 0xC0) {
611 /* The device at this address is not a CS4270 codec */
616 printk(KERN_INFO "cs4270: found device at I2C address %X\n", addr);
617 printk(KERN_INFO "cs4270: hardware revision %X\n", ret & 0xF);
619 /* Tell the I2C layer a new client has arrived */
621 ret = i2c_attach_client(i2c_client);
623 printk(KERN_ERR "cs4270: could not attach codec, "
624 "I2C address %x, error code %i\n", addr, ret);
628 codec->control_data = i2c_client;
629 codec->read = cs4270_read_reg_cache;
630 codec->write = cs4270_i2c_write;
631 codec->reg_cache_size = CS4270_NUMREGS;
633 /* The I2C interface is set up, so pre-fill our register cache */
635 ret = cs4270_fill_cache(codec);
637 printk(KERN_ERR "cs4270: failed to fill register cache\n");
641 /* Add the non-DAPM controls */
643 for (i = 0; i < ARRAY_SIZE(cs4270_snd_controls); i++) {
644 struct snd_kcontrol *kctrl =
645 snd_soc_cnew(&cs4270_snd_controls[i], codec, NULL);
647 ret = snd_ctl_add(codec->card, kctrl);
655 if (codec->control_data) {
656 i2c_detach_client(i2c_client);
657 codec->control_data = NULL;
660 kfree(codec->reg_cache);
661 codec->reg_cache = NULL;
662 codec->reg_cache_size = 0;
671 struct snd_soc_codec_dai cs4270_dai = {
674 .stream_name = "Playback",
678 .formats = CS4270_FORMATS,
681 .stream_name = "Capture",
685 .formats = CS4270_FORMATS,
688 EXPORT_SYMBOL_GPL(cs4270_dai);
691 * ASoC probe function
693 * This function is called when the machine driver calls
694 * platform_device_add().
696 static int cs4270_probe(struct platform_device *pdev)
698 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
699 struct snd_soc_codec *codec;
702 printk(KERN_INFO "CS4270 ALSA SoC Codec\n");
704 /* Allocate enough space for the snd_soc_codec structure
705 and our private data together. */
706 codec = kzalloc(ALIGN(sizeof(struct snd_soc_codec), 4) +
707 sizeof(struct cs4270_private), GFP_KERNEL);
709 printk(KERN_ERR "cs4270: Could not allocate codec structure\n");
713 mutex_init(&codec->mutex);
714 INIT_LIST_HEAD(&codec->dapm_widgets);
715 INIT_LIST_HEAD(&codec->dapm_paths);
717 codec->name = "CS4270";
718 codec->owner = THIS_MODULE;
719 codec->dai = &cs4270_dai;
721 codec->private_data = (void *) codec +
722 ALIGN(sizeof(struct snd_soc_codec), 4);
724 socdev->codec = codec;
728 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
730 printk(KERN_ERR "cs4270: failed to create PCMs\n");
735 cs4270_socdev = socdev;
737 ret = i2c_add_driver(&cs4270_i2c_driver);
739 printk(KERN_ERR "cs4270: failed to attach driver");
740 snd_soc_free_pcms(socdev);
744 /* Did we find a CS4270 on the I2C bus? */
745 if (codec->control_data) {
746 /* Initialize codec ops */
747 cs4270_dai.ops.hw_params = cs4270_hw_params;
748 cs4270_dai.dai_ops.set_sysclk = cs4270_set_dai_sysclk;
749 cs4270_dai.dai_ops.set_fmt = cs4270_set_dai_fmt;
750 #ifdef CONFIG_SND_SOC_CS4270_HWMUTE
751 cs4270_dai.dai_ops.digital_mute = cs4270_mute;
754 printk(KERN_INFO "cs4270: no I2C device found, "
755 "using stand-alone mode\n");
757 printk(KERN_INFO "cs4270: I2C disabled, using stand-alone mode\n");
760 ret = snd_soc_register_card(socdev);
762 printk(KERN_ERR "cs4270: failed to register card\n");
763 snd_soc_free_pcms(socdev);
770 static int cs4270_remove(struct platform_device *pdev)
772 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
774 snd_soc_free_pcms(socdev);
777 if (socdev->codec->control_data)
778 i2c_del_driver(&cs4270_i2c_driver);
781 kfree(socdev->codec);
782 socdev->codec = NULL;
788 * ASoC codec device structure
790 * Assign this variable to the codec_dev field of the machine driver's
791 * snd_soc_device structure.
793 struct snd_soc_codec_device soc_codec_device_cs4270 = {
794 .probe = cs4270_probe,
795 .remove = cs4270_remove
797 EXPORT_SYMBOL_GPL(soc_codec_device_cs4270);
799 MODULE_AUTHOR("Timur Tabi <timur@freescale.com>");
800 MODULE_DESCRIPTION("Cirrus Logic CS4270 ALSA SoC Codec Driver");
801 MODULE_LICENSE("GPL");