summaryrefslogtreecommitdiffstats
path: root/Makefile.shared
AgeCommit message (Expand)Author
2010-08-21Makefile.share: fix brown-bag typo in link_o.darwin.Andy Polyakov
2010-07-16Makefile.shared: link_o.darwin comment update.Andy Polyakov
2010-07-15Makefile.shared: debugging line slipped through in previous commit.Andy Polyakov
2010-07-15Makefile.shared: update link_o.dawrin rule.Andy Polyakov
2009-10-15Fixes to CROSS_COMPILE, don't override command line option from environmentDr. Stephen Henson
2009-08-10PR: 2003Dr. Stephen Henson
2009-01-02Makefile.shared: improve portability of commit#17753.Andy Polyakov
2008-12-30Styling update to makefiles: eliminate redundant pipes.Andy Polyakov
2008-12-29Styling update to makefiles: $() to denote make substitutions and $${} -Andy Polyakov
2008-09-12AIX build updates.Andy Polyakov
2008-04-17Apply mingw patches as supplied by Roumen Petrov an Alon Bar-LevLutz Jänicke
2007-09-16Minor fix in link_[oa].hpux.Andy Polyakov
2007-08-26IRIX and Tru64 platform updates.Andy Polyakov
2007-07-31Proper support for shared build under MacOS X.Andy Polyakov
2007-05-19--enable-auto-image-base in cygwin build.Andy Polyakov
2007-03-25Allow shared builds for aix[64]-gcc targets.Andy Polyakov
2007-03-22Fixes for aix-shared rules.Andy Polyakov
2006-10-24Further mingw build procedure updates.Andy Polyakov
2006-10-23Harmonize dll naming in mingw builds.Andy Polyakov
2006-10-23Allow for mingw cross-compile configuration.Andy Polyakov
2006-10-21Rudimentary support for cross-compiling.Andy Polyakov
2006-05-20Tiny up hpux targets.Andy Polyakov
2006-04-11Add BeOS support.Ulf Möller
2005-12-16Fix typos in osf1 shared rules.Andy Polyakov
2005-11-09AIX -blibpath is not accumulative, one apparently has to specify evenAndy Polyakov
2005-10-28Add -install_name in link_a.darwin rule.Andy Polyakov
2005-10-25Fix install problems on MacOS X and HP-UX.Andy Polyakov
2005-06-23Darwin specific update for Configure and Makefile.shared.Andy Polyakov
2005-06-23HP-UX specific updates to Makefile.org and Makefile.shared.Andy Polyakov
2005-06-22Solaris-specific Makefile.shared update from 098.Andy Polyakov
2005-05-21Patches for Cygwin, provided by Corinna Vinschen <vinschen@redhat.com>Richard Levitte
2005-05-16Improve shell portability of new rules in Makefile.shared.Andy Polyakov
2005-05-16Make Makefile.shared quiet again.Andy Polyakov
2005-05-15Simplify shared rules, link run-path into applications only.Andy Polyakov
2005-04-30Cygwin/mingw sync with stable.Andy Polyakov
2005-04-13Parameterize do_solaris rules in Makefile.shared.Andy Polyakov
2005-04-04Extend Solaris x86 support to amd64.Andy Polyakov
2005-03-31Get rid of irritating noise.Ben Laurie
2005-02-06Make Makefile.shared BSD make-friendly, remove more redundant -lc, set upAndy Polyakov
2005-02-03Drop redundant -lc from a number of rules in Makefile.shared. It'sAndy Polyakov
2005-01-26The mix of CFLAGS and LDFLAGS is a bit confusing in my opinion, andRichard Levitte
2004-12-27As new major IRIX release is highly unlikely to appear [and break following],Andy Polyakov
2004-09-28Fix Solaris 10_x86 shared build. -Bsymbolic is required to avoidAndy Polyakov
2004-08-29Proper support for OpenBSD-i386 shared build, including assember modules!Andy Polyakov
2004-08-01Clean-up GAS targets: get rid of "cpp" stuff and replace it with "purified"Andy Polyakov
2004-07-24Minor HP-UX make update. IA-64-based HP-UX favor .so extension for sharedAndy Polyakov
2004-07-18Add anchors for AES, SHA-256/-512 assembler modules and SSE2 code pathes.Andy Polyakov
2004-05-31Minimal work-around for ./engine shared builds. "Minimal" means that IAndy Polyakov
2004-05-3132-bit PA-RISC requires -Bsymbolic when linking libcrypto.sl. WithoutAndy Polyakov
2004-05-31Working on HP-UX shared support...Andy Polyakov
59' href='#n459'>459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816
/*
 * Device driver for the PMU on 68K-based Apple PowerBooks
 *
 * The VIA (versatile interface adapter) interfaces to the PMU,
 * a 6805 microprocessor core whose primary function is to control
 * battery charging and system power on the PowerBooks.
 * The PMU also controls the ADB (Apple Desktop Bus) which connects
 * to the keyboard and mouse, as well as the non-volatile RAM
 * and the RTC (real time clock) chip.
 *
 * Adapted for 68K PMU by Joshua M. Thompson
 *
 * Based largely on the PowerMac PMU code by Paul Mackerras and
 * Fabio Riccardi.
 *
 * Also based on the PMU driver from MkLinux by Apple Computer, Inc.
 * and the Open Software Foundation, Inc.
 */

