From patchwork Tue Jul 10 05:07:33 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qiao Zhou X-Patchwork-Id: 170039 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-ob0-f184.google.com (mail-ob0-f184.google.com [209.85.214.184]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 263742C0081 for ; Tue, 10 Jul 2012 15:15:26 +1000 (EST) Received: by obbwc20 with SMTP id wc20sf12566381obb.11 for ; Mon, 09 Jul 2012 22:15:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=mime-version:x-beenthere:received-spf:from:to:cc:subject:date :message-id:x-mailer:in-reply-to:references:x-originalarrivaltime :x-original-sender:x-original-authentication-results:reply-to :precedence:mailing-list:list-id:x-google-group-id:list-post :list-help:list-archive:sender:list-subscribe:list-unsubscribe :content-type; bh=5hV/DKNCdx55QgRRENw542rKg9+RL/bBoToyOtnWjwA=; b=mRlz83W3yTJ2UhKo37p7UJUCz2hqvD7D8+G81BCGLpZfkfhMRaB+07sqmYHsuF0Oee mIvSTD+N6od29mun071RJ8z3ALA622co1j1u+rXsKudqVTdURJhXSIrZxPKonBzzr/WJ xiZcLjfGaqIrc/FHLdxK3ca8XPa6nPuCvCj/c= Received: by 10.68.244.100 with SMTP id xf4mr322571pbc.3.1341897323379; Mon, 09 Jul 2012 22:15:23 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.68.227.136 with SMTP id sa8ls13185103pbc.8.gmail; Mon, 09 Jul 2012 22:15:22 -0700 (PDT) Received: by 10.68.223.40 with SMTP id qr8mr23608864pbc.0.1341897322982; Mon, 09 Jul 2012 22:15:22 -0700 (PDT) Received: by 10.68.223.40 with SMTP id qr8mr23608863pbc.0.1341897322972; Mon, 09 Jul 2012 22:15:22 -0700 (PDT) Received: from na3sys009aog132.obsmtp.com ([74.125.149.250]) by gmr-mx.google.com with SMTP id oh7si1143622pbb.2.2012.07.09.22.15.05; Mon, 09 Jul 2012 22:15:22 -0700 (PDT) Received-SPF: temperror (google.com: error in processing during lookup of zhouqiao@marvell.com: DNS timeout) client-ip=74.125.149.250; Received: from MSI-MTA.marvell.com ([65.219.4.132]) by na3sys009aob132.postini.com ([74.125.148.12]) with SMTP ID DSNKT/u6WXq93DlLnymM+W22jhMMPYofmXbt@postini.com; Mon, 09 Jul 2012 22:15:22 PDT Received: from maili.marvell.com ([10.68.76.210]) by MSI-MTA.marvell.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 9 Jul 2012 22:07:34 -0700 Received: from localhost (unknown [10.38.36.111]) by maili.marvell.com (Postfix) with ESMTP id ED3734E50D; Mon, 9 Jul 2012 22:07:34 -0700 (PDT) From: Qiao Zhou To: arnd@arndb.de, broonie@opensource.wolfsonmicro.com, rpurdie@rpsys.net, a.zummo@towertech.it, sameo@linux.intel.com, wfg@linux.intel.com, haojian.zhuang@gmail.com, chao.xie@marvell.com, yu.tang@marvell.com, wilbur.wang@marvell.com, linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org, rtc-linux@googlegroups.com Cc: Qiao Zhou Subject: [rtc-linux] [PATCH V6 4/4] input: add onkey support to 88PM80X PMIC Date: Tue, 10 Jul 2012 13:07:33 +0800 Message-Id: <1341896853-29755-5-git-send-email-zhouqiao@marvell.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1341896853-29755-1-git-send-email-zhouqiao@marvell.com> References: <1341896853-29755-1-git-send-email-zhouqiao@marvell.com> X-OriginalArrivalTime: 10 Jul 2012 05:07:34.0765 (UTC) FILETIME=[EAC769D0:01CD5E59] X-Original-Sender: zhouqiao@marvell.com X-Original-Authentication-Results: gmr-mx.google.com; spf=temperror (google.com: error in processing during lookup of zhouqiao@marvell.com: DNS timeout) smtp.mail=zhouqiao@marvell.com Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: Sender: rtc-linux@googlegroups.com List-Subscribe: , List-Unsubscribe: , add onkey support to MARVELL 88PM80X PMIC. Signed-off-by: Qiao Zhou --- drivers/input/misc/88pm80x_onkey.c | 176 ++++++++++++++++++++++++++++++++++++ drivers/input/misc/Kconfig | 10 ++ drivers/input/misc/Makefile | 1 + 3 files changed, 187 insertions(+), 0 deletions(-) create mode 100644 drivers/input/misc/88pm80x_onkey.c diff --git a/drivers/input/misc/88pm80x_onkey.c b/drivers/input/misc/88pm80x_onkey.c new file mode 100644 index 0000000..807587f --- /dev/null +++ b/drivers/input/misc/88pm80x_onkey.c @@ -0,0 +1,176 @@ +/* + * 88pm80x_onkey.c - Marvell 88PM80x ONKEY driver + * + * Copyright (C) 2012 Marvell International Ltd. + * Haojian Zhuang + * Qiao Zhou + * + * This file is subject to the terms and conditions of the GNU General + * Public License. See the file "COPYING" in the main directory of this + * archive for more details. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include +#include +#include +#include + +#define PM800_LONG_ONKEY_EN (1 << 0) +#define PM800_LONG_KEY_DELAY (8) /* 1 .. 16 seconds */ +#define PM800_LONKEY_PRESS_TIME ((PM800_LONG_KEY_DELAY-1) << 4) +#define PM800_LONKEY_PRESS_TIME_MASK (0xF0) +#define PM800_SW_PDOWN (1 << 5) + +struct pm80x_onkey_info { + struct input_dev *idev; + struct pm80x_chip *pm80x; + struct regmap *map; + int irq; +}; + +/* 88PM80x gives us an interrupt when ONKEY is held */ +static irqreturn_t pm80x_onkey_handler(int irq, void *data) +{ + struct pm80x_onkey_info *info = data; + int ret = 0; + + regmap_read(info->map, PM800_STATUS_1, &ret); + ret &= PM800_ONKEY_STS1; + + input_report_key(info->idev, KEY_POWER, ret); + input_sync(info->idev); + + return IRQ_HANDLED; +} + +#ifdef CONFIG_PM +static int pm80x_onkey_suspend(struct device *dev) +{ + return pm80x_dev_suspend(dev); +} + +static int pm80x_onkey_resume(struct device *dev) +{ + return pm80x_dev_resume(dev); +} +#endif + +static SIMPLE_DEV_PM_OPS(pm80x_onkey_pm_ops, pm80x_onkey_suspend, + pm80x_onkey_resume); + +static int __devinit pm80x_onkey_probe(struct platform_device *pdev) +{ + + void *chip = dev_get_drvdata(pdev->dev.parent); + struct pm80x_onkey_info *info; + int ret; + + info = + devm_kzalloc(&pdev->dev, sizeof(struct pm80x_onkey_info), + GFP_KERNEL); + if (!info) + return -ENOMEM; + + info->pm80x = (struct pm80x_chip *)chip; + + info->irq = platform_get_irq(pdev, 0); + if (info->irq < 0) { + dev_err(&pdev->dev, "No IRQ resource!\n"); + return -EINVAL; + } + + info->map = info->pm80x->regmap; + if (!info->map) { + dev_err(&pdev->dev, "no regmap!\n"); + ret = -EINVAL; + goto out; + } + + info->idev = input_allocate_device(); + if (!info->idev) { + dev_err(&pdev->dev, "Failed to allocate input dev\n"); + ret = -ENOMEM; + goto out; + } + + info->idev->name = "88pm80x_on"; + info->idev->phys = "88pm80x_on/input0"; + info->idev->id.bustype = BUS_I2C; + info->idev->dev.parent = &pdev->dev; + info->idev->evbit[0] = BIT_MASK(EV_KEY); + info->idev->keybit[BIT_WORD(KEY_POWER)] = BIT_MASK(KEY_POWER); + + ret = input_register_device(info->idev); + if (ret) { + dev_err(&pdev->dev, "Can't register input device: %d\n", ret); + goto out_reg; + } + + ret = pm80x_request_irq(info->pm80x, info->irq, pm80x_onkey_handler, + IRQF_ONESHOT, "onkey", info); + if (ret < 0) { + dev_err(&pdev->dev, "Failed to request IRQ: #%d: %d\n", + info->irq, ret); + goto out_irq; + } + + platform_set_drvdata(pdev, info); + + /* Enable long onkey detection */ + regmap_update_bits(info->map, PM800_RTC_MISC4, PM800_LONG_ONKEY_EN, + PM800_LONG_ONKEY_EN); + /* Set 8-second interval */ + regmap_update_bits(info->map, PM800_RTC_MISC3, + PM800_LONKEY_PRESS_TIME_MASK, + PM800_LONKEY_PRESS_TIME); + + device_init_wakeup(&pdev->dev, 1); + return 0; + +out_irq: + input_unregister_device(info->idev); +out_reg: + input_free_device(info->idev); +out: + devm_kfree(&pdev->dev, info); + return ret; +} + +static int __devexit pm80x_onkey_remove(struct platform_device *pdev) +{ + struct pm80x_onkey_info *info = platform_get_drvdata(pdev); + + pm80x_free_irq(info->pm80x, info->irq, info); + input_unregister_device(info->idev); + input_free_device(info->idev); + devm_kfree(&pdev->dev, info); + return 0; +} + +static struct platform_driver pm80x_onkey_driver = { + .driver = { + .name = "88pm80x-onkey", + .owner = THIS_MODULE, + .pm = &pm80x_onkey_pm_ops, + }, + .probe = pm80x_onkey_probe, + .remove = __devexit_p(pm80x_onkey_remove), +}; + +module_platform_driver(pm80x_onkey_driver); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Marvell 88PM80x ONKEY driver"); +MODULE_AUTHOR("Qiao Zhou "); +MODULE_ALIAS("platform:88pm80x-onkey"); diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index 7faf4a7..7c0f1ec 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig @@ -22,6 +22,16 @@ config INPUT_88PM860X_ONKEY To compile this driver as a module, choose M here: the module will be called 88pm860x_onkey. +config INPUT_88PM80X_ONKEY + tristate "88PM80x ONKEY support" + depends on MFD_88PM800 + help + Support the ONKEY of Marvell 88PM80x PMICs as an input device + reporting power button status. + + To compile this driver as a module, choose M here: the module + will be called 88pm80x_onkey. + config INPUT_AB8500_PONKEY tristate "AB8500 Pon (PowerOn) Key" depends on AB8500_CORE diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile index f55cdf4..83fe6f5 100644 --- a/drivers/input/misc/Makefile +++ b/drivers/input/misc/Makefile @@ -5,6 +5,7 @@ # Each configuration option enables a list of files. obj-$(CONFIG_INPUT_88PM860X_ONKEY) += 88pm860x_onkey.o +obj-$(CONFIG_INPUT_88PM80X_ONKEY) += 88pm80x_onkey.o obj-$(CONFIG_INPUT_AB8500_PONKEY) += ab8500-ponkey.o obj-$(CONFIG_INPUT_AD714X) += ad714x.o obj-$(CONFIG_INPUT_AD714X_I2C) += ad714x-i2c.o