From patchwork Mon Feb 10 12:07:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 11373095 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 53272109A for ; Mon, 10 Feb 2020 12:07:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 29F872082F for ; Mon, 10 Feb 2020 12:07:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="DstRwno7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727740AbgBJMHi (ORCPT ); Mon, 10 Feb 2020 07:07:38 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:39912 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727696AbgBJMHg (ORCPT ); Mon, 10 Feb 2020 07:07:36 -0500 Received: by mail-wm1-f65.google.com with SMTP id c84so10297175wme.4 for ; Mon, 10 Feb 2020 04:07:35 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=4vOm1LXNJhnwimlbtOdMQ8AqBayT1JjO4KI+XVXsMbQ=; b=DstRwno7OIow9npa/S6cUSzmuRfag4D5sbzBWRr52oJU4qzkmEylrcVxUUbm8kK0yW cIQG3YFigAvPSWuUkgu5yMp47LlCCcaCXgDeVlEPBdX4mG2l3vlJCB6sSr9Vln1yHjKI +ETx6MLn5ci64wesmMAqCNWq4Okn2gCEZrqOYT90OrtybWcKPkhO/4rb02Wxo/u6ItzJ 4FQbU7D075RVk9BqHoyuait4YVPRoySsCF2JWzHhTqpVBbeBG/mOhGaIojhLxkYWgUGo ndb0BGy0PleRFd01kG/+peRtgFY7sNn8JGkpBDZZ2vmsJqS0LOguw5VTJXmJWkYfPm3N BZKg== 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:mime-version:content-transfer-encoding; bh=4vOm1LXNJhnwimlbtOdMQ8AqBayT1JjO4KI+XVXsMbQ=; b=jgRIevhWNtX2pKldDhdmKMy1QYGCmWBvPbd8F8M+Luff2qYKezoXv6Zj//ay1Yo8Ur JnrjZ3mR7op3jdrzC0SbkY/5Xtd2sHm5+jtVkKdx1BfkA8U2SCKHNCCsAjYTgaBA3vZL 8ZZt8zmOYbp4rtFq8MrK67V2jozXevU3CmhkJ3N0bEEfZsLmw+3UwKTb0fyztXdIaZIT U8z7sRU2PsvWXapGK+y5UNh91JVdlUc5ifoo7IFeOBCQAK2sBASYHCWYnrwsZXrNdxqb nsB9QpJusgB0Cp/b6LjWITXtGYTFe6TSY+xW9LoAVmAwugEtEnXGxsG0PQvPsI7vCPT4 S5Bw== X-Gm-Message-State: APjAAAV2S8fB8ixCfkp9DKt/OfKO4M/OtAk7TmgbLSWqw82QvZJmeiK/ 6ExgS66jkETEQjtIfAxZwEzyiA== X-Google-Smtp-Source: APXvYqxVz2NduFqOu6Xoek9DmJXj5G4kqgPzif1jy60dxYAHvwA5tzhcO1ime/S130QX1FfCZICn8g== X-Received: by 2002:a05:600c:21c5:: with SMTP id x5mr15575520wmj.72.1581336454143; Mon, 10 Feb 2020 04:07:34 -0800 (PST) Received: from localhost.localdomain ([176.61.57.127]) by smtp.gmail.com with ESMTPSA id i204sm293124wma.44.2020.02.10.04.07.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2020 04:07:33 -0800 (PST) From: Bryan O'Donoghue To: linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org, gregkh@linuxfoundation.org, jackp@codeaurora.org, balbi@kernel.org, bjorn.andersson@linaro.org, robh@kernel.org Cc: linux-kernel@vger.kernel.org, Bryan O'Donoghue , Andy Gross , Lee Jones , Philipp Zabel Subject: [PATCH v6 11/18] usb: dwc3: Add support for a role-switch notifier Date: Mon, 10 Feb 2020 12:07:16 +0000 Message-Id: <20200210120723.91794-12-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200210120723.91794-1-bryan.odonoghue@linaro.org> References: <20200210120723.91794-1-bryan.odonoghue@linaro.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Role-switching is a 1:1 mapping between a producer and a consumer. For DWC3 we have some vendor specific wrappers, notably the qcom wrapper that want to toggle some PHY related bits on a USB role switch. This patch adds a role-switch notifier to the dwc3 drd code. When the USB role-switch set() routine runs, the notifier will fire passing the notified mode to the consumer, thus allowing vendor specific fix-ups to toggle from the role-switching events. Cc: Andy Gross Cc: Bjorn Andersson Cc: Lee Jones Cc: Felipe Balbi Cc: Greg Kroah-Hartman Cc: Philipp Zabel Cc: Jack Pham Cc: linux-arm-msm@vger.kernel.org Cc: linux-usb@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Jack Pham Signed-off-by: Bryan O'Donoghue --- drivers/usb/dwc3/core.h | 19 +++++++++++++++++++ drivers/usb/dwc3/drd.c | 17 +++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index a99e57636172..c2e85f587674 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -955,6 +955,7 @@ struct dwc3_scratchpad_array { * - USBPHY_INTERFACE_MODE_UTMI * - USBPHY_INTERFACE_MODE_UTMIW * @role_sw: usb_role_switch handle + * @role_sw_nl: role switch notifier list * @usb2_phy: pointer to USB2 PHY * @usb3_phy: pointer to USB3 PHY * @usb2_generic_phy: pointer to USB2 PHY @@ -1089,6 +1090,7 @@ struct dwc3 { struct notifier_block edev_nb; enum usb_phy_interface hsphy_mode; struct usb_role_switch *role_sw; + struct raw_notifier_head role_sw_nl; u32 fladj; u32 irq_gadget; @@ -1499,4 +1501,21 @@ static inline void dwc3_ulpi_exit(struct dwc3 *dwc) { } #endif +#if IS_ENABLED(CONFIG_USB_ROLE_SWITCH) +int dwc3_role_switch_notifier_register(struct dwc3 *dwc, + struct notifier_block *nb); +int dwc3_role_switch_notifier_unregister(struct dwc3 *dwc, + struct notifier_block *nb); +#else +static inline int +dwc3_role_switch_notifier_register(struct dwc3 *dwc, + struct notifier_block *nb) +{ return 0; } + +static inline int +dwc3_role_switch_notifier_unregister(struct dwc3 *dwc, + struct notifier_block *nb) +{ return 0; } +#endif + #endif /* __DRIVERS_USB_DWC3_CORE_H */ diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c index c1825fd655f6..8d3f1599d422 100644 --- a/drivers/usb/dwc3/drd.c +++ b/drivers/usb/dwc3/drd.c @@ -496,6 +496,8 @@ static int dwc3_usb_role_switch_set(struct device *dev, enum usb_role role) } dwc3_set_mode(dwc, mode); + raw_notifier_call_chain(&dwc->role_sw_nl, mode, NULL); + return 0; } @@ -558,6 +560,18 @@ static int dwc3_register_gpio_usb_connector(struct dwc3 *dwc) return ret; } +int dwc3_role_switch_notifier_register(struct dwc3 *dwc, + struct notifier_block *nb) +{ + return raw_notifier_chain_register(&dwc->role_sw_nl, nb); +} + +int dwc3_role_switch_notifier_unregister(struct dwc3 *dwc, + struct notifier_block *nb) +{ + return raw_notifier_chain_unregister(&dwc->role_sw_nl, nb); +} + #else #define dwc3_setup_role_switch(x) 0 #define dwc3_register_gpio_usb_connector(x) 0 @@ -579,6 +593,9 @@ int dwc3_drd_init(struct dwc3 *dwc) ret = dwc3_register_gpio_usb_connector(dwc); if (ret < 0) return ret; + + RAW_INIT_NOTIFIER_HEAD(&dwc->role_sw_nl); + } else if (dwc->edev) { dwc->edev_nb.notifier_call = dwc3_drd_notifier; ret = extcon_register_notifier(dwc->edev, EXTCON_USB_HOST,