Skip to content

Commit e6cdd15

Browse files
hdellerdtor
authored andcommitted
Input: locomokbd - add 'off' button support for Sharp Collie/Poodle
Enables the Sharp Zaurus Collie and Poodle devices to be turned off by pressing the "Cancel" button for a few seconds (as designed by Sharp). Additional small cleanups: - removal of unused #defines and variables - add missing __devinit/__devexit/__devinitconst annotations - reorganized copyright notice Signed-off-by: Helge Deller <deller@gmx.de> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
1 parent 3797fec commit e6cdd15

1 file changed

Lines changed: 48 additions & 25 deletions

File tree

‎drivers/input/keyboard/locomokbd.c‎

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
/*
2-
* Copyright (c) 2005 John Lenz
2+
* LoCoMo keyboard driver for Linux-based ARM PDAs:
3+
* - SHARP Zaurus Collie (SL-5500)
4+
* - SHARP Zaurus Poodle (SL-5600)
35
*
6+
* Copyright (c) 2005 John Lenz
47
* Based on from xtkbd.c
5-
*/
6-
7-
/*
8-
* LoCoMo keyboard driver for Linux/ARM
9-
*/
10-
11-
/*
8+
*
9+
*
1210
* This program is free software; you can redistribute it and/or modify
1311
* it under the terms of the GNU General Public License as published by
1412
* the Free Software Foundation; either version 2 of the License, or
@@ -47,7 +45,8 @@ MODULE_LICENSE("GPL");
4745
#define KEY_CONTACT KEY_F18
4846
#define KEY_CENTER KEY_F15
4947

50-
static unsigned char locomokbd_keycode[LOCOMOKBD_NUMKEYS] = {
48+
static const unsigned char
49+
locomokbd_keycode[LOCOMOKBD_NUMKEYS] __devinitconst = {
5150
0, KEY_ESC, KEY_ACTIVITY, 0, 0, 0, 0, 0, 0, 0, /* 0 - 9 */
5251
0, 0, 0, 0, 0, 0, 0, KEY_MENU, KEY_HOME, KEY_CONTACT, /* 10 - 19 */
5352
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 20 - 29 */
@@ -67,22 +66,21 @@ static unsigned char locomokbd_keycode[LOCOMOKBD_NUMKEYS] = {
6766
#define KB_COLS 8
6867
#define KB_ROWMASK(r) (1 << (r))
6968
#define SCANCODE(c,r) ( ((c)<<4) + (r) + 1 )
70-
#define NR_SCANCODES 128
7169

7270
#define KB_DELAY 8
7371
#define SCAN_INTERVAL (HZ/10)
74-
#define LOCOMOKBD_PRESSED 1
7572

7673
struct locomokbd {
7774
unsigned char keycode[LOCOMOKBD_NUMKEYS];
7875
struct input_dev *input;
7976
char phys[32];
8077

81-
struct locomo_dev *ldev;
8278
unsigned long base;
8379
spinlock_t lock;
8480

8581
struct timer_list timer;
82+
unsigned long suspend_jiffies;
83+
unsigned int count_cancel;
8684
};
8785

8886
/* helper functions for reading the keyboard matrix */
@@ -128,7 +126,7 @@ static inline void locomokbd_reset_col(unsigned long membase, int col)
128126
/* Scan the hardware keyboard and push any changes up through the input layer */
129127
static void locomokbd_scankeyboard(struct locomokbd *locomokbd)
130128
{
131-
unsigned int row, col, rowd, scancode;
129+
unsigned int row, col, rowd;
132130
unsigned long flags;
133131
unsigned int num_pressed;
134132
unsigned long membase = locomokbd->base;
@@ -145,13 +143,33 @@ static void locomokbd_scankeyboard(struct locomokbd *locomokbd)
145143

146144
rowd = ~locomo_readl(membase + LOCOMO_KIB);
147145
for (row = 0; row < KB_ROWS; row++) {
146+
unsigned int scancode, pressed, key;
147+
148148
scancode = SCANCODE(col, row);
149-
if (rowd & KB_ROWMASK(row)) {
150-
num_pressed += 1;
151-
input_report_key(locomokbd->input, locomokbd->keycode[scancode], 1);
152-
} else {
153-
input_report_key(locomokbd->input, locomokbd->keycode[scancode], 0);
154-
}
149+
pressed = rowd & KB_ROWMASK(row);
150+
key = locomokbd->keycode[scancode];
151+
152+
input_report_key(locomokbd->input, key, pressed);
153+
if (likely(!pressed))
154+
continue;
155+
156+
num_pressed++;
157+
158+
/* The "Cancel/ESC" key is labeled "On/Off" on
159+
* Collie and Poodle and should suspend the device
160+
* if it was pressed for more than a second. */
161+
if (unlikely(key == KEY_ESC)) {
162+
if (!time_after(jiffies,
163+
locomokbd->suspend_jiffies + HZ))
164+
continue;
165+
if (locomokbd->count_cancel++
166+
!= (HZ/SCAN_INTERVAL + 1))
167+
continue;
168+
input_event(locomokbd->input, EV_PWR,
169+
KEY_SUSPEND, 1);
170+
locomokbd->suspend_jiffies = jiffies;
171+
} else
172+
locomokbd->count_cancel = 0;
155173
}
156174
locomokbd_reset_col(membase, col);
157175
}
@@ -162,6 +180,8 @@ static void locomokbd_scankeyboard(struct locomokbd *locomokbd)
162180
/* if any keys are pressed, enable the timer */
163181
if (num_pressed)
164182
mod_timer(&locomokbd->timer, jiffies + SCAN_INTERVAL);
183+
else
184+
locomokbd->count_cancel = 0;
165185

166186
spin_unlock_irqrestore(&locomokbd->lock, flags);
167187
}
@@ -186,10 +206,11 @@ static irqreturn_t locomokbd_interrupt(int irq, void *dev_id)
186206
static void locomokbd_timer_callback(unsigned long data)
187207
{
188208
struct locomokbd *locomokbd = (struct locomokbd *) data;
209+
189210
locomokbd_scankeyboard(locomokbd);
190211
}
191212

192-
static int locomokbd_probe(struct locomo_dev *dev)
213+
static int __devinit locomokbd_probe(struct locomo_dev *dev)
193214
{
194215
struct locomokbd *locomokbd;
195216
struct input_dev *input_dev;
@@ -211,7 +232,6 @@ static int locomokbd_probe(struct locomo_dev *dev)
211232
goto err_free_mem;
212233
}
213234

214-
locomokbd->ldev = dev;
215235
locomo_set_drvdata(dev, locomokbd);
216236

217237
locomokbd->base = (unsigned long) dev->mapbase;
@@ -222,6 +242,8 @@ static int locomokbd_probe(struct locomo_dev *dev)
222242
locomokbd->timer.function = locomokbd_timer_callback;
223243
locomokbd->timer.data = (unsigned long) locomokbd;
224244

245+
locomokbd->suspend_jiffies = jiffies;
246+
225247
locomokbd->input = input_dev;
226248
strcpy(locomokbd->phys, "locomokbd/input0");
227249

@@ -233,9 +255,10 @@ static int locomokbd_probe(struct locomo_dev *dev)
233255
input_dev->id.version = 0x0100;
234256
input_dev->dev.parent = &dev->dev;
235257

236-
input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
258+
input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) |
259+
BIT_MASK(EV_PWR);
237260
input_dev->keycode = locomokbd->keycode;
238-
input_dev->keycodesize = sizeof(unsigned char);
261+
input_dev->keycodesize = sizeof(locomokbd_keycode[0]);
239262
input_dev->keycodemax = ARRAY_SIZE(locomokbd_keycode);
240263

241264
memcpy(locomokbd->keycode, locomokbd_keycode, sizeof(locomokbd->keycode));
@@ -268,7 +291,7 @@ static int locomokbd_probe(struct locomo_dev *dev)
268291
return err;
269292
}
270293

271-
static int locomokbd_remove(struct locomo_dev *dev)
294+
static int __devexit locomokbd_remove(struct locomo_dev *dev)
272295
{
273296
struct locomokbd *locomokbd = locomo_get_drvdata(dev);
274297

@@ -292,7 +315,7 @@ static struct locomo_driver keyboard_driver = {
292315
},
293316
.devid = LOCOMO_DEVID_KEYBOARD,
294317
.probe = locomokbd_probe,
295-
.remove = locomokbd_remove,
318+
.remove = __devexit_p(locomokbd_remove),
296319
};
297320

298321
static int __init locomokbd_init(void)

0 commit comments

Comments
 (0)