Skip to contentSkip to conversation

ALSA: jack: Refactoring for jack kctls

PATCH Superseded Jie Yang 4 participants 16 messages Apr 23, 2015 – Apr 27, 2015

Subsystems (4)

v9 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Jie Yang

author
#0 lore raw

v9 cover ALSA: jack: Refactoring for jack kctls

Currently only hda will create kctls for hda jacks, for asoc, people may need create jack kctls in specific driver.

Here we are introducing kctls for each jack, by creating kctls and add them to jack controls list (considering exist of combo jack). At the same time, we will report events for each control in the list.

With this new implementation, both HDA and soc jack kctls works fine, they are compatible for old HDA jack kctls, too.

For soc,
a. snd_jack_new() with NULL jack_kctl;
b. for each pin, call snd_jack_add_kctls() to add one kctl(it will call snd_ctl_add() to add kctl to card);

For HDA,
With snd_jack_new(), we can use phantom_jack = true for phantom jack creating, and the jack kctl pointer will be filled with the new created kcontrol.

Changes in v9:
1. move struct snd_jack_kctl definition to jack.c, to hides the internal implementation details;
2. some small code fixing;
3. update documentation file.

Changes in v8:
1. remove snd_jack_kctl from HDA part, change snd_jack_new param to use bool for creating kcontrol at jack creating stage;
2. create jack for phantom jack, with no input device;
3. remove HDA jack get_unique_index() and index related code.

Changes in v7:
1. move name generating and index getting part into ctljack.c;
2. remove exposing private_data and destructor to hda, then jack core can handle kctls by itself totally.
3. some small code fixing.

Changes in v6:
1. refine kctl name generating function;
2. integrate HDA jack kctl more deeply, support phantom jack in snd_jack_new();
3. add documentation for Jack kcontrols to explain how to use it.

Changes in v5:
1. remove SND_KCTL_JACK config item, we need jack kctl once CONFIG_SND_JACK is selected.

Changes in v4:
1. use snd_ctl_find_id() to get avaliable index;
2. add initial kctl for snd_jack_new(compatible for HDA);
3. add struct snd_jack_kctl * field to struct hda_jack_tbl;
4. new kctls for soc jack during jack pins creating.
5. add a patch to remove exporting snd_kctl_jack_new().

Changes in v3:
1. replace bit index with bit mask in jack_kctl;
2. add exception for SND_JACK_HEADSET and SND_JACK_AVOUT, only create one jack kctl for these two combo jacks, respectively.
3. add NULL check, mem kfree, and fix some potential risk.

Change in v2:
1. define jack_kctl struct, and put jack kctl related stuff there;
2. add a patch to remove the existing controls for HDA jack.

Jie Yang (7):
ALSA: jack: implement kctl creating for jack device
ALSA: Jack: handle jack embedded kcontrol creating within ctljack
ALSA: jack: extend snd_jack_new to support phantom jack
ALSA: hda - Update to use the new jack kctls method
ASoC: jack: create kctls according to jack pins info
ALSA: jack: remove exporting ctljack functions
ALSA: Docs: Add documentation for Jack kcontrols

 Documentation/sound/alsa/Jack-Controls.txt |  49 ++++++++++
 include/sound/control.h                    |   2 +-
 include/sound/jack.h                       |  13 ++-
 sound/core/Kconfig                         |   3 -
 sound/core/Makefile                        |   3 +-
 sound/core/ctljack.c                       |  41 ++++++--
 sound/core/jack.c                          | 152 ++++++++++++++++++++++++++---
 sound/pci/hda/Kconfig                      |   2 +-
 sound/pci/hda/hda_jack.c                   |  90 +++++------------
 sound/pci/hda/hda_jack.h                   |   5 +-
 sound/pci/hda/patch_hdmi.c                 |   2 +-
 sound/pci/oxygen/xonar_wm87x6.c            |   2 +-
 sound/soc/soc-jack.c                       |   3 +-
 13 files changed, 266 insertions(+), 101 deletions(-)
 create mode 100644 Documentation/sound/alsa/Jack-Controls.txt
Signature · 1 line
1.9.1
author
#2 lore raw

PATCH v9 2/7 ALSA: Jack: handle jack embedded kcontrol creating within ctljack

In ctljack.c, add function get_available_index() to allocate index for new kcontrol, and jack_kctl_name_gen() to remove redundant " Jack" which is passed in wrongly in some cases.

---
 include/sound/control.h  |  2 +-
 sound/core/ctljack.c     | 37 ++++++++++++++++++++++++++++++++++---
 sound/core/jack.c        |  2 +-
 sound/pci/hda/hda_jack.c |  2 +-
 4 files changed, 37 insertions(+), 6 deletions(-)
