From patchwork Wed Jan 11 20:02:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 9511151 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 92A8D6075C for ; Wed, 11 Jan 2017 20:03:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8230E28675 for ; Wed, 11 Jan 2017 20:03:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7707B28685; Wed, 11 Jan 2017 20:03:04 +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 5112428681 for ; Wed, 11 Jan 2017 20:03:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754863AbdAKUCm (ORCPT ); Wed, 11 Jan 2017 15:02:42 -0500 Received: from vern.gendns.com ([206.190.152.46]:49965 "EHLO vern.gendns.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757421AbdAKUCU (ORCPT ); Wed, 11 Jan 2017 15:02:20 -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=w8/dZvva4yFGbjzOkpRItuVMsFAXEMdkgiwjlyoGJC8=; b=ZsRKtzQ6/a4AgUds2GaBXcyZG PHlYyjRXjJnpR3vFYuTbqspQXFoAzoXRPNmJk0Ym7q3XQhiMW7UHKQfNc3ymC2CSaDtPARw4t5de7 7iEnE4XM36V39Cx1YAtYrCKpI/oLgNk2yMw1ChKMN7dcJDz+6f1WO8UC0VtEgvAULkgbSThzIb3qm CgXguimj+xzLaNA293wC+Jx3dF+q6Dk8pmA3WjmKRidEeFXiIcS7v011kyfnI+I6jjYN7g7YvoW3M CHinnn5pRO8U4Y1c7ffXsrZ04GhXFuNs6JhfM5EQ6fEjS2JLlO9cPYn+z84ZG41FmJcJUQX7lXRhm Ej177d9xQ==; Received: from 108-198-5-147.lightspeed.okcbok.sbcglobal.net ([108.198.5.147]:52454 helo=freyr.lechnology.com) by vern.gendns.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-SHA256:128) (Exim 4.87) (envelope-from ) id 1cRP67-001Exb-Nu; Wed, 11 Jan 2017 15:02:16 -0500 From: David Lechner To: linux-input@vger.kernel.org, devicetree@vger.kernel.org Cc: David Lechner , Dmitry Torokhov , Rob Herring , Mark Rutland , linux-kernel@vger.kernel.org Subject: [PATCH v2 3/3] Input: pwm-beeper: add optional amplifier regulator Date: Wed, 11 Jan 2017 14:02:01 -0600 Message-Id: <1484164921-30587-4-git-send-email-david@lechnology.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1484164921-30587-1-git-send-email-david@lechnology.com> References: <1484164921-30587-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 regulator to the pwm-beeper device. This regulator acts as an amplifier. The amplifier is only enabled while beeping in order to reduce power consumption. Tested on LEGO MINDSTORMS EV3, which has a speaker connected to PWM through an amplifier. Signed-off-by: David Lechner --- drivers/input/misc/pwm-beeper.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c index 30ac227..708e88e 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,8 +26,10 @@ struct pwm_beeper { struct input_dev *input; struct pwm_device *pwm; + struct regulator *reg; struct work_struct work; unsigned long period; + bool reg_enabled; }; #define HZ_TO_NANOSECONDS(x) (1000000000UL/(x)) @@ -38,8 +41,20 @@ 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->reg) { + int error; + + error = regulator_enable(beeper->reg); + if (!error) + beeper->reg_enabled = true; + } + } else { + if (beeper->reg_enabled) { + regulator_disable(beeper->reg); + beeper->reg_enabled = false; + } pwm_disable(beeper->pwm); + } } static void pwm_beeper_work(struct work_struct *work) @@ -82,6 +97,10 @@ static void pwm_beeper_stop(struct pwm_beeper *beeper) { cancel_work_sync(&beeper->work); + if (beeper->reg_enabled) { + regulator_disable(beeper->reg); + beeper->reg_enabled = false; + } if (beeper->period) pwm_disable(beeper->pwm); } @@ -111,6 +130,14 @@ static int pwm_beeper_probe(struct platform_device *pdev) return error; } + beeper->reg = devm_regulator_get_optional(&pdev->dev, "amp"); + error = PTR_ERR_OR_ZERO(beeper->reg); + if (error) { + if (error != -EPROBE_DEFER) + dev_err(dev, "Failed to get amp regulator\n"); + return error; + } + /* * FIXME: pwm_apply_args() should be removed when switching to * the atomic PWM API.