805-v6.2-thermal-drivers-mtk-use-function-pointer-for-raw_to_.patch 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. From 69c17529e8418da3eec703dde31e1b01e5b0f7e8 Mon Sep 17 00:00:00 2001
  2. From: Daniel Golle <[email protected]>
  3. Date: Wed, 18 Jan 2023 02:48:41 +0000
  4. Subject: [PATCH 1/2] thermal/drivers/mtk: use function pointer for
  5. raw_to_mcelsius
  6. Instead of having if-else logic selecting either raw_to_mcelsius_v1 or
  7. raw_to_mcelsius_v2 in mtk_thermal_bank_temperature introduce a function
  8. pointer raw_to_mcelsius to struct mtk_thermal which is initialized in the
  9. probe function.
  10. Signed-off-by: Daniel Golle <[email protected]>
  11. ---
  12. drivers/thermal/mtk_thermal.c | 17 ++++++++++-------
  13. 1 file changed, 10 insertions(+), 7 deletions(-)
  14. --- a/drivers/thermal/mtk_thermal.c
  15. +++ b/drivers/thermal/mtk_thermal.c
  16. @@ -292,6 +292,8 @@ struct mtk_thermal {
  17. const struct mtk_thermal_data *conf;
  18. struct mtk_thermal_bank banks[MAX_NUM_ZONES];
  19. +
  20. + int (*raw_to_mcelsius)(struct mtk_thermal *mt, int sensno, s32 raw);
  21. };
  22. /* MT8183 thermal sensor data */
  23. @@ -656,13 +658,9 @@ static int mtk_thermal_bank_temperature(
  24. for (i = 0; i < conf->bank_data[bank->id].num_sensors; i++) {
  25. raw = readl(mt->thermal_base + conf->msr[i]);
  26. - if (mt->conf->version == MTK_THERMAL_V1) {
  27. - temp = raw_to_mcelsius_v1(
  28. - mt, conf->bank_data[bank->id].sensors[i], raw);
  29. - } else {
  30. - temp = raw_to_mcelsius_v2(
  31. - mt, conf->bank_data[bank->id].sensors[i], raw);
  32. - }
  33. + temp = mt->raw_to_mcelsius(
  34. + mt, conf->bank_data[bank->id].sensors[i], raw);
  35. +
  36. /*
  37. * The first read of a sensor often contains very high bogus
  38. @@ -1085,6 +1083,11 @@ static int mtk_thermal_probe(struct plat
  39. mtk_thermal_release_periodic_ts(mt, auxadc_base);
  40. }
  41. + if (mt->conf->version == MTK_THERMAL_V1)
  42. + mt->raw_to_mcelsius = raw_to_mcelsius_v1;
  43. + else
  44. + mt->raw_to_mcelsius = raw_to_mcelsius_v2;
  45. +
  46. for (ctrl_id = 0; ctrl_id < mt->conf->num_controller ; ctrl_id++)
  47. for (i = 0; i < mt->conf->num_banks; i++)
  48. mtk_thermal_init_bank(mt, i, apmixed_phys_base,