1 // SPDX-License-Identifier: ISC
3 * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
9 static u32
mt76_mmio_rr(struct mt76_dev
*dev
, u32 offset
)
13 val
= readl(dev
->mmio
.regs
+ offset
);
14 trace_reg_rr(dev
, offset
, val
);
19 static void mt76_mmio_wr(struct mt76_dev
*dev
, u32 offset
, u32 val
)
21 trace_reg_wr(dev
, offset
, val
);
22 writel(val
, dev
->mmio
.regs
+ offset
);
25 static u32
mt76_mmio_rmw(struct mt76_dev
*dev
, u32 offset
, u32 mask
, u32 val
)
27 val
|= mt76_mmio_rr(dev
, offset
) & ~mask
;
28 mt76_mmio_wr(dev
, offset
, val
);
32 static void mt76_mmio_write_copy(struct mt76_dev
*dev
, u32 offset
,
33 const void *data
, int len
)
35 __iowrite32_copy(dev
->mmio
.regs
+ offset
, data
, DIV_ROUND_UP(len
, 4));
38 static void mt76_mmio_read_copy(struct mt76_dev
*dev
, u32 offset
,
41 __ioread32_copy(data
, dev
->mmio
.regs
+ offset
, DIV_ROUND_UP(len
, 4));
44 static int mt76_mmio_wr_rp(struct mt76_dev
*dev
, u32 base
,
45 const struct mt76_reg_pair
*data
, int len
)
48 mt76_mmio_wr(dev
, data
->reg
, data
->value
);
56 static int mt76_mmio_rd_rp(struct mt76_dev
*dev
, u32 base
,
57 struct mt76_reg_pair
*data
, int len
)
60 data
->value
= mt76_mmio_rr(dev
, data
->reg
);
68 void mt76_set_irq_mask(struct mt76_dev
*dev
, u32 addr
,
73 spin_lock_irqsave(&dev
->mmio
.irq_lock
, flags
);
74 dev
->mmio
.irqmask
&= ~clear
;
75 dev
->mmio
.irqmask
|= set
;
77 mt76_mmio_wr(dev
, addr
, dev
->mmio
.irqmask
);
78 spin_unlock_irqrestore(&dev
->mmio
.irq_lock
, flags
);
80 EXPORT_SYMBOL_GPL(mt76_set_irq_mask
);
82 void mt76_mmio_init(struct mt76_dev
*dev
, void __iomem
*regs
)
84 static const struct mt76_bus_ops mt76_mmio_ops
= {
88 .write_copy
= mt76_mmio_write_copy
,
89 .read_copy
= mt76_mmio_read_copy
,
90 .wr_rp
= mt76_mmio_wr_rp
,
91 .rd_rp
= mt76_mmio_rd_rp
,
92 .type
= MT76_BUS_MMIO
,
95 dev
->bus
= &mt76_mmio_ops
;
96 dev
->mmio
.regs
= regs
;
98 spin_lock_init(&dev
->mmio
.irq_lock
);
100 EXPORT_SYMBOL_GPL(mt76_mmio_init
);