Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: pwm-beeper - support customized freq for SND_BELL

Extend the pwm-beeper driver to support customized frequency for SND_BELL
from device properties.

Signed-off-by: Guan Ben <ben.guan@cn.bosch.com>
Signed-off-by: Mark Jonas <mark.jonas@de.bosch.com>
Signed-off-by: Heiko Schocher <hs@denx.de>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Guan Ben and committed by
Dmitry Torokhov
fad358a0 a3cbfd56

+15 -1
+1
Documentation/devicetree/bindings/input/pwm-beeper.txt
··· 8 8 9 9 Optional properties: 10 10 - amp-supply: phandle to a regulator that acts as an amplifier for the beeper 11 + - beeper-hz: bell frequency in Hz 11 12 12 13 Example: 13 14
+14 -1
drivers/input/misc/pwm-beeper.c
··· 19 19 #include <linux/kernel.h> 20 20 #include <linux/of.h> 21 21 #include <linux/platform_device.h> 22 + #include <linux/property.h> 22 23 #include <linux/pwm.h> 23 24 #include <linux/slab.h> 24 25 #include <linux/workqueue.h> ··· 30 29 struct regulator *amplifier; 31 30 struct work_struct work; 32 31 unsigned long period; 32 + unsigned int bell_frequency; 33 33 bool suspended; 34 34 bool amplifier_on; 35 35 }; ··· 96 94 97 95 switch (code) { 98 96 case SND_BELL: 99 - value = value ? 1000 : 0; 97 + value = value ? beeper->bell_frequency : 0; 100 98 break; 101 99 case SND_TONE: 102 100 break; ··· 133 131 struct device *dev = &pdev->dev; 134 132 struct pwm_beeper *beeper; 135 133 struct pwm_state state; 134 + u32 bell_frequency; 136 135 int error; 137 136 138 137 beeper = devm_kzalloc(dev, sizeof(*beeper), GFP_KERNEL); ··· 169 166 } 170 167 171 168 INIT_WORK(&beeper->work, pwm_beeper_work); 169 + 170 + error = device_property_read_u32(dev, "beeper-hz", &bell_frequency); 171 + if (error) { 172 + bell_frequency = 1000; 173 + dev_dbg(dev, 174 + "failed to parse 'beeper-hz' property, using default: %uHz\n", 175 + bell_frequency); 176 + } 177 + 178 + beeper->bell_frequency = bell_frequency; 172 179 173 180 beeper->input = devm_input_allocate_device(dev); 174 181 if (!beeper->input) {