linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Lezcano <daniel.lezcano@linaro.org>
To: zhuyinbo <zhuyinbo@loongson.cn>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	Amit Kucheria <amitk@kernel.org>, Zhang Rui <rui.zhang@intel.com>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	linux-pm@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: Jianmin Lv <lvjianmin@loongson.cn>,
	wanghongliang@loongson.cn, Liu Peibao <liupeibao@loongson.cn>,
	loongson-kernel@lists.loongnix.cn,
	zhanghongchen <zhanghongchen@loongson.cn>
Subject: Re: [PATCH v14 1/2] thermal: loongson-2: add thermal management support
Date: Wed, 14 Jun 2023 12:59:07 +0200	[thread overview]
Message-ID: <d652acef-ab25-7d5e-6af0-584dacfbbd8d@linaro.org> (raw)
In-Reply-To: <ac5b3982-a658-e05b-1b5c-3aeeda1585ed@loongson.cn>


Hi Yinbo,


On 14/06/2023 10:03, zhuyinbo wrote:
> 
> Hi Daniel,
> 
> Thank you very much for your feedback and suggestions. Below, I have
> some comments, please review.

[ ... ]

>>> +
>>> +    low += 100;
>>> +    high += 100;

Literals -> macros

>>> +    reg_ctrl = low;
>>> +    reg_ctrl |= enable ? 0x100 : 0;
>>> +    writew(reg_ctrl, data->regs + LOONGSON2_TSENSOR_CTRL_LO + reg_off);
>>> +
>>> +    reg_ctrl = high;
>>> +    reg_ctrl |= enable ? 0x100 : 0;
>>> +    writew(reg_ctrl, data->regs + LOONGSON2_TSENSOR_CTRL_HI + reg_off);
>>
>> Is the 'enable' boolean really useful?
> 
> 
> Yes, this 'enable' was to enable thermal irq.
> 
>>
>> Wouldn't be the sensor trip points disabled by default at reset time?
>>
> 
> 
> Only here will thermal irq be enabled throughout the entire driver, and
> actual testing has shown that interrupts are valid, so this is
> meaningful.

Ok.

>> If it is the case then we can get ride of this variable and make the 
>> routine simpler
>>
>>> +    return 0;
>>> +}
>>> +
>>> +static int loongson2_thermal_get_temp(struct thermal_zone_device 
>>> *tz, int *temp)
>>> +{
>>> +    u32 reg_val;
>>> +    struct loongson2_thermal_data *data = tz->devdata;
>>> +
>>> +    reg_val = readl(data->regs + LOONGSON2_TSENSOR_OUT);
>>
>> Seems like there is no offset for the sensor id here ?
> 
> 
> There is no need for a sensor ID here.
> 
> There are some things that I didn't describe clearly, which made you
> misunderstand. Actually, the temperature sensor of 2K1000 is like this:
> 
> There are 4 sets of temperature interrupt controllers, only one set of
> temperature sampling registers. a sets of temperature interrupt
> controllers was considered a sensor, which sensor include 3 register as
> follows, where "SEL" represents which sensor is referenced, In 2k1000
> datasheet, which "SEL" must be 0.

I'm not sure to understand. Let me rephrase it and know what is wrong.

1. The thermal controller has 4 sensors. The interrupt can be set for 
these 4 sensors.

2. When reading a temperature, we have to select the sensor via the 
'SEL' register.

3. The 2k1000 has one sensor with an id = 0.

4. In the future, more Loongson platform can be submitted with more than 
one sensor

If this is correct, then my comments are about the inconsistency of the 
proposed changes. Guessing in the future Loongson board there will be 
more than one sensor, the existing code mixes support for one and 
multiple sensors as well as assuming id is 0.

So if you add in the of_loongson2_thermal_match table a new platform 
with several sensors, the current code will be broken because:

  - the initialization loop does exit when the first thermal zone 
registration succeed

  - the interrupt handler does not figure out which sensor crossed the 
low/high limit

  - the get_temp is not selecting the right sensor


That is my point:

  - write the code to support one sensor with id=0 only

    *or*

  - write the code to support multiple sensors

If I'm not wrong the code is closer to support multiple sensors ;)

Let me know if these deductions are correct

   -- Daniel

ps : is there an English translation for the 2k1000 datasheet ?





-- 
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog


  reply	other threads:[~2023-06-14 10:59 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-26  6:20 [PATCH v14 1/2] thermal: loongson-2: add thermal management support Yinbo Zhu
2023-04-26  6:20 ` [PATCH v14 2/2] dt-bindings: thermal: add loongson-2 thermal Yinbo Zhu
2023-06-09  9:22 ` [PATCH v14 1/2] thermal: loongson-2: add thermal management support zhuyinbo
2023-06-12 14:22 ` Daniel Lezcano
2023-06-14  8:03   ` zhuyinbo
2023-06-14 10:59     ` Daniel Lezcano [this message]
2023-06-15  2:57       ` zhuyinbo
2023-06-16 14:34         ` [PATCH] thermal/drivers/loongson2: Fix thermal zone private data access Daniel Lezcano
2023-06-16 14:35           ` Daniel Lezcano
2023-06-17  1:52             ` zhuyinbo
2023-06-17  7:12               ` Daniel Lezcano
2023-06-17  7:23                 ` zhuyinbo
2023-06-17  3:25   ` [PATCH v14 1/2] thermal: loongson-2: add thermal management support zhuyinbo
2023-06-17  7:15     ` Daniel Lezcano
2023-06-17  7:25       ` zhuyinbo

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=d652acef-ab25-7d5e-6af0-584dacfbbd8d@linaro.org \
    --to=daniel.lezcano@linaro.org \
    --cc=amitk@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=liupeibao@loongson.cn \
    --cc=loongson-kernel@lists.loongnix.cn \
    --cc=lvjianmin@loongson.cn \
    --cc=rafael@kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=rui.zhang@intel.com \
    --cc=wanghongliang@loongson.cn \
    --cc=zhanghongchen@loongson.cn \
    --cc=zhuyinbo@loongson.cn \
    /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).