Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1560267

Re: [PATCH v4 3/3] thermal: zx2967: add thermal driver for ZTE's zx2967 family

Path csiph.com!aioe.org!bofh.it!news.nic.it!robomod
From Eduardo Valentin <edubezval@gmail.com>
Newsgroups linux.kernel
Subject Re: [PATCH v4 3/3] thermal: zx2967: add thermal driver for ZTE's zx2967 family
Date Tue, 17 Jan 2017 06:30:01 +0100
Message-ID <t0uvf-2US-1@gated-at.bofh.it> (permalink)
References <sZ7AJ-8dm-3@gated-at.bofh.it> <sZ7AK-8dm-27@gated-at.bofh.it>
X-Original-To Baoyou Xie <baoyou.xie@linaro.org>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=qP4yQvNssaScUSuQXdSeiTI99rre3LscyG912SQ15DE=; b=MvOHeGOAB+qSdIv5AuFHFHXMxLH77D4vRyNQ27nPhz0x8du+NK+2xjQUn1aL+FiA3d zFKcP282uxDWY1WmepTukxqE2OMm0GhVg+Jwie9Jc/EnjSAh+RcqCfnnTQgQu1Jde5o4 Gjx7nYfVm71aASV6heW6W3/JC0/qHSXl7f4+LHF6FT+IqsdmTgRkddmaYwS9krsm2NNs 2Q1DC+LGqWRa93WUW9athGirhpLdkw+jxLbLoySeu2fzVmzhQsT/Wkkua5dljEF/HFMt 5YRD4wNC2a+67JqtshMUax6JZw1drBWGe4TPcbH+qBZBpBkD/bqN/6Dx06+unnBQumQc nqHQ==
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=qP4yQvNssaScUSuQXdSeiTI99rre3LscyG912SQ15DE=; b=ZHlLI+qSJ409/WTspA6In2aUdJQnhyMkRATXumV1dv3oyHqUvraEO4X3YXIZ3G3fUJ M6dSVaMlP33j8dxCCb4MrWCh0HlH9wGPR+9MI16mxua3YyWGHawbef6J5tcgTAdPYG0Y UKSk3JHMQMryrHlBZ2dtrDHNIVSAB2wzqKIlUFIMlwPl5rF1iBqdniG1YSdCWbzKfw0J uZIoT3l62w8BydtiaEClAPfCajBXkkGnq57r5a4DAwcYhHGiZq6GYSeVYydCxRYBAr6C 5xli5U1hgdRGhKjcQcVTfeOt890ANOj/9Xo3a+lr13FMWgNkh3Svcp3EXSIeaqmH0xkc j7Zw==
X-Gm-Message-State AIkVDXIKBw/muf27y7OtrrXeZpQFRceIaxiJbNyTHfKk1fTunacLdMn172uF6LAtNdrVFw==
X-Received by 10.98.192.72 with SMTP id x69mr41952274pff.129.1484630629570; Mon, 16 Jan 2017 21:23:49 -0800 (PST)
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Disposition inline
User-Agent Mutt/1.5.23 (2014-03-12)
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 190
Organization linux.* mail to news gateway
X-Original-Cc rui.zhang@intel.com, jun.nie@linaro.org, gregkh@linuxfoundation.org, davem@davemloft.net, geert+renesas@glider.be, akpm@linux-foundation.org, mchehab@kernel.org, linux@roeck-us.net, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, shawnguo@kernel.org, xie.baoyou@zte.com.cn, chen.chaokai@zte.com.cn, wang.qiang01@zte.com.cn
X-Original-Date Mon, 16 Jan 2017 21:23:43 -0800
X-Original-Message-ID <20170117052342.GA3176@localhost.localdomain>
X-Original-References <1484304418-17489-1-git-send-email-baoyou.xie@linaro.org> <1484304418-17489-3-git-send-email-baoyou.xie@linaro.org>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1560267

Show key headers only | View raw


Hello,

