Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / Atom feed
From: andrew-sh.cheng <andrew-sh.cheng@mediatek.com>
To: Chanwoo Choi <cw00.choi@samsung.com>
Cc: Mark Rutland <mark.rutland@arm.com>,
	devicetree@vger.kernel.org, srv_heupstream@mediatek.com,
	linux-pm@vger.kernel.org, Viresh Kumar <viresh.kumar@linaro.org>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	linux-kernel@vger.kernel.org, Rob Herring <robh+dt@kernel.org>,
	fan.chen@mediatek.com, Kyungmin Park <kyungmin.park@samsung.com>,
	MyungJoo Ham <myungjoo.ham@samsung.com>,
	linux-mediatek@lists.infradead.org,
	Matthias Brugger <matthias.bgg@gmail.com>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH 3/3] devfreq: add mediatek cci devfreq
Date: Sat, 16 Feb 2019 14:16:39 +0800
Message-ID: <1550297799.23797.29.camel@mtksdaap41> (raw)
In-Reply-To: <3ff7ac1c-6234-1b82-d38d-389906d295e9@samsung.com>

On Tue, 2019-02-12 at 13:06 +0900, Chanwoo Choi wrote:
> Hi Andrew-sh.Cheng,
> 
> On 19. 1. 29. 오후 3:35, Andrew-sh Cheng wrote:
> > From: "Andrew-sh.Cheng" <andrew-sh.cheng@mediatek.com>
> > 
> > For big/little cpu cluster architecture,
> > not only CPU frequency, but CCI frequency will also affect performance.
> > 
> > Little cores and cci share the same buck in Mediatek mt8183 IC,
> > so we add a CCI devfreq which will get notification when buck voltage
> > is changed, then CCI devfreq can set cci frequency as high as possible.
> > 
> > Signed-off-by: Andrew-sh.Cheng <andrew-sh.cheng@mediatek.com>
> > ---
> >  drivers/devfreq/Kconfig              |   9 ++
> >  drivers/devfreq/Makefile             |   1 +
> >  drivers/devfreq/mt8183-cci-devfreq.c | 224 +++++++++++++++++++++++++++++++++++
> >  3 files changed, 234 insertions(+)
> >  create mode 100644 drivers/devfreq/mt8183-cci-devfreq.c
> > 
> > diff --git a/drivers/devfreq/Kconfig b/drivers/devfreq/Kconfig
> > index 6a172d3..0b14aab 100644
> > --- a/drivers/devfreq/Kconfig
> > +++ b/drivers/devfreq/Kconfig
> > @@ -113,6 +113,15 @@ config ARM_RK3399_DMC_DEVFREQ
> >            It sets the frequency for the memory controller and reads the usage counts
> >            from hardware.
> >  
> > +config ARM_MT8183_CCI_DEVFREQ
> > +	tristate "MT8183 CCI DEVFREQ Driver"
> > +	depends on ARM_MEDIATEK_CPUFREQ
> > +	help
> > +		This adds devfreq for cci clock
> > +		which is shared the same regulator with cpu cluster.
> > +		It can track buck voltage and update a proper cci frequency.
> > +		Use notification to get regulator status.
> > +
> 
> Move ARM_MT8183_CCI_DEVFREQ under ARM_EXYNOS_BUS_DEVFREQ.
> On later, I'll change the order between ARM_TEGRA_DEVFREQ and ARM_RK3399_DMC_DEVFREQ
> alphabetically. So, you better to keep the order of name.
OK.
> 
> 
> >  source "drivers/devfreq/event/Kconfig"
> >  
> >  endif # PM_DEVFREQ
> > diff --git a/drivers/devfreq/Makefile b/drivers/devfreq/Makefile
> > index 32b8d4d..25afe8c 100644
> > --- a/drivers/devfreq/Makefile
> > +++ b/drivers/devfreq/Makefile
> > @@ -11,6 +11,7 @@ obj-$(CONFIG_DEVFREQ_GOV_PASSIVE)	+= governor_passive.o
> >  obj-$(CONFIG_ARM_EXYNOS_BUS_DEVFREQ)	+= exynos-bus.o
> >  obj-$(CONFIG_ARM_RK3399_DMC_DEVFREQ)	+= rk3399_dmc.o
> >  obj-$(CONFIG_ARM_TEGRA_DEVFREQ)		+= tegra-devfreq.o
> > +obj-$(CONFIG_ARM_MT8183_CCI_DEVFREQ)	+= mt8183-cci-devfreq.o
> 
> Move it under obj-$(CONFIG_ARM_EXYNOS_BUS_DEVFREQ).
OK.
> 
> >  
> >  # DEVFREQ Event Drivers
> >  obj-$(CONFIG_PM_DEVFREQ_EVENT)		+= event/
> > diff --git a/drivers/devfreq/mt8183-cci-devfreq.c b/drivers/devfreq/mt8183-cci-devfreq.c
> > new file mode 100644
> > index 0000000..4837892
> > --- /dev/null
> > +++ b/drivers/devfreq/mt8183-cci-devfreq.c
> > @@ -0,0 +1,224 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +//
> > +// Copyright (c) 2018 MediaTek Inc.
> 
> Add blank line and change year 2018 -> 2019.
OK.
> 
> > +#include <linux/cpu.h>
> > +#include <linux/cpufreq.h>
> 
> This driver doesn't use any helper function of cpufreq.h/cpu.h.
> It depends on devfreq/regulator framework. Please remove them.
I will remove it in next patch.
> 
> > +#include <linux/devfreq.h>
> > +#include <linux/module.h>
> > +#include <linux/of.h>
> > +#include <linux/platform_device.h>
> > +#include <linux/regulator/consumer.h>
> > +
> > +#include "governor.h"
> > +
> > +struct cci_devfreq_data {
> > +	struct devfreq		*devfreq;
> > +	struct regulator	*proc_reg;
> > +	struct clk		*cci_clk;
> > +	unsigned long		buck_volt;
> > +	int			volt_increasing;
> > +	struct notifier_block	nb;
> > +};
> > +
> > +static int mtk_cci_governor_get_target(struct devfreq *devfreq,
> > +				       unsigned long *freq)
> > +{
> > +	struct cci_devfreq_data *cci_devdata;
> > +	int	i, opp_count;
> > +	struct dev_pm_opp	*opp;
> > +	unsigned long	opp_rate, opp_voltage;
> 
> Above three definitions use the tab for indentation. Please use space.
OK.
> 
> > +
> > +	cci_devdata = dev_get_drvdata(devfreq->dev.parent);
> > +
> > +	/* find available frequency */
> > +	opp_count = dev_pm_opp_get_opp_count(devfreq->dev.parent);
> > +	for (i = 0, opp_rate = ULONG_MAX; i < opp_count; i++, opp_rate--) {
> > +		opp = dev_pm_opp_find_freq_floor(devfreq->dev.parent,
> > +						 &opp_rate);
> > +		opp_voltage = dev_pm_opp_get_voltage(opp);
> > +		dev_pm_opp_put(opp);
> > +
> > +		if (opp_voltage <= cci_devdata->buck_volt)
> > +			break;
> > +	}
> > +	*freq = opp_rate;
> > +
> > +	return 0;
> > +}
> > +
> > +static int mtk_cci_governor_event_handler(struct devfreq *devfreq,
> > +					  unsigned int event, void *data)
> > +{
> > +	return 0;
> > +}
> 
> The devfreq core enables the governor with using DEVFREQ_GOV_START.
> But, this driver just start after proving the device driver. It break
> the previous sequence of governor.
> 
> So, if you register/unregister the regulator as following,
> it can keep the existing sequence for governor starting.
> 
> 	case DEVFREQ_GOV_START:
> 	case DEVFREQ_GOV_RESUME:
> 		regulator_register_notifier(...);
> 
> 	case DEVFREQ_GOV_STOP:
> 	case DEVFREQ_GOV_SUSPEND:
> 		regulator_unregister_notifier(...);
> 		break;
I will move regulator register/unregister notifier to
governor event handler as above in next patch.
> 
> > +
> > +static struct devfreq_governor mtk_cci_devfreq_governor = {
> > +	.name = "voltage_monitor",
> > +	.get_target_freq = mtk_cci_governor_get_target,
> > +	.event_handler = mtk_cci_governor_event_handler,
> > +};
> > +
> > +static int mtk_cci_devfreq_target(struct device *dev, unsigned long *freq,
> > +				  u32 flags)
> > +{
> > +	struct cci_devfreq_data *cci_devdata;
> > +
> > +	cci_devdata = dev_get_drvdata(dev);
> 
> You better to modify it as following:
> 
> 	struct cci_devfreq_data *cci_devdata = dev_get_drvdata(dev);
> 	
> 	if (!cci_devdata)
> 		return -EINVAL;
I will modify it in next patch
> 
> > +
> > +	clk_set_rate(cci_devdata->cci_clk, *freq);
> > +
> > +	return 0;
> > +}
> > +
> > +static struct devfreq_dev_profile cci_devfreq_profile = {
> > +	.polling_ms	= 0,
> 
> Dont' need to initialize it as zero. just remove this line.
OK.
> 
> > +	.target		= mtk_cci_devfreq_target,
> > +};
> > +
> > +static int cci_devfreq_regulator_notifier(struct notifier_block *nb,
> > +					  unsigned long val, void *data)
> > +{
> > +	struct cci_devfreq_data *cci_devdata =
> > +		container_of(nb, struct cci_devfreq_data, nb);
> > +
> > +	/* deal with reduce frequency */
> > +	if (val & REGULATOR_EVENT_PRE_VOLTAGE_CHANGE) {
> > +		struct pre_voltage_change_data *pvc_data = data;
> > +
> > +		if (pvc_data->old_uV > pvc_data->min_uV) {
> > +			cci_devdata->volt_increasing = 0;
> 
> IMO, 'volt_increasing' is not clear. Instead, cci_devdata
> could have the 'previous_voltage' variable instead of volt_increasing.
> And you could use 'previous_voltage' for comparision.
OK, I will remove volt_increasing in next patch.
> 
> > +			cci_devdata->buck_volt =
> > +				(unsigned long)(pvc_data->min_uV);
> > +			mutex_lock(&cci_devdata->devfreq->lock);
> > +			update_devfreq(cci_devdata->devfreq);
> > +			mutex_unlock(&cci_devdata->devfreq->lock);
> > +		} else {
> > +			cci_devdata->volt_increasing = 1;
> > +		}
> > +	}
> > +	/* deal with abort reduce frequency */
> > +	if ((val & REGULATOR_EVENT_ABORT_VOLTAGE_CHANGE) ||
> 
> if -> else if
> 
> At the same time, receives only one notification.
> It is not necessary to check the two if statement always, .
OK, I will separate it in next patch.
> 
> 
> 
> > +	    /* deal with increase frequency */
> > +	    ((val & REGULATOR_EVENT_VOLTAGE_CHANGE) &&
> > +	     cci_devdata->volt_increasing == 1)) {
> > +		cci_devdata->buck_volt = (unsigned long)data;
> > +		mutex_lock(&cci_devdata->devfreq->lock);
> > +		update_devfreq(cci_devdata->devfreq);
> > +		mutex_unlock(&cci_devdata->devfreq->lock);
> > +	}
> > +
> > +	return 0;
> > +}
> > +
> > +static int mtk_cci_devfreq_probe(struct platform_device *pdev)
> > +{
> > +	struct device *cci_dev = &pdev->dev;
> > +	struct cci_devfreq_data *cci_devdata;
> > +	struct notifier_block *nb;
> > +	int ret;
> > +
> > +	dev_pm_opp_of_add_table(&pdev->dev);
> 
> Move it after getting clock/regulator. After checking that all resourcess are available,
> and then you better to get the opp table. And check the return value  of dev_pm_opp...()
> 
OK. I will move it after checking clock/regulator are available, and add
return value checking. 
> > +
> > +	cci_devdata = devm_kzalloc(cci_dev, sizeof(*cci_devdata), GFP_KERNEL);
> > +	if (!cci_devdata)
> > +		return -ENOMEM;
> > +	nb = &cci_devdata->nb;
> > +	cci_devdata->cci_clk = ERR_PTR(-ENODEV);
> 
> It should be handled when error happen. It is not good for readability.
I will remove it in next patch.
> 
> > +	cci_devdata->proc_reg = ERR_PTR(-ENODEV);
> 
> ditto.
I will remove it in next patch.
> 
> > +
> > +	cci_devdata->cci_clk = clk_get(cci_dev, "cci_clock");
> > +	ret = PTR_ERR_OR_ZERO(cci_devdata->cci_clk);
> > +	if (ret) {
> > +		if (ret == -EPROBE_DEFER)
> > +			pr_err("cci clock not ready, retry\n");
> 
> You should use 'dev_err' instead of pr_err on this driver.
> 
> I think that don't show the error when EPROBE_DEFER. you better to just return.
I will change pr_err to dev_err, and remove the log with EPROBE_DEFER in
next patch.
> 
> > +		else
> > +			pr_err("no clock for cci: %d\n", ret);
> 
> How about changing the log like below?
> "failed to get clock for CCI"
OK.
> 
> pr_err -> dev_err
> 
> > +
> > +		goto out_free_resources;
> > +	}
> > +
> > +	cci_devdata->proc_reg = regulator_get_optional(cci_dev, "proc");
> > +	ret = PTR_ERR_OR_ZERO(cci_devdata->proc_reg);
> > +	if (ret) {
> > +		if (ret == -EPROBE_DEFER)
> > +			pr_err("cci regulator not ready, retry\n");
> 
> ditto.
> 
> > +		else
> > +			pr_err("no regulator for cci: %d\n", ret);
> 
> How about changing the log like below?
> "failed to get regulator for CCI"
OK.
> 
> > +
> > +		goto out_free_resources;
> > +	}
> > +
> > +	platform_set_drvdata(pdev, cci_devdata);
> > +
> > +	/* create cci_devfreq and add to cci device.
> > +	 * governor is voltage_monitor.
> > +	 * governor will get platform_device data to make decision.
> > +	 */
> 
> I think that you don't need to explain the kind of governor and how to
> decide the next frequency by governor. It is enough to call the devm_devfreq_add_device.
I will remove these explanation in next patch.
> 
> > +	cci_devdata->devfreq = devm_devfreq_add_device(cci_dev,
> > +						       &cci_devfreq_profile,
> > +						       "voltage_monitor",
> > +						       NULL);
> > +
> > +	nb->notifier_call = cci_devfreq_regulator_notifier;
> > +	regulator_register_notifier(cci_devdata->proc_reg,
> > +				    nb);
> 
> As I commented, regulator_register_notifier() should be handled in event_handler function.
OK. I will move it into governor event handler
> 
> > +
> > +	return 0;
> > +
> > +out_free_resources:
> > +	if (!IS_ERR(cci_devdata->cci_clk))
> > +		clk_put(cci_devdata->cci_clk);
> > +	if (!IS_ERR(cci_devdata->proc_reg))
> > +		regulator_put(cci_devdata->proc_reg);
> > +
> > +	return ret;
> > +}
> > +
> > +static const struct of_device_id mediatek_cci_devfreq_of_match[] = {
> > +	{ .compatible = "mediatek,mt8183-cci" },
> > +	{ },
> > +};
> > +MODULE_DEVICE_TABLE(of, mediatek_cci_devfreq_of_match);
> > +
> > +static struct platform_driver cci_devfreq_driver = {
> > +	.probe	= mtk_cci_devfreq_probe,
> > +	.driver = {
> > +		.name = "mediatek-cci-devfreq",
> > +		.of_match_table = mediatek_cci_devfreq_of_match,
> > +	},
> > +};
> > +
> > +static int __init mtk_cci_devfreq_init(void)
> > +{
> > +	int ret = 0;
> > +
> > +	ret = devfreq_add_governor(&mtk_cci_devfreq_governor);
> > +	if (ret) {
> > +		pr_err("%s: failed to add governor: %d\n", __func__, ret);
> > +		return ret;
> > +	}
> > +
> > +	ret = platform_driver_register(&cci_devfreq_driver);
> > +	if (ret)
> > +		devfreq_remove_governor(&mtk_cci_devfreq_governor);
> > +
> > +	return ret;
> > +}
> > +module_init(mtk_cci_devfreq_init)
> > +
> > +static void __exit mtk_cci_devfreq_exit(void)
> > +{
> > +	int ret = 0;
> > +
> > +	platform_driver_unregister(&cci_devfreq_driver);
> > +
> > +	ret = devfreq_remove_governor(&mtk_cci_devfreq_governor);
> > +	if (ret)
> > +		pr_err("%s: failed to remove governor: %d\n", __func__, ret);
> > +}
> > +module_exit(mtk_cci_devfreq_exit)
> > +
> > +MODULE_LICENSE("GPL v2");
> 
> nitpick. better to move it under MODULE_AUTHOR("")
I will move it after MODULE_AUTHOR :)
> 
> > +MODULE_DESCRIPTION("Mediatek CCI devfreq driver");
> > +MODULE_AUTHOR("andrew-sh.cheng");
> 
> Add full name and email as following:
> - MODULE_AUTHOR("Andrew-sh.Cheng <andrew-sh.cheng@mediatek.com>"
I will change to full name and email in next patch.
> 
> 
> > +
> > 
> 
> Remove unneeded blank line.
OK.
> 
> 



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply index

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-29  6:35 [PATCH 0/3] Add cpufreq and cci devfreq for mt8183 Andrew-sh Cheng
2019-01-29  6:35 ` [PATCH 1/3] cpufreq: mediatek: add mt8183 cpufreq support Andrew-sh Cheng
2019-01-29 10:13   ` Viresh Kumar
2019-02-11 13:19     ` andrew-sh.cheng
2019-01-29  6:35 ` [PATCH 2/3] dt-bindings: devfreq: add compatible for mt8183 cci devfreq Andrew-sh Cheng
2019-02-12  1:00   ` Chanwoo Choi
2019-02-16  0:09     ` andrew-sh.cheng
2019-01-29  6:35 ` [PATCH 3/3] devfreq: add mediatek " Andrew-sh Cheng
2019-02-01  3:43   ` Nicolas Boichat
2019-02-12  9:05     ` andrew-sh.cheng
2019-02-01 20:13   ` Matthias Kaehlcke
2019-02-16  3:07     ` andrew-sh.cheng
2019-02-12  4:06   ` Chanwoo Choi
2019-02-16  6:16     ` andrew-sh.cheng [this message]
     [not found] ` <CGME20190129063600epcas2p255b062c64f22555692ff895634ea4eb0@epcms1p4>
2019-01-29  8:17   ` MyungJoo Ham
2019-02-11 13:21     ` andrew-sh.cheng

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1550297799.23797.29.camel@mtksdaap41 \
    --to=andrew-sh.cheng@mediatek.com \
    --cc=cw00.choi@samsung.com \
    --cc=devicetree@vger.kernel.org \
    --cc=fan.chen@mediatek.com \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=matthias.bgg@gmail.com \
    --cc=myungjoo.ham@samsung.com \
    --cc=rjw@rjwysocki.net \
    --cc=robh+dt@kernel.org \
    --cc=srv_heupstream@mediatek.com \
    --cc=viresh.kumar@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-ARM-Kernel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/0 linux-arm-kernel/git/0.git
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/1 linux-arm-kernel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-arm-kernel linux-arm-kernel/ https://lore.kernel.org/linux-arm-kernel \
		linux-arm-kernel@lists.infradead.org
	public-inbox-index linux-arm-kernel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-arm-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git