forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/drivers/firmware/tegra/bpmp.c
....@@ -1,23 +1,17 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
3
- *
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.
7
- *
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.
124 */
135
146 #include <linux/clk/tegra.h>
157 #include <linux/genalloc.h>
168 #include <linux/mailbox_client.h>
9
+#include <linux/module.h>
1710 #include <linux/of.h>
1811 #include <linux/of_address.h>
1912 #include <linux/of_device.h>
2013 #include <linux/platform_device.h>
14
+#include <linux/pm.h>
2115 #include <linux/semaphore.h>
2216 #include <linux/sched/clock.h>
2317
....@@ -25,13 +19,24 @@
2519 #include <soc/tegra/bpmp-abi.h>
2620 #include <soc/tegra/ivc.h>
2721
22
+#include "bpmp-private.h"
23
+
2824 #define MSG_ACK BIT(0)
2925 #define MSG_RING BIT(1)
26
+#define TAG_SZ 32
3027
3128 static inline struct tegra_bpmp *
3229 mbox_client_to_bpmp(struct mbox_client *client)
3330 {
3431 return container_of(client, struct tegra_bpmp, mbox.client);
32
+}
33
+
34
+static inline const struct tegra_bpmp_ops *
35
+channel_to_ops(struct tegra_bpmp_channel *channel)
36
+{
37
+ struct tegra_bpmp *bpmp = channel->bpmp;
38
+
39
+ return bpmp->soc->ops;
3540 }
3641
3742 struct tegra_bpmp *tegra_bpmp_get(struct device *dev)
....@@ -94,22 +99,21 @@
9499 (msg->rx.size == 0 || msg->rx.data);
95100 }
96101
97
-static bool tegra_bpmp_master_acked(struct tegra_bpmp_channel *channel)
102
+static bool tegra_bpmp_is_response_ready(struct tegra_bpmp_channel *channel)
98103 {
99
- void *frame;
104
+ const struct tegra_bpmp_ops *ops = channel_to_ops(channel);
100105
101
- frame = tegra_ivc_read_get_next_frame(channel->ivc);
102
- if (IS_ERR(frame)) {
103
- channel->ib = NULL;
104
- return false;
105
- }
106
-
107
- channel->ib = frame;
108
-
109
- return true;
106
+ return ops->is_response_ready(channel);
110107 }
111108
112
-static int tegra_bpmp_wait_ack(struct tegra_bpmp_channel *channel)
109
+static bool tegra_bpmp_is_request_ready(struct tegra_bpmp_channel *channel)
110
+{
111
+ const struct tegra_bpmp_ops *ops = channel_to_ops(channel);
112
+
113
+ return ops->is_request_ready(channel);
114
+}
115
+
116
+static int tegra_bpmp_wait_response(struct tegra_bpmp_channel *channel)
113117 {
114118 unsigned long timeout = channel->bpmp->soc->channels.cpu_tx.timeout;
115119 ktime_t end;
....@@ -117,29 +121,45 @@
117121 end = ktime_add_us(ktime_get(), timeout);
118122
119123 do {
120
- if (tegra_bpmp_master_acked(channel))
124
+ if (tegra_bpmp_is_response_ready(channel))
121125 return 0;
122126 } while (ktime_before(ktime_get(), end));
123127
124128 return -ETIMEDOUT;
125129 }
126130
127
-static bool tegra_bpmp_master_free(struct tegra_bpmp_channel *channel)
131
+static int tegra_bpmp_ack_response(struct tegra_bpmp_channel *channel)
128132 {
129
- void *frame;
133
+ const struct tegra_bpmp_ops *ops = channel_to_ops(channel);
130134
131
- frame = tegra_ivc_write_get_next_frame(channel->ivc);
132
- if (IS_ERR(frame)) {
133
- channel->ob = NULL;
134
- return false;
135
- }
136
-
137
- channel->ob = frame;
138
-
139
- return true;
135
+ return ops->ack_response(channel);
140136 }
141137
142
-static int tegra_bpmp_wait_master_free(struct tegra_bpmp_channel *channel)
138
+static int tegra_bpmp_ack_request(struct tegra_bpmp_channel *channel)
139
+{
140
+ const struct tegra_bpmp_ops *ops = channel_to_ops(channel);
141
+
142
+ return ops->ack_request(channel);
143
+}
144
+
145
+static bool
146
+tegra_bpmp_is_request_channel_free(struct tegra_bpmp_channel *channel)
147
+{
148
+ const struct tegra_bpmp_ops *ops = channel_to_ops(channel);
149
+
150
+ return ops->is_request_channel_free(channel);
151
+}
152
+
153
+static bool
154
+tegra_bpmp_is_response_channel_free(struct tegra_bpmp_channel *channel)
155
+{
156
+ const struct tegra_bpmp_ops *ops = channel_to_ops(channel);
157
+
158
+ return ops->is_response_channel_free(channel);
159
+}
160
+
161
+static int
162
+tegra_bpmp_wait_request_channel_free(struct tegra_bpmp_channel *channel)
143163 {
144164 unsigned long timeout = channel->bpmp->soc->channels.cpu_tx.timeout;
145165 ktime_t start, now;
....@@ -147,13 +167,32 @@
147167 start = ns_to_ktime(local_clock());
148168
149169 do {
150
- if (tegra_bpmp_master_free(channel))
170
+ if (tegra_bpmp_is_request_channel_free(channel))
151171 return 0;
152172
153173 now = ns_to_ktime(local_clock());
154174 } while (ktime_us_delta(now, start) < timeout);
155175
156176 return -ETIMEDOUT;
177
+}
178
+
179
+static int tegra_bpmp_post_request(struct tegra_bpmp_channel *channel)
180
+{
181
+ const struct tegra_bpmp_ops *ops = channel_to_ops(channel);
182
+
183
+ return ops->post_request(channel);
184
+}
185
+
186
+static int tegra_bpmp_post_response(struct tegra_bpmp_channel *channel)
187
+{
188
+ const struct tegra_bpmp_ops *ops = channel_to_ops(channel);
189
+
190
+ return ops->post_response(channel);
191
+}
192
+
193
+static int tegra_bpmp_ring_doorbell(struct tegra_bpmp *bpmp)
194
+{
195
+ return bpmp->soc->ops->ring_doorbell(bpmp);
157196 }
158197
159198 static ssize_t __tegra_bpmp_channel_read(struct tegra_bpmp_channel *channel,
....@@ -164,7 +203,7 @@
164203 if (data && size > 0)
165204 memcpy(data, channel->ib->data, size);
166205
167
- err = tegra_ivc_read_advance(channel->ivc);
206
+ err = tegra_bpmp_ack_response(channel);
168207 if (err < 0)
169208 return err;
170209
....@@ -208,7 +247,7 @@
208247 if (data && size > 0)
209248 memcpy(channel->ob->data, data, size);
210249
211
- return tegra_ivc_write_advance(channel->ivc);
250
+ return tegra_bpmp_post_request(channel);
212251 }
213252
214253 static struct tegra_bpmp_channel *
....@@ -236,7 +275,7 @@
236275
237276 channel = &bpmp->threaded_channels[index];
238277
239
- if (!tegra_bpmp_master_free(channel)) {
278
+ if (!tegra_bpmp_is_request_channel_free(channel)) {
240279 err = -EBUSY;
241280 goto unlock;
242281 }
....@@ -268,7 +307,7 @@
268307 {
269308 int err;
270309
271
- err = tegra_bpmp_wait_master_free(channel);
310
+ err = tegra_bpmp_wait_request_channel_free(channel);
272311 if (err < 0)
273312 return err;
274313
....@@ -300,13 +339,11 @@
300339
301340 spin_unlock(&bpmp->atomic_tx_lock);
302341
303
- err = mbox_send_message(bpmp->mbox.channel, NULL);
342
+ err = tegra_bpmp_ring_doorbell(bpmp);
304343 if (err < 0)
305344 return err;
306345
307
- mbox_client_txdone(bpmp->mbox.channel, 0);
308
-
309
- err = tegra_bpmp_wait_ack(channel);
346
+ err = tegra_bpmp_wait_response(channel);
310347 if (err < 0)
311348 return err;
312349
....@@ -333,11 +370,9 @@
333370 if (IS_ERR(channel))
334371 return PTR_ERR(channel);
335372
336
- err = mbox_send_message(bpmp->mbox.channel, NULL);
373
+ err = tegra_bpmp_ring_doorbell(bpmp);
337374 if (err < 0)
338375 return err;
339
-
340
- mbox_client_txdone(bpmp->mbox.channel, 0);
341376
342377 timeout = usecs_to_jiffies(bpmp->soc->channels.thread.timeout);
343378
....@@ -367,38 +402,34 @@
367402 {
368403 unsigned long flags = channel->ib->flags;
369404 struct tegra_bpmp *bpmp = channel->bpmp;
370
- struct tegra_bpmp_mb_data *frame;
371405 int err;
372406
373407 if (WARN_ON(size > MSG_DATA_MIN_SZ))
374408 return;
375409
376
- err = tegra_ivc_read_advance(channel->ivc);
410
+ err = tegra_bpmp_ack_request(channel);
377411 if (WARN_ON(err < 0))
378412 return;
379413
380414 if ((flags & MSG_ACK) == 0)
381415 return;
382416
383
- frame = tegra_ivc_write_get_next_frame(channel->ivc);
384
- if (WARN_ON(IS_ERR(frame)))
417
+ if (WARN_ON(!tegra_bpmp_is_response_channel_free(channel)))
385418 return;
386419
387
- frame->code = code;
420
+ channel->ob->code = code;
388421
389422 if (data && size > 0)
390
- memcpy(frame->data, data, size);
423
+ memcpy(channel->ob->data, data, size);
391424
392
- err = tegra_ivc_write_advance(channel->ivc);
425
+ err = tegra_bpmp_post_response(channel);
393426 if (WARN_ON(err < 0))
394427 return;
395428
396429 if (flags & MSG_RING) {
397
- err = mbox_send_message(bpmp->mbox.channel, NULL);
430
+ err = tegra_bpmp_ring_doorbell(bpmp);
398431 if (WARN_ON(err < 0))
399432 return;
400
-
401
- mbox_client_txdone(bpmp->mbox.channel, 0);
402433 }
403434 }
404435 EXPORT_SYMBOL_GPL(tegra_bpmp_mrq_return);
....@@ -469,6 +500,31 @@
469500 }
470501 EXPORT_SYMBOL_GPL(tegra_bpmp_free_mrq);
471502
503
+bool tegra_bpmp_mrq_is_supported(struct tegra_bpmp *bpmp, unsigned int mrq)
504
+{
505
+ struct mrq_query_abi_request req = { .mrq = cpu_to_le32(mrq) };
506
+ struct mrq_query_abi_response resp;
507
+ struct tegra_bpmp_message msg = {
508
+ .mrq = MRQ_QUERY_ABI,
509
+ .tx = {
510
+ .data = &req,
511
+ .size = sizeof(req),
512
+ },
513
+ .rx = {
514
+ .data = &resp,
515
+ .size = sizeof(resp),
516
+ },
517
+ };
518
+ int err;
519
+
520
+ err = tegra_bpmp_transfer(bpmp, &msg);
521
+ if (err || msg.rx.ret)
522
+ return false;
523
+
524
+ return resp.status == 0;
525
+}
526
+EXPORT_SYMBOL_GPL(tegra_bpmp_mrq_is_supported);
527
+
472528 static void tegra_bpmp_mrq_handle_ping(unsigned int mrq,
473529 struct tegra_bpmp_channel *channel,
474530 void *data)
....@@ -520,8 +576,9 @@
520576 return err;
521577 }
522578
523
-static int tegra_bpmp_get_firmware_tag(struct tegra_bpmp *bpmp, char *tag,
524
- size_t size)
579
+/* deprecated version of tag query */
580
+static int tegra_bpmp_get_firmware_tag_old(struct tegra_bpmp *bpmp, char *tag,
581
+ size_t size)
525582 {
526583 struct mrq_query_tag_request request;
527584 struct tegra_bpmp_message msg;
....@@ -530,7 +587,10 @@
530587 void *virt;
531588 int err;
532589
533
- virt = dma_alloc_coherent(bpmp->dev, MSG_DATA_MIN_SZ, &phys,
590
+ if (size != TAG_SZ)
591
+ return -EINVAL;
592
+
593
+ virt = dma_alloc_coherent(bpmp->dev, TAG_SZ, &phys,
534594 GFP_KERNEL | GFP_DMA32);
535595 if (!virt)
536596 return -ENOMEM;
....@@ -548,11 +608,42 @@
548608 local_irq_restore(flags);
549609
550610 if (err == 0)
551
- strlcpy(tag, virt, size);
611
+ memcpy(tag, virt, TAG_SZ);
552612
553
- dma_free_coherent(bpmp->dev, MSG_DATA_MIN_SZ, virt, phys);
613
+ dma_free_coherent(bpmp->dev, TAG_SZ, virt, phys);
554614
555615 return err;
616
+}
617
+
618
+static int tegra_bpmp_get_firmware_tag(struct tegra_bpmp *bpmp, char *tag,
619
+ size_t size)
620
+{
621
+ if (tegra_bpmp_mrq_is_supported(bpmp, MRQ_QUERY_FW_TAG)) {
622
+ struct mrq_query_fw_tag_response resp;
623
+ struct tegra_bpmp_message msg = {
624
+ .mrq = MRQ_QUERY_FW_TAG,
625
+ .rx = {
626
+ .data = &resp,
627
+ .size = sizeof(resp),
628
+ },
629
+ };
630
+ int err;
631
+
632
+ if (size != sizeof(resp.tag))
633
+ return -EINVAL;
634
+
635
+ err = tegra_bpmp_transfer(bpmp, &msg);
636
+
637
+ if (err)
638
+ return err;
639
+ if (msg.rx.ret < 0)
640
+ return -EINVAL;
641
+
642
+ memcpy(tag, resp.tag, sizeof(resp.tag));
643
+ return 0;
644
+ }
645
+
646
+ return tegra_bpmp_get_firmware_tag_old(bpmp, tag, size);
556647 }
557648
558649 static void tegra_bpmp_channel_signal(struct tegra_bpmp_channel *channel)
....@@ -565,9 +656,8 @@
565656 complete(&channel->completion);
566657 }
567658
568
-static void tegra_bpmp_handle_rx(struct mbox_client *client, void *data)
659
+void tegra_bpmp_handle_rx(struct tegra_bpmp *bpmp)
569660 {
570
- struct tegra_bpmp *bpmp = mbox_client_to_bpmp(client);
571661 struct tegra_bpmp_channel *channel;
572662 unsigned int i, count;
573663 unsigned long *busy;
....@@ -576,7 +666,7 @@
576666 count = bpmp->soc->channels.thread.count;
577667 busy = bpmp->threaded.busy;
578668
579
- if (tegra_bpmp_master_acked(channel))
669
+ if (tegra_bpmp_is_request_ready(channel))
580670 tegra_bpmp_handle_mrq(bpmp, channel->ib->code, channel);
581671
582672 spin_lock(&bpmp->lock);
....@@ -586,7 +676,7 @@
586676
587677 channel = &bpmp->threaded_channels[i];
588678
589
- if (tegra_bpmp_master_acked(channel)) {
679
+ if (tegra_bpmp_is_response_ready(channel)) {
590680 tegra_bpmp_channel_signal(channel);
591681 clear_bit(i, busy);
592682 }
....@@ -595,75 +685,10 @@
595685 spin_unlock(&bpmp->lock);
596686 }
597687
598
-static void tegra_bpmp_ivc_notify(struct tegra_ivc *ivc, void *data)
599
-{
600
- struct tegra_bpmp *bpmp = data;
601
- int err;
602
-
603
- if (WARN_ON(bpmp->mbox.channel == NULL))
604
- return;
605
-
606
- err = mbox_send_message(bpmp->mbox.channel, NULL);
607
- if (err < 0)
608
- return;
609
-
610
- mbox_client_txdone(bpmp->mbox.channel, 0);
611
-}
612
-
613
-static int tegra_bpmp_channel_init(struct tegra_bpmp_channel *channel,
614
- struct tegra_bpmp *bpmp,
615
- unsigned int index)
616
-{
617
- size_t message_size, queue_size;
618
- unsigned int offset;
619
- int err;
620
-
621
- channel->ivc = devm_kzalloc(bpmp->dev, sizeof(*channel->ivc),
622
- GFP_KERNEL);
623
- if (!channel->ivc)
624
- return -ENOMEM;
625
-
626
- message_size = tegra_ivc_align(MSG_MIN_SZ);
627
- queue_size = tegra_ivc_total_queue_size(message_size);
628
- offset = queue_size * index;
629
-
630
- err = tegra_ivc_init(channel->ivc, NULL,
631
- bpmp->rx.virt + offset, bpmp->rx.phys + offset,
632
- bpmp->tx.virt + offset, bpmp->tx.phys + offset,
633
- 1, message_size, tegra_bpmp_ivc_notify,
634
- bpmp);
635
- if (err < 0) {
636
- dev_err(bpmp->dev, "failed to setup IVC for channel %u: %d\n",
637
- index, err);
638
- return err;
639
- }
640
-
641
- init_completion(&channel->completion);
642
- channel->bpmp = bpmp;
643
-
644
- return 0;
645
-}
646
-
647
-static void tegra_bpmp_channel_reset(struct tegra_bpmp_channel *channel)
648
-{
649
- /* reset the channel state */
650
- tegra_ivc_reset(channel->ivc);
651
-
652
- /* sync the channel state with BPMP */
653
- while (tegra_ivc_notified(channel->ivc))
654
- ;
655
-}
656
-
657
-static void tegra_bpmp_channel_cleanup(struct tegra_bpmp_channel *channel)
658
-{
659
- tegra_ivc_cleanup(channel->ivc);
660
-}
661
-
662688 static int tegra_bpmp_probe(struct platform_device *pdev)
663689 {
664690 struct tegra_bpmp *bpmp;
665
- unsigned int i;
666
- char tag[32];
691
+ char tag[TAG_SZ];
667692 size_t size;
668693 int err;
669694
....@@ -674,32 +699,6 @@
674699 bpmp->soc = of_device_get_match_data(&pdev->dev);
675700 bpmp->dev = &pdev->dev;
676701
677
- bpmp->tx.pool = of_gen_pool_get(pdev->dev.of_node, "shmem", 0);
678
- if (!bpmp->tx.pool) {
679
- dev_err(&pdev->dev, "TX shmem pool not found\n");
680
- return -ENOMEM;
681
- }
682
-
683
- bpmp->tx.virt = gen_pool_dma_alloc(bpmp->tx.pool, 4096, &bpmp->tx.phys);
684
- if (!bpmp->tx.virt) {
685
- dev_err(&pdev->dev, "failed to allocate from TX pool\n");
686
- return -ENOMEM;
687
- }
688
-
689
- bpmp->rx.pool = of_gen_pool_get(pdev->dev.of_node, "shmem", 1);
690
- if (!bpmp->rx.pool) {
691
- dev_err(&pdev->dev, "RX shmem pool not found\n");
692
- err = -ENOMEM;
693
- goto free_tx;
694
- }
695
-
696
- bpmp->rx.virt = gen_pool_dma_alloc(bpmp->rx.pool, 4096, &bpmp->rx.phys);
697
- if (!bpmp->rx.virt) {
698
- dev_err(&pdev->dev, "failed to allocate from RX pool\n");
699
- err = -ENOMEM;
700
- goto free_tx;
701
- }
702
-
703702 INIT_LIST_HEAD(&bpmp->mrqs);
704703 spin_lock_init(&bpmp->lock);
705704
....@@ -709,81 +708,38 @@
709708 size = BITS_TO_LONGS(bpmp->threaded.count) * sizeof(long);
710709
711710 bpmp->threaded.allocated = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
712
- if (!bpmp->threaded.allocated) {
713
- err = -ENOMEM;
714
- goto free_rx;
715
- }
711
+ if (!bpmp->threaded.allocated)
712
+ return -ENOMEM;
716713
717714 bpmp->threaded.busy = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
718
- if (!bpmp->threaded.busy) {
719
- err = -ENOMEM;
720
- goto free_rx;
721
- }
715
+ if (!bpmp->threaded.busy)
716
+ return -ENOMEM;
722717
723718 spin_lock_init(&bpmp->atomic_tx_lock);
724719 bpmp->tx_channel = devm_kzalloc(&pdev->dev, sizeof(*bpmp->tx_channel),
725720 GFP_KERNEL);
726
- if (!bpmp->tx_channel) {
727
- err = -ENOMEM;
728
- goto free_rx;
729
- }
721
+ if (!bpmp->tx_channel)
722
+ return -ENOMEM;
730723
731724 bpmp->rx_channel = devm_kzalloc(&pdev->dev, sizeof(*bpmp->rx_channel),
732725 GFP_KERNEL);
733
- if (!bpmp->rx_channel) {
734
- err = -ENOMEM;
735
- goto free_rx;
736
- }
726
+ if (!bpmp->rx_channel)
727
+ return -ENOMEM;
737728
738729 bpmp->threaded_channels = devm_kcalloc(&pdev->dev, bpmp->threaded.count,
739730 sizeof(*bpmp->threaded_channels),
740731 GFP_KERNEL);
741
- if (!bpmp->threaded_channels) {
742
- err = -ENOMEM;
743
- goto free_rx;
744
- }
732
+ if (!bpmp->threaded_channels)
733
+ return -ENOMEM;
745734
746
- err = tegra_bpmp_channel_init(bpmp->tx_channel, bpmp,
747
- bpmp->soc->channels.cpu_tx.offset);
735
+ err = bpmp->soc->ops->init(bpmp);
748736 if (err < 0)
749
- goto free_rx;
750
-
751
- err = tegra_bpmp_channel_init(bpmp->rx_channel, bpmp,
752
- bpmp->soc->channels.cpu_rx.offset);
753
- if (err < 0)
754
- goto cleanup_tx_channel;
755
-
756
- for (i = 0; i < bpmp->threaded.count; i++) {
757
- err = tegra_bpmp_channel_init(
758
- &bpmp->threaded_channels[i], bpmp,
759
- bpmp->soc->channels.thread.offset + i);
760
- if (err < 0)
761
- goto cleanup_threaded_channels;
762
- }
763
-
764
- /* mbox registration */
765
- bpmp->mbox.client.dev = &pdev->dev;
766
- bpmp->mbox.client.rx_callback = tegra_bpmp_handle_rx;
767
- bpmp->mbox.client.tx_block = false;
768
- bpmp->mbox.client.knows_txdone = false;
769
-
770
- bpmp->mbox.channel = mbox_request_channel(&bpmp->mbox.client, 0);
771
- if (IS_ERR(bpmp->mbox.channel)) {
772
- err = PTR_ERR(bpmp->mbox.channel);
773
- dev_err(&pdev->dev, "failed to get HSP mailbox: %d\n", err);
774
- goto cleanup_threaded_channels;
775
- }
776
-
777
- /* reset message channels */
778
- tegra_bpmp_channel_reset(bpmp->tx_channel);
779
- tegra_bpmp_channel_reset(bpmp->rx_channel);
780
- for (i = 0; i < bpmp->threaded.count; i++)
781
- tegra_bpmp_channel_reset(&bpmp->threaded_channels[i]);
737
+ return err;
782738
783739 err = tegra_bpmp_request_mrq(bpmp, MRQ_PING,
784740 tegra_bpmp_mrq_handle_ping, bpmp);
785741 if (err < 0)
786
- goto free_mbox;
742
+ goto deinit;
787743
788744 err = tegra_bpmp_ping(bpmp);
789745 if (err < 0) {
....@@ -791,13 +747,13 @@
791747 goto free_mrq;
792748 }
793749
794
- err = tegra_bpmp_get_firmware_tag(bpmp, tag, sizeof(tag) - 1);
750
+ err = tegra_bpmp_get_firmware_tag(bpmp, tag, sizeof(tag));
795751 if (err < 0) {
796752 dev_err(&pdev->dev, "failed to get firmware tag: %d\n", err);
797753 goto free_mrq;
798754 }
799755
800
- dev_info(&pdev->dev, "firmware: %s\n", tag);
756
+ dev_info(&pdev->dev, "firmware: %.*s\n", (int)sizeof(tag), tag);
801757
802758 platform_set_drvdata(pdev, bpmp);
803759
....@@ -805,17 +761,23 @@
805761 if (err < 0)
806762 goto free_mrq;
807763
808
- err = tegra_bpmp_init_clocks(bpmp);
809
- if (err < 0)
810
- goto free_mrq;
764
+ if (of_find_property(pdev->dev.of_node, "#clock-cells", NULL)) {
765
+ err = tegra_bpmp_init_clocks(bpmp);
766
+ if (err < 0)
767
+ goto free_mrq;
768
+ }
811769
812
- err = tegra_bpmp_init_resets(bpmp);
813
- if (err < 0)
814
- goto free_mrq;
770
+ if (of_find_property(pdev->dev.of_node, "#reset-cells", NULL)) {
771
+ err = tegra_bpmp_init_resets(bpmp);
772
+ if (err < 0)
773
+ goto free_mrq;
774
+ }
815775
816
- err = tegra_bpmp_init_powergates(bpmp);
817
- if (err < 0)
818
- goto free_mrq;
776
+ if (of_find_property(pdev->dev.of_node, "#power-domain-cells", NULL)) {
777
+ err = tegra_bpmp_init_powergates(bpmp);
778
+ if (err < 0)
779
+ goto free_mrq;
780
+ }
819781
820782 err = tegra_bpmp_init_debugfs(bpmp);
821783 if (err < 0)
....@@ -825,24 +787,30 @@
825787
826788 free_mrq:
827789 tegra_bpmp_free_mrq(bpmp, MRQ_PING, bpmp);
828
-free_mbox:
829
- mbox_free_channel(bpmp->mbox.channel);
830
-cleanup_threaded_channels:
831
- for (i = 0; i < bpmp->threaded.count; i++) {
832
- if (bpmp->threaded_channels[i].bpmp)
833
- tegra_bpmp_channel_cleanup(&bpmp->threaded_channels[i]);
834
- }
790
+deinit:
791
+ if (bpmp->soc->ops->deinit)
792
+ bpmp->soc->ops->deinit(bpmp);
835793
836
- tegra_bpmp_channel_cleanup(bpmp->rx_channel);
837
-cleanup_tx_channel:
838
- tegra_bpmp_channel_cleanup(bpmp->tx_channel);
839
-free_rx:
840
- gen_pool_free(bpmp->rx.pool, (unsigned long)bpmp->rx.virt, 4096);
841
-free_tx:
842
- gen_pool_free(bpmp->tx.pool, (unsigned long)bpmp->tx.virt, 4096);
843794 return err;
844795 }
845796
797
+static int __maybe_unused tegra_bpmp_resume(struct device *dev)
798
+{
799
+ struct tegra_bpmp *bpmp = dev_get_drvdata(dev);
800
+
801
+ if (bpmp->soc->ops->resume)
802
+ return bpmp->soc->ops->resume(bpmp);
803
+ else
804
+ return 0;
805
+}
806
+
807
+static const struct dev_pm_ops tegra_bpmp_pm_ops = {
808
+ .resume_noirq = tegra_bpmp_resume,
809
+};
810
+
811
+#if IS_ENABLED(CONFIG_ARCH_TEGRA_186_SOC) || \
812
+ IS_ENABLED(CONFIG_ARCH_TEGRA_194_SOC) || \
813
+ IS_ENABLED(CONFIG_ARCH_TEGRA_234_SOC)
846814 static const struct tegra_bpmp_soc tegra186_soc = {
847815 .channels = {
848816 .cpu_tx = {
....@@ -859,11 +827,43 @@
859827 .timeout = 0,
860828 },
861829 },
830
+ .ops = &tegra186_bpmp_ops,
862831 .num_resets = 193,
863832 };
833
+#endif
834
+
835
+#if IS_ENABLED(CONFIG_ARCH_TEGRA_210_SOC)
836
+static const struct tegra_bpmp_soc tegra210_soc = {
837
+ .channels = {
838
+ .cpu_tx = {
839
+ .offset = 0,
840
+ .count = 1,
841
+ .timeout = 60 * USEC_PER_SEC,
842
+ },
843
+ .thread = {
844
+ .offset = 4,
845
+ .count = 1,
846
+ .timeout = 600 * USEC_PER_SEC,
847
+ },
848
+ .cpu_rx = {
849
+ .offset = 8,
850
+ .count = 1,
851
+ .timeout = 0,
852
+ },
853
+ },
854
+ .ops = &tegra210_bpmp_ops,
855
+};
856
+#endif
864857
865858 static const struct of_device_id tegra_bpmp_match[] = {
859
+#if IS_ENABLED(CONFIG_ARCH_TEGRA_186_SOC) || \
860
+ IS_ENABLED(CONFIG_ARCH_TEGRA_194_SOC) || \
861
+ IS_ENABLED(CONFIG_ARCH_TEGRA_234_SOC)
866862 { .compatible = "nvidia,tegra186-bpmp", .data = &tegra186_soc },
863
+#endif
864
+#if IS_ENABLED(CONFIG_ARCH_TEGRA_210_SOC)
865
+ { .compatible = "nvidia,tegra210-bpmp", .data = &tegra210_soc },
866
+#endif
867867 { }
868868 };
869869
....@@ -871,12 +871,9 @@
871871 .driver = {
872872 .name = "tegra-bpmp",
873873 .of_match_table = tegra_bpmp_match,
874
+ .pm = &tegra_bpmp_pm_ops,
875
+ .suppress_bind_attrs = true,
874876 },
875877 .probe = tegra_bpmp_probe,
876878 };
877
-
878
-static int __init tegra_bpmp_init(void)
879
-{
880
- return platform_driver_register(&tegra_bpmp_driver);
881
-}
882
-core_initcall(tegra_bpmp_init);
879
+builtin_platform_driver(tegra_bpmp_driver);