18
18
#include <linux/pm_runtime.h>
19
19
#include <linux/property.h>
20
20
#include <linux/seq_file.h>
21
+ #include <linux/string_helpers.h>
21
22
22
23
#include <linux/pinctrl/pinctrl.h>
23
24
#include <linux/pinctrl/pinmux.h>
52
53
#define BYT_PULL_STR_10K (1 << BYT_PULL_STR_SHIFT)
53
54
#define BYT_PULL_STR_20K (2 << BYT_PULL_STR_SHIFT)
54
55
#define BYT_PULL_STR_40K (3 << BYT_PULL_STR_SHIFT)
55
- #define BYT_PULL_ASSIGN_SHIFT 7
56
56
#define BYT_PULL_ASSIGN_MASK GENMASK(8, 7)
57
- #define BYT_PULL_ASSIGN_UP (1 << BYT_PULL_ASSIGN_SHIFT )
58
- #define BYT_PULL_ASSIGN_DOWN (2 << BYT_PULL_ASSIGN_SHIFT )
57
+ #define BYT_PULL_ASSIGN_DOWN BIT(8 )
58
+ #define BYT_PULL_ASSIGN_UP BIT(7 )
59
59
#define BYT_PIN_MUX GENMASK(2, 0)
60
60
61
61
/* BYT_VAL_REG register bits */
@@ -668,8 +668,7 @@ static void byt_set_group_simple_mux(struct intel_pinctrl *vg,
668
668
669
669
padcfg0 = byt_gpio_reg (vg , group .grp .pins [i ], BYT_CONF0_REG );
670
670
if (!padcfg0 ) {
671
- dev_warn (vg -> dev ,
672
- "Group %s, pin %i not muxed (no padcfg0)\n" ,
671
+ dev_warn (vg -> dev , "Group %s, pin %i not muxed (can't retrieve CONF0)\n" ,
673
672
group .grp .name , i );
674
673
continue ;
675
674
}
@@ -698,8 +697,7 @@ static void byt_set_group_mixed_mux(struct intel_pinctrl *vg,
698
697
699
698
padcfg0 = byt_gpio_reg (vg , group .grp .pins [i ], BYT_CONF0_REG );
700
699
if (!padcfg0 ) {
701
- dev_warn (vg -> dev ,
702
- "Group %s, pin %i not muxed (no padcfg0)\n" ,
700
+ dev_warn (vg -> dev , "Group %s, pin %i not muxed (can't retrieve CONF0)\n" ,
703
701
group .grp .name , i );
704
702
continue ;
705
703
}
@@ -755,9 +753,7 @@ static void byt_gpio_clear_triggering(struct intel_pinctrl *vg, unsigned int off
755
753
value = readl (reg );
756
754
757
755
/* Do not clear direct-irq enabled IRQs (from gpio_disable_free) */
758
- if (value & BYT_DIRECT_IRQ_EN )
759
- /* nothing to do */ ;
760
- else
756
+ if (!(value & BYT_DIRECT_IRQ_EN ))
761
757
value &= ~(BYT_TRIG_POS | BYT_TRIG_NEG | BYT_TRIG_LVL );
762
758
763
759
writel (value , reg );
@@ -791,7 +787,7 @@ static int byt_gpio_request_enable(struct pinctrl_dev *pctl_dev,
791
787
value |= gpio_mux ;
792
788
writel (value , reg );
793
789
794
- dev_warn (vg -> dev , FW_BUG "pin %u forcibly re-configured as GPIO\n" , offset );
790
+ dev_warn (vg -> dev , FW_BUG "Pin %i: forcibly re-configured as GPIO\n" , offset );
795
791
}
796
792
797
793
raw_spin_unlock_irqrestore (& byt_lock , flags );
@@ -823,7 +819,9 @@ static void byt_gpio_direct_irq_check(struct intel_pinctrl *vg,
823
819
* themselves in the foot.
824
820
*/
825
821
if (readl (conf_reg ) & BYT_DIRECT_IRQ_EN )
826
- dev_info_once (vg -> dev , "Potential Error: Setting GPIO with direct_irq_en to output" );
822
+ dev_info_once (vg -> dev ,
823
+ "Potential Error: Pin %i: forcibly set GPIO with DIRECT_IRQ_EN to output\n" ,
824
+ offset );
827
825
}
828
826
829
827
static int byt_gpio_set_direction (struct pinctrl_dev * pctl_dev ,
@@ -1026,9 +1024,7 @@ static int byt_pin_config_set(struct pinctrl_dev *pctl_dev,
1026
1024
if (val & BYT_INPUT_EN ) {
1027
1025
val &= ~BYT_INPUT_EN ;
1028
1026
writel (val , val_reg );
1029
- dev_warn (vg -> dev ,
1030
- "pin %u forcibly set to input mode\n" ,
1031
- offset );
1027
+ dev_warn (vg -> dev , "Pin %i: forcibly set to input mode\n" , offset );
1032
1028
}
1033
1029
1034
1030
conf &= ~BYT_PULL_ASSIGN_MASK ;
@@ -1048,9 +1044,7 @@ static int byt_pin_config_set(struct pinctrl_dev *pctl_dev,
1048
1044
if (val & BYT_INPUT_EN ) {
1049
1045
val &= ~BYT_INPUT_EN ;
1050
1046
writel (val , val_reg );
1051
- dev_warn (vg -> dev ,
1052
- "pin %u forcibly set to input mode\n" ,
1053
- offset );
1047
+ dev_warn (vg -> dev , "Pin %i: forcibly set to input mode\n" , offset );
1054
1048
}
1055
1049
1056
1050
conf &= ~BYT_PULL_ASSIGN_MASK ;
@@ -1245,39 +1239,35 @@ static void byt_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
1245
1239
1246
1240
for (i = 0 ; i < vg -> soc -> npins ; i ++ ) {
1247
1241
const struct intel_community * comm ;
1242
+ void __iomem * conf_reg , * val_reg ;
1248
1243
const char * pull_str = NULL ;
1249
1244
const char * pull = NULL ;
1250
- void __iomem * reg ;
1251
1245
unsigned long flags ;
1252
1246
const char * label ;
1253
1247
unsigned int pin ;
1254
1248
1255
- raw_spin_lock_irqsave (& byt_lock , flags );
1256
1249
pin = vg -> soc -> pins [i ].number ;
1257
- reg = byt_gpio_reg (vg , pin , BYT_CONF0_REG );
1258
- if (!reg ) {
1259
- seq_printf (s ,
1260
- "Could not retrieve pin %i conf0 reg\n" ,
1261
- pin );
1262
- raw_spin_unlock_irqrestore (& byt_lock , flags );
1250
+
1251
+ conf_reg = byt_gpio_reg (vg , pin , BYT_CONF0_REG );
1252
+ if (!conf_reg ) {
1253
+ seq_printf (s , "Pin %i: can't retrieve CONF0\n" , pin );
1263
1254
continue ;
1264
1255
}
1265
- conf0 = readl (reg );
1266
1256
1267
- reg = byt_gpio_reg (vg , pin , BYT_VAL_REG );
1268
- if (!reg ) {
1269
- seq_printf (s ,
1270
- "Could not retrieve pin %i val reg\n" , pin );
1271
- raw_spin_unlock_irqrestore (& byt_lock , flags );
1257
+ val_reg = byt_gpio_reg (vg , pin , BYT_VAL_REG );
1258
+ if (!val_reg ) {
1259
+ seq_printf (s , "Pin %i: can't retrieve VAL\n" , pin );
1272
1260
continue ;
1273
1261
}
1274
- val = readl (reg );
1262
+
1263
+ raw_spin_lock_irqsave (& byt_lock , flags );
1264
+ conf0 = readl (conf_reg );
1265
+ val = readl (val_reg );
1275
1266
raw_spin_unlock_irqrestore (& byt_lock , flags );
1276
1267
1277
1268
comm = byt_get_community (vg , pin );
1278
1269
if (!comm ) {
1279
- seq_printf (s ,
1280
- "Could not get community for pin %i\n" , pin );
1270
+ seq_printf (s , "Pin %i: can't retrieve community\n" , pin );
1281
1271
continue ;
1282
1272
}
1283
1273
label = gpiochip_is_requested (chip , i );
@@ -1314,7 +1304,7 @@ static void byt_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
1314
1304
label ,
1315
1305
val & BYT_INPUT_EN ? " " : "in" ,
1316
1306
val & BYT_OUTPUT_EN ? " " : "out" ,
1317
- val & BYT_LEVEL ? "hi" : "lo" ,
1307
+ str_hi_lo ( val & BYT_LEVEL ) ,
1318
1308
comm -> pad_map [i ], comm -> pad_map [i ] * 16 ,
1319
1309
conf0 & 0x7 ,
1320
1310
conf0 & BYT_TRIG_NEG ? " fall" : " " ,
@@ -1429,7 +1419,7 @@ static int byt_irq_type(struct irq_data *d, unsigned int type)
1429
1419
value = readl (reg );
1430
1420
1431
1421
WARN (value & BYT_DIRECT_IRQ_EN ,
1432
- "Bad pad config for io mode, force direct_irq_en bit clearing" );
1422
+ "Bad pad config for IO mode, force DIRECT_IRQ_EN bit clearing" );
1433
1423
1434
1424
/* For level trigges the BYT_TRIG_POS and BYT_TRIG_NEG bits
1435
1425
* are used to indicate high and low level triggering
@@ -1476,9 +1466,7 @@ static void byt_gpio_irq_handler(struct irq_desc *desc)
1476
1466
reg = byt_gpio_reg (vg , base , BYT_INT_STAT_REG );
1477
1467
1478
1468
if (!reg ) {
1479
- dev_warn (vg -> dev ,
1480
- "Pin %i: could not retrieve interrupt status register\n" ,
1481
- base );
1469
+ dev_warn (vg -> dev , "Pin %i: can't retrieve INT_STAT%u\n" , base / 32 , base );
1482
1470
continue ;
1483
1471
}
1484
1472
@@ -1501,7 +1489,7 @@ static bool byt_direct_irq_sanity_check(struct intel_pinctrl *vg, int pin, u32 c
1501
1489
sizeof (direct_irq_mux ));
1502
1490
match = memchr (direct_irq_mux , pin , sizeof (direct_irq_mux ));
1503
1491
if (!match ) {
1504
- dev_warn (vg -> dev , FW_BUG "pin %i: direct_irq_en set but no IRQ assigned, clearing\n" , pin );
1492
+ dev_warn (vg -> dev , FW_BUG "Pin %i: DIRECT_IRQ_EN set but no IRQ assigned, clearing\n" , pin );
1505
1493
return false;
1506
1494
}
1507
1495
@@ -1528,7 +1516,8 @@ static bool byt_direct_irq_sanity_check(struct intel_pinctrl *vg, int pin, u32 c
1528
1516
trig = conf0 & BYT_TRIG_MASK ;
1529
1517
if (trig != (BYT_TRIG_POS | BYT_TRIG_LVL ) &&
1530
1518
trig != (BYT_TRIG_NEG | BYT_TRIG_LVL )) {
1531
- dev_warn (vg -> dev , FW_BUG "pin %i: direct_irq_en set without trigger (conf0: %xh), clearing\n" ,
1519
+ dev_warn (vg -> dev ,
1520
+ FW_BUG "Pin %i: DIRECT_IRQ_EN set without trigger (CONF0: %#08x), clearing\n" ,
1532
1521
pin , conf0 );
1533
1522
return false;
1534
1523
}
@@ -1555,9 +1544,7 @@ static void byt_init_irq_valid_mask(struct gpio_chip *chip,
1555
1544
1556
1545
reg = byt_gpio_reg (vg , pin , BYT_CONF0_REG );
1557
1546
if (!reg ) {
1558
- dev_warn (vg -> dev ,
1559
- "Pin %i: could not retrieve conf0 register\n" ,
1560
- i );
1547
+ dev_warn (vg -> dev , "Pin %i: could not retrieve CONF0\n" , i );
1561
1548
continue ;
1562
1549
}
1563
1550
@@ -1588,9 +1575,7 @@ static int byt_gpio_irq_init_hw(struct gpio_chip *chip)
1588
1575
reg = byt_gpio_reg (vg , base , BYT_INT_STAT_REG );
1589
1576
1590
1577
if (!reg ) {
1591
- dev_warn (vg -> dev ,
1592
- "Pin %i: could not retrieve irq status reg\n" ,
1593
- base );
1578
+ dev_warn (vg -> dev , "Pin %i: can't retrieve INT_STAT%u\n" , base / 32 , base );
1594
1579
continue ;
1595
1580
}
1596
1581
@@ -1600,7 +1585,7 @@ static int byt_gpio_irq_init_hw(struct gpio_chip *chip)
1600
1585
value = readl (reg );
1601
1586
if (value )
1602
1587
dev_err (vg -> dev ,
1603
- "GPIO interrupt error, pins misconfigured. INT_STAT%u: 0x% 08x\n" ,
1588
+ "GPIO interrupt error, pins misconfigured. INT_STAT%u: %# 08x\n" ,
1604
1589
base / 32 , value );
1605
1590
}
1606
1591
@@ -1764,15 +1749,17 @@ static int byt_gpio_suspend(struct device *dev)
1764
1749
1765
1750
reg = byt_gpio_reg (vg , pin , BYT_CONF0_REG );
1766
1751
if (!reg ) {
1767
- dev_warn (vg -> dev ,
1768
- "Pin %i: could not retrieve conf0 register\n" ,
1769
- i );
1752
+ dev_warn (vg -> dev , "Pin %i: can't retrieve CONF0\n" , i );
1770
1753
continue ;
1771
1754
}
1772
1755
value = readl (reg ) & BYT_CONF0_RESTORE_MASK ;
1773
1756
vg -> context .pads [i ].conf0 = value ;
1774
1757
1775
1758
reg = byt_gpio_reg (vg , pin , BYT_VAL_REG );
1759
+ if (!reg ) {
1760
+ dev_warn (vg -> dev , "Pin %i: can't retrieve VAL\n" , i );
1761
+ continue ;
1762
+ }
1776
1763
value = readl (reg ) & BYT_VAL_RESTORE_MASK ;
1777
1764
vg -> context .pads [i ].val = value ;
1778
1765
}
@@ -1796,9 +1783,7 @@ static int byt_gpio_resume(struct device *dev)
1796
1783
1797
1784
reg = byt_gpio_reg (vg , pin , BYT_CONF0_REG );
1798
1785
if (!reg ) {
1799
- dev_warn (vg -> dev ,
1800
- "Pin %i: could not retrieve conf0 register\n" ,
1801
- i );
1786
+ dev_warn (vg -> dev , "Pin %i: can't retrieve CONF0\n" , i );
1802
1787
continue ;
1803
1788
}
1804
1789
value = readl (reg );
@@ -1807,10 +1792,14 @@ static int byt_gpio_resume(struct device *dev)
1807
1792
value &= ~BYT_CONF0_RESTORE_MASK ;
1808
1793
value |= vg -> context .pads [i ].conf0 ;
1809
1794
writel (value , reg );
1810
- dev_info (dev , "restored pin %d conf0 %#08x" , i , value );
1795
+ dev_info (dev , "restored pin %d CONF0 %#08x" , i , value );
1811
1796
}
1812
1797
1813
1798
reg = byt_gpio_reg (vg , pin , BYT_VAL_REG );
1799
+ if (!reg ) {
1800
+ dev_warn (vg -> dev , "Pin %i: can't retrieve VAL\n" , i );
1801
+ continue ;
1802
+ }
1814
1803
value = readl (reg );
1815
1804
if ((value & BYT_VAL_RESTORE_MASK ) !=
1816
1805
vg -> context .pads [i ].val ) {
@@ -1820,8 +1809,7 @@ static int byt_gpio_resume(struct device *dev)
1820
1809
v |= vg -> context .pads [i ].val ;
1821
1810
if (v != value ) {
1822
1811
writel (v , reg );
1823
- dev_dbg (dev , "restored pin %d val %#08x\n" ,
1824
- i , v );
1812
+ dev_dbg (dev , "restored pin %d VAL %#08x\n" , i , v );
1825
1813
}
1826
1814
}
1827
1815
}
0 commit comments