Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / memory / tegra / mc.c
blob44064de962c2f6e49dea9bd4045f4ed3b961ae1e
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (C) 2014 NVIDIA CORPORATION. All rights reserved.
4 */
6 #include <linux/clk.h>
7 #include <linux/delay.h>
8 #include <linux/dma-mapping.h>
9 #include <linux/export.h>
10 #include <linux/interrupt.h>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/of.h>
14 #include <linux/of_device.h>
15 #include <linux/platform_device.h>
16 #include <linux/slab.h>
17 #include <linux/sort.h>
19 #include <soc/tegra/fuse.h>
21 #include "mc.h"
23 static const struct of_device_id tegra_mc_of_match[] = {
24 #ifdef CONFIG_ARCH_TEGRA_2x_SOC
25 { .compatible = "nvidia,tegra20-mc-gart", .data = &tegra20_mc_soc },
26 #endif
27 #ifdef CONFIG_ARCH_TEGRA_3x_SOC
28 { .compatible = "nvidia,tegra30-mc", .data = &tegra30_mc_soc },
29 #endif
30 #ifdef CONFIG_ARCH_TEGRA_114_SOC
31 { .compatible = "nvidia,tegra114-mc", .data = &tegra114_mc_soc },
32 #endif
33 #ifdef CONFIG_ARCH_TEGRA_124_SOC
34 { .compatible = "nvidia,tegra124-mc", .data = &tegra124_mc_soc },
35 #endif
36 #ifdef CONFIG_ARCH_TEGRA_132_SOC
37 { .compatible = "nvidia,tegra132-mc", .data = &tegra132_mc_soc },
38 #endif
39 #ifdef CONFIG_ARCH_TEGRA_210_SOC
40 { .compatible = "nvidia,tegra210-mc", .data = &tegra210_mc_soc },
41 #endif
42 { }
44 MODULE_DEVICE_TABLE(of, tegra_mc_of_match);
46 static void tegra_mc_devm_action_put_device(void *data)
48 struct tegra_mc *mc = data;
50 put_device(mc->dev);
53 /**
54 * devm_tegra_memory_controller_get() - get Tegra Memory Controller handle
55 * @dev: device pointer for the consumer device
57 * This function will search for the Memory Controller node in a device-tree
58 * and retrieve the Memory Controller handle.
60 * Return: ERR_PTR() on error or a valid pointer to a struct tegra_mc.
62 struct tegra_mc *devm_tegra_memory_controller_get(struct device *dev)
64 struct platform_device *pdev;
65 struct device_node *np;
66 struct tegra_mc *mc;
67 int err;
69 np = of_parse_phandle(dev->of_node, "nvidia,memory-controller", 0);
70 if (!np)
71 return ERR_PTR(-ENOENT);
73 pdev = of_find_device_by_node(np);
74 of_node_put(np);
75 if (!pdev)
76 return ERR_PTR(-ENODEV);
78 mc = platform_get_drvdata(pdev);
79 if (!mc) {
80 put_device(&pdev->dev);
81 return ERR_PTR(-EPROBE_DEFER);
84 err = devm_add_action(dev, tegra_mc_devm_action_put_device, mc);
85 if (err) {
86 put_device(mc->dev);
87 return ERR_PTR(err);
90 return mc;
92 EXPORT_SYMBOL_GPL(devm_tegra_memory_controller_get);
94 static int tegra_mc_block_dma_common(struct tegra_mc *mc,
95 const struct tegra_mc_reset *rst)
97 unsigned long flags;
98 u32 value;
100 spin_lock_irqsave(&mc->lock, flags);
102 value = mc_readl(mc, rst->control) | BIT(rst->bit);
103 mc_writel(mc, value, rst->control);
105 spin_unlock_irqrestore(&mc->lock, flags);
107 return 0;
110 static bool tegra_mc_dma_idling_common(struct tegra_mc *mc,
111 const struct tegra_mc_reset *rst)
113 return (mc_readl(mc, rst->status) & BIT(rst->bit)) != 0;
116 static int tegra_mc_unblock_dma_common(struct tegra_mc *mc,
117 const struct tegra_mc_reset *rst)
119 unsigned long flags;
120 u32 value;
122 spin_lock_irqsave(&mc->lock, flags);
124 value = mc_readl(mc, rst->control) & ~BIT(rst->bit);
125 mc_writel(mc, value, rst->control);
127 spin_unlock_irqrestore(&mc->lock, flags);
129 return 0;
132 static int tegra_mc_reset_status_common(struct tegra_mc *mc,
133 const struct tegra_mc_reset *rst)
135 return (mc_readl(mc, rst->control) & BIT(rst->bit)) != 0;
138 const struct tegra_mc_reset_ops tegra_mc_reset_ops_common = {
139 .block_dma = tegra_mc_block_dma_common,
140 .dma_idling = tegra_mc_dma_idling_common,
141 .unblock_dma = tegra_mc_unblock_dma_common,
142 .reset_status = tegra_mc_reset_status_common,
145 static inline struct tegra_mc *reset_to_mc(struct reset_controller_dev *rcdev)
147 return container_of(rcdev, struct tegra_mc, reset);
150 static const struct tegra_mc_reset *tegra_mc_reset_find(struct tegra_mc *mc,
151 unsigned long id)
153 unsigned int i;
155 for (i = 0; i < mc->soc->num_resets; i++)
156 if (mc->soc->resets[i].id == id)
157 return &mc->soc->resets[i];
159 return NULL;
162 static int tegra_mc_hotreset_assert(struct reset_controller_dev *rcdev,
163 unsigned long id)
165 struct tegra_mc *mc = reset_to_mc(rcdev);
166 const struct tegra_mc_reset_ops *rst_ops;
167 const struct tegra_mc_reset *rst;
168 int retries = 500;
169 int err;
171 rst = tegra_mc_reset_find(mc, id);
172 if (!rst)
173 return -ENODEV;
175 rst_ops = mc->soc->reset_ops;
176 if (!rst_ops)
177 return -ENODEV;
179 if (rst_ops->block_dma) {
180 /* block clients DMA requests */
181 err = rst_ops->block_dma(mc, rst);
182 if (err) {
183 dev_err(mc->dev, "failed to block %s DMA: %d\n",
184 rst->name, err);
185 return err;
189 if (rst_ops->dma_idling) {
190 /* wait for completion of the outstanding DMA requests */
191 while (!rst_ops->dma_idling(mc, rst)) {
192 if (!retries--) {
193 dev_err(mc->dev, "failed to flush %s DMA\n",
194 rst->name);
195 return -EBUSY;
198 usleep_range(10, 100);
202 if (rst_ops->hotreset_assert) {
203 /* clear clients DMA requests sitting before arbitration */
204 err = rst_ops->hotreset_assert(mc, rst);
205 if (err) {
206 dev_err(mc->dev, "failed to hot reset %s: %d\n",
207 rst->name, err);
208 return err;
212 return 0;
215 static int tegra_mc_hotreset_deassert(struct reset_controller_dev *rcdev,
216 unsigned long id)
218 struct tegra_mc *mc = reset_to_mc(rcdev);
219 const struct tegra_mc_reset_ops *rst_ops;
220 const struct tegra_mc_reset *rst;
221 int err;
223 rst = tegra_mc_reset_find(mc, id);
224 if (!rst)
225 return -ENODEV;
227 rst_ops = mc->soc->reset_ops;
228 if (!rst_ops)
229 return -ENODEV;
231 if (rst_ops->hotreset_deassert) {
232 /* take out client from hot reset */
233 err = rst_ops->hotreset_deassert(mc, rst);
234 if (err) {
235 dev_err(mc->dev, "failed to deassert hot reset %s: %d\n",
236 rst->name, err);
237 return err;
241 if (rst_ops->unblock_dma) {
242 /* allow new DMA requests to proceed to arbitration */
243 err = rst_ops->unblock_dma(mc, rst);
244 if (err) {
245 dev_err(mc->dev, "failed to unblock %s DMA : %d\n",
246 rst->name, err);
247 return err;
251 return 0;
254 static int tegra_mc_hotreset_status(struct reset_controller_dev *rcdev,
255 unsigned long id)
257 struct tegra_mc *mc = reset_to_mc(rcdev);
258 const struct tegra_mc_reset_ops *rst_ops;
259 const struct tegra_mc_reset *rst;
261 rst = tegra_mc_reset_find(mc, id);
262 if (!rst)
263 return -ENODEV;
265 rst_ops = mc->soc->reset_ops;
266 if (!rst_ops)
267 return -ENODEV;
269 return rst_ops->reset_status(mc, rst);
272 static const struct reset_control_ops tegra_mc_reset_ops = {
273 .assert = tegra_mc_hotreset_assert,
274 .deassert = tegra_mc_hotreset_deassert,
275 .status = tegra_mc_hotreset_status,
278 static int tegra_mc_reset_setup(struct tegra_mc *mc)
280 int err;
282 mc->reset.ops = &tegra_mc_reset_ops;
283 mc->reset.owner = THIS_MODULE;
284 mc->reset.of_node = mc->dev->of_node;
285 mc->reset.of_reset_n_cells = 1;
286 mc->reset.nr_resets = mc->soc->num_resets;
288 err = reset_controller_register(&mc->reset);
289 if (err < 0)
290 return err;
292 return 0;
295 static int tegra_mc_setup_latency_allowance(struct tegra_mc *mc)
297 unsigned long long tick;
298 unsigned int i;
299 u32 value;
301 /* compute the number of MC clock cycles per tick */
302 tick = (unsigned long long)mc->tick * clk_get_rate(mc->clk);
303 do_div(tick, NSEC_PER_SEC);
305 value = mc_readl(mc, MC_EMEM_ARB_CFG);
306 value &= ~MC_EMEM_ARB_CFG_CYCLES_PER_UPDATE_MASK;
307 value |= MC_EMEM_ARB_CFG_CYCLES_PER_UPDATE(tick);
308 mc_writel(mc, value, MC_EMEM_ARB_CFG);
310 /* write latency allowance defaults */
311 for (i = 0; i < mc->soc->num_clients; i++) {
312 const struct tegra_mc_la *la = &mc->soc->clients[i].la;
313 u32 value;
315 value = mc_readl(mc, la->reg);
316 value &= ~(la->mask << la->shift);
317 value |= (la->def & la->mask) << la->shift;
318 mc_writel(mc, value, la->reg);
321 /* latch new values */
322 mc_writel(mc, MC_TIMING_UPDATE, MC_TIMING_CONTROL);
324 return 0;
327 int tegra_mc_write_emem_configuration(struct tegra_mc *mc, unsigned long rate)
329 unsigned int i;
330 struct tegra_mc_timing *timing = NULL;
332 for (i = 0; i < mc->num_timings; i++) {
333 if (mc->timings[i].rate == rate) {
334 timing = &mc->timings[i];
335 break;
339 if (!timing) {
340 dev_err(mc->dev, "no memory timing registered for rate %lu\n",
341 rate);
342 return -EINVAL;
345 for (i = 0; i < mc->soc->num_emem_regs; ++i)
346 mc_writel(mc, timing->emem_data[i], mc->soc->emem_regs[i]);
348 return 0;
350 EXPORT_SYMBOL_GPL(tegra_mc_write_emem_configuration);
352 unsigned int tegra_mc_get_emem_device_count(struct tegra_mc *mc)
354 u8 dram_count;
356 dram_count = mc_readl(mc, MC_EMEM_ADR_CFG);
357 dram_count &= MC_EMEM_ADR_CFG_EMEM_NUMDEV;
358 dram_count++;
360 return dram_count;
362 EXPORT_SYMBOL_GPL(tegra_mc_get_emem_device_count);
364 static int load_one_timing(struct tegra_mc *mc,
365 struct tegra_mc_timing *timing,
366 struct device_node *node)
368 int err;
369 u32 tmp;
371 err = of_property_read_u32(node, "clock-frequency", &tmp);
372 if (err) {
373 dev_err(mc->dev,
374 "timing %pOFn: failed to read rate\n", node);
375 return err;
378 timing->rate = tmp;
379 timing->emem_data = devm_kcalloc(mc->dev, mc->soc->num_emem_regs,
380 sizeof(u32), GFP_KERNEL);
381 if (!timing->emem_data)
382 return -ENOMEM;
384 err = of_property_read_u32_array(node, "nvidia,emem-configuration",
385 timing->emem_data,
386 mc->soc->num_emem_regs);
387 if (err) {
388 dev_err(mc->dev,
389 "timing %pOFn: failed to read EMEM configuration\n",
390 node);
391 return err;
394 return 0;
397 static int load_timings(struct tegra_mc *mc, struct device_node *node)
399 struct device_node *child;
400 struct tegra_mc_timing *timing;
401 int child_count = of_get_child_count(node);
402 int i = 0, err;
404 mc->timings = devm_kcalloc(mc->dev, child_count, sizeof(*timing),
405 GFP_KERNEL);
406 if (!mc->timings)
407 return -ENOMEM;
409 mc->num_timings = child_count;
411 for_each_child_of_node(node, child) {
412 timing = &mc->timings[i++];
414 err = load_one_timing(mc, timing, child);
415 if (err) {
416 of_node_put(child);
417 return err;
421 return 0;
424 static int tegra_mc_setup_timings(struct tegra_mc *mc)
426 struct device_node *node;
427 u32 ram_code, node_ram_code;
428 int err;
430 ram_code = tegra_read_ram_code();
432 mc->num_timings = 0;
434 for_each_child_of_node(mc->dev->of_node, node) {
435 err = of_property_read_u32(node, "nvidia,ram-code",
436 &node_ram_code);
437 if (err || (node_ram_code != ram_code))
438 continue;
440 err = load_timings(mc, node);
441 of_node_put(node);
442 if (err)
443 return err;
444 break;
447 if (mc->num_timings == 0)
448 dev_warn(mc->dev,
449 "no memory timings for RAM code %u registered\n",
450 ram_code);
452 return 0;
455 static const char *const status_names[32] = {
456 [ 1] = "External interrupt",
457 [ 6] = "EMEM address decode error",
458 [ 7] = "GART page fault",
459 [ 8] = "Security violation",
460 [ 9] = "EMEM arbitration error",
461 [10] = "Page fault",
462 [11] = "Invalid APB ASID update",
463 [12] = "VPR violation",
464 [13] = "Secure carveout violation",
465 [16] = "MTS carveout violation",
468 static const char *const error_names[8] = {
469 [2] = "EMEM decode error",
470 [3] = "TrustZone violation",
471 [4] = "Carveout violation",
472 [6] = "SMMU translation error",
475 static irqreturn_t tegra_mc_irq(int irq, void *data)
477 struct tegra_mc *mc = data;
478 unsigned long status;
479 unsigned int bit;
481 /* mask all interrupts to avoid flooding */
482 status = mc_readl(mc, MC_INTSTATUS) & mc->soc->intmask;
483 if (!status)
484 return IRQ_NONE;
486 for_each_set_bit(bit, &status, 32) {
487 const char *error = status_names[bit] ?: "unknown";
488 const char *client = "unknown", *desc;
489 const char *direction, *secure;
490 phys_addr_t addr = 0;
491 unsigned int i;
492 char perm[7];
493 u8 id, type;
494 u32 value;
496 value = mc_readl(mc, MC_ERR_STATUS);
498 #ifdef CONFIG_PHYS_ADDR_T_64BIT
499 if (mc->soc->num_address_bits > 32) {
500 addr = ((value >> MC_ERR_STATUS_ADR_HI_SHIFT) &
501 MC_ERR_STATUS_ADR_HI_MASK);
502 addr <<= 32;
504 #endif
506 if (value & MC_ERR_STATUS_RW)
507 direction = "write";
508 else
509 direction = "read";
511 if (value & MC_ERR_STATUS_SECURITY)
512 secure = "secure ";
513 else
514 secure = "";
516 id = value & mc->soc->client_id_mask;
518 for (i = 0; i < mc->soc->num_clients; i++) {
519 if (mc->soc->clients[i].id == id) {
520 client = mc->soc->clients[i].name;
521 break;
525 type = (value & MC_ERR_STATUS_TYPE_MASK) >>
526 MC_ERR_STATUS_TYPE_SHIFT;
527 desc = error_names[type];
529 switch (value & MC_ERR_STATUS_TYPE_MASK) {
530 case MC_ERR_STATUS_TYPE_INVALID_SMMU_PAGE:
531 perm[0] = ' ';
532 perm[1] = '[';
534 if (value & MC_ERR_STATUS_READABLE)
535 perm[2] = 'R';
536 else
537 perm[2] = '-';
539 if (value & MC_ERR_STATUS_WRITABLE)
540 perm[3] = 'W';
541 else
542 perm[3] = '-';
544 if (value & MC_ERR_STATUS_NONSECURE)
545 perm[4] = '-';
546 else
547 perm[4] = 'S';
549 perm[5] = ']';
550 perm[6] = '\0';
551 break;
553 default:
554 perm[0] = '\0';
555 break;
558 value = mc_readl(mc, MC_ERR_ADR);
559 addr |= value;
561 dev_err_ratelimited(mc->dev, "%s: %s%s @%pa: %s (%s%s)\n",
562 client, secure, direction, &addr, error,
563 desc, perm);
566 /* clear interrupts */
567 mc_writel(mc, status, MC_INTSTATUS);
569 return IRQ_HANDLED;
572 static __maybe_unused irqreturn_t tegra20_mc_irq(int irq, void *data)
574 struct tegra_mc *mc = data;
575 unsigned long status;
576 unsigned int bit;
578 /* mask all interrupts to avoid flooding */
579 status = mc_readl(mc, MC_INTSTATUS) & mc->soc->intmask;
580 if (!status)
581 return IRQ_NONE;
583 for_each_set_bit(bit, &status, 32) {
584 const char *direction = "read", *secure = "";
585 const char *error = status_names[bit];
586 const char *client, *desc;
587 phys_addr_t addr;
588 u32 value, reg;
589 u8 id, type;
591 switch (BIT(bit)) {
592 case MC_INT_DECERR_EMEM:
593 reg = MC_DECERR_EMEM_OTHERS_STATUS;
594 value = mc_readl(mc, reg);
596 id = value & mc->soc->client_id_mask;
597 desc = error_names[2];
599 if (value & BIT(31))
600 direction = "write";
601 break;
603 case MC_INT_INVALID_GART_PAGE:
604 reg = MC_GART_ERROR_REQ;
605 value = mc_readl(mc, reg);
607 id = (value >> 1) & mc->soc->client_id_mask;
608 desc = error_names[2];
610 if (value & BIT(0))
611 direction = "write";
612 break;
614 case MC_INT_SECURITY_VIOLATION:
615 reg = MC_SECURITY_VIOLATION_STATUS;
616 value = mc_readl(mc, reg);
618 id = value & mc->soc->client_id_mask;
619 type = (value & BIT(30)) ? 4 : 3;
620 desc = error_names[type];
621 secure = "secure ";
623 if (value & BIT(31))
624 direction = "write";
625 break;
627 default:
628 continue;
631 client = mc->soc->clients[id].name;
632 addr = mc_readl(mc, reg + sizeof(u32));
634 dev_err_ratelimited(mc->dev, "%s: %s%s @%pa: %s (%s)\n",
635 client, secure, direction, &addr, error,
636 desc);
639 /* clear interrupts */
640 mc_writel(mc, status, MC_INTSTATUS);
642 return IRQ_HANDLED;
646 * Memory Controller (MC) has few Memory Clients that are issuing memory
647 * bandwidth allocation requests to the MC interconnect provider. The MC
648 * provider aggregates the requests and then sends the aggregated request
649 * up to the External Memory Controller (EMC) interconnect provider which
650 * re-configures hardware interface to External Memory (EMEM) in accordance
651 * to the required bandwidth. Each MC interconnect node represents an
652 * individual Memory Client.
654 * Memory interconnect topology:
656 * +----+
657 * +--------+ | |
658 * | TEXSRD +--->+ |
659 * +--------+ | |
660 * | | +-----+ +------+
661 * ... | MC +--->+ EMC +--->+ EMEM |
662 * | | +-----+ +------+
663 * +--------+ | |
664 * | DISP.. +--->+ |
665 * +--------+ | |
666 * +----+
668 static int tegra_mc_interconnect_setup(struct tegra_mc *mc)
670 struct icc_node *node;
671 unsigned int i;
672 int err;
674 /* older device-trees don't have interconnect properties */
675 if (!device_property_present(mc->dev, "#interconnect-cells") ||
676 !mc->soc->icc_ops)
677 return 0;
679 mc->provider.dev = mc->dev;
680 mc->provider.data = &mc->provider;
681 mc->provider.set = mc->soc->icc_ops->set;
682 mc->provider.aggregate = mc->soc->icc_ops->aggregate;
683 mc->provider.xlate_extended = mc->soc->icc_ops->xlate_extended;
685 err = icc_provider_add(&mc->provider);
686 if (err)
687 return err;
689 /* create Memory Controller node */
690 node = icc_node_create(TEGRA_ICC_MC);
691 if (IS_ERR(node)) {
692 err = PTR_ERR(node);
693 goto del_provider;
696 node->name = "Memory Controller";
697 icc_node_add(node, &mc->provider);
699 /* link Memory Controller to External Memory Controller */
700 err = icc_link_create(node, TEGRA_ICC_EMC);
701 if (err)
702 goto remove_nodes;
704 for (i = 0; i < mc->soc->num_clients; i++) {
705 /* create MC client node */
706 node = icc_node_create(mc->soc->clients[i].id);
707 if (IS_ERR(node)) {
708 err = PTR_ERR(node);
709 goto remove_nodes;
712 node->name = mc->soc->clients[i].name;
713 icc_node_add(node, &mc->provider);
715 /* link Memory Client to Memory Controller */
716 err = icc_link_create(node, TEGRA_ICC_MC);
717 if (err)
718 goto remove_nodes;
722 * MC driver is registered too early, so early that generic driver
723 * syncing doesn't work for the MC. But it doesn't really matter
724 * since syncing works for the EMC drivers, hence we can sync the
725 * MC driver by ourselves and then EMC will complete syncing of
726 * the whole ICC state.
728 icc_sync_state(mc->dev);
730 return 0;
732 remove_nodes:
733 icc_nodes_remove(&mc->provider);
734 del_provider:
735 icc_provider_del(&mc->provider);
737 return err;
740 static int tegra_mc_probe(struct platform_device *pdev)
742 struct resource *res;
743 struct tegra_mc *mc;
744 void *isr;
745 u64 mask;
746 int err;
748 mc = devm_kzalloc(&pdev->dev, sizeof(*mc), GFP_KERNEL);
749 if (!mc)
750 return -ENOMEM;
752 platform_set_drvdata(pdev, mc);
753 spin_lock_init(&mc->lock);
754 mc->soc = of_device_get_match_data(&pdev->dev);
755 mc->dev = &pdev->dev;
757 mask = DMA_BIT_MASK(mc->soc->num_address_bits);
759 err = dma_coerce_mask_and_coherent(&pdev->dev, mask);
760 if (err < 0) {
761 dev_err(&pdev->dev, "failed to set DMA mask: %d\n", err);
762 return err;
765 /* length of MC tick in nanoseconds */
766 mc->tick = 30;
768 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
769 mc->regs = devm_ioremap_resource(&pdev->dev, res);
770 if (IS_ERR(mc->regs))
771 return PTR_ERR(mc->regs);
773 mc->clk = devm_clk_get(&pdev->dev, "mc");
774 if (IS_ERR(mc->clk)) {
775 dev_err(&pdev->dev, "failed to get MC clock: %ld\n",
776 PTR_ERR(mc->clk));
777 return PTR_ERR(mc->clk);
780 #ifdef CONFIG_ARCH_TEGRA_2x_SOC
781 if (mc->soc == &tegra20_mc_soc) {
782 isr = tegra20_mc_irq;
783 } else
784 #endif
786 /* ensure that debug features are disabled */
787 mc_writel(mc, 0x00000000, MC_TIMING_CONTROL_DBG);
789 err = tegra_mc_setup_latency_allowance(mc);
790 if (err < 0) {
791 dev_err(&pdev->dev,
792 "failed to setup latency allowance: %d\n",
793 err);
794 return err;
797 isr = tegra_mc_irq;
799 err = tegra_mc_setup_timings(mc);
800 if (err < 0) {
801 dev_err(&pdev->dev, "failed to setup timings: %d\n",
802 err);
803 return err;
807 mc->irq = platform_get_irq(pdev, 0);
808 if (mc->irq < 0)
809 return mc->irq;
811 WARN(!mc->soc->client_id_mask, "missing client ID mask for this SoC\n");
813 mc_writel(mc, mc->soc->intmask, MC_INTMASK);
815 err = devm_request_irq(&pdev->dev, mc->irq, isr, 0,
816 dev_name(&pdev->dev), mc);
817 if (err < 0) {
818 dev_err(&pdev->dev, "failed to request IRQ#%u: %d\n", mc->irq,
819 err);
820 return err;
823 err = tegra_mc_reset_setup(mc);
824 if (err < 0)
825 dev_err(&pdev->dev, "failed to register reset controller: %d\n",
826 err);
828 err = tegra_mc_interconnect_setup(mc);
829 if (err < 0)
830 dev_err(&pdev->dev, "failed to initialize interconnect: %d\n",
831 err);
833 if (IS_ENABLED(CONFIG_TEGRA_IOMMU_SMMU) && mc->soc->smmu) {
834 mc->smmu = tegra_smmu_probe(&pdev->dev, mc->soc->smmu, mc);
835 if (IS_ERR(mc->smmu)) {
836 dev_err(&pdev->dev, "failed to probe SMMU: %ld\n",
837 PTR_ERR(mc->smmu));
838 mc->smmu = NULL;
842 if (IS_ENABLED(CONFIG_TEGRA_IOMMU_GART) && !mc->soc->smmu) {
843 mc->gart = tegra_gart_probe(&pdev->dev, mc);
844 if (IS_ERR(mc->gart)) {
845 dev_err(&pdev->dev, "failed to probe GART: %ld\n",
846 PTR_ERR(mc->gart));
847 mc->gart = NULL;
851 return 0;
854 static int tegra_mc_suspend(struct device *dev)
856 struct tegra_mc *mc = dev_get_drvdata(dev);
857 int err;
859 if (IS_ENABLED(CONFIG_TEGRA_IOMMU_GART) && mc->gart) {
860 err = tegra_gart_suspend(mc->gart);
861 if (err)
862 return err;
865 return 0;
868 static int tegra_mc_resume(struct device *dev)
870 struct tegra_mc *mc = dev_get_drvdata(dev);
871 int err;
873 if (IS_ENABLED(CONFIG_TEGRA_IOMMU_GART) && mc->gart) {
874 err = tegra_gart_resume(mc->gart);
875 if (err)
876 return err;
879 return 0;
882 static const struct dev_pm_ops tegra_mc_pm_ops = {
883 .suspend = tegra_mc_suspend,
884 .resume = tegra_mc_resume,
887 static struct platform_driver tegra_mc_driver = {
888 .driver = {
889 .name = "tegra-mc",
890 .of_match_table = tegra_mc_of_match,
891 .pm = &tegra_mc_pm_ops,
892 .suppress_bind_attrs = true,
894 .prevent_deferred_probe = true,
895 .probe = tegra_mc_probe,
898 static int tegra_mc_init(void)
900 return platform_driver_register(&tegra_mc_driver);
902 arch_initcall(tegra_mc_init);
904 MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
905 MODULE_DESCRIPTION("NVIDIA Tegra Memory Controller driver");
906 MODULE_LICENSE("GPL v2");