Skip to contentSkip to conversation

Input: pwm-beeper: support customized freq for SND_BELL

PATCH In review Heiko Schocher 2 participants 2 messages Mar 1, 2017 – Mar 7, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 Input: pwm-beeper: support customized freq for SND_BELL

From: Guan Ben <[email protected]>

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

---

Changes in v3:
- add comment from David Lechner:
- readd the switch statement, instead using if / then
- remove check IS_ENABLED(CONFIG_OF)
- remove not used node variable
- change warning string from "Failed to read beeper-hz" to "'beeper-hz' not specified"
- remove function pwm_beeper_init_bell_frequency() as it is to simple.
- checked that device_property_read_u32() does not modify the bell_frequency, if the property "beeper_hz" is not defined.
- add comment from Rob Herring:
- add Acked-by from Rob Herring
Rob also mentioned to remove the IS_ENABLED(CONFIG_OF) check and node variable is unused.

Changes in v2:
- add comment from Rob Herring:
rename property name "bell-frequency" to "beeper-hz"
- add comment from Dmitry Torokhov:
use device_property_read_u32() instead of of_property_read_u32()
- rebased against c470abd4fde40ea6a0846a2beab642a578c0b8cd Linux 4.10

 Documentation/devicetree/bindings/input/pwm-beeper.txt |  3 +++
 drivers/input/misc/pwm-beeper.c                        | 11 ++++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/input/pwm-beeper.txt +3 -0
index be332ae..4e4e128 100644
@@ -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:
+- beeper-hz:  bell frequency in Hz
drivers/input/misc/pwm-beeper.c +10 -1
index 5f9655d..f2fcd50 100644
@@ -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))
@@ -60,7 +61,7 @@ static int pwm_beeper_event(struct input_dev *input,
 
 	switch (code) {
 	case SND_BELL:
-		value = value ? 1000 : 0;
+		value = value ? beeper->bell_frequency : 0;
 		break;
 	case SND_TONE:
 		break;
@@ -97,6 +98,7 @@ static int pwm_beeper_probe(struct platform_device *pdev)
 {
 	unsigned long pwm_id = (unsigned long)dev_get_platdata(&pdev->dev);
 	struct pwm_beeper *beeper;
+	unsigned int bell_frequency = 1000;
 	int error;
 
 	beeper = kzalloc(sizeof(*beeper), GFP_KERNEL);
@@ -122,6 +124,13 @@ static int pwm_beeper_probe(struct platform_device *pdev)
 	pwm_apply_args(beeper->pwm);
 
 	INIT_WORK(&beeper->work, pwm_beeper_work);
+	error = device_property_read_u32(&pdev->dev, "beeper-hz",
+				       &bell_frequency);
+	if (error < 0)
+		dev_dbg(&pdev->dev, "'beeper-hz' not specified, using default: %u Hz\n",
+			bell_frequency);
+
+	beeper->bell_frequency = bell_frequency;
 
 	beeper->input = input_allocate_device();
 	if (!beeper->input) {
Signature · 1 line
2.7.4
maintainer
#1 lore raw
Quoted 11 lines · Heiko Schocher

From: Guan Ben <[email protected]>

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

Reconciled with the latest version and applied, thank you.

Quoted 87 lines

---

Changes in v3:
- add comment from David Lechner:
- readd the switch statement, instead using if / then
- remove check IS_ENABLED(CONFIG_OF)
- remove not used node variable
- change warning string from "Failed to read beeper-hz" to "'beeper-hz' not specified"
- remove function pwm_beeper_init_bell_frequency() as it is to simple.
- checked that device_property_read_u32() does not modify the bell_frequency, if the property "beeper_hz" is not defined.
- add comment from Rob Herring:
- add Acked-by from Rob Herring
Rob also mentioned to remove the IS_ENABLED(CONFIG_OF) check and node variable is unused.

Changes in v2:
- add comment from Rob Herring:
rename property name "bell-frequency" to "beeper-hz"
- add comment from Dmitry Torokhov:
use device_property_read_u32() instead of of_property_read_u32()
- rebased against c470abd4fde40ea6a0846a2beab642a578c0b8cd Linux 4.10

 Documentation/devicetree/bindings/input/pwm-beeper.txt |  3 +++
 drivers/input/misc/pwm-beeper.c                        | 11 ++++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/input/pwm-beeper.txt +3 -0
index be332ae..4e4e128 100644
@@ -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:
+- beeper-hz:  bell frequency in Hz
drivers/input/misc/pwm-beeper.c +10 -1
index 5f9655d..f2fcd50 100644
@@ -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))
@@ -60,7 +61,7 @@ static int pwm_beeper_event(struct input_dev *input,
 
 	switch (code) {
 	case SND_BELL:
-		value = value ? 1000 : 0;
+		value = value ? beeper->bell_frequency : 0;
 		break;
 	case SND_TONE:
 		break;
@@ -97,6 +98,7 @@ static int pwm_beeper_probe(struct platform_device *pdev)
 {
 	unsigned long pwm_id = (unsigned long)dev_get_platdata(&pdev->dev);
 	struct pwm_beeper *beeper;
+	unsigned int bell_frequency = 1000;
 	int error;
 
 	beeper = kzalloc(sizeof(*beeper), GFP_KERNEL);
@@ -122,6 +124,13 @@ static int pwm_beeper_probe(struct platform_device *pdev)
 	pwm_apply_args(beeper->pwm);
 
 	INIT_WORK(&beeper->work, pwm_beeper_work);
+	error = device_property_read_u32(&pdev->dev, "beeper-hz",
+				       &bell_frequency);
+	if (error < 0)
+		dev_dbg(&pdev->dev, "'beeper-hz' not specified, using default: %u Hz\n",
+			bell_frequency);
+
+	beeper->bell_frequency = bell_frequency;
 
 	beeper->input = input_allocate_device();
 	if (!beeper->input) {
Signature · 1 line
2.7.4
Signature · 1 line
Dmitry