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