From: Lucas Tanure <tanureal@opensource.cirrus.com>
To: James Schulman <james.schulman@cirrus.com>,
David Rhodes <david.rhodes@cirrus.com>,
Mark Brown <broonie@kernel.org>,
Liam Girdwood <lgirdwood@gmail.com>
Cc: Richard Fitzgerald <rf@opensource.cirrus.com>,
<alsa-devel@alsa-project.org>, <patches@opensource.cirrus.com>,
Lucas Tanure <tanureal@opensource.cirrus.com>,
<linux-kernel@vger.kernel.org>
Subject: [PATCH 10/15] ASoC: cs42l42: Report jack and button detection
Date: Tue, 2 Mar 2021 17:04:49 +0000 [thread overview]
Message-ID: <20210302170454.39679-11-tanureal@opensource.cirrus.com> (raw)
In-Reply-To: <20210302170454.39679-1-tanureal@opensource.cirrus.com>
Report the Jack events to the user space through ALSA.
Also moves request_threaded_irq() to component_probe so it don't get
interrupts before the initialization the struct snd_soc_jack.
Signed-off-by: Lucas Tanure <tanureal@opensource.cirrus.com>
---
sound/soc/codecs/cs42l42.c | 142 +++++++++++++++++++++++++------------
sound/soc/codecs/cs42l42.h | 4 ++
2 files changed, 99 insertions(+), 47 deletions(-)
diff --git a/sound/soc/codecs/cs42l42.c b/sound/soc/codecs/cs42l42.c
index 9a7217cf59f36..8345f52ec9d58 100644
--- a/sound/soc/codecs/cs42l42.c
+++ b/sound/soc/codecs/cs42l42.c
@@ -517,29 +517,6 @@ static const struct snd_soc_dapm_route cs42l42_audio_map[] = {
{ "SDOUT2", NULL, "ASP TX EN" },
};
-static int cs42l42_component_probe(struct snd_soc_component *component)
-{
- struct cs42l42_private *cs42l42 =
- (struct cs42l42_private *)snd_soc_component_get_drvdata(component);
-
- cs42l42->component = component;
-
- return 0;
-}
-
-static const struct snd_soc_component_driver soc_component_dev_cs42l42 = {
- .probe = cs42l42_component_probe,
- .dapm_widgets = cs42l42_dapm_widgets,
- .num_dapm_widgets = ARRAY_SIZE(cs42l42_dapm_widgets),
- .dapm_routes = cs42l42_audio_map,
- .num_dapm_routes = ARRAY_SIZE(cs42l42_audio_map),
- .controls = cs42l42_snd_controls,
- .num_controls = ARRAY_SIZE(cs42l42_snd_controls),
- .idle_bias_on = 1,
- .endianness = 1,
- .non_legacy_dai_naming = 1,
-};
-
struct cs42l42_pll_params {
u32 sclk;
u8 mclk_div;
@@ -1196,7 +1173,7 @@ static void cs42l42_cancel_hs_type_detect(struct cs42l42_private *cs42l42)
(3 << CS42L42_HSDET_AUTO_TIME_SHIFT));
}
-static void cs42l42_handle_button_press(struct cs42l42_private *cs42l42)
+static int cs42l42_handle_button_press(struct cs42l42_private *cs42l42)
{
int bias_level;
unsigned int detect_status;
@@ -1239,17 +1216,24 @@ static void cs42l42_handle_button_press(struct cs42l42_private *cs42l42)
switch (bias_level) {
case 1: /* Function C button press */
+ bias_level = SND_JACK_BTN_2;
dev_dbg(cs42l42->component->dev, "Function C button press\n");
break;
case 2: /* Function B button press */
+ bias_level = SND_JACK_BTN_1;
dev_dbg(cs42l42->component->dev, "Function B button press\n");
break;
case 3: /* Function D button press */
+ bias_level = SND_JACK_BTN_3;
dev_dbg(cs42l42->component->dev, "Function D button press\n");
break;
case 4: /* Function A button press */
+ bias_level = SND_JACK_BTN_0;
dev_dbg(cs42l42->component->dev, "Function A button press\n");
break;
+ default:
+ bias_level = 0;
+ break;
}
/* Set button detect level sensitivity back to default */
@@ -1279,6 +1263,8 @@ static void cs42l42_handle_button_press(struct cs42l42_private *cs42l42)
(0 << CS42L42_M_HSBIAS_HIZ_SHIFT) |
(1 << CS42L42_M_SHORT_RLS_SHIFT) |
(1 << CS42L42_M_SHORT_DET_SHIFT));
+
+ return bias_level;
}
struct cs42l42_irq_params {
@@ -1323,6 +1309,8 @@ static irqreturn_t cs42l42_irq_thread(int irq, void *data)
unsigned int current_plug_status;
unsigned int current_button_status;
unsigned int i;
+ int report = 0;
+
/* Read sticky registers to clear interurpt */
for (i = 0; i < ARRAY_SIZE(stickies); i++) {
@@ -1349,9 +1337,20 @@ static irqreturn_t cs42l42_irq_thread(int irq, void *data)
if ((~masks[5]) & irq_params_table[5].mask) {
if (stickies[5] & CS42L42_HSDET_AUTO_DONE_MASK) {
cs42l42_process_hs_type_detect(cs42l42);
- dev_dbg(component->dev,
- "Auto detect done (%d)\n",
- cs42l42->hs_type);
+ switch(cs42l42->hs_type){
+ case CS42L42_PLUG_CTIA:
+ case CS42L42_PLUG_OMTP:
+ snd_soc_jack_report(&cs42l42->jack, SND_JACK_HEADSET,
+ SND_JACK_HEADSET);
+ break;
+ case CS42L42_PLUG_HEADPHONE:
+ snd_soc_jack_report(&cs42l42->jack, SND_JACK_HEADPHONE,
+ SND_JACK_HEADPHONE);
+ break;
+ default:
+ break;
+ }
+ dev_dbg(component->dev, "Auto detect done (%d)\n", cs42l42->hs_type);
}
}
@@ -1369,8 +1368,19 @@ static irqreturn_t cs42l42_irq_thread(int irq, void *data)
if (cs42l42->plug_state != CS42L42_TS_UNPLUG) {
cs42l42->plug_state = CS42L42_TS_UNPLUG;
cs42l42_cancel_hs_type_detect(cs42l42);
- dev_dbg(component->dev,
- "Unplug event\n");
+
+ switch(cs42l42->hs_type){
+ case CS42L42_PLUG_CTIA:
+ case CS42L42_PLUG_OMTP:
+ snd_soc_jack_report(&cs42l42->jack, 0, SND_JACK_HEADSET);
+ break;
+ case CS42L42_PLUG_HEADPHONE:
+ snd_soc_jack_report(&cs42l42->jack, 0, SND_JACK_HEADPHONE);
+ break;
+ default:
+ break;
+ }
+ dev_dbg(component->dev, "Unplug event\n");
}
break;
@@ -1385,14 +1395,15 @@ static irqreturn_t cs42l42_irq_thread(int irq, void *data)
if (!(current_button_status &
CS42L42_M_HSBIAS_HIZ_MASK)) {
- if (current_button_status &
- CS42L42_M_DETECT_TF_MASK) {
- dev_dbg(component->dev,
- "Button released\n");
- } else if (current_button_status &
- CS42L42_M_DETECT_FT_MASK) {
- cs42l42_handle_button_press(cs42l42);
+ if (current_button_status & CS42L42_M_DETECT_TF_MASK) {
+ dev_dbg(component->dev, "Button released\n");
+ report = 0;
+ } else if (current_button_status & CS42L42_M_DETECT_FT_MASK) {
+ report = cs42l42_handle_button_press(cs42l42);
+
}
+ snd_soc_jack_report(&cs42l42->jack, report, SND_JACK_BTN_0 | SND_JACK_BTN_1 |
+ SND_JACK_BTN_2 | SND_JACK_BTN_3);
}
}
@@ -1731,6 +1742,53 @@ static int cs42l42_handle_device_data(struct i2c_client *i2c_client,
return 0;
}
+static int cs42l42_component_probe(struct snd_soc_component *comp)
+{
+ struct cs42l42_private *cs42l42 = snd_soc_component_get_drvdata(comp);
+ struct snd_soc_card *crd = comp->card;
+ int ret = 0;
+
+ cs42l42->component = comp;
+
+ ret = snd_soc_card_jack_new(crd, "CS42L42 Headset", SND_JACK_HEADSET | SND_JACK_BTN_0 |
+ SND_JACK_BTN_1 | SND_JACK_BTN_2 | SND_JACK_BTN_3,
+ &cs42l42->jack, NULL, 0);
+ if (ret < 0) {
+ dev_err(comp->dev, "Cannot create CS42L42 Headset: %d\n", ret);
+ return ret;
+ }
+
+ /* Request IRQ */
+ ret = request_threaded_irq(cs42l42->irq, NULL, cs42l42_irq_thread,
+ IRQF_ONESHOT | IRQF_TRIGGER_LOW, "cs42l42", cs42l42);
+
+ if (ret)
+ dev_err(comp->dev, "Failed to request IRQ: %d\n", ret);
+
+ return ret;
+}
+
+static void cs42l42_component_remove(struct snd_soc_component *comp)
+{
+ struct cs42l42_private *cs42l42 = snd_soc_component_get_drvdata(comp);
+
+ free_irq(cs42l42->irq, cs42l42);
+}
+
+static const struct snd_soc_component_driver soc_component_dev_cs42l42 = {
+ .probe = cs42l42_component_probe,
+ .remove = cs42l42_component_remove,
+ .dapm_widgets = cs42l42_dapm_widgets,
+ .num_dapm_widgets = ARRAY_SIZE(cs42l42_dapm_widgets),
+ .dapm_routes = cs42l42_audio_map,
+ .num_dapm_routes = ARRAY_SIZE(cs42l42_audio_map),
+ .controls = cs42l42_snd_controls,
+ .num_controls = ARRAY_SIZE(cs42l42_snd_controls),
+ .idle_bias_on = 1,
+ .endianness = 1,
+ .non_legacy_dai_naming = 1,
+};
+
static int cs42l42_i2c_probe(struct i2c_client *i2c_client,
const struct i2c_device_id *id)
{
@@ -1745,6 +1803,7 @@ static int cs42l42_i2c_probe(struct i2c_client *i2c_client,
return -ENOMEM;
i2c_set_clientdata(i2c_client, cs42l42);
+ cs42l42->irq = i2c_client->irq;
cs42l42->regmap = devm_regmap_init_i2c(i2c_client, &cs42l42_regmap);
if (IS_ERR(cs42l42->regmap)) {
@@ -1787,17 +1846,6 @@ static int cs42l42_i2c_probe(struct i2c_client *i2c_client,
}
usleep_range(CS42L42_BOOT_TIME_US, CS42L42_BOOT_TIME_US * 2);
- /* Request IRQ */
- ret = devm_request_threaded_irq(&i2c_client->dev,
- i2c_client->irq,
- NULL, cs42l42_irq_thread,
- IRQF_ONESHOT | IRQF_TRIGGER_LOW,
- "cs42l42", cs42l42);
-
- if (ret != 0)
- dev_err(&i2c_client->dev,
- "Failed to request IRQ: %d\n", ret);
-
/* initialize codec */
ret = regmap_read(cs42l42->regmap, CS42L42_DEVID_AB, ®);
devid = (reg & 0xFF) << 12;
diff --git a/sound/soc/codecs/cs42l42.h b/sound/soc/codecs/cs42l42.h
index c373259ed46f7..267c2b616e57d 100644
--- a/sound/soc/codecs/cs42l42.h
+++ b/sound/soc/codecs/cs42l42.h
@@ -12,6 +12,8 @@
#ifndef __CS42L42_H__
#define __CS42L42_H__
+#include <sound/jack.h>
+
#define CS42L42_PAGE_REGISTER 0x00 /* Page Select Register */
#define CS42L42_WIN_START 0x00
#define CS42L42_WIN_LEN 0x100
@@ -768,6 +770,8 @@ struct cs42l42_private {
struct regulator_bulk_data supplies[CS42L42_NUM_SUPPLIES];
struct gpio_desc *reset_gpio;
struct completion pdn_done;
+ struct snd_soc_jack jack;
+ int irq;
u32 sclk;
u32 srate;
u8 plug_state;
--
2.30.1
next prev parent reply other threads:[~2021-03-02 20:41 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-02 17:04 [PATCH 00/15] Report jack and button detection + Capture Support Lucas Tanure
2021-03-02 17:04 ` [PATCH 01/15] ASoC: cs42l42: Don't enable/disable regulator at Bias Level Lucas Tanure
2021-03-02 17:04 ` [PATCH 02/15] ASoC: cs42l42: Always wait at least 3ms after reset Lucas Tanure
2021-03-02 17:04 ` [PATCH 03/15] ASoC: cs42l42: Remove power if the driver is being removed Lucas Tanure
2021-03-02 17:12 ` Mark Brown
2021-03-02 17:04 ` [PATCH 04/15] ASoC: cs42l42: Disable regulators if probe fails Lucas Tanure
2021-03-02 17:04 ` [PATCH 05/15] ASoC: cs42l42: Fix Bitclock polarity inversion Lucas Tanure
2021-03-02 17:15 ` Mark Brown
2021-03-02 17:04 ` [PATCH 06/15] ASoC: cs42l42: Provide finer control on playback path Lucas Tanure
2021-03-02 17:04 ` [PATCH 07/15] ASoC: cs42l42: Set clock source for both ways of stream Lucas Tanure
2021-03-03 0:02 ` kernel test robot
2021-03-02 17:04 ` [PATCH 08/15] ASoC: cs42l42: Fix channel width support Lucas Tanure
2021-03-02 17:20 ` Mark Brown
2021-03-02 17:04 ` [PATCH 09/15] ASoC: cs42l42: Add Capture Support Lucas Tanure
2021-03-02 17:04 ` Lucas Tanure [this message]
2021-03-02 17:29 ` [PATCH 10/15] ASoC: cs42l42: Report jack and button detection Mark Brown
2021-03-02 17:04 ` [PATCH 11/15] ASoC: cs42l42: Use bclk from hw_params if set_sysclk was not called Lucas Tanure
2021-03-02 17:04 ` [PATCH 12/15] ASoC: cs42l42: Wait at least 150us after writing SCLK_PRESENT Lucas Tanure
2021-03-02 17:30 ` Mark Brown
2021-03-02 22:56 ` kernel test robot
2021-03-02 22:56 ` [PATCH] ASoC: cs42l42: fix semicolon.cocci warnings kernel test robot
2021-03-02 17:04 ` [PATCH 13/15] ASoC: cs42l42: Only start PLL if it is needed Lucas Tanure
2021-03-02 17:04 ` [PATCH 14/15] ASoC: cs42l42: Wait for PLL to lock before switching to it Lucas Tanure
2021-03-02 17:04 ` [PATCH 15/15] ASoC: cs42l42: Fix mixer volume control Lucas Tanure
2021-03-02 17:30 ` Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210302170454.39679-11-tanureal@opensource.cirrus.com \
--to=tanureal@opensource.cirrus.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=david.rhodes@cirrus.com \
--cc=james.schulman@cirrus.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=patches@opensource.cirrus.com \
--cc=rf@opensource.cirrus.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).