2022-09-09 10:16:55

by Astrid Rost

[permalink] [raw]
Subject: [PATCH] ASoC: ts3a227e: allow enabling the jack detect in driver

ti,jack-detect enables the jack detection input device

Signed-off-by: Astrid Rost <[email protected]>
---
sound/soc/codecs/Kconfig | 2 ++
sound/soc/codecs/ts3a227e.c | 62 ++++++++++++++++++++++++++++++++++++-
2 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index d16b4efb88a7..cb86e52cd02f 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -1671,6 +1671,8 @@ config SND_SOC_TLV320ADCX140
config SND_SOC_TS3A227E
tristate "TI Headset/Mic detect and keypress chip"
depends on I2C
+ select SND_JACK
+ select SND_JACK_INPUT_DEV

config SND_SOC_TSCS42XX
tristate "Tempo Semiconductor TSCS42xx CODEC"
diff --git a/sound/soc/codecs/ts3a227e.c b/sound/soc/codecs/ts3a227e.c
index d8ab0810fceb..b5d0d32cafdb 100644
--- a/sound/soc/codecs/ts3a227e.c
+++ b/sound/soc/codecs/ts3a227e.c
@@ -38,6 +38,32 @@ static const int ts3a227e_buttons[] = {
SND_JACK_BTN_3,
};

+/* Headphones jack detection DAPM pin */
+static struct snd_soc_jack_pin ts3a227e_jack_pins[] = {
+
+ {
+ .pin = "Headphone Jack",
+ .mask = SND_JACK_HEADPHONE,
+ },
+ {
+ .pin = "Internal Speaker",
+ /* disable speaker when hp jack is inserted */
+ .mask = SND_JACK_HEADPHONE,
+ .invert = 1,
+ },
+ {
+ .pin = "Headset Mic",
+ .mask = SND_JACK_MICROPHONE,
+ },
+ {
+ .pin = "Internal Mic",
+ /* disable microphone when microphone jack is inserted */
+ .mask = SND_JACK_MICROPHONE,
+ .invert = 1,
+ },
+
+};
+
#define TS3A227E_NUM_BUTTONS 4
#define TS3A227E_JACK_MASK (SND_JACK_HEADPHONE | \
SND_JACK_MICROPHONE | \
@@ -250,7 +276,12 @@ int ts3a227e_enable_jack_detect(struct snd_soc_component *component,
}
EXPORT_SYMBOL_GPL(ts3a227e_enable_jack_detect);

-static struct snd_soc_component_driver ts3a227e_soc_driver;
+static int ts3a227e_probe(struct snd_soc_component *component);
+
+static const struct snd_soc_component_driver ts3a227e_soc_driver = {
+ .name = "Audio Accessory Detection ts3a227e",
+ .probe = ts3a227e_probe,
+};

static const struct regmap_config ts3a227e_regmap_config = {
.val_bits = 8,
@@ -355,6 +386,35 @@ static int ts3a227e_resume(struct device *dev)
}
#endif

+static int ts3a227e_probe(struct snd_soc_component *component)
+{
+ int ret = 0;
+ bool enable = 0;
+ struct snd_soc_card *card = component->card;
+ struct ts3a227e *ts3a227e = snd_soc_component_get_drvdata(component);
+
+ enable = device_property_read_bool(component->dev, "ti,jack-detect");
+ if (enable) {
+ /* Enable Headset and 4 Buttons Jack detection */
+ ts3a227e->jack = devm_kzalloc(component->dev,
+ sizeof(struct snd_soc_jack), GFP_KERNEL);
+
+ ret = snd_soc_card_jack_new_pins(card, "Headset Jack",
+ SND_JACK_HEADSET |
+ SND_JACK_BTN_0 | SND_JACK_BTN_1 |
+ SND_JACK_BTN_2 | SND_JACK_BTN_3,
+ ts3a227e->jack,
+ ts3a227e_jack_pins,
+ ARRAY_SIZE(ts3a227e_jack_pins));
+ if (ret)
+ return ret;
+
+ ret = ts3a227e_enable_jack_detect(component, ts3a227e->jack);
+ }
+
+ return ret;
+}
+
static const struct dev_pm_ops ts3a227e_pm = {
SET_SYSTEM_SLEEP_PM_OPS(ts3a227e_suspend, ts3a227e_resume)
};
--
2.20.1


