Skip to content

Commit 156f721

Browse files
AngeloGioacchino Del Regnolinusw
authored andcommitted
pinctrl: mediatek: common-v1: Commonize spec_ies_smt_set callback
All of the MediaTek pinctrl drivers registering with pinctrl-mtk-common that are offering a .spec_ies_smt_set() callback are declaring their own function which is doing exactly the same on all drivers: calling mtk_pconf_spec_set_ies_smt_range() with their struct and a simple check. Commonize this callback by adding the ies and smt structure pointers to struct mtk_pinctrl_devdata and changing the callback signature to take it. Removing the callback and checking for the existance of the spec_smt and/or spec_ies data would allow us to staticize the function mtk_pconf_spec_set_ies_smt_range(), but this solution was avoided as to keep flexibility, as some SoCs may need to perform a very different operation compared to what this commonized function is doing. Signed-off-by: AngeloGioacchino Del Regno <[email protected]> Reviewed-by: Chen-Yu Tsai <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Linus Walleij <[email protected]>
1 parent c19763c commit 156f721

File tree

9 files changed

+71
-103
lines changed

9 files changed

+71
-103
lines changed

drivers/pinctrl/mediatek/pinctrl-mt2701.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -429,18 +429,6 @@ static const struct mtk_pin_ies_smt_set mt2701_smt_set[] = {
429429
MTK_PIN_IES_SMT_SPEC(278, 278, 0xb70, 13),
430430
};
431431

