Bartlomiej Zolnierkiewicz | 712eddf7 | 2015-01-24 14:05:50 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011-2014 Samsung Electronics Co., Ltd. |
Jaecheol Lee | 3d73998 | 2011-03-16 07:28:23 +0900 | [diff] [blame] | 3 | * http://www.samsung.com |
| 4 | * |
Bartlomiej Zolnierkiewicz | 712eddf7 | 2015-01-24 14:05:50 +0900 | [diff] [blame] | 5 | * Coupled cpuidle support based on the work of: |
| 6 | * Colin Cross <ccross@android.com> |
| 7 | * Daniel Lezcano <daniel.lezcano@linaro.org> |
| 8 | * |
Jaecheol Lee | 3d73998 | 2011-03-16 07:28:23 +0900 | [diff] [blame] | 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
| 13 | |
Jaecheol Lee | 3d73998 | 2011-03-16 07:28:23 +0900 | [diff] [blame] | 14 | #include <linux/cpuidle.h> |
Amit Daniel Kachhap | 67173ca | 2012-03-08 02:07:27 -0800 | [diff] [blame] | 15 | #include <linux/cpu_pm.h> |
Kyungmin Park | 76ee455 | 2011-11-08 19:57:59 +0900 | [diff] [blame] | 16 | #include <linux/export.h> |
Arnd Bergmann | 96c3a25 | 2014-03-19 18:29:36 +0100 | [diff] [blame] | 17 | #include <linux/module.h> |
Bartlomiej Zolnierkiewicz | 35baa33 | 2013-08-30 12:15:04 +0200 | [diff] [blame] | 18 | #include <linux/platform_device.h> |
Bartlomiej Zolnierkiewicz | 712eddf7 | 2015-01-24 14:05:50 +0900 | [diff] [blame] | 19 | #include <linux/of.h> |
| 20 | #include <linux/platform_data/cpuidle-exynos.h> |
Jaecheol Lee | 3d73998 | 2011-03-16 07:28:23 +0900 | [diff] [blame] | 21 | |
Amit Daniel Kachhap | 67173ca | 2012-03-08 02:07:27 -0800 | [diff] [blame] | 22 | #include <asm/suspend.h> |
Amit Daniel Kachhap | 06c77b3 | 2012-05-12 16:29:21 +0900 | [diff] [blame] | 23 | #include <asm/cpuidle.h> |
Amit Daniel Kachhap | 67173ca | 2012-03-08 02:07:27 -0800 | [diff] [blame] | 24 | |
Bartlomiej Zolnierkiewicz | 712eddf7 | 2015-01-24 14:05:50 +0900 | [diff] [blame] | 25 | static atomic_t exynos_idle_barrier; |
| 26 | |
| 27 | static struct cpuidle_exynos_data *exynos_cpuidle_pdata; |
Daniel Lezcano | 277f504 | 2014-05-09 06:56:29 +0900 | [diff] [blame] | 28 | static void (*exynos_enter_aftr)(void); |
Kukjin Kim | ccd458c | 2012-12-31 10:06:48 -0800 | [diff] [blame] | 29 | |
Bartlomiej Zolnierkiewicz | 712eddf7 | 2015-01-24 14:05:50 +0900 | [diff] [blame] | 30 | static int exynos_enter_coupled_lowpower(struct cpuidle_device *dev, |
| 31 | struct cpuidle_driver *drv, |
| 32 | int index) |
| 33 | { |
| 34 | int ret; |
| 35 | |
| 36 | exynos_cpuidle_pdata->pre_enter_aftr(); |
| 37 | |
| 38 | /* |
| 39 | * Waiting all cpus to reach this point at the same moment |
| 40 | */ |
| 41 | cpuidle_coupled_parallel_barrier(dev, &exynos_idle_barrier); |
| 42 | |
| 43 | /* |
| 44 | * Both cpus will reach this point at the same time |
| 45 | */ |
| 46 | ret = dev->cpu ? exynos_cpuidle_pdata->cpu1_powerdown() |
| 47 | : exynos_cpuidle_pdata->cpu0_enter_aftr(); |
| 48 | if (ret) |
| 49 | index = ret; |
| 50 | |
| 51 | /* |
| 52 | * Waiting all cpus to finish the power sequence before going further |
| 53 | */ |
| 54 | cpuidle_coupled_parallel_barrier(dev, &exynos_idle_barrier); |
| 55 | |
| 56 | exynos_cpuidle_pdata->post_enter_aftr(); |
| 57 | |
| 58 | return index; |
| 59 | } |
| 60 | |
Daniel Lezcano | 7880e45 | 2014-05-09 06:43:26 +0900 | [diff] [blame] | 61 | static int exynos_enter_lowpower(struct cpuidle_device *dev, |
Amit Daniel Kachhap | 67173ca | 2012-03-08 02:07:27 -0800 | [diff] [blame] | 62 | struct cpuidle_driver *drv, |
| 63 | int index) |
| 64 | { |
| 65 | int new_index = index; |
| 66 | |
Bartlomiej Zolnierkiewicz | 118f5c1 | 2013-12-20 19:47:23 +0100 | [diff] [blame] | 67 | /* AFTR can only be entered when cores other than CPU0 are offline */ |
| 68 | if (num_online_cpus() > 1 || dev->cpu != 0) |
Amit Daniel Kachhap | 67173ca | 2012-03-08 02:07:27 -0800 | [diff] [blame] | 69 | new_index = drv->safe_state_index; |
| 70 | |
| 71 | if (new_index == 0) |
Amit Daniel Kachhap | 06c77b3 | 2012-05-12 16:29:21 +0900 | [diff] [blame] | 72 | return arm_cpuidle_simple_enter(dev, drv, new_index); |
Tomasz Figa | 01601b3 | 2014-08-05 14:43:10 +0200 | [diff] [blame] | 73 | |
| 74 | exynos_enter_aftr(); |
| 75 | |
| 76 | return new_index; |
Amit Daniel Kachhap | 67173ca | 2012-03-08 02:07:27 -0800 | [diff] [blame] | 77 | } |
| 78 | |
Daniel Lezcano | 7880e45 | 2014-05-09 06:43:26 +0900 | [diff] [blame] | 79 | static struct cpuidle_driver exynos_idle_driver = { |
| 80 | .name = "exynos_idle", |
Daniel Lezcano | 53af16a | 2014-05-09 06:43:26 +0900 | [diff] [blame] | 81 | .owner = THIS_MODULE, |
| 82 | .states = { |
| 83 | [0] = ARM_CPUIDLE_WFI_STATE, |
| 84 | [1] = { |
Daniel Lezcano | 7880e45 | 2014-05-09 06:43:26 +0900 | [diff] [blame] | 85 | .enter = exynos_enter_lowpower, |
Daniel Lezcano | 53af16a | 2014-05-09 06:43:26 +0900 | [diff] [blame] | 86 | .exit_latency = 300, |
| 87 | .target_residency = 100000, |
Daniel Lezcano | 53af16a | 2014-05-09 06:43:26 +0900 | [diff] [blame] | 88 | .name = "C1", |
| 89 | .desc = "ARM power down", |
| 90 | }, |
| 91 | }, |
| 92 | .state_count = 2, |
| 93 | .safe_state_index = 0, |
| 94 | }; |
| 95 | |
Bartlomiej Zolnierkiewicz | 712eddf7 | 2015-01-24 14:05:50 +0900 | [diff] [blame] | 96 | static struct cpuidle_driver exynos_coupled_idle_driver = { |
| 97 | .name = "exynos_coupled_idle", |
| 98 | .owner = THIS_MODULE, |
| 99 | .states = { |
| 100 | [0] = ARM_CPUIDLE_WFI_STATE, |
| 101 | [1] = { |
| 102 | .enter = exynos_enter_coupled_lowpower, |
| 103 | .exit_latency = 5000, |
| 104 | .target_residency = 10000, |
| 105 | .flags = CPUIDLE_FLAG_COUPLED | |
| 106 | CPUIDLE_FLAG_TIMER_STOP, |
| 107 | .name = "C1", |
| 108 | .desc = "ARM power down", |
| 109 | }, |
| 110 | }, |
| 111 | .state_count = 2, |
| 112 | .safe_state_index = 0, |
| 113 | }; |
| 114 | |
Jingoo Han | f612a4f | 2013-10-21 10:53:03 +0900 | [diff] [blame] | 115 | static int exynos_cpuidle_probe(struct platform_device *pdev) |
Jaecheol Lee | 3d73998 | 2011-03-16 07:28:23 +0900 | [diff] [blame] | 116 | { |
Daniel Lezcano | 043c86b | 2014-05-09 06:43:26 +0900 | [diff] [blame] | 117 | int ret; |
Jaecheol Lee | 3d73998 | 2011-03-16 07:28:23 +0900 | [diff] [blame] | 118 | |
Bartlomiej Zolnierkiewicz | cfdda35 | 2015-03-18 03:26:11 +0900 | [diff] [blame] | 119 | if (IS_ENABLED(CONFIG_SMP) && |
| 120 | of_machine_is_compatible("samsung,exynos4210")) { |
Bartlomiej Zolnierkiewicz | 712eddf7 | 2015-01-24 14:05:50 +0900 | [diff] [blame] | 121 | exynos_cpuidle_pdata = pdev->dev.platform_data; |
Daniel Lezcano | 277f504 | 2014-05-09 06:56:29 +0900 | [diff] [blame] | 122 | |
Bartlomiej Zolnierkiewicz | 712eddf7 | 2015-01-24 14:05:50 +0900 | [diff] [blame] | 123 | ret = cpuidle_register(&exynos_coupled_idle_driver, |
| 124 | cpu_possible_mask); |
| 125 | } else { |
| 126 | exynos_enter_aftr = (void *)(pdev->dev.platform_data); |
| 127 | |
| 128 | ret = cpuidle_register(&exynos_idle_driver, NULL); |
| 129 | } |
| 130 | |
Daniel Lezcano | 5db9f43 | 2013-01-18 21:57:58 -0800 | [diff] [blame] | 131 | if (ret) { |
Jingoo Han | ae7c4c8 | 2013-10-21 10:52:15 +0900 | [diff] [blame] | 132 | dev_err(&pdev->dev, "failed to register cpuidle driver\n"); |
Daniel Lezcano | 5db9f43 | 2013-01-18 21:57:58 -0800 | [diff] [blame] | 133 | return ret; |
Deepthi Dharwar | 46bcfad | 2011-10-28 16:20:42 +0530 | [diff] [blame] | 134 | } |
Jaecheol Lee | 3d73998 | 2011-03-16 07:28:23 +0900 | [diff] [blame] | 135 | |
Jaecheol Lee | 3d73998 | 2011-03-16 07:28:23 +0900 | [diff] [blame] | 136 | return 0; |
| 137 | } |
Bartlomiej Zolnierkiewicz | 35baa33 | 2013-08-30 12:15:04 +0200 | [diff] [blame] | 138 | |
| 139 | static struct platform_driver exynos_cpuidle_driver = { |
| 140 | .probe = exynos_cpuidle_probe, |
| 141 | .driver = { |
| 142 | .name = "exynos_cpuidle", |
Bartlomiej Zolnierkiewicz | 35baa33 | 2013-08-30 12:15:04 +0200 | [diff] [blame] | 143 | }, |
| 144 | }; |
| 145 | |
| 146 | module_platform_driver(exynos_cpuidle_driver); |