diff options
Diffstat (limited to 'drivers/gpio/wm831x-gpio.c')
-rw-r--r-- | drivers/gpio/wm831x-gpio.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/drivers/gpio/wm831x-gpio.c b/drivers/gpio/wm831x-gpio.c index 1fa449a1a4cb..309644cf4d9b 100644 --- a/drivers/gpio/wm831x-gpio.c +++ b/drivers/gpio/wm831x-gpio.c | |||
@@ -108,6 +108,37 @@ static int wm831x_gpio_to_irq(struct gpio_chip *chip, unsigned offset) | |||
108 | return wm831x->irq_base + WM831X_IRQ_GPIO_1 + offset; | 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 | #ifdef CONFIG_DEBUG_FS | 142 | #ifdef CONFIG_DEBUG_FS |
112 | static void wm831x_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) | 143 | static void wm831x_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) |
113 | { | 144 | { |
@@ -208,6 +239,7 @@ static struct gpio_chip template_chip = { | |||
208 | .direction_output = wm831x_gpio_direction_out, | 239 | .direction_output = wm831x_gpio_direction_out, |
209 | .set = wm831x_gpio_set, | 240 | .set = wm831x_gpio_set, |
210 | .to_irq = wm831x_gpio_to_irq, | 241 | .to_irq = wm831x_gpio_to_irq, |
242 | .set_debounce = wm831x_gpio_set_debounce, | ||
211 | .dbg_show = wm831x_gpio_dbg_show, | 243 | .dbg_show = wm831x_gpio_dbg_show, |
212 | .can_sleep = 1, | 244 | .can_sleep = 1, |
213 | }; | 245 | }; |