From patchwork Fri May 20 09:48:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuninori Morimoto X-Patchwork-Id: 9129053 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 969F260762 for ; Fri, 20 May 2016 09:48:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 88BC41FF6C for ; Fri, 20 May 2016 09:48:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7DA2525D91; Fri, 20 May 2016 09:48:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE6BE1FF6C for ; Fri, 20 May 2016 09:48:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932274AbcETJsn (ORCPT ); Fri, 20 May 2016 05:48:43 -0400 Received: from relmlor3.renesas.com ([210.160.252.173]:31830 "EHLO relmlie2.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932604AbcETJsm (ORCPT ); Fri, 20 May 2016 05:48:42 -0400 Received: from unknown (HELO relmlir2.idc.renesas.com) ([10.200.68.152]) by relmlie2.idc.renesas.com with ESMTP; 20 May 2016 18:48:41 +0900 Received: from relmlac4.idc.renesas.com (relmlac4.idc.renesas.com [10.200.69.24]) by relmlir2.idc.renesas.com (Postfix) with ESMTP id 0897752C0E; Fri, 20 May 2016 18:48:41 +0900 (JST) Received: by relmlac4.idc.renesas.com (Postfix, from userid 0) id E2B43480A4; Fri, 20 May 2016 18:48:40 +0900 (JST) Received: from relmlac4.idc.renesas.com (localhost [127.0.0.1]) by relmlac4.idc.renesas.com (Postfix) with ESMTP id DBEFF480A3; Fri, 20 May 2016 18:48:40 +0900 (JST) Received: from relmlii2.idc.renesas.com [10.200.68.66] by relmlac4.idc.renesas.com with ESMTP id UAC03906; Fri, 20 May 2016 18:48:40 +0900 X-IronPort-AV: E=Sophos;i="5.22,559,1449500400"; d="scan'";a="211713834" Received: from mail-sg2apc01lp0243.outbound.protection.outlook.com (HELO APC01-SG2-obe.outbound.protection.outlook.com) ([65.55.88.243]) by relmlii2.idc.renesas.com with ESMTP/TLS/AES256-SHA; 20 May 2016 18:48:40 +0900 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesasgroup.onmicrosoft.com; s=selector1-renesas-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=rSlsondhiQ46Rf2ioqsa/jjRpKFHQa+81Cn3YzlXDk0=; b=XJ9xq3NrTmsbLBn8aGiXmeRda6wdMFF2s3YmzAxsXL2EOrYf8/jt8phAZ2qx427bIiFKwedGgLU66Ejkb15Ej0eAQNrRb625SAryOO153qQQLYk+TNWOhD9INKF4ZWm60/J1UTdC6eS0P3HPA9jyI7Q2ql0V7gyEruCfaptbI6U= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none; kernel.org; dmarc=none action=none header.from=renesas.com; Received: from morimoto-PC.renesas.com (211.11.155.144) by HK2PR06MB1698.apcprd06.prod.outlook.com (10.167.73.12) with Microsoft SMTP Server (TLS) id 15.1.497.12; Fri, 20 May 2016 09:48:38 +0000 Message-ID: <87zirlqd4t.wl%kuninori.morimoto.gx@renesas.com> From: Kuninori Morimoto Subject: [PATCH 15/49] ASoC: simple-card-core: add asoc_simple_card_init_jack() User-Agent: Wanderlust/2.15.9 Emacs/24.3 Mule/6.0 To: Mark Brown CC: Linux-ALSA , Liam Girdwood , Simon , In-Reply-To: <87lh35rs8w.wl%kuninori.morimoto.gx@renesas.com> References: <87lh35rs8w.wl%kuninori.morimoto.gx@renesas.com> MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Date: Fri, 20 May 2016 09:48:38 +0000 X-Originating-IP: [211.11.155.144] X-ClientProxiedBy: OS2PR01CA0067.jpnprd01.prod.outlook.com (10.165.51.155) To HK2PR06MB1698.apcprd06.prod.outlook.com (10.167.73.12) X-MS-Office365-Filtering-Correlation-Id: 5bff26ae-ad46-4d5e-9a1e-08d38093eb63 X-Microsoft-Exchange-Diagnostics: 1; HK2PR06MB1698; 2:zag1gm4tWsmK+UXTYwgLl//QrqekMPcn+/o3yzxUb0gQomPvN7Mb2as9fCbKnQuZMOYLQgPuWJHRnsyAC+PAPwvAXZeWs9oYFx6XuDkhF02XZ5elM4k2VFIDCU3NCiUfpVgqe+NJhwkaUJ1v3ibaVLwcclcdVmxxFIBXYoSFL4UTkw6XLFXzOqvw5fZ93vUK; 3:hGCqjBshvDIHCs1lvVOryaVSaVJhVhgLwp+YJwF8o3k9qNUox0Zc7kfwwfISE8dSO1Al2puBgvsYSLEvO2PfUApLpjlVK5s/HlhNYp8VoKWDaIxf9Mz7gVLbuenWAIrd X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:HK2PR06MB1698; X-Microsoft-Exchange-Diagnostics: 1; HK2PR06MB1698; 25:sU/NFVK8BgPKPRqFssgHggHK9AQeuXqZhXw6xomS21pEKqavY3pgCHtT48QMcTJ3w5P51bdx3a1IK9OyztL2whPmPIQ+vWWPawIcdcSzQ7YJs/Gkgzw7Fee2Q6INjPtq1h8O/IiLTac3xNGk+cn17xJFRmbQVydrb+meocq1OnfY2m5TfMmKYol4d6ClMGoMeWifa/vw2dlktrKQD/uiecOvvizZeNOmSZH6DBzsMLxGCKTiYqyewMSj+aBlRxFIddLljeV4dX8/7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ioe+sv62phWe7Fx+0YA3cWzzFy+OSvxYIlsVCSl5tcxQqXQztxCCEu984mq/2mzNoXDSDXG9XGY4hTZDkJGDpfasLO8SnkFbgp8stQhhaOMLd4Bj8xB477UGX/u0WBj9J2dFe/3deFXSQz6TB2X+SO2cg7MPhBvcoeaPB0I75p+LWWdr/bbN8ghJ+4JCx00IUc7twteI3cex/Tj08B8zPVZ3M1gGsvOtLrhsAzAOez+9NHA2N8iM5AFzX7rt28KqRJfmdEmEN+bOxyWo8NaCoY9EX2kmE4br8it1O X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026); SRVR:HK2PR06MB1698; BCL:0; PCL:0; RULEID:; SRVR:HK2PR06MB1698; X-Forefront-PRVS: 09480768F8 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6009001)(53416004)(6116002)(230783001)(23726003)(42186005)(92566002)(50466002)(5004730100002)(46406003)(229853001)(586003)(4326007)(8676002)(66066001)(77096005)(110136002)(81166006)(3846002)(5008740100001)(47776003)(2906002)(189998001)(76176999)(50986999)(19580395003)(19580405001)(36756003)(54356999)(83506001)(2950100001)(33646002)(86362001)(16060500001); DIR:OUT; SFP:1102; SCL:1; SRVR:HK2PR06MB1698; H:morimoto-PC.renesas.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; HK2PR06MB1698; 23:bdT56i6qAHLoHAV9jOCSJ39LlJHfxzVQxtIU3fJA17BeBG/RWdo0G6fK/zCrGWYD1ebfKRUPqJm4uP9EI6WKFAYeMmFFcnI7UGTbY7KUCo5aDd796bLtyknuvavdPcgghICSXdTpE/rjdAz0et0e2AlqnSUIov6MxawcONa+5I+7t4T5WqKnPmezzGtPnb26/BkoFYt0x855MvUwpOV+77zhEq7Aw7i4t/G/uvGlLTvYu3m3ZTOhJBs3vg/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3Y/EmrTa3zSTvajzgmv2YEXZn7K/0mJSihL63rlWm1w+SMpTJaQMMyjsyeR0FggcLd7FT7mMGMCFjEKUD4uFE/yoiqd+Xp3dD2ZeRsB; 20:li37z/lhf9KgoXAEdEsSLkrTXjpewd1f7AJuyKwa57SJbBkTd3nwSvbhRkUyqtI8Sp3oIvZcKAYh0oOhtAkalfFRe9iJmqp9feAgySCkURV4CNV9Eu5m4KyT0GlEp6wLPwfBan7RiMUji2yRbZlV6Dm3S52uG2LIbeG/K3DAy48= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 May 2016 09:48:38.1780 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HK2PR06MB1698 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Kuninori Morimoto simple-card is supporting jack/gpio. This patch makes this method simple style standard. Signed-off-by: Kuninori Morimoto --- include/sound/simple_card_core.h | 18 +++++++++++ sound/soc/generic/simple-card-core.c | 60 ++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/include/sound/simple_card_core.h b/include/sound/simple_card_core.h index 5e2e824..d37acee 100644 --- a/include/sound/simple_card_core.h +++ b/include/sound/simple_card_core.h @@ -11,6 +11,13 @@ #define __SIMPLE_CARD_CORE_H #include +#include + +struct asoc_simple_jack { + struct snd_soc_jack jack; + struct snd_soc_jack_pin pin; + struct snd_soc_jack_gpio gpio; +}; struct asoc_simple_dai { const char *name; @@ -76,4 +83,15 @@ int asoc_simple_card_parse_endpoint(struct device_node *port_np, void asoc_simple_card_parse_dpcm(struct snd_soc_dai_link *dai_link, int (*be_fixup)(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params)); + +#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) +int asoc_simple_card_init_jack(struct snd_soc_card *card, + struct asoc_simple_jack *sjack, + int is_hp, char *prefix); + +void asoc_simple_card_remove_jack(struct asoc_simple_jack *sjack); + #endif /* __SIMPLE_CARD_CORE_H */ diff --git a/sound/soc/generic/simple-card-core.c b/sound/soc/generic/simple-card-core.c index d3aab6d..86f64da 100644 --- a/sound/soc/generic/simple-card-core.c +++ b/sound/soc/generic/simple-card-core.c @@ -9,6 +9,7 @@ */ #include #include +#include #include int asoc_simple_card_parse_daifmt(struct device *dev, @@ -271,3 +272,62 @@ void asoc_simple_card_parse_dpcm(struct snd_soc_dai_link *dai_link, dai_link->dpcm_capture = 1; } EXPORT_SYMBOL_GPL(asoc_simple_card_parse_dpcm); + +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; +} +EXPORT_SYMBOL_GPL(asoc_simple_card_init_jack); + +void asoc_simple_card_remove_jack(struct asoc_simple_jack *sjack) +{ + if (gpio_is_valid(sjack->gpio.gpio)) + snd_soc_jack_free_gpios(&sjack->jack, 1, &sjack->gpio); +} +EXPORT_SYMBOL_GPL(asoc_simple_card_remove_jack);