Commit b759b3ac authored by Takashi Iwai's avatar Takashi Iwai

Merge branch 'topic/lola' into for-linus

parents e28fb9c6 f428c94c
......@@ -1230,6 +1230,13 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
This module supports multiple cards.
The driver requires the firmware loader support on kernel.
Module snd-lola
---------------
Module for Digigram Lola PCI-e boards
This module supports multiple cards.
Module snd-lx6464es
-------------------
......
......@@ -658,6 +658,15 @@ config SND_KORG1212
To compile this driver as a module, choose M here: the module
will be called snd-korg1212.
config SND_LOLA
tristate "Digigram Lola"
select SND_PCM
help
Say Y to include support for Digigram Lola boards.
To compile this driver as a module, choose M here: the module
will be called snd-lola.
config SND_LX6464ES
tristate "Digigram LX6464ES"
select SND_PCM
......
......@@ -64,6 +64,7 @@ obj-$(CONFIG_SND) += \
ca0106/ \
cs46xx/ \
cs5535audio/ \
lola/ \
lx6464es/ \
echoaudio/ \
emu10k1/ \
......
snd-lola-y := lola.o lola_pcm.o lola_clock.o lola_mixer.o
snd-lola-$(CONFIG_SND_DEBUG) += lola_proc.o
obj-$(CONFIG_SND_LOLA) += snd-lola.o
This diff is collapsed.
This diff is collapsed.
/*
* Support for Digigram Lola PCI-e boards
*
* Copyright (c) 2011 Takashi Iwai <tiwai@suse.de>
*
* 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 <linux/kernel.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include "lola.h"
unsigned int lola_sample_rate_convert(unsigned int coded)
{
unsigned int freq;
/* base frequency */
switch (coded & 0x3) {
case 0: freq = 48000; break;
case 1: freq = 44100; break;
case 2: freq = 32000; break;
default: return 0; /* error */
}
/* multiplier / devisor */
switch (coded & 0x1c) {
case (0 << 2): break;
case (4 << 2): break;
case (1 << 2): freq *= 2; break;
case (2 << 2): freq *= 4; break;
case (5 << 2): freq /= 2; break;
case (6 << 2): freq /= 4; break;
default: return 0; /* error */
}
/* ajustement */
switch (coded & 0x60) {
case (0 << 5): break;
case (1 << 5): freq = (freq * 999) / 1000; break;
case (2 << 5): freq = (freq * 1001) / 1000; break;
default: return 0; /* error */
}
return freq;
}
/*
* Granualrity
*/
#define LOLA_MAXFREQ_AT_GRANULARITY_MIN 48000
#define LOLA_MAXFREQ_AT_GRANULARITY_BELOW_MAX 96000
static bool check_gran_clock_compatibility(struct lola *chip,
unsigned int val,
unsigned int freq)
{
if (!chip->granularity)
return true;
if (val < LOLA_GRANULARITY_MIN || val > LOLA_GRANULARITY_MAX ||
(val % LOLA_GRANULARITY_STEP) != 0)
return false;
if (val == LOLA_GRANULARITY_MIN) {
if (freq > LOLA_MAXFREQ_AT_GRANULARITY_MIN)
return false;
} else if (val < LOLA_GRANULARITY_MAX) {
if (freq > LOLA_MAXFREQ_AT_GRANULARITY_BELOW_MAX)
return false;
}
return true;
}
int lola_set_granularity(struct lola *chip, unsigned int val, bool force)
{
int err;
if (!force) {
if (val == chip->granularity)
return 0;
#if 0
/* change Gran only if there are no streams allocated ! */
if (chip->audio_in_alloc_mask || chip->audio_out_alloc_mask)
return -EBUSY;
#endif
if (!check_gran_clock_compatibility(chip, val,
chip->clock.cur_freq))
return -EINVAL;
}
chip->granularity = val;
val /= LOLA_GRANULARITY_STEP;
/* audio function group */
err = lola_codec_write(chip, 1, LOLA_VERB_SET_GRANULARITY_STEPS,
val, 0);
if (err < 0)
return err;
/* this can be a very slow function !!! */
usleep_range(400 * val, 20000);
return lola_codec_flush(chip);
}
/*
* Clock widget handling
*/
int __devinit lola_init_clock_widget(struct lola *chip, int nid)
{
unsigned int val;
int i, j, nitems, nb_verbs, idx, idx_list;
int err;
err = lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
if (err < 0) {
printk(KERN_ERR SFX "Can't read wcaps for 0x%x\n", nid);
return err;
}
if ((val & 0xfff00000) != 0x01f00000) { /* test SubType and Type */
snd_printdd("No valid clock widget\n");
return 0;
}
chip->clock.nid = nid;
chip->clock.items = val & 0xff;
snd_printdd("clock_list nid=%x, entries=%d\n", nid,
chip->clock.items);
if (chip->clock.items > MAX_SAMPLE_CLOCK_COUNT) {
printk(KERN_ERR SFX "CLOCK_LIST too big: %d\n",
chip->clock.items);
return -EINVAL;
}
nitems = chip->clock.items;
nb_verbs = (nitems + 3) / 4;
idx = 0;
idx_list = 0;
for (i = 0; i < nb_verbs; i++) {
unsigned int res_ex;
unsigned short items[4];
err = lola_codec_read(chip, nid, LOLA_VERB_GET_CLOCK_LIST,
idx, 0, &val, &res_ex);
if (err < 0) {
printk(KERN_ERR SFX "Can't read CLOCK_LIST\n");
return -EINVAL;
}
items[0] = val & 0xfff;
items[1] = (val >> 16) & 0xfff;
items[2] = res_ex & 0xfff;
items[3] = (res_ex >> 16) & 0xfff;
for (j = 0; j < 4; j++) {
unsigned char type = items[j] >> 8;
unsigned int freq = items[j] & 0xff;
int format = LOLA_CLOCK_FORMAT_NONE;
bool add_clock = true;
if (type == LOLA_CLOCK_TYPE_INTERNAL) {
freq = lola_sample_rate_convert(freq);
if (freq < chip->sample_rate_min)
add_clock = false;
else if (freq == 48000) {
chip->clock.cur_index = idx_list;
chip->clock.cur_freq = 48000;
chip->clock.cur_valid = true;
}
} else if (type == LOLA_CLOCK_TYPE_VIDEO) {
freq = lola_sample_rate_convert(freq);
if (freq < chip->sample_rate_min)
add_clock = false;
/* video clock has a format (0:NTSC, 1:PAL)*/
if (items[j] & 0x80)
format = LOLA_CLOCK_FORMAT_NTSC;
else
format = LOLA_CLOCK_FORMAT_PAL;
}
if (add_clock) {
struct lola_sample_clock *sc;
sc = &chip->clock.sample_clock[idx_list];
sc->type = type;
sc->format = format;
sc->freq = freq;
/* keep the index used with the board */
chip->clock.idx_lookup[idx_list] = idx;
idx_list++;
} else {
chip->clock.items--;
}
if (++idx >= nitems)
break;
}
}
return 0;
}
/* enable unsolicited events of the clock widget */
int lola_enable_clock_events(struct lola *chip)
{
unsigned int res;
int err;
err = lola_codec_read(chip, chip->clock.nid,
LOLA_VERB_SET_UNSOLICITED_ENABLE,
LOLA_UNSOLICITED_ENABLE | LOLA_UNSOLICITED_TAG,
0, &res, NULL);
if (err < 0)
return err;
if (res) {
printk(KERN_WARNING SFX "error in enable_clock_events %d\n",
res);
return -EINVAL;
}
return 0;
}
int lola_set_clock_index(struct lola *chip, unsigned int idx)
{
unsigned int res;
int err;
err = lola_codec_read(chip, chip->clock.nid,
LOLA_VERB_SET_CLOCK_SELECT,
chip->clock.idx_lookup[idx],
0, &res, NULL);
if (err < 0)
return err;
if (res) {
printk(KERN_WARNING SFX "error in set_clock %d\n", res);
return -EINVAL;
}
return 0;
}
bool lola_update_ext_clock_freq(struct lola *chip, unsigned int val)
{
unsigned int tag;
/* the current EXTERNAL clock information gets updated by interrupt
* with an unsolicited response
*/
if (!val)
return false;
tag = (val >> LOLA_UNSOL_RESP_TAG_OFFSET) & LOLA_UNSOLICITED_TAG_MASK;
if (tag != LOLA_UNSOLICITED_TAG)
return false;
/* only for current = external clocks */
if (chip->clock.sample_clock[chip->clock.cur_index].type !=
LOLA_CLOCK_TYPE_INTERNAL) {
chip->clock.cur_freq = lola_sample_rate_convert(val & 0x7f);
chip->clock.cur_valid = (val & 0x100) != 0;
}
return true;
}
int lola_set_clock(struct lola *chip, int idx)
{
int freq = 0;
bool valid = false;
if (idx == chip->clock.cur_index) {
/* current clock is allowed */
freq = chip->clock.cur_freq;
valid = chip->clock.cur_valid;
} else if (chip->clock.sample_clock[idx].type ==
LOLA_CLOCK_TYPE_INTERNAL) {
/* internal clocks allowed */
freq = chip->clock.sample_clock[idx].freq;
valid = true;
}
if (!freq || !valid)
return -EINVAL;
if (!check_gran_clock_compatibility(chip, chip->granularity, freq))
return -EINVAL;
if (idx != chip->clock.cur_index) {
int err = lola_set_clock_index(chip, idx);
if (err < 0)
return err;
/* update new settings */
chip->clock.cur_index = idx;
chip->clock.cur_freq = freq;
chip->clock.cur_valid = true;
}
return 0;
}
int lola_set_sample_rate(struct lola *chip, int rate)
{
int i;
if (chip->clock.cur_freq == rate && chip->clock.cur_valid)
return 0;
/* search for new dwClockIndex */
for (i = 0; i < chip->clock.items; i++) {
if (chip->clock.sample_clock[i].type == LOLA_CLOCK_TYPE_INTERNAL &&
chip->clock.sample_clock[i].freq == rate)
break;
}
if (i >= chip->clock.items)
return -EINVAL;
return lola_set_clock(chip, i);
}
This diff is collapsed.
This diff is collapsed.
/*
* Support for Digigram Lola PCI-e boards
*
* Copyright (c) 2011 Takashi Iwai <tiwai@suse.de>
*
* 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 <linux/kernel.h>
#include <linux/init.h>
#include <linux/io.h>
#include <sound/core.h>
#include <sound/info.h>
#include <sound/pcm.h>
#include "lola.h"
static void print_audio_widget(struct snd_info_buffer *buffer,
struct lola *chip, int nid, const char *name)
{
unsigned int val;
lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
snd_iprintf(buffer, "Node 0x%02x %s wcaps 0x%x\n", nid, name, val);
lola_read_param(chip, nid, LOLA_PAR_STREAM_FORMATS, &val);
snd_iprintf(buffer, " Formats: 0x%x\n", val);
}
static void print_pin_widget(struct snd_info_buffer *buffer,
struct lola *chip, int nid, unsigned int ampcap,
const char *name)
{
unsigned int val;
lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
snd_iprintf(buffer, "Node 0x%02x %s wcaps 0x%x\n", nid, name, val);
if (val == 0x00400200)
return;
lola_read_param(chip, nid, ampcap, &val);
snd_iprintf(buffer, " Amp-Caps: 0x%x\n", val);
snd_iprintf(buffer, " mute=%d, step-size=%d, steps=%d, ofs=%d\n",
LOLA_AMP_MUTE_CAPABLE(val),
LOLA_AMP_STEP_SIZE(val),
LOLA_AMP_NUM_STEPS(val),
LOLA_AMP_OFFSET(val));
lola_codec_read(chip, nid, LOLA_VERB_GET_MAX_LEVEL, 0, 0, &val, NULL);
snd_iprintf(buffer, " Max-level: 0x%x\n", val);
}
static void print_clock_widget(struct snd_info_buffer *buffer,
struct lola *chip, int nid)
{
int i, j, num_clocks;
unsigned int val;
lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
snd_iprintf(buffer, "Node 0x%02x [Clock] wcaps 0x%x\n", nid, val);
num_clocks = val & 0xff;
for (i = 0; i < num_clocks; i += 4) {
unsigned int res_ex;
unsigned short items[4];
const char *name;
lola_codec_read(chip, nid, LOLA_VERB_GET_CLOCK_LIST,
i, 0, &val, &res_ex);
items[0] = val & 0xfff;
items[1] = (val >> 16) & 0xfff;
items[2] = res_ex & 0xfff;
items[3] = (res_ex >> 16) & 0xfff;
for (j = 0; j < 4; j++) {
unsigned char type = items[j] >> 8;
unsigned int freq = items[j] & 0xff;
if (i + j >= num_clocks)
break;
if (type == LOLA_CLOCK_TYPE_INTERNAL) {
name = "Internal";
freq = lola_sample_rate_convert(freq);
} else if (type == LOLA_CLOCK_TYPE_VIDEO) {
name = "Video";
freq = lola_sample_rate_convert(freq);
} else {
name = "Other";
}
snd_iprintf(buffer, " Clock %d: Type %d:%s, freq=%d\n",
i + j, type, name, freq);
}
}
}
static void print_mixer_widget(struct snd_info_buffer *buffer,
struct lola *chip, int nid)
{
unsigned int val;
lola_read_param(chip, nid, LOLA_PAR_AUDIO_WIDGET_CAP, &val);
snd_iprintf(buffer, "Node 0x%02x [Mixer] wcaps 0x%x\n", nid, val);
}
static void lola_proc_codec_read(struct snd_info_entry *entry,
struct snd_info_buffer *buffer)
{
struct lola *chip = entry->private_data;
unsigned int val;
int i, nid;
lola_read_param(chip, 0, LOLA_PAR_VENDOR_ID, &val);
snd_iprintf(buffer, "Vendor: 0x%08x\n", val);
lola_read_param(chip, 1, LOLA_PAR_FUNCTION_TYPE, &val);
snd_iprintf(buffer, "Function Type: %d\n", val);
lola_read_param(chip, 1, LOLA_PAR_SPECIFIC_CAPS, &val);
snd_iprintf(buffer, "Specific-Caps: 0x%08x\n", val);
snd_iprintf(buffer, " Pins-In %d, Pins-Out %d\n",
chip->pin[CAPT].num_pins, chip->pin[PLAY].num_pins);
nid = 2;
for (i = 0; i < chip->pcm[CAPT].num_streams; i++, nid++)
print_audio_widget(buffer, chip, nid, "[Audio-In]");
for (i = 0; i < chip->pcm[PLAY].num_streams; i++, nid++)
print_audio_widget(buffer, chip, nid, "[Audio-Out]");
for (i = 0; i < chip->pin[CAPT].num_pins; i++, nid++)
print_pin_widget(buffer, chip, nid, LOLA_PAR_AMP_IN_CAP,
"[Pin-In]");
for (i = 0; i < chip->pin[PLAY].num_pins; i++, nid++)
print_pin_widget(buffer, chip, nid, LOLA_PAR_AMP_OUT_CAP,
"[Pin-Out]");
if (LOLA_AFG_CLOCK_WIDGET_PRESENT(chip->lola_caps)) {
print_clock_widget(buffer, chip, nid);
nid++;
}
if (LOLA_AFG_MIXER_WIDGET_PRESENT(chip->lola_caps)) {
print_mixer_widget(buffer, chip, nid);
nid++;
}
}
/* direct codec access for debugging */
static void lola_proc_codec_rw_write(struct snd_info_entry *entry,
struct snd_info_buffer *buffer)
{
struct lola *chip = entry->private_data;
char line[64];
unsigned int id, verb, data, extdata;
while (!snd_info_get_line(buffer, line, sizeof(line))) {
if (sscanf(line, "%i %i %i %i", &id, &verb, &data, &extdata) != 4)
continue;
lola_codec_read(chip, id, verb, data, extdata,
&chip->debug_res,
&chip->debug_res_ex);
}
}
static void lola_proc_codec_rw_read(struct snd_info_entry *entry,
struct snd_info_buffer *buffer)
{
struct lola *chip = entry->private_data;
snd_iprintf(buffer, "0x%x 0x%x\n", chip->debug_res, chip->debug_res_ex);
}
/*
* dump some registers
*/
static void lola_proc_regs_read(struct snd_info_entry *entry,
struct snd_info_buffer *buffer)
{
struct lola *chip = entry->private_data;
int i;
for (i = 0; i < 0x40; i += 4) {
snd_iprintf(buffer, "BAR0 %02x: %08x\n", i,
readl(chip->bar[BAR0].remap_addr + i));
}
snd_iprintf(buffer, "\n");
for (i = 0; i < 0x30; i += 4) {
snd_iprintf(buffer, "BAR1 %02x: %08x\n", i,
readl(chip->bar[BAR1].remap_addr + i));
}
snd_iprintf(buffer, "\n");
for (i = 0x80; i < 0xa0; i += 4) {
snd_iprintf(buffer, "BAR1 %02x: %08x\n", i,
readl(chip->bar[BAR1].remap_addr + i));
}
snd_iprintf(buffer, "\n");
for (i = 0; i < 32; i++) {
snd_iprintf(buffer, "DSD %02x STS %08x\n", i,
lola_dsd_read(chip, i, STS));
snd_iprintf(buffer, "DSD %02x LPIB %08x\n", i,
lola_dsd_read(chip, i, LPIB));
snd_iprintf(buffer, "DSD %02x CTL %08x\n", i,
lola_dsd_read(chip, i, CTL));
snd_iprintf(buffer, "DSD %02x LVIL %08x\n", i,
lola_dsd_read(chip, i, LVI));
snd_iprintf(buffer, "DSD %02x BDPL %08x\n", i,
lola_dsd_read(chip, i, BDPL));
snd_iprintf(buffer, "DSD %02x BDPU %08x\n", i,
lola_dsd_read(chip, i, BDPU));
}
}
void __devinit lola_proc_debug_new(struct lola *chip)
{
struct snd_info_entry *entry;
if (!snd_card_proc_new(chip->card, "codec", &entry))
snd_info_set_text_ops(entry, chip, lola_proc_codec_read);
if (!snd_card_proc_new(chip->card, "codec_rw", &entry)) {
snd_info_set_text_ops(entry, chip, lola_proc_codec_rw_read);
entry->mode |= S_IWUSR;
entry->c.text.write = lola_proc_codec_rw_write;
}
if (!snd_card_proc_new(chip->card, "regs", &entry))
snd_info_set_text_ops(entry, chip, lola_proc_regs_read);
}
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