Skip to content

Commit c19763c

Browse files
AngeloGioacchino Del Regnolinusw
authored andcommitted
pinctrl: mediatek: common-v1: Commonize spec_pupd callback
Reduce code size and duplication by using a common spec_pupd callback, which is possible to use on all of the pinctrl drivers that are using the v1 pinctrl-mtk-common code, with the exception of mt8135, which has a different handling compared to the others. Since the callback function signature was changed, this had to be propagated to pinctrl-mt8135's spec_pull_set(). 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 c8c206c commit c19763c

File tree

10 files changed

+46
-75
lines changed

10 files changed

+46
-75
lines changed

drivers/pinctrl/mediatek/pinctrl-mt2701.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,6 @@ static const struct mtk_pin_spec_pupd_set_samereg mt2701_spec_pupd[] = {
270270
MTK_PIN_PUPD_SPEC_SR(261, 0x140, 8, 9, 10), /* ms1 ins */
271271
};
272272

273-
static int mt2701_spec_pull_set(struct regmap *regmap, unsigned int pin,
274-
unsigned char align, bool isup, unsigned int r1r0)
275-
{
276-
return mtk_pctrl_spec_pull_set_samereg(regmap, mt2701_spec_pupd,
277-
ARRAY_SIZE(mt2701_spec_pupd), pin, align, isup, r1r0);
278-
}
279-
280273
static const struct mtk_pin_ies_smt_set mt2701_ies_set[] = {
281274
MTK_PIN_IES_SMT_SPEC(0, 6, 0xb20, 0),
282275
MTK_PIN_IES_SMT_SPEC(7, 9, 0xb20, 1),
@@ -508,7 +501,9 @@ static const struct mtk_pinctrl_devdata mt2701_pinctrl_data = {
508501
.n_grp_cls = ARRAY_SIZE(mt2701_drv_grp),
509502
.pin_drv_grp = mt2701_pin_drv,
510503
.n_pin_drv_grps = ARRAY_SIZE(mt2701_pin_drv),
511-
.spec_pull_set = mt2701_spec_pull_set,
504+
.spec_pupd = mt2701_spec_pupd,
505+
.n_spec_pupd = ARRAY_SIZE(mt2701_spec_pupd),
506+
.spec_pull_set = mtk_pctrl_spec_pull_set_samereg,
512507
.spec_ies_smt_set = mt2701_ies_smt_set,
513508
.spec_pinmux_set = mt2701_spec_pinmux_set,
514509
.spec_dir_set = mt2701_spec_dir_set,

drivers/pinctrl/mediatek/pinctrl-mt2712.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,6 @@ static const struct mtk_pin_spec_pupd_set_samereg mt2712_spec_pupd[] = {
8181
MTK_PIN_PUPD_SPEC_SR(142, 0xe60, 5, 4, 3)
8282
};
8383

84-
static int mt2712_spec_pull_set(struct regmap *regmap,
85-
unsigned int pin,
86-
unsigned char align,
87-
bool isup,
88-
unsigned int r1r0)
89-
{
90-
return mtk_pctrl_spec_pull_set_samereg(regmap, mt2712_spec_pupd,
91-
ARRAY_SIZE(mt2712_spec_pupd), pin, align, isup, r1r0);
92-
}
93-
9484
static const struct mtk_pin_ies_smt_set mt2712_smt_set[] = {
9585
MTK_PIN_IES_SMT_SPEC(0, 3, 0x900, 2),
9686
MTK_PIN_IES_SMT_SPEC(4, 7, 0x900, 0),
@@ -563,7 +553,9 @@ static const struct mtk_pinctrl_devdata mt2712_pinctrl_data = {
563553
.n_grp_cls = ARRAY_SIZE(mt2712_drv_grp),
564554
.pin_drv_grp = mt2712_pin_drv,
565555
.n_pin_drv_grps = ARRAY_SIZE(mt2712_pin_drv),
566-
.spec_pull_set = mt2712_spec_pull_set,
556+
.spec_pupd = mt2712_spec_pupd,
557+
.n_spec_pupd = ARRAY_SIZE(mt2712_spec_pupd),
558+
.spec_pull_set = mtk_pctrl_spec_pull_set_samereg,
567559
.spec_ies_smt_set = mt2712_ies_smt_set,
568560
.dir_offset = 0x0000,
569561
.pullen_offset = 0x0100,

drivers/pinctrl/mediatek/pinctrl-mt8127.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,6 @@ static const struct mtk_pin_spec_pupd_set_samereg mt8127_spec_pupd[] = {
172172
MTK_PIN_PUPD_SPEC_SR(142, 0xdc0, 2, 0, 1), /* EINT21 */
173173
};
174174

175-
static int mt8127_spec_pull_set(struct regmap *regmap, unsigned int pin,
176-
unsigned char align, bool isup, unsigned int r1r0)
177-
{
178-
return mtk_pctrl_spec_pull_set_samereg(regmap, mt8127_spec_pupd,
179-
ARRAY_SIZE(mt8127_spec_pupd), pin, align, isup, r1r0);
180-
}
181-
182175
static const struct mtk_pin_ies_smt_set mt8127_ies_set[] = {
183176
MTK_PIN_IES_SMT_SPEC(0, 9, 0x900, 0),
184177
MTK_PIN_IES_SMT_SPEC(10, 13, 0x900, 1),
@@ -279,7 +272,9 @@ static const struct mtk_pinctrl_devdata mt8127_pinctrl_data = {
279272
.n_grp_cls = ARRAY_SIZE(mt8127_drv_grp),
280273
.pin_drv_grp = mt8127_pin_drv,
281274
.n_pin_drv_grps = ARRAY_SIZE(mt8127_pin_drv),
282-
.spec_pull_set = mt8127_spec_pull_set,
275+
.spec_pupd = mt8127_spec_pupd,
276+
.n_spec_pupd = ARRAY_SIZE(mt8127_spec_pupd),
277+
.spec_pull_set = mtk_pctrl_spec_pull_set_samereg,
283278
.spec_ies_smt_set = mt8127_ies_smt_set,
284279
.dir_offset = 0x0000,
285280
.pullen_offset = 0x0100,

drivers/pinctrl/mediatek/pinctrl-mt8135.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,14 @@ static const struct mtk_spec_pull_set spec_pupd[] = {
230230
SPEC_PULL(202, PUPD_BASE2+0xc0, 10, R0_BASE1, 12, R1_BASE2+0xc0, 10)
231231
};
232232

233-
static int spec_pull_set(struct regmap *regmap, unsigned int pin,
234-
unsigned char align, bool isup, unsigned int r1r0)
233+
static int spec_pull_set(struct regmap *regmap,
234+
const struct mtk_pinctrl_devdata *devdata,
235+
unsigned int pin, bool isup, unsigned int r1r0)
235236
{
236237
unsigned int i;
237238
unsigned int reg_pupd, reg_set_r0, reg_set_r1;
238239
unsigned int reg_rst_r0, reg_rst_r1;
240+
unsigned char align = devdata->port_align;
239241
bool find = false;
240242

241243
for (i = 0; i < ARRAY_SIZE(spec_pupd); i++) {

drivers/pinctrl/mediatek/pinctrl-mt8167.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,6 @@ static const struct mtk_pin_spec_pupd_set_samereg mt8167_spec_pupd[] = {
186186
MTK_PIN_PUPD_SPEC_SR(120, 0xe00, 2, 1, 0),
187187
};
188188

189-
static int mt8167_spec_pull_set(struct regmap *regmap, unsigned int pin,
190-
unsigned char align, bool isup, unsigned int r1r0)
191-
{
192-
return mtk_pctrl_spec_pull_set_samereg(regmap, mt8167_spec_pupd,
193-
ARRAY_SIZE(mt8167_spec_pupd), pin, align, isup, r1r0);
194-
}
195-
196189
static const struct mtk_pin_ies_smt_set mt8167_ies_set[] = {
197190
MTK_PIN_IES_SMT_SPEC(0, 6, 0x900, 2),
198191
MTK_PIN_IES_SMT_SPEC(7, 10, 0x900, 3),
@@ -311,7 +304,9 @@ static const struct mtk_pinctrl_devdata mt8167_pinctrl_data = {
311304
.n_grp_cls = ARRAY_SIZE(mt8167_drv_grp),
312305
.pin_drv_grp = mt8167_pin_drv,
313306
.n_pin_drv_grps = ARRAY_SIZE(mt8167_pin_drv),
314-
.spec_pull_set = mt8167_spec_pull_set,
307+
.spec_pupd = mt8167_spec_pupd,
308+
.n_spec_pupd = ARRAY_SIZE(mt8167_spec_pupd),
309+
.spec_pull_set = mtk_pctrl_spec_pull_set_samereg,
315310
.spec_ies_smt_set = mt8167_ies_smt_set,
316311
.dir_offset = 0x0000,
317312
.pullen_offset = 0x0500,

drivers/pinctrl/mediatek/pinctrl-mt8173.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,6 @@ static const struct mtk_pin_spec_pupd_set_samereg mt8173_spec_pupd[] = {
6161
MTK_PIN_PUPD_SPEC_SR(27, 0xcd0, 2, 1, 0) /* ms3 cmd */
6262
};
6363

64-
static int mt8173_spec_pull_set(struct regmap *regmap, unsigned int pin,
65-
unsigned char align, bool isup, unsigned int r1r0)
66-
{
67-
return mtk_pctrl_spec_pull_set_samereg(regmap, mt8173_spec_pupd,
68-
ARRAY_SIZE(mt8173_spec_pupd), pin, align, isup, r1r0);
69-
}
70-
7164
static const struct mtk_pin_ies_smt_set mt8173_smt_set[] = {
7265
MTK_PIN_IES_SMT_SPEC(0, 4, 0x930, 1),
7366
MTK_PIN_IES_SMT_SPEC(5, 9, 0x930, 2),
@@ -319,7 +312,9 @@ static const struct mtk_pinctrl_devdata mt8173_pinctrl_data = {
319312
.n_grp_cls = ARRAY_SIZE(mt8173_drv_grp),
320313
.pin_drv_grp = mt8173_pin_drv,
321314
.n_pin_drv_grps = ARRAY_SIZE(mt8173_pin_drv),
322-
.spec_pull_set = mt8173_spec_pull_set,
315+
.spec_pupd = mt8173_spec_pupd,
316+
.n_spec_pupd = ARRAY_SIZE(mt8173_spec_pupd),
317+
.spec_pull_set = mtk_pctrl_spec_pull_set_samereg,
323318
.spec_ies_smt_set = mt8173_ies_smt_set,
324319
.dir_offset = 0x0000,
325320
.pullen_offset = 0x0100,

drivers/pinctrl/mediatek/pinctrl-mt8365.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -416,13 +416,6 @@ 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_spec_pull_set(struct regmap *regmap, unsigned int pin,
420-
unsigned char align, bool isup, unsigned int r1r0)
421-
{
422-
return mtk_pctrl_spec_pull_set_samereg(regmap, mt8365_spec_pupd,
423-
ARRAY_SIZE(mt8365_spec_pupd), pin, align, isup, r1r0);
424-
}
425-
426419
static int mt8365_ies_smt_set(struct regmap *regmap, unsigned int pin,
427420
unsigned char align, int value, enum pin_config_param arg)
428421
{
@@ -442,7 +435,9 @@ static const struct mtk_pinctrl_devdata mt8365_pinctrl_data = {
442435
.n_grp_cls = ARRAY_SIZE(mt8365_drv_grp),
443436
.pin_drv_grp = mt8365_pin_drv,
444437
.n_pin_drv_grps = ARRAY_SIZE(mt8365_pin_drv),
445-
.spec_pull_set = mt8365_spec_pull_set,
438+
.spec_pupd = mt8365_spec_pupd,
439+
.n_spec_pupd = ARRAY_SIZE(mt8365_spec_pupd),
440+
.spec_pull_set = mtk_pctrl_spec_pull_set_samereg,
446441
.spec_ies_smt_set = mt8365_ies_smt_set,
447442
.dir_offset = 0x0140,
448443
.dout_offset = 0x00A0,

drivers/pinctrl/mediatek/pinctrl-mt8516.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,6 @@ static const struct mtk_pin_spec_pupd_set_samereg mt8516_spec_pupd[] = {
186186
MTK_PIN_PUPD_SPEC_SR(120, 0xe00, 2, 1, 0),
187187
};
188188

189-
static int mt8516_spec_pull_set(struct regmap *regmap, unsigned int pin,
190-
unsigned char align, bool isup, unsigned int r1r0)
191-
{
192-
return mtk_pctrl_spec_pull_set_samereg(regmap, mt8516_spec_pupd,
193-
ARRAY_SIZE(mt8516_spec_pupd), pin, align, isup, r1r0);
194-
}
195-
196189
static const struct mtk_pin_ies_smt_set mt8516_ies_set[] = {
197190
MTK_PIN_IES_SMT_SPEC(0, 6, 0x900, 2),
198191
MTK_PIN_IES_SMT_SPEC(7, 10, 0x900, 3),
@@ -311,7 +304,9 @@ static const struct mtk_pinctrl_devdata mt8516_pinctrl_data = {
311304
.n_grp_cls = ARRAY_SIZE(mt8516_drv_grp),
312305
.pin_drv_grp = mt8516_pin_drv,
313306
.n_pin_drv_grps = ARRAY_SIZE(mt8516_pin_drv),
314-
.spec_pull_set = mt8516_spec_pull_set,
307+
.spec_pupd = mt8516_spec_pupd,
308+
.n_spec_pupd = ARRAY_SIZE(mt8516_spec_pupd),
309+
.spec_pull_set = mtk_pctrl_spec_pull_set_samereg,
315310
.spec_ies_smt_set = mt8516_ies_smt_set,
316311
.dir_offset = 0x0000,
317312
.pullen_offset = 0x0500,

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,18 +222,20 @@ static int mtk_pconf_set_driving(struct mtk_pinctrl *pctl,
222222
}
223223

224224
int mtk_pctrl_spec_pull_set_samereg(struct regmap *regmap,
225-
const struct mtk_pin_spec_pupd_set_samereg *pupd_infos,
226-
unsigned int info_num, unsigned int pin,
227-
unsigned char align, bool isup, unsigned int r1r0)
225+
const struct mtk_pinctrl_devdata *devdata,
226+
unsigned int pin, bool isup, unsigned int r1r0)
228227
{
229228
unsigned int i;
230229
unsigned int reg_pupd, reg_set, reg_rst;
231230
unsigned int bit_pupd, bit_r0, bit_r1;
232231
const struct mtk_pin_spec_pupd_set_samereg *spec_pupd_pin;
233232
bool find = false;
234233

235-
for (i = 0; i < info_num; i++) {
236-
if (pin == pupd_infos[i].pin) {
234+
if (!devdata->spec_pupd)
235+
return -EINVAL;
236+
237+
for (i = 0; i < devdata->n_spec_pupd; i++) {
238+
if (pin == devdata->spec_pupd[i].pin) {
237239
find = true;
238240
break;
239241
}
@@ -242,9 +244,9 @@ int mtk_pctrl_spec_pull_set_samereg(struct regmap *regmap,
242244
if (!find)
243245
return -EINVAL;
244246

245-
spec_pupd_pin = pupd_infos + i;
246-
reg_set = spec_pupd_pin->offset + align;
247-
reg_rst = spec_pupd_pin->offset + (align << 1);
247+
spec_pupd_pin = devdata->spec_pupd + i;
248+
reg_set = spec_pupd_pin->offset + devdata->port_align;
249+
reg_rst = spec_pupd_pin->offset + (devdata->port_align << 1);
248250

249251
if (isup)
250252
reg_pupd = reg_rst;
@@ -298,7 +300,8 @@ static int mtk_pconf_set_pull_select(struct mtk_pinctrl *pctl,
298300
*/
299301
r1r0 = enable ? arg : MTK_PUPD_SET_R1R0_00;
300302
ret = pctl->devdata->spec_pull_set(mtk_get_regmap(pctl, pin),
301-
pin, pctl->devdata->port_align, isup, r1r0);
303+
pctl->devdata, pin, isup,
304+
r1r0);
302305
if (!ret)
303306
return 0;
304307
}

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ struct mtk_eint_offsets {
193193
*
194194
* @grp_desc: The driving group info.
195195
* @pin_drv_grp: The driving group for all pins.
196+
* @spec_pupd: Special pull up/down setting
197+
* @n_spec_pupd: Number of entries in spec_pupd
196198
* @spec_pull_set: Each SoC may have special pins for pull up/down setting,
197199
* these pins' pull setting are very different, they have separate pull
198200
* up/down bit, R0 and R1 resistor bit, so they need special pull setting.
@@ -231,8 +233,11 @@ struct mtk_pinctrl_devdata {
231233
unsigned int n_grp_cls;
232234
const struct mtk_pin_drv_grp *pin_drv_grp;
233235
unsigned int n_pin_drv_grps;
234-
int (*spec_pull_set)(struct regmap *reg, unsigned int pin,
235-
unsigned char align, bool isup, unsigned int arg);
236+
const struct mtk_pin_spec_pupd_set_samereg *spec_pupd;
237+
unsigned int n_spec_pupd;
238+
int (*spec_pull_set)(struct regmap *regmap,
239+
const struct mtk_pinctrl_devdata *devdata,
240+
unsigned int pin, bool isup, unsigned int r1r0);
236241
int (*spec_ies_smt_set)(struct regmap *reg, unsigned int pin,
237242
unsigned char align, int value, enum pin_config_param arg);
238243
void (*spec_pinmux_set)(struct regmap *reg, unsigned int pin,
@@ -280,9 +285,8 @@ int mtk_pctrl_init(struct platform_device *pdev,
280285
int mtk_pctrl_common_probe(struct platform_device *pdev);
281286

282287
int mtk_pctrl_spec_pull_set_samereg(struct regmap *regmap,
283-
const struct mtk_pin_spec_pupd_set_samereg *pupd_infos,
284-
unsigned int info_num, unsigned int pin,
285-
unsigned char align, bool isup, unsigned int r1r0);
288+
const struct mtk_pinctrl_devdata *devdata,
289+
unsigned int pin, bool isup, unsigned int r1r0);
286290

287291
int mtk_pconf_spec_set_ies_smt_range(struct regmap *regmap,
288292
const struct mtk_pin_ies_smt_set *ies_smt_infos, unsigned int info_num,

0 commit comments

Comments
 (0)