From: Sandeep Singh <Sandeep.Singh@amd.com>
To: jikos@kernel.org, benjamin.tissoires@redhat.com,
linux-kernel@vger.kernel.org, linux-input@vger.kernel.org,
srinivas.pandruvada@linux.intel.com, jic23@kernel.org,
linux-iio@vger.kernel.org, Nehal-bakulchandra.Shah@amd.com
Cc: Shyam-sundar.S-k@amd.com, Sandeep Singh <sandeep.singh@amd.com>
Subject: [PATCH v3 4/5] SFH: Add debugfs support to AMD Sensor Fusion Hub
Date: Wed, 12 Feb 2020 08:26:36 +0530 [thread overview]
Message-ID: <1581476197-25854-5-git-send-email-Sandeep.Singh@amd.com> (raw)
In-Reply-To: <1581476197-25854-1-git-send-email-Sandeep.Singh@amd.com>
From: Sandeep Singh <sandeep.singh@amd.com>
This part would give access to internals of
AMD Sensor Fusion Hub through debugfs. it provide raw values in debugfs
Signed-off-by: Sandeep Singh <sandeep.singh@amd.com>
Signed-off-by: Nehal Shah <Nehal-bakulchandra.Shah@amd.com>
---
drivers/hid/amd-sfh-hid/amdsfh-debugfs.c | 250 +++++++++++++++++++++++++++++++
drivers/hid/amd-sfh-hid/amdsfh-debugfs.h | 14 ++
2 files changed, 264 insertions(+)
create mode 100644 drivers/hid/amd-sfh-hid/amdsfh-debugfs.c
create mode 100644 drivers/hid/amd-sfh-hid/amdsfh-debugfs.h
diff --git a/drivers/hid/amd-sfh-hid/amdsfh-debugfs.c b/drivers/hid/amd-sfh-hid/amdsfh-debugfs.c
new file mode 100644
index 0000000..15aeef8
--- /dev/null
+++ b/drivers/hid/amd-sfh-hid/amdsfh-debugfs.c
@@ -0,0 +1,250 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * AMD SFH Debugfs
+ * This part would access MP2 registers through debugfs
+ * for AMD SFH debugging.
+ * Author: Nehal Bakulchandra Shah <Nehal-Bakulchandra.Shah@amd.com>
+ */
+
+#include <linux/slab.h>
+#include "amd_mp2_pcie.h"
+#include "amdsfh-debugfs.h"
+
+/* DebugFS helpers */
+#define OBUFP (obuf + oboff)
+#define OBUFLEN 512
+#define OBUFSPC (OBUFLEN - oboff)
+#define OSCNPRINTF(fmt, ...) \
+ scnprintf(OBUFP, OBUFSPC, fmt, ## __VA_ARGS__)
+
+static ssize_t amdsfh_debugfs_accel_read(struct file *filp, char __user *ubuf,
+ size_t count, loff_t *offp)
+{
+ unsigned int oboff = 0, i;
+ struct amdtp_cl_data *cl_data = filp->private_data;
+ bool found = false;
+ ssize_t ret;
+ char *obuf;
+
+ for (i = 0; i < cl_data->num_hid_devices; i++) {
+ if (cl_data->sensor_idx[i] == ACCEL_IDX) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found)
+ return -1;
+
+ obuf = kmalloc(OBUFLEN, GFP_KERNEL);
+ if (!obuf)
+ return -ENOMEM;
+
+ oboff += OSCNPRINTF("Accel_X_Raw:%d\n",
+ (int)cl_data->sensor_virt_addr[i][0]);
+ oboff += OSCNPRINTF("Accel_Y_Raw:%d\n",
+ (int)cl_data->sensor_virt_addr[i][1]);
+ oboff += OSCNPRINTF("Accel_Z_Raw:%d\n",
+ (int)cl_data->sensor_virt_addr[i][2]);
+ ret = simple_read_from_buffer(ubuf, count, offp, obuf, oboff);
+
+ kfree(obuf);
+
+ return ret;
+}
+
+static ssize_t amdsfh_debugfs_gyro_read(struct file *filp, char __user *ubuf,
+ size_t count, loff_t *offp)
+{
+ unsigned int oboff = 0, i;
+ bool found = false;
+ struct amdtp_cl_data *cl_data = filp->private_data;
+ ssize_t ret;
+ char *obuf;
+
+ for (i = 0; i < cl_data->num_hid_devices; i++) {
+ if (cl_data->sensor_idx[i] == GYRO_IDX) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found)
+ return -1;
+
+ obuf = kmalloc(OBUFLEN, GFP_KERNEL);
+ if (!obuf)
+ return -ENOMEM;
+
+ oboff += OSCNPRINTF("Gyro_X_Raw:%d\n",
+ (int)cl_data->sensor_virt_addr[i][0]);
+ oboff += OSCNPRINTF("Gyro_Y_Raw:%d\n",
+ (int)cl_data->sensor_virt_addr[i][1]);
+ oboff += OSCNPRINTF("Gyro_Z_Raw:%d\n",
+ (int)cl_data->sensor_virt_addr[i][2]);
+ ret = simple_read_from_buffer(ubuf, count, offp, obuf, oboff);
+
+ kfree(obuf);
+
+ return ret;
+}
+
+static ssize_t amdsfh_debugfs_mag_read(struct file *filp, char __user *ubuf,
+ size_t count, loff_t *offp)
+{
+ unsigned int oboff = 0, i;
+ bool found = false;
+ ssize_t ret;
+ char *obuf;
+ struct amdtp_cl_data *cl_data = filp->private_data;
+
+ for (i = 0; i < cl_data->num_hid_devices; i++) {
+ if (cl_data->sensor_idx[i] == MAG_IDX) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found)
+ return -1;
+
+ obuf = kmalloc(OBUFLEN, GFP_KERNEL);
+ if (!obuf)
+ return -ENOMEM;
+
+ oboff += OSCNPRINTF("Mag_X_Raw:%d\n",
+ (int)cl_data->sensor_virt_addr[i][0]);
+ oboff += OSCNPRINTF("Mag_Y_Raw:%d\n",
+ (int)cl_data->sensor_virt_addr[i][1]);
+ oboff += OSCNPRINTF("Mag_Z_Raw:%d\n",
+ (int)cl_data->sensor_virt_addr[i][2]);
+ ret = simple_read_from_buffer(ubuf, count, offp, obuf, oboff);
+
+ kfree(obuf);
+
+ return ret;
+}
+
+static ssize_t amdsfh_debugfs_als_read(struct file *filp, char __user *ubuf,
+ size_t count, loff_t *offp)
+{
+ unsigned int oboff = 0, i;
+ bool found = false;
+ ssize_t ret;
+ char *obuf;
+ struct amdtp_cl_data *cl_data = filp->private_data;
+
+ for (i = 0; i < cl_data->num_hid_devices; i++) {
+ if (cl_data->sensor_idx[i] == AMBIENT_LIGHT_IDX) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found)
+ return -1;
+
+ obuf = kmalloc(OBUFLEN, GFP_KERNEL);
+ if (!obuf)
+ return -ENOMEM;
+
+ oboff += OSCNPRINTF("Gyro_X_Raw:%d\n",
+ (int)cl_data->sensor_virt_addr[i][0]);
+ oboff += OSCNPRINTF("Gyro_Y_Raw:%d\n",
+ (int)cl_data->sensor_virt_addr[i][1]);
+ oboff += OSCNPRINTF("Gyro_Z_Raw:%d\n",
+ (int)cl_data->sensor_virt_addr[i][2]);
+ ret = simple_read_from_buffer(ubuf, count, offp, obuf, oboff);
+
+ kfree(obuf);
+
+ return ret;
+}
+
+static const struct file_operations amdsfh_debugfs_accel_ops = {
+ .owner = THIS_MODULE,
+ .open = simple_open,
+ .read = amdsfh_debugfs_accel_read,
+};
+
+static const struct file_operations amdsfh_debugfs_gyro_ops = {
+ .owner = THIS_MODULE,
+ .open = simple_open,
+ .read = amdsfh_debugfs_gyro_read,
+};
+
+static const struct file_operations amdsfh_debugfs_mag_ops = {
+ .owner = THIS_MODULE,
+ .open = simple_open,
+ .read = amdsfh_debugfs_mag_read,
+};
+
+static const struct file_operations amdsfh_debugfs_als_ops = {
+ .owner = THIS_MODULE,
+ .open = simple_open,
+ .read = amdsfh_debugfs_als_read,
+};
+
+int amdsfh_debugfs_setup(struct amdtp_cl_data *cl_data)
+{
+ /* DebugFS info */
+ struct dentry *dbgfs;
+ int i;
+
+ if (!debugfs_initialized())
+ return -1;
+
+ if (!cl_data->amd_debugfs_dir)
+ cl_data->amd_debugfs_dir = debugfs_create_dir
+ (KBUILD_MODNAME, NULL);
+
+ if (!cl_data->amd_debugfs_dir)
+ return -1;
+
+ for (i = 0; i < cl_data->num_hid_devices; i++) {
+ switch (cl_data->sensor_idx[i]) {
+ case ACCEL_IDX:
+ dbgfs = debugfs_create_dir("accel",
+ cl_data->amd_debugfs_dir);
+ debugfs_create_file("raw_value", 0400,
+ dbgfs, cl_data,
+ &amdsfh_debugfs_accel_ops);
+ break;
+
+ case GYRO_IDX:
+ dbgfs = debugfs_create_dir("gyro",
+ cl_data->amd_debugfs_dir);
+ debugfs_create_file("raw_value", 0400,
+ dbgfs, cl_data,
+ &amdsfh_debugfs_gyro_ops);
+ break;
+
+ case MAG_IDX:
+ dbgfs = debugfs_create_dir("magnetometer",
+ cl_data->amd_debugfs_dir);
+ debugfs_create_file("raw_value", 0400,
+ dbgfs, cl_data,
+ &amdsfh_debugfs_mag_ops);
+ break;
+
+ case AMBIENT_LIGHT_IDX:
+ dbgfs = debugfs_create_dir("als",
+ cl_data->amd_debugfs_dir);
+ debugfs_create_file("raw_value", 0400,
+ dbgfs, cl_data,
+ &amdsfh_debugfs_als_ops);
+ break;
+
+ default:
+ return 0;
+ }
+ }
+ return 0;
+}
+EXPORT_SYMBOL(amdsfh_debugfs_setup);
+
+void amdsfh_debugfs_destroy(struct amdtp_cl_data *cl_data)
+{
+ debugfs_remove_recursive(cl_data->amd_debugfs_dir);
+}
+EXPORT_SYMBOL(amdsfh_debugfs_destroy);
diff --git a/drivers/hid/amd-sfh-hid/amdsfh-debugfs.h b/drivers/hid/amd-sfh-hid/amdsfh-debugfs.h
new file mode 100644
index 0000000..470f1f12
--- /dev/null
+++ b/drivers/hid/amd-sfh-hid/amdsfh-debugfs.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * AMD SFH DebugFS
+ * Author: Nehal Bakulchandra Shah <Nehal-Bakulchandra.Shah@amd.com>
+ */
+#include "amdsfh-hid.h"
+
+#ifndef AMDSFH_DEBUGFS_H
+#define AMDSFH_DEBUGFS_H
+
+int amdsfh_debugfs_setup(struct amdtp_cl_data *cl_data);
+void amdsfh_debugfs_destroy(struct amdtp_cl_data *cl_data);
+
+#endif
--
2.7.4
next prev parent reply other threads:[~2020-02-12 2:57 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-12 2:56 [PATCH v3 0/5] SFH: Add Support for AMD Sensor Fusion Hub Sandeep Singh
2020-02-12 2:56 ` [PATCH v3 1/5] SFH: Add maintainers and documentation for AMD SFH based on HID framework Sandeep Singh
2020-02-12 2:56 ` [PATCH v3 2/5] SFH: PCI driver to add support of AMD sensor fusion Hub using " Sandeep Singh
2020-02-12 2:56 ` [PATCH v3 3/5] SFH: Transport Driver to add support of AMD Sensor Fusion Hub (SFH) Sandeep Singh
2020-02-12 2:56 ` Sandeep Singh [this message]
2020-02-12 2:56 ` [PATCH v3 5/5] SFH: Create HID report to Enable support of AMD sensor fusion " Sandeep Singh
2020-02-12 14:45 ` [PATCH v3 0/5] SFH: Add Support for AMD Sensor Fusion Hub Hans de Goede
2020-02-13 14:56 ` Benjamin Tissoires
2020-02-14 4:40 ` Srinivas Pandruvada
2020-02-14 10:04 ` Shah, Nehal-bakulchandra
2020-02-14 11:11 ` Benjamin Tissoires
2020-02-19 15:04 ` Shah, Nehal-bakulchandra
2020-02-21 12:47 ` Jiri Kosina
2020-02-14 11:11 ` Hans de Goede
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=1581476197-25854-5-git-send-email-Sandeep.Singh@amd.com \
--to=sandeep.singh@amd.com \
--cc=Nehal-bakulchandra.Shah@amd.com \
--cc=Shyam-sundar.S-k@amd.com \
--cc=benjamin.tissoires@redhat.com \
--cc=jic23@kernel.org \
--cc=jikos@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=srinivas.pandruvada@linux.intel.com \
/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;
as well as URLs for NNTP newsgroup(s).