2 * Copyright 2004 Tyan Computer
6 #include <console/console.h>
7 #include <device/device.h>
8 #include <device/smbus.h>
9 #include <device/pci.h>
10 #include <device/pci_ids.h>
11 #include <device/pci_ops.h>
15 static void nic_init(struct device *dev)
17 uint32_t dword, old, mac_h, mac_l;
19 struct southbridge_nvidia_ck804_config *conf;
20 static uint32_t nic_index = 0;
24 res = find_resource(dev, 0x10);
25 base = (unsigned long)res->base;
27 #define NvRegPhyInterface 0xC0
28 #define PHY_RGMII 0x10000000
30 write32(base + NvRegPhyInterface, PHY_RGMII);
32 old = dword = pci_read_config32(dev, 0x30);
36 pci_write_config32(dev, 0x30, dword);
38 conf = dev->chip_info;
40 if (conf->mac_eeprom_smbus != 0) {
41 /* Read MAC address from EEPROM at first. */
42 struct device *dev_eeprom;
43 dev_eeprom = dev_find_slot_on_smbus(conf->mac_eeprom_smbus,
44 conf->mac_eeprom_addr);
47 /* If that is valid we will use that. */
50 for (i = 0; i < 6; i++) {
51 status = smbus_read_byte(dev_eeprom, i);
54 dat[i] = status & 0xff;
58 for (i = 3; i >= 0; i--) {
62 if (mac_l != 0xffffffff) {
65 for (i = 5; i >= 4; i--) {
75 /* If that is invalid we will read that from romstrap. */
77 unsigned long mac_pos;
78 mac_pos = 0xffffffd0; /* See romstrap.inc and romstrap.lds. */
79 mac_l = read32(mac_pos) + nic_index;
80 mac_h = read32(mac_pos + 4);
83 /* Set that into NIC MMIO. */
84 #define NvRegMacAddrA 0xA8
85 #define NvRegMacAddrB 0xAC
86 write32(base + NvRegMacAddrA, mac_l);
87 write32(base + NvRegMacAddrB, mac_h);
89 /* Set that into NIC. */
90 pci_write_config32(dev, 0xa8, mac_l);
91 pci_write_config32(dev, 0xac, mac_h);
96 #if CONFIG_PCI_ROM_RUN == 1
97 pci_dev_init(dev); /* It will init Option ROM. */
101 static void lpci_set_subsystem(device_t dev, unsigned vendor, unsigned device)
103 pci_write_config32(dev, 0x40,
104 ((device & 0xffff) << 16) | (vendor & 0xffff));
107 static struct pci_operations lops_pci = {
108 .set_subsystem = lpci_set_subsystem,
111 static struct device_operations nic_ops = {
112 .read_resources = pci_dev_read_resources,
113 .set_resources = pci_dev_set_resources,
114 .enable_resources = pci_dev_enable_resources,
117 // .enable = ck804_enable,
118 .ops_pci = &lops_pci,
121 static const struct pci_driver nic_driver __pci_driver = {
123 .vendor = PCI_VENDOR_ID_NVIDIA,
124 .device = PCI_DEVICE_ID_NVIDIA_CK804_NIC,
127 static const struct pci_driver nic_bridge_driver __pci_driver = {
129 .vendor = PCI_VENDOR_ID_NVIDIA,
130 .device = PCI_DEVICE_ID_NVIDIA_CK804_NIC_BRIDGE,