From: Francesco Lavra <francescolavra.fl@gmail.com>
To: Hongbo Zhang <hongbo.zhang@linaro.org>
Cc: linaro-dev@lists.linaro.org, linux-kernel@vger.kernel.org,
linux-pm@vger.kernel.org, STEricsson_nomadik_linux@list.st.com,
kernel@igloocommunity.org, linaro-kernel@lists.linaro.org,
"hongbo.zhang" <hongbo.zhang@linaro.com>,
patches@linaro.org
Subject: Re: [PATCH 5/5] Thermal: Add ST-Ericsson db8500 thermal dirver.
Date: Mon, 22 Oct 2012 20:51:12 +0200 [thread overview]
Message-ID: <508595A0.4040604@gmail.com> (raw)
In-Reply-To: <CAJLyvQxC8eNRmB40o18JR0k7f38+=fpt4UimSYxDCNzNH03Cfw@mail.gmail.com>
On 10/22/2012 02:02 PM, Hongbo Zhang wrote:
[...]
>>> +static irqreturn_t prcmu_low_irq_handler(int irq, void *irq_data)
>>> +{
>>> + struct db8500_thermal_zone *pzone = irq_data;
>>> + struct db8500_thsens_platform_data *ptrips;
>>> + unsigned long next_low, next_high;
>>> + unsigned int idx;
>>> +
>>> + ptrips = pzone->trip_tab;
>>> + idx = pzone->cur_index;
>>> + if (unlikely(idx == 0))
>>> + /* Meaningless for thermal management, ignoring it */
>>> + return IRQ_HANDLED;
>>> +
>>> + if (idx == 1) {
>>> + next_high = ptrips->trip_points[0].temp;
>>> + next_low = PRCMU_DEFAULT_LOW_TEMP;
>>> + } else {
>>> + next_high = ptrips->trip_points[idx-1].temp;
>>> + next_low = ptrips->trip_points[idx-2].temp;
>>> + }
>>> +
>>> + pzone->cur_index -= 1;
>>> + pzone->cur_temp_pseudo = (next_high + next_low)/2;
>>> +
>>> + prcmu_stop_temp_sense();
>>> + prcmu_config_hotmon((u8)(next_low/1000), (u8)(next_high/1000));
>>> + prcmu_start_temp_sense(PRCMU_DEFAULT_MEASURE_TIME);
>>> +
>>> + pr_debug("PRCMU set max %ld, set min %ld\n", next_high, next_low);
>>> +
>>> + pzone->trend = THERMAL_TREND_DROPPING;
>>> + schedule_work(&pzone->therm_work);
>>> +
>>> + return IRQ_HANDLED;
>>> +}
>>> +
>>> +static irqreturn_t prcmu_high_irq_handler(int irq, void *irq_data)
>>> +{
>>> + struct db8500_thermal_zone *pzone = irq_data;
>>> + struct db8500_thsens_platform_data *ptrips;
>>> + unsigned long next_low, next_high;
>>> + unsigned int idx;
>>> +
>>> + ptrips = pzone->trip_tab;
>>> + idx = pzone->cur_index;
>>> +
>>> + if (idx < ptrips->num_trips - 1) {
>>> + next_high = ptrips->trip_points[idx+1].temp;
>>> + next_low = ptrips->trip_points[idx].temp;
>>> +
>>> + pzone->cur_index += 1;
>>> + pzone->cur_temp_pseudo = (next_high + next_low)/2;
>>> +
>>> + prcmu_stop_temp_sense();
>>> + prcmu_config_hotmon((u8)(next_low/1000), (u8)(next_high/1000));
>>> + prcmu_start_temp_sense(PRCMU_DEFAULT_MEASURE_TIME);
>>> +
>>> + pr_debug("PRCMU set max %ld, min %ld\n", next_high, next_low);
>>> + }
>>> +
>>> + if (idx == ptrips->num_trips - 1)
>>
>> } else if ()
> There is no else condition here, because it it the highest critical
> trip point, system will be shut down in thermal_work.
> But I'd like to add some comments here to state this situation.
I didn't mean adding a new else condition, what I meant is that if the
first condition (idx < ptrips->num_trips - 1) is verified, then there is
no need to check for the second condition (idx == ptrips->num_trips -
1). So I was thinking of changing the code to:
if (idx < ptrips->num_trips - 1)
...
else if (idx == ptrips->num_trips - 1)
...
Sorry if I wasn't clear.
>>
>>> + pzone->cur_temp_pseudo = ptrips->trip_points[idx].temp + 1;
>>> +
>>> + pzone->trend = THERMAL_TREND_RAISING;
>>> + schedule_work(&pzone->therm_work);
>>> +
>>> + return IRQ_HANDLED;
>>> +}
>>> +
>>> +static void db8500_thermal_work(struct work_struct *work)
>>> +{
>>> + enum thermal_device_mode cur_mode;
>>> + struct db8500_thermal_zone *pzone;
>>> +
>>> + pzone = container_of(work, struct db8500_thermal_zone, therm_work);
>>> +
>>> + mutex_lock(&pzone->th_lock);
>>> + cur_mode = pzone->mode;
>>> + mutex_unlock(&pzone->th_lock);
>>> +
>>> + if (cur_mode == THERMAL_DEVICE_DISABLED) {
>>> + pr_warn("Warning: thermal function disabled.\n");
>>> + return;
>>> + }
>>> +
>>> + thermal_zone_device_update(pzone->therm_dev);
>>> + pr_debug("db8500_thermal_work finished.\n");
>>> +}
>>> +
>>> +static int __devinit db8500_thermal_probe(struct platform_device *pdev)
>>> +{
>>> + struct db8500_thermal_zone *pzone = NULL;
>>> + struct db8500_thsens_platform_data *ptrips;
>>> + int low_irq, high_irq, ret = 0;
>>> + unsigned long dft_low, dft_high;
>>> +
>>> + pzone = devm_kzalloc(&pdev->dev,
>>> + sizeof(struct db8500_thermal_zone), GFP_KERNEL);
>>> + if (!pzone)
>>> + return -ENOMEM;
>>> +
>>> + pzone->thsens_pdev = pdev;
>>> +
>>> + low_irq = platform_get_irq_byname(pdev, "IRQ_HOTMON_LOW");
>>> + if (low_irq < 0) {
>>> + pr_err("Get IRQ_HOTMON_LOW failed.\n");
>>> + return low_irq;
>>> + }
>>> +
>>> + ret = devm_request_threaded_irq(&pdev->dev, low_irq, NULL,
>>> + prcmu_low_irq_handler,
>>> + IRQF_NO_SUSPEND | IRQF_ONESHOT, "dbx500_temp_low", pzone);
>>> + if (ret < 0) {
>>> + pr_err("Failed to allocate temp low irq.\n");
>>> + return ret;
>>> + }
>>> +
>>> + high_irq = platform_get_irq_byname(pdev, "IRQ_HOTMON_HIGH");
>>> + if (high_irq < 0) {
>>> + pr_err("Get IRQ_HOTMON_HIGH failed.\n");
>>> + return high_irq;
>>> + }
>>> +
>>> + ret = devm_request_threaded_irq(&pdev->dev, high_irq, NULL,
>>> + prcmu_high_irq_handler,
>>> + IRQF_NO_SUSPEND | IRQF_ONESHOT, "dbx500_temp_high", pzone);
>>> + if (ret < 0) {
>>> + pr_err("Failed to allocate temp high irq.\n");
>>> + return ret;
>>> + }
>>> +
>>> + pzone->low_irq = low_irq;
>>> + pzone->high_irq = high_irq;
>>> +
>>> + pzone->mode = THERMAL_DEVICE_DISABLED;
>>> +
>>> + mutex_init(&pzone->th_lock);
>>> +
>>> + INIT_WORK(&pzone->therm_work, db8500_thermal_work);
>>> +
>>> + ptrips = pdev->dev.platform_data;
>>> + pzone->trip_tab = ptrips;
>>> +
>>> + pzone->therm_dev = thermal_zone_device_register("db8500_thermal_zone",
>>> + ptrips->num_trips, 0, pzone, &thdev_ops, 0, 0);
>>> +
>>> + if (IS_ERR(pzone->therm_dev)) {
>>> + pr_err("Failed to register thermal zone device\n");
>>> + return PTR_ERR(pzone->therm_dev);
>>> + }
>>> +
>>> + dft_low = PRCMU_DEFAULT_LOW_TEMP;
>>> + dft_high = ptrips->trip_points[0].temp;
>>> +
>>> + prcmu_stop_temp_sense();
>>> + prcmu_config_hotmon((u8)(dft_low/1000), (u8)(dft_high/1000));
>>> + prcmu_start_temp_sense(PRCMU_DEFAULT_MEASURE_TIME);
>>> +
>>> + pzone->cur_index = 0;
>>> + pzone->cur_temp_pseudo = (dft_low + dft_high)/2;
>>> + pzone->trend = THERMAL_TREND_STABLE;
>>
>> All the stuff from prcmu_stop_temp_sense() up to this line can race with
>> the irq handlers, I would suggest doing it before requesting the irqs.
>>
>>> + pzone->mode = THERMAL_DEVICE_ENABLED;
>>
>> Shouldn't this be protected by pzone->th_lock? Otherwise it should be
>> set before the thermal zone is registered.
>>
>>> +
>>> + platform_set_drvdata(pdev, pzone);
>>> +
>>> + return 0;
>>> +}
>>> +
>>> +static int __devexit db8500_thermal_remove(struct platform_device *pdev)
>>> +{
>>> + struct db8500_thermal_zone *pzone;
>>> + pzone = platform_get_drvdata(pdev);
>>> +
>>> + cancel_work_sync(&pzone->therm_work);
>>> +
>>> + if (pzone->therm_dev)
>>> + thermal_zone_device_unregister(pzone->therm_dev);
>>> +
>>> + return 0;
>>> +}
>>
>> mutex_destroy() should be called on pzone->th_lock
>>
>>> +
>>> +static int db8500_thermal_suspend(struct platform_device *pdev,
>>> + pm_message_t state)
>>> +{
>>> + struct db8500_thermal_zone *pzone;
>>> + pzone = platform_get_drvdata(pdev);
>>> +
>>> + flush_work_sync(&pzone->therm_work);
>>> + prcmu_stop_temp_sense();
>>> +
>>> + return 0;
>>> +}
>>> +
>>> +static int db8500_thermal_resume(struct platform_device *pdev)
>>> +{
>>> + struct db8500_thermal_zone *pzone;
>>> + struct db8500_thsens_platform_data *ptrips;
>>> + unsigned long dft_low, dft_high;
>>> +
>>> + pzone = platform_get_drvdata(pdev);
>>> + ptrips = pzone->trip_tab;
>>> + dft_low = PRCMU_DEFAULT_LOW_TEMP;
>>> + dft_high = ptrips->trip_points[0].temp;
>>> +
>>> + prcmu_config_hotmon((u8)(dft_low/1000), (u8)(dft_high/1000));
>>> + prcmu_start_temp_sense(PRCMU_DEFAULT_MEASURE_TIME);
>>
>> Shouldn't cur_index and cur_temp_pseudo be updated as well? You may want
>> to define a helper function with all the code shared by irq handlers
>> (both high and low), probe and resume.
> No, they cannot be update because we don't know the actual current
> temp[1] after short or long time suspend, everything goes as
> beginning.
That's what I wanted to say, if everything is reset to a default value,
then cur_index and cur_temp should be reset too, as it's done in the
probe function. Otherwise you may have a current pseudo-temp and a
current index unrelated to how the hotmon is configured.
> If a helper function is introduced, it can be only used in probe and
> resume I think, different and a bit complicated algorithm in irq
> handlers.
I was thinking about a function which takes the new index and the new
low and high parameters, and updates cur_index and cur_pseudo_temp and
does the prcmu stuff. It seems to me this is (or should be) common to
all the 4 functions.
> [1] due to lack of corresponding interface, search "TODO" in this file
> to get more explanation.
--
Francesco
next prev parent reply other threads:[~2012-10-22 18:49 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1350387889-15324-1-git-send-email-hongbo.zhang@linaro.com>
[not found] ` <1350387889-15324-2-git-send-email-hongbo.zhang@linaro.com>
2012-10-21 10:05 ` [PATCH 1/5] Thermal: do bind operation after thermal zone or cooling device register returns Francesco Lavra
2012-10-23 8:23 ` Hongbo Zhang
2012-10-23 22:13 ` Francesco Lavra
2012-10-24 2:37 ` Hongbo Zhang
[not found] ` <1350387889-15324-6-git-send-email-hongbo.zhang@linaro.com>
2012-10-21 15:01 ` [PATCH 5/5] Thermal: Add ST-Ericsson db8500 thermal dirver Francesco Lavra
2012-10-22 12:02 ` Hongbo Zhang
2012-10-22 18:51 ` Francesco Lavra [this message]
2012-10-24 4:40 ` Hongbo Zhang
2012-10-24 11:58 ` [PATCH V2 0/6] Fix thermal bugs and Upstream ST-Ericsson thermal driver hongbo.zhang
2012-10-24 11:58 ` [PATCH V2 1/6] Thermal: add indent for code alignment hongbo.zhang
[not found] ` <1351079900-32236-1-git-send-email-hongbo.zhang-68IGFXMjmZ7QT0dZR+AlfA@public.gmane.org>
2012-10-24 11:58 ` [PATCH V2 2/6] Thermal: make sure cpufreq cooling register after cpufreq driver hongbo.zhang
2012-10-29 11:42 ` Amit Kachhap
2012-10-30 8:59 ` Hongbo Zhang
2012-10-24 11:58 ` [PATCH V2 3/6] Thermal: fix bug of counting cpu frequencies hongbo.zhang
2012-10-24 13:34 ` Viresh Kumar
2012-10-29 11:54 ` Amit Kachhap
2012-10-24 11:58 ` [PATCH V2 5/6] Thermal: Add ST-Ericsson DB8500 thermal dirver hongbo.zhang
2012-10-24 14:38 ` Viresh Kumar
2012-10-25 8:26 ` Hongbo Zhang
2012-10-25 8:41 ` Viresh Kumar
2012-10-25 9:33 ` Hongbo Zhang
2012-10-25 9:42 ` Viresh Kumar
2012-10-25 10:43 ` Hongbo Zhang
[not found] ` <CAJLyvQw7=ucSTXH8YyPrm6LS8uDyxJkWGEVP2jQ3FL=cYN7frg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-25 9:56 ` Hongbo Zhang
2012-10-25 10:04 ` Viresh Kumar
2012-10-25 10:11 ` Viresh Kumar
2012-10-25 10:45 ` Hongbo Zhang
2012-10-25 11:13 ` [PATCH V2 5/6] Thermal: Add ST-Ericsson DB8500 thermal driver hongbo.zhang
2012-10-27 10:53 ` Francesco Lavra
2012-10-24 11:58 ` [PATCH V2 6/6] Thermal: Add ST-Ericsson DB8500 thermal properties and platform data hongbo.zhang
2012-10-24 14:32 ` Joe Perches
2012-10-25 3:45 ` Hongbo Zhang
[not found] ` <1351079900-32236-7-git-send-email-hongbo.zhang-68IGFXMjmZ7QT0dZR+AlfA@public.gmane.org>
2012-10-24 14:47 ` Viresh Kumar
[not found] ` <CAKohpom0EOAuahLQoNr1ODbTT-Trv3eE0-oBEmbbdbiKBJPCng-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-10-25 3:49 ` Hongbo Zhang
2012-10-25 11:15 ` hongbo.zhang
2012-10-25 11:39 ` hongbo.zhang
2012-10-24 11:58 ` [PATCH V2 4/6] Thermal: Remove the cooling_cpufreq_list hongbo.zhang
2012-10-25 19:14 ` Francesco Lavra
2012-10-26 2:59 ` Hongbo Zhang
2012-10-26 7:09 ` hongbo.zhang
2012-10-27 6:39 ` Francesco Lavra
2012-10-30 8:03 ` Amit Kachhap
2012-10-30 8:53 ` Hongbo Zhang
2012-10-30 16:48 ` [PATCH V3 0/5] Fix thermal bugs and Upstream ST-Ericsson thermal driver hongbo.zhang
2012-10-30 16:48 ` [PATCH V3 1/5] Thermal: add indent for code alignment hongbo.zhang
[not found] ` <1351615741-24134-2-git-send-email-hongbo.zhang-68IGFXMjmZ7QT0dZR+AlfA@public.gmane.org>
2012-11-07 6:54 ` Zhang Rui
[not found] ` <1351615741-24134-1-git-send-email-hongbo.zhang-68IGFXMjmZ7QT0dZR+AlfA@public.gmane.org>
2012-10-30 16:48 ` [PATCH V3 2/5] Thermal: fix bug of counting cpu frequencies hongbo.zhang
2012-11-07 6:54 ` Zhang Rui
2012-10-30 16:48 ` [PATCH V3 3/5] Thermal: Remove the cooling_cpufreq_list hongbo.zhang
2012-11-07 6:54 ` Zhang Rui
2012-11-09 11:54 ` Hongbo Zhang
2012-10-30 16:49 ` [PATCH V3 4/5] Thermal: Add ST-Ericsson DB8500 thermal driver hongbo.zhang
2012-10-31 2:33 ` Viresh Kumar
[not found] ` <1351615741-24134-5-git-send-email-hongbo.zhang-68IGFXMjmZ7QT0dZR+AlfA@public.gmane.org>
2012-11-01 1:52 ` Zhang, Rui
2012-11-06 10:17 ` Hongbo Zhang
2012-11-06 10:30 ` Hongbo Zhang
2012-11-01 14:48 ` Francesco Lavra
2012-10-30 16:49 ` [PATCH V3 5/5] Thermal: Add ST-Ericsson DB8500 thermal properties and platform data hongbo.zhang
2012-10-31 2:18 ` viresh kumar
2012-11-06 7:25 ` Hongbo Zhang
2012-10-31 2:08 ` [PATCH V3 0/5] Fix thermal bugs and Upstream ST-Ericsson thermal driver viresh kumar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=508595A0.4040604@gmail.com \
--to=francescolavra.fl@gmail.com \
--cc=STEricsson_nomadik_linux@list.st.com \
--cc=hongbo.zhang@linaro.com \
--cc=hongbo.zhang@linaro.org \
--cc=kernel@igloocommunity.org \
--cc=linaro-dev@lists.linaro.org \
--cc=linaro-kernel@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=patches@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).