2 * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 static u32
mt76_mmio_rr(struct mt76_dev
*dev
, u32 offset
)
24 val
= ioread32(dev
->mmio
.regs
+ offset
);
25 trace_reg_rr(dev
, offset
, val
);
30 static void mt76_mmio_wr(struct mt76_dev
*dev
, u32 offset
, u32 val
)
32 trace_reg_wr(dev
, offset
, val
);
33 iowrite32(val
, dev
->mmio
.regs
+ offset
);
36 static u32
mt76_mmio_rmw(struct mt76_dev
*dev
, u32 offset
, u32 mask
, u32 val
)
38 val
|= mt76_mmio_rr(dev
, offset
) & ~mask
;
39 mt76_mmio_wr(dev
, offset
, val
);
43 static void mt76_mmio_copy(struct mt76_dev
*dev
, u32 offset
, const void *data
,
46 __iowrite32_copy(dev
->mmio
.regs
+ offset
, data
, len
>> 2);
49 static int mt76_mmio_wr_rp(struct mt76_dev
*dev
, u32 base
,
50 const struct mt76_reg_pair
*data
, int len
)
53 mt76_mmio_wr(dev
, data
->reg
, data
->value
);
61 static int mt76_mmio_rd_rp(struct mt76_dev
*dev
, u32 base
,
62 struct mt76_reg_pair
*data
, int len
)
65 data
->value
= mt76_mmio_rr(dev
, data
->reg
);
73 void mt76_mmio_init(struct mt76_dev
*dev
, void __iomem
*regs
)
75 static const struct mt76_bus_ops mt76_mmio_ops
= {
79 .copy
= mt76_mmio_copy
,
80 .wr_rp
= mt76_mmio_wr_rp
,
81 .rd_rp
= mt76_mmio_rd_rp
,
82 .type
= MT76_BUS_MMIO
,
85 dev
->bus
= &mt76_mmio_ops
;
86 dev
->mmio
.regs
= regs
;
88 skb_queue_head_init(&dev
->mmio
.mcu
.res_q
);
89 init_waitqueue_head(&dev
->mmio
.mcu
.wait
);
90 spin_lock_init(&dev
->mmio
.irq_lock
);
91 mutex_init(&dev
->mmio
.mcu
.mutex
);
93 EXPORT_SYMBOL_GPL(mt76_mmio_init
);