arm: tegra: move common edp cdev init to edp code
Diwakar Tundlam [Fri, 11 Jan 2013 23:27:43 +0000 (15:27 -0800)]
Moved repetitive platform initalization of edp features to common
areas in preparation for handling these cdevs from soc_therm.

Bug 1200075

Change-Id: I8f7fe45d8f0797c72272e5ee1db3707493ec90a5
Signed-off-by: Diwakar Tundlam <dtundlam@nvidia.com>
Reviewed-on: http://git-master/r/190765
(cherry picked from commit f36a20dd1bce7314a97f48213f2180b0a7440a97)
Reviewed-on: http://git-master/r/192538
Reviewed-by: Automatic_Commit_Validation_User

arch/arm/mach-tegra/board-common.c
arch/arm/mach-tegra/board-common.h
arch/arm/mach-tegra/board-dalmore-sensors.c
arch/arm/mach-tegra/board-pismo-sensors.c
arch/arm/mach-tegra/board-pluto-sensors.c
arch/arm/mach-tegra/board-roth-sensors.c
arch/arm/mach-tegra/edp.c
arch/arm/mach-tegra/include/mach/edp.h

index ab962ab..4a17891 100644 (file)
 #include <linux/serial_8250.h>
 
 #include <mach/clk.h>
+#include <mach/edp.h>
 
 #include "board.h"
 #include "board-common.h"
 #include "devices.h"
 #include "clock.h"
+#include "dvfs.h"
 
 extern unsigned long  debug_uart_port_base;
 extern struct clk *debug_uart_clk;
@@ -133,25 +135,23 @@ int uart_console_debug_init(int default_debug_port)
        return debug_port_id;
 }
 
