.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0+ |
---|
1 | 2 | /* |
---|
2 | 3 | * Access to GPIOs on TWL4030/TPS659x0 chips |
---|
3 | 4 | * |
---|
.. | .. |
---|
9 | 10 | * |
---|
10 | 11 | * Initial Code: |
---|
11 | 12 | * Andy Lowe / Nishanth Menon |
---|
12 | | - * |
---|
13 | | - * This program is free software; you can redistribute it and/or modify |
---|
14 | | - * it under the terms of the GNU General Public License as published by |
---|
15 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
16 | | - * (at your option) any later version. |
---|
17 | | - * |
---|
18 | | - * This program is distributed in the hope that it will be useful, |
---|
19 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
20 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
21 | | - * GNU General Public License for more details. |
---|
22 | | - * |
---|
23 | | - * You should have received a copy of the GNU General Public License |
---|
24 | | - * along with this program; if not, write to the Free Software |
---|
25 | | - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
26 | 13 | */ |
---|
27 | 14 | |
---|
28 | 15 | #include <linux/module.h> |
---|
.. | .. |
---|
30 | 17 | #include <linux/interrupt.h> |
---|
31 | 18 | #include <linux/kthread.h> |
---|
32 | 19 | #include <linux/irq.h> |
---|
33 | | -#include <linux/gpio.h> |
---|
| 20 | +#include <linux/gpio/driver.h> |
---|
34 | 21 | #include <linux/platform_device.h> |
---|
35 | 22 | #include <linux/of.h> |
---|
36 | 23 | #include <linux/irqdomain.h> |
---|
.. | .. |
---|
165 | 152 | ret = gpio_twl4030_write(base, reg); |
---|
166 | 153 | } |
---|
167 | 154 | return ret; |
---|
| 155 | +} |
---|
| 156 | + |
---|
| 157 | +static int twl4030_get_gpio_direction(int gpio) |
---|
| 158 | +{ |
---|
| 159 | + u8 d_bnk = gpio >> 3; |
---|
| 160 | + u8 d_msk = BIT(gpio & 0x7); |
---|
| 161 | + u8 base = REG_GPIODATADIR1 + d_bnk; |
---|
| 162 | + int ret = 0; |
---|
| 163 | + |
---|
| 164 | + ret = gpio_twl4030_read(base); |
---|
| 165 | + if (ret < 0) |
---|
| 166 | + return ret; |
---|
| 167 | + |
---|
| 168 | + if (ret & d_msk) |
---|
| 169 | + return GPIO_LINE_DIRECTION_OUT; |
---|
| 170 | + |
---|
| 171 | + return GPIO_LINE_DIRECTION_IN; |
---|
168 | 172 | } |
---|
169 | 173 | |
---|
170 | 174 | static int twl4030_set_gpio_dataout(int gpio, int enable) |
---|
.. | .. |
---|
372 | 376 | return ret; |
---|
373 | 377 | } |
---|
374 | 378 | |
---|
| 379 | +static int twl_get_direction(struct gpio_chip *chip, unsigned offset) |
---|
| 380 | +{ |
---|
| 381 | + struct gpio_twl4030_priv *priv = gpiochip_get_data(chip); |
---|
| 382 | + /* |
---|
| 383 | + * Default GPIO_LINE_DIRECTION_OUT |
---|
| 384 | + * LED GPIOs >= TWL4030_GPIO_MAX are always output |
---|
| 385 | + */ |
---|
| 386 | + int ret = GPIO_LINE_DIRECTION_OUT; |
---|
| 387 | + |
---|
| 388 | + mutex_lock(&priv->mutex); |
---|
| 389 | + if (offset < TWL4030_GPIO_MAX) { |
---|
| 390 | + ret = twl4030_get_gpio_direction(offset); |
---|
| 391 | + if (ret) { |
---|
| 392 | + mutex_unlock(&priv->mutex); |
---|
| 393 | + return ret; |
---|
| 394 | + } |
---|
| 395 | + } |
---|
| 396 | + mutex_unlock(&priv->mutex); |
---|
| 397 | + |
---|
| 398 | + return ret; |
---|
| 399 | +} |
---|
| 400 | + |
---|
375 | 401 | static int twl_to_irq(struct gpio_chip *chip, unsigned offset) |
---|
376 | 402 | { |
---|
377 | 403 | struct gpio_twl4030_priv *priv = gpiochip_get_data(chip); |
---|
.. | .. |
---|
387 | 413 | .request = twl_request, |
---|
388 | 414 | .free = twl_free, |
---|
389 | 415 | .direction_input = twl_direction_in, |
---|
390 | | - .get = twl_get, |
---|
391 | 416 | .direction_output = twl_direction_out, |
---|
| 417 | + .get_direction = twl_get_direction, |
---|
| 418 | + .get = twl_get, |
---|
392 | 419 | .set = twl_set, |
---|
393 | 420 | .to_irq = twl_to_irq, |
---|
394 | 421 | .can_sleep = true, |
---|