Commit 0948e3c8 authored by Takashi Iwai's avatar Takashi Iwai Committed by Jaroslav Kysela

[ALSA] Clean up sa11xx-uda1341 driver

Modules: SA11xx UDA1341 driver,L3 drivers,UDA1341

Clean up sa11xx-uda1341 driver:

- Fix buggy destructor
- Remove the global variable
- Move array definitions from uda1341.h
- Make functions in uda1341.c static
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent c8714ba1
......@@ -15,7 +15,7 @@
* features support
*/
/* $Id: uda1341.h,v 1.6 2004/05/03 17:36:50 tiwai Exp $ */
/* $Id: uda1341.h,v 1.7 2005/11/17 10:25:22 tiwai Exp $ */
#define UDA1341_ALSA_NAME "snd-uda1341"
......@@ -37,11 +37,6 @@ enum uda1341_onoff {
ON,
};
const char *onoff_names[] = {
"Off",
"On",
};
enum uda1341_format {
I2S=0,
LSB16,
......@@ -53,17 +48,6 @@ enum uda1341_format {
LSB20MSB,
};
const char *format_names[] = {
"I2S-bus",
"LSB 16bits",
"LSB 18bits",
"LSB 20bits",
"MSB",
"in LSB 16bits/out MSB",
"in LSB 18bits/out MSB",
"in LSB 20bits/out MSB",
};
enum uda1341_fs {
F512=0,
F384,
......@@ -71,23 +55,11 @@ enum uda1341_fs {
Funused,
};
const char *fs_names[] = {
"512*fs",
"384*fs",
"256*fs",
"Unused - bad value!",
};
enum uda1341_peak {
BEFORE=0,
AFTER,
};
const char *peak_names[] = {
"before",
"after",
};
enum uda1341_filter {
FLAT=0,
MIN,
......@@ -95,24 +67,6 @@ enum uda1341_filter {
MAX,
};
const char *filter_names[] = {
"flat",
"min",
"min",
"max",
};
const char*bass_values[][16] = {
{"0 dB", "0 dB", "0 dB", "0 dB", "0 dB", "0 dB", "0 dB", "0 dB", "0 dB", "0 dB", "0 dB",
"0 dB", "0 dB", "0 dB", "0 dB", "undefined", }, //flat
{"0 dB", "2 dB", "4 dB", "6 dB", "8 dB", "10 dB", "12 dB", "14 dB", "16 dB", "18 dB", "18 dB",
"18 dB", "18 dB", "18 dB", "18 dB", "undefined",}, // min
{"0 dB", "2 dB", "4 dB", "6 dB", "8 dB", "10 dB", "12 dB", "14 dB", "16 dB", "18 dB", "18 dB",
"18 dB", "18 dB", "18 dB", "18 dB", "undefined",}, // min
{"0 dB", "2 dB", "4 dB", "6 dB", "8 dB", "10 dB", "12 dB", "14 dB", "16 dB", "18 dB", "20 dB",
"22 dB", "24 dB", "24 dB", "24 dB", "undefined",}, // max
};
enum uda1341_mixer {
DOUBLE,
LINE,
......@@ -120,13 +74,6 @@ enum uda1341_mixer {
MIXER,
};
const char *mixer_names[] = {
"double differential",
"input channel 1 (line in)",
"input channel 2 (microphone)",
"digital mixer",
};
enum uda1341_deemp {
NONE,
D32,
......@@ -134,58 +81,6 @@ enum uda1341_deemp {
D48,
};
const char *deemp_names[] = {
"none",
"32 kHz",
"44.1 kHz",
"48 kHz",
};
const char *mic_sens_value[] = {
"-3 dB", "0 dB", "3 dB", "9 dB", "15 dB", "21 dB", "27 dB", "not used",
};
const unsigned short AGC_atime[] = {
11, 16, 11, 16, 21, 11, 16, 21,
};
const unsigned short AGC_dtime[] = {
100, 100, 200, 200, 200, 400, 400, 400,
};
const char *AGC_level[] = {
"-9.0", "-11.5", "-15.0", "-17.5",
};
const char *ig_small_value[] = {
"-3.0", "-2.5", "-2.0", "-1.5", "-1.0", "-0.5",
};
/*
* this was computed as peak_value[i] = pow((63-i)*1.42,1.013)
*
* UDA1341 datasheet on page 21: Peak value (dB) = (Peak level - 63.5)*5*log2
* There is an table with these values [level]=value: [3]=-90.31, [7]=-84.29
* [61]=-2.78, [62] = -1.48, [63] = 0.0
* I tried to compute it, but using but even using logarithm with base either 10 or 2
* i was'n able to get values in the table from the formula. So I constructed another
* formula (see above) to interpolate the values as good as possible. If there is some
* mistake, please contact me on tomas.kasparek@seznam.cz. Thanks.
* UDA1341TS datasheet is available at:
* http://www-us9.semiconductors.com/acrobat/datasheets/UDA1341TS_3.pdf
*/
const char *peak_value[] = {
"-INF dB", "N.A.", "N.A", "90.31 dB", "N.A.", "N.A.", "N.A.", "-84.29 dB",
"-82.65 dB", "-81.13 dB", "-79.61 dB", "-78.09 dB", "-76.57 dB", "-75.05 dB", "-73.53 dB",
"-72.01 dB", "-70.49 dB", "-68.97 dB", "-67.45 dB", "-65.93 dB", "-64.41 dB", "-62.90 dB",
"-61.38 dB", "-59.86 dB", "-58.35 dB", "-56.83 dB", "-55.32 dB", "-53.80 dB", "-52.29 dB",
"-50.78 dB", "-49.26 dB", "-47.75 dB", "-46.24 dB", "-44.73 dB", "-43.22 dB", "-41.71 dB",
"-40.20 dB", "-38.69 dB", "-37.19 dB", "-35.68 dB", "-34.17 dB", "-32.67 dB", "-31.17 dB",
"-29.66 dB", "-28.16 dB", "-26.66 dB", "-25.16 dB", "-23.66 dB", "-22.16 dB", "-20.67 dB",
"-19.17 dB", "-17.68 dB", "-16.19 dB", "-14.70 dB", "-13.21 dB", "-11.72 dB", "-10.24 dB",
"-8.76 dB", "-7.28 dB", "-5.81 dB", "-4.34 dB", "-2.88 dB", "-1.43 dB", "0.00 dB",
};
enum uda1341_config {
CMD_READ_REG = 0,
CMD_RESET,
......
......@@ -21,7 +21,7 @@
* merged HAL layer (patches from Brian)
*/
/* $Id: sa11xx-uda1341.c,v 1.23 2005/09/09 13:22:34 tiwai Exp $ */
/* $Id: sa11xx-uda1341.c,v 1.24 2005/11/17 10:25:22 tiwai Exp $ */
/***************************************************************************************************
*
......@@ -141,8 +141,6 @@ typedef struct snd_card_sa11xx_uda1341 {
audio_stream_t s[2]; /* playback & capture */
} sa11xx_uda1341_t;
static struct snd_card_sa11xx_uda1341 *sa11xx_uda1341 = NULL;
static unsigned int rates[] = {
8000, 10666, 10985, 14647,
16000, 21970, 22050, 24000,
......@@ -411,8 +409,8 @@ static int audio_dma_request(audio_stream_t *s, void (*callback)(void *))
static void audio_dma_free(audio_stream_t *s)
{
sa1100_free_dma((s)->dma_regs);
(s)->dma_regs = 0;
sa1100_free_dma(s->dma_regs);
s->dma_regs = 0;
}
#endif
......@@ -835,8 +833,8 @@ static int __init snd_card_sa11xx_uda1341_pcm(sa11xx_uda1341_t *sa11xx_uda1341,
* isa works but I'm not sure why (or if) it's the right choice
* this may be too large, trying it for now
*/
snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_ISA,
snd_pcm_dma_flags(0),
snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
snd_dma_isa_data(),
64*1024, 64*1024);
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_card_sa11xx_uda1341_playback_ops);
......@@ -900,15 +898,15 @@ void snd_sa11xx_uda1341_free(snd_card_t *card)
audio_dma_free(&chip->s[SNDRV_PCM_STREAM_PLAYBACK]);
audio_dma_free(&chip->s[SNDRV_PCM_STREAM_CAPTURE]);
sa11xx_uda1341 = NULL;
card->private_data = NULL;
kfree(chip);
}
static snd_card_t *sa11xx_uda1341_card;
static int __init sa11xx_uda1341_init(void)
{
int err;
snd_card_t *card;
sa11xx_uda1341_t *chip;
if (!machine_is_h3xxx())
return -ENODEV;
......@@ -921,26 +919,25 @@ static int __init sa11xx_uda1341_init(void)
sa11xx_uda1341 = kzalloc(sizeof(*sa11xx_uda1341), GFP_KERNEL);
if (sa11xx_uda1341 == NULL)
return -ENOMEM;
card->private_free = snd_sa11xx_uda1341_free;
chip = card->private_data;
spin_lock_init(&chip->s[0].dma_lock);
spin_lock_init(&chip->s[1].dma_lock);
card->private_data = (void *)sa11xx_uda1341;
card->private_free = snd_sa11xx_uda1341_free;
sa11xx_uda1341->card = card;
sa11xx_uda1341->samplerate = AUDIO_RATE_DEFAULT;
chip->card = card;
chip->samplerate = AUDIO_RATE_DEFAULT;
// mixer
if ((err = snd_chip_uda1341_mixer_new(sa11xx_uda1341->card, &sa11xx_uda1341->uda1341)))
if ((err = snd_chip_uda1341_mixer_new(chip->card, &sa11xx_uda1341->uda1341)))
goto nodev;
// PCM
if ((err = snd_card_sa11xx_uda1341_pcm(sa11xx_uda1341, 0)) < 0)
if ((err = snd_card_sa11xx_uda1341_pcm(chip, 0)) < 0)
goto nodev;
snd_card_set_generic_pm_callback(card,
snd_sa11xx_uda1341_suspend, snd_sa11_uda1341_resume,
sa11xx_uda1341);
chip);
strcpy(card->driver, "UDA1341");
strcpy(card->shortname, "H3600 UDA1341TS");
......@@ -951,6 +948,7 @@ static int __init sa11xx_uda1341_init(void)
if ((err = snd_card_register(card)) == 0) {
printk( KERN_INFO "iPAQ audio support initialized\n" );
sa11xx_uda1341_card = card;
return 0;
}
......@@ -961,7 +959,7 @@ static int __init sa11xx_uda1341_init(void)
static void __exit sa11xx_uda1341_exit(void)
{
snd_card_free(sa11xx_uda1341->card);
snd_card_free(sa11xx_uda1341_card);
}
module_init(sa11xx_uda1341_init);
......
......@@ -17,7 +17,7 @@
* 2002-05-12 Tomas Kasparek another code cleanup
*/
/* $Id: uda1341.c,v 1.16 2005/09/09 13:22:34 tiwai Exp $ */
/* $Id: uda1341.c,v 1.17 2005/11/17 10:25:22 tiwai Exp $ */
#include <sound/driver.h>
#include <linux/module.h>
......@@ -56,6 +56,33 @@
/* }}} */
static const char *peak_names[] = {
"before",
"after",
};
static const char *filter_names[] = {
"flat",
"min",
"min",
"max",
};
static const char *mixer_names[] = {
"double differential",
"input channel 1 (line in)",
"input channel 2 (microphone)",
"digital mixer",
};
static const char *deemp_names[] = {
"none",
"32 kHz",
"44.1 kHz",
"48 kHz",
};
enum uda1341_regs_names {
stat0,
stat1,
......@@ -73,7 +100,7 @@ enum uda1341_regs_names {
uda1341_reg_last,
};
const char *uda1341_reg_names[] = {
static const char *uda1341_reg_names[] = {
"stat 0 ",
"stat 1 ",
"data 00",
......@@ -89,7 +116,7 @@ const char *uda1341_reg_names[] = {
"ext 6",
};
const int uda1341_enum_items[] = {
static const int uda1341_enum_items[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2, //peak - before/after
4, //deemp - none/32/44.1/48
......@@ -100,7 +127,7 @@ const int uda1341_enum_items[] = {
0, 0, 0, 0, 0,
};
const char ** uda1341_enum_names[] = {
static const char ** uda1341_enum_names[] = {
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
peak_names, //peak - before/after
deemp_names, //deemp - none/32/44.1/48
......@@ -129,11 +156,9 @@ struct uda1341 {
#endif
};
//hack for ALSA magic casting
typedef struct l3_client l3_client_t;
/* transfer 8bit integer into string with binary representation */
void int2str_bin8(uint8_t val, char *buf){
static void int2str_bin8(uint8_t val, char *buf)
{
const int size = sizeof(val) * 8;
int i;
......@@ -146,7 +171,7 @@ void int2str_bin8(uint8_t val, char *buf){
/* {{{ HW manipulation routines */
int snd_uda1341_codec_write(struct l3_client *clnt, unsigned short reg, unsigned short val)
static int snd_uda1341_codec_write(struct l3_client *clnt, unsigned short reg, unsigned short val)
{
struct uda1341 *uda = clnt->driver_data;
unsigned char buf[2] = { 0xc0, 0xe0 }; // for EXT addressing
......@@ -171,7 +196,7 @@ int snd_uda1341_codec_write(struct l3_client *clnt, unsigned short reg, unsigned
return err;
}
int snd_uda1341_codec_read(struct l3_client *clnt, unsigned short reg)
static int snd_uda1341_codec_read(struct l3_client *clnt, unsigned short reg)
{
unsigned char val;
int err;
......@@ -188,8 +213,9 @@ static inline int snd_uda1341_valid_reg(struct l3_client *clnt, unsigned short r
return reg < uda1341_reg_last;
}
int snd_uda1341_update_bits(struct l3_client *clnt, unsigned short reg, unsigned short mask,
unsigned short shift, unsigned short value, int flush)
static int snd_uda1341_update_bits(struct l3_client *clnt, unsigned short reg,
unsigned short mask, unsigned short shift,
unsigned short value, int flush)
{
int change;
unsigned short old, new;
......@@ -214,7 +240,7 @@ int snd_uda1341_update_bits(struct l3_client *clnt, unsigned short reg, unsigned
return change;
}
int snd_uda1341_cfg_write(struct l3_client *clnt, unsigned short what,
static int snd_uda1341_cfg_write(struct l3_client *clnt, unsigned short what,
unsigned short value, int flush)
{
struct uda1341 *uda = clnt->driver_data;
......@@ -327,6 +353,81 @@ int snd_uda1341_cfg_write(struct l3_client *clnt, unsigned short what,
/* }}} */
/* {{{ Proc interface */
#ifdef CONFIG_PROC_FS
static const char *format_names[] = {
"I2S-bus",
"LSB 16bits",
"LSB 18bits",
"LSB 20bits",
"MSB",
"in LSB 16bits/out MSB",
"in LSB 18bits/out MSB",
"in LSB 20bits/out MSB",
};
static const char *fs_names[] = {
"512*fs",
"384*fs",
"256*fs",
"Unused - bad value!",
};
static const char* bass_values[][16] = {
{"0 dB", "0 dB", "0 dB", "0 dB", "0 dB", "0 dB", "0 dB", "0 dB", "0 dB", "0 dB", "0 dB",
"0 dB", "0 dB", "0 dB", "0 dB", "undefined", }, //flat
{"0 dB", "2 dB", "4 dB", "6 dB", "8 dB", "10 dB", "12 dB", "14 dB", "16 dB", "18 dB", "18 dB",
"18 dB", "18 dB", "18 dB", "18 dB", "undefined",}, // min
{"0 dB", "2 dB", "4 dB", "6 dB", "8 dB", "10 dB", "12 dB", "14 dB", "16 dB", "18 dB", "18 dB",
"18 dB", "18 dB", "18 dB", "18 dB", "undefined",}, // min
{"0 dB", "2 dB", "4 dB", "6 dB", "8 dB", "10 dB", "12 dB", "14 dB", "16 dB", "18 dB", "20 dB",
"22 dB", "24 dB", "24 dB", "24 dB", "undefined",}, // max
};
static const char *mic_sens_value[] = {
"-3 dB", "0 dB", "3 dB", "9 dB", "15 dB", "21 dB", "27 dB", "not used",
};
static const unsigned short AGC_atime[] = {
11, 16, 11, 16, 21, 11, 16, 21,
};
static const unsigned short AGC_dtime[] = {
100, 100, 200, 200, 200, 400, 400, 400,
};
static const char *AGC_level[] = {
"-9.0", "-11.5", "-15.0", "-17.5",
};
static const char *ig_small_value[] = {
"-3.0", "-2.5", "-2.0", "-1.5", "-1.0", "-0.5",
};
/*
* this was computed as peak_value[i] = pow((63-i)*1.42,1.013)
*
* UDA1341 datasheet on page 21: Peak value (dB) = (Peak level - 63.5)*5*log2
* There is an table with these values [level]=value: [3]=-90.31, [7]=-84.29
* [61]=-2.78, [62] = -1.48, [63] = 0.0
* I tried to compute it, but using but even using logarithm with base either 10 or 2
* i was'n able to get values in the table from the formula. So I constructed another
* formula (see above) to interpolate the values as good as possible. If there is some
* mistake, please contact me on tomas.kasparek@seznam.cz. Thanks.
* UDA1341TS datasheet is available at:
* http://www-us9.semiconductors.com/acrobat/datasheets/UDA1341TS_3.pdf
*/
static const char *peak_value[] = {
"-INF dB", "N.A.", "N.A", "90.31 dB", "N.A.", "N.A.", "N.A.", "-84.29 dB",
"-82.65 dB", "-81.13 dB", "-79.61 dB", "-78.09 dB", "-76.57 dB", "-75.05 dB", "-73.53 dB",
"-72.01 dB", "-70.49 dB", "-68.97 dB", "-67.45 dB", "-65.93 dB", "-64.41 dB", "-62.90 dB",
"-61.38 dB", "-59.86 dB", "-58.35 dB", "-56.83 dB", "-55.32 dB", "-53.80 dB", "-52.29 dB",
"-50.78 dB", "-49.26 dB", "-47.75 dB", "-46.24 dB", "-44.73 dB", "-43.22 dB", "-41.71 dB",
"-40.20 dB", "-38.69 dB", "-37.19 dB", "-35.68 dB", "-34.17 dB", "-32.67 dB", "-31.17 dB",
"-29.66 dB", "-28.16 dB", "-26.66 dB", "-25.16 dB", "-23.66 dB", "-22.16 dB", "-20.67 dB",
"-19.17 dB", "-17.68 dB", "-16.19 dB", "-14.70 dB", "-13.21 dB", "-11.72 dB", "-10.24 dB",
"-8.76 dB", "-7.28 dB", "-5.81 dB", "-4.34 dB", "-2.88 dB", "-1.43 dB", "0.00 dB",
};
static void snd_uda1341_proc_read(snd_info_entry_t *entry,
snd_info_buffer_t * buffer)
......@@ -401,7 +502,6 @@ static void snd_uda1341_proc_regs_read(snd_info_entry_t *entry,
int reg;
char buf[12];
spin_lock(&uda->reg_lock);
for (reg = 0; reg < uda1341_reg_last; reg ++) {
if (reg == empty)
continue;
......@@ -411,9 +511,8 @@ static void snd_uda1341_proc_regs_read(snd_info_entry_t *entry,
int2str_bin8(snd_uda1341_codec_read(clnt, UDA1341_DATA1), buf);
snd_iprintf(buffer, "DATA1 = %s\n", buf);
spin_unlock(&uda->reg_lock);
}
#endif /* CONFIG_PROC_FS */
static void __devinit snd_uda1341_proc_init(snd_card_t *card, struct l3_client *clnt)
{
......@@ -647,10 +746,10 @@ static snd_kcontrol_new_t snd_uda1341_controls[] = {
UDA1341_2REGS("Gain Input Amplifier Gain (channel 2)", CMD_IG, ext4, ext5, 0, 0, 3, 31, 0),
};
static void uda1341_free(struct l3_client *uda1341)
static void uda1341_free(struct l3_client *clnt)
{
l3_detach_client(uda1341); // calls kfree for driver_data (uda1341_t)
kfree(uda1341);
l3_detach_client(clnt); // calls kfree for driver_data (uda1341_t)
kfree(clnt);
}
static int uda1341_dev_free(snd_device_t *device)
......@@ -660,41 +759,42 @@ static int uda1341_dev_free(snd_device_t *device)
return 0;
}
int __init snd_chip_uda1341_mixer_new(snd_card_t *card, struct l3_client **clnt)
int __init snd_chip_uda1341_mixer_new(snd_card_t *card, struct l3_client **clntp)
{
static snd_device_ops_t ops = {
.dev_free = uda1341_dev_free,
};
struct l3_client *uda1341;
struct l3_client *clnt;
int idx, err;
snd_assert(card != NULL, return -EINVAL);
uda1341 = kzalloc(sizeof(*uda1341), GFP_KERNEL);
if (uda1341 == NULL)
clnt = kzalloc(sizeof(*clnt), GFP_KERNEL);
if (clnt == NULL)
return -ENOMEM;
if ((err = l3_attach_client(uda1341, "l3-bit-sa1100-gpio", "snd-uda1341"))) {
kfree(uda1341);
if ((err = l3_attach_client(clnt, "l3-bit-sa1100-gpio", UDA1341_ALSA_NAME))) {
kfree(clnt);
return err;
}
if ((err = snd_device_new(card, SNDRV_DEV_CODEC, uda1341, &ops)) < 0) {
l3_detach_client(uda1341);
kfree(uda1341);
for (idx = 0; idx < ARRAY_SIZE(snd_uda1341_controls); idx++) {
if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_uda1341_controls[idx], clnt))) < 0) {
uda1341_free(clnt);
return err;
}
}
for (idx = 0; idx < ARRAY_SIZE(snd_uda1341_controls); idx++) {
if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_uda1341_controls[idx], uda1341))) < 0)
if ((err = snd_device_new(card, SNDRV_DEV_CODEC, clnt, &ops)) < 0) {
uda1341_free(clnt);
return err;
}
*clnt = uda1341;
*clntp = clnt;
strcpy(card->mixername, "UDA1341TS Mixer");
((uda1341_t *)uda1341->driver_data)->card = card;
snd_uda1341_proc_init(card, uda1341);
snd_uda1341_proc_init(card, clnt);
return 0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment