From patchwork Wed Apr 18 09:31:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: thomas.abraham@linaro.org X-Patchwork-Id: 7915 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 69F6A23E4C for ; Wed, 18 Apr 2012 09:22:33 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id 1952EA18844 for ; Wed, 18 Apr 2012 09:22:32 +0000 (UTC) Received: by mail-iy0-f180.google.com with SMTP id e36so13939631iag.11 for ; Wed, 18 Apr 2012 02:22:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:x-auditid :from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-brightmail-tracker:x-tm-as-mml:x-gm-message-state; bh=gYZQMQXXkokXaOYCa3r3O4n6YUl6elLG84kOgLssyYY=; b=UzFoLP4bxkzJG/EawbnTlxXsz4BtNPZxJtxx/eEQoKwz6oIwG80VBmNigZedqwx9y5 hyB0JKxBGIxGWlsWe44wM4UDRdVXpjYrZq44JES2uHNv7XbNJZE+pdLXLGRCho8JkXlh s0BV8NbBm6wr2gQ5uXPB8iOTuwCp7MOnDmmizzCFxeeLSxtXZx+j6h2kVnpB3tUix05M PsuoS7vKXGvzY0nc8NxYM55eZhUufQaXUrEOA6jpkoOtBKNa0lmpz6/EEOfDk8j3M0aJ g1KlGQ8BG/TKmcof9C137JVHy8F+WTkqzNgfmrv6yvt7veVHWhSZKDwVtR7w2YLjcutS bfog== Received: by 10.50.194.163 with SMTP id hx3mr1793264igc.49.1334740952818; Wed, 18 Apr 2012 02:22:32 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.137.198 with SMTP id x6csp204530ibt; Wed, 18 Apr 2012 02:22:32 -0700 (PDT) Received: by 10.68.138.193 with SMTP id qs1mr5008644pbb.70.1334740951790; Wed, 18 Apr 2012 02:22:31 -0700 (PDT) Received: from mailout4.samsung.com (mailout4.samsung.com. [203.254.224.34]) by mx.google.com with ESMTP id vs4si2464530pbc.337.2012.04.18.02.22.30; Wed, 18 Apr 2012 02:22:31 -0700 (PDT) Received-SPF: neutral (google.com: 203.254.224.34 is neither permitted nor denied by best guess record for domain of thomas.abraham@linaro.org) client-ip=203.254.224.34; Authentication-Results: mx.google.com; spf=neutral (google.com: 203.254.224.34 is neither permitted nor denied by best guess record for domain of thomas.abraham@linaro.org) smtp.mail=thomas.abraham@linaro.org Received: from epcpsbgm2.samsung.com (mailout4.samsung.com [203.254.224.34]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0M2O00MWN4OR86W0@mailout4.samsung.com> for patches@linaro.org; Wed, 18 Apr 2012 18:22:29 +0900 (KST) X-AuditID: cbfee61b-b7cb4ae000000d81-c9-4f8e87d55a9d Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2.samsung.com (MMPCPMTA) with SMTP id 3A.50.03457.5D78E8F4; Wed, 18 Apr 2012 18:22:29 +0900 (KST) Received: from localhost.localdomain ([107.108.73.37]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0M2O007YQ4OUUW40@mmp2.samsung.com> for patches@linaro.org; Wed, 18 Apr 2012 18:22:29 +0900 (KST) From: Thomas Abraham To: linux-kernel@vger.kernel.org Cc: k.lewandowsk@samsung.com, devicetree-discuss@lists.ozlabs.org, rob.herring@calxeda.com, grant.likely@secretlab.ca, kgene.kim@samsung.com, broonie@opensource.wolfsonmicro.com, myungjoo.ham@samsung.com, kyungmin.park@samsung.com, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, patches@linaro.org Subject: [PATCH v5 1/2] mfd: add irq domain support for max8997 interrupts Date: Wed, 18 Apr 2012 15:01:02 +0530 Message-id: <1334741463-25058-2-git-send-email-thomas.abraham@linaro.org> X-Mailer: git-send-email 1.6.6.rc2 In-reply-to: <1334741463-25058-1-git-send-email-thomas.abraham@linaro.org> References: <1334741463-25058-1-git-send-email-thomas.abraham@linaro.org> X-Brightmail-Tracker: AAAAAA== X-TM-AS-MML: No X-Gm-Message-State: ALoCoQnJCJYhBhCYvrgpCPTJB0dhtfelqpphxpEdLImwRmVUdiWvN/52SQj+er8drzQxHf5rPtVC Add irq domain support for max8997 interrupts. The reverse mapping method used is linear mapping since the sub-drivers of max8997 such as regulator and charger drivers can use the max8997 irq_domain to get the linux irq number for max8997 interrupts. All uses of irq_base in platform data and max8997 driver private data are removed. Cc: Karol Lewandowski Cc: MyungJoo Ham Signed-off-by: Thomas Abraham Acked-by: Grant Likely --- arch/arm/mach-exynos/mach-nuri.c | 4 -- arch/arm/mach-exynos/mach-origen.c | 1 - drivers/mfd/max8997-irq.c | 70 ++++++++++++++++++----------------- drivers/mfd/max8997.c | 1 - include/linux/mfd/max8997-private.h | 4 +- include/linux/mfd/max8997.h | 1 - 6 files changed, 39 insertions(+), 42 deletions(-) diff --git a/arch/arm/mach-exynos/mach-nuri.c b/arch/arm/mach-exynos/mach-nuri.c index 91e5986..d5496d9 100644 --- a/arch/arm/mach-exynos/mach-nuri.c +++ b/arch/arm/mach-exynos/mach-nuri.c @@ -1034,12 +1034,8 @@ static struct platform_device nuri_max8903_device = { static void __init nuri_power_init(void) { int gpio; - int irq_base = IRQ_GPIO_END + 1; int ta_en = 0; - nuri_max8997_pdata.irq_base = irq_base; - irq_base += MAX8997_IRQ_NR; - gpio = EXYNOS4_GPX0(7); gpio_request(gpio, "AP_PMIC_IRQ"); s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(0xf)); diff --git a/arch/arm/mach-exynos/mach-origen.c b/arch/arm/mach-exynos/mach-origen.c index 827cb99..d3b2e9d 100644 --- a/arch/arm/mach-exynos/mach-origen.c +++ b/arch/arm/mach-exynos/mach-origen.c @@ -424,7 +424,6 @@ static struct max8997_platform_data __initdata origen_max8997_pdata = { .buck1_gpiodvs = false, .buck2_gpiodvs = false, .buck5_gpiodvs = false, - .irq_base = IRQ_GPIO_END + 1, .ignore_gpiodvs_side_effect = true, .buck125_default_idx = 0x0, diff --git a/drivers/mfd/max8997-irq.c b/drivers/mfd/max8997-irq.c index 09274cf..42ea220 100644 --- a/drivers/mfd/max8997-irq.c +++ b/drivers/mfd/max8997-irq.c @@ -139,17 +139,10 @@ static void max8997_irq_sync_unlock(struct irq_data *data) mutex_unlock(&max8997->irqlock); } -static const inline struct max8997_irq_data * -irq_to_max8997_irq(struct max8997_dev *max8997, int irq) -{ - return &max8997_irqs[irq - max8997->irq_base]; -} - static void max8997_irq_mask(struct irq_data *data) { struct max8997_dev *max8997 = irq_get_chip_data(data->irq); - const struct max8997_irq_data *irq_data = irq_to_max8997_irq(max8997, - data->irq); + const struct max8997_irq_data *irq_data = &max8997_irqs[data->hwirq]; max8997->irq_masks_cur[irq_data->group] |= irq_data->mask; } @@ -157,8 +150,7 @@ static void max8997_irq_mask(struct irq_data *data) static void max8997_irq_unmask(struct irq_data *data) { struct max8997_dev *max8997 = irq_get_chip_data(data->irq); - const struct max8997_irq_data *irq_data = irq_to_max8997_irq(max8997, - data->irq); + const struct max8997_irq_data *irq_data = &max8997_irqs[data->hwirq]; max8997->irq_masks_cur[irq_data->group] &= ~irq_data->mask; } @@ -182,7 +174,7 @@ static irqreturn_t max8997_irq_thread(int irq, void *data) u8 irq_reg[MAX8997_IRQ_GROUP_NR] = {}; u8 irq_src; int ret; - int i; + int i, cur_irq; ret = max8997_read_reg(max8997->i2c, MAX8997_REG_INTSRC, &irq_src); if (ret < 0) { @@ -269,8 +261,11 @@ static irqreturn_t max8997_irq_thread(int irq, void *data) /* Report */ for (i = 0; i < MAX8997_IRQ_NR; i++) { - if (irq_reg[max8997_irqs[i].group] & max8997_irqs[i].mask) - handle_nested_irq(max8997->irq_base + i); + if (irq_reg[max8997_irqs[i].group] & max8997_irqs[i].mask) { + cur_irq = irq_find_mapping(max8997->irq_domain, i); + if (cur_irq) + handle_nested_irq(cur_irq); + } } return IRQ_HANDLED; @@ -278,26 +273,40 @@ static irqreturn_t max8997_irq_thread(int irq, void *data) int max8997_irq_resume(struct max8997_dev *max8997) { - if (max8997->irq && max8997->irq_base) - max8997_irq_thread(max8997->irq_base, max8997); + if (max8997->irq && max8997->irq_domain) + max8997_irq_thread(0, max8997); + return 0; +} + +static int max8997_irq_domain_map(struct irq_domain *d, unsigned int irq, + irq_hw_number_t hw) +{ + struct max8997_dev *max8997 = d->host_data; + + irq_set_chip_data(irq, max8997); + irq_set_chip_and_handler(irq, &max8997_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 max8997_irq_domain_ops = { + .map = max8997_irq_domain_map, +}; + int max8997_irq_init(struct max8997_dev *max8997) { + struct irq_domain *domain; int i; - int cur_irq; int ret; u8 val; if (!max8997->irq) { dev_warn(max8997->dev, "No interrupt specified.\n"); - max8997->irq_base = 0; - return 0; - } - - if (!max8997->irq_base) { - dev_err(max8997->dev, "No interrupt base specified.\n"); return 0; } @@ -327,18 +336,11 @@ int max8997_irq_init(struct max8997_dev *max8997) true : false; } - /* Register with genirq */ - for (i = 0; i < MAX8997_IRQ_NR; i++) { - cur_irq = i + max8997->irq_base; - irq_set_chip_data(cur_irq, max8997); - irq_set_chip_and_handler(cur_irq, &max8997_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_linear(NULL, MAX8997_IRQ_NR, + &max8997_irq_domain_ops, &max8997); + if (!domain) { + dev_err(max8997->dev, "could not create irq domain\n"); + return -ENODEV; } ret = request_threaded_irq(max8997->irq, NULL, max8997_irq_thread, diff --git a/drivers/mfd/max8997.c b/drivers/mfd/max8997.c index cb83a7a..20ecad3 100644 --- a/drivers/mfd/max8997.c +++ b/drivers/mfd/max8997.c @@ -143,7 +143,6 @@ static int max8997_i2c_probe(struct i2c_client *i2c, if (!pdata) goto err; - max8997->irq_base = pdata->irq_base; max8997->ono = pdata->ono; mutex_init(&max8997->iolock); diff --git a/include/linux/mfd/max8997-private.h b/include/linux/mfd/max8997-private.h index 3f4deb6..830152c 100644 --- a/include/linux/mfd/max8997-private.h +++ b/include/linux/mfd/max8997-private.h @@ -23,6 +23,8 @@ #define __LINUX_MFD_MAX8997_PRIV_H #include +#include +#include #define MAX8997_REG_INVALID (0xff) @@ -325,7 +327,7 @@ struct max8997_dev { int irq; int ono; - int irq_base; + struct irq_domain *irq_domain; struct mutex irqlock; int irq_masks_cur[MAX8997_IRQ_GROUP_NR]; int irq_masks_cache[MAX8997_IRQ_GROUP_NR]; diff --git a/include/linux/mfd/max8997.h b/include/linux/mfd/max8997.h index 28726dd..24b1a76 100644 --- a/include/linux/mfd/max8997.h +++ b/include/linux/mfd/max8997.h @@ -204,7 +204,6 @@ struct max8997_led_platform_data { struct max8997_platform_data { /* IRQ */ - int irq_base; int ono; int wakeup;