Lines Matching +full:smem +full:- +full:state +full:- +full:names
1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
17 * struct qcom_smem_state - state context
18 * @refcount: refcount for the state
19 * @orphan: boolean indicator that this state has been unregistered
21 * @of_node: of_node to use for matching the state in DT
23 * @ops: ops for the state
38 * qcom_smem_state_update_bits() - update the masked bits in state with value
39 * @state: state handle acquired by calling qcom_smem_state_get()
45 int qcom_smem_state_update_bits(struct qcom_smem_state *state, in qcom_smem_state_update_bits() argument
49 if (state->orphan) in qcom_smem_state_update_bits()
50 return -ENXIO; in qcom_smem_state_update_bits()
52 if (!state->ops.update_bits) in qcom_smem_state_update_bits()
53 return -ENOTSUPP; in qcom_smem_state_update_bits()
55 return state->ops.update_bits(state->priv, mask, value); in qcom_smem_state_update_bits()
61 struct qcom_smem_state *state; in of_node_to_state() local
65 list_for_each_entry(state, &smem_states, list) { in of_node_to_state()
66 if (state->of_node == np) { in of_node_to_state()
67 kref_get(&state->refcount); in of_node_to_state()
71 state = ERR_PTR(-EPROBE_DEFER); in of_node_to_state()
76 return state; in of_node_to_state()
80 * qcom_smem_state_get() - acquire handle to a state
82 * @con_id: name of the state to lookup
83 * @bit: flags from the state reference, indicating which bit's affected
85 * Returns handle to the state, or ERR_PTR(). qcom_smem_state_put() must be
86 * called to release the returned state handle.
92 struct qcom_smem_state *state; in qcom_smem_state_get() local
98 index = of_property_match_string(dev->of_node, in qcom_smem_state_get()
99 "qcom,smem-state-names", in qcom_smem_state_get()
102 dev_err(dev, "missing qcom,smem-state-names\n"); in qcom_smem_state_get()
107 ret = of_parse_phandle_with_args(dev->of_node, in qcom_smem_state_get()
108 "qcom,smem-states", in qcom_smem_state_get()
109 "#qcom,smem-state-cells", in qcom_smem_state_get()
113 dev_err(dev, "failed to parse qcom,smem-states property\n"); in qcom_smem_state_get()
118 dev_err(dev, "invalid #qcom,smem-state-cells\n"); in qcom_smem_state_get()
119 return ERR_PTR(-EINVAL); in qcom_smem_state_get()
122 state = of_node_to_state(args.np); in qcom_smem_state_get()
123 if (IS_ERR(state)) in qcom_smem_state_get()
130 return state; in qcom_smem_state_get()
136 struct qcom_smem_state *state = container_of(ref, struct qcom_smem_state, refcount); in qcom_smem_state_release() local
138 list_del(&state->list); in qcom_smem_state_release()
139 of_node_put(state->of_node); in qcom_smem_state_release()
140 kfree(state); in qcom_smem_state_release()
144 * qcom_smem_state_put() - release state handle
145 * @state: state handle to be released
147 void qcom_smem_state_put(struct qcom_smem_state *state) in qcom_smem_state_put() argument
150 kref_put(&state->refcount, qcom_smem_state_release); in qcom_smem_state_put()
161 * devm_qcom_smem_state_get() - acquire handle to a devres managed state
163 * @con_id: name of the state to lookup
164 * @bit: flags from the state reference, indicating which bit's affected
166 * Returns handle to the state, or ERR_PTR(). qcom_smem_state_put() is called
173 struct qcom_smem_state **ptr, *state; in devm_qcom_smem_state_get() local
177 return ERR_PTR(-ENOMEM); in devm_qcom_smem_state_get()
179 state = qcom_smem_state_get(dev, con_id, bit); in devm_qcom_smem_state_get()
180 if (!IS_ERR(state)) { in devm_qcom_smem_state_get()
181 *ptr = state; in devm_qcom_smem_state_get()
187 return state; in devm_qcom_smem_state_get()
192 * qcom_smem_state_register() - register a new state
201 struct qcom_smem_state *state; in qcom_smem_state_register() local
203 state = kzalloc(sizeof(*state), GFP_KERNEL); in qcom_smem_state_register()
204 if (!state) in qcom_smem_state_register()
205 return ERR_PTR(-ENOMEM); in qcom_smem_state_register()
207 kref_init(&state->refcount); in qcom_smem_state_register()
209 state->of_node = of_node_get(of_node); in qcom_smem_state_register()
210 state->ops = *ops; in qcom_smem_state_register()
211 state->priv = priv; in qcom_smem_state_register()
214 list_add(&state->list, &smem_states); in qcom_smem_state_register()
217 return state; in qcom_smem_state_register()
222 * qcom_smem_state_unregister() - unregister a registered state
223 * @state: state handle to be unregistered
225 void qcom_smem_state_unregister(struct qcom_smem_state *state) in qcom_smem_state_unregister() argument
227 state->orphan = true; in qcom_smem_state_unregister()
228 qcom_smem_state_put(state); in qcom_smem_state_unregister()