a1cab08c883b210a3675c77e6dce79ac6e21bbaa
[coreboot.git] / src / southbridge / amd / cs5535 / cs5535_early_setup.c
1 /*
2  *
3  * cs5535_early_setup.c:        Early chipset initialization for CS5535 companion device
4  *
5  *
6  * This file implements the initialization sequence documented in section 4.2 of
7  * AMD Geode GX Processor CS5535 Companion Device GoedeROM Porting Guide.
8  *
9  */
10
11 #define CS5535_GLINK_PORT_NUM   0x02    /* the geode link port number to the CS5535 */       
12 #define CS5535_DEV_NUM          0x0F    /* default PCI device number for CS5535 */
13
14 /**
15  * @brief Setup PCI IDSEL for CS5535
16  *
17  * 
18  */
19
20 static void cs5535_setup_extmsr(void)
21 {
22         msr_t msr;
23
24         /* forward MSR access to CS5535_GLINK_PORT_NUM to CS5535_DEV_NUM */
25         msr.hi = msr.lo = 0x00000000;
26         if (CS5535_GLINK_PORT_NUM <= 4) {
27                 msr.lo = CS5535_DEV_NUM << ((CS5535_GLINK_PORT_NUM - 1) * 8);
28         } else {
29                 msr.hi = CS5535_DEV_NUM << ((CS5535_GLINK_PORT_NUM - 5) * 8);
30         }
31         wrmsr(0x5000201e, msr);
32 }
33
34 static void cs5535_setup_idsel(void)
35 {
36         /* write IDSEL to the write once register at address 0x0000 */
37         outl(0x1 << (CS5535_DEV_NUM + 10), 0);
38 }
39
40 static int cs5535_setup_iobase(void)
41 {
42         msr_t msr;
43
44         /* setup LBAR for SMBus controller */
45         __builtin_wrmsr(0x5140000b, 0x00006000, 0x0000f001);
46         /* setup LBAR for GPIO */
47         __builtin_wrmsr(0x5140000c, 0x00006100, 0x0000f001);
48         /* setup LBAR for MFGPT */
49         __builtin_wrmsr(0x5140000d, 0x00006200, 0x0000f001);
50         /* setup LBAR for ACPI */
51         __builtin_wrmsr(0x5140000e, 0x00009c00, 0x0000f001);
52         /* setup LBAR for MFGPT */
53         __builtin_wrmsr(0x5140000f, 0x00009d00, 0x0000f001);
54 }
55
56 static void cs5535_setup_gpio(void)
57 {
58         uint32_t val;
59
60         /* setup GPIO pins 14/15 for SDA/SCL */
61         val = (1<<14 | 1<<15);
62         /* Output Enable */
63         outl(0x3fffc000, 0x6100 + 0x04);
64         //outl(val, 0x6100 + 0x04);
65         /* Output AUX1 */
66         outl(0x3fffc000, 0x6100 + 0x10);
67         //outl(val, 0x6100 + 0x10);
68         /* Input Enable */
69         //outl(0x0f5af0a5, 0x6100 + 0x20);
70         outl(0x3fffc000, 0x6100 + 0x20);
71         //outl(val, 0x6100 + 0x20);
72         /* Input AUX1 */
73         //outl(0x3ffbc004, 0x6100 + 0x34);
74         outl(0x3fffc000, 0x6100 + 0x34);
75         //outl(val, 0x6100 + 0x34);
76 }
77
78 static void cs5535_setup_cis_mode(void)
79 {
80         msr_t msr;
81
82         /* setup CPU interface serial to mode C on both sides */
83         msr = __builtin_rdmsr(0x51000010);
84         msr.lo &= ~0x18;
85         msr.lo |= 0x10;
86         __builtin_wrmsr(0x51000010, msr.lo, msr.hi);
87         __builtin_wrmsr(0x54002010, 0x00000002, 0x00000000);
88 }
89
90 static void dummy(void)
91 {
92 }
93
94 static int cs5535_early_setup(void)
95 {
96         msr_t msr;
97
98         cs5535_setup_extmsr();
99
100         msr = rdmsr(0x4c000014);
101         if (msr.lo & (0x3f << 26)) {
102                 /* PLL is already set and we are reboot from PLL reset */
103                 print_debug("reboot from BIOS reset\n\r");
104                 return;
105         }
106         print_debug("Setup idsel\r\n");
107         cs5535_setup_idsel();
108         print_debug("Setup iobase\r\n");
109         cs5535_setup_iobase();
110         print_debug("Setup gpio\r\n");
111         cs5535_setup_gpio();
112         print_debug("Setup cis_mode\r\n");
113         cs5535_setup_cis_mode();
114         print_debug("Setup smbus\r\n");
115         cs5535_enable_smbus();
116         dummy();
117 }