From patchwork Tue Jan 24 16:42:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manuel Traut X-Patchwork-Id: 47776 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2259460wrn; Tue, 24 Jan 2023 08:55:24 -0800 (PST) X-Google-Smtp-Source: AMrXdXurE4quoK1bmdpvRxtzOPMu6nsyNNdzXiQyghPtfLQHqQg5g5pTirkFJnFf6S6YkP23XUO3 X-Received: by 2002:a17:907:3f20:b0:7c0:f7b0:9aed with SMTP id hq32-20020a1709073f2000b007c0f7b09aedmr39511130ejc.55.1674579324634; Tue, 24 Jan 2023 08:55:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1674579324; cv=pass; d=google.com; s=arc-20160816; b=fCuexciwQ7N+GQzH6QkYVySKn56G3R40RUUduTY/rDNXbg+iNEM1EHl8L4Svcnxl7+ wziyl6IaUCc0V3P1oCT3cDEsSnbG8ZHk2glF+o3Pk/1kG1OK8/tOuhMpTzBsPiHhrsMx Hb0oYCl0a6jUYSv7mJYKoP2OOleCmx2Yd+5kRS234v5srIwJkTd2FIiiSRbxqwe6ncxQ 8vZ2ELky5w4eAO3OrXDsLrVL4ohgBHgXCMswis6zYASmN3ag0JYP6BM9315VozxSeBjf TER6UocD/ndqpS7c/N9VUKN7XyfBAP7WtW8NgNEj9a9BAtXO55xJcvZTQCotwTqEc3Ze bouA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-disposition:message-id :subject:to:from:date:dkim-signature; bh=IdcH2axOv2c7o0Vt6zlylT4AeahmKORGfip2xDaBbyE=; b=e3Jj0hcpQAtjS1z41HApwiV3yFRlIyQ/tou9wpHpUAynRZU52LHueRTvyMR8RikOBC 1jPRF+08H5omBxyjmOJcsqvfbOzh2XT+XLvW/kvUqxkxTXV1Sp3KprGV5xoaxRTy9EBp h4ELgxghQOj+JMFnkrl/+vvoNEYEg7FFirmbo+4FMIyo6/tsVawpeQTm5+DYZthEPSv/ ooeZLr1QNr7oh3Z7WwtJ6yFLVnIhSiatj4ZZS7yTK402u+K6TplkJRRN0jN/yVdh7K00 XhT/jxSiKaKVPnnMZ5YkI73HMz3Mw7snn+JKfFS/b+p6qKCs43vQWWWaaMwkgt2nPkWK U9sw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mt.com header.s=selector2 header.b=FI1EwIRB; 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 c28-20020a1709063f1c00b0084d37a7d9casi2888977ejj.187.2023.01.24.08.55.00; Tue, 24 Jan 2023 08:55:24 -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=FI1EwIRB; 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 S234452AbjAXQn1 (ORCPT + 99 others); Tue, 24 Jan 2023 11:43:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234307AbjAXQnW (ORCPT ); Tue, 24 Jan 2023 11:43:22 -0500 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2112.outbound.protection.outlook.com [40.107.7.112]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E09E64DBF4 for ; Tue, 24 Jan 2023 08:43:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MWU18Zhe2Zo+Qj9zfTGMJWZqOOi6jR21aSx5C7mJKQTjfWSNDiKmy9weef72eK4mfJ2QmGMj9fnmc1FVBlVcoa+iNWE2hw5Hib7eo/erqYUMD1upeQqcx6cjfJbHzAt85DQLQTACGNDjXEvgZDmXUm1H+qb4W9CxCx/aTF0OD32Lkzw0NtC5en5e7W5gUC5gGwLT84NRy5GwUA9g7WgOFEmW0mRIQ62kyI31yZMqRzPpKJRCoFn0SLvE9cXnzvlkwvZJiGVSBfqQZFxCsu9QaR7PCHCdVh/08sVWEXyR9p2zKkoB/EkptjeM7PzZdp1DJQJup22d45mds9DMEGHuYw== 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=IdcH2axOv2c7o0Vt6zlylT4AeahmKORGfip2xDaBbyE=; b=fFUX3H8iYHfh1GWD7LKImQtVwDuZl1Xr9HsCsnsinbxEaXvpf5KlZyTQ9KELpvhdvDJ5obdZQyyN6W/WcvmE35I18U6S/bf3i/l2H8MAXHamldfvkvoDCgwDSFnfcFamf/+a+aaGO0pphfNDbUBYKSu7J1U+sDLDLTHUg8bZ1Sb9z4/C4wUXQMRTGsWO7hVVJZDyOqF1ViRWGUSrvdte9DrX0LZ9UHu/V5WZmaRqU6l1UsmtbpiwpEWL6OqTdrxx1/hldFWtUWNZJ5Lu2ATQtCT+exaAUW5qrDKcwa5NJ0ip8+1rxGLJ5d38L/iLFJFZ164qJDXR/s4yJjnSVVIjXg== 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=IdcH2axOv2c7o0Vt6zlylT4AeahmKORGfip2xDaBbyE=; b=FI1EwIRBbzy5Ic91Ov4L7382uTt6oCnX1snotre5okVdCP6BDhfBghTPt7v/nxujaqlNk/Yfi6ygQShEyxSvSp+IdkzWHq01hh62kBAiymCcGpQRLAaL3PRd/0w7b7zfjIRfa37RevKlCYIk4hYpwHhS8xKBDAvcKmfc6T1A99sP2r9PYp9jLhhXe908tm7xSXxIr4lY/jGjDw5mnZBUO8tfBn9LMVPyTK5rLfYNLW6OM3tKhWQKAXT4TQjz60TfqjmYwCk/BtjIwgOm7ZHhJ8qhOh8T+ZVW1JjxSuEeDrW5di89DXEqm25GfntR+MDS0pTcPiIMz4cw3wfJH3APyQ== 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 PAVPR03MB9848.eurprd03.prod.outlook.com (2603:10a6:102:31c::6) 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 16:42:57 +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 16:42:57 +0000 Date: Tue, 24 Jan 2023 17:42:56 +0100 From: Manuel Traut To: linux-kernel@vger.kernel.org Subject: [PATCH 4/5 v7] input: pwm-beeper: add devicetree bindings to set volume levels Message-ID: Content-Disposition: inline X-ClientProxiedBy: FRYP281CA0018.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::28) To AS8PR03MB7621.eurprd03.prod.outlook.com (2603:10a6:20b:345::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR03MB7621:EE_|PAVPR03MB9848:EE_ X-MS-Office365-Filtering-Correlation-Id: 17546beb-53a8-4b6d-ccb0-08dafe2a0c6f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ao8Vq4+OGKTFDnvySOM7CYys7cyP/eXOmJbfuJhhZ/k1or9ogxdMxCRUJvY+SCIRI8dohg6ykvLds/ooKqFvortkO88/RO4PgIW0lyUYLSkexY0HdX2f/3CDVnkP9R+oFtJkdPP4UsA6lP42bKjST+nci1veNvjs05XFrDvqCLVc7B/+QAD2anuZH7alv8tnXITT/7Ag6q06gCIa0FocDUE0CmvVZL6TVp1sIBaj//Nt03LiZK0eppQ+AlkhScNCRAdFwTBSU7Tz/QzCDRVEKrAeC/BgpPyAeVTC6PVQuAvH9mQ+G0/nf5YPtMbdGONV1K3hUJDmjZQz5n2HcqiMhL3Ex39bvUU3JXq2XFWxzlZiBbkplJjqiD1DXj+46Klwwb51RKsnDksBiklN5Zx0cJ3xfPzZ4ISA0FPMA256EiMyk+dVoqoazkD3Wq1f2tUgI+YH98zbpBmu2cTEMWXpe6eSvza5xW/grVHOD09h+/s2qByF/YJZbGWz6Chky+QFrtp6wde75ykMe5+0ojBcGaDCHi2d2GRuolUYGc6n7K8sA3ixuWf0YqmXyrShrWyw8+MVlHz4vTzn0ki+A+m8wSeXxomoSVIuhJSQUVIU6VSVYb8+SAi5QS3z+Hb622N76xujNTMDI2bsRw11Jt5nKs6xVRy+G4zCpmr/pg6Sp7q++jt8Mw1IvGCodhI2dQj+wht7QalubBDbsUi+ErpSYg== 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)(366004)(396003)(376002)(136003)(346002)(39860400002)(451199015)(38350700002)(38100700002)(83380400001)(41300700001)(86362001)(44832011)(2906002)(8936002)(5660300002)(316002)(6916009)(26005)(6512007)(6506007)(8676002)(186003)(66476007)(66556008)(2616005)(478600001)(52116002)(6486002)(66946007)(36756003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?/Y8r+G8kbwcRRQ+HHJZqgqz/memg?= =?utf-8?q?7ZvYzJYh/tnRUGvxnoD/8DmGS2wzD9zgfT32O15AEYHigkxQ1Fo2cw6nWNhVjtK+W?= =?utf-8?q?FnPInnilMmmV013hiDeSM2VF+mzcsFjYixqRJjQiiWqPyddWBlsC3hk8K+zq/LtY5?= =?utf-8?q?3GTOyjoXRCHTGMHCG59YpHPK8TrZ4m+O7+M1RFrjFwpouchq5io6u/3pyh7c7hxhF?= =?utf-8?q?M8XyhMc8sS6BCfrQvIBX+4lewKanu5UYFwP6BTMuJ2oUBSKEtel4tYmzuK2VqvP4Q?= =?utf-8?q?cqD4t+dHPudjntAh4E5SHPS71xXzZze0R0P8A0djin9fmqoFyoEAYXGHmXVlhygJq?= =?utf-8?q?638g0+H60hwoN0+n4ofl107FXDkZaflEqll/6+PlYvVuzwt3/KW0peQS5FLcH4n5X?= =?utf-8?q?DpqKRKGUUv9VZaZow9yO5acO+rCCEDtft/0l+uPq6B9XR8F+rRLVfGoSsW4Uuyqw/?= =?utf-8?q?wPSULcSd1yz4mPYejxX6mj6xq8xCVMXBITsMpQHMNW4mIA7V2BSBKPUlurclZM2ZG?= =?utf-8?q?gHUmvsNb2a5DPUtGHTXQ7j0WU1Tz28GP8BihXd7swaAXON7KR41jn+luovwpBm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4b2ULsvrU8XdswUUEdPQXdehGdtXQazyfGpT90U39dCEHoDLIq4GOiLsHQe4rFGdO?= =?utf-8?q?Lpj+p5PBMjMh?= X-OriginatorOrg: mt.com X-MS-Exchange-CrossTenant-Network-Message-Id: 17546beb-53a8-4b6d-ccb0-08dafe2a0c6f X-MS-Exchange-CrossTenant-AuthSource: AS8PR03MB7621.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jan 2023 16:42:57.8487 (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: 1k/5O+cT291bZS/OJqxd+7Y07/oUdAAbBh8NuLWsiIIgJEDSSTxAEkmnKZenizRgdei72BOJ/0aL3C9ldA5WZw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAVPR03MB9848 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,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?1755923689948971771?= X-GMAIL-MSGID: =?utf-8?q?1755923689948971771?= This patch adds the devicetree bindings to set the volume levels and the default volume level. Signed-off-by: Frieder Schrempf Signed-off-by: Manuel Traut Tested-by: Manuel Traut --- 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 fb7b377fee6a..fe543c4151d6 100644 --- a/drivers/input/misc/pwm-beeper.c +++ b/drivers/input/misc/pwm-beeper.c @@ -182,8 +182,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) @@ -229,23 +230,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) {