From: Pawel Laszczak <pawell@cadence.com>
To: devicetree@vger.kernel.org
Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org,
rogerq@ti.com, linux-kernel@vger.kernel.org,
adouglas@cadence.com, jbergsagel@ti.com, nsekhar@ti.com,
nm@ti.com, sureshp@cadence.com, peter.chen@nxp.com,
pjez@cadence.com, kurahul@cadence.com,
Pawel Laszczak <pawell@cadence.com>
Subject: [RFC PATCH v2 15/15] usb:cdns3: Feature for changing role
Date: Sun, 18 Nov 2018 10:09:11 +0000 [thread overview]
Message-ID: <1542535751-16079-16-git-send-email-pawell@cadence.com> (raw)
In-Reply-To: <1542535751-16079-1-git-send-email-pawell@cadence.com>
Patch adds feature that allow to change role from user space.
Signed-off-by: Pawel Laszczak <pawell@cadence.com>
---
drivers/usb/cdns3/Makefile | 2 +-
drivers/usb/cdns3/core.c | 2 +
drivers/usb/cdns3/debugfs.c | 93 +++++++++++++++++++++++++++++++++++++
drivers/usb/cdns3/drd.h | 3 ++
4 files changed, 99 insertions(+), 1 deletion(-)
create mode 100644 drivers/usb/cdns3/debugfs.c
diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile
index 34e60d03c4ec..08e6cdbebd46 100644
--- a/drivers/usb/cdns3/Makefile
+++ b/drivers/usb/cdns3/Makefile
@@ -1,7 +1,7 @@
obj-$(CONFIG_USB_CDNS3) += cdns3.o
obj-$(CONFIG_USB_CDNS3_PCI_WRAP) += cdns3-pci.o
-cdns3-y := core.o drd.o
+cdns3-y := core.o drd.o debugfs.o
cdns3-$(CONFIG_USB_CDNS3_GADGET) += gadget.o ep0.o debug.o
cdns3-$(CONFIG_USB_CDNS3_HOST) += host.o
cdns3-pci-y := cdns3-pci-wrap.o
diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c
index 1fa233415901..304323b643f2 100644
--- a/drivers/usb/cdns3/core.c
+++ b/drivers/usb/cdns3/core.c
@@ -323,6 +323,7 @@ static int cdns3_probe(struct platform_device *pdev)
goto err2;
}
+ cdns3_debugfs_init(cdns);
device_set_wakeup_capable(dev, true);
pm_runtime_set_active(dev);
pm_runtime_enable(dev);
@@ -358,6 +359,7 @@ static int cdns3_remove(struct platform_device *pdev)
pm_runtime_get_sync(&pdev->dev);
pm_runtime_disable(&pdev->dev);
pm_runtime_put_noidle(&pdev->dev);
+ cdns3_debugfs_exit(cdns);
cdns3_remove_roles(cdns);
return 0;
diff --git a/drivers/usb/cdns3/debugfs.c b/drivers/usb/cdns3/debugfs.c
new file mode 100644
index 000000000000..189b12d96cbf
--- /dev/null
+++ b/drivers/usb/cdns3/debugfs.c
@@ -0,0 +1,93 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Cadence USBSS DRD Controller DebugFS filer.
+ *
+ * Copyright (C) 2018 Cadence.
+ *
+ * Author: Pawel Laszczak <pawell@cadence.com>
+ */
+
+#include <linux/types.h>
+#include <linux/debugfs.h>
+#include <linux/seq_file.h>
+#include <linux/uaccess.h>
+
+#include "core.h"
+#include "gadget.h"
+
+static int cdns3_mode_show(struct seq_file *s, void *unused)
+{
+ struct cdns3 *cdns = s->private;
+
+ switch (cdns->current_dr_mode) {
+ case USB_DR_MODE_HOST:
+ seq_puts(s, "host\n");
+ break;
+ case USB_DR_MODE_PERIPHERAL:
+ seq_puts(s, "device\n");
+ break;
+ case USB_DR_MODE_OTG:
+ seq_puts(s, "otg\n");
+ break;
+ default:
+ seq_puts(s, "UNKNOWN mode\n");
+ }
+
+ return 0;
+}
+
+static int cdns3_mode_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, cdns3_mode_show, inode->i_private);
+}
+
+static ssize_t cdns3_mode_write(struct file *file,
+ const char __user *ubuf,
+ size_t count, loff_t *ppos)
+{
+ struct seq_file *s = file->private_data;
+ struct cdns3 *cdns = s->private;
+ u32 mode = 0;
+ char buf[32];
+
+ if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
+ return -EFAULT;
+
+ if (!strncmp(buf, "host", 4))
+ mode = USB_DR_MODE_HOST;
+
+ if (!strncmp(buf, "device", 6))
+ mode = USB_DR_MODE_PERIPHERAL;
+
+ if (!strncmp(buf, "otg", 3))
+ mode = USB_DR_MODE_OTG;
+
+ cdns->desired_dr_mode = mode;
+ queue_work(system_freezable_wq, &cdns->role_switch_wq);
+ return count;
+}
+
+static const struct file_operations cdns3_mode_fops = {
+ .open = cdns3_mode_open,
+ .write = cdns3_mode_write,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
+void cdns3_debugfs_init(struct cdns3 *cdns)
+{
+ struct dentry *root;
+
+ root = debugfs_create_dir(dev_name(cdns->dev), NULL);
+ cdns->root = root;
+ if (IS_ENABLED(CONFIG_USB_CDNS3_GADGET) &&
+ IS_ENABLED(CONFIG_USB_CDNS3_HOST))
+ debugfs_create_file("mode", 0644, root, cdns,
+ &cdns3_mode_fops);
+}
+
+void cdns3_debugfs_exit(struct cdns3 *cdns)
+{
+ debugfs_remove_recursive(cdns->root);
+}
diff --git a/drivers/usb/cdns3/drd.h b/drivers/usb/cdns3/drd.h
index 0faa7520ecac..8367032e12a3 100644
--- a/drivers/usb/cdns3/drd.h
+++ b/drivers/usb/cdns3/drd.h
@@ -119,4 +119,7 @@ int cdns3_drd_init(struct cdns3 *cdns);
int cdns3_drd_update_mode(struct cdns3 *cdns);
irqreturn_t cdns3_drd_irq(struct cdns3 *cdns);
+void cdns3_debugfs_init(struct cdns3 *cdns);
+void cdns3_debugfs_exit(struct cdns3 *cdns);
+
#endif /* __LINUX_CDNS3_DRD */
--
2.17.1
prev parent reply other threads:[~2018-11-18 10:09 UTC|newest]
Thread overview: 85+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-18 10:08 [RFC PATCH v2 00/15] Introduced new Cadence USBSS DRD Driver Pawel Laszczak
2018-11-18 10:08 ` [RFC PATCH v2 01/15] usb:cdns3: add pci to platform driver wrapper Pawel Laszczak
2018-11-23 10:44 ` Roger Quadros
2018-11-18 10:08 ` [RFC PATCH v2 02/15] usb:cdns3: Device side header file Pawel Laszczak
2018-11-30 6:48 ` PETER CHEN
2018-12-02 19:27 ` Pawel Laszczak
2018-11-18 10:08 ` [RFC PATCH v2 03/15] dt-bindings: add binding for USBSS-DRD controller Pawel Laszczak
2018-11-23 10:53 ` Roger Quadros
2018-11-25 7:33 ` Pawel Laszczak
2018-12-04 22:41 ` Rob Herring
2018-12-06 10:26 ` Pawel Laszczak
2018-11-18 10:09 ` [RFC PATCH v2 04/15] usb:cdns3: Driver initialization code Pawel Laszczak
2018-11-23 11:35 ` Roger Quadros
2018-11-25 12:35 ` Pawel Laszczak
2018-12-04 9:09 ` Peter Chen
2018-12-06 7:00 ` Pawel Laszczak
2018-12-04 8:50 ` Peter Chen
2018-12-04 10:46 ` Roger Quadros
2018-12-05 8:57 ` Peter Chen
2018-12-06 9:31 ` Pawel Laszczak
2018-12-05 19:24 ` Pawel Laszczak
2018-12-05 19:42 ` Pawel Laszczak
2018-12-06 10:02 ` Pawel Laszczak
2018-11-30 7:32 ` Peter Chen
2018-12-02 20:34 ` Pawel Laszczak
2018-12-04 7:11 ` Peter Chen
2018-12-05 7:19 ` Pawel Laszczak
2018-12-05 8:55 ` Alan Douglas
2018-12-05 9:07 ` Peter Chen
2018-11-18 10:09 ` [RFC PATCH v2 05/15] usb:cdns3: Added DRD support Pawel Laszczak
2018-11-23 14:51 ` Roger Quadros
2018-11-26 7:23 ` Pawel Laszczak
2018-11-26 8:07 ` Roger Quadros
2018-11-26 8:39 ` Pawel Laszczak
2018-11-26 9:39 ` Roger Quadros
2018-11-26 10:09 ` Pawel Laszczak
2018-11-26 10:15 ` Roger Quadros
2018-11-27 11:29 ` Pawel Laszczak
2018-11-27 12:10 ` Roger Quadros
2018-12-04 9:18 ` Peter Chen
2018-12-06 7:25 ` Pawel Laszczak
2018-11-18 10:09 ` [RFC PATCH v2 06/15] usb:cdns3: Adds Host support Pawel Laszczak
2018-11-23 14:23 ` Roger Quadros
2018-11-26 8:24 ` Pawel Laszczak
2018-11-26 9:50 ` Roger Quadros
2018-11-26 10:17 ` Pawel Laszczak
2018-12-05 8:41 ` Peter Chen
2018-11-18 10:09 ` [RFC PATCH v2 07/15] usb:cdns3: Adds Device mode support - initialization Pawel Laszczak
2018-11-28 11:34 ` Roger Quadros
2018-11-28 11:40 ` Felipe Balbi
2018-11-30 4:20 ` PETER CHEN
2018-11-30 6:29 ` Pawel Laszczak
2018-11-30 14:36 ` Pawel Laszczak
2018-11-18 10:09 ` [RFC PATCH v2 08/15] usb:cdns3: Implements device operations part of the API Pawel Laszczak
2018-11-28 12:22 ` Roger Quadros
2018-12-01 11:11 ` Pawel Laszczak
2018-12-03 10:19 ` Pawel Laszczak
2018-12-10 2:12 ` Peter Chen
2018-12-11 11:26 ` Sekhar Nori
2018-12-11 19:49 ` Pawel Laszczak
2018-12-14 1:34 ` Peter Chen
2018-12-14 6:49 ` Pawel Laszczak
2018-12-14 10:39 ` Sekhar Nori
2018-12-14 10:47 ` Felipe Balbi
2018-12-14 11:13 ` Sekhar Nori
2018-12-14 11:26 ` Felipe Balbi
2018-12-14 12:20 ` Sekhar Nori
2018-12-14 12:30 ` Felipe Balbi
2018-12-16 13:31 ` Pawel Laszczak
2018-11-18 10:09 ` [RFC PATCH v2 09/15] usb:cdns3: EpX " Pawel Laszczak
2018-11-28 12:46 ` Roger Quadros
2018-12-01 13:30 ` Pawel Laszczak
2018-11-18 10:09 ` [RFC PATCH v2 10/15] usb:cdns3: Ep0 " Pawel Laszczak
2018-11-28 14:31 ` Roger Quadros
2018-12-02 10:34 ` Pawel Laszczak
2018-11-18 10:09 ` [RFC PATCH v2 11/15] usb:cdns3: Implements ISR functionality Pawel Laszczak
2018-11-28 14:54 ` Roger Quadros
2018-12-02 11:49 ` Pawel Laszczak
2018-12-02 12:52 ` Pawel Laszczak
2018-11-18 10:09 ` [RFC PATCH v2 12/15] usb:cdns3: Adds enumeration related function Pawel Laszczak
2018-11-28 15:50 ` Roger Quadros
2018-12-02 16:39 ` Pawel Laszczak
2018-11-18 10:09 ` [RFC PATCH v2 13/15] usb:cdns3: Adds transfer " Pawel Laszczak
2018-11-18 10:09 ` [RFC PATCH v2 14/15] usb:cdns3: Adds debugging function Pawel Laszczak
2018-11-18 10:09 ` Pawel Laszczak [this message]
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=1542535751-16079-16-git-send-email-pawell@cadence.com \
--to=pawell@cadence.com \
--cc=adouglas@cadence.com \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=jbergsagel@ti.com \
--cc=kurahul@cadence.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=nm@ti.com \
--cc=nsekhar@ti.com \
--cc=peter.chen@nxp.com \
--cc=pjez@cadence.com \
--cc=rogerq@ti.com \
--cc=sureshp@cadence.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).