1875a92b3SAndy Shevchenko // SPDX-License-Identifier: GPL-2.0 27981c001SMika Westerberg /* 37981c001SMika Westerberg * Intel pinctrl/GPIO core driver. 47981c001SMika Westerberg * 57981c001SMika Westerberg * Copyright (C) 2015, Intel Corporation 67981c001SMika Westerberg * Authors: Mathias Nyman <mathias.nyman@linux.intel.com> 77981c001SMika Westerberg * Mika Westerberg <mika.westerberg@linux.intel.com> 87981c001SMika Westerberg */ 97981c001SMika Westerberg 10924cf800SAndy Shevchenko #include <linux/acpi.h> 117981c001SMika Westerberg #include <linux/module.h> 12193b40c8SMika Westerberg #include <linux/interrupt.h> 137981c001SMika Westerberg #include <linux/gpio/driver.h> 14e57725eaSMika Westerberg #include <linux/log2.h> 157981c001SMika Westerberg #include <linux/platform_device.h> 16924cf800SAndy Shevchenko #include <linux/property.h> 17924cf800SAndy Shevchenko 187981c001SMika Westerberg #include <linux/pinctrl/pinctrl.h> 197981c001SMika Westerberg #include <linux/pinctrl/pinmux.h> 207981c001SMika Westerberg #include <linux/pinctrl/pinconf.h> 217981c001SMika Westerberg #include <linux/pinctrl/pinconf-generic.h> 227981c001SMika Westerberg 23c538b943SMika Westerberg #include "../core.h" 247981c001SMika Westerberg #include "pinctrl-intel.h" 257981c001SMika Westerberg 267981c001SMika Westerberg /* Offset from regs */ 27e57725eaSMika Westerberg #define REVID 0x000 28e57725eaSMika Westerberg #define REVID_SHIFT 16 29e57725eaSMika Westerberg #define REVID_MASK GENMASK(31, 16) 30e57725eaSMika Westerberg 317981c001SMika Westerberg #define PADBAR 0x00c 327981c001SMika Westerberg #define GPI_IS 0x100 337981c001SMika Westerberg 347981c001SMika Westerberg #define PADOWN_BITS 4 357981c001SMika Westerberg #define PADOWN_SHIFT(p) ((p) % 8 * PADOWN_BITS) 367981c001SMika Westerberg #define PADOWN_MASK(p) (0xf << PADOWN_SHIFT(p)) 3799a735b3SQipeng Zha #define PADOWN_GPP(p) ((p) / 8) 387981c001SMika Westerberg 397981c001SMika Westerberg /* Offset from pad_regs */ 407981c001SMika Westerberg #define PADCFG0 0x000 417981c001SMika Westerberg #define PADCFG0_RXEVCFG_SHIFT 25 427981c001SMika Westerberg #define PADCFG0_RXEVCFG_MASK (3 << PADCFG0_RXEVCFG_SHIFT) 437981c001SMika Westerberg #define PADCFG0_RXEVCFG_LEVEL 0 447981c001SMika Westerberg #define PADCFG0_RXEVCFG_EDGE 1 457981c001SMika Westerberg #define PADCFG0_RXEVCFG_DISABLED 2 467981c001SMika Westerberg #define PADCFG0_RXEVCFG_EDGE_BOTH 3 47e57725eaSMika Westerberg #define PADCFG0_PREGFRXSEL BIT(24) 487981c001SMika Westerberg #define PADCFG0_RXINV BIT(23) 497981c001SMika Westerberg #define PADCFG0_GPIROUTIOXAPIC BIT(20) 507981c001SMika Westerberg #define PADCFG0_GPIROUTSCI BIT(19) 517981c001SMika Westerberg #define PADCFG0_GPIROUTSMI BIT(18) 527981c001SMika Westerberg #define PADCFG0_GPIROUTNMI BIT(17) 537981c001SMika Westerberg #define PADCFG0_PMODE_SHIFT 10 547981c001SMika Westerberg #define PADCFG0_PMODE_MASK (0xf << PADCFG0_PMODE_SHIFT) 557981c001SMika Westerberg #define PADCFG0_GPIORXDIS BIT(9) 567981c001SMika Westerberg #define PADCFG0_GPIOTXDIS BIT(8) 577981c001SMika Westerberg #define PADCFG0_GPIORXSTATE BIT(1) 587981c001SMika Westerberg #define PADCFG0_GPIOTXSTATE BIT(0) 597981c001SMika Westerberg 607981c001SMika Westerberg #define PADCFG1 0x004 617981c001SMika Westerberg #define PADCFG1_TERM_UP BIT(13) 627981c001SMika Westerberg #define PADCFG1_TERM_SHIFT 10 637981c001SMika Westerberg #define PADCFG1_TERM_MASK (7 << PADCFG1_TERM_SHIFT) 647981c001SMika Westerberg #define PADCFG1_TERM_20K 4 657981c001SMika Westerberg #define PADCFG1_TERM_2K 3 667981c001SMika Westerberg #define PADCFG1_TERM_5K 2 677981c001SMika Westerberg #define PADCFG1_TERM_1K 1 687981c001SMika Westerberg 69e57725eaSMika Westerberg #define PADCFG2 0x008 70e57725eaSMika Westerberg #define PADCFG2_DEBEN BIT(0) 71e57725eaSMika Westerberg #define PADCFG2_DEBOUNCE_SHIFT 1 72e57725eaSMika Westerberg #define PADCFG2_DEBOUNCE_MASK GENMASK(4, 1) 73e57725eaSMika Westerberg 74e57725eaSMika Westerberg #define DEBOUNCE_PERIOD 31250 /* ns */ 75e57725eaSMika Westerberg 767981c001SMika Westerberg struct intel_pad_context { 777981c001SMika Westerberg u32 padcfg0; 787981c001SMika Westerberg u32 padcfg1; 79e57725eaSMika Westerberg u32 padcfg2; 807981c001SMika Westerberg }; 817981c001SMika Westerberg 827981c001SMika Westerberg struct intel_community_context { 837981c001SMika Westerberg u32 *intmask; 847981c001SMika Westerberg }; 857981c001SMika Westerberg 867981c001SMika Westerberg struct intel_pinctrl_context { 877981c001SMika Westerberg struct intel_pad_context *pads; 887981c001SMika Westerberg struct intel_community_context *communities; 897981c001SMika Westerberg }; 907981c001SMika Westerberg 917981c001SMika Westerberg /** 927981c001SMika Westerberg * struct intel_pinctrl - Intel pinctrl private structure 937981c001SMika Westerberg * @dev: Pointer to the device structure 947981c001SMika Westerberg * @lock: Lock to serialize register access 957981c001SMika Westerberg * @pctldesc: Pin controller description 967981c001SMika Westerberg * @pctldev: Pointer to the pin controller device 977981c001SMika Westerberg * @chip: GPIO chip in this pin controller 987981c001SMika Westerberg * @soc: SoC/PCH specific pin configuration data 997981c001SMika Westerberg * @communities: All communities in this pin controller 1007981c001SMika Westerberg * @ncommunities: Number of communities in this pin controller 1017981c001SMika Westerberg * @context: Configuration saved over system sleep 10201dabe91SNilesh Bacchewar * @irq: pinctrl/GPIO chip irq number 1037981c001SMika Westerberg */ 1047981c001SMika Westerberg struct intel_pinctrl { 1057981c001SMika Westerberg struct device *dev; 10627d9098cSMika Westerberg raw_spinlock_t lock; 1077981c001SMika Westerberg struct pinctrl_desc pctldesc; 1087981c001SMika Westerberg struct pinctrl_dev *pctldev; 1097981c001SMika Westerberg struct gpio_chip chip; 1107981c001SMika Westerberg const struct intel_pinctrl_soc_data *soc; 1117981c001SMika Westerberg struct intel_community *communities; 1127981c001SMika Westerberg size_t ncommunities; 1137981c001SMika Westerberg struct intel_pinctrl_context context; 11401dabe91SNilesh Bacchewar int irq; 1157981c001SMika Westerberg }; 1167981c001SMika Westerberg 1177981c001SMika Westerberg #define pin_to_padno(c, p) ((p) - (c)->pin_base) 118919eb475SMika Westerberg #define padgroup_offset(g, p) ((p) - (g)->base) 1197981c001SMika Westerberg 1207981c001SMika Westerberg static struct intel_community *intel_get_community(struct intel_pinctrl *pctrl, 12104035f7fSAndy Shevchenko unsigned int pin) 1227981c001SMika Westerberg { 1237981c001SMika Westerberg struct intel_community *community; 1247981c001SMika Westerberg int i; 1257981c001SMika Westerberg 1267981c001SMika Westerberg for (i = 0; i < pctrl->ncommunities; i++) { 1277981c001SMika Westerberg community = &pctrl->communities[i]; 1287981c001SMika Westerberg if (pin >= community->pin_base && 1297981c001SMika Westerberg pin < community->pin_base + community->npins) 1307981c001SMika Westerberg return community; 1317981c001SMika Westerberg } 1327981c001SMika Westerberg 1337981c001SMika Westerberg dev_warn(pctrl->dev, "failed to find community for pin %u\n", pin); 1347981c001SMika Westerberg return NULL; 1357981c001SMika Westerberg } 1367981c001SMika Westerberg 137919eb475SMika Westerberg static const struct intel_padgroup * 138919eb475SMika Westerberg intel_community_get_padgroup(const struct intel_community *community, 13904035f7fSAndy Shevchenko unsigned int pin) 140919eb475SMika Westerberg { 141919eb475SMika Westerberg int i; 142919eb475SMika Westerberg 143919eb475SMika Westerberg for (i = 0; i < community->ngpps; i++) { 144919eb475SMika Westerberg const struct intel_padgroup *padgrp = &community->gpps[i]; 145919eb475SMika Westerberg 146919eb475SMika Westerberg if (pin >= padgrp->base && pin < padgrp->base + padgrp->size) 147919eb475SMika Westerberg return padgrp; 148919eb475SMika Westerberg } 149919eb475SMika Westerberg 150919eb475SMika Westerberg return NULL; 151919eb475SMika Westerberg } 152919eb475SMika Westerberg 15304035f7fSAndy Shevchenko static void __iomem *intel_get_padcfg(struct intel_pinctrl *pctrl, 15404035f7fSAndy Shevchenko unsigned int pin, unsigned int reg) 1557981c001SMika Westerberg { 1567981c001SMika Westerberg const struct intel_community *community; 15704035f7fSAndy Shevchenko unsigned int padno; 158e57725eaSMika Westerberg size_t nregs; 1597981c001SMika Westerberg 1607981c001SMika Westerberg community = intel_get_community(pctrl, pin); 1617981c001SMika Westerberg if (!community) 1627981c001SMika Westerberg return NULL; 1637981c001SMika Westerberg 1647981c001SMika Westerberg padno = pin_to_padno(community, pin); 165e57725eaSMika Westerberg nregs = (community->features & PINCTRL_FEATURE_DEBOUNCE) ? 4 : 2; 166e57725eaSMika Westerberg 167e57725eaSMika Westerberg if (reg == PADCFG2 && !(community->features & PINCTRL_FEATURE_DEBOUNCE)) 168e57725eaSMika Westerberg return NULL; 169e57725eaSMika Westerberg 170e57725eaSMika Westerberg return community->pad_regs + reg + padno * nregs * 4; 1717981c001SMika Westerberg } 1727981c001SMika Westerberg 17304035f7fSAndy Shevchenko static bool intel_pad_owned_by_host(struct intel_pinctrl *pctrl, unsigned int pin) 1747981c001SMika Westerberg { 1757981c001SMika Westerberg const struct intel_community *community; 176919eb475SMika Westerberg const struct intel_padgroup *padgrp; 17704035f7fSAndy Shevchenko unsigned int gpp, offset, gpp_offset; 1787981c001SMika Westerberg void __iomem *padown; 1797981c001SMika Westerberg 1807981c001SMika Westerberg community = intel_get_community(pctrl, pin); 1817981c001SMika Westerberg if (!community) 1827981c001SMika Westerberg return false; 1837981c001SMika Westerberg if (!community->padown_offset) 1847981c001SMika Westerberg return true; 1857981c001SMika Westerberg 186919eb475SMika Westerberg padgrp = intel_community_get_padgroup(community, pin); 187919eb475SMika Westerberg if (!padgrp) 188919eb475SMika Westerberg return false; 189919eb475SMika Westerberg 190919eb475SMika Westerberg gpp_offset = padgroup_offset(padgrp, pin); 191919eb475SMika Westerberg gpp = PADOWN_GPP(gpp_offset); 192919eb475SMika Westerberg offset = community->padown_offset + padgrp->padown_num * 4 + gpp * 4; 1937981c001SMika Westerberg padown = community->regs + offset; 1947981c001SMika Westerberg 195919eb475SMika Westerberg return !(readl(padown) & PADOWN_MASK(gpp_offset)); 1967981c001SMika Westerberg } 1977981c001SMika Westerberg 19804035f7fSAndy Shevchenko static bool intel_pad_acpi_mode(struct intel_pinctrl *pctrl, unsigned int pin) 1997981c001SMika Westerberg { 2007981c001SMika Westerberg const struct intel_community *community; 201919eb475SMika Westerberg const struct intel_padgroup *padgrp; 20204035f7fSAndy Shevchenko unsigned int offset, gpp_offset; 2037981c001SMika Westerberg void __iomem *hostown; 2047981c001SMika Westerberg 2057981c001SMika Westerberg community = intel_get_community(pctrl, pin); 2067981c001SMika Westerberg if (!community) 2077981c001SMika Westerberg return true; 2087981c001SMika Westerberg if (!community->hostown_offset) 2097981c001SMika Westerberg return false; 2107981c001SMika Westerberg 211919eb475SMika Westerberg padgrp = intel_community_get_padgroup(community, pin); 212919eb475SMika Westerberg if (!padgrp) 213919eb475SMika Westerberg return true; 214919eb475SMika Westerberg 215919eb475SMika Westerberg gpp_offset = padgroup_offset(padgrp, pin); 216919eb475SMika Westerberg offset = community->hostown_offset + padgrp->reg_num * 4; 2177981c001SMika Westerberg hostown = community->regs + offset; 2187981c001SMika Westerberg 219919eb475SMika Westerberg return !(readl(hostown) & BIT(gpp_offset)); 2207981c001SMika Westerberg } 2217981c001SMika Westerberg 22204035f7fSAndy Shevchenko static bool intel_pad_locked(struct intel_pinctrl *pctrl, unsigned int pin) 2237981c001SMika Westerberg { 2247981c001SMika Westerberg struct intel_community *community; 225919eb475SMika Westerberg const struct intel_padgroup *padgrp; 22604035f7fSAndy Shevchenko unsigned int offset, gpp_offset; 2277981c001SMika Westerberg u32 value; 2287981c001SMika Westerberg 2297981c001SMika Westerberg community = intel_get_community(pctrl, pin); 2307981c001SMika Westerberg if (!community) 2317981c001SMika Westerberg return true; 2327981c001SMika Westerberg if (!community->padcfglock_offset) 2337981c001SMika Westerberg return false; 2347981c001SMika Westerberg 235919eb475SMika Westerberg padgrp = intel_community_get_padgroup(community, pin); 236919eb475SMika Westerberg if (!padgrp) 237919eb475SMika Westerberg return true; 238919eb475SMika Westerberg 239919eb475SMika Westerberg gpp_offset = padgroup_offset(padgrp, pin); 2407981c001SMika Westerberg 2417981c001SMika Westerberg /* 2427981c001SMika Westerberg * If PADCFGLOCK and PADCFGLOCKTX bits are both clear for this pad, 2437981c001SMika Westerberg * the pad is considered unlocked. Any other case means that it is 2447981c001SMika Westerberg * either fully or partially locked and we don't touch it. 2457981c001SMika Westerberg */ 246919eb475SMika Westerberg offset = community->padcfglock_offset + padgrp->reg_num * 8; 2477981c001SMika Westerberg value = readl(community->regs + offset); 248919eb475SMika Westerberg if (value & BIT(gpp_offset)) 2497981c001SMika Westerberg return true; 2507981c001SMika Westerberg 251919eb475SMika Westerberg offset = community->padcfglock_offset + 4 + padgrp->reg_num * 8; 2527981c001SMika Westerberg value = readl(community->regs + offset); 253919eb475SMika Westerberg if (value & BIT(gpp_offset)) 2547981c001SMika Westerberg return true; 2557981c001SMika Westerberg 2567981c001SMika Westerberg return false; 2577981c001SMika Westerberg } 2587981c001SMika Westerberg 25904035f7fSAndy Shevchenko static bool intel_pad_usable(struct intel_pinctrl *pctrl, unsigned int pin) 2607981c001SMika Westerberg { 2617981c001SMika Westerberg return intel_pad_owned_by_host(pctrl, pin) && 2627981c001SMika Westerberg !intel_pad_locked(pctrl, pin); 2637981c001SMika Westerberg } 2647981c001SMika Westerberg 2657981c001SMika Westerberg static int intel_get_groups_count(struct pinctrl_dev *pctldev) 2667981c001SMika Westerberg { 2677981c001SMika Westerberg struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 2687981c001SMika Westerberg 2697981c001SMika Westerberg return pctrl->soc->ngroups; 2707981c001SMika Westerberg } 2717981c001SMika Westerberg 2727981c001SMika Westerberg static const char *intel_get_group_name(struct pinctrl_dev *pctldev, 27304035f7fSAndy Shevchenko unsigned int group) 2747981c001SMika Westerberg { 2757981c001SMika Westerberg struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 2767981c001SMika Westerberg 2777981c001SMika Westerberg return pctrl->soc->groups[group].name; 2787981c001SMika Westerberg } 2797981c001SMika Westerberg 28004035f7fSAndy Shevchenko static int intel_get_group_pins(struct pinctrl_dev *pctldev, unsigned int group, 28104035f7fSAndy Shevchenko const unsigned int **pins, unsigned int *npins) 2827981c001SMika Westerberg { 2837981c001SMika Westerberg struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 2847981c001SMika Westerberg 2857981c001SMika Westerberg *pins = pctrl->soc->groups[group].pins; 2867981c001SMika Westerberg *npins = pctrl->soc->groups[group].npins; 2877981c001SMika Westerberg return 0; 2887981c001SMika Westerberg } 2897981c001SMika Westerberg 2907981c001SMika Westerberg static void intel_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s, 29104035f7fSAndy Shevchenko unsigned int pin) 2927981c001SMika Westerberg { 2937981c001SMika Westerberg struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 294e57725eaSMika Westerberg void __iomem *padcfg; 2957981c001SMika Westerberg u32 cfg0, cfg1, mode; 2967981c001SMika Westerberg bool locked, acpi; 2977981c001SMika Westerberg 2987981c001SMika Westerberg if (!intel_pad_owned_by_host(pctrl, pin)) { 2997981c001SMika Westerberg seq_puts(s, "not available"); 3007981c001SMika Westerberg return; 3017981c001SMika Westerberg } 3027981c001SMika Westerberg 3037981c001SMika Westerberg cfg0 = readl(intel_get_padcfg(pctrl, pin, PADCFG0)); 3047981c001SMika Westerberg cfg1 = readl(intel_get_padcfg(pctrl, pin, PADCFG1)); 3057981c001SMika Westerberg 3067981c001SMika Westerberg mode = (cfg0 & PADCFG0_PMODE_MASK) >> PADCFG0_PMODE_SHIFT; 3077981c001SMika Westerberg if (!mode) 3087981c001SMika Westerberg seq_puts(s, "GPIO "); 3097981c001SMika Westerberg else 3107981c001SMika Westerberg seq_printf(s, "mode %d ", mode); 3117981c001SMika Westerberg 3127981c001SMika Westerberg seq_printf(s, "0x%08x 0x%08x", cfg0, cfg1); 3137981c001SMika Westerberg 314e57725eaSMika Westerberg /* Dump the additional PADCFG registers if available */ 315e57725eaSMika Westerberg padcfg = intel_get_padcfg(pctrl, pin, PADCFG2); 316e57725eaSMika Westerberg if (padcfg) 317e57725eaSMika Westerberg seq_printf(s, " 0x%08x", readl(padcfg)); 318e57725eaSMika Westerberg 3197981c001SMika Westerberg locked = intel_pad_locked(pctrl, pin); 3204341e8a5SMika Westerberg acpi = intel_pad_acpi_mode(pctrl, pin); 3217981c001SMika Westerberg 3227981c001SMika Westerberg if (locked || acpi) { 3237981c001SMika Westerberg seq_puts(s, " ["); 3247981c001SMika Westerberg if (locked) { 3257981c001SMika Westerberg seq_puts(s, "LOCKED"); 3267981c001SMika Westerberg if (acpi) 3277981c001SMika Westerberg seq_puts(s, ", "); 3287981c001SMika Westerberg } 3297981c001SMika Westerberg if (acpi) 3307981c001SMika Westerberg seq_puts(s, "ACPI"); 3317981c001SMika Westerberg seq_puts(s, "]"); 3327981c001SMika Westerberg } 3337981c001SMika Westerberg } 3347981c001SMika Westerberg 3357981c001SMika Westerberg static const struct pinctrl_ops intel_pinctrl_ops = { 3367981c001SMika Westerberg .get_groups_count = intel_get_groups_count, 3377981c001SMika Westerberg .get_group_name = intel_get_group_name, 3387981c001SMika Westerberg .get_group_pins = intel_get_group_pins, 3397981c001SMika Westerberg .pin_dbg_show = intel_pin_dbg_show, 3407981c001SMika Westerberg }; 3417981c001SMika Westerberg 3427981c001SMika Westerberg static int intel_get_functions_count(struct pinctrl_dev *pctldev) 3437981c001SMika Westerberg { 3447981c001SMika Westerberg struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 3457981c001SMika Westerberg 3467981c001SMika Westerberg return pctrl->soc->nfunctions; 3477981c001SMika Westerberg } 3487981c001SMika Westerberg 3497981c001SMika Westerberg static const char *intel_get_function_name(struct pinctrl_dev *pctldev, 35004035f7fSAndy Shevchenko unsigned int function) 3517981c001SMika Westerberg { 3527981c001SMika Westerberg struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 3537981c001SMika Westerberg 3547981c001SMika Westerberg return pctrl->soc->functions[function].name; 3557981c001SMika Westerberg } 3567981c001SMika Westerberg 3577981c001SMika Westerberg static int intel_get_function_groups(struct pinctrl_dev *pctldev, 35804035f7fSAndy Shevchenko unsigned int function, 3597981c001SMika Westerberg const char * const **groups, 36004035f7fSAndy Shevchenko unsigned int * const ngroups) 3617981c001SMika Westerberg { 3627981c001SMika Westerberg struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 3637981c001SMika Westerberg 3647981c001SMika Westerberg *groups = pctrl->soc->functions[function].groups; 3657981c001SMika Westerberg *ngroups = pctrl->soc->functions[function].ngroups; 3667981c001SMika Westerberg return 0; 3677981c001SMika Westerberg } 3687981c001SMika Westerberg 36904035f7fSAndy Shevchenko static int intel_pinmux_set_mux(struct pinctrl_dev *pctldev, 37004035f7fSAndy Shevchenko unsigned int function, unsigned int group) 3717981c001SMika Westerberg { 3727981c001SMika Westerberg struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 3737981c001SMika Westerberg const struct intel_pingroup *grp = &pctrl->soc->groups[group]; 3747981c001SMika Westerberg unsigned long flags; 3757981c001SMika Westerberg int i; 3767981c001SMika Westerberg 37727d9098cSMika Westerberg raw_spin_lock_irqsave(&pctrl->lock, flags); 3787981c001SMika Westerberg 3797981c001SMika Westerberg /* 3807981c001SMika Westerberg * All pins in the groups needs to be accessible and writable 3817981c001SMika Westerberg * before we can enable the mux for this group. 3827981c001SMika Westerberg */ 3837981c001SMika Westerberg for (i = 0; i < grp->npins; i++) { 3847981c001SMika Westerberg if (!intel_pad_usable(pctrl, grp->pins[i])) { 38527d9098cSMika Westerberg raw_spin_unlock_irqrestore(&pctrl->lock, flags); 3867981c001SMika Westerberg return -EBUSY; 3877981c001SMika Westerberg } 3887981c001SMika Westerberg } 3897981c001SMika Westerberg 3907981c001SMika Westerberg /* Now enable the mux setting for each pin in the group */ 3917981c001SMika Westerberg for (i = 0; i < grp->npins; i++) { 3927981c001SMika Westerberg void __iomem *padcfg0; 3937981c001SMika Westerberg u32 value; 3947981c001SMika Westerberg 3957981c001SMika Westerberg padcfg0 = intel_get_padcfg(pctrl, grp->pins[i], PADCFG0); 3967981c001SMika Westerberg value = readl(padcfg0); 3977981c001SMika Westerberg 3987981c001SMika Westerberg value &= ~PADCFG0_PMODE_MASK; 3991f6b419bSMika Westerberg 4001f6b419bSMika Westerberg if (grp->modes) 4011f6b419bSMika Westerberg value |= grp->modes[i] << PADCFG0_PMODE_SHIFT; 4021f6b419bSMika Westerberg else 4037981c001SMika Westerberg value |= grp->mode << PADCFG0_PMODE_SHIFT; 4047981c001SMika Westerberg 4057981c001SMika Westerberg writel(value, padcfg0); 4067981c001SMika Westerberg } 4077981c001SMika Westerberg 40827d9098cSMika Westerberg raw_spin_unlock_irqrestore(&pctrl->lock, flags); 4097981c001SMika Westerberg 4107981c001SMika Westerberg return 0; 4117981c001SMika Westerberg } 4127981c001SMika Westerberg 41317fab473SAndy Shevchenko static void __intel_gpio_set_direction(void __iomem *padcfg0, bool input) 41417fab473SAndy Shevchenko { 41517fab473SAndy Shevchenko u32 value; 41617fab473SAndy Shevchenko 41717fab473SAndy Shevchenko value = readl(padcfg0); 41817fab473SAndy Shevchenko if (input) { 41917fab473SAndy Shevchenko value &= ~PADCFG0_GPIORXDIS; 42017fab473SAndy Shevchenko value |= PADCFG0_GPIOTXDIS; 42117fab473SAndy Shevchenko } else { 42217fab473SAndy Shevchenko value &= ~PADCFG0_GPIOTXDIS; 42317fab473SAndy Shevchenko value |= PADCFG0_GPIORXDIS; 42417fab473SAndy Shevchenko } 42517fab473SAndy Shevchenko writel(value, padcfg0); 42617fab473SAndy Shevchenko } 42717fab473SAndy Shevchenko 428f5a26acfSMika Westerberg static void intel_gpio_set_gpio_mode(void __iomem *padcfg0) 429f5a26acfSMika Westerberg { 430f5a26acfSMika Westerberg u32 value; 431f5a26acfSMika Westerberg 432f5a26acfSMika Westerberg /* Put the pad into GPIO mode */ 433f5a26acfSMika Westerberg value = readl(padcfg0) & ~PADCFG0_PMODE_MASK; 434f5a26acfSMika Westerberg /* Disable SCI/SMI/NMI generation */ 435f5a26acfSMika Westerberg value &= ~(PADCFG0_GPIROUTIOXAPIC | PADCFG0_GPIROUTSCI); 436f5a26acfSMika Westerberg value &= ~(PADCFG0_GPIROUTSMI | PADCFG0_GPIROUTNMI); 437f5a26acfSMika Westerberg writel(value, padcfg0); 438f5a26acfSMika Westerberg } 439f5a26acfSMika Westerberg 4407981c001SMika Westerberg static int intel_gpio_request_enable(struct pinctrl_dev *pctldev, 4417981c001SMika Westerberg struct pinctrl_gpio_range *range, 44204035f7fSAndy Shevchenko unsigned int pin) 4437981c001SMika Westerberg { 4447981c001SMika Westerberg struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 4457981c001SMika Westerberg void __iomem *padcfg0; 4467981c001SMika Westerberg unsigned long flags; 4477981c001SMika Westerberg 44827d9098cSMika Westerberg raw_spin_lock_irqsave(&pctrl->lock, flags); 4497981c001SMika Westerberg 4507981c001SMika Westerberg if (!intel_pad_usable(pctrl, pin)) { 45127d9098cSMika Westerberg raw_spin_unlock_irqrestore(&pctrl->lock, flags); 4527981c001SMika Westerberg return -EBUSY; 4537981c001SMika Westerberg } 4547981c001SMika Westerberg 4557981c001SMika Westerberg padcfg0 = intel_get_padcfg(pctrl, pin, PADCFG0); 456f5a26acfSMika Westerberg intel_gpio_set_gpio_mode(padcfg0); 45717fab473SAndy Shevchenko /* Disable TX buffer and enable RX (this will be input) */ 45817fab473SAndy Shevchenko __intel_gpio_set_direction(padcfg0, true); 45917fab473SAndy Shevchenko 46027d9098cSMika Westerberg raw_spin_unlock_irqrestore(&pctrl->lock, flags); 4617981c001SMika Westerberg 4627981c001SMika Westerberg return 0; 4637981c001SMika Westerberg } 4647981c001SMika Westerberg 4657981c001SMika Westerberg static int intel_gpio_set_direction(struct pinctrl_dev *pctldev, 4667981c001SMika Westerberg struct pinctrl_gpio_range *range, 46704035f7fSAndy Shevchenko unsigned int pin, bool input) 4687981c001SMika Westerberg { 4697981c001SMika Westerberg struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 4707981c001SMika Westerberg void __iomem *padcfg0; 4717981c001SMika Westerberg unsigned long flags; 4727981c001SMika Westerberg 47327d9098cSMika Westerberg raw_spin_lock_irqsave(&pctrl->lock, flags); 4747981c001SMika Westerberg 4757981c001SMika Westerberg padcfg0 = intel_get_padcfg(pctrl, pin, PADCFG0); 47617fab473SAndy Shevchenko __intel_gpio_set_direction(padcfg0, input); 4777981c001SMika Westerberg 47827d9098cSMika Westerberg raw_spin_unlock_irqrestore(&pctrl->lock, flags); 4797981c001SMika Westerberg 4807981c001SMika Westerberg return 0; 4817981c001SMika Westerberg } 4827981c001SMika Westerberg 4837981c001SMika Westerberg static const struct pinmux_ops intel_pinmux_ops = { 4847981c001SMika Westerberg .get_functions_count = intel_get_functions_count, 4857981c001SMika Westerberg .get_function_name = intel_get_function_name, 4867981c001SMika Westerberg .get_function_groups = intel_get_function_groups, 4877981c001SMika Westerberg .set_mux = intel_pinmux_set_mux, 4887981c001SMika Westerberg .gpio_request_enable = intel_gpio_request_enable, 4897981c001SMika Westerberg .gpio_set_direction = intel_gpio_set_direction, 4907981c001SMika Westerberg }; 4917981c001SMika Westerberg 49204035f7fSAndy Shevchenko static int intel_config_get(struct pinctrl_dev *pctldev, unsigned int pin, 4937981c001SMika Westerberg unsigned long *config) 4947981c001SMika Westerberg { 4957981c001SMika Westerberg struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 4967981c001SMika Westerberg enum pin_config_param param = pinconf_to_config_param(*config); 49704cc058fSMika Westerberg const struct intel_community *community; 4987981c001SMika Westerberg u32 value, term; 499e57725eaSMika Westerberg u32 arg = 0; 5007981c001SMika Westerberg 5017981c001SMika Westerberg if (!intel_pad_owned_by_host(pctrl, pin)) 5027981c001SMika Westerberg return -ENOTSUPP; 5037981c001SMika Westerberg 50404cc058fSMika Westerberg community = intel_get_community(pctrl, pin); 5057981c001SMika Westerberg value = readl(intel_get_padcfg(pctrl, pin, PADCFG1)); 5067981c001SMika Westerberg term = (value & PADCFG1_TERM_MASK) >> PADCFG1_TERM_SHIFT; 5077981c001SMika Westerberg 5087981c001SMika Westerberg switch (param) { 5097981c001SMika Westerberg case PIN_CONFIG_BIAS_DISABLE: 5107981c001SMika Westerberg if (term) 5117981c001SMika Westerberg return -EINVAL; 5127981c001SMika Westerberg break; 5137981c001SMika Westerberg 5147981c001SMika Westerberg case PIN_CONFIG_BIAS_PULL_UP: 5157981c001SMika Westerberg if (!term || !(value & PADCFG1_TERM_UP)) 5167981c001SMika Westerberg return -EINVAL; 5177981c001SMika Westerberg 5187981c001SMika Westerberg switch (term) { 5197981c001SMika Westerberg case PADCFG1_TERM_1K: 5207981c001SMika Westerberg arg = 1000; 5217981c001SMika Westerberg break; 5227981c001SMika Westerberg case PADCFG1_TERM_2K: 5237981c001SMika Westerberg arg = 2000; 5247981c001SMika Westerberg break; 5257981c001SMika Westerberg case PADCFG1_TERM_5K: 5267981c001SMika Westerberg arg = 5000; 5277981c001SMika Westerberg break; 5287981c001SMika Westerberg case PADCFG1_TERM_20K: 5297981c001SMika Westerberg arg = 20000; 5307981c001SMika Westerberg break; 5317981c001SMika Westerberg } 5327981c001SMika Westerberg 5337981c001SMika Westerberg break; 5347981c001SMika Westerberg 5357981c001SMika Westerberg case PIN_CONFIG_BIAS_PULL_DOWN: 5367981c001SMika Westerberg if (!term || value & PADCFG1_TERM_UP) 5377981c001SMika Westerberg return -EINVAL; 5387981c001SMika Westerberg 5397981c001SMika Westerberg switch (term) { 54004cc058fSMika Westerberg case PADCFG1_TERM_1K: 54104cc058fSMika Westerberg if (!(community->features & PINCTRL_FEATURE_1K_PD)) 54204cc058fSMika Westerberg return -EINVAL; 54304cc058fSMika Westerberg arg = 1000; 54404cc058fSMika Westerberg break; 5457981c001SMika Westerberg case PADCFG1_TERM_5K: 5467981c001SMika Westerberg arg = 5000; 5477981c001SMika Westerberg break; 5487981c001SMika Westerberg case PADCFG1_TERM_20K: 5497981c001SMika Westerberg arg = 20000; 5507981c001SMika Westerberg break; 5517981c001SMika Westerberg } 5527981c001SMika Westerberg 5537981c001SMika Westerberg break; 5547981c001SMika Westerberg 555e57725eaSMika Westerberg case PIN_CONFIG_INPUT_DEBOUNCE: { 556e57725eaSMika Westerberg void __iomem *padcfg2; 557e57725eaSMika Westerberg u32 v; 558e57725eaSMika Westerberg 559e57725eaSMika Westerberg padcfg2 = intel_get_padcfg(pctrl, pin, PADCFG2); 560e57725eaSMika Westerberg if (!padcfg2) 561e57725eaSMika Westerberg return -ENOTSUPP; 562e57725eaSMika Westerberg 563e57725eaSMika Westerberg v = readl(padcfg2); 564e57725eaSMika Westerberg if (!(v & PADCFG2_DEBEN)) 565e57725eaSMika Westerberg return -EINVAL; 566e57725eaSMika Westerberg 567e57725eaSMika Westerberg v = (v & PADCFG2_DEBOUNCE_MASK) >> PADCFG2_DEBOUNCE_SHIFT; 568e57725eaSMika Westerberg arg = BIT(v) * DEBOUNCE_PERIOD / 1000; 569e57725eaSMika Westerberg 570e57725eaSMika Westerberg break; 571e57725eaSMika Westerberg } 572e57725eaSMika Westerberg 5737981c001SMika Westerberg default: 5747981c001SMika Westerberg return -ENOTSUPP; 5757981c001SMika Westerberg } 5767981c001SMika Westerberg 5777981c001SMika Westerberg *config = pinconf_to_config_packed(param, arg); 5787981c001SMika Westerberg return 0; 5797981c001SMika Westerberg } 5807981c001SMika Westerberg 58104035f7fSAndy Shevchenko static int intel_config_set_pull(struct intel_pinctrl *pctrl, unsigned int pin, 5827981c001SMika Westerberg unsigned long config) 5837981c001SMika Westerberg { 58404035f7fSAndy Shevchenko unsigned int param = pinconf_to_config_param(config); 58504035f7fSAndy Shevchenko unsigned int arg = pinconf_to_config_argument(config); 58604cc058fSMika Westerberg const struct intel_community *community; 5877981c001SMika Westerberg void __iomem *padcfg1; 5887981c001SMika Westerberg unsigned long flags; 5897981c001SMika Westerberg int ret = 0; 5907981c001SMika Westerberg u32 value; 5917981c001SMika Westerberg 59227d9098cSMika Westerberg raw_spin_lock_irqsave(&pctrl->lock, flags); 5937981c001SMika Westerberg 59404cc058fSMika Westerberg community = intel_get_community(pctrl, pin); 5957981c001SMika Westerberg padcfg1 = intel_get_padcfg(pctrl, pin, PADCFG1); 5967981c001SMika Westerberg value = readl(padcfg1); 5977981c001SMika Westerberg 5987981c001SMika Westerberg switch (param) { 5997981c001SMika Westerberg case PIN_CONFIG_BIAS_DISABLE: 6007981c001SMika Westerberg value &= ~(PADCFG1_TERM_MASK | PADCFG1_TERM_UP); 6017981c001SMika Westerberg break; 6027981c001SMika Westerberg 6037981c001SMika Westerberg case PIN_CONFIG_BIAS_PULL_UP: 6047981c001SMika Westerberg value &= ~PADCFG1_TERM_MASK; 6057981c001SMika Westerberg 6067981c001SMika Westerberg value |= PADCFG1_TERM_UP; 6077981c001SMika Westerberg 6087981c001SMika Westerberg switch (arg) { 6097981c001SMika Westerberg case 20000: 6107981c001SMika Westerberg value |= PADCFG1_TERM_20K << PADCFG1_TERM_SHIFT; 6117981c001SMika Westerberg break; 6127981c001SMika Westerberg case 5000: 6137981c001SMika Westerberg value |= PADCFG1_TERM_5K << PADCFG1_TERM_SHIFT; 6147981c001SMika Westerberg break; 6157981c001SMika Westerberg case 2000: 6167981c001SMika Westerberg value |= PADCFG1_TERM_2K << PADCFG1_TERM_SHIFT; 6177981c001SMika Westerberg break; 6187981c001SMika Westerberg case 1000: 6197981c001SMika Westerberg value |= PADCFG1_TERM_1K << PADCFG1_TERM_SHIFT; 6207981c001SMika Westerberg break; 6217981c001SMika Westerberg default: 6227981c001SMika Westerberg ret = -EINVAL; 6237981c001SMika Westerberg } 6247981c001SMika Westerberg 6257981c001SMika Westerberg break; 6267981c001SMika Westerberg 6277981c001SMika Westerberg case PIN_CONFIG_BIAS_PULL_DOWN: 6287981c001SMika Westerberg value &= ~(PADCFG1_TERM_UP | PADCFG1_TERM_MASK); 6297981c001SMika Westerberg 6307981c001SMika Westerberg switch (arg) { 6317981c001SMika Westerberg case 20000: 6327981c001SMika Westerberg value |= PADCFG1_TERM_20K << PADCFG1_TERM_SHIFT; 6337981c001SMika Westerberg break; 6347981c001SMika Westerberg case 5000: 6357981c001SMika Westerberg value |= PADCFG1_TERM_5K << PADCFG1_TERM_SHIFT; 6367981c001SMika Westerberg break; 63704cc058fSMika Westerberg case 1000: 638aa1dd80fSDan Carpenter if (!(community->features & PINCTRL_FEATURE_1K_PD)) { 639aa1dd80fSDan Carpenter ret = -EINVAL; 640aa1dd80fSDan Carpenter break; 641aa1dd80fSDan Carpenter } 64204cc058fSMika Westerberg value |= PADCFG1_TERM_1K << PADCFG1_TERM_SHIFT; 64304cc058fSMika Westerberg break; 6447981c001SMika Westerberg default: 6457981c001SMika Westerberg ret = -EINVAL; 6467981c001SMika Westerberg } 6477981c001SMika Westerberg 6487981c001SMika Westerberg break; 6497981c001SMika Westerberg } 6507981c001SMika Westerberg 6517981c001SMika Westerberg if (!ret) 6527981c001SMika Westerberg writel(value, padcfg1); 6537981c001SMika Westerberg 65427d9098cSMika Westerberg raw_spin_unlock_irqrestore(&pctrl->lock, flags); 6557981c001SMika Westerberg 6567981c001SMika Westerberg return ret; 6577981c001SMika Westerberg } 6587981c001SMika Westerberg 65904035f7fSAndy Shevchenko static int intel_config_set_debounce(struct intel_pinctrl *pctrl, 66004035f7fSAndy Shevchenko unsigned int pin, unsigned int debounce) 661e57725eaSMika Westerberg { 662e57725eaSMika Westerberg void __iomem *padcfg0, *padcfg2; 663e57725eaSMika Westerberg unsigned long flags; 664e57725eaSMika Westerberg u32 value0, value2; 665e57725eaSMika Westerberg int ret = 0; 666e57725eaSMika Westerberg 667e57725eaSMika Westerberg padcfg2 = intel_get_padcfg(pctrl, pin, PADCFG2); 668e57725eaSMika Westerberg if (!padcfg2) 669e57725eaSMika Westerberg return -ENOTSUPP; 670e57725eaSMika Westerberg 671e57725eaSMika Westerberg padcfg0 = intel_get_padcfg(pctrl, pin, PADCFG0); 672e57725eaSMika Westerberg 673e57725eaSMika Westerberg raw_spin_lock_irqsave(&pctrl->lock, flags); 674e57725eaSMika Westerberg 675e57725eaSMika Westerberg value0 = readl(padcfg0); 676e57725eaSMika Westerberg value2 = readl(padcfg2); 677e57725eaSMika Westerberg 678e57725eaSMika Westerberg /* Disable glitch filter and debouncer */ 679e57725eaSMika Westerberg value0 &= ~PADCFG0_PREGFRXSEL; 680e57725eaSMika Westerberg value2 &= ~(PADCFG2_DEBEN | PADCFG2_DEBOUNCE_MASK); 681e57725eaSMika Westerberg 682e57725eaSMika Westerberg if (debounce) { 683e57725eaSMika Westerberg unsigned long v; 684e57725eaSMika Westerberg 685e57725eaSMika Westerberg v = order_base_2(debounce * 1000 / DEBOUNCE_PERIOD); 686e57725eaSMika Westerberg if (v < 3 || v > 15) { 687e57725eaSMika Westerberg ret = -EINVAL; 688e57725eaSMika Westerberg goto exit_unlock; 689e57725eaSMika Westerberg } else { 690e57725eaSMika Westerberg /* Enable glitch filter and debouncer */ 691e57725eaSMika Westerberg value0 |= PADCFG0_PREGFRXSEL; 692e57725eaSMika Westerberg value2 |= v << PADCFG2_DEBOUNCE_SHIFT; 693e57725eaSMika Westerberg value2 |= PADCFG2_DEBEN; 694e57725eaSMika Westerberg } 695e57725eaSMika Westerberg } 696e57725eaSMika Westerberg 697e57725eaSMika Westerberg writel(value0, padcfg0); 698e57725eaSMika Westerberg writel(value2, padcfg2); 699e57725eaSMika Westerberg 700e57725eaSMika Westerberg exit_unlock: 701e57725eaSMika Westerberg raw_spin_unlock_irqrestore(&pctrl->lock, flags); 702e57725eaSMika Westerberg 703e57725eaSMika Westerberg return ret; 704e57725eaSMika Westerberg } 705e57725eaSMika Westerberg 70604035f7fSAndy Shevchenko static int intel_config_set(struct pinctrl_dev *pctldev, unsigned int pin, 70704035f7fSAndy Shevchenko unsigned long *configs, unsigned int nconfigs) 7087981c001SMika Westerberg { 7097981c001SMika Westerberg struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 7107981c001SMika Westerberg int i, ret; 7117981c001SMika Westerberg 7127981c001SMika Westerberg if (!intel_pad_usable(pctrl, pin)) 7137981c001SMika Westerberg return -ENOTSUPP; 7147981c001SMika Westerberg 7157981c001SMika Westerberg for (i = 0; i < nconfigs; i++) { 7167981c001SMika Westerberg switch (pinconf_to_config_param(configs[i])) { 7177981c001SMika Westerberg case PIN_CONFIG_BIAS_DISABLE: 7187981c001SMika Westerberg case PIN_CONFIG_BIAS_PULL_UP: 7197981c001SMika Westerberg case PIN_CONFIG_BIAS_PULL_DOWN: 7207981c001SMika Westerberg ret = intel_config_set_pull(pctrl, pin, configs[i]); 7217981c001SMika Westerberg if (ret) 7227981c001SMika Westerberg return ret; 7237981c001SMika Westerberg break; 7247981c001SMika Westerberg 725e57725eaSMika Westerberg case PIN_CONFIG_INPUT_DEBOUNCE: 726e57725eaSMika Westerberg ret = intel_config_set_debounce(pctrl, pin, 727e57725eaSMika Westerberg pinconf_to_config_argument(configs[i])); 728e57725eaSMika Westerberg if (ret) 729e57725eaSMika Westerberg return ret; 730e57725eaSMika Westerberg break; 731e57725eaSMika Westerberg 7327981c001SMika Westerberg default: 7337981c001SMika Westerberg return -ENOTSUPP; 7347981c001SMika Westerberg } 7357981c001SMika Westerberg } 7367981c001SMika Westerberg 7377981c001SMika Westerberg return 0; 7387981c001SMika Westerberg } 7397981c001SMika Westerberg 7407981c001SMika Westerberg static const struct pinconf_ops intel_pinconf_ops = { 7417981c001SMika Westerberg .is_generic = true, 7427981c001SMika Westerberg .pin_config_get = intel_config_get, 7437981c001SMika Westerberg .pin_config_set = intel_config_set, 7447981c001SMika Westerberg }; 7457981c001SMika Westerberg 7467981c001SMika Westerberg static const struct pinctrl_desc intel_pinctrl_desc = { 7477981c001SMika Westerberg .pctlops = &intel_pinctrl_ops, 7487981c001SMika Westerberg .pmxops = &intel_pinmux_ops, 7497981c001SMika Westerberg .confops = &intel_pinconf_ops, 7507981c001SMika Westerberg .owner = THIS_MODULE, 7517981c001SMika Westerberg }; 7527981c001SMika Westerberg 753a60eac32SMika Westerberg /** 754a60eac32SMika Westerberg * intel_gpio_to_pin() - Translate from GPIO offset to pin number 755a60eac32SMika Westerberg * @pctrl: Pinctrl structure 756a60eac32SMika Westerberg * @offset: GPIO offset from gpiolib 757946ffefcSAndy Shevchenko * @community: Community is filled here if not %NULL 758a60eac32SMika Westerberg * @padgrp: Pad group is filled here if not %NULL 759a60eac32SMika Westerberg * 760a60eac32SMika Westerberg * When coming through gpiolib irqchip, the GPIO offset is not 761a60eac32SMika Westerberg * automatically translated to pinctrl pin number. This function can be 762a60eac32SMika Westerberg * used to find out the corresponding pinctrl pin. 763a60eac32SMika Westerberg */ 76404035f7fSAndy Shevchenko static int intel_gpio_to_pin(struct intel_pinctrl *pctrl, unsigned int offset, 765a60eac32SMika Westerberg const struct intel_community **community, 766a60eac32SMika Westerberg const struct intel_padgroup **padgrp) 767a60eac32SMika Westerberg { 768a60eac32SMika Westerberg int i; 769a60eac32SMika Westerberg 770a60eac32SMika Westerberg for (i = 0; i < pctrl->ncommunities; i++) { 771a60eac32SMika Westerberg const struct intel_community *comm = &pctrl->communities[i]; 772a60eac32SMika Westerberg int j; 773a60eac32SMika Westerberg 774a60eac32SMika Westerberg for (j = 0; j < comm->ngpps; j++) { 775a60eac32SMika Westerberg const struct intel_padgroup *pgrp = &comm->gpps[j]; 776a60eac32SMika Westerberg 777a60eac32SMika Westerberg if (pgrp->gpio_base < 0) 778a60eac32SMika Westerberg continue; 779a60eac32SMika Westerberg 780a60eac32SMika Westerberg if (offset >= pgrp->gpio_base && 781a60eac32SMika Westerberg offset < pgrp->gpio_base + pgrp->size) { 782a60eac32SMika Westerberg int pin; 783a60eac32SMika Westerberg 784a60eac32SMika Westerberg pin = pgrp->base + offset - pgrp->gpio_base; 785a60eac32SMika Westerberg if (community) 786a60eac32SMika Westerberg *community = comm; 787a60eac32SMika Westerberg if (padgrp) 788a60eac32SMika Westerberg *padgrp = pgrp; 789a60eac32SMika Westerberg 790a60eac32SMika Westerberg return pin; 791a60eac32SMika Westerberg } 792a60eac32SMika Westerberg } 793a60eac32SMika Westerberg } 794a60eac32SMika Westerberg 795a60eac32SMika Westerberg return -EINVAL; 796a60eac32SMika Westerberg } 797a60eac32SMika Westerberg 79804035f7fSAndy Shevchenko static int intel_gpio_get(struct gpio_chip *chip, unsigned int offset) 79955aedef5SAndy Shevchenko { 80096147db1SMika Westerberg struct intel_pinctrl *pctrl = gpiochip_get_data(chip); 80196147db1SMika Westerberg void __iomem *reg; 80296147db1SMika Westerberg u32 padcfg0; 80355aedef5SAndy Shevchenko int pin; 80455aedef5SAndy Shevchenko 80596147db1SMika Westerberg pin = intel_gpio_to_pin(pctrl, offset, NULL, NULL); 80696147db1SMika Westerberg if (pin < 0) 80796147db1SMika Westerberg return -EINVAL; 80896147db1SMika Westerberg 80996147db1SMika Westerberg reg = intel_get_padcfg(pctrl, pin, PADCFG0); 81096147db1SMika Westerberg if (!reg) 81196147db1SMika Westerberg return -EINVAL; 81296147db1SMika Westerberg 81396147db1SMika Westerberg padcfg0 = readl(reg); 81496147db1SMika Westerberg if (!(padcfg0 & PADCFG0_GPIOTXDIS)) 81596147db1SMika Westerberg return !!(padcfg0 & PADCFG0_GPIOTXSTATE); 81696147db1SMika Westerberg 81796147db1SMika Westerberg return !!(padcfg0 & PADCFG0_GPIORXSTATE); 81855aedef5SAndy Shevchenko } 81955aedef5SAndy Shevchenko 82004035f7fSAndy Shevchenko static void intel_gpio_set(struct gpio_chip *chip, unsigned int offset, 82104035f7fSAndy Shevchenko int value) 82296147db1SMika Westerberg { 82396147db1SMika Westerberg struct intel_pinctrl *pctrl = gpiochip_get_data(chip); 82496147db1SMika Westerberg unsigned long flags; 82596147db1SMika Westerberg void __iomem *reg; 82696147db1SMika Westerberg u32 padcfg0; 82796147db1SMika Westerberg int pin; 82896147db1SMika Westerberg 82996147db1SMika Westerberg pin = intel_gpio_to_pin(pctrl, offset, NULL, NULL); 83096147db1SMika Westerberg if (pin < 0) 83196147db1SMika Westerberg return; 83296147db1SMika Westerberg 83396147db1SMika Westerberg reg = intel_get_padcfg(pctrl, pin, PADCFG0); 83496147db1SMika Westerberg if (!reg) 83596147db1SMika Westerberg return; 83696147db1SMika Westerberg 83796147db1SMika Westerberg raw_spin_lock_irqsave(&pctrl->lock, flags); 83896147db1SMika Westerberg padcfg0 = readl(reg); 83996147db1SMika Westerberg if (value) 84096147db1SMika Westerberg padcfg0 |= PADCFG0_GPIOTXSTATE; 84196147db1SMika Westerberg else 84296147db1SMika Westerberg padcfg0 &= ~PADCFG0_GPIOTXSTATE; 84396147db1SMika Westerberg writel(padcfg0, reg); 84496147db1SMika Westerberg raw_spin_unlock_irqrestore(&pctrl->lock, flags); 84596147db1SMika Westerberg } 84696147db1SMika Westerberg 84796147db1SMika Westerberg static int intel_gpio_get_direction(struct gpio_chip *chip, unsigned int offset) 84896147db1SMika Westerberg { 84996147db1SMika Westerberg struct intel_pinctrl *pctrl = gpiochip_get_data(chip); 85096147db1SMika Westerberg void __iomem *reg; 85196147db1SMika Westerberg u32 padcfg0; 85296147db1SMika Westerberg int pin; 85396147db1SMika Westerberg 85496147db1SMika Westerberg pin = intel_gpio_to_pin(pctrl, offset, NULL, NULL); 85596147db1SMika Westerberg if (pin < 0) 85696147db1SMika Westerberg return -EINVAL; 85796147db1SMika Westerberg 85896147db1SMika Westerberg reg = intel_get_padcfg(pctrl, pin, PADCFG0); 85996147db1SMika Westerberg if (!reg) 86096147db1SMika Westerberg return -EINVAL; 86196147db1SMika Westerberg 86296147db1SMika Westerberg padcfg0 = readl(reg); 86396147db1SMika Westerberg 86496147db1SMika Westerberg if (padcfg0 & PADCFG0_PMODE_MASK) 86596147db1SMika Westerberg return -EINVAL; 86696147db1SMika Westerberg 86796147db1SMika Westerberg return !!(padcfg0 & PADCFG0_GPIOTXDIS); 86896147db1SMika Westerberg } 86996147db1SMika Westerberg 87004035f7fSAndy Shevchenko static int intel_gpio_direction_input(struct gpio_chip *chip, unsigned int offset) 87196147db1SMika Westerberg { 87296147db1SMika Westerberg return pinctrl_gpio_direction_input(chip->base + offset); 87396147db1SMika Westerberg } 87496147db1SMika Westerberg 87504035f7fSAndy Shevchenko static int intel_gpio_direction_output(struct gpio_chip *chip, unsigned int offset, 87696147db1SMika Westerberg int value) 87796147db1SMika Westerberg { 87896147db1SMika Westerberg intel_gpio_set(chip, offset, value); 87996147db1SMika Westerberg return pinctrl_gpio_direction_output(chip->base + offset); 88096147db1SMika Westerberg } 88196147db1SMika Westerberg 88296147db1SMika Westerberg static const struct gpio_chip intel_gpio_chip = { 88396147db1SMika Westerberg .owner = THIS_MODULE, 88496147db1SMika Westerberg .request = gpiochip_generic_request, 88596147db1SMika Westerberg .free = gpiochip_generic_free, 88696147db1SMika Westerberg .get_direction = intel_gpio_get_direction, 88796147db1SMika Westerberg .direction_input = intel_gpio_direction_input, 88896147db1SMika Westerberg .direction_output = intel_gpio_direction_output, 88996147db1SMika Westerberg .get = intel_gpio_get, 89096147db1SMika Westerberg .set = intel_gpio_set, 89196147db1SMika Westerberg .set_config = gpiochip_generic_config, 89296147db1SMika Westerberg }; 89396147db1SMika Westerberg 8947981c001SMika Westerberg static void intel_gpio_irq_ack(struct irq_data *d) 8957981c001SMika Westerberg { 8967981c001SMika Westerberg struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 897acfd4c63SLinus Walleij struct intel_pinctrl *pctrl = gpiochip_get_data(gc); 8987981c001SMika Westerberg const struct intel_community *community; 899919eb475SMika Westerberg const struct intel_padgroup *padgrp; 900a60eac32SMika Westerberg int pin; 9017981c001SMika Westerberg 902a60eac32SMika Westerberg pin = intel_gpio_to_pin(pctrl, irqd_to_hwirq(d), &community, &padgrp); 903a60eac32SMika Westerberg if (pin >= 0) { 90404035f7fSAndy Shevchenko unsigned int gpp, gpp_offset, is_offset; 905919eb475SMika Westerberg 906919eb475SMika Westerberg gpp = padgrp->reg_num; 907919eb475SMika Westerberg gpp_offset = padgroup_offset(padgrp, pin); 908cf769bd8SMika Westerberg is_offset = community->is_offset + gpp * 4; 909919eb475SMika Westerberg 910919eb475SMika Westerberg raw_spin_lock(&pctrl->lock); 911cf769bd8SMika Westerberg writel(BIT(gpp_offset), community->regs + is_offset); 91227d9098cSMika Westerberg raw_spin_unlock(&pctrl->lock); 9137981c001SMika Westerberg } 914919eb475SMika Westerberg } 9157981c001SMika Westerberg 916a939bb57SQi Zheng static void intel_gpio_irq_enable(struct irq_data *d) 917a939bb57SQi Zheng { 918a939bb57SQi Zheng struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 919a939bb57SQi Zheng struct intel_pinctrl *pctrl = gpiochip_get_data(gc); 920a939bb57SQi Zheng const struct intel_community *community; 921919eb475SMika Westerberg const struct intel_padgroup *padgrp; 922a60eac32SMika Westerberg int pin; 923a60eac32SMika Westerberg 924a60eac32SMika Westerberg pin = intel_gpio_to_pin(pctrl, irqd_to_hwirq(d), &community, &padgrp); 925a60eac32SMika Westerberg if (pin >= 0) { 92604035f7fSAndy Shevchenko unsigned int gpp, gpp_offset, is_offset; 927919eb475SMika Westerberg unsigned long flags; 928a939bb57SQi Zheng u32 value; 929a939bb57SQi Zheng 930919eb475SMika Westerberg gpp = padgrp->reg_num; 931919eb475SMika Westerberg gpp_offset = padgroup_offset(padgrp, pin); 932cf769bd8SMika Westerberg is_offset = community->is_offset + gpp * 4; 933919eb475SMika Westerberg 934919eb475SMika Westerberg raw_spin_lock_irqsave(&pctrl->lock, flags); 935a939bb57SQi Zheng /* Clear interrupt status first to avoid unexpected interrupt */ 936cf769bd8SMika Westerberg writel(BIT(gpp_offset), community->regs + is_offset); 937a939bb57SQi Zheng 938a939bb57SQi Zheng value = readl(community->regs + community->ie_offset + gpp * 4); 939a939bb57SQi Zheng value |= BIT(gpp_offset); 940a939bb57SQi Zheng writel(value, community->regs + community->ie_offset + gpp * 4); 94127d9098cSMika Westerberg raw_spin_unlock_irqrestore(&pctrl->lock, flags); 942a939bb57SQi Zheng } 943919eb475SMika Westerberg } 944a939bb57SQi Zheng 9457981c001SMika Westerberg static void intel_gpio_irq_mask_unmask(struct irq_data *d, bool mask) 9467981c001SMika Westerberg { 9477981c001SMika Westerberg struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 948acfd4c63SLinus Walleij struct intel_pinctrl *pctrl = gpiochip_get_data(gc); 9497981c001SMika Westerberg const struct intel_community *community; 950919eb475SMika Westerberg const struct intel_padgroup *padgrp; 951a60eac32SMika Westerberg int pin; 952a60eac32SMika Westerberg 953a60eac32SMika Westerberg pin = intel_gpio_to_pin(pctrl, irqd_to_hwirq(d), &community, &padgrp); 954a60eac32SMika Westerberg if (pin >= 0) { 95504035f7fSAndy Shevchenko unsigned int gpp, gpp_offset; 956919eb475SMika Westerberg unsigned long flags; 9577981c001SMika Westerberg void __iomem *reg; 9587981c001SMika Westerberg u32 value; 9597981c001SMika Westerberg 960919eb475SMika Westerberg gpp = padgrp->reg_num; 961919eb475SMika Westerberg gpp_offset = padgroup_offset(padgrp, pin); 962919eb475SMika Westerberg 9637981c001SMika Westerberg reg = community->regs + community->ie_offset + gpp * 4; 964919eb475SMika Westerberg 965919eb475SMika Westerberg raw_spin_lock_irqsave(&pctrl->lock, flags); 9667981c001SMika Westerberg value = readl(reg); 9677981c001SMika Westerberg if (mask) 9687981c001SMika Westerberg value &= ~BIT(gpp_offset); 9697981c001SMika Westerberg else 9707981c001SMika Westerberg value |= BIT(gpp_offset); 9717981c001SMika Westerberg writel(value, reg); 97227d9098cSMika Westerberg raw_spin_unlock_irqrestore(&pctrl->lock, flags); 9737981c001SMika Westerberg } 974919eb475SMika Westerberg } 9757981c001SMika Westerberg 9767981c001SMika Westerberg static void intel_gpio_irq_mask(struct irq_data *d) 9777981c001SMika Westerberg { 9787981c001SMika Westerberg intel_gpio_irq_mask_unmask(d, true); 9797981c001SMika Westerberg } 9807981c001SMika Westerberg 9817981c001SMika Westerberg static void intel_gpio_irq_unmask(struct irq_data *d) 9827981c001SMika Westerberg { 9837981c001SMika Westerberg intel_gpio_irq_mask_unmask(d, false); 9847981c001SMika Westerberg } 9857981c001SMika Westerberg 98604035f7fSAndy Shevchenko static int intel_gpio_irq_type(struct irq_data *d, unsigned int type) 9877981c001SMika Westerberg { 9887981c001SMika Westerberg struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 989acfd4c63SLinus Walleij struct intel_pinctrl *pctrl = gpiochip_get_data(gc); 99004035f7fSAndy Shevchenko unsigned int pin = intel_gpio_to_pin(pctrl, irqd_to_hwirq(d), NULL, NULL); 9917981c001SMika Westerberg unsigned long flags; 9927981c001SMika Westerberg void __iomem *reg; 9937981c001SMika Westerberg u32 value; 9947981c001SMika Westerberg 9957981c001SMika Westerberg reg = intel_get_padcfg(pctrl, pin, PADCFG0); 9967981c001SMika Westerberg if (!reg) 9977981c001SMika Westerberg return -EINVAL; 9987981c001SMika Westerberg 9994341e8a5SMika Westerberg /* 10004341e8a5SMika Westerberg * If the pin is in ACPI mode it is still usable as a GPIO but it 10014341e8a5SMika Westerberg * cannot be used as IRQ because GPI_IS status bit will not be 10024341e8a5SMika Westerberg * updated by the host controller hardware. 10034341e8a5SMika Westerberg */ 10044341e8a5SMika Westerberg if (intel_pad_acpi_mode(pctrl, pin)) { 10054341e8a5SMika Westerberg dev_warn(pctrl->dev, "pin %u cannot be used as IRQ\n", pin); 10064341e8a5SMika Westerberg return -EPERM; 10074341e8a5SMika Westerberg } 10084341e8a5SMika Westerberg 100927d9098cSMika Westerberg raw_spin_lock_irqsave(&pctrl->lock, flags); 10107981c001SMika Westerberg 1011f5a26acfSMika Westerberg intel_gpio_set_gpio_mode(reg); 1012f5a26acfSMika Westerberg 10137981c001SMika Westerberg value = readl(reg); 10147981c001SMika Westerberg 10157981c001SMika Westerberg value &= ~(PADCFG0_RXEVCFG_MASK | PADCFG0_RXINV); 10167981c001SMika Westerberg 10177981c001SMika Westerberg if ((type & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH) { 10187981c001SMika Westerberg value |= PADCFG0_RXEVCFG_EDGE_BOTH << PADCFG0_RXEVCFG_SHIFT; 10197981c001SMika Westerberg } else if (type & IRQ_TYPE_EDGE_FALLING) { 10207981c001SMika Westerberg value |= PADCFG0_RXEVCFG_EDGE << PADCFG0_RXEVCFG_SHIFT; 10217981c001SMika Westerberg value |= PADCFG0_RXINV; 10227981c001SMika Westerberg } else if (type & IRQ_TYPE_EDGE_RISING) { 10237981c001SMika Westerberg value |= PADCFG0_RXEVCFG_EDGE << PADCFG0_RXEVCFG_SHIFT; 1024bf380cfaSQipeng Zha } else if (type & IRQ_TYPE_LEVEL_MASK) { 1025bf380cfaSQipeng Zha if (type & IRQ_TYPE_LEVEL_LOW) 10267981c001SMika Westerberg value |= PADCFG0_RXINV; 10277981c001SMika Westerberg } else { 10287981c001SMika Westerberg value |= PADCFG0_RXEVCFG_DISABLED << PADCFG0_RXEVCFG_SHIFT; 10297981c001SMika Westerberg } 10307981c001SMika Westerberg 10317981c001SMika Westerberg writel(value, reg); 10327981c001SMika Westerberg 10337981c001SMika Westerberg if (type & IRQ_TYPE_EDGE_BOTH) 1034fc756bcdSThomas Gleixner irq_set_handler_locked(d, handle_edge_irq); 10357981c001SMika Westerberg else if (type & IRQ_TYPE_LEVEL_MASK) 1036fc756bcdSThomas Gleixner irq_set_handler_locked(d, handle_level_irq); 10377981c001SMika Westerberg 103827d9098cSMika Westerberg raw_spin_unlock_irqrestore(&pctrl->lock, flags); 10397981c001SMika Westerberg 10407981c001SMika Westerberg return 0; 10417981c001SMika Westerberg } 10427981c001SMika Westerberg 10437981c001SMika Westerberg static int intel_gpio_irq_wake(struct irq_data *d, unsigned int on) 10447981c001SMika Westerberg { 10457981c001SMika Westerberg struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 1046acfd4c63SLinus Walleij struct intel_pinctrl *pctrl = gpiochip_get_data(gc); 104704035f7fSAndy Shevchenko unsigned int pin = intel_gpio_to_pin(pctrl, irqd_to_hwirq(d), NULL, NULL); 10487981c001SMika Westerberg 10497981c001SMika Westerberg if (on) 105001dabe91SNilesh Bacchewar enable_irq_wake(pctrl->irq); 10517981c001SMika Westerberg else 105201dabe91SNilesh Bacchewar disable_irq_wake(pctrl->irq); 10539a520fd9SAndy Shevchenko 10547981c001SMika Westerberg dev_dbg(pctrl->dev, "%sable wake for pin %u\n", on ? "en" : "dis", pin); 10557981c001SMika Westerberg return 0; 10567981c001SMika Westerberg } 10577981c001SMika Westerberg 1058193b40c8SMika Westerberg static irqreturn_t intel_gpio_community_irq_handler(struct intel_pinctrl *pctrl, 10597981c001SMika Westerberg const struct intel_community *community) 10607981c001SMika Westerberg { 1061193b40c8SMika Westerberg struct gpio_chip *gc = &pctrl->chip; 1062193b40c8SMika Westerberg irqreturn_t ret = IRQ_NONE; 10637981c001SMika Westerberg int gpp; 10647981c001SMika Westerberg 10657981c001SMika Westerberg for (gpp = 0; gpp < community->ngpps; gpp++) { 1066919eb475SMika Westerberg const struct intel_padgroup *padgrp = &community->gpps[gpp]; 10677981c001SMika Westerberg unsigned long pending, enabled, gpp_offset; 10687981c001SMika Westerberg 1069cf769bd8SMika Westerberg pending = readl(community->regs + community->is_offset + 1070cf769bd8SMika Westerberg padgrp->reg_num * 4); 10717981c001SMika Westerberg enabled = readl(community->regs + community->ie_offset + 1072919eb475SMika Westerberg padgrp->reg_num * 4); 10737981c001SMika Westerberg 10747981c001SMika Westerberg /* Only interrupts that are enabled */ 10757981c001SMika Westerberg pending &= enabled; 10767981c001SMika Westerberg 1077919eb475SMika Westerberg for_each_set_bit(gpp_offset, &pending, padgrp->size) { 1078a60eac32SMika Westerberg unsigned irq; 10797981c001SMika Westerberg 1080f0fbe7bcSThierry Reding irq = irq_find_mapping(gc->irq.domain, 1081a60eac32SMika Westerberg padgrp->gpio_base + gpp_offset); 10827981c001SMika Westerberg generic_handle_irq(irq); 1083193b40c8SMika Westerberg 1084193b40c8SMika Westerberg ret |= IRQ_HANDLED; 10857981c001SMika Westerberg } 10867981c001SMika Westerberg } 10877981c001SMika Westerberg 1088193b40c8SMika Westerberg return ret; 1089193b40c8SMika Westerberg } 1090193b40c8SMika Westerberg 1091193b40c8SMika Westerberg static irqreturn_t intel_gpio_irq(int irq, void *data) 10927981c001SMika Westerberg { 1093193b40c8SMika Westerberg const struct intel_community *community; 1094193b40c8SMika Westerberg struct intel_pinctrl *pctrl = data; 1095193b40c8SMika Westerberg irqreturn_t ret = IRQ_NONE; 10967981c001SMika Westerberg int i; 10977981c001SMika Westerberg 10987981c001SMika Westerberg /* Need to check all communities for pending interrupts */ 1099193b40c8SMika Westerberg for (i = 0; i < pctrl->ncommunities; i++) { 1100193b40c8SMika Westerberg community = &pctrl->communities[i]; 1101193b40c8SMika Westerberg ret |= intel_gpio_community_irq_handler(pctrl, community); 1102193b40c8SMika Westerberg } 11037981c001SMika Westerberg 1104193b40c8SMika Westerberg return ret; 11057981c001SMika Westerberg } 11067981c001SMika Westerberg 11077981c001SMika Westerberg static struct irq_chip intel_gpio_irqchip = { 11087981c001SMika Westerberg .name = "intel-gpio", 1109a939bb57SQi Zheng .irq_enable = intel_gpio_irq_enable, 11107981c001SMika Westerberg .irq_ack = intel_gpio_irq_ack, 11117981c001SMika Westerberg .irq_mask = intel_gpio_irq_mask, 11127981c001SMika Westerberg .irq_unmask = intel_gpio_irq_unmask, 11137981c001SMika Westerberg .irq_set_type = intel_gpio_irq_type, 11147981c001SMika Westerberg .irq_set_wake = intel_gpio_irq_wake, 11155ff56b01SRushikesh S Kadam .flags = IRQCHIP_MASK_ON_SUSPEND, 11167981c001SMika Westerberg }; 11177981c001SMika Westerberg 1118a60eac32SMika Westerberg static int intel_gpio_add_pin_ranges(struct intel_pinctrl *pctrl, 1119a60eac32SMika Westerberg const struct intel_community *community) 1120a60eac32SMika Westerberg { 112133b6cb58SColin Ian King int ret = 0, i; 1122a60eac32SMika Westerberg 1123a60eac32SMika Westerberg for (i = 0; i < community->ngpps; i++) { 1124a60eac32SMika Westerberg const struct intel_padgroup *gpp = &community->gpps[i]; 1125a60eac32SMika Westerberg 1126a60eac32SMika Westerberg if (gpp->gpio_base < 0) 1127a60eac32SMika Westerberg continue; 1128a60eac32SMika Westerberg 1129a60eac32SMika Westerberg ret = gpiochip_add_pin_range(&pctrl->chip, dev_name(pctrl->dev), 1130a60eac32SMika Westerberg gpp->gpio_base, gpp->base, 1131a60eac32SMika Westerberg gpp->size); 1132a60eac32SMika Westerberg if (ret) 1133a60eac32SMika Westerberg return ret; 1134a60eac32SMika Westerberg } 1135a60eac32SMika Westerberg 1136a60eac32SMika Westerberg return ret; 1137a60eac32SMika Westerberg } 1138a60eac32SMika Westerberg 1139a60eac32SMika Westerberg static unsigned intel_gpio_ngpio(const struct intel_pinctrl *pctrl) 1140a60eac32SMika Westerberg { 1141a60eac32SMika Westerberg const struct intel_community *community; 114204035f7fSAndy Shevchenko unsigned int ngpio = 0; 1143a60eac32SMika Westerberg int i, j; 1144a60eac32SMika Westerberg 1145a60eac32SMika Westerberg for (i = 0; i < pctrl->ncommunities; i++) { 1146a60eac32SMika Westerberg community = &pctrl->communities[i]; 1147a60eac32SMika Westerberg for (j = 0; j < community->ngpps; j++) { 1148a60eac32SMika Westerberg const struct intel_padgroup *gpp = &community->gpps[j]; 1149a60eac32SMika Westerberg 1150a60eac32SMika Westerberg if (gpp->gpio_base < 0) 1151a60eac32SMika Westerberg continue; 1152a60eac32SMika Westerberg 1153a60eac32SMika Westerberg if (gpp->gpio_base + gpp->size > ngpio) 1154a60eac32SMika Westerberg ngpio = gpp->gpio_base + gpp->size; 1155a60eac32SMika Westerberg } 1156a60eac32SMika Westerberg } 1157a60eac32SMika Westerberg 1158a60eac32SMika Westerberg return ngpio; 1159a60eac32SMika Westerberg } 1160a60eac32SMika Westerberg 11617981c001SMika Westerberg static int intel_gpio_probe(struct intel_pinctrl *pctrl, int irq) 11627981c001SMika Westerberg { 1163a60eac32SMika Westerberg int ret, i; 11647981c001SMika Westerberg 11657981c001SMika Westerberg pctrl->chip = intel_gpio_chip; 11667981c001SMika Westerberg 1167a60eac32SMika Westerberg pctrl->chip.ngpio = intel_gpio_ngpio(pctrl); 11687981c001SMika Westerberg pctrl->chip.label = dev_name(pctrl->dev); 116958383c78SLinus Walleij pctrl->chip.parent = pctrl->dev; 11707981c001SMika Westerberg pctrl->chip.base = -1; 117101dabe91SNilesh Bacchewar pctrl->irq = irq; 11727981c001SMika Westerberg 1173f25c3aa9SMika Westerberg ret = devm_gpiochip_add_data(pctrl->dev, &pctrl->chip, pctrl); 11747981c001SMika Westerberg if (ret) { 11757981c001SMika Westerberg dev_err(pctrl->dev, "failed to register gpiochip\n"); 11767981c001SMika Westerberg return ret; 11777981c001SMika Westerberg } 11787981c001SMika Westerberg 1179a60eac32SMika Westerberg for (i = 0; i < pctrl->ncommunities; i++) { 1180a60eac32SMika Westerberg struct intel_community *community = &pctrl->communities[i]; 1181a60eac32SMika Westerberg 1182a60eac32SMika Westerberg ret = intel_gpio_add_pin_ranges(pctrl, community); 11837981c001SMika Westerberg if (ret) { 11847981c001SMika Westerberg dev_err(pctrl->dev, "failed to add GPIO pin range\n"); 1185f25c3aa9SMika Westerberg return ret; 1186193b40c8SMika Westerberg } 1187a60eac32SMika Westerberg } 1188193b40c8SMika Westerberg 1189193b40c8SMika Westerberg /* 1190193b40c8SMika Westerberg * We need to request the interrupt here (instead of providing chip 1191193b40c8SMika Westerberg * to the irq directly) because on some platforms several GPIO 1192193b40c8SMika Westerberg * controllers share the same interrupt line. 1193193b40c8SMika Westerberg */ 11941a7d1cb8SMika Westerberg ret = devm_request_irq(pctrl->dev, irq, intel_gpio_irq, 11951a7d1cb8SMika Westerberg IRQF_SHARED | IRQF_NO_THREAD, 1196193b40c8SMika Westerberg dev_name(pctrl->dev), pctrl); 1197193b40c8SMika Westerberg if (ret) { 1198193b40c8SMika Westerberg dev_err(pctrl->dev, "failed to request interrupt\n"); 1199f25c3aa9SMika Westerberg return ret; 12007981c001SMika Westerberg } 12017981c001SMika Westerberg 12027981c001SMika Westerberg ret = gpiochip_irqchip_add(&pctrl->chip, &intel_gpio_irqchip, 0, 12033ae02c14SAndy Shevchenko handle_bad_irq, IRQ_TYPE_NONE); 12047981c001SMika Westerberg if (ret) { 12057981c001SMika Westerberg dev_err(pctrl->dev, "failed to add irqchip\n"); 1206f25c3aa9SMika Westerberg return ret; 12077981c001SMika Westerberg } 12087981c001SMika Westerberg 12097981c001SMika Westerberg gpiochip_set_chained_irqchip(&pctrl->chip, &intel_gpio_irqchip, irq, 1210193b40c8SMika Westerberg NULL); 12117981c001SMika Westerberg return 0; 12127981c001SMika Westerberg } 12137981c001SMika Westerberg 1214919eb475SMika Westerberg static int intel_pinctrl_add_padgroups(struct intel_pinctrl *pctrl, 1215919eb475SMika Westerberg struct intel_community *community) 1216919eb475SMika Westerberg { 1217919eb475SMika Westerberg struct intel_padgroup *gpps; 121804035f7fSAndy Shevchenko unsigned int npins = community->npins; 121904035f7fSAndy Shevchenko unsigned int padown_num = 0; 1220919eb475SMika Westerberg size_t ngpps, i; 1221919eb475SMika Westerberg 1222919eb475SMika Westerberg if (community->gpps) 1223919eb475SMika Westerberg ngpps = community->ngpps; 1224919eb475SMika Westerberg else 1225919eb475SMika Westerberg ngpps = DIV_ROUND_UP(community->npins, community->gpp_size); 1226919eb475SMika Westerberg 1227919eb475SMika Westerberg gpps = devm_kcalloc(pctrl->dev, ngpps, sizeof(*gpps), GFP_KERNEL); 1228919eb475SMika Westerberg if (!gpps) 1229919eb475SMika Westerberg return -ENOMEM; 1230919eb475SMika Westerberg 1231919eb475SMika Westerberg for (i = 0; i < ngpps; i++) { 1232919eb475SMika Westerberg if (community->gpps) { 1233919eb475SMika Westerberg gpps[i] = community->gpps[i]; 1234919eb475SMika Westerberg } else { 123504035f7fSAndy Shevchenko unsigned int gpp_size = community->gpp_size; 1236919eb475SMika Westerberg 1237919eb475SMika Westerberg gpps[i].reg_num = i; 1238919eb475SMika Westerberg gpps[i].base = community->pin_base + i * gpp_size; 1239919eb475SMika Westerberg gpps[i].size = min(gpp_size, npins); 1240919eb475SMika Westerberg npins -= gpps[i].size; 1241919eb475SMika Westerberg } 1242919eb475SMika Westerberg 1243919eb475SMika Westerberg if (gpps[i].size > 32) 1244919eb475SMika Westerberg return -EINVAL; 1245919eb475SMika Westerberg 1246a60eac32SMika Westerberg if (!gpps[i].gpio_base) 1247a60eac32SMika Westerberg gpps[i].gpio_base = gpps[i].base; 1248a60eac32SMika Westerberg 1249919eb475SMika Westerberg gpps[i].padown_num = padown_num; 1250919eb475SMika Westerberg 1251919eb475SMika Westerberg /* 1252919eb475SMika Westerberg * In older hardware the number of padown registers per 1253919eb475SMika Westerberg * group is fixed regardless of the group size. 1254919eb475SMika Westerberg */ 1255919eb475SMika Westerberg if (community->gpp_num_padown_regs) 1256919eb475SMika Westerberg padown_num += community->gpp_num_padown_regs; 1257919eb475SMika Westerberg else 1258919eb475SMika Westerberg padown_num += DIV_ROUND_UP(gpps[i].size * 4, 32); 1259919eb475SMika Westerberg } 1260919eb475SMika Westerberg 1261919eb475SMika Westerberg community->ngpps = ngpps; 1262919eb475SMika Westerberg community->gpps = gpps; 1263919eb475SMika Westerberg 1264919eb475SMika Westerberg return 0; 1265919eb475SMika Westerberg } 1266919eb475SMika Westerberg 12677981c001SMika Westerberg static int intel_pinctrl_pm_init(struct intel_pinctrl *pctrl) 12687981c001SMika Westerberg { 12697981c001SMika Westerberg #ifdef CONFIG_PM_SLEEP 12707981c001SMika Westerberg const struct intel_pinctrl_soc_data *soc = pctrl->soc; 12717981c001SMika Westerberg struct intel_community_context *communities; 12727981c001SMika Westerberg struct intel_pad_context *pads; 12737981c001SMika Westerberg int i; 12747981c001SMika Westerberg 12757981c001SMika Westerberg pads = devm_kcalloc(pctrl->dev, soc->npins, sizeof(*pads), GFP_KERNEL); 12767981c001SMika Westerberg if (!pads) 12777981c001SMika Westerberg return -ENOMEM; 12787981c001SMika Westerberg 12797981c001SMika Westerberg communities = devm_kcalloc(pctrl->dev, pctrl->ncommunities, 12807981c001SMika Westerberg sizeof(*communities), GFP_KERNEL); 12817981c001SMika Westerberg if (!communities) 12827981c001SMika Westerberg return -ENOMEM; 12837981c001SMika Westerberg 12847981c001SMika Westerberg 12857981c001SMika Westerberg for (i = 0; i < pctrl->ncommunities; i++) { 12867981c001SMika Westerberg struct intel_community *community = &pctrl->communities[i]; 12877981c001SMika Westerberg u32 *intmask; 12887981c001SMika Westerberg 12897981c001SMika Westerberg intmask = devm_kcalloc(pctrl->dev, community->ngpps, 12907981c001SMika Westerberg sizeof(*intmask), GFP_KERNEL); 12917981c001SMika Westerberg if (!intmask) 12927981c001SMika Westerberg return -ENOMEM; 12937981c001SMika Westerberg 12947981c001SMika Westerberg communities[i].intmask = intmask; 12957981c001SMika Westerberg } 12967981c001SMika Westerberg 12977981c001SMika Westerberg pctrl->context.pads = pads; 12987981c001SMika Westerberg pctrl->context.communities = communities; 12997981c001SMika Westerberg #endif 13007981c001SMika Westerberg 13017981c001SMika Westerberg return 0; 13027981c001SMika Westerberg } 13037981c001SMika Westerberg 13047981c001SMika Westerberg int intel_pinctrl_probe(struct platform_device *pdev, 13057981c001SMika Westerberg const struct intel_pinctrl_soc_data *soc_data) 13067981c001SMika Westerberg { 13077981c001SMika Westerberg struct intel_pinctrl *pctrl; 13087981c001SMika Westerberg int i, ret, irq; 13097981c001SMika Westerberg 13107981c001SMika Westerberg if (!soc_data) 13117981c001SMika Westerberg return -EINVAL; 13127981c001SMika Westerberg 13137981c001SMika Westerberg pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL); 13147981c001SMika Westerberg if (!pctrl) 13157981c001SMika Westerberg return -ENOMEM; 13167981c001SMika Westerberg 13177981c001SMika Westerberg pctrl->dev = &pdev->dev; 13187981c001SMika Westerberg pctrl->soc = soc_data; 131927d9098cSMika Westerberg raw_spin_lock_init(&pctrl->lock); 13207981c001SMika Westerberg 13217981c001SMika Westerberg /* 13227981c001SMika Westerberg * Make a copy of the communities which we can use to hold pointers 13237981c001SMika Westerberg * to the registers. 13247981c001SMika Westerberg */ 13257981c001SMika Westerberg pctrl->ncommunities = pctrl->soc->ncommunities; 13267981c001SMika Westerberg pctrl->communities = devm_kcalloc(&pdev->dev, pctrl->ncommunities, 13277981c001SMika Westerberg sizeof(*pctrl->communities), GFP_KERNEL); 13287981c001SMika Westerberg if (!pctrl->communities) 13297981c001SMika Westerberg return -ENOMEM; 13307981c001SMika Westerberg 13317981c001SMika Westerberg for (i = 0; i < pctrl->ncommunities; i++) { 13327981c001SMika Westerberg struct intel_community *community = &pctrl->communities[i]; 13337981c001SMika Westerberg struct resource *res; 13347981c001SMika Westerberg void __iomem *regs; 13357981c001SMika Westerberg u32 padbar; 13367981c001SMika Westerberg 13377981c001SMika Westerberg *community = pctrl->soc->communities[i]; 13387981c001SMika Westerberg 13397981c001SMika Westerberg res = platform_get_resource(pdev, IORESOURCE_MEM, 13407981c001SMika Westerberg community->barno); 13417981c001SMika Westerberg regs = devm_ioremap_resource(&pdev->dev, res); 13427981c001SMika Westerberg if (IS_ERR(regs)) 13437981c001SMika Westerberg return PTR_ERR(regs); 13447981c001SMika Westerberg 1345e57725eaSMika Westerberg /* 1346e57725eaSMika Westerberg * Determine community features based on the revision if 1347e57725eaSMika Westerberg * not specified already. 1348e57725eaSMika Westerberg */ 1349e57725eaSMika Westerberg if (!community->features) { 1350e57725eaSMika Westerberg u32 rev; 1351e57725eaSMika Westerberg 1352e57725eaSMika Westerberg rev = (readl(regs + REVID) & REVID_MASK) >> REVID_SHIFT; 135304cc058fSMika Westerberg if (rev >= 0x94) { 1354e57725eaSMika Westerberg community->features |= PINCTRL_FEATURE_DEBOUNCE; 135504cc058fSMika Westerberg community->features |= PINCTRL_FEATURE_1K_PD; 135604cc058fSMika Westerberg } 1357e57725eaSMika Westerberg } 1358e57725eaSMika Westerberg 13597981c001SMika Westerberg /* Read offset of the pad configuration registers */ 13607981c001SMika Westerberg padbar = readl(regs + PADBAR); 13617981c001SMika Westerberg 13627981c001SMika Westerberg community->regs = regs; 13637981c001SMika Westerberg community->pad_regs = regs + padbar; 1364919eb475SMika Westerberg 1365cf769bd8SMika Westerberg if (!community->is_offset) 1366cf769bd8SMika Westerberg community->is_offset = GPI_IS; 1367cf769bd8SMika Westerberg 1368919eb475SMika Westerberg ret = intel_pinctrl_add_padgroups(pctrl, community); 1369919eb475SMika Westerberg if (ret) 1370919eb475SMika Westerberg return ret; 13717981c001SMika Westerberg } 13727981c001SMika Westerberg 13737981c001SMika Westerberg irq = platform_get_irq(pdev, 0); 13747981c001SMika Westerberg if (irq < 0) { 13757981c001SMika Westerberg dev_err(&pdev->dev, "failed to get interrupt number\n"); 13767981c001SMika Westerberg return irq; 13777981c001SMika Westerberg } 13787981c001SMika Westerberg 13797981c001SMika Westerberg ret = intel_pinctrl_pm_init(pctrl); 13807981c001SMika Westerberg if (ret) 13817981c001SMika Westerberg return ret; 13827981c001SMika Westerberg 13837981c001SMika Westerberg pctrl->pctldesc = intel_pinctrl_desc; 13847981c001SMika Westerberg pctrl->pctldesc.name = dev_name(&pdev->dev); 13857981c001SMika Westerberg pctrl->pctldesc.pins = pctrl->soc->pins; 13867981c001SMika Westerberg pctrl->pctldesc.npins = pctrl->soc->npins; 13877981c001SMika Westerberg 138854d46cd7SLaxman Dewangan pctrl->pctldev = devm_pinctrl_register(&pdev->dev, &pctrl->pctldesc, 138954d46cd7SLaxman Dewangan pctrl); 1390323de9efSMasahiro Yamada if (IS_ERR(pctrl->pctldev)) { 13917981c001SMika Westerberg dev_err(&pdev->dev, "failed to register pinctrl driver\n"); 1392323de9efSMasahiro Yamada return PTR_ERR(pctrl->pctldev); 13937981c001SMika Westerberg } 13947981c001SMika Westerberg 13957981c001SMika Westerberg ret = intel_gpio_probe(pctrl, irq); 139654d46cd7SLaxman Dewangan if (ret) 13977981c001SMika Westerberg return ret; 13987981c001SMika Westerberg 13997981c001SMika Westerberg platform_set_drvdata(pdev, pctrl); 14007981c001SMika Westerberg 14017981c001SMika Westerberg return 0; 14027981c001SMika Westerberg } 14037981c001SMika Westerberg EXPORT_SYMBOL_GPL(intel_pinctrl_probe); 14047981c001SMika Westerberg 140570c263c4SAndy Shevchenko int intel_pinctrl_probe_by_hid(struct platform_device *pdev) 140670c263c4SAndy Shevchenko { 140770c263c4SAndy Shevchenko const struct intel_pinctrl_soc_data *data; 140870c263c4SAndy Shevchenko 140970c263c4SAndy Shevchenko data = device_get_match_data(&pdev->dev); 141070c263c4SAndy Shevchenko return intel_pinctrl_probe(pdev, data); 141170c263c4SAndy Shevchenko } 141270c263c4SAndy Shevchenko EXPORT_SYMBOL_GPL(intel_pinctrl_probe_by_hid); 141370c263c4SAndy Shevchenko 1414924cf800SAndy Shevchenko int intel_pinctrl_probe_by_uid(struct platform_device *pdev) 1415924cf800SAndy Shevchenko { 1416924cf800SAndy Shevchenko const struct intel_pinctrl_soc_data *data = NULL; 1417924cf800SAndy Shevchenko const struct intel_pinctrl_soc_data **table; 1418924cf800SAndy Shevchenko struct acpi_device *adev; 1419924cf800SAndy Shevchenko unsigned int i; 1420924cf800SAndy Shevchenko 1421924cf800SAndy Shevchenko adev = ACPI_COMPANION(&pdev->dev); 1422924cf800SAndy Shevchenko if (adev) { 1423924cf800SAndy Shevchenko const void *match = device_get_match_data(&pdev->dev); 1424924cf800SAndy Shevchenko 1425924cf800SAndy Shevchenko table = (const struct intel_pinctrl_soc_data **)match; 1426924cf800SAndy Shevchenko for (i = 0; table[i]; i++) { 1427924cf800SAndy Shevchenko if (!strcmp(adev->pnp.unique_id, table[i]->uid)) { 1428924cf800SAndy Shevchenko data = table[i]; 1429924cf800SAndy Shevchenko break; 1430924cf800SAndy Shevchenko } 1431924cf800SAndy Shevchenko } 1432924cf800SAndy Shevchenko } else { 1433924cf800SAndy Shevchenko const struct platform_device_id *id; 1434924cf800SAndy Shevchenko 1435924cf800SAndy Shevchenko id = platform_get_device_id(pdev); 1436924cf800SAndy Shevchenko if (!id) 1437924cf800SAndy Shevchenko return -ENODEV; 1438924cf800SAndy Shevchenko 1439924cf800SAndy Shevchenko table = (const struct intel_pinctrl_soc_data **)id->driver_data; 1440924cf800SAndy Shevchenko data = table[pdev->id]; 1441924cf800SAndy Shevchenko } 1442924cf800SAndy Shevchenko if (!data) 1443924cf800SAndy Shevchenko return -ENODEV; 1444924cf800SAndy Shevchenko 1445924cf800SAndy Shevchenko return intel_pinctrl_probe(pdev, data); 1446924cf800SAndy Shevchenko } 1447924cf800SAndy Shevchenko EXPORT_SYMBOL_GPL(intel_pinctrl_probe_by_uid); 1448924cf800SAndy Shevchenko 14497981c001SMika Westerberg #ifdef CONFIG_PM_SLEEP 145004035f7fSAndy Shevchenko static bool intel_pinctrl_should_save(struct intel_pinctrl *pctrl, unsigned int pin) 1451c538b943SMika Westerberg { 1452c538b943SMika Westerberg const struct pin_desc *pd = pin_desc_get(pctrl->pctldev, pin); 1453c538b943SMika Westerberg 1454c538b943SMika Westerberg if (!pd || !intel_pad_usable(pctrl, pin)) 1455c538b943SMika Westerberg return false; 1456c538b943SMika Westerberg 1457c538b943SMika Westerberg /* 1458c538b943SMika Westerberg * Only restore the pin if it is actually in use by the kernel (or 1459c538b943SMika Westerberg * by userspace). It is possible that some pins are used by the 1460c538b943SMika Westerberg * BIOS during resume and those are not always locked down so leave 1461c538b943SMika Westerberg * them alone. 1462c538b943SMika Westerberg */ 1463c538b943SMika Westerberg if (pd->mux_owner || pd->gpio_owner || 1464c538b943SMika Westerberg gpiochip_line_is_irq(&pctrl->chip, pin)) 1465c538b943SMika Westerberg return true; 1466c538b943SMika Westerberg 1467c538b943SMika Westerberg return false; 1468c538b943SMika Westerberg } 1469c538b943SMika Westerberg 14707981c001SMika Westerberg int intel_pinctrl_suspend(struct device *dev) 14717981c001SMika Westerberg { 1472*cb035d74SWolfram Sang struct intel_pinctrl *pctrl = dev_get_drvdata(dev); 14737981c001SMika Westerberg struct intel_community_context *communities; 14747981c001SMika Westerberg struct intel_pad_context *pads; 14757981c001SMika Westerberg int i; 14767981c001SMika Westerberg 14777981c001SMika Westerberg pads = pctrl->context.pads; 14787981c001SMika Westerberg for (i = 0; i < pctrl->soc->npins; i++) { 14797981c001SMika Westerberg const struct pinctrl_pin_desc *desc = &pctrl->soc->pins[i]; 1480e57725eaSMika Westerberg void __iomem *padcfg; 14817981c001SMika Westerberg u32 val; 14827981c001SMika Westerberg 1483c538b943SMika Westerberg if (!intel_pinctrl_should_save(pctrl, desc->number)) 14847981c001SMika Westerberg continue; 14857981c001SMika Westerberg 14867981c001SMika Westerberg val = readl(intel_get_padcfg(pctrl, desc->number, PADCFG0)); 14877981c001SMika Westerberg pads[i].padcfg0 = val & ~PADCFG0_GPIORXSTATE; 14887981c001SMika Westerberg val = readl(intel_get_padcfg(pctrl, desc->number, PADCFG1)); 14897981c001SMika Westerberg pads[i].padcfg1 = val; 1490e57725eaSMika Westerberg 1491e57725eaSMika Westerberg padcfg = intel_get_padcfg(pctrl, desc->number, PADCFG2); 1492e57725eaSMika Westerberg if (padcfg) 1493e57725eaSMika Westerberg pads[i].padcfg2 = readl(padcfg); 14947981c001SMika Westerberg } 14957981c001SMika Westerberg 14967981c001SMika Westerberg communities = pctrl->context.communities; 14977981c001SMika Westerberg for (i = 0; i < pctrl->ncommunities; i++) { 14987981c001SMika Westerberg struct intel_community *community = &pctrl->communities[i]; 14997981c001SMika Westerberg void __iomem *base; 150004035f7fSAndy Shevchenko unsigned int gpp; 15017981c001SMika Westerberg 15027981c001SMika Westerberg base = community->regs + community->ie_offset; 15037981c001SMika Westerberg for (gpp = 0; gpp < community->ngpps; gpp++) 15047981c001SMika Westerberg communities[i].intmask[gpp] = readl(base + gpp * 4); 15057981c001SMika Westerberg } 15067981c001SMika Westerberg 15077981c001SMika Westerberg return 0; 15087981c001SMika Westerberg } 15097981c001SMika Westerberg EXPORT_SYMBOL_GPL(intel_pinctrl_suspend); 15107981c001SMika Westerberg 1511f487bbf3SMika Westerberg static void intel_gpio_irq_init(struct intel_pinctrl *pctrl) 1512f487bbf3SMika Westerberg { 1513f487bbf3SMika Westerberg size_t i; 1514f487bbf3SMika Westerberg 1515f487bbf3SMika Westerberg for (i = 0; i < pctrl->ncommunities; i++) { 1516f487bbf3SMika Westerberg const struct intel_community *community; 1517f487bbf3SMika Westerberg void __iomem *base; 151804035f7fSAndy Shevchenko unsigned int gpp; 1519f487bbf3SMika Westerberg 1520f487bbf3SMika Westerberg community = &pctrl->communities[i]; 1521f487bbf3SMika Westerberg base = community->regs; 1522f487bbf3SMika Westerberg 1523f487bbf3SMika Westerberg for (gpp = 0; gpp < community->ngpps; gpp++) { 1524f487bbf3SMika Westerberg /* Mask and clear all interrupts */ 1525f487bbf3SMika Westerberg writel(0, base + community->ie_offset + gpp * 4); 1526cf769bd8SMika Westerberg writel(0xffff, base + community->is_offset + gpp * 4); 1527f487bbf3SMika Westerberg } 1528f487bbf3SMika Westerberg } 1529f487bbf3SMika Westerberg } 1530f487bbf3SMika Westerberg 15317981c001SMika Westerberg int intel_pinctrl_resume(struct device *dev) 15327981c001SMika Westerberg { 1533*cb035d74SWolfram Sang struct intel_pinctrl *pctrl = dev_get_drvdata(dev); 15347981c001SMika Westerberg const struct intel_community_context *communities; 15357981c001SMika Westerberg const struct intel_pad_context *pads; 15367981c001SMika Westerberg int i; 15377981c001SMika Westerberg 15387981c001SMika Westerberg /* Mask all interrupts */ 15397981c001SMika Westerberg intel_gpio_irq_init(pctrl); 15407981c001SMika Westerberg 15417981c001SMika Westerberg pads = pctrl->context.pads; 15427981c001SMika Westerberg for (i = 0; i < pctrl->soc->npins; i++) { 15437981c001SMika Westerberg const struct pinctrl_pin_desc *desc = &pctrl->soc->pins[i]; 15447981c001SMika Westerberg void __iomem *padcfg; 15457981c001SMika Westerberg u32 val; 15467981c001SMika Westerberg 1547c538b943SMika Westerberg if (!intel_pinctrl_should_save(pctrl, desc->number)) 15487981c001SMika Westerberg continue; 15497981c001SMika Westerberg 15507981c001SMika Westerberg padcfg = intel_get_padcfg(pctrl, desc->number, PADCFG0); 15517981c001SMika Westerberg val = readl(padcfg) & ~PADCFG0_GPIORXSTATE; 15527981c001SMika Westerberg if (val != pads[i].padcfg0) { 15537981c001SMika Westerberg writel(pads[i].padcfg0, padcfg); 15547981c001SMika Westerberg dev_dbg(dev, "restored pin %u padcfg0 %#08x\n", 15557981c001SMika Westerberg desc->number, readl(padcfg)); 15567981c001SMika Westerberg } 15577981c001SMika Westerberg 15587981c001SMika Westerberg padcfg = intel_get_padcfg(pctrl, desc->number, PADCFG1); 15597981c001SMika Westerberg val = readl(padcfg); 15607981c001SMika Westerberg if (val != pads[i].padcfg1) { 15617981c001SMika Westerberg writel(pads[i].padcfg1, padcfg); 15627981c001SMika Westerberg dev_dbg(dev, "restored pin %u padcfg1 %#08x\n", 15637981c001SMika Westerberg desc->number, readl(padcfg)); 15647981c001SMika Westerberg } 1565e57725eaSMika Westerberg 1566e57725eaSMika Westerberg padcfg = intel_get_padcfg(pctrl, desc->number, PADCFG2); 1567e57725eaSMika Westerberg if (padcfg) { 1568e57725eaSMika Westerberg val = readl(padcfg); 1569e57725eaSMika Westerberg if (val != pads[i].padcfg2) { 1570e57725eaSMika Westerberg writel(pads[i].padcfg2, padcfg); 1571e57725eaSMika Westerberg dev_dbg(dev, "restored pin %u padcfg2 %#08x\n", 1572e57725eaSMika Westerberg desc->number, readl(padcfg)); 1573e57725eaSMika Westerberg } 1574e57725eaSMika Westerberg } 15757981c001SMika Westerberg } 15767981c001SMika Westerberg 15777981c001SMika Westerberg communities = pctrl->context.communities; 15787981c001SMika Westerberg for (i = 0; i < pctrl->ncommunities; i++) { 15797981c001SMika Westerberg struct intel_community *community = &pctrl->communities[i]; 15807981c001SMika Westerberg void __iomem *base; 158104035f7fSAndy Shevchenko unsigned int gpp; 15827981c001SMika Westerberg 15837981c001SMika Westerberg base = community->regs + community->ie_offset; 15847981c001SMika Westerberg for (gpp = 0; gpp < community->ngpps; gpp++) { 15857981c001SMika Westerberg writel(communities[i].intmask[gpp], base + gpp * 4); 15867981c001SMika Westerberg dev_dbg(dev, "restored mask %d/%u %#08x\n", i, gpp, 15877981c001SMika Westerberg readl(base + gpp * 4)); 15887981c001SMika Westerberg } 15897981c001SMika Westerberg } 15907981c001SMika Westerberg 15917981c001SMika Westerberg return 0; 15927981c001SMika Westerberg } 15937981c001SMika Westerberg EXPORT_SYMBOL_GPL(intel_pinctrl_resume); 15947981c001SMika Westerberg #endif 15957981c001SMika Westerberg 15967981c001SMika Westerberg MODULE_AUTHOR("Mathias Nyman <mathias.nyman@linux.intel.com>"); 15977981c001SMika Westerberg MODULE_AUTHOR("Mika Westerberg <mika.westerberg@linux.intel.com>"); 15987981c001SMika Westerberg MODULE_DESCRIPTION("Intel pinctrl/GPIO core driver"); 15997981c001SMika Westerberg MODULE_LICENSE("GPL v2"); 1600