X-Git-Url: http://pilppa.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=drivers%2Finput%2Fkeyboard%2Flocomokbd.c;h=9caed30f3bbba29203377d45e61e633a21cfec7f;hb=44e7ed396114a0c43bb2494877aceeb7782e084a;hp=2c510881874ab70e5827bee15619286872542ed4;hpb=ad8f76be48d817b48222411ae16a7dfe257bdb24;p=linux-2.6-omap-h63xx.git diff --git a/drivers/input/keyboard/locomokbd.c b/drivers/input/keyboard/locomokbd.c index 2c510881874..9caed30f3bb 100644 --- a/drivers/input/keyboard/locomokbd.c +++ b/drivers/input/keyboard/locomokbd.c @@ -1,14 +1,12 @@ /* - * Copyright (c) 2005 John Lenz + * LoCoMo keyboard driver for Linux-based ARM PDAs: + * - SHARP Zaurus Collie (SL-5500) + * - SHARP Zaurus Poodle (SL-5600) * + * Copyright (c) 2005 John Lenz * Based on from xtkbd.c - */ - -/* - * LoCoMo keyboard driver for Linux/ARM - */ - -/* + * + * * 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 @@ -25,7 +23,6 @@ * */ -#include #include #include #include @@ -48,7 +45,8 @@ MODULE_LICENSE("GPL"); #define KEY_CONTACT KEY_F18 #define KEY_CENTER KEY_F15 -static unsigned char locomokbd_keycode[LOCOMOKBD_NUMKEYS] = { +static const unsigned char +locomokbd_keycode[LOCOMOKBD_NUMKEYS] __devinitconst = { 0, KEY_ESC, KEY_ACTIVITY, 0, 0, 0, 0, 0, 0, 0, /* 0 - 9 */ 0, 0, 0, 0, 0, 0, 0, KEY_MENU, KEY_HOME, KEY_CONTACT, /* 10 - 19 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 20 - 29 */ @@ -68,22 +66,21 @@ static unsigned char locomokbd_keycode[LOCOMOKBD_NUMKEYS] = { #define KB_COLS 8 #define KB_ROWMASK(r) (1 << (r)) #define SCANCODE(c,r) ( ((c)<<4) + (r) + 1 ) -#define NR_SCANCODES 128 #define KB_DELAY 8 #define SCAN_INTERVAL (HZ/10) -#define LOCOMOKBD_PRESSED 1 struct locomokbd { unsigned char keycode[LOCOMOKBD_NUMKEYS]; struct input_dev *input; char phys[32]; - struct locomo_dev *ldev; unsigned long base; spinlock_t lock; struct timer_list timer; + unsigned long suspend_jiffies; + unsigned int count_cancel; }; /* helper functions for reading the keyboard matrix */ @@ -127,17 +124,15 @@ static inline void locomokbd_reset_col(unsigned long membase, int col) */ /* Scan the hardware keyboard and push any changes up through the input layer */ -static void locomokbd_scankeyboard(struct locomokbd *locomokbd, struct pt_regs *regs) +static void locomokbd_scankeyboard(struct locomokbd *locomokbd) { - unsigned int row, col, rowd, scancode; + unsigned int row, col, rowd; unsigned long flags; unsigned int num_pressed; unsigned long membase = locomokbd->base; spin_lock_irqsave(&locomokbd->lock, flags); - input_regs(locomokbd->input, regs); - locomokbd_charge_all(membase); num_pressed = 0; @@ -148,13 +143,33 @@ static void locomokbd_scankeyboard(struct locomokbd *locomokbd, struct pt_regs * rowd = ~locomo_readl(membase + LOCOMO_KIB); for (row = 0; row < KB_ROWS; row++) { + unsigned int scancode, pressed, key; + scancode = SCANCODE(col, row); - if (rowd & KB_ROWMASK(row)) { - num_pressed += 1; - input_report_key(locomokbd->input, locomokbd->keycode[scancode], 1); - } else { - input_report_key(locomokbd->input, locomokbd->keycode[scancode], 0); - } + pressed = rowd & KB_ROWMASK(row); + key = locomokbd->keycode[scancode]; + + input_report_key(locomokbd->input, key, pressed); + if (likely(!pressed)) + continue; + + num_pressed++; + + /* The "Cancel/ESC" key is labeled "On/Off" on + * Collie and Poodle and should suspend the device + * if it was pressed for more than a second. */ + if (unlikely(key == KEY_ESC)) { + if (!time_after(jiffies, + locomokbd->suspend_jiffies + HZ)) + continue; + if (locomokbd->count_cancel++ + != (HZ/SCAN_INTERVAL + 1)) + continue; + input_event(locomokbd->input, EV_PWR, + KEY_SUSPEND, 1); + locomokbd->suspend_jiffies = jiffies; + } else + locomokbd->count_cancel = 0; } locomokbd_reset_col(membase, col); } @@ -165,6 +180,8 @@ static void locomokbd_scankeyboard(struct locomokbd *locomokbd, struct pt_regs * /* if any keys are pressed, enable the timer */ if (num_pressed) mod_timer(&locomokbd->timer, jiffies + SCAN_INTERVAL); + else + locomokbd->count_cancel = 0; spin_unlock_irqrestore(&locomokbd->lock, flags); } @@ -172,13 +189,13 @@ static void locomokbd_scankeyboard(struct locomokbd *locomokbd, struct pt_regs * /* * LoCoMo keyboard interrupt handler. */ -static irqreturn_t locomokbd_interrupt(int irq, void *dev_id, struct pt_regs *regs) +static irqreturn_t locomokbd_interrupt(int irq, void *dev_id) { struct locomokbd *locomokbd = dev_id; /** wait chattering delay **/ udelay(100); - locomokbd_scankeyboard(locomokbd, regs); + locomokbd_scankeyboard(locomokbd); return IRQ_HANDLED; } @@ -189,32 +206,32 @@ static irqreturn_t locomokbd_interrupt(int irq, void *dev_id, struct pt_regs *re static void locomokbd_timer_callback(unsigned long data) { struct locomokbd *locomokbd = (struct locomokbd *) data; - locomokbd_scankeyboard(locomokbd, NULL); + + locomokbd_scankeyboard(locomokbd); } -static int locomokbd_probe(struct locomo_dev *dev) +static int __devinit locomokbd_probe(struct locomo_dev *dev) { struct locomokbd *locomokbd; struct input_dev *input_dev; - int i, ret; + int i, err; locomokbd = kzalloc(sizeof(struct locomokbd), GFP_KERNEL); input_dev = input_allocate_device(); if (!locomokbd || !input_dev) { - ret = -ENOMEM; - goto free; + err = -ENOMEM; + goto err_free_mem; } /* try and claim memory region */ if (!request_mem_region((unsigned long) dev->mapbase, dev->length, LOCOMO_DRIVER_NAME(dev))) { - ret = -EBUSY; + err = -EBUSY; printk(KERN_ERR "locomokbd: Can't acquire access to io memory for keyboard\n"); - goto free; + goto err_free_mem; } - locomokbd->ldev = dev; locomo_set_drvdata(dev, locomokbd); locomokbd->base = (unsigned long) dev->mapbase; @@ -225,6 +242,8 @@ static int locomokbd_probe(struct locomo_dev *dev) locomokbd->timer.function = locomokbd_timer_callback; locomokbd->timer.data = (unsigned long) locomokbd; + locomokbd->suspend_jiffies = jiffies; + locomokbd->input = input_dev; strcpy(locomokbd->phys, "locomokbd/input0"); @@ -234,11 +253,12 @@ static int locomokbd_probe(struct locomo_dev *dev) input_dev->id.vendor = 0x0001; input_dev->id.product = 0x0001; input_dev->id.version = 0x0100; - input_dev->private = locomokbd; + input_dev->dev.parent = &dev->dev; - input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP); + input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) | + BIT_MASK(EV_PWR); input_dev->keycode = locomokbd->keycode; - input_dev->keycodesize = sizeof(unsigned char); + input_dev->keycodesize = sizeof(locomokbd_keycode[0]); input_dev->keycodemax = ARRAY_SIZE(locomokbd_keycode); memcpy(locomokbd->keycode, locomokbd_keycode, sizeof(locomokbd->keycode)); @@ -247,27 +267,31 @@ static int locomokbd_probe(struct locomo_dev *dev) clear_bit(0, input_dev->keybit); /* attempt to get the interrupt */ - ret = request_irq(dev->irq[0], locomokbd_interrupt, 0, "locomokbd", locomokbd); - if (ret) { + err = request_irq(dev->irq[0], locomokbd_interrupt, 0, "locomokbd", locomokbd); + if (err) { printk(KERN_ERR "locomokbd: Can't get irq for keyboard\n"); - goto out; + goto err_release_region; } - input_register_device(locomokbd->input); + err = input_register_device(locomokbd->input); + if (err) + goto err_free_irq; return 0; -out: + err_free_irq: + free_irq(dev->irq[0], locomokbd); + err_release_region: release_mem_region((unsigned long) dev->mapbase, dev->length); locomo_set_drvdata(dev, NULL); -free: + err_free_mem: input_free_device(input_dev); kfree(locomokbd); - return ret; + return err; } -static int locomokbd_remove(struct locomo_dev *dev) +static int __devexit locomokbd_remove(struct locomo_dev *dev) { struct locomokbd *locomokbd = locomo_get_drvdata(dev); @@ -291,7 +315,7 @@ static struct locomo_driver keyboard_driver = { }, .devid = LOCOMO_DEVID_KEYBOARD, .probe = locomokbd_probe, - .remove = locomokbd_remove, + .remove = __devexit_p(locomokbd_remove), }; static int __init locomokbd_init(void)