From patchwork Fri Oct 7 09:08:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frieder Schrempf X-Patchwork-Id: 9365803 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 B7E5360487 for ; Fri, 7 Oct 2016 09:09:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A855B29423 for ; Fri, 7 Oct 2016 09:09:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D4B129426; Fri, 7 Oct 2016 09:09:07 +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=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 57CDA29425 for ; Fri, 7 Oct 2016 09:09:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756278AbcJGJIh convert rfc822-to-8bit (ORCPT ); Fri, 7 Oct 2016 05:08:37 -0400 Received: from smtp.exceet.ch ([77.245.33.226]:41043 "EHLO smtp.exceet.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754585AbcJGJIX (ORCPT ); Fri, 7 Oct 2016 05:08:23 -0400 Received: from XMAIL01.exceet.ch ([fe80::7c99:96b7:232d:52b1]) by XMAIL02.exceet.ch ([fe80::54c9:4bff:1172:809%12]) with mapi id 14.03.0210.002; Fri, 7 Oct 2016 11:08:18 +0200 From: Schrempf Frieder To: "robh@kernel.org" CC: "dmitry.torokhov@gmail.com" , "pawel.moll@arm.com" , "ijc+devicetree@hellion.org.uk" , "galak@codeaurora.org" , "luis@debethencourt.com" , "linux-input@vger.kernel.org" , "devicetree@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "Schrempf Frieder" Subject: [PATCH v2 3/3] input: pwm-beeper: add devicetree bindings to set volume levels Thread-Topic: [PATCH v2 3/3] input: pwm-beeper: add devicetree bindings to set volume levels Thread-Index: AQHSIHpYdTC6bffkWEuc6XV064Ng7w== Date: Fri, 7 Oct 2016 09:08:18 +0000 Message-ID: <1475831223-6006-4-git-send-email-frieder.schrempf@exceet.de> References: <1475831223-6006-1-git-send-email-frieder.schrempf@exceet.de> In-Reply-To: <1475831223-6006-1-git-send-email-frieder.schrempf@exceet.de> Accept-Language: de-DE, en-US Content-Language: de-DE X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [178.2.219.242] x-tm-as-product-ver: SMEX-11.0.0.4255-8.000.1202-22622.006 x-tm-as-result: No--38.340900-5.000000-31 x-tm-as-user-approved-sender: No x-tm-as-user-blocked-sender: No MIME-Version: 1.0 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 patch adds the devicetree bindings to set the volume levels and the default volume level. Signed-off-by: Frieder Schrempf --- Changes in v2: - split into 3 separate patches - make volume properties optional drivers/input/misc/pwm-beeper.c | 49 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c index 3ed21da..a7f9d70 100644 --- a/drivers/input/misc/pwm-beeper.c +++ b/drivers/input/misc/pwm-beeper.c @@ -32,7 +32,7 @@ struct pwm_beeper { struct work_struct work; unsigned long period; unsigned int volume; - unsigned int volume_levels[] = {0, 8, 20, 40, 500}; + unsigned int *volume_levels; unsigned int max_volume_level; }; @@ -161,8 +161,11 @@ static void pwm_beeper_close(struct input_dev *input) static int pwm_beeper_probe(struct platform_device *pdev) { unsigned long pwm_id = (unsigned long)dev_get_platdata(&pdev->dev); + struct device_node *np = pdev->dev.of_node; struct pwm_beeper *beeper; - int error; + struct property *prop; + int error, length; + u32 value; beeper = kzalloc(sizeof(*beeper), GFP_KERNEL); if (!beeper) @@ -188,7 +191,47 @@ static int pwm_beeper_probe(struct platform_device *pdev) INIT_WORK(&beeper->work, pwm_beeper_work); - beeper->max_volume_level = ARRAY_SIZE(beeper->volume_levels) - 1; + /* determine the number of volume levels */ + prop = of_find_property(np, "volume-levels", &length); + if (!prop) { + dev_dbg(&pdev->dev, "no volume levels specified, using max volume\n"); + beeper->max_volume_level = 1; + } else + beeper->max_volume_level = length / sizeof(u32); + + /* read volume levels from DT property */ + if (beeper->max_volume_level > 0) { + size_t size = sizeof(*beeper->volume_levels) * + beeper->max_volume_level; + + beeper->volume_levels = devm_kzalloc(&(pdev->dev), size, + GFP_KERNEL); + if (!beeper->volume_levels) + return -ENOMEM; + + if (prop) { + error = of_property_read_u32_array(np, "volume-levels", + beeper->volume_levels, + beeper->max_volume_level); + + if (error < 0) + return error; + + error = of_property_read_u32(np, "default-volume-level", + &value); + + if (error < 0) { + dev_dbg(&pdev->dev, "no default volume specified, using max volume\n"); + value = beeper->max_volume_level - 1; + } + } else { + beeper->volume_levels[0] = 500; + value = 0; + } + + beeper->volume = value; + beeper->max_volume_level--; + } beeper->input = input_allocate_device(); if (!beeper->input) {