1a83c29e1SYixun Lan // SPDX-License-Identifier: GPL-2.0
2a83c29e1SYixun Lan /* Copyright (c) 2024 Yixun Lan <dlan@gentoo.org> */
3a83c29e1SYixun Lan
4a83c29e1SYixun Lan #include <linux/bits.h>
5a83c29e1SYixun Lan #include <linux/cleanup.h>
6a83c29e1SYixun Lan #include <linux/io.h>
7a83c29e1SYixun Lan #include <linux/of.h>
8a83c29e1SYixun Lan #include <linux/platform_device.h>
9a83c29e1SYixun Lan #include <linux/seq_file.h>
10a83c29e1SYixun Lan #include <linux/spinlock.h>
11a83c29e1SYixun Lan #include <linux/module.h>
12a83c29e1SYixun Lan
13a83c29e1SYixun Lan #include <linux/pinctrl/pinconf-generic.h>
14a83c29e1SYixun Lan #include <linux/pinctrl/pinconf.h>
15a83c29e1SYixun Lan #include <linux/pinctrl/pinctrl.h>
16a83c29e1SYixun Lan #include <linux/pinctrl/pinmux.h>
17a83c29e1SYixun Lan
18a83c29e1SYixun Lan #include "../core.h"
19a83c29e1SYixun Lan #include "../pinctrl-utils.h"
20a83c29e1SYixun Lan #include "../pinconf.h"
21a83c29e1SYixun Lan #include "../pinmux.h"
22a83c29e1SYixun Lan #include "pinctrl-k1.h"
23a83c29e1SYixun Lan
24a83c29e1SYixun Lan /*
25a83c29e1SYixun Lan * +---------+----------+-----------+--------+--------+----------+--------+
26a83c29e1SYixun Lan * | pull | drive | schmitter | slew | edge | strong | mux |
27a83c29e1SYixun Lan * | up/down | strength | trigger | rate | detect | pull | mode |
28a83c29e1SYixun Lan * +---------+----------+-----------+--------+--------+----------+--------+
29a83c29e1SYixun Lan * 3 bits 3 bits 2 bits 1 bit 3 bits 1 bit 3 bits
30a83c29e1SYixun Lan */
31a83c29e1SYixun Lan
32a83c29e1SYixun Lan #define PAD_MUX GENMASK(2, 0)
33a83c29e1SYixun Lan #define PAD_STRONG_PULL BIT(3)
34a83c29e1SYixun Lan #define PAD_EDGE_RISE BIT(4)
35a83c29e1SYixun Lan #define PAD_EDGE_FALL BIT(5)
36a83c29e1SYixun Lan #define PAD_EDGE_CLEAR BIT(6)
37a83c29e1SYixun Lan #define PAD_SLEW_RATE GENMASK(12, 11)
38a83c29e1SYixun Lan #define PAD_SLEW_RATE_EN BIT(7)
39a83c29e1SYixun Lan #define PAD_SCHMITT GENMASK(9, 8)
40a83c29e1SYixun Lan #define PAD_DRIVE GENMASK(12, 10)
41a83c29e1SYixun Lan #define PAD_PULLDOWN BIT(13)
42a83c29e1SYixun Lan #define PAD_PULLUP BIT(14)
43a83c29e1SYixun Lan #define PAD_PULL_EN BIT(15)
44a83c29e1SYixun Lan
45a83c29e1SYixun Lan struct spacemit_pin {
46a83c29e1SYixun Lan u16 pin;
47a83c29e1SYixun Lan u16 flags;
48a83c29e1SYixun Lan u8 gpiofunc;
49a83c29e1SYixun Lan };
50a83c29e1SYixun Lan
51a83c29e1SYixun Lan struct spacemit_pinctrl {
52a83c29e1SYixun Lan struct device *dev;
53a83c29e1SYixun Lan struct pinctrl_dev *pctl_dev;
54a83c29e1SYixun Lan const struct spacemit_pinctrl_data *data;
55a83c29e1SYixun Lan struct pinctrl_desc pdesc;
56a83c29e1SYixun Lan
57a83c29e1SYixun Lan struct mutex mutex;
58a83c29e1SYixun Lan raw_spinlock_t lock;
59a83c29e1SYixun Lan
60a83c29e1SYixun Lan void __iomem *regs;
61a83c29e1SYixun Lan };
62a83c29e1SYixun Lan
63a83c29e1SYixun Lan struct spacemit_pinctrl_data {
64a83c29e1SYixun Lan const struct pinctrl_pin_desc *pins;
65a83c29e1SYixun Lan const struct spacemit_pin *data;
66a83c29e1SYixun Lan u16 npins;
67a83c29e1SYixun Lan };
68a83c29e1SYixun Lan
69a83c29e1SYixun Lan struct spacemit_pin_mux_config {
70a83c29e1SYixun Lan const struct spacemit_pin *pin;
71a83c29e1SYixun Lan u32 config;
72a83c29e1SYixun Lan };
73a83c29e1SYixun Lan
74a83c29e1SYixun Lan struct spacemit_pin_drv_strength {
75a83c29e1SYixun Lan u8 val;
76a83c29e1SYixun Lan u32 mA;
77a83c29e1SYixun Lan };
78a83c29e1SYixun Lan
79a83c29e1SYixun Lan /* map pin id to pinctrl register offset, refer MFPR definition */
spacemit_pin_to_offset(unsigned int pin)80a83c29e1SYixun Lan static unsigned int spacemit_pin_to_offset(unsigned int pin)
81a83c29e1SYixun Lan {
82a83c29e1SYixun Lan unsigned int offset = 0;
83a83c29e1SYixun Lan
84a83c29e1SYixun Lan switch (pin) {
85a83c29e1SYixun Lan case 0 ... 85:
86a83c29e1SYixun Lan offset = pin + 1;
87a83c29e1SYixun Lan break;
88a83c29e1SYixun Lan case 86 ... 92:
89a83c29e1SYixun Lan offset = pin + 37;
90a83c29e1SYixun Lan break;
91a83c29e1SYixun Lan case 93 ... 97:
92a83c29e1SYixun Lan offset = pin + 24;
93a83c29e1SYixun Lan break;
94a83c29e1SYixun Lan case 98:
95a83c29e1SYixun Lan offset = 93;
96a83c29e1SYixun Lan break;
97a83c29e1SYixun Lan case 99:
98a83c29e1SYixun Lan offset = 92;
99a83c29e1SYixun Lan break;
100a83c29e1SYixun Lan case 100:
101a83c29e1SYixun Lan offset = 91;
102a83c29e1SYixun Lan break;
103a83c29e1SYixun Lan case 101:
104a83c29e1SYixun Lan offset = 90;
105a83c29e1SYixun Lan break;
106a83c29e1SYixun Lan case 102:
107a83c29e1SYixun Lan offset = 95;
108a83c29e1SYixun Lan break;
109a83c29e1SYixun Lan case 103:
110a83c29e1SYixun Lan offset = 94;
111a83c29e1SYixun Lan break;
112a83c29e1SYixun Lan case 104 ... 110:
113a83c29e1SYixun Lan offset = pin + 6;
114a83c29e1SYixun Lan break;
115a83c29e1SYixun Lan case 111 ... 127:
116a83c29e1SYixun Lan offset = pin + 20;
117a83c29e1SYixun Lan break;
118a83c29e1SYixun Lan default:
119a83c29e1SYixun Lan break;
120a83c29e1SYixun Lan }
121a83c29e1SYixun Lan
122a83c29e1SYixun Lan return offset << 2;
123a83c29e1SYixun Lan }
124a83c29e1SYixun Lan
spacemit_pin_to_reg(struct spacemit_pinctrl * pctrl,unsigned int pin)125a83c29e1SYixun Lan static inline void __iomem *spacemit_pin_to_reg(struct spacemit_pinctrl *pctrl,
126a83c29e1SYixun Lan unsigned int pin)
127a83c29e1SYixun Lan {
128a83c29e1SYixun Lan return pctrl->regs + spacemit_pin_to_offset(pin);
129a83c29e1SYixun Lan }
130a83c29e1SYixun Lan
spacemit_dt_get_pin(u32 value)131a83c29e1SYixun Lan static u16 spacemit_dt_get_pin(u32 value)
132a83c29e1SYixun Lan {
133a83c29e1SYixun Lan return value >> 16;
134a83c29e1SYixun Lan }
135a83c29e1SYixun Lan
spacemit_dt_get_pin_mux(u32 value)136a83c29e1SYixun Lan static u16 spacemit_dt_get_pin_mux(u32 value)
137a83c29e1SYixun Lan {
138a83c29e1SYixun Lan return value & GENMASK(15, 0);
139a83c29e1SYixun Lan }
140a83c29e1SYixun Lan
spacemit_get_pin(struct spacemit_pinctrl * pctrl,unsigned long pin)141a83c29e1SYixun Lan static const struct spacemit_pin *spacemit_get_pin(struct spacemit_pinctrl *pctrl,
142a83c29e1SYixun Lan unsigned long pin)
143a83c29e1SYixun Lan {
144a83c29e1SYixun Lan const struct spacemit_pin *pdata = pctrl->data->data;
145a83c29e1SYixun Lan int i;
146a83c29e1SYixun Lan
147a83c29e1SYixun Lan for (i = 0; i < pctrl->data->npins; i++) {
148a83c29e1SYixun Lan if (pin == pdata[i].pin)
149a83c29e1SYixun Lan return &pdata[i];
150a83c29e1SYixun Lan }
151a83c29e1SYixun Lan
152a83c29e1SYixun Lan return NULL;
153a83c29e1SYixun Lan }
154a83c29e1SYixun Lan
spacemit_to_pin_io_type(const struct spacemit_pin * pin)155a83c29e1SYixun Lan static inline enum spacemit_pin_io_type spacemit_to_pin_io_type(
156a83c29e1SYixun Lan const struct spacemit_pin *pin)
157a83c29e1SYixun Lan {
158a83c29e1SYixun Lan return K1_PIN_GET_IO_TYPE(pin->flags);
159a83c29e1SYixun Lan }
160a83c29e1SYixun Lan
161a83c29e1SYixun Lan /* External: IO voltage via external source, can be 1.8V or 3.3V */
162a83c29e1SYixun Lan static const char * const io_type_desc[] = {
163a83c29e1SYixun Lan "None",
164a83c29e1SYixun Lan "Fixed/1V8",
165a83c29e1SYixun Lan "Fixed/3V3",
166a83c29e1SYixun Lan "External",
167a83c29e1SYixun Lan };
168a83c29e1SYixun Lan
spacemit_pctrl_dbg_show(struct pinctrl_dev * pctldev,struct seq_file * seq,unsigned int pin)169a83c29e1SYixun Lan static void spacemit_pctrl_dbg_show(struct pinctrl_dev *pctldev,
170a83c29e1SYixun Lan struct seq_file *seq, unsigned int pin)
171a83c29e1SYixun Lan {
172a83c29e1SYixun Lan struct spacemit_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
173a83c29e1SYixun Lan const struct spacemit_pin *spin = spacemit_get_pin(pctrl, pin);
174a83c29e1SYixun Lan enum spacemit_pin_io_type type = spacemit_to_pin_io_type(spin);
175a83c29e1SYixun Lan void __iomem *reg;
176a83c29e1SYixun Lan u32 value;
177a83c29e1SYixun Lan
178a83c29e1SYixun Lan seq_printf(seq, "offset: 0x%04x ", spacemit_pin_to_offset(pin));
179a83c29e1SYixun Lan seq_printf(seq, "type: %s ", io_type_desc[type]);
180a83c29e1SYixun Lan
181a83c29e1SYixun Lan reg = spacemit_pin_to_reg(pctrl, pin);
182a83c29e1SYixun Lan value = readl(reg);
183a83c29e1SYixun Lan seq_printf(seq, "mux: %ld reg: 0x%04x", (value & PAD_MUX), value);
184a83c29e1SYixun Lan }
185a83c29e1SYixun Lan
186a83c29e1SYixun Lan /* use IO high level output current as the table */
187a83c29e1SYixun Lan static struct spacemit_pin_drv_strength spacemit_ds_1v8_tbl[4] = {
188a83c29e1SYixun Lan { 0, 11 },
189a83c29e1SYixun Lan { 2, 21 },
190a83c29e1SYixun Lan { 4, 32 },
191a83c29e1SYixun Lan { 6, 42 },
192a83c29e1SYixun Lan };
193a83c29e1SYixun Lan
194a83c29e1SYixun Lan static struct spacemit_pin_drv_strength spacemit_ds_3v3_tbl[8] = {
195a83c29e1SYixun Lan { 0, 7 },
196a83c29e1SYixun Lan { 2, 10 },
197a83c29e1SYixun Lan { 4, 13 },
198a83c29e1SYixun Lan { 6, 16 },
199a83c29e1SYixun Lan { 1, 19 },
200a83c29e1SYixun Lan { 3, 23 },
201a83c29e1SYixun Lan { 5, 26 },
202a83c29e1SYixun Lan { 7, 29 },
203a83c29e1SYixun Lan };
204a83c29e1SYixun Lan
spacemit_get_ds_value(struct spacemit_pin_drv_strength * tbl,u32 num,u32 mA)205a83c29e1SYixun Lan static inline u8 spacemit_get_ds_value(struct spacemit_pin_drv_strength *tbl,
206a83c29e1SYixun Lan u32 num, u32 mA)
207a83c29e1SYixun Lan {
208a83c29e1SYixun Lan int i;
209a83c29e1SYixun Lan
210a83c29e1SYixun Lan for (i = 0; i < num; i++)
211a83c29e1SYixun Lan if (mA <= tbl[i].mA)
212a83c29e1SYixun Lan return tbl[i].val;
213a83c29e1SYixun Lan
214a83c29e1SYixun Lan return tbl[num - 1].val;
215a83c29e1SYixun Lan }
216a83c29e1SYixun Lan
spacemit_get_ds_mA(struct spacemit_pin_drv_strength * tbl,u32 num,u32 val)217a83c29e1SYixun Lan static inline u32 spacemit_get_ds_mA(struct spacemit_pin_drv_strength *tbl,
218a83c29e1SYixun Lan u32 num, u32 val)
219a83c29e1SYixun Lan {
220a83c29e1SYixun Lan int i;
221a83c29e1SYixun Lan
222a83c29e1SYixun Lan for (i = 0; i < num; i++)
223a83c29e1SYixun Lan if (val == tbl[i].val)
224a83c29e1SYixun Lan return tbl[i].mA;
225a83c29e1SYixun Lan
226a83c29e1SYixun Lan return 0;
227a83c29e1SYixun Lan }
228a83c29e1SYixun Lan
spacemit_get_driver_strength(enum spacemit_pin_io_type type,u32 mA)229a83c29e1SYixun Lan static inline u8 spacemit_get_driver_strength(enum spacemit_pin_io_type type,
230a83c29e1SYixun Lan u32 mA)
231a83c29e1SYixun Lan {
232a83c29e1SYixun Lan switch (type) {
233a83c29e1SYixun Lan case IO_TYPE_1V8:
234a83c29e1SYixun Lan return spacemit_get_ds_value(spacemit_ds_1v8_tbl,
235a83c29e1SYixun Lan ARRAY_SIZE(spacemit_ds_1v8_tbl),
236a83c29e1SYixun Lan mA);
237a83c29e1SYixun Lan case IO_TYPE_3V3:
238a83c29e1SYixun Lan return spacemit_get_ds_value(spacemit_ds_3v3_tbl,
239a83c29e1SYixun Lan ARRAY_SIZE(spacemit_ds_3v3_tbl),
240a83c29e1SYixun Lan mA);
241a83c29e1SYixun Lan default:
242a83c29e1SYixun Lan return 0;
243a83c29e1SYixun Lan }
244a83c29e1SYixun Lan }
245a83c29e1SYixun Lan
spacemit_get_drive_strength_mA(enum spacemit_pin_io_type type,u32 value)246a83c29e1SYixun Lan static inline u32 spacemit_get_drive_strength_mA(enum spacemit_pin_io_type type,
247a83c29e1SYixun Lan u32 value)
248a83c29e1SYixun Lan {
249a83c29e1SYixun Lan switch (type) {
250a83c29e1SYixun Lan case IO_TYPE_1V8:
251a83c29e1SYixun Lan return spacemit_get_ds_mA(spacemit_ds_1v8_tbl,
252a83c29e1SYixun Lan ARRAY_SIZE(spacemit_ds_1v8_tbl),
253a83c29e1SYixun Lan value & 0x6);
254a83c29e1SYixun Lan case IO_TYPE_3V3:
255a83c29e1SYixun Lan return spacemit_get_ds_mA(spacemit_ds_3v3_tbl,
256a83c29e1SYixun Lan ARRAY_SIZE(spacemit_ds_3v3_tbl),
257a83c29e1SYixun Lan value);
258a83c29e1SYixun Lan default:
259a83c29e1SYixun Lan return 0;
260a83c29e1SYixun Lan }
261a83c29e1SYixun Lan }
262a83c29e1SYixun Lan
spacemit_pctrl_check_power(struct pinctrl_dev * pctldev,struct device_node * dn,struct spacemit_pin_mux_config * pinmuxs,int num_pins,const char * grpname)263a83c29e1SYixun Lan static int spacemit_pctrl_check_power(struct pinctrl_dev *pctldev,
264a83c29e1SYixun Lan struct device_node *dn,
265a83c29e1SYixun Lan struct spacemit_pin_mux_config *pinmuxs,
266a83c29e1SYixun Lan int num_pins, const char *grpname)
267a83c29e1SYixun Lan {
268a83c29e1SYixun Lan struct spacemit_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
269a83c29e1SYixun Lan struct device *dev = pctrl->dev;
270a83c29e1SYixun Lan enum spacemit_pin_io_type type;
271a83c29e1SYixun Lan u32 power = 0, i;
272a83c29e1SYixun Lan
273a83c29e1SYixun Lan of_property_read_u32(dn, "power-source", &power);
274a83c29e1SYixun Lan
275a83c29e1SYixun Lan for (i = 0; i < num_pins; i++) {
276a83c29e1SYixun Lan type = spacemit_to_pin_io_type(pinmuxs[i].pin);
277a83c29e1SYixun Lan
278a83c29e1SYixun Lan if (type != IO_TYPE_EXTERNAL)
279a83c29e1SYixun Lan continue;
280a83c29e1SYixun Lan
281a83c29e1SYixun Lan switch (power) {
282a83c29e1SYixun Lan case PIN_POWER_STATE_1V8:
283a83c29e1SYixun Lan case PIN_POWER_STATE_3V3:
284a83c29e1SYixun Lan break;
285a83c29e1SYixun Lan default:
286a83c29e1SYixun Lan dev_err(dev, "group %s has unsupported power\n",
287a83c29e1SYixun Lan grpname);
288a83c29e1SYixun Lan return -ENOTSUPP;
289a83c29e1SYixun Lan }
290a83c29e1SYixun Lan }
291a83c29e1SYixun Lan
292a83c29e1SYixun Lan return 0;
293a83c29e1SYixun Lan }
294a83c29e1SYixun Lan
spacemit_pctrl_dt_node_to_map(struct pinctrl_dev * pctldev,struct device_node * np,struct pinctrl_map ** maps,unsigned int * num_maps)295a83c29e1SYixun Lan static int spacemit_pctrl_dt_node_to_map(struct pinctrl_dev *pctldev,
296a83c29e1SYixun Lan struct device_node *np,
297a83c29e1SYixun Lan struct pinctrl_map **maps,
298a83c29e1SYixun Lan unsigned int *num_maps)
299a83c29e1SYixun Lan {
300a83c29e1SYixun Lan struct spacemit_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
301a83c29e1SYixun Lan struct device *dev = pctrl->dev;
302a83c29e1SYixun Lan struct device_node *child;
303a83c29e1SYixun Lan struct pinctrl_map *map;
304a83c29e1SYixun Lan const char **grpnames;
305a83c29e1SYixun Lan const char *grpname;
306a83c29e1SYixun Lan int ngroups = 0;
307a83c29e1SYixun Lan int nmaps = 0;
308a83c29e1SYixun Lan int ret;
309a83c29e1SYixun Lan
310a83c29e1SYixun Lan for_each_available_child_of_node(np, child)
311a83c29e1SYixun Lan ngroups += 1;
312a83c29e1SYixun Lan
313a83c29e1SYixun Lan grpnames = devm_kcalloc(dev, ngroups, sizeof(*grpnames), GFP_KERNEL);
314a83c29e1SYixun Lan if (!grpnames)
315a83c29e1SYixun Lan return -ENOMEM;
316a83c29e1SYixun Lan
317*5a18e2beSDan Carpenter map = kcalloc(ngroups * 2, sizeof(*map), GFP_KERNEL);
318a83c29e1SYixun Lan if (!map)
319a83c29e1SYixun Lan return -ENOMEM;
320a83c29e1SYixun Lan
321a83c29e1SYixun Lan ngroups = 0;
322a83c29e1SYixun Lan guard(mutex)(&pctrl->mutex);
323a83c29e1SYixun Lan for_each_available_child_of_node_scoped(np, child) {
324a83c29e1SYixun Lan struct spacemit_pin_mux_config *pinmuxs;
325a83c29e1SYixun Lan unsigned int config, *pins;
326a83c29e1SYixun Lan int i, npins;
327a83c29e1SYixun Lan
328a83c29e1SYixun Lan npins = of_property_count_u32_elems(child, "pinmux");
329a83c29e1SYixun Lan
330a83c29e1SYixun Lan if (npins < 1) {
331a83c29e1SYixun Lan dev_err(dev, "invalid pinctrl group %pOFn.%pOFn\n",
332a83c29e1SYixun Lan np, child);
333a83c29e1SYixun Lan return -EINVAL;
334a83c29e1SYixun Lan }
335a83c29e1SYixun Lan
336a83c29e1SYixun Lan grpname = devm_kasprintf(dev, GFP_KERNEL, "%pOFn.%pOFn",
337a83c29e1SYixun Lan np, child);
338a83c29e1SYixun Lan if (!grpname)
339a83c29e1SYixun Lan return -ENOMEM;
340a83c29e1SYixun Lan
341a83c29e1SYixun Lan grpnames[ngroups++] = grpname;
342a83c29e1SYixun Lan
343a83c29e1SYixun Lan pins = devm_kcalloc(dev, npins, sizeof(*pins), GFP_KERNEL);
344a83c29e1SYixun Lan if (!pins)
345a83c29e1SYixun Lan return -ENOMEM;
346a83c29e1SYixun Lan
347a83c29e1SYixun Lan pinmuxs = devm_kcalloc(dev, npins, sizeof(*pinmuxs), GFP_KERNEL);
348a83c29e1SYixun Lan if (!pinmuxs)
349a83c29e1SYixun Lan return -ENOMEM;
350a83c29e1SYixun Lan
351a83c29e1SYixun Lan for (i = 0; i < npins; i++) {
352a83c29e1SYixun Lan ret = of_property_read_u32_index(child, "pinmux",
353a83c29e1SYixun Lan i, &config);
354a83c29e1SYixun Lan
355a83c29e1SYixun Lan if (ret)
356a83c29e1SYixun Lan return -EINVAL;
357a83c29e1SYixun Lan
358a83c29e1SYixun Lan pins[i] = spacemit_dt_get_pin(config);
359a83c29e1SYixun Lan pinmuxs[i].config = config;
360a83c29e1SYixun Lan pinmuxs[i].pin = spacemit_get_pin(pctrl, pins[i]);
361a83c29e1SYixun Lan
362a83c29e1SYixun Lan if (!pinmuxs[i].pin)
363a83c29e1SYixun Lan return dev_err_probe(dev, -ENODEV, "failed to get pin %d\n", pins[i]);
364a83c29e1SYixun Lan }
365a83c29e1SYixun Lan
366a83c29e1SYixun Lan ret = spacemit_pctrl_check_power(pctldev, child, pinmuxs,
367a83c29e1SYixun Lan npins, grpname);
368a83c29e1SYixun Lan if (ret < 0)
369a83c29e1SYixun Lan return ret;
370a83c29e1SYixun Lan
371a83c29e1SYixun Lan map[nmaps].type = PIN_MAP_TYPE_MUX_GROUP;
372a83c29e1SYixun Lan map[nmaps].data.mux.function = np->name;
373a83c29e1SYixun Lan map[nmaps].data.mux.group = grpname;
374a83c29e1SYixun Lan nmaps += 1;
375a83c29e1SYixun Lan
376a83c29e1SYixun Lan ret = pinctrl_generic_add_group(pctldev, grpname,
377a83c29e1SYixun Lan pins, npins, pinmuxs);
378a83c29e1SYixun Lan if (ret < 0)
379a83c29e1SYixun Lan return dev_err_probe(dev, ret, "failed to add group %s: %d\n", grpname, ret);
380a83c29e1SYixun Lan
381a83c29e1SYixun Lan ret = pinconf_generic_parse_dt_config(child, pctldev,
382a83c29e1SYixun Lan &map[nmaps].data.configs.configs,
383a83c29e1SYixun Lan &map[nmaps].data.configs.num_configs);
384a83c29e1SYixun Lan if (ret)
385a83c29e1SYixun Lan return dev_err_probe(dev, ret, "failed to parse pin config of group %s\n",
386a83c29e1SYixun Lan grpname);
387a83c29e1SYixun Lan
388a83c29e1SYixun Lan if (map[nmaps].data.configs.num_configs == 0)
389a83c29e1SYixun Lan continue;
390a83c29e1SYixun Lan
391a83c29e1SYixun Lan map[nmaps].type = PIN_MAP_TYPE_CONFIGS_GROUP;
392a83c29e1SYixun Lan map[nmaps].data.configs.group_or_pin = grpname;
393a83c29e1SYixun Lan nmaps += 1;
394a83c29e1SYixun Lan }
395a83c29e1SYixun Lan
396a83c29e1SYixun Lan ret = pinmux_generic_add_function(pctldev, np->name,
397a83c29e1SYixun Lan grpnames, ngroups, NULL);
398a83c29e1SYixun Lan if (ret < 0) {
399a83c29e1SYixun Lan pinctrl_utils_free_map(pctldev, map, nmaps);
400a83c29e1SYixun Lan return dev_err_probe(dev, ret, "error adding function %s\n", np->name);
401a83c29e1SYixun Lan }
402a83c29e1SYixun Lan
403a83c29e1SYixun Lan *maps = map;
404a83c29e1SYixun Lan *num_maps = nmaps;
405a83c29e1SYixun Lan
406a83c29e1SYixun Lan return 0;
407a83c29e1SYixun Lan }
408a83c29e1SYixun Lan
409a83c29e1SYixun Lan static const struct pinctrl_ops spacemit_pctrl_ops = {
410a83c29e1SYixun Lan .get_groups_count = pinctrl_generic_get_group_count,
411a83c29e1SYixun Lan .get_group_name = pinctrl_generic_get_group_name,
412a83c29e1SYixun Lan .get_group_pins = pinctrl_generic_get_group_pins,
413a83c29e1SYixun Lan .pin_dbg_show = spacemit_pctrl_dbg_show,
414a83c29e1SYixun Lan .dt_node_to_map = spacemit_pctrl_dt_node_to_map,
415a83c29e1SYixun Lan .dt_free_map = pinctrl_utils_free_map,
416a83c29e1SYixun Lan };
417a83c29e1SYixun Lan
spacemit_pmx_set_mux(struct pinctrl_dev * pctldev,unsigned int fsel,unsigned int gsel)418a83c29e1SYixun Lan static int spacemit_pmx_set_mux(struct pinctrl_dev *pctldev,
419a83c29e1SYixun Lan unsigned int fsel, unsigned int gsel)
420a83c29e1SYixun Lan {
421a83c29e1SYixun Lan struct spacemit_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
422a83c29e1SYixun Lan const struct group_desc *group;
423a83c29e1SYixun Lan const struct spacemit_pin_mux_config *configs;
424a83c29e1SYixun Lan unsigned int i, mux;
425a83c29e1SYixun Lan void __iomem *reg;
426a83c29e1SYixun Lan
427a83c29e1SYixun Lan group = pinctrl_generic_get_group(pctldev, gsel);
428a83c29e1SYixun Lan if (!group)
429a83c29e1SYixun Lan return -EINVAL;
430a83c29e1SYixun Lan
431a83c29e1SYixun Lan configs = group->data;
432a83c29e1SYixun Lan
433a83c29e1SYixun Lan for (i = 0; i < group->grp.npins; i++) {
434a83c29e1SYixun Lan const struct spacemit_pin *spin = configs[i].pin;
435a83c29e1SYixun Lan u32 value = configs[i].config;
436a83c29e1SYixun Lan
437a83c29e1SYixun Lan reg = spacemit_pin_to_reg(pctrl, spin->pin);
438a83c29e1SYixun Lan mux = spacemit_dt_get_pin_mux(value);
439a83c29e1SYixun Lan
440a83c29e1SYixun Lan guard(raw_spinlock_irqsave)(&pctrl->lock);
441a83c29e1SYixun Lan value = readl_relaxed(reg) & ~PAD_MUX;
442a83c29e1SYixun Lan writel_relaxed(mux | value, reg);
443a83c29e1SYixun Lan }
444a83c29e1SYixun Lan
445a83c29e1SYixun Lan return 0;
446a83c29e1SYixun Lan }
447a83c29e1SYixun Lan
spacemit_request_gpio(struct pinctrl_dev * pctldev,struct pinctrl_gpio_range * range,unsigned int pin)448a83c29e1SYixun Lan static int spacemit_request_gpio(struct pinctrl_dev *pctldev,
449a83c29e1SYixun Lan struct pinctrl_gpio_range *range,
450a83c29e1SYixun Lan unsigned int pin)
451a83c29e1SYixun Lan {
452a83c29e1SYixun Lan struct spacemit_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
453a83c29e1SYixun Lan const struct spacemit_pin *spin = spacemit_get_pin(pctrl, pin);
454a83c29e1SYixun Lan void __iomem *reg;
455a83c29e1SYixun Lan
456a83c29e1SYixun Lan reg = spacemit_pin_to_reg(pctrl, pin);
457a83c29e1SYixun Lan guard(raw_spinlock_irqsave)(&pctrl->lock);
458a83c29e1SYixun Lan writel_relaxed(spin->gpiofunc, reg);
459a83c29e1SYixun Lan
460a83c29e1SYixun Lan return 0;
461a83c29e1SYixun Lan }
462a83c29e1SYixun Lan
463a83c29e1SYixun Lan static const struct pinmux_ops spacemit_pmx_ops = {
464a83c29e1SYixun Lan .get_functions_count = pinmux_generic_get_function_count,
465a83c29e1SYixun Lan .get_function_name = pinmux_generic_get_function_name,
466a83c29e1SYixun Lan .get_function_groups = pinmux_generic_get_function_groups,
467a83c29e1SYixun Lan .set_mux = spacemit_pmx_set_mux,
468a83c29e1SYixun Lan .gpio_request_enable = spacemit_request_gpio,
469a83c29e1SYixun Lan .strict = true,
470a83c29e1SYixun Lan };
471a83c29e1SYixun Lan
spacemit_pinconf_get(struct pinctrl_dev * pctldev,unsigned int pin,unsigned long * config)472a83c29e1SYixun Lan static int spacemit_pinconf_get(struct pinctrl_dev *pctldev,
473a83c29e1SYixun Lan unsigned int pin, unsigned long *config)
474a83c29e1SYixun Lan {
475a83c29e1SYixun Lan struct spacemit_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
476a83c29e1SYixun Lan int param = pinconf_to_config_param(*config);
477a83c29e1SYixun Lan u32 value, arg = 0;
478a83c29e1SYixun Lan
479a83c29e1SYixun Lan if (!pin)
480a83c29e1SYixun Lan return -EINVAL;
481a83c29e1SYixun Lan
482a83c29e1SYixun Lan value = readl(spacemit_pin_to_reg(pctrl, pin));
483a83c29e1SYixun Lan
484a83c29e1SYixun Lan switch (param) {
485a83c29e1SYixun Lan case PIN_CONFIG_SLEW_RATE:
486a83c29e1SYixun Lan if (FIELD_GET(PAD_SLEW_RATE_EN, value))
487a83c29e1SYixun Lan arg = FIELD_GET(PAD_SLEW_RATE, value) + 2;
488a83c29e1SYixun Lan else
489a83c29e1SYixun Lan arg = 0;
490a83c29e1SYixun Lan break;
491a83c29e1SYixun Lan default:
492a83c29e1SYixun Lan return -EINVAL;
493a83c29e1SYixun Lan }
494a83c29e1SYixun Lan
495a83c29e1SYixun Lan *config = pinconf_to_config_packed(param, arg);
496a83c29e1SYixun Lan
497a83c29e1SYixun Lan return 0;
498a83c29e1SYixun Lan }
499a83c29e1SYixun Lan
500a83c29e1SYixun Lan #define ENABLE_DRV_STRENGTH BIT(1)
501a83c29e1SYixun Lan #define ENABLE_SLEW_RATE BIT(2)
spacemit_pinconf_generate_config(const struct spacemit_pin * spin,unsigned long * configs,unsigned int num_configs,u32 * value)502a83c29e1SYixun Lan static int spacemit_pinconf_generate_config(const struct spacemit_pin *spin,
503a83c29e1SYixun Lan unsigned long *configs,
504a83c29e1SYixun Lan unsigned int num_configs,
505a83c29e1SYixun Lan u32 *value)
506a83c29e1SYixun Lan {
507a83c29e1SYixun Lan enum spacemit_pin_io_type type;
508a83c29e1SYixun Lan int i, param;
509a83c29e1SYixun Lan u32 v = 0, voltage = 0, arg, val;
510a83c29e1SYixun Lan u32 flag = 0, drv_strength, slew_rate;
511a83c29e1SYixun Lan
512a83c29e1SYixun Lan if (!spin)
513a83c29e1SYixun Lan return -EINVAL;
514a83c29e1SYixun Lan
515a83c29e1SYixun Lan for (i = 0; i < num_configs; i++) {
516a83c29e1SYixun Lan param = pinconf_to_config_param(configs[i]);
517a83c29e1SYixun Lan arg = pinconf_to_config_argument(configs[i]);
518a83c29e1SYixun Lan
519a83c29e1SYixun Lan switch (param) {
520a83c29e1SYixun Lan case PIN_CONFIG_BIAS_DISABLE:
521a83c29e1SYixun Lan v &= ~(PAD_PULL_EN | PAD_PULLDOWN | PAD_PULLUP);
522a83c29e1SYixun Lan v &= ~PAD_STRONG_PULL;
523a83c29e1SYixun Lan break;
524a83c29e1SYixun Lan case PIN_CONFIG_BIAS_PULL_DOWN:
525a83c29e1SYixun Lan v &= ~(PAD_PULLUP | PAD_STRONG_PULL);
526a83c29e1SYixun Lan v |= (PAD_PULL_EN | PAD_PULLDOWN);
527a83c29e1SYixun Lan break;
528a83c29e1SYixun Lan case PIN_CONFIG_BIAS_PULL_UP:
529a83c29e1SYixun Lan v &= ~PAD_PULLDOWN;
530a83c29e1SYixun Lan v |= (PAD_PULL_EN | PAD_PULLUP);
531a83c29e1SYixun Lan
532a83c29e1SYixun Lan if (arg == 1)
533a83c29e1SYixun Lan v |= PAD_STRONG_PULL;
534a83c29e1SYixun Lan break;
535a83c29e1SYixun Lan case PIN_CONFIG_DRIVE_STRENGTH:
536a83c29e1SYixun Lan flag |= ENABLE_DRV_STRENGTH;
537a83c29e1SYixun Lan drv_strength = arg;
538a83c29e1SYixun Lan break;
539a83c29e1SYixun Lan case PIN_CONFIG_INPUT_SCHMITT:
540a83c29e1SYixun Lan v &= ~PAD_SCHMITT;
541a83c29e1SYixun Lan v |= FIELD_PREP(PAD_SCHMITT, arg);
542a83c29e1SYixun Lan break;
543a83c29e1SYixun Lan case PIN_CONFIG_POWER_SOURCE:
544a83c29e1SYixun Lan voltage = arg;
545a83c29e1SYixun Lan break;
546a83c29e1SYixun Lan case PIN_CONFIG_SLEW_RATE:
547a83c29e1SYixun Lan if (arg) {
548a83c29e1SYixun Lan flag |= ENABLE_SLEW_RATE;
549a83c29e1SYixun Lan v |= PAD_SLEW_RATE_EN;
550a83c29e1SYixun Lan slew_rate = arg;
551a83c29e1SYixun Lan } else {
552a83c29e1SYixun Lan v &= ~PAD_SLEW_RATE_EN;
553a83c29e1SYixun Lan }
554a83c29e1SYixun Lan break;
555a83c29e1SYixun Lan default:
556a83c29e1SYixun Lan return -EINVAL;
557a83c29e1SYixun Lan }
558a83c29e1SYixun Lan }
559a83c29e1SYixun Lan
560a83c29e1SYixun Lan if (flag & ENABLE_DRV_STRENGTH) {
561a83c29e1SYixun Lan type = spacemit_to_pin_io_type(spin);
562a83c29e1SYixun Lan
563a83c29e1SYixun Lan /* fix external io type */
564a83c29e1SYixun Lan if (type == IO_TYPE_EXTERNAL) {
565a83c29e1SYixun Lan switch (voltage) {
566a83c29e1SYixun Lan case 1800:
567a83c29e1SYixun Lan type = IO_TYPE_1V8;
568a83c29e1SYixun Lan break;
569a83c29e1SYixun Lan case 3300:
570a83c29e1SYixun Lan type = IO_TYPE_3V3;
571a83c29e1SYixun Lan break;
572a83c29e1SYixun Lan default:
573a83c29e1SYixun Lan return -EINVAL;
574a83c29e1SYixun Lan }
575a83c29e1SYixun Lan }
576a83c29e1SYixun Lan
577a83c29e1SYixun Lan val = spacemit_get_driver_strength(type, drv_strength);
578a83c29e1SYixun Lan
579a83c29e1SYixun Lan v &= ~PAD_DRIVE;
580a83c29e1SYixun Lan v |= FIELD_PREP(PAD_DRIVE, val);
581a83c29e1SYixun Lan }
582a83c29e1SYixun Lan
583a83c29e1SYixun Lan if (flag & ENABLE_SLEW_RATE) {
584a83c29e1SYixun Lan /* check, driver strength & slew rate */
585a83c29e1SYixun Lan if (flag & ENABLE_DRV_STRENGTH) {
586a83c29e1SYixun Lan val = FIELD_GET(PAD_SLEW_RATE, v) + 2;
587a83c29e1SYixun Lan if (slew_rate > 1 && slew_rate != val) {
588a83c29e1SYixun Lan pr_err("slew rate conflict with drive strength\n");
589a83c29e1SYixun Lan return -EINVAL;
590a83c29e1SYixun Lan }
591a83c29e1SYixun Lan } else {
592a83c29e1SYixun Lan v &= ~PAD_SLEW_RATE;
593a83c29e1SYixun Lan slew_rate = slew_rate > 1 ? (slew_rate - 2) : 0;
594a83c29e1SYixun Lan v |= FIELD_PREP(PAD_SLEW_RATE, slew_rate);
595a83c29e1SYixun Lan }
596a83c29e1SYixun Lan }
597a83c29e1SYixun Lan
598a83c29e1SYixun Lan *value = v;
599a83c29e1SYixun Lan
600a83c29e1SYixun Lan return 0;
601a83c29e1SYixun Lan }
602a83c29e1SYixun Lan
spacemit_pin_set_config(struct spacemit_pinctrl * pctrl,unsigned int pin,u32 value)603a83c29e1SYixun Lan static int spacemit_pin_set_config(struct spacemit_pinctrl *pctrl,
604a83c29e1SYixun Lan unsigned int pin, u32 value)
605a83c29e1SYixun Lan {
606a83c29e1SYixun Lan const struct spacemit_pin *spin = spacemit_get_pin(pctrl, pin);
607a83c29e1SYixun Lan void __iomem *reg;
608a83c29e1SYixun Lan unsigned int mux;
609a83c29e1SYixun Lan
610a83c29e1SYixun Lan if (!pin)
611a83c29e1SYixun Lan return -EINVAL;
612a83c29e1SYixun Lan
613a83c29e1SYixun Lan reg = spacemit_pin_to_reg(pctrl, spin->pin);
614a83c29e1SYixun Lan
615a83c29e1SYixun Lan guard(raw_spinlock_irqsave)(&pctrl->lock);
616a83c29e1SYixun Lan mux = readl_relaxed(reg) & PAD_MUX;
617a83c29e1SYixun Lan writel_relaxed(mux | value, reg);
618a83c29e1SYixun Lan
619a83c29e1SYixun Lan return 0;
620a83c29e1SYixun Lan }
621a83c29e1SYixun Lan
spacemit_pinconf_set(struct pinctrl_dev * pctldev,unsigned int pin,unsigned long * configs,unsigned int num_configs)622a83c29e1SYixun Lan static int spacemit_pinconf_set(struct pinctrl_dev *pctldev,
623a83c29e1SYixun Lan unsigned int pin, unsigned long *configs,
624a83c29e1SYixun Lan unsigned int num_configs)
625a83c29e1SYixun Lan {
626a83c29e1SYixun Lan struct spacemit_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
627a83c29e1SYixun Lan const struct spacemit_pin *spin = spacemit_get_pin(pctrl, pin);
628a83c29e1SYixun Lan u32 value;
629a83c29e1SYixun Lan
630a83c29e1SYixun Lan if (spacemit_pinconf_generate_config(spin, configs, num_configs, &value))
631a83c29e1SYixun Lan return -EINVAL;
632a83c29e1SYixun Lan
633a83c29e1SYixun Lan return spacemit_pin_set_config(pctrl, pin, value);
634a83c29e1SYixun Lan }
635a83c29e1SYixun Lan
spacemit_pinconf_group_set(struct pinctrl_dev * pctldev,unsigned int gsel,unsigned long * configs,unsigned int num_configs)636a83c29e1SYixun Lan static int spacemit_pinconf_group_set(struct pinctrl_dev *pctldev,
637a83c29e1SYixun Lan unsigned int gsel,
638a83c29e1SYixun Lan unsigned long *configs,
639a83c29e1SYixun Lan unsigned int num_configs)
640a83c29e1SYixun Lan {
641a83c29e1SYixun Lan struct spacemit_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
642a83c29e1SYixun Lan const struct spacemit_pin *spin;
643a83c29e1SYixun Lan const struct group_desc *group;
644a83c29e1SYixun Lan u32 value;
645a83c29e1SYixun Lan int i;
646a83c29e1SYixun Lan
647a83c29e1SYixun Lan group = pinctrl_generic_get_group(pctldev, gsel);
648a83c29e1SYixun Lan if (!group)
649a83c29e1SYixun Lan return -EINVAL;
650a83c29e1SYixun Lan
651a83c29e1SYixun Lan spin = spacemit_get_pin(pctrl, group->grp.pins[0]);
652a83c29e1SYixun Lan if (spacemit_pinconf_generate_config(spin, configs, num_configs, &value))
653a83c29e1SYixun Lan return -EINVAL;
654a83c29e1SYixun Lan
655a83c29e1SYixun Lan for (i = 0; i < group->grp.npins; i++)
656a83c29e1SYixun Lan spacemit_pin_set_config(pctrl, group->grp.pins[i], value);
657a83c29e1SYixun Lan
658a83c29e1SYixun Lan return 0;
659a83c29e1SYixun Lan }
660a83c29e1SYixun Lan
spacemit_pinconf_dbg_pull(struct seq_file * seq,unsigned int value)661a83c29e1SYixun Lan static void spacemit_pinconf_dbg_pull(struct seq_file *seq, unsigned int value)
662a83c29e1SYixun Lan {
663a83c29e1SYixun Lan u32 normal, strong;
664a83c29e1SYixun Lan
665a83c29e1SYixun Lan if (!FIELD_GET(PAD_PULL_EN, value)) {
666a83c29e1SYixun Lan seq_puts(seq, ", bias pull disabled");
667a83c29e1SYixun Lan return;
668a83c29e1SYixun Lan }
669a83c29e1SYixun Lan
670a83c29e1SYixun Lan if (FIELD_GET(PAD_PULLDOWN, value))
671a83c29e1SYixun Lan seq_puts(seq, ", bias pull down");
672a83c29e1SYixun Lan
673a83c29e1SYixun Lan normal = FIELD_GET(PAD_PULLUP, value);
674a83c29e1SYixun Lan strong = FIELD_GET(PAD_STRONG_PULL, value);
675a83c29e1SYixun Lan
676a83c29e1SYixun Lan if (normal && strong)
677a83c29e1SYixun Lan seq_puts(seq, ", bias strong pull up");
678a83c29e1SYixun Lan else if (normal)
679a83c29e1SYixun Lan seq_puts(seq, ", bias normal pull up");
680a83c29e1SYixun Lan }
681a83c29e1SYixun Lan
spacemit_pinconf_dbg_show(struct pinctrl_dev * pctldev,struct seq_file * seq,unsigned int pin)682a83c29e1SYixun Lan static void spacemit_pinconf_dbg_show(struct pinctrl_dev *pctldev,
683a83c29e1SYixun Lan struct seq_file *seq, unsigned int pin)
684a83c29e1SYixun Lan {
685a83c29e1SYixun Lan struct spacemit_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
686a83c29e1SYixun Lan const struct spacemit_pin *spin = spacemit_get_pin(pctrl, pin);
687a83c29e1SYixun Lan enum spacemit_pin_io_type type = spacemit_to_pin_io_type(spin);
688a83c29e1SYixun Lan void __iomem *reg = spacemit_pin_to_reg(pctrl, pin);
689a83c29e1SYixun Lan u32 value, tmp, mA;
690a83c29e1SYixun Lan
691a83c29e1SYixun Lan value = readl(reg);
692a83c29e1SYixun Lan spacemit_pinconf_dbg_pull(seq, value);
693a83c29e1SYixun Lan
694a83c29e1SYixun Lan seq_printf(seq, ", io type (%s)", io_type_desc[type]);
695a83c29e1SYixun Lan
696a83c29e1SYixun Lan tmp = FIELD_GET(PAD_DRIVE, value);
697a83c29e1SYixun Lan if (type == IO_TYPE_1V8 || type == IO_TYPE_3V3) {
698a83c29e1SYixun Lan mA = spacemit_get_drive_strength_mA(type, tmp);
699a83c29e1SYixun Lan seq_printf(seq, ", drive strength (%d mA)", mA);
700a83c29e1SYixun Lan }
701a83c29e1SYixun Lan
702a83c29e1SYixun Lan /* drive strength depend on power source, so show all values */
703a83c29e1SYixun Lan if (type == IO_TYPE_EXTERNAL)
704a83c29e1SYixun Lan seq_printf(seq, ", drive strength (%d or %d mA)",
705a83c29e1SYixun Lan spacemit_get_drive_strength_mA(IO_TYPE_1V8, tmp),
706a83c29e1SYixun Lan spacemit_get_drive_strength_mA(IO_TYPE_3V3, tmp));
707a83c29e1SYixun Lan
708a83c29e1SYixun Lan seq_printf(seq, ", register (0x%04x)\n", value);
709a83c29e1SYixun Lan }
710a83c29e1SYixun Lan
711a83c29e1SYixun Lan static const struct pinconf_ops spacemit_pinconf_ops = {
712a83c29e1SYixun Lan .pin_config_get = spacemit_pinconf_get,
713a83c29e1SYixun Lan .pin_config_set = spacemit_pinconf_set,
714a83c29e1SYixun Lan .pin_config_group_set = spacemit_pinconf_group_set,
715a83c29e1SYixun Lan .pin_config_dbg_show = spacemit_pinconf_dbg_show,
716a83c29e1SYixun Lan .is_generic = true,
717a83c29e1SYixun Lan };
718a83c29e1SYixun Lan
spacemit_pinctrl_probe(struct platform_device * pdev)719a83c29e1SYixun Lan static int spacemit_pinctrl_probe(struct platform_device *pdev)
720a83c29e1SYixun Lan {
721a83c29e1SYixun Lan struct device *dev = &pdev->dev;
722a83c29e1SYixun Lan struct spacemit_pinctrl *pctrl;
723a83c29e1SYixun Lan const struct spacemit_pinctrl_data *pctrl_data;
724a83c29e1SYixun Lan int ret;
725a83c29e1SYixun Lan
726a83c29e1SYixun Lan pctrl_data = device_get_match_data(dev);
727a83c29e1SYixun Lan if (!pctrl_data)
728a83c29e1SYixun Lan return -ENODEV;
729a83c29e1SYixun Lan
730a83c29e1SYixun Lan if (pctrl_data->npins == 0)
731a83c29e1SYixun Lan return dev_err_probe(dev, -EINVAL, "invalid pin data\n");
732a83c29e1SYixun Lan
733a83c29e1SYixun Lan pctrl = devm_kzalloc(dev, sizeof(*pctrl), GFP_KERNEL);
734a83c29e1SYixun Lan if (!pctrl)
735a83c29e1SYixun Lan return -ENOMEM;
736a83c29e1SYixun Lan
737a83c29e1SYixun Lan pctrl->regs = devm_platform_ioremap_resource(pdev, 0);
738a83c29e1SYixun Lan if (IS_ERR(pctrl->regs))
739a83c29e1SYixun Lan return PTR_ERR(pctrl->regs);
740a83c29e1SYixun Lan
741a83c29e1SYixun Lan pctrl->pdesc.name = dev_name(dev);
742a83c29e1SYixun Lan pctrl->pdesc.pins = pctrl_data->pins;
743a83c29e1SYixun Lan pctrl->pdesc.npins = pctrl_data->npins;
744a83c29e1SYixun Lan pctrl->pdesc.pctlops = &spacemit_pctrl_ops;
745a83c29e1SYixun Lan pctrl->pdesc.pmxops = &spacemit_pmx_ops;
746a83c29e1SYixun Lan pctrl->pdesc.confops = &spacemit_pinconf_ops;
747a83c29e1SYixun Lan pctrl->pdesc.owner = THIS_MODULE;
748a83c29e1SYixun Lan
749a83c29e1SYixun Lan pctrl->data = pctrl_data;
750a83c29e1SYixun Lan pctrl->dev = dev;
751a83c29e1SYixun Lan raw_spin_lock_init(&pctrl->lock);
752a83c29e1SYixun Lan mutex_init(&pctrl->mutex);
753a83c29e1SYixun Lan
754a83c29e1SYixun Lan platform_set_drvdata(pdev, pctrl);
755a83c29e1SYixun Lan
756a83c29e1SYixun Lan ret = devm_pinctrl_register_and_init(dev, &pctrl->pdesc,
757a83c29e1SYixun Lan pctrl, &pctrl->pctl_dev);
758a83c29e1SYixun Lan if (ret)
759a83c29e1SYixun Lan return dev_err_probe(dev, ret,
760a83c29e1SYixun Lan "fail to register pinctrl driver\n");
761a83c29e1SYixun Lan
762a83c29e1SYixun Lan return pinctrl_enable(pctrl->pctl_dev);
763a83c29e1SYixun Lan }
764a83c29e1SYixun Lan
765a83c29e1SYixun Lan static const struct pinctrl_pin_desc k1_pin_desc[] = {
766a83c29e1SYixun Lan PINCTRL_PIN(0, "GPIO_00"),
767a83c29e1SYixun Lan PINCTRL_PIN(1, "GPIO_01"),
768a83c29e1SYixun Lan PINCTRL_PIN(2, "GPIO_02"),
769a83c29e1SYixun Lan PINCTRL_PIN(3, "GPIO_03"),
770a83c29e1SYixun Lan PINCTRL_PIN(4, "GPIO_04"),
771a83c29e1SYixun Lan PINCTRL_PIN(5, "GPIO_05"),
772a83c29e1SYixun Lan PINCTRL_PIN(6, "GPIO_06"),
773a83c29e1SYixun Lan PINCTRL_PIN(7, "GPIO_07"),
774a83c29e1SYixun Lan PINCTRL_PIN(8, "GPIO_08"),
775a83c29e1SYixun Lan PINCTRL_PIN(9, "GPIO_09"),
776a83c29e1SYixun Lan PINCTRL_PIN(10, "GPIO_10"),
777a83c29e1SYixun Lan PINCTRL_PIN(11, "GPIO_11"),
778a83c29e1SYixun Lan PINCTRL_PIN(12, "GPIO_12"),
779a83c29e1SYixun Lan PINCTRL_PIN(13, "GPIO_13"),
780a83c29e1SYixun Lan PINCTRL_PIN(14, "GPIO_14"),
781a83c29e1SYixun Lan PINCTRL_PIN(15, "GPIO_15"),
782a83c29e1SYixun Lan PINCTRL_PIN(16, "GPIO_16"),
783a83c29e1SYixun Lan PINCTRL_PIN(17, "GPIO_17"),
784a83c29e1SYixun Lan PINCTRL_PIN(18, "GPIO_18"),
785a83c29e1SYixun Lan PINCTRL_PIN(19, "GPIO_19"),
786a83c29e1SYixun Lan PINCTRL_PIN(20, "GPIO_20"),
787a83c29e1SYixun Lan PINCTRL_PIN(21, "GPIO_21"),
788a83c29e1SYixun Lan PINCTRL_PIN(22, "GPIO_22"),
789a83c29e1SYixun Lan PINCTRL_PIN(23, "GPIO_23"),
790a83c29e1SYixun Lan PINCTRL_PIN(24, "GPIO_24"),
791a83c29e1SYixun Lan PINCTRL_PIN(25, "GPIO_25"),
792a83c29e1SYixun Lan PINCTRL_PIN(26, "GPIO_26"),
793a83c29e1SYixun Lan PINCTRL_PIN(27, "GPIO_27"),
794a83c29e1SYixun Lan PINCTRL_PIN(28, "GPIO_28"),
795a83c29e1SYixun Lan PINCTRL_PIN(29, "GPIO_29"),
796a83c29e1SYixun Lan PINCTRL_PIN(30, "GPIO_30"),
797a83c29e1SYixun Lan PINCTRL_PIN(31, "GPIO_31"),
798a83c29e1SYixun Lan PINCTRL_PIN(32, "GPIO_32"),
799a83c29e1SYixun Lan PINCTRL_PIN(33, "GPIO_33"),
800a83c29e1SYixun Lan PINCTRL_PIN(34, "GPIO_34"),
801a83c29e1SYixun Lan PINCTRL_PIN(35, "GPIO_35"),
802a83c29e1SYixun Lan PINCTRL_PIN(36, "GPIO_36"),
803a83c29e1SYixun Lan PINCTRL_PIN(37, "GPIO_37"),
804a83c29e1SYixun Lan PINCTRL_PIN(38, "GPIO_38"),
805a83c29e1SYixun Lan PINCTRL_PIN(39, "GPIO_39"),
806a83c29e1SYixun Lan PINCTRL_PIN(40, "GPIO_40"),
807a83c29e1SYixun Lan PINCTRL_PIN(41, "GPIO_41"),
808a83c29e1SYixun Lan PINCTRL_PIN(42, "GPIO_42"),
809a83c29e1SYixun Lan PINCTRL_PIN(43, "GPIO_43"),
810a83c29e1SYixun Lan PINCTRL_PIN(44, "GPIO_44"),
811a83c29e1SYixun Lan PINCTRL_PIN(45, "GPIO_45"),
812a83c29e1SYixun Lan PINCTRL_PIN(46, "GPIO_46"),
813a83c29e1SYixun Lan PINCTRL_PIN(47, "GPIO_47"),
814a83c29e1SYixun Lan PINCTRL_PIN(48, "GPIO_48"),
815a83c29e1SYixun Lan PINCTRL_PIN(49, "GPIO_49"),
816a83c29e1SYixun Lan PINCTRL_PIN(50, "GPIO_50"),
817a83c29e1SYixun Lan PINCTRL_PIN(51, "GPIO_51"),
818a83c29e1SYixun Lan PINCTRL_PIN(52, "GPIO_52"),
819a83c29e1SYixun Lan PINCTRL_PIN(53, "GPIO_53"),
820a83c29e1SYixun Lan PINCTRL_PIN(54, "GPIO_54"),
821a83c29e1SYixun Lan PINCTRL_PIN(55, "GPIO_55"),
822a83c29e1SYixun Lan PINCTRL_PIN(56, "GPIO_56"),
823a83c29e1SYixun Lan PINCTRL_PIN(57, "GPIO_57"),
824a83c29e1SYixun Lan PINCTRL_PIN(58, "GPIO_58"),
825a83c29e1SYixun Lan PINCTRL_PIN(59, "GPIO_59"),
826a83c29e1SYixun Lan PINCTRL_PIN(60, "GPIO_60"),
827a83c29e1SYixun Lan PINCTRL_PIN(61, "GPIO_61"),
828a83c29e1SYixun Lan PINCTRL_PIN(62, "GPIO_62"),
829a83c29e1SYixun Lan PINCTRL_PIN(63, "GPIO_63"),
830a83c29e1SYixun Lan PINCTRL_PIN(64, "GPIO_64"),
831a83c29e1SYixun Lan PINCTRL_PIN(65, "GPIO_65"),
832a83c29e1SYixun Lan PINCTRL_PIN(66, "GPIO_66"),
833a83c29e1SYixun Lan PINCTRL_PIN(67, "GPIO_67"),
834a83c29e1SYixun Lan PINCTRL_PIN(68, "GPIO_68"),
835a83c29e1SYixun Lan PINCTRL_PIN(69, "GPIO_69"),
836a83c29e1SYixun Lan PINCTRL_PIN(70, "GPIO_70/PRI_DTI"),
837a83c29e1SYixun Lan PINCTRL_PIN(71, "GPIO_71/PRI_TMS"),
838a83c29e1SYixun Lan PINCTRL_PIN(72, "GPIO_72/PRI_TCK"),
839a83c29e1SYixun Lan PINCTRL_PIN(73, "GPIO_73/PRI_TDO"),
840a83c29e1SYixun Lan PINCTRL_PIN(74, "GPIO_74"),
841a83c29e1SYixun Lan PINCTRL_PIN(75, "GPIO_75"),
842a83c29e1SYixun Lan PINCTRL_PIN(76, "GPIO_76"),
843a83c29e1SYixun Lan PINCTRL_PIN(77, "GPIO_77"),
844a83c29e1SYixun Lan PINCTRL_PIN(78, "GPIO_78"),
845a83c29e1SYixun Lan PINCTRL_PIN(79, "GPIO_79"),
846a83c29e1SYixun Lan PINCTRL_PIN(80, "GPIO_80"),
847a83c29e1SYixun Lan PINCTRL_PIN(81, "GPIO_81"),
848a83c29e1SYixun Lan PINCTRL_PIN(82, "GPIO_82"),
849a83c29e1SYixun Lan PINCTRL_PIN(83, "GPIO_83"),
850a83c29e1SYixun Lan PINCTRL_PIN(84, "GPIO_84"),
851a83c29e1SYixun Lan PINCTRL_PIN(85, "GPIO_85"),
852a83c29e1SYixun Lan PINCTRL_PIN(86, "GPIO_86"),
853a83c29e1SYixun Lan PINCTRL_PIN(87, "GPIO_87"),
854a83c29e1SYixun Lan PINCTRL_PIN(88, "GPIO_88"),
855a83c29e1SYixun Lan PINCTRL_PIN(89, "GPIO_89"),
856a83c29e1SYixun Lan PINCTRL_PIN(90, "GPIO_90"),
857a83c29e1SYixun Lan PINCTRL_PIN(91, "GPIO_91"),
858a83c29e1SYixun Lan PINCTRL_PIN(92, "GPIO_92"),
859a83c29e1SYixun Lan PINCTRL_PIN(93, "GPIO_93/PWR_SCL"),
860a83c29e1SYixun Lan PINCTRL_PIN(94, "GPIO_94/PWR_SDA"),
861a83c29e1SYixun Lan PINCTRL_PIN(95, "GPIO_95/VCX0_EN"),
862a83c29e1SYixun Lan PINCTRL_PIN(96, "GPIO_96/DVL0"),
863a83c29e1SYixun Lan PINCTRL_PIN(97, "GPIO_97/DVL1"),
864a83c29e1SYixun Lan PINCTRL_PIN(98, "GPIO_98/QSPI_DAT3"),
865a83c29e1SYixun Lan PINCTRL_PIN(99, "GPIO_99/QSPI_DAT2"),
866a83c29e1SYixun Lan PINCTRL_PIN(100, "GPIO_100/QSPI_DAT1"),
867a83c29e1SYixun Lan PINCTRL_PIN(101, "GPIO_101/QSPI_DAT0"),
868a83c29e1SYixun Lan PINCTRL_PIN(102, "GPIO_102/QSPI_CLK"),
869a83c29e1SYixun Lan PINCTRL_PIN(103, "GPIO_103/QSPI_CS1"),
870a83c29e1SYixun Lan PINCTRL_PIN(104, "GPIO_104/MMC1_DAT3"),
871a83c29e1SYixun Lan PINCTRL_PIN(105, "GPIO_105/MMC1_DAT2"),
872a83c29e1SYixun Lan PINCTRL_PIN(106, "GPIO_106/MMC1_DAT1"),
873a83c29e1SYixun Lan PINCTRL_PIN(107, "GPIO_107/MMC1_DAT0"),
874a83c29e1SYixun Lan PINCTRL_PIN(108, "GPIO_108/MMC1_CMD"),
875a83c29e1SYixun Lan PINCTRL_PIN(109, "GPIO_109/MMC1_CLK"),
876a83c29e1SYixun Lan PINCTRL_PIN(110, "GPIO_110"),
877a83c29e1SYixun Lan PINCTRL_PIN(111, "GPIO_111"),
878a83c29e1SYixun Lan PINCTRL_PIN(112, "GPIO_112"),
879a83c29e1SYixun Lan PINCTRL_PIN(113, "GPIO_113"),
880a83c29e1SYixun Lan PINCTRL_PIN(114, "GPIO_114"),
881a83c29e1SYixun Lan PINCTRL_PIN(115, "GPIO_115"),
882a83c29e1SYixun Lan PINCTRL_PIN(116, "GPIO_116"),
883a83c29e1SYixun Lan PINCTRL_PIN(117, "GPIO_117"),
884a83c29e1SYixun Lan PINCTRL_PIN(118, "GPIO_118"),
885a83c29e1SYixun Lan PINCTRL_PIN(119, "GPIO_119"),
886a83c29e1SYixun Lan PINCTRL_PIN(120, "GPIO_120"),
887a83c29e1SYixun Lan PINCTRL_PIN(121, "GPIO_121"),
888a83c29e1SYixun Lan PINCTRL_PIN(122, "GPIO_122"),
889a83c29e1SYixun Lan PINCTRL_PIN(123, "GPIO_123"),
890a83c29e1SYixun Lan PINCTRL_PIN(124, "GPIO_124"),
891a83c29e1SYixun Lan PINCTRL_PIN(125, "GPIO_125"),
892a83c29e1SYixun Lan PINCTRL_PIN(126, "GPIO_126"),
893a83c29e1SYixun Lan PINCTRL_PIN(127, "GPIO_127"),
894a83c29e1SYixun Lan };
895a83c29e1SYixun Lan
896a83c29e1SYixun Lan static const struct spacemit_pin k1_pin_data[ARRAY_SIZE(k1_pin_desc)] = {
897a83c29e1SYixun Lan K1_FUNC_PIN(0, 0, IO_TYPE_1V8),
898a83c29e1SYixun Lan K1_FUNC_PIN(1, 0, IO_TYPE_1V8),
899a83c29e1SYixun Lan K1_FUNC_PIN(2, 0, IO_TYPE_1V8),
900a83c29e1SYixun Lan K1_FUNC_PIN(3, 0, IO_TYPE_1V8),
901a83c29e1SYixun Lan K1_FUNC_PIN(4, 0, IO_TYPE_1V8),
902a83c29e1SYixun Lan K1_FUNC_PIN(5, 0, IO_TYPE_1V8),
903a83c29e1SYixun Lan K1_FUNC_PIN(6, 0, IO_TYPE_1V8),
904a83c29e1SYixun Lan K1_FUNC_PIN(7, 0, IO_TYPE_1V8),
905a83c29e1SYixun Lan K1_FUNC_PIN(8, 0, IO_TYPE_1V8),
906a83c29e1SYixun Lan K1_FUNC_PIN(9, 0, IO_TYPE_1V8),
907a83c29e1SYixun Lan K1_FUNC_PIN(10, 0, IO_TYPE_1V8),
908a83c29e1SYixun Lan K1_FUNC_PIN(11, 0, IO_TYPE_1V8),
909a83c29e1SYixun Lan K1_FUNC_PIN(12, 0, IO_TYPE_1V8),
910a83c29e1SYixun Lan K1_FUNC_PIN(13, 0, IO_TYPE_1V8),
911a83c29e1SYixun Lan K1_FUNC_PIN(14, 0, IO_TYPE_1V8),
912a83c29e1SYixun Lan K1_FUNC_PIN(15, 0, IO_TYPE_1V8),
913a83c29e1SYixun Lan K1_FUNC_PIN(16, 0, IO_TYPE_1V8),
914a83c29e1SYixun Lan K1_FUNC_PIN(17, 0, IO_TYPE_1V8),
915a83c29e1SYixun Lan K1_FUNC_PIN(18, 0, IO_TYPE_1V8),
916a83c29e1SYixun Lan K1_FUNC_PIN(19, 0, IO_TYPE_1V8),
917a83c29e1SYixun Lan K1_FUNC_PIN(20, 0, IO_TYPE_1V8),
918a83c29e1SYixun Lan K1_FUNC_PIN(21, 0, IO_TYPE_1V8),
919a83c29e1SYixun Lan K1_FUNC_PIN(22, 0, IO_TYPE_1V8),
920a83c29e1SYixun Lan K1_FUNC_PIN(23, 0, IO_TYPE_1V8),
921a83c29e1SYixun Lan K1_FUNC_PIN(24, 0, IO_TYPE_1V8),
922a83c29e1SYixun Lan K1_FUNC_PIN(25, 0, IO_TYPE_1V8),
923a83c29e1SYixun Lan K1_FUNC_PIN(26, 0, IO_TYPE_1V8),
924a83c29e1SYixun Lan K1_FUNC_PIN(27, 0, IO_TYPE_1V8),
925a83c29e1SYixun Lan K1_FUNC_PIN(28, 0, IO_TYPE_1V8),
926a83c29e1SYixun Lan K1_FUNC_PIN(29, 0, IO_TYPE_1V8),
927a83c29e1SYixun Lan K1_FUNC_PIN(30, 0, IO_TYPE_1V8),
928a83c29e1SYixun Lan K1_FUNC_PIN(31, 0, IO_TYPE_1V8),
929a83c29e1SYixun Lan K1_FUNC_PIN(32, 0, IO_TYPE_1V8),
930a83c29e1SYixun Lan K1_FUNC_PIN(33, 0, IO_TYPE_1V8),
931a83c29e1SYixun Lan K1_FUNC_PIN(34, 0, IO_TYPE_1V8),
932a83c29e1SYixun Lan K1_FUNC_PIN(35, 0, IO_TYPE_1V8),
933a83c29e1SYixun Lan K1_FUNC_PIN(36, 0, IO_TYPE_1V8),
934a83c29e1SYixun Lan K1_FUNC_PIN(37, 0, IO_TYPE_1V8),
935a83c29e1SYixun Lan K1_FUNC_PIN(38, 0, IO_TYPE_1V8),
936a83c29e1SYixun Lan K1_FUNC_PIN(39, 0, IO_TYPE_1V8),
937a83c29e1SYixun Lan K1_FUNC_PIN(40, 0, IO_TYPE_1V8),
938a83c29e1SYixun Lan K1_FUNC_PIN(41, 0, IO_TYPE_1V8),
939a83c29e1SYixun Lan K1_FUNC_PIN(42, 0, IO_TYPE_1V8),
940a83c29e1SYixun Lan K1_FUNC_PIN(43, 0, IO_TYPE_1V8),
941a83c29e1SYixun Lan K1_FUNC_PIN(44, 0, IO_TYPE_1V8),
942a83c29e1SYixun Lan K1_FUNC_PIN(45, 0, IO_TYPE_1V8),
943a83c29e1SYixun Lan K1_FUNC_PIN(46, 0, IO_TYPE_1V8),
944a83c29e1SYixun Lan K1_FUNC_PIN(47, 0, IO_TYPE_EXTERNAL),
945a83c29e1SYixun Lan K1_FUNC_PIN(48, 0, IO_TYPE_EXTERNAL),
946a83c29e1SYixun Lan K1_FUNC_PIN(49, 0, IO_TYPE_EXTERNAL),
947a83c29e1SYixun Lan K1_FUNC_PIN(50, 0, IO_TYPE_EXTERNAL),
948a83c29e1SYixun Lan K1_FUNC_PIN(51, 0, IO_TYPE_EXTERNAL),
949a83c29e1SYixun Lan K1_FUNC_PIN(52, 0, IO_TYPE_EXTERNAL),
950a83c29e1SYixun Lan K1_FUNC_PIN(53, 0, IO_TYPE_1V8),
951a83c29e1SYixun Lan K1_FUNC_PIN(54, 0, IO_TYPE_1V8),
952a83c29e1SYixun Lan K1_FUNC_PIN(55, 0, IO_TYPE_1V8),
953a83c29e1SYixun Lan K1_FUNC_PIN(56, 0, IO_TYPE_1V8),
954a83c29e1SYixun Lan K1_FUNC_PIN(57, 0, IO_TYPE_1V8),
955a83c29e1SYixun Lan K1_FUNC_PIN(58, 0, IO_TYPE_1V8),
956a83c29e1SYixun Lan K1_FUNC_PIN(59, 0, IO_TYPE_1V8),
957a83c29e1SYixun Lan K1_FUNC_PIN(60, 0, IO_TYPE_1V8),
958a83c29e1SYixun Lan K1_FUNC_PIN(61, 0, IO_TYPE_1V8),
959a83c29e1SYixun Lan K1_FUNC_PIN(62, 0, IO_TYPE_1V8),
960a83c29e1SYixun Lan K1_FUNC_PIN(63, 0, IO_TYPE_1V8),
961a83c29e1SYixun Lan K1_FUNC_PIN(64, 0, IO_TYPE_1V8),
962a83c29e1SYixun Lan K1_FUNC_PIN(65, 0, IO_TYPE_1V8),
963a83c29e1SYixun Lan K1_FUNC_PIN(66, 0, IO_TYPE_1V8),
964a83c29e1SYixun Lan K1_FUNC_PIN(67, 0, IO_TYPE_1V8),
965a83c29e1SYixun Lan K1_FUNC_PIN(68, 0, IO_TYPE_1V8),
966a83c29e1SYixun Lan K1_FUNC_PIN(69, 0, IO_TYPE_1V8),
967a83c29e1SYixun Lan K1_FUNC_PIN(70, 1, IO_TYPE_1V8),
968a83c29e1SYixun Lan K1_FUNC_PIN(71, 1, IO_TYPE_1V8),
969a83c29e1SYixun Lan K1_FUNC_PIN(72, 1, IO_TYPE_1V8),
970a83c29e1SYixun Lan K1_FUNC_PIN(73, 1, IO_TYPE_1V8),
971a83c29e1SYixun Lan K1_FUNC_PIN(74, 0, IO_TYPE_1V8),
972a83c29e1SYixun Lan K1_FUNC_PIN(75, 0, IO_TYPE_EXTERNAL),
973a83c29e1SYixun Lan K1_FUNC_PIN(76, 0, IO_TYPE_EXTERNAL),
974a83c29e1SYixun Lan K1_FUNC_PIN(77, 0, IO_TYPE_EXTERNAL),
975a83c29e1SYixun Lan K1_FUNC_PIN(78, 0, IO_TYPE_EXTERNAL),
976a83c29e1SYixun Lan K1_FUNC_PIN(79, 0, IO_TYPE_EXTERNAL),
977a83c29e1SYixun Lan K1_FUNC_PIN(80, 0, IO_TYPE_EXTERNAL),
978a83c29e1SYixun Lan K1_FUNC_PIN(81, 0, IO_TYPE_1V8),
979a83c29e1SYixun Lan K1_FUNC_PIN(82, 0, IO_TYPE_1V8),
980a83c29e1SYixun Lan K1_FUNC_PIN(83, 0, IO_TYPE_1V8),
981a83c29e1SYixun Lan K1_FUNC_PIN(84, 0, IO_TYPE_1V8),
982a83c29e1SYixun Lan K1_FUNC_PIN(85, 0, IO_TYPE_1V8),
983a83c29e1SYixun Lan K1_FUNC_PIN(86, 0, IO_TYPE_1V8),
984a83c29e1SYixun Lan K1_FUNC_PIN(87, 0, IO_TYPE_1V8),
985a83c29e1SYixun Lan K1_FUNC_PIN(88, 0, IO_TYPE_1V8),
986a83c29e1SYixun Lan K1_FUNC_PIN(89, 0, IO_TYPE_1V8),
987a83c29e1SYixun Lan K1_FUNC_PIN(90, 0, IO_TYPE_1V8),
988a83c29e1SYixun Lan K1_FUNC_PIN(91, 0, IO_TYPE_1V8),
989a83c29e1SYixun Lan K1_FUNC_PIN(92, 0, IO_TYPE_1V8),
990a83c29e1SYixun Lan K1_FUNC_PIN(93, 1, IO_TYPE_1V8),
991a83c29e1SYixun Lan K1_FUNC_PIN(94, 1, IO_TYPE_1V8),
992a83c29e1SYixun Lan K1_FUNC_PIN(95, 1, IO_TYPE_1V8),
993a83c29e1SYixun Lan K1_FUNC_PIN(96, 1, IO_TYPE_1V8),
994a83c29e1SYixun Lan K1_FUNC_PIN(97, 1, IO_TYPE_1V8),
995a83c29e1SYixun Lan K1_FUNC_PIN(98, 1, IO_TYPE_EXTERNAL),
996a83c29e1SYixun Lan K1_FUNC_PIN(99, 1, IO_TYPE_EXTERNAL),
997a83c29e1SYixun Lan K1_FUNC_PIN(100, 1, IO_TYPE_EXTERNAL),
998a83c29e1SYixun Lan K1_FUNC_PIN(101, 1, IO_TYPE_EXTERNAL),
999a83c29e1SYixun Lan K1_FUNC_PIN(102, 1, IO_TYPE_EXTERNAL),
1000a83c29e1SYixun Lan K1_FUNC_PIN(103, 1, IO_TYPE_EXTERNAL),
1001a83c29e1SYixun Lan K1_FUNC_PIN(104, 4, IO_TYPE_EXTERNAL),
1002a83c29e1SYixun Lan K1_FUNC_PIN(105, 4, IO_TYPE_EXTERNAL),
1003a83c29e1SYixun Lan K1_FUNC_PIN(106, 4, IO_TYPE_EXTERNAL),
1004a83c29e1SYixun Lan K1_FUNC_PIN(107, 4, IO_TYPE_EXTERNAL),
1005a83c29e1SYixun Lan K1_FUNC_PIN(108, 4, IO_TYPE_EXTERNAL),
1006a83c29e1SYixun Lan K1_FUNC_PIN(109, 4, IO_TYPE_EXTERNAL),
1007a83c29e1SYixun Lan K1_FUNC_PIN(110, 0, IO_TYPE_1V8),
1008a83c29e1SYixun Lan K1_FUNC_PIN(111, 0, IO_TYPE_1V8),
1009a83c29e1SYixun Lan K1_FUNC_PIN(112, 0, IO_TYPE_1V8),
1010a83c29e1SYixun Lan K1_FUNC_PIN(113, 0, IO_TYPE_1V8),
1011a83c29e1SYixun Lan K1_FUNC_PIN(114, 0, IO_TYPE_1V8),
1012a83c29e1SYixun Lan K1_FUNC_PIN(115, 0, IO_TYPE_1V8),
1013a83c29e1SYixun Lan K1_FUNC_PIN(116, 0, IO_TYPE_1V8),
1014a83c29e1SYixun Lan K1_FUNC_PIN(117, 0, IO_TYPE_1V8),
1015a83c29e1SYixun Lan K1_FUNC_PIN(118, 0, IO_TYPE_1V8),
1016a83c29e1SYixun Lan K1_FUNC_PIN(119, 0, IO_TYPE_1V8),
1017a83c29e1SYixun Lan K1_FUNC_PIN(120, 0, IO_TYPE_1V8),
1018a83c29e1SYixun Lan K1_FUNC_PIN(121, 0, IO_TYPE_1V8),
1019a83c29e1SYixun Lan K1_FUNC_PIN(122, 0, IO_TYPE_1V8),
1020a83c29e1SYixun Lan K1_FUNC_PIN(123, 0, IO_TYPE_1V8),
1021a83c29e1SYixun Lan K1_FUNC_PIN(124, 0, IO_TYPE_1V8),
1022a83c29e1SYixun Lan K1_FUNC_PIN(125, 0, IO_TYPE_1V8),
1023a83c29e1SYixun Lan K1_FUNC_PIN(126, 0, IO_TYPE_1V8),
1024a83c29e1SYixun Lan K1_FUNC_PIN(127, 0, IO_TYPE_1V8),
1025a83c29e1SYixun Lan };
1026a83c29e1SYixun Lan
1027a83c29e1SYixun Lan static const struct spacemit_pinctrl_data k1_pinctrl_data = {
1028a83c29e1SYixun Lan .pins = k1_pin_desc,
1029a83c29e1SYixun Lan .data = k1_pin_data,
1030a83c29e1SYixun Lan .npins = ARRAY_SIZE(k1_pin_desc),
1031a83c29e1SYixun Lan };
1032a83c29e1SYixun Lan
1033a83c29e1SYixun Lan static const struct of_device_id k1_pinctrl_ids[] = {
1034a83c29e1SYixun Lan { .compatible = "spacemit,k1-pinctrl", .data = &k1_pinctrl_data },
1035a83c29e1SYixun Lan { /* sentinel */ }
1036a83c29e1SYixun Lan };
1037a83c29e1SYixun Lan MODULE_DEVICE_TABLE(of, k1_pinctrl_ids);
1038a83c29e1SYixun Lan
1039a83c29e1SYixun Lan static struct platform_driver k1_pinctrl_driver = {
1040a83c29e1SYixun Lan .probe = spacemit_pinctrl_probe,
1041a83c29e1SYixun Lan .driver = {
1042a83c29e1SYixun Lan .name = "k1-pinctrl",
1043a83c29e1SYixun Lan .suppress_bind_attrs = true,
1044a83c29e1SYixun Lan .of_match_table = k1_pinctrl_ids,
1045a83c29e1SYixun Lan },
1046a83c29e1SYixun Lan };
1047a83c29e1SYixun Lan module_platform_driver(k1_pinctrl_driver);
1048a83c29e1SYixun Lan
1049a83c29e1SYixun Lan MODULE_AUTHOR("Yixun Lan <dlan@gentoo.org>");
1050a83c29e1SYixun Lan MODULE_DESCRIPTION("Pinctrl driver for the SpacemiT K1 SoC");
1051a83c29e1SYixun Lan MODULE_LICENSE("GPL");
1052