aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/keyboard/spitzkbd.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/keyboard/spitzkbd.c')
-rw-r--r--drivers/input/keyboard/spitzkbd.c119
1 files changed, 64 insertions, 55 deletions
diff --git a/drivers/input/keyboard/spitzkbd.c b/drivers/input/keyboard/spitzkbd.c
index 344f46005401..cee9c734a048 100644
--- a/drivers/input/keyboard/spitzkbd.c
+++ b/drivers/input/keyboard/spitzkbd.c
@@ -85,7 +85,7 @@ static int spitz_senses[] = {
85 85
86struct spitzkbd { 86struct spitzkbd {
87 unsigned char keycode[ARRAY_SIZE(spitzkbd_keycode)]; 87 unsigned char keycode[ARRAY_SIZE(spitzkbd_keycode)];
88 struct input_dev input; 88 struct input_dev *input;
89 char phys[32]; 89 char phys[32];
90 90
91 spinlock_t lock; 91 spinlock_t lock;
@@ -187,8 +187,7 @@ static void spitzkbd_scankeyboard(struct spitzkbd *spitzkbd_data, struct pt_regs
187 187
188 spin_lock_irqsave(&spitzkbd_data->lock, flags); 188 spin_lock_irqsave(&spitzkbd_data->lock, flags);
189 189
190 if (regs) 190 input_regs(spitzkbd_data->input, regs);
191 input_regs(&spitzkbd_data->input, regs);
192 191
193 num_pressed = 0; 192 num_pressed = 0;
194 for (col = 0; col < KB_COLS; col++) { 193 for (col = 0; col < KB_COLS; col++) {
@@ -210,7 +209,7 @@ static void spitzkbd_scankeyboard(struct spitzkbd *spitzkbd_data, struct pt_regs
210 scancode = SCANCODE(row, col); 209 scancode = SCANCODE(row, col);
211 pressed = rowd & KB_ROWMASK(row); 210 pressed = rowd & KB_ROWMASK(row);
212 211
213 input_report_key(&spitzkbd_data->input, spitzkbd_data->keycode[scancode], pressed); 212 input_report_key(spitzkbd_data->input, spitzkbd_data->keycode[scancode], pressed);
214 213
215 if (pressed) 214 if (pressed)
216 num_pressed++; 215 num_pressed++;
@@ -220,15 +219,15 @@ static void spitzkbd_scankeyboard(struct spitzkbd *spitzkbd_data, struct pt_regs
220 219
221 spitzkbd_activate_all(); 220 spitzkbd_activate_all();
222 221
223 input_report_key(&spitzkbd_data->input, SPITZ_KEY_SYNC, (GPLR(SPITZ_GPIO_SYNC) & GPIO_bit(SPITZ_GPIO_SYNC)) != 0 ); 222 input_report_key(spitzkbd_data->input, SPITZ_KEY_SYNC, (GPLR(SPITZ_GPIO_SYNC) & GPIO_bit(SPITZ_GPIO_SYNC)) != 0 );
224 input_report_key(&spitzkbd_data->input, KEY_SUSPEND, pwrkey); 223 input_report_key(spitzkbd_data->input, KEY_SUSPEND, pwrkey);
225 224
226 if (pwrkey && time_after(jiffies, spitzkbd_data->suspend_jiffies + msecs_to_jiffies(1000))) { 225 if (pwrkey && time_after(jiffies, spitzkbd_data->suspend_jiffies + msecs_to_jiffies(1000))) {
227 input_event(&spitzkbd_data->input, EV_PWR, KEY_SUSPEND, 1); 226 input_event(spitzkbd_data->input, EV_PWR, KEY_SUSPEND, 1);
228 spitzkbd_data->suspend_jiffies = jiffies; 227 spitzkbd_data->suspend_jiffies = jiffies;
229 } 228 }
230 229
231 input_sync(&spitzkbd_data->input); 230 input_sync(spitzkbd_data->input);
232 231
233 /* if any keys are pressed, enable the timer */ 232 /* if any keys are pressed, enable the timer */
234 if (num_pressed) 233 if (num_pressed)
@@ -259,6 +258,7 @@ static irqreturn_t spitzkbd_interrupt(int irq, void *dev_id, struct pt_regs *reg
259static void spitzkbd_timer_callback(unsigned long data) 258static void spitzkbd_timer_callback(unsigned long data)
260{ 259{
261 struct spitzkbd *spitzkbd_data = (struct spitzkbd *) data; 260 struct spitzkbd *spitzkbd_data = (struct spitzkbd *) data;
261
262 spitzkbd_scankeyboard(spitzkbd_data, NULL); 262 spitzkbd_scankeyboard(spitzkbd_data, NULL);
263} 263}
264 264
@@ -298,9 +298,9 @@ static void spitzkbd_hinge_timer(unsigned long data)
298 if (hinge_count >= HINGE_STABLE_COUNT) { 298 if (hinge_count >= HINGE_STABLE_COUNT) {
299 spin_lock_irqsave(&spitzkbd_data->lock, flags); 299 spin_lock_irqsave(&spitzkbd_data->lock, flags);
300 300
301 input_report_switch(&spitzkbd_data->input, SW_0, ((GPLR(SPITZ_GPIO_SWA) & GPIO_bit(SPITZ_GPIO_SWA)) != 0)); 301 input_report_switch(spitzkbd_data->input, SW_0, ((GPLR(SPITZ_GPIO_SWA) & GPIO_bit(SPITZ_GPIO_SWA)) != 0));
302 input_report_switch(&spitzkbd_data->input, SW_1, ((GPLR(SPITZ_GPIO_SWB) & GPIO_bit(SPITZ_GPIO_SWB)) != 0)); 302 input_report_switch(spitzkbd_data->input, SW_1, ((GPLR(SPITZ_GPIO_SWB) & GPIO_bit(SPITZ_GPIO_SWB)) != 0));
303 input_sync(&spitzkbd_data->input); 303 input_sync(spitzkbd_data->input);
304 304
305 spin_unlock_irqrestore(&spitzkbd_data->lock, flags); 305 spin_unlock_irqrestore(&spitzkbd_data->lock, flags);
306 } else { 306 } else {
@@ -309,34 +309,32 @@ static void spitzkbd_hinge_timer(unsigned long data)
309} 309}
310 310
311#ifdef CONFIG_PM 311#ifdef CONFIG_PM
312static int spitzkbd_suspend(struct device *dev, pm_message_t state, uint32_t level) 312static int spitzkbd_suspend(struct device *dev, pm_message_t state)
313{ 313{
314 if (level == SUSPEND_POWER_DOWN) { 314 int i;
315 int i; 315 struct spitzkbd *spitzkbd = dev_get_drvdata(dev);
316 struct spitzkbd *spitzkbd = dev_get_drvdata(dev); 316 spitzkbd->suspended = 1;
317 spitzkbd->suspended = 1; 317
318 318 /* Set Strobe lines as inputs - *except* strobe line 0 leave this
319 /* Set Strobe lines as inputs - *except* strobe line 0 leave this 319 enabled so we can detect a power button press for resume */
320 enabled so we can detect a power button press for resume */ 320 for (i = 1; i < SPITZ_KEY_STROBE_NUM; i++)
321 for (i = 1; i < SPITZ_KEY_STROBE_NUM; i++) 321 pxa_gpio_mode(spitz_strobes[i] | GPIO_IN);
322 pxa_gpio_mode(spitz_strobes[i] | GPIO_IN); 322
323 }
324 return 0; 323 return 0;
325} 324}
326 325
327static int spitzkbd_resume(struct device *dev, uint32_t level) 326static int spitzkbd_resume(struct device *dev)
328{ 327{
329 if (level == RESUME_POWER_ON) { 328 int i;
330 int i; 329 struct spitzkbd *spitzkbd = dev_get_drvdata(dev);
331 struct spitzkbd *spitzkbd = dev_get_drvdata(dev);
332 330
333 for (i = 0; i < SPITZ_KEY_STROBE_NUM; i++) 331 for (i = 0; i < SPITZ_KEY_STROBE_NUM; i++)
334 pxa_gpio_mode(spitz_strobes[i] | GPIO_OUT | GPIO_DFLT_HIGH); 332 pxa_gpio_mode(spitz_strobes[i] | GPIO_OUT | GPIO_DFLT_HIGH);
333
334 /* Upon resume, ignore the suspend key for a short while */
335 spitzkbd->suspend_jiffies = jiffies;
336 spitzkbd->suspended = 0;
335 337
336 /* Upon resume, ignore the suspend key for a short while */
337 spitzkbd->suspend_jiffies = jiffies;
338 spitzkbd->suspended = 0;
339 }
340 return 0; 338 return 0;
341} 339}
342#else 340#else
@@ -346,14 +344,21 @@ static int spitzkbd_resume(struct device *dev, uint32_t level)
346 344
347static int __init spitzkbd_probe(struct device *dev) 345static int __init spitzkbd_probe(struct device *dev)
348{ 346{
349 int i;
350 struct spitzkbd *spitzkbd; 347 struct spitzkbd *spitzkbd;
348 struct input_dev *input_dev;
349 int i;
351 350
352 spitzkbd = kzalloc(sizeof(struct spitzkbd), GFP_KERNEL); 351 spitzkbd = kzalloc(sizeof(struct spitzkbd), GFP_KERNEL);
353 if (!spitzkbd) 352 if (!spitzkbd)
354 return -ENOMEM; 353 return -ENOMEM;
355 354
356 dev_set_drvdata(dev,spitzkbd); 355 input_dev = input_allocate_device();
356 if (!input_dev) {
357 kfree(spitzkbd);
358 return -ENOMEM;
359 }
360
361 dev_set_drvdata(dev, spitzkbd);
357 strcpy(spitzkbd->phys, "spitzkbd/input0"); 362 strcpy(spitzkbd->phys, "spitzkbd/input0");
358 363
359 spin_lock_init(&spitzkbd->lock); 364 spin_lock_init(&spitzkbd->lock);
@@ -368,30 +373,34 @@ static int __init spitzkbd_probe(struct device *dev)
368 spitzkbd->htimer.function = spitzkbd_hinge_timer; 373 spitzkbd->htimer.function = spitzkbd_hinge_timer;
369 spitzkbd->htimer.data = (unsigned long) spitzkbd; 374 spitzkbd->htimer.data = (unsigned long) spitzkbd;
370 375
371 spitzkbd->suspend_jiffies=jiffies; 376 spitzkbd->suspend_jiffies = jiffies;
372 377
373 init_input_dev(&spitzkbd->input); 378 spitzkbd->input = input_dev;
374 spitzkbd->input.private = spitzkbd; 379
375 spitzkbd->input.name = "Spitz Keyboard"; 380 input_dev->private = spitzkbd;
376 spitzkbd->input.dev = dev; 381 input_dev->name = "Spitz Keyboard";
377 spitzkbd->input.phys = spitzkbd->phys; 382 input_dev->phys = spitzkbd->phys;
378 spitzkbd->input.id.bustype = BUS_HOST; 383 input_dev->cdev.dev = dev;
379 spitzkbd->input.id.vendor = 0x0001; 384
380 spitzkbd->input.id.product = 0x0001; 385 input_dev->id.bustype = BUS_HOST;
381 spitzkbd->input.id.version = 0x0100; 386 input_dev->id.vendor = 0x0001;
382 spitzkbd->input.evbit[0] = BIT(EV_KEY) | BIT(EV_REP) | BIT(EV_PWR) | BIT(EV_SW); 387 input_dev->id.product = 0x0001;
383 spitzkbd->input.keycode = spitzkbd->keycode; 388 input_dev->id.version = 0x0100;
384 spitzkbd->input.keycodesize = sizeof(unsigned char); 389
385 spitzkbd->input.keycodemax = ARRAY_SIZE(spitzkbd_keycode); 390 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP) | BIT(EV_PWR) | BIT(EV_SW);
391 input_dev->keycode = spitzkbd->keycode;
392 input_dev->keycodesize = sizeof(unsigned char);
393 input_dev->keycodemax = ARRAY_SIZE(spitzkbd_keycode);
386 394
387 memcpy(spitzkbd->keycode, spitzkbd_keycode, sizeof(spitzkbd->keycode)); 395 memcpy(spitzkbd->keycode, spitzkbd_keycode, sizeof(spitzkbd->keycode));
388 for (i = 0; i < ARRAY_SIZE(spitzkbd_keycode); i++) 396 for (i = 0; i < ARRAY_SIZE(spitzkbd_keycode); i++)
389 set_bit(spitzkbd->keycode[i], spitzkbd->input.keybit); 397 set_bit(spitzkbd->keycode[i], input_dev->keybit);
390 clear_bit(0, spitzkbd->input.keybit); 398 clear_bit(0, input_dev->keybit);
391 set_bit(SW_0, spitzkbd->input.swbit); 399 set_bit(SW_0, input_dev->swbit);
392 set_bit(SW_1, spitzkbd->input.swbit); 400 set_bit(SW_1, input_dev->swbit);
401
402 input_register_device(input_dev);
393 403
394 input_register_device(&spitzkbd->input);
395 mod_timer(&spitzkbd->htimer, jiffies + msecs_to_jiffies(HINGE_SCAN_INTERVAL)); 404 mod_timer(&spitzkbd->htimer, jiffies + msecs_to_jiffies(HINGE_SCAN_INTERVAL));
396 405
397 /* Setup sense interrupts - RisingEdge Detect, sense lines as inputs */ 406 /* Setup sense interrupts - RisingEdge Detect, sense lines as inputs */
@@ -444,7 +453,7 @@ static int spitzkbd_remove(struct device *dev)
444 del_timer_sync(&spitzkbd->htimer); 453 del_timer_sync(&spitzkbd->htimer);
445 del_timer_sync(&spitzkbd->timer); 454 del_timer_sync(&spitzkbd->timer);
446 455
447 input_unregister_device(&spitzkbd->input); 456 input_unregister_device(spitzkbd->input);
448 457
449 kfree(spitzkbd); 458 kfree(spitzkbd);
450 459