From patchwork Tue May 12 16:50:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 6390221 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9021CBEEE1 for ; Tue, 12 May 2015 18:02:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5EF46203B6 for ; Tue, 12 May 2015 18:02:45 +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 592F4203E3 for ; Tue, 12 May 2015 18:02:43 +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 1YsET9-0007Z9-Qw; Tue, 12 May 2015 17:59:51 +0000 Received: from mail-bn1bon0116.outbound.protection.outlook.com ([157.56.111.116] helo=na01-bn1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YsESx-0007UL-ES for linux-arm-kernel@lists.infradead.org; Tue, 12 May 2015 17:59:41 +0000 Received: from BN3PR0301CA0038.namprd03.prod.outlook.com (10.160.180.176) by CY1PR03MB1358.namprd03.prod.outlook.com (10.163.16.24) with Microsoft SMTP Server (TLS) id 15.1.160.19; Tue, 12 May 2015 17:59:16 +0000 Received: from BY2FFO11FD031.protection.gbl (2a01:111:f400:7c0c::173) by BN3PR0301CA0038.outlook.office365.com (2a01:111:e400:4000::48) with Microsoft SMTP Server (TLS) id 15.1.160.19 via Frontend Transport; Tue, 12 May 2015 17:59:15 +0000 Authentication-Results: spf=fail (sender IP is 192.88.158.2) 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.158.2 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Received: from az84smr01.freescale.net (192.88.158.2) by BY2FFO11FD031.mail.protection.outlook.com (10.1.14.196) with Microsoft SMTP Server (TLS) id 15.1.160.8 via Frontend Transport; Tue, 12 May 2015 17:59:15 +0000 Received: from shlinux2.ap.freescale.net (shlinux2.ap.freescale.net [10.192.224.44]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id t4CHx8Y5025914; Tue, 12 May 2015 10:59:12 -0700 From: To: , , Subject: [PATCH 2/3] input: keyboad: imx: add snvs power key driver Date: Wed, 13 May 2015 00:50:37 +0800 Message-ID: <1431449438-19460-2-git-send-email-Frank.Li@freescale.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1431449438-19460-1-git-send-email-Frank.Li@freescale.com> References: <1431449438-19460-1-git-send-email-Frank.Li@freescale.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD031; 1:+O+o7zAokRdu/2Zb/osYy1e1ojmFrPBf9rIDnLwY48W/dVv4IvZL3MG75zcWZE9EQXOVAcq6X3KL5UAIrDbpaPj4/CGNKUqMTHjDZuh+uP4zZgBQa90rBARwwALuQ0EEZvCzh0KW1U150vkgzzxyLbAkor6TT8rn5ASjgVv9cnGgr0FlRKcbYop+qTKUCfGCNY9uLfnEx4/U+42qycJrPr4Cl99e9lIbG/iAOGgVesbXyci3+kQm5CFh2aOGuzH0fg78K+qDwdiVzYX09fg7LuZqi4wTfji6hdt26htOVEz3gkys9QRwftUp9UeWjZu11u4NAveAFqffeBmnezJjGQ== X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(339900001)(189002)(199003)(76176999)(50986999)(229853001)(36756003)(105606002)(46102003)(104016003)(106466001)(86362001)(15975445007)(77096005)(19580395003)(19580405001)(48376002)(47776003)(62966003)(77156002)(85426001)(2201001)(86152002)(87936001)(6806004)(2950100001)(92566002)(50226001)(189998001)(50466002)(5001770100001)(5001960100002)(107886002)(4001430100001); DIR:OUT; SFP:1102; SCL:1; SRVR:CY1PR03MB1358; H:az84smr01.freescale.net; FPR:; SPF:Fail; MLV:sfv; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1PR03MB1358; 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:CY1PR03MB1358; BCL:0; PCL:0; RULEID:; SRVR:CY1PR03MB1358; X-Forefront-PRVS: 0574D4712B X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 May 2015 17:59:15.1363 (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.158.2]; Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR03MB1358 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150512_105939_842412_480C4B7C X-CRM114-Status: GOOD ( 16.24 ) X-Spam-Score: -0.0 (/) Cc: Frank Li , Robin Gong , linux-arm-kernel@lists.infradead.org, linux-input@vger.kernel.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=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 Signed-off-by: Robin Gong Signed-off-by: Frank Li --- drivers/input/keyboard/Kconfig | 7 ++ drivers/input/keyboard/Makefile | 1 + drivers/input/keyboard/snvs_pwrkey.c | 226 +++++++++++++++++++++++++++++++++++ 3 files changed, 234 insertions(+) create mode 100644 drivers/input/keyboard/snvs_pwrkey.c diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig index 106fbac..33c9bed 100644 --- a/drivers/input/keyboard/Kconfig +++ b/drivers/input/keyboard/Kconfig @@ -400,6 +400,13 @@ 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 "IMX6SX SNVS Power Key Driver" + depends on SOC_IMX6SX + help + This is the snvs powerkey driver for the Freescale i.MX6SX application + processors. + 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..24abbb4 --- /dev/null +++ b/drivers/input/keyboard/snvs_pwrkey.c @@ -0,0 +1,226 @@ +/* + * Copyright (C) 2011-2014 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 + +#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 (0x1 << 6) +#define SNVS_LPSR_SPO (0x1 << 18) +#define SNVS_LPCR_DEP_EN (0x1 << 5) + +struct pwrkey_drv_data { + void __iomem *ioaddr; + 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; + void __iomem *ioaddr = pdata->ioaddr; + u32 state; + + state = ((readl_relaxed(ioaddr + SNVS_HPSR_REG) & 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(60)); + } +} + +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); + void __iomem *ioaddr = pdata->ioaddr; + u32 lp_status; + + pm_wakeup_event(pdata->input->dev.parent, 0); + lp_status = readl_relaxed(ioaddr + SNVS_LPSR_REG); + if (lp_status & SNVS_LPSR_SPO) + mod_timer(&pdata->check_timer, jiffies + msecs_to_jiffies(2)); + + /* clear SPO status */ + writel_relaxed(lp_status, ioaddr + SNVS_LPSR_REG); + + return IRQ_HANDLED; +} + +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; + void __iomem *ioaddr; + u32 val; + int ret = 0; + + pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); + if (!pdata) + return -ENOMEM; + + /* Get SNVS register Page */ + np = of_find_compatible_node(NULL, NULL, "fsl,imx6sx-snvs-pwrkey"); + if (!np) + return -ENODEV; + pdata->ioaddr = of_iomap(np, 0); + if (IS_ERR(pdata->ioaddr)) + return PTR_ERR(pdata->ioaddr); + + if (of_property_read_u32(np, "fsl,keycode", &pdata->keycode)) { + pdata->keycode = KEY_POWER; + dev_warn(&pdev->dev, "KEY_POWER without setting in dts\n"); + } + + pdata->wakeup = !!of_get_property(np, "fsl,wakeup", NULL); + + pdata->irq = platform_get_irq(pdev, 0); + if (pdata->irq < 0) { + dev_err(&pdev->dev, "no irq defined in platform data\n"); + return -EINVAL; + } + + ioaddr = pdata->ioaddr; + val = readl_relaxed(ioaddr + SNVS_LPCR_REG); + val |= SNVS_LPCR_DEP_EN, + writel_relaxed(val, ioaddr + SNVS_LPCR_REG); + /* clear the unexpected interrupt before driver ready */ + val = readl_relaxed(ioaddr + SNVS_LPSR_REG); + if (val & SNVS_LPSR_SPO) + writel_relaxed(val | SNVS_LPSR_SPO, ioaddr + SNVS_LPSR_REG); + + setup_timer(&pdata->check_timer, + imx_imx_snvs_check_for_events, (unsigned long) pdata); + + if (pdata->irq >= 0) { + ret = devm_request_irq(&pdev->dev, pdata->irq, + imx_snvs_pwrkey_interrupt, + IRQF_TRIGGER_HIGH | IRQF_NO_SUSPEND, pdev->name, pdev); + if (ret) { + dev_err(&pdev->dev, "interrupt not available.\n"); + return ret; + } + } + + 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->evbit[0] = BIT_MASK(EV_KEY); + + input_set_capability(input, EV_KEY, pdata->keycode); + + ret = input_register_device(input); + if (ret < 0) { + dev_err(&pdev->dev, "failed to register input device\n"); + input_free_device(input); + return ret; + } + + pdata->input = input; + platform_set_drvdata(pdev, pdata); + + device_init_wakeup(&pdev->dev, pdata->wakeup); + + dev_info(&pdev->dev, "i.MX snvs powerkey probed\n"); + + return 0; +} + +static int imx_snvs_pwrkey_remove(struct platform_device *pdev) +{ + struct pwrkey_drv_data *pdata = platform_get_drvdata(pdev); + + input_unregister_device(pdata->input); + del_timer_sync(&pdata->check_timer); + + 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,imx6sx-snvs-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", + .owner = THIS_MODULE, + .pm = &imx_snvs_pwrkey_pm_ops, + .of_match_table = imx_snvs_pwrkey_ids, + }, + .probe = imx_snvs_pwrkey_probe, + .remove = imx_snvs_pwrkey_remove, +}; +module_platform_driver(imx_snvs_pwrkey_driver); + +MODULE_AUTHOR("Freescale Semiconductor"); +MODULE_DESCRIPTION("i.MX snvs power key Driver"); +MODULE_LICENSE("GPL");