From patchwork Mon Jun 11 08:32:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Katsuhiro Suzuki X-Patchwork-Id: 138205 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp3777266lji; Mon, 11 Jun 2018 01:32:23 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL0jyqOtxoTSNEaJpfSvmArR3XCn4cyvQET53on7MZZIC9vwto51lDBZlegsWbJbXxIcKKB X-Received: by 2002:a17:902:24a5:: with SMTP id w34-v6mr17426547pla.52.1528705943191; Mon, 11 Jun 2018 01:32:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528705943; cv=none; d=google.com; s=arc-20160816; b=0CgjzCArAHdBkHcX5lKFa7ZN0Z1PD63MBybSqjFYStAK9I1LE1IZtAZQu5HaTnwnsa Ocg3CpEbXb1H80x4m9daFhv9GFXgeZ4IeLTCDctdO490fTiBSk6KqCVI3z1pGEOm3W/3 +gfehSuxV8XWUqqwSzsCJsjSCYlbGCwOa5fUv6+JwIuKyF0El4F6qikIe/job/MzZWT5 Z8ac/kKiw1cZOMIIZDJvGiepB0c0hSSQeu7Fjollj6dasGff182kAeQYQpvMGoM8J8SS Y+NvsIAiLm003KsjmItXmLOpZ+a06THBNo/6sABSJ8II6K0yrCwm1px/kprBOQb2eBIz JQXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=0laYlUklv7aPuZgYhYEztQWsV+wP8fgKG0rtAduUAQw=; b=xFfAAU1zvCBeRfTduDxTsHnh/GJCFMcslkl7ic1JSvPBzuPykSWBSiTGBftdusg5+b /+Gi4biRAUcP0bgAJTt+3komIgXW00wYg+PEAYXXdYlIjD6DkeQiUtKLfGyc6gbc57CX nTdsQVWpLhc9c5SLoImW28DmPRLtR6MxgAd5J99lKz78psaWkb/wBjbHA2uenNUHjRT4 3ofrDljwUeVU26AkBDAhs9jSfQT4NUpRbFN9UAFEV6h8uKdldT8F9qd03Y2nRW0YUi9k V5dL3kgTF9R0IuiyUiO5U6qCteWZDfaI4JXE5venr3NMKdhQsDmFgMcB7HtTVVqY2oW/ gcwA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v7-v6si61163914plp.304.2018.06.11.01.32.22; Mon, 11 Jun 2018 01:32:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754198AbeFKIcU (ORCPT + 30 others); Mon, 11 Jun 2018 04:32:20 -0400 Received: from mx.socionext.com ([202.248.49.38]:23019 "EHLO mx.socionext.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754010AbeFKIcS (ORCPT ); Mon, 11 Jun 2018 04:32:18 -0400 Received: from unknown (HELO iyokan-ex.css.socionext.com) ([172.31.9.54]) by mx.socionext.com with ESMTP; 11 Jun 2018 17:32:17 +0900 Received: from mail.mfilter.local (m-filter-1 [10.213.24.61]) by iyokan-ex.css.socionext.com (Postfix) with ESMTP id 0FF896006F; Mon, 11 Jun 2018 17:32:17 +0900 (JST) Received: from 172.31.9.53 (172.31.9.53) by m-FILTER with ESMTP; Mon, 11 Jun 2018 17:32:17 +0900 Received: from yuzu.css.socionext.com (yuzu [172.31.8.45]) by iyokan.css.socionext.com (Postfix) with ESMTP id 9B82F40386; Mon, 11 Jun 2018 17:32:16 +0900 (JST) Received: from aegis.e01.socionext.com (unknown [10.213.134.210]) by yuzu.css.socionext.com (Postfix) with ESMTP id 7126812013B; Mon, 11 Jun 2018 17:32:16 +0900 (JST) From: Katsuhiro Suzuki To: Kuninori Morimoto , Mark Brown , alsa-devel@alsa-project.org Cc: Masami Hiramatsu , Jassi Brar , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Katsuhiro Suzuki Subject: [PATCH v3 1/3] ASoC: simple-card-utils: move hp and mic detect gpios from simple-card Date: Mon, 11 Jun 2018 17:32:12 +0900 Message-Id: <20180611083214.16858-1-suzuki.katsuhiro@socionext.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch moves headphone and microphone jack detection gpios from simple-card driver. It is preparing for using this feature from other drivers. Signed-off-by: Katsuhiro Suzuki --- Changes from v2: - Nothing Changes from v1: - Move changes of audio-graph-card to other patch --- include/sound/simple_card_utils.h | 15 +++++++ sound/soc/generic/simple-card-utils.c | 59 ++++++++++++++++++++++++ sound/soc/generic/simple-card.c | 64 --------------------------- 3 files changed, 74 insertions(+), 64 deletions(-) -- 2.17.1 Acked-by: Kuninori Morimoto diff --git a/include/sound/simple_card_utils.h b/include/sound/simple_card_utils.h index 7e25afce6566..f82acef3b992 100644 --- a/include/sound/simple_card_utils.h +++ b/include/sound/simple_card_utils.h @@ -12,6 +12,11 @@ #include +#define asoc_simple_card_init_hp(card, sjack, prefix) \ + asoc_simple_card_init_jack(card, sjack, 1, prefix) +#define asoc_simple_card_init_mic(card, sjack, prefix) \ + asoc_simple_card_init_jack(card, sjack, 0, prefix) + struct asoc_simple_dai { const char *name; unsigned int sysclk; @@ -28,6 +33,12 @@ struct asoc_simple_card_data { u32 convert_channels; }; +struct asoc_simple_jack { + struct snd_soc_jack jack; + struct snd_soc_jack_pin pin; + struct snd_soc_jack_gpio gpio; +}; + int asoc_simple_card_parse_daifmt(struct device *dev, struct device_node *node, struct device_node *codec, @@ -107,4 +118,8 @@ int asoc_simple_card_of_parse_routing(struct snd_soc_card *card, int asoc_simple_card_of_parse_widgets(struct snd_soc_card *card, char *prefix); +int asoc_simple_card_init_jack(struct snd_soc_card *card, + struct asoc_simple_jack *sjack, + int is_hp, char *prefix); + #endif /* __SIMPLE_CARD_UTILS_H */ diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c index 3751a07de6aa..4398c9580929 100644 --- a/sound/soc/generic/simple-card-utils.c +++ b/sound/soc/generic/simple-card-utils.c @@ -8,9 +8,13 @@ * published by the Free Software Foundation. */ #include +#include +#include #include #include +#include #include +#include #include void asoc_simple_card_convert_fixup(struct asoc_simple_card_data *data, @@ -419,6 +423,61 @@ int asoc_simple_card_of_parse_widgets(struct snd_soc_card *card, } EXPORT_SYMBOL_GPL(asoc_simple_card_of_parse_widgets); +int asoc_simple_card_init_jack(struct snd_soc_card *card, + struct asoc_simple_jack *sjack, + int is_hp, char *prefix) +{ + struct device *dev = card->dev; + enum of_gpio_flags flags; + char prop[128]; + char *pin_name; + char *gpio_name; + int mask; + int det; + + if (!prefix) + prefix = ""; + + sjack->gpio.gpio = -ENOENT; + + if (is_hp) { + snprintf(prop, sizeof(prop), "%shp-det-gpio", prefix); + pin_name = "Headphones"; + gpio_name = "Headphone detection"; + mask = SND_JACK_HEADPHONE; + } else { + snprintf(prop, sizeof(prop), "%smic-det-gpio", prefix); + pin_name = "Mic Jack"; + gpio_name = "Mic detection"; + mask = SND_JACK_MICROPHONE; + } + + det = of_get_named_gpio_flags(dev->of_node, prop, 0, &flags); + if (det == -EPROBE_DEFER) + return -EPROBE_DEFER; + + if (gpio_is_valid(det)) { + sjack->pin.pin = pin_name; + sjack->pin.mask = mask; + + sjack->gpio.name = gpio_name; + sjack->gpio.report = mask; + sjack->gpio.gpio = det; + sjack->gpio.invert = !!(flags & OF_GPIO_ACTIVE_LOW); + sjack->gpio.debounce_time = 150; + + snd_soc_card_jack_new(card, pin_name, mask, + &sjack->jack, + &sjack->pin, 1); + + snd_soc_jack_add_gpios(&sjack->jack, 1, + &sjack->gpio); + } + + return 0; +} +EXPORT_SYMBOL_GPL(asoc_simple_card_init_jack); + /* Module information */ MODULE_AUTHOR("Kuninori Morimoto "); MODULE_DESCRIPTION("ALSA SoC Simple Card Utils"); diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c index 4a516c428b3d..1bbd9e46bf2a 100644 --- a/sound/soc/generic/simple-card.c +++ b/sound/soc/generic/simple-card.c @@ -10,23 +10,14 @@ */ #include #include -#include #include #include -#include #include #include -#include #include #include #include -struct asoc_simple_jack { - struct snd_soc_jack jack; - struct snd_soc_jack_pin pin; - struct snd_soc_jack_gpio gpio; -}; - struct simple_card_data { struct snd_soc_card snd_card; struct simple_dai_props { @@ -49,61 +40,6 @@ struct simple_card_data { #define CELL "#sound-dai-cells" #define PREFIX "simple-audio-card," -#define asoc_simple_card_init_hp(card, sjack, prefix)\ - asoc_simple_card_init_jack(card, sjack, 1, prefix) -#define asoc_simple_card_init_mic(card, sjack, prefix)\ - asoc_simple_card_init_jack(card, sjack, 0, prefix) -static int asoc_simple_card_init_jack(struct snd_soc_card *card, - struct asoc_simple_jack *sjack, - int is_hp, char *prefix) -{ - struct device *dev = card->dev; - enum of_gpio_flags flags; - char prop[128]; - char *pin_name; - char *gpio_name; - int mask; - int det; - - sjack->gpio.gpio = -ENOENT; - - if (is_hp) { - snprintf(prop, sizeof(prop), "%shp-det-gpio", prefix); - pin_name = "Headphones"; - gpio_name = "Headphone detection"; - mask = SND_JACK_HEADPHONE; - } else { - snprintf(prop, sizeof(prop), "%smic-det-gpio", prefix); - pin_name = "Mic Jack"; - gpio_name = "Mic detection"; - mask = SND_JACK_MICROPHONE; - } - - det = of_get_named_gpio_flags(dev->of_node, prop, 0, &flags); - if (det == -EPROBE_DEFER) - return -EPROBE_DEFER; - - if (gpio_is_valid(det)) { - sjack->pin.pin = pin_name; - sjack->pin.mask = mask; - - sjack->gpio.name = gpio_name; - sjack->gpio.report = mask; - sjack->gpio.gpio = det; - sjack->gpio.invert = !!(flags & OF_GPIO_ACTIVE_LOW); - sjack->gpio.debounce_time = 150; - - snd_soc_card_jack_new(card, pin_name, mask, - &sjack->jack, - &sjack->pin, 1); - - snd_soc_jack_add_gpios(&sjack->jack, 1, - &sjack->gpio); - } - - return 0; -} - static int asoc_simple_card_startup(struct snd_pcm_substream *substream) { struct snd_soc_pcm_runtime *rtd = substream->private_data;