106106#define PM_OUTPUT 0x2
107107
108108#define RZG2L_PIN_ID_TO_PORT (id ) ((id) / RZG2L_PINS_PER_PORT)
109+ #define RZG2L_PIN_ID_TO_PORT_OFFSET (id ) (RZG2L_PIN_ID_TO_PORT(id) + 0x10)
109110#define RZG2L_PIN_ID_TO_PIN (id ) ((id) % RZG2L_PINS_PER_PORT)
110111
111112struct rzg2l_dedicated_configs {
@@ -424,6 +425,23 @@ static int rzg2l_dt_node_to_map(struct pinctrl_dev *pctldev,
424425 return ret ;
425426}
426427
428+ static int rzg2l_validate_gpio_pin (struct rzg2l_pinctrl * pctrl ,
429+ u32 cfg , u32 port , u8 bit )
430+ {
431+ u8 pincount = RZG2L_GPIO_PORT_GET_PINCNT (cfg );
432+ u32 port_index = RZG2L_GPIO_PORT_GET_INDEX (cfg );
433+ u32 data ;
434+
435+ if (bit >= pincount || port >= pctrl -> data -> n_port_pins )
436+ return - EINVAL ;
437+
438+ data = pctrl -> data -> port_pin_configs [port ];
439+ if (port_index != RZG2L_GPIO_PORT_GET_INDEX (data ))
440+ return - EINVAL ;
441+
442+ return 0 ;
443+ }
444+
427445static u32 rzg2l_read_pin_config (struct rzg2l_pinctrl * pctrl , u32 offset ,
428446 u8 bit , u32 mask )
429447{
@@ -466,9 +484,9 @@ static int rzg2l_pinctrl_pinconf_get(struct pinctrl_dev *pctldev,
466484 const struct pinctrl_pin_desc * pin = & pctrl -> desc .pins [_pin ];
467485 unsigned int * pin_data = pin -> drv_data ;
468486 unsigned int arg = 0 ;
469- u32 port_offset = 0 ;
470487 unsigned long flags ;
471488 void __iomem * addr ;
489+ u32 port_offset ;
472490 u32 cfg = 0 ;
473491 u8 bit = 0 ;
474492
@@ -479,6 +497,13 @@ static int rzg2l_pinctrl_pinconf_get(struct pinctrl_dev *pctldev,
479497 port_offset = RZG2L_SINGLE_PIN_GET_PORT_OFFSET (* pin_data );
480498 cfg = RZG2L_SINGLE_PIN_GET_CFGS (* pin_data );
481499 bit = RZG2L_SINGLE_PIN_GET_BIT (* pin_data );
500+ } else {
501+ cfg = RZG2L_GPIO_PORT_GET_CFGS (* pin_data );
502+ port_offset = RZG2L_PIN_ID_TO_PORT_OFFSET (_pin );
503+ bit = RZG2L_PIN_ID_TO_PIN (_pin );
504+
505+ if (rzg2l_validate_gpio_pin (pctrl , * pin_data , RZG2L_PIN_ID_TO_PORT (_pin ), bit ))
506+ return - EINVAL ;
482507 }
483508
484509 switch (param ) {
@@ -525,9 +550,9 @@ static int rzg2l_pinctrl_pinconf_set(struct pinctrl_dev *pctldev,
525550 const struct pinctrl_pin_desc * pin = & pctrl -> desc .pins [_pin ];
526551 unsigned int * pin_data = pin -> drv_data ;
527552 enum pin_config_param param ;
528- u32 port_offset = 0 ;
529553 unsigned long flags ;
530554 void __iomem * addr ;
555+ u32 port_offset ;
531556 unsigned int i ;
532557 u32 cfg = 0 ;
533558 u8 bit = 0 ;
@@ -539,6 +564,13 @@ static int rzg2l_pinctrl_pinconf_set(struct pinctrl_dev *pctldev,
539564 port_offset = RZG2L_SINGLE_PIN_GET_PORT_OFFSET (* pin_data );
540565 cfg = RZG2L_SINGLE_PIN_GET_CFGS (* pin_data );
541566 bit = RZG2L_SINGLE_PIN_GET_BIT (* pin_data );
567+ } else {
568+ cfg = RZG2L_GPIO_PORT_GET_CFGS (* pin_data );
569+ port_offset = RZG2L_PIN_ID_TO_PORT_OFFSET (_pin );
570+ bit = RZG2L_PIN_ID_TO_PIN (_pin );
571+
572+ if (rzg2l_validate_gpio_pin (pctrl , * pin_data , RZG2L_PIN_ID_TO_PORT (_pin ), bit ))
573+ return - EINVAL ;
542574 }
543575
544576 for (i = 0 ; i < num_configs ; i ++ ) {
0 commit comments