xref: /linux/drivers/pinctrl/qcom/pinctrl-msm.h (revision fd702f895c5addaf9dea1a9d765209592e469cf0)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2013, Sony Mobile Communications AB.
4  */
5 #ifndef __PINCTRL_MSM_H__
6 #define __PINCTRL_MSM_H__
7 
8 #include <linux/pm.h>
9 #include <linux/types.h>
10 
11 #include <linux/pinctrl/pinctrl.h>
12 
13 struct platform_device;
14 
15 struct pinctrl_pin_desc;
16 
17 #define MSM_PIN_FUNCTION(fname) 				\
18 	[msm_mux_##fname] = PINCTRL_PINFUNCTION(#fname,		\
19 					fname##_groups,		\
20 					ARRAY_SIZE(fname##_groups))
21 
22 #define MSM_GPIO_PIN_FUNCTION(fname)				\
23 	[msm_mux_##fname] = PINCTRL_GPIO_PINFUNCTION(#fname,	\
24 					fname##_groups,		\
25 					ARRAY_SIZE(fname##_groups))
26 
27 /**
28  * struct msm_pingroup - Qualcomm pingroup definition
29  * @grp:                  Generic data of the pin group (name and pins)
30  * @funcs:                A list of pinmux functions that can be selected for
31  *                        this group. The index of the selected function is used
32  *                        for programming the function selector.
33  *                        Entries should be indices into the groups list of the
34  *                        struct msm_pinctrl_soc_data.
35  * @ctl_reg:              Offset of the register holding control bits for this group.
36  * @io_reg:               Offset of the register holding input/output bits for this group.
37  * @intr_cfg_reg:         Offset of the register holding interrupt configuration bits.
38  * @intr_status_reg:      Offset of the register holding the status bits for this group.
39  * @intr_target_reg:      Offset of the register specifying routing of the interrupts
40  *                        from this group. On most SoCs this register is the same as
41  *                        @intr_cfg_reg; leaving this field as zero causes the driver
42  *                        to fall back to @intr_cfg_reg automatically. Only set this
43  *                        explicitly on older SoCs where the interrupt target routing
44  *                        lives in a separate register (e.g. APQ8064, MSM8960).
45  * @mux_bit:              Offset in @ctl_reg for the pinmux function selection.
46  * @pull_bit:             Offset in @ctl_reg for the bias configuration.
47  * @drv_bit:              Offset in @ctl_reg for the drive strength configuration.
48  * @od_bit:               Offset in @ctl_reg for controlling open drain.
49  * @oe_bit:               Offset in @ctl_reg for controlling output enable.
50  * @in_bit:               Offset in @io_reg for the input bit value.
51  * @out_bit:              Offset in @io_reg for the output bit value.
52  * @intr_enable_bit:      Offset in @intr_cfg_reg for enabling the interrupt for this group.
53  * @intr_status_bit:      Offset in @intr_status_reg for reading and acking the interrupt
54  *                        status.
55  * @intr_wakeup_present_bit: Offset in @intr_target_reg specifying the GPIO can generate
56  *			  wakeup events.
57  * @intr_wakeup_enable_bit: Offset in @intr_target_reg to enable wakeup events for the GPIO.
58  * @intr_target_bit:      Offset in @intr_target_reg for configuring the interrupt routing.
59  * @intr_target_width:    Number of bits used for specifying interrupt routing target.
60  * @intr_target_kpss_val: Value in @intr_target_bit for specifying that the interrupt from
61  *                        this gpio should get routed to the KPSS processor.
62  * @intr_raw_status_bit:  Offset in @intr_cfg_reg for the raw status bit.
63  * @intr_polarity_bit:    Offset in @intr_cfg_reg for specifying polarity of the interrupt.
64  * @intr_detection_bit:   Offset in @intr_cfg_reg for specifying interrupt type.
65  * @intr_detection_width: Number of bits used for specifying interrupt type,
66  *                        Should be 2 for SoCs that can detect both edges in hardware,
67  *                        otherwise 1.
68  */
69 struct msm_pingroup {
70 	struct pingroup grp;
71 
72 	unsigned *funcs;
73 	unsigned nfuncs;
74 
75 	u32 ctl_reg;
76 	u32 io_reg;
77 	u32 intr_cfg_reg;
78 	u32 intr_status_reg;
79 	u32 intr_target_reg;
80 
81 	unsigned int tile:2;
82 
83 	unsigned mux_bit:5;
84 
85 	unsigned pull_bit:5;
86 	unsigned drv_bit:5;
87 	unsigned i2c_pull_bit:5;
88 
89 	unsigned od_bit:5;
90 	unsigned egpio_enable:5;
91 	unsigned egpio_present:5;
92 	unsigned oe_bit:5;
93 	unsigned in_bit:5;
94 	unsigned out_bit:5;
95 
96 	unsigned intr_enable_bit:5;
97 	unsigned intr_status_bit:5;
98 	unsigned intr_ack_high:1;
99 
100 	unsigned intr_wakeup_present_bit:5;
101 	unsigned intr_wakeup_enable_bit:5;
102 	unsigned intr_target_bit:5;
103 	unsigned intr_target_width:5;
104 	unsigned intr_target_kpss_val:5;
105 	unsigned intr_raw_status_bit:5;
106 	unsigned intr_polarity_bit:5;
107 	unsigned intr_detection_bit:5;
108 	unsigned intr_detection_width:5;
109 };
110 
111 /**
112  * struct msm_gpio_wakeirq_map - Map of GPIOs and their wakeup pins
113  * @gpio:          The GPIOs that are wakeup capable
114  * @wakeirq:       The interrupt at the always-on interrupt controller
115  */
116 struct msm_gpio_wakeirq_map {
117 	unsigned int gpio;
118 	unsigned int wakeirq;
119 };
120 
121 /**
122  * struct msm_pinctrl_soc_data - Qualcomm pin controller driver configuration
123  * @pins:	    An array describing all pins the pin controller affects.
124  * @npins:	    The number of entries in @pins.
125  * @functions:	    An array describing all mux functions the SoC supports.
126  * @nfunctions:	    The number of entries in @functions.
127  * @groups:	    An array describing all pin groups the pin SoC supports.
128  * @ngroups:	    The numbmer of entries in @groups.
129  * @ngpio:	    The number of pingroups the driver should expose as GPIOs.
130  * @pull_no_keeper: The SoC does not support keeper bias.
131  * @wakeirq_map:    The map of wakeup capable GPIOs and the pin at PDC/MPM
132  * @nwakeirq_map:   The number of entries in @wakeirq_map
133  * @wakeirq_dual_edge_errata: If true then GPIOs using the wakeirq_map need
134  *                            to be aware that their parent can't handle dual
135  *                            edge interrupts.
136  * @gpio_func: Which function number is GPIO (usually 0).
137  * @egpio_func: If non-zero then this SoC supports eGPIO. Even though in
138  *              hardware this is a mux 1-level above the TLMM, we'll treat
139  *              it as if this is just another mux state of the TLMM. Since
140  *              it doesn't really map to hardware, we'll allocate a virtual
141  *              function number for eGPIO and any time we see that function
142  *              number used we'll treat it as a request to mux away from
143  *              our TLMM towards another owner.
144  */
145 struct msm_pinctrl_soc_data {
146 	const struct pinctrl_pin_desc *pins;
147 	unsigned npins;
148 	const struct pinfunction *functions;
149 	unsigned nfunctions;
150 	const struct msm_pingroup *groups;
151 	unsigned ngroups;
152 	unsigned ngpios;
153 	bool pull_no_keeper;
154 	const char *const *tiles;
155 	unsigned int ntiles;
156 	const int *reserved_gpios;
157 	const struct msm_gpio_wakeirq_map *wakeirq_map;
158 	unsigned int nwakeirq_map;
159 	bool wakeirq_dual_edge_errata;
160 	unsigned int gpio_func;
161 	unsigned int egpio_func;
162 };
163 
164 extern const struct dev_pm_ops msm_pinctrl_dev_pm_ops;
165 
166 int msm_pinctrl_probe(struct platform_device *pdev,
167 		      const struct msm_pinctrl_soc_data *soc_data);
168 
169 #endif
170