Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp8601581ybc; Fri, 29 Nov 2019 13:25:19 -0800 (PST) X-Google-Smtp-Source: APXvYqw/xdsMg9jTQ1ESPX+Nw6jU/v0GN1jn6cOrja4ryxEO5vC2wd8Y/wOs7dR7CeIKhXSsgI2B X-Received: by 2002:a50:9555:: with SMTP id v21mr47953173eda.90.1575062719668; Fri, 29 Nov 2019 13:25:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575062719; cv=none; d=google.com; s=arc-20160816; b=Bg4kviUpTXck/yJ6THe2ehLkUK5sR+zKcCoLaFYek9Vfz3jXU/94hOD3UmugbNRPYS gN0JtoZWqV0aH2CxUyI4n4XYtMZMlPNKSDsL2LKArkpmJeXJh33PUljfsDd5BTHLlrIg 4luxECPZ6wiy2U8UQwCYSJGc+ORwrK+dtNG9vaYVzJ+0h1z8ZiGdz2TC3gFrZiMjk29+ qx45e5jmYaQ81aIK5VRw8wJit9omECePdaP9dwrrlGMagMl+J8rxcnoM6Hqapa5aHQmc ubGpAWYJTGvyerXkK3V5Hev3X3LoHwgYdQyuvaLQDsjdatKccrTfycoIIfKxhPg0G/Mn Jxww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8sxzWMs2V/OQllfVDvsR445cEGiGCVgLHfjx3hHukdw=; b=FIEzLJ2bh4yfeluNGlmJnHT7LpmcrRxcUMmPTPKX+Syuyt/izBDBVgJrVNh3dR4rsE 3zXKm5dyGD5jFQvlrTPftu41x+gBVLJNcR5RUH4Gz8tcxLggJGnqLh+kXNl9ZKDBrF48 taTvLLxGiqI7bhc8Fjsondm6wqX9GjkwmYHLiD6jN1CzCeKkTqNpYfZE8EWk/hpHeTSh V5RmPy+l87ANd5Px1V0i4eHYLdX0HSOKACc7qL27YzGS44c5s9SWxoquHM9uf+FFyoH7 8c6jBlVGtT8ZRswTjQP4vDGM3XOHgm7DTJiLBhPReG/i3z0t0/r1Hxw4qPwxNvblILN7 11NA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kemnade.info header.s=20180802 header.b=JzHeBySM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id jt21si15425545ejb.390.2019.11.29.13.24.55; Fri, 29 Nov 2019 13:25:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@kemnade.info header.s=20180802 header.b=JzHeBySM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727328AbfK2VVj (ORCPT + 99 others); Fri, 29 Nov 2019 16:21:39 -0500 Received: from mail.andi.de1.cc ([85.214.55.253]:52446 "EHLO mail.andi.de1.cc" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727296AbfK2VVf (ORCPT ); Fri, 29 Nov 2019 16:21:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kemnade.info; s=20180802; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=8sxzWMs2V/OQllfVDvsR445cEGiGCVgLHfjx3hHukdw=; b=JzHeBySMGvM0hbKkzWPIr9bvsE EiuaeRIpoy9CbMaT6fI5ZmWyQ/lNVV6Q/fsIJA/k4eBEPonBK1jDjcyuT6zfkQfCeDTPKrqvT5I+s Wkf2gdm/ZAxHFFY7KHxH+0UtcQSDJIdcnCOKtN4niTDtRS82c4PmvZnLBCm31LoAwp6A=; Received: from p200300ccff0871001a3da2fffebfd33a.dip0.t-ipconnect.de ([2003:cc:ff08:7100:1a3d:a2ff:febf:d33a] helo=aktux) by mail.andi.de1.cc with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1ianhc-0001yX-ER; Fri, 29 Nov 2019 22:21:24 +0100 Received: from andi by aktux with local (Exim 4.92) (envelope-from ) id 1ianhc-0004mZ-6F; Fri, 29 Nov 2019 22:21:24 +0100 From: Andreas Kemnade To: lee.jones@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, a.zummo@towertech.it, alexandre.belloni@bootlin.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rtc@vger.kernel.org, stefan@agner.ch, b.galvani@gmail.com, phh@phh.me, letux-kernel@openphoenux.org Cc: Andreas Kemnade Subject: [PATCH v3 3/6] mfd: rn5t618: add irq support Date: Fri, 29 Nov 2019 22:20:42 +0100 Message-Id: <20191129212045.18325-4-andreas@kemnade.info> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191129212045.18325-1-andreas@kemnade.info> References: <20191129212045.18325-1-andreas@kemnade.info> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Score: -1.0 (-) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This adds support for irq handling in the rc5t619 which is required for properly implementing subdevices like rtc. For now only definitions for the variant rc5t619 are included. Signed-off-by: Andreas Kemnade --- Changes in v3: alignment cleanup Changes in v2: - no dead code, did some more testing and thinking for that - remove extra empty lines drivers/mfd/Kconfig | 1 + drivers/mfd/Makefile | 2 +- drivers/mfd/rn5t618-core.c | 34 ++++++++++++++- drivers/mfd/rn5t618-irq.c | 85 +++++++++++++++++++++++++++++++++++++ include/linux/mfd/rn5t618.h | 16 +++++++ 5 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 drivers/mfd/rn5t618-irq.c diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index ae24d3ea68ea..522e068d0082 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -1057,6 +1057,7 @@ config MFD_RN5T618 depends on OF select MFD_CORE select REGMAP_I2C + select REGMAP_IRQ help Say yes here to add support for the Ricoh RN5T567, RN5T618, RC5T619 PMIC. diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 110ea700231b..2906d5db67d0 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -217,7 +217,7 @@ obj-$(CONFIG_MFD_VIPERBOARD) += viperboard.o obj-$(CONFIG_MFD_RC5T583) += rc5t583.o rc5t583-irq.o obj-$(CONFIG_MFD_RK808) += rk808.o -rn5t618-objs := rn5t618-core.o +rn5t618-objs := rn5t618-core.o rn5t618-irq.o obj-$(CONFIG_MFD_RN5T618) += rn5t618.o obj-$(CONFIG_MFD_SEC_CORE) += sec-core.o sec-irq.o obj-$(CONFIG_MFD_SYSCON) += syscon.o diff --git a/drivers/mfd/rn5t618-core.c b/drivers/mfd/rn5t618-core.c index da5cd9c92a59..1e2326217681 100644 --- a/drivers/mfd/rn5t618-core.c +++ b/drivers/mfd/rn5t618-core.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -105,7 +106,8 @@ static int rn5t618_i2c_probe(struct i2c_client *i2c, i2c_set_clientdata(i2c, priv); priv->variant = (long)of_id->data; - + priv->chip_irq = i2c->irq; + priv->dev = &i2c->dev; priv->regmap = devm_regmap_init_i2c(i2c, &rn5t618_regmap_config); if (IS_ERR(priv->regmap)) { ret = PTR_ERR(priv->regmap); @@ -137,6 +139,11 @@ static int rn5t618_i2c_probe(struct i2c_client *i2c, return ret; } + if (priv->chip_irq > 0) { + if (rn5t618_irq_init(priv)) + priv->chip_irq = 0; + } + return 0; } @@ -154,15 +161,40 @@ static int rn5t618_i2c_remove(struct i2c_client *i2c) return 0; } +static int __maybe_unused rn5t618_i2c_suspend(struct device *dev) +{ + struct rn5t618 *priv = dev_get_drvdata(dev); + + if (priv->chip_irq) + disable_irq(priv->chip_irq); + + return 0; +} + +static int __maybe_unused rn5t618_i2c_resume(struct device *dev) +{ + struct rn5t618 *priv = dev_get_drvdata(dev); + + if (priv->chip_irq) + enable_irq(priv->chip_irq); + + return 0; +} + static const struct i2c_device_id rn5t618_i2c_id[] = { { } }; MODULE_DEVICE_TABLE(i2c, rn5t618_i2c_id); +static SIMPLE_DEV_PM_OPS(rn5t618_i2c_dev_pm_ops, + rn5t618_i2c_suspend, + rn5t618_i2c_resume); + static struct i2c_driver rn5t618_i2c_driver = { .driver = { .name = "rn5t618", .of_match_table = of_match_ptr(rn5t618_of_match), + .pm = &rn5t618_i2c_dev_pm_ops, }, .probe = rn5t618_i2c_probe, .remove = rn5t618_i2c_remove, diff --git a/drivers/mfd/rn5t618-irq.c b/drivers/mfd/rn5t618-irq.c new file mode 100644 index 000000000000..8a4c56429768 --- /dev/null +++ b/drivers/mfd/rn5t618-irq.c @@ -0,0 +1,85 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2019 Andreas Kemnade + */ +#include +#include +#include +#include +#include + +#include + +static const struct regmap_irq rc5t619_irqs[] = { + [RN5T618_IRQ_SYS] = { + .reg_offset = 0, + .mask = (0 << 1) + }, + [RN5T618_IRQ_DCDC] = { + .reg_offset = 0, + .mask = (1 << 1) + }, + [RN5T618_IRQ_RTC] = { + .reg_offset = 0, + .mask = (1 << 2) + }, + [RN5T618_IRQ_ADC] = { + .reg_offset = 0, + .mask = (1 << 3) + }, + [RN5T618_IRQ_GPIO] = { + .reg_offset = 0, + .mask = (1 << 4) + }, + [RN5T618_IRQ_CHG] = { + .reg_offset = 0, + .mask = (1 << 6), + } +}; + +static const struct regmap_irq_chip rc5t619_irq_chip = { + .name = "rc5t619", + .irqs = rc5t619_irqs, + .num_irqs = ARRAY_SIZE(rc5t619_irqs), + .num_regs = 1, + .status_base = RN5T618_INTMON, + .mask_base = RN5T618_INTEN, + .mask_invert = true, +}; + +int rn5t618_irq_init(struct rn5t618 *rn5t618) +{ + const struct regmap_irq_chip *irq_chip; + int ret; + + if (!rn5t618->chip_irq) + return 0; + + switch (rn5t618->variant) { + case RC5T619: + irq_chip = &rc5t619_irq_chip; + break; + + /* TODO: check irq definitions for other variants */ + + default: + irq_chip = NULL; + break; + } + + if (!irq_chip) { + dev_err(rn5t618->dev, "no IRQ definition known for variant\n"); + return -ENOENT; + } + + ret = devm_regmap_add_irq_chip(rn5t618->dev, rn5t618->regmap, + rn5t618->chip_irq, + IRQF_TRIGGER_FALLING | IRQF_ONESHOT, + 0, irq_chip, &rn5t618->irq_data); + if (ret != 0) { + dev_err(rn5t618->dev, "Failed to register IRQ chip\n"); + return ret; + } + + return 0; +} diff --git a/include/linux/mfd/rn5t618.h b/include/linux/mfd/rn5t618.h index d62ef48060b5..edd2b6485e3b 100644 --- a/include/linux/mfd/rn5t618.h +++ b/include/linux/mfd/rn5t618.h @@ -242,9 +242,25 @@ enum { RC5T619, }; +/* RN5T618 IRQ definitions */ +enum { + RN5T618_IRQ_SYS, + RN5T618_IRQ_DCDC, + RN5T618_IRQ_RTC, + RN5T618_IRQ_ADC, + RN5T618_IRQ_GPIO, + RN5T618_IRQ_CHG, + RN5T618_NR_IRQS, +}; + struct rn5t618 { struct regmap *regmap; + struct device *dev; long variant; + + int chip_irq; + struct regmap_irq_chip_data *irq_data; }; +extern int rn5t618_irq_init(struct rn5t618 *rn5t618); #endif /* __LINUX_MFD_RN5T618_H */ -- 2.20.1