Skip to contentSkip to conversation

hwmon: Add driver for EXYNOS4 TMU

PATCH Applied Donggeun Kim 3 participants 6 messages Sep 7, 2011 – Nov 17, 2011

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v7 1/1 hwmon: Add driver for EXYNOS4 TMU

This patch allows to read temperature
from TMU(Thermal Management Unit) of SAMSUNG EXYNOS4 series of SoC.

---
Changes for v7
- removed sysfs_notify function call
- changed kobject_uevent_env to kobject_uevent
- cleaned up documentation
Changes for v6
- changed type of a variable in read function
- cleaned up code
Changes for v5
- added checking range of temp and temp code
- cleaned up code
Changes for v4
- added comment for unit of threshold and trigger_levels
- cleaned up code
Changes for v3
- cleaned up redundant code
- added mutex
- changed error codes
Changes for v2
- added six attributes for alarms
- changed error code of EAGAIN
- changed initialize function to return error code

 Documentation/hwmon/exynos4_tmu           |   81 +++++
 drivers/hwmon/Kconfig                     |   10 +
 drivers/hwmon/Makefile                    |    1 +
 drivers/hwmon/exynos4_tmu.c               |  524 +++++++++++++++++++++++++++++
 include/linux/platform_data/exynos4_tmu.h |   83 +++++
 5 files changed, 699 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/hwmon/exynos4_tmu
 create mode 100644 drivers/hwmon/exynos4_tmu.c
 create mode 100644 include/linux/platform_data/exynos4_tmu.h
Documentation/hwmon/exynos4_tmu new file +80 -0
new file mode 100644
index 0000000..c3c6b41
@@ -0,0 +1,81 @@
+Kernel driver exynos4_tmu
+========+
+Supported chips:
+* ARM SAMSUNG EXYNOS4 series of SoC
+  Prefix: 'exynos4-tmu'
+  Datasheet: Not publicly available
+
+Authors: Donggeun Kim <[email protected]>
+
+Description
+-----------
+
+This driver allows to read temperature inside SAMSUNG EXYNOS4 series of SoC.
+
+The chip only exposes the measured 8-bit temperature code value
+through a register.
+Temperature can be taken from the temperature code.
+There are three equations converting from temperature to temperature code.
+
+The three equations are:
+  1. Two point trimming
+	Tc = (T - 25) * (TI2 - TI1) / (85 - 25) + TI1
+
+  2. One point trimming
+	Tc = T + TI1 - 25
+
+  3. No trimming
+	Tc = T + 50
+
+  Tc: Temperature code, T: Temperature,
+  TI1: Trimming info for 25 degree Celsius (stored at TRIMINFO register)
+       Temperature code measured at 25 degree Celsius which is unchanged
+  TI2: Trimming info for 85 degree Celsius (stored at TRIMINFO register)
+       Temperature code measured at 85 degree Celsius which is unchanged
+
+TMU(Thermal Management Unit) in EXYNOS4 generates interrupt
+when temperature exceeds pre-defined levels.
+The maximum number of configurable threshold is four.
+The threshold levels are defined as follows:
+  Level_0: current temperature > trigger_level_0 + threshold
+  Level_1: current temperature > trigger_level_1 + threshold
+  Level_2: current temperature > trigger_level_2 + threshold
+  Level_3: current temperature > trigger_level_3 + threshold
+
+  The threshold and each trigger_level are set
+  through the corresponding registers.
+
+When an interrupt occurs, this driver notify user space of
+one of four threshold levels for the interrupt
+through kobject_uevent_env and sysfs_notify functions.
+Although an interrupt condition for level_0 can be set,
+it is not notified to user space through sysfs_notify function.
+
+Sysfs Interface
+---------------
+name		name of the temperature sensor
+		RO
+
+temp1_input	temperature
+		RO
+
+temp1_max	temperature for level_1 interrupt
+		RO
+
+temp1_crit	temperature for level_2 interrupt
+		RO
+
+temp1_emergency	temperature for level_3 interrupt
+		RO
+
+temp1_max_alarm	alarm for level_1 interrupt
+		RO
+
+temp1_crit_alarm
+		alarm for level_2 interrupt
+		RO
+
+temp1_emergency_alarm
+		alarm for level_3 interrupt
+		RO
drivers/hwmon/Kconfig +10 -0
index 0b62c3c..c6fb761 100644
@@ -303,6 +303,16 @@ config SENSORS_DS1621
 	  This driver can also be built as a module.  If so, the module
 	  will be called ds1621.
 
