Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1377196ybl; Mon, 2 Dec 2019 02:33:13 -0800 (PST) X-Google-Smtp-Source: APXvYqzYs0NpGOuW1Wu1j5LTl0wmJejjFtFU4h6k5naS6xahGK9vINZbO2a4u4h1bx4/kCscj/rK X-Received: by 2002:a05:6402:2d0:: with SMTP id b16mr26987777edx.227.1575282793104; Mon, 02 Dec 2019 02:33:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575282793; cv=none; d=google.com; s=arc-20160816; b=HaJM3rHaAR5YsZjneHA7KwTWW1qu2o0YX4+07kI+5UM5XkaqKThnWtBcEMXhc4cvnN 6yD9QCEELbqfsqYdGthXr/eraMPussc1luiT5YgGtZHZPgQLOSwOSu2UrGe4K3PTrLCW mpgddayGne75VUg6lmYR+YnNpatkf2xBcZRwSY81J2886NCuWXTZNsWq0eIN0IrrQhjW x/HJzzqcyR6x9MLSMNUGwUd+9uZ/7TFN43XoRkWUiD86+wuZ/hwX8CJ/bJ/FYX0NM0QN umd32vCGsiP1aXNwzaPaO+3XPnxofKat2O80xmuY4DO8PoI+l8Sg9cLie2k6LtAIFu89 Tp/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=g6dP6ry74SEyd5dt7pE6fUowydAenmGxZnWV3bHJzlY=; b=se3cKC2nR3DEi9nL1fzCKArnxSQiMFvceeiV88YPzyOrKIdj3nulyTAqpeH+1gE1E7 cEW/Khlh+dGAlu0cjzu9m8AISoD9TRy/G3r4wKKZ7n9u1SH2VnIMzvAZSlB1V1az6eaq EYCmdTCSEMaYHAbK/55FNWKm7zH+ZEPSyZaQzOt+wiuvl6W/uTaykxtTyxdtglHHdcO1 9Hm0NbWvXD+T7fE+G5NQOoZU7k2V9dw/zcW2Sx6hQ+NGMG9B9iled3Gr0vEMcT+DEt+A OGU7YbuVBnGBaDPPfllVPuXPLKSHJb+1zTdDsJjE6LGijWufvaNjZzfENUDIFHYK3/jl JODQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nexus-software-ie.20150623.gappssmtp.com header.s=20150623 header.b=FRWIy0Lc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i3si774187edj.304.2019.12.02.02.32.49; Mon, 02 Dec 2019 02:33:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nexus-software-ie.20150623.gappssmtp.com header.s=20150623 header.b=FRWIy0Lc; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727493AbfLBKb4 (ORCPT + 99 others); Mon, 2 Dec 2019 05:31:56 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:32991 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726330AbfLBKbz (ORCPT ); Mon, 2 Dec 2019 05:31:55 -0500 Received: by mail-wr1-f67.google.com with SMTP id b6so13902733wrq.0 for ; Mon, 02 Dec 2019 02:31:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nexus-software-ie.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=g6dP6ry74SEyd5dt7pE6fUowydAenmGxZnWV3bHJzlY=; b=FRWIy0LcmognG1qfwrTGSr0PLfZcbrji5ZkGhbvmL9+t5Z/1tkWpUJWpg4LbR/u722 G3G0iev2HvWqjWawHkbYyLH0J+/EzVoarvqvFa5OiCCrMeLBpI+dElbXhO9v5hMxk3HQ PpOxzCHtpjunyLTRE2C3SUQHBQY45W6fVIJPtTUl6GULbJ6KrYBW2hmM1tKyTfWM4QDI 0vsEXerQ3h2xjj6m4bW0HGeazo4BxoPk+rVg0WgvpLHxtDDhDBtoYCW7WDWtEbyeAAX8 L/gYWyPPNI6lVfVFvi5nklBlHiZq/sACEUi3VGP6WIKF+iywnenX4aDy2hEUiARmzugT Zq7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=g6dP6ry74SEyd5dt7pE6fUowydAenmGxZnWV3bHJzlY=; b=gYhq3LguVYtcHRzYsTU1aIOZUIqax5R7FLsu8rZKylhzhgjGwUO6eG570U+B3e10mX jNFhg1FmnRwvo59W5QnyzkzQHEcx3Ud5NpCkzGvrvKyua0RoJzLLgoXuT+dSjykPz0eZ rFAo4cNLp2sWXICSMdxL6vJC8pPeSHadzJAkza0or9XZdlYBtn0JuXgVO1cJnjvEuBAv JiftQS59+Yce908GZad8T+GicVOqgh/zk8iIr1yGnW1gTLXY7zBNcyd9J7qAgpR7O7Bb QcwON2lZe5jl2eDky0zyGnjqEUrBkeSYNHamn5wq4ZWnzznffHyh0gu3bW+UzZWgEU7y Wl8g== X-Gm-Message-State: APjAAAWOmSq9bnaJoCO2J6mqM1s1NS593LKoTa+QYLHx+F5BV/kyTm53 XWC8IJF3KIPpNPkQzZ4WYv0o/Q== X-Received: by 2002:a5d:4a84:: with SMTP id o4mr9589645wrq.396.1575282713284; Mon, 02 Dec 2019 02:31:53 -0800 (PST) Received: from [192.168.0.38] ([176.61.57.127]) by smtp.gmail.com with ESMTPSA id i127sm24352606wma.35.2019.12.02.02.31.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 02 Dec 2019 02:31:52 -0800 (PST) Subject: Re: [PATCH v6 3/8] usb: dwc3: Add support for role-switch-default-mode binding To: John Stultz , lkml Cc: Greg Kroah-Hartman , Rob Herring , Mark Rutland , ShuFan Lee , Heikki Krogerus , Suzuki K Poulose , Chunfeng Yun , Yu Chen , Felipe Balbi , Hans de Goede , Andy Shevchenko , Jun Li , Valentin Schneider , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org References: <20191128051001.18995-1-john.stultz@linaro.org> <20191128051001.18995-4-john.stultz@linaro.org> From: Bryan O'Donoghue Message-ID: <97d3570e-2b4f-b32e-fe1a-bf0f49603238@nexus-software.ie> Date: Mon, 2 Dec 2019 10:32:07 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <20191128051001.18995-4-john.stultz@linaro.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 28/11/2019 05:09, John Stultz wrote: > Support the new role-switch-default-mode binding for configuring > the default role the controller assumes as when the usb role is > USB_ROLE_NONE > > This patch was split out from a larger patch originally by > Yu Chen > > Cc: Greg Kroah-Hartman > Cc: Rob Herring > Cc: Mark Rutland > CC: ShuFan Lee > Cc: Heikki Krogerus > Cc: Suzuki K Poulose > Cc: Chunfeng Yun > Cc: Yu Chen > Cc: Felipe Balbi > Cc: Hans de Goede > Cc: Andy Shevchenko > Cc: Jun Li > Cc: Valentin Schneider > Cc: Jack Pham > Cc: linux-usb@vger.kernel.org > Cc: devicetree@vger.kernel.org > Signed-off-by: John Stultz > Change-Id: Ic6e4df1109b350deaecdc69f667d49ce91d599f3 > --- > v3: Split this patch out from addition of usb-role-switch > handling > v5: Reworked to use string based role-switch-default-mode > --- > drivers/usb/dwc3/core.h | 3 +++ > drivers/usb/dwc3/drd.c | 25 ++++++++++++++++++++++--- > 2 files changed, 25 insertions(+), 3 deletions(-) > > diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h > index 6f19e9891767..3c879c9ab1aa 100644 > --- a/drivers/usb/dwc3/core.h > +++ b/drivers/usb/dwc3/core.h > @@ -953,6 +953,8 @@ struct dwc3_scratchpad_array { > * - USBPHY_INTERFACE_MODE_UTMI > * - USBPHY_INTERFACE_MODE_UTMIW > * @role_sw: usb_role_switch handle > + * @role_switch_default_mode: default operation mode of controller while > + * usb role is USB_ROLE_NONE. > * @usb2_phy: pointer to USB2 PHY > * @usb3_phy: pointer to USB3 PHY > * @usb2_generic_phy: pointer to USB2 PHY > @@ -1087,6 +1089,7 @@ struct dwc3 { > struct notifier_block edev_nb; > enum usb_phy_interface hsphy_mode; > struct usb_role_switch *role_sw; > + enum usb_dr_mode role_switch_default_mode; > > u32 fladj; > u32 irq_gadget; > diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c > index 3b57d2ddda93..865341facece 100644 > --- a/drivers/usb/dwc3/drd.c > +++ b/drivers/usb/dwc3/drd.c > @@ -491,7 +491,10 @@ static int dwc3_usb_role_switch_set(struct device *dev, enum usb_role role) > mode = DWC3_GCTL_PRTCAP_DEVICE; > break; > default: > - mode = DWC3_GCTL_PRTCAP_DEVICE; > + if (dwc->role_switch_default_mode == USB_DR_MODE_HOST) > + mode = DWC3_GCTL_PRTCAP_HOST; > + else > + mode = DWC3_GCTL_PRTCAP_DEVICE; > break; > } > > @@ -517,7 +520,10 @@ static enum usb_role dwc3_usb_role_switch_get(struct device *dev) > role = dwc->current_otg_role; > break; > default: > - role = USB_ROLE_DEVICE; > + if (dwc->role_switch_default_mode == USB_DR_MODE_HOST) > + role = USB_ROLE_HOST; > + else > + role = USB_ROLE_DEVICE; > break; > } > spin_unlock_irqrestore(&dwc->lock, flags); > @@ -527,6 +533,19 @@ static enum usb_role dwc3_usb_role_switch_get(struct device *dev) > static int dwc3_setup_role_switch(struct dwc3 *dwc) > { > struct usb_role_switch_desc dwc3_role_switch = {NULL}; > + const char *str; > + u32 mode; > + int ret; > + > + ret = device_property_read_string(dwc->dev, "role-switch-default-mode", > + &str); > + if (ret >= 0 && !strncmp(str, "host", strlen("host"))) { > + dwc->role_switch_default_mode = USB_DR_MODE_HOST; > + mode = DWC3_GCTL_PRTCAP_HOST; > + } else { > + dwc->role_switch_default_mode = USB_DR_MODE_PERIPHERAL; > + mode = DWC3_GCTL_PRTCAP_DEVICE; > + } > > dwc3_role_switch.fwnode = dev_fwnode(dwc->dev); > dwc3_role_switch.set = dwc3_usb_role_switch_set; > @@ -535,7 +554,7 @@ static int dwc3_setup_role_switch(struct dwc3 *dwc) > if (IS_ERR(dwc->role_sw)) > return PTR_ERR(dwc->role_sw); > > - dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE); > + dwc3_set_mode(dwc, mode); > return 0; > } > #else > I've used this on a qcs404 - it works for me. Tested-by: Bryan O'Donoghue