Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: simple-card-utils: create jack inputs for

Merge series from Astrid Rost <astrid.rost@axis.com>:

Add a generic way to create jack inputs for auxiliary jack detection
drivers (e.g. via i2c, spi), which are not part of any real codec.
The simple-card can be used as combining card driver to add the jacks,
no new one is required.

Create a jack (for input-events) for jack devices in the auxiliary
device list (aux_devs). A device which returns a valid value on
get_jack_type counts as jack device; set_jack is required
to add the jack to the device.

+97 -1
+3
include/sound/simple_card_utils.h
··· 69 69 } *dai_props; 70 70 struct asoc_simple_jack hp_jack; 71 71 struct asoc_simple_jack mic_jack; 72 + struct snd_soc_jack *aux_jacks; 72 73 struct snd_soc_dai_link *dai_link; 73 74 struct asoc_simple_dai *dais; 74 75 struct snd_soc_dai_link_component *dlcs; ··· 188 187 int asoc_simple_init_jack(struct snd_soc_card *card, 189 188 struct asoc_simple_jack *sjack, 190 189 int is_hp, char *prefix, char *pin); 190 + int asoc_simple_init_aux_jacks(struct asoc_simple_priv *priv, 191 + char *prefix); 191 192 int asoc_simple_init_priv(struct asoc_simple_priv *priv, 192 193 struct link_info *li); 193 194 int asoc_simple_remove(struct platform_device *pdev);
+2
include/sound/soc-component.h
··· 98 98 int source, unsigned int freq_in, unsigned int freq_out); 99 99 int (*set_jack)(struct snd_soc_component *component, 100 100 struct snd_soc_jack *jack, void *data); 101 + int (*get_jack_type)(struct snd_soc_component *component); 101 102 102 103 /* DT */ 103 104 int (*of_xlate_dai_name)(struct snd_soc_component *component, ··· 385 384 unsigned int freq_out); 386 385 int snd_soc_component_set_jack(struct snd_soc_component *component, 387 386 struct snd_soc_jack *jack, void *data); 387 + int snd_soc_component_get_jack_type(struct snd_soc_component *component); 388 388 389 389 void snd_soc_component_seq_notifier(struct snd_soc_component *component, 390 390 enum snd_soc_dapm_type type, int subseq);
+19 -1
sound/soc/codecs/ts3a227e.c
··· 258 258 } 259 259 EXPORT_SYMBOL_GPL(ts3a227e_enable_jack_detect); 260 260 261 - static struct snd_soc_component_driver ts3a227e_soc_driver; 261 + static int ts3a227e_set_jack(struct snd_soc_component *component, 262 + struct snd_soc_jack *jack, void *data) 263 + { 264 + if (jack == NULL) 265 + return -EINVAL; 266 + 267 + return ts3a227e_enable_jack_detect(component, jack); 268 + } 269 + 270 + static int ts3a227e_get_jack_type(struct snd_soc_component *component) 271 + { 272 + return SND_JACK_HEADSET; 273 + } 274 + 275 + static const struct snd_soc_component_driver ts3a227e_soc_driver = { 276 + .name = "ti,ts3a227e", 277 + .set_jack = ts3a227e_set_jack, 278 + .get_jack_type = ts3a227e_get_jack_type, 279 + }; 262 280 263 281 static const struct regmap_config ts3a227e_regmap_config = { 264 282 .val_bits = 8,
+49
sound/soc/generic/simple-card-utils.c
··· 786 786 } 787 787 EXPORT_SYMBOL_GPL(asoc_simple_init_jack); 788 788 789 + int asoc_simple_init_aux_jacks(struct asoc_simple_priv *priv, char *prefix) 790 + { 791 + struct snd_soc_card *card = simple_priv_to_card(priv); 792 + struct snd_soc_component *component; 793 + int found_jack_index = 0; 794 + int type = 0; 795 + int num = 0; 796 + int ret; 797 + 798 + if (priv->aux_jacks) 799 + return 0; 800 + 801 + for_each_card_auxs(card, component) { 802 + type = snd_soc_component_get_jack_type(component); 803 + if (type > 0) 804 + num++; 805 + } 806 + if (num < 1) 807 + return 0; 808 + 809 + priv->aux_jacks = devm_kcalloc(card->dev, num, 810 + sizeof(struct snd_soc_jack), GFP_KERNEL); 811 + if (!priv->aux_jacks) 812 + return -ENOMEM; 813 + 814 + for_each_card_auxs(card, component) { 815 + char id[128]; 816 + struct snd_soc_jack *jack; 817 + 818 + if (found_jack_index >= num) 819 + break; 820 + 821 + type = snd_soc_component_get_jack_type(component); 822 + if (type <= 0) 823 + continue; 824 + 825 + /* create jack */ 826 + jack = &(priv->aux_jacks[found_jack_index++]); 827 + snprintf(id, sizeof(id), "%s-jack", component->name); 828 + ret = snd_soc_card_jack_new(card, id, type, jack); 829 + if (ret) 830 + continue; 831 + 832 + (void)snd_soc_component_set_jack(component, jack, NULL); 833 + } 834 + return 0; 835 + } 836 + EXPORT_SYMBOL_GPL(asoc_simple_init_aux_jacks); 837 + 789 838 int asoc_simple_init_priv(struct asoc_simple_priv *priv, 790 839 struct link_info *li) 791 840 {
+4
sound/soc/generic/simple-card.c
··· 623 623 if (ret < 0) 624 624 return ret; 625 625 626 + ret = asoc_simple_init_aux_jacks(priv, PREFIX); 627 + if (ret < 0) 628 + return ret; 629 + 626 630 return 0; 627 631 } 628 632
+20
sound/soc/soc-component.c
··· 256 256 } 257 257 EXPORT_SYMBOL_GPL(snd_soc_component_set_jack); 258 258 259 + /** 260 + * snd_soc_component_get_jack_type 261 + * @component: COMPONENTs 262 + * 263 + * Returns the jack type of the component 264 + * This can either be the supported type or one read from 265 + * devicetree with the property: jack-type. 266 + */ 267 + int snd_soc_component_get_jack_type( 268 + struct snd_soc_component *component) 269 + { 270 + int ret = -ENOTSUPP; 271 + 272 + if (component->driver->get_jack_type) 273 + ret = component->driver->get_jack_type(component); 274 + 275 + return soc_component_ret(component, ret); 276 + } 277 + EXPORT_SYMBOL_GPL(snd_soc_component_get_jack_type); 278 + 259 279 int snd_soc_component_module_get(struct snd_soc_component *component, 260 280 void *mark, int upon_open) 261 281 {