+config SENSORS_EXYNOS4_TMU
+	tristate "Temperature sensor on Samsung EXYNOS4"
+	depends on EXYNOS4_DEV_TMU
+	help
+	  If you say yes here you get support for TMU (Thermal Managment
+	  Unit) on SAMSUNG EXYNOS4 series of SoC.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called exynos4-tmu.
+
 config SENSORS_I5K_AMB
 	tristate "FB-DIMM AMB temperature sensor on Intel 5000 series chipsets"
 	depends on PCI && EXPERIMENTAL
drivers/hwmon/Makefile +1 -0
index 3c9ccef..dbd8963 100644
@@ -47,6 +47,7 @@ obj-$(CONFIG_SENSORS_DS1621)	+= ds1621.o
 obj-$(CONFIG_SENSORS_EMC1403)	+= emc1403.o
 obj-$(CONFIG_SENSORS_EMC2103)	+= emc2103.o
 obj-$(CONFIG_SENSORS_EMC6W201)	+= emc6w201.o
+obj-$(CONFIG_SENSORS_EXYNOS4_TMU)	+= exynos4_tmu.o
 obj-$(CONFIG_SENSORS_F71805F)	+= f71805f.o
 obj-$(CONFIG_SENSORS_F71882FG)	+= f71882fg.o
 obj-$(CONFIG_SENSORS_F75375S)	+= f75375s.o
drivers/hwmon/exynos4_tmu.c new file +524 -0

524 lines not on this page · raw message

include/linux/platform_data/exynos4_tmu.h new file +83 -0

83 lines not on this page · raw message

Signature · 7 lines
1.7.4.1


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#1 lore raw
Quoted 11 lines · Donggeun Kim

This patch allows to read temperature
from TMU(Thermal Management Unit) of SAMSUNG EXYNOS4 series of SoC.

---
Changes for v7
- removed sysfs_notify function call
- changed kobject_uevent_env to kobject_uevent
- cleaned up documentation

Thanks, applied.

FYI, I requested access to the chip datasheet - if I get it, I'll see if there is a way to get interrupts for 1->0 transitions.

Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#2 lore raw
In reply to Donggeun Kim

(This is an attempt to do a bit of review after the fact. See, this appears to be to the patch that ended up as commit 9d97e5c81e15afaef65d00f077f863c94f750839 in the mainline tree. Since that tree is at v3.2-rc2 now this might be in time for v3.2. If my comments have merit, that is.)

Quoted 2 lines · Donggeun Kim

This patch allows to read temperature
from TMU(Thermal Management Unit) of SAMSUNG EXYNOS4 series of SoC.

[...]

drivers/hwmon/Kconfig config SENSORS_DS1621 · line 308

Quoted 11 lines
drivers/hwmon/Kconfig +3 -0
index 0b62c3c..c6fb761 100644
@@ -303,6 +303,16 @@ config SENSORS_DS1621
 	  This driver can also be built as a module.  If so, the module
 	  will be called ds1621.
 
+config SENSORS_EXYNOS4_TMU
+	tristate "Temperature sensor on Samsung EXYNOS4"
+	depends on EXYNOS4_DEV_TMU

It doesn't look like that Kconfig symbol is part of the tree just yet. That means people will not be able to build this driver from the mainline tree. Why is this dependency needed? In a (rather quick) scan of the code of this driver I couldn't spot anything not yet available in the tree.

Quoted 10 lines
drivers/hwmon/Kconfig +7 -0
+	help
+	  If you say yes here you get support for TMU (Thermal Managment
+	  Unit) on SAMSUNG EXYNOS4 series of SoC.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called exynos4-tmu.
+
 config SENSORS_I5K_AMB
 	tristate "FB-DIMM AMB temperature sensor on Intel 5000 series chipsets"
 	depends on PCI && EXPERIMENTAL

[...]

Quoted 5 lines
drivers/hwmon/exynos4_tmu.c new file +0 -0
new file mode 100644
index 0000000..0170c90

[...]

