1 // SPDX-License-Identifier: GPL-2.0
3 * Cherryview/Braswell pinctrl driver
5 * Copyright (C) 2014, Intel Corporation
6 * Author: Mika Westerberg <mika.westerberg@linux.intel.com>
8 * This driver is based on the original Cherryview GPIO driver by
9 * Ning Li <ning.li@intel.com>
10 * Alan Cox <alan@linux.intel.com>
13 #include <linux/acpi.h>
14 #include <linux/dmi.h>
15 #include <linux/gpio/driver.h>
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/platform_device.h>
19 #include <linux/types.h>
21 #include <linux/pinctrl/pinctrl.h>
22 #include <linux/pinctrl/pinmux.h>
23 #include <linux/pinctrl/pinconf.h>
24 #include <linux/pinctrl/pinconf-generic.h>
26 #include "pinctrl-intel.h"
28 #define CHV_INTSTAT 0x300
29 #define CHV_INTMASK 0x380
31 #define FAMILY_PAD_REGS_OFF 0x4400
32 #define FAMILY_PAD_REGS_SIZE 0x400
33 #define MAX_FAMILY_PAD_GPIO_NO 15
34 #define GPIO_REGS_SIZE 8
36 #define CHV_PADCTRL0 0x000
37 #define CHV_PADCTRL0_INTSEL_SHIFT 28
38 #define CHV_PADCTRL0_INTSEL_MASK GENMASK(31, 28)
39 #define CHV_PADCTRL0_TERM_UP BIT(23)
40 #define CHV_PADCTRL0_TERM_SHIFT 20
41 #define CHV_PADCTRL0_TERM_MASK GENMASK(22, 20)
42 #define CHV_PADCTRL0_TERM_20K 1
43 #define CHV_PADCTRL0_TERM_5K 2
44 #define CHV_PADCTRL0_TERM_1K 4
45 #define CHV_PADCTRL0_PMODE_SHIFT 16
46 #define CHV_PADCTRL0_PMODE_MASK GENMASK(19, 16)
47 #define CHV_PADCTRL0_GPIOEN BIT(15)
48 #define CHV_PADCTRL0_GPIOCFG_SHIFT 8
49 #define CHV_PADCTRL0_GPIOCFG_MASK GENMASK(10, 8)
50 #define CHV_PADCTRL0_GPIOCFG_GPIO 0
51 #define CHV_PADCTRL0_GPIOCFG_GPO 1
52 #define CHV_PADCTRL0_GPIOCFG_GPI 2
53 #define CHV_PADCTRL0_GPIOCFG_HIZ 3
54 #define CHV_PADCTRL0_GPIOTXSTATE BIT(1)
55 #define CHV_PADCTRL0_GPIORXSTATE BIT(0)
57 #define CHV_PADCTRL1 0x004
58 #define CHV_PADCTRL1_CFGLOCK BIT(31)
59 #define CHV_PADCTRL1_INVRXTX_SHIFT 4
60 #define CHV_PADCTRL1_INVRXTX_MASK GENMASK(7, 4)
61 #define CHV_PADCTRL1_INVRXTX_RXDATA BIT(6)
62 #define CHV_PADCTRL1_INVRXTX_TXENABLE BIT(5)
63 #define CHV_PADCTRL1_ODEN BIT(3)
64 #define CHV_PADCTRL1_INTWAKECFG_MASK GENMASK(2, 0)
65 #define CHV_PADCTRL1_INTWAKECFG_FALLING 1
66 #define CHV_PADCTRL1_INTWAKECFG_RISING 2
67 #define CHV_PADCTRL1_INTWAKECFG_BOTH 3
68 #define CHV_PADCTRL1_INTWAKECFG_LEVEL 4
71 * struct chv_community - A community specific configuration
72 * @uid: ACPI _UID used to match the community
73 * @pins: All pins in this community
74 * @npins: Number of pins
75 * @groups: All groups in this community
76 * @ngroups: Number of groups
77 * @functions: All functions in this community
78 * @nfunctions: Number of functions
80 * @ngpps: Number of pad groups in this community
81 * @nirqs: Total number of IRQs this community can generate
82 * @acpi_space_id: An address space ID for ACPI OpRegion handler
84 struct chv_community {
86 const struct pinctrl_pin_desc *pins;
88 const struct intel_pingroup *groups;
90 const struct intel_function *functions;
92 const struct intel_padgroup *gpps;
95 acpi_adr_space_type acpi_space_id;
98 struct chv_pin_context {
104 * struct chv_pinctrl - CHV pinctrl private structure
105 * @dev: Pointer to the parent device
106 * @pctldesc: Pin controller description
107 * @pctldev: Pointer to the pin controller device
108 * @chip: GPIO chip in this pin controller
109 * @irqchip: IRQ chip in this pin controller
110 * @regs: MMIO registers
111 * @irq: Our parent irq
112 * @intr_lines: Stores mapping between 16 HW interrupt wires and GPIO
113 * offset (in GPIO number space)
114 * @community: Community this pinctrl instance represents
115 * @saved_intmask: Interrupt mask saved for system sleep
116 * @saved_pin_context: Pointer to a context of the pins saved for system sleep
118 * The first group in @groups is expected to contain all pins that can be
123 struct pinctrl_desc pctldesc;
124 struct pinctrl_dev *pctldev;
125 struct gpio_chip chip;
126 struct irq_chip irqchip;
129 unsigned int intr_lines[16];
130 const struct chv_community *community;
132 struct chv_pin_context *saved_pin_context;
135 #define PINMODE_INVERT_OE BIT(15)
137 #define PINMODE(m, i) ((m) | ((i) * PINMODE_INVERT_OE))
139 #define CHV_GPP(start, end) \
142 .size = (end) - (start) + 1, \
145 static const struct pinctrl_pin_desc southwest_pins[] = {
146 PINCTRL_PIN(0, "FST_SPI_D2"),
147 PINCTRL_PIN(1, "FST_SPI_D0"),
148 PINCTRL_PIN(2, "FST_SPI_CLK"),
149 PINCTRL_PIN(3, "FST_SPI_D3"),
150 PINCTRL_PIN(4, "FST_SPI_CS1_B"),
151 PINCTRL_PIN(5, "FST_SPI_D1"),
152 PINCTRL_PIN(6, "FST_SPI_CS0_B"),
153 PINCTRL_PIN(7, "FST_SPI_CS2_B"),
155 PINCTRL_PIN(15, "UART1_RTS_B"),
156 PINCTRL_PIN(16, "UART1_RXD"),
157 PINCTRL_PIN(17, "UART2_RXD"),
158 PINCTRL_PIN(18, "UART1_CTS_B"),
159 PINCTRL_PIN(19, "UART2_RTS_B"),
160 PINCTRL_PIN(20, "UART1_TXD"),
161 PINCTRL_PIN(21, "UART2_TXD"),
162 PINCTRL_PIN(22, "UART2_CTS_B"),
164 PINCTRL_PIN(30, "MF_HDA_CLK"),
165 PINCTRL_PIN(31, "MF_HDA_RSTB"),
166 PINCTRL_PIN(32, "MF_HDA_SDIO"),
167 PINCTRL_PIN(33, "MF_HDA_SDO"),
168 PINCTRL_PIN(34, "MF_HDA_DOCKRSTB"),
169 PINCTRL_PIN(35, "MF_HDA_SYNC"),
170 PINCTRL_PIN(36, "MF_HDA_SDI1"),
171 PINCTRL_PIN(37, "MF_HDA_DOCKENB"),
173 PINCTRL_PIN(45, "I2C5_SDA"),
174 PINCTRL_PIN(46, "I2C4_SDA"),
175 PINCTRL_PIN(47, "I2C6_SDA"),
176 PINCTRL_PIN(48, "I2C5_SCL"),
177 PINCTRL_PIN(49, "I2C_NFC_SDA"),
178 PINCTRL_PIN(50, "I2C4_SCL"),
179 PINCTRL_PIN(51, "I2C6_SCL"),
180 PINCTRL_PIN(52, "I2C_NFC_SCL"),
182 PINCTRL_PIN(60, "I2C1_SDA"),
183 PINCTRL_PIN(61, "I2C0_SDA"),
184 PINCTRL_PIN(62, "I2C2_SDA"),
185 PINCTRL_PIN(63, "I2C1_SCL"),
186 PINCTRL_PIN(64, "I2C3_SDA"),
187 PINCTRL_PIN(65, "I2C0_SCL"),
188 PINCTRL_PIN(66, "I2C2_SCL"),
189 PINCTRL_PIN(67, "I2C3_SCL"),
191 PINCTRL_PIN(75, "SATA_GP0"),
192 PINCTRL_PIN(76, "SATA_GP1"),
193 PINCTRL_PIN(77, "SATA_LEDN"),
194 PINCTRL_PIN(78, "SATA_GP2"),
195 PINCTRL_PIN(79, "MF_SMB_ALERTB"),
196 PINCTRL_PIN(80, "SATA_GP3"),
197 PINCTRL_PIN(81, "MF_SMB_CLK"),
198 PINCTRL_PIN(82, "MF_SMB_DATA"),
200 PINCTRL_PIN(90, "PCIE_CLKREQ0B"),
201 PINCTRL_PIN(91, "PCIE_CLKREQ1B"),
202 PINCTRL_PIN(92, "GP_SSP_2_CLK"),
203 PINCTRL_PIN(93, "PCIE_CLKREQ2B"),
204 PINCTRL_PIN(94, "GP_SSP_2_RXD"),
205 PINCTRL_PIN(95, "PCIE_CLKREQ3B"),
206 PINCTRL_PIN(96, "GP_SSP_2_FS"),
207 PINCTRL_PIN(97, "GP_SSP_2_TXD"),
210 static const unsigned southwest_uart0_pins[] = { 16, 20 };
211 static const unsigned southwest_uart1_pins[] = { 15, 16, 18, 20 };
212 static const unsigned southwest_uart2_pins[] = { 17, 19, 21, 22 };
213 static const unsigned southwest_i2c0_pins[] = { 61, 65 };
214 static const unsigned southwest_hda_pins[] = { 30, 31, 32, 33, 34, 35, 36, 37 };
215 static const unsigned southwest_lpe_pins[] = {
216 30, 31, 32, 33, 34, 35, 36, 37, 92, 94, 96, 97,
218 static const unsigned southwest_i2c1_pins[] = { 60, 63 };
219 static const unsigned southwest_i2c2_pins[] = { 62, 66 };
220 static const unsigned southwest_i2c3_pins[] = { 64, 67 };
221 static const unsigned southwest_i2c4_pins[] = { 46, 50 };
222 static const unsigned southwest_i2c5_pins[] = { 45, 48 };
223 static const unsigned southwest_i2c6_pins[] = { 47, 51 };
224 static const unsigned southwest_i2c_nfc_pins[] = { 49, 52 };
225 static const unsigned southwest_spi3_pins[] = { 76, 79, 80, 81, 82 };
227 /* Some of LPE I2S TXD pins need to have OE inversion set */
228 static const unsigned int southwest_lpe_altfuncs[] = {
229 PINMODE(1, 1), PINMODE(1, 0), PINMODE(1, 0), PINMODE(1, 0), /* 30, 31, 32, 33 */
230 PINMODE(1, 1), PINMODE(1, 0), PINMODE(1, 0), PINMODE(1, 0), /* 34, 35, 36, 37 */
231 PINMODE(1, 0), PINMODE(1, 0), PINMODE(1, 0), PINMODE(1, 1), /* 92, 94, 96, 97 */
235 * Two spi3 chipselects are available in different mode than the main spi3
236 * functionality, which is using mode 2.
238 static const unsigned int southwest_spi3_altfuncs[] = {
239 PINMODE(3, 0), PINMODE(2, 0), PINMODE(3, 0), PINMODE(2, 0), /* 76, 79, 80, 81 */
240 PINMODE(2, 0), /* 82 */
243 static const struct intel_pingroup southwest_groups[] = {
244 PIN_GROUP("uart0_grp", southwest_uart0_pins, PINMODE(2, 0)),
245 PIN_GROUP("uart1_grp", southwest_uart1_pins, PINMODE(1, 0)),
246 PIN_GROUP("uart2_grp", southwest_uart2_pins, PINMODE(1, 0)),
247 PIN_GROUP("hda_grp", southwest_hda_pins, PINMODE(2, 0)),
248 PIN_GROUP("i2c0_grp", southwest_i2c0_pins, PINMODE(1, 1)),
249 PIN_GROUP("i2c1_grp", southwest_i2c1_pins, PINMODE(1, 1)),
250 PIN_GROUP("i2c2_grp", southwest_i2c2_pins, PINMODE(1, 1)),
251 PIN_GROUP("i2c3_grp", southwest_i2c3_pins, PINMODE(1, 1)),
252 PIN_GROUP("i2c4_grp", southwest_i2c4_pins, PINMODE(1, 1)),
253 PIN_GROUP("i2c5_grp", southwest_i2c5_pins, PINMODE(1, 1)),
254 PIN_GROUP("i2c6_grp", southwest_i2c6_pins, PINMODE(1, 1)),
255 PIN_GROUP("i2c_nfc_grp", southwest_i2c_nfc_pins, PINMODE(2, 1)),
256 PIN_GROUP("lpe_grp", southwest_lpe_pins, southwest_lpe_altfuncs),
257 PIN_GROUP("spi3_grp", southwest_spi3_pins, southwest_spi3_altfuncs),
260 static const char * const southwest_uart0_groups[] = { "uart0_grp" };
261 static const char * const southwest_uart1_groups[] = { "uart1_grp" };
262 static const char * const southwest_uart2_groups[] = { "uart2_grp" };
263 static const char * const southwest_hda_groups[] = { "hda_grp" };
264 static const char * const southwest_lpe_groups[] = { "lpe_grp" };
265 static const char * const southwest_i2c0_groups[] = { "i2c0_grp" };
266 static const char * const southwest_i2c1_groups[] = { "i2c1_grp" };
267 static const char * const southwest_i2c2_groups[] = { "i2c2_grp" };
268 static const char * const southwest_i2c3_groups[] = { "i2c3_grp" };
269 static const char * const southwest_i2c4_groups[] = { "i2c4_grp" };
270 static const char * const southwest_i2c5_groups[] = { "i2c5_grp" };
271 static const char * const southwest_i2c6_groups[] = { "i2c6_grp" };
272 static const char * const southwest_i2c_nfc_groups[] = { "i2c_nfc_grp" };
273 static const char * const southwest_spi3_groups[] = { "spi3_grp" };
276 * Only do pinmuxing for certain LPSS devices for now. Rest of the pins are
277 * enabled only as GPIOs.
279 static const struct intel_function southwest_functions[] = {
280 FUNCTION("uart0", southwest_uart0_groups),
281 FUNCTION("uart1", southwest_uart1_groups),
282 FUNCTION("uart2", southwest_uart2_groups),
283 FUNCTION("hda", southwest_hda_groups),
284 FUNCTION("lpe", southwest_lpe_groups),
285 FUNCTION("i2c0", southwest_i2c0_groups),
286 FUNCTION("i2c1", southwest_i2c1_groups),
287 FUNCTION("i2c2", southwest_i2c2_groups),
288 FUNCTION("i2c3", southwest_i2c3_groups),
289 FUNCTION("i2c4", southwest_i2c4_groups),
290 FUNCTION("i2c5", southwest_i2c5_groups),
291 FUNCTION("i2c6", southwest_i2c6_groups),
292 FUNCTION("i2c_nfc", southwest_i2c_nfc_groups),
293 FUNCTION("spi3", southwest_spi3_groups),
296 static const struct intel_padgroup southwest_gpps[] = {
306 static const struct chv_community southwest_community = {
308 .pins = southwest_pins,
309 .npins = ARRAY_SIZE(southwest_pins),
310 .groups = southwest_groups,
311 .ngroups = ARRAY_SIZE(southwest_groups),
312 .functions = southwest_functions,
313 .nfunctions = ARRAY_SIZE(southwest_functions),
314 .gpps = southwest_gpps,
315 .ngpps = ARRAY_SIZE(southwest_gpps),
317 * Southwest community can generate GPIO interrupts only for the
318 * first 8 interrupts. The upper half (8-15) can only be used to
322 .acpi_space_id = 0x91,
325 static const struct pinctrl_pin_desc north_pins[] = {
326 PINCTRL_PIN(0, "GPIO_DFX_0"),
327 PINCTRL_PIN(1, "GPIO_DFX_3"),
328 PINCTRL_PIN(2, "GPIO_DFX_7"),
329 PINCTRL_PIN(3, "GPIO_DFX_1"),
330 PINCTRL_PIN(4, "GPIO_DFX_5"),
331 PINCTRL_PIN(5, "GPIO_DFX_4"),
332 PINCTRL_PIN(6, "GPIO_DFX_8"),
333 PINCTRL_PIN(7, "GPIO_DFX_2"),
334 PINCTRL_PIN(8, "GPIO_DFX_6"),
336 PINCTRL_PIN(15, "GPIO_SUS0"),
337 PINCTRL_PIN(16, "SEC_GPIO_SUS10"),
338 PINCTRL_PIN(17, "GPIO_SUS3"),
339 PINCTRL_PIN(18, "GPIO_SUS7"),
340 PINCTRL_PIN(19, "GPIO_SUS1"),
341 PINCTRL_PIN(20, "GPIO_SUS5"),
342 PINCTRL_PIN(21, "SEC_GPIO_SUS11"),
343 PINCTRL_PIN(22, "GPIO_SUS4"),
344 PINCTRL_PIN(23, "SEC_GPIO_SUS8"),
345 PINCTRL_PIN(24, "GPIO_SUS2"),
346 PINCTRL_PIN(25, "GPIO_SUS6"),
347 PINCTRL_PIN(26, "CX_PREQ_B"),
348 PINCTRL_PIN(27, "SEC_GPIO_SUS9"),
350 PINCTRL_PIN(30, "TRST_B"),
351 PINCTRL_PIN(31, "TCK"),
352 PINCTRL_PIN(32, "PROCHOT_B"),
353 PINCTRL_PIN(33, "SVIDO_DATA"),
354 PINCTRL_PIN(34, "TMS"),
355 PINCTRL_PIN(35, "CX_PRDY_B_2"),
356 PINCTRL_PIN(36, "TDO_2"),
357 PINCTRL_PIN(37, "CX_PRDY_B"),
358 PINCTRL_PIN(38, "SVIDO_ALERT_B"),
359 PINCTRL_PIN(39, "TDO"),
360 PINCTRL_PIN(40, "SVIDO_CLK"),
361 PINCTRL_PIN(41, "TDI"),
363 PINCTRL_PIN(45, "GP_CAMERASB_05"),
364 PINCTRL_PIN(46, "GP_CAMERASB_02"),
365 PINCTRL_PIN(47, "GP_CAMERASB_08"),
366 PINCTRL_PIN(48, "GP_CAMERASB_00"),
367 PINCTRL_PIN(49, "GP_CAMERASB_06"),
368 PINCTRL_PIN(50, "GP_CAMERASB_10"),
369 PINCTRL_PIN(51, "GP_CAMERASB_03"),
370 PINCTRL_PIN(52, "GP_CAMERASB_09"),
371 PINCTRL_PIN(53, "GP_CAMERASB_01"),
372 PINCTRL_PIN(54, "GP_CAMERASB_07"),
373 PINCTRL_PIN(55, "GP_CAMERASB_11"),
374 PINCTRL_PIN(56, "GP_CAMERASB_04"),
376 PINCTRL_PIN(60, "PANEL0_BKLTEN"),
377 PINCTRL_PIN(61, "HV_DDI0_HPD"),
378 PINCTRL_PIN(62, "HV_DDI2_DDC_SDA"),
379 PINCTRL_PIN(63, "PANEL1_BKLTCTL"),
380 PINCTRL_PIN(64, "HV_DDI1_HPD"),
381 PINCTRL_PIN(65, "PANEL0_BKLTCTL"),
382 PINCTRL_PIN(66, "HV_DDI0_DDC_SDA"),
383 PINCTRL_PIN(67, "HV_DDI2_DDC_SCL"),
384 PINCTRL_PIN(68, "HV_DDI2_HPD"),
385 PINCTRL_PIN(69, "PANEL1_VDDEN"),
386 PINCTRL_PIN(70, "PANEL1_BKLTEN"),
387 PINCTRL_PIN(71, "HV_DDI0_DDC_SCL"),
388 PINCTRL_PIN(72, "PANEL0_VDDEN"),
391 static const struct intel_padgroup north_gpps[] = {
399 static const struct chv_community north_community = {
402 .npins = ARRAY_SIZE(north_pins),
404 .ngpps = ARRAY_SIZE(north_gpps),
406 * North community can generate GPIO interrupts only for the first
407 * 8 interrupts. The upper half (8-15) can only be used to trigger
411 .acpi_space_id = 0x92,
414 static const struct pinctrl_pin_desc east_pins[] = {
415 PINCTRL_PIN(0, "PMU_SLP_S3_B"),
416 PINCTRL_PIN(1, "PMU_BATLOW_B"),
417 PINCTRL_PIN(2, "SUS_STAT_B"),
418 PINCTRL_PIN(3, "PMU_SLP_S0IX_B"),
419 PINCTRL_PIN(4, "PMU_AC_PRESENT"),
420 PINCTRL_PIN(5, "PMU_PLTRST_B"),
421 PINCTRL_PIN(6, "PMU_SUSCLK"),
422 PINCTRL_PIN(7, "PMU_SLP_LAN_B"),
423 PINCTRL_PIN(8, "PMU_PWRBTN_B"),
424 PINCTRL_PIN(9, "PMU_SLP_S4_B"),
425 PINCTRL_PIN(10, "PMU_WAKE_B"),
426 PINCTRL_PIN(11, "PMU_WAKE_LAN_B"),
428 PINCTRL_PIN(15, "MF_ISH_GPIO_3"),
429 PINCTRL_PIN(16, "MF_ISH_GPIO_7"),
430 PINCTRL_PIN(17, "MF_ISH_I2C1_SCL"),
431 PINCTRL_PIN(18, "MF_ISH_GPIO_1"),
432 PINCTRL_PIN(19, "MF_ISH_GPIO_5"),
433 PINCTRL_PIN(20, "MF_ISH_GPIO_9"),
434 PINCTRL_PIN(21, "MF_ISH_GPIO_0"),
435 PINCTRL_PIN(22, "MF_ISH_GPIO_4"),
436 PINCTRL_PIN(23, "MF_ISH_GPIO_8"),
437 PINCTRL_PIN(24, "MF_ISH_GPIO_2"),
438 PINCTRL_PIN(25, "MF_ISH_GPIO_6"),
439 PINCTRL_PIN(26, "MF_ISH_I2C1_SDA"),
442 static const struct intel_padgroup east_gpps[] = {
447 static const struct chv_community east_community = {
450 .npins = ARRAY_SIZE(east_pins),
452 .ngpps = ARRAY_SIZE(east_gpps),
454 .acpi_space_id = 0x93,
457 static const struct pinctrl_pin_desc southeast_pins[] = {
458 PINCTRL_PIN(0, "MF_PLT_CLK0"),
459 PINCTRL_PIN(1, "PWM1"),
460 PINCTRL_PIN(2, "MF_PLT_CLK1"),
461 PINCTRL_PIN(3, "MF_PLT_CLK4"),
462 PINCTRL_PIN(4, "MF_PLT_CLK3"),
463 PINCTRL_PIN(5, "PWM0"),
464 PINCTRL_PIN(6, "MF_PLT_CLK5"),
465 PINCTRL_PIN(7, "MF_PLT_CLK2"),
467 PINCTRL_PIN(15, "SDMMC2_D3_CD_B"),
468 PINCTRL_PIN(16, "SDMMC1_CLK"),
469 PINCTRL_PIN(17, "SDMMC1_D0"),
470 PINCTRL_PIN(18, "SDMMC2_D1"),
471 PINCTRL_PIN(19, "SDMMC2_CLK"),
472 PINCTRL_PIN(20, "SDMMC1_D2"),
473 PINCTRL_PIN(21, "SDMMC2_D2"),
474 PINCTRL_PIN(22, "SDMMC2_CMD"),
475 PINCTRL_PIN(23, "SDMMC1_CMD"),
476 PINCTRL_PIN(24, "SDMMC1_D1"),
477 PINCTRL_PIN(25, "SDMMC2_D0"),
478 PINCTRL_PIN(26, "SDMMC1_D3_CD_B"),
480 PINCTRL_PIN(30, "SDMMC3_D1"),
481 PINCTRL_PIN(31, "SDMMC3_CLK"),
482 PINCTRL_PIN(32, "SDMMC3_D3"),
483 PINCTRL_PIN(33, "SDMMC3_D2"),
484 PINCTRL_PIN(34, "SDMMC3_CMD"),
485 PINCTRL_PIN(35, "SDMMC3_D0"),
487 PINCTRL_PIN(45, "MF_LPC_AD2"),
488 PINCTRL_PIN(46, "LPC_CLKRUNB"),
489 PINCTRL_PIN(47, "MF_LPC_AD0"),
490 PINCTRL_PIN(48, "LPC_FRAMEB"),
491 PINCTRL_PIN(49, "MF_LPC_CLKOUT1"),
492 PINCTRL_PIN(50, "MF_LPC_AD3"),
493 PINCTRL_PIN(51, "MF_LPC_CLKOUT0"),
494 PINCTRL_PIN(52, "MF_LPC_AD1"),
496 PINCTRL_PIN(60, "SPI1_MISO"),
497 PINCTRL_PIN(61, "SPI1_CSO_B"),
498 PINCTRL_PIN(62, "SPI1_CLK"),
499 PINCTRL_PIN(63, "MMC1_D6"),
500 PINCTRL_PIN(64, "SPI1_MOSI"),
501 PINCTRL_PIN(65, "MMC1_D5"),
502 PINCTRL_PIN(66, "SPI1_CS1_B"),
503 PINCTRL_PIN(67, "MMC1_D4_SD_WE"),
504 PINCTRL_PIN(68, "MMC1_D7"),
505 PINCTRL_PIN(69, "MMC1_RCLK"),
507 PINCTRL_PIN(75, "USB_OC1_B"),
508 PINCTRL_PIN(76, "PMU_RESETBUTTON_B"),
509 PINCTRL_PIN(77, "GPIO_ALERT"),
510 PINCTRL_PIN(78, "SDMMC3_PWR_EN_B"),
511 PINCTRL_PIN(79, "ILB_SERIRQ"),
512 PINCTRL_PIN(80, "USB_OC0_B"),
513 PINCTRL_PIN(81, "SDMMC3_CD_B"),
514 PINCTRL_PIN(82, "SPKR"),
515 PINCTRL_PIN(83, "SUSPWRDNACK"),
516 PINCTRL_PIN(84, "SPARE_PIN"),
517 PINCTRL_PIN(85, "SDMMC3_1P8_EN"),
520 static const unsigned southeast_pwm0_pins[] = { 5 };
521 static const unsigned southeast_pwm1_pins[] = { 1 };
522 static const unsigned southeast_sdmmc1_pins[] = {
523 16, 17, 20, 23, 24, 26, 63, 65, 67, 68, 69,
525 static const unsigned southeast_sdmmc2_pins[] = { 15, 18, 19, 21, 22, 25 };
526 static const unsigned southeast_sdmmc3_pins[] = {
527 30, 31, 32, 33, 34, 35, 78, 81, 85,
529 static const unsigned southeast_spi1_pins[] = { 60, 61, 62, 64, 66 };
530 static const unsigned southeast_spi2_pins[] = { 2, 3, 4, 6, 7 };
532 static const struct intel_pingroup southeast_groups[] = {
533 PIN_GROUP("pwm0_grp", southeast_pwm0_pins, PINMODE(1, 0)),
534 PIN_GROUP("pwm1_grp", southeast_pwm1_pins, PINMODE(1, 0)),
535 PIN_GROUP("sdmmc1_grp", southeast_sdmmc1_pins, PINMODE(1, 0)),
536 PIN_GROUP("sdmmc2_grp", southeast_sdmmc2_pins, PINMODE(1, 0)),
537 PIN_GROUP("sdmmc3_grp", southeast_sdmmc3_pins, PINMODE(1, 0)),
538 PIN_GROUP("spi1_grp", southeast_spi1_pins, PINMODE(1, 0)),
539 PIN_GROUP("spi2_grp", southeast_spi2_pins, PINMODE(4, 0)),
542 static const char * const southeast_pwm0_groups[] = { "pwm0_grp" };
543 static const char * const southeast_pwm1_groups[] = { "pwm1_grp" };
544 static const char * const southeast_sdmmc1_groups[] = { "sdmmc1_grp" };
545 static const char * const southeast_sdmmc2_groups[] = { "sdmmc2_grp" };
546 static const char * const southeast_sdmmc3_groups[] = { "sdmmc3_grp" };
547 static const char * const southeast_spi1_groups[] = { "spi1_grp" };
548 static const char * const southeast_spi2_groups[] = { "spi2_grp" };
550 static const struct intel_function southeast_functions[] = {
551 FUNCTION("pwm0", southeast_pwm0_groups),
552 FUNCTION("pwm1", southeast_pwm1_groups),
553 FUNCTION("sdmmc1", southeast_sdmmc1_groups),
554 FUNCTION("sdmmc2", southeast_sdmmc2_groups),
555 FUNCTION("sdmmc3", southeast_sdmmc3_groups),
556 FUNCTION("spi1", southeast_spi1_groups),
557 FUNCTION("spi2", southeast_spi2_groups),
560 static const struct intel_padgroup southeast_gpps[] = {
569 static const struct chv_community southeast_community = {
571 .pins = southeast_pins,
572 .npins = ARRAY_SIZE(southeast_pins),
573 .groups = southeast_groups,
574 .ngroups = ARRAY_SIZE(southeast_groups),
575 .functions = southeast_functions,
576 .nfunctions = ARRAY_SIZE(southeast_functions),
577 .gpps = southeast_gpps,
578 .ngpps = ARRAY_SIZE(southeast_gpps),
580 .acpi_space_id = 0x94,
583 static const struct chv_community *chv_communities[] = {
584 &southwest_community,
587 &southeast_community,
591 * Lock to serialize register accesses
593 * Due to a silicon issue, a shared lock must be used to prevent
594 * concurrent accesses across the 4 GPIO controllers.
596 * See Intel Atom Z8000 Processor Series Specification Update (Rev. 005),
597 * errata #CHT34, for further information.
599 static DEFINE_RAW_SPINLOCK(chv_lock);
601 static void __iomem *chv_padreg(struct chv_pinctrl *pctrl, unsigned int offset,
604 unsigned int family_no = offset / MAX_FAMILY_PAD_GPIO_NO;
605 unsigned int pad_no = offset % MAX_FAMILY_PAD_GPIO_NO;
607 offset = FAMILY_PAD_REGS_OFF + FAMILY_PAD_REGS_SIZE * family_no +
608 GPIO_REGS_SIZE * pad_no;
610 return pctrl->regs + offset + reg;
613 static void chv_writel(u32 value, void __iomem *reg)
616 /* simple readback to confirm the bus transferring done */
620 /* When Pad Cfg is locked, driver can only change GPIOTXState or GPIORXState */
621 static bool chv_pad_locked(struct chv_pinctrl *pctrl, unsigned int offset)
625 reg = chv_padreg(pctrl, offset, CHV_PADCTRL1);
626 return readl(reg) & CHV_PADCTRL1_CFGLOCK;
629 static int chv_get_groups_count(struct pinctrl_dev *pctldev)
631 struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
633 return pctrl->community->ngroups;
636 static const char *chv_get_group_name(struct pinctrl_dev *pctldev,
639 struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
641 return pctrl->community->groups[group].name;
644 static int chv_get_group_pins(struct pinctrl_dev *pctldev, unsigned int group,
645 const unsigned int **pins, unsigned int *npins)
647 struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
649 *pins = pctrl->community->groups[group].pins;
650 *npins = pctrl->community->groups[group].npins;
654 static void chv_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s,
657 struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
662 raw_spin_lock_irqsave(&chv_lock, flags);
664 ctrl0 = readl(chv_padreg(pctrl, offset, CHV_PADCTRL0));
665 ctrl1 = readl(chv_padreg(pctrl, offset, CHV_PADCTRL1));
666 locked = chv_pad_locked(pctrl, offset);
668 raw_spin_unlock_irqrestore(&chv_lock, flags);
670 if (ctrl0 & CHV_PADCTRL0_GPIOEN) {
671 seq_puts(s, "GPIO ");
675 mode = ctrl0 & CHV_PADCTRL0_PMODE_MASK;
676 mode >>= CHV_PADCTRL0_PMODE_SHIFT;
678 seq_printf(s, "mode %d ", mode);
681 seq_printf(s, "0x%08x 0x%08x", ctrl0, ctrl1);
684 seq_puts(s, " [LOCKED]");
687 static const struct pinctrl_ops chv_pinctrl_ops = {
688 .get_groups_count = chv_get_groups_count,
689 .get_group_name = chv_get_group_name,
690 .get_group_pins = chv_get_group_pins,
691 .pin_dbg_show = chv_pin_dbg_show,
694 static int chv_get_functions_count(struct pinctrl_dev *pctldev)
696 struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
698 return pctrl->community->nfunctions;
701 static const char *chv_get_function_name(struct pinctrl_dev *pctldev,
702 unsigned int function)
704 struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
706 return pctrl->community->functions[function].name;
709 static int chv_get_function_groups(struct pinctrl_dev *pctldev,
710 unsigned int function,
711 const char * const **groups,
712 unsigned int * const ngroups)
714 struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
716 *groups = pctrl->community->functions[function].groups;
717 *ngroups = pctrl->community->functions[function].ngroups;
721 static int chv_pinmux_set_mux(struct pinctrl_dev *pctldev,
722 unsigned int function, unsigned int group)
724 struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
725 const struct intel_pingroup *grp;
729 grp = &pctrl->community->groups[group];
731 raw_spin_lock_irqsave(&chv_lock, flags);
733 /* Check first that the pad is not locked */
734 for (i = 0; i < grp->npins; i++) {
735 if (chv_pad_locked(pctrl, grp->pins[i])) {
736 dev_warn(pctrl->dev, "unable to set mode for locked pin %u\n",
738 raw_spin_unlock_irqrestore(&chv_lock, flags);
743 for (i = 0; i < grp->npins; i++) {
744 int pin = grp->pins[i];
750 /* Check if there is pin-specific config */
752 mode = grp->modes[i];
756 /* Extract OE inversion */
757 invert_oe = mode & PINMODE_INVERT_OE;
758 mode &= ~PINMODE_INVERT_OE;
760 reg = chv_padreg(pctrl, pin, CHV_PADCTRL0);
762 /* Disable GPIO mode */
763 value &= ~CHV_PADCTRL0_GPIOEN;
764 /* Set to desired mode */
765 value &= ~CHV_PADCTRL0_PMODE_MASK;
766 value |= mode << CHV_PADCTRL0_PMODE_SHIFT;
767 chv_writel(value, reg);
769 /* Update for invert_oe */
770 reg = chv_padreg(pctrl, pin, CHV_PADCTRL1);
771 value = readl(reg) & ~CHV_PADCTRL1_INVRXTX_MASK;
773 value |= CHV_PADCTRL1_INVRXTX_TXENABLE;
774 chv_writel(value, reg);
776 dev_dbg(pctrl->dev, "configured pin %u mode %u OE %sinverted\n",
777 pin, mode, invert_oe ? "" : "not ");
780 raw_spin_unlock_irqrestore(&chv_lock, flags);
785 static void chv_gpio_clear_triggering(struct chv_pinctrl *pctrl,
791 reg = chv_padreg(pctrl, offset, CHV_PADCTRL1);
793 value &= ~CHV_PADCTRL1_INTWAKECFG_MASK;
794 value &= ~CHV_PADCTRL1_INVRXTX_MASK;
795 chv_writel(value, reg);
798 static int chv_gpio_request_enable(struct pinctrl_dev *pctldev,
799 struct pinctrl_gpio_range *range,
802 struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
807 raw_spin_lock_irqsave(&chv_lock, flags);
809 if (chv_pad_locked(pctrl, offset)) {
810 value = readl(chv_padreg(pctrl, offset, CHV_PADCTRL0));
811 if (!(value & CHV_PADCTRL0_GPIOEN)) {
812 /* Locked so cannot enable */
813 raw_spin_unlock_irqrestore(&chv_lock, flags);
819 /* Reset the interrupt mapping */
820 for (i = 0; i < ARRAY_SIZE(pctrl->intr_lines); i++) {
821 if (pctrl->intr_lines[i] == offset) {
822 pctrl->intr_lines[i] = 0;
827 /* Disable interrupt generation */
828 chv_gpio_clear_triggering(pctrl, offset);
830 reg = chv_padreg(pctrl, offset, CHV_PADCTRL0);
834 * If the pin is in HiZ mode (both TX and RX buffers are
835 * disabled) we turn it to be input now.
837 if ((value & CHV_PADCTRL0_GPIOCFG_MASK) ==
838 (CHV_PADCTRL0_GPIOCFG_HIZ << CHV_PADCTRL0_GPIOCFG_SHIFT)) {
839 value &= ~CHV_PADCTRL0_GPIOCFG_MASK;
840 value |= CHV_PADCTRL0_GPIOCFG_GPI <<
841 CHV_PADCTRL0_GPIOCFG_SHIFT;
844 /* Switch to a GPIO mode */
845 value |= CHV_PADCTRL0_GPIOEN;
846 chv_writel(value, reg);
849 raw_spin_unlock_irqrestore(&chv_lock, flags);
854 static void chv_gpio_disable_free(struct pinctrl_dev *pctldev,
855 struct pinctrl_gpio_range *range,
858 struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
861 raw_spin_lock_irqsave(&chv_lock, flags);
863 if (!chv_pad_locked(pctrl, offset))
864 chv_gpio_clear_triggering(pctrl, offset);
866 raw_spin_unlock_irqrestore(&chv_lock, flags);
869 static int chv_gpio_set_direction(struct pinctrl_dev *pctldev,
870 struct pinctrl_gpio_range *range,
871 unsigned int offset, bool input)
873 struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
874 void __iomem *reg = chv_padreg(pctrl, offset, CHV_PADCTRL0);
878 raw_spin_lock_irqsave(&chv_lock, flags);
880 ctrl0 = readl(reg) & ~CHV_PADCTRL0_GPIOCFG_MASK;
882 ctrl0 |= CHV_PADCTRL0_GPIOCFG_GPI << CHV_PADCTRL0_GPIOCFG_SHIFT;
884 ctrl0 |= CHV_PADCTRL0_GPIOCFG_GPO << CHV_PADCTRL0_GPIOCFG_SHIFT;
885 chv_writel(ctrl0, reg);
887 raw_spin_unlock_irqrestore(&chv_lock, flags);
892 static const struct pinmux_ops chv_pinmux_ops = {
893 .get_functions_count = chv_get_functions_count,
894 .get_function_name = chv_get_function_name,
895 .get_function_groups = chv_get_function_groups,
896 .set_mux = chv_pinmux_set_mux,
897 .gpio_request_enable = chv_gpio_request_enable,
898 .gpio_disable_free = chv_gpio_disable_free,
899 .gpio_set_direction = chv_gpio_set_direction,
902 static int chv_config_get(struct pinctrl_dev *pctldev, unsigned int pin,
903 unsigned long *config)
905 struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
906 enum pin_config_param param = pinconf_to_config_param(*config);
912 raw_spin_lock_irqsave(&chv_lock, flags);
913 ctrl0 = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0));
914 ctrl1 = readl(chv_padreg(pctrl, pin, CHV_PADCTRL1));
915 raw_spin_unlock_irqrestore(&chv_lock, flags);
917 term = (ctrl0 & CHV_PADCTRL0_TERM_MASK) >> CHV_PADCTRL0_TERM_SHIFT;
920 case PIN_CONFIG_BIAS_DISABLE:
925 case PIN_CONFIG_BIAS_PULL_UP:
926 if (!(ctrl0 & CHV_PADCTRL0_TERM_UP))
930 case CHV_PADCTRL0_TERM_20K:
933 case CHV_PADCTRL0_TERM_5K:
936 case CHV_PADCTRL0_TERM_1K:
943 case PIN_CONFIG_BIAS_PULL_DOWN:
944 if (!term || (ctrl0 & CHV_PADCTRL0_TERM_UP))
948 case CHV_PADCTRL0_TERM_20K:
951 case CHV_PADCTRL0_TERM_5K:
958 case PIN_CONFIG_DRIVE_OPEN_DRAIN:
959 if (!(ctrl1 & CHV_PADCTRL1_ODEN))
963 case PIN_CONFIG_BIAS_HIGH_IMPEDANCE: {
966 cfg = ctrl0 & CHV_PADCTRL0_GPIOCFG_MASK;
967 cfg >>= CHV_PADCTRL0_GPIOCFG_SHIFT;
968 if (cfg != CHV_PADCTRL0_GPIOCFG_HIZ)
978 *config = pinconf_to_config_packed(param, arg);
982 static int chv_config_set_pull(struct chv_pinctrl *pctrl, unsigned int pin,
983 enum pin_config_param param, u32 arg)
985 void __iomem *reg = chv_padreg(pctrl, pin, CHV_PADCTRL0);
989 raw_spin_lock_irqsave(&chv_lock, flags);
993 case PIN_CONFIG_BIAS_DISABLE:
994 ctrl0 &= ~(CHV_PADCTRL0_TERM_MASK | CHV_PADCTRL0_TERM_UP);
997 case PIN_CONFIG_BIAS_PULL_UP:
998 ctrl0 &= ~(CHV_PADCTRL0_TERM_MASK | CHV_PADCTRL0_TERM_UP);
1002 /* For 1k there is only pull up */
1003 pull = CHV_PADCTRL0_TERM_1K << CHV_PADCTRL0_TERM_SHIFT;
1006 pull = CHV_PADCTRL0_TERM_5K << CHV_PADCTRL0_TERM_SHIFT;
1009 pull = CHV_PADCTRL0_TERM_20K << CHV_PADCTRL0_TERM_SHIFT;
1012 raw_spin_unlock_irqrestore(&chv_lock, flags);
1016 ctrl0 |= CHV_PADCTRL0_TERM_UP | pull;
1019 case PIN_CONFIG_BIAS_PULL_DOWN:
1020 ctrl0 &= ~(CHV_PADCTRL0_TERM_MASK | CHV_PADCTRL0_TERM_UP);
1024 pull = CHV_PADCTRL0_TERM_5K << CHV_PADCTRL0_TERM_SHIFT;
1027 pull = CHV_PADCTRL0_TERM_20K << CHV_PADCTRL0_TERM_SHIFT;
1030 raw_spin_unlock_irqrestore(&chv_lock, flags);
1038 raw_spin_unlock_irqrestore(&chv_lock, flags);
1042 chv_writel(ctrl0, reg);
1043 raw_spin_unlock_irqrestore(&chv_lock, flags);
1048 static int chv_config_set_oden(struct chv_pinctrl *pctrl, unsigned int pin,
1051 void __iomem *reg = chv_padreg(pctrl, pin, CHV_PADCTRL1);
1052 unsigned long flags;
1055 raw_spin_lock_irqsave(&chv_lock, flags);
1059 ctrl1 |= CHV_PADCTRL1_ODEN;
1061 ctrl1 &= ~CHV_PADCTRL1_ODEN;
1063 chv_writel(ctrl1, reg);
1064 raw_spin_unlock_irqrestore(&chv_lock, flags);
1069 static int chv_config_set(struct pinctrl_dev *pctldev, unsigned int pin,
1070 unsigned long *configs, unsigned int nconfigs)
1072 struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
1073 enum pin_config_param param;
1077 if (chv_pad_locked(pctrl, pin))
1080 for (i = 0; i < nconfigs; i++) {
1081 param = pinconf_to_config_param(configs[i]);
1082 arg = pinconf_to_config_argument(configs[i]);
1085 case PIN_CONFIG_BIAS_DISABLE:
1086 case PIN_CONFIG_BIAS_PULL_UP:
1087 case PIN_CONFIG_BIAS_PULL_DOWN:
1088 ret = chv_config_set_pull(pctrl, pin, param, arg);
1093 case PIN_CONFIG_DRIVE_PUSH_PULL:
1094 ret = chv_config_set_oden(pctrl, pin, false);
1099 case PIN_CONFIG_DRIVE_OPEN_DRAIN:
1100 ret = chv_config_set_oden(pctrl, pin, true);
1109 dev_dbg(pctrl->dev, "pin %d set config %d arg %u\n", pin,
1116 static int chv_config_group_get(struct pinctrl_dev *pctldev,
1118 unsigned long *config)
1120 const unsigned int *pins;
1124 ret = chv_get_group_pins(pctldev, group, &pins, &npins);
1128 ret = chv_config_get(pctldev, pins[0], config);
1135 static int chv_config_group_set(struct pinctrl_dev *pctldev,
1136 unsigned int group, unsigned long *configs,
1137 unsigned int num_configs)
1139 const unsigned int *pins;
1143 ret = chv_get_group_pins(pctldev, group, &pins, &npins);
1147 for (i = 0; i < npins; i++) {
1148 ret = chv_config_set(pctldev, pins[i], configs, num_configs);
1156 static const struct pinconf_ops chv_pinconf_ops = {
1158 .pin_config_set = chv_config_set,
1159 .pin_config_get = chv_config_get,
1160 .pin_config_group_get = chv_config_group_get,
1161 .pin_config_group_set = chv_config_group_set,
1164 static struct pinctrl_desc chv_pinctrl_desc = {
1165 .pctlops = &chv_pinctrl_ops,
1166 .pmxops = &chv_pinmux_ops,
1167 .confops = &chv_pinconf_ops,
1168 .owner = THIS_MODULE,
1171 static int chv_gpio_get(struct gpio_chip *chip, unsigned int offset)
1173 struct chv_pinctrl *pctrl = gpiochip_get_data(chip);
1174 unsigned long flags;
1177 raw_spin_lock_irqsave(&chv_lock, flags);
1178 ctrl0 = readl(chv_padreg(pctrl, offset, CHV_PADCTRL0));
1179 raw_spin_unlock_irqrestore(&chv_lock, flags);
1181 cfg = ctrl0 & CHV_PADCTRL0_GPIOCFG_MASK;
1182 cfg >>= CHV_PADCTRL0_GPIOCFG_SHIFT;
1184 if (cfg == CHV_PADCTRL0_GPIOCFG_GPO)
1185 return !!(ctrl0 & CHV_PADCTRL0_GPIOTXSTATE);
1186 return !!(ctrl0 & CHV_PADCTRL0_GPIORXSTATE);
1189 static void chv_gpio_set(struct gpio_chip *chip, unsigned int offset, int value)
1191 struct chv_pinctrl *pctrl = gpiochip_get_data(chip);
1192 unsigned long flags;
1196 raw_spin_lock_irqsave(&chv_lock, flags);
1198 reg = chv_padreg(pctrl, offset, CHV_PADCTRL0);
1202 ctrl0 |= CHV_PADCTRL0_GPIOTXSTATE;
1204 ctrl0 &= ~CHV_PADCTRL0_GPIOTXSTATE;
1206 chv_writel(ctrl0, reg);
1208 raw_spin_unlock_irqrestore(&chv_lock, flags);
1211 static int chv_gpio_get_direction(struct gpio_chip *chip, unsigned int offset)
1213 struct chv_pinctrl *pctrl = gpiochip_get_data(chip);
1214 u32 ctrl0, direction;
1215 unsigned long flags;
1217 raw_spin_lock_irqsave(&chv_lock, flags);
1218 ctrl0 = readl(chv_padreg(pctrl, offset, CHV_PADCTRL0));
1219 raw_spin_unlock_irqrestore(&chv_lock, flags);
1221 direction = ctrl0 & CHV_PADCTRL0_GPIOCFG_MASK;
1222 direction >>= CHV_PADCTRL0_GPIOCFG_SHIFT;
1224 if (direction == CHV_PADCTRL0_GPIOCFG_GPO)
1225 return GPIO_LINE_DIRECTION_OUT;
1227 return GPIO_LINE_DIRECTION_IN;
1230 static int chv_gpio_direction_input(struct gpio_chip *chip, unsigned int offset)
1232 return pinctrl_gpio_direction_input(chip->base + offset);
1235 static int chv_gpio_direction_output(struct gpio_chip *chip, unsigned int offset,
1238 chv_gpio_set(chip, offset, value);
1239 return pinctrl_gpio_direction_output(chip->base + offset);
1242 static const struct gpio_chip chv_gpio_chip = {
1243 .owner = THIS_MODULE,
1244 .request = gpiochip_generic_request,
1245 .free = gpiochip_generic_free,
1246 .get_direction = chv_gpio_get_direction,
1247 .direction_input = chv_gpio_direction_input,
1248 .direction_output = chv_gpio_direction_output,
1249 .get = chv_gpio_get,
1250 .set = chv_gpio_set,
1253 static void chv_gpio_irq_ack(struct irq_data *d)
1255 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
1256 struct chv_pinctrl *pctrl = gpiochip_get_data(gc);
1257 int pin = irqd_to_hwirq(d);
1260 raw_spin_lock(&chv_lock);
1262 intr_line = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0));
1263 intr_line &= CHV_PADCTRL0_INTSEL_MASK;
1264 intr_line >>= CHV_PADCTRL0_INTSEL_SHIFT;
1265 chv_writel(BIT(intr_line), pctrl->regs + CHV_INTSTAT);
1267 raw_spin_unlock(&chv_lock);
1270 static void chv_gpio_irq_mask_unmask(struct irq_data *d, bool mask)
1272 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
1273 struct chv_pinctrl *pctrl = gpiochip_get_data(gc);
1274 int pin = irqd_to_hwirq(d);
1275 u32 value, intr_line;
1276 unsigned long flags;
1278 raw_spin_lock_irqsave(&chv_lock, flags);
1280 intr_line = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0));
1281 intr_line &= CHV_PADCTRL0_INTSEL_MASK;
1282 intr_line >>= CHV_PADCTRL0_INTSEL_SHIFT;
1284 value = readl(pctrl->regs + CHV_INTMASK);
1286 value &= ~BIT(intr_line);
1288 value |= BIT(intr_line);
1289 chv_writel(value, pctrl->regs + CHV_INTMASK);
1291 raw_spin_unlock_irqrestore(&chv_lock, flags);
1294 static void chv_gpio_irq_mask(struct irq_data *d)
1296 chv_gpio_irq_mask_unmask(d, true);
1299 static void chv_gpio_irq_unmask(struct irq_data *d)
1301 chv_gpio_irq_mask_unmask(d, false);
1304 static unsigned chv_gpio_irq_startup(struct irq_data *d)
1307 * Check if the interrupt has been requested with 0 as triggering
1308 * type. In that case it is assumed that the current values
1309 * programmed to the hardware are used (e.g BIOS configured
1312 * In that case ->irq_set_type() will never be called so we need to
1313 * read back the values from hardware now, set correct flow handler
1314 * and update mappings before the interrupt is being used.
1316 if (irqd_get_trigger_type(d) == IRQ_TYPE_NONE) {
1317 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
1318 struct chv_pinctrl *pctrl = gpiochip_get_data(gc);
1319 unsigned int pin = irqd_to_hwirq(d);
1320 irq_flow_handler_t handler;
1321 unsigned long flags;
1324 raw_spin_lock_irqsave(&chv_lock, flags);
1325 intsel = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0));
1326 intsel &= CHV_PADCTRL0_INTSEL_MASK;
1327 intsel >>= CHV_PADCTRL0_INTSEL_SHIFT;
1329 value = readl(chv_padreg(pctrl, pin, CHV_PADCTRL1));
1330 if (value & CHV_PADCTRL1_INTWAKECFG_LEVEL)
1331 handler = handle_level_irq;
1333 handler = handle_edge_irq;
1335 if (!pctrl->intr_lines[intsel]) {
1336 irq_set_handler_locked(d, handler);
1337 pctrl->intr_lines[intsel] = pin;
1339 raw_spin_unlock_irqrestore(&chv_lock, flags);
1342 chv_gpio_irq_unmask(d);
1346 static int chv_gpio_irq_type(struct irq_data *d, unsigned int type)
1348 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
1349 struct chv_pinctrl *pctrl = gpiochip_get_data(gc);
1350 unsigned int pin = irqd_to_hwirq(d);
1351 unsigned long flags;
1354 raw_spin_lock_irqsave(&chv_lock, flags);
1357 * Pins which can be used as shared interrupt are configured in
1358 * BIOS. Driver trusts BIOS configurations and assigns different
1359 * handler according to the irq type.
1361 * Driver needs to save the mapping between each pin and
1362 * its interrupt line.
1363 * 1. If the pin cfg is locked in BIOS:
1364 * Trust BIOS has programmed IntWakeCfg bits correctly,
1365 * driver just needs to save the mapping.
1366 * 2. If the pin cfg is not locked in BIOS:
1367 * Driver programs the IntWakeCfg bits and save the mapping.
1369 if (!chv_pad_locked(pctrl, pin)) {
1370 void __iomem *reg = chv_padreg(pctrl, pin, CHV_PADCTRL1);
1373 value &= ~CHV_PADCTRL1_INTWAKECFG_MASK;
1374 value &= ~CHV_PADCTRL1_INVRXTX_MASK;
1376 if (type & IRQ_TYPE_EDGE_BOTH) {
1377 if ((type & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH)
1378 value |= CHV_PADCTRL1_INTWAKECFG_BOTH;
1379 else if (type & IRQ_TYPE_EDGE_RISING)
1380 value |= CHV_PADCTRL1_INTWAKECFG_RISING;
1381 else if (type & IRQ_TYPE_EDGE_FALLING)
1382 value |= CHV_PADCTRL1_INTWAKECFG_FALLING;
1383 } else if (type & IRQ_TYPE_LEVEL_MASK) {
1384 value |= CHV_PADCTRL1_INTWAKECFG_LEVEL;
1385 if (type & IRQ_TYPE_LEVEL_LOW)
1386 value |= CHV_PADCTRL1_INVRXTX_RXDATA;
1389 chv_writel(value, reg);
1392 value = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0));
1393 value &= CHV_PADCTRL0_INTSEL_MASK;
1394 value >>= CHV_PADCTRL0_INTSEL_SHIFT;
1396 pctrl->intr_lines[value] = pin;
1398 if (type & IRQ_TYPE_EDGE_BOTH)
1399 irq_set_handler_locked(d, handle_edge_irq);
1400 else if (type & IRQ_TYPE_LEVEL_MASK)
1401 irq_set_handler_locked(d, handle_level_irq);
1403 raw_spin_unlock_irqrestore(&chv_lock, flags);
1408 static void chv_gpio_irq_handler(struct irq_desc *desc)
1410 struct gpio_chip *gc = irq_desc_get_handler_data(desc);
1411 struct chv_pinctrl *pctrl = gpiochip_get_data(gc);
1412 struct irq_chip *chip = irq_desc_get_chip(desc);
1413 unsigned long pending;
1414 unsigned long flags;
1417 chained_irq_enter(chip, desc);
1419 raw_spin_lock_irqsave(&chv_lock, flags);
1420 pending = readl(pctrl->regs + CHV_INTSTAT);
1421 raw_spin_unlock_irqrestore(&chv_lock, flags);
1423 for_each_set_bit(intr_line, &pending, pctrl->community->nirqs) {
1424 unsigned int irq, offset;
1426 offset = pctrl->intr_lines[intr_line];
1427 irq = irq_find_mapping(gc->irq.domain, offset);
1428 generic_handle_irq(irq);
1431 chained_irq_exit(chip, desc);
1435 * Certain machines seem to hardcode Linux IRQ numbers in their ACPI
1436 * tables. Since we leave GPIOs that are not capable of generating
1437 * interrupts out of the irqdomain the numbering will be different and
1438 * cause devices using the hardcoded IRQ numbers fail. In order not to
1439 * break such machines we will only mask pins from irqdomain if the machine
1440 * is not listed below.
1442 static const struct dmi_system_id chv_no_valid_mask[] = {
1443 /* See https://bugzilla.kernel.org/show_bug.cgi?id=194945 */
1445 .ident = "Intel_Strago based Chromebooks (All models)",
1447 DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
1448 DMI_MATCH(DMI_PRODUCT_FAMILY, "Intel_Strago"),
1452 .ident = "HP Chromebook 11 G5 (Setzer)",
1454 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
1455 DMI_MATCH(DMI_PRODUCT_NAME, "Setzer"),
1459 .ident = "Acer Chromebook R11 (Cyan)",
1461 DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
1462 DMI_MATCH(DMI_PRODUCT_NAME, "Cyan"),
1466 .ident = "Samsung Chromebook 3 (Celes)",
1468 DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
1469 DMI_MATCH(DMI_PRODUCT_NAME, "Celes"),
1475 static void chv_init_irq_valid_mask(struct gpio_chip *chip,
1476 unsigned long *valid_mask,
1477 unsigned int ngpios)
1479 struct chv_pinctrl *pctrl = gpiochip_get_data(chip);
1480 const struct chv_community *community = pctrl->community;
1483 /* Do not add GPIOs that can only generate GPEs to the IRQ domain */
1484 for (i = 0; i < community->npins; i++) {
1485 const struct pinctrl_pin_desc *desc;
1488 desc = &community->pins[i];
1490 intsel = readl(chv_padreg(pctrl, desc->number, CHV_PADCTRL0));
1491 intsel &= CHV_PADCTRL0_INTSEL_MASK;
1492 intsel >>= CHV_PADCTRL0_INTSEL_SHIFT;
1494 if (intsel >= community->nirqs)
1495 clear_bit(desc->number, valid_mask);
1499 static int chv_gpio_irq_init_hw(struct gpio_chip *chip)
1501 struct chv_pinctrl *pctrl = gpiochip_get_data(chip);
1504 * The same set of machines in chv_no_valid_mask[] have incorrectly
1505 * configured GPIOs that generate spurious interrupts so we use
1506 * this same list to apply another quirk for them.
1508 * See also https://bugzilla.kernel.org/show_bug.cgi?id=197953.
1510 if (!pctrl->chip.irq.init_valid_mask) {
1512 * Mask all interrupts the community is able to generate
1513 * but leave the ones that can only generate GPEs unmasked.
1515 chv_writel(GENMASK(31, pctrl->community->nirqs),
1516 pctrl->regs + CHV_INTMASK);
1519 /* Clear all interrupts */
1520 chv_writel(0xffff, pctrl->regs + CHV_INTSTAT);
1525 static int chv_gpio_add_pin_ranges(struct gpio_chip *chip)
1527 struct chv_pinctrl *pctrl = gpiochip_get_data(chip);
1528 const struct chv_community *community = pctrl->community;
1529 const struct intel_padgroup *gpp;
1532 for (i = 0; i < community->ngpps; i++) {
1533 gpp = &community->gpps[i];
1534 ret = gpiochip_add_pin_range(chip, dev_name(pctrl->dev),
1535 gpp->base, gpp->base,
1538 dev_err(pctrl->dev, "failed to add GPIO pin range\n");
1546 static int chv_gpio_probe(struct chv_pinctrl *pctrl, int irq)
1548 const struct intel_padgroup *gpp;
1549 struct gpio_chip *chip = &pctrl->chip;
1550 bool need_valid_mask = !dmi_check_system(chv_no_valid_mask);
1551 const struct chv_community *community = pctrl->community;
1552 int ret, i, irq_base;
1554 *chip = chv_gpio_chip;
1556 chip->ngpio = community->pins[community->npins - 1].number + 1;
1557 chip->label = dev_name(pctrl->dev);
1558 chip->add_pin_ranges = chv_gpio_add_pin_ranges;
1559 chip->parent = pctrl->dev;
1563 pctrl->irqchip.name = "chv-gpio";
1564 pctrl->irqchip.irq_startup = chv_gpio_irq_startup;
1565 pctrl->irqchip.irq_ack = chv_gpio_irq_ack;
1566 pctrl->irqchip.irq_mask = chv_gpio_irq_mask;
1567 pctrl->irqchip.irq_unmask = chv_gpio_irq_unmask;
1568 pctrl->irqchip.irq_set_type = chv_gpio_irq_type;
1569 pctrl->irqchip.flags = IRQCHIP_SKIP_SET_WAKE;
1571 chip->irq.chip = &pctrl->irqchip;
1572 chip->irq.init_hw = chv_gpio_irq_init_hw;
1573 chip->irq.parent_handler = chv_gpio_irq_handler;
1574 chip->irq.num_parents = 1;
1575 chip->irq.parents = &pctrl->irq;
1576 chip->irq.default_type = IRQ_TYPE_NONE;
1577 chip->irq.handler = handle_bad_irq;
1578 if (need_valid_mask) {
1579 chip->irq.init_valid_mask = chv_init_irq_valid_mask;
1581 irq_base = devm_irq_alloc_descs(pctrl->dev, -1, 0,
1582 community->npins, NUMA_NO_NODE);
1584 dev_err(pctrl->dev, "Failed to allocate IRQ numbers\n");
1589 ret = devm_gpiochip_add_data(pctrl->dev, chip, pctrl);
1591 dev_err(pctrl->dev, "Failed to register gpiochip\n");
1595 if (!need_valid_mask) {
1596 for (i = 0; i < community->ngpps; i++) {
1597 gpp = &community->gpps[i];
1599 irq_domain_associate_many(chip->irq.domain, irq_base,
1600 gpp->base, gpp->size);
1601 irq_base += gpp->size;
1608 static acpi_status chv_pinctrl_mmio_access_handler(u32 function,
1609 acpi_physical_address address, u32 bits, u64 *value,
1610 void *handler_context, void *region_context)
1612 struct chv_pinctrl *pctrl = region_context;
1613 unsigned long flags;
1614 acpi_status ret = AE_OK;
1616 raw_spin_lock_irqsave(&chv_lock, flags);
1618 if (function == ACPI_WRITE)
1619 chv_writel((u32)(*value), pctrl->regs + (u32)address);
1620 else if (function == ACPI_READ)
1621 *value = readl(pctrl->regs + (u32)address);
1623 ret = AE_BAD_PARAMETER;
1625 raw_spin_unlock_irqrestore(&chv_lock, flags);
1630 static int chv_pinctrl_probe(struct platform_device *pdev)
1632 struct chv_pinctrl *pctrl;
1633 struct acpi_device *adev;
1637 adev = ACPI_COMPANION(&pdev->dev);
1641 pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL);
1645 for (i = 0; i < ARRAY_SIZE(chv_communities); i++)
1646 if (!strcmp(adev->pnp.unique_id, chv_communities[i]->uid)) {
1647 pctrl->community = chv_communities[i];
1650 if (i == ARRAY_SIZE(chv_communities))
1653 pctrl->dev = &pdev->dev;
1655 #ifdef CONFIG_PM_SLEEP
1656 pctrl->saved_pin_context = devm_kcalloc(pctrl->dev,
1657 pctrl->community->npins, sizeof(*pctrl->saved_pin_context),
1659 if (!pctrl->saved_pin_context)
1663 pctrl->regs = devm_platform_ioremap_resource(pdev, 0);
1664 if (IS_ERR(pctrl->regs))
1665 return PTR_ERR(pctrl->regs);
1667 irq = platform_get_irq(pdev, 0);
1671 pctrl->pctldesc = chv_pinctrl_desc;
1672 pctrl->pctldesc.name = dev_name(&pdev->dev);
1673 pctrl->pctldesc.pins = pctrl->community->pins;
1674 pctrl->pctldesc.npins = pctrl->community->npins;
1676 pctrl->pctldev = devm_pinctrl_register(&pdev->dev, &pctrl->pctldesc,
1678 if (IS_ERR(pctrl->pctldev)) {
1679 dev_err(&pdev->dev, "failed to register pinctrl driver\n");
1680 return PTR_ERR(pctrl->pctldev);
1683 ret = chv_gpio_probe(pctrl, irq);
1687 status = acpi_install_address_space_handler(adev->handle,
1688 pctrl->community->acpi_space_id,
1689 chv_pinctrl_mmio_access_handler,
1691 if (ACPI_FAILURE(status))
1692 dev_err(&pdev->dev, "failed to install ACPI addr space handler\n");
1694 platform_set_drvdata(pdev, pctrl);
1699 static int chv_pinctrl_remove(struct platform_device *pdev)
1701 struct chv_pinctrl *pctrl = platform_get_drvdata(pdev);
1703 acpi_remove_address_space_handler(ACPI_COMPANION(&pdev->dev),
1704 pctrl->community->acpi_space_id,
1705 chv_pinctrl_mmio_access_handler);
1710 #ifdef CONFIG_PM_SLEEP
1711 static int chv_pinctrl_suspend_noirq(struct device *dev)
1713 struct chv_pinctrl *pctrl = dev_get_drvdata(dev);
1714 unsigned long flags;
1717 raw_spin_lock_irqsave(&chv_lock, flags);
1719 pctrl->saved_intmask = readl(pctrl->regs + CHV_INTMASK);
1721 for (i = 0; i < pctrl->community->npins; i++) {
1722 const struct pinctrl_pin_desc *desc;
1723 struct chv_pin_context *ctx;
1726 desc = &pctrl->community->pins[i];
1727 if (chv_pad_locked(pctrl, desc->number))
1730 ctx = &pctrl->saved_pin_context[i];
1732 reg = chv_padreg(pctrl, desc->number, CHV_PADCTRL0);
1733 ctx->padctrl0 = readl(reg) & ~CHV_PADCTRL0_GPIORXSTATE;
1735 reg = chv_padreg(pctrl, desc->number, CHV_PADCTRL1);
1736 ctx->padctrl1 = readl(reg);
1739 raw_spin_unlock_irqrestore(&chv_lock, flags);
1744 static int chv_pinctrl_resume_noirq(struct device *dev)
1746 struct chv_pinctrl *pctrl = dev_get_drvdata(dev);
1747 unsigned long flags;
1750 raw_spin_lock_irqsave(&chv_lock, flags);
1753 * Mask all interrupts before restoring per-pin configuration
1754 * registers because we don't know in which state BIOS left them
1755 * upon exiting suspend.
1757 chv_writel(0, pctrl->regs + CHV_INTMASK);
1759 for (i = 0; i < pctrl->community->npins; i++) {
1760 const struct pinctrl_pin_desc *desc;
1761 const struct chv_pin_context *ctx;
1765 desc = &pctrl->community->pins[i];
1766 if (chv_pad_locked(pctrl, desc->number))
1769 ctx = &pctrl->saved_pin_context[i];
1771 /* Only restore if our saved state differs from the current */
1772 reg = chv_padreg(pctrl, desc->number, CHV_PADCTRL0);
1773 val = readl(reg) & ~CHV_PADCTRL0_GPIORXSTATE;
1774 if (ctx->padctrl0 != val) {
1775 chv_writel(ctx->padctrl0, reg);
1776 dev_dbg(pctrl->dev, "restored pin %2u ctrl0 0x%08x\n",
1777 desc->number, readl(reg));
1780 reg = chv_padreg(pctrl, desc->number, CHV_PADCTRL1);
1782 if (ctx->padctrl1 != val) {
1783 chv_writel(ctx->padctrl1, reg);
1784 dev_dbg(pctrl->dev, "restored pin %2u ctrl1 0x%08x\n",
1785 desc->number, readl(reg));
1790 * Now that all pins are restored to known state, we can restore
1791 * the interrupt mask register as well.
1793 chv_writel(0xffff, pctrl->regs + CHV_INTSTAT);
1794 chv_writel(pctrl->saved_intmask, pctrl->regs + CHV_INTMASK);
1796 raw_spin_unlock_irqrestore(&chv_lock, flags);
1802 static const struct dev_pm_ops chv_pinctrl_pm_ops = {
1803 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(chv_pinctrl_suspend_noirq,
1804 chv_pinctrl_resume_noirq)
1807 static const struct acpi_device_id chv_pinctrl_acpi_match[] = {
1811 MODULE_DEVICE_TABLE(acpi, chv_pinctrl_acpi_match);
1813 static struct platform_driver chv_pinctrl_driver = {
1814 .probe = chv_pinctrl_probe,
1815 .remove = chv_pinctrl_remove,
1817 .name = "cherryview-pinctrl",
1818 .pm = &chv_pinctrl_pm_ops,
1819 .acpi_match_table = chv_pinctrl_acpi_match,
1823 static int __init chv_pinctrl_init(void)
1825 return platform_driver_register(&chv_pinctrl_driver);
1827 subsys_initcall(chv_pinctrl_init);
1829 static void __exit chv_pinctrl_exit(void)
1831 platform_driver_unregister(&chv_pinctrl_driver);
1833 module_exit(chv_pinctrl_exit);
1835 MODULE_AUTHOR("Mika Westerberg <mika.westerberg@linux.intel.com>");
1836 MODULE_DESCRIPTION("Intel Cherryview/Braswell pinctrl driver");
1837 MODULE_LICENSE("GPL v2");