From 45c58e93c501425f73f43a2f572a516a226ebccd Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Thu, 20 Mar 2014 11:59:09 +0900 Subject: PM / devfreq: exynos4: Fix bug of resource leak and code clean on probe() This patch fix bug about resource leak when happening probe fail and code clean to add debug message. Signed-off-by: Chanwoo Choi Reviewed-by: Tomasz Figa Signed-off-by: MyungJoo Ham --- drivers/devfreq/exynos/exynos4_bus.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/drivers/devfreq/exynos/exynos4_bus.c b/drivers/devfreq/exynos/exynos4_bus.c index e07b0c6..4c1bbd9 100644 --- a/drivers/devfreq/exynos/exynos4_bus.c +++ b/drivers/devfreq/exynos/exynos4_bus.c @@ -763,19 +763,11 @@ static int exynos4_bus_get_dev_status(struct device *dev, return 0; } -static void exynos4_bus_exit(struct device *dev) -{ - struct busfreq_data *data = dev_get_drvdata(dev); - - devfreq_unregister_opp_notifier(dev, data->devfreq); -} - static struct devfreq_dev_profile exynos4_devfreq_profile = { .initial_freq = 400000, .polling_ms = 50, .target = exynos4_bus_target, .get_dev_status = exynos4_bus_get_dev_status, - .exit = exynos4_bus_exit, }; static int exynos4210_init_tables(struct busfreq_data *data) @@ -1048,8 +1040,11 @@ static int exynos4_busfreq_probe(struct platform_device *pdev) dev_err(dev, "Cannot determine the device id %d\n", data->type); err = -EINVAL; } - if (err) + if (err) { + dev_err(dev, "Cannot initialize busfreq table %d\n", + data->type); return err; + } data->vdd_int = devm_regulator_get(dev, "vdd_int"); if (IS_ERR(data->vdd_int)) { @@ -1086,23 +1081,39 @@ static int exynos4_busfreq_probe(struct platform_device *pdev) if (IS_ERR(data->devfreq)) return PTR_ERR(data->devfreq); - devfreq_register_opp_notifier(dev, data->devfreq); + /* Register opp_notifier for Exynos4 busfreq */ + err = devfreq_register_opp_notifier(dev, data->devfreq); + if (err < 0) { + dev_err(dev, "Failed to register opp notifier\n"); + goto err_notifier_opp; + } + /* Register pm_notifier for Exynos4 busfreq */ err = register_pm_notifier(&data->pm_notifier); if (err) { dev_err(dev, "Failed to setup pm notifier\n"); - devfreq_remove_device(data->devfreq); - return err; + goto err_notifier_pm; } return 0; + +err_notifier_pm: + devfreq_unregister_opp_notifier(dev, data->devfreq); +err_notifier_opp: + devfreq_remove_device(data->devfreq); + + return err; } static int exynos4_busfreq_remove(struct platform_device *pdev) { struct busfreq_data *data = platform_get_drvdata(pdev); + /* Unregister all of notifier chain */ unregister_pm_notifier(&data->pm_notifier); + devfreq_unregister_opp_notifier(data->dev, data->devfreq); + + /* Remove devfreq instance */ devfreq_remove_device(data->devfreq); return 0; -- cgit v1.1 From 60d6977c25817aa983d70a5c9a848b32cefc9316 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Thu, 20 Mar 2014 11:59:10 +0900 Subject: PM / devfreq: exynos4: Use SIMPLE_DEV_PM_OPS macro This patch use SIMPLE_DEV_PM_OPS macro instead of legacy method. Signed-off-by: Chanwoo Choi Reviewed-by: Tomasz Figa Signed-off-by: MyungJoo Ham --- drivers/devfreq/exynos/exynos4_bus.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/devfreq/exynos/exynos4_bus.c b/drivers/devfreq/exynos/exynos4_bus.c index 4c1bbd9..5a48d16 100644 --- a/drivers/devfreq/exynos/exynos4_bus.c +++ b/drivers/devfreq/exynos/exynos4_bus.c @@ -1119,6 +1119,7 @@ static int exynos4_busfreq_remove(struct platform_device *pdev) return 0; } +#ifdef CONFIG_PM_SLEEP static int exynos4_busfreq_resume(struct device *dev) { struct busfreq_data *data = dev_get_drvdata(dev); @@ -1126,10 +1127,9 @@ static int exynos4_busfreq_resume(struct device *dev) busfreq_mon_reset(data); return 0; } +#endif -static const struct dev_pm_ops exynos4_busfreq_pm = { - .resume = exynos4_busfreq_resume, -}; +static SIMPLE_DEV_PM_OPS(exynos4_busfreq_pm_ops, NULL, exynos4_busfreq_resume); static const struct platform_device_id exynos4_busfreq_id[] = { { "exynos4210-busfreq", TYPE_BUSF_EXYNOS4210 }, @@ -1145,7 +1145,7 @@ static struct platform_driver exynos4_busfreq_driver = { .driver = { .name = "exynos4-busfreq", .owner = THIS_MODULE, - .pm = &exynos4_busfreq_pm, + .pm = &exynos4_busfreq_pm_ops, }, }; -- cgit v1.1 From b0d5068a9c6a9cad8bdca13d5c578553fe2b315a Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Thu, 20 Mar 2014 11:59:11 +0900 Subject: PM / devfreq: exynos4: Add CONFIG_PM_OPP dependency to fix probe fail This patch add CONFIG_PM_OPP dependecy to exynos4_bus driver to fix probe fail as following log: [ 3.721389] exynos4-busfreq busfreq.3: Fail to add opp entries. [ 3.721697] exynos4-busfreq: probe of busfreq.3 failed with error -22 If CONFIG_PM_OPP is disabled, dev_pm_opp_find_freq_floor() in xxx_probe() will always return -EINVAL error. Signed-off-by: Chanwoo Choi Reviewed-by: Tomasz Figa Signed-off-by: MyungJoo Ham --- drivers/devfreq/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/devfreq/Kconfig b/drivers/devfreq/Kconfig index 7d2f435..b2de2a1 100644 --- a/drivers/devfreq/Kconfig +++ b/drivers/devfreq/Kconfig @@ -70,6 +70,7 @@ config ARM_EXYNOS4_BUS_DEVFREQ depends on (CPU_EXYNOS4210 || SOC_EXYNOS4212 || SOC_EXYNOS4412) && !ARCH_MULTIPLATFORM select ARCH_HAS_OPP select DEVFREQ_GOV_SIMPLE_ONDEMAND + select PM_OPP help This adds the DEVFREQ driver for Exynos4210 memory bus (vdd_int) and Exynos4212/4412 memory interface and bus (vdd_mif + vdd_int). -- cgit v1.1 From edb06a2d4226c65e1c03c279963ca0ede9ccf990 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Thu, 20 Mar 2014 11:59:12 +0900 Subject: PM / devfreq: exynos5: Use SIMPLE_DEV_PM_OPS macro This patch use SIMPLE_DEV_PM_OPS macro instead of legacy method. Signed-off-by: Chanwoo Choi Reviewed-by: Tomasz Figa Signed-off-by: MyungJoo Ham --- drivers/devfreq/exynos/exynos5_bus.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/devfreq/exynos/exynos5_bus.c b/drivers/devfreq/exynos/exynos5_bus.c index 6eef1f7..af6213f 100644 --- a/drivers/devfreq/exynos/exynos5_bus.c +++ b/drivers/devfreq/exynos/exynos5_bus.c @@ -429,6 +429,7 @@ static int exynos5_busfreq_int_remove(struct platform_device *pdev) return 0; } +#ifdef CONFIG_PM_SLEEP static int exynos5_busfreq_int_resume(struct device *dev) { struct platform_device *pdev = container_of(dev, struct platform_device, @@ -438,10 +439,12 @@ static int exynos5_busfreq_int_resume(struct device *dev) busfreq_mon_reset(data); return 0; } - static const struct dev_pm_ops exynos5_busfreq_int_pm = { .resume = exynos5_busfreq_int_resume, }; +#endif +static SIMPLE_DEV_PM_OPS(exynos5_busfreq_int_pm_ops, NULL, + exynos5_busfreq_int_resume); /* platform device pointer for exynos5 devfreq device. */ static struct platform_device *exynos5_devfreq_pdev; @@ -452,7 +455,7 @@ static struct platform_driver exynos5_busfreq_int_driver = { .driver = { .name = "exynos5-bus-int", .owner = THIS_MODULE, - .pm = &exynos5_busfreq_int_pm, + .pm = &exynos5_busfreq_int_pm_ops, }, }; -- cgit v1.1 From ae29fa1d50bead8f1971f30aa9a73bfbff984824 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Thu, 20 Mar 2014 11:59:13 +0900 Subject: PM / devfreq: exynos5: Add CONFIG_PM_OPP dependency to fix probe fail This patch add CONFIG_PM_OPP dependecy to exynos5_bus driver to fix probe fail. If CONFIG_PM_OPP is disabled, dev_pm_opp_find_freq_floor() will always return ERR_PTR(-EINVAL) error. Signed-off-by: Chanwoo Choi Reviewed-by: Tomasz Figa Signed-off-by: MyungJoo Ham --- drivers/devfreq/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/devfreq/Kconfig b/drivers/devfreq/Kconfig index b2de2a1..c023c57 100644 --- a/drivers/devfreq/Kconfig +++ b/drivers/devfreq/Kconfig @@ -84,6 +84,7 @@ config ARM_EXYNOS5_BUS_DEVFREQ depends on SOC_EXYNOS5250 select ARCH_HAS_OPP select DEVFREQ_GOV_SIMPLE_ONDEMAND + select PM_OPP help This adds the DEVFREQ driver for Exynos5250 bus interface (vdd_int). It reads PPMU counters of memory controllers and adjusts the -- cgit v1.1 From ba778b374d55945a190f01f7a741c9657ae5f519 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 21 Mar 2014 18:31:43 +0100 Subject: PM / devfreq: exynos4: use common PPMU code This patch converts exynos4_bus driver to use common PPMU code (exynos_ppmu.c) instead of individual functions related to PPC because PPMU is integrated module with both PPC and Bus event generator. When using PPMU to get bus performance read/write event exynos4_bus driver deson't need to consider memory type. Signed-off-by: Chanwoo Choi [bzolnier: splitted out changes from the bigger patch] Signed-off-by: Bartlomiej Zolnierkiewicz Signed-off-by: MyungJoo Ham --- drivers/devfreq/exynos/Makefile | 2 +- drivers/devfreq/exynos/exynos4_bus.c | 164 +++++++++++++---------------------- 2 files changed, 62 insertions(+), 104 deletions(-) diff --git a/drivers/devfreq/exynos/Makefile b/drivers/devfreq/exynos/Makefile index bfaaf5b..49bc917 100644 --- a/drivers/devfreq/exynos/Makefile +++ b/drivers/devfreq/exynos/Makefile @@ -1,3 +1,3 @@ # Exynos DEVFREQ Drivers -obj-$(CONFIG_ARM_EXYNOS4_BUS_DEVFREQ) += exynos4_bus.o +obj-$(CONFIG_ARM_EXYNOS4_BUS_DEVFREQ) += exynos_ppmu.o exynos4_bus.o obj-$(CONFIG_ARM_EXYNOS5_BUS_DEVFREQ) += exynos_ppmu.o exynos5_bus.o diff --git a/drivers/devfreq/exynos/exynos4_bus.c b/drivers/devfreq/exynos/exynos4_bus.c index 5a48d16..228c658 100644 --- a/drivers/devfreq/exynos/exynos4_bus.c +++ b/drivers/devfreq/exynos/exynos4_bus.c @@ -25,15 +25,16 @@ #include #include +#include + +#include "exynos_ppmu.h" +#include "exynos4_bus.h" + /* Exynos4 ASV has been in the mailing list, but not upstreamed, yet. */ #ifdef CONFIG_EXYNOS_ASV extern unsigned int exynos_result_of_asv; #endif -#include - -#include "exynos4_bus.h" - #define MAX_SAFEVOLT 1200000 /* 1.2V */ enum exynos4_busf_type { @@ -44,22 +45,6 @@ enum exynos4_busf_type { /* Assume that the bus is saturated if the utilization is 40% */ #define BUS_SATURATION_RATIO 40 -enum ppmu_counter { - PPMU_PMNCNT0 = 0, - PPMU_PMCCNT1, - PPMU_PMNCNT2, - PPMU_PMNCNT3, - PPMU_PMNCNT_MAX, -}; -struct exynos4_ppmu { - void __iomem *hw_base; - unsigned int ccnt; - unsigned int event; - unsigned int count[PPMU_PMNCNT_MAX]; - bool ccnt_overflow; - bool count_overflow[PPMU_PMNCNT_MAX]; -}; - enum busclk_level_idx { LV_0 = 0, LV_1, @@ -68,6 +53,13 @@ enum busclk_level_idx { LV_4, _LV_END }; + +enum exynos_ppmu_idx { + PPMU_DMC0, + PPMU_DMC1, + PPMU_END, +}; + #define EX4210_LV_MAX LV_2 #define EX4x12_LV_MAX LV_4 #define EX4210_LV_NUM (LV_2 + 1) @@ -91,7 +83,7 @@ struct busfreq_data { struct regulator *vdd_int; struct regulator *vdd_mif; /* Exynos4412/4212 only */ struct busfreq_opp_info curr_oppinfo; - struct exynos4_ppmu dmc[2]; + struct exynos_ppmu ppmu[PPMU_END]; struct notifier_block pm_notifier; struct mutex lock; @@ -101,12 +93,6 @@ struct busfreq_data { unsigned int top_divtable[_LV_END]; }; -struct bus_opp_table { - unsigned int idx; - unsigned long clk; - unsigned long volt; -}; - /* 4210 controls clock of mif and voltage of int */ static struct bus_opp_table exynos4210_busclk_table[] = { {LV_0, 400000, 1150000}, @@ -524,27 +510,22 @@ static int exynos4x12_set_busclk(struct busfreq_data *data, return 0; } - static void busfreq_mon_reset(struct busfreq_data *data) { unsigned int i; - for (i = 0; i < 2; i++) { - void __iomem *ppmu_base = data->dmc[i].hw_base; + for (i = 0; i < PPMU_END; i++) { + void __iomem *ppmu_base = data->ppmu[i].hw_base; - /* Reset PPMU */ - __raw_writel(0x8000000f, ppmu_base + 0xf010); - __raw_writel(0x8000000f, ppmu_base + 0xf050); - __raw_writel(0x6, ppmu_base + 0xf000); - __raw_writel(0x0, ppmu_base + 0xf100); + /* Reset the performance and cycle counters */ + exynos_ppmu_reset(ppmu_base); - /* Set PPMU Event */ - data->dmc[i].event = 0x6; - __raw_writel(((data->dmc[i].event << 12) | 0x1), - ppmu_base + 0xfc); + /* Setup count registers to monitor read/write transactions */ + data->ppmu[i].event[PPMU_PMNCNT3] = RDWR_DATA_COUNT; + exynos_ppmu_setevent(ppmu_base, PPMU_PMNCNT3, + data->ppmu[i].event[PPMU_PMNCNT3]); - /* Start PPMU */ - __raw_writel(0x1, ppmu_base + 0xf000); + exynos_ppmu_start(ppmu_base); } } @@ -552,23 +533,20 @@ static void exynos4_read_ppmu(struct busfreq_data *data) { int i, j; - for (i = 0; i < 2; i++) { - void __iomem *ppmu_base = data->dmc[i].hw_base; - u32 overflow; + for (i = 0; i < PPMU_END; i++) { + void __iomem *ppmu_base = data->ppmu[i].hw_base; - /* Stop PPMU */ - __raw_writel(0x0, ppmu_base + 0xf000); + exynos_ppmu_stop(ppmu_base); /* Update local data from PPMU */ - overflow = __raw_readl(ppmu_base + 0xf050); - - data->dmc[i].ccnt = __raw_readl(ppmu_base + 0xf100); - data->dmc[i].ccnt_overflow = overflow & (1 << 31); - - for (j = 0; j < PPMU_PMNCNT_MAX; j++) { - data->dmc[i].count[j] = __raw_readl( - ppmu_base + (0xf110 + (0x10 * j))); - data->dmc[i].count_overflow[j] = overflow & (1 << j); + data->ppmu[i].ccnt = __raw_readl(ppmu_base + PPMU_CCNT); + + for (j = PPMU_PMNCNT0; j < PPMU_PMNCNT_MAX; j++) { + if (data->ppmu[i].event[j] == 0) + data->ppmu[i].count[j] = 0; + else + data->ppmu[i].count[j] = + exynos_ppmu_read(ppmu_base, j); } } @@ -698,66 +676,42 @@ out: return err; } -static int exynos4_get_busier_dmc(struct busfreq_data *data) +static int exynos4_get_busier_ppmu(struct busfreq_data *data) { - u64 p0 = data->dmc[0].count[0]; - u64 p1 = data->dmc[1].count[0]; - - p0 *= data->dmc[1].ccnt; - p1 *= data->dmc[0].ccnt; - - if (data->dmc[1].ccnt == 0) - return 0; + int i, j; + int busy = 0; + unsigned int temp = 0; + + for (i = 0; i < PPMU_END; i++) { + for (j = PPMU_PMNCNT0; j < PPMU_PMNCNT_MAX; j++) { + if (data->ppmu[i].count[j] > temp) { + temp = data->ppmu[i].count[j]; + busy = i; + } + } + } - if (p0 > p1) - return 0; - return 1; + return busy; } static int exynos4_bus_get_dev_status(struct device *dev, struct devfreq_dev_status *stat) { struct busfreq_data *data = dev_get_drvdata(dev); - int busier_dmc; - int cycles_x2 = 2; /* 2 x cycles */ - void __iomem *addr; - u32 timing; - u32 memctrl; + int busier; exynos4_read_ppmu(data); - busier_dmc = exynos4_get_busier_dmc(data); + busier = exynos4_get_busier_ppmu(data); stat->current_frequency = data->curr_oppinfo.rate; - if (busier_dmc) - addr = S5P_VA_DMC1; - else - addr = S5P_VA_DMC0; - - memctrl = __raw_readl(addr + 0x04); /* one of DDR2/3/LPDDR2 */ - timing = __raw_readl(addr + 0x38); /* CL or WL/RL values */ - - switch ((memctrl >> 8) & 0xf) { - case 0x4: /* DDR2 */ - cycles_x2 = ((timing >> 16) & 0xf) * 2; - break; - case 0x5: /* LPDDR2 */ - case 0x6: /* DDR3 */ - cycles_x2 = ((timing >> 8) & 0xf) + ((timing >> 0) & 0xf); - break; - default: - pr_err("%s: Unknown Memory Type(%d).\n", __func__, - (memctrl >> 8) & 0xf); - return -EINVAL; - } - /* Number of cycles spent on memory access */ - stat->busy_time = data->dmc[busier_dmc].count[0] / 2 * (cycles_x2 + 2); + stat->busy_time = data->ppmu[busier].count[PPMU_PMNCNT3]; stat->busy_time *= 100 / BUS_SATURATION_RATIO; - stat->total_time = data->dmc[busier_dmc].ccnt; + stat->total_time = data->ppmu[busier].ccnt; /* If the counters have overflown, retry */ - if (data->dmc[busier_dmc].ccnt_overflow || - data->dmc[busier_dmc].count_overflow[0]) + if (data->ppmu[busier].ccnt_overflow || + data->ppmu[busier].count_overflow[0]) return -EAGAIN; return 0; @@ -1023,8 +977,8 @@ static int exynos4_busfreq_probe(struct platform_device *pdev) } data->type = pdev->id_entry->driver_data; - data->dmc[0].hw_base = S5P_VA_DMC0; - data->dmc[1].hw_base = S5P_VA_DMC1; + data->ppmu[PPMU_DMC0].hw_base = S5P_VA_DMC0; + data->ppmu[PPMU_DMC1].hw_base = S5P_VA_DMC1; data->pm_notifier.notifier_call = exynos4_busfreq_pm_notifier_event; data->dev = dev; mutex_init(&data->lock); @@ -1074,13 +1028,17 @@ static int exynos4_busfreq_probe(struct platform_device *pdev) platform_set_drvdata(pdev, data); - busfreq_mon_reset(data); - data->devfreq = devfreq_add_device(dev, &exynos4_devfreq_profile, "simple_ondemand", NULL); if (IS_ERR(data->devfreq)) return PTR_ERR(data->devfreq); + /* + * Start PPMU (Performance Profiling Monitoring Unit) to check + * utilization of each IP in the Exynos4 SoC. + */ + busfreq_mon_reset(data); + /* Register opp_notifier for Exynos4 busfreq */ err = devfreq_register_opp_notifier(dev, data->devfreq); if (err < 0) { -- cgit v1.1 From f4145270894ba3e4edc120d8940f515a2cd75b4c Mon Sep 17 00:00:00 2001 From: Bartlomiej Zolnierkiewicz Date: Fri, 21 Mar 2014 18:31:44 +0100 Subject: PM / devfreq: exynos4: introduce struct busfreq_ppmu_data This is a preparation for making more PPMU code common for EXYNOS devfreq drivers. There should be no functional changes caused by this patch. Signed-off-by: Bartlomiej Zolnierkiewicz Signed-off-by: MyungJoo Ham --- drivers/devfreq/exynos/exynos4_bus.c | 74 ++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 28 deletions(-) diff --git a/drivers/devfreq/exynos/exynos4_bus.c b/drivers/devfreq/exynos/exynos4_bus.c index 228c658..d99ef9e 100644 --- a/drivers/devfreq/exynos/exynos4_bus.c +++ b/drivers/devfreq/exynos/exynos4_bus.c @@ -75,6 +75,11 @@ struct busfreq_opp_info { unsigned long volt; }; +struct busfreq_ppmu_data { + struct exynos_ppmu *ppmu; + int ppmu_end; +}; + struct busfreq_data { enum exynos4_busf_type type; struct device *dev; @@ -83,7 +88,7 @@ struct busfreq_data { struct regulator *vdd_int; struct regulator *vdd_mif; /* Exynos4412/4212 only */ struct busfreq_opp_info curr_oppinfo; - struct exynos_ppmu ppmu[PPMU_END]; + struct busfreq_ppmu_data ppmu_data; struct notifier_block pm_notifier; struct mutex lock; @@ -510,47 +515,47 @@ static int exynos4x12_set_busclk(struct busfreq_data *data, return 0; } -static void busfreq_mon_reset(struct busfreq_data *data) +static void busfreq_mon_reset(struct busfreq_ppmu_data *ppmu_data) { unsigned int i; - for (i = 0; i < PPMU_END; i++) { - void __iomem *ppmu_base = data->ppmu[i].hw_base; + for (i = 0; i < ppmu_data->ppmu_end; i++) { + void __iomem *ppmu_base = ppmu_data->ppmu[i].hw_base; /* Reset the performance and cycle counters */ exynos_ppmu_reset(ppmu_base); /* Setup count registers to monitor read/write transactions */ - data->ppmu[i].event[PPMU_PMNCNT3] = RDWR_DATA_COUNT; + ppmu_data->ppmu[i].event[PPMU_PMNCNT3] = RDWR_DATA_COUNT; exynos_ppmu_setevent(ppmu_base, PPMU_PMNCNT3, - data->ppmu[i].event[PPMU_PMNCNT3]); + ppmu_data->ppmu[i].event[PPMU_PMNCNT3]); exynos_ppmu_start(ppmu_base); } } -static void exynos4_read_ppmu(struct busfreq_data *data) +static void exynos4_read_ppmu(struct busfreq_ppmu_data *ppmu_data) { int i, j; - for (i = 0; i < PPMU_END; i++) { - void __iomem *ppmu_base = data->ppmu[i].hw_base; + for (i = 0; i < ppmu_data->ppmu_end; i++) { + void __iomem *ppmu_base = ppmu_data->ppmu[i].hw_base; exynos_ppmu_stop(ppmu_base); /* Update local data from PPMU */ - data->ppmu[i].ccnt = __raw_readl(ppmu_base + PPMU_CCNT); + ppmu_data->ppmu[i].ccnt = __raw_readl(ppmu_base + PPMU_CCNT); for (j = PPMU_PMNCNT0; j < PPMU_PMNCNT_MAX; j++) { - if (data->ppmu[i].event[j] == 0) - data->ppmu[i].count[j] = 0; + if (ppmu_data->ppmu[i].event[j] == 0) + ppmu_data->ppmu[i].count[j] = 0; else - data->ppmu[i].count[j] = + ppmu_data->ppmu[i].count[j] = exynos_ppmu_read(ppmu_base, j); } } - busfreq_mon_reset(data); + busfreq_mon_reset(ppmu_data); } static int exynos4x12_get_intspec(unsigned long mifclk) @@ -676,16 +681,16 @@ out: return err; } -static int exynos4_get_busier_ppmu(struct busfreq_data *data) +static int exynos4_get_busier_ppmu(struct busfreq_ppmu_data *ppmu_data) { int i, j; int busy = 0; unsigned int temp = 0; - for (i = 0; i < PPMU_END; i++) { + for (i = 0; i < ppmu_data->ppmu_end; i++) { for (j = PPMU_PMNCNT0; j < PPMU_PMNCNT_MAX; j++) { - if (data->ppmu[i].count[j] > temp) { - temp = data->ppmu[i].count[j]; + if (ppmu_data->ppmu[i].count[j] > temp) { + temp = ppmu_data->ppmu[i].count[j]; busy = i; } } @@ -698,20 +703,21 @@ static int exynos4_bus_get_dev_status(struct device *dev, struct devfreq_dev_status *stat) { struct busfreq_data *data = dev_get_drvdata(dev); + struct busfreq_ppmu_data *ppmu_data = &data->ppmu_data; int busier; - exynos4_read_ppmu(data); - busier = exynos4_get_busier_ppmu(data); + exynos4_read_ppmu(ppmu_data); + busier = exynos4_get_busier_ppmu(ppmu_data); stat->current_frequency = data->curr_oppinfo.rate; /* Number of cycles spent on memory access */ - stat->busy_time = data->ppmu[busier].count[PPMU_PMNCNT3]; + stat->busy_time = ppmu_data->ppmu[busier].count[PPMU_PMNCNT3]; stat->busy_time *= 100 / BUS_SATURATION_RATIO; - stat->total_time = data->ppmu[busier].ccnt; + stat->total_time = ppmu_data->ppmu[busier].ccnt; /* If the counters have overflown, retry */ - if (data->ppmu[busier].ccnt_overflow || - data->ppmu[busier].count_overflow[0]) + if (ppmu_data->ppmu[busier].ccnt_overflow || + ppmu_data->ppmu[busier].count_overflow[0]) return -EAGAIN; return 0; @@ -966,6 +972,7 @@ unlock: static int exynos4_busfreq_probe(struct platform_device *pdev) { struct busfreq_data *data; + struct busfreq_ppmu_data *ppmu_data; struct dev_pm_opp *opp; struct device *dev = &pdev->dev; int err = 0; @@ -976,9 +983,19 @@ static int exynos4_busfreq_probe(struct platform_device *pdev) return -ENOMEM; } + ppmu_data = &data->ppmu_data; + ppmu_data->ppmu_end = PPMU_END; + ppmu_data->ppmu = devm_kzalloc(dev, + sizeof(struct exynos_ppmu) * PPMU_END, + GFP_KERNEL); + if (!ppmu_data->ppmu) { + dev_err(dev, "Failed to allocate memory for exynos_ppmu\n"); + return -ENOMEM; + } + data->type = pdev->id_entry->driver_data; - data->ppmu[PPMU_DMC0].hw_base = S5P_VA_DMC0; - data->ppmu[PPMU_DMC1].hw_base = S5P_VA_DMC1; + ppmu_data->ppmu[PPMU_DMC0].hw_base = S5P_VA_DMC0; + ppmu_data->ppmu[PPMU_DMC1].hw_base = S5P_VA_DMC1; data->pm_notifier.notifier_call = exynos4_busfreq_pm_notifier_event; data->dev = dev; mutex_init(&data->lock); @@ -1037,7 +1054,7 @@ static int exynos4_busfreq_probe(struct platform_device *pdev) * Start PPMU (Performance Profiling Monitoring Unit) to check * utilization of each IP in the Exynos4 SoC. */ - busfreq_mon_reset(data); + busfreq_mon_reset(ppmu_data); /* Register opp_notifier for Exynos4 busfreq */ err = devfreq_register_opp_notifier(dev, data->devfreq); @@ -1081,8 +1098,9 @@ static int exynos4_busfreq_remove(struct platform_device *pdev) static int exynos4_busfreq_resume(struct device *dev) { struct busfreq_data *data = dev_get_drvdata(dev); + struct busfreq_ppmu_data *ppmu_data = &data->ppmu_data; - busfreq_mon_reset(data); + busfreq_mon_reset(ppmu_data); return 0; } #endif -- cgit v1.1 From a94f6b4a6f60b4e80102dc431c11026df1307cbb Mon Sep 17 00:00:00 2001 From: Bartlomiej Zolnierkiewicz Date: Fri, 21 Mar 2014 18:31:45 +0100 Subject: PM / devfreq: exynos5: introduce struct busfreq_ppmu_data This is a preparation for making more PPMU code common for EXYNOS devfreq drivers. There should be no functional changes caused by this patch. Signed-off-by: Bartlomiej Zolnierkiewicz Signed-off-by: MyungJoo Ham --- drivers/devfreq/exynos/exynos5_bus.c | 72 ++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 27 deletions(-) diff --git a/drivers/devfreq/exynos/exynos5_bus.c b/drivers/devfreq/exynos/exynos5_bus.c index af6213f..b8ab32a 100644 --- a/drivers/devfreq/exynos/exynos5_bus.c +++ b/drivers/devfreq/exynos/exynos5_bus.c @@ -46,11 +46,16 @@ enum exynos_ppmu_list { PPMU_END, }; +struct busfreq_ppmu_data { + struct exynos_ppmu *ppmu; + int ppmu_end; +}; + struct busfreq_data_int { struct device *dev; struct devfreq *devfreq; struct regulator *vdd_int; - struct exynos_ppmu ppmu[PPMU_END]; + struct busfreq_ppmu_data ppmu_data; unsigned long curr_freq; bool disabled; @@ -75,47 +80,47 @@ static struct int_bus_opp_table exynos5_int_opp_table[] = { {0, 0, 0}, }; -static void busfreq_mon_reset(struct busfreq_data_int *data) +static void busfreq_mon_reset(struct busfreq_ppmu_data *ppmu_data) { unsigned int i; - for (i = PPMU_RIGHT; i < PPMU_END; i++) { - void __iomem *ppmu_base = data->ppmu[i].hw_base; + for (i = 0; i < ppmu_data->ppmu_end; i++) { + void __iomem *ppmu_base = ppmu_data->ppmu[i].hw_base; /* Reset the performance and cycle counters */ exynos_ppmu_reset(ppmu_base); /* Setup count registers to monitor read/write transactions */ - data->ppmu[i].event[PPMU_PMNCNT3] = RDWR_DATA_COUNT; + ppmu_data->ppmu[i].event[PPMU_PMNCNT3] = RDWR_DATA_COUNT; exynos_ppmu_setevent(ppmu_base, PPMU_PMNCNT3, - data->ppmu[i].event[PPMU_PMNCNT3]); + ppmu_data->ppmu[i].event[PPMU_PMNCNT3]); exynos_ppmu_start(ppmu_base); } } -static void exynos5_read_ppmu(struct busfreq_data_int *data) +static void exynos5_read_ppmu(struct busfreq_ppmu_data *ppmu_data) { int i, j; - for (i = PPMU_RIGHT; i < PPMU_END; i++) { - void __iomem *ppmu_base = data->ppmu[i].hw_base; + for (i = 0; i < ppmu_data->ppmu_end; i++) { + void __iomem *ppmu_base = ppmu_data->ppmu[i].hw_base; exynos_ppmu_stop(ppmu_base); /* Update local data from PPMU */ - data->ppmu[i].ccnt = __raw_readl(ppmu_base + PPMU_CCNT); + ppmu_data->ppmu[i].ccnt = __raw_readl(ppmu_base + PPMU_CCNT); for (j = PPMU_PMNCNT0; j < PPMU_PMNCNT_MAX; j++) { - if (data->ppmu[i].event[j] == 0) - data->ppmu[i].count[j] = 0; + if (ppmu_data->ppmu[i].event[j] == 0) + ppmu_data->ppmu[i].count[j] = 0; else - data->ppmu[i].count[j] = + ppmu_data->ppmu[i].count[j] = exynos_ppmu_read(ppmu_base, j); } } - busfreq_mon_reset(data); + busfreq_mon_reset(ppmu_data); } static int exynos5_int_setvolt(struct busfreq_data_int *data, @@ -185,16 +190,16 @@ out: return err; } -static int exynos5_get_busier_dmc(struct busfreq_data_int *data) +static int exynos5_get_busier_dmc(struct busfreq_ppmu_data *ppmu_data) { int i, j; int busy = 0; unsigned int temp = 0; - for (i = PPMU_RIGHT; i < PPMU_END; i++) { + for (i = 0; i < ppmu_data->ppmu_end; i++) { for (j = PPMU_PMNCNT0; j < PPMU_PMNCNT_MAX; j++) { - if (data->ppmu[i].count[j] > temp) { - temp = data->ppmu[i].count[j]; + if (ppmu_data->ppmu[i].count[j] > temp) { + temp = ppmu_data->ppmu[i].count[j]; busy = i; } } @@ -209,17 +214,18 @@ static int exynos5_int_get_dev_status(struct device *dev, struct platform_device *pdev = container_of(dev, struct platform_device, dev); struct busfreq_data_int *data = platform_get_drvdata(pdev); + struct busfreq_ppmu_data *ppmu_data = &data->ppmu_data; int busier_dmc; - exynos5_read_ppmu(data); - busier_dmc = exynos5_get_busier_dmc(data); + exynos5_read_ppmu(ppmu_data); + busier_dmc = exynos5_get_busier_dmc(ppmu_data); stat->current_frequency = data->curr_freq; /* Number of cycles spent on memory access */ - stat->busy_time = data->ppmu[busier_dmc].count[PPMU_PMNCNT3]; + stat->busy_time = ppmu_data->ppmu[busier_dmc].count[PPMU_PMNCNT3]; stat->busy_time *= 100 / INT_BUS_SATURATION_RATIO; - stat->total_time = data->ppmu[busier_dmc].ccnt; + stat->total_time = ppmu_data->ppmu[busier_dmc].ccnt; return 0; } @@ -315,6 +321,7 @@ unlock: static int exynos5_busfreq_int_probe(struct platform_device *pdev) { struct busfreq_data_int *data; + struct busfreq_ppmu_data *ppmu_data; struct dev_pm_opp *opp; struct device *dev = &pdev->dev; struct device_node *np; @@ -330,16 +337,26 @@ static int exynos5_busfreq_int_probe(struct platform_device *pdev) return -ENOMEM; } + ppmu_data = &data->ppmu_data; + ppmu_data->ppmu_end = PPMU_END; + ppmu_data->ppmu = devm_kzalloc(dev, + sizeof(struct exynos_ppmu) * PPMU_END, + GFP_KERNEL); + if (!ppmu_data->ppmu) { + dev_err(dev, "Failed to allocate memory for exynos_ppmu\n"); + return -ENOMEM; + } + np = of_find_compatible_node(NULL, NULL, "samsung,exynos5250-ppmu"); if (np == NULL) { pr_err("Unable to find PPMU node\n"); return -ENOENT; } - for (i = PPMU_RIGHT; i < PPMU_END; i++) { + for (i = 0; i < ppmu_data->ppmu_end; i++) { /* map PPMU memory region */ - data->ppmu[i].hw_base = of_iomap(np, i); - if (data->ppmu[i].hw_base == NULL) { + ppmu_data->ppmu[i].hw_base = of_iomap(np, i); + if (ppmu_data->ppmu[i].hw_base == NULL) { dev_err(&pdev->dev, "failed to map memory region\n"); return -ENOMEM; } @@ -390,7 +407,7 @@ static int exynos5_busfreq_int_probe(struct platform_device *pdev) platform_set_drvdata(pdev, data); - busfreq_mon_reset(data); + busfreq_mon_reset(ppmu_data); data->devfreq = devfreq_add_device(dev, &exynos5_devfreq_int_profile, "simple_ondemand", NULL); @@ -435,8 +452,9 @@ static int exynos5_busfreq_int_resume(struct device *dev) struct platform_device *pdev = container_of(dev, struct platform_device, dev); struct busfreq_data_int *data = platform_get_drvdata(pdev); + struct busfreq_ppmu_data *ppmu_data = &data->ppmu_data; - busfreq_mon_reset(data); + busfreq_mon_reset(ppmu_data); return 0; } static const struct dev_pm_ops exynos5_busfreq_int_pm = { -- cgit v1.1 From 26d518530b19c62dd8165165958d7429db4cd1fe Mon Sep 17 00:00:00 2001 From: Bartlomiej Zolnierkiewicz Date: Fri, 21 Mar 2014 18:31:46 +0100 Subject: PM / devfreq: exynos: make more PPMU code common Move common PPMU code from exynos[45]_bus.c to exynos_ppmu.c. There should be no functional changes caused by this patch. Signed-off-by: Bartlomiej Zolnierkiewicz Signed-off-by: MyungJoo Ham --- drivers/devfreq/exynos/exynos4_bus.c | 70 ++---------------------------------- drivers/devfreq/exynos/exynos5_bus.c | 70 ++---------------------------------- drivers/devfreq/exynos/exynos_ppmu.c | 60 +++++++++++++++++++++++++++++++ drivers/devfreq/exynos/exynos_ppmu.h | 8 +++++ 4 files changed, 72 insertions(+), 136 deletions(-) diff --git a/drivers/devfreq/exynos/exynos4_bus.c b/drivers/devfreq/exynos/exynos4_bus.c index d99ef9e..d257f1f 100644 --- a/drivers/devfreq/exynos/exynos4_bus.c +++ b/drivers/devfreq/exynos/exynos4_bus.c @@ -75,11 +75,6 @@ struct busfreq_opp_info { unsigned long volt; }; -struct busfreq_ppmu_data { - struct exynos_ppmu *ppmu; - int ppmu_end; -}; - struct busfreq_data { enum exynos4_busf_type type; struct device *dev; @@ -515,49 +510,6 @@ static int exynos4x12_set_busclk(struct busfreq_data *data, return 0; } -static void busfreq_mon_reset(struct busfreq_ppmu_data *ppmu_data) -{ - unsigned int i; - - for (i = 0; i < ppmu_data->ppmu_end; i++) { - void __iomem *ppmu_base = ppmu_data->ppmu[i].hw_base; - - /* Reset the performance and cycle counters */ - exynos_ppmu_reset(ppmu_base); - - /* Setup count registers to monitor read/write transactions */ - ppmu_data->ppmu[i].event[PPMU_PMNCNT3] = RDWR_DATA_COUNT; - exynos_ppmu_setevent(ppmu_base, PPMU_PMNCNT3, - ppmu_data->ppmu[i].event[PPMU_PMNCNT3]); - - exynos_ppmu_start(ppmu_base); - } -} - -static void exynos4_read_ppmu(struct busfreq_ppmu_data *ppmu_data) -{ - int i, j; - - for (i = 0; i < ppmu_data->ppmu_end; i++) { - void __iomem *ppmu_base = ppmu_data->ppmu[i].hw_base; - - exynos_ppmu_stop(ppmu_base); - - /* Update local data from PPMU */ - ppmu_data->ppmu[i].ccnt = __raw_readl(ppmu_base + PPMU_CCNT); - - for (j = PPMU_PMNCNT0; j < PPMU_PMNCNT_MAX; j++) { - if (ppmu_data->ppmu[i].event[j] == 0) - ppmu_data->ppmu[i].count[j] = 0; - else - ppmu_data->ppmu[i].count[j] = - exynos_ppmu_read(ppmu_base, j); - } - } - - busfreq_mon_reset(ppmu_data); -} - static int exynos4x12_get_intspec(unsigned long mifclk) { int i = 0; @@ -681,24 +633,6 @@ out: return err; } -static int exynos4_get_busier_ppmu(struct busfreq_ppmu_data *ppmu_data) -{ - int i, j; - int busy = 0; - unsigned int temp = 0; - - for (i = 0; i < ppmu_data->ppmu_end; i++) { - for (j = PPMU_PMNCNT0; j < PPMU_PMNCNT_MAX; j++) { - if (ppmu_data->ppmu[i].count[j] > temp) { - temp = ppmu_data->ppmu[i].count[j]; - busy = i; - } - } - } - - return busy; -} - static int exynos4_bus_get_dev_status(struct device *dev, struct devfreq_dev_status *stat) { @@ -706,8 +640,8 @@ static int exynos4_bus_get_dev_status(struct device *dev, struct busfreq_ppmu_data *ppmu_data = &data->ppmu_data; int busier; - exynos4_read_ppmu(ppmu_data); - busier = exynos4_get_busier_ppmu(ppmu_data); + exynos_read_ppmu(ppmu_data); + busier = exynos_get_busier_ppmu(ppmu_data); stat->current_frequency = data->curr_oppinfo.rate; /* Number of cycles spent on memory access */ diff --git a/drivers/devfreq/exynos/exynos5_bus.c b/drivers/devfreq/exynos/exynos5_bus.c index b8ab32a..ab54a69 100644 --- a/drivers/devfreq/exynos/exynos5_bus.c +++ b/drivers/devfreq/exynos/exynos5_bus.c @@ -46,11 +46,6 @@ enum exynos_ppmu_list { PPMU_END, }; -struct busfreq_ppmu_data { - struct exynos_ppmu *ppmu; - int ppmu_end; -}; - struct busfreq_data_int { struct device *dev; struct devfreq *devfreq; @@ -80,49 +75,6 @@ static struct int_bus_opp_table exynos5_int_opp_table[] = { {0, 0, 0}, }; -static void busfreq_mon_reset(struct busfreq_ppmu_data *ppmu_data) -{ - unsigned int i; - - for (i = 0; i < ppmu_data->ppmu_end; i++) { - void __iomem *ppmu_base = ppmu_data->ppmu[i].hw_base; - - /* Reset the performance and cycle counters */ - exynos_ppmu_reset(ppmu_base); - - /* Setup count registers to monitor read/write transactions */ - ppmu_data->ppmu[i].event[PPMU_PMNCNT3] = RDWR_DATA_COUNT; - exynos_ppmu_setevent(ppmu_base, PPMU_PMNCNT3, - ppmu_data->ppmu[i].event[PPMU_PMNCNT3]); - - exynos_ppmu_start(ppmu_base); - } -} - -static void exynos5_read_ppmu(struct busfreq_ppmu_data *ppmu_data) -{ - int i, j; - - for (i = 0; i < ppmu_data->ppmu_end; i++) { - void __iomem *ppmu_base = ppmu_data->ppmu[i].hw_base; - - exynos_ppmu_stop(ppmu_base); - - /* Update local data from PPMU */ - ppmu_data->ppmu[i].ccnt = __raw_readl(ppmu_base + PPMU_CCNT); - - for (j = PPMU_PMNCNT0; j < PPMU_PMNCNT_MAX; j++) { - if (ppmu_data->ppmu[i].event[j] == 0) - ppmu_data->ppmu[i].count[j] = 0; - else - ppmu_data->ppmu[i].count[j] = - exynos_ppmu_read(ppmu_base, j); - } - } - - busfreq_mon_reset(ppmu_data); -} - static int exynos5_int_setvolt(struct busfreq_data_int *data, unsigned long volt) { @@ -190,24 +142,6 @@ out: return err; } -static int exynos5_get_busier_dmc(struct busfreq_ppmu_data *ppmu_data) -{ - int i, j; - int busy = 0; - unsigned int temp = 0; - - for (i = 0; i < ppmu_data->ppmu_end; i++) { - for (j = PPMU_PMNCNT0; j < PPMU_PMNCNT_MAX; j++) { - if (ppmu_data->ppmu[i].count[j] > temp) { - temp = ppmu_data->ppmu[i].count[j]; - busy = i; - } - } - } - - return busy; -} - static int exynos5_int_get_dev_status(struct device *dev, struct devfreq_dev_status *stat) { @@ -217,8 +151,8 @@ static int exynos5_int_get_dev_status(struct device *dev, struct busfreq_ppmu_data *ppmu_data = &data->ppmu_data; int busier_dmc; - exynos5_read_ppmu(ppmu_data); - busier_dmc = exynos5_get_busier_dmc(ppmu_data); + exynos_read_ppmu(ppmu_data); + busier_dmc = exynos_get_busier_ppmu(ppmu_data); stat->current_frequency = data->curr_freq; diff --git a/drivers/devfreq/exynos/exynos_ppmu.c b/drivers/devfreq/exynos/exynos_ppmu.c index 85fc5ac..75fcc51 100644 --- a/drivers/devfreq/exynos/exynos_ppmu.c +++ b/drivers/devfreq/exynos/exynos_ppmu.c @@ -54,3 +54,63 @@ unsigned int exynos_ppmu_read(void __iomem *ppmu_base, unsigned int ch) return total; } + +void busfreq_mon_reset(struct busfreq_ppmu_data *ppmu_data) +{ + unsigned int i; + + for (i = 0; i < ppmu_data->ppmu_end; i++) { + void __iomem *ppmu_base = ppmu_data->ppmu[i].hw_base; + + /* Reset the performance and cycle counters */ + exynos_ppmu_reset(ppmu_base); + + /* Setup count registers to monitor read/write transactions */ + ppmu_data->ppmu[i].event[PPMU_PMNCNT3] = RDWR_DATA_COUNT; + exynos_ppmu_setevent(ppmu_base, PPMU_PMNCNT3, + ppmu_data->ppmu[i].event[PPMU_PMNCNT3]); + + exynos_ppmu_start(ppmu_base); + } +} + +void exynos_read_ppmu(struct busfreq_ppmu_data *ppmu_data) +{ + int i, j; + + for (i = 0; i < ppmu_data->ppmu_end; i++) { + void __iomem *ppmu_base = ppmu_data->ppmu[i].hw_base; + + exynos_ppmu_stop(ppmu_base); + + /* Update local data from PPMU */ + ppmu_data->ppmu[i].ccnt = __raw_readl(ppmu_base + PPMU_CCNT); + + for (j = PPMU_PMNCNT0; j < PPMU_PMNCNT_MAX; j++) { + if (ppmu_data->ppmu[i].event[j] == 0) + ppmu_data->ppmu[i].count[j] = 0; + else + ppmu_data->ppmu[i].count[j] = + exynos_ppmu_read(ppmu_base, j); + } + } + + busfreq_mon_reset(ppmu_data); +} + +int exynos_get_busier_ppmu(struct busfreq_ppmu_data *ppmu_data) +{ + unsigned int count = 0; + int i, j, busy = 0; + + for (i = 0; i < ppmu_data->ppmu_end; i++) { + for (j = PPMU_PMNCNT0; j < PPMU_PMNCNT_MAX; j++) { + if (ppmu_data->ppmu[i].count[j] > count) { + count = ppmu_data->ppmu[i].count[j]; + busy = i; + } + } + } + + return busy; +} diff --git a/drivers/devfreq/exynos/exynos_ppmu.h b/drivers/devfreq/exynos/exynos_ppmu.h index 7dfb221..71f17ba 100644 --- a/drivers/devfreq/exynos/exynos_ppmu.h +++ b/drivers/devfreq/exynos/exynos_ppmu.h @@ -69,10 +69,18 @@ struct exynos_ppmu { bool count_overflow[PPMU_PMNCNT_MAX]; }; +struct busfreq_ppmu_data { + struct exynos_ppmu *ppmu; + int ppmu_end; +}; + void exynos_ppmu_reset(void __iomem *ppmu_base); void exynos_ppmu_setevent(void __iomem *ppmu_base, unsigned int ch, unsigned int evt); void exynos_ppmu_start(void __iomem *ppmu_base); void exynos_ppmu_stop(void __iomem *ppmu_base); unsigned int exynos_ppmu_read(void __iomem *ppmu_base, unsigned int ch); +void busfreq_mon_reset(struct busfreq_ppmu_data *ppmu_data); +void exynos_read_ppmu(struct busfreq_ppmu_data *ppmu_data); +int exynos_get_busier_ppmu(struct busfreq_ppmu_data *ppmu_data); #endif /* __DEVFREQ_EXYNOS_PPMU_H */ -- cgit v1.1 From 585fc83ece43be63d5775e536f855db33dd752cf Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 9 May 2014 16:43:07 +0900 Subject: PM / devfreq: Fix devfreq_remove_device() to improve the sequence of resource free This patch modify devfreq_remove_device() to improve the sequence of resource free. If executing existing devfreq_remove_device(), this function always executes _remove_devfreq() twice. In result, second _remove_devfreq() always return error value. So, This patch resolves complicated function sequence as following: [Flow sequence before modification] devfreq_remove_device() _remove_devfreq(devfreq, false) kfree(devfreq); /* Free devfreq */ if (!skip ...) { /* skip is false */ device_unregister(&devfreq->dev) put_device(&devfreq->dev); ... dev->release() devfreq_dev_release() _remove_devfreq(devfreq, true) <- Recall to free devfreq /* * Always return error without freeing resource because * already _remove_devfreq() frees the memory of devfreq. */ } [Flow sequence after modification] devfreq_remove_device device_unregister(&devfreq->dev) put_device(&devfreq->dev); .. dev->release() devfreq_dev_release() _remove_devfreq() kfree(devfreq); /* Free devfreq */ Signed-off-by: Chanwoo Choi [Merge conflict resolved by MyungJoo] Signed-off-by: MyungJoo Ham --- drivers/devfreq/devfreq.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index 2042ec3..af4af77 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -394,7 +394,7 @@ static int devfreq_notifier_call(struct notifier_block *nb, unsigned long type, * @devfreq: the devfreq struct * @skip: skip calling device_unregister(). */ -static void _remove_devfreq(struct devfreq *devfreq, bool skip) +static void _remove_devfreq(struct devfreq *devfreq) { mutex_lock(&devfreq_list_lock); if (IS_ERR(find_device_devfreq(devfreq->dev.parent))) { @@ -412,11 +412,6 @@ static void _remove_devfreq(struct devfreq *devfreq, bool skip) if (devfreq->profile->exit) devfreq->profile->exit(devfreq->dev.parent); - if (!skip && get_device(&devfreq->dev)) { - device_unregister(&devfreq->dev); - put_device(&devfreq->dev); - } - mutex_destroy(&devfreq->lock); kfree(devfreq); } @@ -426,14 +421,12 @@ static void _remove_devfreq(struct devfreq *devfreq, bool skip) * @dev: the devfreq device * * This calls _remove_devfreq() if _remove_devfreq() is not called. - * Note that devfreq_dev_release() could be called by _remove_devfreq() as - * well as by others unregistering the device. */ static void devfreq_dev_release(struct device *dev) { struct devfreq *devfreq = to_devfreq(dev); - _remove_devfreq(devfreq, true); + _remove_devfreq(devfreq); } /** @@ -544,7 +537,8 @@ int devfreq_remove_device(struct devfreq *devfreq) if (!devfreq) return -EINVAL; - _remove_devfreq(devfreq, false); + device_unregister(&devfreq->dev); + put_device(&devfreq->dev); return 0; } -- cgit v1.1 From 8cd84092d35e52372da2c3c3c2afb1a719917af2 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 9 May 2014 16:43:08 +0900 Subject: PM / devfreq: Add resource-managed function for devfreq device This patch add resource-managed function for devfreq device as following functions. The devm_devfreq_add_device() manages automatically the memory of devfreq device using device resource management. - devm_devfreq_add_device() - devm_devfreq_remove_device() Signed-off-by: Chanwoo Choi Signed-off-by: MyungJoo Ham --- drivers/devfreq/devfreq.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/devfreq.h | 21 +++++++++++++++- 2 files changed, 83 insertions(+), 1 deletion(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index af4af77..8b6295d 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -544,6 +544,69 @@ int devfreq_remove_device(struct devfreq *devfreq) } EXPORT_SYMBOL(devfreq_remove_device); +static int devm_devfreq_dev_match(struct device *dev, void *res, void *data) +{ + struct devfreq **r = res; + + if (WARN_ON(!r || !*r)) + return 0; + + return *r == data; +} + +static void devm_devfreq_dev_release(struct device *dev, void *res) +{ + devfreq_remove_device(*(struct devfreq **)res); +} + +/** + * devm_devfreq_add_device() - Resource-managed devfreq_add_device() + * @dev: the device to add devfreq feature. + * @profile: device-specific profile to run devfreq. + * @governor_name: name of the policy to choose frequency. + * @data: private data for the governor. The devfreq framework does not + * touch this value. + * + * This function manages automatically the memory of devfreq device using device + * resource management and simplify the free operation for memory of devfreq + * device. + */ +struct devfreq *devm_devfreq_add_device(struct device *dev, + struct devfreq_dev_profile *profile, + const char *governor_name, + void *data) +{ + struct devfreq **ptr, *devfreq; + + ptr = devres_alloc(devm_devfreq_dev_release, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return ERR_PTR(-ENOMEM); + + devfreq = devfreq_add_device(dev, profile, governor_name, data); + if (IS_ERR(devfreq)) { + devres_free(ptr); + return ERR_PTR(-ENOMEM); + } + + *ptr = devfreq; + devres_add(dev, ptr); + + return devfreq; +} +EXPORT_SYMBOL(devm_devfreq_add_device); + +/** + * devm_devfreq_remove_device() - Resource-managed devfreq_remove_device() + * @dev: the device to add devfreq feature. + * @devfreq: the devfreq instance to be removed + */ +void devm_devfreq_remove_device(struct device *dev, struct devfreq *devfreq) +{ + WARN_ON(devres_release(dev, devm_devfreq_dev_release, + devm_devfreq_dev_match, devfreq)); +} +EXPORT_SYMBOL(devm_devfreq_remove_device); + /** * devfreq_suspend_device() - Suspend devfreq of a device. * @devfreq: the devfreq instance to be suspended diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h index d48dc00..023d668 100644 --- a/include/linux/devfreq.h +++ b/include/linux/devfreq.h @@ -181,6 +181,12 @@ extern struct devfreq *devfreq_add_device(struct device *dev, const char *governor_name, void *data); extern int devfreq_remove_device(struct devfreq *devfreq); +extern struct devfreq *devm_devfreq_add_device(struct device *dev, + struct devfreq_dev_profile *profile, + const char *governor_name, + void *data); +extern void devm_devfreq_remove_device(struct device *dev, + struct devfreq *devfreq); /* Supposed to be called by PM_SLEEP/PM_RUNTIME callbacks */ extern int devfreq_suspend_device(struct devfreq *devfreq); @@ -220,7 +226,7 @@ static inline struct devfreq *devfreq_add_device(struct device *dev, const char *governor_name, void *data) { - return NULL; + return ERR_PTR(-ENOSYS); } static inline int devfreq_remove_device(struct devfreq *devfreq) @@ -228,6 +234,19 @@ static inline int devfreq_remove_device(struct devfreq *devfreq) return 0; } +static inline struct devfreq *devm_devfreq_add_device(struct device *dev, + struct devfreq_dev_profile *profile, + const char *governor_name, + void *data) +{ + return ERR_PTR(-ENOSYS); +} + +static inline void devm_devfreq_remove_device(struct device *dev, + struct devfreq *devfreq) +{ +} + static inline int devfreq_suspend_device(struct devfreq *devfreq) { return 0; -- cgit v1.1 From d5b040d0cab9cae1dc1ad61a07019062235f4878 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 9 May 2014 16:43:09 +0900 Subject: PM / devfreq: Add devm_devfreq_{register,unregister}_opp_notfier function This patch add resource-managed function for devfreq opp as following functions. The devm_devfreq_register_opp_notifier() manages automatically the registration of devfreq opp using device resource management. - devm_devfreq_register_opp_notifier - devm_devfreq_unregister_opp_notifier() Signed-off-by: Chanwoo Choi Signed-off-by: MyungJoo Ham --- drivers/devfreq/devfreq.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/devfreq.h | 14 ++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index 8b6295d..9f90369 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -1169,6 +1169,54 @@ int devfreq_unregister_opp_notifier(struct device *dev, struct devfreq *devfreq) return ret; } +static void devm_devfreq_opp_release(struct device *dev, void *res) +{ + devfreq_unregister_opp_notifier(dev, *(struct devfreq **)res); +} + +/** + * devm_ devfreq_register_opp_notifier() + * - Resource-managed devfreq_register_opp_notifier() + * @dev: The devfreq user device. (parent of devfreq) + * @devfreq: The devfreq object. + */ +int devm_devfreq_register_opp_notifier(struct device *dev, + struct devfreq *devfreq) +{ + struct devfreq **ptr; + int ret; + + ptr = devres_alloc(devm_devfreq_opp_release, sizeof(*ptr), GFP_KERNEL); + if (!ptr) + return -ENOMEM; + + ret = devfreq_register_opp_notifier(dev, devfreq); + if (ret) { + devres_free(ptr); + return ret; + } + + *ptr = devfreq; + devres_add(dev, ptr); + + return 0; +} +EXPORT_SYMBOL(devm_devfreq_register_opp_notifier); + +/** + * devm_devfreq_unregister_opp_notifier() + * - Resource-managed devfreq_unregister_opp_notifier() + * @dev: The devfreq user device. (parent of devfreq) + * @devfreq: The devfreq object. + */ +void devm_devfreq_unregister_opp_notifier(struct device *dev, + struct devfreq *devfreq) +{ + WARN_ON(devres_release(dev, devm_devfreq_opp_release, + devm_devfreq_dev_match, devfreq)); +} +EXPORT_SYMBOL(devm_devfreq_unregister_opp_notifier); + MODULE_AUTHOR("MyungJoo Ham "); MODULE_DESCRIPTION("devfreq class support"); MODULE_LICENSE("GPL"); diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h index 023d668..f1863dc 100644 --- a/include/linux/devfreq.h +++ b/include/linux/devfreq.h @@ -199,6 +199,10 @@ extern int devfreq_register_opp_notifier(struct device *dev, struct devfreq *devfreq); extern int devfreq_unregister_opp_notifier(struct device *dev, struct devfreq *devfreq); +extern int devm_devfreq_register_opp_notifier(struct device *dev, + struct devfreq *devfreq); +extern void devm_devfreq_unregister_opp_notifier(struct device *dev, + struct devfreq *devfreq); #if IS_ENABLED(CONFIG_DEVFREQ_GOV_SIMPLE_ONDEMAND) /** @@ -275,6 +279,16 @@ static inline int devfreq_unregister_opp_notifier(struct device *dev, return -EINVAL; } +static inline int devm_devfreq_register_opp_notifier(struct device *dev, + struct devfreq *devfreq) +{ + return -EINVAL; +} + +static inline void devm_devfreq_unregister_opp_notifier(struct device *dev, + struct devfreq *devfreq) +{ +} #endif /* CONFIG_PM_DEVFREQ */ #endif /* __LINUX_DEVFREQ_H__ */ -- cgit v1.1 From c1b13d4e54d9777dc68c28503728ea63c6bfff37 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 9 May 2014 16:43:10 +0900 Subject: PM / devfreq: exynos4: Use devm_devfreq_* function using device resource management This patch uses devm_devfreq_add_device()/devm_devfreq_register_opp_notifier() to control automatically the resource of devfreq. Signed-off-by: Chanwoo Choi Cc: Kukjin Kim Cc: Bartlomiej Zolnierkiewicz Cc: Wei Yongjun Cc: linux-arm-kernel@lists.infradead.org Cc: linux-samsung-soc@vger.kernel.org Signed-off-by: MyungJoo Ham --- drivers/devfreq/exynos/exynos4_bus.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/drivers/devfreq/exynos/exynos4_bus.c b/drivers/devfreq/exynos/exynos4_bus.c index d257f1f..bebb0a4 100644 --- a/drivers/devfreq/exynos/exynos4_bus.c +++ b/drivers/devfreq/exynos/exynos4_bus.c @@ -979,7 +979,7 @@ static int exynos4_busfreq_probe(struct platform_device *pdev) platform_set_drvdata(pdev, data); - data->devfreq = devfreq_add_device(dev, &exynos4_devfreq_profile, + data->devfreq = devm_devfreq_add_device(dev, &exynos4_devfreq_profile, "simple_ondemand", NULL); if (IS_ERR(data->devfreq)) return PTR_ERR(data->devfreq); @@ -991,27 +991,20 @@ static int exynos4_busfreq_probe(struct platform_device *pdev) busfreq_mon_reset(ppmu_data); /* Register opp_notifier for Exynos4 busfreq */ - err = devfreq_register_opp_notifier(dev, data->devfreq); + err = devm_devfreq_register_opp_notifier(dev, data->devfreq); if (err < 0) { dev_err(dev, "Failed to register opp notifier\n"); - goto err_notifier_opp; + return err; } /* Register pm_notifier for Exynos4 busfreq */ err = register_pm_notifier(&data->pm_notifier); if (err) { dev_err(dev, "Failed to setup pm notifier\n"); - goto err_notifier_pm; + return err; } return 0; - -err_notifier_pm: - devfreq_unregister_opp_notifier(dev, data->devfreq); -err_notifier_opp: - devfreq_remove_device(data->devfreq); - - return err; } static int exynos4_busfreq_remove(struct platform_device *pdev) @@ -1020,10 +1013,6 @@ static int exynos4_busfreq_remove(struct platform_device *pdev) /* Unregister all of notifier chain */ unregister_pm_notifier(&data->pm_notifier); - devfreq_unregister_opp_notifier(data->dev, data->devfreq); - - /* Remove devfreq instance */ - devfreq_remove_device(data->devfreq); return 0; } -- cgit v1.1 From 2456963c0b736f4111f9c4517ae12f63d332c312 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 9 May 2014 16:43:11 +0900 Subject: PM / devfreq: exynos5: Use devm_devfreq_* function using device resource management This patch uses devm_devfreq_add_device()/devm_devfreq_register_opp_notifier() to control automatically the resource of devfreq. Signed-off-by: Chanwoo Choi Cc: Kukjin Kim Cc: Sachin Kamat Cc: Bartlomiej Zolnierkiewicz Cc: Manish Badarkhe Cc: Abhilash Kesavan Cc: linux-arm-kernel@lists.infradead.org Cc: linux-samsung-soc@vger.kernel.org Signed-off-by: MyungJoo Ham --- drivers/devfreq/exynos/exynos5_bus.c | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/drivers/devfreq/exynos/exynos5_bus.c b/drivers/devfreq/exynos/exynos5_bus.c index ab54a69..6cd0392 100644 --- a/drivers/devfreq/exynos/exynos5_bus.c +++ b/drivers/devfreq/exynos/exynos5_bus.c @@ -163,21 +163,12 @@ static int exynos5_int_get_dev_status(struct device *dev, return 0; } -static void exynos5_int_exit(struct device *dev) -{ - struct platform_device *pdev = container_of(dev, struct platform_device, - dev); - struct busfreq_data_int *data = platform_get_drvdata(pdev); - - devfreq_unregister_opp_notifier(dev, data->devfreq); -} static struct devfreq_dev_profile exynos5_devfreq_int_profile = { .initial_freq = 160000, .polling_ms = 100, .target = exynos5_busfreq_int_target, .get_dev_status = exynos5_int_get_dev_status, - .exit = exynos5_int_exit, }; static int exynos5250_init_int_tables(struct busfreq_data_int *data) @@ -343,30 +334,27 @@ static int exynos5_busfreq_int_probe(struct platform_device *pdev) busfreq_mon_reset(ppmu_data); - data->devfreq = devfreq_add_device(dev, &exynos5_devfreq_int_profile, + data->devfreq = devm_devfreq_add_device(dev, &exynos5_devfreq_int_profile, "simple_ondemand", NULL); + if (IS_ERR(data->devfreq)) + return PTR_ERR(data->devfreq); - if (IS_ERR(data->devfreq)) { - err = PTR_ERR(data->devfreq); - goto err_devfreq_add; + err = devm_devfreq_register_opp_notifier(dev, data->devfreq); + if (err < 0) { + dev_err(dev, "Failed to register opp notifier\n"); + return err; } - devfreq_register_opp_notifier(dev, data->devfreq); - err = register_pm_notifier(&data->pm_notifier); if (err) { dev_err(dev, "Failed to setup pm notifier\n"); - goto err_devfreq_add; + return err; } /* TODO: Add a new QOS class for int/mif bus */ pm_qos_add_request(&data->int_req, PM_QOS_NETWORK_THROUGHPUT, -1); return 0; - -err_devfreq_add: - devfreq_remove_device(data->devfreq); - return err; } static int exynos5_busfreq_int_remove(struct platform_device *pdev) @@ -375,7 +363,6 @@ static int exynos5_busfreq_int_remove(struct platform_device *pdev) pm_qos_remove_request(&data->int_req); unregister_pm_notifier(&data->pm_notifier); - devfreq_remove_device(data->devfreq); return 0; } -- cgit v1.1 From cb7063f453e543b97285a10343cfc02983d792ad Mon Sep 17 00:00:00 2001 From: Paul Bolle Date: Wed, 21 May 2014 22:37:34 +0200 Subject: PM / devfreq: remove checks for CONFIG_EXYNOS_ASV Checks for CONFIG_EXYNOS_ASV were added in v3.3. But the related Kconfig symbol has never been added to the tree. Remove these checks, as they always evaluate to false. Signed-off-by: Paul Bolle [Merge conflict resolved by MyungJoo] Signed-off-by: MyungJoo Ham --- drivers/devfreq/Kconfig | 3 +-- drivers/devfreq/exynos/exynos4_bus.c | 17 ++++------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/drivers/devfreq/Kconfig b/drivers/devfreq/Kconfig index c023c57..49e74c1 100644 --- a/drivers/devfreq/Kconfig +++ b/drivers/devfreq/Kconfig @@ -76,8 +76,7 @@ config ARM_EXYNOS4_BUS_DEVFREQ and Exynos4212/4412 memory interface and bus (vdd_mif + vdd_int). It reads PPMU counters of memory controllers and adjusts the operating frequencies and voltages with OPP support. - To operate with optimal voltages, ASV support is required - (CONFIG_EXYNOS_ASV). + This does not yet operate with optimal voltages. config ARM_EXYNOS5_BUS_DEVFREQ bool "ARM Exynos5250 Bus DEVFREQ Driver" diff --git a/drivers/devfreq/exynos/exynos4_bus.c b/drivers/devfreq/exynos/exynos4_bus.c index bebb0a4..d9b08d3 100644 --- a/drivers/devfreq/exynos/exynos4_bus.c +++ b/drivers/devfreq/exynos/exynos4_bus.c @@ -30,11 +30,6 @@ #include "exynos_ppmu.h" #include "exynos4_bus.h" -/* Exynos4 ASV has been in the mailing list, but not upstreamed, yet. */ -#ifdef CONFIG_EXYNOS_ASV -extern unsigned int exynos_result_of_asv; -#endif - #define MAX_SAFEVOLT 1200000 /* 1.2V */ enum exynos4_busf_type { @@ -723,11 +718,11 @@ static int exynos4210_init_tables(struct busfreq_data *data) data->top_divtable[i] = tmp; } -#ifdef CONFIG_EXYNOS_ASV - tmp = exynos4_result_of_asv; -#else + /* + * TODO: init tmp based on busfreq_data + * (device-tree or platform-data) + */ tmp = 0; /* Max voltages for the reliability of the unknown */ -#endif pr_debug("ASV Group of Exynos4 is %d\n", tmp); /* Use merged grouping for voltage */ @@ -808,11 +803,7 @@ static int exynos4x12_init_tables(struct busfreq_data *data) data->dmc_divtable[i] = tmp; } -#ifdef CONFIG_EXYNOS_ASV - tmp = exynos4_result_of_asv; -#else tmp = 0; /* Max voltages for the reliability of the unknown */ -#endif if (tmp > 8) tmp = 0; -- cgit v1.1