From patchwork Fri Feb 10 08:59:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tinghan Shen X-Patchwork-Id: 55332 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp840434wrn; Fri, 10 Feb 2023 01:02:15 -0800 (PST) X-Google-Smtp-Source: AK7set/TCAu0S2fGu+JBNG4zn/JAKE3HRO2pbccI/P2XXL+wer6oaT5P3EAdCDtmLzNlWIJTJbI8 X-Received: by 2002:a17:90a:190f:b0:233:4454:4c81 with SMTP id 15-20020a17090a190f00b0023344544c81mr3964513pjg.16.1676019735240; Fri, 10 Feb 2023 01:02:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676019735; cv=none; d=google.com; s=arc-20160816; b=iQVZUlocJkh35D5BoCBBaVSxclJeR1W6EAocS4uOxCMtY58zN7ahZhmTrB2LyBNvYf ZeOnTd1ESB1lgTv6rwc+sHTCwye8vwaeiMTcughofI5MPXl1TMQuBTxqjlxpIz0pXU/u py4cKPH3c1uPiIuP5ZkuhHBKfwa1Jk1mDi8MP08xpieQW5hwSs1SKkHvfK38j0mFJK2+ GytMaFG+ld6rnB/AGmar3OmecLoM89Dr/FFdu7Z9J5RnFRBRtpIV4RSWcnToH37beMR0 qNhAE4rc2jO0wrVDnDLXP8VbpQRggjgPV/3t7P/XNoPwq8SNyTIONc9+puE+VJRcHzXZ 20PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=SUD3fqkoCLZDULBrwrDENF0iMnUmbMM9p2CAPvcnOzM=; b=WFJsPosmVFKkLYaDjQhRjtyRXcX3hDswwbqRD/aIuDcEFIfrsUlX4yjBsbR0Hj1b4+ rF68OD2msQw856LZZXHYsH4zOwB6tnjotpDiMmqg9sGH7lRdMuyib1EYcVAfTCNwvn6q LrY6tHZJMy4c52RNUVw4ZDUugQ2xxXeMMIgT0KwjA6tM8mLK7O0GtLToK/0pujZACEoT pwGxqwlSUOF8qnTfnIsYqrATu8Pd/u6c3gurEmBk4lutM3W5tU04osbg9GMav978eIpF dC8rIWGvk4disQG3cJMzLpxv+4emyecl2SVBeLhiQBrAIeQYzmawWg4tMlZ92OKbPZB/ TCRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=NK+FwcCg; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fz15-20020a17090b024f00b002299b3cd7acsi7330325pjb.83.2023.02.10.01.02.02; Fri, 10 Feb 2023 01:02:15 -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=@mediatek.com header.s=dk header.b=NK+FwcCg; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231819AbjBJJAR (ORCPT + 99 others); Fri, 10 Feb 2023 04:00:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231720AbjBJI7o (ORCPT ); Fri, 10 Feb 2023 03:59:44 -0500 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 194C2458A5; Fri, 10 Feb 2023 00:59:41 -0800 (PST) X-UUID: 3dbd0d3ea92111eda06fc9ecc4dadd91-20230210 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=SUD3fqkoCLZDULBrwrDENF0iMnUmbMM9p2CAPvcnOzM=; b=NK+FwcCgqGTLrpwy7UlKS0bjg6sgSL0/Z7kzVpIKh4JSNCBCqKePTgnvxHj0AzLemcv42EXZR6mb7LKpDJy3V7tyen1PKQy5bztLRbzuLJSnAgWEhlrkJak3N+5RBN1JmFiK1upl0ttm40vs2TDOCBCluKSY0y1Trk9VksC6wYg=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.19,REQID:cdd7737a-038a-4154-8113-d733bebd5265,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:95 X-CID-INFO: VERSION:1.1.19,REQID:cdd7737a-038a-4154-8113-d733bebd5265,IP:0,URL :0,TC:0,Content:0,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Spam_GS981B3D,ACTION :quarantine,TS:95 X-CID-META: VersionHash:885ddb2,CLOUDID:b2bc0ff8-ff42-4fb0-b929-626456a83c14,B ulkID:2302101659363AUZ531H,BulkQuantity:0,Recheck:0,SF:38|29|28|17|19|48,T C:nil,Content:0,EDM:-3,IP:nil,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 ,OSI:0,OSA:0,AV:0 X-CID-BVR: 0,NGT X-UUID: 3dbd0d3ea92111eda06fc9ecc4dadd91-20230210 Received: from mtkmbs13n1.mediatek.inc [(172.21.101.193)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 2062458772; Fri, 10 Feb 2023 16:59:35 +0800 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by mtkmbs10n2.mediatek.inc (172.21.101.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.3; Fri, 10 Feb 2023 16:59:34 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Fri, 10 Feb 2023 16:59:34 +0800 From: Tinghan Shen To: Bjorn Andersson , Mathieu Poirier , Rob Herring , "Krzysztof Kozlowski" , Matthias Brugger , AngeloGioacchino Del Regno , Tinghan Shen CC: , , , , , Subject: [PATCH v5 08/12] remoteproc: mediatek: Control SCP core 1 by rproc subdevice Date: Fri, 10 Feb 2023 16:59:27 +0800 Message-ID: <20230210085931.8941-9-tinghan.shen@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20230210085931.8941-1-tinghan.shen@mediatek.com> References: <20230210085931.8941-1-tinghan.shen@mediatek.com> MIME-Version: 1.0 X-MTK: N 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_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS,UNPARSEABLE_RELAY 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757434069808220737?= X-GMAIL-MSGID: =?utf-8?q?1757434069808220737?= Register SCP core 1 as a subdevice of core 0 for the boot sequence and watchdog timeout handling. The core 1 has to boot after core 0 because the SCP clock and SRAM power is controlled by SCP core 0. As for watchdog timeout handling, the remoteproc framework helps to stop/start subdevices automatically when SCP driver receives watchdog timeout event. Signed-off-by: Tinghan Shen --- drivers/remoteproc/mtk_common.h | 8 ++++ drivers/remoteproc/mtk_scp.c | 66 +++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/drivers/remoteproc/mtk_common.h b/drivers/remoteproc/mtk_common.h index 0b2c4bbb55f0..e4ef97f2d3a1 100644 --- a/drivers/remoteproc/mtk_common.h +++ b/drivers/remoteproc/mtk_common.h @@ -123,6 +123,13 @@ struct mtk_scp_cluster { struct list_head cores; }; +struct mtk_scp_core_subdev { + struct rproc_subdev subdev; + struct mtk_scp *scp; +}; + +#define to_core_subdev(d) container_of(d, struct mtk_scp_core_subdev, subdev) + struct mtk_scp { struct device *dev; struct rproc *rproc; @@ -154,6 +161,7 @@ struct mtk_scp { struct list_head elem; struct mtk_scp_cluster *cluster; + struct mtk_scp_core_subdev *core_subdev; }; /** diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c index 8e2a82174e5f..f1dfe610dfb1 100644 --- a/drivers/remoteproc/mtk_scp.c +++ b/drivers/remoteproc/mtk_scp.c @@ -854,6 +854,60 @@ static void scp_remove_rpmsg_subdev(struct mtk_scp *scp) } } +static int scp_core_subdev_start(struct rproc_subdev *subdev) +{ + struct mtk_scp_core_subdev *core_subdev = to_core_subdev(subdev); + struct mtk_scp *scp = core_subdev->scp; + + rproc_boot(scp->rproc); + + return 0; +} + +static void scp_core_subdev_stop(struct rproc_subdev *subdev, bool crashed) +{ + struct mtk_scp_core_subdev *core_subdev = to_core_subdev(subdev); + struct mtk_scp *scp = core_subdev->scp; + + rproc_shutdown(scp->rproc); +} + +static int scp_core_subdev_register(struct mtk_scp *scp) +{ + struct device *dev = scp->dev; + struct mtk_scp_core_subdev *core_subdev; + struct mtk_scp *scp_c0; + + scp_c0 = list_first_entry(&scp->cluster->cores, struct mtk_scp, elem); + if (!scp_c0) + return -ENODATA; + + core_subdev = devm_kzalloc(dev, sizeof(*core_subdev), GFP_KERNEL); + if (!core_subdev) + return -ENOMEM; + + core_subdev->scp = scp; + core_subdev->subdev.start = scp_core_subdev_start; + core_subdev->subdev.stop = scp_core_subdev_stop; + + scp->core_subdev = core_subdev; + rproc_add_subdev(scp_c0->rproc, &scp->core_subdev->subdev); + + return 0; +} + +static void scp_core_subdev_unregister(struct mtk_scp *scp) +{ + struct mtk_scp *scp_c0; + + if (scp->core_subdev) { + scp_c0 = list_first_entry(&scp->cluster->cores, struct mtk_scp, elem); + rproc_remove_subdev(scp_c0->rproc, &scp->core_subdev->subdev); + devm_kfree(scp->dev, scp->core_subdev); + scp->core_subdev = NULL; + } +} + static int scp_rproc_init(struct platform_device *pdev, struct mtk_scp_of_regs *of_regs, const struct mtk_scp_of_data *of_data, @@ -954,6 +1008,7 @@ static void scp_rproc_free(struct mtk_scp *scp) { int i; + scp_core_subdev_unregister(scp); scp_remove_rpmsg_subdev(scp); scp_ipi_unregister(scp, SCP_IPI_INIT); scp_unmap_memory_region(scp); @@ -1018,6 +1073,17 @@ static int scp_cluster_init(struct platform_device *pdev, } list_for_each_entry_safe_reverse(scp, temp, &cluster->cores, elem) { + if (!list_is_first(&scp->elem, &scp->cluster->cores)) { + ret = scp_core_subdev_register(scp); + if (ret) { + dev_err_probe(scp->dev, ret, "Failed to register as subdev\n"); + goto add_fail; + } + + /* sub cores are booted as subdevices of core 0 */ + scp->rproc->auto_boot = false; + } + ret = rproc_add(scp->rproc); if (ret) goto add_fail;