0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #include <linux/module.h>
0017 #include <linux/init.h>
0018 #include <linux/input.h>
0019 #include <linux/interrupt.h>
0020 #include <linux/platform_device.h>
0021
0022 #include <asm/irq.h>
0023 #include <asm/setup.h>
0024 #include <linux/uaccess.h>
0025 #include <asm/amigahw.h>
0026 #include <asm/amigaints.h>
0027
0028 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
0029 MODULE_DESCRIPTION("Amiga mouse driver");
0030 MODULE_LICENSE("GPL");
0031
0032 static int amimouse_lastx, amimouse_lasty;
0033
0034 static irqreturn_t amimouse_interrupt(int irq, void *data)
0035 {
0036 struct input_dev *dev = data;
0037 unsigned short joy0dat, potgor;
0038 int nx, ny, dx, dy;
0039
0040 joy0dat = amiga_custom.joy0dat;
0041
0042 nx = joy0dat & 0xff;
0043 ny = joy0dat >> 8;
0044
0045 dx = nx - amimouse_lastx;
0046 dy = ny - amimouse_lasty;
0047
0048 if (dx < -127) dx = (256 + nx) - amimouse_lastx;
0049 if (dx > 127) dx = (nx - 256) - amimouse_lastx;
0050 if (dy < -127) dy = (256 + ny) - amimouse_lasty;
0051 if (dy > 127) dy = (ny - 256) - amimouse_lasty;
0052
0053 amimouse_lastx = nx;
0054 amimouse_lasty = ny;
0055
0056 potgor = amiga_custom.potgor;
0057
0058 input_report_rel(dev, REL_X, dx);
0059 input_report_rel(dev, REL_Y, dy);
0060
0061 input_report_key(dev, BTN_LEFT, ciaa.pra & 0x40);
0062 input_report_key(dev, BTN_MIDDLE, potgor & 0x0100);
0063 input_report_key(dev, BTN_RIGHT, potgor & 0x0400);
0064
0065 input_sync(dev);
0066
0067 return IRQ_HANDLED;
0068 }
0069
0070 static int amimouse_open(struct input_dev *dev)
0071 {
0072 unsigned short joy0dat;
0073 int error;
0074
0075 joy0dat = amiga_custom.joy0dat;
0076
0077 amimouse_lastx = joy0dat & 0xff;
0078 amimouse_lasty = joy0dat >> 8;
0079
0080 error = request_irq(IRQ_AMIGA_VERTB, amimouse_interrupt, 0, "amimouse",
0081 dev);
0082 if (error)
0083 dev_err(&dev->dev, "Can't allocate irq %d\n", IRQ_AMIGA_VERTB);
0084
0085 return error;
0086 }
0087
0088 static void amimouse_close(struct input_dev *dev)
0089 {
0090 free_irq(IRQ_AMIGA_VERTB, dev);
0091 }
0092
0093 static int __init amimouse_probe(struct platform_device *pdev)
0094 {
0095 int err;
0096 struct input_dev *dev;
0097
0098 dev = input_allocate_device();
0099 if (!dev)
0100 return -ENOMEM;
0101
0102 dev->name = pdev->name;
0103 dev->phys = "amimouse/input0";
0104 dev->id.bustype = BUS_AMIGA;
0105 dev->id.vendor = 0x0001;
0106 dev->id.product = 0x0002;
0107 dev->id.version = 0x0100;
0108
0109 dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
0110 dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
0111 dev->keybit[BIT_WORD(BTN_LEFT)] = BIT_MASK(BTN_LEFT) |
0112 BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
0113 dev->open = amimouse_open;
0114 dev->close = amimouse_close;
0115 dev->dev.parent = &pdev->dev;
0116
0117 err = input_register_device(dev);
0118 if (err) {
0119 input_free_device(dev);
0120 return err;
0121 }
0122
0123 platform_set_drvdata(pdev, dev);
0124
0125 return 0;
0126 }
0127
0128 static int __exit amimouse_remove(struct platform_device *pdev)
0129 {
0130 struct input_dev *dev = platform_get_drvdata(pdev);
0131
0132 input_unregister_device(dev);
0133 return 0;
0134 }
0135
0136 static struct platform_driver amimouse_driver = {
0137 .remove = __exit_p(amimouse_remove),
0138 .driver = {
0139 .name = "amiga-mouse",
0140 },
0141 };
0142
0143 module_platform_driver_probe(amimouse_driver, amimouse_probe);
0144
0145 MODULE_ALIAS("platform:amiga-mouse");