From patchwork Fri May 15 13:36:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 6414941 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 92EFA9F32E for ; Fri, 15 May 2015 14:50:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6884A20377 for ; Fri, 15 May 2015 14:50:38 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CFEB320527 for ; Fri, 15 May 2015 14:50:36 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YtGts-00022U-Rz; Fri, 15 May 2015 14:47:44 +0000 Received: from mail-by2on0118.outbound.protection.outlook.com ([207.46.100.118] helo=na01-by2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YtGsD-0000he-EO for linux-arm-kernel@lists.infradead.org; Fri, 15 May 2015 14:46:02 +0000 Received: from BN3PR0301CA0015.namprd03.prod.outlook.com (10.160.180.153) by BY1PR03MB1355.namprd03.prod.outlook.com (10.162.109.25) with Microsoft SMTP Server (TLS) id 15.1.166.22; Fri, 15 May 2015 14:45:39 +0000 Received: from BN1AFFO11FD030.protection.gbl (2a01:111:f400:7c10::156) by BN3PR0301CA0015.outlook.office365.com (2a01:111:e400:4000::25) with Microsoft SMTP Server (TLS) id 15.1.166.22 via Frontend Transport; Fri, 15 May 2015 14:45:39 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; freescale.mail.onmicrosoft.com; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BN1AFFO11FD030.mail.protection.outlook.com (10.58.52.168) with Microsoft SMTP Server (TLS) id 15.1.160.8 via Frontend Transport; Fri, 15 May 2015 14:45:38 +0000 Received: from shlinux2.ap.freescale.net (shlinux2.ap.freescale.net [10.192.224.44]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id t4FEjA54016852; Fri, 15 May 2015 07:45:33 -0700 From: To: , , , , , , , Subject: [PATCH 5/7] input: keyboard: imx: add snvs power key driver Date: Fri, 15 May 2015 21:36:28 +0800 Message-ID: <1431696990-23078-6-git-send-email-Frank.Li@freescale.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1431696990-23078-1-git-send-email-Frank.Li@freescale.com> References: <1431696990-23078-1-git-send-email-Frank.Li@freescale.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD030; 1:yMKD5ZWx3/laXkNVv2f4E5NddBY7E6RruHBO3LAriZUAKqRny5eQtio4kWdBHoIu1PCbmcu85njvI5CToa8IGQbgNswdRUix4QkjavSiWGqWfZL+YUMXJI/SHG/adlxTt3N7833WOauIpqgaD2/L2LqBFOU4ET73g0NE8cY3SVFwHptv4oY3T/9sVDRejIgJ0fi/GgjwBZwG3oQ/EWatK2aWAbcGPK2LXFiVXO96EewtuRO6aDE5/7MChRQrEPxv6hgYIE5KJ3D3J07XaAg5Gi6Nc0t2kJYghYdwpd16zPYqAfWz9ea8vM/4YnIeEe/CX556wFNeuW2ipMyh1e/xfw== X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(339900001)(199003)(189002)(105606002)(229853001)(106466001)(77096005)(15975445007)(104016003)(5001770100001)(50226001)(189998001)(5001960100002)(107886002)(50986999)(76176999)(19580405001)(19580395003)(85426001)(46102003)(47776003)(86362001)(87936001)(6806004)(2201001)(86152002)(77156002)(62966003)(36756003)(92566002)(2950100001)(50466002)(48376002)(4001430100001)(2101003); DIR:OUT; SFP:1102; SCL:1; SRVR:BY1PR03MB1355; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; MLV:sfv; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; BY1PR03MB1355; 2:G61/BbeXROZ5flHo58zdt9nZLEXEKtbzc8nLpwsrxm+Cw7IPcUUwerSYaCe6n65c; 2:8K5ZxDjPIKqwon2AtXYJvqJFFsVX6W6GnIIpISuk/TETHoRdhpr+TCUHkJbCq5PeJuG5HoNo+n9r9d5iO6Y7PNeYxazioDlx08bH0VAUP3oj6Qsj99aziz/lZJryihtGTAnIcolc2roMZmkGVCapnH/Px/4w+Bj0kKjcYp/ZWX9VP8V558IZ2ctD6ApKzsd9TlJLdp1Ddk2pGmsjdOBtMH5d6km3nQ+HEYuWiMbW+5g=; 6:Y81HdiOOhYHC0S7O56g6xtHpL7PvaNFcrLm8IKOqHaEvu8ZgyCnSIg4NpYwGU5GrUv3LHL8ghcr6fahsCAG4Kjd4ekVtJpHd0UKzDwjYGzpUIafxJUyoYF5Hpqed47bYgAtUzkQcqOraELqysZW5VKSPWtnu7tqvQF2TQC7kln25dQz1zUW21N3F2m61tuTQFWwi5TYY9UjtEZj1gfCaH6Ou9cxUbFQ6YCD+nGVe3E+kWrcMfEmNqbJ3YTH/S8lerauivA88J+2goTU2Xybroamh5Fa2/s4NjHiz7jty7ETv/CPLongNNaLYJ0E21ZvALTiUZGjB5wOV4AtuE98d4A==; 3:N+1FmOQ6TeorQrx5t9wK0uJXJF9ZIb1DPrmFBRvUN/qWCpXZmh0vYr7lL/ujgc5bmnUQu+yn9j0dVBZeT5DvJQB7U3T/JWRPO+9ABHmAdX7193X9MrkJ+zNXrr370KT2j5TTRW8XUSK8F9+wMjTsGvtaqOMz2HEG8t4ICU1AsLBdhshPj0QGGq7EA4MzBBVavgttZCNaZw2zYUnH3JJ9DMLSFuK3I/Joiw/RfUYaC1I44hqDg7lopDefPwdFNhbCkOeuIiE8/zrjBrYhw2CmjeMEmFURRuhkUkqXHdssRRg= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY1PR03MB1355; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(3002001); SRVR:BY1PR03MB1355; BCL:0; PCL:0; RULEID:; SRVR:BY1PR03MB1355; X-Forefront-PRVS: 0577AD41D6 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY1PR03MB1355; 9:ZR4POQ+TMsF/znHppvyqiQsg3WcGnO3pOD7FJ0869j?= =?us-ascii?Q?JI3Q9FkOGe8hhPMBr7lH8x4/6d70Zopt+Aai7YGS6Q+61C1jxk9SnPosluiU?= =?us-ascii?Q?gJ5gJx4t+6Ny6IELW9Iw67rnBj4mBMQquQNtVNo+ybaETX0vnffGxODzqyRY?= =?us-ascii?Q?WsVSCr4C1msjHyi38G1Jv4A3jOGFn6dQ1sl6U8xZOn/pSXfuIUj/UXmXzHaj?= =?us-ascii?Q?TH1UUkEPJcHbdwAOtTY8QZ2UGwCjUdnFNMKuTp1WnSQ2Q4fgxU8SsKY9N9bs?= =?us-ascii?Q?ETZCOpc74quMOahKPYzfOVcdzyUd0ymuefVgfvZDEbm07uFNIS0G2QuQw9Ps?= =?us-ascii?Q?+2ErwMS9UkNyA4TYtG27OTWjRePwCuSjqp+BAxKMs2qsZmCnHhl7za9enKhN?= =?us-ascii?Q?S+pLYLHsxU7YXnbA68Sp04M1qIanEkBRIJ/32zKuNFmkKXb8xxIa8I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enant-OriginalArrivalTime: 15 May 2015 14:45:38.3377 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR03MB1355 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150515_074601_561321_857367E7 X-CRM114-Status: GOOD ( 16.31 ) X-Spam-Score: -0.2 (/) Cc: devicetree@vger.kernel.org, Frank Li , rtc-linux@googlegroups.com, linux-pm@vger.kernel.org, Robin Gong , linux-input@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Robin Gong add snvs power key driver. It work in imx chips after i.mx6sx ON/OFF key used power on/off whole system. This driver make it wakeup from suspend state when short press ON/OFF key. Long time press will trig SNVS power off chip without software intervention. Signed-off-by: Robin Gong Signed-off-by: Frank Li Acked-by: Dmitry Torokhov --- drivers/input/keyboard/Kconfig | 11 ++ drivers/input/keyboard/Makefile | 1 + drivers/input/keyboard/snvs_pwrkey.c | 232 +++++++++++++++++++++++++++++++++++ 3 files changed, 244 insertions(+) create mode 100644 drivers/input/keyboard/snvs_pwrkey.c diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig index 106fbac..61b3fab 100644 --- a/drivers/input/keyboard/Kconfig +++ b/drivers/input/keyboard/Kconfig @@ -400,6 +400,17 @@ config KEYBOARD_MPR121 To compile this driver as a module, choose M here: the module will be called mpr121_touchkey. +config KEYBOARD_SNVS_PWRKEY + tristate "IMX SNVS Power Key Driver" + depends on SOC_IMX6SX + depends on OF + help + This is the snvs powerkey driver for the Freescale i.MX application + processors that are newer than i.MX6 SX. + + To compile this driver as a module, choose M here; the + module will be called snvs_pwrkey. + config KEYBOARD_IMX tristate "IMX keypad support" depends on ARCH_MXC diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile index df28d55..1d416dd 100644 --- a/drivers/input/keyboard/Makefile +++ b/drivers/input/keyboard/Makefile @@ -51,6 +51,7 @@ obj-$(CONFIG_KEYBOARD_QT1070) += qt1070.o obj-$(CONFIG_KEYBOARD_QT2160) += qt2160.o obj-$(CONFIG_KEYBOARD_SAMSUNG) += samsung-keypad.o obj-$(CONFIG_KEYBOARD_SH_KEYSC) += sh_keysc.o +obj-$(CONFIG_KEYBOARD_SNVS_PWRKEY) += snvs_pwrkey.o obj-$(CONFIG_KEYBOARD_SPEAR) += spear-keyboard.o obj-$(CONFIG_KEYBOARD_STMPE) += stmpe-keypad.o obj-$(CONFIG_KEYBOARD_STOWAWAY) += stowaway.o diff --git a/drivers/input/keyboard/snvs_pwrkey.c b/drivers/input/keyboard/snvs_pwrkey.c new file mode 100644 index 0000000..98c340e --- /dev/null +++ b/drivers/input/keyboard/snvs_pwrkey.c @@ -0,0 +1,232 @@ +/* + * Driver for the IMX SNVS ON/OFF Power Key + * Copyright (C) 2015 Freescale Semiconductor, Inc. All Rights Reserved. + * + * The code contained herein is licensed under the GNU General Public + * License. You may obtain a copy of the GNU General Public License + * Version 2 or later at the following locations: + * + * http://www.opensource.org/licenses/gpl-license.html + * http://www.gnu.org/copyleft/gpl.html + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define SNVS_LPSR_REG 0x4C /* LP Status Register */ +#define SNVS_LPCR_REG 0x38 /* LP Control Register */ +#define SNVS_HPSR_REG 0x14 +#define SNVS_HPSR_BTN BIT(6) +#define SNVS_LPSR_SPO BIT(18) +#define SNVS_LPCR_DEP_EN BIT(5) + +#define DEBOUNCE_TIME 30 +#define REPEAT_INTERVAL 60 + +struct pwrkey_drv_data { + struct regmap *snvs; + int irq; + int keycode; + int keystate; /* 1:pressed */ + int wakeup; + struct timer_list check_timer; + struct input_dev *input; +}; + +static void imx_imx_snvs_check_for_events(unsigned long data) +{ + struct pwrkey_drv_data *pdata = (struct pwrkey_drv_data *) data; + struct input_dev *input = pdata->input; + u32 state; + + regmap_read(pdata->snvs, SNVS_HPSR_REG, &state); + state = state & SNVS_HPSR_BTN ? 1 : 0; + + /* only report new event if status changed */ + if (state ^ pdata->keystate) { + pdata->keystate = state; + input_event(input, EV_KEY, pdata->keycode, state); + input_sync(input); + pm_relax(pdata->input->dev.parent); + } + + /* repeat check if pressed long */ + if (state) { + mod_timer(&pdata->check_timer, + jiffies + msecs_to_jiffies(REPEAT_INTERVAL)); + } +} + +static irqreturn_t imx_snvs_pwrkey_interrupt(int irq, void *dev_id) +{ + struct platform_device *pdev = dev_id; + struct pwrkey_drv_data *pdata = platform_get_drvdata(pdev); + u32 lp_status; + + pm_wakeup_event(pdata->input->dev.parent, 0); + + regmap_read(pdata->snvs, SNVS_LPSR_REG, &lp_status); + if (lp_status & SNVS_LPSR_SPO) + mod_timer(&pdata->check_timer, jiffies + msecs_to_jiffies(DEBOUNCE_TIME)); + + /* clear SPO status */ + regmap_write(pdata->snvs, SNVS_LPSR_REG, SNVS_LPSR_SPO); + + return IRQ_HANDLED; +} + +static void imx_snvs_pwrkey_act(void *pdata) +{ + struct pwrkey_drv_data *pd = pdata; + + del_timer_sync(&pd->check_timer); +} + +static int imx_snvs_pwrkey_probe(struct platform_device *pdev) +{ + struct pwrkey_drv_data *pdata = NULL; + struct input_dev *input = NULL; + struct device_node *np, *snvs_np; + int error; + + /* Get SNVS register Page */ + np = pdev->dev.of_node; + if (!np) + return -ENODEV; + + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + if (!pdata) + return -ENOMEM; + + snvs_np = of_get_parent(pdev->dev.of_node); + if (!snvs_np) + return -ENODEV; + + pdata->snvs = syscon_node_to_regmap(snvs_np); + of_node_put(snvs_np); + + if (!pdata->snvs) { + pr_err("Can't get snvs syscon\n"); + return -ENODEV; + } + + if (of_property_read_u32(np, "linux,keycode", &pdata->keycode)) { + pdata->keycode = KEY_POWER; + dev_warn(&pdev->dev, "KEY_POWER without setting in dts\n"); + } + + pdata->wakeup = of_property_read_bool(np, "wakeup"); + + pdata->irq = platform_get_irq(pdev, 0); + if (pdata->irq < 0) { + dev_err(&pdev->dev, "no irq defined in platform data\n"); + return -EINVAL; + } + + regmap_update_bits(pdata->snvs, SNVS_LPCR_REG, SNVS_LPCR_DEP_EN, SNVS_LPCR_DEP_EN); + + /* clear the unexpected interrupt before driver ready */ + regmap_write(pdata->snvs, SNVS_LPSR_REG, SNVS_LPSR_SPO); + + setup_timer(&pdata->check_timer, + imx_imx_snvs_check_for_events, (unsigned long) pdata); + + input = devm_input_allocate_device(&pdev->dev); + if (!input) { + dev_err(&pdev->dev, "failed to allocate the input device\n"); + return -ENOMEM; + } + + input->name = pdev->name; + input->phys = "snvs-pwrkey/input0"; + input->id.bustype = BUS_HOST; + + input_set_capability(input, EV_KEY, pdata->keycode); + + /* input customer action to cancel release timer */ + error = devm_add_action(&pdev->dev, imx_snvs_pwrkey_act, pdata); + if (error) { + dev_err(&pdev->dev, "failed to register remove action\n"); + return error; + } + + error = devm_request_irq(&pdev->dev, pdata->irq, + imx_snvs_pwrkey_interrupt, + 0, pdev->name, pdev); + + if (error) { + dev_err(&pdev->dev, "interrupt not available.\n"); + return error; + } + + error = input_register_device(input); + if (error < 0) { + dev_err(&pdev->dev, "failed to register input device\n"); + input_free_device(input); + return error; + } + + pdata->input = input; + platform_set_drvdata(pdev, pdata); + + device_init_wakeup(&pdev->dev, pdata->wakeup); + + return 0; +} + +static int imx_snvs_pwrkey_suspend(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct pwrkey_drv_data *pdata = platform_get_drvdata(pdev); + + if (device_may_wakeup(&pdev->dev)) + enable_irq_wake(pdata->irq); + + return 0; +} + +static int imx_snvs_pwrkey_resume(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct pwrkey_drv_data *pdata = platform_get_drvdata(pdev); + + if (device_may_wakeup(&pdev->dev)) + disable_irq_wake(pdata->irq); + + return 0; +} + +static const struct of_device_id imx_snvs_pwrkey_ids[] = { + { .compatible = "fsl,sec-v4.0-pwrkey" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, imx_snvs_pwrkey_ids); + +static SIMPLE_DEV_PM_OPS(imx_snvs_pwrkey_pm_ops, imx_snvs_pwrkey_suspend, + imx_snvs_pwrkey_resume); + +static struct platform_driver imx_snvs_pwrkey_driver = { + .driver = { + .name = "snvs_pwrkey", + .pm = &imx_snvs_pwrkey_pm_ops, + .of_match_table = imx_snvs_pwrkey_ids, + }, + .probe = imx_snvs_pwrkey_probe, +}; +module_platform_driver(imx_snvs_pwrkey_driver); + +MODULE_AUTHOR("Freescale Semiconductor"); +MODULE_DESCRIPTION("i.MX snvs power key Driver"); +MODULE_LICENSE("GPL");