From patchwork Tue Mar 8 07:34:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Ji X-Patchwork-Id: 12773186 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E242DC433F5 for ; Tue, 8 Mar 2022 07:35:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344573AbiCHHgH (ORCPT ); Tue, 8 Mar 2022 02:36:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344539AbiCHHgG (ORCPT ); Tue, 8 Mar 2022 02:36:06 -0500 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam08on2134.outbound.protection.outlook.com [40.107.101.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C25D33DA69; Mon, 7 Mar 2022 23:35:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YuAMDodXTUadPUW0E03U88bQOthxVBT1WWX8sdW1/ipDs+d6bjTDEizm1MAhl09xTtWM1k3w4mlR80YvEri/7uZChJWGembJ/R87hdaMsyU/kOje5kQMsUWz5UMXsuCVMgUnzLQV8dWBVsWEyC93B2SGTBhgxSRMdJxtJ076NgyWZpGOZ5fw7qWbvFBy0n9uhFLRLBwNJdKp/1SqbC5qr/RGFsehgjKku+y5NZ12xlaJnIhlMVxjsb50wyBY3O2WEw8qG6Oi8E8ysD5HfQ5vM/9xYitL+HaHPZ7qWjq5GlGaS0/UsF7DMm4D9asdJ2h5PvMIkJHcWTJPDczbBprVwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dWlAhl5oUhm7qEe3EfFCM3od0qBU34dqA0qLEJfF2hU=; b=c4RNdR80BSPn/1FMflALdT+qPk0qrCxM8JLaP2+N6b1nMkiS7OfOz22ugB2m2t6c9tILHyHiQDz0f3Q7snqXAzyubQj5YhIwzqrvQCoWH+OmxH8TQiqiuwTm6+PGVQouPKil9PypyIF/u0qYTnxXNNhROMlBEu1+mmXrfCZoHKv6RDG8zjZujvOnqzFijpJNY4J1y3IkEZSzMn5bfgU0C8c2vZxBLUskiGIbsouI1anzeArkt54IpBymBrQqmtxP9bueERVQXwt/oGXTNhCr/FgHBKVErYfyPsdx7nUC8Z9LfbuDFush+VFznCe9RAvn6lQ7nFMGl3TLnehoB6FGnA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=analogixsemi.com; dmarc=pass action=none header.from=analogixsemi.com; dkim=pass header.d=analogixsemi.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Analogixsemi.onmicrosoft.com; s=selector2-Analogixsemi-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dWlAhl5oUhm7qEe3EfFCM3od0qBU34dqA0qLEJfF2hU=; b=GswAUuogq+WSY+fO2eVCT8VuLJK4EZlq3PCghbCsJxr1wiJL8pHs3japGdSVcRhc6FFHiXK6fJOqZiE/AiexeglOfSwe8O7E47InqduX+ERbRh/QrLlf/cLSJlPn814jO2yw4ISSBfi/C4V6745almtOB44VZDsy1E1tmBNsrCQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=analogixsemi.com; Received: from BY5PR04MB6739.namprd04.prod.outlook.com (2603:10b6:a03:229::8) by DM6PR04MB6592.namprd04.prod.outlook.com (2603:10b6:5:1bf::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Tue, 8 Mar 2022 07:35:07 +0000 Received: from BY5PR04MB6739.namprd04.prod.outlook.com ([fe80::a865:6d10:c4a9:1142]) by BY5PR04MB6739.namprd04.prod.outlook.com ([fe80::a865:6d10:c4a9:1142%9]) with mapi id 15.20.5038.027; Tue, 8 Mar 2022 07:35:07 +0000 From: Xin Ji To: Guenter Roeck , Heikki Krogerus , Greg Kroah-Hartman , Matthias Brugger Cc: bliang@analogixsemi.com, qwen@analogixsemi.com, jli@analogixsemi.com, Xin Ji , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH v8 1/3] usb: typec: tcpci: move tcpci.h to include/linux/usb/ directory Date: Tue, 8 Mar 2022 15:34:28 +0800 Message-Id: <20220308073431.1217890-1-xji@analogixsemi.com> X-Mailer: git-send-email 2.25.1 X-ClientProxiedBy: HK2PR0302CA0015.apcprd03.prod.outlook.com (2603:1096:202::25) To BY5PR04MB6739.namprd04.prod.outlook.com (2603:10b6:a03:229::8) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a114aa6b-a981-4a86-405b-08da00d62afe X-MS-TrafficTypeDiagnostic: DM6PR04MB6592:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: r6IGSBH29VHGhL/APQizSJg7jOZfaNAScOcH92m8OPrkGv0U/MDa2CLsAvI1XXR0KGMqojTpEMJaXXZKK5QA8hCXZwejXaQ/GvwyBSv9lMRnrUKvfNDQxMaPQjjLFcMeTp202FXl8xszXZCM9+GPITtaHeGixq6lwtfznR6FaQRDHDujaV+UTAFh57GuP2XVm/exQXKPvMXQH9cubT71l+kn5iuO3AJcmrIDjS/25PuSFrwcGjoF7iDm4WJrIIt07g/VE/cFEmKAMAtzl9KKXiMPnbAtmS9ph8c9rkdS0f6FGfRD2ZchbE1RHf2MJVEIjY8zZ5eutgQy/To/iRyxPngspl5WU+r/njEBmsGsCei8NGrCsvQGKOwhS4KW/RKUtZnOVUbc+d609mLoV1Ejmrn0XG19NHvONMPQjcm7blWM2kWO810cAtLuZn2As4vAKAghZXQgpkwPHwrkfY0CDMitXm3wAUmYH4+JYsDTtrOrMv3KbhxeREekGz8TTniE5Qii0fN0P1QcIBNnPEwuvYJgjJLPslW17Ym6DvifQzcFF+x6bvuyr62tUieq/QbDOUokPXem+wa1xov1SZdwzaTaa/PppIY6Y1Cu3Hki/BNDzdOnYutHiRrLchaNl8DXeYJ0fUwvhQux84uTlxvu0X8+9fWE3WeqEEieCvxZ2hhHGPEAMSc0VitDtemBMXYxT8PaBC8jMpSnw2/HlIxCqg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR04MB6739.namprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(83380400001)(38100700002)(38350700002)(8936002)(5660300002)(6486002)(66556008)(4326008)(1076003)(110136005)(2616005)(66476007)(26005)(186003)(498600001)(6666004)(6512007)(55236004)(52116002)(6506007)(2906002)(36756003)(8676002)(86362001)(66946007);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xQfznDyFmbmEDkwljdbGsfIbVBCzdzYVNQZ1XICIRnStFPkiifDvGo5AmxNvJOyt6qiFTQl4+rE9vDfQXW6Z3/5DqgpK1emEGuWwy84VcLDQNYDcQ2G4n8Cww3BwuHPocja8xvzv9Gpt9tRcLxVjrqNPBk9sKEQTlqSh+Cv/GX9mV8/H4zk0YCfUnGIaIfu/VJL2rRoZgKNYiRmcofJGhE+jLdCZQR2lGX96mOLXm1Ai9fnwLiB/2K4Dn7hivur9QYlCsW7ghstvlKXtfq1XTJ2hX38A2H/nIA7EDRgZduzBtiWOg6CqPw38MeYdaaah3YynU9s0aKzzS9MK8aTrRJGhL8sxgxFjEFUo5Dub6fKquUUK5/jgx7JzbcMy27ju4XpED2XYcM5OEV7c4SKA6jXDhw5kOd1qCEaOuYbzptt8l7TOeRF+ZqYrYv0vo7BNQoACRtMsMp0DK4pQhr81TyAzKG+XjsGnBt0ws+Vb8AFqJTcdJ5xBSl0/esmtMZL8l4oSZWea0djOpvKTNolzfwYr/gv1YnqD282qP6XNeRJjmpYRvsCXvwgoFKTwaDnN3DseTigw/ZpESToAjjEoa004oq/lbJ0Qivub/tROQjw0p5OF2KPlWOhgBm2Kk4CGrW8GJBLY/aCPN8DVFzYYl4JFW0caZu2q2uWWCupFkUDYOBGn3w6VLIrlB3Sti+JWRVxP/i1L3g0CKfmCW06teWJBsbc/YnPziGwQxAc7cripPe/E6c2qjGk1IqJSrMg4v6Yb8URZb+Mw551EYVQfpbkDL0C2RbKyiLIM2dF5kn5oVqaUKTGAjrjkim/ahS+qvZ0LoyWKl/PorgroX3WgSpDqcsPpD8/wTrj2WKJ7QnSizebmON5CxF/9iwcNEt43Sd/FQ2gscWRTGu+U6IvlbfdadjvXC2oQUcdTDDq7rdcBuAAkeW7sQnHNJAnAQUb9ZKNQfcWQi0f83EFKDj+YGttWBk95xTRW2JhuVvY2b8YxpAx/avsi0CDvH5o69DcviWazvCRMMVXhzbKqK2df3FJ08Q48R8ehcr2sRwozE8MumMfAW7MP4SWPsWsEgxm0SrdlUNwtu+5HHTqiLdQWciIdNP0PcqXYKPZwnMYBm+0Y89MzVcs/+P47bR+KMnBpQB9scUYRtg0s3t8xzDzSf8RaMKDMduczMb5I8J6OAVmm6+nlhqe6Qc2Ryg6yGAbmDxVn+LMs38JBO6S0NG5B4yCUniTEuzvPETMtVGtbu80WqXobMjPanp1NIm79DK84ZqGiyH4emrFgdnylByBtBvijurFMYs0b4O9Jujs3QP5JUAZycezWFUd5TdpxMWb/aolLUtCykYrxB0/UC15ybe0d4d4SBcEzipLi2h1nUcPPuEHJL7DcQjrOfFl8iX/JdfjghI0BNldZBT/dn72I325TX1AtHQsAGc4Gf/MsV5T59awUG2P84M4PiGtOtwGkRrExrbbsYfgPTPFG6ukEhQ/F45sU+WP/b0hc9YGJN8cXJ8QTS08o6am44OMjprDcMeaerTf1yzFT1WpANgAfh9qSoytgXlDmfpA/gg2nc6E0DIyu6awt4/6VK7KAf9wCskqEVS5jlLkjobd58rSbAnY37qDjqzX/FsM4qikxUEo= X-OriginatorOrg: analogixsemi.com X-MS-Exchange-CrossTenant-Network-Message-Id: a114aa6b-a981-4a86-405b-08da00d62afe X-MS-Exchange-CrossTenant-AuthSource: BY5PR04MB6739.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2022 07:35:07.1915 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b099b0b4-f26c-4cf5-9a0f-d5be9acab205 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: FGchbgmBlXFyZ3Uhw+ijku65j+6rHrGJ3BthqDkg2xdDUb4+JCELoNsR6mFN/JHiUSSmVew6JBZvFwL8VPkCnw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR04MB6592 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org As for convenience use TCPCI register definition, move tcpci.h to include/linux/usb/ directory. Signed-off-by: Xin Ji --- V7 -> V8: Fix Guanter's comment, remove unnecessary explain. --- drivers/usb/typec/tcpm/tcpci.c | 3 +-- drivers/usb/typec/tcpm/tcpci_maxim.c | 3 +-- drivers/usb/typec/tcpm/tcpci_mt6360.c | 3 +-- drivers/usb/typec/tcpm/tcpci_rt1711h.c | 2 +- {drivers/usb/typec/tcpm => include/linux/usb}/tcpci.h | 1 + 5 files changed, 5 insertions(+), 7 deletions(-) rename {drivers/usb/typec/tcpm => include/linux/usb}/tcpci.h (99%) diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c index e07d26a3cd8e..9c907296596f 100644 --- a/drivers/usb/typec/tcpm/tcpci.c +++ b/drivers/usb/typec/tcpm/tcpci.c @@ -13,11 +13,10 @@ #include #include #include +#include #include #include -#include "tcpci.h" - #define PD_RETRY_COUNT_DEFAULT 3 #define PD_RETRY_COUNT_3_0_OR_HIGHER 2 #define AUTO_DISCHARGE_DEFAULT_THRESHOLD_MV 3500 diff --git a/drivers/usb/typec/tcpm/tcpci_maxim.c b/drivers/usb/typec/tcpm/tcpci_maxim.c index df2505570f07..4b6705f3d7b7 100644 --- a/drivers/usb/typec/tcpm/tcpci_maxim.c +++ b/drivers/usb/typec/tcpm/tcpci_maxim.c @@ -11,11 +11,10 @@ #include #include #include +#include #include #include -#include "tcpci.h" - #define PD_ACTIVITY_TIMEOUT_MS 10000 #define TCPC_VENDOR_ALERT 0x80 diff --git a/drivers/usb/typec/tcpm/tcpci_mt6360.c b/drivers/usb/typec/tcpm/tcpci_mt6360.c index f1bd9e09bc87..9e0338bce7ef 100644 --- a/drivers/usb/typec/tcpm/tcpci_mt6360.c +++ b/drivers/usb/typec/tcpm/tcpci_mt6360.c @@ -11,10 +11,9 @@ #include #include #include +#include #include -#include "tcpci.h" - #define MT6360_REG_VCONNCTRL1 0x8C #define MT6360_REG_MODECTRL2 0x8F #define MT6360_REG_SWRESET 0xA0 diff --git a/drivers/usb/typec/tcpm/tcpci_rt1711h.c b/drivers/usb/typec/tcpm/tcpci_rt1711h.c index b56a0880a044..3291ca4948da 100644 --- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c +++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c @@ -10,9 +10,9 @@ #include #include #include +#include #include #include -#include "tcpci.h" #define RT1711H_VID 0x29CF #define RT1711H_PID 0x1711 diff --git a/drivers/usb/typec/tcpm/tcpci.h b/include/linux/usb/tcpci.h similarity index 99% rename from drivers/usb/typec/tcpm/tcpci.h rename to include/linux/usb/tcpci.h index b2edd45f13c6..20c0bedb8ec8 100644 --- a/drivers/usb/typec/tcpm/tcpci.h +++ b/include/linux/usb/tcpci.h @@ -9,6 +9,7 @@ #define __LINUX_USB_TCPCI_H #include +#include #define TCPC_VENDOR_ID 0x0 #define TCPC_PRODUCT_ID 0x2 From patchwork Tue Mar 8 07:34:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Ji X-Patchwork-Id: 12773187 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55823C433F5 for ; Tue, 8 Mar 2022 07:35:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344599AbiCHHg0 (ORCPT ); Tue, 8 Mar 2022 02:36:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241703AbiCHHgY (ORCPT ); Tue, 8 Mar 2022 02:36:24 -0500 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2102.outbound.protection.outlook.com [40.107.223.102]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9D373DA7E; Mon, 7 Mar 2022 23:35:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XuegMAh9Oif1g2XgZ6iW/7lnhaRpifSF021yqvXO14sZBlYpkRbfOQD9dLIkSELnKx5tbxQlb+AEvJr5tt57DQIQKjTQDrHwXLcCnpt2Fxaw7VakJknBhMN/Kbc3lHobT9haMV7/58uWhVLBP7L0mSvHfpVf1qUnbuc3VEZpJzLJa9Pj5ZntwIlb1iMbxlecnDAnEUjzKOP6oIk6VEVGm5e9snFNKSULht90Y6zSLYRAL2gkrGxEchipoXcjaReZRsA0uFvHwIIueG0B+Rk/9JJCutqdjD4HRUapw2hvmeJ1t8cVbdxJnxrHIM1grKm9zSkiVT0Hitl9t6GgUo6v0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=3AE8IR/Q35SjIum4hi0AsFqvQnEf1l/8fXca+rNHjMk=; b=XInvlrWb8XrhkmeuzCBOveMKr95sc/3DmHp7pHmEdwihIK7z+nJnzzjjv4Fpz+iqSZLkwB2PyYqrtcLNol6yN3Holrmfc11vzzOavlhy6mNhXOakQti2AaWsEkV5FCHIb4ZhjY8bSneHEG/y/96+UOnsWVfFkoVUwON7Zu+nuL2/yRhpPQpFZ58cFqZFF3oiVVKxaL0+ii7BUS0H9Lcr/PGNFDU0PSuPHvZFZI0DryGhIwRN15e86w1Aks91B5WXrR9poYEx/YCEyY/LOTKB/xA4hV9Ys0FsG7ogmqP6UJb7gWE47A/PkKwjqXvLBqPxAPxeMIF44CpIiBAFm+R98Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=analogixsemi.com; dmarc=pass action=none header.from=analogixsemi.com; dkim=pass header.d=analogixsemi.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Analogixsemi.onmicrosoft.com; s=selector2-Analogixsemi-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3AE8IR/Q35SjIum4hi0AsFqvQnEf1l/8fXca+rNHjMk=; b=tvlkaoH6ZH/mAE+Zs0E6krS8izDArFjtetbbOUJS50v3ScOvQNAyLWBfTr9t3SOx4sJuywnyGCdEDJCbYQAJRhQGgLyP47+inkyhG3wwYNibD9TGXsGZcVN+THQuY8Vupi8cndvfBxPU1NYLuRaToEEtDekLSMONItWpiOV4zRY= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=analogixsemi.com; Received: from BY5PR04MB6739.namprd04.prod.outlook.com (2603:10b6:a03:229::8) by MWHPR04MB1152.namprd04.prod.outlook.com (2603:10b6:300:79::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Tue, 8 Mar 2022 07:35:25 +0000 Received: from BY5PR04MB6739.namprd04.prod.outlook.com ([fe80::a865:6d10:c4a9:1142]) by BY5PR04MB6739.namprd04.prod.outlook.com ([fe80::a865:6d10:c4a9:1142%9]) with mapi id 15.20.5038.027; Tue, 8 Mar 2022 07:35:24 +0000 From: Xin Ji To: Greg Kroah-Hartman , Rob Herring , Xin Ji Cc: bliang@analogixsemi.com, qwen@analogixsemi.com, jli@analogixsemi.com, Rob Herring , linux-usb@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 2/3] dt-bindings: usb: Add analogix anx7411 PD binding Date: Tue, 8 Mar 2022 15:34:29 +0800 Message-Id: <20220308073431.1217890-2-xji@analogixsemi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308073431.1217890-1-xji@analogixsemi.com> References: <20220308073431.1217890-1-xji@analogixsemi.com> X-ClientProxiedBy: SG2PR01CA0197.apcprd01.prod.exchangelabs.com (2603:1096:4:189::8) To BY5PR04MB6739.namprd04.prod.outlook.com (2603:10b6:a03:229::8) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 44afb967-ae6e-49aa-ed80-08da00d63560 X-MS-TrafficTypeDiagnostic: MWHPR04MB1152:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xPcSVdQwo/AtopYUzGwQ9lbtlHrLot2oVlpXFMQs4umAJ3MHMcS5IlHNOuUWyMIX+VRs9ghqR8GuqKTBJdFbqBMVSTaFXfW2uWDxGtmV9pPH+l0ZwuhE7mBglyVZWXqvZmslsqBK6FAiXLlElA776hinlBU66D+Njk5cqoaB315SjcBVfnukHN+S7/IvJxR1QakZJQC0d1EAxByQHujcpHNlPpzsOK165ls06Uq6K6tl61TC2OY3tjT9+VHb4U36ePP2qb6VW4U3hbJcxTNL7Rith70mV9zI5cBKWiVo8Jwkqj4bzIq6x+mS1vcKzKlO88rAe1HUQ30Q3moWhZVOcXq3RnMFuSIQvkIbm31VDyf4l34Ov88DtwQsA7b5xDbC3tQmsBek1vdExZIY8SnNFgLE35dvyQhHYpQwUh7PxzZlJaGmbfl/7aUQNTDbYelHMlIC/StgV/o3l2cZVN37sM6Qosjc8dzbAZyPUvHcYwRPxbfArsGjRh9MKyvb2MdG6HzrTcOzDdt+sU7X9QCrhbKIDHyP/nKpxs4WL0dn8dVyrOQFnDvl84CfiiLJifu7VpvHadNmIqTIEL4AdtalsEDOjehuPo5aLWAwXpzYGWxFGwuVFqQbF+Jeu7JuTJjKZjFW98GB1JAjozdVAiS3jS2eMMCe28+WaAVkiRGFZMZlhqu5C50YzGfEu/UjZHsSO/UAlg71Ltd38MEWvwjQhz4GgbZDr/CCUvR14NXUuT/x6Yp0YnQ3AqDNM9kadVfw5wLjhWcS0xwfXBphT7uUCkiznaPX6bsxdk4D3Fi5Wcw= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR04MB6739.namprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(5660300002)(6506007)(498600001)(55236004)(52116002)(86362001)(8936002)(2616005)(66556008)(6486002)(7049001)(2906002)(1076003)(6512007)(186003)(26005)(4326008)(66476007)(8676002)(66946007)(38100700002)(38350700002)(110136005)(36756003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XWvxk1ZA0buACPRA38uptJ/FfAvJP9m5787PzkZ9Xrf68kqdaAPaRgDdUBCTodaQ7Q1FYRV0TnaxwAfOxJ+u58xm9k4dku3S+Jr+gmHAUFH+KIaB9Eu2R6rgMIrrjxcqzF7R0UqJkDI2uTGFjuV3PxVDYuXCWrrycbcmoJXIQfpqjU34cwhfkuffTX8SICAyczunAuiMGWTJYkgUPTWyBcSIq18UQ3MRVrJ4ivgMbrOk+QTSnWmcE8FPORrNjfo/cYJVD9Ya12aKa+gR+QNSNF5aaIC5IcmqvlVvq/Fe6VVPbDRkq2FBQmDxAXkiGTfXtg8dtNZztAYSqOK0M7GzjQxLAyeZG0VwzIdr5ucI2QV8GspbUw8zR/xTjF0FKdACPzskkab6fBP4N+obfXNRGvqRhrjY6rXMTejsA04LqeVTJ6HKF8feHUJv9qjhkyGotbY8TPIxm4dZhMeN9RjC4Vxf3oxWbhmGpl0SA9JHtGHqyspASZVHiowcWAjwa+DqiFGW3oUU1E7esOc5KlOS0qZtCVT1L+9MOJ6jsg27BVXx1SW0RRldcPC8hIrz1C7gaqnB9xQPAHPr+S5h9qWtmHP83zlOphSHbGXzVFf2wSm17qQvw4SVFwPzv0blMQdR/uOU2rhgxSbcCjmNawELEXBKaSAljWgNDgcwVNTAByg7ko5dcTxUH86rPFvdCHMnTC6DOu4KJJ4F1rUDLLIdSKuaRUOhssKw8vZ9q7n/8n4D8vFWN/HNZzoK8bnj2OsvekFdWJwHT66kt1vn+zOMvan9nAppW/vMNaw68wV08W1p1LbWSdSIExgoLWnvbDPvbaCOEF6XNQQGIN7KE7Ldll+q95lUqcdw+U+zlwISO5GcFZ5uDJEW0BD96pPN9zcboIQq2F19HUfoyR0GwwJ1nVywxBFKNoh4WNCSI8FDaDQspuWCle5VNeYoPjcVw0xIhG2DFYU++6g/e/rjmRsMDE1IXWxL5gCmnlvOlY4TaYenFoUkL5LGLP5Wh2mTqrZXybGKnfZsqO5PhqOuSViHBtr/pP9m2YiXMdxzCLm9QBlV++bgATqoCkO94XeCARwYlRfvO9vAZtLzq3ef9q9pOyb46MdD5vtbTvd15YsuD3tQhEpigZtMyv2nz+oDU5JwWp+5uwHNRW9nfuWf6/qiikCciSSLpf+IrnLgQ6iSaNew/uloCUY83vBF1d/nYAR8dXBh+qUZS+5QjVke8rAMjZAtqCDOMW3uq2F/Ez+C8yGipRNPaTiJGcW1imgKi4X38PW0a22Qsdb1uhG8QLHlRQjlCyw4kkhbFGUVKmL47cy2DAVg9X/Po0qU+DMBu5BSUEdbkcBH2+p6PYRQC+W56IrpwfvZYb+h4xEY1k07Kb53Fk6Yux/8q1cz48AI4GBj5TBTktEf5FYCr4SxUcWObmtsinp+egq9OCveRNF7ERanwyGe6h470/WNHiHr61FVcuKpVJHQZEAH3AUPEl2ObPAxSktYGgMWEAf5dqUVoPLtFBebVUSkW7q0D8dMPCGpiP36PylhCJ+L4C8DQg6tUHd0RBJG6sM4GC+Ph96am2GrME+uXtKSjuSb2Ck/+kdD9q4wiWDb6AGvpk0IIzvqpxjvJKLx2smarsTmcMGXQu8= X-OriginatorOrg: analogixsemi.com X-MS-Exchange-CrossTenant-Network-Message-Id: 44afb967-ae6e-49aa-ed80-08da00d63560 X-MS-Exchange-CrossTenant-AuthSource: BY5PR04MB6739.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2022 07:35:24.6141 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b099b0b4-f26c-4cf5-9a0f-d5be9acab205 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Klz0cdiKZSbP2TRzDaRE8on7vhSO5aZEDsHZ2+zxhkosGpKGuKOBCbdC2STEm6B4Fwe7zNy8pI/Yd31Yjkx+AQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR04MB1152 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add analogix PD chip anx7411 device binding Reviewed-by: Rob Herring Signed-off-by: Xin Ji --- .../bindings/usb/analogix,anx7411.yaml | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/analogix,anx7411.yaml diff --git a/Documentation/devicetree/bindings/usb/analogix,anx7411.yaml b/Documentation/devicetree/bindings/usb/analogix,anx7411.yaml new file mode 100644 index 000000000000..c5c6d5a9dc17 --- /dev/null +++ b/Documentation/devicetree/bindings/usb/analogix,anx7411.yaml @@ -0,0 +1,76 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: "http://devicetree.org/schemas/usb/analogix,anx7411.yaml#" +$schema: "http://devicetree.org/meta-schemas/core.yaml#" + +title: Analogix ANX7411 Type-C controller bindings + +maintainers: + - Xin Ji + +properties: + compatible: + enum: + - analogix,anx7411 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + connector: + type: object + + allOf: + - $ref: ../connector/usb-connector.yaml + + properties: + compatible: + const: usb-c-connector + + power-role: true + + data-role: true + + try-power-role: true + + required: + - compatible + +required: + - compatible + - reg + - connector + +additionalProperties: false + +examples: + - | + #include + i2c1 { + #address-cells = <1>; + #size-cells = <0>; + + typec: anx7411@2C { + compatible = "analogix,anx7411"; + reg = <0x2C>; + interrupts = <8 IRQ_TYPE_EDGE_FALLING>; + interrupt-parent = <&gpio0>; + + typec_con: connector { + compatible = "usb-c-connector"; + power-role = "dual"; + data-role = "dual"; + try-power-role = "source"; + + port { + typec_con_ep: endpoint { + remote-endpoint = <&usbotg_hs_ep>; + }; + }; + }; + }; + }; +... From patchwork Tue Mar 8 07:34:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Ji X-Patchwork-Id: 12773188 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4376AC433F5 for ; Tue, 8 Mar 2022 07:35:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344616AbiCHHgn (ORCPT ); Tue, 8 Mar 2022 02:36:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344613AbiCHHgm (ORCPT ); Tue, 8 Mar 2022 02:36:42 -0500 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2119.outbound.protection.outlook.com [40.107.243.119]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFA8F3DDC6; Mon, 7 Mar 2022 23:35:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jjRLmRf4pEkAh5zt1F7qK6PljX8xjoyPpUXpDCjlvud7ahRHoKrzrzDeqr5iysiPYWPtM0JOKQI+4Dog5bqw27tNRYouB+n42FyM6v8abDSrKSx4u05IlrLiCztmBOexK7hXlZG+C+RzeD/p8BiZBvE8gj560DLBbgtGIrtTBeGepssiPwTbR4MWAHoMoclUpDL93V024YJwgIWvwgDX8JBgu3pszjcFvG0qPtRVb4bYqrVHEqTLyvOHrCVEBSYPOc8hFzRow2t6rjBxGcsMB1WMrXzNPSYnx4ZUpJoJK5AJ+IUtIqUSOfrBBiaZpVZp/iozh8E1NOsl5msOfOQIOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ekMIIyA1/k9gTIhWDWn8dT0FBcxZchNUtGZuU2teqA4=; b=fMfALuiJWWmFVH5TTdKOW8m9ffOVc/d6ch59Uum01+gtzJw9nVcx7l4mkedOpgcS6AA7RLIBfxEqqxNbgayNgTr8hpDZRVfI6CninscziXNcpMRn/LOuqMIRZ5AjgyIWftJC9/FcRv/orCLOZmT7GT291M08COFNfZNh5lSyEW/kJyVxkx1DO02jSx0ht3OqMHqE/wvXGU+CQ9eGonbxHXWPcB798H6XGGJ4G2dFToCsHBQzkG66SBD4U1p74U/CYQAUBgMwPpjVGiQBWJPvaHaCI7jx4Av2U/QtTFDbuBOljh/x1aHbN6iYhSkMrM4yFjWo6g5Qa+mRAvFRUlR2aw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=analogixsemi.com; dmarc=pass action=none header.from=analogixsemi.com; dkim=pass header.d=analogixsemi.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Analogixsemi.onmicrosoft.com; s=selector2-Analogixsemi-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ekMIIyA1/k9gTIhWDWn8dT0FBcxZchNUtGZuU2teqA4=; b=Jq7IuHJGk+6pdpxHcKAZwqzyy+za4BimfdbUPen03ialjnztEgvOT18P0B1gqtYo3/Jof7stYDo6M3OotZ0liAFTXHQXRt/xskR+JJV6bsLac5Q2F5JLngsiE72YNGKTod2bz79W93B1wdlK4qTFFLUTsdvB8hrj7mo3TFUURvk= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=analogixsemi.com; Received: from BY5PR04MB6739.namprd04.prod.outlook.com (2603:10b6:a03:229::8) by MWHPR04MB1152.namprd04.prod.outlook.com (2603:10b6:300:79::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Tue, 8 Mar 2022 07:35:41 +0000 Received: from BY5PR04MB6739.namprd04.prod.outlook.com ([fe80::a865:6d10:c4a9:1142]) by BY5PR04MB6739.namprd04.prod.outlook.com ([fe80::a865:6d10:c4a9:1142%9]) with mapi id 15.20.5038.027; Tue, 8 Mar 2022 07:35:41 +0000 From: Xin Ji To: Heikki Krogerus , Greg Kroah-Hartman Cc: bliang@analogixsemi.com, qwen@analogixsemi.com, jli@analogixsemi.com, Xin Ji , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v8 3/3] usb: typec: anx7411: Add Analogix PD ANX7411 support Date: Tue, 8 Mar 2022 15:34:30 +0800 Message-Id: <20220308073431.1217890-3-xji@analogixsemi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308073431.1217890-1-xji@analogixsemi.com> References: <20220308073431.1217890-1-xji@analogixsemi.com> X-ClientProxiedBy: SG2PR0601CA0009.apcprd06.prod.outlook.com (2603:1096:3::19) To BY5PR04MB6739.namprd04.prod.outlook.com (2603:10b6:a03:229::8) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: df00dcd3-2766-43e8-9330-08da00d63f03 X-MS-TrafficTypeDiagnostic: MWHPR04MB1152:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ayM3WlOTkFhETKH0Rf43OCa+i/1tULOR/fmK/5YUqYPCrYLBcG6efeuUGiQq6UAc8byezTSajvSn+KaiAb0JQUiZ9SYm69z0FN6JoeK/F0qqtrdxype9RmSJaQPrQI/35iFJgeIqmeb73HqNiNwBTTVLV0K6fF5Hg75ViyyALzIg1D9Y8Hv+fDOav7Sti74TrpIchz58zm8QmW4BxcUISfz2UIPWEtXvBHToE0W2vLbhzwKHhout2fWDvwzHxQKQHcm9fPVq8XYCxlOyFEezyAhv982BiJXo371eSfXtWWsO5TQB6cDp4XG4LPmbbKpfB9yl0N++YQFmujXd3vXrPtfyjQ8qXU4SKBiK8q9biwHlkveRT8hBlIaMfxzF4c1n1Gj8BgUjVZbqw5RL+nss1pW9wzBVgA5z6XRgQ4oBcprivf6lJKOOdFNQk9rWvHX3rBja1MbO8NSzbAQ6i2VuhwIvYCREUrG3wPL+jiR/3gnWFeZFD0jPPSLe6F+ncGRc2P/rNpJREKfwxVCnW/XRu5+lCjPM4xXRFQ1igrnnCEGMp+l+8VwoZFgAXmB9zFBk3LVuJwqFqek80jJSxIH97FnV1s8DBez30mtbfLXVF+1v5TtxIsCYFa5NB0M6QNFc/Nlc/qpedtvWImURAdO72ax6v0yPjTgla/aHJkEB7l3VwF+UH+AGWST4FrJaQ1uf8QG/iwDzbECM1jSnS9auOw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR04MB6739.namprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(5660300002)(6506007)(498600001)(55236004)(52116002)(86362001)(8936002)(2616005)(66556008)(30864003)(6666004)(6486002)(2906002)(1076003)(6512007)(186003)(26005)(4326008)(66476007)(8676002)(66946007)(38100700002)(38350700002)(110136005)(36756003)(83380400001)(579004);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: My30Sez161Uofq16WL7cKX51lNCsD4v/NcxNGUypn8SoDYlziU37w6c7Gvt1c9K9JTKIZ9itg3V+knMzvpqhAJUzqi2/Ekn2jTto+6Q0BYUouCPJOQx1N8S2uK4nqJcc4yKCSRw0m6If6B1jLWmoG63me6kAR6qPmjOd3hpSacNHZ+MVIRx3K4EM7CSnRZtsqhY8pVzwpvIhD1lr+UxWpOW4miyj8VaL4zrEbYrbcqvu1dMGPxsJasQRIRS7b7wp3aqe2z6Z3dB8TW3zd/diiz+sjBoGLbKANmmp3Av6mdDdJ26mkMVhVtg6Q9pIpZNiN/FqHRa3GR6u3LSmEgvGgTNL6zwd/ku6O94HCg0dBnfKsd0zfFxrAjp2/yUg5cyp1Hw75VuGvUMM7XoIUO5yzYWyuIq2enDDjyuOKRyGQu1n/z01ZBl/d12UV3pmMkRsoH4Evhz5rKFeFfBye3+E6sPmPQRhoP49H0htlchJ1l/IVVlORctUFoL9fUQuXfvTu3CQVnk0TKwxneNG6ynPs2XbbAU1MsTHNYGqo9lmm0wfWI9jVTPos3vNtu+TP9++8NIWLBGIMqF60alc7GCxnzA9hYxX0+qD7lHP5HNW9mYKvMN4W+bR5S3adpJdf/zsmghXsJK1ieiAHCRnB/vq0wCq+cdg09s8jrdAnjRs/JefUdP1haAec+2oX0nY6Nt9VDkiyCwmqy3u6iUJcpM2B+chLiZxbq5TSlEC2VjkvoQDBz6+q4wJ34ynKvuOnglkwAsbwR8CqbF2P+IOP0QQR259xxAdmPPx3FOd2ZmCjK3sA31fXpqR55bfCebWATL22SYVxJrbT7z2232Gk6WjRBO/SCbJfvzjuUSZEJmOo2dYJv77YWtcccqJo2rhD+5QK/ciJKXRC6YitZQEi/65+UmHgvS4BeOJh4piRpIKi3KHSlraQrBNHSqZuFotgQmJ6w5g1nb22+mA3L6pM93p1XHTsT/MYTWnqwxhURCvY7L7npvh9HO9JJW4fyRFzuq8kM7D9peE/cp4mNhwsjDT8G1Kf2kqMEt2aDwgBmkgMjMhMGulhBsNeRvOiUDc+B/BWuNbnFbhQ/CO29UFsPDH3qmtaAECoAXf67tijT3Dbj4rPo/9cAxRxonGelZ4mnKDz8tZJCN7zT5C5V45r65WZC+6RJ11S+4KEcMZzEtTww8YiLTbyiIVR0APA5oTqJF1ykd1J4+Qg+bwc5rRxilxT8XWtQSkZ9Bt0xms+01oBJRYlk1K1A1q0iXRDQIrpSTuTOu1ky1N/9ZNel1evUgWjl+4dB52DrxxtHzsdUEjFEznJHYCWyRlCJ7SIbPsH5Y0MKqGKbdvxGyPm5f8QFDM+evHMKJN5sYvyJRgVwoFfO4XjHfel+A9tQsnlHLGhgBRtMuY7UqUZyrcYKZMKm8I/u2zATD7cIjduMittW32Sz8ZB0KbtaK8EUxj3bLWIgVV90FgQh6egOtZgDXDde5oyFcsGOzHX6QQHtDlBzmIm9VnH1LIp2mriJLC80OgemE2bXiKx4qvufWJZ4prnz6RUINt4ywfCbJuS7QKcoj2j+ZiDrXQ/lHbKWnj9WBbSYp/rJgIeKasjtkL2BHglIQLX/1np+fesV4vhQ+T8itxdTU= X-OriginatorOrg: analogixsemi.com X-MS-Exchange-CrossTenant-Network-Message-Id: df00dcd3-2766-43e8-9330-08da00d63f03 X-MS-Exchange-CrossTenant-AuthSource: BY5PR04MB6739.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2022 07:35:40.9982 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b099b0b4-f26c-4cf5-9a0f-d5be9acab205 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: RdxFQJTWqb59vUw73fEJNcA4+HkBfTaG9+vy/U9TTsuKCJeiS8rl7P+Z+yIBwNjwjN1zwej4y3NYYXufkcPKgg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR04MB1152 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add driver for analogix ANX7411 USB Type-C DRP port controller. Signed-off-by: Xin Ji --- V6 -> V7: Fix Heikki's comment Rebase on Greg's latest usb-next branch Move tcpci.h to include/linux/usb/ Remove double definition V5 -> V6: Fix Heikki's comment V4 -> V5: Fix Greg h-k comment, remove DEBUG define V3 -> V4: Fix compiling waring V2 -> V3: Add changelog history V1 -> V2: Fix compiling warning issue --- drivers/usb/typec/Kconfig | 11 + drivers/usb/typec/Makefile | 1 + drivers/usb/typec/anx7411.c | 1327 +++++++++++++++++++++++++++++++++++ drivers/usb/typec/anx7411.h | 265 +++++++ 4 files changed, 1604 insertions(+) create mode 100644 drivers/usb/typec/anx7411.c create mode 100644 drivers/usb/typec/anx7411.h diff --git a/drivers/usb/typec/Kconfig b/drivers/usb/typec/Kconfig index 8f921213b17d..eaa4c088aafa 100644 --- a/drivers/usb/typec/Kconfig +++ b/drivers/usb/typec/Kconfig @@ -52,6 +52,17 @@ source "drivers/usb/typec/ucsi/Kconfig" source "drivers/usb/typec/tipd/Kconfig" +config TYPEC_ANX7411 + tristate "Analogix ANX7411 Type-C DRP Port controller driver" + depends on I2C + depends on USB_ROLE_SWITCH + help + Say Y or M here if your system has Analogix ANX7411 Type-C DRP Port + controller driver. + + If you choose to build this driver as a dynamically linked module, the + module will be called anx7411.ko. + config TYPEC_RT1719 tristate "Richtek RT1719 Sink Only Type-C controller driver" depends on USB_ROLE_SWITCH || !USB_ROLE_SWITCH diff --git a/drivers/usb/typec/Makefile b/drivers/usb/typec/Makefile index 43626acc0aaf..e4e4db55a55d 100644 --- a/drivers/usb/typec/Makefile +++ b/drivers/usb/typec/Makefile @@ -6,6 +6,7 @@ obj-$(CONFIG_TYPEC) += altmodes/ obj-$(CONFIG_TYPEC_TCPM) += tcpm/ obj-$(CONFIG_TYPEC_UCSI) += ucsi/ obj-$(CONFIG_TYPEC_TPS6598X) += tipd/ +obj-$(CONFIG_TYPEC_ANX7411) += anx7411.o obj-$(CONFIG_TYPEC_HD3SS3220) += hd3ss3220.o obj-$(CONFIG_TYPEC_QCOM_PMIC) += qcom-pmic-typec.o obj-$(CONFIG_TYPEC_STUSB160X) += stusb160x.o diff --git a/drivers/usb/typec/anx7411.c b/drivers/usb/typec/anx7411.c new file mode 100644 index 000000000000..ede39dea8366 --- /dev/null +++ b/drivers/usb/typec/anx7411.c @@ -0,0 +1,1327 @@ +// SPDX-License-Identifier: GPL-2.0-only + +/* + * Copyright(c) 2022, Analogix Semiconductor. All rights reserved. + * + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "anx7411.h" + +static u8 snk_identity[] = { + LOBYTE(VID_ANALOGIX), HIBYTE(VID_ANALOGIX), 0x00, 0x82, /* snk_id_hdr */ + 0x00, 0x00, 0x00, 0x00, /* snk_cert */ + 0x00, 0x00, LOBYTE(PID_ANALOGIX), HIBYTE(PID_ANALOGIX), /* 5snk_ama */ +}; + +static u8 dp_caps[4] = {0xC6, 0x00, 0x00, 0x00}; + +static int anx7411_reg_read(struct i2c_client *client, + u8 reg_addr) +{ + return i2c_smbus_read_byte_data(client, reg_addr); +} + +static int anx7411_reg_block_read(struct i2c_client *client, + u8 reg_addr, u8 len, u8 *buf) +{ + return i2c_smbus_read_i2c_block_data(client, reg_addr, len, buf); +} + +static int anx7411_reg_write(struct i2c_client *client, + u8 reg_addr, u8 reg_val) +{ + return i2c_smbus_write_byte_data(client, reg_addr, reg_val); +} + +static int anx7411_reg_block_write(struct i2c_client *client, + u8 reg_addr, u8 len, u8 *buf) +{ + return i2c_smbus_write_i2c_block_data(client, reg_addr, len, buf); +} + +static struct anx7411_i2c_select anx7411_i2c_addr[] = { + {TCPC_ADDRESS1, SPI_ADDRESS1}, + {TCPC_ADDRESS2, SPI_ADDRESS2}, + {TCPC_ADDRESS3, SPI_ADDRESS3}, + {TCPC_ADDRESS4, SPI_ADDRESS4}, +}; + +static int anx7411_detect_power_mode(struct anx7411_data *ctx) +{ + int ret; + int mode; + + ret = anx7411_reg_read(ctx->spi_client, REQUEST_CURRENT); + if (ret < 0) + return ret; + + ctx->typec.request_current = ret * CURRENT_UNIT; /* 50ma per unit */ + + ret = anx7411_reg_read(ctx->spi_client, REQUEST_VOLTAGE); + if (ret < 0) + return ret; + + ctx->typec.request_voltage = ret * VOLTAGE_UNIT; /* 100mv per unit */ + + if (ctx->psy_online == ANX7411_PSY_OFFLINE) { + ctx->psy_online = ANX7411_PSY_FIXED_ONLINE; + ctx->usb_type = POWER_SUPPLY_USB_TYPE_PD; + power_supply_changed(ctx->psy); + } + + if (!ctx->typec.cc_orientation_valid) + return 0; + + if (ctx->typec.cc_connect == CC1_CONNECTED) + mode = CC1_RP(ctx->typec.cc_status); + else + mode = CC2_RP(ctx->typec.cc_status); + if (mode) { + typec_set_pwr_opmode(ctx->typec.port, mode - 1); + return 0; + } + + typec_set_pwr_opmode(ctx->typec.port, TYPEC_PWR_MODE_PD); + + return 0; +} + +static int anx7411_register_partner(struct anx7411_data *ctx, + int pd, int accessory) +{ + struct typec_partner_desc desc; + + if (ctx->typec.partner) + return 0; + + desc.usb_pd = pd; + desc.accessory = accessory; + desc.identity = NULL; + ctx->typec.partner = typec_register_partner(ctx->typec.port, &desc); + if (IS_ERR(ctx->typec.partner)) { + ctx->typec.partner = NULL; + return PTR_ERR(ctx->typec.partner); + } + + return 0; +} + +static int anx7411_detect_cc_orientation(struct anx7411_data *ctx) +{ + int ret; + int cc1_rd, cc2_rd; + int cc1_ra, cc2_ra; + int cc1_rp, cc2_rp; + + ret = anx7411_reg_read(ctx->spi_client, CC_STATUS); + if (ret < 0) + return ret; + + ctx->typec.cc_status = ret; + + cc1_rd = ret & CC1_RD ? 1 : 0; + cc2_rd = ret & CC2_RD ? 1 : 0; + cc1_ra = ret & CC1_RA ? 1 : 0; + cc2_ra = ret & CC2_RA ? 1 : 0; + cc1_rp = CC1_RP(ret); + cc2_rp = CC2_RP(ret); + + /* Debug cable, nothing to do */ + if (cc1_rd && cc2_rd) { + ctx->typec.cc_orientation_valid = 0; + anx7411_register_partner(ctx, 0, TYPEC_ACCESSORY_DEBUG); + return 0; + } + + if (cc1_ra && cc2_ra) { + ctx->typec.cc_orientation_valid = 0; + anx7411_register_partner(ctx, 0, TYPEC_ACCESSORY_AUDIO); + return 0; + } + + ctx->typec.cc_orientation_valid = 1; + + anx7411_register_partner(ctx, 1, TYPEC_ACCESSORY_NONE); + + if (cc1_rd || cc1_rp) { + typec_set_orientation(ctx->typec.port, + TYPEC_ORIENTATION_NORMAL); + ctx->typec.cc_connect = CC1_CONNECTED; + } + + if (cc2_rd || cc2_rp) { + typec_set_orientation(ctx->typec.port, + TYPEC_ORIENTATION_REVERSE); + ctx->typec.cc_connect = CC2_CONNECTED; + } + + return 0; +} + +static int anx7411_set_mux(struct anx7411_data *ctx, int pin_assignment) +{ + int mode = TYPEC_STATE_SAFE; + + switch (pin_assignment) { + case SELECT_PIN_ASSIGMENT_U: + /* default 4 line USB 3.1 */ + mode = TYPEC_STATE_MODAL; + break; + case SELECT_PIN_ASSIGMENT_C: + case SELECT_PIN_ASSIGMENT_E: + /* 4 line DP */ + mode = TYPEC_STATE_SAFE; + break; + case SELECT_PIN_ASSIGMENT_D: + /* 2 line DP, 2 line USB */ + mode = TYPEC_MODE_USB3; + break; + default: + mode = TYPEC_STATE_SAFE; + break; + } + + ctx->typec.pin_assignment = pin_assignment; + + return typec_set_mode(ctx->typec.port, mode); +} + +static void anx7411_set_usb_role(struct anx7411_data *ctx, enum usb_role role) +{ + if (!ctx->typec.role_sw) + return; + + usb_role_switch_set_role(ctx->typec.role_sw, role); +} + +static int anx7411_data_role_detect(struct anx7411_data *ctx) +{ + int ret; + + ret = anx7411_reg_read(ctx->spi_client, SYSTEM_STSTUS); + if (ret < 0) + return ret; + + ctx->typec.data_role = (ret & DATA_ROLE) ? TYPEC_HOST : TYPEC_DEVICE; + ctx->typec.vconn_role = (ret & VCONN_STATUS) ? TYPEC_SOURCE : TYPEC_SINK; + + typec_set_data_role(ctx->typec.port, ctx->typec.data_role); + typec_set_vconn_role(ctx->typec.port, ctx->typec.vconn_role); + + if (ctx->typec.data_role == TYPEC_HOST) + anx7411_set_usb_role(ctx, USB_ROLE_HOST); + else + anx7411_set_usb_role(ctx, USB_ROLE_DEVICE); + + return 0; +} + +static int anx7411_power_role_detect(struct anx7411_data *ctx) +{ + int ret; + + ret = anx7411_reg_read(ctx->spi_client, SYSTEM_STSTUS); + if (ret < 0) + return ret; + + ctx->typec.power_role = (ret & SINK_STATUS) ? TYPEC_SINK : TYPEC_SOURCE; + + if (ctx->typec.power_role == TYPEC_SOURCE) { + ctx->typec.request_current = DEF_1_5A; + ctx->typec.request_voltage = DEF_5V; + } + + typec_set_pwr_role(ctx->typec.port, ctx->typec.power_role); + + return 0; +} + +static int anx7411_cc_status_detect(struct anx7411_data *ctx) +{ + anx7411_detect_cc_orientation(ctx); + anx7411_detect_power_mode(ctx); + + return 0; +} + +static int anx7411_partner_unregister_altmode(struct anx7411_data *ctx) +{ + int i; + + ctx->typec.dp_altmode_enter = 0; + ctx->typec.cust_altmode_enter = 0; + + for (i = 0; i < MAX_ALTMODE; i++) + if (ctx->typec.amode[i]) { + typec_unregister_altmode(ctx->typec.amode[i]); + ctx->typec.amode[i] = NULL; + } + + ctx->typec.pin_assignment = 0; + return 0; +} + +static int anx7411_typec_register_altmode(struct anx7411_data *ctx, + int svid, int vdo) +{ + struct device *dev = &ctx->spi_client->dev; + struct typec_altmode_desc desc; + int i; + + desc.svid = svid; + desc.vdo = vdo; + + for (i = 0; i < MAX_ALTMODE; i++) + if (!ctx->typec.amode[i]) + break; + + desc.mode = i + 1; /* start with 1 */ + + if (i >= MAX_ALTMODE) { + dev_err(dev, "no altmode space for registering\n"); + return -ENOMEM; + } + + ctx->typec.amode[i] = typec_partner_register_altmode(ctx->typec.partner, + &desc); + if (IS_ERR(ctx->typec.amode[i])) { + dev_err(dev, "failed to register altmode\n"); + ctx->typec.amode[i] = NULL; + return PTR_ERR(ctx->typec.amode); + } + + return 0; +} + +static int anx7411_unregister_partner(struct anx7411_data *ctx) +{ + if (ctx->typec.partner) { + typec_unregister_partner(ctx->typec.partner); + ctx->typec.partner = NULL; + } + + return 0; +} + +static int anx7411_update_altmode(struct anx7411_data *ctx, int svid) +{ + int i; + + if (svid == DP_SVID) + ctx->typec.dp_altmode_enter = 1; + else + ctx->typec.cust_altmode_enter = 1; + + for (i = 0; i < MAX_ALTMODE; i++) { + if (!ctx->typec.amode[i]) + continue; + + if (ctx->typec.amode[i]->svid == svid) { + typec_altmode_update_active(ctx->typec.amode[i], true); + typec_altmode_notify(ctx->typec.amode[i], + ctx->typec.pin_assignment, + &ctx->typec.data); + break; + } + } + + return 0; +} + +static int anx7411_register_altmode(struct anx7411_data *ctx, + bool dp_altmode, u8 *buf) +{ + int ret; + int svid; + int mid; + + if (!ctx->typec.partner) + return 0; + + svid = DP_SVID; + if (dp_altmode) { + mid = buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24); + + return anx7411_typec_register_altmode(ctx, svid, mid); + } + + svid = (buf[3] << 8) | buf[2]; + if ((buf[0] & VDM_CMD_AND_ACK_MASK) != (VDM_ACK | VDM_CMD_ENTER_MODE)) + return anx7411_update_altmode(ctx, svid); + + if ((buf[0] & VDM_CMD_AND_ACK_MASK) != (VDM_ACK | VDM_CMD_DIS_MOD)) + return 0; + + mid = buf[4] | (buf[5] << 8) | (buf[6] << 16) | (buf[7] << 24); + + ret = anx7411_typec_register_altmode(ctx, svid, mid); + if (ctx->typec.cust_altmode_enter) + ret |= anx7411_update_altmode(ctx, svid); + + return ret; +} + +static int anx7411_parse_cmd(struct anx7411_data *ctx, u8 type, u8 *buf, u8 len) +{ + struct device *dev = &ctx->spi_client->dev; + u8 cur_50ma, vol_100mv; + + dev_info(dev, "received message: type:0x%.02x, len:%d, buf[0]:%d\n", + type, len, buf[0]); + + switch (type) { + case TYPE_SRC_CAP: + cur_50ma = anx7411_reg_read(ctx->spi_client, REQUEST_CURRENT); + vol_100mv = anx7411_reg_read(ctx->spi_client, REQUEST_VOLTAGE); + dev_info(dev, "get current(%dma), voltage(%dmv), power(%dmw)\n", + cur_50ma * CURRENT_UNIT, vol_100mv * VOLTAGE_UNIT, + cur_50ma * vol_100mv * 5); + + ctx->typec.request_voltage = vol_100mv * VOLTAGE_UNIT; + ctx->typec.request_current = cur_50ma * CURRENT_UNIT; + + ctx->psy_online = ANX7411_PSY_FIXED_ONLINE; + ctx->usb_type = POWER_SUPPLY_USB_TYPE_PD; + power_supply_changed(ctx->psy); + break; + case TYPE_SNK_CAP: + break; + case TYPE_SVID: + break; + case TYPE_SNK_IDENTITY: + break; + case TYPE_GET_DP_ALT_ENTER: + /* DP alt mode enter success */ + if (buf[0]) + anx7411_update_altmode(ctx, DP_SVID); + break; + case TYPE_DP_ALT_ENTER: + /* Update DP altmode */ + anx7411_update_altmode(ctx, DP_SVID); + break; + case TYPE_OBJ_REQ: + anx7411_detect_power_mode(ctx); + break; + case TYPE_DP_CONFIGURE: + anx7411_set_mux(ctx, buf[1]); + break; + case TYPE_DP_DISCOVER_MODES_INFO: + /* Make sure discover modes valid */ + if (buf[0] | buf[1]) + /* Register DP Altmode */ + anx7411_register_altmode(ctx, 1, buf); + break; + case TYPE_VDM: + /* Register other altmode */ + anx7411_register_altmode(ctx, 0, buf); + break; + default: + dev_err(dev, "ignore message(0x%.02x).\n", type); + break; + } + + return 0; +} + +static u8 checksum(struct device *dev, u8 *buf, u8 len) +{ + u8 ret = 0; + u8 i; + + for (i = 0; i < len; i++) + ret += buf[i]; + + return ret; +} + +static int anx7411_read_msg_ctrl_status(struct i2c_client *client) +{ + return anx7411_reg_read(client, CMD_SEND_BUF); +} + +static int anx7411_wait_msg_empty(struct i2c_client *client) +{ + int val; + + return readx_poll_timeout(anx7411_read_msg_ctrl_status, + client, val, (val < 0) || (val == 0), + 2000, 2000 * 150); +} + +static int anx7411_send_msg(struct anx7411_data *ctx, u8 type, u8 *buf, u8 size) +{ + struct device *dev = &ctx->spi_client->dev; + u8 msg[MSG_LEN]; + u8 crc; + int ret; + + if (size) + memcpy(&msg[MSG_RAWDATA], buf, size); + msg[MSG_TYPE] = type; + msg[MSG_HEADER] = size + 1; + + crc = checksum(dev, msg, size + HEADER_LEN); + msg[size + HEADER_LEN] = 0 - crc; + + ret = anx7411_wait_msg_empty(ctx->spi_client); + if (ret) + return ret; + + anx7411_reg_block_write(ctx->spi_client, + CMD_SEND_BUF + 1, size + HEADER_LEN, + &msg[MSG_TYPE]); + return anx7411_reg_write(ctx->spi_client, CMD_SEND_BUF, + msg[MSG_HEADER]); +} + +static int anx7411_process_cmd(struct anx7411_data *ctx) +{ + struct device *dev = &ctx->spi_client->dev; + u8 msg[MSG_LEN]; + u8 len; + u8 crc; + + /* Read message from firmware */ + anx7411_reg_block_read(ctx->spi_client, CMD_RECV_BUF, MSG_LEN, msg); + anx7411_reg_write(ctx->spi_client, CMD_RECV_BUF, 0); + + if (!msg[MSG_HEADER]) + return 0; + + len = msg[MSG_HEADER] & MSG_LEN_MASK; + crc = checksum(dev, msg, len + HEADER_LEN); + if (crc) { + dev_err(dev, "message error crc(0x%.02x)\n", crc); + return -ERANGE; + } + + return anx7411_parse_cmd(ctx, msg[MSG_TYPE], + &msg[MSG_RAWDATA], len - 1); +} + +static void anx7411_translate_payload(struct device *dev, __le32 *payload, + u32 *pdo, int nr, const char *type) +{ + int i; + + if (nr > PDO_MAX_OBJECTS) { + dev_err(dev, "nr(%d) exceed PDO_MAX_OBJECTS(%d)\n", + nr, PDO_MAX_OBJECTS); + + return; + } + + for (i = 0; i < nr; i++) + payload[i] = cpu_to_le32(pdo[i]); +} + +static void anx7411_config(struct anx7411_data *ctx) +{ + struct device *dev = &ctx->spi_client->dev; + struct typec_params *typecp = &ctx->typec; + __le32 payload[PDO_MAX_OBJECTS]; + + /* Config PD FW work under PD 2.0 */ + anx7411_reg_write(ctx->spi_client, PD_REV_INIT, PD_REV20); + anx7411_reg_write(ctx->tcpc_client, FW_CTRL_0, + UNSTRUCT_VDM_EN | DELAY_200MS | + VSAFE1 | FRS_EN); + anx7411_reg_write(ctx->spi_client, FW_CTRL_1, + AUTO_PD_EN | FORCE_SEND_RDO); + + /* Set VBUS current threshold */ + anx7411_reg_write(ctx->tcpc_client, VBUS_THRESHOLD_H, 0xff); + anx7411_reg_write(ctx->tcpc_client, VBUS_THRESHOLD_L, 0x03); + + /* Fix dongle compatible issue */ + anx7411_reg_write(ctx->tcpc_client, FW_PARAM, + anx7411_reg_read(ctx->tcpc_client, FW_PARAM) | + DONGLE_IOP); + anx7411_reg_write(ctx->spi_client, INT_MASK, 0); + + anx7411_reg_write(ctx->spi_client, PD_EXT_MSG_CTRL, 0xFF); + + if (typecp->caps_flags & HAS_SOURCE_CAP) { + anx7411_translate_payload(dev, payload, typecp->src_pdo, + typecp->src_pdo_nr, "source"); + anx7411_send_msg(ctx, TYPE_SRC_CAP, (u8 *)&payload, + typecp->src_pdo_nr * 4); + anx7411_send_msg(ctx, TYPE_SNK_IDENTITY, snk_identity, + sizeof(snk_identity)); + anx7411_send_msg(ctx, TYPE_SET_SNK_DP_CAP, dp_caps, + sizeof(dp_caps)); + } + + if (typecp->caps_flags & HAS_SINK_CAP) { + anx7411_translate_payload(dev, payload, typecp->sink_pdo, + typecp->sink_pdo_nr, "sink"); + anx7411_send_msg(ctx, TYPE_SNK_CAP, (u8 *)&payload, + typecp->sink_pdo_nr * 4); + } + + if (typecp->caps_flags & HAS_SINK_WATT) { + if (typecp->sink_watt) { + anx7411_reg_write(ctx->spi_client, MAX_POWER, + typecp->sink_watt); + /* Set min power to 1W */ + anx7411_reg_write(ctx->spi_client, MIN_POWER, 2); + } + + if (typecp->sink_voltage) + anx7411_reg_write(ctx->spi_client, MAX_VOLTAGE, + typecp->sink_voltage); + } + + if (!typecp->caps_flags) + usleep_range(5000, 6000); + + ctx->fw_version = anx7411_reg_read(ctx->spi_client, FW_VER); + ctx->fw_subversion = anx7411_reg_read(ctx->spi_client, + FW_SUBVER); +} + +static void anx7411_chip_standby(struct anx7411_data *ctx) +{ + anx7411_reg_write(ctx->spi_client, OCM_CTRL_0, + anx7411_reg_read(ctx->spi_client, OCM_CTRL_0) | + OCM_RESET); + anx7411_reg_write(ctx->tcpc_client, ANALOG_CTRL_10, 0x80); + /* Set TCPC to RD and DRP enable */ + anx7411_reg_write(ctx->tcpc_client, + TCPC_ROLE_CTRL, + TCPC_ROLE_CTRL_DRP | + (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC1_SHIFT) | + (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC2_SHIFT)); + + /* Send DRP toggle command */ + anx7411_reg_write(ctx->tcpc_client, TCPC_COMMAND, + TCPC_CMD_LOOK4CONNECTION); + + /* Send TCPC enter standby command */ + anx7411_reg_write(ctx->tcpc_client, TCPC_COMMAND, TCPC_CMD_I2C_IDLE); +} + +static void anx7411_work_func(struct work_struct *work) +{ + int ret; + u8 buf[STATUS_LEN]; + u8 int_change; /* Interrupt change */ + u8 int_status; /* Firmware status update */ + u8 alert0, alert1; /* Interrupt alert source */ + struct anx7411_data *ctx = container_of(work, struct anx7411_data, work); + + mutex_lock(&ctx->lock); + + /* Read interrupt change status */ + ret = anx7411_reg_block_read(ctx->spi_client, INT_STS, STATUS_LEN, buf); + if (ret < 0) { + /* Power standby mode, just return */ + goto unlock; + } + int_change = buf[0]; + int_status = buf[1]; + + /* Read alert register */ + ret = anx7411_reg_block_read(ctx->tcpc_client, ALERT_0, STATUS_LEN, buf); + if (ret < 0) + goto unlock; + + alert0 = buf[0]; + alert1 = buf[1]; + + /* Clear interrupt and alert status */ + anx7411_reg_write(ctx->spi_client, INT_STS, 0); + anx7411_reg_write(ctx->tcpc_client, ALERT_0, alert0); + anx7411_reg_write(ctx->tcpc_client, ALERT_1, alert1); + + if (alert1 & INTP_POW_OFF) { + anx7411_partner_unregister_altmode(ctx); + anx7411_set_usb_role(ctx, USB_ROLE_NONE); + anx7411_unregister_partner(ctx); + ctx->psy_online = ANX7411_PSY_OFFLINE; + ctx->usb_type = POWER_SUPPLY_USB_TYPE_C; + ctx->typec.request_voltage = 0; + ctx->typec.request_current = 0; + power_supply_changed(ctx->psy); + anx7411_chip_standby(ctx); + goto unlock; + } + + if ((alert0 & SOFTWARE_INT) && (int_change & OCM_BOOT_UP)) { + anx7411_config(ctx); + anx7411_data_role_detect(ctx); + anx7411_power_role_detect(ctx); + anx7411_set_mux(ctx, SELECT_PIN_ASSIGMENT_C); + } + + if (alert0 & RECEIVED_MSG) + anx7411_process_cmd(ctx); + + ret = (int_status & DATA_ROLE) ? TYPEC_HOST : TYPEC_DEVICE; + if (ctx->typec.data_role != ret) + anx7411_data_role_detect(ctx); + + ret = (int_status & SINK_STATUS) ? TYPEC_SINK : TYPEC_SOURCE; + if (ctx->typec.power_role != ret) + anx7411_power_role_detect(ctx); + + if ((alert0 & SOFTWARE_INT) && (int_change & CC_STATUS_CHANGE)) + anx7411_cc_status_detect(ctx); + +unlock: + mutex_unlock(&ctx->lock); +} + +static irqreturn_t anx7411_intr_isr(int irq, void *data) +{ + struct anx7411_data *ctx = (struct anx7411_data *)data; + + queue_work(ctx->workqueue, &ctx->work); + + return IRQ_HANDLED; +} + +static int anx7411_register_i2c_dummy_clients(struct anx7411_data *ctx, + struct i2c_client *client) +{ + int i; + u8 spi_addr; + + for (i = 0; i < sizeof(anx7411_i2c_addr); i++) { + if (client->addr == (anx7411_i2c_addr[i].tcpc_address >> 1)) { + spi_addr = anx7411_i2c_addr[i].spi_address >> 1; + ctx->spi_client = i2c_new_dummy_device(client->adapter, + spi_addr); + if (ctx->spi_client) + return 0; + } + } + + dev_err(&client->dev, "unable to get SPI slave\n"); + return -ENOMEM; +} + +static void anx7411_port_unregister_altmodes(struct typec_altmode **adev) +{ + int i; + + for (i = 0; i < MAX_ALTMODE; i++) + if (adev[i]) { + typec_unregister_altmode(adev[i]); + adev[i] = NULL; + } +} + +static int anx7411_usb_mux_set(struct typec_mux *mux, + struct typec_mux_state *state) +{ + struct anx7411_data *ctx = typec_mux_get_drvdata(mux); + struct device *dev = &ctx->spi_client->dev; + int has_dp; + + has_dp = (state->alt && state->alt->svid == USB_TYPEC_DP_SID && + state->alt->mode == USB_TYPEC_DP_MODE); + if (!has_dp) + dev_err(dev, "dp altmode not register\n"); + + return 0; +} + +static int anx7411_usb_set_orientation(struct typec_switch *sw, + enum typec_orientation orientation) +{ + /* No need set */ + + return 0; +} + +static int anx7411_register_switch(struct anx7411_data *ctx, + struct device *dev, + struct fwnode_handle *fwnode) +{ + struct typec_switch_desc sw_desc = { }; + + sw_desc.fwnode = fwnode; + sw_desc.drvdata = ctx; + sw_desc.name = fwnode_get_name(fwnode); + sw_desc.set = anx7411_usb_set_orientation; + + ctx->typec.typec_switch = typec_switch_register(dev, &sw_desc); + if (IS_ERR(ctx->typec.typec_switch)) { + dev_err(dev, "switch register failed\n"); + return PTR_ERR(ctx->typec.typec_switch); + } + + return 0; +} + +static int anx7411_register_mux(struct anx7411_data *ctx, + struct device *dev, + struct fwnode_handle *fwnode) +{ + struct typec_mux_desc mux_desc = { }; + + mux_desc.fwnode = fwnode; + mux_desc.drvdata = ctx; + mux_desc.name = fwnode_get_name(fwnode); + mux_desc.set = anx7411_usb_mux_set; + + ctx->typec.typec_mux = typec_mux_register(dev, &mux_desc); + if (IS_ERR(ctx->typec.typec_mux)) { + dev_err(dev, "mux register failed\n"); + return PTR_ERR(ctx->typec.typec_mux); + } + + return 0; +} + +static void anx7411_unregister_mux(struct anx7411_data *ctx) +{ + if (ctx->typec.typec_mux) { + typec_mux_unregister(ctx->typec.typec_mux); + ctx->typec.typec_mux = NULL; + } +} + +static void anx7411_unregister_switch(struct anx7411_data *ctx) +{ + if (ctx->typec.typec_switch) { + typec_switch_unregister(ctx->typec.typec_switch); + ctx->typec.typec_switch = NULL; + } +} + +static int anx7411_typec_switch_probe(struct anx7411_data *ctx, + struct device *dev) +{ + int ret; + struct device_node *node; + + node = of_find_node_by_name(dev->of_node, "orientation_switch"); + if (!node) { + dev_info(dev, "no typec switch exist\n"); + return 0; + } + + ret = anx7411_register_switch(ctx, dev, &node->fwnode); + if (ret) { + dev_err(dev, "failed register switch"); + return ret; + } + + node = of_find_node_by_name(dev->of_node, "mode_switch"); + if (!node) { + dev_err(dev, "no typec mux exist"); + ret = -ENODEV; + goto unregister_switch; + } + + ret = anx7411_register_mux(ctx, dev, &node->fwnode); + if (ret) { + dev_err(dev, "failed register mode switch"); + ret = -ENODEV; + goto unregister_switch; + } + + return 0; + +unregister_switch: + anx7411_unregister_switch(ctx); + + return ret; +} + +static int anx7411_typec_port_probe(struct anx7411_data *ctx, + struct device *dev) +{ + struct typec_capability *cap = &ctx->typec.caps; + struct typec_params *typecp = &ctx->typec; + struct fwnode_handle *fwnode; + const char *buf; + int ret, i; + + fwnode = device_get_named_child_node(dev, "connector"); + if (!fwnode) + return -EINVAL; + + ret = fwnode_property_read_string(fwnode, "power-role", &buf); + if (ret) { + dev_err(dev, "power-role not found: %d\n", ret); + return ret; + } + + ret = typec_find_port_power_role(buf); + if (ret < 0) + return ret; + cap->type = ret; + + ret = fwnode_property_read_string(fwnode, "data-role", &buf); + if (ret) { + dev_err(dev, "data-role not found: %d\n", ret); + return ret; + } + + ret = typec_find_port_data_role(buf); + if (ret < 0) + return ret; + cap->data = ret; + + ret = fwnode_property_read_string(fwnode, "try-power-role", &buf); + if (ret) { + dev_err(dev, "try-power-role not found: %d\n", ret); + return ret; + } + + ret = typec_find_power_role(buf); + if (ret < 0) + return ret; + cap->prefer_role = ret; + + /* Get source pdos */ + ret = fwnode_property_count_u32(fwnode, "source-pdos"); + if (ret > 0) { + dev_info(dev, "%d source-pdos found\n", ret); + typecp->src_pdo_nr = min(ret, PDO_MAX_OBJECTS); + ret = fwnode_property_read_u32_array(fwnode, "source-pdos", + typecp->src_pdo, + typecp->src_pdo_nr); + if (ret < 0) { + dev_err(dev, "source cap validate failed: %d\n", ret); + return -EINVAL; + } + + typecp->caps_flags |= HAS_SOURCE_CAP; + } + + ret = fwnode_property_count_u32(fwnode, "sink-pdos"); + if (ret > 0) { + dev_info(dev, "%d sink-pdos found\n", ret); + typecp->sink_pdo_nr = min(ret, PDO_MAX_OBJECTS); + ret = fwnode_property_read_u32_array(fwnode, "sink-pdos", + typecp->sink_pdo, + typecp->sink_pdo_nr); + if (ret < 0) { + dev_err(dev, "sink cap validate failed: %d\n", ret); + return -EINVAL; + } + + for (i = 0; i < typecp->sink_pdo_nr; i++) { + ret = 0; + switch (pdo_type(typecp->sink_pdo[i])) { + case PDO_TYPE_FIXED: + ret = pdo_fixed_voltage(typecp->sink_pdo[i]); + break; + case PDO_TYPE_BATT: + case PDO_TYPE_VAR: + ret = pdo_max_voltage(typecp->sink_pdo[i]); + break; + case PDO_TYPE_APDO: + default: + ret = 0; + break; + } + + /* 100mv per unit */ + typecp->sink_voltage = max(5000, ret) / 100; + } + + typecp->caps_flags |= HAS_SINK_CAP; + } + + if (!fwnode_property_read_u32(fwnode, "op-sink-microwatt", &ret)) { + dev_info(dev, "%d sink-microwat found\n", ret); + typecp->sink_watt = ret / 500000; /* 500mw per unit */ + typecp->caps_flags |= HAS_SINK_WATT; + } + + cap->fwnode = fwnode; + + ctx->typec.role_sw = usb_role_switch_get(dev); + if (IS_ERR(ctx->typec.role_sw)) { + dev_err(dev, "USB role switch not found.\n"); + ctx->typec.role_sw = NULL; + } + + ctx->typec.port = typec_register_port(dev, cap); + if (IS_ERR(ctx->typec.port)) { + ret = PTR_ERR(ctx->typec.port); + ctx->typec.port = NULL; + dev_err(dev, "Failed to register type c port %d\n", ret); + return ret; + } + + typec_port_register_altmodes(ctx->typec.port, NULL, ctx, + ctx->typec.port_amode, + MAX_ALTMODE); + + return 0; +} + +static int anx7411_typec_check_connection(struct anx7411_data *ctx) +{ + int ret; + + ret = anx7411_reg_read(ctx->spi_client, FW_VER); + if (ret < 0) + return 0; /* No device attached in typec port */ + + /* Clear interrupt and alert status */ + anx7411_reg_write(ctx->spi_client, INT_STS, 0); + anx7411_reg_write(ctx->tcpc_client, ALERT_0, 0xFF); + anx7411_reg_write(ctx->tcpc_client, ALERT_1, 0xFF); + + anx7411_cc_status_detect(ctx); + anx7411_power_role_detect(ctx); + anx7411_data_role_detect(ctx); + anx7411_set_mux(ctx, SELECT_PIN_ASSIGMENT_C); + + anx7411_send_msg(ctx, TYPE_GET_DP_ALT_ENTER, NULL, 0); + anx7411_send_msg(ctx, TYPE_GET_DP_DISCOVER_MODES_INFO, NULL, 0); + + return 0; +} + +static int __maybe_unused anx7411_runtime_pm_suspend(struct device *dev) +{ + struct anx7411_data *ctx = dev_get_drvdata(dev); + + mutex_lock(&ctx->lock); + + anx7411_partner_unregister_altmode(ctx); + + if (ctx->typec.partner) + anx7411_unregister_partner(ctx); + + mutex_unlock(&ctx->lock); + + return 0; +} + +static int __maybe_unused anx7411_runtime_pm_resume(struct device *dev) +{ + struct anx7411_data *ctx = dev_get_drvdata(dev); + + mutex_lock(&ctx->lock); + /* Detect PD connection */ + anx7411_typec_check_connection(ctx); + + mutex_unlock(&ctx->lock); + + return 0; +} + +static const struct dev_pm_ops anx7411_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, + pm_runtime_force_resume) + SET_RUNTIME_PM_OPS(anx7411_runtime_pm_suspend, + anx7411_runtime_pm_resume, NULL) +}; + +static void anx7411_get_gpio_irq(struct anx7411_data *ctx) +{ + struct device *dev = &ctx->tcpc_client->dev; + + ctx->intp_gpiod = devm_gpiod_get_optional(dev, "interrupt", GPIOD_IN); + if (!ctx->intp_gpiod) { + dev_err(dev, "no interrupt gpio property\n"); + return; + } + + ctx->intp_irq = gpiod_to_irq(ctx->intp_gpiod); + dev_info(dev, "request gpio(%d) irq(%d)\n", + desc_to_gpio(ctx->intp_gpiod), ctx->intp_irq); + + if (!ctx->intp_irq) + dev_err(dev, "failed to get GPIO IRQ\n"); +} + +static const char *anx7411_psy_name_prefix = "anx7411-source-psy-"; + +static enum power_supply_usb_type anx7411_psy_usb_types[] = { + POWER_SUPPLY_USB_TYPE_C, + POWER_SUPPLY_USB_TYPE_PD, + POWER_SUPPLY_USB_TYPE_PD_PPS, +}; + +static enum power_supply_property anx7411_psy_props[] = { + POWER_SUPPLY_PROP_USB_TYPE, + POWER_SUPPLY_PROP_ONLINE, + POWER_SUPPLY_PROP_VOLTAGE_MIN, + POWER_SUPPLY_PROP_VOLTAGE_MAX, + POWER_SUPPLY_PROP_VOLTAGE_NOW, + POWER_SUPPLY_PROP_CURRENT_MAX, + POWER_SUPPLY_PROP_CURRENT_NOW, +}; + +static int anx7411_psy_set_prop(struct power_supply *psy, + enum power_supply_property psp, + const union power_supply_propval *val) +{ + struct anx7411_data *ctx = power_supply_get_drvdata(psy); + int ret = 0; + + if (psp == POWER_SUPPLY_PROP_ONLINE) + ctx->psy_online = val->intval; + else + ret = -EINVAL; + + power_supply_changed(ctx->psy); + return ret; +} + +static int anx7411_psy_prop_writeable(struct power_supply *psy, + enum power_supply_property psp) +{ + return psp == POWER_SUPPLY_PROP_ONLINE; +} + +static int anx7411_psy_get_prop(struct power_supply *psy, + enum power_supply_property psp, + union power_supply_propval *val) +{ + struct anx7411_data *ctx = power_supply_get_drvdata(psy); + int ret = 0; + + switch (psp) { + case POWER_SUPPLY_PROP_USB_TYPE: + val->intval = ctx->usb_type; + break; + case POWER_SUPPLY_PROP_ONLINE: + val->intval = ctx->psy_online; + break; + case POWER_SUPPLY_PROP_VOLTAGE_NOW: + case POWER_SUPPLY_PROP_VOLTAGE_MIN: + case POWER_SUPPLY_PROP_VOLTAGE_MAX: + val->intval = (ctx->psy_online) ? + ctx->typec.request_voltage * 1000 : 0; + break; + case POWER_SUPPLY_PROP_CURRENT_NOW: + case POWER_SUPPLY_PROP_CURRENT_MAX: + val->intval = (ctx->psy_online) ? + ctx->typec.request_current * 1000 : 0; + break; + default: + ret = -EINVAL; + break; + } + return ret; +} + +static int anx7411_psy_register(struct anx7411_data *ctx) +{ + struct power_supply_config psy_cfg = {}; + const char *port_dev_name = dev_name(ctx->dev); + size_t psy_name_len = strlen(anx7411_psy_name_prefix) + + strlen(port_dev_name) + 1; + char *psy_name; + struct power_supply_desc *psy_desc = &ctx->psy_desc; + + psy_cfg.drv_data = ctx; + psy_cfg.fwnode = dev_fwnode(ctx->dev); + psy_name = devm_kzalloc(ctx->dev, psy_name_len, GFP_KERNEL); + if (!psy_name) { + dev_warn(ctx->dev, "unable to alloc psy memory\n"); + return -ENOMEM; + } + + snprintf(psy_name, psy_name_len, "%s%s", anx7411_psy_name_prefix, + port_dev_name); + + psy_desc->name = psy_name; + psy_desc->type = POWER_SUPPLY_TYPE_USB; + psy_desc->usb_types = anx7411_psy_usb_types; + psy_desc->num_usb_types = ARRAY_SIZE(anx7411_psy_usb_types); + psy_desc->properties = anx7411_psy_props, + psy_desc->num_properties = ARRAY_SIZE(anx7411_psy_props), + + psy_desc->get_property = anx7411_psy_get_prop, + psy_desc->set_property = anx7411_psy_set_prop, + psy_desc->property_is_writeable = anx7411_psy_prop_writeable, + + ctx->usb_type = POWER_SUPPLY_USB_TYPE_C; + ctx->psy = devm_power_supply_register(ctx->dev, psy_desc, &psy_cfg); + + if (IS_ERR(ctx->psy)) + dev_warn(ctx->dev, "unable to register psy\n"); + + return PTR_ERR_OR_ZERO(ctx->psy); +} + +static int anx7411_i2c_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct anx7411_data *plat; + struct device *dev = &client->dev; + int ret; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) + return -ENODEV; + + plat = devm_kzalloc(dev, sizeof(*plat), GFP_KERNEL); + if (!plat) + return -ENOMEM; + + plat->tcpc_client = client; + i2c_set_clientdata(client, plat); + + mutex_init(&plat->lock); + + ret = anx7411_register_i2c_dummy_clients(plat, client); + if (ret) { + dev_err(dev, "fail to reserve I2C bus\n"); + return ret; + } + + ret = anx7411_typec_switch_probe(plat, dev); + if (ret) { + dev_err(dev, "fail to probe typec switch\n"); + goto free_i2c_dummy; + } + + ret = anx7411_typec_port_probe(plat, dev); + if (ret) { + dev_err(dev, "fail to probe typec property.\n"); + ret = -ENODEV; + goto free_typec_switch; + } + + plat->intp_irq = client->irq; + if (!client->irq) { + dev_warn(dev, "no default interrupt IRQ, probe GPIO interrupt"); + anx7411_get_gpio_irq(plat); + } + + if (!plat->intp_irq) { + dev_err(dev, "fail to get interrupt IRQ\n"); + goto free_typec_port; + } + + plat->dev = dev; + plat->psy_online = ANX7411_PSY_OFFLINE; + anx7411_psy_register(plat); + + if (plat->intp_irq) { + INIT_WORK(&plat->work, anx7411_work_func); + plat->workqueue = alloc_workqueue("anx7411_work", + WQ_FREEZABLE | + WQ_MEM_RECLAIM, + 1); + if (!plat->workqueue) { + dev_err(dev, "fail to create work queue\n"); + ret = -ENOMEM; + goto free_typec_port; + } + + ret = devm_request_threaded_irq(dev, plat->intp_irq, + NULL, anx7411_intr_isr, + IRQF_TRIGGER_FALLING | + IRQF_ONESHOT, + "anx7411-intp", plat); + if (ret) { + dev_err(dev, "fail to request irq\n"); + goto free_wq; + } + } + + anx7411_typec_check_connection(plat); + + pm_runtime_enable(dev); + + return 0; + +free_wq: + destroy_workqueue(plat->workqueue); + +free_typec_port: + typec_unregister_port(plat->typec.port); + anx7411_port_unregister_altmodes(plat->typec.port_amode); + +free_typec_switch: + anx7411_unregister_switch(plat); + anx7411_unregister_mux(plat); + +free_i2c_dummy: + i2c_unregister_device(plat->spi_client); + + return ret; +} + +static int anx7411_i2c_remove(struct i2c_client *client) +{ + struct anx7411_data *plat = i2c_get_clientdata(client); + + anx7411_partner_unregister_altmode(plat); + anx7411_unregister_partner(plat); + + if (plat->workqueue) + destroy_workqueue(plat->workqueue); + + if (plat->spi_client) + i2c_unregister_device(plat->spi_client); + + if (plat->typec.role_sw) + usb_role_switch_put(plat->typec.role_sw); + + anx7411_unregister_mux(plat); + + anx7411_unregister_switch(plat); + + if (plat->typec.port) + typec_unregister_port(plat->typec.port); + + anx7411_port_unregister_altmodes(plat->typec.port_amode); + + return 0; +} + +static const struct i2c_device_id anx7411_id[] = { + {"anx7411", 0}, + {} +}; + +MODULE_DEVICE_TABLE(i2c, anx7411_id); + +static const struct of_device_id anx_match_table[] = { + {.compatible = "analogix,anx7411",}, + {}, +}; + +static struct i2c_driver anx7411_driver = { + .driver = { + .name = "anx7411", + .of_match_table = anx_match_table, + .pm = &anx7411_pm_ops, + }, + .probe = anx7411_i2c_probe, + .remove = anx7411_i2c_remove, + + .id_table = anx7411_id, +}; + +module_i2c_driver(anx7411_driver); + +MODULE_DESCRIPTION("Anx7411 USB Type-C PD driver"); +MODULE_AUTHOR("Xin Ji "); +MODULE_LICENSE("GPL v2"); +MODULE_VERSION("0.1.5"); diff --git a/drivers/usb/typec/anx7411.h b/drivers/usb/typec/anx7411.h new file mode 100644 index 000000000000..11f972756e0d --- /dev/null +++ b/drivers/usb/typec/anx7411.h @@ -0,0 +1,265 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +/* + * Copyright(c) 2022, Analogix Semiconductor. All rights reserved. + * + */ + +#ifndef __ANX7411_H__ +#define __ANX7411_H__ + +#define TCPC_ADDRESS1 0x58 +#define TCPC_ADDRESS2 0x56 +#define TCPC_ADDRESS3 0x54 +#define TCPC_ADDRESS4 0x52 +#define SPI_ADDRESS1 0x7e +#define SPI_ADDRESS2 0x6e +#define SPI_ADDRESS3 0x64 +#define SPI_ADDRESS4 0x62 + +struct anx7411_i2c_select { + u8 tcpc_address; + u8 spi_address; +}; + +#define VID_ANALOGIX 0x1F29 +#define PID_ANALOGIX 0x7411 + +/* TCPC register define */ + +#define ANALOG_CTRL_10 0xAA + +#define STATUS_LEN 2 +#define ALERT_0 0xCB +#define RECEIVED_MSG BIT(7) +#define SOFTWARE_INT BIT(6) +#define MSG_LEN 32 +#define HEADER_LEN 2 +#define MSG_HEADER 0x00 +#define MSG_TYPE 0x01 +#define MSG_RAWDATA 0x02 +#define MSG_LEN_MASK 0x1F + +#define ALERT_1 0xCC +#define INTP_POW_ON BIT(7) +#define INTP_POW_OFF BIT(6) + +#define VBUS_THRESHOLD_H 0xDD +#define VBUS_THRESHOLD_L 0xDE + +#define FW_CTRL_0 0xF0 +#define UNSTRUCT_VDM_EN BIT(0) +#define DELAY_200MS BIT(1) +#define VSAFE0 0 +#define VSAFE1 BIT(2) +#define VSAFE2 BIT(3) +#define VSAFE3 (BIT(2) | BIT(3)) +#define FRS_EN BIT(7) + +#define FW_PARAM 0xF1 +#define DONGLE_IOP BIT(0) + +#define FW_CTRL_2 0xF7 +#define SINK_CTRL_DIS_FLAG BIT(5) + +/* SPI register define */ +#define OCM_CTRL_0 0x6E +#define OCM_RESET BIT(6) + +#define MAX_VOLTAGE 0xAC +#define MAX_POWER 0xAD +#define MIN_POWER 0xAE + +#define REQUEST_VOLTAGE 0xAF +#define VOLTAGE_UNIT 100 /* mV per unit */ + +#define REQUEST_CURRENT 0xB1 +#define CURRENT_UNIT 50 /* mA per unit */ + +#define CMD_SEND_BUF 0xC0 +#define CMD_RECV_BUF 0xE0 + +#define REQ_VOL_20V_IN_100MV 0xC8 +#define REQ_CUR_2_25A_IN_50MA 0x2D +#define REQ_CUR_3_25A_IN_50MA 0x41 + +#define DEF_5V 5000 +#define DEF_1_5A 1500 + +#define LOBYTE(w) ((u8)(w) & 0xFF) +#define HIBYTE(w) ((u8)(((u16)(w) >> 8) & 0xFF)) + +enum anx7411_typec_message_type { + TYPE_SRC_CAP = 0x00, + TYPE_SNK_CAP = 0x01, + TYPE_SNK_IDENTITY = 0x02, + TYPE_SVID = 0x03, + TYPE_SET_SNK_DP_CAP = 0x08, + TYPE_PSWAP_REQ = 0x10, + TYPE_DSWAP_REQ = 0x11, + TYPE_VDM = 0x14, + TYPE_OBJ_REQ = 0x16, + TYPE_DP_ALT_ENTER = 0x19, + TYPE_DP_DISCOVER_MODES_INFO = 0x27, + TYPE_GET_DP_CONFIG = 0x29, + TYPE_DP_CONFIGURE = 0x2A, + TYPE_GET_DP_DISCOVER_MODES_INFO = 0x2E, + TYPE_GET_DP_ALT_ENTER = 0x2F, +}; + +#define FW_CTRL_1 0xB2 +#define AUTO_PD_EN BIT(1) +#define TRYSRC_EN BIT(2) +#define TRYSNK_EN BIT(3) +#define FORCE_SEND_RDO BIT(6) + +#define FW_VER 0xB4 +#define FW_SUBVER 0xB5 + +#define INT_MASK 0xB6 +#define INT_STS 0xB7 +#define OCM_BOOT_UP BIT(0) +#define OC_OV_EVENT BIT(1) +#define VCONN_CHANGE BIT(2) +#define VBUS_CHANGE BIT(3) +#define CC_STATUS_CHANGE BIT(4) +#define DATA_ROLE_CHANGE BIT(5) +#define PR_CONSUMER_GOT_POWER BIT(6) +#define HPD_STATUS_CHANGE BIT(7) + +#define SYSTEM_STSTUS 0xB8 +/* 0: SINK off; 1: SINK on */ +#define SINK_STATUS BIT(1) +/* 0: VCONN off; 1: VCONN on*/ +#define VCONN_STATUS BIT(2) +/* 0: vbus off; 1: vbus on*/ +#define VBUS_STATUS BIT(3) +/* 1: host; 0:device*/ +#define DATA_ROLE BIT(5) +/* 0: Chunking; 1: Unchunked*/ +#define SUPPORT_UNCHUNKING BIT(6) +/* 0: HPD low; 1: HPD high*/ +#define HPD_STATUS BIT(7) + +#define DATA_DFP 1 +#define DATA_UFP 2 +#define POWER_SOURCE 1 +#define POWER_SINK 2 + +#define CC_STATUS 0xB9 +#define CC1_RD BIT(0) +#define CC2_RD BIT(4) +#define CC1_RA BIT(1) +#define CC2_RA BIT(5) +#define CC1_RD BIT(0) +#define CC1_RP(cc) (((cc) >> 2) & 0x03) +#define CC2_RP(cc) (((cc) >> 6) & 0x03) + +#define PD_REV_INIT 0xBA + +#define PD_EXT_MSG_CTRL 0xBB +#define SRC_CAP_EXT_REPLY BIT(0) +#define MANUFACTURER_INFO_REPLY BIT(1) +#define BATTERY_STS_REPLY BIT(2) +#define BATTERY_CAP_REPLY BIT(3) +#define ALERT_REPLY BIT(4) +#define STATUS_REPLY BIT(5) +#define PPS_STATUS_REPLY BIT(6) +#define SNK_CAP_EXT_REPLY BIT(7) + +#define NO_CONNECT 0x00 +#define USB3_1_CONNECTED 0x01 +#define DP_ALT_4LANES 0x02 +#define USB3_1_DP_2LANES 0x03 +#define CC1_CONNECTED 0x01 +#define CC2_CONNECTED 0x02 +#define SELECT_PIN_ASSIGMENT_C 0x04 +#define SELECT_PIN_ASSIGMENT_D 0x08 +#define SELECT_PIN_ASSIGMENT_E 0x10 +#define SELECT_PIN_ASSIGMENT_U 0x00 +#define REDRIVER_ADDRESS 0x20 +#define REDRIVER_OFFSET 0x00 + +#define DP_SVID 0xFF01 +#define VDM_ACK 0x40 +#define VDM_CMD_RES 0x00 +#define VDM_CMD_DIS_ID 0x01 +#define VDM_CMD_DIS_SVID 0x02 +#define VDM_CMD_DIS_MOD 0x03 +#define VDM_CMD_ENTER_MODE 0x04 +#define VDM_CMD_EXIT_MODE 0x05 +#define VDM_CMD_ATTENTION 0x06 +#define VDM_CMD_GET_STS 0x10 +#define VDM_CMD_AND_ACK_MASK 0x5F + +#define MAX_ALTMODE 2 + +#define HAS_SOURCE_CAP BIT(0) +#define HAS_SINK_CAP BIT(1) +#define HAS_SINK_WATT BIT(2) + +enum anx7411_psy_state { + /* copy from drivers/usb/typec/tcpm */ + ANX7411_PSY_OFFLINE = 0, + ANX7411_PSY_FIXED_ONLINE, + + /* private */ + /* PD keep in, but disconnct power to bq25700, + * this state can be active when higher capacity adapter plug in, + * and change to ONLINE state when higher capacity adapter plug out + */ + ANX7411_PSY_HANG = 0xff, +}; + +struct typec_params { + int request_current; /* ma */ + int request_voltage; /* mv */ + int cc_connect; + int cc_orientation_valid; + int cc_status; + int data_role; + int power_role; + int vconn_role; + int dp_altmode_enter; + int cust_altmode_enter; + struct usb_role_switch *role_sw; + struct typec_port *port; + struct typec_partner *partner; + struct typec_mux *typec_mux; + struct typec_switch *typec_switch; + struct typec_altmode *amode[MAX_ALTMODE]; + struct typec_altmode *port_amode[MAX_ALTMODE]; + struct typec_displayport_data data; + int pin_assignment; + struct typec_capability caps; + u32 src_pdo[PDO_MAX_OBJECTS]; + u32 sink_pdo[PDO_MAX_OBJECTS]; + u8 caps_flags; + u8 src_pdo_nr; + u8 sink_pdo_nr; + u8 sink_watt; + u8 sink_voltage; +}; + +struct anx7411_data { + int fw_version; + int fw_subversion; + struct i2c_client *tcpc_client; + struct i2c_client *spi_client; + struct gpio_desc *intp_gpiod; + struct fwnode_handle *connector_fwnode; + struct typec_params typec; + int intp_irq; + struct work_struct work; + struct workqueue_struct *workqueue; + /* Lock for interrupt work queue */ + struct mutex lock; + + enum anx7411_psy_state psy_online; + enum power_supply_usb_type usb_type; + struct power_supply *psy; + struct power_supply_desc psy_desc; + struct device *dev; +}; + +#endif /* __ANX7411_H__ */