20
20
#include <linux/types.h>
21
21
#include <linux/bitops.h>
22
22
#include <linux/interrupt.h>
23
+ #include <linux/gpio.h>
23
24
#include <linux/gpio/driver.h>
24
25
#include <linux/acpi.h>
25
26
#include <linux/platform_device.h>
@@ -1363,44 +1364,45 @@ static void byt_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
1363
1364
unsigned long flags ;
1364
1365
u32 old_val ;
1365
1366
1366
- raw_spin_lock_irqsave (& vg -> lock , flags );
1367
+ if (!reg )
1368
+ return ;
1367
1369
1370
+ raw_spin_lock_irqsave (& vg -> lock , flags );
1368
1371
old_val = readl (reg );
1369
-
1370
1372
if (value )
1371
1373
writel (old_val | BYT_LEVEL , reg );
1372
1374
else
1373
1375
writel (old_val & ~BYT_LEVEL , reg );
1374
-
1375
1376
raw_spin_unlock_irqrestore (& vg -> lock , flags );
1376
1377
}
1377
1378
1378
- static int byt_gpio_direction_input (struct gpio_chip * chip , unsigned offset )
1379
+ static int byt_gpio_get_direction (struct gpio_chip * chip , unsigned int offset )
1379
1380
{
1380
1381
struct byt_gpio * vg = gpiochip_get_data (chip );
1381
1382
void __iomem * reg = byt_gpio_reg (vg , offset , BYT_VAL_REG );
1382
1383
unsigned long flags ;
1383
1384
u32 value ;
1384
1385
1385
- raw_spin_lock_irqsave (& vg -> lock , flags );
1386
-
1387
- value = readl (reg ) | BYT_DIR_MASK ;
1388
- value &= ~BYT_INPUT_EN ; /* active low */
1389
- writel (value , reg );
1386
+ if (!reg )
1387
+ return - EINVAL ;
1390
1388
1389
+ raw_spin_lock_irqsave (& vg -> lock , flags );
1390
+ value = readl (reg );
1391
1391
raw_spin_unlock_irqrestore (& vg -> lock , flags );
1392
1392
1393
- return 0 ;
1393
+ if (!(value & BYT_OUTPUT_EN ))
1394
+ return GPIOF_DIR_OUT ;
1395
+ if (!(value & BYT_INPUT_EN ))
1396
+ return GPIOF_DIR_IN ;
1397
+
1398
+ return - EINVAL ;
1394
1399
}
1395
1400
1396
- static int byt_gpio_direction_output (struct gpio_chip * chip ,
1397
- unsigned gpio , int value )
1401
+ static int byt_gpio_direction_input (struct gpio_chip * chip , unsigned int offset )
1398
1402
{
1399
1403
struct byt_gpio * vg = gpiochip_get_data (chip );
1400
- void __iomem * conf_reg = byt_gpio_reg (vg , gpio , BYT_CONF0_REG );
1401
- void __iomem * reg = byt_gpio_reg (vg , gpio , BYT_VAL_REG );
1404
+ void __iomem * conf_reg = byt_gpio_reg (vg , offset , BYT_CONF0_REG );
1402
1405
unsigned long flags ;
1403
- u32 reg_val ;
1404
1406
1405
1407
raw_spin_lock_irqsave (& vg -> lock , flags );
1406
1408
@@ -1413,15 +1415,18 @@ static int byt_gpio_direction_output(struct gpio_chip *chip,
1413
1415
WARN (readl (conf_reg ) & BYT_DIRECT_IRQ_EN ,
1414
1416
"Potential Error: Setting GPIO with direct_irq_en to output" );
1415
1417
1416
- reg_val = readl ( reg ) | BYT_DIR_MASK ;
1417
- reg_val &= ~( BYT_OUTPUT_EN | BYT_INPUT_EN );
1418
+ return pinctrl_gpio_direction_input ( chip -> base + offset ) ;
1419
+ }
1418
1420
1419
- if ( value )
1420
- writel ( reg_val | BYT_LEVEL , reg );
1421
- else
1422
- writel ( reg_val & ~ BYT_LEVEL , reg );
1421
+ static int byt_gpio_direction_output ( struct gpio_chip * chip ,
1422
+ unsigned int offset , int value )
1423
+ {
1424
+ int ret = pinctrl_gpio_direction_output ( chip -> base + offset );
1423
1425
1424
- raw_spin_unlock_irqrestore (& vg -> lock , flags );
1426
+ if (ret )
1427
+ return ret ;
1428
+
1429
+ byt_gpio_set (chip , offset , value );
1425
1430
1426
1431
return 0 ;
1427
1432
}
@@ -1430,20 +1435,42 @@ static void byt_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
1430
1435
{
1431
1436
struct byt_gpio * vg = gpiochip_get_data (chip );
1432
1437
int i ;
1433
- u32 conf0 , val , offs ;
1438
+ u32 conf0 , val ;
1434
1439
1435
- for (i = 0 ; i < vg -> chip .ngpio ; i ++ ) {
1440
+ for (i = 0 ; i < vg -> soc_data -> npins ; i ++ ) {
1441
+ const struct byt_community * comm ;
1436
1442
const char * pull_str = NULL ;
1437
1443
const char * pull = NULL ;
1444
+ void __iomem * reg ;
1438
1445
unsigned long flags ;
1439
1446
const char * label ;
1440
- offs = vg -> range -> pins [ i ] * 16 ;
1447
+ unsigned int pin ;
1441
1448
1442
1449
raw_spin_lock_irqsave (& vg -> lock , flags );
1443
- conf0 = readl (vg -> reg_base + offs + BYT_CONF0_REG );
1444
- val = readl (vg -> reg_base + offs + BYT_VAL_REG );
1450
+ pin = vg -> soc_data -> pins [i ].number ;
1451
+ reg = byt_gpio_reg (vg , pin , BYT_CONF0_REG );
1452
+ if (!reg ) {
1453
+ seq_printf (s ,
1454
+ "Could not retrieve pin %i conf0 reg\n" ,
1455
+ pin );
1456
+ continue ;
1457
+ }
1458
+ conf0 = readl (reg );
1459
+
1460
+ reg = byt_gpio_reg (vg , pin , BYT_VAL_REG );
1461
+ if (!reg ) {
1462
+ seq_printf (s ,
1463
+ "Could not retrieve pin %i val reg\n" , pin );
1464
+ }
1465
+ val = readl (reg );
1445
1466
raw_spin_unlock_irqrestore (& vg -> lock , flags );
1446
1467
1468
+ comm = byt_get_community (vg , pin );
1469
+ if (!comm ) {
1470
+ seq_printf (s ,
1471
+ "Could not get community for pin %i\n" , pin );
1472
+ continue ;
1473
+ }
1447
1474
label = gpiochip_is_requested (chip , i );
1448
1475
if (!label )
1449
1476
label = "Unrequested" ;
@@ -1474,12 +1501,12 @@ static void byt_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
1474
1501
1475
1502
seq_printf (s ,
1476
1503
" gpio-%-3d (%-20.20s) %s %s %s pad-%-3d offset:0x%03x mux:%d %s%s%s" ,
1477
- i ,
1504
+ pin ,
1478
1505
label ,
1479
1506
val & BYT_INPUT_EN ? " " : "in" ,
1480
1507
val & BYT_OUTPUT_EN ? " " : "out" ,
1481
1508
val & BYT_LEVEL ? "hi" : "lo" ,
1482
- vg -> range -> pins [i ], offs ,
1509
+ comm -> pad_map [ i ], comm -> pad_map [i ] * 32 ,
1483
1510
conf0 & 0x7 ,
1484
1511
conf0 & BYT_TRIG_NEG ? " fall" : " " ,
1485
1512
conf0 & BYT_TRIG_POS ? " rise" : " " ,
@@ -1519,6 +1546,18 @@ static void byt_gpio_irq_handler(struct irq_desc *desc)
1519
1546
chip -> irq_eoi (data );
1520
1547
}
1521
1548
1549
+ static const struct gpio_chip byt_gpio_chip = {
1550
+ .owner = THIS_MODULE ,
1551
+ .request = gpiochip_generic_request ,
1552
+ .free = gpiochip_generic_free ,
1553
+ .get_direction = byt_gpio_get_direction ,
1554
+ .direction_input = byt_gpio_direction_input ,
1555
+ .direction_output = byt_gpio_direction_output ,
1556
+ .get = byt_gpio_get ,
1557
+ .set = byt_gpio_set ,
1558
+ .dbg_show = byt_gpio_dbg_show ,
1559
+ };
1560
+
1522
1561
static void byt_irq_ack (struct irq_data * d )
1523
1562
{
1524
1563
struct gpio_chip * gc = irq_data_get_irq_chip_data (d );
0 commit comments