include/sound/control.h +1 -1
index 75f3054..6c798fc 100644
@@ -252,7 +252,7 @@ void snd_ctl_sync_vmaster(struct snd_kcontrol *kctl, bool hook_only);
  * Helper functions for jack-detection controls
  */
 struct snd_kcontrol *
-snd_kctl_jack_new(const char *name, int idx, void *private_data);
+snd_kctl_jack_new(const char *name, void *private_data, struct snd_card *card);
 void snd_kctl_jack_report(struct snd_card *card,
 			  struct snd_kcontrol *kctl, bool status);
 
sound/core/ctljack.c +34 -3
index e4b38fb..df7c6cd 100644
@@ -31,15 +31,46 @@ static struct snd_kcontrol_new jack_detect_kctl = {
 	.get = jack_detect_kctl_get,
 };
 
+static int get_available_index(struct snd_card *card, const char *name)
+{
+	struct snd_ctl_elem_id sid;
+
+	memset(&sid, 0, sizeof(sid));
+
+	sid.index = 0;
+	sid.iface = SNDRV_CTL_ELEM_IFACE_CARD;
+	strlcpy(sid.name, name, sizeof(sid.name));
+
+	while (snd_ctl_find_id(card, &sid))
+		sid.index++;
+
+	return sid.index;
+}
+
+static void jack_kctl_name_gen(char *name, const char *src_name, int size)
+{
+	size_t count = strlen(src_name);
+	bool need_cat = true;
+
+	/* remove redundant " Jack" from src_name */
+	if (count >= 5)
+		need_cat = strncmp(&src_name[count - 5], " Jack", 5) ? true : false;
+
+	snprintf(name, size, need_cat ? "%s Jack" : "%s", src_name);
+
+}
+
 struct snd_kcontrol *
-snd_kctl_jack_new(const char *name, int idx, void *private_data)
+snd_kctl_jack_new(const char *name, void *private_data, struct snd_card *card)
 {
 	struct snd_kcontrol *kctl;
+
 	kctl = snd_ctl_new1(&jack_detect_kctl, private_data);
 	if (!kctl)
 		return NULL;
-	snprintf(kctl->id.name, sizeof(kctl->id.name), "%s Jack", name);
-	kctl->id.index = idx;
+
+	jack_kctl_name_gen(kctl->id.name, name, sizeof(kctl->id.name));
+	kctl->id.index = get_available_index(card, name);
 	kctl->private_value = 0;
 	return kctl;
 }
