/* * Copyright (c) 2008 Néstor Amigo Cairo, based on * Copyright (c) 2000 Justin Cormack */ /* * Samko encoder driver for Linux */ /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Should you need to contact me, the author, you can do so by * e-mail - mail your message to . */ #include #include #include #include #include #define DRIVER_DESC "Samko Serial Encoder controller device input driver" MODULE_AUTHOR("Néstor Amigo Cairo "); MODULE_DESCRIPTION(DRIVER_DESC); MODULE_LICENSE("GPL"); #define SERIO_SAM 0x36 #define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) static unsigned char nkbd_keycode[256] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; struct nkbd { unsigned char keycode[256]; struct input_dev *dev; struct serio *serio; char phys[32]; }; static irqreturn_t nkbd_interrupt(struct serio *serio, unsigned char data, unsigned int flags) { struct nkbd *nkbd = serio_get_drvdata(serio); /* invalid scan codes are probably the init sequence, so we ignore them */ //if (nkbd->keycode[data]) { if ((int)data == 217) // Then, left key is pressed { input_report_key(nkbd->dev, KEY_LEFTSHIFT, 1); input_report_key(nkbd->dev, KEY_TAB, 1); input_report_key(nkbd->dev, KEY_TAB, 0); input_report_key(nkbd->dev, KEY_LEFTSHIFT, 0); input_sync(nkbd->dev); printk(KERN_INFO "Samko's Left Key: 96\n"); } else if ((int)data == 200) // Then, center key is pressed { input_report_key(nkbd->dev, KEY_A, 1); input_report_key(nkbd->dev, KEY_A, 0); input_sync(nkbd->dev); printk(KERN_INFO "Samko's Center Key: 32\n"); } else if ((int)data == 208) // Then, right key is pressed { input_report_key(nkbd->dev, KEY_TAB, 1); input_report_key(nkbd->dev, KEY_TAB, 0); input_sync(nkbd->dev); printk(KERN_INFO "Samko's Right Key: 80\n"); } else { printk(KERN_INFO "Samko's Key pressed: %i\n",(int)data); } //} //else if (data == 0xe7) /* end of init sequence */ // printk(KERN_INFO "input: %s on %s\n", nkbd->dev->name, serio->phys); //else //{ // printk(KERN_INFO "Samko's Key pressed (other situation): %i\n",(int)data); //} return IRQ_HANDLED; } static int nkbd_connect(struct serio *serio, struct serio_driver *drv) { struct nkbd *nkbd; struct input_dev *input_dev; int err = -ENOMEM; int i; nkbd = kzalloc(sizeof(struct nkbd), GFP_KERNEL); input_dev = input_allocate_device(); if (!nkbd || !input_dev) goto fail1; nkbd->serio = serio; nkbd->dev = input_dev; snprintf(nkbd->phys, sizeof(nkbd->phys), "%s/input0", serio->phys); memcpy(nkbd->keycode, nkbd_keycode, sizeof(nkbd->keycode)); input_dev->name = "Samko Serial Encoder Device"; input_dev->phys = nkbd->phys; input_dev->id.bustype = BUS_RS232; input_dev->id.vendor = SERIO_SAM; input_dev->id.product = 0x0001; input_dev->id.version = 0x0100; input_dev->dev.parent = &serio->dev; input_dev->evbit[0] = BIT_MASK(EV_KEY); input_dev->keycode = nkbd->keycode; input_dev->keycodesize = sizeof(unsigned char); input_dev->keycodemax = sizeof(nkbd_keycode); for (i = 0; i < 255; i++) set_bit(nkbd->keycode[i], input_dev->keybit); clear_bit(0, input_dev->keybit); serio_set_drvdata(serio, nkbd); err = serio_open(serio, drv); if (err) goto fail2; err = input_register_device(nkbd->dev); if (err) goto fail3; return 0; fail3: serio_close(serio); fail2: serio_set_drvdata(serio, NULL); fail1: input_free_device(input_dev); kfree(nkbd); return err; } static void nkbd_disconnect(struct serio *serio) { struct nkbd *nkbd = serio_get_drvdata(serio); serio_close(serio); serio_set_drvdata(serio, NULL); input_unregister_device(nkbd->dev); kfree(nkbd); } static struct serio_device_id nkbd_serio_ids[] = { { .type = SERIO_RS232, .proto = SERIO_SAM, .id = SERIO_ANY, .extra = SERIO_ANY, }, { 0 } }; MODULE_DEVICE_TABLE(serio, nkbd_serio_ids); static struct serio_driver nkbd_drv = { .driver = { .name = "serenc", }, .description = DRIVER_DESC, .id_table = nkbd_serio_ids, .interrupt = nkbd_interrupt, .connect = nkbd_connect, .disconnect = nkbd_disconnect, //.write = tty_write, }; static int __init nkbd_init(void) { return serio_register_driver(&nkbd_drv); } static void __exit nkbd_exit(void) { serio_unregister_driver(&nkbd_drv); } module_init(nkbd_init); module_exit(nkbd_exit);