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