From patchwork Fri Oct 18 15:41:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 176863 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp1031065ill; Fri, 18 Oct 2019 08:43:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqxAU8neQYkngWgf3dt5+MesARPYFtBYN1aCMtQ+Q2O0icTYb4i3Le/nmZ7o9+etxNl7US6M X-Received: by 2002:a05:6402:1514:: with SMTP id f20mr10425076edw.35.1571413408137; Fri, 18 Oct 2019 08:43:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571413408; cv=none; d=google.com; s=arc-20160816; b=MvVHr4uwNZvVxhxyzADLf5uMrJKYkQWnbLxtZUk1IxiRIVPip0IdmvQYq/aYa9kqBT unUa9It1xE0chE9Engmend+mbO8y2KcT/EdwzzPpJasd1df9Dvvy4n6viO10JRtDEBBu lXsnG/OaDNR4l6fwv3sPukSH91yVkcScR/O8E7N+QLZj8MOT1c5JX+kSSH2IXllQGLbA vmX/0mhHddh1U2Xv7YJBJ+I3G8d1EgTzXSkVDtxNyZq90lgNF6NacDDUhkHzlHYzSEaZ FI/sXkqdZk4bwhhvYwZlSr6K0Ebfq9PJuu/HPOGaLntWjnwhRFnxdS0/OuOkm8erP0YC H+xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=UgikP/FgtJKQmirt+f2Th2onclSnYjMgbbYHDh3FkNs=; b=DTwhdVAjn3N+xhidErAo9a4RpeivxC5EHt2fpyT36QG73sKphHJDpQPfnbe4mmR+cI 23lajUBTeTdmuF5RIWbGpIC9Dhuo1C8OZPahOt7X+icDaJtuzkA3zHHQkFmpNAu56CVz IOehLe5dkj3nppDu68+Wia+HexrQM3C/TUwd5R2YJ+EL0ryj8xwcnyTfrF7NaDJRVTLG nrOHUOdo8x4xMC+Vp1eXGX8PzTfckhsfW6uLVESYiJ3WSGkwxe3R8UTVfWm22tPoED6/ LigOiOExadocoQ28EtBu/xe4LWtQ5W+WqtbmWzakn6ENnEE0YUUO1N5BgGnuTSw0OQz1 +59w== 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 g13si3897729edu.4.2019.10.18.08.43.27; Fri, 18 Oct 2019 08:43:28 -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 S2505249AbfJRPmw (ORCPT + 26 others); Fri, 18 Oct 2019 11:42:52 -0400 Received: from mout.kundenserver.de ([217.72.192.75]:50619 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2505191AbfJRPmn (ORCPT ); Fri, 18 Oct 2019 11:42:43 -0400 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MqrwN-1hhUo60Vc1-00moY8; Fri, 18 Oct 2019 17:42:27 +0200 From: Arnd Bergmann To: Daniel Mack , Haojian Zhuang , Robert Jarzmik Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij , Arnd Bergmann , Mark Brown , alsa-devel@alsa-project.org Subject: [PATCH 21/46] ARM: pxa: spitz: use gpio descriptors for audio Date: Fri, 18 Oct 2019 17:41:36 +0200 Message-Id: <20191018154201.1276638-21-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191018154052.1276506-1-arnd@arndb.de> References: <20191018154052.1276506-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:EnGATBO6UcVguXcv7G62u/so/z4MGLoOyIeCs3iHNegQs2eAeZx RXCX3mThC+ltOlQdPgJxtQZMZlOJ3twIf0mEeLe18rdoMMe6IE0UavPRiwZY+GxnbCoIXXx siq75br/ck5gUvdB2C3VR34VF3oWZTLCtTdwjYxeT5yXVF7pAztV6fyrPa/tQoSOff6iOPp zo94i1VPUXq+5/kWovNeA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:gb1LxFRHfzU=:NfvjD9Kuk7/AeZGNDEvdV5 /bA7c+abFvFFLaLKBvWWnHjzupokHiHg+jaqNzpFE2WYjHrtVuC4gMgvdZO4y3S34PNXdWjfM wqnMk/b2q75h1WdC6/kWPHOhbZNQr0ANRen9w1R70PqjvOCI7XcpjgRHimD2CzXB7AzVFcdoZ pPtTdkbQYvTSLxw8BYBW0i4v7yZHl5P59PDCdn2AtdJWVUfaRRmTs0dagR3/WQ/DODNBZxfM/ p6kbEQ8tNW7bhHzZBXJ7axwTspl8UXp6zg1Tk/fAh2x4rG+pOOHq6RoHMTD6t9HaP/rgv6gXf 5OFYhi91hf2ie0nje0StPKzkgLRKO7gUty9VBnyVCtI/6Rj7xcB5jzN/gsvV11G6+6e+y2GUz 7t26S42/ZX7OgdCDpAheaGua3bETTjvsPIBIfhetggs3Epj3Z6NTVX6cL+4Ivr7+4nhWY/qXI AYth/l5P6vp8KCf77uHQBogHOKmwJDXErHvdIUq3X5U+pIz/ktxdh6pN8SmVbA8YD+Hkq3anT GzbxCqdRH8nJfiftqSrar5m9Q969UJl8/Ge1ByvLjkN5fcWhnE6ZjK9jo8xRdqz9gKC7o+q7+ x8oU/4DNj52NVSPjh2Qb3PHMOfV6ZX1Ev7+bPWibNMlKkVqjGET3b/6QnaJ3BcQ/22q/YH8FU 3/qDrnVldAV+jR6qk6Eo+h6TluH8p89dkfB13mGUNThpGCPiz0AJorbMciyZ8PuLkix1Qp9rC NMH2LjHPDg0qwgyC/LCkvS5bRUiNT7TFDxcv3qFg7v6CS4ZFPNRsGFiwuxFBqpzn7Mmh3gUzY +GAC7QacilOEXNX3IXRGa7guukryclQBQCGzVNLeOc5B1pqXFRg8qVMAZnvmsSPIWlsHgaqzE r39gMLYEcFN91mxgZCVw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The audio driver should not use a hardwired gpio number from the header. Change it to use a lookup table. Cc: Mark Brown Cc: alsa-devel@alsa-project.org Signed-off-by: Arnd Bergmann Acked-by: Mark Brown --- arch/arm/mach-pxa/spitz.c | 33 ++++++++++- arch/arm/mach-pxa/{include/mach => }/spitz.h | 2 +- arch/arm/mach-pxa/spitz_pm.c | 2 +- sound/soc/pxa/spitz.c | 58 ++++++++------------ 4 files changed, 57 insertions(+), 38 deletions(-) rename arch/arm/mach-pxa/{include/mach => }/spitz.h (99%) -- 2.20.0 diff --git a/arch/arm/mach-pxa/spitz.c b/arch/arm/mach-pxa/spitz.c index a4fdc399d152..6028fd83c44d 100644 --- a/arch/arm/mach-pxa/spitz.c +++ b/arch/arm/mach-pxa/spitz.c @@ -44,7 +44,7 @@ #include #include #include -#include +#include "spitz.h" #include "sharpsl_pm.h" #include @@ -948,11 +948,42 @@ static void __init spitz_i2c_init(void) static inline void spitz_i2c_init(void) {} #endif +static struct gpiod_lookup_table spitz_audio_gpio_table = { + .dev_id = "spitz-audio", + .table = { + GPIO_LOOKUP("sharp-scoop.0", SPITZ_GPIO_MUTE_L - SPITZ_SCP_GPIO_BASE, + "mute-l", GPIO_ACTIVE_HIGH), + GPIO_LOOKUP("sharp-scoop.0", SPITZ_GPIO_MUTE_R - SPITZ_SCP_GPIO_BASE, + "mute-r", GPIO_ACTIVE_HIGH), + GPIO_LOOKUP("sharp-scoop.1", SPITZ_GPIO_MIC_BIAS - SPITZ_SCP2_GPIO_BASE, + "mic", GPIO_ACTIVE_HIGH), + { }, + }, +}; + +static struct gpiod_lookup_table akita_audio_gpio_table = { + .dev_id = "spitz-audio", + .table = { + GPIO_LOOKUP("sharp-scoop.0", SPITZ_GPIO_MUTE_L - SPITZ_SCP_GPIO_BASE, + "mute-l", GPIO_ACTIVE_HIGH), + GPIO_LOOKUP("sharp-scoop.0", SPITZ_GPIO_MUTE_R - SPITZ_SCP_GPIO_BASE, + "mute-r", GPIO_ACTIVE_HIGH), + GPIO_LOOKUP("gpio-pxa", AKITA_GPIO_MIC_BIAS - AKITA_IOEXP_GPIO_BASE, + "mic", GPIO_ACTIVE_HIGH), + { }, + }, +}; + /****************************************************************************** * Audio devices ******************************************************************************/ static inline void spitz_audio_init(void) { + if (machine_is_akita()) + gpiod_add_lookup_table(&akita_audio_gpio_table); + else + gpiod_add_lookup_table(&spitz_audio_gpio_table); + platform_device_register_simple("spitz-audio", -1, NULL, 0); } diff --git a/arch/arm/mach-pxa/include/mach/spitz.h b/arch/arm/mach-pxa/spitz.h similarity index 99% rename from arch/arm/mach-pxa/include/mach/spitz.h rename to arch/arm/mach-pxa/spitz.h index 04828d8918aa..f97e3ebd762d 100644 --- a/arch/arm/mach-pxa/include/mach/spitz.h +++ b/arch/arm/mach-pxa/spitz.h @@ -11,7 +11,7 @@ #define __ASM_ARCH_SPITZ_H 1 #endif -#include "irqs.h" /* PXA_NR_BUILTIN_GPIO, PXA_GPIO_TO_IRQ */ +#include /* PXA_NR_BUILTIN_GPIO, PXA_GPIO_TO_IRQ */ #include /* Spitz/Akita GPIOs */ diff --git a/arch/arm/mach-pxa/spitz_pm.c b/arch/arm/mach-pxa/spitz_pm.c index 201dabe883b6..6689b67f9ce5 100644 --- a/arch/arm/mach-pxa/spitz_pm.c +++ b/arch/arm/mach-pxa/spitz_pm.c @@ -19,7 +19,7 @@ #include #include -#include +#include "spitz.h" #include "pxa27x.h" #include "sharpsl_pm.h" diff --git a/sound/soc/pxa/spitz.c b/sound/soc/pxa/spitz.c index f7babffb7228..8fcdade9c8dd 100644 --- a/sound/soc/pxa/spitz.c +++ b/sound/soc/pxa/spitz.c @@ -14,13 +14,12 @@ #include #include #include -#include +#include #include #include #include #include -#include #include "../codecs/wm8750.h" #include "pxa2xx-i2s.h" @@ -37,7 +36,7 @@ static int spitz_jack_func; static int spitz_spk_func; -static int spitz_mic_gpio; +static struct gpio_desc *gpiod_mic, *gpiod_mute_l, *gpiod_mute_r; static void spitz_ext_control(struct snd_soc_dapm_context *dapm) { @@ -56,8 +55,8 @@ static void spitz_ext_control(struct snd_soc_dapm_context *dapm) snd_soc_dapm_disable_pin_unlocked(dapm, "Mic Jack"); snd_soc_dapm_disable_pin_unlocked(dapm, "Line Jack"); snd_soc_dapm_enable_pin_unlocked(dapm, "Headphone Jack"); - gpio_set_value(SPITZ_GPIO_MUTE_L, 1); - gpio_set_value(SPITZ_GPIO_MUTE_R, 1); + gpiod_set_value(gpiod_mute_l, 1); + gpiod_set_value(gpiod_mute_r, 1); break; case SPITZ_MIC: /* enable mic jack and bias, mute hp */ @@ -65,8 +64,8 @@ static void spitz_ext_control(struct snd_soc_dapm_context *dapm) snd_soc_dapm_disable_pin_unlocked(dapm, "Headset Jack"); snd_soc_dapm_disable_pin_unlocked(dapm, "Line Jack"); snd_soc_dapm_enable_pin_unlocked(dapm, "Mic Jack"); - gpio_set_value(SPITZ_GPIO_MUTE_L, 0); - gpio_set_value(SPITZ_GPIO_MUTE_R, 0); + gpiod_set_value(gpiod_mute_l, 0); + gpiod_set_value(gpiod_mute_r, 0); break; case SPITZ_LINE: /* enable line jack, disable mic bias and mute hp */ @@ -74,8 +73,8 @@ static void spitz_ext_control(struct snd_soc_dapm_context *dapm) snd_soc_dapm_disable_pin_unlocked(dapm, "Headset Jack"); snd_soc_dapm_disable_pin_unlocked(dapm, "Mic Jack"); snd_soc_dapm_enable_pin_unlocked(dapm, "Line Jack"); - gpio_set_value(SPITZ_GPIO_MUTE_L, 0); - gpio_set_value(SPITZ_GPIO_MUTE_R, 0); + gpiod_set_value(gpiod_mute_l, 0); + gpiod_set_value(gpiod_mute_r, 0); break; case SPITZ_HEADSET: /* enable and unmute headset jack enable mic bias, mute L hp */ @@ -83,8 +82,8 @@ static void spitz_ext_control(struct snd_soc_dapm_context *dapm) snd_soc_dapm_enable_pin_unlocked(dapm, "Mic Jack"); snd_soc_dapm_disable_pin_unlocked(dapm, "Line Jack"); snd_soc_dapm_enable_pin_unlocked(dapm, "Headset Jack"); - gpio_set_value(SPITZ_GPIO_MUTE_L, 0); - gpio_set_value(SPITZ_GPIO_MUTE_R, 1); + gpiod_set_value(gpiod_mute_l, 0); + gpiod_set_value(gpiod_mute_r, 1); break; case SPITZ_HP_OFF: @@ -93,8 +92,8 @@ static void spitz_ext_control(struct snd_soc_dapm_context *dapm) snd_soc_dapm_disable_pin_unlocked(dapm, "Headset Jack"); snd_soc_dapm_disable_pin_unlocked(dapm, "Mic Jack"); snd_soc_dapm_disable_pin_unlocked(dapm, "Line Jack"); - gpio_set_value(SPITZ_GPIO_MUTE_L, 0); - gpio_set_value(SPITZ_GPIO_MUTE_R, 0); + gpiod_set_value(gpiod_mute_l, 0); + gpiod_set_value(gpiod_mute_r, 0); break; } @@ -199,7 +198,7 @@ static int spitz_set_spk(struct snd_kcontrol *kcontrol, static int spitz_mic_bias(struct snd_soc_dapm_widget *w, struct snd_kcontrol *k, int event) { - gpio_set_value_cansleep(spitz_mic_gpio, SND_SOC_DAPM_EVENT_ON(event)); + gpiod_set_value_cansleep(gpiod_mic, SND_SOC_DAPM_EVENT_ON(event)); return 0; } @@ -287,39 +286,28 @@ static int spitz_probe(struct platform_device *pdev) struct snd_soc_card *card = &snd_soc_spitz; int ret; - if (machine_is_akita()) - spitz_mic_gpio = AKITA_GPIO_MIC_BIAS; - else - spitz_mic_gpio = SPITZ_GPIO_MIC_BIAS; - - ret = gpio_request(spitz_mic_gpio, "MIC GPIO"); - if (ret) - goto err1; - - ret = gpio_direction_output(spitz_mic_gpio, 0); - if (ret) - goto err2; + gpiod_mic = devm_gpiod_get(&pdev->dev, "mic", GPIOD_OUT_LOW); + if (IS_ERR(gpiod_mic)) + return PTR_ERR(gpiod_mic); + gpiod_mute_l = devm_gpiod_get(&pdev->dev, "mute-l", GPIOD_OUT_LOW); + if (IS_ERR(gpiod_mute_l)) + return PTR_ERR(gpiod_mute_l); + gpiod_mute_r = devm_gpiod_get(&pdev->dev, "mute-r", GPIOD_OUT_LOW); + if (IS_ERR(gpiod_mute_r)) + return PTR_ERR(gpiod_mute_r); card->dev = &pdev->dev; ret = devm_snd_soc_register_card(&pdev->dev, card); - if (ret) { + if (ret) dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret); - goto err2; - } - - return 0; -err2: - gpio_free(spitz_mic_gpio); -err1: return ret; } static int spitz_remove(struct platform_device *pdev) { - gpio_free(spitz_mic_gpio); return 0; }