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/judcjgDi5rc0qQuULI5jEwstfrQNdZ9Y2IEGlGIGad3EB98I8HK4gqalPV4BE+LF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MnP21CN9e/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 */