| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * DT idle states parsing code. |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2014 ARM Ltd. |
|---|
| 5 | 6 | * Author: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> |
|---|
| 6 | | - * |
|---|
| 7 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 8 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 9 | | - * published by the Free Software Foundation. |
|---|
| 10 | 7 | */ |
|---|
| 11 | 8 | |
|---|
| 12 | 9 | #define pr_fmt(fmt) "DT idle-states: " fmt |
|---|
| .. | .. |
|---|
| 22 | 19 | #include "dt_idle_states.h" |
|---|
| 23 | 20 | |
|---|
| 24 | 21 | static int init_state_node(struct cpuidle_state *idle_state, |
|---|
| 25 | | - const struct of_device_id *matches, |
|---|
| 22 | + const struct of_device_id *match_id, |
|---|
| 26 | 23 | struct device_node *state_node) |
|---|
| 27 | 24 | { |
|---|
| 28 | 25 | int err; |
|---|
| 29 | | - const struct of_device_id *match_id; |
|---|
| 30 | 26 | const char *desc; |
|---|
| 31 | 27 | |
|---|
| 32 | | - match_id = of_match_node(matches, state_node); |
|---|
| 33 | | - if (!match_id) |
|---|
| 34 | | - return -ENODEV; |
|---|
| 35 | 28 | /* |
|---|
| 36 | 29 | * CPUidle drivers are expected to initialize the const void *data |
|---|
| 37 | 30 | * pointer of the passed in struct of_device_id array to the idle |
|---|
| .. | .. |
|---|
| 118 | 111 | for (cpu = cpumask_next(cpumask_first(cpumask), cpumask); |
|---|
| 119 | 112 | cpu < nr_cpu_ids; cpu = cpumask_next(cpu, cpumask)) { |
|---|
| 120 | 113 | cpu_node = of_cpu_device_node_get(cpu); |
|---|
| 121 | | - curr_state_node = of_parse_phandle(cpu_node, "cpu-idle-states", |
|---|
| 122 | | - idx); |
|---|
| 114 | + curr_state_node = of_get_cpu_state_node(cpu_node, idx); |
|---|
| 123 | 115 | if (state_node != curr_state_node) |
|---|
| 124 | 116 | valid = false; |
|---|
| 125 | 117 | |
|---|
| .. | .. |
|---|
| 160 | 152 | { |
|---|
| 161 | 153 | struct cpuidle_state *idle_state; |
|---|
| 162 | 154 | struct device_node *state_node, *cpu_node; |
|---|
| 155 | + const struct of_device_id *match_id; |
|---|
| 163 | 156 | int i, err = 0; |
|---|
| 164 | 157 | const cpumask_t *cpumask; |
|---|
| 165 | 158 | unsigned int state_idx = start_idx; |
|---|
| .. | .. |
|---|
| 176 | 169 | cpu_node = of_cpu_device_node_get(cpumask_first(cpumask)); |
|---|
| 177 | 170 | |
|---|
| 178 | 171 | for (i = 0; ; i++) { |
|---|
| 179 | | - state_node = of_parse_phandle(cpu_node, "cpu-idle-states", i); |
|---|
| 172 | + state_node = of_get_cpu_state_node(cpu_node, i); |
|---|
| 180 | 173 | if (!state_node) |
|---|
| 181 | 174 | break; |
|---|
| 175 | + |
|---|
| 176 | + match_id = of_match_node(matches, state_node); |
|---|
| 177 | + if (!match_id) { |
|---|
| 178 | + err = -ENODEV; |
|---|
| 179 | + break; |
|---|
| 180 | + } |
|---|
| 182 | 181 | |
|---|
| 183 | 182 | if (!of_device_is_available(state_node)) { |
|---|
| 184 | 183 | of_node_put(state_node); |
|---|
| .. | .. |
|---|
| 198 | 197 | } |
|---|
| 199 | 198 | |
|---|
| 200 | 199 | idle_state = &drv->states[state_idx++]; |
|---|
| 201 | | - err = init_state_node(idle_state, matches, state_node); |
|---|
| 200 | + err = init_state_node(idle_state, match_id, state_node); |
|---|
| 202 | 201 | if (err) { |
|---|
| 203 | 202 | pr_err("Parsing idle state node %pOF failed with err %d\n", |
|---|
| 204 | 203 | state_node, err); |
|---|