2 * Copyright 2012 Linaro Ltd.
4 * The code contained herein is licensed under the GNU General Public
5 * License. You may obtain a copy of the GNU General Public License
6 * Version 2 or later at the following locations:
8 * http://www.opensource.org/licenses/gpl-license.html
9 * http://www.gnu.org/copyleft/gpl.html
12 #include <linux/cpuidle.h>
14 #include <linux/of_device.h>
15 #include <asm/cpuidle.h>
17 extern struct of_cpuidle_method __cpuidle_method_of_table
[];
19 static const struct of_cpuidle_method __cpuidle_method_of_table_sentinel
20 __used
__section(__cpuidle_method_of_table_end
);
22 static struct cpuidle_ops cpuidle_ops
[NR_CPUS
];
25 * arm_cpuidle_simple_enter() - a wrapper to cpu_do_idle()
30 * A trivial wrapper to allow the cpu_do_idle function to be assigned as a
31 * cpuidle callback by matching the function signature.
33 * Returns the index passed as parameter
35 int arm_cpuidle_simple_enter(struct cpuidle_device
*dev
,
36 struct cpuidle_driver
*drv
, int index
)
44 * arm_cpuidle_suspend() - function to enter low power idle states
45 * @index: an integer used as an identifier for the low level PM callbacks
47 * This function calls the underlying arch specific low level PM code as
48 * registered at the init time.
50 * Returns -EOPNOTSUPP if no suspend callback is defined, the result of the
53 int arm_cpuidle_suspend(int index
)
55 int ret
= -EOPNOTSUPP
;
56 int cpu
= smp_processor_id();
58 if (cpuidle_ops
[cpu
].suspend
)
59 ret
= cpuidle_ops
[cpu
].suspend(cpu
, index
);
65 * arm_cpuidle_get_ops() - find a registered cpuidle_ops by name
66 * @method: the method name
68 * Search in the __cpuidle_method_of_table array the cpuidle ops matching the
71 * Returns a struct cpuidle_ops pointer, NULL if not found.
73 static struct cpuidle_ops
*__init
arm_cpuidle_get_ops(const char *method
)
75 struct of_cpuidle_method
*m
= __cpuidle_method_of_table
;
77 for (; m
->method
; m
++)
78 if (!strcmp(m
->method
, method
))
85 * arm_cpuidle_read_ops() - Initialize the cpuidle ops with the device tree
86 * @dn: a pointer to a struct device node corresponding to a cpu node
87 * @cpu: the cpu identifier
89 * Get the method name defined in the 'enable-method' property, retrieve the
90 * associated cpuidle_ops and do a struct copy. This copy is needed because all
91 * cpuidle_ops are tagged __initdata and will be unloaded after the init
94 * Return 0 on sucess, -ENOENT if no 'enable-method' is defined, -EOPNOTSUPP if
95 * no cpuidle_ops is registered for the 'enable-method'.
97 static int __init
arm_cpuidle_read_ops(struct device_node
*dn
, int cpu
)
99 const char *enable_method
;
100 struct cpuidle_ops
*ops
;
102 enable_method
= of_get_property(dn
, "enable-method", NULL
);
106 ops
= arm_cpuidle_get_ops(enable_method
);
108 pr_warn("%s: unsupported enable-method property: %s\n",
109 dn
->full_name
, enable_method
);
113 cpuidle_ops
[cpu
] = *ops
; /* structure copy */
115 pr_notice("cpuidle: enable-method property '%s'"
116 " found operations\n", enable_method
);
122 * arm_cpuidle_init() - Initialize cpuidle_ops for a specific cpu
123 * @cpu: the cpu to be initialized
125 * Initialize the cpuidle ops with the device for the cpu and then call
126 * the cpu's idle initialization callback. This may fail if the underlying HW
127 * is not operational.
131 * -ENODEV if it fails to find the cpu node in the device tree,
132 * -EOPNOTSUPP if it does not find a registered cpuidle_ops for this cpu,
133 * -ENOENT if it fails to find an 'enable-method' property,
134 * -ENXIO if the HW reports a failure or a misconfiguration,
135 * -ENOMEM if the HW report an memory allocation failure
137 int __init
arm_cpuidle_init(int cpu
)
139 struct device_node
*cpu_node
= of_cpu_device_node_get(cpu
);
145 ret
= arm_cpuidle_read_ops(cpu_node
, cpu
);
146 if (!ret
&& cpuidle_ops
[cpu
].init
)
147 ret
= cpuidle_ops
[cpu
].init(cpu_node
, cpu
);
149 of_node_put(cpu_node
);