linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] thermal: Add support for thermal sensor present on SPEAr13xx machines
@ 2012-02-24  7:27 Viresh Kumar
  2012-02-24 20:02 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Viresh Kumar @ 2012-02-24  7:27 UTC (permalink / raw)
  To: akpm, rui.zhang
  Cc: armando.visconti, shiraz.hashim, vipin.kumar, rajeev-dlh.kumar,
	deepak.sikri, vipulkumar.samar, amit.virdi, viresh.kumar,
	pratyush.anand, bhupesh.sharma, viresh.linux, bhavna.yadav,
	vincenzo.frascino, mirko.gardi, salvatore.dedominicis,
	linux-kernel, len.brown

From: Vincenzo Frascino <vincenzo.frascino@st.com>

ST's SPEAr13xx machines are based on CortexA9 ARM processors. These
machines contain a thermal sensor for junction temperature monitoring.

This patch adds support for this thermal sensor in existing thermal
framework.

Signed-off-by: Vincenzo Frascino <vincenzo.frascino@st.com>
Signed-off-by: Viresh Kumar <viresh.kumar@st.com>
---
 drivers/thermal/Kconfig                     |    7 +
 drivers/thermal/Makefile                    |    1 +
 drivers/thermal/spear_thermal.c             |  205 +++++++++++++++++++++++++++
 include/linux/platform_data/spear_thermal.h |   26 ++++
 4 files changed, 239 insertions(+), 0 deletions(-)
 create mode 100644 drivers/thermal/spear_thermal.c
 create mode 100644 include/linux/platform_data/spear_thermal.h

diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig
index f7f71b2..2633fe0 100644
--- a/drivers/thermal/Kconfig
+++ b/drivers/thermal/Kconfig
@@ -18,3 +18,10 @@ config THERMAL_HWMON
 	depends on THERMAL
 	depends on HWMON=y || HWMON=THERMAL
 	default y
+
+config SPEAR_THERMAL
+	bool "SPEAr thermal sensor driver"
+	depends on THERMAL
+	help
+	  Enable this to plug the SPEAr thermal sensor driver into the Linux
+	  thermal framework
diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile
index 31108a0..a9fff0b 100644
--- a/drivers/thermal/Makefile
+++ b/drivers/thermal/Makefile
@@ -3,3 +3,4 @@
 #
 
 obj-$(CONFIG_THERMAL)		+= thermal_sys.o
