.. | .. |
---|
2 | 2 | /* |
---|
3 | 3 | * Cherryview/Braswell pinctrl driver |
---|
4 | 4 | * |
---|
5 | | - * Copyright (C) 2014, Intel Corporation |
---|
| 5 | + * Copyright (C) 2014, 2020 Intel Corporation |
---|
6 | 6 | * Author: Mika Westerberg <mika.westerberg@linux.intel.com> |
---|
7 | 7 | * |
---|
8 | 8 | * This driver is based on the original Cherryview GPIO driver by |
---|
.. | .. |
---|
10 | 10 | * Alan Cox <alan@linux.intel.com> |
---|
11 | 11 | */ |
---|
12 | 12 | |
---|
| 13 | +#include <linux/acpi.h> |
---|
13 | 14 | #include <linux/dmi.h> |
---|
| 15 | +#include <linux/gpio/driver.h> |
---|
14 | 16 | #include <linux/kernel.h> |
---|
15 | 17 | #include <linux/module.h> |
---|
16 | | -#include <linux/init.h> |
---|
| 18 | +#include <linux/platform_device.h> |
---|
17 | 19 | #include <linux/types.h> |
---|
18 | | -#include <linux/gpio.h> |
---|
19 | | -#include <linux/gpio/driver.h> |
---|
20 | | -#include <linux/acpi.h> |
---|
| 20 | + |
---|
21 | 21 | #include <linux/pinctrl/pinctrl.h> |
---|
22 | 22 | #include <linux/pinctrl/pinmux.h> |
---|
23 | 23 | #include <linux/pinctrl/pinconf.h> |
---|
24 | 24 | #include <linux/pinctrl/pinconf-generic.h> |
---|
25 | | -#include <linux/platform_device.h> |
---|
| 25 | + |
---|
| 26 | +#include "pinctrl-intel.h" |
---|
26 | 27 | |
---|
27 | 28 | #define CHV_INTSTAT 0x300 |
---|
28 | 29 | #define CHV_INTMASK 0x380 |
---|
.. | .. |
---|
34 | 35 | |
---|
35 | 36 | #define CHV_PADCTRL0 0x000 |
---|
36 | 37 | #define CHV_PADCTRL0_INTSEL_SHIFT 28 |
---|
37 | | -#define CHV_PADCTRL0_INTSEL_MASK (0xf << CHV_PADCTRL0_INTSEL_SHIFT) |
---|
| 38 | +#define CHV_PADCTRL0_INTSEL_MASK GENMASK(31, 28) |
---|
38 | 39 | #define CHV_PADCTRL0_TERM_UP BIT(23) |
---|
39 | 40 | #define CHV_PADCTRL0_TERM_SHIFT 20 |
---|
40 | | -#define CHV_PADCTRL0_TERM_MASK (7 << CHV_PADCTRL0_TERM_SHIFT) |
---|
| 41 | +#define CHV_PADCTRL0_TERM_MASK GENMASK(22, 20) |
---|
41 | 42 | #define CHV_PADCTRL0_TERM_20K 1 |
---|
42 | 43 | #define CHV_PADCTRL0_TERM_5K 2 |
---|
43 | 44 | #define CHV_PADCTRL0_TERM_1K 4 |
---|
44 | 45 | #define CHV_PADCTRL0_PMODE_SHIFT 16 |
---|
45 | | -#define CHV_PADCTRL0_PMODE_MASK (0xf << CHV_PADCTRL0_PMODE_SHIFT) |
---|
| 46 | +#define CHV_PADCTRL0_PMODE_MASK GENMASK(19, 16) |
---|
46 | 47 | #define CHV_PADCTRL0_GPIOEN BIT(15) |
---|
47 | 48 | #define CHV_PADCTRL0_GPIOCFG_SHIFT 8 |
---|
48 | | -#define CHV_PADCTRL0_GPIOCFG_MASK (7 << CHV_PADCTRL0_GPIOCFG_SHIFT) |
---|
| 49 | +#define CHV_PADCTRL0_GPIOCFG_MASK GENMASK(10, 8) |
---|
49 | 50 | #define CHV_PADCTRL0_GPIOCFG_GPIO 0 |
---|
50 | 51 | #define CHV_PADCTRL0_GPIOCFG_GPO 1 |
---|
51 | 52 | #define CHV_PADCTRL0_GPIOCFG_GPI 2 |
---|
.. | .. |
---|
56 | 57 | #define CHV_PADCTRL1 0x004 |
---|
57 | 58 | #define CHV_PADCTRL1_CFGLOCK BIT(31) |
---|
58 | 59 | #define CHV_PADCTRL1_INVRXTX_SHIFT 4 |
---|
59 | | -#define CHV_PADCTRL1_INVRXTX_MASK (0xf << CHV_PADCTRL1_INVRXTX_SHIFT) |
---|
60 | | -#define CHV_PADCTRL1_INVRXTX_TXENABLE (2 << CHV_PADCTRL1_INVRXTX_SHIFT) |
---|
| 60 | +#define CHV_PADCTRL1_INVRXTX_MASK GENMASK(7, 4) |
---|
| 61 | +#define CHV_PADCTRL1_INVRXTX_TXDATA BIT(7) |
---|
| 62 | +#define CHV_PADCTRL1_INVRXTX_RXDATA BIT(6) |
---|
| 63 | +#define CHV_PADCTRL1_INVRXTX_TXENABLE BIT(5) |
---|
61 | 64 | #define CHV_PADCTRL1_ODEN BIT(3) |
---|
62 | | -#define CHV_PADCTRL1_INVRXTX_RXDATA (4 << CHV_PADCTRL1_INVRXTX_SHIFT) |
---|
63 | | -#define CHV_PADCTRL1_INTWAKECFG_MASK 7 |
---|
| 65 | +#define CHV_PADCTRL1_INTWAKECFG_MASK GENMASK(2, 0) |
---|
64 | 66 | #define CHV_PADCTRL1_INTWAKECFG_FALLING 1 |
---|
65 | 67 | #define CHV_PADCTRL1_INTWAKECFG_RISING 2 |
---|
66 | 68 | #define CHV_PADCTRL1_INTWAKECFG_BOTH 3 |
---|
67 | 69 | #define CHV_PADCTRL1_INTWAKECFG_LEVEL 4 |
---|
68 | 70 | |
---|
69 | | -/** |
---|
70 | | - * struct chv_alternate_function - A per group or per pin alternate function |
---|
71 | | - * @pin: Pin number (only used in per pin configs) |
---|
72 | | - * @mode: Mode the pin should be set in |
---|
73 | | - * @invert_oe: Invert OE for this pin |
---|
74 | | - */ |
---|
75 | | -struct chv_alternate_function { |
---|
76 | | - unsigned pin; |
---|
77 | | - u8 mode; |
---|
78 | | - bool invert_oe; |
---|
79 | | -}; |
---|
80 | | - |
---|
81 | | -/** |
---|
82 | | - * struct chv_pincgroup - describes a CHV pin group |
---|
83 | | - * @name: Name of the group |
---|
84 | | - * @pins: An array of pins in this group |
---|
85 | | - * @npins: Number of pins in this group |
---|
86 | | - * @altfunc: Alternate function applied to all pins in this group |
---|
87 | | - * @overrides: Alternate function override per pin or %NULL if not used |
---|
88 | | - * @noverrides: Number of per pin alternate function overrides if |
---|
89 | | - * @overrides != NULL. |
---|
90 | | - */ |
---|
91 | | -struct chv_pingroup { |
---|
92 | | - const char *name; |
---|
93 | | - const unsigned *pins; |
---|
94 | | - size_t npins; |
---|
95 | | - struct chv_alternate_function altfunc; |
---|
96 | | - const struct chv_alternate_function *overrides; |
---|
97 | | - size_t noverrides; |
---|
98 | | -}; |
---|
99 | | - |
---|
100 | | -/** |
---|
101 | | - * struct chv_function - A CHV pinmux function |
---|
102 | | - * @name: Name of the function |
---|
103 | | - * @groups: An array of groups for this function |
---|
104 | | - * @ngroups: Number of groups in @groups |
---|
105 | | - */ |
---|
106 | | -struct chv_function { |
---|
107 | | - const char *name; |
---|
108 | | - const char * const *groups; |
---|
109 | | - size_t ngroups; |
---|
110 | | -}; |
---|
111 | | - |
---|
112 | | -/** |
---|
113 | | - * struct chv_gpio_pinrange - A range of pins that can be used as GPIOs |
---|
114 | | - * @base: Start pin number |
---|
115 | | - * @npins: Number of pins in this range |
---|
116 | | - */ |
---|
117 | | -struct chv_gpio_pinrange { |
---|
118 | | - unsigned base; |
---|
119 | | - unsigned npins; |
---|
120 | | -}; |
---|
121 | | - |
---|
122 | | -/** |
---|
123 | | - * struct chv_community - A community specific configuration |
---|
124 | | - * @uid: ACPI _UID used to match the community |
---|
125 | | - * @pins: All pins in this community |
---|
126 | | - * @npins: Number of pins |
---|
127 | | - * @groups: All groups in this community |
---|
128 | | - * @ngroups: Number of groups |
---|
129 | | - * @functions: All functions in this community |
---|
130 | | - * @nfunctions: Number of functions |
---|
131 | | - * @gpio_ranges: An array of GPIO ranges in this community |
---|
132 | | - * @ngpio_ranges: Number of GPIO ranges |
---|
133 | | - * @nirqs: Total number of IRQs this community can generate |
---|
134 | | - */ |
---|
135 | | -struct chv_community { |
---|
136 | | - const char *uid; |
---|
137 | | - const struct pinctrl_pin_desc *pins; |
---|
138 | | - size_t npins; |
---|
139 | | - const struct chv_pingroup *groups; |
---|
140 | | - size_t ngroups; |
---|
141 | | - const struct chv_function *functions; |
---|
142 | | - size_t nfunctions; |
---|
143 | | - const struct chv_gpio_pinrange *gpio_ranges; |
---|
144 | | - size_t ngpio_ranges; |
---|
145 | | - size_t nirqs; |
---|
146 | | - acpi_adr_space_type acpi_space_id; |
---|
147 | | -}; |
---|
148 | | - |
---|
149 | | -struct chv_pin_context { |
---|
| 71 | +struct intel_pad_context { |
---|
150 | 72 | u32 padctrl0; |
---|
151 | 73 | u32 padctrl1; |
---|
152 | 74 | }; |
---|
153 | 75 | |
---|
154 | 76 | /** |
---|
155 | | - * struct chv_pinctrl - CHV pinctrl private structure |
---|
156 | | - * @dev: Pointer to the parent device |
---|
157 | | - * @pctldesc: Pin controller description |
---|
158 | | - * @pctldev: Pointer to the pin controller device |
---|
159 | | - * @chip: GPIO chip in this pin controller |
---|
160 | | - * @irqchip: IRQ chip in this pin controller |
---|
161 | | - * @regs: MMIO registers |
---|
162 | | - * @intr_lines: Stores mapping between 16 HW interrupt wires and GPIO |
---|
163 | | - * offset (in GPIO number space) |
---|
164 | | - * @community: Community this pinctrl instance represents |
---|
165 | | - * |
---|
166 | | - * The first group in @groups is expected to contain all pins that can be |
---|
167 | | - * used as GPIOs. |
---|
| 77 | + * struct intel_community_context - community context for Cherryview |
---|
| 78 | + * @intr_lines: Mapping between 16 HW interrupt wires and GPIO offset (in GPIO number space) |
---|
| 79 | + * @saved_intmask: Interrupt mask saved for system sleep |
---|
168 | 80 | */ |
---|
169 | | -struct chv_pinctrl { |
---|
170 | | - struct device *dev; |
---|
171 | | - struct pinctrl_desc pctldesc; |
---|
172 | | - struct pinctrl_dev *pctldev; |
---|
173 | | - struct gpio_chip chip; |
---|
174 | | - struct irq_chip irqchip; |
---|
175 | | - void __iomem *regs; |
---|
176 | | - unsigned intr_lines[16]; |
---|
177 | | - const struct chv_community *community; |
---|
| 81 | +struct intel_community_context { |
---|
| 82 | + unsigned int intr_lines[16]; |
---|
178 | 83 | u32 saved_intmask; |
---|
179 | | - struct chv_pin_context *saved_pin_context; |
---|
180 | 84 | }; |
---|
181 | 85 | |
---|
182 | | -#define ALTERNATE_FUNCTION(p, m, i) \ |
---|
183 | | - { \ |
---|
184 | | - .pin = (p), \ |
---|
185 | | - .mode = (m), \ |
---|
186 | | - .invert_oe = (i), \ |
---|
187 | | - } |
---|
| 86 | +#define PINMODE_INVERT_OE BIT(15) |
---|
188 | 87 | |
---|
189 | | -#define PIN_GROUP(n, p, m, i) \ |
---|
190 | | - { \ |
---|
191 | | - .name = (n), \ |
---|
192 | | - .pins = (p), \ |
---|
193 | | - .npins = ARRAY_SIZE((p)), \ |
---|
194 | | - .altfunc.mode = (m), \ |
---|
195 | | - .altfunc.invert_oe = (i), \ |
---|
196 | | - } |
---|
| 88 | +#define PINMODE(m, i) ((m) | ((i) * PINMODE_INVERT_OE)) |
---|
197 | 89 | |
---|
198 | | -#define PIN_GROUP_WITH_OVERRIDE(n, p, m, i, o) \ |
---|
199 | | - { \ |
---|
200 | | - .name = (n), \ |
---|
201 | | - .pins = (p), \ |
---|
202 | | - .npins = ARRAY_SIZE((p)), \ |
---|
203 | | - .altfunc.mode = (m), \ |
---|
204 | | - .altfunc.invert_oe = (i), \ |
---|
205 | | - .overrides = (o), \ |
---|
206 | | - .noverrides = ARRAY_SIZE((o)), \ |
---|
207 | | - } |
---|
208 | | - |
---|
209 | | -#define FUNCTION(n, g) \ |
---|
210 | | - { \ |
---|
211 | | - .name = (n), \ |
---|
212 | | - .groups = (g), \ |
---|
213 | | - .ngroups = ARRAY_SIZE((g)), \ |
---|
214 | | - } |
---|
215 | | - |
---|
216 | | -#define GPIO_PINRANGE(start, end) \ |
---|
| 90 | +#define CHV_GPP(start, end) \ |
---|
217 | 91 | { \ |
---|
218 | 92 | .base = (start), \ |
---|
219 | | - .npins = (end) - (start) + 1, \ |
---|
| 93 | + .size = (end) - (start) + 1, \ |
---|
| 94 | + } |
---|
| 95 | + |
---|
| 96 | +#define CHV_COMMUNITY(g, i, a) \ |
---|
| 97 | + { \ |
---|
| 98 | + .gpps = (g), \ |
---|
| 99 | + .ngpps = ARRAY_SIZE(g), \ |
---|
| 100 | + .nirqs = (i), \ |
---|
| 101 | + .acpi_space_id = (a), \ |
---|
220 | 102 | } |
---|
221 | 103 | |
---|
222 | 104 | static const struct pinctrl_pin_desc southwest_pins[] = { |
---|
.. | .. |
---|
284 | 166 | PINCTRL_PIN(97, "GP_SSP_2_TXD"), |
---|
285 | 167 | }; |
---|
286 | 168 | |
---|
287 | | -static const unsigned southwest_fspi_pins[] = { 0, 1, 2, 3, 4, 5, 6, 7 }; |
---|
288 | 169 | static const unsigned southwest_uart0_pins[] = { 16, 20 }; |
---|
289 | 170 | static const unsigned southwest_uart1_pins[] = { 15, 16, 18, 20 }; |
---|
290 | 171 | static const unsigned southwest_uart2_pins[] = { 17, 19, 21, 22 }; |
---|
.. | .. |
---|
300 | 181 | static const unsigned southwest_i2c5_pins[] = { 45, 48 }; |
---|
301 | 182 | static const unsigned southwest_i2c6_pins[] = { 47, 51 }; |
---|
302 | 183 | static const unsigned southwest_i2c_nfc_pins[] = { 49, 52 }; |
---|
303 | | -static const unsigned southwest_smbus_pins[] = { 79, 81, 82 }; |
---|
304 | 184 | static const unsigned southwest_spi3_pins[] = { 76, 79, 80, 81, 82 }; |
---|
305 | 185 | |
---|
306 | | -/* LPE I2S TXD pins need to have invert_oe set */ |
---|
307 | | -static const struct chv_alternate_function southwest_lpe_altfuncs[] = { |
---|
308 | | - ALTERNATE_FUNCTION(30, 1, true), |
---|
309 | | - ALTERNATE_FUNCTION(34, 1, true), |
---|
310 | | - ALTERNATE_FUNCTION(97, 1, true), |
---|
| 186 | +/* Some of LPE I2S TXD pins need to have OE inversion set */ |
---|
| 187 | +static const unsigned int southwest_lpe_altfuncs[] = { |
---|
| 188 | + PINMODE(1, 1), PINMODE(1, 0), PINMODE(1, 0), PINMODE(1, 0), /* 30, 31, 32, 33 */ |
---|
| 189 | + PINMODE(1, 1), PINMODE(1, 0), PINMODE(1, 0), PINMODE(1, 0), /* 34, 35, 36, 37 */ |
---|
| 190 | + PINMODE(1, 0), PINMODE(1, 0), PINMODE(1, 0), PINMODE(1, 1), /* 92, 94, 96, 97 */ |
---|
311 | 191 | }; |
---|
312 | 192 | |
---|
313 | 193 | /* |
---|
314 | 194 | * Two spi3 chipselects are available in different mode than the main spi3 |
---|
315 | | - * functionality, which is using mode 1. |
---|
| 195 | + * functionality, which is using mode 2. |
---|
316 | 196 | */ |
---|
317 | | -static const struct chv_alternate_function southwest_spi3_altfuncs[] = { |
---|
318 | | - ALTERNATE_FUNCTION(76, 3, false), |
---|
319 | | - ALTERNATE_FUNCTION(80, 3, false), |
---|
| 197 | +static const unsigned int southwest_spi3_altfuncs[] = { |
---|
| 198 | + PINMODE(3, 0), PINMODE(2, 0), PINMODE(3, 0), PINMODE(2, 0), /* 76, 79, 80, 81 */ |
---|
| 199 | + PINMODE(2, 0), /* 82 */ |
---|
320 | 200 | }; |
---|
321 | 201 | |
---|
322 | | -static const struct chv_pingroup southwest_groups[] = { |
---|
323 | | - PIN_GROUP("uart0_grp", southwest_uart0_pins, 2, false), |
---|
324 | | - PIN_GROUP("uart1_grp", southwest_uart1_pins, 1, false), |
---|
325 | | - PIN_GROUP("uart2_grp", southwest_uart2_pins, 1, false), |
---|
326 | | - PIN_GROUP("hda_grp", southwest_hda_pins, 2, false), |
---|
327 | | - PIN_GROUP("i2c0_grp", southwest_i2c0_pins, 1, true), |
---|
328 | | - PIN_GROUP("i2c1_grp", southwest_i2c1_pins, 1, true), |
---|
329 | | - PIN_GROUP("i2c2_grp", southwest_i2c2_pins, 1, true), |
---|
330 | | - PIN_GROUP("i2c3_grp", southwest_i2c3_pins, 1, true), |
---|
331 | | - PIN_GROUP("i2c4_grp", southwest_i2c4_pins, 1, true), |
---|
332 | | - PIN_GROUP("i2c5_grp", southwest_i2c5_pins, 1, true), |
---|
333 | | - PIN_GROUP("i2c6_grp", southwest_i2c6_pins, 1, true), |
---|
334 | | - PIN_GROUP("i2c_nfc_grp", southwest_i2c_nfc_pins, 2, true), |
---|
335 | | - |
---|
336 | | - PIN_GROUP_WITH_OVERRIDE("lpe_grp", southwest_lpe_pins, 1, false, |
---|
337 | | - southwest_lpe_altfuncs), |
---|
338 | | - PIN_GROUP_WITH_OVERRIDE("spi3_grp", southwest_spi3_pins, 2, false, |
---|
339 | | - southwest_spi3_altfuncs), |
---|
| 202 | +static const struct intel_pingroup southwest_groups[] = { |
---|
| 203 | + PIN_GROUP("uart0_grp", southwest_uart0_pins, PINMODE(2, 0)), |
---|
| 204 | + PIN_GROUP("uart1_grp", southwest_uart1_pins, PINMODE(1, 0)), |
---|
| 205 | + PIN_GROUP("uart2_grp", southwest_uart2_pins, PINMODE(1, 0)), |
---|
| 206 | + PIN_GROUP("hda_grp", southwest_hda_pins, PINMODE(2, 0)), |
---|
| 207 | + PIN_GROUP("i2c0_grp", southwest_i2c0_pins, PINMODE(1, 1)), |
---|
| 208 | + PIN_GROUP("i2c1_grp", southwest_i2c1_pins, PINMODE(1, 1)), |
---|
| 209 | + PIN_GROUP("i2c2_grp", southwest_i2c2_pins, PINMODE(1, 1)), |
---|
| 210 | + PIN_GROUP("i2c3_grp", southwest_i2c3_pins, PINMODE(1, 1)), |
---|
| 211 | + PIN_GROUP("i2c4_grp", southwest_i2c4_pins, PINMODE(1, 1)), |
---|
| 212 | + PIN_GROUP("i2c5_grp", southwest_i2c5_pins, PINMODE(1, 1)), |
---|
| 213 | + PIN_GROUP("i2c6_grp", southwest_i2c6_pins, PINMODE(1, 1)), |
---|
| 214 | + PIN_GROUP("i2c_nfc_grp", southwest_i2c_nfc_pins, PINMODE(2, 1)), |
---|
| 215 | + PIN_GROUP("lpe_grp", southwest_lpe_pins, southwest_lpe_altfuncs), |
---|
| 216 | + PIN_GROUP("spi3_grp", southwest_spi3_pins, southwest_spi3_altfuncs), |
---|
340 | 217 | }; |
---|
341 | 218 | |
---|
342 | 219 | static const char * const southwest_uart0_groups[] = { "uart0_grp" }; |
---|
.. | .. |
---|
358 | 235 | * Only do pinmuxing for certain LPSS devices for now. Rest of the pins are |
---|
359 | 236 | * enabled only as GPIOs. |
---|
360 | 237 | */ |
---|
361 | | -static const struct chv_function southwest_functions[] = { |
---|
| 238 | +static const struct intel_function southwest_functions[] = { |
---|
362 | 239 | FUNCTION("uart0", southwest_uart0_groups), |
---|
363 | 240 | FUNCTION("uart1", southwest_uart1_groups), |
---|
364 | 241 | FUNCTION("uart2", southwest_uart2_groups), |
---|
.. | .. |
---|
375 | 252 | FUNCTION("spi3", southwest_spi3_groups), |
---|
376 | 253 | }; |
---|
377 | 254 | |
---|
378 | | -static const struct chv_gpio_pinrange southwest_gpio_ranges[] = { |
---|
379 | | - GPIO_PINRANGE(0, 7), |
---|
380 | | - GPIO_PINRANGE(15, 22), |
---|
381 | | - GPIO_PINRANGE(30, 37), |
---|
382 | | - GPIO_PINRANGE(45, 52), |
---|
383 | | - GPIO_PINRANGE(60, 67), |
---|
384 | | - GPIO_PINRANGE(75, 82), |
---|
385 | | - GPIO_PINRANGE(90, 97), |
---|
| 255 | +static const struct intel_padgroup southwest_gpps[] = { |
---|
| 256 | + CHV_GPP(0, 7), |
---|
| 257 | + CHV_GPP(15, 22), |
---|
| 258 | + CHV_GPP(30, 37), |
---|
| 259 | + CHV_GPP(45, 52), |
---|
| 260 | + CHV_GPP(60, 67), |
---|
| 261 | + CHV_GPP(75, 82), |
---|
| 262 | + CHV_GPP(90, 97), |
---|
386 | 263 | }; |
---|
387 | 264 | |
---|
388 | | -static const struct chv_community southwest_community = { |
---|
| 265 | +/* |
---|
| 266 | + * Southwest community can generate GPIO interrupts only for the first 8 |
---|
| 267 | + * interrupts. The upper half (8-15) can only be used to trigger GPEs. |
---|
| 268 | + */ |
---|
| 269 | +static const struct intel_community southwest_communities[] = { |
---|
| 270 | + CHV_COMMUNITY(southwest_gpps, 8, 0x91), |
---|
| 271 | +}; |
---|
| 272 | + |
---|
| 273 | +static const struct intel_pinctrl_soc_data southwest_soc_data = { |
---|
389 | 274 | .uid = "1", |
---|
390 | 275 | .pins = southwest_pins, |
---|
391 | 276 | .npins = ARRAY_SIZE(southwest_pins), |
---|
.. | .. |
---|
393 | 278 | .ngroups = ARRAY_SIZE(southwest_groups), |
---|
394 | 279 | .functions = southwest_functions, |
---|
395 | 280 | .nfunctions = ARRAY_SIZE(southwest_functions), |
---|
396 | | - .gpio_ranges = southwest_gpio_ranges, |
---|
397 | | - .ngpio_ranges = ARRAY_SIZE(southwest_gpio_ranges), |
---|
398 | | - /* |
---|
399 | | - * Southwest community can benerate GPIO interrupts only for the |
---|
400 | | - * first 8 interrupts. The upper half (8-15) can only be used to |
---|
401 | | - * trigger GPEs. |
---|
402 | | - */ |
---|
403 | | - .nirqs = 8, |
---|
404 | | - .acpi_space_id = 0x91, |
---|
| 281 | + .communities = southwest_communities, |
---|
| 282 | + .ncommunities = ARRAY_SIZE(southwest_communities), |
---|
405 | 283 | }; |
---|
406 | 284 | |
---|
407 | 285 | static const struct pinctrl_pin_desc north_pins[] = { |
---|
.. | .. |
---|
470 | 348 | PINCTRL_PIN(72, "PANEL0_VDDEN"), |
---|
471 | 349 | }; |
---|
472 | 350 | |
---|
473 | | -static const struct chv_gpio_pinrange north_gpio_ranges[] = { |
---|
474 | | - GPIO_PINRANGE(0, 8), |
---|
475 | | - GPIO_PINRANGE(15, 27), |
---|
476 | | - GPIO_PINRANGE(30, 41), |
---|
477 | | - GPIO_PINRANGE(45, 56), |
---|
478 | | - GPIO_PINRANGE(60, 72), |
---|
| 351 | +static const struct intel_padgroup north_gpps[] = { |
---|
| 352 | + CHV_GPP(0, 8), |
---|
| 353 | + CHV_GPP(15, 27), |
---|
| 354 | + CHV_GPP(30, 41), |
---|
| 355 | + CHV_GPP(45, 56), |
---|
| 356 | + CHV_GPP(60, 72), |
---|
479 | 357 | }; |
---|
480 | 358 | |
---|
481 | | -static const struct chv_community north_community = { |
---|
| 359 | +/* |
---|
| 360 | + * North community can generate GPIO interrupts only for the first 8 |
---|
| 361 | + * interrupts. The upper half (8-15) can only be used to trigger GPEs. |
---|
| 362 | + */ |
---|
| 363 | +static const struct intel_community north_communities[] = { |
---|
| 364 | + CHV_COMMUNITY(north_gpps, 8, 0x92), |
---|
| 365 | +}; |
---|
| 366 | + |
---|
| 367 | +static const struct intel_pinctrl_soc_data north_soc_data = { |
---|
482 | 368 | .uid = "2", |
---|
483 | 369 | .pins = north_pins, |
---|
484 | 370 | .npins = ARRAY_SIZE(north_pins), |
---|
485 | | - .gpio_ranges = north_gpio_ranges, |
---|
486 | | - .ngpio_ranges = ARRAY_SIZE(north_gpio_ranges), |
---|
487 | | - /* |
---|
488 | | - * North community can generate GPIO interrupts only for the first |
---|
489 | | - * 8 interrupts. The upper half (8-15) can only be used to trigger |
---|
490 | | - * GPEs. |
---|
491 | | - */ |
---|
492 | | - .nirqs = 8, |
---|
493 | | - .acpi_space_id = 0x92, |
---|
| 371 | + .communities = north_communities, |
---|
| 372 | + .ncommunities = ARRAY_SIZE(north_communities), |
---|
494 | 373 | }; |
---|
495 | 374 | |
---|
496 | 375 | static const struct pinctrl_pin_desc east_pins[] = { |
---|
.. | .. |
---|
521 | 400 | PINCTRL_PIN(26, "MF_ISH_I2C1_SDA"), |
---|
522 | 401 | }; |
---|
523 | 402 | |
---|
524 | | -static const struct chv_gpio_pinrange east_gpio_ranges[] = { |
---|
525 | | - GPIO_PINRANGE(0, 11), |
---|
526 | | - GPIO_PINRANGE(15, 26), |
---|
| 403 | +static const struct intel_padgroup east_gpps[] = { |
---|
| 404 | + CHV_GPP(0, 11), |
---|
| 405 | + CHV_GPP(15, 26), |
---|
527 | 406 | }; |
---|
528 | 407 | |
---|
529 | | -static const struct chv_community east_community = { |
---|
| 408 | +static const struct intel_community east_communities[] = { |
---|
| 409 | + CHV_COMMUNITY(east_gpps, 16, 0x93), |
---|
| 410 | +}; |
---|
| 411 | + |
---|
| 412 | +static const struct intel_pinctrl_soc_data east_soc_data = { |
---|
530 | 413 | .uid = "3", |
---|
531 | 414 | .pins = east_pins, |
---|
532 | 415 | .npins = ARRAY_SIZE(east_pins), |
---|
533 | | - .gpio_ranges = east_gpio_ranges, |
---|
534 | | - .ngpio_ranges = ARRAY_SIZE(east_gpio_ranges), |
---|
535 | | - .nirqs = 16, |
---|
536 | | - .acpi_space_id = 0x93, |
---|
| 416 | + .communities = east_communities, |
---|
| 417 | + .ncommunities = ARRAY_SIZE(east_communities), |
---|
537 | 418 | }; |
---|
538 | 419 | |
---|
539 | 420 | static const struct pinctrl_pin_desc southeast_pins[] = { |
---|
.. | .. |
---|
611 | 492 | static const unsigned southeast_spi1_pins[] = { 60, 61, 62, 64, 66 }; |
---|
612 | 493 | static const unsigned southeast_spi2_pins[] = { 2, 3, 4, 6, 7 }; |
---|
613 | 494 | |
---|
614 | | -static const struct chv_pingroup southeast_groups[] = { |
---|
615 | | - PIN_GROUP("pwm0_grp", southeast_pwm0_pins, 1, false), |
---|
616 | | - PIN_GROUP("pwm1_grp", southeast_pwm1_pins, 1, false), |
---|
617 | | - PIN_GROUP("sdmmc1_grp", southeast_sdmmc1_pins, 1, false), |
---|
618 | | - PIN_GROUP("sdmmc2_grp", southeast_sdmmc2_pins, 1, false), |
---|
619 | | - PIN_GROUP("sdmmc3_grp", southeast_sdmmc3_pins, 1, false), |
---|
620 | | - PIN_GROUP("spi1_grp", southeast_spi1_pins, 1, false), |
---|
621 | | - PIN_GROUP("spi2_grp", southeast_spi2_pins, 4, false), |
---|
| 495 | +static const struct intel_pingroup southeast_groups[] = { |
---|
| 496 | + PIN_GROUP("pwm0_grp", southeast_pwm0_pins, PINMODE(1, 0)), |
---|
| 497 | + PIN_GROUP("pwm1_grp", southeast_pwm1_pins, PINMODE(1, 0)), |
---|
| 498 | + PIN_GROUP("sdmmc1_grp", southeast_sdmmc1_pins, PINMODE(1, 0)), |
---|
| 499 | + PIN_GROUP("sdmmc2_grp", southeast_sdmmc2_pins, PINMODE(1, 0)), |
---|
| 500 | + PIN_GROUP("sdmmc3_grp", southeast_sdmmc3_pins, PINMODE(1, 0)), |
---|
| 501 | + PIN_GROUP("spi1_grp", southeast_spi1_pins, PINMODE(1, 0)), |
---|
| 502 | + PIN_GROUP("spi2_grp", southeast_spi2_pins, PINMODE(4, 0)), |
---|
622 | 503 | }; |
---|
623 | 504 | |
---|
624 | 505 | static const char * const southeast_pwm0_groups[] = { "pwm0_grp" }; |
---|
.. | .. |
---|
629 | 510 | static const char * const southeast_spi1_groups[] = { "spi1_grp" }; |
---|
630 | 511 | static const char * const southeast_spi2_groups[] = { "spi2_grp" }; |
---|
631 | 512 | |
---|
632 | | -static const struct chv_function southeast_functions[] = { |
---|
| 513 | +static const struct intel_function southeast_functions[] = { |
---|
633 | 514 | FUNCTION("pwm0", southeast_pwm0_groups), |
---|
634 | 515 | FUNCTION("pwm1", southeast_pwm1_groups), |
---|
635 | 516 | FUNCTION("sdmmc1", southeast_sdmmc1_groups), |
---|
.. | .. |
---|
639 | 520 | FUNCTION("spi2", southeast_spi2_groups), |
---|
640 | 521 | }; |
---|
641 | 522 | |
---|
642 | | -static const struct chv_gpio_pinrange southeast_gpio_ranges[] = { |
---|
643 | | - GPIO_PINRANGE(0, 7), |
---|
644 | | - GPIO_PINRANGE(15, 26), |
---|
645 | | - GPIO_PINRANGE(30, 35), |
---|
646 | | - GPIO_PINRANGE(45, 52), |
---|
647 | | - GPIO_PINRANGE(60, 69), |
---|
648 | | - GPIO_PINRANGE(75, 85), |
---|
| 523 | +static const struct intel_padgroup southeast_gpps[] = { |
---|
| 524 | + CHV_GPP(0, 7), |
---|
| 525 | + CHV_GPP(15, 26), |
---|
| 526 | + CHV_GPP(30, 35), |
---|
| 527 | + CHV_GPP(45, 52), |
---|
| 528 | + CHV_GPP(60, 69), |
---|
| 529 | + CHV_GPP(75, 85), |
---|
649 | 530 | }; |
---|
650 | 531 | |
---|
651 | | -static const struct chv_community southeast_community = { |
---|
| 532 | +static const struct intel_community southeast_communities[] = { |
---|
| 533 | + CHV_COMMUNITY(southeast_gpps, 16, 0x94), |
---|
| 534 | +}; |
---|
| 535 | + |
---|
| 536 | +static const struct intel_pinctrl_soc_data southeast_soc_data = { |
---|
652 | 537 | .uid = "4", |
---|
653 | 538 | .pins = southeast_pins, |
---|
654 | 539 | .npins = ARRAY_SIZE(southeast_pins), |
---|
.. | .. |
---|
656 | 541 | .ngroups = ARRAY_SIZE(southeast_groups), |
---|
657 | 542 | .functions = southeast_functions, |
---|
658 | 543 | .nfunctions = ARRAY_SIZE(southeast_functions), |
---|
659 | | - .gpio_ranges = southeast_gpio_ranges, |
---|
660 | | - .ngpio_ranges = ARRAY_SIZE(southeast_gpio_ranges), |
---|
661 | | - .nirqs = 16, |
---|
662 | | - .acpi_space_id = 0x94, |
---|
| 544 | + .communities = southeast_communities, |
---|
| 545 | + .ncommunities = ARRAY_SIZE(southeast_communities), |
---|
663 | 546 | }; |
---|
664 | 547 | |
---|
665 | | -static const struct chv_community *chv_communities[] = { |
---|
666 | | - &southwest_community, |
---|
667 | | - &north_community, |
---|
668 | | - &east_community, |
---|
669 | | - &southeast_community, |
---|
| 548 | +static const struct intel_pinctrl_soc_data *chv_soc_data[] = { |
---|
| 549 | + &southwest_soc_data, |
---|
| 550 | + &north_soc_data, |
---|
| 551 | + &east_soc_data, |
---|
| 552 | + &southeast_soc_data, |
---|
| 553 | + NULL |
---|
670 | 554 | }; |
---|
671 | 555 | |
---|
672 | 556 | /* |
---|
.. | .. |
---|
680 | 564 | */ |
---|
681 | 565 | static DEFINE_RAW_SPINLOCK(chv_lock); |
---|
682 | 566 | |
---|
683 | | -static void __iomem *chv_padreg(struct chv_pinctrl *pctrl, unsigned offset, |
---|
684 | | - unsigned reg) |
---|
| 567 | +static u32 chv_pctrl_readl(struct intel_pinctrl *pctrl, unsigned int offset) |
---|
685 | 568 | { |
---|
686 | | - unsigned family_no = offset / MAX_FAMILY_PAD_GPIO_NO; |
---|
687 | | - unsigned pad_no = offset % MAX_FAMILY_PAD_GPIO_NO; |
---|
| 569 | + const struct intel_community *community = &pctrl->communities[0]; |
---|
688 | 570 | |
---|
689 | | - offset = FAMILY_PAD_REGS_OFF + FAMILY_PAD_REGS_SIZE * family_no + |
---|
690 | | - GPIO_REGS_SIZE * pad_no; |
---|
691 | | - |
---|
692 | | - return pctrl->regs + offset + reg; |
---|
| 571 | + return readl(community->regs + offset); |
---|
693 | 572 | } |
---|
694 | 573 | |
---|
695 | | -static void chv_writel(u32 value, void __iomem *reg) |
---|
| 574 | +static void chv_pctrl_writel(struct intel_pinctrl *pctrl, unsigned int offset, u32 value) |
---|
696 | 575 | { |
---|
| 576 | + const struct intel_community *community = &pctrl->communities[0]; |
---|
| 577 | + void __iomem *reg = community->regs + offset; |
---|
| 578 | + |
---|
| 579 | + /* Write and simple read back to confirm the bus transferring done */ |
---|
697 | 580 | writel(value, reg); |
---|
698 | | - /* simple readback to confirm the bus transferring done */ |
---|
| 581 | + readl(reg); |
---|
| 582 | +} |
---|
| 583 | + |
---|
| 584 | +static void __iomem *chv_padreg(struct intel_pinctrl *pctrl, unsigned int offset, |
---|
| 585 | + unsigned int reg) |
---|
| 586 | +{ |
---|
| 587 | + const struct intel_community *community = &pctrl->communities[0]; |
---|
| 588 | + unsigned int family_no = offset / MAX_FAMILY_PAD_GPIO_NO; |
---|
| 589 | + unsigned int pad_no = offset % MAX_FAMILY_PAD_GPIO_NO; |
---|
| 590 | + |
---|
| 591 | + offset = FAMILY_PAD_REGS_SIZE * family_no + GPIO_REGS_SIZE * pad_no; |
---|
| 592 | + |
---|
| 593 | + return community->pad_regs + offset + reg; |
---|
| 594 | +} |
---|
| 595 | + |
---|
| 596 | +static u32 chv_readl(struct intel_pinctrl *pctrl, unsigned int pin, unsigned int offset) |
---|
| 597 | +{ |
---|
| 598 | + return readl(chv_padreg(pctrl, pin, offset)); |
---|
| 599 | +} |
---|
| 600 | + |
---|
| 601 | +static void chv_writel(struct intel_pinctrl *pctrl, unsigned int pin, unsigned int offset, u32 value) |
---|
| 602 | +{ |
---|
| 603 | + void __iomem *reg = chv_padreg(pctrl, pin, offset); |
---|
| 604 | + |
---|
| 605 | + /* Write and simple read back to confirm the bus transferring done */ |
---|
| 606 | + writel(value, reg); |
---|
699 | 607 | readl(reg); |
---|
700 | 608 | } |
---|
701 | 609 | |
---|
702 | 610 | /* When Pad Cfg is locked, driver can only change GPIOTXState or GPIORXState */ |
---|
703 | | -static bool chv_pad_locked(struct chv_pinctrl *pctrl, unsigned offset) |
---|
| 611 | +static bool chv_pad_locked(struct intel_pinctrl *pctrl, unsigned int offset) |
---|
704 | 612 | { |
---|
705 | | - void __iomem *reg; |
---|
706 | | - |
---|
707 | | - reg = chv_padreg(pctrl, offset, CHV_PADCTRL1); |
---|
708 | | - return readl(reg) & CHV_PADCTRL1_CFGLOCK; |
---|
| 613 | + return chv_readl(pctrl, offset, CHV_PADCTRL1) & CHV_PADCTRL1_CFGLOCK; |
---|
709 | 614 | } |
---|
710 | 615 | |
---|
711 | 616 | static int chv_get_groups_count(struct pinctrl_dev *pctldev) |
---|
712 | 617 | { |
---|
713 | | - struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
---|
| 618 | + struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
---|
714 | 619 | |
---|
715 | | - return pctrl->community->ngroups; |
---|
| 620 | + return pctrl->soc->ngroups; |
---|
716 | 621 | } |
---|
717 | 622 | |
---|
718 | 623 | static const char *chv_get_group_name(struct pinctrl_dev *pctldev, |
---|
719 | | - unsigned group) |
---|
| 624 | + unsigned int group) |
---|
720 | 625 | { |
---|
721 | | - struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
---|
| 626 | + struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
---|
722 | 627 | |
---|
723 | | - return pctrl->community->groups[group].name; |
---|
| 628 | + return pctrl->soc->groups[group].name; |
---|
724 | 629 | } |
---|
725 | 630 | |
---|
726 | | -static int chv_get_group_pins(struct pinctrl_dev *pctldev, unsigned group, |
---|
727 | | - const unsigned **pins, unsigned *npins) |
---|
| 631 | +static int chv_get_group_pins(struct pinctrl_dev *pctldev, unsigned int group, |
---|
| 632 | + const unsigned int **pins, unsigned int *npins) |
---|
728 | 633 | { |
---|
729 | | - struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
---|
| 634 | + struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
---|
730 | 635 | |
---|
731 | | - *pins = pctrl->community->groups[group].pins; |
---|
732 | | - *npins = pctrl->community->groups[group].npins; |
---|
| 636 | + *pins = pctrl->soc->groups[group].pins; |
---|
| 637 | + *npins = pctrl->soc->groups[group].npins; |
---|
733 | 638 | return 0; |
---|
734 | 639 | } |
---|
735 | 640 | |
---|
736 | 641 | static void chv_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s, |
---|
737 | | - unsigned offset) |
---|
| 642 | + unsigned int offset) |
---|
738 | 643 | { |
---|
739 | | - struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
---|
| 644 | + struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
---|
740 | 645 | unsigned long flags; |
---|
741 | 646 | u32 ctrl0, ctrl1; |
---|
742 | 647 | bool locked; |
---|
743 | 648 | |
---|
744 | 649 | raw_spin_lock_irqsave(&chv_lock, flags); |
---|
745 | 650 | |
---|
746 | | - ctrl0 = readl(chv_padreg(pctrl, offset, CHV_PADCTRL0)); |
---|
747 | | - ctrl1 = readl(chv_padreg(pctrl, offset, CHV_PADCTRL1)); |
---|
| 651 | + ctrl0 = chv_readl(pctrl, offset, CHV_PADCTRL0); |
---|
| 652 | + ctrl1 = chv_readl(pctrl, offset, CHV_PADCTRL1); |
---|
748 | 653 | locked = chv_pad_locked(pctrl, offset); |
---|
749 | 654 | |
---|
750 | 655 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
---|
.. | .. |
---|
775 | 680 | |
---|
776 | 681 | static int chv_get_functions_count(struct pinctrl_dev *pctldev) |
---|
777 | 682 | { |
---|
778 | | - struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
---|
| 683 | + struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
---|
779 | 684 | |
---|
780 | | - return pctrl->community->nfunctions; |
---|
| 685 | + return pctrl->soc->nfunctions; |
---|
781 | 686 | } |
---|
782 | 687 | |
---|
783 | 688 | static const char *chv_get_function_name(struct pinctrl_dev *pctldev, |
---|
784 | | - unsigned function) |
---|
| 689 | + unsigned int function) |
---|
785 | 690 | { |
---|
786 | | - struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
---|
| 691 | + struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
---|
787 | 692 | |
---|
788 | | - return pctrl->community->functions[function].name; |
---|
| 693 | + return pctrl->soc->functions[function].name; |
---|
789 | 694 | } |
---|
790 | 695 | |
---|
791 | 696 | static int chv_get_function_groups(struct pinctrl_dev *pctldev, |
---|
792 | | - unsigned function, |
---|
| 697 | + unsigned int function, |
---|
793 | 698 | const char * const **groups, |
---|
794 | | - unsigned * const ngroups) |
---|
| 699 | + unsigned int * const ngroups) |
---|
795 | 700 | { |
---|
796 | | - struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
---|
| 701 | + struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
---|
797 | 702 | |
---|
798 | | - *groups = pctrl->community->functions[function].groups; |
---|
799 | | - *ngroups = pctrl->community->functions[function].ngroups; |
---|
| 703 | + *groups = pctrl->soc->functions[function].groups; |
---|
| 704 | + *ngroups = pctrl->soc->functions[function].ngroups; |
---|
800 | 705 | return 0; |
---|
801 | 706 | } |
---|
802 | 707 | |
---|
803 | | -static int chv_pinmux_set_mux(struct pinctrl_dev *pctldev, unsigned function, |
---|
804 | | - unsigned group) |
---|
| 708 | +static int chv_pinmux_set_mux(struct pinctrl_dev *pctldev, |
---|
| 709 | + unsigned int function, unsigned int group) |
---|
805 | 710 | { |
---|
806 | | - struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
---|
807 | | - const struct chv_pingroup *grp; |
---|
| 711 | + struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
---|
| 712 | + const struct intel_pingroup *grp; |
---|
808 | 713 | unsigned long flags; |
---|
809 | 714 | int i; |
---|
810 | 715 | |
---|
811 | | - grp = &pctrl->community->groups[group]; |
---|
| 716 | + grp = &pctrl->soc->groups[group]; |
---|
812 | 717 | |
---|
813 | 718 | raw_spin_lock_irqsave(&chv_lock, flags); |
---|
814 | 719 | |
---|
.. | .. |
---|
823 | 728 | } |
---|
824 | 729 | |
---|
825 | 730 | for (i = 0; i < grp->npins; i++) { |
---|
826 | | - const struct chv_alternate_function *altfunc = &grp->altfunc; |
---|
827 | 731 | int pin = grp->pins[i]; |
---|
828 | | - void __iomem *reg; |
---|
| 732 | + unsigned int mode; |
---|
| 733 | + bool invert_oe; |
---|
829 | 734 | u32 value; |
---|
830 | 735 | |
---|
831 | 736 | /* Check if there is pin-specific config */ |
---|
832 | | - if (grp->overrides) { |
---|
833 | | - int j; |
---|
| 737 | + if (grp->modes) |
---|
| 738 | + mode = grp->modes[i]; |
---|
| 739 | + else |
---|
| 740 | + mode = grp->mode; |
---|
834 | 741 | |
---|
835 | | - for (j = 0; j < grp->noverrides; j++) { |
---|
836 | | - if (grp->overrides[j].pin == pin) { |
---|
837 | | - altfunc = &grp->overrides[j]; |
---|
838 | | - break; |
---|
839 | | - } |
---|
840 | | - } |
---|
841 | | - } |
---|
| 742 | + /* Extract OE inversion */ |
---|
| 743 | + invert_oe = mode & PINMODE_INVERT_OE; |
---|
| 744 | + mode &= ~PINMODE_INVERT_OE; |
---|
842 | 745 | |
---|
843 | | - reg = chv_padreg(pctrl, pin, CHV_PADCTRL0); |
---|
844 | | - value = readl(reg); |
---|
| 746 | + value = chv_readl(pctrl, pin, CHV_PADCTRL0); |
---|
845 | 747 | /* Disable GPIO mode */ |
---|
846 | 748 | value &= ~CHV_PADCTRL0_GPIOEN; |
---|
847 | 749 | /* Set to desired mode */ |
---|
848 | 750 | value &= ~CHV_PADCTRL0_PMODE_MASK; |
---|
849 | | - value |= altfunc->mode << CHV_PADCTRL0_PMODE_SHIFT; |
---|
850 | | - chv_writel(value, reg); |
---|
| 751 | + value |= mode << CHV_PADCTRL0_PMODE_SHIFT; |
---|
| 752 | + chv_writel(pctrl, pin, CHV_PADCTRL0, value); |
---|
851 | 753 | |
---|
852 | 754 | /* Update for invert_oe */ |
---|
853 | | - reg = chv_padreg(pctrl, pin, CHV_PADCTRL1); |
---|
854 | | - value = readl(reg) & ~CHV_PADCTRL1_INVRXTX_MASK; |
---|
855 | | - if (altfunc->invert_oe) |
---|
| 755 | + value = chv_readl(pctrl, pin, CHV_PADCTRL1) & ~CHV_PADCTRL1_INVRXTX_MASK; |
---|
| 756 | + if (invert_oe) |
---|
856 | 757 | value |= CHV_PADCTRL1_INVRXTX_TXENABLE; |
---|
857 | | - chv_writel(value, reg); |
---|
| 758 | + chv_writel(pctrl, pin, CHV_PADCTRL1, value); |
---|
858 | 759 | |
---|
859 | 760 | dev_dbg(pctrl->dev, "configured pin %u mode %u OE %sinverted\n", |
---|
860 | | - pin, altfunc->mode, altfunc->invert_oe ? "" : "not "); |
---|
| 761 | + pin, mode, invert_oe ? "" : "not "); |
---|
861 | 762 | } |
---|
862 | 763 | |
---|
863 | 764 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
---|
.. | .. |
---|
865 | 766 | return 0; |
---|
866 | 767 | } |
---|
867 | 768 | |
---|
| 769 | +static void chv_gpio_clear_triggering(struct intel_pinctrl *pctrl, |
---|
| 770 | + unsigned int offset) |
---|
| 771 | +{ |
---|
| 772 | + u32 invrxtx_mask = CHV_PADCTRL1_INVRXTX_MASK; |
---|
| 773 | + u32 value; |
---|
| 774 | + |
---|
| 775 | + /* |
---|
| 776 | + * One some devices the GPIO should output the inverted value from what |
---|
| 777 | + * device-drivers / ACPI code expects (inverted external buffer?). The |
---|
| 778 | + * BIOS makes this work by setting the CHV_PADCTRL1_INVRXTX_TXDATA flag, |
---|
| 779 | + * preserve this flag if the pin is already setup as GPIO. |
---|
| 780 | + */ |
---|
| 781 | + value = chv_readl(pctrl, offset, CHV_PADCTRL0); |
---|
| 782 | + if (value & CHV_PADCTRL0_GPIOEN) |
---|
| 783 | + invrxtx_mask &= ~CHV_PADCTRL1_INVRXTX_TXDATA; |
---|
| 784 | + |
---|
| 785 | + value = chv_readl(pctrl, offset, CHV_PADCTRL1); |
---|
| 786 | + value &= ~CHV_PADCTRL1_INTWAKECFG_MASK; |
---|
| 787 | + value &= ~invrxtx_mask; |
---|
| 788 | + chv_writel(pctrl, offset, CHV_PADCTRL1, value); |
---|
| 789 | +} |
---|
| 790 | + |
---|
868 | 791 | static int chv_gpio_request_enable(struct pinctrl_dev *pctldev, |
---|
869 | 792 | struct pinctrl_gpio_range *range, |
---|
870 | | - unsigned offset) |
---|
| 793 | + unsigned int offset) |
---|
871 | 794 | { |
---|
872 | | - struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
---|
| 795 | + struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
---|
873 | 796 | unsigned long flags; |
---|
874 | | - void __iomem *reg; |
---|
875 | 797 | u32 value; |
---|
876 | 798 | |
---|
877 | 799 | raw_spin_lock_irqsave(&chv_lock, flags); |
---|
878 | 800 | |
---|
879 | 801 | if (chv_pad_locked(pctrl, offset)) { |
---|
880 | | - value = readl(chv_padreg(pctrl, offset, CHV_PADCTRL0)); |
---|
| 802 | + value = chv_readl(pctrl, offset, CHV_PADCTRL0); |
---|
881 | 803 | if (!(value & CHV_PADCTRL0_GPIOEN)) { |
---|
882 | 804 | /* Locked so cannot enable */ |
---|
883 | 805 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
---|
884 | 806 | return -EBUSY; |
---|
885 | 807 | } |
---|
886 | 808 | } else { |
---|
| 809 | + struct intel_community_context *cctx = &pctrl->context.communities[0]; |
---|
887 | 810 | int i; |
---|
888 | 811 | |
---|
889 | 812 | /* Reset the interrupt mapping */ |
---|
890 | | - for (i = 0; i < ARRAY_SIZE(pctrl->intr_lines); i++) { |
---|
891 | | - if (pctrl->intr_lines[i] == offset) { |
---|
892 | | - pctrl->intr_lines[i] = 0; |
---|
| 813 | + for (i = 0; i < ARRAY_SIZE(cctx->intr_lines); i++) { |
---|
| 814 | + if (cctx->intr_lines[i] == offset) { |
---|
| 815 | + cctx->intr_lines[i] = 0; |
---|
893 | 816 | break; |
---|
894 | 817 | } |
---|
895 | 818 | } |
---|
896 | 819 | |
---|
897 | 820 | /* Disable interrupt generation */ |
---|
898 | | - reg = chv_padreg(pctrl, offset, CHV_PADCTRL1); |
---|
899 | | - value = readl(reg); |
---|
900 | | - value &= ~CHV_PADCTRL1_INTWAKECFG_MASK; |
---|
901 | | - value &= ~CHV_PADCTRL1_INVRXTX_MASK; |
---|
902 | | - chv_writel(value, reg); |
---|
| 821 | + chv_gpio_clear_triggering(pctrl, offset); |
---|
903 | 822 | |
---|
904 | | - reg = chv_padreg(pctrl, offset, CHV_PADCTRL0); |
---|
905 | | - value = readl(reg); |
---|
| 823 | + value = chv_readl(pctrl, offset, CHV_PADCTRL0); |
---|
906 | 824 | |
---|
907 | 825 | /* |
---|
908 | 826 | * If the pin is in HiZ mode (both TX and RX buffers are |
---|
.. | .. |
---|
911 | 829 | if ((value & CHV_PADCTRL0_GPIOCFG_MASK) == |
---|
912 | 830 | (CHV_PADCTRL0_GPIOCFG_HIZ << CHV_PADCTRL0_GPIOCFG_SHIFT)) { |
---|
913 | 831 | value &= ~CHV_PADCTRL0_GPIOCFG_MASK; |
---|
914 | | - value |= CHV_PADCTRL0_GPIOCFG_GPI << |
---|
915 | | - CHV_PADCTRL0_GPIOCFG_SHIFT; |
---|
| 832 | + value |= CHV_PADCTRL0_GPIOCFG_GPI << CHV_PADCTRL0_GPIOCFG_SHIFT; |
---|
916 | 833 | } |
---|
917 | 834 | |
---|
918 | 835 | /* Switch to a GPIO mode */ |
---|
919 | 836 | value |= CHV_PADCTRL0_GPIOEN; |
---|
920 | | - chv_writel(value, reg); |
---|
| 837 | + chv_writel(pctrl, offset, CHV_PADCTRL0, value); |
---|
921 | 838 | } |
---|
922 | 839 | |
---|
923 | 840 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
---|
.. | .. |
---|
927 | 844 | |
---|
928 | 845 | static void chv_gpio_disable_free(struct pinctrl_dev *pctldev, |
---|
929 | 846 | struct pinctrl_gpio_range *range, |
---|
930 | | - unsigned offset) |
---|
| 847 | + unsigned int offset) |
---|
931 | 848 | { |
---|
932 | | - struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
---|
| 849 | + struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
---|
933 | 850 | unsigned long flags; |
---|
934 | | - void __iomem *reg; |
---|
935 | | - u32 value; |
---|
936 | 851 | |
---|
937 | 852 | raw_spin_lock_irqsave(&chv_lock, flags); |
---|
938 | 853 | |
---|
939 | | - reg = chv_padreg(pctrl, offset, CHV_PADCTRL0); |
---|
940 | | - value = readl(reg) & ~CHV_PADCTRL0_GPIOEN; |
---|
941 | | - chv_writel(value, reg); |
---|
| 854 | + if (!chv_pad_locked(pctrl, offset)) |
---|
| 855 | + chv_gpio_clear_triggering(pctrl, offset); |
---|
942 | 856 | |
---|
943 | 857 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
---|
944 | 858 | } |
---|
945 | 859 | |
---|
946 | 860 | static int chv_gpio_set_direction(struct pinctrl_dev *pctldev, |
---|
947 | 861 | struct pinctrl_gpio_range *range, |
---|
948 | | - unsigned offset, bool input) |
---|
| 862 | + unsigned int offset, bool input) |
---|
949 | 863 | { |
---|
950 | | - struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
---|
951 | | - void __iomem *reg = chv_padreg(pctrl, offset, CHV_PADCTRL0); |
---|
| 864 | + struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
---|
952 | 865 | unsigned long flags; |
---|
953 | 866 | u32 ctrl0; |
---|
954 | 867 | |
---|
955 | 868 | raw_spin_lock_irqsave(&chv_lock, flags); |
---|
956 | 869 | |
---|
957 | | - ctrl0 = readl(reg) & ~CHV_PADCTRL0_GPIOCFG_MASK; |
---|
| 870 | + ctrl0 = chv_readl(pctrl, offset, CHV_PADCTRL0) & ~CHV_PADCTRL0_GPIOCFG_MASK; |
---|
958 | 871 | if (input) |
---|
959 | 872 | ctrl0 |= CHV_PADCTRL0_GPIOCFG_GPI << CHV_PADCTRL0_GPIOCFG_SHIFT; |
---|
960 | 873 | else |
---|
961 | 874 | ctrl0 |= CHV_PADCTRL0_GPIOCFG_GPO << CHV_PADCTRL0_GPIOCFG_SHIFT; |
---|
962 | | - chv_writel(ctrl0, reg); |
---|
| 875 | + chv_writel(pctrl, offset, CHV_PADCTRL0, ctrl0); |
---|
963 | 876 | |
---|
964 | 877 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
---|
965 | 878 | |
---|
.. | .. |
---|
976 | 889 | .gpio_set_direction = chv_gpio_set_direction, |
---|
977 | 890 | }; |
---|
978 | 891 | |
---|
979 | | -static int chv_config_get(struct pinctrl_dev *pctldev, unsigned pin, |
---|
| 892 | +static int chv_config_get(struct pinctrl_dev *pctldev, unsigned int pin, |
---|
980 | 893 | unsigned long *config) |
---|
981 | 894 | { |
---|
982 | | - struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
---|
| 895 | + struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
---|
983 | 896 | enum pin_config_param param = pinconf_to_config_param(*config); |
---|
984 | 897 | unsigned long flags; |
---|
985 | 898 | u32 ctrl0, ctrl1; |
---|
.. | .. |
---|
987 | 900 | u32 term; |
---|
988 | 901 | |
---|
989 | 902 | raw_spin_lock_irqsave(&chv_lock, flags); |
---|
990 | | - ctrl0 = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0)); |
---|
991 | | - ctrl1 = readl(chv_padreg(pctrl, pin, CHV_PADCTRL1)); |
---|
| 903 | + ctrl0 = chv_readl(pctrl, pin, CHV_PADCTRL0); |
---|
| 904 | + ctrl1 = chv_readl(pctrl, pin, CHV_PADCTRL1); |
---|
992 | 905 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
---|
993 | 906 | |
---|
994 | 907 | term = (ctrl0 & CHV_PADCTRL0_TERM_MASK) >> CHV_PADCTRL0_TERM_SHIFT; |
---|
.. | .. |
---|
1032 | 945 | |
---|
1033 | 946 | break; |
---|
1034 | 947 | |
---|
1035 | | - case PIN_CONFIG_DRIVE_OPEN_DRAIN: |
---|
1036 | | - if (!(ctrl1 & CHV_PADCTRL1_ODEN)) |
---|
1037 | | - return -EINVAL; |
---|
1038 | | - break; |
---|
1039 | | - |
---|
1040 | 948 | case PIN_CONFIG_BIAS_HIGH_IMPEDANCE: { |
---|
1041 | 949 | u32 cfg; |
---|
1042 | 950 | |
---|
.. | .. |
---|
1045 | 953 | if (cfg != CHV_PADCTRL0_GPIOCFG_HIZ) |
---|
1046 | 954 | return -EINVAL; |
---|
1047 | 955 | |
---|
| 956 | + break; |
---|
| 957 | + |
---|
| 958 | + case PIN_CONFIG_DRIVE_PUSH_PULL: |
---|
| 959 | + if (ctrl1 & CHV_PADCTRL1_ODEN) |
---|
| 960 | + return -EINVAL; |
---|
| 961 | + break; |
---|
| 962 | + |
---|
| 963 | + case PIN_CONFIG_DRIVE_OPEN_DRAIN: |
---|
| 964 | + if (!(ctrl1 & CHV_PADCTRL1_ODEN)) |
---|
| 965 | + return -EINVAL; |
---|
1048 | 966 | break; |
---|
1049 | 967 | } |
---|
1050 | 968 | |
---|
.. | .. |
---|
1056 | 974 | return 0; |
---|
1057 | 975 | } |
---|
1058 | 976 | |
---|
1059 | | -static int chv_config_set_pull(struct chv_pinctrl *pctrl, unsigned pin, |
---|
| 977 | +static int chv_config_set_pull(struct intel_pinctrl *pctrl, unsigned int pin, |
---|
1060 | 978 | enum pin_config_param param, u32 arg) |
---|
1061 | 979 | { |
---|
1062 | | - void __iomem *reg = chv_padreg(pctrl, pin, CHV_PADCTRL0); |
---|
1063 | 980 | unsigned long flags; |
---|
1064 | 981 | u32 ctrl0, pull; |
---|
1065 | 982 | |
---|
1066 | 983 | raw_spin_lock_irqsave(&chv_lock, flags); |
---|
1067 | | - ctrl0 = readl(reg); |
---|
| 984 | + ctrl0 = chv_readl(pctrl, pin, CHV_PADCTRL0); |
---|
1068 | 985 | |
---|
1069 | 986 | switch (param) { |
---|
1070 | 987 | case PIN_CONFIG_BIAS_DISABLE: |
---|
.. | .. |
---|
1116 | 1033 | return -EINVAL; |
---|
1117 | 1034 | } |
---|
1118 | 1035 | |
---|
1119 | | - chv_writel(ctrl0, reg); |
---|
| 1036 | + chv_writel(pctrl, pin, CHV_PADCTRL0, ctrl0); |
---|
1120 | 1037 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
---|
1121 | 1038 | |
---|
1122 | 1039 | return 0; |
---|
1123 | 1040 | } |
---|
1124 | 1041 | |
---|
1125 | | -static int chv_config_set_oden(struct chv_pinctrl *pctrl, unsigned int pin, |
---|
| 1042 | +static int chv_config_set_oden(struct intel_pinctrl *pctrl, unsigned int pin, |
---|
1126 | 1043 | bool enable) |
---|
1127 | 1044 | { |
---|
1128 | | - void __iomem *reg = chv_padreg(pctrl, pin, CHV_PADCTRL1); |
---|
1129 | 1045 | unsigned long flags; |
---|
1130 | 1046 | u32 ctrl1; |
---|
1131 | 1047 | |
---|
1132 | 1048 | raw_spin_lock_irqsave(&chv_lock, flags); |
---|
1133 | | - ctrl1 = readl(reg); |
---|
| 1049 | + ctrl1 = chv_readl(pctrl, pin, CHV_PADCTRL1); |
---|
1134 | 1050 | |
---|
1135 | 1051 | if (enable) |
---|
1136 | 1052 | ctrl1 |= CHV_PADCTRL1_ODEN; |
---|
1137 | 1053 | else |
---|
1138 | 1054 | ctrl1 &= ~CHV_PADCTRL1_ODEN; |
---|
1139 | 1055 | |
---|
1140 | | - chv_writel(ctrl1, reg); |
---|
| 1056 | + chv_writel(pctrl, pin, CHV_PADCTRL1, ctrl1); |
---|
1141 | 1057 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
---|
1142 | 1058 | |
---|
1143 | 1059 | return 0; |
---|
1144 | 1060 | } |
---|
1145 | 1061 | |
---|
1146 | | -static int chv_config_set(struct pinctrl_dev *pctldev, unsigned pin, |
---|
1147 | | - unsigned long *configs, unsigned nconfigs) |
---|
| 1062 | +static int chv_config_set(struct pinctrl_dev *pctldev, unsigned int pin, |
---|
| 1063 | + unsigned long *configs, unsigned int nconfigs) |
---|
1148 | 1064 | { |
---|
1149 | | - struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
---|
| 1065 | + struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
---|
1150 | 1066 | enum pin_config_param param; |
---|
1151 | 1067 | int i, ret; |
---|
1152 | 1068 | u32 arg; |
---|
.. | .. |
---|
1245 | 1161 | .owner = THIS_MODULE, |
---|
1246 | 1162 | }; |
---|
1247 | 1163 | |
---|
1248 | | -static int chv_gpio_get(struct gpio_chip *chip, unsigned offset) |
---|
| 1164 | +static int chv_gpio_get(struct gpio_chip *chip, unsigned int offset) |
---|
1249 | 1165 | { |
---|
1250 | | - struct chv_pinctrl *pctrl = gpiochip_get_data(chip); |
---|
| 1166 | + struct intel_pinctrl *pctrl = gpiochip_get_data(chip); |
---|
1251 | 1167 | unsigned long flags; |
---|
1252 | 1168 | u32 ctrl0, cfg; |
---|
1253 | 1169 | |
---|
1254 | 1170 | raw_spin_lock_irqsave(&chv_lock, flags); |
---|
1255 | | - ctrl0 = readl(chv_padreg(pctrl, offset, CHV_PADCTRL0)); |
---|
| 1171 | + ctrl0 = chv_readl(pctrl, offset, CHV_PADCTRL0); |
---|
1256 | 1172 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
---|
1257 | 1173 | |
---|
1258 | 1174 | cfg = ctrl0 & CHV_PADCTRL0_GPIOCFG_MASK; |
---|
.. | .. |
---|
1263 | 1179 | return !!(ctrl0 & CHV_PADCTRL0_GPIORXSTATE); |
---|
1264 | 1180 | } |
---|
1265 | 1181 | |
---|
1266 | | -static void chv_gpio_set(struct gpio_chip *chip, unsigned offset, int value) |
---|
| 1182 | +static void chv_gpio_set(struct gpio_chip *chip, unsigned int offset, int value) |
---|
1267 | 1183 | { |
---|
1268 | | - struct chv_pinctrl *pctrl = gpiochip_get_data(chip); |
---|
| 1184 | + struct intel_pinctrl *pctrl = gpiochip_get_data(chip); |
---|
1269 | 1185 | unsigned long flags; |
---|
1270 | | - void __iomem *reg; |
---|
1271 | 1186 | u32 ctrl0; |
---|
1272 | 1187 | |
---|
1273 | 1188 | raw_spin_lock_irqsave(&chv_lock, flags); |
---|
1274 | 1189 | |
---|
1275 | | - reg = chv_padreg(pctrl, offset, CHV_PADCTRL0); |
---|
1276 | | - ctrl0 = readl(reg); |
---|
| 1190 | + ctrl0 = chv_readl(pctrl, offset, CHV_PADCTRL0); |
---|
1277 | 1191 | |
---|
1278 | 1192 | if (value) |
---|
1279 | 1193 | ctrl0 |= CHV_PADCTRL0_GPIOTXSTATE; |
---|
1280 | 1194 | else |
---|
1281 | 1195 | ctrl0 &= ~CHV_PADCTRL0_GPIOTXSTATE; |
---|
1282 | 1196 | |
---|
1283 | | - chv_writel(ctrl0, reg); |
---|
| 1197 | + chv_writel(pctrl, offset, CHV_PADCTRL0, ctrl0); |
---|
1284 | 1198 | |
---|
1285 | 1199 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
---|
1286 | 1200 | } |
---|
1287 | 1201 | |
---|
1288 | | -static int chv_gpio_get_direction(struct gpio_chip *chip, unsigned offset) |
---|
| 1202 | +static int chv_gpio_get_direction(struct gpio_chip *chip, unsigned int offset) |
---|
1289 | 1203 | { |
---|
1290 | | - struct chv_pinctrl *pctrl = gpiochip_get_data(chip); |
---|
| 1204 | + struct intel_pinctrl *pctrl = gpiochip_get_data(chip); |
---|
1291 | 1205 | u32 ctrl0, direction; |
---|
1292 | 1206 | unsigned long flags; |
---|
1293 | 1207 | |
---|
1294 | 1208 | raw_spin_lock_irqsave(&chv_lock, flags); |
---|
1295 | | - ctrl0 = readl(chv_padreg(pctrl, offset, CHV_PADCTRL0)); |
---|
| 1209 | + ctrl0 = chv_readl(pctrl, offset, CHV_PADCTRL0); |
---|
1296 | 1210 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
---|
1297 | 1211 | |
---|
1298 | 1212 | direction = ctrl0 & CHV_PADCTRL0_GPIOCFG_MASK; |
---|
1299 | 1213 | direction >>= CHV_PADCTRL0_GPIOCFG_SHIFT; |
---|
1300 | 1214 | |
---|
1301 | | - return direction != CHV_PADCTRL0_GPIOCFG_GPO; |
---|
| 1215 | + if (direction == CHV_PADCTRL0_GPIOCFG_GPO) |
---|
| 1216 | + return GPIO_LINE_DIRECTION_OUT; |
---|
| 1217 | + |
---|
| 1218 | + return GPIO_LINE_DIRECTION_IN; |
---|
1302 | 1219 | } |
---|
1303 | 1220 | |
---|
1304 | | -static int chv_gpio_direction_input(struct gpio_chip *chip, unsigned offset) |
---|
| 1221 | +static int chv_gpio_direction_input(struct gpio_chip *chip, unsigned int offset) |
---|
1305 | 1222 | { |
---|
1306 | 1223 | return pinctrl_gpio_direction_input(chip->base + offset); |
---|
1307 | 1224 | } |
---|
1308 | 1225 | |
---|
1309 | | -static int chv_gpio_direction_output(struct gpio_chip *chip, unsigned offset, |
---|
| 1226 | +static int chv_gpio_direction_output(struct gpio_chip *chip, unsigned int offset, |
---|
1310 | 1227 | int value) |
---|
1311 | 1228 | { |
---|
1312 | 1229 | chv_gpio_set(chip, offset, value); |
---|
.. | .. |
---|
1327 | 1244 | static void chv_gpio_irq_ack(struct irq_data *d) |
---|
1328 | 1245 | { |
---|
1329 | 1246 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
---|
1330 | | - struct chv_pinctrl *pctrl = gpiochip_get_data(gc); |
---|
| 1247 | + struct intel_pinctrl *pctrl = gpiochip_get_data(gc); |
---|
1331 | 1248 | int pin = irqd_to_hwirq(d); |
---|
1332 | 1249 | u32 intr_line; |
---|
1333 | 1250 | |
---|
1334 | 1251 | raw_spin_lock(&chv_lock); |
---|
1335 | 1252 | |
---|
1336 | | - intr_line = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0)); |
---|
| 1253 | + intr_line = chv_readl(pctrl, pin, CHV_PADCTRL0); |
---|
1337 | 1254 | intr_line &= CHV_PADCTRL0_INTSEL_MASK; |
---|
1338 | 1255 | intr_line >>= CHV_PADCTRL0_INTSEL_SHIFT; |
---|
1339 | | - chv_writel(BIT(intr_line), pctrl->regs + CHV_INTSTAT); |
---|
| 1256 | + chv_pctrl_writel(pctrl, CHV_INTSTAT, BIT(intr_line)); |
---|
1340 | 1257 | |
---|
1341 | 1258 | raw_spin_unlock(&chv_lock); |
---|
1342 | 1259 | } |
---|
.. | .. |
---|
1344 | 1261 | static void chv_gpio_irq_mask_unmask(struct irq_data *d, bool mask) |
---|
1345 | 1262 | { |
---|
1346 | 1263 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
---|
1347 | | - struct chv_pinctrl *pctrl = gpiochip_get_data(gc); |
---|
| 1264 | + struct intel_pinctrl *pctrl = gpiochip_get_data(gc); |
---|
1348 | 1265 | int pin = irqd_to_hwirq(d); |
---|
1349 | 1266 | u32 value, intr_line; |
---|
1350 | 1267 | unsigned long flags; |
---|
1351 | 1268 | |
---|
1352 | 1269 | raw_spin_lock_irqsave(&chv_lock, flags); |
---|
1353 | 1270 | |
---|
1354 | | - intr_line = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0)); |
---|
| 1271 | + intr_line = chv_readl(pctrl, pin, CHV_PADCTRL0); |
---|
1355 | 1272 | intr_line &= CHV_PADCTRL0_INTSEL_MASK; |
---|
1356 | 1273 | intr_line >>= CHV_PADCTRL0_INTSEL_SHIFT; |
---|
1357 | 1274 | |
---|
1358 | | - value = readl(pctrl->regs + CHV_INTMASK); |
---|
| 1275 | + value = chv_pctrl_readl(pctrl, CHV_INTMASK); |
---|
1359 | 1276 | if (mask) |
---|
1360 | 1277 | value &= ~BIT(intr_line); |
---|
1361 | 1278 | else |
---|
1362 | 1279 | value |= BIT(intr_line); |
---|
1363 | | - chv_writel(value, pctrl->regs + CHV_INTMASK); |
---|
| 1280 | + chv_pctrl_writel(pctrl, CHV_INTMASK, value); |
---|
1364 | 1281 | |
---|
1365 | 1282 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
---|
1366 | 1283 | } |
---|
.. | .. |
---|
1389 | 1306 | */ |
---|
1390 | 1307 | if (irqd_get_trigger_type(d) == IRQ_TYPE_NONE) { |
---|
1391 | 1308 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
---|
1392 | | - struct chv_pinctrl *pctrl = gpiochip_get_data(gc); |
---|
1393 | | - unsigned pin = irqd_to_hwirq(d); |
---|
| 1309 | + struct intel_pinctrl *pctrl = gpiochip_get_data(gc); |
---|
| 1310 | + struct intel_community_context *cctx = &pctrl->context.communities[0]; |
---|
| 1311 | + unsigned int pin = irqd_to_hwirq(d); |
---|
1394 | 1312 | irq_flow_handler_t handler; |
---|
1395 | 1313 | unsigned long flags; |
---|
1396 | 1314 | u32 intsel, value; |
---|
1397 | 1315 | |
---|
1398 | 1316 | raw_spin_lock_irqsave(&chv_lock, flags); |
---|
1399 | | - intsel = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0)); |
---|
| 1317 | + intsel = chv_readl(pctrl, pin, CHV_PADCTRL0); |
---|
1400 | 1318 | intsel &= CHV_PADCTRL0_INTSEL_MASK; |
---|
1401 | 1319 | intsel >>= CHV_PADCTRL0_INTSEL_SHIFT; |
---|
1402 | 1320 | |
---|
1403 | | - value = readl(chv_padreg(pctrl, pin, CHV_PADCTRL1)); |
---|
| 1321 | + value = chv_readl(pctrl, pin, CHV_PADCTRL1); |
---|
1404 | 1322 | if (value & CHV_PADCTRL1_INTWAKECFG_LEVEL) |
---|
1405 | 1323 | handler = handle_level_irq; |
---|
1406 | 1324 | else |
---|
1407 | 1325 | handler = handle_edge_irq; |
---|
1408 | 1326 | |
---|
1409 | | - if (!pctrl->intr_lines[intsel]) { |
---|
| 1327 | + if (!cctx->intr_lines[intsel]) { |
---|
1410 | 1328 | irq_set_handler_locked(d, handler); |
---|
1411 | | - pctrl->intr_lines[intsel] = pin; |
---|
| 1329 | + cctx->intr_lines[intsel] = pin; |
---|
1412 | 1330 | } |
---|
1413 | 1331 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
---|
1414 | 1332 | } |
---|
.. | .. |
---|
1417 | 1335 | return 0; |
---|
1418 | 1336 | } |
---|
1419 | 1337 | |
---|
1420 | | -static int chv_gpio_irq_type(struct irq_data *d, unsigned type) |
---|
| 1338 | +static int chv_gpio_irq_type(struct irq_data *d, unsigned int type) |
---|
1421 | 1339 | { |
---|
1422 | 1340 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
---|
1423 | | - struct chv_pinctrl *pctrl = gpiochip_get_data(gc); |
---|
1424 | | - unsigned pin = irqd_to_hwirq(d); |
---|
| 1341 | + struct intel_pinctrl *pctrl = gpiochip_get_data(gc); |
---|
| 1342 | + struct intel_community_context *cctx = &pctrl->context.communities[0]; |
---|
| 1343 | + unsigned int pin = irqd_to_hwirq(d); |
---|
1425 | 1344 | unsigned long flags; |
---|
1426 | 1345 | u32 value; |
---|
1427 | 1346 | |
---|
.. | .. |
---|
1441 | 1360 | * Driver programs the IntWakeCfg bits and save the mapping. |
---|
1442 | 1361 | */ |
---|
1443 | 1362 | if (!chv_pad_locked(pctrl, pin)) { |
---|
1444 | | - void __iomem *reg = chv_padreg(pctrl, pin, CHV_PADCTRL1); |
---|
1445 | | - |
---|
1446 | | - value = readl(reg); |
---|
| 1363 | + value = chv_readl(pctrl, pin, CHV_PADCTRL1); |
---|
1447 | 1364 | value &= ~CHV_PADCTRL1_INTWAKECFG_MASK; |
---|
1448 | 1365 | value &= ~CHV_PADCTRL1_INVRXTX_MASK; |
---|
1449 | 1366 | |
---|
.. | .. |
---|
1460 | 1377 | value |= CHV_PADCTRL1_INVRXTX_RXDATA; |
---|
1461 | 1378 | } |
---|
1462 | 1379 | |
---|
1463 | | - chv_writel(value, reg); |
---|
| 1380 | + chv_writel(pctrl, pin, CHV_PADCTRL1, value); |
---|
1464 | 1381 | } |
---|
1465 | 1382 | |
---|
1466 | | - value = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0)); |
---|
| 1383 | + value = chv_readl(pctrl, pin, CHV_PADCTRL0); |
---|
1467 | 1384 | value &= CHV_PADCTRL0_INTSEL_MASK; |
---|
1468 | 1385 | value >>= CHV_PADCTRL0_INTSEL_SHIFT; |
---|
1469 | 1386 | |
---|
1470 | | - pctrl->intr_lines[value] = pin; |
---|
| 1387 | + cctx->intr_lines[value] = pin; |
---|
1471 | 1388 | |
---|
1472 | 1389 | if (type & IRQ_TYPE_EDGE_BOTH) |
---|
1473 | 1390 | irq_set_handler_locked(d, handle_edge_irq); |
---|
.. | .. |
---|
1482 | 1399 | static void chv_gpio_irq_handler(struct irq_desc *desc) |
---|
1483 | 1400 | { |
---|
1484 | 1401 | struct gpio_chip *gc = irq_desc_get_handler_data(desc); |
---|
1485 | | - struct chv_pinctrl *pctrl = gpiochip_get_data(gc); |
---|
| 1402 | + struct intel_pinctrl *pctrl = gpiochip_get_data(gc); |
---|
| 1403 | + const struct intel_community *community = &pctrl->communities[0]; |
---|
| 1404 | + struct intel_community_context *cctx = &pctrl->context.communities[0]; |
---|
1486 | 1405 | struct irq_chip *chip = irq_desc_get_chip(desc); |
---|
1487 | 1406 | unsigned long pending; |
---|
1488 | 1407 | unsigned long flags; |
---|
.. | .. |
---|
1491 | 1410 | chained_irq_enter(chip, desc); |
---|
1492 | 1411 | |
---|
1493 | 1412 | raw_spin_lock_irqsave(&chv_lock, flags); |
---|
1494 | | - pending = readl(pctrl->regs + CHV_INTSTAT); |
---|
| 1413 | + pending = chv_pctrl_readl(pctrl, CHV_INTSTAT); |
---|
1495 | 1414 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
---|
1496 | 1415 | |
---|
1497 | | - for_each_set_bit(intr_line, &pending, pctrl->community->nirqs) { |
---|
1498 | | - unsigned irq, offset; |
---|
| 1416 | + for_each_set_bit(intr_line, &pending, community->nirqs) { |
---|
| 1417 | + unsigned int irq, offset; |
---|
1499 | 1418 | |
---|
1500 | | - offset = pctrl->intr_lines[intr_line]; |
---|
| 1419 | + offset = cctx->intr_lines[intr_line]; |
---|
1501 | 1420 | irq = irq_find_mapping(gc->irq.domain, offset); |
---|
1502 | 1421 | generic_handle_irq(irq); |
---|
1503 | 1422 | } |
---|
.. | .. |
---|
1546 | 1465 | {} |
---|
1547 | 1466 | }; |
---|
1548 | 1467 | |
---|
1549 | | -static int chv_gpio_probe(struct chv_pinctrl *pctrl, int irq) |
---|
| 1468 | +static void chv_init_irq_valid_mask(struct gpio_chip *chip, |
---|
| 1469 | + unsigned long *valid_mask, |
---|
| 1470 | + unsigned int ngpios) |
---|
1550 | 1471 | { |
---|
1551 | | - const struct chv_gpio_pinrange *range; |
---|
1552 | | - struct gpio_chip *chip = &pctrl->chip; |
---|
1553 | | - bool need_valid_mask = !dmi_check_system(chv_no_valid_mask); |
---|
1554 | | - const struct chv_community *community = pctrl->community; |
---|
1555 | | - int ret, i, irq_base; |
---|
1556 | | - |
---|
1557 | | - *chip = chv_gpio_chip; |
---|
1558 | | - |
---|
1559 | | - chip->ngpio = community->pins[community->npins - 1].number + 1; |
---|
1560 | | - chip->label = dev_name(pctrl->dev); |
---|
1561 | | - chip->parent = pctrl->dev; |
---|
1562 | | - chip->base = -1; |
---|
1563 | | - chip->irq.need_valid_mask = need_valid_mask; |
---|
1564 | | - |
---|
1565 | | - ret = devm_gpiochip_add_data(pctrl->dev, chip, pctrl); |
---|
1566 | | - if (ret) { |
---|
1567 | | - dev_err(pctrl->dev, "Failed to register gpiochip\n"); |
---|
1568 | | - return ret; |
---|
1569 | | - } |
---|
1570 | | - |
---|
1571 | | - for (i = 0; i < community->ngpio_ranges; i++) { |
---|
1572 | | - range = &community->gpio_ranges[i]; |
---|
1573 | | - ret = gpiochip_add_pin_range(chip, dev_name(pctrl->dev), |
---|
1574 | | - range->base, range->base, |
---|
1575 | | - range->npins); |
---|
1576 | | - if (ret) { |
---|
1577 | | - dev_err(pctrl->dev, "failed to add GPIO pin range\n"); |
---|
1578 | | - return ret; |
---|
1579 | | - } |
---|
1580 | | - } |
---|
| 1472 | + struct intel_pinctrl *pctrl = gpiochip_get_data(chip); |
---|
| 1473 | + const struct intel_community *community = &pctrl->communities[0]; |
---|
| 1474 | + int i; |
---|
1581 | 1475 | |
---|
1582 | 1476 | /* Do not add GPIOs that can only generate GPEs to the IRQ domain */ |
---|
1583 | | - for (i = 0; i < community->npins; i++) { |
---|
| 1477 | + for (i = 0; i < pctrl->soc->npins; i++) { |
---|
1584 | 1478 | const struct pinctrl_pin_desc *desc; |
---|
1585 | 1479 | u32 intsel; |
---|
1586 | 1480 | |
---|
1587 | | - desc = &community->pins[i]; |
---|
| 1481 | + desc = &pctrl->soc->pins[i]; |
---|
1588 | 1482 | |
---|
1589 | | - intsel = readl(chv_padreg(pctrl, desc->number, CHV_PADCTRL0)); |
---|
| 1483 | + intsel = chv_readl(pctrl, desc->number, CHV_PADCTRL0); |
---|
1590 | 1484 | intsel &= CHV_PADCTRL0_INTSEL_MASK; |
---|
1591 | 1485 | intsel >>= CHV_PADCTRL0_INTSEL_SHIFT; |
---|
1592 | 1486 | |
---|
1593 | | - if (need_valid_mask && intsel >= community->nirqs) |
---|
1594 | | - clear_bit(desc->number, chip->irq.valid_mask); |
---|
| 1487 | + if (intsel >= community->nirqs) |
---|
| 1488 | + clear_bit(desc->number, valid_mask); |
---|
1595 | 1489 | } |
---|
| 1490 | +} |
---|
| 1491 | + |
---|
| 1492 | +static int chv_gpio_irq_init_hw(struct gpio_chip *chip) |
---|
| 1493 | +{ |
---|
| 1494 | + struct intel_pinctrl *pctrl = gpiochip_get_data(chip); |
---|
| 1495 | + const struct intel_community *community = &pctrl->communities[0]; |
---|
1596 | 1496 | |
---|
1597 | 1497 | /* |
---|
1598 | 1498 | * The same set of machines in chv_no_valid_mask[] have incorrectly |
---|
.. | .. |
---|
1601 | 1501 | * |
---|
1602 | 1502 | * See also https://bugzilla.kernel.org/show_bug.cgi?id=197953. |
---|
1603 | 1503 | */ |
---|
1604 | | - if (!need_valid_mask) { |
---|
| 1504 | + if (!pctrl->chip.irq.init_valid_mask) { |
---|
1605 | 1505 | /* |
---|
1606 | 1506 | * Mask all interrupts the community is able to generate |
---|
1607 | 1507 | * but leave the ones that can only generate GPEs unmasked. |
---|
1608 | 1508 | */ |
---|
1609 | | - chv_writel(GENMASK(31, pctrl->community->nirqs), |
---|
1610 | | - pctrl->regs + CHV_INTMASK); |
---|
| 1509 | + chv_pctrl_writel(pctrl, CHV_INTMASK, GENMASK(31, community->nirqs)); |
---|
1611 | 1510 | } |
---|
1612 | 1511 | |
---|
1613 | 1512 | /* Clear all interrupts */ |
---|
1614 | | - chv_writel(0xffff, pctrl->regs + CHV_INTSTAT); |
---|
| 1513 | + chv_pctrl_writel(pctrl, CHV_INTSTAT, 0xffff); |
---|
1615 | 1514 | |
---|
1616 | | - if (!need_valid_mask) { |
---|
1617 | | - irq_base = devm_irq_alloc_descs(pctrl->dev, -1, 0, |
---|
1618 | | - community->npins, NUMA_NO_NODE); |
---|
1619 | | - if (irq_base < 0) { |
---|
1620 | | - dev_err(pctrl->dev, "Failed to allocate IRQ numbers\n"); |
---|
1621 | | - return irq_base; |
---|
| 1515 | + return 0; |
---|
| 1516 | +} |
---|
| 1517 | + |
---|
| 1518 | +static int chv_gpio_add_pin_ranges(struct gpio_chip *chip) |
---|
| 1519 | +{ |
---|
| 1520 | + struct intel_pinctrl *pctrl = gpiochip_get_data(chip); |
---|
| 1521 | + const struct intel_community *community = &pctrl->communities[0]; |
---|
| 1522 | + const struct intel_padgroup *gpp; |
---|
| 1523 | + int ret, i; |
---|
| 1524 | + |
---|
| 1525 | + for (i = 0; i < community->ngpps; i++) { |
---|
| 1526 | + gpp = &community->gpps[i]; |
---|
| 1527 | + ret = gpiochip_add_pin_range(chip, dev_name(pctrl->dev), |
---|
| 1528 | + gpp->base, gpp->base, |
---|
| 1529 | + gpp->size); |
---|
| 1530 | + if (ret) { |
---|
| 1531 | + dev_err(pctrl->dev, "failed to add GPIO pin range\n"); |
---|
| 1532 | + return ret; |
---|
1622 | 1533 | } |
---|
1623 | 1534 | } |
---|
1624 | 1535 | |
---|
| 1536 | + return 0; |
---|
| 1537 | +} |
---|
| 1538 | + |
---|
| 1539 | +static int chv_gpio_probe(struct intel_pinctrl *pctrl, int irq) |
---|
| 1540 | +{ |
---|
| 1541 | + const struct intel_community *community = &pctrl->communities[0]; |
---|
| 1542 | + const struct intel_padgroup *gpp; |
---|
| 1543 | + struct gpio_chip *chip = &pctrl->chip; |
---|
| 1544 | + bool need_valid_mask = !dmi_check_system(chv_no_valid_mask); |
---|
| 1545 | + int ret, i, irq_base; |
---|
| 1546 | + |
---|
| 1547 | + *chip = chv_gpio_chip; |
---|
| 1548 | + |
---|
| 1549 | + chip->ngpio = pctrl->soc->pins[pctrl->soc->npins - 1].number + 1; |
---|
| 1550 | + chip->label = dev_name(pctrl->dev); |
---|
| 1551 | + chip->add_pin_ranges = chv_gpio_add_pin_ranges; |
---|
| 1552 | + chip->parent = pctrl->dev; |
---|
| 1553 | + chip->base = -1; |
---|
| 1554 | + |
---|
| 1555 | + pctrl->irq = irq; |
---|
1625 | 1556 | pctrl->irqchip.name = "chv-gpio"; |
---|
1626 | 1557 | pctrl->irqchip.irq_startup = chv_gpio_irq_startup; |
---|
1627 | 1558 | pctrl->irqchip.irq_ack = chv_gpio_irq_ack; |
---|
.. | .. |
---|
1630 | 1561 | pctrl->irqchip.irq_set_type = chv_gpio_irq_type; |
---|
1631 | 1562 | pctrl->irqchip.flags = IRQCHIP_SKIP_SET_WAKE; |
---|
1632 | 1563 | |
---|
1633 | | - ret = gpiochip_irqchip_add(chip, &pctrl->irqchip, 0, |
---|
1634 | | - handle_bad_irq, IRQ_TYPE_NONE); |
---|
| 1564 | + chip->irq.chip = &pctrl->irqchip; |
---|
| 1565 | + chip->irq.init_hw = chv_gpio_irq_init_hw; |
---|
| 1566 | + chip->irq.parent_handler = chv_gpio_irq_handler; |
---|
| 1567 | + chip->irq.num_parents = 1; |
---|
| 1568 | + chip->irq.parents = &pctrl->irq; |
---|
| 1569 | + chip->irq.default_type = IRQ_TYPE_NONE; |
---|
| 1570 | + chip->irq.handler = handle_bad_irq; |
---|
| 1571 | + if (need_valid_mask) { |
---|
| 1572 | + chip->irq.init_valid_mask = chv_init_irq_valid_mask; |
---|
| 1573 | + } else { |
---|
| 1574 | + irq_base = devm_irq_alloc_descs(pctrl->dev, -1, 0, |
---|
| 1575 | + pctrl->soc->npins, NUMA_NO_NODE); |
---|
| 1576 | + if (irq_base < 0) { |
---|
| 1577 | + dev_err(pctrl->dev, "Failed to allocate IRQ numbers\n"); |
---|
| 1578 | + return irq_base; |
---|
| 1579 | + } |
---|
| 1580 | + } |
---|
| 1581 | + |
---|
| 1582 | + ret = devm_gpiochip_add_data(pctrl->dev, chip, pctrl); |
---|
1635 | 1583 | if (ret) { |
---|
1636 | | - dev_err(pctrl->dev, "failed to add IRQ chip\n"); |
---|
| 1584 | + dev_err(pctrl->dev, "Failed to register gpiochip\n"); |
---|
1637 | 1585 | return ret; |
---|
1638 | 1586 | } |
---|
1639 | 1587 | |
---|
1640 | 1588 | if (!need_valid_mask) { |
---|
1641 | | - for (i = 0; i < community->ngpio_ranges; i++) { |
---|
1642 | | - range = &community->gpio_ranges[i]; |
---|
| 1589 | + for (i = 0; i < community->ngpps; i++) { |
---|
| 1590 | + gpp = &community->gpps[i]; |
---|
1643 | 1591 | |
---|
1644 | 1592 | irq_domain_associate_many(chip->irq.domain, irq_base, |
---|
1645 | | - range->base, range->npins); |
---|
1646 | | - irq_base += range->npins; |
---|
| 1593 | + gpp->base, gpp->size); |
---|
| 1594 | + irq_base += gpp->size; |
---|
1647 | 1595 | } |
---|
1648 | 1596 | } |
---|
1649 | 1597 | |
---|
1650 | | - gpiochip_set_chained_irqchip(chip, &pctrl->irqchip, irq, |
---|
1651 | | - chv_gpio_irq_handler); |
---|
1652 | 1598 | return 0; |
---|
1653 | 1599 | } |
---|
1654 | 1600 | |
---|
.. | .. |
---|
1656 | 1602 | acpi_physical_address address, u32 bits, u64 *value, |
---|
1657 | 1603 | void *handler_context, void *region_context) |
---|
1658 | 1604 | { |
---|
1659 | | - struct chv_pinctrl *pctrl = region_context; |
---|
| 1605 | + struct intel_pinctrl *pctrl = region_context; |
---|
1660 | 1606 | unsigned long flags; |
---|
1661 | 1607 | acpi_status ret = AE_OK; |
---|
1662 | 1608 | |
---|
1663 | 1609 | raw_spin_lock_irqsave(&chv_lock, flags); |
---|
1664 | 1610 | |
---|
1665 | 1611 | if (function == ACPI_WRITE) |
---|
1666 | | - chv_writel((u32)(*value), pctrl->regs + (u32)address); |
---|
| 1612 | + chv_pctrl_writel(pctrl, address, *value); |
---|
1667 | 1613 | else if (function == ACPI_READ) |
---|
1668 | | - *value = readl(pctrl->regs + (u32)address); |
---|
| 1614 | + *value = chv_pctrl_readl(pctrl, address); |
---|
1669 | 1615 | else |
---|
1670 | 1616 | ret = AE_BAD_PARAMETER; |
---|
1671 | 1617 | |
---|
.. | .. |
---|
1676 | 1622 | |
---|
1677 | 1623 | static int chv_pinctrl_probe(struct platform_device *pdev) |
---|
1678 | 1624 | { |
---|
1679 | | - struct chv_pinctrl *pctrl; |
---|
1680 | | - struct acpi_device *adev; |
---|
1681 | | - struct resource *res; |
---|
| 1625 | + const struct intel_pinctrl_soc_data *soc_data; |
---|
| 1626 | + struct intel_community *community; |
---|
| 1627 | + struct device *dev = &pdev->dev; |
---|
| 1628 | + struct intel_pinctrl *pctrl; |
---|
1682 | 1629 | acpi_status status; |
---|
1683 | | - int ret, irq, i; |
---|
| 1630 | + int ret, irq; |
---|
1684 | 1631 | |
---|
1685 | | - adev = ACPI_COMPANION(&pdev->dev); |
---|
1686 | | - if (!adev) |
---|
1687 | | - return -ENODEV; |
---|
| 1632 | + soc_data = intel_pinctrl_get_soc_data(pdev); |
---|
| 1633 | + if (IS_ERR(soc_data)) |
---|
| 1634 | + return PTR_ERR(soc_data); |
---|
1688 | 1635 | |
---|
1689 | | - pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL); |
---|
| 1636 | + pctrl = devm_kzalloc(dev, sizeof(*pctrl), GFP_KERNEL); |
---|
1690 | 1637 | if (!pctrl) |
---|
1691 | 1638 | return -ENOMEM; |
---|
1692 | 1639 | |
---|
1693 | | - for (i = 0; i < ARRAY_SIZE(chv_communities); i++) |
---|
1694 | | - if (!strcmp(adev->pnp.unique_id, chv_communities[i]->uid)) { |
---|
1695 | | - pctrl->community = chv_communities[i]; |
---|
1696 | | - break; |
---|
1697 | | - } |
---|
1698 | | - if (i == ARRAY_SIZE(chv_communities)) |
---|
1699 | | - return -ENODEV; |
---|
| 1640 | + pctrl->dev = dev; |
---|
| 1641 | + pctrl->soc = soc_data; |
---|
1700 | 1642 | |
---|
1701 | | - pctrl->dev = &pdev->dev; |
---|
| 1643 | + pctrl->ncommunities = pctrl->soc->ncommunities; |
---|
| 1644 | + pctrl->communities = devm_kmemdup(dev, pctrl->soc->communities, |
---|
| 1645 | + pctrl->ncommunities * sizeof(*pctrl->communities), |
---|
| 1646 | + GFP_KERNEL); |
---|
| 1647 | + if (!pctrl->communities) |
---|
| 1648 | + return -ENOMEM; |
---|
| 1649 | + |
---|
| 1650 | + community = &pctrl->communities[0]; |
---|
| 1651 | + community->regs = devm_platform_ioremap_resource(pdev, 0); |
---|
| 1652 | + if (IS_ERR(community->regs)) |
---|
| 1653 | + return PTR_ERR(community->regs); |
---|
| 1654 | + |
---|
| 1655 | + community->pad_regs = community->regs + FAMILY_PAD_REGS_OFF; |
---|
1702 | 1656 | |
---|
1703 | 1657 | #ifdef CONFIG_PM_SLEEP |
---|
1704 | | - pctrl->saved_pin_context = devm_kcalloc(pctrl->dev, |
---|
1705 | | - pctrl->community->npins, sizeof(*pctrl->saved_pin_context), |
---|
1706 | | - GFP_KERNEL); |
---|
1707 | | - if (!pctrl->saved_pin_context) |
---|
| 1658 | + pctrl->context.pads = devm_kcalloc(dev, pctrl->soc->npins, |
---|
| 1659 | + sizeof(*pctrl->context.pads), |
---|
| 1660 | + GFP_KERNEL); |
---|
| 1661 | + if (!pctrl->context.pads) |
---|
1708 | 1662 | return -ENOMEM; |
---|
1709 | 1663 | #endif |
---|
1710 | 1664 | |
---|
1711 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
---|
1712 | | - pctrl->regs = devm_ioremap_resource(&pdev->dev, res); |
---|
1713 | | - if (IS_ERR(pctrl->regs)) |
---|
1714 | | - return PTR_ERR(pctrl->regs); |
---|
| 1665 | + pctrl->context.communities = devm_kcalloc(dev, pctrl->soc->ncommunities, |
---|
| 1666 | + sizeof(*pctrl->context.communities), |
---|
| 1667 | + GFP_KERNEL); |
---|
| 1668 | + if (!pctrl->context.communities) |
---|
| 1669 | + return -ENOMEM; |
---|
1715 | 1670 | |
---|
1716 | 1671 | irq = platform_get_irq(pdev, 0); |
---|
1717 | | - if (irq < 0) { |
---|
1718 | | - dev_err(&pdev->dev, "failed to get interrupt number\n"); |
---|
| 1672 | + if (irq < 0) |
---|
1719 | 1673 | return irq; |
---|
1720 | | - } |
---|
1721 | 1674 | |
---|
1722 | 1675 | pctrl->pctldesc = chv_pinctrl_desc; |
---|
1723 | | - pctrl->pctldesc.name = dev_name(&pdev->dev); |
---|
1724 | | - pctrl->pctldesc.pins = pctrl->community->pins; |
---|
1725 | | - pctrl->pctldesc.npins = pctrl->community->npins; |
---|
| 1676 | + pctrl->pctldesc.name = dev_name(dev); |
---|
| 1677 | + pctrl->pctldesc.pins = pctrl->soc->pins; |
---|
| 1678 | + pctrl->pctldesc.npins = pctrl->soc->npins; |
---|
1726 | 1679 | |
---|
1727 | | - pctrl->pctldev = devm_pinctrl_register(&pdev->dev, &pctrl->pctldesc, |
---|
1728 | | - pctrl); |
---|
| 1680 | + pctrl->pctldev = devm_pinctrl_register(dev, &pctrl->pctldesc, pctrl); |
---|
1729 | 1681 | if (IS_ERR(pctrl->pctldev)) { |
---|
1730 | | - dev_err(&pdev->dev, "failed to register pinctrl driver\n"); |
---|
| 1682 | + dev_err(dev, "failed to register pinctrl driver\n"); |
---|
1731 | 1683 | return PTR_ERR(pctrl->pctldev); |
---|
1732 | 1684 | } |
---|
1733 | 1685 | |
---|
.. | .. |
---|
1735 | 1687 | if (ret) |
---|
1736 | 1688 | return ret; |
---|
1737 | 1689 | |
---|
1738 | | - status = acpi_install_address_space_handler(adev->handle, |
---|
1739 | | - pctrl->community->acpi_space_id, |
---|
| 1690 | + status = acpi_install_address_space_handler(ACPI_HANDLE(dev), |
---|
| 1691 | + community->acpi_space_id, |
---|
1740 | 1692 | chv_pinctrl_mmio_access_handler, |
---|
1741 | 1693 | NULL, pctrl); |
---|
1742 | 1694 | if (ACPI_FAILURE(status)) |
---|
1743 | | - dev_err(&pdev->dev, "failed to install ACPI addr space handler\n"); |
---|
| 1695 | + dev_err(dev, "failed to install ACPI addr space handler\n"); |
---|
1744 | 1696 | |
---|
1745 | 1697 | platform_set_drvdata(pdev, pctrl); |
---|
1746 | 1698 | |
---|
.. | .. |
---|
1749 | 1701 | |
---|
1750 | 1702 | static int chv_pinctrl_remove(struct platform_device *pdev) |
---|
1751 | 1703 | { |
---|
1752 | | - struct chv_pinctrl *pctrl = platform_get_drvdata(pdev); |
---|
| 1704 | + struct intel_pinctrl *pctrl = platform_get_drvdata(pdev); |
---|
| 1705 | + const struct intel_community *community = &pctrl->communities[0]; |
---|
1753 | 1706 | |
---|
1754 | | - acpi_remove_address_space_handler(ACPI_COMPANION(&pdev->dev), |
---|
1755 | | - pctrl->community->acpi_space_id, |
---|
| 1707 | + acpi_remove_address_space_handler(ACPI_HANDLE(&pdev->dev), |
---|
| 1708 | + community->acpi_space_id, |
---|
1756 | 1709 | chv_pinctrl_mmio_access_handler); |
---|
1757 | 1710 | |
---|
1758 | 1711 | return 0; |
---|
.. | .. |
---|
1761 | 1714 | #ifdef CONFIG_PM_SLEEP |
---|
1762 | 1715 | static int chv_pinctrl_suspend_noirq(struct device *dev) |
---|
1763 | 1716 | { |
---|
1764 | | - struct platform_device *pdev = to_platform_device(dev); |
---|
1765 | | - struct chv_pinctrl *pctrl = platform_get_drvdata(pdev); |
---|
| 1717 | + struct intel_pinctrl *pctrl = dev_get_drvdata(dev); |
---|
| 1718 | + struct intel_community_context *cctx = &pctrl->context.communities[0]; |
---|
1766 | 1719 | unsigned long flags; |
---|
1767 | 1720 | int i; |
---|
1768 | 1721 | |
---|
1769 | 1722 | raw_spin_lock_irqsave(&chv_lock, flags); |
---|
1770 | 1723 | |
---|
1771 | | - pctrl->saved_intmask = readl(pctrl->regs + CHV_INTMASK); |
---|
| 1724 | + cctx->saved_intmask = chv_pctrl_readl(pctrl, CHV_INTMASK); |
---|
1772 | 1725 | |
---|
1773 | | - for (i = 0; i < pctrl->community->npins; i++) { |
---|
| 1726 | + for (i = 0; i < pctrl->soc->npins; i++) { |
---|
1774 | 1727 | const struct pinctrl_pin_desc *desc; |
---|
1775 | | - struct chv_pin_context *ctx; |
---|
1776 | | - void __iomem *reg; |
---|
| 1728 | + struct intel_pad_context *ctx = &pctrl->context.pads[i]; |
---|
1777 | 1729 | |
---|
1778 | | - desc = &pctrl->community->pins[i]; |
---|
| 1730 | + desc = &pctrl->soc->pins[i]; |
---|
1779 | 1731 | if (chv_pad_locked(pctrl, desc->number)) |
---|
1780 | 1732 | continue; |
---|
1781 | 1733 | |
---|
1782 | | - ctx = &pctrl->saved_pin_context[i]; |
---|
| 1734 | + ctx->padctrl0 = chv_readl(pctrl, desc->number, CHV_PADCTRL0); |
---|
| 1735 | + ctx->padctrl0 &= ~CHV_PADCTRL0_GPIORXSTATE; |
---|
1783 | 1736 | |
---|
1784 | | - reg = chv_padreg(pctrl, desc->number, CHV_PADCTRL0); |
---|
1785 | | - ctx->padctrl0 = readl(reg) & ~CHV_PADCTRL0_GPIORXSTATE; |
---|
1786 | | - |
---|
1787 | | - reg = chv_padreg(pctrl, desc->number, CHV_PADCTRL1); |
---|
1788 | | - ctx->padctrl1 = readl(reg); |
---|
| 1737 | + ctx->padctrl1 = chv_readl(pctrl, desc->number, CHV_PADCTRL1); |
---|
1789 | 1738 | } |
---|
1790 | 1739 | |
---|
1791 | 1740 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
---|
.. | .. |
---|
1795 | 1744 | |
---|
1796 | 1745 | static int chv_pinctrl_resume_noirq(struct device *dev) |
---|
1797 | 1746 | { |
---|
1798 | | - struct platform_device *pdev = to_platform_device(dev); |
---|
1799 | | - struct chv_pinctrl *pctrl = platform_get_drvdata(pdev); |
---|
| 1747 | + struct intel_pinctrl *pctrl = dev_get_drvdata(dev); |
---|
| 1748 | + struct intel_community_context *cctx = &pctrl->context.communities[0]; |
---|
1800 | 1749 | unsigned long flags; |
---|
1801 | 1750 | int i; |
---|
1802 | 1751 | |
---|
.. | .. |
---|
1807 | 1756 | * registers because we don't know in which state BIOS left them |
---|
1808 | 1757 | * upon exiting suspend. |
---|
1809 | 1758 | */ |
---|
1810 | | - chv_writel(0, pctrl->regs + CHV_INTMASK); |
---|
| 1759 | + chv_pctrl_writel(pctrl, CHV_INTMASK, 0x0000); |
---|
1811 | 1760 | |
---|
1812 | | - for (i = 0; i < pctrl->community->npins; i++) { |
---|
| 1761 | + for (i = 0; i < pctrl->soc->npins; i++) { |
---|
1813 | 1762 | const struct pinctrl_pin_desc *desc; |
---|
1814 | | - const struct chv_pin_context *ctx; |
---|
1815 | | - void __iomem *reg; |
---|
| 1763 | + struct intel_pad_context *ctx = &pctrl->context.pads[i]; |
---|
1816 | 1764 | u32 val; |
---|
1817 | 1765 | |
---|
1818 | | - desc = &pctrl->community->pins[i]; |
---|
| 1766 | + desc = &pctrl->soc->pins[i]; |
---|
1819 | 1767 | if (chv_pad_locked(pctrl, desc->number)) |
---|
1820 | 1768 | continue; |
---|
1821 | 1769 | |
---|
1822 | | - ctx = &pctrl->saved_pin_context[i]; |
---|
1823 | | - |
---|
1824 | 1770 | /* Only restore if our saved state differs from the current */ |
---|
1825 | | - reg = chv_padreg(pctrl, desc->number, CHV_PADCTRL0); |
---|
1826 | | - val = readl(reg) & ~CHV_PADCTRL0_GPIORXSTATE; |
---|
| 1771 | + val = chv_readl(pctrl, desc->number, CHV_PADCTRL0); |
---|
| 1772 | + val &= ~CHV_PADCTRL0_GPIORXSTATE; |
---|
1827 | 1773 | if (ctx->padctrl0 != val) { |
---|
1828 | | - chv_writel(ctx->padctrl0, reg); |
---|
| 1774 | + chv_writel(pctrl, desc->number, CHV_PADCTRL0, ctx->padctrl0); |
---|
1829 | 1775 | dev_dbg(pctrl->dev, "restored pin %2u ctrl0 0x%08x\n", |
---|
1830 | | - desc->number, readl(reg)); |
---|
| 1776 | + desc->number, chv_readl(pctrl, desc->number, CHV_PADCTRL0)); |
---|
1831 | 1777 | } |
---|
1832 | 1778 | |
---|
1833 | | - reg = chv_padreg(pctrl, desc->number, CHV_PADCTRL1); |
---|
1834 | | - val = readl(reg); |
---|
| 1779 | + val = chv_readl(pctrl, desc->number, CHV_PADCTRL1); |
---|
1835 | 1780 | if (ctx->padctrl1 != val) { |
---|
1836 | | - chv_writel(ctx->padctrl1, reg); |
---|
| 1781 | + chv_writel(pctrl, desc->number, CHV_PADCTRL1, ctx->padctrl1); |
---|
1837 | 1782 | dev_dbg(pctrl->dev, "restored pin %2u ctrl1 0x%08x\n", |
---|
1838 | | - desc->number, readl(reg)); |
---|
| 1783 | + desc->number, chv_readl(pctrl, desc->number, CHV_PADCTRL1)); |
---|
1839 | 1784 | } |
---|
1840 | 1785 | } |
---|
1841 | 1786 | |
---|
.. | .. |
---|
1843 | 1788 | * Now that all pins are restored to known state, we can restore |
---|
1844 | 1789 | * the interrupt mask register as well. |
---|
1845 | 1790 | */ |
---|
1846 | | - chv_writel(0xffff, pctrl->regs + CHV_INTSTAT); |
---|
1847 | | - chv_writel(pctrl->saved_intmask, pctrl->regs + CHV_INTMASK); |
---|
| 1791 | + chv_pctrl_writel(pctrl, CHV_INTSTAT, 0xffff); |
---|
| 1792 | + chv_pctrl_writel(pctrl, CHV_INTMASK, cctx->saved_intmask); |
---|
1848 | 1793 | |
---|
1849 | 1794 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
---|
1850 | 1795 | |
---|
.. | .. |
---|
1858 | 1803 | }; |
---|
1859 | 1804 | |
---|
1860 | 1805 | static const struct acpi_device_id chv_pinctrl_acpi_match[] = { |
---|
1861 | | - { "INT33FF" }, |
---|
| 1806 | + { "INT33FF", (kernel_ulong_t)chv_soc_data }, |
---|
1862 | 1807 | { } |
---|
1863 | 1808 | }; |
---|
1864 | 1809 | MODULE_DEVICE_TABLE(acpi, chv_pinctrl_acpi_match); |
---|