cpuidle-exynos.c 3.4 KB
Newer Older
1 2
/*
 * Copyright (c) 2011-2014 Samsung Electronics Co., Ltd.
J
Jaecheol Lee 已提交
3 4
 *		http://www.samsung.com
 *
5 6 7 8
 * Coupled cpuidle support based on the work of:
 *	Colin Cross <ccross@android.com>
 *	Daniel Lezcano <daniel.lezcano@linaro.org>
 *
J
Jaecheol Lee 已提交
9 10 11 12 13 14
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
*/

#include <linux/cpuidle.h>
15
#include <linux/cpu_pm.h>
16
#include <linux/export.h>
17
#include <linux/module.h>
18
#include <linux/platform_device.h>
19 20
#include <linux/of.h>
#include <linux/platform_data/cpuidle-exynos.h>
J
Jaecheol Lee 已提交
21 22

#include <asm/proc-fns.h>
23
#include <asm/suspend.h>
24
#include <asm/cpuidle.h>
25

26 27 28
static atomic_t exynos_idle_barrier;

static struct cpuidle_exynos_data *exynos_cpuidle_pdata;
29
static void (*exynos_enter_aftr)(void);
30

31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
static int exynos_enter_coupled_lowpower(struct cpuidle_device *dev,
					 struct cpuidle_driver *drv,
					 int index)
{
	int ret;

	exynos_cpuidle_pdata->pre_enter_aftr();

	/*
	 * Waiting all cpus to reach this point at the same moment
	 */
	cpuidle_coupled_parallel_barrier(dev, &exynos_idle_barrier);

	/*
	 * Both cpus will reach this point at the same time
	 */
	ret = dev->cpu ? exynos_cpuidle_pdata->cpu1_powerdown()
		       : exynos_cpuidle_pdata->cpu0_enter_aftr();
	if (ret)
		index = ret;

	/*
	 * Waiting all cpus to finish the power sequence before going further
	 */
	cpuidle_coupled_parallel_barrier(dev, &exynos_idle_barrier);

	exynos_cpuidle_pdata->post_enter_aftr();

	return index;
}

62
static int exynos_enter_lowpower(struct cpuidle_device *dev,
63 64 65 66 67
				struct cpuidle_driver *drv,
				int index)
{
	int new_index = index;

68 69
	/* AFTR can only be entered when cores other than CPU0 are offline */
	if (num_online_cpus() > 1 || dev->cpu != 0)
70 71 72
		new_index = drv->safe_state_index;

	if (new_index == 0)
73
		return arm_cpuidle_simple_enter(dev, drv, new_index);
74 75 76 77

	exynos_enter_aftr();

	return new_index;
78 79
}

80 81
static struct cpuidle_driver exynos_idle_driver = {
	.name			= "exynos_idle",
82 83 84 85
	.owner			= THIS_MODULE,
	.states = {
		[0] = ARM_CPUIDLE_WFI_STATE,
		[1] = {
86
			.enter			= exynos_enter_lowpower,
87 88 89 90 91 92 93 94 95 96
			.exit_latency		= 300,
			.target_residency	= 100000,
			.name			= "C1",
			.desc			= "ARM power down",
		},
	},
	.state_count = 2,
	.safe_state_index = 0,
};

97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
static struct cpuidle_driver exynos_coupled_idle_driver = {
	.name			= "exynos_coupled_idle",
	.owner			= THIS_MODULE,
	.states = {
		[0] = ARM_CPUIDLE_WFI_STATE,
		[1] = {
			.enter			= exynos_enter_coupled_lowpower,
			.exit_latency		= 5000,
			.target_residency	= 10000,
			.flags			= CPUIDLE_FLAG_COUPLED |
						  CPUIDLE_FLAG_TIMER_STOP,
			.name			= "C1",
			.desc			= "ARM power down",
		},
	},
	.state_count = 2,
	.safe_state_index = 0,
};

116
static int exynos_cpuidle_probe(struct platform_device *pdev)
J
Jaecheol Lee 已提交
117
{
118
	int ret;
119

120 121
	if (IS_ENABLED(CONFIG_SMP) &&
	    of_machine_is_compatible("samsung,exynos4210")) {
122 123 124 125 126 127 128 129 130
		exynos_cpuidle_pdata = pdev->dev.platform_data;

		ret = cpuidle_register(&exynos_coupled_idle_driver,
				       cpu_possible_mask);
	} else {
		exynos_enter_aftr = (void *)(pdev->dev.platform_data);

		ret = cpuidle_register(&exynos_idle_driver, NULL);
	}
131

132
	if (ret) {
133
		dev_err(&pdev->dev, "failed to register cpuidle driver\n");
134
		return ret;
135
	}
J
Jaecheol Lee 已提交
136 137 138

	return 0;
}
139 140 141 142 143 144 145 146 147

static struct platform_driver exynos_cpuidle_driver = {
	.probe	= exynos_cpuidle_probe,
	.driver = {
		.name = "exynos_cpuidle",
	},
};

module_platform_driver(exynos_cpuidle_driver);