Преглед изворни кода

qcacld-3.0: Add USB bus support (PLD)

Add PLD specific changes for USB bus support.

CRs-Fixed: 1023663
Change-Id: I030ee8a5e6dd13ed8bd970d80f435219677c4e4b
Mohit Khanna пре 9 година
родитељ
комит
1d531c408f
4 измењених фајлова са 293 додато и 1 уклоњено
  1. 4 1
      core/pld/inc/pld_common.h
  2. 26 0
      core/pld/src/pld_common.c
  3. 211 0
      core/pld/src/pld_usb.c
  4. 52 0
      core/pld/src/pld_usb.h

+ 4 - 1
core/pld/inc/pld_common.h

@@ -50,7 +50,8 @@ enum pld_bus_type {
 	PLD_BUS_TYPE_NONE = -1,
 	PLD_BUS_TYPE_PCIE = 0,
 	PLD_BUS_TYPE_SNOC,
-	PLD_BUS_TYPE_SDIO
+	PLD_BUS_TYPE_SDIO,
+	PLD_BUS_TYPE_USB
 };
 
 #define PLD_MAX_FIRMWARE_SIZE (1 * 1024 * 1024)
@@ -316,6 +317,8 @@ struct pld_driver_ops {
 		       pm_message_t state);
 	int (*resume)(struct device *dev,
 		      enum pld_bus_type bus_type);
+	int (*reset_resume)(struct device *dev,
+		      enum pld_bus_type bus_type);
 	void (*modem_status)(struct device *dev,
 			     enum pld_bus_type bus_type,
 			     int state);

+ 26 - 0
core/pld/src/pld_common.c

@@ -44,10 +44,13 @@
 #include "pld_pcie.h"
 #include "pld_snoc.h"
 #include "pld_sdio.h"
+#include "pld_usb.h"
 
 #define PLD_PCIE_REGISTERED BIT(0)
 #define PLD_SNOC_REGISTERED BIT(1)
 #define PLD_SDIO_REGISTERED BIT(2)
+#define PLD_USB_REGISTERED BIT(3)
+#define PLD_BUS_MASK 0xf
 
 static struct pld_context *pld_ctx;
 
@@ -238,6 +241,7 @@ int pld_register_driver(struct pld_driver_ops *ops)
 	}
 
 	pld_context->ops = ops;
+	pld_context->pld_driver_state = 0;
 
 	ret = pld_pcie_register_driver();
 	if (ret) {
@@ -260,8 +264,17 @@ int pld_register_driver(struct pld_driver_ops *ops)
 	}
 	pld_context->pld_driver_state |= PLD_SDIO_REGISTERED;
 
+	ret = pld_usb_register_driver();
+	if (ret) {
+		pr_err("Fail to register usb driver\n");
+		goto fail_usb;
+	}
+	pld_context->pld_driver_state |= PLD_USB_REGISTERED;
+
 	return ret;
 
+fail_usb:
+	pld_sdio_unregister_driver();
 fail_sdio:
 	pld_snoc_unregister_driver();
 fail_snoc:
@@ -301,6 +314,7 @@ void pld_unregister_driver(void)
 	pld_pcie_unregister_driver();
 	pld_snoc_unregister_driver();
 	pld_sdio_unregister_driver();
+	pld_usb_unregister_driver();
 
 	pld_context->pld_driver_state = 0;
 
