From patchwork Fri Jan 6 02:43:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 9499921 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 1C67560236 for ; Fri, 6 Jan 2017 02:44:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 12DE02848B for ; Fri, 6 Jan 2017 02:44:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 07F812848D; Fri, 6 Jan 2017 02:44:41 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable 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 577552848B for ; Fri, 6 Jan 2017 02:44:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754324AbdAFCoH (ORCPT ); Thu, 5 Jan 2017 21:44:07 -0500 Received: from vern.gendns.com ([206.190.152.46]:56124 "EHLO vern.gendns.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932107AbdAFCoB (ORCPT ); Thu, 5 Jan 2017 21:44:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lechnology.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject :Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=7GwoLpOM6RRJM0T97stcVAWzt2H149CZEHpaxL1QD7I=; b=uGgLfAQfyColr996b1ne9aURY c1eG3gt82RDX+VEZCDBwwUukVgP/ZImOX+uTlSxSOaIQylgvjY0y0KeVhPpgMwpA7Is1ypcVIEXiZ LPSmIsSUMiJuBmp5ydwFYnt9WZ6UfPYt30aG1fdV/WURKEcPLDgiNCtxSGbBqjZrOO3HrJHulnRY8 TJLoyaOh4b9g/d8dOm/W+4Py01uY2Y0QFIXh4q96DJO3miEYPs0XNcgd9B1wsKVBtxF20HJmZaphl WEiqTxNbkau7Nod2CXDwwB31u68Q0Sdyw3gh8tRWD0feHC+m+ebc3urVn+TjYPGaRWh8pMcTwrHR0 bX/PZGZCA==; Received: from 108-198-5-147.lightspeed.okcbok.sbcglobal.net ([108.198.5.147]:47742 helo=freyr.lechnology.com) by vern.gendns.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-SHA256:128) (Exim 4.87) (envelope-from ) id 1cPKVZ-000JaJ-Uz; Thu, 05 Jan 2017 21:43:58 -0500 From: David Lechner To: Dmitry Torokhov , Rob Herring , Mark Rutland Cc: David Lechner , linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] Input: pwm-beeper: add optional enable gpio Date: Thu, 5 Jan 2017 20:43:54 -0600 Message-Id: <1483670635-25060-4-git-send-email-david@lechnology.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1483670635-25060-1-git-send-email-david@lechnology.com> References: <1483670635-25060-1-git-send-email-david@lechnology.com> X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - vern.gendns.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lechnology.com X-Get-Message-Sender-Via: vern.gendns.com: authenticated_id: davidmain+lechnology.com/only user confirmed/virtual account not confirmed X-Authenticated-Sender: vern.gendns.com: davidmain@lechnology.com X-Source: X-Source-Args: X-Source-Dir: Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This adds an optional enable gpio to the pwm-beeper device. This gpio is used in cases where the beeper needs to be switched on before using it. For example, there may be an amplifier that is not always powered on. Tested on LEGO MINDSTORMS EV3, which has a speaker connected to PWM through an amplifier. The amplifier has an enable pin that is connected to a gpio. Signed-off-by: David Lechner --- drivers/input/misc/pwm-beeper.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c index e76b710..4379ceb 100644 --- a/drivers/input/misc/pwm-beeper.c +++ b/drivers/input/misc/pwm-beeper.c @@ -14,6 +14,7 @@ */ #include +#include #include #include #include @@ -25,6 +26,7 @@ struct pwm_beeper { struct input_dev *input; struct pwm_device *pwm; + struct gpio_desc *enable_gpio; struct work_struct work; unsigned long period; }; @@ -38,8 +40,13 @@ static void __pwm_beeper_set(struct pwm_beeper *beeper) if (period) { pwm_config(beeper->pwm, period / 2, period); pwm_enable(beeper->pwm); - } else + if (beeper->enable_gpio) + gpiod_direction_output(beeper->enable_gpio, 1); + } else { + if (beeper->enable_gpio) + gpiod_direction_output(beeper->enable_gpio, 0); pwm_disable(beeper->pwm); + } } static void pwm_beeper_work(struct work_struct *work) @@ -82,6 +89,8 @@ static void pwm_beeper_stop(struct pwm_beeper *beeper) { cancel_work_sync(&beeper->work); + if (beeper->enable_gpio) + gpiod_direction_output(beeper->enable_gpio, 0); if (beeper->period) pwm_disable(beeper->pwm); } @@ -116,6 +125,15 @@ static int pwm_beeper_probe(struct platform_device *pdev) goto err_free; } + beeper->enable_gpio = devm_gpiod_get_optional(&pdev->dev, "enable", + GPIOD_OUT_LOW); + error = PTR_ERR_OR_ZERO(beeper->enable_gpio); + if (error) { + if (error != -EPROBE_DEFER) + dev_err(&pdev->dev, "Failed to get enable gpio\n"); + goto err_pwm_free; + } + /* * FIXME: pwm_apply_args() should be removed when switching to * the atomic PWM API.