From patchwork Thu Mar 2 00:22:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 9599319 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 68934604A8 for ; Thu, 2 Mar 2017 00:23:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A27428576 for ; Thu, 2 Mar 2017 00:23:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4EF9F2857B; Thu, 2 Mar 2017 00:23:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED9BD28576 for ; Thu, 2 Mar 2017 00:23:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753909AbdCBAXE (ORCPT ); Wed, 1 Mar 2017 19:23:04 -0500 Received: from mail.kernel.org ([198.145.29.136]:51786 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753729AbdCBAXA (ORCPT ); Wed, 1 Mar 2017 19:23:00 -0500 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5BF0A20398; Thu, 2 Mar 2017 00:22:58 +0000 (UTC) Received: from mail.kernel.org (unknown [178.162.198.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D01BA2038A; Thu, 2 Mar 2017 00:22:56 +0000 (UTC) From: Sebastian Reichel To: Sebastian Reichel , Tony Lindgren , Dmitry Torokhov , Lee Jones Cc: Rob Herring , Mark Rutland , linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCHv2 1/2] mfd: cpcap: implement irq sense helper Date: Thu, 2 Mar 2017 01:22:41 +0100 Message-Id: <20170302002242.21819-1-sre@kernel.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170224085909.30559-1-sre@kernel.org> References: <20170224085909.30559-1-sre@kernel.org> X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP CPCAP can sense if IRQ is currently set or not. This functionality is required for a few subdevices, such as the power button and usb phy modules. Signed-off-by: Sebastian Reichel Acked-by: Tony Lindgren --- Changes since PATCHv1: - Newly introduced patch --- drivers/mfd/motorola-cpcap.c | 25 +++++++++++++++++++++++++ include/linux/mfd/motorola-cpcap.h | 2 ++ 2 files changed, 27 insertions(+) diff --git a/drivers/mfd/motorola-cpcap.c b/drivers/mfd/motorola-cpcap.c index 6aeada7d7ce5..b2a53750d579 100644 --- a/drivers/mfd/motorola-cpcap.c +++ b/drivers/mfd/motorola-cpcap.c @@ -32,6 +32,31 @@ struct cpcap_ddata { struct regmap *regmap; }; +static int cpcap_sense_irq(struct regmap *regmap, int irq) +{ + int reg = CPCAP_REG_INTS1 + (irq / 16) * 4; + int mask = 1 << (irq % 16); + int err, val; + + if (irq < 0 || irq > 64) + return -EINVAL; + + err = regmap_read(regmap, reg, &val); + if (err) + return err; + + return !!(val & mask); +} + +int cpcap_sense_virq(struct regmap *regmap, int virq) +{ + struct regmap_irq_chip_data *d = irq_get_chip_data(virq); + int base = regmap_irq_chip_get_base(d); + + return cpcap_sense_irq(regmap, virq - base); +} +EXPORT_SYMBOL_GPL(cpcap_sense_irq); + static int cpcap_check_revision(struct cpcap_ddata *cpcap) { u16 vendor, rev; diff --git a/include/linux/mfd/motorola-cpcap.h b/include/linux/mfd/motorola-cpcap.h index b4031c2b2214..7629e0d24d26 100644 --- a/include/linux/mfd/motorola-cpcap.h +++ b/include/linux/mfd/motorola-cpcap.h @@ -290,3 +290,5 @@ static inline int cpcap_get_vendor(struct device *dev, return 0; } + +int cpcap_sense_virq(struct regmap *regmap, int virq);