From a97e148a8b8da8b04bc3e18ceb824a8f5f56d567 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Tue, 6 Sep 2005 15:18:33 -0700 Subject: [PATCH] input: convert kcalloc to kzalloc This patch converts kcalloc(1, ...) calls to use the new kzalloc() function. Signed-off-by: Pekka Enberg Cc: Vojtech Pavlik Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/input/keyboard/corgikbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/input/keyboard') diff --git a/drivers/input/keyboard/corgikbd.c b/drivers/input/keyboard/corgikbd.c index a8551711e8d..7719bdfa9ee 100644 --- a/drivers/input/keyboard/corgikbd.c +++ b/drivers/input/keyboard/corgikbd.c @@ -260,7 +260,7 @@ static int __init corgikbd_probe(struct device *dev) int i; struct corgikbd *corgikbd; - corgikbd = kcalloc(1, sizeof(struct corgikbd), GFP_KERNEL); + corgikbd = kzalloc(sizeof(struct corgikbd), GFP_KERNEL); if (!corgikbd) return -ENOMEM; -- cgit v1.2.3 From aba5a4c055dde13a3cece53e1b4b060294d631ed Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Tue, 6 Sep 2005 15:18:59 -0700 Subject: [PATCH] Corgi Keyboard: Fix a couple of compile errors Fix a couple of compile errors in the corgi keyboard driver. Signed-off-by: Richard Purdie Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/input/keyboard/corgikbd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/input/keyboard') diff --git a/drivers/input/keyboard/corgikbd.c b/drivers/input/keyboard/corgikbd.c index 7719bdfa9ee..a31c3d64af3 100644 --- a/drivers/input/keyboard/corgikbd.c +++ b/drivers/input/keyboard/corgikbd.c @@ -235,7 +235,7 @@ static void corgikbd_hinge_timer(unsigned long data) unsigned long gprr; unsigned long flags; - gprr = read_scoop_reg(SCOOP_GPRR) & (CORGI_SCP_SWA | CORGI_SCP_SWB); + gprr = read_scoop_reg(&corgiscoop_device.dev, SCOOP_GPRR) & (CORGI_SCP_SWA | CORGI_SCP_SWB); if (gprr != sharpsl_hinge_state) { hinge_count = 0; sharpsl_hinge_state = gprr; @@ -267,7 +267,7 @@ static int __init corgikbd_probe(struct device *dev) dev_set_drvdata(dev,corgikbd); strcpy(corgikbd->phys, "corgikbd/input0"); - spin_lock_init(corgikbd->lock); + spin_lock_init(&corgikbd->lock); /* Init Keyboard rescan timer */ init_timer(&corgikbd->timer); -- cgit v1.2.3 From 8240a4a4bc95814502da522d5ee929fe0f0dc679 Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Tue, 6 Sep 2005 15:18:59 -0700 Subject: [PATCH] Corgi Keyboard: Add some power management code Add some power management code to the corgi keyboard driver so that only one power event gets reported within any reasonable time frame and the driver doesn't enter an infinte loop due to key repeat. Signed-off-by: Richard Purdie Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/input/keyboard/corgikbd.c | 42 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'drivers/input/keyboard') diff --git a/drivers/input/keyboard/corgikbd.c b/drivers/input/keyboard/corgikbd.c index a31c3d64af3..43d6edb3cf0 100644 --- a/drivers/input/keyboard/corgikbd.c +++ b/drivers/input/keyboard/corgikbd.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -78,6 +79,9 @@ struct corgikbd { struct timer_list timer; struct timer_list htimer; + + unsigned int suspended; + unsigned long suspend_jiffies; }; static void handle_scancode(unsigned int pressed,unsigned int scancode, struct corgikbd *corgikbd_data) @@ -85,8 +89,11 @@ static void handle_scancode(unsigned int pressed,unsigned int scancode, struct c if (pressed && !(corgikbd_data->state[scancode] & CORGIKBD_PRESSED)) { corgikbd_data->state[scancode] |= CORGIKBD_PRESSED; input_report_key(&corgikbd_data->input, corgikbd_data->keycode[scancode], 1); - if (corgikbd_data->keycode[scancode] == CORGI_KEY_OFF) + if ((corgikbd_data->keycode[scancode] == CORGI_KEY_OFF) + && time_after(jiffies, corgikbd_data->suspend_jiffies + HZ)) { input_event(&corgikbd_data->input, EV_PWR, CORGI_KEY_OFF, 1); + corgikbd_data->suspend_jiffies=jiffies; + } } else if (!pressed && corgikbd_data->state[scancode] & CORGIKBD_PRESSED) { corgikbd_data->state[scancode] &= ~CORGIKBD_PRESSED; input_report_key(&corgikbd_data->input, corgikbd_data->keycode[scancode], 0); @@ -153,6 +160,9 @@ static void corgikbd_scankeyboard(struct corgikbd *corgikbd_data, struct pt_regs unsigned long flags; unsigned int num_pressed; + if (corgikbd_data->suspended) + return; + spin_lock_irqsave(&corgikbd_data->lock, flags); if (regs) @@ -255,6 +265,32 @@ static void corgikbd_hinge_timer(unsigned long data) mod_timer(&corgikbd_data->htimer, jiffies + HINGE_SCAN_INTERVAL); } +#ifdef CONFIG_PM +static int corgikbd_suspend(struct device *dev, pm_message_t state, uint32_t level) +{ + if (level == SUSPEND_POWER_DOWN) { + struct corgikbd *corgikbd = dev_get_drvdata(dev); + corgikbd->suspended = 1; + } + return 0; +} + +static int corgikbd_resume(struct device *dev, uint32_t level) +{ + if (level == RESUME_POWER_ON) { + struct corgikbd *corgikbd = dev_get_drvdata(dev); + + /* Upon resume, ignore the suspend key for a short while */ + corgikbd->suspend_jiffies=jiffies; + corgikbd->suspended = 0; + } + return 0; +} +#else +#define corgikbd_suspend NULL +#define corgikbd_resume NULL +#endif + static int __init corgikbd_probe(struct device *dev) { int i; @@ -279,6 +315,8 @@ static int __init corgikbd_probe(struct device *dev) corgikbd->htimer.function = corgikbd_hinge_timer; corgikbd->htimer.data = (unsigned long) corgikbd; + corgikbd->suspend_jiffies=jiffies; + init_input_dev(&corgikbd->input); corgikbd->input.private = corgikbd; corgikbd->input.name = "Corgi Keyboard"; @@ -343,6 +381,8 @@ static struct device_driver corgikbd_driver = { .bus = &platform_bus_type, .probe = corgikbd_probe, .remove = corgikbd_remove, + .suspend = corgikbd_suspend, + .resume = corgikbd_resume, }; static int __devinit corgikbd_init(void) -- cgit v1.2.3 From 948e12f0bd51db439659fed857971e22fbdd7527 Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Tue, 6 Sep 2005 15:19:00 -0700 Subject: [PATCH] Corgi Keyboard: Code tidying The input system handles key state tracking so there's no need for the driver to do so as well. Also tidy up some comment formatting and remove a now unneeded function. Signed-off-by: Richard Purdie Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/input/keyboard/corgikbd.c | 61 ++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 33 deletions(-) (limited to 'drivers/input/keyboard') diff --git a/drivers/input/keyboard/corgikbd.c b/drivers/input/keyboard/corgikbd.c index 43d6edb3cf0..767e853dd76 100644 --- a/drivers/input/keyboard/corgikbd.c +++ b/drivers/input/keyboard/corgikbd.c @@ -33,7 +33,6 @@ /* zero code, 124 scancodes + 3 hinge combinations */ #define NR_SCANCODES ( SCANCODE(KB_ROWS-1,KB_COLS-1) +1 +1 +3 ) #define SCAN_INTERVAL (HZ/10) -#define CORGIKBD_PRESSED 1 #define HINGE_SCAN_INTERVAL (HZ/4) @@ -74,9 +73,7 @@ struct corgikbd { struct input_dev input; char phys[32]; - unsigned char state[ARRAY_SIZE(corgikbd_keycode)]; spinlock_t lock; - struct timer_list timer; struct timer_list htimer; @@ -84,22 +81,6 @@ struct corgikbd { unsigned long suspend_jiffies; }; -static void handle_scancode(unsigned int pressed,unsigned int scancode, struct corgikbd *corgikbd_data) -{ - if (pressed && !(corgikbd_data->state[scancode] & CORGIKBD_PRESSED)) { - corgikbd_data->state[scancode] |= CORGIKBD_PRESSED; - input_report_key(&corgikbd_data->input, corgikbd_data->keycode[scancode], 1); - if ((corgikbd_data->keycode[scancode] == CORGI_KEY_OFF) - && time_after(jiffies, corgikbd_data->suspend_jiffies + HZ)) { - input_event(&corgikbd_data->input, EV_PWR, CORGI_KEY_OFF, 1); - corgikbd_data->suspend_jiffies=jiffies; - } - } else if (!pressed && corgikbd_data->state[scancode] & CORGIKBD_PRESSED) { - corgikbd_data->state[scancode] &= ~CORGIKBD_PRESSED; - input_report_key(&corgikbd_data->input, corgikbd_data->keycode[scancode], 0); - } -} - #define KB_DISCHARGE_DELAY 10 #define KB_ACTIVATE_DELAY 10 @@ -112,36 +93,36 @@ static void handle_scancode(unsigned int pressed,unsigned int scancode, struct c */ static inline void corgikbd_discharge_all(void) { - // STROBE All HiZ + /* STROBE All HiZ */ GPCR2 = CORGI_GPIO_ALL_STROBE_BIT; GPDR2 &= ~CORGI_GPIO_ALL_STROBE_BIT; } static inline void corgikbd_activate_all(void) { - // STROBE ALL -> High + /* STROBE ALL -> High */ GPSR2 = CORGI_GPIO_ALL_STROBE_BIT; GPDR2 |= CORGI_GPIO_ALL_STROBE_BIT; udelay(KB_DISCHARGE_DELAY); - // Clear any interrupts we may have triggered when altering the GPIO lines + /* Clear any interrupts we may have triggered when altering the GPIO lines */ GEDR1 = CORGI_GPIO_HIGH_SENSE_BIT; GEDR2 = CORGI_GPIO_LOW_SENSE_BIT; } static inline void corgikbd_activate_col(int col) { - // STROBE col -> High, not col -> HiZ + /* STROBE col -> High, not col -> HiZ */ GPSR2 = CORGI_GPIO_STROBE_BIT(col); GPDR2 = (GPDR2 & ~CORGI_GPIO_ALL_STROBE_BIT) | CORGI_GPIO_STROBE_BIT(col); } static inline void corgikbd_reset_col(int col) { - // STROBE col -> Low + /* STROBE col -> Low */ GPCR2 = CORGI_GPIO_STROBE_BIT(col); - // STROBE col -> out, not col -> HiZ + /* STROBE col -> out, not col -> HiZ */ GPDR2 = (GPDR2 & ~CORGI_GPIO_ALL_STROBE_BIT) | CORGI_GPIO_STROBE_BIT(col); } @@ -156,7 +137,7 @@ static inline void corgikbd_reset_col(int col) /* Scan the hardware keyboard and push any changes up through the input layer */ static void corgikbd_scankeyboard(struct corgikbd *corgikbd_data, struct pt_regs *regs) { - unsigned int row, col, rowd, scancode; + unsigned int row, col, rowd; unsigned long flags; unsigned int num_pressed; @@ -183,10 +164,21 @@ static void corgikbd_scankeyboard(struct corgikbd *corgikbd_data, struct pt_regs rowd = GET_ROWS_STATUS(col); for (row = 0; row < KB_ROWS; row++) { + unsigned int scancode, pressed; + scancode = SCANCODE(row, col); - handle_scancode((rowd & KB_ROWMASK(row)), scancode, corgikbd_data); - if (rowd & KB_ROWMASK(row)) + pressed = rowd & KB_ROWMASK(row); + + input_report_key(&corgikbd_data->input, corgikbd_data->keycode[scancode], pressed); + + if (pressed) num_pressed++; + + if (pressed && (corgikbd_data->keycode[scancode] == CORGI_KEY_OFF) + && time_after(jiffies, corgikbd_data->suspend_jiffies + HZ)) { + input_event(&corgikbd_data->input, EV_PWR, CORGI_KEY_OFF, 1); + corgikbd_data->suspend_jiffies=jiffies; + } } corgikbd_reset_col(col); } @@ -231,8 +223,11 @@ static void corgikbd_timer_callback(unsigned long data) * The hinge switches generate no interrupt so they need to be * monitored by a timer. * - * When we detect changes, we debounce it and then pass the three - * positions the system can take as keypresses to the input system. + * We debounce the switches and pass them to the input system. + * + * gprr == 0x00 - Keyboard with Landscape Screen + * 0x08 - No Keyboard with Portrait Screen + * 0x0c - Keyboard and Screen Closed */ #define HINGE_STABLE_COUNT 2 @@ -254,9 +249,9 @@ static void corgikbd_hinge_timer(unsigned long data) if (hinge_count >= HINGE_STABLE_COUNT) { spin_lock_irqsave(&corgikbd_data->lock, flags); - handle_scancode((sharpsl_hinge_state == 0x00), 125, corgikbd_data); /* Keyboard with Landscape Screen */ - handle_scancode((sharpsl_hinge_state == 0x08), 126, corgikbd_data); /* No Keyboard with Portrait Screen */ - handle_scancode((sharpsl_hinge_state == 0x0c), 127, corgikbd_data); /* Keyboard and Screen Closed */ + input_report_key(&corgikbd_data->input, corgikbd_data->keycode[125], (sharpsl_hinge_state == 0x00)); + input_report_key(&corgikbd_data->input, corgikbd_data->keycode[126], (sharpsl_hinge_state == 0x08)); + input_report_key(&corgikbd_data->input, corgikbd_data->keycode[127], (sharpsl_hinge_state == 0x0c)); input_sync(&corgikbd_data->input); spin_unlock_irqrestore(&corgikbd_data->lock, flags); -- cgit v1.2.3 From 3158106685acac8f8d4e74a17b974f160fe77c0b Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Tue, 6 Sep 2005 15:19:06 -0700 Subject: [PATCH] Input: Add a new switch event type The corgi keyboard has need of a switch event type with slightly type to the input system as recommended by the input maintainer. Signed-off-by: Richard Purdie Cc: Vojtech Pavlik Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/input/keyboard/corgikbd.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'drivers/input/keyboard') diff --git a/drivers/input/keyboard/corgikbd.c b/drivers/input/keyboard/corgikbd.c index 767e853dd76..cd4b6e79501 100644 --- a/drivers/input/keyboard/corgikbd.c +++ b/drivers/input/keyboard/corgikbd.c @@ -249,9 +249,8 @@ static void corgikbd_hinge_timer(unsigned long data) if (hinge_count >= HINGE_STABLE_COUNT) { spin_lock_irqsave(&corgikbd_data->lock, flags); - input_report_key(&corgikbd_data->input, corgikbd_data->keycode[125], (sharpsl_hinge_state == 0x00)); - input_report_key(&corgikbd_data->input, corgikbd_data->keycode[126], (sharpsl_hinge_state == 0x08)); - input_report_key(&corgikbd_data->input, corgikbd_data->keycode[127], (sharpsl_hinge_state == 0x0c)); + input_report_switch(&corgikbd_data->input, SW_0, ((sharpsl_hinge_state & CORGI_SCP_SWA) != 0)); + input_report_switch(&corgikbd_data->input, SW_1, ((sharpsl_hinge_state & CORGI_SCP_SWB) != 0)); input_sync(&corgikbd_data->input); spin_unlock_irqrestore(&corgikbd_data->lock, flags); @@ -321,7 +320,7 @@ static int __init corgikbd_probe(struct device *dev) corgikbd->input.id.vendor = 0x0001; corgikbd->input.id.product = 0x0001; corgikbd->input.id.version = 0x0100; - corgikbd->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REP) | BIT(EV_PWR); + corgikbd->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REP) | BIT(EV_PWR) | BIT(EV_SW); corgikbd->input.keycode = corgikbd->keycode; corgikbd->input.keycodesize = sizeof(unsigned char); corgikbd->input.keycodemax = ARRAY_SIZE(corgikbd_keycode); @@ -330,6 +329,8 @@ static int __init corgikbd_probe(struct device *dev) for (i = 0; i < ARRAY_SIZE(corgikbd_keycode); i++) set_bit(corgikbd->keycode[i], corgikbd->input.keybit); clear_bit(0, corgikbd->input.keybit); + set_bit(SW_0, corgikbd->input.swbit); + set_bit(SW_1, corgikbd->input.swbit); input_register_device(&corgikbd->input); mod_timer(&corgikbd->htimer, jiffies + HINGE_SCAN_INTERVAL); -- cgit v1.2.3