From patchwork Tue Jan 15 12:55:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 14066 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 B91A723E2E for ; Tue, 15 Jan 2013 12:56:57 +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 62CFBA19341 for ; Tue, 15 Jan 2013 12:56:57 +0000 (UTC) Received: by mail-vb0-f48.google.com with SMTP id fc21so53076vbb.35 for ; Tue, 15 Jan 2013 04:56:57 -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=8Sp9aJeCIQNVJjr3Gvic1AVwW4oGe1bdgtPKrO2bwFg=; b=GkxycvrME/qNOK/SU+XFvm+6T+A6Cn+n0IddVvZuY3U9ulzQN6v6QZ3G4T3w1QV7lr h3Aq3o9FAvyOGgiOSEmTMcUFHD7a9pni/HUi6cXUJY+l+1oMlSVWy28gO1spfmi2BZ0h 2MqLz4aPK/Iq2vRIoafPCuB9ejeg5pRl3Jb0E6s32MmgtSkDXHRMdo04Vp2hHZle8Cmb 3BrZu0kl0zc6QcsL88ycyC8iOSfowzMwQpepKiCGVKIfX3BCB2XgUhhHl/RnH8O1grVo Hf4WwUK84M6qvaZPDVOGvP9tf7Se8hzLEY1qqHXBfZwT3hSAcoAO0JEoj/TIAR5rZiuz tU/A== X-Received: by 10.52.88.168 with SMTP id bh8mr89831404vdb.51.1358254616907; Tue, 15 Jan 2013 04:56:56 -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 st5csp110618veb; Tue, 15 Jan 2013 04:56:56 -0800 (PST) X-Received: by 10.194.92.180 with SMTP id cn20mr141781540wjb.51.1358254615846; Tue, 15 Jan 2013 04:56:55 -0800 (PST) Received: from mail-wi0-x22a.google.com ([2a00:1450:400c:c05::22a]) by mx.google.com with ESMTPS id fu4si3378327wib.20.2013.01.15.04.56.55 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 15 Jan 2013 04:56:55 -0800 (PST) Received-SPF: neutral (google.com: 2a00:1450:400c:c05::22a is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=2a00:1450:400c:c05::22a; Authentication-Results: mx.google.com; spf=neutral (google.com: 2a00:1450:400c:c05::22a 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-f170.google.com with SMTP id hq7so2314181wib.3 for ; Tue, 15 Jan 2013 04:56:55 -0800 (PST) X-Received: by 10.194.174.234 with SMTP id bv10mr26252640wjc.47.1358254615427; Tue, 15 Jan 2013 04:56:55 -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.53 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 15 Jan 2013 04:56:54 -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, Mian Yousaf Kaukab , Lee Jones Subject: [PATCH 17/26] mfd: ab8500-debugfs: add debugfs node to read all registers Date: Tue, 15 Jan 2013 12:55:57 +0000 Message-Id: <1358254566-12419-18-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: ALoCoQmMxneNpJvWUadb+tEQWwIzDD+a6kvCwOSvsmD/qpDLDbnn1nbv1c3/RwdYUiWrZrDOyW5v From: Mian Yousaf Kaukab Update the ab8500_registers_print() to reuse it from multiple places. Signed-off-by: Lee Jones Signed-off-by: Mian Yousaf Kaukab Reviewed-by: Linus WALLEIJ Reviewed-by: Jonas ABERG --- drivers/mfd/ab8500-debugfs.c | 95 +++++++++++++++++++++++++++++++++++------- 1 file changed, 81 insertions(+), 14 deletions(-) diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c index a231faf..a1ce55e 100644 --- a/drivers/mfd/ab8500-debugfs.c +++ b/drivers/mfd/ab8500-debugfs.c @@ -495,15 +495,12 @@ static irqreturn_t ab8500_debug_handler(int irq, void *data) return IRQ_HANDLED; } -static int ab8500_registers_print(struct seq_file *s, void *p) +/* Prints to seq_file or log_buf */ +static int ab8500_registers_print(struct device *dev, u32 bank, + struct seq_file *s) { - struct device *dev = s->private; unsigned int i; - u32 bank = debug_bank; - - seq_printf(s, AB8500_NAME_STRING " register values:\n"); - seq_printf(s, " bank %u:\n", bank); for (i = 0; i < debug_ranges[bank].num_ranges; i++) { u32 reg; @@ -520,22 +517,42 @@ static int ab8500_registers_print(struct seq_file *s, void *p) return err; } - err = seq_printf(s, " [%u/0x%02X]: 0x%02X\n", bank, - reg, value); - if (err < 0) { - dev_err(dev, "seq_printf overflow\n"); - /* Error is not returned here since - * the output is wanted in any case */ - return 0; + if (s) { + err = seq_printf(s, " [%u/0x%02X]: 0x%02X\n", + bank, reg, value); + if (err < 0) { + dev_err(dev, + "seq_printf overflow bank=%d reg=%d\n", + bank, reg); + /* Error is not returned here since + * the output is wanted in any case */ + return 0; + } + } else { + printk(KERN_INFO" [%u/0x%02X]: 0x%02X\n", bank, + reg, value); } } } return 0; } +static int ab8500_print_bank_registers(struct seq_file *s, void *p) +{ + struct device *dev = s->private; + u32 bank = debug_bank; + + seq_printf(s, AB8500_NAME_STRING " register values:\n"); + + seq_printf(s, " bank %u:\n", bank); + + ab8500_registers_print(dev, bank, s); + return 0; +} + static int ab8500_registers_open(struct inode *inode, struct file *file) { - return single_open(file, ab8500_registers_print, inode->i_private); + return single_open(file, ab8500_print_bank_registers, inode->i_private); } static const struct file_operations ab8500_registers_fops = { @@ -546,6 +563,51 @@ static const struct file_operations ab8500_registers_fops = { .owner = THIS_MODULE, }; +static int ab8500_print_all_banks(struct seq_file *s, void *p) +{ + struct device *dev = s->private; + unsigned int i; + int err; + + seq_printf(s, AB8500_NAME_STRING " register values:\n"); + + for (i = 1; i < AB8500_NUM_BANKS; i++) { + err = seq_printf(s, " bank %u:\n", i); + if (err < 0) + dev_err(dev, "seq_printf overflow, bank=%d\n", i); + + ab8500_registers_print(dev, i, s); + } + return 0; +} + +static int ab8500_all_banks_open(struct inode *inode, struct file *file) +{ + struct seq_file *s; + int err; + + err = single_open(file, ab8500_print_all_banks, inode->i_private); + if (!err) { + /* Default buf size in seq_read is not enough */ + s = (struct seq_file *)file->private_data; + s->size = (PAGE_SIZE * 2); + s->buf = kmalloc(s->size, GFP_KERNEL); + if (!s->buf) { + single_release(inode, file); + err = -ENOMEM; + } + } + return err; +} + +static const struct file_operations ab8500_all_banks_fops = { + .open = ab8500_all_banks_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, + .owner = THIS_MODULE, +}; + static int ab8500_bank_print(struct seq_file *s, void *p) { return seq_printf(s, "%d\n", debug_bank); @@ -1475,6 +1537,11 @@ static int __devinit ab8500_debug_probe(struct platform_device *plf) if (!file) goto err; + file = debugfs_create_file("all-banks", S_IRUGO, + ab8500_dir, &plf->dev, &ab8500_all_banks_fops); + if (!file) + goto err; + file = debugfs_create_file("register-bank", (S_IRUGO | S_IWUSR), ab8500_dir, &plf->dev, &ab8500_bank_fops); if (!file)