Commit 173bdd746b128241d3d6d202142820692e7dd530

Authored by Shubhrajyoti D
Committed by Dmitry Torokhov
1 parent 448cd1664a

Input: gpio_keys - add hooks to enable/disable device

Allow platform code to specify callbcks that will be invoked when
input device is opened or closed, allowing, for example, to enable
the device.

Signed-off-by: Shubhrajyoti D <shubhrajyoti@ti.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>

Showing 2 changed files with 24 additions and 0 deletions Side-by-side Diff

drivers/input/keyboard/gpio_keys.c
... ... @@ -39,6 +39,8 @@
39 39 struct input_dev *input;
40 40 struct mutex disable_lock;
41 41 unsigned int n_buttons;
  42 + int (*enable)(struct device *dev);
  43 + void (*disable)(struct device *dev);
42 44 struct gpio_button_data data[0];
43 45 };
44 46  
... ... @@ -423,6 +425,21 @@
423 425 return error;
424 426 }
425 427  
  428 +static int gpio_keys_open(struct input_dev *input)
  429 +{
  430 + struct gpio_keys_drvdata *ddata = input_get_drvdata(input);
  431 +
  432 + return ddata->enable ? ddata->enable(input->dev.parent) : 0;
  433 +}
  434 +
  435 +static void gpio_keys_close(struct input_dev *input)
  436 +{
  437 + struct gpio_keys_drvdata *ddata = input_get_drvdata(input);
  438 +
  439 + if (ddata->disable)
  440 + ddata->disable(input->dev.parent);
  441 +}
  442 +
426 443 static int __devinit gpio_keys_probe(struct platform_device *pdev)
427 444 {
428 445 struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
429 446  
430 447  
... ... @@ -444,13 +461,18 @@
444 461  
445 462 ddata->input = input;
446 463 ddata->n_buttons = pdata->nbuttons;
  464 + ddata->enable = pdata->enable;
  465 + ddata->disable = pdata->disable;
447 466 mutex_init(&ddata->disable_lock);
448 467  
449 468 platform_set_drvdata(pdev, ddata);
  469 + input_set_drvdata(input, ddata);
450 470  
451 471 input->name = pdev->name;
452 472 input->phys = "gpio-keys/input0";
453 473 input->dev.parent = &pdev->dev;
  474 + input->open = gpio_keys_open;
  475 + input->close = gpio_keys_close;
454 476  
455 477 input->id.bustype = BUS_HOST;
456 478 input->id.vendor = 0x0001;
include/linux/gpio_keys.h
... ... @@ -17,6 +17,8 @@
17 17 struct gpio_keys_button *buttons;
18 18 int nbuttons;
19 19 unsigned int rep:1; /* enable input subsystem auto repeat */
  20 + int (*enable)(struct device *dev);
  21 + void (*disable)(struct device *dev);
20 22 };
21 23  
22 24 #endif