.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
---|
1 | 2 | /* |
---|
2 | 3 | * GPIO interface for Intel Poulsbo SCH |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (c) 2010 CompuLab Ltd |
---|
5 | 6 | * 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. |
---|
19 | 7 | */ |
---|
20 | 8 | |
---|
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> |
---|
22 | 13 | #include <linux/kernel.h> |
---|
23 | 14 | #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> |
---|
28 | 15 | #include <linux/pci_ids.h> |
---|
29 | | -#include <linux/gpio/driver.h> |
---|
| 16 | +#include <linux/platform_device.h> |
---|
30 | 17 | |
---|
31 | 18 | #define GEN 0x00 |
---|
32 | 19 | #define GIO 0x04 |
---|
.. | .. |
---|
36 | 23 | struct gpio_chip chip; |
---|
37 | 24 | spinlock_t lock; |
---|
38 | 25 | unsigned short iobase; |
---|
39 | | - unsigned short core_base; |
---|
40 | 26 | unsigned short resume_base; |
---|
41 | 27 | }; |
---|
42 | 28 | |
---|
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) |
---|
45 | 31 | { |
---|
46 | | - unsigned base = 0; |
---|
| 32 | + unsigned int base = 0; |
---|
47 | 33 | |
---|
48 | 34 | if (gpio >= sch->resume_base) { |
---|
49 | 35 | gpio -= sch->resume_base; |
---|
.. | .. |
---|
53 | 39 | return base + reg + gpio / 8; |
---|
54 | 40 | } |
---|
55 | 41 | |
---|
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) |
---|
57 | 43 | { |
---|
58 | 44 | if (gpio >= sch->resume_base) |
---|
59 | 45 | gpio -= sch->resume_base; |
---|
60 | 46 | return gpio % 8; |
---|
61 | 47 | } |
---|
62 | 48 | |
---|
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) |
---|
64 | 50 | { |
---|
65 | 51 | unsigned short offset, bit; |
---|
66 | 52 | u8 reg_val; |
---|
.. | .. |
---|
73 | 59 | return reg_val; |
---|
74 | 60 | } |
---|
75 | 61 | |
---|
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, |
---|
77 | 63 | int val) |
---|
78 | 64 | { |
---|
79 | 65 | unsigned short offset, bit; |
---|
.. | .. |
---|
90 | 76 | outb((reg_val & ~BIT(bit)), sch->iobase + offset); |
---|
91 | 77 | } |
---|
92 | 78 | |
---|
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) |
---|
94 | 80 | { |
---|
95 | 81 | struct sch_gpio *sch = gpiochip_get_data(gc); |
---|
96 | 82 | |
---|
.. | .. |
---|
100 | 86 | return 0; |
---|
101 | 87 | } |
---|
102 | 88 | |
---|
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) |
---|
104 | 90 | { |
---|
105 | 91 | struct sch_gpio *sch = gpiochip_get_data(gc); |
---|
| 92 | + |
---|
106 | 93 | return sch_gpio_reg_get(sch, gpio_num, GLV); |
---|
107 | 94 | } |
---|
108 | 95 | |
---|
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) |
---|
110 | 97 | { |
---|
111 | 98 | struct sch_gpio *sch = gpiochip_get_data(gc); |
---|
112 | 99 | |
---|
.. | .. |
---|
115 | 102 | spin_unlock(&sch->lock); |
---|
116 | 103 | } |
---|
117 | 104 | |
---|
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, |
---|
119 | 106 | int val) |
---|
120 | 107 | { |
---|
121 | 108 | struct sch_gpio *sch = gpiochip_get_data(gc); |
---|
.. | .. |
---|
137 | 124 | return 0; |
---|
138 | 125 | } |
---|
139 | 126 | |
---|
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) |
---|
141 | 128 | { |
---|
142 | 129 | struct sch_gpio *sch = gpiochip_get_data(gc); |
---|
143 | 130 | |
---|
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; |
---|
145 | 135 | } |
---|
146 | 136 | |
---|
147 | 137 | static const struct gpio_chip sch_gpio_chip = { |
---|
.. | .. |
---|
179 | 169 | |
---|
180 | 170 | switch (pdev->id) { |
---|
181 | 171 | case PCI_DEVICE_ID_INTEL_SCH_LPC: |
---|
182 | | - sch->core_base = 0; |
---|
183 | 172 | sch->resume_base = 10; |
---|
184 | 173 | sch->chip.ngpio = 14; |
---|
185 | 174 | |
---|
.. | .. |
---|
198 | 187 | break; |
---|
199 | 188 | |
---|
200 | 189 | case PCI_DEVICE_ID_INTEL_ITC_LPC: |
---|
201 | | - sch->core_base = 0; |
---|
202 | 190 | sch->resume_base = 5; |
---|
203 | 191 | sch->chip.ngpio = 14; |
---|
204 | 192 | break; |
---|
205 | 193 | |
---|
206 | 194 | case PCI_DEVICE_ID_INTEL_CENTERTON_ILB: |
---|
207 | | - sch->core_base = 0; |
---|
208 | 195 | sch->resume_base = 21; |
---|
209 | 196 | sch->chip.ngpio = 30; |
---|
210 | 197 | break; |
---|
211 | 198 | |
---|
212 | 199 | case PCI_DEVICE_ID_INTEL_QUARK_X1000_ILB: |
---|
213 | | - sch->core_base = 0; |
---|
214 | 200 | sch->resume_base = 2; |
---|
215 | 201 | sch->chip.ngpio = 8; |
---|
216 | 202 | break; |
---|
.. | .. |
---|
235 | 221 | |
---|
236 | 222 | MODULE_AUTHOR("Denis Turischev <denis@compulab.co.il>"); |
---|
237 | 223 | MODULE_DESCRIPTION("GPIO interface for Intel Poulsbo SCH"); |
---|
238 | | -MODULE_LICENSE("GPL"); |
---|
| 224 | +MODULE_LICENSE("GPL v2"); |
---|
239 | 225 | MODULE_ALIAS("platform:sch_gpio"); |
---|