This patch converts __FUNCTION__ to __func__, since __func__ is standard.
[coreboot.git] / src / mainboard / olpc / btest / mainboard.c
1 #include <console/console.h>
2 #include <device/device.h>
3 #include <device/pci.h>
4 #include <device/pci_ids.h>
5 #include <device/pci_ops.h>
6 #include <arch/io.h>
7 #include <pc80/mc146818rtc.h>
8 #include "chip.h"
9 #include "../southbridge/amd/cs5536/cs5536_smbus2.h"
10 #include <cpu/amd/vr.h>
11
12 /* Borrowed from mc146818rtc.c */
13
14 #define CMOS_READ(addr) ({ \
15                 outb((addr),RTC_PORT(0)); \
16                 inb(RTC_PORT(1)); \
17                 })
18
19 #define CMOS_WRITE(val, addr) ({ \
20                 outb((addr),RTC_PORT(0)); \
21                 outb((val),RTC_PORT(1)); \
22                 })
23
24 static void write_bit(unsigned char val) {
25
26         unsigned char byte = CMOS_READ(440 / 8);
27
28         /* Don't change it if its already set */
29
30         if ((byte & 1) == (val & 1))
31                 return;
32
33         byte &= ~1;
34         byte |= val & 1;
35         CMOS_WRITE(val, 440/8);
36 }
37
38 static unsigned short _getsmbusbase(void) {
39         unsigned devfn = PCI_DEVFN(0xf, 0);
40         device_t dev = dev_find_slot(0x0, devfn);
41         unsigned long addr = pci_read_config32(dev, PCI_BASE_ADDRESS_0);
42
43         return (unsigned short) (addr & ~1);
44 }
45
46 static void init_dcon(void) {
47
48   int ret = 1;
49   unsigned short rev = 0;
50   unsigned short iobase = _getsmbusbase();
51
52   printk_debug("CHECKING FOR DCON (%x)\n", iobase);
53
54   /* Get the IO base for the SMBUS */
55
56   rev = do_smbus_read_word(iobase, 0x0D << 1, 0x00);
57
58   if (rev & 0xDC00) {
59         printk_debug("DCON FOUND - REV %x\n", rev);
60
61         /* Enable the DCON */
62         ret = do_smbus_write_word(iobase, 0x0D << 1, 0x01, 0x0069);
63         if (ret != 0)
64                 printk_debug("DCON ENABLE FAILED\n", ret);
65   }
66   else
67           printk_debug("DCON NOT FOUND (%x)\n", rev);
68
69   write_bit(rev > 0 ? 1 : 0);
70 }
71
72 void
73 init_cafe_irq(void){
74         const unsigned char slots_cafe[4] = {11, 0, 0, 0};
75
76  
77         /* CAFE PCI slots */ 
78         pci_assign_irqs(0, 0x0C, slots_cafe); 
79
80         /* Make the pin assignments - NOTENOTENOTE:  This should be 
81           * configurable! 
82           */ 
83
84         /* Configure the GPIO pins to use - class 0, index 9 to configure 
85           * AB.  Write 0xFF to disable 
86           */ 
87         
88         vrWrite(0x9, 0XFF00); 
89         
90         /* Configure the GPIO pins to use - class 0, index A to configure 
91           * CD.  Write 0xFF to disable 
92           */ 
93         
94        vrWrite(0xA, 0xFFFF); 
95          
96 }
97
98
99 static void init(struct device *dev) {
100 /*
101         unsigned bus = 0;
102         unsigned devfn = PCI_DEVFN(0xf, 4);
103         device_t usb = NULL;
104         unsigned char usbirq = 0xa;
105 */
106
107         printk_debug("OLPC BTEST ENTER %s\n", __func__);
108
109 #if 0
110         /* I can't think of any reason NOT to just set this. If it turns out we want this to be
111           * conditional we can make it a config variable later.
112           */
113
114         printk_debug("%s (%x,%x)SET USB PCI interrupt line to %d\n", 
115                 __func__, bus, devfn, usbirq);
116         usb = dev_find_slot(bus, devfn);
117         if (! usb){
118                 printk_err("Could not find USB\n");
119         } else {
120                 pci_write_config8(usb, PCI_INTERRUPT_LINE, usbirq);
121         }
122 #endif
123
124         init_dcon();
125         init_cafe_irq();
126         printk_debug("OLPC BTEST EXIT %s\n", __func__);
127 }
128
129 static void enable_dev(struct device *dev)
130 {
131         dev->ops->init = init;
132 }
133
134 struct chip_operations mainboard_olpc_btest_ops = {
135         CHIP_NAME("OLPC btest Mainboard")
136         .enable_dev = enable_dev,
137 };