@@ -114,13 +114,29 @@ struct intel_community_context {
114114#define pin_to_padno (c , p ) ((p) - (c)->pin_base)
115115#define padgroup_offset (g , p ) ((p) - (g)->base)
116116
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+
117135const struct intel_community * intel_get_community (struct intel_pinctrl * pctrl , unsigned int pin )
118136{
119137 const struct intel_community * community ;
120- int i ;
121138
122- for (i = 0 ; i < pctrl -> ncommunities ; i ++ ) {
123- community = & pctrl -> communities [i ];
139+ for_each_intel_pin_community (pctrl , community ) {
124140 if (pin >= community -> pin_base &&
125141 pin < community -> pin_base + community -> npins )
126142 return community ;
@@ -135,11 +151,9 @@ static const struct intel_padgroup *
135151intel_community_get_padgroup (const struct intel_community * community ,
136152 unsigned int pin )
137153{
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 ;
142155
156+ for_each_intel_community_pad_group (community , padgrp ) {
143157 if (pin >= padgrp -> base && pin < padgrp -> base + padgrp -> size )
144158 return padgrp ;
145159 }
@@ -942,30 +956,17 @@ static int intel_gpio_to_pin(struct intel_pinctrl *pctrl, unsigned int offset,
942956 const struct intel_community * * community ,
943957 const struct intel_padgroup * * padgrp )
944958{
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 ;
950961
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 ;
953968
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 ;
969970 }
970971 }
971972
@@ -1258,12 +1259,11 @@ static const struct irq_chip intel_gpio_irq_chip = {
12581259static int intel_gpio_community_irq_handler (struct intel_pinctrl * pctrl ,
12591260 const struct intel_community * community )
12601261{
1262+ const struct intel_padgroup * padgrp ;
12611263 struct gpio_chip * gc = & pctrl -> chip ;
1262- unsigned int gpp ;
12631264 int ret = 0 ;
12641265
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 ) {
12671267 unsigned long pending , enabled ;
12681268 unsigned int gpp , gpp_offset ;
12691269 void __iomem * reg , * is ;
@@ -1294,29 +1294,23 @@ static irqreturn_t intel_gpio_irq(int irq, void *data)
12941294{
12951295 const struct intel_community * community ;
12961296 struct intel_pinctrl * pctrl = data ;
1297- unsigned int i ;
12981297 int ret = 0 ;
12991298
13001299 /* 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 )
13031301 ret += intel_gpio_community_irq_handler (pctrl , community );
1304- }
13051302
13061303 return IRQ_RETVAL (ret );
13071304}
13081305
13091306static void intel_gpio_irq_init (struct intel_pinctrl * pctrl )
13101307{
1311- int i ;
1308+ const struct intel_community * community ;
13121309
1313- for (i = 0 ; i < pctrl -> ncommunities ; i ++ ) {
1314- const struct intel_community * community ;
1310+ for_each_intel_pin_community (pctrl , community ) {
13151311 void __iomem * reg , * is ;
13161312 unsigned int gpp ;
13171313
1318- community = & pctrl -> communities [i ];
1319-
13201314 for (gpp = 0 ; gpp < community -> ngpps ; gpp ++ ) {
13211315 reg = community -> regs + community -> ie_offset + gpp * 4 ;
13221316 is = community -> regs + community -> is_offset + gpp * 4 ;
@@ -1341,36 +1335,17 @@ static int intel_gpio_irq_init_hw(struct gpio_chip *gc)
13411335 return 0 ;
13421336}
13431337
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-
13651338static int intel_gpio_add_pin_ranges (struct gpio_chip * gc )
13661339{
13671340 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 ;
13721344
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 );
13741349 if (ret ) {
13751350 dev_err (pctrl -> dev , "failed to add GPIO pin range\n" );
13761351 return ret ;
@@ -1383,20 +1358,12 @@ static int intel_gpio_add_pin_ranges(struct gpio_chip *gc)
13831358static unsigned int intel_gpio_ngpio (const struct intel_pinctrl * pctrl )
13841359{
13851360 const struct intel_community * community ;
1361+ const struct intel_padgroup * grp ;
13861362 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 ];
13931363
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 ;
14001367 }
14011368
14021369 return ngpio ;
0 commit comments