blob: ef0cee1357f60d964ce40056adc8e464f83cadba [file] [log] [blame]
Eric Biederman52685572003-05-19 19:16:21 +00001#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 Biederman83b991a2003-10-11 06:20:25 +00006#include "amd8111.h"
Eric Biederman52685572003-05-19 19:16:21 +00007
8static void ide_init(struct device *dev)
9{
Eric Biedermandbec2d42004-10-21 10:44:08 +000010 struct southbridge_amd_amd8111_config *conf;
Eric Biederman52685572003-05-19 19:16:21 +000011 /* Enable ide devices so the linux ide driver will work */
12 uint16_t word;
Yinghai Lu7ccff4e2004-05-05 18:03:42 +000013 uint8_t byte;
Eric Biedermandbec2d42004-10-21 10:44:08 +000014 conf = dev->chip_info;
Eric Biederman52685572003-05-19 19:16:21 +000015
Eric Biederman7a5416a2003-06-12 19:23:51 +000016 word = pci_read_config16(dev, 0x40);
Eric Biederman52685572003-05-19 19:16:21 +000017 /* Ensure prefetch is disabled */
18 word &= ~((1 << 15) | (1 << 13));
Eric Biedermandbec2d42004-10-21 10:44:08 +000019 if (conf->ide1_enable) {
Eric Biederman52685572003-05-19 19:16:21 +000020 /* Enable secondary ide interface */
21 word |= (1<<0);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000022 printk(BIOS_DEBUG, "IDE1 ");
Eric Biederman52685572003-05-19 19:16:21 +000023 }
Eric Biedermandbec2d42004-10-21 10:44:08 +000024 if (conf->ide0_enable) {
Eric Biederman52685572003-05-19 19:16:21 +000025 /* Enable primary ide interface */
26 word |= (1<<1);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000027 printk(BIOS_DEBUG, "IDE0 ");
Eric Biederman52685572003-05-19 19:16:21 +000028 }
29
30 word |= (1<<12);
31 word |= (1<<14);
32
Eric Biederman7a5416a2003-06-12 19:23:51 +000033 pci_write_config16(dev, 0x40, word);
Eric Biederman52685572003-05-19 19:16:21 +000034
Yinghai Lu7ccff4e2004-05-05 18:03:42 +000035
36 byte = 0x20 ; // Latency: 64-->32
37 pci_write_config8(dev, 0xd, byte);
38
Eric Biederman52685572003-05-19 19:16:21 +000039 word = 0x0f;
Eric Biederman7a5416a2003-06-12 19:23:51 +000040 pci_write_config16(dev, 0x42, word);
Eric Biederman52685572003-05-19 19:16:21 +000041}
42
Eric Biedermandbec2d42004-10-21 10:44:08 +000043static void lpci_set_subsystem(device_t dev, unsigned vendor, unsigned device)
44{
Stefan Reinauer14e22772010-04-27 06:56:47 +000045 pci_write_config32(dev, 0x70,
Eric Biedermandbec2d42004-10-21 10:44:08 +000046 ((device & 0xffff) << 16) | (vendor & 0xffff));
47}
48static struct pci_operations lops_pci = {
49 .set_subsystem = lpci_set_subsystem,
50};
Eric Biederman52685572003-05-19 19:16:21 +000051static struct device_operations ide_ops = {
Eric Biedermane9a271e32003-09-02 03:36:25 +000052 .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 Biedermandbec2d42004-10-21 10:44:08 +000057 .enable = amd8111_enable,
58 .ops_pci = &lops_pci
Eric Biederman52685572003-05-19 19:16:21 +000059};
60
Stefan Reinauerf1cf1f72007-10-24 09:08:58 +000061static const struct pci_driver ide_driver __pci_driver = {
Eric Biederman52685572003-05-19 19:16:21 +000062 .ops = &ide_ops,
63 .vendor = PCI_VENDOR_ID_AMD,
64 .device = PCI_DEVICE_ID_AMD_8111_IDE,
65};