Lines Matching defs:clock
20 * The "IPA Clock" manages both the IPA core clock and the interconnects
23 * Transitions of that count from 0 to 1 result in the clock and interconnects
25 * disabled. We currently operate the core clock at a fixed clock rate, and
27 * features are enabled, we can make better use of clock and bus scaling.
29 * An IPA clock reference must be held for any access to IPA hardware.
47 * @mutex: Protects clock enable/disable
48 * @core: IPA core clock
55 struct mutex mutex; /* protects clock enable/disable */
76 static int ipa_interconnect_init(struct ipa_clock *clock, struct device *dev)
83 clock->memory_path = path;
88 clock->imem_path = path;
93 clock->config_path = path;
98 icc_put(clock->imem_path);
100 icc_put(clock->memory_path);
106 static void ipa_interconnect_exit(struct ipa_clock *clock)
108 icc_put(clock->config_path);
109 icc_put(clock->imem_path);
110 icc_put(clock->memory_path);
116 struct ipa_clock *clock = ipa->clock;
119 ret = icc_set_bw(clock->memory_path, IPA_MEMORY_AVG, IPA_MEMORY_PEAK);
123 ret = icc_set_bw(clock->imem_path, IPA_IMEM_AVG, IPA_IMEM_PEAK);
127 ret = icc_set_bw(clock->config_path, IPA_CONFIG_AVG, IPA_CONFIG_PEAK);
134 (void)icc_set_bw(clock->imem_path, 0, 0);
136 (void)icc_set_bw(clock->memory_path, 0, 0);
144 struct ipa_clock *clock = ipa->clock;
147 ret = icc_set_bw(clock->memory_path, 0, 0);
151 ret = icc_set_bw(clock->imem_path, 0, 0);
155 ret = icc_set_bw(clock->config_path, 0, 0);
162 (void)icc_set_bw(clock->imem_path, IPA_IMEM_AVG, IPA_IMEM_PEAK);
164 (void)icc_set_bw(clock->memory_path, IPA_MEMORY_AVG, IPA_MEMORY_PEAK);
178 ret = clk_prepare_enable(ipa->clock->core);
188 clk_disable_unprepare(ipa->clock->core);
192 /* Get an IPA clock reference, but only if the reference count is
198 return refcount_inc_not_zero(&ipa->clock->count);
201 /* Get an IPA clock reference. If the reference count is non-zero, it is
203 * under protection of the mutex, and if appropriate the IPA clock
207 * after the clock is running and endpoints are resumed.
211 struct ipa_clock *clock = ipa->clock;
214 /* If the clock is running, just bump the reference count */
219 mutex_lock(&clock->mutex);
227 dev_err(&ipa->pdev->dev, "error %d enabling IPA clock\n", ret);
231 refcount_set(&clock->count, 1);
234 mutex_unlock(&clock->mutex);
237 /* Attempt to remove an IPA clock reference. If this represents the
238 * last reference, disable the IPA clock under protection of the mutex.
242 struct ipa_clock *clock = ipa->clock;
245 if (!refcount_dec_and_mutex_lock(&clock->count, &clock->mutex))
250 mutex_unlock(&clock->mutex);
253 /* Return the current IPA core clock rate */
256 return ipa->clock ? (u32)clk_get_rate(ipa->clock->core) : 0;
262 struct ipa_clock *clock;
268 dev_err(dev, "error %ld getting core clock\n", PTR_ERR(clk));
274 dev_err(dev, "error %d setting core clock rate to %lu\n",
279 clock = kzalloc(sizeof(*clock), GFP_KERNEL);
280 if (!clock) {
284 clock->core = clk;
286 ret = ipa_interconnect_init(clock, dev);
290 mutex_init(&clock->mutex);
291 refcount_set(&clock->count, 0);
293 return clock;
296 kfree(clock);
304 void ipa_clock_exit(struct ipa_clock *clock)
306 struct clk *clk = clock->core;
308 WARN_ON(refcount_read(&clock->count) != 0);
309 mutex_destroy(&clock->mutex);
310 ipa_interconnect_exit(clock);
311 kfree(clock);