Quoted 20 lines
drivers/hwmon/exynos4_tmu.c new file +20 -0
+#ifdef CONFIG_PM
+static int exynos4_tmu_suspend(struct platform_device *pdev, pm_message_t state)
+{
+	exynos4_tmu_control(pdev, false);
+
+	return 0;
+}
+
+static int exynos4_tmu_resume(struct platform_device *pdev)
+{
+	exynos4_tmu_initialize(pdev);
+	exynos4_tmu_control(pdev, true);
+
+	return 0;
+}
+#else
+#define exynos4_tmu_suspend NULL
+#define exynos4_tmu_resume NULL
+#endif
+

drivers/hwmon/exynos4_tmu.c line 507

Quoted 10 lines
drivers/hwmon/exynos4_tmu.c new file +10 -0
+static struct platform_driver exynos4_tmu_driver = {
+	.driver = {
+		.name   = "exynos4-tmu",
+		.owner  = THIS_MODULE,
+	},
+	.probe = exynos4_tmu_probe,
+	.remove	= __devexit_p(exynos4_tmu_remove),
+	.suspend = exynos4_tmu_suspend,
+	.resume = exynos4_tmu_resume,
+};

A common idiom seems to be (I'm speaking from memory here) to wrap .suspend and .resume inside an "#ifdef CONFIG_PM" / "#endif" pair. That would allow to drop both "#define exynos4_tmu_suspend NULL" and "#define exynos4_tmu_resume NULL" above. Would that work here too?

Paul Bolle

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#3 lore raw
Quoted 18 lines · Paul Bolle

(This is an attempt to do a bit of review after the fact. See, this appears to be to the patch that ended up as commit 9d97e5c81e15afaef65d00f077f863c94f750839 in the mainline tree. Since that tree is at v3.2-rc2 now this might be in time for v3.2. If my comments have merit, that is.)

Quoted 2 lines · Donggeun Kim

This patch allows to read temperature
from TMU(Thermal Management Unit) of SAMSUNG EXYNOS4 series of SoC.

[...]

Quoted 8 lines
drivers/hwmon/Kconfig +0 -0
index 0b62c3c..c6fb761 100644
@@ -303,6 +303,16 @@ config SENSORS_DS1621
 	  This driver can also be built as a module.  If so, the module
 	  will be called ds1621.
 
Quoted 10 lines

drivers/hwmon/Kconfig config SENSORS_DS1621 · line 308

Quoted 3 lines
drivers/hwmon/Kconfig +3 -0
+config SENSORS_EXYNOS4_TMU
+	tristate "Temperature sensor on Samsung EXYNOS4"
+	depends on EXYNOS4_DEV_TMU

It doesn't look like that Kconfig symbol is part of the tree just yet. That means people will not be able to build this driver from the mainline tree. Why is this dependency needed? In a (rather quick) scan of the code of this driver I couldn't spot anything not yet available in the tree.

I have to defer to the driver author for that. Maybe the dependency was renamed at some point, or removed altogether.

Quoted 44 lines
Quoted 10 lines
drivers/hwmon/Kconfig +7 -0
+	help
+	  If you say yes here you get support for TMU (Thermal Managment
+	  Unit) on SAMSUNG EXYNOS4 series of SoC.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called exynos4-tmu.
+
 config SENSORS_I5K_AMB
 	tristate "FB-DIMM AMB temperature sensor on Intel 5000 series chipsets"
 	depends on PCI && EXPERIMENTAL

[...]

Quoted 5 lines
drivers/hwmon/exynos4_tmu.c new file +0 -0
new file mode 100644
index 0000000..0170c90

[...]

Quoted 27 lines
drivers/hwmon/exynos4_tmu.c new file +27 -0
+#ifdef CONFIG_PM
+static int exynos4_tmu_suspend(struct platform_device *pdev, pm_message_t state)
+{
+	exynos4_tmu_control(pdev, false);
+
+	return 0;
+}
+
+static int exynos4_tmu_resume(struct platform_device *pdev)
+{
+	exynos4_tmu_initialize(pdev);
+	exynos4_tmu_control(pdev, true);
+
+	return 0;
+}
+#else
+#define exynos4_tmu_suspend NULL
+#define exynos4_tmu_resume NULL
+#endif
+
+static struct platform_driver exynos4_tmu_driver = {
+	.driver = {
+		.name   = "exynos4-tmu",
+		.owner  = THIS_MODULE,
+	},
+	.probe = exynos4_tmu_probe,
+	.remove	= __devexit_p(exynos4_tmu_remove),
Quoted 9 lines

drivers/hwmon/exynos4_tmu.c line 507

Quoted 3 lines
drivers/hwmon/exynos4_tmu.c new file +3 -0
+	.suspend = exynos4_tmu_suspend,
+	.resume = exynos4_tmu_resume,
+};

A common idiom seems to be (I'm speaking from memory here) to wrap .suspend and .resume inside an "#ifdef CONFIG_PM" / "#endif" pair. That would allow to drop both "#define exynos4_tmu_suspend NULL" and "#define exynos4_tmu_resume NULL" above. Would that work here too?

Seems to be a matter of opinion. I personally don't care one way or the other, but I was told some time ago that the above method would be preferred over using a second #ifdef.

Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#4 lore raw

T24gMjAxMeuFhCAxMeyblCAxNuydvCAwNjoyNCwgR3VlbnRlciBSb2VjayB3cm90ZToKPiBPbiBU dWUsIDIwMTEtMTEtMTUgYXQgMTU6MzQgLTA1MDAsIFBhdWwgQm9sbGUgd3JvdGU6Cj4+IChUaGlz IGlzIGFuIGF0dGVtcHQgdG8gZG8gYSBiaXQgb2YgcmV2aWV3IGFmdGVyIHRoZSBmYWN0LiBTZWUs IHRoaXMKPj4gYXBwZWFycyB0byBiZSB0byB0aGUgcGF0Y2ggdGhhdCBlbmRlZCB1cCBhcyBjb21t aXQKPj4gOWQ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1M0X0RFVl9UTVUK Pj4KPj4gSXQgZG9lc24ndCBsb29rIGxpa2UgdGhhdCBLY29uZmlnIHN5bWJvbCBpcyBwYXJ0IG9m IHRoZSB0cmVlIGp1c3QgeWV0Lgo+PiBUaGF0IG1lYW5zIHBlb3BsZSB3aWxsIG5vdCBiZSBhYmxl IHRvIGJ1aWxkIHRoaXMgZHJpdmVyIGZyb20gdGhlCj4+IG1haW5saW5lIHRyZWUuIFdoeSBpcyB0 aGlzIGRlcGVuZGVuY3kgbmVlZGVkPyBJbiBhIChyYXRoZXIgcXVpY2spIHNjYW4KPj4gb2YgdGhl IGNvZGUgb2YgdGhpcyBkcml2ZXIgSSBjb3VsZG4ndCBzcG90IGFueXRoaW5nIG5vdCB5ZXQgYXZh aWxhYmxlIGluCj4+IHRoZSB0cmVlLgo+Pgo+IEkgaGF2ZSB0byBkZWZlciB0byB0aGUgZHJpdmVy IGF1dGhvciBmb3IgdGhhdC4gTWF5YmUgdGhlIGRlcGVuZGVuY3kgd2FzCj4gcmVuYW1lZCBhdCBz b21lIHBvaW50LCBvciByZW1vdmVkIGFsdG9nZXRoZXIuCj4gClRoZSBkZXBlbmRlbmN5IHdpbGwg YmUgcmVuYW1lZCB0byAnQVJDSF9FWFlOT1M0Jy4KClRoYW5rcywKRG9uZ2dldW4KCgoKX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KbG0tc2Vuc29ycyBtYWls aW5nIGxpc3QKbG0tc2Vuc29yc0BsbS1zZW5zb3JzLm9yZwpodHRwOi8vbGlzdHMubG0tc2Vuc29y cy5vcmcvbWFpbG1hbi9saXN0aW5mby9sbS1zZW5zb3Jz

#5 lore raw

On Thu, Nov 17, 2011 at 12:20:31AM -0500, Donggeun Kim wrote:
[ ... ]

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

drivers/hwmon/Kconfig config SENSORS_DS1621 · line 308

Quoted 4 lines
drivers/hwmon/Kconfig +3 -0
+config SENSORS_EXYNOS4_TMU
+	tristate "Temperature sensor on Samsung EXYNOS4"
+	depends on EXYNOS4_DEV_TMU

It doesn't look like that Kconfig symbol is part of the tree just yet. That means people will not be able to build this driver from the mainline tree. Why is this dependency needed? In a (rather quick) scan of the code of this driver I couldn't spot anything not yet available in the tree.

Quoted 5 lines
Quoted 3 lines

I have to defer to the driver author for that. Maybe the dependency was renamed at some point, or removed altogether.

The dependency will be renamed to 'ARCH_EXYNOS4'.

Please submit a patch.

Thanks,
Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors