Lines Matching +full:ipa +full:- +full:clock +full:- +full:enabled +full:- +full:valid
1 // SPDX-License-Identifier: GPL-2.0
3 /* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
4 * Copyright (C) 2019-2020 Linaro Ltd.
15 #include "ipa.h"
20 * DOC: IPA SMP2P communication with the modem
23 * the modem. The IPA driver uses this for two purposes: to enable the modem
25 * state of the IPA clock in the event of a crash.
29 * latter case, the modem uses an SMP2P interrupt to tell the AP IPA driver
32 * The modem is also able to inquire about the current state of the IPA
33 * clock by trigging another SMP2P interrupt to the AP. We communicate
34 * whether the clock is enabled using two SMP2P state bits--one to
35 * indicate the clock state (on or off), and a second to indicate the
36 * clock state bit is valid. The modem will poll the valid bit until it
37 * is set, and at that time records whether the AP has the IPA clock enabled.
44 * struct ipa_smp2p - IPA SMP2P information
45 * @ipa: IPA pointer
46 * @valid_state: SMEM state indicating enabled state is valid
47 * @enabled_state: SMEM state to indicate clock is enabled
48 * @valid_bit: Valid bit in 32-bit SMEM state mask
49 * @enabled_bit: Enabled bit in 32-bit SMEM state mask
50 * @enabled_bit: Enabled bit in 32-bit SMEM state mask
51 * @clock_query_irq: IPA interrupt triggered by modem for clock query
52 * @setup_ready_irq: IPA interrupt triggered by modem to signal GSI ready
53 * @clock_on: Whether IPA clock is on
54 * @notified: Whether modem has been notified of clock state
56 * @mutex: Mutex protecting ready-interrupt/shutdown interlock
60 struct ipa *ipa; member
75 * ipa_smp2p_notify() - use SMP2P to tell modem about IPA clock state
79 * the modem clock query IPA interrupt) or whenever the AP is shutting down
80 * (via a panic notifier). It sets the two SMP2P state bits--one saying
81 * whether the IPA clock is running, and the other indicating the first bit
82 * is valid.
89 if (smp2p->notified) in ipa_smp2p_notify()
92 smp2p->clock_on = ipa_clock_get_additional(smp2p->ipa); in ipa_smp2p_notify()
94 /* Signal whether the clock is enabled */ in ipa_smp2p_notify()
95 mask = BIT(smp2p->enabled_bit); in ipa_smp2p_notify()
96 value = smp2p->clock_on ? mask : 0; in ipa_smp2p_notify()
97 qcom_smem_state_update_bits(smp2p->enabled_state, mask, value); in ipa_smp2p_notify()
99 /* Now indicate that the enabled flag is valid */ in ipa_smp2p_notify()
100 mask = BIT(smp2p->valid_bit); in ipa_smp2p_notify()
102 qcom_smem_state_update_bits(smp2p->valid_state, mask, value); in ipa_smp2p_notify()
104 smp2p->notified = true; in ipa_smp2p_notify()
107 /* Threaded IRQ handler for modem "ipa-clock-query" SMP2P interrupt */
126 if (smp2p->clock_on) in ipa_smp2p_panic_notifier()
127 ipa_uc_panic_notifier(smp2p->ipa); in ipa_smp2p_panic_notifier()
134 /* IPA panic handler needs to run before modem shuts down */ in ipa_smp2p_panic_notifier_register()
135 smp2p->panic_notifier.notifier_call = ipa_smp2p_panic_notifier; in ipa_smp2p_panic_notifier_register()
136 smp2p->panic_notifier.priority = INT_MAX; /* Do it early */ in ipa_smp2p_panic_notifier_register()
139 &smp2p->panic_notifier); in ipa_smp2p_panic_notifier_register()
145 &smp2p->panic_notifier); in ipa_smp2p_panic_notifier_unregister()
148 /* Threaded IRQ handler for modem "ipa-setup-ready" SMP2P interrupt */
153 mutex_lock(&smp2p->mutex); in ipa_smp2p_modem_setup_ready_isr()
155 if (!smp2p->disabled) { in ipa_smp2p_modem_setup_ready_isr()
158 ret = ipa_setup(smp2p->ipa); in ipa_smp2p_modem_setup_ready_isr()
160 dev_err(&smp2p->ipa->pdev->dev, in ipa_smp2p_modem_setup_ready_isr()
162 smp2p->disabled = true; in ipa_smp2p_modem_setup_ready_isr()
165 mutex_unlock(&smp2p->mutex); in ipa_smp2p_modem_setup_ready_isr()
174 struct device *dev = &smp2p->ipa->pdev->dev; in ipa_smp2p_irq_init()
178 ret = platform_get_irq_byname(smp2p->ipa->pdev, name); in ipa_smp2p_irq_init()
182 return ret ? : -EINVAL; in ipa_smp2p_irq_init()
200 /* Drop the clock reference if it was taken in ipa_smp2p_notify() */
201 static void ipa_smp2p_clock_release(struct ipa *ipa) in ipa_smp2p_clock_release() argument
203 if (!ipa->smp2p->clock_on) in ipa_smp2p_clock_release()
206 ipa_clock_put(ipa); in ipa_smp2p_clock_release()
207 ipa->smp2p->clock_on = false; in ipa_smp2p_clock_release()
210 /* Initialize the IPA SMP2P subsystem */
211 int ipa_smp2p_init(struct ipa *ipa, bool modem_init) in ipa_smp2p_init() argument
214 struct device *dev = &ipa->pdev->dev; in ipa_smp2p_init()
221 valid_state = qcom_smem_state_get(dev, "ipa-clock-enabled-valid", in ipa_smp2p_init()
226 return -EINVAL; in ipa_smp2p_init()
228 enabled_state = qcom_smem_state_get(dev, "ipa-clock-enabled", in ipa_smp2p_init()
233 return -EINVAL; in ipa_smp2p_init()
237 return -ENOMEM; in ipa_smp2p_init()
239 smp2p->ipa = ipa; in ipa_smp2p_init()
241 /* These fields are needed by the clock query interrupt in ipa_smp2p_init()
244 mutex_init(&smp2p->mutex); in ipa_smp2p_init()
245 smp2p->valid_state = valid_state; in ipa_smp2p_init()
246 smp2p->valid_bit = valid_bit; in ipa_smp2p_init()
247 smp2p->enabled_state = enabled_state; in ipa_smp2p_init()
248 smp2p->enabled_bit = enabled_bit; in ipa_smp2p_init()
251 ipa->smp2p = smp2p; in ipa_smp2p_init()
253 ret = ipa_smp2p_irq_init(smp2p, "ipa-clock-query", in ipa_smp2p_init()
257 smp2p->clock_query_irq = ret; in ipa_smp2p_init()
264 /* Result will be non-zero (negative for error) */ in ipa_smp2p_init()
265 ret = ipa_smp2p_irq_init(smp2p, "ipa-setup-ready", in ipa_smp2p_init()
269 smp2p->setup_ready_irq = ret; in ipa_smp2p_init()
277 ipa_smp2p_irq_exit(smp2p, smp2p->clock_query_irq); in ipa_smp2p_init()
279 ipa->smp2p = NULL; in ipa_smp2p_init()
280 mutex_destroy(&smp2p->mutex); in ipa_smp2p_init()
286 void ipa_smp2p_exit(struct ipa *ipa) in ipa_smp2p_exit() argument
288 struct ipa_smp2p *smp2p = ipa->smp2p; in ipa_smp2p_exit()
290 if (smp2p->setup_ready_irq) in ipa_smp2p_exit()
291 ipa_smp2p_irq_exit(smp2p, smp2p->setup_ready_irq); in ipa_smp2p_exit()
293 ipa_smp2p_irq_exit(smp2p, smp2p->clock_query_irq); in ipa_smp2p_exit()
294 /* We won't get notified any more; drop clock reference (if any) */ in ipa_smp2p_exit()
295 ipa_smp2p_clock_release(ipa); in ipa_smp2p_exit()
296 ipa->smp2p = NULL; in ipa_smp2p_exit()
297 mutex_destroy(&smp2p->mutex); in ipa_smp2p_exit()
301 void ipa_smp2p_disable(struct ipa *ipa) in ipa_smp2p_disable() argument
303 struct ipa_smp2p *smp2p = ipa->smp2p; in ipa_smp2p_disable()
305 if (!smp2p->setup_ready_irq) in ipa_smp2p_disable()
308 mutex_lock(&smp2p->mutex); in ipa_smp2p_disable()
310 smp2p->disabled = true; in ipa_smp2p_disable()
312 mutex_unlock(&smp2p->mutex); in ipa_smp2p_disable()
316 void ipa_smp2p_notify_reset(struct ipa *ipa) in ipa_smp2p_notify_reset() argument
318 struct ipa_smp2p *smp2p = ipa->smp2p; in ipa_smp2p_notify_reset()
321 if (!smp2p->notified) in ipa_smp2p_notify_reset()
324 ipa_smp2p_clock_release(ipa); in ipa_smp2p_notify_reset()
326 /* Reset the clock enabled valid flag */ in ipa_smp2p_notify_reset()
327 mask = BIT(smp2p->valid_bit); in ipa_smp2p_notify_reset()
328 qcom_smem_state_update_bits(smp2p->valid_state, mask, 0); in ipa_smp2p_notify_reset()
330 /* Mark the clock disabled for good measure... */ in ipa_smp2p_notify_reset()
331 mask = BIT(smp2p->enabled_bit); in ipa_smp2p_notify_reset()
332 qcom_smem_state_update_bits(smp2p->enabled_state, mask, 0); in ipa_smp2p_notify_reset()
334 smp2p->notified = false; in ipa_smp2p_notify_reset()