18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * arch/sh/drivers/pci/fixups-rts7751r2d.c
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * RTS7751R2D / LBOXRE2 PCI fixups
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Copyright (C) 2003  Lineo uSolutions, Inc.
88c2ecf20Sopenharmony_ci * Copyright (C) 2004  Paul Mundt
98c2ecf20Sopenharmony_ci * Copyright (C) 2007  Nobuhiro Iwamatsu
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci#include <linux/pci.h>
128c2ecf20Sopenharmony_ci#include <mach/lboxre2.h>
138c2ecf20Sopenharmony_ci#include <mach/r2d.h>
148c2ecf20Sopenharmony_ci#include "pci-sh4.h"
158c2ecf20Sopenharmony_ci#include <generated/machtypes.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#define PCIMCR_MRSET_OFF	0xBFFFFFFF
188c2ecf20Sopenharmony_ci#define PCIMCR_RFSH_OFF		0xFFFFFFFB
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_cistatic u8 rts7751r2d_irq_tab[] = {
218c2ecf20Sopenharmony_ci	IRQ_PCI_INTA,
228c2ecf20Sopenharmony_ci	IRQ_PCI_INTB,
238c2ecf20Sopenharmony_ci	IRQ_PCI_INTC,
248c2ecf20Sopenharmony_ci	IRQ_PCI_INTD,
258c2ecf20Sopenharmony_ci};
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_cistatic char lboxre2_irq_tab[] = {
288c2ecf20Sopenharmony_ci	IRQ_ETH0, IRQ_ETH1, IRQ_INTA, IRQ_INTD,
298c2ecf20Sopenharmony_ci};
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ciint pcibios_map_platform_irq(const struct pci_dev *pdev, u8 slot, u8 pin)
328c2ecf20Sopenharmony_ci{
338c2ecf20Sopenharmony_ci	if (mach_is_lboxre2())
348c2ecf20Sopenharmony_ci		return lboxre2_irq_tab[slot];
358c2ecf20Sopenharmony_ci	else
368c2ecf20Sopenharmony_ci		return rts7751r2d_irq_tab[slot];
378c2ecf20Sopenharmony_ci}
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ciint pci_fixup_pcic(struct pci_channel *chan)
408c2ecf20Sopenharmony_ci{
418c2ecf20Sopenharmony_ci	unsigned long bcr1, mcr;
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci	bcr1 = __raw_readl(SH7751_BCR1);
448c2ecf20Sopenharmony_ci	bcr1 |= 0x40080000;	/* Enable Bit 19 BREQEN, set PCIC to slave */
458c2ecf20Sopenharmony_ci	pci_write_reg(chan, bcr1, SH4_PCIBCR1);
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci	/* Enable all interrupts, so we known what to fix */
488c2ecf20Sopenharmony_ci	pci_write_reg(chan, 0x0000c3ff, SH4_PCIINTM);
498c2ecf20Sopenharmony_ci	pci_write_reg(chan, 0x0000380f, SH4_PCIAINTM);
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci	pci_write_reg(chan, 0xfb900047, SH7751_PCICONF1);
528c2ecf20Sopenharmony_ci	pci_write_reg(chan, 0xab000001, SH7751_PCICONF4);
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci	mcr = __raw_readl(SH7751_MCR);
558c2ecf20Sopenharmony_ci	mcr = (mcr & PCIMCR_MRSET_OFF) & PCIMCR_RFSH_OFF;
568c2ecf20Sopenharmony_ci	pci_write_reg(chan, mcr, SH4_PCIMCR);
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci	pci_write_reg(chan, 0x0c000000, SH7751_PCICONF5);
598c2ecf20Sopenharmony_ci	pci_write_reg(chan, 0xd0000000, SH7751_PCICONF6);
608c2ecf20Sopenharmony_ci	pci_write_reg(chan, 0x0c000000, SH4_PCILAR0);
618c2ecf20Sopenharmony_ci	pci_write_reg(chan, 0x00000000, SH4_PCILAR1);
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci	return 0;
648c2ecf20Sopenharmony_ci}
65