#include <stdarg.h>
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/miscdevice.h>
#include <linux/blkdev.h>
#include <linux/pci.h>
#include <linux/init.h>
#include <linux/interrupt.h>

#include <linux/adb.h>
#include <linux/pmu.h>
#include <linux/cuda.h>

#include <asm/macintosh.h>
#include <asm/macints.h>
#include <asm/mac_via.h>

#include <asm/pgtable.h>
#include <asm/irq.h>
#include <asm/uaccess.h>

/* Misc minor number allocated for /dev/pmu */
#define PMU_MINOR	154

/* VIA registers - spaced 0x200 bytes apart */
#define RS		0x200		/* skip between registers */
#define B		0		/* B-side data */
#define A		RS		/* A-side data */
#define DIRB		(2*RS)		/* B-side direction (1=output) */
#define DIRA		(3*RS)		/* A-side direction (1=output) */
#define T1CL		(4*RS)		/* Timer 1 ctr/latch (low 8 bits) */
#define T1CH		(5*RS)		/* Timer 1 counter (high 8 bits) */
#define T1LL		(6*RS)		/* Timer 1 latch (low 8 bits) */
#define T1LH		(7*RS)		/* Timer 1 latch (high 8 bits) */
#define T2CL		(8*RS)		/* Timer 2 ctr/latch (low 8 bits) */
#define T2CH		(9*RS)		/* Timer 2 counter (high 8 bits) */
#define SR		(10*RS)		/* Shift register */
#define ACR		(11*RS)		/* Auxiliary control register */
#define PCR		(12*RS)		/* Peripheral control register */
#define IFR		(13*RS)		/* Interrupt flag register */
#define IER		(14*RS)		/* Interrupt enable register */
#define ANH		(15*RS)		/* A-side data, no handshake */

/* Bits in B data register: both active low */
#define TACK		0x02		/* Transfer acknowledge (input) */
#define TREQ		0x04		/* Transfer request (output) */

/* Bits in ACR */
#define SR_CTRL		0x1c		/* Shift register control bits */
#define SR_EXT		0x0c		/* Shift on external clock */
#define SR_OUT		0x10		/* Shift out if 1 */

/* Bits in IFR and IER */
#define SR_INT		0x04		/* Shift register full/empty */
#define CB1_INT		0x10		/* transition on CB1 input */

static enum pmu_state {
	idle,
	sending,
	intack,
	reading,
	reading_intr,
} pmu_state;

static struct adb_request *current_req;
static struct adb_request *last_req;
static struct adb_request *req_awaiting_reply;
static unsigned char interrupt_data[32];
static unsigned char *reply_ptr;
static int data_index;
static int data_len;
static int adb_int_pending;
static int pmu_adb_flags;
static int adb_dev_map;
static struct adb_request bright_req_1, bright_req_2, bright_req_3;
static int pmu_kind = PMU_UNKNOWN;
static int pmu_fully_inited;

int asleep;

static int pmu_probe(void);
static int pmu_init(void);
static void pmu_start(void);
static irqreturn_t pmu_interrupt(int irq, void *arg);
static int pmu_send_request(struct adb_request *req, int sync);
static int pmu_autopoll(int devs);
void pmu_poll(void);
static int pmu_reset_bus(void);

static void pmu_start(void);
static void send_byte(int x);
static void recv_byte(void);
static void pmu_done(struct adb_request *req);
static void pmu_handle_data(unsigned char *data, int len);
static void set_volume(int level);
static void pmu_enable_backlight(int on);
static void pmu_set_brightness(int level);

struct adb_driver via_pmu_driver = {
	"68K PMU",
	pmu_probe,
	pmu_init,
	pmu_send_request,
	pmu_autopoll,
	pmu_poll,
	pmu_reset_bus
};

/*
 * This table indicates for each PMU opcode:
 * - the number of data bytes to be sent with the command, or -1
 *   if a length byte should be sent,
 * - the number of response bytes which the PMU will return, or
 *   -1 if it will send a length byte.
 */
static s8 pmu_data_len[256][2] = {
/*	   0	   1	   2	   3	   4	   5	   6	   7  */
/*00*/	{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
/*08*/	{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
/*10*/	{ 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
/*18*/	{ 0, 1},{ 0, 1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{ 0, 0},
/*20*/	{-1, 0},{ 0, 0},{ 2, 0},{ 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},
/*28*/	{ 0,-1},{ 0,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{ 0,-1},
/*30*/	{ 4, 0},{20, 0},{-1, 0},{ 3, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
/*38*/	{ 0, 4},{ 0,20},{ 2,-1},{ 2, 1},{ 3,-1},{-1,-1},{-1,-1},{ 4, 0},
/*40*/	{ 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
/*48*/	{ 0, 1},{ 0, 1},{-1,-1},{ 1, 0},{ 1, 0},{-1,-1},{-1,-1},{-1,-1},
/*50*/	{ 1, 0},{ 0, 0},{ 2, 0},{ 2, 0},{-1, 0},{ 1, 0},{ 3, 0},{ 1, 0},
/*58*/	{ 0, 1},{ 1, 0},{ 0, 2},{ 0, 2},{ 0,-1},{-1,-1},{-1,-1},{-1,-1},
/*60*/	{ 2, 0},{-1, 0},{-1, 0