@@ -493,6 +493,23 @@ static void rzv2h_pmc_writeb(struct rzg2l_pinctrl *pctrl, u8 val, u16 offset)
493
493
writeb (pwpr & ~PWPR_REGWE_A , pctrl -> base + regs -> pwpr );
494
494
}
495
495
496
+ static int rzg2l_validate_pin (struct rzg2l_pinctrl * pctrl ,
497
+ u64 cfg , u32 port , u8 bit )
498
+ {
499
+ u8 pinmap = FIELD_GET (PIN_CFG_PIN_MAP_MASK , cfg );
500
+ u32 off = RZG2L_PIN_CFG_TO_PORT_OFFSET (cfg );
501
+ u64 data ;
502
+
503
+ if (!(pinmap & BIT (bit )) || port >= pctrl -> data -> n_port_pins )
504
+ return - EINVAL ;
505
+
506
+ data = pctrl -> data -> port_pin_configs [port ];
507
+ if (off != RZG2L_PIN_CFG_TO_PORT_OFFSET (data ))
508
+ return - EINVAL ;
509
+
510
+ return 0 ;
511
+ }
512
+
496
513
static void rzg2l_pinctrl_set_pfc_mode (struct rzg2l_pinctrl * pctrl ,
497
514
u8 pin , u8 off , u8 func )
498
515
{
@@ -536,6 +553,7 @@ static int rzg2l_pinctrl_set_mux(struct pinctrl_dev *pctldev,
536
553
unsigned int i , * psel_val ;
537
554
struct group_desc * group ;
538
555
const unsigned int * pins ;
556
+ int ret ;
539
557
540
558
func = pinmux_generic_get_function (pctldev , func_selector );
541
559
if (!func )
@@ -552,6 +570,10 @@ static int rzg2l_pinctrl_set_mux(struct pinctrl_dev *pctldev,
552
570
u32 off = RZG2L_PIN_CFG_TO_PORT_OFFSET (* pin_data );
553
571
u32 pin = RZG2L_PIN_ID_TO_PIN (pins [i ]);
554
572
573
+ ret = rzg2l_validate_pin (pctrl , * pin_data , RZG2L_PIN_ID_TO_PORT (pins [i ]), pin );
574
+ if (ret )
575
+ return ret ;
576
+
555
577
dev_dbg (pctrl -> dev , "port:%u pin: %u off:%x PSEL:%u\n" ,
556
578
RZG2L_PIN_ID_TO_PORT (pins [i ]), pin , off , psel_val [i ] - hwcfg -> func_base );
557
579
@@ -806,23 +828,6 @@ static int rzg2l_dt_node_to_map(struct pinctrl_dev *pctldev,
806
828
return ret ;
807
829
}
808
830
809
- static int rzg2l_validate_gpio_pin (struct rzg2l_pinctrl * pctrl ,
810
- u64 cfg , u32 port , u8 bit )
811
- {
812
- u8 pinmap = FIELD_GET (PIN_CFG_PIN_MAP_MASK , cfg );
813
- u32 off = RZG2L_PIN_CFG_TO_PORT_OFFSET (cfg );
814
- u64 data ;
815
-
816
- if (!(pinmap & BIT (bit )) || port >= pctrl -> data -> n_port_pins )
817
- return - EINVAL ;
818
-
819
- data = pctrl -> data -> port_pin_configs [port ];
820
- if (off != RZG2L_PIN_CFG_TO_PORT_OFFSET (data ))
821
- return - EINVAL ;
822
-
823
- return 0 ;
824
- }
825
-
826
831
static u32 rzg2l_read_pin_config (struct rzg2l_pinctrl * pctrl , u32 offset ,
827
832
u8 bit , u32 mask )
828
833
{
@@ -1287,7 +1292,7 @@ static int rzg2l_pinctrl_pinconf_get(struct pinctrl_dev *pctldev,
1287
1292
} else {
1288
1293
bit = RZG2L_PIN_ID_TO_PIN (_pin );
1289
1294
1290
- if (rzg2l_validate_gpio_pin (pctrl , * pin_data , RZG2L_PIN_ID_TO_PORT (_pin ), bit ))
1295
+ if (rzg2l_validate_pin (pctrl , * pin_data , RZG2L_PIN_ID_TO_PORT (_pin ), bit ))
1291
1296
return - EINVAL ;
1292
1297
}
1293
1298
@@ -1447,7 +1452,7 @@ static int rzg2l_pinctrl_pinconf_set(struct pinctrl_dev *pctldev,
1447
1452
} else {
1448
1453
bit = RZG2L_PIN_ID_TO_PIN (_pin );
1449
1454
1450
- if (rzg2l_validate_gpio_pin (pctrl , * pin_data , RZG2L_PIN_ID_TO_PORT (_pin ), bit ))
1455
+ if (rzg2l_validate_pin (pctrl , * pin_data , RZG2L_PIN_ID_TO_PORT (_pin ), bit ))
1451
1456
return - EINVAL ;
1452
1457
}
1453
1458
@@ -1687,7 +1692,7 @@ static int rzg2l_gpio_request(struct gpio_chip *chip, unsigned int offset)
1687
1692
u8 reg8 ;
1688
1693
int ret ;
1689
1694
1690
- ret = rzg2l_validate_gpio_pin (pctrl , * pin_data , port , bit );
1695
+ ret = rzg2l_validate_pin (pctrl , * pin_data , port , bit );
1691
1696
if (ret )
1692
1697
return ret ;
1693
1698
0 commit comments