via-pmu.c (3d5271f9883cba7b54762bc4fe027d4172f06db7) via-pmu.c (51d3082fe6e55aecfa17113dbe98077c749f724c)
1/*
2 * Device driver for the via-pmu on Apple Powermacs.
3 *
4 * The VIA (versatile interface adapter) interfaces to the PMU,
5 * a 6805 microprocessor core whose primary function is to control
6 * battery charging and system power on the PowerBook 3400 and 2400.
7 * The PMU also controls the ADB (Apple Desktop Bus) which connects
8 * to the keyboard and mouse, as well as the non-volatile RAM

--- 133 unchanged lines hidden (view full) ---

142static int data_len;
143static volatile int adb_int_pending;
144static volatile int disable_poll;
145static struct adb_request bright_req_1, bright_req_2;
146static struct device_node *vias;
147static int pmu_kind = PMU_UNKNOWN;
148static int pmu_fully_inited = 0;
149static int pmu_has_adb;
1/*
2 * Device driver for the via-pmu on Apple Powermacs.
3 *
4 * The VIA (versatile interface adapter) interfaces to the PMU,
5 * a 6805 microprocessor core whose primary function is to control
6 * battery charging and system power on the PowerBook 3400 and 2400.
7 * The PMU also controls the ADB (Apple Desktop Bus) which connects
8 * to the keyboard and mouse, as well as the non-volatile RAM

--- 133 unchanged lines hidden (view full) ---

142static int data_len;
143static volatile int adb_int_pending;
144static volatile int disable_poll;
145static struct adb_request bright_req_1, bright_req_2;
146static struct device_node *vias;
147static int pmu_kind = PMU_UNKNOWN;
148static int pmu_fully_inited = 0;
149static int pmu_has_adb;
150static struct device_node *gpio_node;
150static unsigned char __iomem *gpio_reg = NULL;
151static int gpio_irq = -1;
152static int gpio_irq_enabled = -1;
153static volatile int pmu_suspended = 0;
154static spinlock_t pmu_lock;
155static u8 pmu_intr_mask;
156static int pmu_version;
157static int drop_interrupts;

--- 132 unchanged lines hidden (view full) ---

290
291#ifdef CONFIG_PMAC_BACKLIGHT
292static struct backlight_controller pmu_backlight_controller = {
293 pmu_set_backlight_enable,
294 pmu_set_backlight_level
295};
296#endif /* CONFIG_PMAC_BACKLIGHT */
297
151static unsigned char __iomem *gpio_reg = NULL;
152static int gpio_irq = -1;
153static int gpio_irq_enabled = -1;
154static volatile int pmu_suspended = 0;
155static spinlock_t pmu_lock;
156static u8 pmu_intr_mask;
157static int pmu_version;
158static int drop_interrupts;

--- 132 unchanged lines hidden (view full) ---

