summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornetchild <netchild@FreeBSD.org>2006-09-30 16:53:40 +0000
committernetchild <netchild@FreeBSD.org>2006-09-30 16:53:40 +0000
commitcefdaf86ea45ac47cf66fce3708a523aa82d705b (patch)
tree192500081d9d238b405dc5e8d1da154e4c5fbf41
parent1358d3f1ae9e1f9fc95d63f0f7cfb9d8339aff33 (diff)
downloadFreeBSD-src-cefdaf86ea45ac47cf66fce3708a523aa82d705b.zip
FreeBSD-src-cefdaf86ea45ac47cf66fce3708a523aa82d705b.tar.gz
After repo copy from ak452x.[ch]: SPIcds is the I2S SPI audio codec code
used by the Envy* drivers. Submitted by: "Konstantin Dimitrov" <kosio.dimitrov@gmail.com>
-rw-r--r--sys/dev/sound/pci/spicds.c213
-rw-r--r--sys/dev/sound/pci/spicds.h51
2 files changed, 192 insertions, 72 deletions
diff --git a/sys/dev/sound/pci/spicds.c b/sys/dev/sound/pci/spicds.c
index feb550e..e9b29f1 100644
--- a/sys/dev/sound/pci/spicds.c
+++ b/sys/dev/sound/pci/spicds.c
@@ -1,4 +1,5 @@
/*
+ * Copyright (c) 2006 Konstantin Dimitrov <kosio.dimitrov@gmail.com>
* Copyright (c) 2001 Katsurajima Naoto <raven@katsurajima.seya.yokohama.jp>
* All rights reserved.
*
@@ -28,14 +29,14 @@
#include <dev/sound/pcm/sound.h>
-#include <dev/sound/pci/ak452x.h>
+#include <dev/sound/pci/spicds.h>
-MALLOC_DEFINE(M_AK452X, "ak452x", "ak452x codec");
+MALLOC_DEFINE(M_SPICDS, "spicds", "SPI codec");
-#define AK452X_NAMELEN 16
-struct ak452x_info {
+#define SPICDS_NAMELEN 16
+struct spicds_info {
device_t dev;
- ak452x_ctrl ctrl;
+ spicds_ctrl ctrl;
void *devinfo;
int num; /* number of this device */
unsigned int type; /* codec type */
@@ -43,12 +44,12 @@ struct ak452x_info {
unsigned int format; /* data format and master clock frequency */
unsigned int dvc; /* De-emphasis and Volume Control */
unsigned int left, right;
- char name[AK452X_NAMELEN];
+ char name[SPICDS_NAMELEN];
void *lock;
};
static void
-ak452x_wrbit(struct ak452x_info *codec, int bit)
+spicds_wrbit(struct spicds_info *codec, int bit)
{
unsigned int cs, cdti;
if (codec->cif)
@@ -68,12 +69,12 @@ ak452x_wrbit(struct ak452x_info *codec, int bit)
}
static void
-ak452x_wrcd(struct ak452x_info *codec, int reg, u_int8_t val)
+spicds_wrcd(struct spicds_info *codec, int reg, u_int16_t val)
{
int mask;
#if(0)
- device_printf(codec->dev, "ak452x_wrcd(codec, 0x%02x, 0x%02x)\n", reg, val);
+ device_printf(codec->dev, "spicds_wrcd(codec, 0x%02x, 0x%02x)\n", reg, val);
#endif
/* start */
if (codec->cif)
@@ -81,19 +82,38 @@ ak452x_wrcd(struct ak452x_info *codec, int reg, u_int8_t val)
else
codec->ctrl(codec->devinfo, 0, 1, 0);
DELAY(1);
+ if (codec->type != SPICDS_TYPE_WM8770) {
+ if (codec->type == SPICDS_TYPE_AK4381) {
+ /* AK4381 chip address */
+ spicds_wrbit(codec, 0);
+ spicds_wrbit(codec, 1);
+ }
+ else {
/* chip address */
- ak452x_wrbit(codec, 1);
- ak452x_wrbit(codec, 0);
+ spicds_wrbit(codec, 1);
+ spicds_wrbit(codec, 0);
+ }
/* write */
- ak452x_wrbit(codec, 1);
+ spicds_wrbit(codec, 1);
/* register address */
for (mask = 0x10; mask != 0; mask >>= 1)
- ak452x_wrbit(codec, reg & mask);
+ spicds_wrbit(codec, reg & mask);
/* data */
for (mask = 0x80; mask != 0; mask >>= 1)
- ak452x_wrbit(codec, val & mask);
+ spicds_wrbit(codec, val & mask);
/* stop */
DELAY(1);
+ }
+ else {
+ /* register address */
+ for (mask = 0x40; mask != 0; mask >>= 1)
+ spicds_wrbit(codec, reg & mask);
+ /* data */
+ for (mask = 0x100; mask != 0; mask >>= 1)
+ spicds_wrbit(codec, val & mask);
+ /* stop */
+ DELAY(1);
+ }
if (codec->cif) {
codec->ctrl(codec->devinfo, 0, 1, 0);
DELAY(1);
@@ -106,25 +126,25 @@ ak452x_wrcd(struct ak452x_info *codec, int reg, u_int8_t val)
return;
}
-struct ak452x_info *
-ak452x_create(device_t dev, void *devinfo, int num, ak452x_ctrl ctrl)
+struct spicds_info *
+spicds_create(device_t dev, void *devinfo, int num, spicds_ctrl ctrl)
{
- struct ak452x_info *codec;
+ struct spicds_info *codec;
#if(0)
- device_printf(dev, "ak452x_create(dev, devinfo, %d, ctrl)\n", num);
+ device_printf(dev, "spicds_create(dev, devinfo, %d, ctrl)\n", num);
#endif
- codec = (struct ak452x_info *)malloc(sizeof *codec, M_AK452X, M_NOWAIT);
+ codec = (struct spicds_info *)malloc(sizeof *codec, M_SPICDS, M_NOWAIT);
if (codec == NULL)
return NULL;
- snprintf(codec->name, AK452X_NAMELEN, "%s:ak452x%d", device_get_nameunit(dev), num);
+ snprintf(codec->name, SPICDS_NAMELEN, "%s:spicds%d", device_get_nameunit(dev), num);
codec->lock = snd_mtxcreate(codec->name, codec->name);
codec->dev = dev;
codec->ctrl = ctrl;
codec->devinfo = devinfo;
codec->num = num;
- codec->type = AK452X_TYPE_4524;
+ codec->type = SPICDS_TYPE_AK4524;
codec->cif = 0;
codec->format = AK452X_FORMAT_I2S | AK452X_FORMAT_256FSN | AK452X_FORMAT_1X;
codec->dvc = AK452X_DVC_DEMOFF | AK452X_DVC_ZTM1024 | AK452X_DVC_ZCE;
@@ -133,14 +153,14 @@ ak452x_create(device_t dev, void *devinfo, int num, ak452x_ctrl ctrl)
}
void
-ak452x_destroy(struct ak452x_info *codec)
+spicds_destroy(struct spicds_info *codec)
{
snd_mtxfree(codec->lock);
- free(codec, M_AK452X);
+ free(codec, M_SPICDS);
}
void
-ak452x_settype(struct ak452x_info *codec, unsigned int type)
+spicds_settype(struct spicds_info *codec, unsigned int type)
{
snd_mtxlock(codec->lock);
codec->type = type;
@@ -148,7 +168,7 @@ ak452x_settype(struct ak452x_info *codec, unsigned int type)
}
void
-ak452x_setcif(struct ak452x_info *codec, unsigned int cif)
+spicds_setcif(struct spicds_info *codec, unsigned int cif)
{
snd_mtxlock(codec->lock);
codec->cif = cif;
@@ -156,7 +176,7 @@ ak452x_setcif(struct ak452x_info *codec, unsigned int cif)
}
void
-ak452x_setformat(struct ak452x_info *codec, unsigned int format)
+spicds_setformat(struct spicds_info *codec, unsigned int format)
{
snd_mtxlock(codec->lock);
codec->format = format;
@@ -164,7 +184,7 @@ ak452x_setformat(struct ak452x_info *codec, unsigned int format)
}
void
-ak452x_setdvc(struct ak452x_info *codec, unsigned int dvc)
+spicds_setdvc(struct spicds_info *codec, unsigned int dvc)
{
snd_mtxlock(codec->lock);
codec->dvc = dvc;
@@ -172,76 +192,151 @@ ak452x_setdvc(struct ak452x_info *codec, unsigned int dvc)
}
void
-ak452x_init(struct ak452x_info *codec)
+spicds_init(struct spicds_info *codec)
{
#if(0)
- device_printf(codec->dev, "ak452x_init(codec)\n");
+ device_printf(codec->dev, "spicds_init(codec)\n");
#endif
snd_mtxlock(codec->lock);
+ if (codec->type == SPICDS_TYPE_AK4524 ||\
+ codec->type == SPICDS_TYPE_AK4528) {
/* power off */
- ak452x_wrcd(codec, AK4524_POWER, 0);
+ spicds_wrcd(codec, AK4524_POWER, 0);
/* set parameter */
- ak452x_wrcd(codec, AK4524_FORMAT, codec->format);
- ak452x_wrcd(codec, AK4524_DVC, codec->dvc);
+ spicds_wrcd(codec, AK4524_FORMAT, codec->format);
+ spicds_wrcd(codec, AK4524_DVC, codec->dvc);
/* power on */
- ak452x_wrcd(codec, AK4524_POWER, AK452X_POWER_PWDA | AK452X_POWER_PWAD | AK452X_POWER_PWVR);
+ spicds_wrcd(codec, AK4524_POWER, AK452X_POWER_PWDA | AK452X_POWER_PWAD | AK452X_POWER_PWVR);
/* free reset register */
- ak452x_wrcd(codec, AK4524_RESET, AK452X_RESET_RSDA | AK452X_RESET_RSAD);
+ spicds_wrcd(codec, AK4524_RESET, AK452X_RESET_RSDA | AK452X_RESET_RSAD);
+ }
+ if (codec->type == SPICDS_TYPE_WM8770) {
+ /* WM8770 init values are taken from ALSA */
+ /* These come first to reduce init pop noise */
+ spicds_wrcd(codec, 0x1b, 0x044); /* ADC Mux (AC'97 source) */
+ spicds_wrcd(codec, 0x1c, 0x00B); /* Out Mux1 (VOUT1 = DAC+AUX, VOUT2 = DAC) */
+ spicds_wrcd(codec, 0x1d, 0x009); /* Out Mux2 (VOUT2 = DAC, VOUT3 = DAC) */
+
+ spicds_wrcd(codec, 0x18, 0x000); /* All power-up */
+
+ spicds_wrcd(codec, 0x16, 0x122); /* I2S, normal polarity, 24bit */
+ spicds_wrcd(codec, 0x17, 0x022); /* 256fs, slave mode */
+
+ spicds_wrcd(codec, 0x19, 0x000); /* -12dB ADC/L */
+ spicds_wrcd(codec, 0x1a, 0x000); /* -12dB ADC/R */
+ }
+ if (codec->type == SPICDS_TYPE_AK4358)
+ spicds_wrcd(codec, 0x00, 0x07); /* I2S, 24bit, power-up */
+ if (codec->type == SPICDS_TYPE_AK4381)
+ spicds_wrcd(codec, 0x00, 0x0f); /* I2S, 24bit, power-up */
snd_mtxunlock(codec->lock);
}
void
-ak452x_reinit(struct ak452x_info *codec)
+spicds_reinit(struct spicds_info *codec)
{
snd_mtxlock(codec->lock);
+ if (codec->type != SPICDS_TYPE_WM8770) {
/* reset */
- ak452x_wrcd(codec, AK4524_RESET, 0);
+ spicds_wrcd(codec, AK4524_RESET, 0);
/* set parameter */
- ak452x_wrcd(codec, AK4524_FORMAT, codec->format);
- ak452x_wrcd(codec, AK4524_DVC, codec->dvc);
+ spicds_wrcd(codec, AK4524_FORMAT, codec->format);
+ spicds_wrcd(codec, AK4524_DVC, codec->dvc);
/* free reset register */
- ak452x_wrcd(codec, AK4524_RESET, AK452X_RESET_RSDA | AK452X_RESET_RSAD);
+ spicds_wrcd(codec, AK4524_RESET, AK452X_RESET_RSDA | AK452X_RESET_RSAD);
+ }
+ else {
+ /* WM8770 reinit */
+ /* AK4358 reinit */
+ /* AK4381 reinit */
+ }
snd_mtxunlock(codec->lock);
}
void
-ak452x_set(struct ak452x_info *codec, int dir, unsigned int left, unsigned int right)
+spicds_set(struct spicds_info *codec, int dir, unsigned int left, unsigned int right)
{
#if(0)
- device_printf(codec->dev, "ak452x_set(codec, %d, %d, %d)\n", dir, left, right);
+ device_printf(codec->dev, "spicds_set(codec, %d, %d, %d)\n", dir, left, right);
#endif
snd_mtxlock(codec->lock);
if (left >= 100)
- left = 127;
+ if (codec->type == SPICDS_TYPE_AK4381)
+ left = 255;
+ else
+ left = 127;
else
- left = left * 127 / 100;
+ switch (codec->type) {
+ case SPICDS_TYPE_WM8770:
+ left = left + 27;
+ break;
+ case SPICDS_TYPE_AK4381:
+ left = left * 255 / 100;
+ break;
+ default:
+ left = left * 127 / 100;
+ }
if (right >= 100)
- right = 127;
+ if (codec->type == SPICDS_TYPE_AK4381)
+ right = 255;
+ else
+ right = 127;
else
- right = right * 127 / 100;
- if (dir == PCMDIR_REC && codec->type == AK452X_TYPE_4524) {
+ switch (codec->type) {
+ case SPICDS_TYPE_WM8770:
+ right = right + 27;
+ break;
+ case SPICDS_TYPE_AK4381:
+ right = right * 255 / 100;
+ break;
+ default:
+ right = right * 127 / 100;
+ }
+ if (dir == PCMDIR_REC && codec->type == SPICDS_TYPE_AK4524) {
#if(0)
- device_printf(codec->dev, "ak452x_set(): AK4524(REC) %d/%d\n", left, right);
+ device_printf(codec->dev, "spicds_set(): AK4524(REC) %d/%d\n", left, right);
#endif
- ak452x_wrcd(codec, AK4524_LIPGA, left);
- ak452x_wrcd(codec, AK4524_RIPGA, right);
+ spicds_wrcd(codec, AK4524_LIPGA, left);
+ spicds_wrcd(codec, AK4524_RIPGA, right);
}
- if (dir == PCMDIR_PLAY && codec->type == AK452X_TYPE_4524) {
+ if (dir == PCMDIR_PLAY && codec->type == SPICDS_TYPE_AK4524) {
#if(0)
- device_printf(codec->dev, "ak452x_set(): AK4524(PLAY) %d/%d\n", left, right);
+ device_printf(codec->dev, "spicds_set(): AK4524(PLAY) %d/%d\n", left, right);
#endif
- ak452x_wrcd(codec, AK4524_LOATT, left);
- ak452x_wrcd(codec, AK4524_ROATT, right);
+ spicds_wrcd(codec, AK4524_LOATT, left);
+ spicds_wrcd(codec, AK4524_ROATT, right);
}
- if (dir == PCMDIR_PLAY && codec->type == AK452X_TYPE_4528) {
+ if (dir == PCMDIR_PLAY && codec->type == SPICDS_TYPE_AK4528) {
#if(0)
- device_printf(codec->dev, "ak452x_set(): AK4528(PLAY) %d/%d\n", left, right);
+ device_printf(codec->dev, "spicds_set(): AK4528(PLAY) %d/%d\n", left, right);
#endif
- ak452x_wrcd(codec, AK4528_LOATT, left);
- ak452x_wrcd(codec, AK4528_ROATT, right);
+ spicds_wrcd(codec, AK4528_LOATT, left);
+ spicds_wrcd(codec, AK4528_ROATT, right);
}
+ if (dir == PCMDIR_PLAY && codec->type == SPICDS_TYPE_WM8770) {
+#if(0)
+ device_printf(codec->dev, "spicds_set(): WM8770(PLAY) %d/%d\n", left, right);
+#endif
+ spicds_wrcd(codec, WM8770_AOATT_L1, left | WM8770_AOATT_UPDATE);
+ spicds_wrcd(codec, WM8770_AOATT_R1, right | WM8770_AOATT_UPDATE);
+ }
+ if (dir == PCMDIR_PLAY && codec->type == SPICDS_TYPE_AK4358) {
+#if(0)
+ device_printf(codec->dev, "spicds_set(): AK4358(PLAY) %d/%d\n", left, right);
+#endif
+ spicds_wrcd(codec, AK4358_LO1ATT, left | AK4358_OATT_ENABLE);
+ spicds_wrcd(codec, AK4358_RO1ATT, right | AK4358_OATT_ENABLE);
+ }
+ if (dir == PCMDIR_PLAY && codec->type == SPICDS_TYPE_AK4381) {
+#if(0)
+ device_printf(codec->dev, "spicds_set(): AK4381(PLAY) %d/%d\n", left, right);
+#endif
+ spicds_wrcd(codec, AK4381_LOATT, left);
+ spicds_wrcd(codec, AK4381_ROATT, right);
+ }
+
snd_mtxunlock(codec->lock);
}
-MODULE_DEPEND(snd_ak452x, sound, SOUND_MINVER, SOUND_PREFVER, SOUND_MAXVER);
-MODULE_VERSION(snd_ak452x, 1);
+MODULE_DEPEND(snd_spicds, sound, SOUND_MINVER, SOUND_PREFVER, SOUND_MAXVER);
+MODULE_VERSION(snd_spicds, 1);
diff --git a/sys/dev/sound/pci/spicds.h b/sys/dev/sound/pci/spicds.h
index 1df631f..c999b4c 100644
--- a/sys/dev/sound/pci/spicds.h
+++ b/sys/dev/sound/pci/spicds.h
@@ -1,4 +1,5 @@
/*
+ * Copyright (c) 2006 Konstantin Dimitrov <kosio.dimitrov@gmail.com>
* Copyright (c) 2001 Katsurajima Naoto <raven@katsurajima.seya.yokohama.jp>
* All rights reserved.
*
@@ -27,8 +28,11 @@
*/
/* supported CODECs */
-#define AK452X_TYPE_4524 0
-#define AK452X_TYPE_4528 1
+#define SPICDS_TYPE_AK4524 0
+#define SPICDS_TYPE_AK4528 1
+#define SPICDS_TYPE_WM8770 2
+#define SPICDS_TYPE_AK4358 3
+#define SPICDS_TYPE_AK4381 4
/* AK4524/AK4528 control registers */
#define AK4524_POWER 0x00
@@ -76,16 +80,37 @@
#define AK4528_LOATT 0x04
#define AK4528_ROATT 0x05
-struct ak452x_info;
+/* WM8770 control registers */
+#define WM8770_AOATT_L1 0x00
+#define WM8770_AOATT_R1 0x01
+#define WM8770_AOATT_L2 0x02
+#define WM8770_AOATT_R2 0x03
+#define WM8770_AOATT_L3 0x04
+#define WM8770_AOATT_R3 0x05
+#define WM8770_AOATT_L4 0x06
+#define WM8770_AOATT_R4 0x07
+#define WM8770_AOATT_MAST 0x08
+#define WM8770_AOATT_UPDATE 0x100
-typedef void (*ak452x_ctrl)(void *, unsigned int, unsigned int, unsigned int);
+/* AK4358 control registers */
+#define AK4358_LO1ATT 0x04
+#define AK4358_RO1ATT 0x05
+#define AK4358_OATT_ENABLE 0x80
-struct ak452x_info *ak452x_create(device_t dev, void *devinfo, int num, ak452x_ctrl);
-void ak452x_destroy(struct ak452x_info *codec);
-void ak452x_settype(struct ak452x_info *codec, unsigned int type);
-void ak452x_setcif(struct ak452x_info *codec, unsigned int cif);
-void ak452x_setformat(struct ak452x_info *codec, unsigned int format);
-void ak452x_setdvc(struct ak452x_info *codec, unsigned int dvc);
-void ak452x_init(struct ak452x_info *codec);
-void ak452x_reinit(struct ak452x_info *codec);
-void ak452x_set(struct ak452x_info *codec, int dir, unsigned int left, unsigned int right);
+/* AK4381 control registers */
+#define AK4381_LOATT 0x03
+#define AK4381_ROATT 0x04
+
+struct spicds_info;
+
+typedef void (*spicds_ctrl)(void *, unsigned int, unsigned int, unsigned int);
+
+struct spicds_info *spicds_create(device_t dev, void *devinfo, int num, spicds_ctrl);
+void spicds_destroy(struct spicds_info *codec);
+void spicds_settype(struct spicds_info *codec, unsigned int type);
+void spicds_setcif(struct spicds_info *codec, unsigned int cif);
+void spicds_setformat(struct spicds_info *codec, unsigned int format);
+void spicds_setdvc(struct spicds_info *codec, unsigned int dvc);
+void spicds_init(struct spicds_info *codec);
+void spicds_reinit(struct spicds_info *codec);
+void spicds_set(struct spicds_info *codec, int dir, unsigned int left, unsigned int right);
OpenPOWER on IntegriCloud