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/13uP0flnpn7OWJWWFnauSZp8x7nH3lfpEfziH0KQsGYKfz6bYJM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qdxR3oekFYdMrtVFM0kl5bnYT4ghVJmuMdCBH122fmrWi5ySEf1zupQbIVxlFdBJn3lQIRU4802Ubtb3G1+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 */