mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Corentin Chary <corentincj@iksaif.net>
To: platform-driver-x86@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@suse.de>,
	Corentin Chary <corentincj@iksaif.net>,
	Matthew Garrett <mjg@redhat.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 06/15] samsung-laptop: add small debugfs interface
Date: Tue, 22 Nov 2011 23:02:37 +0100	[thread overview]
Message-ID: <1321999366-23784-7-git-send-email-corentincj@iksaif.net> (raw)
In-Reply-To: <1321999366-23784-1-git-send-email-corentincj@iksaif.net>

Signed-off-by: Corentin Chary <corentincj@iksaif.net>
---
 drivers/platform/x86/samsung-laptop.c |  136 +++++++++++++++++++++++++++++++++
 1 files changed, 136 insertions(+), 0 deletions(-)

diff --git a/drivers/platform/x86/samsung-laptop.c b/drivers/platform/x86/samsung-laptop.c
index 9dcb582..8dc71a3 100644
--- a/drivers/platform/x86/samsung-laptop.c
+++ b/drivers/platform/x86/samsung-laptop.c
@@ -22,6 +22,8 @@
 #include <linux/platform_device.h>
 #include <linux/rfkill.h>
 #include <linux/acpi.h>
+#include <linux/seq_file.h>
+#include <linux/debugfs.h>
 
 /*
  * This driver is needed because a number of Samsung laptops do not hook
@@ -226,6 +228,24 @@ static const struct sabi_config sabi_configs[] = {
 	{ },
 };
 
+/*
+ * samsung-laptop/    - debugfs root directory
+ *   f0000_segment    - dump f0000 segment
+ *   command          - current command
+ *   data             - current data
+ *   d0, d1, d2, d3   - data fields
+ *   call             - call SABI using command and data
+ */
+
+struct samsung_laptop_debug {
+	struct dentry *root;
+	struct sabi_data data;
+	u16 command;
+
+	struct debugfs_blob_wrapper f0000_wrapper;
+	struct debugfs_blob_wrapper data_wrapper;
+};
+
 struct samsung_laptop {
 	const struct sabi_config *config;
 
@@ -239,6 +259,8 @@ struct samsung_laptop {
 	struct backlight_device *backlight_device;
 	struct rfkill *rfk;
 
+	struct samsung_laptop_debug debug;
+
 	bool handle_backlight;
 	bool has_stepping_quirk;
 };
@@ -679,6 +701,113 @@ static int __init samsung_sysfs_init(struct samsung_laptop *samsung)
 
 }
 
+static int show_call(struct seq_file *m, void *data)
+{
+	struct samsung_laptop *samsung = m->private;
+	struct sabi_data *sdata = &samsung->debug.data;
+	int ret;
+
+	seq_printf(m, "SABI 0x%04x {0x%08x, 0x%08x, 0x%04x, 0x%02x}\n",
+		   samsung->debug.command,
+		   sdata->d0, sdata->d1, sdata->d2, sdata->d3);
+
+	ret = sabi_command(samsung, samsung->debug.command, sdata, sdata);
+
+	if (ret) {
+		seq_printf(m, "SABI command 0x%04x failed\n",
+			   samsung->debug.command);
+		return ret;
+	}
+
+	seq_printf(m, "SABI {0x%08x, 0x%08x, 0x%04x, 0x%02x}\n",
+		   sdata->d0, sdata->d1, sdata->d2, sdata->d3);
+	return 0;
+}
+
+static int samsung_debugfs_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, show_call, inode->i_private);
+}
+
+static const struct file_operations samsung_laptop_call_io_ops = {
+	.owner = THIS_MODULE,
+	.open = samsung_debugfs_open,
+	.read = seq_read,
+	.llseek = seq_lseek,
+	.release = single_release,
+};
+
+static void samsung_debugfs_exit(struct samsung_laptop *samsung)
+{
+	debugfs_remove_recursive(samsung->debug.root);
+}
+
+static int samsung_debugfs_init(struct samsung_laptop *samsung)
+{
+	struct dentry *dent;
+
+	samsung->debug.root = debugfs_create_dir("samsung-laptop", NULL);
+	if (!samsung->debug.root) {
+		pr_err("failed to create debugfs directory");
+		goto error_debugfs;
+	}
+
+	samsung->debug.f0000_wrapper.data = samsung->f0000_segment;
+	samsung->debug.f0000_wrapper.size = 0xffff;
+
+	samsung->debug.data_wrapper.data = &samsung->debug.data;
+	samsung->debug.data_wrapper.size = sizeof(samsung->debug.data);
+
+	dent = debugfs_create_u16("command", S_IRUGO | S_IWUSR,
+				  samsung->debug.root, &samsung->debug.command);
+	if (!dent)
+		goto error_debugfs;
+
+	dent = debugfs_create_u32("d0", S_IRUGO | S_IWUSR, samsung->debug.root,
+				  &samsung->debug.data.d0);
+	if (!dent)
+		goto error_debugfs;
+
+	dent = debugfs_create_u32("d1", S_IRUGO | S_IWUSR, samsung->debug.root,
+				  &samsung->debug.data.d1);
+	if (!dent)
+		goto error_debugfs;
+
+	dent = debugfs_create_u16("d2", S_IRUGO | S_IWUSR, samsung->debug.root,
+				  &samsung->debug.data.d2);
+	if (!dent)
+		goto error_debugfs;
+
+	dent = debugfs_create_u8("d3", S_IRUGO | S_IWUSR, samsung->debug.root,
+				 &samsung->debug.data.d3);
+	if (!dent)
+		goto error_debugfs;
+
+	dent = debugfs_create_blob("data", S_IRUGO | S_IWUSR,
+				   samsung->debug.root,
+				   &samsung->debug.data_wrapper);
+	if (!dent)
+		goto error_debugfs;
+
+	dent = debugfs_create_blob("f0000_segment", S_IRUSR | S_IWUSR,
+				   samsung->debug.root,
+				   &samsung->debug.f0000_wrapper);
+	if (!dent)
+		goto error_debugfs;
+
+	dent = debugfs_create_file("call", S_IFREG | S_IRUGO,
+				   samsung->debug.root, samsung,
+				   &samsung_laptop_call_io_ops);
+	if (!dent)
+		goto error_debugfs;
+
+	return 0;
+
+error_debugfs:
+	samsung_debugfs_exit(samsung);
+	return -ENOMEM;
+}
+
 static void samsung_sabi_exit(struct samsung_laptop *samsung)
 {
 	const struct sabi_config *config = samsung->config;
@@ -1122,9 +1251,15 @@ static int __init samsung_init(void)
 	if (ret)
 		goto error_rfkill;
 
+	ret = samsung_debugfs_init(samsung);
+	if (ret)
+		goto error_debugfs;
+
 	samsung_platform_device = samsung->platform_device;
 	return ret;
 
+error_debugfs:
+	samsung_rfkill_exit(samsung);
 error_rfkill:
 	samsung_backlight_exit(samsung);
 error_backlight:
@@ -1144,6 +1279,7 @@ static void __exit samsung_exit(void)
 
 	samsung = platform_get_drvdata(samsung_platform_device);
 
+	samsung_debugfs_exit(samsung);
 	samsung_rfkill_exit(samsung);
 	samsung_backlight_exit(samsung);
 	samsung_sysfs_exit(samsung);
-- 
1.7.5.4


  parent reply	other threads:[~2011-11-22 22:03 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1321999366-23784-1-git-send-email-corentincj@iksaif.net>
2011-11-22 22:02 ` [PATCH 01/15] samsung-laptop: put all local variables in a single structure Corentin Chary
2011-11-22 22:18   ` Greg KH
2011-11-22 22:02 ` [PATCH 02/15] samsung-laptop: move code into init/exit functions Corentin Chary
2011-11-22 22:19   ` Greg KH
2011-11-23  6:24     ` Corentin Chary
2011-11-22 22:02 ` [PATCH 03/15] samsung-laptop: don't handle backlight if handled by acpi/video Corentin Chary
2011-11-22 22:16   ` Greg KH
2011-11-23  6:58     ` Corentin Chary
2011-11-23 20:30       ` Greg KH
2011-11-23 16:01   ` David Herrmann
2011-11-22 22:02 ` [PATCH 04/15] samsung-laptop: use a sysfs group Corentin Chary
2011-11-22 22:19   ` Greg KH
2011-11-22 22:02 ` [PATCH 05/15] samsung-laptop: ehance SABI support Corentin Chary
2011-11-22 22:18   ` Greg KH
2011-11-23  6:22     ` Corentin Chary
2011-11-22 22:02 ` Corentin Chary [this message]
2011-11-22 22:20   ` [PATCH 06/15] samsung-laptop: add small debugfs interface Greg KH
2011-11-23  6:27     ` Corentin Chary
2011-11-22 22:02 ` [PATCH 07/15] samsung-laptop: remove selftest Corentin Chary
2011-11-22 22:21   ` Greg KH
2011-11-22 22:02 ` [PATCH 08/15] samsung-laptop: add battery life extender support Corentin Chary
2011-11-22 22:21   ` Greg KH
2011-11-23  6:28     ` Corentin Chary
2011-11-23 16:17   ` David Herrmann
2011-11-23 16:54     ` Corentin Chary
2011-11-23 17:10       ` David Herrmann
2011-11-23 18:11         ` Corentin Chary
2011-11-23 20:14           ` David Herrmann
2011-11-22 22:02 ` [PATCH 09/15] samsung-laptop: add usb charge support Corentin Chary
2011-11-22 22:22   ` Greg KH
2011-11-22 22:02 ` [PATCH 10/15] samsung-laptop: cleanup KConfig Corentin Chary
2011-11-22 22:22   ` Greg KH
2011-11-23 16:19   ` David Herrmann
2011-11-22 22:02 ` [PATCH 11/15] samsung-laptop: add keyboard backlight support Corentin Chary
2011-11-22 22:23   ` Greg KH
2011-11-23  6:35     ` Corentin Chary
2011-11-23 16:41       ` David Herrmann
2011-11-23 16:51         ` Corentin Chary
2011-11-24  7:07           ` Corentin Chary
2011-11-25 19:18             ` David Herrmann
2011-11-25 21:41               ` Corentin Chary
2011-11-22 22:02 ` [PATCH 12/15] samsung-laptop: add true rfkill support for swsmi Corentin Chary
2011-11-22 22:24   ` Greg KH
2011-11-23  6:37     ` Corentin Chary
2011-11-23 20:29       ` Greg KH
2011-11-22 22:02 ` [PATCH 13/15] samsung-laptop: make the dmi check less strict Corentin Chary
2011-11-22 22:27   ` Greg KH
2011-11-23  7:17     ` Corentin Chary
2011-11-23 20:30       ` Greg KH
2011-11-22 22:02 ` [PATCH 14/15] samsung-laptop: dump model and version informations Corentin Chary
2011-11-22 22:28   ` Greg KH
2011-11-23  6:37     ` Corentin Chary
2011-11-22 22:02 ` [PATCH 15/15] samsung-laptop: promote myself as maintainer of samsung-laptop Corentin Chary
2011-11-22 22:29   ` Greg KH
2011-11-23  6:38     ` Corentin Chary
2011-11-23 16:46       ` David Herrmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1321999366-23784-7-git-send-email-corentincj@iksaif.net \
    --to=corentincj@iksaif.net \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mjg@redhat.com \
    --cc=platform-driver-x86@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®