hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/gpio/gpio-uniphier.c
....@@ -1,18 +1,9 @@
1
-/*
2
- * Copyright (C) 2017 Socionext Inc.
3
- * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
4
- *
5
- * This program is free software; you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License version 2 as
7
- * published by the Free Software Foundation.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- */
1
+// SPDX-License-Identifier: GPL-2.0
2
+//
3
+// Copyright (C) 2017 Socionext Inc.
4
+// Author: Masahiro Yamada <yamada.masahiro@socionext.com>
145
15
-#include <linux/bitops.h>
6
+#include <linux/bits.h>
167 #include <linux/gpio/driver.h>
178 #include <linux/irq.h>
189 #include <linux/irqdomain.h>
....@@ -23,9 +14,6 @@
2314 #include <linux/platform_device.h>
2415 #include <linux/spinlock.h>
2516 #include <dt-bindings/gpio/uniphier-gpio.h>
26
-
27
-#define UNIPHIER_GPIO_BANK_MASK \
28
- GENMASK((UNIPHIER_GPIO_LINES_PER_BANK) - 1, 0)
2917
3018 #define UNIPHIER_GPIO_IRQ_MAX_NUM 24
3119
....@@ -42,7 +30,7 @@
4230 struct irq_domain *domain;
4331 void __iomem *regs;
4432 spinlock_t lock;
45
- u32 saved_vals[0];
33
+ u32 saved_vals[];
4634 };
4735
4836 static unsigned int uniphier_gpio_bank_to_reg(unsigned int bank)
....@@ -122,7 +110,10 @@
122110 static int uniphier_gpio_get_direction(struct gpio_chip *chip,
123111 unsigned int offset)
124112 {
125
- return uniphier_gpio_offset_read(chip, offset, UNIPHIER_GPIO_PORT_DIR);
113
+ if (uniphier_gpio_offset_read(chip, offset, UNIPHIER_GPIO_PORT_DIR))
114
+ return GPIO_LINE_DIRECTION_IN;
115
+
116
+ return GPIO_LINE_DIRECTION_OUT;
126117 }
127118
128119 static int uniphier_gpio_direction_input(struct gpio_chip *chip,
....@@ -156,15 +147,11 @@
156147 static void uniphier_gpio_set_multiple(struct gpio_chip *chip,
157148 unsigned long *mask, unsigned long *bits)
158149 {
159
- unsigned int bank, shift, bank_mask, bank_bits;
160
- int i;
150
+ unsigned long i, bank, bank_mask, bank_bits;
161151
162
- for (i = 0; i < chip->ngpio; i += UNIPHIER_GPIO_LINES_PER_BANK) {
152
+ for_each_set_clump8(i, bank_mask, mask, chip->ngpio) {
163153 bank = i / UNIPHIER_GPIO_LINES_PER_BANK;
164
- shift = i % BITS_PER_LONG;
165
- bank_mask = (mask[BIT_WORD(i)] >> shift) &
166
- UNIPHIER_GPIO_BANK_MASK;
167
- bank_bits = bits[BIT_WORD(i)] >> shift;
154
+ bank_bits = bitmap_get_value8(bits, i);
168155
169156 uniphier_gpio_bank_write(chip, bank, UNIPHIER_GPIO_PORT_DATA,
170157 bank_mask, bank_bits);
....@@ -355,7 +342,6 @@
355342 struct uniphier_gpio_priv *priv;
356343 struct gpio_chip *chip;
357344 struct irq_chip *irq_chip;
358
- struct resource *regs;
359345 unsigned int nregs;
360346 u32 ngpios;
361347 int ret;
....@@ -379,8 +365,7 @@
379365 if (!priv)
380366 return -ENOMEM;
381367
382
- regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
383
- priv->regs = devm_ioremap_resource(dev, regs);
368
+ priv->regs = devm_platform_ioremap_resource(pdev, 0);
384369 if (IS_ERR(priv->regs))
385370 return PTR_ERR(priv->regs);
386371