2018-06-29 20:36:34 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2015-03-30 22:31:49 +08:00
|
|
|
/*
|
|
|
|
* Core pinctrl/GPIO driver for Intel GPIO controllers
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015, Intel Corporation
|
|
|
|
* Authors: Mathias Nyman <mathias.nyman@linux.intel.com>
|
|
|
|
* Mika Westerberg <mika.westerberg@linux.intel.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PINCTRL_INTEL_H
|
|
|
|
#define PINCTRL_INTEL_H
|
|
|
|
|
2019-10-25 17:10:28 +08:00
|
|
|
#include <linux/gpio/driver.h>
|
|
|
|
#include <linux/irq.h>
|
2018-09-04 19:26:17 +08:00
|
|
|
#include <linux/pm.h>
|
2019-10-25 17:10:28 +08:00
|
|
|
#include <linux/spinlock_types.h>
|
2018-09-04 19:26:17 +08:00
|
|
|
|
2015-03-30 22:31:49 +08:00
|
|
|
struct pinctrl_pin_desc;
|
|
|
|
struct platform_device;
|
|
|
|
struct device;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct intel_pingroup - Description about group of pins
|
|
|
|
* @name: Name of the groups
|
|
|
|
* @pins: All pins in this group
|
|
|
|
* @npins: Number of pins in this groups
|
2017-06-06 21:18:18 +08:00
|
|
|
* @mode: Native mode in which the group is muxed out @pins. Used if @modes
|
|
|
|
* is %NULL.
|
|
|
|
* @modes: If not %NULL this will hold mode for each pin in @pins
|
2015-03-30 22:31:49 +08:00
|
|
|
*/
|
|
|
|
struct intel_pingroup {
|
|
|
|
const char *name;
|
2018-09-26 22:50:26 +08:00
|
|
|
const unsigned int *pins;
|
2015-03-30 22:31:49 +08:00
|
|
|
size_t npins;
|
|
|
|
unsigned short mode;
|
2018-09-26 22:50:26 +08:00
|
|
|
const unsigned int *modes;
|
2015-03-30 22:31:49 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct intel_function - Description about a function
|
|
|
|
* @name: Name of the function
|
|
|
|
* @groups: An array of groups for this function
|
|
|
|
* @ngroups: Number of groups in @groups
|
|
|
|
*/
|
|
|
|
struct intel_function {
|
|
|
|
const char *name;
|
|
|
|
const char * const *groups;
|
|
|
|
size_t ngroups;
|
|
|
|
};
|
|
|
|
|
2017-06-06 21:18:17 +08:00
|
|
|
/**
|
|
|
|
* struct intel_padgroup - Hardware pad group information
|
|
|
|
* @reg_num: GPI_IS register number
|
|
|
|
* @base: Starting pin of this group
|
|
|
|
* @size: Size of this group (maximum is 32).
|
2020-04-13 19:18:20 +08:00
|
|
|
* @gpio_base: Starting GPIO base of this group
|
2017-06-06 21:18:17 +08:00
|
|
|
* @padown_num: PAD_OWN register number (assigned by the core driver)
|
|
|
|
*
|
|
|
|
* If pad groups of a community are not the same size, use this structure
|
|
|
|
* to specify them.
|
|
|
|
*/
|
|
|
|
struct intel_padgroup {
|
2018-09-26 22:50:26 +08:00
|
|
|
unsigned int reg_num;
|
|
|
|
unsigned int base;
|
|
|
|
unsigned int size;
|
2017-11-27 21:54:43 +08:00
|
|
|
int gpio_base;
|
2018-09-26 22:50:26 +08:00
|
|
|
unsigned int padown_num;
|
2017-06-06 21:18:17 +08:00
|
|
|
};
|
|
|
|
|
2020-04-13 19:18:20 +08:00
|
|
|
/**
|
|
|
|
* enum - Special treatment for GPIO base in pad group
|
|
|
|
*
|
2020-04-13 19:18:24 +08:00
|
|
|
* @INTEL_GPIO_BASE_ZERO: force GPIO base to be 0
|
2020-04-13 19:18:20 +08:00
|
|
|
* @INTEL_GPIO_BASE_NOMAP: no GPIO mapping should be created
|
|
|
|
* @INTEL_GPIO_BASE_MATCH: matches with starting pin number
|
|
|
|
*/
|
|
|
|
enum {
|
2020-04-13 19:18:24 +08:00
|
|
|
INTEL_GPIO_BASE_ZERO = -2,
|
2020-04-13 19:18:20 +08:00
|
|
|
INTEL_GPIO_BASE_NOMAP = -1,
|
|
|
|
INTEL_GPIO_BASE_MATCH = 0,
|
|
|
|
};
|
|
|
|
|
2015-03-30 22:31:49 +08:00
|
|
|
/**
|
|
|
|
* struct intel_community - Intel pin community description
|
|
|
|
* @barno: MMIO BAR number where registers for this community reside
|
|
|
|
* @padown_offset: Register offset of PAD_OWN register from @regs. If %0
|
|
|
|
* then there is no support for owner.
|
|
|
|
* @padcfglock_offset: Register offset of PADCFGLOCK from @regs. If %0 then
|
|
|
|
* locking is not supported.
|
|
|
|
* @hostown_offset: Register offset of HOSTSW_OWN from @regs. If %0 then it
|
|
|
|
* is assumed that the host owns the pin (rather than
|
|
|
|
* ACPI).
|
2019-07-23 23:56:33 +08:00
|
|
|
* @is_offset: Register offset of GPI_IS from @regs.
|
2015-03-30 22:31:49 +08:00
|
|
|
* @ie_offset: Register offset of GPI_IE from @regs.
|
2019-07-27 04:16:36 +08:00
|
|
|
* @features: Additional features supported by the hardware
|
2015-03-30 22:31:49 +08:00
|
|
|
* @pin_base: Starting pin of pins in this community
|
2020-04-22 03:00:49 +08:00
|
|
|
* @npins: Number of pins in this community
|
2015-11-26 01:09:51 +08:00
|
|
|
* @gpp_size: Maximum number of pads in each group, such as PADCFGLOCK,
|
2020-04-22 03:00:48 +08:00
|
|
|
* HOSTSW_OWN, GPI_IS, GPI_IE. Used when @gpps is %NULL.
|
2017-06-06 21:18:17 +08:00
|
|
|
* @gpp_num_padown_regs: Number of pad registers each pad group consumes at
|
|
|
|
* minimum. Use %0 if the number of registers can be
|
|
|
|
* determined by the size of the group.
|
|
|
|
* @gpps: Pad groups if the controller has variable size pad groups
|
|
|
|
* @ngpps: Number of pad groups in this community
|
2019-07-27 04:16:36 +08:00
|
|
|
* @pad_map: Optional non-linear mapping of the pads
|
2020-06-10 02:24:47 +08:00
|
|
|
* @nirqs: Optional total number of IRQs this community can generate
|
2020-06-10 02:24:48 +08:00
|
|
|
* @acpi_space_id: Optional address space ID for ACPI OpRegion handler
|
2015-03-30 22:31:49 +08:00
|
|
|
* @regs: Community specific common registers (reserved for core driver)
|
|
|
|
* @pad_regs: Community specific pad registers (reserved for core driver)
|
2017-06-06 21:18:17 +08:00
|
|
|
*
|
2020-04-22 03:00:48 +08:00
|
|
|
* In some of Intel GPIO host controllers this driver supports each pad group
|
|
|
|
* is of equal size (except the last one). In that case the driver can just
|
2017-06-06 21:18:17 +08:00
|
|
|
* fill in @gpp_size field and let the core driver to handle the rest. If
|
|
|
|
* the controller has pad groups of variable size the client driver can
|
|
|
|
* pass custom @gpps and @ngpps instead.
|
2015-03-30 22:31:49 +08:00
|
|
|
*/
|
|
|
|
struct intel_community {
|
2018-09-26 22:50:26 +08:00
|
|
|
unsigned int barno;
|
|
|
|
unsigned int padown_offset;
|
|
|
|
unsigned int padcfglock_offset;
|
|
|
|
unsigned int hostown_offset;
|
|
|
|
unsigned int is_offset;
|
|
|
|
unsigned int ie_offset;
|
2019-07-27 04:16:36 +08:00
|
|
|
unsigned int features;
|
2018-09-26 22:50:26 +08:00
|
|
|
unsigned int pin_base;
|
2020-04-22 03:00:49 +08:00
|
|
|
size_t npins;
|
2018-09-26 22:50:26 +08:00
|
|
|
unsigned int gpp_size;
|
|
|
|
unsigned int gpp_num_padown_regs;
|
2017-06-06 21:18:17 +08:00
|
|
|
const struct intel_padgroup *gpps;
|
|
|
|
size_t ngpps;
|
2019-07-27 04:16:36 +08:00
|
|
|
const unsigned int *pad_map;
|
2020-06-10 02:24:47 +08:00
|
|
|
unsigned short nirqs;
|
2020-06-10 02:24:48 +08:00
|
|
|
unsigned short acpi_space_id;
|
2020-04-22 03:00:49 +08:00
|
|
|
|
2017-06-06 21:18:17 +08:00
|
|
|
/* Reserved for the core driver */
|
2015-03-30 22:31:49 +08:00
|
|
|
void __iomem *regs;
|
|
|
|
void __iomem *pad_regs;
|
|
|
|
};
|
|
|
|
|
2017-01-27 18:07:14 +08:00
|
|
|
/* Additional features supported by the hardware */
|
|
|
|
#define PINCTRL_FEATURE_DEBOUNCE BIT(0)
|
2017-01-27 18:07:15 +08:00
|
|
|
#define PINCTRL_FEATURE_1K_PD BIT(1)
|
2017-01-27 18:07:14 +08:00
|
|
|
|
2017-06-06 21:18:18 +08:00
|
|
|
/**
|
|
|
|
* PIN_GROUP - Declare a pin group
|
|
|
|
* @n: Name of the group
|
|
|
|
* @p: An array of pins this group consists
|
|
|
|
* @m: Mode which the pins are put when this group is active. Can be either
|
|
|
|
* a single integer or an array of integers in which case mode is per
|
|
|
|
* pin.
|
|
|
|
*/
|
|
|
|
#define PIN_GROUP(n, p, m) \
|
|
|
|
{ \
|
|
|
|
.name = (n), \
|
|
|
|
.pins = (p), \
|
|
|
|
.npins = ARRAY_SIZE((p)), \
|
|
|
|
.mode = __builtin_choose_expr( \
|
|
|
|
__builtin_constant_p((m)), (m), 0), \
|
|
|
|
.modes = __builtin_choose_expr( \
|
|
|
|
__builtin_constant_p((m)), NULL, (m)), \
|
2015-03-30 22:31:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#define FUNCTION(n, g) \
|
|
|
|
{ \
|
|
|
|
.name = (n), \
|
|
|
|
.groups = (g), \
|
|
|
|
.ngroups = ARRAY_SIZE((g)), \
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct intel_pinctrl_soc_data - Intel pin controller per-SoC configuration
|
|
|
|
* @uid: ACPI _UID for the probe driver use if needed
|
|
|
|
* @pins: Array if pins this pinctrl controls
|
|
|
|
* @npins: Number of pins in the array
|
|
|
|
* @groups: Array of pin groups
|
|
|
|
* @ngroups: Number of groups in the array
|
|
|
|
* @functions: Array of functions
|
|
|
|
* @nfunctions: Number of functions in the array
|
|
|
|
* @communities: Array of communities this pinctrl handles
|
|
|
|
* @ncommunities: Number of communities in the array
|
|
|
|
*
|
|
|
|
* The @communities is used as a template by the core driver. It will make
|
|
|
|
* copy of all communities and fill in rest of the information.
|
|
|
|
*/
|
|
|
|
struct intel_pinctrl_soc_data {
|
|
|
|
const char *uid;
|
|
|
|
const struct pinctrl_pin_desc *pins;
|
|
|
|
size_t npins;
|
|
|
|
const struct intel_pingroup *groups;
|
|
|
|
size_t ngroups;
|
|
|
|
const struct intel_function *functions;
|
|
|
|
size_t nfunctions;
|
|
|
|
const struct intel_community *communities;
|
|
|
|
size_t ncommunities;
|
|
|
|
};
|
|
|
|
|
2020-07-29 19:57:06 +08:00
|
|
|
const struct intel_pinctrl_soc_data *intel_pinctrl_get_soc_data(struct platform_device *pdev);
|
|
|
|
|
2019-10-25 17:10:28 +08:00
|
|
|
struct intel_pad_context;
|
|
|
|
struct intel_community_context;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct intel_pinctrl_context - context to be saved during suspend-resume
|
|
|
|
* @pads: Opaque context per pad (driver dependent)
|
|
|
|
* @communities: Opaque context per community (driver dependent)
|
|
|
|
*/
|
|
|
|
struct intel_pinctrl_context {
|
|
|
|
struct intel_pad_context *pads;
|
|
|
|
struct intel_community_context *communities;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct intel_pinctrl - Intel pinctrl private structure
|
|
|
|
* @dev: Pointer to the device structure
|
|
|
|
* @lock: Lock to serialize register access
|
|
|
|
* @pctldesc: Pin controller description
|
|
|
|
* @pctldev: Pointer to the pin controller device
|
|
|
|
* @chip: GPIO chip in this pin controller
|
|
|
|
* @irqchip: IRQ chip in this pin controller
|
|
|
|
* @soc: SoC/PCH specific pin configuration data
|
|
|
|
* @communities: All communities in this pin controller
|
|
|
|
* @ncommunities: Number of communities in this pin controller
|
|
|
|
* @context: Configuration saved over system sleep
|
|
|
|
* @irq: pinctrl/GPIO chip irq number
|
|
|
|
*/
|
|
|
|
struct intel_pinctrl {
|
|
|
|
struct device *dev;
|
|
|
|
raw_spinlock_t lock;
|
|
|
|
struct pinctrl_desc pctldesc;
|
|
|
|
struct pinctrl_dev *pctldev;
|
|
|
|
struct gpio_chip chip;
|
|
|
|
struct irq_chip irqchip;
|
|
|
|
const struct intel_pinctrl_soc_data *soc;
|
|
|
|
struct intel_community *communities;
|
|
|
|
size_t ncommunities;
|
|
|
|
struct intel_pinctrl_context context;
|
|
|
|
int irq;
|
|
|
|
};
|
|
|
|
|
2018-08-31 00:27:40 +08:00
|
|
|
int intel_pinctrl_probe_by_hid(struct platform_device *pdev);
|
2018-08-31 00:27:36 +08:00
|
|
|
int intel_pinctrl_probe_by_uid(struct platform_device *pdev);
|
|
|
|
|
2015-03-30 22:31:49 +08:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
pinctrl: pinctrl-intel: move gpio suspend/resume to noirq phase
In current driver, SET_LATE_SYSTEM_SLEEP_PM_OPS is used to install the
callbacks for suspend/resume.
GPIO pin may be used as the interrupt pin by some device. However, using
SET_LATE_SYSTEM_SLEEP_PM_OPS() to install the callbacks, the resume
callback is called after resume_device_irqs(). Unintended interrupts may
arrive due to resuming device irqs first, but the GPIO controller is not
properly restored.
Normally, for a SMP system, there are multiple cores, so even when there are
unintended interrupts, BSP gets the chance to initialize the GPIO chip soon.
But when there is only 1 core is active (other cores are offlined or
single core) during resume, it is more easily to observe the unintended
interrupts.
This patch renames the suspend/resume function by adding suffix "_noirq",
and installs the callbacks using SET_NOIRQ_SYSTEM_SLEEP_PM_OPS().
Signed-off-by: Binbin Wu <binbin.wu@intel.com>
Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2019-04-08 18:49:26 +08:00
|
|
|
int intel_pinctrl_suspend_noirq(struct device *dev);
|
|
|
|
int intel_pinctrl_resume_noirq(struct device *dev);
|
2015-03-30 22:31:49 +08:00
|
|
|
#endif
|
|
|
|
|
pinctrl: pinctrl-intel: move gpio suspend/resume to noirq phase
In current driver, SET_LATE_SYSTEM_SLEEP_PM_OPS is used to install the
callbacks for suspend/resume.
GPIO pin may be used as the interrupt pin by some device. However, using
SET_LATE_SYSTEM_SLEEP_PM_OPS() to install the callbacks, the resume
callback is called after resume_device_irqs(). Unintended interrupts may
arrive due to resuming device irqs first, but the GPIO controller is not
properly restored.
Normally, for a SMP system, there are multiple cores, so even when there are
unintended interrupts, BSP gets the chance to initialize the GPIO chip soon.
But when there is only 1 core is active (other cores are offlined or
single core) during resume, it is more easily to observe the unintended
interrupts.
This patch renames the suspend/resume function by adding suffix "_noirq",
and installs the callbacks using SET_NOIRQ_SYSTEM_SLEEP_PM_OPS().
Signed-off-by: Binbin Wu <binbin.wu@intel.com>
Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2019-04-08 18:49:26 +08:00
|
|
|
#define INTEL_PINCTRL_PM_OPS(_name) \
|
|
|
|
const struct dev_pm_ops _name = { \
|
|
|
|
SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(intel_pinctrl_suspend_noirq, \
|
|
|
|
intel_pinctrl_resume_noirq) \
|
2018-08-31 00:27:43 +08:00
|
|
|
}
|
|
|
|
|
2015-03-30 22:31:49 +08:00
|
|
|
#endif /* PINCTRL_INTEL_H */
|