2022-09-09 18:16:15

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH] ASoC: ts3a227e: allow enabling the jack detect in driver

On Fri, Sep 09, 2022 at 11:30:01AM +0200, Astrid Rost wrote:

> ti,jack-detect enables the jack detection input device

New properties need to be documented, I'm happy for that to be in the
existing document though obviously a conversion to YAML would be very
much appreciated. However...

> + if (enable) {
> + /* Enable Headset and 4 Buttons Jack detection */
> + ts3a227e->jack = devm_kzalloc(component->dev,
> + sizeof(struct snd_soc_jack), GFP_KERNEL);
> +
> + ret = snd_soc_card_jack_new_pins(card, "Headset Jack",
> + SND_JACK_HEADSET |
> + SND_JACK_BTN_0 | SND_JACK_BTN_1 |
> + SND_JACK_BTN_2 | SND_JACK_BTN_3,
> + ts3a227e->jack,
> + ts3a227e_jack_pins,
> + ARRAY_SIZE(ts3a227e_jack_pins));
> + if (ret)
> + return ret;
> +
> + ret = ts3a227e_enable_jack_detect(component, ts3a227e->jack);
> + }

...this is something that should be done in the machine driver rather
than the CODEC, the way the device is wired up in an individual system
may be surprising or the system may have some more specific labelling
that can be usefully applied so this is all deferred to the card.

It would sense to convert ts3a277e_enable_jack_detect() to be a
component set_jack() operation, that'd enable it to be used more easily
with generic cards (though I see that it's not yet wired up for
audio-graph-card unfortunately).


Attachments:
(No filename) (1.38 kB)
signature.asc (499.00 B)
Download all attachments

2022-09-10 02:53:52

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] ASoC: ts3a227e: allow enabling the jack detect in driver

Hi Astrid,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on broonie-sound/for-next]
[also build test ERROR on linus/master v6.0-rc4 next-20220909]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Astrid-Rost/ASoC-ts3a227e-allow-enabling-the-jack-detect-in-driver/20220909-173508
base: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
config: arm64-randconfig-r035-20220909 (https://download.01.org/0day-ci/archive/20220910/[email protected]/config)
compiler: aarch64-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/f147a518459c71521cfe5bc786b804ba317091a0
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Astrid-Rost/ASoC-ts3a227e-allow-enabling-the-jack-detect-in-driver/20220909-173508
git checkout f147a518459c71521cfe5bc786b804ba317091a0
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arm64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>, old ones prefixed by <<):

>> ERROR: modpost: "input_allocate_device" [sound/core/snd.ko] undefined!
>> ERROR: modpost: "input_unregister_device" [sound/core/snd.ko] undefined!
>> ERROR: modpost: "input_free_device" [sound/core/snd.ko] undefined!
>> ERROR: modpost: "input_register_device" [sound/core/snd.ko] undefined!
>> ERROR: modpost: "input_set_capability" [sound/core/snd.ko] undefined!
>> ERROR: modpost: "input_event" [sound/core/snd.ko] undefined!

--
0-DAY CI Kernel Test Service
https://01.org/lkp

2022-09-10 14:54:41

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] ASoC: ts3a227e: allow enabling the jack detect in driver

Hi Astrid,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on broonie-sound/for-next]
[also build test ERROR on linus/master v6.0-rc4 next-20220909]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Astrid-Rost/ASoC-ts3a227e-allow-enabling-the-jack-detect-in-driver/20220909-173508
base: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
config: arm64-randconfig-c023-20220909
compiler: aarch64-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/f147a518459c71521cfe5bc786b804ba317091a0
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Astrid-Rost/ASoC-ts3a227e-allow-enabling-the-jack-detect-in-driver/20220909-173508
git checkout f147a518459c71521cfe5bc786b804ba317091a0
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arm64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