sound/core/jack.c +1 -1
index 75cf1bf..0ccd3b0 100644
@@ -147,7 +147,7 @@ static struct snd_jack_kctl * snd_jack_kctl_new(struct snd_card *card, const cha
 	struct snd_jack_kctl *jack_kctl;
 	int err;
 
-	kctl = snd_kctl_jack_new(name, 0, card);
+	kctl = snd_kctl_jack_new(name, card, card);
 	if (!kctl)
 		return NULL;
 
sound/pci/hda/hda_jack.c +1 -1
index e664307..6bf1cde 100644
@@ -402,7 +402,7 @@ static int __snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid,
 		return 0;
 	if (jack->kctl)
 		return 0; /* already created */
-	kctl = snd_kctl_jack_new(name, idx, codec);
+	kctl = snd_kctl_jack_new(name, codec, codec->bus->card);
 	if (!kctl)
 		return -ENOMEM;
 	err = snd_hda_ctl_add(codec, nid, kctl);
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH v9 1/7 ALSA: jack: implement kctl creating for jack device

In reply to Jie Yang

Currently the ALSA jack core registers only input devices for each jack registered. These jack input devices are not readable by userspace devices that run as non root. This patch and the following series patches will implement kctls inside the core jack part, including kctls creating, status changing report, for both HD-Audio and ASoC jack. This allows non root userspace to read jack status and act on it.

This patch implement snd_jack_add_new_kctl(), which will create a kcontrol, add it to the card, and also attach it to the jack kctl list.

The patch also initial the jack kctl list after jack is newed, and report kctl status when doing jack report.

In the following patches, We will update snd_jack_new() to support phantom jack creating, and also enable a kcontrol creating at this jack new stage. After that, we can remove these part from HDA jack, and leave jack kctls handled by core part thoroughly.

---
 include/sound/jack.h  |   9 ++++-
 sound/core/Kconfig    |   3 --
 sound/core/Makefile   |   3 +-
 sound/core/jack.c     | 110 +++++++++++++++++++++++++++++++++++++++++++++++++-
 sound/pci/hda/Kconfig |   2 +-
 5 files changed, 119 insertions(+), 8 deletions(-)
include/sound/jack.h +8 -1
index 2182350..433b13b 100644
@@ -73,6 +73,8 @@ enum snd_jack_types {
 
 struct snd_jack {
 	struct input_dev *input_dev;
+	struct list_head kctl_list;
+	struct snd_card *card;
 	int registered;
 	int type;
 	const char *id;
@@ -86,6 +88,7 @@ struct snd_jack {
 
 int snd_jack_new(struct snd_card *card, const char *id, int type,
 		 struct snd_jack **jack);
+int snd_jack_add_new_kctl(struct snd_jack *jack, const char * name, int mask);
 void snd_jack_set_parent(struct snd_jack *jack, struct device *parent);
 int snd_jack_set_key(struct snd_jack *jack, enum snd_jack_types type,
 		     int keytype);
@@ -93,13 +96,17 @@ int snd_jack_set_key(struct snd_jack *jack, enum snd_jack_types type,
 void snd_jack_report(struct snd_jack *jack, int status);
 
 #else
-
 static inline int snd_jack_new(struct snd_card *card, const char *id, int type,
 			       struct snd_jack **jack)
 {
 	return 0;
 }
 
+static inline int snd_jack_add_new_kctl(struct snd_jack *jack, const char * name, int mask)
+{
+	return 0;
+}
+
 static inline void snd_jack_set_parent(struct snd_jack *jack,
 				       struct device *parent)
 {
sound/core/Kconfig +0 -3
index 313f22e..63cc2e9 100644
@@ -221,9 +221,6 @@ config SND_PCM_XRUN_DEBUG
 config SND_VMASTER
 	bool
 
-config SND_KCTL_JACK
-	bool
-
 config SND_DMA_SGBUF
 	def_bool y
 	depends on X86
sound/core/Makefile +1 -2
index 4daf2f5..e041dc2 100644
@@ -7,8 +7,7 @@ snd-y     := sound.o init.o memory.o info.o control.o misc.o device.o
 snd-$(CONFIG_ISA_DMA_API) += isadma.o
 snd-$(CONFIG_SND_OSSEMUL) += sound_oss.o info_oss.o
 snd-$(CONFIG_SND_VMASTER) += vmaster.o
-snd-$(CONFIG_SND_KCTL_JACK) += ctljack.o
-snd-$(CONFIG_SND_JACK)	  += jack.o
+snd-$(CONFIG_SND_JACK)	  += ctljack.o jack.o
 
 snd-pcm-y := pcm.o pcm_native.o pcm_lib.o pcm_timer.o pcm_misc.o \
 		pcm_memory.o memalloc.o
sound/core/jack.c +109 -1

153 lines not on this page · raw message

sound/pci/hda/Kconfig +1 -1
index 7f0f2c5..3c84107 100644
@@ -4,7 +4,7 @@ config SND_HDA
 	tristate
 	select SND_PCM
 	select SND_VMASTER
-	select SND_KCTL_JACK
+	select SND_JACK
 
 config SND_HDA_INTEL
 	tristate "HD Audio PCI"
Signature · 1 line
1.9.1
author
#4 lore raw

PATCH v9 4/7 ALSA: hda - Update to use the new jack kctls method

In reply to Jie Yang

In the new jack kctls design, snd_kcontrol can be created during snd_jack_new(), or calling snd_jack_add_new_kctls() to create and attach to the created jack later.

Here we create jack kctls at the jack creating stage, for both phantom/non-phantom jack.

---
 include/sound/control.h    |  2 +-
 sound/core/ctljack.c       |  4 +--
 sound/core/jack.c          |  2 +-
 sound/pci/hda/hda_jack.c   | 90 +++++++++++++---------------------------------
 sound/pci/hda/hda_jack.h   |  5 +--
 sound/pci/hda/patch_hdmi.c |  2 +-
 6 files changed, 31 insertions(+), 74 deletions(-)
include/sound/control.h +1 -1
index 6c798fc..58751a0 100644
@@ -252,7 +252,7 @@ void snd_ctl_sync_vmaster(struct snd_kcontrol *kctl, bool hook_only);
  * Helper functions for jack-detection controls
  */
 struct snd_kcontrol *
-snd_kctl_jack_new(const char *name, void *private_data, struct snd_card *card);
+snd_kctl_jack_new(const char *name, struct snd_card *card);
 void snd_kctl_jack_report(struct snd_card *card,
 			  struct snd_kcontrol *kctl, bool status);
 
sound/core/ctljack.c +2 -2
index df7c6cd..6435e82 100644
@@ -61,11 +61,11 @@ static void jack_kctl_name_gen(char *name, const char *src_name, int size)
 }
 
 struct snd_kcontrol *
-snd_kctl_jack_new(const char *name, void *private_data, struct snd_card *card)
+snd_kctl_jack_new(const char *name, struct snd_card *card)
 {
 	struct snd_kcontrol *kctl;
 
-	kctl = snd_ctl_new1(&jack_detect_kctl, private_data);
+	kctl = snd_ctl_new1(&jack_detect_kctl, NULL);
 	if (!kctl)
 		return NULL;
 
sound/core/jack.c +1 -1
index d84850c..b40605b 100644
@@ -147,7 +147,7 @@ static struct snd_jack_kctl * snd_jack_kctl_new(struct snd_card *card, const cha
 	struct snd_jack_kctl *jack_kctl;
 	int err;
 
-	kctl = snd_kctl_jack_new(name, card, card);
+	kctl = snd_kctl_jack_new(name, card);
 	if (!kctl)
 		return NULL;
 
sound/pci/hda/hda_jack.c +25 -65

170 lines not on this page · raw message

sound/pci/hda/hda_jack.h +1 -4
index b279e32..387d309 100644
@@ -39,11 +39,8 @@ struct hda_jack_tbl {
 	unsigned int block_report:1;    /* in a transitional state - do not report to userspace */
 	hda_nid_t gating_jack;		/* valid when gating jack plugged */
 	hda_nid_t gated_jack;		/* gated is dependent on this jack */
-	struct snd_kcontrol *kctl;	/* assigned kctl for jack-detection */
-#ifdef CONFIG_SND_HDA_INPUT_JACK
 	int type;
 	struct snd_jack *jack;
-#endif
 };
 
 struct hda_jack_tbl *
@@ -85,7 +82,7 @@ static inline bool snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid)
 bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid);
 
 int snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid,
-			  const char *name, int idx);
+			  const char *name);
 int snd_hda_jack_add_kctls(struct hda_codec *codec,
 			   const struct auto_pin_cfg *cfg);
 
sound/pci/hda/patch_hdmi.c +1 -1
index b422e40..1679337 100644
@@ -2089,7 +2089,7 @@ static int generic_hdmi_build_jack(struct hda_codec *codec, int pin_idx)
 		strncat(hdmi_str, " Phantom",
 			sizeof(hdmi_str) - strlen(hdmi_str) - 1);
 
-	return snd_hda_jack_add_kctl(codec, per_pin->pin_nid, hdmi_str, 0);
+	return snd_hda_jack_add_kctl(codec, per_pin->pin_nid, hdmi_str);
 }
 
 static int generic_hdmi_build_controls(struct hda_codec *codec)
Signature · 1 line
1.9.1
author
#3 lore raw

PATCH v9 3/7 ALSA: jack: extend snd_jack_new to support phantom jack

In reply to Jie Yang

For phantom jack, we won't create input device, but jack kctl may be needed.

Here, we extend snd_jack_new() to support phantom jack creating:
pass in a bool param for [non-]phantom flag, and a bool param initial_jack to indicate that if we need create kctl at this jack creating stage.

We can also add kctl to a jack after the jack is created.

This make the integrating the existing HDA jack kctl and soc jack kctl possible.

---
 include/sound/jack.h            |  4 ++--
 sound/core/jack.c               | 42 +++++++++++++++++++++++++++++------------
 sound/pci/hda/hda_jack.c        |  2 +-
 sound/pci/oxygen/xonar_wm87x6.c |  2 +-
 sound/soc/soc-jack.c            |  2 +-
 5 files changed, 35 insertions(+), 17 deletions(-)
include/sound/jack.h +2 -2
index 433b13b..23bede1 100644
@@ -87,7 +87,7 @@ struct snd_jack {
 #ifdef CONFIG_SND_JACK
 
 int snd_jack_new(struct snd_card *card, const char *id, int type,
-		 struct snd_jack **jack);
+		 struct snd_jack **jack, bool initial_kctl, bool phantom_jack);
 int snd_jack_add_new_kctl(struct snd_jack *jack, const char * name, int mask);
 void snd_jack_set_parent(struct snd_jack *jack, struct device *parent);
 int snd_jack_set_key(struct snd_jack *jack, enum snd_jack_types type,
@@ -97,7 +97,7 @@ void snd_jack_report(struct snd_jack *jack, int status);
 
 #else
 static inline int snd_jack_new(struct snd_card *card, const char *id, int type,
-			       struct snd_jack **jack)
+			       struct snd_jack **jack, bool initial_kctl, bool phantom_jack)
 {
 	return 0;
 }
sound/core/jack.c +30 -12

77 lines not on this page · raw message

sound/pci/hda/hda_jack.c +1 -1
index 6bf1cde..f648229 100644
@@ -417,7 +417,7 @@ static int __snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid,
 	if (!phantom_jack) {
 		jack->type = get_input_jack_type(codec, nid);
 		err = snd_jack_new(codec->bus->card, name, jack->type,
-				   &jack->jack);
+				   &jack->jack, false, false);
 		if (err < 0)
 			return err;
 		jack->jack->private_data = jack;
sound/pci/oxygen/xonar_wm87x6.c +1 -1
index 6ce6860..90ac479 100644
@@ -286,7 +286,7 @@ static void xonar_ds_init(struct oxygen *chip)
 	xonar_enable_output(chip);
 
 	snd_jack_new(chip->card, "Headphone",
-		     SND_JACK_HEADPHONE, &data->hp_jack);
+		     SND_JACK_HEADPHONE, &data->hp_jack, false, false);
 	xonar_ds_handle_hp_jack(chip);
 
 	snd_component_add(chip->card, "WM8776");
sound/soc/soc-jack.c +1 -1
index 9f60c25..70a9bdd 100644
@@ -48,7 +48,7 @@ int snd_soc_card_jack_new(struct snd_soc_card *card, const char *id, int type,
 	INIT_LIST_HEAD(&jack->jack_zones);
 	BLOCKING_INIT_NOTIFIER_HEAD(&jack->notifier);
 
-	ret = snd_jack_new(card->snd_card, id, type, &jack->jack);
+	ret = snd_jack_new(card->snd_card, id, type, &jack->jack, false, false);
 	if (ret)
 		return ret;
 
Signature · 1 line
1.9.1
author
#5 lore raw

PATCH v9 5/7 ASoC: jack: create kctls according to jack pins info

In reply to Jie Yang

In the new jack kctls design, we can create kctls according to pins info:

1. during jack creating, snd_jack_new() with NULL jack_kctl;
2. for each pin, call snd_jack_add_kctl() to add one kctl (it will call snd_ctl_add() to add kctl to card);

---
 sound/soc/soc-jack.c | 1 +
 1 file changed, 1 insertion(+)
sound/soc/soc-jack.c +1 -0
index 70a9bdd..87ca980 100644
@@ -197,6 +197,7 @@ int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count,
 
 		INIT_LIST_HEAD(&pins[i].list);
 		list_add(&(pins[i].list), &jack->pins);
+		snd_jack_add_new_kctl(jack->jack, pins[i].pin, pins[i].mask);
 	}
 
 	/* Update to reflect the last reported status; canned jack
Signature · 1 line
1.9.1
author
#7 lore raw

PATCH v9 6/7 ALSA: jack: remove exporting ctljack functions

In reply to Jie Yang

After created jack embedded kctls and removed hda jack kctls, the funcs snd_kctl_jack_new() and snd_kctl_jack_report() are merely internal called, so here remove exporting them.

---
 sound/core/ctljack.c | 2 --
 1 file changed, 2 deletions(-)
sound/core/ctljack.c +0 -2
index 6435e82..8f8d103 100644
@@ -74,7 +74,6 @@ snd_kctl_jack_new(const char *name, struct snd_card *card)
 	kctl->private_value = 0;
 	return kctl;
 }
-EXPORT_SYMBOL_GPL(snd_kctl_jack_new);
 
 void snd_kctl_jack_report(struct snd_card *card,
 			  struct snd_kcontrol *kctl, bool status)
@@ -84,4 +83,3 @@ void snd_kctl_jack_report(struct snd_card *card,
 	kctl->private_value = status;
 	snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id);
 }
-EXPORT_SYMBOL_GPL(snd_kctl_jack_report);
Signature · 1 line
1.9.1
author
#8 lore raw

PATCH v9 7/7 ALSA: Docs: Add documentation for Jack kcontrols

In reply to Jie Yang

Add documentation describing Jack embedded kcontrols, and how to use it on HD-Audio and ASoC case.

---
 Documentation/sound/alsa/Jack-Controls.txt | 49 ++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 Documentation/sound/alsa/Jack-Controls.txt
Documentation/sound/alsa/Jack-Controls.txt new file +49 -0
new file mode 100644
index 0000000..c5dd866
@@ -0,0 +1,49 @@
+Why we need kcontrols for Jack?
+===============================
+
+ALSA using kcontrols to export controlling(switch, volume, Mux, ...) to
+user space, e.g. pulseaudio can switch off headphone and switch on
+speaker when no heaphone is pluged in.
+
+For each physical jack, there may be dynamic pluged in/out status which
+upper layer may be interested in. Currently the ALSA jack core registers
+only input devices for each jack registered. These jack input devices
+are not readable by userspace devices that run as non root.
+
+So we create embeded kcontrols for each jack(including phantom jack),
+report jack event via these kcontrols, userspace switch them to ack on
+these event, to implement what they are wanna to.
+
+Combining with ucm machanism, userpace can do fantasic controlling as
+they want to.
+
+Jack and kcontrols
+==================
+
+Each jack will have a kcontrol list, we can create a kcontrol and attach
+it to the jack, at jack creating stage. Also, we can add kcontrol to an
+exist jack, at anytime when you are happy.
+
+Those kcontrols will be freed automatically when the Jack is freed.
+
+How to create kcontrol embedded jack?
+=====================================
+
+To be compatible with previous HD-Audio jack and ASoC jack, we modify
+snd_jack_new() with adding two params:
+
+ - @initial_kctl: create kctl if true, also add it to the non-phantom
+	jack kctl list.
+ - @phantom_jack: for phantom jack, only create needed kctl, won't create
+	input device.
+
+For HDA jack, we can use phantom_jack = true for phantom jack creating,
+and set initial_kctl to true to initial kcontrol with the jack id.
+
+For ASoC jack, usually, we create kcontrols after jack is
+created(calling snd_jack_new() with initial_kctl==false), with
+calling snd_hda_jack_add_kctl() for each jack pins. And, the pin name
+will be assigned to the corresponding kcontrol name. So, to make
+userspace understand and recognize it, please assign proper name for
+each jack pin.
+
Signature · 1 line
1.9.1
#9 lore raw
In reply to Jie Yang

At Thu, 23 Apr 2015 10:32:39 +0800,

Quoted 66 lines · Jie Yang

Currently only hda will create kctls for hda jacks, for asoc, people may need create jack kctls in specific driver.

Here we are introducing kctls for each jack, by creating kctls and add them to jack controls list (considering exist of combo jack). At the same time, we will report events for each control in the list.

With this new implementation, both HDA and soc jack kctls works fine, they are compatible for old HDA jack kctls, too.

For soc,
a. snd_jack_new() with NULL jack_kctl;
b. for each pin, call snd_jack_add_kctls() to add one kctl(it will call snd_ctl_add() to add kctl to card);

For HDA,
With snd_jack_new(), we can use phantom_jack = true for phantom jack creating, and the jack kctl pointer will be filled with the new created kcontrol.

Changes in v9:
1. move struct snd_jack_kctl definition to jack.c, to hides the internal implementation details;
2. some small code fixing;
3. update documentation file.

Changes in v8:
1. remove snd_jack_kctl from HDA part, change snd_jack_new param to use bool for creating kcontrol at jack creating stage;
2. create jack for phantom jack, with no input device;
3. remove HDA jack get_unique_index() and index related code.

Changes in v7:
1. move name generating and index getting part into ctljack.c;
2. remove exposing private_data and destructor to hda, then jack core can handle kctls by itself totally.
3. some small code fixing.

Changes in v6:
1. refine kctl name generating function;
2. integrate HDA jack kctl more deeply, support phantom jack in snd_jack_new();
3. add documentation for Jack kcontrols to explain how to use it.

Changes in v5:
1. remove SND_KCTL_JACK config item, we need jack kctl once CONFIG_SND_JACK is selected.

Changes in v4:
1. use snd_ctl_find_id() to get avaliable index;
2. add initial kctl for snd_jack_new(compatible for HDA);
3. add struct snd_jack_kctl * field to struct hda_jack_tbl;
4. new kctls for soc jack during jack pins creating.
5. add a patch to remove exporting snd_kctl_jack_new().

Changes in v3:
1. replace bit index with bit mask in jack_kctl;
2. add exception for SND_JACK_HEADSET and SND_JACK_AVOUT, only create one jack kctl for these two combo jacks, respectively.
3. add NULL check, mem kfree, and fix some potential risk.

Change in v2:
1. define jack_kctl struct, and put jack kctl related stuff there;
2. add a patch to remove the existing controls for HDA jack.

Quoted 8 lines

Jie Yang (7):
ALSA: jack: implement kctl creating for jack device
ALSA: Jack: handle jack embedded kcontrol creating within ctljack
ALSA: jack: extend snd_jack_new to support phantom jack
ALSA: hda - Update to use the new jack kctls method
ASoC: jack: create kctls according to jack pins info
ALSA: jack: remove exporting ctljack functions
ALSA: Docs: Add documentation for Jack kcontrols

Thanks, now the series look almost good, but still a few things to be fixed:

- Please rebase it on top of for-linus branch (or Linus tree). Some patches can't be applied cleanly due to recent HD-audio reworks.

- Fix typos and syntax errors in comments and descriptions. A spell checker is your friend.

- The kerneldoc comment doesn't have to be applied to static functions. Drop an asterisk from "/**" from snd_jack_kctl_new().

- For ASoC change, I'd like to have an ack from Mark. It's a trivial addition but I'm not sure whether he is satisfied with this new style.

Takashi

author
#10 lore raw
Quoted 83 lines

-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Thursday, April 23, 2015 8:47 PM
To: Jie, Yang
Cc: [email protected]; [email protected]; Girdwood, Liam R; [email protected]
Subject: Re: [PATCH v9 0/7] ALSA: jack: Refactoring for jack kctls

At Thu, 23 Apr 2015 10:32:39 +0800,

Quoted 64 lines · Jie Yang

Currently only hda will create kctls for hda jacks, for asoc, people may need create jack kctls in specific driver.

Here we are introducing kctls for each jack, by creating kctls and add them to jack controls list (considering exist of combo jack). At the same time, we will report events for each control in the list.

With this new implementation, both HDA and soc jack kctls works fine, they are compatible for old HDA jack kctls, too.

For soc,
a. snd_jack_new() with NULL jack_kctl; b. for each pin, call snd_jack_add_kctls() to add one kctl(it will call snd_ctl_add() to add kctl to card);

For HDA,
With snd_jack_new(), we can use phantom_jack = true for phantom jack creating, and the jack kctl pointer will be filled with the new created kcontrol.

Changes in v9:
1. move struct snd_jack_kctl definition to jack.c, to hides the internal implementation details; 2. some small code fixing; 3. update documentation file.

Changes in v8:
1. remove snd_jack_kctl from HDA part, change snd_jack_new param to use bool for creating kcontrol at jack creating stage; 2. create jack for phantom jack, with no input device; 3. remove HDA jack get_unique_index() and index related code.

Changes in v7:
1. move name generating and index getting part into ctljack.c; 2. remove exposing private_data and destructor to hda, then jack core can handle kctls by itself totally.
3. some small code fixing.

Changes in v6:
1. refine kctl name generating function; 2. integrate HDA jack kctl more deeply, support phantom jack in snd_jack_new(); 3. add documentation for Jack kcontrols to explain how to use it.

Changes in v5:
1. remove SND_KCTL_JACK config item, we need jack kctl once CONFIG_SND_JACK is selected.

Changes in v4:
1. use snd_ctl_find_id() to get avaliable index; 2. add initial kctl for snd_jack_new(compatible for HDA); 3. add struct snd_jack_kctl * field to struct hda_jack_tbl; 4. new kctls for soc jack during jack pins creating.
5. add a patch to remove exporting snd_kctl_jack_new().

Changes in v3:
1. replace bit index with bit mask in jack_kctl; 2. add exception for SND_JACK_HEADSET and SND_JACK_AVOUT, only create one jack kctl for these two combo jacks, respectively.
3. add NULL check, mem kfree, and fix some potential risk.

Change in v2:
1. define jack_kctl struct, and put jack kctl related stuff there; 2. add a patch to remove the existing controls for HDA jack.

Quoted 8 lines

Jie Yang (7):
ALSA: jack: implement kctl creating for jack device
ALSA: Jack: handle jack embedded kcontrol creating within ctljack
ALSA: jack: extend snd_jack_new to support phantom jack
ALSA: hda - Update to use the new jack kctls method
ASoC: jack: create kctls according to jack pins info
ALSA: jack: remove exporting ctljack functions
ALSA: Docs: Add documentation for Jack kcontrols

Quoted 6 lines

Thanks, now the series look almost good, but still a few things to be fixed:

- Please rebase it on top of for-linus branch (or Linus tree). Some patches can't be applied cleanly due to recent HD-audio reworks.

OK, I will rebase it on top of your for-linus branch and resend.

Quoted 3 lines

- Fix typos and syntax errors in comments and descriptions. A spell checker is your friend.

I just download one from git://github.com/mprpic/git-spell-check.git,
now learning to use it, do you have better suggestion?

Quoted 3 lines

- The kerneldoc comment doesn't have to be applied to static functions. Drop an asterisk from "/**" from snd_jack_kctl_new().

OK, will remove it.

Quoted 4 lines

- For ASoC change, I'd like to have an ack from Mark. It's a trivial addition but I'm not sure whether he is satisfied with this new style.

Understood.

Hi, Mark, per my understanding, we didn't create specific kcontrols for each ASoC jack, now, my new change reuse the jack pins' info to create these kcontrols, which can be seen and controlled from upper layer (e.g. PA).

I checked it on Broadwell-rt286 platform, together with ucm config file, here pulseaudio can switch on/off headphone/mic kcontrols for headset jack fluently.

How do you think about this implementation? Are there any risk or side effect for it in your opinion?

~Keyon

Quoted 3 lines

Takashi

#11 lore raw

At Thu, 23 Apr 2015 13:45:07 +0000,

Quoted 6 lines · Yang
Quoted 3 lines

- Fix typos and syntax errors in comments and descriptions. A spell checker is your friend.

I just download one from git://github.com/mprpic/git-spell-check.git,
now learning to use it, do you have better suggestion?

Any spell checker would be fine. I don't know of this tool, but isn't it only for XML?

Also, for a lengthy document like in the last patch, it'd be good to get it proof read once by some native English speakers. I remember a guy living in a corner of British Islands in your team ;)

Last but not least, reading twice before submission is always an old good method to catch silly typos or errors. (I forget this often, too.)

Takashi

#12 lore raw
Quoted 9 lines · Takashi Iwai

At Thu, 23 Apr 2015 13:45:07 +0000,

Quoted 6 lines · Yang
Quoted 3 lines

- Fix typos and syntax errors in comments and descriptions. A spell checker is your friend.

I just download one from git://github.com/mprpic/git-spell-check.git,
now learning to use it, do you have better suggestion?

Quoted 7 lines

Any spell checker would be fine. I don't know of this tool, but isn't it only for XML?

Also, for a lengthy document like in the last patch, it'd be good to get it proof read once by some native English speakers. I remember a guy living in a corner of British Islands in your team ;)

Hehe, that will be me :)

Quoted 4 lines

Last but not least, reading twice before submission is always an old good method to catch silly typos or errors. (I forget this often, too.)

Keyon, please send V10 internally and I'll read over the English comments, commit messages, spelling etc before you send it to the list.

Thanks

Liam

---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47

This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.

maintainer
#14 lore raw
In reply to Jie, Yang
Quoted 4 lines · Yang

Hi, Mark, per my understanding, we didn't create specific kcontrols for each ASoC jack, now, my new change reuse the jack pins' info to create these kcontrols, which can be seen and controlled from upper layer (e.g. PA).

I have not been keeping up with this series because it's quite large and there have been many revisions in a short period of time, along with a large number of other substantial patch serieses from your colleagues.

author
#13 lore raw
In reply to Liam Girdwood
Quoted 29 lines

-----Original Message-----
From: Girdwood, Liam R
Sent: Thursday, April 23, 2015 11:21 PM
To: Takashi Iwai
Cc: Jie, Yang; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v9 0/7] ALSA: jack: Refactoring for jack kctls

Quoted 10 lines · Takashi Iwai

At Thu, 23 Apr 2015 13:45:07 +0000,

Quoted 7 lines · Yang
Quoted 3 lines

- Fix typos and syntax errors in comments and descriptions. A spell checker is your friend.

I just download one from
git://github.com/mprpic/git-spell-check.git,
now learning to use it, do you have better suggestion?

Quoted 7 lines

Any spell checker would be fine. I don't know of this tool, but isn't it only for XML?

Also, for a lengthy document like in the last patch, it'd be good to get it proof read once by some native English speakers. I remember a guy living in a corner of British Islands in your team ;)

Hehe, that will be me :)

Quoted 7 lines
Quoted 4 lines

Last but not least, reading twice before submission is always an old good method to catch silly typos or errors. (I forget this often, too.)

Keyon, please send V10 internally and I'll read over the English comments, commit messages, spelling etc before you send it to the list.

OK, thanks.

Quoted 4 lines

Thanks

Liam

author
#15 lore raw
In reply to Mark Brown
Quoted 10 lines

-----Original Message-----
From: Mark Brown [mailto:[email protected]]
Sent: Friday, April 24, 2015 2:18 AM
To: Jie, Yang
Cc: Takashi Iwai; [email protected]; Girdwood, Liam R; [email protected]
Subject: Re: [PATCH v9 0/7] ALSA: jack: Refactoring for jack kctls

On Thu, Apr 23, 2015 at 01:45:07PM +0000, Jie, Yang wrote:

Quoted 8 lines
Quoted 4 lines

Hi, Mark, per my understanding, we didn't create specific kcontrols for each ASoC jack, now, my new change reuse the jack pins' info to create these kcontrols, which can be seen and controlled from upper layer (e.g. PA).

I have not been keeping up with this series because it's quite large and there have been many revisions in a short period of time, along with a large number of other substantial patch serieses from your colleagues.

I can imagine and understand that. Care yourself, Mark. :)

To simplify it, let me summarize it:
only the patch 5 in the series ([PATCH v9 5/7] ASoC: jack: create kctls according to jack pins info) change ASoC code, when looking into it, you can find only one line is added:
+ snd_jack_add_new_kctl(jack->jack, pins[i].pin, pins[i].mask);

So the patch will create extra kcontrols for ASoC jack, comparing to the current upstream code.

Thanks,
~Keyon

maintainer Acked-by on v9 5/7
#6 lore raw

Re: [PATCH v9 5/7] ASoC: jack: create kctls according to jack pins info

In reply to Jie Yang
Quoted 6 lines · Jie Yang

In the new jack kctls design, we can create kctls according to pins info:

1. during jack creating, snd_jack_new() with NULL jack_kctl;
2. for each pin, call snd_jack_add_kctl() to add one kctl (it will call snd_ctl_add() to add kctl to card);