/* * GPIO Button Hotplug driver * * Copyright (C) 2012 Felix Fietkau * Copyright (C) 2008-2010 Gabor Juhos * * Based on the diag.c - GPIO interface driver for Broadcom boards * Copyright (C) 2006 Mike Baker , * Copyright (C) 2006-2007 Felix Fietkau * Copyright (C) 2008 Andy Boyett * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation. */ #include #include #include #include #include #include #include #include #include #include #include #include #define DRV_NAME "gpio-keys" #define BH_SKB_SIZE 2048 #define PFX DRV_NAME ": " #undef BH_DEBUG #ifdef BH_DEBUG #define BH_DBG(fmt, args...) printk(KERN_DEBUG "%s: " fmt, DRV_NAME, ##args ) #else #define BH_DBG(fmt, args...) do {} while (0) #endif #define BH_ERR(fmt, args...) printk(KERN_ERR "%s: " fmt, DRV_NAME, ##args ) struct bh_priv { unsigned long seen; }; struct bh_event { const char *name; unsigned int type; char *action; unsigned long seen; struct sk_buff *skb; struct work_struct work; }; struct bh_map { unsigned int code; const char *name; }; struct gpio_keys_button_data { struct delayed_work work; struct bh_priv bh; int last_state; int count; int threshold; int can_sleep; struct gpio_keys_button *b; }; extern u64 uevent_next_seqnum(void); #define BH_MAP(_code, _name) \ { \ .code = (_code), \ .name = (_name), \ } static struct bh_map button_map[] = { BH_MAP(BTN_0, "BTN_0"), BH_MAP(BTN_1, "BTN_1"), BH_MAP(BTN_2, "BTN_2"), BH_MAP(BTN_3, "BTN_3"), BH_MAP(BTN_4, "BTN_4"), BH_MAP(BTN_5, "BTN_5"), BH_MAP(BTN_6, "BTN_6"), BH_MAP(BTN_7, "BTN_7"), BH_MAP(BTN_8, "BTN_8"), BH_MAP(BTN_9, "BTN_9"), BH_MAP(KEY_POWER, "power"), BH_MAP(KEY_RESTART, "reset"), BH_MAP(KEY_RFKILL, "rfkill"), BH_MAP(KEY_WPS_BUTTON, "wps"), BH_MAP(KEY_WIMAX, "wwan"), }; /* -------------------------------------------------------------------------*/ static int bh_event_add_var(struct bh_event *event, int argv, const char *format, ...) { static char buf[128]; char *s; va_list args; int len; if (argv) return 0; va_start(args, format); len = vsnprintf(buf, sizeof(buf), format, args); va_end(args); if (len >= sizeof(buf)) { BH_ERR("buffer size too small\n"); WARN_ON(1); return -ENOMEM; } s = skb_put(event->skb, len + 1); strcpy(s, buf); BH_DBG("added variable '%s'\n", s); return 0; } static int button_hotplug_fill_event(struct bh_event *event) { int ret; ret = bh_event_add_var(event, 0, "HOME=%s", "/"); if (ret) return ret; ret = bh_event_add_var(event, 0, "PATH=%s", "/sbin:/bin:/usr/sbin:/usr/bin"); if (ret) return ret; ret = bh_event_add_var(event, 0, "SUBSYSTEM=%s", "button"); if (ret) return ret; ret = bh_event_add_var(event, 0, "ACTION=%s", event->action); if (ret) return ret; ret = bh_event_add_var(event, 0, "BUTTON=%s", event->name); if (ret) return ret; if (event->type == EV_SW) { ret = bh_event_add_var(event, 0, "TYPE=%s", "switch"); if (ret) return ret; } ret = bh_event_add_var(event, 0, "SEEN=%ld", event->seen); if (ret) return ret; ret = bh_event_add_var(event, 0, "SEQNUM=%llu", uevent_next_seqnum()); return ret; } static void button_hotplug_work(struct work_struct *work) { struct bh_event *event = container_of(work, struct bh_event, work); int ret = 0; event->skb = alloc_skb(BH_SKB_SIZE, GFP_KERNEL); if (!event->skb) goto out_free_event; ret = bh_event_add_var(event, 0, "%s@", event->action); if (ret) goto out_free_skb; ret = button_hotplug_fill_event(event); if (ret) goto out_free_skb; NETLINK_CB(event->skb).dst_group = 1; broadcast_uevent(event->skb, 0, 1, GFP_KERNEL); out_free_skb: if (ret) { BH_ERR("work error %d\n", ret); kfree_skb(event->skb); } out_free_event: kfree(event); } static int button_hotplug_create_event(const char *name, unsigned int type, unsigned long seen, int pressed) { struct bh_event *event; BH_DBG("create event, name=%s, seen=%lu, pressed=%d\n", name, seen, pressed); event = kzalloc(sizeof(*event), GFP_KERNEL); if (!event) return -ENOMEM; event->name = name; event->type = type; event->seen = seen; event->action = pressed ? "pressed" : "released"; INIT_WORK(&event->work, (void *)(void *)button_hotplug_work); schedule_work(&event->work); return 0; } /* -------------------------------------------------------------------------*/ static int button_get_index(unsigned int code) { int i; for (i = 0; i < ARRAY_SIZE(button_map); i++) if (button_map[i].code == code) return i; return -1; } static void button_hotplug_event(struct gpio_keys_button_data *data, unsigned int type, int value) { struct bh_priv *priv = &data->bh; unsigned long seen = jiffies; int btn; BH_DBG("event type=%u, code=%u, value=%d\n", type, data->b->code, value); if ((type != EV_KEY) && (type != EV_SW)) return; btn = button_get_index(data->b->code); if (btn < 0) return; button_hotplug_create_event(button_map[btn].name, type, (seen - priv->seen) / HZ, value); priv->seen = seen; } struct gpio_keys_button_dev { i
From: John Crispin <john@phrozen.org>
Subject: hack: kernel: add generic image_cmdline hack to MIPS targets

lede-commit: d59f5b3a987a48508257a0ddbaeadc7909f9f976
Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
---
 arch/mips/Kconfig       | 4 ++++
 arch/mips/kernel/head.S | 6 ++++++
 2 files changed, 10 insertions(+)

--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -1167,6 +1167,10 @@ config MIPS_MSC
 config SYNC_R4K
 	bool
 
+config IMAGE_CMDLINE_HACK
+	bool "OpenWrt specific image command line hack"
+	default n
+
 config NO_IOPORT_MAP
 	def_bool n
 
--- a/arch/mips/kernel/head.S
+++ b/arch/mips/kernel/head.S
@@ -79,6 +79,12 @@ FEXPORT(__kernel_entry)
 	j	kernel_entry
 #endif /* CONFIG_BOOT_RAW */
 
+#ifdef CONFIG_IMAGE_CMDLINE_HACK
+	.ascii	"CMDLINE:"
+EXPORT(__image_cmdline)
+	.fill	0x400
+#endif /* CONFIG_IMAGE_CMDLINE_HACK */
+
 	__REF
 
 NESTED(kernel_entry, 16, sp)			# kernel entry point
) { dev_err(&pdev->dev, "failed to get irq for gpio:%d\n", button->gpio); continue; } ret = devm_request_irq(&pdev->dev, button->irq, button_handle_irq, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, dev_name(&pdev->dev), bdata); if (ret) 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); if (bdata->b->type == EV_SW) button_hotplug_event(bdata, EV_SW, gpio_button_get_value(bdata)); } return 0; } static int gpio_keys_polled_probe(struct platform_device *pdev) { struct gpio_keys_platform_data *pdata; struct gpio_keys_button_dev *bdev; int ret; int i; ret = gpio_keys_button_probe(pdev, &bdev, 1); if (ret) return ret; INIT_DELAYED_WORK(&bdev->work, gpio_keys_polled_poll); pdata = bdev->pdata; if (pdata->enable) pdata->enable(bdev->dev); for (i = 0; i < pdata->nbuttons; i++) gpio_keys_polled_check_state(&bdev->data[i]); gpio_keys_polled_queue_work(bdev); return ret; } static int gpio_keys_remove(struct platform_device *pdev) { struct gpio_keys_button_dev *bdev = platform_get_drvdata(pdev); platform_set_drvdata(pdev, NULL); if (bdev->polled) gpio_keys_polled_close(bdev); return 0; } static struct platform_driver gpio_keys_driver = { .probe = gpio_keys_probe, .remove = gpio_keys_remove, .driver = { .name = "gpio-keys", .owner = THIS_MODULE, .of_match_table = of_match_ptr(gpio_keys_of_match), }, }; static struct platform_driver gpio_keys_polled_driver = { .probe = gpio_keys_polled_probe, .remove = gpio_keys_remove, .driver = { .name = "gpio-keys-polled", .owner = THIS_MODULE, .of_match_table = of_match_ptr(gpio_keys_polled_of_match), }, }; static int __init gpio_button_init(void) { int ret; ret = platform_driver_register(&gpio_keys_driver); if (ret) return ret; ret = platform_driver_register(&gpio_keys_polled_driver); if (ret) platform_driver_unregister(&gpio_keys_driver); return ret; } static void __exit gpio_button_exit(void) { platform_driver_unregister(&gpio_keys_driver); platform_driver_unregister(&gpio_keys_polled_driver); } module_init(gpio_button_init); module_exit(gpio_button_exit); MODULE_AUTHOR("Gabor Juhos "); MODULE_AUTHOR("Felix Fietkau "); MODULE_DESCRIPTION("Polled GPIO Buttons hotplug driver"); MODULE_LICENSE("GPL v2"); MODULE_ALIAS("platform:" DRV_NAME);