linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pawel Laszczak <pawell@cadence.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	<linux-usb@vger.kernel.org>, Felipe Balbi <balbi@kernel.org>
Cc: <linux-kernel@vger.kernel.org>, <ltyrala@cadence.com>,
	<pawell@cadence.com>
Subject: [PATCH 12/15] Introduce Cadence USBSSP DRD Driver - added usbssp-plat.c file
Date: Tue, 3 Jul 2018 20:57:56 +0100	[thread overview]
Message-ID: <1530647879-10007-13-git-send-email-pawell@cadence.com> (raw)
In-Reply-To: <1530647879-10007-1-git-send-email-pawell@cadence.com>

Signed-off-by: Laszczak Pawel <pawell@cadence.com>
---
 drivers/usb/usbssp/usbssp-plat.c | 186 +++++++++++++++++++++++++++++++
 1 file changed, 186 insertions(+)
 create mode 100644 drivers/usb/usbssp/usbssp-plat.c

diff --git a/drivers/usb/usbssp/usbssp-plat.c b/drivers/usb/usbssp/usbssp-plat.c
new file mode 100644
index 000000000000..91abd7a00907
--- /dev/null
+++ b/drivers/usb/usbssp/usbssp-plat.c
@@ -0,0 +1,186 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * USBSSP device controller driver
+ *
+ * Copyright (C) 2018 Cadence.
+ *
+ * Author: Pawel Laszczak
+ * Some code borrowed from the Linux XHCI driver.
+ */
+
+#include <linux/clk.h>
+#include <linux/dma-mapping.h>
+#include <linux/module.h>
+#include <linux/pci.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+#include <linux/usb/phy.h>
+#include <linux/slab.h>
+#include <linux/acpi.h>
+
+#include "gadget.h"
+
+#define DRIVER_AUTHOR "Pawel Laszczak"
+#define DRIVER_DESC "USBSSP Device Controller (USBSSP) Driver"
+
+#ifdef CONFIG_OF
+
+static const struct of_device_id usbssp_dev_of_match[] = {
+	{
+		.compatible = "Cadence, usbssp-dev",
+	},
+	{},
+};
+MODULE_DEVICE_TABLE(of, usbssp_dev_of_match);
+#endif
+
+int usbssp_is_platform(void)
+{
+	return 1;
+}
+
+static int usbssp_plat_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct resource *res;
+	struct usbssp_udc *usbssp_data;
+	int ret = 0;
+	int irq;
+	struct device *sysdev;
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0) {
+		dev_err(&pdev->dev, "Incorrect IRQ number\n");
+		return -ENODEV;
+	}
+
+	usbssp_data = devm_kzalloc(dev, sizeof(*usbssp_data), GFP_KERNEL);
+	if (!usbssp_data)
+		return -ENOMEM;
+
+	for (sysdev = &pdev->dev; sysdev; sysdev = sysdev->parent) {
+		if (is_of_node(sysdev->fwnode) ||
+		    is_acpi_device_node(sysdev->fwnode))
+			break;
+#ifdef CONFIG_PCI
+		else if (sysdev->bus == &pci_bus_type)
+			break;
+#endif
+	}
+
+	if (!sysdev)
+		sysdev = &pdev->dev;
+
+	/* Try to set 64-bit DMA first */
+	if (WARN_ON(!dev->dma_mask))
+		/* Platform did not initialize dma_mask */
+		ret = dma_coerce_mask_and_coherent(dev,
+				DMA_BIT_MASK(64));
+	else
+		ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
+
+	/* If seting 64-bit DMA mask fails, fall back to 32-bit DMA mask */
+	if (ret) {
+		ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
+		if (ret)
+			return ret;
+	}
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	usbssp_data->regs = devm_ioremap_resource(dev, res);
+
+	if (IS_ERR(usbssp_data->regs)) {
+		ret = PTR_ERR(usbssp_data->regs);
+		return ret;
+	}
+
+	usbssp_data->rsrc_start = res->start;
+	usbssp_data->rsrc_len = resource_size(res);
+
+	ret = devm_request_irq(dev, irq, usbssp_irq, IRQF_SHARED,
+			dev_name(dev), usbssp_data);
+
+	if (ret < 0)
+		return ret;
+
+	usbssp_data->irq = irq;
+	usbssp_data->dev = dev;
+	platform_set_drvdata(pdev, usbssp_data);
+	ret = usbssp_gadget_init(usbssp_data);
+
+	return ret;
+}
+
+static int usbssp_plat_remove(struct platform_device *pdev)
+{
+	int ret = 0;
+	struct usbssp_udc *usbssp_data;
+
+	usbssp_data = (struct usbssp_udc *)platform_get_drvdata(pdev);
+	ret = usbssp_gadget_exit(usbssp_data);
+	return ret;
+
+}
+
+static int __maybe_unused usbssp_plat_suspend(struct device *dev)
+{
+	struct usbssp_udc *usbssp_data = dev_get_drvdata(dev);
+
+	return usbssp_suspend(usbssp_data, device_may_wakeup(dev));
+}
+
+static int __maybe_unused usbssp_plat_resume(struct device *dev)
+{
+	struct usbssp_udc *usbssp_data = dev_get_drvdata(dev);
+
+	return usbssp_resume(usbssp_data, 0);
+}
+
+static int __maybe_unused usbssp_plat_runtime_suspend(struct device *dev)
+{
+	struct usbssp_udc *usbssp_data = dev_get_drvdata(dev);
+
+	return usbssp_suspend(usbssp_data, true);
+}
+
+static int __maybe_unused usbssp_plat_runtime_resume(struct device *dev)
+{
+	struct usbssp_udc *usbssp_data = dev_get_drvdata(dev);
+
+	return usbssp_resume(usbssp_data, 0);
+}
+
+static const struct dev_pm_ops usbssp_plat_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(usbssp_plat_suspend, usbssp_plat_resume)
+
+	SET_RUNTIME_PM_OPS(usbssp_plat_runtime_suspend,
+			usbssp_plat_runtime_resume,
+			NULL)
+};
+
+static struct platform_driver usbssp_driver = {
+	.probe	= usbssp_plat_probe,
+	.remove	= usbssp_plat_remove,
+	.driver	= {
+		.name = "usbssp-dev",
+		.pm = &usbssp_plat_pm_ops,
+		.of_match_table = of_match_ptr(usbssp_dev_of_match),
+	},
+};
+
+static int __init usbssp_plat_init(void)
+{
+	return platform_driver_register(&usbssp_driver);
+}
+module_init(usbssp_plat_init);
+
+static void __exit usbssp_plat_exit(void)
+{
+	platform_driver_unregister(&usbssp_driver);
+}
+module_exit(usbssp_plat_exit);
+
+MODULE_ALIAS("platform:usbss-gadget");
+MODULE_DESCRIPTION("USBSSP' Device Controller (USBSSP) Driver");
+MODULE_LICENSE("GPL");
-- 
2.17.1


  parent reply	other threads:[~2018-07-03 20:00 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-03 19:57 Introduced new Cadence USBSSP DRD Driver Pawel Laszczak
2018-07-03 19:57 ` [PATCH 01/15] Introduce Cadence USBSSP DRD Driver - added gadget.c file Pawel Laszczak
2018-07-04  9:13   ` Greg Kroah-Hartman
2018-07-05 10:15     ` Pawel Laszczak
2018-07-05 15:14       ` Greg Kroah-Hartman
2018-07-03 19:57 ` [PATCH 02/15] Introduce Cadence USBSSP DRD driver - added gadget-mem.c Pawel Laszczak
2018-07-03 19:57 ` [PATCH 03/15] Introduce Cadence USBSSP DRD Driver - added gadget-ring.c file Pawel Laszczak
2018-07-03 19:57 ` [PATCH 04/15] Introduce Cadence USBSSP DRD Driver - added gadget.h file Pawel Laszczak
2018-07-03 19:57 ` [PATCH 05/15] Introduce Cadence USBSSP DRD Driver - added gadget-port.c file Pawel Laszczak
2018-07-03 19:57 ` [PATCH 06/15] Introduce Cadence USBSSP DRD Driver - added gadget-ep0 file Pawel Laszczak
2018-07-03 19:57 ` [PATCH 07/15] Introduce Cadence USBSSP DRD Driver - added gadget-if.c Driver implements interface between gadget drivers and USBSSP device driver Pawel Laszczak
2018-07-03 19:57 ` [PATCH 08/15] Introduce Cadence USBSSP DRD driver - added gadget-ext-caps.h Pawel Laszczak
2018-07-03 19:57 ` [PATCH 09/15] Introduce Cadence USBSSP DRD Driver - added debugfs files Pawel Laszczak
2018-07-04  9:15   ` Greg Kroah-Hartman
2018-07-05  9:44     ` Pawel Laszczak
2018-07-05 15:13       ` Greg Kroah-Hartman
2018-07-03 19:57 ` [PATCH 10/15] Introduce Cadence USBSSP DRD Driver - added trace files Pawel Laszczak
2018-07-03 19:57 ` [PATCH 11/15] Introduce Cadence USBSSP DRD driver - added gadget-dbg.c file Pawel Laszczak
2018-07-03 19:57 ` Pawel Laszczak [this message]
2018-07-03 19:57 ` [PATCH 13/15] Introduce Cadence USBSSP DRD Driver - added usbssp-pci-of-wrap.c file This file implements wrapper between PCI adn platform driver Pawel Laszczak
2018-07-03 19:57 ` [PATCH 14/15] Introduce Cadence USBSSP DRD Driver - added Kconfig and Makefile files Pawel Laszczak
2018-07-03 20:30   ` Randy Dunlap
2018-07-03 19:57 ` [PATCH 15/15] Introduce Cadence USBSSP DRD Driver - added USBSSP in Makefile and Kconfig files Pawel Laszczak

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=1530647879-10007-13-git-send-email-pawell@cadence.com \
    --to=pawell@cadence.com \
    --cc=balbi@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=ltyrala@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).