Skip to content

Commit c70c35d

Browse files
Finn Thainmpe
authored andcommitted
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>
1 parent c57902d commit c70c35d

File tree

1 file changed

+69
-73
lines changed

1 file changed

+69
-73
lines changed

drivers/macintosh/via-pmu.c

Lines changed: 69 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676
#define BATTERY_POLLING_COUNT 2
7777

7878
static DEFINE_MUTEX(pmu_info_proc_mutex);
79-
static volatile unsigned char __iomem *via;
8079

8180
/* VIA registers - spaced 0x200 bytes apart */
8281
#define RS 0x200 /* skip between registers */
@@ -145,6 +144,8 @@ static struct device_node *vias;
145144
static int pmu_kind = PMU_UNKNOWN;
146145
static int pmu_fully_inited;
147146
static int pmu_has_adb;
147+
static volatile unsigned char __iomem *via1;
148+
static volatile unsigned char __iomem *via2;
148149
static struct device_node *gpio_node;
149150
static unsigned char __iomem *gpio_reg;
150151
static int gpio_irq = 0;
@@ -340,14 +341,14 @@ int __init find_via_pmu(void)
340341
} else
341342
pmu_kind = PMU_UNKNOWN;
342343

343-
via = ioremap(taddr, 0x2000);
344-
if (via == NULL) {
344+
via1 = via2 = ioremap(taddr, 0x2000);
345+
if (via1 == NULL) {
345346
printk(KERN_ERR "via-pmu: Can't map address !\n");
346347
goto fail_via_remap;
347348
}
348349

349-
out_8(&via[IER], IER_CLR | 0x7f); /* disable all intrs */
350-
out_8(&via[IFR], 0x7f); /* clear IFR */
350+
out_8(&via1[IER], IER_CLR | 0x7f); /* disable all intrs */
351+
out_8(&via1[IFR], 0x7f); /* clear IFR */
351352

352353
pmu_state = idle;
353354

@@ -362,8 +363,8 @@ int __init find_via_pmu(void)
362363
return 1;
363364

364365
fail_init:
365-
iounmap(via);
366-
via = NULL;
366+
iounmap(via1);
367+
via1 = via2 = NULL;
367368
fail_via_remap:
368369
iounmap(gpio_reg);
369370
gpio_reg = NULL;
@@ -437,7 +438,7 @@ static int __init via_pmu_start(void)
437438
}
438439

439440
/* Enable interrupts */
440-
out_8(&via[IER], IER_SET | SR_INT | CB1_INT);
441+
out_8(&via1[IER], IER_SET | SR_INT | CB1_INT);
441442

442443
pmu_fully_inited = 1;
443444

@@ -535,8 +536,8 @@ init_pmu(void)
535536
struct adb_request req;
536537

537538
/* Negate TREQ. Set TACK to input and TREQ to output. */
538-
out_8(&via[B], in_8(&via[B]) | TREQ);
539-
out_8(&via[DIRB], (in_8(&via[DIRB]) | TREQ) & ~TACK);
539+
out_8(&via2[B], in_8(&via2[B]) | TREQ);
540+
out_8(&via2[DIRB], (in_8(&via2[DIRB]) | TREQ) & ~TACK);
540541

