From patchwork Tue Feb 25 17:52:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 183869 Delivered-To: patches@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp2041136ile; Tue, 25 Feb 2020 09:53:34 -0800 (PST) X-Received: by 2002:a17:90a:102:: with SMTP id b2mr176817pjb.64.1582653213900; Tue, 25 Feb 2020 09:53:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582653213; cv=none; d=google.com; s=arc-20160816; b=B94d2rm3Ma1cCgQCoGNATgcTBVz3JzFfopjciGa8ElCe/Zgabw2IGqlCmXvMsfPZKn OuJdjofMdSAIKljEnYseBLs1zr0kbXRumYMadqo0H8hjwiJgjR7/yglEbOXpZECVmt3V Zqi99r0xsj3djkSSFCUzAkx9Y+hPnMgbPYFAK/djOfA2aEbZlTIsHIlXLBS5pwjyszzx 7+72rh9MIuYk77wauoac2MUejWfBH6FyobmeWiXCfYlZzySkvdIdSElXEfenWM/Xf0zn z3v1t2GC+FahjPKJ/s6wivSu5HWdunNg4CTwrDx5W3Fw2XrG800eB5fZCn4+V5eGbV/K wa3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WAV7i9DpkYyptymNiUj/uooXSddOTDPzEmF8/rLdzNA=; b=iGdYvYG6qx3j62hVXR367DuiRXOlbsekn2EcvzaZ0JWjttPHuw527f1W5I9wsNsoss tiZrF0vSNkXl8wQ7+jAAQWnxnvErBW7rrLVoHWV1ztXRUUq6k30d0XrIEX5OqLTaNqcr Ps1az6sdDrbEg2uFlcqa67CKcHtgvI+wya8Coh+66AbxSyrNaSqrCnJMh6zSIZ96Owv9 aTk3f/togmum2lWHXh4nwazLEKlOlgI0+7Vkw+avaq3wW3W14k4NVFfnErzn8SSH1zc+ E+ZvoorNSSpVPlDHyf1WBvEImk667b86NXuNzgjoLQ9JKBK7XoI2TbScDzYVdssi3zdJ 2zow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=d+TgHQXB; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id w3sor259432plq.36.2020.02.25.09.53.33 for (Google Transport Security); Tue, 25 Feb 2020 09:53:33 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=d+TgHQXB; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WAV7i9DpkYyptymNiUj/uooXSddOTDPzEmF8/rLdzNA=; b=d+TgHQXBZ2fj6XhsaxC9E2hoQsUCLxnFHPnwEo6sgOuLEXduum3xsPaooFFHauzSVB muhHv3f59kZsioiKtKmx5BRfHkHXJyTdZRHpVxZ0FqMHIz5qfIjPSCghyork9+f68w7/ 5WBA0U7TdBf5Uw1ljyMHMHCHGBdWJ32oZY10Fn3dR4CIEWP/aAPkDNvyWwU8/zCUGEuS 8pBdp/I3O1ffy7TvB71P13R4S4SC6BT6hkFRm/+jr/XAUPKqMFLgkie0omQjiaWtohy4 JVHQnr7i2nEMB/5Mj/HVPN2ZkluthJFBCR5sQYygn8fQofWWo3wWY3mGwioSMWLInJCO xMGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WAV7i9DpkYyptymNiUj/uooXSddOTDPzEmF8/rLdzNA=; b=tTvO+NHpbin1bGjJHWxnZkgK4inTWIdMsy8CHd1/cubLnhTUA7cN5Da8gFwFIrWKjK +qp8xsE6MbtUsxPAxj6zJxGuzfzSKaHH8JofC38OeGbpD4w+VSMv9z3An2EqTIbVf2w6 HRd4gnxPJ6AfN4rV6Z8WCC3eCBgac9p2AyOJoMmPQDD84j3LknLA0QC5LH3/EKTTSzBQ /GrQmzyABA7kXD3MR0YCNPTKy4SRpOy3cwkDHPoQdG5y0E21qqrNWyutydfIOBX/Cy66 CuemGKm2uBDwxIWuHWkqa7Wl5QI1p3wVCchBoqKKT8P7glDm3AGci6/6jW3yDUa67HLI RaPg== X-Gm-Message-State: APjAAAVy9BaqiWTAd29syjpPecmeGXic8UCMIcij+THkh4K/nLVZS05a y9VspS5QSm0HADjHbRgovimXkeeH X-Google-Smtp-Source: APXvYqyqzh2Wh9kpkkh4/o+bVTS4si3nFIOu+ZMfqBQGNOyilHJUHwQZkihm64jlso6bjaZZmtzQiQ== X-Received: by 2002:a17:902:8549:: with SMTP id d9mr54945952plo.153.1582653213518; Tue, 25 Feb 2020 09:53:33 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id v8sm18013291pgt.52.2020.02.25.09.53.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 09:53:33 -0800 (PST) From: John Stultz To: lkml Cc: Yu Chen , Greg Kroah-Hartman , Rob Herring , Mark Rutland , ShuFan Lee , Heikki Krogerus , Suzuki K Poulose , Chunfeng Yun , Felipe Balbi , Hans de Goede , Andy Shevchenko , Jun Li , Valentin Schneider , Guillaume Gardet , Jack Pham , Bryan O'Donoghue , linux-usb@vger.kernel.org, devicetree@vger.kernel.org, John Stultz Subject: [PATCH v8 1/6] usb: dwc3: Registering a role switch in the DRD code. Date: Tue, 25 Feb 2020 17:52:59 +0000 Message-Id: <20200225175304.36406-2-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200225175304.36406-1-john.stultz@linaro.org> References: <20200225175304.36406-1-john.stultz@linaro.org> From: Yu Chen The Type-C drivers use USB role switch API to inform the system about the negotiated data role, so registering a role switch in the DRD code in order to support platforms with USB Type-C connectors. 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: Guillaume Gardet Cc: Jack Pham Cc: Bryan O'Donoghue Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Suggested-by: Heikki Krogerus Tested-by: Bryan O'Donoghue Signed-off-by: Yu Chen Signed-off-by: John Stultz --- v2: Fix role_sw and role_switch_default_mode descriptions as reported by kbuild test robot v3: Split out the role-switch-default-host logic into its own patch v5: Drop selecting CONFIG_USB_ROLE_SWITCH & ifdef dependent code v6: Fix build issue Reported-by: kbuild test robot v7: Minor fix for CONFIG_USB_ROLE_SWITCH=m case not building the role switch handling code, reported by Guillaume Gardet --- drivers/usb/dwc3/core.h | 3 ++ drivers/usb/dwc3/drd.c | 77 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 79 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 77c4a9abe365..a99e57636172 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -953,6 +954,7 @@ struct dwc3_scratchpad_array { * @hsphy_mode: UTMI phy mode, one of following: * - USBPHY_INTERFACE_MODE_UTMI * - USBPHY_INTERFACE_MODE_UTMIW + * @role_sw: usb_role_switch handle * @usb2_phy: pointer to USB2 PHY * @usb3_phy: pointer to USB3 PHY * @usb2_generic_phy: pointer to USB2 PHY @@ -1086,6 +1088,7 @@ struct dwc3 { struct extcon_dev *edev; struct notifier_block edev_nb; enum usb_phy_interface hsphy_mode; + struct usb_role_switch *role_sw; u32 fladj; u32 irq_gadget; diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c index c946d64142ad..331c6e997f0c 100644 --- a/drivers/usb/dwc3/drd.c +++ b/drivers/usb/dwc3/drd.c @@ -476,6 +476,73 @@ static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc) return edev; } +#if IS_ENABLED(CONFIG_USB_ROLE_SWITCH) +#define ROLE_SWITCH 1 +static int dwc3_usb_role_switch_set(struct device *dev, enum usb_role role) +{ + struct dwc3 *dwc = dev_get_drvdata(dev); + u32 mode; + + switch (role) { + case USB_ROLE_HOST: + mode = DWC3_GCTL_PRTCAP_HOST; + break; + case USB_ROLE_DEVICE: + mode = DWC3_GCTL_PRTCAP_DEVICE; + break; + default: + mode = DWC3_GCTL_PRTCAP_DEVICE; + break; + } + + dwc3_set_mode(dwc, mode); + return 0; +} + +static enum usb_role dwc3_usb_role_switch_get(struct device *dev) +{ + struct dwc3 *dwc = dev_get_drvdata(dev); + unsigned long flags; + enum usb_role role; + + spin_lock_irqsave(&dwc->lock, flags); + switch (dwc->current_dr_role) { + case DWC3_GCTL_PRTCAP_HOST: + role = USB_ROLE_HOST; + break; + case DWC3_GCTL_PRTCAP_DEVICE: + role = USB_ROLE_DEVICE; + break; + case DWC3_GCTL_PRTCAP_OTG: + role = dwc->current_otg_role; + break; + default: + role = USB_ROLE_DEVICE; + break; + } + spin_unlock_irqrestore(&dwc->lock, flags); + return role; +} + +static int dwc3_setup_role_switch(struct dwc3 *dwc) +{ + struct usb_role_switch_desc dwc3_role_switch = {NULL}; + + dwc3_role_switch.fwnode = dev_fwnode(dwc->dev); + dwc3_role_switch.set = dwc3_usb_role_switch_set; + dwc3_role_switch.get = dwc3_usb_role_switch_get; + dwc->role_sw = usb_role_switch_register(dwc->dev, &dwc3_role_switch); + if (IS_ERR(dwc->role_sw)) + return PTR_ERR(dwc->role_sw); + + dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE); + return 0; +} +#else +#define ROLE_SWITCH 0 +#define dwc3_setup_role_switch(x) 0 +#endif + int dwc3_drd_init(struct dwc3 *dwc) { int ret, irq; @@ -484,7 +551,12 @@ int dwc3_drd_init(struct dwc3 *dwc) if (IS_ERR(dwc->edev)) return PTR_ERR(dwc->edev); - if (dwc->edev) { + if (ROLE_SWITCH && + device_property_read_bool(dwc->dev, "usb-role-switch")) { + ret = dwc3_setup_role_switch(dwc); + if (ret < 0) + return ret; + } else if (dwc->edev) { dwc->edev_nb.notifier_call = dwc3_drd_notifier; ret = extcon_register_notifier(dwc->edev, EXTCON_USB_HOST, &dwc->edev_nb); @@ -531,6 +603,9 @@ void dwc3_drd_exit(struct dwc3 *dwc) { unsigned long flags; + if (dwc->role_sw) + usb_role_switch_unregister(dwc->role_sw); + if (dwc->edev) extcon_unregister_notifier(dwc->edev, EXTCON_USB_HOST, &dwc->edev_nb); From patchwork Tue Feb 25 17:53:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 183870 Delivered-To: patches@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp2041255ile; Tue, 25 Feb 2020 09:53:41 -0800 (PST) X-Received: by 2002:a65:5306:: with SMTP id m6mr54420012pgq.5.1582653221617; Tue, 25 Feb 2020 09:53:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582653221; cv=none; d=google.com; s=arc-20160816; b=aXh5K+6yVsH/XVSWeOXXD5rwZSCu1z6ywtqUT4sgGLz/cNqwxzWAvnuahaPjGRCy5i RBZAGtpcrBWsTw7C03ZEAZzOrfx+Kt2YMqedVfydfjiCr887K8iGkDQMyYcH8xzRKInM xXdiZLmLvv2YI77a7CMwbTdMubcQHiSenDZX2D1WyGapP00UXKoH1OGM9F11DzUy3zYL 7AXQ9NR8fqe9Bx8Ef61xA4mye3D3+yO6W+SRxVLXWeW8PslvI53q/sqInnAwIOvAxVp1 M/39UNOg7aIW0N91UXcyoFGWPE030TT7pO0lgVFyxSCyON2oWmrqYKWts1rMlsEKNzYS bkBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BvrsPeqWN8PtkcsNQt8nmKsbCOyaPIU6nwAu5WHHWq8=; b=Drqz/9nTA3liI6pchipcRA5vF8CSS0xC0WdPTABD6hwkPfw4Wta1p/i2Z2mbq/nsVO 1uVfcHSLYLeSlnMQEkiepG1V+Nb1lXad2HHPRMRda8CVZDqmef21buVpjgnfSurzP/dD PYTNAtfLxoqVFy85cro2VrSEOyzQlL0Elcc/+ay8MdaLOUT71alAx8tJ6Ri24aeIaCVS taI11KKtSvJdlrZfxTCwceOJ8PRvxaYGBTJgLdevaKeI/i87CjijtSppjlkFNwbveDJ8 /HrJDQ7Xf7Be2W9Udsbf0pChUHH2J++HBji3vcpB9OERdJRtHJdTAxcFftKtV3OmVnHe fkGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qJIcjNpq; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id s24sor91612pjp.21.2020.02.25.09.53.41 for (Google Transport Security); Tue, 25 Feb 2020 09:53:41 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qJIcjNpq; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BvrsPeqWN8PtkcsNQt8nmKsbCOyaPIU6nwAu5WHHWq8=; b=qJIcjNpq7sNoGonrSyBwsUENY6YaoKkRyUf20hxq8GnBbV3M27SCu0TVozV1KzZdlM 8VBOe1y43XOXOxUEvDB+W7bWNdMDQgS3/Tstdgx/URb7qasOfRM4L+T6OTFEUKIksSZb Y8095fEto0/TFnclle7yDkOmHXwf+D7G95FlABoJfmhlv/oRE2KYDjFdLynf90Mu57c0 /03xXJeFOzwv383EhjYytugA4QmBO9KJmPRVnVqEKk0jGojepBVvWUzwxQNBe5usWNUa HMterUg597cX+SsY3MY78kRiB7g6NRJUlVW0sEtn+8DRWhN1mni7MzBb95i+SVj8eOBV nxqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=BvrsPeqWN8PtkcsNQt8nmKsbCOyaPIU6nwAu5WHHWq8=; b=rP/5/rFbfH5M3rkRyUcTSIEH3LJR5IoN2dCqrFX+jhBZfy3+ooePYsre8Jyfza6Ke+ 1q3y6wZoCKk0hzJCOxpUnMmQ7GwW30/QesvsDZ4gwamItfzP77vzYw1hPiB2zqrwJLjc 9/v1qXLMoDHa7B0gn87OvNpHcndGVoXkvMBD5nW1ZrWmOmWjF0q0LYeOl7KqxWGFRhaP Xrd9t9CpnpuSZJ9cEd6UhxV7f93/zsU07EikaK2Fdm7tgnxjLdFYDTHBik8TWRntOphc xNFD+hemac3Thx7cIPcFmMq92nKhJtLCZajh+FPnJE9ZBg+sU2Kj3zeO//J0rKDv0ME3 akdA== X-Gm-Message-State: APjAAAWOpjWwuFsiH2IJjBwNxwD6/I77dMThqRWnlzoFAENURyecb/GK ePuCcIqmMR8IpGUc0YUd23k1/D+X X-Google-Smtp-Source: APXvYqyuKIgv1526C84JiSsSOclqQi0aMoZtQERj2XWo+5FnwHBWcbSGK4675peuZbzUFDL4AF5KFg== X-Received: by 2002:a17:90a:9284:: with SMTP id n4mr123696pjo.69.1582653221195; Tue, 25 Feb 2020 09:53:41 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id v8sm18013291pgt.52.2020.02.25.09.53.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 09:53:40 -0800 (PST) From: John Stultz To: lkml Cc: John Stultz , 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 , Guillaume Gardet , Jack Pham , Bryan O'Donoghue , linux-usb@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v8 2/6] dt-bindings: usb: generic: Add role-switch-default-mode binding Date: Tue, 25 Feb 2020 17:53:00 +0000 Message-Id: <20200225175304.36406-3-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200225175304.36406-1-john.stultz@linaro.org> References: <20200225175304.36406-1-john.stultz@linaro.org> Add binding to configure the default role the controller assumes is host mode when the usb role is USB_ROLE_NONE. 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: Guillaume Gardet Cc: Jack Pham Cc: Bryan O'Donoghue Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Reviewed-by: Rob Herring Signed-off-by: John Stultz --- v5: Switch to string rather then a bool --- Documentation/devicetree/bindings/usb/generic.txt | 6 ++++++ 1 file changed, 6 insertions(+) -- 2.17.1 diff --git a/Documentation/devicetree/bindings/usb/generic.txt b/Documentation/devicetree/bindings/usb/generic.txt index e6790d2a4da9..67c51759a642 100644 --- a/Documentation/devicetree/bindings/usb/generic.txt +++ b/Documentation/devicetree/bindings/usb/generic.txt @@ -35,6 +35,12 @@ Optional properties: the USB data role (USB host or USB device) for a given USB connector, such as Type-C, Type-B(micro). see connector/usb-connector.txt. + - role-switch-default-mode: indicating if usb-role-switch is enabled, the + device default operation mode of controller while usb + role is USB_ROLE_NONE. Valid arguments are "host" and + "peripheral". Defaults to "peripheral" if not + specified. + This is an attribute to a USB controller such as: From patchwork Tue Feb 25 17:53:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 183871 Delivered-To: patches@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp2041370ile; Tue, 25 Feb 2020 09:53:50 -0800 (PST) X-Received: by 2002:a17:90b:3cc:: with SMTP id go12mr118525pjb.89.1582653230650; Tue, 25 Feb 2020 09:53:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582653230; cv=none; d=google.com; s=arc-20160816; b=FK5oYFj5rIdy4dY2HK/lydI+ca/5SUNjdPfUvtLCLfB9dJbs8izgZ2iHguI/POpY7y 7rxk0j6h6NapuKwTfUUsdsnj1DmUxqM5TC2kG8eqhqNhgFyQvhx6YadLBLMfkGXnxHqO a6SnBu5uOJkMSBm8kZC37zpJqIFjV2XuC11xRFI95XWsTDJk8IebamPZe3pa+030Ov3V /ivekkY3GnUWKGyd0l6Gco+eiLkS1VVL66FeFFrwkBdPQUfaGA+ciBf26mp0XBIpDrqt qFglDhN9c7ZMjgy+2VKEUn5HnUzAST7KPw3svkp3BhvMaWR/qfwbXgj/zwDTBEBbpdpA RJDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qTnHuEFnXMMcLEn+/gKdeCOo8JW3ThjOO4eEIBgF+Bo=; b=RmUftmG+MO7ox2wL/7KbVpxZsON0bsP4xr7q9//tLTDgxs4WlqdiJPxJSLYsRcgRRY eVKCTuCxLaGfeLipM2VGLjvmDrX2gtmzHN52Z8Pzc/YQy+tyRZYT4YagIOrx4qOSD6Cl 31egWjPgN1AMjNuJKqM3LpLZG0m+mJxN2f1Onp5NwF2mRvlrLTYPe0RqI5ku3uwOo6Xp Pt7BY4FMtBdNfUx8S/2dgfITAHbNHLbgYfuzkEOmo/RJh7WQSAjjpsKM9TWG05vH/pkC LAvpEcTuEjyg1pcLnDzdR1CAJjcgyDqNF38m45xaItDEccdxx6qr9H3Aj57iSKBnpEU1 1pTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=egLJMAf6; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id u1sor16537572pgu.60.2020.02.25.09.53.50 for (Google Transport Security); Tue, 25 Feb 2020 09:53:50 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=egLJMAf6; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qTnHuEFnXMMcLEn+/gKdeCOo8JW3ThjOO4eEIBgF+Bo=; b=egLJMAf6s7yzY8fc5m2fjxU1pVNXST4lwptfKw803AsiPdoABJwat6lH3hP5/VRZiO vDMBDhCOquTGdhPOr8VFP1ywBWbxm7pN1A7vyCA1wVZRVL6Kc0Wo7grIKL6akYhunqwR 8ahj+nY0mQF3UA67NoNRje1RNJ9/wGuq/A1CYbPZQseR3jGtkT4Qh9YJJQhcxgZRJd+T hrsUWavoqzcuF1eKlVehbtGzOZXqBeoDdCdkjCuxMbJSoEesDo0aBZoAiByjnOHSSJfp gatbN5FJUFVJSRa94iYvwf/hLr3W8KQY76nK6ugW5TSUAORLWdOFsDZD19SjuuhvOizH Lu7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qTnHuEFnXMMcLEn+/gKdeCOo8JW3ThjOO4eEIBgF+Bo=; b=mxfIBLT6FLisVCgLEQrwKRzrUATFszy4MRFh77oHvBJ2T6C6k9iIZVQxpoH6Lv1TU+ Bbian+VlWDyNfsdJzSjWsLeljFTRN0bUKzxc3NJxE/UngpOzuhJecuDnBRXufd54BFsv vcHEdONsAzvnoe005JeOIbyCd3eJNqVmf4ybLDzUPXQdHgfZRm0Q6tZ5IKjIjq3ETwW8 dzTWR/xxGJPO9A/eVIX9S/yEED7RKlYUE6XrjOBg2J3QQoc+O5KVSdMnqeTiPfOdz+1A PqvoKuhMeuDKFqwFT884eT0CzYs4YEqIBsNvrl146m/uD5l7UW/j0fS9vEAAfCtpp/ud YrVg== X-Gm-Message-State: APjAAAULZX4uPXseWLEIh9SnceYJSJh9NLScL/vP/G9d451aFmNB/kVV TZ9Zh+7xwLnGmCmk+oHNwCEbd3d4 X-Google-Smtp-Source: APXvYqzLkUdjAvPjt/6k7JvP/BEHrBZbEVZr551JrnO8oAHXm+AKYuFXsIjYgQpnNh5bLVB1gczxzQ== X-Received: by 2002:a63:7152:: with SMTP id b18mr59879884pgn.232.1582653230278; Tue, 25 Feb 2020 09:53:50 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id v8sm18013291pgt.52.2020.02.25.09.53.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 09:53:49 -0800 (PST) From: John Stultz To: lkml Cc: John Stultz , 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 , Guillaume Gardet , Bryan O'Donoghue , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v8 3/6] usb: dwc3: Add support for role-switch-default-mode binding Date: Tue, 25 Feb 2020 17:53:01 +0000 Message-Id: <20200225175304.36406-4-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200225175304.36406-1-john.stultz@linaro.org> References: <20200225175304.36406-1-john.stultz@linaro.org> 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: Guillaume Gardet Cc: Bryan O'Donoghue Cc: Jack Pham Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Tested-by: Bryan O'Donoghue Signed-off-by: John Stultz --- 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(-) -- 2.17.1 diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index a99e57636172..57d549a1ad0b 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -955,6 +955,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 @@ -1089,6 +1091,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 331c6e997f0c..db68d48c2267 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 From patchwork Tue Feb 25 17:53:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 183872 Delivered-To: patches@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp2041477ile; Tue, 25 Feb 2020 09:53:58 -0800 (PST) X-Received: by 2002:a17:902:b612:: with SMTP id b18mr53163493pls.318.1582653238021; Tue, 25 Feb 2020 09:53:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582653238; cv=none; d=google.com; s=arc-20160816; b=FzdsRc+wKAMSRGKBHgd9BPRDOC6gWuMf9RlFEoW+UqKjuEfjcxjzDNRfR1zEJHW5dQ +fsFuS28Ioa72KvGIUnCFRHoYxwmskhabTkcNR7ueOkG1Dkk26sIhkhDM2a9tegMPUNf g3jmRdTN5AOj+8JYSgiz9JLL45eOFS6tlAB1XpKwEhlLgdXIJ0ennKY/t2Kh1w38CFEz +7GD8RB8hTuJJx6wKCRQ+KN0WlvLYan5pN+Zuj9uMOqj6dw/8dRDONio75Pt1RtexpqN v/8NR1/i2etbUxUnk0xD2pkuDHfSti/ZUyUy5ftu2tmAW7m/4wuwt0fZrUm2mNhxbTW1 Wbng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jz3XZ9gPuD/g+1P6LY7Aq8wTOFKwQIrTyqi7Mx3AGIU=; b=KJ9zeR6yDpzo10xtWhTJSkkK2OPfyPGJCxwnt3Ye4PAg+W95T+H7kpFizlzXu4ICLs 4OBkch6ZCZU7N0/AAiU8HpRsUCJtMZj5hxQuqSZ/wBDKgEOOYreO4ZMlZit/OeSZUoJV tCWNM7+z3A3FKuo9Pkd7bxEaj6ZHL0g2RwdxNhJzB85JA5MZhHWX9R8/XJmHtH943Q8b mG3JdKpvBMUjOb334IFsUyL/pK8E6jooeci9LrFkDCTlGHLOUXE900KWnXrqJzbSi3TA SrY3Wb9sevYWxAEcDiUkcIlBU8BduNzk86egKupr6uScScpGrTrQsLJ5yasoJi/bjeb5 2sHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lwkPosxw; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id jx16sor123856pjb.7.2020.02.25.09.53.57 for (Google Transport Security); Tue, 25 Feb 2020 09:53:58 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lwkPosxw; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jz3XZ9gPuD/g+1P6LY7Aq8wTOFKwQIrTyqi7Mx3AGIU=; b=lwkPosxwVHqNL5aijGc3VaCBSOXdBybtaEjZmFJj4LRQBc1cqJt17DPUHecWz7PfVI hrJucelVYpu3RNZKaaJtVsLaapcJgfF2RefqH7NetZv296lTcKDVuY2vWXMxsbzPIc/p FLwAkCyBx7W5nD2LDHW1DhzMp0RsUJtGxuTXQHgSw3r4hINvWge1vrAKod17Xc2+yrtQ pgKL8VpdpBgS8CGcvqEesteDbeyt5fqBJfyuKV9ZSlofhecFeoO98snsQ7JLh7m/WGTN xWO5PssZiu5agAlIKGQ98OUFjxR8qLWrq4dWCDWECc2NR6WxB1OhpBTR3DZT5T78QEJb ux7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jz3XZ9gPuD/g+1P6LY7Aq8wTOFKwQIrTyqi7Mx3AGIU=; b=mZNiLuhScYzVB4sXXkAgP/kM/LGOU6CugX0L/sS1JYzjzDxxa+H4XPifXOFVfuR7J4 hMfMVkRU1BqDfkoZ0YkSpo/nm8z35xiwi8eBiXSkNRLwjzx9QfUpN9+SDSGMT2INNLnS yKkRyDU7QOeKbVnHImO/Ay7LbvYEj0DMEKLaROrOUKrXdlKdveSYzBrDmCCMZPR88Uig e88KpWWa6vcYUk+cIu2diDCq34C5t//SrJIBL/XPj0cgpqpuxffPW7Nn8SJoI13Xdv4C wQg3+VkFo2wi7kiNyxfJaWYSp2whpm80Xj85JjPVcpf3ADwqJvvl4AJ1oEaPtNgLyrL5 PdsA== X-Gm-Message-State: APjAAAW8in0K2Zs37mKyzIOr7nkgVsTSYYJEu5PRxy0DYWX9EGzpacd6 mPy2CIG2HFe6eeEXTHuDUTPtP+j1 X-Google-Smtp-Source: APXvYqx9tINDep9zfUWEUUEMxu2YZzjpfKET0phziXq5UW9ojBW7/2GMgqVX/Yt4bAQq8H6W+ZvGFw== X-Received: by 2002:a17:90a:ff15:: with SMTP id ce21mr155938pjb.124.1582653237674; Tue, 25 Feb 2020 09:53:57 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id v8sm18013291pgt.52.2020.02.25.09.53.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 09:53:57 -0800 (PST) From: John Stultz To: lkml Cc: John Stultz , 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 , Guillaume Gardet , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v8 4/6] dt-bindings: usb: dwc3: Allow clock list & resets to be more flexible Date: Tue, 25 Feb 2020 17:53:02 +0000 Message-Id: <20200225175304.36406-5-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200225175304.36406-1-john.stultz@linaro.org> References: <20200225175304.36406-1-john.stultz@linaro.org> Rather then adding another device specific binding to support hikey960, Rob Herring suggested we expand the current dwc3 binding to allow for variable numbers of clocks and resets. 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: Guillaume Gardet Cc: Jack Pham Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Suggested-by: Rob Herring Reviewed-by: Rob Herring Signed-off-by: John Stultz --- Documentation/devicetree/bindings/usb/dwc3.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/Documentation/devicetree/bindings/usb/dwc3.txt b/Documentation/devicetree/bindings/usb/dwc3.txt index 66780a47ad85..29768b0ca923 100644 --- a/Documentation/devicetree/bindings/usb/dwc3.txt +++ b/Documentation/devicetree/bindings/usb/dwc3.txt @@ -7,7 +7,8 @@ Required properties: - compatible: must be "snps,dwc3" - reg : Address and length of the register set for the device - interrupts: Interrupts used by the dwc3 controller. - - clock-names: should contain "ref", "bus_early", "suspend" + - clock-names: list of clock names. Ideally should be "ref", + "bus_early", "suspend" but may be less or more. - clocks: list of phandle and clock specifier pairs corresponding to entries in the clock-names property. @@ -36,7 +37,7 @@ Optional properties: - phys: from the *Generic PHY* bindings - phy-names: from the *Generic PHY* bindings; supported names are "usb2-phy" or "usb3-phy". - - resets: a single pair of phandle and reset specifier + - resets: set of phandle and reset specifier pairs - snps,usb2-lpm-disable: indicate if we don't want to enable USB2 HW LPM - snps,usb3_lpm_capable: determines if platform is USB3 LPM capable - snps,dis-start-transfer-quirk: when set, disable isoc START TRANSFER command From patchwork Tue Feb 25 17:53:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 183873 Delivered-To: patches@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp2041605ile; Tue, 25 Feb 2020 09:54:05 -0800 (PST) X-Received: by 2002:a63:ed14:: with SMTP id d20mr58324018pgi.267.1582653245063; Tue, 25 Feb 2020 09:54:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582653245; cv=none; d=google.com; s=arc-20160816; b=Um7zbKBP2r1DjGL6xsEW772ow2ZY9z+rv/XGKcJkA8I6qpJiDGWgKXtPn+qnV2KLNR 7U2OidAk43dhjFjnhxGFGASdBXpC2Y9P9Wytfu83PAdVWple5nyt1K3MjYxU8W9WktP9 cwZdqFtcqHSnBf0ZBFVwUEzyIZRmf4pdOidfv6aqNljFo+DWOSLM37C48aSdwz3rqzFJ zkoLc9nGGiwXZ8OSwzBH5Dt6PyuF5oWRpf6RzKBicCpwboW9+ZzOcSfP4V1I+nlz+R/o 79XHQCKQDhLTgxJCIbJEET83Usm4TgPbOfA1qiwpPeJ6ip0evaeBFE2ciCacYrcLf59Q NpCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CpmywWyp6aExqYXO2nsoyNHZG6T/FiFmGDy6H1VmZYo=; b=yeetVMMPRlWSDaoFGX0k2pQ5n3PWn5u0qvgvsRzjO133JwzGHq8kUwZNhYhVhOt2A3 z0FqbuwWSWcOWjI6Qpq8UZhRW9Q7GCCBZawd/2EHIFj4BZtmcKL/Zxj4IeN8tS6mCxIc kENhE269lX57h4F1Ok1xcEQ/V/cfhxQmCrIfQ5fxoxkfNAteFTHOFQOlccU2ucRaKN69 NIJSROOYFxrHI8/cSY9oEiwCZWqksOm5WST+diZ9azmmXbb4RNIGRQSNi81wx2SxduJH sH4M4ZqKSIB+blnRn0AvzvUsAJkOtAAqZn1DlC0sJbUbSNqgcdySdV/Pt1/u51ZtNP4P 6YjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ASuZESBs; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id l129sor2277544pgl.67.2020.02.25.09.54.04 for (Google Transport Security); Tue, 25 Feb 2020 09:54:05 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ASuZESBs; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CpmywWyp6aExqYXO2nsoyNHZG6T/FiFmGDy6H1VmZYo=; b=ASuZESBsToschmHjBbgEc3jfR3shNL1vpcT7qJeCfsurb2NjTft4SutlPuhnOOJwpv w0YXal/pHV67j2wlcIfNz8ABT7AzFinBpm71SU6eHSOmUaw2rOn4Oele9Nx4ekt5GQ+P VwPPurcKjc99Z1vChtyxA5w2NbZkayU8asApDjoLX416t0GGg3AR6Teub6jG0AjwsXxP lsGccjBqajtNtNTqwyuVBO0mLXkidobN/csXNNDzhYC9LxjFana27NKfoAGwFKPzOsb0 66/ycCvpXGQ26/Ou5JNA41pfnmjA3kQnBbJ/QqDVvP8xBOPFiUS/jF5tm3IL6bD0RgPc G1Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=CpmywWyp6aExqYXO2nsoyNHZG6T/FiFmGDy6H1VmZYo=; b=s8uhhyPTjb7QfwiSzJGscwVzEsXkqo0mSjrahNz2b9vL2RknIgpUb67zt7t3O/NM0B bsJjDU71tMHT/x6moxekM0PJnfRuQi9e0ls3JcPMhB7Mf7x7g5rG6efFd6cQIlr0Bhn3 sKKO18gztCS3xuUXR9+eV0hxiXh+kr5fkuykZxtECLgPeWdKbDmAlZihKaaoiYn+b1PL I1GtSIPfJHk2FJnSaDMA4AtukapgdqsXT5cb4mALTmwXD+NC77HD5FA1AKLvSje44ptb BMVmMuOGjKRPl4mmOFstgEbUOz1Ykxu+9KUFn2CfcA1yma6jxbOIOpj/FED1s2yJMqXU W77w== X-Gm-Message-State: APjAAAU1VARK+rpgmAYRJl/BVM/tY96Trfnp2/p8aGESibmafme6KTtL yAbfv+BqFcKo7wA2ml57YwaInST3 X-Google-Smtp-Source: APXvYqwpHKqD+EUq28KEJF7IXzIP1hpR7FRD9XctnUIftrS+HfPh4WaCyCgkjKFUI/d1YZOsWn0oKA== X-Received: by 2002:a63:7e1a:: with SMTP id z26mr5483897pgc.226.1582653244705; Tue, 25 Feb 2020 09:54:04 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id v8sm18013291pgt.52.2020.02.25.09.53.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 09:54:04 -0800 (PST) From: John Stultz To: lkml Cc: John Stultz , 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 , Guillaume Gardet , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v8 5/6] usb: dwc3: Rework clock initialization to be more flexible Date: Tue, 25 Feb 2020 17:53:03 +0000 Message-Id: <20200225175304.36406-6-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200225175304.36406-1-john.stultz@linaro.org> References: <20200225175304.36406-1-john.stultz@linaro.org> The dwc3 core binding specifies three clocks: ref, bus_early, and suspend which are all controlled in the driver together. However some variants of the hardware my not have all three clks, or some may have more. Usually this was handled by using the dwc3-of-simple glue driver, but that resulted in a proliferation of bindings for for every variant, when the only difference was the clocks and resets lists. So this patch reworks the reading of the clks from the dts to use devm_clk_bulk_get_all() will will fetch all the clocks specified in the dts together. This patch was recommended by Rob Herring as an alternative to creating multiple bindings for each variant of hardware. 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: Guillaume Gardet Cc: Jack Pham Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Suggested-by: Rob Herring Signed-off-by: John Stultz --- v3: Rework dwc3 core rather then adding another dwc-of-simple binding. v6: Re-introduce this patch, on Rob's suggestion --- drivers/usb/dwc3/core.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) -- 2.17.1 diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 1d85c42b9c67..ba21af5c1204 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -289,12 +289,6 @@ static int dwc3_core_soft_reset(struct dwc3 *dwc) return 0; } -static const struct clk_bulk_data dwc3_core_clks[] = { - { .id = "ref" }, - { .id = "bus_early" }, - { .id = "suspend" }, -}; - /* * dwc3_frame_length_adjustment - Adjusts frame length if required * @dwc3: Pointer to our controller context structure @@ -1441,11 +1435,6 @@ static int dwc3_probe(struct platform_device *pdev) if (!dwc) return -ENOMEM; - dwc->clks = devm_kmemdup(dev, dwc3_core_clks, sizeof(dwc3_core_clks), - GFP_KERNEL); - if (!dwc->clks) - return -ENOMEM; - dwc->dev = dev; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -1481,17 +1470,18 @@ static int dwc3_probe(struct platform_device *pdev) return PTR_ERR(dwc->reset); if (dev->of_node) { - dwc->num_clks = ARRAY_SIZE(dwc3_core_clks); - - ret = devm_clk_bulk_get(dev, dwc->num_clks, dwc->clks); + ret = devm_clk_bulk_get_all(dev, &dwc->clks); if (ret == -EPROBE_DEFER) return ret; /* * Clocks are optional, but new DT platforms should support all * clocks as required by the DT-binding. */ - if (ret) + if (ret < 0) dwc->num_clks = 0; + else + dwc->num_clks = ret; + } ret = reset_control_deassert(dwc->reset); From patchwork Tue Feb 25 17:53:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 183874 Delivered-To: patches@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp2041659ile; Tue, 25 Feb 2020 09:54:08 -0800 (PST) X-Received: by 2002:a63:c846:: with SMTP id l6mr58724816pgi.144.1582653248727; Tue, 25 Feb 2020 09:54:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582653248; cv=none; d=google.com; s=arc-20160816; b=ImSZnYHpIm2z472S8GR8QcBxj0ViOtMvk8PYoISyfuiid1nV9XNmgi2sOOXiuUuosT vsWPsqqxGxDCR0AkpbqiQZl0bg9DfcuQxvo7Hc6kNZ5WKUrmwNE5tCzOT9CtmZyhwfw/ i8JA9MfZs8bOxEIhl7ICjWvHBAkUeu+eV9hGhSkqMlrYh9UgRO0hU6NS34vWWu3UtD/B a+iZnMj2yF9XH7QTwDMvdr/BPdeHLRD+gc0RZ3XRJ1+IJ9GTQvg2WyO393hQWCnAPS5Q buvAkbpkmLM0aBKQG4/ewhkkrfu/IR2+X20RTEK3KQrRvbXVdMB9ZSCiIoqoTZoB2Me9 W0IQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EGHWPlxApQjuktMa4xDP9Q063H+hJfu1b6AJ+NVENyk=; b=vjSelN2pgczFdhHexhb7icOiI9o70faemQhNyudDdHnMAUjPsxwPfQNymTK67HBn1M bB2GjWO58hvxXP3bVZCoCVpDHc334KXSam4ygEf4fKa3sRC4cN9Sm7SqCEuj9dJV6oqm X1R0PFB6fwIhN/TUOLbe071DIJQfViWWJUzFlEYRC/l6xUL+1LK/J69YgDy9QnZhdaWd DzVSlYEVgZDpuDwD/fA9BBF+0PDDh4rEGPTwOyxgsADEJ+IGZzVHvkjIznVmot9Rl4nj FIGjCuSv4zXED3nm88OxmdPpwL25Tqh7kdPj1PA9ZZA1ZfBeGYbT9SWHcMYpdeWVdIyA VLyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mopFLxsW; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id i11sor18340551pgh.78.2020.02.25.09.54.08 for (Google Transport Security); Tue, 25 Feb 2020 09:54:08 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mopFLxsW; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=EGHWPlxApQjuktMa4xDP9Q063H+hJfu1b6AJ+NVENyk=; b=mopFLxsWbeU0/yL28BByX3Qmrqu4/lNA+fcgdrQ0c38OZPHrInJHNTj2WYC/ILCWI3 rXsIHYNPOo1xWFMGo7b/0CEJyDfVXjQ/OF3IJs1bd8q8HuaPPs18JlBn3fRBNx7jqN5f fC8vxPOg23B/AWvtJ+Qf4eNAws51cK2BgiyA2EA5uI5P3NgCw0Wv9hQUdeTRc3PUrZ0V hRk0YjbtV5tCBvV82AvEH/9gQey8wstJTVxNI3gzLRzj7PSSlwWMWxLKk9pa39J5/c6r JpjLoP7WYSaFE7JvzH24FqeckT308GZ6KURzKIQEE9oy3BJrKRDDhYmWeLqZFBVK+T/2 mbng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=EGHWPlxApQjuktMa4xDP9Q063H+hJfu1b6AJ+NVENyk=; b=FYb2IVQWxs2/sWnH8N0MsavC71qSu7QPAmGEnM2TceSnkVgnEuW8W9tA9qsRlzCENe dxDqC+YTzwQis/MCTw4BFebV9kKIeCtKJDPhIkXO63yiVXfuWVwyhHVEiv93K56Bt9OR JaXHya8SQjfsP/AIOfQ/IXqLI0cr+BbxUUsmyVu0TzSjM0/9gmVE+5cG44pzFk/0XSRY ZM3U444XHtgzPQtC0gGtpMkM6/gP+FwEGRihApBmmmKPv8zihSHPQ0Nraxl5ZVirVMtM w2lMCO7tiuOIoeVV1V27AQFMxilEYOaAYpAH1kQAEXLcKFE2m4f+4YhnkmotyYNs5wRB faRQ== X-Gm-Message-State: APjAAAUv9RIYCv+v8p74KMV8sR13992uJEkiyjCRY9mWMtBm8FlLzbBb N+k6/Vswrd0h3d5wi/lafY9BByGd X-Google-Smtp-Source: APXvYqzHMYAmH1VGS/4L4IKuT3hh7pV1x1nh2bDeq23It8zTwLG0Ky2zYk/YSXEkpzQl6uUTVp43bQ== X-Received: by 2002:a63:2b0a:: with SMTP id r10mr12434661pgr.213.1582653248359; Tue, 25 Feb 2020 09:54:08 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id v8sm18013291pgt.52.2020.02.25.09.54.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 09:54:07 -0800 (PST) From: John Stultz To: lkml Cc: John Stultz , 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 , Guillaume Gardet , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v8 6/6] usb: dwc3: Rework resets initialization to be more flexible Date: Tue, 25 Feb 2020 17:53:04 +0000 Message-Id: <20200225175304.36406-7-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200225175304.36406-1-john.stultz@linaro.org> References: <20200225175304.36406-1-john.stultz@linaro.org> The dwc3 core binding specifies one reset. However some variants of the hardware may have more. Previously this was handled by using the dwc3-of-simple glue driver, but that resulted in a proliferation of bindings for for every variant, when the only difference was the clocks and resets lists. So this patch reworks the reading of the resets to fetch all the resets specified in the dts together. This patch was recommended by Rob Herring as an alternative to creating multiple bindings for each variant of hardware. 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: Guillaume Gardet Cc: Jack Pham Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Suggested-by: Rob Herring Signed-off-by: John Stultz --- v3: Rework dwc3 core rather then adding another dwc-of-simple binding. v6: Re-introduce this patch, on Rob's suggestion --- drivers/usb/dwc3/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.17.1 diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index ba21af5c1204..2afcc04da338 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -1465,7 +1465,7 @@ static int dwc3_probe(struct platform_device *pdev) dwc3_get_properties(dwc); - dwc->reset = devm_reset_control_get_optional_shared(dev, NULL); + dwc->reset = devm_reset_control_array_get(dev, true, true); if (IS_ERR(dwc->reset)) return PTR_ERR(dwc->reset);