Andy Shevchenko | 875a92b | 2018-06-29 15:36:34 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Cherryview/Braswell pinctrl driver |
| 4 | * |
| 5 | * Copyright (C) 2014, Intel Corporation |
| 6 | * Author: Mika Westerberg <mika.westerberg@linux.intel.com> |
| 7 | * |
| 8 | * This driver is based on the original Cherryview GPIO driver by |
| 9 | * Ning Li <ning.li@intel.com> |
| 10 | * Alan Cox <alan@linux.intel.com> |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 11 | */ |
| 12 | |
Mika Westerberg | 7036502 | 2017-04-10 13:16:33 +0300 | [diff] [blame] | 13 | #include <linux/dmi.h> |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 14 | #include <linux/kernel.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/types.h> |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 18 | #include <linux/gpio/driver.h> |
| 19 | #include <linux/acpi.h> |
| 20 | #include <linux/pinctrl/pinctrl.h> |
| 21 | #include <linux/pinctrl/pinmux.h> |
| 22 | #include <linux/pinctrl/pinconf.h> |
| 23 | #include <linux/pinctrl/pinconf-generic.h> |
| 24 | #include <linux/platform_device.h> |
| 25 | |
Andy Shevchenko | 5458b7c | 2018-09-04 14:26:21 +0300 | [diff] [blame^] | 26 | #include "pinctrl-intel.h" |
| 27 | |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 28 | #define CHV_INTSTAT 0x300 |
| 29 | #define CHV_INTMASK 0x380 |
| 30 | |
| 31 | #define FAMILY_PAD_REGS_OFF 0x4400 |
| 32 | #define FAMILY_PAD_REGS_SIZE 0x400 |
| 33 | #define MAX_FAMILY_PAD_GPIO_NO 15 |
| 34 | #define GPIO_REGS_SIZE 8 |
| 35 | |
| 36 | #define CHV_PADCTRL0 0x000 |
| 37 | #define CHV_PADCTRL0_INTSEL_SHIFT 28 |
| 38 | #define CHV_PADCTRL0_INTSEL_MASK (0xf << CHV_PADCTRL0_INTSEL_SHIFT) |
| 39 | #define CHV_PADCTRL0_TERM_UP BIT(23) |
| 40 | #define CHV_PADCTRL0_TERM_SHIFT 20 |
| 41 | #define CHV_PADCTRL0_TERM_MASK (7 << CHV_PADCTRL0_TERM_SHIFT) |
| 42 | #define CHV_PADCTRL0_TERM_20K 1 |
| 43 | #define CHV_PADCTRL0_TERM_5K 2 |
| 44 | #define CHV_PADCTRL0_TERM_1K 4 |
| 45 | #define CHV_PADCTRL0_PMODE_SHIFT 16 |
| 46 | #define CHV_PADCTRL0_PMODE_MASK (0xf << CHV_PADCTRL0_PMODE_SHIFT) |
| 47 | #define CHV_PADCTRL0_GPIOEN BIT(15) |
| 48 | #define CHV_PADCTRL0_GPIOCFG_SHIFT 8 |
| 49 | #define CHV_PADCTRL0_GPIOCFG_MASK (7 << CHV_PADCTRL0_GPIOCFG_SHIFT) |
| 50 | #define CHV_PADCTRL0_GPIOCFG_GPIO 0 |
| 51 | #define CHV_PADCTRL0_GPIOCFG_GPO 1 |
| 52 | #define CHV_PADCTRL0_GPIOCFG_GPI 2 |
| 53 | #define CHV_PADCTRL0_GPIOCFG_HIZ 3 |
| 54 | #define CHV_PADCTRL0_GPIOTXSTATE BIT(1) |
| 55 | #define CHV_PADCTRL0_GPIORXSTATE BIT(0) |
| 56 | |
| 57 | #define CHV_PADCTRL1 0x004 |
| 58 | #define CHV_PADCTRL1_CFGLOCK BIT(31) |
| 59 | #define CHV_PADCTRL1_INVRXTX_SHIFT 4 |
| 60 | #define CHV_PADCTRL1_INVRXTX_MASK (0xf << CHV_PADCTRL1_INVRXTX_SHIFT) |
| 61 | #define CHV_PADCTRL1_INVRXTX_TXENABLE (2 << CHV_PADCTRL1_INVRXTX_SHIFT) |
| 62 | #define CHV_PADCTRL1_ODEN BIT(3) |
| 63 | #define CHV_PADCTRL1_INVRXTX_RXDATA (4 << CHV_PADCTRL1_INVRXTX_SHIFT) |
| 64 | #define CHV_PADCTRL1_INTWAKECFG_MASK 7 |
| 65 | #define CHV_PADCTRL1_INTWAKECFG_FALLING 1 |
| 66 | #define CHV_PADCTRL1_INTWAKECFG_RISING 2 |
| 67 | #define CHV_PADCTRL1_INTWAKECFG_BOTH 3 |
| 68 | #define CHV_PADCTRL1_INTWAKECFG_LEVEL 4 |
| 69 | |
| 70 | /** |
| 71 | * struct chv_alternate_function - A per group or per pin alternate function |
| 72 | * @pin: Pin number (only used in per pin configs) |
| 73 | * @mode: Mode the pin should be set in |
| 74 | * @invert_oe: Invert OE for this pin |
| 75 | */ |
| 76 | struct chv_alternate_function { |
| 77 | unsigned pin; |
| 78 | u8 mode; |
| 79 | bool invert_oe; |
| 80 | }; |
| 81 | |
| 82 | /** |
| 83 | * struct chv_pincgroup - describes a CHV pin group |
| 84 | * @name: Name of the group |
| 85 | * @pins: An array of pins in this group |
| 86 | * @npins: Number of pins in this group |
| 87 | * @altfunc: Alternate function applied to all pins in this group |
| 88 | * @overrides: Alternate function override per pin or %NULL if not used |
| 89 | * @noverrides: Number of per pin alternate function overrides if |
| 90 | * @overrides != NULL. |
| 91 | */ |
| 92 | struct chv_pingroup { |
| 93 | const char *name; |
| 94 | const unsigned *pins; |
| 95 | size_t npins; |
| 96 | struct chv_alternate_function altfunc; |
| 97 | const struct chv_alternate_function *overrides; |
| 98 | size_t noverrides; |
| 99 | }; |
| 100 | |
| 101 | /** |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 102 | * struct chv_gpio_pinrange - A range of pins that can be used as GPIOs |
| 103 | * @base: Start pin number |
| 104 | * @npins: Number of pins in this range |
| 105 | */ |
| 106 | struct chv_gpio_pinrange { |
| 107 | unsigned base; |
| 108 | unsigned npins; |
| 109 | }; |
| 110 | |
| 111 | /** |
| 112 | * struct chv_community - A community specific configuration |
| 113 | * @uid: ACPI _UID used to match the community |
| 114 | * @pins: All pins in this community |
| 115 | * @npins: Number of pins |
| 116 | * @groups: All groups in this community |
| 117 | * @ngroups: Number of groups |
| 118 | * @functions: All functions in this community |
| 119 | * @nfunctions: Number of functions |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 120 | * @gpio_ranges: An array of GPIO ranges in this community |
| 121 | * @ngpio_ranges: Number of GPIO ranges |
Mika Westerberg | 47c950d | 2016-09-20 15:15:22 +0300 | [diff] [blame] | 122 | * @nirqs: Total number of IRQs this community can generate |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 123 | */ |
| 124 | struct chv_community { |
| 125 | const char *uid; |
| 126 | const struct pinctrl_pin_desc *pins; |
| 127 | size_t npins; |
| 128 | const struct chv_pingroup *groups; |
| 129 | size_t ngroups; |
Andy Shevchenko | 5458b7c | 2018-09-04 14:26:21 +0300 | [diff] [blame^] | 130 | const struct intel_function *functions; |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 131 | size_t nfunctions; |
| 132 | const struct chv_gpio_pinrange *gpio_ranges; |
| 133 | size_t ngpio_ranges; |
Mika Westerberg | 47c950d | 2016-09-20 15:15:22 +0300 | [diff] [blame] | 134 | size_t nirqs; |
Hans de Goede | a0b0285 | 2017-03-23 14:23:25 +0100 | [diff] [blame] | 135 | acpi_adr_space_type acpi_space_id; |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 136 | }; |
| 137 | |
Mika Westerberg | 9eb457b | 2014-12-04 12:32:50 +0200 | [diff] [blame] | 138 | struct chv_pin_context { |
| 139 | u32 padctrl0; |
| 140 | u32 padctrl1; |
| 141 | }; |
| 142 | |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 143 | /** |
| 144 | * struct chv_pinctrl - CHV pinctrl private structure |
| 145 | * @dev: Pointer to the parent device |
| 146 | * @pctldesc: Pin controller description |
| 147 | * @pctldev: Pointer to the pin controller device |
| 148 | * @chip: GPIO chip in this pin controller |
| 149 | * @regs: MMIO registers |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 150 | * @intr_lines: Stores mapping between 16 HW interrupt wires and GPIO |
| 151 | * offset (in GPIO number space) |
| 152 | * @community: Community this pinctrl instance represents |
| 153 | * |
| 154 | * The first group in @groups is expected to contain all pins that can be |
| 155 | * used as GPIOs. |
| 156 | */ |
| 157 | struct chv_pinctrl { |
| 158 | struct device *dev; |
| 159 | struct pinctrl_desc pctldesc; |
| 160 | struct pinctrl_dev *pctldev; |
| 161 | struct gpio_chip chip; |
| 162 | void __iomem *regs; |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 163 | unsigned intr_lines[16]; |
| 164 | const struct chv_community *community; |
Mika Westerberg | 9eb457b | 2014-12-04 12:32:50 +0200 | [diff] [blame] | 165 | u32 saved_intmask; |
| 166 | struct chv_pin_context *saved_pin_context; |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 167 | }; |
| 168 | |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 169 | #define ALTERNATE_FUNCTION(p, m, i) \ |
| 170 | { \ |
| 171 | .pin = (p), \ |
| 172 | .mode = (m), \ |
| 173 | .invert_oe = (i), \ |
| 174 | } |
| 175 | |
Andy Shevchenko | 5458b7c | 2018-09-04 14:26:21 +0300 | [diff] [blame^] | 176 | #define PIN_GROUP_WITH_ALT(n, p, m, i) \ |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 177 | { \ |
| 178 | .name = (n), \ |
| 179 | .pins = (p), \ |
| 180 | .npins = ARRAY_SIZE((p)), \ |
| 181 | .altfunc.mode = (m), \ |
| 182 | .altfunc.invert_oe = (i), \ |
| 183 | } |
| 184 | |
| 185 | #define PIN_GROUP_WITH_OVERRIDE(n, p, m, i, o) \ |
| 186 | { \ |
| 187 | .name = (n), \ |
| 188 | .pins = (p), \ |
| 189 | .npins = ARRAY_SIZE((p)), \ |
| 190 | .altfunc.mode = (m), \ |
| 191 | .altfunc.invert_oe = (i), \ |
| 192 | .overrides = (o), \ |
| 193 | .noverrides = ARRAY_SIZE((o)), \ |
| 194 | } |
| 195 | |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 196 | #define GPIO_PINRANGE(start, end) \ |
| 197 | { \ |
| 198 | .base = (start), \ |
| 199 | .npins = (end) - (start) + 1, \ |
| 200 | } |
| 201 | |
| 202 | static const struct pinctrl_pin_desc southwest_pins[] = { |
| 203 | PINCTRL_PIN(0, "FST_SPI_D2"), |
| 204 | PINCTRL_PIN(1, "FST_SPI_D0"), |
| 205 | PINCTRL_PIN(2, "FST_SPI_CLK"), |
| 206 | PINCTRL_PIN(3, "FST_SPI_D3"), |
| 207 | PINCTRL_PIN(4, "FST_SPI_CS1_B"), |
| 208 | PINCTRL_PIN(5, "FST_SPI_D1"), |
| 209 | PINCTRL_PIN(6, "FST_SPI_CS0_B"), |
| 210 | PINCTRL_PIN(7, "FST_SPI_CS2_B"), |
| 211 | |
| 212 | PINCTRL_PIN(15, "UART1_RTS_B"), |
| 213 | PINCTRL_PIN(16, "UART1_RXD"), |
| 214 | PINCTRL_PIN(17, "UART2_RXD"), |
| 215 | PINCTRL_PIN(18, "UART1_CTS_B"), |
| 216 | PINCTRL_PIN(19, "UART2_RTS_B"), |
| 217 | PINCTRL_PIN(20, "UART1_TXD"), |
| 218 | PINCTRL_PIN(21, "UART2_TXD"), |
| 219 | PINCTRL_PIN(22, "UART2_CTS_B"), |
| 220 | |
| 221 | PINCTRL_PIN(30, "MF_HDA_CLK"), |
| 222 | PINCTRL_PIN(31, "MF_HDA_RSTB"), |
| 223 | PINCTRL_PIN(32, "MF_HDA_SDIO"), |
| 224 | PINCTRL_PIN(33, "MF_HDA_SDO"), |
| 225 | PINCTRL_PIN(34, "MF_HDA_DOCKRSTB"), |
| 226 | PINCTRL_PIN(35, "MF_HDA_SYNC"), |
| 227 | PINCTRL_PIN(36, "MF_HDA_SDI1"), |
| 228 | PINCTRL_PIN(37, "MF_HDA_DOCKENB"), |
| 229 | |
| 230 | PINCTRL_PIN(45, "I2C5_SDA"), |
| 231 | PINCTRL_PIN(46, "I2C4_SDA"), |
| 232 | PINCTRL_PIN(47, "I2C6_SDA"), |
| 233 | PINCTRL_PIN(48, "I2C5_SCL"), |
| 234 | PINCTRL_PIN(49, "I2C_NFC_SDA"), |
| 235 | PINCTRL_PIN(50, "I2C4_SCL"), |
| 236 | PINCTRL_PIN(51, "I2C6_SCL"), |
| 237 | PINCTRL_PIN(52, "I2C_NFC_SCL"), |
| 238 | |
| 239 | PINCTRL_PIN(60, "I2C1_SDA"), |
| 240 | PINCTRL_PIN(61, "I2C0_SDA"), |
| 241 | PINCTRL_PIN(62, "I2C2_SDA"), |
| 242 | PINCTRL_PIN(63, "I2C1_SCL"), |
| 243 | PINCTRL_PIN(64, "I2C3_SDA"), |
| 244 | PINCTRL_PIN(65, "I2C0_SCL"), |
| 245 | PINCTRL_PIN(66, "I2C2_SCL"), |
| 246 | PINCTRL_PIN(67, "I2C3_SCL"), |
| 247 | |
| 248 | PINCTRL_PIN(75, "SATA_GP0"), |
| 249 | PINCTRL_PIN(76, "SATA_GP1"), |
| 250 | PINCTRL_PIN(77, "SATA_LEDN"), |
| 251 | PINCTRL_PIN(78, "SATA_GP2"), |
| 252 | PINCTRL_PIN(79, "MF_SMB_ALERTB"), |
| 253 | PINCTRL_PIN(80, "SATA_GP3"), |
| 254 | PINCTRL_PIN(81, "MF_SMB_CLK"), |
| 255 | PINCTRL_PIN(82, "MF_SMB_DATA"), |
| 256 | |
| 257 | PINCTRL_PIN(90, "PCIE_CLKREQ0B"), |
| 258 | PINCTRL_PIN(91, "PCIE_CLKREQ1B"), |
| 259 | PINCTRL_PIN(92, "GP_SSP_2_CLK"), |
| 260 | PINCTRL_PIN(93, "PCIE_CLKREQ2B"), |
| 261 | PINCTRL_PIN(94, "GP_SSP_2_RXD"), |
| 262 | PINCTRL_PIN(95, "PCIE_CLKREQ3B"), |
| 263 | PINCTRL_PIN(96, "GP_SSP_2_FS"), |
| 264 | PINCTRL_PIN(97, "GP_SSP_2_TXD"), |
| 265 | }; |
| 266 | |
| 267 | static const unsigned southwest_fspi_pins[] = { 0, 1, 2, 3, 4, 5, 6, 7 }; |
| 268 | static const unsigned southwest_uart0_pins[] = { 16, 20 }; |
| 269 | static const unsigned southwest_uart1_pins[] = { 15, 16, 18, 20 }; |
| 270 | static const unsigned southwest_uart2_pins[] = { 17, 19, 21, 22 }; |
| 271 | static const unsigned southwest_i2c0_pins[] = { 61, 65 }; |
| 272 | static const unsigned southwest_hda_pins[] = { 30, 31, 32, 33, 34, 35, 36, 37 }; |
| 273 | static const unsigned southwest_lpe_pins[] = { |
| 274 | 30, 31, 32, 33, 34, 35, 36, 37, 92, 94, 96, 97, |
| 275 | }; |
| 276 | static const unsigned southwest_i2c1_pins[] = { 60, 63 }; |
| 277 | static const unsigned southwest_i2c2_pins[] = { 62, 66 }; |
| 278 | static const unsigned southwest_i2c3_pins[] = { 64, 67 }; |
| 279 | static const unsigned southwest_i2c4_pins[] = { 46, 50 }; |
| 280 | static const unsigned southwest_i2c5_pins[] = { 45, 48 }; |
| 281 | static const unsigned southwest_i2c6_pins[] = { 47, 51 }; |
| 282 | static const unsigned southwest_i2c_nfc_pins[] = { 49, 52 }; |
| 283 | static const unsigned southwest_smbus_pins[] = { 79, 81, 82 }; |
| 284 | static const unsigned southwest_spi3_pins[] = { 76, 79, 80, 81, 82 }; |
| 285 | |
| 286 | /* LPE I2S TXD pins need to have invert_oe set */ |
| 287 | static const struct chv_alternate_function southwest_lpe_altfuncs[] = { |
| 288 | ALTERNATE_FUNCTION(30, 1, true), |
| 289 | ALTERNATE_FUNCTION(34, 1, true), |
| 290 | ALTERNATE_FUNCTION(97, 1, true), |
| 291 | }; |
| 292 | |
| 293 | /* |
| 294 | * Two spi3 chipselects are available in different mode than the main spi3 |
| 295 | * functionality, which is using mode 1. |
| 296 | */ |
| 297 | static const struct chv_alternate_function southwest_spi3_altfuncs[] = { |
| 298 | ALTERNATE_FUNCTION(76, 3, false), |
| 299 | ALTERNATE_FUNCTION(80, 3, false), |
| 300 | }; |
| 301 | |
| 302 | static const struct chv_pingroup southwest_groups[] = { |
Andy Shevchenko | 5458b7c | 2018-09-04 14:26:21 +0300 | [diff] [blame^] | 303 | PIN_GROUP_WITH_ALT("uart0_grp", southwest_uart0_pins, 2, false), |
| 304 | PIN_GROUP_WITH_ALT("uart1_grp", southwest_uart1_pins, 1, false), |
| 305 | PIN_GROUP_WITH_ALT("uart2_grp", southwest_uart2_pins, 1, false), |
| 306 | PIN_GROUP_WITH_ALT("hda_grp", southwest_hda_pins, 2, false), |
| 307 | PIN_GROUP_WITH_ALT("i2c0_grp", southwest_i2c0_pins, 1, true), |
| 308 | PIN_GROUP_WITH_ALT("i2c1_grp", southwest_i2c1_pins, 1, true), |
| 309 | PIN_GROUP_WITH_ALT("i2c2_grp", southwest_i2c2_pins, 1, true), |
| 310 | PIN_GROUP_WITH_ALT("i2c3_grp", southwest_i2c3_pins, 1, true), |
| 311 | PIN_GROUP_WITH_ALT("i2c4_grp", southwest_i2c4_pins, 1, true), |
| 312 | PIN_GROUP_WITH_ALT("i2c5_grp", southwest_i2c5_pins, 1, true), |
| 313 | PIN_GROUP_WITH_ALT("i2c6_grp", southwest_i2c6_pins, 1, true), |
| 314 | PIN_GROUP_WITH_ALT("i2c_nfc_grp", southwest_i2c_nfc_pins, 2, true), |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 315 | |
| 316 | PIN_GROUP_WITH_OVERRIDE("lpe_grp", southwest_lpe_pins, 1, false, |
| 317 | southwest_lpe_altfuncs), |
| 318 | PIN_GROUP_WITH_OVERRIDE("spi3_grp", southwest_spi3_pins, 2, false, |
| 319 | southwest_spi3_altfuncs), |
| 320 | }; |
| 321 | |
| 322 | static const char * const southwest_uart0_groups[] = { "uart0_grp" }; |
| 323 | static const char * const southwest_uart1_groups[] = { "uart1_grp" }; |
| 324 | static const char * const southwest_uart2_groups[] = { "uart2_grp" }; |
| 325 | static const char * const southwest_hda_groups[] = { "hda_grp" }; |
| 326 | static const char * const southwest_lpe_groups[] = { "lpe_grp" }; |
| 327 | static const char * const southwest_i2c0_groups[] = { "i2c0_grp" }; |
| 328 | static const char * const southwest_i2c1_groups[] = { "i2c1_grp" }; |
| 329 | static const char * const southwest_i2c2_groups[] = { "i2c2_grp" }; |
| 330 | static const char * const southwest_i2c3_groups[] = { "i2c3_grp" }; |
| 331 | static const char * const southwest_i2c4_groups[] = { "i2c4_grp" }; |
| 332 | static const char * const southwest_i2c5_groups[] = { "i2c5_grp" }; |
| 333 | static const char * const southwest_i2c6_groups[] = { "i2c6_grp" }; |
| 334 | static const char * const southwest_i2c_nfc_groups[] = { "i2c_nfc_grp" }; |
| 335 | static const char * const southwest_spi3_groups[] = { "spi3_grp" }; |
| 336 | |
| 337 | /* |
| 338 | * Only do pinmuxing for certain LPSS devices for now. Rest of the pins are |
| 339 | * enabled only as GPIOs. |
| 340 | */ |
Andy Shevchenko | 5458b7c | 2018-09-04 14:26:21 +0300 | [diff] [blame^] | 341 | static const struct intel_function southwest_functions[] = { |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 342 | FUNCTION("uart0", southwest_uart0_groups), |
| 343 | FUNCTION("uart1", southwest_uart1_groups), |
| 344 | FUNCTION("uart2", southwest_uart2_groups), |
| 345 | FUNCTION("hda", southwest_hda_groups), |
| 346 | FUNCTION("lpe", southwest_lpe_groups), |
| 347 | FUNCTION("i2c0", southwest_i2c0_groups), |
| 348 | FUNCTION("i2c1", southwest_i2c1_groups), |
| 349 | FUNCTION("i2c2", southwest_i2c2_groups), |
| 350 | FUNCTION("i2c3", southwest_i2c3_groups), |
| 351 | FUNCTION("i2c4", southwest_i2c4_groups), |
| 352 | FUNCTION("i2c5", southwest_i2c5_groups), |
| 353 | FUNCTION("i2c6", southwest_i2c6_groups), |
| 354 | FUNCTION("i2c_nfc", southwest_i2c_nfc_groups), |
| 355 | FUNCTION("spi3", southwest_spi3_groups), |
| 356 | }; |
| 357 | |
| 358 | static const struct chv_gpio_pinrange southwest_gpio_ranges[] = { |
| 359 | GPIO_PINRANGE(0, 7), |
| 360 | GPIO_PINRANGE(15, 22), |
| 361 | GPIO_PINRANGE(30, 37), |
| 362 | GPIO_PINRANGE(45, 52), |
| 363 | GPIO_PINRANGE(60, 67), |
| 364 | GPIO_PINRANGE(75, 82), |
| 365 | GPIO_PINRANGE(90, 97), |
| 366 | }; |
| 367 | |
| 368 | static const struct chv_community southwest_community = { |
| 369 | .uid = "1", |
| 370 | .pins = southwest_pins, |
| 371 | .npins = ARRAY_SIZE(southwest_pins), |
| 372 | .groups = southwest_groups, |
| 373 | .ngroups = ARRAY_SIZE(southwest_groups), |
| 374 | .functions = southwest_functions, |
| 375 | .nfunctions = ARRAY_SIZE(southwest_functions), |
| 376 | .gpio_ranges = southwest_gpio_ranges, |
| 377 | .ngpio_ranges = ARRAY_SIZE(southwest_gpio_ranges), |
Mika Westerberg | 47c950d | 2016-09-20 15:15:22 +0300 | [diff] [blame] | 378 | /* |
| 379 | * Southwest community can benerate GPIO interrupts only for the |
| 380 | * first 8 interrupts. The upper half (8-15) can only be used to |
| 381 | * trigger GPEs. |
| 382 | */ |
| 383 | .nirqs = 8, |
Hans de Goede | a0b0285 | 2017-03-23 14:23:25 +0100 | [diff] [blame] | 384 | .acpi_space_id = 0x91, |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 385 | }; |
| 386 | |
| 387 | static const struct pinctrl_pin_desc north_pins[] = { |
| 388 | PINCTRL_PIN(0, "GPIO_DFX_0"), |
| 389 | PINCTRL_PIN(1, "GPIO_DFX_3"), |
| 390 | PINCTRL_PIN(2, "GPIO_DFX_7"), |
| 391 | PINCTRL_PIN(3, "GPIO_DFX_1"), |
| 392 | PINCTRL_PIN(4, "GPIO_DFX_5"), |
| 393 | PINCTRL_PIN(5, "GPIO_DFX_4"), |
| 394 | PINCTRL_PIN(6, "GPIO_DFX_8"), |
| 395 | PINCTRL_PIN(7, "GPIO_DFX_2"), |
| 396 | PINCTRL_PIN(8, "GPIO_DFX_6"), |
| 397 | |
| 398 | PINCTRL_PIN(15, "GPIO_SUS0"), |
| 399 | PINCTRL_PIN(16, "SEC_GPIO_SUS10"), |
| 400 | PINCTRL_PIN(17, "GPIO_SUS3"), |
| 401 | PINCTRL_PIN(18, "GPIO_SUS7"), |
| 402 | PINCTRL_PIN(19, "GPIO_SUS1"), |
| 403 | PINCTRL_PIN(20, "GPIO_SUS5"), |
| 404 | PINCTRL_PIN(21, "SEC_GPIO_SUS11"), |
| 405 | PINCTRL_PIN(22, "GPIO_SUS4"), |
| 406 | PINCTRL_PIN(23, "SEC_GPIO_SUS8"), |
| 407 | PINCTRL_PIN(24, "GPIO_SUS2"), |
| 408 | PINCTRL_PIN(25, "GPIO_SUS6"), |
| 409 | PINCTRL_PIN(26, "CX_PREQ_B"), |
| 410 | PINCTRL_PIN(27, "SEC_GPIO_SUS9"), |
| 411 | |
| 412 | PINCTRL_PIN(30, "TRST_B"), |
| 413 | PINCTRL_PIN(31, "TCK"), |
| 414 | PINCTRL_PIN(32, "PROCHOT_B"), |
| 415 | PINCTRL_PIN(33, "SVIDO_DATA"), |
| 416 | PINCTRL_PIN(34, "TMS"), |
| 417 | PINCTRL_PIN(35, "CX_PRDY_B_2"), |
| 418 | PINCTRL_PIN(36, "TDO_2"), |
| 419 | PINCTRL_PIN(37, "CX_PRDY_B"), |
| 420 | PINCTRL_PIN(38, "SVIDO_ALERT_B"), |
| 421 | PINCTRL_PIN(39, "TDO"), |
| 422 | PINCTRL_PIN(40, "SVIDO_CLK"), |
| 423 | PINCTRL_PIN(41, "TDI"), |
| 424 | |
| 425 | PINCTRL_PIN(45, "GP_CAMERASB_05"), |
| 426 | PINCTRL_PIN(46, "GP_CAMERASB_02"), |
| 427 | PINCTRL_PIN(47, "GP_CAMERASB_08"), |
| 428 | PINCTRL_PIN(48, "GP_CAMERASB_00"), |
| 429 | PINCTRL_PIN(49, "GP_CAMERASB_06"), |
| 430 | PINCTRL_PIN(50, "GP_CAMERASB_10"), |
| 431 | PINCTRL_PIN(51, "GP_CAMERASB_03"), |
| 432 | PINCTRL_PIN(52, "GP_CAMERASB_09"), |
| 433 | PINCTRL_PIN(53, "GP_CAMERASB_01"), |
| 434 | PINCTRL_PIN(54, "GP_CAMERASB_07"), |
| 435 | PINCTRL_PIN(55, "GP_CAMERASB_11"), |
| 436 | PINCTRL_PIN(56, "GP_CAMERASB_04"), |
| 437 | |
| 438 | PINCTRL_PIN(60, "PANEL0_BKLTEN"), |
| 439 | PINCTRL_PIN(61, "HV_DDI0_HPD"), |
| 440 | PINCTRL_PIN(62, "HV_DDI2_DDC_SDA"), |
| 441 | PINCTRL_PIN(63, "PANEL1_BKLTCTL"), |
| 442 | PINCTRL_PIN(64, "HV_DDI1_HPD"), |
| 443 | PINCTRL_PIN(65, "PANEL0_BKLTCTL"), |
| 444 | PINCTRL_PIN(66, "HV_DDI0_DDC_SDA"), |
| 445 | PINCTRL_PIN(67, "HV_DDI2_DDC_SCL"), |
| 446 | PINCTRL_PIN(68, "HV_DDI2_HPD"), |
| 447 | PINCTRL_PIN(69, "PANEL1_VDDEN"), |
| 448 | PINCTRL_PIN(70, "PANEL1_BKLTEN"), |
| 449 | PINCTRL_PIN(71, "HV_DDI0_DDC_SCL"), |
| 450 | PINCTRL_PIN(72, "PANEL0_VDDEN"), |
| 451 | }; |
| 452 | |
| 453 | static const struct chv_gpio_pinrange north_gpio_ranges[] = { |
| 454 | GPIO_PINRANGE(0, 8), |
| 455 | GPIO_PINRANGE(15, 27), |
| 456 | GPIO_PINRANGE(30, 41), |
| 457 | GPIO_PINRANGE(45, 56), |
| 458 | GPIO_PINRANGE(60, 72), |
| 459 | }; |
| 460 | |
| 461 | static const struct chv_community north_community = { |
| 462 | .uid = "2", |
| 463 | .pins = north_pins, |
| 464 | .npins = ARRAY_SIZE(north_pins), |
| 465 | .gpio_ranges = north_gpio_ranges, |
| 466 | .ngpio_ranges = ARRAY_SIZE(north_gpio_ranges), |
Mika Westerberg | 47c950d | 2016-09-20 15:15:22 +0300 | [diff] [blame] | 467 | /* |
Chris Gorman | 505485a | 2017-09-26 12:27:40 -0400 | [diff] [blame] | 468 | * North community can generate GPIO interrupts only for the first |
Mika Westerberg | 47c950d | 2016-09-20 15:15:22 +0300 | [diff] [blame] | 469 | * 8 interrupts. The upper half (8-15) can only be used to trigger |
| 470 | * GPEs. |
| 471 | */ |
| 472 | .nirqs = 8, |
Hans de Goede | a0b0285 | 2017-03-23 14:23:25 +0100 | [diff] [blame] | 473 | .acpi_space_id = 0x92, |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 474 | }; |
| 475 | |
| 476 | static const struct pinctrl_pin_desc east_pins[] = { |
| 477 | PINCTRL_PIN(0, "PMU_SLP_S3_B"), |
| 478 | PINCTRL_PIN(1, "PMU_BATLOW_B"), |
| 479 | PINCTRL_PIN(2, "SUS_STAT_B"), |
| 480 | PINCTRL_PIN(3, "PMU_SLP_S0IX_B"), |
| 481 | PINCTRL_PIN(4, "PMU_AC_PRESENT"), |
| 482 | PINCTRL_PIN(5, "PMU_PLTRST_B"), |
| 483 | PINCTRL_PIN(6, "PMU_SUSCLK"), |
| 484 | PINCTRL_PIN(7, "PMU_SLP_LAN_B"), |
| 485 | PINCTRL_PIN(8, "PMU_PWRBTN_B"), |
| 486 | PINCTRL_PIN(9, "PMU_SLP_S4_B"), |
| 487 | PINCTRL_PIN(10, "PMU_WAKE_B"), |
| 488 | PINCTRL_PIN(11, "PMU_WAKE_LAN_B"), |
| 489 | |
| 490 | PINCTRL_PIN(15, "MF_ISH_GPIO_3"), |
| 491 | PINCTRL_PIN(16, "MF_ISH_GPIO_7"), |
| 492 | PINCTRL_PIN(17, "MF_ISH_I2C1_SCL"), |
| 493 | PINCTRL_PIN(18, "MF_ISH_GPIO_1"), |
| 494 | PINCTRL_PIN(19, "MF_ISH_GPIO_5"), |
| 495 | PINCTRL_PIN(20, "MF_ISH_GPIO_9"), |
| 496 | PINCTRL_PIN(21, "MF_ISH_GPIO_0"), |
| 497 | PINCTRL_PIN(22, "MF_ISH_GPIO_4"), |
| 498 | PINCTRL_PIN(23, "MF_ISH_GPIO_8"), |
| 499 | PINCTRL_PIN(24, "MF_ISH_GPIO_2"), |
| 500 | PINCTRL_PIN(25, "MF_ISH_GPIO_6"), |
| 501 | PINCTRL_PIN(26, "MF_ISH_I2C1_SDA"), |
| 502 | }; |
| 503 | |
| 504 | static const struct chv_gpio_pinrange east_gpio_ranges[] = { |
| 505 | GPIO_PINRANGE(0, 11), |
| 506 | GPIO_PINRANGE(15, 26), |
| 507 | }; |
| 508 | |
| 509 | static const struct chv_community east_community = { |
| 510 | .uid = "3", |
| 511 | .pins = east_pins, |
| 512 | .npins = ARRAY_SIZE(east_pins), |
| 513 | .gpio_ranges = east_gpio_ranges, |
| 514 | .ngpio_ranges = ARRAY_SIZE(east_gpio_ranges), |
Mika Westerberg | 47c950d | 2016-09-20 15:15:22 +0300 | [diff] [blame] | 515 | .nirqs = 16, |
Hans de Goede | a0b0285 | 2017-03-23 14:23:25 +0100 | [diff] [blame] | 516 | .acpi_space_id = 0x93, |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 517 | }; |
| 518 | |
| 519 | static const struct pinctrl_pin_desc southeast_pins[] = { |
| 520 | PINCTRL_PIN(0, "MF_PLT_CLK0"), |
| 521 | PINCTRL_PIN(1, "PWM1"), |
| 522 | PINCTRL_PIN(2, "MF_PLT_CLK1"), |
| 523 | PINCTRL_PIN(3, "MF_PLT_CLK4"), |
| 524 | PINCTRL_PIN(4, "MF_PLT_CLK3"), |
| 525 | PINCTRL_PIN(5, "PWM0"), |
| 526 | PINCTRL_PIN(6, "MF_PLT_CLK5"), |
| 527 | PINCTRL_PIN(7, "MF_PLT_CLK2"), |
| 528 | |
| 529 | PINCTRL_PIN(15, "SDMMC2_D3_CD_B"), |
| 530 | PINCTRL_PIN(16, "SDMMC1_CLK"), |
| 531 | PINCTRL_PIN(17, "SDMMC1_D0"), |
| 532 | PINCTRL_PIN(18, "SDMMC2_D1"), |
| 533 | PINCTRL_PIN(19, "SDMMC2_CLK"), |
| 534 | PINCTRL_PIN(20, "SDMMC1_D2"), |
| 535 | PINCTRL_PIN(21, "SDMMC2_D2"), |
| 536 | PINCTRL_PIN(22, "SDMMC2_CMD"), |
| 537 | PINCTRL_PIN(23, "SDMMC1_CMD"), |
| 538 | PINCTRL_PIN(24, "SDMMC1_D1"), |
| 539 | PINCTRL_PIN(25, "SDMMC2_D0"), |
| 540 | PINCTRL_PIN(26, "SDMMC1_D3_CD_B"), |
| 541 | |
| 542 | PINCTRL_PIN(30, "SDMMC3_D1"), |
| 543 | PINCTRL_PIN(31, "SDMMC3_CLK"), |
| 544 | PINCTRL_PIN(32, "SDMMC3_D3"), |
| 545 | PINCTRL_PIN(33, "SDMMC3_D2"), |
| 546 | PINCTRL_PIN(34, "SDMMC3_CMD"), |
| 547 | PINCTRL_PIN(35, "SDMMC3_D0"), |
| 548 | |
| 549 | PINCTRL_PIN(45, "MF_LPC_AD2"), |
| 550 | PINCTRL_PIN(46, "LPC_CLKRUNB"), |
| 551 | PINCTRL_PIN(47, "MF_LPC_AD0"), |
| 552 | PINCTRL_PIN(48, "LPC_FRAMEB"), |
| 553 | PINCTRL_PIN(49, "MF_LPC_CLKOUT1"), |
| 554 | PINCTRL_PIN(50, "MF_LPC_AD3"), |
| 555 | PINCTRL_PIN(51, "MF_LPC_CLKOUT0"), |
| 556 | PINCTRL_PIN(52, "MF_LPC_AD1"), |
| 557 | |
| 558 | PINCTRL_PIN(60, "SPI1_MISO"), |
| 559 | PINCTRL_PIN(61, "SPI1_CSO_B"), |
| 560 | PINCTRL_PIN(62, "SPI1_CLK"), |
| 561 | PINCTRL_PIN(63, "MMC1_D6"), |
| 562 | PINCTRL_PIN(64, "SPI1_MOSI"), |
| 563 | PINCTRL_PIN(65, "MMC1_D5"), |
| 564 | PINCTRL_PIN(66, "SPI1_CS1_B"), |
| 565 | PINCTRL_PIN(67, "MMC1_D4_SD_WE"), |
| 566 | PINCTRL_PIN(68, "MMC1_D7"), |
| 567 | PINCTRL_PIN(69, "MMC1_RCLK"), |
| 568 | |
| 569 | PINCTRL_PIN(75, "USB_OC1_B"), |
| 570 | PINCTRL_PIN(76, "PMU_RESETBUTTON_B"), |
| 571 | PINCTRL_PIN(77, "GPIO_ALERT"), |
| 572 | PINCTRL_PIN(78, "SDMMC3_PWR_EN_B"), |
| 573 | PINCTRL_PIN(79, "ILB_SERIRQ"), |
| 574 | PINCTRL_PIN(80, "USB_OC0_B"), |
| 575 | PINCTRL_PIN(81, "SDMMC3_CD_B"), |
| 576 | PINCTRL_PIN(82, "SPKR"), |
| 577 | PINCTRL_PIN(83, "SUSPWRDNACK"), |
| 578 | PINCTRL_PIN(84, "SPARE_PIN"), |
| 579 | PINCTRL_PIN(85, "SDMMC3_1P8_EN"), |
| 580 | }; |
| 581 | |
| 582 | static const unsigned southeast_pwm0_pins[] = { 5 }; |
| 583 | static const unsigned southeast_pwm1_pins[] = { 1 }; |
| 584 | static const unsigned southeast_sdmmc1_pins[] = { |
| 585 | 16, 17, 20, 23, 24, 26, 63, 65, 67, 68, 69, |
| 586 | }; |
| 587 | static const unsigned southeast_sdmmc2_pins[] = { 15, 18, 19, 21, 22, 25 }; |
| 588 | static const unsigned southeast_sdmmc3_pins[] = { |
| 589 | 30, 31, 32, 33, 34, 35, 78, 81, 85, |
| 590 | }; |
| 591 | static const unsigned southeast_spi1_pins[] = { 60, 61, 62, 64, 66 }; |
| 592 | static const unsigned southeast_spi2_pins[] = { 2, 3, 4, 6, 7 }; |
| 593 | |
| 594 | static const struct chv_pingroup southeast_groups[] = { |
Andy Shevchenko | 5458b7c | 2018-09-04 14:26:21 +0300 | [diff] [blame^] | 595 | PIN_GROUP_WITH_ALT("pwm0_grp", southeast_pwm0_pins, 1, false), |
| 596 | PIN_GROUP_WITH_ALT("pwm1_grp", southeast_pwm1_pins, 1, false), |
| 597 | PIN_GROUP_WITH_ALT("sdmmc1_grp", southeast_sdmmc1_pins, 1, false), |
| 598 | PIN_GROUP_WITH_ALT("sdmmc2_grp", southeast_sdmmc2_pins, 1, false), |
| 599 | PIN_GROUP_WITH_ALT("sdmmc3_grp", southeast_sdmmc3_pins, 1, false), |
| 600 | PIN_GROUP_WITH_ALT("spi1_grp", southeast_spi1_pins, 1, false), |
| 601 | PIN_GROUP_WITH_ALT("spi2_grp", southeast_spi2_pins, 4, false), |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 602 | }; |
| 603 | |
| 604 | static const char * const southeast_pwm0_groups[] = { "pwm0_grp" }; |
| 605 | static const char * const southeast_pwm1_groups[] = { "pwm1_grp" }; |
| 606 | static const char * const southeast_sdmmc1_groups[] = { "sdmmc1_grp" }; |
| 607 | static const char * const southeast_sdmmc2_groups[] = { "sdmmc2_grp" }; |
| 608 | static const char * const southeast_sdmmc3_groups[] = { "sdmmc3_grp" }; |
| 609 | static const char * const southeast_spi1_groups[] = { "spi1_grp" }; |
| 610 | static const char * const southeast_spi2_groups[] = { "spi2_grp" }; |
| 611 | |
Andy Shevchenko | 5458b7c | 2018-09-04 14:26:21 +0300 | [diff] [blame^] | 612 | static const struct intel_function southeast_functions[] = { |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 613 | FUNCTION("pwm0", southeast_pwm0_groups), |
| 614 | FUNCTION("pwm1", southeast_pwm1_groups), |
| 615 | FUNCTION("sdmmc1", southeast_sdmmc1_groups), |
| 616 | FUNCTION("sdmmc2", southeast_sdmmc2_groups), |
| 617 | FUNCTION("sdmmc3", southeast_sdmmc3_groups), |
| 618 | FUNCTION("spi1", southeast_spi1_groups), |
| 619 | FUNCTION("spi2", southeast_spi2_groups), |
| 620 | }; |
| 621 | |
| 622 | static const struct chv_gpio_pinrange southeast_gpio_ranges[] = { |
| 623 | GPIO_PINRANGE(0, 7), |
| 624 | GPIO_PINRANGE(15, 26), |
| 625 | GPIO_PINRANGE(30, 35), |
| 626 | GPIO_PINRANGE(45, 52), |
| 627 | GPIO_PINRANGE(60, 69), |
| 628 | GPIO_PINRANGE(75, 85), |
| 629 | }; |
| 630 | |
| 631 | static const struct chv_community southeast_community = { |
| 632 | .uid = "4", |
| 633 | .pins = southeast_pins, |
| 634 | .npins = ARRAY_SIZE(southeast_pins), |
| 635 | .groups = southeast_groups, |
| 636 | .ngroups = ARRAY_SIZE(southeast_groups), |
| 637 | .functions = southeast_functions, |
| 638 | .nfunctions = ARRAY_SIZE(southeast_functions), |
| 639 | .gpio_ranges = southeast_gpio_ranges, |
| 640 | .ngpio_ranges = ARRAY_SIZE(southeast_gpio_ranges), |
Mika Westerberg | 47c950d | 2016-09-20 15:15:22 +0300 | [diff] [blame] | 641 | .nirqs = 16, |
Hans de Goede | a0b0285 | 2017-03-23 14:23:25 +0100 | [diff] [blame] | 642 | .acpi_space_id = 0x94, |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 643 | }; |
| 644 | |
| 645 | static const struct chv_community *chv_communities[] = { |
| 646 | &southwest_community, |
| 647 | &north_community, |
| 648 | &east_community, |
| 649 | &southeast_community, |
| 650 | }; |
| 651 | |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 652 | /* |
| 653 | * Lock to serialize register accesses |
| 654 | * |
| 655 | * Due to a silicon issue, a shared lock must be used to prevent |
| 656 | * concurrent accesses across the 4 GPIO controllers. |
| 657 | * |
| 658 | * See Intel Atom Z8000 Processor Series Specification Update (Rev. 005), |
| 659 | * errata #CHT34, for further information. |
| 660 | */ |
| 661 | static DEFINE_RAW_SPINLOCK(chv_lock); |
| 662 | |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 663 | static void __iomem *chv_padreg(struct chv_pinctrl *pctrl, unsigned offset, |
| 664 | unsigned reg) |
| 665 | { |
| 666 | unsigned family_no = offset / MAX_FAMILY_PAD_GPIO_NO; |
| 667 | unsigned pad_no = offset % MAX_FAMILY_PAD_GPIO_NO; |
| 668 | |
| 669 | offset = FAMILY_PAD_REGS_OFF + FAMILY_PAD_REGS_SIZE * family_no + |
| 670 | GPIO_REGS_SIZE * pad_no; |
| 671 | |
| 672 | return pctrl->regs + offset + reg; |
| 673 | } |
| 674 | |
| 675 | static void chv_writel(u32 value, void __iomem *reg) |
| 676 | { |
| 677 | writel(value, reg); |
| 678 | /* simple readback to confirm the bus transferring done */ |
| 679 | readl(reg); |
| 680 | } |
| 681 | |
| 682 | /* When Pad Cfg is locked, driver can only change GPIOTXState or GPIORXState */ |
| 683 | static bool chv_pad_locked(struct chv_pinctrl *pctrl, unsigned offset) |
| 684 | { |
| 685 | void __iomem *reg; |
| 686 | |
| 687 | reg = chv_padreg(pctrl, offset, CHV_PADCTRL1); |
| 688 | return readl(reg) & CHV_PADCTRL1_CFGLOCK; |
| 689 | } |
| 690 | |
| 691 | static int chv_get_groups_count(struct pinctrl_dev *pctldev) |
| 692 | { |
| 693 | struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 694 | |
| 695 | return pctrl->community->ngroups; |
| 696 | } |
| 697 | |
| 698 | static const char *chv_get_group_name(struct pinctrl_dev *pctldev, |
| 699 | unsigned group) |
| 700 | { |
| 701 | struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 702 | |
| 703 | return pctrl->community->groups[group].name; |
| 704 | } |
| 705 | |
| 706 | static int chv_get_group_pins(struct pinctrl_dev *pctldev, unsigned group, |
| 707 | const unsigned **pins, unsigned *npins) |
| 708 | { |
| 709 | struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 710 | |
| 711 | *pins = pctrl->community->groups[group].pins; |
| 712 | *npins = pctrl->community->groups[group].npins; |
| 713 | return 0; |
| 714 | } |
| 715 | |
| 716 | static void chv_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s, |
| 717 | unsigned offset) |
| 718 | { |
| 719 | struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 720 | unsigned long flags; |
| 721 | u32 ctrl0, ctrl1; |
| 722 | bool locked; |
| 723 | |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 724 | raw_spin_lock_irqsave(&chv_lock, flags); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 725 | |
| 726 | ctrl0 = readl(chv_padreg(pctrl, offset, CHV_PADCTRL0)); |
| 727 | ctrl1 = readl(chv_padreg(pctrl, offset, CHV_PADCTRL1)); |
| 728 | locked = chv_pad_locked(pctrl, offset); |
| 729 | |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 730 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 731 | |
| 732 | if (ctrl0 & CHV_PADCTRL0_GPIOEN) { |
| 733 | seq_puts(s, "GPIO "); |
| 734 | } else { |
| 735 | u32 mode; |
| 736 | |
| 737 | mode = ctrl0 & CHV_PADCTRL0_PMODE_MASK; |
| 738 | mode >>= CHV_PADCTRL0_PMODE_SHIFT; |
| 739 | |
| 740 | seq_printf(s, "mode %d ", mode); |
| 741 | } |
| 742 | |
Mika Westerberg | 684373e | 2016-10-31 16:57:34 +0200 | [diff] [blame] | 743 | seq_printf(s, "0x%08x 0x%08x", ctrl0, ctrl1); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 744 | |
| 745 | if (locked) |
| 746 | seq_puts(s, " [LOCKED]"); |
| 747 | } |
| 748 | |
| 749 | static const struct pinctrl_ops chv_pinctrl_ops = { |
| 750 | .get_groups_count = chv_get_groups_count, |
| 751 | .get_group_name = chv_get_group_name, |
| 752 | .get_group_pins = chv_get_group_pins, |
| 753 | .pin_dbg_show = chv_pin_dbg_show, |
| 754 | }; |
| 755 | |
| 756 | static int chv_get_functions_count(struct pinctrl_dev *pctldev) |
| 757 | { |
| 758 | struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 759 | |
| 760 | return pctrl->community->nfunctions; |
| 761 | } |
| 762 | |
| 763 | static const char *chv_get_function_name(struct pinctrl_dev *pctldev, |
| 764 | unsigned function) |
| 765 | { |
| 766 | struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 767 | |
| 768 | return pctrl->community->functions[function].name; |
| 769 | } |
| 770 | |
| 771 | static int chv_get_function_groups(struct pinctrl_dev *pctldev, |
| 772 | unsigned function, |
| 773 | const char * const **groups, |
| 774 | unsigned * const ngroups) |
| 775 | { |
| 776 | struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 777 | |
| 778 | *groups = pctrl->community->functions[function].groups; |
| 779 | *ngroups = pctrl->community->functions[function].ngroups; |
| 780 | return 0; |
| 781 | } |
| 782 | |
| 783 | static int chv_pinmux_set_mux(struct pinctrl_dev *pctldev, unsigned function, |
| 784 | unsigned group) |
| 785 | { |
| 786 | struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 787 | const struct chv_pingroup *grp; |
| 788 | unsigned long flags; |
| 789 | int i; |
| 790 | |
| 791 | grp = &pctrl->community->groups[group]; |
| 792 | |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 793 | raw_spin_lock_irqsave(&chv_lock, flags); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 794 | |
| 795 | /* Check first that the pad is not locked */ |
| 796 | for (i = 0; i < grp->npins; i++) { |
| 797 | if (chv_pad_locked(pctrl, grp->pins[i])) { |
| 798 | dev_warn(pctrl->dev, "unable to set mode for locked pin %u\n", |
| 799 | grp->pins[i]); |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 800 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 801 | return -EBUSY; |
| 802 | } |
| 803 | } |
| 804 | |
| 805 | for (i = 0; i < grp->npins; i++) { |
| 806 | const struct chv_alternate_function *altfunc = &grp->altfunc; |
| 807 | int pin = grp->pins[i]; |
| 808 | void __iomem *reg; |
| 809 | u32 value; |
| 810 | |
| 811 | /* Check if there is pin-specific config */ |
| 812 | if (grp->overrides) { |
| 813 | int j; |
| 814 | |
| 815 | for (j = 0; j < grp->noverrides; j++) { |
| 816 | if (grp->overrides[j].pin == pin) { |
| 817 | altfunc = &grp->overrides[j]; |
| 818 | break; |
| 819 | } |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | reg = chv_padreg(pctrl, pin, CHV_PADCTRL0); |
| 824 | value = readl(reg); |
| 825 | /* Disable GPIO mode */ |
| 826 | value &= ~CHV_PADCTRL0_GPIOEN; |
| 827 | /* Set to desired mode */ |
| 828 | value &= ~CHV_PADCTRL0_PMODE_MASK; |
| 829 | value |= altfunc->mode << CHV_PADCTRL0_PMODE_SHIFT; |
| 830 | chv_writel(value, reg); |
| 831 | |
| 832 | /* Update for invert_oe */ |
| 833 | reg = chv_padreg(pctrl, pin, CHV_PADCTRL1); |
| 834 | value = readl(reg) & ~CHV_PADCTRL1_INVRXTX_MASK; |
| 835 | if (altfunc->invert_oe) |
| 836 | value |= CHV_PADCTRL1_INVRXTX_TXENABLE; |
| 837 | chv_writel(value, reg); |
| 838 | |
| 839 | dev_dbg(pctrl->dev, "configured pin %u mode %u OE %sinverted\n", |
| 840 | pin, altfunc->mode, altfunc->invert_oe ? "" : "not "); |
| 841 | } |
| 842 | |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 843 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 844 | |
| 845 | return 0; |
| 846 | } |
| 847 | |
| 848 | static int chv_gpio_request_enable(struct pinctrl_dev *pctldev, |
| 849 | struct pinctrl_gpio_range *range, |
| 850 | unsigned offset) |
| 851 | { |
| 852 | struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 853 | unsigned long flags; |
| 854 | void __iomem *reg; |
| 855 | u32 value; |
| 856 | |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 857 | raw_spin_lock_irqsave(&chv_lock, flags); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 858 | |
| 859 | if (chv_pad_locked(pctrl, offset)) { |
| 860 | value = readl(chv_padreg(pctrl, offset, CHV_PADCTRL0)); |
| 861 | if (!(value & CHV_PADCTRL0_GPIOEN)) { |
| 862 | /* Locked so cannot enable */ |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 863 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 864 | return -EBUSY; |
| 865 | } |
| 866 | } else { |
| 867 | int i; |
| 868 | |
| 869 | /* Reset the interrupt mapping */ |
| 870 | for (i = 0; i < ARRAY_SIZE(pctrl->intr_lines); i++) { |
| 871 | if (pctrl->intr_lines[i] == offset) { |
| 872 | pctrl->intr_lines[i] = 0; |
| 873 | break; |
| 874 | } |
| 875 | } |
| 876 | |
| 877 | /* Disable interrupt generation */ |
| 878 | reg = chv_padreg(pctrl, offset, CHV_PADCTRL1); |
| 879 | value = readl(reg); |
| 880 | value &= ~CHV_PADCTRL1_INTWAKECFG_MASK; |
| 881 | value &= ~CHV_PADCTRL1_INVRXTX_MASK; |
| 882 | chv_writel(value, reg); |
| 883 | |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 884 | reg = chv_padreg(pctrl, offset, CHV_PADCTRL0); |
Mika Westerberg | 2479c73 | 2015-01-29 12:44:48 +0200 | [diff] [blame] | 885 | value = readl(reg); |
| 886 | |
| 887 | /* |
| 888 | * If the pin is in HiZ mode (both TX and RX buffers are |
| 889 | * disabled) we turn it to be input now. |
| 890 | */ |
| 891 | if ((value & CHV_PADCTRL0_GPIOCFG_MASK) == |
| 892 | (CHV_PADCTRL0_GPIOCFG_HIZ << CHV_PADCTRL0_GPIOCFG_SHIFT)) { |
| 893 | value &= ~CHV_PADCTRL0_GPIOCFG_MASK; |
| 894 | value |= CHV_PADCTRL0_GPIOCFG_GPI << |
| 895 | CHV_PADCTRL0_GPIOCFG_SHIFT; |
| 896 | } |
| 897 | |
| 898 | /* Switch to a GPIO mode */ |
| 899 | value |= CHV_PADCTRL0_GPIOEN; |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 900 | chv_writel(value, reg); |
| 901 | } |
| 902 | |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 903 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 904 | |
| 905 | return 0; |
| 906 | } |
| 907 | |
| 908 | static void chv_gpio_disable_free(struct pinctrl_dev *pctldev, |
| 909 | struct pinctrl_gpio_range *range, |
| 910 | unsigned offset) |
| 911 | { |
| 912 | struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 913 | unsigned long flags; |
| 914 | void __iomem *reg; |
| 915 | u32 value; |
| 916 | |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 917 | raw_spin_lock_irqsave(&chv_lock, flags); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 918 | |
| 919 | reg = chv_padreg(pctrl, offset, CHV_PADCTRL0); |
| 920 | value = readl(reg) & ~CHV_PADCTRL0_GPIOEN; |
| 921 | chv_writel(value, reg); |
| 922 | |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 923 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | static int chv_gpio_set_direction(struct pinctrl_dev *pctldev, |
| 927 | struct pinctrl_gpio_range *range, |
| 928 | unsigned offset, bool input) |
| 929 | { |
| 930 | struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 931 | void __iomem *reg = chv_padreg(pctrl, offset, CHV_PADCTRL0); |
| 932 | unsigned long flags; |
| 933 | u32 ctrl0; |
| 934 | |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 935 | raw_spin_lock_irqsave(&chv_lock, flags); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 936 | |
| 937 | ctrl0 = readl(reg) & ~CHV_PADCTRL0_GPIOCFG_MASK; |
| 938 | if (input) |
| 939 | ctrl0 |= CHV_PADCTRL0_GPIOCFG_GPI << CHV_PADCTRL0_GPIOCFG_SHIFT; |
| 940 | else |
| 941 | ctrl0 |= CHV_PADCTRL0_GPIOCFG_GPO << CHV_PADCTRL0_GPIOCFG_SHIFT; |
| 942 | chv_writel(ctrl0, reg); |
| 943 | |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 944 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 945 | |
| 946 | return 0; |
| 947 | } |
| 948 | |
| 949 | static const struct pinmux_ops chv_pinmux_ops = { |
| 950 | .get_functions_count = chv_get_functions_count, |
| 951 | .get_function_name = chv_get_function_name, |
| 952 | .get_function_groups = chv_get_function_groups, |
| 953 | .set_mux = chv_pinmux_set_mux, |
| 954 | .gpio_request_enable = chv_gpio_request_enable, |
| 955 | .gpio_disable_free = chv_gpio_disable_free, |
| 956 | .gpio_set_direction = chv_gpio_set_direction, |
| 957 | }; |
| 958 | |
| 959 | static int chv_config_get(struct pinctrl_dev *pctldev, unsigned pin, |
| 960 | unsigned long *config) |
| 961 | { |
| 962 | struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 963 | enum pin_config_param param = pinconf_to_config_param(*config); |
| 964 | unsigned long flags; |
| 965 | u32 ctrl0, ctrl1; |
| 966 | u16 arg = 0; |
| 967 | u32 term; |
| 968 | |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 969 | raw_spin_lock_irqsave(&chv_lock, flags); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 970 | ctrl0 = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0)); |
| 971 | ctrl1 = readl(chv_padreg(pctrl, pin, CHV_PADCTRL1)); |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 972 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 973 | |
| 974 | term = (ctrl0 & CHV_PADCTRL0_TERM_MASK) >> CHV_PADCTRL0_TERM_SHIFT; |
| 975 | |
| 976 | switch (param) { |
| 977 | case PIN_CONFIG_BIAS_DISABLE: |
| 978 | if (term) |
| 979 | return -EINVAL; |
| 980 | break; |
| 981 | |
| 982 | case PIN_CONFIG_BIAS_PULL_UP: |
| 983 | if (!(ctrl0 & CHV_PADCTRL0_TERM_UP)) |
| 984 | return -EINVAL; |
| 985 | |
| 986 | switch (term) { |
| 987 | case CHV_PADCTRL0_TERM_20K: |
| 988 | arg = 20000; |
| 989 | break; |
| 990 | case CHV_PADCTRL0_TERM_5K: |
| 991 | arg = 5000; |
| 992 | break; |
| 993 | case CHV_PADCTRL0_TERM_1K: |
| 994 | arg = 1000; |
| 995 | break; |
| 996 | } |
| 997 | |
| 998 | break; |
| 999 | |
| 1000 | case PIN_CONFIG_BIAS_PULL_DOWN: |
| 1001 | if (!term || (ctrl0 & CHV_PADCTRL0_TERM_UP)) |
| 1002 | return -EINVAL; |
| 1003 | |
| 1004 | switch (term) { |
| 1005 | case CHV_PADCTRL0_TERM_20K: |
| 1006 | arg = 20000; |
| 1007 | break; |
| 1008 | case CHV_PADCTRL0_TERM_5K: |
| 1009 | arg = 5000; |
| 1010 | break; |
| 1011 | } |
| 1012 | |
| 1013 | break; |
| 1014 | |
| 1015 | case PIN_CONFIG_DRIVE_OPEN_DRAIN: |
| 1016 | if (!(ctrl1 & CHV_PADCTRL1_ODEN)) |
| 1017 | return -EINVAL; |
| 1018 | break; |
| 1019 | |
| 1020 | case PIN_CONFIG_BIAS_HIGH_IMPEDANCE: { |
| 1021 | u32 cfg; |
| 1022 | |
| 1023 | cfg = ctrl0 & CHV_PADCTRL0_GPIOCFG_MASK; |
| 1024 | cfg >>= CHV_PADCTRL0_GPIOCFG_SHIFT; |
| 1025 | if (cfg != CHV_PADCTRL0_GPIOCFG_HIZ) |
| 1026 | return -EINVAL; |
| 1027 | |
| 1028 | break; |
| 1029 | } |
| 1030 | |
| 1031 | default: |
| 1032 | return -ENOTSUPP; |
| 1033 | } |
| 1034 | |
| 1035 | *config = pinconf_to_config_packed(param, arg); |
| 1036 | return 0; |
| 1037 | } |
| 1038 | |
| 1039 | static int chv_config_set_pull(struct chv_pinctrl *pctrl, unsigned pin, |
Mika Westerberg | 58957d2 | 2017-01-23 15:34:32 +0300 | [diff] [blame] | 1040 | enum pin_config_param param, u32 arg) |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1041 | { |
| 1042 | void __iomem *reg = chv_padreg(pctrl, pin, CHV_PADCTRL0); |
| 1043 | unsigned long flags; |
| 1044 | u32 ctrl0, pull; |
| 1045 | |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 1046 | raw_spin_lock_irqsave(&chv_lock, flags); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1047 | ctrl0 = readl(reg); |
| 1048 | |
| 1049 | switch (param) { |
| 1050 | case PIN_CONFIG_BIAS_DISABLE: |
| 1051 | ctrl0 &= ~(CHV_PADCTRL0_TERM_MASK | CHV_PADCTRL0_TERM_UP); |
| 1052 | break; |
| 1053 | |
| 1054 | case PIN_CONFIG_BIAS_PULL_UP: |
| 1055 | ctrl0 &= ~(CHV_PADCTRL0_TERM_MASK | CHV_PADCTRL0_TERM_UP); |
| 1056 | |
| 1057 | switch (arg) { |
| 1058 | case 1000: |
| 1059 | /* For 1k there is only pull up */ |
| 1060 | pull = CHV_PADCTRL0_TERM_1K << CHV_PADCTRL0_TERM_SHIFT; |
| 1061 | break; |
| 1062 | case 5000: |
| 1063 | pull = CHV_PADCTRL0_TERM_5K << CHV_PADCTRL0_TERM_SHIFT; |
| 1064 | break; |
| 1065 | case 20000: |
| 1066 | pull = CHV_PADCTRL0_TERM_20K << CHV_PADCTRL0_TERM_SHIFT; |
| 1067 | break; |
| 1068 | default: |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 1069 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1070 | return -EINVAL; |
| 1071 | } |
| 1072 | |
| 1073 | ctrl0 |= CHV_PADCTRL0_TERM_UP | pull; |
| 1074 | break; |
| 1075 | |
| 1076 | case PIN_CONFIG_BIAS_PULL_DOWN: |
| 1077 | ctrl0 &= ~(CHV_PADCTRL0_TERM_MASK | CHV_PADCTRL0_TERM_UP); |
| 1078 | |
| 1079 | switch (arg) { |
| 1080 | case 5000: |
| 1081 | pull = CHV_PADCTRL0_TERM_5K << CHV_PADCTRL0_TERM_SHIFT; |
| 1082 | break; |
| 1083 | case 20000: |
| 1084 | pull = CHV_PADCTRL0_TERM_20K << CHV_PADCTRL0_TERM_SHIFT; |
| 1085 | break; |
| 1086 | default: |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 1087 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1088 | return -EINVAL; |
| 1089 | } |
| 1090 | |
| 1091 | ctrl0 |= pull; |
| 1092 | break; |
| 1093 | |
| 1094 | default: |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 1095 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1096 | return -EINVAL; |
| 1097 | } |
| 1098 | |
| 1099 | chv_writel(ctrl0, reg); |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 1100 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1101 | |
| 1102 | return 0; |
| 1103 | } |
| 1104 | |
Dan O'Donovan | ccdf81d | 2016-06-10 13:23:35 +0100 | [diff] [blame] | 1105 | static int chv_config_set_oden(struct chv_pinctrl *pctrl, unsigned int pin, |
| 1106 | bool enable) |
| 1107 | { |
| 1108 | void __iomem *reg = chv_padreg(pctrl, pin, CHV_PADCTRL1); |
| 1109 | unsigned long flags; |
| 1110 | u32 ctrl1; |
| 1111 | |
| 1112 | raw_spin_lock_irqsave(&chv_lock, flags); |
| 1113 | ctrl1 = readl(reg); |
| 1114 | |
| 1115 | if (enable) |
| 1116 | ctrl1 |= CHV_PADCTRL1_ODEN; |
| 1117 | else |
| 1118 | ctrl1 &= ~CHV_PADCTRL1_ODEN; |
| 1119 | |
| 1120 | chv_writel(ctrl1, reg); |
| 1121 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
| 1122 | |
| 1123 | return 0; |
| 1124 | } |
| 1125 | |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1126 | static int chv_config_set(struct pinctrl_dev *pctldev, unsigned pin, |
| 1127 | unsigned long *configs, unsigned nconfigs) |
| 1128 | { |
| 1129 | struct chv_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 1130 | enum pin_config_param param; |
| 1131 | int i, ret; |
Mika Westerberg | 58957d2 | 2017-01-23 15:34:32 +0300 | [diff] [blame] | 1132 | u32 arg; |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1133 | |
| 1134 | if (chv_pad_locked(pctrl, pin)) |
| 1135 | return -EBUSY; |
| 1136 | |
| 1137 | for (i = 0; i < nconfigs; i++) { |
| 1138 | param = pinconf_to_config_param(configs[i]); |
| 1139 | arg = pinconf_to_config_argument(configs[i]); |
| 1140 | |
| 1141 | switch (param) { |
| 1142 | case PIN_CONFIG_BIAS_DISABLE: |
| 1143 | case PIN_CONFIG_BIAS_PULL_UP: |
| 1144 | case PIN_CONFIG_BIAS_PULL_DOWN: |
| 1145 | ret = chv_config_set_pull(pctrl, pin, param, arg); |
| 1146 | if (ret) |
| 1147 | return ret; |
| 1148 | break; |
| 1149 | |
Dan O'Donovan | ccdf81d | 2016-06-10 13:23:35 +0100 | [diff] [blame] | 1150 | case PIN_CONFIG_DRIVE_PUSH_PULL: |
| 1151 | ret = chv_config_set_oden(pctrl, pin, false); |
| 1152 | if (ret) |
| 1153 | return ret; |
| 1154 | break; |
| 1155 | |
| 1156 | case PIN_CONFIG_DRIVE_OPEN_DRAIN: |
| 1157 | ret = chv_config_set_oden(pctrl, pin, true); |
| 1158 | if (ret) |
| 1159 | return ret; |
| 1160 | break; |
| 1161 | |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1162 | default: |
| 1163 | return -ENOTSUPP; |
| 1164 | } |
| 1165 | |
| 1166 | dev_dbg(pctrl->dev, "pin %d set config %d arg %u\n", pin, |
| 1167 | param, arg); |
| 1168 | } |
| 1169 | |
| 1170 | return 0; |
| 1171 | } |
| 1172 | |
Dan O'Donovan | 77401d7 | 2016-06-10 13:23:36 +0100 | [diff] [blame] | 1173 | static int chv_config_group_get(struct pinctrl_dev *pctldev, |
| 1174 | unsigned int group, |
| 1175 | unsigned long *config) |
| 1176 | { |
| 1177 | const unsigned int *pins; |
| 1178 | unsigned int npins; |
| 1179 | int ret; |
| 1180 | |
| 1181 | ret = chv_get_group_pins(pctldev, group, &pins, &npins); |
| 1182 | if (ret) |
| 1183 | return ret; |
| 1184 | |
| 1185 | ret = chv_config_get(pctldev, pins[0], config); |
| 1186 | if (ret) |
| 1187 | return ret; |
| 1188 | |
| 1189 | return 0; |
| 1190 | } |
| 1191 | |
| 1192 | static int chv_config_group_set(struct pinctrl_dev *pctldev, |
| 1193 | unsigned int group, unsigned long *configs, |
| 1194 | unsigned int num_configs) |
| 1195 | { |
| 1196 | const unsigned int *pins; |
| 1197 | unsigned int npins; |
| 1198 | int i, ret; |
| 1199 | |
| 1200 | ret = chv_get_group_pins(pctldev, group, &pins, &npins); |
| 1201 | if (ret) |
| 1202 | return ret; |
| 1203 | |
| 1204 | for (i = 0; i < npins; i++) { |
| 1205 | ret = chv_config_set(pctldev, pins[i], configs, num_configs); |
| 1206 | if (ret) |
| 1207 | return ret; |
| 1208 | } |
| 1209 | |
| 1210 | return 0; |
| 1211 | } |
| 1212 | |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1213 | static const struct pinconf_ops chv_pinconf_ops = { |
| 1214 | .is_generic = true, |
| 1215 | .pin_config_set = chv_config_set, |
| 1216 | .pin_config_get = chv_config_get, |
Dan O'Donovan | 77401d7 | 2016-06-10 13:23:36 +0100 | [diff] [blame] | 1217 | .pin_config_group_get = chv_config_group_get, |
| 1218 | .pin_config_group_set = chv_config_group_set, |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1219 | }; |
| 1220 | |
| 1221 | static struct pinctrl_desc chv_pinctrl_desc = { |
| 1222 | .pctlops = &chv_pinctrl_ops, |
| 1223 | .pmxops = &chv_pinmux_ops, |
| 1224 | .confops = &chv_pinconf_ops, |
| 1225 | .owner = THIS_MODULE, |
| 1226 | }; |
| 1227 | |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1228 | static int chv_gpio_get(struct gpio_chip *chip, unsigned offset) |
| 1229 | { |
Linus Walleij | 0587d3d | 2015-12-08 00:16:03 +0100 | [diff] [blame] | 1230 | struct chv_pinctrl *pctrl = gpiochip_get_data(chip); |
Mika Westerberg | 4585b00 | 2015-08-03 12:46:38 +0300 | [diff] [blame] | 1231 | unsigned long flags; |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1232 | u32 ctrl0, cfg; |
| 1233 | |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 1234 | raw_spin_lock_irqsave(&chv_lock, flags); |
Mika Westerberg | 03c4749 | 2017-11-27 16:54:42 +0300 | [diff] [blame] | 1235 | ctrl0 = readl(chv_padreg(pctrl, offset, CHV_PADCTRL0)); |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 1236 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1237 | |
| 1238 | cfg = ctrl0 & CHV_PADCTRL0_GPIOCFG_MASK; |
| 1239 | cfg >>= CHV_PADCTRL0_GPIOCFG_SHIFT; |
| 1240 | |
| 1241 | if (cfg == CHV_PADCTRL0_GPIOCFG_GPO) |
| 1242 | return !!(ctrl0 & CHV_PADCTRL0_GPIOTXSTATE); |
| 1243 | return !!(ctrl0 & CHV_PADCTRL0_GPIORXSTATE); |
| 1244 | } |
| 1245 | |
| 1246 | static void chv_gpio_set(struct gpio_chip *chip, unsigned offset, int value) |
| 1247 | { |
Linus Walleij | 0587d3d | 2015-12-08 00:16:03 +0100 | [diff] [blame] | 1248 | struct chv_pinctrl *pctrl = gpiochip_get_data(chip); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1249 | unsigned long flags; |
| 1250 | void __iomem *reg; |
| 1251 | u32 ctrl0; |
| 1252 | |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 1253 | raw_spin_lock_irqsave(&chv_lock, flags); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1254 | |
Mika Westerberg | 03c4749 | 2017-11-27 16:54:42 +0300 | [diff] [blame] | 1255 | reg = chv_padreg(pctrl, offset, CHV_PADCTRL0); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1256 | ctrl0 = readl(reg); |
| 1257 | |
| 1258 | if (value) |
| 1259 | ctrl0 |= CHV_PADCTRL0_GPIOTXSTATE; |
| 1260 | else |
| 1261 | ctrl0 &= ~CHV_PADCTRL0_GPIOTXSTATE; |
| 1262 | |
| 1263 | chv_writel(ctrl0, reg); |
| 1264 | |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 1265 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1266 | } |
| 1267 | |
| 1268 | static int chv_gpio_get_direction(struct gpio_chip *chip, unsigned offset) |
| 1269 | { |
Linus Walleij | 0587d3d | 2015-12-08 00:16:03 +0100 | [diff] [blame] | 1270 | struct chv_pinctrl *pctrl = gpiochip_get_data(chip); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1271 | u32 ctrl0, direction; |
Mika Westerberg | 4585b00 | 2015-08-03 12:46:38 +0300 | [diff] [blame] | 1272 | unsigned long flags; |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1273 | |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 1274 | raw_spin_lock_irqsave(&chv_lock, flags); |
Mika Westerberg | 03c4749 | 2017-11-27 16:54:42 +0300 | [diff] [blame] | 1275 | ctrl0 = readl(chv_padreg(pctrl, offset, CHV_PADCTRL0)); |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 1276 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1277 | |
| 1278 | direction = ctrl0 & CHV_PADCTRL0_GPIOCFG_MASK; |
| 1279 | direction >>= CHV_PADCTRL0_GPIOCFG_SHIFT; |
| 1280 | |
| 1281 | return direction != CHV_PADCTRL0_GPIOCFG_GPO; |
| 1282 | } |
| 1283 | |
| 1284 | static int chv_gpio_direction_input(struct gpio_chip *chip, unsigned offset) |
| 1285 | { |
| 1286 | return pinctrl_gpio_direction_input(chip->base + offset); |
| 1287 | } |
| 1288 | |
| 1289 | static int chv_gpio_direction_output(struct gpio_chip *chip, unsigned offset, |
| 1290 | int value) |
| 1291 | { |
qipeng.zha | 549e783 | 2015-03-03 18:13:22 +0800 | [diff] [blame] | 1292 | chv_gpio_set(chip, offset, value); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1293 | return pinctrl_gpio_direction_output(chip->base + offset); |
| 1294 | } |
| 1295 | |
| 1296 | static const struct gpio_chip chv_gpio_chip = { |
| 1297 | .owner = THIS_MODULE, |
Jonas Gorski | 98c85d5 | 2015-10-11 17:34:19 +0200 | [diff] [blame] | 1298 | .request = gpiochip_generic_request, |
| 1299 | .free = gpiochip_generic_free, |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1300 | .get_direction = chv_gpio_get_direction, |
| 1301 | .direction_input = chv_gpio_direction_input, |
| 1302 | .direction_output = chv_gpio_direction_output, |
| 1303 | .get = chv_gpio_get, |
| 1304 | .set = chv_gpio_set, |
| 1305 | }; |
| 1306 | |
| 1307 | static void chv_gpio_irq_ack(struct irq_data *d) |
| 1308 | { |
| 1309 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
Linus Walleij | 0587d3d | 2015-12-08 00:16:03 +0100 | [diff] [blame] | 1310 | struct chv_pinctrl *pctrl = gpiochip_get_data(gc); |
Mika Westerberg | 03c4749 | 2017-11-27 16:54:42 +0300 | [diff] [blame] | 1311 | int pin = irqd_to_hwirq(d); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1312 | u32 intr_line; |
| 1313 | |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 1314 | raw_spin_lock(&chv_lock); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1315 | |
| 1316 | intr_line = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0)); |
| 1317 | intr_line &= CHV_PADCTRL0_INTSEL_MASK; |
| 1318 | intr_line >>= CHV_PADCTRL0_INTSEL_SHIFT; |
| 1319 | chv_writel(BIT(intr_line), pctrl->regs + CHV_INTSTAT); |
| 1320 | |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 1321 | raw_spin_unlock(&chv_lock); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | static void chv_gpio_irq_mask_unmask(struct irq_data *d, bool mask) |
| 1325 | { |
| 1326 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
Linus Walleij | 0587d3d | 2015-12-08 00:16:03 +0100 | [diff] [blame] | 1327 | struct chv_pinctrl *pctrl = gpiochip_get_data(gc); |
Mika Westerberg | 03c4749 | 2017-11-27 16:54:42 +0300 | [diff] [blame] | 1328 | int pin = irqd_to_hwirq(d); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1329 | u32 value, intr_line; |
| 1330 | unsigned long flags; |
| 1331 | |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 1332 | raw_spin_lock_irqsave(&chv_lock, flags); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1333 | |
| 1334 | intr_line = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0)); |
| 1335 | intr_line &= CHV_PADCTRL0_INTSEL_MASK; |
| 1336 | intr_line >>= CHV_PADCTRL0_INTSEL_SHIFT; |
| 1337 | |
| 1338 | value = readl(pctrl->regs + CHV_INTMASK); |
| 1339 | if (mask) |
| 1340 | value &= ~BIT(intr_line); |
| 1341 | else |
| 1342 | value |= BIT(intr_line); |
| 1343 | chv_writel(value, pctrl->regs + CHV_INTMASK); |
| 1344 | |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 1345 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | static void chv_gpio_irq_mask(struct irq_data *d) |
| 1349 | { |
| 1350 | chv_gpio_irq_mask_unmask(d, true); |
| 1351 | } |
| 1352 | |
| 1353 | static void chv_gpio_irq_unmask(struct irq_data *d) |
| 1354 | { |
| 1355 | chv_gpio_irq_mask_unmask(d, false); |
| 1356 | } |
| 1357 | |
Mika Westerberg | e6c906d | 2015-05-12 13:35:37 +0300 | [diff] [blame] | 1358 | static unsigned chv_gpio_irq_startup(struct irq_data *d) |
| 1359 | { |
| 1360 | /* |
| 1361 | * Check if the interrupt has been requested with 0 as triggering |
| 1362 | * type. In that case it is assumed that the current values |
| 1363 | * programmed to the hardware are used (e.g BIOS configured |
| 1364 | * defaults). |
| 1365 | * |
| 1366 | * In that case ->irq_set_type() will never be called so we need to |
| 1367 | * read back the values from hardware now, set correct flow handler |
| 1368 | * and update mappings before the interrupt is being used. |
| 1369 | */ |
| 1370 | if (irqd_get_trigger_type(d) == IRQ_TYPE_NONE) { |
| 1371 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
Linus Walleij | 0587d3d | 2015-12-08 00:16:03 +0100 | [diff] [blame] | 1372 | struct chv_pinctrl *pctrl = gpiochip_get_data(gc); |
Mika Westerberg | 03c4749 | 2017-11-27 16:54:42 +0300 | [diff] [blame] | 1373 | unsigned pin = irqd_to_hwirq(d); |
Mika Westerberg | e6c906d | 2015-05-12 13:35:37 +0300 | [diff] [blame] | 1374 | irq_flow_handler_t handler; |
| 1375 | unsigned long flags; |
| 1376 | u32 intsel, value; |
| 1377 | |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 1378 | raw_spin_lock_irqsave(&chv_lock, flags); |
Mika Westerberg | e6c906d | 2015-05-12 13:35:37 +0300 | [diff] [blame] | 1379 | intsel = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0)); |
| 1380 | intsel &= CHV_PADCTRL0_INTSEL_MASK; |
| 1381 | intsel >>= CHV_PADCTRL0_INTSEL_SHIFT; |
| 1382 | |
| 1383 | value = readl(chv_padreg(pctrl, pin, CHV_PADCTRL1)); |
| 1384 | if (value & CHV_PADCTRL1_INTWAKECFG_LEVEL) |
| 1385 | handler = handle_level_irq; |
| 1386 | else |
| 1387 | handler = handle_edge_irq; |
| 1388 | |
Mika Westerberg | e6c906d | 2015-05-12 13:35:37 +0300 | [diff] [blame] | 1389 | if (!pctrl->intr_lines[intsel]) { |
Thomas Gleixner | a4e3f78 | 2015-06-23 15:52:44 +0200 | [diff] [blame] | 1390 | irq_set_handler_locked(d, handler); |
Mika Westerberg | 03c4749 | 2017-11-27 16:54:42 +0300 | [diff] [blame] | 1391 | pctrl->intr_lines[intsel] = pin; |
Mika Westerberg | e6c906d | 2015-05-12 13:35:37 +0300 | [diff] [blame] | 1392 | } |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 1393 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
Mika Westerberg | e6c906d | 2015-05-12 13:35:37 +0300 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | chv_gpio_irq_unmask(d); |
| 1397 | return 0; |
| 1398 | } |
| 1399 | |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1400 | static int chv_gpio_irq_type(struct irq_data *d, unsigned type) |
| 1401 | { |
| 1402 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
Linus Walleij | 0587d3d | 2015-12-08 00:16:03 +0100 | [diff] [blame] | 1403 | struct chv_pinctrl *pctrl = gpiochip_get_data(gc); |
Mika Westerberg | 03c4749 | 2017-11-27 16:54:42 +0300 | [diff] [blame] | 1404 | unsigned pin = irqd_to_hwirq(d); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1405 | unsigned long flags; |
| 1406 | u32 value; |
| 1407 | |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 1408 | raw_spin_lock_irqsave(&chv_lock, flags); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1409 | |
| 1410 | /* |
| 1411 | * Pins which can be used as shared interrupt are configured in |
| 1412 | * BIOS. Driver trusts BIOS configurations and assigns different |
| 1413 | * handler according to the irq type. |
| 1414 | * |
| 1415 | * Driver needs to save the mapping between each pin and |
| 1416 | * its interrupt line. |
| 1417 | * 1. If the pin cfg is locked in BIOS: |
| 1418 | * Trust BIOS has programmed IntWakeCfg bits correctly, |
| 1419 | * driver just needs to save the mapping. |
| 1420 | * 2. If the pin cfg is not locked in BIOS: |
| 1421 | * Driver programs the IntWakeCfg bits and save the mapping. |
| 1422 | */ |
| 1423 | if (!chv_pad_locked(pctrl, pin)) { |
| 1424 | void __iomem *reg = chv_padreg(pctrl, pin, CHV_PADCTRL1); |
| 1425 | |
| 1426 | value = readl(reg); |
| 1427 | value &= ~CHV_PADCTRL1_INTWAKECFG_MASK; |
| 1428 | value &= ~CHV_PADCTRL1_INVRXTX_MASK; |
| 1429 | |
| 1430 | if (type & IRQ_TYPE_EDGE_BOTH) { |
| 1431 | if ((type & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH) |
| 1432 | value |= CHV_PADCTRL1_INTWAKECFG_BOTH; |
| 1433 | else if (type & IRQ_TYPE_EDGE_RISING) |
| 1434 | value |= CHV_PADCTRL1_INTWAKECFG_RISING; |
| 1435 | else if (type & IRQ_TYPE_EDGE_FALLING) |
| 1436 | value |= CHV_PADCTRL1_INTWAKECFG_FALLING; |
| 1437 | } else if (type & IRQ_TYPE_LEVEL_MASK) { |
| 1438 | value |= CHV_PADCTRL1_INTWAKECFG_LEVEL; |
| 1439 | if (type & IRQ_TYPE_LEVEL_LOW) |
| 1440 | value |= CHV_PADCTRL1_INVRXTX_RXDATA; |
| 1441 | } |
| 1442 | |
| 1443 | chv_writel(value, reg); |
| 1444 | } |
| 1445 | |
| 1446 | value = readl(chv_padreg(pctrl, pin, CHV_PADCTRL0)); |
| 1447 | value &= CHV_PADCTRL0_INTSEL_MASK; |
| 1448 | value >>= CHV_PADCTRL0_INTSEL_SHIFT; |
| 1449 | |
Mika Westerberg | 03c4749 | 2017-11-27 16:54:42 +0300 | [diff] [blame] | 1450 | pctrl->intr_lines[value] = pin; |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1451 | |
| 1452 | if (type & IRQ_TYPE_EDGE_BOTH) |
Thomas Gleixner | a4e3f78 | 2015-06-23 15:52:44 +0200 | [diff] [blame] | 1453 | irq_set_handler_locked(d, handle_edge_irq); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1454 | else if (type & IRQ_TYPE_LEVEL_MASK) |
Thomas Gleixner | a4e3f78 | 2015-06-23 15:52:44 +0200 | [diff] [blame] | 1455 | irq_set_handler_locked(d, handle_level_irq); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1456 | |
Dan O'Donovan | 0bd50d719 | 2016-06-10 13:23:34 +0100 | [diff] [blame] | 1457 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1458 | |
| 1459 | return 0; |
| 1460 | } |
| 1461 | |
| 1462 | static struct irq_chip chv_gpio_irqchip = { |
| 1463 | .name = "chv-gpio", |
Mika Westerberg | e6c906d | 2015-05-12 13:35:37 +0300 | [diff] [blame] | 1464 | .irq_startup = chv_gpio_irq_startup, |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1465 | .irq_ack = chv_gpio_irq_ack, |
| 1466 | .irq_mask = chv_gpio_irq_mask, |
| 1467 | .irq_unmask = chv_gpio_irq_unmask, |
| 1468 | .irq_set_type = chv_gpio_irq_type, |
| 1469 | .flags = IRQCHIP_SKIP_SET_WAKE, |
| 1470 | }; |
| 1471 | |
Thomas Gleixner | bd0b9ac | 2015-09-14 10:42:37 +0200 | [diff] [blame] | 1472 | static void chv_gpio_irq_handler(struct irq_desc *desc) |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1473 | { |
| 1474 | struct gpio_chip *gc = irq_desc_get_handler_data(desc); |
Linus Walleij | 0587d3d | 2015-12-08 00:16:03 +0100 | [diff] [blame] | 1475 | struct chv_pinctrl *pctrl = gpiochip_get_data(gc); |
Jiang Liu | 5663bb2 | 2015-06-04 12:13:16 +0800 | [diff] [blame] | 1476 | struct irq_chip *chip = irq_desc_get_chip(desc); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1477 | unsigned long pending; |
| 1478 | u32 intr_line; |
| 1479 | |
| 1480 | chained_irq_enter(chip, desc); |
| 1481 | |
| 1482 | pending = readl(pctrl->regs + CHV_INTSTAT); |
Mika Westerberg | 47c950d | 2016-09-20 15:15:22 +0300 | [diff] [blame] | 1483 | for_each_set_bit(intr_line, &pending, pctrl->community->nirqs) { |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1484 | unsigned irq, offset; |
| 1485 | |
| 1486 | offset = pctrl->intr_lines[intr_line]; |
Thierry Reding | f0fbe7b | 2017-11-07 19:15:47 +0100 | [diff] [blame] | 1487 | irq = irq_find_mapping(gc->irq.domain, offset); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1488 | generic_handle_irq(irq); |
| 1489 | } |
| 1490 | |
| 1491 | chained_irq_exit(chip, desc); |
| 1492 | } |
| 1493 | |
Mika Westerberg | 7036502 | 2017-04-10 13:16:33 +0300 | [diff] [blame] | 1494 | /* |
| 1495 | * Certain machines seem to hardcode Linux IRQ numbers in their ACPI |
| 1496 | * tables. Since we leave GPIOs that are not capable of generating |
| 1497 | * interrupts out of the irqdomain the numbering will be different and |
| 1498 | * cause devices using the hardcoded IRQ numbers fail. In order not to |
| 1499 | * break such machines we will only mask pins from irqdomain if the machine |
| 1500 | * is not listed below. |
| 1501 | */ |
| 1502 | static const struct dmi_system_id chv_no_valid_mask[] = { |
Mika Westerberg | 2a8209f | 2017-05-17 13:25:14 +0300 | [diff] [blame] | 1503 | /* See https://bugzilla.kernel.org/show_bug.cgi?id=194945 */ |
Mika Westerberg | 7036502 | 2017-04-10 13:16:33 +0300 | [diff] [blame] | 1504 | { |
Mika Westerberg | 2a8209f | 2017-05-17 13:25:14 +0300 | [diff] [blame] | 1505 | .ident = "Intel_Strago based Chromebooks (All models)", |
Mika Westerberg | 7036502 | 2017-04-10 13:16:33 +0300 | [diff] [blame] | 1506 | .matches = { |
| 1507 | DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"), |
Mika Westerberg | 2a8209f | 2017-05-17 13:25:14 +0300 | [diff] [blame] | 1508 | DMI_MATCH(DMI_PRODUCT_FAMILY, "Intel_Strago"), |
Dmitry Torokhov | 86c5dd6 | 2018-05-22 13:47:53 -0700 | [diff] [blame] | 1509 | DMI_MATCH(DMI_BOARD_VERSION, "1.0"), |
Mika Westerberg | 2a8209f | 2017-05-17 13:25:14 +0300 | [diff] [blame] | 1510 | }, |
| 1511 | }, |
| 1512 | { |
Andy Shevchenko | 2d80bd3 | 2017-07-04 15:58:39 +0300 | [diff] [blame] | 1513 | .ident = "HP Chromebook 11 G5 (Setzer)", |
| 1514 | .matches = { |
| 1515 | DMI_MATCH(DMI_SYS_VENDOR, "HP"), |
| 1516 | DMI_MATCH(DMI_PRODUCT_NAME, "Setzer"), |
Dmitry Torokhov | 86c5dd6 | 2018-05-22 13:47:53 -0700 | [diff] [blame] | 1517 | DMI_MATCH(DMI_BOARD_VERSION, "1.0"), |
Andy Shevchenko | 2d80bd3 | 2017-07-04 15:58:39 +0300 | [diff] [blame] | 1518 | }, |
| 1519 | }, |
| 1520 | { |
Mika Westerberg | 2a8209f | 2017-05-17 13:25:14 +0300 | [diff] [blame] | 1521 | .ident = "Acer Chromebook R11 (Cyan)", |
| 1522 | .matches = { |
| 1523 | DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"), |
| 1524 | DMI_MATCH(DMI_PRODUCT_NAME, "Cyan"), |
Dmitry Torokhov | 86c5dd6 | 2018-05-22 13:47:53 -0700 | [diff] [blame] | 1525 | DMI_MATCH(DMI_BOARD_VERSION, "1.0"), |
Mika Westerberg | 2a8209f | 2017-05-17 13:25:14 +0300 | [diff] [blame] | 1526 | }, |
| 1527 | }, |
| 1528 | { |
| 1529 | .ident = "Samsung Chromebook 3 (Celes)", |
| 1530 | .matches = { |
| 1531 | DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"), |
| 1532 | DMI_MATCH(DMI_PRODUCT_NAME, "Celes"), |
Dmitry Torokhov | 86c5dd6 | 2018-05-22 13:47:53 -0700 | [diff] [blame] | 1533 | DMI_MATCH(DMI_BOARD_VERSION, "1.0"), |
Mika Westerberg | 7036502 | 2017-04-10 13:16:33 +0300 | [diff] [blame] | 1534 | }, |
Wei Yongjun | a9de080 | 2017-04-25 06:22:05 +0000 | [diff] [blame] | 1535 | }, |
| 1536 | {} |
Mika Westerberg | 7036502 | 2017-04-10 13:16:33 +0300 | [diff] [blame] | 1537 | }; |
| 1538 | |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1539 | static int chv_gpio_probe(struct chv_pinctrl *pctrl, int irq) |
| 1540 | { |
| 1541 | const struct chv_gpio_pinrange *range; |
| 1542 | struct gpio_chip *chip = &pctrl->chip; |
Mika Westerberg | 7036502 | 2017-04-10 13:16:33 +0300 | [diff] [blame] | 1543 | bool need_valid_mask = !dmi_check_system(chv_no_valid_mask); |
Mika Westerberg | 03c4749 | 2017-11-27 16:54:42 +0300 | [diff] [blame] | 1544 | const struct chv_community *community = pctrl->community; |
| 1545 | int ret, i, irq_base; |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1546 | |
| 1547 | *chip = chv_gpio_chip; |
| 1548 | |
Mika Westerberg | 03c4749 | 2017-11-27 16:54:42 +0300 | [diff] [blame] | 1549 | chip->ngpio = community->pins[community->npins - 1].number + 1; |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1550 | chip->label = dev_name(pctrl->dev); |
Linus Walleij | 58383c78 | 2015-11-04 09:56:26 +0100 | [diff] [blame] | 1551 | chip->parent = pctrl->dev; |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1552 | chip->base = -1; |
Thierry Reding | dc7b038 | 2017-11-07 19:15:52 +0100 | [diff] [blame] | 1553 | chip->irq.need_valid_mask = need_valid_mask; |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1554 | |
Mika Westerberg | d107341 | 2016-09-20 15:15:23 +0300 | [diff] [blame] | 1555 | ret = devm_gpiochip_add_data(pctrl->dev, chip, pctrl); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1556 | if (ret) { |
| 1557 | dev_err(pctrl->dev, "Failed to register gpiochip\n"); |
| 1558 | return ret; |
| 1559 | } |
| 1560 | |
Mika Westerberg | 03c4749 | 2017-11-27 16:54:42 +0300 | [diff] [blame] | 1561 | for (i = 0; i < community->ngpio_ranges; i++) { |
| 1562 | range = &community->gpio_ranges[i]; |
| 1563 | ret = gpiochip_add_pin_range(chip, dev_name(pctrl->dev), |
| 1564 | range->base, range->base, |
| 1565 | range->npins); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1566 | if (ret) { |
| 1567 | dev_err(pctrl->dev, "failed to add GPIO pin range\n"); |
Mika Westerberg | d107341 | 2016-09-20 15:15:23 +0300 | [diff] [blame] | 1568 | return ret; |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1569 | } |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1570 | } |
| 1571 | |
Mika Westerberg | 47c950d | 2016-09-20 15:15:22 +0300 | [diff] [blame] | 1572 | /* Do not add GPIOs that can only generate GPEs to the IRQ domain */ |
Mika Westerberg | 03c4749 | 2017-11-27 16:54:42 +0300 | [diff] [blame] | 1573 | for (i = 0; i < community->npins; i++) { |
Mika Westerberg | 47c950d | 2016-09-20 15:15:22 +0300 | [diff] [blame] | 1574 | const struct pinctrl_pin_desc *desc; |
| 1575 | u32 intsel; |
| 1576 | |
Mika Westerberg | 03c4749 | 2017-11-27 16:54:42 +0300 | [diff] [blame] | 1577 | desc = &community->pins[i]; |
Mika Westerberg | 47c950d | 2016-09-20 15:15:22 +0300 | [diff] [blame] | 1578 | |
| 1579 | intsel = readl(chv_padreg(pctrl, desc->number, CHV_PADCTRL0)); |
| 1580 | intsel &= CHV_PADCTRL0_INTSEL_MASK; |
| 1581 | intsel >>= CHV_PADCTRL0_INTSEL_SHIFT; |
| 1582 | |
Mika Westerberg | 03c4749 | 2017-11-27 16:54:42 +0300 | [diff] [blame] | 1583 | if (need_valid_mask && intsel >= community->nirqs) |
Thierry Reding | dc7b038 | 2017-11-07 19:15:52 +0100 | [diff] [blame] | 1584 | clear_bit(i, chip->irq.valid_mask); |
Mika Westerberg | 47c950d | 2016-09-20 15:15:22 +0300 | [diff] [blame] | 1585 | } |
| 1586 | |
Mika Westerberg | d2b3c35 | 2017-12-04 12:11:02 +0300 | [diff] [blame] | 1587 | /* |
| 1588 | * The same set of machines in chv_no_valid_mask[] have incorrectly |
| 1589 | * configured GPIOs that generate spurious interrupts so we use |
| 1590 | * this same list to apply another quirk for them. |
| 1591 | * |
| 1592 | * See also https://bugzilla.kernel.org/show_bug.cgi?id=197953. |
| 1593 | */ |
| 1594 | if (!need_valid_mask) { |
| 1595 | /* |
| 1596 | * Mask all interrupts the community is able to generate |
| 1597 | * but leave the ones that can only generate GPEs unmasked. |
| 1598 | */ |
| 1599 | chv_writel(GENMASK(31, pctrl->community->nirqs), |
| 1600 | pctrl->regs + CHV_INTMASK); |
| 1601 | } |
| 1602 | |
Mika Westerberg | bcb48cc | 2016-08-22 14:42:52 +0300 | [diff] [blame] | 1603 | /* Clear all interrupts */ |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1604 | chv_writel(0xffff, pctrl->regs + CHV_INTSTAT); |
| 1605 | |
Grygorii Strashko | 845e405 | 2017-10-03 12:00:49 -0500 | [diff] [blame] | 1606 | if (!need_valid_mask) { |
| 1607 | irq_base = devm_irq_alloc_descs(pctrl->dev, -1, 0, |
Mika Westerberg | 83b9dc1 | 2018-04-25 13:32:11 +0300 | [diff] [blame] | 1608 | community->npins, NUMA_NO_NODE); |
Grygorii Strashko | 845e405 | 2017-10-03 12:00:49 -0500 | [diff] [blame] | 1609 | if (irq_base < 0) { |
| 1610 | dev_err(pctrl->dev, "Failed to allocate IRQ numbers\n"); |
| 1611 | return irq_base; |
| 1612 | } |
Grygorii Strashko | 845e405 | 2017-10-03 12:00:49 -0500 | [diff] [blame] | 1613 | } |
| 1614 | |
Mika Westerberg | 83b9dc1 | 2018-04-25 13:32:11 +0300 | [diff] [blame] | 1615 | ret = gpiochip_irqchip_add(chip, &chv_gpio_irqchip, 0, |
Mika Westerberg | bcb48cc | 2016-08-22 14:42:52 +0300 | [diff] [blame] | 1616 | handle_bad_irq, IRQ_TYPE_NONE); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1617 | if (ret) { |
| 1618 | dev_err(pctrl->dev, "failed to add IRQ chip\n"); |
Mika Westerberg | d107341 | 2016-09-20 15:15:23 +0300 | [diff] [blame] | 1619 | return ret; |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1620 | } |
| 1621 | |
Mika Westerberg | 83b9dc1 | 2018-04-25 13:32:11 +0300 | [diff] [blame] | 1622 | if (!need_valid_mask) { |
| 1623 | for (i = 0; i < community->ngpio_ranges; i++) { |
| 1624 | range = &community->gpio_ranges[i]; |
| 1625 | |
| 1626 | irq_domain_associate_many(chip->irq.domain, irq_base, |
| 1627 | range->base, range->npins); |
| 1628 | irq_base += range->npins; |
| 1629 | } |
| 1630 | } |
| 1631 | |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1632 | gpiochip_set_chained_irqchip(chip, &chv_gpio_irqchip, irq, |
| 1633 | chv_gpio_irq_handler); |
| 1634 | return 0; |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1635 | } |
| 1636 | |
Hans de Goede | a0b0285 | 2017-03-23 14:23:25 +0100 | [diff] [blame] | 1637 | static acpi_status chv_pinctrl_mmio_access_handler(u32 function, |
| 1638 | acpi_physical_address address, u32 bits, u64 *value, |
| 1639 | void *handler_context, void *region_context) |
| 1640 | { |
| 1641 | struct chv_pinctrl *pctrl = region_context; |
| 1642 | unsigned long flags; |
| 1643 | acpi_status ret = AE_OK; |
| 1644 | |
| 1645 | raw_spin_lock_irqsave(&chv_lock, flags); |
| 1646 | |
| 1647 | if (function == ACPI_WRITE) |
| 1648 | chv_writel((u32)(*value), pctrl->regs + (u32)address); |
| 1649 | else if (function == ACPI_READ) |
| 1650 | *value = readl(pctrl->regs + (u32)address); |
| 1651 | else |
| 1652 | ret = AE_BAD_PARAMETER; |
| 1653 | |
| 1654 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
| 1655 | |
| 1656 | return ret; |
| 1657 | } |
| 1658 | |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1659 | static int chv_pinctrl_probe(struct platform_device *pdev) |
| 1660 | { |
| 1661 | struct chv_pinctrl *pctrl; |
| 1662 | struct acpi_device *adev; |
| 1663 | struct resource *res; |
Hans de Goede | a0b0285 | 2017-03-23 14:23:25 +0100 | [diff] [blame] | 1664 | acpi_status status; |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1665 | int ret, irq, i; |
| 1666 | |
| 1667 | adev = ACPI_COMPANION(&pdev->dev); |
| 1668 | if (!adev) |
| 1669 | return -ENODEV; |
| 1670 | |
| 1671 | pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL); |
| 1672 | if (!pctrl) |
| 1673 | return -ENOMEM; |
| 1674 | |
| 1675 | for (i = 0; i < ARRAY_SIZE(chv_communities); i++) |
| 1676 | if (!strcmp(adev->pnp.unique_id, chv_communities[i]->uid)) { |
| 1677 | pctrl->community = chv_communities[i]; |
| 1678 | break; |
| 1679 | } |
| 1680 | if (i == ARRAY_SIZE(chv_communities)) |
| 1681 | return -ENODEV; |
| 1682 | |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1683 | pctrl->dev = &pdev->dev; |
| 1684 | |
Mika Westerberg | 9eb457b | 2014-12-04 12:32:50 +0200 | [diff] [blame] | 1685 | #ifdef CONFIG_PM_SLEEP |
| 1686 | pctrl->saved_pin_context = devm_kcalloc(pctrl->dev, |
| 1687 | pctrl->community->npins, sizeof(*pctrl->saved_pin_context), |
| 1688 | GFP_KERNEL); |
| 1689 | if (!pctrl->saved_pin_context) |
| 1690 | return -ENOMEM; |
| 1691 | #endif |
| 1692 | |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1693 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1694 | pctrl->regs = devm_ioremap_resource(&pdev->dev, res); |
| 1695 | if (IS_ERR(pctrl->regs)) |
| 1696 | return PTR_ERR(pctrl->regs); |
| 1697 | |
| 1698 | irq = platform_get_irq(pdev, 0); |
| 1699 | if (irq < 0) { |
| 1700 | dev_err(&pdev->dev, "failed to get interrupt number\n"); |
| 1701 | return irq; |
| 1702 | } |
| 1703 | |
| 1704 | pctrl->pctldesc = chv_pinctrl_desc; |
| 1705 | pctrl->pctldesc.name = dev_name(&pdev->dev); |
| 1706 | pctrl->pctldesc.pins = pctrl->community->pins; |
| 1707 | pctrl->pctldesc.npins = pctrl->community->npins; |
| 1708 | |
Laxman Dewangan | 7cf061fa | 2016-02-24 14:44:07 +0530 | [diff] [blame] | 1709 | pctrl->pctldev = devm_pinctrl_register(&pdev->dev, &pctrl->pctldesc, |
| 1710 | pctrl); |
Masahiro Yamada | 323de9e | 2015-06-09 13:01:16 +0900 | [diff] [blame] | 1711 | if (IS_ERR(pctrl->pctldev)) { |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1712 | dev_err(&pdev->dev, "failed to register pinctrl driver\n"); |
Masahiro Yamada | 323de9e | 2015-06-09 13:01:16 +0900 | [diff] [blame] | 1713 | return PTR_ERR(pctrl->pctldev); |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1714 | } |
| 1715 | |
| 1716 | ret = chv_gpio_probe(pctrl, irq); |
Laxman Dewangan | 7cf061fa | 2016-02-24 14:44:07 +0530 | [diff] [blame] | 1717 | if (ret) |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1718 | return ret; |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1719 | |
Hans de Goede | a0b0285 | 2017-03-23 14:23:25 +0100 | [diff] [blame] | 1720 | status = acpi_install_address_space_handler(adev->handle, |
| 1721 | pctrl->community->acpi_space_id, |
| 1722 | chv_pinctrl_mmio_access_handler, |
| 1723 | NULL, pctrl); |
| 1724 | if (ACPI_FAILURE(status)) |
| 1725 | dev_err(&pdev->dev, "failed to install ACPI addr space handler\n"); |
| 1726 | |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1727 | platform_set_drvdata(pdev, pctrl); |
| 1728 | |
| 1729 | return 0; |
| 1730 | } |
| 1731 | |
Hans de Goede | a0b0285 | 2017-03-23 14:23:25 +0100 | [diff] [blame] | 1732 | static int chv_pinctrl_remove(struct platform_device *pdev) |
| 1733 | { |
| 1734 | struct chv_pinctrl *pctrl = platform_get_drvdata(pdev); |
| 1735 | |
| 1736 | acpi_remove_address_space_handler(ACPI_COMPANION(&pdev->dev), |
| 1737 | pctrl->community->acpi_space_id, |
| 1738 | chv_pinctrl_mmio_access_handler); |
| 1739 | |
| 1740 | return 0; |
| 1741 | } |
| 1742 | |
Mika Westerberg | 9eb457b | 2014-12-04 12:32:50 +0200 | [diff] [blame] | 1743 | #ifdef CONFIG_PM_SLEEP |
Mika Westerberg | d2cdf5dc | 2016-10-31 16:57:33 +0200 | [diff] [blame] | 1744 | static int chv_pinctrl_suspend_noirq(struct device *dev) |
Mika Westerberg | 9eb457b | 2014-12-04 12:32:50 +0200 | [diff] [blame] | 1745 | { |
| 1746 | struct platform_device *pdev = to_platform_device(dev); |
| 1747 | struct chv_pinctrl *pctrl = platform_get_drvdata(pdev); |
Mika Westerberg | 5621112 | 2016-10-31 16:57:32 +0200 | [diff] [blame] | 1748 | unsigned long flags; |
Mika Westerberg | 9eb457b | 2014-12-04 12:32:50 +0200 | [diff] [blame] | 1749 | int i; |
| 1750 | |
Mika Westerberg | 5621112 | 2016-10-31 16:57:32 +0200 | [diff] [blame] | 1751 | raw_spin_lock_irqsave(&chv_lock, flags); |
| 1752 | |
Mika Westerberg | 9eb457b | 2014-12-04 12:32:50 +0200 | [diff] [blame] | 1753 | pctrl->saved_intmask = readl(pctrl->regs + CHV_INTMASK); |
| 1754 | |
| 1755 | for (i = 0; i < pctrl->community->npins; i++) { |
| 1756 | const struct pinctrl_pin_desc *desc; |
| 1757 | struct chv_pin_context *ctx; |
| 1758 | void __iomem *reg; |
| 1759 | |
| 1760 | desc = &pctrl->community->pins[i]; |
| 1761 | if (chv_pad_locked(pctrl, desc->number)) |
| 1762 | continue; |
| 1763 | |
| 1764 | ctx = &pctrl->saved_pin_context[i]; |
| 1765 | |
| 1766 | reg = chv_padreg(pctrl, desc->number, CHV_PADCTRL0); |
| 1767 | ctx->padctrl0 = readl(reg) & ~CHV_PADCTRL0_GPIORXSTATE; |
| 1768 | |
| 1769 | reg = chv_padreg(pctrl, desc->number, CHV_PADCTRL1); |
| 1770 | ctx->padctrl1 = readl(reg); |
| 1771 | } |
| 1772 | |
Mika Westerberg | 5621112 | 2016-10-31 16:57:32 +0200 | [diff] [blame] | 1773 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
| 1774 | |
Mika Westerberg | 9eb457b | 2014-12-04 12:32:50 +0200 | [diff] [blame] | 1775 | return 0; |
| 1776 | } |
| 1777 | |
Mika Westerberg | d2cdf5dc | 2016-10-31 16:57:33 +0200 | [diff] [blame] | 1778 | static int chv_pinctrl_resume_noirq(struct device *dev) |
Mika Westerberg | 9eb457b | 2014-12-04 12:32:50 +0200 | [diff] [blame] | 1779 | { |
| 1780 | struct platform_device *pdev = to_platform_device(dev); |
| 1781 | struct chv_pinctrl *pctrl = platform_get_drvdata(pdev); |
Mika Westerberg | 5621112 | 2016-10-31 16:57:32 +0200 | [diff] [blame] | 1782 | unsigned long flags; |
Mika Westerberg | 9eb457b | 2014-12-04 12:32:50 +0200 | [diff] [blame] | 1783 | int i; |
| 1784 | |
Mika Westerberg | 5621112 | 2016-10-31 16:57:32 +0200 | [diff] [blame] | 1785 | raw_spin_lock_irqsave(&chv_lock, flags); |
| 1786 | |
Mika Westerberg | 9eb457b | 2014-12-04 12:32:50 +0200 | [diff] [blame] | 1787 | /* |
| 1788 | * Mask all interrupts before restoring per-pin configuration |
| 1789 | * registers because we don't know in which state BIOS left them |
| 1790 | * upon exiting suspend. |
| 1791 | */ |
| 1792 | chv_writel(0, pctrl->regs + CHV_INTMASK); |
| 1793 | |
| 1794 | for (i = 0; i < pctrl->community->npins; i++) { |
| 1795 | const struct pinctrl_pin_desc *desc; |
| 1796 | const struct chv_pin_context *ctx; |
| 1797 | void __iomem *reg; |
| 1798 | u32 val; |
| 1799 | |
| 1800 | desc = &pctrl->community->pins[i]; |
| 1801 | if (chv_pad_locked(pctrl, desc->number)) |
| 1802 | continue; |
| 1803 | |
| 1804 | ctx = &pctrl->saved_pin_context[i]; |
| 1805 | |
| 1806 | /* Only restore if our saved state differs from the current */ |
| 1807 | reg = chv_padreg(pctrl, desc->number, CHV_PADCTRL0); |
| 1808 | val = readl(reg) & ~CHV_PADCTRL0_GPIORXSTATE; |
| 1809 | if (ctx->padctrl0 != val) { |
| 1810 | chv_writel(ctx->padctrl0, reg); |
| 1811 | dev_dbg(pctrl->dev, "restored pin %2u ctrl0 0x%08x\n", |
| 1812 | desc->number, readl(reg)); |
| 1813 | } |
| 1814 | |
| 1815 | reg = chv_padreg(pctrl, desc->number, CHV_PADCTRL1); |
| 1816 | val = readl(reg); |
| 1817 | if (ctx->padctrl1 != val) { |
| 1818 | chv_writel(ctx->padctrl1, reg); |
| 1819 | dev_dbg(pctrl->dev, "restored pin %2u ctrl1 0x%08x\n", |
| 1820 | desc->number, readl(reg)); |
| 1821 | } |
| 1822 | } |
| 1823 | |
| 1824 | /* |
| 1825 | * Now that all pins are restored to known state, we can restore |
| 1826 | * the interrupt mask register as well. |
| 1827 | */ |
| 1828 | chv_writel(0xffff, pctrl->regs + CHV_INTSTAT); |
| 1829 | chv_writel(pctrl->saved_intmask, pctrl->regs + CHV_INTMASK); |
| 1830 | |
Mika Westerberg | 5621112 | 2016-10-31 16:57:32 +0200 | [diff] [blame] | 1831 | raw_spin_unlock_irqrestore(&chv_lock, flags); |
| 1832 | |
Mika Westerberg | 9eb457b | 2014-12-04 12:32:50 +0200 | [diff] [blame] | 1833 | return 0; |
| 1834 | } |
| 1835 | #endif |
| 1836 | |
| 1837 | static const struct dev_pm_ops chv_pinctrl_pm_ops = { |
Mika Westerberg | d2cdf5dc | 2016-10-31 16:57:33 +0200 | [diff] [blame] | 1838 | SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(chv_pinctrl_suspend_noirq, |
| 1839 | chv_pinctrl_resume_noirq) |
Mika Westerberg | 9eb457b | 2014-12-04 12:32:50 +0200 | [diff] [blame] | 1840 | }; |
| 1841 | |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1842 | static const struct acpi_device_id chv_pinctrl_acpi_match[] = { |
| 1843 | { "INT33FF" }, |
| 1844 | { } |
| 1845 | }; |
| 1846 | MODULE_DEVICE_TABLE(acpi, chv_pinctrl_acpi_match); |
| 1847 | |
| 1848 | static struct platform_driver chv_pinctrl_driver = { |
| 1849 | .probe = chv_pinctrl_probe, |
Hans de Goede | a0b0285 | 2017-03-23 14:23:25 +0100 | [diff] [blame] | 1850 | .remove = chv_pinctrl_remove, |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1851 | .driver = { |
| 1852 | .name = "cherryview-pinctrl", |
Mika Westerberg | 9eb457b | 2014-12-04 12:32:50 +0200 | [diff] [blame] | 1853 | .pm = &chv_pinctrl_pm_ops, |
Mika Westerberg | 6e08d6b | 2014-11-03 13:01:33 +0200 | [diff] [blame] | 1854 | .acpi_match_table = chv_pinctrl_acpi_match, |
| 1855 | }, |
| 1856 | }; |
| 1857 | |
| 1858 | static int __init chv_pinctrl_init(void) |
| 1859 | { |
| 1860 | return platform_driver_register(&chv_pinctrl_driver); |
| 1861 | } |
| 1862 | subsys_initcall(chv_pinctrl_init); |
| 1863 | |
| 1864 | static void __exit chv_pinctrl_exit(void) |
| 1865 | { |
| 1866 | platform_driver_unregister(&chv_pinctrl_driver); |
| 1867 | } |
| 1868 | module_exit(chv_pinctrl_exit); |
| 1869 | |
| 1870 | MODULE_AUTHOR("Mika Westerberg <mika.westerberg@linux.intel.com>"); |
| 1871 | MODULE_DESCRIPTION("Intel Cherryview/Braswell pinctrl driver"); |
| 1872 | MODULE_LICENSE("GPL v2"); |