From patchwork Tue Jan 15 12:55:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 14068 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 8FBB223E2E for ; Tue, 15 Jan 2013 12:57:00 +0000 (UTC) Received: from mail-vb0-f48.google.com (mail-vb0-f48.google.com [209.85.212.48]) by fiordland.canonical.com (Postfix) with ESMTP id 33D84A19341 for ; Tue, 15 Jan 2013 12:57:00 +0000 (UTC) Received: by mail-vb0-f48.google.com with SMTP id fc21so56137vbb.7 for ; Tue, 15 Jan 2013 04:56:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=tZ1bqG/2/EUcdVFCToOf/+b4AMWmwjH8F3eaTZf3FVM=; b=dbesBQ8qseEaNJWWaCn8lmNmSt2qWeJF3iWpBkYRfMWatz9uv7RL/+PuaQg3n/wR8L /+GLXXViEGy+6HWQHNNwZ4WYj6UcMlIECUzZCHWNdffl039yyAWXvGp2DeXDa7q8gkuU gS9F8V75CG9aQYS+7qG/4/qOjNJLySOVjYccVM8oRghr2hKqJ37bnCG5PpzJpXCeW4uf emlKbMACz0EPNZ5k/gP3Je1rFT3DWuWtSKgv1kOgoODc3E4qZTvBWjeY5Y0edJWOMqIg v55FGapjDk/5ww6fHb+zcvBTqC3jHQZG7tVoHbdy6xKv+JUX7yGB/1eegUs5MPS4wJjT C34A== X-Received: by 10.58.196.196 with SMTP id io4mr108341190vec.22.1358254619652; Tue, 15 Jan 2013 04:56:59 -0800 (PST) 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.58.145.101 with SMTP id st5csp110626veb; Tue, 15 Jan 2013 04:56:59 -0800 (PST) X-Received: by 10.194.19.10 with SMTP id a10mr141206449wje.45.1358254618765; Tue, 15 Jan 2013 04:56:58 -0800 (PST) Received: from mail-wi0-f178.google.com (mail-wi0-f178.google.com [209.85.212.178]) by mx.google.com with ESMTPS id cz9si3384678wib.14.2013.01.15.04.56.58 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 15 Jan 2013 04:56:58 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.178 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=209.85.212.178; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.178 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) smtp.mail=lee.jones@linaro.org Received: by mail-wi0-f178.google.com with SMTP id hn3so63517wib.5 for ; Tue, 15 Jan 2013 04:56:58 -0800 (PST) X-Received: by 10.180.78.66 with SMTP id z2mr3551288wiw.23.1358254618369; Tue, 15 Jan 2013 04:56:58 -0800 (PST) Received: from localhost.localdomain (cpc1-aztw13-0-0-cust473.18-1.cable.virginmedia.com. [77.102.241.218]) by mx.google.com with ESMTPS id eo10sm3672833wib.9.2013.01.15.04.56.56 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 15 Jan 2013 04:56:57 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: arnd@arndb.de, linus.walleij@stericsson.com, sameo@linux.intel.com, Lee Jones Subject: [PATCH 19/26] mfd: ab8500-debugfs: Allow number of IRQs to be provided more dynamically Date: Tue, 15 Jan 2013 12:55:59 +0000 Message-Id: <1358254566-12419-20-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1358254566-12419-1-git-send-email-lee.jones@linaro.org> References: <1358254566-12419-1-git-send-email-lee.jones@linaro.org> X-Gm-Message-State: ALoCoQkR54/rJd3vay2cqHsLMTDwJgHEsQbWHS2VbCxwDqoF9YYDAoyxUZHKIAQnY0Nj9IdQtiDN From: Linus Walleij With the introduction of new AB* platforms, it's important to allow as much code reuse as possible. By allowing a system's number of IRQs to be dynamically passed, we can reuse almost all of the -debugfs driver. Signed-off-by: Lee Jones Signed-off-by: Linus Walleij --- drivers/mfd/ab8500-debugfs.c | 51 +++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c index ec57e43..d23b6cc 100644 --- a/drivers/mfd/ab8500-debugfs.c +++ b/drivers/mfd/ab8500-debugfs.c @@ -94,10 +94,11 @@ static u32 debug_address; static int irq_first; static int irq_last; -static u32 irq_count[AB8500_NR_IRQS]; +static u32 *irq_count; +static int num_irqs; -static struct device_attribute *dev_attr[AB8500_NR_IRQS]; -static char *event_name[AB8500_NR_IRQS]; +static struct device_attribute **dev_attr; +static char **event_name; /** * struct ab8500_reg_range @@ -483,7 +484,7 @@ static irqreturn_t ab8500_debug_handler(int irq, void *data) struct kobject *kobj = (struct kobject *)data; unsigned int irq_abb = irq - irq_first; - if (irq_abb < AB8500_NR_IRQS) + if (irq_abb < num_irqs) irq_count[irq_abb]++; /* * This makes it possible to use poll for events (POLLPRI | POLLERR) @@ -1338,7 +1339,7 @@ static ssize_t show_irq(struct device *dev, return err; irq_index = name - irq_first; - if (irq_index >= AB8500_NR_IRQS) + if (irq_index >= num_irqs) return -EINVAL; else return sprintf(buf, "%u\n", irq_count[irq_index]); @@ -1374,7 +1375,7 @@ static ssize_t ab8500_subscribe_write(struct file *file, } irq_index = user_val - irq_first; - if (irq_index >= AB8500_NR_IRQS) + if (irq_index >= num_irqs) return -EINVAL; /* @@ -1438,7 +1439,7 @@ static ssize_t ab8500_unsubscribe_write(struct file *file, } irq_index = user_val - irq_first; - if (irq_index >= AB8500_NR_IRQS) + if (irq_index >= num_irqs) return -EINVAL; /* Set irq count to 0 when unsubscribe */ @@ -1519,21 +1520,40 @@ static struct dentry *ab8500_gpadc_dir; static int __devinit ab8500_debug_probe(struct platform_device *plf) { struct dentry *file; + int ret = -ENOMEM; + struct ab8500 *ab8500; debug_bank = AB8500_MISC; debug_address = AB8500_REV_REG & 0x00FF; + ab8500 = dev_get_drvdata(plf->dev.parent); + num_irqs = ab8500->mask_size; + + irq_count = kzalloc(sizeof(irq_count)*num_irqs, GFP_KERNEL); + if (!irq_count) + return -ENOMEM; + + dev_attr = kzalloc(sizeof(*dev_attr)*num_irqs,GFP_KERNEL); + if (!dev_attr) + goto out_freeirq_count; + + event_name = kzalloc(sizeof(*event_name)*num_irqs, GFP_KERNEL); + if (!event_name) + goto out_freedev_attr; + irq_first = platform_get_irq_byname(plf, "IRQ_FIRST"); if (irq_first < 0) { dev_err(&plf->dev, "First irq not found, err %d\n", irq_first); - return irq_first; + ret = irq_first; + goto out_freeevent_name; } irq_last = platform_get_irq_byname(plf, "IRQ_LAST"); if (irq_last < 0) { dev_err(&plf->dev, "Last irq not found, err %d\n", irq_last); - return irq_last; + ret = irq_last; + goto out_freeevent_name; } ab8500_dir = debugfs_create_dir(AB8500_NAME_STRING, NULL); @@ -1656,12 +1676,23 @@ err: if (ab8500_dir) debugfs_remove_recursive(ab8500_dir); dev_err(&plf->dev, "failed to create debugfs entries.\n"); - return -ENOMEM; +out_freeevent_name: + kfree(event_name); +out_freedev_attr: + kfree(dev_attr); +out_freeirq_count: + kfree(irq_count); + + return ret; } static int __devexit ab8500_debug_remove(struct platform_device *plf) { debugfs_remove_recursive(ab8500_dir); + kfree(event_name); + kfree(dev_attr); + kfree(irq_count); + return 0; }