-err_free_pdata:
- /* If we have no platform_data, we allocated pdata dynamically. */
- if (!dev_get_platdata(&pdev->dev))
- kfree(pdata);
+ ret = gpio_keys_button_probe(pdev, &bdev, 0);
+
+ if (ret)
+ return ret;
+
+ pdata = pdev->dev.platform_data;
+ for (i = 0; i < pdata->nbuttons; i++) {
+ struct gpio_keys_button *button = &pdata->buttons[i];
+ struct gpio_keys_button_data *bdata = &bdev->data[i];
+
+ if (!button->irq)
+ button->irq = gpio_to_irq(button->gpio);
+ if (button->irq < 0) {
+ dev_err(&pdev->dev, "failed to get irq for gpio:%d\n", button->gpio);
+ continue;
+ }
+
+ ret = devm_request_threaded_irq(&pdev->dev, button->irq, NULL, button_handle_irq,
+ IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
+ dev_name(&pdev->dev), bdata);
+ if (ret < 0)
+ dev_err(&pdev->dev, "failed to request irq:%d for gpio:%d\n", button->irq, button->gpio);
+ else
+ dev_dbg(&pdev->dev, "gpio:%d has irq:%d\n", button->gpio, button->irq);