Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

macintosh/via-pmu: Replace via-pmu68k driver with via-pmu driver

Now that the PowerMac via-pmu driver supports m68k PowerBooks,
switch over to that driver and remove the via-pmu68k driver.

Tested-by: Stan Johnson <userm57@yahoo.com>
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org>
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

authored by

Finn Thain and committed by
Michael Ellerman
ebd72227 54c99077

+14 -904
+1 -1
arch/m68k/configs/mac_defconfig
··· 369 369 CONFIG_ADB=y 370 370 CONFIG_ADB_MACII=y 371 371 CONFIG_ADB_IOP=y 372 - CONFIG_ADB_PMU68K=y 372 + CONFIG_ADB_PMU=y 373 373 CONFIG_ADB_CUDA=y 374 374 CONFIG_INPUT_ADBHID=y 375 375 CONFIG_MAC_EMUMOUSEBTN=y
+1 -1
arch/m68k/configs/multi_defconfig
··· 402 402 CONFIG_ADB=y 403 403 CONFIG_ADB_MACII=y 404 404 CONFIG_ADB_IOP=y 405 - CONFIG_ADB_PMU68K=y 405 + CONFIG_ADB_PMU=y 406 406 CONFIG_ADB_CUDA=y 407 407 CONFIG_INPUT_ADBHID=y 408 408 CONFIG_MAC_EMUMOUSEBTN=y
+1 -1
arch/m68k/mac/config.c
··· 891 891 #ifdef CONFIG_ADB_CUDA 892 892 find_via_cuda(); 893 893 #endif 894 - #ifdef CONFIG_ADB_PMU68K 894 + #ifdef CONFIG_ADB_PMU 895 895 find_via_pmu(); 896 896 #endif 897 897 }
+8 -40
arch/m68k/mac/misc.c
··· 85 85 } 86 86 #endif /* CONFIG_ADB_CUDA */ 87 87 88 - #ifdef CONFIG_ADB_PMU68K 88 + #ifdef CONFIG_ADB_PMU 89 89 static long pmu_read_time(void) 90 90 { 91 91 struct adb_request req; ··· 136 136 while (!req.complete) 137 137 pmu_poll(); 138 138 } 139 - #endif /* CONFIG_ADB_PMU68K */ 139 + #endif /* CONFIG_ADB_PMU */ 140 140 141 141 /* 142 142 * VIA PRAM/RTC access routines ··· 367 367 } 368 368 #endif /* CONFIG_ADB_CUDA */ 369 369 370 - #ifdef CONFIG_ADB_PMU68K 371 - 372 - void pmu_restart(void) 373 - { 374 - struct adb_request req; 375 - if (pmu_request(&req, NULL, 376 - 2, PMU_SET_INTR_MASK, PMU_INT_ADB|PMU_INT_TICK) < 0) 377 - return; 378 - while (!req.complete) 379 - pmu_poll(); 380 - if (pmu_request(&req, NULL, 1, PMU_RESET) < 0) 381 - return; 382 - while (!req.complete) 383 - pmu_poll(); 384 - } 385 - 386 - void pmu_shutdown(void) 387 - { 388 - struct adb_request req; 389 - if (pmu_request(&req, NULL, 390 - 2, PMU_SET_INTR_MASK, PMU_INT_ADB|PMU_INT_TICK) < 0) 391 - return; 392 - while (!req.complete) 393 - pmu_poll(); 394 - if (pmu_request(&req, NULL, 5, PMU_SHUTDOWN, 'M', 'A', 'T', 'T') < 0) 395 - return; 396 - while (!req.complete) 397 - pmu_poll(); 398 - } 399 - 400 - #endif 401 - 402 370 /* 403 371 *------------------------------------------------------------------- 404 372 * Below this point are the generic routines; they'll dispatch to the ··· 391 423 func = cuda_read_pram; 392 424 break; 393 425 #endif 394 - #ifdef CONFIG_ADB_PMU68K 426 + #ifdef CONFIG_ADB_PMU 395 427 case MAC_ADB_PB2: 396 428 func = pmu_read_pram; 397 429 break; ··· 421 453 func = cuda_write_pram; 422 454 break; 423 455 #endif 424 - #ifdef CONFIG_ADB_PMU68K 456 + #ifdef CONFIG_ADB_PMU 425 457 case MAC_ADB_PB2: 426 458 func = pmu_write_pram; 427 459 break; ··· 445 477 macintosh_config->adb_type == MAC_ADB_CUDA) { 446 478 cuda_shutdown(); 447 479 #endif 448 - #ifdef CONFIG_ADB_PMU68K 480 + #ifdef CONFIG_ADB_PMU 449 481 } else if (macintosh_config->adb_type == MAC_ADB_PB2) { 450 482 pmu_shutdown(); 451 483 #endif ··· 486 518 macintosh_config->adb_type == MAC_ADB_CUDA) { 487 519 cuda_restart(); 488 520 #endif 489 - #ifdef CONFIG_ADB_PMU68K 521 + #ifdef CONFIG_ADB_PMU 490 522 } else if (macintosh_config->adb_type == MAC_ADB_PB2) { 491 523 pmu_restart(); 492 524 #endif ··· 638 670 now = cuda_read_time(); 639 671 break; 640 672 #endif 641 - #ifdef CONFIG_ADB_PMU68K 673 + #ifdef CONFIG_ADB_PMU 642 674 case MAC_ADB_PB2: 643 675 now = pmu_read_time(); 644 676 break; ··· 674 706 cuda_write_time(now); 675 707 break; 676 708 #endif 677 - #ifdef CONFIG_ADB_PMU68K 709 + #ifdef CONFIG_ADB_PMU 678 710 case MAC_ADB_PB2: 679 711 pmu_write_time(now); 680 712 break;
+1 -12
drivers/macintosh/Kconfig
··· 39 39 <http://www.angelfire.com/ca2/dev68k/iopdesc.html> to enable direct 40 40 support for it, say 'Y' here. 41 41 42 - config ADB_PMU68K 43 - bool "Include PMU (Powerbook) ADB driver" 44 - depends on ADB && MAC 45 - help 46 - Say Y here if want your kernel to support the m68k based Powerbooks. 47 - This includes the PowerBook 140, PowerBook 145, PowerBook 150, 48 - PowerBook 160, PowerBook 165, PowerBook 165c, PowerBook 170, 49 - PowerBook 180, PowerBook, 180c, PowerBook 190cs, PowerBook 520, 50 - PowerBook Duo 210, PowerBook Duo 230, PowerBook Duo 250, 51 - PowerBook Duo 270c, PowerBook Duo 280 and PowerBook Duo 280c. 52 - 53 42 # we want to change this to something like CONFIG_SYSCTRL_CUDA/PMU 54 43 config ADB_CUDA 55 44 bool "Support for Cuda/Egret based Macs and PowerMacs" ··· 55 66 56 67 config ADB_PMU 57 68 bool "Support for PMU based PowerMacs and PowerBooks" 58 - depends on PPC_PMAC 69 + depends on PPC_PMAC || MAC 59 70 help 60 71 On PowerBooks, iBooks, and recent iMacs and Power Macintoshes, the 61 72 PMU is an embedded microprocessor whose primary function is to
-1
drivers/macintosh/Makefile
··· 22 22 obj-$(CONFIG_ADB) += adb.o 23 23 obj-$(CONFIG_ADB_MACII) += via-macii.o 24 24 obj-$(CONFIG_ADB_IOP) += adb-iop.o 25 - obj-$(CONFIG_ADB_PMU68K) += via-pmu68k.o 26 25 obj-$(CONFIG_ADB_MACIO) += macio-adb.o 27 26 28 27 obj-$(CONFIG_THERM_WINDTUNNEL) += therm_windtunnel.o
+1 -1
drivers/macintosh/adb.c
··· 65 65 #ifdef CONFIG_ADB_IOP 66 66 &adb_iop_driver, 67 67 #endif 68 - #if defined(CONFIG_ADB_PMU) || defined(CONFIG_ADB_PMU68K) 68 + #ifdef CONFIG_ADB_PMU 69 69 &via_pmu_driver, 70 70 #endif 71 71 #ifdef CONFIG_ADB_MACIO
-846
drivers/macintosh/via-pmu68k.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - /* 3 - * Device driver for the PMU on 68K-based Apple PowerBooks 4 - * 5 - * The VIA (versatile interface adapter) interfaces to the PMU, 6 - * a 6805 microprocessor core whose primary function is to control 7 - * battery charging and system power on the PowerBooks. 8 - * The PMU also controls the ADB (Apple Desktop Bus) which connects 9 - * to the keyboard and mouse, as well as the non-volatile RAM 10 - * and the RTC (real time clock) chip. 11 - * 12 - * Adapted for 68K PMU by Joshua M. Thompson 13 - * 14 - * Based largely on the PowerMac PMU code by Paul Mackerras and 15 - * Fabio Riccardi. 16 - * 17 - * Also based on the PMU driver from MkLinux by Apple Computer, Inc. 18 - * and the Open Software Foundation, Inc. 19 - */ 20 - 21 - #include <stdarg.h> 22 - #include <linux/types.h> 23 - #include <linux/errno.h> 24 - #include <linux/kernel.h> 25 - #include <linux/delay.h> 26 - #include <linux/miscdevice.h> 27 - #include <linux/blkdev.h> 28 - #include <linux/pci.h> 29 - #include <linux/init.h> 30 - #include <linux/interrupt.h> 31 - 32 - #include <linux/adb.h> 33 - #include <linux/pmu.h> 34 - #include <linux/cuda.h> 35 - 36 - #include <asm/macintosh.h> 37 - #include <asm/macints.h> 38 - #include <asm/mac_via.h> 39 - 40 - #include <asm/pgtable.h> 41 - #include <asm/irq.h> 42 - #include <linux/uaccess.h> 43 - 44 - /* Misc minor number allocated for /dev/pmu */ 45 - #define PMU_MINOR 154 46 - 47 - /* VIA registers - spaced 0x200 bytes apart */ 48 - #define RS 0x200 /* skip between registers */ 49 - #define B 0 /* B-side data */ 50 - #define A RS /* A-side data */ 51 - #define DIRB (2*RS) /* B-side direction (1=output) */ 52 - #define DIRA (3*RS) /* A-side direction (1=output) */ 53 - #define T1CL (4*RS) /* Timer 1 ctr/latch (low 8 bits) */ 54 - #define T1CH (5*RS) /* Timer 1 counter (high 8 bits) */ 55 - #define T1LL (6*RS) /* Timer 1 latch (low 8 bits) */ 56 - #define T1LH (7*RS) /* Timer 1 latch (high 8 bits) */ 57 - #define T2CL (8*RS) /* Timer 2 ctr/latch (low 8 bits) */ 58 - #define T2CH (9*RS) /* Timer 2 counter (high 8 bits) */ 59 - #define SR (10*RS) /* Shift register */ 60 - #define ACR (11*RS) /* Auxiliary control register */ 61 - #define PCR (12*RS) /* Peripheral control register */ 62 - #define IFR (13*RS) /* Interrupt flag register */ 63 - #define IER (14*RS) /* Interrupt enable register */ 64 - #define ANH (15*RS) /* A-side data, no handshake */ 65 - 66 - /* Bits in B data register: both active low */ 67 - #define TACK 0x02 /* Transfer acknowledge (input) */ 68 - #define TREQ 0x04 /* Transfer request (output) */ 69 - 70 - /* Bits in ACR */ 71 - #define SR_CTRL 0x1c /* Shift register control bits */ 72 - #define SR_EXT 0x0c /* Shift on external clock */ 73 - #define SR_OUT 0x10 /* Shift out if 1 */ 74 - 75 - /* Bits in IFR and IER */ 76 - #define SR_INT 0x04 /* Shift register full/empty */ 77 - #define CB1_INT 0x10 /* transition on CB1 input */ 78 - 79 - static enum pmu_state { 80 - idle, 81 - sending, 82 - intack, 83 - reading, 84 - reading_intr, 85 - } pmu_state; 86 - 87 - static struct adb_request *current_req; 88 - static struct adb_request *last_req; 89 - static struct adb_request *req_awaiting_reply; 90 - static unsigned char interrupt_data[32]; 91 - static unsigned char *reply_ptr; 92 - static int data_index; 93 - static int data_len; 94 - static int adb_int_pending; 95 - static int pmu_adb_flags; 96 - static int adb_dev_map; 97 - static struct adb_request bright_req_1, bright_req_2, bright_req_3; 98 - static int pmu_kind = PMU_UNKNOWN; 99 - static int pmu_fully_inited; 100 - 101 - int asleep; 102 - 103 - static int pmu_probe(void); 104 - static int pmu_init(void); 105 - static void pmu_start(void); 106 - static irqreturn_t pmu_interrupt(int irq, void *arg); 107 - static int pmu_send_request(struct adb_request *req, int sync); 108 - static int pmu_autopoll(int devs); 109 - void pmu_poll(void); 110 - static int pmu_reset_bus(void); 111 - 112 - static int init_pmu(void); 113 - static void pmu_start(void); 114 - static void send_byte(int x); 115 - static void recv_byte(void); 116 - static void pmu_done(struct adb_request *req); 117 - static void pmu_handle_data(unsigned char *data, int len); 118 - static void set_volume(int level); 119 - static void pmu_enable_backlight(int on); 120 - static void pmu_set_brightness(int level); 121 - 122 - struct adb_driver via_pmu_driver = { 123 - .name = "68K PMU", 124 - .probe = pmu_probe, 125 - .init = pmu_init, 126 - .send_request = pmu_send_request, 127 - .autopoll = pmu_autopoll, 128 - .poll = pmu_poll, 129 - .reset_bus = pmu_reset_bus, 130 - }; 131 - 132 - /* 133 - * This table indicates for each PMU opcode: 134 - * - the number of data bytes to be sent with the command, or -1 135 - * if a length byte should be sent, 136 - * - the number of response bytes which the PMU will return, or 137 - * -1 if it will send a length byte. 138 - */ 139 - static s8 pmu_data_len[256][2] = { 140 - /* 0 1 2 3 4 5 6 7 */ 141 - /*00*/ {-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0}, 142 - /*08*/ {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1}, 143 - /*10*/ { 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0}, 144 - /*18*/ { 0, 1},{ 0, 1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{ 0, 0}, 145 - /*20*/ {-1, 0},{ 0, 0},{ 2, 0},{ 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0}, 146 - /*28*/ { 0,-1},{ 0,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{ 0,-1}, 147 - /*30*/ { 4, 0},{20, 0},{-1, 0},{ 3, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0}, 148 - /*38*/ { 0, 4},{ 0,20},{ 2,-1},{ 2, 1},{ 3,-1},{-1,-1},{-1,-1},{ 4, 0}, 149 - /*40*/ { 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0}, 150 - /*48*/ { 0, 1},{ 0, 1},{-1,-1},{ 1, 0},{ 1, 0},{-1,-1},{-1,-1},{-1,-1}, 151 - /*50*/ { 1, 0},{ 0, 0},{ 2, 0},{ 2, 0},{-1, 0},{ 1, 0},{ 3, 0},{ 1, 0}, 152 - /*58*/ { 0, 1},{ 1, 0},{ 0, 2},{ 0, 2},{ 0,-1},{-1,-1},{-1,-1},{-1,-1}, 153 - /*60*/ { 2, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0}, 154 - /*68*/ { 0, 3},{ 0, 3},{ 0, 2},{ 0, 8},{ 0,-1},{ 0,-1},{-1,-1},{-1,-1}, 155 - /*70*/ { 1, 0},{ 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0}, 156 - /*78*/ { 0,-1},{ 0,-1},{-1,-1},{-1,-1},{-1,-1},{ 5, 1},{ 4, 1},{ 4, 1}, 157 - /*80*/ { 4, 0},{-1, 0},{ 0, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0}, 158 - /*88*/ { 0, 5},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1}, 159 - /*90*/ { 1, 0},{ 2, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0}, 160 - /*98*/ { 0, 1},{ 0, 1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1}, 161 - /*a0*/ { 2, 0},{ 2, 0},{ 2, 0},{ 4, 0},{-1, 0},{ 0, 0},{-1, 0},{-1, 0}, 162 - /*a8*/ { 1, 1},{ 1, 0},{ 3, 0},{ 2, 0},{-1,-1},{-1,-1},{-1,-1},{-1,-1}, 163 - /*b0*/ {-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0}, 164 - /*b8*/ {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1}, 165 - /*c0*/ {-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0}, 166 - /*c8*/ {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1}, 167 - /*d0*/ { 0, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0}, 168 - /*d8*/ { 1, 1},{ 1, 1},{-1,-1},{-1,-1},{ 0, 1},{ 0,-1},{-1,-1},{-1,-1}, 169 - /*e0*/ {-1, 0},{ 4, 0},{ 0, 1},{-1, 0},{-1, 0},{ 4, 0},{-1, 0},{-1, 0}, 170 - /*e8*/ { 3,-1},{-1,-1},{ 0, 1},{-1,-1},{ 0,-1},{-1,-1},{-1,-1},{ 0, 0}, 171 - /*f0*/ {-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0}, 172 - /*f8*/ {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1}, 173 - }; 174 - 175 - int __init find_via_pmu(void) 176 - { 177 - switch (macintosh_config->adb_type) { 178 - case MAC_ADB_PB2: 179 - pmu_kind = PMU_68K_V2; 180 - break; 181 - default: 182 - pmu_kind = PMU_UNKNOWN; 183 - return -ENODEV; 184 - } 185 - 186 - pmu_state = idle; 187 - 188 - if (!init_pmu()) 189 - goto fail_init; 190 - 191 - pr_info("adb: PMU 68K driver v0.5 for Unified ADB\n"); 192 - 193 - return 1; 194 - 195 - fail_init: 196 - pmu_kind = PMU_UNKNOWN; 197 - return 0; 198 - } 199 - 200 - static int pmu_probe(void) 201 - { 202 - if (pmu_kind == PMU_UNKNOWN) 203 - return -ENODEV; 204 - return 0; 205 - } 206 - 207 - static int pmu_init(void) 208 - { 209 - if (pmu_kind == PMU_UNKNOWN) 210 - return -ENODEV; 211 - return 0; 212 - } 213 - 214 - static int __init via_pmu_start(void) 215 - { 216 - if (pmu_kind == PMU_UNKNOWN) 217 - return -ENODEV; 218 - 219 - if (request_irq(IRQ_MAC_ADB_SR, pmu_interrupt, 0, "PMU_SR", 220 - pmu_interrupt)) { 221 - pr_err("%s: can't get SR irq\n", __func__); 222 - return -ENODEV; 223 - } 224 - if (request_irq(IRQ_MAC_ADB_CL, pmu_interrupt, 0, "PMU_CL", 225 - pmu_interrupt)) { 226 - pr_err("%s: can't get CL irq\n", __func__); 227 - free_irq(IRQ_MAC_ADB_SR, pmu_interrupt); 228 - return -ENODEV; 229 - } 230 - 231 - pmu_fully_inited = 1; 232 - 233 - /* Enable backlight */ 234 - pmu_enable_backlight(1); 235 - 236 - return 0; 237 - } 238 - 239 - arch_initcall(via_pmu_start); 240 - 241 - static int __init init_pmu(void) 242 - { 243 - int timeout; 244 - volatile struct adb_request req; 245 - 246 - via2[B] |= TREQ; /* negate TREQ */ 247 - via2[DIRB] = (via2[DIRB] | TREQ) & ~TACK; /* TACK in, TREQ out */ 248 - 249 - pmu_request((struct adb_request *) &req, NULL, 2, PMU_SET_INTR_MASK, PMU_INT_ADB); 250 - timeout = 100000; 251 - while (!req.complete) { 252 - if (--timeout < 0) { 253 - printk(KERN_ERR "pmu_init: no response from PMU\n"); 254 - return -EAGAIN; 255 - } 256 - udelay(10); 257 - pmu_poll(); 258 - } 259 - 260 - /* ack all pending interrupts */ 261 - timeout = 100000; 262 - interrupt_data[0] = 1; 263 - while (interrupt_data[0] || pmu_state != idle) { 264 - if (--timeout < 0) { 265 - printk(KERN_ERR "pmu_init: timed out acking intrs\n"); 266 - return -EAGAIN; 267 - } 268 - if (pmu_state == idle) { 269 - adb_int_pending = 1; 270 - pmu_interrupt(0, NULL); 271 - } 272 - pmu_poll(); 273 - udelay(10); 274 - } 275 - 276 - pmu_request((struct adb_request *) &req, NULL, 2, PMU_SET_INTR_MASK, 277 - PMU_INT_ADB_AUTO|PMU_INT_SNDBRT|PMU_INT_ADB); 278 - timeout = 100000; 279 - while (!req.complete) { 280 - if (--timeout < 0) { 281 - printk(KERN_ERR "pmu_init: no response from PMU\n"); 282 - return -EAGAIN; 283 - } 284 - udelay(10); 285 - pmu_poll(); 286 - } 287 - 288 - bright_req_1.complete = 1; 289 - bright_req_2.complete = 1; 290 - bright_req_3.complete = 1; 291 - 292 - return 1; 293 - } 294 - 295 - int 296 - pmu_get_model(void) 297 - { 298 - return pmu_kind; 299 - } 300 - 301 - /* Send an ADB command */ 302 - static int 303 - pmu_send_request(struct adb_request *req, int sync) 304 - { 305 - int i, ret; 306 - 307 - if (!pmu_fully_inited) 308 - { 309 - req->complete = 1; 310 - return -ENXIO; 311 - } 312 - 313 - ret = -EINVAL; 314 - 315 - switch (req->data[0]) { 316 - case PMU_PACKET: 317 - for (i = 0; i < req->nbytes - 1; ++i) 318 - req->data[i] = req->data[i+1]; 319 - --req->nbytes; 320 - if (pmu_data_len[req->data[0]][1] != 0) { 321 - req->reply[0] = ADB_RET_OK; 322 - req->reply_len = 1; 323 - } else 324 - req->reply_len = 0; 325 - ret = pmu_queue_request(req); 326 - break; 327 - case CUDA_PACKET: 328 - switch (req->data[1]) { 329 - case CUDA_GET_TIME: 330 - if (req->nbytes != 2) 331 - break; 332 - req->data[0] = PMU_READ_RTC; 333 - req->nbytes = 1; 334 - req->reply_len = 3; 335 - req->reply[0] = CUDA_PACKET; 336 - req->reply[1] = 0; 337 - req->reply[2] = CUDA_GET_TIME; 338 - ret = pmu_queue_request(req); 339 - break; 340 - case CUDA_SET_TIME: 341 - if (req->nbytes != 6) 342 - break; 343 - req->data[0] = PMU_SET_RTC; 344 - req->nbytes = 5; 345 - for (i = 1; i <= 4; ++i) 346 - req->data[i] = req->data[i+1]; 347 - req->reply_len = 3; 348 - req->reply[0] = CUDA_PACKET; 349 - req->reply[1] = 0; 350 - req->reply[2] = CUDA_SET_TIME; 351 - ret = pmu_queue_request(req); 352 - break; 353 - case CUDA_GET_PRAM: 354 - if (req->nbytes != 4) 355 - break; 356 - req->data[0] = PMU_READ_NVRAM; 357 - req->data[1] = req->data[2]; 358 - req->data[2] = req->data[3]; 359 - req->nbytes = 3; 360 - req->reply_len = 3; 361 - req->reply[0] = CUDA_PACKET; 362 - req->reply[1] = 0; 363 - req->reply[2] = CUDA_GET_PRAM; 364 - ret = pmu_queue_request(req); 365 - break; 366 - case CUDA_SET_PRAM: 367 - if (req->nbytes != 5) 368 - break; 369 - req->data[0] = PMU_WRITE_NVRAM; 370 - req->data[1] = req->data[2]; 371 - req->data[2] = req->data[3]; 372 - req->data[3] = req->data[4]; 373 - req->nbytes = 4; 374 - req->reply_len = 3; 375 - req->reply[0] = CUDA_PACKET; 376 - req->reply[1] = 0; 377 - req->reply[2] = CUDA_SET_PRAM; 378 - ret = pmu_queue_request(req); 379 - break; 380 - } 381 - break; 382 - case ADB_PACKET: 383 - for (i = req->nbytes - 1; i > 1; --i) 384 - req->data[i+2] = req->data[i]; 385 - req->data[3] = req->nbytes - 2; 386 - req->data[2] = pmu_adb_flags; 387 - /*req->data[1] = req->data[1];*/ 388 - req->data[0] = PMU_ADB_CMD; 389 - req->nbytes += 2; 390 - req->reply_expected = 1; 391 - req->reply_len = 0; 392 - ret = pmu_queue_request(req); 393 - break; 394 - } 395 - if (ret) 396 - { 397 - req->complete = 1; 398 - return ret; 399 - } 400 - 401 - if (sync) { 402 - while (!req->complete) 403 - pmu_poll(); 404 - } 405 - 406 - return 0; 407 - } 408 - 409 - /* Enable/disable autopolling */ 410 - static int 411 - pmu_autopoll(int devs) 412 - { 413 - struct adb_request req; 414 - 415 - if (!pmu_fully_inited) return -ENXIO; 416 - 417 - if (devs) { 418 - adb_dev_map = devs; 419 - pmu_request(&req, NULL, 5, PMU_ADB_CMD, 0, 0x86, 420 - adb_dev_map >> 8, adb_dev_map); 421 - pmu_adb_flags = 2; 422 - } else { 423 - pmu_request(&req, NULL, 1, PMU_ADB_POLL_OFF); 424 - pmu_adb_flags = 0; 425 - } 426 - while (!req.complete) 427 - pmu_poll(); 428 - return 0; 429 - } 430 - 431 - /* Reset the ADB bus */ 432 - static int 433 - pmu_reset_bus(void) 434 - { 435 - struct adb_request req; 436 - long timeout; 437 - int save_autopoll = adb_dev_map; 438 - 439 - if (!pmu_fully_inited) return -ENXIO; 440 - 441 - /* anyone got a better idea?? */ 442 - pmu_autopoll(0); 443 - 444 - req.nbytes = 5; 445 - req.done = NULL; 446 - req.data[0] = PMU_ADB_CMD; 447 - req.data[1] = 0; 448 - req.data[2] = 3; /* ADB_BUSRESET ??? */ 449 - req.data[3] = 0; 450 - req.data[4] = 0; 451 - req.reply_len = 0; 452 - req.reply_expected = 1; 453 - if (pmu_queue_request(&req) != 0) 454 - { 455 - printk(KERN_ERR "pmu_adb_reset_bus: pmu_queue_request failed\n"); 456 - return -EIO; 457 - } 458 - while (!req.complete) 459 - pmu_poll(); 460 - timeout = 100000; 461 - while (!req.complete) { 462 - if (--timeout < 0) { 463 - printk(KERN_ERR "pmu_adb_reset_bus (reset): no response from PMU\n"); 464 - return -EIO; 465 - } 466 - udelay(10); 467 - pmu_poll(); 468 - } 469 - 470 - if (save_autopoll != 0) 471 - pmu_autopoll(save_autopoll); 472 - 473 - return 0; 474 - } 475 - 476 - /* Construct and send a pmu request */ 477 - int 478 - pmu_request(struct adb_request *req, void (*done)(struct adb_request *), 479 - int nbytes, ...) 480 - { 481 - va_list list; 482 - int i; 483 - 484 - if (nbytes < 0 || nbytes > 32) { 485 - printk(KERN_ERR "pmu_request: bad nbytes (%d)\n", nbytes); 486 - req->complete = 1; 487 - return -EINVAL; 488 - } 489 - req->nbytes = nbytes; 490 - req->done = done; 491 - va_start(list, nbytes); 492 - for (i = 0; i < nbytes; ++i) 493 - req->data[i] = va_arg(list, int); 494 - va_end(list); 495 - if (pmu_data_len[req->data[0]][1] != 0) { 496 - req->reply[0] = ADB_RET_OK; 497 - req->reply_len = 1; 498 - } else 499 - req->reply_len = 0; 500 - req->reply_expected = 0; 501 - return pmu_queue_request(req); 502 - } 503 - 504 - int 505 - pmu_queue_request(struct adb_request *req) 506 - { 507 - unsigned long flags; 508 - int nsend; 509 - 510 - if (req->nbytes <= 0) { 511 - req->complete = 1; 512 - return 0; 513 - } 514 - nsend = pmu_data_len[req->data[0]][0]; 515 - if (nsend >= 0 && req->nbytes != nsend + 1) { 516 - req->complete = 1; 517 - return -EINVAL; 518 - } 519 - 520 - req->next = NULL; 521 - req->sent = 0; 522 - req->complete = 0; 523 - local_irq_save(flags); 524 - 525 - if (current_req != 0) { 526 - last_req->next = req; 527 - last_req = req; 528 - } else { 529 - current_req = req; 530 - last_req = req; 531 - if (pmu_state == idle) 532 - pmu_start(); 533 - } 534 - 535 - local_irq_restore(flags); 536 - return 0; 537 - } 538 - 539 - static void 540 - send_byte(int x) 541 - { 542 - via1[ACR] |= SR_CTRL; 543 - via1[SR] = x; 544 - via2[B] &= ~TREQ; /* assert TREQ */ 545 - } 546 - 547 - static void 548 - recv_byte(void) 549 - { 550 - char c; 551 - 552 - via1[ACR] = (via1[ACR] | SR_EXT) & ~SR_OUT; 553 - c = via1[SR]; /* resets SR */ 554 - via2[B] &= ~TREQ; 555 - } 556 - 557 - static void 558 - pmu_start(void) 559 - { 560 - unsigned long flags; 561 - struct adb_request *req; 562 - 563 - /* assert pmu_state == idle */ 564 - /* get the packet to send */ 565 - local_irq_save(flags); 566 - req = current_req; 567 - if (req == 0 || pmu_state != idle 568 - || (req->reply_expected && req_awaiting_reply)) 569 - goto out; 570 - 571 - pmu_state = sending; 572 - data_index = 1; 573 - data_len = pmu_data_len[req->data[0]][0]; 574 - 575 - /* set the shift register to shift out and send a byte */ 576 - send_byte(req->data[0]); 577 - 578 - out: 579 - local_irq_restore(flags); 580 - } 581 - 582 - void 583 - pmu_poll(void) 584 - { 585 - unsigned long flags; 586 - 587 - local_irq_save(flags); 588 - if (via1[IFR] & SR_INT) { 589 - via1[IFR] = SR_INT; 590 - pmu_interrupt(IRQ_MAC_ADB_SR, NULL); 591 - } 592 - if (via1[IFR] & CB1_INT) { 593 - via1[IFR] = CB1_INT; 594 - pmu_interrupt(IRQ_MAC_ADB_CL, NULL); 595 - } 596 - local_irq_restore(flags); 597 - } 598 - 599 - static irqreturn_t 600 - pmu_interrupt(int irq, void *dev_id) 601 - { 602 - struct adb_request *req; 603 - int timeout, bite = 0; /* to prevent compiler warning */ 604 - 605 - #if 0 606 - printk("pmu_interrupt: irq %d state %d acr %02X, b %02X data_index %d/%d adb_int_pending %d\n", 607 - irq, pmu_state, (uint) via1[ACR], (uint) via2[B], data_index, data_len, adb_int_pending); 608 - #endif 609 - 610 - if (irq == IRQ_MAC_ADB_CL) { /* CB1 interrupt */ 611 - adb_int_pending = 1; 612 - } else if (irq == IRQ_MAC_ADB_SR) { /* SR interrupt */ 613 - if (via2[B] & TACK) { 614 - printk(KERN_DEBUG "PMU: SR_INT but ack still high! (%x)\n", via2[B]); 615 - } 616 - 617 - /* if reading grab the byte */ 618 - if ((via1[ACR] & SR_OUT) == 0) bite = via1[SR]; 619 - 620 - /* reset TREQ and wait for TACK to go high */ 621 - via2[B] |= TREQ; 622 - timeout = 3200; 623 - while (!(via2[B] & TACK)) { 624 - if (--timeout < 0) { 625 - printk(KERN_ERR "PMU not responding (!ack)\n"); 626 - goto finish; 627 - } 628 - udelay(10); 629 - } 630 - 631 - switch (pmu_state) { 632 - case sending: 633 - req = current_req; 634 - if (data_len < 0) { 635 - data_len = req->nbytes - 1; 636 - send_byte(data_len); 637 - break; 638 - } 639 - if (data_index <= data_len) { 640 - send_byte(req->data[data_index++]); 641 - break; 642 - } 643 - req->sent = 1; 644 - data_len = pmu_data_len[req->data[0]][1]; 645 - if (data_len == 0) { 646 - pmu_state = idle; 647 - current_req = req->next; 648 - if (req->reply_expected) 649 - req_awaiting_reply = req; 650 - else 651 - pmu_done(req); 652 - } else { 653 - pmu_state = reading; 654 - data_index = 0; 655 - reply_ptr = req->reply + req->reply_len; 656 - recv_byte(); 657 - } 658 - break; 659 - 660 - case intack: 661 - data_index = 0; 662 - data_len = -1; 663 - pmu_state = reading_intr; 664 - reply_ptr = interrupt_data; 665 - recv_byte(); 666 - break; 667 - 668 - case reading: 669 - case reading_intr: 670 - if (data_len == -1) { 671 - data_len = bite; 672 - if (bite > 32) 673 - printk(KERN_ERR "PMU: bad reply len %d\n", 674 - bite); 675 - } else { 676 - reply_ptr[data_index++] = bite; 677 - } 678 - if (data_index < data_len) { 679 - recv_byte(); 680 - break; 681 - } 682 - 683 - if (pmu_state == reading_intr) { 684 - pmu_handle_data(interrupt_data, data_index); 685 - } else { 686 - req = current_req; 687 - current_req = req->next; 688 - req->reply_len += data_index; 689 - pmu_done(req); 690 - } 691 - pmu_state = idle; 692 - 693 - break; 694 - 695 - default: 696 - printk(KERN_ERR "pmu_interrupt: unknown state %d?\n", 697 - pmu_state); 698 - } 699 - } 700 - finish: 701 - if (pmu_state == idle) { 702 - if (adb_int_pending) { 703 - pmu_state = intack; 704 - send_byte(PMU_INT_ACK); 705 - adb_int_pending = 0; 706 - } else if (current_req) { 707 - pmu_start(); 708 - } 709 - } 710 - 711 - #if 0 712 - printk("pmu_interrupt: exit state %d acr %02X, b %02X data_index %d/%d adb_int_pending %d\n", 713 - pmu_state, (uint) via1[ACR], (uint) via2[B], data_index, data_len, adb_int_pending); 714 - #endif 715 - return IRQ_HANDLED; 716 - } 717 - 718 - static void 719 - pmu_done(struct adb_request *req) 720 - { 721 - req->complete = 1; 722 - if (req->done) 723 - (*req->done)(req); 724 - } 725 - 726 - /* Interrupt data could be the result data from an ADB cmd */ 727 - static void 728 - pmu_handle_data(unsigned char *data, int len) 729 - { 730 - static int show_pmu_ints = 1; 731 - 732 - asleep = 0; 733 - if (len < 1) { 734 - adb_int_pending = 0; 735 - return; 736 - } 737 - if (data[0] & PMU_INT_ADB) { 738 - if ((data[0] & PMU_INT_ADB_AUTO) == 0) { 739 - struct adb_request *req = req_awaiting_reply; 740 - if (req == 0) { 741 - printk(KERN_ERR "PMU: extra ADB reply\n"); 742 - return; 743 - } 744 - req_awaiting_reply = NULL; 745 - if (len <= 2) 746 - req->reply_len = 0; 747 - else { 748 - memcpy(req->reply, data + 1, len - 1); 749 - req->reply_len = len - 1; 750 - } 751 - pmu_done(req); 752 - } else { 753 - adb_input(data+1, len-1, 1); 754 - } 755 - } else { 756 - if (data[0] == 0x08 && len == 3) { 757 - /* sound/brightness buttons pressed */ 758 - pmu_set_brightness(data[1] >> 3); 759 - set_volume(data[2]); 760 - } else if (show_pmu_ints 761 - && !(data[0] == PMU_INT_TICK && len == 1)) { 762 - int i; 763 - printk(KERN_DEBUG "pmu intr"); 764 - for (i = 0; i < len; ++i) 765 - printk(" %.2x", data[i]); 766 - printk("\n"); 767 - } 768 - } 769 - } 770 - 771 - static int backlight_level = -1; 772 - static int backlight_enabled = 0; 773 - 774 - #define LEVEL_TO_BRIGHT(lev) ((lev) < 1? 0x7f: 0x4a - ((lev) << 1)) 775 - 776 - static void 777 - pmu_enable_backlight(int on) 778 - { 779 - struct adb_request req; 780 - 781 - if (on) { 782 - /* first call: get current backlight value */ 783 - if (backlight_level < 0) { 784 - switch(pmu_kind) { 785 - case PMU_68K_V2: 786 - pmu_request(&req, NULL, 3, PMU_READ_NVRAM, 0x14, 0xe); 787 - while (!req.complete) 788 - pmu_poll(); 789 - printk(KERN_DEBUG "pmu: nvram returned bright: %d\n", (int)req.reply[1]); 790 - backlight_level = req.reply[1]; 791 - break; 792 - default: 793 - backlight_enabled = 0; 794 - return; 795 - } 796 - } 797 - pmu_request(&req, NULL, 2, PMU_BACKLIGHT_BRIGHT, 798 - LEVEL_TO_BRIGHT(backlight_level)); 799 - while (!req.complete) 800 - pmu_poll(); 801 - } 802 - pmu_request(&req, NULL, 2, PMU_POWER_CTRL, 803 - PMU_POW_BACKLIGHT | (on ? PMU_POW_ON : PMU_POW_OFF)); 804 - while (!req.complete) 805 - pmu_poll(); 806 - backlight_enabled = on; 807 - } 808 - 809 - static void 810 - pmu_set_brightness(int level) 811 - { 812 - int bright; 813 - 814 - backlight_level = level; 815 - bright = LEVEL_TO_BRIGHT(level); 816 - if (!backlight_enabled) 817 - return; 818 - if (bright_req_1.complete) 819 - pmu_request(&bright_req_1, NULL, 2, PMU_BACKLIGHT_BRIGHT, 820 - bright); 821 - if (bright_req_2.complete) 822 - pmu_request(&bright_req_2, NULL, 2, PMU_POWER_CTRL, 823 - PMU_POW_BACKLIGHT | (bright < 0x7f ? PMU_POW_ON : PMU_POW_OFF)); 824 - } 825 - 826 - void 827 - pmu_enable_irled(int on) 828 - { 829 - struct adb_request req; 830 - 831 - pmu_request(&req, NULL, 2, PMU_POWER_CTRL, PMU_POW_IRLED | 832 - (on ? PMU_POW_ON : PMU_POW_OFF)); 833 - while (!req.complete) 834 - pmu_poll(); 835 - } 836 - 837 - static void 838 - set_volume(int level) 839 - { 840 - } 841 - 842 - int 843 - pmu_present(void) 844 - { 845 - return (pmu_kind != PMU_UNKNOWN); 846 - }
+1 -1
include/uapi/linux/pmu.h
··· 94 94 PMU_PADDINGTON_BASED, /* 1999 PowerBook G3 */ 95 95 PMU_KEYLARGO_BASED, /* Core99 motherboard (PMU99) */ 96 96 PMU_68K_V1, /* Unused/deprecated */ 97 - PMU_68K_V2, /* 68K PMU, version 2 */ 97 + PMU_68K_V2, /* Unused/deprecated */ 98 98 }; 99 99 100 100 /* PMU PMU_POWER_EVENTS commands */