All of lore.kernel.org
 help / color / mirror / Atom feed
* alsa-lib: snd_mixer_selem_is_active changes - which event?
@ 2011-02-15 19:07 Sebastian H.
  2011-02-16  8:38 ` Clemens Ladisch
  2011-04-16  2:02 ` Raymond Yau
  0 siblings, 2 replies; 10+ messages in thread
From: Sebastian H. @ 2011-02-15 19:07 UTC (permalink / raw)
  To: ALSA Development Mailing List

Hello

I wonder which event mask notifies an application that
snd_mixer_selem_is_active() may have changed.

SND_CTL_EVENT_MASK_VALUE
or
SND_CTL_EVENT_MASK_INFO

or something else?

I'd be glad for any insights?


Sebastian H.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: alsa-lib: snd_mixer_selem_is_active changes - which event?
  2011-02-16  8:38 ` Clemens Ladisch
@ 2011-02-16  8:38   ` Sebastian H.
  2011-02-16 11:03   ` Raymond Yau
  2011-02-18  1:54   ` Raymond Yau
  2 siblings, 0 replies; 10+ messages in thread
From: Sebastian H. @ 2011-02-16  8:38 UTC (permalink / raw)
  To: Clemens Ladisch; +Cc: ALSA Development Mailing List

Am 16.02.2011 09:38, schrieb Clemens Ladisch:
> Sebastian H. wrote:
>> I wonder which event mask notifies an application that
>> snd_mixer_selem_is_active() may have changed.
>>
>> SND_CTL_EVENT_MASK_VALUE
>> or
>> SND_CTL_EVENT_MASK_INFO
> 
> _VALUE is only for the value itself; all metadata changes
> generate an _INFO event.

Great, that justifies the removal of some bloated
constructions in qasmixer. :)

Thanks a lot!

Regards,
Sebastian H.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: alsa-lib: snd_mixer_selem_is_active changes - which event?
  2011-02-15 19:07 alsa-lib: snd_mixer_selem_is_active changes - which event? Sebastian H.
@ 2011-02-16  8:38 ` Clemens Ladisch
  2011-02-16  8:38   ` Sebastian H.
                     ` (2 more replies)
  2011-04-16  2:02 ` Raymond Yau
  1 sibling, 3 replies; 10+ messages in thread
From: Clemens Ladisch @ 2011-02-16  8:38 UTC (permalink / raw)
  To: Sebastian H.; +Cc: ALSA Development Mailing List

Sebastian H. wrote:
> I wonder which event mask notifies an application that
> snd_mixer_selem_is_active() may have changed.
> 
> SND_CTL_EVENT_MASK_VALUE
> or
> SND_CTL_EVENT_MASK_INFO

_VALUE is only for the value itself; all metadata changes
generate an _INFO event.


Regards,
Clemens

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: alsa-lib: snd_mixer_selem_is_active changes - which event?
  2011-02-16  8:38 ` Clemens Ladisch
  2011-02-16  8:38   ` Sebastian H.
@ 2011-02-16 11:03   ` Raymond Yau
  2011-02-18  1:54   ` Raymond Yau
  2 siblings, 0 replies; 10+ messages in thread
From: Raymond Yau @ 2011-02-16 11:03 UTC (permalink / raw)
  To: ALSA Development Mailing List

2011/2/16 Clemens Ladisch <clemens@ladisch.de>

> Sebastian H. wrote:
> > I wonder which event mask notifies an application that
> > snd_mixer_selem_is_active() may have changed.
> >
> > SND_CTL_EVENT_MASK_VALUE
> > or
> > SND_CTL_EVENT_MASK_INFO
>
> _VALUE is only for the value itself; all metadata changes
> generate an _INFO event.
>
>
I have doubt about the implementation of alsamixer is different from the
driver

If I add the "Independent HP Switch" which switch the connection of node
0x37 from DAC0 to DAC 1 for ad1988 multi streaming playback model and
activate_ctl(codec, "Headphone Playback Volume", spec->independent_hp )

Both "Headphone Playback Volume" and "Headphone playback Switch" are greyed
( inactive) in alsamixer when the independent HP switch is off , but the
driver only deactivate the "Headphone Playback Volume".

When I toggle the "Independnent HP switch" on and off , the headphone
controls does not change from active to inactive and vice versa


For qasmixer , the "headphone playback volume" and "headphone playback
switch" are disappeared when the Indepdent HP switch is off




