1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2ab8f4d40SNobuhiro Iwamatsu /*
3ab8f4d40SNobuhiro Iwamatsu * SH7780 PCI Controller (PCIC) for U-Boot.
4ab8f4d40SNobuhiro Iwamatsu * (C) Dustin McIntire (dustin@sensoria.com)
5ab8f4d40SNobuhiro Iwamatsu * (C) 2007,2008 Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
6ab8f4d40SNobuhiro Iwamatsu * (C) 2008 Yusuke Goda <goda.yusuke@renesas.com>
7ab8f4d40SNobuhiro Iwamatsu */
8ab8f4d40SNobuhiro Iwamatsu
9ab8f4d40SNobuhiro Iwamatsu #include <common.h>
10ab8f4d40SNobuhiro Iwamatsu
11ab8f4d40SNobuhiro Iwamatsu #include <pci.h>
12b5d10a13SNobuhiro Iwamatsu #include <asm/processor.h>
13b5d10a13SNobuhiro Iwamatsu #include <asm/pci.h>
14b5d10a13SNobuhiro Iwamatsu #include <asm/io.h>
15ab8f4d40SNobuhiro Iwamatsu
16ab8f4d40SNobuhiro Iwamatsu #define SH7780_VENDOR_ID 0x1912
17ab8f4d40SNobuhiro Iwamatsu #define SH7780_DEVICE_ID 0x0002
18ab8f4d40SNobuhiro Iwamatsu #define SH7780_PCICR_PREFIX 0xA5000000
19ab8f4d40SNobuhiro Iwamatsu #define SH7780_PCICR_PFCS 0x00000800
20ab8f4d40SNobuhiro Iwamatsu #define SH7780_PCICR_FTO 0x00000400
21ab8f4d40SNobuhiro Iwamatsu #define SH7780_PCICR_PFE 0x00000200
22ab8f4d40SNobuhiro Iwamatsu #define SH7780_PCICR_TBS 0x00000100
23ab8f4d40SNobuhiro Iwamatsu #define SH7780_PCICR_ARBM 0x00000040
24ab8f4d40SNobuhiro Iwamatsu #define SH7780_PCICR_IOCS 0x00000004
25ab8f4d40SNobuhiro Iwamatsu #define SH7780_PCICR_PRST 0x00000002
26ab8f4d40SNobuhiro Iwamatsu #define SH7780_PCICR_CFIN 0x00000001
27ab8f4d40SNobuhiro Iwamatsu
28b5d10a13SNobuhiro Iwamatsu #define p4_in(addr) (*(vu_long *)addr)
29b5d10a13SNobuhiro Iwamatsu #define p4_out(data, addr) (*(vu_long *)addr) = (data)
30b5d10a13SNobuhiro Iwamatsu #define p4_inw(addr) (*(vu_short *)addr)
31b5d10a13SNobuhiro Iwamatsu #define p4_outw(data, addr) (*(vu_short *)addr) = (data)
32ab8f4d40SNobuhiro Iwamatsu
pci_sh4_read_config_dword(struct pci_controller * hose,pci_dev_t dev,int offset,u32 * value)33ab8f4d40SNobuhiro Iwamatsu int pci_sh4_read_config_dword(struct pci_controller *hose,
34ab8f4d40SNobuhiro Iwamatsu pci_dev_t dev, int offset, u32 *value)
35ab8f4d40SNobuhiro Iwamatsu {
36ab8f4d40SNobuhiro Iwamatsu u32 par_data = 0x80000000 | dev;
37ab8f4d40SNobuhiro Iwamatsu
38ab8f4d40SNobuhiro Iwamatsu p4_out(par_data | (offset & 0xfc), SH7780_PCIPAR);
39ab8f4d40SNobuhiro Iwamatsu *value = p4_in(SH7780_PCIPDR);
40ab8f4d40SNobuhiro Iwamatsu
41ab8f4d40SNobuhiro Iwamatsu return 0;
42ab8f4d40SNobuhiro Iwamatsu }
43ab8f4d40SNobuhiro Iwamatsu
pci_sh4_write_config_dword(struct pci_controller * hose,pci_dev_t dev,int offset,u32 value)44ab8f4d40SNobuhiro Iwamatsu int pci_sh4_write_config_dword(struct pci_controller *hose,
45ab8f4d40SNobuhiro Iwamatsu pci_dev_t dev, int offset, u32 value)
46ab8f4d40SNobuhiro Iwamatsu {
47ab8f4d40SNobuhiro Iwamatsu u32 par_data = 0x80000000 | dev;
48ab8f4d40SNobuhiro Iwamatsu
49ab8f4d40SNobuhiro Iwamatsu p4_out(par_data | (offset & 0xfc), SH7780_PCIPAR);
50ab8f4d40SNobuhiro Iwamatsu p4_out(value, SH7780_PCIPDR);
51ab8f4d40SNobuhiro Iwamatsu return 0;
52ab8f4d40SNobuhiro Iwamatsu }
53ab8f4d40SNobuhiro Iwamatsu
pci_sh7780_init(struct pci_controller * hose)54ab8f4d40SNobuhiro Iwamatsu int pci_sh7780_init(struct pci_controller *hose)
55ab8f4d40SNobuhiro Iwamatsu {
56ab8f4d40SNobuhiro Iwamatsu p4_out(0x01, SH7780_PCIECR);
57ab8f4d40SNobuhiro Iwamatsu
58ab8f4d40SNobuhiro Iwamatsu if (p4_inw(SH7780_PCIVID) != SH7780_VENDOR_ID
59ab8f4d40SNobuhiro Iwamatsu && p4_inw(SH7780_PCIDID) != SH7780_DEVICE_ID) {
60ab8f4d40SNobuhiro Iwamatsu printf("PCI: Unknown PCI host bridge.\n");
61b5d10a13SNobuhiro Iwamatsu return -1;
62ab8f4d40SNobuhiro Iwamatsu }
63ab8f4d40SNobuhiro Iwamatsu printf("PCI: SH7780 PCI host bridge found.\n");
64ab8f4d40SNobuhiro Iwamatsu
65ab8f4d40SNobuhiro Iwamatsu /* Toggle PCI reset pin */
66ab8f4d40SNobuhiro Iwamatsu p4_out((SH7780_PCICR_PREFIX | SH7780_PCICR_PRST), SH7780_PCICR);
67ab8f4d40SNobuhiro Iwamatsu udelay(100000);
68ab8f4d40SNobuhiro Iwamatsu p4_out(SH7780_PCICR_PREFIX, SH7780_PCICR);
69ab8f4d40SNobuhiro Iwamatsu p4_outw(0x0047, SH7780_PCICMD);
70ab8f4d40SNobuhiro Iwamatsu
7106b18163SYoshihiro Shimoda p4_out(CONFIG_SH7780_PCI_LSR, SH7780_PCILSR0);
7206b18163SYoshihiro Shimoda p4_out(CONFIG_SH7780_PCI_LAR, SH7780_PCILAR0);
73ab8f4d40SNobuhiro Iwamatsu p4_out(0x00000000, SH7780_PCILSR1);
74ab8f4d40SNobuhiro Iwamatsu p4_out(0, SH7780_PCILAR1);
7506b18163SYoshihiro Shimoda p4_out(CONFIG_SH7780_PCI_BAR, SH7780_PCIMBAR0);
76ab8f4d40SNobuhiro Iwamatsu p4_out(0x00000000, SH7780_PCIMBAR1);
77ab8f4d40SNobuhiro Iwamatsu
78ab8f4d40SNobuhiro Iwamatsu p4_out(0xFD000000, SH7780_PCIMBR0);
79ab8f4d40SNobuhiro Iwamatsu p4_out(0x00FC0000, SH7780_PCIMBMR0);
80ab8f4d40SNobuhiro Iwamatsu
81ab8f4d40SNobuhiro Iwamatsu /* if use Operand Cache then enable PCICSCR Soonp bits. */
82ab8f4d40SNobuhiro Iwamatsu p4_out(0x08000000, SH7780_PCICSAR0);
83ab8f4d40SNobuhiro Iwamatsu p4_out(0x0000001B, SH7780_PCICSCR0); /* Snoop bit :On */
84ab8f4d40SNobuhiro Iwamatsu
85ab8f4d40SNobuhiro Iwamatsu p4_out((SH7780_PCICR_PREFIX | SH7780_PCICR_CFIN | SH7780_PCICR_ARBM
86ab8f4d40SNobuhiro Iwamatsu | SH7780_PCICR_FTO | SH7780_PCICR_PFCS | SH7780_PCICR_PFE),
87ab8f4d40SNobuhiro Iwamatsu SH7780_PCICR);
88ab8f4d40SNobuhiro Iwamatsu
89ab8f4d40SNobuhiro Iwamatsu pci_sh4_init(hose);
90ab8f4d40SNobuhiro Iwamatsu return 0;
91ab8f4d40SNobuhiro Iwamatsu }
92