291
292#ifdef CONFIG_PMAC_BACKLIGHT
293static struct backlight_controller pmu_backlight_controller = {
294 pmu_set_backlight_enable,
295 pmu_set_backlight_level
296};
297#endif /* CONFIG_PMAC_BACKLIGHT */
298
298int
299find_via_pmu(void)
299int __init find_via_pmu(void)
300{
300{
301 phys_addr_t taddr;
302 u32 *reg;
303
301 if (via != 0)
302 return 1;
304 if (via != 0)
305 return 1;
303 vias = find_devices("via-pmu");
304 if (vias == 0)
306 vias = of_find_node_by_name(NULL, "via-pmu");
307 if (vias == NULL)
305 return 0;
308 return 0;
306 if (vias->next != 0)
307 printk(KERN_WARNING "Warning: only using 1st via-pmu\n");
308
309
309 if (vias->n_addrs < 1 || vias->n_intrs < 1) {
310 printk(KERN_ERR "via-pmu: %d addresses, %d interrupts!\n",
311 vias->n_addrs, vias->n_intrs);
312 if (vias->n_addrs < 1 || vias->n_intrs < 1)
313 return 0;
310 reg = (u32 *)get_property(vias, "reg", NULL);
311 if (reg == NULL) {
312 printk(KERN_ERR "via-pmu: No \"reg\" property !\n");
313 goto fail;
314 }
314 }
315 taddr = of_translate_address(vias, reg);
316 if (taddr == 0) {
317 printk(KERN_ERR "via-pmu: Can't translate address !\n");
318 goto fail;
319 }
315
316 spin_lock_init(&pmu_lock);
317
318 pmu_has_adb = 1;
319
320 pmu_intr_mask = PMU_INT_PCEJECT |
321 PMU_INT_SNDBRT |
322 PMU_INT_ADB |
323 PMU_INT_TICK;
324
325 if (vias->parent->name && ((strcmp(vias->parent->name, "ohare") == 0)
326 || device_is_compatible(vias->parent, "ohare")))
327 pmu_kind = PMU_OHARE_BASED;
328 else if (device_is_compatible(vias->parent, "paddington"))
329 pmu_kind = PMU_PADDINGTON_BASED;
330 else if (device_is_compatible(vias->parent, "heathrow"))
331 pmu_kind = PMU_HEATHROW_BASED;
332 else if (device_is_compatible(vias->parent, "Keylargo")
333 || device_is_compatible(vias->parent, "K2-Keylargo")) {
320
321 spin_lock_init(&pmu_lock);
322
323 pmu_has_adb = 1;
324
325 pmu_intr_mask = PMU_INT_PCEJECT |
326 PMU_INT_SNDBRT |
327 PMU_INT_ADB |
328 PMU_INT_TICK;
329
330 if (vias->parent->name && ((strcmp(vias->parent->name, "ohare") == 0)
331 || device_is_compatible(vias->parent, "ohare")))
332 pmu_kind = PMU_OHARE_BASED;
333 else if (device_is_compatible(vias->parent, "paddington"))
334 pmu_kind = PMU_PADDINGTON_BASED;
335 else if (device_is_compatible(vias->parent, "heathrow"))
336 pmu_kind = PMU_HEATHROW_BASED;
337 else if (device_is_compatible(vias->parent, "Keylargo")
338 || device_is_compatible(vias->parent, "K2-Keylargo")) {
334 struct device_node *gpio, *gpiop;
339 struct device_node *gpiop;
340 phys_addr_t gaddr = 0;
335
336 pmu_kind = PMU_KEYLARGO_BASED;
337 pmu_has_adb = (find_type_devices("adb") != NULL);
338 pmu_intr_mask = PMU_INT_PCEJECT |
339 PMU_INT_SNDBRT |
340 PMU_INT_ADB |
341 PMU_INT_TICK |
342 PMU_INT_ENVIRONMENT;
343
341
342 pmu_kind = PMU_KEYLARGO_BASED;
343 pmu_has_adb = (find_type_devices("adb") != NULL);
344 pmu_intr_mask = PMU_INT_PCEJECT |
345 PMU_INT_SNDBRT |
346 PMU_INT_ADB |
347 PMU_INT_TICK |
348 PMU_INT_ENVIRONMENT;
349
344 gpiop = find_devices("gpio");
345 if (gpiop && gpiop->n_addrs) {
346 gpio_reg = ioremap(gpiop->addrs->address, 0x10);
347 gpio = find_devices("extint-gpio1");
348 if (gpio == NULL)
349 gpio = find_devices("pmu-interrupt");
350 if (gpio && gpio->parent == gpiop && gpio->n_intrs)
351 gpio_irq = gpio->intrs[0].line;
350 gpiop = of_find_node_by_name(NULL, "gpio");
351 if (gpiop) {
352 reg = (u32 *)get_property(gpiop, "reg", NULL);
353 if (reg)
354 gaddr = of_translate_address(gpiop, reg);
355 if (gaddr != 0)
356 gpio_reg = ioremap(gaddr, 0x10);
352 }
357 }
358 if (gpio_reg == NULL)
359 printk(KERN_ERR "via-pmu: Can't find GPIO reg !\n");
353 } else
354 pmu_kind = PMU_UNKNOWN;
355
360 } else
361 pmu_kind = PMU_UNKNOWN;
362
356 via = ioremap(vias->addrs->address, 0x2000);
363 via = ioremap(taddr, 0x2000);
364 if (via == NULL) {
365 printk(KERN_ERR "via-pmu: Can't map address !\n");
366 goto fail;
367 }
357
358 out_8(&via[IER], IER_CLR | 0x7f); /* disable all intrs */
359 out_8(&via[IFR], 0x7f); /* clear IFR */
360
361 pmu_state = idle;
362
363 if (!init_pmu()) {
364 via = NULL;
365 return 0;
366 }
367
368 printk(KERN_INFO "PMU driver %d initialized for %s, firmware: %02x\n",
369 PMU_DRIVER_VERSION, pbook_type[pmu_kind], pmu_version);
370
371 sys_ctrler = SYS_CTRLER_PMU;
372
373 return 1;
368
369 out_8(&via[IER], IER_CLR | 0x7f); /* disable all intrs */
370 out_8(&via[IFR], 0x7f); /* clear IFR */
371
372 pmu_state = idle;
373
374 if (!init_pmu()) {
375 via = NULL;
376 return 0;
377 }
378
379 printk(KERN_INFO "PMU driver %d initialized for %s, firmware: %02x\n",
380 PMU_DRIVER_VERSION, pbook_type[pmu_kind], pmu_version);
381
382 sys_ctrler = SYS_CTRLER_PMU;
383
384 return 1;
385 fail:
386 of_node_put(vias);
387 vias = NULL;
388 return 0;
374}
375
376#ifdef CONFIG_ADB
389}
390
391#ifdef CONFIG_ADB
377static int
378pmu_probe(void)
392static int pmu_probe(void)
379{
380 return vias == NULL? -ENODEV: 0;
381}
382
393{
394 return vias == NULL? -ENODEV: 0;
395}
396
383static int __init
384pmu_init(void)
397static int __init pmu_init(void)
385{
386 if (vias == NULL)
387 return -ENODEV;
388 return 0;
389}
390#endif /* CONFIG_ADB */
391
392/*

--- 7 unchanged lines hidden (view full) ---

400{
401 if (vias == NULL)
402 return -ENODEV;
403
404 bright_req_1.complete = 1;
405 bright_req_2.complete = 1;
406 batt_req.complete = 1;
407
398{
399 if (vias == NULL)
400 return -ENODEV;
401 return 0;
402}
403#endif /* CONFIG_ADB */
404
405/*

--- 7 unchanged lines hidden (view full) ---

413{
414 if (vias == NULL)
415 return -ENODEV;
416
417 bright_req_1.complete = 1;
418 bright_req_2.complete = 1;
419 batt_req.complete = 1;
420
408#if defined(CONFIG_PPC32) && !defined(CONFIG_PPC_MERGE)
421#ifndef CONFIG_PPC_MERGE
409 if (pmu_kind == PMU_KEYLARGO_BASED)
410 openpic_set_irq_priority(vias->intrs[0].line,
411 OPENPIC_PRIORITY_DEFAULT + 1);
412#endif
413
414 if (request_irq(vias->intrs[0].line, via_pmu_interrupt, 0, "VIA-PMU",
415 (void *)0)) {
416 printk(KERN_ERR "VIA-PMU: can't get irq %d\n",
417 vias->intrs[0].line);
418 return -EAGAIN;
419 }
420
422 if (pmu_kind == PMU_KEYLARGO_BASED)
423 openpic_set_irq_priority(vias->intrs[0].line,
424 OPENPIC_PRIORITY_DEFAULT + 1);
425#endif
426
427 if (request_irq(vias->intrs[0].line, via_pmu_interrupt, 0, "VIA-PMU",
428 (void *)0)) {
429 printk(KERN_ERR "VIA-PMU: can't get irq %d\n",
430 vias->intrs[0].line);
431 return -EAGAIN;
432 }
433
421 if (pmu_kind == PMU_KEYLARGO_BASED && gpio_irq != -1) {
422 if (request_irq(gpio_irq, gpio1_interrupt, 0, "GPIO1 ADB", (void *)0))
423 printk(KERN_ERR "pmu: can't get irq %d (GPIO1)\n", gpio_irq);
424 gpio_irq_enabled = 1;
434 if (pmu_kind == PMU_KEYLARGO_BASED) {
435 gpio_node = of_find_node_by_name(NULL, "extint-gpio1");
436 if (gpio_node == NULL)
437 gpio_node = of_find_node_by_name(NULL,
438 "pmu-interrupt");
439 if (gpio_node && gpio_node->n_intrs > 0)
440 gpio_irq = gpio_node->intrs[0].line;
441
442 if (gpio_irq != -1) {
443 if (request_irq(gpio_irq, gpio1_interrupt, 0,
444 "GPIO1 ADB", (void *)0))
445 printk(KERN_ERR "pmu: can't get irq %d"
446 " (GPIO1)\n", gpio_irq);
447 else
448 gpio_irq_enabled = 1;
449 }
425 }
426
427 /* Enable interrupts */
428 out_8(&via[IER], IER_SET | SR_INT | CB1_INT);
429
430 pmu_fully_inited = 1;
431
432 /* Make sure PMU settle down before continuing. This is _very_ important

--- 933 unchanged lines hidden (view full) ---

1366 if (len <= 2)
1367 req->reply_len = 0;
1368 else {
1369 memcpy(req->reply, data + 1, len - 1);
1370 req->reply_len = len - 1;
1371 }
1372 pmu_done(req);
1373 } else {
450 }
451
452 /* Enable interrupts */
453 out_8(&via[IER], IER_SET | SR_INT | CB1_INT);
454
455 pmu_fully_inited = 1;
456
457 /* Make sure PMU settle down before continuing. This is _very_ important

--- 933 unchanged lines hidden (view full) ---

1391 if (len <= 2)
1392 req->reply_len = 0;
1393 else {
1394 memcpy(req->reply, data + 1, len - 1);
1395 req->reply_len = len - 1;
1396 }
1397 pmu_done(req);
1398 } else {
1374#if defined(CONFIG_XMON) && !defined(CONFIG_PPC64)
1375 if (len == 4 && data[1] == 0x2c) {
1376 extern int xmon_wants_key, xmon_adb_keycode;
1377 if (xmon_wants_key) {
1378 xmon_adb_keycode = data[2];
1379 return;
1380 }
1381 }
1399 if (len == 4 && data[1] == 0x2c) {
1400 extern int xmon_wants_key, xmon_adb_keycode;
1401 if (xmon_wants_key) {
1402 xmon_adb_keycode = data[2];
1403 return;
1404 }
1405 }
1382#endif /* defined(CONFIG_XMON) && !defined(CONFIG_PPC64) */
1383#ifdef CONFIG_ADB
1384 /*
1385 * XXX On the [23]400 the PMU gives us an up
1386 * event for keycodes 0x74 or 0x75 when the PC
1387 * card eject buttons are released, so we
1388 * ignore those events.
1389 */
1390 if (!(pmu_kind == PMU_OHARE_BASED && len == 4

--- 1759 unchanged lines hidden ---
1406#ifdef CONFIG_ADB
1407 /*
1408 * XXX On the [23]400 the PMU gives us an up
1409 * event for keycodes 0x74 or 0x75 when the PC
1410 * card eject buttons are released, so we
1411 * ignore those events.
1412 */
1413 if (!(pmu_kind == PMU_OHARE_BASED && len == 4

--- 1759 unchanged lines hidden ---