lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1486444894-18321-1-git-send-email-hs@denx.de>
Date:   Tue,  7 Feb 2017 06:21:34 +0100
From:   Heiko Schocher <hs@...x.de>
To:     linux-input@...r.kernel.org
Cc:     Guan Ben <ben.guan@...bosch.com>,
        Mark Jonas <mark.jonas@...bosch.com>,
        Heiko Schocher <hs@...x.de>, devicetree@...r.kernel.org,
        Thierry Reding <thierry.reding@...il.com>,
        linux-kernel@...r.kernel.org,
        Boris Brezillon <boris.brezillon@...e-electrons.com>,
        Rob Herring <robh+dt@...nel.org>,
        Dmitry Torokhov <dmitry.torokhov@...il.com>,
        Manfred Schlaegl <manfred.schlaegl@....at>,
        Mark Rutland <mark.rutland@....com>
Subject: [PATCH] Input: pwm-beeper: support customized freq for SND_BELL

From: Guan Ben <ben.guan@...bosch.com>

extend the pwm-beeper driver to support customized frequency
for SND_BELL from device tree.

Signed-off-by: Guan Ben <ben.guan@...bosch.com>
Signed-off-by: Mark Jonas <mark.jonas@...bosch.com>
[hs@...x.de: adapted to 4.10-rc7]
Signed-off-by: Heiko Schocher <hs@...x.de>

---

 .../devicetree/bindings/input/pwm-beeper.txt       |  3 ++
 drivers/input/misc/pwm-beeper.c                    | 36 ++++++++++++++++------
 2 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/Documentation/devicetree/bindings/input/pwm-beeper.txt b/Documentation/devicetree/bindings/input/pwm-beeper.txt
index be332ae..438c6e0 100644
--- a/Documentation/devicetree/bindings/input/pwm-beeper.txt
+++ b/Documentation/devicetree/bindings/input/pwm-beeper.txt
@@ -5,3 +5,6 @@ Registers a PWM device as beeper.
 Required properties:
 - compatible: should be "pwm-beeper"
 - pwms: phandle to the physical PWM device
+
+optional properties:
+- bell-frequency:  bell frequency in Hz
diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c
index 5f9655d..99591d5 100644
--- a/drivers/input/misc/pwm-beeper.c
+++ b/drivers/input/misc/pwm-beeper.c
@@ -27,6 +27,7 @@ struct pwm_beeper {
 	struct pwm_device *pwm;
 	struct work_struct work;
 	unsigned long period;
+	unsigned int bell_frequency;
 };
 
 #define HZ_TO_NANOSECONDS(x) (1000000000UL/(x))
@@ -58,20 +59,17 @@ static int pwm_beeper_event(struct input_dev *input,
 	if (type != EV_SND || value < 0)
 		return -EINVAL;
 
-	switch (code) {
-	case SND_BELL:
-		value = value ? 1000 : 0;
-		break;
-	case SND_TONE:
-		break;
-	default:
+	if (code != SND_BELL && code != SND_TONE)
 		return -EINVAL;
-	}
 
 	if (value == 0)
 		beeper->period = 0;
-	else
+	else {
+		if (code == SND_BELL)
+			value = beeper->bell_frequency;
+
 		beeper->period = HZ_TO_NANOSECONDS(value);
+	}
 
 	schedule_work(&beeper->work);
 
@@ -93,6 +91,25 @@ static void pwm_beeper_close(struct input_dev *input)
 	pwm_beeper_stop(beeper);
 }
 
+static void pwm_beeper_init_bell_frequency(struct device *dev,
+					   struct pwm_beeper *beeper)
+{
+	struct device_node *node;
+	unsigned int bell_frequency = 1000;
+	int error;
+
+	if (IS_ENABLED(CONFIG_OF)) {
+		node = dev->of_node;
+		error = of_property_read_u32(node, "bell-frequency",
+					     &bell_frequency);
+		if (error < 0)
+			dev_dbg(dev, "Failed to read bell-frequency, using default: %u Hz\n",
+				bell_frequency);
+	}
+
+	beeper->bell_frequency = bell_frequency;
+}
+
 static int pwm_beeper_probe(struct platform_device *pdev)
 {
 	unsigned long pwm_id = (unsigned long)dev_get_platdata(&pdev->dev);
@@ -122,6 +139,7 @@ static int pwm_beeper_probe(struct platform_device *pdev)
 	pwm_apply_args(beeper->pwm);
 
 	INIT_WORK(&beeper->work, pwm_beeper_work);
+	pwm_beeper_init_bell_frequency(&pdev->dev, beeper);
 
 	beeper->input = input_allocate_device();
 	if (!beeper->input) {
-- 
2.7.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