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