@@ -33,6 +33,26 @@ struct exar_gpio_chip {
3333 unsigned int first_pin ;
3434};
3535
36+ static unsigned int
37+ exar_offset_to_sel_addr (struct exar_gpio_chip * exar_gpio , unsigned int offset )
38+ {
39+ return (offset + exar_gpio -> first_pin ) / 8 ? EXAR_OFFSET_MPIOSEL_HI
40+ : EXAR_OFFSET_MPIOSEL_LO ;
41+ }
42+
43+ static unsigned int
44+ exar_offset_to_lvl_addr (struct exar_gpio_chip * exar_gpio , unsigned int offset )
45+ {
46+ return (offset + exar_gpio -> first_pin ) / 8 ? EXAR_OFFSET_MPIOLVL_HI
47+ : EXAR_OFFSET_MPIOLVL_LO ;
48+ }
49+
50+ static unsigned int
51+ exar_offset_to_bit (struct exar_gpio_chip * exar_gpio , unsigned int offset )
52+ {
53+ return (offset + exar_gpio -> first_pin ) % 8 ;
54+ }
55+
3656static void exar_update (struct gpio_chip * chip , unsigned int reg , int val ,
3757 unsigned int offset )
3858{
@@ -52,9 +72,8 @@ static int exar_set_direction(struct gpio_chip *chip, int direction,
5272 unsigned int offset )
5373{
5474 struct exar_gpio_chip * exar_gpio = gpiochip_get_data (chip );
55- unsigned int addr = (offset + exar_gpio -> first_pin ) / 8 ?
56- EXAR_OFFSET_MPIOSEL_HI : EXAR_OFFSET_MPIOSEL_LO ;
57- unsigned int bit = (offset + exar_gpio -> first_pin ) % 8 ;
75+ unsigned int addr = exar_offset_to_sel_addr (exar_gpio , offset );
76+ unsigned int bit = exar_offset_to_bit (exar_gpio , offset );
5877
5978 exar_update (chip , addr , direction , bit );
6079 return 0 ;
@@ -75,9 +94,8 @@ static int exar_get(struct gpio_chip *chip, unsigned int reg)
7594static int exar_get_direction (struct gpio_chip * chip , unsigned int offset )
7695{
7796 struct exar_gpio_chip * exar_gpio = gpiochip_get_data (chip );
78- unsigned int addr = (offset + exar_gpio -> first_pin ) / 8 ?
79- EXAR_OFFSET_MPIOSEL_HI : EXAR_OFFSET_MPIOSEL_LO ;
80- unsigned int bit = (offset + exar_gpio -> first_pin ) % 8 ;
97+ unsigned int addr = exar_offset_to_sel_addr (exar_gpio , offset );
98+ unsigned int bit = exar_offset_to_bit (exar_gpio , offset );
8199
82100 if (exar_get (chip , addr ) & BIT (bit ))
83101 return GPIO_LINE_DIRECTION_IN ;
@@ -88,9 +106,8 @@ static int exar_get_direction(struct gpio_chip *chip, unsigned int offset)
88106static int exar_get_value (struct gpio_chip * chip , unsigned int offset )
89107{
90108 struct exar_gpio_chip * exar_gpio = gpiochip_get_data (chip );
91- unsigned int addr = (offset + exar_gpio -> first_pin ) / 8 ?
92- EXAR_OFFSET_MPIOLVL_HI : EXAR_OFFSET_MPIOLVL_LO ;
93- unsigned int bit = (offset + exar_gpio -> first_pin ) % 8 ;
109+ unsigned int addr = exar_offset_to_lvl_addr (exar_gpio , offset );
110+ unsigned int bit = exar_offset_to_bit (exar_gpio , offset );
94111
95112 return !!(exar_get (chip , addr ) & BIT (bit ));
96113}
@@ -99,9 +116,8 @@ static void exar_set_value(struct gpio_chip *chip, unsigned int offset,
99116 int value )
100117{
101118 struct exar_gpio_chip * exar_gpio = gpiochip_get_data (chip );
102- unsigned int addr = (offset + exar_gpio -> first_pin ) / 8 ?
103- EXAR_OFFSET_MPIOLVL_HI : EXAR_OFFSET_MPIOLVL_LO ;
104- unsigned int bit = (offset + exar_gpio -> first_pin ) % 8 ;
119+ unsigned int addr = exar_offset_to_lvl_addr (exar_gpio , offset );
120+ unsigned int bit = exar_offset_to_bit (exar_gpio , offset );
105121
106122 exar_update (chip , addr , value , bit );
107123}
0 commit comments