2 * drivers/char/innovator_ps2.c
4 * Basic PS/2 keyboard/mouse driver for the Juno® USAR HID controller
5 * present on the TI Innovator/OMAP1510 Break-out-board.
8 * Author: MontaVista Software, Inc.
9 * <gdavis@mvista.com> or <source@mvista.com>
12 * 2003 (c) MontaVista Software, Inc. This file is licensed under
13 * the terms of the GNU General Public License version 2. This program
14 * is licensed "as is" without any warranty of any kind, whether express
20 * 1. Technical Reference Manual
22 * Multi-function ICs family
23 * UR8HC007-001 HID & Power management controller
24 * Document Number: DOC8-007-001-TR-075
26 * Copyright ©1998-2002 Semtech Corporation
27 * http://www.semtech.com/pdf/doc8-007-001-tr.pdf
29 * 2. Juno® 01 UR8HC007-001 Data Sheet
30 * Extremely Low-power Input Device and Power Management IC
31 * Copyright ©1998-2002 Semtech Corporation
33 * http://www.semtech.com/pdf/doc8-007-001-ds.pdf
38 * 20030626: George G. Davis <gdavis@mvista.com>
39 * Initially based on the following RidgeRun DSPlinux Version 1.6 files:
40 * linux-2.4.15-rmk1-dsplinux/arch/arm/dsplinux/hid/omap1510_hid.c
41 * linux-2.4.15-rmk1-dsplinux/arch/arm/dsplinux/hid/omap1510_hid.h
42 * linux-2.4.15-rmk1-dsplinux/arch/arm/dsplinux/hid/omap1510_ps2.c
43 * linux-2.4.15-rmk1-dsplinux/arch/arm/dsplinux/hid/omap1510_spi.c
44 * All original files above are
45 * Copyright (C) 2001 RidgeRun, Inc.
46 * Author: Alex McMains <aam@ridgerun.com>
48 * 20040812: Thiago Radicchi <trr@dcc.ufmg.br>
49 * Cleanup of old code from 2.4 driver and some debug code.
50 * Minor changes in interrupt handling code.
54 * 1. This driver does not provide support for setting keyboard/mouse
55 * configuration parameters. Both devices are managed directly by
56 * the Juno UR8HC007-001 on behalf of the host. This minimises the
57 * amount of host processing required to manage HID events and state
58 * changes, e.g. both keyboard and mouse devices are hot pluggable
59 * with no host intervention required. However, we cannot customise
60 * keyboard/mouse settings in this case. So we live with the defaults
61 * as setup by the Juno UR8HC007-001 whatever they may be.
62 * 2. Keyboard auto repeat does not work. See 1 above. : )
67 * 1. Complete DPM/LDM stubs and test.
68 * 2. Add SPI error handling support, i.e. resend, etc.,.
69 * 3. Determine why innovator_hid_interrupt() is called for every
70 * invocation of Innovator FPGA IRQ demux. It appears that the
71 * missed Innovator ethernet workaround may be to blame. However,
72 * it does not adversely affect operation of this driver since we
73 * check for assertion of ATN prior to servicing the interrupt. If
74 * ATN is negated, we bug out right away.
78 #include <linux/version.h>
79 #include <linux/stddef.h>
80 #include <linux/module.h>
81 #include <linux/init.h>
82 #include <linux/kernel.h>
83 #include <linux/types.h>
84 #include <linux/delay.h>
85 #include <linux/types.h>
86 #include <linux/ptrace.h>
87 #include <linux/sched.h>
88 #include <linux/interrupt.h>
89 #include <linux/input.h>
90 #include <linux/slab.h>
92 #include <linux/miscdevice.h>
93 #include <linux/poll.h>
94 #include <linux/string.h>
95 #include <linux/ioport.h>
96 #include <linux/platform_device.h>
99 #include <asm/hardware.h>
101 #include <asm/uaccess.h>
102 #include <asm/arch/fpga.h>
104 #undef INNOVATOR_KEYB_DEBUG
105 #ifdef INNOVATOR_KEYB_DEBUG
106 #define dbg(format, arg...) printk(KERN_DEBUG "%s:%d: " format , \
107 __FUNCTION__ , __LINE__ , ## arg)
108 #define entry() printk(KERN_DEBUG "%s:%d: Entry\n" , __FUNCTION__ , __LINE__)
109 #define exit() printk(KERN_DEBUG "%s:%d: Exit\n" , __FUNCTION__ , __LINE__)
110 #define dump_packet(p, n) \
113 printk(KERN_DEBUG "%s:%d: %08x:" , \
114 __FUNCTION__ , __LINE__ , (int) p); \
115 for (i = 0; i < n; i += 1) { \
116 printk(" %02x", (int) p[i]); \
121 #define dbg(format, arg...) do {} while (0)
122 #define entry() do {} while (0)
123 #define exit() do {} while (0)
124 #define dump_packet(p, n) do {} while (0)
128 #define PFX "innovator_ps2"
129 #define err(format, arg...) printk(KERN_ERR PFX ": " format , ## arg)
130 #define info(format, arg...) printk(KERN_INFO PFX ": " format , ## arg)
131 #define warn(format, arg...) printk(KERN_WARNING PFX ": " format , ## arg)
134 /****************************************************************************/
137 * Synchronous communications timing parameters (Reference [1] pg 7-7)
140 #define tMSA 5000 /* -/5ms _SS to _ATN (master transfer) */
141 #define tMAC 100 /* 100us/5ms _ATN to first clock pulse (master
143 #define tMIB 150 /* 150us/5ms Beginning of byte transfer to beginning
144 of next byte transfer */
145 #define tSIB 150 /* 150us/5ms Beginning of byte transfer to beginning
146 of next byte transfer */
147 #define tMSP 100 /* -/100us Last clock pulse of packet to _SS
149 #define tMNSA 100 /* -/100us _SS de-assertion to _ATN de-assertion */
150 #define tMNEXT 120 /* 120uS/- _ATN release to _SS re-assertion
152 #define tSAS 5000 /* -/5ms _ATN to _SS (slave transfer) */
153 #define tSSC 100 /* 100us/5ms _SS to first clock pulse (slave
155 #define tSNA 100 /* -/100us Last clock pulse of packet to _ATN
157 #define tSNAS 100 /* -/100us _ATN release to _SS de-assertion */
158 #define tSNEXT 120 /* 120us/- _SS release to _ATN re-assertion
160 #define tSCK 4 /* 4us/- Clock period */
161 #define tSLOW 2 /* 2us/- Clock LOW period */
162 #define tHOLD 200 /* 200ns/- Master data hold time */
163 #define tSETUP 100 /* 100ns/- Master data setup Time */
164 #define tSSETUP 500 /* -/500ns Slave data setup time from clock
169 * Protocol Headers (Reference [1], pg. 5-1):
173 /* Protocols used in commands issued by the host: */
174 #define SIMPLE 0x80 /* Simple commands
175 * Common for both host and controller
178 #define WRITE_REGISTER_BIT 0x81 /* Write register bit */
179 #define READ_REGISTER_BIT 0x82 /* Read register bit */
180 #define WRITE_REGISTER 0x83 /* Write register */
181 #define READ_REGISTER 0x84 /* Read register */
182 #define WRITE_BLOCK 0x85 /* Write block */
183 #define READ_BLOCK 0x86 /* Read block */
186 /* Protocols used in responses, reports and alerts issued by the controller: */
187 #define REPORT_REGISTER_BIT 0x81 /* Report register bit & event alerts */
188 #define REPORT_REGISTER 0x83 /* Report register */
189 #define REPORT_BLOCK 0x85 /* Report block */
190 #define POINTING_REPORT 0x87 /* Pointing device data report */
191 #define KEYBOARD_REPORT 0x88 /* Keyboard device data report */
194 /* Simple Commands (Reference [1], pg 5-3): */
195 #define INITIALIZE 0x00 /* Forces the recipient to enter the
196 * known default power-on state.
198 #define INITIALIZATION_COMPLETE 0x01 /* Issued as a hand-shake response only
199 * to the "Initialize" command.
201 #define RESEND_REQUEST 0x05 /* Issued upon error in the reception
202 * of a package. The recipient resends
203 * the last transmitted packet.
206 /* Register offsets (Reference [1], pg 6-1 thru 6-9): */
208 #define REG_PM_COMM 0
209 #define REG_PM_STATUS 1
210 #define REG_PAGENO 255
212 /* Power management bits ((Reference [1], pg 6-10): */
214 #define SUS_STATE 0x2 /* in REG_PM_COMM */
216 /* Miscellaneous constants: */
218 #define X_MSB_SHIFT (8-4)
219 #define X_MSB_MASK (3<<4)
220 #define Y_MSB_SHIFT (8-6)
221 #define Y_MSB_MASK (3<<6)
224 #define JUNO_BLOCK_SIZE 32
225 #define JUNO_BUFFER_SIZE 256
232 #define E_BAD_HEADER 1
234 #define E_ZERO_BYTES 3
235 #define E_BAD_VALUE 4
237 #define E_REPORT_MODE 6
239 #define E_BAD_DEVICE_ID 8
244 * Host/Controller Command/Response Formats:
247 typedef struct _simple_t {
251 } __attribute__ ((packed)) simple_t;
253 typedef struct _write_bit_t {
258 } __attribute__ ((packed)) write_bit_t;
260 typedef struct _read_bit_t {
265 } __attribute__ ((packed)) read_bit_t;
267 typedef struct _write_reg_t {
272 } __attribute__ ((packed)) write_reg_t;
274 typedef struct _read_reg_t {
278 } __attribute__ ((packed)) read_reg_t;
280 typedef struct _write_block_t {
284 u8 block[JUNO_BLOCK_SIZE + 1]; /* Hack: LRC is last element of block[] */
285 } __attribute__ ((packed)) write_block_t;
287 typedef struct _read_block_t {
292 } __attribute__ ((packed)) read_block_t;
294 typedef struct _report_bit_t {
299 } __attribute__ ((packed)) report_bit_t;
301 typedef struct _report_reg_t {
306 } __attribute__ ((packed)) report_reg_t;
308 typedef struct _report_block_t {
314 } __attribute__ ((packed)) report_block_t;
316 typedef struct _mse_report_t {
323 } __attribute__ ((packed)) mse_report_t;
325 typedef struct _kdb_report_t {
327 u8 keynum; /* up > 0x80, down < 0x7E, all keys up 0x00 */
329 } __attribute__ ((packed)) kdb_report_t;
332 static u8 buffer[JUNO_BUFFER_SIZE];
334 static void do_hid_tasklet(unsigned long);
335 DECLARE_TASKLET(hid_tasklet, do_hid_tasklet, 0);
336 static struct innovator_hid_dev *hid;
338 struct innovator_hid_dev {
339 struct input_dev mouse, keyboard;
344 /****************************************************************************/
347 * Low-level TI Innovator/OMAP1510 FPGA HID SPI interface helper functions:
351 innovator_fpga_hid_rd(void)
353 u8 val = inb(INNOVATOR_FPGA_HID_SPI);
358 innovator_fpga_hid_wr(u8 val)
360 outb(val, INNOVATOR_FPGA_HID_SPI);
364 innovator_fpga_hid_frob(u8 mask, u8 val)
367 local_irq_save(flags);
368 innovator_fpga_hid_wr((innovator_fpga_hid_rd() & ~mask) | val);
369 local_irq_restore(flags);
373 innovator_fpga_hid_set_bits(u8 x)
375 innovator_fpga_hid_frob(x, x);
381 innovator_fpga_hid_frob(OMAP1510_FPGA_HID_nSS, value ? OMAP1510_FPGA_HID_nSS : 0);
387 innovator_fpga_hid_frob(OMAP1510_FPGA_HID_SCLK, value ? OMAP1510_FPGA_HID_SCLK : 0);
393 innovator_fpga_hid_frob(OMAP1510_FPGA_HID_MOSI, value ? OMAP1510_FPGA_HID_MOSI : 0);
399 return ((innovator_fpga_hid_rd() & OMAP1510_FPGA_HID_MISO) ? 1 : 0);
405 return ((innovator_fpga_hid_rd() & OMAP1510_FPGA_HID_ATN) ? 1 : 0);
409 wait_for_ATN(int assert, int timeout)
415 } while (timeout -= 1);
420 innovator_fpga_hid_xfer_byte(u8 xbyte)
425 for (rbyte = 0, i = 7; i >= 0; i -= 1) {
427 MOSI((xbyte >> i) & 1);
430 rbyte = (rbyte << 1) | MISO();
438 innovator_fpga_hid_reset(void)
440 innovator_fpga_hid_wr(OMAP1510_FPGA_HID_SCLK | OMAP1510_FPGA_HID_MOSI);
442 innovator_fpga_hid_set_bits(OMAP1510_FPGA_HID_RESETn);
446 /*****************************************************************************
448 Refer to Reference [1], Chapter 7 / Low-level communications, Serial
449 Peripheral Interface (SPI) implementation Host (master) packet
450 transmission timing, pg. 7-3, for timing and implementation details
453 *****************************************************************************/
456 spi_xmt(u8 * p, u8 n)
461 local_irq_save(flags);
462 disable_irq(OMAP1510_INT_FPGA_ATN);
465 /* Oops, we have a collision. */
466 enable_irq(OMAP1510_INT_FPGA_ATN);
467 local_irq_restore(flags);
468 dbg("Protocol error: ATN is asserted\n");
474 if (wait_for_ATN(1, tMSA) < 0) {
476 enable_irq(OMAP1510_INT_FPGA_ATN);
477 local_irq_restore(flags);
478 dbg("timeout waiting for ATN assertion\n");
485 innovator_fpga_hid_xfer_byte(*p++);
487 udelay(tMIB - 8 * tSCK);
491 MOSI(1); /* Set MOSI to idle high. */
493 /* NOTE: The data sheet does not specify a minimum delay
494 * here. But innovator_fpga_hid_xfer_byte() gives us a half-clock
495 * delay (tSLOW) after the last bit is sent. So I'm happy with
501 if (wait_for_ATN(0, tMNSA) < 0) {
502 enable_irq(OMAP1510_INT_FPGA_ATN);
503 local_irq_restore(flags);
504 dbg("timeout waiting for ATN negation\n");
509 enable_irq(OMAP1510_INT_FPGA_ATN);
510 local_irq_restore(flags);
515 /*****************************************************************************
517 Refer to Reference [1], Chapter 7 / Low-level communications, Serial
518 Peripheral Interface (SPI) implementation, Slave packet transmission
519 timing, pg. 7-5, for timing and implementation details for spi_rcv().
521 *****************************************************************************/
524 spi_rcv(u8 * p, int len)
530 /* Limit packet size to something reasonable */
534 local_irq_save(flags);
536 if (wait_for_ATN(1, tMSA) < 0) {
537 local_irq_restore(flags);
538 dbg("Protocol error: ATN is not asserted\n");
548 err("over run error\n");
552 p[ret++] = innovator_fpga_hid_xfer_byte(0xff);
553 udelay(tSNA); /* Wait long enough to detect negation of ATN
554 * after last clock pulse of packet.
556 * NOTE: Normally, we need a minimum delay of
557 * tSIB between the start of one byte
558 * and the start of the next. However,
559 * we also need to wait long enough
560 * for the USAR to negate ATN before
561 * starting the next byte. So we use
562 * max(tSIB - 8 * tSCK, tSNA) here to
563 * satisfy both constraints.
567 SS(0); /* NOTE: The data sheet does not specify a minimum delay
568 * here. But innovator_fpga_hid_xfer_byte() gives us a
569 * half-clock delay (tSLOW) after the last bit is sent. So
570 * I'm happy with that (rather than no delay at all : ).
574 udelay(tSNEXT); /* This isn't quite right. Assertion of ATN after
575 * negation of SS is an USAR timing constraint.
576 * What we need here is a spec for the minimum
577 * delay from SS negation to SS assertion. But
578 * for now, just use this brain dead delay.
581 local_irq_restore(flags);
591 /*****************************************************************************
592 Calculate Host/Controller Command/Response Longitudinal Redundancy Check (LRC)
594 The algorithm implemented in calculate_LRC() below is taken directly from
595 the reference [1], Chapter 7 / Low-level communications, LRC (Longitudinal
596 Redundancy Check), pg 5-10.
598 *****************************************************************************/
601 calculate_LRC(u8 * p, int n)
607 * Init the LRC using the first two message bytes.
612 * Update the LRC using the remainder of the p.
614 for (i = 2; i < n; i++)
618 * If the MSB is set then clear the MSB and change the next
619 * most significant bit
629 * Controller response helper functions:
633 report_mouse(mse_report_t * p, int n)
635 if (p->header != POINTING_REPORT)
636 return -E_BAD_HEADER;
638 if (n != sizeof(mse_report_t))
641 return (p->LRC != calculate_LRC((u8 *) p, sizeof(mse_report_t) - 1)) ?
642 -E_BAD_LRC : POINTING_REPORT;
646 report_keyboard(kdb_report_t * p, int n)
648 if (p->header != KEYBOARD_REPORT)
649 return -E_BAD_HEADER;
651 if (n != sizeof(kdb_report_t))
654 return (p->LRC != calculate_LRC((u8 *) p, sizeof(kdb_report_t) - 1)) ?
655 -E_BAD_LRC : KEYBOARD_REPORT;
660 * Miscellaneous helper functions:
664 report_type(u8 * type)
666 /* check the header to find out what kind of report it is */
667 if ((*type) == KEYBOARD_REPORT)
668 return KEYBOARD_REPORT;
669 else if ((*type) == POINTING_REPORT)
670 return POINTING_REPORT;
672 return -E_BAD_HEADER;
676 report_async(void * p, int n)
680 if ((ret = spi_rcv((u8 *) p, n)) < 0)
683 if (report_type((u8 *) p) == POINTING_REPORT)
684 ret = report_mouse((mse_report_t *) p, ret);
685 else if (report_type((u8 *) p) == KEYBOARD_REPORT)
686 ret = report_keyboard((kdb_report_t *) p, ret);
692 * Host command helper functions:
696 /* REVISIT/TODO: Wrapper for command/response with resend handing. */
698 spi_xfer(u8 * optr, u8 osz, u8 * iptr, u8 isz)
705 if (optr != NULL && osz) {
707 ret = spi_xmt((u8 *) optr, osz);
711 ret = spi_rcv((u8 *) buf, 256);
713 if (ret == -EREMOTEIO) {
718 } while (xretries--);
724 /* REVISIT: Enable these when/if additional Juno features are required. */
733 p.LRC = calculate_LRC((u8 *) & p, sizeof(p) - 1);
735 if ((ret = spi_xmt((u8 *) & p, sizeof(p))) < 0)
738 if ((ret = spi_rcv((u8 *) & p, sizeof(p))) < 0)
742 return -E_ZERO_BYTES;
744 if (ret != sizeof(p))
747 if (p.header != SIMPLE)
748 return -E_BAD_HEADER;
750 if (p.LRC != calculate_LRC((u8 *) & p, sizeof(p) - 1))
753 /* REVISIT: Need to check or return response code here? */
757 write_bit(u8 offset, u8 bit, u8 value)
759 static write_bit_t p;
761 p.header = WRITE_REGISTER_BIT;
763 p.value_bit = (bit << 1) | (value & 1);
764 p.LRC = calculate_LRC((u8 *) & p, sizeof(p) - 1);
766 return spi_xmt((u8 *) & p, sizeof(p));
770 read_bit(u8 offset, u8 bit, u8 * data)
773 static report_bit_t q;
776 p.header = READ_REGISTER_BIT;
779 p.LRC = calculate_LRC((u8 *) & p, sizeof(p) - 1);
781 if ((ret = spi_xmt((u8 *) & p, sizeof(p))) < 0)
784 if ((ret = spi_rcv((u8 *) & q, sizeof(q))) < 0)
788 return -E_ZERO_BYTES;
790 if (ret != sizeof(q))
793 if (q.header != REPORT_REGISTER_BIT)
794 return -E_BAD_HEADER;
796 if (q.LRC != calculate_LRC((u8 *) & q, sizeof(q) - 1))
805 write_reg(u8 offset, u8 value)
807 static write_reg_t p;
809 p.header = WRITE_REGISTER;
812 p.LRC = calculate_LRC((u8 *) & p, sizeof(p) - 1);
814 return spi_xmt((u8 *) & p, sizeof(p));
818 read_reg(u8 offset, u8 * data)
821 static report_reg_t q;
824 p.header = READ_REGISTER;
826 p.LRC = calculate_LRC((u8 *) & p, sizeof(p) - 1);
828 if ((ret = spi_xmt((u8 *) & p, sizeof(p))) < 0)
831 if ((ret = spi_rcv((u8 *) & q, sizeof(q))) < 0)
835 return -E_ZERO_BYTES;
837 if (ret != sizeof(q))
840 if (q.header != REPORT_REGISTER)
841 return -E_BAD_HEADER;
843 if (q.LRC != calculate_LRC((u8 *) & q, sizeof(q) - 1))
852 write_block(u8 offset, u8 length, u8 * block)
854 static write_block_t p;
856 p.header = WRITE_BLOCK;
859 memcpy(&p.block, block, length);
860 p.block[length] = calculate_LRC((u8 *) & p, 3 + length);
862 return spi_xmt((u8 *) & p, 4 + length);
866 read_block(u8 offset, u8 length, u8 * buf)
868 static read_block_t p;
869 static report_block_t q;
872 p.header = READ_BLOCK;
875 p.LRC = calculate_LRC((u8 *) & p, sizeof(p) - 1);
877 if ((ret = spi_xmt((u8 *) & p, sizeof(p))) < 0)
880 if ((ret = spi_rcv((u8 *) & q, sizeof(q))) < 0)
884 return -E_ZERO_BYTES;
886 if (ret != sizeof(4 + q.length))
889 if (q.header != REPORT_BLOCK)
890 return -E_BAD_HEADER;
892 if (q.block[q.length] != calculate_LRC((u8 *) & q, 3 + q.length))
895 if (length != q.length)
898 memcpy(buf, &q.block, length);
903 #ifdef INNOVATOR_KEYB_DEBUG
910 for (i = 0; i < 256; i += 8) {
911 read_block(i, 16, buffer);
917 /*****************************************************************************/
920 process_pointing_report(struct innovator_hid_dev *hid, u8 * buffer)
922 static int prev_x, prev_y, prev_btn;
925 if (buffer[1] & (1 << 3)) {
926 /* relative pointing device report */
930 /* check the sign and convert from 2's complement if negative */
931 if (buffer[1] & (1<<4))
934 /* input driver wants -y */
935 if (buffer[1] & (1<<5))
940 input_report_key(&hid->mouse,
941 BTN_LEFT, buffer[1] & (1<<0));
942 input_report_key(&hid->mouse,
943 BTN_RIGHT, buffer[1] & (1<<1));
944 input_report_key(&hid->mouse,
945 BTN_MIDDLE, buffer[1] & (1<<2));
946 input_report_rel(&hid->mouse, REL_X, x);
947 input_report_rel(&hid->mouse, REL_Y, y);
949 /* REVISIT: Does this work? */
950 /* absolute pointing device report */
951 x = buffer[2] + ((buffer[1] & X_MSB_MASK) << X_MSB_SHIFT);
952 y = buffer[3] + ((buffer[1] & Y_MSB_MASK) << Y_MSB_SHIFT);
953 btn = buffer[1] & (1<<0);
955 if ((prev_x == x) && (prev_y == y)
956 && (prev_btn == btn))
959 input_report_key(&hid->mouse, BTN_LEFT, btn);
960 input_report_abs(&hid->mouse, ABS_X, x);
961 input_report_abs(&hid->mouse, ABS_Y, y);
966 input_sync(&hid->mouse);
967 dbg("HID X: %d Y: %d Functions: %x\n", x, y, buffer[1]);
971 * Reference [1], Appendix A, Semtech standard PS/2 key number definitions,
972 * pgs. A-1 through A-3. The following table lists standard PS/2 key numbers
973 * used by the Juno® 01 keyboard manager.
976 * 1. The following table indices are E0 codes which require special handling:
977 * 53..62, 77..78, 94, 96, 100, 102..104, 108..110
978 * 2. The following table indices are E1 codes which require special handling:
982 static unsigned char usar2scancode[128] = {
983 0x00, 0x29, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
984 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
985 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
986 0x18, 0x19, 0x1a, 0x1b, 0x2b, 0x1e, 0x1f, 0x20,
987 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
988 0x1c, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32,
989 0x33, 0x34, 0x35, 0x39, 0x01, 0x52, 0x53, 0x4b,
990 0x47, 0x4f, 0x48, 0x50, 0x49, 0x51, 0x4d, 0x37,
991 0x4e, 0x4f, 0x50, 0x51, 0x4b, 0x4c, 0x4d, 0x47,
992 0x48, 0x49, 0x52, 0x53, 0x4a, 0x1c, 0x35, 0x3b,
993 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43,
994 0x44, 0x57, 0x58, 0x2a, 0x36, 0x38, 0x38, 0x1d,
995 0x1d, 0x3a, 0x45, 0x46, 0x2a, 0x1d, 0x5b, 0x5c,
996 0x5d, 0xff, 0x00, 0x00, 0x5e, 0x5f, 0x63, 0x70,
997 0x7b, 0x79, 0x7d, 0x73, 0x5b, 0x5c, 0x5d, 0x63,
998 0x65, 0x66, 0x68, 0x69, 0x6b, 0x56, 0x54, 0x00
1002 * The following are bit masks used to encode E0 scan codes which
1003 * require special handling. However, scan codes 100 and 101 are
1004 * excludable here since they each require unique multi-byte scan
1005 * code translations and are therefore dealt with individually via
1006 * handle_print_scr() and handle_pause() respectively below.
1009 static unsigned long int e0_codes1 = 0x030003ff; /* scan codes 53..84 */
1010 static unsigned long int e0_codes2 = 0x038e0a00; /* scan codes 85..116 */
1013 handle_print_scr(int up)
1016 input_report_key(&hid->keyboard, 0xe0, 1);
1017 input_report_key(&hid->keyboard, 0xb7, 1);
1018 input_report_key(&hid->keyboard, 0xe0, 1);
1019 input_report_key(&hid->keyboard, 0xaa, 1);
1021 input_report_key(&hid->keyboard, 0xe0, 0);
1022 input_report_key(&hid->keyboard, 0x2a, 0);
1023 input_report_key(&hid->keyboard, 0xe0, 0);
1024 input_report_key(&hid->keyboard, 0x37, 0);
1031 input_report_key(&hid->keyboard, 0xe1, 0);
1032 input_report_key(&hid->keyboard, 0x1d, 0);
1033 input_report_key(&hid->keyboard, 0x45, 0);
1034 input_report_key(&hid->keyboard, 0xe1, 0);
1035 input_report_key(&hid->keyboard, 0x9d, 0);
1036 input_report_key(&hid->keyboard, 0xc5, 0);
1040 process_keyboard_report(struct innovator_hid_dev *hid, u8 * buffer)
1042 unsigned char ch = buffer[1] & 0x7f;
1043 int up = buffer[1] & 0x80 ? 1 : 0;
1046 if ((ch == 106) || (ch == 107))
1047 return; /* no code */
1050 handle_print_scr(up);
1059 if ((ch >= 53) && (ch <= 84)) {
1060 /* first block of e0 codes */
1061 is_e0 = e0_codes1 & (1 << (ch - 53));
1062 } else if ((ch >= 85) && (ch <= 116)) {
1063 /* second block of e0 codes */
1064 is_e0 = e0_codes2 & (1 << (ch - 85));
1068 input_report_key(&hid->keyboard, 0xe0, !up);
1070 input_report_key(&hid->keyboard, usar2scancode[ch], !up);
1071 input_sync(&hid->keyboard);
1075 innovator_hid_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1078 disable_irq(OMAP1510_INT_FPGA_ATN);
1079 tasklet_schedule(&hid_tasklet);
1085 do_hid_tasklet(unsigned long unused)
1088 if ((ret = report_async(buffer, 256)) == -1) {
1089 dbg("Error: Bad Juno return value: %d\n", ret);
1090 } else if (ret == KEYBOARD_REPORT) {
1091 process_keyboard_report(hid, buffer);
1092 } else if (ret == POINTING_REPORT) {
1093 process_pointing_report(hid, buffer);
1095 dbg("ERROR: bad report\n");
1097 enable_irq(OMAP1510_INT_FPGA_ATN);
1101 innovator_hid_open(struct input_dev *dev)
1106 if (request_irq(OMAP1510_INT_FPGA_ATN, (void *) innovator_hid_interrupt,
1107 SA_INTERRUPT, PFX, hid) < 0)
1114 innovator_hid_close(struct input_dev *dev)
1125 static int innovator_ps2_remove(struct device *dev)
1130 static void innovator_ps2_device_release(struct device *dev)
1135 static int innovator_ps2_suspend(struct device *dev, pm_message_t state)
1140 * Set SUS_STATE in REG_PM_COMM (Page 0 R0). This will cause
1141 * PM_MOD bits of REG_PM_STATUS to show suspended state,
1142 * but the SUS_STAT bit of REG_PM_STATUS will continue to
1143 * reflect the state of the _HSUS pin.
1146 if (write_reg(REG_PAGENO, 0) < 0)
1147 printk("ps2 suspend: write_reg REG_PAGENO error\n");
1149 if (read_reg(REG_PM_COMM, &pmcomm) < 0)
1150 printk("ps2 suspend: read_reg REG_PM_COMM error\n");
1152 if (write_reg(REG_PM_COMM, pmcomm | SUS_STATE) < 0)
1153 printk("ps2 suspend: write_reg REG_PM_COMM error\n");
1158 static int innovator_ps2_resume(struct device *dev)
1163 * Clear SUS_STATE from REG_PM_COMM (Page 0 R0).
1166 if (write_reg(REG_PAGENO, 0) < 0)
1167 printk("ps2 resume: write_reg REG_PAGENO error\n");
1169 if (read_reg(REG_PM_COMM, &pmcomm) < 0)
1170 printk("ps2 resume: read_reg REG_PM_COMM error\n");
1172 if (write_reg(REG_PM_COMM, pmcomm & ~SUS_STATE) < 0)
1173 printk("ps2 resume: write_reg REG_PM_COMM error\n");
1178 static struct device_driver innovator_ps2_driver = {
1179 .name = "innovator_ps2",
1180 .bus = &platform_bus_type,
1181 .remove = innovator_ps2_remove,
1182 .suspend = innovator_ps2_suspend,
1183 .resume = innovator_ps2_resume,
1186 static struct platform_device innovator_ps2_device = {
1190 .driver = &innovator_ps2_driver,
1191 .release = innovator_ps2_device_release,
1196 innovator_kbd_init(void)
1199 info("Innovator PS/2 keyboard/mouse driver v1.0\n");
1201 innovator_fpga_hid_reset();
1203 if ((hid = kmalloc(sizeof(struct innovator_hid_dev),
1204 GFP_KERNEL)) == NULL) {
1205 warn("unable to allocate space for HID device\n");
1209 /* setup the mouse */
1210 memset(hid, 0, sizeof(struct innovator_hid_dev));
1211 hid->mouse.evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
1212 hid->mouse.keybit[LONG(BTN_MOUSE)] =
1213 BIT(BTN_LEFT) | BIT(BTN_RIGHT) |
1214 BIT(BTN_MIDDLE) | BIT(BTN_TOUCH);
1215 hid->mouse.relbit[0] = BIT(REL_X) | BIT(REL_Y);
1216 hid->mouse.private = hid;
1217 hid->mouse.open = innovator_hid_open;
1218 hid->mouse.close = innovator_hid_close;
1219 hid->mouse.name = "innovator_mouse";
1220 hid->mouse.id.bustype = 0;
1221 hid->mouse.id.vendor = 0;
1222 hid->mouse.id.product = 0;
1223 hid->mouse.id.version = 0;
1224 hid->keyboard.evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
1225 init_input_dev(&hid->keyboard);
1226 hid->keyboard.keycodesize = sizeof(unsigned char);
1227 hid->keyboard.keycodemax = ARRAY_SIZE(usar2scancode);
1228 for(i = 0; i < 128; i++)
1229 set_bit(usar2scancode[i], hid->keyboard.keybit);
1230 hid->keyboard.private = hid;
1231 hid->keyboard.open = innovator_hid_open;
1232 hid->keyboard.close = innovator_hid_close;
1233 hid->keyboard.name = "innovator_keyboard";
1234 hid->keyboard.id.bustype = 0;
1235 hid->keyboard.id.vendor = 0;
1236 hid->keyboard.id.product = 0;
1237 hid->keyboard.id.version = 0;
1238 input_register_device(&hid->mouse);
1239 input_register_device(&hid->keyboard);
1240 innovator_hid_open(&hid->mouse);
1241 innovator_hid_open(&hid->keyboard);
1243 if (driver_register(&innovator_ps2_driver) != 0)
1244 printk(KERN_ERR "Driver register failed for innovator_ps2\n");
1246 if (platform_device_register(&innovator_ps2_device) != 0) {
1247 printk(KERN_ERR "Device register failed for ps2\n");
1248 driver_unregister(&innovator_ps2_driver);
1251 #ifdef INNOVATOR_KEYB_DEBUG
1258 innovator_kbd_exit(void)
1260 input_unregister_device(&hid->mouse);
1261 input_unregister_device(&hid->keyboard);
1262 free_irq(OMAP1510_INT_FPGA_ATN, hid);
1265 driver_unregister(&innovator_ps2_driver);
1266 platform_device_unregister(&innovator_ps2_device);
1270 module_init(innovator_kbd_init);
1271 module_exit(innovator_kbd_exit);
1273 MODULE_AUTHOR("George G. Davis <gdavis@mvista.com>");
1274 MODULE_DESCRIPTION("Innovator PS/2 Driver");
1275 MODULE_LICENSE("GPL");