Lines Matching full:mhu
162 * @mbox: Mailbox controller belonging to the MHU frame.
207 int (*rx_startup)(struct mhuv2 *mhu, struct mbox_chan *chan);
208 void (*rx_shutdown)(struct mhuv2 *mhu, struct mbox_chan *chan);
209 void *(*read_data)(struct mhuv2 *mhu, struct mbox_chan *chan);
211 void (*tx_startup)(struct mhuv2 *mhu, struct mbox_chan *chan);
212 void (*tx_shutdown)(struct mhuv2 *mhu, struct mbox_chan *chan);
213 int (*last_tx_done)(struct mhuv2 *mhu, struct mbox_chan *chan);
214 int (*send_data)(struct mhuv2 *mhu, struct mbox_chan *chan, void *arg);
261 static int mhuv2_doorbell_rx_startup(struct mhuv2 *mhu, struct mbox_chan *chan) in mhuv2_doorbell_rx_startup() argument
266 &mhu->recv->ch_wn[priv->ch_wn_idx].mask_clear); in mhuv2_doorbell_rx_startup()
270 static void mhuv2_doorbell_rx_shutdown(struct mhuv2 *mhu, in mhuv2_doorbell_rx_shutdown() argument
276 &mhu->recv->ch_wn[priv->ch_wn_idx].mask_set); in mhuv2_doorbell_rx_shutdown()
279 static void *mhuv2_doorbell_read_data(struct mhuv2 *mhu, struct mbox_chan *chan) in mhuv2_doorbell_read_data() argument
284 &mhu->recv->ch_wn[priv->ch_wn_idx].stat_clear); in mhuv2_doorbell_read_data()
288 static int mhuv2_doorbell_last_tx_done(struct mhuv2 *mhu, in mhuv2_doorbell_last_tx_done() argument
293 return !(readl_relaxed(&mhu->send->ch_wn[priv->ch_wn_idx].stat) & in mhuv2_doorbell_last_tx_done()
297 static int mhuv2_doorbell_send_data(struct mhuv2 *mhu, struct mbox_chan *chan, in mhuv2_doorbell_send_data() argument
303 spin_lock_irqsave(&mhu->doorbell_pending_lock, flags); in mhuv2_doorbell_send_data()
307 &mhu->send->ch_wn[priv->ch_wn_idx].stat_set); in mhuv2_doorbell_send_data()
309 spin_unlock_irqrestore(&mhu->doorbell_pending_lock, flags); in mhuv2_doorbell_send_data()
325 static int mhuv2_data_transfer_rx_startup(struct mhuv2 *mhu, in mhuv2_data_transfer_rx_startup() argument
335 writel_relaxed(0xFFFFFFFF, &mhu->recv->ch_wn[i].mask_clear); in mhuv2_data_transfer_rx_startup()
339 static void mhuv2_data_transfer_rx_shutdown(struct mhuv2 *mhu, in mhuv2_data_transfer_rx_shutdown() argument
345 writel_relaxed(0xFFFFFFFF, &mhu->recv->ch_wn[i].mask_set); in mhuv2_data_transfer_rx_shutdown()
348 static void *mhuv2_data_transfer_read_data(struct mhuv2 *mhu, in mhuv2_data_transfer_read_data() argument
378 data[windows - 1 - i] = readl_relaxed(&mhu->recv->ch_wn[idx].stat); in mhuv2_data_transfer_read_data()
379 writel_relaxed(0xFFFFFFFF, &mhu->recv->ch_wn[idx].stat_clear); in mhuv2_data_transfer_read_data()
385 static void mhuv2_data_transfer_tx_startup(struct mhuv2 *mhu, in mhuv2_data_transfer_tx_startup() argument
392 if (mhu->minor) { in mhuv2_data_transfer_tx_startup()
393 writel_relaxed(0x1, &mhu->send->ch_wn[i].int_clr); in mhuv2_data_transfer_tx_startup()
394 writel_relaxed(0x1, &mhu->send->ch_wn[i].int_en); in mhuv2_data_transfer_tx_startup()
398 static void mhuv2_data_transfer_tx_shutdown(struct mhuv2 *mhu, in mhuv2_data_transfer_tx_shutdown() argument
404 if (mhu->minor) in mhuv2_data_transfer_tx_shutdown()
405 writel_relaxed(0x0, &mhu->send->ch_wn[i].int_en); in mhuv2_data_transfer_tx_shutdown()
408 static int mhuv2_data_transfer_last_tx_done(struct mhuv2 *mhu, in mhuv2_data_transfer_last_tx_done() argument
415 return !readl_relaxed(&mhu->send->ch_wn[i].stat); in mhuv2_data_transfer_last_tx_done()
422 * written. As an example, a 6-word message is to be written on a 4-channel MHU
445 static int mhuv2_data_transfer_send_data(struct mhuv2 *mhu, in mhuv2_data_transfer_send_data() argument
456 …dev_err(mhu->mbox.dev, "Data aligned at first window can't be zero to guarantee interrupt generati… in mhuv2_data_transfer_send_data()
460 while(!mhuv2_data_transfer_last_tx_done(mhu, chan)) in mhuv2_data_transfer_send_data()
477 writel_relaxed(word, &mhu->send->ch_wn[priv->ch_wn_idx + windows - 1 - i].stat_set); in mhuv2_data_transfer_send_data()
500 static struct mbox_chan *get_irq_chan_comb(struct mhuv2 *mhu, u32 __iomem *reg) in get_irq_chan_comb() argument
502 struct mbox_chan *chans = mhu->mbox.chans; in get_irq_chan_comb()
513 for (i = 0; i < mhu->length; i += 2) { in get_irq_chan_comb()
514 protocol = mhu->protocols[i]; in get_irq_chan_comb()
515 windows = mhu->protocols[i + 1]; in get_irq_chan_comb()
540 struct mhuv2 *mhu = data; in mhuv2_sender_interrupt() local
541 struct device *dev = mhu->mbox.dev; in mhuv2_sender_interrupt()
548 chan = get_irq_chan_comb(mhu, mhu->send->chcomb_int_st); in mhuv2_sender_interrupt()
557 writel_relaxed(1, &mhu->send->ch_wn[priv->ch_wn_idx + i].int_clr); in mhuv2_sender_interrupt()
570 writel_relaxed(1, &mhu->send->ch_wn[priv->ch_wn_idx].int_clr); in mhuv2_sender_interrupt()
578 spin_lock_irqsave(&mhu->doorbell_pending_lock, flags); in mhuv2_sender_interrupt()
584 stat = readl_relaxed(&mhu->send->ch_wn[priv->ch_wn_idx].stat); in mhuv2_sender_interrupt()
605 spin_unlock_irqrestore(&mhu->doorbell_pending_lock, flags); in mhuv2_sender_interrupt()
621 static struct mbox_chan *get_irq_chan_comb_rx(struct mhuv2 *mhu) in get_irq_chan_comb_rx() argument
627 chan = get_irq_chan_comb(mhu, mhu->recv->chcomb_int_st); in get_irq_chan_comb_rx()
639 stat = readl_relaxed(&mhu->recv->ch_wn[priv->ch_wn_idx].stat_masked); in get_irq_chan_comb_rx()
645 static struct mbox_chan *get_irq_chan_stat_rx(struct mhuv2 *mhu) in get_irq_chan_stat_rx() argument
647 struct mbox_chan *chans = mhu->mbox.chans; in get_irq_chan_stat_rx()
652 while (i < mhu->mbox.num_chans) { in get_irq_chan_stat_rx()
654 stat = readl_relaxed(&mhu->recv->ch_wn[priv->ch_wn_idx].stat_masked); in get_irq_chan_stat_rx()
668 static struct mbox_chan *get_irq_chan_rx(struct mhuv2 *mhu) in get_irq_chan_rx() argument
670 if (!mhu->minor) in get_irq_chan_rx()
671 return get_irq_chan_stat_rx(mhu); in get_irq_chan_rx()
673 return get_irq_chan_comb_rx(mhu); in get_irq_chan_rx()
678 struct mhuv2 *mhu = arg; in mhuv2_receiver_interrupt() local
679 struct mbox_chan *chan = get_irq_chan_rx(mhu); in mhuv2_receiver_interrupt()
680 struct device *dev = mhu->mbox.dev; in mhuv2_receiver_interrupt()
692 data = priv->ops->read_data(mhu, chan); in mhuv2_receiver_interrupt()
713 struct mhuv2 *mhu = mhu_from_mbox(chan->mbox); in mhuv2_sender_last_tx_done() local
716 return priv->ops->last_tx_done(mhu, chan); in mhuv2_sender_last_tx_done()
721 struct mhuv2 *mhu = mhu_from_mbox(chan->mbox); in mhuv2_sender_send_data() local
724 if (!priv->ops->last_tx_done(mhu, chan)) in mhuv2_sender_send_data()
727 return priv->ops->send_data(mhu, chan, data); in mhuv2_sender_send_data()
732 struct mhuv2 *mhu = mhu_from_mbox(chan->mbox); in mhuv2_sender_startup() local
736 priv->ops->tx_startup(mhu, chan); in mhuv2_sender_startup()
742 struct mhuv2 *mhu = mhu_from_mbox(chan->mbox); in mhuv2_sender_shutdown() local
746 priv->ops->tx_shutdown(mhu, chan); in mhuv2_sender_shutdown()
758 struct mhuv2 *mhu = mhu_from_mbox(chan->mbox); in mhuv2_receiver_startup() local
761 return priv->ops->rx_startup(mhu, chan); in mhuv2_receiver_startup()
766 struct mhuv2 *mhu = mhu_from_mbox(chan->mbox); in mhuv2_receiver_shutdown() local
769 priv->ops->rx_shutdown(mhu, chan); in mhuv2_receiver_shutdown()
775 "Trying to transmit on a receiver MHU frame\n"); in mhuv2_receiver_send_data()
781 dev_err(chan->mbox->dev, "Trying to Tx poll on a receiver MHU frame\n"); in mhuv2_receiver_last_tx_done()
795 struct mhuv2 *mhu = mhu_from_mbox(mbox); in mhuv2_mbox_of_xlate() local
807 for (i = 0; i < mhu->length; i += 2) { in mhuv2_mbox_of_xlate()
808 protocol = mhu->protocols[i]; in mhuv2_mbox_of_xlate()
809 windows = mhu->protocols[i + 1]; in mhuv2_mbox_of_xlate()
836 static int mhuv2_verify_protocol(struct mhuv2 *mhu) in mhuv2_verify_protocol() argument
838 struct device *dev = mhu->mbox.dev; in mhuv2_verify_protocol()
841 for (i = 0; i < mhu->length; i += 2) { in mhuv2_verify_protocol()
842 protocol = mhu->protocols[i]; in mhuv2_verify_protocol()
843 windows = mhu->protocols[i + 1]; in mhuv2_verify_protocol()
862 if (total_windows > mhu->windows) { in mhuv2_verify_protocol()
864 total_windows, mhu->windows); in mhuv2_verify_protocol()
868 mhu->mbox.num_chans = channels; in mhuv2_verify_protocol()
872 static int mhuv2_allocate_channels(struct mhuv2 *mhu) in mhuv2_allocate_channels() argument
874 struct mbox_controller *mbox = &mhu->mbox; in mhuv2_allocate_channels()
886 for (i = 0; i < mhu->length; i += 2) { in mhuv2_allocate_channels()
889 protocol = mhu->protocols[i]; in mhuv2_allocate_channels()
890 windows = mhu->protocols[i + 1]; in mhuv2_allocate_channels()
920 if (mhu->frame == SENDER_FRAME && mhu->minor) in mhuv2_allocate_channels()
921 writel_relaxed(0x1, &mhu->send->ch_wn[priv->ch_wn_idx].int_en); in mhuv2_allocate_channels()
931 static int mhuv2_parse_channels(struct mhuv2 *mhu) in mhuv2_parse_channels() argument
933 struct device *dev = mhu->mbox.dev; in mhuv2_parse_channels()
956 mhu->protocols = protocols; in mhuv2_parse_channels()
957 mhu->length = count; in mhuv2_parse_channels()
959 ret = mhuv2_verify_protocol(mhu); in mhuv2_parse_channels()
963 return mhuv2_allocate_channels(mhu); in mhuv2_parse_channels()
966 static int mhuv2_tx_init(struct amba_device *adev, struct mhuv2 *mhu, in mhuv2_tx_init() argument
969 struct device *dev = mhu->mbox.dev; in mhuv2_tx_init()
972 mhu->frame = SENDER_FRAME; in mhuv2_tx_init()
973 mhu->mbox.ops = &mhuv2_sender_ops; in mhuv2_tx_init()
974 mhu->send = reg; in mhuv2_tx_init()
976 mhu->windows = readl_relaxed_bitfield(&mhu->send->mhu_cfg, struct mhu_cfg_t, num_ch); in mhuv2_tx_init()
977 mhu->minor = readl_relaxed_bitfield(&mhu->send->aidr, struct aidr_t, arch_minor_rev); in mhuv2_tx_init()
979 spin_lock_init(&mhu->doorbell_pending_lock); in mhuv2_tx_init()
985 if (mhu->minor && adev->irq[0]) { in mhuv2_tx_init()
988 IRQF_ONESHOT, "mhuv2-tx", mhu); in mhuv2_tx_init()
993 mhu->mbox.txdone_irq = true; in mhuv2_tx_init()
994 mhu->mbox.txdone_poll = false; in mhuv2_tx_init()
995 mhu->irq = adev->irq[0]; in mhuv2_tx_init()
997 writel_relaxed_bitfield(1, &mhu->send->int_en, struct int_en_t, chcomb); in mhuv2_tx_init()
1000 for (i = 0; i < mhu->windows; i++) in mhuv2_tx_init()
1001 writel_relaxed(0x0, &mhu->send->ch_wn[i].int_en); in mhuv2_tx_init()
1007 mhu->mbox.txdone_irq = false; in mhuv2_tx_init()
1008 mhu->mbox.txdone_poll = true; in mhuv2_tx_init()
1009 mhu->mbox.txpoll_period = 1; in mhuv2_tx_init()
1013 writel_relaxed(0x1, &mhu->send->access_request); in mhuv2_tx_init()
1014 while (!readl_relaxed(&mhu->send->access_ready)) in mhuv2_tx_init()
1020 static int mhuv2_rx_init(struct amba_device *adev, struct mhuv2 *mhu, in mhuv2_rx_init() argument
1023 struct device *dev = mhu->mbox.dev; in mhuv2_rx_init()
1026 mhu->frame = RECEIVER_FRAME; in mhuv2_rx_init()
1027 mhu->mbox.ops = &mhuv2_receiver_ops; in mhuv2_rx_init()
1028 mhu->recv = reg; in mhuv2_rx_init()
1030 mhu->windows = readl_relaxed_bitfield(&mhu->recv->mhu_cfg, struct mhu_cfg_t, num_ch); in mhuv2_rx_init()
1031 mhu->minor = readl_relaxed_bitfield(&mhu->recv->aidr, struct aidr_t, arch_minor_rev); in mhuv2_rx_init()
1033 mhu->irq = adev->irq[0]; in mhuv2_rx_init()
1034 if (!mhu->irq) { in mhuv2_rx_init()
1039 ret = devm_request_threaded_irq(dev, mhu->irq, NULL, in mhuv2_rx_init()
1041 "mhuv2-rx", mhu); in mhuv2_rx_init()
1048 for (i = 0; i < mhu->windows; i++) in mhuv2_rx_init()
1049 writel_relaxed(0xFFFFFFFF, &mhu->recv->ch_wn[i].mask_set); in mhuv2_rx_init()
1051 if (mhu->minor) in mhuv2_rx_init()
1052 writel_relaxed_bitfield(1, &mhu->recv->int_en, struct int_en_t, chcomb); in mhuv2_rx_init()
1061 struct mhuv2 *mhu; in mhuv2_probe() local
1069 mhu = devm_kzalloc(dev, sizeof(*mhu), GFP_KERNEL); in mhuv2_probe()
1070 if (!mhu) in mhuv2_probe()
1073 mhu->mbox.dev = dev; in mhuv2_probe()
1074 mhu->mbox.of_xlate = mhuv2_mbox_of_xlate; in mhuv2_probe()
1077 ret = mhuv2_tx_init(adev, mhu, reg); in mhuv2_probe()
1079 ret = mhuv2_rx_init(adev, mhu, reg); in mhuv2_probe()
1087 BUG_ON(!mhu->windows); in mhuv2_probe()
1089 ret = mhuv2_parse_channels(mhu); in mhuv2_probe()
1093 amba_set_drvdata(adev, mhu); in mhuv2_probe()
1095 ret = devm_mbox_controller_register(dev, &mhu->mbox); in mhuv2_probe()
1104 struct mhuv2 *mhu = amba_get_drvdata(adev); in mhuv2_remove() local
1106 if (mhu->frame == SENDER_FRAME) in mhuv2_remove()
1107 writel_relaxed(0x0, &mhu->send->access_request); in mhuv2_remove()