-void nct1008_add_cdev_trips(struct nct1008_platform_data *nct1008_data,
-                           struct tegra_cooling_device *cdev_data)
+static void tegra_add_trip_points(struct nct_trip_temp *trips, int *num_trips,
+                               struct tegra_cooling_device *cdev_data)
 {
-       int i, trip;
+       int i;
        struct nct_trip_temp *trip_state;
 
-       if (!nct1008_data || !cdev_data)
+       if (!trips || !num_trips || !cdev_data)
                return;
 
-       if (nct1008_data->num_trips + cdev_data->trip_temperatures_num >
-           NCT_MAX_TRIPS) {
+       if (*num_trips + cdev_data->trip_temperatures_num > NCT_MAX_TRIPS) {
                WARN(1, "%s: cooling device %s has too many trips\n",
                     __func__, cdev_data->cdev_type);
                return;
        }
 
        for (i = 0; i < cdev_data->trip_temperatures_num; i++) {
-               trip = nct1008_data->num_trips;
-               trip_state = &nct1008_data->trips[trip];
+               trip_state = &trips[*num_trips];
 
                trip_state->cdev_type = cdev_data->cdev_type;
                trip_state->trip_temp = cdev_data->trip_temperatures[i] * 1000;
@@ -159,6 +159,14 @@ void nct1008_add_cdev_trips(struct nct1008_platform_data *nct1008_data,
                trip_state->state = i + 1;
                trip_state->hysteresis = 1000;
 
-               nct1008_data->num_trips++;
+               (*num_trips)++;
        }
 }
+
+void tegra_add_cdev_trips(struct nct_trip_temp *trips, int *num_trips)
+{
+       tegra_add_trip_points(trips, num_trips, tegra_core_edp_get_cdev());
+       tegra_add_trip_points(trips, num_trips, tegra_dvfs_get_cpu_dfll_cdev());
+       tegra_add_trip_points(trips, num_trips, tegra_dvfs_get_cpu_pll_cdev());
+       tegra_add_trip_points(trips, num_trips, tegra_dvfs_get_core_cdev());
+}
index b7a7c9b..760f923 100644 (file)
@@ -27,6 +27,5 @@
 extern struct platform_device *uart_console_debug_device;
 int  uart_console_debug_init(int defaul_debug_port);
 int tegra_vibrator_init(void);
-void nct1008_add_cdev_trips(struct nct1008_platform_data *nct1008_data,
-                           struct tegra_cooling_device *cdev_data);
+void tegra_add_cdev_trips(struct nct_trip_temp *trips, int *num_trips);
 #endif
index cb8a095..2d1fbba 100644 (file)
@@ -36,7 +36,7 @@
 #include <linux/therm_est.h>
 #include <linux/nct1008.h>
 #include <mach/edp.h>
-
+#include <linux/edp.h>
 #include <mach/gpio-tegra.h>
 #include <mach/pinmux-t11.h>
 #include <mach/pinmux.h>
@@ -551,7 +551,7 @@ static void mpuirq_init(void)
 
 static int dalmore_nct1008_init(void)
 {
-       int nct1008_port = -1;
+       int nct1008_port;
        int ret = 0;
 
        if ((board_info.board_id == BOARD_E1612) ||
@@ -573,55 +573,23 @@ static int dalmore_nct1008_init(void)
                        board_info.board_id);
        }
 
-       if (nct1008_port >= 0) {
-               struct nct1008_platform_data *data = &dalmore_nct1008_pdata;
-#ifdef CONFIG_TEGRA_EDP_LIMITS
-               const struct tegra_edp_limits *cpu_edp_limits;
-               int cpu_edp_limits_size;
-               int i;
-               int trip;
-               struct nct_trip_temp *trip_state;
-
-               /* edp capping */
-               tegra_get_cpu_edp_limits(&cpu_edp_limits, &cpu_edp_limits_size);
-
-               if (cpu_edp_limits_size > MAX_THROT_TABLE_SIZE)
-                       BUG();
-
-               for (i = 0; i < cpu_edp_limits_size-1; i++) {
-                       trip = data->num_trips;
-                       trip_state = &data->trips[trip];
+       tegra_platform_edp_init(dalmore_nct1008_pdata.trips,
+                               &dalmore_nct1008_pdata.num_trips);
+       tegra_add_cdev_trips(dalmore_nct1008_pdata.trips,
+                               &dalmore_nct1008_pdata.num_trips);
 
-                       trip_state->cdev_type = "edp";
-                       trip_state->trip_temp =
-                                       cpu_edp_limits[i].temperature * 1000;
-                       trip_state->trip_type = THERMAL_TRIP_ACTIVE;
-                       trip_state->state = i + 1;
-                       trip_state->hysteresis = 1000;
+       dalmore_i2c4_nct1008_board_info[0].irq = gpio_to_irq(nct1008_port);
+       pr_info("%s: dalmore nct1008 irq %d",
+                       __func__, dalmore_i2c4_nct1008_board_info[0].irq);
 
-                       data->num_trips++;
+       ret = gpio_request(nct1008_port, "temp_alert");
+       if (ret < 0)
+               return ret;
 
-                       if (data->num_trips >= NCT_MAX_TRIPS)
-                               BUG();
-               }
-#endif
-               nct1008_add_cdev_trips(data, tegra_core_edp_get_cdev());
-               nct1008_add_cdev_trips(data, tegra_dvfs_get_cpu_dfll_cdev());
-               nct1008_add_cdev_trips(data, tegra_dvfs_get_cpu_pll_cdev());
-               nct1008_add_cdev_trips(data, tegra_dvfs_get_core_cdev());
-
-               dalmore_i2c4_nct1008_board_info[0].irq = gpio_to_irq(nct1008_port);
-               pr_info("%s: dalmore nct1008 irq %d", __func__, dalmore_i2c4_nct1008_board_info[0].irq);
-
-               ret = gpio_request(nct1008_port, "temp_alert");
-               if (ret < 0)
-                       return ret;
-
-               ret = gpio_direction_input(nct1008_port);
-               if (ret < 0) {
-                       pr_info("%s: calling gpio_free(nct1008_port)", __func__);
-                       gpio_free(nct1008_port);
-               }
+       ret = gpio_direction_input(nct1008_port);
+       if (ret < 0) {
+               pr_info("%s: calling gpio_free(nct1008_port)", __func__);
+               gpio_free(nct1008_port);
        }
 
        /* dalmore has thermal sensor on GEN1-I2C i.e. instance 0 */
index 8a27cb0..e05b936 100644 (file)
@@ -549,61 +549,30 @@ static void mpuirq_init(void)
 
 static int pismo_nct1008_init(void)
 {
-       int nct1008_port = -1;
+       int nct1008_port;
        int ret = 0;
 
        nct1008_port = TEGRA_GPIO_PX6;
 
-       if (nct1008_port >= 0) {
-               struct nct1008_platform_data *data = &pismo_nct1008_pdata;
-#ifdef CONFIG_TEGRA_EDP_LIMITS
-               const struct tegra_edp_limits *cpu_edp_limits;
-               int cpu_edp_limits_size;
-               int i;
-               int trip;
-               struct nct_trip_temp *trip_state;
+       tegra_platform_edp_init(pismo_nct1008_pdata.trips,
+                               &pismo_nct1008_pdata.num_trips);
+       tegra_add_cdev_trips(pismo_nct1008_pdata.trips,
+                               &pismo_nct1008_pdata.num_trips);
 
-               /* edp capping */
-               tegra_get_cpu_edp_limits(&cpu_edp_limits, &cpu_edp_limits_size);
+       pismo_i2c4_nct1008_board_info[0].irq =
+                       gpio_to_irq(nct1008_port);
+       pr_info("%s: pismo nct1008 irq %d", __func__,
+                       pismo_i2c4_nct1008_board_info[0].irq);
 
-               if (cpu_edp_limits_size > MAX_THROT_TABLE_SIZE)
-                       BUG();
+       ret = gpio_request(nct1008_port, "temp_alert");
+       if (ret < 0)
+               return ret;
 
-               for (i = 0; i < cpu_edp_limits_size-1; i++) {
-                       trip = data->num_trips;
-                       trip_state = &data->trips[trip];
-
-                       trip_state->cdev_type = "edp";
-                       trip_state->trip_temp =
-                                       cpu_edp_limits[i].temperature * 1000;
-                       trip_state->trip_type = THERMAL_TRIP_ACTIVE;
-                       trip_state->state = i + 1;
-                       trip_state->hysteresis = 1000;
-
-                       data->num_trips++;
-
-                       if (data->num_trips > NCT_MAX_TRIPS)
-                               BUG();
-               }
-#endif
-               nct1008_add_cdev_trips(data, tegra_core_edp_get_cdev());
-               nct1008_add_cdev_trips(data, tegra_dvfs_get_cpu_dfll_cdev());
-
-               pismo_i2c4_nct1008_board_info[0].irq =
-                               gpio_to_irq(nct1008_port);
-               pr_info("%s: pismo nct1008 irq %d", __func__,
-                               pismo_i2c4_nct1008_board_info[0].irq);
-
-               ret = gpio_request(nct1008_port, "temp_alert");
-               if (ret < 0)
-                       return ret;
-
-               ret = gpio_direction_input(nct1008_port);
-               if (ret < 0) {
-                       pr_info("%s: calling gpio_free(nct1008_port)",
-                                       __func__);
-                       gpio_free(nct1008_port);
-               }
+       ret = gpio_direction_input(nct1008_port);
+       if (ret < 0) {
+               pr_info("%s: calling gpio_free(nct1008_port)",
+                               __func__);
+               gpio_free(nct1008_port);
        }
 
        /* pismo has thermal sensor on GEN1-I2C i.e. instance 0 */
index ec56f7e..89de14a 100644 (file)
@@ -753,7 +753,7 @@ static void mpuirq_init(void)
 
 static int pluto_nct1008_init(void)
 {
-       int nct1008_port = -1;
+       int nct1008_port;
        int ret = 0;
 
        if (board_info.board_id == BOARD_E1580 ||
@@ -762,59 +762,27 @@ static int pluto_nct1008_init(void)
        } else {
                nct1008_port = TEGRA_GPIO_PX6;
                pr_err("Warning: nct alert port assumed TEGRA_GPIO_PX6 for unknown pluto board id E%d\n",
-                      board_info.board_id);
+                       board_info.board_id);
        }
 
-       if (nct1008_port >= 0) {
-               struct nct1008_platform_data *data = &pluto_nct1008_pdata;
-#ifdef CONFIG_TEGRA_EDP_LIMITS
-               const struct tegra_edp_limits *cpu_edp_limits;
-               int cpu_edp_limits_size;
-               int i;
-               int trip;
-               struct nct_trip_temp *trip_state;
+       tegra_platform_edp_init(pluto_nct1008_pdata.trips,
+                               &pluto_nct1008_pdata.num_trips);
+       tegra_add_cdev_trips(pluto_nct1008_pdata.trips,
+                               &pluto_nct1008_pdata.num_trips);
 
-               /* edp capping */
-               tegra_get_cpu_edp_limits(&cpu_edp_limits, &cpu_edp_limits_size);
+       pluto_i2c4_nct1008_board_info[0].irq =
+               gpio_to_irq(nct1008_port);
+       pr_info("%s: pluto nct1008 irq %d",
+                       __func__, pluto_i2c4_nct1008_board_info[0].irq);
 
-               if (cpu_edp_limits_size > MAX_THROT_TABLE_SIZE)
-                       BUG();
+       ret = gpio_request(nct1008_port, "temp_alert");
+       if (ret < 0)
+               return ret;
 
-               for (i = 0; i < cpu_edp_limits_size-1; i++) {
-                       trip = data->num_trips;
-                       trip_state = &data->trips[trip];
-
-                       trip_state->cdev_type = "edp";
-                       trip_state->trip_temp =
-                                       cpu_edp_limits[i].temperature * 1000;
-                       trip_state->trip_type = THERMAL_TRIP_ACTIVE;
-                       trip_state->state = i + 1;
-                       trip_state->hysteresis = 1000;
-
-                       data->num_trips++;
-
-                       if (data->num_trips >= NCT_MAX_TRIPS)
-                               BUG();
-               }
-#endif
-               nct1008_add_cdev_trips(data, tegra_core_edp_get_cdev());
-               nct1008_add_cdev_trips(data, tegra_dvfs_get_cpu_dfll_cdev());
-               nct1008_add_cdev_trips(data, tegra_dvfs_get_cpu_pll_cdev());
-               nct1008_add_cdev_trips(data, tegra_dvfs_get_core_cdev());
-
-               pluto_i2c4_nct1008_board_info[0].irq =
-                               gpio_to_irq(nct1008_port);
-               pr_info("%s: pluto nct1008 irq %d", __func__, pluto_i2c4_nct1008_board_info[0].irq);
-
-               ret = gpio_request(nct1008_port, "temp_alert");
-               if (ret < 0)
-                       return ret;
-
-               ret = gpio_direction_input(nct1008_port);
-               if (ret < 0) {
-                       pr_info("%s: calling gpio_free(nct1008_port)", __func__);
-                       gpio_free(nct1008_port);
-               }
+       ret = gpio_direction_input(nct1008_port);
+       if (ret < 0) {
+               pr_info("%s: calling gpio_free(nct1008_port)", __func__);
+               gpio_free(nct1008_port);
        }
 
        /* pluto has thermal sensor on GEN1-I2C i.e. instance 0 */
index 4c19c80..51530d0 100644 (file)
@@ -214,43 +214,11 @@ static int roth_nct1008_init(void)
 {
        int nct1008_port = TEGRA_GPIO_PX6;
        int ret = 0;
-       struct nct1008_platform_data *data = &roth_nct1008_pdata;
 
-#ifdef CONFIG_TEGRA_EDP_LIMITS
-               const struct tegra_edp_limits *cpu_edp_limits;
-               int cpu_edp_limits_size;
-               int i;
-               int trip;
-               struct nct_trip_temp *trip_state;
-
-               /* edp capping */
-               tegra_get_cpu_edp_limits(&cpu_edp_limits, &cpu_edp_limits_size);
-
-               if (cpu_edp_limits_size > MAX_THROT_TABLE_SIZE)
-                       BUG();
-
-               for (i = 0; i < cpu_edp_limits_size-1; i++) {
-                       trip = data->num_trips;
-                       trip_state = &data->trips[trip];
-
-                       trip_state->cdev_type = "edp";
-                       trip_state->trip_temp =
-                                       cpu_edp_limits[i].temperature * 1000;
-                       trip_state->trip_type = THERMAL_TRIP_ACTIVE;
-                       trip_state->state = i + 1;
-                       trip_state->hysteresis = 1000;
-
-                       data->num_trips++;
-
-                       if (data->num_trips >= NCT_MAX_TRIPS)
-                               BUG();
-               }
-#endif
-
-       nct1008_add_cdev_trips(data, tegra_core_edp_get_cdev());
-       nct1008_add_cdev_trips(data, tegra_dvfs_get_cpu_dfll_cdev());
-       nct1008_add_cdev_trips(data, tegra_dvfs_get_cpu_pll_cdev());
-       nct1008_add_cdev_trips(data, tegra_dvfs_get_core_cdev());
+       tegra_platform_edp_init(roth_nct1008_pdata.trips,
+                               &roth_nct1008_pdata.num_trips);
+       tegra_add_cdev_trips(roth_nct1008_pdata.trips,
+                               &roth_nct1008_pdata.num_trips);
 
        roth_i2c4_nct1008_board_info[0].irq = gpio_to_irq(nct1008_port);
        pr_info("%s: roth nct1008 irq %d", __func__, \
index 0e59df6..eac569f 100644 (file)
@@ -771,6 +771,38 @@ void tegra_get_system_edp_limits(const unsigned int **limits)
        *limits = system_edp_limits;
 }
 
+void tegra_platform_edp_init(struct nct_trip_temp *trips, int *num_trips)
+{
+       const struct tegra_edp_limits *cpu_edp_limits;
+       struct nct_trip_temp *trip_state;
+       int i, cpu_edp_limits_size;
+
+       if (!trips || !num_trips)
+               return;
+
+       /* edp capping */
+       tegra_get_cpu_edp_limits(&cpu_edp_limits, &cpu_edp_limits_size);
+
+       if (cpu_edp_limits_size > MAX_THROT_TABLE_SIZE)
+               BUG();
+
+       for (i = 0; i < cpu_edp_limits_size-1; i++) {
+               trip_state = &trips[*num_trips];
+
+               trip_state->cdev_type = "edp";
+               trip_state->trip_temp =
+                       cpu_edp_limits[i].temperature * 1000;
+               trip_state->trip_type = THERMAL_TRIP_ACTIVE;
+               trip_state->state = i + 1;
+               trip_state->hysteresis = 1000;
+
+               (*num_trips)++;
+
+               if (*num_trips >= NCT_MAX_TRIPS)
+                       BUG();
+       }
+}
+
 #ifdef CONFIG_DEBUG_FS
 
 static int edp_limit_debugfs_show(struct seq_file *s, void *data)
index 0e3c218..1dac2ae 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/debugfs.h>
 #include <linux/edp.h>
 #include <linux/thermal.h>
+#include <linux/nct1008.h>
 
 struct tegra_edp_vdd_cpu_entry {
        char speedo_id;
@@ -75,6 +76,8 @@ struct tegra_core_edp_limits {
        unsigned long *cap_rates_scpu_off;
 };
 
+struct nct_trip_temp;
+
 #ifdef CONFIG_TEGRA_EDP_LIMITS
 struct thermal_cooling_device *edp_cooling_device_create(void *v);
 void tegra_init_cpu_edp_limits(unsigned int regulator_mA);
@@ -84,7 +87,7 @@ void tegra_get_cpu_edp_limits(const struct tegra_edp_limits **limits, int *size)
 unsigned int tegra_get_edp_limit(int *get_edp_thermal_index);
 void tegra_get_system_edp_limits(const unsigned int **limits);
 int tegra_system_edp_alarm(bool alarm);
-
+void tegra_platform_edp_init(struct nct_trip_temp *trips, int *num_trips);
 #else
 static inline struct thermal_cooling_device *edp_cooling_device_create(
        int index)
@@ -104,6 +107,9 @@ static inline void tegra_get_system_edp_limits(unsigned int **limits)
 {}
 static inline int tegra_system_edp_alarm(bool alarm)
 { return -1; }
+static inline void tegra_platform_edp_init(struct nct_trip_temp *trips,
+                                          int *num_trips)
+{}
 #endif
 
 #ifdef CONFIG_ARCH_TEGRA_2x_SOC