• Home
  • Raw
  • Download

Lines Matching +full:tegra194 +full:- +full:ccplex

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2016-2018, NVIDIA CORPORATION. All rights reserved.
18 #include <dt-bindings/mailbox/tegra186-hsp.h>
111 return readl(hsp->regs + offset); in tegra_hsp_readl()
117 writel(value, hsp->regs + offset); in tegra_hsp_writel()
123 return readl(channel->regs + offset); in tegra_hsp_channel_readl()
129 writel(value, channel->regs + offset); in tegra_hsp_channel_writel()
136 value = tegra_hsp_channel_readl(&db->channel, HSP_DB_ENABLE); in tegra_hsp_doorbell_can_ring()
146 list_for_each_entry(entry, &hsp->doorbells, list) in __tegra_hsp_doorbell_get()
147 if (entry->master == master) in __tegra_hsp_doorbell_get()
159 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_doorbell_get()
161 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_doorbell_get()
176 value = tegra_hsp_channel_readl(&db->channel, HSP_DB_PENDING); in tegra_hsp_doorbell_irq()
177 tegra_hsp_channel_writel(&db->channel, value, HSP_DB_PENDING); in tegra_hsp_doorbell_irq()
179 spin_lock(&hsp->lock); in tegra_hsp_doorbell_irq()
181 for_each_set_bit(master, &value, hsp->mbox_db.num_chans) { in tegra_hsp_doorbell_irq()
186 * Depending on the bootloader chain, the CCPLEX doorbell will in tegra_hsp_doorbell_irq()
190 * In that case, db->channel.chan will still be NULL here and in tegra_hsp_doorbell_irq()
196 if (db && db->channel.chan) in tegra_hsp_doorbell_irq()
197 mbox_chan_received_data(db->channel.chan, NULL); in tegra_hsp_doorbell_irq()
200 spin_unlock(&hsp->lock); in tegra_hsp_doorbell_irq()
212 status = tegra_hsp_readl(hsp, HSP_INT_IR) & hsp->mask; in tegra_hsp_shared_irq()
217 for_each_set_bit(bit, &mask, hsp->num_sm) { in tegra_hsp_shared_irq()
218 struct tegra_hsp_mailbox *mb = &hsp->mailboxes[bit]; in tegra_hsp_shared_irq()
220 if (mb->producer) { in tegra_hsp_shared_irq()
223 * the next message. These interrupts are level- in tegra_hsp_shared_irq()
228 spin_lock(&hsp->lock); in tegra_hsp_shared_irq()
230 hsp->mask &= ~BIT(HSP_INT_EMPTY_SHIFT + mb->index); in tegra_hsp_shared_irq()
231 tegra_hsp_writel(hsp, hsp->mask, in tegra_hsp_shared_irq()
232 HSP_INT_IE(hsp->shared_irq)); in tegra_hsp_shared_irq()
234 spin_unlock(&hsp->lock); in tegra_hsp_shared_irq()
236 mbox_chan_txdone(mb->channel.chan, 0); in tegra_hsp_shared_irq()
243 for_each_set_bit(bit, &mask, hsp->num_sm) { in tegra_hsp_shared_irq()
244 struct tegra_hsp_mailbox *mb = &hsp->mailboxes[bit]; in tegra_hsp_shared_irq()
246 if (!mb->producer) { in tegra_hsp_shared_irq()
247 value = tegra_hsp_channel_readl(&mb->channel, in tegra_hsp_shared_irq()
251 mbox_chan_received_data(mb->channel.chan, msg); in tegra_hsp_shared_irq()
262 tegra_hsp_channel_writel(&mb->channel, 0x0, in tegra_hsp_shared_irq()
278 db = devm_kzalloc(hsp->dev, sizeof(*db), GFP_KERNEL); in tegra_hsp_doorbell_create()
280 return ERR_PTR(-ENOMEM); in tegra_hsp_doorbell_create()
282 offset = (1 + (hsp->num_sm / 2) + hsp->num_ss + hsp->num_as) * SZ_64K; in tegra_hsp_doorbell_create()
285 db->channel.regs = hsp->regs + offset; in tegra_hsp_doorbell_create()
286 db->channel.hsp = hsp; in tegra_hsp_doorbell_create()
288 db->name = devm_kstrdup_const(hsp->dev, name, GFP_KERNEL); in tegra_hsp_doorbell_create()
289 db->master = master; in tegra_hsp_doorbell_create()
290 db->index = index; in tegra_hsp_doorbell_create()
292 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_doorbell_create()
293 list_add_tail(&db->list, &hsp->doorbells); in tegra_hsp_doorbell_create()
294 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_doorbell_create()
296 return &db->channel; in tegra_hsp_doorbell_create()
301 struct tegra_hsp_doorbell *db = chan->con_priv; in tegra_hsp_doorbell_send_data()
303 tegra_hsp_channel_writel(&db->channel, 1, HSP_DB_TRIGGER); in tegra_hsp_doorbell_send_data()
310 struct tegra_hsp_doorbell *db = chan->con_priv; in tegra_hsp_doorbell_startup()
311 struct tegra_hsp *hsp = db->channel.hsp; in tegra_hsp_doorbell_startup()
312 struct tegra_hsp_doorbell *ccplex; in tegra_hsp_doorbell_startup() local
316 if (db->master >= chan->mbox->num_chans) { in tegra_hsp_doorbell_startup()
317 dev_err(chan->mbox->dev, in tegra_hsp_doorbell_startup()
319 db->master); in tegra_hsp_doorbell_startup()
320 return -EINVAL; in tegra_hsp_doorbell_startup()
323 ccplex = tegra_hsp_doorbell_get(hsp, TEGRA_HSP_DB_MASTER_CCPLEX); in tegra_hsp_doorbell_startup()
324 if (!ccplex) in tegra_hsp_doorbell_startup()
325 return -ENODEV; in tegra_hsp_doorbell_startup()
329 * the doorbell as ringable by the CCPLEX, so we want to skip extra in tegra_hsp_doorbell_startup()
333 return -ENODEV; in tegra_hsp_doorbell_startup()
335 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_doorbell_startup()
337 value = tegra_hsp_channel_readl(&ccplex->channel, HSP_DB_ENABLE); in tegra_hsp_doorbell_startup()
338 value |= BIT(db->master); in tegra_hsp_doorbell_startup()
339 tegra_hsp_channel_writel(&ccplex->channel, value, HSP_DB_ENABLE); in tegra_hsp_doorbell_startup()
341 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_doorbell_startup()
348 struct tegra_hsp_doorbell *db = chan->con_priv; in tegra_hsp_doorbell_shutdown()
349 struct tegra_hsp *hsp = db->channel.hsp; in tegra_hsp_doorbell_shutdown()
350 struct tegra_hsp_doorbell *ccplex; in tegra_hsp_doorbell_shutdown() local
354 ccplex = tegra_hsp_doorbell_get(hsp, TEGRA_HSP_DB_MASTER_CCPLEX); in tegra_hsp_doorbell_shutdown()
355 if (!ccplex) in tegra_hsp_doorbell_shutdown()
358 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_doorbell_shutdown()
360 value = tegra_hsp_channel_readl(&ccplex->channel, HSP_DB_ENABLE); in tegra_hsp_doorbell_shutdown()
361 value &= ~BIT(db->master); in tegra_hsp_doorbell_shutdown()
362 tegra_hsp_channel_writel(&ccplex->channel, value, HSP_DB_ENABLE); in tegra_hsp_doorbell_shutdown()
364 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_doorbell_shutdown()
375 struct tegra_hsp_mailbox *mb = chan->con_priv; in tegra_hsp_mailbox_send_data()
376 struct tegra_hsp *hsp = mb->channel.hsp; in tegra_hsp_mailbox_send_data()
380 if (WARN_ON(!mb->producer)) in tegra_hsp_mailbox_send_data()
381 return -EPERM; in tegra_hsp_mailbox_send_data()
387 tegra_hsp_channel_writel(&mb->channel, value, HSP_SM_SHRD_MBOX); in tegra_hsp_mailbox_send_data()
390 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_mailbox_send_data()
392 hsp->mask |= BIT(HSP_INT_EMPTY_SHIFT + mb->index); in tegra_hsp_mailbox_send_data()
393 tegra_hsp_writel(hsp, hsp->mask, HSP_INT_IE(hsp->shared_irq)); in tegra_hsp_mailbox_send_data()
395 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_mailbox_send_data()
403 struct tegra_hsp_mailbox *mb = chan->con_priv; in tegra_hsp_mailbox_flush()
404 struct tegra_hsp_channel *ch = &mb->channel; in tegra_hsp_mailbox_flush()
415 if (chan->active_req != NULL) in tegra_hsp_mailbox_flush()
424 return -ETIME; in tegra_hsp_mailbox_flush()
429 struct tegra_hsp_mailbox *mb = chan->con_priv; in tegra_hsp_mailbox_startup()
430 struct tegra_hsp_channel *ch = &mb->channel; in tegra_hsp_mailbox_startup()
431 struct tegra_hsp *hsp = mb->channel.hsp; in tegra_hsp_mailbox_startup()
434 chan->txdone_method = TXDONE_BY_IRQ; in tegra_hsp_mailbox_startup()
442 * EMPTY interrupts are level-triggered, so keeping EMPTY interrupts in tegra_hsp_mailbox_startup()
447 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_mailbox_startup()
449 if (mb->producer) in tegra_hsp_mailbox_startup()
450 hsp->mask &= ~BIT(HSP_INT_EMPTY_SHIFT + mb->index); in tegra_hsp_mailbox_startup()
452 hsp->mask |= BIT(HSP_INT_FULL_SHIFT + mb->index); in tegra_hsp_mailbox_startup()
454 tegra_hsp_writel(hsp, hsp->mask, HSP_INT_IE(hsp->shared_irq)); in tegra_hsp_mailbox_startup()
456 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_mailbox_startup()
458 if (hsp->soc->has_per_mb_ie) { in tegra_hsp_mailbox_startup()
459 if (mb->producer) in tegra_hsp_mailbox_startup()
472 struct tegra_hsp_mailbox *mb = chan->con_priv; in tegra_hsp_mailbox_shutdown()
473 struct tegra_hsp_channel *ch = &mb->channel; in tegra_hsp_mailbox_shutdown()
474 struct tegra_hsp *hsp = mb->channel.hsp; in tegra_hsp_mailbox_shutdown()
477 if (hsp->soc->has_per_mb_ie) { in tegra_hsp_mailbox_shutdown()
478 if (mb->producer) in tegra_hsp_mailbox_shutdown()
486 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_mailbox_shutdown()
488 if (mb->producer) in tegra_hsp_mailbox_shutdown()
489 hsp->mask &= ~BIT(HSP_INT_EMPTY_SHIFT + mb->index); in tegra_hsp_mailbox_shutdown()
491 hsp->mask &= ~BIT(HSP_INT_FULL_SHIFT + mb->index); in tegra_hsp_mailbox_shutdown()
493 tegra_hsp_writel(hsp, hsp->mask, HSP_INT_IE(hsp->shared_irq)); in tegra_hsp_mailbox_shutdown()
495 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_mailbox_shutdown()
509 unsigned int type = args->args[0], master = args->args[1]; in tegra_hsp_db_xlate()
510 struct tegra_hsp_channel *channel = ERR_PTR(-ENODEV); in tegra_hsp_db_xlate()
516 if (type != TEGRA_HSP_MBOX_TYPE_DB || !hsp->doorbell_irq) in tegra_hsp_db_xlate()
517 return ERR_PTR(-ENODEV); in tegra_hsp_db_xlate()
521 channel = &db->channel; in tegra_hsp_db_xlate()
526 spin_lock_irqsave(&hsp->lock, flags); in tegra_hsp_db_xlate()
528 for (i = 0; i < mbox->num_chans; i++) { in tegra_hsp_db_xlate()
529 chan = &mbox->chans[i]; in tegra_hsp_db_xlate()
530 if (!chan->con_priv) { in tegra_hsp_db_xlate()
531 channel->chan = chan; in tegra_hsp_db_xlate()
532 chan->con_priv = db; in tegra_hsp_db_xlate()
539 spin_unlock_irqrestore(&hsp->lock, flags); in tegra_hsp_db_xlate()
541 return chan ?: ERR_PTR(-EBUSY); in tegra_hsp_db_xlate()
548 unsigned int type = args->args[0], index; in tegra_hsp_sm_xlate()
551 index = args->args[1] & TEGRA_HSP_SM_MASK; in tegra_hsp_sm_xlate()
553 if (type != TEGRA_HSP_MBOX_TYPE_SM || !hsp->shared_irqs || in tegra_hsp_sm_xlate()
554 index >= hsp->num_sm) in tegra_hsp_sm_xlate()
555 return ERR_PTR(-ENODEV); in tegra_hsp_sm_xlate()
557 mb = &hsp->mailboxes[index]; in tegra_hsp_sm_xlate()
559 if ((args->args[1] & TEGRA_HSP_SM_FLAG_TX) == 0) in tegra_hsp_sm_xlate()
560 mb->producer = false; in tegra_hsp_sm_xlate()
562 mb->producer = true; in tegra_hsp_sm_xlate()
564 return mb->channel.chan; in tegra_hsp_sm_xlate()
569 const struct tegra_hsp_db_map *map = hsp->soc->map; in tegra_hsp_add_doorbells()
572 while (map->name) { in tegra_hsp_add_doorbells()
573 channel = tegra_hsp_doorbell_create(hsp, map->name, in tegra_hsp_add_doorbells()
574 map->master, map->index); in tegra_hsp_add_doorbells()
588 hsp->mailboxes = devm_kcalloc(dev, hsp->num_sm, sizeof(*hsp->mailboxes), in tegra_hsp_add_mailboxes()
590 if (!hsp->mailboxes) in tegra_hsp_add_mailboxes()
591 return -ENOMEM; in tegra_hsp_add_mailboxes()
593 for (i = 0; i < hsp->num_sm; i++) { in tegra_hsp_add_mailboxes()
594 struct tegra_hsp_mailbox *mb = &hsp->mailboxes[i]; in tegra_hsp_add_mailboxes()
596 mb->index = i; in tegra_hsp_add_mailboxes()
598 mb->channel.hsp = hsp; in tegra_hsp_add_mailboxes()
599 mb->channel.regs = hsp->regs + SZ_64K + i * SZ_32K; in tegra_hsp_add_mailboxes()
600 mb->channel.chan = &hsp->mbox_sm.chans[i]; in tegra_hsp_add_mailboxes()
601 mb->channel.chan->con_priv = mb; in tegra_hsp_add_mailboxes()
612 for (i = 0; i < hsp->num_si; i++) { in tegra_hsp_request_shared_irq()
613 irq = hsp->shared_irqs[i]; in tegra_hsp_request_shared_irq()
617 err = devm_request_irq(hsp->dev, irq, tegra_hsp_shared_irq, 0, in tegra_hsp_request_shared_irq()
618 dev_name(hsp->dev), hsp); in tegra_hsp_request_shared_irq()
620 dev_err(hsp->dev, "failed to request interrupt: %d\n", in tegra_hsp_request_shared_irq()
625 hsp->shared_irq = i; in tegra_hsp_request_shared_irq()
628 tegra_hsp_writel(hsp, 0, HSP_INT_IE(hsp->shared_irq)); in tegra_hsp_request_shared_irq()
630 dev_dbg(hsp->dev, "interrupt requested: %u\n", irq); in tegra_hsp_request_shared_irq()
635 if (i == hsp->num_si) { in tegra_hsp_request_shared_irq()
636 dev_err(hsp->dev, "failed to find available interrupt\n"); in tegra_hsp_request_shared_irq()
637 return -ENOENT; in tegra_hsp_request_shared_irq()
651 hsp = devm_kzalloc(&pdev->dev, sizeof(*hsp), GFP_KERNEL); in tegra_hsp_probe()
653 return -ENOMEM; in tegra_hsp_probe()
655 hsp->dev = &pdev->dev; in tegra_hsp_probe()
656 hsp->soc = of_device_get_match_data(&pdev->dev); in tegra_hsp_probe()
657 INIT_LIST_HEAD(&hsp->doorbells); in tegra_hsp_probe()
658 spin_lock_init(&hsp->lock); in tegra_hsp_probe()
661 hsp->regs = devm_ioremap_resource(&pdev->dev, res); in tegra_hsp_probe()
662 if (IS_ERR(hsp->regs)) in tegra_hsp_probe()
663 return PTR_ERR(hsp->regs); in tegra_hsp_probe()
666 hsp->num_sm = (value >> HSP_nSM_SHIFT) & HSP_nINT_MASK; in tegra_hsp_probe()
667 hsp->num_ss = (value >> HSP_nSS_SHIFT) & HSP_nINT_MASK; in tegra_hsp_probe()
668 hsp->num_as = (value >> HSP_nAS_SHIFT) & HSP_nINT_MASK; in tegra_hsp_probe()
669 hsp->num_db = (value >> HSP_nDB_SHIFT) & HSP_nINT_MASK; in tegra_hsp_probe()
670 hsp->num_si = (value >> HSP_nSI_SHIFT) & HSP_nINT_MASK; in tegra_hsp_probe()
674 hsp->doorbell_irq = err; in tegra_hsp_probe()
676 if (hsp->num_si > 0) { in tegra_hsp_probe()
679 hsp->shared_irqs = devm_kcalloc(&pdev->dev, hsp->num_si, in tegra_hsp_probe()
680 sizeof(*hsp->shared_irqs), in tegra_hsp_probe()
682 if (!hsp->shared_irqs) in tegra_hsp_probe()
683 return -ENOMEM; in tegra_hsp_probe()
685 for (i = 0; i < hsp->num_si; i++) { in tegra_hsp_probe()
690 return -ENOMEM; in tegra_hsp_probe()
694 hsp->shared_irqs[i] = err; in tegra_hsp_probe()
702 devm_kfree(&pdev->dev, hsp->shared_irqs); in tegra_hsp_probe()
703 hsp->shared_irqs = NULL; in tegra_hsp_probe()
708 hsp->mbox_db.of_xlate = tegra_hsp_db_xlate; in tegra_hsp_probe()
709 hsp->mbox_db.num_chans = 32; in tegra_hsp_probe()
710 hsp->mbox_db.dev = &pdev->dev; in tegra_hsp_probe()
711 hsp->mbox_db.ops = &tegra_hsp_db_ops; in tegra_hsp_probe()
713 hsp->mbox_db.chans = devm_kcalloc(&pdev->dev, hsp->mbox_db.num_chans, in tegra_hsp_probe()
714 sizeof(*hsp->mbox_db.chans), in tegra_hsp_probe()
716 if (!hsp->mbox_db.chans) in tegra_hsp_probe()
717 return -ENOMEM; in tegra_hsp_probe()
719 if (hsp->doorbell_irq) { in tegra_hsp_probe()
722 dev_err(&pdev->dev, "failed to add doorbells: %d\n", in tegra_hsp_probe()
728 err = devm_mbox_controller_register(&pdev->dev, &hsp->mbox_db); in tegra_hsp_probe()
730 dev_err(&pdev->dev, "failed to register doorbell mailbox: %d\n", in tegra_hsp_probe()
736 hsp->mbox_sm.of_xlate = tegra_hsp_sm_xlate; in tegra_hsp_probe()
737 hsp->mbox_sm.num_chans = hsp->num_sm; in tegra_hsp_probe()
738 hsp->mbox_sm.dev = &pdev->dev; in tegra_hsp_probe()
739 hsp->mbox_sm.ops = &tegra_hsp_sm_ops; in tegra_hsp_probe()
741 hsp->mbox_sm.chans = devm_kcalloc(&pdev->dev, hsp->mbox_sm.num_chans, in tegra_hsp_probe()
742 sizeof(*hsp->mbox_sm.chans), in tegra_hsp_probe()
744 if (!hsp->mbox_sm.chans) in tegra_hsp_probe()
745 return -ENOMEM; in tegra_hsp_probe()
747 if (hsp->shared_irqs) { in tegra_hsp_probe()
748 err = tegra_hsp_add_mailboxes(hsp, &pdev->dev); in tegra_hsp_probe()
750 dev_err(&pdev->dev, "failed to add mailboxes: %d\n", in tegra_hsp_probe()
756 err = devm_mbox_controller_register(&pdev->dev, &hsp->mbox_sm); in tegra_hsp_probe()
758 dev_err(&pdev->dev, "failed to register shared mailbox: %d\n", in tegra_hsp_probe()
765 if (hsp->doorbell_irq) { in tegra_hsp_probe()
766 err = devm_request_irq(&pdev->dev, hsp->doorbell_irq, in tegra_hsp_probe()
768 dev_name(&pdev->dev), hsp); in tegra_hsp_probe()
770 dev_err(&pdev->dev, in tegra_hsp_probe()
772 hsp->doorbell_irq, err); in tegra_hsp_probe()
777 if (hsp->shared_irqs) { in tegra_hsp_probe()
792 list_for_each_entry(db, &hsp->doorbells, list) { in tegra_hsp_resume()
793 if (db && db->channel.chan) in tegra_hsp_resume()
794 tegra_hsp_doorbell_startup(db->channel.chan); in tegra_hsp_resume()
797 if (hsp->mailboxes) { in tegra_hsp_resume()
798 for (i = 0; i < hsp->num_sm; i++) { in tegra_hsp_resume()
799 struct tegra_hsp_mailbox *mb = &hsp->mailboxes[i]; in tegra_hsp_resume()
801 if (mb->channel.chan->cl) in tegra_hsp_resume()
802 tegra_hsp_mailbox_startup(mb->channel.chan); in tegra_hsp_resume()
814 { "ccplex", TEGRA_HSP_DB_MASTER_CCPLEX, HSP_DB_CCPLEX, },
830 { .compatible = "nvidia,tegra186-hsp", .data = &tegra186_hsp_soc },
831 { .compatible = "nvidia,tegra194-hsp", .data = &tegra194_hsp_soc },
837 .name = "tegra-hsp",