1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (c) 2020-2021 Rockchip Electronics Co. Ltd.
5 * Copyright (c) 2013 MundoReader S.L.
6 * Author: Heiko Stuebner <heiko@sntech.de>
8 * With some ideas taken from pinctrl-samsung:
9 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
10 * http://www.samsung.com
11 * Copyright (c) 2012 Linaro Ltd
12 * https://www.linaro.org
15 * Copyright (C) 2011-2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
18 #ifndef _PINCTRL_ROCKCHIP_H
19 #define _PINCTRL_ROCKCHIP_H
21 enum rockchip_pinctrl_type {
36 * struct rockchip_gpio_regs
37 * @port_dr: data register
38 * @port_ddr: data direction register
39 * @int_en: interrupt enable
40 * @int_mask: interrupt mask
41 * @int_type: interrupt trigger type, such as high, low, edge trriger type.
42 * @int_polarity: interrupt polarity enable register
43 * @int_bothedge: interrupt bothedge enable register
44 * @int_status: interrupt status register
45 * @int_rawstatus: int_status = int_rawstatus & int_mask
46 * @debounce: enable debounce for interrupt signal
47 * @dbclk_div_en: enable divider for debounce clock
48 * @dbclk_div_con: setting for divider of debounce clock
49 * @port_eoi: end of interrupt of the port
50 * @ext_port: port data from external
51 * @version_id: controller version register
53 struct rockchip_gpio_regs {
72 * struct rockchip_iomux
73 * @type: iomux variant using IOMUX_* constants
74 * @offset: if initialized to -1 it will be autocalculated, by specifying
75 * an initial offset value the relevant source offset can be reset
76 * to a new value for autocalculating the following iomux registers.
78 struct rockchip_iomux {
84 * enum type index corresponding to rockchip_perpin_drv_list arrays index.
86 enum rockchip_pin_drv_type {
87 DRV_TYPE_IO_DEFAULT = 0,
88 DRV_TYPE_IO_1V8_OR_3V0,
90 DRV_TYPE_IO_1V8_3V0_AUTO,
96 * enum type index corresponding to rockchip_pull_list arrays index.
98 enum rockchip_pin_pull_type {
99 PULL_TYPE_IO_DEFAULT = 0,
100 PULL_TYPE_IO_1V8_ONLY,
105 * struct rockchip_drv
106 * @drv_type: drive strength variant using rockchip_perpin_drv_type
107 * @offset: if initialized to -1 it will be autocalculated, by specifying
108 * an initial offset value the relevant source offset can be reset
109 * to a new value for autocalculating the following drive strength
110 * registers. if used chips own cal_drv func instead to calculate
111 * registers offset, the variant could be ignored.
113 struct rockchip_drv {
114 enum rockchip_pin_drv_type drv_type;
119 * struct rockchip_pin_bank
120 * @dev: the pinctrl device bind to the bank
121 * @reg_base: register base of the gpio bank
122 * @regmap_pull: optional separate register for additional pull settings
123 * @clk: clock of the gpio bank
124 * @db_clk: clock of the gpio debounce
125 * @irq: interrupt of the gpio bank
126 * @saved_masks: Saved content of GPIO_INTEN at suspend time.
127 * @pin_base: first pin number
128 * @nr_pins: number of pins in this bank
129 * @name: name of the bank
130 * @bank_num: number of the bank, to account for holes
131 * @iomux: array describing the 4 iomux sources of the bank
132 * @drv: array describing the 4 drive strength sources of the bank
133 * @pull_type: array describing the 4 pull type sources of the bank
134 * @valid: is all necessary information present
135 * @of_node: dt node of this bank
136 * @drvdata: common pinctrl basedata
137 * @domain: irqdomain of the gpio bank
138 * @gpio_chip: gpiolib chip
139 * @grange: gpio range
140 * @slock: spinlock for the gpio bank
141 * @toggle_edge_mode: bit mask to toggle (falling/rising) edge mode
142 * @recalced_mask: bit mask to indicate a need to recalulate the mask
143 * @route_mask: bits describing the routing pins of per bank
144 * @deferred_output: gpio output settings to be done after gpio bank probed
145 * @deferred_lock: mutex for the deferred_output shared btw gpio and pinctrl
147 struct rockchip_pin_bank {
149 void __iomem *reg_base;
150 struct regmap *regmap_pull;
159 struct rockchip_iomux iomux[4];
160 struct rockchip_drv drv[4];
161 enum rockchip_pin_pull_type pull_type[4];
163 struct device_node *of_node;
164 struct rockchip_pinctrl *drvdata;
165 struct irq_domain *domain;
166 struct gpio_chip gpio_chip;
167 struct pinctrl_gpio_range grange;
168 raw_spinlock_t slock;
169 const struct rockchip_gpio_regs *gpio_regs;
171 u32 toggle_edge_mode;
174 struct list_head deferred_output;
175 struct mutex deferred_lock;
179 * struct rockchip_mux_recalced_data: represent a pin iomux data.
182 * @bit: index at register.
183 * @reg: register offset.
186 struct rockchip_mux_recalced_data {
194 enum rockchip_mux_route_location {
195 ROCKCHIP_ROUTE_SAME = 0,
201 * struct rockchip_mux_recalced_data: represent a pin iomux data.
202 * @bank_num: bank number.
203 * @pin: index at register or used to calc index.
204 * @func: the min pin.
205 * @route_location: the mux route location (same, pmu, grf).
206 * @route_offset: the max pin.
207 * @route_val: the register offset.
209 struct rockchip_mux_route_data {
213 enum rockchip_mux_route_location route_location;
218 struct rockchip_pin_ctrl {
219 struct rockchip_pin_bank *pin_banks;
223 enum rockchip_pinctrl_type type;
228 struct rockchip_mux_recalced_data *iomux_recalced;
230 struct rockchip_mux_route_data *iomux_routes;
233 void (*pull_calc_reg)(struct rockchip_pin_bank *bank,
234 int pin_num, struct regmap **regmap,
236 void (*drv_calc_reg)(struct rockchip_pin_bank *bank,
237 int pin_num, struct regmap **regmap,
239 int (*schmitt_calc_reg)(struct rockchip_pin_bank *bank,
240 int pin_num, struct regmap **regmap,
244 struct rockchip_pin_config {
246 unsigned long *configs;
247 unsigned int nconfigs;
250 struct rockchip_pin_output_deferred {
251 struct list_head head;
257 * struct rockchip_pin_group: represent group of pins of a pinmux function.
258 * @name: name of the pin group, used to lookup the group.
259 * @pins: the pins included in this group.
260 * @npins: number of pins included in this group.
261 * @data: local pin configuration
263 struct rockchip_pin_group {
267 struct rockchip_pin_config *data;
271 * struct rockchip_pmx_func: represent a pin function.
272 * @name: name of the pin function, used to lookup the function.
273 * @groups: one or more names of pin groups that provide this function.
274 * @ngroups: number of groups included in @groups.
276 struct rockchip_pmx_func {
282 struct rockchip_pinctrl {
283 struct regmap *regmap_base;
285 struct regmap *regmap_pull;
286 struct regmap *regmap_pmu;
288 struct rockchip_pin_ctrl *ctrl;
289 struct pinctrl_desc pctl;
290 struct pinctrl_dev *pctl_dev;
291 struct rockchip_pin_group *groups;
292 unsigned int ngroups;
293 struct rockchip_pmx_func *functions;
294 unsigned int nfunctions;