/*
* Philips UDA1341 mixer device driver
* Copyright (c) 2002 Tomas Kasparek <tomas.kasparek@seznam.cz>
*
* Portions are Copyright (C) 2000 Lernout & Hauspie Speech Products, N.V.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License.
*
* History:
*
* 2002-03-13 Tomas Kasparek initial release - based on uda1341.c from OSS
* 2002-03-28 Tomas Kasparek basic mixer is working (volume, bass, treble)
* 2002-03-30 Tomas Kasparek proc filesystem support, complete mixer and DSP
* features support
* 2002-04-12 Tomas Kasparek proc interface update, code cleanup
* 2002-05-12 Tomas Kasparek another code cleanup
*/
/* $Id: uda1341.c,v 1.18 2005/11/17 14:17:21 tiwai Exp $ */
#include <sound/driver.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/slab.h>
#include <linux/errno.h>
#include <linux/ioctl.h>
#include <asm/uaccess.h>
#include <sound/core.h>
#include <sound/control.h>
#include <sound/initval.h>
#include <sound/info.h>
#include <linux/l3/l3.h>
#include <sound/uda1341.h>
/* {{{ HW regs definition */
#define STAT0 0x00
#define STAT1 0x80
#define STAT_MASK 0x80
#define DATA0_0 0x00
#define DATA0_1 0x40
#define DATA0_2 0x80
#define DATA_MASK 0xc0
#define IS_DATA0(x) ((x) >= data0_0 && (x) <= data0_2)
#define IS_DATA1(x) ((x) == data1)
#define IS_STATUS(x) ((x) == stat0 || (x) == stat1)
#define IS_EXTEND(x) ((x) >= ext0 && (x) <= ext6)
/* }}} */
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,
data0_0,
data0_1,
data0_2,
data1,
ext0,
ext1,
ext2,
empty,
ext4,
ext5,
ext6,
uda1341_reg_last,
};
static const char *uda1341_reg_names[] = {
"stat 0 ",
"stat 1 ",
"data 00",
"data 01",
"data 02",
"data 1 ",
"ext 0",
"ext 1",
"ext 2",
"empty",
"ext 4",
"ext 5",
"ext 6",
};
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
0,
4, //filter - flat/min/min/max
0, 0, 0,
4, //mixer - differ/line/mic/mixer
0, 0, 0, 0, 0,
};
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
NULL,
filter_names, //filter - flat/min/min/max
NULL, NULL, NULL,
mixer_names, //mixer - differ/line/mic/mixer
NULL, NULL, NULL, NULL, NULL,
};
typedef int uda1341_cfg[CMD_LAST];
struct uda1341 {
int (*write) (struct l3_client *uda1341, unsigned short reg, unsigned short val);
int (*read) (struct l3_client *uda1341, unsigned short reg);
unsigned char regs[uda1341_reg_last];
int active;
spinlock_t reg_lock;
struct snd_card *card;
uda1341_cfg cfg;
#ifdef CONFIG_PM
unsigned char suspend_regs[uda1341_reg_last];
uda1341_cfg suspend_cfg;
#endif
};
/* transfer 8bit integer into string with binary representation */
static void int2str_bin8(uint8_t val, char *buf)
{
const int size = sizeof(val) * 8;
int i;
for (i= 0; i < size; i++){
*(buf++) = (val >> (size - 1)) ? '1' : '0';
val <<= 1;
}
*buf = '\0'; //end the string with zero
}
/* {{{ HW manipulation routines */
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
int err = 0;
uda->regs[reg] = val;
if (uda->active) {
if (IS_DATA0(reg)) {
err = l3_write(clnt, UDA1341_DATA0, (const unsigned char *)&val, 1);
} else if (IS_DATA1(reg)) {
err = l3_write(clnt, UDA1341_DATA1, (const unsigned char *)&val, 1);
} else if (IS_STATUS(reg)) {
err = l3_write(clnt, UDA1341_S