@@ -460,6 +474,10 @@ int pld_get_fw_files_for_target(struct device *dev,
 		ret = pld_sdio_get_fw_files_for_target(pfw_files,
 				       target_type, target_version);
 		break;
+	case PLD_BUS_TYPE_USB:
+	ret = pld_usb_get_fw_files_for_target(pfw_files,
+				target_type, target_version);
+	break;
 	default:
 		ret = -EINVAL;
 		break;
@@ -574,6 +592,8 @@ int pld_get_codeswap_struct(struct device *dev,
 		break;
 	case PLD_BUS_TYPE_SDIO:
 		break;
+	case PLD_BUS_TYPE_USB:
+		break;
 	default:
 		ret = -EINVAL;
 		break;
@@ -880,6 +900,8 @@ void pld_request_pm_qos(struct device *dev, u32 qos_val)
 	case PLD_BUS_TYPE_SDIO:
 		/* To do Add call cns API */
 		break;
+	case PLD_BUS_TYPE_USB:
+		break;
 	default:
 		pr_err("Invalid device type\n");
 		break;
@@ -1311,6 +1333,8 @@ void pld_lock_pm_sem(struct device *dev)
 		break;
 	case PLD_BUS_TYPE_SDIO:
 		break;
+	case PLD_BUS_TYPE_USB:
+		break;
 	default:
 		pr_err("Invalid device type\n");
 		break;
@@ -1333,6 +1357,8 @@ void pld_release_pm_sem(struct device *dev)
 		break;
 	case PLD_BUS_TYPE_SDIO:
 		break;
+	case PLD_BUS_TYPE_USB:
+		break;
 	default:
 		pr_err("Invalid device type\n");
 		break;

+ 211 - 0
core/pld/src/pld_usb.c

@@ -0,0 +1,211 @@
+/*
+ * Copyright (c) 2016 The Linux Foundation. All rights reserved.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for
+ * any purpose with or without fee is hereby granted, provided that the
+ * above copyright notice and this permission notice appear in all
+ * copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
+ * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "pld_common.h"
+#include "pld_internal.h"
+
+#include <linux/atomic.h>
+#include <linux/usb.h>
+#include <linux/slab.h>
+#include <linux/platform_device.h>
+#include <linux/err.h>
+#include <linux/list.h>
+
+
+#define VENDOR_ATHR             0x0CF3
+static struct usb_device_id pld_usb_id_table[] = {
+	{USB_DEVICE_AND_INTERFACE_INFO(VENDOR_ATHR, 0x9378, 0xFF, 0xFF, 0xFF)},
+	{}			/* Terminating entry */
+};
+
+atomic_t pld_usb_reg_done;
+
+/**
+ * pld_usb_probe() - pld_usb_probe
+ * @interface: pointer to usb_interface structure
+ * @id: pointer to usb_device_id obtained from the enumerated device
+
+ * Return: int 0 on success and errno on failure.
+ */
+static int pld_usb_probe(struct usb_interface *interface,
+					const struct usb_device_id *id)
+{
+	struct usb_device *pdev = interface_to_usbdev(interface);
+	struct pld_context *pld_context;
+	int ret = 0;
+
+	pld_context = pld_get_global_context();
+	if (!pld_context) {
+		ret = -ENODEV;
+		goto out;
+	}
+
+	ret = pld_add_dev(pld_context, &pdev->dev, PLD_BUS_TYPE_USB);
+	if (ret)
+		goto out;
+
+	ret = pld_context->ops->probe(&pdev->dev,
+				      PLD_BUS_TYPE_USB, interface, (void *)id);
+	if (ret != 0) {
+		pr_err("%s, probe returned %d", __func__, ret);
+		atomic_set(&pld_usb_reg_done, false);
+	} else {
+		atomic_set(&pld_usb_reg_done, true);
+	}
+
+out:
+	return ret;
+}
+
+/**
+ * pld_usb_remove() - Remove function for USB device
+ * @interface: pointer to usb_interface for the usb device being removed
+ *
+ * Return: void
+ */
+static void pld_usb_remove(struct usb_interface *interface)
+{
+	struct usb_device *pdev = interface_to_usbdev(interface);
+	struct pld_context *pld_context;
+
+	pld_context = pld_get_global_context();
+
+	if (!pld_context)
+		return;
+
+	if (atomic_read(&pld_usb_reg_done) != true) {
+		pr_info("%s: already de-registered!\n", __func__);
+		return;
+	}
+
+	pld_context->ops->remove(&pdev->dev, PLD_BUS_TYPE_USB);
+
+	pld_del_dev(pld_context, &pdev->dev);
+
+	atomic_set(&pld_usb_reg_done, false);
+	pr_info("%s: done!\n", __func__);
+}
+
+/**
+ * pld_usb_suspend() - Suspend callback function for power management
+ * @interface: pointer to usb_interface for the usb device
+ * @state: power state
+ *
+ * This function is to suspend the PCIE device when power management is
+ * enabled.
+ *
+ * Return: void
+ */
+static int pld_usb_suspend(struct usb_interface *interface,
+						pm_message_t state)
+{
+	struct usb_device *pdev = interface_to_usbdev(interface);
+	struct pld_context *pld_context;
+
+	pld_context = pld_get_global_context();
+	return pld_context->ops->suspend(&pdev->dev, PLD_BUS_TYPE_USB, state);
+}
+
+/**
+ * pld_usb_resume() - Resume callback function for power management
+ * @interface: pointer to usb_interface for the usb device
+ *
+ * This function is to resume the USB device when power management is
+ * enabled.
+ *
+ * Return: void
+ */
+static int pld_usb_resume(struct usb_interface *interface)
+{
+	struct pld_context *pld_context;
+	struct usb_device *pdev = interface_to_usbdev(interface);
+
+	pld_context = pld_get_global_context();
+	return pld_context->ops->resume(&pdev->dev, PLD_BUS_TYPE_USB);
+}
+
+/**
+ * pld_usb_reset_resume() - pld_usb_reset_resume
+ * @interface: pointer to usb_interface for the usb device
+ *
+ * Return: void
+ */
+static int pld_usb_reset_resume(struct usb_interface *interface)
+{
+	struct pld_context *pld_context;
+	struct usb_device *pdev = interface_to_usbdev(interface);
+
+	pld_context = pld_get_global_context();
+	return pld_context->ops->reset_resume(&pdev->dev, PLD_BUS_TYPE_USB);
+}
+
+struct usb_driver pld_usb_ops = {
+	.name = "pld_usb",
+	.id_table = pld_usb_id_table,
+	.probe = pld_usb_probe,
+	.disconnect = pld_usb_remove,
+#ifdef CONFIG_PM
+	.suspend = pld_usb_suspend,
+	.resume = pld_usb_resume,
+	.reset_resume = pld_usb_reset_resume,
+#endif
+	.supports_autosuspend = true,
+};
+
+/**
+ * pld_usb_register_driver() - registration routine for wlan usb driver
+ *
+ * Return: int negative error code on failure and 0 on success
+ */
+int pld_usb_register_driver(void)
+{
+	int status;
+
+	usb_register(&pld_usb_ops);
+
+	if (atomic_read(&pld_usb_reg_done) == true)
+		status = 0;
+	else
+		status = -1;
+
+	pr_info("%s usb_register %s, status %d\n", __func__,
+		(status == 0) ? "done" : "failed", status);
+
+	return status;
+}
+
+/**
+ * pld_usb_unregister_driver() - de-registration routine for wlan usb driver
+ *
+ * Return: void
+ */
+void pld_usb_unregister_driver(void)
+{
+	struct pld_context *pld_context;
+	pld_context = pld_get_global_context();
+
+	if (atomic_read(&pld_usb_reg_done) == false)
+		return;
+
+	pld_context->ops->remove(NULL, PLD_BUS_TYPE_USB);
+
+	atomic_set(&pld_usb_reg_done, false);
+	usb_deregister(&pld_usb_ops);
+	pr_info("%s usb_deregister done!\n", __func__);
+}
+

+ 52 - 0
core/pld/src/pld_usb.h

@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2016 The Linux Foundation. All rights reserved.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for
+ * any purpose with or without fee is hereby granted, provided that the
+ * above copyright notice and this permission notice appear in all
+ * copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
+ * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+#ifndef __PLD_USB_H__
+#define __PLD_USB_H__
+
+#include "pld_common.h"
+
+#if !defined(CONFIG_PLD_USB_CNSS)
+static inline int pld_usb_register_driver(void)
+{
+	return 0;
+}
+
+static inline void pld_usb_unregister_driver(void)
+{
+	return;
+}
+
+static inline int pld_usb_get_ce_id(int irq)
+{
+	return 0;
+}
+#else
+int pld_usb_register_driver(void);
+void pld_usb_unregister_driver(void);
+int pld_usb_get_ce_id(int irq);
+#endif
+
+static inline int
+pld_usb_get_fw_files_for_target(struct pld_fw_files *pfw_files,
+				 u32 target_type, u32 target_version)
+{
+	pld_get_default_fw_files(pfw_files);
+	return 0;
+}
+
+#endif /*__PLD_USB_H__*/