From patchwork Tue Jan 24 11:12:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manuel Traut X-Patchwork-Id: 47664 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2090133wrn; Tue, 24 Jan 2023 03:17:17 -0800 (PST) X-Google-Smtp-Source: AMrXdXsspZo0Z2IOsEoY0g4ubQlmoaJZdYvOvHUkAURbWksK9ggIGLfCdPHuxW/vlW2mmLFOo15v X-Received: by 2002:a17:906:7f05:b0:86c:e53a:d20b with SMTP id d5-20020a1709067f0500b0086ce53ad20bmr26009576ejr.21.1674559037180; Tue, 24 Jan 2023 03:17:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1674559037; cv=pass; d=google.com; s=arc-20160816; b=u1B/FFu1U4Ob9oBi41X/dbv7/BZMXkyPeepWeg6IxxIJ5hiYV0ab1NKK0QSsvcoS1W QSlKfrXVDX9F8xg9Kn9LOe26NoYG6RZZNS//XwyNHow0Slx3KjzQ1LDuS722rdiPWM78 AAJY0GDo20c7s92YXEYkG0tAh3ZyIxvN5H9RtStAUu3CEMfDhahqTERaBNT0HlBBJEQP xRjDRCl1J9+fUjpM/omLneGlJ6SJO1lVObr8cHmZ8CE8Y2eu2GWH1az4j3YgBXqlu6JW Tx3miKtKdjDpXrM9zNYH9d5dIscGEHaflKKJYgfGPRPMtNdfeYsM+Lw/G41Gd4WFeFBt 26TA== 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=3PaccwS4l3/4bLgvse1Lno5JdofhRgcC2KeXYT9suzc=; b=rLcWCNESy1mjQldILZEyVhaS9pW2Te/QhKzl099WNJlP6OsEHSNMiFiwwOxf8kzgQ3 uXjhxPDbt8J2iIoqvvglv89gXre3XHeqHhDqdCfyI3KSWOHjEBzBy8iPZ0WMZi219HfT BLgGW0bTL76wnmrVMx+8UQJ586TG9cCrYRxDVUJNvjcsp3fdtWzP/gZXi8aNNKGM6By4 7CVltmpsTO7LrGoAB1ZXQ1WdM4/LfB9e49yNl1ULoyzpeMippLpTOSKH2Xqdgj7AujzG dHimW4KFLcp6ACjdhvkzkKHT5C1iH9D0vRtLydpKvGK6bPdtyTuz2rCM15YJnUZd3M1E Uzsw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mt.com header.s=selector2 header.b=Pzqj8iry; 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 jr17-20020a170906515100b0081a9c3ca4c3si2585728ejc.374.2023.01.24.03.16.53; Tue, 24 Jan 2023 03:17:17 -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=Pzqj8iry; 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 S233800AbjAXLNB (ORCPT + 99 others); Tue, 24 Jan 2023 06:13:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233812AbjAXLM5 (ORCPT ); Tue, 24 Jan 2023 06:12:57 -0500 Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on2122.outbound.protection.outlook.com [40.107.14.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C51F512F0C; Tue, 24 Jan 2023 03:12:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=haRov4IJm5Xlkmk1hTzh/6M2bVIURjZi+zLwNvNrzZvNCWefm6VVePR6yfZAFspWYyuqKGurkYln/nyL26+5wAsMK7YXJ79GKIIz796f/2UcmY1L8Dl2fwgHNPWQUUeru8a5dnmYwvCIuXE/rHizP9klqGL3LSYkYTc/agi3LmiWk1dbeg6jGWzF7sLvwRFmQNExpcujKtB8PpP9T0XjwTmpNdHhg8xP6Rz13kuz2DbRLXUXo+xeDoXaxMYFHHd370Rn3z8MCN0lnKSH1cQ7z013tUN0EC/ecnxI2/km+tV+F4eDnAy+eU0ERe/ZRi3KQ3MhX+FB9m6r4j07VUkdyg== 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=3PaccwS4l3/4bLgvse1Lno5JdofhRgcC2KeXYT9suzc=; b=ck5yN6K6L8t2r5CTGxGMx/pMJtbv5WuvWc3oGzNYBeJtJAvu4K0U+bAznUCkkiPQvslDPpOnZ61R4+GzacTS0fSYstPf/gvl0DRw+8mxjmW4t15q4Dy6w7vzNQ8x5oBu6WgjZEJsANhcjyKzg1pcmni59/bs0p/zN9C0NC6/nNSVeaFMVGLcIOHkza+5/aS5fMCOWhxOFhYzI4LEKBLOqMDBNwfuDqpzH2YPPd4IFnK9gNXVFlAYRkw64ZgjvBE8zFQ1T8E2LKH9QjULq2ximw/ZawLAg31u9m32luR5E4CK877d7Ud42uzmHkMZNZSK6wQFLWVA8LgUGJjUl+2DDw== 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=3PaccwS4l3/4bLgvse1Lno5JdofhRgcC2KeXYT9suzc=; b=Pzqj8iryzKPBRyaTr8fAsV6jSr0UfGvZsVHfiCWRbgNCGK9uaBSvbd7i5RQnJvwiiDgB8Csa8n9Bbh6mYGzXNcoR7l/ELlDBXlneu6iuoc7ty3iETdeD0RYZnPzW1mfnW9ywpjKPd1zsQ5WsbuZeyHaT2iGKkNZ3+7ro3ZqorkUWTGJ6AuM2Z+L6uxgdKCgu0DprD4Cjs+38na+ajNrP5L+BwS5ZWJ7YNZWC/W10Op0e3/PLOcTjFeCTX2hlhAWWfxGAQ365lmXRlYiqEDbax6i+HQez43jLZnCVl0D8B1wdapF9kcv0DWWlMQiKdLX/ShCislX4ZKPZvNyf9c7cOw== 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 AM9PR03MB7995.eurprd03.prod.outlook.com (2603:10a6:20b:43e::5) 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:12:49 +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:12:49 +0000 Date: Tue, 24 Jan 2023 12:12:47 +0100 From: Manuel Traut To: linux-kernel@vger.kernel.org Cc: Dmitry Torokhov , Frieder Schrempf , linux-input@vger.kernel.org Subject: [PATCH 1/3 v6] input: pwm-beeper: add feature to set volume level Message-ID: References: Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: FR2P281CA0136.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:9e::18) To AS8PR03MB7621.eurprd03.prod.outlook.com (2603:10a6:20b:345::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR03MB7621:EE_|AM9PR03MB7995:EE_ X-MS-Office365-Filtering-Correlation-Id: efd74538-dce9-4479-f93e-08dafdfbeddf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ki+/FBkXpFzBQRdenp+1R7lPWALTrfLtIQPbldMEqMCcU4/RaAQWUheuR+rouZ8lzYhN1TAJpYxgcTgRhI4faPwkrbqOo/n6xie+ki3C2BTDexpXh75jeR3fEJSPRV1WHZohaQC3+AkPL5mz4VZN/+Rl93FYtY4p9MELcJ6f3FcS3XnDdQRqR15/Tb2ZA+GeZo6j6+kJxsF/PWhzg9Vnd1ct1bAscqjP76bomfdY7czNG6HSYpWn/GswbHeGvcvpcjeoeNeT6zsiKM8RXcHyzludqKqF5BNI2Ano71FRbX2kwgNqskHkPDDP/hKkZDerTmAIBg+hBDxv3yQA6PytW6ZmTd71h2WFSscFhUnhDvMGIJzhE9uFIVjgSkwdhjfbTzSNyuNY5GMGPCpbamUeMgmI2JceIS7/hlTJw63AFiGD1v+FJjPKWL7SNLkBkQLlejmksRx7PXH+3YNFVkU4BCwgbLRJIkCPzP2/o4ETFK4LKZhVPwkKz+cJahUXK4T+rsH9QJKvcoHQ8MQ/npUlFmSimV4MCPMGbl13/n4Z9Zxk5ar3KfM6rFtI5IvOrlIHj6IBHEBoloX0M4mNgR6jqVl6Ji/DgHX0Eek618UDWl+IKo4MFXtm3qLhJqoYcU50+IZL+XGL2JG6iDMU2zuQCW9JU1OLsSzxpdpdmgibAlnbyIab/cjlvMniOawXOF6p+MVU/Z4wgq5GWWYs3TSYDOAZ61GKYJPPPkD65R+ch7A= 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)(376002)(136003)(346002)(396003)(366004)(39860400002)(451199015)(36756003)(41300700001)(86362001)(8936002)(5660300002)(4326008)(44832011)(2906002)(38100700002)(38350700002)(83380400001)(52116002)(478600001)(6486002)(66946007)(6916009)(6512007)(26005)(6506007)(186003)(8676002)(316002)(54906003)(2616005)(66476007)(66556008)(67856001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?Yu/hcwQVxYOhqzLuwZrh1tEX9XhD?= =?utf-8?q?COqA6GcdzdPAaZnolOvf2RJDv2msSIsWs15nd298EBSONkI/wOsAmGULl4bicRv6Z?= =?utf-8?q?E7Ux9LbdVoebjLZUQ2C+zwJ1lJwvg3c4EZlwFoBxvSldgazv4BJfbrlDfjSiheVto?= =?utf-8?q?fMZHnaurVFr979TJ/bBAfcRylZalT1wtxF9JLlJ+pG16AyyOT65RQ+RjaydJzIa+g?= =?utf-8?q?XPtqCaOd/dhz1vLR01isal7DulCEdvll1pcArQhXqoNMzNPh9h5m1pUJMz0vsa1oV?= =?utf-8?q?jRrnubjN8eYmAFIUR61Mq1t9GADe0ohrGwYLI12gnRClmQO/rKzK7evK14ZGZzxsU?= =?utf-8?q?d82aOOwEQHDzgUlOJoaCfB5uh9y4tHgSOIS/GDt49oKufKW5Yc2BuVxoLFkwEAiE7?= =?utf-8?q?520LMMEiptD3msLu3aFu1UHM0aHd22kpL0LGnN49BabjvLca5tLZ1IsuEfPH0Outt?= =?utf-8?q?fQM0ZTg/gcJmqsQeNnRx+OyStEmWXFarAaHOCDp48scaov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FGRW8ByRBy+UqB9KAH5lS?= =?utf-8?q?r2RqciEkiFsY74Bub4eAvkRDah1iv/45ykhyURlFmWN//vIU43kn+m95CQ6ZjKzUW?= =?utf-8?q?4Q1C5IHBVMCzkkbV2HbazK/ULMhosxr1UQ9as3eL/HEz75TUen59mYzMgh0YI6j+I?= =?utf-8?q?2tg0gyBS2dI1?= X-OriginatorOrg: mt.com X-MS-Exchange-CrossTenant-Network-Message-Id: efd74538-dce9-4479-f93e-08dafdfbeddf 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:12:49.6780 (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: 8imOwNft2zyERwAoinCml2RtgIFOnzLeLNVZjRFF1e4JsouqHgUS9gCNqiL34QhzrXEUnZhloaiMloUSNXdsZw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR03MB7995 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?1755902235795346530?= X-GMAIL-MSGID: =?utf-8?q?1755902416982064024?= Make the driver accept switching volume levels via sysfs. This can be helpful if the beep/bell sound intensity needs to be adapted to the environment of the device. The volume adjustment is done by changing the duty cycle of the pwm signal. This patch adds the sysfs interface with 5 default volume levels (0 - mute, 4 - max. volume). Signed-off-by: Frieder Schrempf --- .../ABI/testing/sysfs-devices-pwm-beeper | 17 ++++ drivers/input/misc/pwm-beeper.c | 83 ++++++++++++++++++- 2 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-devices-pwm-beeper diff --git a/Documentation/ABI/testing/sysfs-devices-pwm-beeper b/Documentation/ABI/testing/sysfs-devices-pwm-beeper new file mode 100644 index 000000000000..d068c5814f48 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-devices-pwm-beeper @@ -0,0 +1,17 @@ +What: /sys/devices/.../pwm-beeper/volume +Date: February 2017 +KernelVersion: +Contact: Frieder Schrempf +Description: + Control the volume of this pwm-beeper. Values + are between 0 and max_volume. This file will also + show the current volume level stored in the driver. + +What: /sys/devices/.../pwm-beeper/max_volume +Date: February 2017 +KernelVersion: +Contact: Frieder Schrempf +Description: + This file shows the maximum volume level that can be + assigned to volume. + diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c index d6b12477748a..fadc73e1c89a 100644 --- a/drivers/input/misc/pwm-beeper.c +++ b/drivers/input/misc/pwm-beeper.c @@ -1,6 +1,10 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (C) 2010, Lars-Peter Clausen + * + * Copyright (C) 2016, Frieder Schrempf + * (volume support) + * * PWM beeper driver */ @@ -24,10 +28,61 @@ struct pwm_beeper { unsigned int bell_frequency; bool suspended; bool amplifier_on; + unsigned int volume; + unsigned int *volume_levels; + unsigned int max_volume; }; #define HZ_TO_NANOSECONDS(x) (1000000000UL/(x)) +static ssize_t volume_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct pwm_beeper *beeper = dev_get_drvdata(dev); + + return sprintf(buf, "%d\n", beeper->volume); +} + +static ssize_t max_volume_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct pwm_beeper *beeper = dev_get_drvdata(dev); + + return sprintf(buf, "%d\n", beeper->max_volume); +} + +static ssize_t volume_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + int rc; + struct pwm_beeper *beeper = dev_get_drvdata(dev); + unsigned int volume; + + rc = kstrtouint(buf, 0, &volume); + if (rc) + return rc; + + if (volume > beeper->max_volume) + return -EINVAL; + pr_debug("set volume to %u\n", volume); + beeper->volume = volume; + + return count; +} + +static DEVICE_ATTR_RW(volume, 0644, volume_show, volume_store); +static DEVICE_ATTR(max_volume, 0644, max_volume_show, NULL); + +static struct attribute *pwm_beeper_attributes[] = { + &dev_attr_volume.attr, + &dev_attr_max_volume.attr, + NULL, +}; + +static struct attribute_group pwm_beeper_attribute_group = { + .attrs = pwm_beeper_attributes, +}; + static int pwm_beeper_on(struct pwm_beeper *beeper, unsigned long period) { struct pwm_state state; @@ -37,7 +92,8 @@ static int pwm_beeper_on(struct pwm_beeper *beeper, unsigned long period) state.enabled = true; state.period = period; - pwm_set_relative_duty_cycle(&state, 50, 100); + + pwm_set_relative_duty_cycle(&state, beeper->volume_levels[beeper->volume], 1000); error = pwm_apply_state(beeper->pwm, &state); if (error) @@ -126,6 +182,7 @@ static int pwm_beeper_probe(struct platform_device *pdev) struct pwm_state state; u32 bell_frequency; int error; + size_t size; beeper = devm_kzalloc(dev, sizeof(*beeper), GFP_KERNEL); if (!beeper) @@ -171,6 +228,24 @@ 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; + + beeper->volume = beeper->max_volume; + beeper->input = devm_input_allocate_device(dev); if (!beeper->input) { dev_err(dev, "Failed to allocate input device\n"); @@ -192,6 +267,12 @@ static int pwm_beeper_probe(struct platform_device *pdev) input_set_drvdata(beeper->input, beeper); + error = sysfs_create_group(&pdev->dev.kobj, &pwm_beeper_attribute_group); + if (error) { + dev_err(&pdev->dev, "Failed to create sysfs group: %d\n", error); + return error; + } + error = input_register_device(beeper->input); if (error) { dev_err(dev, "Failed to register input device: %d\n", error); From patchwork Tue Jan 24 11:13:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manuel Traut X-Patchwork-Id: 47666 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2092989wrn; Tue, 24 Jan 2023 03:24:38 -0800 (PST) X-Google-Smtp-Source: AMrXdXuBpc1n5xGnIoZh6Z3pujNfrdnpmnRAuX5arrj6JD83OibeTY2RWtGD3XF6lCv6X12xcaKO X-Received: by 2002:a05:6402:28c6:b0:49b:98be:c38 with SMTP id ef6-20020a05640228c600b0049b98be0c38mr30856082edb.11.1674559478538; Tue, 24 Jan 2023 03:24:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1674559478; cv=pass; d=google.com; s=arc-20160816; b=WRElqCrUxnJZgS6y9y3ilaFxyfDWVnmoqT4pStnkCtG+SGTvYccT+C5YF2vbVSOjU8 pDF6VQbaxZV25o1WNhmHC/lLrTCxzw4ChWB9gotsbuguKMlhkogETLc4HOBSPc/J3qZl jCGgI+qnrq3e6U2+Tomx11YIis+XTpq99wi31J4mFnyRt4AwTmjAffjlb9ppr8CJMeY8 8asJz67ltC1UgzrnWTjoWbn93QfYRSn8YXl5bm6KUs/1KC1HLZwYkzWIAkLm21AQhpW+ h1kXBI9QrJIY+DKl1b6ZkSuPhrsw5HOdfmoa7mvpZidPHwv/ggr1UnnCCNIhdzKLIY3A Di5A== 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=WnodbyZMopN7JaAyoJy+8eyLEBzx5ZhK8voZ+UTUvUc=; b=xEWpzxRTY6atEnCzEAUjQ1f7yNscWOCDQn0v+5mqVGLhNT/XGEWfO2vR2/5OYG811p uFuZePfL8lnrHIQczv+XWxFkQ2K4ZYP+h7Q+qFgBKwrTP3Y3w5CURnQS+dJH3rGM0ik/ Dgvctpffekt5uSyXoPz5vCt+qy+2VdNjM/75zyrdISlTwntPkR/q8oAkgW38hOWKypPu C0k53eWmmcRDRylyHbax8fLoEIgRaHGn9bZdTVkVqnxIksG2p0A48VAStz/fNN4KHH9N 2svs0xfVGLzYl06DcZX1gkBPHpQHO6dQZoF2V+vwyuwCKQ5gaC21+eblKZJ6s/VUfGGT Y8Zg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mt.com header.s=selector2 header.b=CxaLKHjk; 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 u2-20020aa7d982000000b0049cbe322904si2584602eds.408.2023.01.24.03.24.09; Tue, 24 Jan 2023 03:24:38 -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=CxaLKHjk; 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 S233806AbjAXLNi (ORCPT + 99 others); Tue, 24 Jan 2023 06:13:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233279AbjAXLNf (ORCPT ); Tue, 24 Jan 2023 06:13:35 -0500 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2123.outbound.protection.outlook.com [40.107.104.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A91BFEC63; Tue, 24 Jan 2023 03:13:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RVhvvgMxMWq8r6se6EOEMvym5azmhiDkJJkB689h2USgqTP1eOa8RVFl12az+I53VOUIg/YXoocE5F2H7M+C5lFF5Hk79aD6ipydwcb58c901HtIFUPCZqfGGZm1T+W02wFeUJIeGX9U7mQpAmDwUD1zxccte0yCQKrREZLj08uVEZuIjSCiPC919KNxteBlsnLWCxac0e0uCaMN0ByJULvX4X7xb6kXZvo9fCW9qprzh65tWi+pejHBUC2baFy+3eQCTW7HzcAU+C4uJzXqjns7ay7cvGI3ZF6MK6vE5em0ujkMZi3ehpe/8Yz99DbZdpj5a++UarsMk1dhjjs6+w== 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=WnodbyZMopN7JaAyoJy+8eyLEBzx5ZhK8voZ+UTUvUc=; b=UkD6qPtlPdzsB9cQwgWpId/tjTYcfQC08jdjI9DWHyT8P29nXVp5tl2EUHHUiOOczWgMt1twbqq3nDrxgjRGbrPNna1IXFsUlrThChSLh8zUpWOspRVgUhV57eqP96ITgCFkSs9pfHz8lFsarg5jzCjnirbThfCZ5oVGavko5+kiP913E9xPi4E8a9H+HzVfNZdN03i9XjPZNzyLsSzM1OJQuaB9h4V8uiozrCNED4UL8JebqQcHLei/Nypczvk+BnwilaDU4vRpfIyiPv0xWTFSvJj5dJ1bFPowtGVilNlBCJ7sThwQpXoCz6lVhysiZu0Yq2WNA3rm+//lvTjtzw== 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=WnodbyZMopN7JaAyoJy+8eyLEBzx5ZhK8voZ+UTUvUc=; b=CxaLKHjkcMMJvOMNccXgh/9aq8s6KUpqwfYdSb8rhFy8ilc28XRZrtOpN21tNsBjVOv9ex1MKU6j7XQlMxqc09A5XLsP0ZZXTSCpvJtCK9uNtG8shLej26DDJA/hd/58OxVeaHXrJNbA+oDOTZZrViJBG1jj+1yb0Z9JBdlLMJZiA/ln4X5Ovmr98WqHsSm7tm7K3cj4u2W1Q5zbTvzuofwuT9FgiskZE3gl7tjvviZ4pIlJ+tSSO9QP2Dl9jz4H7vVsCCqb3GdggLVejrglzYFTgbX8XGqatrcXCcX1LUCqrlKxujRBh/iU0WxcJ2JWxG0Ip/YH/XBebRnD9kAczA== 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:13:31 +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:13:31 +0000 Date: Tue, 24 Jan 2023 12:13:29 +0100 From: Manuel Traut To: linux-kernel@vger.kernel.org Cc: Dmitry Torokhov , Frieder Schrempf , linux-input@vger.kernel.org Subject: [PATCH 2/3 v6] input: pwm-beeper: add feature to set volume level Message-ID: References: Content-Disposition: inline In-Reply-To: X-ClientProxiedBy: AS4P189CA0036.EURP189.PROD.OUTLOOK.COM (2603:10a6:20b:5dd::7) 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: 8202e2c4-155f-43fa-98c1-08dafdfc06f9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /DoLYMOGqCtPgNRme7Ku/UNbTO9/FVKp/le9+9pdagAu1gh1QiyTL11IV69QlOUUSNC03NuaUOBbHTp7X76wHCBRsh5ClPbWAAsZdcTVHGJYHquEWbQq8/sfqogvqO03qKkYa9CiK4vE8BCS/Zm1KK8AZqc1QBRtY2ax0OihhmDhwduT/oKz9crA6hay1PuKMNTLd7u7WSBHgPDUyYKau/2WDODErwzQglnElJNjufimApxTW0whOtm9r12GnuizJJj+DX92NJbUDmmCp5aG8b2bWq774Uu8Kz+HhR88YuMPh/SvfjSnjssTg6R5bOl9sqPKj/zG/cALTLp+ahghp/pObxGJzRxnqYxr83/8MOt9oVFpy5lkoTmaBHhx00yJzCLRFJpWMbJWXZ2aaPAJUXo2h+IOAV+kyZ6epgA356eqNytOCI+Ejxj5XN/hGp6v/JyoDkEeNHilimUQyp7xJBaJq79VQwAtyrcXcGz1Mx5llY4S5oGyf/3yWQg4sTECgHHAFAotlp4pxSjvt3X0Dx6f1ysapah8Ai8o1/rMIQlvyW9ABF9lJV/FSIVDXwwTL1jX+0CLqeqNvt0NCTOIcXDJ/yR3Clx+3yk60KHylC4v+LMHwFgWgP7lZ/JvBiydPRejEAKdbRzTP9zQjxbTUIXbxTYGHumZezDoIifRbJ24xh5k31bol9oL+L4z5DbkWHOO+RjBlOR+cSMzLh47Bw== 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)(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?ALRYwTHsNUWeE/PpSso016i1Y6zy?= =?utf-8?q?XJ4IlAeiRmlbhPyuiwMLFoMPaJ7kSKKzUmwiwEPVvT/tPuQkyyeVTSkqHY4Uec3Xu?= =?utf-8?q?vFAmD2e/2LFB9hZGqD/hZYtEpp/pIdUpqVLPxAAq3yOR5uIYeh0cweRPjj9KSHIfH?= =?utf-8?q?sMhmuLjYw4vrEb6GxVjB1KF6rLh8hm2CToYACWrxb7ywj72/qgdY8Q1+kLVez7kgN?= =?utf-8?q?8HCfazYuDW6ldWyRjF3KcGV0YVvyvF946ezyrRdK2ompQ6W8Rqq9VMs8GHQGIOHiC?= =?utf-8?q?tvIJ1ELjmJAFUozqWfEUgYygnfPJDqF3Bf6J3zeVWNEIiB+2u+0yYJRJPm3jDjwcI?= =?utf-8?q?P9RcTDsjKo/toNSoEGBhZKVwCZiry2NcE4xhecCkX0aRa6M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HGY4tLLm/s?= =?utf-8?q?Hzu38M0voRsSwq/omO3YhsR3MKIMQZA7E0J6S5C+pmpIjmDlcChBm564hPjCMa4/2?= =?utf-8?q?bdPuzVKpNvi9LiupbHKbe4KsFP9og+BXcJF3dGM3TX1VMBkfqg9lkGFDAhQFFdUJq?= =?utf-8?q?N4ptU0lU25TQFjtJsCu4MEvqNUuWrayT3eEbebYQPGJVFmgGF5vwAPCE+Rp1bJLr5?= =?utf-8?q?cHbpRN8RQcKzu5KOp80TJs7plBuWDBk8+g06+Gxi4JAqm7mW0uh4tgXDYIRSQDp8u?= =?utf-8?q?L93GZXnxzjQI?= X-OriginatorOrg: mt.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8202e2c4-155f-43fa-98c1-08dafdfc06f9 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:13:31.7890 (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: b8JjyLNwiyv/EypsAcuvqcOmKhDu8S7ubHHQxR7ZzQ8NUqnRHKJv3UiTOOdrbyuKGOoSiHm2PlXiXw4koTFnpg== 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,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,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?1755902879806099298?= This patch adds the documentation for the devicetree bindings to set the volume levels. Signed-off-by: Frieder Schrempf Acked-by: Rob Herring --- .../devicetree/bindings/input/pwm-beeper.txt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Documentation/devicetree/bindings/input/pwm-beeper.txt b/Documentation/devicetree/bindings/input/pwm-beeper.txt index 8fc0e48c20db..93cab5eee9f2 100644 --- a/Documentation/devicetree/bindings/input/pwm-beeper.txt +++ b/Documentation/devicetree/bindings/input/pwm-beeper.txt @@ -9,6 +9,15 @@ Required properties: Optional properties: - amp-supply: phandle to a regulator that acts as an amplifier for the beeper - beeper-hz: bell frequency in Hz +- volume-levels: Array of PWM duty cycle values that correspond to + linear volume levels. These need to be in the range of 0 to 500, + while 0 means 0% duty cycle (mute) and 500 means 50% duty cycle + (max volume). + Please note that the actual volume of most beepers is highly + non-linear, which means that low volume levels are probably somewhere + in the range of 1 to 30 (0.1-3% duty cycle). +- default-volume-level: the default volume level (index into the + array defined by the "volume-levels" property) Example: @@ -21,4 +30,6 @@ beeper { compatible = "pwm-beeper"; pwms = <&pwm0>; amp-supply = <&beeper_amp>; + volume-levels = <0 8 20 40 500>; + default-volume-level = <4>; }; 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;SF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IP/21y4uJvTn3DPBqMQpu6BVG?= =?utf-8?q?rbh/UkuW+sFVcvX7eekCB1qJA/9fH1n37f6vBmMxpfCvCJIllhac4lBN+39PGUnxm?= =?utf-8?q?VrqhYlH5Zca4s33zQcc+odrDmafwWPayltULJJVMRnHk0Ax9+2xwLPsLrnCJqEFM2?= =?utf-8?q?zzpA5sNRFUcvEiMN0EqkT9/AxRWKBdi9/vsU4yjk7Ho7rQJimgSAEc/uzD0V3yMBY?= =?utf-8?q?8dS5kvKlZD9fJEStILx9qCMVLSis957j0hSGzXh5kXJIZYpSXc7zBlP04HZ76rbmv?= =?utf-8?q?dk56VtxQjA+ARt8pAFCjfrlZN/UjAzCNpKzOea8vS0e0C4UEi6lnX5ndSvLNlAka1?= =?utf-8?q?pv3QlHogH6NwcooBvi4zIDSc6+XM+tbC3+1pkjwvEjvG2swLxyWy3LliMdWD2om86?= =?utf-8?q?AWPla26nwLtr/m4Km82eLllw1M/1YYTwCv0LMJHi/oOW5gtmyfOIMx9fI+GVHddUI?= =?utf-8?q?IxsCUHBiJydLvuw3TkvENqVeJq30CEbizCq2VyVyVCuXsxo21MUjVNGJl9cV/GSsT?= =?utf-8?q?1njQvQegX7ITljcbIBUOKM1N+vVqMvqGXHmoXWvnTtJpGTo5N4WA1gfs9zJgjqULV?= =?utf-8?q?KAKpHkocaUEW3F6+o+fx7iBuLhubLXahHyDW/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) {