From patchwork Mon Feb 20 08:37:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiko Schocher X-Patchwork-Id: 9582157 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 19C66600C1 for ; Mon, 20 Feb 2017 08:38:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C89728851 for ; Mon, 20 Feb 2017 08:38:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F3F4E28864; Mon, 20 Feb 2017 08:38:06 +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,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 F1BB628851 for ; Mon, 20 Feb 2017 08:38:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751893AbdBTIiE (ORCPT ); Mon, 20 Feb 2017 03:38:04 -0500 Received: from mail-out.m-online.net ([212.18.0.10]:52980 "EHLO mail-out.m-online.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750936AbdBTIiE (ORCPT ); Mon, 20 Feb 2017 03:38:04 -0500 Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 3vRcTQ28c4z3hnV9; Mon, 20 Feb 2017 09:38:02 +0100 (CET) Received: from localhost (dynscan01.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 3vRcTQ0glKzvkQM; Mon, 20 Feb 2017 09:38:02 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan01.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id 9BR0cIojPcIv; Mon, 20 Feb 2017 09:38:01 +0100 (CET) X-Auth-Info: 2V0fHAAqNiFH4lUk72nVUR4XyNp6bj/GAcr0AUvd97k= Received: from mail-internal.denx.de (p578adb1c.dip0.t-ipconnect.de [87.138.219.28]) by mail.mnet-online.de (Postfix) with ESMTPA; Mon, 20 Feb 2017 09:38:01 +0100 (CET) Received: from pollux.denx.de (pollux [192.168.1.1]) by mail-internal.denx.de (Postfix) with ESMTP id BC467180793; Mon, 20 Feb 2017 09:37:45 +0100 (CET) Received: by pollux.denx.de (Postfix, from userid 515) id 8A7F92134; Mon, 20 Feb 2017 09:37:45 +0100 (CET) From: Heiko Schocher To: linux-input@vger.kernel.org Cc: Guan Ben , Mark Jonas , Heiko Schocher , devicetree@vger.kernel.org, Thierry Reding , linux-kernel@vger.kernel.org, Boris Brezillon , Rob Herring , Dmitry Torokhov , Manfred Schlaegl , Mark Rutland Subject: [PATCH v2] Input: pwm-beeper: support customized freq for SND_BELL Date: Mon, 20 Feb 2017 09:37:43 +0100 Message-Id: <1487579863-7256-1-git-send-email-hs@denx.de> X-Mailer: git-send-email 2.7.4 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 From: Guan Ben extend the pwm-beeper driver to support customized frequency for SND_BELL from device tree. Signed-off-by: Guan Ben Signed-off-by: Mark Jonas [hs@denx.de: adapted to 4.10-rc7] Signed-off-by: Heiko Schocher Acked-by: Rob Herring --- Changes in v2: - add comment from Rob Herring: rename property name "bell-frequency" to "beeper-hz" - add comment from Dmitry Torokhov: use device_property_read_u32() instead of of_property_read_u32() - rebased against c470abd4fde40ea6a0846a2beab642a578c0b8cd Linux 4.10 .../devicetree/bindings/input/pwm-beeper.txt | 3 ++ drivers/input/misc/pwm-beeper.c | 36 ++++++++++++++++------ 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/Documentation/devicetree/bindings/input/pwm-beeper.txt b/Documentation/devicetree/bindings/input/pwm-beeper.txt index be332ae..4e4e128 100644 --- a/Documentation/devicetree/bindings/input/pwm-beeper.txt +++ b/Documentation/devicetree/bindings/input/pwm-beeper.txt @@ -5,3 +5,6 @@ Registers a PWM device as beeper. Required properties: - compatible: should be "pwm-beeper" - pwms: phandle to the physical PWM device + +optional properties: +- beeper-hz: bell frequency in Hz diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c index 5f9655d..5ea6fda 100644 --- a/drivers/input/misc/pwm-beeper.c +++ b/drivers/input/misc/pwm-beeper.c @@ -27,6 +27,7 @@ struct pwm_beeper { struct pwm_device *pwm; struct work_struct work; unsigned long period; + unsigned int bell_frequency; }; #define HZ_TO_NANOSECONDS(x) (1000000000UL/(x)) @@ -58,20 +59,17 @@ static int pwm_beeper_event(struct input_dev *input, if (type != EV_SND || value < 0) return -EINVAL; - switch (code) { - case SND_BELL: - value = value ? 1000 : 0; - break; - case SND_TONE: - break; - default: + if (code != SND_BELL && code != SND_TONE) return -EINVAL; - } if (value == 0) beeper->period = 0; - else + else { + if (code == SND_BELL) + value = beeper->bell_frequency; + beeper->period = HZ_TO_NANOSECONDS(value); + } schedule_work(&beeper->work); @@ -93,6 +91,25 @@ static void pwm_beeper_close(struct input_dev *input) pwm_beeper_stop(beeper); } +static void pwm_beeper_init_bell_frequency(struct device *dev, + struct pwm_beeper *beeper) +{ + struct device_node *node; + unsigned int bell_frequency = 1000; + int err; + + if (IS_ENABLED(CONFIG_OF)) { + node = dev->of_node; + err = device_property_read_u32(dev, "beeper-hz", + &bell_frequency); + if (err < 0) + dev_dbg(dev, "Failed to read beeper-hz, using default: %u Hz\n", + bell_frequency); + } + + beeper->bell_frequency = bell_frequency; +} + static int pwm_beeper_probe(struct platform_device *pdev) { unsigned long pwm_id = (unsigned long)dev_get_platdata(&pdev->dev); @@ -122,6 +139,7 @@ static int pwm_beeper_probe(struct platform_device *pdev) pwm_apply_args(beeper->pwm); INIT_WORK(&beeper->work, pwm_beeper_work); + pwm_beeper_init_bell_frequency(&pdev->dev, beeper); beeper->input = input_allocate_device(); if (!beeper->input) {