gpio-button-hotplug: sync upstream

This commit is contained in:
coolsnowwolf 2025-01-26 23:08:15 +08:00
parent 19978f14dc
commit 171cb58c1d

View File

@ -302,7 +302,7 @@ struct gpio_keys_button_dev {
struct device *dev; struct device *dev;
struct gpio_keys_platform_data *pdata; struct gpio_keys_platform_data *pdata;
struct gpio_keys_button_data data[0]; struct gpio_keys_button_data data[];
}; };
static void gpio_keys_polled_queue_work(struct gpio_keys_button_dev *bdev) static void gpio_keys_polled_queue_work(struct gpio_keys_button_dev *bdev)
@ -373,7 +373,7 @@ gpio_keys_get_devtree_pdata(struct device *dev)
if (!node) if (!node)
return NULL; return NULL;
nbuttons = of_get_child_count(node); nbuttons = of_get_available_child_count(node);
if (nbuttons == 0) if (nbuttons == 0)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
@ -388,7 +388,7 @@ gpio_keys_get_devtree_pdata(struct device *dev)
pdata->rep = !!of_get_property(node, "autorepeat", NULL); pdata->rep = !!of_get_property(node, "autorepeat", NULL);
of_property_read_u32(node, "poll-interval", &pdata->poll_interval); of_property_read_u32(node, "poll-interval", &pdata->poll_interval);
for_each_child_of_node(node, pp) { for_each_available_child_of_node(node, pp) {
button = (struct gpio_keys_button *)(&pdata->buttons[i++]); button = (struct gpio_keys_button *)(&pdata->buttons[i++]);
if (of_property_read_u32(pp, "linux,code", &button->code)) { if (of_property_read_u32(pp, "linux,code", &button->code)) {
@ -525,10 +525,9 @@ static int gpio_keys_button_probe(struct platform_device *pdev,
button->active_low ? GPIOF_ACTIVE_LOW : button->active_low ? GPIOF_ACTIVE_LOW :
0), desc); 0), desc);
if (error) { if (error) {
if (error != -EPROBE_DEFER) { dev_err_probe(dev, error,
dev_err(dev, "unable to claim gpio %d, err=%d\n", "unable to claim gpio %d",
button->gpio, error); button->gpio);
}
goto out; goto out;
} }
@ -679,7 +678,11 @@ static void gpio_keys_irq_close(struct gpio_keys_button_dev *bdev)
} }
} }
#if LINUX_VERSION_CODE < KERNEL_VERSION(6,11,0)
static int gpio_keys_remove(struct platform_device *pdev) static int gpio_keys_remove(struct platform_device *pdev)
#else
static void gpio_keys_remove(struct platform_device *pdev)
#endif
{ {
struct gpio_keys_button_dev *bdev = platform_get_drvdata(pdev); struct gpio_keys_button_dev *bdev = platform_get_drvdata(pdev);
@ -690,29 +693,25 @@ static int gpio_keys_remove(struct platform_device *pdev)
else else
gpio_keys_irq_close(bdev); gpio_keys_irq_close(bdev);
#if LINUX_VERSION_CODE < KERNEL_VERSION(6,11,0)
return 0; return 0;
#endif
} }
static struct platform_driver gpio_keys_driver = { static struct platform_driver gpio_keys_driver = {
.probe = gpio_keys_probe, .probe = gpio_keys_probe,
#if LINUX_VERSION_CODE < KERNEL_VERSION(6,12,0)
.remove = gpio_keys_remove, .remove = gpio_keys_remove,
#endif
.driver = { .driver = {
.name = "gpio-keys", .name = "gpio-keys",
.owner = THIS_MODULE,
.of_match_table = of_match_ptr(gpio_keys_of_match), .of_match_table = of_match_ptr(gpio_keys_of_match),
}, },
}; };
static struct platform_driver gpio_keys_polled_driver = { static struct platform_driver gpio_keys_polled_driver = {
.probe = gpio_keys_polled_probe, .probe = gpio_keys_polled_probe,
#if LINUX_VERSION_CODE < KERNEL_VERSION(6,12,0)
.remove = gpio_keys_remove, .remove = gpio_keys_remove,
#endif
.driver = { .driver = {
.name = "gpio-keys-polled", .name = "gpio-keys-polled",
.owner = THIS_MODULE,
.of_match_table = of_match_ptr(gpio_keys_polled_of_match), .of_match_table = of_match_ptr(gpio_keys_polled_of_match),
}, },
}; };