hwmon: Add driver for EXYNOS4 TMU
Subsystems (3)
PATCH v3 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 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 | 530 +++++++++++++++++++++++++++++ include/linux/platform_data/exynos4_tmu.h | 81 +++++ 5 files changed, 703 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 +530 -0
530 lines not on this page · raw message
include/linux/platform_data/exynos4_tmu.h new file +81 -0
81 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
Hi,
Some minor comments.
Removing the clean code, to reduce traffic.
Quoted 17 lines
Documentation/hwmon/exynos4_tmu new file +17
-0+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 +
Documentation/hwmon/exynos4_tmu line 80
Quoted 10 lines
Documentation/hwmon/exynos4_tmu new file +10
-0+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
All these are standard ABI for Thermal related Hwmon drivers. So, Do we really need to have them explained here again ?
Guenter/Jean, I would like to see your inputs here.
drivers/hwmon/exynos4_tmu.c line 139
Quoted 5 lines
drivers/hwmon/exynos4_tmu.c new file +5
-0+static int exynos4_tmu_initialize (struct platform_device *pdev) +{ +struct exynos4_tmu_data *data =platform_get_drvdata (pdev); +struct exynos4_tmu_platform_data *pdata = data->pdata; +unsigned int status, trim_info;
Can the status be a 'u8' since we are populating it with readb(...) ? I am blindly assuming readb returns a byte. Please correct me if I am wrong.
drivers/hwmon/exynos4_tmu.c line 209
Quoted 2 lines
drivers/hwmon/exynos4_tmu.c new file +2
-0+ +static int exynos4_tmu_read (struct exynos4_tmu_data *data)
The return type can better be 'u8', since translate_code_to_temp(...) returns a 'u8'.
drivers/hwmon/exynos4_tmu.c line 268
Quoted 3 lines
drivers/hwmon/exynos4_tmu.c new file +3
-0+static irqreturn_t exynos4_tmu_irq (int irq,void *id) +{ +struct exynos4_tmu_data *data = id;
I am not sure whether we _must_ cast 'id', as (struct exynos4_tmu_data *)..
drivers/hwmon/exynos4_tmu.c line 292
Quoted 11 lines
drivers/hwmon/exynos4_tmu.c new file +11
-0+static ssize_t exynos4_tmu_show_temp (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct exynos4_tmu_data *data =dev_get_drvdata (dev); +int ret; + + ret =exynos4_tmu_read (data); +if (ret <0 ) +return ret; +/* convert from degree Celsius to millidegree Celsius */ +return sprintf (buf,"%d\n" , ret *1000 );
One Opinion here:
I do not know what values your temp_code takes.
In the translate_code_to_temp function, we can add the code, to convert the value directly into millidegree Celsius. Basically, do the multiplication by 1000 there, to achieve a little more accuracy.
drivers/hwmon/exynos4_tmu.c line 301
Quoted 7 lines
drivers/hwmon/exynos4_tmu.c new file +7
-0+static ssize_t exynos4_tmu_show_alarm (struct device *dev, +struct device_attribute *devattr,char *buf) +{ +struct sensor_device_attribute *attr =to_sensor_dev_attr (devattr); +struct exynos4_tmu_data *data =dev_get_drvdata (dev); +struct exynos4_tmu_platform_data *pdata = data->pdata; +int temp, trigger_level;
trigger_level is an 'int' here and in the function below, it is an unsigned int, but defined as an 'u8' in .h file. Please keep the data type consistent across the code.
drivers/hwmon/exynos4_tmu.c line 318
Quoted 8 lines
drivers/hwmon/exynos4_tmu.c new file +8
-0+static ssize_t exynos4_tmu_show_level (struct device *dev, +struct device_attribute *devattr,char *buf) +{ +struct sensor_device_attribute *attr =to_sensor_dev_attr (devattr); +struct exynos4_tmu_data *data =dev_get_drvdata (dev); +struct exynos4_tmu_platform_data *pdata = data->pdata; +unsigned int temp = pdata->threshold + + pdata->trigger_levels[attr->index];
Pdata->threshold and pdata->trigger_levels, both are of type u8. So, why is temp an unsigned int ?
drivers/hwmon/exynos4_tmu.c line 468
Quoted 8 lines
drivers/hwmon/exynos4_tmu.c new file +8
-0+static int __devexit exynos4_tmu_remove(struct platform_device *pdev) +{ +struct exynos4_tmu_data *data =platform_get_drvdata (pdev); + +exynos4_tmu_control (pdev, false); + +hwmon_device_unregister (data->hwmon_dev); +sysfs_remove_group (&pdev->dev.kobj, &exynos4_tmu_attr_group);
Shouldn't we send a KOBJ_REMOVE event here ?
Quoted 4 lines
+/**
+ * structexynos4_tmu_platform_data
+ * @threshold: basic temperature for generating interrupt
+ * @trigger_levels: array for each interrupt levels
Please specify the Unit. Since we convert between millidegree Celsius Celsius, it is better to have a comment here, for thresholds and trigger_levels. Something like the following would do:
@threshold: basic temperature(in Celsius) for generating interrupt.
Thanks,
Durga
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 36 lines · Durgadoss
Hi,
Some minor comments.
Removing the clean code, to reduce traffic.Quoted 17 lines
Documentation/hwmon/exynos4_tmu new file +17
-0+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 +Documentation/hwmon/exynos4_tmu line 80
Quoted 10 lines
Documentation/hwmon/exynos4_tmu new file +10
-0+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 + ROAll these are standard ABI for Thermal related Hwmon drivers. So, Do we really need to have them explained here again ?
Quoted 2 lines
Guenter/Jean, I would like to see your inputs here.
For my part, I think listing the attributes is useful to show the user which attributes are supported without having to look into the code. In this case, listing the attributes is even more useful because it shows that the limits are RO.
Quoted 9 lines
drivers/hwmon/exynos4_tmu.c line 139
Quoted 5 lines
drivers/hwmon/exynos4_tmu.c new file +5
-0+static int exynos4_tmu_initialize (struct platform_device *pdev) +{ +struct exynos4_tmu_data *data =platform_get_drvdata (pdev); +struct exynos4_tmu_platform_data *pdata = data->pdata; +unsigned int status, trim_info;Can the status be a 'u8' since we are populating it with readb(...) ? I am blindly assuming readb returns a byte. Please correct me if I am wrong.
One general comment regarding variable types. On many platforms, u8 is more expensive than int or unsigned int because the compiler needs to mask pretty much every operation. That is probably not an issue for Intel CPUs, but for most others. For that reason, I usually leave it to the implementors to decide what variable types to use.
That is a bit different for stored data, but even there it does not provide value to embed an u8 in integers because the compiler will end up aligning the structure anyway.
Thanks,
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 4 lines · Durgadoss
Hi,
Some minor comments.
Removing the clean code, to reduce traffic.
[ ... ]
Quoted 6 lines
drivers/hwmon/exynos4_tmu.c line 209
Quoted 2 lines
drivers/hwmon/exynos4_tmu.c new file +2
-0+ +static int exynos4_tmu_read (struct exynos4_tmu_data *data)The return type can better be 'u8', since
translate_code_to_temp(...)returns a 'u8'.
Quoted 6 lines
drivers/hwmon/exynos4_tmu.c line 268
Quoted 3 lines
drivers/hwmon/exynos4_tmu.c new file +3
-0+static irqreturn_t exynos4_tmu_irq (int irq,void *id) +{ +struct exynos4_tmu_data *data = id;I am not sure whether we _must_ cast 'id', as (struct
exynos4_tmu_data*)..
Typecast is not necessary for void pointers.
[ ... ]
Quoted 12 lines
drivers/hwmon/exynos4_tmu.c line 468
Quoted 9 lines
drivers/hwmon/exynos4_tmu.c new file +8
-0+static int __devexit exynos4_tmu_remove(struct platform_device *pdev) +{ +struct exynos4_tmu_data *data =platform_get_drvdata (pdev); + +exynos4_tmu_control (pdev, false); + +hwmon_device_unregister (data->hwmon_dev); +sysfs_remove_group (&pdev->dev.kobj, &exynos4_tmu_attr_group);Shouldn't we send a
KOBJ_REMOVEevent here ?
sysfs_remove_group should take care of that, though I did not test it and may be wrong.
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 4 lines · Durgadoss
Hi,
Some minor comments.
Removing the clean code, to reduce traffic.
[snip]
Quoted 5 lines
Quoted 1 line
+static int
exynos4_tmu_read(struct exynos4_tmu_data *data)The return type can better be 'u8', since
translate_code_to_temp(...)returns a 'u8'.
The read function returns error code (-ENODATA) for abnormal case. So, the return type should be 'int'.
Quoted 6 lines
drivers/hwmon/exynos4_tmu.c line 268
Quoted 3 lines
drivers/hwmon/exynos4_tmu.c new file +3
-0+static irqreturn_t exynos4_tmu_irq (int irq,void *id) +{ +struct exynos4_tmu_data *data = id;I am not sure whether we _must_ cast 'id', as (struct
exynos4_tmu_data*)..
In exynos4_tmu_irq function, 'irq_work' field in 'exynos4_tmu_data' is accessed. Thus, it should be casted.
[snip]
Quoted 12 lines
drivers/hwmon/exynos4_tmu.c line 301
Quoted 7 lines
drivers/hwmon/exynos4_tmu.c new file +7
-0+static ssize_t exynos4_tmu_show_alarm (struct device *dev, +struct device_attribute *devattr,char *buf) +{ +struct sensor_device_attribute *attr =to_sensor_dev_attr (devattr); +struct exynos4_tmu_data *data =dev_get_drvdata (dev); +struct exynos4_tmu_platform_data *pdata = data->pdata; +int temp, trigger_level;
trigger_levelis an 'int' here and in the function below, it is an unsigned int, but defined as an 'u8' in .h file. Please keep the data type consistent across the code.
Okay, it would be better to change type from 'int' to 'unsigned int' or 'u8'.
[snip]
Quoted 10 lines
Quoted 4 lines
+/**
+ * structexynos4_tmu_platform_data
+ * @threshold: basic temperature for generating interrupt
+ * @trigger_levels: array for each interrupt levelsPlease specify the Unit. Since we convert between millidegree Celsius Celsius, it is better to have a comment here, for thresholds and
trigger_levels. Something like the following would do:
@threshold: basic temperature(in Celsius) for generating interrupt.
I will specify the unit for the both fields.
Quoted 3 lines
Thanks,
Durga
Thanks for your comment.
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 11 lines · Donggeun Kim
On 2011년 08월 29일 21:22, R, Durgadoss wrote:
The read function returns error code (-ENODATA) for abnormal case. So, the return type should be 'int'.Quoted 6 lines
drivers/hwmon/exynos4_tmu.c line 268
Quoted 3 lines
drivers/hwmon/exynos4_tmu.c new file +3
-0+static irqreturn_t exynos4_tmu_irq (int irq,void *id) +{ +struct exynos4_tmu_data *data = id;I am not sure whether we _must_ cast 'id', as (struct
exynos4_tmu_data*)..In
exynos4_tmu_irqfunction, 'irq_work' field in 'exynos4_tmu_data' is accessed. Thus, it should be casted.
The last sentence is 'Thus, it should not be casted'. It was my mistake.
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors