Commit e8158535 authored by Jaroslav Kysela's avatar Jaroslav Kysela

[ALSA] Added ICE1724 - ESI Juli@ code (not complete) + AK4114 code + AK4358

Serial BUS drivers,AK4114 receiver,AK4XXX AD/DA converters
ICE1712 driver,ICE1724 driver
Initial incomplete driver for ESI Juli@ cardcards based on ICE1724, AK4114,
AK4358 and AK5385. The ICE1724 and ICE1712 main files plus some drivers are
also updated (cleanups and new callbacks).
Signed-off-by: default avatarJaroslav Kysela <perex@suse.cz>
parent f2e84c94
#ifndef __SOUND_AK4114_H
#define __SOUND_AK4114_H
/*
* Routines for Asahi Kasei AK4114
* Copyright (c) by Jaroslav Kysela <perex@suse.cz>,
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/* AK4114 registers */
#define AK4114_REG_PWRDN 0x00 /* power down */
#define AK4114_REG_FORMAT 0x01 /* format control */
#define AK4114_REG_IO0 0x02 /* input/output control */
#define AK4114_REG_IO1 0x03 /* input/output control */
#define AK4114_REG_INT0_MASK 0x04 /* interrupt0 mask */
#define AK4114_REG_INT1_MASK 0x05 /* interrupt1 mask */
#define AK4114_REG_RCS0 0x06 /* receiver status 0 */
#define AK4114_REG_RCS1 0x07 /* receiver status 1 */
#define AK4114_REG_RXCSB0 0x08 /* RX channel status byte 0 */
#define AK4114_REG_RXCSB1 0x09 /* RX channel status byte 1 */
#define AK4114_REG_RXCSB2 0x0a /* RX channel status byte 2 */
#define AK4114_REG_RXCSB3 0x0b /* RX channel status byte 3 */
#define AK4114_REG_RXCSB4 0x0c /* RX channel status byte 4 */
#define AK4114_REG_TXCSB0 0x0d /* TX channel status byte 0 */
#define AK4114_REG_TXCSB1 0x0e /* TX channel status byte 1 */
#define AK4114_REG_TXCSB2 0x0f /* TX channel status byte 2 */
#define AK4114_REG_TXCSB3 0x10 /* TX channel status byte 3 */
#define AK4114_REG_TXCSB4 0x11 /* TX channel status byte 4 */
#define AK4114_REG_Pc0 0x12 /* burst preamble Pc byte 0 */
#define AK4114_REG_Pc1 0x13 /* burst preamble Pc byte 1 */
#define AK4114_REG_Pd0 0x14 /* burst preamble Pd byte 0 */
#define AK4114_REG_Pd1 0x15 /* burst preamble Pd byte 1 */
#define AK4114_REG_QSUB_ADDR 0x16 /* Q-subcode address + control */
#define AK4114_REG_QSUB_TRACK 0x17 /* Q-subcode track */
#define AK4114_REG_QSUB_INDEX 0x18 /* Q-subcode index */
#define AK4114_REG_QSUB_MINUTE 0x19 /* Q-subcode minute */
#define AK4114_REG_QSUB_SECOND 0x1a /* Q-subcode second */
#define AK4114_REG_QSUB_FRAME 0x1b /* Q-subcode frame */
#define AK4114_REG_QSUB_ZERO 0x1c /* Q-subcode zero */
#define AK4114_REG_QSUB_ABSMIN 0x1d /* Q-subcode absolute minute */
#define AK4114_REG_QSUB_ABSSEC 0x1e /* Q-subcode absolute second */
#define AK4114_REG_QSUB_ABSFRM 0x1f /* Q-subcode absolute frame */
/* sizes */
#define AK4114_REG_RXCSB_SIZE ((AK4114_REG_RXCSB4-AK4114_REG_RXCSB0)+1)
#define AK4114_REG_TXCSB_SIZE ((AK4114_REG_TXCSB4-AK4114_REG_TXCSB0)+1)
#define AK4114_REG_QSUB_SIZE ((AK4114_REG_QSUB_ABSFRM-AK4114_REG_QSUB_ADDR)+1)
/* AK4117_REG_PWRDN bits */
#define AK4114_CS12 (1<<7) /* Channel Status Select */
#define AK4114_BCU (1<<6) /* Block Start & C/U Output Mode */
#define AK4114_CM1 (1<<5) /* Master Clock Operation Select */
#define AK4114_CM0 (1<<4) /* Master Clock Operation Select */
#define AK4114_OCKS1 (1<<3) /* Master Clock Frequency Select */
#define AK4114_OCKS0 (1<<2) /* Master Clock Frequency Select */
#define AK4114_PWN (1<<1) /* 0 = power down, 1 = normal operation */
#define AK4114_RST (1<<0) /* 0 = reset & initialize (except this register), 1 = normal operation */
/* AK4114_REQ_FORMAT bits */
#define AK4114_MONO (1<<7) /* Double Sampling Frequency Mode: 0 = stereo, 1 = mono */
#define AK4114_DIF2 (1<<5) /* Audio Data Control */
#define AK4114_DIF1 (1<<5) /* Audio Data Control */
#define AK4114_DIF0 (1<<4) /* Audio Data Control */
#define AK4114_DIF_16R (0) /* STDO: 16-bit, right justified */
#define AK4114_DIF_18R (AK4114_DIF0) /* STDO: 18-bit, right justified */
#define AK4114_DIF_20R (AK4114_DIF1) /* STDO: 20-bit, right justified */
#define AK4114_DIF_24R (AK4114_DIF1|AK4114_DIF0) /* STDO: 24-bit, right justified */
#define AK4114_DIF_24L (AK4114_DIF2) /* STDO: 24-bit, left justified */
#define AK4114_DIF_24I2S (AK4114_DIF2|AK4114_DIF0) /* STDO: I2S */
#define AK4114_DIF_I24L (AK4114_DIF2|AK4114_DIF1) /* STDO: 24-bit, left justified; LRCLK, BICK = Input */
#define AK4114_DIF_I24I2S (AK4114_DIF2|AK4114_DIF1|AK4114_DIF0) /* STDO: I2S; LRCLK, BICK = Input */
#define AK4114_DEAU (1<<3) /* Deemphasis Autodetect Enable (1 = enable) */
#define AK4114_DEM1 (1<<2) /* 32kHz-48kHz Deemphasis Control */
#define AK4114_DEM0 (1<<1) /* 32kHz-48kHz Deemphasis Control */
#define AK4114_DEM_44KHZ (0)
#define AK4114_DEM_48KHZ (AK4114_DEM1)
#define AK4114_DEM_32KHZ (AK4114_DEM0|AK4114_DEM1)
#define AK4114_DEM_96KHZ (AK4114_DEM1) /* DFS must be set */
#define AK4114_DFS (1<<0) /* 96kHz Deemphasis Control */
/* AK4114_REG_IO0 */
#define AK4114_TX1E (1<<7) /* TX1 Output Enable (1 = enable) */
#define AK4114_OPS12 (1<<2) /* Output Though Data Selector for TX1 pin */
#define AK4114_OPS11 (1<<1) /* Output Though Data Selector for TX1 pin */
#define AK4114_OPS10 (1<<0) /* Output Though Data Selector for TX1 pin */
#define AK4114_TX0E (1<<3) /* TX0 Output Enable (1 = enable) */
#define AK4114_OPS02 (1<<2) /* Output Though Data Selector for TX0 pin */
#define AK4114_OPS01 (1<<1) /* Output Though Data Selector for TX0 pin */
#define AK4114_OPS00 (1<<0) /* Output Though Data Selector for TX0 pin */
/* AK4114_REG_IO1 */
#define AK4114_EFH1 (1<<7) /* Interrupt 0 pin Hold */
#define AK4114_EFH0 (1<<6) /* Interrupt 0 pin Hold */
#define AK4114_EFH_512 (0)
#define AK4114_EFH_1024 (AK4114_EFH0)
#define AK4114_EFH_2048 (AK4114_EFH1)
#define AK4114_EFH_4096 (AK4114_EFH1|AK4114_EFH0)
#define AK4114_UDIT (1<<5) /* U-bit Control for DIT (0 = fixed '0', 1 = recovered) */
#define AK4114_TLR (1<<4) /* Double Sampling Frequency Select for DIT (0 = L channel, 1 = R channel) */
#define AK4114_DIT (1<<3) /* TX1 out: 0 = Through Data (RX data), 1 = Transmit Data (DAUX data) */
#define AK4114_IPS2 (1<<2) /* Input Recovery Data Select */
#define AK4114_IPS1 (1<<1) /* Input Recovery Data Select */
#define AK4114_IPS0 (1<<0) /* Input Recovery Data Select */
#define AK4114_IPS(x) ((x)&7)
/* AK4114_REG_INT0_MASK && AK4114_REG_INT1_MASK*/
#define AK4117_MQI (1<<7) /* mask enable for QINT bit */
#define AK4117_MAT (1<<6) /* mask enable for AUTO bit */
#define AK4117_MCI (1<<5) /* mask enable for CINT bit */
#define AK4117_MUL (1<<4) /* mask enable for UNLOCK bit */
#define AK4117_MDTS (1<<3) /* mask enable for DTSCD bit */
#define AK4117_MPE (1<<2) /* mask enable for PEM bit */
#define AK4117_MAN (1<<1) /* mask enable for AUDN bit */
#define AK4117_MPR (1<<0) /* mask enable for PAR bit */
/* AK4114_REG_RCS0 */
#define AK4114_QINT (1<<7) /* Q-subcode buffer interrupt, 0 = no change, 1 = changed */
#define AK4114_AUTO (1<<6) /* Non-PCM or DTS stream auto detection, 0 = no detect, 1 = detect */
#define AK4114_CINT (1<<5) /* channel status buffer interrupt, 0 = no change, 1 = change */
#define AK4114_UNLCK (1<<4) /* PLL lock status, 0 = lock, 1 = unlock */
#define AK4114_DTSCD (1<<3) /* DTS-CD Detect, 0 = No detect, 1 = Detect */
#define AK4114_PEM (1<<2) /* Pre-emphasis Detect, 0 = OFF, 1 = ON */
#define AK4114_AUDION (1<<1) /* audio bit output, 0 = audio, 1 = non-audio */
#define AK4114_PAR (1<<0) /* parity error or biphase error status, 0 = no error, 1 = error */
/* AK4114_REG_RCS1 */
#define AK4114_FS3 (1<<7) /* sampling frequency detection */
#define AK4114_FS2 (1<<6)
#define AK4114_FS1 (1<<5)
#define AK4114_FS0 (1<<4)
#define AK4114_FS_44100HZ (0)
#define AK4114_FS_48000HZ (AK4114_FS1)
#define AK4114_FS_32000HZ (AK4114_FS1|AK4114_FS0)
#define AK4114_FS_88200HZ (AK4114_FS3)
#define AK4114_FS_96000HZ (AK4114_FS3|AK4114_FS1)
#define AK4114_FS_176400HZ (AK4114_FS3|AK4114_FS2)
#define AK4114_FS_192000HZ (AK4114_FS3|AK4114_FS2|AK4114_FS1)
#define AK4114_V (1<<3) /* Validity of Channel Status, 0 = Valid, 1 = Invalid */
#define AK4114_QCRC (1<<1) /* CRC for Q-subcode, 0 = no error, 1 = error */
#define AK4114_CCRC (1<<0) /* CRC for channel status, 0 = no error, 1 = error */
/* flags for snd_ak4114_check_rate_and_errors() */
#define AK4114_CHECK_NO_STAT (1<<0) /* no statistics */
#define AK4114_CHECK_NO_RATE (1<<1) /* no rate check */
#define AK4114_CONTROLS 14
typedef void (ak4114_write_t)(void *private_data, unsigned char addr, unsigned char data);
typedef unsigned char (ak4114_read_t)(void *private_data, unsigned char addr);
typedef struct ak4114 ak4114_t;
struct ak4114 {
snd_card_t * card;
ak4114_write_t * write;
ak4114_read_t * read;
void * private_data;
unsigned int init: 1;
spinlock_t lock;
unsigned char regmap[7];
unsigned char txcsb[5];
snd_kcontrol_t *kctls[AK4114_CONTROLS];
snd_pcm_substream_t *playback_substream;
snd_pcm_substream_t *capture_substream;
unsigned long parity_errors;
unsigned long v_bit_errors;
unsigned long qcrc_errors;
unsigned long ccrc_errors;
unsigned char rcs0;
unsigned char rcs1;
struct workqueue_struct *workqueue;
struct work_struct work;
void *change_callback_private;
void (*change_callback)(ak4114_t *ak4114, unsigned char c0, unsigned char c1);
};
int snd_ak4114_create(snd_card_t *card,
ak4114_read_t *read, ak4114_write_t *write,
unsigned char pgm[7], unsigned char txcsb[5],
void *private_data, ak4114_t **r_ak4114);
void snd_ak4114_reg_write(ak4114_t *ak4114, unsigned char reg, unsigned char mask, unsigned char val);
void snd_ak4114_reinit(ak4114_t *ak4114);
int snd_ak4114_build(ak4114_t *ak4114,
snd_pcm_substream_t *playback_substream,
snd_pcm_substream_t *capture_substream);
int snd_ak4114_external_rate(ak4114_t *ak4114);
int snd_ak4114_check_rate_and_errors(ak4114_t *ak4114, unsigned int flags);
#endif /* __SOUND_AK4114_H */
......@@ -50,7 +50,8 @@ struct snd_akm4xxx {
/* template should fill the following fields */
unsigned int idx_offset; /* control index offset */
enum {
SND_AK4524, SND_AK4528, SND_AK4529, SND_AK4355, SND_AK4381
SND_AK4524, SND_AK4528, SND_AK4529,
SND_AK4355, SND_AK4358, SND_AK4381
} type;
struct snd_ak4xxx_ops ops;
};
......
......@@ -3,6 +3,7 @@
# Copyright (c) 2003 by Jaroslav Kysela <perex@suse.cz>
#
snd-ak4114-objs := ak4114.o
snd-ak4117-objs := ak4117.o
snd-ak4xxx-adda-objs := ak4xxx-adda.o
snd-tea575x-tuner-objs := tea575x-tuner.o
......@@ -11,4 +12,5 @@ snd-tea575x-tuner-objs := tea575x-tuner.o
obj-$(CONFIG_SND_PDAUDIOCF) += snd-ak4117.o
obj-$(CONFIG_SND_ICE1712) += snd-ak4xxx-adda.o
obj-$(CONFIG_SND_ICE1724) += snd-ak4xxx-adda.o
obj-$(CONFIG_SND_ICE1724) += snd-ak4114.o
obj-$(CONFIG_SND_FM801_TEA575X) += snd-tea575x-tuner.o
/*
* Routines for control of the AK4114 via I2C and 4-wire serial interface
* IEC958 (S/PDIF) receiver by Asahi Kasei
* Copyright (c) by Jaroslav Kysela <perex@suse.cz>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <sound/driver.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <sound/core.h>
#include <sound/control.h>
#include <sound/pcm.h>
#include <sound/ak4114.h>
#include <sound/asoundef.h>
MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
MODULE_DESCRIPTION("AK4114 IEC958 (S/PDIF) receiver by Asahi Kasei");
MODULE_LICENSE("GPL");
#define AK4114_ADDR 0x00 /* fixed address */
static void ak4114_stats(void *);
static void reg_write(ak4114_t *ak4114, unsigned char reg, unsigned char val)
{
ak4114->write(ak4114->private_data, reg, val);
if (reg <= AK4114_REG_INT1_MASK)
ak4114->regmap[reg] = val;
else if (reg >= AK4114_REG_RXCSB0 && reg <= AK4114_REG_TXCSB4)
ak4114->txcsb[reg-AK4114_REG_RXCSB0] = val;
}
static inline unsigned char reg_read(ak4114_t *ak4114, unsigned char reg)
{
return ak4114->read(ak4114->private_data, reg);
}
#if 0
static void reg_dump(ak4114_t *ak4114)
{
int i;
printk("AK4114 REG DUMP:\n");
for (i = 0; i < 0x20; i++)
printk("reg[%02x] = %02x (%02x)\n", i, reg_read(ak4114, i), i < sizeof(ak4114->regmap) ? ak4114->regmap[i] : 0);
}
#endif
static void snd_ak4114_free(ak4114_t *chip)
{
chip->init = 1; /* don't schedule new work */
mb();
if (chip->workqueue != NULL) {
flush_workqueue(chip->workqueue);
destroy_workqueue(chip->workqueue);
}
kfree(chip);
}
static int snd_ak4114_dev_free(snd_device_t *device)
{
ak4114_t *chip = device->device_data;
snd_ak4114_free(chip);
return 0;
}
int snd_ak4114_create(snd_card_t *card,
ak4114_read_t *read, ak4114_write_t *write,
unsigned char pgm[7], unsigned char txcsb[5],
void *private_data, ak4114_t **r_ak4114)
{
ak4114_t *chip;
int err = 0;
unsigned char reg;
static snd_device_ops_t ops = {
.dev_free = snd_ak4114_dev_free,
};
chip = kcalloc(1, sizeof(*chip), GFP_KERNEL);
if (chip == NULL)
return -ENOMEM;
spin_lock_init(&chip->lock);
chip->card = card;
chip->read = read;
chip->write = write;
chip->private_data = private_data;
for (reg = 0; reg < 7; reg++)
chip->regmap[reg] = pgm[reg];
for (reg = 0; reg < 5; reg++)
chip->txcsb[reg] = txcsb[reg];
snd_ak4114_reinit(chip);
chip->rcs0 = reg_read(chip, AK4114_REG_RCS0) & ~(AK4114_QINT | AK4114_CINT);
chip->rcs1 = reg_read(chip, AK4114_REG_RCS1);
if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0)
goto __fail;
chip->workqueue = create_workqueue("snd-ak4114");
if (chip->workqueue == NULL) {
err = -ENOMEM;
goto __fail;
}
if (r_ak4114)
*r_ak4114 = chip;
return 0;
__fail:
snd_ak4114_free(chip);
return err < 0 ? err : -EIO;
}
void snd_ak4114_reg_write(ak4114_t *chip, unsigned char reg, unsigned char mask, unsigned char val)
{
if (reg <= AK4114_REG_INT1_MASK)
reg_write(chip, reg, (chip->regmap[reg] & ~mask) | val);
else if (reg >= AK4114_REG_TXCSB0 && reg <= AK4114_REG_TXCSB4)
reg_write(chip, reg, (chip->txcsb[reg] & ~mask) | val);
}
void snd_ak4114_reinit(ak4114_t *chip)
{
unsigned char old = chip->regmap[AK4114_REG_PWRDN], reg;
chip->init = 1;
mb();
flush_workqueue(chip->workqueue);
/* bring the chip to reset state and powerdown state */
reg_write(chip, AK4114_REG_PWRDN, old & ~(AK4114_RST|AK4114_PWN));
udelay(200);
/* release reset, but leave powerdown */
reg_write(chip, AK4114_REG_PWRDN, (old | AK4114_RST) & ~AK4114_PWN);
udelay(200);
for (reg = 1; reg < 7; reg++)
reg_write(chip, reg, chip->regmap[reg]);
for (reg = 0; reg < 5; reg++)
reg_write(chip, reg + AK4114_REG_TXCSB0, chip->txcsb[reg]);
/* release powerdown, everything is initialized now */
reg_write(chip, AK4114_REG_PWRDN, old | AK4114_RST | AK4114_PWN);
/* bring up statistics / event queing */
chip->init = 0;
INIT_WORK(&chip->work, ak4114_stats, chip);
queue_delayed_work(chip->workqueue, &chip->work, 1);
}
static unsigned int external_rate(unsigned char rcs1)
{
switch (rcs1 & (AK4114_FS0|AK4114_FS1|AK4114_FS2|AK4114_FS3)) {
case AK4114_FS_32000HZ: return 32000;
case AK4114_FS_44100HZ: return 44100;
case AK4114_FS_48000HZ: return 48000;
case AK4114_FS_88200HZ: return 88200;
case AK4114_FS_96000HZ: return 96000;
case AK4114_FS_176400HZ: return 176400;
case AK4114_FS_192000HZ: return 192000;
default: return 0;
}
}
static int snd_ak4114_in_error_info(snd_kcontrol_t *kcontrol,
snd_ctl_elem_info_t *uinfo)
{
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = 1;
uinfo->value.integer.min = 0;
uinfo->value.integer.max = LONG_MAX;
return 0;
}
static int snd_ak4114_in_error_get(snd_kcontrol_t *kcontrol,
snd_ctl_elem_value_t *ucontrol)
{
ak4114_t *chip = snd_kcontrol_chip(kcontrol);
long *ptr;
spin_lock_irq(&chip->lock);
ptr = (long *)(((char *)chip) + kcontrol->private_value);
ucontrol->value.integer.value[0] = *ptr;
*ptr = 0;
spin_unlock_irq(&chip->lock);
return 0;
}
static int snd_ak4114_in_bit_info(snd_kcontrol_t *kcontrol,
snd_ctl_elem_info_t *uinfo)
{
uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
uinfo->count = 1;
uinfo->value.integer.min = 0;
uinfo->value.integer.max = 1;
return 0;
}
static int snd_ak4114_in_bit_get(snd_kcontrol_t *kcontrol,
snd_ctl_elem_value_t *ucontrol)
{
ak4114_t *chip = snd_kcontrol_chip(kcontrol);
unsigned char reg = kcontrol->private_value & 0xff;
unsigned char bit = (kcontrol->private_value >> 8) & 0xff;
unsigned char inv = (kcontrol->private_value >> 31) & 1;
ucontrol->value.integer.value[0] = ((reg_read(chip, reg) & (1 << bit)) ? 1 : 0) ^ inv;
return 0;
}
static int snd_ak4114_rate_info(snd_kcontrol_t *kcontrol,
snd_ctl_elem_info_t *uinfo)
{
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = 1;
uinfo->value.integer.min = 0;
uinfo->value.integer.max = 192000;
return 0;
}
static int snd_ak4114_rate_get(snd_kcontrol_t *kcontrol,
snd_ctl_elem_value_t *ucontrol)
{
ak4114_t *chip = snd_kcontrol_chip(kcontrol);
ucontrol->value.integer.value[0] = external_rate(reg_read(chip, AK4114_REG_RCS1));
return 0;
}
static int snd_ak4114_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
{
uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
uinfo->count = 1;
return 0;
}
static int snd_ak4114_spdif_get(snd_kcontrol_t * kcontrol,
snd_ctl_elem_value_t * ucontrol)
{
ak4114_t *chip = snd_kcontrol_chip(kcontrol);
unsigned i;
for (i = 0; i < AK4114_REG_RXCSB_SIZE; i++)
ucontrol->value.iec958.status[i] = reg_read(chip, AK4114_REG_RXCSB0 + i);
return 0;
}
static int snd_ak4114_spdif_playback_get(snd_kcontrol_t * kcontrol,
snd_ctl_elem_value_t * ucontrol)
{
ak4114_t *chip = snd_kcontrol_chip(kcontrol);
unsigned i;
for (i = 0; i < AK4114_REG_TXCSB_SIZE; i++)
ucontrol->value.iec958.status[i] = chip->txcsb[i];
return 0;
}
static int snd_ak4114_spdif_playback_put(snd_kcontrol_t * kcontrol,
snd_ctl_elem_value_t * ucontrol)
{
ak4114_t *chip = snd_kcontrol_chip(kcontrol);
unsigned i;
for (i = 0; i < AK4114_REG_TXCSB_SIZE; i++)
reg_write(chip, AK4114_REG_TXCSB0 + i, ucontrol->value.iec958.status[i]);
return 0;
}
static int snd_ak4114_spdif_mask_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
{
uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
uinfo->count = 1;
return 0;
}
static int snd_ak4114_spdif_mask_get(snd_kcontrol_t * kcontrol,
snd_ctl_elem_value_t * ucontrol)
{
memset(ucontrol->value.iec958.status, 0xff, AK4114_REG_RXCSB_SIZE);
return 0;
}
static int snd_ak4114_spdif_pinfo(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
{
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->value.integer.min = 0;
uinfo->value.integer.max = 0xffff;
uinfo->count = 4;
return 0;
}
static int snd_ak4114_spdif_pget(snd_kcontrol_t * kcontrol,
snd_ctl_elem_value_t * ucontrol)
{
ak4114_t *chip = snd_kcontrol_chip(kcontrol);
unsigned short tmp;
ucontrol->value.integer.value[0] = 0xf8f2;
ucontrol->value.integer.value[1] = 0x4e1f;
tmp = reg_read(chip, AK4114_REG_Pc0) | (reg_read(chip, AK4114_REG_Pc1) << 8);
ucontrol->value.integer.value[2] = tmp;
tmp = reg_read(chip, AK4114_REG_Pd0) | (reg_read(chip, AK4114_REG_Pd1) << 8);
ucontrol->value.integer.value[3] = tmp;
return 0;
}
static int snd_ak4114_spdif_qinfo(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
{
uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
uinfo->count = AK4114_REG_QSUB_SIZE;
return 0;
}
static int snd_ak4114_spdif_qget(snd_kcontrol_t * kcontrol,
snd_ctl_elem_value_t * ucontrol)
{
ak4114_t *chip = snd_kcontrol_chip(kcontrol);
unsigned i;
for (i = 0; i < AK4114_REG_QSUB_SIZE; i++)
ucontrol->value.bytes.data[i] = reg_read(chip, AK4114_REG_QSUB_ADDR + i);
return 0;
}
/* Don't forget to change AK4114_CONTROLS define!!! */
static snd_kcontrol_new_t snd_ak4114_iec958_controls[] = {
{
.iface = SNDRV_CTL_ELEM_IFACE_PCM,
.name = "IEC958 Parity Errors",
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
.info = snd_ak4114_in_error_info,
.get = snd_ak4114_in_error_get,
.private_value = offsetof(ak4114_t, parity_errors),
},
{
.iface = SNDRV_CTL_ELEM_IFACE_PCM,
.name = "IEC958 V-Bit Errors",
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
.info = snd_ak4114_in_error_info,
.get = snd_ak4114_in_error_get,
.private_value = offsetof(ak4114_t, v_bit_errors),
},
{
.iface = SNDRV_CTL_ELEM_IFACE_PCM,
.name = "IEC958 C-CRC Errors",
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
.info = snd_ak4114_in_error_info,
.get = snd_ak4114_in_error_get,
.private_value = offsetof(ak4114_t, ccrc_errors),
},
{
.iface = SNDRV_CTL_ELEM_IFACE_PCM,
.name = "IEC958 Q-CRC Errors",
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
.info = snd_ak4114_in_error_info,
.get = snd_ak4114_in_error_get,
.private_value = offsetof(ak4114_t, qcrc_errors),
},
{
.iface = SNDRV_CTL_ELEM_IFACE_PCM,
.name = "IEC958 External Rate",
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
.info = snd_ak4114_rate_info,
.get = snd_ak4114_rate_get,
},
{
.iface = SNDRV_CTL_ELEM_IFACE_PCM,
.name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,MASK),
.access = SNDRV_CTL_ELEM_ACCESS_READ,
.info = snd_ak4114_spdif_mask_info,
.get = snd_ak4114_spdif_mask_get,
},
{
.iface = SNDRV_CTL_ELEM_IFACE_PCM,
.name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
.info = snd_ak4114_spdif_info,
.get = snd_ak4114_spdif_playback_get,
.get = snd_ak4114_spdif_playback_put,
},
{
.iface = SNDRV_CTL_ELEM_IFACE_PCM,
.name = SNDRV_CTL_NAME_IEC958("",CAPTURE,MASK),
.access = SNDRV_CTL_ELEM_ACCESS_READ,
.info = snd_ak4114_spdif_mask_info,
.get = snd_ak4114_spdif_mask_get,
},
{
.iface = SNDRV_CTL_ELEM_IFACE_PCM,
.name = SNDRV_CTL_NAME_IEC958("",CAPTURE,DEFAULT),
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
.info = snd_ak4114_spdif_info,
.get = snd_ak4114_spdif_get,
},
{
.iface = SNDRV_CTL_ELEM_IFACE_PCM,
.name = "IEC958 Preample Capture Default",
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
.info = snd_ak4114_spdif_pinfo,
.get = snd_ak4114_spdif_pget,
},
{
.iface = SNDRV_CTL_ELEM_IFACE_PCM,
.name = "IEC958 Q-subcode Capture Default",
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
.info = snd_ak4114_spdif_qinfo,
.get = snd_ak4114_spdif_qget,
},
{
.iface = SNDRV_CTL_ELEM_IFACE_PCM,
.name = "IEC958 Audio",
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
.info = snd_ak4114_in_bit_info,
.get = snd_ak4114_in_bit_get,
.private_value = (1<<31) | (1<<8) | AK4114_REG_RCS0,
},
{
.iface = SNDRV_CTL_ELEM_IFACE_PCM,
.name = "IEC958 Non-PCM Bitstream",
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
.info = snd_ak4114_in_bit_info,
.get = snd_ak4114_in_bit_get,
.private_value = (6<<8) | AK4114_REG_RCS1,
},
{
.iface = SNDRV_CTL_ELEM_IFACE_PCM,
.name = "IEC958 DTS Bitstream",
.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
.info = snd_ak4114_in_bit_info,
.get = snd_ak4114_in_bit_get,
.private_value = (3<<8) | AK4114_REG_RCS1,
}
};
int snd_ak4114_build(ak4114_t *ak4114,
snd_pcm_substream_t *ply_substream,
snd_pcm_substream_t *cap_substream)
{
snd_kcontrol_t *kctl;
unsigned int idx;
int err;
snd_assert(cap_substream, return -EINVAL);
ak4114->playback_substream = ply_substream;
ak4114->capture_substream = cap_substream;
for (idx = 0; idx < AK4114_CONTROLS; idx++) {
kctl = snd_ctl_new1(&snd_ak4114_iec958_controls[idx], ak4114);
if (kctl == NULL)
return -ENOMEM;
if (!strstr(kctl->id.name, "Playback")) {
if (ply_substream == NULL) {
snd_ctl_free_one(kctl);
ak4114->kctls[idx] = NULL;
continue;
}
kctl->id.device = ply_substream->pcm->device;
kctl->id.subdevice = ply_substream->number;
} else {
kctl->id.device = cap_substream->pcm->device;
kctl->id.subdevice = cap_substream->number;
}
err = snd_ctl_add(ak4114->card, kctl);
if (err < 0)
return err;
ak4114->kctls[idx] = kctl;
}
return 0;
}
int snd_ak4114_external_rate(ak4114_t *ak4114)
{
unsigned char rcs1;
rcs1 = reg_read(ak4114, AK4114_REG_RCS1);
return external_rate(rcs1);
}
int snd_ak4114_check_rate_and_errors(ak4114_t *ak4114, unsigned int flags)
{
snd_pcm_runtime_t *runtime = ak4114->capture_substream ? ak4114->capture_substream->runtime : NULL;
unsigned long _flags;
int res = 0;
unsigned char rcs0, rcs1;
unsigned char c0, c1;
rcs1 = reg_read(ak4114, AK4114_REG_RCS1);
if (flags & AK4114_CHECK_NO_STAT)
goto __rate;
rcs0 = reg_read(ak4114, AK4114_REG_RCS0);
printk("AK4114 IRQ: rcs0 = 0x%x, rcs1 = 0x%x\n", rcs0, rcs1);
return 0;
spin_lock_irqsave(&ak4114->lock, _flags);
if (rcs0 & AK4114_PAR)
ak4114->parity_errors++;
if (rcs1 & AK4114_V)
ak4114->v_bit_errors++;
if (rcs1 & AK4114_CCRC)
ak4114->ccrc_errors++;
if (rcs1 & AK4114_QCRC)
ak4114->qcrc_errors++;
c0 = (ak4114->rcs0 & (AK4114_QINT | AK4114_CINT | AK4114_PEM | AK4114_AUDION | AK4114_AUTO | AK4114_UNLCK)) ^
(rcs0 & (AK4114_QINT | AK4114_CINT | AK4114_PEM | AK4114_AUDION | AK4114_AUTO | AK4114_UNLCK));
c1 = (ak4114->rcs1 & 0xf0) ^ (rcs1 & 0xf0);
ak4114->rcs0 = rcs0 & ~(AK4114_QINT | AK4114_CINT);
ak4114->rcs1 = rcs1;
spin_unlock_irqrestore(&ak4114->lock, _flags);
if (rcs0 & AK4114_PAR)
snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4114->kctls[0]->id);
if (rcs0 & AK4114_V)
snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4114->kctls[1]->id);
if (rcs1 & AK4114_CCRC)
snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4114->kctls[2]->id);
if (rcs1 & AK4114_QCRC)
snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4114->kctls[3]->id);
/* rate change */
if (c1 & 0xf0)
snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4114->kctls[4]->id);
if ((c0 & AK4114_PEM) | (c0 & AK4114_CINT))
snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4114->kctls[9]->id);
if (c0 & AK4114_QINT)
snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4114->kctls[10]->id);
if (c0 & AK4114_AUDION)
snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4114->kctls[11]->id);
if (c0 & AK4114_AUTO)
snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4114->kctls[12]->id);
if (c0 & AK4114_DTSCD)
snd_ctl_notify(ak4114->card, SNDRV_CTL_EVENT_MASK_VALUE, &ak4114->kctls[13]->id);
if (ak4114->change_callback && (c0 | c1) != 0)
ak4114->change_callback(ak4114, c0, c1);
__rate:
/* compare rate */
res = external_rate(rcs1);
if (!(flags & AK4114_CHECK_NO_RATE) && runtime && runtime->rate != res) {
snd_pcm_stream_lock_irqsave(ak4114->capture_substream, _flags);
if (snd_pcm_running(ak4114->capture_substream)) {
// printk("rate changed (%i <- %i)\n", runtime->rate, res);
snd_pcm_stop(ak4114->capture_substream, SNDRV_PCM_STATE_DRAINING);
wake_up(&runtime->sleep);
res = 1;
}
snd_pcm_stream_unlock_irqrestore(ak4114->capture_substream, _flags);
}
return res;
}
static void ak4114_stats(void *data)
{
ak4114_t *chip = (ak4114_t *)data;
if (chip->init)
return;
snd_ak4114_check_rate_and_errors(chip, 0);
queue_delayed_work(chip->workqueue, &chip->work, 1);
}
EXPORT_SYMBOL(snd_ak4114_create);
EXPORT_SYMBOL(snd_ak4114_reg_write);
EXPORT_SYMBOL(snd_ak4114_reinit);
EXPORT_SYMBOL(snd_ak4114_build);
EXPORT_SYMBOL(snd_ak4114_external_rate);
EXPORT_SYMBOL(snd_ak4114_check_rate_and_errors);
/*
* ALSA driver for AK4524 / AK4528 / AK4529 / AK4355 / AK4381
* ALSA driver for AK4524 / AK4528 / AK4529 / AK4355 / AK4358 / AK4381
* AD and DA converters
*
* Copyright (c) 2000-2003 Jaroslav Kysela <perex@suse.cz>,
* Copyright (c) 2000-2004 Jaroslav Kysela <perex@suse.cz>,
* Takashi Iwai <tiwai@suse.de>
*
* This program is free software; you can redistribute it and/or modify
......@@ -84,6 +84,7 @@ void snd_akm4xxx_reset(akm4xxx_t *ak, int state)
/* FIXME: needed for ak4529? */
break;
case SND_AK4355:
case SND_AK4358:
if (state) {
snd_akm4xxx_write(ak, 0, 0x01, 0x02); /* reset and soft-mute */
return;
......@@ -166,6 +167,24 @@ void snd_akm4xxx_init(akm4xxx_t *ak)
0x01, 0x01, /* 1: un-reset, unmute */
0xff, 0xff
};
static unsigned char inits_ak4358[] = {
0x01, 0x02, /* 1: reset and soft-mute */
0x00, 0x06, /* 0: mode3(i2s), disable auto-clock detect, disable DZF, sharp roll-off, RSTN#=0 */
0x02, 0x0e, /* 2: DA's power up, normal speed, RSTN#=0 */
// 0x02, 0x2e, /* quad speed */
0x03, 0x01, /* 3: de-emphasis off */
0x04, 0x00, /* 4: LOUT1 volume muted */
0x05, 0x00, /* 5: ROUT1 volume muted */
0x06, 0x00, /* 6: LOUT2 volume muted */
0x07, 0x00, /* 7: ROUT2 volume muted */
0x08, 0x00, /* 8: LOUT3 volume muted */
0x09, 0x00, /* 9: ROUT3 volume muted */
0x0b, 0x00, /* b: LOUT4 volume muted */
0x0c, 0x00, /* c: ROUT4 volume muted */
0x0a, 0x00, /* a: DATT speed=0, ignore DZF */
0x01, 0x01, /* 1: un-reset, unmute */
0xff, 0xff
};
static unsigned char inits_ak4381[] = {
0x00, 0x0c, /* 0: mode3(i2s), disable auto-clock detect */
0x01, 0x02, /* 1: de-emphasis off, normal speed, sharp roll-off, DZF off */
......@@ -197,6 +216,10 @@ void snd_akm4xxx_init(akm4xxx_t *ak)
inits = inits_ak4355;
num_chips = 1;
break;
case SND_AK4358:
inits = inits_ak4358;
num_chips = 1;
break;
case SND_AK4381:
inits = inits_ak4381;
num_chips = ak->num_dacs / 2;
......@@ -370,6 +393,12 @@ int snd_akm4xxx_build_controls(akm4xxx_t *ak)
case SND_AK4355:
ctl.private_value = AK_COMPOSE(0, idx + 4, 0, 255); /* register 4-9, chip #0 only */
break;
case SND_AK4358:
if (idx >= 6)
ctl.private_value = AK_COMPOSE(0, idx + 5, 0, 255); /* register 4-9, chip #0 only */
else
ctl.private_value = AK_COMPOSE(0, idx + 4, 0, 255); /* register 4-9, chip #0 only */
break;
case SND_AK4381:
ctl.private_value = AK_COMPOSE(idx/2, (idx%2) + 3, 0, 255); /* register 3 & 4 */
break;
......@@ -407,7 +436,7 @@ int snd_akm4xxx_build_controls(akm4xxx_t *ak)
if ((err = snd_ctl_add(ak->card, snd_ctl_new(&ctl, SNDRV_CTL_ELEM_ACCESS_READ|SNDRV_CTL_ELEM_ACCESS_WRITE))) < 0)
return err;
}
if (ak->type == SND_AK4355)
if (ak->type == SND_AK4355 || ak->type == SND_AK4358)
num_emphs = 1;
else
num_emphs = ak->num_dacs / 2;
......@@ -432,6 +461,7 @@ int snd_akm4xxx_build_controls(akm4xxx_t *ak)
break;
}
case SND_AK4355:
case SND_AK4358:
ctl.private_value = AK_COMPOSE(idx, 3, 0, 0);
break;
case SND_AK4381:
......
......@@ -5,7 +5,7 @@
snd-ice17xx-ak4xxx-objs := ak4xxx.o
snd-ice1712-objs := ice1712.o delta.o hoontech.o ews.o
snd-ice1724-objs := ice1724.o amp.o revo.o aureon.o vt1720_mobo.o pontis.o prodigy192.o
snd-ice1724-objs := ice1724.o amp.o revo.o aureon.o vt1720_mobo.o pontis.o prodigy192.o juli.o
# Toplevel Module Dependency
obj-$(CONFIG_SND_ICE1712) += snd-ice1712.o snd-ice17xx-ak4xxx.o
......
......@@ -126,12 +126,16 @@ int snd_ice1712_akm4xxx_init(akm4xxx_t *ak, const akm4xxx_t *temp,
{
struct snd_ak4xxx_private *priv;
priv = kmalloc(sizeof(*priv), GFP_KERNEL);
if (priv == NULL)
return -ENOMEM;
if (_priv != NULL) {
priv = kmalloc(sizeof(*priv), GFP_KERNEL);
if (priv == NULL)
return -ENOMEM;
*priv = *_priv;
} else {
priv = NULL;
}
*ak = *temp;
ak->card = ice->card;
*priv = *_priv;
ak->private_value[0] = (unsigned long)priv;
ak->private_data[0] = ice;
if (ak->ops.lock == NULL)
......
......@@ -106,7 +106,7 @@ enum {
#define VT1724_REG_I2C_BYTE_ADDR 0x11 /* byte */
#define VT1724_REG_I2C_DATA 0x12 /* byte */
#define VT1724_REG_I2C_CTRL 0x13 /* byte */
#define VT1724_I2C_EEPROM 0x80 /* EEPROM exists */
#define VT1724_I2C_EEPROM 0x80 /* 1 = EEPROM exists */
#define VT1724_I2C_BUSY 0x01 /* busy bit */
#define VT1724_REG_GPIO_DATA 0x14 /* word */
......
......@@ -1014,21 +1014,9 @@ static int snd_ice1712_pro_trigger(snd_pcm_substream_t *substream,
static void snd_ice1712_set_pro_rate(ice1712_t *ice, unsigned int rate, int force)
{
unsigned long flags;
unsigned char val;
unsigned char val, old;
unsigned int i;
spin_lock_irqsave(&ice->reg_lock, flags);
if (inb(ICEMT(ice, PLAYBACK_CONTROL)) & (ICE1712_CAPTURE_START_SHADOW|
ICE1712_PLAYBACK_PAUSE|
ICE1712_PLAYBACK_START)) {
spin_unlock_irqrestore(&ice->reg_lock, flags);
return;
}
if (!force && is_pro_rate_locked(ice)) {
spin_unlock_irqrestore(&ice->reg_lock, flags);
return;
}
switch (rate) {
case 8000: val = 6; break;
case 9600: val = 3; break;
......@@ -1049,8 +1037,22 @@ static void snd_ice1712_set_pro_rate(ice1712_t *ice, unsigned int rate, int forc
rate = 48000;
break;
}
outb(val, ICEMT(ice, RATE));
spin_lock_irqsave(&ice->reg_lock, flags);
if (inb(ICEMT(ice, PLAYBACK_CONTROL)) & (ICE1712_CAPTURE_START_SHADOW|
ICE1712_PLAYBACK_PAUSE|
ICE1712_PLAYBACK_START)) {
__out:
spin_unlock_irqrestore(&ice->reg_lock, flags);
return;
}
if (!force && is_pro_rate_locked(ice))
goto __out;
old = inb(ICEMT(ice, RATE));
if (!force && old == val)
goto __out;
outb(val, ICEMT(ice, RATE));
spin_unlock_irqrestore(&ice->reg_lock, flags);
if (ice->gpio.set_pro_rate)
......@@ -2405,6 +2407,7 @@ static int __devinit snd_ice1712_chip_init(ice1712_t *ice)
udelay(200);
snd_ice1712_write(ice, ICE1712_IREG_CONSUMER_POWERDOWN, 0);
}
snd_ice1712_set_pro_rate(ice, 48000, 1);
return 0;
}
......@@ -2545,6 +2548,7 @@ static int __devinit snd_ice1712_create(snd_card_t * card,
ice->cs8427_timeout = cs8427_timeout;
spin_lock_init(&ice->reg_lock);
init_MUTEX(&ice->gpio_mutex);
init_MUTEX(&ice->i2c_mutex);
init_MUTEX(&ice->open_mutex);
ice->gpio.set_mask = snd_ice1712_set_gpio_mask;
ice->gpio.set_dir = snd_ice1712_set_gpio_dir;
......
......@@ -27,6 +27,7 @@
#include <sound/rawmidi.h>
#include <sound/i2c.h>
#include <sound/ak4xxx-adda.h>
#include <sound/ak4114.h>
#include <sound/pcm.h>
......@@ -340,6 +341,7 @@ struct _snd_ice1712 {
akm4xxx_t *akm;
struct snd_ice1712_spdif spdif;
struct semaphore i2c_mutex; /* I2C mutex for ICE1724 registers */
snd_i2c_bus_t *i2c; /* I2C bus */
snd_i2c_device_t *cs8427; /* CS8427 I2C device */
unsigned int cs8427_timeout; /* CS8427 reset timeout in HZ/100 */
......@@ -355,12 +357,13 @@ struct _snd_ice1712 {
unsigned int (*get_data)(ice1712_t *ice);
/* misc operators - move to another place? */
void (*set_pro_rate)(ice1712_t *ice, unsigned int rate);
void (*i2s_mclk_changed)(ice1712_t *ice);
} gpio;
struct semaphore gpio_mutex;
/* other board-specific data */
union {
/* additional i2c devices for EWS boards*/
/* additional i2c devices for EWS boards */
snd_i2c_device_t *i2cdevs[3];
/* AC97 register cache for Aureon */
struct aureon_spec {
......@@ -375,6 +378,10 @@ struct _snd_ice1712 {
unsigned int config;
unsigned short boxconfig[4];
} hoontech;
struct {
ak4114_t *ak4114;
unsigned int analog: 1;
} juli;
} spec;
};
......
......@@ -47,6 +47,7 @@
#include "vt1720_mobo.h"
#include "pontis.h"
#include "prodigy192.h"
#include "juli.h"
MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
......@@ -59,6 +60,7 @@ MODULE_SUPPORTED_DEVICE("{"
VT1720_MOBO_DEVICE_DESC
PONTIS_DEVICE_DESC
PRODIGY192_DEVICE_DESC
JULI_DEVICE_DESC
"{VIA,VT1720},"
"{VIA,VT1724},"
"{ICEnsemble,Generic ICE1724},"
......@@ -401,23 +403,11 @@ static void snd_vt1724_set_pro_rate(ice1712_t *ice, unsigned int rate, int force
{
unsigned long flags;
unsigned char val, old;
unsigned int i;
unsigned int i, mclk_change;
if (rate > get_max_rate(ice))
return;
spin_lock_irqsave(&ice->reg_lock, flags);
if ((inb(ICEMT1724(ice, DMA_CONTROL)) & DMA_STARTS) ||
(inb(ICEMT1724(ice, DMA_PAUSE)) & DMA_PAUSES)) {
/* running? we cannot change the rate now... */
spin_unlock_irqrestore(&ice->reg_lock, flags);
return;
}
if (!force && is_pro_rate_locked(ice)) {
spin_unlock_irqrestore(&ice->reg_lock, flags);
return;
}
switch (rate) {
case 8000: val = 6; break;
case 9600: val = 3; break;
......@@ -439,8 +429,21 @@ static void snd_vt1724_set_pro_rate(ice1712_t *ice, unsigned int rate, int force
val = 0;
break;
}
spin_lock_irqsave(&ice->reg_lock, flags);
if ((inb(ICEMT1724(ice, DMA_CONTROL)) & DMA_STARTS) ||
(inb(ICEMT1724(ice, DMA_PAUSE)) & DMA_PAUSES)) {
/* running? we cannot change the rate now... */
spin_unlock_irqrestore(&ice->reg_lock, flags);
return;
}
if (!force && is_pro_rate_locked(ice)) {
spin_unlock_irqrestore(&ice->reg_lock, flags);
return;
}
old = inb(ICEMT1724(ice, RATE));
if (old != val)
if (force || old != val)
outb(val, ICEMT1724(ice, RATE));
else if (rate == ice->cur_rate) {
spin_unlock_irqrestore(&ice->reg_lock, flags);
......@@ -450,6 +453,7 @@ static void snd_vt1724_set_pro_rate(ice1712_t *ice, unsigned int rate, int force
ice->cur_rate = rate;
/* check MT02 */
mclk_change = 0;
if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
val = old = inb(ICEMT1724(ice, I2S_FORMAT));
if (rate > 96000)
......@@ -458,25 +462,23 @@ static void snd_vt1724_set_pro_rate(ice1712_t *ice, unsigned int rate, int force
val &= ~VT1724_MT_I2S_MCLK_128X; /* 256x MCLK */
if (val != old) {
outb(val, ICEMT1724(ice, I2S_FORMAT));
if (ice->eeprom.subvendor == VT1724_SUBDEVICE_REVOLUTION71) {
/* FIXME: is this revo only? */
/* assert PRST# to converters; MT05 bit 7 */
outb(inb(ICEMT1724(ice, AC97_CMD)) | 0x80, ICEMT1724(ice, AC97_CMD));
spin_unlock_irqrestore(&ice->reg_lock, flags);
mdelay(5);
spin_lock_irqsave(&ice->reg_lock, flags);
/* deassert PRST# */
outb(inb(ICEMT1724(ice, AC97_CMD)) & ~0x80, ICEMT1724(ice, AC97_CMD));
}
mclk_change = 1;
}
}
spin_unlock_irqrestore(&ice->reg_lock, flags);
if (mclk_change && ice->gpio.i2s_mclk_changed)
ice->gpio.i2s_mclk_changed(ice);
if (ice->gpio.set_pro_rate)
ice->gpio.set_pro_rate(ice, rate);
/* set up codecs */
for (i = 0; i < ice->akm_codecs; i++) {
if (ice->akm[i].ops.set_rate_val)
ice->akm[i].ops.set_rate_val(&ice->akm[i], rate);
}
if (ice->spdif.ops.setup_rate)
ice->spdif.ops.setup_rate(ice, rate);
}
static int snd_vt1724_pcm_hw_params(snd_pcm_substream_t * substream,
......@@ -1866,6 +1868,7 @@ static struct snd_ice1712_card_info *card_tables[] __devinitdata = {
snd_vt1720_mobo_cards,
snd_vt1720_pontis_cards,
snd_vt1724_prodigy192_cards,
snd_vt1724_juli_cards,
NULL,
};
......@@ -1878,23 +1881,34 @@ static void wait_i2c_busy(ice1712_t *ice)
int t = 0x10000;
while ((inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_BUSY) && t--)
;
if (t == -1)
printk(KERN_ERR "ice1724: i2c busy timeout\n");
}
unsigned char snd_vt1724_read_i2c(ice1712_t *ice, unsigned char dev, unsigned char addr)
{
unsigned char val;
down(&ice->i2c_mutex);
outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR));
outb(dev & ~VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR));
wait_i2c_busy(ice);
return inb(ICEREG1724(ice, I2C_DATA));
val = inb(ICEREG1724(ice, I2C_DATA));
up(&ice->i2c_mutex);
//printk("i2c_read: [0x%x,0x%x] = 0x%x\n", dev, addr, val);
return val;
}
void snd_vt1724_write_i2c(ice1712_t *ice, unsigned char dev, unsigned char addr, unsigned char data)
{
down(&ice->i2c_mutex);
wait_i2c_busy(ice);
//printk("i2c_write: [0x%x,0x%x] = 0x%x\n", dev, addr, data);
outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR));
outb(data, ICEREG1724(ice, I2C_DATA));
outb(dev | VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR));
wait_i2c_busy(ice);
up(&ice->i2c_mutex);
}
static int __devinit snd_vt1724_read_eeprom(ice1712_t *ice, const char *modelname)
......@@ -1906,7 +1920,8 @@ static int __devinit snd_vt1724_read_eeprom(ice1712_t *ice, const char *modelnam
if (! modelname || ! *modelname) {
ice->eeprom.subvendor = 0;
if ((inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_EEPROM) != 0)
ice->eeprom.subvendor = (snd_vt1724_read_i2c(ice, dev, 0x00) << 0) |
ice->eeprom.subvendor =
(snd_vt1724_read_i2c(ice, dev, 0x00) << 0) |
(snd_vt1724_read_i2c(ice, dev, 0x01) << 8) |
(snd_vt1724_read_i2c(ice, dev, 0x02) << 16) |
(snd_vt1724_read_i2c(ice, dev, 0x03) << 24);
......@@ -2114,6 +2129,7 @@ static int __devinit snd_vt1724_create(snd_card_t * card,
spin_lock_init(&ice->reg_lock);
init_MUTEX(&ice->gpio_mutex);
init_MUTEX(&ice->open_mutex);
init_MUTEX(&ice->i2c_mutex);
ice->gpio.set_mask = snd_vt1724_set_gpio_mask;
ice->gpio.set_dir = snd_vt1724_set_gpio_dir;
ice->gpio.set_data = snd_vt1724_set_gpio_data;
......
/*
* ALSA driver for ICEnsemble VT1724 (Envy24HT)
*
* Lowlevel functions for ESI Juli@ cards
*
* Copyright (c) 2004 Jaroslav Kysela <perex@suse.cz>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <sound/driver.h>
#include <asm/io.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <sound/core.h>
#include "ice1712.h"
#include "envy24ht.h"
#include "juli.h"
/*
* chip addresses on I2C bus
*/
#define AK4114_ADDR 0x20 /* S/PDIF receiver */
#define AK4358_ADDR 0x22 /* DAC */
/*
* GPIO pins
*/
#define GPIO_FREQ_MASK (3<<0)
#define GPIO_FREQ_32KHZ (0<<0)
#define GPIO_FREQ_44KHZ (1<<0)
#define GPIO_FREQ_48KHZ (2<<0)
#define GPIO_MULTI_MASK (3<<2)
#define GPIO_MULTI_4X (0<<2)
#define GPIO_MULTI_2X (1<<2)
#define GPIO_MULTI_1X (2<<2) /* also external */
#define GPIO_MULTI_HALF (3<<2)
#define GPIO_INTERNAL_CLOCK (1<<4)
#define GPIO_ANALOG_PRESENT (1<<5) /* RO only: 0 = present */
#define GPIO_RXMCLK_SEL (1<<7) /* must be 0 */
#define GPIO_AK5385A_CKS0 (1<<8)
#define GPIO_AK5385A_DFS0 (1<<9) /* swapped with DFS1 according doc? */
#define GPIO_AK5385A_DFS1 (1<<10)
#define GPIO_DIGOUT_MONITOR (1<<11) /* 1 = active */
#define GPIO_DIGIN_MONITOR (1<<12) /* 1 = active */
#define GPIO_ANAIN_MONITOR (1<<13) /* 1 = active */
#define GPIO_AK5385A_MCLK (1<<14) /* must be 0 */
#define GPIO_MUTE_CONTROL (1<<15) /* 0 = off, 1 = on */
static void juli_ak4114_write(void *private_data, unsigned char reg, unsigned char val)
{
snd_vt1724_write_i2c((ice1712_t *)private_data, AK4114_ADDR, reg, val);
}
static unsigned char juli_ak4114_read(void *private_data, unsigned char reg)
{
return snd_vt1724_read_i2c((ice1712_t *)private_data, AK4114_ADDR, reg);
}
/*
* AK4358 section
*/
static void juli_akm_lock(akm4xxx_t *ak, int chip)
{
}
static void juli_akm_unlock(akm4xxx_t *ak, int chip)
{
}
static void juli_akm_write(akm4xxx_t *ak, int chip,
unsigned char addr, unsigned char data)
{
ice1712_t *ice = ak->private_data[0];
snd_assert(chip == 0, return);
snd_vt1724_write_i2c(ice, AK4358_ADDR, addr, data);
}
/*
* change the rate of envy24HT, AK4358
*/
static void juli_akm_set_rate_val(akm4xxx_t *ak, unsigned int rate)
{
unsigned char old, tmp, dfs;
if (rate == 0) /* no hint - S/PDIF input is master, simply return */
return;
/* adjust DFS on codecs */
if (rate > 96000)
dfs = 2;
else if (rate > 48000)
dfs = 1;
else
dfs = 0;
tmp = snd_akm4xxx_get(ak, 0, 2);
old = (tmp >> 4) & 0x03;
if (old == dfs)
return;
/* reset DFS */
snd_akm4xxx_reset(ak, 1);
tmp = snd_akm4xxx_get(ak, 0, 2);
tmp &= ~(0x03 << 4);
tmp |= dfs << 4;
snd_akm4xxx_set(ak, 0, 2, tmp);
snd_akm4xxx_reset(ak, 0);
}
static akm4xxx_t akm_juli_dac __devinitdata = {
.type = SND_AK4358,
.num_dacs = 2,
.ops = {
.lock = juli_akm_lock,
.unlock = juli_akm_unlock,
.write = juli_akm_write,
.set_rate_val = juli_akm_set_rate_val
}
};
static int __devinit juli_add_controls(ice1712_t *ice)
{
return snd_ice1712_akm4xxx_build_controls(ice);
}
/*
* initialize the chip
*/
static int __devinit juli_init(ice1712_t *ice)
{
static unsigned char ak4114_init_vals[] = {
/* AK4117_REG_PWRDN */ AK4114_RST | AK4114_PWN | AK4114_OCKS0 | AK4114_OCKS1,
/* AK4114_REQ_FORMAT */ AK4114_DIF_I24I2S,
/* AK4114_REG_IO0 */ AK4114_TX1E,
/* AK4114_REG_IO1 */ AK4114_EFH_1024 | AK4114_DIT | AK4114_IPS(1),
/* AK4114_REG_INT0_MASK */ 0,
/* AK4114_REG_INT1_MASK */ 0
};
static unsigned char ak4114_init_txcsb[] = {
0x41, 0x02, 0x2c, 0x00, 0x00
};
int err;
akm4xxx_t *ak;
#if 0
for (err = 0; err < 0x20; err++)
juli_ak4114_read(ice, err);
juli_ak4114_write(ice, 0, 0x0f);
juli_ak4114_read(ice, 0);
juli_ak4114_read(ice, 1);
#endif
err = snd_ak4114_create(ice->card,
juli_ak4114_read,
juli_ak4114_write,
ak4114_init_vals, ak4114_init_txcsb,
ice, &ice->spec.juli.ak4114);
if (err < 0)
return err;
ice->spec.juli.analog = ice->gpio.get_data(ice) & GPIO_ANALOG_PRESENT;
if (ice->spec.juli.analog) {
printk(KERN_INFO "juli@: analog I/O detected\n");
ice->num_total_dacs = 2;
ice->num_total_adcs = 2;
ak = ice->akm = kcalloc(1, sizeof(akm4xxx_t), GFP_KERNEL);
if (! ak)
return -ENOMEM;
ice->akm_codecs = 1;
if ((err = snd_ice1712_akm4xxx_init(ak, &akm_juli_dac, NULL, ice)) < 0)
return err;
}
return 0;
}
/*
* Juli@ boards don't provide the EEPROM data except for the vendor IDs.
* hence the driver needs to sets up it properly.
*/
static unsigned char juli_eeprom[] __devinitdata = {
0x20, /* SYSCONF: clock 512, mpu401, 1xADC, 1xDACs */
0x80, /* ACLINK: I2S */
0xf8, /* I2S: vol, 96k, 24bit, 192k */
0xc3, /* SPDIF: out-en, out-int, spdif-in */
0x9f, /* GPIO_DIR */
0xff, /* GPIO_DIR1 */
0x7f, /* GPIO_DIR2 */
0x9f, /* GPIO_MASK */
0xff, /* GPIO_MASK1 */
0x7f, /* GPIO_MASK2 */
0x16, /* GPIO_STATE: internal clock, multiple 1x, 48kHz */
0x80, /* GPIO_STATE1: mute */
0x00, /* GPIO_STATE2 */
};
/* entry point */
struct snd_ice1712_card_info snd_vt1724_juli_cards[] __devinitdata = {
{
.subvendor = VT1724_SUBDEVICE_JULI,
.name = "ESI Juli@",
.model = "juli",
.chip_init = juli_init,
.build_controls = juli_add_controls,
.eeprom_size = sizeof(juli_eeprom),
.eeprom_data = juli_eeprom,
},
{ } /* terminator */
};
#ifndef __SOUND_JULI_H
#define __SOUND_JULI_H
#define JULI_DEVICE_DESC "{ESI,Juli@},"
#define VT1724_SUBDEVICE_JULI 0x31305345 /* Juli@ */
extern struct snd_ice1712_card_info snd_vt1724_juli_cards[];
#endif /* __SOUND_JULI_H */
......@@ -36,12 +36,12 @@
#include "prodigy192.h"
#include "stac946x.h"
static void stac9460_put(ice1712_t *ice, int reg, unsigned char val)
static inline void stac9460_put(ice1712_t *ice, int reg, unsigned char val)
{
snd_vt1724_write_i2c(ice, PRODIGY192_STAC9460_ADDR, reg, val);
}
static unsigned char stac9460_get(ice1712_t *ice, int reg)
static inline unsigned char stac9460_get(ice1712_t *ice, int reg)
{
return snd_vt1724_read_i2c(ice, PRODIGY192_STAC9460_ADDR, reg);
}
......
......@@ -33,6 +33,15 @@
#include "envy24ht.h"
#include "revo.h"
static void revo_i2s_mclk_changed(ice1712_t *ice)
{
/* assert PRST# to converters; MT05 bit 7 */
outb(inb(ICEMT1724(ice, AC97_CMD)) | 0x80, ICEMT1724(ice, AC97_CMD));
mdelay(5);
/* deassert PRST# */
outb(inb(ICEMT1724(ice, AC97_CMD)) & ~0x80, ICEMT1724(ice, AC97_CMD));
}
/*
* change the rate of envy24HT, AK4355 and AK4381
*/
......@@ -135,6 +144,8 @@ static int __devinit revo_init(ice1712_t *ice)
return -EINVAL;
}
ice->gpio.i2s_mclk_changed = revo_i2s_mclk_changed;
/* second stage of initialization, analog parts and others */
ak = ice->akm = kcalloc(2, sizeof(akm4xxx_t), GFP_KERNEL);
if (! ak)
......
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