dt-bindings: mtd: ingenic: Use standard ecc-engine property
[linux/fpc-iii.git] / drivers / firmware / tegra / bpmp.c
blobdd775e8ba5a02ff930d2153b7c65cd76cd43784c
1 /*
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
11 * more details.
14 #include <linux/clk/tegra.h>
15 #include <linux/genalloc.h>
16 #include <linux/mailbox_client.h>
17 #include <linux/of.h>
18 #include <linux/of_address.h>
19 #include <linux/of_device.h>
20 #include <linux/platform_device.h>
21 #include <linux/pm.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 #include "bpmp-private.h"
31 #define MSG_ACK BIT(0)
32 #define MSG_RING BIT(1)
33 #define TAG_SZ 32
35 static inline struct tegra_bpmp *
36 mbox_client_to_bpmp(struct mbox_client *client)
38 return container_of(client, struct tegra_bpmp, mbox.client);
41 static inline const struct tegra_bpmp_ops *
42 channel_to_ops(struct tegra_bpmp_channel *channel)
44 struct tegra_bpmp *bpmp = channel->bpmp;
46 return bpmp->soc->ops;
49 struct tegra_bpmp *tegra_bpmp_get(struct device *dev)
51 struct platform_device *pdev;
52 struct tegra_bpmp *bpmp;
53 struct device_node *np;
55 np = of_parse_phandle(dev->of_node, "nvidia,bpmp", 0);
56 if (!np)
57 return ERR_PTR(-ENOENT);
59 pdev = of_find_device_by_node(np);
60 if (!pdev) {
61 bpmp = ERR_PTR(-ENODEV);
62 goto put;
65 bpmp = platform_get_drvdata(pdev);
66 if (!bpmp) {
67 bpmp = ERR_PTR(-EPROBE_DEFER);
68 put_device(&pdev->dev);
69 goto put;
72 put:
73 of_node_put(np);
74 return bpmp;
76 EXPORT_SYMBOL_GPL(tegra_bpmp_get);
78 void tegra_bpmp_put(struct tegra_bpmp *bpmp)
80 if (bpmp)
81 put_device(bpmp->dev);
83 EXPORT_SYMBOL_GPL(tegra_bpmp_put);
85 static int
86 tegra_bpmp_channel_get_thread_index(struct tegra_bpmp_channel *channel)
88 struct tegra_bpmp *bpmp = channel->bpmp;
89 unsigned int count;
90 int index;
92 count = bpmp->soc->channels.thread.count;
94 index = channel - channel->bpmp->threaded_channels;
95 if (index < 0 || index >= count)
96 return -EINVAL;
98 return index;
101 static bool tegra_bpmp_message_valid(const struct tegra_bpmp_message *msg)
103 return (msg->tx.size <= MSG_DATA_MIN_SZ) &&
104 (msg->rx.size <= MSG_DATA_MIN_SZ) &&
105 (msg->tx.size == 0 || msg->tx.data) &&
106 (msg->rx.size == 0 || msg->rx.data);
109 static bool tegra_bpmp_is_response_ready(struct tegra_bpmp_channel *channel)
111 const struct tegra_bpmp_ops *ops = channel_to_ops(channel);
113 return ops->is_response_ready(channel);
116 static bool tegra_bpmp_is_request_ready(struct tegra_bpmp_channel *channel)
118 const struct tegra_bpmp_ops *ops = channel_to_ops(channel);
120 return ops->is_request_ready(channel);
123 static int tegra_bpmp_wait_response(struct tegra_bpmp_channel *channel)
125 unsigned long timeout = channel->bpmp->soc->channels.cpu_tx.timeout;
126 ktime_t end;
128 end = ktime_add_us(ktime_get(), timeout);
130 do {
131 if (tegra_bpmp_is_response_ready(channel))
132 return 0;
133 } while (ktime_before(ktime_get(), end));
135 return -ETIMEDOUT;
138 static int tegra_bpmp_ack_response(struct tegra_bpmp_channel *channel)
140 const struct tegra_bpmp_ops *ops = channel_to_ops(channel);
142 return ops->ack_response(channel);
145 static int tegra_bpmp_ack_request(struct tegra_bpmp_channel *channel)
147 const struct tegra_bpmp_ops *ops = channel_to_ops(channel);
149 return ops->ack_request(channel);
152 static bool
153 tegra_bpmp_is_request_channel_free(struct tegra_bpmp_channel *channel)
155 const struct tegra_bpmp_ops *ops = channel_to_ops(channel);
157 return ops->is_request_channel_free(channel);
160 static bool
161 tegra_bpmp_is_response_channel_free(struct tegra_bpmp_channel *channel)
163 const struct tegra_bpmp_ops *ops = channel_to_ops(channel);
165 return ops->is_response_channel_free(channel);
168 static int
169 tegra_bpmp_wait_request_channel_free(struct tegra_bpmp_channel *channel)
171 unsigned long timeout = channel->bpmp->soc->channels.cpu_tx.timeout;
172 ktime_t start, now;
174 start = ns_to_ktime(local_clock());
176 do {
177 if (tegra_bpmp_is_request_channel_free(channel))
178 return 0;
180 now = ns_to_ktime(local_clock());
181 } while (ktime_us_delta(now, start) < timeout);
183 return -ETIMEDOUT;
186 static int tegra_bpmp_post_request(struct tegra_bpmp_channel *channel)
188 const struct tegra_bpmp_ops *ops = channel_to_ops(channel);
190 return ops->post_request(channel);
193 static int tegra_bpmp_post_response(struct tegra_bpmp_channel *channel)
195 const struct tegra_bpmp_ops *ops = channel_to_ops(channel);
197 return ops->post_response(channel);
200 static int tegra_bpmp_ring_doorbell(struct tegra_bpmp *bpmp)
202 return bpmp->soc->ops->ring_doorbell(bpmp);
205 static ssize_t __tegra_bpmp_channel_read(struct tegra_bpmp_channel *channel,
206 void *data, size_t size, int *ret)
208 int err;
210 if (data && size > 0)
211 memcpy(data, channel->ib->data, size);
213 err = tegra_bpmp_ack_response(channel);
214 if (err < 0)
215 return err;
217 *ret = channel->ib->code;
219 return 0;
222 static ssize_t tegra_bpmp_channel_read(struct tegra_bpmp_channel *channel,
223 void *data, size_t size, int *ret)
225 struct tegra_bpmp *bpmp = channel->bpmp;
226 unsigned long flags;
227 ssize_t err;
228 int index;
230 index = tegra_bpmp_channel_get_thread_index(channel);
231 if (index < 0) {
232 err = index;
233 goto unlock;
236 spin_lock_irqsave(&bpmp->lock, flags);
237 err = __tegra_bpmp_channel_read(channel, data, size, ret);
238 clear_bit(index, bpmp->threaded.allocated);
239 spin_unlock_irqrestore(&bpmp->lock, flags);
241 unlock:
242 up(&bpmp->threaded.lock);
244 return err;
247 static ssize_t __tegra_bpmp_channel_write(struct tegra_bpmp_channel *channel,
248 unsigned int mrq, unsigned long flags,
249 const void *data, size_t size)
251 channel->ob->code = mrq;
252 channel->ob->flags = flags;
254 if (data && size > 0)
255 memcpy(channel->ob->data, data, size);
257 return tegra_bpmp_post_request(channel);
260 static struct tegra_bpmp_channel *
261 tegra_bpmp_write_threaded(struct tegra_bpmp *bpmp, unsigned int mrq,
262 const void *data, size_t size)
264 unsigned long timeout = bpmp->soc->channels.thread.timeout;
265 unsigned int count = bpmp->soc->channels.thread.count;
266 struct tegra_bpmp_channel *channel;
267 unsigned long flags;
268 unsigned int index;
269 int err;
271 err = down_timeout(&bpmp->threaded.lock, usecs_to_jiffies(timeout));
272 if (err < 0)
273 return ERR_PTR(err);
275 spin_lock_irqsave(&bpmp->lock, flags);
277 index = find_first_zero_bit(bpmp->threaded.allocated, count);
278 if (index == count) {
279 err = -EBUSY;
280 goto unlock;
283 channel = &bpmp->threaded_channels[index];
285 if (!tegra_bpmp_is_request_channel_free(channel)) {
286 err = -EBUSY;
287 goto unlock;
290 set_bit(index, bpmp->threaded.allocated);
292 err = __tegra_bpmp_channel_write(channel, mrq, MSG_ACK | MSG_RING,
293 data, size);
294 if (err < 0)
295 goto clear_allocated;
297 set_bit(index, bpmp->threaded.busy);
299 spin_unlock_irqrestore(&bpmp->lock, flags);
300 return channel;
302 clear_allocated:
303 clear_bit(index, bpmp->threaded.allocated);
304 unlock:
305 spin_unlock_irqrestore(&bpmp->lock, flags);
306 up(&bpmp->threaded.lock);
308 return ERR_PTR(err);
311 static ssize_t tegra_bpmp_channel_write(struct tegra_bpmp_channel *channel,
312 unsigned int mrq, unsigned long flags,
313 const void *data, size_t size)
315 int err;
317 err = tegra_bpmp_wait_request_channel_free(channel);
318 if (err < 0)
319 return err;
321 return __tegra_bpmp_channel_write(channel, mrq, flags, data, size);
324 int tegra_bpmp_transfer_atomic(struct tegra_bpmp *bpmp,
325 struct tegra_bpmp_message *msg)
327 struct tegra_bpmp_channel *channel;
328 int err;
330 if (WARN_ON(!irqs_disabled()))
331 return -EPERM;
333 if (!tegra_bpmp_message_valid(msg))
334 return -EINVAL;
336 channel = bpmp->tx_channel;
338 spin_lock(&bpmp->atomic_tx_lock);
340 err = tegra_bpmp_channel_write(channel, msg->mrq, MSG_ACK,
341 msg->tx.data, msg->tx.size);
342 if (err < 0) {
343 spin_unlock(&bpmp->atomic_tx_lock);
344 return err;
347 spin_unlock(&bpmp->atomic_tx_lock);
349 err = tegra_bpmp_ring_doorbell(bpmp);
350 if (err < 0)
351 return err;
353 err = tegra_bpmp_wait_response(channel);
354 if (err < 0)
355 return err;
357 return __tegra_bpmp_channel_read(channel, msg->rx.data, msg->rx.size,
358 &msg->rx.ret);
360 EXPORT_SYMBOL_GPL(tegra_bpmp_transfer_atomic);
362 int tegra_bpmp_transfer(struct tegra_bpmp *bpmp,
363 struct tegra_bpmp_message *msg)
365 struct tegra_bpmp_channel *channel;
366 unsigned long timeout;
367 int err;
369 if (WARN_ON(irqs_disabled()))
370 return -EPERM;
372 if (!tegra_bpmp_message_valid(msg))
373 return -EINVAL;
375 channel = tegra_bpmp_write_threaded(bpmp, msg->mrq, msg->tx.data,
376 msg->tx.size);
377 if (IS_ERR(channel))
378 return PTR_ERR(channel);
380 err = tegra_bpmp_ring_doorbell(bpmp);
381 if (err < 0)
382 return err;
384 timeout = usecs_to_jiffies(bpmp->soc->channels.thread.timeout);
386 err = wait_for_completion_timeout(&channel->completion, timeout);
387 if (err == 0)
388 return -ETIMEDOUT;
390 return tegra_bpmp_channel_read(channel, msg->rx.data, msg->rx.size,
391 &msg->rx.ret);
393 EXPORT_SYMBOL_GPL(tegra_bpmp_transfer);
395 static struct tegra_bpmp_mrq *tegra_bpmp_find_mrq(struct tegra_bpmp *bpmp,
396 unsigned int mrq)
398 struct tegra_bpmp_mrq *entry;
400 list_for_each_entry(entry, &bpmp->mrqs, list)
401 if (entry->mrq == mrq)
402 return entry;
404 return NULL;
407 void tegra_bpmp_mrq_return(struct tegra_bpmp_channel *channel, int code,
408 const void *data, size_t size)
410 unsigned long flags = channel->ib->flags;
411 struct tegra_bpmp *bpmp = channel->bpmp;
412 int err;
414 if (WARN_ON(size > MSG_DATA_MIN_SZ))
415 return;
417 err = tegra_bpmp_ack_request(channel);
418 if (WARN_ON(err < 0))
419 return;
421 if ((flags & MSG_ACK) == 0)
422 return;
424 if (WARN_ON(!tegra_bpmp_is_response_channel_free(channel)))
425 return;
427 channel->ob->code = code;
429 if (data && size > 0)
430 memcpy(channel->ob->data, data, size);
432 err = tegra_bpmp_post_response(channel);
433 if (WARN_ON(err < 0))
434 return;
436 if (flags & MSG_RING) {
437 err = tegra_bpmp_ring_doorbell(bpmp);
438 if (WARN_ON(err < 0))
439 return;
442 EXPORT_SYMBOL_GPL(tegra_bpmp_mrq_return);
444 static void tegra_bpmp_handle_mrq(struct tegra_bpmp *bpmp,
445 unsigned int mrq,
446 struct tegra_bpmp_channel *channel)
448 struct tegra_bpmp_mrq *entry;
449 u32 zero = 0;
451 spin_lock(&bpmp->lock);
453 entry = tegra_bpmp_find_mrq(bpmp, mrq);
454 if (!entry) {
455 spin_unlock(&bpmp->lock);
456 tegra_bpmp_mrq_return(channel, -EINVAL, &zero, sizeof(zero));
457 return;
460 entry->handler(mrq, channel, entry->data);
462 spin_unlock(&bpmp->lock);
465 int tegra_bpmp_request_mrq(struct tegra_bpmp *bpmp, unsigned int mrq,
466 tegra_bpmp_mrq_handler_t handler, void *data)
468 struct tegra_bpmp_mrq *entry;
469 unsigned long flags;
471 if (!handler)
472 return -EINVAL;
474 entry = devm_kzalloc(bpmp->dev, sizeof(*entry), GFP_KERNEL);
475 if (!entry)
476 return -ENOMEM;
478 spin_lock_irqsave(&bpmp->lock, flags);
480 entry->mrq = mrq;
481 entry->handler = handler;
482 entry->data = data;
483 list_add(&entry->list, &bpmp->mrqs);
485 spin_unlock_irqrestore(&bpmp->lock, flags);
487 return 0;
489 EXPORT_SYMBOL_GPL(tegra_bpmp_request_mrq);
491 void tegra_bpmp_free_mrq(struct tegra_bpmp *bpmp, unsigned int mrq, void *data)
493 struct tegra_bpmp_mrq *entry;
494 unsigned long flags;
496 spin_lock_irqsave(&bpmp->lock, flags);
498 entry = tegra_bpmp_find_mrq(bpmp, mrq);
499 if (!entry)
500 goto unlock;
502 list_del(&entry->list);
503 devm_kfree(bpmp->dev, entry);
505 unlock:
506 spin_unlock_irqrestore(&bpmp->lock, flags);
508 EXPORT_SYMBOL_GPL(tegra_bpmp_free_mrq);
510 bool tegra_bpmp_mrq_is_supported(struct tegra_bpmp *bpmp, unsigned int mrq)
512 struct mrq_query_abi_request req = { .mrq = cpu_to_le32(mrq) };
513 struct mrq_query_abi_response resp;
514 struct tegra_bpmp_message msg = {
515 .mrq = MRQ_QUERY_ABI,
516 .tx = {
517 .data = &req,
518 .size = sizeof(req),
520 .rx = {
521 .data = &resp,
522 .size = sizeof(resp),
525 int ret;
527 ret = tegra_bpmp_transfer(bpmp, &msg);
528 if (ret || msg.rx.ret)
529 return false;
531 return resp.status == 0;
533 EXPORT_SYMBOL_GPL(tegra_bpmp_mrq_is_supported);
535 static void tegra_bpmp_mrq_handle_ping(unsigned int mrq,
536 struct tegra_bpmp_channel *channel,
537 void *data)
539 struct mrq_ping_request *request;
540 struct mrq_ping_response response;
542 request = (struct mrq_ping_request *)channel->ib->data;
544 memset(&response, 0, sizeof(response));
545 response.reply = request->challenge << 1;
547 tegra_bpmp_mrq_return(channel, 0, &response, sizeof(response));
550 static int tegra_bpmp_ping(struct tegra_bpmp *bpmp)
552 struct mrq_ping_response response;
553 struct mrq_ping_request request;
554 struct tegra_bpmp_message msg;
555 unsigned long flags;
556 ktime_t start, end;
557 int err;
559 memset(&request, 0, sizeof(request));
560 request.challenge = 1;
562 memset(&response, 0, sizeof(response));
564 memset(&msg, 0, sizeof(msg));
565 msg.mrq = MRQ_PING;
566 msg.tx.data = &request;
567 msg.tx.size = sizeof(request);
568 msg.rx.data = &response;
569 msg.rx.size = sizeof(response);
571 local_irq_save(flags);
572 start = ktime_get();
573 err = tegra_bpmp_transfer_atomic(bpmp, &msg);
574 end = ktime_get();
575 local_irq_restore(flags);
577 if (!err)
578 dev_dbg(bpmp->dev,
579 "ping ok: challenge: %u, response: %u, time: %lld\n",
580 request.challenge, response.reply,
581 ktime_to_us(ktime_sub(end, start)));
583 return err;
586 /* deprecated version of tag query */
587 static int tegra_bpmp_get_firmware_tag_old(struct tegra_bpmp *bpmp, char *tag,
588 size_t size)
590 struct mrq_query_tag_request request;
591 struct tegra_bpmp_message msg;
592 unsigned long flags;
593 dma_addr_t phys;
594 void *virt;
595 int err;
597 if (size != TAG_SZ)
598 return -EINVAL;
600 virt = dma_alloc_coherent(bpmp->dev, TAG_SZ, &phys,
601 GFP_KERNEL | GFP_DMA32);
602 if (!virt)
603 return -ENOMEM;
605 memset(&request, 0, sizeof(request));
606 request.addr = phys;
608 memset(&msg, 0, sizeof(msg));
609 msg.mrq = MRQ_QUERY_TAG;
610 msg.tx.data = &request;
611 msg.tx.size = sizeof(request);
613 local_irq_save(flags);
614 err = tegra_bpmp_transfer_atomic(bpmp, &msg);
615 local_irq_restore(flags);
617 if (err == 0)
618 memcpy(tag, virt, TAG_SZ);
620 dma_free_coherent(bpmp->dev, TAG_SZ, virt, phys);
622 return err;
625 static int tegra_bpmp_get_firmware_tag(struct tegra_bpmp *bpmp, char *tag,
626 size_t size)
628 if (tegra_bpmp_mrq_is_supported(bpmp, MRQ_QUERY_FW_TAG)) {
629 struct mrq_query_fw_tag_response resp;
630 struct tegra_bpmp_message msg = {
631 .mrq = MRQ_QUERY_FW_TAG,
632 .rx = {
633 .data = &resp,
634 .size = sizeof(resp),
637 int err;
639 if (size != sizeof(resp.tag))
640 return -EINVAL;
642 err = tegra_bpmp_transfer(bpmp, &msg);
644 if (err)
645 return err;
646 if (msg.rx.ret < 0)
647 return -EINVAL;
649 memcpy(tag, resp.tag, sizeof(resp.tag));
650 return 0;
653 return tegra_bpmp_get_firmware_tag_old(bpmp, tag, size);
656 static void tegra_bpmp_channel_signal(struct tegra_bpmp_channel *channel)
658 unsigned long flags = channel->ob->flags;
660 if ((flags & MSG_RING) == 0)
661 return;
663 complete(&channel->completion);
666 void tegra_bpmp_handle_rx(struct tegra_bpmp *bpmp)
668 struct tegra_bpmp_channel *channel;
669 unsigned int i, count;
670 unsigned long *busy;
672 channel = bpmp->rx_channel;
673 count = bpmp->soc->channels.thread.count;
674 busy = bpmp->threaded.busy;
676 if (tegra_bpmp_is_request_ready(channel))
677 tegra_bpmp_handle_mrq(bpmp, channel->ib->code, channel);
679 spin_lock(&bpmp->lock);
681 for_each_set_bit(i, busy, count) {
682 struct tegra_bpmp_channel *channel;
684 channel = &bpmp->threaded_channels[i];
686 if (tegra_bpmp_is_response_ready(channel)) {
687 tegra_bpmp_channel_signal(channel);
688 clear_bit(i, busy);
692 spin_unlock(&bpmp->lock);
695 static int tegra_bpmp_probe(struct platform_device *pdev)
697 struct tegra_bpmp *bpmp;
698 char tag[TAG_SZ];
699 size_t size;
700 int err;
702 bpmp = devm_kzalloc(&pdev->dev, sizeof(*bpmp), GFP_KERNEL);
703 if (!bpmp)
704 return -ENOMEM;
706 bpmp->soc = of_device_get_match_data(&pdev->dev);
707 bpmp->dev = &pdev->dev;
709 INIT_LIST_HEAD(&bpmp->mrqs);
710 spin_lock_init(&bpmp->lock);
712 bpmp->threaded.count = bpmp->soc->channels.thread.count;
713 sema_init(&bpmp->threaded.lock, bpmp->threaded.count);
715 size = BITS_TO_LONGS(bpmp->threaded.count) * sizeof(long);
717 bpmp->threaded.allocated = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
718 if (!bpmp->threaded.allocated)
719 return -ENOMEM;
721 bpmp->threaded.busy = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
722 if (!bpmp->threaded.busy)
723 return -ENOMEM;
725 spin_lock_init(&bpmp->atomic_tx_lock);
726 bpmp->tx_channel = devm_kzalloc(&pdev->dev, sizeof(*bpmp->tx_channel),
727 GFP_KERNEL);
728 if (!bpmp->tx_channel)
729 return -ENOMEM;
731 bpmp->rx_channel = devm_kzalloc(&pdev->dev, sizeof(*bpmp->rx_channel),
732 GFP_KERNEL);
733 if (!bpmp->rx_channel)
734 return -ENOMEM;
736 bpmp->threaded_channels = devm_kcalloc(&pdev->dev, bpmp->threaded.count,
737 sizeof(*bpmp->threaded_channels),
738 GFP_KERNEL);
739 if (!bpmp->threaded_channels)
740 return -ENOMEM;
742 err = bpmp->soc->ops->init(bpmp);
743 if (err < 0)
744 return err;
746 err = tegra_bpmp_request_mrq(bpmp, MRQ_PING,
747 tegra_bpmp_mrq_handle_ping, bpmp);
748 if (err < 0)
749 goto deinit;
751 err = tegra_bpmp_ping(bpmp);
752 if (err < 0) {
753 dev_err(&pdev->dev, "failed to ping BPMP: %d\n", err);
754 goto free_mrq;
757 err = tegra_bpmp_get_firmware_tag(bpmp, tag, sizeof(tag));
758 if (err < 0) {
759 dev_err(&pdev->dev, "failed to get firmware tag: %d\n", err);
760 goto free_mrq;
763 dev_info(&pdev->dev, "firmware: %.*s\n", (int)sizeof(tag), tag);
765 platform_set_drvdata(pdev, bpmp);
767 err = of_platform_default_populate(pdev->dev.of_node, NULL, &pdev->dev);
768 if (err < 0)
769 goto free_mrq;
771 if (of_find_property(pdev->dev.of_node, "#clock-cells", NULL)) {
772 err = tegra_bpmp_init_clocks(bpmp);
773 if (err < 0)
774 goto free_mrq;
777 if (of_find_property(pdev->dev.of_node, "#reset-cells", NULL)) {
778 err = tegra_bpmp_init_resets(bpmp);
779 if (err < 0)
780 goto free_mrq;
783 if (of_find_property(pdev->dev.of_node, "#power-domain-cells", NULL)) {
784 err = tegra_bpmp_init_powergates(bpmp);
785 if (err < 0)
786 goto free_mrq;
789 err = tegra_bpmp_init_debugfs(bpmp);
790 if (err < 0)
791 dev_err(&pdev->dev, "debugfs initialization failed: %d\n", err);
793 return 0;
795 free_mrq:
796 tegra_bpmp_free_mrq(bpmp, MRQ_PING, bpmp);
797 deinit:
798 if (bpmp->soc->ops->deinit)
799 bpmp->soc->ops->deinit(bpmp);
801 return err;
804 static int __maybe_unused tegra_bpmp_resume(struct device *dev)
806 struct tegra_bpmp *bpmp = dev_get_drvdata(dev);
808 if (bpmp->soc->ops->resume)
809 return bpmp->soc->ops->resume(bpmp);
810 else
811 return 0;
814 static SIMPLE_DEV_PM_OPS(tegra_bpmp_pm_ops, NULL, tegra_bpmp_resume);
816 #if IS_ENABLED(CONFIG_ARCH_TEGRA_186_SOC) || \
817 IS_ENABLED(CONFIG_ARCH_TEGRA_194_SOC)
818 static const struct tegra_bpmp_soc tegra186_soc = {
819 .channels = {
820 .cpu_tx = {
821 .offset = 3,
822 .timeout = 60 * USEC_PER_SEC,
824 .thread = {
825 .offset = 0,
826 .count = 3,
827 .timeout = 600 * USEC_PER_SEC,
829 .cpu_rx = {
830 .offset = 13,
831 .timeout = 0,
834 .ops = &tegra186_bpmp_ops,
835 .num_resets = 193,
837 #endif
839 #if IS_ENABLED(CONFIG_ARCH_TEGRA_210_SOC)
840 static const struct tegra_bpmp_soc tegra210_soc = {
841 .channels = {
842 .cpu_tx = {
843 .offset = 0,
844 .count = 1,
845 .timeout = 60 * USEC_PER_SEC,
847 .thread = {
848 .offset = 4,
849 .count = 1,
850 .timeout = 600 * USEC_PER_SEC,
852 .cpu_rx = {
853 .offset = 8,
854 .count = 1,
855 .timeout = 0,
858 .ops = &tegra210_bpmp_ops,
860 #endif
862 static const struct of_device_id tegra_bpmp_match[] = {
863 #if IS_ENABLED(CONFIG_ARCH_TEGRA_186_SOC) || \
864 IS_ENABLED(CONFIG_ARCH_TEGRA_194_SOC)
865 { .compatible = "nvidia,tegra186-bpmp", .data = &tegra186_soc },
866 #endif
867 #if IS_ENABLED(CONFIG_ARCH_TEGRA_210_SOC)
868 { .compatible = "nvidia,tegra210-bpmp", .data = &tegra210_soc },
869 #endif
873 static struct platform_driver tegra_bpmp_driver = {
874 .driver = {
875 .name = "tegra-bpmp",
876 .of_match_table = tegra_bpmp_match,
877 .pm = &tegra_bpmp_pm_ops,
879 .probe = tegra_bpmp_probe,
882 static int __init tegra_bpmp_init(void)
884 return platform_driver_register(&tegra_bpmp_driver);
886 core_initcall(tegra_bpmp_init);