Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp2864327ybc; Wed, 13 Nov 2019 23:43:57 -0800 (PST) X-Google-Smtp-Source: APXvYqwhd9hsnjU3JNBA3VLG9lkBbb08Q2fD/wdH7XbLdHY4Tj87aHQQXznRA2v540BNaZBC/x5q X-Received: by 2002:a17:906:a457:: with SMTP id cb23mr7051563ejb.191.1573717437213; Wed, 13 Nov 2019 23:43:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573717437; cv=none; d=google.com; s=arc-20160816; b=zBFKh20QFE65Ez3XH08zRZiAnTJWvGXdygmLiZgKeba4G+IEoarPuPmgY/+5ilGsmI CKSSmfMQ2zyagL9DiqfEtaMx19UYXOdaOw6H2rCSF3n3mjgjlb1SLkoqV5oOeZfTbcid WTXjqlUbZ+dYnQEtEXz+dq3A8mfH9q4Z3Ees8L4uBSeSul73FSYaRYC/WS6X95bhOLDW k4KiNo13LrSZ8pRxZvOV8zYiug+rqlRJs5GVlAaeAuMhSFAP5doxXtJcLyEXI2YXSFWM PWlrGWCPjiTW2fVYKmNandnvLQ1TXXmBJ5g5Mjo1bNSeSrLiH9cmyPo3lUGwfIBpfHrN 1vhw== 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=b4oVKxmBs4/RCYOKu4hwaTsf6M0D7a2xIkhCkKT+Pto=; b=XQq1di2LX1neoA8js+a5lQPavsOfWiIFusxvPX7z5ThgsQ7A+pRs0P/v2ATy+xSA8c W7AMonM2zYeyB5Ie4M6YfVHN4Q935JHTOoXnlOHqf1NpefcyWi00AF4GGaB3oPLEnsHV /FHAoRttCFEOpORHNyoHvnPje1/UUzY0RNWsMSbVQT01he4zxS+v2S0PhkNmjAIvoiN6 REy6zCY3SNxNjIq05iCoz78Gy00KScGXTo7OSfvmgjQJsweDCYeIdc6LMM9gLviATCtr lX1duBahiXZg5z5FzL6F2mhYWmOumCY+ZustXajKMw56gcMjaQpSnHzalCF//5nEUn5v 7KGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=B9xFb8FN; 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 o24si3462846edc.342.2019.11.13.23.43.32; Wed, 13 Nov 2019 23:43:57 -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=B9xFb8FN; 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 S1726818AbfKNHl5 (ORCPT + 99 others); Thu, 14 Nov 2019 02:41:57 -0500 Received: from mail-ed1-f66.google.com ([209.85.208.66]:46829 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726098AbfKNHl4 (ORCPT ); Thu, 14 Nov 2019 02:41:56 -0500 Received: by mail-ed1-f66.google.com with SMTP id x11so4132631eds.13 for ; Wed, 13 Nov 2019 23:41:53 -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=b4oVKxmBs4/RCYOKu4hwaTsf6M0D7a2xIkhCkKT+Pto=; b=B9xFb8FNqh/gxYhmiXwmoboX9b0W301cObyelGcHy+jepHxS+R9vPMMrJYylMOQXlM 51z2p/t5u0IbsMSgsDBX5z2VowBIW5MPZtYErL29n1z3iPMkQrfib/Lu2WTZRChW3FXd 0zV4AvJNKL+6nlpVVhTwC7oi15bZdlzyWb7rM= 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=b4oVKxmBs4/RCYOKu4hwaTsf6M0D7a2xIkhCkKT+Pto=; b=QxB6rNy5jsKemweTZcusLe/3wYWyBHi8uct/kEhnBDJ5AS27NI7WL+MPp5hdkrUkgH lg/5ANNy7yEkHBfcBZal4EqTtXadSezZC70iiGSo4woffOYfABMVJm+6+qMQy56tBLVH sDU3zk2Lo+iN+4jf8VDW7jtSoAGT7Vqe9L5aG49HOxnMu8gJQ2I/6IjCgpcw7Rtr1cL4 sqdtmraAr982Wjn0LswVDK1LIKFezDZAZ1hjLfWf8waujZLqEKtQwCbxZ8p5KQR7V7gy pn6uta1UjsBqaZ7f2fK83+CodVonGHcznFndbpPIqjl+VZFc3jzCVEvj1w7H0Me7F1GR cuVg== X-Gm-Message-State: APjAAAUsxi4x1qNM3M4p9SdDDWhup4qFBujSFJGNLDJGLfTuZ3SW4FeA 6wFE5RtMZxv2v8ncwFtWIZB45be472ZfGB6bVWzAxA== X-Received: by 2002:a17:906:2518:: with SMTP id i24mr7155659ejb.4.1573717312605; Wed, 13 Nov 2019 23:41:52 -0800 (PST) MIME-Version: 1.0 References: <20190906100514.30803-1-roger.lu@mediatek.com> <20190906100514.30803-4-roger.lu@mediatek.com> In-Reply-To: <20190906100514.30803-4-roger.lu@mediatek.com> From: Pi-Hsun Shih Date: Thu, 14 Nov 2019 15:41:16 +0800 Message-ID: Subject: Re: [PATCH v5 3/3] PM / AVS: SVS: Introduce SVS engine To: Roger Lu Cc: Kevin Hilman , Rob Herring , Nicolas Boichat , Stephen Boyd , Fan Chen , HenryC Chen , yt.lee@mediatek.com, Angus Lin , Mark Rutland , Matthias Brugger , Nishanth Menon , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , "moderated list:ARM/Mediatek SoC support" , "moderated list:ARM/Mediatek SoC support" , open list , "open list:THERMAL" 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 Hi Roger, On Fri, Sep 6, 2019 at 6:06 PM Roger Lu wrote: > > The SVS (Smart Voltage Scaling) engine is a piece of hardware which is > used to calculate optimized voltage values of several power domains, e.g. > CPU/GPU/CCI, according to chip process corner, temperatures, and other > factors. Then DVFS driver could apply those optimized voltage values to > reduce power consumption. > > Signed-off-by: Roger Lu > --- > drivers/power/avs/Kconfig | 10 + > drivers/power/avs/Makefile | 1 + > drivers/power/avs/mtk_svs.c | 2075 +++++++++++++++++++++++++++++++++ > include/linux/power/mtk_svs.h | 23 + > 4 files changed, 2109 insertions(+) > create mode 100644 drivers/power/avs/mtk_svs.c > create mode 100644 include/linux/power/mtk_svs.h > > [...] > diff --git a/drivers/power/avs/mtk_svs.c b/drivers/power/avs/mtk_svs.c > new file mode 100644 > index 000000000000..78ec93c3a4a5 > --- /dev/null > +++ b/drivers/power/avs/mtk_svs.c > [...] > +static int svs_set_volts(struct svs_bank *svsb, bool force_update) > +{ > + u32 i, svsb_volt, opp_volt, low_temp_offset = 0; > + int zone_temp, ret; > + > + mutex_lock(&svsb->lock); > + > + /* If bank is suspended, it means init02 voltage is applied. > + * Don't need to update opp voltage anymore. > + */ > + if (svsb->suspended && !force_update) { > + pr_notice("%s: bank is suspended\n", svsb->name); > + mutex_unlock(&svsb->lock); > + return -EPERM; > + } > + > + /* get thermal effect */ > + if (svsb->phase == SVS_PHASE_MON) { > + if (svsb->svs_temp > svsb->upper_temp_bound && > + svsb->svs_temp < svsb->lower_temp_bound) { > + pr_err("%s: svs_temp is abnormal (0x%x)?\n", > + svsb->name, svsb->svs_temp); > + mutex_unlock(&svsb->lock); > + return -EINVAL; > + } > + > + ret = svs_get_zone_temperature(svsb, &zone_temp); > + if (ret) { > + pr_err("%s: cannot get zone \"%s\" temperature\n", > + svsb->name, svsb->zone_name); > + pr_err("%s: add low_temp_offset = %u\n", > + svsb->name, svsb->low_temp_offset); > + zone_temp = svsb->low_temp_threashold; > + } > + > + if (zone_temp <= svsb->low_temp_threashold) > + low_temp_offset = svsb->low_temp_offset; > + } > + > + /* vmin <= svsb_volt (opp_volt) <= signed-off voltage */ > + for (i = 0; i < svsb->opp_count; i++) { > + if (svsb->phase == SVS_PHASE_MON) { > + svsb_volt = max((svsb->volts[i] + svsb->volt_offset + > + low_temp_offset), svsb->vmin); > + opp_volt = svs_volt_to_opp_volt(svsb_volt, > + svsb->volt_step, > + svsb->volt_base); > + } else if (svsb->phase == SVS_PHASE_INIT02) { > + svsb_volt = max((svsb->init02_volts[i] + > + svsb->volt_offset), svsb->vmin); > + opp_volt = svs_volt_to_opp_volt(svsb_volt, > + svsb->volt_step, > + svsb->volt_base); > + } else if (svsb->phase == SVS_PHASE_ERROR) { > + opp_volt = svsb->opp_volts[i]; > + } else { > + pr_err("%s: unknown phase: %u?\n", > + svsb->name, svsb->phase); > + mutex_unlock(&svsb->lock); > + return -EINVAL; > + } > + > + opp_volt = min(opp_volt, svsb->opp_volts[i]); > + ret = dev_pm_opp_adjust_voltage(svsb->dev, svsb->opp_freqs[i], > + opp_volt); The version of this function in opp tree (https://git.kernel.org/pub/scm/linux/kernel/git/vireshk/pm.git/commit/?h=opp/linux-next&id=25cb20a212a1f989385dfe23230817e69c62bee5) has a different function signature, so this should be changed too. > + if (ret) { > + pr_err("%s: set voltage failed: %d\n", svsb->name, ret); > + mutex_unlock(&svsb->lock); > + return ret; > + } > + } > + > + mutex_unlock(&svsb->lock); > + > + return 0; > +} > + > [...] > +static int svs_init01(struct mtk_svs *svs) > +{ > + const struct svs_platform *svsp = svs->platform; > + struct svs_bank *svsb; > + struct pm_qos_request qos_request = { {0} }; > + unsigned long flags, time_left; > + bool search_done; > + int ret = -EINVAL; > + u32 opp_freqs, opp_vboot, buck_volt, idx, i; > + > + /* Let CPUs leave idle-off state for initializing svs_init01. */ > + pm_qos_add_request(&qos_request, PM_QOS_CPU_DMA_LATENCY, 0); > + > + /* Sometimes two svs_bank use the same buck. > + * Therefore, we set each svs_bank to vboot voltage first. > + */ > + for (idx = 0; idx < svsp->bank_num; idx++) { > + svsb = &svsp->banks[idx]; > + search_done = false; > + > + if (!svsb->init01_support) > + continue; > + > + ret = regulator_set_mode(svsb->buck, REGULATOR_MODE_FAST); > + if (ret) > + pr_notice("%s: fail to set fast mode: %d\n", > + svsb->name, ret); > + > + if (svsb->mtcmos_request) { > + ret = regulator_enable(svsb->buck); > + if (ret) { > + pr_err("%s: fail to enable %s power: %d\n", > + svsb->name, svsb->buck_name, ret); > + goto init01_finish; > + } > + > + ret = dev_pm_domain_attach(svsb->dev, false); > + if (ret) { > + pr_err("%s: attach pm domain fail: %d\n", > + svsb->name, ret); > + goto init01_finish; > + } > + > + pm_runtime_enable(svsb->dev); > + ret = pm_runtime_get_sync(svsb->dev); > + if (ret < 0) { > + pr_err("%s: turn mtcmos on fail: %d\n", > + svsb->name, ret); > + goto init01_finish; > + } > + } > + > + /* Find the fastest freq that can be run at vboot and > + * fix to that freq until svs_init01 is done. > + */ > + opp_vboot = svs_volt_to_opp_volt(svsb->vboot, > + svsb->volt_step, > + svsb->volt_base); > + > + for (i = 0; i < svsb->opp_count; i++) { > + opp_freqs = svsb->opp_freqs[i]; > + if (!search_done && svsb->opp_volts[i] <= opp_vboot) { > + ret = dev_pm_opp_adjust_voltage(svsb->dev, > + opp_freqs, > + opp_vboot); Same here. > + if (ret) { > + pr_err("%s: set voltage failed: %d\n", > + svsb->name, ret); > + goto init01_finish; > + } > + > + search_done = true; > + } else { > + dev_pm_opp_disable(svsb->dev, > + svsb->opp_freqs[i]); > + } > + } > + } > + > + for (idx = 0; idx < svsp->bank_num; idx++) { > + svsb = &svsp->banks[idx]; > + svs->bank = svsb; > + > + if (!svsb->init01_support) > + continue; > + > + opp_vboot = svs_volt_to_opp_volt(svsb->vboot, > + svsb->volt_step, > + svsb->volt_base); > + > + buck_volt = regulator_get_voltage(svsb->buck); > + if (buck_volt != opp_vboot) { > + pr_err("%s: buck voltage: %u, expected vboot: %u\n", > + svsb->name, buck_volt, opp_vboot); > + ret = -EPERM; > + goto init01_finish; > + } > + > + init_completion(&svsb->init_completion); > + flags = claim_mtk_svs_lock(); > + svs_set_phase(svs, SVS_PHASE_INIT01); > + release_mtk_svs_lock(flags); > + time_left = > + wait_for_completion_timeout(&svsb->init_completion, > + msecs_to_jiffies(2000)); > + if (time_left == 0) { > + pr_err("%s: init01 completion timeout\n", svsb->name); > + ret = -EBUSY; > + goto init01_finish; > + } > + } > + > +init01_finish: > + for (idx = 0; idx < svsp->bank_num; idx++) { > + svsb = &svsp->banks[idx]; > + > + if (!svsb->init01_support) > + continue; > + > + for (i = 0; i < svsb->opp_count; i++) > + dev_pm_opp_enable(svsb->dev, svsb->opp_freqs[i]); > + > + if (regulator_set_mode(svsb->buck, REGULATOR_MODE_NORMAL)) > + pr_notice("%s: fail to set normal mode: %d\n", > + svsb->name, ret); > + > + if (svsb->mtcmos_request) { > + if (pm_runtime_put_sync(svsb->dev)) > + pr_err("%s: turn mtcmos off fail: %d\n", > + svsb->name, ret); > + pm_runtime_disable(svsb->dev); > + dev_pm_domain_detach(svsb->dev, 0); > + if (regulator_disable(svsb->buck)) > + pr_err("%s: fail to disable %s power: %d\n", > + svsb->name, svsb->buck_name, ret); > + } > + } > + > + pm_qos_remove_request(&qos_request); > + > + return ret; > +} > + > [...]