From 578582392c44fd9e50245d9bc46385742c1d2557 Mon Sep 17 00:00:00 2001 From: Zhou weixin Date: Mon, 19 Dec 2016 11:04:36 +0800 Subject: [PATCH] HID: i2c-hid: add support wakeup Change-Id: I15890509ff5983e1a8adaa48b28391ec67de8bb5 Signed-off-by: Zhou weixin --- drivers/hid/i2c-hid/i2c-hid.c | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c index 0b80633bae91..6c37c4a039f0 100644 --- a/drivers/hid/i2c-hid/i2c-hid.c +++ b/drivers/hid/i2c-hid/i2c-hid.c @@ -38,6 +38,9 @@ #include #include #include +#include +#include +#include #include @@ -151,8 +154,40 @@ struct i2c_hid { struct i2c_hid_platform_data pdata; bool irq_wake_enabled; + + struct notifier_block fb_notif; + int is_suspend; }; +static int ihid_fb_notifier_callback(struct notifier_block *self, + unsigned long action, void *data) +{ + struct i2c_hid *ihid; + struct fb_event *event = data; + + ihid = container_of(self, struct i2c_hid, fb_notif); + + if (action == FB_EARLY_EVENT_BLANK) { + switch (*((int *)event->data)) { + case FB_BLANK_UNBLANK: + break; + default: + ihid->is_suspend = 1; + break; + } + } else if (action == FB_EVENT_BLANK) { + switch (*((int *)event->data)) { + case FB_BLANK_UNBLANK: + ihid->is_suspend = 0; + break; + default: + break; + } + } + + return NOTIFY_OK; +} + static int __i2c_hid_command(struct i2c_client *client, const struct i2c_hid_cmd *command, u8 reportID, u8 reportType, u8 *args, int args_len, @@ -427,6 +462,9 @@ static irqreturn_t i2c_hid_irq(int irq, void *dev_id) i2c_hid_get_input(ihid); + if (ihid->is_suspend == 1) + rk_send_wakeup_key(); + return IRQ_HANDLED; } @@ -1014,6 +1052,16 @@ static int i2c_hid_probe(struct i2c_client *client, if (ret < 0) goto err_pm; + if (client->dev.of_node) { + ret = of_property_read_bool(client->dev.of_node, "hid-support-wakeup"); + if (ret) { + device_init_wakeup(&client->dev, true); + ihid->is_suspend = 0; + ihid->fb_notif.notifier_call = ihid_fb_notifier_callback; + fb_register_client(&ihid->fb_notif); + } + } + hid = hid_allocate_device(); if (IS_ERR(hid)) { ret = PTR_ERR(hid); -- 2.34.1