2019-07-24 16:58:20 +08:00
|
|
|
// SPDX-License-Identifier: ISC
|
2017-11-21 17:50:52 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mt76.h"
|
|
|
|
#include "trace.h"
|
|
|
|
|
|
|
|
static u32 mt76_mmio_rr(struct mt76_dev *dev, u32 offset)
|
|
|
|
{
|
|
|
|
u32 val;
|
|
|
|
|
2019-03-23 22:24:56 +08:00
|
|
|
val = readl(dev->mmio.regs + offset);
|
2017-11-21 17:50:52 +08:00
|
|
|
trace_reg_rr(dev, offset, val);
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mt76_mmio_wr(struct mt76_dev *dev, u32 offset, u32 val)
|
|
|
|
{
|
|
|
|
trace_reg_wr(dev, offset, val);
|
2019-03-23 22:24:56 +08:00
|
|
|
writel(val, dev->mmio.regs + offset);
|
2017-11-21 17:50:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static u32 mt76_mmio_rmw(struct mt76_dev *dev, u32 offset, u32 mask, u32 val)
|
|
|
|
{
|
|
|
|
val |= mt76_mmio_rr(dev, offset) & ~mask;
|
|
|
|
mt76_mmio_wr(dev, offset, val);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2019-07-13 23:09:06 +08:00
|
|
|
static void mt76_mmio_write_copy(struct mt76_dev *dev, u32 offset,
|
|
|
|
const void *data, int len)
|
2017-11-21 17:50:52 +08:00
|
|
|
{
|
2019-07-01 19:15:07 +08:00
|
|
|
__iowrite32_copy(dev->mmio.regs + offset, data, DIV_ROUND_UP(len, 4));
|
2017-11-21 17:50:52 +08:00
|
|
|
}
|
|
|
|
|
2019-07-13 23:09:06 +08:00
|
|
|
static void mt76_mmio_read_copy(struct mt76_dev *dev, u32 offset,
|
|
|
|
void *data, int len)
|
|
|
|
{
|
|
|
|
__ioread32_copy(data, dev->mmio.regs + offset, DIV_ROUND_UP(len, 4));
|
|
|
|
}
|
|
|
|
|
2018-09-28 19:38:50 +08:00
|
|
|
static int mt76_mmio_wr_rp(struct mt76_dev *dev, u32 base,
|
|
|
|
const struct mt76_reg_pair *data, int len)
|
|
|
|
{
|
|
|
|
while (len > 0) {
|
|
|
|
mt76_mmio_wr(dev, data->reg, data->value);
|
|
|
|
data++;
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mt76_mmio_rd_rp(struct mt76_dev *dev, u32 base,
|
|
|
|
struct mt76_reg_pair *data, int len)
|
|
|
|
{
|
|
|
|
while (len > 0) {
|
|
|
|
data->value = mt76_mmio_rr(dev, data->reg);
|
|
|
|
data++;
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-01 00:54:31 +08:00
|
|
|
void mt76_set_irq_mask(struct mt76_dev *dev, u32 addr,
|
|
|
|
u32 clear, u32 set)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&dev->mmio.irq_lock, flags);
|
|
|
|
dev->mmio.irqmask &= ~clear;
|
|
|
|
dev->mmio.irqmask |= set;
|
2020-04-09 20:37:50 +08:00
|
|
|
if (addr)
|
|
|
|
mt76_mmio_wr(dev, addr, dev->mmio.irqmask);
|
2019-03-01 00:54:31 +08:00
|
|
|
spin_unlock_irqrestore(&dev->mmio.irq_lock, flags);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mt76_set_irq_mask);
|
|
|
|
|
2017-11-21 17:50:52 +08:00
|
|
|
void mt76_mmio_init(struct mt76_dev *dev, void __iomem *regs)
|
|
|
|
{
|
|
|
|
static const struct mt76_bus_ops mt76_mmio_ops = {
|
|
|
|
.rr = mt76_mmio_rr,
|
|
|
|
.rmw = mt76_mmio_rmw,
|
|
|
|
.wr = mt76_mmio_wr,
|
2019-07-13 23:09:06 +08:00
|
|
|
.write_copy = mt76_mmio_write_copy,
|
|
|
|
.read_copy = mt76_mmio_read_copy,
|
2018-09-28 19:38:50 +08:00
|
|
|
.wr_rp = mt76_mmio_wr_rp,
|
|
|
|
.rd_rp = mt76_mmio_rd_rp,
|
2018-10-04 18:04:53 +08:00
|
|
|
.type = MT76_BUS_MMIO,
|
2017-11-21 17:50:52 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
dev->bus = &mt76_mmio_ops;
|
2018-09-10 05:57:58 +08:00
|
|
|
dev->mmio.regs = regs;
|
2018-09-10 05:57:57 +08:00
|
|
|
|
2018-09-28 19:38:47 +08:00
|
|
|
spin_lock_init(&dev->mmio.irq_lock);
|
2017-11-21 17:50:52 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(mt76_mmio_init);
|