Commit d43f3010 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: Add the driver for Digigram Lola PCI-e boards

Added a new driver for supporting Digigram Lola PCI-e boards.

Lola has a similar h/w design like HD-audio but with extended verbs.
Thus the driver is written similarly like HD-audio driver in the bus
part.  The codec part is rather written in a fixed way specific to the
Lola board because of the verb incompatibility.

The driver provides basic PCM, supporting multi-streams and mixing.
Signed-off-by: Takashi Iwai's avatarTakashi Iwai <tiwai@suse.de>
parent 521cb40b
......@@ -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
-------------------
......
......@@ -652,6 +652,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-m = 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 <sound/core.h>
#include <sound/pcm.h>
#include "lola.h"
static unsigned int 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 = 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 = 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 = 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"
/* direct codec access for debugging */
static void lola_proc_codec_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_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));
}
for (i = 0; i < 0x30; i += 4) {
snd_iprintf(buffer, "BAR1 %02x: %08x\n", i,
readl(chip->bar[BAR1].remap_addr + i));
}
for (i = 0x80; i < 0xa0; i += 4) {
snd_iprintf(buffer, "BAR1 %02x: %08x\n", i,
readl(chip->bar[BAR1].remap_addr + i));
}
}
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);
entry->mode |= S_IWUSR;
entry->c.text.write = lola_proc_codec_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