541542
pmu_request(&req, NULL, 2, PMU_SET_INTR_MASK, pmu_intr_mask);
542543
timeout = 100000;
@@ -1137,7 +1138,7 @@ wait_for_ack(void)
11371138
* reported
11381139
*/
11391140
int timeout = 4000;
1140-
while ((in_8(&via[B]) & TACK) == 0) {
1141+
while ((in_8(&via2[B]) & TACK) == 0) {
11411142
if (--timeout < 0) {
11421143
printk(KERN_ERR "PMU not responding (!ack)\n");
11431144
return;
@@ -1151,23 +1152,19 @@ wait_for_ack(void)
11511152
static inline void
11521153
send_byte(int x)
11531154
{
1154-
volatile unsigned char __iomem *v = via;
1155-
1156-
out_8(&v[ACR], in_8(&v[ACR]) | SR_OUT | SR_EXT);
1157-
out_8(&v[SR], x);
1158-
out_8(&v[B], in_8(&v[B]) & ~TREQ); /* assert TREQ */
1159-
(void)in_8(&v[B]);
1155+
out_8(&via1[ACR], in_8(&via1[ACR]) | SR_OUT | SR_EXT);
1156+
out_8(&via1[SR], x);
1157+
out_8(&via2[B], in_8(&via2[B]) & ~TREQ); /* assert TREQ */
1158+
(void)in_8(&via2[B]);
11601159
}
11611160

11621161
static inline void
11631162
recv_byte(void)
11641163
{
1165-
volatile unsigned char __iomem *v = via;
1166-
1167-
out_8(&v[ACR], (in_8(&v[ACR]) & ~SR_OUT) | SR_EXT);
1168-
in_8(&v[SR]); /* resets SR */
1169-
out_8(&v[B], in_8(&v[B]) & ~TREQ);
1170-
(void)in_8(&v[B]);
1164+
out_8(&via1[ACR], (in_8(&via1[ACR]) & ~SR_OUT) | SR_EXT);
1165+
in_8(&via1[SR]); /* resets SR */
1166+
out_8(&via2[B], in_8(&via2[B]) & ~TREQ);
1167+
(void)in_8(&via2[B]);
11711168
}
11721169

11731170
static inline void
@@ -1270,7 +1267,7 @@ pmu_suspend(void)
12701267
if (!adb_int_pending && pmu_state == idle && !req_awaiting_reply) {
12711268
if (gpio_irq >= 0)
12721269
disable_irq_nosync(gpio_irq);
1273-
out_8(&via[IER], CB1_INT | IER_CLR);
1270+
out_8(&via1[IER], CB1_INT | IER_CLR);
12741271
spin_unlock_irqrestore(&pmu_lock, flags);
12751272
break;
12761273
}
@@ -1294,7 +1291,7 @@ pmu_resume(void)
12941291
adb_int_pending = 1;
12951292
if (gpio_irq >= 0)
12961293
enable_irq(gpio_irq);
1297-
out_8(&via[IER], CB1_INT | IER_SET);
1294+
out_8(&via1[IER], CB1_INT | IER_SET);
12981295
spin_unlock_irqrestore(&pmu_lock, flags);
12991296
pmu_poll();
13001297
}
@@ -1419,20 +1416,20 @@ pmu_sr_intr(void)
14191416
struct adb_request *req;
14201417
int bite = 0;
14211418

1422-
if (in_8(&via[B]) & TREQ) {
1423-
printk(KERN_ERR "PMU: spurious SR intr (%x)\n", in_8(&via[B]));
1419+
if (in_8(&via2[B]) & TREQ) {
1420+
printk(KERN_ERR "PMU: spurious SR intr (%x)\n", in_8(&via2[B]));
14241421
return NULL;
14251422
}
14261423
/* 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)
14281425
;
14291426

14301427
/* if reading grab the byte, and reset the interrupt */
14311428
if (pmu_state == reading || pmu_state == reading_intr)
1432-
bite = in_8(&via[SR]);
1429+
bite = in_8(&via1[SR]);
14331430

14341431
/* 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);
14361433
wait_for_ack();
14371434

14381435
switch (pmu_state) {
@@ -1533,17 +1530,17 @@ via_pmu_interrupt(int irq, void *arg)
15331530
++disable_poll;
15341531

15351532
for (;;) {
1536-
intr = in_8(&via[IFR]) & (SR_INT | CB1_INT);
1533+
intr = in_8(&via1[IFR]) & (SR_INT | CB1_INT);
15371534
if (intr == 0)
15381535
break;
15391536
handled = 1;
15401537
if (++nloop > 1000) {
15411538
printk(KERN_DEBUG "PMU: stuck in intr loop, "
15421539
"intr=%x, ier=%x pmu_state=%d\n",
1543-
intr, in_8(&via[IER]), pmu_state);
1540+
intr, in_8(&via1[IER]), pmu_state);
15441541
break;
15451542
}
1546-
out_8(&via[IFR], intr);
1543+
out_8(&via1[IFR], intr);
15471544
if (intr & CB1_INT) {
15481545
adb_int_pending = 1;
15491546
pmu_irq_stats[0]++;
@@ -1725,29 +1722,29 @@ static u32 save_via[8];
17251722
static void
17261723
save_via_state(void)
17271724
{
1728-
save_via[0] = in_8(&via[ANH]);
1729-
save_via[1] = in_8(&via[DIRA]);
1730-
save_via[2] = in_8(&via[B]);
1731-
save_via[3] = in_8(&via[DIRB]);
1732-
save_via[4] = in_8(&via[PCR]);
1733-
save_via[5] = in_8(&via[ACR]);
1734-
save_via[6] = in_8(&via[T1CL]);
1735-
save_via[7] = in_8(&via[T1CH]);
1725+
save_via[0] = in_8(&via1[ANH]);
1726+
save_via[1] = in_8(&via1[DIRA]);
1727+
save_via[2] = in_8(&via1[B]);
1728+
save_via[3] = in_8(&via1[DIRB]);
1729+
save_via[4] = in_8(&via1[PCR]);
1730+
save_via[5] = in_8(&via1[ACR]);
1731+
save_via[6] = in_8(&via1[T1CL]);
1732+
save_via[7] = in_8(&via1[T1CH]);
17361733
}
17371734
static void
17381735
restore_via_state(void)
17391736
{
1740-
out_8(&via[ANH], save_via[0]);
1741-
out_8(&via[DIRA], save_via[1]);
1742-
out_8(&via[B], save_via[2]);
1743-
out_8(&via[DIRB], save_via[3]);
1744-
out_8(&via[PCR], save_via[4]);
1745-
out_8(&via[ACR], save_via[5]);
1746-
out_8(&via[T1CL], save_via[6]);
1747-
out_8(&via[T1CH], save_via[7]);
1748-
out_8(&via[IER], IER_CLR | 0x7f); /* disable all intrs */
1749-
out_8(&via[IFR], 0x7f); /* clear IFR */
1750-
out_8(&via[IER], IER_SET | SR_INT | CB1_INT);
1737+
out_8(&via1[ANH], save_via[0]);
1738+
out_8(&via1[DIRA], save_via[1]);
1739+
out_8(&via1[B], save_via[2]);
1740+
out_8(&via1[DIRB], save_via[3]);
1741+
out_8(&via1[PCR], save_via[4]);
1742+
out_8(&via1[ACR], save_via[5]);
1743+
out_8(&via1[T1CL], save_via[6]);
1744+
out_8(&via1[T1CH], save_via[7]);
1745+
out_8(&via1[IER], IER_CLR | 0x7f); /* disable all intrs */
1746+
out_8(&via1[IFR], 0x7f); /* clear IFR */
1747+
out_8(&via1[IER], IER_SET | SR_INT | CB1_INT);
17511748
}
17521749

17531750
#define GRACKLE_PM (1<<7)
@@ -2389,33 +2386,33 @@ device_initcall(pmu_device_init);
23892386

23902387
#ifdef DEBUG_SLEEP
23912388
static inline void
2392-
polled_handshake(volatile unsigned char __iomem *via)
2389+
polled_handshake(void)
23932390
{
2394-
via[B] &= ~TREQ; eieio();
2395-
while ((via[B] & TACK) != 0)
2391+
via2[B] &= ~TREQ; eieio();
2392+
while ((via2[B] & TACK) != 0)
23962393
;
2397-
via[B] |= TREQ; eieio();
2398-
while ((via[B] & TACK) == 0)
2394+
via2[B] |= TREQ; eieio();
2395+
while ((via2[B] & TACK) == 0)
23992396
;
24002397
}
24012398

24022399
static inline void
2403-
polled_send_byte(volatile unsigned char __iomem *via, int x)
2400+
polled_send_byte(int x)
24042401
{
2405-
via[ACR] |= SR_OUT | SR_EXT; eieio();
2406-
via[SR] = x; eieio();
2407-
polled_handshake(via);
2402+
via1[ACR] |= SR_OUT | SR_EXT; eieio();
2403+
via1[SR] = x; eieio();
2404+
polled_handshake();
24082405
}
24092406

24102407
static inline int
2411-
polled_recv_byte(volatile unsigned char __iomem *via)
2408+
polled_recv_byte(void)
24122409
{
24132410
int x;
24142411

2415-
via[ACR] = (via[ACR] & ~SR_OUT) | SR_EXT; eieio();
2416-
x = via[SR]; eieio();
2417-
polled_handshake(via);
2418-
x = via[SR]; eieio();
2412+
via1[ACR] = (via1[ACR] & ~SR_OUT) | SR_EXT; eieio();
2413+
x = via1[SR]; eieio();
2414+
polled_handshake();
2415+
x = via1[SR]; eieio();
24192416
return x;
24202417
}
24212418

@@ -2424,7 +2421,6 @@ pmu_polled_request(struct adb_request *req)
24242421
{
24252422
unsigned long flags;
24262423
int i, l, c;
2427-
volatile unsigned char __iomem *v = via;
24282424

24292425
req->complete = 1;
24302426
c = req->data[0];
@@ -2436,21 +2432,21 @@ pmu_polled_request(struct adb_request *req)
24362432
while (pmu_state != idle)
24372433
pmu_poll();
24382434

2439-
while ((via[B] & TACK) == 0)
2435+
while ((via2[B] & TACK) == 0)
24402436
;
2441-
polled_send_byte(v, c);
2437+
polled_send_byte(c);
24422438
if (l < 0) {
24432439
l = req->nbytes - 1;
2444-
polled_send_byte(v, l);
2440+
polled_send_byte(l);
24452441
}
24462442
for (i = 1; i <= l; ++i)
2447-
polled_send_byte(v, req->data[i]);
2443+
polled_send_byte(req->data[i]);
24482444

24492445
l = pmu_data_len[c][1];
24502446
if (l < 0)
2451-
l = polled_recv_byte(v);
2447+
l = polled_recv_byte();
24522448
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();
24542450

24552451
if (req->done)
24562452
(*req->done)(req);

0 commit comments

Comments
 (0)