442185994659b4b57d3fb24974bb619678b2c451
[coreboot.git] / src / southbridge / intel / i82801dbm / i82801dbm_sata.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 "i82801dbm.h"
7
8 static void sata_init(struct device *dev)
9 {
10
11         uint16_t word;
12         uint8_t byte;
13         int enable_c=1, enable_d=1;
14         //      int i;
15                 
16         //Enable Serial ATA port
17         byte = pci_read_config8(dev,0x90);
18         byte &= 0xf8;
19         byte |= ICH5_SATA_ADDRESS_MAP & 7;
20         pci_write_config8(dev,0x90,byte);
21
22 //        for(i=0;i<10;i++) {
23                 word = pci_read_config16(dev,0x92);
24                 word &= 0xfffc;
25 //                if( (word & 0x0003) == 0x0003) break;
26                 word |= 0x0003; // enable P0/P1 
27                 pci_write_config16(dev,0x92,word);
28 //        }
29
30 //        for(i=0;i<10;i++) {
31               /* enable ide0 */
32                 word = pci_read_config16(dev, 0x40);
33                 word &= ~(1 << 15);
34                 if(enable_c==0) {
35 //                      if( (word & 0x8000) == 0x0000) break;
36                         word |= 0x0000;
37                 }
38                 else {
39 //                              if( (word & 0x8000) == 0x8000) break;
40                         word |= 0x8000;
41                 }
42                 pci_write_config16(dev, 0x40, word);
43 //      }
44                 /* enable ide1 */
45 //        for(i=0;i<10;i++) {
46                 word = pci_read_config16(dev, 0x42);
47                 word &= ~(1 << 15);
48                 if(enable_d==0) {
49 //                              if( (word & 0x8000) == 0x0000) break;
50                         word |= 0x0000;
51                 }
52                 else {
53 //                              if( (word & 0x8000) == 0x8000) break;
54                         word |= 0x8000;
55                 }
56                 pci_write_config16(dev, 0x42, word);
57 //        }
58
59 }
60
61 static struct device_operations sata_ops  = {
62         .read_resources   = pci_dev_read_resources,
63         .set_resources    = pci_dev_set_resources,
64         .enable_resources = pci_dev_enable_resources,
65         .init             = sata_init,
66         .scan_bus         = 0,
67         .enable           = i82801dbm_enable,
68 };
69
70 static struct pci_driver stat_driver __pci_driver = {
71         .ops    = &sata_ops,
72         .vendor = PCI_VENDOR_ID_INTEL,
73         .device = PCI_DEVICE_ID_INTEL_82801ER_1F2_R,
74 };
75