hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/gpio/gpio-sch.c
....@@ -1,32 +1,19 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * GPIO interface for Intel Poulsbo SCH
34 *
45 * Copyright (c) 2010 CompuLab Ltd
56 * Author: Denis Turischev <denis@compulab.co.il>
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License 2 as published
9
- * by the Free Software Foundation.
10
- *
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with this program; see the file COPYING. If not, write to
18
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
197 */
208
21
-#include <linux/init.h>
9
+#include <linux/acpi.h>
10
+#include <linux/errno.h>
11
+#include <linux/gpio/driver.h>
12
+#include <linux/io.h>
2213 #include <linux/kernel.h>
2314 #include <linux/module.h>
24
-#include <linux/io.h>
25
-#include <linux/errno.h>
26
-#include <linux/acpi.h>
27
-#include <linux/platform_device.h>
2815 #include <linux/pci_ids.h>
29
-#include <linux/gpio/driver.h>
16
+#include <linux/platform_device.h>
3017
3118 #define GEN 0x00
3219 #define GIO 0x04
....@@ -36,14 +23,13 @@
3623 struct gpio_chip chip;
3724 spinlock_t lock;
3825 unsigned short iobase;
39
- unsigned short core_base;
4026 unsigned short resume_base;
4127 };
4228
43
-static unsigned sch_gpio_offset(struct sch_gpio *sch, unsigned gpio,
44
- unsigned reg)
29
+static unsigned int sch_gpio_offset(struct sch_gpio *sch, unsigned int gpio,
30
+ unsigned int reg)
4531 {
46
- unsigned base = 0;
32
+ unsigned int base = 0;
4733
4834 if (gpio >= sch->resume_base) {
4935 gpio -= sch->resume_base;
....@@ -53,14 +39,14 @@
5339 return base + reg + gpio / 8;
5440 }
5541
56
-static unsigned sch_gpio_bit(struct sch_gpio *sch, unsigned gpio)
42
+static unsigned int sch_gpio_bit(struct sch_gpio *sch, unsigned int gpio)
5743 {
5844 if (gpio >= sch->resume_base)
5945 gpio -= sch->resume_base;
6046 return gpio % 8;
6147 }
6248
63
-static int sch_gpio_reg_get(struct sch_gpio *sch, unsigned gpio, unsigned reg)
49
+static int sch_gpio_reg_get(struct sch_gpio *sch, unsigned int gpio, unsigned int reg)
6450 {
6551 unsigned short offset, bit;
6652 u8 reg_val;
....@@ -73,7 +59,7 @@
7359 return reg_val;
7460 }
7561
76
-static void sch_gpio_reg_set(struct sch_gpio *sch, unsigned gpio, unsigned reg,
62
+static void sch_gpio_reg_set(struct sch_gpio *sch, unsigned int gpio, unsigned int reg,
7763 int val)
7864 {
7965 unsigned short offset, bit;
....@@ -90,7 +76,7 @@
9076 outb((reg_val & ~BIT(bit)), sch->iobase + offset);
9177 }
9278
93
-static int sch_gpio_direction_in(struct gpio_chip *gc, unsigned gpio_num)
79
+static int sch_gpio_direction_in(struct gpio_chip *gc, unsigned int gpio_num)
9480 {
9581 struct sch_gpio *sch = gpiochip_get_data(gc);
9682
....@@ -100,13 +86,14 @@
10086 return 0;
10187 }
10288
103
-static int sch_gpio_get(struct gpio_chip *gc, unsigned gpio_num)
89
+static int sch_gpio_get(struct gpio_chip *gc, unsigned int gpio_num)
10490 {
10591 struct sch_gpio *sch = gpiochip_get_data(gc);
92
+
10693 return sch_gpio_reg_get(sch, gpio_num, GLV);
10794 }
10895
109
-static void sch_gpio_set(struct gpio_chip *gc, unsigned gpio_num, int val)
96
+static void sch_gpio_set(struct gpio_chip *gc, unsigned int gpio_num, int val)
11097 {
11198 struct sch_gpio *sch = gpiochip_get_data(gc);
11299
....@@ -115,7 +102,7 @@
115102 spin_unlock(&sch->lock);
116103 }
117104
118
-static int sch_gpio_direction_out(struct gpio_chip *gc, unsigned gpio_num,
105
+static int sch_gpio_direction_out(struct gpio_chip *gc, unsigned int gpio_num,
119106 int val)
120107 {
121108 struct sch_gpio *sch = gpiochip_get_data(gc);
....@@ -137,11 +124,14 @@
137124 return 0;
138125 }
139126
140
-static int sch_gpio_get_direction(struct gpio_chip *gc, unsigned gpio_num)
127
+static int sch_gpio_get_direction(struct gpio_chip *gc, unsigned int gpio_num)
141128 {
142129 struct sch_gpio *sch = gpiochip_get_data(gc);
143130
144
- return sch_gpio_reg_get(sch, gpio_num, GIO);
131
+ if (sch_gpio_reg_get(sch, gpio_num, GIO))
132
+ return GPIO_LINE_DIRECTION_IN;
133
+
134
+ return GPIO_LINE_DIRECTION_OUT;
145135 }
146136
147137 static const struct gpio_chip sch_gpio_chip = {
....@@ -179,7 +169,6 @@
179169
180170 switch (pdev->id) {
181171 case PCI_DEVICE_ID_INTEL_SCH_LPC:
182
- sch->core_base = 0;
183172 sch->resume_base = 10;
184173 sch->chip.ngpio = 14;
185174
....@@ -198,19 +187,16 @@
198187 break;
199188
200189 case PCI_DEVICE_ID_INTEL_ITC_LPC:
201
- sch->core_base = 0;
202190 sch->resume_base = 5;
203191 sch->chip.ngpio = 14;
204192 break;
205193
206194 case PCI_DEVICE_ID_INTEL_CENTERTON_ILB:
207
- sch->core_base = 0;
208195 sch->resume_base = 21;
209196 sch->chip.ngpio = 30;
210197 break;
211198
212199 case PCI_DEVICE_ID_INTEL_QUARK_X1000_ILB:
213
- sch->core_base = 0;
214200 sch->resume_base = 2;
215201 sch->chip.ngpio = 8;
216202 break;
....@@ -235,5 +221,5 @@
235221
236222 MODULE_AUTHOR("Denis Turischev <denis@compulab.co.il>");
237223 MODULE_DESCRIPTION("GPIO interface for Intel Poulsbo SCH");
238
-MODULE_LICENSE("GPL");
224
+MODULE_LICENSE("GPL v2");
239225 MODULE_ALIAS("platform:sch_gpio");