[PATCH 14/15] usb: dwc2: Read host DMA device properties

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Read in and set the host DMA-related device properties. This is used to
control the DMA mode as a host.

Signed-off-by: John Youn <johnyoun@xxxxxxxxxxxx>
---
 drivers/usb/dwc2/core.h   |  10 +++--
 drivers/usb/dwc2/params.c | 103 +++++++++++++++-------------------------------
 2 files changed, 40 insertions(+), 73 deletions(-)

diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index ba26cb6..333e9f4 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -451,9 +451,6 @@ struct dwc2_core_params {
 #define DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE	2
 
 	int otg_ver;
-	int host_dma;
-	int host_dma_desc;
-	int host_dma_desc_fs;
 	int speed;
 #define DWC2_SPEED_PARAM_HIGH	0
 #define DWC2_SPEED_PARAM_FULL	1
@@ -491,10 +488,17 @@ struct dwc2_core_params {
 	int external_id_pin_ctl;
 	int hibernation;
 
+	/* Host parameters */
+	u8 host_dma;
+	u8 host_dma_desc;
+	u8 host_dma_desc_fs;
+
 	/*
 	 * The following parameters are *only* set via device
 	 * properties and cannot be set directly in this structure.
 	 */
+
+	/* Gadget parameters */
 	bool g_dma;
 	u16 g_rx_fifo_size;
 	u16 g_np_tx_fifo_size;
diff --git a/drivers/usb/dwc2/params.c b/drivers/usb/dwc2/params.c
index 107fd79..3db3657 100644
--- a/drivers/usb/dwc2/params.c
+++ b/drivers/usb/dwc2/params.c
@@ -388,6 +388,18 @@ static void dwc2_set_param(struct dwc2_hsotg *hsotg,
 	dwc2_set_core_param(param, size, value);
 }
 
+/**
+ * dwc2_set_param_u8() - Set a u8 parameter
+ *
+ * See dwc2_set_param().
+ */
+static void dwc2_set_param_u8(struct dwc2_hsotg *hsotg,
+			      u8 *param, char *name, u8 value,
+			      u8 def, u8 min, u8 max)
+{
+	dwc2_set_param(hsotg, param, name, value, def, min, max, 1);
+}
+
 /**
  * dwc2_set_param_u16() - Set a u16 parameter
  *
@@ -473,73 +485,6 @@ static void dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg, int val)
 	hsotg->params.otg_cap = val;
 }
 
-static void dwc2_set_param_host_dma(struct dwc2_hsotg *hsotg, int val)
-{
-	int valid = 1;
-
-	if (val > 0 && hsotg->hw_params.arch == GHWCFG2_SLAVE_ONLY_ARCH)
-		valid = 0;
-	if (val < 0)
-		valid = 0;
-
-	if (!valid) {
-		if (val >= 0)
-			dev_err(hsotg->dev,
-				"%d invalid for host_dma parameter. Check HW configuration.\n",
-				val);
-		val = hsotg->hw_params.arch != GHWCFG2_SLAVE_ONLY_ARCH;
-		dev_dbg(hsotg->dev, "Setting host_dma to %d\n", val);
-	}
-
-	hsotg->params.host_dma = val;
-}
-
-static void dwc2_set_param_host_dma_desc(struct dwc2_hsotg *hsotg, int val)
-{
-	int valid = 1;
-
-	if (val > 0 && (hsotg->params.host_dma <= 0 ||
-			!hsotg->hw_params.dma_desc_enable))
-		valid = 0;
-	if (val < 0)
-		valid = 0;
-
-	if (!valid) {
-		if (val >= 0)
-			dev_err(hsotg->dev,
-				"%d invalid for host_dma_desc parameter. Check HW configuration.\n",
-				val);
-		val = (hsotg->params.host_dma > 0 &&
-			hsotg->hw_params.dma_desc_enable);
-		dev_dbg(hsotg->dev, "Setting host_dma_desc to %d\n", val);
-	}
-
-	hsotg->params.host_dma_desc = val;
-}
-
-static void dwc2_set_param_host_dma_desc_fs(struct dwc2_hsotg *hsotg, int val)
-{
-	int valid = 1;
-
-	if (val > 0 && (hsotg->params.host_dma <= 0 ||
-			!hsotg->hw_params.dma_desc_enable))
-		valid = 0;
-	if (val < 0)
-		valid = 0;
-
-	if (!valid) {
-		if (val >= 0)
-			dev_err(hsotg->dev,
-				"%d invalid for host_dma_desc_fs parameter. Check HW configuration.\n",
-				val);
-		val = (hsotg->params.host_dma > 0 &&
-			hsotg->hw_params.dma_desc_enable);
-	}
-
-	hsotg->params.host_dma_desc_fs = val;
-	dev_dbg(hsotg->dev, "Setting host_dma_desc_fs to %d\n", val);
-}
-
 static void
 dwc2_set_param_host_support_fs_ls_low_power(struct dwc2_hsotg *hsotg,
 					    int val)
@@ -1115,9 +1060,27 @@ static void dwc2_set_parameters(struct dwc2_hsotg *hsotg,
 	dev_dbg(hsotg->dev, "%s()\n", __func__);
 
 	dwc2_set_param_otg_cap(hsotg, params->otg_cap);
-	dwc2_set_param_host_dma(hsotg, params->host_dma);
-	dwc2_set_param_host_dma_desc(hsotg, params->host_dma_desc);
-	dwc2_set_param_host_dma_desc_fs(hsotg, params->host_dma_desc_fs);
+
+	if ((hsotg->dr_mode == USB_DR_MODE_HOST) ||
+	    (hsotg->dr_mode == USB_DR_MODE_OTG)) {
+		bool slave_only = (hw->arch == GHWCFG2_SLAVE_ONLY_ARCH);
+
+		dev_dbg(hsotg->dev, "Setting HOST parameters\n");
+
+		dwc2_set_param_u8(hsotg, &p->host_dma,
+				  "host-dma", params->host_dma,
+				  slave_only ? 0 : 1,
+				  0, slave_only ? 0 : 1);
+
+		dwc2_set_param_u8(hsotg, &p->host_dma_desc,
+				  "host-dma-desc", params->host_dma_desc,
+				  0, 0, hw->dma_desc_enable ? 0 : 1);
+
+		dwc2_set_param_u8(hsotg, &p->host_dma_desc_fs,
+				  "host-dma-desc-fs", params->host_dma_desc_fs,
+				  0, 0, hw->dma_desc_enable ? 0 : 1);
+	}
+
 	dwc2_set_param_host_support_fs_ls_low_power(hsotg,
 			params->host_support_fs_ls_low_power);
 	dwc2_set_param_enable_dynamic_fifo(hsotg,
-- 
2.10.0

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux