On Wed, Feb 08, 2023 at 11:13:33AM +0800, zhuyinbo wrote:
[ ... ]
After taking into account all the comments, enabled_irq() won't beThe 'tzd' element is needed, because the thermal_zone_device_update need+struct loongson2_thermal_data {'tzd' won't be needed after taking into account the comments
+ struct thermal_zone_device *tzd;
pass a data->tzd element.
static irqreturn_t loongson2_thermal_irq_thread(int irq, void *dev)
{
struct loongson2_thermal_data *data = dev;
thermal_zone_device_update(data->tzd,
THERMAL_EVENT_UNSPECIFIED);
enable_irq(data->irq);
return IRQ_HANDLED;
}
called, so 'data' won't be needed. 'tzd' will be passed to
devm_request_threaded_irq() instead of 'data'.
As loongson2_thermal_irq_thread() is the only place where 'tzd' is
needed and 'tzd' being local to the call site of
thermal_zone_device_register() and devm_request_threaded_irq(), there
is no need to store the pointer in the 'data' structure.
My previous calculation is to consider that the range of 8bit representation is 0 to 255,
Documentation says -40, 125I will drop it.+ int irq;'irq' won't be needed after taking into account the comments
I will drop it.+ int id;'pdev' is not needed
+ void __iomem *regs;
+ struct platform_device *pdev;
I will drop it.+ u16 ctrl_low_val;Those fields won't be needed after taking into account the comments
+ u16 ctrl_hi_val;
+};
+
+static int loongson2_thermal_set(struct loongson2_thermal_data *data,
+ int low, int high, bool enable)
+{
+ u64 reg_ctrl = 0;
+ int reg_off = data->id * 2;
+
+ if (low > high)
+ return -EINVAL;
+
+ low = max(low, -100);
+ high = min(high, 155);
I have review the 3a5000 datasheet, what you said is right about 3a5000, but in 2k1000 datasheet,
If I refer to the documentation it is a raw value converted fromnode(cpu) temp = Thens0_out -100,+ low += 100;Why are those values added to the low and high ? Did you mean low += 0x100 ?
+ high += 100;
Mind to describe a bit the register layout?
low and high is record node temp, so low and high need add '100' as
Thens0_out.
centigrade. The function has degree.
So it should be:
temp_deci = temp_milli / 10
raw = temp_to_raw(temp_deci);
-> temp_to_raw to be determined from temp = (raw * 731) / 0x4000 - 273
[ ... ]
If I refer to the Loongson-3A5000 manual and assuming it is the rightnode(cpu) temp = Thens0_out -100,+static int loongson2_thermal_get_temp(struct thermal_zone_device *tz, int *temp)Why '-100' ?
+{
+ u32 reg_val;
+ struct loongson2_thermal_data *data = tz->devdata;
+
+ reg_val = readl(data->regs + LOONGSON2_TSENSOR_OUT);
+ *temp = ((reg_val & 0xff) - 100) * 1000;
Is the unit returned 'degrees' ?
Here we need to get a node temp.
one, the documentation says:
Temperature = Thens0_out * 731 / 0x4000 - 273
The unit is centigrade.
[ ... ]
thanks your explicate! but our platform doesn't support it.
After a reset, the thermal controller should be in default state and the interruptsorry, I don't get your meaning. Please describe more details about 'reset+ writeb(0xff, data->regs + LOONGSON2_TSENSOR_STATUS);It would be nicer to use a reset line if it is available
+
+ loongson2_thermal_set(data, 0, 0, false);
line'.
flag cleared.
One example:
[1] https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git/tree/arch/arm64/boot/dts/nvidia/tegra210.dtsi#n1560
[2] https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git/tree/drivers/thermal/tegra/soctherm.c#n2169
Then search in the driver for:
reset_control_assert(reset);
reset_control_deassert(reset);
[ ... ]
Thanks
-- Daniel