1 // SPDX-License-Identifier: ISC
3 * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
10 static u32
mt76_mmio_rr(struct mt76_dev
*dev
, u32 offset
)
14 val
= readl(dev
->mmio
.regs
+ offset
);
15 trace_reg_rr(dev
, offset
, val
);
20 static void mt76_mmio_wr(struct mt76_dev
*dev
, u32 offset
, u32 val
)
22 trace_reg_wr(dev
, offset
, val
);
23 writel(val
, dev
->mmio
.regs
+ offset
);
26 static u32
mt76_mmio_rmw(struct mt76_dev
*dev
, u32 offset
, u32 mask
, u32 val
)
28 val
|= mt76_mmio_rr(dev
, offset
) & ~mask
;
29 mt76_mmio_wr(dev
, offset
, val
);
33 static void mt76_mmio_write_copy(struct mt76_dev
*dev
, u32 offset
,
34 const void *data
, int len
)
36 __iowrite32_copy(dev
->mmio
.regs
+ offset
, data
, DIV_ROUND_UP(len
, 4));
39 static void mt76_mmio_read_copy(struct mt76_dev
*dev
, u32 offset
,
42 __ioread32_copy(data
, dev
->mmio
.regs
+ offset
, DIV_ROUND_UP(len
, 4));
45 static int mt76_mmio_wr_rp(struct mt76_dev
*dev
, u32 base
,
46 const struct mt76_reg_pair
*data
, int len
)
49 mt76_mmio_wr(dev
, data
->reg
, data
->value
);
57 static int mt76_mmio_rd_rp(struct mt76_dev
*dev
, u32 base
,
58 struct mt76_reg_pair
*data
, int len
)
61 data
->value
= mt76_mmio_rr(dev
, data
->reg
);
69 void mt76_set_irq_mask(struct mt76_dev
*dev
, u32 addr
,
74 spin_lock_irqsave(&dev
->mmio
.irq_lock
, flags
);
75 dev
->mmio
.irqmask
&= ~clear
;
76 dev
->mmio
.irqmask
|= set
;
78 if (mtk_wed_device_active(&dev
->mmio
.wed
))
79 mtk_wed_device_irq_set_mask(&dev
->mmio
.wed
,
82 mt76_mmio_wr(dev
, addr
, dev
->mmio
.irqmask
);
84 spin_unlock_irqrestore(&dev
->mmio
.irq_lock
, flags
);
86 EXPORT_SYMBOL_GPL(mt76_set_irq_mask
);
88 void mt76_mmio_init(struct mt76_dev
*dev
, void __iomem
*regs
)
90 static const struct mt76_bus_ops mt76_mmio_ops
= {
94 .write_copy
= mt76_mmio_write_copy
,
95 .read_copy
= mt76_mmio_read_copy
,
96 .wr_rp
= mt76_mmio_wr_rp
,
97 .rd_rp
= mt76_mmio_rd_rp
,
98 .type
= MT76_BUS_MMIO
,
101 dev
->bus
= &mt76_mmio_ops
;
102 dev
->mmio
.regs
= regs
;
104 spin_lock_init(&dev
->mmio
.irq_lock
);
106 EXPORT_SYMBOL_GPL(mt76_mmio_init
);