hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/gpio/gpio-tegra.c
....@@ -1,20 +1,12 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * arch/arm/mach-tegra/gpio.c
34 *
45 * Copyright (c) 2010 Google, Inc
6
+ * Copyright (c) 2011-2016, NVIDIA CORPORATION. All rights reserved.
57 *
68 * Author:
79 * Erik Gilling <konkers@google.com>
8
- *
9
- * This software is licensed under the terms of the GNU General Public
10
- * License version 2, as published by the Free Software Foundation, and
11
- * may be copied, distributed, and modified under those terms.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- * GNU General Public License for more details.
17
- *
1810 */
1911
2012 #include <linux/err.h>
....@@ -104,12 +96,12 @@
10496 static inline void tegra_gpio_writel(struct tegra_gpio_info *tgi,
10597 u32 val, u32 reg)
10698 {
107
- __raw_writel(val, tgi->regs + reg);
99
+ writel_relaxed(val, tgi->regs + reg);
108100 }
109101
110102 static inline u32 tegra_gpio_readl(struct tegra_gpio_info *tgi, u32 reg)
111103 {
112
- return __raw_readl(tgi->regs + reg);
104
+ return readl_relaxed(tgi->regs + reg);
113105 }
114106
115107 static unsigned int tegra_gpio_compose(unsigned int bank, unsigned int port,
....@@ -141,14 +133,14 @@
141133
142134 static int tegra_gpio_request(struct gpio_chip *chip, unsigned int offset)
143135 {
144
- return pinctrl_gpio_request(offset);
136
+ return pinctrl_gpio_request(chip->base + offset);
145137 }
146138
147139 static void tegra_gpio_free(struct gpio_chip *chip, unsigned int offset)
148140 {
149141 struct tegra_gpio_info *tgi = gpiochip_get_data(chip);
150142
151
- pinctrl_gpio_free(offset);
143
+ pinctrl_gpio_free(chip->base + offset);
152144 tegra_gpio_disable(tgi, offset);
153145 }
154146
....@@ -176,10 +168,18 @@
176168 unsigned int offset)
177169 {
178170 struct tegra_gpio_info *tgi = gpiochip_get_data(chip);
171
+ int ret;
179172
180173 tegra_gpio_mask_write(tgi, GPIO_MSK_OE(tgi, offset), offset, 0);
181174 tegra_gpio_enable(tgi, offset);
182
- return 0;
175
+
176
+ ret = pinctrl_gpio_direction_input(chip->base + offset);
177
+ if (ret < 0)
178
+ dev_err(tgi->dev,
179
+ "Failed to set pinctrl input direction of GPIO %d: %d",
180
+ chip->base + offset, ret);
181
+
182
+ return ret;
183183 }
184184
185185 static int tegra_gpio_direction_output(struct gpio_chip *chip,
....@@ -187,11 +187,19 @@
187187 int value)
188188 {
189189 struct tegra_gpio_info *tgi = gpiochip_get_data(chip);
190
+ int ret;
190191
191192 tegra_gpio_set(chip, offset, value);
192193 tegra_gpio_mask_write(tgi, GPIO_MSK_OE(tgi, offset), offset, 1);
193194 tegra_gpio_enable(tgi, offset);
194
- return 0;
195
+
196
+ ret = pinctrl_gpio_direction_output(chip->base + offset);
197
+ if (ret < 0)
198
+ dev_err(tgi->dev,
199
+ "Failed to set pinctrl output direction of GPIO %d: %d",
200
+ chip->base + offset, ret);
201
+
202
+ return ret;
195203 }
196204
197205 static int tegra_gpio_get_direction(struct gpio_chip *chip,
....@@ -207,7 +215,10 @@
207215
208216 oe = tegra_gpio_readl(tgi, GPIO_OE(tgi, offset));
209217
210
- return !(oe & pin_mask);
218
+ if (oe & pin_mask)
219
+ return GPIO_LINE_DIRECTION_OUT;
220
+
221
+ return GPIO_LINE_DIRECTION_IN;
211222 }
212223
213224 static int tegra_gpio_set_debounce(struct gpio_chip *chip, unsigned int offset,
....@@ -405,12 +416,8 @@
405416 #ifdef CONFIG_PM_SLEEP
406417 static int tegra_gpio_resume(struct device *dev)
407418 {
408
- struct platform_device *pdev = to_platform_device(dev);
409
- struct tegra_gpio_info *tgi = platform_get_drvdata(pdev);
410
- unsigned long flags;
419
+ struct tegra_gpio_info *tgi = dev_get_drvdata(dev);
411420 unsigned int b, p;
412
-
413
- local_irq_save(flags);
414421
415422 for (b = 0; b < tgi->bank_count; b++) {
416423 struct tegra_gpio_bank *bank = &tgi->bank_info[b];
....@@ -439,18 +446,14 @@
439446 }
440447 }
441448
442
- local_irq_restore(flags);
443449 return 0;
444450 }
445451
446452 static int tegra_gpio_suspend(struct device *dev)
447453 {
448
- struct platform_device *pdev = to_platform_device(dev);
449
- struct tegra_gpio_info *tgi = platform_get_drvdata(pdev);
450
- unsigned long flags;
454
+ struct tegra_gpio_info *tgi = dev_get_drvdata(dev);
451455 unsigned int b, p;
452456
453
- local_irq_save(flags);
454457 for (b = 0; b < tgi->bank_count; b++) {
455458 struct tegra_gpio_bank *bank = &tgi->bank_info[b];
456459
....@@ -480,7 +483,7 @@
480483 GPIO_INT_ENB(tgi, gpio));
481484 }
482485 }
483
- local_irq_restore(flags);
486
+
484487 return 0;
485488 }
486489
....@@ -489,6 +492,11 @@
489492 struct tegra_gpio_bank *bank = irq_data_get_irq_chip_data(d);
490493 unsigned int gpio = d->hwirq;
491494 u32 port, bit, mask;
495
+ int err;
496
+
497
+ err = irq_set_irq_wake(bank->irq, enable);
498
+ if (err)
499
+ return err;
492500
493501 port = GPIO_PORT(gpio);
494502 bit = GPIO_BIT(gpio);
....@@ -499,7 +507,7 @@
499507 else
500508 bank->wake_enb[port] &= ~mask;
501509
502
- return irq_set_irq_wake(bank->irq, enable);
510
+ return 0;
503511 }
504512 #endif
505513
....@@ -536,8 +544,8 @@
536544
537545 static void tegra_gpio_debuginit(struct tegra_gpio_info *tgi)
538546 {
539
- (void) debugfs_create_file("tegra_gpio", 0444,
540
- NULL, tgi, &tegra_dbg_gpio_fops);
547
+ debugfs_create_file("tegra_gpio", 0444, NULL, tgi,
548
+ &tegra_dbg_gpio_fops);
541549 }
542550
543551 #else
....@@ -549,13 +557,12 @@
549557 #endif
550558
551559 static const struct dev_pm_ops tegra_gpio_pm_ops = {
552
- SET_SYSTEM_SLEEP_PM_OPS(tegra_gpio_suspend, tegra_gpio_resume)
560
+ SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(tegra_gpio_suspend, tegra_gpio_resume)
553561 };
554562
555563 static int tegra_gpio_probe(struct platform_device *pdev)
556564 {
557565 struct tegra_gpio_info *tgi;
558
- struct resource *res;
559566 struct tegra_gpio_bank *bank;
560567 unsigned int gpio, i, j;
561568 int ret;
....@@ -620,10 +627,8 @@
620627
621628 for (i = 0; i < tgi->bank_count; i++) {
622629 ret = platform_get_irq(pdev, i);
623
- if (ret < 0) {
624
- dev_err(&pdev->dev, "Missing IRQ resource: %d\n", ret);
630
+ if (ret < 0)
625631 return ret;
626
- }
627632
628633 bank = &tgi->bank_info[i];
629634 bank->bank = i;
....@@ -631,8 +636,7 @@
631636 bank->tgi = tgi;
632637 }
633638
634
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
635
- tgi->regs = devm_ioremap_resource(&pdev->dev, res);
639
+ tgi->regs = devm_platform_ioremap_resource(pdev, 0);
636640 if (IS_ERR(tgi->regs))
637641 return PTR_ERR(tgi->regs);
638642