Ever wondered where those "setting incorrect section attributes for
[coreboot.git] / src / southbridge / broadcom / bcm5785 / bcm5785_sb_pci_main.c
1 /*
2  * Copyright  2005 AMD
3  *  by yinghai.lu@amd.com
4  */
5
6 #include <console/console.h>
7 #include <device/device.h>
8 #include <device/pci.h>
9 #include <device/pnp.h>
10 #include <device/pci_ids.h>
11 #include <device/pci_ops.h>
12 #include <pc80/mc146818rtc.h>
13 #include <pc80/isa-dma.h>
14 #include <bitops.h>
15 #include <arch/io.h>
16 #include <device/smbus.h>
17 #include "bcm5785.h"
18 #include "bcm5785_smbus.h"
19
20 #define NMI_OFF 0
21
22 static void sb_init(device_t dev)
23 {
24         uint8_t byte;
25         uint8_t byte_old;
26         int nmi_option;
27
28         uint32_t dword;
29
30         /* Set up NMI on errors */
31         byte = inb(0x70); // RTC70
32         byte_old = byte;
33         nmi_option = NMI_OFF;
34         get_option(&nmi_option, "nmi");
35         if (nmi_option) {                       
36                 byte &= ~(1 << 7); /* set NMI */
37         } else {
38                 byte |= ( 1 << 7); // Can not mask NMI from PCI-E and NMI_NOW
39         }
40         if( byte != byte_old) {
41                 outb(0x70, byte);
42         }
43
44
45 }
46
47 static void bcm5785_sb_read_resources(device_t dev)
48 {
49         struct resource *res;
50         unsigned long index;
51
52         /* Get the normal pci resources of this device */
53         pci_dev_read_resources(dev);            
54         
55         /* Get Resource for SMBUS */    
56         pci_get_resource(dev, 0x90);    
57
58         compact_resources(dev); 
59
60         /* Add an extra subtractive resource for both memory and I/O */
61         res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0));
62         res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED;
63         
64         res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0));
65         res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED;
66
67 }
68 static int lsmbus_recv_byte(device_t dev)
69 {
70         unsigned device;
71         struct resource *res;
72         struct bus *pbus;
73
74         device = dev->path.u.i2c.device;
75         pbus = get_pbus_smbus(dev);
76
77         res = find_resource(pbus->dev, 0x90);
78
79         return do_smbus_recv_byte(res->base, device);
80 }
81         
82 static int lsmbus_send_byte(device_t dev, uint8_t val)
83 {
84         unsigned device;
85         struct resource *res;
86         struct bus *pbus;
87
88         device = dev->path.u.i2c.device;
89         pbus = get_pbus_smbus(dev);
90
91         res = find_resource(pbus->dev, 0x90);
92
93         return do_smbus_send_byte(res->base, device, val);
94 }
95 static int lsmbus_read_byte(device_t dev, uint8_t address)
96 {
97         unsigned device;
98         struct resource *res;
99         struct bus *pbus;
100
101         device = dev->path.u.i2c.device;
102         pbus = get_pbus_smbus(dev);
103
104         res = find_resource(pbus->dev, 0x90);
105
106         return do_smbus_read_byte(res->base, device, address);
107 }
108 static int lsmbus_write_byte(device_t dev, uint8_t address, uint8_t val)
109 {
110         unsigned device;
111         struct resource *res;
112         struct bus *pbus;
113
114         device = dev->path.u.i2c.device;
115         pbus = get_pbus_smbus(dev);
116
117         res = find_resource(pbus->dev, 0x90);
118
119         return do_smbus_write_byte(res->base, device, address, val);
120 }
121 static struct smbus_bus_operations lops_smbus_bus = {
122         .recv_byte  = lsmbus_recv_byte,
123         .send_byte  = lsmbus_send_byte,
124         .read_byte  = lsmbus_read_byte,
125         .write_byte = lsmbus_write_byte,
126 };
127
128 static void lpci_set_subsystem(device_t dev, unsigned vendor, unsigned device)
129 {
130         pci_write_config32(dev, 0x2c,
131                 ((device & 0xffff) << 16) | (vendor & 0xffff));
132 }
133
134 static struct pci_operations lops_pci = {
135         .set_subsystem = lpci_set_subsystem,
136 };
137
138 static struct device_operations sb_ops = {
139         .read_resources   = bcm5785_sb_read_resources,
140         .set_resources    = pci_dev_set_resources,
141         .enable_resources = pci_dev_enable_resources,
142         .init             = sb_init,
143         .scan_bus         = scan_static_bus,
144 //        .enable           = bcm5785_enable,
145         .ops_pci          = &lops_pci,
146         .ops_smbus_bus    = &lops_smbus_bus,
147 };
148 static const struct pci_driver sb_driver __pci_driver = {
149         .ops    = &sb_ops,
150         .vendor = PCI_VENDOR_ID_SERVERWORKS,
151         .device = PCI_DEVICE_ID_SERVERWORKS_BCM5785_SB_PCI_MAIN,
152 };
153