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/dquSKb94MNSzNVPOW0mFzxvzJ8k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doTPxhhCr1ujOzmWTBXRTlI3/IpeipZgDT2rnGKmnb+dJ+rxdjRQ4gKeuqa5Kfv9TjyZg//uQfyPBEt4FOsZiDz1ODzA91u7GxKVxwKe01M+Pnxx56JzgtwfbiB//9KC+7HDKJZzAGZC0wuvDjNpGDkbkmWU0MVz1Abtrn4AEQI0PuPvzuuvZdrij3sDBVP5d/bTT5vWORlWqp8P50k1UInFexTS7mMWbMnNez/bkzBT5W0bH/YzWwZghchH4CYWP4d70aoJ2GCaY/q62wd0NkIOWiJtF9UA==;5:m6nNr/TWNjxNDHTXE2/DBnfxbuWqRq6f1vxJx83MDQZ8UeI+UaA+4C17/aXjrYJ41+jIeSeCV30lhxG6VxhBLU7k9hUDYKWCkAsvpiwsm+PsC17QfHOwba1OiVRMWemGMMf2XpjX+YRmFDpM+1vOIuz34FGX7dBl+zsYsse5IGw=;7:f1+Nm2bnMnB+c59NZJBVBs+qtmTmSWIy0VvRmqZQ6AaoFgNuKUKQPLqcksEYdlhmqMo9QGKq/J1MizI0FlccAINNJElxvMVEcQGp//CTEY84DuM/WjPmsCgU1BvNbI/UlStyaN5LuWMBfWYnOmHxTw== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 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 */