Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1460133ybl; Wed, 18 Dec 2019 19:43:50 -0800 (PST) X-Google-Smtp-Source: APXvYqxQtzcbzBNvp7NVY64xmaS/EV71gbYHeg8yfF3QvtM4NZl3SkyIoiZu/lEf8x8HpdX6wO6j X-Received: by 2002:a9d:7ada:: with SMTP id m26mr6632368otn.111.1576727030843; Wed, 18 Dec 2019 19:43:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576727030; cv=none; d=google.com; s=arc-20160816; b=quOBDNgs5sfVN5j7tFErCbxBk3XRuxFiummela9fOTfMhSrcytWd9aDkK+BP67NtCS otAb0ka67VhfXOAEpaaG2wonpgnDW4xpp6n0xzcIW/st+IAY4PsIqkvDxOIteizgXCwY ylaGmOYFVrZTijvhTCTw83UjPtHu6Jg8gwEYRvvuqqOm+WPN7OMqs+s1dVEohRrVpXlr IfG3edxzuZnXAmlDdGz3jFwiysaAELrTQao4J+7Eo3z7jXv6iMD1A/IIKgn91y0JZaUP NokEp/L8pDzGN0PpeUpH3baULjug9OsSWGjaoi0SJLmEGvpgIKR+D9Nndi+FvnfoT3DQ h4aQ== 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; bh=O6LOFVunh/OJDC7JvnA4isOAWmQTXpcdKGgNnEbH64k=; b=s9+f+hDTp85Q/qkpOLnV4BSlwtFoMDn1Ya8djfZ1cfo2fWp5TEEmtOIfpLwtrvYYGP tH5NP5XvAFk52SjFyuahQ9m2FqthXV4mLvxVTdkzQ7lbaVMubsN81ViiuAji6Hfoj5Pd i2tD7GgughUw1K5uSiYd9PyNVNX3nO3SzHRXkvuP4hRc4YHIQ7g4QZFy17n+bC+OWxDw RSKjXcu1Luwri0fQ2Q73D0kvBn1dI9RynGEKnjjZrvhy7AbylCJ50MlHRCzaHmjp83ZI 68fF8RKBMP+/agULOfFieluUgsXFTrwp7Ql6x8aZdZjyjxxGNOoUwr1VcaPm0PAtuFZB 8RDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=TpULE9OX; 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 w5si2767358otq.238.2019.12.18.19.43.38; Wed, 18 Dec 2019 19:43:50 -0800 (PST) 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=TpULE9OX; 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 S1726841AbfLSDma (ORCPT + 99 others); Wed, 18 Dec 2019 22:42:30 -0500 Received: from mail-qk1-f193.google.com ([209.85.222.193]:46553 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726779AbfLSDma (ORCPT ); Wed, 18 Dec 2019 22:42:30 -0500 Received: by mail-qk1-f193.google.com with SMTP id r14so3484612qke.13 for ; Wed, 18 Dec 2019 19:42:30 -0800 (PST) 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=O6LOFVunh/OJDC7JvnA4isOAWmQTXpcdKGgNnEbH64k=; b=TpULE9OXsOToVRsqIEUUz/0B5xzbX3OOmWBLyc4F5l6u3dO1p8OyzXbWfPNaWQy/Q9 oFe99o0qfiy2B83AF2rbUCC0TwM4oTtWJhe97usSuT8iNv4jUH11GbTHJn0uNooIQdAt vJqLFDMdnIOQsjKsyCNjK5+w0TSJK6ToFOiNg= 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=O6LOFVunh/OJDC7JvnA4isOAWmQTXpcdKGgNnEbH64k=; b=g6t56k9wpuK6y5+r2KLIxY1ClTGxAbB7VgvBlBOa4FAnETvzkWtdhYxc4bwxyT8JDO Dhx6BzoRpDRw2aq8kopFdEshc2ixE+uisRgr+GizGJZuqisQHaKA4y29sFu6FwhpQhDt 5XsGUl4enCpyKlfFvKEm+9eMzsG4YTXBAM2/4DkNssCipBo6f4iZMxJu0qiOaeAC8SnI k09wXxvGPznrQR8gHWWmEOQnN/47K8/w9MrB+0GBvXlN24ghjwNh8IShUw1BOvuaASFm CbuTrab1yJwfZnCZ92Qkf6BsD3q5K/R0XyHjqtrTUlbdOpvIu9OHiy4DBjr4nJFJGF81 GNpA== X-Gm-Message-State: APjAAAVhpHu3+F1rxyRQsGgFGIdFgH+hz4dLzBvZCoKGMZtijdoFR4LX H4BJ9KZijBD+x6LwJHHPeX46/syzHompZwmubUELoA== X-Received: by 2002:a37:6551:: with SMTP id z78mr6443627qkb.144.1576726949364; Wed, 18 Dec 2019 19:42:29 -0800 (PST) MIME-Version: 1.0 References: <1575960413-6900-1-git-send-email-weiyi.lu@mediatek.com> <1575960413-6900-5-git-send-email-weiyi.lu@mediatek.com> <1576551056.14035.19.camel@mtksdaap41> <1576635932.13343.8.camel@mtksdaap41> In-Reply-To: <1576635932.13343.8.camel@mtksdaap41> From: Nicolas Boichat Date: Thu, 19 Dec 2019 11:42:18 +0800 Message-ID: Subject: Re: [PATCH v9 4/9] soc: mediatek: Add multiple step bus protection control To: Weiyi Lu Cc: Matthias Brugger , Rob Herring , James Liao , Fan Chen , linux-arm Mailing List , lkml , "moderated list:ARM/Mediatek SoC support" , srv_heupstream , Yong Wu 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 Wed, Dec 18, 2019 at 10:25 AM Weiyi Lu wrote: > > On Tue, 2019-12-17 at 13:33 +0800, Nicolas Boichat wrote: > > On Tue, Dec 17, 2019 at 10:51 AM Weiyi Lu wrote: > > > > > > On Mon, 2019-12-16 at 15:21 +0800, Nicolas Boichat wrote: > > > > On Tue, Dec 10, 2019 at 2:47 PM Weiyi Lu wrote: > > > > > > > > > > Both MT8183 & MT6765 have more control steps of bus protection > > > > > than previous project. And there add more bus protection registers > > > > > reside at infracfg & smi-common. Also add new APIs for multiple > > > > > step bus protection control with more customized arguments. > > > > > > > > > > Signed-off-by: Weiyi Lu > > > > > --- > > > > > drivers/soc/mediatek/Makefile | 2 +- > > > > > drivers/soc/mediatek/mtk-scpsys-ext.c | 99 +++++++++++++++++++++++++++++++++ > > > > > drivers/soc/mediatek/mtk-scpsys.c | 39 +++++++++---- > > > > > include/linux/soc/mediatek/scpsys-ext.h | 39 +++++++++++++ > > > > > 4 files changed, 168 insertions(+), 11 deletions(-) > > > > > create mode 100644 drivers/soc/mediatek/mtk-scpsys-ext.c > > > > > create mode 100644 include/linux/soc/mediatek/scpsys-ext.h > > > > > > > > > > diff --git a/drivers/soc/mediatek/Makefile b/drivers/soc/mediatek/Makefile > > > > > index b017330..b442be9 100644 > > > > > --- a/drivers/soc/mediatek/Makefile > > > > > +++ b/drivers/soc/mediatek/Makefile > > > > > @@ -1,5 +1,5 @@ > > > > > # SPDX-License-Identifier: GPL-2.0-only > > > > > obj-$(CONFIG_MTK_CMDQ) += mtk-cmdq-helper.o > > > > > -obj-$(CONFIG_MTK_INFRACFG) += mtk-infracfg.o > > > > > +obj-$(CONFIG_MTK_INFRACFG) += mtk-infracfg.o mtk-scpsys-ext.o > > > > > obj-$(CONFIG_MTK_PMIC_WRAP) += mtk-pmic-wrap.o > > > > > obj-$(CONFIG_MTK_SCPSYS) += mtk-scpsys.o > > > > > diff --git a/drivers/soc/mediatek/mtk-scpsys-ext.c b/drivers/soc/mediatek/mtk-scpsys-ext.c > > > > > new file mode 100644 > > > > > index 0000000..4f1adda > > > > > --- /dev/null > > > > > +++ b/drivers/soc/mediatek/mtk-scpsys-ext.c > > > > > @@ -0,0 +1,99 @@ > > > > > +// SPDX-License-Identifier: GPL-2.0 > > > > > +/* > > > > > + * Copyright (c) 2018 MediaTek Inc. > > > > > + * Author: Owen Chen > > > > > + */ > > > > > +#include > > > > > +#include > > > > > +#include > > > > > +#include > > > > > +#include > > > > > + > > > > > +#define MTK_POLL_DELAY_US 10 > > > > > +#define MTK_POLL_TIMEOUT USEC_PER_SEC > > > > > + > > > > > +static int set_bus_protection(struct regmap *map, u32 mask, u32 ack_mask, > > > > > + u32 reg_set, u32 reg_sta, u32 reg_en) > > > > > +{ > > > > > + u32 val; > > > > > + > > > > > + if (reg_set) > > > > > + regmap_write(map, reg_set, mask); > > > > > + else > > > > > + regmap_update_bits(map, reg_en, mask, mask); > > > > > > > > At least for 8183, we never seen to use the reg_set case, can we > > > > simplify this function? > > > > > > > > > > Actually 6765 will use it and all the other MediaTek chips at least in > > > near future. > > > https://patchwork.kernel.org/patch/11042003/ > > > > Ok, that's fine then. > > > > > > > + > > > > > + return regmap_read_poll_timeout(map, reg_sta, > > > > > + val, (val & ack_mask) == ack_mask, > > > > > + MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT); > > > > > > > > From 8183, I see that you have either: > > > > 1. mask == ack_mask > > > > 2. ack_mask == 0 (essentially this skips this test) > > > > > > > > Would it be simpler to just skip this test if reg_sta == 0, and always > > > > assume mask == ack_mask otherwise? > > > > > > > > e.g. > > > > if (reg_sta == 0) > > > > return 0; > > > > > > > > return regmap_read_poll_timeout(map, reg_sta, > > > > val, (val & mask) == mask, > > > > MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT); > > > > > > > > > > I'm not sure if you mean ack_mask == 0? > > > reg_sta would be possible to be 0 because it's a register address > > > offset. > > > > Right, so maybe "0" is not a good invalid value, or maybe you can have a > > #define REG_STA_INVALID U32_MAX > > > > And then test for: > > if (reg_sta == REG_STA_INVALID) > > return 0; > > > > My point here is that mask and ack_mask are always the same (unless > > you don't care about reading back the status), so maybe you only need > > to specify mask? > > > > (but if you need different mask and ack_mask for future chips, feel > > free to ignore) > > > > I do need different mask and ack_mask. > For the special case of 8183 here, we still have to check the ack status > when setting bus protection but only ignore the ack status when clearing > bus protection. > > case A. > SET: reg_set, reg_sta, mask == ack mask > CLEAR: reg_clr, reg_sta, mask == clear ack mask > > case B. (the special case we discussed) > SET: reg_set, reg_sta, mask == ack mask > CLEAR: reg_clr, reg_sta, mask != clear ack mask(which is 0 now) > > If I use the REG_STA_INVALID to replace the clear ack mask way. > I might need two reg_sta to satisfy the check of set and clear bus > protection. > One is valid for setting case and another is invalid for clearing case, > e.g. case 2 below > > case 1. > SET: reg_set, reg_sta(valid), mask == ack mask > CLEAR: reg_clr, reg_sta(valid), mask == ack mask > > case 2. > SET: reg_set, reg_sta(valid), mask == ack mask > CLEAR: reg_clr, reg_sta(invalid then return), mask == ack mask > > so I'd like to keep the original proposal. What do you think? Ooh, I see. This is quite confusing to be honest... I wonder if it wouldn't be clearer to have a boolean instead in bus_prot (something like "clk_no_check", can't find a better name right now).