Andy Shevchenko | 875a92b | 2018-06-29 15:36:34 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 2 | /* |
| 3 | * Intel pinctrl/GPIO core driver. |
| 4 | * |
| 5 | * Copyright (C) 2015, Intel Corporation |
| 6 | * Authors: Mathias Nyman <mathias.nyman@linux.intel.com> |
| 7 | * Mika Westerberg <mika.westerberg@linux.intel.com> |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 8 | */ |
| 9 | |
Andy Shevchenko | 924cf80 | 2018-08-30 19:27:36 +0300 | [diff] [blame] | 10 | #include <linux/acpi.h> |
Mika Westerberg | 193b40c | 2015-10-21 13:08:43 +0300 | [diff] [blame] | 11 | #include <linux/interrupt.h> |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 12 | #include <linux/gpio/driver.h> |
Mika Westerberg | e57725e | 2017-01-27 13:07:14 +0300 | [diff] [blame] | 13 | #include <linux/log2.h> |
Andy Shevchenko | 6a33a1d | 2019-08-07 16:41:50 +0300 | [diff] [blame] | 14 | #include <linux/module.h> |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 15 | #include <linux/platform_device.h> |
Andy Shevchenko | 924cf80 | 2018-08-30 19:27:36 +0300 | [diff] [blame] | 16 | #include <linux/property.h> |
Andy Shevchenko | 6a33a1d | 2019-08-07 16:41:50 +0300 | [diff] [blame] | 17 | #include <linux/time.h> |
Andy Shevchenko | 924cf80 | 2018-08-30 19:27:36 +0300 | [diff] [blame] | 18 | |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 19 | #include <linux/pinctrl/pinctrl.h> |
| 20 | #include <linux/pinctrl/pinmux.h> |
| 21 | #include <linux/pinctrl/pinconf.h> |
| 22 | #include <linux/pinctrl/pinconf-generic.h> |
| 23 | |
Mika Westerberg | c538b94 | 2016-10-10 16:39:31 +0300 | [diff] [blame] | 24 | #include "../core.h" |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 25 | #include "pinctrl-intel.h" |
| 26 | |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 27 | /* Offset from regs */ |
Mika Westerberg | e57725e | 2017-01-27 13:07:14 +0300 | [diff] [blame] | 28 | #define REVID 0x000 |
| 29 | #define REVID_SHIFT 16 |
| 30 | #define REVID_MASK GENMASK(31, 16) |
| 31 | |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 32 | #define PADBAR 0x00c |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 33 | |
| 34 | #define PADOWN_BITS 4 |
| 35 | #define PADOWN_SHIFT(p) ((p) % 8 * PADOWN_BITS) |
Andy Shevchenko | e58926e | 2019-04-01 15:06:44 +0300 | [diff] [blame] | 36 | #define PADOWN_MASK(p) (GENMASK(3, 0) << PADOWN_SHIFT(p)) |
Qipeng Zha | 99a735b | 2015-11-30 19:20:16 +0800 | [diff] [blame] | 37 | #define PADOWN_GPP(p) ((p) / 8) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 38 | |
| 39 | /* Offset from pad_regs */ |
| 40 | #define PADCFG0 0x000 |
| 41 | #define PADCFG0_RXEVCFG_SHIFT 25 |
Andy Shevchenko | e58926e | 2019-04-01 15:06:44 +0300 | [diff] [blame] | 42 | #define PADCFG0_RXEVCFG_MASK GENMASK(26, 25) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 43 | #define PADCFG0_RXEVCFG_LEVEL 0 |
| 44 | #define PADCFG0_RXEVCFG_EDGE 1 |
| 45 | #define PADCFG0_RXEVCFG_DISABLED 2 |
| 46 | #define PADCFG0_RXEVCFG_EDGE_BOTH 3 |
Mika Westerberg | e57725e | 2017-01-27 13:07:14 +0300 | [diff] [blame] | 47 | #define PADCFG0_PREGFRXSEL BIT(24) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 48 | #define PADCFG0_RXINV BIT(23) |
| 49 | #define PADCFG0_GPIROUTIOXAPIC BIT(20) |
| 50 | #define PADCFG0_GPIROUTSCI BIT(19) |
| 51 | #define PADCFG0_GPIROUTSMI BIT(18) |
| 52 | #define PADCFG0_GPIROUTNMI BIT(17) |
| 53 | #define PADCFG0_PMODE_SHIFT 10 |
Andy Shevchenko | e58926e | 2019-04-01 15:06:44 +0300 | [diff] [blame] | 54 | #define PADCFG0_PMODE_MASK GENMASK(13, 10) |
Andy Shevchenko | 4973ddc | 2019-10-14 12:51:04 +0300 | [diff] [blame] | 55 | #define PADCFG0_PMODE_GPIO 0 |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 56 | #define PADCFG0_GPIORXDIS BIT(9) |
| 57 | #define PADCFG0_GPIOTXDIS BIT(8) |
| 58 | #define PADCFG0_GPIORXSTATE BIT(1) |
| 59 | #define PADCFG0_GPIOTXSTATE BIT(0) |
| 60 | |
| 61 | #define PADCFG1 0x004 |
| 62 | #define PADCFG1_TERM_UP BIT(13) |
| 63 | #define PADCFG1_TERM_SHIFT 10 |
Andy Shevchenko | e58926e | 2019-04-01 15:06:44 +0300 | [diff] [blame] | 64 | #define PADCFG1_TERM_MASK GENMASK(12, 10) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 65 | #define PADCFG1_TERM_20K 4 |
| 66 | #define PADCFG1_TERM_2K 3 |
| 67 | #define PADCFG1_TERM_5K 2 |
| 68 | #define PADCFG1_TERM_1K 1 |
| 69 | |
Mika Westerberg | e57725e | 2017-01-27 13:07:14 +0300 | [diff] [blame] | 70 | #define PADCFG2 0x008 |
| 71 | #define PADCFG2_DEBEN BIT(0) |
| 72 | #define PADCFG2_DEBOUNCE_SHIFT 1 |
| 73 | #define PADCFG2_DEBOUNCE_MASK GENMASK(4, 1) |
| 74 | |
Andy Shevchenko | 6a33a1d | 2019-08-07 16:41:50 +0300 | [diff] [blame] | 75 | #define DEBOUNCE_PERIOD_NSEC 31250 |
Mika Westerberg | e57725e | 2017-01-27 13:07:14 +0300 | [diff] [blame] | 76 | |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 77 | struct intel_pad_context { |
| 78 | u32 padcfg0; |
| 79 | u32 padcfg1; |
Mika Westerberg | e57725e | 2017-01-27 13:07:14 +0300 | [diff] [blame] | 80 | u32 padcfg2; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | struct intel_community_context { |
| 84 | u32 *intmask; |
Chris Chiu | a0a5f76 | 2019-04-15 13:53:58 +0800 | [diff] [blame] | 85 | u32 *hostown; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | struct intel_pinctrl_context { |
| 89 | struct intel_pad_context *pads; |
| 90 | struct intel_community_context *communities; |
| 91 | }; |
| 92 | |
| 93 | /** |
| 94 | * struct intel_pinctrl - Intel pinctrl private structure |
| 95 | * @dev: Pointer to the device structure |
| 96 | * @lock: Lock to serialize register access |
| 97 | * @pctldesc: Pin controller description |
| 98 | * @pctldev: Pointer to the pin controller device |
| 99 | * @chip: GPIO chip in this pin controller |
Andy Shevchenko | 57ff2df | 2019-09-16 17:47:51 +0300 | [diff] [blame] | 100 | * @irqchip: IRQ chip in this pin controller |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 101 | * @soc: SoC/PCH specific pin configuration data |
| 102 | * @communities: All communities in this pin controller |
| 103 | * @ncommunities: Number of communities in this pin controller |
| 104 | * @context: Configuration saved over system sleep |
Nilesh Bacchewar | 01dabe9 | 2016-09-21 16:35:23 -0700 | [diff] [blame] | 105 | * @irq: pinctrl/GPIO chip irq number |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 106 | */ |
| 107 | struct intel_pinctrl { |
| 108 | struct device *dev; |
Mika Westerberg | 27d9098 | 2016-06-16 11:25:36 +0300 | [diff] [blame] | 109 | raw_spinlock_t lock; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 110 | struct pinctrl_desc pctldesc; |
| 111 | struct pinctrl_dev *pctldev; |
| 112 | struct gpio_chip chip; |
Andy Shevchenko | 57ff2df | 2019-09-16 17:47:51 +0300 | [diff] [blame] | 113 | struct irq_chip irqchip; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 114 | const struct intel_pinctrl_soc_data *soc; |
| 115 | struct intel_community *communities; |
| 116 | size_t ncommunities; |
| 117 | struct intel_pinctrl_context context; |
Nilesh Bacchewar | 01dabe9 | 2016-09-21 16:35:23 -0700 | [diff] [blame] | 118 | int irq; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 119 | }; |
| 120 | |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 121 | #define pin_to_padno(c, p) ((p) - (c)->pin_base) |
Mika Westerberg | 919eb47 | 2017-06-06 16:18:17 +0300 | [diff] [blame] | 122 | #define padgroup_offset(g, p) ((p) - (g)->base) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 123 | |
| 124 | static struct intel_community *intel_get_community(struct intel_pinctrl *pctrl, |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 125 | unsigned int pin) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 126 | { |
| 127 | struct intel_community *community; |
| 128 | int i; |
| 129 | |
| 130 | for (i = 0; i < pctrl->ncommunities; i++) { |
| 131 | community = &pctrl->communities[i]; |
| 132 | if (pin >= community->pin_base && |
| 133 | pin < community->pin_base + community->npins) |
| 134 | return community; |
| 135 | } |
| 136 | |
| 137 | dev_warn(pctrl->dev, "failed to find community for pin %u\n", pin); |
| 138 | return NULL; |
| 139 | } |
| 140 | |
Mika Westerberg | 919eb47 | 2017-06-06 16:18:17 +0300 | [diff] [blame] | 141 | static const struct intel_padgroup * |
| 142 | intel_community_get_padgroup(const struct intel_community *community, |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 143 | unsigned int pin) |
Mika Westerberg | 919eb47 | 2017-06-06 16:18:17 +0300 | [diff] [blame] | 144 | { |
| 145 | int i; |
| 146 | |
| 147 | for (i = 0; i < community->ngpps; i++) { |
| 148 | const struct intel_padgroup *padgrp = &community->gpps[i]; |
| 149 | |
| 150 | if (pin >= padgrp->base && pin < padgrp->base + padgrp->size) |
| 151 | return padgrp; |
| 152 | } |
| 153 | |
| 154 | return NULL; |
| 155 | } |
| 156 | |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 157 | static void __iomem *intel_get_padcfg(struct intel_pinctrl *pctrl, |
| 158 | unsigned int pin, unsigned int reg) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 159 | { |
| 160 | const struct intel_community *community; |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 161 | unsigned int padno; |
Mika Westerberg | e57725e | 2017-01-27 13:07:14 +0300 | [diff] [blame] | 162 | size_t nregs; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 163 | |
| 164 | community = intel_get_community(pctrl, pin); |
| 165 | if (!community) |
| 166 | return NULL; |
| 167 | |
| 168 | padno = pin_to_padno(community, pin); |
Mika Westerberg | e57725e | 2017-01-27 13:07:14 +0300 | [diff] [blame] | 169 | nregs = (community->features & PINCTRL_FEATURE_DEBOUNCE) ? 4 : 2; |
| 170 | |
Andy Shevchenko | 7eb7ecd | 2019-07-23 18:55:14 +0300 | [diff] [blame] | 171 | if (reg >= nregs * 4) |
Mika Westerberg | e57725e | 2017-01-27 13:07:14 +0300 | [diff] [blame] | 172 | return NULL; |
| 173 | |
| 174 | return community->pad_regs + reg + padno * nregs * 4; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 175 | } |
| 176 | |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 177 | static bool intel_pad_owned_by_host(struct intel_pinctrl *pctrl, unsigned int pin) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 178 | { |
| 179 | const struct intel_community *community; |
Mika Westerberg | 919eb47 | 2017-06-06 16:18:17 +0300 | [diff] [blame] | 180 | const struct intel_padgroup *padgrp; |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 181 | unsigned int gpp, offset, gpp_offset; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 182 | void __iomem *padown; |
| 183 | |
| 184 | community = intel_get_community(pctrl, pin); |
| 185 | if (!community) |
| 186 | return false; |
| 187 | if (!community->padown_offset) |
| 188 | return true; |
| 189 | |
Mika Westerberg | 919eb47 | 2017-06-06 16:18:17 +0300 | [diff] [blame] | 190 | padgrp = intel_community_get_padgroup(community, pin); |
| 191 | if (!padgrp) |
| 192 | return false; |
| 193 | |
| 194 | gpp_offset = padgroup_offset(padgrp, pin); |
| 195 | gpp = PADOWN_GPP(gpp_offset); |
| 196 | offset = community->padown_offset + padgrp->padown_num * 4 + gpp * 4; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 197 | padown = community->regs + offset; |
| 198 | |
Mika Westerberg | 919eb47 | 2017-06-06 16:18:17 +0300 | [diff] [blame] | 199 | return !(readl(padown) & PADOWN_MASK(gpp_offset)); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 200 | } |
| 201 | |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 202 | static bool intel_pad_acpi_mode(struct intel_pinctrl *pctrl, unsigned int pin) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 203 | { |
| 204 | const struct intel_community *community; |
Mika Westerberg | 919eb47 | 2017-06-06 16:18:17 +0300 | [diff] [blame] | 205 | const struct intel_padgroup *padgrp; |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 206 | unsigned int offset, gpp_offset; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 207 | void __iomem *hostown; |
| 208 | |
| 209 | community = intel_get_community(pctrl, pin); |
| 210 | if (!community) |
| 211 | return true; |
| 212 | if (!community->hostown_offset) |
| 213 | return false; |
| 214 | |
Mika Westerberg | 919eb47 | 2017-06-06 16:18:17 +0300 | [diff] [blame] | 215 | padgrp = intel_community_get_padgroup(community, pin); |
| 216 | if (!padgrp) |
| 217 | return true; |
| 218 | |
| 219 | gpp_offset = padgroup_offset(padgrp, pin); |
| 220 | offset = community->hostown_offset + padgrp->reg_num * 4; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 221 | hostown = community->regs + offset; |
| 222 | |
Mika Westerberg | 919eb47 | 2017-06-06 16:18:17 +0300 | [diff] [blame] | 223 | return !(readl(hostown) & BIT(gpp_offset)); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 224 | } |
| 225 | |
Andy Shevchenko | 1bd2315 | 2019-08-12 19:14:01 +0300 | [diff] [blame] | 226 | /** |
| 227 | * enum - Locking variants of the pad configuration |
| 228 | * |
| 229 | * @PAD_UNLOCKED: pad is fully controlled by the configuration registers |
| 230 | * @PAD_LOCKED: pad configuration registers, except TX state, are locked |
| 231 | * @PAD_LOCKED_TX: pad configuration TX state is locked |
| 232 | * @PAD_LOCKED_FULL: pad configuration registers are locked completely |
| 233 | * |
| 234 | * Locking is considered as read-only mode for corresponding registers and |
| 235 | * their respective fields. That said, TX state bit is locked separately from |
| 236 | * the main locking scheme. |
| 237 | */ |
| 238 | enum { |
| 239 | PAD_UNLOCKED = 0, |
| 240 | PAD_LOCKED = 1, |
| 241 | PAD_LOCKED_TX = 2, |
| 242 | PAD_LOCKED_FULL = PAD_LOCKED | PAD_LOCKED_TX, |
| 243 | }; |
| 244 | |
| 245 | static int intel_pad_locked(struct intel_pinctrl *pctrl, unsigned int pin) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 246 | { |
| 247 | struct intel_community *community; |
Mika Westerberg | 919eb47 | 2017-06-06 16:18:17 +0300 | [diff] [blame] | 248 | const struct intel_padgroup *padgrp; |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 249 | unsigned int offset, gpp_offset; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 250 | u32 value; |
Andy Shevchenko | 1bd2315 | 2019-08-12 19:14:01 +0300 | [diff] [blame] | 251 | int ret = PAD_UNLOCKED; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 252 | |
| 253 | community = intel_get_community(pctrl, pin); |
| 254 | if (!community) |
Andy Shevchenko | 1bd2315 | 2019-08-12 19:14:01 +0300 | [diff] [blame] | 255 | return PAD_LOCKED_FULL; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 256 | if (!community->padcfglock_offset) |
Andy Shevchenko | 1bd2315 | 2019-08-12 19:14:01 +0300 | [diff] [blame] | 257 | return PAD_UNLOCKED; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 258 | |
Mika Westerberg | 919eb47 | 2017-06-06 16:18:17 +0300 | [diff] [blame] | 259 | padgrp = intel_community_get_padgroup(community, pin); |
| 260 | if (!padgrp) |
Andy Shevchenko | 1bd2315 | 2019-08-12 19:14:01 +0300 | [diff] [blame] | 261 | return PAD_LOCKED_FULL; |
Mika Westerberg | 919eb47 | 2017-06-06 16:18:17 +0300 | [diff] [blame] | 262 | |
| 263 | gpp_offset = padgroup_offset(padgrp, pin); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 264 | |
| 265 | /* |
| 266 | * If PADCFGLOCK and PADCFGLOCKTX bits are both clear for this pad, |
| 267 | * the pad is considered unlocked. Any other case means that it is |
Andy Shevchenko | 1bd2315 | 2019-08-12 19:14:01 +0300 | [diff] [blame] | 268 | * either fully or partially locked. |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 269 | */ |
Andy Shevchenko | 1bd2315 | 2019-08-12 19:14:01 +0300 | [diff] [blame] | 270 | offset = community->padcfglock_offset + 0 + padgrp->reg_num * 8; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 271 | value = readl(community->regs + offset); |
Mika Westerberg | 919eb47 | 2017-06-06 16:18:17 +0300 | [diff] [blame] | 272 | if (value & BIT(gpp_offset)) |
Andy Shevchenko | 1bd2315 | 2019-08-12 19:14:01 +0300 | [diff] [blame] | 273 | ret |= PAD_LOCKED; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 274 | |
Mika Westerberg | 919eb47 | 2017-06-06 16:18:17 +0300 | [diff] [blame] | 275 | offset = community->padcfglock_offset + 4 + padgrp->reg_num * 8; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 276 | value = readl(community->regs + offset); |
Mika Westerberg | 919eb47 | 2017-06-06 16:18:17 +0300 | [diff] [blame] | 277 | if (value & BIT(gpp_offset)) |
Andy Shevchenko | 1bd2315 | 2019-08-12 19:14:01 +0300 | [diff] [blame] | 278 | ret |= PAD_LOCKED_TX; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 279 | |
Andy Shevchenko | 1bd2315 | 2019-08-12 19:14:01 +0300 | [diff] [blame] | 280 | return ret; |
| 281 | } |
| 282 | |
| 283 | static bool intel_pad_is_unlocked(struct intel_pinctrl *pctrl, unsigned int pin) |
| 284 | { |
| 285 | return (intel_pad_locked(pctrl, pin) & PAD_LOCKED) == PAD_UNLOCKED; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 286 | } |
| 287 | |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 288 | static bool intel_pad_usable(struct intel_pinctrl *pctrl, unsigned int pin) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 289 | { |
Andy Shevchenko | 1bd2315 | 2019-08-12 19:14:01 +0300 | [diff] [blame] | 290 | return intel_pad_owned_by_host(pctrl, pin) && intel_pad_is_unlocked(pctrl, pin); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | static int intel_get_groups_count(struct pinctrl_dev *pctldev) |
| 294 | { |
| 295 | struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 296 | |
| 297 | return pctrl->soc->ngroups; |
| 298 | } |
| 299 | |
| 300 | static const char *intel_get_group_name(struct pinctrl_dev *pctldev, |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 301 | unsigned int group) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 302 | { |
| 303 | struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 304 | |
| 305 | return pctrl->soc->groups[group].name; |
| 306 | } |
| 307 | |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 308 | static int intel_get_group_pins(struct pinctrl_dev *pctldev, unsigned int group, |
| 309 | const unsigned int **pins, unsigned int *npins) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 310 | { |
| 311 | struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 312 | |
| 313 | *pins = pctrl->soc->groups[group].pins; |
| 314 | *npins = pctrl->soc->groups[group].npins; |
| 315 | return 0; |
| 316 | } |
| 317 | |
| 318 | static void intel_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s, |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 319 | unsigned int pin) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 320 | { |
| 321 | struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
Mika Westerberg | e57725e | 2017-01-27 13:07:14 +0300 | [diff] [blame] | 322 | void __iomem *padcfg; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 323 | u32 cfg0, cfg1, mode; |
Andy Shevchenko | 1bd2315 | 2019-08-12 19:14:01 +0300 | [diff] [blame] | 324 | int locked; |
| 325 | bool acpi; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 326 | |
| 327 | if (!intel_pad_owned_by_host(pctrl, pin)) { |
| 328 | seq_puts(s, "not available"); |
| 329 | return; |
| 330 | } |
| 331 | |
| 332 | cfg0 = readl(intel_get_padcfg(pctrl, pin, PADCFG0)); |
| 333 | cfg1 = readl(intel_get_padcfg(pctrl, pin, PADCFG1)); |
| 334 | |
| 335 | mode = (cfg0 & PADCFG0_PMODE_MASK) >> PADCFG0_PMODE_SHIFT; |
Andy Shevchenko | 4973ddc | 2019-10-14 12:51:04 +0300 | [diff] [blame] | 336 | if (mode == PADCFG0_PMODE_GPIO) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 337 | seq_puts(s, "GPIO "); |
| 338 | else |
| 339 | seq_printf(s, "mode %d ", mode); |
| 340 | |
| 341 | seq_printf(s, "0x%08x 0x%08x", cfg0, cfg1); |
| 342 | |
Mika Westerberg | e57725e | 2017-01-27 13:07:14 +0300 | [diff] [blame] | 343 | /* Dump the additional PADCFG registers if available */ |
| 344 | padcfg = intel_get_padcfg(pctrl, pin, PADCFG2); |
| 345 | if (padcfg) |
| 346 | seq_printf(s, " 0x%08x", readl(padcfg)); |
| 347 | |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 348 | locked = intel_pad_locked(pctrl, pin); |
Mika Westerberg | 4341e8a | 2015-10-21 13:08:44 +0300 | [diff] [blame] | 349 | acpi = intel_pad_acpi_mode(pctrl, pin); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 350 | |
| 351 | if (locked || acpi) { |
| 352 | seq_puts(s, " ["); |
Andy Shevchenko | 1bd2315 | 2019-08-12 19:14:01 +0300 | [diff] [blame] | 353 | if (locked) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 354 | seq_puts(s, "LOCKED"); |
Andy Shevchenko | 1bd2315 | 2019-08-12 19:14:01 +0300 | [diff] [blame] | 355 | if ((locked & PAD_LOCKED_FULL) == PAD_LOCKED_TX) |
| 356 | seq_puts(s, " tx"); |
| 357 | else if ((locked & PAD_LOCKED_FULL) == PAD_LOCKED_FULL) |
| 358 | seq_puts(s, " full"); |
| 359 | |
| 360 | if (locked && acpi) |
| 361 | seq_puts(s, ", "); |
| 362 | |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 363 | if (acpi) |
| 364 | seq_puts(s, "ACPI"); |
| 365 | seq_puts(s, "]"); |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | static const struct pinctrl_ops intel_pinctrl_ops = { |
| 370 | .get_groups_count = intel_get_groups_count, |
| 371 | .get_group_name = intel_get_group_name, |
| 372 | .get_group_pins = intel_get_group_pins, |
| 373 | .pin_dbg_show = intel_pin_dbg_show, |
| 374 | }; |
| 375 | |
| 376 | static int intel_get_functions_count(struct pinctrl_dev *pctldev) |
| 377 | { |
| 378 | struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 379 | |
| 380 | return pctrl->soc->nfunctions; |
| 381 | } |
| 382 | |
| 383 | static const char *intel_get_function_name(struct pinctrl_dev *pctldev, |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 384 | unsigned int function) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 385 | { |
| 386 | struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 387 | |
| 388 | return pctrl->soc->functions[function].name; |
| 389 | } |
| 390 | |
| 391 | static int intel_get_function_groups(struct pinctrl_dev *pctldev, |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 392 | unsigned int function, |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 393 | const char * const **groups, |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 394 | unsigned int * const ngroups) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 395 | { |
| 396 | struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 397 | |
| 398 | *groups = pctrl->soc->functions[function].groups; |
| 399 | *ngroups = pctrl->soc->functions[function].ngroups; |
| 400 | return 0; |
| 401 | } |
| 402 | |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 403 | static int intel_pinmux_set_mux(struct pinctrl_dev *pctldev, |
| 404 | unsigned int function, unsigned int group) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 405 | { |
| 406 | struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 407 | const struct intel_pingroup *grp = &pctrl->soc->groups[group]; |
| 408 | unsigned long flags; |
| 409 | int i; |
| 410 | |
Mika Westerberg | 27d9098 | 2016-06-16 11:25:36 +0300 | [diff] [blame] | 411 | raw_spin_lock_irqsave(&pctrl->lock, flags); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 412 | |
| 413 | /* |
| 414 | * All pins in the groups needs to be accessible and writable |
| 415 | * before we can enable the mux for this group. |
| 416 | */ |
| 417 | for (i = 0; i < grp->npins; i++) { |
| 418 | if (!intel_pad_usable(pctrl, grp->pins[i])) { |
Mika Westerberg | 27d9098 | 2016-06-16 11:25:36 +0300 | [diff] [blame] | 419 | raw_spin_unlock_irqrestore(&pctrl->lock, flags); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 420 | return -EBUSY; |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | /* Now enable the mux setting for each pin in the group */ |
| 425 | for (i = 0; i < grp->npins; i++) { |
| 426 | void __iomem *padcfg0; |
| 427 | u32 value; |
| 428 | |
| 429 | padcfg0 = intel_get_padcfg(pctrl, grp->pins[i], PADCFG0); |
| 430 | value = readl(padcfg0); |
| 431 | |
| 432 | value &= ~PADCFG0_PMODE_MASK; |
Mika Westerberg | 1f6b419 | 2017-06-06 16:18:18 +0300 | [diff] [blame] | 433 | |
| 434 | if (grp->modes) |
| 435 | value |= grp->modes[i] << PADCFG0_PMODE_SHIFT; |
| 436 | else |
| 437 | value |= grp->mode << PADCFG0_PMODE_SHIFT; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 438 | |
| 439 | writel(value, padcfg0); |
| 440 | } |
| 441 | |
Mika Westerberg | 27d9098 | 2016-06-16 11:25:36 +0300 | [diff] [blame] | 442 | raw_spin_unlock_irqrestore(&pctrl->lock, flags); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 443 | |
| 444 | return 0; |
| 445 | } |
| 446 | |
Andy Shevchenko | 17fab47 | 2017-01-02 14:07:22 +0200 | [diff] [blame] | 447 | static void __intel_gpio_set_direction(void __iomem *padcfg0, bool input) |
| 448 | { |
| 449 | u32 value; |
| 450 | |
| 451 | value = readl(padcfg0); |
| 452 | if (input) { |
| 453 | value &= ~PADCFG0_GPIORXDIS; |
| 454 | value |= PADCFG0_GPIOTXDIS; |
| 455 | } else { |
| 456 | value &= ~PADCFG0_GPIOTXDIS; |
| 457 | value |= PADCFG0_GPIORXDIS; |
| 458 | } |
| 459 | writel(value, padcfg0); |
| 460 | } |
| 461 | |
Andy Shevchenko | 4973ddc | 2019-10-14 12:51:04 +0300 | [diff] [blame] | 462 | static int intel_gpio_get_gpio_mode(void __iomem *padcfg0) |
| 463 | { |
| 464 | return (readl(padcfg0) & PADCFG0_PMODE_MASK) >> PADCFG0_PMODE_SHIFT; |
| 465 | } |
| 466 | |
Mika Westerberg | f5a26ac | 2017-11-29 16:25:44 +0300 | [diff] [blame] | 467 | static void intel_gpio_set_gpio_mode(void __iomem *padcfg0) |
| 468 | { |
| 469 | u32 value; |
| 470 | |
| 471 | /* Put the pad into GPIO mode */ |
| 472 | value = readl(padcfg0) & ~PADCFG0_PMODE_MASK; |
| 473 | /* Disable SCI/SMI/NMI generation */ |
| 474 | value &= ~(PADCFG0_GPIROUTIOXAPIC | PADCFG0_GPIROUTSCI); |
| 475 | value &= ~(PADCFG0_GPIROUTSMI | PADCFG0_GPIROUTNMI); |
| 476 | writel(value, padcfg0); |
| 477 | } |
| 478 | |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 479 | static int intel_gpio_request_enable(struct pinctrl_dev *pctldev, |
| 480 | struct pinctrl_gpio_range *range, |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 481 | unsigned int pin) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 482 | { |
| 483 | struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 484 | void __iomem *padcfg0; |
| 485 | unsigned long flags; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 486 | |
Mika Westerberg | 27d9098 | 2016-06-16 11:25:36 +0300 | [diff] [blame] | 487 | raw_spin_lock_irqsave(&pctrl->lock, flags); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 488 | |
Andy Shevchenko | 1bd2315 | 2019-08-12 19:14:01 +0300 | [diff] [blame] | 489 | if (!intel_pad_owned_by_host(pctrl, pin)) { |
Mika Westerberg | 27d9098 | 2016-06-16 11:25:36 +0300 | [diff] [blame] | 490 | raw_spin_unlock_irqrestore(&pctrl->lock, flags); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 491 | return -EBUSY; |
| 492 | } |
| 493 | |
Andy Shevchenko | 1bd2315 | 2019-08-12 19:14:01 +0300 | [diff] [blame] | 494 | if (!intel_pad_is_unlocked(pctrl, pin)) { |
| 495 | raw_spin_unlock_irqrestore(&pctrl->lock, flags); |
| 496 | return 0; |
| 497 | } |
| 498 | |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 499 | padcfg0 = intel_get_padcfg(pctrl, pin, PADCFG0); |
Andy Shevchenko | 4973ddc | 2019-10-14 12:51:04 +0300 | [diff] [blame] | 500 | |
| 501 | /* |
| 502 | * If pin is already configured in GPIO mode, we assume that |
| 503 | * firmware provides correct settings. In such case we avoid |
| 504 | * potential glitches on the pin. Otherwise, for the pin in |
| 505 | * alternative mode, consumer has to supply respective flags. |
| 506 | */ |
| 507 | if (intel_gpio_get_gpio_mode(padcfg0) == PADCFG0_PMODE_GPIO) { |
| 508 | raw_spin_unlock_irqrestore(&pctrl->lock, flags); |
| 509 | return 0; |
| 510 | } |
| 511 | |
Mika Westerberg | f5a26ac | 2017-11-29 16:25:44 +0300 | [diff] [blame] | 512 | intel_gpio_set_gpio_mode(padcfg0); |
Andy Shevchenko | 4973ddc | 2019-10-14 12:51:04 +0300 | [diff] [blame] | 513 | |
Andy Shevchenko | 17fab47 | 2017-01-02 14:07:22 +0200 | [diff] [blame] | 514 | /* Disable TX buffer and enable RX (this will be input) */ |
| 515 | __intel_gpio_set_direction(padcfg0, true); |
| 516 | |
Mika Westerberg | 27d9098 | 2016-06-16 11:25:36 +0300 | [diff] [blame] | 517 | raw_spin_unlock_irqrestore(&pctrl->lock, flags); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 518 | |
| 519 | return 0; |
| 520 | } |
| 521 | |
| 522 | static int intel_gpio_set_direction(struct pinctrl_dev *pctldev, |
| 523 | struct pinctrl_gpio_range *range, |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 524 | unsigned int pin, bool input) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 525 | { |
| 526 | struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 527 | void __iomem *padcfg0; |
| 528 | unsigned long flags; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 529 | |
Mika Westerberg | 27d9098 | 2016-06-16 11:25:36 +0300 | [diff] [blame] | 530 | raw_spin_lock_irqsave(&pctrl->lock, flags); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 531 | |
| 532 | padcfg0 = intel_get_padcfg(pctrl, pin, PADCFG0); |
Andy Shevchenko | 17fab47 | 2017-01-02 14:07:22 +0200 | [diff] [blame] | 533 | __intel_gpio_set_direction(padcfg0, input); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 534 | |
Mika Westerberg | 27d9098 | 2016-06-16 11:25:36 +0300 | [diff] [blame] | 535 | raw_spin_unlock_irqrestore(&pctrl->lock, flags); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 536 | |
| 537 | return 0; |
| 538 | } |
| 539 | |
| 540 | static const struct pinmux_ops intel_pinmux_ops = { |
| 541 | .get_functions_count = intel_get_functions_count, |
| 542 | .get_function_name = intel_get_function_name, |
| 543 | .get_function_groups = intel_get_function_groups, |
| 544 | .set_mux = intel_pinmux_set_mux, |
| 545 | .gpio_request_enable = intel_gpio_request_enable, |
| 546 | .gpio_set_direction = intel_gpio_set_direction, |
| 547 | }; |
| 548 | |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 549 | static int intel_config_get(struct pinctrl_dev *pctldev, unsigned int pin, |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 550 | unsigned long *config) |
| 551 | { |
| 552 | struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 553 | enum pin_config_param param = pinconf_to_config_param(*config); |
Mika Westerberg | 04cc058 | 2017-01-27 13:07:15 +0300 | [diff] [blame] | 554 | const struct intel_community *community; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 555 | u32 value, term; |
Mika Westerberg | e57725e | 2017-01-27 13:07:14 +0300 | [diff] [blame] | 556 | u32 arg = 0; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 557 | |
| 558 | if (!intel_pad_owned_by_host(pctrl, pin)) |
| 559 | return -ENOTSUPP; |
| 560 | |
Mika Westerberg | 04cc058 | 2017-01-27 13:07:15 +0300 | [diff] [blame] | 561 | community = intel_get_community(pctrl, pin); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 562 | value = readl(intel_get_padcfg(pctrl, pin, PADCFG1)); |
| 563 | term = (value & PADCFG1_TERM_MASK) >> PADCFG1_TERM_SHIFT; |
| 564 | |
| 565 | switch (param) { |
| 566 | case PIN_CONFIG_BIAS_DISABLE: |
| 567 | if (term) |
| 568 | return -EINVAL; |
| 569 | break; |
| 570 | |
| 571 | case PIN_CONFIG_BIAS_PULL_UP: |
| 572 | if (!term || !(value & PADCFG1_TERM_UP)) |
| 573 | return -EINVAL; |
| 574 | |
| 575 | switch (term) { |
| 576 | case PADCFG1_TERM_1K: |
| 577 | arg = 1000; |
| 578 | break; |
| 579 | case PADCFG1_TERM_2K: |
| 580 | arg = 2000; |
| 581 | break; |
| 582 | case PADCFG1_TERM_5K: |
| 583 | arg = 5000; |
| 584 | break; |
| 585 | case PADCFG1_TERM_20K: |
| 586 | arg = 20000; |
| 587 | break; |
| 588 | } |
| 589 | |
| 590 | break; |
| 591 | |
| 592 | case PIN_CONFIG_BIAS_PULL_DOWN: |
| 593 | if (!term || value & PADCFG1_TERM_UP) |
| 594 | return -EINVAL; |
| 595 | |
| 596 | switch (term) { |
Mika Westerberg | 04cc058 | 2017-01-27 13:07:15 +0300 | [diff] [blame] | 597 | case PADCFG1_TERM_1K: |
| 598 | if (!(community->features & PINCTRL_FEATURE_1K_PD)) |
| 599 | return -EINVAL; |
| 600 | arg = 1000; |
| 601 | break; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 602 | case PADCFG1_TERM_5K: |
| 603 | arg = 5000; |
| 604 | break; |
| 605 | case PADCFG1_TERM_20K: |
| 606 | arg = 20000; |
| 607 | break; |
| 608 | } |
| 609 | |
| 610 | break; |
| 611 | |
Mika Westerberg | e57725e | 2017-01-27 13:07:14 +0300 | [diff] [blame] | 612 | case PIN_CONFIG_INPUT_DEBOUNCE: { |
| 613 | void __iomem *padcfg2; |
| 614 | u32 v; |
| 615 | |
| 616 | padcfg2 = intel_get_padcfg(pctrl, pin, PADCFG2); |
| 617 | if (!padcfg2) |
| 618 | return -ENOTSUPP; |
| 619 | |
| 620 | v = readl(padcfg2); |
| 621 | if (!(v & PADCFG2_DEBEN)) |
| 622 | return -EINVAL; |
| 623 | |
| 624 | v = (v & PADCFG2_DEBOUNCE_MASK) >> PADCFG2_DEBOUNCE_SHIFT; |
Andy Shevchenko | 6a33a1d | 2019-08-07 16:41:50 +0300 | [diff] [blame] | 625 | arg = BIT(v) * DEBOUNCE_PERIOD_NSEC / NSEC_PER_USEC; |
Mika Westerberg | e57725e | 2017-01-27 13:07:14 +0300 | [diff] [blame] | 626 | |
| 627 | break; |
| 628 | } |
| 629 | |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 630 | default: |
| 631 | return -ENOTSUPP; |
| 632 | } |
| 633 | |
| 634 | *config = pinconf_to_config_packed(param, arg); |
| 635 | return 0; |
| 636 | } |
| 637 | |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 638 | static int intel_config_set_pull(struct intel_pinctrl *pctrl, unsigned int pin, |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 639 | unsigned long config) |
| 640 | { |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 641 | unsigned int param = pinconf_to_config_param(config); |
| 642 | unsigned int arg = pinconf_to_config_argument(config); |
Mika Westerberg | 04cc058 | 2017-01-27 13:07:15 +0300 | [diff] [blame] | 643 | const struct intel_community *community; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 644 | void __iomem *padcfg1; |
| 645 | unsigned long flags; |
| 646 | int ret = 0; |
| 647 | u32 value; |
| 648 | |
Mika Westerberg | 27d9098 | 2016-06-16 11:25:36 +0300 | [diff] [blame] | 649 | raw_spin_lock_irqsave(&pctrl->lock, flags); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 650 | |
Mika Westerberg | 04cc058 | 2017-01-27 13:07:15 +0300 | [diff] [blame] | 651 | community = intel_get_community(pctrl, pin); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 652 | padcfg1 = intel_get_padcfg(pctrl, pin, PADCFG1); |
| 653 | value = readl(padcfg1); |
| 654 | |
| 655 | switch (param) { |
| 656 | case PIN_CONFIG_BIAS_DISABLE: |
| 657 | value &= ~(PADCFG1_TERM_MASK | PADCFG1_TERM_UP); |
| 658 | break; |
| 659 | |
| 660 | case PIN_CONFIG_BIAS_PULL_UP: |
| 661 | value &= ~PADCFG1_TERM_MASK; |
| 662 | |
| 663 | value |= PADCFG1_TERM_UP; |
| 664 | |
| 665 | switch (arg) { |
| 666 | case 20000: |
| 667 | value |= PADCFG1_TERM_20K << PADCFG1_TERM_SHIFT; |
| 668 | break; |
| 669 | case 5000: |
| 670 | value |= PADCFG1_TERM_5K << PADCFG1_TERM_SHIFT; |
| 671 | break; |
| 672 | case 2000: |
| 673 | value |= PADCFG1_TERM_2K << PADCFG1_TERM_SHIFT; |
| 674 | break; |
| 675 | case 1000: |
| 676 | value |= PADCFG1_TERM_1K << PADCFG1_TERM_SHIFT; |
| 677 | break; |
| 678 | default: |
| 679 | ret = -EINVAL; |
| 680 | } |
| 681 | |
| 682 | break; |
| 683 | |
| 684 | case PIN_CONFIG_BIAS_PULL_DOWN: |
| 685 | value &= ~(PADCFG1_TERM_UP | PADCFG1_TERM_MASK); |
| 686 | |
| 687 | switch (arg) { |
| 688 | case 20000: |
| 689 | value |= PADCFG1_TERM_20K << PADCFG1_TERM_SHIFT; |
| 690 | break; |
| 691 | case 5000: |
| 692 | value |= PADCFG1_TERM_5K << PADCFG1_TERM_SHIFT; |
| 693 | break; |
Mika Westerberg | 04cc058 | 2017-01-27 13:07:15 +0300 | [diff] [blame] | 694 | case 1000: |
Dan Carpenter | aa1dd80 | 2017-02-07 16:20:08 +0300 | [diff] [blame] | 695 | if (!(community->features & PINCTRL_FEATURE_1K_PD)) { |
| 696 | ret = -EINVAL; |
| 697 | break; |
| 698 | } |
Mika Westerberg | 04cc058 | 2017-01-27 13:07:15 +0300 | [diff] [blame] | 699 | value |= PADCFG1_TERM_1K << PADCFG1_TERM_SHIFT; |
| 700 | break; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 701 | default: |
| 702 | ret = -EINVAL; |
| 703 | } |
| 704 | |
| 705 | break; |
| 706 | } |
| 707 | |
| 708 | if (!ret) |
| 709 | writel(value, padcfg1); |
| 710 | |
Mika Westerberg | 27d9098 | 2016-06-16 11:25:36 +0300 | [diff] [blame] | 711 | raw_spin_unlock_irqrestore(&pctrl->lock, flags); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 712 | |
| 713 | return ret; |
| 714 | } |
| 715 | |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 716 | static int intel_config_set_debounce(struct intel_pinctrl *pctrl, |
| 717 | unsigned int pin, unsigned int debounce) |
Mika Westerberg | e57725e | 2017-01-27 13:07:14 +0300 | [diff] [blame] | 718 | { |
| 719 | void __iomem *padcfg0, *padcfg2; |
| 720 | unsigned long flags; |
| 721 | u32 value0, value2; |
| 722 | int ret = 0; |
| 723 | |
| 724 | padcfg2 = intel_get_padcfg(pctrl, pin, PADCFG2); |
| 725 | if (!padcfg2) |
| 726 | return -ENOTSUPP; |
| 727 | |
| 728 | padcfg0 = intel_get_padcfg(pctrl, pin, PADCFG0); |
| 729 | |
| 730 | raw_spin_lock_irqsave(&pctrl->lock, flags); |
| 731 | |
| 732 | value0 = readl(padcfg0); |
| 733 | value2 = readl(padcfg2); |
| 734 | |
| 735 | /* Disable glitch filter and debouncer */ |
| 736 | value0 &= ~PADCFG0_PREGFRXSEL; |
| 737 | value2 &= ~(PADCFG2_DEBEN | PADCFG2_DEBOUNCE_MASK); |
| 738 | |
| 739 | if (debounce) { |
| 740 | unsigned long v; |
| 741 | |
Andy Shevchenko | 6a33a1d | 2019-08-07 16:41:50 +0300 | [diff] [blame] | 742 | v = order_base_2(debounce * NSEC_PER_USEC / DEBOUNCE_PERIOD_NSEC); |
Mika Westerberg | e57725e | 2017-01-27 13:07:14 +0300 | [diff] [blame] | 743 | if (v < 3 || v > 15) { |
| 744 | ret = -EINVAL; |
| 745 | goto exit_unlock; |
| 746 | } else { |
| 747 | /* Enable glitch filter and debouncer */ |
| 748 | value0 |= PADCFG0_PREGFRXSEL; |
| 749 | value2 |= v << PADCFG2_DEBOUNCE_SHIFT; |
| 750 | value2 |= PADCFG2_DEBEN; |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | writel(value0, padcfg0); |
| 755 | writel(value2, padcfg2); |
| 756 | |
| 757 | exit_unlock: |
| 758 | raw_spin_unlock_irqrestore(&pctrl->lock, flags); |
| 759 | |
| 760 | return ret; |
| 761 | } |
| 762 | |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 763 | static int intel_config_set(struct pinctrl_dev *pctldev, unsigned int pin, |
| 764 | unsigned long *configs, unsigned int nconfigs) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 765 | { |
| 766 | struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); |
| 767 | int i, ret; |
| 768 | |
| 769 | if (!intel_pad_usable(pctrl, pin)) |
| 770 | return -ENOTSUPP; |
| 771 | |
| 772 | for (i = 0; i < nconfigs; i++) { |
| 773 | switch (pinconf_to_config_param(configs[i])) { |
| 774 | case PIN_CONFIG_BIAS_DISABLE: |
| 775 | case PIN_CONFIG_BIAS_PULL_UP: |
| 776 | case PIN_CONFIG_BIAS_PULL_DOWN: |
| 777 | ret = intel_config_set_pull(pctrl, pin, configs[i]); |
| 778 | if (ret) |
| 779 | return ret; |
| 780 | break; |
| 781 | |
Mika Westerberg | e57725e | 2017-01-27 13:07:14 +0300 | [diff] [blame] | 782 | case PIN_CONFIG_INPUT_DEBOUNCE: |
| 783 | ret = intel_config_set_debounce(pctrl, pin, |
| 784 | pinconf_to_config_argument(configs[i])); |
| 785 | if (ret) |
| 786 | return ret; |
| 787 | break; |
| 788 | |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 789 | default: |
| 790 | return -ENOTSUPP; |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | return 0; |
| 795 | } |
| 796 | |
| 797 | static const struct pinconf_ops intel_pinconf_ops = { |
| 798 | .is_generic = true, |
| 799 | .pin_config_get = intel_config_get, |
| 800 | .pin_config_set = intel_config_set, |
| 801 | }; |
| 802 | |
| 803 | static const struct pinctrl_desc intel_pinctrl_desc = { |
| 804 | .pctlops = &intel_pinctrl_ops, |
| 805 | .pmxops = &intel_pinmux_ops, |
| 806 | .confops = &intel_pinconf_ops, |
| 807 | .owner = THIS_MODULE, |
| 808 | }; |
| 809 | |
Mika Westerberg | a60eac3 | 2017-11-27 16:54:43 +0300 | [diff] [blame] | 810 | /** |
| 811 | * intel_gpio_to_pin() - Translate from GPIO offset to pin number |
| 812 | * @pctrl: Pinctrl structure |
| 813 | * @offset: GPIO offset from gpiolib |
Andy Shevchenko | 946ffef | 2018-09-26 17:43:17 +0300 | [diff] [blame] | 814 | * @community: Community is filled here if not %NULL |
Mika Westerberg | a60eac3 | 2017-11-27 16:54:43 +0300 | [diff] [blame] | 815 | * @padgrp: Pad group is filled here if not %NULL |
| 816 | * |
| 817 | * When coming through gpiolib irqchip, the GPIO offset is not |
| 818 | * automatically translated to pinctrl pin number. This function can be |
| 819 | * used to find out the corresponding pinctrl pin. |
| 820 | */ |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 821 | static int intel_gpio_to_pin(struct intel_pinctrl *pctrl, unsigned int offset, |
Mika Westerberg | a60eac3 | 2017-11-27 16:54:43 +0300 | [diff] [blame] | 822 | const struct intel_community **community, |
| 823 | const struct intel_padgroup **padgrp) |
| 824 | { |
| 825 | int i; |
| 826 | |
| 827 | for (i = 0; i < pctrl->ncommunities; i++) { |
| 828 | const struct intel_community *comm = &pctrl->communities[i]; |
| 829 | int j; |
| 830 | |
| 831 | for (j = 0; j < comm->ngpps; j++) { |
| 832 | const struct intel_padgroup *pgrp = &comm->gpps[j]; |
| 833 | |
| 834 | if (pgrp->gpio_base < 0) |
| 835 | continue; |
| 836 | |
| 837 | if (offset >= pgrp->gpio_base && |
| 838 | offset < pgrp->gpio_base + pgrp->size) { |
| 839 | int pin; |
| 840 | |
| 841 | pin = pgrp->base + offset - pgrp->gpio_base; |
| 842 | if (community) |
| 843 | *community = comm; |
| 844 | if (padgrp) |
| 845 | *padgrp = pgrp; |
| 846 | |
| 847 | return pin; |
| 848 | } |
| 849 | } |
| 850 | } |
| 851 | |
| 852 | return -EINVAL; |
| 853 | } |
| 854 | |
Chris Chiu | 6cb0880 | 2019-08-16 17:38:38 +0800 | [diff] [blame] | 855 | /** |
| 856 | * intel_pin_to_gpio() - Translate from pin number to GPIO offset |
| 857 | * @pctrl: Pinctrl structure |
| 858 | * @pin: pin number |
| 859 | * |
| 860 | * Translate the pin number of pinctrl to GPIO offset |
| 861 | */ |
Arnd Bergmann | 55dac43 | 2019-09-06 20:51:59 +0200 | [diff] [blame] | 862 | static __maybe_unused int intel_pin_to_gpio(struct intel_pinctrl *pctrl, int pin) |
Chris Chiu | 6cb0880 | 2019-08-16 17:38:38 +0800 | [diff] [blame] | 863 | { |
| 864 | const struct intel_community *community; |
| 865 | const struct intel_padgroup *padgrp; |
| 866 | |
| 867 | community = intel_get_community(pctrl, pin); |
| 868 | if (!community) |
| 869 | return -EINVAL; |
| 870 | |
| 871 | padgrp = intel_community_get_padgroup(community, pin); |
| 872 | if (!padgrp) |
| 873 | return -EINVAL; |
| 874 | |
| 875 | return pin - padgrp->base + padgrp->gpio_base; |
| 876 | } |
| 877 | |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 878 | static int intel_gpio_get(struct gpio_chip *chip, unsigned int offset) |
Andy Shevchenko | 55aedef5 | 2018-07-25 15:42:08 +0300 | [diff] [blame] | 879 | { |
Mika Westerberg | 96147db | 2018-09-18 18:36:21 +0300 | [diff] [blame] | 880 | struct intel_pinctrl *pctrl = gpiochip_get_data(chip); |
| 881 | void __iomem *reg; |
| 882 | u32 padcfg0; |
Andy Shevchenko | 55aedef5 | 2018-07-25 15:42:08 +0300 | [diff] [blame] | 883 | int pin; |
| 884 | |
Mika Westerberg | 96147db | 2018-09-18 18:36:21 +0300 | [diff] [blame] | 885 | pin = intel_gpio_to_pin(pctrl, offset, NULL, NULL); |
| 886 | if (pin < 0) |
| 887 | return -EINVAL; |
| 888 | |
| 889 | reg = intel_get_padcfg(pctrl, pin, PADCFG0); |
| 890 | if (!reg) |
| 891 | return -EINVAL; |
| 892 | |
| 893 | padcfg0 = readl(reg); |
| 894 | if (!(padcfg0 & PADCFG0_GPIOTXDIS)) |
| 895 | return !!(padcfg0 & PADCFG0_GPIOTXSTATE); |
| 896 | |
| 897 | return !!(padcfg0 & PADCFG0_GPIORXSTATE); |
Andy Shevchenko | 55aedef5 | 2018-07-25 15:42:08 +0300 | [diff] [blame] | 898 | } |
| 899 | |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 900 | static void intel_gpio_set(struct gpio_chip *chip, unsigned int offset, |
| 901 | int value) |
Mika Westerberg | 96147db | 2018-09-18 18:36:21 +0300 | [diff] [blame] | 902 | { |
| 903 | struct intel_pinctrl *pctrl = gpiochip_get_data(chip); |
| 904 | unsigned long flags; |
| 905 | void __iomem *reg; |
| 906 | u32 padcfg0; |
| 907 | int pin; |
| 908 | |
| 909 | pin = intel_gpio_to_pin(pctrl, offset, NULL, NULL); |
| 910 | if (pin < 0) |
| 911 | return; |
| 912 | |
| 913 | reg = intel_get_padcfg(pctrl, pin, PADCFG0); |
| 914 | if (!reg) |
| 915 | return; |
| 916 | |
| 917 | raw_spin_lock_irqsave(&pctrl->lock, flags); |
| 918 | padcfg0 = readl(reg); |
| 919 | if (value) |
| 920 | padcfg0 |= PADCFG0_GPIOTXSTATE; |
| 921 | else |
| 922 | padcfg0 &= ~PADCFG0_GPIOTXSTATE; |
| 923 | writel(padcfg0, reg); |
| 924 | raw_spin_unlock_irqrestore(&pctrl->lock, flags); |
| 925 | } |
| 926 | |
| 927 | static int intel_gpio_get_direction(struct gpio_chip *chip, unsigned int offset) |
| 928 | { |
| 929 | struct intel_pinctrl *pctrl = gpiochip_get_data(chip); |
| 930 | void __iomem *reg; |
| 931 | u32 padcfg0; |
| 932 | int pin; |
| 933 | |
| 934 | pin = intel_gpio_to_pin(pctrl, offset, NULL, NULL); |
| 935 | if (pin < 0) |
| 936 | return -EINVAL; |
| 937 | |
| 938 | reg = intel_get_padcfg(pctrl, pin, PADCFG0); |
| 939 | if (!reg) |
| 940 | return -EINVAL; |
| 941 | |
| 942 | padcfg0 = readl(reg); |
| 943 | |
| 944 | if (padcfg0 & PADCFG0_PMODE_MASK) |
| 945 | return -EINVAL; |
| 946 | |
| 947 | return !!(padcfg0 & PADCFG0_GPIOTXDIS); |
| 948 | } |
| 949 | |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 950 | static int intel_gpio_direction_input(struct gpio_chip *chip, unsigned int offset) |
Mika Westerberg | 96147db | 2018-09-18 18:36:21 +0300 | [diff] [blame] | 951 | { |
| 952 | return pinctrl_gpio_direction_input(chip->base + offset); |
| 953 | } |
| 954 | |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 955 | static int intel_gpio_direction_output(struct gpio_chip *chip, unsigned int offset, |
Mika Westerberg | 96147db | 2018-09-18 18:36:21 +0300 | [diff] [blame] | 956 | int value) |
| 957 | { |
| 958 | intel_gpio_set(chip, offset, value); |
| 959 | return pinctrl_gpio_direction_output(chip->base + offset); |
| 960 | } |
| 961 | |
| 962 | static const struct gpio_chip intel_gpio_chip = { |
| 963 | .owner = THIS_MODULE, |
| 964 | .request = gpiochip_generic_request, |
| 965 | .free = gpiochip_generic_free, |
| 966 | .get_direction = intel_gpio_get_direction, |
| 967 | .direction_input = intel_gpio_direction_input, |
| 968 | .direction_output = intel_gpio_direction_output, |
| 969 | .get = intel_gpio_get, |
| 970 | .set = intel_gpio_set, |
| 971 | .set_config = gpiochip_generic_config, |
| 972 | }; |
| 973 | |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 974 | static void intel_gpio_irq_ack(struct irq_data *d) |
| 975 | { |
| 976 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
Linus Walleij | acfd4c6 | 2015-12-08 00:18:59 +0100 | [diff] [blame] | 977 | struct intel_pinctrl *pctrl = gpiochip_get_data(gc); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 978 | const struct intel_community *community; |
Mika Westerberg | a60eac3 | 2017-11-27 16:54:43 +0300 | [diff] [blame] | 979 | const struct intel_padgroup *padgrp; |
| 980 | int pin; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 981 | |
Mika Westerberg | a60eac3 | 2017-11-27 16:54:43 +0300 | [diff] [blame] | 982 | pin = intel_gpio_to_pin(pctrl, irqd_to_hwirq(d), &community, &padgrp); |
| 983 | if (pin >= 0) { |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 984 | unsigned int gpp, gpp_offset, is_offset; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 985 | |
Mika Westerberg | 919eb47 | 2017-06-06 16:18:17 +0300 | [diff] [blame] | 986 | gpp = padgrp->reg_num; |
| 987 | gpp_offset = padgroup_offset(padgrp, pin); |
Mika Westerberg | cf769bd | 2017-10-23 15:40:25 +0300 | [diff] [blame] | 988 | is_offset = community->is_offset + gpp * 4; |
Mika Westerberg | 919eb47 | 2017-06-06 16:18:17 +0300 | [diff] [blame] | 989 | |
| 990 | raw_spin_lock(&pctrl->lock); |
Mika Westerberg | cf769bd | 2017-10-23 15:40:25 +0300 | [diff] [blame] | 991 | writel(BIT(gpp_offset), community->regs + is_offset); |
Mika Westerberg | 919eb47 | 2017-06-06 16:18:17 +0300 | [diff] [blame] | 992 | raw_spin_unlock(&pctrl->lock); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 993 | } |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | static void intel_gpio_irq_mask_unmask(struct irq_data *d, bool mask) |
| 997 | { |
| 998 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
Linus Walleij | acfd4c6 | 2015-12-08 00:18:59 +0100 | [diff] [blame] | 999 | struct intel_pinctrl *pctrl = gpiochip_get_data(gc); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1000 | const struct intel_community *community; |
Mika Westerberg | a60eac3 | 2017-11-27 16:54:43 +0300 | [diff] [blame] | 1001 | const struct intel_padgroup *padgrp; |
| 1002 | int pin; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1003 | |
Mika Westerberg | a60eac3 | 2017-11-27 16:54:43 +0300 | [diff] [blame] | 1004 | pin = intel_gpio_to_pin(pctrl, irqd_to_hwirq(d), &community, &padgrp); |
| 1005 | if (pin >= 0) { |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 1006 | unsigned int gpp, gpp_offset; |
Mika Westerberg | 919eb47 | 2017-06-06 16:18:17 +0300 | [diff] [blame] | 1007 | unsigned long flags; |
Kai-Heng Feng | 670784f | 2019-04-30 16:37:53 +0800 | [diff] [blame] | 1008 | void __iomem *reg, *is; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1009 | u32 value; |
| 1010 | |
Mika Westerberg | 919eb47 | 2017-06-06 16:18:17 +0300 | [diff] [blame] | 1011 | gpp = padgrp->reg_num; |
| 1012 | gpp_offset = padgroup_offset(padgrp, pin); |
| 1013 | |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1014 | reg = community->regs + community->ie_offset + gpp * 4; |
Kai-Heng Feng | 670784f | 2019-04-30 16:37:53 +0800 | [diff] [blame] | 1015 | is = community->regs + community->is_offset + gpp * 4; |
Mika Westerberg | 919eb47 | 2017-06-06 16:18:17 +0300 | [diff] [blame] | 1016 | |
| 1017 | raw_spin_lock_irqsave(&pctrl->lock, flags); |
Kai-Heng Feng | 670784f | 2019-04-30 16:37:53 +0800 | [diff] [blame] | 1018 | |
| 1019 | /* Clear interrupt status first to avoid unexpected interrupt */ |
| 1020 | writel(BIT(gpp_offset), is); |
| 1021 | |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1022 | value = readl(reg); |
| 1023 | if (mask) |
| 1024 | value &= ~BIT(gpp_offset); |
| 1025 | else |
| 1026 | value |= BIT(gpp_offset); |
| 1027 | writel(value, reg); |
Mika Westerberg | 919eb47 | 2017-06-06 16:18:17 +0300 | [diff] [blame] | 1028 | raw_spin_unlock_irqrestore(&pctrl->lock, flags); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1029 | } |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | static void intel_gpio_irq_mask(struct irq_data *d) |
| 1033 | { |
| 1034 | intel_gpio_irq_mask_unmask(d, true); |
| 1035 | } |
| 1036 | |
| 1037 | static void intel_gpio_irq_unmask(struct irq_data *d) |
| 1038 | { |
| 1039 | intel_gpio_irq_mask_unmask(d, false); |
| 1040 | } |
| 1041 | |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 1042 | static int intel_gpio_irq_type(struct irq_data *d, unsigned int type) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1043 | { |
| 1044 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
Linus Walleij | acfd4c6 | 2015-12-08 00:18:59 +0100 | [diff] [blame] | 1045 | struct intel_pinctrl *pctrl = gpiochip_get_data(gc); |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 1046 | unsigned int pin = intel_gpio_to_pin(pctrl, irqd_to_hwirq(d), NULL, NULL); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1047 | unsigned long flags; |
| 1048 | void __iomem *reg; |
| 1049 | u32 value; |
| 1050 | |
| 1051 | reg = intel_get_padcfg(pctrl, pin, PADCFG0); |
| 1052 | if (!reg) |
| 1053 | return -EINVAL; |
| 1054 | |
Mika Westerberg | 4341e8a | 2015-10-21 13:08:44 +0300 | [diff] [blame] | 1055 | /* |
| 1056 | * If the pin is in ACPI mode it is still usable as a GPIO but it |
| 1057 | * cannot be used as IRQ because GPI_IS status bit will not be |
| 1058 | * updated by the host controller hardware. |
| 1059 | */ |
| 1060 | if (intel_pad_acpi_mode(pctrl, pin)) { |
| 1061 | dev_warn(pctrl->dev, "pin %u cannot be used as IRQ\n", pin); |
| 1062 | return -EPERM; |
| 1063 | } |
| 1064 | |
Mika Westerberg | 27d9098 | 2016-06-16 11:25:36 +0300 | [diff] [blame] | 1065 | raw_spin_lock_irqsave(&pctrl->lock, flags); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1066 | |
Mika Westerberg | f5a26ac | 2017-11-29 16:25:44 +0300 | [diff] [blame] | 1067 | intel_gpio_set_gpio_mode(reg); |
| 1068 | |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1069 | value = readl(reg); |
| 1070 | |
| 1071 | value &= ~(PADCFG0_RXEVCFG_MASK | PADCFG0_RXINV); |
| 1072 | |
| 1073 | if ((type & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH) { |
| 1074 | value |= PADCFG0_RXEVCFG_EDGE_BOTH << PADCFG0_RXEVCFG_SHIFT; |
| 1075 | } else if (type & IRQ_TYPE_EDGE_FALLING) { |
| 1076 | value |= PADCFG0_RXEVCFG_EDGE << PADCFG0_RXEVCFG_SHIFT; |
| 1077 | value |= PADCFG0_RXINV; |
| 1078 | } else if (type & IRQ_TYPE_EDGE_RISING) { |
| 1079 | value |= PADCFG0_RXEVCFG_EDGE << PADCFG0_RXEVCFG_SHIFT; |
Qipeng Zha | bf380cf | 2016-03-17 02:15:25 +0800 | [diff] [blame] | 1080 | } else if (type & IRQ_TYPE_LEVEL_MASK) { |
| 1081 | if (type & IRQ_TYPE_LEVEL_LOW) |
| 1082 | value |= PADCFG0_RXINV; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1083 | } else { |
| 1084 | value |= PADCFG0_RXEVCFG_DISABLED << PADCFG0_RXEVCFG_SHIFT; |
| 1085 | } |
| 1086 | |
| 1087 | writel(value, reg); |
| 1088 | |
| 1089 | if (type & IRQ_TYPE_EDGE_BOTH) |
Thomas Gleixner | fc756bc | 2015-06-23 15:52:45 +0200 | [diff] [blame] | 1090 | irq_set_handler_locked(d, handle_edge_irq); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1091 | else if (type & IRQ_TYPE_LEVEL_MASK) |
Thomas Gleixner | fc756bc | 2015-06-23 15:52:45 +0200 | [diff] [blame] | 1092 | irq_set_handler_locked(d, handle_level_irq); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1093 | |
Mika Westerberg | 27d9098 | 2016-06-16 11:25:36 +0300 | [diff] [blame] | 1094 | raw_spin_unlock_irqrestore(&pctrl->lock, flags); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1095 | |
| 1096 | return 0; |
| 1097 | } |
| 1098 | |
| 1099 | static int intel_gpio_irq_wake(struct irq_data *d, unsigned int on) |
| 1100 | { |
| 1101 | struct gpio_chip *gc = irq_data_get_irq_chip_data(d); |
Linus Walleij | acfd4c6 | 2015-12-08 00:18:59 +0100 | [diff] [blame] | 1102 | struct intel_pinctrl *pctrl = gpiochip_get_data(gc); |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 1103 | unsigned int pin = intel_gpio_to_pin(pctrl, irqd_to_hwirq(d), NULL, NULL); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1104 | |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1105 | if (on) |
Nilesh Bacchewar | 01dabe9 | 2016-09-21 16:35:23 -0700 | [diff] [blame] | 1106 | enable_irq_wake(pctrl->irq); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1107 | else |
Nilesh Bacchewar | 01dabe9 | 2016-09-21 16:35:23 -0700 | [diff] [blame] | 1108 | disable_irq_wake(pctrl->irq); |
Andy Shevchenko | 9a520fd | 2016-07-08 14:30:46 +0300 | [diff] [blame] | 1109 | |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1110 | dev_dbg(pctrl->dev, "%sable wake for pin %u\n", on ? "en" : "dis", pin); |
| 1111 | return 0; |
| 1112 | } |
| 1113 | |
Mika Westerberg | 193b40c | 2015-10-21 13:08:43 +0300 | [diff] [blame] | 1114 | static irqreturn_t intel_gpio_community_irq_handler(struct intel_pinctrl *pctrl, |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1115 | const struct intel_community *community) |
| 1116 | { |
Mika Westerberg | 193b40c | 2015-10-21 13:08:43 +0300 | [diff] [blame] | 1117 | struct gpio_chip *gc = &pctrl->chip; |
| 1118 | irqreturn_t ret = IRQ_NONE; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1119 | int gpp; |
| 1120 | |
| 1121 | for (gpp = 0; gpp < community->ngpps; gpp++) { |
Mika Westerberg | 919eb47 | 2017-06-06 16:18:17 +0300 | [diff] [blame] | 1122 | const struct intel_padgroup *padgrp = &community->gpps[gpp]; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1123 | unsigned long pending, enabled, gpp_offset; |
| 1124 | |
Mika Westerberg | cf769bd | 2017-10-23 15:40:25 +0300 | [diff] [blame] | 1125 | pending = readl(community->regs + community->is_offset + |
| 1126 | padgrp->reg_num * 4); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1127 | enabled = readl(community->regs + community->ie_offset + |
Mika Westerberg | 919eb47 | 2017-06-06 16:18:17 +0300 | [diff] [blame] | 1128 | padgrp->reg_num * 4); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1129 | |
| 1130 | /* Only interrupts that are enabled */ |
| 1131 | pending &= enabled; |
| 1132 | |
Mika Westerberg | 919eb47 | 2017-06-06 16:18:17 +0300 | [diff] [blame] | 1133 | for_each_set_bit(gpp_offset, &pending, padgrp->size) { |
Mika Westerberg | a60eac3 | 2017-11-27 16:54:43 +0300 | [diff] [blame] | 1134 | unsigned irq; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1135 | |
Thierry Reding | f0fbe7b | 2017-11-07 19:15:47 +0100 | [diff] [blame] | 1136 | irq = irq_find_mapping(gc->irq.domain, |
Mika Westerberg | a60eac3 | 2017-11-27 16:54:43 +0300 | [diff] [blame] | 1137 | padgrp->gpio_base + gpp_offset); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1138 | generic_handle_irq(irq); |
Mika Westerberg | 193b40c | 2015-10-21 13:08:43 +0300 | [diff] [blame] | 1139 | |
| 1140 | ret |= IRQ_HANDLED; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1141 | } |
| 1142 | } |
Mika Westerberg | 193b40c | 2015-10-21 13:08:43 +0300 | [diff] [blame] | 1143 | |
| 1144 | return ret; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1145 | } |
| 1146 | |
Mika Westerberg | 193b40c | 2015-10-21 13:08:43 +0300 | [diff] [blame] | 1147 | static irqreturn_t intel_gpio_irq(int irq, void *data) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1148 | { |
Mika Westerberg | 193b40c | 2015-10-21 13:08:43 +0300 | [diff] [blame] | 1149 | const struct intel_community *community; |
| 1150 | struct intel_pinctrl *pctrl = data; |
| 1151 | irqreturn_t ret = IRQ_NONE; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1152 | int i; |
| 1153 | |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1154 | /* Need to check all communities for pending interrupts */ |
Mika Westerberg | 193b40c | 2015-10-21 13:08:43 +0300 | [diff] [blame] | 1155 | for (i = 0; i < pctrl->ncommunities; i++) { |
| 1156 | community = &pctrl->communities[i]; |
| 1157 | ret |= intel_gpio_community_irq_handler(pctrl, community); |
| 1158 | } |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1159 | |
Mika Westerberg | 193b40c | 2015-10-21 13:08:43 +0300 | [diff] [blame] | 1160 | return ret; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1161 | } |
| 1162 | |
Mika Westerberg | a60eac3 | 2017-11-27 16:54:43 +0300 | [diff] [blame] | 1163 | static int intel_gpio_add_pin_ranges(struct intel_pinctrl *pctrl, |
| 1164 | const struct intel_community *community) |
| 1165 | { |
Colin Ian King | 33b6cb5 | 2017-12-04 17:08:15 +0000 | [diff] [blame] | 1166 | int ret = 0, i; |
Mika Westerberg | a60eac3 | 2017-11-27 16:54:43 +0300 | [diff] [blame] | 1167 | |
| 1168 | for (i = 0; i < community->ngpps; i++) { |
| 1169 | const struct intel_padgroup *gpp = &community->gpps[i]; |
| 1170 | |
| 1171 | if (gpp->gpio_base < 0) |
| 1172 | continue; |
| 1173 | |
| 1174 | ret = gpiochip_add_pin_range(&pctrl->chip, dev_name(pctrl->dev), |
| 1175 | gpp->gpio_base, gpp->base, |
| 1176 | gpp->size); |
| 1177 | if (ret) |
| 1178 | return ret; |
| 1179 | } |
| 1180 | |
| 1181 | return ret; |
| 1182 | } |
| 1183 | |
| 1184 | static unsigned intel_gpio_ngpio(const struct intel_pinctrl *pctrl) |
| 1185 | { |
| 1186 | const struct intel_community *community; |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 1187 | unsigned int ngpio = 0; |
Mika Westerberg | a60eac3 | 2017-11-27 16:54:43 +0300 | [diff] [blame] | 1188 | int i, j; |
| 1189 | |
| 1190 | for (i = 0; i < pctrl->ncommunities; i++) { |
| 1191 | community = &pctrl->communities[i]; |
| 1192 | for (j = 0; j < community->ngpps; j++) { |
| 1193 | const struct intel_padgroup *gpp = &community->gpps[j]; |
| 1194 | |
| 1195 | if (gpp->gpio_base < 0) |
| 1196 | continue; |
| 1197 | |
| 1198 | if (gpp->gpio_base + gpp->size > ngpio) |
| 1199 | ngpio = gpp->gpio_base + gpp->size; |
| 1200 | } |
| 1201 | } |
| 1202 | |
| 1203 | return ngpio; |
| 1204 | } |
| 1205 | |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1206 | static int intel_gpio_probe(struct intel_pinctrl *pctrl, int irq) |
| 1207 | { |
Mika Westerberg | a60eac3 | 2017-11-27 16:54:43 +0300 | [diff] [blame] | 1208 | int ret, i; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1209 | |
| 1210 | pctrl->chip = intel_gpio_chip; |
| 1211 | |
Andy Shevchenko | 57ff2df | 2019-09-16 17:47:51 +0300 | [diff] [blame] | 1212 | /* Setup GPIO chip */ |
Mika Westerberg | a60eac3 | 2017-11-27 16:54:43 +0300 | [diff] [blame] | 1213 | pctrl->chip.ngpio = intel_gpio_ngpio(pctrl); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1214 | pctrl->chip.label = dev_name(pctrl->dev); |
Linus Walleij | 58383c78 | 2015-11-04 09:56:26 +0100 | [diff] [blame] | 1215 | pctrl->chip.parent = pctrl->dev; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1216 | pctrl->chip.base = -1; |
Nilesh Bacchewar | 01dabe9 | 2016-09-21 16:35:23 -0700 | [diff] [blame] | 1217 | pctrl->irq = irq; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1218 | |
Andy Shevchenko | 57ff2df | 2019-09-16 17:47:51 +0300 | [diff] [blame] | 1219 | /* Setup IRQ chip */ |
| 1220 | pctrl->irqchip.name = dev_name(pctrl->dev); |
| 1221 | pctrl->irqchip.irq_ack = intel_gpio_irq_ack; |
| 1222 | pctrl->irqchip.irq_mask = intel_gpio_irq_mask; |
| 1223 | pctrl->irqchip.irq_unmask = intel_gpio_irq_unmask; |
| 1224 | pctrl->irqchip.irq_set_type = intel_gpio_irq_type; |
| 1225 | pctrl->irqchip.irq_set_wake = intel_gpio_irq_wake; |
| 1226 | pctrl->irqchip.flags = IRQCHIP_MASK_ON_SUSPEND; |
| 1227 | |
Mika Westerberg | f25c3aa | 2017-01-10 17:31:57 +0300 | [diff] [blame] | 1228 | ret = devm_gpiochip_add_data(pctrl->dev, &pctrl->chip, pctrl); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1229 | if (ret) { |
| 1230 | dev_err(pctrl->dev, "failed to register gpiochip\n"); |
| 1231 | return ret; |
| 1232 | } |
| 1233 | |
Mika Westerberg | a60eac3 | 2017-11-27 16:54:43 +0300 | [diff] [blame] | 1234 | for (i = 0; i < pctrl->ncommunities; i++) { |
| 1235 | struct intel_community *community = &pctrl->communities[i]; |
| 1236 | |
| 1237 | ret = intel_gpio_add_pin_ranges(pctrl, community); |
| 1238 | if (ret) { |
| 1239 | dev_err(pctrl->dev, "failed to add GPIO pin range\n"); |
| 1240 | return ret; |
| 1241 | } |
Mika Westerberg | 193b40c | 2015-10-21 13:08:43 +0300 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | /* |
| 1245 | * We need to request the interrupt here (instead of providing chip |
| 1246 | * to the irq directly) because on some platforms several GPIO |
| 1247 | * controllers share the same interrupt line. |
| 1248 | */ |
Mika Westerberg | 1a7d1cb | 2016-06-16 11:25:37 +0300 | [diff] [blame] | 1249 | ret = devm_request_irq(pctrl->dev, irq, intel_gpio_irq, |
| 1250 | IRQF_SHARED | IRQF_NO_THREAD, |
Mika Westerberg | 193b40c | 2015-10-21 13:08:43 +0300 | [diff] [blame] | 1251 | dev_name(pctrl->dev), pctrl); |
| 1252 | if (ret) { |
| 1253 | dev_err(pctrl->dev, "failed to request interrupt\n"); |
Mika Westerberg | f25c3aa | 2017-01-10 17:31:57 +0300 | [diff] [blame] | 1254 | return ret; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1255 | } |
| 1256 | |
Andy Shevchenko | 57ff2df | 2019-09-16 17:47:51 +0300 | [diff] [blame] | 1257 | ret = gpiochip_irqchip_add(&pctrl->chip, &pctrl->irqchip, 0, |
Andy Shevchenko | 3ae02c1 | 2016-11-25 13:31:16 +0200 | [diff] [blame] | 1258 | handle_bad_irq, IRQ_TYPE_NONE); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1259 | if (ret) { |
| 1260 | dev_err(pctrl->dev, "failed to add irqchip\n"); |
Mika Westerberg | f25c3aa | 2017-01-10 17:31:57 +0300 | [diff] [blame] | 1261 | return ret; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1262 | } |
| 1263 | |
Andy Shevchenko | 57ff2df | 2019-09-16 17:47:51 +0300 | [diff] [blame] | 1264 | gpiochip_set_chained_irqchip(&pctrl->chip, &pctrl->irqchip, irq, NULL); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1265 | return 0; |
| 1266 | } |
| 1267 | |
Mika Westerberg | 919eb47 | 2017-06-06 16:18:17 +0300 | [diff] [blame] | 1268 | static int intel_pinctrl_add_padgroups(struct intel_pinctrl *pctrl, |
| 1269 | struct intel_community *community) |
| 1270 | { |
| 1271 | struct intel_padgroup *gpps; |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 1272 | unsigned int npins = community->npins; |
| 1273 | unsigned int padown_num = 0; |
Mika Westerberg | 919eb47 | 2017-06-06 16:18:17 +0300 | [diff] [blame] | 1274 | size_t ngpps, i; |
| 1275 | |
| 1276 | if (community->gpps) |
| 1277 | ngpps = community->ngpps; |
| 1278 | else |
| 1279 | ngpps = DIV_ROUND_UP(community->npins, community->gpp_size); |
| 1280 | |
| 1281 | gpps = devm_kcalloc(pctrl->dev, ngpps, sizeof(*gpps), GFP_KERNEL); |
| 1282 | if (!gpps) |
| 1283 | return -ENOMEM; |
| 1284 | |
| 1285 | for (i = 0; i < ngpps; i++) { |
| 1286 | if (community->gpps) { |
| 1287 | gpps[i] = community->gpps[i]; |
| 1288 | } else { |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 1289 | unsigned int gpp_size = community->gpp_size; |
Mika Westerberg | 919eb47 | 2017-06-06 16:18:17 +0300 | [diff] [blame] | 1290 | |
| 1291 | gpps[i].reg_num = i; |
| 1292 | gpps[i].base = community->pin_base + i * gpp_size; |
| 1293 | gpps[i].size = min(gpp_size, npins); |
| 1294 | npins -= gpps[i].size; |
| 1295 | } |
| 1296 | |
| 1297 | if (gpps[i].size > 32) |
| 1298 | return -EINVAL; |
| 1299 | |
Mika Westerberg | a60eac3 | 2017-11-27 16:54:43 +0300 | [diff] [blame] | 1300 | if (!gpps[i].gpio_base) |
| 1301 | gpps[i].gpio_base = gpps[i].base; |
| 1302 | |
Mika Westerberg | 919eb47 | 2017-06-06 16:18:17 +0300 | [diff] [blame] | 1303 | gpps[i].padown_num = padown_num; |
| 1304 | |
| 1305 | /* |
| 1306 | * In older hardware the number of padown registers per |
| 1307 | * group is fixed regardless of the group size. |
| 1308 | */ |
| 1309 | if (community->gpp_num_padown_regs) |
| 1310 | padown_num += community->gpp_num_padown_regs; |
| 1311 | else |
| 1312 | padown_num += DIV_ROUND_UP(gpps[i].size * 4, 32); |
| 1313 | } |
| 1314 | |
| 1315 | community->ngpps = ngpps; |
| 1316 | community->gpps = gpps; |
| 1317 | |
| 1318 | return 0; |
| 1319 | } |
| 1320 | |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1321 | static int intel_pinctrl_pm_init(struct intel_pinctrl *pctrl) |
| 1322 | { |
| 1323 | #ifdef CONFIG_PM_SLEEP |
| 1324 | const struct intel_pinctrl_soc_data *soc = pctrl->soc; |
| 1325 | struct intel_community_context *communities; |
| 1326 | struct intel_pad_context *pads; |
| 1327 | int i; |
| 1328 | |
| 1329 | pads = devm_kcalloc(pctrl->dev, soc->npins, sizeof(*pads), GFP_KERNEL); |
| 1330 | if (!pads) |
| 1331 | return -ENOMEM; |
| 1332 | |
| 1333 | communities = devm_kcalloc(pctrl->dev, pctrl->ncommunities, |
| 1334 | sizeof(*communities), GFP_KERNEL); |
| 1335 | if (!communities) |
| 1336 | return -ENOMEM; |
| 1337 | |
| 1338 | |
| 1339 | for (i = 0; i < pctrl->ncommunities; i++) { |
| 1340 | struct intel_community *community = &pctrl->communities[i]; |
Chris Chiu | a0a5f76 | 2019-04-15 13:53:58 +0800 | [diff] [blame] | 1341 | u32 *intmask, *hostown; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1342 | |
| 1343 | intmask = devm_kcalloc(pctrl->dev, community->ngpps, |
| 1344 | sizeof(*intmask), GFP_KERNEL); |
| 1345 | if (!intmask) |
| 1346 | return -ENOMEM; |
| 1347 | |
| 1348 | communities[i].intmask = intmask; |
Chris Chiu | a0a5f76 | 2019-04-15 13:53:58 +0800 | [diff] [blame] | 1349 | |
| 1350 | hostown = devm_kcalloc(pctrl->dev, community->ngpps, |
| 1351 | sizeof(*hostown), GFP_KERNEL); |
| 1352 | if (!hostown) |
| 1353 | return -ENOMEM; |
| 1354 | |
| 1355 | communities[i].hostown = hostown; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1356 | } |
| 1357 | |
| 1358 | pctrl->context.pads = pads; |
| 1359 | pctrl->context.communities = communities; |
| 1360 | #endif |
| 1361 | |
| 1362 | return 0; |
| 1363 | } |
| 1364 | |
Andy Shevchenko | 0dd519e | 2018-10-17 19:10:27 +0300 | [diff] [blame] | 1365 | static int intel_pinctrl_probe(struct platform_device *pdev, |
| 1366 | const struct intel_pinctrl_soc_data *soc_data) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1367 | { |
| 1368 | struct intel_pinctrl *pctrl; |
| 1369 | int i, ret, irq; |
| 1370 | |
| 1371 | if (!soc_data) |
| 1372 | return -EINVAL; |
| 1373 | |
| 1374 | pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL); |
| 1375 | if (!pctrl) |
| 1376 | return -ENOMEM; |
| 1377 | |
| 1378 | pctrl->dev = &pdev->dev; |
| 1379 | pctrl->soc = soc_data; |
Mika Westerberg | 27d9098 | 2016-06-16 11:25:36 +0300 | [diff] [blame] | 1380 | raw_spin_lock_init(&pctrl->lock); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1381 | |
| 1382 | /* |
| 1383 | * Make a copy of the communities which we can use to hold pointers |
| 1384 | * to the registers. |
| 1385 | */ |
| 1386 | pctrl->ncommunities = pctrl->soc->ncommunities; |
| 1387 | pctrl->communities = devm_kcalloc(&pdev->dev, pctrl->ncommunities, |
| 1388 | sizeof(*pctrl->communities), GFP_KERNEL); |
| 1389 | if (!pctrl->communities) |
| 1390 | return -ENOMEM; |
| 1391 | |
| 1392 | for (i = 0; i < pctrl->ncommunities; i++) { |
| 1393 | struct intel_community *community = &pctrl->communities[i]; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1394 | void __iomem *regs; |
| 1395 | u32 padbar; |
| 1396 | |
| 1397 | *community = pctrl->soc->communities[i]; |
| 1398 | |
Andy Shevchenko | 9d5b6a9 | 2019-07-03 17:44:20 +0300 | [diff] [blame] | 1399 | regs = devm_platform_ioremap_resource(pdev, community->barno); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1400 | if (IS_ERR(regs)) |
| 1401 | return PTR_ERR(regs); |
| 1402 | |
Mika Westerberg | e57725e | 2017-01-27 13:07:14 +0300 | [diff] [blame] | 1403 | /* |
| 1404 | * Determine community features based on the revision if |
| 1405 | * not specified already. |
| 1406 | */ |
| 1407 | if (!community->features) { |
| 1408 | u32 rev; |
| 1409 | |
| 1410 | rev = (readl(regs + REVID) & REVID_MASK) >> REVID_SHIFT; |
Mika Westerberg | 04cc058 | 2017-01-27 13:07:15 +0300 | [diff] [blame] | 1411 | if (rev >= 0x94) { |
Mika Westerberg | e57725e | 2017-01-27 13:07:14 +0300 | [diff] [blame] | 1412 | community->features |= PINCTRL_FEATURE_DEBOUNCE; |
Mika Westerberg | 04cc058 | 2017-01-27 13:07:15 +0300 | [diff] [blame] | 1413 | community->features |= PINCTRL_FEATURE_1K_PD; |
| 1414 | } |
Mika Westerberg | e57725e | 2017-01-27 13:07:14 +0300 | [diff] [blame] | 1415 | } |
| 1416 | |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1417 | /* Read offset of the pad configuration registers */ |
| 1418 | padbar = readl(regs + PADBAR); |
| 1419 | |
| 1420 | community->regs = regs; |
| 1421 | community->pad_regs = regs + padbar; |
Mika Westerberg | 919eb47 | 2017-06-06 16:18:17 +0300 | [diff] [blame] | 1422 | |
| 1423 | ret = intel_pinctrl_add_padgroups(pctrl, community); |
| 1424 | if (ret) |
| 1425 | return ret; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | irq = platform_get_irq(pdev, 0); |
Stephen Boyd | 4e73d02 | 2019-07-30 11:15:34 -0700 | [diff] [blame] | 1429 | if (irq < 0) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1430 | return irq; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1431 | |
| 1432 | ret = intel_pinctrl_pm_init(pctrl); |
| 1433 | if (ret) |
| 1434 | return ret; |
| 1435 | |
| 1436 | pctrl->pctldesc = intel_pinctrl_desc; |
| 1437 | pctrl->pctldesc.name = dev_name(&pdev->dev); |
| 1438 | pctrl->pctldesc.pins = pctrl->soc->pins; |
| 1439 | pctrl->pctldesc.npins = pctrl->soc->npins; |
| 1440 | |
Laxman Dewangan | 54d46cd | 2016-02-28 14:42:47 +0530 | [diff] [blame] | 1441 | pctrl->pctldev = devm_pinctrl_register(&pdev->dev, &pctrl->pctldesc, |
| 1442 | pctrl); |
Masahiro Yamada | 323de9e | 2015-06-09 13:01:16 +0900 | [diff] [blame] | 1443 | if (IS_ERR(pctrl->pctldev)) { |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1444 | dev_err(&pdev->dev, "failed to register pinctrl driver\n"); |
Masahiro Yamada | 323de9e | 2015-06-09 13:01:16 +0900 | [diff] [blame] | 1445 | return PTR_ERR(pctrl->pctldev); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | ret = intel_gpio_probe(pctrl, irq); |
Laxman Dewangan | 54d46cd | 2016-02-28 14:42:47 +0530 | [diff] [blame] | 1449 | if (ret) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1450 | return ret; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1451 | |
| 1452 | platform_set_drvdata(pdev, pctrl); |
| 1453 | |
| 1454 | return 0; |
| 1455 | } |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1456 | |
Andy Shevchenko | 70c263c | 2018-08-30 19:27:40 +0300 | [diff] [blame] | 1457 | int intel_pinctrl_probe_by_hid(struct platform_device *pdev) |
| 1458 | { |
| 1459 | const struct intel_pinctrl_soc_data *data; |
| 1460 | |
| 1461 | data = device_get_match_data(&pdev->dev); |
| 1462 | return intel_pinctrl_probe(pdev, data); |
| 1463 | } |
| 1464 | EXPORT_SYMBOL_GPL(intel_pinctrl_probe_by_hid); |
| 1465 | |
Andy Shevchenko | 924cf80 | 2018-08-30 19:27:36 +0300 | [diff] [blame] | 1466 | int intel_pinctrl_probe_by_uid(struct platform_device *pdev) |
| 1467 | { |
| 1468 | const struct intel_pinctrl_soc_data *data = NULL; |
| 1469 | const struct intel_pinctrl_soc_data **table; |
| 1470 | struct acpi_device *adev; |
| 1471 | unsigned int i; |
| 1472 | |
| 1473 | adev = ACPI_COMPANION(&pdev->dev); |
| 1474 | if (adev) { |
| 1475 | const void *match = device_get_match_data(&pdev->dev); |
| 1476 | |
| 1477 | table = (const struct intel_pinctrl_soc_data **)match; |
| 1478 | for (i = 0; table[i]; i++) { |
| 1479 | if (!strcmp(adev->pnp.unique_id, table[i]->uid)) { |
| 1480 | data = table[i]; |
| 1481 | break; |
| 1482 | } |
| 1483 | } |
| 1484 | } else { |
| 1485 | const struct platform_device_id *id; |
| 1486 | |
| 1487 | id = platform_get_device_id(pdev); |
| 1488 | if (!id) |
| 1489 | return -ENODEV; |
| 1490 | |
| 1491 | table = (const struct intel_pinctrl_soc_data **)id->driver_data; |
| 1492 | data = table[pdev->id]; |
| 1493 | } |
Andy Shevchenko | 924cf80 | 2018-08-30 19:27:36 +0300 | [diff] [blame] | 1494 | |
| 1495 | return intel_pinctrl_probe(pdev, data); |
| 1496 | } |
| 1497 | EXPORT_SYMBOL_GPL(intel_pinctrl_probe_by_uid); |
| 1498 | |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1499 | #ifdef CONFIG_PM_SLEEP |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 1500 | static bool intel_pinctrl_should_save(struct intel_pinctrl *pctrl, unsigned int pin) |
Mika Westerberg | c538b94 | 2016-10-10 16:39:31 +0300 | [diff] [blame] | 1501 | { |
| 1502 | const struct pin_desc *pd = pin_desc_get(pctrl->pctldev, pin); |
| 1503 | |
| 1504 | if (!pd || !intel_pad_usable(pctrl, pin)) |
| 1505 | return false; |
| 1506 | |
| 1507 | /* |
| 1508 | * Only restore the pin if it is actually in use by the kernel (or |
| 1509 | * by userspace). It is possible that some pins are used by the |
| 1510 | * BIOS during resume and those are not always locked down so leave |
| 1511 | * them alone. |
| 1512 | */ |
| 1513 | if (pd->mux_owner || pd->gpio_owner || |
Chris Chiu | 6cb0880 | 2019-08-16 17:38:38 +0800 | [diff] [blame] | 1514 | gpiochip_line_is_irq(&pctrl->chip, intel_pin_to_gpio(pctrl, pin))) |
Mika Westerberg | c538b94 | 2016-10-10 16:39:31 +0300 | [diff] [blame] | 1515 | return true; |
| 1516 | |
| 1517 | return false; |
| 1518 | } |
| 1519 | |
Binbin Wu | 2fef327 | 2019-04-08 18:49:26 +0800 | [diff] [blame] | 1520 | int intel_pinctrl_suspend_noirq(struct device *dev) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1521 | { |
Wolfram Sang | cb035d7 | 2018-10-21 22:00:29 +0200 | [diff] [blame] | 1522 | struct intel_pinctrl *pctrl = dev_get_drvdata(dev); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1523 | struct intel_community_context *communities; |
| 1524 | struct intel_pad_context *pads; |
| 1525 | int i; |
| 1526 | |
| 1527 | pads = pctrl->context.pads; |
| 1528 | for (i = 0; i < pctrl->soc->npins; i++) { |
| 1529 | const struct pinctrl_pin_desc *desc = &pctrl->soc->pins[i]; |
Mika Westerberg | e57725e | 2017-01-27 13:07:14 +0300 | [diff] [blame] | 1530 | void __iomem *padcfg; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1531 | u32 val; |
| 1532 | |
Mika Westerberg | c538b94 | 2016-10-10 16:39:31 +0300 | [diff] [blame] | 1533 | if (!intel_pinctrl_should_save(pctrl, desc->number)) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1534 | continue; |
| 1535 | |
| 1536 | val = readl(intel_get_padcfg(pctrl, desc->number, PADCFG0)); |
| 1537 | pads[i].padcfg0 = val & ~PADCFG0_GPIORXSTATE; |
| 1538 | val = readl(intel_get_padcfg(pctrl, desc->number, PADCFG1)); |
| 1539 | pads[i].padcfg1 = val; |
Mika Westerberg | e57725e | 2017-01-27 13:07:14 +0300 | [diff] [blame] | 1540 | |
| 1541 | padcfg = intel_get_padcfg(pctrl, desc->number, PADCFG2); |
| 1542 | if (padcfg) |
| 1543 | pads[i].padcfg2 = readl(padcfg); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1544 | } |
| 1545 | |
| 1546 | communities = pctrl->context.communities; |
| 1547 | for (i = 0; i < pctrl->ncommunities; i++) { |
| 1548 | struct intel_community *community = &pctrl->communities[i]; |
| 1549 | void __iomem *base; |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 1550 | unsigned int gpp; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1551 | |
| 1552 | base = community->regs + community->ie_offset; |
| 1553 | for (gpp = 0; gpp < community->ngpps; gpp++) |
| 1554 | communities[i].intmask[gpp] = readl(base + gpp * 4); |
Chris Chiu | a0a5f76 | 2019-04-15 13:53:58 +0800 | [diff] [blame] | 1555 | |
| 1556 | base = community->regs + community->hostown_offset; |
| 1557 | for (gpp = 0; gpp < community->ngpps; gpp++) |
| 1558 | communities[i].hostown[gpp] = readl(base + gpp * 4); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1559 | } |
| 1560 | |
| 1561 | return 0; |
| 1562 | } |
Binbin Wu | 2fef327 | 2019-04-08 18:49:26 +0800 | [diff] [blame] | 1563 | EXPORT_SYMBOL_GPL(intel_pinctrl_suspend_noirq); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1564 | |
Mika Westerberg | f487bbf | 2015-10-13 17:51:25 +0300 | [diff] [blame] | 1565 | static void intel_gpio_irq_init(struct intel_pinctrl *pctrl) |
| 1566 | { |
| 1567 | size_t i; |
| 1568 | |
| 1569 | for (i = 0; i < pctrl->ncommunities; i++) { |
| 1570 | const struct intel_community *community; |
| 1571 | void __iomem *base; |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 1572 | unsigned int gpp; |
Mika Westerberg | f487bbf | 2015-10-13 17:51:25 +0300 | [diff] [blame] | 1573 | |
| 1574 | community = &pctrl->communities[i]; |
| 1575 | base = community->regs; |
| 1576 | |
| 1577 | for (gpp = 0; gpp < community->ngpps; gpp++) { |
| 1578 | /* Mask and clear all interrupts */ |
| 1579 | writel(0, base + community->ie_offset + gpp * 4); |
Mika Westerberg | cf769bd | 2017-10-23 15:40:25 +0300 | [diff] [blame] | 1580 | writel(0xffff, base + community->is_offset + gpp * 4); |
Mika Westerberg | f487bbf | 2015-10-13 17:51:25 +0300 | [diff] [blame] | 1581 | } |
| 1582 | } |
| 1583 | } |
| 1584 | |
Chris Chiu | a0a5f76 | 2019-04-15 13:53:58 +0800 | [diff] [blame] | 1585 | static u32 |
| 1586 | intel_gpio_is_requested(struct gpio_chip *chip, int base, unsigned int size) |
| 1587 | { |
| 1588 | u32 requested = 0; |
| 1589 | unsigned int i; |
| 1590 | |
| 1591 | for (i = 0; i < size; i++) |
| 1592 | if (gpiochip_is_requested(chip, base + i)) |
| 1593 | requested |= BIT(i); |
| 1594 | |
| 1595 | return requested; |
| 1596 | } |
| 1597 | |
| 1598 | static u32 |
| 1599 | intel_gpio_update_pad_mode(void __iomem *hostown, u32 mask, u32 value) |
| 1600 | { |
Andy Shevchenko | 5f61d95 | 2019-04-28 20:19:06 +0300 | [diff] [blame] | 1601 | u32 curr, updated; |
Chris Chiu | a0a5f76 | 2019-04-15 13:53:58 +0800 | [diff] [blame] | 1602 | |
Andy Shevchenko | 5f61d95 | 2019-04-28 20:19:06 +0300 | [diff] [blame] | 1603 | curr = readl(hostown); |
| 1604 | updated = (curr & ~mask) | (value & mask); |
Chris Chiu | a0a5f76 | 2019-04-15 13:53:58 +0800 | [diff] [blame] | 1605 | writel(updated, hostown); |
Andy Shevchenko | 5f61d95 | 2019-04-28 20:19:06 +0300 | [diff] [blame] | 1606 | |
Chris Chiu | a0a5f76 | 2019-04-15 13:53:58 +0800 | [diff] [blame] | 1607 | return curr; |
| 1608 | } |
| 1609 | |
Andy Shevchenko | 7101e02 | 2019-10-22 13:00:01 +0300 | [diff] [blame^] | 1610 | static void intel_restore_hostown(struct intel_pinctrl *pctrl, unsigned int c, |
| 1611 | void __iomem *base, unsigned int gpp, u32 saved) |
| 1612 | { |
| 1613 | const struct intel_community *community = &pctrl->communities[c]; |
| 1614 | const struct intel_padgroup *padgrp = &community->gpps[gpp]; |
| 1615 | struct device *dev = pctrl->dev; |
| 1616 | u32 requested, value; |
| 1617 | |
| 1618 | if (padgrp->gpio_base < 0) |
| 1619 | return; |
| 1620 | |
| 1621 | requested = intel_gpio_is_requested(&pctrl->chip, padgrp->gpio_base, padgrp->size); |
| 1622 | value = intel_gpio_update_pad_mode(base + gpp * 4, requested, saved); |
| 1623 | if (!((value ^ saved) & requested)) |
| 1624 | return; |
| 1625 | |
| 1626 | dev_warn(dev, "restored hostown %u/%u %#8x->%#8x\n", c, gpp, value, saved); |
| 1627 | } |
| 1628 | |
Andy Shevchenko | f78f152 | 2019-10-22 13:00:00 +0300 | [diff] [blame] | 1629 | static void intel_restore_padcfg(struct intel_pinctrl *pctrl, unsigned int pin, |
| 1630 | unsigned int reg, u32 saved) |
| 1631 | { |
| 1632 | u32 mask = (reg == PADCFG0) ? PADCFG0_GPIORXSTATE : 0; |
| 1633 | unsigned int n = reg / sizeof(u32); |
| 1634 | struct device *dev = pctrl->dev; |
| 1635 | void __iomem *padcfg; |
| 1636 | u32 value; |
| 1637 | |
| 1638 | padcfg = intel_get_padcfg(pctrl, pin, reg); |
| 1639 | if (!padcfg) |
| 1640 | return; |
| 1641 | |
| 1642 | value = readl(padcfg) & ~mask; |
| 1643 | if (value == saved) |
| 1644 | return; |
| 1645 | |
| 1646 | writel(saved, padcfg); |
| 1647 | dev_dbg(dev, "restored pin %u padcfg%u %#08x\n", pin, n, readl(padcfg)); |
| 1648 | } |
| 1649 | |
Binbin Wu | 2fef327 | 2019-04-08 18:49:26 +0800 | [diff] [blame] | 1650 | int intel_pinctrl_resume_noirq(struct device *dev) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1651 | { |
Wolfram Sang | cb035d7 | 2018-10-21 22:00:29 +0200 | [diff] [blame] | 1652 | struct intel_pinctrl *pctrl = dev_get_drvdata(dev); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1653 | const struct intel_community_context *communities; |
| 1654 | const struct intel_pad_context *pads; |
| 1655 | int i; |
| 1656 | |
| 1657 | /* Mask all interrupts */ |
| 1658 | intel_gpio_irq_init(pctrl); |
| 1659 | |
| 1660 | pads = pctrl->context.pads; |
| 1661 | for (i = 0; i < pctrl->soc->npins; i++) { |
| 1662 | const struct pinctrl_pin_desc *desc = &pctrl->soc->pins[i]; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1663 | |
Mika Westerberg | c538b94 | 2016-10-10 16:39:31 +0300 | [diff] [blame] | 1664 | if (!intel_pinctrl_should_save(pctrl, desc->number)) |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1665 | continue; |
| 1666 | |
Andy Shevchenko | f78f152 | 2019-10-22 13:00:00 +0300 | [diff] [blame] | 1667 | intel_restore_padcfg(pctrl, desc->number, PADCFG0, pads[i].padcfg0); |
| 1668 | intel_restore_padcfg(pctrl, desc->number, PADCFG1, pads[i].padcfg1); |
| 1669 | intel_restore_padcfg(pctrl, desc->number, PADCFG2, pads[i].padcfg2); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1670 | } |
| 1671 | |
| 1672 | communities = pctrl->context.communities; |
| 1673 | for (i = 0; i < pctrl->ncommunities; i++) { |
| 1674 | struct intel_community *community = &pctrl->communities[i]; |
| 1675 | void __iomem *base; |
Andy Shevchenko | 04035f7 | 2018-09-26 17:50:26 +0300 | [diff] [blame] | 1676 | unsigned int gpp; |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1677 | |
| 1678 | base = community->regs + community->ie_offset; |
| 1679 | for (gpp = 0; gpp < community->ngpps; gpp++) { |
| 1680 | writel(communities[i].intmask[gpp], base + gpp * 4); |
| 1681 | dev_dbg(dev, "restored mask %d/%u %#08x\n", i, gpp, |
| 1682 | readl(base + gpp * 4)); |
| 1683 | } |
Chris Chiu | a0a5f76 | 2019-04-15 13:53:58 +0800 | [diff] [blame] | 1684 | |
| 1685 | base = community->regs + community->hostown_offset; |
Andy Shevchenko | 7101e02 | 2019-10-22 13:00:01 +0300 | [diff] [blame^] | 1686 | for (gpp = 0; gpp < community->ngpps; gpp++) |
| 1687 | intel_restore_hostown(pctrl, i, base, gpp, communities[i].hostown[gpp]); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1688 | } |
| 1689 | |
| 1690 | return 0; |
| 1691 | } |
Binbin Wu | 2fef327 | 2019-04-08 18:49:26 +0800 | [diff] [blame] | 1692 | EXPORT_SYMBOL_GPL(intel_pinctrl_resume_noirq); |
Mika Westerberg | 7981c001 | 2015-03-30 17:31:49 +0300 | [diff] [blame] | 1693 | #endif |
| 1694 | |
| 1695 | MODULE_AUTHOR("Mathias Nyman <mathias.nyman@linux.intel.com>"); |
| 1696 | MODULE_AUTHOR("Mika Westerberg <mika.westerberg@linux.intel.com>"); |
| 1697 | MODULE_DESCRIPTION("Intel pinctrl/GPIO core driver"); |
| 1698 | MODULE_LICENSE("GPL v2"); |