diff options
author | Finn Thain <fthain@telegraphics.com.au> | 2018-07-02 04:21:18 -0400 |
---|---|---|
committer | Michael Ellerman <mpe@ellerman.id.au> | 2018-07-31 05:56:40 -0400 |
commit | c70c35da52c064983199b1b1cbd4daa5a07ef60c (patch) | |
tree | 9c4c0a52e1cfadf7340c356357ce2d09be7af0e4 /drivers/macintosh | |
parent | c57902d52e2d61299872ddc89645d3aa299f1b91 (diff) |
macintosh/via-pmu: Replace via pointer with via1 and via2 pointers
On most PowerPC Macs, the PMU driver uses the shift register and
IO port B from a single VIA chip.
On 68k and early PowerPC PowerBooks, the driver uses the shift register
from one VIA chip together with IO port B from another.
Replace via with via1 and via2 to accommodate this. For the
CONFIG_PPC_PMAC case, set via1 = via2 so there is no change.
Tested-by: Stan Johnson <userm57@yahoo.com>
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Diffstat (limited to 'drivers/macintosh')
-rw-r--r-- | drivers/macintosh/via-pmu.c | 142 |
1 files changed, 69 insertions, 73 deletions
diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c index 6a6f1666712e..2557f3e49f18 100644 --- a/drivers/macintosh/via-pmu.c +++ b/drivers/macintosh/via-pmu.c | |||
@@ -76,7 +76,6 @@ | |||
76 | #define BATTERY_POLLING_COUNT 2 | 76 | #define BATTERY_POLLING_COUNT 2 |
77 | 77 | ||
78 | static DEFINE_MUTEX(pmu_info_proc_mutex); | 78 | static DEFINE_MUTEX(pmu_info_proc_mutex); |
79 | static volatile unsigned char __iomem *via; | ||
80 | 79 | ||
81 | /* VIA registers - spaced 0x200 bytes apart */ | 80 | /* VIA registers - spaced 0x200 bytes apart */ |
82 | #define RS 0x200 /* skip between registers */ | 81 | #define RS 0x200 /* skip between registers */ |
@@ -145,6 +144,8 @@ static struct device_node *vias; | |||
145 | static int pmu_kind = PMU_UNKNOWN; | 144 | static int pmu_kind = PMU_UNKNOWN; |
146 | static int pmu_fully_inited; | 145 | static int pmu_fully_inited; |
147 | static int pmu_has_adb; | 146 | static int pmu_has_adb; |
147 | static volatile unsigned char __iomem *via1; | ||
148 | static volatile unsigned char __iomem *via2; | ||
148 | static struct device_node *gpio_node; | 149 | static struct device_node *gpio_node; |
149 | static unsigned char __iomem *gpio_reg; | 150 | static unsigned char __iomem *gpio_reg; |
150 | static int gpio_irq = 0; | 151 | static int gpio_irq = 0; |
@@ -340,14 +341,14 @@ int __init find_via_pmu(void) | |||
340 | } else | 341 | } else |
341 | pmu_kind = PMU_UNKNOWN; | 342 | pmu_kind = PMU_UNKNOWN; |
342 | 343 | ||
343 | via = ioremap(taddr, 0x2000); | 344 | via1 = via2 = ioremap(taddr, 0x2000); |
344 | if (via == NULL) { | 345 | if (via1 == NULL) { |
345 | printk(KERN_ERR "via-pmu: Can't map address !\n"); | 346 | printk(KERN_ERR "via-pmu: Can't map address !\n"); |
346 | goto fail_via_remap; | 347 | goto fail_via_remap; |
347 | } | 348 | } |
348 | 349 | ||
349 | out_8(&via[IER], IER_CLR | 0x7f); /* disable all intrs */ | 350 | out_8(&via1[IER], IER_CLR | 0x7f); /* disable all intrs */ |
350 | out_8(&via[IFR], 0x7f); /* clear IFR */ | 351 | out_8(&via1[IFR], 0x7f); /* clear IFR */ |
351 | 352 | ||
352 | pmu_state = idle; | 353 | pmu_state = idle; |
353 | 354 | ||
@@ -362,8 +363,8 @@ int __init find_via_pmu(void) | |||
362 | return 1; | 363 | return 1; |
363 | 364 | ||
364 | fail_init: | 365 | fail_init: |
365 | iounmap(via); | 366 | iounmap(via1); |
366 | via = NULL; | 367 | via1 = via2 = NULL; |
367 | fail_via_remap: | 368 | fail_via_remap: |
368 | iounmap(gpio_reg); | 369 | iounmap(gpio_reg); |
369 | gpio_reg = NULL; | 370 | gpio_reg = NULL; |
@@ -437,7 +438,7 @@ static int __init via_pmu_start(void) | |||
437 | } | 438 | } |
438 | 439 | ||
439 | /* Enable interrupts */ | 440 | /* Enable interrupts */ |
440 | out_8(&via[IER], IER_SET | SR_INT | CB1_INT); | 441 | out_8(&via1[IER], IER_SET | SR_INT | CB1_INT); |
441 | 442 | ||
442 | pmu_fully_inited = 1; | 443 | pmu_fully_inited = 1; |
443 | 444 | ||
@@ -535,8 +536,8 @@ init_pmu(void) | |||
535 | struct adb_request req; | 536 | struct adb_request req; |
536 | 537 | ||
537 | /* Negate TREQ. Set TACK to input and TREQ to output. */ | 538 | /* Negate TREQ. Set TACK to input and TREQ to output. */ |
538 | out_8(&via[B], in_8(&via[B]) | TREQ); | 539 | out_8(&via2[B], in_8(&via2[B]) | TREQ); |
539 | out_8(&via[DIRB], (in_8(&via[DIRB]) | TREQ) & ~TACK); | 540 | out_8(&via2[DIRB], (in_8(&via2[DIRB]) | TREQ) & ~TACK); |
540 | 541 | ||
541 | pmu_request(&req, NULL, 2, PMU_SET_INTR_MASK, pmu_intr_mask); | 542 | pmu_request(&req, NULL, 2, PMU_SET_INTR_MASK, pmu_intr_mask); |
542 | timeout = 100000; | 543 | timeout = 100000; |
@@ -1137,7 +1138,7 @@ wait_for_ack(void) | |||
1137 | * reported | 1138 | * reported |
1138 | */ | 1139 | */ |
1139 | int timeout = 4000; | 1140 | int timeout = 4000; |
1140 | while ((in_8(&via[B]) & TACK) == 0) { | 1141 | while ((in_8(&via2[B]) & TACK) == 0) { |
1141 | if (--timeout < 0) { | 1142 | if (--timeout < 0) { |
1142 | printk(KERN_ERR "PMU not responding (!ack)\n"); | 1143 | printk(KERN_ERR "PMU not responding (!ack)\n"); |
1143 | return; | 1144 | return; |
@@ -1151,23 +1152,19 @@ wait_for_ack(void) | |||
1151 | static inline void | 1152 | static inline void |
1152 | send_byte(int x) | 1153 | send_byte(int x) |
1153 | { | 1154 | { |
1154 | volatile unsigned char __iomem *v = via; | 1155 | out_8(&via1[ACR], in_8(&via1[ACR]) | SR_OUT | SR_EXT); |
1155 | 1156 | out_8(&via1[SR], x); | |
1156 | out_8(&v[ACR], in_8(&v[ACR]) | SR_OUT | SR_EXT); | 1157 | out_8(&via2[B], in_8(&via2[B]) & ~TREQ); /* assert TREQ */ |
1157 | out_8(&v[SR], x); | 1158 | (void)in_8(&via2[B]); |
1158 | out_8(&v[B], in_8(&v[B]) & ~TREQ); /* assert TREQ */ | ||
1159 | (void)in_8(&v[B]); | ||
1160 | } | 1159 | } |
1161 | 1160 | ||
1162 | static inline void | 1161 | static inline void |
1163 | recv_byte(void) | 1162 | recv_byte(void) |
1164 | { | 1163 | { |
1165 | volatile unsigned char __iomem *v = via; | 1164 | out_8(&via1[ACR], (in_8(&via1[ACR]) & ~SR_OUT) | SR_EXT); |
1166 | 1165 | in_8(&via1[SR]); /* resets SR */ | |
1167 | out_8(&v[ACR], (in_8(&v[ACR]) & ~SR_OUT) | SR_EXT); | 1166 | out_8(&via2[B], in_8(&via2[B]) & ~TREQ); |
1168 | in_8(&v[SR]); /* resets SR */ | 1167 | (void)in_8(&via2[B]); |
1169 | out_8(&v[B], in_8(&v[B]) & ~TREQ); | ||
1170 | (void)in_8(&v[B]); | ||
1171 | } | 1168 | } |
1172 | 1169 | ||
1173 | static inline void | 1170 | static inline void |
@@ -1270,7 +1267,7 @@ pmu_suspend(void) | |||
1270 | if (!adb_int_pending && pmu_state == idle && !req_awaiting_reply) { | 1267 | if (!adb_int_pending && pmu_state == idle && !req_awaiting_reply) { |
1271 | if (gpio_irq >= 0) | 1268 | if (gpio_irq >= 0) |
1272 | disable_irq_nosync(gpio_irq); | 1269 | disable_irq_nosync(gpio_irq); |
1273 | out_8(&via[IER], CB1_INT | IER_CLR); | 1270 | out_8(&via1[IER], CB1_INT | IER_CLR); |
1274 | spin_unlock_irqrestore(&pmu_lock, flags); | 1271 | spin_unlock_irqrestore(&pmu_lock, flags); |
1275 | break; | 1272 | break; |
1276 | } | 1273 | } |
@@ -1294,7 +1291,7 @@ pmu_resume(void) | |||
1294 | adb_int_pending = 1; | 1291 | adb_int_pending = 1; |
1295 | if (gpio_irq >= 0) | 1292 | if (gpio_irq >= 0) |
1296 | enable_irq(gpio_irq); | 1293 | enable_irq(gpio_irq); |
1297 | out_8(&via[IER], CB1_INT | IER_SET); | 1294 | out_8(&via1[IER], CB1_INT | IER_SET); |
1298 | spin_unlock_irqrestore(&pmu_lock, flags); | 1295 | spin_unlock_irqrestore(&pmu_lock, flags); |
1299 | pmu_poll(); | 1296 | pmu_poll(); |
1300 | } | 1297 | } |
@@ -1419,20 +1416,20 @@ pmu_sr_intr(void) | |||
1419 | struct adb_request *req; | 1416 | struct adb_request *req; |
1420 | int bite = 0; | 1417 | int bite = 0; |
1421 | 1418 | ||
1422 | if (in_8(&via[B]) & TREQ) { | 1419 | if (in_8(&via2[B]) & TREQ) { |
1423 | printk(KERN_ERR "PMU: spurious SR intr (%x)\n", in_8(&via[B])); | 1420 | printk(KERN_ERR "PMU: spurious SR intr (%x)\n", in_8(&via2[B])); |
1424 | return NULL; | 1421 | return NULL; |
1425 | } | 1422 | } |
1426 | /* The ack may not yet be low when we get the interrupt */ | 1423 | /* The ack may not yet be low when we get the interrupt */ |
1427 | while ((in_8(&via[B]) & TACK) != 0) | 1424 | while ((in_8(&via2[B]) & TACK) != 0) |
1428 | ; | 1425 | ; |
1429 | 1426 | ||
1430 | /* if reading grab the byte, and reset the interrupt */ | 1427 | /* if reading grab the byte, and reset the interrupt */ |
1431 | if (pmu_state == reading || pmu_state == reading_intr) | 1428 | if (pmu_state == reading || pmu_state == reading_intr) |
1432 | bite = in_8(&via[SR]); | 1429 | bite = in_8(&via1[SR]); |
1433 | 1430 | ||
1434 | /* reset TREQ and wait for TACK to go high */ | 1431 | /* reset TREQ and wait for TACK to go high */ |
1435 | out_8(&via[B], in_8(&via[B]) | TREQ); | 1432 | out_8(&via2[B], in_8(&via2[B]) | TREQ); |
1436 | wait_for_ack(); | 1433 | wait_for_ack(); |
1437 | 1434 | ||
1438 | switch (pmu_state) { | 1435 | switch (pmu_state) { |
@@ -1533,17 +1530,17 @@ via_pmu_interrupt(int irq, void *arg) | |||
1533 | ++disable_poll; | 1530 | ++disable_poll; |
1534 | 1531 | ||
1535 | for (;;) { | 1532 | for (;;) { |
1536 | intr = in_8(&via[IFR]) & (SR_INT | CB1_INT); | 1533 | intr = in_8(&via1[IFR]) & (SR_INT | CB1_INT); |
1537 | if (intr == 0) | 1534 | if (intr == 0) |
1538 | break; | 1535 | break; |
1539 | handled = 1; | 1536 | handled = 1; |
1540 | if (++nloop > 1000) { | 1537 | if (++nloop > 1000) { |
1541 | printk(KERN_DEBUG "PMU: stuck in intr loop, " | 1538 | printk(KERN_DEBUG "PMU: stuck in intr loop, " |
1542 | "intr=%x, ier=%x pmu_state=%d\n", | 1539 | "intr=%x, ier=%x pmu_state=%d\n", |
1543 | intr, in_8(&via[IER]), pmu_state); | 1540 | intr, in_8(&via1[IER]), pmu_state); |
1544 | break; | 1541 | break; |
1545 | } | 1542 | } |
1546 | out_8(&via[IFR], intr); | 1543 | out_8(&via1[IFR], intr); |
1547 | if (intr & CB1_INT) { | 1544 | if (intr & CB1_INT) { |
1548 | adb_int_pending = 1; | 1545 | adb_int_pending = 1; |
1549 | pmu_irq_stats[0]++; | 1546 | pmu_irq_stats[0]++; |
@@ -1725,29 +1722,29 @@ static u32 save_via[8]; | |||
1725 | static void | 1722 | static void |
1726 | save_via_state(void) | 1723 | save_via_state(void) |
1727 | { | 1724 | { |
1728 | save_via[0] = in_8(&via[ANH]); | 1725 | save_via[0] = in_8(&via1[ANH]); |
1729 | save_via[1] = in_8(&via[DIRA]); | 1726 | save_via[1] = in_8(&via1[DIRA]); |
1730 | save_via[2] = in_8(&via[B]); | 1727 | save_via[2] = in_8(&via1[B]); |
1731 | save_via[3] = in_8(&via[DIRB]); | 1728 | save_via[3] = in_8(&via1[DIRB]); |
1732 | save_via[4] = in_8(&via[PCR]); | 1729 | save_via[4] = in_8(&via1[PCR]); |
1733 | save_via[5] = in_8(&via[ACR]); | 1730 | save_via[5] = in_8(&via1[ACR]); |
1734 | save_via[6] = in_8(&via[T1CL]); | 1731 | save_via[6] = in_8(&via1[T1CL]); |
1735 | save_via[7] = in_8(&via[T1CH]); | 1732 | save_via[7] = in_8(&via1[T1CH]); |
1736 | } | 1733 | } |
1737 | static void | 1734 | static void |
1738 | restore_via_state(void) | 1735 | restore_via_state(void) |
1739 | { | 1736 | { |
1740 | out_8(&via[ANH], save_via[0]); | 1737 | out_8(&via1[ANH], save_via[0]); |
1741 | out_8(&via[DIRA], save_via[1]); | 1738 | out_8(&via1[DIRA], save_via[1]); |
1742 | out_8(&via[B], save_via[2]); | 1739 | out_8(&via1[B], save_via[2]); |
1743 | out_8(&via[DIRB], save_via[3]); | 1740 | out_8(&via1[DIRB], save_via[3]); |
1744 | out_8(&via[PCR], save_via[4]); | 1741 | out_8(&via1[PCR], save_via[4]); |
1745 | out_8(&via[ACR], save_via[5]); | 1742 | out_8(&via1[ACR], save_via[5]); |
1746 | out_8(&via[T1CL], save_via[6]); | 1743 | out_8(&via1[T1CL], save_via[6]); |
1747 | out_8(&via[T1CH], save_via[7]); | 1744 | out_8(&via1[T1CH], save_via[7]); |
1748 | out_8(&via[IER], IER_CLR | 0x7f); /* disable all intrs */ | 1745 | out_8(&via1[IER], IER_CLR | 0x7f); /* disable all intrs */ |
1749 | out_8(&via[IFR], 0x7f); /* clear IFR */ | 1746 | out_8(&via1[IFR], 0x7f); /* clear IFR */ |
1750 | out_8(&via[IER], IER_SET | SR_INT | CB1_INT); | 1747 | out_8(&via1[IER], IER_SET | SR_INT | CB1_INT); |
1751 | } | 1748 | } |
1752 | 1749 | ||
1753 | #define GRACKLE_PM (1<<7) | 1750 | #define GRACKLE_PM (1<<7) |
@@ -2389,33 +2386,33 @@ device_initcall(pmu_device_init); | |||
2389 | 2386 | ||
2390 | #ifdef DEBUG_SLEEP | 2387 | #ifdef DEBUG_SLEEP |
2391 | static inline void | 2388 | static inline void |
2392 | polled_handshake(volatile unsigned char __iomem *via) | 2389 | polled_handshake(void) |
2393 | { | 2390 | { |
2394 | via[B] &= ~TREQ; eieio(); | 2391 | via2[B] &= ~TREQ; eieio(); |
2395 | while ((via[B] & TACK) != 0) | 2392 | while ((via2[B] & TACK) != 0) |
2396 | ; | 2393 | ; |
2397 | via[B] |= TREQ; eieio(); | 2394 | via2[B] |= TREQ; eieio(); |
2398 | while ((via[B] & TACK) == 0) | 2395 | while ((via2[B] & TACK) == 0) |
2399 | ; | 2396 | ; |
2400 | } | 2397 | } |
2401 | 2398 | ||
2402 | static inline void | 2399 | static inline void |
2403 | polled_send_byte(volatile unsigned char __iomem *via, int x) | 2400 | polled_send_byte(int x) |
2404 | { | 2401 | { |
2405 | via[ACR] |= SR_OUT | SR_EXT; eieio(); | 2402 | via1[ACR] |= SR_OUT | SR_EXT; eieio(); |
2406 | via[SR] = x; eieio(); | 2403 | via1[SR] = x; eieio(); |
2407 | polled_handshake(via); | 2404 | polled_handshake(); |
2408 | } | 2405 | } |
2409 | 2406 | ||
2410 | static inline int | 2407 | static inline int |
2411 | polled_recv_byte(volatile unsigned char __iomem *via) | 2408 | polled_recv_byte(void) |
2412 | { | 2409 | { |
2413 | int x; | 2410 | int x; |
2414 | 2411 | ||
2415 | via[ACR] = (via[ACR] & ~SR_OUT) | SR_EXT; eieio(); | 2412 | via1[ACR] = (via1[ACR] & ~SR_OUT) | SR_EXT; eieio(); |
2416 | x = via[SR]; eieio(); | 2413 | x = via1[SR]; eieio(); |
2417 | polled_handshake(via); | 2414 | polled_handshake(); |
2418 | x = via[SR]; eieio(); | 2415 | x = via1[SR]; eieio(); |
2419 | return x; | 2416 | return x; |
2420 | } | 2417 | } |
2421 | 2418 | ||
@@ -2424,7 +2421,6 @@ pmu_polled_request(struct adb_request *req) | |||
2424 | { | 2421 | { |
2425 | unsigned long flags; | 2422 | unsigned long flags; |
2426 | int i, l, c; | 2423 | int i, l, c; |
2427 | volatile unsigned char __iomem *v = via; | ||
2428 | 2424 | ||
2429 | req->complete = 1; | 2425 | req->complete = 1; |
2430 | c = req->data[0]; | 2426 | c = req->data[0]; |
@@ -2436,21 +2432,21 @@ pmu_polled_request(struct adb_request *req) | |||
2436 | while (pmu_state != idle) | 2432 | while (pmu_state != idle) |
2437 | pmu_poll(); | 2433 | pmu_poll(); |
2438 | 2434 | ||
2439 | while ((via[B] & TACK) == 0) | 2435 | while ((via2[B] & TACK) == 0) |
2440 | ; | 2436 | ; |
2441 | polled_send_byte(v, c); | 2437 | polled_send_byte(c); |
2442 | if (l < 0) { | 2438 | if (l < 0) { |
2443 | l = req->nbytes - 1; | 2439 | l = req->nbytes - 1; |
2444 | polled_send_byte(v, l); | 2440 | polled_send_byte(l); |
2445 | } | 2441 | } |
2446 | for (i = 1; i <= l; ++i) | 2442 | for (i = 1; i <= l; ++i) |
2447 | polled_send_byte(v, req->data[i]); | 2443 | polled_send_byte(req->data[i]); |
2448 | 2444 | ||
2449 | l = pmu_data_len[c][1]; | 2445 | l = pmu_data_len[c][1]; |
2450 | if (l < 0) | 2446 | if (l < 0) |
2451 | l = polled_recv_byte(v); | 2447 | l = polled_recv_byte(); |
2452 | for (i = 0; i < l; ++i) | 2448 | for (i = 0; i < l; ++i) |
2453 | req->reply[i + req->reply_len] = polled_recv_byte(v); | 2449 | req->reply[i + req->reply_len] = polled_recv_byte(); |
2454 | 2450 | ||
2455 | if (req->done) | 2451 | if (req->done) |
2456 | (*req->done)(req); | 2452 | (*req->done)(req); |