17981c001SMika Westerberg /* 27981c001SMika Westerberg * Intel pinctrl/GPIO core driver. 37981c001SMika Westerberg * 47981c001SMika Westerberg * Copyright (C) 2015, Intel Corporation 57981c001SMika Westerberg * Authors: Mathias Nyman <mathias.nyman@linux.intel.com> 67981c001SMika Westerberg * Mika Westerberg <mika.westerberg@linux.intel.com> 77981c001SMika Westerberg * 87981c001SMika Westerberg * This program is free software; you can redistribute it and/or modify 97981c001SMika Westerberg * it under the terms of the GNU General Public License version 2 as 107981c001SMika Westerberg * published by the Free Software Foundation. 117981c001SMika Westerberg */ 127981c001SMika Westerberg 137981c001SMika Westerberg #include <linux/module.h> 14193b40c8SMika Westerberg #include <linux/interrupt.h> 157981c001SMika Westerberg #include <linux/gpio/driver.h> 167981c001SMika Westerberg #include <linux/platform_device.h> 177981c001SMika Westerberg #include <linux/pinctrl/pinctrl.h> 187981c001SMika Westerberg #include <linux/pinctrl/pinmux.h> 197981c001SMika Westerberg #include <linux/pinctrl/pinconf.h> 207981c001SMika Westerberg #include <linux/pinctrl/pinconf-generic.h> 217981c001SMika Westerberg 227981c001SMika Westerberg #include "pinctrl-intel.h" 237981c001SMika Westerberg 247981c001SMika Westerberg /* Offset from regs */ 257981c001SMika Westerberg #define PADBAR 0x00c 267981c001SMika Westerberg #define GPI_IS 0x100 277981c001SMika Westerberg #define GPI_GPE_STS 0x140 287981c001SMika Westerberg #define GPI_GPE_EN 0x160 297981c001SMika Westerberg 307981c001SMika Westerberg #define PADOWN_BITS 4 317981c001SMika Westerberg #define PADOWN_SHIFT(p) ((p) % 8 * PADOWN_BITS) 327981c001SMika Westerberg #define PADOWN_MASK(p) (0xf << PADOWN_SHIFT(p)) 3399a735b3SQipeng Zha #define PADOWN_GPP(p) ((p) / 8) 347981c001SMika Westerberg 357981c001SMika Westerberg /* Offset from pad_regs */ 367981c001SMika Westerberg #define PADCFG0 0x000 377981c001SMika Westerberg #define PADCFG0_RXEVCFG_SHIFT 25 387981c001SMika Westerberg #define PADCFG0_RXEVCFG_MASK (3 << PADCFG0_RXEVCFG_SHIFT) 397981c001SMika Westerberg #define PADCFG0_RXEVCFG_LEVEL 0 407981c001SMika Westerberg #define PADCFG0_RXEVCFG_EDGE 1 417981c001SMika Westerberg #define PADCFG0_RXEVCFG_DISABLED 2 427981c001SMika Westerberg #define PADCFG0_RXEVCFG_EDGE_BOTH 3 437981c001SMika Westerberg #define PADCFG0_RXINV BIT(23) 447981c001SMika Westerberg #define PADCFG0_GPIROUTIOXAPIC BIT(20) 457981c001SMika Westerberg #define PADCFG0_GPIROUTSCI BIT(19) 467981c001SMika Westerberg #define PADCFG0_GPIROUTSMI BIT(18) 477981c001SMika Westerberg #define PADCFG0_GPIROUTNMI BIT(17) 487981c001SMika Westerberg #define PADCFG0_PMODE_SHIFT 10 497981c001SMika Westerberg #define PADCFG0_PMODE_MASK (0xf << PADCFG0_PMODE_SHIFT) 507981c001SMika Westerberg #define PADCFG0_GPIORXDIS BIT(9) 517981c001SMika Westerberg #define PADCFG0_GPIOTXDIS BIT(8) 527981c001SMika Westerberg #define PADCFG0_GPIORXSTATE BIT(1) 537981c001SMika Westerberg #define PADCFG0_GPIOTXSTATE BIT(0) 547981c001SMika Westerberg 557981c001SMika Westerberg #define PADCFG1 0x004 567981c001SMika Westerberg #define PADCFG1_TERM_UP BIT(13) 577981c001SMika Westerberg #define PADCFG1_TERM_SHIFT 10 587981c001SMika Westerberg #define PADCFG1_TERM_MASK (7 << PADCFG1_TERM_SHIFT) 597981c001SMika Westerberg #define PADCFG1_TERM_20K 4 607981c001SMika Westerberg #define PADCFG1_TERM_2K 3 617981c001SMika Westerberg #define PADCFG1_TERM_5K 2 627981c001SMika Westerberg #define PADCFG1_TERM_1K 1 637981c001SMika Westerberg 647981c001SMika Westerberg struct intel_pad_context { 657981c001SMika Westerberg u32 padcfg0; 667981c001SMika Westerberg u32 padcfg1; 677981c001SMika Westerberg }; 687981c001SMika Westerberg 697981c001SMika Westerberg struct intel_community_context { 707981c001SMika Westerberg u32 *intmask; 717981c001SMika Westerberg }; 727981c001SMika Westerberg 737981c001SMika Westerberg struct intel_pinctrl_context { 747981c001SMika Westerberg struct intel_pad_context *pads; 757981c001SMika Westerberg struct intel_community_context *communities; 767981c001SMika Westerberg }; 777981c001SMika Westerberg 787981c001SMika Westerberg /** 797981c001SMika Westerberg * struct intel_pinctrl - Intel pinctrl private structure 807981c001SMika Westerberg * @dev: Pointer to the device structure 817981c001SMika Westerberg * @lock: Lock to serialize register access 827981c001SMika Westerberg * @pctldesc: Pin controller description 837981c001SMika Westerberg * @pctldev: Pointer to the pin controller device 847981c001SMika Westerberg * @chip: GPIO chip in this pin controller 857981c001SMika Westerberg * @soc: SoC/PCH specific pin configuration data 867981c001SMika Westerberg * @communities: All communities in this pin controller 877981c001SMika Westerberg * @ncommunities: Number of communities in this pin controller 887981c001SMika Westerberg * @context: Configuration saved over system sleep 897981c001SMika Westerberg */ 907981c001SMika Westerberg struct intel_pinctrl { 917981c001SMika Westerberg struct device *dev; 927981c001SMika Westerberg spinlock_t lock; 937981c001SMika Westerberg struct pinctrl_desc pctldesc; 947981c001SMika Westerberg struct pinctrl_dev *pctldev; 957981c001SMika Westerberg struct gpio_chip chip; 967981c001SMika Westerberg const struct intel_pinctrl_soc_data *soc; 977981c001SMika Westerberg struct intel_community *communities; 987981c001SMika Westerberg size_t ncommunities; 997981c001SMika Westerberg struct intel_pinctrl_context context; 1007981c001SMika Westerberg }; 1017981c001SMika Westerberg 1027981c001SMika Westerberg #define pin_to_padno(c, p) ((p) - (c)->pin_base) 1037981c001SMika Westerberg 1047981c001SMika Westerberg static struct intel_community *intel_get_community(struct intel_pinctrl *pctrl, 1057981c001SMika Westerberg unsigned pin) 1067981c001SMika Westerberg { 1077981c001SMika Westerberg struct intel_community *community; 1087981c001SMika Westerberg int i; 1097981c001SMika Westerberg 1107981c001SMika Westerberg for (i = 0; i < pctrl->ncommunities; i++) { 1117981c001SMika Westerberg community = &pctrl->communities[i]; 1127981c001SMika Westerberg if (pin >= community->pin_base && 1137981c001SMika Westerberg pin < community->pin_base + community->npins) 1147981c001SMika Westerberg return community; 1157981c001SMika Westerberg } 1167981c001SMika Westerberg 1177981c001SMika Westerberg dev_warn(pctrl->dev, "failed to find community for pin %u\n", pin); 1187981c001SMika Westerberg return NULL; 1197981c001SMika Westerberg } 1207981c001SMika Westerberg 1217981c001SMika Westerberg static void __iomem *intel_get_padcfg(struct intel_pinctrl *pctrl, unsigned pin, 1227981c001SMika Westerberg unsigned reg) 1237981c001SMika Westerberg { 1247981c001SMika Westerberg const struct intel_community *community; 1257981c001SMika Westerberg unsigned padno; 1267981c001SMika Westerberg 1277981c001SMika Westerberg community = intel_get_community(pctrl, pin); 1287981c001SMika Westerberg if (!community) 1297981c001SMika Westerberg return NULL; 1307981c001SMika Westerberg 1317981c001SMika Westerberg padno = pin_to_padno(community, pin); 1327981c001SMika Westerberg return community->pad_regs + reg + padno * 8; 1337981c001SMika Westerberg } 1347981c001SMika Westerberg 1357981c001SMika Westerberg static bool intel_pad_owned_by_host(struct intel_pinctrl *pctrl, unsigned pin) 1367981c001SMika Westerberg { 1377981c001SMika Westerberg const struct intel_community *community; 13899a735b3SQipeng Zha unsigned padno, gpp, offset, group; 1397981c001SMika Westerberg void __iomem *padown; 1407981c001SMika Westerberg 1417981c001SMika Westerberg community = intel_get_community(pctrl, pin); 1427981c001SMika Westerberg if (!community) 1437981c001SMika Westerberg return false; 1447981c001SMika Westerberg if (!community->padown_offset) 1457981c001SMika Westerberg return true; 1467981c001SMika Westerberg 1477981c001SMika Westerberg padno = pin_to_padno(community, pin); 14899a735b3SQipeng Zha group = padno / community->gpp_size; 14999a735b3SQipeng Zha gpp = PADOWN_GPP(padno % community->gpp_size); 15099a735b3SQipeng Zha offset = community->padown_offset + 0x10 * group + gpp * 4; 1517981c001SMika Westerberg padown = community->regs + offset; 1527981c001SMika Westerberg 1537981c001SMika Westerberg return !(readl(padown) & PADOWN_MASK(padno)); 1547981c001SMika Westerberg } 1557981c001SMika Westerberg 1564341e8a5SMika Westerberg static bool intel_pad_acpi_mode(struct intel_pinctrl *pctrl, unsigned pin) 1577981c001SMika Westerberg { 1587981c001SMika Westerberg const struct intel_community *community; 1597981c001SMika Westerberg unsigned padno, gpp, offset; 1607981c001SMika Westerberg void __iomem *hostown; 1617981c001SMika Westerberg 1627981c001SMika Westerberg community = intel_get_community(pctrl, pin); 1637981c001SMika Westerberg if (!community) 1647981c001SMika Westerberg return true; 1657981c001SMika Westerberg if (!community->hostown_offset) 1667981c001SMika Westerberg return false; 1677981c001SMika Westerberg 1687981c001SMika Westerberg padno = pin_to_padno(community, pin); 169618a919bSQipeng Zha gpp = padno / community->gpp_size; 1707981c001SMika Westerberg offset = community->hostown_offset + gpp * 4; 1717981c001SMika Westerberg hostown = community->regs + offset; 1727981c001SMika Westerberg 173618a919bSQipeng Zha return !(readl(hostown) & BIT(padno % community->gpp_size)); 1747981c001SMika Westerberg } 1757981c001SMika Westerberg 1767981c001SMika Westerberg static bool intel_pad_locked(struct intel_pinctrl *pctrl, unsigned pin) 1777981c001SMika Westerberg { 1787981c001SMika Westerberg struct intel_community *community; 1797981c001SMika Westerberg unsigned padno, gpp, offset; 1807981c001SMika Westerberg u32 value; 1817981c001SMika Westerberg 1827981c001SMika Westerberg community = intel_get_community(pctrl, pin); 1837981c001SMika Westerberg if (!community) 1847981c001SMika Westerberg return true; 1857981c001SMika Westerberg if (!community->padcfglock_offset) 1867981c001SMika Westerberg return false; 1877981c001SMika Westerberg 1887981c001SMika Westerberg padno = pin_to_padno(community, pin); 189618a919bSQipeng Zha gpp = padno / community->gpp_size; 1907981c001SMika Westerberg 1917981c001SMika Westerberg /* 1927981c001SMika Westerberg * If PADCFGLOCK and PADCFGLOCKTX bits are both clear for this pad, 1937981c001SMika Westerberg * the pad is considered unlocked. Any other case means that it is 1947981c001SMika Westerberg * either fully or partially locked and we don't touch it. 1957981c001SMika Westerberg */ 1967981c001SMika Westerberg offset = community->padcfglock_offset + gpp * 8; 1977981c001SMika Westerberg value = readl(community->regs + offset); 198618a919bSQipeng Zha if (value & BIT(pin % community->gpp_size)) 1997981c001SMika Westerberg return true; 2007981c001SMika Westerberg 2017981c001SMika Westerberg offset = community->padcfglock_offset + 4 + gpp * 8; 2027981c001SMika Westerberg value = readl(community->regs + offset); 203618a919bSQipeng Zha if (value & BIT(pin % community->gpp_size)) 2047981c001SMika Westerberg return true; 2057981c001SMika Westerberg 2067981c001SMika Westerberg return false; 2077981c001SMika Westerberg } 2087981c001SMika Westerberg 2097981c001SMika Westerberg static bool intel_pad_usable(struct intel_pinctrl *pctrl, unsigned pin) 2107981c001SMika Westerberg { 2117981c001SMika Westerberg return intel_pad_owned_by_host(pctrl, pin) && 2127981c001SMika Westerberg !intel_pad_locked(pctrl, pin); 2137981c001SMika Westerberg } 2147981c001SMika Westerberg 2157981c001SMika Westerberg static int intel_get_groups_count(struct pinctrl_dev *pctldev) 2167981c001SMika Westerberg { 2177981c001SMika Westerberg struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 2187981c001SMika Westerberg 2197981c001SMika Westerberg return pctrl->soc->ngroups; 2207981c001SMika Westerberg } 2217981c001SMika Westerberg 2227981c001SMika Westerberg static const char *intel_get_group_name(struct pinctrl_dev *pctldev, 2237981c001SMika Westerberg unsigned group) 2247981c001SMika Westerberg { 2257981c001SMika Westerberg struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 2267981c001SMika Westerberg 2277981c001SMika Westerberg return pctrl->soc->groups[group].name; 2287981c001SMika Westerberg } 2297981c001SMika Westerberg 2307981c001SMika Westerberg static int intel_get_group_pins(struct pinctrl_dev *pctldev, unsigned group, 2317981c001SMika Westerberg const unsigned **pins, unsigned *npins) 2327981c001SMika Westerberg { 2337981c001SMika Westerberg struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 2347981c001SMika Westerberg 2357981c001SMika Westerberg *pins = pctrl->soc->groups[group].pins; 2367981c001SMika Westerberg *npins = pctrl->soc->groups[group].npins; 2377981c001SMika Westerberg return 0; 2387981c001SMika Westerberg } 2397981c001SMika Westerberg 2407981c001SMika Westerberg static void intel_pin_dbg_show(struct pinctrl_dev *pctldev, struct seq_file *s, 2417981c001SMika Westerberg unsigned pin) 2427981c001SMika Westerberg { 2437981c001SMika Westerberg struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 2447981c001SMika Westerberg u32 cfg0, cfg1, mode; 2457981c001SMika Westerberg bool locked, acpi; 2467981c001SMika Westerberg 2477981c001SMika Westerberg if (!intel_pad_owned_by_host(pctrl, pin)) { 2487981c001SMika Westerberg seq_puts(s, "not available"); 2497981c001SMika Westerberg return; 2507981c001SMika Westerberg } 2517981c001SMika Westerberg 2527981c001SMika Westerberg cfg0 = readl(intel_get_padcfg(pctrl, pin, PADCFG0)); 2537981c001SMika Westerberg cfg1 = readl(intel_get_padcfg(pctrl, pin, PADCFG1)); 2547981c001SMika Westerberg 2557981c001SMika Westerberg mode = (cfg0 & PADCFG0_PMODE_MASK) >> PADCFG0_PMODE_SHIFT; 2567981c001SMika Westerberg if (!mode) 2577981c001SMika Westerberg seq_puts(s, "GPIO "); 2587981c001SMika Westerberg else 2597981c001SMika Westerberg seq_printf(s, "mode %d ", mode); 2607981c001SMika Westerberg 2617981c001SMika Westerberg seq_printf(s, "0x%08x 0x%08x", cfg0, cfg1); 2627981c001SMika Westerberg 2637981c001SMika Westerberg locked = intel_pad_locked(pctrl, pin); 2644341e8a5SMika Westerberg acpi = intel_pad_acpi_mode(pctrl, pin); 2657981c001SMika Westerberg 2667981c001SMika Westerberg if (locked || acpi) { 2677981c001SMika Westerberg seq_puts(s, " ["); 2687981c001SMika Westerberg if (locked) { 2697981c001SMika Westerberg seq_puts(s, "LOCKED"); 2707981c001SMika Westerberg if (acpi) 2717981c001SMika Westerberg seq_puts(s, ", "); 2727981c001SMika Westerberg } 2737981c001SMika Westerberg if (acpi) 2747981c001SMika Westerberg seq_puts(s, "ACPI"); 2757981c001SMika Westerberg seq_puts(s, "]"); 2767981c001SMika Westerberg } 2777981c001SMika Westerberg } 2787981c001SMika Westerberg 2797981c001SMika Westerberg static const struct pinctrl_ops intel_pinctrl_ops = { 2807981c001SMika Westerberg .get_groups_count = intel_get_groups_count, 2817981c001SMika Westerberg .get_group_name = intel_get_group_name, 2827981c001SMika Westerberg .get_group_pins = intel_get_group_pins, 2837981c001SMika Westerberg .pin_dbg_show = intel_pin_dbg_show, 2847981c001SMika Westerberg }; 2857981c001SMika Westerberg 2867981c001SMika Westerberg static int intel_get_functions_count(struct pinctrl_dev *pctldev) 2877981c001SMika Westerberg { 2887981c001SMika Westerberg struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 2897981c001SMika Westerberg 2907981c001SMika Westerberg return pctrl->soc->nfunctions; 2917981c001SMika Westerberg } 2927981c001SMika Westerberg 2937981c001SMika Westerberg static const char *intel_get_function_name(struct pinctrl_dev *pctldev, 2947981c001SMika Westerberg unsigned function) 2957981c001SMika Westerberg { 2967981c001SMika Westerberg struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 2977981c001SMika Westerberg 2987981c001SMika Westerberg return pctrl->soc->functions[function].name; 2997981c001SMika Westerberg } 3007981c001SMika Westerberg 3017981c001SMika Westerberg static int intel_get_function_groups(struct pinctrl_dev *pctldev, 3027981c001SMika Westerberg unsigned function, 3037981c001SMika Westerberg const char * const **groups, 3047981c001SMika Westerberg unsigned * const ngroups) 3057981c001SMika Westerberg { 3067981c001SMika Westerberg struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 3077981c001SMika Westerberg 3087981c001SMika Westerberg *groups = pctrl->soc->functions[function].groups; 3097981c001SMika Westerberg *ngroups = pctrl->soc->functions[function].ngroups; 3107981c001SMika Westerberg return 0; 3117981c001SMika Westerberg } 3127981c001SMika Westerberg 3137981c001SMika Westerberg static int intel_pinmux_set_mux(struct pinctrl_dev *pctldev, unsigned function, 3147981c001SMika Westerberg unsigned group) 3157981c001SMika Westerberg { 3167981c001SMika Westerberg struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 3177981c001SMika Westerberg const struct intel_pingroup *grp = &pctrl->soc->groups[group]; 3187981c001SMika Westerberg unsigned long flags; 3197981c001SMika Westerberg int i; 3207981c001SMika Westerberg 3217981c001SMika Westerberg spin_lock_irqsave(&pctrl->lock, flags); 3227981c001SMika Westerberg 3237981c001SMika Westerberg /* 3247981c001SMika Westerberg * All pins in the groups needs to be accessible and writable 3257981c001SMika Westerberg * before we can enable the mux for this group. 3267981c001SMika Westerberg */ 3277981c001SMika Westerberg for (i = 0; i < grp->npins; i++) { 3287981c001SMika Westerberg if (!intel_pad_usable(pctrl, grp->pins[i])) { 3297981c001SMika Westerberg spin_unlock_irqrestore(&pctrl->lock, flags); 3307981c001SMika Westerberg return -EBUSY; 3317981c001SMika Westerberg } 3327981c001SMika Westerberg } 3337981c001SMika Westerberg 3347981c001SMika Westerberg /* Now enable the mux setting for each pin in the group */ 3357981c001SMika Westerberg for (i = 0; i < grp->npins; i++) { 3367981c001SMika Westerberg void __iomem *padcfg0; 3377981c001SMika Westerberg u32 value; 3387981c001SMika Westerberg 3397981c001SMika Westerberg padcfg0 = intel_get_padcfg(pctrl, grp->pins[i], PADCFG0); 3407981c001SMika Westerberg value = readl(padcfg0); 3417981c001SMika Westerberg 3427981c001SMika Westerberg value &= ~PADCFG0_PMODE_MASK; 3437981c001SMika Westerberg value |= grp->mode << PADCFG0_PMODE_SHIFT; 3447981c001SMika Westerberg 3457981c001SMika Westerberg writel(value, padcfg0); 3467981c001SMika Westerberg } 3477981c001SMika Westerberg 3487981c001SMika Westerberg spin_unlock_irqrestore(&pctrl->lock, flags); 3497981c001SMika Westerberg 3507981c001SMika Westerberg return 0; 3517981c001SMika Westerberg } 3527981c001SMika Westerberg 3537981c001SMika Westerberg static int intel_gpio_request_enable(struct pinctrl_dev *pctldev, 3547981c001SMika Westerberg struct pinctrl_gpio_range *range, 3557981c001SMika Westerberg unsigned pin) 3567981c001SMika Westerberg { 3577981c001SMika Westerberg struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 3587981c001SMika Westerberg void __iomem *padcfg0; 3597981c001SMika Westerberg unsigned long flags; 3607981c001SMika Westerberg u32 value; 3617981c001SMika Westerberg 3627981c001SMika Westerberg spin_lock_irqsave(&pctrl->lock, flags); 3637981c001SMika Westerberg 3647981c001SMika Westerberg if (!intel_pad_usable(pctrl, pin)) { 3657981c001SMika Westerberg spin_unlock_irqrestore(&pctrl->lock, flags); 3667981c001SMika Westerberg return -EBUSY; 3677981c001SMika Westerberg } 3687981c001SMika Westerberg 3697981c001SMika Westerberg padcfg0 = intel_get_padcfg(pctrl, pin, PADCFG0); 3707981c001SMika Westerberg /* Put the pad into GPIO mode */ 3717981c001SMika Westerberg value = readl(padcfg0) & ~PADCFG0_PMODE_MASK; 3727981c001SMika Westerberg /* Disable SCI/SMI/NMI generation */ 3737981c001SMika Westerberg value &= ~(PADCFG0_GPIROUTIOXAPIC | PADCFG0_GPIROUTSCI); 3747981c001SMika Westerberg value &= ~(PADCFG0_GPIROUTSMI | PADCFG0_GPIROUTNMI); 3757981c001SMika Westerberg /* Disable TX buffer and enable RX (this will be input) */ 3767981c001SMika Westerberg value &= ~PADCFG0_GPIORXDIS; 3777981c001SMika Westerberg value |= PADCFG0_GPIOTXDIS; 3787981c001SMika Westerberg writel(value, padcfg0); 3797981c001SMika Westerberg 3807981c001SMika Westerberg spin_unlock_irqrestore(&pctrl->lock, flags); 3817981c001SMika Westerberg 3827981c001SMika Westerberg return 0; 3837981c001SMika Westerberg } 3847981c001SMika Westerberg 3857981c001SMika Westerberg static int intel_gpio_set_direction(struct pinctrl_dev *pctldev, 3867981c001SMika Westerberg struct pinctrl_gpio_range *range, 3877981c001SMika Westerberg unsigned pin, bool input) 3887981c001SMika Westerberg { 3897981c001SMika Westerberg struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 3907981c001SMika Westerberg void __iomem *padcfg0; 3917981c001SMika Westerberg unsigned long flags; 3927981c001SMika Westerberg u32 value; 3937981c001SMika Westerberg 3947981c001SMika Westerberg spin_lock_irqsave(&pctrl->lock, flags); 3957981c001SMika Westerberg 3967981c001SMika Westerberg padcfg0 = intel_get_padcfg(pctrl, pin, PADCFG0); 3977981c001SMika Westerberg 3987981c001SMika Westerberg value = readl(padcfg0); 3997981c001SMika Westerberg if (input) 4007981c001SMika Westerberg value |= PADCFG0_GPIOTXDIS; 4017981c001SMika Westerberg else 4027981c001SMika Westerberg value &= ~PADCFG0_GPIOTXDIS; 4037981c001SMika Westerberg writel(value, padcfg0); 4047981c001SMika Westerberg 4057981c001SMika Westerberg spin_unlock_irqrestore(&pctrl->lock, flags); 4067981c001SMika Westerberg 4077981c001SMika Westerberg return 0; 4087981c001SMika Westerberg } 4097981c001SMika Westerberg 4107981c001SMika Westerberg static const struct pinmux_ops intel_pinmux_ops = { 4117981c001SMika Westerberg .get_functions_count = intel_get_functions_count, 4127981c001SMika Westerberg .get_function_name = intel_get_function_name, 4137981c001SMika Westerberg .get_function_groups = intel_get_function_groups, 4147981c001SMika Westerberg .set_mux = intel_pinmux_set_mux, 4157981c001SMika Westerberg .gpio_request_enable = intel_gpio_request_enable, 4167981c001SMika Westerberg .gpio_set_direction = intel_gpio_set_direction, 4177981c001SMika Westerberg }; 4187981c001SMika Westerberg 4197981c001SMika Westerberg static int intel_config_get(struct pinctrl_dev *pctldev, unsigned pin, 4207981c001SMika Westerberg unsigned long *config) 4217981c001SMika Westerberg { 4227981c001SMika Westerberg struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 4237981c001SMika Westerberg enum pin_config_param param = pinconf_to_config_param(*config); 4247981c001SMika Westerberg u32 value, term; 4257981c001SMika Westerberg u16 arg = 0; 4267981c001SMika Westerberg 4277981c001SMika Westerberg if (!intel_pad_owned_by_host(pctrl, pin)) 4287981c001SMika Westerberg return -ENOTSUPP; 4297981c001SMika Westerberg 4307981c001SMika Westerberg value = readl(intel_get_padcfg(pctrl, pin, PADCFG1)); 4317981c001SMika Westerberg term = (value & PADCFG1_TERM_MASK) >> PADCFG1_TERM_SHIFT; 4327981c001SMika Westerberg 4337981c001SMika Westerberg switch (param) { 4347981c001SMika Westerberg case PIN_CONFIG_BIAS_DISABLE: 4357981c001SMika Westerberg if (term) 4367981c001SMika Westerberg return -EINVAL; 4377981c001SMika Westerberg break; 4387981c001SMika Westerberg 4397981c001SMika Westerberg case PIN_CONFIG_BIAS_PULL_UP: 4407981c001SMika Westerberg if (!term || !(value & PADCFG1_TERM_UP)) 4417981c001SMika Westerberg return -EINVAL; 4427981c001SMika Westerberg 4437981c001SMika Westerberg switch (term) { 4447981c001SMika Westerberg case PADCFG1_TERM_1K: 4457981c001SMika Westerberg arg = 1000; 4467981c001SMika Westerberg break; 4477981c001SMika Westerberg case PADCFG1_TERM_2K: 4487981c001SMika Westerberg arg = 2000; 4497981c001SMika Westerberg break; 4507981c001SMika Westerberg case PADCFG1_TERM_5K: 4517981c001SMika Westerberg arg = 5000; 4527981c001SMika Westerberg break; 4537981c001SMika Westerberg case PADCFG1_TERM_20K: 4547981c001SMika Westerberg arg = 20000; 4557981c001SMika Westerberg break; 4567981c001SMika Westerberg } 4577981c001SMika Westerberg 4587981c001SMika Westerberg break; 4597981c001SMika Westerberg 4607981c001SMika Westerberg case PIN_CONFIG_BIAS_PULL_DOWN: 4617981c001SMika Westerberg if (!term || value & PADCFG1_TERM_UP) 4627981c001SMika Westerberg return -EINVAL; 4637981c001SMika Westerberg 4647981c001SMika Westerberg switch (term) { 4657981c001SMika Westerberg case PADCFG1_TERM_5K: 4667981c001SMika Westerberg arg = 5000; 4677981c001SMika Westerberg break; 4687981c001SMika Westerberg case PADCFG1_TERM_20K: 4697981c001SMika Westerberg arg = 20000; 4707981c001SMika Westerberg break; 4717981c001SMika Westerberg } 4727981c001SMika Westerberg 4737981c001SMika Westerberg break; 4747981c001SMika Westerberg 4757981c001SMika Westerberg default: 4767981c001SMika Westerberg return -ENOTSUPP; 4777981c001SMika Westerberg } 4787981c001SMika Westerberg 4797981c001SMika Westerberg *config = pinconf_to_config_packed(param, arg); 4807981c001SMika Westerberg return 0; 4817981c001SMika Westerberg } 4827981c001SMika Westerberg 4837981c001SMika Westerberg static int intel_config_set_pull(struct intel_pinctrl *pctrl, unsigned pin, 4847981c001SMika Westerberg unsigned long config) 4857981c001SMika Westerberg { 4867981c001SMika Westerberg unsigned param = pinconf_to_config_param(config); 4877981c001SMika Westerberg unsigned arg = pinconf_to_config_argument(config); 4887981c001SMika Westerberg void __iomem *padcfg1; 4897981c001SMika Westerberg unsigned long flags; 4907981c001SMika Westerberg int ret = 0; 4917981c001SMika Westerberg u32 value; 4927981c001SMika Westerberg 4937981c001SMika Westerberg spin_lock_irqsave(&pctrl->lock, flags); 4947981c001SMika Westerberg 4957981c001SMika Westerberg padcfg1 = intel_get_padcfg(pctrl, pin, PADCFG1); 4967981c001SMika Westerberg value = readl(padcfg1); 4977981c001SMika Westerberg 4987981c001SMika Westerberg switch (param) { 4997981c001SMika Westerberg case PIN_CONFIG_BIAS_DISABLE: 5007981c001SMika Westerberg value &= ~(PADCFG1_TERM_MASK | PADCFG1_TERM_UP); 5017981c001SMika Westerberg break; 5027981c001SMika Westerberg 5037981c001SMika Westerberg case PIN_CONFIG_BIAS_PULL_UP: 5047981c001SMika Westerberg value &= ~PADCFG1_TERM_MASK; 5057981c001SMika Westerberg 5067981c001SMika Westerberg value |= PADCFG1_TERM_UP; 5077981c001SMika Westerberg 5087981c001SMika Westerberg switch (arg) { 5097981c001SMika Westerberg case 20000: 5107981c001SMika Westerberg value |= PADCFG1_TERM_20K << PADCFG1_TERM_SHIFT; 5117981c001SMika Westerberg break; 5127981c001SMika Westerberg case 5000: 5137981c001SMika Westerberg value |= PADCFG1_TERM_5K << PADCFG1_TERM_SHIFT; 5147981c001SMika Westerberg break; 5157981c001SMika Westerberg case 2000: 5167981c001SMika Westerberg value |= PADCFG1_TERM_2K << PADCFG1_TERM_SHIFT; 5177981c001SMika Westerberg break; 5187981c001SMika Westerberg case 1000: 5197981c001SMika Westerberg value |= PADCFG1_TERM_1K << PADCFG1_TERM_SHIFT; 5207981c001SMika Westerberg break; 5217981c001SMika Westerberg default: 5227981c001SMika Westerberg ret = -EINVAL; 5237981c001SMika Westerberg } 5247981c001SMika Westerberg 5257981c001SMika Westerberg break; 5267981c001SMika Westerberg 5277981c001SMika Westerberg case PIN_CONFIG_BIAS_PULL_DOWN: 5287981c001SMika Westerberg value &= ~(PADCFG1_TERM_UP | PADCFG1_TERM_MASK); 5297981c001SMika Westerberg 5307981c001SMika Westerberg switch (arg) { 5317981c001SMika Westerberg case 20000: 5327981c001SMika Westerberg value |= PADCFG1_TERM_20K << PADCFG1_TERM_SHIFT; 5337981c001SMika Westerberg break; 5347981c001SMika Westerberg case 5000: 5357981c001SMika Westerberg value |= PADCFG1_TERM_5K << PADCFG1_TERM_SHIFT; 5367981c001SMika Westerberg break; 5377981c001SMika Westerberg default: 5387981c001SMika Westerberg ret = -EINVAL; 5397981c001SMika Westerberg } 5407981c001SMika Westerberg 5417981c001SMika Westerberg break; 5427981c001SMika Westerberg } 5437981c001SMika Westerberg 5447981c001SMika Westerberg if (!ret) 5457981c001SMika Westerberg writel(value, padcfg1); 5467981c001SMika Westerberg 5477981c001SMika Westerberg spin_unlock_irqrestore(&pctrl->lock, flags); 5487981c001SMika Westerberg 5497981c001SMika Westerberg return ret; 5507981c001SMika Westerberg } 5517981c001SMika Westerberg 5527981c001SMika Westerberg static int intel_config_set(struct pinctrl_dev *pctldev, unsigned pin, 5537981c001SMika Westerberg unsigned long *configs, unsigned nconfigs) 5547981c001SMika Westerberg { 5557981c001SMika Westerberg struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 5567981c001SMika Westerberg int i, ret; 5577981c001SMika Westerberg 5587981c001SMika Westerberg if (!intel_pad_usable(pctrl, pin)) 5597981c001SMika Westerberg return -ENOTSUPP; 5607981c001SMika Westerberg 5617981c001SMika Westerberg for (i = 0; i < nconfigs; i++) { 5627981c001SMika Westerberg switch (pinconf_to_config_param(configs[i])) { 5637981c001SMika Westerberg case PIN_CONFIG_BIAS_DISABLE: 5647981c001SMika Westerberg case PIN_CONFIG_BIAS_PULL_UP: 5657981c001SMika Westerberg case PIN_CONFIG_BIAS_PULL_DOWN: 5667981c001SMika Westerberg ret = intel_config_set_pull(pctrl, pin, configs[i]); 5677981c001SMika Westerberg if (ret) 5687981c001SMika Westerberg return ret; 5697981c001SMika Westerberg break; 5707981c001SMika Westerberg 5717981c001SMika Westerberg default: 5727981c001SMika Westerberg return -ENOTSUPP; 5737981c001SMika Westerberg } 5747981c001SMika Westerberg } 5757981c001SMika Westerberg 5767981c001SMika Westerberg return 0; 5777981c001SMika Westerberg } 5787981c001SMika Westerberg 5797981c001SMika Westerberg static const struct pinconf_ops intel_pinconf_ops = { 5807981c001SMika Westerberg .is_generic = true, 5817981c001SMika Westerberg .pin_config_get = intel_config_get, 5827981c001SMika Westerberg .pin_config_set = intel_config_set, 5837981c001SMika Westerberg }; 5847981c001SMika Westerberg 5857981c001SMika Westerberg static const struct pinctrl_desc intel_pinctrl_desc = { 5867981c001SMika Westerberg .pctlops = &intel_pinctrl_ops, 5877981c001SMika Westerberg .pmxops = &intel_pinmux_ops, 5887981c001SMika Westerberg .confops = &intel_pinconf_ops, 5897981c001SMika Westerberg .owner = THIS_MODULE, 5907981c001SMika Westerberg }; 5917981c001SMika Westerberg 5927981c001SMika Westerberg static int intel_gpio_get(struct gpio_chip *chip, unsigned offset) 5937981c001SMika Westerberg { 594acfd4c63SLinus Walleij struct intel_pinctrl *pctrl = gpiochip_get_data(chip); 5957981c001SMika Westerberg void __iomem *reg; 5967981c001SMika Westerberg 5977981c001SMika Westerberg reg = intel_get_padcfg(pctrl, offset, PADCFG0); 5987981c001SMika Westerberg if (!reg) 5997981c001SMika Westerberg return -EINVAL; 6007981c001SMika Westerberg 6017981c001SMika Westerberg return !!(readl(reg) & PADCFG0_GPIORXSTATE); 6027981c001SMika Westerberg } 6037981c001SMika Westerberg 6047981c001SMika Westerberg static void intel_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 6057981c001SMika Westerberg { 606acfd4c63SLinus Walleij struct intel_pinctrl *pctrl = gpiochip_get_data(chip); 6077981c001SMika Westerberg void __iomem *reg; 6087981c001SMika Westerberg 6097981c001SMika Westerberg reg = intel_get_padcfg(pctrl, offset, PADCFG0); 6107981c001SMika Westerberg if (reg) { 6117981c001SMika Westerberg unsigned long flags; 6127981c001SMika Westerberg u32 padcfg0; 6137981c001SMika Westerberg 6147981c001SMika Westerberg spin_lock_irqsave(&pctrl->lock, flags); 6157981c001SMika Westerberg padcfg0 = readl(reg); 6167981c001SMika Westerberg if (value) 6177981c001SMika Westerberg padcfg0 |= PADCFG0_GPIOTXSTATE; 6187981c001SMika Westerberg else 6197981c001SMika Westerberg padcfg0 &= ~PADCFG0_GPIOTXSTATE; 6207981c001SMika Westerberg writel(padcfg0, reg); 6217981c001SMika Westerberg spin_unlock_irqrestore(&pctrl->lock, flags); 6227981c001SMika Westerberg } 6237981c001SMika Westerberg } 6247981c001SMika Westerberg 6257981c001SMika Westerberg static int intel_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 6267981c001SMika Westerberg { 6277981c001SMika Westerberg return pinctrl_gpio_direction_input(chip->base + offset); 6287981c001SMika Westerberg } 6297981c001SMika Westerberg 6307981c001SMika Westerberg static int intel_gpio_direction_output(struct gpio_chip *chip, unsigned offset, 6317981c001SMika Westerberg int value) 6327981c001SMika Westerberg { 6337981c001SMika Westerberg intel_gpio_set(chip, offset, value); 6347981c001SMika Westerberg return pinctrl_gpio_direction_output(chip->base + offset); 6357981c001SMika Westerberg } 6367981c001SMika Westerberg 6377981c001SMika Westerberg static const struct gpio_chip intel_gpio_chip = { 6387981c001SMika Westerberg .owner = THIS_MODULE, 63998c85d58SJonas Gorski .request = gpiochip_generic_request, 64098c85d58SJonas Gorski .free = gpiochip_generic_free, 6417981c001SMika Westerberg .direction_input = intel_gpio_direction_input, 6427981c001SMika Westerberg .direction_output = intel_gpio_direction_output, 6437981c001SMika Westerberg .get = intel_gpio_get, 6447981c001SMika Westerberg .set = intel_gpio_set, 6457981c001SMika Westerberg }; 6467981c001SMika Westerberg 6477981c001SMika Westerberg static void intel_gpio_irq_ack(struct irq_data *d) 6487981c001SMika Westerberg { 6497981c001SMika Westerberg struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 650acfd4c63SLinus Walleij struct intel_pinctrl *pctrl = gpiochip_get_data(gc); 6517981c001SMika Westerberg const struct intel_community *community; 6527981c001SMika Westerberg unsigned pin = irqd_to_hwirq(d); 6537981c001SMika Westerberg 6547981c001SMika Westerberg spin_lock(&pctrl->lock); 6557981c001SMika Westerberg 6567981c001SMika Westerberg community = intel_get_community(pctrl, pin); 6577981c001SMika Westerberg if (community) { 6587981c001SMika Westerberg unsigned padno = pin_to_padno(community, pin); 659618a919bSQipeng Zha unsigned gpp_offset = padno % community->gpp_size; 660618a919bSQipeng Zha unsigned gpp = padno / community->gpp_size; 6617981c001SMika Westerberg 6627981c001SMika Westerberg writel(BIT(gpp_offset), community->regs + GPI_IS + gpp * 4); 6637981c001SMika Westerberg } 6647981c001SMika Westerberg 6657981c001SMika Westerberg spin_unlock(&pctrl->lock); 6667981c001SMika Westerberg } 6677981c001SMika Westerberg 668*a939bb57SQi Zheng static void intel_gpio_irq_enable(struct irq_data *d) 669*a939bb57SQi Zheng { 670*a939bb57SQi Zheng struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 671*a939bb57SQi Zheng struct intel_pinctrl *pctrl = gpiochip_get_data(gc); 672*a939bb57SQi Zheng const struct intel_community *community; 673*a939bb57SQi Zheng unsigned pin = irqd_to_hwirq(d); 674*a939bb57SQi Zheng unsigned long flags; 675*a939bb57SQi Zheng 676*a939bb57SQi Zheng spin_lock_irqsave(&pctrl->lock, flags); 677*a939bb57SQi Zheng 678*a939bb57SQi Zheng community = intel_get_community(pctrl, pin); 679*a939bb57SQi Zheng if (community) { 680*a939bb57SQi Zheng unsigned padno = pin_to_padno(community, pin); 681*a939bb57SQi Zheng unsigned gpp_size = community->gpp_size; 682*a939bb57SQi Zheng unsigned gpp_offset = padno % gpp_size; 683*a939bb57SQi Zheng unsigned gpp = padno / gpp_size; 684*a939bb57SQi Zheng u32 value; 685*a939bb57SQi Zheng 686*a939bb57SQi Zheng /* Clear interrupt status first to avoid unexpected interrupt */ 687*a939bb57SQi Zheng writel(BIT(gpp_offset), community->regs + GPI_IS + gpp * 4); 688*a939bb57SQi Zheng 689*a939bb57SQi Zheng value = readl(community->regs + community->ie_offset + gpp * 4); 690*a939bb57SQi Zheng value |= BIT(gpp_offset); 691*a939bb57SQi Zheng writel(value, community->regs + community->ie_offset + gpp * 4); 692*a939bb57SQi Zheng } 693*a939bb57SQi Zheng 694*a939bb57SQi Zheng spin_unlock_irqrestore(&pctrl->lock, flags); 695*a939bb57SQi Zheng } 696*a939bb57SQi Zheng 6977981c001SMika Westerberg static void intel_gpio_irq_mask_unmask(struct irq_data *d, bool mask) 6987981c001SMika Westerberg { 6997981c001SMika Westerberg struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 700acfd4c63SLinus Walleij struct intel_pinctrl *pctrl = gpiochip_get_data(gc); 7017981c001SMika Westerberg const struct intel_community *community; 7027981c001SMika Westerberg unsigned pin = irqd_to_hwirq(d); 7037981c001SMika Westerberg unsigned long flags; 7047981c001SMika Westerberg 7057981c001SMika Westerberg spin_lock_irqsave(&pctrl->lock, flags); 7067981c001SMika Westerberg 7077981c001SMika Westerberg community = intel_get_community(pctrl, pin); 7087981c001SMika Westerberg if (community) { 7097981c001SMika Westerberg unsigned padno = pin_to_padno(community, pin); 710618a919bSQipeng Zha unsigned gpp_offset = padno % community->gpp_size; 711618a919bSQipeng Zha unsigned gpp = padno / community->gpp_size; 7127981c001SMika Westerberg void __iomem *reg; 7137981c001SMika Westerberg u32 value; 7147981c001SMika Westerberg 7157981c001SMika Westerberg reg = community->regs + community->ie_offset + gpp * 4; 7167981c001SMika Westerberg value = readl(reg); 7177981c001SMika Westerberg if (mask) 7187981c001SMika Westerberg value &= ~BIT(gpp_offset); 7197981c001SMika Westerberg else 7207981c001SMika Westerberg value |= BIT(gpp_offset); 7217981c001SMika Westerberg writel(value, reg); 7227981c001SMika Westerberg } 7237981c001SMika Westerberg 7247981c001SMika Westerberg spin_unlock_irqrestore(&pctrl->lock, flags); 7257981c001SMika Westerberg } 7267981c001SMika Westerberg 7277981c001SMika Westerberg static void intel_gpio_irq_mask(struct irq_data *d) 7287981c001SMika Westerberg { 7297981c001SMika Westerberg intel_gpio_irq_mask_unmask(d, true); 7307981c001SMika Westerberg } 7317981c001SMika Westerberg 7327981c001SMika Westerberg static void intel_gpio_irq_unmask(struct irq_data *d) 7337981c001SMika Westerberg { 7347981c001SMika Westerberg intel_gpio_irq_mask_unmask(d, false); 7357981c001SMika Westerberg } 7367981c001SMika Westerberg 7377981c001SMika Westerberg static int intel_gpio_irq_type(struct irq_data *d, unsigned type) 7387981c001SMika Westerberg { 7397981c001SMika Westerberg struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 740acfd4c63SLinus Walleij struct intel_pinctrl *pctrl = gpiochip_get_data(gc); 7417981c001SMika Westerberg unsigned pin = irqd_to_hwirq(d); 7427981c001SMika Westerberg unsigned long flags; 7437981c001SMika Westerberg void __iomem *reg; 7447981c001SMika Westerberg u32 value; 7457981c001SMika Westerberg 7467981c001SMika Westerberg reg = intel_get_padcfg(pctrl, pin, PADCFG0); 7477981c001SMika Westerberg if (!reg) 7487981c001SMika Westerberg return -EINVAL; 7497981c001SMika Westerberg 7504341e8a5SMika Westerberg /* 7514341e8a5SMika Westerberg * If the pin is in ACPI mode it is still usable as a GPIO but it 7524341e8a5SMika Westerberg * cannot be used as IRQ because GPI_IS status bit will not be 7534341e8a5SMika Westerberg * updated by the host controller hardware. 7544341e8a5SMika Westerberg */ 7554341e8a5SMika Westerberg if (intel_pad_acpi_mode(pctrl, pin)) { 7564341e8a5SMika Westerberg dev_warn(pctrl->dev, "pin %u cannot be used as IRQ\n", pin); 7574341e8a5SMika Westerberg return -EPERM; 7584341e8a5SMika Westerberg } 7594341e8a5SMika Westerberg 7607981c001SMika Westerberg spin_lock_irqsave(&pctrl->lock, flags); 7617981c001SMika Westerberg 7627981c001SMika Westerberg value = readl(reg); 7637981c001SMika Westerberg 7647981c001SMika Westerberg value &= ~(PADCFG0_RXEVCFG_MASK | PADCFG0_RXINV); 7657981c001SMika Westerberg 7667981c001SMika Westerberg if ((type & IRQ_TYPE_EDGE_BOTH) == IRQ_TYPE_EDGE_BOTH) { 7677981c001SMika Westerberg value |= PADCFG0_RXEVCFG_EDGE_BOTH << PADCFG0_RXEVCFG_SHIFT; 7687981c001SMika Westerberg } else if (type & IRQ_TYPE_EDGE_FALLING) { 7697981c001SMika Westerberg value |= PADCFG0_RXEVCFG_EDGE << PADCFG0_RXEVCFG_SHIFT; 7707981c001SMika Westerberg value |= PADCFG0_RXINV; 7717981c001SMika Westerberg } else if (type & IRQ_TYPE_EDGE_RISING) { 7727981c001SMika Westerberg value |= PADCFG0_RXEVCFG_EDGE << PADCFG0_RXEVCFG_SHIFT; 773bf380cfaSQipeng Zha } else if (type & IRQ_TYPE_LEVEL_MASK) { 774bf380cfaSQipeng Zha if (type & IRQ_TYPE_LEVEL_LOW) 7757981c001SMika Westerberg value |= PADCFG0_RXINV; 7767981c001SMika Westerberg } else { 7777981c001SMika Westerberg value |= PADCFG0_RXEVCFG_DISABLED << PADCFG0_RXEVCFG_SHIFT; 7787981c001SMika Westerberg } 7797981c001SMika Westerberg 7807981c001SMika Westerberg writel(value, reg); 7817981c001SMika Westerberg 7827981c001SMika Westerberg if (type & IRQ_TYPE_EDGE_BOTH) 783fc756bcdSThomas Gleixner irq_set_handler_locked(d, handle_edge_irq); 7847981c001SMika Westerberg else if (type & IRQ_TYPE_LEVEL_MASK) 785fc756bcdSThomas Gleixner irq_set_handler_locked(d, handle_level_irq); 7867981c001SMika Westerberg 7877981c001SMika Westerberg spin_unlock_irqrestore(&pctrl->lock, flags); 7887981c001SMika Westerberg 7897981c001SMika Westerberg return 0; 7907981c001SMika Westerberg } 7917981c001SMika Westerberg 7927981c001SMika Westerberg static int intel_gpio_irq_wake(struct irq_data *d, unsigned int on) 7937981c001SMika Westerberg { 7947981c001SMika Westerberg struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 795acfd4c63SLinus Walleij struct intel_pinctrl *pctrl = gpiochip_get_data(gc); 7967981c001SMika Westerberg const struct intel_community *community; 7977981c001SMika Westerberg unsigned pin = irqd_to_hwirq(d); 7987981c001SMika Westerberg unsigned padno, gpp, gpp_offset; 7997981c001SMika Westerberg u32 gpe_en; 8007981c001SMika Westerberg 8017981c001SMika Westerberg community = intel_get_community(pctrl, pin); 8027981c001SMika Westerberg if (!community) 8037981c001SMika Westerberg return -EINVAL; 8047981c001SMika Westerberg 8057981c001SMika Westerberg padno = pin_to_padno(community, pin); 806618a919bSQipeng Zha gpp = padno / community->gpp_size; 807618a919bSQipeng Zha gpp_offset = padno % community->gpp_size; 8087981c001SMika Westerberg 8097981c001SMika Westerberg /* Clear the existing wake status */ 8107981c001SMika Westerberg writel(BIT(gpp_offset), community->regs + GPI_GPE_STS + gpp * 4); 8117981c001SMika Westerberg 8127981c001SMika Westerberg /* 8137981c001SMika Westerberg * The controller will generate wake when GPE of the corresponding 8147981c001SMika Westerberg * pad is enabled and it is not routed to SCI (GPIROUTSCI is not 8157981c001SMika Westerberg * set). 8167981c001SMika Westerberg */ 8177981c001SMika Westerberg gpe_en = readl(community->regs + GPI_GPE_EN + gpp * 4); 8187981c001SMika Westerberg if (on) 8197981c001SMika Westerberg gpe_en |= BIT(gpp_offset); 8207981c001SMika Westerberg else 8217981c001SMika Westerberg gpe_en &= ~BIT(gpp_offset); 8227981c001SMika Westerberg writel(gpe_en, community->regs + GPI_GPE_EN + gpp * 4); 8237981c001SMika Westerberg 8247981c001SMika Westerberg dev_dbg(pctrl->dev, "%sable wake for pin %u\n", on ? "en" : "dis", pin); 8257981c001SMika Westerberg return 0; 8267981c001SMika Westerberg } 8277981c001SMika Westerberg 828193b40c8SMika Westerberg static irqreturn_t intel_gpio_community_irq_handler(struct intel_pinctrl *pctrl, 8297981c001SMika Westerberg const struct intel_community *community) 8307981c001SMika Westerberg { 831193b40c8SMika Westerberg struct gpio_chip *gc = &pctrl->chip; 832193b40c8SMika Westerberg irqreturn_t ret = IRQ_NONE; 8337981c001SMika Westerberg int gpp; 8347981c001SMika Westerberg 8357981c001SMika Westerberg for (gpp = 0; gpp < community->ngpps; gpp++) { 8367981c001SMika Westerberg unsigned long pending, enabled, gpp_offset; 8377981c001SMika Westerberg 8387981c001SMika Westerberg pending = readl(community->regs + GPI_IS + gpp * 4); 8397981c001SMika Westerberg enabled = readl(community->regs + community->ie_offset + 8407981c001SMika Westerberg gpp * 4); 8417981c001SMika Westerberg 8427981c001SMika Westerberg /* Only interrupts that are enabled */ 8437981c001SMika Westerberg pending &= enabled; 8447981c001SMika Westerberg 845618a919bSQipeng Zha for_each_set_bit(gpp_offset, &pending, community->gpp_size) { 8467981c001SMika Westerberg unsigned padno, irq; 8477981c001SMika Westerberg 8487981c001SMika Westerberg /* 8497981c001SMika Westerberg * The last group in community can have less pins 8507981c001SMika Westerberg * than NPADS_IN_GPP. 8517981c001SMika Westerberg */ 852618a919bSQipeng Zha padno = gpp_offset + gpp * community->gpp_size; 8537981c001SMika Westerberg if (padno >= community->npins) 8547981c001SMika Westerberg break; 8557981c001SMika Westerberg 8567981c001SMika Westerberg irq = irq_find_mapping(gc->irqdomain, 8577981c001SMika Westerberg community->pin_base + padno); 8587981c001SMika Westerberg generic_handle_irq(irq); 859193b40c8SMika Westerberg 860193b40c8SMika Westerberg ret |= IRQ_HANDLED; 8617981c001SMika Westerberg } 8627981c001SMika Westerberg } 8637981c001SMika Westerberg 864193b40c8SMika Westerberg return ret; 865193b40c8SMika Westerberg } 866193b40c8SMika Westerberg 867193b40c8SMika Westerberg static irqreturn_t intel_gpio_irq(int irq, void *data) 8687981c001SMika Westerberg { 869193b40c8SMika Westerberg const struct intel_community *community; 870193b40c8SMika Westerberg struct intel_pinctrl *pctrl = data; 871193b40c8SMika Westerberg irqreturn_t ret = IRQ_NONE; 8727981c001SMika Westerberg int i; 8737981c001SMika Westerberg 8747981c001SMika Westerberg /* Need to check all communities for pending interrupts */ 875193b40c8SMika Westerberg for (i = 0; i < pctrl->ncommunities; i++) { 876193b40c8SMika Westerberg community = &pctrl->communities[i]; 877193b40c8SMika Westerberg ret |= intel_gpio_community_irq_handler(pctrl, community); 878193b40c8SMika Westerberg } 8797981c001SMika Westerberg 880193b40c8SMika Westerberg return ret; 8817981c001SMika Westerberg } 8827981c001SMika Westerberg 8837981c001SMika Westerberg static struct irq_chip intel_gpio_irqchip = { 8847981c001SMika Westerberg .name = "intel-gpio", 885*a939bb57SQi Zheng .irq_enable = intel_gpio_irq_enable, 8867981c001SMika Westerberg .irq_ack = intel_gpio_irq_ack, 8877981c001SMika Westerberg .irq_mask = intel_gpio_irq_mask, 8887981c001SMika Westerberg .irq_unmask = intel_gpio_irq_unmask, 8897981c001SMika Westerberg .irq_set_type = intel_gpio_irq_type, 8907981c001SMika Westerberg .irq_set_wake = intel_gpio_irq_wake, 8917981c001SMika Westerberg }; 8927981c001SMika Westerberg 8937981c001SMika Westerberg static int intel_gpio_probe(struct intel_pinctrl *pctrl, int irq) 8947981c001SMika Westerberg { 8957981c001SMika Westerberg int ret; 8967981c001SMika Westerberg 8977981c001SMika Westerberg pctrl->chip = intel_gpio_chip; 8987981c001SMika Westerberg 8997981c001SMika Westerberg pctrl->chip.ngpio = pctrl->soc->npins; 9007981c001SMika Westerberg pctrl->chip.label = dev_name(pctrl->dev); 90158383c78SLinus Walleij pctrl->chip.parent = pctrl->dev; 9027981c001SMika Westerberg pctrl->chip.base = -1; 9037981c001SMika Westerberg 904acfd4c63SLinus Walleij ret = gpiochip_add_data(&pctrl->chip, pctrl); 9057981c001SMika Westerberg if (ret) { 9067981c001SMika Westerberg dev_err(pctrl->dev, "failed to register gpiochip\n"); 9077981c001SMika Westerberg return ret; 9087981c001SMika Westerberg } 9097981c001SMika Westerberg 9107981c001SMika Westerberg ret = gpiochip_add_pin_range(&pctrl->chip, dev_name(pctrl->dev), 9117981c001SMika Westerberg 0, 0, pctrl->soc->npins); 9127981c001SMika Westerberg if (ret) { 9137981c001SMika Westerberg dev_err(pctrl->dev, "failed to add GPIO pin range\n"); 914193b40c8SMika Westerberg goto fail; 915193b40c8SMika Westerberg } 916193b40c8SMika Westerberg 917193b40c8SMika Westerberg /* 918193b40c8SMika Westerberg * We need to request the interrupt here (instead of providing chip 919193b40c8SMika Westerberg * to the irq directly) because on some platforms several GPIO 920193b40c8SMika Westerberg * controllers share the same interrupt line. 921193b40c8SMika Westerberg */ 922193b40c8SMika Westerberg ret = devm_request_irq(pctrl->dev, irq, intel_gpio_irq, IRQF_SHARED, 923193b40c8SMika Westerberg dev_name(pctrl->dev), pctrl); 924193b40c8SMika Westerberg if (ret) { 925193b40c8SMika Westerberg dev_err(pctrl->dev, "failed to request interrupt\n"); 926193b40c8SMika Westerberg goto fail; 9277981c001SMika Westerberg } 9287981c001SMika Westerberg 9297981c001SMika Westerberg ret = gpiochip_irqchip_add(&pctrl->chip, &intel_gpio_irqchip, 0, 9307981c001SMika Westerberg handle_simple_irq, IRQ_TYPE_NONE); 9317981c001SMika Westerberg if (ret) { 9327981c001SMika Westerberg dev_err(pctrl->dev, "failed to add irqchip\n"); 933193b40c8SMika Westerberg goto fail; 9347981c001SMika Westerberg } 9357981c001SMika Westerberg 9367981c001SMika Westerberg gpiochip_set_chained_irqchip(&pctrl->chip, &intel_gpio_irqchip, irq, 937193b40c8SMika Westerberg NULL); 9387981c001SMika Westerberg return 0; 939193b40c8SMika Westerberg 940193b40c8SMika Westerberg fail: 941193b40c8SMika Westerberg gpiochip_remove(&pctrl->chip); 942193b40c8SMika Westerberg 943193b40c8SMika Westerberg return ret; 9447981c001SMika Westerberg } 9457981c001SMika Westerberg 9467981c001SMika Westerberg static int intel_pinctrl_pm_init(struct intel_pinctrl *pctrl) 9477981c001SMika Westerberg { 9487981c001SMika Westerberg #ifdef CONFIG_PM_SLEEP 9497981c001SMika Westerberg const struct intel_pinctrl_soc_data *soc = pctrl->soc; 9507981c001SMika Westerberg struct intel_community_context *communities; 9517981c001SMika Westerberg struct intel_pad_context *pads; 9527981c001SMika Westerberg int i; 9537981c001SMika Westerberg 9547981c001SMika Westerberg pads = devm_kcalloc(pctrl->dev, soc->npins, sizeof(*pads), GFP_KERNEL); 9557981c001SMika Westerberg if (!pads) 9567981c001SMika Westerberg return -ENOMEM; 9577981c001SMika Westerberg 9587981c001SMika Westerberg communities = devm_kcalloc(pctrl->dev, pctrl->ncommunities, 9597981c001SMika Westerberg sizeof(*communities), GFP_KERNEL); 9607981c001SMika Westerberg if (!communities) 9617981c001SMika Westerberg return -ENOMEM; 9627981c001SMika Westerberg 9637981c001SMika Westerberg 9647981c001SMika Westerberg for (i = 0; i < pctrl->ncommunities; i++) { 9657981c001SMika Westerberg struct intel_community *community = &pctrl->communities[i]; 9667981c001SMika Westerberg u32 *intmask; 9677981c001SMika Westerberg 9687981c001SMika Westerberg intmask = devm_kcalloc(pctrl->dev, community->ngpps, 9697981c001SMika Westerberg sizeof(*intmask), GFP_KERNEL); 9707981c001SMika Westerberg if (!intmask) 9717981c001SMika Westerberg return -ENOMEM; 9727981c001SMika Westerberg 9737981c001SMika Westerberg communities[i].intmask = intmask; 9747981c001SMika Westerberg } 9757981c001SMika Westerberg 9767981c001SMika Westerberg pctrl->context.pads = pads; 9777981c001SMika Westerberg pctrl->context.communities = communities; 9787981c001SMika Westerberg #endif 9797981c001SMika Westerberg 9807981c001SMika Westerberg return 0; 9817981c001SMika Westerberg } 9827981c001SMika Westerberg 9837981c001SMika Westerberg int intel_pinctrl_probe(struct platform_device *pdev, 9847981c001SMika Westerberg const struct intel_pinctrl_soc_data *soc_data) 9857981c001SMika Westerberg { 9867981c001SMika Westerberg struct intel_pinctrl *pctrl; 9877981c001SMika Westerberg int i, ret, irq; 9887981c001SMika Westerberg 9897981c001SMika Westerberg if (!soc_data) 9907981c001SMika Westerberg return -EINVAL; 9917981c001SMika Westerberg 9927981c001SMika Westerberg pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL); 9937981c001SMika Westerberg if (!pctrl) 9947981c001SMika Westerberg return -ENOMEM; 9957981c001SMika Westerberg 9967981c001SMika Westerberg pctrl->dev = &pdev->dev; 9977981c001SMika Westerberg pctrl->soc = soc_data; 9987981c001SMika Westerberg spin_lock_init(&pctrl->lock); 9997981c001SMika Westerberg 10007981c001SMika Westerberg /* 10017981c001SMika Westerberg * Make a copy of the communities which we can use to hold pointers 10027981c001SMika Westerberg * to the registers. 10037981c001SMika Westerberg */ 10047981c001SMika Westerberg pctrl->ncommunities = pctrl->soc->ncommunities; 10057981c001SMika Westerberg pctrl->communities = devm_kcalloc(&pdev->dev, pctrl->ncommunities, 10067981c001SMika Westerberg sizeof(*pctrl->communities), GFP_KERNEL); 10077981c001SMika Westerberg if (!pctrl->communities) 10087981c001SMika Westerberg return -ENOMEM; 10097981c001SMika Westerberg 10107981c001SMika Westerberg for (i = 0; i < pctrl->ncommunities; i++) { 10117981c001SMika Westerberg struct intel_community *community = &pctrl->communities[i]; 10127981c001SMika Westerberg struct resource *res; 10137981c001SMika Westerberg void __iomem *regs; 10147981c001SMika Westerberg u32 padbar; 10157981c001SMika Westerberg 10167981c001SMika Westerberg *community = pctrl->soc->communities[i]; 10177981c001SMika Westerberg 10187981c001SMika Westerberg res = platform_get_resource(pdev, IORESOURCE_MEM, 10197981c001SMika Westerberg community->barno); 10207981c001SMika Westerberg regs = devm_ioremap_resource(&pdev->dev, res); 10217981c001SMika Westerberg if (IS_ERR(regs)) 10227981c001SMika Westerberg return PTR_ERR(regs); 10237981c001SMika Westerberg 10247981c001SMika Westerberg /* Read offset of the pad configuration registers */ 10257981c001SMika Westerberg padbar = readl(regs + PADBAR); 10267981c001SMika Westerberg 10277981c001SMika Westerberg community->regs = regs; 10287981c001SMika Westerberg community->pad_regs = regs + padbar; 1029618a919bSQipeng Zha community->ngpps = DIV_ROUND_UP(community->npins, 1030618a919bSQipeng Zha community->gpp_size); 10317981c001SMika Westerberg } 10327981c001SMika Westerberg 10337981c001SMika Westerberg irq = platform_get_irq(pdev, 0); 10347981c001SMika Westerberg if (irq < 0) { 10357981c001SMika Westerberg dev_err(&pdev->dev, "failed to get interrupt number\n"); 10367981c001SMika Westerberg return irq; 10377981c001SMika Westerberg } 10387981c001SMika Westerberg 10397981c001SMika Westerberg ret = intel_pinctrl_pm_init(pctrl); 10407981c001SMika Westerberg if (ret) 10417981c001SMika Westerberg return ret; 10427981c001SMika Westerberg 10437981c001SMika Westerberg pctrl->pctldesc = intel_pinctrl_desc; 10447981c001SMika Westerberg pctrl->pctldesc.name = dev_name(&pdev->dev); 10457981c001SMika Westerberg pctrl->pctldesc.pins = pctrl->soc->pins; 10467981c001SMika Westerberg pctrl->pctldesc.npins = pctrl->soc->npins; 10477981c001SMika Westerberg 10487981c001SMika Westerberg pctrl->pctldev = pinctrl_register(&pctrl->pctldesc, &pdev->dev, pctrl); 1049323de9efSMasahiro Yamada if (IS_ERR(pctrl->pctldev)) { 10507981c001SMika Westerberg dev_err(&pdev->dev, "failed to register pinctrl driver\n"); 1051323de9efSMasahiro Yamada return PTR_ERR(pctrl->pctldev); 10527981c001SMika Westerberg } 10537981c001SMika Westerberg 10547981c001SMika Westerberg ret = intel_gpio_probe(pctrl, irq); 10557981c001SMika Westerberg if (ret) { 10567981c001SMika Westerberg pinctrl_unregister(pctrl->pctldev); 10577981c001SMika Westerberg return ret; 10587981c001SMika Westerberg } 10597981c001SMika Westerberg 10607981c001SMika Westerberg platform_set_drvdata(pdev, pctrl); 10617981c001SMika Westerberg 10627981c001SMika Westerberg return 0; 10637981c001SMika Westerberg } 10647981c001SMika Westerberg EXPORT_SYMBOL_GPL(intel_pinctrl_probe); 10657981c001SMika Westerberg 10667981c001SMika Westerberg int intel_pinctrl_remove(struct platform_device *pdev) 10677981c001SMika Westerberg { 10687981c001SMika Westerberg struct intel_pinctrl *pctrl = platform_get_drvdata(pdev); 10697981c001SMika Westerberg 10707981c001SMika Westerberg gpiochip_remove(&pctrl->chip); 10717981c001SMika Westerberg pinctrl_unregister(pctrl->pctldev); 10727981c001SMika Westerberg 10737981c001SMika Westerberg return 0; 10747981c001SMika Westerberg } 10757981c001SMika Westerberg EXPORT_SYMBOL_GPL(intel_pinctrl_remove); 10767981c001SMika Westerberg 10777981c001SMika Westerberg #ifdef CONFIG_PM_SLEEP 10787981c001SMika Westerberg int intel_pinctrl_suspend(struct device *dev) 10797981c001SMika Westerberg { 10807981c001SMika Westerberg struct platform_device *pdev = to_platform_device(dev); 10817981c001SMika Westerberg struct intel_pinctrl *pctrl = platform_get_drvdata(pdev); 10827981c001SMika Westerberg struct intel_community_context *communities; 10837981c001SMika Westerberg struct intel_pad_context *pads; 10847981c001SMika Westerberg int i; 10857981c001SMika Westerberg 10867981c001SMika Westerberg pads = pctrl->context.pads; 10877981c001SMika Westerberg for (i = 0; i < pctrl->soc->npins; i++) { 10887981c001SMika Westerberg const struct pinctrl_pin_desc *desc = &pctrl->soc->pins[i]; 10897981c001SMika Westerberg u32 val; 10907981c001SMika Westerberg 10917981c001SMika Westerberg if (!intel_pad_usable(pctrl, desc->number)) 10927981c001SMika Westerberg continue; 10937981c001SMika Westerberg 10947981c001SMika Westerberg val = readl(intel_get_padcfg(pctrl, desc->number, PADCFG0)); 10957981c001SMika Westerberg pads[i].padcfg0 = val & ~PADCFG0_GPIORXSTATE; 10967981c001SMika Westerberg val = readl(intel_get_padcfg(pctrl, desc->number, PADCFG1)); 10977981c001SMika Westerberg pads[i].padcfg1 = val; 10987981c001SMika Westerberg } 10997981c001SMika Westerberg 11007981c001SMika Westerberg communities = pctrl->context.communities; 11017981c001SMika Westerberg for (i = 0; i < pctrl->ncommunities; i++) { 11027981c001SMika Westerberg struct intel_community *community = &pctrl->communities[i]; 11037981c001SMika Westerberg void __iomem *base; 11047981c001SMika Westerberg unsigned gpp; 11057981c001SMika Westerberg 11067981c001SMika Westerberg base = community->regs + community->ie_offset; 11077981c001SMika Westerberg for (gpp = 0; gpp < community->ngpps; gpp++) 11087981c001SMika Westerberg communities[i].intmask[gpp] = readl(base + gpp * 4); 11097981c001SMika Westerberg } 11107981c001SMika Westerberg 11117981c001SMika Westerberg return 0; 11127981c001SMika Westerberg } 11137981c001SMika Westerberg EXPORT_SYMBOL_GPL(intel_pinctrl_suspend); 11147981c001SMika Westerberg 1115f487bbf3SMika Westerberg static void intel_gpio_irq_init(struct intel_pinctrl *pctrl) 1116f487bbf3SMika Westerberg { 1117f487bbf3SMika Westerberg size_t i; 1118f487bbf3SMika Westerberg 1119f487bbf3SMika Westerberg for (i = 0; i < pctrl->ncommunities; i++) { 1120f487bbf3SMika Westerberg const struct intel_community *community; 1121f487bbf3SMika Westerberg void __iomem *base; 1122f487bbf3SMika Westerberg unsigned gpp; 1123f487bbf3SMika Westerberg 1124f487bbf3SMika Westerberg community = &pctrl->communities[i]; 1125f487bbf3SMika Westerberg base = community->regs; 1126f487bbf3SMika Westerberg 1127f487bbf3SMika Westerberg for (gpp = 0; gpp < community->ngpps; gpp++) { 1128f487bbf3SMika Westerberg /* Mask and clear all interrupts */ 1129f487bbf3SMika Westerberg writel(0, base + community->ie_offset + gpp * 4); 1130f487bbf3SMika Westerberg writel(0xffff, base + GPI_IS + gpp * 4); 1131f487bbf3SMika Westerberg } 1132f487bbf3SMika Westerberg } 1133f487bbf3SMika Westerberg } 1134f487bbf3SMika Westerberg 11357981c001SMika Westerberg int intel_pinctrl_resume(struct device *dev) 11367981c001SMika Westerberg { 11377981c001SMika Westerberg struct platform_device *pdev = to_platform_device(dev); 11387981c001SMika Westerberg struct intel_pinctrl *pctrl = platform_get_drvdata(pdev); 11397981c001SMika Westerberg const struct intel_community_context *communities; 11407981c001SMika Westerberg const struct intel_pad_context *pads; 11417981c001SMika Westerberg int i; 11427981c001SMika Westerberg 11437981c001SMika Westerberg /* Mask all interrupts */ 11447981c001SMika Westerberg intel_gpio_irq_init(pctrl); 11457981c001SMika Westerberg 11467981c001SMika Westerberg pads = pctrl->context.pads; 11477981c001SMika Westerberg for (i = 0; i < pctrl->soc->npins; i++) { 11487981c001SMika Westerberg const struct pinctrl_pin_desc *desc = &pctrl->soc->pins[i]; 11497981c001SMika Westerberg void __iomem *padcfg; 11507981c001SMika Westerberg u32 val; 11517981c001SMika Westerberg 11527981c001SMika Westerberg if (!intel_pad_usable(pctrl, desc->number)) 11537981c001SMika Westerberg continue; 11547981c001SMika Westerberg 11557981c001SMika Westerberg padcfg = intel_get_padcfg(pctrl, desc->number, PADCFG0); 11567981c001SMika Westerberg val = readl(padcfg) & ~PADCFG0_GPIORXSTATE; 11577981c001SMika Westerberg if (val != pads[i].padcfg0) { 11587981c001SMika Westerberg writel(pads[i].padcfg0, padcfg); 11597981c001SMika Westerberg dev_dbg(dev, "restored pin %u padcfg0 %#08x\n", 11607981c001SMika Westerberg desc->number, readl(padcfg)); 11617981c001SMika Westerberg } 11627981c001SMika Westerberg 11637981c001SMika Westerberg padcfg = intel_get_padcfg(pctrl, desc->number, PADCFG1); 11647981c001SMika Westerberg val = readl(padcfg); 11657981c001SMika Westerberg if (val != pads[i].padcfg1) { 11667981c001SMika Westerberg writel(pads[i].padcfg1, padcfg); 11677981c001SMika Westerberg dev_dbg(dev, "restored pin %u padcfg1 %#08x\n", 11687981c001SMika Westerberg desc->number, readl(padcfg)); 11697981c001SMika Westerberg } 11707981c001SMika Westerberg } 11717981c001SMika Westerberg 11727981c001SMika Westerberg communities = pctrl->context.communities; 11737981c001SMika Westerberg for (i = 0; i < pctrl->ncommunities; i++) { 11747981c001SMika Westerberg struct intel_community *community = &pctrl->communities[i]; 11757981c001SMika Westerberg void __iomem *base; 11767981c001SMika Westerberg unsigned gpp; 11777981c001SMika Westerberg 11787981c001SMika Westerberg base = community->regs + community->ie_offset; 11797981c001SMika Westerberg for (gpp = 0; gpp < community->ngpps; gpp++) { 11807981c001SMika Westerberg writel(communities[i].intmask[gpp], base + gpp * 4); 11817981c001SMika Westerberg dev_dbg(dev, "restored mask %d/%u %#08x\n", i, gpp, 11827981c001SMika Westerberg readl(base + gpp * 4)); 11837981c001SMika Westerberg } 11847981c001SMika Westerberg } 11857981c001SMika Westerberg 11867981c001SMika Westerberg return 0; 11877981c001SMika Westerberg } 11887981c001SMika Westerberg EXPORT_SYMBOL_GPL(intel_pinctrl_resume); 11897981c001SMika Westerberg #endif 11907981c001SMika Westerberg 11917981c001SMika Westerberg MODULE_AUTHOR("Mathias Nyman <mathias.nyman@linux.intel.com>"); 11927981c001SMika Westerberg MODULE_AUTHOR("Mika Westerberg <mika.westerberg@linux.intel.com>"); 11937981c001SMika Westerberg MODULE_DESCRIPTION("Intel pinctrl/GPIO core driver"); 11947981c001SMika Westerberg MODULE_LICENSE("GPL v2"); 1195