From patchwork Wed Jul 12 08:22:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souradeep Chowdhury X-Patchwork-Id: 13309789 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3F00DEB64DD for ; Wed, 12 Jul 2023 08:23:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=lG61Af+aa0u33uOZcaJno496xCwqin/mwqJ5Qk49WQQ=; b=Jeqj2guJoLc68V VoZmrUbYLOJMxbsBwEmepC+/rcwUVEDnAXkOLeEhE9gmiEVAA1+aw5IFq7wXjZCSsmhpAPawImy6h nEwu/tmAJGdcMT9PLU/2S74US+XJgSui8EVHEGb+NH6zhh1pU7YU4A76I3OZtsfDvPCQfVftLtA0e RJ5wVZnY0Qo82nWTE60DbRs/TFoAvT4kdJDH2p3G0VidFo0ObD6ouUd8xrNYQZKz2GX0rCn+mL5W2 5IIQqA4Dh2cV5R0zggysQyR0puu5lH/utsWHD2YkLr/j6bHrkgGkCyNWFxPYCTOFY9Mc9QcA9TQWU pBz7x9JjLaDhrnlb4xyw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qJV7z-00Gtlm-1n; Wed, 12 Jul 2023 08:23:15 +0000 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qJV7v-00Gtkf-2o for linux-arm-kernel@lists.infradead.org; Wed, 12 Jul 2023 08:23:13 +0000 Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36C3mOZR032181; Wed, 12 Jul 2023 08:23:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=qcppdkim1; bh=40o+X8oKsX81WIYXOnfFG7rcPkNuQsSlDf08s1f+OFU=; b=lbf3kT8WLHSNf58d+2fYPsgT/rfIM4BtAjGJ57ivrWQTbA9emg/XLa4X1BnEpQEge76+ YaaXlhf8J/eXsLXPJIlek2vuJRlUoyuHC0HnOu1twbU1yjzNuIKkEvNaj3BYFyBK6mLc 2Y2nXnTDCcIMnrfc+eCR/eQmd7uCu++vvOCiMDae4DdQFGXslUReGzo+NCt7IIZtZliX OuwuBK8gnpuZIM3YsPEg5eE3lcXyWm73RbNgTM99gUHUv/lIW9X7AJsuUT/5PNcTRpb2 /RCIxN7/1JzdJLwiWKxqvEIdOeTb4VoZsnJcDcuouaJc6STs9fVTOZi4xGD7+MWO+N9N Rw== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3rsgd38tv4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 12 Jul 2023 08:23:08 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 36C8N7mo031890 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 12 Jul 2023 08:23:07 GMT Received: from hu-schowdhu-blr.qualcomm.com (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.30; Wed, 12 Jul 2023 01:23:03 -0700 From: Souradeep Chowdhury To: , , Andy Gross , Konrad Dybcio , "Bjorn Andersson" , CC: , , Sibi Sankar , Rajendra Nayak , Souradeep Chowdhury Subject: [PATCH V1 2/3] usb: misc: Add notifier call chain to Embedded USB Debug(EUD) driver Date: Wed, 12 Jul 2023 13:52:39 +0530 Message-ID: <18212c7abbb8c833cc07f8500d4905b79c49ec59.1689148711.git.quic_schowdhu@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: SXiq8Dlvs04sZERfyLzjmvM9owT8ZG2m X-Proofpoint-GUID: SXiq8Dlvs04sZERfyLzjmvM9owT8ZG2m X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-12_04,2023-07-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 clxscore=1015 adultscore=0 mlxlogscore=955 priorityscore=1501 impostorscore=0 bulkscore=0 phishscore=0 malwarescore=0 mlxscore=0 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2307120073 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230712_012311_923216_B4882E61 X-CRM114-Status: GOOD ( 26.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add the notifier call chain to EUD driver. The notifier call chain is added to check the role-switch status of EUD. When multiple modules are switching roles on the same port, they need to call this notifier to check the role-switch status of EUD. If EUD is disabled, then the modules can go for the role-switch, otherwise it needs to be blocked. The notifier chain can be used to link multiple modules switching roles on the same port and create a ordering, priority and conflict resolution among them. The wrapper functions are defined here which can be used to register a notifier block to the chain, deregister it and also call the chain. Signed-off-by: Souradeep Chowdhury --- drivers/usb/misc/qcom_eud.c | 52 +++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/drivers/usb/misc/qcom_eud.c b/drivers/usb/misc/qcom_eud.c index 7f371ea1248c..e6c97a2cf2df 100644 --- a/drivers/usb/misc/qcom_eud.c +++ b/drivers/usb/misc/qcom_eud.c @@ -11,10 +11,13 @@ #include #include #include +#include +#include #include #include #include #include +#include "qcom_eud_notifier.h" #define EUD_REG_INT1_EN_MASK 0x0024 #define EUD_REG_INT_STATUS_1 0x0044 @@ -22,14 +25,16 @@ #define EUD_REG_VBUS_INT_CLR 0x0080 #define EUD_REG_CSR_EUD_EN 0x1014 #define EUD_REG_SW_ATTACH_DET 0x1018 -#define EUD_REG_EUD_EN2 0x0000 +#define EUD_REG_EUD_EN2 0x0000 #define EUD_ENABLE BIT(0) -#define EUD_INT_PET_EUD BIT(0) +#define EUD_INT_PET_EUD BIT(0) #define EUD_INT_VBUS BIT(2) #define EUD_INT_SAFE_MODE BIT(4) #define EUD_INT_ALL (EUD_INT_VBUS | EUD_INT_SAFE_MODE) +static RAW_NOTIFIER_HEAD(eud_nh); + struct eud_chip { struct device *dev; struct usb_role_switch *role_sw; @@ -41,6 +46,42 @@ struct eud_chip { bool usb_attached; }; +int eud_register_notify(struct notifier_block *nb) +{ + return raw_notifier_chain_register(&eud_nh, nb); +} +EXPORT_SYMBOL_GPL(eud_register_notify); + +void eud_unregister_notify(struct notifier_block *nb) +{ + raw_notifier_chain_unregister(&eud_nh, nb); +} +EXPORT_SYMBOL_GPL(eud_unregister_notify); + +void eud_notifier_call_chain(unsigned long role_switch_state) +{ + raw_notifier_call_chain(&eud_nh, role_switch_state, NULL); +} +EXPORT_SYMBOL_GPL(eud_notifier_call_chain); + +static int eud_vbus_spoof_attach_detach(struct notifier_block *nb, unsigned long event, + void *data) +{ + struct device_node *eud = of_find_compatible_node(NULL, NULL, "qcom,eud"); + struct device *eud_device = bus_find_device_by_of_node(&platform_bus_type, eud); + struct eud_chip *eud_data = dev_get_drvdata(eud_device); + + if (eud_data->enabled && event != USB_ROLE_DEVICE) + return NOTIFY_BAD; + else + return NOTIFY_OK; +} + +static struct notifier_block eud_notifier = { + .notifier_call = eud_vbus_spoof_attach_detach, + .priority = 1, +}; + static int enable_eud(struct eud_chip *priv) { writel(EUD_ENABLE, priv->base + EUD_REG_CSR_EUD_EN); @@ -196,6 +237,10 @@ static int eud_probe(struct platform_device *pdev) return dev_err_probe(chip->dev, ret, "failed to add role switch release action\n"); + ret = eud_register_notify(&eud_notifier); + if (ret) + return dev_err_probe(chip->dev, ret, "failed to register notifier\n"); + chip->base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(chip->base)) return PTR_ERR(chip->base); @@ -226,6 +271,9 @@ static void eud_remove(struct platform_device *pdev) device_init_wakeup(&pdev->dev, false); disable_irq_wake(chip->irq); + eud_unregister_notify(&eud_notifier); + + return 0; } static const struct of_device_id eud_dt_match[] = {