[COMMON] thermal: isp_cooling: Add cooling table initialization function
authorSoomin Kim <sm8326.kim@samsung.com>
Sun, 14 Aug 2016 12:33:34 +0000 (21:33 +0900)
committerChungwoo Park <cww.park@samsung.com>
Mon, 21 May 2018 08:13:21 +0000 (17:13 +0900)
Originally, isp_cooling_table_init() is located in exynos thermal driver.
But, it would be better to locate it to isp cooling driver.

Change-Id: I05c77e4d98045e5f2993212ebb2117545647adf5
Signed-off-by: Soomin Kim <sm8326.kim@samsung.com>
drivers/thermal/isp_cooling.c
include/linux/isp_cooling.h

index bcdca29ff0c1762128fec112baf7151650183216..63adafce7acb4750d8e5d39bf27672b53050836b 100644 (file)
 #include <linux/isp_cooling.h>
 
 #include <soc/samsung/tmu.h>
+#if defined(CONFIG_ECT)
+#include <soc/samsung/ect_parser.h>
+#endif
+#include "samsung/exynos_tmu.h"
 
 /**
  * struct isp_cooling_device - data for cooling device with isp
@@ -57,7 +61,7 @@ static BLOCKING_NOTIFIER_HEAD(isp_notifier);
 
 static unsigned int isp_dev_count;
 
-extern struct isp_fps_table isp_fps_table[];
+struct isp_fps_table *isp_fps_table;
 
 /**
  * get_idr - function to get a unique id.
@@ -478,3 +482,88 @@ void isp_cooling_unregister(struct thermal_cooling_device *cdev)
        kfree(isp_dev);
 }
 EXPORT_SYMBOL_GPL(isp_cooling_unregister);
+
+/**
+ * isp_cooling_table_init - function to make ISP fps throttling table.
+ * @pdev : struct platform_device pointer
+ *
+ * Return : a valid struct isp_fps_table pointer on success,
+ * on failture, it returns a corresponding ERR_PTR().
+ */
+int isp_cooling_table_init(struct platform_device *pdev)
+{
+       int ret = 0, i = 0;
+#if defined(CONFIG_ECT)
+       struct exynos_tmu_data *exynos_data;
+       void *thermal_block;
+       struct ect_ap_thermal_function *function;
+       int last_fps = -1, count = 0;
+#else
+       unsigned int table_size;
+       u32 isp_idx_num = 0;
+#endif
+
+#if defined(CONFIG_ECT)
+       exynos_data = platform_get_drvdata(pdev);
+
+       thermal_block = ect_get_block(BLOCK_AP_THERMAL);
+       if (thermal_block == NULL) {
+               dev_err(&pdev->dev, "Failed to get thermal block");
+               return -ENODEV;
+       }
+
+       function = ect_ap_thermal_get_function(thermal_block, exynos_data->tmu_name);
+       if (function == NULL) {
+               dev_err(&pdev->dev, "Failed to get %s information", exynos_data->tmu_name);
+               return -ENODEV;
+       }
+
+       /* Table size can be num_of_range + 1 since last row has the value of TABLE_END */
+       isp_fps_table = kzalloc(sizeof(struct isp_fps_table) * (function->num_of_range + 1), GFP_KERNEL);
+
+       if (thermal_block != NULL && function != NULL) {
+               for (i = 0; i < function->num_of_range + 1; i++) {
+                       if (last_fps == function->range_list[i].max_frequency)
+                               continue;
+
+                       isp_fps_table[count].flags = 0;
+                       isp_fps_table[count].driver_data = count;
+
+                       if (i == function->num_of_range)
+                               isp_fps_table[count].fps = ISP_FPS_TABLE_END;
+                       else
+                               isp_fps_table[count].fps = function->range_list[i].max_frequency;
+
+                       last_fps = isp_fps_table[count].fps;
+
+                       dev_info(&pdev->dev, "[ISP TMU] index : %d, fps : %d \n",
+                               isp_fps_table[count].driver_data, isp_fps_table[count].fps);
+                       count++;
+               }
+       } else
+               return -EINVAL;
+#else
+       /* isp cooling frequency table parse */
+       ret = of_property_read_u32(pdev->dev.of_node, "isp_idx_num", &isp_idx_num);
+       if (ret < 0)
+               dev_err(&pdev->dev, "isp_idx_num happend error value\n");
+
+       if (isp_idx_num) {
+               isp_fps_table = kzalloc(sizeof(struct isp_fps_table)* isp_idx_num, GFP_KERNEL);
+               if (!isp_fps_table) {
+                       dev_err(&pdev->dev, "failed to allocate for isp_table\n");
+                       return -ENODEV;
+               }
+               table_size = sizeof(struct isp_fps_table) / sizeof(unsigned int);
+               ret = of_property_read_u32_array(pdev->dev.of_node, "isp_cooling_table",
+                       (unsigned int *)isp_fps_table, table_size * isp_idx_num);
+
+               for (i = 0; i < isp_idx_num; i++) {
+                       dev_info(&pdev->dev, "[ISP TMU] index : %d, fps : %d \n",
+                               isp_fps_table[i].driver_data, isp_fps_table[i].fps);
+               }
+       }
+#endif
+       return ret;
+}
+EXPORT_SYMBOL_GPL(isp_cooling_table_init);
index b3290b67514588c902f83981a264ef1a57e0c252..ea90308f27b5be3912a874a4486c79ec05ff6109 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/of.h>
 #include <linux/thermal.h>
 #include <linux/cpumask.h>
+#include <linux/platform_device.h>
 
 #define ISP_FPS_INVALID     ~1
 
@@ -105,6 +106,11 @@ void isp_cooling_unregister(struct thermal_cooling_device *cdev);
 
 unsigned long isp_cooling_get_level(unsigned int isp, unsigned int fps);
 unsigned long isp_cooling_get_fps(unsigned int isp, unsigned long level);
+/**
+ * isp_cooling_table_init - function to make ISP fps throttling table.
+ * @pdev : platform_device pointer
+ */
+int isp_cooling_table_init(struct platform_device *pdev);
 #else /* !CONFIG_GPU_THERMAL */
 static inline struct thermal_cooling_device *
 isp_cooling_register(const struct cpumask *clip_gpus)
@@ -132,6 +138,10 @@ unsigned long isp_cooling_get_fps(unsigned int isp, unsigned long level)
 {
        return ISP_FPS_INVALID;
 }
+static inline int isp_cooling_table_init(struct platform_device *dev)
+{
+       return true;
+}
 #endif /* CONFIG_ISP_THERMAL */
 
 #endif /* __ISP_COOLING_H__ */