432-
static int mt2701_ies_smt_set(struct regmap *regmap, unsigned int pin,
433-
unsigned char align, int value, enum pin_config_param arg)
434-
{
435-
if (arg == PIN_CONFIG_INPUT_ENABLE)
436-
return mtk_pconf_spec_set_ies_smt_range(regmap, mt2701_ies_set,
437-
ARRAY_SIZE(mt2701_ies_set), pin, align, value);
438-
else if (arg == PIN_CONFIG_INPUT_SCHMITT_ENABLE)
439-
return mtk_pconf_spec_set_ies_smt_range(regmap, mt2701_smt_set,
440-
ARRAY_SIZE(mt2701_smt_set), pin, align, value);
441-
return -EINVAL;
442-
}
443-
444432
static const struct mtk_spec_pinmux_set mt2701_spec_pinmux[] = {
445433
MTK_PINMUX_SPEC(22, 0xb10, 3),
446434
MTK_PINMUX_SPEC(23, 0xb10, 4),
@@ -501,10 +489,14 @@ static const struct mtk_pinctrl_devdata mt2701_pinctrl_data = {
501489
.n_grp_cls = ARRAY_SIZE(mt2701_drv_grp),
502490
.pin_drv_grp = mt2701_pin_drv,
503491
.n_pin_drv_grps = ARRAY_SIZE(mt2701_pin_drv),
492+
.spec_ies = mt2701_ies_set,
493+
.n_spec_ies = ARRAY_SIZE(mt2701_ies_set),
504494
.spec_pupd = mt2701_spec_pupd,
505495
.n_spec_pupd = ARRAY_SIZE(mt2701_spec_pupd),
496+
.spec_smt = mt2701_smt_set,
497+
.n_spec_smt = ARRAY_SIZE(mt2701_smt_set),
506498
.spec_pull_set = mtk_pctrl_spec_pull_set_samereg,
507-
.spec_ies_smt_set = mt2701_ies_smt_set,
499+
.spec_ies_smt_set = mtk_pconf_spec_set_ies_smt_range,
508500
.spec_pinmux_set = mt2701_spec_pinmux_set,
509501
.spec_dir_set = mt2701_spec_dir_set,
510502
.dir_offset = 0x0000,

drivers/pinctrl/mediatek/pinctrl-mt2712.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -275,19 +275,6 @@ static const struct mtk_pin_ies_smt_set mt2712_ies_set[] = {
275275
MTK_PIN_IES_SMT_SPEC(207, 209, 0x8b0, 15)
276276
};
277277

278-
static int mt2712_ies_smt_set(struct regmap *regmap, unsigned int pin,
279-
unsigned char align,
280-
int value, enum pin_config_param arg)
281-
{
282-
if (arg == PIN_CONFIG_INPUT_ENABLE)
283-
return mtk_pconf_spec_set_ies_smt_range(regmap, mt2712_ies_set,
284-
ARRAY_SIZE(mt2712_ies_set), pin, align, value);
285-
if (arg == PIN_CONFIG_INPUT_SCHMITT_ENABLE)
286-
return mtk_pconf_spec_set_ies_smt_range(regmap, mt2712_smt_set,
287-
ARRAY_SIZE(mt2712_smt_set), pin, align, value);
288-
return -EINVAL;
289-
}
290-
291278
static const struct mtk_drv_group_desc mt2712_drv_grp[] = {
292279
/* 0E4E8SR 4/8/12/16 */
293280
MTK_DRV_GRP(4, 16, 1, 2, 4),
@@ -553,10 +540,14 @@ static const struct mtk_pinctrl_devdata mt2712_pinctrl_data = {
553540
.n_grp_cls = ARRAY_SIZE(mt2712_drv_grp),
554541
.pin_drv_grp = mt2712_pin_drv,
555542
.n_pin_drv_grps = ARRAY_SIZE(mt2712_pin_drv),
543+
.spec_ies = mt2712_ies_set,
544+
.n_spec_ies = ARRAY_SIZE(mt2712_ies_set),
556545
.spec_pupd = mt2712_spec_pupd,
557546
.n_spec_pupd = ARRAY_SIZE(mt2712_spec_pupd),
547+
.spec_smt = mt2712_smt_set,
548+
.n_spec_smt = ARRAY_SIZE(mt2712_smt_set),
558549
.spec_pull_set = mtk_pctrl_spec_pull_set_samereg,
559-
.spec_ies_smt_set = mt2712_ies_smt_set,
550+
.spec_ies_smt_set = mtk_pconf_spec_set_ies_smt_range,
560551
.dir_offset = 0x0000,
561552
.pullen_offset = 0x0100,
562553
.pullsel_offset = 0x0200,

drivers/pinctrl/mediatek/pinctrl-mt8127.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -252,30 +252,21 @@ static const struct mtk_pin_ies_smt_set mt8127_smt_set[] = {
252252
MTK_PIN_IES_SMT_SPEC(142, 142, 0x920, 13),
253253
};
254254

255-
static int mt8127_ies_smt_set(struct regmap *regmap, unsigned int pin,
256-
unsigned char align, int value, enum pin_config_param arg)
257-
{
258-
if (arg == PIN_CONFIG_INPUT_ENABLE)
259-
return mtk_pconf_spec_set_ies_smt_range(regmap, mt8127_ies_set,
260-
ARRAY_SIZE(mt8127_ies_set), pin, align, value);
261-
else if (arg == PIN_CONFIG_INPUT_SCHMITT_ENABLE)
262-
return mtk_pconf_spec_set_ies_smt_range(regmap, mt8127_smt_set,
263-
ARRAY_SIZE(mt8127_smt_set), pin, align, value);
264-
return -EINVAL;
265-
}
266-
267-
268255
static const struct mtk_pinctrl_devdata mt8127_pinctrl_data = {
269256
.pins = mtk_pins_mt8127,
270257
.npins = ARRAY_SIZE(mtk_pins_mt8127),
271258
.grp_desc = mt8127_drv_grp,
272259
.n_grp_cls = ARRAY_SIZE(mt8127_drv_grp),
273260
.pin_drv_grp = mt8127_pin_drv,
274261
.n_pin_drv_grps = ARRAY_SIZE(mt8127_pin_drv),
262+
.spec_ies = mt8127_ies_set,
263+
.n_spec_ies = ARRAY_SIZE(mt8127_ies_set),
275264
.spec_pupd = mt8127_spec_pupd,
276265
.n_spec_pupd = ARRAY_SIZE(mt8127_spec_pupd),
266+
.spec_smt = mt8127_smt_set,
267+
.n_spec_smt = ARRAY_SIZE(mt8127_smt_set),
277268
.spec_pull_set = mtk_pctrl_spec_pull_set_samereg,
278-
.spec_ies_smt_set = mt8127_ies_smt_set,
269+
.spec_ies_smt_set = mtk_pconf_spec_set_ies_smt_range,
279270
.dir_offset = 0x0000,
280271
.pullen_offset = 0x0100,
281272
.pullsel_offset = 0x0200,

drivers/pinctrl/mediatek/pinctrl-mt8167.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -285,29 +285,21 @@ static const struct mtk_pin_ies_smt_set mt8167_smt_set[] = {
285285
MTK_PIN_IES_SMT_SPEC(121, 124, 0xA10, 9),
286286
};
287287

288-
static int mt8167_ies_smt_set(struct regmap *regmap, unsigned int pin,
289-
unsigned char align, int value, enum pin_config_param arg)
290-
{
291-
if (arg == PIN_CONFIG_INPUT_ENABLE)
292-
return mtk_pconf_spec_set_ies_smt_range(regmap, mt8167_ies_set,
293-
ARRAY_SIZE(mt8167_ies_set), pin, align, value);
294-
else if (arg == PIN_CONFIG_INPUT_SCHMITT_ENABLE)
295-
return mtk_pconf_spec_set_ies_smt_range(regmap, mt8167_smt_set,
296-
ARRAY_SIZE(mt8167_smt_set), pin, align, value);
297-
return -EINVAL;
298-
}
299-
300288
static const struct mtk_pinctrl_devdata mt8167_pinctrl_data = {
301289
.pins = mtk_pins_mt8167,
302290
.npins = ARRAY_SIZE(mtk_pins_mt8167),
303291
.grp_desc = mt8167_drv_grp,
304292
.n_grp_cls = ARRAY_SIZE(mt8167_drv_grp),
305293
.pin_drv_grp = mt8167_pin_drv,
306294
.n_pin_drv_grps = ARRAY_SIZE(mt8167_pin_drv),
295+
.spec_ies = mt8167_ies_set,
296+
.n_spec_ies = ARRAY_SIZE(mt8167_ies_set),
307297
.spec_pupd = mt8167_spec_pupd,
308298
.n_spec_pupd = ARRAY_SIZE(mt8167_spec_pupd),
299+
.spec_smt = mt8167_smt_set,
300+
.n_spec_smt = ARRAY_SIZE(mt8167_smt_set),
309301
.spec_pull_set = mtk_pctrl_spec_pull_set_samereg,
310-
.spec_ies_smt_set = mt8167_ies_smt_set,
302+
.spec_ies_smt_set = mtk_pconf_spec_set_ies_smt_range,
311303
.dir_offset = 0x0000,
312304
.pullen_offset = 0x0500,
313305
.pullsel_offset = 0x0600,

drivers/pinctrl/mediatek/pinctrl-mt8173.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -167,18 +167,6 @@ static const struct mtk_pin_ies_smt_set mt8173_ies_set[] = {
167167
MTK_PIN_IES_SMT_SPEC(133, 134, 0x910, 8)
168168
};
169169

170-
static int mt8173_ies_smt_set(struct regmap *regmap, unsigned int pin,
171-
unsigned char align, int value, enum pin_config_param arg)
172-
{
173-
if (arg == PIN_CONFIG_INPUT_ENABLE)
174-
return mtk_pconf_spec_set_ies_smt_range(regmap, mt8173_ies_set,
175-
ARRAY_SIZE(mt8173_ies_set), pin, align, value);
176-
else if (arg == PIN_CONFIG_INPUT_SCHMITT_ENABLE)
177-
return mtk_pconf_spec_set_ies_smt_range(regmap, mt8173_smt_set,
178-
ARRAY_SIZE(mt8173_smt_set), pin, align, value);
179-
return -EINVAL;
180-
}
181-
182170
static const struct mtk_drv_group_desc mt8173_drv_grp[] = {
183171
/* 0E4E8SR 4/8/12/16 */
184172
MTK_DRV_GRP(4, 16, 1, 2, 4),
@@ -312,10 +300,14 @@ static const struct mtk_pinctrl_devdata mt8173_pinctrl_data = {
312300
.n_grp_cls = ARRAY_SIZE(mt8173_drv_grp),
313301
.pin_drv_grp = mt8173_pin_drv,
314302
.n_pin_drv_grps = ARRAY_SIZE(mt8173_pin_drv),
303+
.spec_ies = mt8173_ies_set,
304+
.n_spec_ies = ARRAY_SIZE(mt8173_ies_set),
315305
.spec_pupd = mt8173_spec_pupd,
316306
.n_spec_pupd = ARRAY_SIZE(mt8173_spec_pupd),
307+
.spec_smt = mt8173_smt_set,
308+
.n_spec_smt = ARRAY_SIZE(mt8173_smt_set),
317309
.spec_pull_set = mtk_pctrl_spec_pull_set_samereg,
318-
.spec_ies_smt_set = mt8173_ies_smt_set,
310+
.spec_ies_smt_set = mtk_pconf_spec_set_ies_smt_range,
319311
.dir_offset = 0x0000,
320312
.pullen_offset = 0x0100,
321313
.pullsel_offset = 0x0200,

drivers/pinctrl/mediatek/pinctrl-mt8365.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -416,29 +416,21 @@ static const struct mtk_pin_ies_smt_set mt8365_smt_set[] = {
416416
MTK_PIN_IES_SMT_SPEC(144, 144, 0x480, 22),
417417
};
418418

419-
static int mt8365_ies_smt_set(struct regmap *regmap, unsigned int pin,
420-
unsigned char align, int value, enum pin_config_param arg)
421-
{
422-
if (arg == PIN_CONFIG_INPUT_ENABLE)
423-
return mtk_pconf_spec_set_ies_smt_range(regmap, mt8365_ies_set,
424-
ARRAY_SIZE(mt8365_ies_set), pin, align, value);
425-
else if (arg == PIN_CONFIG_INPUT_SCHMITT_ENABLE)
426-
return mtk_pconf_spec_set_ies_smt_range(regmap, mt8365_smt_set,
427-
ARRAY_SIZE(mt8365_smt_set), pin, align, value);
428-
return -EINVAL;
429-
}
430-
431419
static const struct mtk_pinctrl_devdata mt8365_pinctrl_data = {
432420
.pins = mtk_pins_mt8365,
433421
.npins = ARRAY_SIZE(mtk_pins_mt8365),
434422
.grp_desc = mt8365_drv_grp,
435423
.n_grp_cls = ARRAY_SIZE(mt8365_drv_grp),
436424
.pin_drv_grp = mt8365_pin_drv,
437425
.n_pin_drv_grps = ARRAY_SIZE(mt8365_pin_drv),
426+
.spec_ies = mt8365_ies_set,
427+
.n_spec_ies = ARRAY_SIZE(mt8365_ies_set),
428+
.spec_smt = mt8365_smt_set,
429+
.n_spec_smt = ARRAY_SIZE(mt8365_smt_set),
438430
.spec_pupd = mt8365_spec_pupd,
439431
.n_spec_pupd = ARRAY_SIZE(mt8365_spec_pupd),
440432
.spec_pull_set = mtk_pctrl_spec_pull_set_samereg,
441-
.spec_ies_smt_set = mt8365_ies_smt_set,
433+
.spec_ies_smt_set = mtk_pconf_spec_set_ies_smt_range,
442434
.dir_offset = 0x0140,
443435
.dout_offset = 0x00A0,
444436
.din_offset = 0x0000,

drivers/pinctrl/mediatek/pinctrl-mt8516.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -285,29 +285,21 @@ static const struct mtk_pin_ies_smt_set mt8516_smt_set[] = {
285285
MTK_PIN_IES_SMT_SPEC(121, 124, 0xA10, 9),
286286
};
287287

288-
static int mt8516_ies_smt_set(struct regmap *regmap, unsigned int pin,
289-
unsigned char align, int value, enum pin_config_param arg)
290-
{
291-
if (arg == PIN_CONFIG_INPUT_ENABLE)
292-
return mtk_pconf_spec_set_ies_smt_range(regmap, mt8516_ies_set,
293-
ARRAY_SIZE(mt8516_ies_set), pin, align, value);
294-
else if (arg == PIN_CONFIG_INPUT_SCHMITT_ENABLE)
295-
return mtk_pconf_spec_set_ies_smt_range(regmap, mt8516_smt_set,
296-
ARRAY_SIZE(mt8516_smt_set), pin, align, value);
297-
return -EINVAL;
298-
}
299-
300288
static const struct mtk_pinctrl_devdata mt8516_pinctrl_data = {
301289
.pins = mtk_pins_mt8516,
302290
.npins = ARRAY_SIZE(mtk_pins_mt8516),
303291
.grp_desc = mt8516_drv_grp,
304292
.n_grp_cls = ARRAY_SIZE(mt8516_drv_grp),
305293
.pin_drv_grp = mt8516_pin_drv,
306294
.n_pin_drv_grps = ARRAY_SIZE(mt8516_pin_drv),
295+
.spec_ies = mt8516_ies_set,
296+
.n_spec_ies = ARRAY_SIZE(mt8516_ies_set),
307297
.spec_pupd = mt8516_spec_pupd,
308298
.n_spec_pupd = ARRAY_SIZE(mt8516_spec_pupd),
299+
.spec_smt = mt8516_smt_set,
300+
.n_spec_smt = ARRAY_SIZE(mt8516_smt_set),
309301
.spec_pull_set = mtk_pctrl_spec_pull_set_samereg,
310-
.spec_ies_smt_set = mt8516_ies_smt_set,
302+
.spec_ies_smt_set = mtk_pconf_spec_set_ies_smt_range,
311303
.dir_offset = 0x0000,
312304
.pullen_offset = 0x0500,
313305
.pullsel_offset = 0x0600,

drivers/pinctrl/mediatek/pinctrl-mtk-common.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static int mtk_pconf_set_ies_smt(struct mtk_pinctrl *pctl, unsigned pin,
131131
*/
132132
if (pctl->devdata->spec_ies_smt_set) {
133133
return pctl->devdata->spec_ies_smt_set(mtk_get_regmap(pctl, pin),
134-
pin, pctl->devdata->port_align, value, arg);
134+
pctl->devdata, pin, value, arg);
135135
}
136136

137137
if (arg == PIN_CONFIG_INPUT_ENABLE)
@@ -151,10 +151,27 @@ static int mtk_pconf_set_ies_smt(struct mtk_pinctrl *pctl, unsigned pin,
151151
}
152152

153153
int mtk_pconf_spec_set_ies_smt_range(struct regmap *regmap,
154-
const struct mtk_pin_ies_smt_set *ies_smt_infos, unsigned int info_num,
155-
unsigned int pin, unsigned char align, int value)
154+
const struct mtk_pinctrl_devdata *devdata,
155+
unsigned int pin, int value, enum pin_config_param arg)
156156
{
157-
unsigned int i, reg_addr, bit;
157+
const struct mtk_pin_ies_smt_set *ies_smt_infos = NULL;
158+
unsigned int i, info_num, reg_addr, bit;
159+
160+
switch (arg) {
161+
case PIN_CONFIG_INPUT_ENABLE:
162+
ies_smt_infos = devdata->spec_ies;
163+
info_num = devdata->n_spec_ies;
164+
break;
165+
case PIN_CONFIG_INPUT_SCHMITT_ENABLE:
166+
ies_smt_infos = devdata->spec_smt;
167+
info_num = devdata->n_spec_smt;
168+
break;
169+
default:
170+
break;
171+
};
172+
173+
if (!ies_smt_infos)
174+
return -EINVAL;
158175

159176
for (i = 0; i < info_num; i++) {
160177
if (pin >= ies_smt_infos[i].start &&
@@ -167,9 +184,9 @@ int mtk_pconf_spec_set_ies_smt_range(struct regmap *regmap,
167184
return -EINVAL;
168185

169186
if (value)
170-
reg_addr = ies_smt_infos[i].offset + align;
187+
reg_addr = ies_smt_infos[i].offset + devdata->port_align;
171188
else
172-
reg_addr = ies_smt_infos[i].offset + (align << 1);
189+
reg_addr = ies_smt_infos[i].offset + (devdata->port_align << 1);
173190

174191
bit = BIT(ies_smt_infos[i].bit);
175192
regmap_write(regmap, reg_addr, bit);

drivers/pinctrl/mediatek/pinctrl-mtk-common.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,12 @@ struct mtk_eint_offsets {
193193
*
194194
* @grp_desc: The driving group info.
195195
* @pin_drv_grp: The driving group for all pins.
196+
* @spec_ies: Special pin setting for input enable
197+
* @n_spec_ies: Number of entries in spec_ies
196198
* @spec_pupd: Special pull up/down setting
197199
* @n_spec_pupd: Number of entries in spec_pupd
200+
* @spec_smt: Special pin setting for schmitt
201+
* @n_spec_smt: Number of entries in spec_smt
198202
* @spec_pull_set: Each SoC may have special pins for pull up/down setting,
199203
* these pins' pull setting are very different, they have separate pull
200204
* up/down bit, R0 and R1 resistor bit, so they need special pull setting.
@@ -233,13 +237,18 @@ struct mtk_pinctrl_devdata {
233237
unsigned int n_grp_cls;
234238
const struct mtk_pin_drv_grp *pin_drv_grp;
235239
unsigned int n_pin_drv_grps;
240+
const struct mtk_pin_ies_smt_set *spec_ies;
241+
unsigned int n_spec_ies;
236242
const struct mtk_pin_spec_pupd_set_samereg *spec_pupd;
237243
unsigned int n_spec_pupd;
244+
const struct mtk_pin_ies_smt_set *spec_smt;
245+
unsigned int n_spec_smt;
238246
int (*spec_pull_set)(struct regmap *regmap,
239247
const struct mtk_pinctrl_devdata *devdata,
240248
unsigned int pin, bool isup, unsigned int r1r0);
241-
int (*spec_ies_smt_set)(struct regmap *reg, unsigned int pin,
242-
unsigned char align, int value, enum pin_config_param arg);
249+
int (*spec_ies_smt_set)(struct regmap *reg,
250+
const struct mtk_pinctrl_devdata *devdata,
251+
unsigned int pin, int value, enum pin_config_param arg);
243252
void (*spec_pinmux_set)(struct regmap *reg, unsigned int pin,
244253
unsigned int mode);
245254
void (*spec_dir_set)(unsigned int *reg_addr, unsigned int pin);
@@ -289,8 +298,8 @@ int mtk_pctrl_spec_pull_set_samereg(struct regmap *regmap,
289298
unsigned int pin, bool isup, unsigned int r1r0);
290299

291300
int mtk_pconf_spec_set_ies_smt_range(struct regmap *regmap,
292-
const struct mtk_pin_ies_smt_set *ies_smt_infos, unsigned int info_num,
293-
unsigned int pin, unsigned char align, int value);
301+
const struct mtk_pinctrl_devdata *devdata,
302+
unsigned int pin, int value, enum pin_config_param arg);
294303

295304
extern const struct dev_pm_ops mtk_eint_pm_ops;
296305

0 commit comments

Comments
 (0)