On Fri, Jan 13, 2017 at 06:46:58PM +0800, Baoyou Xie wrote:
> This patch adds thermal driver for ZTE's zx2967 family.

Please consider the comments I sent on your v3. They still apply here.

and also the following:

> 
> Signed-off-by: Baoyou Xie <baoyou.xie@linaro.org>


<cut>

> +static int zx2967_thermal_get_temp(void *data, int *temp)
> +{
> +	void __iomem *regs;
> +	struct zx2967_thermal_sensor *sensor = data;
> +	struct zx2967_thermal_priv *priv = sensor->priv;
> +	unsigned long timeout = jiffies + msecs_to_jiffies(100);
> +	u32 val, sel_id;
> +
> +	regs = priv->regs;
> +	mutex_lock(&priv->lock);
> +
> +	writel_relaxed(0, regs + ZX2967_THERMAL_POWER_MODE);
> +	writel_relaxed(2, regs + ZX2967_THERMAL_DCF);
> +
> +	val = readl_relaxed(regs + ZX2967_THERMAL_SEL);
> +	val &= ~ZX2967_THERMAL_ID_MASK;
> +	sel_id = sensor->id ? ZX2967_THERMAL_ID0 : ZX2967_THERMAL_ID1;
> +	val |= sel_id;
> +	writel_relaxed(val, regs + ZX2967_THERMAL_SEL);
> +
> +	usleep_range(100, 300);
> +	val = readl_relaxed(regs + ZX2967_THERMAL_CTRL);
> +	while (!(val & ZX2967_THERMAL_READY)) {
> +		if (time_after(jiffies, timeout)) {
> +			dev_err(priv->dev, "Thermal sensor %d data timeout\n",
> +				sensor->id);
> +			mutex_unlock(&priv->lock);
> +			return -ETIMEDOUT;
> +		}
> +		val = readl_relaxed(regs + ZX2967_THERMAL_CTRL);

should you usleep_range() in between loops iterations?

> +	}
> +
> +	writel_relaxed(3, regs + ZX2967_THERMAL_DCF);
> +	val = readl_relaxed(regs + ZX2967_THERMAL_CTRL)
> +			 & ZX2967_THERMAL_TEMP_MASK;
> +	writel_relaxed(1, regs + ZX2967_THERMAL_POWER_MODE);
> +
> +	/*
> +	 * Calculate temperature
> +	 *   922	initial value of calibration cure
> +	 *   1.951	slope of calibration cure
> +	 */
> +	*temp = DIV_ROUND_CLOSEST((val - 922) * 1000, 1951);
> +
> +	mutex_unlock(&priv->lock);
> +
> +	return 0;
> +}
> +
> +static struct thermal_zone_of_device_ops zx2967_of_thermal_ops = {
> +	.get_temp = zx2967_thermal_get_temp,
> +};
> +
> +static int zx2967_thermal_probe(struct platform_device *pdev)
> +{
> +	struct zx2967_thermal_priv *priv;
> +	struct resource *res;
> +	int ret, i;
> +
> +	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
> +	if (!priv)
> +		return -ENOMEM;
> +
> +	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	priv->regs = devm_ioremap_resource(&pdev->dev, res);
> +	if (IS_ERR(priv->regs))
> +		return PTR_ERR(priv->regs);
> +
> +	priv->clk_gate = devm_clk_get(&pdev->dev, "gate");
> +	if (IS_ERR(priv->clk_gate)) {
> +		ret = PTR_ERR(priv->clk_gate);
> +		dev_err(&pdev->dev, "failed to get clock gate: %d\n", ret);
> +		return ret;
> +	}
> +
> +	ret = clk_prepare_enable(priv->clk_gate);
> +	if (ret) {
> +		dev_err(&pdev->dev, "failed to enable converter clock: %d\n",
> +			ret);
> +		return ret;
> +	}
> +
> +	priv->pclk = devm_clk_get(&pdev->dev, "pclk");
> +	if (IS_ERR(priv->pclk)) {
> +		ret = PTR_ERR(priv->pclk);
> +		dev_err(&pdev->dev, "failed to get apb clock: %d\n", ret);
> +		return ret;
> +	}
> +
> +	ret = clk_prepare_enable(priv->pclk);
> +	if (ret) {
> +		clk_disable_unprepare(priv->clk_gate);
> +		dev_err(&pdev->dev, "failed to enable converter clock: %d\n",
> +			ret);
> +		return ret;
> +	}
> +
> +	mutex_init(&priv->lock);
> +	for (i = 0; i < NUM_SENSORS; i++) {
> +		struct zx2967_thermal_sensor *sensor = &priv->sensors[i];
> +
> +		sensor->priv = priv;
> +		sensor->id = i;
> +		sensor->tzd = thermal_zone_of_sensor_register(&pdev->dev,
> +					i, sensor, &zx2967_of_thermal_ops);
> +		if (IS_ERR(sensor->tzd)) {
> +			ret = PTR_ERR(sensor->tzd);
> +			dev_err(&pdev->dev, "failed to register sensor %d: %d\n",
> +				i, ret);
> +			goto remove_ts;
> +		}
> +	}
> +	priv->dev = &pdev->dev;
> +	platform_set_drvdata(pdev, priv);
> +
> +	return 0;
> +
> +remove_ts:
> +	clk_disable_unprepare(priv->clk_gate);
> +	clk_disable_unprepare(priv->pclk);
> +	for (i--; i >= 0; i--)
> +		thermal_zone_of_sensor_unregister(&pdev->dev,
> +						  priv->sensors[i].tzd);
> +
> +	return ret;
> +}
> +
> +static int zx2967_thermal_exit(struct platform_device *pdev)
> +{
> +	struct zx2967_thermal_priv *priv = platform_get_drvdata(pdev);
> +	int i;
> +
> +	for (i = 0; i < NUM_SENSORS; i++) {
> +		struct zx2967_thermal_sensor *sensor = &priv->sensors[i];
> +
> +		thermal_zone_of_sensor_unregister(&pdev->dev, sensor->tzd);
> +	}
> +	clk_disable_unprepare(priv->pclk);
> +	clk_disable_unprepare(priv->clk_gate);
> +
> +	return 0;
> +}
> +
> +static const struct of_device_id zx2967_thermal_id_table[] = {
> +	{ .compatible = "zte,zx296718-thermal" },
> +	{}
> +};
> +MODULE_DEVICE_TABLE(of, zx2967_thermal_id_table);
> +
> +static SIMPLE_DEV_PM_OPS(zx2967_thermal_pm_ops,
> +			 zx2967_thermal_suspend, zx2967_thermal_resume);
> +
> +static struct platform_driver zx2967_thermal_driver = {
> +	.probe = zx2967_thermal_probe,
> +	.remove = zx2967_thermal_exit,
> +	.driver = {
> +		.name = "zx2967_thermal",
> +		.of_match_table = zx2967_thermal_id_table,
> +		.pm = &zx2967_thermal_pm_ops,
> +	},
> +};
> +module_platform_driver(zx2967_thermal_driver);
> +
> +MODULE_AUTHOR("Baoyou Xie <baoyou.xie@linaro.org>");
> +MODULE_DESCRIPTION("ZTE zx2967 thermal driver");
> +MODULE_LICENSE("GPL");

GPLv2?

> -- 
> 2.7.4
> 

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[PATCH v4 3/3] thermal: zx2967: add thermal driver for ZTE's zx2967 family Baoyou Xie <baoyou.xie@linaro.org> - 2017-01-13 11:50 +0100
  Re: [PATCH v4 3/3] thermal: zx2967: add thermal driver for ZTE's  zx2967 family Shawn Guo <shawnguo@kernel.org> - 2017-01-16 08:10 +0100
  Re: [PATCH v4 3/3] thermal: zx2967: add thermal driver for ZTE's  zx2967 family Eduardo Valentin <edubezval@gmail.com> - 2017-01-17 06:30 +0100

csiph-web