xref: /linux/drivers/pinctrl/pinctrl-pef2256.c (revision 06d07429858317ded2db7986113a9e0129cd599b)
1*37c646dcSHerve Codina // SPDX-License-Identifier: GPL-2.0
2*37c646dcSHerve Codina /*
3*37c646dcSHerve Codina  * PEF2256 also known as FALC56 driver
4*37c646dcSHerve Codina  *
5*37c646dcSHerve Codina  * Copyright 2023 CS GROUP France
6*37c646dcSHerve Codina  *
7*37c646dcSHerve Codina  * Author: Herve Codina <herve.codina@bootlin.com>
8*37c646dcSHerve Codina  */
9*37c646dcSHerve Codina 
10*37c646dcSHerve Codina #include <linux/bitfield.h>
11*37c646dcSHerve Codina #include <linux/framer/pef2256.h>
12*37c646dcSHerve Codina #include <linux/module.h>
13*37c646dcSHerve Codina #include <linux/of.h>
14*37c646dcSHerve Codina #include <linux/pinctrl/pinctrl.h>
15*37c646dcSHerve Codina #include <linux/pinctrl/pinconf-generic.h>
16*37c646dcSHerve Codina #include <linux/pinctrl/pinmux.h>
17*37c646dcSHerve Codina #include <linux/platform_device.h>
18*37c646dcSHerve Codina #include <linux/regmap.h>
19*37c646dcSHerve Codina #include <linux/slab.h>
20*37c646dcSHerve Codina 
21*37c646dcSHerve Codina /* Port Configuration 1..4 */
22*37c646dcSHerve Codina #define PEF2256_PC1		  0x80
23*37c646dcSHerve Codina #define PEF2256_PC2		  0x81
24*37c646dcSHerve Codina #define PEF2256_PC3		  0x82
25*37c646dcSHerve Codina #define PEF2256_PC4		  0x83
26*37c646dcSHerve Codina #define PEF2256_12_PC_RPC_MASK	  GENMASK(6, 4)
27*37c646dcSHerve Codina #define PEF2256_12_PC_RPC_SYPR	  FIELD_PREP_CONST(PEF2256_12_PC_RPC_MASK, 0x0)
28*37c646dcSHerve Codina #define PEF2256_12_PC_RPC_RFM	  FIELD_PREP_CONST(PEF2256_12_PC_RPC_MASK, 0x1)
29*37c646dcSHerve Codina #define PEF2256_12_PC_RPC_RFMB	  FIELD_PREP_CONST(PEF2256_12_PC_RPC_MASK, 0x2)
30*37c646dcSHerve Codina #define PEF2256_12_PC_RPC_RSIGM	  FIELD_PREP_CONST(PEF2256_12_PC_RPC_MASK, 0x3)
31*37c646dcSHerve Codina #define PEF2256_12_PC_RPC_RSIG	  FIELD_PREP_CONST(PEF2256_12_PC_RPC_MASK, 0x4)
32*37c646dcSHerve Codina #define PEF2256_12_PC_RPC_DLR	  FIELD_PREP_CONST(PEF2256_12_PC_RPC_MASK, 0x5)
33*37c646dcSHerve Codina #define PEF2256_12_PC_RPC_FREEZE  FIELD_PREP_CONST(PEF2256_12_PC_RPC_MASK, 0x6)
34*37c646dcSHerve Codina #define PEF2256_12_PC_RPC_RFSP	  FIELD_PREP_CONST(PEF2256_12_PC_RPC_MASK, 0x7)
35*37c646dcSHerve Codina #define PEF2256_12_PC_XPC_MASK    GENMASK(4, 0)
36*37c646dcSHerve Codina #define PEF2256_12_PC_XPC_SYPX	  FIELD_PREP_CONST(PEF2256_12_PC_XPC_MASK, 0x0)
37*37c646dcSHerve Codina #define PEF2256_12_PC_XPC_XFMS	  FIELD_PREP_CONST(PEF2256_12_PC_XPC_MASK, 0x1)
38*37c646dcSHerve Codina #define PEF2256_12_PC_XPC_XSIG	  FIELD_PREP_CONST(PEF2256_12_PC_XPC_MASK, 0x2)
39*37c646dcSHerve Codina #define PEF2256_12_PC_XPC_TCLK	  FIELD_PREP_CONST(PEF2256_12_PC_XPC_MASK, 0x3)
40*37c646dcSHerve Codina #define PEF2256_12_PC_XPC_XMFB	  FIELD_PREP_CONST(PEF2256_12_PC_XPC_MASK, 0x4)
41*37c646dcSHerve Codina #define PEF2256_12_PC_XPC_XSIGM	  FIELD_PREP_CONST(PEF2256_12_PC_XPC_MASK, 0x5)
42*37c646dcSHerve Codina #define PEF2256_12_PC_XPC_DLX	  FIELD_PREP_CONST(PEF2256_12_PC_XPC_MASK, 0x6)
43*37c646dcSHerve Codina #define PEF2256_12_PC_XPC_XCLK	  FIELD_PREP_CONST(PEF2256_12_PC_XPC_MASK, 0x7)
44*37c646dcSHerve Codina #define PEF2256_12_PC_XPC_XLT	  FIELD_PREP_CONST(PEF2256_12_PC_XPC_MASK, 0x8)
45*37c646dcSHerve Codina #define PEF2256_2X_PC_RPC_MASK	  GENMASK(7, 4)
46*37c646dcSHerve Codina #define PEF2256_2X_PC_RPC_SYPR	  FIELD_PREP_CONST(PEF2256_2X_PC_RPC_MASK, 0x0)
47*37c646dcSHerve Codina #define PEF2256_2X_PC_RPC_RFM	  FIELD_PREP_CONST(PEF2256_2X_PC_RPC_MASK, 0x1)
48*37c646dcSHerve Codina #define PEF2256_2X_PC_RPC_RFMB	  FIELD_PREP_CONST(PEF2256_2X_PC_RPC_MASK, 0x2)
49*37c646dcSHerve Codina #define PEF2256_2X_PC_RPC_RSIGM	  FIELD_PREP_CONST(PEF2256_2X_PC_RPC_MASK, 0x3)
50*37c646dcSHerve Codina #define PEF2256_2X_PC_RPC_RSIG	  FIELD_PREP_CONST(PEF2256_2X_PC_RPC_MASK, 0x4)
51*37c646dcSHerve Codina #define PEF2256_2X_PC_RPC_DLR	  FIELD_PREP_CONST(PEF2256_2X_PC_RPC_MASK, 0x5)
52*37c646dcSHerve Codina #define PEF2256_2X_PC_RPC_FREEZE  FIELD_PREP_CONST(PEF2256_2X_PC_RPC_MASK, 0x6)
53*37c646dcSHerve Codina #define PEF2256_2X_PC_RPC_RFSP	  FIELD_PREP_CONST(PEF2256_2X_PC_RPC_MASK, 0x7)
54*37c646dcSHerve Codina #define PEF2256_2X_PC_RPC_GPI	  FIELD_PREP_CONST(PEF2256_2X_PC_RPC_MASK, 0x9)
55*37c646dcSHerve Codina #define PEF2256_2X_PC_RPC_GPOH	  FIELD_PREP_CONST(PEF2256_2X_PC_RPC_MASK, 0xa)
56*37c646dcSHerve Codina #define PEF2256_2X_PC_RPC_GPOL	  FIELD_PREP_CONST(PEF2256_2X_PC_RPC_MASK, 0xb)
57*37c646dcSHerve Codina #define PEF2256_2X_PC_RPC_LOS	  FIELD_PREP_CONST(PEF2256_2X_PC_RPC_MASK, 0xc)
58*37c646dcSHerve Codina #define PEF2256_2X_PC_XPC_MASK	  GENMASK(3, 0)
59*37c646dcSHerve Codina #define PEF2256_2X_PC_XPC_SYPX	  FIELD_PREP_CONST(PEF2256_2X_PC_XPC_MASK, 0x0)
60*37c646dcSHerve Codina #define PEF2256_2X_PC_XPC_XFMS	  FIELD_PREP_CONST(PEF2256_2X_PC_XPC_MASK, 0x1)
61*37c646dcSHerve Codina #define PEF2256_2X_PC_XPC_XSIG	  FIELD_PREP_CONST(PEF2256_2X_PC_XPC_MASK, 0x2)
62*37c646dcSHerve Codina #define PEF2256_2X_PC_XPC_TCLK	  FIELD_PREP_CONST(PEF2256_2X_PC_XPC_MASK, 0x3)
63*37c646dcSHerve Codina #define PEF2256_2X_PC_XPC_XMFB	  FIELD_PREP_CONST(PEF2256_2X_PC_XPC_MASK, 0x4)
64*37c646dcSHerve Codina #define PEF2256_2X_PC_XPC_XSIGM	  FIELD_PREP_CONST(PEF2256_2X_PC_XPC_MASK, 0x5)
65*37c646dcSHerve Codina #define PEF2256_2X_PC_XPC_DLX	  FIELD_PREP_CONST(PEF2256_2X_PC_XPC_MASK, 0x6)
66*37c646dcSHerve Codina #define PEF2256_2X_PC_XPC_XCLK	  FIELD_PREP_CONST(PEF2256_2X_PC_XPC_MASK, 0x7)
67*37c646dcSHerve Codina #define PEF2256_2X_PC_XPC_XLT	  FIELD_PREP_CONST(PEF2256_2X_PC_XPC_MASK, 0x8)
68*37c646dcSHerve Codina #define PEF2256_2X_PC_XPC_GPI	  FIELD_PREP_CONST(PEF2256_2X_PC_XPC_MASK, 0x9)
69*37c646dcSHerve Codina #define PEF2256_2X_PC_XPC_GPOH	  FIELD_PREP_CONST(PEF2256_2X_PC_XPC_MASK, 0xa)
70*37c646dcSHerve Codina #define PEF2256_2X_PC_XPC_GPOL	  FIELD_PREP_CONST(PEF2256_2X_PC_XPC_MASK, 0xb)
71*37c646dcSHerve Codina 
72*37c646dcSHerve Codina struct pef2256_pinreg_desc {
73*37c646dcSHerve Codina 	int offset;
74*37c646dcSHerve Codina 	u8 mask;
75*37c646dcSHerve Codina };
76*37c646dcSHerve Codina 
77*37c646dcSHerve Codina struct pef2256_function_desc {
78*37c646dcSHerve Codina 	const char *name;
79*37c646dcSHerve Codina 	const char * const*groups;
80*37c646dcSHerve Codina 	unsigned int ngroups;
81*37c646dcSHerve Codina 	u8 func_val;
82*37c646dcSHerve Codina };
83*37c646dcSHerve Codina 
84*37c646dcSHerve Codina struct pef2256_pinctrl {
85*37c646dcSHerve Codina 	struct device *dev;
86*37c646dcSHerve Codina 	struct regmap *regmap;
87*37c646dcSHerve Codina 	enum pef2256_version version;
88*37c646dcSHerve Codina 	struct pinctrl_desc pctrl_desc;
89*37c646dcSHerve Codina 	const struct pef2256_function_desc *functions;
90*37c646dcSHerve Codina 	unsigned int nfunctions;
91*37c646dcSHerve Codina };
92*37c646dcSHerve Codina 
pef2256_get_groups_count(struct pinctrl_dev * pctldev)93*37c646dcSHerve Codina static int pef2256_get_groups_count(struct pinctrl_dev *pctldev)
94*37c646dcSHerve Codina {
95*37c646dcSHerve Codina 	struct pef2256_pinctrl *pef2256 = pinctrl_dev_get_drvdata(pctldev);
96*37c646dcSHerve Codina 
97*37c646dcSHerve Codina 	/* We map 1 group <-> 1 pin */
98*37c646dcSHerve Codina 	return pef2256->pctrl_desc.npins;
99*37c646dcSHerve Codina }
100*37c646dcSHerve Codina 
pef2256_get_group_name(struct pinctrl_dev * pctldev,unsigned int selector)101*37c646dcSHerve Codina static const char *pef2256_get_group_name(struct pinctrl_dev *pctldev,
102*37c646dcSHerve Codina 					  unsigned int selector)
103*37c646dcSHerve Codina {
104*37c646dcSHerve Codina 	struct pef2256_pinctrl *pef2256 = pinctrl_dev_get_drvdata(pctldev);
105*37c646dcSHerve Codina 
106*37c646dcSHerve Codina 	/* We map 1 group <-> 1 pin */
107*37c646dcSHerve Codina 	return pef2256->pctrl_desc.pins[selector].name;
108*37c646dcSHerve Codina }
109*37c646dcSHerve Codina 
pef2256_get_group_pins(struct pinctrl_dev * pctldev,unsigned int selector,const unsigned int ** pins,unsigned int * num_pins)110*37c646dcSHerve Codina static int pef2256_get_group_pins(struct pinctrl_dev *pctldev, unsigned int selector,
111*37c646dcSHerve Codina 				  const unsigned int **pins,
112*37c646dcSHerve Codina 				  unsigned int *num_pins)
113*37c646dcSHerve Codina {
114*37c646dcSHerve Codina 	struct pef2256_pinctrl *pef2256 = pinctrl_dev_get_drvdata(pctldev);
115*37c646dcSHerve Codina 
116*37c646dcSHerve Codina 	/* We map 1 group <-> 1 pin */
117*37c646dcSHerve Codina 	*pins = &pef2256->pctrl_desc.pins[selector].number;
118*37c646dcSHerve Codina 	*num_pins = 1;
119*37c646dcSHerve Codina 
120*37c646dcSHerve Codina 	return 0;
121*37c646dcSHerve Codina }
122*37c646dcSHerve Codina 
123*37c646dcSHerve Codina static const struct pinctrl_ops pef2256_pctlops = {
124*37c646dcSHerve Codina 	.get_groups_count	= pef2256_get_groups_count,
125*37c646dcSHerve Codina 	.get_group_name		= pef2256_get_group_name,
126*37c646dcSHerve Codina 	.get_group_pins		= pef2256_get_group_pins,
127*37c646dcSHerve Codina 	.dt_node_to_map		= pinconf_generic_dt_node_to_map_pin,
128*37c646dcSHerve Codina 	.dt_free_map		= pinconf_generic_dt_free_map,
129*37c646dcSHerve Codina };
130*37c646dcSHerve Codina 
pef2256_get_functions_count(struct pinctrl_dev * pctldev)131*37c646dcSHerve Codina static int pef2256_get_functions_count(struct pinctrl_dev *pctldev)
132*37c646dcSHerve Codina {
133*37c646dcSHerve Codina 	struct pef2256_pinctrl *pef2256 = pinctrl_dev_get_drvdata(pctldev);
134*37c646dcSHerve Codina 
135*37c646dcSHerve Codina 	return pef2256->nfunctions;
136*37c646dcSHerve Codina }
137*37c646dcSHerve Codina 
pef2256_get_function_name(struct pinctrl_dev * pctldev,unsigned int selector)138*37c646dcSHerve Codina static const char *pef2256_get_function_name(struct pinctrl_dev *pctldev,
139*37c646dcSHerve Codina 					     unsigned int selector)
140*37c646dcSHerve Codina {
141*37c646dcSHerve Codina 	struct pef2256_pinctrl *pef2256 = pinctrl_dev_get_drvdata(pctldev);
142*37c646dcSHerve Codina 
143*37c646dcSHerve Codina 	return pef2256->functions[selector].name;
144*37c646dcSHerve Codina }
145*37c646dcSHerve Codina 
pef2256_get_function_groups(struct pinctrl_dev * pctldev,unsigned int selector,const char * const ** groups,unsigned * const num_groups)146*37c646dcSHerve Codina static int pef2256_get_function_groups(struct pinctrl_dev *pctldev, unsigned int selector,
147*37c646dcSHerve Codina 				       const char * const **groups,
148*37c646dcSHerve Codina 				       unsigned * const num_groups)
149*37c646dcSHerve Codina {
150*37c646dcSHerve Codina 	struct pef2256_pinctrl *pef2256 = pinctrl_dev_get_drvdata(pctldev);
151*37c646dcSHerve Codina 
152*37c646dcSHerve Codina 	*groups = pef2256->functions[selector].groups;
153*37c646dcSHerve Codina 	*num_groups = pef2256->functions[selector].ngroups;
154*37c646dcSHerve Codina 	return 0;
155*37c646dcSHerve Codina }
156*37c646dcSHerve Codina 
pef2256_set_mux(struct pinctrl_dev * pctldev,unsigned int func_selector,unsigned int group_selector)157*37c646dcSHerve Codina static int pef2256_set_mux(struct pinctrl_dev *pctldev, unsigned int func_selector,
158*37c646dcSHerve Codina 			   unsigned int group_selector)
159*37c646dcSHerve Codina {
160*37c646dcSHerve Codina 	struct pef2256_pinctrl *pef2256 = pinctrl_dev_get_drvdata(pctldev);
161*37c646dcSHerve Codina 	const struct pef2256_pinreg_desc *pinreg_desc;
162*37c646dcSHerve Codina 	u8 func_val;
163*37c646dcSHerve Codina 
164*37c646dcSHerve Codina 	/* We map 1 group <-> 1 pin */
165*37c646dcSHerve Codina 	pinreg_desc = pef2256->pctrl_desc.pins[group_selector].drv_data;
166*37c646dcSHerve Codina 	func_val = pef2256->functions[func_selector].func_val;
167*37c646dcSHerve Codina 
168*37c646dcSHerve Codina 	return regmap_update_bits(pef2256->regmap, pinreg_desc->offset,
169*37c646dcSHerve Codina 				  pinreg_desc->mask, func_val);
170*37c646dcSHerve Codina }
171*37c646dcSHerve Codina 
172*37c646dcSHerve Codina static const struct pinmux_ops pef2256_pmxops = {
173*37c646dcSHerve Codina 	.get_functions_count	= pef2256_get_functions_count,
174*37c646dcSHerve Codina 	.get_function_name	= pef2256_get_function_name,
175*37c646dcSHerve Codina 	.get_function_groups	= pef2256_get_function_groups,
176*37c646dcSHerve Codina 	.set_mux		= pef2256_set_mux,
177*37c646dcSHerve Codina };
178*37c646dcSHerve Codina 
179*37c646dcSHerve Codina #define PEF2256_PINCTRL_PIN(_number, _name, _offset, _mask) { \
180*37c646dcSHerve Codina 	.number = _number, \
181*37c646dcSHerve Codina 	.name = _name, \
182*37c646dcSHerve Codina 	.drv_data = &(struct pef2256_pinreg_desc) { \
183*37c646dcSHerve Codina 		.offset = _offset, \
184*37c646dcSHerve Codina 		.mask = _mask, \
185*37c646dcSHerve Codina 	}, \
186*37c646dcSHerve Codina }
187*37c646dcSHerve Codina 
188*37c646dcSHerve Codina static const struct pinctrl_pin_desc pef2256_v12_pins[] = {
189*37c646dcSHerve Codina 	PEF2256_PINCTRL_PIN(0, "RPA", PEF2256_PC1, PEF2256_12_PC_RPC_MASK),
190*37c646dcSHerve Codina 	PEF2256_PINCTRL_PIN(1, "RPB", PEF2256_PC2, PEF2256_12_PC_RPC_MASK),
191*37c646dcSHerve Codina 	PEF2256_PINCTRL_PIN(2, "RPC", PEF2256_PC3, PEF2256_12_PC_RPC_MASK),
192*37c646dcSHerve Codina 	PEF2256_PINCTRL_PIN(3, "RPD", PEF2256_PC4, PEF2256_12_PC_RPC_MASK),
193*37c646dcSHerve Codina 	PEF2256_PINCTRL_PIN(4, "XPA", PEF2256_PC1, PEF2256_12_PC_XPC_MASK),
194*37c646dcSHerve Codina 	PEF2256_PINCTRL_PIN(5, "XPB", PEF2256_PC2, PEF2256_12_PC_XPC_MASK),
195*37c646dcSHerve Codina 	PEF2256_PINCTRL_PIN(6, "XPC", PEF2256_PC3, PEF2256_12_PC_XPC_MASK),
196*37c646dcSHerve Codina 	PEF2256_PINCTRL_PIN(7, "XPD", PEF2256_PC4, PEF2256_12_PC_XPC_MASK),
197*37c646dcSHerve Codina };
198*37c646dcSHerve Codina 
199*37c646dcSHerve Codina static const struct pinctrl_pin_desc pef2256_v2x_pins[] = {
200*37c646dcSHerve Codina 	PEF2256_PINCTRL_PIN(0, "RPA", PEF2256_PC1, PEF2256_2X_PC_RPC_MASK),
201*37c646dcSHerve Codina 	PEF2256_PINCTRL_PIN(1, "RPB", PEF2256_PC2, PEF2256_2X_PC_RPC_MASK),
202*37c646dcSHerve Codina 	PEF2256_PINCTRL_PIN(2, "RPC", PEF2256_PC3, PEF2256_2X_PC_RPC_MASK),
203*37c646dcSHerve Codina 	PEF2256_PINCTRL_PIN(3, "RPD", PEF2256_PC4, PEF2256_2X_PC_RPC_MASK),
204*37c646dcSHerve Codina 	PEF2256_PINCTRL_PIN(4, "XPA", PEF2256_PC1, PEF2256_2X_PC_XPC_MASK),
205*37c646dcSHerve Codina 	PEF2256_PINCTRL_PIN(5, "XPB", PEF2256_PC2, PEF2256_2X_PC_XPC_MASK),
206*37c646dcSHerve Codina 	PEF2256_PINCTRL_PIN(6, "XPC", PEF2256_PC3, PEF2256_2X_PC_XPC_MASK),
207*37c646dcSHerve Codina 	PEF2256_PINCTRL_PIN(7, "XPD", PEF2256_PC4, PEF2256_2X_PC_XPC_MASK),
208*37c646dcSHerve Codina };
209*37c646dcSHerve Codina 
210*37c646dcSHerve Codina static const char *const pef2256_rp_groups[] = { "RPA", "RPB", "RPC", "RPD" };
211*37c646dcSHerve Codina static const char *const pef2256_xp_groups[] = { "XPA", "XPB", "XPC", "XPD" };
212*37c646dcSHerve Codina static const char *const pef2256_all_groups[] = { "RPA", "RPB", "RPC", "RPD",
213*37c646dcSHerve Codina 						  "XPA", "XPB", "XPC", "XPD" };
214*37c646dcSHerve Codina 
215*37c646dcSHerve Codina #define PEF2256_FUNCTION(_name, _func_val, _groups) { \
216*37c646dcSHerve Codina 	.name = _name, \
217*37c646dcSHerve Codina 	.groups = _groups, \
218*37c646dcSHerve Codina 	.ngroups = ARRAY_SIZE(_groups), \
219*37c646dcSHerve Codina 	.func_val = _func_val, \
220*37c646dcSHerve Codina }
221*37c646dcSHerve Codina 
222*37c646dcSHerve Codina static const struct pef2256_function_desc pef2256_v2x_functions[] = {
223*37c646dcSHerve Codina 	PEF2256_FUNCTION("SYPR",   PEF2256_2X_PC_RPC_SYPR,   pef2256_rp_groups),
224*37c646dcSHerve Codina 	PEF2256_FUNCTION("RFM",    PEF2256_2X_PC_RPC_RFM,    pef2256_rp_groups),
225*37c646dcSHerve Codina 	PEF2256_FUNCTION("RFMB",   PEF2256_2X_PC_RPC_RFMB,   pef2256_rp_groups),
226*37c646dcSHerve Codina 	PEF2256_FUNCTION("RSIGM",  PEF2256_2X_PC_RPC_RSIGM,  pef2256_rp_groups),
227*37c646dcSHerve Codina 	PEF2256_FUNCTION("RSIG",   PEF2256_2X_PC_RPC_RSIG,   pef2256_rp_groups),
228*37c646dcSHerve Codina 	PEF2256_FUNCTION("DLR",    PEF2256_2X_PC_RPC_DLR,    pef2256_rp_groups),
229*37c646dcSHerve Codina 	PEF2256_FUNCTION("FREEZE", PEF2256_2X_PC_RPC_FREEZE, pef2256_rp_groups),
230*37c646dcSHerve Codina 	PEF2256_FUNCTION("RFSP",   PEF2256_2X_PC_RPC_RFSP,   pef2256_rp_groups),
231*37c646dcSHerve Codina 	PEF2256_FUNCTION("LOS",    PEF2256_2X_PC_RPC_LOS,    pef2256_rp_groups),
232*37c646dcSHerve Codina 
233*37c646dcSHerve Codina 	PEF2256_FUNCTION("SYPX",  PEF2256_2X_PC_XPC_SYPX,  pef2256_xp_groups),
234*37c646dcSHerve Codina 	PEF2256_FUNCTION("XFMS",  PEF2256_2X_PC_XPC_XFMS,  pef2256_xp_groups),
235*37c646dcSHerve Codina 	PEF2256_FUNCTION("XSIG",  PEF2256_2X_PC_XPC_XSIG,  pef2256_xp_groups),
236*37c646dcSHerve Codina 	PEF2256_FUNCTION("TCLK",  PEF2256_2X_PC_XPC_TCLK,  pef2256_xp_groups),
237*37c646dcSHerve Codina 	PEF2256_FUNCTION("XMFB",  PEF2256_2X_PC_XPC_XMFB,  pef2256_xp_groups),
238*37c646dcSHerve Codina 	PEF2256_FUNCTION("XSIGM", PEF2256_2X_PC_XPC_XSIGM, pef2256_xp_groups),
239*37c646dcSHerve Codina 	PEF2256_FUNCTION("DLX",   PEF2256_2X_PC_XPC_DLX,   pef2256_xp_groups),
240*37c646dcSHerve Codina 	PEF2256_FUNCTION("XCLK",  PEF2256_2X_PC_XPC_XCLK,  pef2256_xp_groups),
241*37c646dcSHerve Codina 	PEF2256_FUNCTION("XLT",   PEF2256_2X_PC_XPC_XLT,   pef2256_xp_groups),
242*37c646dcSHerve Codina 
243*37c646dcSHerve Codina 	PEF2256_FUNCTION("GPI",  PEF2256_2X_PC_RPC_GPI | PEF2256_2X_PC_XPC_GPI,
244*37c646dcSHerve Codina 			 pef2256_all_groups),
245*37c646dcSHerve Codina 	PEF2256_FUNCTION("GPOH", PEF2256_2X_PC_RPC_GPOH | PEF2256_2X_PC_XPC_GPOH,
246*37c646dcSHerve Codina 			 pef2256_all_groups),
247*37c646dcSHerve Codina 	PEF2256_FUNCTION("GPOL", PEF2256_2X_PC_RPC_GPOL | PEF2256_2X_PC_XPC_GPOL,
248*37c646dcSHerve Codina 			 pef2256_all_groups),
249*37c646dcSHerve Codina };
250*37c646dcSHerve Codina 
251*37c646dcSHerve Codina static const struct pef2256_function_desc pef2256_v12_functions[] = {
252*37c646dcSHerve Codina 	PEF2256_FUNCTION("SYPR",   PEF2256_12_PC_RPC_SYPR,   pef2256_rp_groups),
253*37c646dcSHerve Codina 	PEF2256_FUNCTION("RFM",    PEF2256_12_PC_RPC_RFM,    pef2256_rp_groups),
254*37c646dcSHerve Codina 	PEF2256_FUNCTION("RFMB",   PEF2256_12_PC_RPC_RFMB,   pef2256_rp_groups),
255*37c646dcSHerve Codina 	PEF2256_FUNCTION("RSIGM",  PEF2256_12_PC_RPC_RSIGM,  pef2256_rp_groups),
256*37c646dcSHerve Codina 	PEF2256_FUNCTION("RSIG",   PEF2256_12_PC_RPC_RSIG,   pef2256_rp_groups),
257*37c646dcSHerve Codina 	PEF2256_FUNCTION("DLR",    PEF2256_12_PC_RPC_DLR,    pef2256_rp_groups),
258*37c646dcSHerve Codina 	PEF2256_FUNCTION("FREEZE", PEF2256_12_PC_RPC_FREEZE, pef2256_rp_groups),
259*37c646dcSHerve Codina 	PEF2256_FUNCTION("RFSP",   PEF2256_12_PC_RPC_RFSP,   pef2256_rp_groups),
260*37c646dcSHerve Codina 
261*37c646dcSHerve Codina 	PEF2256_FUNCTION("SYPX",  PEF2256_12_PC_XPC_SYPX,  pef2256_xp_groups),
262*37c646dcSHerve Codina 	PEF2256_FUNCTION("XFMS",  PEF2256_12_PC_XPC_XFMS,  pef2256_xp_groups),
263*37c646dcSHerve Codina 	PEF2256_FUNCTION("XSIG",  PEF2256_12_PC_XPC_XSIG,  pef2256_xp_groups),
264*37c646dcSHerve Codina 	PEF2256_FUNCTION("TCLK",  PEF2256_12_PC_XPC_TCLK,  pef2256_xp_groups),
265*37c646dcSHerve Codina 	PEF2256_FUNCTION("XMFB",  PEF2256_12_PC_XPC_XMFB,  pef2256_xp_groups),
266*37c646dcSHerve Codina 	PEF2256_FUNCTION("XSIGM", PEF2256_12_PC_XPC_XSIGM, pef2256_xp_groups),
267*37c646dcSHerve Codina 	PEF2256_FUNCTION("DLX",   PEF2256_12_PC_XPC_DLX,   pef2256_xp_groups),
268*37c646dcSHerve Codina 	PEF2256_FUNCTION("XCLK",  PEF2256_12_PC_XPC_XCLK,  pef2256_xp_groups),
269*37c646dcSHerve Codina 	PEF2256_FUNCTION("XLT",   PEF2256_12_PC_XPC_XLT,   pef2256_xp_groups),
270*37c646dcSHerve Codina };
271*37c646dcSHerve Codina 
pef2256_register_pinctrl(struct pef2256_pinctrl * pef2256)272*37c646dcSHerve Codina static int pef2256_register_pinctrl(struct pef2256_pinctrl *pef2256)
273*37c646dcSHerve Codina {
274*37c646dcSHerve Codina 	struct pinctrl_dev	*pctrl;
275*37c646dcSHerve Codina 
276*37c646dcSHerve Codina 	pef2256->pctrl_desc.name    = dev_name(pef2256->dev);
277*37c646dcSHerve Codina 	pef2256->pctrl_desc.owner   = THIS_MODULE;
278*37c646dcSHerve Codina 	pef2256->pctrl_desc.pctlops = &pef2256_pctlops;
279*37c646dcSHerve Codina 	pef2256->pctrl_desc.pmxops  = &pef2256_pmxops;
280*37c646dcSHerve Codina 	if (pef2256->version == PEF2256_VERSION_1_2) {
281*37c646dcSHerve Codina 		pef2256->pctrl_desc.pins  = pef2256_v12_pins;
282*37c646dcSHerve Codina 		pef2256->pctrl_desc.npins = ARRAY_SIZE(pef2256_v12_pins);
283*37c646dcSHerve Codina 		pef2256->functions  = pef2256_v12_functions;
284*37c646dcSHerve Codina 		pef2256->nfunctions = ARRAY_SIZE(pef2256_v12_functions);
285*37c646dcSHerve Codina 	} else {
286*37c646dcSHerve Codina 		pef2256->pctrl_desc.pins  = pef2256_v2x_pins;
287*37c646dcSHerve Codina 		pef2256->pctrl_desc.npins = ARRAY_SIZE(pef2256_v2x_pins);
288*37c646dcSHerve Codina 		pef2256->functions  = pef2256_v2x_functions;
289*37c646dcSHerve Codina 		pef2256->nfunctions = ARRAY_SIZE(pef2256_v2x_functions);
290*37c646dcSHerve Codina 	}
291*37c646dcSHerve Codina 
292*37c646dcSHerve Codina 	pctrl = devm_pinctrl_register(pef2256->dev, &pef2256->pctrl_desc, pef2256);
293*37c646dcSHerve Codina 	if (IS_ERR(pctrl))
294*37c646dcSHerve Codina 		return dev_err_probe(pef2256->dev, PTR_ERR(pctrl),
295*37c646dcSHerve Codina 				     "pinctrl driver registration failed\n");
296*37c646dcSHerve Codina 
297*37c646dcSHerve Codina 	return 0;
298*37c646dcSHerve Codina }
299*37c646dcSHerve Codina 
pef2256_reset_pinmux(struct pef2256_pinctrl * pef2256)300*37c646dcSHerve Codina static void pef2256_reset_pinmux(struct pef2256_pinctrl *pef2256)
301*37c646dcSHerve Codina {
302*37c646dcSHerve Codina 	u8 val;
303*37c646dcSHerve Codina 	/*
304*37c646dcSHerve Codina 	 * Reset values cannot be used.
305*37c646dcSHerve Codina 	 * They define the SYPR/SYPX pin mux for all the RPx and XPx pins and
306*37c646dcSHerve Codina 	 * Only one pin can be muxed to SYPR and one pin can be muxed to SYPX.
307*37c646dcSHerve Codina 	 * Choose here an other reset value.
308*37c646dcSHerve Codina 	 */
309*37c646dcSHerve Codina 	if (pef2256->version == PEF2256_VERSION_1_2)
310*37c646dcSHerve Codina 		val = PEF2256_12_PC_XPC_XCLK | PEF2256_12_PC_RPC_RFSP;
311*37c646dcSHerve Codina 	else
312*37c646dcSHerve Codina 		val = PEF2256_2X_PC_XPC_GPI | PEF2256_2X_PC_RPC_GPI;
313*37c646dcSHerve Codina 
314*37c646dcSHerve Codina 	regmap_write(pef2256->regmap, PEF2256_PC1, val);
315*37c646dcSHerve Codina 	regmap_write(pef2256->regmap, PEF2256_PC2, val);
316*37c646dcSHerve Codina 	regmap_write(pef2256->regmap, PEF2256_PC3, val);
317*37c646dcSHerve Codina 	regmap_write(pef2256->regmap, PEF2256_PC4, val);
318*37c646dcSHerve Codina }
319*37c646dcSHerve Codina 
pef2256_pinctrl_probe(struct platform_device * pdev)320*37c646dcSHerve Codina static int pef2256_pinctrl_probe(struct platform_device *pdev)
321*37c646dcSHerve Codina {
322*37c646dcSHerve Codina 	struct pef2256_pinctrl *pef2256_pinctrl;
323*37c646dcSHerve Codina 	struct pef2256 *pef2256;
324*37c646dcSHerve Codina 	int ret;
325*37c646dcSHerve Codina 
326*37c646dcSHerve Codina 	pef2256_pinctrl = devm_kzalloc(&pdev->dev, sizeof(*pef2256_pinctrl), GFP_KERNEL);
327*37c646dcSHerve Codina 	if (!pef2256_pinctrl)
328*37c646dcSHerve Codina 		return -ENOMEM;
329*37c646dcSHerve Codina 
330*37c646dcSHerve Codina 	device_set_node(&pdev->dev, dev_fwnode(pdev->dev.parent));
331*37c646dcSHerve Codina 
332*37c646dcSHerve Codina 	pef2256 = dev_get_drvdata(pdev->dev.parent);
333*37c646dcSHerve Codina 
334*37c646dcSHerve Codina 	pef2256_pinctrl->dev = &pdev->dev;
335*37c646dcSHerve Codina 	pef2256_pinctrl->regmap = pef2256_get_regmap(pef2256);
336*37c646dcSHerve Codina 	pef2256_pinctrl->version = pef2256_get_version(pef2256);
337*37c646dcSHerve Codina 
338*37c646dcSHerve Codina 	platform_set_drvdata(pdev, pef2256_pinctrl);
339*37c646dcSHerve Codina 
340*37c646dcSHerve Codina 	pef2256_reset_pinmux(pef2256_pinctrl);
341*37c646dcSHerve Codina 	ret = pef2256_register_pinctrl(pef2256_pinctrl);
342*37c646dcSHerve Codina 	if (ret)
343*37c646dcSHerve Codina 		return ret;
344*37c646dcSHerve Codina 
345*37c646dcSHerve Codina 	return 0;
346*37c646dcSHerve Codina }
347*37c646dcSHerve Codina 
348*37c646dcSHerve Codina static struct platform_driver pef2256_pinctrl_driver = {
349*37c646dcSHerve Codina 	.driver = {
350*37c646dcSHerve Codina 		.name = "lantiq-pef2256-pinctrl",
351*37c646dcSHerve Codina 	},
352*37c646dcSHerve Codina 	.probe = pef2256_pinctrl_probe,
353*37c646dcSHerve Codina };
354*37c646dcSHerve Codina module_platform_driver(pef2256_pinctrl_driver);
355*37c646dcSHerve Codina 
356*37c646dcSHerve Codina MODULE_AUTHOR("Herve Codina <herve.codina@bootlin.com>");
357*37c646dcSHerve Codina MODULE_DESCRIPTION("PEF2256 pin controller driver");
358*37c646dcSHerve Codina MODULE_LICENSE("GPL");
359