| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: ISC |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name> |
|---|
| 3 | | - * |
|---|
| 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. |
|---|
| 7 | | - * |
|---|
| 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. |
|---|
| 15 | 4 | */ |
|---|
| 16 | 5 | |
|---|
| 17 | 6 | #include "mt76.h" |
|---|
| .. | .. |
|---|
| 21 | 10 | { |
|---|
| 22 | 11 | u32 val; |
|---|
| 23 | 12 | |
|---|
| 24 | | - val = ioread32(dev->regs + offset); |
|---|
| 13 | + val = readl(dev->mmio.regs + offset); |
|---|
| 25 | 14 | trace_reg_rr(dev, offset, val); |
|---|
| 26 | 15 | |
|---|
| 27 | 16 | return val; |
|---|
| .. | .. |
|---|
| 30 | 19 | static void mt76_mmio_wr(struct mt76_dev *dev, u32 offset, u32 val) |
|---|
| 31 | 20 | { |
|---|
| 32 | 21 | trace_reg_wr(dev, offset, val); |
|---|
| 33 | | - iowrite32(val, dev->regs + offset); |
|---|
| 22 | + writel(val, dev->mmio.regs + offset); |
|---|
| 34 | 23 | } |
|---|
| 35 | 24 | |
|---|
| 36 | 25 | static u32 mt76_mmio_rmw(struct mt76_dev *dev, u32 offset, u32 mask, u32 val) |
|---|
| .. | .. |
|---|
| 40 | 29 | return val; |
|---|
| 41 | 30 | } |
|---|
| 42 | 31 | |
|---|
| 43 | | -static void mt76_mmio_copy(struct mt76_dev *dev, u32 offset, const void *data, |
|---|
| 44 | | - int len) |
|---|
| 32 | +static void mt76_mmio_write_copy(struct mt76_dev *dev, u32 offset, |
|---|
| 33 | + const void *data, int len) |
|---|
| 45 | 34 | { |
|---|
| 46 | | - __iowrite32_copy(dev->regs + offset, data, len >> 2); |
|---|
| 35 | + __iowrite32_copy(dev->mmio.regs + offset, data, DIV_ROUND_UP(len, 4)); |
|---|
| 47 | 36 | } |
|---|
| 37 | + |
|---|
| 38 | +static void mt76_mmio_read_copy(struct mt76_dev *dev, u32 offset, |
|---|
| 39 | + void *data, int len) |
|---|
| 40 | +{ |
|---|
| 41 | + __ioread32_copy(data, dev->mmio.regs + offset, DIV_ROUND_UP(len, 4)); |
|---|
| 42 | +} |
|---|
| 43 | + |
|---|
| 44 | +static int mt76_mmio_wr_rp(struct mt76_dev *dev, u32 base, |
|---|
| 45 | + const struct mt76_reg_pair *data, int len) |
|---|
| 46 | +{ |
|---|
| 47 | + while (len > 0) { |
|---|
| 48 | + mt76_mmio_wr(dev, data->reg, data->value); |
|---|
| 49 | + data++; |
|---|
| 50 | + len--; |
|---|
| 51 | + } |
|---|
| 52 | + |
|---|
| 53 | + return 0; |
|---|
| 54 | +} |
|---|
| 55 | + |
|---|
| 56 | +static int mt76_mmio_rd_rp(struct mt76_dev *dev, u32 base, |
|---|
| 57 | + struct mt76_reg_pair *data, int len) |
|---|
| 58 | +{ |
|---|
| 59 | + while (len > 0) { |
|---|
| 60 | + data->value = mt76_mmio_rr(dev, data->reg); |
|---|
| 61 | + data++; |
|---|
| 62 | + len--; |
|---|
| 63 | + } |
|---|
| 64 | + |
|---|
| 65 | + return 0; |
|---|
| 66 | +} |
|---|
| 67 | + |
|---|
| 68 | +void mt76_set_irq_mask(struct mt76_dev *dev, u32 addr, |
|---|
| 69 | + u32 clear, u32 set) |
|---|
| 70 | +{ |
|---|
| 71 | + unsigned long flags; |
|---|
| 72 | + |
|---|
| 73 | + spin_lock_irqsave(&dev->mmio.irq_lock, flags); |
|---|
| 74 | + dev->mmio.irqmask &= ~clear; |
|---|
| 75 | + dev->mmio.irqmask |= set; |
|---|
| 76 | + if (addr) |
|---|
| 77 | + mt76_mmio_wr(dev, addr, dev->mmio.irqmask); |
|---|
| 78 | + spin_unlock_irqrestore(&dev->mmio.irq_lock, flags); |
|---|
| 79 | +} |
|---|
| 80 | +EXPORT_SYMBOL_GPL(mt76_set_irq_mask); |
|---|
| 48 | 81 | |
|---|
| 49 | 82 | void mt76_mmio_init(struct mt76_dev *dev, void __iomem *regs) |
|---|
| 50 | 83 | { |
|---|
| .. | .. |
|---|
| 52 | 85 | .rr = mt76_mmio_rr, |
|---|
| 53 | 86 | .rmw = mt76_mmio_rmw, |
|---|
| 54 | 87 | .wr = mt76_mmio_wr, |
|---|
| 55 | | - .copy = mt76_mmio_copy, |
|---|
| 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, |
|---|
| 56 | 93 | }; |
|---|
| 57 | 94 | |
|---|
| 58 | 95 | dev->bus = &mt76_mmio_ops; |
|---|
| 59 | | - dev->regs = regs; |
|---|
| 96 | + dev->mmio.regs = regs; |
|---|
| 97 | + |
|---|
| 98 | + spin_lock_init(&dev->mmio.irq_lock); |
|---|
| 60 | 99 | } |
|---|
| 61 | 100 | EXPORT_SYMBOL_GPL(mt76_mmio_init); |
|---|