static int ad1988_independent_hp_info(struct snd_kcontrol *kcontrol,
                   struct snd_ctl_elem_info *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 ad1988_independent_hp_get(struct snd_kcontrol *kcontrol,
                  struct snd_ctl_elem_value *ucontrol)
{
    struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
    struct ad198x_spec *spec = codec->spec;
    *ucontrol->value.integer.value = spec->independent_hp;
    return 0;
}

static void activate_ctl(struct hda_codec *codec, const char *name, int
active)
{
    struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
    if (ctl) {
        ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
        ctl->vd[0].access |= active
            ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
        snd_ctl_notify(codec->bus->card,
                   SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
    }
}

static int ad1988_independent_hp_put(struct snd_kcontrol *kcontrol,
                  struct snd_ctl_elem_value *ucontrol)
{
    struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
    struct ad198x_spec *spec = codec->spec;
    activate_ctl(codec, "Headphone Playback Volume",
            *ucontrol->value.integer.value);
    if ( spec->independent_hp !=  *ucontrol->value.integer.value ) {
            spec->independent_hp =  *ucontrol->value.integer.value;
        snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL,
            spec->independent_hp ? 0x00 : 0x01 );
        return 1;
    }
    return 0;
}


static struct snd_kcontrol_new ad1988_6stack_fp_mixers[] = {
    HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
    {
        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
        .name = "Independent HP",
        .info = ad1988_independent_hp_info,
        .get = ad1988_independent_hp_get,
        .put = ad1988_independent_hp_put,
    },
    { } /* end */
};

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: alsa-lib: snd_mixer_selem_is_active changes - which event?
  2011-02-16  8:38 ` Clemens Ladisch
  2011-02-16  8:38   ` Sebastian H.
  2011-02-16 11:03   ` Raymond Yau
@ 2011-02-18  1:54   ` Raymond Yau
  2011-02-28 14:56     ` Clemens Ladisch
  2 siblings, 1 reply; 10+ messages in thread
From: Raymond Yau @ 2011-02-18  1:54 UTC (permalink / raw)
  To: ALSA Development Mailing List

[-- Attachment #1: Type: text/plain, Size: 575 bytes --]

2011/2/16 Clemens Ladisch <clemens@ladisch.de>

> Sebastian H. wrote:
> > I wonder which event mask notifies an application that
> > snd_mixer_selem_is_active() may have changed.
> >
> > SND_CTL_EVENT_MASK_VALUE
> > or
> > SND_CTL_EVENT_MASK_INFO
>
> _VALUE is only for the value itself; all metadata changes
> generate an _INFO event.
>
>
> Regards,
> Clemens
>


Patch which fix the display of active/inactive controls in alsamixer

but the problem both "Headphone Playback Volume" and "Headphone Playback
Switch" are inactive still not solved using the customised dummy.c

[-- Attachment #2: 0001-Fix-alsamixer-to-display-active-inactive-controls.patch --]
[-- Type: application/octet-stream, Size: 1027 bytes --]

From afa69c6a07eae3ce1eef3a439ec7f266d290c749 Mon Sep 17 00:00:00 2001
From: Raymond Yau <superquad.vortex2@gmail.com>
Date: Fri, 18 Feb 2011 09:34:51 +0800
Subject: [[PATCH] alsamixer - fix display of active/inactive coFix alsamixer to display active/inactive controls


Signed-off-by: Raymond Yau <superquad.vortex2@gmail.com>

diff --git a/alsamixer/mixer_widget.c b/alsamixer/mixer_widget.c
index fb352d3..77b39f0 100644
--- a/alsamixer/mixer_widget.c
+++ b/alsamixer/mixer_widget.c
@@ -59,10 +59,18 @@ enum channel_mask {
 
 static int elem_callback(snd_mixer_elem_t *elem, unsigned int mask)
 {
+	int i;
 	if (mask & (SND_CTL_EVENT_MASK_REMOVE |
 		    SND_CTL_EVENT_MASK_INFO |
 		    SND_CTL_EVENT_MASK_VALUE))
 		controls_changed = TRUE;
+	if (mask & SND_CTL_EVENT_MASK_INFO)
+		for (i = 0; i < controls_count; ++i)
+			if (controls[i].elem == elem) {
+				controls[i].flags &= ~IS_ACTIVE;
+				if (snd_mixer_selem_is_active(controls[i].elem))
+					controls[i].flags |= IS_ACTIVE;
+			}
 	return 0;
 }
 
-- 
1.6.0.6


[-- Attachment #3: dummy.c --]
[-- Type: text/x-csrc, Size: 35367 bytes --]

/*
 *  Dummy soundcard
 *  Copyright (c) by Jaroslav Kysela <perex@perex.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 <linux/init.h>
#include <linux/err.h>
#include <linux/platform_device.h>
#include <linux/jiffies.h>
#include <linux/slab.h>
#include <linux/time.h>
#include <linux/wait.h>
#include <linux/hrtimer.h>
#include <linux/math64.h>
#include <linux/moduleparam.h>
#include <sound/core.h>
#include <sound/control.h>
#include <sound/tlv.h>
#include <sound/pcm.h>
#include <sound/rawmidi.h>
#include <sound/info.h>
#include <sound/initval.h>

MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
MODULE_DESCRIPTION("Dummy soundcard (/dev/null)");
MODULE_LICENSE("GPL");
MODULE_SUPPORTED_DEVICE("{{ALSA,Dummy soundcard}}");

#define MAX_PCM_DEVICES		4
#define MAX_PCM_SUBSTREAMS	128
#define MAX_MIDI_DEVICES	2

/* defaults */
#define MAX_BUFFER_SIZE		(64*1024)
#define MIN_PERIOD_SIZE		64
#define MAX_PERIOD_SIZE		MAX_BUFFER_SIZE
#define USE_FORMATS 		(SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE)
#define USE_RATE		SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000
#define USE_RATE_MIN		5500
#define USE_RATE_MAX		48000
#define USE_CHANNELS_MIN 	1
#define USE_CHANNELS_MAX 	2
#define USE_PERIODS_MIN 	1
#define USE_PERIODS_MAX 	1024

static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;	/* Index 0-MAX */
static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;	/* ID for this card */
static int enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 0};
static char *model[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = NULL};
static int pcm_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
static int pcm_substreams[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 8};
//static int midi_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
#ifdef CONFIG_HIGH_RES_TIMERS
static int hrtimer = 1;
#endif
static int fake_buffer = 1;

module_param_array(index, int, NULL, 0444);
MODULE_PARM_DESC(index, "Index value for dummy soundcard.");
module_param_array(id, charp, NULL, 0444);
MODULE_PARM_DESC(id, "ID string for dummy soundcard.");
module_param_array(enable, bool, NULL, 0444);
MODULE_PARM_DESC(enable, "Enable this dummy soundcard.");
module_param_array(model, charp, NULL, 0444);
MODULE_PARM_DESC(model, "Soundcard model.");
module_param_array(pcm_devs, int, NULL, 0444);
MODULE_PARM_DESC(pcm_devs, "PCM devices # (0-4) for dummy driver.");
module_param_array(pcm_substreams, int, NULL, 0444);
MODULE_PARM_DESC(pcm_substreams, "PCM substreams # (1-128) for dummy driver.");
//module_param_array(midi_devs, int, NULL, 0444);
//MODULE_PARM_DESC(midi_devs, "MIDI devices # (0-2) for dummy driver.");
module_param(fake_buffer, bool, 0444);
MODULE_PARM_DESC(fake_buffer, "Fake buffer allocations.");
#ifdef CONFIG_HIGH_RES_TIMERS
module_param(hrtimer, bool, 0644);
MODULE_PARM_DESC(hrtimer, "Use hrtimer as the timer source.");
#endif

static struct platform_device *devices[SNDRV_CARDS];

#define MIXER_ADDR_MASTER	0
#define MIXER_ADDR_LINE		1
#define MIXER_ADDR_MIC		2
#define MIXER_ADDR_SYNTH	3
#define MIXER_ADDR_CD		4
#define MIXER_ADDR_HP           5
#define MIXER_ADDR_LAST		5

struct dummy_timer_ops {
	int (*create)(struct snd_pcm_substream *);
	void (*free)(struct snd_pcm_substream *);
	int (*prepare)(struct snd_pcm_substream *);
	int (*start)(struct snd_pcm_substream *);
	int (*stop)(struct snd_pcm_substream *);
	snd_pcm_uframes_t (*pointer)(struct snd_pcm_substream *);
};

struct dummy_model {
	const char *name;
	int (*playback_constraints)(struct snd_pcm_runtime *runtime);
	int (*capture_constraints)(struct snd_pcm_runtime *runtime);
	u64 formats;
	size_t buffer_bytes_max;
	size_t period_bytes_min;
	size_t period_bytes_max;
	unsigned int periods_min;
	unsigned int periods_max;
	unsigned int rates;
	unsigned int rate_min;
	unsigned int rate_max;
	unsigned int channels_min;
	unsigned int channels_max;
};

struct snd_dummy {
	struct snd_card *card;
	struct dummy_model *model;
	struct snd_pcm *pcm;
	struct snd_pcm_hardware pcm_hw;
	spinlock_t mixer_lock;
	int mixer_volume[MIXER_ADDR_LAST+1][2];
	int capture_source[MIXER_ADDR_LAST+1][2];
	const struct dummy_timer_ops *timer_ops;
        int independent_hp;
};

/*
 * card models
 */

static int emu10k1_playback_constraints(struct snd_pcm_runtime *runtime)
{
	int err;
	err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
	if (err < 0)
		return err;
	err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 256, UINT_MAX);
	if (err < 0)
		return err;
	return 0;
}

struct dummy_model model_emu10k1 = {
	.name = "emu10k1",
	.playback_constraints = emu10k1_playback_constraints,
	.buffer_bytes_max = 128 * 1024,
};

struct dummy_model model_rme9652 = {
	.name = "rme9652",
	.buffer_bytes_max = 26 * 64 * 1024,
	.formats = SNDRV_PCM_FMTBIT_S32_LE,
	.channels_min = 26,
	.channels_max = 26,
	.periods_min = 2,
	.periods_max = 2,
};

struct dummy_model model_ice1712 = {
	.name = "ice1712",
	.buffer_bytes_max = 256 * 1024,
	.formats = SNDRV_PCM_FMTBIT_S32_LE,
	.channels_min = 10,
	.channels_max = 10,
	.periods_min = 1,
	.periods_max = 1024,
};

struct dummy_model model_uda1341 = {
	.name = "uda1341",
	.buffer_bytes_max = 16380,
	.formats = SNDRV_PCM_FMTBIT_S16_LE,
	.channels_min = 2,
	.channels_max = 2,
	.periods_min = 2,
	.periods_max = 255,
};

struct dummy_model model_ac97 = {
	.name = "ac97",
	.formats = SNDRV_PCM_FMTBIT_S16_LE,
	.channels_min = 2,
	.channels_max = 2,
	.rates = SNDRV_PCM_RATE_48000,
	.rate_min = 48000,
	.rate_max = 48000,
};

struct dummy_model model_ca0106 = {
	.name = "ca0106",
	.formats = SNDRV_PCM_FMTBIT_S16_LE,
	.buffer_bytes_max = ((65536-64)*8),
	.period_bytes_max = (65536-64),
	.periods_min = 2,
	.periods_max = 8,
	.channels_min = 2,
	.channels_max = 2,
	.rates = SNDRV_PCM_RATE_48000|SNDRV_PCM_RATE_96000|SNDRV_PCM_RATE_192000,
	.rate_min = 48000,
	.rate_max = 192000,
};

static struct snd_ratden es1371_dac_clock = {
	.num_min = 3000 * (1 << 15),
	.num_max = 48000 * (1 << 15),
	.num_step = 3000,
	.den = 1 << 15,
};

static struct snd_pcm_hw_constraint_ratdens snd_es1371_hw_constraints_dac_clock = {
	.nrats = 1,
	.rats = &es1371_dac_clock,
};

static struct snd_ratnum es1371_adc_clock = {
	.num = 48000 << 15,
	.den_min = 32768, 
	.den_max = 393216,
	.den_step = 1,
};

static struct snd_pcm_hw_constraint_ratnums snd_es1371_hw_constraints_adc_clock = {
	.nrats = 1,
	.rats = &es1371_adc_clock,
};

static int ens1371_playback_constraints(struct snd_pcm_runtime *runtime)
{
	snd_pcm_hw_constraint_ratdens(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
				      &snd_es1371_hw_constraints_dac_clock);
	snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
				   32);
	snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
				   32);
	return 0;
}

static int ens1371_capture_constraints(struct snd_pcm_runtime *runtime)
{
	snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
				      &snd_es1371_hw_constraints_adc_clock);
	snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
				   32);
	snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
				   32);
	return 0;
}

struct dummy_model model_ens1371 = {
	.name = "ens1371",
	.formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
	.buffer_bytes_max =	(128*1024),
	.period_bytes_min =	64,
	.period_bytes_max =	(128*1024),
	.periods_min =		1,
	.periods_max =		1024,
	.channels_min = 1,
	.channels_max = 2,
	.rates = SNDRV_PCM_RATE_KNOT | 	/* 5512Hz rate */
				 SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_22050 | 
				 SNDRV_PCM_RATE_44100,
	.rate_min =		4000,
	.rate_max =		48000,
	.playback_constraints = ens1371_playback_constraints,
	.capture_constraints = ens1371_capture_constraints,
};

struct dummy_model *dummy_models[] = {
	&model_emu10k1,
	&model_rme9652,
	&model_ice1712,
	&model_uda1341,
	&model_ac97,
	&model_ca0106,
        &model_ens1371,
	NULL
};

/*
 * system timer interface
 */

struct dummy_systimer_pcm {
	spinlock_t lock;
	struct timer_list timer;
	unsigned long base_time;
	unsigned int frac_pos;	/* fractional sample position (based HZ) */
	unsigned int frac_period_rest;
	unsigned int frac_buffer_size;	/* buffer_size * HZ */
	unsigned int frac_period_size;	/* period_size * HZ */
	unsigned int rate;
	int elapsed;
	struct snd_pcm_substream *substream;
};

static void dummy_systimer_rearm(struct dummy_systimer_pcm *dpcm)
{
	dpcm->timer.expires = jiffies +
		(dpcm->frac_period_rest + dpcm->rate - 1) / dpcm->rate;
	add_timer(&dpcm->timer);
}

static void dummy_systimer_update(struct dummy_systimer_pcm *dpcm)
{
	unsigned long delta;

	delta = jiffies - dpcm->base_time;
	if (!delta)
		return;
	dpcm->base_time += delta;
	delta *= dpcm->rate;
	dpcm->frac_pos += delta;
	while (dpcm->frac_pos >= dpcm->frac_buffer_size)
		dpcm->frac_pos -= dpcm->frac_buffer_size;
	while (dpcm->frac_period_rest <= delta) {
		dpcm->elapsed++;
		dpcm->frac_period_rest += dpcm->frac_period_size;
	}
	dpcm->frac_period_rest -= delta;
}

static int dummy_systimer_start(struct snd_pcm_substream *substream)
{
	struct dummy_systimer_pcm *dpcm = substream->runtime->private_data;
	spin_lock(&dpcm->lock);
	dpcm->base_time = jiffies;
	dummy_systimer_rearm(dpcm);
	spin_unlock(&dpcm->lock);
	return 0;
}

static int dummy_systimer_stop(struct snd_pcm_substream *substream)
{
	struct dummy_systimer_pcm *dpcm = substream->runtime->private_data;
	spin_lock(&dpcm->lock);
	del_timer(&dpcm->timer);
	spin_unlock(&dpcm->lock);
	return 0;
}

static int dummy_systimer_prepare(struct snd_pcm_substream *substream)
{
	struct snd_pcm_runtime *runtime = substream->runtime;
	struct dummy_systimer_pcm *dpcm = runtime->private_data;

	dpcm->frac_pos = 0;
	dpcm->rate = runtime->rate;
	dpcm->frac_buffer_size = runtime->buffer_size * HZ;
	dpcm->frac_period_size = runtime->period_size * HZ;
	dpcm->frac_period_rest = dpcm->frac_period_size;
	dpcm->elapsed = 0;

	return 0;
}

static void dummy_systimer_callback(unsigned long data)
{
	struct dummy_systimer_pcm *dpcm = (struct dummy_systimer_pcm *)data;
	unsigned long flags;
	int elapsed = 0;
	
	spin_lock_irqsave(&dpcm->lock, flags);
	dummy_systimer_update(dpcm);
	dummy_systimer_rearm(dpcm);
	elapsed = dpcm->elapsed;
	dpcm->elapsed = 0;
	spin_unlock_irqrestore(&dpcm->lock, flags);
	if (elapsed)
		snd_pcm_period_elapsed(dpcm->substream);
}

static snd_pcm_uframes_t
dummy_systimer_pointer(struct snd_pcm_substream *substream)
{
	struct dummy_systimer_pcm *dpcm = substream->runtime->private_data;
	snd_pcm_uframes_t pos;

	spin_lock(&dpcm->lock);
	dummy_systimer_update(dpcm);
	pos = dpcm->frac_pos / HZ;
	spin_unlock(&dpcm->lock);
	return pos;
}

static int dummy_systimer_create(struct snd_pcm_substream *substream)
{
	struct dummy_systimer_pcm *dpcm;

	dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);
	if (!dpcm)
		return -ENOMEM;
	substream->runtime->private_data = dpcm;
	init_timer(&dpcm->timer);
	dpcm->timer.data = (unsigned long) dpcm;
	dpcm->timer.function = dummy_systimer_callback;
	spin_lock_init(&dpcm->lock);
	dpcm->substream = substream;
	return 0;
}

static void dummy_systimer_free(struct snd_pcm_substream *substream)
{
	kfree(substream->runtime->private_data);
}

static struct dummy_timer_ops dummy_systimer_ops = {
	.create =	dummy_systimer_create,
	.free =		dummy_systimer_free,
	.prepare =	dummy_systimer_prepare,
	.start =	dummy_systimer_start,
	.stop =		dummy_systimer_stop,
	.pointer =	dummy_systimer_pointer,
};

#ifdef CONFIG_HIGH_RES_TIMERS
/*
 * hrtimer interface
 */

struct dummy_hrtimer_pcm {
	ktime_t base_time;
	ktime_t period_time;
	atomic_t running;
	struct hrtimer timer;
	struct tasklet_struct tasklet;
	struct snd_pcm_substream *substream;
};

static void dummy_hrtimer_pcm_elapsed(unsigned long priv)
{
	struct dummy_hrtimer_pcm *dpcm = (struct dummy_hrtimer_pcm *)priv;
	if (atomic_read(&dpcm->running))
		snd_pcm_period_elapsed(dpcm->substream);
}

static enum hrtimer_restart dummy_hrtimer_callback(struct hrtimer *timer)
{
	struct dummy_hrtimer_pcm *dpcm;

	dpcm = container_of(timer, struct dummy_hrtimer_pcm, timer);
	if (!atomic_read(&dpcm->running))
		return HRTIMER_NORESTART;
	tasklet_schedule(&dpcm->tasklet);
	hrtimer_forward_now(timer, dpcm->period_time);
	return HRTIMER_RESTART;
}

static int dummy_hrtimer_start(struct snd_pcm_substream *substream)
{
	struct dummy_hrtimer_pcm *dpcm = substream->runtime->private_data;

	dpcm->base_time = hrtimer_cb_get_time(&dpcm->timer);
	hrtimer_start(&dpcm->timer, dpcm->period_time, HRTIMER_MODE_REL);
	atomic_set(&dpcm->running, 1);
	return 0;
}

static int dummy_hrtimer_stop(struct snd_pcm_substream *substream)
{
	struct dummy_hrtimer_pcm *dpcm = substream->runtime->private_data;

	atomic_set(&dpcm->running, 0);
	hrtimer_cancel(&dpcm->timer);
	return 0;
}

static inline void dummy_hrtimer_sync(struct dummy_hrtimer_pcm *dpcm)
{
	tasklet_kill(&dpcm->tasklet);
}

static snd_pcm_uframes_t
dummy_hrtimer_pointer(struct snd_pcm_substream *substream)
{
	struct snd_pcm_runtime *runtime = substream->runtime;
	struct dummy_hrtimer_pcm *dpcm = runtime->private_data;
	u64 delta;
	u32 pos;

	delta = ktime_us_delta(hrtimer_cb_get_time(&dpcm->timer),
			       dpcm->base_time);
	delta = div_u64(delta * runtime->rate + 999999, 1000000);
	div_u64_rem(delta, runtime->buffer_size, &pos);
	return pos;
}

static int dummy_hrtimer_prepare(struct snd_pcm_substream *substream)
{
	struct snd_pcm_runtime *runtime = substream->runtime;
	struct dummy_hrtimer_pcm *dpcm = runtime->private_data;
	unsigned int period, rate;
	long sec;
	unsigned long nsecs;

	dummy_hrtimer_sync(dpcm);
	period = runtime->period_size;
	rate = runtime->rate;
	sec = period / rate;
	period %= rate;
	nsecs = div_u64((u64)period * 1000000000UL + rate - 1, rate);
	dpcm->period_time = ktime_set(sec, nsecs);

	return 0;
}

static int dummy_hrtimer_create(struct snd_pcm_substream *substream)
{
	struct dummy_hrtimer_pcm *dpcm;

	dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);
	if (!dpcm)
		return -ENOMEM;
	substream->runtime->private_data = dpcm;
	hrtimer_init(&dpcm->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
	dpcm->timer.function = dummy_hrtimer_callback;
	dpcm->substream = substream;
	atomic_set(&dpcm->running, 0);
	tasklet_init(&dpcm->tasklet, dummy_hrtimer_pcm_elapsed,
		     (unsigned long)dpcm);
	return 0;
}

static void dummy_hrtimer_free(struct snd_pcm_substream *substream)
{
	struct dummy_hrtimer_pcm *dpcm = substream->runtime->private_data;
	dummy_hrtimer_sync(dpcm);
	kfree(dpcm);
}

static struct dummy_timer_ops dummy_hrtimer_ops = {
	.create =	dummy_hrtimer_create,
	.free =		dummy_hrtimer_free,
	.prepare =	dummy_hrtimer_prepare,
	.start =	dummy_hrtimer_start,
	.stop =		dummy_hrtimer_stop,
	.pointer =	dummy_hrtimer_pointer,
};

#endif /* CONFIG_HIGH_RES_TIMERS */

/*
 * PCM interface
 */

static int dummy_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
{
	struct snd_dummy *dummy = snd_pcm_substream_chip(substream);

	switch (cmd) {
	case SNDRV_PCM_TRIGGER_START:
	case SNDRV_PCM_TRIGGER_RESUME:
		return dummy->timer_ops->start(substream);
	case SNDRV_PCM_TRIGGER_STOP:
	case SNDRV_PCM_TRIGGER_SUSPEND:
		return dummy->timer_ops->stop(substream);
	}
	return -EINVAL;
}

static int dummy_pcm_prepare(struct snd_pcm_substream *substream)
{
	struct snd_dummy *dummy = snd_pcm_substream_chip(substream);

	return dummy->timer_ops->prepare(substream);
}

static snd_pcm_uframes_t dummy_pcm_pointer(struct snd_pcm_substream *substream)
{
	struct snd_dummy *dummy = snd_pcm_substream_chip(substream);

	return dummy->timer_ops->pointer(substream);
}

static struct snd_pcm_hardware dummy_pcm_hardware = {
	.info =			(SNDRV_PCM_INFO_MMAP |
				 SNDRV_PCM_INFO_INTERLEAVED |
				 SNDRV_PCM_INFO_RESUME |
				 SNDRV_PCM_INFO_MMAP_VALID),
	.formats =		USE_FORMATS,
	.rates =		USE_RATE,
	.rate_min =		USE_RATE_MIN,
	.rate_max =		USE_RATE_MAX,
	.channels_min =		USE_CHANNELS_MIN,
	.channels_max =		USE_CHANNELS_MAX,
	.buffer_bytes_max =	MAX_BUFFER_SIZE,
	.period_bytes_min =	MIN_PERIOD_SIZE,
	.period_bytes_max =	MAX_PERIOD_SIZE,
	.periods_min =		USE_PERIODS_MIN,
	.periods_max =		USE_PERIODS_MAX,
	.fifo_size =		0,
};

static int dummy_pcm_hw_params(struct snd_pcm_substream *substream,
			       struct snd_pcm_hw_params *hw_params)
{
	if (fake_buffer) {
		/* runtime->dma_bytes has to be set manually to allow mmap */
		substream->runtime->dma_bytes = params_buffer_bytes(hw_params);
		return 0;
	}
	return snd_pcm_lib_malloc_pages(substream,
					params_buffer_bytes(hw_params));
}

static int dummy_pcm_hw_free(struct snd_pcm_substream *substream)
{
	if (fake_buffer)
		return 0;
	return snd_pcm_lib_free_pages(substream);
}

static struct snd_kcontrol * snd_dummy_find_mixer_ctl(struct snd_card *card,
			const char *name, int idx)
{
	struct snd_ctl_elem_id id;
	memset(&id, 0, sizeof(id));
	id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
	id.index = idx;
	strcpy(id.name, name);
	return snd_ctl_find_id(card, &id);
}

static void activate_ctl(struct snd_card *card, const char *name, int
active)
{
    struct snd_kcontrol *ctl = snd_dummy_find_mixer_ctl(card, name, 0);
    if (ctl) {
        ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
        ctl->vd[0].access |= active
            ? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
        ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_WRITE;
        ctl->vd[0].access |= active
            ? SNDRV_CTL_ELEM_ACCESS_WRITE : 0;
        snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
    }
}

static int dummy_pcm_open(struct snd_pcm_substream *substream)
{
	struct snd_dummy *dummy = snd_pcm_substream_chip(substream);
	struct dummy_model *model = dummy->model;
	struct snd_pcm_runtime *runtime = substream->runtime;
	int err;
	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 
		if (substream->number == 1 )
			activate_ctl(dummy->card,"Independent HP",0);

	dummy->timer_ops = &dummy_systimer_ops;
#ifdef CONFIG_HIGH_RES_TIMERS
	if (hrtimer)
		dummy->timer_ops = &dummy_hrtimer_ops;
#endif

	err = dummy->timer_ops->create(substream);
	if (err < 0)
		return err;

	runtime->hw = dummy->pcm_hw;
	if (substream->pcm->device & 1) {
		runtime->hw.info &= ~SNDRV_PCM_INFO_INTERLEAVED;
		runtime->hw.info |= SNDRV_PCM_INFO_NONINTERLEAVED;
	}
	if (substream->pcm->device & 2)
		runtime->hw.info &= ~(SNDRV_PCM_INFO_MMAP |
				      SNDRV_PCM_INFO_MMAP_VALID);

	if (model == NULL)
		return 0;

	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
		if (model->playback_constraints)
			err = model->playback_constraints(substream->runtime);
	} else {
		if (model->capture_constraints)
			err = model->capture_constraints(substream->runtime);
	}
	if (err < 0) {
		dummy->timer_ops->free(substream);
		return err;
	}
	return 0;
}

static int dummy_pcm_close(struct snd_pcm_substream *substream)
{
	struct snd_dummy *dummy = snd_pcm_substream_chip(substream);
	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 
		if (substream->number == 1 )
			activate_ctl(dummy->card,"Independent HP",1);
	dummy->timer_ops->free(substream);
	return 0;
}

/*
 * dummy buffer handling
 */

static void *dummy_page[2];

static void free_fake_buffer(void)
{
	if (fake_buffer) {
		int i;
		for (i = 0; i < 2; i++)
			if (dummy_page[i]) {
				free_page((unsigned long)dummy_page[i]);
				dummy_page[i] = NULL;
			}
	}
}

static int alloc_fake_buffer(void)
{
	int i;

	if (!fake_buffer)
		return 0;
	for (i = 0; i < 2; i++) {
		dummy_page[i] = (void *)get_zeroed_page(GFP_KERNEL);
		if (!dummy_page[i]) {
			free_fake_buffer();
			return -ENOMEM;
		}
	}
	return 0;
}

static int dummy_pcm_copy(struct snd_pcm_substream *substream,
			  int channel, snd_pcm_uframes_t pos,
			  void __user *dst, snd_pcm_uframes_t count)
{
	return 0; /* do nothing */
}

static int dummy_pcm_silence(struct snd_pcm_substream *substream,
			     int channel, snd_pcm_uframes_t pos,
			     snd_pcm_uframes_t count)
{
	return 0; /* do nothing */
}

static struct page *dummy_pcm_page(struct snd_pcm_substream *substream,
				   unsigned long offset)
{
	return virt_to_page(dummy_page[substream->stream]); /* the same page */
}

static struct snd_pcm_ops dummy_pcm_ops = {
	.open =		dummy_pcm_open,
	.close =	dummy_pcm_close,
	.ioctl =	snd_pcm_lib_ioctl,
	.hw_params =	dummy_pcm_hw_params,
	.hw_free =	dummy_pcm_hw_free,
	.prepare =	dummy_pcm_prepare,
	.trigger =	dummy_pcm_trigger,
	.pointer =	dummy_pcm_pointer,
};

static struct snd_pcm_ops dummy_pcm_ops_no_buf = {
	.open =		dummy_pcm_open,
	.close =	dummy_pcm_close,
	.ioctl =	snd_pcm_lib_ioctl,
	.hw_params =	dummy_pcm_hw_params,
	.hw_free =	dummy_pcm_hw_free,
	.prepare =	dummy_pcm_prepare,
	.trigger =	dummy_pcm_trigger,
	.pointer =	dummy_pcm_pointer,
	.copy =		dummy_pcm_copy,
	.silence =	dummy_pcm_silence,
	.page =		dummy_pcm_page,
};

static int __devinit snd_card_dummy_pcm(struct snd_dummy *dummy, int device,
					int substreams)
{
	struct snd_pcm *pcm;
	struct snd_pcm_ops *ops;
	int err;

	err = snd_pcm_new(dummy->card, "Dummy PCM", device,
			       substreams, substreams, &pcm);
	if (err < 0)
		return err;
	dummy->pcm = pcm;
	if (fake_buffer)
		ops = &dummy_pcm_ops_no_buf;
	else
		ops = &dummy_pcm_ops;
	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, ops);
	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, ops);
	pcm->private_data = dummy;
	pcm->info_flags = 0;
	strcpy(pcm->name, "Dummy PCM");
	if (!fake_buffer) {
		snd_pcm_lib_preallocate_pages_for_all(pcm,
			SNDRV_DMA_TYPE_CONTINUOUS,
			snd_dma_continuous_data(GFP_KERNEL),
			0, 64*1024);
	}
	return 0;
}

/*
 * mixer interface
 */

#define DUMMY_VOLUME(xname, xindex, addr) \
{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
  .name = xname, .index = xindex, \
  .info = snd_dummy_volume_info, \
  .get = snd_dummy_volume_get, .put = snd_dummy_volume_put, \
  .private_value = addr, \
  .tlv = { .p = db_scale_dummy } }

static int snd_dummy_volume_info(struct snd_kcontrol *kcontrol,
				 struct snd_ctl_elem_info *uinfo)
{
	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
	uinfo->count = 2;
	uinfo->value.integer.min = -50;
	uinfo->value.integer.max = 100;
	return 0;
}
 
static int snd_dummy_volume_get(struct snd_kcontrol *kcontrol,
				struct snd_ctl_elem_value *ucontrol)
{
	struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
	int addr = kcontrol->private_value;

	spin_lock_irq(&dummy->mixer_lock);
	ucontrol->value.integer.value[0] = dummy->mixer_volume[addr][0];
	ucontrol->value.integer.value[1] = dummy->mixer_volume[addr][1];
	spin_unlock_irq(&dummy->mixer_lock);
	return 0;
}

static int snd_dummy_volume_put(struct snd_kcontrol *kcontrol,
				struct snd_ctl_elem_value *ucontrol)
{
	struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
	int change, addr = kcontrol->private_value;
	int left, right;

	left = ucontrol->value.integer.value[0];
	if (left < -50)
		left = -50;
	if (left > 100)
		left = 100;
	right = ucontrol->value.integer.value[1];
	if (right < -50)
		right = -50;
	if (right > 100)
		right = 100;
	spin_lock_irq(&dummy->mixer_lock);
	change = dummy->mixer_volume[addr][0] != left ||
	         dummy->mixer_volume[addr][1] != right;
	dummy->mixer_volume[addr][0] = left;
	dummy->mixer_volume[addr][1] = right;
	spin_unlock_irq(&dummy->mixer_lock);
	return change;
}

static const DECLARE_TLV_DB_SCALE(db_scale_dummy, -4500, 30, 0);

#define DUMMY_CAPSRC(xname, xindex, addr) \
{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
  .info = snd_dummy_capsrc_info, \
  .get = snd_dummy_capsrc_get, .put = snd_dummy_capsrc_put, \
  .private_value = addr }

#define snd_dummy_capsrc_info	snd_ctl_boolean_stereo_info
 
static int snd_dummy_capsrc_get(struct snd_kcontrol *kcontrol,
				struct snd_ctl_elem_value *ucontrol)
{
	struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
	int addr = kcontrol->private_value;

	spin_lock_irq(&dummy->mixer_lock);
	ucontrol->value.integer.value[0] = dummy->capture_source[addr][0];
	ucontrol->value.integer.value[1] = dummy->capture_source[addr][1];
	spin_unlock_irq(&dummy->mixer_lock);
	return 0;
}

static int snd_dummy_capsrc_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{
	struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
	int change, addr = kcontrol->private_value;
	int left, right;

	left = ucontrol->value.integer.value[0] & 1;
	right = ucontrol->value.integer.value[1] & 1;
	spin_lock_irq(&dummy->mixer_lock);
	change = dummy->capture_source[addr][0] != left &&
	         dummy->capture_source[addr][1] != right;
	dummy->capture_source[addr][0] = left;
	dummy->capture_source[addr][1] = right;
	spin_unlock_irq(&dummy->mixer_lock);
	return change;
}

static int snd_dummy_independent_hp_info(struct snd_kcontrol *kcontrol,
                   struct snd_ctl_elem_info *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_dummy_independent_hp_get(struct snd_kcontrol *kcontrol,
                  struct snd_ctl_elem_value *ucontrol)
{
    struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
    *ucontrol->value.integer.value = dummy->independent_hp;
    return 0;
}


static int snd_dummy_independent_hp_put(struct snd_kcontrol *kcontrol,
                  struct snd_ctl_elem_value *ucontrol)
{
    struct snd_dummy *dummy = snd_kcontrol_chip(kcontrol);
    int changed;
    changed = (dummy->independent_hp !=  *ucontrol->value.integer.value);
    dummy->independent_hp =  *ucontrol->value.integer.value;
    activate_ctl(dummy->card, "Headphone Playback Volume", dummy->independent_hp);
    return changed;
}

static struct snd_kcontrol_new snd_dummy_controls[] = {
DUMMY_VOLUME("Master Volume", 0, MIXER_ADDR_MASTER),
DUMMY_CAPSRC("Master Switch", 0, MIXER_ADDR_MASTER),
DUMMY_VOLUME("Synth Volume", 0, MIXER_ADDR_SYNTH),
DUMMY_CAPSRC("Synth Switch", 0, MIXER_ADDR_SYNTH),
DUMMY_VOLUME("Line Volume", 0, MIXER_ADDR_LINE),
DUMMY_CAPSRC("Line Switch", 0, MIXER_ADDR_LINE),
DUMMY_VOLUME("Mic Volume", 0, MIXER_ADDR_MIC),
DUMMY_CAPSRC("Mic Switch", 0, MIXER_ADDR_MIC),
DUMMY_VOLUME("CD Volume", 0, MIXER_ADDR_CD),
DUMMY_CAPSRC("CD Switch", 0, MIXER_ADDR_CD),
DUMMY_VOLUME("Headphone Playback Volume", 0, MIXER_ADDR_HP),
DUMMY_CAPSRC("Headphone Playback Switch", 0, MIXER_ADDR_HP),
    {
        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
        .name = "Independent HP",
        .info = snd_dummy_independent_hp_info,
        .get = snd_dummy_independent_hp_get,
        .put = snd_dummy_independent_hp_put,
    }
};

static int __devinit snd_card_dummy_new_mixer(struct snd_dummy *dummy)
{
	struct snd_card *card = dummy->card;
	unsigned int idx;
	int err;

	spin_lock_init(&dummy->mixer_lock);
	strcpy(card->mixername, "Dummy Mixer");
        dummy->independent_hp=1;
	for (idx = 0; idx < ARRAY_SIZE(snd_dummy_controls); idx++) {
		err = snd_ctl_add(card, snd_ctl_new1(&snd_dummy_controls[idx], dummy));
		if (err < 0)
			return err;
	}
	return 0;
}

#if defined(CONFIG_SND_DEBUG) && defined(CONFIG_PROC_FS)
/*
 * proc interface
 */
static void print_formats(struct snd_dummy *dummy,
			  struct snd_info_buffer *buffer)
{
	int i;

	for (i = 0; i < SNDRV_PCM_FORMAT_LAST; i++) {
		if (dummy->pcm_hw.formats & (1ULL << i))
			snd_iprintf(buffer, " %s", snd_pcm_format_name(i));
	}
}

static void print_rates(struct snd_dummy *dummy,
			struct snd_info_buffer *buffer)
{
	static int rates[] = {
		5512, 8000, 11025, 16000, 22050, 32000, 44100, 48000,
		64000, 88200, 96000, 176400, 192000,
	};
	int i;

	if (dummy->pcm_hw.rates & SNDRV_PCM_RATE_CONTINUOUS)
		snd_iprintf(buffer, " continuous");
	if (dummy->pcm_hw.rates & SNDRV_PCM_RATE_KNOT)
		snd_iprintf(buffer, " knot");
	for (i = 0; i < ARRAY_SIZE(rates); i++)
		if (dummy->pcm_hw.rates & (1 << i))
			snd_iprintf(buffer, " %d", rates[i]);
}

#define get_dummy_int_ptr(dummy, ofs) \
	(unsigned int *)((char *)&((dummy)->pcm_hw) + (ofs))
#define get_dummy_ll_ptr(dummy, ofs) \
	(unsigned long long *)((char *)&((dummy)->pcm_hw) + (ofs))

struct dummy_hw_field {
	const char *name;
	const char *format;
	unsigned int offset;
	unsigned int size;
};
#define FIELD_ENTRY(item, fmt) {		   \
	.name = #item,				   \
	.format = fmt,				   \
	.offset = offsetof(struct snd_pcm_hardware, item), \
	.size = sizeof(dummy_pcm_hardware.item) }

static struct dummy_hw_field fields[] = {
	FIELD_ENTRY(formats, "%#llx"),
	FIELD_ENTRY(rates, "%#x"),
	FIELD_ENTRY(rate_min, "%d"),
	FIELD_ENTRY(rate_max, "%d"),
	FIELD_ENTRY(channels_min, "%d"),
	FIELD_ENTRY(channels_max, "%d"),
	FIELD_ENTRY(buffer_bytes_max, "%ld"),
	FIELD_ENTRY(period_bytes_min, "%ld"),
	FIELD_ENTRY(period_bytes_max, "%ld"),
	FIELD_ENTRY(periods_min, "%d"),
	FIELD_ENTRY(periods_max, "%d"),
};

static void dummy_proc_read(struct snd_info_entry *entry,
			    struct snd_info_buffer *buffer)
{
	struct snd_dummy *dummy = entry->private_data;
	int i;

	for (i = 0; i < ARRAY_SIZE(fields); i++) {
		snd_iprintf(buffer, "%s ", fields[i].name);
		if (fields[i].size == sizeof(int))
			snd_iprintf(buffer, fields[i].format,
				*get_dummy_int_ptr(dummy, fields[i].offset));
		else
			snd_iprintf(buffer, fields[i].format,
				*get_dummy_ll_ptr(dummy, fields[i].offset));
		if (!strcmp(fields[i].name, "formats"))
			print_formats(dummy, buffer);
		else if (!strcmp(fields[i].name, "rates"))
			print_rates(dummy, buffer);
		snd_iprintf(buffer, "\n");
	}
}

static void dummy_proc_write(struct snd_info_entry *entry,
			     struct snd_info_buffer *buffer)
{
	struct snd_dummy *dummy = entry->private_data;
	char line[64];

	while (!snd_info_get_line(buffer, line, sizeof(line))) {
		char item[20];
		const char *ptr;
		unsigned long long val;
		int i;

		ptr = snd_info_get_str(item, line, sizeof(item));
		for (i = 0; i < ARRAY_SIZE(fields); i++) {
			if (!strcmp(item, fields[i].name))
				break;
		}
		if (i >= ARRAY_SIZE(fields))
			continue;
		snd_info_get_str(item, ptr, sizeof(item));
		if (strict_strtoull(item, 0, &val))
			continue;
		if (fields[i].size == sizeof(int))
			*get_dummy_int_ptr(dummy, fields[i].offset) = val;
		else
			*get_dummy_ll_ptr(dummy, fields[i].offset) = val;
	}
}

static void __devinit dummy_proc_init(struct snd_dummy *chip)
{
	struct snd_info_entry *entry;

	if (!snd_card_proc_new(chip->card, "dummy_pcm", &entry)) {
		snd_info_set_text_ops(entry, chip, dummy_proc_read);
		entry->c.text.write = dummy_proc_write;
		entry->mode |= S_IWUSR;
		entry->private_data = chip;
	}
}
#else
#define dummy_proc_init(x)
#endif /* CONFIG_SND_DEBUG && CONFIG_PROC_FS */

static int __devinit snd_dummy_probe(struct platform_device *devptr)
{
	struct snd_card *card;
	struct snd_dummy *dummy;
	struct dummy_model *m = NULL, **mdl;
	int idx, err;
	int dev = devptr->id;

	err = snd_card_create(index[dev], id[dev], THIS_MODULE,
			      sizeof(struct snd_dummy), &card);
	if (err < 0)
		return err;
	dummy = card->private_data;
	dummy->card = card;
	for (mdl = dummy_models; *mdl && model[dev]; mdl++) {
		if (strcmp(model[dev], (*mdl)->name) == 0) {
			printk(KERN_INFO
				"snd-dummy: Using model '%s' for card %i\n",
				(*mdl)->name, card->number);
			m = dummy->model = *mdl;
			break;
		}
	}
	for (idx = 0; idx < MAX_PCM_DEVICES && idx < pcm_devs[dev]; idx++) {
		if (pcm_substreams[dev] < 1)
			pcm_substreams[dev] = 1;
		if (pcm_substreams[dev] > MAX_PCM_SUBSTREAMS)
			pcm_substreams[dev] = MAX_PCM_SUBSTREAMS;
		err = snd_card_dummy_pcm(dummy, idx, pcm_substreams[dev]);
		if (err < 0)
			goto __nodev;
	}

	dummy->pcm_hw = dummy_pcm_hardware;
	if (m) {
		if (m->formats)
			dummy->pcm_hw.formats = m->formats;
		if (m->buffer_bytes_max)
			dummy->pcm_hw.buffer_bytes_max = m->buffer_bytes_max;
		if (m->period_bytes_min)
			dummy->pcm_hw.period_bytes_min = m->period_bytes_min;
		if (m->period_bytes_max)
			dummy->pcm_hw.period_bytes_max = m->period_bytes_max;
		if (m->periods_min)
			dummy->pcm_hw.periods_min = m->periods_min;
		if (m->periods_max)
			dummy->pcm_hw.periods_max = m->periods_max;
		if (m->rates)
			dummy->pcm_hw.rates = m->rates;
		if (m->rate_min)
			dummy->pcm_hw.rate_min = m->rate_min;
		if (m->rate_max)
			dummy->pcm_hw.rate_max = m->rate_max;
		if (m->channels_min)
			dummy->pcm_hw.channels_min = m->channels_min;
		if (m->channels_max)
			dummy->pcm_hw.channels_max = m->channels_max;
	}

	err = snd_card_dummy_new_mixer(dummy);
	if (err < 0)
		goto __nodev;
	strcpy(card->driver, "Dummy");
	strcpy(card->shortname, "Dummy");
	sprintf(card->longname, "Dummy %i", dev + 1);

	dummy_proc_init(dummy);

	snd_card_set_dev(card, &devptr->dev);

	err = snd_card_register(card);
	if (err == 0) {
		platform_set_drvdata(devptr, card);
		return 0;
	}
      __nodev:
	snd_card_free(card);
	return err;
}

static int __devexit snd_dummy_remove(struct platform_device *devptr)
{
	snd_card_free(platform_get_drvdata(devptr));
	platform_set_drvdata(devptr, NULL);
	return 0;
}

#ifdef CONFIG_PM
static int snd_dummy_suspend(struct platform_device *pdev, pm_message_t state)
{
	struct snd_card *card = platform_get_drvdata(pdev);
	struct snd_dummy *dummy = card->private_data;

	snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
	snd_pcm_suspend_all(dummy->pcm);
	return 0;
}
	
static int snd_dummy_resume(struct platform_device *pdev)
{
	struct snd_card *card = platform_get_drvdata(pdev);

	snd_power_change_state(card, SNDRV_CTL_POWER_D0);
	return 0;
}
#endif

#define SND_DUMMY_DRIVER	"snd_dummy"

static struct platform_driver snd_dummy_driver = {
	.probe		= snd_dummy_probe,
	.remove		= __devexit_p(snd_dummy_remove),
#ifdef CONFIG_PM
	.suspend	= snd_dummy_suspend,
	.resume		= snd_dummy_resume,
#endif
	.driver		= {
		.name	= SND_DUMMY_DRIVER
	},
};

static void snd_dummy_unregister_all(void)
{
	int i;

	for (i = 0; i < ARRAY_SIZE(devices); ++i)
		platform_device_unregister(devices[i]);
	platform_driver_unregister(&snd_dummy_driver);
	free_fake_buffer();
}

static int __init alsa_card_dummy_init(void)
{
	int i, cards, err;

	err = platform_driver_register(&snd_dummy_driver);
	if (err < 0)
		return err;

	err = alloc_fake_buffer();
	if (err < 0) {
		platform_driver_unregister(&snd_dummy_driver);
		return err;
	}

	cards = 0;
	for (i = 0; i < SNDRV_CARDS; i++) {
		struct platform_device *device;
		if (! enable[i])
			continue;
		device = platform_device_register_simple(SND_DUMMY_DRIVER,
							 i, NULL, 0);
		if (IS_ERR(device))
			continue;
		if (!platform_get_drvdata(device)) {
			platform_device_unregister(device);
			continue;
		}
		devices[i] = device;
		cards++;
	}
	if (!cards) {
#ifdef MODULE
		printk(KERN_ERR "Dummy soundcard not found or device busy\n");
#endif
		snd_dummy_unregister_all();
		return -ENODEV;
	}
	return 0;
}

static void __exit alsa_card_dummy_exit(void)
{
	snd_dummy_unregister_all();
}

module_init(alsa_card_dummy_init)
module_exit(alsa_card_dummy_exit)

[-- Attachment #4: Type: text/plain, Size: 160 bytes --]

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: alsa-lib: snd_mixer_selem_is_active changes - which event?
  2011-02-18  1:54   ` Raymond Yau
@ 2011-02-28 14:56     ` Clemens Ladisch
  2011-03-11 13:10       ` Raymond Yau
  0 siblings, 1 reply; 10+ messages in thread
From: Clemens Ladisch @ 2011-02-28 14:56 UTC (permalink / raw)
  To: Raymond Yau; +Cc: ALSA Development Mailing List

Raymond Yau wrote:
> Patch which fix the display of active/inactive controls in alsamixer

Applied, thanks.


Clemens

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: alsa-lib: snd_mixer_selem_is_active changes - which event?
  2011-02-28 14:56     ` Clemens Ladisch
@ 2011-03-11 13:10       ` Raymond Yau
  0 siblings, 0 replies; 10+ messages in thread
From: Raymond Yau @ 2011-03-11 13:10 UTC (permalink / raw)
  To: ALSA Development Mailing List

[-- Attachment #1: Type: text/plain, Size: 771 bytes --]

2011/2/28 Clemens Ladisch <clemens@ladisch.de>

> Raymond Yau wrote:
> > Patch which fix the display of active/inactive controls in alsamixer
>
> Applied, thanks.
>
>
> Clemens
>


To really fix the problem, may need to add snd_mixer_selem_xxxxx_
is_active() functions for those controls (where xxxx are. playback_volume,
playback_switch, capture_volume ,capture_switch, .... )

For example ad1988 allow multistreaming , The current "6stack-dig-fp" model
just add the "Headphone Playback Volume" on DAC0 (i.e. node 0x03) and device
2 for multistreaming playback using front panel headphone.

Adding a new "independent HP" switch to allow routing the front panel
headphone back to DAC1 like the "6stack-dig" or auto model need to make
"Headphone Playback Volume" inactive

[-- Attachment #2: 0001-Add-snd_mixer_selem_xxx_is_active-functions.patch --]
[-- Type: application/octet-stream, Size: 3515 bytes --]

From 9e121b0fc9abe5b20d29e93e89dba018fda5050a Mon Sep 17 00:00:00 2001
From: Raymond Yau <superquad.vortex2@gmail.com>
Date: Fri, 11 Mar 2011 11:39:28 +0800
Subject: [[RFC] patch alsa-lib 1/1] Add snd_mixer_selem_xxx_is_active functions

This allow application know which control of mixer selem is active/inactive

Signed-off-by: Raymond Yau <superquad.vortex2@gmail.com>

diff --git a/include/mixer.h b/include/mixer.h
index 58256a6..a931446 100644
--- a/include/mixer.h
+++ b/include/mixer.h
@@ -231,6 +231,10 @@ snd_mixer_elem_t *snd_mixer_find_selem(snd_mixer_t *mixer,
 				       const snd_mixer_selem_id_t *id);
 
 int snd_mixer_selem_is_active(snd_mixer_elem_t *elem);
+int snd_mixer_selem_capture_switch_is_active(snd_mixer_elem_t *elem);
+int snd_mixer_selem_capture_volume_is_active(snd_mixer_elem_t *elem);
+int snd_mixer_selem_playback_switch_is_active(snd_mixer_elem_t *elem);
+int snd_mixer_selem_playback_volume_is_active(snd_mixer_elem_t *elem);
 int snd_mixer_selem_is_playback_mono(snd_mixer_elem_t *elem);
 int snd_mixer_selem_has_playback_channel(snd_mixer_elem_t *obj, snd_mixer_selem_channel_id_t channel);
 int snd_mixer_selem_is_capture_mono(snd_mixer_elem_t *elem);
diff --git a/src/mixer/simple.c b/src/mixer/simple.c
index 8079fe7..eb572fa 100644
--- a/src/mixer/simple.c
+++ b/src/mixer/simple.c
@@ -247,6 +247,34 @@ int snd_mixer_selem_is_active(snd_mixer_elem_t *elem)
 	return sm_selem_ops(elem)->is(elem, SM_PLAY, SM_OPS_IS_ACTIVE, 0);
 }
 
+int snd_mixer_selem_playback_volume_is_active(snd_mixer_elem_t *elem)
+{
+	CHECK_BASIC(elem);
+	CHECK_DIR(elem, SM_CAP_PVOLUME);
+	return sm_selem_ops(elem)->is(elem, SM_PLAY, SM_OPS_IS_ACTIVE, SM_CAP_PVOLUME);
+}
+
+int snd_mixer_selem_playback_switch_is_active(snd_mixer_elem_t *elem)
+{
+	CHECK_BASIC(elem);
+	CHECK_DIR(elem, SM_CAP_PSWITCH);
+	return sm_selem_ops(elem)->is(elem, SM_PLAY, SM_OPS_IS_ACTIVE, SM_CAP_PSWITCH);
+}
+
+int snd_mixer_selem_capture_volume_is_active(snd_mixer_elem_t *elem)
+{
+	CHECK_BASIC(elem);
+	CHECK_DIR(elem, SM_CAP_CVOLUME);
+	return sm_selem_ops(elem)->is(elem, SM_CAPT, SM_OPS_IS_ACTIVE, SM_CAP_CVOLUME);
+}
+
+int snd_mixer_selem_capture_switch_is_active(snd_mixer_elem_t *elem)
+{
+	CHECK_BASIC(elem);
+	CHECK_DIR(elem, SM_CAP_CSWITCH);
+	return sm_selem_ops(elem)->is(elem, SM_CAPT, SM_OPS_IS_ACTIVE, SM_CAP_CSWITCH);
+}
+
 /**
  * \brief Get info about channels of playback stream of a mixer simple element
  * \param elem Mixer simple element handle
diff --git a/src/mixer/simple_none.c b/src/mixer/simple_none.c
index 395e4d6..957363f 100644
--- a/src/mixer/simple_none.c
+++ b/src/mixer/simple_none.c
@@ -1000,9 +1000,32 @@ static int is_ops(snd_mixer_elem_t *elem, int dir, int cmd, int val)
 
 	case SM_OPS_IS_ACTIVE: {
 		selem_ctl_type_t ctl;
-		for (ctl = CTL_SINGLE; ctl <= CTL_LAST; ctl++)
-			if (s->ctls[ctl].elem != NULL && s->ctls[ctl].inactive)
-				return 0;
+		if (val == 0) {
+			for (ctl = CTL_SINGLE; ctl <= CTL_LAST; ctl++)
+				if (s->ctls[ctl].elem != NULL && s->ctls[ctl].inactive)
+					return 0;    
+		}
+		else {
+			switch(val){
+			case SM_CAP_PVOLUME:
+				ctl=CTL_PLAYBACK_VOLUME;
+				break;
+			case SM_CAP_PSWITCH:
+				ctl=CTL_PLAYBACK_SWITCH;
+				break;
+			case SM_CAP_CVOLUME:
+				ctl=CTL_CAPTURE_VOLUME;
+				break;
+			case SM_CAP_CSWITCH:
+				ctl=CTL_CAPTURE_SWITCH;
+				break;
+			default:
+				return 1;
+			};
+			if (ctl <= CTL_LAST)
+				if (s->ctls[ctl].elem != NULL && s->ctls[ctl].inactive)
+				return 0;
+		}
 		return 1;
 	}
 
-- 
1.6.0.6


[-- Attachment #3: Type: text/plain, Size: 160 bytes --]

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: alsa-lib: snd_mixer_selem_is_active changes - which event?
  2011-02-15 19:07 alsa-lib: snd_mixer_selem_is_active changes - which event? Sebastian H.
  2011-02-16  8:38 ` Clemens Ladisch
@ 2011-04-16  2:02 ` Raymond Yau
  2011-04-17 12:06   ` Sebastian H.
  1 sibling, 1 reply; 10+ messages in thread
From: Raymond Yau @ 2011-04-16  2:02 UTC (permalink / raw)
  To: Sebastian H., ALSA Development Mailing List

2011/2/16 Sebastian H. <vand2@gmx.de>

> Hello
>
> I wonder which event mask notifies an application that
> snd_mixer_selem_is_active() may have changed.
>
> SND_CTL_EVENT_MASK_VALUE
> or
> SND_CTL_EVENT_MASK_INFO
>
> or something else?
>
> I'd be glad for any insights?
>
>
qasmixer display the following message when play audio through front device
of emu10k1

alsa_callback_hctl_elem: Unknown mask ( 3 )
[EE] snd_hctl_handle_events : Operation not permitted


which event mask "SND_CTL_EVENT_MASK_VALUE" or "SND_CTL_EVENT_MASK_VALUE "
should the mixer application handle first ?

e.g. it is possible that the driver may change access of  the control

 & ~SNDRV_CTL_ELEM_ACCESS_READ

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: alsa-lib: snd_mixer_selem_is_active changes - which event?
  2011-04-16  2:02 ` Raymond Yau
@ 2011-04-17 12:06   ` Sebastian H.
  2011-04-17 12:09     ` Sebastian H.
  0 siblings, 1 reply; 10+ messages in thread
From: Sebastian H. @ 2011-04-17 12:06 UTC (permalink / raw)
  To: Raymond Yau; +Cc: ALSA Development Mailing List

>> I wonder which event mask notifies an application that
>> snd_mixer_selem_is_active() may have changed.
>>
>> SND_CTL_EVENT_MASK_VALUE
>> or
>> SND_CTL_EVENT_MASK_INFO
>>
>> or something else?
>>
>> I'd be glad for any insights?
>>
>>
> qasmixer display the following message when play audio through front device
> of emu10k1
> 
> alsa_callback_hctl_elem: Unknown mask ( 3 )
> [EE] snd_hctl_handle_events : Operation not permitted

This is actually a bug in qasmixer.
Up to now it could not handle multi event masks.

Mask 3 seems to be
SND_CTL_EVENT_MASK_VALUE & SND_CTL_EVENT_MASK_INFO ( 1 & 2 )
but qasmixer checks for
( mask == SND_CTL_EVENT_MASK_VALUE ) ||
( mask == SND_CTL_EVENT_MASK_INFO )
which fails as ( 3 == 1 ) || ( 3 == 2 ) == false;

That should be fixed now.
A new version should be around next week.
You could also try the development version in the sourceforge mercurial
repo.

> which event mask "SND_CTL_EVENT_MASK_VALUE" or "SND_CTL_EVENT_MASK_VALUE "
> should the mixer application handle first ?

IMO the order doesn't matter as long as both events are handled properly
and the displayed mixer state equals the system mixer state
afterwards.

> e.g. it is possible that the driver may change access of  the control
> 
>  & ~SNDRV_CTL_ELEM_ACCESS_READ

If that triggers a SND_CTL_EVENT_MASK_INFO event it shouldn't be a
problem in the coming version 0.11.0.

Sebastian H.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: alsa-lib: snd_mixer_selem_is_active changes - which event?
  2011-04-17 12:06   ` Sebastian H.
@ 2011-04-17 12:09     ` Sebastian H.
  0 siblings, 0 replies; 10+ messages in thread
From: Sebastian H. @ 2011-04-17 12:09 UTC (permalink / raw)
  To: Raymond Yau; +Cc: ALSA Development Mailing List

Am 17.04.2011 14:06, schrieb Sebastian H.:

> Mask 3 seems to be
> SND_CTL_EVENT_MASK_VALUE & SND_CTL_EVENT_MASK_INFO ( 1 & 2 )
Better
SND_CTL_EVENT_MASK_VALUE | SND_CTL_EVENT_MASK_INFO ( 1 | 2 )

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2011-04-17 12:09 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-15 19:07 alsa-lib: snd_mixer_selem_is_active changes - which event? Sebastian H.
2011-02-16  8:38 ` Clemens Ladisch
2011-02-16  8:38   ` Sebastian H.
2011-02-16 11:03   ` Raymond Yau
2011-02-18  1:54   ` Raymond Yau
2011-02-28 14:56     ` Clemens Ladisch
2011-03-11 13:10       ` Raymond Yau
2011-04-16  2:02 ` Raymond Yau
2011-04-17 12:06   ` Sebastian H.
2011-04-17 12:09     ` Sebastian H.

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.