hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/gpio/gpio-twl4030.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0+
12 /*
23 * Access to GPIOs on TWL4030/TPS659x0 chips
34 *
....@@ -9,20 +10,6 @@
910 *
1011 * Initial Code:
1112 * 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
2613 */
2714
2815 #include <linux/module.h>
....@@ -30,7 +17,7 @@
3017 #include <linux/interrupt.h>
3118 #include <linux/kthread.h>
3219 #include <linux/irq.h>
33
-#include <linux/gpio.h>
20
+#include <linux/gpio/driver.h>
3421 #include <linux/platform_device.h>
3522 #include <linux/of.h>
3623 #include <linux/irqdomain.h>
....@@ -165,6 +152,23 @@
165152 ret = gpio_twl4030_write(base, reg);
166153 }
167154 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;
168172 }
169173
170174 static int twl4030_set_gpio_dataout(int gpio, int enable)
....@@ -372,6 +376,28 @@
372376 return ret;
373377 }
374378
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
+
375401 static int twl_to_irq(struct gpio_chip *chip, unsigned offset)
376402 {
377403 struct gpio_twl4030_priv *priv = gpiochip_get_data(chip);
....@@ -387,8 +413,9 @@
387413 .request = twl_request,
388414 .free = twl_free,
389415 .direction_input = twl_direction_in,
390
- .get = twl_get,
391416 .direction_output = twl_direction_out,
417
+ .get_direction = twl_get_direction,
418
+ .get = twl_get,
392419 .set = twl_set,
393420 .to_irq = twl_to_irq,
394421 .can_sleep = true,