From patchwork Thu Jan 26 09:18:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manuel Traut X-Patchwork-Id: 48537 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp180407wrn; Thu, 26 Jan 2023 01:22:29 -0800 (PST) X-Google-Smtp-Source: AMrXdXu83/V+p17PMNbCzcX/PJA6jJofNAbUz3HbV9k0snlMS9zvXZYB6jVJJU2yGwUrtqrxWnF0 X-Received: by 2002:a17:907:1387:b0:7c8:9f04:ae7e with SMTP id vs7-20020a170907138700b007c89f04ae7emr40328976ejb.22.1674724949136; Thu, 26 Jan 2023 01:22:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1674724949; cv=pass; d=google.com; s=arc-20160816; b=0tQOYIbeNrvGdto9YylQGSSnlsTK1YBQJnfHIlZo/Q36kqYvo8ACd+G8qJeQn3CvEW lRwUXsQ5UtoR3ZG2eh9Ebh1Jr9tTYisLwbWt4eNVCkd245tL39rWND7DW49jH/H0METz 5mY/etp6OK//ISk/Yd0eAaD5iOqRAWGEXJR3LbS5UGrHXaErXDYpjxp5MmOhWqmJKaTV qsjTWKS2XxBVvOeKdXke2w454o5HDNKgsv/9uHEi1LqftyUoBNcrgiEWoY6/Odh5+7OQ VMXSye3Ix7xq5fms7zKhXtYPEHxSXV4UFsYlzkWlvUDkgGg+N/1x184A7KrWqQJnxwNV 2+yA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6wRsHZtWcsVDbpLif8cJQpKMKocgCvOdl+7dr9GHNuY=; b=g3tWn47ATKmjls5B42ZMReeF+3ZAMphofoc/tCgvH2jLp1c5JUyJ2myn84NJkueojm QM1IzP/KgDvuiOHz0Qx7NnXyKJdF0Uex47qbDnuAq3Mtap1t/Q13moNXRfqOjKW5mxV7 Vn76jBShsK8UJ2PdzzcBZrYxasfaL4AuP+INW8yw/eQ7heGo73cuBh2bN3OyYqf0OJ/I IxgatD03gXfAw2K+IiUgQjjEae8ivu2uIlGZrTUPPTo9n2DuBW0uOmEU2c+fPQxJfjKs 7Q938STjZi/DIQxd39v7Wez5TKqAhFCY/yBd/3ebaaml46eonQCDVWCkX1xczR0307SG zgvg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mt.com header.s=selector2 header.b=MUucOLiY; 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 6-20020a170906018600b008722dfb9f4bsi932240ejb.726.2023.01.26.01.22.05; Thu, 26 Jan 2023 01:22:29 -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=MUucOLiY; 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 S236863AbjAZJTl (ORCPT + 99 others); Thu, 26 Jan 2023 04:19:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236841AbjAZJTL (ORCPT ); Thu, 26 Jan 2023 04:19:11 -0500 Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2123.outbound.protection.outlook.com [40.107.247.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19E6216ADD; Thu, 26 Jan 2023 01:19:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dJhd3LjZ/C65cnShPqd7EX/QeI+vNEetXKKAaqFaoyRnZImbzFpsWnu1h4NyaEQY7NUWhy/K+vlnpXqv7hHmR3v1xKeg856RjkznlNNpNaNM5DA0aW/xPdKSWSYQtOukDBdn3EECG58roufcxbJbkRn47jrNt89Tx8EiTtP4SiBIdKAAZRn4g/eYvD8Hn38fl/21mlN6bP/nyVCmbXQE0mvSx8OMp8+m+mAzsbBSu3IuvWnEYG1b/hRe/8xs4bEKQ7cNDDwajKZK30OkcYhwPNBDLja0aMiJpZdAwFap4NbA+hqDVb9H9Bm84kNbfSjwhwY2zhx4uENCd7yJpPo/3Q== 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=6wRsHZtWcsVDbpLif8cJQpKMKocgCvOdl+7dr9GHNuY=; b=Lm3UM5rSCs7LRh/59wGdc+4zW5a7rELtf1Gu/osZyZR9VyjaDMl52MF+gnms1rBA5iwl7qJVGGgNKzVWfBQGFy4KNEmgy0SYPIrpY+gdNqpIp0GCt45qq8MvCCx0VwdcCqx7j50laziaRF6b9TQUFbv/ZSZY4kaS0c5MgQpB8YKuaBNXsPwFy6RBjaqAs+wUgzo9RVkI2pTvheQfnyJMxlFGmMlFZLcEKtopINX16HNo9wsD0CkEiyx3TU6GooaIvH4uYR0j78DH+NVeDKGPdZWphZEHTnUgzQug/aWC9n38hsAx2vmlewUwegc6rr5YiUojzAXfcwIaK8Kw0o+lBA== 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=6wRsHZtWcsVDbpLif8cJQpKMKocgCvOdl+7dr9GHNuY=; b=MUucOLiY21EngF2CxoZmcfO6gZ2z6P9LhY+TQlRDezKiDmfu8Mt/sLs067DbklY16PUOQTGr0Fte6dSNrEthwUoBDyIaWLb8rtXeCnkVXoU1TRMdTubpp9i9PxoOaI3lQwtxtPpOrhBqRws/vFk6ngomsTeih7xqnqO9AhP6/u2a9oTCKQ4XwHnOaPfP1YkcK0iFQnx4xejsMAxtq/twLcMlFUblLQzIua39Ri2VMiu7XEPaVwZsx3GvbtKHPv6Ri4woNKSGAmtCjALV9VP/KSbVezl9hiFsqKCgNwwmAM8jTFA8JkfbePa9QqWdQPa0YGqBK95tH5f+e+wpWAY/cA== 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 AS2PR03MB9516.eurprd03.prod.outlook.com (2603:10a6:20b:598::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.22; Thu, 26 Jan 2023 09:18:51 +0000 Received: from AS8PR03MB7621.eurprd03.prod.outlook.com ([fe80::b42f:82f8:24cb:a225]) by AS8PR03MB7621.eurprd03.prod.outlook.com ([fe80::b42f:82f8:24cb:a225%9]) with mapi id 15.20.6043.022; Thu, 26 Jan 2023 09:18:51 +0000 From: Manuel Traut To: linux-kernel@vger.kernel.org Cc: Frieder Schrempf , Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , Manuel Traut , linux-input@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v8 3/5] input: pwm-beeper: set volume levels by devicetree Date: Thu, 26 Jan 2023 10:18:23 +0100 Message-Id: <20230126091825.220646-4-manuel.traut@mt.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230126091825.220646-1-manuel.traut@mt.com> References: <20230126091825.220646-1-manuel.traut@mt.com> X-ClientProxiedBy: FR2P281CA0131.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:9e::14) To AS8PR03MB7621.eurprd03.prod.outlook.com (2603:10a6:20b:345::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR03MB7621:EE_|AS2PR03MB9516:EE_ X-MS-Office365-Filtering-Correlation-Id: aae706f1-5643-4ffe-80c6-08daff7e567d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tJ1GSxyrmysgbdFWirjRg9TA7d5rI1c+GpiZqxz2IHplYbjIACgHdALu6fD01Sm5fWuCA81aYw65B1m+lsmoSZ8mhRD1t8cPy4cqFfF19V83e3SbaJvV4aIepbhLMA9fU6LnXzaVZqg+BaiDq7GoQlHFnWPPkP9CBHhIbkFALlDl4+5n6kPTtPO7QHd+ZPcsUGudKCOB0rjZnPFjha0VKIxsKg40lqytZbsQpfy4K8CzsP9AXDhdvCq7oKUUgcRaoxI8/Na3IQligxV1Y/a5BUAcbqiY/TP3AQ2ejFPh7vQ5YJh5dQY25nMxNWkuuemlnpNN+9cr0EAfxoUkzKH6EF0kDOn8sjA/rxseCIM/uxyjn7Q04BehZ94UxhuuRL+9+DFE2QEEAt4aCJnc7fr97vxlgJr5rkG9vfjX3bF03PIcqRe8MqgyEndN8Gz3mDZtadWAl7pcn8Xy2djhCnoBiDfdWhJHgn7UKGvGPRynjJIihPdBS4r0nXneZDHfgyxhVBhiXxSAiUm6Xu2LoxOKpGAiAd1grZC+opXhJIYQveL6OXNyqOIzAsAMYqCU8SThZAjcZiNOQX3ykMf+VA8EwiOGtZ1951e4kV/79aEN6W5a1vdxDP/XY15HL/C0O52UOc9CkwK1WifWBOMix/tzAj5c4Q8hKw6zdWbG4TImDoQYM6JHhihglFdVzbWW0qbc6btcvfDWO+QXxLTa/19a6Q== 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:(13230025)(39860400002)(346002)(366004)(396003)(136003)(376002)(451199018)(44832011)(2906002)(38350700002)(38100700002)(2616005)(1076003)(6666004)(6506007)(6512007)(186003)(26005)(86362001)(83380400001)(66556008)(66476007)(6916009)(66946007)(8676002)(4326008)(5660300002)(36756003)(41300700001)(8936002)(52116002)(6486002)(478600001)(316002)(54906003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: kqAWAsm84KDP9ChgQ+MY8jiaGqoNALLl4jO3hjPKCkeU+UcbiP0p11rb4Jixw5kzHcYiJ34PGu3+e4MjdNvawxPOeohrhlW72Miz5h1zmemY26bVwCERgvMz4LZ20SYmmuji0hkTF0TUBy0w1DFX2cxZuYLFE1IRdGzCsJCNfESO/Wwt+AkoupzMiH611/YdRwwirTS20b88CDWRLCYnMsw7DfsXgn6i7phOkRHUQUBpoaTEPUZ9znyYWYVciPtPZGpx5aX6vOj3NPCOKcWhTrzS4SyoLEPhPTfCi8049MXKXZvjzrMbfev21S5FPGqmbBc6TlkThNEQR+SGyOCWl6EV33Gq0pXA415PY6mFqtGH52CnqWyCNG+3L0m747ixyLtc4gK0AqhzE+x86FWRotdL9L9lwFfAT6WuJjg3g9MdqmBqnGJdXnLsHbzEAZJ4kwwP9KSvULIjo+N2mFVLiH9ELWaBTEox2BVXJiS4hmtiBjpb0CpBQPGAkRHk+Al9V9/Gr5NaOodSW+nk//5NP2r6L6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com X-MS-Exchange-CrossTenant-Network-Message-Id: aae706f1-5643-4ffe-80c6-08daff7e567d X-MS-Exchange-CrossTenant-AuthSource: AS8PR03MB7621.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2023 09:18:50.9467 (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: ZoQwFjQiLuAT4tU8/XHidCVGj50qnkZZp1T8slS4F7vABxnkH4X0ASMDFfGhQLKqTU2Y+FHe/sfZq04B7I1RiQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR03MB9516 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?1756076388502242396?= X-GMAIL-MSGID: =?utf-8?q?1756076388502242396?= From: Frieder Schrempf Add devicetree bindings to define supported 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 865e1ec5c39d..82b05f7f4c70 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) {