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> |
Geert Uytterhoeven | 314c926 | 2009-04-05 13:11:28 +0200 | [diff] [blame] | 24 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | #include <asm/irq.h> |
| 27 | #include <asm/setup.h> |
| 28 | #include <asm/system.h> |
| 29 | #include <asm/uaccess.h> |
| 30 | #include <asm/amigahw.h> |
| 31 | #include <asm/amigaints.h> |
| 32 | |
| 33 | MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); |
| 34 | MODULE_DESCRIPTION("Amiga mouse driver"); |
| 35 | MODULE_LICENSE("GPL"); |
| 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | static int amimouse_lastx, amimouse_lasty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Geert Uytterhoeven | 314c926 | 2009-04-05 13:11:28 +0200 | [diff] [blame] | 39 | static irqreturn_t amimouse_interrupt(int irq, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | { |
Geert Uytterhoeven | 314c926 | 2009-04-05 13:11:28 +0200 | [diff] [blame] | 41 | struct input_dev *dev = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | unsigned short joy0dat, potgor; |
| 43 | int nx, ny, dx, dy; |
| 44 | |
Al Viro | b4290a2 | 2006-01-12 01:06:12 -0800 | [diff] [blame] | 45 | joy0dat = amiga_custom.joy0dat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | nx = joy0dat & 0xff; |
| 48 | ny = joy0dat >> 8; |
| 49 | |
| 50 | dx = nx - amimouse_lastx; |
| 51 | dy = ny - amimouse_lasty; |
| 52 | |
| 53 | if (dx < -127) dx = (256 + nx) - amimouse_lastx; |
| 54 | if (dx > 127) dx = (nx - 256) - amimouse_lastx; |
| 55 | if (dy < -127) dy = (256 + ny) - amimouse_lasty; |
| 56 | if (dy > 127) dy = (ny - 256) - amimouse_lasty; |
| 57 | |
| 58 | amimouse_lastx = nx; |
| 59 | amimouse_lasty = ny; |
| 60 | |
Al Viro | b4290a2 | 2006-01-12 01:06:12 -0800 | [diff] [blame] | 61 | potgor = amiga_custom.potgor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Geert Uytterhoeven | 314c926 | 2009-04-05 13:11:28 +0200 | [diff] [blame] | 63 | input_report_rel(dev, REL_X, dx); |
| 64 | input_report_rel(dev, REL_Y, dy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
Geert Uytterhoeven | 314c926 | 2009-04-05 13:11:28 +0200 | [diff] [blame] | 66 | input_report_key(dev, BTN_LEFT, ciaa.pra & 0x40); |
| 67 | input_report_key(dev, BTN_MIDDLE, potgor & 0x0100); |
| 68 | input_report_key(dev, BTN_RIGHT, potgor & 0x0400); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Geert Uytterhoeven | 314c926 | 2009-04-05 13:11:28 +0200 | [diff] [blame] | 70 | input_sync(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
| 72 | return IRQ_HANDLED; |
| 73 | } |
| 74 | |
| 75 | static int amimouse_open(struct input_dev *dev) |
| 76 | { |
| 77 | unsigned short joy0dat; |
Geert Uytterhoeven | 314c926 | 2009-04-05 13:11:28 +0200 | [diff] [blame] | 78 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Al Viro | b4290a2 | 2006-01-12 01:06:12 -0800 | [diff] [blame] | 80 | joy0dat = amiga_custom.joy0dat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
| 82 | amimouse_lastx = joy0dat & 0xff; |
| 83 | amimouse_lasty = joy0dat >> 8; |
| 84 | |
Geert Uytterhoeven | 314c926 | 2009-04-05 13:11:28 +0200 | [diff] [blame] | 85 | error = request_irq(IRQ_AMIGA_VERTB, amimouse_interrupt, 0, "amimouse", |
| 86 | dev); |
| 87 | if (error) |
| 88 | dev_err(&dev->dev, "Can't allocate irq %d\n", IRQ_AMIGA_VERTB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
Geert Uytterhoeven | 314c926 | 2009-04-05 13:11:28 +0200 | [diff] [blame] | 90 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | static void amimouse_close(struct input_dev *dev) |
| 94 | { |
Geert Uytterhoeven | 314c926 | 2009-04-05 13:11:28 +0200 | [diff] [blame] | 95 | free_irq(IRQ_AMIGA_VERTB, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Geert Uytterhoeven | 314c926 | 2009-04-05 13:11:28 +0200 | [diff] [blame] | 98 | static int __init amimouse_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | { |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 100 | int err; |
Geert Uytterhoeven | 314c926 | 2009-04-05 13:11:28 +0200 | [diff] [blame] | 101 | struct input_dev *dev; |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 102 | |
Geert Uytterhoeven | 314c926 | 2009-04-05 13:11:28 +0200 | [diff] [blame] | 103 | dev = input_allocate_device(); |
| 104 | if (!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 | |
Geert Uytterhoeven | 314c926 | 2009-04-05 13:11:28 +0200 | [diff] [blame] | 107 | dev->name = pdev->name; |
| 108 | dev->phys = "amimouse/input0"; |
| 109 | dev->id.bustype = BUS_AMIGA; |
| 110 | dev->id.vendor = 0x0001; |
| 111 | dev->id.product = 0x0002; |
| 112 | dev->id.version = 0x0100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
Geert Uytterhoeven | 314c926 | 2009-04-05 13:11:28 +0200 | [diff] [blame] | 114 | dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); |
| 115 | dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); |
| 116 | dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) | |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 117 | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT); |
Geert Uytterhoeven | 314c926 | 2009-04-05 13:11:28 +0200 | [diff] [blame] | 118 | dev->open = amimouse_open; |
| 119 | dev->close = amimouse_close; |
| 120 | dev->dev.parent = &pdev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Geert Uytterhoeven | 314c926 | 2009-04-05 13:11:28 +0200 | [diff] [blame] | 122 | err = input_register_device(dev); |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 123 | if (err) { |
Geert Uytterhoeven | 314c926 | 2009-04-05 13:11:28 +0200 | [diff] [blame] | 124 | input_free_device(dev); |
Dmitry Torokhov | 7215561 | 2006-11-05 22:40:19 -0500 | [diff] [blame] | 125 | return err; |
| 126 | } |
Dmitry Torokhov | 2e5b636 | 2005-09-15 02:01:44 -0500 | [diff] [blame] | 127 | |
Geert Uytterhoeven | 314c926 | 2009-04-05 13:11:28 +0200 | [diff] [blame] | 128 | platform_set_drvdata(pdev, dev); |
| 129 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | return 0; |
| 131 | } |
| 132 | |
Geert Uytterhoeven | 314c926 | 2009-04-05 13:11:28 +0200 | [diff] [blame] | 133 | static int __exit amimouse_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | { |
Geert Uytterhoeven | 314c926 | 2009-04-05 13:11:28 +0200 | [diff] [blame] | 135 | struct input_dev *dev = platform_get_drvdata(pdev); |
| 136 | |
| 137 | platform_set_drvdata(pdev, NULL); |
| 138 | input_unregister_device(dev); |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | static struct platform_driver amimouse_driver = { |
| 143 | .remove = __exit_p(amimouse_remove), |
| 144 | .driver = { |
| 145 | .name = "amiga-mouse", |
| 146 | .owner = THIS_MODULE, |
| 147 | }, |
| 148 | }; |
| 149 | |
| 150 | static int __init amimouse_init(void) |
| 151 | { |
| 152 | return platform_driver_probe(&amimouse_driver, amimouse_probe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | module_init(amimouse_init); |
Geert Uytterhoeven | 314c926 | 2009-04-05 13:11:28 +0200 | [diff] [blame] | 156 | |
| 157 | static void __exit amimouse_exit(void) |
| 158 | { |
| 159 | platform_driver_unregister(&amimouse_driver); |
| 160 | } |
| 161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | module_exit(amimouse_exit); |
Geert Uytterhoeven | 314c926 | 2009-04-05 13:11:28 +0200 | [diff] [blame] | 163 | |
| 164 | MODULE_ALIAS("platform:amiga-mouse"); |