Skip to contentSkip to conversation

hwmon: Add driver for EXYNOS4 TMU

PATCH Superseded Donggeun Kim 2 participants 2 messages Sep 2, 2011

Subsystems (3)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 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 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               |  542 +++++++++++++++++++++++++++++
 include/linux/platform_data/exynos4_tmu.h |   83 +++++
 5 files changed, 717 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..7fe12c1
@@ -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 +542 -0

542 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 6 lines · Donggeun Kim

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

[ ... ]

drivers/hwmon/exynos4_tmu.c line 80

Quoted 11 lines
drivers/hwmon/exynos4_tmu.c new file +11 -0
+
+struct exynos4_tmu_data {
+       struct exynos4_tmu_platform_data *pdata;
+       struct device *hwmon_dev;
+       struct resource *mem;
+       void __iomem *base;
+       int irq;
+       struct work_struct irq_work;
+       struct mutex lock;
+       struct clk *clk;
+       unsigned int interrupt_stat;

I just noticed that this variable is only set and used in one function, so you can keep it as local variable there.

Quoted 2 lines
drivers/hwmon/exynos4_tmu.c new file +2 -0
+       u8 temp_error1, temp_error2;
+};

[ ... ]

drivers/hwmon/exynos4_tmu.c line 231

Quoted 10 lines
drivers/hwmon/exynos4_tmu.c new file +10 -0
+
+static int exynos4_tmu_read(struct exynos4_tmu_data *data)
+{
+       u8 temp_code, temp;
+
+       mutex_lock(&data->lock);
+       clk_enable(data->clk);
+
+       temp_code = readb(data->base + EXYNOS4_TMU_REG_CURRENT_TEMP);
+       temp = code_to_temp(data, temp_code);

temp is now an u8, so assigning a negative error to it won't do much good.

drivers/hwmon/exynos4_tmu.c line 238

Quoted 7 lines
drivers/hwmon/exynos4_tmu.c new file +7 -0
+
+       clk_disable(data->clk);
+       mutex_unlock(&data->lock);
+
+       return temp;
+}
+

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