Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Amiga mouse driver for Linux/m68k |
| 3 | * |
| 4 | * Copyright (c) 2000-2002 Vojtech Pavlik |
| 5 | * |
| 6 | * Based on the work of: |
| 7 | * Michael Rausch James Banks |
| 8 | * Matther Dillon David Giller |
| 9 | * Nathan Laredo Linus Torvalds |
| 10 | * Johan Myreen Jes Sorensen |
| 11 | * Russell King |
| 12 | */ |
| 13 | |
| 14 | /* |
| 15 | * This program is free software; you can redistribute it and/or modify it |
| 16 | * under the terms of the GNU General Public License version 2 as published by |
| 17 | * the Free Software Foundation |
| 18 | */ |
| 19 | |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/init.h> |
| 22 | #include <linux/input.h> |
| 23 | #include <linux/interrupt.h> |
| 24 | |
| 25 | #include <asm/irq.h> |
| 26 | #include <asm/setup.h> |
| 27 | #include <asm/system.h> |
| 28 | #include <asm/uaccess.h> |
| 29 | #include <asm/amigahw.h> |
| 30 | #include <asm/amigaints.h> |
| 31 | |
| 32 | MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); |
| 33 | MODULE_DESCRIPTION("Amiga mouse driver"); |
| 34 | MODULE_LICENSE("GPL"); |
| 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | static int amimouse_lastx, amimouse_lasty; |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 37 | static struct input_dev *amimouse_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 39 | static irqreturn_t amimouse_interrupt(int irq, void *dummy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | { |
| 41 | unsigned short joy0dat, potgor; |
| 42 | int nx, ny, dx, dy; |
| 43 | |
Al Viro | b4290a2 | 2006-01-12 01:06:12 -0800 | [diff] [blame] | 44 | joy0dat = amiga_custom.joy0dat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | nx = joy0dat & 0xff; |
| 47 | ny = joy0dat >> 8; |
| 48 | |
| 49 | dx = nx - amimouse_lastx; |
| 50 | dy = ny - amimouse_lasty; |
| 51 | |
| 52 | if (dx < -127) dx = (256 + nx) - amimouse_lastx; |
| 53 | if (dx > 127) dx = (nx - 256) - amimouse_lastx; |
| 54 | if (dy < -127) dy = (256 + ny) - amimouse_lasty; |
| 55 | if (dy > 127) dy = (ny - 256) - amimouse_lasty; |
| 56 | |
| 57 | amimouse_lastx = nx; |
| 58 | amimouse_lasty = ny; |
| 59 | |
Al Viro | b4290a2 | 2006-01-12 01:06:12 -0800 | [diff] [blame] | 60 | potgor = amiga_custom.potgor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 62 | input_report_rel(amimouse_dev, REL_X, dx); |
| 63 | input_report_rel(amimouse_dev, REL_Y, dy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 65 | input_report_key(amimouse_dev, BTN_LEFT, ciaa.pra & 0x40); |
| 66 | input_report_key(amimouse_dev, BTN_MIDDLE, potgor & 0x0100); |
| 67 | input_report_key(amimouse_dev, BTN_RIGHT, potgor & 0x0400); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 69 | input_sync(amimouse_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
| 71 | return IRQ_HANDLED; |
| 72 | } |
| 73 | |
| 74 | static int amimouse_open(struct input_dev *dev) |
| 75 | { |
| 76 | unsigned short joy0dat; |
| 77 | |
Al Viro | b4290a2 | 2006-01-12 01:06:12 -0800 | [diff] [blame] | 78 | joy0dat = amiga_custom.joy0dat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
| 80 | amimouse_lastx = joy0dat & 0xff; |
| 81 | amimouse_lasty = joy0dat >> 8; |
| 82 | |
| 83 | if (request_irq(IRQ_AMIGA_VERTB, amimouse_interrupt, 0, "amimouse", amimouse_interrupt)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | printk(KERN_ERR "amimouse.c: Can't allocate irq %d\n", IRQ_AMIGA_VERTB); |
| 85 | return -EBUSY; |
| 86 | } |
| 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | static void amimouse_close(struct input_dev *dev) |
| 92 | { |
Dmitry Torokhov | 3108d42 | 2005-05-29 02:29:30 -0500 | [diff] [blame] | 93 | free_irq(IRQ_AMIGA_VERTB, amimouse_interrupt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | static int __init amimouse_init(void) |
| 97 | { |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 98 | int err; |
| 99 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(AMI_MOUSE)) |
| 101 | return -ENODEV; |
| 102 | |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 103 | amimouse_dev = input_allocate_device(); |
| 104 | if (!amimouse_dev) |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 105 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 107 | amimouse_dev->name = "Amiga mouse"; |
| 108 | amimouse_dev->phys = "amimouse/input0"; |
| 109 | amimouse_dev->id.bustype = BUS_AMIGA; |
| 110 | amimouse_dev->id.vendor = 0x0001; |
| 111 | amimouse_dev->id.product = 0x0002; |
| 112 | amimouse_dev->id.version = 0x0100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 114 | amimouse_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); |
| 115 | amimouse_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); |
| 116 | amimouse_dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) | |
| 117 | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT); |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 118 | amimouse_dev->open = amimouse_open; |
| 119 | amimouse_dev->close = amimouse_close; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 121 | err = input_register_device(amimouse_dev); |
| 122 | if (err) { |
| 123 | input_free_device(amimouse_dev); |
| 124 | return err; |
| 125 | } |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | static void __exit amimouse_exit(void) |
| 131 | { |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 132 | input_unregister_device(amimouse_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | module_init(amimouse_init); |
| 136 | module_exit(amimouse_exit); |