Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 132777
b: refs/heads/master
c: 8a2cd61
h: refs/heads/master
i:
  132775: 2305f70
v: v3
  • Loading branch information
Mark Brown committed Jan 9, 2009
1 parent 5ed6882 commit 0607bc5
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 1649923dd52ce914be98bff0ae352344ef04f305
refs/heads/master: 8a2cd6180f8fa00111843c2f4a4f4361995358e0
32 changes: 32 additions & 0 deletions trunk/include/sound/soc.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ enum snd_soc_bias_level {
SND_SOC_BIAS_OFF,
};

struct snd_jack;
struct snd_soc_card;
struct snd_soc_device;
struct snd_soc_pcm_stream;
struct snd_soc_ops;
Expand All @@ -164,6 +166,8 @@ struct snd_soc_platform;
struct snd_soc_codec;
struct soc_enum;
struct snd_soc_ac97_ops;
struct snd_soc_jack;
struct snd_soc_jack_pin;

typedef int (*hw_write_t)(void *,const char* ,int);
typedef int (*hw_read_t)(void *,char* ,int);
Expand All @@ -184,6 +188,13 @@ int snd_soc_init_card(struct snd_soc_device *socdev);
int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
const struct snd_pcm_hardware *hw);

/* Jack reporting */
int snd_soc_jack_new(struct snd_soc_card *card, const char *id, int type,
struct snd_soc_jack *jack);
void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask);
int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count,
struct snd_soc_jack_pin *pins);

/* codec IO */
#define snd_soc_read(codec, reg) codec->read(codec, reg)
#define snd_soc_write(codec, reg, value) codec->write(codec, reg, value)
Expand Down Expand Up @@ -239,6 +250,27 @@ int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol);

/**
* struct snd_soc_jack_pin - Describes a pin to update based on jack detection
*
* @pin: name of the pin to update
* @mask: bits to check for in reported jack status
* @invert: if non-zero then pin is enabled when status is not reported
*/
struct snd_soc_jack_pin {
struct list_head list;
const char *pin;
int mask;
bool invert;
};

struct snd_soc_jack {
struct snd_jack *jack;
struct snd_soc_card *card;
struct list_head pins;
int status;
};

/* SoC PCM stream information */
struct snd_soc_pcm_stream {
char *stream_name;
Expand Down
1 change: 1 addition & 0 deletions trunk/sound/soc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ menuconfig SND_SOC
tristate "ALSA for SoC audio support"
select SND_PCM
select AC97_BUS if SND_SOC_AC97_BUS
select SND_JACK if INPUT=y || INPUT=SND
---help---

If you want ASoC support, you should say Y here and also to the
Expand Down
2 changes: 1 addition & 1 deletion trunk/sound/soc/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
snd-soc-core-objs := soc-core.o soc-dapm.o
snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o

obj-$(CONFIG_SND_SOC) += snd-soc-core.o
obj-$(CONFIG_SND_SOC) += codecs/
Expand Down
138 changes: 138 additions & 0 deletions trunk/sound/soc/soc-jack.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* soc-jack.c -- ALSA SoC jack handling
*
* Copyright 2008 Wolfson Microelectronics PLC.
*
* Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
*
* 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.
*/

#include <sound/jack.h>
#include <sound/soc.h>
#include <sound/soc-dapm.h>

/**
* snd_soc_jack_new - Create a new jack
* @card: ASoC card
* @id: an identifying string for this jack
* @type: a bitmask of enum snd_jack_type values that can be detected by
* this jack
* @jack: structure to use for the jack
*
* Creates a new jack object.
*
* Returns zero if successful, or a negative error code on failure.
* On success jack will be initialised.
*/
int snd_soc_jack_new(struct snd_soc_card *card, const char *id, int type,
struct snd_soc_jack *jack)
{
jack->card = card;
INIT_LIST_HEAD(&jack->pins);

return snd_jack_new(card->socdev->codec->card, id, type, &jack->jack);
}
EXPORT_SYMBOL_GPL(snd_soc_jack_new);

/**
* snd_soc_jack_report - Report the current status for a jack
*
* @jack: the jack
* @status: a bitmask of enum snd_jack_type values that are currently detected.
* @mask: a bitmask of enum snd_jack_type values that being reported.
*
* If configured using snd_soc_jack_add_pins() then the associated
* DAPM pins will be enabled or disabled as appropriate and DAPM
* synchronised.
*
* Note: This function uses mutexes and should be called from a
* context which can sleep (such as a workqueue).
*/
void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask)
{
struct snd_soc_codec *codec = jack->card->socdev->codec;
struct snd_soc_jack_pin *pin;
int enable;
int oldstatus;

if (!jack) {
WARN_ON_ONCE(!jack);
return;
}

mutex_lock(&codec->mutex);

oldstatus = jack->status;

jack->status &= ~mask;
jack->status |= status;

/* The DAPM sync is expensive enough to be worth skipping */
if (jack->status == oldstatus)
goto out;

list_for_each_entry(pin, &jack->pins, list) {
enable = pin->mask & status;

if (pin->invert)
enable = !enable;

if (enable)
snd_soc_dapm_enable_pin(codec, pin->pin);
else
snd_soc_dapm_disable_pin(codec, pin->pin);
}

snd_soc_dapm_sync(codec);

snd_jack_report(jack->jack, status);

out:
mutex_unlock(&codec->mutex);
}
EXPORT_SYMBOL_GPL(snd_soc_jack_report);

/**
* snd_soc_jack_add_pins - Associate DAPM pins with an ASoC jack
*
* @jack: ASoC jack
* @count: Number of pins
* @pins: Array of pins
*
* After this function has been called the DAPM pins specified in the
* pins array will have their status updated to reflect the current
* state of the jack whenever the jack status is updated.
*/
int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count,
struct snd_soc_jack_pin *pins)
{
int i;

for (i = 0; i < count; i++) {
if (!pins[i].pin) {
printk(KERN_ERR "No name for pin %d\n", i);
return -EINVAL;
}
if (!pins[i].mask) {
printk(KERN_ERR "No mask for pin %d (%s)\n", i,
pins[i].pin);
return -EINVAL;
}

INIT_LIST_HEAD(&pins[i].list);
list_add(&(pins[i].list), &jack->pins);
}

/* Update to reflect the last reported status; canned jack
* implementations are likely to set their state before the
* card has an opportunity to associate pins.
*/
snd_soc_jack_report(jack, 0, 0);

return 0;
}
EXPORT_SYMBOL_GPL(snd_soc_jack_add_pins);

0 comments on commit 0607bc5

Please sign in to comment.