Improve Exynos thermal driver
Subsystems (3)
A message that is not in the archive (sent off-list or not yet received): CGME20231120145057eucas1p2d3f7936d6a988d138af18e0011e7ad75@eucas1p2.samsung.com
v5 cover Improve Exynos thermal driver
This work improves Exynos thermal driver in various ways. This is related to the discussion in
https://lore.kernel.org/all/[email protected]/
The primary issue being fixed is a lockdep warning, which is fixed by the thermal: exynos: use set_trips patch. We also simplify the code in general.
Changelog:
v5:
- Used BIT wherever possible
- Simplified Exynos 7 code and used the correct register offsets for Exynos 7
- Refactored some common register-setting code
v4:
- Resolved merge conflict when applying thermal: exynos: split initialization of TMU and the thermal zone
- Reordered calls done when leaving exynos_tmu_initialize for symmetry
v3:
- Fixed regulator initialization
- Fixed formatting of some comments
v2:
- Added missing field descriptions
- Removed an unnecessary field description
- Removed the commits that made clock management more fine-grained (need more discussion), and adapted the new code to manage clocks
- Removed the devicetree changes (will be uploaded separately), changing the recipient list accordingly
- Improved formatting of the devm_request_threaded_irq call
Mateusz Majewski (9):
thermal: exynos: remove an unnecessary field description
thermal: exynos: drop id field
thermal: exynos: switch from workqueue-driven interrupt handling to
threaded interrupts
thermal: exynos: handle devm_regulator_get_optional return value
correctly
thermal: exynos: simplify regulator (de)initialization
thermal: exynos: stop using the threshold mechanism on Exynos 4210
thermal: exynos: split initialization of TMU and the thermal zone
thermal: exynos: use BIT wherever possible
thermal: exynos: use set_trips
drivers/thermal/samsung/exynos_tmu.c | 532 +++++++++++++-------------- 1 file changed, 258 insertions(+), 274 deletions(-)
Signature · 7 lines
2.42.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v5 1/9 thermal: exynos: remove an unnecessary field description
It seems that the field has been removed in one of the previous commits, but the description has been forgotten.
--- drivers/thermal/samsung/exynos_tmu.c | 1 - 1 file changed, 1 deletion(-)
drivers/thermal/samsung/exynos_tmu.c +0 -1
@@ -160,7 +160,6 @@ enum soc_type {* in the positive-TC generator block * 0 < reference_voltage <= 31 * @regulator: pointer to the TMU regulator structure. -* @reg_conf: pointer to structure to register with core thermal. * @tzd: pointer to thermal_zone_device structure * @ntrip: number of supported trip points. * @enabled: current status of TMU device
Signature · 7 lines
2.42.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v5 2/9 thermal: exynos: drop id field
In reply to Mateusz MajewskiWe do not use the value, and only Exynos 7 defines this alias anyway.
---
v1 -> v2: minor commit message rewording.
drivers/thermal/samsung/exynos_tmu.c | 6 ------ 1 file changed, 6 deletions(-)
drivers/thermal/samsung/exynos_tmu.c +0 -6
@@ -138,7 +138,6 @@ enum soc_type {/** * struct exynos_tmu_data : A structure to hold the private data of the TMU * driver -* @id: identifier of the one instance of the TMU controller. * @base: base address of the single instance of the TMU controller. * @base_second: base address of the common registers of the TMU controller. * @irq: irq number of the TMU controller.
@@ -172,7 +171,6 @@ enum soc_type {* @tmu_clear_irqs: SoC specific TMU interrupts clearing method */ struct exynos_tmu_data { -int id;void __iomem *base;void __iomem *base_second;int irq;
@@ -865,10 +863,6 @@ static int exynos_map_dt_data(struct platform_device *pdev)if (!data || !pdev->dev.of_node)return -ENODEV ; - data->id =of_alias_get_id (pdev->dev.of_node,"tmuctrl" ); -if (data->id <0 ) - data->id =0 ; - data->irq =irq_of_parse_and_map (pdev->dev.of_node,0 );if (data->irq <=0 ) {dev_err (&pdev->dev,"failed to get IRQ\n" );
Signature · 7 lines
2.42.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v5 3/9 thermal: exynos: switch from workqueue-driven interrupt handling to threaded interrupts
In reply to Mateusz MajewskiThe workqueue boilerplate is mostly one-to-one what the threaded interrupts do.
---
v1 -> v2: devm_request_threaded_irq call formatting change.
drivers/thermal/samsung/exynos_tmu.c | 29 +++++++++------------------- 1 file changed, 9 insertions(+), 20 deletions(-)
drivers/thermal/samsung/exynos_tmu.c +9 -20
@@ -142,7 +142,6 @@ enum soc_type {* @base_second: base address of the common registers of the TMU controller. * @irq: irq number of the TMU controller. * @soc: id of the SOC type. -* @irq_work: pointer to the irq work structure. * @lock: lock to implement synchronization. * @clk: pointer to the clock structure. * @clk_sec: pointer to the clock structure for accessing the base_second.
@@ -175,7 +174,6 @@ struct exynos_tmu_data {void __iomem *base_second;int irq;enum soc_type soc; -struct work_struct irq_work;struct mutex lock;struct clk *clk, *clk_sec, *sclk;u32 cal_type;
@@ -763,10 +761,9 @@ static int exynos7_tmu_read(struct exynos_tmu_data *data)EXYNOS7_TMU_TEMP_MASK ; } -static void exynos_tmu_work (struct work_struct *work) +static irqreturn_t exynos_tmu_threaded_irq (int irq,void *id) { -struct exynos_tmu_data *data =container_of (work, - struct exynos_tmu_data, irq_work); +struct exynos_tmu_data *data = id;thermal_zone_device_update (data->tzd,THERMAL_EVENT_UNSPECIFIED );
@@ -778,7 +775,8 @@ static void exynos_tmu_work(struct work_struct *work)clk_disable (data->clk);mutex_unlock (&data->lock); -enable_irq (data->irq); + +return IRQ_HANDLED ; }static void exynos4210_tmu_clear_irqs (struct exynos_tmu_data *data)
@@ -812,16 +810,6 @@ static void exynos4210_tmu_clear_irqs(struct exynos_tmu_data *data)writel (val_irq, data->base + tmu_intclear); } -static irqreturn_t exynos_tmu_irq (int irq,void *id) -{ -struct exynos_tmu_data *data = id; - -disable_irq_nosync (irq); -schedule_work (&data->irq_work); - -return IRQ_HANDLED ; -} -static const struct of_device_id exynos_tmu_match[] = { { .compatible ="samsung,exynos3250-tmu" ,
@@ -1023,8 +1011,6 @@ static int exynos_tmu_probe(struct platform_device *pdev)if (ret) goto err_sensor; -INIT_WORK (&data->irq_work, exynos_tmu_work); - data->clk =devm_clk_get (&pdev->dev,"tmu_apbif" );if (IS_ERR (data->clk)) {dev_err (&pdev->dev,"Failed to get clock\n" );
@@ -1093,8 +1079,11 @@ static int exynos_tmu_probe(struct platform_device *pdev) goto err_sclk; } - ret =devm_request_irq (&pdev->dev, data->irq, exynos_tmu_irq, -IRQF_TRIGGER_RISING |IRQF_SHARED ,dev_name (&pdev->dev), data); + ret =devm_request_threaded_irq (&pdev->dev, data->irq,NULL , + exynos_tmu_threaded_irq, +IRQF_TRIGGER_RISING + |IRQF_SHARED |IRQF_ONESHOT , +dev_name (&pdev->dev), data);if (ret) {dev_err (&pdev->dev,"Failed to request irq: %d\n" , data->irq); goto err_sclk;
Signature · 7 lines
2.42.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v5 4/9 thermal: exynos: handle devm_regulator_get_optional return value correctly
In reply to Mateusz MajewskiCurrently, if regulator is required in the SoC, but devm_regulator_get_optional fails for whatever reason, the execution will proceed without propagating the error. Meanwhile there is no reason to output the error in case of -ENODEV.
---
v3 -> v4: Moved info about not outputting error to the correct commit
message.
drivers/thermal/samsung/exynos_tmu.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/thermal/samsung/exynos_tmu.c +10 -2
@@ -1002,9 +1002,17 @@ static int exynos_tmu_probe(struct platform_device *pdev)return ret; } }else { -if (PTR_ERR (data->regulator) == -EPROBE_DEFER ) + ret =PTR_ERR (data->regulator); +switch (ret) { +case -ENODEV : +break ; +case -EPROBE_DEFER :return -EPROBE_DEFER ; -dev_info (&pdev->dev,"Regulator node (vtmu) not found\n" ); +default : +dev_err (&pdev->dev,"Failed to get regulator: %d\n" , + ret); +return ret; + } } ret =exynos_map_dt_data (pdev);
Signature · 7 lines
2.42.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v5 5/9 thermal: exynos: simplify regulator (de)initialization
In reply to Mateusz MajewskiWe rewrite the initialization to enable the regulator as part of devm, which allows us to not handle the struct instance manually.
---
v3 -> v4: Resolved merge conflict and moved info about not outputting
error to the correct commit message.
v2 -> v3: Fixed error handling of devm_regulator_get_optional to handle
the case in which the regulator is available, but enabling it fails. Also removed the error message, split into two commits and reworded the commit message.
drivers/thermal/samsung/exynos_tmu.c | 49 +++++++++------------------- 1 file changed, 15 insertions(+), 34 deletions(-)
drivers/thermal/samsung/exynos_tmu.c +15 -34
@@ -157,7 +157,6 @@ enum soc_type {* @reference_voltage: reference voltage of amplifier * in the positive-TC generator block * 0 < reference_voltage <= 31 -* @regulator: pointer to the TMU regulator structure. * @tzd: pointer to thermal_zone_device structure * @ntrip: number of supported trip points. * @enabled: current status of TMU device
@@ -183,7 +182,6 @@ struct exynos_tmu_data {u16 temp_error1, temp_error2;u8 gain;u8 reference_voltage; -struct regulator *regulator;struct thermal_zone_device *tzd;unsigned int ntrip;bool enabled;
@@ -994,50 +992,40 @@ static int exynos_tmu_probe(struct platform_device *pdev)* TODO: Add regulator as an SOC feature, so that regulator enable * is a compulsory call. */ - data->regulator =devm_regulator_get_optional (&pdev->dev,"vtmu" ); -if (!IS_ERR (data->regulator)) { - ret =regulator_enable (data->regulator); -if (ret) { -dev_err (&pdev->dev,"failed to enable vtmu\n" ); -return ret; - } - }else { - ret =PTR_ERR (data->regulator); -switch (ret) { -case -ENODEV : -break ; -case -EPROBE_DEFER : -return -EPROBE_DEFER ; -default : -dev_err (&pdev->dev,"Failed to get regulator: %d\n" , - ret); -return ret; - } + ret =devm_regulator_get_enable_optional (&pdev->dev,"vtmu" ); +switch (ret) { +case 0 : +case -ENODEV : +break ; +case -EPROBE_DEFER : +return -EPROBE_DEFER ; +default : +dev_err (&pdev->dev,"Failed to get enabled regulator: %d\n" , + ret); +return ret; } ret =exynos_map_dt_data (pdev);if (ret) - goto err_sensor; +return ret; data->clk =devm_clk_get (&pdev->dev,"tmu_apbif" );if (IS_ERR (data->clk)) {dev_err (&pdev->dev,"Failed to get clock\n" ); - ret =PTR_ERR (data->clk); - goto err_sensor; +return PTR_ERR (data->clk); } data->clk_sec =devm_clk_get (&pdev->dev,"tmu_triminfo_apbif" );if (IS_ERR (data->clk_sec)) {if (data->soc ==SOC_ARCH_EXYNOS5420_TRIMINFO ) {dev_err (&pdev->dev,"Failed to get triminfo clock\n" ); - ret =PTR_ERR (data->clk_sec); - goto err_sensor; +return PTR_ERR (data->clk_sec); } }else { ret =clk_prepare (data->clk_sec);if (ret) {dev_err (&pdev->dev,"Failed to get clock\n" ); - goto err_sensor; +return ret; } }
@@ -1107,10 +1095,6 @@ static int exynos_tmu_probe(struct platform_device *pdev) err_clk_sec:if (!IS_ERR (data->clk_sec))clk_unprepare (data->clk_sec); -err_sensor: -if (!IS_ERR (data->regulator)) -regulator_disable (data->regulator); -return ret; }
@@ -1124,9 +1108,6 @@ static void exynos_tmu_remove(struct platform_device *pdev)clk_unprepare (data->clk);if (!IS_ERR (data->clk_sec))clk_unprepare (data->clk_sec); - -if (!IS_ERR (data->regulator)) -regulator_disable (data->regulator); }#ifdef CONFIG_PM_SLEEP
Signature · 7 lines
2.42.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v5 6/9 thermal: exynos: stop using the threshold mechanism on Exynos 4210
In reply to Mateusz MajewskiExynos 4210 supports setting a base threshold value, which is added to all trip points. This might be useful, but is not really necessary in our usecase, so we always set it to 0 to simplify the code a bit.
Additionally, this change makes it so that we convert the value to the calibrated one in a slightly different place. This is more correct morally, though it does not make any change when single-point calibration is being used (which is the case currently).
--- drivers/thermal/samsung/exynos_tmu.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-)
drivers/thermal/samsung/exynos_tmu.c +3 -14
@@ -343,20 +343,7 @@ static void exynos_tmu_control(struct platform_device *pdev, bool on)static void exynos4210_tmu_set_trip_temp (struct exynos_tmu_data *data,int trip_id,u8 temp) { -struct thermal_trip trip; -u8 ref, th_code; - -if (thermal_zone_get_trip (data->tzd,0 , &trip)) -return ; - - ref = trip.temperature /MCELSIUS ; - -if (trip_id ==0 ) { - th_code =temp_to_code (data, ref); -writeb (th_code, data->base +EXYNOS4210_TMU_REG_THRESHOLD_TEMP ); - } - - temp -= ref; + temp =temp_to_code (data, temp);writeb (temp, data->base +EXYNOS4210_TMU_REG_TRIG_LEVEL0 + trip_id *4 ); }
@@ -371,6 +358,8 @@ static void exynos4210_tmu_initialize(struct platform_device *pdev)struct exynos_tmu_data *data =platform_get_drvdata (pdev);sanitize_temp_error (data,readl (data->base +EXYNOS_TMU_REG_TRIMINFO )); + +writeb (0 , data->base +EXYNOS4210_TMU_REG_THRESHOLD_TEMP ); } static void exynos4412_tmu_set_trip_temp(struct exynos_tmu_data *data,
Signature · 7 lines
2.42.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v5 7/9 thermal: exynos: split initialization of TMU and the thermal zone
In reply to Mateusz MajewskiThis will be needed in the future, as the thermal zone subsystem might call our callbacks right after devm_thermal_of_zone_register. Currently we just make get_temp return EAGAIN in such case, but this will not be possible with state-modifying callbacks, for instance set_trips.
---
v3 -> v4: Reordered calls done while leaving exynos_tmu_initialize so
that they mirror the calls done while entering this function.
v1 -> v2: We take clocks into account; exynos_tmu_initialize needs both
clocks, as tmu_initialize might use the base_second registers. However, exynos_thermal_zone_configure only needs clk.
drivers/thermal/samsung/exynos_tmu.c | 104 +++++++++++++++------------ 1 file changed, 60 insertions(+), 44 deletions(-)
drivers/thermal/samsung/exynos_tmu.c +60 -44
@@ -251,25 +251,8 @@ static void sanitize_temp_error(struct exynos_tmu_data *data, u32 trim_info)static int exynos_tmu_initialize (struct platform_device *pdev) {struct exynos_tmu_data *data =platform_get_drvdata (pdev); -struct thermal_zone_device *tzd = data->tzd; -int num_trips =thermal_zone_get_num_trips (tzd);unsigned int status; -int ret =0 , temp; - - ret =thermal_zone_get_crit_temp (tzd, &temp); -if (ret && data->soc !=SOC_ARCH_EXYNOS5433 ) {/* FIXME */ -dev_err (&pdev->dev, -"No CRITICAL trip point defined in device tree!\n" ); - goto out; - } - -if (num_trips > data->ntrip) { -dev_info (&pdev->dev, -"More trip points than supported by this TMU.\n" ); -dev_info (&pdev->dev, -"%d trip points should be configured in polling mode.\n" , - num_trips - data->ntrip); - } +int ret =0 ;mutex_lock (&data->lock);clk_enable (data->clk);
@@ -280,32 +263,63 @@ static int exynos_tmu_initialize(struct platform_device *pdev)if (!status) { ret = -EBUSY ; }else { -int i, ntrips = -min_t (int, num_trips, data->ntrip); - data->tmu_initialize (pdev); - -/* Write temperature code for rising and falling threshold */ -for (i =0 ; i < ntrips; i++) { - -struct thermal_trip trip; - - ret =thermal_zone_get_trip (tzd, i, &trip); -if (ret) - goto err; - - data->tmu_set_trip_temp (data, i, trip.temperature /MCELSIUS ); - data->tmu_set_trip_hyst (data, i, trip.temperature /MCELSIUS , - trip.hysteresis /MCELSIUS ); - } - data->tmu_clear_irqs (data); } + +if (!IS_ERR (data->clk_sec)) +clk_disable (data->clk_sec); +clk_disable (data->clk); +mutex_unlock (&data->lock); + +return ret; +} + +static int exynos_thermal_zone_configure (struct platform_device *pdev) +{ +struct exynos_tmu_data *data =platform_get_drvdata (pdev); +struct thermal_zone_device *tzd = data->tzd; +int i, num_trips =thermal_zone_get_num_trips (tzd); +int ret =0 , temp; + + ret =thermal_zone_get_crit_temp (tzd, &temp); + +if (ret && data->soc !=SOC_ARCH_EXYNOS5433 ) {/* FIXME */ +dev_err (&pdev->dev, +"No CRITICAL trip point defined in device tree!\n" ); + goto out; + } + +mutex_lock (&data->lock); + +if (num_trips > data->ntrip) { +dev_info (&pdev->dev, +"More trip points than supported by this TMU.\n" ); +dev_info (&pdev->dev, +"%d trip points should be configured in polling mode.\n" , + num_trips - data->ntrip); + } + +clk_enable (data->clk); + + num_trips =min_t (int, num_trips, data->ntrip); + +/* Write temperature code for rising and falling threshold */ +for (i =0 ; i < num_trips; i++) { +struct thermal_trip trip; + + ret =thermal_zone_get_trip (tzd, i, &trip); +if (ret) + goto err; + + data->tmu_set_trip_temp (data, i, trip.temperature /MCELSIUS ); + data->tmu_set_trip_hyst (data, i, trip.temperature /MCELSIUS , + trip.hysteresis /MCELSIUS ); + } + err:clk_disable (data->clk);mutex_unlock (&data->lock); -if (!IS_ERR (data->clk_sec)) -clk_disable (data->clk_sec); out:return ret; }
@@ -1044,10 +1058,12 @@ static int exynos_tmu_probe(struct platform_device *pdev)break ; } -/* -* data->tzd must be registered before calling exynos_tmu_initialize(), -* requesting irq and calling exynos_tmu_control(). -*/ + ret =exynos_tmu_initialize (pdev); +if (ret) { +dev_err (&pdev->dev,"Failed to initialize TMU\n" ); +return ret; + } + data->tzd =devm_thermal_of_zone_register (&pdev->dev,0 , data, &exynos_sensor_ops);if (IS_ERR (data->tzd)) {
@@ -1058,9 +1074,9 @@ static int exynos_tmu_probe(struct platform_device *pdev) goto err_sclk; } - ret =exynos_tmu_initialize (pdev); + ret =exynos_thermal_zone_configure (pdev);if (ret) { -dev_err (&pdev->dev,"Failed to initialize TMU\n" ); +dev_err (&pdev->dev,"Failed to configure the thermal zone\n" ); goto err_sclk; }
Signature · 7 lines
2.42.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v5 7/9] thermal: exynos: split initialization of TMU and the thermal zone
Hi Mateusz,
kernel test robot noticed the following build warnings:
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Mateusz-Majewski/thermal-exynos-remove-an-unnecessary-field-description/20231120-230641 base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git thermal patch link: https://lore.kernel.org/r/20231120145049.310509-8-m.majewski2%40samsung.com patch subject: [PATCH v5 7/9] thermal: exynos: split initialization of TMU and the thermal zone config: arm-randconfig-r081-20231123 (https://download.01.org/0day-ci/archive/20231125/[email protected]/config) compiler: arm-linux-gnueabi-gcc (GCC) 13.2.0 reproduce: (https://download.01.org/0day-ci/archive/20231125/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]> | Reported-by: Dan Carpenter <[email protected]> | Closes: https://lore.kernel.org/r/[email protected]/
smatch warnings:drivers/thermal/samsung/exynos_tmu.c:1064 exynos_tmu_probe() warn: missing unwind goto? drivers/thermal/samsung/exynos_tmu.c:1103 exynos_tmu_probe() warn: 'data->clk' from clk_prepare() not released on lines: 1064. drivers/thermal/samsung/exynos_tmu.c:1103 exynos_tmu_probe() warn: 'data->clk_sec' from clk_prepare() not released on lines: 1064. drivers/thermal/samsung/exynos_tmu.c:1103 exynos_tmu_probe() warn: 'data->sclk' from clk_prepare_enable() not released on lines: 1064.
vim +1064 drivers/thermal/samsung/exynos_tmu.c
cebe7373a7e659 drivers/thermal/samsung/exynos_tmu.c Amit Daniel Kachhap 2013-06-24 980 static int exynos_tmu_probe(struct platform_device *pdev)
cebe7373a7e659 drivers/thermal/samsung/exynos_tmu.c Amit Daniel Kachhap 2013-06-24 981 {
3b6a1a805f3424 drivers/thermal/samsung/exynos_tmu.c Lukasz Majewski 2015-01-23 982 struct exynos_tmu_data *data;
3b6a1a805f3424 drivers/thermal/samsung/exynos_tmu.c Lukasz Majewski 2015-01-23 983 int ret;
cebe7373a7e659 drivers/thermal/samsung/exynos_tmu.c Amit Daniel Kachhap 2013-06-24 984
79e093c3fe9de9 drivers/thermal/exynos_thermal.c Amit Daniel Kachhap 2012-08-16 985 data = devm_kzalloc(&pdev->dev, sizeof(struct exynos_tmu_data),
79e093c3fe9de9 drivers/thermal/exynos_thermal.c Amit Daniel Kachhap 2012-08-16 986 GFP_KERNEL);
2a9675b39ad1af drivers/thermal/samsung/exynos_tmu.c Jingoo Han 2014-05-07 987 if (!data)
9d97e5c81e15af drivers/hwmon/exynos4_tmu.c Donggeun Kim 2011-09-07 988 return -ENOMEM;
9d97e5c81e15af drivers/hwmon/exynos4_tmu.c Donggeun Kim 2011-09-07 989
cebe7373a7e659 drivers/thermal/samsung/exynos_tmu.c Amit Daniel Kachhap 2013-06-24 990 platform_set_drvdata(pdev, data);
cebe7373a7e659 drivers/thermal/samsung/exynos_tmu.c Amit Daniel Kachhap 2013-06-24 991 mutex_init(&data->lock);
9d97e5c81e15af drivers/hwmon/exynos4_tmu.c Donggeun Kim 2011-09-07 992
824ead03b78403 drivers/thermal/samsung/exynos_tmu.c Krzysztof Kozlowski 2015-10-08 993 /*
824ead03b78403 drivers/thermal/samsung/exynos_tmu.c Krzysztof Kozlowski 2015-10-08 994 * Try enabling the regulator if found
824ead03b78403 drivers/thermal/samsung/exynos_tmu.c Krzysztof Kozlowski 2015-10-08 995 * TODO: Add regulator as an SOC feature, so that regulator enable
824ead03b78403 drivers/thermal/samsung/exynos_tmu.c Krzysztof Kozlowski 2015-10-08 996 * is a compulsory call.
824ead03b78403 drivers/thermal/samsung/exynos_tmu.c Krzysztof Kozlowski 2015-10-08 997 */
ef1639e66e72af drivers/thermal/samsung/exynos_tmu.c Mateusz Majewski 2023-11-20 998 ret = devm_regulator_get_enable_optional(&pdev->dev, "vtmu");
b2f20752180f71 drivers/thermal/samsung/exynos_tmu.c Mateusz Majewski 2023-11-20 999 switch (ret) {
ef1639e66e72af drivers/thermal/samsung/exynos_tmu.c Mateusz Majewski 2023-11-20 1000 case 0:
b2f20752180f71 drivers/thermal/samsung/exynos_tmu.c Mateusz Majewski 2023-11-20 1001 case -ENODEV:
b2f20752180f71 drivers/thermal/samsung/exynos_tmu.c Mateusz Majewski 2023-11-20 1002 break;
b2f20752180f71 drivers/thermal/samsung/exynos_tmu.c Mateusz Majewski 2023-11-20 1003 case -EPROBE_DEFER:
ccb361d2fdda89 drivers/thermal/samsung/exynos_tmu.c Javier Martinez Canillas 2016-02-18 1004 return -EPROBE_DEFER;
b2f20752180f71 drivers/thermal/samsung/exynos_tmu.c Mateusz Majewski 2023-11-20 1005 default:
ef1639e66e72af drivers/thermal/samsung/exynos_tmu.c Mateusz Majewski 2023-11-20 1006 dev_err(&pdev->dev, "Failed to get enabled regulator: %d\n",
b2f20752180f71 drivers/thermal/samsung/exynos_tmu.c Mateusz Majewski 2023-11-20 1007 ret);
b2f20752180f71 drivers/thermal/samsung/exynos_tmu.c Mateusz Majewski 2023-11-20 1008 return ret;
b2f20752180f71 drivers/thermal/samsung/exynos_tmu.c Mateusz Majewski 2023-11-20 1009 }
824ead03b78403 drivers/thermal/samsung/exynos_tmu.c Krzysztof Kozlowski 2015-10-08 1010
cebe7373a7e659 drivers/thermal/samsung/exynos_tmu.c Amit Daniel Kachhap 2013-06-24 1011 ret = exynos_map_dt_data(pdev);
cebe7373a7e659 drivers/thermal/samsung/exynos_tmu.c Amit Daniel Kachhap 2013-06-24 1012 if (ret)
ef1639e66e72af drivers/thermal/samsung/exynos_tmu.c Mateusz Majewski 2023-11-20 1013 return ret;
9d97e5c81e15af drivers/hwmon/exynos4_tmu.c Donggeun Kim 2011-09-07 1014
2a16279c68bcfa drivers/thermal/exynos_thermal.c Sachin Kamat 2013-04-18 1015 data->clk = devm_clk_get(&pdev->dev, "tmu_apbif");
9d97e5c81e15af drivers/hwmon/exynos4_tmu.c Donggeun Kim 2011-09-07 1016 if (IS_ERR(data->clk)) {
9d97e5c81e15af drivers/hwmon/exynos4_tmu.c Donggeun Kim 2011-09-07 1017 dev_err(&pdev->dev, "Failed to get clock\n");
ef1639e66e72af drivers/thermal/samsung/exynos_tmu.c Mateusz Majewski 2023-11-20 1018 return PTR_ERR(data->clk);
9d97e5c81e15af drivers/hwmon/exynos4_tmu.c Donggeun Kim 2011-09-07 1019 }
9d97e5c81e15af drivers/hwmon/exynos4_tmu.c Donggeun Kim 2011-09-07 1020
14a11dc7e0dbf4 drivers/thermal/samsung/exynos_tmu.c Naveen Krishna Chatradhi 2013-12-19 1021 data->clk_sec = devm_clk_get(&pdev->dev, "tmu_triminfo_apbif");
14a11dc7e0dbf4 drivers/thermal/samsung/exynos_tmu.c Naveen Krishna Chatradhi 2013-12-19 1022 if (IS_ERR(data->clk_sec)) {
14a11dc7e0dbf4 drivers/thermal/samsung/exynos_tmu.c Naveen Krishna Chatradhi 2013-12-19 1023 if (data->soc == SOC_ARCH_EXYNOS5420_TRIMINFO) {
14a11dc7e0dbf4 drivers/thermal/samsung/exynos_tmu.c Naveen Krishna Chatradhi 2013-12-19 1024 dev_err(&pdev->dev, "Failed to get triminfo clock\n");
ef1639e66e72af drivers/thermal/samsung/exynos_tmu.c Mateusz Majewski 2023-11-20 1025 return PTR_ERR(data->clk_sec);
14a11dc7e0dbf4 drivers/thermal/samsung/exynos_tmu.c Naveen Krishna Chatradhi 2013-12-19 1026 }
14a11dc7e0dbf4 drivers/thermal/samsung/exynos_tmu.c Naveen Krishna Chatradhi 2013-12-19 1027 } else {
14a11dc7e0dbf4 drivers/thermal/samsung/exynos_tmu.c Naveen Krishna Chatradhi 2013-12-19 1028 ret = clk_prepare(data->clk_sec);
14a11dc7e0dbf4 drivers/thermal/samsung/exynos_tmu.c Naveen Krishna Chatradhi 2013-12-19 1029 if (ret) {
14a11dc7e0dbf4 drivers/thermal/samsung/exynos_tmu.c Naveen Krishna Chatradhi 2013-12-19 1030 dev_err(&pdev->dev, "Failed to get clock\n");
ef1639e66e72af drivers/thermal/samsung/exynos_tmu.c Mateusz Majewski 2023-11-20 1031 return ret;
14a11dc7e0dbf4 drivers/thermal/samsung/exynos_tmu.c Naveen Krishna Chatradhi 2013-12-19 1032 }
14a11dc7e0dbf4 drivers/thermal/samsung/exynos_tmu.c Naveen Krishna Chatradhi 2013-12-19 1033 }
14a11dc7e0dbf4 drivers/thermal/samsung/exynos_tmu.c Naveen Krishna Chatradhi 2013-12-19 1034
14a11dc7e0dbf4 drivers/thermal/samsung/exynos_tmu.c Naveen Krishna Chatradhi 2013-12-19 1035 ret = clk_prepare(data->clk);
14a11dc7e0dbf4 drivers/thermal/samsung/exynos_tmu.c Naveen Krishna Chatradhi 2013-12-19 1036 if (ret) {
14a11dc7e0dbf4 drivers/thermal/samsung/exynos_tmu.c Naveen Krishna Chatradhi 2013-12-19 1037 dev_err(&pdev->dev, "Failed to get clock\n");
14a11dc7e0dbf4 drivers/thermal/samsung/exynos_tmu.c Naveen Krishna Chatradhi 2013-12-19 1038 goto err_clk_sec;
14a11dc7e0dbf4 drivers/thermal/samsung/exynos_tmu.c Naveen Krishna Chatradhi 2013-12-19 1039 }
2a16279c68bcfa drivers/thermal/exynos_thermal.c Sachin Kamat 2013-04-18 1040
488c7455d74ce0 drivers/thermal/samsung/exynos_tmu.c Chanwoo Choi 2015-03-10 1041 switch (data->soc) {
488c7455d74ce0 drivers/thermal/samsung/exynos_tmu.c Chanwoo Choi 2015-03-10 1042 case SOC_ARCH_EXYNOS5433:
488c7455d74ce0 drivers/thermal/samsung/exynos_tmu.c Chanwoo Choi 2015-03-10 1043 case SOC_ARCH_EXYNOS7:
6c247393cfdd66 drivers/thermal/samsung/exynos_tmu.c Abhilash Kesavan 2015-01-27 1044 data->sclk = devm_clk_get(&pdev->dev, "tmu_sclk");
6c247393cfdd66 drivers/thermal/samsung/exynos_tmu.c Abhilash Kesavan 2015-01-27 1045 if (IS_ERR(data->sclk)) {
6c247393cfdd66 drivers/thermal/samsung/exynos_tmu.c Abhilash Kesavan 2015-01-27 1046 dev_err(&pdev->dev, "Failed to get sclk\n");
02d438f62c05f0 drivers/thermal/samsung/exynos_tmu.c Dan Carpenter 2021-08-10 1047 ret = PTR_ERR(data->sclk);
6c247393cfdd66 drivers/thermal/samsung/exynos_tmu.c Abhilash Kesavan 2015-01-27 1048 goto err_clk;
6c247393cfdd66 drivers/thermal/samsung/exynos_tmu.c Abhilash Kesavan 2015-01-27 1049 } else {
6c247393cfdd66 drivers/thermal/samsung/exynos_tmu.c Abhilash Kesavan 2015-01-27 1050 ret = clk_prepare_enable(data->sclk);
6c247393cfdd66 drivers/thermal/samsung/exynos_tmu.c Abhilash Kesavan 2015-01-27 1051 if (ret) {
6c247393cfdd66 drivers/thermal/samsung/exynos_tmu.c Abhilash Kesavan 2015-01-27 1052 dev_err(&pdev->dev, "Failed to enable sclk\n");
6c247393cfdd66 drivers/thermal/samsung/exynos_tmu.c Abhilash Kesavan 2015-01-27 1053 goto err_clk;
6c247393cfdd66 drivers/thermal/samsung/exynos_tmu.c Abhilash Kesavan 2015-01-27 1054 }
6c247393cfdd66 drivers/thermal/samsung/exynos_tmu.c Abhilash Kesavan 2015-01-27 1055 }
488c7455d74ce0 drivers/thermal/samsung/exynos_tmu.c Chanwoo Choi 2015-03-10 1056 break;
488c7455d74ce0 drivers/thermal/samsung/exynos_tmu.c Chanwoo Choi 2015-03-10 1057 default:
488c7455d74ce0 drivers/thermal/samsung/exynos_tmu.c Chanwoo Choi 2015-03-10 1058 break;
baba1ebb99ba1f drivers/thermal/samsung/exynos_tmu.c Krzysztof Kozlowski 2015-10-08 1059 }
6c247393cfdd66 drivers/thermal/samsung/exynos_tmu.c Abhilash Kesavan 2015-01-27 1060
9f72236db6c75b drivers/thermal/samsung/exynos_tmu.c Mateusz Majewski 2023-11-20 1061 ret = exynos_tmu_initialize(pdev);
9f72236db6c75b drivers/thermal/samsung/exynos_tmu.c Mateusz Majewski 2023-11-20 1062 if (ret) {
9f72236db6c75b drivers/thermal/samsung/exynos_tmu.c Mateusz Majewski 2023-11-20 1063 dev_err(&pdev->dev, "Failed to initialize TMU\n");9f72236db6c75b drivers/thermal/samsung/exynos_tmu.c Mateusz Majewski 2023-11-20 @1064 return ret;
All these warnings are basically saying that this should be goto err_sclk;
9f72236db6c75b drivers/thermal/samsung/exynos_tmu.c Mateusz Majewski 2023-11-20 1065 }
9f72236db6c75b drivers/thermal/samsung/exynos_tmu.c Mateusz Majewski 2023-11-20 1066
7ea98f70c73ea3 drivers/thermal/samsung/exynos_tmu.c Daniel Lezcano 2022-08-05 1067 data->tzd = devm_thermal_of_zone_register(&pdev->dev, 0, data,
9e4249b4034090 drivers/thermal/samsung/exynos_tmu.c Krzysztof Kozlowski 2015-10-08 1068 &exynos_sensor_ops);
9e4249b4034090 drivers/thermal/samsung/exynos_tmu.c Krzysztof Kozlowski 2015-10-08 1069 if (IS_ERR(data->tzd)) {
9e4249b4034090 drivers/thermal/samsung/exynos_tmu.c Krzysztof Kozlowski 2015-10-08 1070 ret = PTR_ERR(data->tzd);
82bdde8ecdd7e5 drivers/thermal/samsung/exynos_tmu.c Marek Szyprowski 2020-02-28 1071 if (ret != -EPROBE_DEFER)
82bdde8ecdd7e5 drivers/thermal/samsung/exynos_tmu.c Marek Szyprowski 2020-02-28 1072 dev_err(&pdev->dev, "Failed to register sensor: %d\n",
82bdde8ecdd7e5 drivers/thermal/samsung/exynos_tmu.c Marek Szyprowski 2020-02-28 1073 ret);
9e4249b4034090 drivers/thermal/samsung/exynos_tmu.c Krzysztof Kozlowski 2015-10-08 1074 goto err_sclk;
9e4249b4034090 drivers/thermal/samsung/exynos_tmu.c Krzysztof Kozlowski 2015-10-08 1075 }
6c247393cfdd66 drivers/thermal/samsung/exynos_tmu.c Abhilash Kesavan 2015-01-27 1076
9f72236db6c75b drivers/thermal/samsung/exynos_tmu.c Mateusz Majewski 2023-11-20 1077 ret = exynos_thermal_zone_configure(pdev);
9d97e5c81e15af drivers/hwmon/exynos4_tmu.c Donggeun Kim 2011-09-07 1078 if (ret) {
9f72236db6c75b drivers/thermal/samsung/exynos_tmu.c Mateusz Majewski 2023-11-20 1079 dev_err(&pdev->dev, "Failed to configure the thermal zone\n");
7ea98f70c73ea3 drivers/thermal/samsung/exynos_tmu.c Daniel Lezcano 2022-08-05 1080 goto err_sclk;
9d97e5c81e15af drivers/hwmon/exynos4_tmu.c Donggeun Kim 2011-09-07 1081 }
9d97e5c81e15af drivers/hwmon/exynos4_tmu.c Donggeun Kim 2011-09-07 1082
4147281723b2e6 drivers/thermal/samsung/exynos_tmu.c Mateusz Majewski 2023-11-20 1083 ret = devm_request_threaded_irq(&pdev->dev, data->irq, NULL,
4147281723b2e6 drivers/thermal/samsung/exynos_tmu.c Mateusz Majewski 2023-11-20 1084 exynos_tmu_threaded_irq,
4147281723b2e6 drivers/thermal/samsung/exynos_tmu.c Mateusz Majewski 2023-11-20 1085 IRQF_TRIGGER_RISING
4147281723b2e6 drivers/thermal/samsung/exynos_tmu.c Mateusz Majewski 2023-11-20 1086 | IRQF_SHARED | IRQF_ONESHOT,
4147281723b2e6 drivers/thermal/samsung/exynos_tmu.c Mateusz Majewski 2023-11-20 1087 dev_name(&pdev->dev), data);
cebe7373a7e659 drivers/thermal/samsung/exynos_tmu.c Amit Daniel Kachhap 2013-06-24 1088 if (ret) {
cebe7373a7e659 drivers/thermal/samsung/exynos_tmu.c Amit Daniel Kachhap 2013-06-24 1089 dev_err(&pdev->dev, "Failed to request irq: %d\n", data->irq);
7ea98f70c73ea3 drivers/thermal/samsung/exynos_tmu.c Daniel Lezcano 2022-08-05 1090 goto err_sclk;
cebe7373a7e659 drivers/thermal/samsung/exynos_tmu.c Amit Daniel Kachhap 2013-06-24 1091 }
bbf63be4f33135 drivers/thermal/exynos_thermal.c Jonghwa Lee 2012-11-21 1092
3b6a1a805f3424 drivers/thermal/samsung/exynos_tmu.c Lukasz Majewski 2015-01-23 1093 exynos_tmu_control(pdev, true);
9d97e5c81e15af drivers/hwmon/exynos4_tmu.c Donggeun Kim 2011-09-07 1094 return 0;
9e4249b4034090 drivers/thermal/samsung/exynos_tmu.c Krzysztof Kozlowski 2015-10-08 1095
6c247393cfdd66 drivers/thermal/samsung/exynos_tmu.c Abhilash Kesavan 2015-01-27 1096 err_sclk:
6c247393cfdd66 drivers/thermal/samsung/exynos_tmu.c Abhilash Kesavan 2015-01-27 1097 clk_disable_unprepare(data->sclk);
9d97e5c81e15af drivers/hwmon/exynos4_tmu.c Donggeun Kim 2011-09-07 1098 err_clk:
2a16279c68bcfa drivers/thermal/exynos_thermal.c Sachin Kamat 2013-04-18 1099 clk_unprepare(data->clk);
14a11dc7e0dbf4 drivers/thermal/samsung/exynos_tmu.c Naveen Krishna Chatradhi 2013-12-19 1100 err_clk_sec:
14a11dc7e0dbf4 drivers/thermal/samsung/exynos_tmu.c Naveen Krishna Chatradhi 2013-12-19 1101 if (!IS_ERR(data->clk_sec))
14a11dc7e0dbf4 drivers/thermal/samsung/exynos_tmu.c Naveen Krishna Chatradhi 2013-12-19 1102 clk_unprepare(data->clk_sec);
9d97e5c81e15af drivers/hwmon/exynos4_tmu.c Donggeun Kim 2011-09-07 @1103 return ret;
9d97e5c81e15af drivers/hwmon/exynos4_tmu.c Donggeun Kim 2011-09-07 1104 }Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH v5 8/9 thermal: exynos: use BIT wherever possible
In reply to Mateusz MajewskiThe original driver did not use that macro and it allows us to make our intentions slightly clearer.
--- drivers/thermal/samsung/exynos_tmu.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/thermal/samsung/exynos_tmu.c +12 -12
@@ -388,7 +388,7 @@ static void exynos4412_tmu_set_trip_temp(struct exynos_tmu_data *data,if (trip ==3 ) { con =readl (data->base +EXYNOS_TMU_REG_CONTROL ); - con |= (1 <<EXYNOS_TMU_THERM_TRIP_EN_SHIFT ); + con |=BIT (EXYNOS_TMU_THERM_TRIP_EN_SHIFT );writel (con, data->base +EXYNOS_TMU_REG_CONTROL ); } }
@@ -559,16 +559,16 @@ static void exynos4210_tmu_control(struct platform_device *pdev, bool on)continue ; interrupt_en |= - (1 << (EXYNOS_TMU_INTEN_RISE0_SHIFT + i *4 )); +BIT (EXYNOS_TMU_INTEN_RISE0_SHIFT + i *4 ); }if (data->soc !=SOC_ARCH_EXYNOS4210 ) interrupt_en |= interrupt_en <<EXYNOS_TMU_INTEN_FALL0_SHIFT ; - con |= (1 <<EXYNOS_TMU_CORE_EN_SHIFT ); + con |=BIT (EXYNOS_TMU_CORE_EN_SHIFT ); }else { - con &= ~(1 <<EXYNOS_TMU_CORE_EN_SHIFT ); + con &= ~BIT (EXYNOS_TMU_CORE_EN_SHIFT ); }writel (interrupt_en, data->base +EXYNOS_TMU_REG_INTEN );
@@ -590,15 +590,15 @@ static void exynos5433_tmu_control(struct platform_device *pdev, bool on)continue ; interrupt_en |= - (1 << (EXYNOS7_TMU_INTEN_RISE0_SHIFT + i)); +BIT (EXYNOS7_TMU_INTEN_RISE0_SHIFT + i); } interrupt_en |= interrupt_en <<EXYNOS_TMU_INTEN_FALL0_SHIFT ; - con |= (1 <<EXYNOS_TMU_CORE_EN_SHIFT ); + con |=BIT (EXYNOS_TMU_CORE_EN_SHIFT ); }else - con &= ~(1 <<EXYNOS_TMU_CORE_EN_SHIFT ); + con &= ~BIT (EXYNOS_TMU_CORE_EN_SHIFT ); pd_det_en = on ?EXYNOS5433_PD_DET_EN :0 ;
@@ -622,17 +622,17 @@ static void exynos7_tmu_control(struct platform_device *pdev, bool on)continue ; interrupt_en |= - (1 << (EXYNOS7_TMU_INTEN_RISE0_SHIFT + i)); +BIT (EXYNOS7_TMU_INTEN_RISE0_SHIFT + i); } interrupt_en |= interrupt_en <<EXYNOS_TMU_INTEN_FALL0_SHIFT ; - con |= (1 <<EXYNOS_TMU_CORE_EN_SHIFT ); - con |= (1 <<EXYNOS7_PD_DET_EN_SHIFT ); + con |=BIT (EXYNOS_TMU_CORE_EN_SHIFT ); + con |=BIT (EXYNOS7_PD_DET_EN_SHIFT ); }else { - con &= ~(1 <<EXYNOS_TMU_CORE_EN_SHIFT ); - con &= ~(1 <<EXYNOS7_PD_DET_EN_SHIFT ); + con &= ~BIT (EXYNOS_TMU_CORE_EN_SHIFT ); + con &= ~BIT (EXYNOS7_PD_DET_EN_SHIFT ); }writel (interrupt_en, data->base +EXYNOS7_TMU_REG_INTEN );
Signature · 7 lines
2.42.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Lukasz Luba
reviewerRe: [PATCH v5 8/9] thermal: exynos: use BIT wherever possible
Hi Mateusz,
Quoted 8 lines · Mateusz Majewski
The original driver did not use that macro and it allows us to make our intentions slightly clearer.
Signed-off-by Mateusz Majewski <[email protected]>--- drivers/thermal/samsung/exynos_tmu.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
[snip]
Quoted 4 lines
drivers/thermal/samsung/exynos_tmu.c +0
-0@@ -590,15 +590,15 @@ static void exynos5433_tmu_control(struct platform_device *pdev, bool on)continue ; interrupt_en |=
drivers/thermal/samsung/exynos_tmu.c static void exynos5433_tmu_control(struct platform_device *pdev, bool on) · line 600
Quoted 10 lines
drivers/thermal/samsung/exynos_tmu.c +2
-2- (1 << (EXYNOS7_TMU_INTEN_RISE0_SHIFT + i)); +BIT (EXYNOS7_TMU_INTEN_RISE0_SHIFT + i); } interrupt_en |= interrupt_en <<EXYNOS_TMU_INTEN_FALL0_SHIFT ; - con |= (1 <<EXYNOS_TMU_CORE_EN_SHIFT ); + con |=BIT (EXYNOS_TMU_CORE_EN_SHIFT ); }else
Minor issue: the if-else segment here. When the 'if' has the brackets, then the 'else' should have them as well, even if there is only a single line under 'else'. It's not strictly to this patch, but you can address that later somewhere (just saw it here).
Quoted 18 lines
drivers/thermal/samsung/exynos_tmu.c +2
-4- con &= ~(1 <<EXYNOS_TMU_CORE_EN_SHIFT ); + con &= ~BIT (EXYNOS_TMU_CORE_EN_SHIFT ); pd_det_en = on ?EXYNOS5433_PD_DET_EN :0 ;@@ -622,17 +622,17 @@ static void exynos7_tmu_control(struct platform_device *pdev, bool on)continue ; interrupt_en |= - (1 << (EXYNOS7_TMU_INTEN_RISE0_SHIFT + i)); +BIT (EXYNOS7_TMU_INTEN_RISE0_SHIFT + i); } interrupt_en |= interrupt_en <<EXYNOS_TMU_INTEN_FALL0_SHIFT ; - con |= (1 <<EXYNOS_TMU_CORE_EN_SHIFT ); - con |= (1 <<EXYNOS7_PD_DET_EN_SHIFT );
drivers/thermal/samsung/exynos_tmu.c static void exynos7_tmu_control(struct platform_device *pdev, bool on) · line 638
Quoted 10 lines
drivers/thermal/samsung/exynos_tmu.c +4
-2+ con |=BIT (EXYNOS_TMU_CORE_EN_SHIFT ); + con |=BIT (EXYNOS7_PD_DET_EN_SHIFT ); }else { - con &= ~(1 <<EXYNOS_TMU_CORE_EN_SHIFT ); - con &= ~(1 <<EXYNOS7_PD_DET_EN_SHIFT ); + con &= ~BIT (EXYNOS_TMU_CORE_EN_SHIFT ); + con &= ~BIT (EXYNOS7_PD_DET_EN_SHIFT ); }writel (interrupt_en, data->base +EXYNOS7_TMU_REG_INTEN );
The patch LGTM,
Reviewed-by Lukasz Luba <[email protected]>
Regards,
Lukasz
Re: [PATCH v5 8/9] thermal: exynos: use BIT wherever possible
Hi,
Quoted 12 lines
Quoted 12 lines
(quoted diff) +0
-0@@ -590,15 +590,15 @@ static void exynos5433_tmu_control(struct platform_device *pdev, bool on) continue;
interrupt_en |=
- (1 << (EXYNOS7_TMU_INTEN_RISE0_SHIFT+ i)); +BIT(EXYNOS7_TMU_INTEN_RISE0_SHIFT + i); }
interrupt_en |=
interrupt_en <<EXYNOS_TMU_INTEN_FALL0_SHIFT;
- con |= (1 <<EXYNOS_TMU_CORE_EN_SHIFT);
Quoted 8 lines
Quoted 2 lines
+ con |=
BIT(EXYNOS_TMU_CORE_EN_SHIFT); } elseMinor issue: the if-else segment here. When the 'if' has the brackets, then the 'else' should have them as well, even if there is only a single line under 'else'. It's not strictly to this patch, but you can address that later somewhere (just saw it here).
For what it's worth, this issue disappears after the final patch of this series, because the other branch reduces to a single line too (all the interrupt_en operations are done in the tmu_set_*_temp functions).
Thank you :)
Mateusz
Lukasz Luba
reviewerRe: [PATCH v5 8/9] thermal: exynos: use BIT wherever possible
Quoted 23 lines · Mateusz Majewski
Hi,
Quoted 11 lines
Quoted 11 lines
drivers/thermal/samsung/exynos_tmu.c +1
-1@@ -590,15 +590,15 @@ static void exynos5433_tmu_control(struct platform_device *pdev, bool on) continue; interrupt_en |= - (1 << (EXYNOS7_TMU_INTEN_RISE0_SHIFT + i)); + BIT(EXYNOS7_TMU_INTEN_RISE0_SHIFT + i); } interrupt_en |= interrupt_en << EXYNOS_TMU_INTEN_FALL0_SHIFT;Quoted 9 lines
drivers/thermal/samsung/exynos_tmu.c static void exynos5433_tmu_control(struct platform_device *pdev, bool on) · line 600
Quoted 3 lines
drivers/thermal/samsung/exynos_tmu.c +1
-1- con |= (1 << EXYNOS_TMU_CORE_EN_SHIFT); + con |= BIT(EXYNOS_TMU_CORE_EN_SHIFT); } elseMinor issue: the if-else segment here. When the 'if' has the brackets, then the 'else' should have them as well, even if there is only a single line under 'else'. It's not strictly to this patch, but you can address that later somewhere (just saw it here).
Quoted 3 lines
For what it's worth, this issue disappears after the final patch of this series, because the other branch reduces to a single line too (all the
interrupt_enoperations are done in the tmu_set_*_temp functions).
That sounds perfect.
I'm planning to build&run the patch set today evening, so I will finish the review of the patch 9/9.
PATCH v5 9/9 thermal: exynos: use set_trips
In reply to Mateusz MajewskiCurrently, each trip point defined in the device tree corresponds to a single hardware interrupt. This commit instead switches to using two hardware interrupts, whose values are set dynamically using the set_trips callback. Additionally, the critical temperature threshold is handled specifically.
Setting interrupts in this way also fixes a long-standing lockdep warning, which was caused by calling thermal_zone_get_trips with our lock being held. Do note that this requires TMU initialization to be split into two parts, as done by the parent commit: parts of the initialization call into the thermal_zone_device structure and so must be done after its registration, but the initialization is also responsible for setting up calibration, which must be done before thermal_zone_device registration, which will call set_trips for the first time; if the calibration is not done in time, the interrupt values will be silently wrong!
---
v4 -> v5: Simplified Exynos 7 code, used the correct register offsets
for Exynos 7 and refactored some common register-setting code.
v2 -> v3: Fixed formatting of some comments.
v1 -> v2: We take clocks into account; anything that sets temperature
thresholds needs clk.
drivers/thermal/samsung/exynos_tmu.c | 393 ++++++++++++++------------- 1 file changed, 209 insertions(+), 184 deletions(-)
drivers/thermal/samsung/exynos_tmu.c +209 -184
@@ -158,10 +158,12 @@ enum soc_type {* in the positive-TC generator block * 0 < reference_voltage <= 31 * @tzd: pointer to thermal_zone_device structure -* @ntrip: number of supported trip points. * @enabled: current status of TMU device -* @tmu_set_trip_temp: SoC specific method to set trip (rising threshold) -* @tmu_set_trip_hyst: SoC specific to set hysteresis (falling threshold) +* @tmu_set_low_temp: SoC specific method to set trip (falling threshold) +* @tmu_set_high_temp: SoC specific method to set trip (rising threshold) +* @tmu_set_crit_temp: SoC specific method to set critical temperature +* @tmu_disable_low: SoC specific method to disable an interrupt (falling threshold) +* @tmu_disable_high: SoC specific method to disable an interrupt (rising threshold) * @tmu_initialize: SoC specific TMU initialization method * @tmu_control: SoC specific TMU control method * @tmu_read: SoC specific TMU temperature read method
@@ -183,13 +185,13 @@ struct exynos_tmu_data {u8 gain;u8 reference_voltage;struct thermal_zone_device *tzd; -unsigned int ntrip;bool enabled; -void (*tmu_set_trip_temp)(struct exynos_tmu_data *data,int trip, -u8 temp); -void (*tmu_set_trip_hyst)(struct exynos_tmu_data *data,int trip, -u8 temp,u8 hyst); +void (*tmu_set_low_temp)(struct exynos_tmu_data *data,u8 temp); +void (*tmu_set_high_temp)(struct exynos_tmu_data *data,u8 temp); +void (*tmu_set_crit_temp)(struct exynos_tmu_data *data,u8 temp); +void (*tmu_disable_low)(struct exynos_tmu_data *data); +void (*tmu_disable_high)(struct exynos_tmu_data *data);void (*tmu_initialize)(struct platform_device *pdev);void (*tmu_control)(struct platform_device *pdev,bool on);int (*tmu_read)(struct exynos_tmu_data *data);
@@ -279,49 +281,28 @@ static int exynos_thermal_zone_configure(struct platform_device *pdev) {struct exynos_tmu_data *data =platform_get_drvdata (pdev);struct thermal_zone_device *tzd = data->tzd; -int i, num_trips =thermal_zone_get_num_trips (tzd); -int ret =0 , temp; +int ret, temp; ret =thermal_zone_get_crit_temp (tzd, &temp); +if (ret) { +/* FIXME: Remove this special case */ +if (data->soc ==SOC_ARCH_EXYNOS5433 ) +return 0 ; -if (ret && data->soc !=SOC_ARCH_EXYNOS5433 ) {/* FIXME */ dev_err (&pdev->dev,"No CRITICAL trip point defined in device tree!\n" ); - goto out; +return ret; }mutex_lock (&data->lock); - -if (num_trips > data->ntrip) { -dev_info (&pdev->dev, -"More trip points than supported by this TMU.\n" ); -dev_info (&pdev->dev, -"%d trip points should be configured in polling mode.\n" , - num_trips - data->ntrip); - } -clk_enable (data->clk); - num_trips =min_t (int, num_trips, data->ntrip); + data->tmu_set_crit_temp (data, temp /MCELSIUS ); -/* Write temperature code for rising and falling threshold */ -for (i =0 ; i < num_trips; i++) { -struct thermal_trip trip; - - ret =thermal_zone_get_trip (tzd, i, &trip); -if (ret) - goto err; - - data->tmu_set_trip_temp (data, i, trip.temperature /MCELSIUS ); - data->tmu_set_trip_hyst (data, i, trip.temperature /MCELSIUS , - trip.hysteresis /MCELSIUS ); - } - -err:clk_disable (data->clk);mutex_unlock (&data->lock); -out: -return ret; + +return 0 ; }static u32 get_con_reg (struct exynos_tmu_data *data,u32 con)
@@ -354,17 +335,74 @@ static void exynos_tmu_control(struct platform_device *pdev, bool on)mutex_unlock (&data->lock); } -static void exynos4210_tmu_set_trip_temp (struct exynos_tmu_data *data, -int trip_id,u8 temp) +static void exynos_tmu_update_bit (struct exynos_tmu_data *data,int reg_off, +int bit_off,bool enable) { - temp =temp_to_code (data, temp); -writeb (temp, data->base +EXYNOS4210_TMU_REG_TRIG_LEVEL0 + trip_id *4 ); +u32 interrupt_en; + + interrupt_en =readl (data->base + reg_off); +if (enable) + interrupt_en |=BIT (bit_off); +else + interrupt_en &= ~BIT (bit_off); +writel (interrupt_en, data->base + reg_off); } -/* failing thresholds are not supported on Exynos4210 */ -static void exynos4210_tmu_set_trip_hyst (struct exynos_tmu_data *data, -int trip,u8 temp,u8 hyst) +static void exynos_tmu_update_temp (struct exynos_tmu_data *data,int reg_off, +int bit_off,u8 temp) { +u16 tmu_temp_mask; +u32 th; + + tmu_temp_mask = + (data->soc ==SOC_ARCH_EXYNOS7 ) ?EXYNOS7_TMU_TEMP_MASK + :EXYNOS_TMU_TEMP_MASK ; + + th =readl (data->base + reg_off); + th &= ~(tmu_temp_mask << bit_off); + th |=temp_to_code (data, temp) << bit_off; +writel (th, data->base + reg_off); +} + +static void exynos4210_tmu_set_low_temp (struct exynos_tmu_data *data,u8 temp) +{ +/* +* Failing thresholds are not supported on Exynos 4210. +* We use polling instead. +*/ +} + +static void exynos4210_tmu_set_high_temp (struct exynos_tmu_data *data,u8 temp) +{ + temp =temp_to_code (data, temp); +writeb (temp, data->base +EXYNOS4210_TMU_REG_TRIG_LEVEL0 +4 ); +exynos_tmu_update_bit (data,EXYNOS_TMU_REG_INTEN , +EXYNOS_TMU_INTEN_RISE0_SHIFT +4 , true); +} + +static void exynos4210_tmu_disable_low (struct exynos_tmu_data *data) +{ +/* Again, this is handled by polling. */ +} + +static void exynos4210_tmu_disable_high (struct exynos_tmu_data *data) +{ +exynos_tmu_update_bit (data,EXYNOS_TMU_REG_INTEN , +EXYNOS_TMU_INTEN_RISE0_SHIFT +4 , false); +} + +static void exynos4210_tmu_set_crit_temp (struct exynos_tmu_data *data,u8 temp) +{ +/* +* Hardware critical temperature handling is not supported on Exynos 4210. +* We still set the critical temperature threshold, but this is only to +* make sure it is handled as soon as possible. It is just a normal interrupt. +*/ + + temp =temp_to_code (data, temp); +writeb (temp, data->base +EXYNOS4210_TMU_REG_TRIG_LEVEL0 +12 ); +exynos_tmu_update_bit (data,EXYNOS_TMU_REG_INTEN , +EXYNOS_TMU_INTEN_RISE0_SHIFT +12 , true); }static void exynos4210_tmu_initialize (struct platform_device *pdev)
@@ -376,33 +414,31 @@ static void exynos4210_tmu_initialize(struct platform_device *pdev)writeb (0 , data->base +EXYNOS4210_TMU_REG_THRESHOLD_TEMP ); } -static void exynos4412_tmu_set_trip_temp (struct exynos_tmu_data *data, -int trip,u8 temp) +static void exynos4412_tmu_set_low_temp (struct exynos_tmu_data *data,u8 temp) { -u32 th, con; - - th =readl (data->base +EXYNOS_THD_TEMP_RISE ); - th &= ~(0xff <<8 * trip); - th |=temp_to_code (data, temp) <<8 * trip; -writel (th, data->base +EXYNOS_THD_TEMP_RISE ); - -if (trip ==3 ) { - con =readl (data->base +EXYNOS_TMU_REG_CONTROL ); - con |=BIT (EXYNOS_TMU_THERM_TRIP_EN_SHIFT ); -writel (con, data->base +EXYNOS_TMU_REG_CONTROL ); - } +exynos_tmu_update_temp (data,EXYNOS_THD_TEMP_FALL ,0 , temp); +exynos_tmu_update_bit (data,EXYNOS_TMU_REG_INTEN , +EXYNOS_TMU_INTEN_FALL0_SHIFT , true); } -static void exynos4412_tmu_set_trip_hyst (struct exynos_tmu_data *data, -int trip,u8 temp,u8 hyst) +static void exynos4412_tmu_set_high_temp (struct exynos_tmu_data *data,u8 temp) { -u32 th; +exynos_tmu_update_temp (data,EXYNOS_THD_TEMP_RISE ,8 , temp); +exynos_tmu_update_bit (data,EXYNOS_TMU_REG_INTEN , +EXYNOS_TMU_INTEN_RISE0_SHIFT +4 , true); +} - th =readl (data->base +EXYNOS_THD_TEMP_FALL ); - th &= ~(0xff <<8 * trip); -if (hyst) - th |=temp_to_code (data, temp - hyst) <<8 * trip; -writel (th, data->base +EXYNOS_THD_TEMP_FALL ); +static void exynos4412_tmu_disable_low (struct exynos_tmu_data *data) +{ +exynos_tmu_update_bit (data,EXYNOS_TMU_REG_INTEN , +EXYNOS_TMU_INTEN_FALL0_SHIFT , false); +} + +static void exynos4412_tmu_set_crit_temp (struct exynos_tmu_data *data,u8 temp) +{ +exynos_tmu_update_temp (data,EXYNOS_THD_TEMP_RISE ,24 , temp); +exynos_tmu_update_bit (data,EXYNOS_TMU_REG_CONTROL , +EXYNOS_TMU_THERM_TRIP_EN_SHIFT , true); }static void exynos4412_tmu_initialize (struct platform_device *pdev)
@@ -432,44 +468,39 @@ static void exynos4412_tmu_initialize(struct platform_device *pdev)sanitize_temp_error (data, trim_info); } -static void exynos5433_tmu_set_trip_temp (struct exynos_tmu_data *data, -int trip,u8 temp) +static void exynos5433_tmu_set_low_temp (struct exynos_tmu_data *data,u8 temp) { -unsigned int reg_off, j; -u32 th; - -if (trip >3 ) { - reg_off =EXYNOS5433_THD_TEMP_RISE7_4 ; - j = trip -4 ; - }else { - reg_off =EXYNOS5433_THD_TEMP_RISE3_0 ; - j = trip; - } - - th =readl (data->base + reg_off); - th &= ~(0xff << j *8 ); - th |= (temp_to_code (data, temp) << j *8 ); -writel (th, data->base + reg_off); +exynos_tmu_update_temp (data,EXYNOS5433_THD_TEMP_FALL3_0 ,0 , temp); +exynos_tmu_update_bit (data,EXYNOS5433_TMU_REG_INTEN , +EXYNOS_TMU_INTEN_FALL0_SHIFT , true); } -static void exynos5433_tmu_set_trip_hyst (struct exynos_tmu_data *data, -int trip,u8 temp,u8 hyst) +static void exynos5433_tmu_set_high_temp (struct exynos_tmu_data *data,u8 temp) { -unsigned int reg_off, j; -u32 th; +exynos_tmu_update_temp (data,EXYNOS5433_THD_TEMP_RISE3_0 ,8 , temp); +exynos_tmu_update_bit (data,EXYNOS5433_TMU_REG_INTEN , +EXYNOS7_TMU_INTEN_RISE0_SHIFT +1 , true); +} -if (trip >3 ) { - reg_off =EXYNOS5433_THD_TEMP_FALL7_4 ; - j = trip -4 ; - }else { - reg_off =EXYNOS5433_THD_TEMP_FALL3_0 ; - j = trip; - } +static void exynos5433_tmu_disable_low (struct exynos_tmu_data *data) +{ +exynos_tmu_update_bit (data,EXYNOS5433_TMU_REG_INTEN , +EXYNOS_TMU_INTEN_FALL0_SHIFT , false); +} - th =readl (data->base + reg_off); - th &= ~(0xff << j *8 ); - th |= (temp_to_code (data, temp - hyst) << j *8 ); -writel (th, data->base + reg_off); +static void exynos5433_tmu_disable_high (struct exynos_tmu_data *data) +{ +exynos_tmu_update_bit (data,EXYNOS5433_TMU_REG_INTEN , +EXYNOS7_TMU_INTEN_RISE0_SHIFT +1 , false); +} + +static void exynos5433_tmu_set_crit_temp (struct exynos_tmu_data *data,u8 temp) +{ +exynos_tmu_update_temp (data,EXYNOS5433_THD_TEMP_RISE7_4 ,24 , temp); +exynos_tmu_update_bit (data,EXYNOS_TMU_REG_CONTROL , +EXYNOS_TMU_THERM_TRIP_EN_SHIFT , true); +exynos_tmu_update_bit (data,EXYNOS5433_TMU_REG_INTEN , +EXYNOS7_TMU_INTEN_RISE0_SHIFT +7 , true); }static void exynos5433_tmu_initialize (struct platform_device *pdev)
@@ -505,34 +536,41 @@ static void exynos5433_tmu_initialize(struct platform_device *pdev) cal_type ? 2 : 1); } -static void exynos7_tmu_set_trip_temp (struct exynos_tmu_data *data, -int trip,u8 temp) +static void exynos7_tmu_set_low_temp (struct exynos_tmu_data *data,u8 temp) { -unsigned int reg_off, bit_off; -u32 th; - - reg_off = ((7 - trip) /2 ) *4 ; - bit_off = ((8 - trip) %2 ); - - th =readl (data->base +EXYNOS7_THD_TEMP_RISE7_6 + reg_off); - th &= ~(EXYNOS7_TMU_TEMP_MASK << (16 * bit_off)); - th |=temp_to_code (data, temp) << (16 * bit_off); -writel (th, data->base +EXYNOS7_THD_TEMP_RISE7_6 + reg_off); +exynos_tmu_update_temp (data,EXYNOS7_THD_TEMP_FALL7_6 +12 ,0 , temp); +exynos_tmu_update_bit (data,EXYNOS7_TMU_REG_INTEN , +EXYNOS_TMU_INTEN_FALL0_SHIFT +0 , true); } -static void exynos7_tmu_set_trip_hyst (struct exynos_tmu_data *data, -int trip,u8 temp,u8 hyst) +static void exynos7_tmu_set_high_temp (struct exynos_tmu_data *data,u8 temp) { -unsigned int reg_off, bit_off; -u32 th; +exynos_tmu_update_temp (data,EXYNOS7_THD_TEMP_RISE7_6 +12 ,16 , temp); +exynos_tmu_update_bit (data,EXYNOS7_TMU_REG_INTEN , +EXYNOS7_TMU_INTEN_RISE0_SHIFT +1 , true); +} - reg_off = ((7 - trip) /2 ) *4 ; - bit_off = ((8 - trip) %2 ); +static void exynos7_tmu_disable_low (struct exynos_tmu_data *data) +{ +exynos_tmu_update_bit (data,EXYNOS7_TMU_REG_INTEN , +EXYNOS_TMU_INTEN_FALL0_SHIFT +0 , false); +} - th =readl (data->base +EXYNOS7_THD_TEMP_FALL7_6 + reg_off); - th &= ~(EXYNOS7_TMU_TEMP_MASK << (16 * bit_off)); - th |=temp_to_code (data, temp - hyst) << (16 * bit_off); -writel (th, data->base +EXYNOS7_THD_TEMP_FALL7_6 + reg_off); +static void exynos7_tmu_disable_high (struct exynos_tmu_data *data) +{ +exynos_tmu_update_bit (data,EXYNOS7_TMU_REG_INTEN , +EXYNOS7_TMU_INTEN_RISE0_SHIFT +1 , false); +} + +static void exynos7_tmu_set_crit_temp (struct exynos_tmu_data *data,u8 temp) +{ +/* +* Like Exynos 4210, Exynos 7 does not seem to support critical temperature +* handling in hardware. Again, we still set a separate interrupt for it. +*/ +exynos_tmu_update_temp (data,EXYNOS7_THD_TEMP_RISE7_6 +0 ,16 , temp); +exynos_tmu_update_bit (data,EXYNOS7_TMU_REG_INTEN , +EXYNOS7_TMU_INTEN_RISE0_SHIFT +7 , true); }static void exynos7_tmu_initialize (struct platform_device *pdev)
@@ -547,87 +585,44 @@ static void exynos7_tmu_initialize(struct platform_device *pdev)static void exynos4210_tmu_control (struct platform_device *pdev,bool on) {struct exynos_tmu_data *data =platform_get_drvdata (pdev); -struct thermal_zone_device *tz = data->tzd; -struct thermal_trip trip; -unsigned int con, interrupt_en =0 , i; +unsigned int con; con =get_con_reg (data,readl (data->base +EXYNOS_TMU_REG_CONTROL )); -if (on) { -for (i =0 ; i < data->ntrip; i++) { -if (thermal_zone_get_trip (tz, i, &trip)) -continue ; - - interrupt_en |= -BIT (EXYNOS_TMU_INTEN_RISE0_SHIFT + i *4 ); - } - -if (data->soc !=SOC_ARCH_EXYNOS4210 ) - interrupt_en |= - interrupt_en <<EXYNOS_TMU_INTEN_FALL0_SHIFT ; - +if (on) con |=BIT (EXYNOS_TMU_CORE_EN_SHIFT ); - }else { +else con &= ~BIT (EXYNOS_TMU_CORE_EN_SHIFT ); - } -writel (interrupt_en, data->base +EXYNOS_TMU_REG_INTEN );writel (con, data->base +EXYNOS_TMU_REG_CONTROL ); }static void exynos5433_tmu_control (struct platform_device *pdev,bool on) {struct exynos_tmu_data *data =platform_get_drvdata (pdev); -struct thermal_zone_device *tz = data->tzd; -struct thermal_trip trip; -unsigned int con, interrupt_en =0 , pd_det_en, i; +unsigned int con, pd_det_en; con =get_con_reg (data,readl (data->base +EXYNOS_TMU_REG_CONTROL )); -if (on) { -for (i =0 ; i < data->ntrip; i++) { -if (thermal_zone_get_trip (tz, i, &trip)) -continue ; - - interrupt_en |= -BIT (EXYNOS7_TMU_INTEN_RISE0_SHIFT + i); - } - - interrupt_en |= - interrupt_en <<EXYNOS_TMU_INTEN_FALL0_SHIFT ; - +if (on) con |=BIT (EXYNOS_TMU_CORE_EN_SHIFT ); - }else +else con &= ~BIT (EXYNOS_TMU_CORE_EN_SHIFT ); pd_det_en = on ?EXYNOS5433_PD_DET_EN :0 ;writel (pd_det_en, data->base +EXYNOS5433_TMU_PD_DET_EN ); -writel (interrupt_en, data->base +EXYNOS5433_TMU_REG_INTEN );writel (con, data->base +EXYNOS_TMU_REG_CONTROL ); }static void exynos7_tmu_control (struct platform_device *pdev,bool on) {struct exynos_tmu_data *data =platform_get_drvdata (pdev); -struct thermal_zone_device *tz = data->tzd; -struct thermal_trip trip; -unsigned int con, interrupt_en =0 , i; +unsigned int con; con =get_con_reg (data,readl (data->base +EXYNOS_TMU_REG_CONTROL ));if (on) { -for (i =0 ; i < data->ntrip; i++) { -if (thermal_zone_get_trip (tz, i, &trip)) -continue ; - - interrupt_en |= -BIT (EXYNOS7_TMU_INTEN_RISE0_SHIFT + i); - } - - interrupt_en |= - interrupt_en <<EXYNOS_TMU_INTEN_FALL0_SHIFT ; - con |=BIT (EXYNOS_TMU_CORE_EN_SHIFT ); con |=BIT (EXYNOS7_PD_DET_EN_SHIFT ); }else {
@@ -635,7 +630,6 @@ static void exynos7_tmu_control(struct platform_device *pdev, bool on) con &= ~BIT (EXYNOS7_PD_DET_EN_SHIFT ); } -writel (interrupt_en, data->base +EXYNOS7_TMU_REG_INTEN );writel (con, data->base +EXYNOS_TMU_REG_CONTROL ); }
@@ -873,13 +867,15 @@ static int exynos_map_dt_data(struct platform_device *pdev)switch (data->soc) {case SOC_ARCH_EXYNOS4210 : - data->tmu_set_trip_temp = exynos4210_tmu_set_trip_temp; - data->tmu_set_trip_hyst = exynos4210_tmu_set_trip_hyst; + data->tmu_set_low_temp = exynos4210_tmu_set_low_temp; + data->tmu_set_high_temp = exynos4210_tmu_set_high_temp; + data->tmu_disable_low = exynos4210_tmu_disable_low; + data->tmu_disable_high = exynos4210_tmu_disable_high; + data->tmu_set_crit_temp = exynos4210_tmu_set_crit_temp; data->tmu_initialize = exynos4210_tmu_initialize; data->tmu_control = exynos4210_tmu_control; data->tmu_read = exynos4210_tmu_read; data->tmu_clear_irqs = exynos4210_tmu_clear_irqs; - data->ntrip =4 ; data->gain =15 ; data->reference_voltage =7 ; data->efuse_value =55 ;
@@ -892,14 +888,16 @@ static int exynos_map_dt_data(struct platform_device *pdev)case SOC_ARCH_EXYNOS5260 :case SOC_ARCH_EXYNOS5420 :case SOC_ARCH_EXYNOS5420_TRIMINFO : - data->tmu_set_trip_temp = exynos4412_tmu_set_trip_temp; - data->tmu_set_trip_hyst = exynos4412_tmu_set_trip_hyst; + data->tmu_set_low_temp = exynos4412_tmu_set_low_temp; + data->tmu_set_high_temp = exynos4412_tmu_set_high_temp; + data->tmu_disable_low = exynos4412_tmu_disable_low; + data->tmu_disable_high = exynos4210_tmu_disable_high; + data->tmu_set_crit_temp = exynos4412_tmu_set_crit_temp; data->tmu_initialize = exynos4412_tmu_initialize; data->tmu_control = exynos4210_tmu_control; data->tmu_read = exynos4412_tmu_read; data->tmu_set_emulation = exynos4412_tmu_set_emulation; data->tmu_clear_irqs = exynos4210_tmu_clear_irqs; - data->ntrip =4 ; data->gain =8 ; data->reference_voltage =16 ; data->efuse_value =55 ;
@@ -911,14 +909,16 @@ static int exynos_map_dt_data(struct platform_device *pdev) data->max_efuse_value =100 ;break ;case SOC_ARCH_EXYNOS5433 : - data->tmu_set_trip_temp = exynos5433_tmu_set_trip_temp; - data->tmu_set_trip_hyst = exynos5433_tmu_set_trip_hyst; + data->tmu_set_low_temp = exynos5433_tmu_set_low_temp; + data->tmu_set_high_temp = exynos5433_tmu_set_high_temp; + data->tmu_disable_low = exynos5433_tmu_disable_low; + data->tmu_disable_high = exynos5433_tmu_disable_high; + data->tmu_set_crit_temp = exynos5433_tmu_set_crit_temp; data->tmu_initialize = exynos5433_tmu_initialize; data->tmu_control = exynos5433_tmu_control; data->tmu_read = exynos4412_tmu_read; data->tmu_set_emulation = exynos4412_tmu_set_emulation; data->tmu_clear_irqs = exynos4210_tmu_clear_irqs; - data->ntrip =8 ; data->gain =8 ;if (res.start ==EXYNOS5433_G3D_BASE ) data->reference_voltage =23 ;
@@ -929,14 +929,16 @@ static int exynos_map_dt_data(struct platform_device *pdev) data->max_efuse_value =150 ;break ;case SOC_ARCH_EXYNOS7 : - data->tmu_set_trip_temp = exynos7_tmu_set_trip_temp; - data->tmu_set_trip_hyst = exynos7_tmu_set_trip_hyst; + data->tmu_set_low_temp = exynos7_tmu_set_low_temp; + data->tmu_set_high_temp = exynos7_tmu_set_high_temp; + data->tmu_disable_low = exynos7_tmu_disable_low; + data->tmu_disable_high = exynos7_tmu_disable_high; + data->tmu_set_crit_temp = exynos7_tmu_set_crit_temp; data->tmu_initialize = exynos7_tmu_initialize; data->tmu_control = exynos7_tmu_control; data->tmu_read = exynos7_tmu_read; data->tmu_set_emulation = exynos4412_tmu_set_emulation; data->tmu_clear_irqs = exynos4210_tmu_clear_irqs; - data->ntrip =8 ; data->gain =9 ; data->reference_voltage =17 ; data->efuse_value =75 ;
@@ -972,9 +974,32 @@ static int exynos_map_dt_data(struct platform_device *pdev)return 0 ; } +static int exynos_set_trips (struct thermal_zone_device *tz,int low,int high) +{ +struct exynos_tmu_data *data =thermal_zone_device_priv (tz); + +mutex_lock (&data->lock); +clk_enable (data->clk); + +if (low >INT_MIN ) + data->tmu_set_low_temp (data, low /MCELSIUS ); +else + data->tmu_disable_low (data); +if (high <INT_MAX ) + data->tmu_set_high_temp (data, high /MCELSIUS ); +else + data->tmu_disable_high (data); + +clk_disable (data->clk); +mutex_unlock (&data->lock); + +return 0 ; +} +static const struct thermal_zone_device_ops exynos_sensor_ops = { .get_temp = exynos_get_temp, .set_emul_temp = exynos_tmu_set_emulation, + .set_trips = exynos_set_trips, };static int exynos_tmu_probe (struct platform_device *pdev)
Signature · 7 lines
2.42.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v5 9/9] thermal: exynos: use set_trips
Quoted 25 lines · Mateusz Majewski
Currently, each trip point defined in the device tree corresponds to a single hardware interrupt. This commit instead switches to using two hardware interrupts, whose values are set dynamically using the
set_tripscallback. Additionally, the critical temperature threshold is handled specifically.Setting interrupts in this way also fixes a long-standing lockdep warning, which was caused by calling
thermal_zone_get_tripswith our lock being held. Do note that this requires TMU initialization to be split into two parts, as done by the parent commit: parts of the initialization call into thethermal_zone_devicestructure and so must be done after its registration, but the initialization is also responsible for setting up calibration, which must be done beforethermal_zone_deviceregistration, which will callset_tripsfor the first time; if the calibration is not done in time, the interrupt values will be silently wrong!Signed-off-by Mateusz Majewski <[email protected]>---
v4 -> v5: Simplified Exynos 7 code, used the correct register offsets
for Exynos 7 and refactored some common register-setting code.
v2 -> v3: Fixed formatting of some comments.
v1 -> v2: We take clocks into account; anything that sets temperature
thresholds needs clk.
Quoted 2 lines
drivers/thermal/samsung/exynos_tmu.c | 393 ++++++++++++++------------- 1 file changed, 209 insertions(+), 184 deletions(-)
The code LGTM and I like the idea of dynamically configured IRQs for trips.
Regards,
Lukasz