From: Peter Chen <peter.chen-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
To: shawnguo-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org,
stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz@public.gmane.org
Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
pawel.moll-5wv7dgnIgG8@public.gmane.org,
mark.rutland-5wv7dgnIgG8@public.gmane.org,
festevam-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
p.zabel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org,
patryk-6+2coLtxvIyvnle+31E0rA@public.gmane.org,
linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
balbi-l0cyMroinI0@public.gmane.org,
arnd-r2nGTMty4D4@public.gmane.org,
mathieu.poirier-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org,
Peter Chen <peter.chen-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
Subject: [PATCH v2 1/3] usb: misc: generic_onboard_hub: add generic onboard USB HUB driver
Date: Mon, 14 Dec 2015 15:26:12 +0800 [thread overview]
Message-ID: <1450077974-22762-2-git-send-email-peter.chen@freescale.com> (raw)
In-Reply-To: <1450077974-22762-1-git-send-email-peter.chen-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
Current USB HUB driver lacks of platform interfaces to configure
external signal on HUB chip, eg, the PHY input clock and gpio reset
pin for HUB, these kinds of HUBs are usually soldered at the board,
and they are not hot-plug USB devices.
With this patch, the user can configure the HUB's pins at device tree,
and these configuration will be effective before the USB bus can be used,
it can avoid unexpected signals at USB bus during the USB HUB reset,
so we use subsys_initcall for this driver.
Signed-off-by: Peter Chen <peter.chen-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
---
MAINTAINERS | 7 ++
drivers/usb/misc/Kconfig | 10 +++
drivers/usb/misc/Makefile | 1 +
drivers/usb/misc/generic_onboard_hub.c | 143 +++++++++++++++++++++++++++++++++
4 files changed, 161 insertions(+)
create mode 100644 drivers/usb/misc/generic_onboard_hub.c
diff --git a/MAINTAINERS b/MAINTAINERS
index e9caa4b..cc1981e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11121,6 +11121,13 @@ S: Maintained
F: Documentation/usb/ohci.txt
F: drivers/usb/host/ohci*
+USB Generic Onboard HUB Driver
+M: Peter Chen <Peter.Chen-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
+T: git git://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb.git
+L: linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
+S: Maintained
+F: drivers/usb/misc/generic_onboard_hub.c
+
USB OTG FSM (Finite State Machine)
M: Peter Chen <Peter.Chen-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
T: git git://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb.git
diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
index f7a7fc2..5ff74ff 100644
--- a/drivers/usb/misc/Kconfig
+++ b/drivers/usb/misc/Kconfig
@@ -268,3 +268,13 @@ config USB_CHAOSKEY
To compile this driver as a module, choose M here: the
module will be called chaoskey.
+
+config USB_ONBOARD_HUB
+ tristate "Generic USB Onboard HUB"
+ help
+ depends on OF
+ Say Y here if your board has an onboard HUB, and this hub needs
+ to control its PHY clock and reset pin through external signals.
+ If you are not sure, say N.
+
+ To compile this driver as a module, choose M here.
diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile
index 45fd4ac..da52e9a 100644
--- a/drivers/usb/misc/Makefile
+++ b/drivers/usb/misc/Makefile
@@ -29,3 +29,4 @@ obj-$(CONFIG_USB_CHAOSKEY) += chaoskey.o
obj-$(CONFIG_USB_SISUSBVGA) += sisusbvga/
obj-$(CONFIG_USB_LINK_LAYER_TEST) += lvstest.o
+obj-$(CONFIG_USB_ONBOARD_HUB) += generic_onboard_hub.o
diff --git a/drivers/usb/misc/generic_onboard_hub.c b/drivers/usb/misc/generic_onboard_hub.c
new file mode 100644
index 0000000..7db5b78
--- /dev/null
+++ b/drivers/usb/misc/generic_onboard_hub.c
@@ -0,0 +1,143 @@
+/*
+ * usb_hub_generic.c The generic onboard USB HUB driver
+ *
+ * Copyright (C) 2015 Freescale Semiconductor, Inc.
+ * Author: Peter Chen <peter.chen-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 of
+ * the License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * This driver is only for the USB HUB devices which need to control
+ * their external pins(clock, reset, etc), and these USB HUB devices
+ * are soldered at the board.
+ */
+
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_gpio.h>
+#include <linux/platform_device.h>
+#include <linux/regulator/consumer.h>
+#include <linux/slab.h>
+
+struct usb_hub_generic_data {
+ struct clk *clk;
+};
+
+static int usb_hub_generic_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct usb_hub_generic_data *hub_data;
+ int ret = -EINVAL;
+ struct gpio_desc *gpiod_reset = NULL;
+ struct device_node *node = dev->of_node;
+ u32 duration_us = 50, clk_rate = 0;
+
+ /* Only support device tree now */
+ if (!node)
+ return ret;
+
+ hub_data = devm_kzalloc(dev, sizeof(*hub_data), GFP_KERNEL);
+ if (!hub_data)
+ return -ENOMEM;
+
+ hub_data->clk = devm_clk_get(dev, NULL);
+ if (IS_ERR(hub_data->clk)) {
+ dev_dbg(dev, "Can't get clock: %ld\n",
+ PTR_ERR(hub_data->clk));
+ hub_data->clk = NULL;
+ } else {
+ ret = clk_prepare_enable(hub_data->clk);
+ if (ret) {
+ dev_err(dev,
+ "Can't enable external clock: %d\n",
+ ret);
+ return ret;
+ }
+
+ of_property_read_u32(node, "clock-frequency", &clk_rate);
+ if (clk_rate) {
+ ret = clk_set_rate(hub_data->clk, clk_rate);
+ if (ret) {
+ dev_err(dev, "Error setting clock rate\n");
+ goto disable_clk;
+ }
+ }
+ }
+
+ gpiod_reset = devm_gpiod_get_optional(dev, "reset", GPIOD_ASIS);
+ ret = PTR_ERR_OR_ZERO(gpiod_reset);
+ if (ret) {
+ dev_err(dev, "Failed to get reset gpio, err = %d\n", ret);
+ goto disable_clk;
+ }
+
+ of_property_read_u32(node, "reset-duration-us", &duration_us);
+
+ if (gpiod_reset) {
+ gpiod_set_value(gpiod_reset, 1);
+ usleep_range(duration_us, duration_us + 10);
+ gpiod_set_value(gpiod_reset, 0);
+ }
+
+ dev_set_drvdata(dev, hub_data);
+ return ret;
+
+disable_clk:
+ clk_disable_unprepare(hub_data->clk);
+ return ret;
+}
+
+static int usb_hub_generic_remove(struct platform_device *pdev)
+{
+ struct usb_hub_generic_data *hub_data = platform_get_drvdata(pdev);
+
+ clk_disable_unprepare(hub_data->clk);
+
+ return 0;
+}
+
+static const struct of_device_id usb_hub_generic_dt_ids[] = {
+ {.compatible = "generic-onboard-hub"},
+ { },
+};
+MODULE_DEVICE_TABLE(of, usb_hub_generic_dt_ids);
+
+static struct platform_driver usb_hub_generic_driver = {
+ .probe = usb_hub_generic_probe,
+ .remove = usb_hub_generic_remove,
+ .driver = {
+ .name = "usb_hub_generic_onboard",
+ .of_match_table = usb_hub_generic_dt_ids,
+ },
+};
+
+static int __init usb_hub_generic_init(void)
+{
+ return platform_driver_register(&usb_hub_generic_driver);
+}
+subsys_initcall(usb_hub_generic_init);
+
+static void __exit usb_hub_generic_exit(void)
+{
+ platform_driver_unregister(&usb_hub_generic_driver);
+}
+module_exit(usb_hub_generic_exit);
+
+MODULE_AUTHOR("Peter Chen <peter.chen-KZfg59tc24xl57MIdRCFDg@public.gmane.org>");
+MODULE_DESCRIPTION("Generic Onboard USB HUB driver");
+MODULE_LICENSE("GPL v2");
--
1.9.1
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2015-12-14 7:26 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-14 7:26 [PATCH v2 0/3] USB: add generic onboard USB HUB driver Peter Chen
[not found] ` <1450077974-22762-1-git-send-email-peter.chen-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2015-12-14 7:26 ` Peter Chen [this message]
2015-12-14 7:26 ` [PATCH v2 2/3] doc: dt-binding: generic onboard USB HUB Peter Chen
2015-12-14 7:26 ` [PATCH v2 3/3] ARM: dts: imx6qdl-udoo.dtsi: fix onboard USB HUB property Peter Chen
2015-12-14 9:35 ` [PATCH v2 0/3] USB: add generic onboard USB HUB driver Arnd Bergmann
2015-12-15 8:33 ` Peter Chen
2015-12-16 22:59 ` Rob Herring
[not found] ` <CAL_Jsq+KAF6FGyOyC0JzODsSVoK4+V6umpj=cANywgui_wOKMg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-12-16 23:13 ` Arnd Bergmann
2015-12-17 2:31 ` Peter Chen
2015-12-17 13:49 ` Rob Herring
[not found] ` <CAL_Jsq+t6NBh-zzwPH14MYBp6PGFaVv3540Urdn8q6D+erQkLA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-12-18 7:38 ` Peter Chen
2015-12-17 16:13 ` Alan Stern
[not found] ` <Pine.LNX.4.44L0.1512171103080.1675-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2015-12-18 7:42 ` Peter Chen
[not found] ` <CAL411-rK6qfkbQsSjvXH5VPAQAm4tMyD6fVTEgFQrpLHNGMXeA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-12-18 15:38 ` Alan Stern
[not found] ` <Pine.LNX.4.44L0.1512181030590.1682-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2015-12-21 8:33 ` Peter Chen
[not found] ` <CAL411-qKE=12VZAN9=tUWPqkC5BfSgpQb9aNgCU6rmPLasXNHQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-12-21 19:40 ` Alan Stern
[not found] ` <Pine.LNX.4.44L0.1512211436030.1618-100000-pYrvlCTfrz9XsRXLowluHWD2FQJk+8+b@public.gmane.org>
2015-12-22 3:32 ` Peter Chen
[not found] ` <CAL411-oVEbh1cDnUugs0Rxrt1opvH-NeffjcmeMy-OuZS38CbA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-12-22 15:48 ` Alan Stern
2016-01-05 14:36 ` Rob Herring
[not found] ` <CAL_Jsq+P8SBmWzNURrmNgz8soCn4QPOPid4SXF0a3TYL_SH27A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-01-05 15:59 ` Alan Stern
2016-01-06 3:20 ` Peter Chen
2016-01-07 14:18 ` Rob Herring
[not found] ` <CAL_Jsq+rqv1NBSUToX5BsbnBp_goUWhdczU7ETSxOrJ5D4D1rw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-01-08 3:33 ` Peter Chen
2016-02-24 9:22 ` Peter Chen
2015-12-14 11:26 ` Fabio Estevam
[not found] ` <CAOMZO5CfBKuJ584jwbg98s9tn+0Z7W0nOaZnUkm4cJUSvNGTZw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-12-15 6:28 ` Peter Chen
2015-12-15 11:32 ` Fabio Estevam
[not found] ` <CAOMZO5DiRzfy5dULh0C7qU2KUM-i8fBh6W5rS9zOTHJJK6fqwg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-12-16 4:11 ` Peter Chen
2015-12-16 10:11 ` Fabio Estevam
[not found] ` <CAOMZO5An3CK-a3NQtOF3nnPc8vzu2+SKnfJ=iOuAhjCBvZwToQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-12-16 20:05 ` Maciej S. Szmigiero
[not found] ` <5671C40F.3000000-APzI5cXaD1zVlRWJc41N0YvC60bnQu0Y@public.gmane.org>
2015-12-17 6:57 ` Peter Chen
2015-12-18 23:48 ` Maciej S. Szmigiero
[not found] ` <56749B58.4040306-APzI5cXaD1zVlRWJc41N0YvC60bnQu0Y@public.gmane.org>
2015-12-21 8:44 ` Peter Chen
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=1450077974-22762-2-git-send-email-peter.chen@freescale.com \
--to=peter.chen-kzfg59tc24xl57midrcfdg@public.gmane.org \
--cc=arnd-r2nGTMty4D4@public.gmane.org \
--cc=balbi-l0cyMroinI0@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=festevam-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org \
--cc=kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org \
--cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
--cc=mathieu.poirier-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=p.zabel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org \
--cc=patryk-6+2coLtxvIyvnle+31E0rA@public.gmane.org \
--cc=pawel.moll-5wv7dgnIgG8@public.gmane.org \
--cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=shawnguo-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=stern-nwvwT67g6+6dFdvTe/nMLpVzexx5G7lz@public.gmane.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;
as well as URLs for NNTP newsgroup(s).