+obj-$(CONFIG_SPEAR_THERMAL)		+= spear_thermal.o
\ No newline at end of file
diff --git a/drivers/thermal/spear_thermal.c b/drivers/thermal/spear_thermal.c
new file mode 100644
index 0000000..d819b3c
--- /dev/null
+++ b/drivers/thermal/spear_thermal.c
@@ -0,0 +1,205 @@
+/*
+ * SPEAr thermal driver.
+ *
+ * Copyright (C) 2011-2012 ST Microelectronics
+ * Author: Vincenzo Frascino <vincenzo.frascino@st.com>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <linux/clk.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/platform_data/spear_thermal.h>
+#include <linux/thermal.h>
+
+#define MD_FACTOR	1000
+
+/* SPEAr Thermal Sensor Dev Structure */
+struct spear_thermal_dev {
+	/* pointer to base address of the thermal sensor */
+	void __iomem *thermal_base;
+	/* clk structure */
+	struct clk *clk;
+	/* pointer to thermal flags */
+	unsigned int flags;
+};
+
+static inline int thermal_get_temp(struct thermal_zone_device *thermal,
+				unsigned long *temp)
+{
+	struct spear_thermal_dev *stdev = thermal->devdata;
+
+	/*
+	 * Data are ready to be read after 628 usec from POWERDOWN signal
+	 * (PDN) = 1
+	 */
+	*temp = (readl(stdev->thermal_base) & 0x7F) * MD_FACTOR;
+	return 0;
+}
+
+static struct thermal_zone_device_ops ops = {
+	.get_temp = thermal_get_temp,
+};
+
+#ifdef CONFIG_PM
+static int spear_thermal_suspend(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct thermal_zone_device *spear_thermal = platform_get_drvdata(pdev);
+	struct spear_thermal_dev *stdev = spear_thermal->devdata;
+	unsigned int actual_mask = 0;
+
+	/* Disable SPEAr Thermal Sensor */
+	actual_mask = readl(stdev->thermal_base);
+	writel(actual_mask & ~stdev->flags, stdev->thermal_base);
+
+	clk_disable(stdev->clk);
+	dev_info(dev, "Suspended.\n");
+
+	return 0;
+}
+
+static int spear_thermal_resume(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct thermal_zone_device *spear_thermal = platform_get_drvdata(pdev);
+	struct spear_thermal_dev *stdev = spear_thermal->devdata;
+	unsigned int actual_mask = 0;
+	int ret = 0;
+
+	ret = clk_enable(stdev->clk);
+	if (ret) {
+		dev_err(&pdev->dev, "Can't enable clock\n");
+		return ret;
+	}
+
+	/* Enable SPEAr Thermal Sensor */
+	actual_mask = readl(stdev->thermal_base);
+	writel(actual_mask | stdev->flags, stdev->thermal_base);
+
+	dev_info(dev, "Resumed.\n");
+
+	return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(spear_thermal_pm_ops, spear_thermal_suspend,
+		spear_thermal_resume);
+
+static int spear_thermal_probe(struct platform_device *pdev)
+{
+	struct thermal_zone_device *spear_thermal = NULL;
+	struct spear_thermal_dev *stdev;
+	struct spear_thermal_pdata *pdata;
+	int ret = 0;
+	struct resource *stres = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!stres) {
+		dev_err(&pdev->dev, "memory resource missing\n");
+		return -ENODEV;
+	}
+
+	pdata = dev_get_platdata(&pdev->dev);
+	if (!pdata) {
+		dev_err(&pdev->dev, "platform data is NULL\n");
+		return -EINVAL;
+	}
+
+	stdev = devm_kzalloc(&pdev->dev, sizeof(*stdev), GFP_KERNEL);
+	if (!stdev) {
+		dev_err(&pdev->dev, "kzalloc fail\n");
+		return -ENOMEM;
+	}
+
+	/* Enable thermal sensor */
+	stdev->thermal_base = devm_ioremap(&pdev->dev, stres->start,
+			resource_size(stres));
+	if (!stdev->thermal_base) {
+		dev_err(&pdev->dev, "ioremap failed\n");
+		return -ENOMEM;
+	}
+
+	stdev->clk = clk_get(&pdev->dev, NULL);
+	if (IS_ERR(stdev->clk)) {
+		dev_err(&pdev->dev, "Can't get clock\n");
+		return PTR_ERR(stdev->clk);
+	}
+
+	ret = clk_enable(stdev->clk);
+	if (ret) {
+		dev_err(&pdev->dev, "Can't enable clock\n");
+		goto put_clk;
+	}
+
+	stdev->flags = pdata->thermal_flags;
+	writel(stdev->flags, stdev->thermal_base);
+
+	spear_thermal = thermal_zone_device_register("spear_thermal", 0,
+				stdev, &ops, 0, 0, 0, 0);
+	if (!spear_thermal) {
+		dev_err(&pdev->dev, "thermal zone device is NULL\n");
+		ret = -EINVAL;
+		goto disable_clk;
+	}
+
+	platform_set_drvdata(pdev, spear_thermal);
+
+	dev_info(&spear_thermal->device, "Thermal Sensor Loaded at: 0x%x.\n",
+			(unsigned int)stdev->thermal_base);
+
+	return 0;
+
+disable_clk:
+	clk_disable(stdev->clk);
+put_clk:
+	clk_put(stdev->clk);
+
+	return ret;
+}
+
+static int spear_thermal_exit(struct platform_device *pdev)
+{
+	unsigned int actual_mask = 0;
+	struct thermal_zone_device *spear_thermal = platform_get_drvdata(pdev);
+	struct spear_thermal_dev *stdev = spear_thermal->devdata;
+
+	thermal_zone_device_unregister(spear_thermal);
+	platform_set_drvdata(pdev, NULL);
+
+	/* Disable SPEAr Thermal Sensor */
+	actual_mask = readl(stdev->thermal_base);
+	writel(actual_mask & ~stdev->flags, stdev->thermal_base);
+
+	clk_disable(stdev->clk);
+	clk_put(stdev->clk);
+
+	return 0;
+}
+
+static struct platform_driver spear_thermal_driver = {
+	.probe = spear_thermal_probe,
+	.remove = spear_thermal_exit,
+	.driver = {
+		.name = "spear_thermal",
+		.owner = THIS_MODULE,
+		.pm = &spear_thermal_pm_ops,
+	},
+};
+
+module_platform_driver(spear_thermal_driver);
+
+MODULE_AUTHOR("Vincenzo Frascino <vincenzo.frascino@st.com>");
+MODULE_DESCRIPTION("SPEAr thermal driver");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/platform_data/spear_thermal.h b/include/linux/platform_data/spear_thermal.h
new file mode 100644
index 0000000..724f2e1
--- /dev/null
+++ b/include/linux/platform_data/spear_thermal.h
@@ -0,0 +1,26 @@
+/*
+ * SPEAr thermal driver platform data.
+ *
+ * Copyright (C) 2011-2012 ST Microelectronics
+ * Author: Vincenzo Frascino <vincenzo.frascino@st.com>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+#ifndef SPEAR_THERMAL_H
+#define SPEAR_THERMAL_H
+
+/* SPEAr Thermal Sensor Platform Data */
+struct spear_thermal_pdata {
+	/* flags used to enable thermal sensor */
+	unsigned int thermal_flags;
+};
+
+#endif /* SPEAR_THERMAL_H */
-- 
1.7.8.110.g4cb5d


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] thermal: Add support for thermal sensor present on SPEAr13xx machines
  2012-02-24  7:27 [PATCH] thermal: Add support for thermal sensor present on SPEAr13xx machines Viresh Kumar
