1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */ 2*4882a593Smuzhiyun /* 3*4882a593Smuzhiyun * Core pinctrl/GPIO driver for Intel GPIO controllers 4*4882a593Smuzhiyun * 5*4882a593Smuzhiyun * Copyright (C) 2015, Intel Corporation 6*4882a593Smuzhiyun * Authors: Mathias Nyman <mathias.nyman@linux.intel.com> 7*4882a593Smuzhiyun * Mika Westerberg <mika.westerberg@linux.intel.com> 8*4882a593Smuzhiyun */ 9*4882a593Smuzhiyun 10*4882a593Smuzhiyun #ifndef PINCTRL_INTEL_H 11*4882a593Smuzhiyun #define PINCTRL_INTEL_H 12*4882a593Smuzhiyun 13*4882a593Smuzhiyun #include <linux/bits.h> 14*4882a593Smuzhiyun #include <linux/compiler_types.h> 15*4882a593Smuzhiyun #include <linux/gpio/driver.h> 16*4882a593Smuzhiyun #include <linux/irq.h> 17*4882a593Smuzhiyun #include <linux/kernel.h> 18*4882a593Smuzhiyun #include <linux/pm.h> 19*4882a593Smuzhiyun #include <linux/pinctrl/pinctrl.h> 20*4882a593Smuzhiyun #include <linux/spinlock_types.h> 21*4882a593Smuzhiyun 22*4882a593Smuzhiyun struct platform_device; 23*4882a593Smuzhiyun struct device; 24*4882a593Smuzhiyun 25*4882a593Smuzhiyun /** 26*4882a593Smuzhiyun * struct intel_pingroup - Description about group of pins 27*4882a593Smuzhiyun * @name: Name of the groups 28*4882a593Smuzhiyun * @pins: All pins in this group 29*4882a593Smuzhiyun * @npins: Number of pins in this groups 30*4882a593Smuzhiyun * @mode: Native mode in which the group is muxed out @pins. Used if @modes 31*4882a593Smuzhiyun * is %NULL. 32*4882a593Smuzhiyun * @modes: If not %NULL this will hold mode for each pin in @pins 33*4882a593Smuzhiyun */ 34*4882a593Smuzhiyun struct intel_pingroup { 35*4882a593Smuzhiyun const char *name; 36*4882a593Smuzhiyun const unsigned int *pins; 37*4882a593Smuzhiyun size_t npins; 38*4882a593Smuzhiyun unsigned short mode; 39*4882a593Smuzhiyun const unsigned int *modes; 40*4882a593Smuzhiyun }; 41*4882a593Smuzhiyun 42*4882a593Smuzhiyun /** 43*4882a593Smuzhiyun * struct intel_function - Description about a function 44*4882a593Smuzhiyun * @name: Name of the function 45*4882a593Smuzhiyun * @groups: An array of groups for this function 46*4882a593Smuzhiyun * @ngroups: Number of groups in @groups 47*4882a593Smuzhiyun */ 48*4882a593Smuzhiyun struct intel_function { 49*4882a593Smuzhiyun const char *name; 50*4882a593Smuzhiyun const char * const *groups; 51*4882a593Smuzhiyun size_t ngroups; 52*4882a593Smuzhiyun }; 53*4882a593Smuzhiyun 54*4882a593Smuzhiyun /** 55*4882a593Smuzhiyun * struct intel_padgroup - Hardware pad group information 56*4882a593Smuzhiyun * @reg_num: GPI_IS register number 57*4882a593Smuzhiyun * @base: Starting pin of this group 58*4882a593Smuzhiyun * @size: Size of this group (maximum is 32). 59*4882a593Smuzhiyun * @gpio_base: Starting GPIO base of this group 60*4882a593Smuzhiyun * @padown_num: PAD_OWN register number (assigned by the core driver) 61*4882a593Smuzhiyun * 62*4882a593Smuzhiyun * If pad groups of a community are not the same size, use this structure 63*4882a593Smuzhiyun * to specify them. 64*4882a593Smuzhiyun */ 65*4882a593Smuzhiyun struct intel_padgroup { 66*4882a593Smuzhiyun unsigned int reg_num; 67*4882a593Smuzhiyun unsigned int base; 68*4882a593Smuzhiyun unsigned int size; 69*4882a593Smuzhiyun int gpio_base; 70*4882a593Smuzhiyun unsigned int padown_num; 71*4882a593Smuzhiyun }; 72*4882a593Smuzhiyun 73*4882a593Smuzhiyun /** 74*4882a593Smuzhiyun * enum - Special treatment for GPIO base in pad group 75*4882a593Smuzhiyun * 76*4882a593Smuzhiyun * @INTEL_GPIO_BASE_ZERO: force GPIO base to be 0 77*4882a593Smuzhiyun * @INTEL_GPIO_BASE_NOMAP: no GPIO mapping should be created 78*4882a593Smuzhiyun * @INTEL_GPIO_BASE_MATCH: matches with starting pin number 79*4882a593Smuzhiyun */ 80*4882a593Smuzhiyun enum { 81*4882a593Smuzhiyun INTEL_GPIO_BASE_ZERO = -2, 82*4882a593Smuzhiyun INTEL_GPIO_BASE_NOMAP = -1, 83*4882a593Smuzhiyun INTEL_GPIO_BASE_MATCH = 0, 84*4882a593Smuzhiyun }; 85*4882a593Smuzhiyun 86*4882a593Smuzhiyun /** 87*4882a593Smuzhiyun * struct intel_community - Intel pin community description 88*4882a593Smuzhiyun * @barno: MMIO BAR number where registers for this community reside 89*4882a593Smuzhiyun * @padown_offset: Register offset of PAD_OWN register from @regs. If %0 90*4882a593Smuzhiyun * then there is no support for owner. 91*4882a593Smuzhiyun * @padcfglock_offset: Register offset of PADCFGLOCK from @regs. If %0 then 92*4882a593Smuzhiyun * locking is not supported. 93*4882a593Smuzhiyun * @hostown_offset: Register offset of HOSTSW_OWN from @regs. If %0 then it 94*4882a593Smuzhiyun * is assumed that the host owns the pin (rather than 95*4882a593Smuzhiyun * ACPI). 96*4882a593Smuzhiyun * @is_offset: Register offset of GPI_IS from @regs. 97*4882a593Smuzhiyun * @ie_offset: Register offset of GPI_IE from @regs. 98*4882a593Smuzhiyun * @features: Additional features supported by the hardware 99*4882a593Smuzhiyun * @pin_base: Starting pin of pins in this community 100*4882a593Smuzhiyun * @npins: Number of pins in this community 101*4882a593Smuzhiyun * @gpp_size: Maximum number of pads in each group, such as PADCFGLOCK, 102*4882a593Smuzhiyun * HOSTSW_OWN, GPI_IS, GPI_IE. Used when @gpps is %NULL. 103*4882a593Smuzhiyun * @gpp_num_padown_regs: Number of pad registers each pad group consumes at 104*4882a593Smuzhiyun * minimum. Use %0 if the number of registers can be 105*4882a593Smuzhiyun * determined by the size of the group. 106*4882a593Smuzhiyun * @gpps: Pad groups if the controller has variable size pad groups 107*4882a593Smuzhiyun * @ngpps: Number of pad groups in this community 108*4882a593Smuzhiyun * @pad_map: Optional non-linear mapping of the pads 109*4882a593Smuzhiyun * @nirqs: Optional total number of IRQs this community can generate 110*4882a593Smuzhiyun * @acpi_space_id: Optional address space ID for ACPI OpRegion handler 111*4882a593Smuzhiyun * @regs: Community specific common registers (reserved for core driver) 112*4882a593Smuzhiyun * @pad_regs: Community specific pad registers (reserved for core driver) 113*4882a593Smuzhiyun * 114*4882a593Smuzhiyun * In some of Intel GPIO host controllers this driver supports each pad group 115*4882a593Smuzhiyun * is of equal size (except the last one). In that case the driver can just 116*4882a593Smuzhiyun * fill in @gpp_size field and let the core driver to handle the rest. If 117*4882a593Smuzhiyun * the controller has pad groups of variable size the client driver can 118*4882a593Smuzhiyun * pass custom @gpps and @ngpps instead. 119*4882a593Smuzhiyun */ 120*4882a593Smuzhiyun struct intel_community { 121*4882a593Smuzhiyun unsigned int barno; 122*4882a593Smuzhiyun unsigned int padown_offset; 123*4882a593Smuzhiyun unsigned int padcfglock_offset; 124*4882a593Smuzhiyun unsigned int hostown_offset; 125*4882a593Smuzhiyun unsigned int is_offset; 126*4882a593Smuzhiyun unsigned int ie_offset; 127*4882a593Smuzhiyun unsigned int features; 128*4882a593Smuzhiyun unsigned int pin_base; 129*4882a593Smuzhiyun size_t npins; 130*4882a593Smuzhiyun unsigned int gpp_size; 131*4882a593Smuzhiyun unsigned int gpp_num_padown_regs; 132*4882a593Smuzhiyun const struct intel_padgroup *gpps; 133*4882a593Smuzhiyun size_t ngpps; 134*4882a593Smuzhiyun const unsigned int *pad_map; 135*4882a593Smuzhiyun unsigned short nirqs; 136*4882a593Smuzhiyun unsigned short acpi_space_id; 137*4882a593Smuzhiyun 138*4882a593Smuzhiyun /* Reserved for the core driver */ 139*4882a593Smuzhiyun void __iomem *regs; 140*4882a593Smuzhiyun void __iomem *pad_regs; 141*4882a593Smuzhiyun }; 142*4882a593Smuzhiyun 143*4882a593Smuzhiyun /* Additional features supported by the hardware */ 144*4882a593Smuzhiyun #define PINCTRL_FEATURE_DEBOUNCE BIT(0) 145*4882a593Smuzhiyun #define PINCTRL_FEATURE_1K_PD BIT(1) 146*4882a593Smuzhiyun 147*4882a593Smuzhiyun /** 148*4882a593Smuzhiyun * PIN_GROUP - Declare a pin group 149*4882a593Smuzhiyun * @n: Name of the group 150*4882a593Smuzhiyun * @p: An array of pins this group consists 151*4882a593Smuzhiyun * @m: Mode which the pins are put when this group is active. Can be either 152*4882a593Smuzhiyun * a single integer or an array of integers in which case mode is per 153*4882a593Smuzhiyun * pin. 154*4882a593Smuzhiyun */ 155*4882a593Smuzhiyun #define PIN_GROUP(n, p, m) \ 156*4882a593Smuzhiyun { \ 157*4882a593Smuzhiyun .name = (n), \ 158*4882a593Smuzhiyun .pins = (p), \ 159*4882a593Smuzhiyun .npins = ARRAY_SIZE((p)), \ 160*4882a593Smuzhiyun .mode = __builtin_choose_expr( \ 161*4882a593Smuzhiyun __builtin_constant_p((m)), (m), 0), \ 162*4882a593Smuzhiyun .modes = __builtin_choose_expr( \ 163*4882a593Smuzhiyun __builtin_constant_p((m)), NULL, (m)), \ 164*4882a593Smuzhiyun } 165*4882a593Smuzhiyun 166*4882a593Smuzhiyun #define FUNCTION(n, g) \ 167*4882a593Smuzhiyun { \ 168*4882a593Smuzhiyun .name = (n), \ 169*4882a593Smuzhiyun .groups = (g), \ 170*4882a593Smuzhiyun .ngroups = ARRAY_SIZE((g)), \ 171*4882a593Smuzhiyun } 172*4882a593Smuzhiyun 173*4882a593Smuzhiyun /** 174*4882a593Smuzhiyun * struct intel_pinctrl_soc_data - Intel pin controller per-SoC configuration 175*4882a593Smuzhiyun * @uid: ACPI _UID for the probe driver use if needed 176*4882a593Smuzhiyun * @pins: Array if pins this pinctrl controls 177*4882a593Smuzhiyun * @npins: Number of pins in the array 178*4882a593Smuzhiyun * @groups: Array of pin groups 179*4882a593Smuzhiyun * @ngroups: Number of groups in the array 180*4882a593Smuzhiyun * @functions: Array of functions 181*4882a593Smuzhiyun * @nfunctions: Number of functions in the array 182*4882a593Smuzhiyun * @communities: Array of communities this pinctrl handles 183*4882a593Smuzhiyun * @ncommunities: Number of communities in the array 184*4882a593Smuzhiyun * 185*4882a593Smuzhiyun * The @communities is used as a template by the core driver. It will make 186*4882a593Smuzhiyun * copy of all communities and fill in rest of the information. 187*4882a593Smuzhiyun */ 188*4882a593Smuzhiyun struct intel_pinctrl_soc_data { 189*4882a593Smuzhiyun const char *uid; 190*4882a593Smuzhiyun const struct pinctrl_pin_desc *pins; 191*4882a593Smuzhiyun size_t npins; 192*4882a593Smuzhiyun const struct intel_pingroup *groups; 193*4882a593Smuzhiyun size_t ngroups; 194*4882a593Smuzhiyun const struct intel_function *functions; 195*4882a593Smuzhiyun size_t nfunctions; 196*4882a593Smuzhiyun const struct intel_community *communities; 197*4882a593Smuzhiyun size_t ncommunities; 198*4882a593Smuzhiyun }; 199*4882a593Smuzhiyun 200*4882a593Smuzhiyun const struct intel_pinctrl_soc_data *intel_pinctrl_get_soc_data(struct platform_device *pdev); 201*4882a593Smuzhiyun 202*4882a593Smuzhiyun struct intel_pad_context; 203*4882a593Smuzhiyun struct intel_community_context; 204*4882a593Smuzhiyun 205*4882a593Smuzhiyun /** 206*4882a593Smuzhiyun * struct intel_pinctrl_context - context to be saved during suspend-resume 207*4882a593Smuzhiyun * @pads: Opaque context per pad (driver dependent) 208*4882a593Smuzhiyun * @communities: Opaque context per community (driver dependent) 209*4882a593Smuzhiyun */ 210*4882a593Smuzhiyun struct intel_pinctrl_context { 211*4882a593Smuzhiyun struct intel_pad_context *pads; 212*4882a593Smuzhiyun struct intel_community_context *communities; 213*4882a593Smuzhiyun }; 214*4882a593Smuzhiyun 215*4882a593Smuzhiyun /** 216*4882a593Smuzhiyun * struct intel_pinctrl - Intel pinctrl private structure 217*4882a593Smuzhiyun * @dev: Pointer to the device structure 218*4882a593Smuzhiyun * @lock: Lock to serialize register access 219*4882a593Smuzhiyun * @pctldesc: Pin controller description 220*4882a593Smuzhiyun * @pctldev: Pointer to the pin controller device 221*4882a593Smuzhiyun * @chip: GPIO chip in this pin controller 222*4882a593Smuzhiyun * @irqchip: IRQ chip in this pin controller 223*4882a593Smuzhiyun * @soc: SoC/PCH specific pin configuration data 224*4882a593Smuzhiyun * @communities: All communities in this pin controller 225*4882a593Smuzhiyun * @ncommunities: Number of communities in this pin controller 226*4882a593Smuzhiyun * @context: Configuration saved over system sleep 227*4882a593Smuzhiyun * @irq: pinctrl/GPIO chip irq number 228*4882a593Smuzhiyun */ 229*4882a593Smuzhiyun struct intel_pinctrl { 230*4882a593Smuzhiyun struct device *dev; 231*4882a593Smuzhiyun raw_spinlock_t lock; 232*4882a593Smuzhiyun struct pinctrl_desc pctldesc; 233*4882a593Smuzhiyun struct pinctrl_dev *pctldev; 234*4882a593Smuzhiyun struct gpio_chip chip; 235*4882a593Smuzhiyun struct irq_chip irqchip; 236*4882a593Smuzhiyun const struct intel_pinctrl_soc_data *soc; 237*4882a593Smuzhiyun struct intel_community *communities; 238*4882a593Smuzhiyun size_t ncommunities; 239*4882a593Smuzhiyun struct intel_pinctrl_context context; 240*4882a593Smuzhiyun int irq; 241*4882a593Smuzhiyun }; 242*4882a593Smuzhiyun 243*4882a593Smuzhiyun int intel_pinctrl_probe_by_hid(struct platform_device *pdev); 244*4882a593Smuzhiyun int intel_pinctrl_probe_by_uid(struct platform_device *pdev); 245*4882a593Smuzhiyun 246*4882a593Smuzhiyun #ifdef CONFIG_PM_SLEEP 247*4882a593Smuzhiyun int intel_pinctrl_suspend_noirq(struct device *dev); 248*4882a593Smuzhiyun int intel_pinctrl_resume_noirq(struct device *dev); 249*4882a593Smuzhiyun #endif 250*4882a593Smuzhiyun 251*4882a593Smuzhiyun #define INTEL_PINCTRL_PM_OPS(_name) \ 252*4882a593Smuzhiyun const struct dev_pm_ops _name = { \ 253*4882a593Smuzhiyun SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(intel_pinctrl_suspend_noirq, \ 254*4882a593Smuzhiyun intel_pinctrl_resume_noirq) \ 255*4882a593Smuzhiyun } 256*4882a593Smuzhiyun 257*4882a593Smuzhiyun #endif /* PINCTRL_INTEL_H */ 258