@@ -114,13 +114,29 @@ struct intel_community_context {
114
114
#define pin_to_padno (c , p ) ((p) - (c)->pin_base)
115
115
#define padgroup_offset (g , p ) ((p) - (g)->base)
116
116
117
+ #define for_each_intel_pin_community (pctrl , community ) \
118
+ for (unsigned int __ci = 0; \
119
+ __ci < pctrl->ncommunities && (community = &pctrl->communities[__ci]); \
120
+ __ci++) \
121
+
122
+ #define for_each_intel_community_pad_group (community , grp ) \
123
+ for (unsigned int __gi = 0; \
124
+ __gi < community->ngpps && (grp = &community->gpps[__gi]); \
125
+ __gi++) \
126
+
127
+ #define for_each_intel_pad_group (pctrl , community , grp ) \
128
+ for_each_intel_pin_community(pctrl, community) \
129
+ for_each_intel_community_pad_group(community, grp)
130
+
131
+ #define for_each_intel_gpio_group (pctrl , community , grp ) \
132
+ for_each_intel_pad_group(pctrl, community, grp) \
133
+ if (grp->gpio_base == INTEL_GPIO_BASE_NOMAP) {} else
134
+
117
135
const struct intel_community * intel_get_community (struct intel_pinctrl * pctrl , unsigned int pin )
118
136
{
119
137
const struct intel_community * community ;
120
- int i ;
121
138
122
- for (i = 0 ; i < pctrl -> ncommunities ; i ++ ) {
123
- community = & pctrl -> communities [i ];
139
+ for_each_intel_pin_community (pctrl , community ) {
124
140
if (pin >= community -> pin_base &&
125
141
pin < community -> pin_base + community -> npins )
126
142
return community ;
@@ -135,11 +151,9 @@ static const struct intel_padgroup *
135
151
intel_community_get_padgroup (const struct intel_community * community ,
136
152
unsigned int pin )
137
153
{
138
- int i ;
139
-
140
- for (i = 0 ; i < community -> ngpps ; i ++ ) {
141
- const struct intel_padgroup * padgrp = & community -> gpps [i ];
154
+ const struct intel_padgroup * padgrp ;
142
155
156
+ for_each_intel_community_pad_group (community , padgrp ) {
143
157
if (pin >= padgrp -> base && pin < padgrp -> base + padgrp -> size )
144
158
return padgrp ;
145
159
}
@@ -942,30 +956,17 @@ static int intel_gpio_to_pin(struct intel_pinctrl *pctrl, unsigned int offset,
942
956
const struct intel_community * * community ,
943
957
const struct intel_padgroup * * padgrp )
944
958
{
945
- int i ;
946
-
947
- for (i = 0 ; i < pctrl -> ncommunities ; i ++ ) {
948
- const struct intel_community * comm = & pctrl -> communities [i ];
949
- int j ;
959
+ const struct intel_community * comm ;
960
+ const struct intel_padgroup * grp ;
950
961
951
- for (j = 0 ; j < comm -> ngpps ; j ++ ) {
952
- const struct intel_padgroup * pgrp = & comm -> gpps [j ];
962
+ for_each_intel_gpio_group (pctrl , comm , grp ) {
963
+ if (offset >= grp -> gpio_base && offset < grp -> gpio_base + grp -> size ) {
964
+ if (community )
965
+ * community = comm ;
966
+ if (padgrp )
967
+ * padgrp = grp ;
953
968
954
- if (pgrp -> gpio_base == INTEL_GPIO_BASE_NOMAP )
955
- continue ;
956
-
957
- if (offset >= pgrp -> gpio_base &&
958
- offset < pgrp -> gpio_base + pgrp -> size ) {
959
- int pin ;
960
-
961
- pin = pgrp -> base + offset - pgrp -> gpio_base ;
962
- if (community )
963
- * community = comm ;
964
- if (padgrp )
965
- * padgrp = pgrp ;
966
-
967
- return pin ;
968
- }
969
+ return grp -> base + offset - grp -> gpio_base ;
969
970
}
970
971
}
971
972
@@ -1258,12 +1259,11 @@ static const struct irq_chip intel_gpio_irq_chip = {
1258
1259
static int intel_gpio_community_irq_handler (struct intel_pinctrl * pctrl ,
1259
1260
const struct intel_community * community )
1260
1261
{
1262
+ const struct intel_padgroup * padgrp ;
1261
1263
struct gpio_chip * gc = & pctrl -> chip ;
1262
- unsigned int gpp ;
1263
1264
int ret = 0 ;
1264
1265
1265
- for (gpp = 0 ; gpp < community -> ngpps ; gpp ++ ) {
1266
- const struct intel_padgroup * padgrp = & community -> gpps [gpp ];
1266
+ for_each_intel_community_pad_group (community , padgrp ) {
1267
1267
unsigned long pending , enabled ;
1268
1268
unsigned int gpp , gpp_offset ;
1269
1269
void __iomem * reg , * is ;
@@ -1294,29 +1294,23 @@ static irqreturn_t intel_gpio_irq(int irq, void *data)
1294
1294
{
1295
1295
const struct intel_community * community ;
1296
1296
struct intel_pinctrl * pctrl = data ;
1297
- unsigned int i ;
1298
1297
int ret = 0 ;
1299
1298
1300
1299
/* Need to check all communities for pending interrupts */
1301
- for (i = 0 ; i < pctrl -> ncommunities ; i ++ ) {
1302
- community = & pctrl -> communities [i ];
1300
+ for_each_intel_pin_community (pctrl , community )
1303
1301
ret += intel_gpio_community_irq_handler (pctrl , community );
1304
- }
1305
1302
1306
1303
return IRQ_RETVAL (ret );
1307
1304
}
1308
1305
1309
1306
static void intel_gpio_irq_init (struct intel_pinctrl * pctrl )
1310
1307
{
1311
- int i ;
1308
+ const struct intel_community * community ;
1312
1309
1313
- for (i = 0 ; i < pctrl -> ncommunities ; i ++ ) {
1314
- const struct intel_community * community ;
1310
+ for_each_intel_pin_community (pctrl , community ) {
1315
1311
void __iomem * reg , * is ;
1316
1312
unsigned int gpp ;
1317
1313
1318
- community = & pctrl -> communities [i ];
1319
-
1320
1314
for (gpp = 0 ; gpp < community -> ngpps ; gpp ++ ) {
1321
1315
reg = community -> regs + community -> ie_offset + gpp * 4 ;
1322
1316
is = community -> regs + community -> is_offset + gpp * 4 ;
@@ -1341,36 +1335,17 @@ static int intel_gpio_irq_init_hw(struct gpio_chip *gc)
1341
1335
return 0 ;
1342
1336
}
1343
1337
1344
- static int intel_gpio_add_community_ranges (struct intel_pinctrl * pctrl ,
1345
- const struct intel_community * community )
1346
- {
1347
- int ret = 0 , i ;
1348
-
1349
- for (i = 0 ; i < community -> ngpps ; i ++ ) {
1350
- const struct intel_padgroup * gpp = & community -> gpps [i ];
1351
-
1352
- if (gpp -> gpio_base == INTEL_GPIO_BASE_NOMAP )
1353
- continue ;
1354
-
1355
- ret = gpiochip_add_pin_range (& pctrl -> chip , dev_name (pctrl -> dev ),
1356
- gpp -> gpio_base , gpp -> base ,
1357
- gpp -> size );
1358
- if (ret )
1359
- return ret ;
1360
- }
1361
-
1362
- return ret ;
1363
- }
1364
-
1365
1338
static int intel_gpio_add_pin_ranges (struct gpio_chip * gc )
1366
1339
{
1367
1340
struct intel_pinctrl * pctrl = gpiochip_get_data (gc );
1368
- int ret , i ;
1369
-
1370
- for (i = 0 ; i < pctrl -> ncommunities ; i ++ ) {
1371
- const struct intel_community * community = & pctrl -> communities [i ];
1341
+ const struct intel_community * community ;
1342
+ const struct intel_padgroup * grp ;
1343
+ int ret ;
1372
1344
1373
- ret = intel_gpio_add_community_ranges (pctrl , community );
1345
+ for_each_intel_gpio_group (pctrl , community , grp ) {
1346
+ ret = gpiochip_add_pin_range (& pctrl -> chip , dev_name (pctrl -> dev ),
1347
+ grp -> gpio_base , grp -> base ,
1348
+ grp -> size );
1374
1349
if (ret ) {
1375
1350
dev_err (pctrl -> dev , "failed to add GPIO pin range\n" );
1376
1351
return ret ;
@@ -1383,20 +1358,12 @@ static int intel_gpio_add_pin_ranges(struct gpio_chip *gc)
1383
1358
static unsigned int intel_gpio_ngpio (const struct intel_pinctrl * pctrl )
1384
1359
{
1385
1360
const struct intel_community * community ;
1361
+ const struct intel_padgroup * grp ;
1386
1362
unsigned int ngpio = 0 ;
1387
- int i , j ;
1388
-
1389
- for (i = 0 ; i < pctrl -> ncommunities ; i ++ ) {
1390
- community = & pctrl -> communities [i ];
1391
- for (j = 0 ; j < community -> ngpps ; j ++ ) {
1392
- const struct intel_padgroup * gpp = & community -> gpps [j ];
1393
1363
1394
- if (gpp -> gpio_base == INTEL_GPIO_BASE_NOMAP )
1395
- continue ;
1396
-
1397
- if (gpp -> gpio_base + gpp -> size > ngpio )
1398
- ngpio = gpp -> gpio_base + gpp -> size ;
1399
- }
1364
+ for_each_intel_gpio_group (pctrl , community , grp ) {
1365
+ if (grp -> gpio_base + grp -> size > ngpio )
1366
+ ngpio = grp -> gpio_base + grp -> size ;
1400
1367
}
1401
1368
1402
1369
return ngpio ;
0 commit comments