From: Piyush Mehta <piyush.mehta@xilinx.com>
To: <gregkh@linuxfoundation.org>, <--to=robh+dt@kernel.org>,
	<mka@chromium.org>, <ravisadineni@chromium.org>,
	<stern@rowland.harvard.edu>, <alcooperx@gmail.com>,
	<michal.simek@xilinx.com>
Cc: <piyush.mehta@xilinx.com>, <linux-usb@vger.kernel.org>,
	<devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<git@xilinx.com>, <sgoud@xilinx.com>
Subject: [PATCH 2/2] usb: misc: usb244: add support for USB2 ultra fast sd controller
Date: Sun, 24 Oct 2021 23:36:28 +0530	[thread overview]
Message-ID: <20211024180628.2992108-3-piyush.mehta@xilinx.com> (raw)
In-Reply-To: <20211024180628.2992108-1-piyush.mehta@xilinx.com>
Microchip's USB224x family of Hi-Speed USB 2.0 flash media card controllers
provides an ultra-fast interface between a USB host controller and flash
media cards.
This patch adds a GPIO based usb-sd reset for USB2244 USB2 ultra fast
SD controller. This usb2244 driver trigger sd reset signal after soft
reset or core Reset. The SD needs to be resetted after completion of
phy initialization. After the toggling of gpio, controller gets out
form reset. USB2244 is a simple platform device driver.
As part of the reset, sets the direction of the pin to output before
toggling the pin. Delay of microseconds is added in between low and
high to meet the setup and hold time requirement of the reset.
Signed-off-by: Piyush Mehta <piyush.mehta@xilinx.com>
---
 drivers/usb/misc/Kconfig   |  8 ++++++
 drivers/usb/misc/Makefile  |  1 +
 drivers/usb/misc/usb2244.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 78 insertions(+)
 create mode 100644 drivers/usb/misc/usb2244.c
diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
index 8f11443..5480c50 100644
--- a/drivers/usb/misc/Kconfig
+++ b/drivers/usb/misc/Kconfig
@@ -233,6 +233,14 @@ config USB_EZUSB_FX2
 	  Say Y here if you need EZUSB device support.
 	  (Cypress FX/FX2/FX2LP microcontrollers)
 
+config USB_USB2244
+	tristate "Microchip USB2244 Ultra Fast USB 2.0 SD driver"
+	depends on GPIOLIB
+	help
+	  This option enables support for Microchip USB2244 Ultra Fast USB 2.0
+	  SD controller. This driver reset the gpio pin makes controller out of
+	  reset.
+
 config USB_HUB_USB251XB
 	tristate "USB251XB Hub Controller Configuration Driver"
 	depends on I2C
diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile
index 5f4e598..ec22c12 100644
--- a/drivers/usb/misc/Makefile
+++ b/drivers/usb/misc/Makefile
@@ -24,6 +24,7 @@ obj-$(CONFIG_USB_TRANCEVIBRATOR)	+= trancevibrator.o
 obj-$(CONFIG_USB_USS720)		+= uss720.o
 obj-$(CONFIG_USB_SEVSEG)		+= usbsevseg.o
 obj-$(CONFIG_USB_YUREX)			+= yurex.o
+obj-$(CONFIG_USB_USB2244)		+= usb2244.o
 obj-$(CONFIG_USB_HUB_USB251XB)		+= usb251xb.o
 obj-$(CONFIG_USB_HSIC_USB3503)		+= usb3503.o
 obj-$(CONFIG_USB_HSIC_USB4604)		+= usb4604.o
diff --git a/drivers/usb/misc/usb2244.c b/drivers/usb/misc/usb2244.c
new file mode 100644
index 0000000..c9613b6
--- /dev/null
+++ b/drivers/usb/misc/usb2244.c
@@ -0,0 +1,69 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Driver for the Microchip USB2244 Ultra Fast USB 2.0 Multi-Format,
+ * SD/MMC, and MS Flash Media Controllers
+ *
+ * Copyright (c) 2021 Xilinx, Inc.
+ */
+
+#include <linux/delay.h>
+#include <linux/err.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of_platform.h>
+#include <linux/gpio/consumer.h>
+#include <linux/platform_device.h>
+
+struct usb2244 {
+	struct gpio_desc *reset_gpio;
+};
+
+static int usb2244_init_hw(struct device *dev, struct usb2244 *data)
+{
+	data = devm_kzalloc(dev, sizeof(struct usb2244), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	data->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
+	if (IS_ERR(data->reset_gpio)) {
+		dev_err_probe(dev, PTR_ERR(data->reset_gpio),
+			      "Failed to request reset GPIO %ld, errcode",
+			      PTR_ERR(data->reset_gpio));
+		return PTR_ERR(data->reset_gpio);
+	}
+
+	/* Toggle RESET_N to reset the hub. */
+	gpiod_set_value_cansleep(data->reset_gpio, 0);
+	usleep_range(5, 10);
+	gpiod_set_value_cansleep(data->reset_gpio, 1);
+	msleep(5);
+
+	return 0;
+}
+
+static int usb2244_probe(struct platform_device *pdev)
+{
+	struct usb2244 *data = NULL;
+
+	/* Trigger gpio reset to the hub. */
+	return usb2244_init_hw(&pdev->dev, data);
+}
+
+static const struct of_device_id usb2244_of_match[] = {
+	{ .compatible = "microchip,usb2244", },
+	{ }
+};
+
+static struct platform_driver usb2244_driver = {
+	.driver = {
+		.name = "microchip,usb2244",
+		.of_match_table	= usb2244_of_match,
+	},
+	.probe = usb2244_probe,
+};
+
+module_platform_driver(usb2244_driver);
+
+MODULE_AUTHOR("Piyush Mehta <piyush.mehta@xilinx.com>");
+MODULE_DESCRIPTION("USB2244 Ultra Fast SD-Controller");
+MODULE_LICENSE("GPL v2");
-- 
2.7.4
     prev parent reply	other threads:[~2021-10-24 18:07 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-24 18:06 [PATCH 0/2] usb: misc: add support for microchip,usb2244 USB-SD controller Piyush Mehta
2021-10-24 18:06 ` [PATCH 1/2] dt-bindings: usb: misc: Add binding for Microchip usb2244 Controller Piyush Mehta
2021-11-01 20:23   ` Rob Herring
2021-10-24 18:06 ` Piyush Mehta [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=20211024180628.2992108-3-piyush.mehta@xilinx.com \
    --to=piyush.mehta@xilinx.com \
    --cc=--to=robh+dt@kernel.org \
    --cc=alcooperx@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=git@xilinx.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=michal.simek@xilinx.com \
    --cc=mka@chromium.org \
    --cc=ravisadineni@chromium.org \
    --cc=sgoud@xilinx.com \
    --cc=stern@rowland.harvard.edu \
    /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).