1
1
// SPDX-License-Identifier: GPL-2.0
2
2
/*
3
- * Device driver for the via-pmu on Apple Powermacs .
3
+ * Device driver for the PMU in Apple PowerBooks and PowerMacs .
4
4
*
5
5
* The VIA (versatile interface adapter) interfaces to the PMU,
6
6
* a 6805 microprocessor core whose primary function is to control
49
49
#include <linux/compat.h>
50
50
#include <linux/of_address.h>
51
51
#include <linux/of_irq.h>
52
- #include <asm/prom .h>
52
+ #include <linux/uaccess .h>
53
53
#include <asm/machdep.h>
54
54
#include <asm/io.h>
55
55
#include <asm/pgtable.h>
56
56
#include <asm/sections.h>
57
57
#include <asm/irq.h>
58
+ #ifdef CONFIG_PPC_PMAC
58
59
#include <asm/pmac_feature.h>
59
60
#include <asm/pmac_pfunc.h>
60
61
#include <asm/pmac_low_i2c.h>
61
- #include <linux/uaccess .h>
62
+ #include <asm/prom .h>
62
63
#include <asm/mmu_context.h>
63
64
#include <asm/cputable.h>
64
65
#include <asm/time.h>
65
66
#include <asm/backlight.h>
67
+ #else
68
+ #include <asm/macintosh.h>
69
+ #include <asm/macints.h>
70
+ #include <asm/mac_via.h>
71
+ #endif
66
72
67
73
#include "via-pmu-event.h"
68
74
@@ -97,8 +103,13 @@ static DEFINE_MUTEX(pmu_info_proc_mutex);
97
103
#define ANH (15*RS) /* A-side data, no handshake */
98
104
99
105
/* Bits in B data register: both active low */
106
+ #ifdef CONFIG_PPC_PMAC
100
107
#define TACK 0x08 /* Transfer acknowledge (input) */
101
108
#define TREQ 0x10 /* Transfer request (output) */
109
+ #else
110
+ #define TACK 0x02
111
+ #define TREQ 0x04
112
+ #endif
102
113
103
114
/* Bits in ACR */
104
115
#define SR_CTRL 0x1c /* Shift register control bits */
@@ -140,13 +151,15 @@ static int data_index;
140
151
static int data_len ;
141
152
static volatile int adb_int_pending ;
142
153
static volatile int disable_poll ;
143
- static struct device_node * vias ;
144
154
static int pmu_kind = PMU_UNKNOWN ;
145
155
static int pmu_fully_inited ;
146
156
static int pmu_has_adb ;
157
+ #ifdef CONFIG_PPC_PMAC
147
158
static volatile unsigned char __iomem * via1 ;
148
159
static volatile unsigned char __iomem * via2 ;
160
+ static struct device_node * vias ;
149
161
static struct device_node * gpio_node ;
162
+ #endif
150
163
static unsigned char __iomem * gpio_reg ;
151
164
static int gpio_irq = 0 ;
152
165
static int gpio_irq_enabled = -1 ;
@@ -273,6 +286,7 @@ static char *pbook_type[] = {
273
286
274
287
int __init find_via_pmu (void )
275
288
{
289
+ #ifdef CONFIG_PPC_PMAC
276
290
u64 taddr ;
277
291
const u32 * reg ;
278
292
@@ -355,9 +369,6 @@ int __init find_via_pmu(void)
355
369
if (!init_pmu ())
356
370
goto fail_init ;
357
371
358
- printk (KERN_INFO "PMU driver v%d initialized for %s, firmware: %02x\n" ,
359
- PMU_DRIVER_VERSION , pbook_type [pmu_kind ], pmu_version );
360
-
361
372
sys_ctrler = SYS_CTRLER_PMU ;
362
373
363
374
return 1 ;
@@ -373,6 +384,30 @@ int __init find_via_pmu(void)
373
384
vias = NULL ;
374
385
pmu_state = uninitialized ;
375
386
return 0 ;
387
+ #else
388
+ if (macintosh_config -> adb_type != MAC_ADB_PB2 )
389
+ return 0 ;
390
+
391
+ pmu_kind = PMU_UNKNOWN ;
392
+
393
+ spin_lock_init (& pmu_lock );
394
+
395
+ pmu_has_adb = 1 ;
396
+
397
+ pmu_intr_mask = PMU_INT_PCEJECT |
398
+ PMU_INT_SNDBRT |
399
+ PMU_INT_ADB |
400
+ PMU_INT_TICK ;
401
+
402
+ pmu_state = idle ;
403
+
404
+ if (!init_pmu ()) {
405
+ pmu_state = uninitialized ;
406
+ return 0 ;
407
+ }
408
+
409
+ return 1 ;
410
+ #endif /* !CONFIG_PPC_PMAC */
376
411
}
377
412
378
413
#ifdef CONFIG_ADB
@@ -396,13 +431,14 @@ static int pmu_init(void)
396
431
*/
397
432
static int __init via_pmu_start (void )
398
433
{
399
- unsigned int irq ;
434
+ unsigned int __maybe_unused irq ;
400
435
401
436
if (pmu_state == uninitialized )
402
437
return - ENODEV ;
403
438
404
439
batt_req .complete = 1 ;
405
440
441
+ #ifdef CONFIG_PPC_PMAC
406
442
irq = irq_of_parse_and_map (vias , 0 );
407
443
if (!irq ) {
408
444
printk (KERN_ERR "via-pmu: can't map interrupt\n" );
@@ -439,6 +475,19 @@ static int __init via_pmu_start(void)
439
475
440
476
/* Enable interrupts */
441
477
out_8 (& via1 [IER ], IER_SET | SR_INT | CB1_INT );
478
+ #else
479
+ if (request_irq (IRQ_MAC_ADB_SR , via_pmu_interrupt , IRQF_NO_SUSPEND ,
480
+ "VIA-PMU-SR" , NULL )) {
481
+ pr_err ("%s: couldn't get SR irq\n" , __func__ );
482
+ return - ENODEV ;
483
+ }
484
+ if (request_irq (IRQ_MAC_ADB_CL , via_pmu_interrupt , IRQF_NO_SUSPEND ,
485
+ "VIA-PMU-CL" , NULL )) {
486
+ pr_err ("%s: couldn't get CL irq\n" , __func__ );
487
+ free_irq (IRQ_MAC_ADB_SR , NULL );
488
+ return - ENODEV ;
489
+ }
490
+ #endif /* !CONFIG_PPC_PMAC */
442
491
443
492
pmu_fully_inited = 1 ;
444
493
@@ -589,6 +638,10 @@ init_pmu(void)
589
638
option_server_mode ? "enabled" : "disabled" );
590
639
}
591
640
}
641
+
642
+ printk (KERN_INFO "PMU driver v%d initialized for %s, firmware: %02x\n" ,
643
+ PMU_DRIVER_VERSION , pbook_type [pmu_kind ], pmu_version );
644
+
592
645
return 1 ;
593
646
}
594
647
@@ -627,6 +680,7 @@ static void pmu_set_server_mode(int server_mode)
627
680
static void
628
681
done_battery_state_ohare (struct adb_request * req )
629
682
{
683
+ #ifdef CONFIG_PPC_PMAC
630
684
/* format:
631
685
* [0] : flags
632
686
* 0x01 : AC indicator
@@ -708,6 +762,7 @@ done_battery_state_ohare(struct adb_request* req)
708
762
pmu_batteries [pmu_cur_battery ].amperage = amperage ;
709
763
pmu_batteries [pmu_cur_battery ].voltage = voltage ;
710
764
pmu_batteries [pmu_cur_battery ].time_remaining = time ;
765
+ #endif /* CONFIG_PPC_PMAC */
711
766
712
767
clear_bit (0 , & async_req_locks );
713
768
}
@@ -1356,13 +1411,15 @@ pmu_handle_data(unsigned char *data, int len)
1356
1411
}
1357
1412
pmu_done (req );
1358
1413
} else {
1414
+ #ifdef CONFIG_XMON
1359
1415
if (len == 4 && data [1 ] == 0x2c ) {
1360
1416
extern int xmon_wants_key , xmon_adb_keycode ;
1361
1417
if (xmon_wants_key ) {
1362
1418
xmon_adb_keycode = data [2 ];
1363
1419
return ;
1364
1420
}
1365
1421
}
1422
+ #endif /* CONFIG_XMON */
1366
1423
#ifdef CONFIG_ADB
1367
1424
/*
1368
1425
* XXX On the [23]400 the PMU gives us an up
@@ -1530,7 +1587,25 @@ via_pmu_interrupt(int irq, void *arg)
1530
1587
++ disable_poll ;
1531
1588
1532
1589
for (;;) {
1533
- intr = in_8 (& via1 [IFR ]) & (SR_INT | CB1_INT );
1590
+ /* On 68k Macs, VIA interrupts are dispatched individually.
1591
+ * Unless we are polling, the relevant IRQ flag has already
1592
+ * been cleared.
1593
+ */
1594
+ intr = 0 ;
1595
+ if (IS_ENABLED (CONFIG_PPC_PMAC ) || !irq ) {
1596
+ intr = in_8 (& via1 [IFR ]) & (SR_INT | CB1_INT );
1597
+ out_8 (& via1 [IFR ], intr );
1598
+ }
1599
+ #ifndef CONFIG_PPC_PMAC
1600
+ switch (irq ) {
1601
+ case IRQ_MAC_ADB_CL :
1602
+ intr = CB1_INT ;
1603
+ break ;
1604
+ case IRQ_MAC_ADB_SR :
1605
+ intr = SR_INT ;
1606
+ break ;
1607
+ }
1608
+ #endif
1534
1609
if (intr == 0 )
1535
1610
break ;
1536
1611
handled = 1 ;
@@ -1540,7 +1615,6 @@ via_pmu_interrupt(int irq, void *arg)
1540
1615
intr , in_8 (& via1 [IER ]), pmu_state );
1541
1616
break ;
1542
1617
}
1543
- out_8 (& via1 [IFR ], intr );
1544
1618
if (intr & CB1_INT ) {
1545
1619
adb_int_pending = 1 ;
1546
1620
pmu_irq_stats [0 ]++ ;
@@ -1550,6 +1624,9 @@ via_pmu_interrupt(int irq, void *arg)
1550
1624
if (req )
1551
1625
break ;
1552
1626
}
1627
+ #ifndef CONFIG_PPC_PMAC
1628
+ break ;
1629
+ #endif
1553
1630
}
1554
1631
1555
1632
recheck :
@@ -1616,7 +1693,7 @@ pmu_unlock(void)
1616
1693
}
1617
1694
1618
1695
1619
- static irqreturn_t
1696
+ static __maybe_unused irqreturn_t
1620
1697
gpio1_interrupt (int irq , void * arg )
1621
1698
{
1622
1699
unsigned long flags ;
@@ -2250,6 +2327,7 @@ static int pmu_ioctl(struct file *filp,
2250
2327
int error = - EINVAL ;
2251
2328
2252
2329
switch (cmd ) {
2330
+ #ifdef CONFIG_PPC_PMAC
2253
2331
case PMU_IOC_SLEEP :
2254
2332
if (!capable (CAP_SYS_ADMIN ))
2255
2333
return - EACCES ;
@@ -2259,6 +2337,7 @@ static int pmu_ioctl(struct file *filp,
2259
2337
return put_user (0 , argp );
2260
2338
else
2261
2339
return put_user (1 , argp );
2340
+ #endif
2262
2341
2263
2342
#ifdef CONFIG_PMAC_BACKLIGHT_LEGACY
2264
2343
/* Compatibility ioctl's for backlight */
0 commit comments