Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3850472rwb; Sun, 20 Nov 2022 23:40:43 -0800 (PST) X-Google-Smtp-Source: AA0mqf7ul+mqoJMoGxrXeyFtXkohHNxFdZUk/g1ZIDU6dLdjh2Ggp04gfS+ooQAWkRCE/bq7Zo/2 X-Received: by 2002:a05:6a00:27a3:b0:56d:6450:9e49 with SMTP id bd35-20020a056a0027a300b0056d64509e49mr3663538pfb.54.1669016443258; Sun, 20 Nov 2022 23:40:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1669016443; cv=pass; d=google.com; s=arc-20160816; b=VgWJiGse6xwoKMQIB3P0wQGHaciA7Wi5nyyOOzuZoNm5v4Cul0jSTErP6OoqCtq7dz LFpY/MlnDr6e8C0vGwQUHEtb64HiWsirR+Ldk/fblw9mN4yBBfW10UqZKL/IKn+hZhlH iplLqIUJzYyhA54Tq3cikrlSN3tDi42QtGSxqW9Yn1WCBQ3sZcUmrCWFjE/EkoM6lAEO qLk5MjXTi/7x6Wo2DSWBkwuM2wQ6eQhhnb3Wvfiiv4TaAhcPsH7gJKoIy0SEpDFjO0UU 0w5oKLHyD+19tmz60ZPqVW9z5PibwPG45BdklD0t6JDVjtCq63TfsrK7t8On3iCkU7qf UOKQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CI6HiPRkfFukA+gvkjMZqgx2ImVxcURakl6FJilSdaY=; b=RmVYDCVQqJjz5X2n6Ibl+bU3RBIKeLaaSk7fTMuzsxg2OLFFL9nNsjG2I/430sq6MY u39bAIkMsDOVUzTKFJRvbdlp1fmfQG6j4Ne3Z+T5OuaTBQ7ZDxT3V7G9DKZKgJSI3cCV 4bvPgnhmLn0mNDZsMpGVfMaUYBQLKOmjtZSgQqPpnO+IBqkKACPfD/nF+HD8T/WmJyR8 cgjduG7QOx5ZyOWRR7D1lYw2Sc9DgqT9F04Fl3HhaF8aKTfFT+qyw4Dz96SGn4wcSHma UWWS4dBh//k3neguLe+FxOc2GnQi9JquULzg0s+wFNcEO4/Dptlbh/oTibKcCnYYTfKs NNkA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=oklkKTBZ; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j15-20020a170902da8f00b00186a5b86ea3si12237631plx.50.2022.11.20.23.40.31; Sun, 20 Nov 2022 23:40:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=oklkKTBZ; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229712AbiKUH1N (ORCPT + 91 others); Mon, 21 Nov 2022 02:27:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229699AbiKUH1J (ORCPT ); Mon, 21 Nov 2022 02:27:09 -0500 Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-eopbgr130075.outbound.protection.outlook.com [40.107.13.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 465792EF6D; Sun, 20 Nov 2022 23:27:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hLe7iPGUWMFaeoOlJQkgMlRCLWhxNGsfl6ZKsIKNZKO2KJ96vH+mlVjsqCz7v5sqRbemVSmgsUiUOP0yPJkVpjYS0GynRkvo0/wR6tw8RR6Lo8jZNRGv6n1BONEZHL6r0Y9t8mSPmhgx5V9Oah0buBNRDj5s2DoLMdMlg9Cu48eEX4H+y1Nql9JGr/7AYdnwrAdQqKgkXDH2o/MKmlXqElxWfFI5tpqK3VMMro3fUVbfqhDI+IcjfysN5ktYveVSFahW8uzQm2jfaffD3VN7/xylRrGT3UFrfz2x0UqXYQN3UaEkrBpee3l3J5HROx4I8u4hzMeu8qzguB/X1qIHGQ== 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=CI6HiPRkfFukA+gvkjMZqgx2ImVxcURakl6FJilSdaY=; b=c8DBLspV6q3FFZX0X8kLjAORh/ynyWIWXwQ3P0TO6TG3UL1K7kA9MhHjtCjG4EtcyYd+FslLZiC2slaaIwKso9N7gjb89xjfsqZMe0SRPvW+k8Iob4pxBZFs8jTsJlAQG6Z/MX9dH86ff3fMFzv9/aIrF7UnCsYpVkH6rqIoNGEQK4YRYmvO5dRp2OQmC9Q+L1I8WsPZAYGv9S3lez0lE0hTyJTEVshB9DiodmmwIemfq26TqrRavV+FwBCnFg7Yao4BcJ6rEUifQ8Ys9cVM/CufbmxAJwyTkSdDz+rkLvnCKK1JdJNkzlVC2vZv+wyUy9hVw5JV4KgS9QtTHf7U9Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CI6HiPRkfFukA+gvkjMZqgx2ImVxcURakl6FJilSdaY=; b=oklkKTBZYsIBarzXg8tZPCmyBs18EvzKaclyu4330+49LSDhei6ZdK9eo7KfktUG8tV7S+q2JsjmyLrRxN2Pw5SzI3PrAhpJ5G+uTrJSVY5rQ42u8ffPcKk7YSFVGMzgvGAXBd1+zC9yf6tiiGc+yyVRA9bZ99nzTWb/NKvAkj8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9448.eurprd04.prod.outlook.com (2603:10a6:102:2b1::21) by DBBPR04MB7769.eurprd04.prod.outlook.com (2603:10a6:10:1e0::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5834.9; Mon, 21 Nov 2022 07:27:00 +0000 Received: from PAXPR04MB9448.eurprd04.prod.outlook.com ([fe80::60b2:4bec:7707:e196]) by PAXPR04MB9448.eurprd04.prod.outlook.com ([fe80::60b2:4bec:7707:e196%5]) with mapi id 15.20.5834.015; Mon, 21 Nov 2022 07:27:00 +0000 From: Sandor Yu To: andrzej.hajda@intel.com, neil.armstrong@linaro.org, robert.foss@linaro.org, Laurent.pinchart@ideasonboard.com, jonas@kwiboo.se, jernej.skrabec@gmail.com, airlied@gmail.com, daniel@ffwll.ch, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, shawnguo@kernel.org, s.hauer@pengutronix.de, festevam@gmail.com, kishon@ti.com, vkoul@kernel.org, dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-phy@lists.infradead.org, alexander.stein@ew.tq-group.com Cc: kernel@pengutronix.de, linux-imx@nxp.com, Sandor.yu@nxp.com, oliver.brown@nxp.com Subject: [PATCH v4 01/10] drm: bridge: cadence: convert mailbox functions to macro functions Date: Mon, 21 Nov 2022 15:23:51 +0800 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SG2PR06CA0246.apcprd06.prod.outlook.com (2603:1096:4:ac::30) To PAXPR04MB9448.eurprd04.prod.outlook.com (2603:10a6:102:2b1::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9448:EE_|DBBPR04MB7769:EE_ X-MS-Office365-Filtering-Correlation-Id: f17b0c54-ed56-4442-debc-08dacb91c74f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: v3bLgsoc70cRt1VT7wmghzB5CTJySIO+X127bv9VIrlMnBUBcB9Lwor9rA6neH6ykaxvOycRtFGQDwVlYne2UR1KzeZr1kunwzT0V8iU48sXufboasxWrTmW4UBK7TD6NrQfzWg+rdHqSBRByJvL5djt2QtSDD5gMwgCdV7xHISE8Oc6mLleHZyF+AvJycKsdBZWF1sOTR3wYyN6pBStpTd7H0LKcSFNsSzfCIFDWwTL7h2niRscH4d274DOB9yuzYWcQE4vVnSuyPPX61DA3Oa6X4kwFGxro23UWi+jgE8yG6wAKroiMe8KxFtyiXDi4CpjPvC+7dj2RNU/igDGqwS80u7fu6w4yUEyKo+qKJYDOhT+3CDMz4IPSE0z/NXw4F0WEfE4zUmlRItqqdnz2dZY1/HdSpS9qI3ZSFRkbV9jY7xYLyz2o8ZPcth4ikbB14oOwgh1P5+wfD+ZVBCtfQxyHJT5YoRMdjesfP87vgEYYPVH9wErh+VEJBdvY7RZHc/21dnGm8ELLkOQl8kQwMvvlLwE5E8gEe8v4q7z4Llg7z3/3Qg++yYo/rSSOyFBKpVeh3H5HbnwJiNFv7fuPuXPTvt63ylHI0AKf4F7oBhZzWEUhWHuCREtSKa2Xhvmtj6Kin0mWzKyGDuM719Xu6z623lfQy1slTfifnaYZxJ2oBdrZQdDwbrWej/1Bcwm6pFO/iv6mmZlj2YY/jm5lA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9448.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(396003)(366004)(39860400002)(136003)(376002)(346002)(451199015)(86362001)(36756003)(8936002)(5660300002)(7416002)(2616005)(2906002)(186003)(30864003)(15650500001)(316002)(52116002)(4326008)(6506007)(6666004)(66476007)(66946007)(8676002)(66556008)(6512007)(478600001)(38350700002)(38100700002)(26005)(921005)(41300700001)(83380400001)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?QIBKzSt1QZJx8/AFrCHC4ivzT02dd1roKhUrpRHiir7NqKAQnBxrILgvepp8?= =?us-ascii?Q?kTdEF5BzsLLBihWVxfnssXSZJjzdJCVgLMXouf6mExqpWmMJONFuq9bnSiin?= =?us-ascii?Q?OHveW/OGvpO03+gvp9V8e+DowXoM2SSVgN2cz8FjtewsamiSFAQv63VHfkdg?= =?us-ascii?Q?JbjwdRPAy/bI9/pgQYv64yETB3k9Es+FgRLYVpdoZ2jlvNpXEt7UL4xLJ8AX?= =?us-ascii?Q?0xXctGHjxBhkimFMra73lFWN0Z8gYzfZfHxiarmEp4Bb2wtkilFOKEzp7mgt?= =?us-ascii?Q?3pset5viBUfKbGTh83xtGYh/2brSSyUv/bavQmspX9kxhFs0AXmBRfvhSh0Y?= =?us-ascii?Q?VW9j+aubuHQm3bbFZ6XVpxX56hfn3lOPi6+cEay8i8vWNIUeSCgsrWX52kZd?= =?us-ascii?Q?axxTAAkEXW3BjVoAmeZB5FDo1hhxSMl1K2jIqrtsSZI/6irweE9NavF5czLp?= =?us-ascii?Q?eqDEMPoKGHDOMB6o4VdNiw1CRGLhG3O9Cn4J+UH+ZgIHoYQNA/qjmcSusN8F?= =?us-ascii?Q?gUhnt/PVDpNG/2TpnJnmGyO+Lz44OYfRzi4w2LbiHBTW5cQtxzEiRlSQ7Gt6?= =?us-ascii?Q?jjW/gZlETPU3TWi2VZpnLzc8gQIdT41vn6Lrl5GdXyvF9uWO5Bgl8vKX6bAh?= =?us-ascii?Q?tpwkRwYQb9ergPy7fRGsSGe1d9gPrH8FzIl7IsN7QG53lxDM3hEnUsS8pkJ2?= =?us-ascii?Q?LzelZPpmLfmhwkWbWLvKfQgnINzBsOoK/RyVMccKTXQyIIKlNGvcPBkpa73a?= =?us-ascii?Q?IFMaHxp5rxuYpcp8z7inuket58KA3fI5eFpJqPbOndaEqo6eTP2a4J40K/W5?= =?us-ascii?Q?R7Gs/71BDFNG823iwD52/IeG4P129Zx19vVxnkdoFD/JrPaaT/OP2GBBGU40?= =?us-ascii?Q?VJntqEz6b6cA73naqmy934uPJ3bxrLIneohwXyd7M+rMbB6bclMz0DnzT8yW?= =?us-ascii?Q?DJGobkvenp8XrQjTItKXaBuVypZVEBIQZ2mEFB4xpJSOrwlNk9+h8QrEvI6w?= =?us-ascii?Q?FSGu8wMPuVLkUAfBC7Zft6CafIUIQxrkO3Q98pA50XQn2C79QnINilIPVshV?= =?us-ascii?Q?ityStWKQNjJ2OBDFa5mfIKNY1LR4eJ+cOJLFRloNhudAPcq++vsRlC47iUsb?= =?us-ascii?Q?2ZPSXV5eoYLe/eGx8RKd/EchCi9JolpB25+IKi5J7V6mkRrRvOOD/tVzMI6K?= =?us-ascii?Q?ncj/SgCNkIVUuMyGoP9+nRRfrprRObURtzOfBP/O+dVIAk8Vr6choTp5KVsE?= =?us-ascii?Q?amtvnadXQrvLfttNElN60MG/6FFXROOKutvY/yGiJDl4eujI++BVBRgZCwr5?= =?us-ascii?Q?RyzjIFx5uygsznGWIpBKcyxpGo5SVDsIb/4VP5VLucPD/s5AbuuVuP0AXgpS?= =?us-ascii?Q?7Pl9Htx24lc1vdHWb+BWA8A77A712ub/TRFVfAu3N2AZJvoLdu/HQs3Fx30m?= =?us-ascii?Q?quM84oFuQ+v3eUt0o8nCggDts4Vq+QY82aIB+owbco+wryPE40IB9s1jGNsr?= =?us-ascii?Q?z1Dym0NfKGpQNjHJiG/+IadRsUXm9odFDzDkyrkFZPsbOXQRWEai2HZihrE2?= =?us-ascii?Q?8wS6AjAMH0yaghNzvgZj76aLHNr9jHfX7tMfs7uv?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f17b0c54-ed56-4442-debc-08dacb91c74f X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9448.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2022 07:27:00.5017 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 19CzhCVDoCF2uBY6ngFifAiUOjxJGSKc6YRtabuPjUlv8PFgzoIZQ5i4k+9K1g/9UTSHoEgaW9xJDqFpqgvChQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB7769 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Mailbox access functions could be share to other mhdp driver and HDP-TX HDMI/DP PHY drivers, move those functions to head file include/drm/bridge/cdns-mhdp-mailbox.h and convert them to macro functions. Signed-off-by: Sandor Yu --- .../drm/bridge/cadence/cdns-mhdp8546-core.c | 197 +------------- .../drm/bridge/cadence/cdns-mhdp8546-core.h | 1 - include/drm/bridge/cdns-mhdp-mailbox.h | 240 ++++++++++++++++++ 3 files changed, 242 insertions(+), 196 deletions(-) create mode 100644 include/drm/bridge/cdns-mhdp-mailbox.h diff --git a/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c b/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c index 31442a922502..b77b0ddcc9b3 100644 --- a/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c +++ b/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.c @@ -36,6 +36,7 @@ #include #include +#include #include #include #include @@ -55,200 +56,6 @@ #include "cdns-mhdp8546-hdcp.h" #include "cdns-mhdp8546-j721e.h" -static int cdns_mhdp_mailbox_read(struct cdns_mhdp_device *mhdp) -{ - int ret, empty; - - WARN_ON(!mutex_is_locked(&mhdp->mbox_mutex)); - - ret = readx_poll_timeout(readl, mhdp->regs + CDNS_MAILBOX_EMPTY, - empty, !empty, MAILBOX_RETRY_US, - MAILBOX_TIMEOUT_US); - if (ret < 0) - return ret; - - return readl(mhdp->regs + CDNS_MAILBOX_RX_DATA) & 0xff; -} - -static int cdns_mhdp_mailbox_write(struct cdns_mhdp_device *mhdp, u8 val) -{ - int ret, full; - - WARN_ON(!mutex_is_locked(&mhdp->mbox_mutex)); - - ret = readx_poll_timeout(readl, mhdp->regs + CDNS_MAILBOX_FULL, - full, !full, MAILBOX_RETRY_US, - MAILBOX_TIMEOUT_US); - if (ret < 0) - return ret; - - writel(val, mhdp->regs + CDNS_MAILBOX_TX_DATA); - - return 0; -} - -static int cdns_mhdp_mailbox_recv_header(struct cdns_mhdp_device *mhdp, - u8 module_id, u8 opcode, - u16 req_size) -{ - u32 mbox_size, i; - u8 header[4]; - int ret; - - /* read the header of the message */ - for (i = 0; i < sizeof(header); i++) { - ret = cdns_mhdp_mailbox_read(mhdp); - if (ret < 0) - return ret; - - header[i] = ret; - } - - mbox_size = get_unaligned_be16(header + 2); - - if (opcode != header[0] || module_id != header[1] || - req_size != mbox_size) { - /* - * If the message in mailbox is not what we want, we need to - * clear the mailbox by reading its contents. - */ - for (i = 0; i < mbox_size; i++) - if (cdns_mhdp_mailbox_read(mhdp) < 0) - break; - - return -EINVAL; - } - - return 0; -} - -static int cdns_mhdp_mailbox_recv_data(struct cdns_mhdp_device *mhdp, - u8 *buff, u16 buff_size) -{ - u32 i; - int ret; - - for (i = 0; i < buff_size; i++) { - ret = cdns_mhdp_mailbox_read(mhdp); - if (ret < 0) - return ret; - - buff[i] = ret; - } - - return 0; -} - -static int cdns_mhdp_mailbox_send(struct cdns_mhdp_device *mhdp, u8 module_id, - u8 opcode, u16 size, u8 *message) -{ - u8 header[4]; - int ret, i; - - header[0] = opcode; - header[1] = module_id; - put_unaligned_be16(size, header + 2); - - for (i = 0; i < sizeof(header); i++) { - ret = cdns_mhdp_mailbox_write(mhdp, header[i]); - if (ret) - return ret; - } - - for (i = 0; i < size; i++) { - ret = cdns_mhdp_mailbox_write(mhdp, message[i]); - if (ret) - return ret; - } - - return 0; -} - -static -int cdns_mhdp_reg_read(struct cdns_mhdp_device *mhdp, u32 addr, u32 *value) -{ - u8 msg[4], resp[8]; - int ret; - - put_unaligned_be32(addr, msg); - - mutex_lock(&mhdp->mbox_mutex); - - ret = cdns_mhdp_mailbox_send(mhdp, MB_MODULE_ID_GENERAL, - GENERAL_REGISTER_READ, - sizeof(msg), msg); - if (ret) - goto out; - - ret = cdns_mhdp_mailbox_recv_header(mhdp, MB_MODULE_ID_GENERAL, - GENERAL_REGISTER_READ, - sizeof(resp)); - if (ret) - goto out; - - ret = cdns_mhdp_mailbox_recv_data(mhdp, resp, sizeof(resp)); - if (ret) - goto out; - - /* Returned address value should be the same as requested */ - if (memcmp(msg, resp, sizeof(msg))) { - ret = -EINVAL; - goto out; - } - - *value = get_unaligned_be32(resp + 4); - -out: - mutex_unlock(&mhdp->mbox_mutex); - if (ret) { - dev_err(mhdp->dev, "Failed to read register\n"); - *value = 0; - } - - return ret; -} - -static -int cdns_mhdp_reg_write(struct cdns_mhdp_device *mhdp, u16 addr, u32 val) -{ - u8 msg[6]; - int ret; - - put_unaligned_be16(addr, msg); - put_unaligned_be32(val, msg + 2); - - mutex_lock(&mhdp->mbox_mutex); - - ret = cdns_mhdp_mailbox_send(mhdp, MB_MODULE_ID_DP_TX, - DPTX_WRITE_REGISTER, sizeof(msg), msg); - - mutex_unlock(&mhdp->mbox_mutex); - - return ret; -} - -static -int cdns_mhdp_reg_write_bit(struct cdns_mhdp_device *mhdp, u16 addr, - u8 start_bit, u8 bits_no, u32 val) -{ - u8 field[8]; - int ret; - - put_unaligned_be16(addr, field); - field[2] = start_bit; - field[3] = bits_no; - put_unaligned_be32(val, field + 4); - - mutex_lock(&mhdp->mbox_mutex); - - ret = cdns_mhdp_mailbox_send(mhdp, MB_MODULE_ID_DP_TX, - DPTX_WRITE_FIELD, sizeof(field), field); - - mutex_unlock(&mhdp->mbox_mutex); - - return ret; -} - static int cdns_mhdp_dpcd_read(struct cdns_mhdp_device *mhdp, u32 addr, u8 *data, u16 len) @@ -2058,7 +1865,7 @@ static void cdns_mhdp_atomic_disable(struct drm_bridge *bridge, struct drm_bridge_state *bridge_state) { struct cdns_mhdp_device *mhdp = bridge_to_mhdp(bridge); - u32 resp; + u32 resp = 0; dev_dbg(mhdp->dev, "%s\n", __func__); diff --git a/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.h b/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.h index bedddd510d17..10c878bf0e63 100644 --- a/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.h +++ b/drivers/gpu/drm/bridge/cadence/cdns-mhdp8546-core.h @@ -212,7 +212,6 @@ struct phy; #define MB_MODULE_ID_HDCP_TX 0x07 #define MB_MODULE_ID_HDCP_RX 0x08 #define MB_MODULE_ID_HDCP_GENERAL 0x09 -#define MB_MODULE_ID_GENERAL 0x0a /* firmware and opcodes */ #define FW_NAME "cadence/mhdp8546.bin" diff --git a/include/drm/bridge/cdns-mhdp-mailbox.h b/include/drm/bridge/cdns-mhdp-mailbox.h new file mode 100644 index 000000000000..0249322a74b0 --- /dev/null +++ b/include/drm/bridge/cdns-mhdp-mailbox.h @@ -0,0 +1,240 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Cadence MHDP Firmware Access API function by Malibox. + * + * Copyright (C) 2022 NXP Semiconductor, Inc. + * + */ +#ifndef CDNS_MHDP_MAILBOX_H +#define CDNS_MHDP_MAILBOX_H + +#include +#include + +/* mailbox regs offset */ +#define CDNS_MAILBOX_FULL 0x00008 +#define CDNS_MAILBOX_EMPTY 0x0000c +#define CDNS_MAILBOX_TX_DATA 0x00010 +#define CDNS_MAILBOX_RX_DATA 0x00014 + +#define MAILBOX_RETRY_US 1000 +#define MAILBOX_TIMEOUT_US 2000000 + +/* Module ID Code */ +#define MB_MODULE_ID_GENERAL 0x0A +#define MB_MODULE_ID_DP_TX 0x01 + +/* General Commands */ +#define GENERAL_REGISTER_WRITE 0x05 +#define GENERAL_REGISTER_READ 0x07 + +/* DP TX Command */ +#define DPTX_WRITE_FIELD 0x08 + +/* MHDP Firmware access functions by Mailbox */ +#define cdns_mhdp_mailbox_read(__mhdp) \ +({ \ + int ret, empty, val; \ +\ + WARN_ON(!mutex_is_locked(&(__mhdp)->mbox_mutex)); \ +\ + do { \ + ret = readx_poll_timeout(readl, (__mhdp)->regs + CDNS_MAILBOX_EMPTY, \ + empty, !empty, MAILBOX_RETRY_US, \ + MAILBOX_TIMEOUT_US); \ + if (ret < 0) \ + break; \ +\ + val = readl((__mhdp)->regs + CDNS_MAILBOX_RX_DATA) & 0xff; \ + } while (0); \ +\ + (ret < 0) ? ret : val; \ +}) + +#define cdns_mhdp_mailbox_write(__mhdp, __val) \ +({ \ + int ret, full; \ +\ + WARN_ON(!mutex_is_locked(&(__mhdp)->mbox_mutex)); \ +\ + do { \ + ret = readx_poll_timeout(readl, (__mhdp)->regs + CDNS_MAILBOX_FULL, \ + full, !full, MAILBOX_RETRY_US, \ + MAILBOX_TIMEOUT_US); \ + if (ret < 0) \ + break; \ +\ + writel((__val), (__mhdp)->regs + CDNS_MAILBOX_TX_DATA); \ + } while (0); \ +\ + ret; \ +}) + +#define cdns_mhdp_mailbox_recv_header(__mhdp, __module_id, __opcode, __req_size) \ +({ \ + u32 mbox_size, i; \ + u8 header[4]; \ + int ret; \ +\ + do { \ + /* read the header of the message */ \ + for (i = 0; i < sizeof(header); i++) { \ + ret = cdns_mhdp_mailbox_read(__mhdp); \ + if (ret < 0) \ + break; \ +\ + header[i] = ret; \ + } \ +\ + mbox_size = get_unaligned_be16(header + 2); \ +\ + if ((__opcode) != header[0] || (__module_id) != header[1] || \ + (__req_size) != mbox_size) { \ + /* If the message in mailbox is not what we want, we need to + * clear the mailbox by reading its contents. */ \ + for (i = 0; i < mbox_size; i++) \ + if (cdns_mhdp_mailbox_read(__mhdp) < 0) \ + break; \ +\ + ret = -EINVAL; \ + } \ +\ + ret = 0; \ +\ + } while (0); \ +\ + ret; \ +}) + +#define cdns_mhdp_mailbox_recv_data(mhdp, buff, buff_size) \ +({ \ + u32 i; \ + int ret; \ +\ + do { \ + for (i = 0; i < buff_size; i++) { \ + ret = cdns_mhdp_mailbox_read(mhdp); \ + if (ret < 0) \ + break; \ +\ + ((u8 *)buff)[i] = ret; \ + } \ +\ + ret = 0; \ +\ + } while (0); \ +\ + ret; \ +}) + +#define cdns_mhdp_mailbox_send(mhdp, module_id, opcode, size, message) \ +({ \ + u8 header[4]; \ + int ret, i; \ +\ + header[0] = opcode; \ + header[1] = module_id; \ + put_unaligned_be16(size, header + 2); \ +\ + do { \ + for (i = 0; i < sizeof(header); i++) { \ + ret = cdns_mhdp_mailbox_write(mhdp, header[i]); \ + if (ret < 0) \ + break; \ + } \ +\ + for (i = 0; i < size; i++) { \ + ret = cdns_mhdp_mailbox_write(mhdp, ((u8 *)message)[i]); \ + if (ret < 0) \ + break;; \ + } \ + ret = 0; \ + } while (0); \ +\ + ret; \ +}) + +#define cdns_mhdp_reg_read(mhdp, addr, value) \ +({ \ + u8 msg[4], resp[8]; \ + int ret; \ +\ + put_unaligned_be32(addr, msg); \ +\ + mutex_lock(&mhdp->mbox_mutex); \ +\ + do { \ + ret = cdns_mhdp_mailbox_send(mhdp, MB_MODULE_ID_GENERAL, \ + GENERAL_REGISTER_READ, \ + sizeof(msg), msg); \ + if (ret < 0) \ + break; \ +\ + ret = cdns_mhdp_mailbox_recv_header(mhdp, MB_MODULE_ID_GENERAL, \ + GENERAL_REGISTER_READ, \ + sizeof(resp)); \ + if (ret < 0) \ + break; \ +\ + ret = cdns_mhdp_mailbox_recv_data(mhdp, resp, sizeof(resp)); \ + if (ret < 0) \ + break; \ +\ + /* Returned address value should be the same as requested */ \ + if (memcmp(msg, resp, sizeof(msg))) { \ + ret = -EINVAL; \ + break; \ + } \ +\ + *((u32 *)value) = get_unaligned_be32(resp + 4); \ + ret = 0; \ + } while (0); \ +\ + mutex_unlock(&mhdp->mbox_mutex); \ + if (ret < 0) { \ + dev_err(mhdp->dev, "Failed to read register\n"); \ + *((u32 *)value) = 0; \ + } \ +\ + ret; \ +}) + +#define cdns_mhdp_reg_write(mhdp, addr, val) \ +({ \ + u8 msg[8]; \ + int ret; \ +\ + put_unaligned_be32(addr, msg); \ + put_unaligned_be32(val, msg + 4); \ +\ + mutex_lock(&mhdp->mbox_mutex); \ +\ + ret = cdns_mhdp_mailbox_send(mhdp, MB_MODULE_ID_GENERAL, \ + GENERAL_REGISTER_WRITE, sizeof(msg), msg); \ +\ + mutex_unlock(&mhdp->mbox_mutex); \ +\ + ret; \ +}) + +#define cdns_mhdp_reg_write_bit(mhdp, addr, start_bit, bits_no, val) \ +({ \ + u8 field[8]; \ + int ret; \ +\ + put_unaligned_be16(addr, field); \ + field[2] = start_bit; \ + field[3] = bits_no; \ + put_unaligned_be32(val, field + 4); \ +\ + mutex_lock(&mhdp->mbox_mutex); \ +\ + ret = cdns_mhdp_mailbox_send(mhdp, MB_MODULE_ID_DP_TX, \ + DPTX_WRITE_FIELD, sizeof(field), field); \ +\ + mutex_unlock(&mhdp->mbox_mutex); \ +\ + ret; \ +}) + +#endif -- 2.34.1