From patchwork Tue Jan 24 11:14:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manuel Traut X-Patchwork-Id: 47665 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2092952wrn; Tue, 24 Jan 2023 03:24:30 -0800 (PST) X-Google-Smtp-Source: AMrXdXvlU8yEAHV5E4TIJ64HjZp/goarbZiEsJ2E+5F13GqK/Z1QXHjNYEenvrbti966YdYlkfFh X-Received: by 2002:a05:6402:25c4:b0:49e:24a4:4f32 with SMTP id x4-20020a05640225c400b0049e24a44f32mr32670209edb.13.1674559470603; Tue, 24 Jan 2023 03:24:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1674559470; cv=pass; d=google.com; s=arc-20160816; b=zSs0aCzpsXMVEZrP9CV5scDhTlHeqjGy+eTHG7v5xxe8E7uzgr67BnUtuAoefPriwa u9GYhfZ/DcYYPBPl9MMgqEuPCm7EjQat7Lu8k6QcQ2Gxpclz+VLnsMdG/+128146mGXT sD4sD7f+tJdiEUtAPKEgcNc/3A5Bf8D6d8DdaC7svp6XnvAGzRYBaL8AT0xjeMkVnifS LcOIPq0Jdc9ZCU8ueCHMakIxezZOKrHpkdnxjgg7BH2wY4dMLVnCmTyVmUh3IMf2MBFm EqxIwmcSY1ZdAOs2qMhTSESgo6kTishXsi1UrRft2t4wCUrnzUm1EMtSMnrsfKE58NjE NJVg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:in-reply-to:content-disposition :references:message-id:subject:cc:to:from:date:dkim-signature; bh=5rk0Ec+f7oeGVYewHTLfrRpUquwMeGurtyfD8/9RDIw=; b=MB2JW2+hvuMZz7TrNpfgvLICA6WUqwn5BffbLISp5n8IipzH6U+RO6G9aZQNVjzD2d PEMD22zOEAn+5H/1jmvUR6tF52WSni1gtq0nioNTgN9iw7W3tPlxGF429aYLJMfZtI6S YGKu65dKbF/ngf5nTiNzql1TcSIz4vSpm5Y8/gfnAUm7FbUO5l5Unl6tYqB2ZNMeeuDr Vn2Ug7iSdooW+01oqM6xxFvUL8hafVCAC0NkJpByRSHAL1U49CW6XFFKnCtBIVtjjPLr jrhoNhKTPNz4UlSmFucY7r1BUdta1c/EoME4KYpbImfym8p4Pe5FIvzMX32ICxidKXu5 8wYQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mt.com header.s=selector2 header.b=t0vGNhSC; arc=pass (i=1 spf=pass spfdomain=mt.com dkim=pass dkdomain=mt.com dmarc=pass fromdomain=mt.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b15-20020aa7dc0f000000b0049d699c63ccsi2619827edu.82.2023.01.24.03.24.05; Tue, 24 Jan 2023 03:24:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@mt.com header.s=selector2 header.b=t0vGNhSC; arc=pass (i=1 spf=pass spfdomain=mt.com dkim=pass dkdomain=mt.com dmarc=pass fromdomain=mt.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232143AbjAXLOR (ORCPT + 99 others); Tue, 24 Jan 2023 06:14:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233865AbjAXLOO (ORCPT ); Tue, 24 Jan 2023 06:14:14 -0500 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on20713.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe1a::713]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B8D13E622; Tue, 24 Jan 2023 03:14:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RFnfUOJerRBCqlOvh1HbGD5iN+ihiUkwmF0qFVeaSOH18GBTVfs3Aer+2V+9BrtKJQn6ZK7IPE0z/dza2b/iJPe6PlYAUWO0X7B0yf/jkcp5bTImPEwStJFTc4SahUBnjpS+22E+QHchDEo3rL6QKMiKydAviSA322vjFs1hLcWlLYvRXWynB6SFK+z24orSTvX1e7rbvQ/5t84dQYQVN/lEVF0s+pAPFrCQqAg+a9d/QEiC9CVioqjwy9ccXtIlRBVFAelYr7fiH/r/2ZupIzfxenNobzMYMIYLhwIJ6utdiO9MJV7PuQdT/KMfsKXpAni+krjR9ArzQATfWHMV5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5rk0Ec+f7oeGVYewHTLfrRpUquwMeGurtyfD8/9RDIw=; b=aU5x6Skv6QfjrN4oTE04wpvxerYiPThjj5mtThgIYfHgDdNJqoGfC091HRji37A9IQ9xqUs3CDO7OsGLN1+N98uKyfo18iTcjl/mwyiaQVggKJQJXnd4/M0q2ZeztMYss9VE/e/PoCvYEpSPKtgZnXEAAujQojwsrLMPdmz4AFe5Kp0gz+c18JT9jX+Itq42cVVGR/N3XDBea9OE1wsxjyBPjLG6H5HYi3GNujRUru7P4taiNXPq8fHCn+XJG3UnFCiwZCa6nDf+zCDQBC5UjEB7uS/etwbWZqamY1WX9HALanvQMXi/u1kU0kbrHjvNiAEiXgckquNxIqgP+XhYuA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=mt.com; dmarc=pass action=none header.from=mt.com; dkim=pass header.d=mt.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mt.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5rk0Ec+f7oeGVYewHTLfrRpUquwMeGurtyfD8/9RDIw=; b=t0vGNhSCPY1PSZI69MO6yxsCYR83u3tUBNd63ZcCFj2ENVVFtTW68E5+ebR5GzFxlcPnHhaM9XBxllUISZpXZDV5TpvfQ7raZnJvMogvip/dNMRfPNjJJzrQyvcH2b58JzMphJbTYcmEKyx0NPdEHWkFEWSc+1B34L45IwVTnH+NzQxkcfxLPLnkwrdinLPFLPnd3NxICnXHCGPtR7VyvoDZvS7k757Qm+ZvLxtIez932E7HEw68iQidv32tc1b4Dpygrp2TqDo14WGJN5qbrdYmn7SII+tjWWKtLuWiZMJZKSiIgTuthn/oht7JBlj1t4ffmzKKbydSaj+012baEQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=mt.com; Received: from AS8PR03MB7621.eurprd03.prod.outlook.com (2603:10a6:20b:345::20) by DB9PR03MB9639.eurprd03.prod.outlook.com (2603:10a6:10:45b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.33; Tue, 24 Jan 2023 11:14:07 +0000 Received: from AS8PR03MB7621.eurprd03.prod.outlook.com ([fe80::b42f:82f8:24cb:a225]) by AS8PR03MB7621.eurprd03.prod.outlook.com ([fe80::b42f:82f8:24cb:a225%5]) with mapi id 15.20.6002.033; Tue, 24 Jan 2023 11:14:06 +0000 Date: Tue, 24 Jan 2023 12:14:04 +0100 From: Manuel Traut To: linux-kernel@vger.kernel.org Cc: Dmitry Torokhov , Frieder Schrempf , linux-input@vger.kernel.org Subject: [PATCH 3/3 v6] input: pwm-beeper: add feature to set volume level Message-ID: References: Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: FR0P281CA0126.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:97::6) To AS8PR03MB7621.eurprd03.prod.outlook.com (2603:10a6:20b:345::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR03MB7621:EE_|DB9PR03MB9639:EE_ X-MS-Office365-Filtering-Correlation-Id: d1a47523-e166-42e7-f3b1-08dafdfc1bc1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7VHmlfZV2o+WRqMuDqIefGbUy5j2xgKhQjXAxCX2XA4RRnHsYGuLUukxdK0NaVqdy13d8nL8Us6BdqhOtEz5jC369d3UH2dWgD3/ksfKTAnhQN12xeDsdC3qX7RrSLKXNG7DqFTO23dO7cCQdbShwhlWJnjjI0Va0bUq5fLeHT92c3Aq4jBYOST04Y/DbV3KPdymWfiPFXQiyaBeNofWPo9ZXOX/KM9hOBMzDC+cKeaDikFlN+stXPTpa45ErlP1w7aa4a96sypy8LESTKaHSurIP3MvmUv/ZRZbRhvWMO+uBxbYlhlxQGw8nreeBiL2Akk1rHl5FdSA5yLOk18mHtifMVg0BuEmaPShXXTKs4WVI8w2o9Fsgj4lauR8kU+VBlYYvXZXTnFjzMBgtELUbxSR/N5fZ7BG/Ar3t3Y51/0gsYGOjMhPDLiIzgRQS93Wp/+ZM7jx0FI7Pb11x3s6rA+cAmGSAs95ZvnbACRK7cH5HwN7G/s+KMB41B3WUjLj21OcL5jtxaasqAFjJ7JoZNE14+mXligyDgtnBgXARf0jcolvzyOcXXiZwNkrPFQv2iQ08LFVN2HcnTVnryv7Nnk4DVbZ3caPIsCg+wmk5Y2g7N4f5CclHooMPezjWPmT033FnuT5r3ZIP1qk98mVAT2tGkyDR9PxgSq4rdp69dLTwx3S913RtEp3atUTIgTDJp3yv4lA2PKmDWuo9sAGJQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR03MB7621.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(346002)(366004)(136003)(396003)(39860400002)(376002)(451199015)(2906002)(83380400001)(54906003)(41300700001)(4326008)(66476007)(66946007)(36756003)(6916009)(66556008)(8676002)(44832011)(5660300002)(2616005)(8936002)(316002)(186003)(6512007)(38350700002)(86362001)(6506007)(38100700002)(26005)(52116002)(6486002)(478600001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?16D0KPS56VeX7hroTBqKx/NLOAy2?= =?utf-8?q?wjlb4+ZgHCcN8UOOr8bro1DM8rbrRgFxRQ+CFWew0uG07Y/ELS/3GMoaOqW1GqT+q?= =?utf-8?q?+cOgfYZ3PKw2Yc7LDuaEXjRSjtPgjJBJSPNDfGL3Uv81Ze7ciqbM4Xl0UnOLp3x3d?= =?utf-8?q?sUGE2BFnMAHeeQFcTmbCFnhmuM9ikh/sdgKjMec96UdJj1LUQ1Mb5AbKcLN0iUnpl?= =?utf-8?q?ma0diH4kPcJ8f/1gWrfaZBywlkLVTJUWHNxN6k7ZYt9SXgdcabccwDShNcOJrd5P2?= =?utf-8?q?qlAN31l/Oqw7UtiCVWLGjF96c2rZZl/ibuNxGMSN2SkGDxXHUGOcDC8QTlXkQfiQk?= =?utf-8?q?6IMmbDMfqm/osGnWcROIZWnRsrktBqJDv472YiLs8Jt79h+CRGQaspGj1SysIAF43?= =?utf-8?q?qfeKwNcR0mmLkIsFwFKrlR6UT5wTrUecF/W/+aOWuw5eJ6qYKtY4lBeMEVOpogVC/?= =?utf-8?q?NbOmpbAnAKC8n7UHzk4xkzriLROiyMbTLN4+uhGCSgspAfXQlXU1c18XSthjyI1cz?= =?utf-8?q?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iBuLhubLXahHyDW/9+T0tUvnYbPq+Kiy0ZROooNlS6Fp?= =?utf-8?q?0zE+v1E6FicmpobaUs47Xe8EtxZtK1p49YLQQ/hxMD1Tsz5vv6y6i9lsnqtXwn6/2?= =?utf-8?q?AWnFVPLBLqVJ?= X-OriginatorOrg: mt.com X-MS-Exchange-CrossTenant-Network-Message-Id: d1a47523-e166-42e7-f3b1-08dafdfc1bc1 X-MS-Exchange-CrossTenant-AuthSource: AS8PR03MB7621.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2023 11:14:06.6409 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fb4c0aee-6cd2-482f-a1a5-717e7c02496b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 66PhHALcmEW1OXc9G8yCoMqYw9AsCd6aP2zZqDZdx8+uGt84cTppCS/o0lEP74PVf8wzOVzJ+ZLRNkkkgUbH+w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR03MB9639 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755902235795346530?= X-GMAIL-MSGID: =?utf-8?q?1755902871045032367?= This patch adds the devicetree bindings to set the volume levels and the default volume level. Signed-off-by: Frieder Schrempf --- drivers/input/misc/pwm-beeper.c | 58 +++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c index fadc73e1c89a..f95d6b5899c7 100644 --- a/drivers/input/misc/pwm-beeper.c +++ b/drivers/input/misc/pwm-beeper.c @@ -181,8 +181,9 @@ static int pwm_beeper_probe(struct platform_device *pdev) struct pwm_beeper *beeper; struct pwm_state state; u32 bell_frequency; - int error; + int error, length; size_t size; + u32 value; beeper = devm_kzalloc(dev, sizeof(*beeper), GFP_KERNEL); if (!beeper) @@ -228,23 +229,46 @@ static int pwm_beeper_probe(struct platform_device *pdev) beeper->bell_frequency = bell_frequency; - beeper->max_volume = 4; - - size = sizeof(*beeper->volume_levels) * - (beeper->max_volume + 1); - - beeper->volume_levels = devm_kzalloc(&(pdev->dev), size, - GFP_KERNEL); - if (!beeper->volume_levels) - return -ENOMEM; - - beeper->volume_levels[0] = 0; - beeper->volume_levels[1] = 8; - beeper->volume_levels[2] = 20; - beeper->volume_levels[3] = 40; - beeper->volume_levels[4] = 500; + /* determine the number of volume levels */ + length = device_property_read_u32_array(&pdev->dev, "volume-levels", NULL, 0); + if (length <= 0) { + dev_dbg(&pdev->dev, "no volume levels specified, using max volume\n"); + beeper->max_volume = 1; + } else + beeper->max_volume = length; + + /* read volume levels from DT property */ + if (beeper->max_volume > 0) { + size = sizeof(*beeper->volume_levels) * beeper->max_volume; + + beeper->volume_levels = devm_kzalloc(&(pdev->dev), size, + GFP_KERNEL); + if (!beeper->volume_levels) + return -ENOMEM; + + if (length > 0) { + error = device_property_read_u32_array(&pdev->dev, "volume-levels", + beeper->volume_levels, + beeper->max_volume); + + if (error < 0) + return error; + + error = device_property_read_u32(&pdev->dev, "default-volume-level", + &value); + + if (error < 0) { + dev_dbg(&pdev->dev, "no default volume specified, using max volume\n"); + value = beeper->max_volume - 1; + } + } else { + beeper->volume_levels[0] = 500; + value = 0; + } - beeper->volume = beeper->max_volume; + beeper->volume = value; + beeper->max_volume--; + } beeper->input = devm_input_allocate_device(dev); if (!beeper->input) {