Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4637041imm; Fri, 18 May 2018 08:16:39 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpf/nFlxv598N5s0Qqc1HtkPN1iZzuOIcnvaPwQIOiE4/bA0RwdXkvsvu/AXo06T9z161+d X-Received: by 2002:a17:902:bccc:: with SMTP id o12-v6mr10029896pls.56.1526656599869; Fri, 18 May 2018 08:16:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526656599; cv=none; d=google.com; s=arc-20160816; b=TzHNnG37Qr6lnzKL+yiGNg17CZeo+em6eQn28G4RYPpGNtN8GMYtZZouKFb/RqwS8x vWY0I3PRtd3IKTrAgBHxXrw4/2x1KSA6RwEY5XwPpNEJmyslHjn+Rf2nqVLlISi54xOg jR3km4Boz35US9jZmUjMevI0KEAIakHNA9B/dd0Hf4O2QHcvji34rY753T64pWjsjDXF /0vhjPDKTeHQAmauNLRd/OG+Z6EwA+05ZWWKgeB3ZkL9sOUwQGYKh4UrCzC8rX3bLU98 QFItFti2nSq7KWK01q4SzZ2OzaU5OllfYIsmkCFOhuyWvBbkKtGerOXymTFWWqTVyV8M xtjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=8AqRe/EQ01uuo+k+sgIL0V3UzG5ik5c2lH3Q/bqvz1g=; b=J3jW034/LOqX8pD3tdjkb/Ux7pLkwVpvVh/SneKgStUx723VYGQ5CyWlbCsIoRxG69 O/nALcCN2w0i/8zbLzSeu9fgRKIDSMDSrhnze9NvjoWZ9y/YZVe1bwSvhN1xDiUat781 ssLqyIvfUm5o5B/rsKj8+TDx8jGykfyIJpgi79zz1MO6P4o6FQMcXU3AXMPDIH4pqf2g ScbqvyDozNsdzg7R81vi2r0tgwDTJZqWIgxlDFP/BIuuA3AGJ9TsCB+mvmyXoUAxY2gB PNlQ4R5auehdyIN60hePHH4eEzDslt6w4P+jFGcmOHL7aoIOtTWzEATbbHJN0lS0jvh6 sZnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=mrtEW3yF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a9-v6si7264487pls.289.2018.05.18.08.16.25; Fri, 18 May 2018 08:16:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=mrtEW3yF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752221AbeERPPN (ORCPT + 99 others); Fri, 18 May 2018 11:15:13 -0400 Received: from mail-ua0-f194.google.com ([209.85.217.194]:39386 "EHLO mail-ua0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751009AbeERPPJ (ORCPT ); Fri, 18 May 2018 11:15:09 -0400 Received: by mail-ua0-f194.google.com with SMTP id v17-v6so5585789uak.6 for ; Fri, 18 May 2018 08:15:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=8AqRe/EQ01uuo+k+sgIL0V3UzG5ik5c2lH3Q/bqvz1g=; b=mrtEW3yFTCYbWJQ5G07mQIKgNox5rPb0f+VioM3l2E/np3DK+2MiZUEXZ0JFNb86Aw 0lmBeJkAnYERnT1ST7Acf/SjUopCnY4i6TU8Tfdojus8nooW8ssMIpFB0B/EyIGSERgV pxShHBMqFxSa7bXGM6Xl9B/iSafs8b3usDIbo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=8AqRe/EQ01uuo+k+sgIL0V3UzG5ik5c2lH3Q/bqvz1g=; b=t4XZCCjb3ruvCBG7d+WsMCDezBeRCuKMDOTVWGU3kWaiZlURnq+aLuA0S3VJAV/5aB eKa6aCQUeBvDb9LbUJF2j7izVySFyRv0o4t/t0B3ISyeeFMlCi7WiQ/NCt0ac4Oo6nwg n+hU4lD/Ca905snykVeYge25SfcL5zle/7XeztAeFsTsWkK7xepLHhJtpYYzmT1eXZsJ R56EKwMbNWk26mN4FXwHq1E4B4JIvmIkEQgIh+QBl/baFr9gOp8vtZW3k5mlgL79+U/2 qBn8pjLdYcImS2GHoE1vZoFtiMZeqdmV4cJVur2b6VBGfVZBiV4LgrybFTH4kuoIKmpb X79w== X-Gm-Message-State: ALKqPweCCarwqUUrTMHtVWlX7BZASY7TN/rU0pEcNvGC9BhxV72AYjKB B0Y00NAiosWdjV6dStrhz9rDyl3n1tA= X-Received: by 2002:a9f:2d98:: with SMTP id v24-v6mr7614467uaj.5.1526656508576; Fri, 18 May 2018 08:15:08 -0700 (PDT) Received: from mail-vk0-f42.google.com (mail-vk0-f42.google.com. [209.85.213.42]) by smtp.gmail.com with ESMTPSA id 79-v6sm2627736ual.3.2018.05.18.08.15.07 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 May 2018 08:15:07 -0700 (PDT) Received: by mail-vk0-f42.google.com with SMTP id q189-v6so5034479vkb.0 for ; Fri, 18 May 2018 08:15:07 -0700 (PDT) X-Received: by 2002:a1f:3197:: with SMTP id x145-v6mr7109959vkx.3.1526656506952; Fri, 18 May 2018 08:15:06 -0700 (PDT) MIME-Version: 1.0 References: <20180515075859.17217-1-stanimir.varbanov@linaro.org> <20180515075859.17217-9-stanimir.varbanov@linaro.org> In-Reply-To: <20180515075859.17217-9-stanimir.varbanov@linaro.org> From: Tomasz Figa Date: Sat, 19 May 2018 00:14:54 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 08/29] venus: hfi_venus: fix suspend function for venus 3xx versions To: Stanimir Varbanov Cc: Mauro Carvalho Chehab , Hans Verkuil , Linux Media Mailing List , Linux Kernel Mailing List , linux-arm-msm , vgarodia@codeaurora.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 15, 2018 at 5:11 PM Stanimir Varbanov < stanimir.varbanov@linaro.org> wrote: > This fixes the suspend function for Venus 3xx versions by > add a check for WFI (wait for interrupt) bit. This bit > is on when the ARM9 is idle and entered in low power mode. > Signed-off-by: Stanimir Varbanov > --- > drivers/media/platform/qcom/venus/hfi_venus.c | 59 ++++++++++++++++-------- > drivers/media/platform/qcom/venus/hfi_venus_io.h | 1 + > 2 files changed, 41 insertions(+), 19 deletions(-) > diff --git a/drivers/media/platform/qcom/venus/hfi_venus.c b/drivers/media/platform/qcom/venus/hfi_venus.c > index 53546174aab8..aac351f699a0 100644 > --- a/drivers/media/platform/qcom/venus/hfi_venus.c > +++ b/drivers/media/platform/qcom/venus/hfi_venus.c > @@ -1447,7 +1447,7 @@ static int venus_suspend_3xx(struct venus_core *core) > { > struct venus_hfi_device *hdev = to_hfi_priv(core); > struct device *dev = core->dev; > - u32 ctrl_status, wfi_status; > + u32 ctrl_status, cpu_status; > int ret; > int cnt = 100; > @@ -1463,29 +1463,50 @@ static int venus_suspend_3xx(struct venus_core *core) > return -EINVAL; > } > - ctrl_status = venus_readl(hdev, CPU_CS_SCIACMDARG0); > - if (!(ctrl_status & CPU_CS_SCIACMDARG0_PC_READY)) { > - wfi_status = venus_readl(hdev, WRAPPER_CPU_STATUS); > + /* > + * Power collapse sequence for Venus 3xx and 4xx versions: > + * 1. Check for ARM9 and video core to be idle by checking WFI bit > + * (bit 0) in CPU status register and by checking Idle (bit 30) in > + * Control status register for video core. > + * 2. Send a command to prepare for power collapse. > + * 3. Check for WFI and PC_READY bits. > + */ > + > + while (--cnt) { > + cpu_status = venus_readl(hdev, WRAPPER_CPU_STATUS); > ctrl_status = venus_readl(hdev, CPU_CS_SCIACMDARG0); > - ret = venus_prepare_power_collapse(hdev, false); > - if (ret) { > - dev_err(dev, "prepare for power collapse fail (%d)\n", > - ret); > - return ret; > - } > + if (cpu_status & WRAPPER_CPU_STATUS_WFI && > + ctrl_status & CPU_CS_SCIACMDARG0_INIT_IDLE_MSG_MASK) > + break; > - cnt = 100; > - while (cnt--) { > - wfi_status = venus_readl(hdev, WRAPPER_CPU_STATUS); > - ctrl_status = venus_readl(hdev, CPU_CS_SCIACMDARG0); > - if (ctrl_status & CPU_CS_SCIACMDARG0_PC_READY && > - wfi_status & BIT(0)) > - break; > - usleep_range(1000, 1500); > - } > + usleep_range(1000, 1500); > } To avoid opencoding the polling, I'd suggest doing a readx_poll_timeout() trick: static bool venus_arm9_and_video_core_idle(struct venus_hfi_device *hdev) { // Read both registers and return true if both have the right bits set } static int venus_suspend_3xx(struct venus_core *core) { bool val; int ret; // ... ret = readx_poll_timeout(venus_arm9_and_video_core_idle, hdev, val, val, 1500, 100 * 1500); if (ret) return ret; // ... } > + if (!cnt) > + return -ETIMEDOUT; > + > + ret = venus_prepare_power_collapse(hdev, false); > + if (ret) { > + dev_err(dev, "prepare for power collapse fail (%d)\n", ret); > + return ret; > + } > + > + cnt = 100; > + while (--cnt) { > + cpu_status = venus_readl(hdev, WRAPPER_CPU_STATUS); > + ctrl_status = venus_readl(hdev, CPU_CS_SCIACMDARG0); > + > + if (cpu_status & WRAPPER_CPU_STATUS_WFI && > + ctrl_status & CPU_CS_SCIACMDARG0_PC_READY) > + break; > + > + usleep_range(1000, 1500); > + } > + > + if (!cnt) > + return -ETIMEDOUT; Same readx_poll_timeout() trick can be used here, with different helper function, e.g. venus_arm9_idle_and_pc_ready(). Best regards, Tomasz