1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
| ... static int gpio_keys_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; const struct gpio_keys_platform_data *pdata = dev_get_platdata(dev); struct fwnode_handle *child = NULL; struct gpio_keys_drvdata *ddata; struct input_dev *input; int i, error; int wakeup = 0;
if (!pdata) { pdata = gpio_keys_get_devtree_pdata(dev); if (IS_ERR(pdata)) return PTR_ERR(pdata); }
ddata = devm_kzalloc(dev, struct_size(ddata, data, pdata->nbuttons), GFP_KERNEL); if (!ddata) { dev_err(dev, "failed to allocate state\n"); return -ENOMEM; }
ddata->keymap = devm_kcalloc(dev, pdata->nbuttons, sizeof(ddata->keymap[0]), GFP_KERNEL); if (!ddata->keymap) return -ENOMEM;
input = devm_input_allocate_device(dev); if (!input) { dev_err(dev, "failed to allocate input device\n"); return -ENOMEM; }
ddata->pdata = pdata; ddata->input = input; mutex_init(&ddata->disable_lock);
platform_set_drvdata(pdev, ddata); input_set_drvdata(input, ddata);
input->name = pdata->name ? : pdev->name; input->phys = "gpio-keys/input0"; input->dev.parent = dev; input->open = gpio_keys_open; input->close = gpio_keys_close;
input->id.bustype = BUS_HOST; input->id.vendor = 0x0001; input->id.product = 0x0001; input->id.version = 0x0100;
input->keycode = ddata->keymap; input->keycodesize = sizeof(ddata->keymap[0]); input->keycodemax = pdata->nbuttons;
/* Enable auto repeat feature of Linux input subsystem */ if (pdata->rep) __set_bit(EV_REP, input->evbit);
for (i = 0; i < pdata->nbuttons; i++) { const struct gpio_keys_button *button = &pdata->buttons[i];
if (!dev_get_platdata(dev)) { child = device_get_next_child_node(dev, child); if (!child) { dev_err(dev, "missing child device node for entry %d\n", i); return -EINVAL; } }
error = gpio_keys_setup_key(pdev, input, ddata, button, i, child); if (error) { fwnode_handle_put(child); return error; }
if (button->wakeup) wakeup = 1; }
fwnode_handle_put(child);
error = input_register_device(input); if (error) { dev_err(dev, "Unable to register input device, error: %d\n", error); return error; }
device_init_wakeup(dev, wakeup);
return 0; }
static void gpio_keys_shutdown(struct platform_device *pdev) { int ret;
ret = gpio_keys_suspend(&pdev->dev); if (ret) dev_err(&pdev->dev, "failed to shutdown\n"); }
static int __maybe_unused gpio_keys_suspend(struct device *dev) { struct gpio_keys_drvdata *ddata = dev_get_drvdata(dev); struct input_dev *input = ddata->input; int error;
if (device_may_wakeup(dev)) { error = gpio_keys_enable_wakeup(ddata); if (error) return error; } else { mutex_lock(&input->mutex); if (input->users) gpio_keys_close(input); mutex_unlock(&input->mutex); }
return 0; } static int __maybe_unused gpio_keys_resume(struct device *dev) { struct gpio_keys_drvdata *ddata = dev_get_drvdata(dev); struct input_dev *input = ddata->input; int error = 0;
if (device_may_wakeup(dev)) { gpio_keys_disable_wakeup(ddata); } else { mutex_lock(&input->mutex); if (input->users) error = gpio_keys_open(input); mutex_unlock(&input->mutex); }
if (error) return error;
gpio_keys_report_state(ddata); return 0; } static SIMPLE_DEV_PM_OPS(gpio_keys_pm_ops, gpio_keys_suspend, gpio_keys_resume);
static const struct of_device_id gpio_keys_of_match[] = { { .compatible = "gpio-keys", }, { }, }; static struct platform_driver gpio_keys_device_driver = { .probe = gpio_keys_probe, .shutdown = gpio_keys_shutdown, .driver = { .name = "gpio-keys", .pm = &gpio_keys_pm_ops, .of_match_table = gpio_keys_of_match, .dev_groups = gpio_keys_groups, } }; static int __init gpio_keys_init(void) { return platform_driver_register(&gpio_keys_device_driver); }
static void __exit gpio_keys_exit(void) { platform_driver_unregister(&gpio_keys_device_driver); }
|