Skip to content

Commit cecf48e

Browse files
committed
sh: pci: Use I/O accessors consistently in SH7786 PCIe init code.
Some of the existing code is flipping between __raw_xxx() and pci_{read,write}_reg(). As the latter are just wrappers for the former, flip over to using them consistently. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent bd792ae commit cecf48e

2 files changed

Lines changed: 25 additions & 17 deletions

File tree

‎arch/sh/drivers/pci/pcie-sh7786.c‎

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -304,24 +304,24 @@ static int pcie_init(struct sh7786_pcie_port *port)
304304
* LAR1/LAMR1.
305305
*/
306306
if (memsize > SZ_512M) {
307-
__raw_writel(memphys + SZ_512M, chan->reg_base + SH4A_PCIELAR1);
308-
__raw_writel(((memsize - SZ_512M) - SZ_256) | 1,
309-
chan->reg_base + SH4A_PCIELAMR1);
307+
pci_write_reg(chan, memphys + SZ_512M, SH4A_PCIELAR1);
308+
pci_write_reg(chan, ((memsize - SZ_512M) - SZ_256) | 1,
309+
SH4A_PCIELAMR1);
310310
memsize = SZ_512M;
311311
} else {
312312
/*
313313
* Otherwise just zero it out and disable it.
314314
*/
315-
__raw_writel(0, chan->reg_base + SH4A_PCIELAR1);
316-
__raw_writel(0, chan->reg_base + SH4A_PCIELAMR1);
315+
pci_write_reg(chan, 0, SH4A_PCIELAR1);
316+
pci_write_reg(chan, 0, SH4A_PCIELAMR1);
317317
}
318318

319319
/*
320320
* LAR0/LAMR0 covers up to the first 512MB, which is enough to
321321
* cover all of lowmem on most platforms.
322322
*/
323-
__raw_writel(memphys, chan->reg_base + SH4A_PCIELAR0);
324-
__raw_writel((memsize - SZ_256) | 1, chan->reg_base + SH4A_PCIELAMR0);
323+
pci_write_reg(chan, memphys, SH4A_PCIELAR0);
324+
pci_write_reg(chan, (memsize - SZ_256) | 1, SH4A_PCIELAMR0);
325325

326326
/* Finish initialization */
327327
data = pci_read_reg(chan, SH4A_PCIETCTLR);
@@ -370,7 +370,7 @@ static int pcie_init(struct sh7786_pcie_port *port)
370370
for (i = win = 0; i < chan->nr_resources; i++) {
371371
struct resource *res = chan->resources + i;
372372
resource_size_t size;
373-
u32 enable_mask;
373+
u32 mask;
374374

375375
/*
376376
* We can't use the 32-bit mode windows in legacy 29-bit
@@ -381,23 +381,24 @@ static int pcie_init(struct sh7786_pcie_port *port)
381381

382382
pci_write_reg(chan, 0x00000000, SH4A_PCIEPTCTLR(win));
383383

384-
size = resource_size(res);
385-
386384
/*
387385
* The PAMR mask is calculated in units of 256kB, which
388386
* keeps things pretty simple.
389387
*/
390-
__raw_writel(((roundup_pow_of_two(size) / SZ_256K) - 1) << 18,
391-
chan->reg_base + SH4A_PCIEPAMR(win));
388+
size = resource_size(res);
389+
mask = (roundup_pow_of_two(size) / SZ_256K) - 1;
390+
pci_write_reg(chan, mask << 18, SH4A_PCIEPAMR(win));
392391

393-
pci_write_reg(chan, res->start, SH4A_PCIEPARL(win));
394-
pci_write_reg(chan, 0x00000000, SH4A_PCIEPARH(win));
392+
pci_write_reg(chan, RES_TO_U32_HIGH(res->start),
393+
SH4A_PCIEPARH(win));
394+
pci_write_reg(chan, RES_TO_U32_LOW(res->start),
395+
SH4A_PCIEPARL(win));
395396

396-
enable_mask = MASK_PARE;
397+
mask = MASK_PARE;
397398
if (res->flags & IORESOURCE_IO)
398-
enable_mask |= MASK_SPC;
399+
mask |= MASK_SPC;
399400

400-
pci_write_reg(chan, enable_mask, SH4A_PCIEPTCTLR(win));
401+
pci_write_reg(chan, mask, SH4A_PCIEPTCTLR(win));
401402

402403
win++;
403404
}

‎arch/sh/drivers/pci/pcie-sh7786.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,13 @@
568568

569569
#define PCI_REG(x) ((x) + 0x40000)
570570

571+
#define U64_TO_U32_LOW(val) ((u32)((val) & 0x00000000ffffffffULL))
572+
#define U64_TO_U32_HIGH(val) ((u32)((val) >> 32))
573+
#define RES_TO_U32_LOW(val) \
574+
((sizeof(resource_size_t) > sizeof(u32)) ? U64_TO_U32_LOW(val) : (val))
575+
#define RES_TO_U32_HIGH(val) \
576+
((sizeof(resource_size_t) > sizeof(u32)) ? U64_TO_U32_HIGH(val) : (0))
577+
571578
static inline void
572579
pci_write_reg(struct pci_channel *chan, unsigned long val, unsigned long reg)
573580
{

0 commit comments

Comments
 (0)