@@ -131,10 +131,8 @@ struct chv_gpio_pinrange {
131
131
* @ngroups: Number of groups
132
132
* @functions: All functions in this community
133
133
* @nfunctions: Number of functions
134
- * @ngpios: Number of GPIOs in this community
135
134
* @gpio_ranges: An array of GPIO ranges in this community
136
135
* @ngpio_ranges: Number of GPIO ranges
137
- * @ngpios: Total number of GPIOs in this community
138
136
* @nirqs: Total number of IRQs this community can generate
139
137
*/
140
138
struct chv_community {
@@ -147,7 +145,6 @@ struct chv_community {
147
145
size_t nfunctions ;
148
146
const struct chv_gpio_pinrange * gpio_ranges ;
149
147
size_t ngpio_ranges ;
150
- size_t ngpios ;
151
148
size_t nirqs ;
152
149
acpi_adr_space_type acpi_space_id ;
153
150
};
@@ -399,7 +396,6 @@ static const struct chv_community southwest_community = {
399
396
.nfunctions = ARRAY_SIZE (southwest_functions ),
400
397
.gpio_ranges = southwest_gpio_ranges ,
401
398
.ngpio_ranges = ARRAY_SIZE (southwest_gpio_ranges ),
402
- .ngpios = ARRAY_SIZE (southwest_pins ),
403
399
/*
404
400
* Southwest community can benerate GPIO interrupts only for the
405
401
* first 8 interrupts. The upper half (8-15) can only be used to
@@ -489,7 +485,6 @@ static const struct chv_community north_community = {
489
485
.npins = ARRAY_SIZE (north_pins ),
490
486
.gpio_ranges = north_gpio_ranges ,
491
487
.ngpio_ranges = ARRAY_SIZE (north_gpio_ranges ),
492
- .ngpios = ARRAY_SIZE (north_pins ),
493
488
/*
494
489
* North community can generate GPIO interrupts only for the first
495
490
* 8 interrupts. The upper half (8-15) can only be used to trigger
@@ -538,7 +533,6 @@ static const struct chv_community east_community = {
538
533
.npins = ARRAY_SIZE (east_pins ),
539
534
.gpio_ranges = east_gpio_ranges ,
540
535
.ngpio_ranges = ARRAY_SIZE (east_gpio_ranges ),
541
- .ngpios = ARRAY_SIZE (east_pins ),
542
536
.nirqs = 16 ,
543
537
.acpi_space_id = 0x93 ,
544
538
};
@@ -665,7 +659,6 @@ static const struct chv_community southeast_community = {
665
659
.nfunctions = ARRAY_SIZE (southeast_functions ),
666
660
.gpio_ranges = southeast_gpio_ranges ,
667
661
.ngpio_ranges = ARRAY_SIZE (southeast_gpio_ranges ),
668
- .ngpios = ARRAY_SIZE (southeast_pins ),
669
662
.nirqs = 16 ,
670
663
.acpi_space_id = 0x94 ,
671
664
};
@@ -1253,21 +1246,14 @@ static struct pinctrl_desc chv_pinctrl_desc = {
1253
1246
.owner = THIS_MODULE ,
1254
1247
};
1255
1248
1256
- static unsigned chv_gpio_offset_to_pin (struct chv_pinctrl * pctrl ,
1257
- unsigned offset )
1258
- {
1259
- return pctrl -> community -> pins [offset ].number ;
1260
- }
1261
-
1262
1249
static int chv_gpio_get (struct gpio_chip * chip , unsigned offset )
1263
1250
{
1264
1251
struct chv_pinctrl * pctrl = gpiochip_get_data (chip );
1265
- int pin = chv_gpio_offset_to_pin (pctrl , offset );
1266
1252
unsigned long flags ;
1267
1253
u32 ctrl0 , cfg ;
1268
1254
1269
1255
raw_spin_lock_irqsave (& chv_lock , flags );
1270
- ctrl0 = readl (chv_padreg (pctrl , pin , CHV_PADCTRL0 ));
1256
+ ctrl0 = readl (chv_padreg (pctrl , offset , CHV_PADCTRL0 ));
1271
1257
raw_spin_unlock_irqrestore (& chv_lock , flags );
1272
1258
1273
1259
cfg = ctrl0 & CHV_PADCTRL0_GPIOCFG_MASK ;
@@ -1281,14 +1267,13 @@ static int chv_gpio_get(struct gpio_chip *chip, unsigned offset)
1281
1267
static void chv_gpio_set (struct gpio_chip * chip , unsigned offset , int value )
1282
1268
{
1283
1269
struct chv_pinctrl * pctrl = gpiochip_get_data (chip );
1284
- unsigned pin = chv_gpio_offset_to_pin (pctrl , offset );
1285
1270
unsigned long flags ;
1286
1271
void __iomem * reg ;
1287
1272
u32 ctrl0 ;
1288
1273
1289
1274
raw_spin_lock_irqsave (& chv_lock , flags );
1290
1275
1291
- reg = chv_padreg (pctrl , pin , CHV_PADCTRL0 );
1276
+ reg = chv_padreg (pctrl , offset , CHV_PADCTRL0 );
1292
1277
ctrl0 = readl (reg );
1293
1278
1294
1279
if (value )
@@ -1304,12 +1289,11 @@ static void chv_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
1304
1289
static int chv_gpio_get_direction (struct gpio_chip * chip , unsigned offset )
1305
1290
{
1306
1291
struct chv_pinctrl * pctrl = gpiochip_get_data (chip );
1307
- unsigned pin = chv_gpio_offset_to_pin (pctrl , offset );
1308
1292
u32 ctrl0 , direction ;
1309
1293
unsigned long flags ;
1310
1294
1311
1295
raw_spin_lock_irqsave (& chv_lock , flags );
1312
- ctrl0 = readl (chv_padreg (pctrl , pin , CHV_PADCTRL0 ));
1296
+ ctrl0 = readl (chv_padreg (pctrl , offset , CHV_PADCTRL0 ));
1313
1297
raw_spin_unlock_irqrestore (& chv_lock , flags );
1314
1298
1315
1299
direction = ctrl0 & CHV_PADCTRL0_GPIOCFG_MASK ;
@@ -1345,7 +1329,7 @@ static void chv_gpio_irq_ack(struct irq_data *d)
1345
1329
{
1346
1330
struct gpio_chip * gc = irq_data_get_irq_chip_data (d );
1347
1331
struct chv_pinctrl * pctrl = gpiochip_get_data (gc );
1348
- int pin = chv_gpio_offset_to_pin ( pctrl , irqd_to_hwirq (d ) );
1332
+ int pin = irqd_to_hwirq (d );
1349
1333
u32 intr_line ;
1350
1334
1351
1335
raw_spin_lock (& chv_lock );
@@ -1362,7 +1346,7 @@ static void chv_gpio_irq_mask_unmask(struct irq_data *d, bool mask)
1362
1346
{
1363
1347
struct gpio_chip * gc = irq_data_get_irq_chip_data (d );
1364
1348
struct chv_pinctrl * pctrl = gpiochip_get_data (gc );
1365
- int pin = chv_gpio_offset_to_pin ( pctrl , irqd_to_hwirq (d ) );
1349
+ int pin = irqd_to_hwirq (d );
1366
1350
u32 value , intr_line ;
1367
1351
unsigned long flags ;
1368
1352
@@ -1407,8 +1391,7 @@ static unsigned chv_gpio_irq_startup(struct irq_data *d)
1407
1391
if (irqd_get_trigger_type (d ) == IRQ_TYPE_NONE ) {
1408
1392
struct gpio_chip * gc = irq_data_get_irq_chip_data (d );
1409
1393
struct chv_pinctrl * pctrl = gpiochip_get_data (gc );
1410
- unsigned offset = irqd_to_hwirq (d );
1411
- int pin = chv_gpio_offset_to_pin (pctrl , offset );
1394
+ unsigned pin = irqd_to_hwirq (d );
1412
1395
irq_flow_handler_t handler ;
1413
1396
unsigned long flags ;
1414
1397
u32 intsel , value ;
@@ -1426,7 +1409,7 @@ static unsigned chv_gpio_irq_startup(struct irq_data *d)
1426
1409
1427
1410
if (!pctrl -> intr_lines [intsel ]) {
1428
1411
irq_set_handler_locked (d , handler );
1429
- pctrl -> intr_lines [intsel ] = offset ;
1412
+ pctrl -> intr_lines [intsel ] = pin ;
1430
1413
}
1431
1414
raw_spin_unlock_irqrestore (& chv_lock , flags );
1432
1415
}
@@ -1439,8 +1422,7 @@ static int chv_gpio_irq_type(struct irq_data *d, unsigned type)
1439
1422
{
1440
1423
struct gpio_chip * gc = irq_data_get_irq_chip_data (d );
1441
1424
struct chv_pinctrl * pctrl = gpiochip_get_data (gc );
1442
- unsigned offset = irqd_to_hwirq (d );
1443
- int pin = chv_gpio_offset_to_pin (pctrl , offset );
1425
+ unsigned pin = irqd_to_hwirq (d );
1444
1426
unsigned long flags ;
1445
1427
u32 value ;
1446
1428
@@ -1486,7 +1468,7 @@ static int chv_gpio_irq_type(struct irq_data *d, unsigned type)
1486
1468
value &= CHV_PADCTRL0_INTSEL_MASK ;
1487
1469
value >>= CHV_PADCTRL0_INTSEL_SHIFT ;
1488
1470
1489
- pctrl -> intr_lines [value ] = offset ;
1471
+ pctrl -> intr_lines [value ] = pin ;
1490
1472
1491
1473
if (type & IRQ_TYPE_EDGE_BOTH )
1492
1474
irq_set_handler_locked (d , handle_edge_irq );
@@ -1576,12 +1558,12 @@ static int chv_gpio_probe(struct chv_pinctrl *pctrl, int irq)
1576
1558
const struct chv_gpio_pinrange * range ;
1577
1559
struct gpio_chip * chip = & pctrl -> chip ;
1578
1560
bool need_valid_mask = !dmi_check_system (chv_no_valid_mask );
1579
- int ret , i , offset ;
1580
- int irq_base ;
1561
+ const struct chv_community * community = pctrl -> community ;
1562
+ int ret , i , irq_base ;
1581
1563
1582
1564
* chip = chv_gpio_chip ;
1583
1565
1584
- chip -> ngpio = pctrl -> community -> ngpios ;
1566
+ chip -> ngpio = community -> pins [ community -> npins - 1 ]. number + 1 ;
1585
1567
chip -> label = dev_name (pctrl -> dev );
1586
1568
chip -> parent = pctrl -> dev ;
1587
1569
chip -> base = -1 ;
@@ -1593,30 +1575,29 @@ static int chv_gpio_probe(struct chv_pinctrl *pctrl, int irq)
1593
1575
return ret ;
1594
1576
}
1595
1577
1596
- for (i = 0 , offset = 0 ; i < pctrl -> community -> ngpio_ranges ; i ++ ) {
1597
- range = & pctrl -> community -> gpio_ranges [i ];
1598
- ret = gpiochip_add_pin_range (chip , dev_name (pctrl -> dev ), offset ,
1599
- range -> base , range -> npins );
1578
+ for (i = 0 ; i < community -> ngpio_ranges ; i ++ ) {
1579
+ range = & community -> gpio_ranges [i ];
1580
+ ret = gpiochip_add_pin_range (chip , dev_name (pctrl -> dev ),
1581
+ range -> base , range -> base ,
1582
+ range -> npins );
1600
1583
if (ret ) {
1601
1584
dev_err (pctrl -> dev , "failed to add GPIO pin range\n" );
1602
1585
return ret ;
1603
1586
}
1604
-
1605
- offset += range -> npins ;
1606
1587
}
1607
1588
1608
1589
/* Do not add GPIOs that can only generate GPEs to the IRQ domain */
1609
- for (i = 0 ; i < pctrl -> community -> npins ; i ++ ) {
1590
+ for (i = 0 ; i < community -> npins ; i ++ ) {
1610
1591
const struct pinctrl_pin_desc * desc ;
1611
1592
u32 intsel ;
1612
1593
1613
- desc = & pctrl -> community -> pins [i ];
1594
+ desc = & community -> pins [i ];
1614
1595
1615
1596
intsel = readl (chv_padreg (pctrl , desc -> number , CHV_PADCTRL0 ));
1616
1597
intsel &= CHV_PADCTRL0_INTSEL_MASK ;
1617
1598
intsel >>= CHV_PADCTRL0_INTSEL_SHIFT ;
1618
1599
1619
- if (need_valid_mask && intsel >= pctrl -> community -> nirqs )
1600
+ if (need_valid_mask && intsel >= community -> nirqs )
1620
1601
clear_bit (i , chip -> irq .valid_mask );
1621
1602
}
1622
1603
0 commit comments