@@ -31,6 +31,7 @@ struct exar_gpio_chip {
31
31
int index ;
32
32
void __iomem * regs ;
33
33
char name [20 ];
34
+ unsigned int first_pin ;
34
35
};
35
36
36
37
static void exar_update (struct gpio_chip * chip , unsigned int reg , int val ,
@@ -51,11 +52,12 @@ static void exar_update(struct gpio_chip *chip, unsigned int reg, int val,
51
52
static int exar_set_direction (struct gpio_chip * chip , int direction ,
52
53
unsigned int offset )
53
54
{
54
- unsigned int bank = offset / 8 ;
55
- unsigned int addr ;
55
+ struct exar_gpio_chip * exar_gpio = gpiochip_get_data (chip );
56
+ unsigned int addr = (offset + exar_gpio -> first_pin ) / 8 ?
57
+ EXAR_OFFSET_MPIOSEL_HI : EXAR_OFFSET_MPIOSEL_LO ;
58
+ unsigned int bit = (offset + exar_gpio -> first_pin ) % 8 ;
56
59
57
- addr = bank ? EXAR_OFFSET_MPIOSEL_HI : EXAR_OFFSET_MPIOSEL_LO ;
58
- exar_update (chip , addr , direction , offset % 8 );
60
+ exar_update (chip , addr , direction , bit );
59
61
return 0 ;
60
62
}
61
63
@@ -73,36 +75,33 @@ static int exar_get(struct gpio_chip *chip, unsigned int reg)
73
75
74
76
static int exar_get_direction (struct gpio_chip * chip , unsigned int offset )
75
77
{
76
- unsigned int bank = offset / 8 ;
77
- unsigned int addr ;
78
- int val ;
79
-
80
- addr = bank ? EXAR_OFFSET_MPIOSEL_HI : EXAR_OFFSET_MPIOSEL_LO ;
81
- val = exar_get (chip , addr ) & BIT (offset % 8 );
78
+ struct exar_gpio_chip * exar_gpio = gpiochip_get_data (chip );
79
+ unsigned int addr = (offset + exar_gpio -> first_pin ) / 8 ?
80
+ EXAR_OFFSET_MPIOSEL_HI : EXAR_OFFSET_MPIOSEL_LO ;
81
+ unsigned int bit = (offset + exar_gpio -> first_pin ) % 8 ;
82
82
83
- return !!val ;
83
+ return !!( exar_get ( chip , addr ) & BIT ( bit )) ;
84
84
}
85
85
86
86
static int exar_get_value (struct gpio_chip * chip , unsigned int offset )
87
87
{
88
- unsigned int bank = offset / 8 ;
89
- unsigned int addr ;
90
- int val ;
91
-
92
- addr = bank ? EXAR_OFFSET_MPIOLVL_HI : EXAR_OFFSET_MPIOLVL_LO ;
93
- val = exar_get (chip , addr ) & BIT (offset % 8 );
88
+ struct exar_gpio_chip * exar_gpio = gpiochip_get_data (chip );
89
+ unsigned int addr = (offset + exar_gpio -> first_pin ) / 8 ?
90
+ EXAR_OFFSET_MPIOLVL_HI : EXAR_OFFSET_MPIOLVL_LO ;
91
+ unsigned int bit = (offset + exar_gpio -> first_pin ) % 8 ;
94
92
95
- return !!val ;
93
+ return !!( exar_get ( chip , addr ) & BIT ( bit )) ;
96
94
}
97
95
98
96
static void exar_set_value (struct gpio_chip * chip , unsigned int offset ,
99
97
int value )
100
98
{
101
- unsigned int bank = offset / 8 ;
102
- unsigned int addr ;
99
+ struct exar_gpio_chip * exar_gpio = gpiochip_get_data (chip );
100
+ unsigned int addr = (offset + exar_gpio -> first_pin ) / 8 ?
101
+ EXAR_OFFSET_MPIOLVL_HI : EXAR_OFFSET_MPIOLVL_LO ;
102
+ unsigned int bit = (offset + exar_gpio -> first_pin ) % 8 ;
103
103
104
- addr = bank ? EXAR_OFFSET_MPIOLVL_HI : EXAR_OFFSET_MPIOLVL_LO ;
105
- exar_update (chip , addr , value , offset % 8 );
104
+ exar_update (chip , addr , value , bit );
106
105
}
107
106
108
107
static int exar_direction_output (struct gpio_chip * chip , unsigned int offset ,
@@ -121,6 +120,7 @@ static int gpio_exar_probe(struct platform_device *pdev)
121
120
{
122
121
struct pci_dev * pcidev = to_pci_dev (pdev -> dev .parent );
123
122
struct exar_gpio_chip * exar_gpio ;
123
+ u32 first_pin , ngpios ;
124
124
void __iomem * p ;
125
125
int index , ret ;
126
126
@@ -132,6 +132,15 @@ static int gpio_exar_probe(struct platform_device *pdev)
132
132
if (!p )
133
133
return - ENOMEM ;
134
134
135
+ ret = device_property_read_u32 (& pdev -> dev , "linux,first-pin" ,
136
+ & first_pin );
137
+ if (ret )
138
+ return ret ;
139
+
140
+ ret = device_property_read_u32 (& pdev -> dev , "ngpios" , & ngpios );
141
+ if (ret )
142
+ return ret ;
143
+
135
144
exar_gpio = devm_kzalloc (& pdev -> dev , sizeof (* exar_gpio ), GFP_KERNEL );
136
145
if (!exar_gpio )
137
146
return - ENOMEM ;
@@ -149,9 +158,10 @@ static int gpio_exar_probe(struct platform_device *pdev)
149
158
exar_gpio -> gpio_chip .get = exar_get_value ;
150
159
exar_gpio -> gpio_chip .set = exar_set_value ;
151
160
exar_gpio -> gpio_chip .base = -1 ;
152
- exar_gpio -> gpio_chip .ngpio = 16 ;
161
+ exar_gpio -> gpio_chip .ngpio = ngpios ;
153
162
exar_gpio -> regs = p ;
154
163
exar_gpio -> index = index ;
164
+ exar_gpio -> first_pin = first_pin ;
155
165
156
166
ret = devm_gpiochip_add_data (& pdev -> dev ,
157
167
& exar_gpio -> gpio_chip , exar_gpio );
0 commit comments