2 * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 #include <linux/clk/tegra.h>
15 #include <linux/genalloc.h>
16 #include <linux/mailbox_client.h>
18 #include <linux/of_address.h>
19 #include <linux/of_device.h>
20 #include <linux/platform_device.h>
22 #include <linux/semaphore.h>
23 #include <linux/sched/clock.h>
25 #include <soc/tegra/bpmp.h>
26 #include <soc/tegra/bpmp-abi.h>
27 #include <soc/tegra/ivc.h>
29 #define MSG_ACK BIT(0)
30 #define MSG_RING BIT(1)
33 static inline struct tegra_bpmp
*
34 mbox_client_to_bpmp(struct mbox_client
*client
)
36 return container_of(client
, struct tegra_bpmp
, mbox
.client
);
39 struct tegra_bpmp
*tegra_bpmp_get(struct device
*dev
)
41 struct platform_device
*pdev
;
42 struct tegra_bpmp
*bpmp
;
43 struct device_node
*np
;
45 np
= of_parse_phandle(dev
->of_node
, "nvidia,bpmp", 0);
47 return ERR_PTR(-ENOENT
);
49 pdev
= of_find_device_by_node(np
);
51 bpmp
= ERR_PTR(-ENODEV
);
55 bpmp
= platform_get_drvdata(pdev
);
57 bpmp
= ERR_PTR(-EPROBE_DEFER
);
58 put_device(&pdev
->dev
);
66 EXPORT_SYMBOL_GPL(tegra_bpmp_get
);
68 void tegra_bpmp_put(struct tegra_bpmp
*bpmp
)
71 put_device(bpmp
->dev
);
73 EXPORT_SYMBOL_GPL(tegra_bpmp_put
);
76 tegra_bpmp_channel_get_thread_index(struct tegra_bpmp_channel
*channel
)
78 struct tegra_bpmp
*bpmp
= channel
->bpmp
;
82 count
= bpmp
->soc
->channels
.thread
.count
;
84 index
= channel
- channel
->bpmp
->threaded_channels
;
85 if (index
< 0 || index
>= count
)
91 static bool tegra_bpmp_message_valid(const struct tegra_bpmp_message
*msg
)
93 return (msg
->tx
.size
<= MSG_DATA_MIN_SZ
) &&
94 (msg
->rx
.size
<= MSG_DATA_MIN_SZ
) &&
95 (msg
->tx
.size
== 0 || msg
->tx
.data
) &&
96 (msg
->rx
.size
== 0 || msg
->rx
.data
);
99 static bool tegra_bpmp_master_acked(struct tegra_bpmp_channel
*channel
)
103 frame
= tegra_ivc_read_get_next_frame(channel
->ivc
);
114 static int tegra_bpmp_wait_ack(struct tegra_bpmp_channel
*channel
)
116 unsigned long timeout
= channel
->bpmp
->soc
->channels
.cpu_tx
.timeout
;
119 end
= ktime_add_us(ktime_get(), timeout
);
122 if (tegra_bpmp_master_acked(channel
))
124 } while (ktime_before(ktime_get(), end
));
129 static bool tegra_bpmp_master_free(struct tegra_bpmp_channel
*channel
)
133 frame
= tegra_ivc_write_get_next_frame(channel
->ivc
);
144 static int tegra_bpmp_wait_master_free(struct tegra_bpmp_channel
*channel
)
146 unsigned long timeout
= channel
->bpmp
->soc
->channels
.cpu_tx
.timeout
;
149 start
= ns_to_ktime(local_clock());
152 if (tegra_bpmp_master_free(channel
))
155 now
= ns_to_ktime(local_clock());
156 } while (ktime_us_delta(now
, start
) < timeout
);
161 static ssize_t
__tegra_bpmp_channel_read(struct tegra_bpmp_channel
*channel
,
162 void *data
, size_t size
, int *ret
)
166 if (data
&& size
> 0)
167 memcpy(data
, channel
->ib
->data
, size
);
169 err
= tegra_ivc_read_advance(channel
->ivc
);
173 *ret
= channel
->ib
->code
;
178 static ssize_t
tegra_bpmp_channel_read(struct tegra_bpmp_channel
*channel
,
179 void *data
, size_t size
, int *ret
)
181 struct tegra_bpmp
*bpmp
= channel
->bpmp
;
186 index
= tegra_bpmp_channel_get_thread_index(channel
);
192 spin_lock_irqsave(&bpmp
->lock
, flags
);
193 err
= __tegra_bpmp_channel_read(channel
, data
, size
, ret
);
194 clear_bit(index
, bpmp
->threaded
.allocated
);
195 spin_unlock_irqrestore(&bpmp
->lock
, flags
);
198 up(&bpmp
->threaded
.lock
);
203 static ssize_t
__tegra_bpmp_channel_write(struct tegra_bpmp_channel
*channel
,
204 unsigned int mrq
, unsigned long flags
,
205 const void *data
, size_t size
)
207 channel
->ob
->code
= mrq
;
208 channel
->ob
->flags
= flags
;
210 if (data
&& size
> 0)
211 memcpy(channel
->ob
->data
, data
, size
);
213 return tegra_ivc_write_advance(channel
->ivc
);
216 static struct tegra_bpmp_channel
*
217 tegra_bpmp_write_threaded(struct tegra_bpmp
*bpmp
, unsigned int mrq
,
218 const void *data
, size_t size
)
220 unsigned long timeout
= bpmp
->soc
->channels
.thread
.timeout
;
221 unsigned int count
= bpmp
->soc
->channels
.thread
.count
;
222 struct tegra_bpmp_channel
*channel
;
227 err
= down_timeout(&bpmp
->threaded
.lock
, usecs_to_jiffies(timeout
));
231 spin_lock_irqsave(&bpmp
->lock
, flags
);
233 index
= find_first_zero_bit(bpmp
->threaded
.allocated
, count
);
234 if (index
== count
) {
239 channel
= &bpmp
->threaded_channels
[index
];
241 if (!tegra_bpmp_master_free(channel
)) {
246 set_bit(index
, bpmp
->threaded
.allocated
);
248 err
= __tegra_bpmp_channel_write(channel
, mrq
, MSG_ACK
| MSG_RING
,
251 goto clear_allocated
;
253 set_bit(index
, bpmp
->threaded
.busy
);
255 spin_unlock_irqrestore(&bpmp
->lock
, flags
);
259 clear_bit(index
, bpmp
->threaded
.allocated
);
261 spin_unlock_irqrestore(&bpmp
->lock
, flags
);
262 up(&bpmp
->threaded
.lock
);
267 static ssize_t
tegra_bpmp_channel_write(struct tegra_bpmp_channel
*channel
,
268 unsigned int mrq
, unsigned long flags
,
269 const void *data
, size_t size
)
273 err
= tegra_bpmp_wait_master_free(channel
);
277 return __tegra_bpmp_channel_write(channel
, mrq
, flags
, data
, size
);
280 int tegra_bpmp_transfer_atomic(struct tegra_bpmp
*bpmp
,
281 struct tegra_bpmp_message
*msg
)
283 struct tegra_bpmp_channel
*channel
;
286 if (WARN_ON(!irqs_disabled()))
289 if (!tegra_bpmp_message_valid(msg
))
292 channel
= bpmp
->tx_channel
;
294 spin_lock(&bpmp
->atomic_tx_lock
);
296 err
= tegra_bpmp_channel_write(channel
, msg
->mrq
, MSG_ACK
,
297 msg
->tx
.data
, msg
->tx
.size
);
299 spin_unlock(&bpmp
->atomic_tx_lock
);
303 spin_unlock(&bpmp
->atomic_tx_lock
);
305 err
= mbox_send_message(bpmp
->mbox
.channel
, NULL
);
309 mbox_client_txdone(bpmp
->mbox
.channel
, 0);
311 err
= tegra_bpmp_wait_ack(channel
);
315 return __tegra_bpmp_channel_read(channel
, msg
->rx
.data
, msg
->rx
.size
,
318 EXPORT_SYMBOL_GPL(tegra_bpmp_transfer_atomic
);
320 int tegra_bpmp_transfer(struct tegra_bpmp
*bpmp
,
321 struct tegra_bpmp_message
*msg
)
323 struct tegra_bpmp_channel
*channel
;
324 unsigned long timeout
;
327 if (WARN_ON(irqs_disabled()))
330 if (!tegra_bpmp_message_valid(msg
))
333 channel
= tegra_bpmp_write_threaded(bpmp
, msg
->mrq
, msg
->tx
.data
,
336 return PTR_ERR(channel
);
338 err
= mbox_send_message(bpmp
->mbox
.channel
, NULL
);
342 mbox_client_txdone(bpmp
->mbox
.channel
, 0);
344 timeout
= usecs_to_jiffies(bpmp
->soc
->channels
.thread
.timeout
);
346 err
= wait_for_completion_timeout(&channel
->completion
, timeout
);
350 return tegra_bpmp_channel_read(channel
, msg
->rx
.data
, msg
->rx
.size
,
353 EXPORT_SYMBOL_GPL(tegra_bpmp_transfer
);
355 static struct tegra_bpmp_mrq
*tegra_bpmp_find_mrq(struct tegra_bpmp
*bpmp
,
358 struct tegra_bpmp_mrq
*entry
;
360 list_for_each_entry(entry
, &bpmp
->mrqs
, list
)
361 if (entry
->mrq
== mrq
)
367 void tegra_bpmp_mrq_return(struct tegra_bpmp_channel
*channel
, int code
,
368 const void *data
, size_t size
)
370 unsigned long flags
= channel
->ib
->flags
;
371 struct tegra_bpmp
*bpmp
= channel
->bpmp
;
372 struct tegra_bpmp_mb_data
*frame
;
375 if (WARN_ON(size
> MSG_DATA_MIN_SZ
))
378 err
= tegra_ivc_read_advance(channel
->ivc
);
379 if (WARN_ON(err
< 0))
382 if ((flags
& MSG_ACK
) == 0)
385 frame
= tegra_ivc_write_get_next_frame(channel
->ivc
);
386 if (WARN_ON(IS_ERR(frame
)))
391 if (data
&& size
> 0)
392 memcpy(frame
->data
, data
, size
);
394 err
= tegra_ivc_write_advance(channel
->ivc
);
395 if (WARN_ON(err
< 0))
398 if (flags
& MSG_RING
) {
399 err
= mbox_send_message(bpmp
->mbox
.channel
, NULL
);
400 if (WARN_ON(err
< 0))
403 mbox_client_txdone(bpmp
->mbox
.channel
, 0);
406 EXPORT_SYMBOL_GPL(tegra_bpmp_mrq_return
);
408 static void tegra_bpmp_handle_mrq(struct tegra_bpmp
*bpmp
,
410 struct tegra_bpmp_channel
*channel
)
412 struct tegra_bpmp_mrq
*entry
;
415 spin_lock(&bpmp
->lock
);
417 entry
= tegra_bpmp_find_mrq(bpmp
, mrq
);
419 spin_unlock(&bpmp
->lock
);
420 tegra_bpmp_mrq_return(channel
, -EINVAL
, &zero
, sizeof(zero
));
424 entry
->handler(mrq
, channel
, entry
->data
);
426 spin_unlock(&bpmp
->lock
);
429 int tegra_bpmp_request_mrq(struct tegra_bpmp
*bpmp
, unsigned int mrq
,
430 tegra_bpmp_mrq_handler_t handler
, void *data
)
432 struct tegra_bpmp_mrq
*entry
;
438 entry
= devm_kzalloc(bpmp
->dev
, sizeof(*entry
), GFP_KERNEL
);
442 spin_lock_irqsave(&bpmp
->lock
, flags
);
445 entry
->handler
= handler
;
447 list_add(&entry
->list
, &bpmp
->mrqs
);
449 spin_unlock_irqrestore(&bpmp
->lock
, flags
);
453 EXPORT_SYMBOL_GPL(tegra_bpmp_request_mrq
);
455 void tegra_bpmp_free_mrq(struct tegra_bpmp
*bpmp
, unsigned int mrq
, void *data
)
457 struct tegra_bpmp_mrq
*entry
;
460 spin_lock_irqsave(&bpmp
->lock
, flags
);
462 entry
= tegra_bpmp_find_mrq(bpmp
, mrq
);
466 list_del(&entry
->list
);
467 devm_kfree(bpmp
->dev
, entry
);
470 spin_unlock_irqrestore(&bpmp
->lock
, flags
);
472 EXPORT_SYMBOL_GPL(tegra_bpmp_free_mrq
);
474 bool tegra_bpmp_mrq_is_supported(struct tegra_bpmp
*bpmp
, unsigned int mrq
)
476 struct mrq_query_abi_request req
= { .mrq
= cpu_to_le32(mrq
) };
477 struct mrq_query_abi_response resp
;
478 struct tegra_bpmp_message msg
= {
479 .mrq
= MRQ_QUERY_ABI
,
486 .size
= sizeof(resp
),
491 ret
= tegra_bpmp_transfer(bpmp
, &msg
);
492 if (ret
|| msg
.rx
.ret
)
495 return resp
.status
== 0;
497 EXPORT_SYMBOL_GPL(tegra_bpmp_mrq_is_supported
);
499 static void tegra_bpmp_mrq_handle_ping(unsigned int mrq
,
500 struct tegra_bpmp_channel
*channel
,
503 struct mrq_ping_request
*request
;
504 struct mrq_ping_response response
;
506 request
= (struct mrq_ping_request
*)channel
->ib
->data
;
508 memset(&response
, 0, sizeof(response
));
509 response
.reply
= request
->challenge
<< 1;
511 tegra_bpmp_mrq_return(channel
, 0, &response
, sizeof(response
));
514 static int tegra_bpmp_ping(struct tegra_bpmp
*bpmp
)
516 struct mrq_ping_response response
;
517 struct mrq_ping_request request
;
518 struct tegra_bpmp_message msg
;
523 memset(&request
, 0, sizeof(request
));
524 request
.challenge
= 1;
526 memset(&response
, 0, sizeof(response
));
528 memset(&msg
, 0, sizeof(msg
));
530 msg
.tx
.data
= &request
;
531 msg
.tx
.size
= sizeof(request
);
532 msg
.rx
.data
= &response
;
533 msg
.rx
.size
= sizeof(response
);
535 local_irq_save(flags
);
537 err
= tegra_bpmp_transfer_atomic(bpmp
, &msg
);
539 local_irq_restore(flags
);
543 "ping ok: challenge: %u, response: %u, time: %lld\n",
544 request
.challenge
, response
.reply
,
545 ktime_to_us(ktime_sub(end
, start
)));
550 /* deprecated version of tag query */
551 static int tegra_bpmp_get_firmware_tag_old(struct tegra_bpmp
*bpmp
, char *tag
,
554 struct mrq_query_tag_request request
;
555 struct tegra_bpmp_message msg
;
564 virt
= dma_alloc_coherent(bpmp
->dev
, TAG_SZ
, &phys
,
565 GFP_KERNEL
| GFP_DMA32
);
569 memset(&request
, 0, sizeof(request
));
572 memset(&msg
, 0, sizeof(msg
));
573 msg
.mrq
= MRQ_QUERY_TAG
;
574 msg
.tx
.data
= &request
;
575 msg
.tx
.size
= sizeof(request
);
577 local_irq_save(flags
);
578 err
= tegra_bpmp_transfer_atomic(bpmp
, &msg
);
579 local_irq_restore(flags
);
582 memcpy(tag
, virt
, TAG_SZ
);
584 dma_free_coherent(bpmp
->dev
, TAG_SZ
, virt
, phys
);
589 static int tegra_bpmp_get_firmware_tag(struct tegra_bpmp
*bpmp
, char *tag
,
592 if (tegra_bpmp_mrq_is_supported(bpmp
, MRQ_QUERY_FW_TAG
)) {
593 struct mrq_query_fw_tag_response resp
;
594 struct tegra_bpmp_message msg
= {
595 .mrq
= MRQ_QUERY_FW_TAG
,
598 .size
= sizeof(resp
),
603 if (size
!= sizeof(resp
.tag
))
606 err
= tegra_bpmp_transfer(bpmp
, &msg
);
613 memcpy(tag
, resp
.tag
, sizeof(resp
.tag
));
617 return tegra_bpmp_get_firmware_tag_old(bpmp
, tag
, size
);
620 static void tegra_bpmp_channel_signal(struct tegra_bpmp_channel
*channel
)
622 unsigned long flags
= channel
->ob
->flags
;
624 if ((flags
& MSG_RING
) == 0)
627 complete(&channel
->completion
);
630 static void tegra_bpmp_handle_rx(struct mbox_client
*client
, void *data
)
632 struct tegra_bpmp
*bpmp
= mbox_client_to_bpmp(client
);
633 struct tegra_bpmp_channel
*channel
;
634 unsigned int i
, count
;
637 channel
= bpmp
->rx_channel
;
638 count
= bpmp
->soc
->channels
.thread
.count
;
639 busy
= bpmp
->threaded
.busy
;
641 if (tegra_bpmp_master_acked(channel
))
642 tegra_bpmp_handle_mrq(bpmp
, channel
->ib
->code
, channel
);
644 spin_lock(&bpmp
->lock
);
646 for_each_set_bit(i
, busy
, count
) {
647 struct tegra_bpmp_channel
*channel
;
649 channel
= &bpmp
->threaded_channels
[i
];
651 if (tegra_bpmp_master_acked(channel
)) {
652 tegra_bpmp_channel_signal(channel
);
657 spin_unlock(&bpmp
->lock
);
660 static void tegra_bpmp_ivc_notify(struct tegra_ivc
*ivc
, void *data
)
662 struct tegra_bpmp
*bpmp
= data
;
665 if (WARN_ON(bpmp
->mbox
.channel
== NULL
))
668 err
= mbox_send_message(bpmp
->mbox
.channel
, NULL
);
672 mbox_client_txdone(bpmp
->mbox
.channel
, 0);
675 static int tegra_bpmp_channel_init(struct tegra_bpmp_channel
*channel
,
676 struct tegra_bpmp
*bpmp
,
679 size_t message_size
, queue_size
;
683 channel
->ivc
= devm_kzalloc(bpmp
->dev
, sizeof(*channel
->ivc
),
688 message_size
= tegra_ivc_align(MSG_MIN_SZ
);
689 queue_size
= tegra_ivc_total_queue_size(message_size
);
690 offset
= queue_size
* index
;
692 err
= tegra_ivc_init(channel
->ivc
, NULL
,
693 bpmp
->rx
.virt
+ offset
, bpmp
->rx
.phys
+ offset
,
694 bpmp
->tx
.virt
+ offset
, bpmp
->tx
.phys
+ offset
,
695 1, message_size
, tegra_bpmp_ivc_notify
,
698 dev_err(bpmp
->dev
, "failed to setup IVC for channel %u: %d\n",
703 init_completion(&channel
->completion
);
704 channel
->bpmp
= bpmp
;
709 static void tegra_bpmp_channel_reset(struct tegra_bpmp_channel
*channel
)
711 /* reset the channel state */
712 tegra_ivc_reset(channel
->ivc
);
714 /* sync the channel state with BPMP */
715 while (tegra_ivc_notified(channel
->ivc
))
719 static void tegra_bpmp_channel_cleanup(struct tegra_bpmp_channel
*channel
)
721 tegra_ivc_cleanup(channel
->ivc
);
724 static int tegra_bpmp_probe(struct platform_device
*pdev
)
726 struct tegra_bpmp
*bpmp
;
732 bpmp
= devm_kzalloc(&pdev
->dev
, sizeof(*bpmp
), GFP_KERNEL
);
736 bpmp
->soc
= of_device_get_match_data(&pdev
->dev
);
737 bpmp
->dev
= &pdev
->dev
;
739 bpmp
->tx
.pool
= of_gen_pool_get(pdev
->dev
.of_node
, "shmem", 0);
740 if (!bpmp
->tx
.pool
) {
741 dev_err(&pdev
->dev
, "TX shmem pool not found\n");
745 bpmp
->tx
.virt
= gen_pool_dma_alloc(bpmp
->tx
.pool
, 4096, &bpmp
->tx
.phys
);
746 if (!bpmp
->tx
.virt
) {
747 dev_err(&pdev
->dev
, "failed to allocate from TX pool\n");
751 bpmp
->rx
.pool
= of_gen_pool_get(pdev
->dev
.of_node
, "shmem", 1);
752 if (!bpmp
->rx
.pool
) {
753 dev_err(&pdev
->dev
, "RX shmem pool not found\n");
758 bpmp
->rx
.virt
= gen_pool_dma_alloc(bpmp
->rx
.pool
, 4096, &bpmp
->rx
.phys
);
759 if (!bpmp
->rx
.virt
) {
760 dev_err(&pdev
->dev
, "failed to allocate from RX pool\n");
765 INIT_LIST_HEAD(&bpmp
->mrqs
);
766 spin_lock_init(&bpmp
->lock
);
768 bpmp
->threaded
.count
= bpmp
->soc
->channels
.thread
.count
;
769 sema_init(&bpmp
->threaded
.lock
, bpmp
->threaded
.count
);
771 size
= BITS_TO_LONGS(bpmp
->threaded
.count
) * sizeof(long);
773 bpmp
->threaded
.allocated
= devm_kzalloc(&pdev
->dev
, size
, GFP_KERNEL
);
774 if (!bpmp
->threaded
.allocated
) {
779 bpmp
->threaded
.busy
= devm_kzalloc(&pdev
->dev
, size
, GFP_KERNEL
);
780 if (!bpmp
->threaded
.busy
) {
785 spin_lock_init(&bpmp
->atomic_tx_lock
);
786 bpmp
->tx_channel
= devm_kzalloc(&pdev
->dev
, sizeof(*bpmp
->tx_channel
),
788 if (!bpmp
->tx_channel
) {
793 bpmp
->rx_channel
= devm_kzalloc(&pdev
->dev
, sizeof(*bpmp
->rx_channel
),
795 if (!bpmp
->rx_channel
) {
800 bpmp
->threaded_channels
= devm_kcalloc(&pdev
->dev
, bpmp
->threaded
.count
,
801 sizeof(*bpmp
->threaded_channels
),
803 if (!bpmp
->threaded_channels
) {
808 err
= tegra_bpmp_channel_init(bpmp
->tx_channel
, bpmp
,
809 bpmp
->soc
->channels
.cpu_tx
.offset
);
813 err
= tegra_bpmp_channel_init(bpmp
->rx_channel
, bpmp
,
814 bpmp
->soc
->channels
.cpu_rx
.offset
);
816 goto cleanup_tx_channel
;
818 for (i
= 0; i
< bpmp
->threaded
.count
; i
++) {
819 err
= tegra_bpmp_channel_init(
820 &bpmp
->threaded_channels
[i
], bpmp
,
821 bpmp
->soc
->channels
.thread
.offset
+ i
);
823 goto cleanup_threaded_channels
;
826 /* mbox registration */
827 bpmp
->mbox
.client
.dev
= &pdev
->dev
;
828 bpmp
->mbox
.client
.rx_callback
= tegra_bpmp_handle_rx
;
829 bpmp
->mbox
.client
.tx_block
= false;
830 bpmp
->mbox
.client
.knows_txdone
= false;
832 bpmp
->mbox
.channel
= mbox_request_channel(&bpmp
->mbox
.client
, 0);
833 if (IS_ERR(bpmp
->mbox
.channel
)) {
834 err
= PTR_ERR(bpmp
->mbox
.channel
);
835 dev_err(&pdev
->dev
, "failed to get HSP mailbox: %d\n", err
);
836 goto cleanup_threaded_channels
;
839 /* reset message channels */
840 tegra_bpmp_channel_reset(bpmp
->tx_channel
);
841 tegra_bpmp_channel_reset(bpmp
->rx_channel
);
842 for (i
= 0; i
< bpmp
->threaded
.count
; i
++)
843 tegra_bpmp_channel_reset(&bpmp
->threaded_channels
[i
]);
845 err
= tegra_bpmp_request_mrq(bpmp
, MRQ_PING
,
846 tegra_bpmp_mrq_handle_ping
, bpmp
);
850 err
= tegra_bpmp_ping(bpmp
);
852 dev_err(&pdev
->dev
, "failed to ping BPMP: %d\n", err
);
856 err
= tegra_bpmp_get_firmware_tag(bpmp
, tag
, sizeof(tag
));
858 dev_err(&pdev
->dev
, "failed to get firmware tag: %d\n", err
);
862 dev_info(&pdev
->dev
, "firmware: %.*s\n", (int)sizeof(tag
), tag
);
864 platform_set_drvdata(pdev
, bpmp
);
866 err
= of_platform_default_populate(pdev
->dev
.of_node
, NULL
, &pdev
->dev
);
870 err
= tegra_bpmp_init_clocks(bpmp
);
874 err
= tegra_bpmp_init_resets(bpmp
);
878 err
= tegra_bpmp_init_powergates(bpmp
);
882 err
= tegra_bpmp_init_debugfs(bpmp
);
884 dev_err(&pdev
->dev
, "debugfs initialization failed: %d\n", err
);
889 tegra_bpmp_free_mrq(bpmp
, MRQ_PING
, bpmp
);
891 mbox_free_channel(bpmp
->mbox
.channel
);
892 cleanup_threaded_channels
:
893 for (i
= 0; i
< bpmp
->threaded
.count
; i
++) {
894 if (bpmp
->threaded_channels
[i
].bpmp
)
895 tegra_bpmp_channel_cleanup(&bpmp
->threaded_channels
[i
]);
898 tegra_bpmp_channel_cleanup(bpmp
->rx_channel
);
900 tegra_bpmp_channel_cleanup(bpmp
->tx_channel
);
902 gen_pool_free(bpmp
->rx
.pool
, (unsigned long)bpmp
->rx
.virt
, 4096);
904 gen_pool_free(bpmp
->tx
.pool
, (unsigned long)bpmp
->tx
.virt
, 4096);
908 static int __maybe_unused
tegra_bpmp_resume(struct device
*dev
)
910 struct tegra_bpmp
*bpmp
= dev_get_drvdata(dev
);
913 /* reset message channels */
914 tegra_bpmp_channel_reset(bpmp
->tx_channel
);
915 tegra_bpmp_channel_reset(bpmp
->rx_channel
);
917 for (i
= 0; i
< bpmp
->threaded
.count
; i
++)
918 tegra_bpmp_channel_reset(&bpmp
->threaded_channels
[i
]);
923 static SIMPLE_DEV_PM_OPS(tegra_bpmp_pm_ops
, NULL
, tegra_bpmp_resume
);
925 static const struct tegra_bpmp_soc tegra186_soc
= {
929 .timeout
= 60 * USEC_PER_SEC
,
934 .timeout
= 600 * USEC_PER_SEC
,
944 static const struct of_device_id tegra_bpmp_match
[] = {
945 { .compatible
= "nvidia,tegra186-bpmp", .data
= &tegra186_soc
},
949 static struct platform_driver tegra_bpmp_driver
= {
951 .name
= "tegra-bpmp",
952 .of_match_table
= tegra_bpmp_match
,
953 .pm
= &tegra_bpmp_pm_ops
,
955 .probe
= tegra_bpmp_probe
,
958 static int __init
tegra_bpmp_init(void)
960 return platform_driver_register(&tegra_bpmp_driver
);
962 core_initcall(tegra_bpmp_init
);