aarch64-linux-ld: drivers/usb/dwc3/dwc3-qcom.o: in function `dwc3_qcom_suspend':
drivers/usb/dwc3/dwc3-qcom.c:314: undefined reference to `usb_hub_find_child'
drivers/usb/dwc3/dwc3-qcom.c:314:(.text+0xea8): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `usb_hub_find_child'
aarch64-linux-ld: sound/core/jack.o: in function `snd_jack_dev_register':
>> sound/core/jack.c:119: undefined reference to `input_set_capability'
sound/core/jack.c:119:(.text+0x25c): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `input_set_capability'
>> aarch64-linux-ld: sound/core/jack.c:122: undefined reference to `input_register_device'
sound/core/jack.c:122:(.text+0x280): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `input_register_device'
aarch64-linux-ld: sound/core/jack.o: in function `snd_jack_dev_disconnect':
>> sound/core/jack.c:54: undefined reference to `input_unregister_device'
sound/core/jack.c:54:(.text+0x380): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `input_unregister_device'
>> aarch64-linux-ld: sound/core/jack.c:56: undefined reference to `input_free_device'
sound/core/jack.c:56:(.text+0x38c): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `input_free_device'
aarch64-linux-ld: sound/core/jack.o: in function `snd_jack_new':
>> sound/core/jack.c:535: undefined reference to `input_allocate_device'
sound/core/jack.c:535:(.text+0x970): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `input_allocate_device'
>> aarch64-linux-ld: sound/core/jack.c:547: undefined reference to `input_set_capability'
sound/core/jack.c:547:(.text+0x9e0): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `input_set_capability'
aarch64-linux-ld: sound/core/jack.c:569: undefined reference to `input_free_device'
sound/core/jack.c:569:(.text+0xab4): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `input_free_device'
aarch64-linux-ld: sound/core/jack.o: in function `snd_jack_report':
>> include/linux/input.h:425: undefined reference to `input_event'
include/linux/input.h:425:(.text+0xef8): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `input_event'
>> aarch64-linux-ld: include/linux/input.h:445: undefined reference to `input_event'
include/linux/input.h:445:(.text+0xf5c): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `input_event'
aarch64-linux-ld: include/linux/input.h:450: undefined reference to `input_event'
include/linux/input.h:450:(.text+0xf98): additional relocation overflows omitted from the output


vim +119 sound/core/jack.c

