Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 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> |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 6 | #include "amd8111.h" |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 7 | |
| 8 | static void ide_init(struct device *dev) |
| 9 | { |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 10 | struct southbridge_amd_amd8111_config *conf; |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 11 | /* Enable ide devices so the linux ide driver will work */ |
| 12 | uint16_t word; |
Yinghai Lu | 7ccff4e | 2004-05-05 18:03:42 +0000 | [diff] [blame] | 13 | uint8_t byte; |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 14 | conf = dev->chip_info; |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 15 | |
Eric Biederman | 7a5416a | 2003-06-12 19:23:51 +0000 | [diff] [blame] | 16 | word = pci_read_config16(dev, 0x40); |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 17 | /* Ensure prefetch is disabled */ |
| 18 | word &= ~((1 << 15) | (1 << 13)); |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 19 | if (conf->ide1_enable) { |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 20 | /* Enable secondary ide interface */ |
| 21 | word |= (1<<0); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 22 | printk(BIOS_DEBUG, "IDE1 "); |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 23 | } |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 24 | if (conf->ide0_enable) { |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 25 | /* Enable primary ide interface */ |
| 26 | word |= (1<<1); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 27 | printk(BIOS_DEBUG, "IDE0 "); |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | word |= (1<<12); |
| 31 | word |= (1<<14); |
| 32 | |
Eric Biederman | 7a5416a | 2003-06-12 19:23:51 +0000 | [diff] [blame] | 33 | pci_write_config16(dev, 0x40, word); |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 34 | |
Yinghai Lu | 7ccff4e | 2004-05-05 18:03:42 +0000 | [diff] [blame] | 35 | |
| 36 | byte = 0x20 ; // Latency: 64-->32 |
| 37 | pci_write_config8(dev, 0xd, byte); |
| 38 | |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 39 | word = 0x0f; |
Eric Biederman | 7a5416a | 2003-06-12 19:23:51 +0000 | [diff] [blame] | 40 | pci_write_config16(dev, 0x42, word); |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 43 | static void lpci_set_subsystem(device_t dev, unsigned vendor, unsigned device) |
| 44 | { |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 45 | pci_write_config32(dev, 0x70, |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 46 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 47 | } |
| 48 | static struct pci_operations lops_pci = { |
| 49 | .set_subsystem = lpci_set_subsystem, |
| 50 | }; |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 51 | static struct device_operations ide_ops = { |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 52 | .read_resources = pci_dev_read_resources, |
| 53 | .set_resources = pci_dev_set_resources, |
| 54 | .enable_resources = pci_dev_enable_resources, |
| 55 | .init = ide_init, |
| 56 | .scan_bus = 0, |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 57 | .enable = amd8111_enable, |
| 58 | .ops_pci = &lops_pci |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
Stefan Reinauer | f1cf1f7 | 2007-10-24 09:08:58 +0000 | [diff] [blame] | 61 | static const struct pci_driver ide_driver __pci_driver = { |
Eric Biederman | 5268557 | 2003-05-19 19:16:21 +0000 | [diff] [blame] | 62 | .ops = &ide_ops, |
| 63 | .vendor = PCI_VENDOR_ID_AMD, |
| 64 | .device = PCI_DEVICE_ID_AMD_8111_IDE, |
| 65 | }; |