From patchwork Mon Jan 30 13:56:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manuel Traut X-Patchwork-Id: 50293 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2190869wrn; Mon, 30 Jan 2023 05:58:20 -0800 (PST) X-Google-Smtp-Source: AMrXdXtoLK9jlGqbWVZyfTEkUWZIrXd/gAkEFhWUDcjHcImdJSObQOXXp4sK98Ls/6OjdpUerENc X-Received: by 2002:a05:6a20:2d0b:b0:b8:2aab:2309 with SMTP id g11-20020a056a202d0b00b000b82aab2309mr57252312pzl.49.1675087099937; Mon, 30 Jan 2023 05:58:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1675087099; cv=pass; d=google.com; s=arc-20160816; b=SPwxGw6anWlVeheqSfzfrHk1/3F5lfagksVpdOW4tSkwWuwtdcq6/MJaPPI+s4k81+ +Kp1KEiA2Folzh+YpreBVUGdz2wuVhkM9aoswsyxj010tiovgfq2JcBxN9jBOt3jsB3o qe4KCEMyVXs2Z9kuPQWu5LNiYhH3PDKx+uS3QAlPdF4IYzC9kecwTd4Os/rNspxDf0eg RI3y36cm0QIm0EqBzvTE5c37bq47Lc65Tay7jQFzcuVHD30WFzIl6kUHM4fg+A6ruS0C GQ9/s91gmK8SPtpbthxcaes+Vg5TtaZ8bH0xWLAuUwSk7uUk8EgZ826AnFzbeVOSi3ER zmPA== 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=lU5lR4KqLbCbHm/PIjKvuM2WQNlI/qNO/U6FvcYVC0M=; b=xEX7QmnOHTxrrcO3ZS87+yOS8Z++vibwAHBHKyStKhywwhgoDRShp7N3nUAbs6PTXf sr9zUKcpL1JPrdHEPz8mXugrHGsCap5onnS6J4Ahs5qcIfZjGFFPBBBH/nA3bH4YLT0v p0jflKVqTYX+CpleM525oD2IFSd4e/nuqPd7XvQrT8g4NxwpH8mljS6Gg9PyuSWcYWDt VIWD16x8B9KwP0W9m8VVXdH4fFajwi9M15iM/eyYUT98UBz5NBbAmhm8jtNF9rEVSJLk Yjox8yEzHqALM+3gRtlOrT96gHFsPPFuP4GZ3/KVk1EWGme497HTW46OzvYtKz1KmUuJ aEfA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mt.com header.s=selector2 header.b=UDuIqgEK; 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 p13-20020a637f4d000000b0047947d45f57si11768289pgn.745.2023.01.30.05.58.07; Mon, 30 Jan 2023 05:58:19 -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=UDuIqgEK; 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 S236728AbjA3N5d (ORCPT + 99 others); Mon, 30 Jan 2023 08:57:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236705AbjA3N5N (ORCPT ); Mon, 30 Jan 2023 08:57:13 -0500 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2099.outbound.protection.outlook.com [40.107.20.99]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4C9F39CE1; Mon, 30 Jan 2023 05:57:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YyzjX8CcjZSlNXtW855dIZ3HusFVCiPMup2jtVavaNo8ulmF+scHgYzQlR6ltEUlEmoiSn8dFXl7RG/7C9SZ+ER0uGMaD01gX7m4quFnAisuEB+Ep+Nw3U8a3Er41M6DWUo0EqsuF0GnXqf47ShCKHGaGOmsHNe8VSbFPQSfoCpLvUqDoIQCU6g/w11V2ST0Eu/O6CLujO2gc7vx52Mq3Lg81jNTi1ztLsUDJpBISiyYg9wBG5VvK3dpt6D3ge/Aa3Mfe53006aejUkA1AMkp4+94MO4x2qX7X0Jq0jrqAHMjQtmxEqRtA07kTkZKlrsUOBeBBLsAM9Uz6gE+4Tl7w== 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=lU5lR4KqLbCbHm/PIjKvuM2WQNlI/qNO/U6FvcYVC0M=; b=mUtMtC2fRKgbVahcGJt1+m9OLDOj3alpMKPIddtFudNtO6gPLoQrP22dTaFL+8DB98ujJvxlqutYJLGOMWblnH8WerYKv1KCP6tXChoY5zUjozzBjzyn7a+6fH29TK43t0AIWKzlhPSgWL1MdF/QYDl90Cdm9CY2bt64VZFw1iMZX66CDZPEhEG15uHxZZCcF+lNJqFzc8txlLFmj8eSrPaXh64WeU/yoiLhlXWhBbJgMykQsFR7zwPg7jlamSdYuR0kgiDl+3LE1WxG8TaxJBTNiDB55K7HE5+Jfjp6Z0rNrNoydWNvrXk97AG3dkCCaYbzVl6PfX/j/vt9UwcKJw== 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=lU5lR4KqLbCbHm/PIjKvuM2WQNlI/qNO/U6FvcYVC0M=; b=UDuIqgEKUjWEm0/oGRlJt1nJE3E85XekYxPrFikSZu44tm75Jak+KyINSrAfX2FX1EBx+H6EM2mAFFG08/iDRiEOhIoFWtUrXkP+7wmmrYA/NGGXFDD1YvOY5UbMXi25DWo0Tj58sCzoGqSGETCXGw/ZA3znM8q4pP0WCK5mXvOSVRjeIdbzNLkBaYyT3y71NNCHY7h/83GZWtpoPB0RUXeLIyIKrNCJT4sQwSPsVwndvyeo3+SIv+j8VgOduCcB9j673Dn/5uIf2UH7WsF6qQZg+ZXvvza6k2ZGTr9Lmssjl8mgEuh0RbQi7H2eFmHQdOcngSQUG9d+a0cNPVfjNw== 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 PAWPR03MB9081.eurprd03.prod.outlook.com (2603:10a6:102:33d::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.33; Mon, 30 Jan 2023 13:57:10 +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.036; Mon, 30 Jan 2023 13:57:10 +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 v9 4/4] input: pwm-beeper: set volume levels by devicetree Date: Mon, 30 Jan 2023 14:56:50 +0100 Message-Id: <20230130135650.1407156-5-manuel.traut@mt.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230130135650.1407156-1-manuel.traut@mt.com> References: <20230130135650.1407156-1-manuel.traut@mt.com> X-ClientProxiedBy: FR2P281CA0172.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:9f::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_|PAWPR03MB9081:EE_ X-MS-Office365-Filtering-Correlation-Id: 0d76efc7-29ea-4c40-8a26-08db02c9e214 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xO3l4LYCXUHKJO53H74OedGb9tUXbYQtumd2D/Ra1LQECYMA3xDwA+CPb0vKX9ZYdQV23sy/VWjhg76KM5fJ2se90Ctyb6ewZscET8TkLAgtkk9tc2qqwIXPubh1VOcNg4/KlOIBNI3R6tWb2LBYvff7HAZ5vLRrILgpgPyn96DOak8aGmsce0tyU9mxCDICyitxD1UOZusyQlPI2vbxR6g444UIr1J6wbhAjdcdbdmLQ18mmDfrdtd//xwtNzvQSWjofby7w7hFrALOzVpDBTAlaBYtPuy46JafoP7DQVcS5cylBnbznVQ1EeMHHJwp14MSkzcHoTnQsAHZ7JGFL04ydeGizClPU1JkzhVTMcjPtC4CEVtXlF2VOHvTEYXge5X/Jbp3ROp7q7HCWcTfprFEVyUpch0bIjqsBFEYUfZVu2yrB/xp7PnhatVGeo/DGBx+mR8Z8TtZzxRdcLQKcY+ppg+22Ww81DhfoOGViYU3TpIqxhMFIMwk852fumakSV8oKbQ6M2EWtUz1L2CaABLXQkrtVOLMQCFNayT77f4fZh9NDtgx4ifkeWYbaGoUqxecXamfBa8I0VAGnmdMfvXlCn+YPMXjwGt0J1BlNVE/l/wODYBBZWIQvprpFZkEjh3/bVr3dm1EYcPcwMHqV0MonOFr8rwwyVECBrxuzUEnjVO4ZAojI5HkepZomzXragVGZX0W72kjOqdqeLy6hQ== 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)(346002)(136003)(396003)(366004)(376002)(39860400002)(451199018)(5660300002)(36756003)(86362001)(44832011)(38100700002)(38350700002)(2906002)(2616005)(52116002)(6486002)(6512007)(186003)(478600001)(1076003)(26005)(6506007)(83380400001)(54906003)(4326008)(66556008)(66476007)(8676002)(66946007)(6666004)(6916009)(316002)(41300700001)(8936002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: JKy4XGf4wrGYPl/+8lACYhOCl+N2wwYm3kOFzUyCY1v/ehcAoOcnekTD2BWFMzn4hZV79VcNuJTR+kr3n+wgeyXd7DlRYe+ZbPZaOU79EtBR3AkPr++x3a90XdoE1GheY5CAEpnK8PKJIp2xXY7BItNxWDPgsI+KKG9VElyvdn5zkDmFYByaa25aMT/sm9MjSj5HCekBT+0JtBLu4gK31y0l7Cvirn/2uxY22R4XvGH1j0aGwMhksHw7A+UfXe4pc5QEJmCzLPG6nMXqk3os5gTMvSAW1X+pm7IC9OF5S0yQheKLgLNQkfeC/ZuDh4lA8iHRro3OsZMCL3Oj0P9fcQnWEsLmrGYYMMa97dq1ptLMyulr1nz1j+OmqKVdltcx8EXaY4PZuP1HH0CTZWK86gZ2TFkrbfv7LoRgkj/S8mDO0d6Jj/k+V1EpoXFwmN2DfyzfRNB++6P+cym+Ie8i6rMbD1Gm6r61Oyo5/cyexte8uZj8yUTd2pIsT3fQQHv0TEZMm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sTTqhY X-OriginatorOrg: mt.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0d76efc7-29ea-4c40-8a26-08db02c9e214 X-MS-Exchange-CrossTenant-AuthSource: AS8PR03MB7621.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jan 2023 13:57:10.8829 (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: znQfLRlCC/40zxP+sarJlUa2wcVpTS5QhQCMQbbXWDXGqHTlCDy+3UZekTxPxY9Q53/PoUWZx35GHyXtEAQIVQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR03MB9081 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?1756456131237223885?= X-GMAIL-MSGID: =?utf-8?q?1756456131237223885?= 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 | 73 +++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 18 deletions(-) diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c index 214d3fa0a06d..fc367a249490 100644 --- a/drivers/input/misc/pwm-beeper.c +++ b/drivers/input/misc/pwm-beeper.c @@ -93,7 +93,7 @@ static int pwm_beeper_on(struct pwm_beeper *beeper, unsigned long period) state.enabled = true; state.period = period; - pwm_set_relative_duty_cycle(&state, beeper->volume_levels[beeper->volume], 1000); + pwm_set_relative_duty_cycle(&state, beeper->volume_levels[beeper->volume], 10000); error = pwm_apply_state(beeper->pwm, &state); if (error) @@ -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, i, length; size_t size; + u32 value; beeper = devm_kzalloc(dev, sizeof(*beeper), GFP_KERNEL); if (!beeper) @@ -228,23 +229,59 @@ 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] = 80; - beeper->volume_levels[2] = 200; - beeper->volume_levels[3] = 400; - beeper->volume_levels[4] = 5000; + /* determine the number of volume levels */ + length = device_property_read_u32_array(&pdev->dev, "volume-levels-bp", 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-bp", + beeper->volume_levels, + beeper->max_volume); + + if (error < 0) + return error; + + error = device_property_read_u32(&pdev->dev, "default-volume-level-bp", + &value); + + if (error < 0) { + dev_dbg(&pdev->dev, "no default volume specified, using max volume\n"); + value = beeper->max_volume - 1; + } else { + for (i = 0; i < length; i++) { + if (beeper->volume_levels[i] == value) { + value = i; + break; + } + } + if (value != i) { + dev_dbg(&pdev->dev, + "default-volume-level-bp %d invalid, using %d\n", + value, beeper->max_volume - 1); + value = beeper->max_volume - 1; + } + } + } else { + beeper->volume_levels[0] = 5000; + value = 0; + } - beeper->volume = beeper->max_volume; + beeper->volume = value; + beeper->max_volume--; + } beeper->input = devm_input_allocate_device(dev); if (!beeper->input) {