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/dmi.h>
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/init.h>
17 #include <linux/types.h>
18 #include <linux/gpio.h>
19 #include <linux/gpio/driver.h>
20 #include <linux/acpi.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>
25 #include <linux/platform_device.h>
27 #define CHV_INTSTAT 0x300
28 #define CHV_INTMASK 0x380
30 #define FAMILY_PAD_REGS_OFF 0x4400
31 #define FAMILY_PAD_REGS_SIZE 0x400
32 #define MAX_FAMILY_PAD_GPIO_NO 15
33 #define GPIO_REGS_SIZE 8
35 #define CHV_PADCTRL0 0x000
36 #define CHV_PADCTRL0_INTSEL_SHIFT 28
37 #define CHV_PADCTRL0_INTSEL_MASK (0xf << CHV_PADCTRL0_INTSEL_SHIFT)
38 #define CHV_PADCTRL0_TERM_UP BIT(23)
39 #define CHV_PADCTRL0_TERM_SHIFT 20
40 #define CHV_PADCTRL0_TERM_MASK (7 << CHV_PADCTRL0_TERM_SHIFT)
41 #define CHV_PADCTRL0_TERM_20K 1
42 #define CHV_PADCTRL0_TERM_5K 2
43 #define CHV_PADCTRL0_TERM_1K 4
44 #define CHV_PADCTRL0_PMODE_SHIFT 16
45 #define CHV_PADCTRL0_PMODE_MASK (0xf << CHV_PADCTRL0_PMODE_SHIFT)
46 #define CHV_PADCTRL0_GPIOEN BIT(15)
47 #define CHV_PADCTRL0_GPIOCFG_SHIFT 8
48 #define CHV_PADCTRL0_GPIOCFG_MASK (7 << CHV_PADCTRL0_GPIOCFG_SHIFT)
49 #define CHV_PADCTRL0_GPIOCFG_GPIO 0
50 #define CHV_PADCTRL0_GPIOCFG_GPO 1
51 #define CHV_PADCTRL0_GPIOCFG_GPI 2
52 #define CHV_PADCTRL0_GPIOCFG_HIZ 3
53 #define CHV_PADCTRL0_GPIOTXSTATE BIT(1)
54 #define CHV_PADCTRL0_GPIORXSTATE BIT(0)
56 #define CHV_PADCTRL1 0x004
57 #define CHV_PADCTRL1_CFGLOCK BIT(31)
58 #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)
61 #define CHV_PADCTRL1_ODEN BIT(3)
62 #define CHV_PADCTRL1_INVRXTX_RXDATA (4 << CHV_PADCTRL1_INVRXTX_SHIFT)
63 #define CHV_PADCTRL1_INTWAKECFG_MASK 7
64 #define CHV_PADCTRL1_INTWAKECFG_FALLING 1
65 #define CHV_PADCTRL1_INTWAKECFG_RISING 2
66 #define CHV_PADCTRL1_INTWAKECFG_BOTH 3
67 #define CHV_PADCTRL1_INTWAKECFG_LEVEL 4
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
75 struct chv_alternate_function {
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
95 struct chv_alternate_function altfunc;
96 const struct chv_alternate_function *overrides;
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
106 struct chv_function {
108 const char * const *groups;
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
117 struct chv_gpio_pinrange {
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
135 struct chv_community {
137 const struct pinctrl_pin_desc *pins;
139 const struct chv_pingroup *groups;
141 const struct chv_function *functions;
143 const struct chv_gpio_pinrange *gpio_ranges;
146 acpi_adr_space_type acpi_space_id;
149 struct chv_pin_context {
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
166 * The first group in @groups is expected to contain all pins that can be
171 struct pinctrl_desc pctldesc;
172 struct pinctrl_dev *pctldev;
173 struct gpio_chip chip;
174 struct irq_chip irqchip;
176 unsigned intr_lines[16];
177 const struct chv_community *community;
179 struct chv_pin_context *saved_pin_context;
182 #define ALTERNATE_FUNCTION(p, m, i) \
189 #define PIN_GROUP(n, p, m, i) \
193 .npins = ARRAY_SIZE((p)), \
194 .altfunc.mode = (m), \
195 .altfunc.invert_oe = (i), \
198 #define PIN_GROUP_WITH_OVERRIDE(n, p, m, i, o) \
202 .npins = ARRAY_SIZE((p)), \
203 .altfunc.mode = (m), \
204 .altfunc.invert_oe = (i), \
206 .noverrides = ARRAY_SIZE((o)), \
209 #define FUNCTION(n, g) \
213 .ngroups = ARRAY_SIZE((g)), \
216 #define GPIO_PINRANGE(start, end) \
219 .npins = (end) - (start) + 1, \
222 static const struct pinctrl_pin_desc southwest_pins[] = {
223 PINCTRL_PIN(0, "FST_SPI_D2"),
224 PINCTRL_PIN(1, "FST_SPI_D0"),
225 PINCTRL_PIN(2, "FST_SPI_CLK"),
226 PINCTRL_PIN(3, "FST_SPI_D3"),
227 PINCTRL_PIN(4, "FST_SPI_CS1_B"),
228 PINCTRL_PIN(5, "FST_SPI_D1"),
229 PINCTRL_PIN(6, "FST_SPI_CS0_B"),
230 PINCTRL_PIN(7, "FST_SPI_CS2_B"),
232 PINCTRL_PIN(15, "UART1_RTS_B"),
233 PINCTRL_PIN(16, "UART1_RXD"),
234 PINCTRL_PIN(17, "UART2_RXD"),
235 PINCTRL_PIN(18, "UART1_CTS_B"),
236 PINCTRL_PIN(19, "UART2_RTS_B"),
237 PINCTRL_PIN(20, "UART1_TXD"),
238 PINCTRL_PIN(21, "UART2_TXD"),
239 PINCTRL_PIN(22, "UART2_CTS_B"),
241 PINCTRL_PIN(30, "MF_HDA_CLK"),
242 PINCTRL_PIN(31, "MF_HDA_RSTB"),
243 PINCTRL_PIN(32, "MF_HDA_SDIO"),
244 PINCTRL_PIN(33, "MF_HDA_SDO"),
245 PINCTRL_PIN(34, "MF_HDA_DOCKRSTB"),
246 PINCTRL_PIN(35, "MF_HDA_SYNC"),
247 PINCTRL_PIN(36, "MF_HDA_SDI1"),
248 PINCTRL_PIN(37, "MF_HDA_DOCKENB"),
250 PINCTRL_PIN(45, "I2C5_SDA"),
251 PINCTRL_PIN(46, "I2C4_SDA"),
252 PINCTRL_PIN(47, "I2C6_SDA"),
253 PINCTRL_PIN(48, "I2C5_SCL"),
254 PINCTRL_PIN(49, "I2C_NFC_SDA"),
255 PINCTRL_PIN(50, "I2C4_SCL"),
256 PINCTRL_PIN(51, "I2C6_SCL"),
257 PINCTRL_PIN(52, "I2C_NFC_SCL"),
259 PINCTRL_PIN(60, "I2C1_SDA"),
260 PINCTRL_PIN(61, "I2C0_SDA"),
261 PINCTRL_PIN(62, "I2C2_SDA"),
262 PINCTRL_PIN(63, "I2C1_SCL"),
263 PINCTRL_PIN(64, "I2C3_SDA"),
264 PINCTRL_PIN(65, "I2C0_SCL"),
265 PINCTRL_PIN(66, "I2C2_SCL"),
266 PINCTRL_PIN(67, "I2C3_SCL"),
268 PINCTRL_PIN(75, "SATA_GP0"),
269 PINCTRL_PIN(76, "SATA_GP1"),
270 PINCTRL_PIN(77, "SATA_LEDN"),
271 PINCTRL_PIN(78, "SATA_GP2"),
272 PINCTRL_PIN(79, "MF_SMB_ALERTB"),
273 PINCTRL_PIN(80, "SATA_GP3"),
274 PINCTRL_PIN(81, "MF_SMB_CLK"),
275 PINCTRL_PIN(82, "MF_SMB_DATA"),
277 PINCTRL_PIN(90, "PCIE_CLKREQ0B"),
278 PINCTRL_PIN(91, "PCIE_CLKREQ1B"),
279 PINCTRL_PIN(92, "GP_SSP_2_CLK"),
280 PINCTRL_PIN(93, "PCIE_CLKREQ2B"),
281 PINCTRL_PIN(94, "GP_SSP_2_RXD"),
282 PINCTRL_PIN(95, "PCIE_CLKREQ3B"),
283 PINCTRL_PIN(96, "GP_SSP_2_FS"),
284 PINCTRL_PIN(97, "GP_SSP_2_TXD"),
287 static const unsigned southwest_fspi_pins[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
288 static const unsigned southwest_uart0_pins[] = { 16, 20 };
289 static const unsigned southwest_uart1_pins[] = { 15, 16, 18, 20 };
290 static const unsigned southwest_uart2_pins[] = { 17, 19, 21, 22 };
291 static const unsigned southwest_i2c0_pins[] = { 61, 65 };
292 static const unsigned southwest_hda_pins[] = { 30, 31, 32, 33, 34, 35, 36, 37 };
293 static const unsigned southwest_lpe_pins[] = {
294 30, 31, 32, 33, 34, 35, 36, 37, 92, 94, 96, 97,
296 static const unsigned southwest_i2c1_pins[] = { 60, 63 };
297 static const unsigned southwest_i2c2_pins[] = { 62, 66 };
298 static const unsigned southwest_i2c3_pins[] = { 64, 67 };
299 static const unsigned southwest_i2c4_pins[] = { 46, 50 };
300 static const unsigned southwest_i2c5_pins[] = { 45, 48 };
301 static const unsigned southwest_i2c6_pins[] = { 47, 51 };
302 static const unsigned southwest_i2c_nfc_pins[] = { 49, 52 };
303 static const unsigned southwest_smbus_pins[] = { 79, 81, 82 };
304 static const unsigned southwest_spi3_pins[] = { 76, 79, 80, 81, 82 };
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),
314 * Two spi3 chipselects are available in different mode than the main spi3
315 * functionality, which is using mode 1.
317 static const struct chv_alternate_function southwest_spi3_altfuncs[] = {
318 ALTERNATE_FUNCTION(76, 3, false),
319 ALTERNATE_FUNCTION(80, 3, false),
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),
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),
342 static const char * const southwest_uart0_groups[] = { "uart0_grp" };
343 static const char * const southwest_uart1_groups[] = { "uart1_grp" };
344 static const char * const southwest_uart2_groups[] = { "uart2_grp" };
345 static const char * const southwest_hda_groups[] = { "hda_grp" };
346 static const char * const southwest_lpe_groups[] = { "lpe_grp" };
347 static const char * const southwest_i2c0_groups[] = { "i2c0_grp" };
348 static const char * const southwest_i2c1_groups[] = { "i2c1_grp" };
349 static const char * const southwest_i2c2_groups[] = { "i2c2_grp" };
350 static const char * const southwest_i2c3_groups[] = { "i2c3_grp" };
351 static const char * const southwest_i2c4_groups[] = { "i2c4_grp" };
352 static const char * const southwest_i2c5_groups[] = { "i2c5_grp" };
353 static const char * const southwest_i2c6_groups[] = { "i2c6_grp" };
354 static const char * const southwest_i2c_nfc_groups[] = { "i2c_nfc_grp" };
355 static const char * const southwest_spi3_groups[] = { "spi3_grp" };
358 * Only do pinmuxing for certain LPSS devices for now. Rest of the pins are
359 * enabled only as GPIOs.
361 static const struct chv_function southwest_functions[] = {
362 FUNCTION("uart0", southwest_uart0_groups),
363 FUNCTION("uart1", southwest_uart1_groups),
364 FUNCTION("uart2", southwest_uart2_groups),
365 FUNCTION("hda", southwest_hda_groups),
366 FUNCTION("lpe", southwest_lpe_groups),
367 FUNCTION("i2c0", southwest_i2c0_groups),
368 FUNCTION("i2c1", southwest_i2c1_groups),
369 FUNCTION("i2c2", southwest_i2c2_groups),
370 FUNCTION("i2c3", southwest_i2c3_groups),
371 FUNCTION("i2c4", southwest_i2c4_groups),
372 FUNCTION("i2c5", southwest_i2c5_groups),
373 FUNCTION("i2c6", southwest_i2c6_groups),
374 FUNCTION("i2c_nfc", southwest_i2c_nfc_groups),
375 FUNCTION("spi3", southwest_spi3_groups),
378 static const struct chv_gpio_pinrange southwest_gpio_ranges[] = {
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),
388 static const struct chv_community southwest_community = {
390 .pins = southwest_pins,
391 .npins = ARRAY_SIZE(southwest_pins),
392 .groups = southwest_groups,
393 .ngroups = ARRAY_SIZE(southwest_groups),
394 .functions = southwest_functions,
395 .nfunctions = ARRAY_SIZE(southwest_functions),
396 .gpio_ranges = southwest_gpio_ranges,
397 .ngpio_ranges = ARRAY_SIZE(southwest_gpio_ranges),
399 * Southwest community can benerate GPIO interrupts only for the
400 * first 8 interrupts. The upper half (8-15) can only be used to
404 .acpi_space_id = 0x91,
407 static const struct pinctrl_pin_desc north_pins[] = {
408 PINCTRL_PIN(0, "GPIO_DFX_0"),
409 PINCTRL_PIN(1, "GPIO_DFX_3"),
410 PINCTRL_PIN(2, "GPIO_DFX_7"),
411 PINCTRL_PIN(3, "GPIO_DFX_1"),
412 PINCTRL_PIN(4, "GPIO_DFX_5"),
413 PINCTRL_PIN(5, "GPIO_DFX_4"),
414 PINCTRL_PIN(6, "GPIO_DFX_8"),
415 PINCTRL_PIN(7, "GPIO_DFX_2"),
416 PINCTRL_PIN(8, "GPIO_DFX_6"),
418 PINCTRL_PIN(15, "GPIO_SUS0"),
419 PINCTRL_PIN(16, "SEC_GPIO_SUS10"),
420 PINCTRL_PIN(17, "GPIO_SUS3"),
421 PINCTRL_PIN(18, "GPIO_SUS7"),
422 PINCTRL_PIN(19, "GPIO_SUS1"),
423 PINCTRL_PIN(20, "GPIO_SUS5"),
424 PINCTRL_PIN(21, "SEC_GPIO_SUS11"),
425 PINCTRL_PIN(22, "GPIO_SUS4"),
426 PINCTRL_PIN(23, "SEC_GPIO_SUS8"),
427 PINCTRL_PIN(24, "GPIO_SUS2"),
428 PINCTRL_PIN(25, "GPIO_SUS6"),
429 PINCTRL_PIN(26, "CX_PREQ_B"),
430 PINCTRL_PIN(27, "SEC_GPIO_SUS9"),
432 PINCTRL_PIN(30, "TRST_B"),
433 PINCTRL_PIN(31, "TCK"),
434 PINCTRL_PIN(32, "PROCHOT_B"),
435 PINCTRL_PIN(33, "SVIDO_DATA"),
436 PINCTRL_PIN(34, "TMS"),
437 PINCTRL_PIN(35, "CX_PRDY_B_2"),
438 PINCTRL_PIN(36, "TDO_2"),
439 PINCTRL_PIN(37, "CX_PRDY_B"),
440 PINCTRL_PIN(38, "SVIDO_ALERT_B"),
441 PINCTRL_PIN(39, "TDO"),
442 PINCTRL_PIN(40, "SVIDO_CLK"),
443 PINCTRL_PIN(41, "TDI"),
445 PINCTRL_PIN(45, "GP_CAMERASB_05"),
446 PINCTRL_PIN(46, "GP_CAMERASB_02"),
447 PINCTRL_PIN(47, "GP_CAMERASB_08"),
448 PINCTRL_PIN(48, "GP_CAMERASB_00"),
449 PINCTRL_PIN(49, "GP_CAMERASB_06"),
450 PINCTRL_PIN(50, "GP_CAMERASB_10"),
451 PINCTRL_PIN(51, "GP_CAMERASB_03"),
452 PINCTRL_PIN(52, "GP_CAMERASB_09"),
453 PINCTRL_PIN(53, "GP_CAMERASB_01"),
454 PINCTRL_PIN(54, "GP_CAMERASB_07"),
455 PINCTRL_PIN(55, "GP_CAMERASB_11"),
456 PINCTRL_PIN(56, "GP_CAMERASB_04"),
458 PINCTRL_PIN(60, "PANEL0_BKLTEN"),
459 PINCTRL_PIN(61, "HV_DDI0_HPD"),
460 PINCTRL_PIN(62, "HV_DDI2_DDC_SDA"),
461 PINCTRL_PIN(63, "PANEL1_BKLTCTL"),
462 PINCTRL_PIN(64, "HV_DDI1_HPD"),
463 PINCTRL_PIN(65, "PANEL0_BKLTCTL"),
464 PINCTRL_PIN(66, "HV_DDI0_DDC_SDA"),
465 PINCTRL_PIN(67, "HV_DDI2_DDC_SCL"),
466 PINCTRL_PIN(68, "HV_DDI2_HPD"),
467 PINCTRL_PIN(69, "PANEL1_VDDEN"),
468 PINCTRL_PIN(70, "PANEL1_BKLTEN"),
469 PINCTRL_PIN(71, "HV_DDI0_DDC_SCL"),
470 PINCTRL_PIN(72, "PANEL0_VDDEN"),
473 static const struct chv_gpio_pinrange north_gpio_ranges[] = {
475 GPIO_PINRANGE(15, 27),
476 GPIO_PINRANGE(30, 41),
477 GPIO_PINRANGE(45, 56),
478 GPIO_PINRANGE(60, 72),
481 static const struct chv_community north_community = {
484 .npins = ARRAY_SIZE(north_pins),
485 .gpio_ranges = north_gpio_ranges,
486 .ngpio_ranges = ARRAY_SIZE(north_gpio_ranges),
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
493 .acpi_space_id = 0x92,
496 static const struct pinctrl_pin_desc east_pins[] = {
497 PINCTRL_PIN(0, "PMU_SLP_S3_B"),
498 PINCTRL_PIN(1, "PMU_BATLOW_B"),
499 PINCTRL_PIN(2, "SUS_STAT_B"),
500 PINCTRL_PIN(3, "PMU_SLP_S0IX_B"),
501 PINCTRL_PIN(4, "PMU_AC_PRESENT"),
502 PINCTRL_PIN(5, "PMU_PLTRST_B"),
503 PINCTRL_PIN(6, "PMU_SUSCLK"),
504 PINCTRL_PIN(7, "PMU_SLP_LAN_B"),
505 PINCTRL_PIN(8, "PMU_PWRBTN_B"),
506 PINCTRL_PIN(9, "PMU_SLP_S4_B"),
507 PINCTRL_PIN(10, "PMU_WAKE_B"),
508 PINCTRL_PIN(11, "PMU_WAKE_LAN_B"),
510 PINCTRL_PIN(15, "MF_ISH_GPIO_3"),
511 PINCTRL_PIN(16, "MF_ISH_GPIO_7"),
512 PINCTRL_PIN(17, "MF_ISH_I2C1_SCL"),
513 PINCTRL_PIN(18, "MF_ISH_GPIO_1"),
514 PINCTRL_PIN(19, "MF_ISH_GPIO_5"),
515 PINCTRL_PIN(20, "MF_ISH_GPIO_9"),
516 PINCTRL_PIN(21, "MF_ISH_GPIO_0"),
517 PINCTRL_PIN(22, "MF_ISH_GPIO_4"),
518 PINCTRL_PIN(23, "MF_ISH_GPIO_8"),
519 PINCTRL_PIN(24, "MF_ISH_GPIO_2"),
520 PINCTRL_PIN(25, "MF_ISH_GPIO_6"),
521 PINCTRL_PIN(26, "MF_ISH_I2C1_SDA"),
524 static const struct chv_gpio_pinrange east_gpio_ranges[] = {
525 GPIO_PINRANGE(0, 11),
526 GPIO_PINRANGE(15, 26),
529 static const struct chv_community east_community = {
532 .npins = ARRAY_SIZE(east_pins),
533 .gpio_ranges = east_gpio_ranges,
534 .ngpio_ranges = ARRAY_SIZE(east_gpio_ranges),
536 .acpi_space_id = 0x93,
539 static const struct pinctrl_pin_desc southeast_pins[] = {
540 PINCTRL_PIN(0, "MF_PLT_CLK0"),
541 PINCTRL_PIN(1, "PWM1"),
542 PINCTRL_PIN(2, "MF_PLT_CLK1"),
543 PINCTRL_PIN(3, "MF_PLT_CLK4"),
544 PINCTRL_PIN(4, "MF_PLT_CLK3"),
545 PINCTRL_PIN(5, "PWM0"),
546 PINCTRL_PIN(6, "MF_PLT_CLK5"),
547 PINCTRL_PIN(7, "MF_PLT_CLK2"),
549 PINCTRL_PIN(15, "SDMMC2_D3_CD_B"),
550 PINCTRL_PIN(16, "SDMMC1_CLK"),
551 PINCTRL_PIN(17, "SDMMC1_D0"),
552 PINCTRL_PIN(18, "SDMMC2_D1"),
553 PINCTRL_PIN(19, "SDMMC2_CLK"),
554 PINCTRL_PIN(20, "SDMMC1_D2"),
555 PINCTRL_PIN(21, "SDMMC2_D2"),
556 PINCTRL_PIN(22, "SDMMC2_CMD"),
557 PINCTRL_PIN(23, "SDMMC1_CMD"),
558 PINCTRL_PIN(24, "SDMMC1_D1"),
559 PINCTRL_PIN(25, "SDMMC2_D0"),
560 PINCTRL_PIN(26, "SDMMC1_D3_CD_B"),
562 PINCTRL_PIN(30, "SDMMC3_D1"),
563 PINCTRL_PIN(31, "SDMMC3_CLK"),
564 PINCTRL_PIN(32, "SDMMC3_D3"),
565 PINCTRL_PIN(33, "SDMMC3_D2"),
566 PINCTRL_PIN(34, "SDMMC3_CMD"),
567 PINCTRL_PIN(35, "SDMMC3_D0"),
569 PINCTRL_PIN(45, "MF_LPC_AD2"),
570 PINCTRL_PIN(46, "LPC_CLKRUNB"),
571 PINCTRL_PIN(47, "MF_LPC_AD0"),
572 PINCTRL_PIN(48, "LPC_FRAMEB"),
573 PINCTRL_PIN(49, "MF_LPC_CLKOUT1"),
574 PINCTRL_PIN(50, "MF_LPC_AD3"),
575 PINCTRL_PIN(51, "MF_LPC_CLKOUT0"),
576 PINCTRL_PIN(52, "MF_LPC_AD1"),
578 PINCTRL_PIN(60, "SPI1_MISO"),
579 PINCTRL_PIN(61, "SPI1_CSO_B"),
580 PINCTRL_PIN(62, "SPI1_CLK"),
581 PINCTRL_PIN(63, "MMC1_D6"),
582 PINCTRL_PIN(64, "SPI1_MOSI"),
583 PINCTRL_PIN(65, "MMC1_D5"),
584 PINCTRL_PIN(66, "SPI1_CS1_B"),
585 PINCTRL_PIN(67, "MMC1_D4_SD_WE"),
586 PINCTRL_PIN(68, "MMC1_D7"),
587 PINCTRL_PIN(69, "MMC1_RCLK"),
589 PINCTRL_PIN(75, "USB_OC1_B"),
590 PINCTRL_PIN(76, "PMU_RESETBUTTON_B"),
591 PINCTRL_PIN(77, "GPIO_ALERT"),
592 PINCTRL_PIN(78, "SDMMC3_PWR_EN_B"),
593 PINCTRL_PIN(79, "ILB_SERIRQ"),
594 PINCTRL_PIN(80, "USB_OC0_B"),
595 PINCTRL_PIN(81, "SDMMC3_CD_B"),
596 PINCTRL_PIN(82, "SPKR"),
597 PINCTRL_PIN(83, "SUSPWRDNACK"),
598 PINCTRL_PIN(84, "SPARE_PIN"),
599 PINCTRL_PIN(85, "SDMMC3_1P8_EN"),
602 static const unsigned southeast_pwm0_pins[] = { 5 };
603 static const unsigned southeast_pwm1_pins[] = { 1 };
604 static const unsigned southeast_sdmmc1_pins[] = {
605 16, 17, 20, 23, 24, 26, 63, 65, 67, 68, 69,
607 static const unsigned southeast_sdmmc2_pins[] = { 15, 18, 19, 21, 22, 25 };
608 static const unsigned southeast_sdmmc3_pins[] = {
609 30, 31, 32, 33, 34, 35, 78, 81, 85,
611 static const unsigned southeast_spi1_pins[] = { 60, 61, 62, 64, 66 };
612 static const unsigned southeast_spi2_pins[] = { 2, 3, 4, 6, 7 };
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),
624 static const char * const southeast_pwm0_groups[] = { "pwm0_grp" };
625 static const char * const southeast_pwm1_groups[] = { "pwm1_grp" };
626 static const char * const southeast_sdmmc1_groups[] = { "sdmmc1_grp" };
627 static const char * const southeast_sdmmc2_groups[] = { "sdmmc2_grp" };
628 static const char * const southeast_sdmmc3_groups[] = { "sdmmc3_grp" };
629 static const char * const southeast_spi1_groups[] = { "spi1_grp" };
630 static const char * const southeast_spi2_groups[] = { "spi2_grp" };
632 static const struct chv_function southeast_functions[] = {
633 FUNCTION("pwm0", southeast_pwm0_groups),
634 FUNCTION("pwm1", southeast_pwm1_groups),
635 FUNCTION("sdmmc1", southeast_sdmmc1_groups),
636 FUNCTION("sdmmc2", southeast_sdmmc2_groups),
637 FUNCTION("sdmmc3", southeast_sdmmc3_groups),
638 FUNCTION("spi1", southeast_spi1_groups),
639 FUNCTION("spi2", southeast_spi2_groups),
642 static const struct chv_gpio_pinrange southeast_gpio_ranges[] = {
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),
651 static const struct chv_community southeast_community = {
653 .pins = southeast_pins,
654 .npins = ARRAY_SIZE(southeast_pins),
655 .groups = southeast_groups,
656 .ngroups = ARRAY_SIZE(southeast_groups),
657 .functions = southeast_functions,
658 .nfunctions = ARRAY_SIZE(southeast_functions),
659 .gpio_ranges = southeast_gpio_ranges,
660 .ngpio_ranges = ARRAY_SIZE(southeast_gpio_ranges),
662 .acpi_space_id = 0x94,
665 static const struct chv_community *chv_communities[] = {
666 &southwest_community,
669 &southeast_community,
673 * Lock to serialize register accesses
675 * Due to a silicon issue, a shared lock must be used to prevent
676 * concurrent accesses across the 4 GPIO controllers.
678 * See Intel Atom Z8000 Processor Series Specification Update (Rev. 005),
679 * errata #CHT34, for further information.
681 static DEFINE_RAW_SPINLOCK(chv_lock);
683 static void __iomem *chv_padreg(struct chv_pinctrl *pctrl, unsigned offset,
686 unsigned family_no = offset / MAX_FAMILY_PAD_GPIO_NO;
687 unsigned pad_no = offset % MAX_FAMILY_PAD_GPIO_NO;
689 offset = FAMILY_PAD_REGS_OFF + FAMILY_PAD_REGS_SIZE * family_no +
690 GPIO_REGS_SIZE * pad_no;
692 return pctrl->regs + offset + reg;
695 static void chv_writel(u32 value, void __iomem *reg)
698 /* simple readback to confirm the bus transferring done */
702 /* When Pad Cfg is locked, driver can only change GPIOTXState or GPIORXState */
703 static bool chv_pad_locked(struct chv_pinctrl *pctrl, unsigned offset)
707 reg = chv_padreg(pctrl, offset, CHV_PADCTRL1);
708 return readl(reg) & CHV_PADCTRL1_CFGLOCK;
711 static int chv_get_groups_count(struct pinctrl_dev *pctldev)
713 struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
715 return pctrl->community->ngroups;
718 static const char *chv_get_group_name(struct pinctrl_dev *pctldev,
721 struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
723 return pctrl->community->groups[group].name;
726 static int chv_get_group_pins(struct pinctrl_dev *pctldev, unsigned group,
727 const unsigned **pins, unsigned *npins)
729 struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
731 *pins = pctrl->community->groups[group].pins;
732 *npins = pctrl->community->groups[group].npins;
736 static void chv_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s,
739 struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
744 raw_spin_lock_irqsave(&chv_lock, flags);
746 ctrl0 = readl(chv_padreg(pctrl, offset, CHV_PADCTRL0));
747 ctrl1 = readl(chv_padreg(pctrl, offset, CHV_PADCTRL1));
748 locked = chv_pad_locked(pctrl, offset);
750 raw_spin_unlock_irqrestore(&chv_lock, flags);
752 if (ctrl0 & CHV_PADCTRL0_GPIOEN) {
753 seq_puts(s, "GPIO ");
757 mode = ctrl0 & CHV_PADCTRL0_PMODE_MASK;
758 mode >>= CHV_PADCTRL0_PMODE_SHIFT;
760 seq_printf(s, "mode %d ", mode);
763 seq_printf(s, "0x%08x 0x%08x", ctrl0, ctrl1);
766 seq_puts(s, " [LOCKED]");
769 static const struct pinctrl_ops chv_pinctrl_ops = {
770 .get_groups_count = chv_get_groups_count,
771 .get_group_name = chv_get_group_name,
772 .get_group_pins = chv_get_group_pins,
773 .pin_dbg_show = chv_pin_dbg_show,
776 static int chv_get_functions_count(struct pinctrl_dev *pctldev)
778 struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
780 return pctrl->community->nfunctions;
783 static const char *chv_get_function_name(struct pinctrl_dev *pctldev,
786 struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
788 return pctrl->community->functions[function].name;
791 static int chv_get_function_groups(struct pinctrl_dev *pctldev,
793 const char * const **groups,
794 unsigned * const ngroups)
796 struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
798 *groups = pctrl->community->functions[function].groups;
799 *ngroups = pctrl->community->functions[function].ngroups;
803 static int chv_pinmux_set_mux(struct pinctrl_dev *pctldev, unsigned function,
806 struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
807 const struct chv_pingroup *grp;
811 grp = &pctrl->community->groups[group];
813 raw_spin_lock_irqsave(&chv_lock, flags);
815 /* Check first that the pad is not locked */
816 for (i = 0; i < grp->npins; i++) {
817 if (chv_pad_locked(pctrl, grp->pins[i])) {
818 dev_warn(pctrl->dev, "unable to set mode for locked pin %u\n",
820 raw_spin_unlock_irqrestore(&chv_lock, flags);
825 for (i = 0; i < grp->npins; i++) {
826 const struct chv_alternate_function *altfunc = &grp->altfunc;
827 int pin = grp->pins[i];
831 /* Check if there is pin-specific config */
832 if (grp->overrides) {
835 for (j = 0; j < grp->noverrides; j++) {
836 if (grp->overrides[j].pin == pin) {
837 altfunc = &grp->overrides[j];
843 reg = chv_padreg(pctrl, pin, CHV_PADCTRL0);
845 /* Disable GPIO mode */
846 value &= ~CHV_PADCTRL0_GPIOEN;
847 /* Set to desired mode */
848 value &= ~CHV_PADCTRL0_PMODE_MASK;
849 value |= altfunc->mode << CHV_PADCTRL0_PMODE_SHIFT;
850 chv_writel(value, reg);
852 /* 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)
856 value |= CHV_PADCTRL1_INVRXTX_TXENABLE;
857 chv_writel(value, reg);
859 dev_dbg(pctrl->dev, "configured pin %u mode %u OE %sinverted\n",
860 pin, altfunc->mode, altfunc->invert_oe ? "" : "not ");
863 raw_spin_unlock_irqrestore(&chv_lock, flags);
868 static int chv_gpio_request_enable(struct pinctrl_dev *pctldev,
869 struct pinctrl_gpio_range *range,
872 struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
877 raw_spin_lock_irqsave(&chv_lock, flags);
879 if (chv_pad_locked(pctrl, offset)) {
880 value = readl(chv_padreg(pctrl, offset, CHV_PADCTRL0));
881 if (!(value & CHV_PADCTRL0_GPIOEN)) {
882 /* Locked so cannot enable */
883 raw_spin_unlock_irqrestore(&chv_lock, flags);
889 /* 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;
897 /* Disable interrupt generation */
898 reg = chv_padreg(pctrl, offset, CHV_PADCTRL1);
900 value &= ~CHV_PADCTRL1_INTWAKECFG_MASK;
901 value &= ~CHV_PADCTRL1_INVRXTX_MASK;
902 chv_writel(value, reg);
904 reg = chv_padreg(pctrl, offset, CHV_PADCTRL0);
908 * If the pin is in HiZ mode (both TX and RX buffers are
909 * disabled) we turn it to be input now.
911 if ((value & CHV_PADCTRL0_GPIOCFG_MASK) ==
912 (CHV_PADCTRL0_GPIOCFG_HIZ << CHV_PADCTRL0_GPIOCFG_SHIFT)) {
913 value &= ~CHV_PADCTRL0_GPIOCFG_MASK;
914 value |= CHV_PADCTRL0_GPIOCFG_GPI <<
915 CHV_PADCTRL0_GPIOCFG_SHIFT;
918 /* Switch to a GPIO mode */
919 value |= CHV_PADCTRL0_GPIOEN;
920 chv_writel(value, reg);
923 raw_spin_unlock_irqrestore(&chv_lock, flags);
928 static void chv_gpio_disable_free(struct pinctrl_dev *pctldev,
929 struct pinctrl_gpio_range *range,
932 struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
937 raw_spin_lock_irqsave(&chv_lock, flags);
939 reg = chv_padreg(pctrl, offset, CHV_PADCTRL0);
940 value = readl(reg) & ~CHV_PADCTRL0_GPIOEN;
941 chv_writel(value, reg);
943 raw_spin_unlock_irqrestore(&chv_lock, flags);
946 static int chv_gpio_set_direction(struct pinctrl_dev *pctldev,
947 struct pinctrl_gpio_range *range,
948 unsigned offset, bool input)
950 struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
951 void __iomem *reg = chv_padreg(pctrl, offset, CHV_PADCTRL0);
955 raw_spin_lock_irqsave(&chv_lock, flags);
957 ctrl0 = readl(reg) & ~CHV_PADCTRL0_GPIOCFG_MASK;
959 ctrl0 |= CHV_PADCTRL0_GPIOCFG_GPI << CHV_PADCTRL0_GPIOCFG_SHIFT;
961 ctrl0 |= CHV_PADCTRL0_GPIOCFG_GPO << CHV_PADCTRL0_GPIOCFG_SHIFT;
962 chv_writel(ctrl0, reg);
964 raw_spin_unlock_irqrestore(&chv_lock, flags);
969 static const struct pinmux_ops chv_pinmux_ops = {
970 .get_functions_count = chv_get_functions_count,
971 .get_function_name = chv_get_function_name,
972 .get_function_groups = chv_get_function_groups,
973 .set_mux = chv_pinmux_set_mux,
974 .gpio_request_enable = chv_gpio_request_enable,
975 .gpio_disable_free = chv_gpio_disable_free,
976 .gpio_set_direction = chv_gpio_set_direction,
979 static int chv_config_get(struct pinctrl_dev *pctldev, unsigned pin,
980 unsigned long *config)
982 struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
983 enum pin_config_param param = pinconf_to_config_param(*config);
989 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));
992 raw_spin_unlock_irqrestore(&chv_lock, flags);
994 term = (ctrl0 & CHV_PADCTRL0_TERM_MASK) >> CHV_PADCTRL0_TERM_SHIFT;
997 case PIN_CONFIG_BIAS_DISABLE:
1002 case PIN_CONFIG_BIAS_PULL_UP:
1003 if (!(ctrl0 & CHV_PADCTRL0_TERM_UP))
1007 case CHV_PADCTRL0_TERM_20K:
1010 case CHV_PADCTRL0_TERM_5K:
1013 case CHV_PADCTRL0_TERM_1K:
1020 case PIN_CONFIG_BIAS_PULL_DOWN:
1021 if (!term || (ctrl0 & CHV_PADCTRL0_TERM_UP))
1025 case CHV_PADCTRL0_TERM_20K:
1028 case CHV_PADCTRL0_TERM_5K:
1035 case PIN_CONFIG_BIAS_HIGH_IMPEDANCE: {
1038 cfg = ctrl0 & CHV_PADCTRL0_GPIOCFG_MASK;
1039 cfg >>= CHV_PADCTRL0_GPIOCFG_SHIFT;
1040 if (cfg != CHV_PADCTRL0_GPIOCFG_HIZ)
1045 case PIN_CONFIG_DRIVE_PUSH_PULL:
1046 if (ctrl1 & CHV_PADCTRL1_ODEN)
1050 case PIN_CONFIG_DRIVE_OPEN_DRAIN:
1051 if (!(ctrl1 & CHV_PADCTRL1_ODEN))
1060 *config = pinconf_to_config_packed(param, arg);
1064 static int chv_config_set_pull(struct chv_pinctrl *pctrl, unsigned pin,
1065 enum pin_config_param param, u32 arg)
1067 void __iomem *reg = chv_padreg(pctrl, pin, CHV_PADCTRL0);
1068 unsigned long flags;
1071 raw_spin_lock_irqsave(&chv_lock, flags);
1075 case PIN_CONFIG_BIAS_DISABLE:
1076 ctrl0 &= ~(CHV_PADCTRL0_TERM_MASK | CHV_PADCTRL0_TERM_UP);
1079 case PIN_CONFIG_BIAS_PULL_UP:
1080 ctrl0 &= ~(CHV_PADCTRL0_TERM_MASK | CHV_PADCTRL0_TERM_UP);
1084 /* For 1k there is only pull up */
1085 pull = CHV_PADCTRL0_TERM_1K << CHV_PADCTRL0_TERM_SHIFT;
1088 pull = CHV_PADCTRL0_TERM_5K << CHV_PADCTRL0_TERM_SHIFT;
1091 pull = CHV_PADCTRL0_TERM_20K << CHV_PADCTRL0_TERM_SHIFT;
1094 raw_spin_unlock_irqrestore(&chv_lock, flags);
1098 ctrl0 |= CHV_PADCTRL0_TERM_UP | pull;
1101 case PIN_CONFIG_BIAS_PULL_DOWN:
1102 ctrl0 &= ~(CHV_PADCTRL0_TERM_MASK | CHV_PADCTRL0_TERM_UP);
1106 pull = CHV_PADCTRL0_TERM_5K << CHV_PADCTRL0_TERM_SHIFT;
1109 pull = CHV_PADCTRL0_TERM_20K << CHV_PADCTRL0_TERM_SHIFT;
1112 raw_spin_unlock_irqrestore(&chv_lock, flags);
1120 raw_spin_unlock_irqrestore(&chv_lock, flags);
1124 chv_writel(ctrl0, reg);
1125 raw_spin_unlock_irqrestore(&chv_lock, flags);
1130 static int chv_config_set_oden(struct chv_pinctrl *pctrl, unsigned int pin,
1133 void __iomem *reg = chv_padreg(pctrl, pin, CHV_PADCTRL1);
1134 unsigned long flags;
1137 raw_spin_lock_irqsave(&chv_lock, flags);
1141 ctrl1 |= CHV_PADCTRL1_ODEN;
1143 ctrl1 &= ~CHV_PADCTRL1_ODEN;
1145 chv_writel(ctrl1, reg);
1146 raw_spin_unlock_irqrestore(&chv_lock, flags);
1151 static int chv_config_set(struct pinctrl_dev *pctldev, unsigned pin,
1152 unsigned long *configs, unsigned nconfigs)
1154 struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
1155 enum pin_config_param param;
1159 if (chv_pad_locked(pctrl, pin))
1162 for (i = 0; i < nconfigs; i++) {
1163 param = pinconf_to_config_param(configs[i]);
1164 arg = pinconf_to_config_argument(configs[i]);
1167 case PIN_CONFIG_BIAS_DISABLE:
1168 case PIN_CONFIG_BIAS_PULL_UP:
1169 case PIN_CONFIG_BIAS_PULL_DOWN:
1170 ret = chv_config_set_pull(pctrl, pin, param, arg);
1175 case PIN_CONFIG_DRIVE_PUSH_PULL:
1176 ret = chv_config_set_oden(pctrl, pin, false);
1181 case PIN_CONFIG_DRIVE_OPEN_DRAIN:
1182 ret = chv_config_set_oden(pctrl, pin, true);
1191 dev_dbg(pctrl->dev, "pin %d set config %d arg %u\n", pin,
1198 static int chv_config_group_get(struct pinctrl_dev *pctldev,
1200 unsigned long *config)
1202 const unsigned int *pins;
1206 ret = chv_get_group_pins(pctldev, group, &pins, &npins);
1210 ret = chv_config_get(pctldev, pins[0], config);
1217 static int chv_config_group_set(struct pinctrl_dev *pctldev,
1218 unsigned int group, unsigned long *configs,
1219 unsigned int num_configs)
1221 const unsigned int *pins;
1225 ret = chv_get_group_pins(pctldev, group, &pins, &npins);
1229 for (i = 0; i < npins; i++) {
1230 ret = chv_config_set(pctldev, pins[i], configs, num_configs);
1238 static const struct pinconf_ops chv_pinconf_ops = {
1240 .pin_config_set = chv_config_set,
1241 .pin_config_get = chv_config_get,
1242 .pin_config_group_get = chv_config_group_get,
1243 .pin_config_group_set = chv_config_group_set,
1246 static struct pinctrl_desc chv_pinctrl_desc = {
1247 .pctlops = &chv_pinctrl_ops,
1248 .pmxops = &chv_pinmux_ops,
1249 .confops = &chv_pinconf_ops,
1250 .owner = THIS_MODULE,
1253 static int chv_gpio_get(struct gpio_chip *chip, unsigned offset)
1255 struct chv_pinctrl *pctrl = gpiochip_get_data(chip);
1256 unsigned long flags;
1259 raw_spin_lock_irqsave(&chv_lock, flags);
1260 ctrl0 = readl(chv_padreg(pctrl, offset, CHV_PADCTRL0));
1261 raw_spin_unlock_irqrestore(&chv_lock, flags);
1263 cfg = ctrl0 & CHV_PADCTRL0_GPIOCFG_MASK;
1264 cfg >>= CHV_PADCTRL0_GPIOCFG_SHIFT;
1266 if (cfg == CHV_PADCTRL0_GPIOCFG_GPO)
1267 return !!(ctrl0 & CHV_PADCTRL0_GPIOTXSTATE);
1268 return !!(ctrl0 & CHV_PADCTRL0_GPIORXSTATE);
1271 static void chv_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
1273 struct chv_pinctrl *pctrl = gpiochip_get_data(chip);
1274 unsigned long flags;
1278 raw_spin_lock_irqsave(&chv_lock, flags);
1280 reg = chv_padreg(pctrl, offset, CHV_PADCTRL0);
1284 ctrl0 |= CHV_PADCTRL0_GPIOTXSTATE;
1286 ctrl0 &= ~CHV_PADCTRL0_GPIOTXSTATE;
1288 chv_writel(ctrl0, reg);
1290 raw_spin_unlock_irqrestore(&chv_lock, flags);
1293 static int chv_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
1295 struct chv_pinctrl *pctrl = gpiochip_get_data(chip);
1296 u32 ctrl0, direction;
1297 unsigned long flags;
1299 raw_spin_lock_irqsave(&chv_lock, flags);
1300 ctrl0 = readl(chv_padreg(pctrl, offset, CHV_PADCTRL0));
1301 raw_spin_unlock_irqrestore(&chv_lock, flags);
1303 direction = ctrl0 & CHV_PADCTRL0_GPIOCFG_MASK;
1304 direction >>= CHV_PADCTRL0_GPIOCFG_SHIFT;
1306 return direction != CHV_PADCTRL0_GPIOCFG_GPO;
1309 static int chv_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
1311 return pinctrl_gpio_direction_input(chip->base + offset);
1314 static int chv_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
1317 chv_gpio_set(chip, offset, value);
1318 return pinctrl_gpio_direction_output(chip->base + offset);
1321 static const struct gpio_chip chv_gpio_chip = {
1322 .owner = THIS_MODULE,
1323 .request = gpiochip_generic_request,
1324 .free = gpiochip_generic_free,
1325 .get_direction = chv_gpio_get_direction,
1326 .direction_input = chv_gpio_direction_input,
1327 .direction_output = chv_gpio_direction_output,
1328 .get = chv_gpio_get,
1329 .set = chv_gpio_set,
1332 static void chv_gpio_irq_ack(struct irq_data *d)
1334 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
1335 struct chv_pinctrl *pctrl = gpiochip_get_data(gc);
1336 int pin = irqd_to_hwirq(d);
1339 raw_spin_lock(&chv_lock);
1341 intr_line = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0));
1342 intr_line &= CHV_PADCTRL0_INTSEL_MASK;
1343 intr_line >>= CHV_PADCTRL0_INTSEL_SHIFT;
1344 chv_writel(BIT(intr_line), pctrl->regs + CHV_INTSTAT);
1346 raw_spin_unlock(&chv_lock);
1349 static void chv_gpio_irq_mask_unmask(struct irq_data *d, bool mask)
1351 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
1352 struct chv_pinctrl *pctrl = gpiochip_get_data(gc);
1353 int pin = irqd_to_hwirq(d);
1354 u32 value, intr_line;
1355 unsigned long flags;
1357 raw_spin_lock_irqsave(&chv_lock, flags);
1359 intr_line = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0));
1360 intr_line &= CHV_PADCTRL0_INTSEL_MASK;
1361 intr_line >>= CHV_PADCTRL0_INTSEL_SHIFT;
1363 value = readl(pctrl->regs + CHV_INTMASK);
1365 value &= ~BIT(intr_line);
1367 value |= BIT(intr_line);
1368 chv_writel(value, pctrl->regs + CHV_INTMASK);
1370 raw_spin_unlock_irqrestore(&chv_lock, flags);
1373 static void chv_gpio_irq_mask(struct irq_data *d)
1375 chv_gpio_irq_mask_unmask(d, true);
1378 static void chv_gpio_irq_unmask(struct irq_data *d)
1380 chv_gpio_irq_mask_unmask(d, false);
1383 static unsigned chv_gpio_irq_startup(struct irq_data *d)
1386 * Check if the interrupt has been requested with 0 as triggering
1387 * type. In that case it is assumed that the current values
1388 * programmed to the hardware are used (e.g BIOS configured
1391 * In that case ->irq_set_type() will never be called so we need to
1392 * read back the values from hardware now, set correct flow handler
1393 * and update mappings before the interrupt is being used.
1395 if (irqd_get_trigger_type(d) == IRQ_TYPE_NONE) {
1396 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
1397 struct chv_pinctrl *pctrl = gpiochip_get_data(gc);
1398 unsigned pin = irqd_to_hwirq(d);
1399 irq_flow_handler_t handler;
1400 unsigned long flags;
1403 raw_spin_lock_irqsave(&chv_lock, flags);
1404 intsel = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0));
1405 intsel &= CHV_PADCTRL0_INTSEL_MASK;
1406 intsel >>= CHV_PADCTRL0_INTSEL_SHIFT;
1408 value = readl(chv_padreg(pctrl, pin, CHV_PADCTRL1));
1409 if (value & CHV_PADCTRL1_INTWAKECFG_LEVEL)
1410 handler = handle_level_irq;
1412 handler = handle_edge_irq;
1414 if (!pctrl->intr_lines[intsel]) {
1415 irq_set_handler_locked(d, handler);
1416 pctrl->intr_lines[intsel] = pin;
1418 raw_spin_unlock_irqrestore(&chv_lock, flags);
1421 chv_gpio_irq_unmask(d);
1425 static int chv_gpio_irq_type(struct irq_data *d, unsigned type)
1427 struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
1428 struct chv_pinctrl *pctrl = gpiochip_get_data(gc);
1429 unsigned pin = irqd_to_hwirq(d);
1430 unsigned long flags;
1433 raw_spin_lock_irqsave(&chv_lock, flags);
1436 * Pins which can be used as shared interrupt are configured in
1437 * BIOS. Driver trusts BIOS configurations and assigns different
1438 * handler according to the irq type.
1440 * Driver needs to save the mapping between each pin and
1441 * its interrupt line.
1442 * 1. If the pin cfg is locked in BIOS:
1443 * Trust BIOS has programmed IntWakeCfg bits correctly,
1444 * driver just needs to save the mapping.
1445 * 2. If the pin cfg is not locked in BIOS:
1446 * Driver programs the IntWakeCfg bits and save the mapping.
1448 if (!chv_pad_locked(pctrl, pin)) {
1449 void __iomem *reg = chv_padreg(pctrl, pin, CHV_PADCTRL1);
1452 value &= ~CHV_PADCTRL1_INTWAKECFG_MASK;
1453 value &= ~CHV_PADCTRL1_INVRXTX_MASK;
1455 if (type & IRQ_TYPE_EDGE_BOTH) {
1456 if ((type & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH)
1457 value |= CHV_PADCTRL1_INTWAKECFG_BOTH;
1458 else if (type & IRQ_TYPE_EDGE_RISING)
1459 value |= CHV_PADCTRL1_INTWAKECFG_RISING;
1460 else if (type & IRQ_TYPE_EDGE_FALLING)
1461 value |= CHV_PADCTRL1_INTWAKECFG_FALLING;
1462 } else if (type & IRQ_TYPE_LEVEL_MASK) {
1463 value |= CHV_PADCTRL1_INTWAKECFG_LEVEL;
1464 if (type & IRQ_TYPE_LEVEL_LOW)
1465 value |= CHV_PADCTRL1_INVRXTX_RXDATA;
1468 chv_writel(value, reg);
1471 value = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0));
1472 value &= CHV_PADCTRL0_INTSEL_MASK;
1473 value >>= CHV_PADCTRL0_INTSEL_SHIFT;
1475 pctrl->intr_lines[value] = pin;
1477 if (type & IRQ_TYPE_EDGE_BOTH)
1478 irq_set_handler_locked(d, handle_edge_irq);
1479 else if (type & IRQ_TYPE_LEVEL_MASK)
1480 irq_set_handler_locked(d, handle_level_irq);
1482 raw_spin_unlock_irqrestore(&chv_lock, flags);
1487 static void chv_gpio_irq_handler(struct irq_desc *desc)
1489 struct gpio_chip *gc = irq_desc_get_handler_data(desc);
1490 struct chv_pinctrl *pctrl = gpiochip_get_data(gc);
1491 struct irq_chip *chip = irq_desc_get_chip(desc);
1492 unsigned long pending;
1493 unsigned long flags;
1496 chained_irq_enter(chip, desc);
1498 raw_spin_lock_irqsave(&chv_lock, flags);
1499 pending = readl(pctrl->regs + CHV_INTSTAT);
1500 raw_spin_unlock_irqrestore(&chv_lock, flags);
1502 for_each_set_bit(intr_line, &pending, pctrl->community->nirqs) {
1503 unsigned irq, offset;
1505 offset = pctrl->intr_lines[intr_line];
1506 irq = irq_find_mapping(gc->irq.domain, offset);
1507 generic_handle_irq(irq);
1510 chained_irq_exit(chip, desc);
1514 * Certain machines seem to hardcode Linux IRQ numbers in their ACPI
1515 * tables. Since we leave GPIOs that are not capable of generating
1516 * interrupts out of the irqdomain the numbering will be different and
1517 * cause devices using the hardcoded IRQ numbers fail. In order not to
1518 * break such machines we will only mask pins from irqdomain if the machine
1519 * is not listed below.
1521 static const struct dmi_system_id chv_no_valid_mask[] = {
1522 /* See https://bugzilla.kernel.org/show_bug.cgi?id=194945 */
1524 .ident = "Intel_Strago based Chromebooks (All models)",
1526 DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
1527 DMI_MATCH(DMI_PRODUCT_FAMILY, "Intel_Strago"),
1531 .ident = "HP Chromebook 11 G5 (Setzer)",
1533 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
1534 DMI_MATCH(DMI_PRODUCT_NAME, "Setzer"),
1538 .ident = "Acer Chromebook R11 (Cyan)",
1540 DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
1541 DMI_MATCH(DMI_PRODUCT_NAME, "Cyan"),
1545 .ident = "Samsung Chromebook 3 (Celes)",
1547 DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"),
1548 DMI_MATCH(DMI_PRODUCT_NAME, "Celes"),
1554 static int chv_gpio_probe(struct chv_pinctrl *pctrl, int irq)
1556 const struct chv_gpio_pinrange *range;
1557 struct gpio_chip *chip = &pctrl->chip;
1558 bool need_valid_mask = !dmi_check_system(chv_no_valid_mask);
1559 const struct chv_community *community = pctrl->community;
1560 int ret, i, irq_base;
1562 *chip = chv_gpio_chip;
1564 chip->ngpio = community->pins[community->npins - 1].number + 1;
1565 chip->label = dev_name(pctrl->dev);
1566 chip->parent = pctrl->dev;
1568 chip->irq.need_valid_mask = need_valid_mask;
1570 ret = devm_gpiochip_add_data(pctrl->dev, chip, pctrl);
1572 dev_err(pctrl->dev, "Failed to register gpiochip\n");
1576 for (i = 0; i < community->ngpio_ranges; i++) {
1577 range = &community->gpio_ranges[i];
1578 ret = gpiochip_add_pin_range(chip, dev_name(pctrl->dev),
1579 range->base, range->base,
1582 dev_err(pctrl->dev, "failed to add GPIO pin range\n");
1587 /* Do not add GPIOs that can only generate GPEs to the IRQ domain */
1588 for (i = 0; i < community->npins; i++) {
1589 const struct pinctrl_pin_desc *desc;
1592 desc = &community->pins[i];
1594 intsel = readl(chv_padreg(pctrl, desc->number, CHV_PADCTRL0));
1595 intsel &= CHV_PADCTRL0_INTSEL_MASK;
1596 intsel >>= CHV_PADCTRL0_INTSEL_SHIFT;
1598 if (need_valid_mask && intsel >= community->nirqs)
1599 clear_bit(desc->number, chip->irq.valid_mask);
1603 * The same set of machines in chv_no_valid_mask[] have incorrectly
1604 * configured GPIOs that generate spurious interrupts so we use
1605 * this same list to apply another quirk for them.
1607 * See also https://bugzilla.kernel.org/show_bug.cgi?id=197953.
1609 if (!need_valid_mask) {
1611 * Mask all interrupts the community is able to generate
1612 * but leave the ones that can only generate GPEs unmasked.
1614 chv_writel(GENMASK(31, pctrl->community->nirqs),
1615 pctrl->regs + CHV_INTMASK);
1618 /* Clear all interrupts */
1619 chv_writel(0xffff, pctrl->regs + CHV_INTSTAT);
1621 if (!need_valid_mask) {
1622 irq_base = devm_irq_alloc_descs(pctrl->dev, -1, 0,
1623 community->npins, NUMA_NO_NODE);
1625 dev_err(pctrl->dev, "Failed to allocate IRQ numbers\n");
1630 pctrl->irqchip.name = "chv-gpio";
1631 pctrl->irqchip.irq_startup = chv_gpio_irq_startup;
1632 pctrl->irqchip.irq_ack = chv_gpio_irq_ack;
1633 pctrl->irqchip.irq_mask = chv_gpio_irq_mask;
1634 pctrl->irqchip.irq_unmask = chv_gpio_irq_unmask;
1635 pctrl->irqchip.irq_set_type = chv_gpio_irq_type;
1636 pctrl->irqchip.flags = IRQCHIP_SKIP_SET_WAKE;
1638 ret = gpiochip_irqchip_add(chip, &pctrl->irqchip, 0,
1639 handle_bad_irq, IRQ_TYPE_NONE);
1641 dev_err(pctrl->dev, "failed to add IRQ chip\n");
1645 if (!need_valid_mask) {
1646 for (i = 0; i < community->ngpio_ranges; i++) {
1647 range = &community->gpio_ranges[i];
1649 irq_domain_associate_many(chip->irq.domain, irq_base,
1650 range->base, range->npins);
1651 irq_base += range->npins;
1655 gpiochip_set_chained_irqchip(chip, &pctrl->irqchip, irq,
1656 chv_gpio_irq_handler);
1660 static acpi_status chv_pinctrl_mmio_access_handler(u32 function,
1661 acpi_physical_address address, u32 bits, u64 *value,
1662 void *handler_context, void *region_context)
1664 struct chv_pinctrl *pctrl = region_context;
1665 unsigned long flags;
1666 acpi_status ret = AE_OK;
1668 raw_spin_lock_irqsave(&chv_lock, flags);
1670 if (function == ACPI_WRITE)
1671 chv_writel((u32)(*value), pctrl->regs + (u32)address);
1672 else if (function == ACPI_READ)
1673 *value = readl(pctrl->regs + (u32)address);
1675 ret = AE_BAD_PARAMETER;
1677 raw_spin_unlock_irqrestore(&chv_lock, flags);
1682 static int chv_pinctrl_probe(struct platform_device *pdev)
1684 struct chv_pinctrl *pctrl;
1685 struct acpi_device *adev;
1686 struct resource *res;
1690 adev = ACPI_COMPANION(&pdev->dev);
1694 pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL);
1698 for (i = 0; i < ARRAY_SIZE(chv_communities); i++)
1699 if (!strcmp(adev->pnp.unique_id, chv_communities[i]->uid)) {
1700 pctrl->community = chv_communities[i];
1703 if (i == ARRAY_SIZE(chv_communities))
1706 pctrl->dev = &pdev->dev;
1708 #ifdef CONFIG_PM_SLEEP
1709 pctrl->saved_pin_context = devm_kcalloc(pctrl->dev,
1710 pctrl->community->npins, sizeof(*pctrl->saved_pin_context),
1712 if (!pctrl->saved_pin_context)
1716 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1717 pctrl->regs = devm_ioremap_resource(&pdev->dev, res);
1718 if (IS_ERR(pctrl->regs))
1719 return PTR_ERR(pctrl->regs);
1721 irq = platform_get_irq(pdev, 0);
1723 dev_err(&pdev->dev, "failed to get interrupt number\n");
1727 pctrl->pctldesc = chv_pinctrl_desc;
1728 pctrl->pctldesc.name = dev_name(&pdev->dev);
1729 pctrl->pctldesc.pins = pctrl->community->pins;
1730 pctrl->pctldesc.npins = pctrl->community->npins;
1732 pctrl->pctldev = devm_pinctrl_register(&pdev->dev, &pctrl->pctldesc,
1734 if (IS_ERR(pctrl->pctldev)) {
1735 dev_err(&pdev->dev, "failed to register pinctrl driver\n");
1736 return PTR_ERR(pctrl->pctldev);
1739 ret = chv_gpio_probe(pctrl, irq);
1743 status = acpi_install_address_space_handler(adev->handle,
1744 pctrl->community->acpi_space_id,
1745 chv_pinctrl_mmio_access_handler,
1747 if (ACPI_FAILURE(status))
1748 dev_err(&pdev->dev, "failed to install ACPI addr space handler\n");
1750 platform_set_drvdata(pdev, pctrl);
1755 static int chv_pinctrl_remove(struct platform_device *pdev)
1757 struct chv_pinctrl *pctrl = platform_get_drvdata(pdev);
1759 acpi_remove_address_space_handler(ACPI_COMPANION(&pdev->dev),
1760 pctrl->community->acpi_space_id,
1761 chv_pinctrl_mmio_access_handler);
1766 #ifdef CONFIG_PM_SLEEP
1767 static int chv_pinctrl_suspend_noirq(struct device *dev)
1769 struct platform_device *pdev = to_platform_device(dev);
1770 struct chv_pinctrl *pctrl = platform_get_drvdata(pdev);
1771 unsigned long flags;
1774 raw_spin_lock_irqsave(&chv_lock, flags);
1776 pctrl->saved_intmask = readl(pctrl->regs + CHV_INTMASK);
1778 for (i = 0; i < pctrl->community->npins; i++) {
1779 const struct pinctrl_pin_desc *desc;
1780 struct chv_pin_context *ctx;
1783 desc = &pctrl->community->pins[i];
1784 if (chv_pad_locked(pctrl, desc->number))
1787 ctx = &pctrl->saved_pin_context[i];
1789 reg = chv_padreg(pctrl, desc->number, CHV_PADCTRL0);
1790 ctx->padctrl0 = readl(reg) & ~CHV_PADCTRL0_GPIORXSTATE;
1792 reg = chv_padreg(pctrl, desc->number, CHV_PADCTRL1);
1793 ctx->padctrl1 = readl(reg);
1796 raw_spin_unlock_irqrestore(&chv_lock, flags);
1801 static int chv_pinctrl_resume_noirq(struct device *dev)
1803 struct platform_device *pdev = to_platform_device(dev);
1804 struct chv_pinctrl *pctrl = platform_get_drvdata(pdev);
1805 unsigned long flags;
1808 raw_spin_lock_irqsave(&chv_lock, flags);
1811 * Mask all interrupts before restoring per-pin configuration
1812 * registers because we don't know in which state BIOS left them
1813 * upon exiting suspend.
1815 chv_writel(0, pctrl->regs + CHV_INTMASK);
1817 for (i = 0; i < pctrl->community->npins; i++) {
1818 const struct pinctrl_pin_desc *desc;
1819 const struct chv_pin_context *ctx;
1823 desc = &pctrl->community->pins[i];
1824 if (chv_pad_locked(pctrl, desc->number))
1827 ctx = &pctrl->saved_pin_context[i];
1829 /* Only restore if our saved state differs from the current */
1830 reg = chv_padreg(pctrl, desc->number, CHV_PADCTRL0);
1831 val = readl(reg) & ~CHV_PADCTRL0_GPIORXSTATE;
1832 if (ctx->padctrl0 != val) {
1833 chv_writel(ctx->padctrl0, reg);
1834 dev_dbg(pctrl->dev, "restored pin %2u ctrl0 0x%08x\n",
1835 desc->number, readl(reg));
1838 reg = chv_padreg(pctrl, desc->number, CHV_PADCTRL1);
1840 if (ctx->padctrl1 != val) {
1841 chv_writel(ctx->padctrl1, reg);
1842 dev_dbg(pctrl->dev, "restored pin %2u ctrl1 0x%08x\n",
1843 desc->number, readl(reg));
1848 * Now that all pins are restored to known state, we can restore
1849 * the interrupt mask register as well.
1851 chv_writel(0xffff, pctrl->regs + CHV_INTSTAT);
1852 chv_writel(pctrl->saved_intmask, pctrl->regs + CHV_INTMASK);
1854 raw_spin_unlock_irqrestore(&chv_lock, flags);
1860 static const struct dev_pm_ops chv_pinctrl_pm_ops = {
1861 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(chv_pinctrl_suspend_noirq,
1862 chv_pinctrl_resume_noirq)
1865 static const struct acpi_device_id chv_pinctrl_acpi_match[] = {
1869 MODULE_DEVICE_TABLE(acpi, chv_pinctrl_acpi_match);
1871 static struct platform_driver chv_pinctrl_driver = {
1872 .probe = chv_pinctrl_probe,
1873 .remove = chv_pinctrl_remove,
1875 .name = "cherryview-pinctrl",
1876 .pm = &chv_pinctrl_pm_ops,
1877 .acpi_match_table = chv_pinctrl_acpi_match,
1881 static int __init chv_pinctrl_init(void)
1883 return platform_driver_register(&chv_pinctrl_driver);
1885 subsys_initcall(chv_pinctrl_init);
1887 static void __exit chv_pinctrl_exit(void)
1889 platform_driver_unregister(&chv_pinctrl_driver);
1891 module_exit(chv_pinctrl_exit);
1893 MODULE_AUTHOR("Mika Westerberg <mika.westerberg@linux.intel.com>");
1894 MODULE_DESCRIPTION("Intel Cherryview/Braswell pinctrl driver");
1895 MODULE_LICENSE("GPL v2");