From patchwork Sun Nov 18 10:08:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Laszczak X-Patchwork-Id: 10687723 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D36CA109C for ; Sun, 18 Nov 2018 10:12:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BDBBD29D38 for ; Sun, 18 Nov 2018 10:12:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B011F29D43; Sun, 18 Nov 2018 10:12:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA01229D38 for ; Sun, 18 Nov 2018 10:12:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727629AbeKRUcE (ORCPT ); Sun, 18 Nov 2018 15:32:04 -0500 Received: from mx0b-0014ca01.pphosted.com ([208.86.201.193]:41228 "EHLO mx0a-0014ca01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726287AbeKRUaz (ORCPT ); Sun, 18 Nov 2018 15:30:55 -0500 Received: from pps.filterd (m0042333.ppops.net [127.0.0.1]) by mx0b-0014ca01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id wAIA8s0x007707; Sun, 18 Nov 2018 02:10:47 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=proofpoint; bh=Ml6q2VyDM6T5cCTv/BOLUqUu3MkLPOuZH5iFCAWBYUo=; b=m54xYOb2z0x1L8SIQnzjl4VVpoDe64QjJTSOz+QibH0yczXcylyxJPFkbkbTyWT3pdLt +BSWv0SIzOpJRQP0rcMBR8F5HSS59MMLPTtlaaZTI/BqAuSTxfYJgnwi9Hb6M4rV/YDz gnoEhyI59Q9dw00TU3X9MQXb+HWJKDOsRgeCkh2NxuhETBBCQYt64O9VhF0yG7aA/M69 atlB8q5UKLzTonWHrx8MzsveyRqbAdT9MhO520r5G2pWXQ91SEWpoke+vX8Psc/smlc5 y8yDrUrBpkkYNVwTTz7ioQC3zyjnmr6pUJKRkVjrakmg2XsgCMEa8Igg0dRcy3WyG7tg iQ== Authentication-Results: cadence.com; spf=pass smtp.mailfrom=pawell@cadence.com Received: from nam03-dm3-obe.outbound.protection.outlook.com (mail-dm3nam03lp0019.outbound.protection.outlook.com [207.46.163.19]) by mx0b-0014ca01.pphosted.com with ESMTP id 2ntff7w44n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sun, 18 Nov 2018 02:10:47 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ml6q2VyDM6T5cCTv/BOLUqUu3MkLPOuZH5iFCAWBYUo=; b=YXYJ9KS0KmPRzvMv7SxzjJxbbqJQ8lS71ZboYOFjxOmzUT/KfMh+/O5jJres0437t5vZ3uzTTpuArTqc753gR3pg/Wm3Au/h4u0CtEFVN+bG+zOCI9cOSxeD9AuF3zEPPqgy/Ndp6wjTRYCDR71jMaKioI6z93E22Iyx02kF5g8= Received: from DM5PR07CA0045.namprd07.prod.outlook.com (2603:10b6:3:16::31) by BLUPR0701MB1860.namprd07.prod.outlook.com (2a01:111:e400:5165::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.21; Sun, 18 Nov 2018 10:10:44 +0000 Received: from BY2NAM05FT052.eop-nam05.prod.protection.outlook.com (2a01:111:f400:7e52::203) by DM5PR07CA0045.outlook.office365.com (2603:10b6:3:16::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.21 via Frontend Transport; Sun, 18 Nov 2018 10:10:44 +0000 Received-SPF: SoftFail (protection.outlook.com: domain of transitioning cadence.com discourages use of 158.140.1.28 as permitted sender) Received: from sjmaillnx2.cadence.com (158.140.1.28) by BY2NAM05FT052.mail.protection.outlook.com (10.152.100.189) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.3 via Frontend Transport; Sun, 18 Nov 2018 10:10:40 +0000 Received: from maileu3.global.cadence.com (maileu3.cadence.com [10.160.88.99]) by sjmaillnx2.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAb5J029622 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Sun, 18 Nov 2018 02:10:39 -0800 X-CrossPremisesHeadersFilteredBySendConnector: maileu3.global.cadence.com Received: from maileu3.global.cadence.com (10.160.88.99) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Sun, 18 Nov 2018 11:10:40 +0100 Received: from lvlogina.cadence.com (10.165.176.102) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Sun, 18 Nov 2018 11:10:40 +0100 Received: from lvlogina.cadence.com (localhost.localdomain [127.0.0.1]) by lvlogina.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAaGC030892; Sun, 18 Nov 2018 10:10:36 GMT Received: (from pawell@localhost) by lvlogina.cadence.com (8.14.4/8.14.4/Submit) id wAIAAafU030891; Sun, 18 Nov 2018 10:10:36 GMT From: Pawel Laszczak To: CC: , , , , , , , , , , , , "Pawel Laszczak" Subject: [RFC PATCH v2 01/15] usb:cdns3: add pci to platform driver wrapper. Date: Sun, 18 Nov 2018 10:08:57 +0000 Message-ID: <1542535751-16079-2-git-send-email-pawell@cadence.com> X-Mailer: git-send-email 1.7.11.2 In-Reply-To: <1542535751-16079-1-git-send-email-pawell@cadence.com> References: <1542535751-16079-1-git-send-email-pawell@cadence.com> MIME-Version: 1.0 X-OrganizationHeadersPreserved: maileu3.global.cadence.com X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:158.140.1.28;IPV:CAL;SCL:-1;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(376002)(396003)(346002)(39860400002)(136003)(2980300002)(36092001)(189003)(199004)(50226002)(36756003)(47776003)(2351001)(107886003)(106466001)(86362001)(575784001)(426003)(446003)(11346002)(316002)(4720700003)(16586007)(336012)(42186006)(54906003)(6916009)(2616005)(186003)(26005)(105596002)(486006)(126002)(476003)(4326008)(50466002)(26826003)(305945005)(48376002)(8676002)(478600001)(6666004)(246002)(7636002)(87636003)(356004)(8936002)(217873002)(76176011)(51416003)(5660300001)(2906002);DIR:OUT;SFP:1101;SCL:1;SRVR:BLUPR0701MB1860;H:sjmaillnx2.cadence.com;FPR:;SPF:SoftFail;LANG:en;PTR:corp.cadence.com;MX:1;A:1; X-Microsoft-Exchange-Diagnostics: 1;BY2NAM05FT052;1:8ntxFeeauwJ97dWuQN1mGGnvEzd7Kz9/cPU2B1v+dL5x8dokq+wqEYvH5cIQ9xQgjhCZjYndbRRTxymyHDgsCrb4nJsA6qx4+eGiZSFtE0ThzE2C/+GtYdCBqe40E20S X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9ba51b55-ade6-42a5-2eca-08d64d3e19c1 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060);SRVR:BLUPR0701MB1860; X-Microsoft-Exchange-Diagnostics: 1;BLUPR0701MB1860;3:ek/4GZcWXQptA8Baa0BUd+Msah55b9LLUevWlD+fui1ueMFyNCCGFzSyN7FII0Dj0KRHDCwDz92q6rBeAJRV/B58NR7rlA/JWAnwu+8BAjozfN1In7WLKjBOAUV7wcSeuvkElgmFo6LuhodkfkStaSZqNRcXkOGNA0VXr6J/X2OX7+lqjHwS+W62F16Y8UJ0HYFd+UdYWW6dmGTBDSU+lAOXi39ZkhbIVrCfobkWupYe2HOYdOxr6BPAPbXLvr4Of95ScgrWUMxxnQZi4Lr8/57WSUr2zGwxR8wrzRznHrN0Pddneoeo9g8Y40dFtlTU+Y/haE2l60KaoObIGjabrrlwdDE3DOomMfex3v1K/5I=;25:vVMyJ6XaJyFQtJDBtdHIfWNKK+K9svAtiZlFxMvzAmhCFKsRVx/ig/JkAtmNWbeiAheNtMSnIq280/SHwhxGYZ4pfTYq6udmk1vE3QCfh/uL7S3LxiLTQdQ7mXMODHtlg2m1OhO+gJOosmjRhqyLEXH1zWsOxnhbKWPfzxHEtzL4D6gcSP+lAbbLs3kONArnLt4GDTLlYSYkZCid5ffHkzn6DWQN676J91R1/LyT3OwJEw/2dAlLbEsvRN587MvdgUu8MlzyKaEYMLUZiNvu7xJRudJ6+RnTwXCJ94y3s1HEgcdp+xx5nMqqdSeXEJqSDqGWgccg4TPVE/JAQQbRCXOTy4VKktlK9aaEWccjBUo= X-MS-TrafficTypeDiagnostic: BLUPR0701MB1860: X-Microsoft-Exchange-Diagnostics: 1;BLUPR0701MB1860;31:uB7ob1SzVMXIENNH8WaSPgQk+3KHhy6+Nfz90Y97mS3N6QlJkE2p42W2CJFMk/vAcp6q1vv4nPQX336EWooYstNNLBaiUHgCz5F7lttjRUoPhVJsdfQh9Re/PHDttqgX6OeVmfEdKzp1JrOXptYIj//2GXjdKsLKT8zq5TxydBxIh52mhVHgAele88nI9smaLWOrEniWZemdhnR7NQYrP3U2Y5ftFYDmdLMO1M6lfLQ=;20:Ay6VBdEUa6R8YKS7hugQzleqxwmzFE5s4N4Rxx6Vfm1/h+h6gm7HLHaTes1mM4i45ClzHTUk401IXuZ27VE6R4QV/ohLyXIu5qEt6v7pcl1qRhTgdeaIBxqZseWy5wTEfyUNg1u3VQud/dCGqqUsBB5nwCU5Xzz63vt6KtYVKc+sCYmrNBugu0fp7Ja+zAm3ZjZzhelnZz/NRUJ5REUYxdoLbFt/vKqMri/VSSI+NClg5uucxQtCetL8lFBF2g2KWCeC+1lCTqGlw2RytqMXToRmXL5cXn5Eaa5jc+Ja9fq/2LJf7eNybmVsZJVs0LJ4Mt7/oVeJtTWfzMP7Xez/Gu1gqOZgM8OrK5lWx9TNOuhN7nZAmgTzBNkKCd84WeYWA9RmQEcdcCjx13FTM+xRl7eyQiIc93YAmBvrwJg3rjnTHuCOdjVsTAgUQsysNmuYVwHbNDox4VugD1VRZDf0ftYTo6SVxWU1/mlKdhR3fH6AjJqsONWzu/1Lb5ia+4qS X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93003095)(10201501046)(3002001)(3231415)(944501410)(52105112)(148016)(149066)(150057)(6041310)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123558120)(20161123562045)(201708071742011)(7699051)(76991095);SRVR:BLUPR0701MB1860;BCL:0;PCL:0;RULEID:;SRVR:BLUPR0701MB1860; X-Microsoft-Exchange-Diagnostics: 1;BLUPR0701MB1860;4:VKS6Wo3CC/E4IvXH6bkaHZ54PZ7zremSwi7cUKtGahC3Gw4X7cNmzEc1WEZWFqu67FvV0n4UjF2WjJEZjyg0y3oOtJpkvVwm2MSyzv12glEPP3t1urXLyqg/Mhm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wJxvVrr2h+nMaEd38dlkkOEu8vZ6Y9IDNSULUPRxBU8rgdla2FKRqbyTHxvIiQdWsyGe8KNWBoOudGXoFFM94cozEGpKCcQhYat36ly4DaQg6YBUQmu7ceiAltAfeTdHTG68eyl3T0clbyE8kC2w=;5:S88aHlZ/S+ZUrZh4FoZfdiRg6PObNqPcJfpYND+XRALNVKVSl0w+KbxO8meKSbjJqvtwNqCoCt2i5H5XTNV3uJC1yAECQ/BTmOZGMSVvW9Jkcwunk6Z0CsXtXa7w5hSvdWHozG3aCFpk05BWYVuIh1b9fM7ZGlnFVeIMcWR4mPY=;7:nG4OnB+Nf+e5cI2ufEAk/NqJZVR8rlZJS8UUU7PgZdcjvoqa/r2SZhNVXCo2jSelkD1FRT+ZI/bQlwD1zSV2dTU1tvYBQAxOh8iCdYPbOk5kgKY2zAHjsbDZy1CNXHMIBVtslQJgqD3UhrEQnLSYrw== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BLUPR0701MB1860;20:In4Poghvqa55f/gL73Z3IKEzPMHXn8uRjxVpjrqjZo+Cw+5g7stvLwq/PxTC63qXGRO++eJ9qOtCZE+b1Ap4EaQ+orrpOYmmCYHtrtrYSx3Ac4DI64nl76VmuMA8i7P+Mop3jeeKIOSCdWoQz7ITCxVrfSkTA8rbO5E/SWvGfWaiyaMjRCIc19Y3x/l+LPGQHW92Af+Gx72iyEdJdZSl+wOgmm5OiNWe9OPOsO5S6l6+ZkYF4JIO9IqNkEGhVwbU X-OriginatorOrg: cadence.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2018 10:10:40.2561 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9ba51b55-ade6-42a5-2eca-08d64d3e19c1 X-MS-Exchange-CrossTenant-Id: d36035c5-6ce6-4662-a3dc-e762e61ae4c9 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=d36035c5-6ce6-4662-a3dc-e762e61ae4c9;Ip=[158.140.1.28];Helo=[sjmaillnx2.cadence.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR0701MB1860 X-Proofpoint-SPF-Result: pass X-Proofpoint-SPF-Record: v=spf1 a:mx-sanjose2.Cadence.COM a:mx-sanjose4.Cadence.COM a:mx-sanjose5.Cadence.COM include:mktomail.com include:spf-0014ca01.pphosted.com include:spf.protection.outlook.com include:auth.msgapp.com include:spf.mandrillapp.com ~all X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-11-18_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_check_notspam policy=outbound_check score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=827 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811180097 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Patch adds PCI specific glue driver that creates and registers in-system cdns-usb3 platform device. Thanks to that we will be able to use the cdns-usb3 platform driver for USBSS-DEV controller build on PCI board Signed-off-by: Pawel Laszczak --- drivers/usb/Kconfig | 2 + drivers/usb/Makefile | 2 + drivers/usb/cdns3/Kconfig | 24 +++++ drivers/usb/cdns3/Makefile | 3 + drivers/usb/cdns3/cdns3-pci-wrap.c | 157 +++++++++++++++++++++++++++++ 5 files changed, 188 insertions(+) create mode 100644 drivers/usb/cdns3/Kconfig create mode 100644 drivers/usb/cdns3/Makefile create mode 100644 drivers/usb/cdns3/cdns3-pci-wrap.c diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig index 987fc5ba6321..5f9334019d04 100644 --- a/drivers/usb/Kconfig +++ b/drivers/usb/Kconfig @@ -112,6 +112,8 @@ source "drivers/usb/usbip/Kconfig" endif +source "drivers/usb/cdns3/Kconfig" + source "drivers/usb/mtu3/Kconfig" source "drivers/usb/musb/Kconfig" diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile index 7d1b8c82b208..82093a60ea2c 100644 --- a/drivers/usb/Makefile +++ b/drivers/usb/Makefile @@ -8,6 +8,8 @@ obj-$(CONFIG_USB) += core/ obj-$(CONFIG_USB_SUPPORT) += phy/ +obj-$(CONFIG_USB_CDNS3) += cdns3/ + obj-$(CONFIG_USB_DWC3) += dwc3/ obj-$(CONFIG_USB_DWC2) += dwc2/ obj-$(CONFIG_USB_ISP1760) += isp1760/ diff --git a/drivers/usb/cdns3/Kconfig b/drivers/usb/cdns3/Kconfig new file mode 100644 index 000000000000..eb22a8692991 --- /dev/null +++ b/drivers/usb/cdns3/Kconfig @@ -0,0 +1,24 @@ +config USB_CDNS3 + tristate "Cadence USB3 Dual-Role Controller" + depends on USB_SUPPORT && (USB || USB_GADGET) && HAS_DMA + help + Say Y here if your system has a cadence USB3 dual-role controller. + It supports: dual-role switch, Host-only, and Peripheral-only. + + If you choose to build this driver is a dynamically linked + module, the module will be called cdns3.ko. + +if USB_CDNS3 + +config USB_CDNS3_PCI_WRAP + tristate "PCIe-based Platforms" + depends on USB_PCI && ACPI + default USB_CDNS3 + help + If you're using the USBSS Core IP with a PCIe, please say + 'Y' or 'M' here. + + If you choose to build this driver as module it will + be dynamically linked and module will be called cdns3-pci.ko + +endif diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile new file mode 100644 index 000000000000..dcdd62003c6a --- /dev/null +++ b/drivers/usb/cdns3/Makefile @@ -0,0 +1,3 @@ +obj-$(CONFIG_USB_CDNS3_PCI_WRAP) += cdns3-pci.o + +cdns3-pci-y := cdns3-pci-wrap.o diff --git a/drivers/usb/cdns3/cdns3-pci-wrap.c b/drivers/usb/cdns3/cdns3-pci-wrap.c new file mode 100644 index 000000000000..d0a15cc0b738 --- /dev/null +++ b/drivers/usb/cdns3/cdns3-pci-wrap.c @@ -0,0 +1,157 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Cadence USBSS PCI Glue driver + * + * Copyright (C) 2018 Cadence. + * + * Author: Pawel Laszczak + */ + +#include +#include +#include +#include +#include +#include + +struct cdns3_wrap { + struct platform_device *plat_dev; + struct pci_dev *hg_dev; + struct resource dev_res[4]; +}; + +struct cdns3_wrap wrap; + +#define RES_IRQ_ID 0 +#define RES_HOST_ID 1 +#define RES_DEV_ID 2 +#define RES_DRD_ID 3 + +#define PCI_BAR_HOST 0 +#define PCI_BAR_DEV 2 +#define PCI_BAR_OTG 4 + +#define PCI_DEV_FN_HOST_DEVICE 0 +#define PCI_DEV_FN_OTG 1 + +#define PCI_DRIVER_NAME "cdns3-pci-usbss" +#define PLAT_DRIVER_NAME "cdns-usb3" + +#define CDNS_VENDOR_ID 0x17cd +#define CDNS_DEVICE_ID 0x0100 + +/** + * cdns3_pci_probe - Probe function for Cadence USB wrapper driver + * @pdev: platform device object + * @id: pci device id + * + * Returns 0 on success otherwise negative errno + */ +static int cdns3_pci_probe(struct pci_dev *pdev, + const struct pci_device_id *id) +{ + struct platform_device_info plat_info; + struct cdns3_wrap *wrap; + struct resource *res; + int err; + + /* + * for GADGET/HOST PCI (devfn) function number is 0, + * for OTG PCI (devfn) function number is 1 + */ + if (!id || pdev->devfn != PCI_DEV_FN_HOST_DEVICE) + return -EINVAL; + + err = pcim_enable_device(pdev); + if (err) { + dev_err(&pdev->dev, "Enabling PCI device has failed %d\n", err); + return err; + } + + pci_set_master(pdev); + wrap = devm_kzalloc(&pdev->dev, sizeof(*wrap), GFP_KERNEL); + if (!wrap) { + dev_err(&pdev->dev, "Failed to load PCI module\n"); + return -ENOMEM; + } + + /* function 0: host(BAR_0) + device(BAR_1) + otg(BAR_2)). */ + memset(wrap->dev_res, 0x00, + sizeof(struct resource) * ARRAY_SIZE(wrap->dev_res)); + dev_dbg(&pdev->dev, "Initialize Device resources\n"); + res = wrap->dev_res; + + res[RES_DEV_ID].start = pci_resource_start(pdev, PCI_BAR_DEV); + res[RES_DEV_ID].end = pci_resource_end(pdev, PCI_BAR_DEV); + res[RES_DEV_ID].name = "cdns3-dev-regs"; + res[RES_DEV_ID].flags = IORESOURCE_MEM; + dev_dbg(&pdev->dev, "USBSS-DEV physical base addr: %pa\n", + &res[RES_DEV_ID].start); + + res[RES_HOST_ID].start = pci_resource_start(pdev, PCI_BAR_HOST); + res[RES_HOST_ID].end = pci_resource_end(pdev, PCI_BAR_HOST); + res[RES_HOST_ID].name = "cdns3-xhci-regs"; + res[RES_HOST_ID].flags = IORESOURCE_MEM; + dev_dbg(&pdev->dev, "USBSS-XHCI physical base addr: %pa\n", + &res[RES_HOST_ID].start); + + res[RES_DRD_ID].start = pci_resource_start(pdev, PCI_BAR_OTG); + res[RES_DRD_ID].end = pci_resource_end(pdev, PCI_BAR_OTG); + res[RES_DRD_ID].name = "cdns3-otg"; + res[RES_DRD_ID].flags = IORESOURCE_MEM; + dev_dbg(&pdev->dev, "USBSS-DRD physical base addr: %pa\n", + &res[RES_DRD_ID].start); + + /* Interrupt common for both device and XHCI */ + wrap->dev_res[RES_IRQ_ID].start = pdev->irq; + wrap->dev_res[RES_IRQ_ID].name = "cdns3-irq"; + wrap->dev_res[RES_IRQ_ID].flags = IORESOURCE_IRQ; + + /* set up platform device info */ + memset(&plat_info, 0, sizeof(plat_info)); + plat_info.parent = &pdev->dev; + plat_info.fwnode = pdev->dev.fwnode; + plat_info.name = PLAT_DRIVER_NAME; + plat_info.id = pdev->devfn; + plat_info.res = wrap->dev_res; + plat_info.num_res = ARRAY_SIZE(wrap->dev_res); + plat_info.dma_mask = pdev->dma_mask; + + /* register platform device */ + wrap->plat_dev = platform_device_register_full(&plat_info); + if (IS_ERR(wrap->plat_dev)) { + err = PTR_ERR(wrap->plat_dev); + return err; + } + + pci_set_drvdata(pdev, wrap); + + return err; +} + +void cdns3_pci_remove(struct pci_dev *pdev) +{ + struct cdns3_wrap *wrap = (struct cdns3_wrap *)pci_get_drvdata(pdev); + + platform_device_unregister(wrap->plat_dev); +} + +static const struct pci_device_id cdns3_pci_ids[] = { + { PCI_DEVICE(CDNS_VENDOR_ID, CDNS_DEVICE_ID), }, + { 0, } +}; + +static struct pci_driver cdns3_pci_driver = { + .name = PCI_DRIVER_NAME, + .id_table = cdns3_pci_ids, + .probe = cdns3_pci_probe, + .remove = cdns3_pci_remove, +}; + +module_pci_driver(cdns3_pci_driver); +MODULE_DEVICE_TABLE(pci, cdns3_pci_ids); + +MODULE_AUTHOR("Pawel Laszczak "); +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("Cadence USBSS PCI wrapperr"); + From patchwork Sun Nov 18 10:08:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Laszczak X-Patchwork-Id: 10687731 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 719CC17DE for ; Sun, 18 Nov 2018 10:12:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D3FC29D38 for ; Sun, 18 Nov 2018 10:12:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4EB5129D47; Sun, 18 Nov 2018 10:12:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0226829D38 for ; Sun, 18 Nov 2018 10:12:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727678AbeKRUcY (ORCPT ); Sun, 18 Nov 2018 15:32:24 -0500 Received: from mx0a-0014ca01.pphosted.com ([208.84.65.235]:36332 "EHLO mx0a-0014ca01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725962AbeKRUay (ORCPT ); Sun, 18 Nov 2018 15:30:54 -0500 Received: from pps.filterd (m0042385.ppops.net [127.0.0.1]) by mx0a-0014ca01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id wAIA6qt7016172; Sun, 18 Nov 2018 02:10:49 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=proofpoint; bh=dfBVxtCDJpRTOMlgw4Ho5J6B0bD+jvatmAlz3hksdBc=; b=oO+IV1UEKZifouqxfixRyAO2/Lxorg1UuamxxDXOGu1SlFls7z1vGegmmvs+af05IboM vaPl1PAH8H1nGUtGCFutFKI0ShPzCmpfF10pz3WSXoj5pcAaex53rtCxkPst3vjFC8Dc +GRwB4KVIo7JzQcXDekXXwBvraE1CDvlZ2rdn9RpIXOUIBpSoxjvMwRWnwVGShUYRIub UO+EqFrmU/yBr1PackA4k2QeGhpvqSdpRHvgIAbjkNpgaIj5BoQP2vdA1GWTRdL0fSfR uLkIe9IVB762jWlUvD2gC7KyVgA7HU0t5q33mLiBYJWWB1VHGAZ5a6aCrBoWgx1s97JE Kg== Authentication-Results: cadence.com; spf=pass smtp.mailfrom=pawell@cadence.com Received: from nam03-co1-obe.outbound.protection.outlook.com (mail-co1nam03lp0015.outbound.protection.outlook.com [216.32.181.15]) by mx0a-0014ca01.pphosted.com with ESMTP id 2ntge14vg4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sun, 18 Nov 2018 02:10:49 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dfBVxtCDJpRTOMlgw4Ho5J6B0bD+jvatmAlz3hksdBc=; b=H4wIkogM2NO89fCdsbm4DH84fpjQGxMyLKkjVhK65soJjsSTve5dZFAfUz+8FRDXswnMSgHIHrg4QJfA3/v1q4053GZiB2761SBkOy12PKZBBlHQD3Csn9TsiWfUrBTW9cBCd8yTmEyddVALuUY4a4Oh2EWcgsodrIiI1Jrz2Ac= Received: from CY1PR07CA0033.namprd07.prod.outlook.com (2a01:111:e400:c60a::43) by SN1PR0701MB1869.namprd07.prod.outlook.com (2a01:111:e400:517b::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.30; Sun, 18 Nov 2018 10:10:45 +0000 Received: from BY2NAM05FT039.eop-nam05.prod.protection.outlook.com (2a01:111:f400:7e52::207) by CY1PR07CA0033.outlook.office365.com (2a01:111:e400:c60a::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.21 via Frontend Transport; Sun, 18 Nov 2018 10:10:45 +0000 Received-SPF: SoftFail (protection.outlook.com: domain of transitioning cadence.com discourages use of 158.140.1.28 as permitted sender) Received: from sjmaillnx2.cadence.com (158.140.1.28) by BY2NAM05FT039.mail.protection.outlook.com (10.152.100.176) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.3 via Frontend Transport; Sun, 18 Nov 2018 10:10:41 +0000 Received: from maileu3.global.cadence.com (maileu3.cadence.com [10.160.88.99]) by sjmaillnx2.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAb5K029622 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Sun, 18 Nov 2018 02:10:39 -0800 X-CrossPremisesHeadersFilteredBySendConnector: maileu3.global.cadence.com Received: from maileu3.global.cadence.com (10.160.88.99) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Sun, 18 Nov 2018 11:10:40 +0100 Received: from lvlogina.cadence.com (10.165.176.102) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Sun, 18 Nov 2018 11:10:40 +0100 Received: from lvlogina.cadence.com (localhost.localdomain [127.0.0.1]) by lvlogina.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAbLL030927; Sun, 18 Nov 2018 10:10:37 GMT Received: (from pawell@localhost) by lvlogina.cadence.com (8.14.4/8.14.4/Submit) id wAIAAaD0030926; Sun, 18 Nov 2018 10:10:36 GMT From: Pawel Laszczak To: CC: , , , , , , , , , , , , "Pawel Laszczak" Subject: [RFC PATCH v2 02/15] usb:cdns3: Device side header file. Date: Sun, 18 Nov 2018 10:08:58 +0000 Message-ID: <1542535751-16079-3-git-send-email-pawell@cadence.com> X-Mailer: git-send-email 1.7.11.2 In-Reply-To: <1542535751-16079-1-git-send-email-pawell@cadence.com> References: <1542535751-16079-1-git-send-email-pawell@cadence.com> MIME-Version: 1.0 X-OrganizationHeadersPreserved: maileu3.global.cadence.com X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:158.140.1.28;IPV:CAL;SCL:-1;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(396003)(136003)(346002)(39860400002)(376002)(2980300002)(199004)(189003)(36092001)(87636003)(26826003)(7636002)(53946003)(4326008)(305945005)(336012)(16586007)(316002)(42186006)(2616005)(11346002)(446003)(54906003)(426003)(50466002)(86362001)(356004)(476003)(478600001)(6666004)(6916009)(48376002)(486006)(126002)(4720700003)(36756003)(8676002)(4744004)(217873002)(2906002)(14444005)(26005)(5660300001)(76176011)(2351001)(107886003)(50226002)(551934003)(186003)(47776003)(106466001)(8936002)(105596002)(51416003)(246002);DIR:OUT;SFP:1101;SCL:1;SRVR:SN1PR0701MB1869;H:sjmaillnx2.cadence.com;FPR:;SPF:SoftFail;LANG:en;PTR:corp.cadence.com;A:1;MX:1; X-Microsoft-Exchange-Diagnostics: 1;BY2NAM05FT039;1:GGAadEZUXFKyXAvatM8+xH/VHlO8F+5yc312c1smx2pk40MxvIov7/nY0zwVzdIZEdgTrF58CVsJQjUEI9HjsqopWGHJ+l/Vc9sp/qlxKSKoMNej4rg2VoQpvDR/JY5j X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7d922ba9-4005-4a10-cc53-08d64d3e1a51 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060);SRVR:SN1PR0701MB1869; X-Microsoft-Exchange-Diagnostics: 1;SN1PR0701MB1869;3:H7Oh3ivTCexut+jK8eqj45nmRMbRzWc/WsIChVK/pCssHAydZfJuNi9MdbVAIpidTE1T68nFzRrAv5pvHt0FtSPMhkCP8NZeLxjIp203Aq7gI4t4k0QHKiPXzT3GrnQYq2xEVtaT+UDaRM81lADSn6B88NtRW0O6T+o3PEbNhLjBO0WPF7W+x0BrDHKTfWyC6tUtftY8R1A3fk4sNpIclJBrZzFahXHq/XVrO1G+q3dygaaLDGuvfFxMZ67aUIIn7deTi3RnsHr6XZdxW7eBuXKLFy0vpQFnVzmd9B+lwKcyv0OKdj+X+XtLSRQf3jCqIELf0HkFTJUN33VKLBy3Y5Ilygv9AV8dYKJelfQULw8=;25:eFo1M8CcBwjpfxQTLPZGv7tEN6aRQkw+BqncSof7990fGODnRFUdn1us+TpYF15e1yldMEvLw2HlW3gUnrn+1QJew/NRydohUofepeMBIUUH6wirCne1nCGyXtOYCi8kT+bsLQ84Spc9a2/BQnF92d45JBetYI3QbRxkxG1Jw9xLxRnIBL6NCvG0dwTA19xyHZPN9TRMM/gp/+hes5zzReZIm4ydr9hebMhqFoRgSIIGXRvovINH63NqzCoTvMLJ3Zg5KKs1JqmXGiUl0mNAM9uek1VA8mM+r12OI3R2KwMZdRPHou8hnPF8+NYDAitkui5IpYhid1VziU8cEdgwzOQrcLmp5KX1z+DvqN96rZw= X-MS-TrafficTypeDiagnostic: SN1PR0701MB1869: X-Microsoft-Exchange-Diagnostics: 1;SN1PR0701MB1869;31:rErwiMMjuRowsTqNwJWhupxKnIlcSyAlRr6EqYHT3A1tcN8p1Kjl0XT1bdtgPjh2s6HGSb4JGTZODkCH747x5bzO5RQnxc9OP55VhWVzKD42oxBeThqwYFffHB1HHueIqDZ930fsv8REQt0zKTpfUP9moJwFS1PkQ1DTSfVeSPAPsumVPO5b5hBxATpjIDcUHbjKJz7HUCCym+jbXkjjxddwmdqNGowq67A/FybR2r4=;20:tqJNgb8bwMlyIIlYUSvn3osMc2gWWIA87fFQhNkWLQy7PVh6v0v9bDzT0BFST52QdzwXF5HG8GpPmp3d1xh2slNNYerhrIRus0tNapesdZQ8ia7OlCIhb7jQkuQmGDUSSRuppqYUQHS1q1rIVGk81m50bClrP4Q6w80c6cdFN4e2RreJ697OIZOdqq2x7R5PSDECVIqo2yIRZv9SlZrfbLn+cSTwVebmyglB2iEnsY95rMZybRhglfRJQGSxc7xn19gMNQyJz322b9jt9e5FB6vmaGPk08nIaYmlbvbZBnIn4YeAv5LwebJAA1RBH42J5qj1/avbEBLSKWbx/I+YYBG0Da0uGfNexn1eRB1GA4avLaCAHha6XOUFItyHCGLlBvhQ75htLNMizg9D3oBygtPxq+PmTMa/JU5WAZdVe7zbpOkuVj+BgEAEkjoZInvWxYtjmvR6WgMOTpmMN2bJqxJGPc4/0FGiBR2JPhwSp0p10UGSn3v/mfGcOSEDRTRo X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(72806322054110)(185117386973197)(60795455431006); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(93006095)(93003095)(10201501046)(3002001)(3231415)(944501410)(52105112)(148016)(149066)(150057)(6041310)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(20161123560045)(201708071742011)(7699051)(76991095);SRVR:SN1PR0701MB1869;BCL:0;PCL:0;RULEID:;SRVR:SN1PR0701MB1869; X-Microsoft-Exchange-Diagnostics: 1;SN1PR0701MB1869;4:GA5W7zLBUjwQcvzVFenO+ivWoZvEAdDaYpOiEiOwv52Sxa1/OL0o6pKR+JymYtQBCQ1NECVfmPJTrYABBlh1J/xVmuUt/RuxWMa63BfIjzEbD9BKxN7eeLNc53XaDP5LaeAEKkf1At8muZeEfBRrKfYOaXw6rG7AHCFM6ZVrJ92gxpDotUtiyc4YUcEWfzDWJWGYiS/4UMCToJBtzUWEpvrTzkZtYD2P0Ym0TRxHEOmFheH0ob9/dThuE57qSKfk2V7PmTHH3a4y+MY524oppp/mciX+UZNT/Y6NxzWqWxz93WfbT+jgFk2cU3i/eTdcjXYo9yODVJkP8DqmJdoFJ6N6/VbXfewez0uG+vkwlzPJ2jG7NVoQ0mdgYIJ9ADPj X-Forefront-PRVS: 0860FE717F X-Microsoft-Exchange-Diagnostics: 1;SN1PR0701MB1869;23:J5/qvwH8p718+WDz+QEAEpYgFZi/Rvf5dyEkdtEVNwXoO3yt+/RVcKnqOPFHkaWx6tI3ArLbM+Tn2BudKEu88Xu60fQDsJUCylrh7/FyXeXCUax6Py1bUPo3sXcyATPWDCpzjOoI711H3fVTUE1bW0/QZmtzBVCT90yrVcdEQtk5ETKn4c8ZacswiFfAT8nTh32g3Zu9mlLd6Y0bok4juCBKKGQU6bkoTvSs2qFsdf83e4UQPGVrGWOMzMe5l+RjLTdl4hJk1k0hnrNIzjpjzeRLOmnI/vb7huWKyLiwx5Dcjc5ZNQOr2lAVpBojX7C2vudoaZU1bvztN/17Xu7p383bibi+l6BEauNmydsLcvdw0QBGIK6f1qkXL2HiFX+rzVs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EfqI8N7XNFcqdexZwrkGbVnB50KkRNMjcghb7eEt75ACT+1FVP3P1rzTGwWJ2tiS/WZ0PTdAAAZ8aIhVVYfwN/zzidQSlARt8749tjmRBmNZ05B6ZGVmFB0jB6RfqzH6rB3xLjkfuUXyWwvVpVCRjlOS47bqvo/8VI= X-Microsoft-Exchange-Diagnostics: 1;SN1PR0701MB1869;6:31tuj5HEl3HbsmMb+qtiFXTs9vQ55kPna+7qsGTKK80lBqWDP2x4ynJRcXdTYGf4fW0Ff9f4NqYr3c0B/Efyg9XkFAY9mT0Ek5y/HD9JnDE3m/7N1J3xd/Oy99BMVC1a++XeR3dXC5tBMq6BHCZeuUgf/dDUxMTzSJIc+2B6hq0zPRbo5QcrZINziimPbmUJ5EidDjzcW0rCxSorctgb7wpkCkD7SZOUXdFm4JFPnFl7EXknn0nDJSXbx62RSaB8AeGyloXRKf6etzsrTCOf52r0E38nMk65+9wucbqHXR4Pfs2Jek5t9o0BNfgzEbs1MoyN/ZL/p5AEMErfFW8YBJFKMw3Z7Kxxs5SZyN05gh2LNleisvmkOiU3iaPs713UBAtcoRQ8MIjyH0tFT9IZ175fNShGho/QPr3s2nSDHiOWBJ7eEueE5O2BEaJQK3lHn0zDZiUJKkljR3/sTctGWQ==;5:BtztjfxfEfslUwg8aM4QaRsw45FzAdwndK0XnLxmCVNHRjxX7lg5hF1Uu0s7G7/yVg4j7clefs1cx0m8nv1Xzjx+Kms0B+vizr8ctwT1C5JhfvHnBb1eQrI3wFmE3QqvWypfz82P85KtlJut33349JZniomaYWwO/yrpytat8tI=;7:bMJlDA/C9SJ8emgurxYRykZ7R1Bnr3WNfKr0EZmCVewSLs7DWen61KlvSHZLq93CW4nt9+MJnPhslOJJIS07rlbyzs7BJDBRIHLqWsUlJYkF/9m+cVgFVcSb9foR8ZUpH9/tpb2X8DtMnDgQuEtfcg== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;SN1PR0701MB1869;20:ekwONkHO3hEDHHLCMHJXkGD9Tger1v4onvxR7d4tDwSfeLAnTooUv7zBZsUgsxrxo8nq2xKWAl7dFeAQhcXgcr/5yJulO+0GDF/WsUvnuaA6CgPZxeEeUzqy2UmhTjLK4tBSV40YinsESfb65Ru9I59aT6VddYXvpJgDZnnvotDK6rOAlZAZuB5AvnYIgXP40+PCyTg+ngzlvph3A4ysQGmT8iseKLhU6KdvaiVAs+9poUeMWQxc+OY0ftXTS0l/ X-OriginatorOrg: cadence.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2018 10:10:41.0632 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7d922ba9-4005-4a10-cc53-08d64d3e1a51 X-MS-Exchange-CrossTenant-Id: d36035c5-6ce6-4662-a3dc-e762e61ae4c9 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=d36035c5-6ce6-4662-a3dc-e762e61ae4c9;Ip=[158.140.1.28];Helo=[sjmaillnx2.cadence.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR0701MB1869 X-Proofpoint-SPF-Result: pass X-Proofpoint-SPF-Record: v=spf1 a:mx-sanjose2.Cadence.COM a:mx-sanjose4.Cadence.COM a:mx-sanjose5.Cadence.COM include:mktomail.com include:spf-0014ca01.pphosted.com include:spf.protection.outlook.com include:auth.msgapp.com include:spf.mandrillapp.com ~all X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-11-18_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_check_notspam policy=outbound_check score=0 priorityscore=1501 malwarescore=0 suspectscore=4 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811180096 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Patch defines macros used by device side of controller, structures holding registers, and some other object used by device controller. Signed-off-by: Pawel Laszczak --- drivers/usb/cdns3/gadget.h | 1071 ++++++++++++++++++++++++++++++++++++ 1 file changed, 1071 insertions(+) create mode 100644 drivers/usb/cdns3/gadget.h diff --git a/drivers/usb/cdns3/gadget.h b/drivers/usb/cdns3/gadget.h new file mode 100644 index 000000000000..75ca6214e79a --- /dev/null +++ b/drivers/usb/cdns3/gadget.h @@ -0,0 +1,1071 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * USBSS device controller driver + * + * Copyright (C) 2018 Cadence. + * Copyright (C) 2018 NXP + * + * Author: Pawel Laszczak + * Pawel Jez + * Peter Chen + */ +#ifndef __LINUX_CDNS3_GADGET +#define __LINUX_CDNS3_GADGET +#include + +/* + * USBSS-DEV register interface. + * This corresponds to the USBSS Device Controller Interface + */ + +/** + * struct xhci_cap_regs - xHCI Host Controller Capability Registers. + * @usb_conf: Global Configuration Register. + * @usb_sts: Global Status Register. + * @usb_cmd: Global Command Register. + * @usb_iptn: ITP/SOF number Register. + * @usb_lpm: Global Command Register. + * @usb_ien: USB Interrupt Enable Register. + * @usb_ists: USB Interrupt Status Register. + * @ep_sel: Endpoint Select Register. + * @ep_traddr: Endpoint Transfer Ring Address Register. + * @ep_cfg: Endpoint Configuration Register. + * @ep_cmd: Endpoint Command Register. + * @ep_sts: Endpoint Status Register. + * @ep_sts_sid: Endpoint Status Register. + * @ep_sts_en: Endpoint Status Register Enable. + * @drbl: Doorbell Register. + * @ep_ien: EP Interrupt Enable Register. + * @ep_ists: EP Interrupt Status Register. + * @usb_pwr: Global Power Configuration Register. + * @usb_conf2: Global Configuration Register 2. + * @usb_cap1: Capability Register 1. + * @usb_cap2: Capability Register 2. + * @usb_cap3: Capability Register 3. + * @usb_cap4: Capability Register 4. + * @usb_cap5: Capability Register 5. + * @usb_cap6: Capability Register 6. + * @usb_cpkt1: Custom Packet Register 1. + * @usb_cpkt2: Custom Packet Register 2. + * @usb_cpkt3: Custom Packet Register 3. + * @reserved1: Reserved. + * @cfg_regs: Configuration registers. + * @reserved2: Reserved. + * @dma_axi_ctrl: AXI Control register. + * @dma_axi_id: AXI ID register. + * @dma_axi_cap: AXI Capability register. + * @dma_axi_ctrl0: AXI Control 0 register. + * @dma_axi_ctrl1: AXI Control 1 register. + */ +struct cdns3_usb_regs { + __le32 usb_conf; + __le32 usb_sts; + __le32 usb_cmd; + __le32 usb_iptn; + __le32 usb_lpm; + __le32 usb_ien; + __le32 usb_ists; + __le32 ep_sel; + __le32 ep_traddr; + __le32 ep_cfg; + __le32 ep_cmd; + __le32 ep_sts; + __le32 ep_sts_sid; + __le32 ep_sts_en; + __le32 drbl; + __le32 ep_ien; + __le32 ep_ists; + __le32 usb_pwr; + __le32 usb_conf2; + __le32 usb_cap1; + __le32 usb_cap2; + __le32 usb_cap3; + __le32 usb_cap4; + __le32 usb_cap5; + __le32 usb_cap6; + __le32 usb_cpkt1; + __le32 usb_cpkt2; + __le32 usb_cpkt3; + __le32 reserved1[36]; + __le32 cfg_reg1; + __le32 dbg_link1; + __le32 dbg_link2; + __le32 cfg_regs[74]; + __le32 reserved2[34]; + __le32 dma_axi_ctrl; + __le32 dma_axi_id; + __le32 dma_axi_cap; + __le32 dma_axi_ctrl0; + __le32 dma_axi_ctrl1; +}; + +/* USB_CONF - bitmasks */ +/* Reset USB device configuration. */ +#define USB_CONF_CFGRST BIT(0) +/* Set Configuration. */ +#define USB_CONF_CFGSET BIT(1) +/* Disconnect USB device in SuperSpeed. */ +#define USB_CONF_USB3DIS BIT(3) +/* Disconnect USB device in HS/FS */ +#define USB_CONF_USB2DIS BIT(4) +/* Little Endian access - default */ +#define USB_CONF_LENDIAN BIT(5) +/* + * Big Endian access. Driver assume that byte order for + * SFRs access always is as Little Endian so this bit + * is not used. + */ +#define USB_CONF_BENDIAN BIT(6) +/* Device software reset. */ +#define USB_CONF_SWRST BIT(7) +/* Singular DMA transfer mode. */ +#define USB_CONF_DSING BIT(8) +/* Multiple DMA transfers mode. */ +#define USB_CONF_DMULT BIT(9) +/* DMA clock turn-off enable. */ +#define USB_CONF_DMAOFFEN BIT(10) +/* DMA clock turn-off disable. */ +#define USB_CONF_DMAOFFDS BIT(11) +/* Clear Force Full Speed. */ +#define USB_CONF_CFORCE_FS BIT(12) +/* Set Force Full Speed. */ +#define USB_CONF_SFORCE_FS BIT(13) +/* Device enable. */ +#define USB_CONF_DEVEN BIT(14) +/* Device disable. */ +#define USB_CONF_DEVDS BIT(15) +/* L1 LPM state entry enable (used in HS/FS mode). */ +#define USB_CONF_L1EN BIT(16) +/* L1 LPM state entry disable (used in HS/FS mode). */ +#define USB_CONF_L1DS BIT(17) +/* USB 2.0 clock gate disable. */ +#define USB_CONF_CLK2OFFEN BIT(18) +/* USB 2.0 clock gate enable. */ +#define USB_CONF_CLK2OFFDS BIT(19) +/* L0 LPM state entry request (used in HS/FS mode). */ +#define USB_CONF_LGO_L0 BIT(20) +/* USB 3.0 clock gate disable. */ +#define USB_CONF_CLK3OFFEN BIT(21) +/* USB 3.0 clock gate enable. */ +#define USB_CONF_CLK3OFFDS BIT(22) +/* Bit 23 is reserved*/ +/* U1 state entry enable (used in SS mode). */ +#define USB_CONF_U1EN BIT(24) +/* U1 state entry disable (used in SS mode). */ +#define USB_CONF_U1DS BIT(25) +/* U2 state entry enable (used in SS mode). */ +#define USB_CONF_U2EN BIT(26) +/* U2 state entry disable (used in SS mode). */ +#define USB_CONF_U2DS BIT(27) +/* U0 state entry request (used in SS mode). */ +#define USB_CONF_LGO_U0 BIT(28) +/* U1 state entry request (used in SS mode). */ +#define USB_CONF_LGO_U1 BIT(29) +/* U2 state entry request (used in SS mode). */ +#define USB_CONF_LGO_U2 BIT(30) +/* SS.Inactive state entry request (used in SS mode) */ +#define USB_CONF_LGO_SSINACT BIT(31) + +/* USB_STS - bitmasks */ +/* + * Configuration status. + * 1 - device is in the configured state. + * 0 - device is not configured. + */ +#define USB_STS_CFGSTS_MASK BIT(0) +#define USB_STS_CFGSTS(p) ((p) & USB_STS_CFGSTS_MASK) +/* + * On-chip memory overflow. + * 0 - On-chip memory status OK. + * 1 - On-chip memory overflow. + */ +#define USB_STS_OV_MASK BIT(1) +#define USB_STS_OV(p) ((p) & USB_STS_OV_MASK) +/* + * SuperSpeed connection status. + * 0 - USB in SuperSpeed mode disconnected. + * 1 - USB in SuperSpeed mode connected. + */ +#define USB_STS_USB3CONS_MASK BIT(2) +#define USB_STS_USB3CONS(p) ((p) & USB_STS_USB3CONS_MASK) +/* + * DMA transfer configuration status. + * 0 - single request. + * 1 - multiple TRB chain + */ +#define USB_STS_DTRANS_MASK BIT(3) +#define USB_STS_DTRANS(p) ((p) & USB_STS_DTRANS_MASK) +/* + * Device speed. + * 0 - Undefined (value after reset). + * 1 - Low speed + * 2 - Full speed + * 3 - High speed + * 4 - Super speed + */ +#define USB_STS_USBSPEED_MASK GENMASK(6, 4) +#define USB_STS_USBSPEED(p) (((p) & USB_STS_USBSPEED_MASK) >> 4) +#define USB_STS_LS (0x1 << 4) +#define USB_STS_FS (0x2 << 4) +#define USB_STS_HS (0x3 << 4) +#define USB_STS_SS (0x4 << 4) +#define DEV_UNDEFSPEED(p) (((p) & USB_STS_USBSPEED_MASK) == (0x0 << 4)) +#define DEV_LOWSPEED(p) (((p) & USB_STS_USBSPEED_MASK) == USB_STS_LS) +#define DEV_FULLSPEED(p) (((p) & USB_STS_USBSPEED_MASK) == USB_STS_FS) +#define DEV_HIGHSPEED(p) (((p) & USB_STS_USBSPEED_MASK) == USB_STS_HS) +#define DEV_SUPERSPEED(p) (((p) & USB_STS_USBSPEED_MASK) == USB_STS_SS) +/* + * Endianness for SFR access. + * 0 - Little Endian order (default after hardware reset). + * 1 - Big Endian order + */ +#define USB_STS_ENDIAN_MASK BIT(7) +#define USB_STS_ENDIAN(p) ((p) & USB_STS_ENDIAN_MASK) +/* + * HS/FS clock turn-off status. + * 0 - hsfs clock is always on. + * 1 - hsfs clock turn-off in L2 (HS/FS mode) is enabled + * (default after hardware reset). + */ +#define USB_STS_CLK2OFF_MASK BIT(8) +#define USB_STS_CLK2OFF(p) ((p) & USB_STS_CLK2OFF_MASK) +/* + * PCLK clock turn-off status. + * 0 - pclk clock is always on. + * 1 - pclk clock turn-off in U3 (SS mode) is enabled + * (default after hardware reset). + */ +#define USB_STS_CLK3OFF_MASK BIT(9) +#define USB_STS_CLK3OFF(p) ((p) & USB_STS_CLK3OFF_MASK) +/* + * Controller in reset state. + * 0 - Internal reset is active. + * 1 - Internal reset is not active and controller is fully operational. + */ +#define USB_STS_IN_RST_MASK BIT(10) +#define USB_STS_IN_RST(p) ((p) & USB_STS_IN_RST_MASK) +/* + * Device enable Status. + * 0 - USB device is disabled (VBUS input is disconnected from internal logic). + * 1 - USB device is enabled (VBUS input is connected to the internal logic). + */ +#define USB_STS_DEVS_MASK BIT(14) +#define USB_STS_DEVS(p) ((p) & USB_STS_DEVS_MASK) +/* + * DAddress statuss. + * 0 - USB device is default state. + * 1 - USB device is at least in address state. + */ +#define USB_STS_ADDRESSED_MASK BIT(15) +#define USB_STS_ADDRESSED(p) ((p) & USB_STS_ADDRESSED_MASK) +/* + * L1 LPM state enable status (used in HS/FS mode). + * 0 - Entering to L1 LPM state disabled. + * 1 - Entering to L1 LPM state enabled. + */ +#define USB_STS_L1ENS_MASK BIT(16) +#define USB_STS_L1ENS(p) ((p) & USB_STS_L1ENS_MASK) +/* + * Internal VBUS connection status (used both in HS/FS and SS mode). + * 0 - internal VBUS is not detected. + * 1 - internal VBUS is detected. + */ +#define USB_STS_VBUSS_MASK BIT(17) +#define USB_STS_VBUSS(p) ((p) & USB_STS_VBUSS_MASK) +/* + * HS/FS LPM state (used in FS/HS mode). + * 0 - L0 State + * 1 - L1 State + * 2 - L2 State + * 3 - L3 State + */ +#define USB_STS_LPMST_MASK GENMASK(19, 18) +#define DEV_L0_STATE(p) (((p) & USB_STS_LPMST_MASK) == (0x0 << 18)) +#define DEV_L1_STATE(p) (((p) & USB_STS_LPMST_MASK) == (0x1 << 18)) +#define DEV_L2_STATE(p) (((p) & USB_STS_LPMST_MASK) == (0x2 << 18)) +#define DEV_L3_STATE(p) (((p) & USB_STS_LPMST_MASK) == (0x3 << 18)) +/* + * Disable HS status (used in FS/HS mode). + * 0 - the disconnect bit for HS/FS mode is set . + * 1 - the disconnect bit for HS/FS mode is not set. + */ +#define USB_STS_USB2CONS_MASK BIT(20) +#define USB_STS_USB2CONS(p) ((p) & USB_STS_USB2CONS_MASK) +/* + * HS/FS mode connection status (used in FS/HS mode). + * 0 - High Speed operations in USB2.0 (FS/HS) mode not disabled. + * 1 - High Speed operations in USB2.0 (FS/HS). + */ +#define USB_STS_DISABLE_HS_MASK BIT(21) +#define USB_STS_DISABLE_HS(p) ((p) & USB_STS_DISABLE_HS_MASK) +/* + * U1 state enable status (used in SS mode). + * 0 - Entering to U1 state disabled. + * 1 - Entering to U1 state enabled. + */ +#define USB_STS_U1ENS_MASK BIT(24) +#define USB_STS_U1ENS(p) ((p) & USB_STS_U1ENS_MASK) +/* + * U2 state enable status (used in SS mode). + * 0 - Entering to U2 state disabled. + * 1 - Entering to U2 state enabled. + */ +#define USB_STS_U2ENS_MASK BIT(25) +#define USB_STS_U2ENS(p) ((p) & USB_STS_U2ENS_MASK) +/* + * SuperSpeed Link LTSSM state. This field reflects USBSS-DEV current + * SuperSpeed link state + */ +#define USB_STS_LST_MASK GENMASK(29, 26) +#define DEV_LST_U0 (((p) & USB_STS_LST_MASK) == (0x0 << 26)) +#define DEV_LST_U1 (((p) & USB_STS_LST_MASK) == (0x1 << 26)) +#define DEV_LST_U2 (((p) & USB_STS_LST_MASK) == (0x2 << 26)) +#define DEV_LST_U3 (((p) & USB_STS_LST_MASK) == (0x3 << 26)) +#define DEV_LST_DISABLED (((p) & USB_STS_LST_MASK) == (0x4 << 26)) +#define DEV_LST_RXDETECT (((p) & USB_STS_LST_MASK) == (0x5 << 26)) +#define DEV_LST_INACTIVE (((p) & USB_STS_LST_MASK) == (0x6 << 26)) +#define DEV_LST_POLLING (((p) & USB_STS_LST_MASK) == (0x7 << 26)) +#define DEV_LST_RECOVERY (((p) & USB_STS_LST_MASK) == (0x8 << 26)) +#define DEV_LST_HOT_RESET (((p) & USB_STS_LST_MASK) == (0x9 << 26)) +#define DEV_LST_COMP_MODE (((p) & USB_STS_LST_MASK) == (0xa << 26)) +#define DEV_LST_LB_STATE (((p) & USB_STS_LST_MASK) == (0xb << 26)) +/* + * DMA clock turn-off status. + * 0 - DMA clock is always on (default after hardware reset). + * 1 - DMA clock turn-off in U1, U2 and U3 (SS mode) is enabled. + */ +#define USB_STS_DMAOFF_MASK BIT(30) +#define USB_STS_DMAOFF(p) ((p) & USB_STS_DMAOFF_MASK) +/* + * SFR Endian statuss. + * 0 - Little Endian order (default after hardware reset). + * 1 - Big Endian order. + */ +#define USB_STS_ENDIAN2_MASK BIT(31) +#define USB_STS_ENDIAN2(p) ((p) & USB_STS_ENDIAN2_MASK) + +/* USB_CMD - bitmasks */ +/* Set Function Address */ +#define USB_CMD_SET_ADDR BIT(0) +/* + * Function Address This field is saved to the device only when the field + * SET_ADDR is set '1 ' during write to USB_CMD register. + * Software is responsible for entering the address of the device during + * SET_ADDRESS request service. This field should be set immediately after + * the SETUP packet is decoded, and prior to confirmation of the status phase + */ +#define USB_CMD_FADDR_MASK GENMASK(7, 1) +#define USB_CMD_FADDR(p) (((p) << 1) & USB_CMD_FADDR_MASK) +/* Send Function Wake Device Notification TP (used only in SS mode). */ +#define USB_CMD_SDNFW BIT(8) +/* Set Test Mode (used only in HS/FS mode). */ +#define USB_CMD_STMODE BIT(9) +/* Test mode selector (used only in HS/FS mode) */ +#define USB_STS_TMODE_SEL_MASK GENMASK(11, 10) +#define USB_STS_TMODE_SEL(p) (((p) << 10) & USB_STS_TMODE_SEL_MASK) +/* + * Send Latency Tolerance Message Device Notification TP (used only + * in SS mode). + */ +#define USB_CMD_SDNLTM BIT(12) +/* Send Custom Transaction Packet (used only in SS mode) */ +#define USB_CMD_SPKT BIT(13) +/*Device Notification 'Function Wake' - Interface value (only in SS mode. */ +#define USB_CMD_DNFW_INT_MASK GENMASK(23, 16) +#define USB_STS_DNFW_INT(p) (((p) << 16) & USB_CMD_DNFW_INT_MASK) +/* + * Device Notification 'Latency Tolerance Message' -373 BELT value [7:0] + * (used only in SS mode). + */ +#define USB_CMD_DNLTM_BELT_MASK GENMASK(27, 16) +#define USB_STS_DNLTM_BELT(p) (((p) << 16) & USB_CMD_DNLTM_BELT_MASK) + +/* USB_ITPN - bitmasks */ +/* + * ITP(SS) / SOF (HS/FS) number + * In SS mode this field represent number of last ITP received from host. + * In HS/FS mode this field represent number of last SOF received from host. + */ +#define USB_ITPN_MASK GENMASK(13, 0) +#define USB_ITPN(p) ((p) & USB_ITPN_MASK) + +/* USB_LPM - bitmasks */ +/* Host Initiated Resume Duration. */ +#define USB_LPM_HIRD_MASK GENMASK(3, 0) +#define USB_LPM_HIRD(p) ((p) & USB_LPM_HIRD_MASK) +/* Remote Wakeup Enable (bRemoteWake). */ +#define USB_LPM_BRW BIT(4) + +/* USB_IEN - bitmasks */ +/* SS connection interrupt enable */ +#define USB_IEN_CONIEN BIT(0) +/* SS disconnection interrupt enable. */ +#define USB_IEN_DISIEN BIT(1) +/* USB SS warm reset interrupt enable. */ +#define USB_IEN_UWRESIEN BIT(2) +/* USB SS hot reset interrupt enable */ +#define USB_IEN_UHRESIEN BIT(3) +/* SS link U3 state enter interrupt enable (suspend).*/ +#define USB_IEN_U3ENTIEN BIT(4) +/* SS link U3 state exit interrupt enable (wakeup). */ +#define USB_IEN_U3EXTIEN BIT(5) +/* SS link U2 state enter interrupt enable.*/ +#define USB_IEN_U2ENTIEN BIT(6) +/* SS link U2 state exit interrupt enable.*/ +#define USB_IEN_U2EXTIEN BIT(7) +/* SS link U1 state enter interrupt enable.*/ +#define USB_IEN_U1ENTIEN BIT(8) +/* SS link U1 state exit interrupt enable.*/ +#define USB_IEN_U1EXTIEN BIT(9) +/* ITP/SOF packet detected interrupt enable.*/ +#define USB_IEN_ITPIEN BIT(10) +/* Wakeup interrupt enable.*/ +#define USB_IEN_WAKEIEN BIT(11) +/* Send Custom Packet interrupt enable.*/ +#define USB_IEN_SPKTIEN BIT(12) +/* HS/FS mode connection interrupt enable.*/ +#define USB_IEN_CON2IEN BIT(16) +/* HS/FS mode disconnection interrupt enable.*/ +#define USB_IEN_DIS2IEN BIT(17) +/* USB reset (HS/FS mode) interrupt enable.*/ +#define USB_IEN_U2RESIEN BIT(18) +/* LPM L2 state enter interrupt enable.*/ +#define USB_IEN_L2ENTIEN BIT(20) +/* LPM L2 state exit interrupt enable.*/ +#define USB_IEN_L2EXTIEN BIT(21) +/* LPM L1 state enter interrupt enable.*/ +#define USB_IEN_L1ENTIEN BIT(24) +/* LPM L1 state exit interrupt enable.*/ +#define USB_IEN_L1EXTIEN BIT(25) +/* Configuration reset interrupt enable.*/ +#define USB_IEN_CFGRESIEN BIT(26) +/* Start of the USB SS warm reset interrupt enable.*/ +#define USB_IEN_UWRESSIEN BIT(28) +/* End of the USB SS warm reset interrupt enable.*/ +#define USB_IEN_UWRESEIEN BIT(29) + +#define USB_IEN_INIT (USB_IEN_U2RESIEN | USB_ISTS_DIS2I | USB_IEN_CON2IEN \ + | USB_IEN_UHRESIEN | USB_IEN_UWRESIEN | USB_IEN_DISIEN \ + | USB_IEN_CONIEN | USB_IEN_U3EXTIEN | USB_IEN_L2ENTIEN \ + | USB_IEN_L2EXTIEN) + +/* USB_ISTS - bitmasks */ +/* SS Connection detected. */ +#define USB_ISTS_CONI BIT(0) +/* SS Disconnection detected. */ +#define USB_ISTS_DISI BIT(1) +/* UUSB warm reset detectede. */ +#define USB_ISTS_UWRESI BIT(2) +/* USB hot reset detected. */ +#define USB_ISTS_UHRESI BIT(3) +/* U3 link state enter detected (suspend).*/ +#define USB_ISTS_U3ENTI BIT(4) +/* U3 link state exit detected (wakeup). */ +#define USB_ISTS_U3EXTI BIT(5) +/* U2 link state enter detected.*/ +#define USB_ISTS_U2ENTI BIT(6) +/* U2 link state exit detected.*/ +#define USB_ISTS_U2EXTI BIT(7) +/* U1 link state enter detected.*/ +#define USB_ISTS_U1ENTI BIT(8) +/* U1 link state exit detected.*/ +#define USB_ISTS_U1EXTI BIT(9) +/* ITP/SOF packet detected.*/ +#define USB_ISTS_ITPI BIT(10) +/* Wakeup detected.*/ +#define USB_ISTS_WAKEI BIT(11) +/* Send Custom Packet detected.*/ +#define USB_ISTS_SPKTI BIT(12) +/* HS/FS mode connection detected.*/ +#define USB_ISTS_CON2I BIT(16) +/* HS/FS mode disconnection detected.*/ +#define USB_ISTS_DIS2I BIT(17) +/* USB reset (HS/FS mode) detected.*/ +#define USB_ISTS_U2RESI BIT(18) +/* LPM L2 state enter detected.*/ +#define USB_ISTS_L2ENTI BIT(20) +/* LPM L2 state exit detected.*/ +#define USB_ISTS_L2EXTI BIT(21) +/* LPM L1 state enter detected.*/ +#define USB_ISTS_L1ENTI BIT(24) +/* LPM L1 state exit detected.*/ +#define USB_ISTS_L1EXTI BIT(25) +/* USB configuration reset detected.*/ +#define USB_ISTS_CFGRESI BIT(26) +/* Start of the USB warm reset detected.*/ +#define USB_ISTS_UWRESSI BIT(28) +/* End of the USB warm reset detected.*/ +#define USB_ISTS_UWRESEI BIT(29) + +/* USB_SEL - bitmasks */ +#define EP_SEL_EPNO_MASK GENMASK(3, 0) +/* Endpoint number. */ +#define EP_SEL_EPNO(p) ((p) & EP_SEL_EPNO_MASK) +/* Endpoint direction bit - 0 - OUT, 1 - IN. */ +#define EP_SEL_DIR BIT(7) + +#define select_ep_in(nr) (EP_SEL_EPNO(p) | EP_SEL_DIR) +#define select_ep_out (EP_SEL_EPNO(p)) + +/* EP_TRADDR - bitmasks */ +/* Transfer Ring address. */ +#define EP_TRADDR_TRADDR(p) ((p)) + +/* EP_CFG - bitmasks */ +/* Endpoint enable */ +#define EP_CFG_ENABLE BIT(0) +/* + * Endpoint type. + * 1 - isochronous + * 2 - bulk + * 3 - interrupt + */ +#define EP_CFG_EPTYPE_MASK GENMASK(2, 1) +#define EP_CFG_EPTYPE(p) (((p) << 1) & EP_CFG_EPTYPE_MASK) +/* Stream support enable (only in SS mode). */ +#define EP_CFG_STREAM_EN BIT(3) +/* TDL check (only in SS mode for BULK EP). */ +#define EP_CFG_TDL_CHK BIT(4) +/* SID check (only in SS mode for BULK OUT EP). */ +#define EP_CFG_SID_CHK BIT(5) +/* DMA transfer endianness. */ +#define EP_CFG_EPENDIAN BIT(7) +/* Max burst size (used only in SS mode). */ +#define EP_CFG_MAXBURST_MASK GENMASK(11, 8) +#define EP_CFG_MAXBURST(p) (((p) << 8) & EP_CFG_MAXBURST_MASK) +/* ISO max burst. */ +#define EP_CFG_MULT_MASK GENMASK(15, 14) +#define EP_CFG_MULT(p) (((p) << 14) & EP_CFG_MULT) +/* ISO max burst. */ +#define EP_CFG_MAXPKTSIZE_MASK GENMASK(26, 16) +#define EP_CFG_MAXPKTSIZE(p) (((p) << 16) & EP_CFG_MAXPKTSIZE_MASK) +/* Max number of buffered packets. */ +#define EP_CFG_BUFFERING_MASK GENMASK(31, 27) +#define EP_CFG_BUFFERING(p) (((p) << 27) & EP_CFG_BUFFERING_MASK) + +/* EP_CMD - bitmasks */ +/* Endpoint reset. */ +#define EP_CMD_EPRST BIT(0) +/* Endpoint STALL set. */ +#define EP_CMD_SSTALL BIT(1) +/* Endpoint STALL clear. */ +#define EP_CMD_CSTALL BIT(2) +/* Send ERDY TP. */ +#define EP_CMD_ERDY BIT(3) +/* Request complete. */ +#define EP_CMD_REQ_CMPL BIT(5) +/* Transfer descriptor ready. */ +#define EP_CMD_DRDY BIT(6) +/* Data flush. */ +#define EP_CMD_DFLUSH BIT(7) +/* + * Transfer Descriptor Length write (used only for Bulk Stream capable + * endpoints in SS mode). + */ +#define EP_CMD_STDL BIT(8) +/* Transfer Descriptor Length (used only in SS mode for bulk endpoints). */ +#define EP_CMD_TDL_MASK GENMASK(15, 9) +#define EP_CMD_TDL(p) (((p) << 9) & EP_CMD_TDL_MASK) +/* ERDY Stream ID value (used in SS mode). */ +#define EP_CMD_ERDY_SID_MASK GENMASK(31, 16) +#define EP_CMD_ERDY_SID(p) (((p) << 16) & EP_CMD_SID_MASK) + +/* EP_STS - bitmasks */ +/* Setup transfer complete. */ +#define EP_STS_SETUP BIT(0) +/* Endpoint STALL status. */ +#define EP_STS_STALL(p) ((p) & BIT(1)) +/* Interrupt On Complete. */ +#define EP_STS_IOC BIT(2) +/* Interrupt on Short Packet. */ +#define EP_STS_ISP BIT(3) +/* Transfer descriptor missing. */ +#define EP_STS_DESCMIS BIT(4) +/* Stream Rejected (used only in SS mode) */ +#define EP_STS_STREAMR BIT(5) +/* EXIT from MOVE DATA State (used only for stream transfers in SS mode). */ +#define EP_STS_MD_EXIT BIT(6) +/* TRB error. */ +#define EP_STS_TRBERR BIT(7) +/* Not ready (used only in SS mode). */ +#define EP_STS_NRDY BIT(8) +/* DMA busy. */ +#define EP_STS_DBUSY(p) ((p) & BIT(9)) +/* Endpoint Buffer Empty */ +#define EP_STS_BUFFEMPTY(p) ((p) & BIT(10)) +/* Current Cycle Status */ +#define EP_STS_CCS(p) ((p) & BIT(11)) +/* Prime (used only in SS mode. */ +#define EP_STS_PRIME BIT(12) +/* Stream error (used only in SS mode). */ +#define EP_STS_SIDERR BIT(13) +/* OUT size mismatch. */ +#define EP_STS_OUTSMM BIT(14) +/* ISO transmission error. */ +#define EP_STS_ISOERR BIT(15) +/* Host Packet Pending (only for SS mode). */ +#define EP_STS_HOSTPP(p) ((p) & BIT(16)) +/* Stream Protocol State Machine State (only for Bulk stream endpoints). */ +#define EP_STS_SPSMST_MASK GENMASK(18, 17) +#define EP_STS_SPSMST_DISABLED(p) (((p) & EP_STS_SPSMST_MASK) >> 17) +#define EP_STS_SPSMST_IDLE(p) (((p) & EP_STS_SPSMST_MASK) >> 17) +#define EP_STS_SPSMST_START_STREAM(p) (((p) & EP_STS_SPSMST_MASK) >> 17) +#define EP_STS_SPSMST_MOVE_DATA(p) (((p) & EP_STS_SPSMST_MASK) >> 17) +/* Interrupt On Transfer complete. */ +#define EP_STS_IOT BIT(19) +/* OUT queue endpoint number. */ +#define EP_STS_OUTQ_NO_MASK GENMASK(27, 24) +#define EP_STS_OUTQ_NO(p) (((p) & EP_STS_OUTQ_NO_MASK) >> 24) +/* OUT queue valid flag. */ +#define EP_STS_OUTQ_VAL_MASK BIT(28) +#define EP_STS_OUTQ_VAL(p) ((p) & EP_STS_OUTQ_VAL_MASK) +/* SETUP WAIT. */ +#define EP_STS_STPWAIT BIT(31) + +/* EP_STS_SID - bitmasks */ +/* Stream ID (used only in SS mode). */ +#define EP_STS_SID_MASK GENMASK(15, 0) +#define EP_STS_SID(p) ((p) & EP_STS_SID_MASK) + +/* EP_STS_EN - bitmasks */ +/* SETUP interrupt enable. */ +#define EP_STS_EN_SETUPEN BIT(0) +/* OUT transfer missing descriptor enable. */ +#define EP_STS_EN_DESCMISEN BIT(4) +/* Stream Rejected enable. */ +#define EP_STS_EN_STREAMREN BIT(5) +/* Move Data Exit enable.*/ +#define EP_STS_EN_MD_EXITEN BIT(6) +/* TRB enable. */ +#define EP_STS_EN_TRBERREN BIT(7) +/* NRDY enable. */ +#define EP_STS_EN_NRDYEN BIT(8) +/* Prime enable. */ +#define EP_STS_EN_PRIMEEEN BIT(12) +/* Stream error enable. */ +#define EP_STS_EN_SIDERREN BIT(13) +/* OUT size mismatch enable. */ +#define EP_STS_EN_OUTSMMEN BIT(14) +/* ISO transmission error enable. */ +#define EP_STS_EN_ISOERREN BIT(15) +/* Interrupt on Transmission complete enable. */ +#define EP_STS_EN_IOTEN BIT(19) +/* Setup Wait interrupt enable. */ +#define EP_STS_EN_STPWAITEN BIT(31) + +/* DRBL- bitmasks */ +#define DB_VALUE_BY_INDEX(index) (1 << (index)) +#define DB_VALUE_EP0_OUT BIT(0) +#define DB_VALUE_EP0_IN BIT(16) + +/* EP_IEN - bitmasks */ +#define EP_IEN(index) (1 << (index)) +#define EP_IEN_EP_OUT0 BIT(0) +#define EP_IEN_EP_IN0 BIT(16) + +/* EP_ISTS - bitmasks */ +#define EP_ISTS(index) (1 << (index)) +#define EP_ISTS_EP_OUT0 BIT(0) +#define EP_ISTS_EP_IN0 BIT(16) + +/* EP_PWR- bitmasks */ +/*Power Shut Off capability enable*/ +#define PUSB_PWR_PSO_EN BIT(0) +/*Power Shut Off capability disable*/ +#define PUSB_PWR_PSO_DS BIT(1) +/* + * Enables turning-off Reference Clock. + * This bit is optional and implemented only when support for OTG is + * implemented (indicated by OTG_READY bit set to '1'). + */ +#define PUSB_PWR_STB_CLK_SWITCH_EN BIT(8) +/* + * Status bit indicating that operation required by STB_CLK_SWITCH_EN write + * is completed + */ +#define PUSB_PWR_STB_CLK_SWITCH_DONE BIT(9) +/* This bit informs if Fast Registers Access is enabled. */ +#define PUSB_PWR_FST_REG_ACCESS_STAT BIT(30) +/* Fast Registers Access Enable. */ +#define PUSB_PWR_FST_REG_ACCESS BIT(31) + +/* USB_CAP1- bitmasks */ +/* + * SFR Interface type + * These field reflects type of SFR interface implemented: + * 0x0 - OCP + * 0x1 - AHB, + * 0x2 - PLB + * 0x3 - AXI + * 0x4-0xF - reserved + */ +#define USB_CAP1_SFR_TYPE_MASK GENMASK(3, 0) +#define DEV_SFR_TYPE_OCP(p) (((p) & USB_CAP1_SFR_TYPE_MASK) == 0x0) +#define DEV_SFR_TYPE_AHB(p) (((p) & USB_CAP1_SFR_TYPE_MASK) == 0x1) +#define DEV_SFR_TYPE_PLB(p) (((p) & USB_CAP1_SFR_TYPE_MASK) == 0x2) +#define DEV_SFR_TYPE_AXI(p) (((p) & USB_CAP1_SFR_TYPE_MASK) == 0x3) +/* + * SFR Interface width + * These field reflects width of SFR interface implemented: + * 0x0 - 8 bit interface, + * 0x1 - 16 bit interface, + * 0x2 - 32 bit interface + * 0x3 - 64 bit interface + * 0x4-0xF - reserved + */ +#define USB_CAP1_SFR_WIDTH_MASK GENMASK(7, 4) +#define DEV_SFR_WIDTH_8(p) (((p) & USB_CAP1_SFR_WIDTH_MASK) == (0x0 << 4)) +#define DEV_SFR_WIDTH_16(p) (((p) & USB_CAP1_SFR_WIDTH_MASK) == (0x1 << 4)) +#define DEV_SFR_WIDTH_32(p) (((p) & USB_CAP1_SFR_WIDTH_MASK) == (0x2 << 4)) +#define DEV_SFR_WIDTH_64(p) (((p) & USB_CAP1_SFR_WIDTH_MASK) == (0x3 << 4)) +/* + * DMA Interface type + * These field reflects type of DMA interface implemented: + * 0x0 - OCP + * 0x1 - AHB, + * 0x2 - PLB + * 0x3 - AXI + * 0x4-0xF - reserved + */ +#define USB_CAP1_DMA_TYPE_MASK GENMASK(11, 8) +#define DEV_DMA_TYPE_OCP(p) (((p) & USB_CAP1_DMA_TYPE_MASK) == (0x0 << 8)) +#define DEV_DMA_TYPE_AHB(p) (((p) & USB_CAP1_DMA_TYPE_MASK) == (0x1 << 8)) +#define DEV_DMA_TYPE_PLB(p) (((p) & USB_CAP1_DMA_TYPE_MASK) == (0x2 << 8)) +#define DEV_DMA_TYPE_AXI(p) (((p) & USB_CAP1_DMA_TYPE_MASK) == (0x3 << 8)) +/* + * DMA Interface width + * These field reflects width of DMA interface implemented: + * 0x0 - reserved, + * 0x1 - reserved, + * 0x2 - 32 bit interface + * 0x3 - 64 bit interface + * 0x4-0xF - reserved + */ +#define USB_CAP1_DMA_WIDTH_MASK GENMASK(15, 12) +#define DEV_DMA_WIDTH_32(p) (((p) & USB_CAP1_DMA_WIDTH_MASK) == (0x2 << 12)) +#define DEV_DMA_WIDTH_64(p) (((p) & USB_CAP1_DMA_WIDTH_MASK) == (0x3 << 12)) +/* + * USB3 PHY Interface type + * These field reflects type of USB3 PHY interface implemented: + * 0x0 - USB PIPE, + * 0x1 - RMMI, + * 0x2-0xF - reserved + */ +#define USB_CAP1_U3PHY_TYPE_MASK GENMASK(19, 16) +#define DEV_U3PHY_PIPE(p) (((p) & USB_CAP1_U3PHY_TYPE_MASK) == (0x0 << 16)) +#define DEV_U3PHY_RMMI(p) (((p) & USB_CAP1_U3PHY_TYPE_MASK) == (0x1 << 16)) +/* + * USB3 PHY Interface width + * These field reflects width of USB3 PHY interface implemented: + * 0x0 - 8 bit PIPE interface, + * 0x1 - 16 bit PIPE interface, + * 0x2 - 32 bit PIPE interface, + * 0x3 - 64 bit PIPE interface + * 0x4-0xF - reserved + * Note: When SSIC interface is implemented this field shows the width of + * internal PIPE interface. The RMMI interface is always 20bit wide. + */ +#define USB_CAP1_U3PHY_WIDTH_MASK GENMASK(23, 20) +#define DEV_U3PHY_WIDTH_8(p) \ + (((p) & USB_CAP1_U3PHY_WIDTH_MASK) == (0x0 << 20)) +#define DEV_U3PHY_WIDTH_16(p) \ + (((p) & USB_CAP1_U3PHY_WIDTH_MASK) == (0x1 << 16)) +#define DEV_U3PHY_WIDTH_32(p) \ + (((p) & USB_CAP1_U3PHY_WIDTH_MASK) == (0x2 << 20)) +#define DEV_U3PHY_WIDTH_64(p) \ + (((p) & USB_CAP1_U3PHY_WIDTH_MASK) == (0x3 << 16)) + +/* + * USB2 PHY Interface enable + * These field informs if USB2 PHY interface is implemented: + * 0x0 - interface NOT implemented, + * 0x1 - interface implemented + */ +#define USB_CAP1_U2PHY_EN(p) ((p) & BIT(24)) +/* + * USB2 PHY Interface type + * These field reflects type of USB2 PHY interface implemented: + * 0x0 - UTMI, + * 0x1 - ULPI + */ +#define DEV_U2PHY_ULPI(p) ((p) & BIT(25)) +/* + * USB2 PHY Interface width + * These field reflects width of USB2 PHY interface implemented: + * 0x0 - 8 bit interface, + * 0x1 - 16 bit interface, + * Note: The ULPI interface is always 8bit wide. + */ +#define DEV_U2PHY_WIDTH_16(p) ((p) & BIT(26)) +/* + * OTG Ready + * 0x0 - pure device mode + * 0x1 - some features and ports for CDNS USB OTG controller are implemented. + */ +#define USB_CAP1_OTG_READY(p) ((p) & BIT(27)) + +/* USB_CAP2- bitmasks */ +/* + * The actual size of the connected On-chip RAM memory in kB: + * - 0 means 256 kB (max supported mem size) + * - value other than 0 reflects the mem size in kB + */ +#define USB_CAP2_ACTUAL_MEM_SIZE(p) ((p) & GENMASK(7, 0)) +/* + * Max supported mem size + * These field reflects width of on-chip RAM address bus width, + * which determines max supported mem size: + * 0x0-0x7 - reserved, + * 0x8 - support for 4kB mem, + * 0x9 - support for 8kB mem, + * 0xA - support for 16kB mem, + * 0xB - support for 32kB mem, + * 0xC - support for 64kB mem, + * 0xD - support for 128kB mem, + * 0xE - support for 256kB mem, + * 0xF - reserved + */ +#define USB_CAP2_MAX_MEM_SIZE(p) ((p) & GENMASK(11, 8)) + +/* USB_CAP3- bitmasks */ +#define EP_IS_IMPLEMENTED(reg, index) ((reg) & (1 << (index))) + +/* USB_CAP4- bitmasks */ +#define EP_SUPPORT_ISO(reg, index) ((reg) & (1 << (index))) + +/* USB_CAP5- bitmasks */ +#define EP_SUPPORT_STREAM(reg, index) ((reg) & (1 << (index))) + +/* USB_CAP6- bitmasks */ +/* The USBSS-DEV Controller Internal build number. */ +#define GET_DEV_VERSION__INTERNAL_NUMBER(p) ((p) & GENMASK(7, 0)) +/* The USBSS-DEV Controller version number. */ +#define GET_DEV_VERSION(p) ((p) & GENMASK(31, 8)) + +/* DBG_LINK1- bitmasks */ +/* + * LFPS_MIN_DET_U1_EXIT value This parameter configures the minimum + * time required for decoding the received LFPS as an LFPS.U1_Exit. + */ +#define DBG_LINK1_LFPS_MIN_DET_U1_EXIT(p) ((p) & GENMASK(7, 0)) +/* + * LFPS_MIN_GEN_U1_EXIT value This parameter configures the minimum time for + * phytxelecidle deassertion when LFPS.U1_Exit + */ +#define DBG_LINK1_LFPS_MIN_GEN_U1_EXIT(p) (((p) << 8) & GENMASK(15, 8)) +/* + * RXDET_BREAK_DIS value This parameter configures terminating the Far-end + * Receiver termination detection sequence: + * 0: it is possible that USBSS_DEV will terminate Farend receiver + * termination detection sequence + * 1: USBSS_DEV will not terminate Far-end receiver termination + * detection sequence + */ +#define DBG_LINK1_RXDET_BREAK_DIS BIT(16) +/* LFPS_GEN_PING value This parameter configures the LFPS.Ping generation */ +#define DBG_LINK1_LFPS_GEN_PING(p) (((p) << 17) & GENMASK(21, 17)) +/* + * Set the LFPS_MIN_DET_U1_EXIT value Writing '1' to this bit writes the + * LFPS_MIN_DET_U1_EXIT field value to the device. This bit is automatically + * cleared. Writing '0' has no effect + */ +#define DBG_LINK1_LFPS_MIN_DET_U1_EXIT_SET BIT(24) +/* + * Set the LFPS_MIN_GEN_U1_EXIT value. Writing '1' to this bit writes the + * LFPS_MIN_GEN_U1_EXIT field value to the device. This bit is automatically + * cleared. Writing '0' has no effect + */ +#define DBG_LINK1_LFPS_MIN_GEN_U1_EXIT_SET BIT(25) +/* + * Set the RXDET_BREAK_DIS value Writing '1' to this bit writes + * the RXDET_BREAK_DIS field value to the device. This bit is automatically + * cleared. Writing '0' has no effect + */ +#define DBG_LINK1_RXDET_BREAK_DIS_SET BIT(26) +/* + * Set the LFPS_GEN_PING_SET value Writing '1' to this bit writes + * the LFPS_GEN_PING field value to the device. This bit is automatically + * cleared. Writing '0' has no effect." + */ +#define DBG_LINK1_LFPS_GEN_PING_SET BIT(27) + +#define gadget_to_cdns3_device(g) (container_of(g, struct cdns3_device, gadget)) + +#define ep_to_cdns3_ep(ep) (container_of(ep, struct cdns3_endpoint, endpoint)) + +/*-------------------------------------------------------------------------*/ +/* + * USBSS-DEV DMA interface . + */ +#define TRBS_PER_SEGMENT 32 + +struct cdns3_trb { + __le32 buffer; + __le32 length; + __le32 control; +}; + +#define TRB_SIZE (sizeof(struct cdns3_trb)) +#define TRB_RIGN_SIZE (TRB_SIZE * TRBS_PER_SEGMENT) + +/* TRB bit mask */ +#define TRB_TYPE_BITMASK GENMASK(15, 10) +#define TRB_TYPE(p) ((p) << 10) +#define TRB_FIELD_TO_TYPE(p) (((p) & TRB_TYPE_BITMASK) >> 10) + +/* TRB type IDs */ +/* bulk, interrupt, isoc , and control data stage */ +#define TRB_NORMAL 1 +/* TRB for linking ring segments */ +#define TRB_LINK 6 + +/* Cycle bit - indicates TRB ownership by driver or hw*/ +#define TRB_CYCLE BIT(0) +/* + * When set to '1', the device will toggle its interpretation of the Cycle bit + */ +#define TRB_TOGGLE BIT(1) + +/* Interrupt on short packet*/ +#define TRB_ISP BIT(2) +/*Setting this bit enables FIFO DMA operation mode*/ +#define TRB_FIFO_MODE BIT(3) +/* Set PCIe no snoop attribute */ +#define TRB_CHAIN BIT(4) +/* Interrupt on completion */ +#define TRB_IOC BIT(5) + +/* stream ID bitmasks. */ +#define TRB_STREAM_ID(p) ((p) & GENMASK(31, 16)) + +/* transfer_len bitmasks. */ +#define TRB_LEN(p) ((p) & GENMASK(16, 0)) + +/* transfer_len bitmasks - bits 31:24 */ +#define TRB_BURST_LEN(p) ((p) & GENMASK(31, 24)) + +/* Data buffer pointer bitmasks*/ +#define TRB_BUFFER(p) ((p) & GENMASK(31, 0)) + +/*-------------------------------------------------------------------------*/ +/* Driver numeric constants */ + +#define DEVICE_ADDRESS_MAX 127 + +/* Endpoint init values */ +#define ENDPOINT_MAX_PACKET_LIMIT 1024 +#define ENDPOINT_MAX_STREAMS 15 + +#define ENDPOINT0_MAX_PACKET_LIMIT 512 + +/* All endpoints except EP0 */ +#define USB_SS_ENDPOINTS_MAX_COUNT 30 + +#define ADDR_MODULO_8 8 + +#define ENDPOINT_ZLP_BUF_SIZE 1024 + +/*-------------------------------------------------------------------------*/ +/* 18KB is the total size, and 2KB is used for EP0 and configuration */ +#define CDNS3_ONCHIP_BUF_SIZE 16 /* KB */ +#define CDNS3_EP_BUF_SIZE 2 /* KB */ +#define CDNS3_UNALIGNED_BUF_SIZE 16384 /* Bytes */ +/*-------------------------------------------------------------------------*/ +/* Used structs */ + +struct cdns3_device; + +struct cdns3_endpoint { + struct usb_ep endpoint; + struct list_head request_list; + struct list_head ep_match_pending_list; + + struct cdns3_trb *trb_pool; + dma_addr_t trb_pool_dma; + + struct cdns3_device *cdns3_dev; + char name[20]; + +#define EP_ENABLED BIT(0) +#define EP_STALL BIT(1) +#define EP_WEDGE BIT(2) +#define EP_TRANSFER_STARTED BIT(3) +#define EP_UPDATE_EP_TRBADDR BIT(4) +#define EP_PENDING_REQUEST BIT(5) +#define EP_USED BIT(5) + u32 flags; + + void *aligned_buff; + dma_addr_t aligned_dma_addr; + u8 dir; + u8 num; + u8 type; + + int free_trbs; + u8 pcs; + u8 ccs; + int enqueue; + int dequeue; +}; + +struct cdns3_request { + struct usb_request request; + struct cdns3_endpoint *priv_ep; + struct cdns3_trb *trb; + int start_trb; + int end_trb; + int on_ring:1; +}; + +#define to_cdns3_request(r) (container_of(r, struct cdns3_request, request)) + +struct cdns3_device { + struct device dev; + struct cdns3_usb_regs __iomem *regs; + + struct usb_gadget gadget; + struct usb_gadget_driver *gadget_driver; + + struct usb_ctrlrequest *setup; + dma_addr_t setup_dma; + dma_addr_t trb_ep0_dma; + struct cdns3_trb *trb_ep0; + void *zlp_buf; + + struct cdns3_endpoint *eps[USB_SS_ENDPOINTS_MAX_COUNT]; + int ep_nums; + /* + * field used for improving performance. It holds the last + * selected endpoint number + */ + u32 selected_ep; + struct usb_request *ep0_request; + int ep0_data_dir; + int hw_configured_flag; + int wake_up_flag; + u16 isoch_delay; + /* generic spin-lock for drivers */ + spinlock_t lock; + + unsigned is_connected:1; + unsigned in_standby_mode:1; + unsigned status_completion_no_call:1; + unsigned u1_allowed:1; + unsigned u2_allowed:1; + + u32 usb_ien; + u32 ep_ien; + int setup_pending; + struct device *sysdev; + /* The device mode is enabled */ + int start_gadget; + struct list_head ep_match_list; + /* KB */ + int onchip_mem_allocated_size; + /* Memory is allocated for OUT */ + int out_mem_is_allocated:1; + struct work_struct pending_status_wq; + struct usb_request *pending_status_request; +}; + +#endif /* __LINUX_CDNS3_GADGET */ From patchwork Sun Nov 18 10:08:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Laszczak X-Patchwork-Id: 10687725 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2460913BB for ; Sun, 18 Nov 2018 10:12:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1410A29D38 for ; Sun, 18 Nov 2018 10:12:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0766729D43; Sun, 18 Nov 2018 10:12:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9494A29D38 for ; Sun, 18 Nov 2018 10:12:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727224AbeKRUaz (ORCPT ); Sun, 18 Nov 2018 15:30:55 -0500 Received: from mx0b-0014ca01.pphosted.com ([208.86.201.193]:41232 "EHLO mx0a-0014ca01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726180AbeKRUay (ORCPT ); Sun, 18 Nov 2018 15:30:54 -0500 Received: from pps.filterd (m0042333.ppops.net [127.0.0.1]) by mx0b-0014ca01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id wAIA8q7D007702; Sun, 18 Nov 2018 02:10:49 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=proofpoint; bh=s1U4lCyBQeWuKJlCU/aJfDaixvzoEdzjirvSGyyh8wU=; b=CUg4fnPNE1OTR4pWG7aXfUnHr5+rLtr/4LTx80u23n+RQvKbczRL5drVynjKL+wALDgM AcIPFrVDUzdA0oEXoJy/BjzdoUxG0j5okG6QotR9PYsHrdvlQMyMBtTXh4H9cayg3u8V R3fqlVGkNkFiBMS+bq434eLgxnEgk2/8H9WqVYNGmpbdwTqdf4T0KxkZTDU5Zy5A6RQX AC4A15KRTwwuzxuevn0Tr52+AlICMqn4R922r6OoXpCRoXwJeLz7Jkc0X68vBm0doirn gRHJ0v80VUcEj9VumThtd2P03dklOBJsBSwc8bkTMHxMd6M4tN9++z3XwPQFZt+U6wMk ag== Authentication-Results: cadence.com; spf=pass smtp.mailfrom=pawell@cadence.com Received: from nam05-by2-obe.outbound.protection.outlook.com (mail-by2nam05lp0247.outbound.protection.outlook.com [216.32.181.247]) by mx0b-0014ca01.pphosted.com with ESMTP id 2ntff7w44u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 18 Nov 2018 02:10:49 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=s1U4lCyBQeWuKJlCU/aJfDaixvzoEdzjirvSGyyh8wU=; b=bJCq2IQGOm1LIUrefrTWPa4JewGUJILBN4r/Gu27hG1I9YpUuXe3bByxlhyUaGR24e7LrFxuE3yoazR+LM+8acKVSuDSQ15wQreYgBUucPhy9q5FMZXGAVMpeys8tUQ19NR27LIV1NK1BVcsSAk3TkI4AWUHaLBDa7jmRX0/SUY= Received: from BYAPR07CA0086.namprd07.prod.outlook.com (2603:10b6:a03:12b::27) by DM6PR07MB5177.namprd07.prod.outlook.com (2603:10b6:5:4e::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.25; Sun, 18 Nov 2018 10:10:46 +0000 Received: from CO1NAM05FT027.eop-nam05.prod.protection.outlook.com (2a01:111:f400:7e50::207) by BYAPR07CA0086.outlook.office365.com (2603:10b6:a03:12b::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.21 via Frontend Transport; Sun, 18 Nov 2018 10:10:46 +0000 Received-SPF: SoftFail (protection.outlook.com: domain of transitioning cadence.com discourages use of 158.140.1.28 as permitted sender) Received: from sjmaillnx2.cadence.com (158.140.1.28) by CO1NAM05FT027.mail.protection.outlook.com (10.152.96.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.3 via Frontend Transport; Sun, 18 Nov 2018 10:10:41 +0000 Received: from maileu3.global.cadence.com (maileu3.cadence.com [10.160.88.99]) by sjmaillnx2.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAb5L029622 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Sun, 18 Nov 2018 02:10:40 -0800 X-CrossPremisesHeadersFilteredBySendConnector: maileu3.global.cadence.com Received: from maileu3.global.cadence.com (10.160.88.99) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Sun, 18 Nov 2018 11:10:41 +0100 Received: from lvlogina.cadence.com (10.165.176.102) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Sun, 18 Nov 2018 11:10:41 +0100 Received: from lvlogina.cadence.com (localhost.localdomain [127.0.0.1]) by lvlogina.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAbJd030932; Sun, 18 Nov 2018 10:10:37 GMT Received: (from pawell@localhost) by lvlogina.cadence.com (8.14.4/8.14.4/Submit) id wAIAAb6L030931; Sun, 18 Nov 2018 10:10:37 GMT From: Pawel Laszczak To: CC: , , , , , , , , , , , , "Pawel Laszczak" Subject: [RFC PATCH v2 03/15] dt-bindings: add binding for USBSS-DRD controller. Date: Sun, 18 Nov 2018 10:08:59 +0000 Message-ID: <1542535751-16079-4-git-send-email-pawell@cadence.com> X-Mailer: git-send-email 1.7.11.2 In-Reply-To: <1542535751-16079-1-git-send-email-pawell@cadence.com> References: <1542535751-16079-1-git-send-email-pawell@cadence.com> MIME-Version: 1.0 X-OrganizationHeadersPreserved: maileu3.global.cadence.com X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:158.140.1.28;IPV:CAL;SCL:-1;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(39860400002)(376002)(136003)(396003)(346002)(2980300002)(189003)(199004)(36092001)(126002)(486006)(76176011)(51416003)(4326008)(54906003)(16586007)(316002)(50466002)(42186006)(47776003)(106466001)(86362001)(246002)(107886003)(48376002)(2616005)(426003)(11346002)(476003)(26826003)(8676002)(336012)(26005)(446003)(8936002)(2351001)(186003)(217873002)(87636003)(6666004)(478600001)(36756003)(356004)(4720700003)(2906002)(6916009)(7636002)(50226002)(305945005)(105596002)(5660300001);DIR:OUT;SFP:1101;SCL:1;SRVR:DM6PR07MB5177;H:sjmaillnx2.cadence.com;FPR:;SPF:SoftFail;LANG:en;PTR:corp.cadence.com;MX:1;A:1; X-Microsoft-Exchange-Diagnostics: 1;CO1NAM05FT027;1:hka+mEmt8ESohjF5jVpycfoyuGZGfXwJ4t63mHTXdIpHSyH64a9VXh6qDlq5Gzve9Yz+iHivJN+lf+Rvcbv98vx+3J3cv9irDrxkZdJqu/U9yX+A1a/oWVlnHAV8w6Vc X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 894350d3-fcee-484e-2a19-08d64d3e1ac3 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060);SRVR:DM6PR07MB5177; X-Microsoft-Exchange-Diagnostics: 1;DM6PR07MB5177;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U1oLXf+uvL/VNnPbelbZHsFX4AM1C6Q9HQPtUYcPQEbN1uFqJdBRT6b7VkFj3dzGizLLwUIjB/1nbItuisbh1SLK5hWDzFsXnlKIrhEK5slT7zTXHhKDPfSz5q1Le4Q8fbYtzewz3WPP1n+n4fXJW9YztGrvj5qNRPIycsQWl5D63cfKghqeuUGA+HlnWwNf/AqaWjr9hjhWCG1PT45TlU2NGOkkKl0VfKnAiq1km0IXxiAUSKZUcdDAB0077V3Thz/1YuCsZFfcfVkAp1DfSEwQ9fKPaDN8iCzoOGYX+dr5J8juqb5dse94k7A2uOJhnLcYUzw3EbP/upW+j8ahx6vW2AjpTwhicN0S2o8sJS+Z8cmsOxOPT2dgdVKdt1jdBBzSiHWKnGId6RJPc5T+zGM5qKEk54Ai+YFkdexSO4BQqFzvh+G0tBwXDTFgnJW4WvPGSWX+7cqg X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(72806322054110); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231415)(944501410)(52105112)(3002001)(10201501046)(93006095)(93003095)(148016)(149066)(150057)(6041310)(20161123564045)(20161123558120)(20161123560045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051)(76991095);SRVR:DM6PR07MB5177;BCL:0;PCL:0;RULEID:;SRVR:DM6PR07MB5177; X-Microsoft-Exchange-Diagnostics: 1;DM6PR07MB5177;4:gv3Z3W3FaFqQGbynXdpGsYRJKtkJxx/B+Dd1rmVGXtfgFs7joG1PBki1sUgImHtdEG7qARyX38XyUWuxhy+ue7p5ycaFz0O8F29v2IeHF0aZ5VaKz3MqP+9i2aLMk4OdAbY7wV3PQODdI5ibYsUPLOAtA9hm5r5TWY+xJ5DK8lECnmE9uKn+rDjYh1gR6MD/PrJ/Nha6jNW5kpyqP5s0gn9gI97dwlp0FSosutzgSW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0v1kr9MA7UocG+fwHrZWFMafVXb76TL1l1jS+g==;5:XHhxkhwjh7KS7bTpjch7szLx/7FMh2GBcWRRogsVhwrnnH2YAPDt+dU+rsnkC1Jsi5HmN+n8OMvL3AALyk0LwIX23NglTr4OVJhz27xmu0WSefdfFaoxb8eS5EOoksuDOeO9TDOi8GUcEWo9B3JJ/ykecQtQnaOWoPj9chkbz5w=;7:sQzh4FoI/cnZUFo1bYI/r+jToiPMNZjKwL4tTzJMwWgx/eT/Ze5lGtXwvexJr9p9sl4HKuPsTq9lHZal+PFoR3C0c4qRoURXjoe6F4S7jeeaEw3fAPbjfYJOV7TzfFYtzjt2uCAxKQd90S5FFzv2EQ== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DM6PR07MB5177;20:AH/l3ssxrnloD87J6phEEGH3Po87Zy7X2ltmY8bMKooV9mWamX7pf3/GgksXFyeHw7oJaD58eS8IOzNsXRU6W8qiFRgOa9KKWNEHvJKTh9UMcZ4vGd4rIecQ9UxTPdQ/C81qNRo8qiF6iKS2SPljlMUSuCewcjDEGZ6ag8GsDySm5hkRTZonHuChaeGS9O14KJBbrtTRjt0czDaOdBOjeqnKL8BMNavPRnDeJ1v5bRwYcD5u158yRqvPOFa/YBIn X-OriginatorOrg: cadence.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2018 10:10:41.8688 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 894350d3-fcee-484e-2a19-08d64d3e1ac3 X-MS-Exchange-CrossTenant-Id: d36035c5-6ce6-4662-a3dc-e762e61ae4c9 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=d36035c5-6ce6-4662-a3dc-e762e61ae4c9;Ip=[158.140.1.28];Helo=[sjmaillnx2.cadence.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR07MB5177 X-Proofpoint-SPF-Result: pass X-Proofpoint-SPF-Record: v=spf1 a:mx-sanjose2.Cadence.COM a:mx-sanjose4.Cadence.COM a:mx-sanjose5.Cadence.COM include:mktomail.com include:spf-0014ca01.pphosted.com include:spf.protection.outlook.com include:auth.msgapp.com include:spf.mandrillapp.com ~all X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-11-18_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_check_notspam policy=outbound_check score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=540 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811180097 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Thsi patch aim at documenting USB related dt-bindings for the Cadence USBSS-DRD controller. Signed-off-by: Pawel Laszczak --- .../devicetree/bindings/usb/cdns3-usb.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/cdns3-usb.txt diff --git a/Documentation/devicetree/bindings/usb/cdns3-usb.txt b/Documentation/devicetree/bindings/usb/cdns3-usb.txt new file mode 100644 index 000000000000..f9e953f32d47 --- /dev/null +++ b/Documentation/devicetree/bindings/usb/cdns3-usb.txt @@ -0,0 +1,17 @@ +Binding for the Cadence USBSS-DRD controller + +Required properties: + - reg: Physical base address and size of the controller's register area. + - compatible: Should contain: "cdns,usb3" + - interrupts: Interrupt specifier. Refer to interrupt bindings. + + +Example: + cdns3@f3000000 { + compatible = "cdns,usb3"; + interrupts = ; + reg = <0xf3000000 0x10000 //memory area for OTG/DRD registers + 0xf3010000 0x10000 //memory area for HOST registers + 0xf3020000 0x10000>; //memory area for Device registers + }; + From patchwork Sun Nov 18 10:09:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Laszczak X-Patchwork-Id: 10687735 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6AC35109C for ; Sun, 18 Nov 2018 10:12:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 58D9A29D38 for ; Sun, 18 Nov 2018 10:12:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D3D829D47; Sun, 18 Nov 2018 10:12:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 116A729D38 for ; Sun, 18 Nov 2018 10:12:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727082AbeKRUay (ORCPT ); Sun, 18 Nov 2018 15:30:54 -0500 Received: from mx0a-0014ca01.pphosted.com ([208.84.65.235]:36336 "EHLO mx0a-0014ca01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726596AbeKRUax (ORCPT ); Sun, 18 Nov 2018 15:30:53 -0500 Received: from pps.filterd (m0042385.ppops.net [127.0.0.1]) by mx0a-0014ca01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id wAIA6qt6016172; Sun, 18 Nov 2018 02:10:47 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=proofpoint; bh=QEZ7Zua6rEUweI7e5f9FNohYar19xvPS0RxWpb1gc8c=; b=uBgriAp5n9j3EdrHodm0bTkeMQ3rZGxW3TNGnL6RuMNUskykGHKJ5KvJj4zay8o54Zls RbCitP9XzDRgcLdyaPB5UorpqELWgW1sgaUUOHAGyJvxbXA0AYsou+J3Jl6nmV+iHi9L jDfWSqQKjciv6RCuSEzonfmeuDZakarMg375Funpl6IFgCqYRshExY48SkPLhWNNumGl VLdAReHs3CDJDdu+tnV5bovpzT+x+NjvfkUhKlBuWs088TUYHRAct6+u+NFeo0MU2z4b KIQwEqHc12XJTA7c9ZnT1WrHOvMRL5ZgcPbzmw7PLGyfvZNRSOwKmYUz/dsdhCIdTr9+ 7g== Authentication-Results: cadence.com; spf=pass smtp.mailfrom=pawell@cadence.com Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1nam02lp0015.outbound.protection.outlook.com [216.32.180.15]) by mx0a-0014ca01.pphosted.com with ESMTP id 2ntge14vfy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sun, 18 Nov 2018 02:10:46 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QEZ7Zua6rEUweI7e5f9FNohYar19xvPS0RxWpb1gc8c=; b=pmOr17l1cK4tYkdlsqantOMsRgqC3mksD78bQbHclPYaf+ctDtBMrjTU0//H3kFuMRNhsWM3yUUpUPvkLND27qSzMz4nKlOC7V4wRoT3LdXZNiNN82SRmlcJfPsrB2NxJ6QgUwYQzlPwJdygfnEyXptdOEBZK8UkgY0Vgifp9HA= Received: from BYAPR07CA0040.namprd07.prod.outlook.com (2603:10b6:a03:60::17) by DM6PR07MB5178.namprd07.prod.outlook.com (2603:10b6:5:4e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.26; Sun, 18 Nov 2018 10:10:43 +0000 Received: from DM3NAM05FT058.eop-nam05.prod.protection.outlook.com (2a01:111:f400:7e51::201) by BYAPR07CA0040.outlook.office365.com (2603:10b6:a03:60::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.20 via Frontend Transport; Sun, 18 Nov 2018 10:10:42 +0000 Received-SPF: SoftFail (protection.outlook.com: domain of transitioning cadence.com discourages use of 158.140.1.28 as permitted sender) Received: from sjmaillnx2.cadence.com (158.140.1.28) by DM3NAM05FT058.mail.protection.outlook.com (10.152.98.174) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.3 via Frontend Transport; Sun, 18 Nov 2018 10:10:42 +0000 Received: from maileu3.global.cadence.com (maileu3.cadence.com [10.160.88.99]) by sjmaillnx2.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAb5M029622 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Sun, 18 Nov 2018 02:10:41 -0800 X-CrossPremisesHeadersFilteredBySendConnector: maileu3.global.cadence.com Received: from maileu3.global.cadence.com (10.160.88.99) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Sun, 18 Nov 2018 11:10:41 +0100 Received: from lvlogina.cadence.com (10.165.176.102) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Sun, 18 Nov 2018 11:10:41 +0100 Received: from lvlogina.cadence.com (localhost.localdomain [127.0.0.1]) by lvlogina.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAbkJ030946; Sun, 18 Nov 2018 10:10:37 GMT Received: (from pawell@localhost) by lvlogina.cadence.com (8.14.4/8.14.4/Submit) id wAIAAb0k030937; Sun, 18 Nov 2018 10:10:37 GMT From: Pawel Laszczak To: CC: , , , , , , , , , , , , "Pawel Laszczak" Subject: [RFC PATCH v2 04/15] usb:cdns3: Driver initialization code. Date: Sun, 18 Nov 2018 10:09:00 +0000 Message-ID: <1542535751-16079-5-git-send-email-pawell@cadence.com> X-Mailer: git-send-email 1.7.11.2 In-Reply-To: <1542535751-16079-1-git-send-email-pawell@cadence.com> References: <1542535751-16079-1-git-send-email-pawell@cadence.com> MIME-Version: 1.0 X-OrganizationHeadersPreserved: maileu3.global.cadence.com X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:158.140.1.28;IPV:CAL;SCL:-1;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(136003)(346002)(376002)(396003)(39860400002)(2980300002)(36092001)(189003)(199004)(336012)(105596002)(2351001)(106466001)(76176011)(2906002)(446003)(47776003)(486006)(186003)(26005)(476003)(356004)(51416003)(6666004)(36756003)(86362001)(2616005)(11346002)(126002)(426003)(50466002)(4744004)(48376002)(478600001)(87636003)(26826003)(54906003)(16586007)(316002)(42186006)(4720700003)(5660300001)(14444005)(7636002)(107886003)(305945005)(217873002)(4326008)(8676002)(246002)(6916009)(50226002)(8936002);DIR:OUT;SFP:1101;SCL:1;SRVR:DM6PR07MB5178;H:sjmaillnx2.cadence.com;FPR:;SPF:SoftFail;LANG:en;PTR:corp.cadence.com;MX:1;A:1; X-Microsoft-Exchange-Diagnostics: 1;DM3NAM05FT058;1:UT0HQWf6XJftA/+4zsAZZAWdK/SMrqtiKMFb9D5n9Ln3/h4qBkHHdwdiVsuzD2nUMQtI3jhyd9l1JkB89aJ8fCntoHu77cd8hOAgWMMGjwTMEeyHlS5GxdvGulmHAYER X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 93111aca-9727-4135-efd6-08d64d3e1948 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060);SRVR:DM6PR07MB5178; X-Microsoft-Exchange-Diagnostics: 1;DM6PR07MB5178;3:cEHppVzneQTsPK2vL5ozqmgKgnHyxFnwHO4Hdb/460OHlHw8fo1MzsmygxiYZ9kMOxAaJR0eBtK2ryaZ9tmVRikEyWWX4KpYhl6iyoRJtkKY9xiw5dhapN9F6DiUWT+jXa/7MOqXiCGVJo2w8M49ljthJhCkitC16Zeya7wv2GxXY9mWaE82AXpm/yU2s/BA6SWBybF4JvbK740+PaCshYqxFu2FBNKtZnzea/pbsrjXN37nfKJPG5eY89fMYHy8R5dpYtRlzN0uLgH556KYFujgtL+st7SFH4TJE07vJtBfv7gDWtorQKyBqmm1bGmh1rrJeNeQxw3MThnYC9TRhAznfjYtHGt7GQjxpKFh6MI=;25:4G2mvOrjVcJMlTUc1R78LIPIHCiwr6ls44AZNYP++gugYsR9kjZJYgoDsTUOBERzDOyCpIN5uRFskvuInLLXEwCt2BppN1GZXARv1aphuFCskayn8ozK4zXTc5JNqyMqA825ZP5fHvJJur9NLWPhQrVy+vhCfIEctdNIBHXP9urLP2f3aPPvX+1GmTW300S+v/orFUVOvP0Hkto5WOHjlAUQxrfUTQzp8Y+Jx9QrYM1LmwYNhNt8A4aXccPOq44um2djqBi71Oa3JTwPxyOCwtz6JVUcJ4i81JPN3I50fTBzyjj2yEknNZNuMvVofvg7Qk+GeL7pym0y5eX7swAyRw== X-MS-TrafficTypeDiagnostic: DM6PR07MB5178: X-Microsoft-Exchange-Diagnostics: 1;DM6PR07MB5178;31:4IfBdGMWKbelYQg6ZxthfUQQDmaxLo72Ib4FDIvpmP0hwIkmROXZ+Znr6FRMP2DbktPCFsdAmyvUJUzL1Wjz6L9phhaP9H2gmCAjUB4BX0+xUDI/OT+9Vyw5vbFu1lgcpw6XqQHOEImhyLxvAVVp2Gl4fYtgDgAnyzS6Ytn/0del6FTXwmKrKSNn/C+/FkMbNu6zFnAFitDO8i6bm2O4Fyhpw0Z2/AyuVbsQ1sUFHx4=;20:8m1sSB97ZFQQlSrpAEiND+L1ICfKFTlPsiFLUa9rq6mZtcNa3ifUG+RJ09uTlAguZWAfX6O9TvszkMAIgvfPhSF2sQyL4JJz38DLzoxDU9nuF4etzcoLxbwZXziZFzq/eQHF5aPXTN4SSaaYmWF619wEBpwkdYpP9I0ln+1bOk/2rPwTNqxa0JAEttwbjI5mvHbmfKN/pKMjWVdJ+M5DzroaODR6TyIlK8dwdT/YEptTl+dVB/94D/b3sEWzoSy06KNuV0dM87Y+cYp+mKCzNER8IpewW4rEdnJS8IG2C89a77cFH+Z/5PtuJXUflqO/NESPL1D87mnvIWG1FE582qUsvrtQgzg0mHltoKJ7MTpIlH3DPl9Q4fuCs9reJkimXnv4MQ593CzoqWto2CjHgi/IvL0wOb9y1EmXyCt0kM20T2bGlvmfKhhabV4nQywaO3oNob5IyI9VJUTk9CKSZhz65ePGkGlHk+LkFemNAENLu+CYN9MY4NJGeaB9tT73 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(72806322054110)(185117386973197); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231415)(944501410)(52105112)(3002001)(10201501046)(93006095)(93003095)(148016)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123558120)(20161123560045)(20161123562045)(201708071742011)(7699051)(76991095);SRVR:DM6PR07MB5178;BCL:0;PCL:0;RULEID:;SRVR:DM6PR07MB5178; X-Microsoft-Exchange-Diagnostics: 1;DM6PR07MB5178;4:OvQWyRI/eglku8q4knDmGoj3npiyMb/gyozQM3Rm6gOCWp8fnx2ihlOaLOlBW+ZR3cqvT5XzawfOwswjPOo+YIfTchBEeZmcZuT5iCGE/13uP0flnpn7OWJWWFnauSZp8x7nH3lfpEfziH0KQsGYKfz6bYJM75KvzV4LhrP6CLNLO+fm2CT4D3I0eJsoAY6H1nJK1gCb4d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Ef1zupQbIVxlFdBJn3lQIRU4802Ubtb3G1+DRCgxePN/NvSZdpB5CE1rP3t0JoUSDRhWwKjRI0SrcIgn52GymgYyHV41O2cLyLxqW1Hria5IbzXhc+RNpa6PD52fBptfJC21B3G8XYZYdLo8FTYNoa+ESc+w576w6O7qIlS3g==;5:Gc3YIKaHrb4y4qANrH6SYnOGqcoQBP3/tGYG0QWSqMduQQEnvvhJUqJrWq0oWxMcvavrSRMKEq5ZVf2Q4XzI+2D9/mzYntJ78uEDvcAtAh9O0G+cnwq2EWpZ2+4tJ/PyeBGFadYDxofE7/m+ex5xbekFNyeRqSYMYGHAhd8uX3M=;7:vBSTkhJQd3nAuM4/ayphYmLpKBqYSiDKIro2XLFLthbzFfhWFaYrFAhPOERQhdaTrWooxL4XUwZ2jDBT8Nqe8qHqe+e0nEQqZS2L5jad05r0/otI1O7wevsuzPYubHd6NQ6zwdmcg+EITwgs4RRXAQ== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DM6PR07MB5178;20:ZHFcNPrepCfHhwHQ7M+SCZV7mv4EcgcdV1iFcSTX/mO084XicRRHxk5+Z0zGKIJjdV2EG64OiTcUZ6g70G9gjBIYi5h0VnGEjSwZav8RlLkHIWcQk7Q6B0s3lRlxKr0c8aViaqQO5RA4O1ZO/43uOm/v9s45ABy9Zmf5wHlOrVysd2o++DCc87uvhpfc/vLrszjXW8J4ElGM801tqBOrKjMIJdF6ZGzOPcMPwsxApqTJojV4VCUQK2NVJ36AIHXC X-OriginatorOrg: cadence.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2018 10:10:42.1087 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 93111aca-9727-4135-efd6-08d64d3e1948 X-MS-Exchange-CrossTenant-Id: d36035c5-6ce6-4662-a3dc-e762e61ae4c9 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=d36035c5-6ce6-4662-a3dc-e762e61ae4c9;Ip=[158.140.1.28];Helo=[sjmaillnx2.cadence.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR07MB5178 X-Proofpoint-SPF-Result: pass X-Proofpoint-SPF-Record: v=spf1 a:mx-sanjose2.Cadence.COM a:mx-sanjose4.Cadence.COM a:mx-sanjose5.Cadence.COM include:mktomail.com include:spf-0014ca01.pphosted.com include:spf.protection.outlook.com include:auth.msgapp.com include:spf.mandrillapp.com ~all X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-11-18_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_check_notspam policy=outbound_check score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811180096 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Patch adds core.c and core.h file that implements initialization of platform driver and adds function responsible for selecting, switching and running appropriate Device/Host mode. Signed-off-by: Pawel Laszczak --- drivers/usb/cdns3/Makefile | 2 + drivers/usb/cdns3/core.c | 413 +++++++++++++++++++++++++++++++++++++ drivers/usb/cdns3/core.h | 100 +++++++++ 3 files changed, 515 insertions(+) create mode 100644 drivers/usb/cdns3/core.c create mode 100644 drivers/usb/cdns3/core.h diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile index dcdd62003c6a..02d25b23c5d3 100644 --- a/drivers/usb/cdns3/Makefile +++ b/drivers/usb/cdns3/Makefile @@ -1,3 +1,5 @@ +obj-$(CONFIG_USB_CDNS3) += cdns3.o obj-$(CONFIG_USB_CDNS3_PCI_WRAP) += cdns3-pci.o +cdns3-y := core.o cdns3-pci-y := cdns3-pci-wrap.o diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c new file mode 100644 index 000000000000..f9055d4da67f --- /dev/null +++ b/drivers/usb/cdns3/core.c @@ -0,0 +1,413 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Cadence USBSS DRD Driver. + * + * Copyright (C) 2018 Cadence. + * + * Author: Peter Chen + * Pawel Laszczak + */ + +#include +#include +#include +#include +#include +#include + +#include "gadget.h" +#include "core.h" + +static inline struct cdns3_role_driver *cdns3_get_current_role_driver(struct cdns3 *cdns) +{ + WARN_ON(cdns->role >= CDNS3_ROLE_END || !cdns->roles[cdns->role]); + return cdns->roles[cdns->role]; +} + +static inline int cdns3_role_start(struct cdns3 *cdns, enum cdns3_roles role) +{ + int ret; + + if (role >= CDNS3_ROLE_END) + return 0; + + if (!cdns->roles[role]) + return -ENXIO; + + mutex_lock(&cdns->mutex); + cdns->role = role; + ret = cdns->roles[role]->start(cdns); + mutex_unlock(&cdns->mutex); + return ret; +} + +static inline void cdns3_role_stop(struct cdns3 *cdns) +{ + enum cdns3_roles role = cdns->role; + + if (role == CDNS3_ROLE_END) + return; + + mutex_lock(&cdns->mutex); + cdns->roles[role]->stop(cdns); + cdns->role = CDNS3_ROLE_END; + mutex_unlock(&cdns->mutex); +} + +static enum cdns3_roles cdns3_get_role(struct cdns3 *cdns) +{ + if (cdns->roles[CDNS3_ROLE_HOST] && cdns->roles[CDNS3_ROLE_GADGET]) { + //TODO: implements selecting device/host mode + return CDNS3_ROLE_HOST; + } + return cdns->roles[CDNS3_ROLE_HOST] + ? CDNS3_ROLE_HOST + : CDNS3_ROLE_GADGET; +} + +/** + * cdns3_core_init_role - initialize role of operation + * @cdns: Pointer to cdns3 structure + * + * Returns 0 on success otherwise negative errno + */ +static int cdns3_core_init_role(struct cdns3 *cdns) +{ + struct device *dev = cdns->dev; + enum usb_dr_mode dr_mode; + + dr_mode = usb_get_dr_mode(dev); + cdns->role = CDNS3_ROLE_END; + + /* + * If driver can't read mode by means of usb_get_dr_mdoe function then + * chooses mode according with Kernel configuration. This setting + * can be restricted later depending on strap pin configuration. + */ + if (dr_mode == USB_DR_MODE_UNKNOWN) { + if (IS_ENABLED(CONFIG_USB_CDNS3_HOST) && + IS_ENABLED(CONFIG_USB_CDNS3_GADGET)) + dr_mode = USB_DR_MODE_OTG; + else if (IS_ENABLED(CONFIG_USB_CDNS3_HOST)) + dr_mode = USB_DR_MODE_HOST; + else if (IS_ENABLED(CONFIG_USB_CDNS3_GADGET)) + dr_mode = USB_DR_MODE_PERIPHERAL; + } + + if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) { + //TODO: implements host initialization + } + + if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_PERIPHERAL) { + //TODO: implements device initialization + } + + if (!cdns->roles[CDNS3_ROLE_HOST] && !cdns->roles[CDNS3_ROLE_GADGET]) { + dev_err(dev, "no supported roles\n"); + return -ENODEV; + } + + cdns->dr_mode = dr_mode; + return 0; +} + +/** + * cdns3_irq - interrupt handler for cdns3 core device + * + * @irq: irq number for cdns3 core device + * @data: structure of cdns3 + * + * Returns IRQ_HANDLED or IRQ_NONE + */ +static irqreturn_t cdns3_irq(int irq, void *data) +{ + struct cdns3 *cdns = data; + irqreturn_t ret = IRQ_NONE; + + /* Handle device/host interrupt */ + if (cdns->role != CDNS3_ROLE_END) + ret = cdns3_get_current_role_driver(cdns)->irq(cdns); + + return ret; +} + +static void cdns3_remove_roles(struct cdns3 *cdns) +{ + //TODO: implements this function +} + +static int cdns3_do_role_switch(struct cdns3 *cdns, enum cdns3_roles role) +{ + enum cdns3_roles current_role; + int ret = 0; + + current_role = cdns->role; + + if (role == CDNS3_ROLE_END) + return 0; + + dev_dbg(cdns->dev, "Switching role"); + + ret = cdns3_role_start(cdns, role); + if (ret) { + /* Back to current role */ + dev_err(cdns->dev, "set %d has failed, back to %d\n", + role, current_role); + ret = cdns3_role_start(cdns, current_role); + } + + return ret; +} + +/** + * cdns3_role_switch - work queue handler for role switch + * + * @work: work queue item structure + * + * Handles below events: + * - Role switch for dual-role devices + * - CDNS3_ROLE_GADGET <--> CDNS3_ROLE_END for peripheral-only devices + */ +static void cdns3_role_switch(struct work_struct *work) +{ + enum cdns3_roles role = CDNS3_ROLE_END; + struct cdns3 *cdns; + bool device, host; + + cdns = container_of(work, struct cdns3, role_switch_wq); + + //TODO: implements this functions. + //host = cdns3_is_host(cdns); + //device = cdns3_is_device(cdns); + host = 1; + device = 0; + + if (host) + role = CDNS3_ROLE_HOST; + else if (device) + role = CDNS3_ROLE_GADGET; + + if (cdns->desired_dr_mode == cdns->current_dr_mode && + cdns->role == role) + return; + + pm_runtime_get_sync(cdns->dev); + cdns3_role_stop(cdns); + + if (host) { + if (cdns->roles[CDNS3_ROLE_HOST]) + cdns3_do_role_switch(cdns, CDNS3_ROLE_HOST); + pm_runtime_put_sync(cdns->dev); + return; + } + + if (device) + cdns3_do_role_switch(cdns, CDNS3_ROLE_GADGET); + else + cdns3_do_role_switch(cdns, CDNS3_ROLE_END); + + pm_runtime_put_sync(cdns->dev); +} + +/** + * cdns3_probe - probe for cdns3 core device + * @pdev: Pointer to cdns3 core platform device + * + * Returns 0 on success otherwise negative errno + */ +static int cdns3_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct resource *res; + struct cdns3 *cdns; + void __iomem *regs; + int ret; + + cdns = devm_kzalloc(dev, sizeof(*cdns), GFP_KERNEL); + if (!cdns) + return -ENOMEM; + + cdns->dev = dev; + + platform_set_drvdata(pdev, cdns); + + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); + if (!res) { + dev_err(dev, "missing IRQ\n"); + return -ENODEV; + } + cdns->irq = res->start; + + /* + * Request memory region + * region-0: xHCI + * region-1: Peripheral + * region-2: OTG registers + */ + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + regs = devm_ioremap_resource(dev, res); + + if (IS_ERR(regs)) + return PTR_ERR(regs); + cdns->xhci_regs = regs; + cdns->xhci_res = res; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 1); + regs = devm_ioremap_resource(dev, res); + if (IS_ERR(regs)) + return PTR_ERR(regs); + cdns->dev_regs = regs; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 2); + regs = devm_ioremap_resource(dev, res); + if (IS_ERR(regs)) + return PTR_ERR(regs); + cdns->otg_regs = regs; + + mutex_init(&cdns->mutex); + + cdns->phy = devm_phy_get(dev, "cdns3,usbphy"); + if (IS_ERR(cdns->phy)) { + dev_info(dev, "no generic phy found\n"); + cdns->phy = NULL; + /* + * fall through here! + * if no generic phy found, phy init + * should be done under boot! + */ + } else { + phy_init(cdns->phy); + } + + ret = cdns3_core_init_role(cdns); + if (ret) + goto err1; + + INIT_WORK(&cdns->role_switch_wq, cdns3_role_switch); + if (ret) + goto err2; + + if (ret) + goto err2; + + cdns->role = cdns3_get_role(cdns); + + ret = devm_request_irq(dev, cdns->irq, cdns3_irq, IRQF_SHARED, + dev_name(dev), cdns); + + if (ret) + goto err2; + + ret = cdns3_role_start(cdns, cdns->role); + if (ret) { + dev_err(dev, "can't start %s role\n", + cdns3_get_current_role_driver(cdns)->name); + goto err2; + } + + device_set_wakeup_capable(dev, true); + pm_runtime_set_active(dev); + pm_runtime_enable(dev); + + /* + * The controller needs less time between bus and controller suspend, + * and we also needs a small delay to avoid frequently entering low + * power mode. + */ + pm_runtime_set_autosuspend_delay(dev, 20); + pm_runtime_mark_last_busy(dev); + pm_runtime_use_autosuspend(dev); + dev_dbg(dev, "Cadence USB3 core: probe succeed\n"); + + return 0; + +err2: + cdns3_remove_roles(cdns); +err1: + return ret; +} + +/** + * cdns3_remove - unbind drd driver and clean up + * @pdev: Pointer to Linux platform device + * + * Returns 0 on success otherwise negative errno + */ +static int cdns3_remove(struct platform_device *pdev) +{ + struct cdns3 *cdns = platform_get_drvdata(pdev); + + pm_runtime_get_sync(&pdev->dev); + pm_runtime_disable(&pdev->dev); + pm_runtime_put_noidle(&pdev->dev); + cdns3_remove_roles(cdns); + + return 0; +} + +#ifdef CONFIG_OF +static const struct of_device_id of_cdns3_match[] = { + { .compatible = "cdns,usb3" }, + { }, +}; +MODULE_DEVICE_TABLE(of, of_cdns3_match); +#endif + +#ifdef CONFIG_PM + +#ifdef CONFIG_PM_SLEEP +static int cdns3_suspend(struct device *dev) +{ + //TODO: implements this function + return 0; +} + +static int cdns3_resume(struct device *dev) +{ + //TODO: implements this function + return 0; +} +#endif /* CONFIG_PM_SLEEP */ +static int cdns3_runtime_suspend(struct device *dev) +{ //TODO: implements this function + return 0; +} + +static int cdns3_runtime_resume(struct device *dev) +{ + //TODO: implements this function + return 0; +} +#endif /* CONFIG_PM */ + +static const struct dev_pm_ops cdns3_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(cdns3_suspend, cdns3_resume) + SET_RUNTIME_PM_OPS(cdns3_runtime_suspend, cdns3_runtime_resume, NULL) +}; + +static struct platform_driver cdns3_driver = { + .probe = cdns3_probe, + .remove = cdns3_remove, + .driver = { + .name = "cdns-usb3", + .of_match_table = of_match_ptr(of_cdns3_match), + .pm = &cdns3_pm_ops, + }, +}; + +static int __init cdns3_driver_platform_register(void) +{ + return platform_driver_register(&cdns3_driver); +} +module_init(cdns3_driver_platform_register); + +static void __exit cdns3_driver_platform_unregister(void) +{ + platform_driver_unregister(&cdns3_driver); +} +module_exit(cdns3_driver_platform_unregister); + +MODULE_ALIAS("platform:cdns3"); +MODULE_AUTHOR("Pawel Laszczak "); +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("Cadence USB3 DRD Controller Driver"); diff --git a/drivers/usb/cdns3/core.h b/drivers/usb/cdns3/core.h new file mode 100644 index 000000000000..7c8204fe4d3d --- /dev/null +++ b/drivers/usb/cdns3/core.h @@ -0,0 +1,100 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Cadence USBSS DRD Driver. + * + * Copyright (C) 2017 NXP + * Copyright (C) 2018 Cadence. + * + * Authors: Peter Chen + * Pawel Laszczak + */ +#include + +#ifndef __LINUX_CDNS3_CORE_H +#define __LINUX_CDNS3_CORE_H + +struct cdns3; +enum cdns3_roles { + CDNS3_ROLE_HOST = 0, + CDNS3_ROLE_GADGET, + CDNS3_ROLE_END, +}; + +/** + * struct cdns3_role_driver - host/gadget role driver + * @start: start this role + * @stop: stop this role + * @suspend: suspend callback for this role + * @resume: resume callback for this role + * @irq: irq handler for this role + * @name: role name string (host/gadget) + */ +struct cdns3_role_driver { + int (*start)(struct cdns3 *cdns); + void (*stop)(struct cdns3 *cdns); + int (*suspend)(struct cdns3 *cdns, bool do_wakeup); + int (*resume)(struct cdns3 *cdns, bool hibernated); + irqreturn_t (*irq)(struct cdns3 *cdns); + const char *name; +}; + +#define CDNS3_NUM_OF_CLKS 5 +/** + * struct cdns3 - Representation of Cadence USB3 DRD controller. + * @dev: pointer to Cadence device struct + * @xhci_regs: pointer to base of xhci registers + * @xhci_res: the resource for xhci + * @dev_regs: pointer to base of dev registers + * @otg_regs: pointer to base of otg registers + * @irq: irq number for controller + * @roles: array of supported roles for this controller + * @role: current role + * @host_dev: the child host device pointer for cdns3 core + * @gadget_dev: the child gadget device pointer for cdns3 core + * @usb: phy for this controller + * @role_switch_wq: work queue item for role switch + * @in_lpm: the controller in low power mode + * @wakeup_int: the wakeup interrupt + * @mutex: the mutex for concurrent code at driver + * @dr_mode: supported mode of operation it can be only Host, only Device + * or OTG mode that allow to switch between Device and Host mode. + * This field based on hardware configuration and cant't be changed. + * @current_dr_role: current mode of operation when in dual-role mode + * @desired_dr_role: desired mode of operation when in dual-role mode. + * This value can be changed during runtime. + * Available options depends on dr_mode: + * dr_mode | desired_dr_role and current_dr_role + * ---------------------------------------------------------------- + * USB_DR_MODE_HOST | only USB_DR_MODE_HOST + * USB_DR_MODE_PERIPHERAL | only USB_DR_MODE_PERIPHERAL + * USB_DR_MODE_OTG | only USB_DR_MODE_HOST + * USB_DR_MODE_OTG | only USB_DR_MODE_PERIPHERAL + * USB_DR_MODE_OTG | USB_DR_MODE_OTG + * + * Desired_dr_role can be changed by means of debugfs. + * @root: debugfs root folder pointer + */ +struct cdns3 { + struct device *dev; + void __iomem *xhci_regs; + struct resource *xhci_res; + struct cdns3_usb_regs __iomem *dev_regs; + struct cdns3_otg_regs *otg_regs; + int irq; + struct cdns3_role_driver *roles[CDNS3_ROLE_END]; + enum cdns3_roles role; + struct device *host_dev; + struct device *gadget_dev; + struct phy *phy; + struct work_struct role_switch_wq; + int in_lpm:1; + int wakeup_int:1; + /* mutext used in workqueue*/ + struct mutex mutex; + enum usb_dr_mode dr_mode; + enum usb_dr_mode current_dr_mode; + enum usb_dr_mode desired_dr_mode; + struct dentry *root; +}; + +#endif /* __LINUX_CDNS3_CORE_H */ From patchwork Sun Nov 18 10:09:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Laszczak X-Patchwork-Id: 10687715 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0283C109C for ; Sun, 18 Nov 2018 10:11:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFEB929D31 for ; Sun, 18 Nov 2018 10:11:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D27A629D3E; Sun, 18 Nov 2018 10:11:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB8BD29D31 for ; Sun, 18 Nov 2018 10:11:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727469AbeKRUbC (ORCPT ); Sun, 18 Nov 2018 15:31:02 -0500 Received: from mx0b-0014ca01.pphosted.com ([208.86.201.193]:41290 "EHLO mx0a-0014ca01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727396AbeKRUbB (ORCPT ); Sun, 18 Nov 2018 15:31:01 -0500 Received: from pps.filterd (m0042333.ppops.net [127.0.0.1]) by mx0b-0014ca01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id wAIA8s11007707; Sun, 18 Nov 2018 02:10:50 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=proofpoint; bh=lLT6DWDd9d4HDaKp5Agdoe8QUzpo1jFgC0ux9DmSz1g=; b=iNVSV40WVhfYe5olYT0xRRGy95adhgkZVqAlYCiS8bzBZTWWH34NnM1JSy5fQL4ARbTE qE9EVEgdDMt2gE6qEvjko4s9wYERXYokxm0hGivaOY5m8oTXcFtXIxkrA+oSVBiOU8FO T6jlCpFUd0FU06KHZk+1Z4R8WchTgE3551J1ARhUJ14ksxlKm9wpO1TRhrong1CwLmR5 O1AUgTzbhqwygVk2wYH9AppSVznJC6Zs79PTCVCqrL7VjAZRdw4uejR7F73UDd0SO5fS 5/BO65o2CVPO5+tTeq3N84GFEtCe+5aiZeQhekC1V5+zUHQJdonr+bMXUq/UYQW743AY WA== Authentication-Results: cadence.com; spf=pass smtp.mailfrom=pawell@cadence.com Received: from nam05-by2-obe.outbound.protection.outlook.com (mail-by2nam05lp0248.outbound.protection.outlook.com [216.32.181.248]) by mx0b-0014ca01.pphosted.com with ESMTP id 2ntff7w44w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 18 Nov 2018 02:10:49 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lLT6DWDd9d4HDaKp5Agdoe8QUzpo1jFgC0ux9DmSz1g=; b=FVx6u+kXBcoQ7xXgb+qTcLAQ8Z1h/yK7sc0qHvGLJo97Kdl5HKg0mr64TbeG3palCQYMdDTy8JJanm7pz39EMnWEss9rLGTJjgRp9ZlLNIrWMGxsjHc6+4QmgnWsTWClHr6iCrUby1bTNpEwXZVl6ZKYUpzsSXqCvsmEsdP+yd4= Received: from BYAPR07CA0060.namprd07.prod.outlook.com (2603:10b6:a03:60::37) by BL0PR07MB4100.namprd07.prod.outlook.com (2603:10b6:207:4c::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.28; Sun, 18 Nov 2018 10:10:47 +0000 Received: from CO1NAM05FT032.eop-nam05.prod.protection.outlook.com (2a01:111:f400:7e50::205) by BYAPR07CA0060.outlook.office365.com (2603:10b6:a03:60::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.21 via Frontend Transport; Sun, 18 Nov 2018 10:10:46 +0000 Received-SPF: SoftFail (protection.outlook.com: domain of transitioning cadence.com discourages use of 158.140.1.28 as permitted sender) Received: from sjmaillnx2.cadence.com (158.140.1.28) by CO1NAM05FT032.mail.protection.outlook.com (10.152.96.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.3 via Frontend Transport; Sun, 18 Nov 2018 10:10:42 +0000 Received: from maileu3.global.cadence.com (maileu3.cadence.com [10.160.88.99]) by sjmaillnx2.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAb5N029622 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Sun, 18 Nov 2018 02:10:41 -0800 X-CrossPremisesHeadersFilteredBySendConnector: maileu3.global.cadence.com Received: from maileu3.global.cadence.com (10.160.88.99) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Sun, 18 Nov 2018 11:10:41 +0100 Received: from lvlogina.cadence.com (10.165.176.102) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Sun, 18 Nov 2018 11:10:41 +0100 Received: from lvlogina.cadence.com (localhost.localdomain [127.0.0.1]) by lvlogina.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAcc0030983; Sun, 18 Nov 2018 10:10:38 GMT Received: (from pawell@localhost) by lvlogina.cadence.com (8.14.4/8.14.4/Submit) id wAIAAbr5030960; Sun, 18 Nov 2018 10:10:37 GMT From: Pawel Laszczak To: CC: , , , , , , , , , , , , "Pawel Laszczak" Subject: [RFC PATCH v2 05/15] usb:cdns3: Added DRD support Date: Sun, 18 Nov 2018 10:09:01 +0000 Message-ID: <1542535751-16079-6-git-send-email-pawell@cadence.com> X-Mailer: git-send-email 1.7.11.2 In-Reply-To: <1542535751-16079-1-git-send-email-pawell@cadence.com> References: <1542535751-16079-1-git-send-email-pawell@cadence.com> MIME-Version: 1.0 X-OrganizationHeadersPreserved: maileu3.global.cadence.com X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:158.140.1.28;IPV:CAL;SCL:-1;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(979002)(39860400002)(136003)(346002)(376002)(396003)(2980300002)(199004)(189003)(36092001)(2351001)(107886003)(4326008)(47776003)(6916009)(14444005)(16586007)(42186006)(4720700003)(316002)(217873002)(54906003)(76176011)(5660300001)(336012)(51416003)(2906002)(246002)(478600001)(126002)(476003)(486006)(50226002)(87636003)(48376002)(446003)(26826003)(2616005)(8936002)(11346002)(36756003)(50466002)(356004)(105596002)(186003)(6666004)(7636002)(8676002)(106466001)(26005)(86362001)(4744004)(426003)(305945005)(969003)(989001)(999001)(1009001)(1019001);DIR:OUT;SFP:1101;SCL:1;SRVR:BL0PR07MB4100;H:sjmaillnx2.cadence.com;FPR:;SPF:SoftFail;LANG:en;PTR:corp.cadence.com;A:1;MX:1; X-Microsoft-Exchange-Diagnostics: 1;CO1NAM05FT032;1:GfTqsyXaDaITA02bb5BboHxCPlyOPdzSk25DjAzNVe5suiHNzOvc8kKndGY2zq29RX+adMueNSeflQDMdn8f/5o9jqopaEX9lrUhUKLXWsJotcTkyOoTnnSZhgpAVSrM X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 67b66638-9a9a-4464-b4a7-08d64d3e1b60 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060);SRVR:BL0PR07MB4100; X-Microsoft-Exchange-Diagnostics: 1;BL0PR07MB4100;3:fdaRYUnB60rNuTNqbbOYli+ZxYpOY8G/ajPjquwMdi72tOhcTT7P1szgjYbFehiG2AduCxGEWyigh4Ew5qWdhL6ScB3bA54cA7NsgZLIcstpOOt4bPRPFsKHZNQQ76EmuPzWGMc0pjICI9ZjENNoiku4bxCPT07jfVaZ914AWjGjGs6wXHIT43G5YWLPey+rD5MQrf0FXREOqkGTiC8FWI1tHYDl2+Fz2801lcOXhDZW7cUo84OU9uXoMhanwbeGAB1lr2whss24wKtXZaHHUXcZ8Jy2R5l9QarsRB0zFp5E6uNVStFg6vmfEeV2jqPxl2aJ+0Uh5x0lhzv700z3fuGy6ExwOHK9TnL41QdNuyk=;25:GMQrWFBPzm60b6ni+lot3i2xTocxE4UM4OnZ0VvRQQE4piwGiaMsQsNOfnf/BuUvbm2dmH1SduFy4u23rM9dwCgDTr66f9Nl6yvwTmYF6sI18uRuUCrZnvwQs1jrmHPiT00O3Rqa6iqFpMmuZvGuLvpc0JSelhddhvGv7/UYBCNZTf0eai9vb9Y0EVrkkg6QNPPlZRpAk8M4sPFHAgfSY9gm9NSHuDFsu9pjbdNPOsjE4J9JrpNO12466poQ9YmlRkha8j0valbE2HNjh5N0vyWgTCcqzakOUS8nc09Lf1TDYdA9HWvo5uG4M5hVspx9OKRw6krVTM6Ez9svyJNqS+OkiaRawTZvB1f3T6pCigc= X-MS-TrafficTypeDiagnostic: BL0PR07MB4100: X-Microsoft-Exchange-Diagnostics: 1;BL0PR07MB4100;31:8/FhQXo6vfVr8J01V/tWJWTtstpYeEw2GXLfBmqT4Ns9li0kkJ0hXgQPB9cMCt33VcQVSWNibxO8/UD7c3zWkr0jwx+0Hcp9D4WMdmiTlSWB1S9vQJY2TwdjhyMqRCPSi/zgpNXdFOzROFUwdX5jSimBfYAVmHHbLmbfsWq84d5mRcN7PvZFmygVeAbuIwgPsHy6/ZyeQ6ay6WeX1QFuka47gqHKtHcTt0ed0tt/eek=;20:85TNvtUfuMf9BlpJUr9iBLB+DsrUFN+N6BQx6VJ6aGENGQlQV+IYum6D4j0iO4DQz2Ke7lBIXBrWSH2Jlqnc04s91eah/x5lJCD0av0JyjtGRFz0uMrziElKKjUYQTpdVyxwT19ghONbEnwJAH/cg7P+ITsG7/69jLiu+UBiRsqB24VkotCyWLyRsG5zgDop8yc018bWiyxe/E4yYRN8o36gIuDWkEWMPHHpWQemeJJCzVV6Thq0mcnUmMoYKxDT0yG42URFzXZ6R9gslQQjmj//dWngYv5uAJYhSHN5+yWhzNsYzRVe8DYeRf2ENL8dG3YgHjpdnBsIU1X64rYlJGk6rb3aYYaavVd76QXxeEh7Wwd/rcJC+AJOc0yCRcSV5b00jIgR0C8yB0SvZseJRujNCMjC0TbM0ryCcEGX0HU/wiVI91xeEXXR1yvC8Xjw2SP8JhO+s6vjHp8DuNlUtLiy+OCgrmTVCV4CM1bt2j/m2PdaEsY4yKhg/pojhvJ1 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(72806322054110); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93003095)(3231415)(944501410)(52105112)(10201501046)(3002001)(148016)(149066)(150057)(6041310)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051)(76991095);SRVR:BL0PR07MB4100;BCL:0;PCL:0;RULEID:;SRVR:BL0PR07MB4100; X-Microsoft-Exchange-Diagnostics: 1;BL0PR07MB4100;4:XFnXvk+N5AcnRhcSVh0SB6Z51lfWfjPcBDXBmI/W9BLuTKQSEQGcH0pVJWUnzXi/dquSKb94MNSzNVPOW0mFzxvzJ8kv/BtbCmesfHqI5icLFJGHjVU7EcP5SZvwfuQ6aDMzpytCxEITe2x8TkDQh3uDD4KOA0Tm9EXYk18eg9VW0Z/CTMGSxn9xjrAKH7QMNtbpTPnqR7+OKDtvOE0ePJhqml10cjtqF1/hnhWNKBKXepPRJhBGu5q/25y1+6xtHLrBsv7XcvGCVXlCDQYYY93EwNRuTg+9jTeHEN1KhAY6sTjhb+SrG0iFD/Hpf41S X-Forefront-PRVS: 0860FE717F X-Microsoft-Exchange-Diagnostics: 1;BL0PR07MB4100;23:kJTQOl/6lAxwH6PkivWS9zQPuEiOFDOkxUGXCFAUCeVDU9BGdGr7C9glhFfq6qBQX0AoOVMGXVabFABf49cUhyIIiRlrplRbNTnhiGqBLpBMTr2VYnKg7P8LCD+21XsKDCpUMY3j2dpS+m+XISEAn735Fr0F99eitTCU+46mumqUcySlsy6wh93PdJmPUKoqsvLZNs3qQGorbDb4TFiBGeHEirnKWiYme/1TBsCivKaUMcSmjKOXO06uD+DXBdJoflhO1yIRdlRsOt/AJKkeeJEjctFVdQEZUmPC4U+7rMtCEMcvwgno2r0yBTHKj/IbKVRfzGUPgkmdxqG2Tej5SFSptjciVwWORZIRin57rHwmS5ZMMv0tgHqjJq5Yclw3TaW6XJB5QJc6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ics: 1;BL0PR07MB4100;20:G7il4bb7xGjYyHmwSGc2MuGq44fJc8ZZfVBCvQ/nuTeQjLDqiFboimkfGrIbI9dgcmMncc+vOla0W0cNlfiL3NCcyN52bdjLbjBDFb7vcubcVie+n5LxhsLwD7CgNrx6R7SdkryfnzHNkOMSluLXmJbyxcYICWi5pctTAqIdfsrbntX/6vrPM7/0Y5SQY2vMd/qDIhmlkwzsUrhtM3+t5ZaGN+1bO8K+nuSaMlQBRg6uJz2OEDf0camSg1jJhhG4 X-OriginatorOrg: cadence.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2018 10:10:42.8699 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 67b66638-9a9a-4464-b4a7-08d64d3e1b60 X-MS-Exchange-CrossTenant-Id: d36035c5-6ce6-4662-a3dc-e762e61ae4c9 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=d36035c5-6ce6-4662-a3dc-e762e61ae4c9;Ip=[158.140.1.28];Helo=[sjmaillnx2.cadence.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR07MB4100 X-Proofpoint-SPF-Result: pass X-Proofpoint-SPF-Record: v=spf1 a:mx-sanjose2.Cadence.COM a:mx-sanjose4.Cadence.COM a:mx-sanjose5.Cadence.COM include:mktomail.com include:spf-0014ca01.pphosted.com include:spf.protection.outlook.com include:auth.msgapp.com include:spf.mandrillapp.com ~all X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-11-18_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_check_notspam policy=outbound_check score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=962 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811180097 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Patch adds supports for detecting Host/Device mode. Controller has additional OTG register that allow implement even whole OTG functionality. At this moment patch adds support only for detecting the appropriate mode based on strap pins and ID pin. Signed-off-by: Pawel Laszczak --- drivers/usb/cdns3/Makefile | 2 +- drivers/usb/cdns3/core.c | 27 +++-- drivers/usb/cdns3/drd.c | 229 +++++++++++++++++++++++++++++++++++++ drivers/usb/cdns3/drd.h | 122 ++++++++++++++++++++ 4 files changed, 372 insertions(+), 8 deletions(-) create mode 100644 drivers/usb/cdns3/drd.c create mode 100644 drivers/usb/cdns3/drd.h diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile index 02d25b23c5d3..e779b2a2f8eb 100644 --- a/drivers/usb/cdns3/Makefile +++ b/drivers/usb/cdns3/Makefile @@ -1,5 +1,5 @@ obj-$(CONFIG_USB_CDNS3) += cdns3.o obj-$(CONFIG_USB_CDNS3_PCI_WRAP) += cdns3-pci.o -cdns3-y := core.o +cdns3-y := core.o drd.o cdns3-pci-y := cdns3-pci-wrap.o diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c index f9055d4da67f..dbee4325da7f 100644 --- a/drivers/usb/cdns3/core.c +++ b/drivers/usb/cdns3/core.c @@ -17,6 +17,7 @@ #include "gadget.h" #include "core.h" +#include "drd.h" static inline struct cdns3_role_driver *cdns3_get_current_role_driver(struct cdns3 *cdns) { @@ -57,8 +58,10 @@ static inline void cdns3_role_stop(struct cdns3 *cdns) static enum cdns3_roles cdns3_get_role(struct cdns3 *cdns) { if (cdns->roles[CDNS3_ROLE_HOST] && cdns->roles[CDNS3_ROLE_GADGET]) { - //TODO: implements selecting device/host mode - return CDNS3_ROLE_HOST; + if (cdns3_is_host(cdns)) + return CDNS3_ROLE_HOST; + if (cdns3_is_device(cdns)) + return CDNS3_ROLE_GADGET; } return cdns->roles[CDNS3_ROLE_HOST] ? CDNS3_ROLE_HOST @@ -124,6 +127,12 @@ static irqreturn_t cdns3_irq(int irq, void *data) struct cdns3 *cdns = data; irqreturn_t ret = IRQ_NONE; + if (cdns->dr_mode == USB_DR_MODE_OTG) { + ret = cdns3_drd_irq(cdns); + if (ret == IRQ_HANDLED) + return ret; + } + /* Handle device/host interrupt */ if (cdns->role != CDNS3_ROLE_END) ret = cdns3_get_current_role_driver(cdns)->irq(cdns); @@ -176,11 +185,8 @@ static void cdns3_role_switch(struct work_struct *work) cdns = container_of(work, struct cdns3, role_switch_wq); - //TODO: implements this functions. - //host = cdns3_is_host(cdns); - //device = cdns3_is_device(cdns); - host = 1; - device = 0; + host = cdns3_is_host(cdns); + device = cdns3_is_device(cdns); if (host) role = CDNS3_ROLE_HOST; @@ -194,6 +200,12 @@ static void cdns3_role_switch(struct work_struct *work) pm_runtime_get_sync(cdns->dev); cdns3_role_stop(cdns); + if (cdns->desired_dr_mode != cdns->current_dr_mode) { + cdns3_drd_update_mode(cdns); + host = cdns3_is_host(cdns); + device = cdns3_is_device(cdns); + } + if (host) { if (cdns->roles[CDNS3_ROLE_HOST]) cdns3_do_role_switch(cdns, CDNS3_ROLE_HOST); @@ -287,6 +299,7 @@ static int cdns3_probe(struct platform_device *pdev) if (ret) goto err2; + ret = cdns3_drd_init(cdns); if (ret) goto err2; diff --git a/drivers/usb/cdns3/drd.c b/drivers/usb/cdns3/drd.c new file mode 100644 index 000000000000..ac741c80e776 --- /dev/null +++ b/drivers/usb/cdns3/drd.c @@ -0,0 +1,229 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Cadence USBSS DRD Driver. + * + * Copyright (C) 2018 Cadence. + * + * Author: Pawel Laszczak +#include +#include +#include + +#include "gadget.h" +#include "drd.h" + +/** + * cdns3_set_mode - change mode of OTG Core + * @cdns: pointer to context structure + * @mode: selected mode from cdns_role + */ +void cdns3_set_mode(struct cdns3 *cdns, enum usb_dr_mode mode) +{ + u32 reg; + + cdns->current_dr_mode = mode; + switch (mode) { + case USB_DR_MODE_PERIPHERAL: + dev_info(cdns->dev, "Set controller to Gadget mode\n"); + writel(OTGCMD_DEV_BUS_REQ | OTGCMD_OTG_DIS, + &cdns->otg_regs->cmd); + break; + case USB_DR_MODE_HOST: + dev_info(cdns->dev, "Set controller to Host mode\n"); + writel(OTGCMD_HOST_BUS_REQ | OTGCMD_OTG_DIS, + &cdns->otg_regs->cmd); + break; + case USB_DR_MODE_OTG: + dev_info(cdns->dev, "Set controller to OTG mode\n"); + reg = readl(&cdns->otg_regs->ctrl1); + reg |= OTGCTRL1_IDPULLUP; + writel(reg, &cdns->otg_regs->ctrl1); + + /* wait until valid ID (ID_VALUE) can be sampled (50ms). */ + mdelay(50); + break; + default: + cdns->current_dr_mode = USB_DR_MODE_UNKNOWN; + dev_err(cdns->dev, "Unsupported mode of operation %d\n", mode); + return; + } +} + +static int cdns3_otg_get_id(struct cdns3 *cdns) +{ + int id; + + id = readl(&cdns->otg_regs->sts) & OTGSTS_ID_VALUE; + dev_dbg(cdns->dev, "OTG ID: %d", id); + return id; +} + +int cdns3_is_host(struct cdns3 *cdns) +{ + if (cdns->current_dr_mode == USB_DR_MODE_HOST) + return 1; + else if (cdns->current_dr_mode == USB_DR_MODE_OTG) + if (!cdns3_otg_get_id(cdns)) + return 1; + + return 0; +} + +int cdns3_is_device(struct cdns3 *cdns) +{ + if (cdns->current_dr_mode == USB_DR_MODE_PERIPHERAL) + return 1; + else if (cdns->current_dr_mode == USB_DR_MODE_OTG) + if (cdns3_otg_get_id(cdns)) + return 1; + + return 0; +} + +/** + * cdns3_otg_disable_irq - Disable all OTG interrupts + * @cdns: Pointer to controller context structure + */ +static void cdns3_otg_disable_irq(struct cdns3 *cdns) +{ + writel(0, &cdns->otg_regs->ien); +} + +/** + * cdns3_otg_enable_irq - enable id and sess_valid interrupts + * @cdns: Pointer to controller context structure + */ +static void cdns3_otg_enable_irq(struct cdns3 *cdns) +{ + writel(OTGIEN_ID_CHANGE_INT | OTGIEN_VBUSVALID_RISE_INT | + OTGIEN_VBUSVALID_FALL_INT, &cdns->otg_regs->ien); +} + +/** + * cdns3_init_otg_mode - initialize drd controller + * @cdns: Pointer to controller context structure + * + * Returns 0 on success otherwise negative errno + */ +static void cdns3_init_otg_mode(struct cdns3 *cdns) +{ + cdns3_otg_disable_irq(cdns); + /* clear all interrupts */ + writel(~0, &cdns->otg_regs->ivect); + + cdns3_set_mode(cdns, USB_DR_MODE_OTG); + + cdns3_otg_enable_irq(cdns); +} + +/** + * cdns3_drd_update_mode - initialize mode of operation + * @cdns: Pointer to controller context structure + * + * Returns 0 on success otherwise negative errno + */ +int cdns3_drd_update_mode(struct cdns3 *cdns) +{ + int ret = 0; + + switch (cdns->desired_dr_mode) { + case USB_DR_MODE_PERIPHERAL: + cdns3_set_mode(cdns, USB_DR_MODE_PERIPHERAL); + break; + case USB_DR_MODE_HOST: + cdns3_set_mode(cdns, USB_DR_MODE_HOST); + break; + case USB_DR_MODE_OTG: + cdns3_init_otg_mode(cdns); + break; + default: + dev_err(cdns->dev, "Unsupported mode of operation %d\n", + cdns->dr_mode); + return -EINVAL; + } + + return ret; +} + +irqreturn_t cdns3_drd_irq(struct cdns3 *cdns) +{ + irqreturn_t ret = IRQ_NONE; + u32 reg; + + if (cdns->dr_mode != USB_DR_MODE_OTG) + return ret; + + reg = readl(&cdns->otg_regs->ivect); + if (!reg) + return ret; + + if (reg & OTGIEN_ID_CHANGE_INT) { + int id = cdns3_otg_get_id(cdns); + + dev_dbg(cdns->dev, "OTG IRQ: new ID: %d\n", + cdns3_otg_get_id(cdns)); + + if (id) + cdns->role = CDNS3_ROLE_GADGET; + else + cdns->role = CDNS3_ROLE_HOST; + + queue_work(system_freezable_wq, &cdns->role_switch_wq); + + ret = IRQ_HANDLED; + } + + writel(~0, &cdns->otg_regs->ivect); + return IRQ_HANDLED; +} + +int cdns3_drd_init(struct cdns3 *cdns) +{ + enum usb_dr_mode dr_mode; + int ret = 0; + u32 state; + + state = OTGSTS_STRAP(readl(&cdns->otg_regs->sts)); + + dr_mode = cdns->dr_mode; + if (state == OTGSTS_STRAP_HOST) { + dev_info(cdns->dev, "Controller strapped to HOST\n"); + dr_mode = USB_DR_MODE_HOST; + if (cdns->dr_mode != USB_DR_MODE_HOST && + cdns->dr_mode != USB_DR_MODE_OTG) + ret = -EINVAL; + } else if (state == OTGSTS_STRAP_GADGET) { + dev_info(cdns->dev, "Controller strapped to PERIPHERAL\n"); + dr_mode = USB_DR_MODE_PERIPHERAL; + if (cdns->dr_mode != USB_DR_MODE_PERIPHERAL && + cdns->dr_mode != USB_DR_MODE_OTG) + ret = -EINVAL; + } + + if (ret) { + dev_err(cdns->dev, "Incorrect DRD configuration\n"); + return ret; + } + + //Updating DR mode according to strap. + cdns->dr_mode = dr_mode; + cdns->desired_dr_mode = dr_mode; + cdns->current_dr_mode = USB_DR_MODE_UNKNOWN; + + dev_info(cdns->dev, "Controller Device ID: %08lx, Revision ID: %08lx\n", + CDNS_RID(readl(&cdns->otg_regs->rid)), + CDNS_DID(readl(&cdns->otg_regs->did))); + + state = readl(&cdns->otg_regs->sts); + if (OTGSTS_OTG_NRDY(state) != 0) { + dev_err(cdns->dev, "Cadence USB3 OTG device not ready\n"); + return -ENODEV; + } + + ret = cdns3_drd_update_mode(cdns); + + return ret; +} diff --git a/drivers/usb/cdns3/drd.h b/drivers/usb/cdns3/drd.h new file mode 100644 index 000000000000..0faa7520ecac --- /dev/null +++ b/drivers/usb/cdns3/drd.h @@ -0,0 +1,122 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Cadence USB3 DRD part of USBSS driver + * + * Copyright (C) 2018 Cadence. + * + * Author: Pawel Laszczak + */ +#ifndef __LINUX_CDNS3_DRD +#define __LINUX_CDNS3_DRD + +#include +#include +#include "core.h" + +/* DRD register interface. */ +struct cdns3_otg_regs { + __le32 did; + __le32 rid; + __le32 capabilities; + __le32 reserved1; + __le32 cmd; + __le32 sts; + __le32 state; + __le32 reserved2; + __le32 ien; + __le32 ivect; + __le32 refclk; + __le32 tmr; + __le32 reserved3[4]; + __le32 simulate; + __le32 override; + __le32 susp_ctrl; + __le32 reserved4; + __le32 anasts; + __le32 adp_ramp_time; + __le32 ctrl1; + __le32 ctrl2; +}; + +/* CDNS_RID - bitmasks */ +#define CDNS_RID(p) ((p) & GENMASK(15, 0)) + +/* CDNS_VID - bitmasks */ +#define CDNS_DID(p) ((p) & GENMASK(31, 0)) + +/* OTGCMD - bitmasks */ +/* "Request the bus for Device mode. */ +#define OTGCMD_DEV_BUS_REQ BIT(0) +/* Request the bus for Host mode */ +#define OTGCMD_HOST_BUS_REQ BIT(1) +/* Enable OTG mode. */ +#define OTGCMD_OTG_EN BIT(2) +/* Disable OTG mode */ +#define OTGCMD_OTG_DIS BIT(3) +/*"Configure OTG as A-Device. */ +#define OTGCMD_A_DEV_EN BIT(4) +/*"Configure OTG as A-Device. */ +#define OTGCMD_A_DEV_DIS BIT(5) +/* Drop the bus for Device mod e. */ +#define OTGCMD_DEV_BUS_DROP BIT(8) +/* Drop the bus for Host mode*/ +#define OTGCMD_HOST_BUS_DROP BIT(9) +/* Power Down USBSS-DEV. */ +#define OTGCMD_DEV_POWER_OFF BIT(11) +/* Power Down CDNSXHCI. */ +#define OTGCMD_HOST_POWER_OFF BIT(12) + +/* OTGIEN - bitmasks */ +/* ID change interrupt enable */ +#define OTGIEN_ID_CHANGE_INT BIT(0) +/* Vbusvalid fall detected interrupt enable.*/ +#define OTGIEN_VBUSVALID_RISE_INT BIT(4) +/* Vbusvalid fall detected interrupt enable */ +#define OTGIEN_VBUSVALID_FALL_INT BIT(5) + +/* OTGSTS - bitmasks */ +/* + * Current value of the ID pin. It is only valid when idpullup in + * OTGCTRL1_TYPE register is set to '1'. + */ +#define OTGSTS_ID_VALUE BIT(0) +/* Current value of the vbus_valid */ +#define OTGSTS_VBUS_VALID BIT(1) +/* Current value of the b_sess_vld */ +#define OTGSTS_SESSION_VALID BIT(2) +/*Device mode is active*/ +#define OTGSTS_DEV_ACTIVE BIT(3) +/* Host mode is active. */ +#define OTGSTS_HOST_ACTIVE BIT(4) +/* OTG Controller not ready. */ +#define OTGSTS_OTG_NRDY_MASK BIT(11) +#define OTGSTS_OTG_NRDY(p) ((p) & OTGSTS_OTG_NRDY_MASK) +/* + * Value of the strap pins. + * 000 - no default configuration + * 010 - Controller initiall configured as Host + * 100 - Controller initially configured as Device + */ +#define OTGSTS_STRAP(p) (((p) & GENMASK(14, 12)) >> 12) +#define OTGSTS_STRAP_NO_DEFAULT_CFG 0x00 +#define OTGSTS_STRAP_HOST_OTG 0x01 +#define OTGSTS_STRAP_HOST 0x02 +#define OTGSTS_STRAP_GADGET 0x04 +/* Host mode is turned on. */ +#define OTGSTSE_XHCI_READYF BIT(26) +/* "Device mode is turned on .*/ +#define OTGSTS_DEV_READY BIT(27) + +/* OTGREFCLK - bitmasks */ +#define OTGREFCLK_STB_CLK_SWITCH_EN BIT(31) + +/* OTGCTRL1 - bitmasks */ +#define OTGCTRL1_IDPULLUP BIT(24) + +int cdns3_is_host(struct cdns3 *cdns); +int cdns3_is_device(struct cdns3 *cdns); +int cdns3_drd_init(struct cdns3 *cdns); +int cdns3_drd_update_mode(struct cdns3 *cdns); +irqreturn_t cdns3_drd_irq(struct cdns3 *cdns); + +#endif /* __LINUX_CDNS3_DRD */ From patchwork Sun Nov 18 10:09:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Laszczak X-Patchwork-Id: 10687721 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 24D4B13BB for ; Sun, 18 Nov 2018 10:12:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1313029D31 for ; Sun, 18 Nov 2018 10:12:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0713F29D3E; Sun, 18 Nov 2018 10:12:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20D2329D31 for ; Sun, 18 Nov 2018 10:12:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727601AbeKRUbv (ORCPT ); Sun, 18 Nov 2018 15:31:51 -0500 Received: from mx0a-0014ca01.pphosted.com ([208.84.65.235]:36344 "EHLO mx0a-0014ca01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726626AbeKRUaz (ORCPT ); Sun, 18 Nov 2018 15:30:55 -0500 Received: from pps.filterd (m0042385.ppops.net [127.0.0.1]) by mx0a-0014ca01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id wAIA6m2T016126; Sun, 18 Nov 2018 02:10:50 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=proofpoint; bh=HLqWJ82NMnJk1pCLtj8tgQyR/RsmqhSbhukHMirKJbA=; b=RMs4Pqfk0b+IdZo0y3HmNuYZuIow3ysqtE+EZvMUx9FtVagKFprZqCO6ry19tL1r5hOR NbC4rx4HMYwFzFqkb95kKBsklNJ3uMApxN4DOv8Ru53cj9D7S9Id1NCZxyOC0Jjxu9M6 3W4zuIDcGkypZiAbAAIjRrYSjE9D7sDiSk1dlj7qlmkZi6Ma6L7YU4Wt2wc16MxPLtHC oNZc6R/uUf7BankyQVGwqUM9mQvSVJlf1Xrcr1o1fzVMdIR8eNOdJBfUZrT05kQO0ccA wDq3UFqsIFrKp0v5EAxyW0tCDnfCGEavRNb14xj7wD+JqPiHhRTLI8PV9I0VNwpQNo3e hQ== Authentication-Results: cadence.com; spf=pass smtp.mailfrom=pawell@cadence.com Received: from nam01-bn3-obe.outbound.protection.outlook.com (mail-bn3nam01lp0180.outbound.protection.outlook.com [216.32.180.180]) by mx0a-0014ca01.pphosted.com with ESMTP id 2ntge14vga-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sun, 18 Nov 2018 02:10:50 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HLqWJ82NMnJk1pCLtj8tgQyR/RsmqhSbhukHMirKJbA=; b=sUNoUOBCOqLbSuEiqZPqndxuD+92YD25TcnWXMh85oI8FcH+UOdNs2Ft2o7/wJzNExVFvH2nhLlP5gFAjsB91LeOVGi0hAhv+qn5CdD7Ec9oT5c55OWHiJ0wbxkYouegh7EG+vzgin1cfYuVHo0TpEEwSkpnPMV0iNw8GyckA9M= Received: from CY1PR07CA0017.namprd07.prod.outlook.com (2a01:111:e400:c60a::27) by SN1PR07MB4111.namprd07.prod.outlook.com (2603:10b6:802:30::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.26; Sun, 18 Nov 2018 10:10:47 +0000 Received: from CO1NAM05FT010.eop-nam05.prod.protection.outlook.com (2a01:111:f400:7e50::208) by CY1PR07CA0017.outlook.office365.com (2a01:111:e400:c60a::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.20 via Frontend Transport; Sun, 18 Nov 2018 10:10:47 +0000 Received-SPF: SoftFail (protection.outlook.com: domain of transitioning cadence.com discourages use of 158.140.1.28 as permitted sender) Received: from sjmaillnx2.cadence.com (158.140.1.28) by CO1NAM05FT010.mail.protection.outlook.com (10.152.96.117) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.3 via Frontend Transport; Sun, 18 Nov 2018 10:10:43 +0000 Received: from maileu3.global.cadence.com (maileu3.cadence.com [10.160.88.99]) by sjmaillnx2.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAb5O029622 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Sun, 18 Nov 2018 02:10:42 -0800 X-CrossPremisesHeadersFilteredBySendConnector: maileu3.global.cadence.com Received: from maileu3.global.cadence.com (10.160.88.99) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Sun, 18 Nov 2018 11:10:42 +0100 Received: from lvlogina.cadence.com (10.165.176.102) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Sun, 18 Nov 2018 11:10:42 +0100 Received: from lvlogina.cadence.com (localhost.localdomain [127.0.0.1]) by lvlogina.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAcOt031155; Sun, 18 Nov 2018 10:10:38 GMT Received: (from pawell@localhost) by lvlogina.cadence.com (8.14.4/8.14.4/Submit) id wAIAAcvX031111; Sun, 18 Nov 2018 10:10:38 GMT From: Pawel Laszczak To: CC: , , , , , , , , , , , , "Pawel Laszczak" Subject: [RFC PATCH v2 06/15] usb:cdns3: Adds Host support Date: Sun, 18 Nov 2018 10:09:02 +0000 Message-ID: <1542535751-16079-7-git-send-email-pawell@cadence.com> X-Mailer: git-send-email 1.7.11.2 In-Reply-To: <1542535751-16079-1-git-send-email-pawell@cadence.com> References: <1542535751-16079-1-git-send-email-pawell@cadence.com> MIME-Version: 1.0 X-OrganizationHeadersPreserved: maileu3.global.cadence.com X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:158.140.1.28;IPV:CAL;SCL:-1;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(39860400002)(346002)(376002)(136003)(396003)(2980300002)(36092001)(199004)(189003)(2616005)(126002)(476003)(26826003)(478600001)(47776003)(36756003)(51416003)(2351001)(8936002)(87636003)(217873002)(11346002)(16586007)(316002)(42186006)(486006)(246002)(8676002)(86362001)(446003)(50226002)(4720700003)(6916009)(6666004)(54906003)(356004)(2906002)(426003)(50466002)(5660300001)(186003)(26005)(48376002)(6346003)(14444005)(336012)(105596002)(106466001)(305945005)(4326008)(7636002)(76176011)(107886003);DIR:OUT;SFP:1101;SCL:1;SRVR:SN1PR07MB4111;H:sjmaillnx2.cadence.com;FPR:;SPF:SoftFail;LANG:en;PTR:corp.cadence.com;A:1;MX:1; X-Microsoft-Exchange-Diagnostics: 1;CO1NAM05FT010;1:cFhnbc3uqYDz0USn8kGfBhyWZ6but+5kKuZpHNaGjm6bVrCWr5Scsla+VQXSoWigc0pFydtrELIoMeXmzl/U6KrVdh4VEgeR/lr1s1wiWRH+WONaFW6x+rIyMaGQauMu X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7fdd9f0f-1bbe-465d-d0ca-08d64d3e1b99 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060);SRVR:SN1PR07MB4111; X-Microsoft-Exchange-Diagnostics: 1;SN1PR07MB4111;3:Rdks9An4qZl7cDwNZwgIsXPElD8kt7AbnyfGKYYhVU3LQRkoWCwUpWxJbkfrAPqVglyIpNav/Jt51eO5JepyobGpIfCvYtefI9uOD3snPI+vzjJKkkOozQuIV6v6kbqohIQe/mHQOLJ5gj2sS4JO69+g02APP4WDTAsFSJDIBSYifGSancVlX8Rj7M3owszKYB4oWiIihCzR2iA0Eed3ps38NHw8iO4b+kC9YXHCC0+BdTzRAIcCPO0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dhTk3Eu0E4bykoG/rFMn/VfjKAvwwOC3ZN/7Y11Xj9Njsdbz+xHs5EIXY4DFOYy3zQnuwit6JskArKXouhtTR8SItpGPqbmnvCg+1+tPko+8HHcRkvYThi+ot1lBcGXuNPDB9qqUqo0N1LEYQacBiDNr/M00BtA1nRTiANyq06ZgxKCg0z5hbXb+cGjaN/urrTGMXkidj6p X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3002001)(10201501046)(93006095)(93003095)(3231431)(944501410)(52105112)(148016)(149066)(150057)(6041310)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051)(76991095);SRVR:SN1PR07MB4111;BCL:0;PCL:0;RULEID:;SRVR:SN1PR07MB4111; X-Microsoft-Exchange-Diagnostics: 1;SN1PR07MB4111;4:ULdkWdyP5qkY9W5ZcRIvHS+bppwmY8uOm5Y+OS5HqU6CahAndjCGIt2dLv7OBhN2TQUvzc7oL3vrgpYTTDYCfomiAHkKEpSCoOGP5Pp+XVDPXeTgoTbuXw6SfGc5mF7Cs6Nro4iwXI6wLpCtklyM2CAGOC0/+jXjSGTRZZ/ChdPZvyZuysqwRDBKXouex53hxUd9YVjC2UtZgwoSU4uyk6xiLoNPkqg2SHHl4QXroFdw067Bq7+9n336wnZ8qUfbKx74jqHIJwLpakdrSfMH1w== X-Forefront-PRVS: 0860FE717F X-Microsoft-Exchange-Diagnostics: 1;SN1PR07MB4111;23:vL7l0ePhpH2kVlmvVrfivpoKNuMuQPvuHPsTpP2GNg1JmCFKd8T2FrTfYALBBL9l2GRLgHZVKSncBHWxsiTHTT6NMvqu1FJL83pG7WjUoZF1k+HzcZYEESXfe15qQjDRiC9h8kEZvspsljpz6KmrhLr3LBwTWTqtngQQ0LGbz+x01WupoYjYMLHxuVfII3s3l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zk+b8osviWvtcIxZrJ5B6oi2xc2cDPKtTkg4YwMKb9XxpqL/h1DsB1SKm8yKVAFoKlbifZ7Q== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;SN1PR07MB4111;20:nFFqVqsLGD+K7IoSA6PdhGNe4cTjY8jkQbnet3n3Mr/DUz4ItqjNVLmInKFPvZhG+6y5cSvUijAJ80LZm7HeH1qM3wr2jbopJXN+xGzcnmkqopxpmw8vl7w6HfrlI4PldNXcy2Gx0AVFWbazCP8V1MtmDHXJZnMxDNF5455A6LN34DRQ2AyvWUaRrf0Nw9FRvxY3N+ageI62z1wN3oyhH4+XL6+M/WYv04lO7vyAwr9IwoyOl6w/lVJdYNsnnpGk X-OriginatorOrg: cadence.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2018 10:10:43.2754 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7fdd9f0f-1bbe-465d-d0ca-08d64d3e1b99 X-MS-Exchange-CrossTenant-Id: d36035c5-6ce6-4662-a3dc-e762e61ae4c9 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=d36035c5-6ce6-4662-a3dc-e762e61ae4c9;Ip=[158.140.1.28];Helo=[sjmaillnx2.cadence.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR07MB4111 X-Proofpoint-SPF-Result: pass X-Proofpoint-SPF-Record: v=spf1 a:mx-sanjose2.Cadence.COM a:mx-sanjose4.Cadence.COM a:mx-sanjose5.Cadence.COM include:mktomail.com include:spf-0014ca01.pphosted.com include:spf.protection.outlook.com include:auth.msgapp.com include:spf.mandrillapp.com ~all X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-11-18_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_check_notspam policy=outbound_check score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=913 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811180096 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Patch adds host-export.h and host.c file and mplements functions that allow to initialize, start and stop XHCI host driver. Signed-off-by: Pawel Laszczak --- drivers/usb/cdns3/Kconfig | 10 ++ drivers/usb/cdns3/Makefile | 1 + drivers/usb/cdns3/core.c | 7 +- drivers/usb/cdns3/host-export.h | 30 ++++ drivers/usb/cdns3/host.c | 256 ++++++++++++++++++++++++++++++++ 5 files changed, 302 insertions(+), 2 deletions(-) create mode 100644 drivers/usb/cdns3/host-export.h create mode 100644 drivers/usb/cdns3/host.c diff --git a/drivers/usb/cdns3/Kconfig b/drivers/usb/cdns3/Kconfig index eb22a8692991..d92bc3d68eb0 100644 --- a/drivers/usb/cdns3/Kconfig +++ b/drivers/usb/cdns3/Kconfig @@ -10,6 +10,16 @@ config USB_CDNS3 if USB_CDNS3 +config USB_CDNS3_HOST + bool "Cadence USB3 host controller" + depends on USB_XHCI_HCD + help + Say Y here to enable host controller functionality of the + cadence driver. + + Host controller is compliance with XHCI so it will use + standard XHCI driver. + config USB_CDNS3_PCI_WRAP tristate "PCIe-based Platforms" depends on USB_PCI && ACPI diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile index e779b2a2f8eb..976117ba67ff 100644 --- a/drivers/usb/cdns3/Makefile +++ b/drivers/usb/cdns3/Makefile @@ -2,4 +2,5 @@ obj-$(CONFIG_USB_CDNS3) += cdns3.o obj-$(CONFIG_USB_CDNS3_PCI_WRAP) += cdns3-pci.o cdns3-y := core.o drd.o +cdns3-$(CONFIG_USB_CDNS3_HOST) += host.o cdns3-pci-y := cdns3-pci-wrap.o diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c index dbee4325da7f..4cb820be9ff3 100644 --- a/drivers/usb/cdns3/core.c +++ b/drivers/usb/cdns3/core.c @@ -17,6 +17,7 @@ #include "gadget.h" #include "core.h" +#include "host-export.h" #include "drd.h" static inline struct cdns3_role_driver *cdns3_get_current_role_driver(struct cdns3 *cdns) @@ -98,7 +99,8 @@ static int cdns3_core_init_role(struct cdns3 *cdns) } if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_HOST) { - //TODO: implements host initialization + if (cdns3_host_init(cdns)) + dev_info(dev, "doesn't support host\n"); } if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_PERIPHERAL) { @@ -142,7 +144,7 @@ static irqreturn_t cdns3_irq(int irq, void *data) static void cdns3_remove_roles(struct cdns3 *cdns) { - //TODO: implements this function + cdns3_host_remove(cdns); } static int cdns3_do_role_switch(struct cdns3 *cdns, enum cdns3_roles role) @@ -410,6 +412,7 @@ static struct platform_driver cdns3_driver = { static int __init cdns3_driver_platform_register(void) { + cdns3_host_driver_init(); return platform_driver_register(&cdns3_driver); } module_init(cdns3_driver_platform_register); diff --git a/drivers/usb/cdns3/host-export.h b/drivers/usb/cdns3/host-export.h new file mode 100644 index 000000000000..f8f3b230b472 --- /dev/null +++ b/drivers/usb/cdns3/host-export.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Cadence USBSS DRD Driver -Host Export APIs + * + * Copyright (C) 2017 NXP + * + * Authors: Peter Chen + */ +#ifndef __LINUX_CDNS3_HOST_EXPORT +#define __LINUX_CDNS3_HOST_EXPORT + +#ifdef CONFIG_USB_CDNS3_HOST + +int cdns3_host_init(struct cdns3 *cdns); +void cdns3_host_remove(struct cdns3 *cdns); +void cdns3_host_driver_init(void); + +#else + +static inline int cdns3_host_init(struct cdns3 *cdns) +{ + return -ENXIO; +} + +static inline void cdns3_host_remove(struct cdns3 *cdns) { } +static inline void cdns3_host_driver_init(void) {} + +#endif /* CONFIG_USB_CDNS3_HOST */ + +#endif /* __LINUX_CDNS3_HOST_EXPORT */ diff --git a/drivers/usb/cdns3/host.c b/drivers/usb/cdns3/host.c new file mode 100644 index 000000000000..0dd47976cb28 --- /dev/null +++ b/drivers/usb/cdns3/host.c @@ -0,0 +1,256 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Cadence USBSS DRD Driver - host side + * + * Copyright (C) 2018 Cadence Design Systems. + * Copyright (C) 2018 NXP + * + * Authors: Peter Chen + * Pawel Laszczak + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../host/xhci.h" +#include "core.h" +#include "host-export.h" + +static struct hc_driver __read_mostly xhci_cdns3_hc_driver; + +static void xhci_cdns3_quirks(struct device *dev, struct xhci_hcd *xhci) +{ + /* + * As of now platform drivers don't provide MSI support so we ensure + * here that the generic code does not try to make a pci_dev from our + * dev struct in order to setup MSI + */ + xhci->quirks |= XHCI_PLAT; +} + +static int xhci_cdns3_setup(struct usb_hcd *hcd) +{ + struct xhci_hcd *xhci = hcd_to_xhci(hcd); + u32 command; + int ret; + + ret = xhci_gen_setup(hcd, xhci_cdns3_quirks); + if (ret) + return ret; + + /* set usbcmd.EU3S */ + command = readl(&xhci->op_regs->command); + command |= CMD_PM_INDEX; + writel(command, &xhci->op_regs->command); + + return 0; +} + +static const struct xhci_driver_overrides xhci_cdns3_overrides __initconst = { + .extra_priv_size = sizeof(struct xhci_hcd), + .reset = xhci_cdns3_setup, +}; + +struct cdns3_host { + struct device dev; + struct usb_hcd *hcd; +}; + +static irqreturn_t cdns3_host_irq(struct cdns3 *cdns) +{ + struct device *dev = cdns->host_dev; + struct usb_hcd *hcd; + + if (dev) + hcd = dev_get_drvdata(dev); + else + return IRQ_NONE; + + if (hcd) + return usb_hcd_irq(cdns->irq, hcd); + else + return IRQ_NONE; +} + +static void cdns3_host_release(struct device *dev) +{ + struct cdns3_host *host = container_of(dev, struct cdns3_host, dev); + + kfree(host); +} + +static int cdns3_host_start(struct cdns3 *cdns) +{ + struct cdns3_host *host; + struct device *dev; + struct device *sysdev; + struct xhci_hcd *xhci; + int ret; + + host = kzalloc(sizeof(*host), GFP_KERNEL); + if (!host) + return -ENOMEM; + + dev = &host->dev; + dev->release = cdns3_host_release; + dev->parent = cdns->dev; + dev_set_name(dev, "xhci-cdns3"); + cdns->host_dev = dev; + ret = device_register(dev); + if (ret) + goto err1; + + sysdev = cdns->dev; + /* Try to set 64-bit DMA first */ + if (WARN_ON(!sysdev->dma_mask)) + /* Platform did not initialize dma_mask */ + ret = dma_coerce_mask_and_coherent(sysdev, + DMA_BIT_MASK(64)); + else + ret = dma_set_mask_and_coherent(sysdev, DMA_BIT_MASK(64)); + + /* If setting 64-bit DMA mask fails, fall back to 32-bit DMA mask */ + if (ret) { + ret = dma_set_mask_and_coherent(sysdev, DMA_BIT_MASK(32)); + if (ret) + return ret; + } + + pm_runtime_set_active(dev); + pm_runtime_no_callbacks(dev); + pm_runtime_enable(dev); + host->hcd = __usb_create_hcd(&xhci_cdns3_hc_driver, sysdev, dev, + dev_name(dev), NULL); + if (!host->hcd) { + ret = -ENOMEM; + goto err2; + } + + host->hcd->regs = cdns->xhci_regs; + host->hcd->rsrc_start = cdns->xhci_res->start; + host->hcd->rsrc_len = resource_size(cdns->xhci_res); + + device_wakeup_enable(host->hcd->self.controller); + xhci = hcd_to_xhci(host->hcd); + + xhci->main_hcd = host->hcd; + xhci->shared_hcd = __usb_create_hcd(&xhci_cdns3_hc_driver, sysdev, dev, + dev_name(dev), host->hcd); + if (!xhci->shared_hcd) { + ret = -ENOMEM; + goto err3; + } + + host->hcd->tpl_support = of_usb_host_tpl_support(sysdev->of_node); + xhci->shared_hcd->tpl_support = host->hcd->tpl_support; + ret = usb_add_hcd(host->hcd, 0, IRQF_SHARED); + if (ret) + goto err4; + + ret = usb_add_hcd(xhci->shared_hcd, 0, IRQF_SHARED); + if (ret) + goto err5; + + device_set_wakeup_capable(dev, true); + + return 0; + +err5: + usb_remove_hcd(host->hcd); +err4: + usb_put_hcd(xhci->shared_hcd); +err3: + usb_put_hcd(host->hcd); +err2: + device_del(dev); +err1: + put_device(dev); + cdns->host_dev = NULL; + return ret; +} + +static void cdns3_host_stop(struct cdns3 *cdns) +{ + struct device *dev = cdns->host_dev; + struct xhci_hcd *xhci; + struct usb_hcd *hcd; + + if (dev) { + hcd = dev_get_drvdata(dev); + xhci = hcd_to_xhci(hcd); + usb_remove_hcd(xhci->shared_hcd); + usb_remove_hcd(hcd); + synchronize_irq(cdns->irq); + usb_put_hcd(xhci->shared_hcd); + usb_put_hcd(hcd); + cdns->host_dev = NULL; + pm_runtime_set_suspended(dev); + pm_runtime_disable(dev); + device_del(dev); + put_device(dev); + } +} + +#if CONFIG_PM +static int cdns3_host_suspend(struct cdns3 *cdns, bool do_wakeup) +{ + struct device *dev = cdns->host_dev; + struct xhci_hcd *xhci; + + if (!dev) + return 0; + + xhci = hcd_to_xhci(dev_get_drvdata(dev)); + return xhci_suspend(xhci, do_wakeup); +} + +static int cdns3_host_resume(struct cdns3 *cdns, bool hibernated) +{ + struct device *dev = cdns->host_dev; + struct xhci_hcd *xhci; + + if (!dev) + return 0; + + xhci = hcd_to_xhci(dev_get_drvdata(dev)); + return xhci_resume(xhci, hibernated); +} +#endif /* CONFIG_PM */ + +int cdns3_host_init(struct cdns3 *cdns) +{ + struct cdns3_role_driver *rdrv; + + rdrv = devm_kzalloc(cdns->dev, sizeof(*rdrv), GFP_KERNEL); + if (!rdrv) + return -ENOMEM; + + rdrv->start = cdns3_host_start; + rdrv->stop = cdns3_host_stop; + rdrv->irq = cdns3_host_irq; +#if CONFIG_PM + rdrv->suspend = cdns3_host_suspend; + rdrv->resume = cdns3_host_resume; +#endif /* CONFIG_PM */ + rdrv->name = "host"; + cdns->roles[CDNS3_ROLE_HOST] = rdrv; + + return 0; +} + +void cdns3_host_remove(struct cdns3 *cdns) +{ + cdns3_host_stop(cdns); +} + +void __init cdns3_host_driver_init(void) +{ + xhci_init_driver(&xhci_cdns3_hc_driver, &xhci_cdns3_overrides); +} From patchwork Sun Nov 18 10:09:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Laszczak X-Patchwork-Id: 10687729 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A1A17109C for ; Sun, 18 Nov 2018 10:12:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F16A29D38 for ; Sun, 18 Nov 2018 10:12:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 82F6729D43; Sun, 18 Nov 2018 10:12:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38AB929D3E for ; Sun, 18 Nov 2018 10:12:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727647AbeKRUcR (ORCPT ); Sun, 18 Nov 2018 15:32:17 -0500 Received: from mx0b-0014ca01.pphosted.com ([208.86.201.193]:41210 "EHLO mx0a-0014ca01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726269AbeKRUay (ORCPT ); Sun, 18 Nov 2018 15:30:54 -0500 Received: from pps.filterd (m0042333.ppops.net [127.0.0.1]) by mx0b-0014ca01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id wAIA8s10007707; Sun, 18 Nov 2018 02:10:47 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=proofpoint; bh=XnQZ3a4p15TmSZfB/wc1VYtC7gV9U4S7tWUu63wnTYY=; b=oB++1H2g/p2ugDrp4xp/mH2SuieJpT7uECXSbk+efJsgtw9Clj0hpNOHMZUL3MJ1z+Fc 1D9spSl920vUHDZnShl4xhAgMMoNxtILn1E2lmf3WM/gh9/n8dTbeewnCcUi+tZ7q+cb TRWmn3N6vRIgBxO9IxrVZRHR/PjzQAr80dFP8udLntPXXMfxm25VlHWTwH4LNY3r39RJ 8QuLy3AtoD5fz/Zt4bkovEpOI6oqA4N+MM743i2NV3dH9IFWzSqVZDhWaG0mx0LGR5/j 2MPFbKcJ7+iAqN+eBX++asu8y/XTSaC5owcJ9k8ElmyGiovijkoH6NxCDzpqgmYpMA4j Jw== Authentication-Results: cadence.com; spf=pass smtp.mailfrom=pawell@cadence.com Received: from nam03-co1-obe.outbound.protection.outlook.com (mail-co1nam03lp0023.outbound.protection.outlook.com [216.32.181.23]) by mx0b-0014ca01.pphosted.com with ESMTP id 2ntff7w44m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sun, 18 Nov 2018 02:10:47 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XnQZ3a4p15TmSZfB/wc1VYtC7gV9U4S7tWUu63wnTYY=; b=NsjPgkz4jKPofQlON0Zh/MT9lYCVlEqWs1yuACwKRiB/Ssrj94eVcuTiY1kY2NihEDish7J5949HltVPsDuTHbRf4B7472mfI3dg24qg9AuyD93rg44T8MCCFsIC3RuA5mWyXNR3rl/YkHVHOwd+J+g+O79U24LdJxDiY4Sg3/I= Received: from CY1PR07CA0006.namprd07.prod.outlook.com (2a01:111:e400:c60a::16) by DM5PR07MB4104.namprd07.prod.outlook.com (2603:10b6:4:b3::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.23; Sun, 18 Nov 2018 10:10:44 +0000 Received: from DM3NAM05FT059.eop-nam05.prod.protection.outlook.com (2a01:111:f400:7e51::201) by CY1PR07CA0006.outlook.office365.com (2a01:111:e400:c60a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.23 via Frontend Transport; Sun, 18 Nov 2018 10:10:44 +0000 Received-SPF: SoftFail (protection.outlook.com: domain of transitioning cadence.com discourages use of 158.140.1.28 as permitted sender) Received: from sjmaillnx2.cadence.com (158.140.1.28) by DM3NAM05FT059.mail.protection.outlook.com (10.152.98.176) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.3 via Frontend Transport; Sun, 18 Nov 2018 10:10:43 +0000 Received: from maileu3.global.cadence.com (maileu3.cadence.com [10.160.88.99]) by sjmaillnx2.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAb5P029622 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Sun, 18 Nov 2018 02:10:42 -0800 X-CrossPremisesHeadersFilteredBySendConnector: maileu3.global.cadence.com Received: from maileu3.global.cadence.com (10.160.88.99) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Sun, 18 Nov 2018 11:10:42 +0100 Received: from lvlogina.cadence.com (10.165.176.102) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Sun, 18 Nov 2018 11:10:42 +0100 Received: from lvlogina.cadence.com (localhost.localdomain [127.0.0.1]) by lvlogina.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAcAL031344; Sun, 18 Nov 2018 10:10:38 GMT Received: (from pawell@localhost) by lvlogina.cadence.com (8.14.4/8.14.4/Submit) id wAIAAcGL031297; Sun, 18 Nov 2018 10:10:38 GMT From: Pawel Laszczak To: CC: , , , , , , , , , , , , "Pawel Laszczak" Subject: [RFC PATCH v2 07/15] usb:cdns3: Adds Device mode support - initialization. Date: Sun, 18 Nov 2018 10:09:03 +0000 Message-ID: <1542535751-16079-8-git-send-email-pawell@cadence.com> X-Mailer: git-send-email 1.7.11.2 In-Reply-To: <1542535751-16079-1-git-send-email-pawell@cadence.com> References: <1542535751-16079-1-git-send-email-pawell@cadence.com> MIME-Version: 1.0 X-OrganizationHeadersPreserved: maileu3.global.cadence.com X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:158.140.1.28;IPV:CAL;SCL:-1;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(376002)(346002)(136003)(39860400002)(396003)(2980300002)(189003)(199004)(36092001)(6666004)(356004)(217873002)(19627235002)(48376002)(4326008)(50466002)(305945005)(7636002)(2906002)(14444005)(316002)(126002)(486006)(42186006)(446003)(107886003)(86362001)(2616005)(575784001)(11346002)(4744004)(54906003)(16586007)(476003)(5660300001)(36756003)(478600001)(186003)(26826003)(26005)(426003)(87636003)(6916009)(336012)(4720700003)(76176011)(51416003)(106466001)(2351001)(105596002)(8936002)(50226002)(246002)(47776003)(8676002)(309714004);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR07MB4104;H:sjmaillnx2.cadence.com;FPR:;SPF:SoftFail;LANG:en;PTR:corp.cadence.com;MX:1;A:1; X-Microsoft-Exchange-Diagnostics: 1;DM3NAM05FT059;1:pXkEbgaad3yHi0owuRT+CSVHqKwsMdYAPZJ1rg5wU6Bcc7mSvzup/O5a0K4Mtp2/GdvZGVbjUqb3SDKSs9UFyLH4/Ds8uhnrBtdZYA494KKYR3Im3yLvrbRZwCEi09qo X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 256d4a18-52a1-4793-3f17-08d64d3e1a38 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060);SRVR:DM5PR07MB4104; X-Microsoft-Exchange-Diagnostics: 1;DM5PR07MB4104;3:h4LC2ZbkqLAMxY0XKK4CLM9os4SwRgxcAlObMA0fSFvAjy6STA557XdEykeWEIIML/U2ZMRyY81IgsuyE0DSp7J9RmQsCulrETKTt5JK2MDVJYhB/mvY1nubffJ4UZeAUqhMoCRjoQ1CbWI0oRMnI8Ht5qwXMF5T4RaZfU/Lv7hJrQmLqxn7CVwWfx5OnW5wcuz5jyxcjFVRf78pCVSDDr2d6XPWwXcNkqOXG9rVd6Wmec55B72Hf0Xz3J2lng0N7gZWWrZpdxFpncFbXRvQZc7SnJJz616GzPRE96pHVjBiMwxMdew8GWq8415FsMxZZEWQft5Sirv7RPhcakzYF4yRyH/xY8s+K5hf2QG1Wew=;25:VbzYU0KC4AB6J1xiqOMzCeSCLTp3r/pVSrwGgz1d6XL4aoEnZvmQLnCQB63UgKadICN5BojGq3vYrsd4cqzyRfIqARqDMMufC4yEGdfVz84RFcPZ2rcv9li95my9GypO4tUrA86IH0KUN7N3dzyUs2XS+RV01wQekwiSBnsiuKG791Ol6eWd5NqXXefBvJ0IkgXbyWTV8HiHS3GjIP3tjEDWbH9aw+Go7cO9AntkGk76PDmoosnUdQ4+yM0iuOZ/ZauKpoT7uPz1ARk8+xfcOptR6kmEk9fGj6a3Fz7T3gMnQfl6wpn6kj5yIQQHyck+h4cStBbb6ouSm+qpFUS8Ig== X-MS-TrafficTypeDiagnostic: DM5PR07MB4104: X-Microsoft-Exchange-Diagnostics: 1;DM5PR07MB4104;31:LTCoYGqnIKgOKD/etrRgKgzfz1m0nUQOzZti2h9VM/+KyZZ0iL6YfPdDi8xpQBdAwCphudozODRv9fBiogV3AtRG1vWx9JCKrCuE8rB0Y+URV6I1HxJI5q1j4JtLFspUA1qG5KgzxGhvGKk8WXUoDQzUNL8cDNpASNsUuVL/uck2VKsRIoOSn9v1wHkjEvXn3FIe4tLVwqkcpynZHUfe/8p7BrKkl0enMzfNicDgG6M=;20:IyjPJVqBiC0h62KoCzuVbUQfcpuwjeVogu6k5DcpNH8g2SmX4/siXZn5GmMjoo9bYKBmvUyT9Ao6WsGa5Ip+rnZ8i+YTzswRWg0aFXVBHqg79HxUpwTYR4PXd+eeqhD3BrhTmUWEY5Ym1MqcDX9lLmoitWejLl2esiwt+LbOxOn8tz08n9o4Wkb1xdZuaPJdzkIIMtU7CPQCwYAQm4oER/EJ3iYsGnlMcj5Hf0I5Zgy+pYIL07iMwljTSYDQ6nhS/cXmMc8Q0kdXLgroi+c1cRm3KZIW4vN1cACWakv3z71y6Ys/s+JvMPihXE6F36AynxLOKO60NDSvRFjGboyOxoUhbyM7DTI65Fq18nlL3YPmO77j27YGMvaCHtnWN2x/le0hGKDsL6CvJl5azks68TMh+0OUBjFwyV4y1cUa7OQyIHqvFo5pdEf3hw9YP8u8hFqHP6UtdzDWS9S8kPTkD2L04NXis6zTwlfLWWeMbhGgEEefz8FzmQIoA/tIH/Np X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93003095)(3231415)(944501410)(52105112)(10201501046)(3002001)(148016)(149066)(150057)(6041310)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051)(76991095);SRVR:DM5PR07MB4104;BCL:0;PCL:0;RULEID:;SRVR:DM5PR07MB4104; X-Microsoft-Exchange-Diagnostics: 1;DM5PR07MB4104;4:mxFRbBzODMJaaBWZzMkh3iL4a5mO4qOytCYyyN1tBqb/t5YtVvIKkrvM6kJ84O3GiM7CCKRdbB0/judcjgDi5rc0qQuULI5jEwstfrQNdZ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/OsqfvQO2WXX+a1yxM+uGIzs+6EaCsNvrMnP21CN9e/kldw5Sw4RuEhQfYhZ1HitbITZuHxljqXOzNEU2fdtEj17b8t+8NZheTdCfZIxnqXDZLEB1H8bGJXw5HcburCSPOIqX1WtVQSRAqPfy4Ib1elBIImhC7M2YzJrmlFwVoWDBKCfyAVsh9yvQ1bl+kgJFmsdzVmuWGnBqiOjC76BvQ==;5:Yq02rPP3nSpaugad+XPTERbj5qkrkja9SLuHUt6SMjSPlUreZtvh2xXgoASEv59zx0uFnoCjeUkdxysH0sSvIdEPlKreMZnYCiO0qxAa5CIyVn5vpM4lz/tGR+W+VYGdMcqdndxW0AzIPje8M7agBCtDt4UHR6d1tPN2nxbCRNE=;7:QEn6faHWYGAE/zp9vop7ta1VsyhvNQHZHdJdwhyxnBY3YLkCUbO9e2Dp2vvFr/+I5gGOBcX8EsAMta/WCMw0YghsvEskUxE08jqszs3Z4geCSEynnbikr2KMZcAQO+mhGjulKGiqsPwout+bznLiVg== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DM5PR07MB4104;20:8MVwsAV2vURnt8EfgfOsQrjBIxvsBgbelRGJualATf81Bw+NPaCEspUMSp94CJjRqq1MZcq1cP9zsat3VyZpon8waHY4ziT+QndCmHTy9kEh1A9BgdpuguP1ItlzsyztEDiSC66EGVExP771IPedNcBS3cCYsJDI0HU0yfyFttmbl5g+8mUFvF5WIeyPYOd6s5SRBaRk3ggolLnoaFuQRBhFcuAjVpXlERgLYV+JVy/QCisJrfX+e/dXRo8kE+ab X-OriginatorOrg: cadence.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2018 10:10:43.6771 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 256d4a18-52a1-4793-3f17-08d64d3e1a38 X-MS-Exchange-CrossTenant-Id: d36035c5-6ce6-4662-a3dc-e762e61ae4c9 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=d36035c5-6ce6-4662-a3dc-e762e61ae4c9;Ip=[158.140.1.28];Helo=[sjmaillnx2.cadence.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR07MB4104 X-Proofpoint-SPF-Result: pass X-Proofpoint-SPF-Record: v=spf1 a:mx-sanjose2.Cadence.COM a:mx-sanjose4.Cadence.COM a:mx-sanjose5.Cadence.COM include:mktomail.com include:spf-0014ca01.pphosted.com include:spf.protection.outlook.com include:auth.msgapp.com include:spf.mandrillapp.com ~all X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-11-18_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_check_notspam policy=outbound_check score=0 priorityscore=1501 malwarescore=0 suspectscore=4 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=970 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811180097 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Patch implements a set of functions responsible for initialization, configuration, starting and stopping device mode. This patch also adds new ep0.c that holds all functions related to endpoint 0. Signed-off-by: Pawel Laszczak --- drivers/usb/cdns3/Kconfig | 10 + drivers/usb/cdns3/Makefile | 1 + drivers/usb/cdns3/core.c | 5 +- drivers/usb/cdns3/ep0.c | 105 ++++++++ drivers/usb/cdns3/gadget-export.h | 27 +++ drivers/usb/cdns3/gadget.c | 390 ++++++++++++++++++++++++++++++ drivers/usb/cdns3/gadget.h | 4 + 7 files changed, 541 insertions(+), 1 deletion(-) create mode 100644 drivers/usb/cdns3/ep0.c create mode 100644 drivers/usb/cdns3/gadget-export.h create mode 100644 drivers/usb/cdns3/gadget.c diff --git a/drivers/usb/cdns3/Kconfig b/drivers/usb/cdns3/Kconfig index d92bc3d68eb0..b7d71b5c4f60 100644 --- a/drivers/usb/cdns3/Kconfig +++ b/drivers/usb/cdns3/Kconfig @@ -10,6 +10,16 @@ config USB_CDNS3 if USB_CDNS3 +config USB_CDNS3_GADGET + bool "Cadence USB3 device controller" + depends on USB_GADGET + help + Say Y here to enable device controller functionality of the + cadence USBSS-DEV driver. + + This controller support FF, HS and SS mode. It doeasn't support + LS and SSP mode + config USB_CDNS3_HOST bool "Cadence USB3 host controller" depends on USB_XHCI_HCD diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile index 976117ba67ff..bea6173bf37f 100644 --- a/drivers/usb/cdns3/Makefile +++ b/drivers/usb/cdns3/Makefile @@ -2,5 +2,6 @@ obj-$(CONFIG_USB_CDNS3) += cdns3.o obj-$(CONFIG_USB_CDNS3_PCI_WRAP) += cdns3-pci.o cdns3-y := core.o drd.o +cdns3-$(CONFIG_USB_CDNS3_GADGET) += gadget.o ep0.o cdns3-$(CONFIG_USB_CDNS3_HOST) += host.o cdns3-pci-y := cdns3-pci-wrap.o diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c index 4cb820be9ff3..1fa233415901 100644 --- a/drivers/usb/cdns3/core.c +++ b/drivers/usb/cdns3/core.c @@ -18,6 +18,7 @@ #include "gadget.h" #include "core.h" #include "host-export.h" +#include "gadget-export.h" #include "drd.h" static inline struct cdns3_role_driver *cdns3_get_current_role_driver(struct cdns3 *cdns) @@ -104,7 +105,8 @@ static int cdns3_core_init_role(struct cdns3 *cdns) } if (dr_mode == USB_DR_MODE_OTG || dr_mode == USB_DR_MODE_PERIPHERAL) { - //TODO: implements device initialization + if (cdns3_gadget_init(cdns)) + dev_info(dev, "doesn't support gadget\n"); } if (!cdns->roles[CDNS3_ROLE_HOST] && !cdns->roles[CDNS3_ROLE_GADGET]) { @@ -144,6 +146,7 @@ static irqreturn_t cdns3_irq(int irq, void *data) static void cdns3_remove_roles(struct cdns3 *cdns) { + cdns3_gadget_remove(cdns); cdns3_host_remove(cdns); } diff --git a/drivers/usb/cdns3/ep0.c b/drivers/usb/cdns3/ep0.c new file mode 100644 index 000000000000..c08d02665f9d --- /dev/null +++ b/drivers/usb/cdns3/ep0.c @@ -0,0 +1,105 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Cadence USBSS DRD Driver - gadget side. + * + * Copyright (C) 2018 Cadence Design Systems. + * Copyright (C) 2017 NXP + * + * Authors: Pawel Jez , + * Pawel Laszczak + * Peter Chen + */ + +#include "gadget.h" + +static struct usb_endpoint_descriptor cdns3_gadget_ep0_desc = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, + .bmAttributes = USB_ENDPOINT_XFER_CONTROL, +}; + +static void cdns3_prepare_setup_packet(struct cdns3_device *priv_dev) +{ + //TODO: Implements this function +} + +/** + * cdns3_ep0_config - Configures default endpoint + * @priv_dev: extended gadget object + * + * Functions sets parameters: maximal packet size and enables interrupts + */ +void cdns3_ep0_config(struct cdns3_device *priv_dev) +{ + struct cdns3_usb_regs __iomem *regs; + u32 max_packet_size = 64; + + regs = priv_dev->regs; + + if (priv_dev->gadget.speed == USB_SPEED_SUPER) + max_packet_size = 512; + + if (priv_dev->ep0_request) { + list_del_init(&priv_dev->ep0_request->list); + priv_dev->ep0_request = NULL; + } + + priv_dev->gadget.ep0->maxpacket = max_packet_size; + cdns3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(max_packet_size); + + /* init ep out */ + cdns3_select_ep(priv_dev, USB_DIR_OUT); + + writel(EP_CFG_ENABLE | EP_CFG_MAXPKTSIZE(max_packet_size), + ®s->ep_cfg); + + writel(EP_STS_EN_SETUPEN | EP_STS_EN_DESCMISEN | EP_STS_EN_TRBERREN, + ®s->ep_sts_en); + + /* init ep in */ + cdns3_select_ep(priv_dev, USB_DIR_IN); + + writel(EP_CFG_ENABLE | EP_CFG_MAXPKTSIZE(max_packet_size), + ®s->ep_cfg); + + writel(EP_STS_EN_SETUPEN | EP_STS_EN_TRBERREN, ®s->ep_sts_en); + + cdns3_set_register_bit(®s->usb_conf, USB_CONF_U1DS | USB_CONF_U2DS); + cdns3_prepare_setup_packet(priv_dev); +} + +/** + * cdns3_init_ep0 Initializes software endpoint 0 of gadget + * @cdns3: extended gadget object + * + * Returns 0 on success, error code elsewhere + */ +int cdns3_init_ep0(struct cdns3_device *priv_dev) +{ + struct cdns3_endpoint *ep0; + + ep0 = devm_kzalloc(&priv_dev->dev, sizeof(struct cdns3_endpoint), + GFP_KERNEL); + + if (!ep0) + return -ENOMEM; + + ep0->cdns3_dev = priv_dev; + sprintf(ep0->name, "ep0"); + + /* fill linux fields */ + //TODO: implements cdns3_gadget_ep0_ops object + //ep0->endpoint.ops = &cdns3_gadget_ep0_ops; + ep0->endpoint.maxburst = 1; + usb_ep_set_maxpacket_limit(&ep0->endpoint, ENDPOINT0_MAX_PACKET_LIMIT); + ep0->endpoint.address = 0; + ep0->endpoint.caps.type_control = 1; + ep0->endpoint.caps.dir_in = 1; + ep0->endpoint.caps.dir_out = 1; + ep0->endpoint.name = ep0->name; + ep0->endpoint.desc = &cdns3_gadget_ep0_desc; + priv_dev->gadget.ep0 = &ep0->endpoint; + INIT_LIST_HEAD(&ep0->request_list); + + return 0; +} diff --git a/drivers/usb/cdns3/gadget-export.h b/drivers/usb/cdns3/gadget-export.h new file mode 100644 index 000000000000..257e5e0eef31 --- /dev/null +++ b/drivers/usb/cdns3/gadget-export.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Cadence USBSS DRD Driver -Gadget Export APIs + * + * Copyright (C) 2017 NXP + * + * Authors: Peter Chen + */ +#ifndef __LINUX_CDNS3_GADGET_EXPORT +#define __LINUX_CDNS3_GADGET_EXPORT + +#ifdef CONFIG_USB_CDNS3_GADGET + +int cdns3_gadget_init(struct cdns3 *cdns); +void cdns3_gadget_remove(struct cdns3 *cdns); +#else + +static inline int cdns3_gadget_init(struct cdns3 *cdns) +{ + return -ENXIO; +} + +static inline void cdns3_gadget_remove(struct cdns3 *cdns) { } + +#endif + +#endif /* __LINUX_CDNS3_GADGET_EXPORT */ diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c new file mode 100644 index 000000000000..376b68b13d1b --- /dev/null +++ b/drivers/usb/cdns3/gadget.c @@ -0,0 +1,390 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Cadence USBSS DRD Driver - gadget side. + * + * Copyright (C) 2018 Cadence Design Systems. + * Copyright (C) 2017 NXP + * + * Authors: Pawel Jez , + * Pawel Laszczak + * Peter Chen + */ + +#include +#include + +#include "core.h" +#include "gadget-export.h" +#include "gadget.h" + +/** + * cdns3_set_register_bit - set bit in given register. + * @ptr: address of device controller register to be read and changed + * @mask: bits requested to set + */ +void cdns3_set_register_bit(void __iomem *ptr, u32 mask) +{ + mask = readl(ptr) | mask; + writel(mask, ptr); +} + +/** + * select_ep - selects endpoint + * @priv_dev: extended gadget object + * @ep: endpoint address + */ +void cdns3_select_ep(struct cdns3_device *priv_dev, u32 ep) +{ + if (priv_dev->selected_ep == ep) + return; + + dev_dbg(&priv_dev->dev, "Ep sel: 0x%02x\n", ep); + priv_dev->selected_ep = ep; + writel(ep, &priv_dev->regs->ep_sel); +} + +/** + * cdns3_irq_handler - irq line interrupt handler + * @cdns: cdns3 instance + * + * Returns IRQ_HANDLED when interrupt raised by USBSS_DEV, + * IRQ_NONE when interrupt raised by other device connected + * to the irq line + */ +static irqreturn_t cdns3_irq_handler_thread(struct cdns3 *cdns) +{ + irqreturn_t ret = IRQ_NONE; + //TODO: implements this function + return ret; +} + +static void cdns3_gadget_config(struct cdns3_device *priv_dev) +{ + struct cdns3_usb_regs __iomem *regs = priv_dev->regs; + + cdns3_ep0_config(priv_dev); + + /* enable interrupts for endpoint 0 (in and out) */ + writel(EP_IEN_EP_OUT0 | EP_IEN_EP_IN0, ®s->ep_ien); + + /* enable generic interrupt*/ + writel(USB_IEN_INIT, ®s->usb_ien); + writel(USB_CONF_CLK2OFFDS | USB_CONF_L1DS, ®s->usb_conf); + writel(USB_CONF_DMULT, ®s->usb_conf); + writel(USB_CONF_DEVEN, ®s->usb_conf); +} + +/** + * cdns3_init_ep Initializes software endpoints of gadget + * @cdns3: extended gadget object + * + * Returns 0 on success, error code elsewhere + */ +static int cdns3_init_ep(struct cdns3_device *priv_dev) +{ + u32 ep_enabled_reg, iso_ep_reg; + struct cdns3_endpoint *priv_ep; + int found_endpoints = 0; + int ep_dir, ep_number; + u32 ep_mask; + int i; + + /* Read it from USB_CAP3 to USB_CAP5 */ + ep_enabled_reg = readl(&priv_dev->regs->usb_cap3); + iso_ep_reg = readl(&priv_dev->regs->usb_cap4); + + dev_dbg(&priv_dev->dev, "Initializing non-zero endpoints\n"); + + for (i = 0; i < USB_SS_ENDPOINTS_MAX_COUNT; i++) { + ep_number = (i / 2) + 1; + ep_dir = i % 2; + ep_mask = BIT((16 * ep_dir) + ep_number); + + if (!(ep_enabled_reg & ep_mask)) + continue; + + priv_ep = devm_kzalloc(&priv_dev->dev, sizeof(*priv_ep), + GFP_KERNEL); + if (!priv_ep) + return -ENOMEM; + + /* set parent of endpoint object */ + priv_ep->cdns3_dev = priv_dev; + priv_dev->eps[found_endpoints++] = priv_ep; + + snprintf(priv_ep->name, sizeof(priv_ep->name), "ep%d%s", + ep_number, !!ep_dir ? "in" : "out"); + priv_ep->endpoint.name = priv_ep->name; + + usb_ep_set_maxpacket_limit(&priv_ep->endpoint, + ENDPOINT_MAX_PACKET_LIMIT); + priv_ep->endpoint.max_streams = ENDPOINT_MAX_STREAMS; + //TODO: Add implementation of cdns3_gadget_ep_ops + //priv_ep->endpoint.ops = &cdns3_gadget_ep_ops; + if (ep_dir) + priv_ep->endpoint.caps.dir_in = 1; + else + priv_ep->endpoint.caps.dir_out = 1; + + if (iso_ep_reg & ep_mask) + priv_ep->endpoint.caps.type_iso = 1; + + priv_ep->endpoint.caps.type_bulk = 1; + priv_ep->endpoint.caps.type_int = 1; + priv_ep->endpoint.maxburst = CDNS3_EP_BUF_SIZE - 1; + + priv_ep->flags = 0; + + dev_info(&priv_dev->dev, "Initialized %s support: %s %s\n", + priv_ep->name, + priv_ep->endpoint.caps.type_bulk ? "BULK, INT" : "", + priv_ep->endpoint.caps.type_iso ? "ISO" : ""); + + list_add_tail(&priv_ep->endpoint.ep_list, + &priv_dev->gadget.ep_list); + INIT_LIST_HEAD(&priv_ep->request_list); + INIT_LIST_HEAD(&priv_ep->ep_match_pending_list); + } + + priv_dev->ep_nums = found_endpoints; + return 0; +} + +static void cdns3_gadget_release(struct device *dev) +{ + struct cdns3_device *priv_dev; + + priv_dev = container_of(dev, struct cdns3_device, dev); + kfree(priv_dev); +} + +static int __cdns3_gadget_init(struct cdns3 *cdns) +{ + struct cdns3_device *priv_dev; + struct device *dev; + int ret; + + priv_dev = kzalloc(sizeof(*priv_dev), GFP_KERNEL); + if (!priv_dev) + return -ENOMEM; + + dev = &priv_dev->dev; + dev->release = cdns3_gadget_release; + dev->parent = cdns->dev; + dev_set_name(dev, "gadget-cdns3"); + cdns->gadget_dev = dev; + + priv_dev->sysdev = cdns->dev; + ret = device_register(dev); + if (ret) + goto err1; + + priv_dev->regs = cdns->dev_regs; + + /* fill gadget fields */ + priv_dev->gadget.max_speed = USB_SPEED_SUPER; + priv_dev->gadget.speed = USB_SPEED_UNKNOWN; + //TODO: Add implementation of cdns3_gadget_ops + //priv_dev->gadget.ops = &cdns3_gadget_ops; + priv_dev->gadget.name = "usb-ss-gadget"; + priv_dev->gadget.sg_supported = 1; + priv_dev->is_connected = 0; + + spin_lock_init(&priv_dev->lock); + + priv_dev->in_standby_mode = 1; + + /* initialize endpoint container */ + INIT_LIST_HEAD(&priv_dev->gadget.ep_list); + INIT_LIST_HEAD(&priv_dev->ep_match_list); + + ret = cdns3_init_ep0(priv_dev); + if (ret) { + dev_err(dev, "Failed to create endpoint 0\n"); + ret = -ENOMEM; + goto err2; + } + + ret = cdns3_init_ep(priv_dev); + if (ret) { + dev_err(dev, "Failed to create non zero endpoints\n"); + ret = -ENOMEM; + goto err2; + } + + /* allocate memory for default endpoint TRB */ + priv_dev->trb_ep0 = dma_alloc_coherent(priv_dev->sysdev, 24, + &priv_dev->trb_ep0_dma, GFP_DMA); + if (!priv_dev->trb_ep0) { + dev_err(dev, "Failed to allocate memory for ep0 TRB\n"); + ret = -ENOMEM; + goto err2; + } + + /* allocate memory for setup packet buffer */ + priv_dev->setup = dma_alloc_coherent(priv_dev->sysdev, 8, + &priv_dev->setup_dma, GFP_DMA); + if (!priv_dev->setup) { + dev_err(dev, "Failed to allocate memory for SETUP buffer\n"); + ret = -ENOMEM; + goto err3; + } + + dev_dbg(dev, "Device Controller version: %08x\n", + readl(&priv_dev->regs->usb_cap6)); + dev_dbg(dev, "USB Capabilities:: %08x\n", + readl(&priv_dev->regs->usb_cap1)); + dev_dbg(dev, "On-Chip memory cnfiguration: %08x\n", + readl(&priv_dev->regs->usb_cap2)); + + /* add USB gadget device */ + ret = usb_add_gadget_udc(&priv_dev->dev, &priv_dev->gadget); + if (ret < 0) { + dev_err(dev, "Failed to register USB device controller\n"); + goto err4; + } + + priv_dev->zlp_buf = kzalloc(ENDPOINT_ZLP_BUF_SIZE, GFP_KERNEL); + if (!priv_dev->zlp_buf) { + ret = -ENOMEM; + goto err4; + } + + return 0; +err4: + dma_free_coherent(priv_dev->sysdev, 8, priv_dev->setup, + priv_dev->setup_dma); +err3: + dma_free_coherent(priv_dev->sysdev, TRB_SIZE * 2, priv_dev->trb_ep0, + priv_dev->trb_ep0_dma); +err2: + device_del(dev); +err1: + put_device(dev); + cdns->gadget_dev = NULL; + return ret; +} + +/** + * cdns3_gadget_remove: parent must call this to remove UDC + * + * cdns: cdns3 instance + */ +void cdns3_gadget_remove(struct cdns3 *cdns) +{ + struct cdns3_device *priv_dev; + + if (!cdns->roles[CDNS3_ROLE_GADGET]) + return; + + priv_dev = container_of(cdns->gadget_dev, struct cdns3_device, dev); + usb_del_gadget_udc(&priv_dev->gadget); + dma_free_coherent(priv_dev->sysdev, 8, priv_dev->setup, + priv_dev->setup_dma); + dma_free_coherent(priv_dev->sysdev, TRB_SIZE * 2, priv_dev->trb_ep0, + priv_dev->trb_ep0_dma); + device_unregister(cdns->gadget_dev); + cdns->gadget_dev = NULL; + kfree(priv_dev->zlp_buf); +} + +static int cdns3_gadget_start(struct cdns3 *cdns) +{ + struct cdns3_device *priv_dev = container_of(cdns->gadget_dev, + struct cdns3_device, dev); + unsigned long flags; + + pm_runtime_get_sync(cdns->dev); + spin_lock_irqsave(&priv_dev->lock, flags); + priv_dev->start_gadget = 1; + + if (!priv_dev->gadget_driver) { + spin_unlock_irqrestore(&priv_dev->lock, flags); + return 0; + } + + cdns3_gadget_config(priv_dev); + priv_dev->in_standby_mode = 0; + spin_unlock_irqrestore(&priv_dev->lock, flags); + return 0; +} + +static void __cdns3_gadget_stop(struct cdns3 *cdns) +{ + struct cdns3_device *priv_dev; + unsigned long flags; + + priv_dev = container_of(cdns->gadget_dev, struct cdns3_device, dev); + + if (priv_dev->gadget_driver) + priv_dev->gadget_driver->disconnect(&priv_dev->gadget); + + usb_gadget_disconnect(&priv_dev->gadget); + spin_lock_irqsave(&priv_dev->lock, flags); + priv_dev->gadget.speed = USB_SPEED_UNKNOWN; + + /* disable interrupt for device */ + writel(0, &priv_dev->regs->usb_ien); + writel(USB_CONF_DEVDS, &priv_dev->regs->usb_conf); + priv_dev->start_gadget = 0; + spin_unlock_irqrestore(&priv_dev->lock, flags); +} + +static void cdns3_gadget_stop(struct cdns3 *cdns) +{ + if (cdns->role == CDNS3_ROLE_GADGET) + __cdns3_gadget_stop(cdns); + + pm_runtime_mark_last_busy(cdns->dev); + pm_runtime_put_autosuspend(cdns->dev); +} + +static int cdns3_gadget_suspend(struct cdns3 *cdns, bool do_wakeup) +{ + __cdns3_gadget_stop(cdns); + return 0; +} + +static int cdns3_gadget_resume(struct cdns3 *cdns, bool hibernated) +{ + struct cdns3_device *priv_dev; + unsigned long flags; + + priv_dev = container_of(cdns->gadget_dev, struct cdns3_device, dev); + spin_lock_irqsave(&priv_dev->lock, flags); + priv_dev->start_gadget = 1; + if (!priv_dev->gadget_driver) { + spin_unlock_irqrestore(&priv_dev->lock, flags); + return 0; + } + + cdns3_gadget_config(priv_dev); + priv_dev->in_standby_mode = 0; + spin_unlock_irqrestore(&priv_dev->lock, flags); + return 0; +} + +/** + * cdns3_gadget_init - initialize device structure + * + * cdns: cdns3 instance + * + * This function initializes the gadget. + */ +int cdns3_gadget_init(struct cdns3 *cdns) +{ + struct cdns3_role_driver *rdrv; + + rdrv = devm_kzalloc(cdns->dev, sizeof(*rdrv), GFP_KERNEL); + if (!rdrv) + return -ENOMEM; + + rdrv->start = cdns3_gadget_start; + rdrv->stop = cdns3_gadget_stop; + rdrv->suspend = cdns3_gadget_suspend; + rdrv->resume = cdns3_gadget_resume; + rdrv->irq = cdns3_irq_handler_thread; + rdrv->name = "gadget"; + cdns->roles[CDNS3_ROLE_GADGET] = rdrv; + return __cdns3_gadget_init(cdns); +} diff --git a/drivers/usb/cdns3/gadget.h b/drivers/usb/cdns3/gadget.h index 75ca6214e79a..3b0d4d2e4831 100644 --- a/drivers/usb/cdns3/gadget.h +++ b/drivers/usb/cdns3/gadget.h @@ -1068,4 +1068,8 @@ struct cdns3_device { struct usb_request *pending_status_request; }; +void cdns3_set_register_bit(void __iomem *ptr, u32 mask); +int cdns3_init_ep0(struct cdns3_device *priv_dev); +void cdns3_ep0_config(struct cdns3_device *priv_dev); +void cdns3_select_ep(struct cdns3_device *priv_dev, u32 ep); #endif /* __LINUX_CDNS3_GADGET */ From patchwork Sun Nov 18 10:09:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Laszczak X-Patchwork-Id: 10687733 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D3F80109C for ; Sun, 18 Nov 2018 10:12:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF96B29D38 for ; Sun, 18 Nov 2018 10:12:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE7F629D47; Sun, 18 Nov 2018 10:12:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CFB7D29D38 for ; Sun, 18 Nov 2018 10:12:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727188AbeKRUcb (ORCPT ); Sun, 18 Nov 2018 15:32:31 -0500 Received: from mx0a-0014ca01.pphosted.com ([208.84.65.235]:36314 "EHLO mx0a-0014ca01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726258AbeKRUay (ORCPT ); Sun, 18 Nov 2018 15:30:54 -0500 Received: from pps.filterd (m0042385.ppops.net [127.0.0.1]) by mx0a-0014ca01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id wAIA6m2U016126; Sun, 18 Nov 2018 02:10:51 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=proofpoint; bh=Arf43ZtvLsNPLtnGOxAd4T17ad51DKPvS5I3RCNruZ0=; b=Eo+cPsOEwrH28gMYbFNDLCtEXD5XHPhWHguhM907GhSCuDyIx//NYDe9BiEF4P00Wij0 rDn66rvpIzpUs6yZCcGJ+EzSa4Jv3fGuASt9kzSsYSI++O3TdeKSlahFSJ5LILVL+f3B ZbNiXfyiklxAV+BaDdiGE77A2vaUXZrQU6Yw/Sa+g0/CxE6MXyj5vCigU3dWpf3P4qHN n4ErTMRaO4ahGgVKQNc3e3WZjgN21LtDdJs50tgITTNeVtUgH70+hGAEJBvWNUUO5ENB xV2JQv+eRKvAy3dtQYghC3fWjERQBk9Um8uAFmR1s3rCTnXe3x1EkK8stJyS+qMby01G fg== Authentication-Results: cadence.com; spf=pass smtp.mailfrom=pawell@cadence.com Received: from nam03-dm3-obe.outbound.protection.outlook.com (mail-dm3nam03lp0016.outbound.protection.outlook.com [207.46.163.16]) by mx0a-0014ca01.pphosted.com with ESMTP id 2ntge14vgc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sun, 18 Nov 2018 02:10:51 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Arf43ZtvLsNPLtnGOxAd4T17ad51DKPvS5I3RCNruZ0=; b=Fm4rnqng01o85BwSAJuURV34uQBugaVUFl6tG9O3ounv2e0I9mw2BRY/HkXY57OS7sgEUrDxurI0BvMl/v+wdzQ03/gsYIDxjjBMceJbc/DSBNykolGX7JX1CZAaqbzgr9vVTBUqj4DDXyx+QKUJj4mVL+4xcCvMTPfnsDbQ+wQ= Received: from BYAPR07CA0039.namprd07.prod.outlook.com (2603:10b6:a03:60::16) by SN1PR07MB4112.namprd07.prod.outlook.com (2603:10b6:802:30::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.23; Sun, 18 Nov 2018 10:10:48 +0000 Received: from CO1NAM05FT032.eop-nam05.prod.protection.outlook.com (2a01:111:f400:7e50::203) by BYAPR07CA0039.outlook.office365.com (2603:10b6:a03:60::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.20 via Frontend Transport; Sun, 18 Nov 2018 10:10:48 +0000 Received-SPF: SoftFail (protection.outlook.com: domain of transitioning cadence.com discourages use of 158.140.1.28 as permitted sender) Received: from sjmaillnx2.cadence.com (158.140.1.28) by CO1NAM05FT032.mail.protection.outlook.com (10.152.96.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.3 via Frontend Transport; Sun, 18 Nov 2018 10:10:44 +0000 Received: from maileu3.global.cadence.com (maileu3.cadence.com [10.160.88.99]) by sjmaillnx2.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAb5Q029622 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Sun, 18 Nov 2018 02:10:43 -0800 X-CrossPremisesHeadersFilteredBySendConnector: maileu3.global.cadence.com Received: from maileu3.global.cadence.com (10.160.88.99) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Sun, 18 Nov 2018 11:10:42 +0100 Received: from lvlogina.cadence.com (10.165.176.102) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Sun, 18 Nov 2018 11:10:42 +0100 Received: from lvlogina.cadence.com (localhost.localdomain [127.0.0.1]) by lvlogina.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAdvO031498; Sun, 18 Nov 2018 10:10:39 GMT Received: (from pawell@localhost) by lvlogina.cadence.com (8.14.4/8.14.4/Submit) id wAIAAcZK031458; Sun, 18 Nov 2018 10:10:38 GMT From: Pawel Laszczak To: CC: , , , , , , , , , , , , "Pawel Laszczak" Subject: [RFC PATCH v2 08/15] usb:cdns3: Implements device operations part of the API Date: Sun, 18 Nov 2018 10:09:04 +0000 Message-ID: <1542535751-16079-9-git-send-email-pawell@cadence.com> X-Mailer: git-send-email 1.7.11.2 In-Reply-To: <1542535751-16079-1-git-send-email-pawell@cadence.com> References: <1542535751-16079-1-git-send-email-pawell@cadence.com> MIME-Version: 1.0 X-OrganizationHeadersPreserved: maileu3.global.cadence.com X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:158.140.1.28;IPV:CAL;SCL:-1;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(346002)(376002)(136003)(396003)(39860400002)(2980300002)(36092001)(199004)(189003)(50466002)(48376002)(316002)(42186006)(26826003)(16586007)(305945005)(87636003)(7636002)(478600001)(54906003)(11346002)(446003)(8936002)(426003)(50226002)(486006)(476003)(8676002)(126002)(2616005)(336012)(5660300001)(246002)(76176011)(86362001)(51416003)(186003)(26005)(2351001)(105596002)(106466001)(47776003)(2906002)(36756003)(217873002)(14444005)(356004)(6666004)(4326008)(6916009)(107886003)(4720700003)(309714004);DIR:OUT;SFP:1101;SCL:1;SRVR:SN1PR07MB4112;H:sjmaillnx2.cadence.com;FPR:;SPF:SoftFail;LANG:en;PTR:corp.cadence.com;A:1;MX:1; X-Microsoft-Exchange-Diagnostics: 1;CO1NAM05FT032;1:IcD8cP822NapHUO4lWQml/oa7tct4wuIdn0eEck6w7h0JKw0/xdEKE2zHmw+5FgN37ND1uJYZ3dMx/91nMxV6eIkyNCgWG9ETfIQ+XgczY648NK3s06QQlwbVyLoedjS X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a93ef498-d0d2-43db-1fd5-08d64d3e1c6e X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060);SRVR:SN1PR07MB4112; X-Microsoft-Exchange-Diagnostics: 1;SN1PR07MB4112;3:i8Oel7C4m34Ui7psLOgd/51sVkG/4mLDXGkzs3PXfNIxDVps4UeBqmeZB29/7ND58RWs/QQXAPAluWyds2Wy0zvUB08SSm7uyCcG5w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DtbSVjvs78bYKN1qQ/WHbEtIrTiTV0U0muDQUurITKn8z2vpCOJVk87tRMMTdt1xa4kSRyb02RycMK4EOEKdvbZA3apTQB+0c4ZKvlNV03ogNlYFykB49yHHf9lgBhSH7JUhQeOx1ow0c4XtBhk77bZ+nWIGgxrXDkqn78zzIiTeZNO9XMo04HYmfLLKzrdzltFpjiHxxaVv/rtRb9zMieEhvudS3blnTPzjc8Byp6ppHHDCq4cLHj0x5pZSU9Blw1R6S3nlyqqoXlGqUc8XjUeAk02StaTD8GwbNjViIGH7RGRRHgJvT+6jXUHCJbjIijAsUztZ/cnH4tlqIvTUhAvrcZoYLrk+vonqgoAw5N+o X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(93006095)(93003095)(10201501046)(3002001)(3231415)(944501410)(52105112)(148016)(149066)(150057)(6041310)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(20161123560045)(201708071742011)(7699051)(76991095);SRVR:SN1PR07MB4112;BCL:0;PCL:0;RULEID:;SRVR:SN1PR07MB4112; X-Microsoft-Exchange-Diagnostics: 1;SN1PR07MB4112;4:kOl+AfkoaKYItysjNcxThq9fQHk4wHHCe8BaS+54S1bQpCoW1VO/KW5q7Y6bfbI0vuQrVfBfPB9dugDeMyA1tampqnIjwXOiw/f6URXgp7qqyg951cECON6r3y2XOZr4a29ZwfBfG1dTrwoh0f0gjxU5t+uAIvfoGCA/8dMgjIAtcZIlLG9YWhEJZPI7YkNK6NoTtMveBPK3/42jFX56I5SjNxmAv15ufr0ECPj5eAoxWVCWucTcAOWVLKRjYNiyaS9fRgPtqT/fvmujHaW8zA== X-Forefront-PRVS: 0860FE717F X-Microsoft-Exchange-Diagnostics: 1;SN1PR07MB4112;23:H/0SJugcatVAThZKG/NQDb6MXDeqEEoeJmCaKT1nvV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qFGvb5tORDDN4UvtVr62s2WGG7uWriuGz6mCfRHp9OIUvJCvPMnoUM0So+rw=;7:NhGNnflUJ+vt3SrHkhP4khFjYRsavL9CxeKA2ZBG/zpvUUcgxKgGhz3JoCveyLx+37/KLB8eKXrAdDy2h/eo76TNPvnLB3okRzieMUaT211QQIIfj/NxIN2dIq7Oi41Z0EX4e5sB6jsKFMuf2rCZDg== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;SN1PR07MB4112;20:I7QahwH2v/cCFtUM8OfTfg51lEqCbl5qjYY0rYhJN3TddTYwTbAKQ/NiEr8NOI8RlAJNCLvjA5NNbUUGibeRZU17VANO5B+xOEe8xs6jQBGE+xWAGIgUbjO4kfB40I5fItPn+5Yi8DXOkMxLAZA+Y/53odIbHpaiLpcL5KyK2o9xTxwLTULdkT0j2TD41tbRjt7Yzlfv6vCsqkJH6Ep5CUdu2cr3o47NLmRur7cZda9NRozHZntI8kXjAgvjPF+g X-OriginatorOrg: cadence.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2018 10:10:44.4949 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a93ef498-d0d2-43db-1fd5-08d64d3e1c6e X-MS-Exchange-CrossTenant-Id: d36035c5-6ce6-4662-a3dc-e762e61ae4c9 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=d36035c5-6ce6-4662-a3dc-e762e61ae4c9;Ip=[158.140.1.28];Helo=[sjmaillnx2.cadence.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR07MB4112 X-Proofpoint-SPF-Result: pass X-Proofpoint-SPF-Record: v=spf1 a:mx-sanjose2.Cadence.COM a:mx-sanjose4.Cadence.COM a:mx-sanjose5.Cadence.COM include:mktomail.com include:spf-0014ca01.pphosted.com include:spf.protection.outlook.com include:auth.msgapp.com include:spf.mandrillapp.com ~all X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-11-18_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_check_notspam policy=outbound_check score=0 priorityscore=1501 malwarescore=0 suspectscore=4 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811180096 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Patch adds implementation callback function defined in usb_gadget_ops object. Signed-off-by: Pawel Laszczak --- drivers/usb/cdns3/gadget.c | 249 ++++++++++++++++++++++++++++++++++++- 1 file changed, 247 insertions(+), 2 deletions(-) diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c index 376b68b13d1b..702a05faa664 100644 --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/gadget.c @@ -17,6 +17,36 @@ #include "gadget-export.h" #include "gadget.h" +/** + * cdns3_handshake - spin reading until handshake completes or fails + * @ptr: address of device controller register to be read + * @mask: bits to look at in result of read + * @done: value of those bits when handshake succeeds + * @usec: timeout in microseconds + * + * Returns negative errno, or zero on success + * + * Success happens when the "mask" bits have the specified value (hardware + * handshake done). There are two failure modes: "usec" have passed (major + * hardware flakeout), or the register reads as all-ones (hardware removed). + */ +int cdns3_handshake(void __iomem *ptr, u32 mask, u32 done, int usec) +{ + u32 result; + + do { + result = readl(ptr); + if (result == ~(u32)0) /* card removed */ + return -ENODEV; + result &= mask; + if (result == done) + return 0; + udelay(1); + usec--; + } while (usec > 0); + return -ETIMEDOUT; +} + /** * cdns3_set_register_bit - set bit in given register. * @ptr: address of device controller register to be read and changed @@ -43,6 +73,25 @@ void cdns3_select_ep(struct cdns3_device *priv_dev, u32 ep) writel(ep, &priv_dev->regs->ep_sel); } +static void cdns3_free_trb_pool(struct cdns3_endpoint *priv_ep) +{ + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + + if (priv_ep->trb_pool) { + dma_free_coherent(priv_dev->sysdev, + TRB_RIGN_SIZE, + priv_ep->trb_pool, priv_ep->trb_pool_dma); + priv_ep->trb_pool = NULL; + } + + if (priv_ep->aligned_buff) { + dma_free_coherent(priv_dev->sysdev, CDNS3_UNALIGNED_BUF_SIZE, + priv_ep->aligned_buff, + priv_ep->aligned_dma_addr); + priv_ep->aligned_buff = NULL; + } +} + /** * cdns3_irq_handler - irq line interrupt handler * @cdns: cdns3 instance @@ -58,6 +107,114 @@ static irqreturn_t cdns3_irq_handler_thread(struct cdns3 *cdns) return ret; } +/* Find correct direction for HW endpoint according to description */ +static int cdns3_ep_dir_is_correct(struct usb_endpoint_descriptor *desc, + struct cdns3_endpoint *priv_ep) +{ + return (priv_ep->endpoint.caps.dir_in && usb_endpoint_dir_in(desc)) || + (priv_ep->endpoint.caps.dir_out && usb_endpoint_dir_out(desc)); +} + +static struct cdns3_endpoint *cdns3_find_available_ss_ep(struct cdns3_device *priv_dev, + struct usb_endpoint_descriptor *desc) +{ + struct usb_ep *ep; + struct cdns3_endpoint *priv_ep; + + list_for_each_entry(ep, &priv_dev->gadget.ep_list, ep_list) { + unsigned long num; + int ret; + /* ep name pattern likes epXin or epXout */ + char c[2] = {ep->name[2], '\0'}; + + ret = kstrtoul(c, 10, &num); + if (ret) + return ERR_PTR(ret); + + priv_ep = ep_to_cdns3_ep(ep); + if (cdns3_ep_dir_is_correct(desc, priv_ep)) { + if (!(priv_ep->flags & EP_USED)) { + priv_ep->num = num; + priv_ep->flags |= EP_USED; + return priv_ep; + } + } + } + return ERR_PTR(-ENOENT); +} + +static struct usb_ep *cdns3_gadget_match_ep(struct usb_gadget *gadget, + struct usb_endpoint_descriptor *desc, + struct usb_ss_ep_comp_descriptor *comp_desc) +{ + struct cdns3_device *priv_dev = gadget_to_cdns3_device(gadget); + struct cdns3_endpoint *priv_ep; + unsigned long flags; + + priv_ep = cdns3_find_available_ss_ep(priv_dev, desc); + if (IS_ERR(priv_ep)) { + dev_err(&priv_dev->dev, "no available ep\n"); + return NULL; + } + + dev_dbg(&priv_dev->dev, "match endpoint: %s\n", priv_ep->name); + + spin_lock_irqsave(&priv_dev->lock, flags); + priv_ep->endpoint.desc = desc; + priv_ep->dir = usb_endpoint_dir_in(desc) ? USB_DIR_IN : USB_DIR_OUT; + priv_ep->type = usb_endpoint_type(desc); + + list_add_tail(&priv_ep->ep_match_pending_list, + &priv_dev->ep_match_list); + spin_unlock_irqrestore(&priv_dev->lock, flags); + return &priv_ep->endpoint; +} + +/** + * cdns3_gadget_get_frame Returns number of actual ITP frame + * @gadget: gadget object + * + * Returns number of actual ITP frame + */ +static int cdns3_gadget_get_frame(struct usb_gadget *gadget) +{ + struct cdns3_device *priv_dev = gadget_to_cdns3_device(gadget); + + return readl(&priv_dev->regs->usb_iptn); +} + +static int cdns3_gadget_wakeup(struct usb_gadget *gadget) +{ + return 0; +} + +static int cdns3_gadget_set_selfpowered(struct usb_gadget *gadget, + int is_selfpowered) +{ + struct cdns3_device *priv_dev = gadget_to_cdns3_device(gadget); + unsigned long flags; + + spin_lock_irqsave(&priv_dev->lock, flags); + gadget->is_selfpowered = !!is_selfpowered; + spin_unlock_irqrestore(&priv_dev->lock, flags); + return 0; +} + +static int cdns3_gadget_pullup(struct usb_gadget *gadget, int is_on) +{ + struct cdns3_device *priv_dev = gadget_to_cdns3_device(gadget); + + if (!priv_dev->start_gadget) + return 0; + + if (is_on) + writel(USB_CONF_DEVEN, &priv_dev->regs->usb_conf); + else + writel(USB_CONF_DEVDS, &priv_dev->regs->usb_conf); + + return 0; +} + static void cdns3_gadget_config(struct cdns3_device *priv_dev) { struct cdns3_usb_regs __iomem *regs = priv_dev->regs; @@ -74,6 +231,95 @@ static void cdns3_gadget_config(struct cdns3_device *priv_dev) writel(USB_CONF_DEVEN, ®s->usb_conf); } +/** + * cdns3_gadget_udc_start Gadget start + * @gadget: gadget object + * @driver: driver which operates on this gadget + * + * Returns 0 on success, error code elsewhere + */ +static int cdns3_gadget_udc_start(struct usb_gadget *gadget, + struct usb_gadget_driver *driver) +{ + struct cdns3_device *priv_dev = gadget_to_cdns3_device(gadget); + unsigned long flags; + + if (priv_dev->gadget_driver) { + dev_err(&priv_dev->dev, "%s is already bound to %s\n", + priv_dev->gadget.name, + priv_dev->gadget_driver->driver.name); + return -EBUSY; + } + + spin_lock_irqsave(&priv_dev->lock, flags); + priv_dev->gadget_driver = driver; + if (!priv_dev->start_gadget) + goto unlock; + + cdns3_gadget_config(priv_dev); +unlock: + spin_unlock_irqrestore(&priv_dev->lock, flags); + return 0; +} + +/** + * cdns3_gadget_udc_stop Stops gadget + * @gadget: gadget object + * + * Returns 0 + */ +static int cdns3_gadget_udc_stop(struct usb_gadget *gadget) +{ + struct cdns3_device *priv_dev = gadget_to_cdns3_device(gadget); + struct cdns3_endpoint *priv_ep, *temp_ep; + u32 bEndpointAddress; + struct usb_ep *ep; + int ret = 0; + int i; + + priv_dev->gadget_driver = NULL; + list_for_each_entry_safe(priv_ep, temp_ep, &priv_dev->ep_match_list, + ep_match_pending_list) { + list_del(&priv_ep->ep_match_pending_list); + priv_ep->flags &= ~EP_USED; + } + + priv_dev->onchip_mem_allocated_size = 0; + priv_dev->out_mem_is_allocated = 0; + priv_dev->gadget.speed = USB_SPEED_UNKNOWN; + + for (i = 0; i < priv_dev->ep_nums ; i++) + cdns3_free_trb_pool(priv_dev->eps[i]); + + if (!priv_dev->start_gadget) + return 0; + + list_for_each_entry(ep, &priv_dev->gadget.ep_list, ep_list) { + priv_ep = ep_to_cdns3_ep(ep); + bEndpointAddress = priv_ep->num | priv_ep->dir; + cdns3_select_ep(priv_dev, bEndpointAddress); + writel(EP_CMD_EPRST, &priv_dev->regs->ep_cmd); + ret = cdns3_handshake(&priv_dev->regs->ep_cmd, + EP_CMD_EPRST, 0, 100); + } + + /* disable interrupt for device */ + writel(0, &priv_dev->regs->usb_ien); + writel(USB_CONF_DEVDS, &priv_dev->regs->usb_conf); + + return ret; +} + +static const struct usb_gadget_ops cdns3_gadget_ops = { + .get_frame = cdns3_gadget_get_frame, + .wakeup = cdns3_gadget_wakeup, + .set_selfpowered = cdns3_gadget_set_selfpowered, + .pullup = cdns3_gadget_pullup, + .udc_start = cdns3_gadget_udc_start, + .udc_stop = cdns3_gadget_udc_stop, + .match_ep = cdns3_gadget_match_ep, +}; + /** * cdns3_init_ep Initializes software endpoints of gadget * @cdns3: extended gadget object @@ -184,8 +430,7 @@ static int __cdns3_gadget_init(struct cdns3 *cdns) /* fill gadget fields */ priv_dev->gadget.max_speed = USB_SPEED_SUPER; priv_dev->gadget.speed = USB_SPEED_UNKNOWN; - //TODO: Add implementation of cdns3_gadget_ops - //priv_dev->gadget.ops = &cdns3_gadget_ops; + priv_dev->gadget.ops = &cdns3_gadget_ops; priv_dev->gadget.name = "usb-ss-gadget"; priv_dev->gadget.sg_supported = 1; priv_dev->is_connected = 0; From patchwork Sun Nov 18 10:09:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Laszczak X-Patchwork-Id: 10687709 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B86AF109C for ; Sun, 18 Nov 2018 10:11:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A7D9829D31 for ; Sun, 18 Nov 2018 10:11:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9A20B29D43; Sun, 18 Nov 2018 10:11:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DCAA29D31 for ; Sun, 18 Nov 2018 10:11:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727459AbeKRUbB (ORCPT ); Sun, 18 Nov 2018 15:31:01 -0500 Received: from mx0a-0014ca01.pphosted.com ([208.84.65.235]:36408 "EHLO mx0a-0014ca01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727332AbeKRUbA (ORCPT ); Sun, 18 Nov 2018 15:31:00 -0500 Received: from pps.filterd (m0042385.ppops.net [127.0.0.1]) by mx0a-0014ca01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id wAIA6Vw2016029; Sun, 18 Nov 2018 02:10:49 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=proofpoint; bh=bzpE4qQALzyWPjEOjKHnjLU28Zpeyt/p3Gm66EUqIBw=; b=IQA8RXr1GdnPhhOucgAFmozkUHVOYeC40jvAwWH5IwFwsRyv8eY6UNP/Ycv4WiEprnG4 JJLQjEFdAycTsAMH91VFsED+qTCr56cinG95nLgOAsu24Pf3dETO6zSbpBa4XU5XdRt4 /2YiFpZI0IWXX8hZAXIGO6n6PGwVp575QQ9O3hIMHgH9jEOv3GT7bM3Tg5JJi76qQqIe Tu/X4h7ASYIuALooJ7G8/chkAALzFArOLh1KEfwqGTp8eYqrEtiJB//p5Q6tsfSv7rYM 82QyAP6bhCw4NoXEWrl2z8K8lfRR/OdqfeGVpAIX9KQPEXYiOdmPjlon/1z8ty/Bn4qT 3g== Authentication-Results: cadence.com; spf=pass smtp.mailfrom=pawell@cadence.com Received: from nam01-by2-obe.outbound.protection.outlook.com (mail-by2nam01lp0178.outbound.protection.outlook.com [216.32.181.178]) by mx0a-0014ca01.pphosted.com with ESMTP id 2ntge14vg7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sun, 18 Nov 2018 02:10:49 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=bzpE4qQALzyWPjEOjKHnjLU28Zpeyt/p3Gm66EUqIBw=; b=dZkk1HXMiI6ibnyRShx7jmy72N58SmFaKMpvwTl/ghRyHcZqIoxaTbTMwyZzrapUSPwSp5mXwlAELXOxocsUrglo0iv3c5pUSZ/7CLiq4dcdGAkIjKViLEbJ6ejXvD1gIVvsVXNmXCsaKi3mWqXrQPZ1lSK3yhqj1rHCq2L+r7U= Received: from DM5PR07CA0051.namprd07.prod.outlook.com (2603:10b6:4:ad::16) by BLUPR0701MB1857.namprd07.prod.outlook.com (2a01:111:e400:5165::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.26; Sun, 18 Nov 2018 10:10:46 +0000 Received: from DM3NAM05FT017.eop-nam05.prod.protection.outlook.com (2a01:111:f400:7e51::204) by DM5PR07CA0051.outlook.office365.com (2603:10b6:4:ad::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.21 via Frontend Transport; Sun, 18 Nov 2018 10:10:45 +0000 Received-SPF: SoftFail (protection.outlook.com: domain of transitioning cadence.com discourages use of 158.140.1.28 as permitted sender) Received: from sjmaillnx2.cadence.com (158.140.1.28) by DM3NAM05FT017.mail.protection.outlook.com (10.152.98.126) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.3 via Frontend Transport; Sun, 18 Nov 2018 10:10:44 +0000 Received: from maileu3.global.cadence.com (maileu3.cadence.com [10.160.88.99]) by sjmaillnx2.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAb5R029622 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Sun, 18 Nov 2018 02:10:44 -0800 X-CrossPremisesHeadersFilteredBySendConnector: maileu3.global.cadence.com Received: from maileu3.global.cadence.com (10.160.88.99) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Sun, 18 Nov 2018 11:10:43 +0100 Received: from lvlogina.cadence.com (10.165.176.102) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Sun, 18 Nov 2018 11:10:43 +0100 Received: from lvlogina.cadence.com (localhost.localdomain [127.0.0.1]) by lvlogina.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAdwF031663; Sun, 18 Nov 2018 10:10:39 GMT Received: (from pawell@localhost) by lvlogina.cadence.com (8.14.4/8.14.4/Submit) id wAIAAdnH031610; Sun, 18 Nov 2018 10:10:39 GMT From: Pawel Laszczak To: CC: , , , , , , , , , , , , "Pawel Laszczak" Subject: [RFC PATCH v2 09/15] usb:cdns3: EpX operations part of the API Date: Sun, 18 Nov 2018 10:09:05 +0000 Message-ID: <1542535751-16079-10-git-send-email-pawell@cadence.com> X-Mailer: git-send-email 1.7.11.2 In-Reply-To: <1542535751-16079-1-git-send-email-pawell@cadence.com> References: <1542535751-16079-1-git-send-email-pawell@cadence.com> MIME-Version: 1.0 X-OrganizationHeadersPreserved: maileu3.global.cadence.com X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:158.140.1.28;IPV:CAL;SCL:-1;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(346002)(376002)(39860400002)(136003)(396003)(2980300002)(36092001)(189003)(199004)(486006)(246002)(11346002)(6916009)(126002)(476003)(2616005)(2906002)(426003)(4744004)(4326008)(6666004)(4720700003)(446003)(105596002)(575784001)(26005)(86362001)(106466001)(2351001)(478600001)(26826003)(356004)(87636003)(14444005)(107886003)(336012)(76176011)(217873002)(50466002)(16586007)(36756003)(48376002)(47776003)(51416003)(316002)(186003)(8676002)(50226002)(8936002)(5660300001)(7636002)(305945005)(54906003)(42186006)(309714004);DIR:OUT;SFP:1101;SCL:1;SRVR:BLUPR0701MB1857;H:sjmaillnx2.cadence.com;FPR:;SPF:SoftFail;LANG:en;PTR:corp.cadence.com;MX:1;A:1; X-Microsoft-Exchange-Diagnostics: 1;DM3NAM05FT017;1:VZwdZ/uSg15PkpSpR/cgfKw2PgGnEMLqJeX17f5KsJuFo5Fgjw4dY+wjpug6IzWoGBlJcZQNAk4C2b+me4R9fjG/WCXyfHcqbgB7wj18Qe6atPFVqhLCxvfAS8E2lK3H X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 97a94859-96f5-46fe-d380-08d64d3e1aeb X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060);SRVR:BLUPR0701MB1857; X-Microsoft-Exchange-Diagnostics: 1;BLUPR0701MB1857;3:q0tdBbVD7kCqWZMUtwxN/WZPNpM9YhjxGmnZcehuIoHMEzSUhWjddZerYOcf4qotfBGjD2s9OakFeiBvz30oMiipYr1e1IHHcr6vjE3yEXDt8ztmP0tjOTYFcBGvQFmDDMdB+wkoS40WPeDWWdEDn+M4U6yZc6ImG2rkJ8GhNIvVxe7SGGiKzEOSRY4EEz9qz94d2s+2N1b2OBLwoltm7EHwqZISBlLm9bMwH5vmsh7pnxYrl6mbjFg1wQ9xoEPDhtIOG+jugFzQvChK9/hItUo/Mn8ImJDGRRGDZs6lAOMrKO+fwGgLkkPS3A/ZA5rERhMwqpAbweKBPC0wAkBzTkBb/7k7jiCmKF6+Y9L0EIA=;25:VnqMkEJ4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N0w6UqbshFe9EO0Ureh18OHna17CjGLXSTThzScbfMOTuTbywK4H0o4SUjck5O8YWxhqk2XjzWavm4QSNN2SVld9uxoYYd X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(72806322054110); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93003095)(3231415)(944501410)(52105112)(10201501046)(3002001)(148016)(149066)(150057)(6041310)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051)(76991095);SRVR:BLUPR0701MB1857;BCL:0;PCL:0;RULEID:;SRVR:BLUPR0701MB1857; X-Microsoft-Exchange-Diagnostics: 1;BLUPR0701MB1857;4:wq8K8EfiDpkHvTZBO1ACGMyZtGXOVphFFspe3KK4O6w2cI9zPtMWBjkS8QIIHzeGrEKR2AifNmz7oOkkPetxJwuvr5x3fX0u5D7WEPnkSRm0Gz1kVa/9SGvx2sCAywIEer5Gsc/NKiQhNA3KZRRSn7MKUw2t20GzFCNZWEvjbZBdid17LeREk4SA/l/7afFKYa5+VGcMBxiADM3chl5FHpW9vF5G/f/b4JRI5qfojdsCSyY0jqQJYxtDGR8kud6/9nfR2KrEaORIZkGrZywSD36/uBGXLG73mCCGza27p1DUjF8rACorLWtsFaKz7fjo X-Forefront-PRVS: 0860FE717F X-Microsoft-Exchange-Diagnostics: 1;BLUPR0701MB1857;23:vV2hw3d60bA0j5MALl42449IihmXis/1hmCv9vKnR7r+lB+Z2q3WYY1Dc64f+qN6vsBhjU4Usj78fMHi0DlCklTlK4J9scCBPG0w1HCA+i4rrSUr88pPB9nSgGuOZ16VfPzzvITmVfk3J4Bj0NhTtw+ssgpYz5DK0OXogTM4DWL1CHl5+dC4lP/qkgjWzCvlmLOnI6nmFSe9DnAFSeTNGogT7IpF0A8yB/zc8GjQcs04ikVDu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zSmtG4V40/R8DpL0YzAQp9rIQ77LBD7pX66+LfvmTmaw01qPpg70Jch/J6yuBICFl8QflgbXoBKAuCqjGI2I16rUA== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BLUPR0701MB1857;20:ZXGnL+gLcrSnqY2jK6p+6/l4Ncj8YVUJiilgk/K6mxG/8lRVEhaS3uQJtWDpOchrva3fW3yw4hTF7jYqdKmnxNeU4ekkhoLgHwYYtZZxcfPNmyTcIbAdqacK8ET0kJV5kmm3Updf2gmOzvMb0VH30UnX9CnXX8Kh0EgQhz45dbZe9DeP7ctir5cqwJ0OeZIygDHp6PFTpxN7rMpBaTc+3oEc93UvoAOoY/a2ISOAyN0dlJ4HWDmfYyW1GQS574JG X-OriginatorOrg: cadence.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2018 10:10:44.9008 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 97a94859-96f5-46fe-d380-08d64d3e1aeb X-MS-Exchange-CrossTenant-Id: d36035c5-6ce6-4662-a3dc-e762e61ae4c9 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=d36035c5-6ce6-4662-a3dc-e762e61ae4c9;Ip=[158.140.1.28];Helo=[sjmaillnx2.cadence.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR0701MB1857 X-Proofpoint-SPF-Result: pass X-Proofpoint-SPF-Record: v=spf1 a:mx-sanjose2.Cadence.COM a:mx-sanjose4.Cadence.COM a:mx-sanjose5.Cadence.COM include:mktomail.com include:spf-0014ca01.pphosted.com include:spf.protection.outlook.com include:auth.msgapp.com include:spf.mandrillapp.com ~all X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-11-18_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_check_notspam policy=outbound_check score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=725 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811180096 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Patch implements callback functions for non-default endpoints defined in usb_ep_ops object. Signed-off-by: Pawel Laszczak --- drivers/usb/cdns3/ep0.c | 18 ++ drivers/usb/cdns3/gadget.c | 442 ++++++++++++++++++++++++++++++++++++- drivers/usb/cdns3/gadget.h | 3 + 3 files changed, 461 insertions(+), 2 deletions(-) diff --git a/drivers/usb/cdns3/ep0.c b/drivers/usb/cdns3/ep0.c index c08d02665f9d..ca1795467155 100644 --- a/drivers/usb/cdns3/ep0.c +++ b/drivers/usb/cdns3/ep0.c @@ -23,6 +23,24 @@ static void cdns3_prepare_setup_packet(struct cdns3_device *priv_dev) //TODO: Implements this function } +/** + * cdns3_gadget_ep_set_wedge Set wedge on selected endpoint + * @ep: endpoint object + * + * Returns 0 + */ +int cdns3_gadget_ep_set_wedge(struct usb_ep *ep) +{ + struct cdns3_endpoint *priv_ep = ep_to_cdns3_ep(ep); + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + + dev_dbg(&priv_dev->dev, "Wedge for %s\n", ep->name); + cdns3_gadget_ep_set_halt(ep, 1); + priv_ep->flags |= EP_WEDGE; + + return 0; +} + /** * cdns3_ep0_config - Configures default endpoint * @priv_dev: extended gadget object diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c index 702a05faa664..1f2a434486dc 100644 --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/gadget.c @@ -58,6 +58,19 @@ void cdns3_set_register_bit(void __iomem *ptr, u32 mask) writel(mask, ptr); } +/** + * cdns3_next_request - returns next request from list + * @list: list containing requests + * + * Returns request or NULL if no requests in list + */ +struct usb_request *cdns3_next_request(struct list_head *list) +{ + if (list_empty(list)) + return NULL; + return list_first_entry(list, struct usb_request, list); +} + /** * select_ep - selects endpoint * @priv_dev: extended gadget object @@ -73,6 +86,53 @@ void cdns3_select_ep(struct cdns3_device *priv_dev, u32 ep) writel(ep, &priv_dev->regs->ep_sel); } +/** + * cdns3_allocate_trb_pool - Allocates TRB's pool for selected endpoint + * @priv_ep: endpoint object + * + * Function will return 0 on success or -ENOMEM on allocation error + */ +static int cdns3_allocate_trb_pool(struct cdns3_endpoint *priv_ep) +{ + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + struct cdns3_trb *link_trb; + + if (!priv_ep->trb_pool) { + priv_ep->trb_pool = dma_zalloc_coherent(priv_dev->sysdev, + TRB_RIGN_SIZE, + &priv_ep->trb_pool_dma, + GFP_DMA); + if (!priv_ep->trb_pool) + return -ENOMEM; + } else { + memset(priv_ep->trb_pool, 0, TRB_RIGN_SIZE); + } + + if (!priv_ep->aligned_buff) { + priv_ep->aligned_buff = dma_alloc_coherent(priv_dev->sysdev, + CDNS3_UNALIGNED_BUF_SIZE, + &priv_ep->aligned_dma_addr, + GFP_DMA); + if (!priv_ep->aligned_buff) { + dma_free_coherent(priv_dev->sysdev, + TRB_RIGN_SIZE, + priv_ep->trb_pool, + priv_ep->trb_pool_dma); + priv_ep->trb_pool = NULL; + + return -ENOMEM; + } + } + + /* Initialize the last TRB as Link TRB */ + link_trb = (priv_ep->trb_pool + TRBS_PER_SEGMENT - 1); + link_trb->buffer = TRB_BUFFER(priv_ep->trb_pool_dma); + link_trb->control = TRB_CYCLE | TRB_TYPE(TRB_LINK) | + TRB_CHAIN | TRB_TOGGLE; + + return 0; +} + static void cdns3_free_trb_pool(struct cdns3_endpoint *priv_ep) { struct cdns3_device *priv_dev = priv_ep->cdns3_dev; @@ -92,6 +152,73 @@ static void cdns3_free_trb_pool(struct cdns3_endpoint *priv_ep) } } +/** + * cdns3_data_flush - flush data at onchip buffer + * @priv_ep: endpoint object + * + * Endpoint must be selected before call to this function + * + * Returns zero on success or negative value on failure + */ +static int cdns3_data_flush(struct cdns3_endpoint *priv_ep) +{ + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + + writel(EP_CMD_DFLUSH, &priv_dev->regs->ep_cmd); + + /* wait for DFLUSH cleared */ + return cdns3_handshake(&priv_dev->regs->ep_cmd, EP_CMD_DFLUSH, 0, 100); +} + +/** + * cdns3_ep_stall_flush - Stalls and flushes selected endpoint + * @priv_ep: endpoint object + * + * Endpoint must be selected before call to this function + */ +static void cdns3_ep_stall_flush(struct cdns3_endpoint *priv_ep) +{ + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + + writel(EP_CMD_DFLUSH | EP_CMD_ERDY | EP_CMD_SSTALL, + &priv_dev->regs->ep_cmd); + + /* wait for DFLUSH cleared */ + cdns3_handshake(&priv_dev->regs->ep_cmd, EP_CMD_DFLUSH, 0, 100); + priv_ep->flags |= EP_STALL; +} + +/** + * cdns3_gadget_giveback - call struct usb_request's ->complete callback + * @priv_ep: The endpoint to whom the request belongs to + * @priv_req: The request we're giving back + * @status: completion code for the request + * + * Must be called with controller's lock held and interrupts disabled. This + * function will unmap @req and call its ->complete() callback to notify upper + * layers that it has completed. + */ +void cdns3_gadget_giveback(struct cdns3_endpoint *priv_ep, + struct cdns3_request *priv_req, + int status) +{ + //TODO: Implements this function. +} + +/** + * cdns3_ep_run_transfer - start transfer on no-default endpoint hardware + * @priv_ep: endpoint object + * + * Returns zero on success or negative value on failure + */ +int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, + struct usb_request *request) +{ + //TODO: Implements this function. + + return 0; +} + /** * cdns3_irq_handler - irq line interrupt handler * @cdns: cdns3 instance @@ -170,6 +297,318 @@ static struct usb_ep *cdns3_gadget_match_ep(struct usb_gadget *gadget, return &priv_ep->endpoint; } +/** + * cdns3_gadget_ep_enable Enable endpoint + * @ep: endpoint object + * @desc: endpoint descriptor + * + * Returns 0 on success, error code elsewhere + */ +static int cdns3_gadget_ep_enable(struct usb_ep *ep, + const struct usb_endpoint_descriptor *desc) +{ + struct cdns3_endpoint *priv_ep; + struct cdns3_device *priv_dev; + unsigned long flags; + int ret; + u32 reg; + + priv_ep = ep_to_cdns3_ep(ep); + priv_dev = priv_ep->cdns3_dev; + + if (!ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT) { + dev_err(&priv_dev->dev, "usbss: invalid parameters\n"); + return -EINVAL; + } + + if (!desc->wMaxPacketSize) { + dev_err(&priv_dev->dev, "usbss: missing wMaxPacketSize\n"); + return -EINVAL; + } + + if (dev_WARN_ONCE(&priv_dev->dev, priv_ep->flags & EP_ENABLED, + "%s is already enabled\n", priv_ep->name)) + return 0; + + ret = cdns3_allocate_trb_pool(priv_ep); + if (ret) + return ret; + + dev_dbg(&priv_dev->dev, "Enabling endpoint: %s\n", ep->name); + spin_lock_irqsave(&priv_dev->lock, flags); + cdns3_select_ep(priv_dev, desc->bEndpointAddress); + writel(EP_CMD_EPRST, &priv_dev->regs->ep_cmd); + + ret = cdns3_handshake(&priv_dev->regs->ep_cmd, + EP_CMD_CSTALL | EP_CMD_EPRST, 0, 100); + + cdns3_set_register_bit(&priv_dev->regs->ep_cfg, EP_CFG_ENABLE); + + ep->desc = desc; + priv_ep->flags &= ~(EP_PENDING_REQUEST | EP_STALL); + priv_ep->flags |= EP_ENABLED | EP_UPDATE_EP_TRBADDR; + priv_ep->enqueue = 0; + priv_ep->dequeue = 0; + reg = readl(&priv_dev->regs->ep_sts); + priv_ep->pcs = !!EP_STS_CCS(reg); + priv_ep->ccs = !!EP_STS_CCS(reg); + /* one TRB is reserved for link TRB used in DMULT mode*/ + priv_ep->free_trbs = TRBS_PER_SEGMENT - 1; + + spin_unlock_irqrestore(&priv_dev->lock, flags); + return 0; +} + +/** + * cdns3_gadget_ep_disable Disable endpoint + * @ep: endpoint object + * + * Returns 0 on success, error code elsewhere + */ +static int cdns3_gadget_ep_disable(struct usb_ep *ep) +{ + struct cdns3_endpoint *priv_ep; + struct cdns3_device *priv_dev; + unsigned long flags; + int ret = 0; + struct usb_request *request; + u32 ep_cfg; + + if (!ep) { + pr_debug("usbss: invalid parameters\n"); + return -EINVAL; + } + + priv_ep = ep_to_cdns3_ep(ep); + priv_dev = priv_ep->cdns3_dev; + + if (dev_WARN_ONCE(&priv_dev->dev, !(priv_ep->flags & EP_ENABLED), + "%s is already disabled\n", priv_ep->name)) + return 0; + + spin_lock_irqsave(&priv_dev->lock, flags); + if (!priv_dev->start_gadget) { + dev_dbg(&priv_dev->dev, + "Disabling endpoint at disconnection: %s\n", ep->name); + spin_unlock_irqrestore(&priv_dev->lock, flags); + return 0; + } + + dev_dbg(&priv_dev->dev, "Disabling endpoint: %s\n", ep->name); + + cdns3_select_ep(priv_dev, ep->desc->bEndpointAddress); + ret = cdns3_data_flush(priv_ep); + while (!list_empty(&priv_ep->request_list)) { + request = cdns3_next_request(&priv_ep->request_list); + + cdns3_gadget_giveback(priv_ep, to_cdns3_request(request), + -ESHUTDOWN); + } + + ep_cfg = readl(&priv_dev->regs->ep_cfg); + ep_cfg &= ~EP_CFG_ENABLE; + writel(ep_cfg, &priv_dev->regs->ep_cfg); + ep->desc = NULL; + priv_ep->flags &= ~EP_ENABLED; + + spin_unlock_irqrestore(&priv_dev->lock, flags); + + return ret; +} + +/** + * cdns3_gadget_ep_alloc_request Allocates request + * @ep: endpoint object associated with request + * @gfp_flags: gfp flags + * + * Returns allocated request address, NULL on allocation error + */ +struct usb_request *cdns3_gadget_ep_alloc_request(struct usb_ep *ep, + gfp_t gfp_flags) +{ + struct cdns3_endpoint *priv_ep = ep_to_cdns3_ep(ep); + struct cdns3_request *priv_req; + + priv_req = kzalloc(sizeof(*priv_req), gfp_flags); + if (!priv_req) + return NULL; + + priv_req->priv_ep = priv_ep; + + return &priv_req->request; +} + +/** + * cdns3_gadget_ep_free_request Free memory occupied by request + * @ep: endpoint object associated with request + * @request: request to free memory + */ +void cdns3_gadget_ep_free_request(struct usb_ep *ep, + struct usb_request *request) +{ + struct cdns3_request *priv_req = to_cdns3_request(request); + + kfree(priv_req); +} + +/** + * cdns3_gadget_ep_queue Transfer data on endpoint + * @ep: endpoint object + * @request: request object + * @gfp_flags: gfp flags + * + * Returns 0 on success, error code elsewhere + */ +static int __cdns3_gadget_ep_queue(struct usb_ep *ep, + struct usb_request *request, + gfp_t gfp_flags) +{ + struct cdns3_endpoint *priv_ep = ep_to_cdns3_ep(ep); + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + int ret = 0; + + request->actual = 0; + request->status = -EINPROGRESS; + + dev_dbg(&priv_dev->dev, "Queuing to endpoint: %s\n", priv_ep->name); + + ret = usb_gadget_map_request_by_dev(priv_dev->sysdev, request, + usb_endpoint_dir_in(ep->desc)); + + if (ret) + return ret; + + if (!cdns3_ep_run_transfer(priv_ep, request)) + list_add_tail(&request->list, &priv_ep->request_list); + + return ret; +} + +static int cdns3_gadget_ep_queue(struct usb_ep *ep, struct usb_request *request, + gfp_t gfp_flags) +{ + struct cdns3_endpoint *priv_ep = ep_to_cdns3_ep(ep); + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + struct usb_request *zlp_request; + unsigned long flags; + int ret; + + spin_lock_irqsave(&priv_dev->lock, flags); + ret = __cdns3_gadget_ep_queue(ep, request, gfp_flags); + + if (ret == 0 && request->zero && request->length && + (request->length % ep->maxpacket == 0)) { + zlp_request = cdns3_gadget_ep_alloc_request(ep, GFP_ATOMIC); + zlp_request->buf = priv_dev->zlp_buf; + zlp_request->length = 0; + + dev_dbg(&priv_dev->dev, "Queuing ZLP for endpoint: %s\n", + priv_ep->name); + ret = __cdns3_gadget_ep_queue(ep, zlp_request, gfp_flags); + } + + spin_unlock_irqrestore(&priv_dev->lock, flags); + return ret; +} + +/** + * cdns3_gadget_ep_dequeue Remove request from transfer queue + * @ep: endpoint object associated with request + * @request: request object + * + * Returns 0 on success, error code elsewhere + */ +int cdns3_gadget_ep_dequeue(struct usb_ep *ep, + struct usb_request *request) +{ + struct cdns3_endpoint *priv_ep = ep_to_cdns3_ep(ep); + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + struct usb_request *req, *req_temp; + unsigned long flags; + int ret = 0; + + if (!ep || !request || !ep->desc) + return -EINVAL; + + spin_lock_irqsave(&priv_dev->lock, flags); + dev_dbg(&priv_dev->dev, "Dequeue from %s\n", ep->name); + + cdns3_select_ep(priv_dev, ep->desc->bEndpointAddress); + if (priv_dev->start_gadget) + ret = cdns3_data_flush(priv_ep); + + list_for_each_entry_safe(req, req_temp, &priv_ep->request_list, list) { + if (request == req) { + cdns3_gadget_giveback(priv_ep, + to_cdns3_request(request), + -ECONNRESET); + break; + } + } + + spin_unlock_irqrestore(&priv_dev->lock, flags); + return ret; +} + +/** + * cdns3_gadget_ep_set_halt Sets/clears stall on selected endpoint + * @ep: endpoint object to set/clear stall on + * @value: 1 for set stall, 0 for clear stall + * + * Returns 0 on success, error code elsewhere + */ +int cdns3_gadget_ep_set_halt(struct usb_ep *ep, int value) +{ + struct cdns3_endpoint *priv_ep = ep_to_cdns3_ep(ep); + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + unsigned long flags; + int ret = 0; + + if (!(priv_ep->flags & EP_ENABLED)) + return -EPERM; + + /* if actual transfer is pending defer setting stall on this endpoint */ + if ((priv_ep->flags & EP_PENDING_REQUEST) && value) { + priv_ep->flags |= EP_STALL; + return 0; + } + + dev_dbg(&priv_dev->dev, "Halt endpoint %s\n", priv_ep->name); + + spin_lock_irqsave(&priv_dev->lock, flags); + + cdns3_select_ep(priv_dev, ep->desc->bEndpointAddress); + if (value) { + cdns3_ep_stall_flush(priv_ep); + } else { + priv_ep->flags &= ~EP_WEDGE; + writel(EP_CMD_CSTALL | EP_CMD_EPRST, &priv_dev->regs->ep_cmd); + + /* wait for EPRST cleared */ + ret = cdns3_handshake(&priv_dev->regs->ep_cmd, + EP_CMD_EPRST, 0, 100); + priv_ep->flags &= ~EP_STALL; + } + + priv_ep->flags &= ~EP_PENDING_REQUEST; + spin_unlock_irqrestore(&priv_dev->lock, flags); + + return ret; +} + +extern const struct usb_ep_ops cdns3_gadget_ep0_ops; + +static const struct usb_ep_ops cdns3_gadget_ep_ops = { + .enable = cdns3_gadget_ep_enable, + .disable = cdns3_gadget_ep_disable, + .alloc_request = cdns3_gadget_ep_alloc_request, + .free_request = cdns3_gadget_ep_free_request, + .queue = cdns3_gadget_ep_queue, + .dequeue = cdns3_gadget_ep_dequeue, + .set_halt = cdns3_gadget_ep_set_halt, + .set_wedge = cdns3_gadget_ep_set_wedge, +}; + /** * cdns3_gadget_get_frame Returns number of actual ITP frame * @gadget: gadget object @@ -365,8 +804,7 @@ static int cdns3_init_ep(struct cdns3_device *priv_dev) usb_ep_set_maxpacket_limit(&priv_ep->endpoint, ENDPOINT_MAX_PACKET_LIMIT); priv_ep->endpoint.max_streams = ENDPOINT_MAX_STREAMS; - //TODO: Add implementation of cdns3_gadget_ep_ops - //priv_ep->endpoint.ops = &cdns3_gadget_ep_ops; + priv_ep->endpoint.ops = &cdns3_gadget_ep_ops; if (ep_dir) priv_ep->endpoint.caps.dir_in = 1; else diff --git a/drivers/usb/cdns3/gadget.h b/drivers/usb/cdns3/gadget.h index 3b0d4d2e4831..a4be288b34cb 100644 --- a/drivers/usb/cdns3/gadget.h +++ b/drivers/usb/cdns3/gadget.h @@ -1072,4 +1072,7 @@ void cdns3_set_register_bit(void __iomem *ptr, u32 mask); int cdns3_init_ep0(struct cdns3_device *priv_dev); void cdns3_ep0_config(struct cdns3_device *priv_dev); void cdns3_select_ep(struct cdns3_device *priv_dev, u32 ep); +int cdns3_gadget_ep_set_wedge(struct usb_ep *ep); +int cdns3_gadget_ep_set_halt(struct usb_ep *ep, int value); + #endif /* __LINUX_CDNS3_GADGET */ From patchwork Sun Nov 18 10:09:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Laszczak X-Patchwork-Id: 10687713 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4DA0D13BB for ; Sun, 18 Nov 2018 10:11:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3829729D31 for ; Sun, 18 Nov 2018 10:11:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2769629D3E; Sun, 18 Nov 2018 10:11:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C08F29D31 for ; Sun, 18 Nov 2018 10:11:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727542AbeKRUbE (ORCPT ); Sun, 18 Nov 2018 15:31:04 -0500 Received: from mx0a-0014ca01.pphosted.com ([208.84.65.235]:36426 "EHLO mx0a-0014ca01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727330AbeKRUbD (ORCPT ); Sun, 18 Nov 2018 15:31:03 -0500 Received: from pps.filterd (m0042385.ppops.net [127.0.0.1]) by mx0a-0014ca01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id wAIA6qt9016172; Sun, 18 Nov 2018 02:10:51 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=proofpoint; bh=vNZYT0SK8/988waVE7XtXpo7nb57FIsXrJgh1vBsHpM=; b=CImbAyFMT4s/psAf6hrzh4fRgWMlBgk662fMijQarfMseW7TNuOySMPF+fXdKWI3PsUq i9Ycz5C/oOuGob+5wPbB61duEHmJKjaeF/4QQkf+J8oCFn3Wk3IO+gxLTK3OthP7LYP4 HYlgCsO2Lhqs5wpAyKPBR4i9sGRYz5ySJ3r6KaJDEk73HwaGev5ntCtS1PnKAdI8TqPs URHZXyEJTED/rQhgOHN49w9q9IDzMt72XHHB2VO0nyWkiWv+XKTK3NtVKCu5QHUgb3eD OtQNfa+iLYNF/fUSLUydDEgddETcNSjFacxYACYhzdUZebeU2bLmNPpd8ZTTRJskDBer jg== Authentication-Results: cadence.com; spf=pass smtp.mailfrom=pawell@cadence.com Received: from nam01-by2-obe.outbound.protection.outlook.com (mail-by2nam01lp0183.outbound.protection.outlook.com [216.32.181.183]) by mx0a-0014ca01.pphosted.com with ESMTP id 2ntge14vge-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sun, 18 Nov 2018 02:10:51 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vNZYT0SK8/988waVE7XtXpo7nb57FIsXrJgh1vBsHpM=; b=h/WH5TSbNjnHCERe2BNipGgCdoHoDiXfDK7Tx4j+swbPr9GIbacZdYYqCYNA4wIgCCZj1MER20DmUBhz5dOU0yyy3nuosLyNA4npGqUy/TzUO34xyJgp3vnmMmTwey6QHUrZW4plmeBB8YukdH9jMiKpizM5s6FXaAoq/5SErJg= Received: from CY1PR07CA0028.namprd07.prod.outlook.com (2a01:111:e400:c60a::38) by BYAPR07MB5175.namprd07.prod.outlook.com (2603:10b6:a03:6d::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.26; Sun, 18 Nov 2018 10:10:49 +0000 Received: from BY2NAM05FT011.eop-nam05.prod.protection.outlook.com (2a01:111:f400:7e52::201) by CY1PR07CA0028.outlook.office365.com (2a01:111:e400:c60a::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.20 via Frontend Transport; Sun, 18 Nov 2018 10:10:49 +0000 Received-SPF: SoftFail (protection.outlook.com: domain of transitioning cadence.com discourages use of 158.140.1.28 as permitted sender) Received: from sjmaillnx2.cadence.com (158.140.1.28) by BY2NAM05FT011.mail.protection.outlook.com (10.152.100.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.3 via Frontend Transport; Sun, 18 Nov 2018 10:10:45 +0000 Received: from maileu3.global.cadence.com (maileu3.cadence.com [10.160.88.99]) by sjmaillnx2.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAb5S029622 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Sun, 18 Nov 2018 02:10:44 -0800 X-CrossPremisesHeadersFilteredBySendConnector: maileu3.global.cadence.com Received: from maileu3.global.cadence.com (10.160.88.99) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Sun, 18 Nov 2018 11:10:43 +0100 Received: from lvlogina.cadence.com (10.165.176.102) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Sun, 18 Nov 2018 11:10:43 +0100 Received: from lvlogina.cadence.com (localhost.localdomain [127.0.0.1]) by lvlogina.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAdMH031818; Sun, 18 Nov 2018 10:10:39 GMT Received: (from pawell@localhost) by lvlogina.cadence.com (8.14.4/8.14.4/Submit) id wAIAAdmp031769; Sun, 18 Nov 2018 10:10:39 GMT From: Pawel Laszczak To: CC: , , , , , , , , , , , , "Pawel Laszczak" Subject: [RFC PATCH v2 10/15] usb:cdns3: Ep0 operations part of the API Date: Sun, 18 Nov 2018 10:09:06 +0000 Message-ID: <1542535751-16079-11-git-send-email-pawell@cadence.com> X-Mailer: git-send-email 1.7.11.2 In-Reply-To: <1542535751-16079-1-git-send-email-pawell@cadence.com> References: <1542535751-16079-1-git-send-email-pawell@cadence.com> MIME-Version: 1.0 X-OrganizationHeadersPreserved: maileu3.global.cadence.com X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:158.140.1.28;IPV:CAL;SCL:-1;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(396003)(136003)(376002)(39860400002)(346002)(2980300002)(199004)(189003)(36092001)(4326008)(106466001)(217873002)(2351001)(14444005)(19627235002)(356004)(16586007)(4720700003)(36756003)(105596002)(42186006)(575784001)(6916009)(86362001)(47776003)(6666004)(316002)(54906003)(11346002)(2616005)(126002)(446003)(476003)(486006)(76176011)(336012)(26005)(426003)(186003)(107886003)(2906002)(48376002)(50466002)(305945005)(246002)(7636002)(87636003)(26826003)(478600001)(5660300001)(8936002)(8676002)(50226002)(51416003);DIR:OUT;SFP:1101;SCL:1;SRVR:BYAPR07MB5175;H:sjmaillnx2.cadence.com;FPR:;SPF:SoftFail;LANG:en;PTR:corp.cadence.com;A:1;MX:1; X-Microsoft-Exchange-Diagnostics: 1;BY2NAM05FT011;1:jsjv7TgBNdNjcE/5humcTEoikBCDQfuWQm5aNuuxMSsV2iMKYB9dkmeKRMR9Fbaq+t09q43v8zW2Fx0MNugRI1SIm80d0KVFzc9k4aGybXi8aBFKJOMcVYhZeC6jf5fQ X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8d53fae3-c9f9-4fd1-c543-08d64d3e1cd7 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060);SRVR:BYAPR07MB5175; X-Microsoft-Exchange-Diagnostics: 1;BYAPR07MB5175;3:iOAQ1Ol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6+FsJR+9oquskGdcOd13UqVZwfKLaXlIKJs/67iERWO5ZgmrhlC5oquk6VdxRUs9o1zBJZtqOS8u1qkK627myqloDFaV0G5xsiMvc4TQGV5nfapqHJ7hwcHXeoIFchp+HAaC4gtUxzfpItJrxjISMYZK3kWd+uM/IKbgpDf4lrdn/SxVqMvrjomQhMjJQy+Q6UwELOQpZ9/bbzoNH/49dKQ39it1H/UINpPv3kHN7dZNueJVPlAGo47RSzuDNFK0LJWkEQWF8uRZCeBuCGb/DnkzL8aRRSIyJQ1oLAeammmtt+5HSDZmqHFaMFb0l6JGdo8kVL7A5XvD46bce6vYu3HV51fqlb3RSbqp6i1zRbdtxy1mTOB+6qehM1Mk3CgXXvjm7rjm5rT0im9Bnexm1FL2fgIrab+6G4wn7npNb3DHfMlZmMp/Ghj X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3002001)(10201501046)(93006095)(93003095)(3231415)(944501410)(52105112)(148016)(149066)(150057)(6041310)(20161123564045)(20161123562045)(20161123560045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051)(76991095);SRVR:BYAPR07MB5175;BCL:0;PCL:0;RULEID:;SRVR:BYAPR07MB5175; X-Microsoft-Exchange-Diagnostics: 1;BYAPR07MB5175;4:N/VVcfxoH58nXV9VGe1f/9iv59u6JE08xKYMwCuS2pqkdfRoxzOCCkwmimh32oU9qUXeFti1vkr/L6AViU4fQBfRBNT2+3cln06VPBjX5ZPg1hIkZ8e5AXRZrHDksZgroKUiXtuY742OPS6czG7hQP0oW9sXNY+pX7oZgzRdAdwCembnhBP4sHANl58HS76fy4BD3JtjN3pqwYoDl5QqslXC4qP9XCC8hDUUWAOl6iUHID03cvuQnG+lvbzWeUZlayl6nUaLuMn6RBDTEj8rNg== X-Forefront-PRVS: 0860FE717F X-Microsoft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KOAJ3hhiGOG3r7tlg0NLcCjMQWpaibi/HarSYcKgjk+pW4zclkvKS7O0FgP7kQZjWbPQaSfc3xqBfaDpJqs0kqT1N+NS4YcToeUIHyClS4DexmUS1ZTwBtxnoE/6MaOHKEXBXBD/3PhEIZ5D/D65PDt98yNgcZZFXCZke27eRFc=;7:lg3p1DG6LIlEdtz2imQ5NOIK6GYB5AAgj+lULtbnCFuYVOHTXVAPnBvAm2lhn7dhu9yLWNPDOegp2K+6fDT/HE9i6mkyfw1ob90O9TYrWIkmdCBZFtM7+hjpSRouwyVNmjAWigtI5X1QWvbo3HtTLA== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BYAPR07MB5175;20:Jj2ZqCjusBpSDwuTnvBsmt5PsxrBHlzyGEOH3l1HkFdwbzB4N68dvN1gRg8bwjkR0qs2ci1iQaoGjLg0tFMm1Ymeu4wQTgFpdMzmXL7JhyZLIg372u8bLXNLsiQX+u1rxdf85lwXlwJ+K78uaGxdaakAM24SHyAA4fNrs1mUp+ILGKjE2bkmck/v+hqp9FVAJbiR/ZNJb1cWza/iKmI2GrPYhMnyyrP3x2leuhfJfncRkMlsFDn6QZO5wD+ZXM7u X-OriginatorOrg: cadence.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2018 10:10:45.3748 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8d53fae3-c9f9-4fd1-c543-08d64d3e1cd7 X-MS-Exchange-CrossTenant-Id: d36035c5-6ce6-4662-a3dc-e762e61ae4c9 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=d36035c5-6ce6-4662-a3dc-e762e61ae4c9;Ip=[158.140.1.28];Helo=[sjmaillnx2.cadence.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR07MB5175 X-Proofpoint-SPF-Result: pass X-Proofpoint-SPF-Record: v=spf1 a:mx-sanjose2.Cadence.COM a:mx-sanjose4.Cadence.COM a:mx-sanjose5.Cadence.COM include:mktomail.com include:spf-0014ca01.pphosted.com include:spf.protection.outlook.com include:auth.msgapp.com include:spf.mandrillapp.com ~all X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-11-18_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_check_notspam policy=outbound_check score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811180096 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Patch implements related to default endpoint callback functions defined in usb_ep_ops object Signed-off-by: Pawel Laszczak --- drivers/usb/cdns3/ep0.c | 191 ++++++++++++++++++++++++++++++++++++- drivers/usb/cdns3/gadget.c | 8 ++ drivers/usb/cdns3/gadget.h | 10 ++ 3 files changed, 207 insertions(+), 2 deletions(-) diff --git a/drivers/usb/cdns3/ep0.c b/drivers/usb/cdns3/ep0.c index ca1795467155..d05169e73631 100644 --- a/drivers/usb/cdns3/ep0.c +++ b/drivers/usb/cdns3/ep0.c @@ -18,11 +18,185 @@ static struct usb_endpoint_descriptor cdns3_gadget_ep0_desc = { .bmAttributes = USB_ENDPOINT_XFER_CONTROL, }; +/** + * cdns3_ep0_run_transfer - Do transfer on default endpoint hardware + * @priv_dev: extended gadget object + * @dma_addr: physical address where data is/will be stored + * @length: data length + * @erdy: set it to 1 when ERDY packet should be sent - + * exit from flow control state + */ +static void cdns3_ep0_run_transfer(struct cdns3_device *priv_dev, + dma_addr_t dma_addr, + unsigned int length, int erdy) +{ + struct cdns3_usb_regs __iomem *regs = priv_dev->regs; + + priv_dev->trb_ep0->buffer = TRB_BUFFER(dma_addr); + priv_dev->trb_ep0->length = TRB_LEN(length); + priv_dev->trb_ep0->control = TRB_CYCLE | TRB_IOC | TRB_TYPE(TRB_NORMAL); + + cdns3_select_ep(priv_dev, + priv_dev->ep0_data_dir ? USB_DIR_IN : USB_DIR_OUT); + + writel(EP_STS_TRBERR, ®s->ep_sts); + writel(EP_TRADDR_TRADDR(priv_dev->trb_ep0_dma), ®s->ep_traddr); + + dev_dbg(&priv_dev->dev, "//Ding Dong ep0%s\n", + priv_dev->ep0_data_dir ? "IN" : "OUT"); + + /* TRB should be prepared before starting transfer */ + writel(EP_CMD_DRDY, ®s->ep_cmd); + + if (erdy) + writel(EP_CMD_ERDY, &priv_dev->regs->ep_cmd); +} + static void cdns3_prepare_setup_packet(struct cdns3_device *priv_dev) { //TODO: Implements this function } +static void cdns3_set_hw_configuration(struct cdns3_device *priv_dev) +{ + struct cdns3_endpoint *priv_ep; + struct usb_request *request; + struct usb_ep *ep; + int result = 0; + + if (priv_dev->hw_configured_flag) + return; + + writel(USB_CONF_CFGSET, &priv_dev->regs->usb_conf); + writel(EP_CMD_ERDY | EP_CMD_REQ_CMPL, &priv_dev->regs->ep_cmd); + + cdns3_set_register_bit(&priv_dev->regs->usb_conf, + USB_CONF_U1EN | USB_CONF_U2EN); + + /* wait until configuration set */ + result = cdns3_handshake(&priv_dev->regs->usb_sts, + USB_STS_CFGSTS_MASK, 1, 100); + + priv_dev->hw_configured_flag = 1; + cdns3_enable_l1(priv_dev, 1); + + list_for_each_entry(ep, &priv_dev->gadget.ep_list, ep_list) { + if (ep->enabled) { + priv_ep = ep_to_cdns3_ep(ep); + request = cdns3_next_request(&priv_ep->request_list); + if (request) + cdns3_ep_run_transfer(priv_ep, request); + } + } +} + +/** + * cdns3_gadget_ep0_enable + * Function shouldn't be called by gadget driver, + * endpoint 0 is allways active + */ +static int cdns3_gadget_ep0_enable(struct usb_ep *ep, + const struct usb_endpoint_descriptor *desc) +{ + return -EINVAL; +} + +/** + * cdns3_gadget_ep0_disable + * Function shouldn't be called by gadget driver, + * endpoint 0 is allways active + */ +static int cdns3_gadget_ep0_disable(struct usb_ep *ep) +{ + return -EINVAL; +} + +/** + * cdns3_gadget_ep0_set_halt + * @ep: pointer to endpoint zero object + * @value: 1 for set stall, 0 for clear stall + * + * Returns 0 + */ +static int cdns3_gadget_ep0_set_halt(struct usb_ep *ep, int value) +{ + /* TODO */ + return 0; +} + +/** + * cdns3_gadget_ep0_queue Transfer data on endpoint zero + * @ep: pointer to endpoint zero object + * @request: pointer to request object + * @gfp_flags: gfp flags + * + * Returns 0 on success, error code elsewhere + */ +static int cdns3_gadget_ep0_queue(struct usb_ep *ep, + struct usb_request *request, + gfp_t gfp_flags) +{ + struct cdns3_endpoint *priv_ep = ep_to_cdns3_ep(ep); + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + unsigned long flags; + int erdy_sent = 0; + int ret = 0; + + dev_dbg(&priv_dev->dev, "Queue to Ep0%s L: %d\n", + priv_dev->ep0_data_dir ? "IN" : "OUT", + request->length); + + /* send STATUS stage */ + if (request->length == 0 && request->zero == 0) { + spin_lock_irqsave(&priv_dev->lock, flags); + cdns3_select_ep(priv_dev, 0x00); + + erdy_sent = !priv_dev->hw_configured_flag; + cdns3_set_hw_configuration(priv_dev); + + if (!erdy_sent) + writel(EP_CMD_ERDY | EP_CMD_REQ_CMPL, + &priv_dev->regs->ep_cmd); + + cdns3_prepare_setup_packet(priv_dev); + request->actual = 0; + priv_dev->status_completion_no_call = true; + priv_dev->pending_status_request = request; + spin_unlock_irqrestore(&priv_dev->lock, flags); + + /* + * Since there is no completion interrupt for status stage, + * it needs to call ->completion in software after + * ep0_queue is back. + */ + queue_work(system_freezable_wq, &priv_dev->pending_status_wq); + return 0; + } + + spin_lock_irqsave(&priv_dev->lock, flags); + if (!list_empty(&priv_ep->request_list)) { + dev_err(&priv_dev->dev, + "can't handle multiple requests for ep0\n"); + spin_unlock_irqrestore(&priv_dev->lock, flags); + return -EOPNOTSUPP; + } + + ret = usb_gadget_map_request_by_dev(priv_dev->sysdev, request, + priv_dev->ep0_data_dir); + if (ret) { + spin_unlock_irqrestore(&priv_dev->lock, flags); + dev_err(&priv_dev->dev, "failed to map request\n"); + return -EINVAL; + } + + priv_dev->ep0_request = request; + list_add_tail(&request->list, &priv_ep->request_list); + cdns3_ep0_run_transfer(priv_dev, request->dma, request->length, 1); + spin_unlock_irqrestore(&priv_dev->lock, flags); + + return ret; +} + /** * cdns3_gadget_ep_set_wedge Set wedge on selected endpoint * @ep: endpoint object @@ -41,6 +215,17 @@ int cdns3_gadget_ep_set_wedge(struct usb_ep *ep) return 0; } +const struct usb_ep_ops cdns3_gadget_ep0_ops = { + .enable = cdns3_gadget_ep0_enable, + .disable = cdns3_gadget_ep0_disable, + .alloc_request = cdns3_gadget_ep_alloc_request, + .free_request = cdns3_gadget_ep_free_request, + .queue = cdns3_gadget_ep0_queue, + .dequeue = cdns3_gadget_ep_dequeue, + .set_halt = cdns3_gadget_ep0_set_halt, + .set_wedge = cdns3_gadget_ep_set_wedge, +}; + /** * cdns3_ep0_config - Configures default endpoint * @priv_dev: extended gadget object @@ -62,6 +247,9 @@ void cdns3_ep0_config(struct cdns3_device *priv_dev) priv_dev->ep0_request = NULL; } + priv_dev->u1_allowed = 0; + priv_dev->u2_allowed = 0; + priv_dev->gadget.ep0->maxpacket = max_packet_size; cdns3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(max_packet_size); @@ -106,8 +294,7 @@ int cdns3_init_ep0(struct cdns3_device *priv_dev) sprintf(ep0->name, "ep0"); /* fill linux fields */ - //TODO: implements cdns3_gadget_ep0_ops object - //ep0->endpoint.ops = &cdns3_gadget_ep0_ops; + ep0->endpoint.ops = &cdns3_gadget_ep0_ops; ep0->endpoint.maxburst = 1; usb_ep_set_maxpacket_limit(&ep0->endpoint, ENDPOINT0_MAX_PACKET_LIMIT); ep0->endpoint.address = 0; diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c index 1f2a434486dc..c965da16c0c8 100644 --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/gadget.c @@ -188,6 +188,14 @@ static void cdns3_ep_stall_flush(struct cdns3_endpoint *priv_ep) priv_ep->flags |= EP_STALL; } +void cdns3_enable_l1(struct cdns3_device *priv_dev, int enable) +{ + if (enable) + writel(USB_CONF_L1EN, &priv_dev->regs->usb_conf); + else + writel(USB_CONF_L1DS, &priv_dev->regs->usb_conf); +} + /** * cdns3_gadget_giveback - call struct usb_request's ->complete callback * @priv_ep: The endpoint to whom the request belongs to diff --git a/drivers/usb/cdns3/gadget.h b/drivers/usb/cdns3/gadget.h index a4be288b34cb..224f6b830bc9 100644 --- a/drivers/usb/cdns3/gadget.h +++ b/drivers/usb/cdns3/gadget.h @@ -1068,11 +1068,21 @@ struct cdns3_device { struct usb_request *pending_status_request; }; +int cdns3_handshake(void __iomem *ptr, u32 mask, u32 done, int usec); void cdns3_set_register_bit(void __iomem *ptr, u32 mask); int cdns3_init_ep0(struct cdns3_device *priv_dev); void cdns3_ep0_config(struct cdns3_device *priv_dev); void cdns3_select_ep(struct cdns3_device *priv_dev, u32 ep); +void cdns3_enable_l1(struct cdns3_device *priv_dev, int enable); +struct usb_request *cdns3_next_request(struct list_head *list); +int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, + struct usb_request *request); int cdns3_gadget_ep_set_wedge(struct usb_ep *ep); int cdns3_gadget_ep_set_halt(struct usb_ep *ep, int value); +struct usb_request *cdns3_gadget_ep_alloc_request(struct usb_ep *ep, + gfp_t gfp_flags); +void cdns3_gadget_ep_free_request(struct usb_ep *ep, + struct usb_request *request); +int cdns3_gadget_ep_dequeue(struct usb_ep *ep, struct usb_request *request); #endif /* __LINUX_CDNS3_GADGET */ From patchwork Sun Nov 18 10:09:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Laszczak X-Patchwork-Id: 10687727 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F0F4513BB for ; Sun, 18 Nov 2018 10:12:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E09CC29D38 for ; Sun, 18 Nov 2018 10:12:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D3F5E29D47; Sun, 18 Nov 2018 10:12:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCD1129D38 for ; Sun, 18 Nov 2018 10:12:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727189AbeKRUay (ORCPT ); Sun, 18 Nov 2018 15:30:54 -0500 Received: from mx0a-0014ca01.pphosted.com ([208.84.65.235]:36320 "EHLO mx0a-0014ca01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726077AbeKRUax (ORCPT ); Sun, 18 Nov 2018 15:30:53 -0500 Received: from pps.filterd (m0042385.ppops.net [127.0.0.1]) by mx0a-0014ca01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id wAIA6XnW016036; Sun, 18 Nov 2018 02:10:50 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=proofpoint; bh=GmCP/vlRhYQlwtTkQNa6rLxmtTQ5sIucxHWwCjFi8D4=; b=P8pK2GtxJ3WMf0DRypQ7CPoT7gacDPlBjXbA1bRZXfGxk34yaJIvP+zmBYfdbOlkgUPB VYK/4ivLKIod0An5xj4o0Xu+yjUHJJayzIjejS4YuahwY5kTv9yKwue+Yhnc/8DPRehT MfMsKlImix0pSzdFS0S5PzX5IR09p3SxOQeUjKCqKeD9g3uB9SZDzSqERGdhGonVgAaw 34Ya9at8W3SnNq261ztVjNQaKChJ4lGx87Ncj6C9gWo5CJ98R3Tcv//NJPgXQ+lyJOZp zpKqfcYLhHUS5WE7555XpnyuzGUPA6g0pRLN+8XTTMzLO2cawvpadztHQnIft/pzirYs 7g== Authentication-Results: cadence.com; spf=pass smtp.mailfrom=pawell@cadence.com Received: from nam01-sn1-obe.outbound.protection.outlook.com (mail-sn1nam01lp0118.outbound.protection.outlook.com [207.46.163.118]) by mx0a-0014ca01.pphosted.com with ESMTP id 2ntge14vg8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 18 Nov 2018 02:10:49 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GmCP/vlRhYQlwtTkQNa6rLxmtTQ5sIucxHWwCjFi8D4=; b=pe0Pmk1mEEul43cIMi6oGuqhpIz9MWqSd9KnRMpFYHesrG4XV/hSiwarny0g3b3XzYEbYu4dP2hjl9HXOHn6JmiqVlG6B8hTOJvY6piKcPMTtrihhn95kwl0dbhxcRyQcO+EtzFFPUG7aFttakYn0raj3IAvv4E7f6nLWgEu+bU= Received: from DM5PR07CA0028.namprd07.prod.outlook.com (2603:10b6:3:16::14) by BN7PR07MB5169.namprd07.prod.outlook.com (2603:10b6:408:25::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.27; Sun, 18 Nov 2018 10:10:47 +0000 Received: from DM3NAM05FT006.eop-nam05.prod.protection.outlook.com (2a01:111:f400:7e51::203) by DM5PR07CA0028.outlook.office365.com (2603:10b6:3:16::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.21 via Frontend Transport; Sun, 18 Nov 2018 10:10:46 +0000 Received-SPF: SoftFail (protection.outlook.com: domain of transitioning cadence.com discourages use of 158.140.1.28 as permitted sender) Received: from sjmaillnx2.cadence.com (158.140.1.28) by DM3NAM05FT006.mail.protection.outlook.com (10.152.98.111) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.3 via Frontend Transport; Sun, 18 Nov 2018 10:10:45 +0000 Received: from maileu3.global.cadence.com (maileu3.cadence.com [10.160.88.99]) by sjmaillnx2.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAb5T029622 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Sun, 18 Nov 2018 02:10:45 -0800 X-CrossPremisesHeadersFilteredBySendConnector: maileu3.global.cadence.com Received: from maileu3.global.cadence.com (10.160.88.99) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Sun, 18 Nov 2018 11:10:43 +0100 Received: from lvlogina.cadence.com (10.165.176.102) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Sun, 18 Nov 2018 11:10:43 +0100 Received: from lvlogina.cadence.com (localhost.localdomain [127.0.0.1]) by lvlogina.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAeV3032015; Sun, 18 Nov 2018 10:10:40 GMT Received: (from pawell@localhost) by lvlogina.cadence.com (8.14.4/8.14.4/Submit) id wAIAAdVP031955; Sun, 18 Nov 2018 10:10:39 GMT From: Pawel Laszczak To: CC: , , , , , , , , , , , , "Pawel Laszczak" Subject: [RFC PATCH v2 11/15] usb:cdns3: Implements ISR functionality. Date: Sun, 18 Nov 2018 10:09:07 +0000 Message-ID: <1542535751-16079-12-git-send-email-pawell@cadence.com> X-Mailer: git-send-email 1.7.11.2 In-Reply-To: <1542535751-16079-1-git-send-email-pawell@cadence.com> References: <1542535751-16079-1-git-send-email-pawell@cadence.com> MIME-Version: 1.0 X-OrganizationHeadersPreserved: maileu3.global.cadence.com X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:158.140.1.28;IPV:CAL;SCL:-1;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(39860400002)(346002)(136003)(396003)(376002)(2980300002)(36092001)(199004)(189003)(26826003)(2351001)(217873002)(575784001)(86362001)(50466002)(50226002)(16586007)(356004)(6666004)(4326008)(54906003)(42186006)(316002)(106466001)(478600001)(87636003)(2906002)(4744004)(48376002)(26005)(51416003)(8936002)(186003)(76176011)(246002)(36756003)(426003)(336012)(446003)(305945005)(7636002)(8676002)(105596002)(4720700003)(6916009)(47776003)(5660300001)(14444005)(486006)(107886003)(2616005)(126002)(11346002)(476003);DIR:OUT;SFP:1101;SCL:1;SRVR:BN7PR07MB5169;H:sjmaillnx2.cadence.com;FPR:;SPF:SoftFail;LANG:en;PTR:corp.cadence.com;A:1;MX:1; X-Microsoft-Exchange-Diagnostics: 1;DM3NAM05FT006;1:Qn2W8ze8pdc/0UEnFBLGhubRU6Q8mEuF25lFoHyJXYdgaHHunFpwbON+SNcGIaIzmfuyUQEl1TMFhQhqySVz9vX2i6IvSapRa14gq3TuAoHKBsdvxzy+XQO/uILCTDij X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3be6d323-0d59-44e6-b3db-08d64d3e1b94 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060);SRVR:BN7PR07MB5169; X-Microsoft-Exchange-Diagnostics: 1;BN7PR07MB5169;3:tQgahCP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wijlEWxD0j7f1kubwAWZPMA2Hx22VhZ9iJLGXCyD8y8+MGXLwpEIlgoEE/2NoEDiqLkMO0xpkoX1qGIDAUAZH7fBkQwZnZ+v6KH1zbmVKovHRqa55OPd5av5J/bLFQRJ3ClcUwtE9Qmiq6mC12oAeRe5tuVtZOXHNauqU2yIdbfjGqPhp8u2GpBrH6P3vlYOz++HSbeU85UPf8oTORnuuhlgHm+MV4nSGSCicvEkIKdPrWIeeIRhZnJzMUGbRFNL0oL4KS8MhsGr+HqeAZCr5fmje0I7QiuCeLUe0LBB+UkLnyqnJiSIdbb+XfeEJ6cPbzF6OzRbviRpvaNJVCQHMNn3jX1y3HZaYf4TdhvEMiPNf5rr+0qJLNI/EDSwrgP/gHQMlb7tJpEmeLAgjhc9b+bfe3KEocwfEOlndfKvRvorSjtny3R4SOYoRghGs1 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(72806322054110); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(93006095)(93003095)(3002001)(3231415)(944501410)(52105112)(148016)(149066)(150057)(6041310)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051)(76991095);SRVR:BN7PR07MB5169;BCL:0;PCL:0;RULEID:;SRVR:BN7PR07MB5169; X-Microsoft-Exchange-Diagnostics: 1;BN7PR07MB5169;4:8jET2WkXYntJRq7rMEjpOURbUWQlWR+sgMCR5IyBcFVeEtKOZKQdTFFbexC1whLV43ZwcCdBC3GwxjDCfBDTafRZbBrKxQB05AWnCvVl25kRqUWdc/5N0dgncpg5pgUNLS8zMR+1844TWVQtMgOHriRyAl2Z/KMt/0j6oDlW+TbYSd51yRgDLdBYZLrrmahDF3LSV7jnuk073/F3JVfA3QFiiqJqWTpjh1fhBWV0gYSmKFNmczR6iOId2dvikz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VmnbmQFuBDqPBgFBAEAylSnpN3kIrlaA6/+gUKmILhzFAxig9UR2/wlIjz6M8CS3XhLpXlkszlN2idOpnOPrA==;5:rNg7gdyBZXMU2lr78MEfkvPpBwfKh+SnPiVzcO73BQqPwjsxfNU/t28yzMczMMhRbxqpFuiPPg6XGsf1o2Ptkd86u8X8lLubwnHLKeViKm7/160AW8NnoxmskMnEPhelRBDiSCkdEcJdh9xA5cdESomXe8f3qG9pGV8GoH5MJN0=;7:8KNWHwNOEwjVK2Q1CKYDEq6KBeGuODpNAoIE8TZoY+zIKk22370SwYbHwKt9tpBIyN3BSCkqsHchdPwcmEsIgqHbIElm48TmZU6smo77HX5P6hH3WM4/wmjGeTuK6XgcmByzIEz+HVC2lA/0FqbkwQ== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BN7PR07MB5169;20:53L1rPtKbTpx3885oergDMgrv27xUM0vZTDWKh9UIVxxsZXJk0L7UnUy7UiomHwanj955PelBTrw+/3S42q+m3uEu4wEy4CZW/C7ad6iRQUjQ+g3/q7EbuCBHqXuNx+cUOHP8t3QOBYfxj9HCvFYTWTostLErrEHXbCSb/Kity1/rgtlSPW+7nH2YE0920A40XlHEODt9gKisV9ZFrjl1yKj/VYMBzvi5N27BD54xO+QC0TbkY1zdbLkPCXMls6B X-OriginatorOrg: cadence.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2018 10:10:45.9607 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3be6d323-0d59-44e6-b3db-08d64d3e1b94 X-MS-Exchange-CrossTenant-Id: d36035c5-6ce6-4662-a3dc-e762e61ae4c9 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=d36035c5-6ce6-4662-a3dc-e762e61ae4c9;Ip=[158.140.1.28];Helo=[sjmaillnx2.cadence.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR07MB5169 X-Proofpoint-SPF-Result: pass X-Proofpoint-SPF-Record: v=spf1 a:mx-sanjose2.Cadence.COM a:mx-sanjose4.Cadence.COM a:mx-sanjose5.Cadence.COM include:mktomail.com include:spf-0014ca01.pphosted.com include:spf.protection.outlook.com include:auth.msgapp.com include:spf.mandrillapp.com ~all X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-11-18_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_check_notspam policy=outbound_check score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=966 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811180096 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Patch adds set of generic functions used for handling interrupts generated by controller. Interrupt related functions are divided into three groups. The first is related to ep0 and is placed in ep0.c. The second is responsible for non-default endpoints and is implemented in gadget.c file. The last group is not related to endpoints interrupts and is placed in gadget.c. All groups have common entry point in cdns3_irq_handler_thread function. Signed-off-by: Pawel Laszczak --- drivers/usb/cdns3/ep0.c | 63 +++++++++++ drivers/usb/cdns3/gadget.c | 224 ++++++++++++++++++++++++++++++++++++- drivers/usb/cdns3/gadget.h | 1 + 3 files changed, 287 insertions(+), 1 deletion(-) diff --git a/drivers/usb/cdns3/ep0.c b/drivers/usb/cdns3/ep0.c index d05169e73631..eb92fd234bd7 100644 --- a/drivers/usb/cdns3/ep0.c +++ b/drivers/usb/cdns3/ep0.c @@ -90,6 +90,69 @@ static void cdns3_set_hw_configuration(struct cdns3_device *priv_dev) } } +static void __pending_setup_status_handler(struct cdns3_device *priv_dev) +{ + //TODO: Implements this function +} + +/** + * cdns3_ep0_setup_phase - Handling setup USB requests + * @priv_dev: extended gadget object + */ +static void cdns3_ep0_setup_phase(struct cdns3_device *priv_dev) +{ + //TODO: Implements this function. +} + +static void cdns3_transfer_completed(struct cdns3_device *priv_dev) +{ + //TODO: Implements this function +} + +/** + * cdns3_check_ep0_interrupt_proceed - Processes interrupt related to endpoint 0 + * @priv_dev: extended gadget object + * @dir: 1 for IN direction, 0 for OUT direction + */ +void cdns3_check_ep0_interrupt_proceed(struct cdns3_device *priv_dev, int dir) +{ + struct cdns3_usb_regs __iomem *regs = priv_dev->regs; + u32 ep_sts_reg; + + cdns3_select_ep(priv_dev, 0 | (dir ? USB_DIR_IN : USB_DIR_OUT)); + ep_sts_reg = readl(®s->ep_sts); + + __pending_setup_status_handler(priv_dev); + + if ((ep_sts_reg & EP_STS_SETUP) && dir == 0) { + struct usb_ctrlrequest *setup = priv_dev->setup; + + writel(EP_STS_SETUP | EP_STS_IOC | EP_STS_ISP, ®s->ep_sts); + + priv_dev->ep0_data_dir = setup->bRequestType & USB_DIR_IN; + cdns3_ep0_setup_phase(priv_dev); + ep_sts_reg &= ~(EP_STS_SETUP | EP_STS_IOC | EP_STS_ISP); + } + + if (ep_sts_reg & EP_STS_TRBERR) + writel(EP_STS_TRBERR, &priv_dev->regs->ep_sts); + + if (ep_sts_reg & EP_STS_DESCMIS) { + writel(EP_STS_DESCMIS, &priv_dev->regs->ep_sts); + + if (dir == 0 && !priv_dev->setup_pending) { + priv_dev->ep0_data_dir = 0; + cdns3_ep0_run_transfer(priv_dev, priv_dev->setup_dma, + 8, 0); + } + } + + if ((ep_sts_reg & EP_STS_IOC) || (ep_sts_reg & EP_STS_ISP)) { + writel(EP_STS_IOC, &priv_dev->regs->ep_sts); + cdns3_transfer_completed(priv_dev); + } +} + /** * cdns3_gadget_ep0_enable * Function shouldn't be called by gadget driver, diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c index c965da16c0c8..309202474e57 100644 --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/gadget.c @@ -58,6 +58,18 @@ void cdns3_set_register_bit(void __iomem *ptr, u32 mask) writel(mask, ptr); } +/** + * cdns3_ep_reg_pos_to_index - Macro converts bit position of ep_ists register + * to index of endpoint object in cdns3_device.eps[] container + * @i: bit position of endpoint for which endpoint object is required + * + * Remember that endpoint container doesn't contain default endpoint + */ +static u8 cdns3_ep_reg_pos_to_index(int i) +{ + return ((i / 16) + (((i % 16) - 2) * 2)); +} + /** * cdns3_next_request - returns next request from list * @list: list containing requests @@ -188,6 +200,21 @@ static void cdns3_ep_stall_flush(struct cdns3_endpoint *priv_ep) priv_ep->flags |= EP_STALL; } +/** + * cdns3_gadget_unconfig - reset device configuration + * @priv_dev: extended gadget object + */ +void cdns3_gadget_unconfig(struct cdns3_device *priv_dev) +{ + /* RESET CONFIGURATION */ + writel(USB_CONF_CFGRST, &priv_dev->regs->usb_conf); + + cdns3_enable_l1(priv_dev, 0); + priv_dev->hw_configured_flag = 0; + priv_dev->onchip_mem_allocated_size = 0; + priv_dev->out_mem_is_allocated = 0; +} + void cdns3_enable_l1(struct cdns3_device *priv_dev, int enable) { if (enable) @@ -196,6 +223,23 @@ void cdns3_enable_l1(struct cdns3_device *priv_dev, int enable) writel(USB_CONF_L1DS, &priv_dev->regs->usb_conf); } +static enum usb_device_speed cdns3_get_speed(struct cdns3_device *priv_dev) +{ + u32 reg; + + reg = readl(&priv_dev->regs->usb_sts); + + if (DEV_SUPERSPEED(reg)) + return USB_SPEED_SUPER; + else if (DEV_HIGHSPEED(reg)) + return USB_SPEED_HIGH; + else if (DEV_FULLSPEED(reg)) + return USB_SPEED_FULL; + else if (DEV_LOWSPEED(reg)) + return USB_SPEED_LOW; + return USB_SPEED_UNKNOWN; +} + /** * cdns3_gadget_giveback - call struct usb_request's ->complete callback * @priv_ep: The endpoint to whom the request belongs to @@ -221,12 +265,136 @@ void cdns3_gadget_giveback(struct cdns3_endpoint *priv_ep, */ int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, struct usb_request *request) +{ + return 0; +} + +static void cdns3_transfer_completed(struct cdns3_device *priv_dev, + struct cdns3_endpoint *priv_ep) { //TODO: Implements this function. +} + +/** + * cdns3_check_ep_interrupt_proceed - Processes interrupt related to endpoint + * @priv_ep: endpoint object + * + * Returns 0 + */ +static int cdns3_check_ep_interrupt_proceed(struct cdns3_endpoint *priv_ep) +{ + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + struct cdns3_usb_regs __iomem *regs; + u32 ep_sts_reg; + + regs = priv_dev->regs; + + cdns3_select_ep(priv_dev, priv_ep->endpoint.address); + ep_sts_reg = readl(®s->ep_sts); + + if (ep_sts_reg & EP_STS_TRBERR) + writel(EP_STS_TRBERR, ®s->ep_sts); + + if (ep_sts_reg & EP_STS_ISOERR) + writel(EP_STS_ISOERR, ®s->ep_sts); + + if (ep_sts_reg & EP_STS_OUTSMM) + writel(EP_STS_OUTSMM, ®s->ep_sts); + + if (ep_sts_reg & EP_STS_NRDY) + writel(EP_STS_NRDY, ®s->ep_sts); + + if ((ep_sts_reg & EP_STS_IOC) || (ep_sts_reg & EP_STS_ISP)) { + writel(EP_STS_IOC | EP_STS_ISP, ®s->ep_sts); + cdns3_transfer_completed(priv_dev, priv_ep); + } + + if (ep_sts_reg & EP_STS_DESCMIS) + writel(EP_STS_DESCMIS, ®s->ep_sts); return 0; } +/** + * cdns3_check_usb_interrupt_proceed - Processes interrupt related to device + * @priv_dev: extended gadget object + * @usb_ists: bitmap representation of device's reported interrupts + * (usb_ists register value) + */ +static void cdns3_check_usb_interrupt_proceed(struct cdns3_device *priv_dev, + u32 usb_ists) +{ + struct cdns3_usb_regs __iomem *regs; + int speed = 0; + + regs = priv_dev->regs; + + /* Connection detected */ + if (usb_ists & (USB_ISTS_CON2I | USB_ISTS_CONI)) { + writel(USB_ISTS_CON2I | USB_ISTS_CONI, ®s->usb_ists); + speed = cdns3_get_speed(priv_dev); + + dev_dbg(&priv_dev->dev, "Connection detected at speed: %s %d\n", + usb_speed_string(speed), speed); + + priv_dev->gadget.speed = speed; + priv_dev->is_connected = 1; + usb_gadget_set_state(&priv_dev->gadget, USB_STATE_POWERED); + cdns3_ep0_config(priv_dev); + } + + /* SS Disconnection detected */ + if (usb_ists & (USB_ISTS_DIS2I | USB_ISTS_DISI)) { + dev_dbg(&priv_dev->dev, "Disconnection detected\n"); + + writel(USB_ISTS_DIS2I | USB_ISTS_DISI, ®s->usb_ists); + if (priv_dev->gadget_driver && + priv_dev->gadget_driver->disconnect) { + spin_unlock(&priv_dev->lock); + priv_dev->gadget_driver->disconnect(&priv_dev->gadget); + spin_lock(&priv_dev->lock); + } + priv_dev->gadget.speed = USB_SPEED_UNKNOWN; + usb_gadget_set_state(&priv_dev->gadget, USB_STATE_NOTATTACHED); + priv_dev->is_connected = 0; + cdns3_gadget_unconfig(priv_dev); + } + + if (usb_ists & USB_ISTS_L2ENTI) { + dev_dbg(&priv_dev->dev, "Device suspended\n"); + writel(USB_ISTS_L2ENTI, ®s->usb_ists); + } + + /* Exit from standby mode on L2 exit (Suspend in HS/FS or SS) */ + if (usb_ists & USB_ISTS_L2EXTI) { + dev_dbg(&priv_dev->dev, "[Interrupt] L2 exit detected\n"); + writel(USB_ISTS_L2EXTI, ®s->usb_ists); + } + + /* Exit from standby mode on U3 exit (Suspend in HS/FS or SS). */ + if (usb_ists & USB_ISTS_U3EXTI) { + dev_dbg(&priv_dev->dev, "U3 exit detected\n"); + writel(USB_ISTS_U3EXTI, ®s->usb_ists); + } + + /* resets cases */ + if (usb_ists & (USB_ISTS_UWRESI | USB_ISTS_UHRESI | USB_ISTS_U2RESI)) { + writel(USB_ISTS_U2RESI | USB_ISTS_UWRESI | USB_ISTS_UHRESI, + ®s->usb_ists); + + /*read again to check the actuall speed*/ + speed = cdns3_get_speed(priv_dev); + + dev_dbg(&priv_dev->dev, "Reset detected at speed: %s %d\n", + usb_speed_string(speed), speed); + + usb_gadget_set_state(&priv_dev->gadget, USB_STATE_DEFAULT); + priv_dev->gadget.speed = speed; + cdns3_gadget_unconfig(priv_dev); + cdns3_ep0_config(priv_dev); + } +} + /** * cdns3_irq_handler - irq line interrupt handler * @cdns: cdns3 instance @@ -237,8 +405,62 @@ int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, */ static irqreturn_t cdns3_irq_handler_thread(struct cdns3 *cdns) { + struct cdns3_device *priv_dev; irqreturn_t ret = IRQ_NONE; - //TODO: implements this function + unsigned long flags; + u32 reg; + + priv_dev = container_of(cdns->gadget_dev, struct cdns3_device, dev); + spin_lock_irqsave(&priv_dev->lock, flags); + + /* check USB device interrupt */ + reg = readl(&priv_dev->regs->usb_ists); + if (reg) { + dev_dbg(&priv_dev->dev, "IRQ: usb_ists: %08X\n", reg); + cdns3_check_usb_interrupt_proceed(priv_dev, reg); + ret = IRQ_HANDLED; + } + + /* check endpoint interrupt */ + reg = readl(&priv_dev->regs->ep_ists); + if (reg != 0) { + dev_dbg(&priv_dev->dev, "IRQ ep_ists: %08X\n", reg); + } else { + if (USB_STS_CFGSTS(readl(&priv_dev->regs->usb_sts))) + ret = IRQ_HANDLED; + goto irqend; + } + + /* handle default endpoint OUT */ + if (reg & EP_ISTS_EP_OUT0) { + cdns3_check_ep0_interrupt_proceed(priv_dev, 0); + ret = IRQ_HANDLED; + } + + /* handle default endpoint IN */ + if (reg & EP_ISTS_EP_IN0) { + cdns3_check_ep0_interrupt_proceed(priv_dev, 1); + ret = IRQ_HANDLED; + } + + /* check if interrupt from non default endpoint, if no exit */ + reg &= ~(EP_ISTS_EP_OUT0 | EP_ISTS_EP_IN0); + if (!reg) + goto irqend; + + do { + unsigned int bit_pos = ffs(reg); + u32 bit_mask = 1 << (bit_pos - 1); + int index; + + index = cdns3_ep_reg_pos_to_index(bit_pos); + cdns3_check_ep_interrupt_proceed(priv_dev->eps[index]); + reg &= ~bit_mask; + ret = IRQ_HANDLED; + } while (reg); + +irqend: + spin_unlock_irqrestore(&priv_dev->lock, flags); return ret; } diff --git a/drivers/usb/cdns3/gadget.h b/drivers/usb/cdns3/gadget.h index 224f6b830bc9..8c2f363f9340 100644 --- a/drivers/usb/cdns3/gadget.h +++ b/drivers/usb/cdns3/gadget.h @@ -1072,6 +1072,7 @@ int cdns3_handshake(void __iomem *ptr, u32 mask, u32 done, int usec); void cdns3_set_register_bit(void __iomem *ptr, u32 mask); int cdns3_init_ep0(struct cdns3_device *priv_dev); void cdns3_ep0_config(struct cdns3_device *priv_dev); +void cdns3_check_ep0_interrupt_proceed(struct cdns3_device *priv_dev, int dir); void cdns3_select_ep(struct cdns3_device *priv_dev, u32 ep); void cdns3_enable_l1(struct cdns3_device *priv_dev, int enable); struct usb_request *cdns3_next_request(struct list_head *list); From patchwork Sun Nov 18 10:09:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Laszczak X-Patchwork-Id: 10687711 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B357B13BB for ; Sun, 18 Nov 2018 10:11:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A162129D31 for ; Sun, 18 Nov 2018 10:11:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9505629D38; Sun, 18 Nov 2018 10:11:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A7E129D3E for ; Sun, 18 Nov 2018 10:11:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727593AbeKRUbH (ORCPT ); Sun, 18 Nov 2018 15:31:07 -0500 Received: from mx0b-0014ca01.pphosted.com ([208.86.201.193]:41298 "EHLO mx0a-0014ca01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727332AbeKRUbE (ORCPT ); Sun, 18 Nov 2018 15:31:04 -0500 Received: from pps.filterd (m0042333.ppops.net [127.0.0.1]) by mx0b-0014ca01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id wAIA8q7E007702; Sun, 18 Nov 2018 02:10:51 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=proofpoint; bh=Ri0rRoCuzi5Zwr6rL2q84TLb34WtlpwOf1ixAbyJhXk=; b=P5Y7POIcio1Df7c07gUew2Kx/qBt0VG1rpCpGHTpybtzKby5zCXw4BaF7YBQFjbzwVkZ OVd6PbLp04zmySAbAtp3OJvq6+fBnyvHgfPpwjTY7lePCXyQVJIzIi3KS36LoXkdHtat IyFvkWOOHJB5OOnh50ayC1DiUG5vSe+uE3/JBJfBJ8617RDLcp91fntODkoVAw4RJzlX 3FoQ9oURfFaSrpetnCVmrPt+4DlXA5Cq3YrvcKNzPC7I//UD2gIma6wV7n/3nIcNQbNc NpEzD4PtTRuKxA3y89mkMmYurhD1+BQZjWmrG5dNQWYJhFlM48Ktmq9YJc0YC8y+xyd3 yA== Authentication-Results: cadence.com; spf=pass smtp.mailfrom=pawell@cadence.com Received: from nam05-dm3-obe.outbound.protection.outlook.com (mail-dm3nam05lp0118.outbound.protection.outlook.com [216.32.181.118]) by mx0b-0014ca01.pphosted.com with ESMTP id 2ntff7w450-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 18 Nov 2018 02:10:50 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ri0rRoCuzi5Zwr6rL2q84TLb34WtlpwOf1ixAbyJhXk=; b=hw8HbTXKXUI2o9yxbaOrJp3ZqNyXucezc1ripe6al7GZyIdqLVfEGZKFRHwb+miqGkHpjH3D2CQFrZY1uxK3XEVEnhBLSfymEairVu2m1Fi6Z2/N2yjcgypXrFCR9lfSSj5qpN8GkN8sEZz+eIVz3q7HVb69+wH/FzFOQnTN8K8= Received: from CO2PR07CA0063.namprd07.prod.outlook.com (2603:10b6:100::31) by SN1PR0701MB1870.namprd07.prod.outlook.com (2a01:111:e400:517b::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.26; Sun, 18 Nov 2018 10:10:47 +0000 Received: from DM3NAM05FT042.eop-nam05.prod.protection.outlook.com (2a01:111:f400:7e51::202) by CO2PR07CA0063.outlook.office365.com (2603:10b6:100::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.22 via Frontend Transport; Sun, 18 Nov 2018 10:10:47 +0000 Received-SPF: SoftFail (protection.outlook.com: domain of transitioning cadence.com discourages use of 158.140.1.28 as permitted sender) Received: from sjmaillnx2.cadence.com (158.140.1.28) by DM3NAM05FT042.mail.protection.outlook.com (10.152.98.156) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.3 via Frontend Transport; Sun, 18 Nov 2018 10:10:46 +0000 Received: from maileu3.global.cadence.com (maileu3.cadence.com [10.160.88.99]) by sjmaillnx2.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAb5U029622 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Sun, 18 Nov 2018 02:10:45 -0800 X-CrossPremisesHeadersFilteredBySendConnector: maileu3.global.cadence.com Received: from maileu3.global.cadence.com (10.160.88.99) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Sun, 18 Nov 2018 11:10:44 +0100 Received: from lvlogina.cadence.com (10.165.176.102) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Sun, 18 Nov 2018 11:10:44 +0100 Received: from lvlogina.cadence.com (localhost.localdomain [127.0.0.1]) by lvlogina.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAexH032166; Sun, 18 Nov 2018 10:10:40 GMT Received: (from pawell@localhost) by lvlogina.cadence.com (8.14.4/8.14.4/Submit) id wAIAAeAY032123; Sun, 18 Nov 2018 10:10:40 GMT From: Pawel Laszczak To: CC: , , , , , , , , , , , , "Pawel Laszczak" Subject: [RFC PATCH v2 12/15] usb:cdns3: Adds enumeration related function. Date: Sun, 18 Nov 2018 10:09:08 +0000 Message-ID: <1542535751-16079-13-git-send-email-pawell@cadence.com> X-Mailer: git-send-email 1.7.11.2 In-Reply-To: <1542535751-16079-1-git-send-email-pawell@cadence.com> References: <1542535751-16079-1-git-send-email-pawell@cadence.com> MIME-Version: 1.0 X-OrganizationHeadersPreserved: maileu3.global.cadence.com X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:158.140.1.28;IPV:CAL;SCL:-1;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(39850400004)(396003)(136003)(376002)(346002)(2980300002)(199004)(189003)(36092001)(356004)(486006)(51416003)(76176011)(50226002)(8936002)(186003)(26005)(126002)(86362001)(2906002)(426003)(446003)(11346002)(6666004)(4326008)(336012)(4744004)(476003)(2616005)(6916009)(107886003)(4720700003)(47776003)(8676002)(246002)(36756003)(7636002)(5660300001)(54906003)(16586007)(478600001)(305945005)(106466001)(26826003)(105596002)(42186006)(87636003)(316002)(50466002)(217873002)(48376002)(14444005)(2351001)(309714004);DIR:OUT;SFP:1101;SCL:1;SRVR:SN1PR0701MB1870;H:sjmaillnx2.cadence.com;FPR:;SPF:SoftFail;LANG:en;PTR:corp.cadence.com;A:1;MX:1; X-Microsoft-Exchange-Diagnostics: 1;DM3NAM05FT042;1:YII8wd/a4EoFRCSoGFM6rSQ7bfh1yKmP8yzbQUsgDDqqqPx48NqG5iGKXTto0ZX1gPYkOjN7ITa8XUf4O3ib1NASbVZJp1Leb+ZvvTURN3ZaVdKYkIEmWzAGud1nKjso X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ed79e2ba-3de0-4c21-e49b-08d64d3e1be0 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060);SRVR:SN1PR0701MB1870; X-Microsoft-Exchange-Diagnostics: 1;SN1PR0701MB1870;3:3IgVhbvGQF7/83WVQb6qc1dyjo8BHOurWh2nPzPs+wG+5cIu4XEfbA0B5WK2h9jfxWhYBrdzf9imy54zgeWMWyx/EUu+/icBWTq+KFU8YfJtJtstY7TbjDcSvXrqig3noOvXxcRz8Dc1wl2Sdeyxcq5JwXyxw9l0phD7XXumBcaSrEBAGsPYkiiB4kTZQEhubfoYDfutCQ3sjymsEjQ908uof4C/xhP2g/Wl3GUbklalfwc8Rb+3y5ZXzfL+Yp+A8vYEdBcqPE5j+yVnzoWJgWJPEVYarO4FRSWCWGP22urgPkviIxLSdDbYfLxX6pfOVqEwtV0fwzWceI+sqB4HEhlzkhPWn9ZvPi0g0Wg21XY=;25:Ek0861f01ivLBTodiGYpvYGusi9JLMjcr/gIWEuJkjL9aW7envYsq35ziojjFW5ivLIpOAshB9NVSL7osKG7yTkzlmOJiwPXkR66+owWvTEUwNFfvIXqsRyJsxurZnHWGDzUGzdn9znkCMYd0DxD6jU7WL8x9lztY042KJmqmSTOO9wEvFCjylqKHCvrxYcppk+pvZd2kOtIo61I3XMHDRpHQgyNyqUKjfIQR+1FrCF8viKevKDj3MvZXxX7CSFg+TwoHt7zF7fJ34Z5Y9HOalRjWJ+/gcfTiarf6hFKc4FBW0d1tk/HkkCfSqnhXQZOVk6tJUqsc1tfs0Ubaul+IjYWlcVUZm0QcJOAo8rDznY= X-MS-TrafficTypeDiagnostic: SN1PR0701MB1870: X-Microsoft-Exchange-Diagnostics: 1;SN1PR0701MB1870;31:sq5UJFgchVw5QMk6jJUr1hxivFCIGzMBjo7QA3Xjb9ZcFO2bQ4fEY8ECSkMK5ekC+G4ZEKHIcyEWoPpCmVFws0YXbxZzb9O1KmaQHvS1pApFA+O4Qzcm0FYscKpucY/mhT5/uggBeGDroAjYk1PW2DrfwhwoLee6e0PVsx9FmZCTRNKeVtLv1ZqKLStqQ+oD4coa8YU3JqF0t8xD/3ZKevvj1H9mVl6elNq1AopwSlk=;20:P0x/QWxr5OmpUDtHJrvckZDXnrMZUjKKN45Ws44rqZ+XeWc8t6u8kOHQPxZnDroTsoUdHZfG3yDjdG7FEZXLCAbvYfy8zn3hLWWLCetTjlH5sCvY5aw7Qx5v4NaQ0FdNdcp2cwuKsRPJ0AMfXYihsmWkLQuhpo544gzcKth3eRxcOm0vwiuMvuVruQZQiSkYhbiHF2dg39nHLG+m89wFcxN1Q1Oe3Jubsm4F4hQ6VkkEh/qtgiJMdARiaGYPHyYWG+SqJPPOTIKgQzmxf58G5RM2h7Xq9uOHPW0GgFzIUrfdcji+LWlpqvsaI31Z5nhHJLLyCa9a/0uhzMePHL76vpE+aQeXSrVv1+tGYXxgZ6B4DpJy2YeH1ya3MDabuVbeIfyyB2kyaDVBfKdte/qzKLxobN2U2ChGHdGjdfCYHIo6xQcJgFdrS0rj8gVaftf4YSkZ1LGbGzQexxcT1Re64NXCiVYPPIdxxWrbLQBpIbQb64ogePnKFe9s1aylNLJT X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(72806322054110)(185117386973197); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93003095)(3231415)(944501410)(52105112)(10201501046)(3002001)(148016)(149066)(150057)(6041310)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051)(76991095);SRVR:SN1PR0701MB1870;BCL:0;PCL:0;RULEID:;SRVR:SN1PR0701MB1870; X-Microsoft-Exchange-Diagnostics: 1;SN1PR0701MB1870;4:yoaeGGvx8pqfZhEHZz1URzxW+7z0WH+exKiE1kY/RMsO6UJUt3OKk1Zl/nwVMaZZ/bq58BotAUItoBUbrGb2qnO1Hri9Bn0gwiXjNkGoLck0BSfK++bThgn/Duj9f6IIzzq0aTKz47S0u4LGKofRntUbaVndTWphMmYKkdYa7zQp62PAid2+twVFdR1b5SRULV23ex5pZ1Jw/joPwX+lmnNdqNoav+XiBPwQdPj1ZZsdOW56HEIV3okavv6h1WTnIZq22pKr28bNnXO+v3Lw1bBomBf/vElzJtkAWO/B1kyboU/4/Lqeu8gCRCf14WtvVqjVrMkwSWZQNdFFppWJLtf3Vu9bPAr2YUg52NF5YVM= X-Forefront-PRVS: 0860FE717F X-Microsoft-Exchange-Diagnostics: 1;SN1PR0701MB1870;23:Iim2ZTlJCzt/v6VtRkf6fC77++aDaXC6Dd94naOmB0RIGYES9NkWfcVEYaDNgBBJPIEC/Uhr15OgIunmO3Q3YgcdDFyg0u7ki5aWE5UnW3hM/U0y8AqRncDBVTYtbjdft9TUaudN6fxkHWgbJHkRVM2OjychEvYW3OP/V/kta4WTQ3apTkmQm5XyuX39JF9P3LLYXgpV1XgDvTJAEUSAndvXaem4uH2qKVHL3BTQd9pUxdjoow5qIbCoiyH8QMfEAiTEr1FMumJ+5D/8c3BA1Roz6jWy/1yzmXRe3FXFA12tfV35wg3iCYg659bZgRCYikNtgc2n6QD/Rj2ylcOXzYSom8k4UQRimqtTkVj+ALifhzRkecefaLFmIZCA3vCcT9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bZgm8BXDLKC6pY11WsjBjEBsgkfv5HQWCsAd3TtPGjwSAqYvfTQLMaoiimjtBjJXHB7sez3D928AXZ4yEUFZzkskbo5pP+6FgjeITuZFpU8JjnkY53k= X-Microsoft-Exchange-Diagnostics: 1;SN1PR0701MB1870;6:K3+qCxDlqkKnw6Lyjt/h3uUAMqD5day1UJrtAc1fkT/CEr8QFQbQNRWITJqMPunOFR8ZCNoZH0CFw4EHMbGiOCJzdE6G446Y59tkFo1oiCtJgfsuJLfRP/8zlDVCJ8YzssKH3v3S67euGpCbP1MrlBQqQkSAdQ2x60sQtSKYhCZiiuDJrESl5Iz+PPLoGCugNunSrAUovMsjQJgsZEYkd1+qKwJ+rFAMeAButwHAUe1l2YFUY1Fh64ECKoGCVHYUfo5sk5kcwhXbJNhTuy1xPKaPzKgGvPGokuY4pn6ESbYL8UE5JOZjCzVu9DOb8uvAYa83yX2v1iOCJyx+HOqxShDDx94PNcvd8aH5Fh0+xzYB5g7ZWfhK025WVIwOTyrVjpMNgh4gg50NvgY5JiJE4zpXdzSakma8HOC0ke5SS0wkNka9vaXw73vADHlquBFSzbZUEgfE/k4cP/JluS+qag==;5:KgNjIa0IngOLTS6Wm56+c9HmvNhiFm4nZBP9WcaTy7ZtkXLLRL/9Dnp3kctt7chhGYYnknEfvgXGmhbuwPkj+4RDkVrxuJU8W/oNMIzzGymeDutZBerSH8P+IEl4GjrisIjrRNPzb4Pqc+BzNqOw05M7Z18vyFCL58XwhAstFbo=;7:/3FCiOCPYFarPGy+31imNAnHtgo6GgCOnilurATJrWUVe+M4ebyYbrHI2EzEi9DOMet62CLD0H5uutYGgQTY7L4J/vod5r0gdWAypp5QujMzUyy5dw79tClwt+TFv8fpTFxihp9hkjjwnjuQWdcHjg== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;SN1PR0701MB1870;20:lY3tEl/pdURczK7wTOtXxEEh+0XOqQS8kDW+Z93qTH7FvwWO67KUb0DuCWuYnJUbR3dn5KuMdOJK7VlIHyk6L1jY6omPZ7lfwXVl6rs+wMkWYOfd9h6TiunXxkXAZQJIaKk4UOcS+e7g1h/R5HfWcHYwPZUSEHR9Z6DLF6c9kXBMVH0kbjIFy4+Lmd8Ymgf0FIwFAU5yp5Q6Jadw100a4SBSs0tYCysP+BuqKJ1DgzwuBP8MfJ3wQXZtxMnI6QJP X-OriginatorOrg: cadence.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2018 10:10:46.4757 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ed79e2ba-3de0-4c21-e49b-08d64d3e1be0 X-MS-Exchange-CrossTenant-Id: d36035c5-6ce6-4662-a3dc-e762e61ae4c9 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=d36035c5-6ce6-4662-a3dc-e762e61ae4c9;Ip=[158.140.1.28];Helo=[sjmaillnx2.cadence.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR0701MB1870 X-Proofpoint-SPF-Result: pass X-Proofpoint-SPF-Record: v=spf1 a:mx-sanjose2.Cadence.COM a:mx-sanjose4.Cadence.COM a:mx-sanjose5.Cadence.COM include:mktomail.com include:spf-0014ca01.pphosted.com include:spf.protection.outlook.com include:auth.msgapp.com include:spf.mandrillapp.com ~all X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-11-18_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_check_notspam policy=outbound_check score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811180097 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Patch implements a set of function related to enumeration process. Some standard requests are handled on controller driver level and other are delegated to gadget core driver. All class requests are delegated to gadget core driver. Signed-off-by: Pawel Laszczak --- drivers/usb/cdns3/ep0.c | 491 ++++++++++++++++++++++++++++++++++++- drivers/usb/cdns3/gadget.c | 119 +++++++++ drivers/usb/cdns3/gadget.h | 4 + 3 files changed, 610 insertions(+), 4 deletions(-) diff --git a/drivers/usb/cdns3/ep0.c b/drivers/usb/cdns3/ep0.c index eb92fd234bd7..6f33d98f7684 100644 --- a/drivers/usb/cdns3/ep0.c +++ b/drivers/usb/cdns3/ep0.c @@ -10,6 +10,7 @@ * Peter Chen */ +#include #include "gadget.h" static struct usb_endpoint_descriptor cdns3_gadget_ep0_desc = { @@ -52,9 +53,31 @@ static void cdns3_ep0_run_transfer(struct cdns3_device *priv_dev, writel(EP_CMD_ERDY, &priv_dev->regs->ep_cmd); } +/** + * cdns3_ep0_delegate_req - Returns status of handling setup packet + * Setup is handled by gadget driver + * @priv_dev: extended gadget object + * @ctrl_req: pointer to received setup packet + * + * Returns zero on success or negative value on failure + */ +static int cdns3_ep0_delegate_req(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl_req) +{ + int ret; + + spin_unlock(&priv_dev->lock); + priv_dev->setup_pending = 1; + ret = priv_dev->gadget_driver->setup(&priv_dev->gadget, ctrl_req); + priv_dev->setup_pending = 0; + spin_lock(&priv_dev->lock); + return ret; +} + static void cdns3_prepare_setup_packet(struct cdns3_device *priv_dev) { - //TODO: Implements this function + priv_dev->ep0_data_dir = 0; + cdns3_ep0_run_transfer(priv_dev, priv_dev->setup_dma, 8, 0); } static void cdns3_set_hw_configuration(struct cdns3_device *priv_dev) @@ -90,9 +113,431 @@ static void cdns3_set_hw_configuration(struct cdns3_device *priv_dev) } } +/** + * cdns3_req_ep0_set_configuration - Handling of SET_CONFIG standard USB request + * @priv_dev: extended gadget object + * @ctrl_req: pointer to received setup packet + * + * Returns 0 if success, 0x7FFF on deferred status stage, error code on error + */ +static int cdns3_req_ep0_set_configuration(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl_req) +{ + enum usb_device_state device_state = priv_dev->gadget.state; + struct cdns3_endpoint *priv_ep, *temp_ep; + u32 config = le16_to_cpu(ctrl_req->wValue); + int result = 0; + + switch (device_state) { + case USB_STATE_ADDRESS: + /* Configure non-control EPs */ + list_for_each_entry_safe(priv_ep, temp_ep, + &priv_dev->ep_match_list, + ep_match_pending_list) + cdns3_ep_config(priv_ep); + + result = cdns3_ep0_delegate_req(priv_dev, ctrl_req); + + if (result) + return result; + + if (config) { + cdns3_set_hw_configuration(priv_dev); + } else { + cdns3_gadget_unconfig(priv_dev); + usb_gadget_set_state(&priv_dev->gadget, + USB_STATE_ADDRESS); + } + break; + case USB_STATE_CONFIGURED: + result = cdns3_ep0_delegate_req(priv_dev, ctrl_req); + + if (!config && !result) { + cdns3_gadget_unconfig(priv_dev); + usb_gadget_set_state(&priv_dev->gadget, + USB_STATE_ADDRESS); + } + break; + default: + result = -EINVAL; + } + + return result; +} + +/** + * cdns3_req_ep0_set_address - Handling of SET_ADDRESS standard USB request + * @priv_dev: extended gadget object + * @ctrl_req: pointer to received setup packet + * + * Returns 0 if success, error code on error + */ +static int cdns3_req_ep0_set_address(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl_req) +{ + enum usb_device_state device_state = priv_dev->gadget.state; + u32 reg; + u32 addr; + + addr = le16_to_cpu(ctrl_req->wValue); + + if (addr > DEVICE_ADDRESS_MAX) { + dev_err(&priv_dev->dev, + "Device address (%d) cannot be greater than %d\n", + addr, DEVICE_ADDRESS_MAX); + return -EINVAL; + } + + if (device_state == USB_STATE_CONFIGURED) { + dev_err(&priv_dev->dev, "USB device already configured\n"); + return -EINVAL; + } + + reg = readl(&priv_dev->regs->usb_cmd); + + writel(reg | USB_CMD_FADDR(addr) | USB_CMD_SET_ADDR, + &priv_dev->regs->usb_cmd); + + usb_gadget_set_state(&priv_dev->gadget, + (addr ? USB_STATE_ADDRESS : USB_STATE_DEFAULT)); + + cdns3_prepare_setup_packet(priv_dev); + + writel(EP_CMD_ERDY | EP_CMD_REQ_CMPL, &priv_dev->regs->ep_cmd); + + return 0; +} + +/** + * cdns3_req_ep0_get_status - Handling of GET_STATUS standard USB request + * @priv_dev: extended gadget object + * @ctrl_req: pointer to received setup packet + * + * Returns 0 if success, error code on error + */ +static int cdns3_req_ep0_get_status(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl) +{ + __le16 *response_pkt; + u16 usb_status = 0; + u32 recip; + u32 reg; + + recip = ctrl->bRequestType & USB_RECIP_MASK; + + switch (recip) { + case USB_RECIP_DEVICE: + /* self powered */ + usb_status |= priv_dev->gadget.is_selfpowered; + + if (priv_dev->gadget.speed != USB_SPEED_SUPER) + break; + + reg = readl(&priv_dev->regs->usb_sts); + + if (priv_dev->u1_allowed) + usb_status |= BIT(USB_DEV_STAT_U1_ENABLED); + + if (priv_dev->u2_allowed) + usb_status |= BIT(USB_DEV_STAT_U2_ENABLED); + + if (priv_dev->wake_up_flag) + usb_status |= BIT(USB_DEVICE_REMOTE_WAKEUP); + break; + case USB_RECIP_INTERFACE: + return cdns3_ep0_delegate_req(priv_dev, ctrl); + case USB_RECIP_ENDPOINT: + /* check if endpoint is stalled */ + cdns3_select_ep(priv_dev, ctrl->wIndex); + if (EP_STS_STALL(readl(&priv_dev->regs->ep_sts))) + usb_status = BIT(USB_ENDPOINT_HALT); + break; + default: + return -EINVAL; + } + + response_pkt = (__le16 *)priv_dev->setup; + *response_pkt = cpu_to_le16(usb_status); + + cdns3_ep0_run_transfer(priv_dev, priv_dev->setup_dma, + sizeof(*response_pkt), 1); + return 0; +} + +static int cdns3_ep0_feature_handle_device(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl, + int set) +{ + enum usb_device_state state; + enum usb_device_speed speed; + int ret = 0; + u32 wValue; + u32 wIndex; + u16 tmode; + + wValue = le16_to_cpu(ctrl->wValue); + wIndex = le16_to_cpu(ctrl->wIndex); + state = priv_dev->gadget.state; + speed = priv_dev->gadget.speed; + + switch (ctrl->wValue) { + case USB_DEVICE_REMOTE_WAKEUP: + priv_dev->wake_up_flag = !!set; + break; + case USB_DEVICE_U1_ENABLE: + if (state != USB_STATE_CONFIGURED || speed != USB_SPEED_SUPER) + return -EINVAL; + + priv_dev->u1_allowed = !!set; + break; + case USB_DEVICE_U2_ENABLE: + if (state != USB_STATE_CONFIGURED || speed != USB_SPEED_SUPER) + return -EINVAL; + + priv_dev->u2_allowed = !!set; + break; + case USB_DEVICE_LTM_ENABLE: + ret = -EINVAL; + break; + case USB_DEVICE_TEST_MODE: + if (state != USB_STATE_CONFIGURED || speed > USB_SPEED_HIGH) + return -EINVAL; + + tmode = le16_to_cpu(ctrl->wIndex); + + if (!set || (tmode & 0xff) != 0) + return -EINVAL; + + switch (tmode >> 8) { + case TEST_J: + case TEST_K: + case TEST_SE0_NAK: + case TEST_PACKET: + cdns3_set_register_bit(&priv_dev->regs->usb_cmd, + USB_CMD_STMODE | + USB_STS_TMODE_SEL(tmode - 1)); + break; + default: + ret = -EINVAL; + } + break; + default: + ret = -EINVAL; + } + + return ret; +} + +static int cdns3_ep0_feature_handle_intf(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl, + int set) +{ + u32 wValue; + int ret = 0; + + wValue = le16_to_cpu(ctrl->wValue); + + switch (wValue) { + case USB_INTRF_FUNC_SUSPEND: + break; + default: + ret = -EINVAL; + } + + return ret; +} + +static int cdns3_ep0_feature_handle_endpoint(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl, + int set) +{ + struct cdns3_endpoint *priv_ep; + int ret = 0; + u8 index; + + if (!(ctrl->wIndex & ~USB_DIR_IN)) + return 0; + + index = cdns3_ep_addr_to_index(ctrl->wIndex); + priv_ep = priv_dev->eps[index]; + + cdns3_select_ep(priv_dev, ctrl->wIndex); + + if (le16_to_cpu(ctrl->wValue) != USB_ENDPOINT_HALT) + return -EINVAL; + + if (set) { + writel(EP_CMD_SSTALL, &priv_dev->regs->ep_cmd); + priv_ep->flags |= EP_STALL; + } else { + struct usb_request *request; + + if (priv_dev->eps[index]->flags & EP_WEDGE) { + cdns3_select_ep(priv_dev, 0x00); + return 0; + } + + writel(EP_CMD_CSTALL | EP_CMD_EPRST, &priv_dev->regs->ep_cmd); + + /* wait for EPRST cleared */ + ret = cdns3_handshake(&priv_dev->regs->ep_cmd, + EP_CMD_EPRST, 0, 100); + if (ret) + return -EINVAL; + + priv_ep->flags &= ~EP_STALL; + + request = cdns3_next_request(&priv_ep->request_list); + if (request) + cdns3_ep_run_transfer(priv_ep, request); + } + return ret; +} + +/** + * cdns3_req_ep0_handle_feature - + * Handling of GET/SET_FEATURE standard USB request + * + * @priv_dev: extended gadget object + * @ctrl_req: pointer to received setup packet + * @set: must be set to 1 for SET_FEATURE request + * + * Returns 0 if success, error code on error + */ +static int cdns3_req_ep0_handle_feature(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl, + int set) +{ + int ret = 0; + u32 recip; + + recip = ctrl->bRequestType & USB_RECIP_MASK; + + switch (recip) { + case USB_RECIP_DEVICE: + ret = cdns3_ep0_feature_handle_device(priv_dev, ctrl, set); + break; + case USB_RECIP_INTERFACE: + ret = cdns3_ep0_feature_handle_intf(priv_dev, ctrl, set); + break; + case USB_RECIP_ENDPOINT: + ret = cdns3_ep0_feature_handle_endpoint(priv_dev, ctrl, set); + break; + default: + return -EINVAL; + } + + if (!ret) + writel(EP_CMD_ERDY | EP_CMD_REQ_CMPL, &priv_dev->regs->ep_cmd); + + return ret; +} + +/** + * cdns3_req_ep0_set_sel - Handling of SET_SEL standard USB request + * @priv_dev: extended gadget object + * @ctrl_req: pointer to received setup packet + * + * Returns 0 if success, error code on error + */ +static int cdns3_req_ep0_set_sel(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl_req) +{ + if (priv_dev->gadget.state < USB_STATE_ADDRESS) + return -EINVAL; + + if (ctrl_req->wLength != 6) { + dev_err(&priv_dev->dev, "Set SEL should be 6 bytes, got %d\n", + ctrl_req->wLength); + return -EINVAL; + } + + priv_dev->ep0_data_dir = 0; + cdns3_ep0_run_transfer(priv_dev, priv_dev->setup_dma, 6, 1); + return 0; +} + +/** + * cdns3_req_ep0_set_isoch_delay - + * Handling of GET_ISOCH_DELAY standard USB request + * @priv_dev: extended gadget object + * @ctrl_req: pointer to received setup packet + * + * Returns 0 if success, error code on error + */ +static int cdns3_req_ep0_set_isoch_delay(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl_req) +{ + if (ctrl_req->wIndex || ctrl_req->wLength) + return -EINVAL; + + priv_dev->isoch_delay = ctrl_req->wValue; + writel(EP_CMD_ERDY | EP_CMD_REQ_CMPL, &priv_dev->regs->ep_cmd); + return 0; +} + +/** + * cdns3_ep0_standard_request - Handling standard USB requests + * @priv_dev: extended gadget object + * @ctrl_req: pointer to received setup packet + * + * Returns 0 if success, error code on error + */ +static int cdns3_ep0_standard_request(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl_req) +{ + int ret; + + switch (ctrl_req->bRequest) { + case USB_REQ_SET_ADDRESS: + ret = cdns3_req_ep0_set_address(priv_dev, ctrl_req); + break; + case USB_REQ_SET_CONFIGURATION: + ret = cdns3_req_ep0_set_configuration(priv_dev, ctrl_req); + break; + case USB_REQ_GET_STATUS: + ret = cdns3_req_ep0_get_status(priv_dev, ctrl_req); + break; + case USB_REQ_CLEAR_FEATURE: + ret = cdns3_req_ep0_handle_feature(priv_dev, ctrl_req, 0); + break; + case USB_REQ_SET_FEATURE: + ret = cdns3_req_ep0_handle_feature(priv_dev, ctrl_req, 1); + break; + case USB_REQ_SET_SEL: + ret = cdns3_req_ep0_set_sel(priv_dev, ctrl_req); + break; + case USB_REQ_SET_ISOCH_DELAY: + ret = cdns3_req_ep0_set_isoch_delay(priv_dev, ctrl_req); + break; + default: + ret = cdns3_ep0_delegate_req(priv_dev, ctrl_req); + break; + } + + return ret; +} + static void __pending_setup_status_handler(struct cdns3_device *priv_dev) { - //TODO: Implements this function + struct usb_request *request = priv_dev->pending_status_request; + + if (priv_dev->status_completion_no_call && request && + request->complete) { + request->complete(priv_dev->gadget.ep0, request); + priv_dev->status_completion_no_call = 0; + } +} + +void cdns3_pending_setup_status_handler(struct work_struct *work) +{ + struct cdns3_device *priv_dev = container_of(work, struct cdns3_device, + pending_status_wq); + unsigned long flags; + + spin_lock_irqsave(&priv_dev->lock, flags); + __pending_setup_status_handler(priv_dev); + spin_unlock_irqrestore(&priv_dev->lock, flags); } /** @@ -101,12 +546,50 @@ static void __pending_setup_status_handler(struct cdns3_device *priv_dev) */ static void cdns3_ep0_setup_phase(struct cdns3_device *priv_dev) { - //TODO: Implements this function. + struct usb_ctrlrequest *ctrl = priv_dev->setup; + int result; + + if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) + result = cdns3_ep0_standard_request(priv_dev, ctrl); + else + result = cdns3_ep0_delegate_req(priv_dev, ctrl); + + if (result != 0 && result != USB_GADGET_DELAYED_STATUS) { + dev_dbg(&priv_dev->dev, "STALL for ep0\n"); + /* set_stall on ep0 */ + cdns3_select_ep(priv_dev, 0x00); + writel(EP_CMD_SSTALL, &priv_dev->regs->ep_cmd); + writel(EP_CMD_ERDY | EP_CMD_REQ_CMPL, &priv_dev->regs->ep_cmd); + } } static void cdns3_transfer_completed(struct cdns3_device *priv_dev) { - //TODO: Implements this function + if (priv_dev->ep0_request) { + usb_gadget_unmap_request_by_dev(priv_dev->sysdev, + priv_dev->ep0_request, + priv_dev->ep0_data_dir); + + priv_dev->ep0_request->actual = + TRB_LEN(le32_to_cpu(priv_dev->trb_ep0->length)); + + dev_dbg(&priv_dev->dev, "Ep0 completion length %d\n", + priv_dev->ep0_request->actual); + list_del_init(&priv_dev->ep0_request->list); + } + + if (priv_dev->ep0_request && + priv_dev->ep0_request->complete) { + spin_unlock(&priv_dev->lock); + priv_dev->ep0_request->complete(priv_dev->gadget.ep0, + priv_dev->ep0_request); + + priv_dev->ep0_request = NULL; + spin_lock(&priv_dev->lock); + } + + cdns3_prepare_setup_packet(priv_dev); + writel(EP_CMD_REQ_CMPL, &priv_dev->regs->ep_cmd); } /** diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c index 309202474e57..0202ff5f6c90 100644 --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/gadget.c @@ -70,6 +70,30 @@ static u8 cdns3_ep_reg_pos_to_index(int i) return ((i / 16) + (((i % 16) - 2) * 2)); } +/** + * cdns3_ep_addr_to_index - Macro converts endpoint address to + * index of endpoint object in cdns3_device.eps[] container + * @ep_addr: endpoint address for which endpoint object is required + * + * Remember that endpoint container doesn't contain default endpoint + */ +u8 cdns3_ep_addr_to_index(u8 ep_addr) +{ + return (((ep_addr & 0x7F) - 1) + ((ep_addr & USB_DIR_IN) ? 1 : 0)); +} + +/** + * cdns3_ep_addr_to_bit_pos - Macro converts endpoint address to + * bit position in ep_ists register + * @ep_addr: endpoint address for which bit position is required + * + * Remember that endpoint container doesn't contain default endpoint + */ +static u32 cdns3_ep_addr_to_bit_pos(u8 ep_addr) +{ + return (1 << (ep_addr & 0x7F)) << ((ep_addr & 0x80) ? 16 : 0); +} + /** * cdns3_next_request - returns next request from list * @list: list containing requests @@ -464,6 +488,99 @@ static irqreturn_t cdns3_irq_handler_thread(struct cdns3 *cdns) return ret; } +/** + * cdns3_ep_onchip_buffer_alloc - Try to allocate onchip buf for EP + * + * The real allocation will occur during write to EP_CFG register, + * this function is used to check if the 'size' allocation is allowed. + * + * @priv_dev: extended gadget object + * @size: the size (KB) for EP would like to allocate + * @is_in: the direction for EP + * + * Return 0 if the later allocation is allowed or negative value on failure + */ +static int cdns3_ep_onchip_buffer_alloc(struct cdns3_device *priv_dev, + int size, int is_in) +{ + if (is_in) { + priv_dev->onchip_mem_allocated_size += size; + } else if (!priv_dev->out_mem_is_allocated) { + /* ALL OUT EPs are shared the same chunk onchip memory */ + priv_dev->onchip_mem_allocated_size += size; + priv_dev->out_mem_is_allocated = 1; + } + + if (priv_dev->onchip_mem_allocated_size > CDNS3_ONCHIP_BUF_SIZE) { + priv_dev->onchip_mem_allocated_size -= size; + return -EPERM; + } else { + return 0; + } +} + +/** + * cdns3_ep_config Configure hardware endpoint + * @priv_ep: extended endpoint object + */ +void cdns3_ep_config(struct cdns3_endpoint *priv_ep) +{ + bool is_iso_ep = (priv_ep->type == USB_ENDPOINT_XFER_ISOC); + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + u32 bEndpointAddress = priv_ep->num | priv_ep->dir; + u32 interrupt_mask = EP_STS_EN_TRBERREN; + u32 max_packet_size = 0; + u32 ep_cfg = 0; + int ret; + + if (priv_ep->type == USB_ENDPOINT_XFER_INT) { + ep_cfg = EP_CFG_EPTYPE(USB_ENDPOINT_XFER_INT); + } else if (priv_ep->type == USB_ENDPOINT_XFER_BULK) { + ep_cfg = EP_CFG_EPTYPE(USB_ENDPOINT_XFER_BULK); + } else { + ep_cfg = EP_CFG_EPTYPE(USB_ENDPOINT_XFER_ISOC); + interrupt_mask = 0xFFFFFFFF; + } + + switch (priv_dev->gadget.speed) { + case USB_SPEED_FULL: + max_packet_size = is_iso_ep ? 1023 : 64; + break; + case USB_SPEED_HIGH: + max_packet_size = is_iso_ep ? 1024 : 512; + break; + case USB_SPEED_SUPER: + max_packet_size = 1024; + break; + default: + //all other speed are not supported + return; + } + + ret = cdns3_ep_onchip_buffer_alloc(priv_dev, CDNS3_EP_BUF_SIZE, + priv_ep->dir); + if (ret) { + dev_err(&priv_dev->dev, "onchip mem is full, ep is invalid\n"); + return; + } + + ep_cfg |= EP_CFG_MAXPKTSIZE(max_packet_size) | + EP_CFG_BUFFERING(CDNS3_EP_BUF_SIZE - 1) | + EP_CFG_MAXBURST(priv_ep->endpoint.maxburst); + + cdns3_select_ep(priv_dev, bEndpointAddress); + + writel(ep_cfg, &priv_dev->regs->ep_cfg); + writel(interrupt_mask, &priv_dev->regs->ep_sts_en); + + dev_dbg(&priv_dev->dev, "Configure %s: with val %08x\n", + priv_ep->name, ep_cfg); + + /* enable interrupt for selected endpoint */ + cdns3_set_register_bit(&priv_dev->regs->ep_ien, + cdns3_ep_addr_to_bit_pos(bEndpointAddress)); +} + /* Find correct direction for HW endpoint according to description */ static int cdns3_ep_dir_is_correct(struct usb_endpoint_descriptor *desc, struct cdns3_endpoint *priv_ep) @@ -1104,6 +1221,8 @@ static int __cdns3_gadget_init(struct cdns3 *cdns) priv_dev->is_connected = 0; spin_lock_init(&priv_dev->lock); + INIT_WORK(&priv_dev->pending_status_wq, + cdns3_pending_setup_status_handler); priv_dev->in_standby_mode = 1; diff --git a/drivers/usb/cdns3/gadget.h b/drivers/usb/cdns3/gadget.h index 8c2f363f9340..db8c6cb9f2a5 100644 --- a/drivers/usb/cdns3/gadget.h +++ b/drivers/usb/cdns3/gadget.h @@ -1070,14 +1070,18 @@ struct cdns3_device { int cdns3_handshake(void __iomem *ptr, u32 mask, u32 done, int usec); void cdns3_set_register_bit(void __iomem *ptr, u32 mask); +void cdns3_pending_setup_status_handler(struct work_struct *work); int cdns3_init_ep0(struct cdns3_device *priv_dev); void cdns3_ep0_config(struct cdns3_device *priv_dev); +void cdns3_ep_config(struct cdns3_endpoint *priv_ep); void cdns3_check_ep0_interrupt_proceed(struct cdns3_device *priv_dev, int dir); void cdns3_select_ep(struct cdns3_device *priv_dev, u32 ep); void cdns3_enable_l1(struct cdns3_device *priv_dev, int enable); struct usb_request *cdns3_next_request(struct list_head *list); +void cdns3_gadget_unconfig(struct cdns3_device *priv_dev); int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, struct usb_request *request); +u8 cdns3_ep_addr_to_index(u8 ep_addr); int cdns3_gadget_ep_set_wedge(struct usb_ep *ep); int cdns3_gadget_ep_set_halt(struct usb_ep *ep, int value); struct usb_request *cdns3_gadget_ep_alloc_request(struct usb_ep *ep, From patchwork Sun Nov 18 10:09:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Laszczak X-Patchwork-Id: 10687719 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BF30113BB for ; Sun, 18 Nov 2018 10:11:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD94529D31 for ; Sun, 18 Nov 2018 10:11:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A132929D3E; Sun, 18 Nov 2018 10:11:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D0DCD29D31 for ; Sun, 18 Nov 2018 10:11:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727337AbeKRUa7 (ORCPT ); Sun, 18 Nov 2018 15:30:59 -0500 Received: from mx0a-0014ca01.pphosted.com ([208.84.65.235]:36382 "EHLO mx0a-0014ca01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726180AbeKRUa7 (ORCPT ); Sun, 18 Nov 2018 15:30:59 -0500 Received: from pps.filterd (m0042385.ppops.net [127.0.0.1]) by mx0a-0014ca01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id wAIA6XnX016036; Sun, 18 Nov 2018 02:10:53 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=proofpoint; bh=RbBYnu6XCdppM5JOAT28tKGA2sIdM637Iqwktx/Z0vQ=; b=MJiFmmPb7WhP/ksWeb0f6iQGuAjRnntkWyFALmlhS3z5aYv7Bq7sZWekjunIFfzBlC4Y Om+oFlMPEqLc4VI9o2qJ5kh9uWWcqgNKtVhnZs+lzG4NEfKSroJAgvr6mXAq2GU4CO/Q Bd7AIngbxFG6uUydTU7WzxPWdrzaka8dM7DTgS8acIVVLcFiFYFDo6yYbZRFb/UhyY0J XCbZdCUpcP9JT3qPhuxp19911u9aTbye+zbKgmeqyPVOOb8WpMOXehGzi7Fgn53bMEJ9 jTD0BuUFrlR8ZHeByIRGdb5wmDfOFs6mWp2ILOScFQFwLunzOPOslurLA5oEHEz1erfN yQ== Authentication-Results: cadence.com; spf=pass smtp.mailfrom=pawell@cadence.com Received: from nam01-by2-obe.outbound.protection.outlook.com (mail-by2nam01lp0175.outbound.protection.outlook.com [216.32.181.175]) by mx0a-0014ca01.pphosted.com with ESMTP id 2ntge14vgk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sun, 18 Nov 2018 02:10:53 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RbBYnu6XCdppM5JOAT28tKGA2sIdM637Iqwktx/Z0vQ=; b=hcSoD4s8lPKpDQbhfqn5lNaDxGhmm+kojG4pHb8+d/AZrJI7dNahPCSS09AOGKEGrXrGqLC/j3OxyEevsJvP0DZjusMGyrg5WNsG++2HZC6yVR1rv3Cy+bE9TL2RLXih1cLr0v02Em7d54hkQrLrPIBbbG5Zm+mTA2U3a4h6eqU= Received: from DM5PR07CA0079.namprd07.prod.outlook.com (2603:10b6:4:ad::44) by BYAPR07MB5175.namprd07.prod.outlook.com (2603:10b6:a03:6d::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.26; Sun, 18 Nov 2018 10:10:51 +0000 Received: from CO1NAM05FT011.eop-nam05.prod.protection.outlook.com (2a01:111:f400:7e50::207) by DM5PR07CA0079.outlook.office365.com (2603:10b6:4:ad::44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.20 via Frontend Transport; Sun, 18 Nov 2018 10:10:51 +0000 Received-SPF: SoftFail (protection.outlook.com: domain of transitioning cadence.com discourages use of 158.140.1.28 as permitted sender) Received: from sjmaillnx2.cadence.com (158.140.1.28) by CO1NAM05FT011.mail.protection.outlook.com (10.152.96.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.3 via Frontend Transport; Sun, 18 Nov 2018 10:10:47 +0000 Received: from maileu3.global.cadence.com (maileu3.cadence.com [10.160.88.99]) by sjmaillnx2.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAb5V029622 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Sun, 18 Nov 2018 02:10:46 -0800 X-CrossPremisesHeadersFilteredBySendConnector: maileu3.global.cadence.com Received: from maileu3.global.cadence.com (10.160.88.99) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Sun, 18 Nov 2018 11:10:44 +0100 Received: from lvlogina.cadence.com (10.165.176.102) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Sun, 18 Nov 2018 11:10:44 +0100 Received: from lvlogina.cadence.com (localhost.localdomain [127.0.0.1]) by lvlogina.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAeEe032339; Sun, 18 Nov 2018 10:10:40 GMT Received: (from pawell@localhost) by lvlogina.cadence.com (8.14.4/8.14.4/Submit) id wAIAAenF032301; Sun, 18 Nov 2018 10:10:40 GMT From: Pawel Laszczak To: CC: , , , , , , , , , , , , "Pawel Laszczak" Subject: [RFC PATCH v2 13/15] usb:cdns3: Adds transfer related function. Date: Sun, 18 Nov 2018 10:09:09 +0000 Message-ID: <1542535751-16079-14-git-send-email-pawell@cadence.com> X-Mailer: git-send-email 1.7.11.2 In-Reply-To: <1542535751-16079-1-git-send-email-pawell@cadence.com> References: <1542535751-16079-1-git-send-email-pawell@cadence.com> MIME-Version: 1.0 X-OrganizationHeadersPreserved: maileu3.global.cadence.com X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:158.140.1.28;IPV:CAL;SCL:-1;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(396003)(136003)(376002)(39860400002)(346002)(2980300002)(199004)(189003)(36092001)(4326008)(106466001)(217873002)(2351001)(14444005)(356004)(16586007)(4720700003)(36756003)(105596002)(42186006)(6916009)(86362001)(47776003)(6666004)(316002)(54906003)(11346002)(2616005)(126002)(446003)(476003)(486006)(76176011)(336012)(26005)(426003)(186003)(107886003)(2906002)(48376002)(50466002)(305945005)(246002)(7636002)(87636003)(26826003)(478600001)(5660300001)(8936002)(8676002)(50226002)(51416003);DIR:OUT;SFP:1101;SCL:1;SRVR:BYAPR07MB5175;H:sjmaillnx2.cadence.com;FPR:;SPF:SoftFail;LANG:en;PTR:corp.cadence.com;A:1;MX:1; X-Microsoft-Exchange-Diagnostics: 1;CO1NAM05FT011;1:sjTvcmcxvf1mx1D/e0pTogGhsD6p6Us/RtqkkaTcTAuxvTQzYohWf1wxLCJb7bS4uXm+e9Upbflphu5b4OjnLT0/7Lq2T7uxPrn3KBSsIYxqMj6p2/bXANJ5JdjVGdBi X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5b538636-8c49-4088-9f9a-08d64d3e1e12 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060);SRVR:BYAPR07MB5175; X-Microsoft-Exchange-Diagnostics: 1;BYAPR07MB5175;3:J4mirXqvdv0FlrjkctBBy+TScLl+UA4d+n3LyvIsUALHLGqrgkhdGmxqw6SGn3tahs6o9u/CZMdgd4wst7YOqhKKVwyGvM7WQWzgbRGfqPSPNAosx0NIyHEpOBfNuCcIrj/B0ylNpUTR6+Hqmy0kWxGkbD0PDdCzQ+sxxIAMPB6UlPSN1DdUCq40RDsQyFzeWIfxG4u1C/QcFY/agzIS3pIfyEhY4h7g7/OhWiHiV6bLJ1QYLSzqCEeuly+QXndDj1zndSOWb+KjRua3jQEGexnflOuXBAomNxs43+z91iUu39ke6u1SezojFcRiF/j8evouLYX6+QhI3BYyEYp23cM1K24ZXnVQMFvaHOPdR14=;25:vrkiEoVa4KwJei0DzrQHpX6AAYqRlQ47W+XCYuCEV113Ce5pcO1dtLVqomx6Ema+trlbI2SO0rcz/7Q59wmtpX9G72/mOxF2Atvcuv4WjkKBaPfMJJfopApTi87/9zaO+eJyEelH+boZYbfsBBZiTeCHzeJl2HumtQtydvVGmbS/Phf+dmnnircFL7t3HJ+Aay415JKDsipiSJWwoEC5QWmWMIdE2kTVS8n+OOwTgeW5HwHybRBJPchVZZ8LOxw8EZTbpCPRzjeE8XVWYCG+f514xNts8Dgupr4DccoCuaXQrRlF+Vt6hEWLOp2+LWi9ZfWd+ljMmbD6kGSoRaZmkA== X-MS-TrafficTypeDiagnostic: BYAPR07MB5175: X-Microsoft-Exchange-Diagnostics: 1;BYAPR07MB5175;31:mvNxnld+QBpJxu3wlgG3pkRlGObWTZ2tebz7zyIFOYLE2zfuJfIS63Jv/S+3g+kK3AqHSEwzFEU8rxnLolW8QrH28tMYmT6wV8iSW4Lrgou9XRtcAPk3fy4ZADCu7oH5WNed98kDM1geJgciT44Gp6brPP54SOQOeeZqvDbRyjse9PCCBJ0G+ocBh/2N2UCLfBcQD0zWCM0+yodbNLjp4jXKaO073t0YBAamnQMY9Vs=;20:8UZ4qRPKAfxM4kcZVKxVddhYpLF2MtX5uMx8RDElRj5tQBsWx+MuOwnhAEhst6Q1H8WXpTUCM9KRtenXx2b9cBL6xC/cbWSfnpwQBWNZBb2M9AvaYb6sbwNsneTLjykZQJXCv7tmna64ZqksIOE7KIPx7i1CQpV9oyZRpyO1LCYtZjGdSYnZG2vqM3fXI+sDIDZhzjT1Y4fbXv1kcQkkvROZs+UMhCVyE7fQZ7aKwD2voWYiE3oeSi8gCM/E8dB95XGeXRstnKFjdfIrubksew6BwimX4Nj7aASf6iO/giWAJ7u0B5b7U8/OeFhVGHT2DLa6pOMME7Zok+bYhmLuzMNINNZRTbtdEzHEASM/jH8ijuR9r9FFMB/9Sp+Lmy4ptWvB4ZdqqXCcKno5SbmiMkCVUHIjLu1wxWL9qkJThzmTCgHyVYP1ITKyhery/ODcCXjo0Wqi8tYPZTA4ofHYNZ5v3kmeTW7acc3kLRVQq4tysFDqAqIyJmxgEGltpYjS X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3002001)(10201501046)(93006095)(93003095)(3231415)(944501410)(52105112)(148016)(149066)(150057)(6041310)(20161123564045)(20161123562045)(20161123560045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051)(76991095);SRVR:BYAPR07MB5175;BCL:0;PCL:0;RULEID:;SRVR:BYAPR07MB5175; X-Microsoft-Exchange-Diagnostics: 1;BYAPR07MB5175;4:HVXWtZqSkom0WPrwsjALegriLB0nHFFMwC9aNPqO/TX3dBsfF9XRyYs7OidGtHtY0u/WQMLHmd2laCh5y84W3Jv2IRg1ubDX13niEuLEyVe5dCJX1n+RNKC3itxprYZG24Gk+YO0mMy81+AvBJjjmUFiKw0vQ6lD8ZoJidnKeK6BjWtSgSHKdCxrsCp4QLtmnQvN5ZKm7uP9qo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gdK5Ycqdeb1uEZQGjI4KBRE6Kmw==;5:5HQtmkl2cDsr8uD0x3nntip7swTh9GBTlFOh8ee/3Fzj/3hee8jGCLuUZ1DgRaQaPCYhZwJSM3uhgCX1xgT9sKez1f0vcdseYEtvIAz002CZUeXO3Ip015jb/T7XOsYt8Av+tYhhXOFf5AdQGSXKrSbdPAlUW5+UEWhiDKFAHg4=;7:ZZjZhLXqvCuRNd3yL2p6dENGBVXvFAi9TqCcMkRd8ln91Ui4Y77dUkplYDVLQ2FdoXPt5j8gm3QumR2TZpA3E7dycKp7TZjIgPr1Xd9hw6js7S7WEF3H2e4xEyMXckj1iKkFKpR8q1SyLKg1pliVKw== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BYAPR07MB5175;20:d/JqL4zTuF3NfqPOhc8DPB/PVOGc2mLJk6mdB3InRkYMM/Z0sCKjga0gAvn1d5Z+oG2/yTyGlGHmRR7WzrCkRZiZllC6Vk4ZGQLCEC1sWqA6OoYsF9AA9CVRZFLlxRJ4upiYxO9PgEATYMs3VkskWcFTrxlTdlQKUxfjgkaqucdiU28C8OdpBS8zMni3KYYklR4DghYgcn0hszlYUqWBv4JMnmC9RSepFTYPmk/fRQrXl/tx+6uCwww1YjdWS3f2 X-OriginatorOrg: cadence.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2018 10:10:47.0632 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5b538636-8c49-4088-9f9a-08d64d3e1e12 X-MS-Exchange-CrossTenant-Id: d36035c5-6ce6-4662-a3dc-e762e61ae4c9 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=d36035c5-6ce6-4662-a3dc-e762e61ae4c9;Ip=[158.140.1.28];Helo=[sjmaillnx2.cadence.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR07MB5175 X-Proofpoint-SPF-Result: pass X-Proofpoint-SPF-Record: v=spf1 a:mx-sanjose2.Cadence.COM a:mx-sanjose4.Cadence.COM a:mx-sanjose5.Cadence.COM include:mktomail.com include:spf-0014ca01.pphosted.com include:spf.protection.outlook.com include:auth.msgapp.com include:spf.mandrillapp.com ~all X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-11-18_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_check_notspam policy=outbound_check score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=759 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811180096 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Patch implements a set of function handling transfer on none-default endpoints. For handling transfer controller use cdns3_trb structure. Each transfer request block (TRB) contains data buffer address, length and some control bits. Each transfer can consist of many trbs. Such group of trbs is called transfer descriptors (TD). Each endpoint has own array of trbs that make up a transfer ring. The last element on ring is reserved and is set as Link TRB that point to the first TRB. Signed-off-by: Pawel Laszczak --- drivers/usb/cdns3/gadget.c | 235 ++++++++++++++++++++++++++++++++++++- 1 file changed, 233 insertions(+), 2 deletions(-) diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c index 0202ff5f6c90..911d9b8c1c8f 100644 --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/gadget.c @@ -239,6 +239,45 @@ void cdns3_gadget_unconfig(struct cdns3_device *priv_dev) priv_dev->out_mem_is_allocated = 0; } +/** + * cdns3_ep_inc_trb - increment a trb index. + * @index: Pointer to the TRB index to increment. + * @cs: Cycle state + * + * The index should never point to the link TRB. After incrementing, + * if it is point to the link TRB, wrap around to the beginning and revert + * cycle state bit The + * link TRB is always at the last TRB entry. + */ +static void cdns3_ep_inc_trb(int *index, u8 *cs) +{ + (*index)++; + if (*index == (TRBS_PER_SEGMENT - 1)) { + *index = 0; + *cs ^= 1; + } +} + +/** + * cdns3_ep_inc_enq - increment endpoint's enqueue pointer + * @priv_ep: The endpoint whose enqueue pointer we're incrementing + */ +static void cdns3_ep_inc_enq(struct cdns3_endpoint *priv_ep) +{ + priv_ep->free_trbs--; + cdns3_ep_inc_trb(&priv_ep->enqueue, &priv_ep->pcs); +} + +/** + * cdns3_ep_inc_deq - increment endpoint's dequeue pointer + * @priv_ep: The endpoint whose dequeue pointer we're incrementing + */ +static void cdns3_ep_inc_deq(struct cdns3_endpoint *priv_ep) +{ + priv_ep->free_trbs++; + cdns3_ep_inc_trb(&priv_ep->dequeue, &priv_ep->ccs); +} + void cdns3_enable_l1(struct cdns3_device *priv_dev, int enable) { if (enable) @@ -278,7 +317,27 @@ void cdns3_gadget_giveback(struct cdns3_endpoint *priv_ep, struct cdns3_request *priv_req, int status) { - //TODO: Implements this function. + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + struct usb_request *request = &priv_req->request; + + list_del_init(&request->list); + if (request->status == -EINPROGRESS) + request->status = status; + + usb_gadget_unmap_request_by_dev(priv_dev->sysdev, request, + priv_ep->dir); + + priv_req->on_ring = 0; + + if (request->complete) { + spin_unlock(&priv_dev->lock); + usb_gadget_giveback_request(&priv_ep->endpoint, + request); + spin_lock(&priv_dev->lock); + } + + if (request->buf == priv_dev->zlp_buf) + cdns3_gadget_ep_free_request(&priv_ep->endpoint, request); } /** @@ -290,13 +349,185 @@ void cdns3_gadget_giveback(struct cdns3_endpoint *priv_ep, int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, struct usb_request *request) { + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + struct cdns3_request *priv_req; + struct cdns3_trb *trb; + dma_addr_t trb_dma; + int sg_iter = 0; + u32 first_pcs; + int num_trb; + int address; + int pcs; + + if (!request) + return -EINVAL; + + num_trb = request->num_sgs ? request->num_sgs : 1; + + if (num_trb > priv_ep->free_trbs) + return -EINVAL; + + priv_req = to_cdns3_request(request); + address = priv_ep->endpoint.desc->bEndpointAddress; + + if (priv_req->on_ring) + goto arm; + + priv_ep->flags |= EP_PENDING_REQUEST; + trb_dma = request->dma; + + /* must allocate buffer aligned to 8 */ + if ((request->dma % ADDR_MODULO_8)) { + if (request->length <= CDNS3_UNALIGNED_BUF_SIZE) { + memcpy(priv_ep->aligned_buff, request->buf, + request->length); + trb_dma = priv_ep->aligned_dma_addr; + } else { + return -ENOMEM; + } + } + + trb = priv_ep->trb_pool + priv_ep->enqueue; + priv_req->trb = trb; + priv_req->start_trb = priv_ep->enqueue; + + //prepare ring + if ((priv_ep->enqueue + num_trb) >= (TRBS_PER_SEGMENT - 1)) { + /*updating C bt in Link TRB before starting DMA*/ + struct cdns3_trb *link_trb = priv_ep->trb_pool + + (TRBS_PER_SEGMENT - 1); + link_trb->control = ((priv_ep->pcs) ? TRB_CYCLE : 0) | + TRB_TYPE(TRB_LINK) | TRB_CHAIN | + TRB_TOGGLE; + } + + first_pcs = priv_ep->pcs ? TRB_CYCLE : 0; + + do { + /* fill TRB */ + trb->buffer = TRB_BUFFER(request->num_sgs == 0 + ? trb_dma : request->sg[sg_iter].dma_address); + + trb->length = TRB_BURST_LEN(16) | + TRB_LEN(request->num_sgs == 0 ? + request->length : request->sg[sg_iter].length); + + trb->control = TRB_TYPE(TRB_NORMAL); + pcs = priv_ep->pcs ? TRB_CYCLE : 0; + + /* + * first trb should be prepared as last to avoid processing + * transfer to early + */ + if (sg_iter == request->num_sgs && sg_iter != 0) + trb->control |= pcs | TRB_IOC | TRB_ISP; + else if (sg_iter != 0) + trb->control |= pcs; + + ++sg_iter; + ++trb; + cdns3_ep_inc_enq(priv_ep); + } while (sg_iter < request->num_sgs); + + trb = priv_req->trb; + + /* give the TD to the consumer*/ + if (sg_iter == 1) + trb->control |= first_pcs | TRB_IOC | TRB_ISP; + else + trb->control |= first_pcs; + + priv_req->on_ring = 1; +arm: + /* arm transfer on selected endpoint */ + cdns3_select_ep(priv_ep->cdns3_dev, address); + + /* + * For DMULT mode we can set address to transfer ring only once after + * enabling endpoint. + */ + if (priv_ep->flags & EP_UPDATE_EP_TRBADDR) { + writel(EP_TRADDR_TRADDR(priv_ep->trb_pool_dma), + &priv_dev->regs->ep_traddr); + priv_ep->flags &= ~EP_UPDATE_EP_TRBADDR; + } + + if (priv_dev->hw_configured_flag) { + /*clearing TRBERR before seting DRDY*/ + writel(EP_STS_TRBERR, &priv_dev->regs->ep_sts); + /* memory barrier*/ + wmb(); + dev_dbg(&priv_dev->dev, "//Ding Dong %s ep_trbaddr %08x\n", + priv_ep->name, readl(&priv_dev->regs->ep_traddr)); + writel(EP_CMD_DRDY, &priv_dev->regs->ep_cmd); + } + return 0; } +static bool cdns3_request_handled(struct cdns3_endpoint *priv_ep, + struct cdns3_request *ss_request) +{ + int current_index; + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + struct cdns3_trb *trb = ss_request->trb; + + cdns3_select_ep(priv_dev, priv_ep->endpoint.desc->bEndpointAddress); + current_index = (readl(&priv_dev->regs->ep_traddr) - + priv_ep->trb_pool_dma) / TRB_SIZE; + + trb = &priv_ep->trb_pool[ss_request->start_trb]; + + if ((trb->control & TRB_CYCLE) != priv_ep->ccs) + return false; + + /** + * case where ep_traddr point to last trb in ring (link trb) + * and dequeue pointer already has been changed to first trb + */ + if ((current_index == (TRBS_PER_SEGMENT - 1)) && !priv_ep->dequeue) + return false; + + if (ss_request->start_trb != current_index) + return true; + + return false; +} + static void cdns3_transfer_completed(struct cdns3_device *priv_dev, struct cdns3_endpoint *priv_ep) { - //TODO: Implements this function. + struct usb_request *request, *request_temp; + struct cdns3_request *priv_req; + struct cdns3_trb *trb; + + list_for_each_entry_safe(request, request_temp, + &priv_ep->request_list, list) { + priv_req = to_cdns3_request(request); + + if (!cdns3_request_handled(priv_ep, priv_req)) + return; + + if (request->dma % ADDR_MODULO_8 && + priv_ep->dir == USB_DIR_OUT) + memcpy(request->buf, priv_ep->aligned_buff, + request->length); + + trb = priv_ep->trb_pool + priv_ep->dequeue; + + if (trb != priv_req->trb) + dev_warn(&priv_dev->dev, "request_trb=0x%p, queue_trb=0x%p\n", + priv_req->trb, trb); + + request->actual = TRB_LEN(le32_to_cpu(trb->length)); + + priv_ep->free_trbs++; + cdns3_ep_inc_deq(priv_ep); + + cdns3_gadget_giveback(priv_ep, priv_req, 0); + } + + priv_ep->flags &= ~EP_PENDING_REQUEST; } /** From patchwork Sun Nov 18 10:09:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Laszczak X-Patchwork-Id: 10687707 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9423613BB for ; Sun, 18 Nov 2018 10:11:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8115429D43 for ; Sun, 18 Nov 2018 10:11:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7374429D38; Sun, 18 Nov 2018 10:11:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B254629D38 for ; Sun, 18 Nov 2018 10:11:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727491AbeKRUbC (ORCPT ); Sun, 18 Nov 2018 15:31:02 -0500 Received: from mx0b-0014ca01.pphosted.com ([208.86.201.193]:41282 "EHLO mx0a-0014ca01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727374AbeKRUbC (ORCPT ); Sun, 18 Nov 2018 15:31:02 -0500 Received: from pps.filterd (m0042333.ppops.net [127.0.0.1]) by mx0b-0014ca01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id wAIA8s12007707; Sun, 18 Nov 2018 02:10:56 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=proofpoint; bh=G4WTivoVWNC8CzhOVrnihtRPizlwoQD21JVx9xHSCJg=; b=tTj7q0XiG7bKryXi+P6Jx5r7ccuz6veXZQu2M6ADAP2ALX2HwXs9IMlLpzKSGK7CRcaW UbiQCEBWB/NVoLUg+GGpUk+hR7V1hJebFYNm183qm7tXN9zgnsXPk974SNZekZO9hp2s dHMT1pcvBlkBH/VbdlFw29QNG/J7HvbxPIDBwu/MbGYScw+zNBwcF8ctuQJ4HA3yCVEJ RQLK8v4AICP6Q3vkW74/h4p5EFeaY8Eko8mK9phUaqZQNB6VjrF8wc+kflTQzd4coss+ yU6CfQTGmhSzVuT8ZQdaKF8ITkZdmonlGo2d5tr86m1GEZlbLLbZ1TtrL8+jv35o2nQF Eg== Authentication-Results: cadence.com; spf=pass smtp.mailfrom=pawell@cadence.com Received: from nam03-by2-obe.outbound.protection.outlook.com (mail-by2nam03lp0048.outbound.protection.outlook.com [216.32.180.48]) by mx0b-0014ca01.pphosted.com with ESMTP id 2ntff7w460-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sun, 18 Nov 2018 02:10:56 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=G4WTivoVWNC8CzhOVrnihtRPizlwoQD21JVx9xHSCJg=; b=sQwznuVQMCWInTFi1uQMh1ipKvZIvnU4fNuXBEs+tGKVu4pYoHMekyX/B9cKYWZPfWs2HsUHS1XJCTU7qC9UOO41stqLyj18i/a3Akw2lRe4bRXnt8tC79hJMzxjoIx2lHNGeJ+TTAfTzv1KiDGKYdDqRzZVNDYVOgPyy7CJ8/w= Received: from DM5PR07CA0068.namprd07.prod.outlook.com (2603:10b6:4:ad::33) by BLUPR0701MB1858.namprd07.prod.outlook.com (2a01:111:e400:5165::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.23; Sun, 18 Nov 2018 10:10:52 +0000 Received: from CO1NAM05FT025.eop-nam05.prod.protection.outlook.com (2a01:111:f400:7e50::200) by DM5PR07CA0068.outlook.office365.com (2603:10b6:4:ad::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.20 via Frontend Transport; Sun, 18 Nov 2018 10:10:51 +0000 Received-SPF: SoftFail (protection.outlook.com: domain of transitioning cadence.com discourages use of 158.140.1.28 as permitted sender) Received: from sjmaillnx2.cadence.com (158.140.1.28) by CO1NAM05FT025.mail.protection.outlook.com (10.152.96.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.3 via Frontend Transport; Sun, 18 Nov 2018 10:10:47 +0000 Received: from maileu3.global.cadence.com (maileu3.cadence.com [10.160.88.99]) by sjmaillnx2.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAb5W029622 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Sun, 18 Nov 2018 02:10:46 -0800 X-CrossPremisesHeadersFilteredBySendConnector: maileu3.global.cadence.com Received: from maileu3.global.cadence.com (10.160.88.99) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Sun, 18 Nov 2018 11:10:44 +0100 Received: from lvlogina.cadence.com (10.165.176.102) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Sun, 18 Nov 2018 11:10:44 +0100 Received: from lvlogina.cadence.com (localhost.localdomain [127.0.0.1]) by lvlogina.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAfpR032414; Sun, 18 Nov 2018 10:10:41 GMT Received: (from pawell@localhost) by lvlogina.cadence.com (8.14.4/8.14.4/Submit) id wAIAAfB8032388; Sun, 18 Nov 2018 10:10:41 GMT From: Pawel Laszczak To: CC: , , , , , , , , , , , , "Pawel Laszczak" Subject: [RFC PATCH v2 14/15] usb:cdns3: Adds debugging function. Date: Sun, 18 Nov 2018 10:09:10 +0000 Message-ID: <1542535751-16079-15-git-send-email-pawell@cadence.com> X-Mailer: git-send-email 1.7.11.2 In-Reply-To: <1542535751-16079-1-git-send-email-pawell@cadence.com> References: <1542535751-16079-1-git-send-email-pawell@cadence.com> MIME-Version: 1.0 X-OrganizationHeadersPreserved: maileu3.global.cadence.com X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:158.140.1.28;IPV:CAL;SCL:-1;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(136003)(346002)(376002)(39860400002)(396003)(2980300002)(189003)(199004)(36092001)(50466002)(186003)(2351001)(246002)(6916009)(16586007)(7636002)(305945005)(478600001)(87636003)(36756003)(26826003)(48376002)(54906003)(8676002)(5660300001)(11346002)(2616005)(126002)(476003)(47776003)(2906002)(426003)(356004)(6666004)(8936002)(107886003)(336012)(446003)(105596002)(486006)(4720700003)(50226002)(26005)(316002)(42186006)(86362001)(575784001)(106466001)(51416003)(76176011)(217873002)(4326008)(14444005);DIR:OUT;SFP:1101;SCL:1;SRVR:BLUPR0701MB1858;H:sjmaillnx2.cadence.com;FPR:;SPF:SoftFail;LANG:en;PTR:corp.cadence.com;MX:1;A:1; X-Microsoft-Exchange-Diagnostics: 1;CO1NAM05FT025;1:vPXnVcdBZ2o5JAq6rW2VR/WX097kYfCsSuo1wYwVjuJHXdeXRDb+hxSdywsHUOSMXaehLpdBY7RUQ4MF9tDDYYuvhTHqpT14I5zwtM5uAYcoMSF9ual3hauMGdVC7ZdP X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 598b90f7-6459-496f-3827-08d64d3e1e31 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060);SRVR:BLUPR0701MB1858; X-Microsoft-Exchange-Diagnostics: 1;BLUPR0701MB1858;3:zOIYXJspRdbVe4gDj0V+zka6xdOaGCpCcmrfxdSoQ+LR+gqIjp3DReX1uiRi1LW2k1vt4UbDYlpZf4IIeuhPE+fQVVywjb+0x+UT4DDlTEv6MCH58PDlGxCY40G4tWtNP2VKNwMf9SJcSqKi1U8EELkKSbx3JWluN6uDNvTPrEfEC5RzVKogcg7qPzGD5dqY6uZHk4ISDjuUf3bS1KzD8MgfllnmSg7nj5XCtgXFiK+V7TF2e+7lgB2YGOVOYpphe+gj27fGUrkVzU4XwLUv/ZTb9xNm0clYxEY76PQkZLK+o2w24HmqYMSC5m0D9QcPuy4lgvDJ7EpbW7kH1PXcPqKTvJ3X7z0dwsNN44rayPc=;25:PoR83cnhCCXOIP8SOwC/3PWsRsE+eO/FTsVFYEMo9f7ujg1lH/tThK0TgIk6JdBaRtzVyBI5K+ei+j6PQvx9jrNX7vGvMyqVDSCeRKT0rwIbnylg6kd+StGKP9/kyjzp8+fttfHVlJ8aJFpMPolCXb/NgGSVodzWQh1hhLraTfJ3g0qPiCQW18QqoJRFWtmm1dZTy92QP8DQRGWj4hkzv5qW386/H71vj+/9L8lTEKA3xvSDtEJE5xA+hgxDLBpQx9KcQMPNJSso5snbdFwVXVClBF5L1q5N/sVn2oXTz1t+aGEwm993iut6ZfG1wvXxOg/AsB6lsIvZE/CDd5w33YRKZYDNrqGGFrZ9ySPYJ/I= X-MS-TrafficTypeDiagnostic: BLUPR0701MB1858: X-Microsoft-Exchange-Diagnostics: 1;BLUPR0701MB1858;31:p1r784d/cAGT4nbHOSYw0am2FqWBidpDoSwgEOHCfNB29Pp8XNfTIHF4qAgMrCXDkzvksfZRlAhTR14167dBvRHGOAAQ2p8sl4yMZh/tKxcB/fnlKzqaKqUzACMGySknr0cwaLA57Doc0RTIfRW56L58yM/62WpRjNp+aR6eiYHE/44ZwCX4VahovRD482Ka0gXw2FEJd+uvQUJ6669zb0o8ExO3NZRhWiUkUhiERQQ=;20:BOpfxzRX6is31siYJICh9xKoaJhpE3y+CD1x4rUmQqdCLNKOiXzwbbS4uSTRhKlqwRPmjm0n1ghv1C3zWglKPd21d8PdyE2/SYrrlHyqc7pG/KE2z8Z5/ewTUiKy6A6CZkZjKCpUL5tHuKZw9UYZBv9giS5qbNaxGC51StIWO+rbkdRbHKv6gJA95v6vLjFAyhjBOVXE9LeufPwjMUilnEbT+Ez5dNaTCqPgDwsualxVucU4Eo2tJRokcMQC8eoX8aJt9uXb0cO3X6GNqo2dTPsrMyWfQvGM8k5k8Oj/lI3X+prFnB1OM+XI3zKQXdLCVz0w7v1VbignnH8VAU1YEtvRL+3wSY3EWTee4mXQmx52lNYDdnXOZEilqBDHSxGk5TDKQHXACF8li+4pMI/h7j779+Nk++GFT5rZR5O7n257dW0HU36hVKVZ39PaxVcZHXCRS5raciE5yXB/YcLdAWn6LemVHJvQbzGXit+i3nTyYbJDEg8aRBiffc2PIvbh X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(93006095)(93003095)(10201501046)(3002001)(3231415)(944501410)(52105112)(148016)(149066)(150057)(6041310)(20161123564045)(20161123562045)(20161123560045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051)(76991095);SRVR:BLUPR0701MB1858;BCL:0;PCL:0;RULEID:;SRVR:BLUPR0701MB1858; X-Microsoft-Exchange-Diagnostics: 1;BLUPR0701MB1858;4:xEUBFbbrEuqbkkxrGO5f4BirSqrtkzP7Uwbe0v2uI1QsCD2AxxijhcNgDsr1tAxzQh9ElDQgS1x8Ae5yA8B2a5Um/DCkRE+q5HgbmqXhOr2SZKLQqMI409Nc7gRziYQgi+Yhz32SpkNquLdbmgwWHAGYe+l7xcY4prHMjve0OgYWtqCxUiHuKnMrG3572wNBKvWxc01JKrkJ+6L66byiamVVGoqRBbwNC/sAr+y3PtkmcAiaRFO3D3giNlY8dhvqXP74SNG9Ewjt3nMsX73qyQ== X-Forefront-PRVS: 0860FE717F X-Microsoft-Exchange-Diagnostics: 1;BLUPR0701MB1858;23:tUMOnKFkZLVMzGyXPpvlbgkGv7b+K+EvuUNXFO7662guq8+k/yvgrqiA9Xv9U3B1zfSg5RKXz2pXiHUzUlTiC1mhNZw0q4rtN0FBBehTnrUIM07YJrkixDxsABtN9Euv8DeSOk6+RkmtIVVgV/Ha6Fc087bPyPYG48by3xr9aeZf5znD62wCPOhNkxpcRqWIGcpSqXlqgJGmS6obdyW4ixkokVcVheNroINs8UU8leHmt3EFhaGDMZ/j/qkX4xOYJIfTRtBWMiFWd0gCsGAtPz0OzLuS5utEe8WAafFnBiM+bAf069Og+a26bNcQn77QCNRKEa1xQ1JLaEAgGHWUqJLmexJYSlv29KKcw8DZLEVi+aDHbmD26FoaIW4XBFij1D5KsPvSWuZ6CZkRUkQmvmM8qxAp8QaNojqXhOIVS23h5WKfrAPcaevj57uXvPowVkLAIgV8WlI9LO7XEc4yQrP7MbOMdcOR8uw4S4Kzp7dr2anO/5GWhB8zSng6BXdMQxcIqCBj7LX+dRhyUNbDJp9CiHOymCA019fqITstQPuOFaPVnoz1u8Tfd10pyFzkeSJWZkKH/aKhi7Q7Vtc0lbJ+znn7Q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vUfDHu X-OriginatorOrg: cadence.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2018 10:10:47.6230 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 598b90f7-6459-496f-3827-08d64d3e1e31 X-MS-Exchange-CrossTenant-Id: d36035c5-6ce6-4662-a3dc-e762e61ae4c9 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=d36035c5-6ce6-4662-a3dc-e762e61ae4c9;Ip=[158.140.1.28];Helo=[sjmaillnx2.cadence.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLUPR0701MB1858 X-Proofpoint-SPF-Result: pass X-Proofpoint-SPF-Record: v=spf1 a:mx-sanjose2.Cadence.COM a:mx-sanjose4.Cadence.COM a:mx-sanjose5.Cadence.COM include:mktomail.com include:spf-0014ca01.pphosted.com include:spf.protection.outlook.com include:auth.msgapp.com include:spf.mandrillapp.com ~all X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-11-18_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_check_notspam policy=outbound_check score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=936 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811180097 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Patch implements some function used for debugging driver. Signed-off-by: Pawel Laszczak --- drivers/usb/cdns3/Makefile | 4 +- drivers/usb/cdns3/debug.c | 128 +++++++++++++++++++++++++++++++++++++ drivers/usb/cdns3/ep0.c | 3 + drivers/usb/cdns3/gadget.c | 12 ++++ drivers/usb/cdns3/gadget.h | 13 +++- 5 files changed, 157 insertions(+), 3 deletions(-) create mode 100644 drivers/usb/cdns3/debug.c diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile index bea6173bf37f..34e60d03c4ec 100644 --- a/drivers/usb/cdns3/Makefile +++ b/drivers/usb/cdns3/Makefile @@ -2,6 +2,6 @@ obj-$(CONFIG_USB_CDNS3) += cdns3.o obj-$(CONFIG_USB_CDNS3_PCI_WRAP) += cdns3-pci.o cdns3-y := core.o drd.o -cdns3-$(CONFIG_USB_CDNS3_GADGET) += gadget.o ep0.o -cdns3-$(CONFIG_USB_CDNS3_HOST) += host.o +cdns3-$(CONFIG_USB_CDNS3_GADGET) += gadget.o ep0.o debug.o +cdns3-$(CONFIG_USB_CDNS3_HOST) += host.o cdns3-pci-y := cdns3-pci-wrap.o diff --git a/drivers/usb/cdns3/debug.c b/drivers/usb/cdns3/debug.c new file mode 100644 index 000000000000..b9a779b35789 --- /dev/null +++ b/drivers/usb/cdns3/debug.c @@ -0,0 +1,128 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Cadence USBSS DRD Driver. + * + * Copyright (C) 2018 Cadence. + * + * Author: Pawel Laszczak + */ + +#include "gadget.h" + +static char *cdns3_decode_ep_irq(u32 ep_sts, const char *ep_name) +{ + static char str[256]; + int ret; + + ret = sprintf(str, "IRQ for %s: %08x ", ep_name, ep_sts); + + if (ep_sts & EP_STS_SETUP) + ret += sprintf(str + ret, "SETUP "); + if (ep_sts & EP_STS_IOC) + ret += sprintf(str + ret, "IOC "); + if (ep_sts & EP_STS_ISP) + ret += sprintf(str + ret, "ISP "); + if (ep_sts & EP_STS_DESCMIS) + ret += sprintf(str + ret, "DESCMIS "); + if (ep_sts & EP_STS_STREAMR) + ret += sprintf(str + ret, "STREAMR "); + if (ep_sts & EP_STS_MD_EXIT) + ret += sprintf(str + ret, "MD_EXIT "); + if (ep_sts & EP_STS_TRBERR) + ret += sprintf(str + ret, "TRBERR "); + if (ep_sts & EP_STS_NRDY) + ret += sprintf(str + ret, "NRDY "); + if (ep_sts & EP_STS_PRIME) + ret += sprintf(str + ret, "PRIME "); + if (ep_sts & EP_STS_SIDERR) + ret += sprintf(str + ret, "SIDERRT "); + if (ep_sts & EP_STS_OUTSMM) + ret += sprintf(str + ret, "OUTSMM "); + if (ep_sts & EP_STS_ISOERR) + ret += sprintf(str + ret, "ISOERR "); + if (ep_sts & EP_STS_IOT) + ret += sprintf(str + ret, "IOT "); + + return str; +} + +char *cdns3_decode_epx_irq(struct cdns3_endpoint *priv_ep) +{ + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + + return cdns3_decode_ep_irq(readl(&priv_dev->regs->ep_sts), + priv_ep->name); +} + +char *cdns3_decode_ep0_irq(struct cdns3_device *priv_dev, int dir) +{ + if (dir) + return cdns3_decode_ep_irq(readl(&priv_dev->regs->ep_sts), + "ep0IN"); + else + return cdns3_decode_ep_irq(readl(&priv_dev->regs->ep_sts), + "ep0OUT"); +} + +void cdns3_dbg_setup(struct cdns3_device *priv_dev) +{ + struct usb_ctrlrequest *setup = priv_dev->setup; + + dev_dbg(&priv_dev->dev, + "SETUP BRT: %02x BR: %02x V: %04x I: %04x L: %04x\n", + setup->bRequestType, + setup->bRequest, + le16_to_cpu(setup->wValue), + le16_to_cpu(setup->wIndex), + le16_to_cpu(setup->wLength)); +} + +/** + * Debug a transfer ring. + * + * Prints out all TRBs in the endpoint ring, even those after the Link TRB. + *. + */ +void cdns3_dbg_ring(struct cdns3_device *priv_dev, + struct cdns3_endpoint *priv_ep) +{ + u64 addr = priv_ep->trb_pool_dma; + struct cdns3_trb *trb; + int i; + + for (i = 0; i < TRBS_PER_SEGMENT; ++i) { + trb = &priv_ep->trb_pool[i]; + dev_dbg(&priv_dev->dev, "@%016llx %08x %08x %08x\n", addr, + le32_to_cpu(trb->buffer), + le32_to_cpu(trb->length), + le32_to_cpu(trb->control)); + addr += sizeof(*trb); + } +} + +void cdns3_dbg_ring_ptrs(struct cdns3_device *priv_dev, + struct cdns3_endpoint *priv_ep) +{ + struct cdns3_trb *trb; + + trb = &priv_ep->trb_pool[priv_ep->dequeue]; + dev_dbg(&priv_dev->dev, + "Ring deq index: %d, trb: %p (virt), 0x%llx (dma)\n", + priv_ep->dequeue, trb, + (unsigned long long)cdns3_trb_virt_to_dma(priv_ep, trb)); + + trb = &priv_ep->trb_pool[priv_ep->enqueue]; + dev_dbg(&priv_dev->dev, + "Ring enq index: %d, trb: %p (virt), 0x%llx (dma)\n", + priv_ep->enqueue, trb, + (unsigned long long)cdns3_trb_virt_to_dma(priv_ep, trb)); +} + +void cdns3_dbg_ep_rings(struct cdns3_device *priv_dev, + struct cdns3_endpoint *priv_ep) +{ + dev_dbg(&priv_dev->dev, "Endpoint ring %s:\n", priv_ep->name); + + cdns3_dbg_ring_ptrs(priv_dev, priv_ep); + cdns3_dbg_ring(priv_dev, priv_ep); +} diff --git a/drivers/usb/cdns3/ep0.c b/drivers/usb/cdns3/ep0.c index 6f33d98f7684..8807cb02d7b7 100644 --- a/drivers/usb/cdns3/ep0.c +++ b/drivers/usb/cdns3/ep0.c @@ -605,12 +605,15 @@ void cdns3_check_ep0_interrupt_proceed(struct cdns3_device *priv_dev, int dir) cdns3_select_ep(priv_dev, 0 | (dir ? USB_DIR_IN : USB_DIR_OUT)); ep_sts_reg = readl(®s->ep_sts); + dev_dbg(&priv_dev->dev, "%s\n", cdns3_decode_ep0_irq(priv_dev, dir)); + __pending_setup_status_handler(priv_dev); if ((ep_sts_reg & EP_STS_SETUP) && dir == 0) { struct usb_ctrlrequest *setup = priv_dev->setup; writel(EP_STS_SETUP | EP_STS_IOC | EP_STS_ISP, ®s->ep_sts); + cdns3_dbg_setup(priv_dev); priv_dev->ep0_data_dir = setup->bRequestType & USB_DIR_IN; cdns3_ep0_setup_phase(priv_dev); diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c index 911d9b8c1c8f..97bdb292eaf2 100644 --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/gadget.c @@ -122,6 +122,14 @@ void cdns3_select_ep(struct cdns3_device *priv_dev, u32 ep) writel(ep, &priv_dev->regs->ep_sel); } +dma_addr_t cdns3_trb_virt_to_dma(struct cdns3_endpoint *priv_ep, + struct cdns3_trb *trb) +{ + u32 offset = (char *)trb - (char *)priv_ep->trb_pool; + + return priv_ep->trb_pool_dma + offset; +} + /** * cdns3_allocate_trb_pool - Allocates TRB's pool for selected endpoint * @priv_ep: endpoint object @@ -438,6 +446,8 @@ int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, trb->control |= first_pcs; priv_req->on_ring = 1; + + cdns3_dbg_ep_rings(priv_dev, priv_ep); arm: /* arm transfer on selected endpoint */ cdns3_select_ep(priv_ep->cdns3_dev, address); @@ -547,6 +557,8 @@ static int cdns3_check_ep_interrupt_proceed(struct cdns3_endpoint *priv_ep) cdns3_select_ep(priv_dev, priv_ep->endpoint.address); ep_sts_reg = readl(®s->ep_sts); + dev_dbg(&priv_dev->dev, "%s\n", cdns3_decode_epx_irq(priv_ep)); + if (ep_sts_reg & EP_STS_TRBERR) writel(EP_STS_TRBERR, ®s->ep_sts); diff --git a/drivers/usb/cdns3/gadget.h b/drivers/usb/cdns3/gadget.h index db8c6cb9f2a5..db5ab6b6c969 100644 --- a/drivers/usb/cdns3/gadget.h +++ b/drivers/usb/cdns3/gadget.h @@ -1089,5 +1089,16 @@ struct usb_request *cdns3_gadget_ep_alloc_request(struct usb_ep *ep, void cdns3_gadget_ep_free_request(struct usb_ep *ep, struct usb_request *request); int cdns3_gadget_ep_dequeue(struct usb_ep *ep, struct usb_request *request); - +dma_addr_t cdns3_trb_virt_to_dma(struct cdns3_endpoint *priv_ep, + struct cdns3_trb *trb); + +char *cdns3_decode_epx_irq(struct cdns3_endpoint *priv_ep); +char *cdns3_decode_ep0_irq(struct cdns3_device *priv_dev, int dir); +void cdns3_dbg_ring(struct cdns3_device *priv_dev, + struct cdns3_endpoint *priv_ep); +void cdns3_dbg_ring_ptrs(struct cdns3_device *priv_dev, + struct cdns3_endpoint *priv_ep); +void cdns3_dbg_ep_rings(struct cdns3_device *priv_dev, + struct cdns3_endpoint *priv_ep); +void cdns3_dbg_setup(struct cdns3_device *priv_dev); #endif /* __LINUX_CDNS3_GADGET */ From patchwork Sun Nov 18 10:09:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Laszczak X-Patchwork-Id: 10687717 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 94725109C for ; Sun, 18 Nov 2018 10:11:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B41829D31 for ; Sun, 18 Nov 2018 10:11:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 695D829D3E; Sun, 18 Nov 2018 10:11:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A075129D31 for ; Sun, 18 Nov 2018 10:11:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727382AbeKRUbA (ORCPT ); Sun, 18 Nov 2018 15:31:00 -0500 Received: from mx0b-0014ca01.pphosted.com ([208.86.201.193]:41278 "EHLO mx0a-0014ca01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727330AbeKRUbA (ORCPT ); Sun, 18 Nov 2018 15:31:00 -0500 Received: from pps.filterd (m0042333.ppops.net [127.0.0.1]) by mx0b-0014ca01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id wAIA8fNS007685; Sun, 18 Nov 2018 02:10:52 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=proofpoint; bh=rLIi4STjcy2dAVqkHNE3xAx2tlETUrDL/Z3vZN4VWck=; b=pfvMduyExmqv9Q7II32+TaEtaQDfOXLYUuWeyfLgi63n6FBBe0wNou7JQkYiUp0ocA8V 5cGE6LhH1V/pKPlmoIWi/6zWgqdUAoKzh14Xw4g9OnaYXUL/a9i8AmPl6O1tlnb8U70h lPsANa0wvKG1Dhe6i5Q2J5pu6RJFyp1h0QoOa+btz1vOt30rpxHx2gsOdvD8Srs2bpXh LXjseyN23y45eYb43rBPNnICITs0l5dOl83AemRiZD1iBteG09R//SchQnftY5mxZsfg Fka2ReZqNEXug2VpAvvKUW2iPOZsu+Ai5hoE+Ys2mC5khMgFBYDLAcQXCzk6ekQqrMs6 AA== Authentication-Results: cadence.com; spf=pass smtp.mailfrom=pawell@cadence.com Received: from nam01-sn1-obe.outbound.protection.outlook.com (mail-sn1nam01lp0111.outbound.protection.outlook.com [207.46.163.111]) by mx0b-0014ca01.pphosted.com with ESMTP id 2ntff7w455-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 18 Nov 2018 02:10:52 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rLIi4STjcy2dAVqkHNE3xAx2tlETUrDL/Z3vZN4VWck=; b=lxVqWZ37wC5CtcS9a2qxce4ayrXWgNcd7zNtbMhTJGNQqqg8bQDZAspVY3NuwfL/YvEwxWTd/5qUPxKfcBpipme6F5JoVT8SRMdL/pLgPNUR0kmQD2cka2E/vdVvDhSTvyKc+3RAFeyFsJyZcOa0j9RQb3gGsHlMwMAp0CHb0hE= Received: from CY1PR07CA0009.namprd07.prod.outlook.com (2a01:111:e400:c60a::19) by MW2PR07MB4107.namprd07.prod.outlook.com (2603:10b6:907:7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.26; Sun, 18 Nov 2018 10:10:49 +0000 Received: from DM3NAM05FT059.eop-nam05.prod.protection.outlook.com (2a01:111:f400:7e51::209) by CY1PR07CA0009.outlook.office365.com (2a01:111:e400:c60a::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.21 via Frontend Transport; Sun, 18 Nov 2018 10:10:48 +0000 Received-SPF: SoftFail (protection.outlook.com: domain of transitioning cadence.com discourages use of 158.140.1.28 as permitted sender) Received: from sjmaillnx2.cadence.com (158.140.1.28) by DM3NAM05FT059.mail.protection.outlook.com (10.152.98.176) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.3 via Frontend Transport; Sun, 18 Nov 2018 10:10:47 +0000 Received: from maileu3.global.cadence.com (maileu3.cadence.com [10.160.88.99]) by sjmaillnx2.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAb5X029622 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Sun, 18 Nov 2018 02:10:47 -0800 X-CrossPremisesHeadersFilteredBySendConnector: maileu3.global.cadence.com Received: from maileu3.global.cadence.com (10.160.88.99) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Sun, 18 Nov 2018 11:10:45 +0100 Received: from lvlogina.cadence.com (10.165.176.102) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Sun, 18 Nov 2018 11:10:45 +0100 Received: from lvlogina.cadence.com (localhost.localdomain [127.0.0.1]) by lvlogina.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAfHb032620; Sun, 18 Nov 2018 10:10:41 GMT Received: (from pawell@localhost) by lvlogina.cadence.com (8.14.4/8.14.4/Submit) id wAIAAfWN032542; Sun, 18 Nov 2018 10:10:41 GMT From: Pawel Laszczak To: CC: , , , , , , , , , , , , "Pawel Laszczak" Subject: [RFC PATCH v2 15/15] usb:cdns3: Feature for changing role Date: Sun, 18 Nov 2018 10:09:11 +0000 Message-ID: <1542535751-16079-16-git-send-email-pawell@cadence.com> X-Mailer: git-send-email 1.7.11.2 In-Reply-To: <1542535751-16079-1-git-send-email-pawell@cadence.com> References: <1542535751-16079-1-git-send-email-pawell@cadence.com> MIME-Version: 1.0 X-OrganizationHeadersPreserved: maileu3.global.cadence.com X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:158.140.1.28;IPV:CAL;SCL:-1;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(396003)(39860400002)(136003)(346002)(376002)(2980300002)(189003)(199004)(36092001)(8676002)(8936002)(86362001)(107886003)(6916009)(105596002)(26826003)(14444005)(11346002)(476003)(446003)(426003)(42186006)(316002)(106466001)(486006)(126002)(217873002)(4720700003)(2616005)(246002)(51416003)(336012)(16586007)(5660300001)(54906003)(7636002)(186003)(50226002)(36756003)(26005)(47776003)(87636003)(76176011)(478600001)(4326008)(48376002)(2906002)(6666004)(356004)(50466002)(2351001)(305945005);DIR:OUT;SFP:1101;SCL:1;SRVR:MW2PR07MB4107;H:sjmaillnx2.cadence.com;FPR:;SPF:SoftFail;LANG:en;PTR:corp.cadence.com;MX:1;A:1; X-Microsoft-Exchange-Diagnostics: 1;DM3NAM05FT059;1:LYaV5q0GwMfd9dpYeD2DNcnJVDMPoFWAVSAugzx4iPljT4VUm+oHdczUfOcFqgQCbmNtgICnJlr1uBx4yPFWooZkHXOpupbdgEMaVkavEKp6tTx2AStIz9K7139X1+sn X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6442047b-6bfe-458b-5e21-08d64d3e1cbe X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060);SRVR:MW2PR07MB4107; X-Microsoft-Exchange-Diagnostics: 1;MW2PR07MB4107;3:iyx/npAYnBYh9C/iqWDGTHqWqFxEnar8cVe0WSbmC7FYAyXVxfa7d73XBc1zqguSbeQmnAfkCT+5cMP/XVnW2lwSmkpwwNxWE38QRT4WmUcP/ppYmFZxANZhFSFmjC2KDpTkMp1N18g7DeobNttML4ZsrlGDe2sDT+y8CVMqF5ueShF52V0o7EzC+Ff50aNj3HpcaYQNhasaNwEFyn0b/dGPBRrWqtGjPvATuB2XAMcFBNZt6fZ3u9U1Ndb8pw1FdMBL03Du2cQtCeWqLietgBQxAqsagt7l31vUKqHL6IbDGgk6BunvmYy9lTryTdhKC3gTnRD8OPvEVIHyV9qvFT0E6syhwdpAmaEoKaSIf+E=;25:rRidzHGVuJiqs0Efkjf2A7Ro17eGCKVcmj3zpdoJqt7s+IN0iaZjXa1l9SLs3TsYo+8P+RS2k3zMT35nnZJAh3fIArhP+4z0uHtO3WYf4BtYiDUf2/DluFjD4yzejMHSiE67TpB9uBR5T9d9TGQG9TMbRXW0GyBD2LKYVkTrO8rW5m40K2PAwn/Htw9TRgdZGE/+3A2reCplcyOmfrEkpaXWDhL0/AGYRK7LDFCf4vXfTMlrNdRldNHT3qbXGJLK8ShryDCwV/yYyfoT1fVGVRT+ZLm0qNP21FmPxr7dESj76qJ2incYeX3OUViL98xwbD/84cI9NO0087t+5nIytzt7r0ZanL9Ni7GYsyz7Tu0= X-MS-TrafficTypeDiagnostic: MW2PR07MB4107: X-Microsoft-Exchange-Diagnostics: 1;MW2PR07MB4107;31:Guip2tXq240e3/ZoqiMrSkbCmnUNuIc21Ry7FlL95BQuE3wWNjKdxlp2K486YYTtrNiEkQYulJ2XZ+5AyJpFo78/mHBxWsIXNYIh+nDI/me9OYjIYvQGxR/c4ukO6q7rZsl354MF1TIP70RISZp5MuCH49AWNFZkI8Vat79OEovmAr84P3RajQitGxHdltA931s/W/G73lsw3O2XJ0yPsiYI1POfKURXBlgymRHFV7s=;20:v5+4Ja++1WKSu47QLpznQ8WL/MWotVIJsWHjtVLIqAv6oCLtN7pi6Q0pd33a7WG/9WJPYCARuBovXNkYf48DmAd4KsOJOT4l2wiXJgIlJW8gmNyd4Vj2zpDu9xVnnYAWgHJiksaQnoS0Y67la6TGe9Q7AYKYfBQMAJYiVEQeJeWzaLlbEeWM5GOVV4anpMOhbmMiCcDULcUYP6A68h/id3gsmtj8c1CjWqNlVoTdACvP/nYnUWLAEurOR5PcoaWBSUkCXEkZRTdOT+0LCmaywQvOAMxYXjYUEDYYeVjl2IwyDsLw+6IKePp+3DYGJFFJxIFR3/5trHcjYlUImYdVfdvzrEoM/4DK+f6QHU5TmzfA92byPw1+3Co+iXm7ligUACSInO5oaHkGVuEQXfqubDP+U6/5gHksKUDwNdMbkrOymvbK8Bda4QQdINhMje8+sYpvTd/9ZDlx3fXhuNBMEPnzIg7KrFZWrQBgQY9qIM8mIZ50DFe3dzSCt8DMv+F7 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(72806322054110); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231415)(944501410)(52105112)(3002001)(10201501046)(93006095)(93003095)(148016)(149066)(150057)(6041310)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123562045)(201708071742011)(7699051)(76991095);SRVR:MW2PR07MB4107;BCL:0;PCL:0;RULEID:;SRVR:MW2PR07MB4107; X-Microsoft-Exchange-Diagnostics: 1;MW2PR07MB4107;4:DHlhKz1wdJxieYKA4zBX/J5ihod5c36yQtuzyiXtfXsejlCGqiRQL6uFcbMrmklx4/nZJ5sDGr07pO/LhA0ts4liT2XkQiEdXSRnnqTABILl82Vmd6FESbl/0bZR2hn5Q8/Dkp2vy50CANHVs/RPP/awuU1iueOplG9NgU1C+KO6kflQ1vjj2PGdiZhrQOq/apch5zjnz661Lh/sUpUakoDH7YCMb+Dmw6XVYTpR0RGGhO+Bx+Ry8mU06p2yq+PelI5utRnU99kx9htjo4zyqXidMVy253o/nxrgibIB9CXl95V/LnfbiyQB9tbkvYEn X-Forefront-PRVS: 0860FE717F X-Microsoft-Exchange-Diagnostics: 1;MW2PR07MB4107;23:n3FvUje9dCf7HMI+WN4Be+IAYnjRcD4Q2irEJcW4qIjaKxT/uR/b+QWGuo/9n7bHmyYGVznBTNqWInxhSMbLjZwn3di0eAGfXyNBqnuIYZ3T4Czd9xMeRszACr0MS63qncVVBzzAjbo+zlUFIzqai0u3FOGkBAj6SpYNDOGVPw+S9hI8MaG1wojJhVH+ByN21uCQSp9gAgFN07B14Uvi+G2e/jk/I3TGmqUAm35mYkham+x/uggafE50gENpssroLl+b3ZIyRgG9xI1OnOPt+lvYG54HmzkKYthzs+qQ1+NZOki2waJ9+lIIlATbO3FeNDlH4l33VJzGozbVSE/7NoUj7krFRjDTIXP/5qPPE1PsI6HM3JL6fpOTcijYvtjwzfabnojuX6FzuZzXNX+Ii90OnCKeTokcx4Kv8F8xArcaXaXPHer9PhNXFLIJL11d6PlNXQQp32syIgdaWSxJHr4wBWK2dtCd+7UT18FmyYnQlQf9OJD+BMognliw6UqOHP/JAS3zOgMEyTHVUDHMD0+3M+4eug6R4xMDu1rGfRy+R6uvFk5gFUkSoy4zSPKstcs0THyHRJjhZNQM4keK8A+9xHpGECxSOjLcsPZL78PjoB/2sLh4L6NthtAJ79G8Kb9NOSDBIIANECsh4DSfGMckJYN+muLWP6NPYxuUla0WJEzviC2kTNF03GsLcqdv06P96fKryuyRZiWOVpnyX9cnLZ8bQoTR21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rL8777RwveUfWxm+lDtCl7obMjbunbzvJFsKffc1HmeIQH0kYUVdgXEn3ecJohYsTHRHls5EItvaaNzcafAuLskNRJVQd02x9W2JGawd/j5h8HcFiDGMowOpbw5gVoWQ5UE3Ptw4Lo6PYovdizkyzo8dTpnZ8XVHvcUJWalnq6OeeKF+WO02MZ4zgcvzPymJmX9dhVwDgcIhQz/fC1x4mUY5Qw1ls4KInqguzBVkkKMfVAQ/+w==;5:lVWvV1lH1hJRrvDKvEmAnC9k8Bw7KYABc2ZEfBBTQ4zySAb9jXwzlVQQMQ9OXO+mPWPYo5v+jMbmyeN1dcSlY+pNgu7WnWhrlT7H1Z9FuzcRdQv2tI2puyAra04M4lPnbqQcERdt+zPtt9K6Wu9w2vYqjxTsbZmxDWiwlk9kqhw=;7:JtmhUy4r1kzGJQdgD5y15iiKQy18C96kRea3a6+t1DHW3SAgk4Iqbx9qF/lpgUJ/3sJ31Ec9sF/ajkJJJ7EBr45/iWKQujkHe1s4+NK4yKvWLMsE6CqNOcmUzLUQSjKFnH0b4o3/w6UaMQHsOEtbhg== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;MW2PR07MB4107;20:fT1mt9SXxwKtjqQ/W8OigCGWGcyEkqfy4D/z7GBfpwbjK8o6P3G4TnsYJpuIPUTve4i1r47k9nAoBNDKypbHJUgWDspXAxtTXYvHmhWswDcw5Y9jr2yN1TmrMcBiUzyGPL5i4jC6HZ+f/z/V2wXVS81UBGLDTObg5hqt4OHE4OIn2q2K7aef1kAtoSeJ+Oap8+1I4/Z1ZfIWll2R3JMa8w5hvRWlstrga1lBgbtmW8QUx7astLCeruDO4iEeFWcO X-OriginatorOrg: cadence.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2018 10:10:47.9584 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6442047b-6bfe-458b-5e21-08d64d3e1cbe X-MS-Exchange-CrossTenant-Id: d36035c5-6ce6-4662-a3dc-e762e61ae4c9 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=d36035c5-6ce6-4662-a3dc-e762e61ae4c9;Ip=[158.140.1.28];Helo=[sjmaillnx2.cadence.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR07MB4107 X-Proofpoint-SPF-Result: pass X-Proofpoint-SPF-Record: v=spf1 a:mx-sanjose2.Cadence.COM a:mx-sanjose4.Cadence.COM a:mx-sanjose5.Cadence.COM include:mktomail.com include:spf-0014ca01.pphosted.com include:spf.protection.outlook.com include:auth.msgapp.com include:spf.mandrillapp.com ~all X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-11-18_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_check_notspam policy=outbound_check score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=840 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811180097 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Patch adds feature that allow to change role from user space. Signed-off-by: Pawel Laszczak --- drivers/usb/cdns3/Makefile | 2 +- drivers/usb/cdns3/core.c | 2 + drivers/usb/cdns3/debugfs.c | 93 +++++++++++++++++++++++++++++++++++++ drivers/usb/cdns3/drd.h | 3 ++ 4 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 drivers/usb/cdns3/debugfs.c diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile index 34e60d03c4ec..08e6cdbebd46 100644 --- a/drivers/usb/cdns3/Makefile +++ b/drivers/usb/cdns3/Makefile @@ -1,7 +1,7 @@ obj-$(CONFIG_USB_CDNS3) += cdns3.o obj-$(CONFIG_USB_CDNS3_PCI_WRAP) += cdns3-pci.o -cdns3-y := core.o drd.o +cdns3-y := core.o drd.o debugfs.o cdns3-$(CONFIG_USB_CDNS3_GADGET) += gadget.o ep0.o debug.o cdns3-$(CONFIG_USB_CDNS3_HOST) += host.o cdns3-pci-y := cdns3-pci-wrap.o diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c index 1fa233415901..304323b643f2 100644 --- a/drivers/usb/cdns3/core.c +++ b/drivers/usb/cdns3/core.c @@ -323,6 +323,7 @@ static int cdns3_probe(struct platform_device *pdev) goto err2; } + cdns3_debugfs_init(cdns); device_set_wakeup_capable(dev, true); pm_runtime_set_active(dev); pm_runtime_enable(dev); @@ -358,6 +359,7 @@ static int cdns3_remove(struct platform_device *pdev) pm_runtime_get_sync(&pdev->dev); pm_runtime_disable(&pdev->dev); pm_runtime_put_noidle(&pdev->dev); + cdns3_debugfs_exit(cdns); cdns3_remove_roles(cdns); return 0; diff --git a/drivers/usb/cdns3/debugfs.c b/drivers/usb/cdns3/debugfs.c new file mode 100644 index 000000000000..189b12d96cbf --- /dev/null +++ b/drivers/usb/cdns3/debugfs.c @@ -0,0 +1,93 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Cadence USBSS DRD Controller DebugFS filer. + * + * Copyright (C) 2018 Cadence. + * + * Author: Pawel Laszczak + */ + +#include +#include +#include +#include + +#include "core.h" +#include "gadget.h" + +static int cdns3_mode_show(struct seq_file *s, void *unused) +{ + struct cdns3 *cdns = s->private; + + switch (cdns->current_dr_mode) { + case USB_DR_MODE_HOST: + seq_puts(s, "host\n"); + break; + case USB_DR_MODE_PERIPHERAL: + seq_puts(s, "device\n"); + break; + case USB_DR_MODE_OTG: + seq_puts(s, "otg\n"); + break; + default: + seq_puts(s, "UNKNOWN mode\n"); + } + + return 0; +} + +static int cdns3_mode_open(struct inode *inode, struct file *file) +{ + return single_open(file, cdns3_mode_show, inode->i_private); +} + +static ssize_t cdns3_mode_write(struct file *file, + const char __user *ubuf, + size_t count, loff_t *ppos) +{ + struct seq_file *s = file->private_data; + struct cdns3 *cdns = s->private; + u32 mode = 0; + char buf[32]; + + if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) + return -EFAULT; + + if (!strncmp(buf, "host", 4)) + mode = USB_DR_MODE_HOST; + + if (!strncmp(buf, "device", 6)) + mode = USB_DR_MODE_PERIPHERAL; + + if (!strncmp(buf, "otg", 3)) + mode = USB_DR_MODE_OTG; + + cdns->desired_dr_mode = mode; + queue_work(system_freezable_wq, &cdns->role_switch_wq); + return count; +} + +static const struct file_operations cdns3_mode_fops = { + .open = cdns3_mode_open, + .write = cdns3_mode_write, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +void cdns3_debugfs_init(struct cdns3 *cdns) +{ + struct dentry *root; + + root = debugfs_create_dir(dev_name(cdns->dev), NULL); + cdns->root = root; + if (IS_ENABLED(CONFIG_USB_CDNS3_GADGET) && + IS_ENABLED(CONFIG_USB_CDNS3_HOST)) + debugfs_create_file("mode", 0644, root, cdns, + &cdns3_mode_fops); +} + +void cdns3_debugfs_exit(struct cdns3 *cdns) +{ + debugfs_remove_recursive(cdns->root); +} diff --git a/drivers/usb/cdns3/drd.h b/drivers/usb/cdns3/drd.h index 0faa7520ecac..8367032e12a3 100644 --- a/drivers/usb/cdns3/drd.h +++ b/drivers/usb/cdns3/drd.h @@ -119,4 +119,7 @@ int cdns3_drd_init(struct cdns3 *cdns); int cdns3_drd_update_mode(struct cdns3 *cdns); irqreturn_t cdns3_drd_irq(struct cdns3 *cdns); +void cdns3_debugfs_init(struct cdns3 *cdns); +void cdns3_debugfs_exit(struct cdns3 *cdns); + #endif /* __LINUX_CDNS3_DRD */