This patch unifies the use of config options in v2 to all start with CONFIG_
[coreboot.git] / src / southbridge / broadcom / bcm5785 / bcm5785_early_setup.c
1 /*
2  * Copyright  2005 AMD
3  *  by yinghai.lu@amd.com
4  */
5
6 #if CONFIG_USE_FALLBACK_IMAGE == 1
7
8 static void bcm5785_enable_rom(void)
9 {
10         unsigned char byte;
11         uint32_t dword;
12         uint16_t word;
13         device_t addr;
14
15         /* Enable 4MB rom access at 0xFFC00000 - 0xFFFFFFFF */
16         /* Locate the BCM 5785 SB PCI Main */
17         addr = pci_locate_device(PCI_ID(0x1166, 0x0205), 0); // 0x0201?
18
19         /* Set the 4MB enable bit bit */
20         byte = pci_read_config8(addr, 0x41);
21         byte |= 0x0e;
22         pci_write_config8(addr, 0x41, byte);
23 }
24
25 static void bcm5785_enable_lpc(void)
26 {
27
28         uint8_t byte;
29         device_t dev;
30
31         dev = pci_locate_device(PCI_ID(0x1166, 0x0234), 0);
32
33         /* LPC Control 0 */
34         byte = pci_read_config8(dev, 0x44);
35         /* Serial 0 */
36         byte |= (1<<6);
37         pci_write_config8(dev, 0x44, byte);
38
39         /* LPC Control 4 */
40         byte = pci_read_config8(dev, 0x48);
41         /* superio port 0x2e/4e enable */
42         byte |=(1<<1)|(1<<0);
43         pci_write_config8(dev, 0x48, byte);
44 }
45 #endif /* CONFIG_USE_FALLBACK_IMAGE == 1 */
46
47
48 static void bcm5785_enable_wdt_port_cf9(void)
49 {
50         device_t dev;
51         uint32_t dword;
52         uint32_t dword_old;
53
54         dev = pci_locate_device(PCI_ID(0x1166, 0x0205), 0);
55
56         dword_old = pci_read_config32(dev, 0x4c);
57         dword = dword_old | (1<<4); //enable Timer Func
58         if(dword != dword_old ) {
59                 pci_write_config32(dev, 0x4c, dword);
60         }
61
62         dword_old = pci_read_config32(dev, 0x6c);
63         dword = dword_old | (1<<9); //unhide Timer Func in pci space
64         if(dword != dword_old ) {
65                 pci_write_config32(dev, 0x6c, dword);
66         }
67
68         dev = pci_locate_device(PCI_ID(0x1166, 0x0238), 0);
69
70         /* enable cf9 */
71         pci_write_config8(dev, 0x40, (1<<2));
72 }
73
74 static unsigned get_sbdn(unsigned bus)
75 {
76         device_t dev;
77
78         /* Find the device.
79          * There can only be one 8111 on a hypertransport chain/bus.
80          */
81         dev = pci_locate_device_on_bus(
82                 PCI_ID(0x1166, 0x0036),
83                 bus);
84
85         return (dev>>15) & 0x1f;
86
87 }
88
89 #define SB_VFSMAF 0
90
91 static void enable_fid_change_on_sb(unsigned sbbusn, unsigned sbdn)
92 {
93         //ACPI Decode Enable    
94         outb(0x0e, 0xcd6);
95         outb((1<<3), 0xcd7);
96
97         // set port to 0x2060
98         outb(0x67, 0xcd6);
99         outb(0x60, 0xcd7);
100         outb(0x68, 0xcd6);
101         outb(0x20, 0xcd7);
102
103         outb(0x69, 0xcd6);
104         outb(7, 0xcd7);
105
106         outb(0x64, 0xcd6);
107         outb(9, 0xcd7);
108 }
109
110 static void ldtstop_sb(void)
111 {
112         outb(1, 0x2060);
113 }
114
115
116 static void hard_reset(void)
117 {
118         bcm5785_enable_wdt_port_cf9();
119
120         set_bios_reset();
121
122         /* full reset */
123         outb(0x0a, 0x0cf9);
124         outb(0x0e, 0x0cf9);
125 }
126
127 static void soft_reset(void)
128 {
129         bcm5785_enable_wdt_port_cf9();
130
131         set_bios_reset();
132 #if 1
133         /* link reset */
134 //        outb(0x02, 0x0cf9);
135         outb(0x06, 0x0cf9);
136 #endif
137 }
138
139
140
141 static void bcm5785_enable_msg(void)
142 {
143         device_t dev;
144         uint32_t dword;
145         uint32_t dword_old;
146         uint8_t byte;
147
148         dev = pci_locate_device(PCI_ID(0x1166, 0x0205), 0);
149
150         byte = pci_read_config8(dev, 0x42);
151         byte = (1<<1); //enable a20
152         pci_write_config8(dev, 0x42, byte);
153
154         dword_old = pci_read_config32(dev, 0x6c);
155         // bit 5: enable A20 Message
156         // bit 4: enable interrupt messages
157         // bit 3: enable reset init message
158         // bit 2: enable keyboard init message
159         // bit 1: enable upsteam messages
160         // bit 0: enable shutdowm message to init generation
161         dword = dword_old | (1<<5) | (1<<3) | (1<<2) | (1<<1) | (1<<0); // bit 1 and bit 4 must be set, otherwise interrupt msg will not be delivered to the processor
162         if(dword != dword_old ) {
163                 pci_write_config32(dev, 0x6c, dword);
164         }
165
166 }
167
168 static void bcm5785_early_setup(void)
169 {
170         uint8_t byte;
171         uint16_t word;
172         uint32_t dword;
173         device_t dev;
174
175 //F0
176         // enable device on bcm5785 at first
177         dev = pci_locate_device(PCI_ID(0x1166, 0x0205), 0);
178         dword = pci_read_config32(dev, 0x64);
179         dword |=  (1<<15) | (1<<11) | (1<<3); // ioapci enable
180         dword |= (1<<8); // USB enable
181         dword |= /* (1<<27)|*/(1<<14); // IDE enable
182         pci_write_config32(dev, 0x64, dword);
183
184         byte = pci_read_config8(dev, 0x84);
185         byte |= (1<<0); // SATA enable
186         pci_write_config8(dev, 0x84, byte);
187
188 // wdt and cf9 for later in coreboot_ram to call hard_reset
189         bcm5785_enable_wdt_port_cf9();
190
191         bcm5785_enable_msg();
192
193
194 #if 1
195 // IDE related
196         //F0
197         byte = pci_read_config8(dev, 0x4e);
198         byte |= (1<<4); //enable IDE ext regs
199         pci_write_config8(dev, 0x4e, byte);
200
201         //F1
202         dev = pci_locate_device(PCI_ID(0x1166, 0x0214), 0);
203         byte = pci_read_config8(dev, 0x48);
204         byte &= ~1; // disable pri channel
205         pci_write_config8(dev, 0x48, byte);
206         pci_write_config8(dev, 0xb0, 0x01);
207         pci_write_config8(dev, 0xb2, 0x02);
208         byte = pci_read_config8(dev, 0x06);
209         byte |= (1<<4); // so b0, b2 can not be changed from now
210         pci_write_config8(dev, 0x06, byte);
211         byte = pci_read_config8(dev, 0x49);
212         byte |= 1; // enable second channel
213         pci_write_config8(dev, 0x49, byte);
214 #endif
215
216 //F2
217         dev = pci_locate_device(PCI_ID(0x1166, 0x0234), 0);
218
219         byte = pci_read_config8(dev, 0x40);
220         byte |= (1<<3)|(1<<2); // LPC Retry, LPC to PCI DMA enable
221         pci_write_config8(dev, 0x40, byte);
222
223         pci_write_config32(dev, 0x60, 0x0000ffff); // LPC Memory hole start and end
224
225 #if 1
226 // USB related
227         pci_write_config8(dev, 0x90, 0x40);
228         pci_write_config8(dev, 0x92, 0x06);
229         pci_write_config8(dev, 0x9c, 0x7c); //PHY timinig register
230         pci_write_config8(dev, 0xa4, 0x02); //mask reg - low/full speed func
231         pci_write_config8(dev, 0xa5, 0x02); //mask reg - low/full speed func
232         pci_write_config8(dev, 0xa6, 0x00); //mask reg - high speed func
233         pci_write_config8(dev, 0xb4, 0x40);
234 #endif
235 }