Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1582941 > unrolled thread
| Started by | Frieder Schrempf <frieder.schrempf@exceet.de> |
|---|---|
| First post | 2017-02-16 22:10 +0100 |
| Last post | 2017-02-17 11:00 +0100 |
| Articles | 7 — 1 participant |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH v4 0/3] input: pwm-beeper: add feature to set volume level Frieder Schrempf <frieder.schrempf@exceet.de> - 2017-02-16 22:10 +0100
[PATCH v4 3/3] input: pwm-beeper: add devicetree bindings to set volume levels Frieder Schrempf <frieder.schrempf@exceet.de> - 2017-02-16 22:20 +0100
[PATCH v4 2/3] input: pwm-beeper: add documentation for volume devicetree bindings Frieder Schrempf <frieder.schrempf@exceet.de> - 2017-02-16 22:20 +0100
[PATCH v5 3/3] input: pwm-beeper: add devicetree bindings to set volume levels Frieder Schrempf <frieder.schrempf@exceet.de> - 2017-02-17 11:00 +0100
[PATCH v5 1/3] input: pwm-beeper: add feature to set volume via sysfs Frieder Schrempf <frieder.schrempf@exceet.de> - 2017-02-17 11:00 +0100
[PATCH v5 0/3] input: pwm-beeper: add feature to set volume level Frieder Schrempf <frieder.schrempf@exceet.de> - 2017-02-17 11:00 +0100
[PATCH v5 2/3] input: pwm-beeper: add documentation for volume devicetree bindings Frieder Schrempf <frieder.schrempf@exceet.de> - 2017-02-17 11:00 +0100
| From | Frieder Schrempf <frieder.schrempf@exceet.de> |
|---|---|
| Date | 2017-02-16 22:10 +0100 |
| Subject | [PATCH v4 0/3] input: pwm-beeper: add feature to set volume level |
| Message-ID | <tbBtn-3uQ-15@gated-at.bofh.it> |
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 number of volume levels available and their values can be specified via device tree (similar to pwm-backlight). The volume adjustment is done by changing the duty cycle of the pwm signal. Changes in v4: - move sysfs attributes from class/input to devices/pwm-beeper - rename max_volume_level to max_volume - move array allocation to probe function - rename attribute structs - remove needless code - update date - use generic device properties instead of dt properties Frieder Schrempf (3): input: pwm-beeper: add feature to set volume via sysfs input: pwm-beeper: add documentation for volume devicetree bindings input: pwm-beeper: add devicetree bindings to set volume levels Documentation/ABI/testing/sysfs-devices-pwm-beeper | 17 ++++ .../devicetree/bindings/input/pwm-beeper.txt | 20 ++++ drivers/input/misc/pwm-beeper.c | 111 ++++++++++++++++++++- 3 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-devices-pwm-beeper -- 2.7.4
[toc] | [next] | [standalone]
| From | Frieder Schrempf <frieder.schrempf@exceet.de> |
|---|---|
| Date | 2017-02-16 22:20 +0100 |
| Subject | [PATCH v4 3/3] input: pwm-beeper: add devicetree bindings to set volume levels |
| Message-ID | <tbBD4-3zv-17@gated-at.bofh.it> |
| In reply to | #1582941 |
This patch adds the devicetree bindings to set the volume levels
and the default volume level.
Signed-off-by: Frieder Schrempf <frieder.schrempf@exceet.de>
---
Changes in v4:
- use generic device properties instead of dt properties
drivers/input/misc/pwm-beeper.c | 63 ++++++++++++++++++++++++++++-------------
1 file changed, 44 insertions(+), 19 deletions(-)
diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c
index e29904e..6fe54de 100644
--- a/drivers/input/misc/pwm-beeper.c
+++ b/drivers/input/misc/pwm-beeper.c
@@ -154,8 +154,9 @@ static int pwm_beeper_probe(struct platform_device *pdev)
{
unsigned long pwm_id = (unsigned long)dev_get_platdata(&pdev->dev);
struct pwm_beeper *beeper;
- int error;
- size_t size;
+ int error, length;
+ size_t size;
+ u32 value;
beeper = kzalloc(sizeof(*beeper), GFP_KERNEL);
if (!beeper)
@@ -181,23 +182,47 @@ static int pwm_beeper_probe(struct platform_device *pdev)
INIT_WORK(&beeper->work, pwm_beeper_work);
- 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;
+ /* 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_level = 1;
+ } else
+ beeper->max_volume_level = length;
+
+ /* read volume levels from DT property */
+ if (beeper->max_volume_level > 0) {
+ size_t size = sizeof(*beeper->volume_levels) *
+ beeper->max_volume_level;
+
+ 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_level);
+
+ 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_level - 1;
+ }
+ } else {
+ beeper->volume_levels[0] = 500;
+ value = 0;
+ }
+
+ beeper->volume = value;
+ beeper->max_volume_level--;
+ }
beeper->input = input_allocate_device();
if (!beeper->input) {
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Frieder Schrempf <frieder.schrempf@exceet.de> |
|---|---|
| Date | 2017-02-16 22:20 +0100 |
| Subject | [PATCH v4 2/3] input: pwm-beeper: add documentation for volume devicetree bindings |
| Message-ID | <tbBD5-3zv-25@gated-at.bofh.it> |
| In reply to | #1582941 |
This patch adds the documentation for the devicetree bindings to set
the volume levels.
Signed-off-by: Frieder Schrempf <frieder.schrempf@exceet.de>
Acked-by: Rob Herring <robh@kernel.org>
---
Changes in v4:
- none
.../devicetree/bindings/input/pwm-beeper.txt | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/Documentation/devicetree/bindings/input/pwm-beeper.txt b/Documentation/devicetree/bindings/input/pwm-beeper.txt
index be332ae..496b68f 100644
--- a/Documentation/devicetree/bindings/input/pwm-beeper.txt
+++ b/Documentation/devicetree/bindings/input/pwm-beeper.txt
@@ -5,3 +5,23 @@ Registers a PWM device as beeper.
Required properties:
- compatible: should be "pwm-beeper"
- pwms: phandle to the physical PWM device
+
+Optional properties:
+- 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:
+
+ pwm-beeper {
+ compatible = "pwm-beeper";
+ pwms = <&pwm4 0 5000>;
+ volume-levels = <0 8 20 40 500>;
+ default-volume-level = <4>;
+ };
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Frieder Schrempf <frieder.schrempf@exceet.de> |
|---|---|
| Date | 2017-02-17 11:00 +0100 |
| Subject | [PATCH v5 3/3] input: pwm-beeper: add devicetree bindings to set volume levels |
| Message-ID | <tbNuy-2Ef-13@gated-at.bofh.it> |
| In reply to | #1582941 |
This patch adds the devicetree bindings to set the volume levels
and the default volume level.
Signed-off-by: Frieder Schrempf <frieder.schrempf@exceet.de>
---
Changes in v5:
- fix renaming of max_volume_level to max_volume
- remove needless variable declaration
drivers/input/misc/pwm-beeper.c | 60 ++++++++++++++++++++++++++++-------------
1 file changed, 42 insertions(+), 18 deletions(-)
diff --git a/drivers/input/misc/pwm-beeper.c b/drivers/input/misc/pwm-beeper.c
index 5fbc198..aee88d6 100644
--- a/drivers/input/misc/pwm-beeper.c
+++ b/drivers/input/misc/pwm-beeper.c
@@ -154,8 +154,9 @@ static int pwm_beeper_probe(struct platform_device *pdev)
{
unsigned long pwm_id = (unsigned long)dev_get_platdata(&pdev->dev);
struct pwm_beeper *beeper;
- int error;
+ int error, length;
size_t size;
+ u32 value;
beeper = kzalloc(sizeof(*beeper), GFP_KERNEL);
if (!beeper)
@@ -181,23 +182,46 @@ static int pwm_beeper_probe(struct platform_device *pdev)
INIT_WORK(&beeper->work, pwm_beeper_work);
- 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;
+ /* 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 = value;
+ beeper->max_volume--;
+ }
beeper->input = input_allocate_device();
if (!beeper->input) {
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Frieder Schrempf <frieder.schrempf@exceet.de> |
|---|---|
| Date | 2017-02-17 11:00 +0100 |
| Subject | [PATCH v5 1/3] input: pwm-beeper: add feature to set volume via sysfs |
| Message-ID | <tbNuy-2Ef-27@gated-at.bofh.it> |
| In reply to | #1582941 |
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 <frieder.schrempf@exceet.de>
---
Changes in v5:
- none
Documentation/ABI/testing/sysfs-devices-pwm-beeper | 17 +++++
drivers/input/misc/pwm-beeper.c | 84 +++++++++++++++++++++-
2 files changed, 100 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 0000000..d068c58
--- /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 <frieder.schrempf@exceet.de>
+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 <frieder.schrempf@exceet.de>
+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 5f9655d..5fbc198 100644
--- a/drivers/input/misc/pwm-beeper.c
+++ b/drivers/input/misc/pwm-beeper.c
@@ -1,5 +1,9 @@
/*
* Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
+ *
+ * Copyright (C) 2016, Frieder Schrempf <frieder.schrempf@exceet.de>
+ * (volume support)
+ *
* PWM beeper driver
*
* This program is free software; you can redistribute it and/or modify it
@@ -27,16 +31,69 @@ struct pwm_beeper {
struct pwm_device *pwm;
struct work_struct work;
unsigned long period;
+ unsigned int volume;
+ unsigned int *volume_levels;
+ unsigned int max_volume;
};
#define HZ_TO_NANOSECONDS(x) (1000000000UL/(x))
+static ssize_t beeper_show_volume(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 beeper_show_max_volume(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 beeper_store_volume(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(volume, 0644, beeper_show_volume, beeper_store_volume);
+static DEVICE_ATTR(max_volume, 0644, beeper_show_max_volume, 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 void __pwm_beeper_set(struct pwm_beeper *beeper)
{
unsigned long period = beeper->period;
if (period) {
- pwm_config(beeper->pwm, period / 2, period);
+ pwm_config(beeper->pwm,
+ period / 1000 * beeper->volume_levels[beeper->volume],
+ period);
pwm_enable(beeper->pwm);
} else
pwm_disable(beeper->pwm);
@@ -98,6 +155,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;
int error;
+ size_t size;
beeper = kzalloc(sizeof(*beeper), GFP_KERNEL);
if (!beeper)
@@ -123,6 +181,24 @@ static int pwm_beeper_probe(struct platform_device *pdev)
INIT_WORK(&beeper->work, pwm_beeper_work);
+ 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 = input_allocate_device();
if (!beeper->input) {
dev_err(&pdev->dev, "Failed to allocate input device\n");
@@ -146,6 +222,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);
+ goto err_pwm_free;
+ }
+
error = input_register_device(beeper->input);
if (error) {
dev_err(&pdev->dev, "Failed to register input device: %d\n", error);
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Frieder Schrempf <frieder.schrempf@exceet.de> |
|---|---|
| Date | 2017-02-17 11:00 +0100 |
| Subject | [PATCH v5 0/3] input: pwm-beeper: add feature to set volume level |
| Message-ID | <tbNuy-2Ef-15@gated-at.bofh.it> |
| In reply to | #1582941 |
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 number of volume levels available and their values can be specified via device tree (similar to pwm-backlight). The volume adjustment is done by changing the duty cycle of the pwm signal. Changes in v5: - fix renaming of max_volume_level to max_volume - remove needless variable declaration Frieder Schrempf (3): input: pwm-beeper: add feature to set volume via sysfs input: pwm-beeper: add documentation for volume devicetree bindings input: pwm-beeper: add devicetree bindings to set volume levels Documentation/ABI/testing/sysfs-devices-pwm-beeper | 17 ++++ .../devicetree/bindings/input/pwm-beeper.txt | 20 ++++ drivers/input/misc/pwm-beeper.c | 110 ++++++++++++++++++++- 3 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-devices-pwm-beeper -- 2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Frieder Schrempf <frieder.schrempf@exceet.de> |
|---|---|
| Date | 2017-02-17 11:00 +0100 |
| Subject | [PATCH v5 2/3] input: pwm-beeper: add documentation for volume devicetree bindings |
| Message-ID | <tbNuz-2Ef-47@gated-at.bofh.it> |
| In reply to | #1583276 |
This patch adds the documentation for the devicetree bindings to set
the volume levels.
Signed-off-by: Frieder Schrempf <frieder.schrempf@exceet.de>
Acked-by: Rob Herring <robh@kernel.org>
---
Changes in v5:
- none
.../devicetree/bindings/input/pwm-beeper.txt | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/Documentation/devicetree/bindings/input/pwm-beeper.txt b/Documentation/devicetree/bindings/input/pwm-beeper.txt
index be332ae..496b68f 100644
--- a/Documentation/devicetree/bindings/input/pwm-beeper.txt
+++ b/Documentation/devicetree/bindings/input/pwm-beeper.txt
@@ -5,3 +5,23 @@ Registers a PWM device as beeper.
Required properties:
- compatible: should be "pwm-beeper"
- pwms: phandle to the physical PWM device
+
+Optional properties:
+- 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:
+
+ pwm-beeper {
+ compatible = "pwm-beeper";
+ pwms = <&pwm4 0 5000>;
+ volume-levels = <0 8 20 40 500>;
+ default-volume-level = <4>;
+ };
--
2.7.4
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web