@@ -424,6 +424,39 @@ static int rzg2l_dt_node_to_map(struct pinctrl_dev *pctldev,
424424 return ret ;
425425}
426426
427+ static u32 rzg2l_read_pin_config (struct rzg2l_pinctrl * pctrl , u32 offset ,
428+ u8 bit , u32 mask )
429+ {
430+ void __iomem * addr = pctrl -> base + offset ;
431+
432+ /* handle _L/_H for 32-bit register read/write */
433+ if (bit >= 4 ) {
434+ bit -= 4 ;
435+ addr += 4 ;
436+ }
437+
438+ return (readl (addr ) >> (bit * 8 )) & mask ;
439+ }
440+
441+ static void rzg2l_rmw_pin_config (struct rzg2l_pinctrl * pctrl , u32 offset ,
442+ u8 bit , u32 mask , u32 val )
443+ {
444+ void __iomem * addr = pctrl -> base + offset ;
445+ unsigned long flags ;
446+ u32 reg ;
447+
448+ /* handle _L/_H for 32-bit register read/write */
449+ if (bit >= 4 ) {
450+ bit -= 4 ;
451+ addr += 4 ;
452+ }
453+
454+ spin_lock_irqsave (& pctrl -> lock , flags );
455+ reg = readl (addr ) & ~(mask << (bit * 8 ));
456+ writel (reg | (val << (bit * 8 )), addr );
457+ spin_unlock_irqrestore (& pctrl -> lock , flags );
458+ }
459+
427460static int rzg2l_pinctrl_pinconf_get (struct pinctrl_dev * pctldev ,
428461 unsigned int _pin ,
429462 unsigned long * config )
@@ -432,8 +465,8 @@ static int rzg2l_pinctrl_pinconf_get(struct pinctrl_dev *pctldev,
432465 enum pin_config_param param = pinconf_to_config_param (* config );
433466 const struct pinctrl_pin_desc * pin = & pctrl -> desc .pins [_pin ];
434467 unsigned int * pin_data = pin -> drv_data ;
435- u32 port_offset = 0 , reg ;
436468 unsigned int arg = 0 ;
469+ u32 port_offset = 0 ;
437470 unsigned long flags ;
438471 void __iomem * addr ;
439472 u32 cfg = 0 ;
@@ -452,17 +485,7 @@ static int rzg2l_pinctrl_pinconf_get(struct pinctrl_dev *pctldev,
452485 case PIN_CONFIG_INPUT_ENABLE :
453486 if (!(cfg & PIN_CFG_IEN ))
454487 return - EINVAL ;
455- spin_lock_irqsave (& pctrl -> lock , flags );
456- /* handle _L/_H for 32-bit register read/write */
457- addr = pctrl -> base + IEN (port_offset );
458- if (bit >= 4 ) {
459- bit -= 4 ;
460- addr += 4 ;
461- }
462-
463- reg = readl (addr ) & (IEN_MASK << (bit * 8 ));
464- arg = (reg >> (bit * 8 )) & 0x1 ;
465- spin_unlock_irqrestore (& pctrl -> lock , flags );
488+ arg = rzg2l_read_pin_config (pctrl , IEN (port_offset ), bit , IEN_MASK );
466489 break ;
467490
468491 case PIN_CONFIG_POWER_SOURCE : {
@@ -502,7 +525,7 @@ static int rzg2l_pinctrl_pinconf_set(struct pinctrl_dev *pctldev,
502525 const struct pinctrl_pin_desc * pin = & pctrl -> desc .pins [_pin ];
503526 unsigned int * pin_data = pin -> drv_data ;
504527 enum pin_config_param param ;
505- u32 port_offset = 0 , reg ;
528+ u32 port_offset = 0 ;
506529 unsigned long flags ;
507530 void __iomem * addr ;
508531 unsigned int i ;
@@ -528,17 +551,7 @@ static int rzg2l_pinctrl_pinconf_set(struct pinctrl_dev *pctldev,
528551 if (!(cfg & PIN_CFG_IEN ))
529552 return - EINVAL ;
530553
531- /* handle _L/_H for 32-bit register read/write */
532- addr = pctrl -> base + IEN (port_offset );
533- if (bit >= 4 ) {
534- bit -= 4 ;
535- addr += 4 ;
536- }
537-
538- spin_lock_irqsave (& pctrl -> lock , flags );
539- reg = readl (addr ) & ~(IEN_MASK << (bit * 8 ));
540- writel (reg | (arg << (bit * 8 )), addr );
541- spin_unlock_irqrestore (& pctrl -> lock , flags );
554+ rzg2l_rmw_pin_config (pctrl , IEN (port_offset ), bit , IEN_MASK , !!arg );
542555 break ;
543556 }
544557
0 commit comments