1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2015-2016 MediaTek Inc.
6 #include <linux/memblock.h>
9 #include <linux/component.h>
10 #include <linux/device.h>
11 #include <linux/dma-iommu.h>
12 #include <linux/err.h>
13 #include <linux/interrupt.h>
15 #include <linux/iommu.h>
16 #include <linux/iopoll.h>
17 #include <linux/list.h>
18 #include <linux/of_address.h>
19 #include <linux/of_iommu.h>
20 #include <linux/of_irq.h>
21 #include <linux/of_platform.h>
22 #include <linux/platform_device.h>
23 #include <linux/slab.h>
24 #include <linux/spinlock.h>
25 #include <asm/barrier.h>
26 #include <soc/mediatek/smi.h>
28 #include "mtk_iommu.h"
30 #define REG_MMU_PT_BASE_ADDR 0x000
32 #define REG_MMU_INVALIDATE 0x020
33 #define F_ALL_INVLD 0x2
34 #define F_MMU_INV_RANGE 0x1
36 #define REG_MMU_INVLD_START_A 0x024
37 #define REG_MMU_INVLD_END_A 0x028
39 #define REG_MMU_INV_SEL 0x038
40 #define F_INVLD_EN0 BIT(0)
41 #define F_INVLD_EN1 BIT(1)
43 #define REG_MMU_STANDARD_AXI_MODE 0x048
44 #define REG_MMU_DCM_DIS 0x050
46 #define REG_MMU_CTRL_REG 0x110
47 #define F_MMU_PREFETCH_RT_REPLACE_MOD BIT(4)
48 #define F_MMU_TF_PROTECT_SEL_SHIFT(data) \
49 ((data)->m4u_plat == M4U_MT2712 ? 4 : 5)
50 /* It's named by F_MMU_TF_PROT_SEL in mt2712. */
51 #define F_MMU_TF_PROTECT_SEL(prot, data) \
52 (((prot) & 0x3) << F_MMU_TF_PROTECT_SEL_SHIFT(data))
54 #define REG_MMU_IVRP_PADDR 0x114
56 #define REG_MMU_VLD_PA_RNG 0x118
57 #define F_MMU_VLD_PA_RNG(EA, SA) (((EA) << 8) | (SA))
59 #define REG_MMU_INT_CONTROL0 0x120
60 #define F_L2_MULIT_HIT_EN BIT(0)
61 #define F_TABLE_WALK_FAULT_INT_EN BIT(1)
62 #define F_PREETCH_FIFO_OVERFLOW_INT_EN BIT(2)
63 #define F_MISS_FIFO_OVERFLOW_INT_EN BIT(3)
64 #define F_PREFETCH_FIFO_ERR_INT_EN BIT(5)
65 #define F_MISS_FIFO_ERR_INT_EN BIT(6)
66 #define F_INT_CLR_BIT BIT(12)
68 #define REG_MMU_INT_MAIN_CONTROL 0x124
69 #define F_INT_TRANSLATION_FAULT BIT(0)
70 #define F_INT_MAIN_MULTI_HIT_FAULT BIT(1)
71 #define F_INT_INVALID_PA_FAULT BIT(2)
72 #define F_INT_ENTRY_REPLACEMENT_FAULT BIT(3)
73 #define F_INT_TLB_MISS_FAULT BIT(4)
74 #define F_INT_MISS_TRANSACTION_FIFO_FAULT BIT(5)
75 #define F_INT_PRETETCH_TRANSATION_FIFO_FAULT BIT(6)
77 #define REG_MMU_CPE_DONE 0x12C
79 #define REG_MMU_FAULT_ST1 0x134
81 #define REG_MMU_FAULT_VA 0x13c
82 #define F_MMU_FAULT_VA_WRITE_BIT BIT(1)
83 #define F_MMU_FAULT_VA_LAYER_BIT BIT(0)
85 #define REG_MMU_INVLD_PA 0x140
86 #define REG_MMU_INT_ID 0x150
87 #define F_MMU0_INT_ID_LARB_ID(a) (((a) >> 7) & 0x7)
88 #define F_MMU0_INT_ID_PORT_ID(a) (((a) >> 2) & 0x1f)
90 #define MTK_PROTECT_PA_ALIGN 128
93 * Get the local arbiter ID and the portid within the larb arbiter
94 * from mtk_m4u_id which is defined by MTK_M4U_ID.
96 #define MTK_M4U_TO_LARB(id) (((id) >> 5) & 0xf)
97 #define MTK_M4U_TO_PORT(id) ((id) & 0x1f)
99 struct mtk_iommu_domain {
100 spinlock_t pgtlock; /* lock for page table */
102 struct io_pgtable_cfg cfg;
103 struct io_pgtable_ops *iop;
105 struct iommu_domain domain;
108 static const struct iommu_ops mtk_iommu_ops;
110 static LIST_HEAD(m4ulist); /* List all the M4U HWs */
112 #define for_each_m4u(data) list_for_each_entry(data, &m4ulist, list)
115 * There may be 1 or 2 M4U HWs, But we always expect they are in the same domain
116 * for the performance.
118 * Here always return the mtk_iommu_data of the first probed M4U where the
119 * iommu domain information is recorded.
121 static struct mtk_iommu_data *mtk_iommu_get_m4u_data(void)
123 struct mtk_iommu_data *data;
131 static struct mtk_iommu_domain *to_mtk_domain(struct iommu_domain *dom)
133 return container_of(dom, struct mtk_iommu_domain, domain);
136 static void mtk_iommu_tlb_flush_all(void *cookie)
138 struct mtk_iommu_data *data = cookie;
141 writel_relaxed(F_INVLD_EN1 | F_INVLD_EN0,
142 data->base + REG_MMU_INV_SEL);
143 writel_relaxed(F_ALL_INVLD, data->base + REG_MMU_INVALIDATE);
144 wmb(); /* Make sure the tlb flush all done */
148 static void mtk_iommu_tlb_add_flush_nosync(unsigned long iova, size_t size,
149 size_t granule, bool leaf,
152 struct mtk_iommu_data *data = cookie;
155 writel_relaxed(F_INVLD_EN1 | F_INVLD_EN0,
156 data->base + REG_MMU_INV_SEL);
158 writel_relaxed(iova, data->base + REG_MMU_INVLD_START_A);
159 writel_relaxed(iova + size - 1,
160 data->base + REG_MMU_INVLD_END_A);
161 writel_relaxed(F_MMU_INV_RANGE,
162 data->base + REG_MMU_INVALIDATE);
163 data->tlb_flush_active = true;
167 static void mtk_iommu_tlb_sync(void *cookie)
169 struct mtk_iommu_data *data = cookie;
174 /* Avoid timing out if there's nothing to wait for */
175 if (!data->tlb_flush_active)
178 ret = readl_poll_timeout_atomic(data->base + REG_MMU_CPE_DONE,
179 tmp, tmp != 0, 10, 100000);
182 "Partial TLB flush timed out, falling back to full flush\n");
183 mtk_iommu_tlb_flush_all(cookie);
185 /* Clear the CPE status */
186 writel_relaxed(0, data->base + REG_MMU_CPE_DONE);
187 data->tlb_flush_active = false;
191 static const struct iommu_gather_ops mtk_iommu_gather_ops = {
192 .tlb_flush_all = mtk_iommu_tlb_flush_all,
193 .tlb_add_flush = mtk_iommu_tlb_add_flush_nosync,
194 .tlb_sync = mtk_iommu_tlb_sync,
197 static irqreturn_t mtk_iommu_isr(int irq, void *dev_id)
199 struct mtk_iommu_data *data = dev_id;
200 struct mtk_iommu_domain *dom = data->m4u_dom;
201 u32 int_state, regval, fault_iova, fault_pa;
202 unsigned int fault_larb, fault_port;
205 /* Read error info from registers */
206 int_state = readl_relaxed(data->base + REG_MMU_FAULT_ST1);
207 fault_iova = readl_relaxed(data->base + REG_MMU_FAULT_VA);
208 layer = fault_iova & F_MMU_FAULT_VA_LAYER_BIT;
209 write = fault_iova & F_MMU_FAULT_VA_WRITE_BIT;
210 fault_pa = readl_relaxed(data->base + REG_MMU_INVLD_PA);
211 regval = readl_relaxed(data->base + REG_MMU_INT_ID);
212 fault_larb = F_MMU0_INT_ID_LARB_ID(regval);
213 fault_port = F_MMU0_INT_ID_PORT_ID(regval);
215 if (report_iommu_fault(&dom->domain, data->dev, fault_iova,
216 write ? IOMMU_FAULT_WRITE : IOMMU_FAULT_READ)) {
219 "fault type=0x%x iova=0x%x pa=0x%x larb=%d port=%d layer=%d %s\n",
220 int_state, fault_iova, fault_pa, fault_larb, fault_port,
221 layer, write ? "write" : "read");
224 /* Interrupt clear */
225 regval = readl_relaxed(data->base + REG_MMU_INT_CONTROL0);
226 regval |= F_INT_CLR_BIT;
227 writel_relaxed(regval, data->base + REG_MMU_INT_CONTROL0);
229 mtk_iommu_tlb_flush_all(data);
234 static void mtk_iommu_config(struct mtk_iommu_data *data,
235 struct device *dev, bool enable)
237 struct mtk_smi_larb_iommu *larb_mmu;
238 unsigned int larbid, portid;
239 struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
242 for (i = 0; i < fwspec->num_ids; ++i) {
243 larbid = MTK_M4U_TO_LARB(fwspec->ids[i]);
244 portid = MTK_M4U_TO_PORT(fwspec->ids[i]);
245 larb_mmu = &data->smi_imu.larb_imu[larbid];
247 dev_dbg(dev, "%s iommu port: %d\n",
248 enable ? "enable" : "disable", portid);
251 larb_mmu->mmu |= MTK_SMI_MMU_EN(portid);
253 larb_mmu->mmu &= ~MTK_SMI_MMU_EN(portid);
257 static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom)
259 struct mtk_iommu_data *data = mtk_iommu_get_m4u_data();
261 spin_lock_init(&dom->pgtlock);
263 dom->cfg = (struct io_pgtable_cfg) {
264 .quirks = IO_PGTABLE_QUIRK_ARM_NS |
265 IO_PGTABLE_QUIRK_NO_PERMS |
266 IO_PGTABLE_QUIRK_TLBI_ON_MAP,
267 .pgsize_bitmap = mtk_iommu_ops.pgsize_bitmap,
270 .tlb = &mtk_iommu_gather_ops,
271 .iommu_dev = data->dev,
274 if (data->enable_4GB)
275 dom->cfg.quirks |= IO_PGTABLE_QUIRK_ARM_MTK_4GB;
277 dom->iop = alloc_io_pgtable_ops(ARM_V7S, &dom->cfg, data);
279 dev_err(data->dev, "Failed to alloc io pgtable\n");
283 /* Update our support page sizes bitmap */
284 dom->domain.pgsize_bitmap = dom->cfg.pgsize_bitmap;
288 static struct iommu_domain *mtk_iommu_domain_alloc(unsigned type)
290 struct mtk_iommu_domain *dom;
292 if (type != IOMMU_DOMAIN_DMA)
295 dom = kzalloc(sizeof(*dom), GFP_KERNEL);
299 if (iommu_get_dma_cookie(&dom->domain))
302 if (mtk_iommu_domain_finalise(dom))
305 dom->domain.geometry.aperture_start = 0;
306 dom->domain.geometry.aperture_end = DMA_BIT_MASK(32);
307 dom->domain.geometry.force_aperture = true;
312 iommu_put_dma_cookie(&dom->domain);
318 static void mtk_iommu_domain_free(struct iommu_domain *domain)
320 struct mtk_iommu_domain *dom = to_mtk_domain(domain);
322 free_io_pgtable_ops(dom->iop);
323 iommu_put_dma_cookie(domain);
324 kfree(to_mtk_domain(domain));
327 static int mtk_iommu_attach_device(struct iommu_domain *domain,
330 struct mtk_iommu_domain *dom = to_mtk_domain(domain);
331 struct mtk_iommu_data *data = dev_iommu_fwspec_get(dev)->iommu_priv;
336 /* Update the pgtable base address register of the M4U HW */
337 if (!data->m4u_dom) {
339 writel(dom->cfg.arm_v7s_cfg.ttbr[0],
340 data->base + REG_MMU_PT_BASE_ADDR);
343 mtk_iommu_config(data, dev, true);
347 static void mtk_iommu_detach_device(struct iommu_domain *domain,
350 struct mtk_iommu_data *data = dev_iommu_fwspec_get(dev)->iommu_priv;
355 mtk_iommu_config(data, dev, false);
358 static int mtk_iommu_map(struct iommu_domain *domain, unsigned long iova,
359 phys_addr_t paddr, size_t size, int prot)
361 struct mtk_iommu_domain *dom = to_mtk_domain(domain);
365 spin_lock_irqsave(&dom->pgtlock, flags);
366 ret = dom->iop->map(dom->iop, iova, paddr & DMA_BIT_MASK(32),
368 spin_unlock_irqrestore(&dom->pgtlock, flags);
373 static size_t mtk_iommu_unmap(struct iommu_domain *domain,
374 unsigned long iova, size_t size)
376 struct mtk_iommu_domain *dom = to_mtk_domain(domain);
380 spin_lock_irqsave(&dom->pgtlock, flags);
381 unmapsz = dom->iop->unmap(dom->iop, iova, size);
382 spin_unlock_irqrestore(&dom->pgtlock, flags);
387 static void mtk_iommu_iotlb_sync(struct iommu_domain *domain)
389 mtk_iommu_tlb_sync(mtk_iommu_get_m4u_data());
392 static phys_addr_t mtk_iommu_iova_to_phys(struct iommu_domain *domain,
395 struct mtk_iommu_domain *dom = to_mtk_domain(domain);
396 struct mtk_iommu_data *data = mtk_iommu_get_m4u_data();
400 spin_lock_irqsave(&dom->pgtlock, flags);
401 pa = dom->iop->iova_to_phys(dom->iop, iova);
402 spin_unlock_irqrestore(&dom->pgtlock, flags);
404 if (data->enable_4GB)
410 static int mtk_iommu_add_device(struct device *dev)
412 struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
413 struct mtk_iommu_data *data;
414 struct iommu_group *group;
416 if (!fwspec || fwspec->ops != &mtk_iommu_ops)
417 return -ENODEV; /* Not a iommu client device */
419 data = fwspec->iommu_priv;
420 iommu_device_link(&data->iommu, dev);
422 group = iommu_group_get_for_dev(dev);
424 return PTR_ERR(group);
426 iommu_group_put(group);
430 static void mtk_iommu_remove_device(struct device *dev)
432 struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
433 struct mtk_iommu_data *data;
435 if (!fwspec || fwspec->ops != &mtk_iommu_ops)
438 data = fwspec->iommu_priv;
439 iommu_device_unlink(&data->iommu, dev);
441 iommu_group_remove_device(dev);
442 iommu_fwspec_free(dev);
445 static struct iommu_group *mtk_iommu_device_group(struct device *dev)
447 struct mtk_iommu_data *data = mtk_iommu_get_m4u_data();
450 return ERR_PTR(-ENODEV);
452 /* All the client devices are in the same m4u iommu-group */
453 if (!data->m4u_group) {
454 data->m4u_group = iommu_group_alloc();
455 if (IS_ERR(data->m4u_group))
456 dev_err(dev, "Failed to allocate M4U IOMMU group\n");
458 iommu_group_ref_get(data->m4u_group);
460 return data->m4u_group;
463 static int mtk_iommu_of_xlate(struct device *dev, struct of_phandle_args *args)
465 struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
466 struct platform_device *m4updev;
468 if (args->args_count != 1) {
469 dev_err(dev, "invalid #iommu-cells(%d) property for IOMMU\n",
474 if (!fwspec->iommu_priv) {
475 /* Get the m4u device */
476 m4updev = of_find_device_by_node(args->np);
477 if (WARN_ON(!m4updev))
480 fwspec->iommu_priv = platform_get_drvdata(m4updev);
483 return iommu_fwspec_add_ids(dev, args->args, 1);
486 static const struct iommu_ops mtk_iommu_ops = {
487 .domain_alloc = mtk_iommu_domain_alloc,
488 .domain_free = mtk_iommu_domain_free,
489 .attach_dev = mtk_iommu_attach_device,
490 .detach_dev = mtk_iommu_detach_device,
491 .map = mtk_iommu_map,
492 .unmap = mtk_iommu_unmap,
493 .flush_iotlb_all = mtk_iommu_iotlb_sync,
494 .iotlb_sync = mtk_iommu_iotlb_sync,
495 .iova_to_phys = mtk_iommu_iova_to_phys,
496 .add_device = mtk_iommu_add_device,
497 .remove_device = mtk_iommu_remove_device,
498 .device_group = mtk_iommu_device_group,
499 .of_xlate = mtk_iommu_of_xlate,
500 .pgsize_bitmap = SZ_4K | SZ_64K | SZ_1M | SZ_16M,
503 static int mtk_iommu_hw_init(const struct mtk_iommu_data *data)
508 ret = clk_prepare_enable(data->bclk);
510 dev_err(data->dev, "Failed to enable iommu bclk(%d)\n", ret);
514 regval = F_MMU_TF_PROTECT_SEL(2, data);
515 if (data->m4u_plat == M4U_MT8173)
516 regval |= F_MMU_PREFETCH_RT_REPLACE_MOD;
517 writel_relaxed(regval, data->base + REG_MMU_CTRL_REG);
519 regval = F_L2_MULIT_HIT_EN |
520 F_TABLE_WALK_FAULT_INT_EN |
521 F_PREETCH_FIFO_OVERFLOW_INT_EN |
522 F_MISS_FIFO_OVERFLOW_INT_EN |
523 F_PREFETCH_FIFO_ERR_INT_EN |
524 F_MISS_FIFO_ERR_INT_EN;
525 writel_relaxed(regval, data->base + REG_MMU_INT_CONTROL0);
527 regval = F_INT_TRANSLATION_FAULT |
528 F_INT_MAIN_MULTI_HIT_FAULT |
529 F_INT_INVALID_PA_FAULT |
530 F_INT_ENTRY_REPLACEMENT_FAULT |
531 F_INT_TLB_MISS_FAULT |
532 F_INT_MISS_TRANSACTION_FIFO_FAULT |
533 F_INT_PRETETCH_TRANSATION_FIFO_FAULT;
534 writel_relaxed(regval, data->base + REG_MMU_INT_MAIN_CONTROL);
536 if (data->m4u_plat == M4U_MT8173)
537 regval = (data->protect_base >> 1) | (data->enable_4GB << 31);
539 regval = lower_32_bits(data->protect_base) |
540 upper_32_bits(data->protect_base);
541 writel_relaxed(regval, data->base + REG_MMU_IVRP_PADDR);
543 if (data->enable_4GB && data->m4u_plat != M4U_MT8173) {
545 * If 4GB mode is enabled, the validate PA range is from
546 * 0x1_0000_0000 to 0x1_ffff_ffff. here record bit[32:30].
548 regval = F_MMU_VLD_PA_RNG(7, 4);
549 writel_relaxed(regval, data->base + REG_MMU_VLD_PA_RNG);
551 writel_relaxed(0, data->base + REG_MMU_DCM_DIS);
553 /* It's MISC control register whose default value is ok except mt8173.*/
554 if (data->m4u_plat == M4U_MT8173)
555 writel_relaxed(0, data->base + REG_MMU_STANDARD_AXI_MODE);
557 if (devm_request_irq(data->dev, data->irq, mtk_iommu_isr, 0,
558 dev_name(data->dev), (void *)data)) {
559 writel_relaxed(0, data->base + REG_MMU_PT_BASE_ADDR);
560 clk_disable_unprepare(data->bclk);
561 dev_err(data->dev, "Failed @ IRQ-%d Request\n", data->irq);
568 static const struct component_master_ops mtk_iommu_com_ops = {
569 .bind = mtk_iommu_bind,
570 .unbind = mtk_iommu_unbind,
573 static int mtk_iommu_probe(struct platform_device *pdev)
575 struct mtk_iommu_data *data;
576 struct device *dev = &pdev->dev;
577 struct resource *res;
578 resource_size_t ioaddr;
579 struct component_match *match = NULL;
583 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
587 data->m4u_plat = (enum mtk_iommu_plat)of_device_get_match_data(dev);
589 /* Protect memory. HW will access here while translation fault.*/
590 protect = devm_kzalloc(dev, MTK_PROTECT_PA_ALIGN * 2, GFP_KERNEL);
593 data->protect_base = ALIGN(virt_to_phys(protect), MTK_PROTECT_PA_ALIGN);
595 /* Whether the current dram is over 4GB */
596 data->enable_4GB = !!(max_pfn > (BIT_ULL(32) >> PAGE_SHIFT));
598 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
599 data->base = devm_ioremap_resource(dev, res);
600 if (IS_ERR(data->base))
601 return PTR_ERR(data->base);
604 data->irq = platform_get_irq(pdev, 0);
608 data->bclk = devm_clk_get(dev, "bclk");
609 if (IS_ERR(data->bclk))
610 return PTR_ERR(data->bclk);
612 larb_nr = of_count_phandle_with_args(dev->of_node,
613 "mediatek,larbs", NULL);
616 data->smi_imu.larb_nr = larb_nr;
618 for (i = 0; i < larb_nr; i++) {
619 struct device_node *larbnode;
620 struct platform_device *plarbdev;
623 larbnode = of_parse_phandle(dev->of_node, "mediatek,larbs", i);
627 if (!of_device_is_available(larbnode)) {
628 of_node_put(larbnode);
632 ret = of_property_read_u32(larbnode, "mediatek,larb-id", &id);
633 if (ret)/* The id is consecutive if there is no this property */
636 plarbdev = of_find_device_by_node(larbnode);
638 of_node_put(larbnode);
639 return -EPROBE_DEFER;
641 data->smi_imu.larb_imu[id].dev = &plarbdev->dev;
643 component_match_add_release(dev, &match, release_of,
644 compare_of, larbnode);
647 platform_set_drvdata(pdev, data);
649 ret = mtk_iommu_hw_init(data);
653 ret = iommu_device_sysfs_add(&data->iommu, dev, NULL,
654 "mtk-iommu.%pa", &ioaddr);
658 iommu_device_set_ops(&data->iommu, &mtk_iommu_ops);
659 iommu_device_set_fwnode(&data->iommu, &pdev->dev.of_node->fwnode);
661 ret = iommu_device_register(&data->iommu);
665 list_add_tail(&data->list, &m4ulist);
667 if (!iommu_present(&platform_bus_type))
668 bus_set_iommu(&platform_bus_type, &mtk_iommu_ops);
670 return component_master_add_with_match(dev, &mtk_iommu_com_ops, match);
673 static int mtk_iommu_remove(struct platform_device *pdev)
675 struct mtk_iommu_data *data = platform_get_drvdata(pdev);
677 iommu_device_sysfs_remove(&data->iommu);
678 iommu_device_unregister(&data->iommu);
680 if (iommu_present(&platform_bus_type))
681 bus_set_iommu(&platform_bus_type, NULL);
683 clk_disable_unprepare(data->bclk);
684 devm_free_irq(&pdev->dev, data->irq, data);
685 component_master_del(&pdev->dev, &mtk_iommu_com_ops);
689 static int __maybe_unused mtk_iommu_suspend(struct device *dev)
691 struct mtk_iommu_data *data = dev_get_drvdata(dev);
692 struct mtk_iommu_suspend_reg *reg = &data->reg;
693 void __iomem *base = data->base;
695 reg->standard_axi_mode = readl_relaxed(base +
696 REG_MMU_STANDARD_AXI_MODE);
697 reg->dcm_dis = readl_relaxed(base + REG_MMU_DCM_DIS);
698 reg->ctrl_reg = readl_relaxed(base + REG_MMU_CTRL_REG);
699 reg->int_control0 = readl_relaxed(base + REG_MMU_INT_CONTROL0);
700 reg->int_main_control = readl_relaxed(base + REG_MMU_INT_MAIN_CONTROL);
701 reg->ivrp_paddr = readl_relaxed(base + REG_MMU_IVRP_PADDR);
702 clk_disable_unprepare(data->bclk);
706 static int __maybe_unused mtk_iommu_resume(struct device *dev)
708 struct mtk_iommu_data *data = dev_get_drvdata(dev);
709 struct mtk_iommu_suspend_reg *reg = &data->reg;
710 void __iomem *base = data->base;
713 ret = clk_prepare_enable(data->bclk);
715 dev_err(data->dev, "Failed to enable clk(%d) in resume\n", ret);
718 writel_relaxed(reg->standard_axi_mode,
719 base + REG_MMU_STANDARD_AXI_MODE);
720 writel_relaxed(reg->dcm_dis, base + REG_MMU_DCM_DIS);
721 writel_relaxed(reg->ctrl_reg, base + REG_MMU_CTRL_REG);
722 writel_relaxed(reg->int_control0, base + REG_MMU_INT_CONTROL0);
723 writel_relaxed(reg->int_main_control, base + REG_MMU_INT_MAIN_CONTROL);
724 writel_relaxed(reg->ivrp_paddr, base + REG_MMU_IVRP_PADDR);
726 writel(data->m4u_dom->cfg.arm_v7s_cfg.ttbr[0],
727 base + REG_MMU_PT_BASE_ADDR);
731 static const struct dev_pm_ops mtk_iommu_pm_ops = {
732 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(mtk_iommu_suspend, mtk_iommu_resume)
735 static const struct of_device_id mtk_iommu_of_ids[] = {
736 { .compatible = "mediatek,mt2712-m4u", .data = (void *)M4U_MT2712},
737 { .compatible = "mediatek,mt8173-m4u", .data = (void *)M4U_MT8173},
741 static struct platform_driver mtk_iommu_driver = {
742 .probe = mtk_iommu_probe,
743 .remove = mtk_iommu_remove,
746 .of_match_table = of_match_ptr(mtk_iommu_of_ids),
747 .pm = &mtk_iommu_pm_ops,
751 static int __init mtk_iommu_init(void)
755 ret = platform_driver_register(&mtk_iommu_driver);
757 pr_err("Failed to register MTK IOMMU driver\n");
762 subsys_initcall(mtk_iommu_init)