hwmon: Add driver for EXYNOS4 TMU
Subsystems (3)
PATCH v6 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 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 | 543 +++++++++++++++++++++++++++++ include/linux/platform_data/exynos4_tmu.h | 83 +++++ 5 files changed, 718 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
@@ -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
@@ -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
@@ -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 +543 -0
543 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
Quoted 6 lines · Donggeun Kim
This patch allows to read temperature
from TMU(Thermal Management Unit) of SAMSUNG EXYNOS4 series of SoC.Signed-off-by Donggeun Kim <[email protected]>Signed-off-by MyungJoo Ham <[email protected]>Signed-off-by Kyungmin Park <[email protected]>
Looks pretty good now. Only a whitespace nitpick, and we'll still have to resolve the uevent issue.
[ ... ]
Quoted 25 lines
Documentation/hwmon/exynos4_tmu new file +19
-0@@ -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. +
Documentation/hwmon/exynos4_tmu line 29
Quoted 10 lines
Documentation/hwmon/exynos4_tmu new file +10
-0+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 +
The above assignment lines create a whitespace warning (blank before tab). Please fix.
[ ... ]
Quoted 22 lines
Documentation/hwmon/exynos4_tmu new file +22
-0+ +static void exynos4_tmu_work(struct work_struct *work) +{ + struct exynos4_tmu_data *data = container_of(work, + struct exynos4_tmu_data, irq_work); + unsigned int interrupt_stat; + char *envp[2]; + + mutex_lock(&data->lock); + clk_enable(data->clk); + + interrupt_stat = readl(data->base + EXYNOS4_TMU_REG_INTSTAT); + + writel(EXYNOS4_TMU_INTCLEAR_VAL, data->base + EXYNOS4_TMU_REG_INTCLEAR); + + if (interrupt_stat & EXYNOS4_TMU_TRIG_LEVEL3_MASK) { + envp[0] = "TRIG_LEVEL=3"; + sysfs_notify(&data->hwmon_dev->kobj, NULL, + "temp1_emergency_alarm"); + } else if (interrupt_stat & EXYNOS4_TMU_TRIG_LEVEL2_MASK) { + envp[0] = "TRIG_LEVEL=2"; + sysfs_notify(&data->hwmon_dev->kobj, NULL,
Documentation/hwmon/exynos4_tmu line 61
Quoted 10 lines
Documentation/hwmon/exynos4_tmu new file +10
-0+ "temp1_crit_alarm"); + } else if (interrupt_stat & EXYNOS4_TMU_TRIG_LEVEL1_MASK) { + envp[0] = "TRIG_LEVEL=1"; + sysfs_notify(&data->hwmon_dev->kobj, NULL, "temp1_max_alarm"); + } else + envp[0] = "TRIG_LEVEL=0"; + envp[1] = NULL; + + kobject_uevent_env(&data->hwmon_dev->kobj, KOBJ_CHANGE, envp); +
Concern here is two-fold: envp is driver specific, and sysfs_notify() should really be called whenever an attribute changes its state. Right now it is only called for 0->1 transitions, but not for 1->0 transitions, which means that any listener will not get notified for 1->0 transitions. This makes the sysfs notification pretty much useless.
For the uevent, I would suggest to generate the global uevent as other drivers do it right now.
kobject_uevent(&data->hwmon_dev->kobj, KOBJ_CHANGE);
An alternative would be to pass one of the changed attribute names as environment (eg the highest temperature 0->1 transition).
For the 1->0 transitions, I don't really have a good idea how to handle it if the chip does not generate interrupts in this case. Not really sure, though, if calling sysfs_notify even makes sense in that case, since a poll on a "triggered" attribute file will be stuck forever.
Thanks,
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 8 lines · Guenter Roeck
Quoted 6 lines · Donggeun Kim
This patch allows to read temperature
from TMU(Thermal Management Unit) of SAMSUNG EXYNOS4 series of SoC.Signed-off-by Donggeun Kim <[email protected]>Signed-off-by MyungJoo Ham <[email protected]>Signed-off-by Kyungmin Park <[email protected]>
[snip]
Quoted 39 lines
Quoted 22 lines
drivers/hwmon/exynos4_tmu.c new file +22
-0+ +static void exynos4_tmu_work (struct work_struct *work) +{ +struct exynos4_tmu_data *data =container_of (work, + struct exynos4_tmu_data, irq_work); +unsigned int interrupt_stat; +char *envp[2 ]; + +mutex_lock (&data->lock); +clk_enable (data->clk); + + interrupt_stat =readl (data->base +EXYNOS4_TMU_REG_INTSTAT ); + +writel (EXYNOS4_TMU_INTCLEAR_VAL , data->base +EXYNOS4_TMU_REG_INTCLEAR ); + +if (interrupt_stat &EXYNOS4_TMU_TRIG_LEVEL3_MASK ) { + envp[0 ] ="TRIG_LEVEL=3" ; +sysfs_notify (&data->hwmon_dev->kobj,NULL , +"temp1_emergency_alarm" ); + }else if (interrupt_stat &EXYNOS4_TMU_TRIG_LEVEL2_MASK ) { + envp[0 ] ="TRIG_LEVEL=2" ; + sysfs_notify(&data->hwmon_dev->kobj, NULL,drivers/hwmon/exynos4_tmu.c line 269
Quoted 10 lines
drivers/hwmon/exynos4_tmu.c new file +10
-0+ "temp1_crit_alarm"); + }else if (interrupt_stat &EXYNOS4_TMU_TRIG_LEVEL1_MASK ) { + envp[0 ] ="TRIG_LEVEL=1" ; +sysfs_notify (&data->hwmon_dev->kobj,NULL ,"temp1_max_alarm" ); + }else + envp[0 ] ="TRIG_LEVEL=0" ; + envp[1 ] =NULL ; + +kobject_uevent_env (&data->hwmon_dev->kobj,KOBJ_CHANGE , envp); +Concern here is two-fold: envp is driver specific, and
sysfs_notify()should really be called whenever an attribute changes its state. Right now it is only called for 0->1 transitions, but not for 1->0 transitions, which means that any listener will not get notified for 1->0 transitions. This makes the sysfs notification pretty much useless.
Quoted 6 lines
For the uevent, I would suggest to generate the global uevent as other drivers do it right now.
kobject_uevent(&data->hwmon_dev->kobj, KOBJ_CHANGE);An alternative would be to pass one of the changed attribute names as environment (eg the highest temperature 0->1 transition).
It would be okay to call 'kobject_uevent' function instead of 'kobject_uevent_env' function.
Quoted 5 lines
For the 1->0 transitions, I don't really have a good idea how to handle it if the chip does not generate interrupts in this case. Not really sure, though, if calling
sysfs_notifyeven makes sense in that case, since a poll on a "triggered" attribute file will be stuck forever.
I think the sysfs notification is not useful due to no support for 1->0 transitions. I will remove it in the next patch.
[snip]
Thanks.
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors