Lines Matching +full:smp2p +full:- +full:modem
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.
21 * DOC: IPA SMP2P communication with the modem
23 * SMP2P is a primitive communication mechanism available between the AP and
24 * the modem. The IPA driver uses this for two purposes: to enable the modem
29 * This initialization is done either by Trust Zone or by the modem. In the
30 * latter case, the modem uses an SMP2P interrupt to tell the AP IPA driver
33 * The modem is also able to inquire about the current state of IPA
34 * power by trigging another SMP2P interrupt to the AP. We communicate
35 * whether power is enabled using two SMP2P state bits--one to indicate
37 * bit is valid. The modem will poll the valid bit until it is set, and
40 * Finally, if the AP kernel panics, we update the SMP2P state bits even if
41 * we never receive an interrupt from the modem requesting this.
45 * struct ipa_smp2p - IPA SMP2P information
49 * @valid_bit: Valid bit in 32-bit SMEM state mask
50 * @enabled_bit: Enabled bit in 32-bit SMEM state mask
51 * @enabled_bit: Enabled bit in 32-bit SMEM state mask
52 * @clock_query_irq: IPA interrupt triggered by modem for power query
53 * @setup_ready_irq: IPA interrupt triggered by modem to signal GSI ready
55 * @notified: Whether modem has been notified of power state
57 * @mutex: Mutex protecting ready-interrupt/shutdown interlock
76 * ipa_smp2p_notify() - use SMP2P to tell modem about IPA power state
77 * @smp2p: SMP2P information
79 * This is called either when the modem has requested it (by triggering
80 * the modem power query IPA interrupt) or whenever the AP is shutting down
81 * (via a panic notifier). It sets the two SMP2P state bits--one saying
85 static void ipa_smp2p_notify(struct ipa_smp2p *smp2p) in ipa_smp2p_notify() argument
91 if (smp2p->notified) in ipa_smp2p_notify()
94 dev = &smp2p->ipa->pdev->dev; in ipa_smp2p_notify()
95 smp2p->power_on = pm_runtime_get_if_active(dev, true) > 0; in ipa_smp2p_notify()
98 mask = BIT(smp2p->enabled_bit); in ipa_smp2p_notify()
99 value = smp2p->power_on ? mask : 0; in ipa_smp2p_notify()
100 qcom_smem_state_update_bits(smp2p->enabled_state, mask, value); in ipa_smp2p_notify()
103 mask = BIT(smp2p->valid_bit); in ipa_smp2p_notify()
105 qcom_smem_state_update_bits(smp2p->valid_state, mask, value); in ipa_smp2p_notify()
107 smp2p->notified = true; in ipa_smp2p_notify()
110 /* Threaded IRQ handler for modem "ipa-clock-query" SMP2P interrupt */
113 struct ipa_smp2p *smp2p = dev_id; in ipa_smp2p_modem_clk_query_isr() local
115 ipa_smp2p_notify(smp2p); in ipa_smp2p_modem_clk_query_isr()
123 struct ipa_smp2p *smp2p; in ipa_smp2p_panic_notifier() local
125 smp2p = container_of(nb, struct ipa_smp2p, panic_notifier); in ipa_smp2p_panic_notifier()
127 ipa_smp2p_notify(smp2p); in ipa_smp2p_panic_notifier()
129 if (smp2p->power_on) in ipa_smp2p_panic_notifier()
130 ipa_uc_panic_notifier(smp2p->ipa); in ipa_smp2p_panic_notifier()
135 static int ipa_smp2p_panic_notifier_register(struct ipa_smp2p *smp2p) in ipa_smp2p_panic_notifier_register() argument
137 /* IPA panic handler needs to run before modem shuts down */ in ipa_smp2p_panic_notifier_register()
138 smp2p->panic_notifier.notifier_call = ipa_smp2p_panic_notifier; in ipa_smp2p_panic_notifier_register()
139 smp2p->panic_notifier.priority = INT_MAX; /* Do it early */ in ipa_smp2p_panic_notifier_register()
142 &smp2p->panic_notifier); in ipa_smp2p_panic_notifier_register()
145 static void ipa_smp2p_panic_notifier_unregister(struct ipa_smp2p *smp2p) in ipa_smp2p_panic_notifier_unregister() argument
148 &smp2p->panic_notifier); in ipa_smp2p_panic_notifier_unregister()
151 /* Threaded IRQ handler for modem "ipa-setup-ready" SMP2P interrupt */
154 struct ipa_smp2p *smp2p = dev_id; in ipa_smp2p_modem_setup_ready_isr() local
158 mutex_lock(&smp2p->mutex); in ipa_smp2p_modem_setup_ready_isr()
160 if (smp2p->disabled) in ipa_smp2p_modem_setup_ready_isr()
162 smp2p->disabled = true; /* If any others arrive, ignore them */ in ipa_smp2p_modem_setup_ready_isr()
165 dev = &smp2p->ipa->pdev->dev; in ipa_smp2p_modem_setup_ready_isr()
173 ret = ipa_setup(smp2p->ipa); in ipa_smp2p_modem_setup_ready_isr()
180 mutex_unlock(&smp2p->mutex); in ipa_smp2p_modem_setup_ready_isr()
185 /* Initialize SMP2P interrupts */
186 static int ipa_smp2p_irq_init(struct ipa_smp2p *smp2p, const char *name, in ipa_smp2p_irq_init() argument
189 struct device *dev = &smp2p->ipa->pdev->dev; in ipa_smp2p_irq_init()
193 ret = platform_get_irq_byname(smp2p->ipa->pdev, name); in ipa_smp2p_irq_init()
195 return ret ? : -EINVAL; in ipa_smp2p_irq_init()
198 ret = request_threaded_irq(irq, NULL, handler, 0, name, smp2p); in ipa_smp2p_irq_init()
207 static void ipa_smp2p_irq_exit(struct ipa_smp2p *smp2p, u32 irq) in ipa_smp2p_irq_exit() argument
209 free_irq(irq, smp2p); in ipa_smp2p_irq_exit()
215 struct device *dev = &ipa->pdev->dev; in ipa_smp2p_power_release()
217 if (!ipa->smp2p->power_on) in ipa_smp2p_power_release()
222 ipa->smp2p->power_on = false; in ipa_smp2p_power_release()
225 /* Initialize the IPA SMP2P subsystem */
229 struct device *dev = &ipa->pdev->dev; in ipa_smp2p_init()
231 struct ipa_smp2p *smp2p; in ipa_smp2p_init() local
236 valid_state = qcom_smem_state_get(dev, "ipa-clock-enabled-valid", in ipa_smp2p_init()
241 return -EINVAL; in ipa_smp2p_init()
243 enabled_state = qcom_smem_state_get(dev, "ipa-clock-enabled", in ipa_smp2p_init()
248 return -EINVAL; in ipa_smp2p_init()
250 smp2p = kzalloc(sizeof(*smp2p), GFP_KERNEL); in ipa_smp2p_init()
251 if (!smp2p) in ipa_smp2p_init()
252 return -ENOMEM; in ipa_smp2p_init()
254 smp2p->ipa = ipa; in ipa_smp2p_init()
259 mutex_init(&smp2p->mutex); in ipa_smp2p_init()
260 smp2p->valid_state = valid_state; in ipa_smp2p_init()
261 smp2p->valid_bit = valid_bit; in ipa_smp2p_init()
262 smp2p->enabled_state = enabled_state; in ipa_smp2p_init()
263 smp2p->enabled_bit = enabled_bit; in ipa_smp2p_init()
266 ipa->smp2p = smp2p; in ipa_smp2p_init()
268 ret = ipa_smp2p_irq_init(smp2p, "ipa-clock-query", in ipa_smp2p_init()
272 smp2p->clock_query_irq = ret; in ipa_smp2p_init()
274 ret = ipa_smp2p_panic_notifier_register(smp2p); in ipa_smp2p_init()
279 /* Result will be non-zero (negative for error) */ in ipa_smp2p_init()
280 ret = ipa_smp2p_irq_init(smp2p, "ipa-setup-ready", in ipa_smp2p_init()
284 smp2p->setup_ready_irq = ret; in ipa_smp2p_init()
290 ipa_smp2p_panic_notifier_unregister(smp2p); in ipa_smp2p_init()
292 ipa_smp2p_irq_exit(smp2p, smp2p->clock_query_irq); in ipa_smp2p_init()
294 ipa->smp2p = NULL; in ipa_smp2p_init()
295 mutex_destroy(&smp2p->mutex); in ipa_smp2p_init()
296 kfree(smp2p); in ipa_smp2p_init()
303 struct ipa_smp2p *smp2p = ipa->smp2p; in ipa_smp2p_exit() local
305 if (smp2p->setup_ready_irq) in ipa_smp2p_exit()
306 ipa_smp2p_irq_exit(smp2p, smp2p->setup_ready_irq); in ipa_smp2p_exit()
307 ipa_smp2p_panic_notifier_unregister(smp2p); in ipa_smp2p_exit()
308 ipa_smp2p_irq_exit(smp2p, smp2p->clock_query_irq); in ipa_smp2p_exit()
311 ipa->smp2p = NULL; in ipa_smp2p_exit()
312 mutex_destroy(&smp2p->mutex); in ipa_smp2p_exit()
313 kfree(smp2p); in ipa_smp2p_exit()
318 struct ipa_smp2p *smp2p = ipa->smp2p; in ipa_smp2p_disable() local
320 if (!smp2p->setup_ready_irq) in ipa_smp2p_disable()
323 mutex_lock(&smp2p->mutex); in ipa_smp2p_disable()
325 smp2p->disabled = true; in ipa_smp2p_disable()
327 mutex_unlock(&smp2p->mutex); in ipa_smp2p_disable()
330 /* Reset state tracking whether we have notified the modem */
333 struct ipa_smp2p *smp2p = ipa->smp2p; in ipa_smp2p_notify_reset() local
336 if (!smp2p->notified) in ipa_smp2p_notify_reset()
342 mask = BIT(smp2p->valid_bit); in ipa_smp2p_notify_reset()
343 qcom_smem_state_update_bits(smp2p->valid_state, mask, 0); in ipa_smp2p_notify_reset()
346 mask = BIT(smp2p->enabled_bit); in ipa_smp2p_notify_reset()
347 qcom_smem_state_update_bits(smp2p->enabled_state, mask, 0); in ipa_smp2p_notify_reset()
349 smp2p->notified = false; in ipa_smp2p_notify_reset()