blob: 326e870d712394fad445033defd8e3ff5975ebdd [file] [log] [blame]
Shawn Guo12bb34402012-12-04 22:55:14 +08001/*
2 * Copyright (C) 2012 Freescale Semiconductor, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9#include <linux/cpuidle.h>
10#include <linux/module.h>
11#include <asm/cpuidle.h>
12
Ben Dooks47096102016-06-21 13:13:11 +010013#include <soc/imx/cpuidle.h>
14
Shawn Guoe5f9dec2012-12-04 22:55:15 +080015#include "common.h"
Shawn Guo12bb34402012-12-04 22:55:14 +080016#include "cpuidle.h"
Anson Huanga25d67a2014-06-20 13:44:05 +080017#include "hardware.h"
Shawn Guo12bb34402012-12-04 22:55:14 +080018
Kohji Okuno0e146142019-02-26 11:34:13 +090019static int num_idle_cpus = 0;
20static DEFINE_SPINLOCK(cpuidle_lock);
Shawn Guoe5f9dec2012-12-04 22:55:15 +080021
22static int imx6q_enter_wait(struct cpuidle_device *dev,
23 struct cpuidle_driver *drv, int index)
24{
Kohji Okuno0e146142019-02-26 11:34:13 +090025 spin_lock(&cpuidle_lock);
26 if (++num_idle_cpus == num_online_cpus())
Shawn Guo8fb76a02015-04-25 22:59:19 +080027 imx6_set_lpm(WAIT_UNCLOCKED);
Kohji Okuno0e146142019-02-26 11:34:13 +090028 spin_unlock(&cpuidle_lock);
Shawn Guoe5f9dec2012-12-04 22:55:15 +080029
Shawn Guoe5f9dec2012-12-04 22:55:15 +080030 cpu_do_idle();
Kohji Okuno0e146142019-02-26 11:34:13 +090031
32 spin_lock(&cpuidle_lock);
33 if (num_idle_cpus-- == num_online_cpus())
34 imx6_set_lpm(WAIT_CLOCKED);
35 spin_unlock(&cpuidle_lock);
Shawn Guoe5f9dec2012-12-04 22:55:15 +080036
37 return index;
38}
39
Shawn Guo12bb34402012-12-04 22:55:14 +080040static struct cpuidle_driver imx6q_cpuidle_driver = {
41 .name = "imx6q_cpuidle",
42 .owner = THIS_MODULE,
Shawn Guoe5f9dec2012-12-04 22:55:15 +080043 .states = {
44 /* WFI */
45 ARM_CPUIDLE_WFI_STATE,
46 /* WAIT */
47 {
48 .exit_latency = 50,
49 .target_residency = 75,
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +010050 .flags = CPUIDLE_FLAG_TIMER_STOP,
Shawn Guoe5f9dec2012-12-04 22:55:15 +080051 .enter = imx6q_enter_wait,
52 .name = "WAIT",
53 .desc = "Clock off",
54 },
55 },
56 .state_count = 2,
57 .safe_state_index = 0,
Shawn Guo12bb34402012-12-04 22:55:14 +080058};
59
Lucas Stach29380902016-06-03 18:31:19 +020060/*
61 * i.MX6 Q/DL has an erratum (ERR006687) that prevents the FEC from waking the
62 * CPUs when they are in wait(unclocked) state. As the hardware workaround isn't
63 * applicable to all boards, disable the deeper idle state when the workaround
64 * isn't present and the FEC is in use.
65 */
66void imx6q_cpuidle_fec_irqs_used(void)
67{
68 imx6q_cpuidle_driver.states[1].disabled = true;
69}
Shawn Guo2cb9caa2016-06-21 10:30:44 +080070EXPORT_SYMBOL_GPL(imx6q_cpuidle_fec_irqs_used);
Lucas Stach29380902016-06-03 18:31:19 +020071
72void imx6q_cpuidle_fec_irqs_unused(void)
73{
74 imx6q_cpuidle_driver.states[1].disabled = false;
75}
Shawn Guo2cb9caa2016-06-21 10:30:44 +080076EXPORT_SYMBOL_GPL(imx6q_cpuidle_fec_irqs_unused);
Lucas Stach29380902016-06-03 18:31:19 +020077
Shawn Guo12bb34402012-12-04 22:55:14 +080078int __init imx6q_cpuidle_init(void)
79{
Fabio Estevamfa6be652014-01-07 08:00:40 -020080 /* Set INT_MEM_CLK_LPM bit to get a reliable WAIT mode support */
Anson Huang8765caa2016-08-29 21:49:56 +080081 imx6_set_int_mem_clk_lpm(true);
Shawn Guoe5f9dec2012-12-04 22:55:15 +080082
Daniel Lezcano54a46442013-04-23 08:54:45 +000083 return cpuidle_register(&imx6q_cpuidle_driver, NULL);
Shawn Guo12bb34402012-12-04 22:55:14 +080084}