bd8a71a7b0f50d Mark Brown 2009-01-03 39
32b8544296b944 Takashi Iwai 2013-11-14 40 static int snd_jack_dev_disconnect(struct snd_device *device)
e76d8ceaaff9d7 Mark Brown 2008-07-28 41 {
fe0d128c57bf92 Takashi Iwai 2016-02-17 42 #ifdef CONFIG_SND_JACK_INPUT_DEV
e76d8ceaaff9d7 Mark Brown 2008-07-28 43 struct snd_jack *jack = device->device_data;
e76d8ceaaff9d7 Mark Brown 2008-07-28 44
1b6a6fc5280e97 Amadeusz Sławiński 2022-04-12 45 mutex_lock(&jack->input_dev_lock);
1b6a6fc5280e97 Amadeusz Sławiński 2022-04-12 46 if (!jack->input_dev) {
1b6a6fc5280e97 Amadeusz Sławiński 2022-04-12 47 mutex_unlock(&jack->input_dev_lock);
32b8544296b944 Takashi Iwai 2013-11-14 48 return 0;
1b6a6fc5280e97 Amadeusz Sławiński 2022-04-12 49 }
9d59065cd6fae8 Takashi Iwai 2009-04-14 50
e76d8ceaaff9d7 Mark Brown 2008-07-28 51 /* If the input device is registered with the input subsystem
e76d8ceaaff9d7 Mark Brown 2008-07-28 52 * then we need to use a different deallocator. */
e76d8ceaaff9d7 Mark Brown 2008-07-28 53 if (jack->registered)
e76d8ceaaff9d7 Mark Brown 2008-07-28 @54 input_unregister_device(jack->input_dev);
e76d8ceaaff9d7 Mark Brown 2008-07-28 55 else
e76d8ceaaff9d7 Mark Brown 2008-07-28 @56 input_free_device(jack->input_dev);
32b8544296b944 Takashi Iwai 2013-11-14 57 jack->input_dev = NULL;
1b6a6fc5280e97 Amadeusz Sławiński 2022-04-12 58 mutex_unlock(&jack->input_dev_lock);
fe0d128c57bf92 Takashi Iwai 2016-02-17 59 #endif /* CONFIG_SND_JACK_INPUT_DEV */
32b8544296b944 Takashi Iwai 2013-11-14 60 return 0;
32b8544296b944 Takashi Iwai 2013-11-14 61 }
32b8544296b944 Takashi Iwai 2013-11-14 62
32b8544296b944 Takashi Iwai 2013-11-14 63 static int snd_jack_dev_free(struct snd_device *device)
32b8544296b944 Takashi Iwai 2013-11-14 64 {
32b8544296b944 Takashi Iwai 2013-11-14 65 struct snd_jack *jack = device->device_data;
9058cbe1eed293 Jie Yang 2015-04-27 66 struct snd_card *card = device->card;
9058cbe1eed293 Jie Yang 2015-04-27 67 struct snd_jack_kctl *jack_kctl, *tmp_jack_kctl;
32b8544296b944 Takashi Iwai 2013-11-14 68
06764dc931848c Takashi Iwai 2021-11-16 69 down_write(&card->controls_rwsem);
9058cbe1eed293 Jie Yang 2015-04-27 70 list_for_each_entry_safe(jack_kctl, tmp_jack_kctl, &jack->kctl_list, list) {
9058cbe1eed293 Jie Yang 2015-04-27 71 list_del_init(&jack_kctl->list);
9058cbe1eed293 Jie Yang 2015-04-27 72 snd_ctl_remove(card, jack_kctl->kctl);
9058cbe1eed293 Jie Yang 2015-04-27 73 }
06764dc931848c Takashi Iwai 2021-11-16 74 up_write(&card->controls_rwsem);
06764dc931848c Takashi Iwai 2021-11-16 75
32b8544296b944 Takashi Iwai 2013-11-14 76 if (jack->private_free)
32b8544296b944 Takashi Iwai 2013-11-14 77 jack->private_free(jack);
32b8544296b944 Takashi Iwai 2013-11-14 78
32b8544296b944 Takashi Iwai 2013-11-14 79 snd_jack_dev_disconnect(device);
e76d8ceaaff9d7 Mark Brown 2008-07-28 80
282cd76ffca781 Matt Ranostay 2008-10-25 81 kfree(jack->id);
e76d8ceaaff9d7 Mark Brown 2008-07-28 82 kfree(jack);
e76d8ceaaff9d7 Mark Brown 2008-07-28 83
e76d8ceaaff9d7 Mark Brown 2008-07-28 84 return 0;
e76d8ceaaff9d7 Mark Brown 2008-07-28 85 }
e76d8ceaaff9d7 Mark Brown 2008-07-28 86
fe0d128c57bf92 Takashi Iwai 2016-02-17 87 #ifdef CONFIG_SND_JACK_INPUT_DEV
e76d8ceaaff9d7 Mark Brown 2008-07-28 88 static int snd_jack_dev_register(struct snd_device *device)
e76d8ceaaff9d7 Mark Brown 2008-07-28 89 {
e76d8ceaaff9d7 Mark Brown 2008-07-28 90 struct snd_jack *jack = device->device_data;
e76d8ceaaff9d7 Mark Brown 2008-07-28 91 struct snd_card *card = device->card;
ebb812cb8df48e Mark Brown 2010-03-17 92 int err, i;
e76d8ceaaff9d7 Mark Brown 2008-07-28 93
e76d8ceaaff9d7 Mark Brown 2008-07-28 94 snprintf(jack->name, sizeof(jack->name), "%s %s",
2678f60d2bc05a Takashi Iwai 2009-02-18 95 card->shortname, jack->id);
43b2cd547edcba Takashi Iwai 2015-04-30 96
1b6a6fc5280e97 Amadeusz Sławiński 2022-04-12 97 mutex_lock(&jack->input_dev_lock);
1b6a6fc5280e97 Amadeusz Sławiński 2022-04-12 98 if (!jack->input_dev) {
1b6a6fc5280e97 Amadeusz Sławiński 2022-04-12 99 mutex_unlock(&jack->input_dev_lock);
43b2cd547edcba Takashi Iwai 2015-04-30 100 return 0;
1b6a6fc5280e97 Amadeusz Sławiński 2022-04-12 101 }
43b2cd547edcba Takashi Iwai 2015-04-30 102
e76d8ceaaff9d7 Mark Brown 2008-07-28 103 jack->input_dev->name = jack->name;
e76d8ceaaff9d7 Mark Brown 2008-07-28 104
e76d8ceaaff9d7 Mark Brown 2008-07-28 105 /* Default to the sound card device. */
e76d8ceaaff9d7 Mark Brown 2008-07-28 106 if (!jack->input_dev->dev.parent)
1f3fff7bda95b7 Kay Sievers 2009-06-10 107 jack->input_dev->dev.parent = snd_card_get_device_link(card);
e76d8ceaaff9d7 Mark Brown 2008-07-28 108
ebb812cb8df48e Mark Brown 2010-03-17 109 /* Add capabilities for any keys that are enabled */
ebb812cb8df48e Mark Brown 2010-03-17 110 for (i = 0; i < ARRAY_SIZE(jack->key); i++) {
ebb812cb8df48e Mark Brown 2010-03-17 111 int testbit = SND_JACK_BTN_0 >> i;
ebb812cb8df48e Mark Brown 2010-03-17 112
ebb812cb8df48e Mark Brown 2010-03-17 113 if (!(jack->type & testbit))
ebb812cb8df48e Mark Brown 2010-03-17 114 continue;
ebb812cb8df48e Mark Brown 2010-03-17 115
ebb812cb8df48e Mark Brown 2010-03-17 116 if (!jack->key[i])
ebb812cb8df48e Mark Brown 2010-03-17 117 jack->key[i] = BTN_0 + i;
ebb812cb8df48e Mark Brown 2010-03-17 118
ebb812cb8df48e Mark Brown 2010-03-17 @119 input_set_capability(jack->input_dev, EV_KEY, jack->key[i]);
ebb812cb8df48e Mark Brown 2010-03-17 120 }
ebb812cb8df48e Mark Brown 2010-03-17 121
e76d8ceaaff9d7 Mark Brown 2008-07-28 @122 err = input_register_device(jack->input_dev);
e76d8ceaaff9d7 Mark Brown 2008-07-28 123 if (err == 0)
e76d8ceaaff9d7 Mark Brown 2008-07-28 124 jack->registered = 1;
e76d8ceaaff9d7 Mark Brown 2008-07-28 125
1b6a6fc5280e97 Amadeusz Sławiński 2022-04-12 126 mutex_unlock(&jack->input_dev_lock);
e76d8ceaaff9d7 Mark Brown 2008-07-28 127 return err;
e76d8ceaaff9d7 Mark Brown 2008-07-28 128 }
fe0d128c57bf92 Takashi Iwai 2016-02-17 129 #endif /* CONFIG_SND_JACK_INPUT_DEV */
e76d8ceaaff9d7 Mark Brown 2008-07-28 130

--
0-DAY CI Kernel Test Service
https://01.org/lkp


Attachments:
(No filename) (11.18 kB)
config (176.93 kB)
Download all attachments

2022-09-12 07:36:14

by Astrid Rost

[permalink] [raw]
Subject: Re: [PATCH] ASoC: ts3a227e: allow enabling the jack detect in driver

Hello,


> New properties need to be documented, I'm happy for that to be in the
> existing document though obviously a conversion to YAML would be very
> much appreciated. However...

Yes, I am doing the yaml conversion for the other patch.
I guess this one - I will try to do differently.

On 9/9/22 19:45, Mark Brown wrote:
> ...this is something that should be done in the machine driver rather
> than the CODEC, the way the device is wired up in an individual system
> may be surprising or the system may have some more specific labelling
> that can be usefully applied so this is all deferred to the card.
>
> It would sense to convert ts3a277e_enable_jack_detect() to be a
> component set_jack() operation, that'd enable it to be used more easily
> with generic cards (though I see that it's not yet wired up for
> audio-graph-card unfortunately).

Thank you! Yes, set_jack I did not see.
I actually thinking of putting this into simple_card.c. But than it
needs to be really generic.

I will have a look.

Astrid