From patchwork Mon Jun 24 12:39:52 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Figa X-Patchwork-Id: 253819 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-oa0-x238.google.com (mail-oa0-x238.google.com [IPv6:2607:f8b0:4003:c02::238]) (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 5175E2C0098 for ; Mon, 24 Jun 2013 22:40:07 +1000 (EST) Received: by mail-oa0-f56.google.com with SMTP id h1sf3624243oag.11 for ; Mon, 24 Jun 2013 05:40:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=mime-version:x-beenthere:x-auditid:from:to:cc:subject:date :message-id:x-mailer:in-reply-to:references:x-brightmail-tracker :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=9B3jHq3htykRG8fqfyXgv/GnVjjDsstqYT60QdXkSXI=; b=yx5MX76tjm7eBNpJeGXsBQdipxclqZMSV6bom4ng/9IyuHCoSVkfSjHd5U0DF3JdCl U4W2oeXoVIpVr3Wh5XqmV3UZtnsmWRQCfCuKZYLf1XI+d/MIBvZtXZkRBnaeir8DcodK 25SHiZfCgz5Qd6roeFjlUXqf04YcFPIwBakglwIiMKUog0A8Q4dGsMYd5qJFaldeSVJi 8Mrr0TEF6YtZLLdgh6nNIe1zLU7w/k9kZgw9B1XtnmTbHmrNW0fEyI4bhkMsz4hE4bFY 9LF8GL/jH31eJEIC7OQL58RrE6oQbhcwrglUsBacaOqsklCW2QiV9k1kLynZj/IFGNNb b87w== X-Received: by 10.50.9.7 with SMTP id v7mr508234iga.2.1372077605579; Mon, 24 Jun 2013 05:40:05 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.50.11.82 with SMTP id o18ls2042627igb.14.canary; Mon, 24 Jun 2013 05:40:05 -0700 (PDT) X-Received: by 10.66.119.136 with SMTP id ku8mr4780156pab.10.1372077605132; Mon, 24 Jun 2013 05:40:05 -0700 (PDT) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com. [210.118.77.12]) by gmr-mx.google.com with ESMTP id rv7si2628130pbc.1.2013.06.24.05.40.04 for ; Mon, 24 Jun 2013 05:40:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of t.figa@samsung.com designates 210.118.77.12 as permitted sender) client-ip=210.118.77.12; Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout2.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MOW00AQXDT5MU10@mailout2.w1.samsung.com> for rtc-linux@googlegroups.com; Mon, 24 Jun 2013 13:40:03 +0100 (BST) X-AuditID: cbfec7f4-b7fd76d0000035e1-2e-51c83e23120e Received: from eusync2.samsung.com ( [203.254.199.212]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 44.DB.13793.32E38C15; Mon, 24 Jun 2013 13:40:03 +0100 (BST) Received: from amdc1227.digital.local ([106.116.147.199]) by eusync2.samsung.com (Oracle Communications Messaging Server 7u4-23.01(7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0MOW00H8UDUN1B20@eusync2.samsung.com>; Mon, 24 Jun 2013 13:40:03 +0100 (BST) From: Tomasz Figa To: linux-kernel@vger.kernel.org Cc: linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Kukjin Kim , Alessandro Zummo , Grant Likely , Jiri Kosina , Liam Girdwood , Mark Brown , Masanari Iida , Rob Herring , Rob Landley , rtc-linux@googlegroups.com, Russell King , Samuel Ortiz , Rasmus Villemoes , Tomasz Figa Subject: [rtc-linux] [PATCH v3 1/3] mfd: Add irq domain support for max8998 interrupts Date: Mon, 24 Jun 2013 14:39:52 +0200 Message-id: <1372077594-17052-2-git-send-email-t.figa@samsung.com> X-Mailer: git-send-email 1.8.2.1 In-reply-to: <1372077594-17052-1-git-send-email-t.figa@samsung.com> References: <1372077594-17052-1-git-send-email-t.figa@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrALMWRmVeSWpSXmKPExsVy+t/xK7rKdicCDRa9E7ZYcvEqu8XUh0/Y LA782cFosXvOYhaL3gVX2Sy+Xelgstj0+BqrxeVdc9gsZpzfx2Rx+zKvxeNZ89gsDq84wGSx 7uV0Fov9nR2MFqe7WS0uzbjObrF+xmsWB0GPluYeNo8Fn6+we+ycdZfdY8/Ek2wem1Z1snm8 Wj2T1ePOtT1sHvNOBnpsXlLvcaEr26NvyypGjzMLjrB7TJ/3k8nj8ya5AL4oLpuU1JzMstQi fbsErozP6xuYC46bV+yZ2cLawHhUt4uRg0NCwETi6+aELkZOIFNM4sK99WxdjFwcQgJLGSWu XZ/NDOH0MUlsmHyEBaSKTUBN4nPDIzYQW0RAQWJz7zNWkCJmgRssEh2Hm9lBEsICXhK3Lyxh BrFZBFQllq1+wwRi8wo4Saw5u4YRYp2CxPHt28BsTgFniQc/poLVCwHVPLrXyziBkXcBI8Mq RtHU0uSC4qT0XEO94sTc4tK8dL3k/NxNjJBY+LKDcfExq0OMAhyMSjy8Py2PBwqxJpYVV+Ye YpTgYFYS4Q0VOREoxJuSWFmVWpQfX1Sak1p8iJGJg1OqgXGLuIJ08D3Hc0sv/p38//3izW4c gixcAqeMbRfd5Piizf9O78Tua1G502w3bmgOZLjiG3+m99EtndZSx41MU97sS8mSS7A6uGba emadn9J24gyrvzktte3NW3iWq2NTa7zP/YZNMfUnW4+vTwic8n4R43+vuH2inPukxM+kVv2a e016qnW5p40SS3FGoqEWc1FxIgBEENuKYwIAAA== X-Original-Sender: t.figa@samsung.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: best guess record for domain of t.figa@samsung.com designates 210.118.77.12 as permitted sender) smtp.mail=t.figa@samsung.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: , This patch adds irq domain support for max8998 interrupts. To keep both non-DT and DT worlds happy, simple domain is used, which is linear when no explicit IRQ base is specified and legacy, with static mapping, otherwise. Signed-off-by: Tomasz Figa --- drivers/mfd/Kconfig | 1 + drivers/mfd/max8998-irq.c | 65 +++++++++++++++++++++++-------------- drivers/rtc/rtc-max8998.c | 12 ++++++- include/linux/mfd/max8998-private.h | 5 ++- include/linux/mfd/max8998.h | 2 +- 5 files changed, 57 insertions(+), 28 deletions(-) diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index d54e985..360be92 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -1002,6 +1002,7 @@ config MFD_TC6393XB config MFD_VX855 tristate "VIA VX855/VX875 integrated south bridge" depends on PCI && GENERIC_HARDIRQS + select IRQ_DOMAIN select MFD_CORE help Say yes here to enable support for various functions of the diff --git a/drivers/mfd/max8998-irq.c b/drivers/mfd/max8998-irq.c index 5919710..c469477 100644 --- a/drivers/mfd/max8998-irq.c +++ b/drivers/mfd/max8998-irq.c @@ -14,6 +14,7 @@ #include #include #include +#include #include struct max8998_irq_data { @@ -99,7 +100,8 @@ static struct max8998_irq_data max8998_irqs[] = { static inline struct max8998_irq_data * irq_to_max8998_irq(struct max8998_dev *max8998, int irq) { - return &max8998_irqs[irq - max8998->irq_base]; + struct irq_data *data = irq_get_irq_data(irq); + return &max8998_irqs[data->hwirq]; } static void max8998_irq_lock(struct irq_data *data) @@ -176,8 +178,14 @@ static irqreturn_t max8998_irq_thread(int irq, void *data) /* Report */ for (i = 0; i < MAX8998_IRQ_NR; i++) { - if (irq_reg[max8998_irqs[i].reg - 1] & max8998_irqs[i].mask) - handle_nested_irq(max8998->irq_base + i); + if (irq_reg[max8998_irqs[i].reg - 1] & max8998_irqs[i].mask) { + irq = irq_find_mapping(max8998->irq_domain, i); + if (WARN_ON(!irq)) { + disable_irq_nosync(max8998->irq); + return IRQ_NONE; + } + handle_nested_irq(irq); + } } return IRQ_HANDLED; @@ -185,27 +193,40 @@ static irqreturn_t max8998_irq_thread(int irq, void *data) int max8998_irq_resume(struct max8998_dev *max8998) { - if (max8998->irq && max8998->irq_base) - max8998_irq_thread(max8998->irq_base, max8998); + if (max8998->irq && max8998->irq_domain) + max8998_irq_thread(max8998->irq, max8998); + return 0; +} + +static int max8998_irq_domain_map(struct irq_domain *d, unsigned int irq, + irq_hw_number_t hw) +{ + struct max8997_dev *max8998 = d->host_data; + + irq_set_chip_data(irq, max8998); + irq_set_chip_and_handler(irq, &max8998_irq_chip, handle_edge_irq); + irq_set_nested_thread(irq, 1); +#ifdef CONFIG_ARM + set_irq_flags(irq, IRQF_VALID); +#else + irq_set_noprobe(irq); +#endif return 0; } +static struct irq_domain_ops max8998_irq_domain_ops = { + .map = max8998_irq_domain_map, +}; + int max8998_irq_init(struct max8998_dev *max8998) { int i; - int cur_irq; int ret; + struct irq_domain *domain; if (!max8998->irq) { dev_warn(max8998->dev, "No interrupt specified, no interrupts\n"); - max8998->irq_base = 0; - return 0; - } - - if (!max8998->irq_base) { - dev_err(max8998->dev, - "No interrupt base specified, no interrupts\n"); return 0; } @@ -221,19 +242,13 @@ int max8998_irq_init(struct max8998_dev *max8998) max8998_write_reg(max8998->i2c, MAX8998_REG_STATUSM1, 0xff); max8998_write_reg(max8998->i2c, MAX8998_REG_STATUSM2, 0xff); - /* register with genirq */ - for (i = 0; i < MAX8998_IRQ_NR; i++) { - cur_irq = i + max8998->irq_base; - irq_set_chip_data(cur_irq, max8998); - irq_set_chip_and_handler(cur_irq, &max8998_irq_chip, - handle_edge_irq); - irq_set_nested_thread(cur_irq, 1); -#ifdef CONFIG_ARM - set_irq_flags(cur_irq, IRQF_VALID); -#else - irq_set_noprobe(cur_irq); -#endif + domain = irq_domain_add_simple(NULL, MAX8998_IRQ_NR, + max8998->irq_base, &max8998_irq_domain_ops, max8998); + if (!domain) { + dev_err(max8998->dev, "could not create irq domain\n"); + return -ENODEV; } + max8998->irq_domain = domain; ret = request_threaded_irq(max8998->irq, NULL, max8998_irq_thread, IRQF_TRIGGER_FALLING | IRQF_ONESHOT, diff --git a/drivers/rtc/rtc-max8998.c b/drivers/rtc/rtc-max8998.c index d5af7ba..46f2301 100644 --- a/drivers/rtc/rtc-max8998.c +++ b/drivers/rtc/rtc-max8998.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -264,7 +265,6 @@ static int max8998_rtc_probe(struct platform_device *pdev) info->dev = &pdev->dev; info->max8998 = max8998; info->rtc = max8998->rtc; - info->irq = max8998->irq_base + MAX8998_IRQ_ALARM0; platform_set_drvdata(pdev, info); @@ -277,6 +277,15 @@ static int max8998_rtc_probe(struct platform_device *pdev) goto out_rtc; } + if (!max8998->irq_domain) + goto no_irq; + + info->irq = irq_create_mapping(max8998->irq_domain, MAX8998_IRQ_ALARM0); + if (!info->irq) { + dev_warn(&pdev->dev, "Failed to map alarm IRQ\n"); + goto no_irq; + } + ret = devm_request_threaded_irq(&pdev->dev, info->irq, NULL, max8998_rtc_alarm_irq, 0, "rtc-alarm0", info); @@ -284,6 +293,7 @@ static int max8998_rtc_probe(struct platform_device *pdev) dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n", info->irq, ret); +no_irq: dev_info(&pdev->dev, "RTC CHIP NAME: %s\n", pdev->id_entry->name); if (pdata && pdata->rtc_delay) { info->lp3974_bug_workaround = true; diff --git a/include/linux/mfd/max8998-private.h b/include/linux/mfd/max8998-private.h index effa5d3..bfb48b6 100644 --- a/include/linux/mfd/max8998-private.h +++ b/include/linux/mfd/max8998-private.h @@ -132,6 +132,8 @@ enum { #define MAX8998_ENRAMP (1 << 4) +struct irq_domain; + /** * struct max8998_dev - max8998 master device for sub-drivers * @dev: master device of the chip (can be used to access platform data) @@ -153,7 +155,8 @@ struct max8998_dev { struct mutex iolock; struct mutex irqlock; - int irq_base; + unsigned int irq_base; + struct irq_domain *irq_domain; int irq; int ono; u8 irq_masks_cur[MAX8998_NUM_IRQ_REGS]; diff --git a/include/linux/mfd/max8998.h b/include/linux/mfd/max8998.h index 6823548..7547118 100644 --- a/include/linux/mfd/max8998.h +++ b/include/linux/mfd/max8998.h @@ -100,7 +100,7 @@ struct max8998_regulator_data { struct max8998_platform_data { struct max8998_regulator_data *regulators; int num_regulators; - int irq_base; + unsigned int irq_base; int ono; bool buck_voltage_lock; int buck1_voltage1;