1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Pinctrl driver for the Wondermedia SoC's
4  *
5  * Copyright (c) 2013 Tony Prisk <linux@prisktech.co.nz>
6  */
7 
8 #include <linux/gpio/driver.h>
9 
10 /* VT8500 has no enable register in the extgpio bank. */
11 #define NO_REG	0xFFFF
12 
13 #define WMT_PINCTRL_BANK(__en, __dir, __dout, __din, __pen, __pcfg)	\
14 {									\
15 	.reg_en		= __en,						\
16 	.reg_dir	= __dir,					\
17 	.reg_data_out	= __dout,					\
18 	.reg_data_in	= __din,					\
19 	.reg_pull_en	= __pen,					\
20 	.reg_pull_cfg	= __pcfg,					\
21 }
22 
23 /* Encode/decode the bank/bit pairs into a pin value */
24 #define WMT_PIN(__bank, __offset)	((__bank << 5) | __offset)
25 #define WMT_BANK_FROM_PIN(__pin)	(__pin >> 5)
26 #define WMT_BIT_FROM_PIN(__pin)		(__pin & 0x1f)
27 
28 #define WMT_GROUP(__name, __data)		\
29 {						\
30 	.name = __name,				\
31 	.pins = __data,				\
32 	.npins = ARRAY_SIZE(__data),		\
33 }
34 
35 struct wmt_pinctrl_bank_registers {
36 	u32	reg_en;
37 	u32	reg_dir;
38 	u32	reg_data_out;
39 	u32	reg_data_in;
40 
41 	u32	reg_pull_en;
42 	u32	reg_pull_cfg;
43 };
44 
45 struct wmt_pinctrl_group {
46 	const char *name;
47 	const unsigned int *pins;
48 	const unsigned npins;
49 };
50 
51 struct wmt_pinctrl_data {
52 	struct device *dev;
53 	struct pinctrl_dev *pctl_dev;
54 
55 	/* must be initialized before calling wmt_pinctrl_probe */
56 	void __iomem *base;
57 	const struct wmt_pinctrl_bank_registers *banks;
58 	const struct pinctrl_pin_desc *pins;
59 	const char * const *groups;
60 
61 	u32 nbanks;
62 	u32 npins;
63 	u32 ngroups;
64 
65 	struct gpio_chip gpio_chip;
66 	struct pinctrl_gpio_range gpio_range;
67 };
68 
69 int wmt_pinctrl_probe(struct platform_device *pdev,
70 		      struct wmt_pinctrl_data *data);
71