Re: [PATCH] usb: dwc3: Initialize DMA ops/mask for xhci-hcd

From: Adam Wallis
Date: Mon Aug 28 2017 - 11:31:47 EST


On 8/25/2017 7:03 PM, Grygorii Strashko wrote:
>
>
> On 08/25/2017 01:02 PM, Adam Wallis wrote:
>> The dma ops from the parent DWC device are not getting passed to the
>> child xhci-hcd device. This patch makes use of
>> platform_device_register_full to set the DMA ops. For the DT/OF case,
>> dma_ops were still null after the the device register, so
>> of_dma_configure is called in only the OF case.
>>
>> Signed-off-by: Adam Wallis <awallis@xxxxxxxxxxxxxx>
>
> Hm. There were set of fixes in this area recently which actually removed
> settings you are going to restore

The set of fixes works for DWC if it is a child device, but in my testing, those
DMA settings do not get propagated to the created xHCI-hcd child device (which
is instantiated in dwc3_host_init). I see the same behavior with ACPI and
Device-Tree/OF boot.

>
> 4c39d4b usb: xhci: use bus->sysdev for DMA configuration
>
> d64ff40 usb: dwc3: use bus->sysdev for DMA configuration
>
>> ---
>> Â drivers/usb/dwc3/host.c | 39 +++++++++++++++++----------------------
>> Â 1 file changed, 17 insertions(+), 22 deletions(-)
>>
>> diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c
>> index 76f0b0d..662e9e2 100644
>> --- a/drivers/usb/dwc3/host.c
>> +++ b/drivers/usb/dwc3/host.c
>> @@ -16,6 +16,7 @@
>> ÂÂ */
>> Â Â #include <linux/platform_device.h>
>> +#include <linux/of_platform.h>
>> Â Â #include "core.h"
>> Â @@ -56,6 +57,7 @@ int dwc3_host_init(struct dwc3 *dwc)
>> Â {
>> ÂÂÂÂÂ struct property_entryÂÂÂ props[3];
>> ÂÂÂÂÂ struct platform_deviceÂÂÂ *xhci;
>> +ÂÂÂ struct platform_device_info dwc_plat_info = {};
>> ÂÂÂÂÂ intÂÂÂÂÂÂÂÂÂÂÂ ret, irq;
>> ÂÂÂÂÂ struct resourceÂÂÂÂÂÂÂ *res;
>> ÂÂÂÂÂ struct platform_deviceÂÂÂ *dwc3_pdev = to_platform_device(dwc->dev);
>> @@ -79,22 +81,22 @@ int dwc3_host_init(struct dwc3 *dwc)
>> ÂÂÂÂÂ dwc->xhci_resources[1].flags = res->flags;
>> ÂÂÂÂÂ dwc->xhci_resources[1].name = res->name;
>> Â -ÂÂÂ xhci = platform_device_alloc("xhci-hcd", PLATFORM_DEVID_AUTO);
>> -ÂÂÂ if (!xhci) {
>> -ÂÂÂÂÂÂÂ dev_err(dwc->dev, "couldn't allocate xHCI device\n");
>> -ÂÂÂÂÂÂÂ return -ENOMEM;
>> -ÂÂÂ }
>> +ÂÂÂ dwc_plat_info.name = "xhci-hcd";
>> +ÂÂÂ dwc_plat_info.parent = dwc->dev;
>> +ÂÂÂ dwc_plat_info.res = dwc->xhci_resources;
>> +ÂÂÂ dwc_plat_info.num_res = DWC3_XHCI_RESOURCES_NUM;
>> +ÂÂÂ dwc_plat_info.fwnode = dwc->dev->fwnode;
>> +ÂÂÂ dwc_plat_info.dma_mask = *dwc->dev->dma_mask;
>> Â -ÂÂÂ xhci->dev.parentÂÂÂ = dwc->dev;
>> +ÂÂÂ xhci = platform_device_register_full(&dwc_plat_info);
>> +ÂÂÂ if (IS_ERR(xhci)) {
>> +ÂÂÂÂÂÂÂ dev_err(dwc->dev, "failed to register xHCI device\n");
>> +ÂÂÂÂÂÂÂ return PTR_ERR(xhci);
>> +ÂÂÂ }
>> Â ÂÂÂÂÂ dwc->xhci = xhci;
>> -
>> -ÂÂÂ ret = platform_device_add_resources(xhci, dwc->xhci_resources,
>> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ DWC3_XHCI_RESOURCES_NUM);
>> -ÂÂÂ if (ret) {
>> -ÂÂÂÂÂÂÂ dev_err(dwc->dev, "couldn't add resources to xHCI device\n");
>> -ÂÂÂÂÂÂÂ goto err1;
>> -ÂÂÂ }
>> +ÂÂÂ if (dwc->dev->of_node)
>> +ÂÂÂÂÂÂÂ of_dma_configure(&xhci->dev, dwc->dev->of_node);
>> Â ÂÂÂÂÂ memset(props, 0, sizeof(struct property_entry) * ARRAY_SIZE(props));
>> Â @@ -117,7 +119,7 @@ int dwc3_host_init(struct dwc3 *dwc)
>> ÂÂÂÂÂÂÂÂÂ ret = platform_device_add_properties(xhci, props);
>> ÂÂÂÂÂÂÂÂÂ if (ret) {
>> ÂÂÂÂÂÂÂÂÂÂÂÂÂ dev_err(dwc->dev, "failed to add properties to xHCI\n");
>> -ÂÂÂÂÂÂÂÂÂÂÂ goto err1;
>> +ÂÂÂÂÂÂÂÂÂÂÂ goto err;
>> ÂÂÂÂÂÂÂÂÂ }
>> ÂÂÂÂÂ }
>> Â @@ -126,19 +128,12 @@ int dwc3_host_init(struct dwc3 *dwc)
>> ÂÂÂÂÂ phy_create_lookup(dwc->usb3_generic_phy, "usb3-phy",
>> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ dev_name(dwc->dev));
>> Â -ÂÂÂ ret = platform_device_add(xhci);
>> -ÂÂÂ if (ret) {
>> -ÂÂÂÂÂÂÂ dev_err(dwc->dev, "failed to register xHCI device\n");
>> -ÂÂÂÂÂÂÂ goto err2;
>> -ÂÂÂ }
>> -
>> ÂÂÂÂÂ return 0;
>> -err2:
>> +err:
>> ÂÂÂÂÂ phy_remove_lookup(dwc->usb2_generic_phy, "usb2-phy",
>> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ dev_name(dwc->dev));
>> ÂÂÂÂÂ phy_remove_lookup(dwc->usb3_generic_phy, "usb3-phy",
>> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ dev_name(dwc->dev));
>> -err1:
>> ÂÂÂÂÂ platform_device_put(xhci);
>> ÂÂÂÂÂ return ret;
>> Â }
>>
>


--
Adam Wallis
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project.