Commit b12c35e22d102172cd2a69581f939ec9a70a7942
Committed by
Samuel Ortiz
1 parent
f94add3bd4
Exists in
master
and in
39 other branches
gpiolib: Implement set_debounce for WM831x GPIOs
The debounce times are approximate, they can be selected using the two input functions. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Showing 1 changed file with 32 additions and 0 deletions Side-by-side Diff
drivers/gpio/wm831x-gpio.c
... | ... | @@ -108,6 +108,37 @@ |
108 | 108 | return wm831x->irq_base + WM831X_IRQ_GPIO_1 + offset; |
109 | 109 | } |
110 | 110 | |
111 | +static int wm831x_gpio_set_debounce(struct gpio_chip *chip, unsigned offset, | |
112 | + unsigned debounce) | |
113 | +{ | |
114 | + struct wm831x_gpio *wm831x_gpio = to_wm831x_gpio(chip); | |
115 | + struct wm831x *wm831x = wm831x_gpio->wm831x; | |
116 | + int reg = WM831X_GPIO1_CONTROL + offset; | |
117 | + int ret, fn; | |
118 | + | |
119 | + ret = wm831x_reg_read(wm831x, reg); | |
120 | + if (ret < 0) | |
121 | + return ret; | |
122 | + | |
123 | + switch (ret & WM831X_GPN_FN_MASK) { | |
124 | + case 0: | |
125 | + case 1: | |
126 | + break; | |
127 | + default: | |
128 | + /* Not in GPIO mode */ | |
129 | + return -EBUSY; | |
130 | + } | |
131 | + | |
132 | + if (debounce >= 32 && debounce <= 64) | |
133 | + fn = 0; | |
134 | + else if (debounce >= 4000 && debounce <= 8000) | |
135 | + fn = 1; | |
136 | + else | |
137 | + return -EINVAL; | |
138 | + | |
139 | + return wm831x_set_bits(wm831x, reg, WM831X_GPN_FN_MASK, fn); | |
140 | +} | |
141 | + | |
111 | 142 | #ifdef CONFIG_DEBUG_FS |
112 | 143 | static void wm831x_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) |
113 | 144 | { |
... | ... | @@ -208,6 +239,7 @@ |
208 | 239 | .direction_output = wm831x_gpio_direction_out, |
209 | 240 | .set = wm831x_gpio_set, |
210 | 241 | .to_irq = wm831x_gpio_to_irq, |
242 | + .set_debounce = wm831x_gpio_set_debounce, | |
211 | 243 | .dbg_show = wm831x_gpio_dbg_show, |
212 | 244 | .can_sleep = 1, |
213 | 245 | }; |