16e08d6bbSMika Westerberg /* 26e08d6bbSMika Westerberg * Cherryview/Braswell pinctrl driver 36e08d6bbSMika Westerberg * 46e08d6bbSMika Westerberg * Copyright (C) 2014, Intel Corporation 56e08d6bbSMika Westerberg * Author: Mika Westerberg <mika.westerberg@linux.intel.com> 66e08d6bbSMika Westerberg * 76e08d6bbSMika Westerberg * This driver is based on the original Cherryview GPIO driver by 86e08d6bbSMika Westerberg * Ning Li <ning.li@intel.com> 96e08d6bbSMika Westerberg * Alan Cox <alan@linux.intel.com> 106e08d6bbSMika Westerberg * 116e08d6bbSMika Westerberg * This program is free software; you can redistribute it and/or modify 126e08d6bbSMika Westerberg * it under the terms of the GNU General Public License version 2 as 136e08d6bbSMika Westerberg * published by the Free Software Foundation. 146e08d6bbSMika Westerberg */ 156e08d6bbSMika Westerberg 166e08d6bbSMika Westerberg #include <linux/kernel.h> 176e08d6bbSMika Westerberg #include <linux/module.h> 186e08d6bbSMika Westerberg #include <linux/init.h> 196e08d6bbSMika Westerberg #include <linux/types.h> 206e08d6bbSMika Westerberg #include <linux/gpio.h> 216e08d6bbSMika Westerberg #include <linux/gpio/driver.h> 226e08d6bbSMika Westerberg #include <linux/acpi.h> 236e08d6bbSMika Westerberg #include <linux/pinctrl/pinctrl.h> 246e08d6bbSMika Westerberg #include <linux/pinctrl/pinmux.h> 256e08d6bbSMika Westerberg #include <linux/pinctrl/pinconf.h> 266e08d6bbSMika Westerberg #include <linux/pinctrl/pinconf-generic.h> 276e08d6bbSMika Westerberg #include <linux/platform_device.h> 286e08d6bbSMika Westerberg 296e08d6bbSMika Westerberg #define CHV_INTSTAT 0x300 306e08d6bbSMika Westerberg #define CHV_INTMASK 0x380 316e08d6bbSMika Westerberg 326e08d6bbSMika Westerberg #define FAMILY_PAD_REGS_OFF 0x4400 336e08d6bbSMika Westerberg #define FAMILY_PAD_REGS_SIZE 0x400 346e08d6bbSMika Westerberg #define MAX_FAMILY_PAD_GPIO_NO 15 356e08d6bbSMika Westerberg #define GPIO_REGS_SIZE 8 366e08d6bbSMika Westerberg 376e08d6bbSMika Westerberg #define CHV_PADCTRL0 0x000 386e08d6bbSMika Westerberg #define CHV_PADCTRL0_INTSEL_SHIFT 28 396e08d6bbSMika Westerberg #define CHV_PADCTRL0_INTSEL_MASK (0xf << CHV_PADCTRL0_INTSEL_SHIFT) 406e08d6bbSMika Westerberg #define CHV_PADCTRL0_TERM_UP BIT(23) 416e08d6bbSMika Westerberg #define CHV_PADCTRL0_TERM_SHIFT 20 426e08d6bbSMika Westerberg #define CHV_PADCTRL0_TERM_MASK (7 << CHV_PADCTRL0_TERM_SHIFT) 436e08d6bbSMika Westerberg #define CHV_PADCTRL0_TERM_20K 1 446e08d6bbSMika Westerberg #define CHV_PADCTRL0_TERM_5K 2 456e08d6bbSMika Westerberg #define CHV_PADCTRL0_TERM_1K 4 466e08d6bbSMika Westerberg #define CHV_PADCTRL0_PMODE_SHIFT 16 476e08d6bbSMika Westerberg #define CHV_PADCTRL0_PMODE_MASK (0xf << CHV_PADCTRL0_PMODE_SHIFT) 486e08d6bbSMika Westerberg #define CHV_PADCTRL0_GPIOEN BIT(15) 496e08d6bbSMika Westerberg #define CHV_PADCTRL0_GPIOCFG_SHIFT 8 506e08d6bbSMika Westerberg #define CHV_PADCTRL0_GPIOCFG_MASK (7 << CHV_PADCTRL0_GPIOCFG_SHIFT) 516e08d6bbSMika Westerberg #define CHV_PADCTRL0_GPIOCFG_GPIO 0 526e08d6bbSMika Westerberg #define CHV_PADCTRL0_GPIOCFG_GPO 1 536e08d6bbSMika Westerberg #define CHV_PADCTRL0_GPIOCFG_GPI 2 546e08d6bbSMika Westerberg #define CHV_PADCTRL0_GPIOCFG_HIZ 3 556e08d6bbSMika Westerberg #define CHV_PADCTRL0_GPIOTXSTATE BIT(1) 566e08d6bbSMika Westerberg #define CHV_PADCTRL0_GPIORXSTATE BIT(0) 576e08d6bbSMika Westerberg 586e08d6bbSMika Westerberg #define CHV_PADCTRL1 0x004 596e08d6bbSMika Westerberg #define CHV_PADCTRL1_CFGLOCK BIT(31) 606e08d6bbSMika Westerberg #define CHV_PADCTRL1_INVRXTX_SHIFT 4 616e08d6bbSMika Westerberg #define CHV_PADCTRL1_INVRXTX_MASK (0xf << CHV_PADCTRL1_INVRXTX_SHIFT) 626e08d6bbSMika Westerberg #define CHV_PADCTRL1_INVRXTX_TXENABLE (2 << CHV_PADCTRL1_INVRXTX_SHIFT) 636e08d6bbSMika Westerberg #define CHV_PADCTRL1_ODEN BIT(3) 646e08d6bbSMika Westerberg #define CHV_PADCTRL1_INVRXTX_RXDATA (4 << CHV_PADCTRL1_INVRXTX_SHIFT) 656e08d6bbSMika Westerberg #define CHV_PADCTRL1_INTWAKECFG_MASK 7 666e08d6bbSMika Westerberg #define CHV_PADCTRL1_INTWAKECFG_FALLING 1 676e08d6bbSMika Westerberg #define CHV_PADCTRL1_INTWAKECFG_RISING 2 686e08d6bbSMika Westerberg #define CHV_PADCTRL1_INTWAKECFG_BOTH 3 696e08d6bbSMika Westerberg #define CHV_PADCTRL1_INTWAKECFG_LEVEL 4 706e08d6bbSMika Westerberg 716e08d6bbSMika Westerberg /** 726e08d6bbSMika Westerberg * struct chv_alternate_function - A per group or per pin alternate function 736e08d6bbSMika Westerberg * @pin: Pin number (only used in per pin configs) 746e08d6bbSMika Westerberg * @mode: Mode the pin should be set in 756e08d6bbSMika Westerberg * @invert_oe: Invert OE for this pin 766e08d6bbSMika Westerberg */ 776e08d6bbSMika Westerberg struct chv_alternate_function { 786e08d6bbSMika Westerberg unsigned pin; 796e08d6bbSMika Westerberg u8 mode; 806e08d6bbSMika Westerberg bool invert_oe; 816e08d6bbSMika Westerberg }; 826e08d6bbSMika Westerberg 836e08d6bbSMika Westerberg /** 846e08d6bbSMika Westerberg * struct chv_pincgroup - describes a CHV pin group 856e08d6bbSMika Westerberg * @name: Name of the group 866e08d6bbSMika Westerberg * @pins: An array of pins in this group 876e08d6bbSMika Westerberg * @npins: Number of pins in this group 886e08d6bbSMika Westerberg * @altfunc: Alternate function applied to all pins in this group 896e08d6bbSMika Westerberg * @overrides: Alternate function override per pin or %NULL if not used 906e08d6bbSMika Westerberg * @noverrides: Number of per pin alternate function overrides if 916e08d6bbSMika Westerberg * @overrides != NULL. 926e08d6bbSMika Westerberg */ 936e08d6bbSMika Westerberg struct chv_pingroup { 946e08d6bbSMika Westerberg const char *name; 956e08d6bbSMika Westerberg const unsigned *pins; 966e08d6bbSMika Westerberg size_t npins; 976e08d6bbSMika Westerberg struct chv_alternate_function altfunc; 986e08d6bbSMika Westerberg const struct chv_alternate_function *overrides; 996e08d6bbSMika Westerberg size_t noverrides; 1006e08d6bbSMika Westerberg }; 1016e08d6bbSMika Westerberg 1026e08d6bbSMika Westerberg /** 1036e08d6bbSMika Westerberg * struct chv_function - A CHV pinmux function 1046e08d6bbSMika Westerberg * @name: Name of the function 1056e08d6bbSMika Westerberg * @groups: An array of groups for this function 1066e08d6bbSMika Westerberg * @ngroups: Number of groups in @groups 1076e08d6bbSMika Westerberg */ 1086e08d6bbSMika Westerberg struct chv_function { 1096e08d6bbSMika Westerberg const char *name; 1106e08d6bbSMika Westerberg const char * const *groups; 1116e08d6bbSMika Westerberg size_t ngroups; 1126e08d6bbSMika Westerberg }; 1136e08d6bbSMika Westerberg 1146e08d6bbSMika Westerberg /** 1156e08d6bbSMika Westerberg * struct chv_gpio_pinrange - A range of pins that can be used as GPIOs 1166e08d6bbSMika Westerberg * @base: Start pin number 1176e08d6bbSMika Westerberg * @npins: Number of pins in this range 1186e08d6bbSMika Westerberg */ 1196e08d6bbSMika Westerberg struct chv_gpio_pinrange { 1206e08d6bbSMika Westerberg unsigned base; 1216e08d6bbSMika Westerberg unsigned npins; 1226e08d6bbSMika Westerberg }; 1236e08d6bbSMika Westerberg 1246e08d6bbSMika Westerberg /** 1256e08d6bbSMika Westerberg * struct chv_community - A community specific configuration 1266e08d6bbSMika Westerberg * @uid: ACPI _UID used to match the community 1276e08d6bbSMika Westerberg * @pins: All pins in this community 1286e08d6bbSMika Westerberg * @npins: Number of pins 1296e08d6bbSMika Westerberg * @groups: All groups in this community 1306e08d6bbSMika Westerberg * @ngroups: Number of groups 1316e08d6bbSMika Westerberg * @functions: All functions in this community 1326e08d6bbSMika Westerberg * @nfunctions: Number of functions 1336e08d6bbSMika Westerberg * @ngpios: Number of GPIOs in this community 1346e08d6bbSMika Westerberg * @gpio_ranges: An array of GPIO ranges in this community 1356e08d6bbSMika Westerberg * @ngpio_ranges: Number of GPIO ranges 1366e08d6bbSMika Westerberg * @ngpios: Total number of GPIOs in this community 1376e08d6bbSMika Westerberg */ 1386e08d6bbSMika Westerberg struct chv_community { 1396e08d6bbSMika Westerberg const char *uid; 1406e08d6bbSMika Westerberg const struct pinctrl_pin_desc *pins; 1416e08d6bbSMika Westerberg size_t npins; 1426e08d6bbSMika Westerberg const struct chv_pingroup *groups; 1436e08d6bbSMika Westerberg size_t ngroups; 1446e08d6bbSMika Westerberg const struct chv_function *functions; 1456e08d6bbSMika Westerberg size_t nfunctions; 1466e08d6bbSMika Westerberg const struct chv_gpio_pinrange *gpio_ranges; 1476e08d6bbSMika Westerberg size_t ngpio_ranges; 1486e08d6bbSMika Westerberg size_t ngpios; 1496e08d6bbSMika Westerberg }; 1506e08d6bbSMika Westerberg 1519eb457b5SMika Westerberg struct chv_pin_context { 1529eb457b5SMika Westerberg u32 padctrl0; 1539eb457b5SMika Westerberg u32 padctrl1; 1549eb457b5SMika Westerberg }; 1559eb457b5SMika Westerberg 1566e08d6bbSMika Westerberg /** 1576e08d6bbSMika Westerberg * struct chv_pinctrl - CHV pinctrl private structure 1586e08d6bbSMika Westerberg * @dev: Pointer to the parent device 1596e08d6bbSMika Westerberg * @pctldesc: Pin controller description 1606e08d6bbSMika Westerberg * @pctldev: Pointer to the pin controller device 1616e08d6bbSMika Westerberg * @chip: GPIO chip in this pin controller 1626e08d6bbSMika Westerberg * @regs: MMIO registers 1636e08d6bbSMika Westerberg * @lock: Lock to serialize register accesses 1646e08d6bbSMika Westerberg * @intr_lines: Stores mapping between 16 HW interrupt wires and GPIO 1656e08d6bbSMika Westerberg * offset (in GPIO number space) 1666e08d6bbSMika Westerberg * @community: Community this pinctrl instance represents 1676e08d6bbSMika Westerberg * 1686e08d6bbSMika Westerberg * The first group in @groups is expected to contain all pins that can be 1696e08d6bbSMika Westerberg * used as GPIOs. 1706e08d6bbSMika Westerberg */ 1716e08d6bbSMika Westerberg struct chv_pinctrl { 1726e08d6bbSMika Westerberg struct device *dev; 1736e08d6bbSMika Westerberg struct pinctrl_desc pctldesc; 1746e08d6bbSMika Westerberg struct pinctrl_dev *pctldev; 1756e08d6bbSMika Westerberg struct gpio_chip chip; 1766e08d6bbSMika Westerberg void __iomem *regs; 177109fdf15SMika Westerberg raw_spinlock_t lock; 1786e08d6bbSMika Westerberg unsigned intr_lines[16]; 1796e08d6bbSMika Westerberg const struct chv_community *community; 1809eb457b5SMika Westerberg u32 saved_intmask; 1819eb457b5SMika Westerberg struct chv_pin_context *saved_pin_context; 1826e08d6bbSMika Westerberg }; 1836e08d6bbSMika Westerberg 1846e08d6bbSMika Westerberg #define gpiochip_to_pinctrl(c) container_of(c, struct chv_pinctrl, chip) 1856e08d6bbSMika Westerberg 1866e08d6bbSMika Westerberg #define ALTERNATE_FUNCTION(p, m, i) \ 1876e08d6bbSMika Westerberg { \ 1886e08d6bbSMika Westerberg .pin = (p), \ 1896e08d6bbSMika Westerberg .mode = (m), \ 1906e08d6bbSMika Westerberg .invert_oe = (i), \ 1916e08d6bbSMika Westerberg } 1926e08d6bbSMika Westerberg 1936e08d6bbSMika Westerberg #define PIN_GROUP(n, p, m, i) \ 1946e08d6bbSMika Westerberg { \ 1956e08d6bbSMika Westerberg .name = (n), \ 1966e08d6bbSMika Westerberg .pins = (p), \ 1976e08d6bbSMika Westerberg .npins = ARRAY_SIZE((p)), \ 1986e08d6bbSMika Westerberg .altfunc.mode = (m), \ 1996e08d6bbSMika Westerberg .altfunc.invert_oe = (i), \ 2006e08d6bbSMika Westerberg } 2016e08d6bbSMika Westerberg 2026e08d6bbSMika Westerberg #define PIN_GROUP_WITH_OVERRIDE(n, p, m, i, o) \ 2036e08d6bbSMika Westerberg { \ 2046e08d6bbSMika Westerberg .name = (n), \ 2056e08d6bbSMika Westerberg .pins = (p), \ 2066e08d6bbSMika Westerberg .npins = ARRAY_SIZE((p)), \ 2076e08d6bbSMika Westerberg .altfunc.mode = (m), \ 2086e08d6bbSMika Westerberg .altfunc.invert_oe = (i), \ 2096e08d6bbSMika Westerberg .overrides = (o), \ 2106e08d6bbSMika Westerberg .noverrides = ARRAY_SIZE((o)), \ 2116e08d6bbSMika Westerberg } 2126e08d6bbSMika Westerberg 2136e08d6bbSMika Westerberg #define FUNCTION(n, g) \ 2146e08d6bbSMika Westerberg { \ 2156e08d6bbSMika Westerberg .name = (n), \ 2166e08d6bbSMika Westerberg .groups = (g), \ 2176e08d6bbSMika Westerberg .ngroups = ARRAY_SIZE((g)), \ 2186e08d6bbSMika Westerberg } 2196e08d6bbSMika Westerberg 2206e08d6bbSMika Westerberg #define GPIO_PINRANGE(start, end) \ 2216e08d6bbSMika Westerberg { \ 2226e08d6bbSMika Westerberg .base = (start), \ 2236e08d6bbSMika Westerberg .npins = (end) - (start) + 1, \ 2246e08d6bbSMika Westerberg } 2256e08d6bbSMika Westerberg 2266e08d6bbSMika Westerberg static const struct pinctrl_pin_desc southwest_pins[] = { 2276e08d6bbSMika Westerberg PINCTRL_PIN(0, "FST_SPI_D2"), 2286e08d6bbSMika Westerberg PINCTRL_PIN(1, "FST_SPI_D0"), 2296e08d6bbSMika Westerberg PINCTRL_PIN(2, "FST_SPI_CLK"), 2306e08d6bbSMika Westerberg PINCTRL_PIN(3, "FST_SPI_D3"), 2316e08d6bbSMika Westerberg PINCTRL_PIN(4, "FST_SPI_CS1_B"), 2326e08d6bbSMika Westerberg PINCTRL_PIN(5, "FST_SPI_D1"), 2336e08d6bbSMika Westerberg PINCTRL_PIN(6, "FST_SPI_CS0_B"), 2346e08d6bbSMika Westerberg PINCTRL_PIN(7, "FST_SPI_CS2_B"), 2356e08d6bbSMika Westerberg 2366e08d6bbSMika Westerberg PINCTRL_PIN(15, "UART1_RTS_B"), 2376e08d6bbSMika Westerberg PINCTRL_PIN(16, "UART1_RXD"), 2386e08d6bbSMika Westerberg PINCTRL_PIN(17, "UART2_RXD"), 2396e08d6bbSMika Westerberg PINCTRL_PIN(18, "UART1_CTS_B"), 2406e08d6bbSMika Westerberg PINCTRL_PIN(19, "UART2_RTS_B"), 2416e08d6bbSMika Westerberg PINCTRL_PIN(20, "UART1_TXD"), 2426e08d6bbSMika Westerberg PINCTRL_PIN(21, "UART2_TXD"), 2436e08d6bbSMika Westerberg PINCTRL_PIN(22, "UART2_CTS_B"), 2446e08d6bbSMika Westerberg 2456e08d6bbSMika Westerberg PINCTRL_PIN(30, "MF_HDA_CLK"), 2466e08d6bbSMika Westerberg PINCTRL_PIN(31, "MF_HDA_RSTB"), 2476e08d6bbSMika Westerberg PINCTRL_PIN(32, "MF_HDA_SDIO"), 2486e08d6bbSMika Westerberg PINCTRL_PIN(33, "MF_HDA_SDO"), 2496e08d6bbSMika Westerberg PINCTRL_PIN(34, "MF_HDA_DOCKRSTB"), 2506e08d6bbSMika Westerberg PINCTRL_PIN(35, "MF_HDA_SYNC"), 2516e08d6bbSMika Westerberg PINCTRL_PIN(36, "MF_HDA_SDI1"), 2526e08d6bbSMika Westerberg PINCTRL_PIN(37, "MF_HDA_DOCKENB"), 2536e08d6bbSMika Westerberg 2546e08d6bbSMika Westerberg PINCTRL_PIN(45, "I2C5_SDA"), 2556e08d6bbSMika Westerberg PINCTRL_PIN(46, "I2C4_SDA"), 2566e08d6bbSMika Westerberg PINCTRL_PIN(47, "I2C6_SDA"), 2576e08d6bbSMika Westerberg PINCTRL_PIN(48, "I2C5_SCL"), 2586e08d6bbSMika Westerberg PINCTRL_PIN(49, "I2C_NFC_SDA"), 2596e08d6bbSMika Westerberg PINCTRL_PIN(50, "I2C4_SCL"), 2606e08d6bbSMika Westerberg PINCTRL_PIN(51, "I2C6_SCL"), 2616e08d6bbSMika Westerberg PINCTRL_PIN(52, "I2C_NFC_SCL"), 2626e08d6bbSMika Westerberg 2636e08d6bbSMika Westerberg PINCTRL_PIN(60, "I2C1_SDA"), 2646e08d6bbSMika Westerberg PINCTRL_PIN(61, "I2C0_SDA"), 2656e08d6bbSMika Westerberg PINCTRL_PIN(62, "I2C2_SDA"), 2666e08d6bbSMika Westerberg PINCTRL_PIN(63, "I2C1_SCL"), 2676e08d6bbSMika Westerberg PINCTRL_PIN(64, "I2C3_SDA"), 2686e08d6bbSMika Westerberg PINCTRL_PIN(65, "I2C0_SCL"), 2696e08d6bbSMika Westerberg PINCTRL_PIN(66, "I2C2_SCL"), 2706e08d6bbSMika Westerberg PINCTRL_PIN(67, "I2C3_SCL"), 2716e08d6bbSMika Westerberg 2726e08d6bbSMika Westerberg PINCTRL_PIN(75, "SATA_GP0"), 2736e08d6bbSMika Westerberg PINCTRL_PIN(76, "SATA_GP1"), 2746e08d6bbSMika Westerberg PINCTRL_PIN(77, "SATA_LEDN"), 2756e08d6bbSMika Westerberg PINCTRL_PIN(78, "SATA_GP2"), 2766e08d6bbSMika Westerberg PINCTRL_PIN(79, "MF_SMB_ALERTB"), 2776e08d6bbSMika Westerberg PINCTRL_PIN(80, "SATA_GP3"), 2786e08d6bbSMika Westerberg PINCTRL_PIN(81, "MF_SMB_CLK"), 2796e08d6bbSMika Westerberg PINCTRL_PIN(82, "MF_SMB_DATA"), 2806e08d6bbSMika Westerberg 2816e08d6bbSMika Westerberg PINCTRL_PIN(90, "PCIE_CLKREQ0B"), 2826e08d6bbSMika Westerberg PINCTRL_PIN(91, "PCIE_CLKREQ1B"), 2836e08d6bbSMika Westerberg PINCTRL_PIN(92, "GP_SSP_2_CLK"), 2846e08d6bbSMika Westerberg PINCTRL_PIN(93, "PCIE_CLKREQ2B"), 2856e08d6bbSMika Westerberg PINCTRL_PIN(94, "GP_SSP_2_RXD"), 2866e08d6bbSMika Westerberg PINCTRL_PIN(95, "PCIE_CLKREQ3B"), 2876e08d6bbSMika Westerberg PINCTRL_PIN(96, "GP_SSP_2_FS"), 2886e08d6bbSMika Westerberg PINCTRL_PIN(97, "GP_SSP_2_TXD"), 2896e08d6bbSMika Westerberg }; 2906e08d6bbSMika Westerberg 2916e08d6bbSMika Westerberg static const unsigned southwest_fspi_pins[] = { 0, 1, 2, 3, 4, 5, 6, 7 }; 2926e08d6bbSMika Westerberg static const unsigned southwest_uart0_pins[] = { 16, 20 }; 2936e08d6bbSMika Westerberg static const unsigned southwest_uart1_pins[] = { 15, 16, 18, 20 }; 2946e08d6bbSMika Westerberg static const unsigned southwest_uart2_pins[] = { 17, 19, 21, 22 }; 2956e08d6bbSMika Westerberg static const unsigned southwest_i2c0_pins[] = { 61, 65 }; 2966e08d6bbSMika Westerberg static const unsigned southwest_hda_pins[] = { 30, 31, 32, 33, 34, 35, 36, 37 }; 2976e08d6bbSMika Westerberg static const unsigned southwest_lpe_pins[] = { 2986e08d6bbSMika Westerberg 30, 31, 32, 33, 34, 35, 36, 37, 92, 94, 96, 97, 2996e08d6bbSMika Westerberg }; 3006e08d6bbSMika Westerberg static const unsigned southwest_i2c1_pins[] = { 60, 63 }; 3016e08d6bbSMika Westerberg static const unsigned southwest_i2c2_pins[] = { 62, 66 }; 3026e08d6bbSMika Westerberg static const unsigned southwest_i2c3_pins[] = { 64, 67 }; 3036e08d6bbSMika Westerberg static const unsigned southwest_i2c4_pins[] = { 46, 50 }; 3046e08d6bbSMika Westerberg static const unsigned southwest_i2c5_pins[] = { 45, 48 }; 3056e08d6bbSMika Westerberg static const unsigned southwest_i2c6_pins[] = { 47, 51 }; 3066e08d6bbSMika Westerberg static const unsigned southwest_i2c_nfc_pins[] = { 49, 52 }; 3076e08d6bbSMika Westerberg static const unsigned southwest_smbus_pins[] = { 79, 81, 82 }; 3086e08d6bbSMika Westerberg static const unsigned southwest_spi3_pins[] = { 76, 79, 80, 81, 82 }; 3096e08d6bbSMika Westerberg 3106e08d6bbSMika Westerberg /* LPE I2S TXD pins need to have invert_oe set */ 3116e08d6bbSMika Westerberg static const struct chv_alternate_function southwest_lpe_altfuncs[] = { 3126e08d6bbSMika Westerberg ALTERNATE_FUNCTION(30, 1, true), 3136e08d6bbSMika Westerberg ALTERNATE_FUNCTION(34, 1, true), 3146e08d6bbSMika Westerberg ALTERNATE_FUNCTION(97, 1, true), 3156e08d6bbSMika Westerberg }; 3166e08d6bbSMika Westerberg 3176e08d6bbSMika Westerberg /* 3186e08d6bbSMika Westerberg * Two spi3 chipselects are available in different mode than the main spi3 3196e08d6bbSMika Westerberg * functionality, which is using mode 1. 3206e08d6bbSMika Westerberg */ 3216e08d6bbSMika Westerberg static const struct chv_alternate_function southwest_spi3_altfuncs[] = { 3226e08d6bbSMika Westerberg ALTERNATE_FUNCTION(76, 3, false), 3236e08d6bbSMika Westerberg ALTERNATE_FUNCTION(80, 3, false), 3246e08d6bbSMika Westerberg }; 3256e08d6bbSMika Westerberg 3266e08d6bbSMika Westerberg static const struct chv_pingroup southwest_groups[] = { 3276e08d6bbSMika Westerberg PIN_GROUP("uart0_grp", southwest_uart0_pins, 2, false), 3286e08d6bbSMika Westerberg PIN_GROUP("uart1_grp", southwest_uart1_pins, 1, false), 3296e08d6bbSMika Westerberg PIN_GROUP("uart2_grp", southwest_uart2_pins, 1, false), 3306e08d6bbSMika Westerberg PIN_GROUP("hda_grp", southwest_hda_pins, 2, false), 3316e08d6bbSMika Westerberg PIN_GROUP("i2c0_grp", southwest_i2c0_pins, 1, true), 3326e08d6bbSMika Westerberg PIN_GROUP("i2c1_grp", southwest_i2c1_pins, 1, true), 3336e08d6bbSMika Westerberg PIN_GROUP("i2c2_grp", southwest_i2c2_pins, 1, true), 3346e08d6bbSMika Westerberg PIN_GROUP("i2c3_grp", southwest_i2c3_pins, 1, true), 3356e08d6bbSMika Westerberg PIN_GROUP("i2c4_grp", southwest_i2c4_pins, 1, true), 3366e08d6bbSMika Westerberg PIN_GROUP("i2c5_grp", southwest_i2c5_pins, 1, true), 3376e08d6bbSMika Westerberg PIN_GROUP("i2c6_grp", southwest_i2c6_pins, 1, true), 3386e08d6bbSMika Westerberg PIN_GROUP("i2c_nfc_grp", southwest_i2c_nfc_pins, 2, true), 3396e08d6bbSMika Westerberg 3406e08d6bbSMika Westerberg PIN_GROUP_WITH_OVERRIDE("lpe_grp", southwest_lpe_pins, 1, false, 3416e08d6bbSMika Westerberg southwest_lpe_altfuncs), 3426e08d6bbSMika Westerberg PIN_GROUP_WITH_OVERRIDE("spi3_grp", southwest_spi3_pins, 2, false, 3436e08d6bbSMika Westerberg southwest_spi3_altfuncs), 3446e08d6bbSMika Westerberg }; 3456e08d6bbSMika Westerberg 3466e08d6bbSMika Westerberg static const char * const southwest_uart0_groups[] = { "uart0_grp" }; 3476e08d6bbSMika Westerberg static const char * const southwest_uart1_groups[] = { "uart1_grp" }; 3486e08d6bbSMika Westerberg static const char * const southwest_uart2_groups[] = { "uart2_grp" }; 3496e08d6bbSMika Westerberg static const char * const southwest_hda_groups[] = { "hda_grp" }; 3506e08d6bbSMika Westerberg static const char * const southwest_lpe_groups[] = { "lpe_grp" }; 3516e08d6bbSMika Westerberg static const char * const southwest_i2c0_groups[] = { "i2c0_grp" }; 3526e08d6bbSMika Westerberg static const char * const southwest_i2c1_groups[] = { "i2c1_grp" }; 3536e08d6bbSMika Westerberg static const char * const southwest_i2c2_groups[] = { "i2c2_grp" }; 3546e08d6bbSMika Westerberg static const char * const southwest_i2c3_groups[] = { "i2c3_grp" }; 3556e08d6bbSMika Westerberg static const char * const southwest_i2c4_groups[] = { "i2c4_grp" }; 3566e08d6bbSMika Westerberg static const char * const southwest_i2c5_groups[] = { "i2c5_grp" }; 3576e08d6bbSMika Westerberg static const char * const southwest_i2c6_groups[] = { "i2c6_grp" }; 3586e08d6bbSMika Westerberg static const char * const southwest_i2c_nfc_groups[] = { "i2c_nfc_grp" }; 3596e08d6bbSMika Westerberg static const char * const southwest_spi3_groups[] = { "spi3_grp" }; 3606e08d6bbSMika Westerberg 3616e08d6bbSMika Westerberg /* 3626e08d6bbSMika Westerberg * Only do pinmuxing for certain LPSS devices for now. Rest of the pins are 3636e08d6bbSMika Westerberg * enabled only as GPIOs. 3646e08d6bbSMika Westerberg */ 3656e08d6bbSMika Westerberg static const struct chv_function southwest_functions[] = { 3666e08d6bbSMika Westerberg FUNCTION("uart0", southwest_uart0_groups), 3676e08d6bbSMika Westerberg FUNCTION("uart1", southwest_uart1_groups), 3686e08d6bbSMika Westerberg FUNCTION("uart2", southwest_uart2_groups), 3696e08d6bbSMika Westerberg FUNCTION("hda", southwest_hda_groups), 3706e08d6bbSMika Westerberg FUNCTION("lpe", southwest_lpe_groups), 3716e08d6bbSMika Westerberg FUNCTION("i2c0", southwest_i2c0_groups), 3726e08d6bbSMika Westerberg FUNCTION("i2c1", southwest_i2c1_groups), 3736e08d6bbSMika Westerberg FUNCTION("i2c2", southwest_i2c2_groups), 3746e08d6bbSMika Westerberg FUNCTION("i2c3", southwest_i2c3_groups), 3756e08d6bbSMika Westerberg FUNCTION("i2c4", southwest_i2c4_groups), 3766e08d6bbSMika Westerberg FUNCTION("i2c5", southwest_i2c5_groups), 3776e08d6bbSMika Westerberg FUNCTION("i2c6", southwest_i2c6_groups), 3786e08d6bbSMika Westerberg FUNCTION("i2c_nfc", southwest_i2c_nfc_groups), 3796e08d6bbSMika Westerberg FUNCTION("spi3", southwest_spi3_groups), 3806e08d6bbSMika Westerberg }; 3816e08d6bbSMika Westerberg 3826e08d6bbSMika Westerberg static const struct chv_gpio_pinrange southwest_gpio_ranges[] = { 3836e08d6bbSMika Westerberg GPIO_PINRANGE(0, 7), 3846e08d6bbSMika Westerberg GPIO_PINRANGE(15, 22), 3856e08d6bbSMika Westerberg GPIO_PINRANGE(30, 37), 3866e08d6bbSMika Westerberg GPIO_PINRANGE(45, 52), 3876e08d6bbSMika Westerberg GPIO_PINRANGE(60, 67), 3886e08d6bbSMika Westerberg GPIO_PINRANGE(75, 82), 3896e08d6bbSMika Westerberg GPIO_PINRANGE(90, 97), 3906e08d6bbSMika Westerberg }; 3916e08d6bbSMika Westerberg 3926e08d6bbSMika Westerberg static const struct chv_community southwest_community = { 3936e08d6bbSMika Westerberg .uid = "1", 3946e08d6bbSMika Westerberg .pins = southwest_pins, 3956e08d6bbSMika Westerberg .npins = ARRAY_SIZE(southwest_pins), 3966e08d6bbSMika Westerberg .groups = southwest_groups, 3976e08d6bbSMika Westerberg .ngroups = ARRAY_SIZE(southwest_groups), 3986e08d6bbSMika Westerberg .functions = southwest_functions, 3996e08d6bbSMika Westerberg .nfunctions = ARRAY_SIZE(southwest_functions), 4006e08d6bbSMika Westerberg .gpio_ranges = southwest_gpio_ranges, 4016e08d6bbSMika Westerberg .ngpio_ranges = ARRAY_SIZE(southwest_gpio_ranges), 4026e08d6bbSMika Westerberg .ngpios = ARRAY_SIZE(southwest_pins), 4036e08d6bbSMika Westerberg }; 4046e08d6bbSMika Westerberg 4056e08d6bbSMika Westerberg static const struct pinctrl_pin_desc north_pins[] = { 4066e08d6bbSMika Westerberg PINCTRL_PIN(0, "GPIO_DFX_0"), 4076e08d6bbSMika Westerberg PINCTRL_PIN(1, "GPIO_DFX_3"), 4086e08d6bbSMika Westerberg PINCTRL_PIN(2, "GPIO_DFX_7"), 4096e08d6bbSMika Westerberg PINCTRL_PIN(3, "GPIO_DFX_1"), 4106e08d6bbSMika Westerberg PINCTRL_PIN(4, "GPIO_DFX_5"), 4116e08d6bbSMika Westerberg PINCTRL_PIN(5, "GPIO_DFX_4"), 4126e08d6bbSMika Westerberg PINCTRL_PIN(6, "GPIO_DFX_8"), 4136e08d6bbSMika Westerberg PINCTRL_PIN(7, "GPIO_DFX_2"), 4146e08d6bbSMika Westerberg PINCTRL_PIN(8, "GPIO_DFX_6"), 4156e08d6bbSMika Westerberg 4166e08d6bbSMika Westerberg PINCTRL_PIN(15, "GPIO_SUS0"), 4176e08d6bbSMika Westerberg PINCTRL_PIN(16, "SEC_GPIO_SUS10"), 4186e08d6bbSMika Westerberg PINCTRL_PIN(17, "GPIO_SUS3"), 4196e08d6bbSMika Westerberg PINCTRL_PIN(18, "GPIO_SUS7"), 4206e08d6bbSMika Westerberg PINCTRL_PIN(19, "GPIO_SUS1"), 4216e08d6bbSMika Westerberg PINCTRL_PIN(20, "GPIO_SUS5"), 4226e08d6bbSMika Westerberg PINCTRL_PIN(21, "SEC_GPIO_SUS11"), 4236e08d6bbSMika Westerberg PINCTRL_PIN(22, "GPIO_SUS4"), 4246e08d6bbSMika Westerberg PINCTRL_PIN(23, "SEC_GPIO_SUS8"), 4256e08d6bbSMika Westerberg PINCTRL_PIN(24, "GPIO_SUS2"), 4266e08d6bbSMika Westerberg PINCTRL_PIN(25, "GPIO_SUS6"), 4276e08d6bbSMika Westerberg PINCTRL_PIN(26, "CX_PREQ_B"), 4286e08d6bbSMika Westerberg PINCTRL_PIN(27, "SEC_GPIO_SUS9"), 4296e08d6bbSMika Westerberg 4306e08d6bbSMika Westerberg PINCTRL_PIN(30, "TRST_B"), 4316e08d6bbSMika Westerberg PINCTRL_PIN(31, "TCK"), 4326e08d6bbSMika Westerberg PINCTRL_PIN(32, "PROCHOT_B"), 4336e08d6bbSMika Westerberg PINCTRL_PIN(33, "SVIDO_DATA"), 4346e08d6bbSMika Westerberg PINCTRL_PIN(34, "TMS"), 4356e08d6bbSMika Westerberg PINCTRL_PIN(35, "CX_PRDY_B_2"), 4366e08d6bbSMika Westerberg PINCTRL_PIN(36, "TDO_2"), 4376e08d6bbSMika Westerberg PINCTRL_PIN(37, "CX_PRDY_B"), 4386e08d6bbSMika Westerberg PINCTRL_PIN(38, "SVIDO_ALERT_B"), 4396e08d6bbSMika Westerberg PINCTRL_PIN(39, "TDO"), 4406e08d6bbSMika Westerberg PINCTRL_PIN(40, "SVIDO_CLK"), 4416e08d6bbSMika Westerberg PINCTRL_PIN(41, "TDI"), 4426e08d6bbSMika Westerberg 4436e08d6bbSMika Westerberg PINCTRL_PIN(45, "GP_CAMERASB_05"), 4446e08d6bbSMika Westerberg PINCTRL_PIN(46, "GP_CAMERASB_02"), 4456e08d6bbSMika Westerberg PINCTRL_PIN(47, "GP_CAMERASB_08"), 4466e08d6bbSMika Westerberg PINCTRL_PIN(48, "GP_CAMERASB_00"), 4476e08d6bbSMika Westerberg PINCTRL_PIN(49, "GP_CAMERASB_06"), 4486e08d6bbSMika Westerberg PINCTRL_PIN(50, "GP_CAMERASB_10"), 4496e08d6bbSMika Westerberg PINCTRL_PIN(51, "GP_CAMERASB_03"), 4506e08d6bbSMika Westerberg PINCTRL_PIN(52, "GP_CAMERASB_09"), 4516e08d6bbSMika Westerberg PINCTRL_PIN(53, "GP_CAMERASB_01"), 4526e08d6bbSMika Westerberg PINCTRL_PIN(54, "GP_CAMERASB_07"), 4536e08d6bbSMika Westerberg PINCTRL_PIN(55, "GP_CAMERASB_11"), 4546e08d6bbSMika Westerberg PINCTRL_PIN(56, "GP_CAMERASB_04"), 4556e08d6bbSMika Westerberg 4566e08d6bbSMika Westerberg PINCTRL_PIN(60, "PANEL0_BKLTEN"), 4576e08d6bbSMika Westerberg PINCTRL_PIN(61, "HV_DDI0_HPD"), 4586e08d6bbSMika Westerberg PINCTRL_PIN(62, "HV_DDI2_DDC_SDA"), 4596e08d6bbSMika Westerberg PINCTRL_PIN(63, "PANEL1_BKLTCTL"), 4606e08d6bbSMika Westerberg PINCTRL_PIN(64, "HV_DDI1_HPD"), 4616e08d6bbSMika Westerberg PINCTRL_PIN(65, "PANEL0_BKLTCTL"), 4626e08d6bbSMika Westerberg PINCTRL_PIN(66, "HV_DDI0_DDC_SDA"), 4636e08d6bbSMika Westerberg PINCTRL_PIN(67, "HV_DDI2_DDC_SCL"), 4646e08d6bbSMika Westerberg PINCTRL_PIN(68, "HV_DDI2_HPD"), 4656e08d6bbSMika Westerberg PINCTRL_PIN(69, "PANEL1_VDDEN"), 4666e08d6bbSMika Westerberg PINCTRL_PIN(70, "PANEL1_BKLTEN"), 4676e08d6bbSMika Westerberg PINCTRL_PIN(71, "HV_DDI0_DDC_SCL"), 4686e08d6bbSMika Westerberg PINCTRL_PIN(72, "PANEL0_VDDEN"), 4696e08d6bbSMika Westerberg }; 4706e08d6bbSMika Westerberg 4716e08d6bbSMika Westerberg static const struct chv_gpio_pinrange north_gpio_ranges[] = { 4726e08d6bbSMika Westerberg GPIO_PINRANGE(0, 8), 4736e08d6bbSMika Westerberg GPIO_PINRANGE(15, 27), 4746e08d6bbSMika Westerberg GPIO_PINRANGE(30, 41), 4756e08d6bbSMika Westerberg GPIO_PINRANGE(45, 56), 4766e08d6bbSMika Westerberg GPIO_PINRANGE(60, 72), 4776e08d6bbSMika Westerberg }; 4786e08d6bbSMika Westerberg 4796e08d6bbSMika Westerberg static const struct chv_community north_community = { 4806e08d6bbSMika Westerberg .uid = "2", 4816e08d6bbSMika Westerberg .pins = north_pins, 4826e08d6bbSMika Westerberg .npins = ARRAY_SIZE(north_pins), 4836e08d6bbSMika Westerberg .gpio_ranges = north_gpio_ranges, 4846e08d6bbSMika Westerberg .ngpio_ranges = ARRAY_SIZE(north_gpio_ranges), 4856e08d6bbSMika Westerberg .ngpios = ARRAY_SIZE(north_pins), 4866e08d6bbSMika Westerberg }; 4876e08d6bbSMika Westerberg 4886e08d6bbSMika Westerberg static const struct pinctrl_pin_desc east_pins[] = { 4896e08d6bbSMika Westerberg PINCTRL_PIN(0, "PMU_SLP_S3_B"), 4906e08d6bbSMika Westerberg PINCTRL_PIN(1, "PMU_BATLOW_B"), 4916e08d6bbSMika Westerberg PINCTRL_PIN(2, "SUS_STAT_B"), 4926e08d6bbSMika Westerberg PINCTRL_PIN(3, "PMU_SLP_S0IX_B"), 4936e08d6bbSMika Westerberg PINCTRL_PIN(4, "PMU_AC_PRESENT"), 4946e08d6bbSMika Westerberg PINCTRL_PIN(5, "PMU_PLTRST_B"), 4956e08d6bbSMika Westerberg PINCTRL_PIN(6, "PMU_SUSCLK"), 4966e08d6bbSMika Westerberg PINCTRL_PIN(7, "PMU_SLP_LAN_B"), 4976e08d6bbSMika Westerberg PINCTRL_PIN(8, "PMU_PWRBTN_B"), 4986e08d6bbSMika Westerberg PINCTRL_PIN(9, "PMU_SLP_S4_B"), 4996e08d6bbSMika Westerberg PINCTRL_PIN(10, "PMU_WAKE_B"), 5006e08d6bbSMika Westerberg PINCTRL_PIN(11, "PMU_WAKE_LAN_B"), 5016e08d6bbSMika Westerberg 5026e08d6bbSMika Westerberg PINCTRL_PIN(15, "MF_ISH_GPIO_3"), 5036e08d6bbSMika Westerberg PINCTRL_PIN(16, "MF_ISH_GPIO_7"), 5046e08d6bbSMika Westerberg PINCTRL_PIN(17, "MF_ISH_I2C1_SCL"), 5056e08d6bbSMika Westerberg PINCTRL_PIN(18, "MF_ISH_GPIO_1"), 5066e08d6bbSMika Westerberg PINCTRL_PIN(19, "MF_ISH_GPIO_5"), 5076e08d6bbSMika Westerberg PINCTRL_PIN(20, "MF_ISH_GPIO_9"), 5086e08d6bbSMika Westerberg PINCTRL_PIN(21, "MF_ISH_GPIO_0"), 5096e08d6bbSMika Westerberg PINCTRL_PIN(22, "MF_ISH_GPIO_4"), 5106e08d6bbSMika Westerberg PINCTRL_PIN(23, "MF_ISH_GPIO_8"), 5116e08d6bbSMika Westerberg PINCTRL_PIN(24, "MF_ISH_GPIO_2"), 5126e08d6bbSMika Westerberg PINCTRL_PIN(25, "MF_ISH_GPIO_6"), 5136e08d6bbSMika Westerberg PINCTRL_PIN(26, "MF_ISH_I2C1_SDA"), 5146e08d6bbSMika Westerberg }; 5156e08d6bbSMika Westerberg 5166e08d6bbSMika Westerberg static const struct chv_gpio_pinrange east_gpio_ranges[] = { 5176e08d6bbSMika Westerberg GPIO_PINRANGE(0, 11), 5186e08d6bbSMika Westerberg GPIO_PINRANGE(15, 26), 5196e08d6bbSMika Westerberg }; 5206e08d6bbSMika Westerberg 5216e08d6bbSMika Westerberg static const struct chv_community east_community = { 5226e08d6bbSMika Westerberg .uid = "3", 5236e08d6bbSMika Westerberg .pins = east_pins, 5246e08d6bbSMika Westerberg .npins = ARRAY_SIZE(east_pins), 5256e08d6bbSMika Westerberg .gpio_ranges = east_gpio_ranges, 5266e08d6bbSMika Westerberg .ngpio_ranges = ARRAY_SIZE(east_gpio_ranges), 5276e08d6bbSMika Westerberg .ngpios = ARRAY_SIZE(east_pins), 5286e08d6bbSMika Westerberg }; 5296e08d6bbSMika Westerberg 5306e08d6bbSMika Westerberg static const struct pinctrl_pin_desc southeast_pins[] = { 5316e08d6bbSMika Westerberg PINCTRL_PIN(0, "MF_PLT_CLK0"), 5326e08d6bbSMika Westerberg PINCTRL_PIN(1, "PWM1"), 5336e08d6bbSMika Westerberg PINCTRL_PIN(2, "MF_PLT_CLK1"), 5346e08d6bbSMika Westerberg PINCTRL_PIN(3, "MF_PLT_CLK4"), 5356e08d6bbSMika Westerberg PINCTRL_PIN(4, "MF_PLT_CLK3"), 5366e08d6bbSMika Westerberg PINCTRL_PIN(5, "PWM0"), 5376e08d6bbSMika Westerberg PINCTRL_PIN(6, "MF_PLT_CLK5"), 5386e08d6bbSMika Westerberg PINCTRL_PIN(7, "MF_PLT_CLK2"), 5396e08d6bbSMika Westerberg 5406e08d6bbSMika Westerberg PINCTRL_PIN(15, "SDMMC2_D3_CD_B"), 5416e08d6bbSMika Westerberg PINCTRL_PIN(16, "SDMMC1_CLK"), 5426e08d6bbSMika Westerberg PINCTRL_PIN(17, "SDMMC1_D0"), 5436e08d6bbSMika Westerberg PINCTRL_PIN(18, "SDMMC2_D1"), 5446e08d6bbSMika Westerberg PINCTRL_PIN(19, "SDMMC2_CLK"), 5456e08d6bbSMika Westerberg PINCTRL_PIN(20, "SDMMC1_D2"), 5466e08d6bbSMika Westerberg PINCTRL_PIN(21, "SDMMC2_D2"), 5476e08d6bbSMika Westerberg PINCTRL_PIN(22, "SDMMC2_CMD"), 5486e08d6bbSMika Westerberg PINCTRL_PIN(23, "SDMMC1_CMD"), 5496e08d6bbSMika Westerberg PINCTRL_PIN(24, "SDMMC1_D1"), 5506e08d6bbSMika Westerberg PINCTRL_PIN(25, "SDMMC2_D0"), 5516e08d6bbSMika Westerberg PINCTRL_PIN(26, "SDMMC1_D3_CD_B"), 5526e08d6bbSMika Westerberg 5536e08d6bbSMika Westerberg PINCTRL_PIN(30, "SDMMC3_D1"), 5546e08d6bbSMika Westerberg PINCTRL_PIN(31, "SDMMC3_CLK"), 5556e08d6bbSMika Westerberg PINCTRL_PIN(32, "SDMMC3_D3"), 5566e08d6bbSMika Westerberg PINCTRL_PIN(33, "SDMMC3_D2"), 5576e08d6bbSMika Westerberg PINCTRL_PIN(34, "SDMMC3_CMD"), 5586e08d6bbSMika Westerberg PINCTRL_PIN(35, "SDMMC3_D0"), 5596e08d6bbSMika Westerberg 5606e08d6bbSMika Westerberg PINCTRL_PIN(45, "MF_LPC_AD2"), 5616e08d6bbSMika Westerberg PINCTRL_PIN(46, "LPC_CLKRUNB"), 5626e08d6bbSMika Westerberg PINCTRL_PIN(47, "MF_LPC_AD0"), 5636e08d6bbSMika Westerberg PINCTRL_PIN(48, "LPC_FRAMEB"), 5646e08d6bbSMika Westerberg PINCTRL_PIN(49, "MF_LPC_CLKOUT1"), 5656e08d6bbSMika Westerberg PINCTRL_PIN(50, "MF_LPC_AD3"), 5666e08d6bbSMika Westerberg PINCTRL_PIN(51, "MF_LPC_CLKOUT0"), 5676e08d6bbSMika Westerberg PINCTRL_PIN(52, "MF_LPC_AD1"), 5686e08d6bbSMika Westerberg 5696e08d6bbSMika Westerberg PINCTRL_PIN(60, "SPI1_MISO"), 5706e08d6bbSMika Westerberg PINCTRL_PIN(61, "SPI1_CSO_B"), 5716e08d6bbSMika Westerberg PINCTRL_PIN(62, "SPI1_CLK"), 5726e08d6bbSMika Westerberg PINCTRL_PIN(63, "MMC1_D6"), 5736e08d6bbSMika Westerberg PINCTRL_PIN(64, "SPI1_MOSI"), 5746e08d6bbSMika Westerberg PINCTRL_PIN(65, "MMC1_D5"), 5756e08d6bbSMika Westerberg PINCTRL_PIN(66, "SPI1_CS1_B"), 5766e08d6bbSMika Westerberg PINCTRL_PIN(67, "MMC1_D4_SD_WE"), 5776e08d6bbSMika Westerberg PINCTRL_PIN(68, "MMC1_D7"), 5786e08d6bbSMika Westerberg PINCTRL_PIN(69, "MMC1_RCLK"), 5796e08d6bbSMika Westerberg 5806e08d6bbSMika Westerberg PINCTRL_PIN(75, "USB_OC1_B"), 5816e08d6bbSMika Westerberg PINCTRL_PIN(76, "PMU_RESETBUTTON_B"), 5826e08d6bbSMika Westerberg PINCTRL_PIN(77, "GPIO_ALERT"), 5836e08d6bbSMika Westerberg PINCTRL_PIN(78, "SDMMC3_PWR_EN_B"), 5846e08d6bbSMika Westerberg PINCTRL_PIN(79, "ILB_SERIRQ"), 5856e08d6bbSMika Westerberg PINCTRL_PIN(80, "USB_OC0_B"), 5866e08d6bbSMika Westerberg PINCTRL_PIN(81, "SDMMC3_CD_B"), 5876e08d6bbSMika Westerberg PINCTRL_PIN(82, "SPKR"), 5886e08d6bbSMika Westerberg PINCTRL_PIN(83, "SUSPWRDNACK"), 5896e08d6bbSMika Westerberg PINCTRL_PIN(84, "SPARE_PIN"), 5906e08d6bbSMika Westerberg PINCTRL_PIN(85, "SDMMC3_1P8_EN"), 5916e08d6bbSMika Westerberg }; 5926e08d6bbSMika Westerberg 5936e08d6bbSMika Westerberg static const unsigned southeast_pwm0_pins[] = { 5 }; 5946e08d6bbSMika Westerberg static const unsigned southeast_pwm1_pins[] = { 1 }; 5956e08d6bbSMika Westerberg static const unsigned southeast_sdmmc1_pins[] = { 5966e08d6bbSMika Westerberg 16, 17, 20, 23, 24, 26, 63, 65, 67, 68, 69, 5976e08d6bbSMika Westerberg }; 5986e08d6bbSMika Westerberg static const unsigned southeast_sdmmc2_pins[] = { 15, 18, 19, 21, 22, 25 }; 5996e08d6bbSMika Westerberg static const unsigned southeast_sdmmc3_pins[] = { 6006e08d6bbSMika Westerberg 30, 31, 32, 33, 34, 35, 78, 81, 85, 6016e08d6bbSMika Westerberg }; 6026e08d6bbSMika Westerberg static const unsigned southeast_spi1_pins[] = { 60, 61, 62, 64, 66 }; 6036e08d6bbSMika Westerberg static const unsigned southeast_spi2_pins[] = { 2, 3, 4, 6, 7 }; 6046e08d6bbSMika Westerberg 6056e08d6bbSMika Westerberg static const struct chv_pingroup southeast_groups[] = { 6066e08d6bbSMika Westerberg PIN_GROUP("pwm0_grp", southeast_pwm0_pins, 1, false), 6076e08d6bbSMika Westerberg PIN_GROUP("pwm1_grp", southeast_pwm1_pins, 1, false), 6086e08d6bbSMika Westerberg PIN_GROUP("sdmmc1_grp", southeast_sdmmc1_pins, 1, false), 6096e08d6bbSMika Westerberg PIN_GROUP("sdmmc2_grp", southeast_sdmmc2_pins, 1, false), 6106e08d6bbSMika Westerberg PIN_GROUP("sdmmc3_grp", southeast_sdmmc3_pins, 1, false), 6116e08d6bbSMika Westerberg PIN_GROUP("spi1_grp", southeast_spi1_pins, 1, false), 6126e08d6bbSMika Westerberg PIN_GROUP("spi2_grp", southeast_spi2_pins, 4, false), 6136e08d6bbSMika Westerberg }; 6146e08d6bbSMika Westerberg 6156e08d6bbSMika Westerberg static const char * const southeast_pwm0_groups[] = { "pwm0_grp" }; 6166e08d6bbSMika Westerberg static const char * const southeast_pwm1_groups[] = { "pwm1_grp" }; 6176e08d6bbSMika Westerberg static const char * const southeast_sdmmc1_groups[] = { "sdmmc1_grp" }; 6186e08d6bbSMika Westerberg static const char * const southeast_sdmmc2_groups[] = { "sdmmc2_grp" }; 6196e08d6bbSMika Westerberg static const char * const southeast_sdmmc3_groups[] = { "sdmmc3_grp" }; 6206e08d6bbSMika Westerberg static const char * const southeast_spi1_groups[] = { "spi1_grp" }; 6216e08d6bbSMika Westerberg static const char * const southeast_spi2_groups[] = { "spi2_grp" }; 6226e08d6bbSMika Westerberg 6236e08d6bbSMika Westerberg static const struct chv_function southeast_functions[] = { 6246e08d6bbSMika Westerberg FUNCTION("pwm0", southeast_pwm0_groups), 6256e08d6bbSMika Westerberg FUNCTION("pwm1", southeast_pwm1_groups), 6266e08d6bbSMika Westerberg FUNCTION("sdmmc1", southeast_sdmmc1_groups), 6276e08d6bbSMika Westerberg FUNCTION("sdmmc2", southeast_sdmmc2_groups), 6286e08d6bbSMika Westerberg FUNCTION("sdmmc3", southeast_sdmmc3_groups), 6296e08d6bbSMika Westerberg FUNCTION("spi1", southeast_spi1_groups), 6306e08d6bbSMika Westerberg FUNCTION("spi2", southeast_spi2_groups), 6316e08d6bbSMika Westerberg }; 6326e08d6bbSMika Westerberg 6336e08d6bbSMika Westerberg static const struct chv_gpio_pinrange southeast_gpio_ranges[] = { 6346e08d6bbSMika Westerberg GPIO_PINRANGE(0, 7), 6356e08d6bbSMika Westerberg GPIO_PINRANGE(15, 26), 6366e08d6bbSMika Westerberg GPIO_PINRANGE(30, 35), 6376e08d6bbSMika Westerberg GPIO_PINRANGE(45, 52), 6386e08d6bbSMika Westerberg GPIO_PINRANGE(60, 69), 6396e08d6bbSMika Westerberg GPIO_PINRANGE(75, 85), 6406e08d6bbSMika Westerberg }; 6416e08d6bbSMika Westerberg 6426e08d6bbSMika Westerberg static const struct chv_community southeast_community = { 6436e08d6bbSMika Westerberg .uid = "4", 6446e08d6bbSMika Westerberg .pins = southeast_pins, 6456e08d6bbSMika Westerberg .npins = ARRAY_SIZE(southeast_pins), 6466e08d6bbSMika Westerberg .groups = southeast_groups, 6476e08d6bbSMika Westerberg .ngroups = ARRAY_SIZE(southeast_groups), 6486e08d6bbSMika Westerberg .functions = southeast_functions, 6496e08d6bbSMika Westerberg .nfunctions = ARRAY_SIZE(southeast_functions), 6506e08d6bbSMika Westerberg .gpio_ranges = southeast_gpio_ranges, 6516e08d6bbSMika Westerberg .ngpio_ranges = ARRAY_SIZE(southeast_gpio_ranges), 6526e08d6bbSMika Westerberg .ngpios = ARRAY_SIZE(southeast_pins), 6536e08d6bbSMika Westerberg }; 6546e08d6bbSMika Westerberg 6556e08d6bbSMika Westerberg static const struct chv_community *chv_communities[] = { 6566e08d6bbSMika Westerberg &southwest_community, 6576e08d6bbSMika Westerberg &north_community, 6586e08d6bbSMika Westerberg &east_community, 6596e08d6bbSMika Westerberg &southeast_community, 6606e08d6bbSMika Westerberg }; 6616e08d6bbSMika Westerberg 6626e08d6bbSMika Westerberg static void __iomem *chv_padreg(struct chv_pinctrl *pctrl, unsigned offset, 6636e08d6bbSMika Westerberg unsigned reg) 6646e08d6bbSMika Westerberg { 6656e08d6bbSMika Westerberg unsigned family_no = offset / MAX_FAMILY_PAD_GPIO_NO; 6666e08d6bbSMika Westerberg unsigned pad_no = offset % MAX_FAMILY_PAD_GPIO_NO; 6676e08d6bbSMika Westerberg 6686e08d6bbSMika Westerberg offset = FAMILY_PAD_REGS_OFF + FAMILY_PAD_REGS_SIZE * family_no + 6696e08d6bbSMika Westerberg GPIO_REGS_SIZE * pad_no; 6706e08d6bbSMika Westerberg 6716e08d6bbSMika Westerberg return pctrl->regs + offset + reg; 6726e08d6bbSMika Westerberg } 6736e08d6bbSMika Westerberg 6746e08d6bbSMika Westerberg static void chv_writel(u32 value, void __iomem *reg) 6756e08d6bbSMika Westerberg { 6766e08d6bbSMika Westerberg writel(value, reg); 6776e08d6bbSMika Westerberg /* simple readback to confirm the bus transferring done */ 6786e08d6bbSMika Westerberg readl(reg); 6796e08d6bbSMika Westerberg } 6806e08d6bbSMika Westerberg 6816e08d6bbSMika Westerberg /* When Pad Cfg is locked, driver can only change GPIOTXState or GPIORXState */ 6826e08d6bbSMika Westerberg static bool chv_pad_locked(struct chv_pinctrl *pctrl, unsigned offset) 6836e08d6bbSMika Westerberg { 6846e08d6bbSMika Westerberg void __iomem *reg; 6856e08d6bbSMika Westerberg 6866e08d6bbSMika Westerberg reg = chv_padreg(pctrl, offset, CHV_PADCTRL1); 6876e08d6bbSMika Westerberg return readl(reg) & CHV_PADCTRL1_CFGLOCK; 6886e08d6bbSMika Westerberg } 6896e08d6bbSMika Westerberg 6906e08d6bbSMika Westerberg static int chv_get_groups_count(struct pinctrl_dev *pctldev) 6916e08d6bbSMika Westerberg { 6926e08d6bbSMika Westerberg struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 6936e08d6bbSMika Westerberg 6946e08d6bbSMika Westerberg return pctrl->community->ngroups; 6956e08d6bbSMika Westerberg } 6966e08d6bbSMika Westerberg 6976e08d6bbSMika Westerberg static const char *chv_get_group_name(struct pinctrl_dev *pctldev, 6986e08d6bbSMika Westerberg unsigned group) 6996e08d6bbSMika Westerberg { 7006e08d6bbSMika Westerberg struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 7016e08d6bbSMika Westerberg 7026e08d6bbSMika Westerberg return pctrl->community->groups[group].name; 7036e08d6bbSMika Westerberg } 7046e08d6bbSMika Westerberg 7056e08d6bbSMika Westerberg static int chv_get_group_pins(struct pinctrl_dev *pctldev, unsigned group, 7066e08d6bbSMika Westerberg const unsigned **pins, unsigned *npins) 7076e08d6bbSMika Westerberg { 7086e08d6bbSMika Westerberg struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 7096e08d6bbSMika Westerberg 7106e08d6bbSMika Westerberg *pins = pctrl->community->groups[group].pins; 7116e08d6bbSMika Westerberg *npins = pctrl->community->groups[group].npins; 7126e08d6bbSMika Westerberg return 0; 7136e08d6bbSMika Westerberg } 7146e08d6bbSMika Westerberg 7156e08d6bbSMika Westerberg static void chv_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s, 7166e08d6bbSMika Westerberg unsigned offset) 7176e08d6bbSMika Westerberg { 7186e08d6bbSMika Westerberg struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 7196e08d6bbSMika Westerberg unsigned long flags; 7206e08d6bbSMika Westerberg u32 ctrl0, ctrl1; 7216e08d6bbSMika Westerberg bool locked; 7226e08d6bbSMika Westerberg 723109fdf15SMika Westerberg raw_spin_lock_irqsave(&pctrl->lock, flags); 7246e08d6bbSMika Westerberg 7256e08d6bbSMika Westerberg ctrl0 = readl(chv_padreg(pctrl, offset, CHV_PADCTRL0)); 7266e08d6bbSMika Westerberg ctrl1 = readl(chv_padreg(pctrl, offset, CHV_PADCTRL1)); 7276e08d6bbSMika Westerberg locked = chv_pad_locked(pctrl, offset); 7286e08d6bbSMika Westerberg 729109fdf15SMika Westerberg raw_spin_unlock_irqrestore(&pctrl->lock, flags); 7306e08d6bbSMika Westerberg 7316e08d6bbSMika Westerberg if (ctrl0 & CHV_PADCTRL0_GPIOEN) { 7326e08d6bbSMika Westerberg seq_puts(s, "GPIO "); 7336e08d6bbSMika Westerberg } else { 7346e08d6bbSMika Westerberg u32 mode; 7356e08d6bbSMika Westerberg 7366e08d6bbSMika Westerberg mode = ctrl0 & CHV_PADCTRL0_PMODE_MASK; 7376e08d6bbSMika Westerberg mode >>= CHV_PADCTRL0_PMODE_SHIFT; 7386e08d6bbSMika Westerberg 7396e08d6bbSMika Westerberg seq_printf(s, "mode %d ", mode); 7406e08d6bbSMika Westerberg } 7416e08d6bbSMika Westerberg 7426e08d6bbSMika Westerberg seq_printf(s, "ctrl0 0x%08x ctrl1 0x%08x", ctrl0, ctrl1); 7436e08d6bbSMika Westerberg 7446e08d6bbSMika Westerberg if (locked) 7456e08d6bbSMika Westerberg seq_puts(s, " [LOCKED]"); 7466e08d6bbSMika Westerberg } 7476e08d6bbSMika Westerberg 7486e08d6bbSMika Westerberg static const struct pinctrl_ops chv_pinctrl_ops = { 7496e08d6bbSMika Westerberg .get_groups_count = chv_get_groups_count, 7506e08d6bbSMika Westerberg .get_group_name = chv_get_group_name, 7516e08d6bbSMika Westerberg .get_group_pins = chv_get_group_pins, 7526e08d6bbSMika Westerberg .pin_dbg_show = chv_pin_dbg_show, 7536e08d6bbSMika Westerberg }; 7546e08d6bbSMika Westerberg 7556e08d6bbSMika Westerberg static int chv_get_functions_count(struct pinctrl_dev *pctldev) 7566e08d6bbSMika Westerberg { 7576e08d6bbSMika Westerberg struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 7586e08d6bbSMika Westerberg 7596e08d6bbSMika Westerberg return pctrl->community->nfunctions; 7606e08d6bbSMika Westerberg } 7616e08d6bbSMika Westerberg 7626e08d6bbSMika Westerberg static const char *chv_get_function_name(struct pinctrl_dev *pctldev, 7636e08d6bbSMika Westerberg unsigned function) 7646e08d6bbSMika Westerberg { 7656e08d6bbSMika Westerberg struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 7666e08d6bbSMika Westerberg 7676e08d6bbSMika Westerberg return pctrl->community->functions[function].name; 7686e08d6bbSMika Westerberg } 7696e08d6bbSMika Westerberg 7706e08d6bbSMika Westerberg static int chv_get_function_groups(struct pinctrl_dev *pctldev, 7716e08d6bbSMika Westerberg unsigned function, 7726e08d6bbSMika Westerberg const char * const **groups, 7736e08d6bbSMika Westerberg unsigned * const ngroups) 7746e08d6bbSMika Westerberg { 7756e08d6bbSMika Westerberg struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 7766e08d6bbSMika Westerberg 7776e08d6bbSMika Westerberg *groups = pctrl->community->functions[function].groups; 7786e08d6bbSMika Westerberg *ngroups = pctrl->community->functions[function].ngroups; 7796e08d6bbSMika Westerberg return 0; 7806e08d6bbSMika Westerberg } 7816e08d6bbSMika Westerberg 7826e08d6bbSMika Westerberg static int chv_pinmux_set_mux(struct pinctrl_dev *pctldev, unsigned function, 7836e08d6bbSMika Westerberg unsigned group) 7846e08d6bbSMika Westerberg { 7856e08d6bbSMika Westerberg struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 7866e08d6bbSMika Westerberg const struct chv_pingroup *grp; 7876e08d6bbSMika Westerberg unsigned long flags; 7886e08d6bbSMika Westerberg int i; 7896e08d6bbSMika Westerberg 7906e08d6bbSMika Westerberg grp = &pctrl->community->groups[group]; 7916e08d6bbSMika Westerberg 792109fdf15SMika Westerberg raw_spin_lock_irqsave(&pctrl->lock, flags); 7936e08d6bbSMika Westerberg 7946e08d6bbSMika Westerberg /* Check first that the pad is not locked */ 7956e08d6bbSMika Westerberg for (i = 0; i < grp->npins; i++) { 7966e08d6bbSMika Westerberg if (chv_pad_locked(pctrl, grp->pins[i])) { 7976e08d6bbSMika Westerberg dev_warn(pctrl->dev, "unable to set mode for locked pin %u\n", 7986e08d6bbSMika Westerberg grp->pins[i]); 799109fdf15SMika Westerberg raw_spin_unlock_irqrestore(&pctrl->lock, flags); 8006e08d6bbSMika Westerberg return -EBUSY; 8016e08d6bbSMika Westerberg } 8026e08d6bbSMika Westerberg } 8036e08d6bbSMika Westerberg 8046e08d6bbSMika Westerberg for (i = 0; i < grp->npins; i++) { 8056e08d6bbSMika Westerberg const struct chv_alternate_function *altfunc = &grp->altfunc; 8066e08d6bbSMika Westerberg int pin = grp->pins[i]; 8076e08d6bbSMika Westerberg void __iomem *reg; 8086e08d6bbSMika Westerberg u32 value; 8096e08d6bbSMika Westerberg 8106e08d6bbSMika Westerberg /* Check if there is pin-specific config */ 8116e08d6bbSMika Westerberg if (grp->overrides) { 8126e08d6bbSMika Westerberg int j; 8136e08d6bbSMika Westerberg 8146e08d6bbSMika Westerberg for (j = 0; j < grp->noverrides; j++) { 8156e08d6bbSMika Westerberg if (grp->overrides[j].pin == pin) { 8166e08d6bbSMika Westerberg altfunc = &grp->overrides[j]; 8176e08d6bbSMika Westerberg break; 8186e08d6bbSMika Westerberg } 8196e08d6bbSMika Westerberg } 8206e08d6bbSMika Westerberg } 8216e08d6bbSMika Westerberg 8226e08d6bbSMika Westerberg reg = chv_padreg(pctrl, pin, CHV_PADCTRL0); 8236e08d6bbSMika Westerberg value = readl(reg); 8246e08d6bbSMika Westerberg /* Disable GPIO mode */ 8256e08d6bbSMika Westerberg value &= ~CHV_PADCTRL0_GPIOEN; 8266e08d6bbSMika Westerberg /* Set to desired mode */ 8276e08d6bbSMika Westerberg value &= ~CHV_PADCTRL0_PMODE_MASK; 8286e08d6bbSMika Westerberg value |= altfunc->mode << CHV_PADCTRL0_PMODE_SHIFT; 8296e08d6bbSMika Westerberg chv_writel(value, reg); 8306e08d6bbSMika Westerberg 8316e08d6bbSMika Westerberg /* Update for invert_oe */ 8326e08d6bbSMika Westerberg reg = chv_padreg(pctrl, pin, CHV_PADCTRL1); 8336e08d6bbSMika Westerberg value = readl(reg) & ~CHV_PADCTRL1_INVRXTX_MASK; 8346e08d6bbSMika Westerberg if (altfunc->invert_oe) 8356e08d6bbSMika Westerberg value |= CHV_PADCTRL1_INVRXTX_TXENABLE; 8366e08d6bbSMika Westerberg chv_writel(value, reg); 8376e08d6bbSMika Westerberg 8386e08d6bbSMika Westerberg dev_dbg(pctrl->dev, "configured pin %u mode %u OE %sinverted\n", 8396e08d6bbSMika Westerberg pin, altfunc->mode, altfunc->invert_oe ? "" : "not "); 8406e08d6bbSMika Westerberg } 8416e08d6bbSMika Westerberg 842109fdf15SMika Westerberg raw_spin_unlock_irqrestore(&pctrl->lock, flags); 8436e08d6bbSMika Westerberg 8446e08d6bbSMika Westerberg return 0; 8456e08d6bbSMika Westerberg } 8466e08d6bbSMika Westerberg 8476e08d6bbSMika Westerberg static int chv_gpio_request_enable(struct pinctrl_dev *pctldev, 8486e08d6bbSMika Westerberg struct pinctrl_gpio_range *range, 8496e08d6bbSMika Westerberg unsigned offset) 8506e08d6bbSMika Westerberg { 8516e08d6bbSMika Westerberg struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 8526e08d6bbSMika Westerberg unsigned long flags; 8536e08d6bbSMika Westerberg void __iomem *reg; 8546e08d6bbSMika Westerberg u32 value; 8556e08d6bbSMika Westerberg 856109fdf15SMika Westerberg raw_spin_lock_irqsave(&pctrl->lock, flags); 8576e08d6bbSMika Westerberg 8586e08d6bbSMika Westerberg if (chv_pad_locked(pctrl, offset)) { 8596e08d6bbSMika Westerberg value = readl(chv_padreg(pctrl, offset, CHV_PADCTRL0)); 8606e08d6bbSMika Westerberg if (!(value & CHV_PADCTRL0_GPIOEN)) { 8616e08d6bbSMika Westerberg /* Locked so cannot enable */ 862109fdf15SMika Westerberg raw_spin_unlock_irqrestore(&pctrl->lock, flags); 8636e08d6bbSMika Westerberg return -EBUSY; 8646e08d6bbSMika Westerberg } 8656e08d6bbSMika Westerberg } else { 8666e08d6bbSMika Westerberg int i; 8676e08d6bbSMika Westerberg 8686e08d6bbSMika Westerberg /* Reset the interrupt mapping */ 8696e08d6bbSMika Westerberg for (i = 0; i < ARRAY_SIZE(pctrl->intr_lines); i++) { 8706e08d6bbSMika Westerberg if (pctrl->intr_lines[i] == offset) { 8716e08d6bbSMika Westerberg pctrl->intr_lines[i] = 0; 8726e08d6bbSMika Westerberg break; 8736e08d6bbSMika Westerberg } 8746e08d6bbSMika Westerberg } 8756e08d6bbSMika Westerberg 8766e08d6bbSMika Westerberg /* Disable interrupt generation */ 8776e08d6bbSMika Westerberg reg = chv_padreg(pctrl, offset, CHV_PADCTRL1); 8786e08d6bbSMika Westerberg value = readl(reg); 8796e08d6bbSMika Westerberg value &= ~CHV_PADCTRL1_INTWAKECFG_MASK; 8806e08d6bbSMika Westerberg value &= ~CHV_PADCTRL1_INVRXTX_MASK; 8816e08d6bbSMika Westerberg chv_writel(value, reg); 8826e08d6bbSMika Westerberg 8836e08d6bbSMika Westerberg reg = chv_padreg(pctrl, offset, CHV_PADCTRL0); 8842479c730SMika Westerberg value = readl(reg); 8852479c730SMika Westerberg 8862479c730SMika Westerberg /* 8872479c730SMika Westerberg * If the pin is in HiZ mode (both TX and RX buffers are 8882479c730SMika Westerberg * disabled) we turn it to be input now. 8892479c730SMika Westerberg */ 8902479c730SMika Westerberg if ((value & CHV_PADCTRL0_GPIOCFG_MASK) == 8912479c730SMika Westerberg (CHV_PADCTRL0_GPIOCFG_HIZ << CHV_PADCTRL0_GPIOCFG_SHIFT)) { 8922479c730SMika Westerberg value &= ~CHV_PADCTRL0_GPIOCFG_MASK; 8932479c730SMika Westerberg value |= CHV_PADCTRL0_GPIOCFG_GPI << 8942479c730SMika Westerberg CHV_PADCTRL0_GPIOCFG_SHIFT; 8952479c730SMika Westerberg } 8962479c730SMika Westerberg 8972479c730SMika Westerberg /* Switch to a GPIO mode */ 8982479c730SMika Westerberg value |= CHV_PADCTRL0_GPIOEN; 8996e08d6bbSMika Westerberg chv_writel(value, reg); 9006e08d6bbSMika Westerberg } 9016e08d6bbSMika Westerberg 902109fdf15SMika Westerberg raw_spin_unlock_irqrestore(&pctrl->lock, flags); 9036e08d6bbSMika Westerberg 9046e08d6bbSMika Westerberg return 0; 9056e08d6bbSMika Westerberg } 9066e08d6bbSMika Westerberg 9076e08d6bbSMika Westerberg static void chv_gpio_disable_free(struct pinctrl_dev *pctldev, 9086e08d6bbSMika Westerberg struct pinctrl_gpio_range *range, 9096e08d6bbSMika Westerberg unsigned offset) 9106e08d6bbSMika Westerberg { 9116e08d6bbSMika Westerberg struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 9126e08d6bbSMika Westerberg unsigned long flags; 9136e08d6bbSMika Westerberg void __iomem *reg; 9146e08d6bbSMika Westerberg u32 value; 9156e08d6bbSMika Westerberg 916109fdf15SMika Westerberg raw_spin_lock_irqsave(&pctrl->lock, flags); 9176e08d6bbSMika Westerberg 9186e08d6bbSMika Westerberg reg = chv_padreg(pctrl, offset, CHV_PADCTRL0); 9196e08d6bbSMika Westerberg value = readl(reg) & ~CHV_PADCTRL0_GPIOEN; 9206e08d6bbSMika Westerberg chv_writel(value, reg); 9216e08d6bbSMika Westerberg 922109fdf15SMika Westerberg raw_spin_unlock_irqrestore(&pctrl->lock, flags); 9236e08d6bbSMika Westerberg } 9246e08d6bbSMika Westerberg 9256e08d6bbSMika Westerberg static int chv_gpio_set_direction(struct pinctrl_dev *pctldev, 9266e08d6bbSMika Westerberg struct pinctrl_gpio_range *range, 9276e08d6bbSMika Westerberg unsigned offset, bool input) 9286e08d6bbSMika Westerberg { 9296e08d6bbSMika Westerberg struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 9306e08d6bbSMika Westerberg void __iomem *reg = chv_padreg(pctrl, offset, CHV_PADCTRL0); 9316e08d6bbSMika Westerberg unsigned long flags; 9326e08d6bbSMika Westerberg u32 ctrl0; 9336e08d6bbSMika Westerberg 934109fdf15SMika Westerberg raw_spin_lock_irqsave(&pctrl->lock, flags); 9356e08d6bbSMika Westerberg 9366e08d6bbSMika Westerberg ctrl0 = readl(reg) & ~CHV_PADCTRL0_GPIOCFG_MASK; 9376e08d6bbSMika Westerberg if (input) 9386e08d6bbSMika Westerberg ctrl0 |= CHV_PADCTRL0_GPIOCFG_GPI << CHV_PADCTRL0_GPIOCFG_SHIFT; 9396e08d6bbSMika Westerberg else 9406e08d6bbSMika Westerberg ctrl0 |= CHV_PADCTRL0_GPIOCFG_GPO << CHV_PADCTRL0_GPIOCFG_SHIFT; 9416e08d6bbSMika Westerberg chv_writel(ctrl0, reg); 9426e08d6bbSMika Westerberg 943109fdf15SMika Westerberg raw_spin_unlock_irqrestore(&pctrl->lock, flags); 9446e08d6bbSMika Westerberg 9456e08d6bbSMika Westerberg return 0; 9466e08d6bbSMika Westerberg } 9476e08d6bbSMika Westerberg 9486e08d6bbSMika Westerberg static const struct pinmux_ops chv_pinmux_ops = { 9496e08d6bbSMika Westerberg .get_functions_count = chv_get_functions_count, 9506e08d6bbSMika Westerberg .get_function_name = chv_get_function_name, 9516e08d6bbSMika Westerberg .get_function_groups = chv_get_function_groups, 9526e08d6bbSMika Westerberg .set_mux = chv_pinmux_set_mux, 9536e08d6bbSMika Westerberg .gpio_request_enable = chv_gpio_request_enable, 9546e08d6bbSMika Westerberg .gpio_disable_free = chv_gpio_disable_free, 9556e08d6bbSMika Westerberg .gpio_set_direction = chv_gpio_set_direction, 9566e08d6bbSMika Westerberg }; 9576e08d6bbSMika Westerberg 9586e08d6bbSMika Westerberg static int chv_config_get(struct pinctrl_dev *pctldev, unsigned pin, 9596e08d6bbSMika Westerberg unsigned long *config) 9606e08d6bbSMika Westerberg { 9616e08d6bbSMika Westerberg struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 9626e08d6bbSMika Westerberg enum pin_config_param param = pinconf_to_config_param(*config); 9636e08d6bbSMika Westerberg unsigned long flags; 9646e08d6bbSMika Westerberg u32 ctrl0, ctrl1; 9656e08d6bbSMika Westerberg u16 arg = 0; 9666e08d6bbSMika Westerberg u32 term; 9676e08d6bbSMika Westerberg 968109fdf15SMika Westerberg raw_spin_lock_irqsave(&pctrl->lock, flags); 9696e08d6bbSMika Westerberg ctrl0 = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0)); 9706e08d6bbSMika Westerberg ctrl1 = readl(chv_padreg(pctrl, pin, CHV_PADCTRL1)); 971109fdf15SMika Westerberg raw_spin_unlock_irqrestore(&pctrl->lock, flags); 9726e08d6bbSMika Westerberg 9736e08d6bbSMika Westerberg term = (ctrl0 & CHV_PADCTRL0_TERM_MASK) >> CHV_PADCTRL0_TERM_SHIFT; 9746e08d6bbSMika Westerberg 9756e08d6bbSMika Westerberg switch (param) { 9766e08d6bbSMika Westerberg case PIN_CONFIG_BIAS_DISABLE: 9776e08d6bbSMika Westerberg if (term) 9786e08d6bbSMika Westerberg return -EINVAL; 9796e08d6bbSMika Westerberg break; 9806e08d6bbSMika Westerberg 9816e08d6bbSMika Westerberg case PIN_CONFIG_BIAS_PULL_UP: 9826e08d6bbSMika Westerberg if (!(ctrl0 & CHV_PADCTRL0_TERM_UP)) 9836e08d6bbSMika Westerberg return -EINVAL; 9846e08d6bbSMika Westerberg 9856e08d6bbSMika Westerberg switch (term) { 9866e08d6bbSMika Westerberg case CHV_PADCTRL0_TERM_20K: 9876e08d6bbSMika Westerberg arg = 20000; 9886e08d6bbSMika Westerberg break; 9896e08d6bbSMika Westerberg case CHV_PADCTRL0_TERM_5K: 9906e08d6bbSMika Westerberg arg = 5000; 9916e08d6bbSMika Westerberg break; 9926e08d6bbSMika Westerberg case CHV_PADCTRL0_TERM_1K: 9936e08d6bbSMika Westerberg arg = 1000; 9946e08d6bbSMika Westerberg break; 9956e08d6bbSMika Westerberg } 9966e08d6bbSMika Westerberg 9976e08d6bbSMika Westerberg break; 9986e08d6bbSMika Westerberg 9996e08d6bbSMika Westerberg case PIN_CONFIG_BIAS_PULL_DOWN: 10006e08d6bbSMika Westerberg if (!term || (ctrl0 & CHV_PADCTRL0_TERM_UP)) 10016e08d6bbSMika Westerberg return -EINVAL; 10026e08d6bbSMika Westerberg 10036e08d6bbSMika Westerberg switch (term) { 10046e08d6bbSMika Westerberg case CHV_PADCTRL0_TERM_20K: 10056e08d6bbSMika Westerberg arg = 20000; 10066e08d6bbSMika Westerberg break; 10076e08d6bbSMika Westerberg case CHV_PADCTRL0_TERM_5K: 10086e08d6bbSMika Westerberg arg = 5000; 10096e08d6bbSMika Westerberg break; 10106e08d6bbSMika Westerberg } 10116e08d6bbSMika Westerberg 10126e08d6bbSMika Westerberg break; 10136e08d6bbSMika Westerberg 10146e08d6bbSMika Westerberg case PIN_CONFIG_DRIVE_OPEN_DRAIN: 10156e08d6bbSMika Westerberg if (!(ctrl1 & CHV_PADCTRL1_ODEN)) 10166e08d6bbSMika Westerberg return -EINVAL; 10176e08d6bbSMika Westerberg break; 10186e08d6bbSMika Westerberg 10196e08d6bbSMika Westerberg case PIN_CONFIG_BIAS_HIGH_IMPEDANCE: { 10206e08d6bbSMika Westerberg u32 cfg; 10216e08d6bbSMika Westerberg 10226e08d6bbSMika Westerberg cfg = ctrl0 & CHV_PADCTRL0_GPIOCFG_MASK; 10236e08d6bbSMika Westerberg cfg >>= CHV_PADCTRL0_GPIOCFG_SHIFT; 10246e08d6bbSMika Westerberg if (cfg != CHV_PADCTRL0_GPIOCFG_HIZ) 10256e08d6bbSMika Westerberg return -EINVAL; 10266e08d6bbSMika Westerberg 10276e08d6bbSMika Westerberg break; 10286e08d6bbSMika Westerberg } 10296e08d6bbSMika Westerberg 10306e08d6bbSMika Westerberg default: 10316e08d6bbSMika Westerberg return -ENOTSUPP; 10326e08d6bbSMika Westerberg } 10336e08d6bbSMika Westerberg 10346e08d6bbSMika Westerberg *config = pinconf_to_config_packed(param, arg); 10356e08d6bbSMika Westerberg return 0; 10366e08d6bbSMika Westerberg } 10376e08d6bbSMika Westerberg 10386e08d6bbSMika Westerberg static int chv_config_set_pull(struct chv_pinctrl *pctrl, unsigned pin, 10396e08d6bbSMika Westerberg enum pin_config_param param, u16 arg) 10406e08d6bbSMika Westerberg { 10416e08d6bbSMika Westerberg void __iomem *reg = chv_padreg(pctrl, pin, CHV_PADCTRL0); 10426e08d6bbSMika Westerberg unsigned long flags; 10436e08d6bbSMika Westerberg u32 ctrl0, pull; 10446e08d6bbSMika Westerberg 1045109fdf15SMika Westerberg raw_spin_lock_irqsave(&pctrl->lock, flags); 10466e08d6bbSMika Westerberg ctrl0 = readl(reg); 10476e08d6bbSMika Westerberg 10486e08d6bbSMika Westerberg switch (param) { 10496e08d6bbSMika Westerberg case PIN_CONFIG_BIAS_DISABLE: 10506e08d6bbSMika Westerberg ctrl0 &= ~(CHV_PADCTRL0_TERM_MASK | CHV_PADCTRL0_TERM_UP); 10516e08d6bbSMika Westerberg break; 10526e08d6bbSMika Westerberg 10536e08d6bbSMika Westerberg case PIN_CONFIG_BIAS_PULL_UP: 10546e08d6bbSMika Westerberg ctrl0 &= ~(CHV_PADCTRL0_TERM_MASK | CHV_PADCTRL0_TERM_UP); 10556e08d6bbSMika Westerberg 10566e08d6bbSMika Westerberg switch (arg) { 10576e08d6bbSMika Westerberg case 1000: 10586e08d6bbSMika Westerberg /* For 1k there is only pull up */ 10596e08d6bbSMika Westerberg pull = CHV_PADCTRL0_TERM_1K << CHV_PADCTRL0_TERM_SHIFT; 10606e08d6bbSMika Westerberg break; 10616e08d6bbSMika Westerberg case 5000: 10626e08d6bbSMika Westerberg pull = CHV_PADCTRL0_TERM_5K << CHV_PADCTRL0_TERM_SHIFT; 10636e08d6bbSMika Westerberg break; 10646e08d6bbSMika Westerberg case 20000: 10656e08d6bbSMika Westerberg pull = CHV_PADCTRL0_TERM_20K << CHV_PADCTRL0_TERM_SHIFT; 10666e08d6bbSMika Westerberg break; 10676e08d6bbSMika Westerberg default: 1068109fdf15SMika Westerberg raw_spin_unlock_irqrestore(&pctrl->lock, flags); 10696e08d6bbSMika Westerberg return -EINVAL; 10706e08d6bbSMika Westerberg } 10716e08d6bbSMika Westerberg 10726e08d6bbSMika Westerberg ctrl0 |= CHV_PADCTRL0_TERM_UP | pull; 10736e08d6bbSMika Westerberg break; 10746e08d6bbSMika Westerberg 10756e08d6bbSMika Westerberg case PIN_CONFIG_BIAS_PULL_DOWN: 10766e08d6bbSMika Westerberg ctrl0 &= ~(CHV_PADCTRL0_TERM_MASK | CHV_PADCTRL0_TERM_UP); 10776e08d6bbSMika Westerberg 10786e08d6bbSMika Westerberg switch (arg) { 10796e08d6bbSMika Westerberg case 5000: 10806e08d6bbSMika Westerberg pull = CHV_PADCTRL0_TERM_5K << CHV_PADCTRL0_TERM_SHIFT; 10816e08d6bbSMika Westerberg break; 10826e08d6bbSMika Westerberg case 20000: 10836e08d6bbSMika Westerberg pull = CHV_PADCTRL0_TERM_20K << CHV_PADCTRL0_TERM_SHIFT; 10846e08d6bbSMika Westerberg break; 10856e08d6bbSMika Westerberg default: 1086109fdf15SMika Westerberg raw_spin_unlock_irqrestore(&pctrl->lock, flags); 10876e08d6bbSMika Westerberg return -EINVAL; 10886e08d6bbSMika Westerberg } 10896e08d6bbSMika Westerberg 10906e08d6bbSMika Westerberg ctrl0 |= pull; 10916e08d6bbSMika Westerberg break; 10926e08d6bbSMika Westerberg 10936e08d6bbSMika Westerberg default: 1094109fdf15SMika Westerberg raw_spin_unlock_irqrestore(&pctrl->lock, flags); 10956e08d6bbSMika Westerberg return -EINVAL; 10966e08d6bbSMika Westerberg } 10976e08d6bbSMika Westerberg 10986e08d6bbSMika Westerberg chv_writel(ctrl0, reg); 1099109fdf15SMika Westerberg raw_spin_unlock_irqrestore(&pctrl->lock, flags); 11006e08d6bbSMika Westerberg 11016e08d6bbSMika Westerberg return 0; 11026e08d6bbSMika Westerberg } 11036e08d6bbSMika Westerberg 11046e08d6bbSMika Westerberg static int chv_config_set(struct pinctrl_dev *pctldev, unsigned pin, 11056e08d6bbSMika Westerberg unsigned long *configs, unsigned nconfigs) 11066e08d6bbSMika Westerberg { 11076e08d6bbSMika Westerberg struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 11086e08d6bbSMika Westerberg enum pin_config_param param; 11096e08d6bbSMika Westerberg int i, ret; 11106e08d6bbSMika Westerberg u16 arg; 11116e08d6bbSMika Westerberg 11126e08d6bbSMika Westerberg if (chv_pad_locked(pctrl, pin)) 11136e08d6bbSMika Westerberg return -EBUSY; 11146e08d6bbSMika Westerberg 11156e08d6bbSMika Westerberg for (i = 0; i < nconfigs; i++) { 11166e08d6bbSMika Westerberg param = pinconf_to_config_param(configs[i]); 11176e08d6bbSMika Westerberg arg = pinconf_to_config_argument(configs[i]); 11186e08d6bbSMika Westerberg 11196e08d6bbSMika Westerberg switch (param) { 11206e08d6bbSMika Westerberg case PIN_CONFIG_BIAS_DISABLE: 11216e08d6bbSMika Westerberg case PIN_CONFIG_BIAS_PULL_UP: 11226e08d6bbSMika Westerberg case PIN_CONFIG_BIAS_PULL_DOWN: 11236e08d6bbSMika Westerberg ret = chv_config_set_pull(pctrl, pin, param, arg); 11246e08d6bbSMika Westerberg if (ret) 11256e08d6bbSMika Westerberg return ret; 11266e08d6bbSMika Westerberg break; 11276e08d6bbSMika Westerberg 11286e08d6bbSMika Westerberg default: 11296e08d6bbSMika Westerberg return -ENOTSUPP; 11306e08d6bbSMika Westerberg } 11316e08d6bbSMika Westerberg 11326e08d6bbSMika Westerberg dev_dbg(pctrl->dev, "pin %d set config %d arg %u\n", pin, 11336e08d6bbSMika Westerberg param, arg); 11346e08d6bbSMika Westerberg } 11356e08d6bbSMika Westerberg 11366e08d6bbSMika Westerberg return 0; 11376e08d6bbSMika Westerberg } 11386e08d6bbSMika Westerberg 11396e08d6bbSMika Westerberg static const struct pinconf_ops chv_pinconf_ops = { 11406e08d6bbSMika Westerberg .is_generic = true, 11416e08d6bbSMika Westerberg .pin_config_set = chv_config_set, 11426e08d6bbSMika Westerberg .pin_config_get = chv_config_get, 11436e08d6bbSMika Westerberg }; 11446e08d6bbSMika Westerberg 11456e08d6bbSMika Westerberg static struct pinctrl_desc chv_pinctrl_desc = { 11466e08d6bbSMika Westerberg .pctlops = &chv_pinctrl_ops, 11476e08d6bbSMika Westerberg .pmxops = &chv_pinmux_ops, 11486e08d6bbSMika Westerberg .confops = &chv_pinconf_ops, 11496e08d6bbSMika Westerberg .owner = THIS_MODULE, 11506e08d6bbSMika Westerberg }; 11516e08d6bbSMika Westerberg 11526e08d6bbSMika Westerberg static int chv_gpio_request(struct gpio_chip *chip, unsigned offset) 11536e08d6bbSMika Westerberg { 11546e08d6bbSMika Westerberg return pinctrl_request_gpio(chip->base + offset); 11556e08d6bbSMika Westerberg } 11566e08d6bbSMika Westerberg 11576e08d6bbSMika Westerberg static void chv_gpio_free(struct gpio_chip *chip, unsigned offset) 11586e08d6bbSMika Westerberg { 11596e08d6bbSMika Westerberg pinctrl_free_gpio(chip->base + offset); 11606e08d6bbSMika Westerberg } 11616e08d6bbSMika Westerberg 11626e08d6bbSMika Westerberg static unsigned chv_gpio_offset_to_pin(struct chv_pinctrl *pctrl, 11636e08d6bbSMika Westerberg unsigned offset) 11646e08d6bbSMika Westerberg { 11656e08d6bbSMika Westerberg return pctrl->community->pins[offset].number; 11666e08d6bbSMika Westerberg } 11676e08d6bbSMika Westerberg 11686e08d6bbSMika Westerberg static int chv_gpio_get(struct gpio_chip *chip, unsigned offset) 11696e08d6bbSMika Westerberg { 11706e08d6bbSMika Westerberg struct chv_pinctrl *pctrl = gpiochip_to_pinctrl(chip); 11716e08d6bbSMika Westerberg int pin = chv_gpio_offset_to_pin(pctrl, offset); 11724585b000SMika Westerberg unsigned long flags; 11736e08d6bbSMika Westerberg u32 ctrl0, cfg; 11746e08d6bbSMika Westerberg 1175109fdf15SMika Westerberg raw_spin_lock_irqsave(&pctrl->lock, flags); 11766e08d6bbSMika Westerberg ctrl0 = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0)); 1177109fdf15SMika Westerberg raw_spin_unlock_irqrestore(&pctrl->lock, flags); 11786e08d6bbSMika Westerberg 11796e08d6bbSMika Westerberg cfg = ctrl0 & CHV_PADCTRL0_GPIOCFG_MASK; 11806e08d6bbSMika Westerberg cfg >>= CHV_PADCTRL0_GPIOCFG_SHIFT; 11816e08d6bbSMika Westerberg 11826e08d6bbSMika Westerberg if (cfg == CHV_PADCTRL0_GPIOCFG_GPO) 11836e08d6bbSMika Westerberg return !!(ctrl0 & CHV_PADCTRL0_GPIOTXSTATE); 11846e08d6bbSMika Westerberg return !!(ctrl0 & CHV_PADCTRL0_GPIORXSTATE); 11856e08d6bbSMika Westerberg } 11866e08d6bbSMika Westerberg 11876e08d6bbSMika Westerberg static void chv_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 11886e08d6bbSMika Westerberg { 11896e08d6bbSMika Westerberg struct chv_pinctrl *pctrl = gpiochip_to_pinctrl(chip); 11906e08d6bbSMika Westerberg unsigned pin = chv_gpio_offset_to_pin(pctrl, offset); 11916e08d6bbSMika Westerberg unsigned long flags; 11926e08d6bbSMika Westerberg void __iomem *reg; 11936e08d6bbSMika Westerberg u32 ctrl0; 11946e08d6bbSMika Westerberg 1195109fdf15SMika Westerberg raw_spin_lock_irqsave(&pctrl->lock, flags); 11966e08d6bbSMika Westerberg 11976e08d6bbSMika Westerberg reg = chv_padreg(pctrl, pin, CHV_PADCTRL0); 11986e08d6bbSMika Westerberg ctrl0 = readl(reg); 11996e08d6bbSMika Westerberg 12006e08d6bbSMika Westerberg if (value) 12016e08d6bbSMika Westerberg ctrl0 |= CHV_PADCTRL0_GPIOTXSTATE; 12026e08d6bbSMika Westerberg else 12036e08d6bbSMika Westerberg ctrl0 &= ~CHV_PADCTRL0_GPIOTXSTATE; 12046e08d6bbSMika Westerberg 12056e08d6bbSMika Westerberg chv_writel(ctrl0, reg); 12066e08d6bbSMika Westerberg 1207109fdf15SMika Westerberg raw_spin_unlock_irqrestore(&pctrl->lock, flags); 12086e08d6bbSMika Westerberg } 12096e08d6bbSMika Westerberg 12106e08d6bbSMika Westerberg static int chv_gpio_get_direction(struct gpio_chip *chip, unsigned offset) 12116e08d6bbSMika Westerberg { 12126e08d6bbSMika Westerberg struct chv_pinctrl *pctrl = gpiochip_to_pinctrl(chip); 12136e08d6bbSMika Westerberg unsigned pin = chv_gpio_offset_to_pin(pctrl, offset); 12146e08d6bbSMika Westerberg u32 ctrl0, direction; 12154585b000SMika Westerberg unsigned long flags; 12166e08d6bbSMika Westerberg 1217109fdf15SMika Westerberg raw_spin_lock_irqsave(&pctrl->lock, flags); 12186e08d6bbSMika Westerberg ctrl0 = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0)); 1219109fdf15SMika Westerberg raw_spin_unlock_irqrestore(&pctrl->lock, flags); 12206e08d6bbSMika Westerberg 12216e08d6bbSMika Westerberg direction = ctrl0 & CHV_PADCTRL0_GPIOCFG_MASK; 12226e08d6bbSMika Westerberg direction >>= CHV_PADCTRL0_GPIOCFG_SHIFT; 12236e08d6bbSMika Westerberg 12246e08d6bbSMika Westerberg return direction != CHV_PADCTRL0_GPIOCFG_GPO; 12256e08d6bbSMika Westerberg } 12266e08d6bbSMika Westerberg 12276e08d6bbSMika Westerberg static int chv_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 12286e08d6bbSMika Westerberg { 12296e08d6bbSMika Westerberg return pinctrl_gpio_direction_input(chip->base + offset); 12306e08d6bbSMika Westerberg } 12316e08d6bbSMika Westerberg 12326e08d6bbSMika Westerberg static int chv_gpio_direction_output(struct gpio_chip *chip, unsigned offset, 12336e08d6bbSMika Westerberg int value) 12346e08d6bbSMika Westerberg { 1235549e783fSqipeng.zha chv_gpio_set(chip, offset, value); 12366e08d6bbSMika Westerberg return pinctrl_gpio_direction_output(chip->base + offset); 12376e08d6bbSMika Westerberg } 12386e08d6bbSMika Westerberg 12396e08d6bbSMika Westerberg static const struct gpio_chip chv_gpio_chip = { 12406e08d6bbSMika Westerberg .owner = THIS_MODULE, 12416e08d6bbSMika Westerberg .request = chv_gpio_request, 12426e08d6bbSMika Westerberg .free = chv_gpio_free, 12436e08d6bbSMika Westerberg .get_direction = chv_gpio_get_direction, 12446e08d6bbSMika Westerberg .direction_input = chv_gpio_direction_input, 12456e08d6bbSMika Westerberg .direction_output = chv_gpio_direction_output, 12466e08d6bbSMika Westerberg .get = chv_gpio_get, 12476e08d6bbSMika Westerberg .set = chv_gpio_set, 12486e08d6bbSMika Westerberg }; 12496e08d6bbSMika Westerberg 12506e08d6bbSMika Westerberg static void chv_gpio_irq_ack(struct irq_data *d) 12516e08d6bbSMika Westerberg { 12526e08d6bbSMika Westerberg struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 12536e08d6bbSMika Westerberg struct chv_pinctrl *pctrl = gpiochip_to_pinctrl(gc); 12546e08d6bbSMika Westerberg int pin = chv_gpio_offset_to_pin(pctrl, irqd_to_hwirq(d)); 12556e08d6bbSMika Westerberg u32 intr_line; 12566e08d6bbSMika Westerberg 1257109fdf15SMika Westerberg raw_spin_lock(&pctrl->lock); 12586e08d6bbSMika Westerberg 12596e08d6bbSMika Westerberg intr_line = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0)); 12606e08d6bbSMika Westerberg intr_line &= CHV_PADCTRL0_INTSEL_MASK; 12616e08d6bbSMika Westerberg intr_line >>= CHV_PADCTRL0_INTSEL_SHIFT; 12626e08d6bbSMika Westerberg chv_writel(BIT(intr_line), pctrl->regs + CHV_INTSTAT); 12636e08d6bbSMika Westerberg 1264109fdf15SMika Westerberg raw_spin_unlock(&pctrl->lock); 12656e08d6bbSMika Westerberg } 12666e08d6bbSMika Westerberg 12676e08d6bbSMika Westerberg static void chv_gpio_irq_mask_unmask(struct irq_data *d, bool mask) 12686e08d6bbSMika Westerberg { 12696e08d6bbSMika Westerberg struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 12706e08d6bbSMika Westerberg struct chv_pinctrl *pctrl = gpiochip_to_pinctrl(gc); 12716e08d6bbSMika Westerberg int pin = chv_gpio_offset_to_pin(pctrl, irqd_to_hwirq(d)); 12726e08d6bbSMika Westerberg u32 value, intr_line; 12736e08d6bbSMika Westerberg unsigned long flags; 12746e08d6bbSMika Westerberg 1275109fdf15SMika Westerberg raw_spin_lock_irqsave(&pctrl->lock, flags); 12766e08d6bbSMika Westerberg 12776e08d6bbSMika Westerberg intr_line = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0)); 12786e08d6bbSMika Westerberg intr_line &= CHV_PADCTRL0_INTSEL_MASK; 12796e08d6bbSMika Westerberg intr_line >>= CHV_PADCTRL0_INTSEL_SHIFT; 12806e08d6bbSMika Westerberg 12816e08d6bbSMika Westerberg value = readl(pctrl->regs + CHV_INTMASK); 12826e08d6bbSMika Westerberg if (mask) 12836e08d6bbSMika Westerberg value &= ~BIT(intr_line); 12846e08d6bbSMika Westerberg else 12856e08d6bbSMika Westerberg value |= BIT(intr_line); 12866e08d6bbSMika Westerberg chv_writel(value, pctrl->regs + CHV_INTMASK); 12876e08d6bbSMika Westerberg 1288109fdf15SMika Westerberg raw_spin_unlock_irqrestore(&pctrl->lock, flags); 12896e08d6bbSMika Westerberg } 12906e08d6bbSMika Westerberg 12916e08d6bbSMika Westerberg static void chv_gpio_irq_mask(struct irq_data *d) 12926e08d6bbSMika Westerberg { 12936e08d6bbSMika Westerberg chv_gpio_irq_mask_unmask(d, true); 12946e08d6bbSMika Westerberg } 12956e08d6bbSMika Westerberg 12966e08d6bbSMika Westerberg static void chv_gpio_irq_unmask(struct irq_data *d) 12976e08d6bbSMika Westerberg { 12986e08d6bbSMika Westerberg chv_gpio_irq_mask_unmask(d, false); 12996e08d6bbSMika Westerberg } 13006e08d6bbSMika Westerberg 1301e6c906deSMika Westerberg static unsigned chv_gpio_irq_startup(struct irq_data *d) 1302e6c906deSMika Westerberg { 1303e6c906deSMika Westerberg /* 1304e6c906deSMika Westerberg * Check if the interrupt has been requested with 0 as triggering 1305e6c906deSMika Westerberg * type. In that case it is assumed that the current values 1306e6c906deSMika Westerberg * programmed to the hardware are used (e.g BIOS configured 1307e6c906deSMika Westerberg * defaults). 1308e6c906deSMika Westerberg * 1309e6c906deSMika Westerberg * In that case ->irq_set_type() will never be called so we need to 1310e6c906deSMika Westerberg * read back the values from hardware now, set correct flow handler 1311e6c906deSMika Westerberg * and update mappings before the interrupt is being used. 1312e6c906deSMika Westerberg */ 1313e6c906deSMika Westerberg if (irqd_get_trigger_type(d) == IRQ_TYPE_NONE) { 1314e6c906deSMika Westerberg struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 1315e6c906deSMika Westerberg struct chv_pinctrl *pctrl = gpiochip_to_pinctrl(gc); 1316e6c906deSMika Westerberg unsigned offset = irqd_to_hwirq(d); 1317e6c906deSMika Westerberg int pin = chv_gpio_offset_to_pin(pctrl, offset); 1318e6c906deSMika Westerberg irq_flow_handler_t handler; 1319e6c906deSMika Westerberg unsigned long flags; 1320e6c906deSMika Westerberg u32 intsel, value; 1321e6c906deSMika Westerberg 1322109fdf15SMika Westerberg raw_spin_lock_irqsave(&pctrl->lock, flags); 1323e6c906deSMika Westerberg intsel = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0)); 1324e6c906deSMika Westerberg intsel &= CHV_PADCTRL0_INTSEL_MASK; 1325e6c906deSMika Westerberg intsel >>= CHV_PADCTRL0_INTSEL_SHIFT; 1326e6c906deSMika Westerberg 1327e6c906deSMika Westerberg value = readl(chv_padreg(pctrl, pin, CHV_PADCTRL1)); 1328e6c906deSMika Westerberg if (value & CHV_PADCTRL1_INTWAKECFG_LEVEL) 1329e6c906deSMika Westerberg handler = handle_level_irq; 1330e6c906deSMika Westerberg else 1331e6c906deSMika Westerberg handler = handle_edge_irq; 1332e6c906deSMika Westerberg 1333e6c906deSMika Westerberg if (!pctrl->intr_lines[intsel]) { 1334a4e3f783SThomas Gleixner irq_set_handler_locked(d, handler); 1335e6c906deSMika Westerberg pctrl->intr_lines[intsel] = offset; 1336e6c906deSMika Westerberg } 1337109fdf15SMika Westerberg raw_spin_unlock_irqrestore(&pctrl->lock, flags); 1338e6c906deSMika Westerberg } 1339e6c906deSMika Westerberg 1340e6c906deSMika Westerberg chv_gpio_irq_unmask(d); 1341e6c906deSMika Westerberg return 0; 1342e6c906deSMika Westerberg } 1343e6c906deSMika Westerberg 13446e08d6bbSMika Westerberg static int chv_gpio_irq_type(struct irq_data *d, unsigned type) 13456e08d6bbSMika Westerberg { 13466e08d6bbSMika Westerberg struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 13476e08d6bbSMika Westerberg struct chv_pinctrl *pctrl = gpiochip_to_pinctrl(gc); 13486e08d6bbSMika Westerberg unsigned offset = irqd_to_hwirq(d); 13496e08d6bbSMika Westerberg int pin = chv_gpio_offset_to_pin(pctrl, offset); 13506e08d6bbSMika Westerberg unsigned long flags; 13516e08d6bbSMika Westerberg u32 value; 13526e08d6bbSMika Westerberg 1353109fdf15SMika Westerberg raw_spin_lock_irqsave(&pctrl->lock, flags); 13546e08d6bbSMika Westerberg 13556e08d6bbSMika Westerberg /* 13566e08d6bbSMika Westerberg * Pins which can be used as shared interrupt are configured in 13576e08d6bbSMika Westerberg * BIOS. Driver trusts BIOS configurations and assigns different 13586e08d6bbSMika Westerberg * handler according to the irq type. 13596e08d6bbSMika Westerberg * 13606e08d6bbSMika Westerberg * Driver needs to save the mapping between each pin and 13616e08d6bbSMika Westerberg * its interrupt line. 13626e08d6bbSMika Westerberg * 1. If the pin cfg is locked in BIOS: 13636e08d6bbSMika Westerberg * Trust BIOS has programmed IntWakeCfg bits correctly, 13646e08d6bbSMika Westerberg * driver just needs to save the mapping. 13656e08d6bbSMika Westerberg * 2. If the pin cfg is not locked in BIOS: 13666e08d6bbSMika Westerberg * Driver programs the IntWakeCfg bits and save the mapping. 13676e08d6bbSMika Westerberg */ 13686e08d6bbSMika Westerberg if (!chv_pad_locked(pctrl, pin)) { 13696e08d6bbSMika Westerberg void __iomem *reg = chv_padreg(pctrl, pin, CHV_PADCTRL1); 13706e08d6bbSMika Westerberg 13716e08d6bbSMika Westerberg value = readl(reg); 13726e08d6bbSMika Westerberg value &= ~CHV_PADCTRL1_INTWAKECFG_MASK; 13736e08d6bbSMika Westerberg value &= ~CHV_PADCTRL1_INVRXTX_MASK; 13746e08d6bbSMika Westerberg 13756e08d6bbSMika Westerberg if (type & IRQ_TYPE_EDGE_BOTH) { 13766e08d6bbSMika Westerberg if ((type & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH) 13776e08d6bbSMika Westerberg value |= CHV_PADCTRL1_INTWAKECFG_BOTH; 13786e08d6bbSMika Westerberg else if (type & IRQ_TYPE_EDGE_RISING) 13796e08d6bbSMika Westerberg value |= CHV_PADCTRL1_INTWAKECFG_RISING; 13806e08d6bbSMika Westerberg else if (type & IRQ_TYPE_EDGE_FALLING) 13816e08d6bbSMika Westerberg value |= CHV_PADCTRL1_INTWAKECFG_FALLING; 13826e08d6bbSMika Westerberg } else if (type & IRQ_TYPE_LEVEL_MASK) { 13836e08d6bbSMika Westerberg value |= CHV_PADCTRL1_INTWAKECFG_LEVEL; 13846e08d6bbSMika Westerberg if (type & IRQ_TYPE_LEVEL_LOW) 13856e08d6bbSMika Westerberg value |= CHV_PADCTRL1_INVRXTX_RXDATA; 13866e08d6bbSMika Westerberg } 13876e08d6bbSMika Westerberg 13886e08d6bbSMika Westerberg chv_writel(value, reg); 13896e08d6bbSMika Westerberg } 13906e08d6bbSMika Westerberg 13916e08d6bbSMika Westerberg value = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0)); 13926e08d6bbSMika Westerberg value &= CHV_PADCTRL0_INTSEL_MASK; 13936e08d6bbSMika Westerberg value >>= CHV_PADCTRL0_INTSEL_SHIFT; 13946e08d6bbSMika Westerberg 13956e08d6bbSMika Westerberg pctrl->intr_lines[value] = offset; 13966e08d6bbSMika Westerberg 13976e08d6bbSMika Westerberg if (type & IRQ_TYPE_EDGE_BOTH) 1398a4e3f783SThomas Gleixner irq_set_handler_locked(d, handle_edge_irq); 13996e08d6bbSMika Westerberg else if (type & IRQ_TYPE_LEVEL_MASK) 1400a4e3f783SThomas Gleixner irq_set_handler_locked(d, handle_level_irq); 14016e08d6bbSMika Westerberg 1402109fdf15SMika Westerberg raw_spin_unlock_irqrestore(&pctrl->lock, flags); 14036e08d6bbSMika Westerberg 14046e08d6bbSMika Westerberg return 0; 14056e08d6bbSMika Westerberg } 14066e08d6bbSMika Westerberg 14076e08d6bbSMika Westerberg static struct irq_chip chv_gpio_irqchip = { 14086e08d6bbSMika Westerberg .name = "chv-gpio", 1409e6c906deSMika Westerberg .irq_startup = chv_gpio_irq_startup, 14106e08d6bbSMika Westerberg .irq_ack = chv_gpio_irq_ack, 14116e08d6bbSMika Westerberg .irq_mask = chv_gpio_irq_mask, 14126e08d6bbSMika Westerberg .irq_unmask = chv_gpio_irq_unmask, 14136e08d6bbSMika Westerberg .irq_set_type = chv_gpio_irq_type, 14146e08d6bbSMika Westerberg .flags = IRQCHIP_SKIP_SET_WAKE, 14156e08d6bbSMika Westerberg }; 14166e08d6bbSMika Westerberg 14176e08d6bbSMika Westerberg static void chv_gpio_irq_handler(unsigned irq, struct irq_desc *desc) 14186e08d6bbSMika Westerberg { 14196e08d6bbSMika Westerberg struct gpio_chip *gc = irq_desc_get_handler_data(desc); 14206e08d6bbSMika Westerberg struct chv_pinctrl *pctrl = gpiochip_to_pinctrl(gc); 14215663bb27SJiang Liu struct irq_chip *chip = irq_desc_get_chip(desc); 14226e08d6bbSMika Westerberg unsigned long pending; 14236e08d6bbSMika Westerberg u32 intr_line; 14246e08d6bbSMika Westerberg 14256e08d6bbSMika Westerberg chained_irq_enter(chip, desc); 14266e08d6bbSMika Westerberg 14276e08d6bbSMika Westerberg pending = readl(pctrl->regs + CHV_INTSTAT); 14286e08d6bbSMika Westerberg for_each_set_bit(intr_line, &pending, 16) { 14296e08d6bbSMika Westerberg unsigned irq, offset; 14306e08d6bbSMika Westerberg 14316e08d6bbSMika Westerberg offset = pctrl->intr_lines[intr_line]; 14326e08d6bbSMika Westerberg irq = irq_find_mapping(gc->irqdomain, offset); 14336e08d6bbSMika Westerberg generic_handle_irq(irq); 14346e08d6bbSMika Westerberg } 14356e08d6bbSMika Westerberg 14366e08d6bbSMika Westerberg chained_irq_exit(chip, desc); 14376e08d6bbSMika Westerberg } 14386e08d6bbSMika Westerberg 14396e08d6bbSMika Westerberg static int chv_gpio_probe(struct chv_pinctrl *pctrl, int irq) 14406e08d6bbSMika Westerberg { 14416e08d6bbSMika Westerberg const struct chv_gpio_pinrange *range; 14426e08d6bbSMika Westerberg struct gpio_chip *chip = &pctrl->chip; 14436e08d6bbSMika Westerberg int ret, i, offset; 14446e08d6bbSMika Westerberg 14456e08d6bbSMika Westerberg *chip = chv_gpio_chip; 14466e08d6bbSMika Westerberg 14476e08d6bbSMika Westerberg chip->ngpio = pctrl->community->ngpios; 14486e08d6bbSMika Westerberg chip->label = dev_name(pctrl->dev); 14496e08d6bbSMika Westerberg chip->dev = pctrl->dev; 14506e08d6bbSMika Westerberg chip->base = -1; 14516e08d6bbSMika Westerberg 14526e08d6bbSMika Westerberg ret = gpiochip_add(chip); 14536e08d6bbSMika Westerberg if (ret) { 14546e08d6bbSMika Westerberg dev_err(pctrl->dev, "Failed to register gpiochip\n"); 14556e08d6bbSMika Westerberg return ret; 14566e08d6bbSMika Westerberg } 14576e08d6bbSMika Westerberg 14586e08d6bbSMika Westerberg for (i = 0, offset = 0; i < pctrl->community->ngpio_ranges; i++) { 14596e08d6bbSMika Westerberg range = &pctrl->community->gpio_ranges[i]; 14606e08d6bbSMika Westerberg ret = gpiochip_add_pin_range(chip, dev_name(pctrl->dev), offset, 14616e08d6bbSMika Westerberg range->base, range->npins); 14626e08d6bbSMika Westerberg if (ret) { 14636e08d6bbSMika Westerberg dev_err(pctrl->dev, "failed to add GPIO pin range\n"); 14646e08d6bbSMika Westerberg goto fail; 14656e08d6bbSMika Westerberg } 14666e08d6bbSMika Westerberg 14676e08d6bbSMika Westerberg offset += range->npins; 14686e08d6bbSMika Westerberg } 14696e08d6bbSMika Westerberg 14706e08d6bbSMika Westerberg /* Mask and clear all interrupts */ 14716e08d6bbSMika Westerberg chv_writel(0, pctrl->regs + CHV_INTMASK); 14726e08d6bbSMika Westerberg chv_writel(0xffff, pctrl->regs + CHV_INTSTAT); 14736e08d6bbSMika Westerberg 14746e08d6bbSMika Westerberg ret = gpiochip_irqchip_add(chip, &chv_gpio_irqchip, 0, 14756e08d6bbSMika Westerberg handle_simple_irq, IRQ_TYPE_NONE); 14766e08d6bbSMika Westerberg if (ret) { 14776e08d6bbSMika Westerberg dev_err(pctrl->dev, "failed to add IRQ chip\n"); 14786e08d6bbSMika Westerberg goto fail; 14796e08d6bbSMika Westerberg } 14806e08d6bbSMika Westerberg 14816e08d6bbSMika Westerberg gpiochip_set_chained_irqchip(chip, &chv_gpio_irqchip, irq, 14826e08d6bbSMika Westerberg chv_gpio_irq_handler); 14836e08d6bbSMika Westerberg return 0; 14846e08d6bbSMika Westerberg 14856e08d6bbSMika Westerberg fail: 14866e08d6bbSMika Westerberg gpiochip_remove(chip); 14876e08d6bbSMika Westerberg 14886e08d6bbSMika Westerberg return ret; 14896e08d6bbSMika Westerberg } 14906e08d6bbSMika Westerberg 14916e08d6bbSMika Westerberg static int chv_pinctrl_probe(struct platform_device *pdev) 14926e08d6bbSMika Westerberg { 14936e08d6bbSMika Westerberg struct chv_pinctrl *pctrl; 14946e08d6bbSMika Westerberg struct acpi_device *adev; 14956e08d6bbSMika Westerberg struct resource *res; 14966e08d6bbSMika Westerberg int ret, irq, i; 14976e08d6bbSMika Westerberg 14986e08d6bbSMika Westerberg adev = ACPI_COMPANION(&pdev->dev); 14996e08d6bbSMika Westerberg if (!adev) 15006e08d6bbSMika Westerberg return -ENODEV; 15016e08d6bbSMika Westerberg 15026e08d6bbSMika Westerberg pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL); 15036e08d6bbSMika Westerberg if (!pctrl) 15046e08d6bbSMika Westerberg return -ENOMEM; 15056e08d6bbSMika Westerberg 15066e08d6bbSMika Westerberg for (i = 0; i < ARRAY_SIZE(chv_communities); i++) 15076e08d6bbSMika Westerberg if (!strcmp(adev->pnp.unique_id, chv_communities[i]->uid)) { 15086e08d6bbSMika Westerberg pctrl->community = chv_communities[i]; 15096e08d6bbSMika Westerberg break; 15106e08d6bbSMika Westerberg } 15116e08d6bbSMika Westerberg if (i == ARRAY_SIZE(chv_communities)) 15126e08d6bbSMika Westerberg return -ENODEV; 15136e08d6bbSMika Westerberg 1514109fdf15SMika Westerberg raw_spin_lock_init(&pctrl->lock); 15156e08d6bbSMika Westerberg pctrl->dev = &pdev->dev; 15166e08d6bbSMika Westerberg 15179eb457b5SMika Westerberg #ifdef CONFIG_PM_SLEEP 15189eb457b5SMika Westerberg pctrl->saved_pin_context = devm_kcalloc(pctrl->dev, 15199eb457b5SMika Westerberg pctrl->community->npins, sizeof(*pctrl->saved_pin_context), 15209eb457b5SMika Westerberg GFP_KERNEL); 15219eb457b5SMika Westerberg if (!pctrl->saved_pin_context) 15229eb457b5SMika Westerberg return -ENOMEM; 15239eb457b5SMika Westerberg #endif 15249eb457b5SMika Westerberg 15256e08d6bbSMika Westerberg res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 15266e08d6bbSMika Westerberg pctrl->regs = devm_ioremap_resource(&pdev->dev, res); 15276e08d6bbSMika Westerberg if (IS_ERR(pctrl->regs)) 15286e08d6bbSMika Westerberg return PTR_ERR(pctrl->regs); 15296e08d6bbSMika Westerberg 15306e08d6bbSMika Westerberg irq = platform_get_irq(pdev, 0); 15316e08d6bbSMika Westerberg if (irq < 0) { 15326e08d6bbSMika Westerberg dev_err(&pdev->dev, "failed to get interrupt number\n"); 15336e08d6bbSMika Westerberg return irq; 15346e08d6bbSMika Westerberg } 15356e08d6bbSMika Westerberg 15366e08d6bbSMika Westerberg pctrl->pctldesc = chv_pinctrl_desc; 15376e08d6bbSMika Westerberg pctrl->pctldesc.name = dev_name(&pdev->dev); 15386e08d6bbSMika Westerberg pctrl->pctldesc.pins = pctrl->community->pins; 15396e08d6bbSMika Westerberg pctrl->pctldesc.npins = pctrl->community->npins; 15406e08d6bbSMika Westerberg 15416e08d6bbSMika Westerberg pctrl->pctldev = pinctrl_register(&pctrl->pctldesc, &pdev->dev, pctrl); 1542323de9efSMasahiro Yamada if (IS_ERR(pctrl->pctldev)) { 15436e08d6bbSMika Westerberg dev_err(&pdev->dev, "failed to register pinctrl driver\n"); 1544323de9efSMasahiro Yamada return PTR_ERR(pctrl->pctldev); 15456e08d6bbSMika Westerberg } 15466e08d6bbSMika Westerberg 15476e08d6bbSMika Westerberg ret = chv_gpio_probe(pctrl, irq); 15486e08d6bbSMika Westerberg if (ret) { 15496e08d6bbSMika Westerberg pinctrl_unregister(pctrl->pctldev); 15506e08d6bbSMika Westerberg return ret; 15516e08d6bbSMika Westerberg } 15526e08d6bbSMika Westerberg 15536e08d6bbSMika Westerberg platform_set_drvdata(pdev, pctrl); 15546e08d6bbSMika Westerberg 15556e08d6bbSMika Westerberg return 0; 15566e08d6bbSMika Westerberg } 15576e08d6bbSMika Westerberg 15586e08d6bbSMika Westerberg static int chv_pinctrl_remove(struct platform_device *pdev) 15596e08d6bbSMika Westerberg { 15606e08d6bbSMika Westerberg struct chv_pinctrl *pctrl = platform_get_drvdata(pdev); 15616e08d6bbSMika Westerberg 15626e08d6bbSMika Westerberg gpiochip_remove(&pctrl->chip); 15636e08d6bbSMika Westerberg pinctrl_unregister(pctrl->pctldev); 15646e08d6bbSMika Westerberg 15656e08d6bbSMika Westerberg return 0; 15666e08d6bbSMika Westerberg } 15676e08d6bbSMika Westerberg 15689eb457b5SMika Westerberg #ifdef CONFIG_PM_SLEEP 15699eb457b5SMika Westerberg static int chv_pinctrl_suspend(struct device *dev) 15709eb457b5SMika Westerberg { 15719eb457b5SMika Westerberg struct platform_device *pdev = to_platform_device(dev); 15729eb457b5SMika Westerberg struct chv_pinctrl *pctrl = platform_get_drvdata(pdev); 15739eb457b5SMika Westerberg int i; 15749eb457b5SMika Westerberg 15759eb457b5SMika Westerberg pctrl->saved_intmask = readl(pctrl->regs + CHV_INTMASK); 15769eb457b5SMika Westerberg 15779eb457b5SMika Westerberg for (i = 0; i < pctrl->community->npins; i++) { 15789eb457b5SMika Westerberg const struct pinctrl_pin_desc *desc; 15799eb457b5SMika Westerberg struct chv_pin_context *ctx; 15809eb457b5SMika Westerberg void __iomem *reg; 15819eb457b5SMika Westerberg 15829eb457b5SMika Westerberg desc = &pctrl->community->pins[i]; 15839eb457b5SMika Westerberg if (chv_pad_locked(pctrl, desc->number)) 15849eb457b5SMika Westerberg continue; 15859eb457b5SMika Westerberg 15869eb457b5SMika Westerberg ctx = &pctrl->saved_pin_context[i]; 15879eb457b5SMika Westerberg 15889eb457b5SMika Westerberg reg = chv_padreg(pctrl, desc->number, CHV_PADCTRL0); 15899eb457b5SMika Westerberg ctx->padctrl0 = readl(reg) & ~CHV_PADCTRL0_GPIORXSTATE; 15909eb457b5SMika Westerberg 15919eb457b5SMika Westerberg reg = chv_padreg(pctrl, desc->number, CHV_PADCTRL1); 15929eb457b5SMika Westerberg ctx->padctrl1 = readl(reg); 15939eb457b5SMika Westerberg } 15949eb457b5SMika Westerberg 15959eb457b5SMika Westerberg return 0; 15969eb457b5SMika Westerberg } 15979eb457b5SMika Westerberg 15989eb457b5SMika Westerberg static int chv_pinctrl_resume(struct device *dev) 15999eb457b5SMika Westerberg { 16009eb457b5SMika Westerberg struct platform_device *pdev = to_platform_device(dev); 16019eb457b5SMika Westerberg struct chv_pinctrl *pctrl = platform_get_drvdata(pdev); 16029eb457b5SMika Westerberg int i; 16039eb457b5SMika Westerberg 16049eb457b5SMika Westerberg /* 16059eb457b5SMika Westerberg * Mask all interrupts before restoring per-pin configuration 16069eb457b5SMika Westerberg * registers because we don't know in which state BIOS left them 16079eb457b5SMika Westerberg * upon exiting suspend. 16089eb457b5SMika Westerberg */ 16099eb457b5SMika Westerberg chv_writel(0, pctrl->regs + CHV_INTMASK); 16109eb457b5SMika Westerberg 16119eb457b5SMika Westerberg for (i = 0; i < pctrl->community->npins; i++) { 16129eb457b5SMika Westerberg const struct pinctrl_pin_desc *desc; 16139eb457b5SMika Westerberg const struct chv_pin_context *ctx; 16149eb457b5SMika Westerberg void __iomem *reg; 16159eb457b5SMika Westerberg u32 val; 16169eb457b5SMika Westerberg 16179eb457b5SMika Westerberg desc = &pctrl->community->pins[i]; 16189eb457b5SMika Westerberg if (chv_pad_locked(pctrl, desc->number)) 16199eb457b5SMika Westerberg continue; 16209eb457b5SMika Westerberg 16219eb457b5SMika Westerberg ctx = &pctrl->saved_pin_context[i]; 16229eb457b5SMika Westerberg 16239eb457b5SMika Westerberg /* Only restore if our saved state differs from the current */ 16249eb457b5SMika Westerberg reg = chv_padreg(pctrl, desc->number, CHV_PADCTRL0); 16259eb457b5SMika Westerberg val = readl(reg) & ~CHV_PADCTRL0_GPIORXSTATE; 16269eb457b5SMika Westerberg if (ctx->padctrl0 != val) { 16279eb457b5SMika Westerberg chv_writel(ctx->padctrl0, reg); 16289eb457b5SMika Westerberg dev_dbg(pctrl->dev, "restored pin %2u ctrl0 0x%08x\n", 16299eb457b5SMika Westerberg desc->number, readl(reg)); 16309eb457b5SMika Westerberg } 16319eb457b5SMika Westerberg 16329eb457b5SMika Westerberg reg = chv_padreg(pctrl, desc->number, CHV_PADCTRL1); 16339eb457b5SMika Westerberg val = readl(reg); 16349eb457b5SMika Westerberg if (ctx->padctrl1 != val) { 16359eb457b5SMika Westerberg chv_writel(ctx->padctrl1, reg); 16369eb457b5SMika Westerberg dev_dbg(pctrl->dev, "restored pin %2u ctrl1 0x%08x\n", 16379eb457b5SMika Westerberg desc->number, readl(reg)); 16389eb457b5SMika Westerberg } 16399eb457b5SMika Westerberg } 16409eb457b5SMika Westerberg 16419eb457b5SMika Westerberg /* 16429eb457b5SMika Westerberg * Now that all pins are restored to known state, we can restore 16439eb457b5SMika Westerberg * the interrupt mask register as well. 16449eb457b5SMika Westerberg */ 16459eb457b5SMika Westerberg chv_writel(0xffff, pctrl->regs + CHV_INTSTAT); 16469eb457b5SMika Westerberg chv_writel(pctrl->saved_intmask, pctrl->regs + CHV_INTMASK); 16479eb457b5SMika Westerberg 16489eb457b5SMika Westerberg return 0; 16499eb457b5SMika Westerberg } 16509eb457b5SMika Westerberg #endif 16519eb457b5SMika Westerberg 16529eb457b5SMika Westerberg static const struct dev_pm_ops chv_pinctrl_pm_ops = { 16539eb457b5SMika Westerberg SET_LATE_SYSTEM_SLEEP_PM_OPS(chv_pinctrl_suspend, chv_pinctrl_resume) 16549eb457b5SMika Westerberg }; 16559eb457b5SMika Westerberg 16566e08d6bbSMika Westerberg static const struct acpi_device_id chv_pinctrl_acpi_match[] = { 16576e08d6bbSMika Westerberg { "INT33FF" }, 16586e08d6bbSMika Westerberg { } 16596e08d6bbSMika Westerberg }; 16606e08d6bbSMika Westerberg MODULE_DEVICE_TABLE(acpi, chv_pinctrl_acpi_match); 16616e08d6bbSMika Westerberg 16626e08d6bbSMika Westerberg static struct platform_driver chv_pinctrl_driver = { 16636e08d6bbSMika Westerberg .probe = chv_pinctrl_probe, 16646e08d6bbSMika Westerberg .remove = chv_pinctrl_remove, 16656e08d6bbSMika Westerberg .driver = { 16666e08d6bbSMika Westerberg .name = "cherryview-pinctrl", 16679eb457b5SMika Westerberg .pm = &chv_pinctrl_pm_ops, 16686e08d6bbSMika Westerberg .acpi_match_table = chv_pinctrl_acpi_match, 16696e08d6bbSMika Westerberg }, 16706e08d6bbSMika Westerberg }; 16716e08d6bbSMika Westerberg 16726e08d6bbSMika Westerberg static int __init chv_pinctrl_init(void) 16736e08d6bbSMika Westerberg { 16746e08d6bbSMika Westerberg return platform_driver_register(&chv_pinctrl_driver); 16756e08d6bbSMika Westerberg } 16766e08d6bbSMika Westerberg subsys_initcall(chv_pinctrl_init); 16776e08d6bbSMika Westerberg 16786e08d6bbSMika Westerberg static void __exit chv_pinctrl_exit(void) 16796e08d6bbSMika Westerberg { 16806e08d6bbSMika Westerberg platform_driver_unregister(&chv_pinctrl_driver); 16816e08d6bbSMika Westerberg } 16826e08d6bbSMika Westerberg module_exit(chv_pinctrl_exit); 16836e08d6bbSMika Westerberg 16846e08d6bbSMika Westerberg MODULE_AUTHOR("Mika Westerberg <mika.westerberg@linux.intel.com>"); 16856e08d6bbSMika Westerberg MODULE_DESCRIPTION("Intel Cherryview/Braswell pinctrl driver"); 16866e08d6bbSMika Westerberg MODULE_LICENSE("GPL v2"); 1687