2 * sound/ubicom32/ubi32-cs4384.c
3 * Interface to ubicom32 virtual audio peripheral - using CS4384 DAC
5 * (C) Copyright 2009, Ubicom, Inc.
7 * This file is part of the Ubicom32 Linux Kernel Port.
9 * The Ubicom32 Linux Kernel Port is free software: you can redistribute
10 * it and/or modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation, either version 2 of the
12 * License, or (at your option) any later version.
14 * The Ubicom32 Linux Kernel Port is distributed in the hope that it
15 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
16 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17 * the GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with the Ubicom32 Linux Kernel Port. If not,
21 * see <http://www.gnu.org/licenses/>.
24 #include <linux/i2c.h>
25 #include <linux/module.h>
26 #include <linux/moduleparam.h>
27 #include <linux/delay.h>
28 #include <sound/core.h>
29 #include <sound/tlv.h>
30 #include <sound/control.h>
31 #include <sound/pcm.h>
32 #include <sound/initval.h>
33 #include <asm/ip5000.h>
35 #include <asm/audio.h>
36 #include <asm/ubi32-cs4384.h>
39 #define DRIVER_NAME "snd-ubi32-cs4384"
44 static const struct i2c_device_id snd_ubi32_cs4384_id[] = {
48 MODULE_DEVICE_TABLE(i2c, ubicom32audio_id);
50 static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
57 * Be careful of changing the order of these IDs, they
58 * are used to index the volume array.
60 SND_UBI32_CS4384_FRONT_ID,
61 SND_UBI32_CS4384_SURROUND_ID,
62 SND_UBI32_CS4384_CENTER_ID,
63 SND_UBI32_CS4384_LFE_ID,
64 SND_UBI32_CS4384_REAR_ID,
67 * This should be the last ID
69 SND_UBI32_CS4384_LAST_ID,
71 static const u8_t snd_ubi32_cs4384_ch_ofs[] = {0, 2, 4, 5, 6};
73 static const DECLARE_TLV_DB_SCALE(snd_ubi32_cs4384_db, -12750, 50, 0);
75 #define snd_ubi32_cs4384_info_mute snd_ctl_boolean_stereo_info
76 #define snd_ubi32_cs4384_info_mute_mono snd_ctl_boolean_mono_info
81 static int snd_ubi32_cs4384_info_volume(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo);
82 static int snd_ubi32_cs4384_get_volume(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol);
83 static int snd_ubi32_cs4384_put_volume(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol);
84 static int snd_ubi32_cs4384_get_mute(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol);
85 static int snd_ubi32_cs4384_put_mute(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol);
88 * Make sure to update these if the structure below is changed
90 #define SND_UBI32_MUTE_CTL_START 5
91 #define SND_UBI32_MUTE_CTL_END 9
92 static struct snd_kcontrol_new snd_ubi32_cs4384_controls[] __devinitdata = {
94 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
95 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
96 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
97 .name = "Front Playback Volume",
98 .info = snd_ubi32_cs4384_info_volume,
99 .get = snd_ubi32_cs4384_get_volume,
100 .put = snd_ubi32_cs4384_put_volume,
101 .private_value = SND_UBI32_CS4384_FRONT_ID,
103 .p = snd_ubi32_cs4384_db,
107 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
108 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
109 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
110 .name = "Surround Playback Volume",
111 .info = snd_ubi32_cs4384_info_volume,
112 .get = snd_ubi32_cs4384_get_volume,
113 .put = snd_ubi32_cs4384_put_volume,
114 .private_value = SND_UBI32_CS4384_SURROUND_ID,
116 .p = snd_ubi32_cs4384_db,
120 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
121 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
122 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
123 .name = "Center Playback Volume",
124 .info = snd_ubi32_cs4384_info_volume,
125 .get = snd_ubi32_cs4384_get_volume,
126 .put = snd_ubi32_cs4384_put_volume,
127 .private_value = SND_UBI32_CS4384_CENTER_ID,
129 .p = snd_ubi32_cs4384_db,
133 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
134 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
135 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
136 .name = "LFE Playback Volume",
137 .info = snd_ubi32_cs4384_info_volume,
138 .get = snd_ubi32_cs4384_get_volume,
139 .put = snd_ubi32_cs4384_put_volume,
140 .private_value = SND_UBI32_CS4384_LFE_ID,
142 .p = snd_ubi32_cs4384_db,
146 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
147 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
148 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
149 .name = "Rear Playback Volume",
150 .info = snd_ubi32_cs4384_info_volume,
151 .get = snd_ubi32_cs4384_get_volume,
152 .put = snd_ubi32_cs4384_put_volume,
153 .private_value = SND_UBI32_CS4384_REAR_ID,
155 .p = snd_ubi32_cs4384_db,
159 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
160 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
161 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
162 .name = "Front Playback Switch",
163 .info = snd_ubi32_cs4384_info_mute,
164 .get = snd_ubi32_cs4384_get_mute,
165 .put = snd_ubi32_cs4384_put_mute,
166 .private_value = SND_UBI32_CS4384_FRONT_ID,
169 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
170 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
171 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
172 .name = "Surround Playback Switch",
173 .info = snd_ubi32_cs4384_info_mute,
174 .get = snd_ubi32_cs4384_get_mute,
175 .put = snd_ubi32_cs4384_put_mute,
176 .private_value = SND_UBI32_CS4384_SURROUND_ID,
179 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
180 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
181 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
182 .name = "Center Playback Switch",
183 .info = snd_ubi32_cs4384_info_mute_mono,
184 .get = snd_ubi32_cs4384_get_mute,
185 .put = snd_ubi32_cs4384_put_mute,
186 .private_value = SND_UBI32_CS4384_CENTER_ID,
189 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
190 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
191 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
192 .name = "LFE Playback Switch",
193 .info = snd_ubi32_cs4384_info_mute_mono,
194 .get = snd_ubi32_cs4384_get_mute,
195 .put = snd_ubi32_cs4384_put_mute,
196 .private_value = SND_UBI32_CS4384_LFE_ID,
199 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
200 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
201 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
202 .name = "Rear Playback Switch",
203 .info = snd_ubi32_cs4384_info_mute,
204 .get = snd_ubi32_cs4384_get_mute,
205 .put = snd_ubi32_cs4384_put_mute,
206 .private_value = SND_UBI32_CS4384_REAR_ID,
213 struct snd_ubi32_cs4384_priv {
215 * Array of current volumes
216 * (L, R, SL, SR, C, LFE, RL, RR)
222 * MSB (RR, RL, LFE, C, SR, SL, R, L) LSB
229 struct snd_kcontrol *kctls[ARRAY_SIZE(snd_ubi32_cs4384_controls)];
232 * Lock to protect our card
238 * snd_ubi32_cs4384_info_volume
240 static int snd_ubi32_cs4384_info_volume(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
242 unsigned int id = (unsigned int)kcontrol->private_value;
244 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
246 if ((id != SND_UBI32_CS4384_LFE_ID) &&
247 (id != SND_UBI32_CS4384_CENTER_ID)) {
250 uinfo->value.integer.min = 0;
251 uinfo->value.integer.max = 255;
256 * snd_ubi32_cs4384_get_volume
258 static int snd_ubi32_cs4384_get_volume(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
260 struct ubi32_snd_priv *priv = snd_kcontrol_chip(kcontrol);
261 struct snd_ubi32_cs4384_priv *cs4384_priv;
262 unsigned int id = (unsigned int)kcontrol->private_value;
263 int ch = snd_ubi32_cs4384_ch_ofs[id];
266 if (id >= SND_UBI32_CS4384_LAST_ID) {
270 cs4384_priv = snd_ubi32_priv_get_drv(priv);
272 spin_lock_irqsave(&cs4384_priv->lock, flags);
274 ucontrol->value.integer.value[0] = cs4384_priv->volume[ch];
275 if ((id != SND_UBI32_CS4384_LFE_ID) &&
276 (id != SND_UBI32_CS4384_CENTER_ID)) {
278 ucontrol->value.integer.value[1] = cs4384_priv->volume[ch];
281 spin_unlock_irqrestore(&cs4384_priv->lock, flags);
287 * snd_ubi32_cs4384_put_volume
289 static int snd_ubi32_cs4384_put_volume(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
291 struct ubi32_snd_priv *priv = snd_kcontrol_chip(kcontrol);
292 struct i2c_client *client = (struct i2c_client *)priv->client;
293 struct snd_ubi32_cs4384_priv *cs4384_priv;
294 unsigned int id = (unsigned int)kcontrol->private_value;
295 int ch = snd_ubi32_cs4384_ch_ofs[id];
297 unsigned char send[3];
301 if (id >= SND_UBI32_CS4384_LAST_ID) {
305 cs4384_priv = snd_ubi32_priv_get_drv(priv);
307 spin_lock_irqsave(&cs4384_priv->lock, flags);
311 case SND_UBI32_CS4384_REAR_ID:
318 case SND_UBI32_CS4384_SURROUND_ID:
325 case SND_UBI32_CS4384_FRONT_ID:
328 send[1] = 255 - (ucontrol->value.integer.value[0] & 0xFF);
329 send[2] = 255 - (ucontrol->value.integer.value[1] & 0xFF);
330 cs4384_priv->volume[ch++] = send[1];
331 cs4384_priv->volume[ch] = send[2];
334 case SND_UBI32_CS4384_LFE_ID:
341 case SND_UBI32_CS4384_CENTER_ID:
344 send[1] = 255 - (ucontrol->value.integer.value[0] & 0xFF);
345 cs4384_priv->volume[ch] = send[1];
349 spin_unlock_irqrestore(&cs4384_priv->lock, flags);
355 * Send the volume to the chip
358 ret = i2c_master_send(client, send, nch);
360 snd_printk(KERN_ERR "Failed to set volume on CS4384\n");
364 spin_unlock_irqrestore(&cs4384_priv->lock, flags);
370 * snd_ubi32_cs4384_get_mute
372 static int snd_ubi32_cs4384_get_mute(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
374 struct ubi32_snd_priv *priv = snd_kcontrol_chip(kcontrol);
375 struct snd_ubi32_cs4384_priv *cs4384_priv;
376 unsigned int id = (unsigned int)kcontrol->private_value;
377 int ch = snd_ubi32_cs4384_ch_ofs[id];
380 if (id >= SND_UBI32_CS4384_LAST_ID) {
384 cs4384_priv = snd_ubi32_priv_get_drv(priv);
386 spin_lock_irqsave(&cs4384_priv->lock, flags);
388 ucontrol->value.integer.value[0] = !(cs4384_priv->mute & (1 << ch));
390 if ((id != SND_UBI32_CS4384_LFE_ID) &&
391 (id != SND_UBI32_CS4384_CENTER_ID)) {
393 ucontrol->value.integer.value[1] = !(cs4384_priv->mute & (1 << ch));
396 spin_unlock_irqrestore(&cs4384_priv->lock, flags);
402 * snd_ubi32_cs4384_put_mute
404 static int snd_ubi32_cs4384_put_mute(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
406 struct ubi32_snd_priv *priv = snd_kcontrol_chip(kcontrol);
407 struct i2c_client *client = (struct i2c_client *)priv->client;
408 struct snd_ubi32_cs4384_priv *cs4384_priv;
409 unsigned int id = (unsigned int)kcontrol->private_value;
410 int ch = snd_ubi32_cs4384_ch_ofs[id];
412 unsigned char send[2];
415 if (id >= SND_UBI32_CS4384_LAST_ID) {
419 cs4384_priv = snd_ubi32_priv_get_drv(priv);
421 spin_lock_irqsave(&cs4384_priv->lock, flags);
423 if (ucontrol->value.integer.value[0]) {
424 cs4384_priv->mute &= ~(1 << ch);
426 cs4384_priv->mute |= (1 << ch);
429 if ((id != SND_UBI32_CS4384_LFE_ID) && (id != SND_UBI32_CS4384_CENTER_ID)) {
431 if (ucontrol->value.integer.value[1]) {
432 cs4384_priv->mute &= ~(1 << ch);
434 cs4384_priv->mute |= (1 << ch);
439 * Update the chip's mute reigster
442 send[1] = cs4384_priv->mute;
443 ret = i2c_master_send(client, send, 2);
445 snd_printk(KERN_ERR "Failed to set mute on CS4384\n");
448 spin_unlock_irqrestore(&cs4384_priv->lock, flags);
454 * snd_ubi32_cs4384_mixer
455 * Setup the mixer controls
457 static int __devinit snd_ubi32_cs4384_mixer(struct ubi32_snd_priv *priv)
459 struct snd_card *card = priv->card;
460 struct snd_ubi32_cs4384_priv *cs4384_priv;
463 cs4384_priv = snd_ubi32_priv_get_drv(priv);
464 for (i = 0; i < ARRAY_SIZE(snd_ubi32_cs4384_controls); i++) {
467 cs4384_priv->kctls[i] = snd_ctl_new1(&snd_ubi32_cs4384_controls[i], priv);
468 err = snd_ctl_add(card, cs4384_priv->kctls[i]);
470 snd_printk(KERN_WARNING "Failed to add control %d\n", i);
478 * snd_ubi32_cs4384_free
479 * Card private data free function
481 void snd_ubi32_cs4384_free(struct snd_card *card)
483 struct snd_ubi32_cs4384_priv *cs4384_priv;
484 struct ubi32_snd_priv *ubi32_priv;
486 ubi32_priv = card->private_data;
487 cs4384_priv = snd_ubi32_priv_get_drv(ubi32_priv);
494 * snd_ubi32_cs4384_setup_mclk
496 static int snd_ubi32_cs4384_setup_mclk(struct ubi32_cs4384_platform_data *pdata)
498 struct ubicom32_io_port *ioa = (struct ubicom32_io_port *)RA;
499 struct ubicom32_io_port *ioc = (struct ubicom32_io_port *)RC;
500 struct ubicom32_io_port *iod = (struct ubicom32_io_port *)RD;
501 struct ubicom32_io_port *ioe = (struct ubicom32_io_port *)RE;
502 struct ubicom32_io_port *ioh = (struct ubicom32_io_port *)RH;
507 div = pdata->mclk_entries[0].div;
510 ctlx = ((div - 1) << 16) | (div / 2);
512 switch (pdata->mclk_src) {
513 case UBI32_CS4384_MCLK_PWM_0:
517 if (!ioa->function) {
522 case UBI32_CS4384_MCLK_PWM_1:
524 ioc->ctl0 |= ctl0 << 16;
526 if (!ioe->function) {
531 case UBI32_CS4384_MCLK_PWM_2:
534 if (!iod->function) {
539 case UBI32_CS4384_MCLK_CLKDIV_1:
540 ioa->gpio_mask &= (1 << 7);
541 ioa->ctl1 &= ~(0x7F << 14);
542 ioa->ctl1 |= ((div - 1) << 14);
545 case UBI32_CS4384_MCLK_OTHER:
553 * snd_ubi32_cs4384_set_rate
555 static int snd_ubi32_cs4384_set_rate(struct ubi32_snd_priv *priv, int rate)
557 struct ubi32_cs4384_platform_data *cpd = priv->pdata->priv_data;
558 struct ubicom32_io_port *ioa = (struct ubicom32_io_port *)RA;
559 struct ubicom32_io_port *ioc = (struct ubicom32_io_port *)RC;
560 struct ubicom32_io_port *ioh = (struct ubicom32_io_port *)RH;
562 unsigned int div = 0;
563 const u16_t mult[] = {64, 96, 128, 192, 256, 384, 512, 768, 1024};
568 for (i = 0; i < sizeof(mult) / sizeof(u16_t); i++) {
569 for (j = 0; j < cpd->n_mclk; j++) {
570 if (((unsigned int)rate * (unsigned int)mult[i]) ==
571 cpd->mclk_entries[j].rate) {
572 div = cpd->mclk_entries[j].div;
578 ctl = ((div - 1) << 16) | (div / 2);
580 switch (cpd->mclk_src) {
581 case UBI32_CS4384_MCLK_PWM_0:
585 case UBI32_CS4384_MCLK_PWM_1:
589 case UBI32_CS4384_MCLK_PWM_2:
593 case UBI32_CS4384_MCLK_CLKDIV_1:
594 ioa->ctl1 &= ~(0x7F << 14);
595 ioa->ctl1 |= ((div - 1) << 14);
598 case UBI32_CS4384_MCLK_OTHER:
606 * snd_ubi32_cs4384_set_channels
607 * Mute unused channels
609 static int snd_ubi32_cs4384_set_channels(struct ubi32_snd_priv *priv, int channels)
611 struct i2c_client *client = (struct i2c_client *)priv->client;
612 struct snd_ubi32_cs4384_priv *cs4384_priv;
613 unsigned char send[2];
619 * Only support 0, 2, 4, 6, 8 channels
621 if ((channels > 8) || (channels & 1)) {
625 cs4384_priv = snd_ubi32_priv_get_drv(priv);
626 spin_lock_irqsave(&cs4384_priv->lock, flags);
629 * Address 09h, Mute control
632 send[1] = (unsigned char)(0xFF << channels);
634 ret = i2c_master_send(client, send, 2);
636 spin_unlock_irqrestore(&cs4384_priv->lock, flags);
639 * Notify the system that we changed the mutes
641 cs4384_priv->mute = (unsigned char)(0xFF << channels);
643 for (i = SND_UBI32_MUTE_CTL_START; i < SND_UBI32_MUTE_CTL_END; i++) {
644 snd_ctl_notify(priv->card, SNDRV_CTL_EVENT_MASK_VALUE,
645 &cs4384_priv->kctls[i]->id);
656 * snd_ubi32_cs4384_dac_init
658 static int snd_ubi32_cs4384_dac_init(struct i2c_client *client, const struct i2c_device_id *id)
661 unsigned char send[2];
662 unsigned char recv[2];
665 * Initialize the CS4384 DAC over the I2C interface
667 snd_printk(KERN_INFO "Initializing CS4384 DAC\n");
670 * Register 0x01: device/revid
673 ret = i2c_master_send(client, send, 1);
675 snd_printk(KERN_ERR "Failed 1st attempt to write to CS4384 register 0x01\n");
678 ret = i2c_master_recv(client, recv, 1);
680 snd_printk(KERN_ERR "Failed initial read of CS4384 registers\n");
683 snd_printk(KERN_INFO "CS4384 DAC Device/Rev: %08x\n", recv[0]);
686 * Register 0x02: Mode Control 1
687 * Control Port Enable, PCM, All DACs enabled, Power Down
691 ret = i2c_master_send(client, send, 2);
693 snd_printk(KERN_ERR "Failed to set CPEN CS4384\n");
698 * Register 0x08: Ramp and Mute
699 * RMP_UP, RMP_DN, PAMUTE, DAMUTE
703 ret = i2c_master_send(client, send, 2);
705 snd_printk(KERN_ERR "Failed to set CPEN CS4384\n");
710 * Register 0x03: PCM Control
711 * I2S DIF[3:0] = 0001, no De-Emphasis, Auto speed mode
715 ret = i2c_master_send(client, send, 2);
717 snd_printk(KERN_ERR "Failed to set CS4384 to I2S mode\n");
722 * Register 0x0B/0x0C: Volume control A1/B1
723 * Register 0x0E/0x0F: Volume control A2/B2
724 * Register 0x11/0x12: Volume control A3/B3
725 * Register 0x14/0x15: Volume control A4/B4
727 send[0] = 0x80 | 0x0B;
730 ret = i2c_master_send(client, send, 3);
732 snd_printk(KERN_ERR "Failed to set ch1 volume on CS4384\n");
736 send[0] = 0x80 | 0x0E;
739 ret = i2c_master_send(client, send, 3);
741 snd_printk(KERN_ERR "Failed to set ch2 volume on CS4384\n");
745 send[0] = 0x80 | 0x11;
748 ret = i2c_master_send(client, send, 3);
750 snd_printk(KERN_ERR "Failed to set ch3 volume on CS4384\n");
754 send[0] = 0x80 | 0x14;
757 ret = i2c_master_send(client, send, 3);
759 snd_printk(KERN_ERR "Failed to set ch4 volume on CS4384\n");
764 * Register 09h: Mute control
765 * Mute all (we will unmute channels as needed)
769 ret = i2c_master_send(client, send, 2);
771 snd_printk(KERN_ERR "Failed to power up CS4384\n");
776 * Register 0x02: Mode Control 1
777 * Control Port Enable, PCM, All DACs enabled, Power Up
781 ret = i2c_master_send(client, send, 2);
783 snd_printk(KERN_ERR "Failed to power up CS4384\n");
788 * Make sure the changes took place, this helps verify we are talking to
791 send[0] = 0x80 | 0x03;
792 ret = i2c_master_send(client, send, 1);
794 snd_printk(KERN_ERR "Failed to initiate readback\n");
798 ret = i2c_master_recv(client, recv, 1);
800 snd_printk(KERN_ERR "Failed second read of CS4384 registers\n");
804 if (recv[0] != 0x13) {
805 snd_printk(KERN_ERR "Failed to initialize CS4384 DAC\n");
809 snd_printk(KERN_INFO "CS4384 DAC Initialized\n");
817 * snd_ubi32_cs4384_i2c_probe
819 static int snd_ubi32_cs4384_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
821 struct snd_card *card;
822 struct ubi32_snd_priv *ubi32_priv;
824 struct platform_device *pdev;
825 struct ubi32_cs4384_platform_data *pdata;
826 struct snd_ubi32_cs4384_priv *cs4384_priv;
829 * pdev is audio device
831 pdev = client->dev.platform_data;
837 * pdev->dev.platform_data is ubi32-pcm platform_data
839 pdata = audio_device_priv(pdev);
845 * Initialize the CS4384 DAC
847 ret = snd_ubi32_cs4384_dac_init(client, id);
850 * Initialization failed. Propagate the error.
855 if (snd_ubi32_cs4384_setup_mclk(pdata)) {
860 * Create a snd_card structure
862 card = snd_card_new(index, "Ubi32-CS4384", THIS_MODULE, sizeof(struct ubi32_snd_priv));
867 card->private_free = snd_ubi32_cs4384_free;
868 ubi32_priv = card->private_data;
871 * Initialize the snd_card's private data structure
873 ubi32_priv->card = card;
874 ubi32_priv->client = client;
875 ubi32_priv->set_channels = snd_ubi32_cs4384_set_channels;
876 ubi32_priv->set_rate = snd_ubi32_cs4384_set_rate;
879 * CS4384 DAC has a minimum sample rate of 4khz and an
880 * upper limit of 216khz for it's auto-detect.
882 ubi32_priv->min_sample_rate = 4000;
883 ubi32_priv->max_sample_rate = 216000;
886 * Create our private data (to manage volume, etc)
888 cs4384_priv = kzalloc(sizeof(struct snd_ubi32_cs4384_priv), GFP_KERNEL);
893 snd_ubi32_priv_set_drv(ubi32_priv, cs4384_priv);
894 spin_lock_init(&cs4384_priv->lock);
897 * We start off all muted and max volume
899 cs4384_priv->mute = 0xFF;
900 memset(cs4384_priv->volume, 0xFF, 8);
903 * Create the new PCM instance
905 err = snd_ubi32_pcm_probe(ubi32_priv, pdev);
908 return err; /* What is err? Need to include correct file */
911 strcpy(card->driver, "Ubi32-CS4384");
912 strcpy(card->shortname, "Ubi32-CS4384");
913 snprintf(card->longname, sizeof(card->longname),
914 "%s at sendirq=%d.%d recvirq=%d.%d regs=%p",
915 card->shortname, ubi32_priv->tx_irq, ubi32_priv->irq_idx,
916 ubi32_priv->rx_irq, ubi32_priv->irq_idx, ubi32_priv->adr);
918 snd_card_set_dev(card, &client->dev);
923 snd_ubi32_cs4384_mixer(ubi32_priv);
926 * Register the sound card
928 if ((err = snd_card_register(card)) != 0) {
929 snd_printk(KERN_INFO "snd_card_register error\n");
933 * Store card for access from other methods
935 i2c_set_clientdata(client, card);
941 * snd_ubi32_cs4384_i2c_remove
943 static int __devexit snd_ubi32_cs4384_i2c_remove(struct i2c_client *client)
945 struct snd_card *card;
946 struct ubi32_snd_priv *ubi32_priv;
948 card = i2c_get_clientdata(client);
950 ubi32_priv = card->private_data;
951 snd_ubi32_pcm_remove(ubi32_priv);
953 snd_card_free(i2c_get_clientdata(client));
954 i2c_set_clientdata(client, NULL);
960 * I2C driver description
962 static struct i2c_driver snd_ubi32_cs4384_driver = {
965 .owner = THIS_MODULE,
967 .id_table = snd_ubi32_cs4384_id,
968 .probe = snd_ubi32_cs4384_i2c_probe,
969 .remove = __devexit_p(snd_ubi32_cs4384_i2c_remove),
975 static int __init snd_ubi32_cs4384_init(void)
977 return i2c_add_driver(&snd_ubi32_cs4384_driver);
979 module_init(snd_ubi32_cs4384_init);
982 * snd_ubi32_cs4384_exit
984 static void __exit snd_ubi32_cs4384_exit(void)
986 i2c_del_driver(&snd_ubi32_cs4384_driver);
988 module_exit(snd_ubi32_cs4384_exit);
993 MODULE_ALIAS("i2c:" DRIVER_NAME);
994 MODULE_AUTHOR("Patrick Tjin");
995 MODULE_DESCRIPTION("Driver for Ubicom32 audio devices CS4384");
996 MODULE_LICENSE("GPL");