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