@ 2012-02-24 20:02 ` Andrew Morton
       [not found]   ` <CAOh2x=kszwxhwKqwKN37Yd_KRKG5DwC_5zXXevsLpUJmJsZV0w@mail.gmail.com>
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2012-02-24 20:02 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: rui.zhang, armando.visconti, shiraz.hashim, vipin.kumar,
	rajeev-dlh.kumar, deepak.sikri, vipulkumar.samar, amit.virdi,
	pratyush.anand, bhupesh.sharma, viresh.linux, bhavna.yadav,
	vincenzo.frascino, mirko.gardi, salvatore.dedominicis,
	linux-kernel, len.brown

On Fri, 24 Feb 2012 12:57:38 +0530
Viresh Kumar <viresh.kumar@st.com> wrote:

> From: Vincenzo Frascino <vincenzo.frascino@st.com>
> 
> ST's SPEAr13xx machines are based on CortexA9 ARM processors. These
> machines contain a thermal sensor for junction temperature monitoring.
> 
> This patch adds support for this thermal sensor in existing thermal
> framework.
> 
> --- a/drivers/thermal/Kconfig
> +++ b/drivers/thermal/Kconfig
> @@ -18,3 +18,10 @@ config THERMAL_HWMON
>  	depends on THERMAL
>  	depends on HWMON=y || HWMON=THERMAL
>  	default y
> +
> +config SPEAR_THERMAL
> +	bool "SPEAr thermal sensor driver"
> +	depends on THERMAL
> +	help
> +	  Enable this to plug the SPEAr thermal sensor driver into the Linux
> +	  thermal framework

The driver can be compiled for all architectures which support
CONFIG_THERMAL.  This includes x86_64.  Was that intended?

I don't think it's necessarily a bad thing: it gives the driver a lot
more compilation coverage and exposes bugs such as

drivers/thermal/spear_thermal.c: In function 'spear_thermal_probe':
drivers/thermal/spear_thermal.c:159: warning: cast from pointer to integer of different size

--- a/drivers/thermal/spear_thermal.c~thermal-add-support-for-thermal-sensor-present-on-spear13xx-machines-fix
+++ a/drivers/thermal/spear_thermal.c
@@ -156,8 +156,8 @@ static int spear_thermal_probe(struct pl
 
 	platform_set_drvdata(pdev, spear_thermal);
 
-	dev_info(&spear_thermal->device, "Thermal Sensor Loaded at: 0x%x.\n",
-			(unsigned int)stdev->thermal_base);
+	dev_info(&spear_thermal->device, "Thermal Sensor Loaded at: 0x%p.\n",
+			stdev->thermal_base);
 
 	return 0;
 

but I do wonder if this was intentional.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] thermal: Add support for thermal sensor present on SPEAr13xx machines
       [not found]   ` <CAOh2x=kszwxhwKqwKN37Yd_KRKG5DwC_5zXXevsLpUJmJsZV0w@mail.gmail.com>
@ 2012-02-27 22:49     ` Andrew Morton
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2012-02-27 22:49 UTC (permalink / raw)
  To: viresh kumar
  Cc: salvatore.dedominicis, bhavna.yadav, rajeev-dlh.kumar,
	Viresh Kumar, pratyush.anand, shiraz.hashim, deepak.sikri,
	mirko.gardi, vipulkumar.samar, rui.zhang, len.brown,
	armando.visconti, amit.virdi, vincenzo.frascino, vipin.kumar,
	linux-kernel, bhupesh.sharma

On Fri, 24 Feb 2012 19:30:54 -0800
viresh kumar <viresh.linux@gmail.com> wrote:

> On Feb 25, 2012 1:32 AM, "Andrew Morton" <akpm@linux-foundation.org> wrote:
> >
> 
> > The driver can be compiled for all architectures which support
> > CONFIG_THERMAL.  This includes x86_64.  Was that intended?
> >
> 
> No.
> 
> > I don't think it's necessarily a bad thing:
> 
> Ya we thought about removing spear_* from the driver. But the hardware
> looked a bit proprietary.

I don't really understand this reply.  Does it mean that you will be
updating the Kconfig logic?


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-02-27 22:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-24  7:27 [PATCH] thermal: Add support for thermal sensor present on SPEAr13xx machines Viresh Kumar
2012-02-24 20:02 ` Andrew Morton
     [not found]   ` <CAOh2x=kszwxhwKqwKN37Yd_KRKG5DwC_5zXXevsLpUJmJsZV0w@mail.gmail.com>
2012-02-27 22:49     ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).