aa06253a4672c87cdedb5cbb3315e74cc6267e60
[coreboot.git] / src / southbridge / amd / amd8111 / amd8111_nic.c
1 /*
2  * (C) 2003 Linux Networx
3  */
4 #include <console/console.h>
5 #include <device/device.h>
6 #include <device/pci.h>
7 #include <device/pci_ids.h>
8 #include <device/pci_ops.h>
9 #include <arch/io.h>
10 #include <delay.h>
11 #include "amd8111.h"
12
13
14 #define CMD3            0x54
15
16 typedef enum {
17         VAL3                    = (1 << 31),   /* VAL bit for byte 3 */
18         VAL2                    = (1 << 23),   /* VAL bit for byte 2 */
19         VAL1                    = (1 << 15),   /* VAL bit for byte 1 */
20         VAL0                    = (1 << 7),    /* VAL bit for byte 0 */
21 }VAL_BITS;
22
23 typedef enum {
24         /* VAL3 */
25         ASF_INIT_DONE_ALIAS     = (1 << 29),
26         /* VAL2 */
27         JUMBO                   = (1 << 21),
28         VSIZE                   = (1 << 20),    
29         VLONLY                  = (1 << 19),
30         VL_TAG_DEL              = (1 << 18),    
31         /* VAL1 */
32         EN_PMGR                 = (1 << 14),                    
33         INTLEVEL                = (1 << 13),
34         FORCE_FULL_DUPLEX       = (1 << 12),    
35         FORCE_LINK_STATUS       = (1 << 11),    
36         APEP                    = (1 << 10),    
37         MPPLBA                  = (1 << 9),     
38         /* VAL0 */
39         RESET_PHY_PULSE         = (1 << 2),     
40         RESET_PHY               = (1 << 1),     
41         PHY_RST_POL             = (1 << 0),     
42 }CMD3_BITS;
43
44 static void nic_init(struct device *dev)
45 {
46         struct southbridge_amd_amd8111_config *conf;
47         struct resource *resource;
48         unsigned long mmio;
49
50         conf = dev->chip_info;
51         resource = find_resource(dev, PCI_BASE_ADDRESS_0);
52         mmio = resource->base;
53
54         /* Hard Reset PHY */
55         printk_debug("Reseting PHY... ");
56         if (conf->phy_lowreset) {
57                 write32((mmio + CMD3), VAL0 | PHY_RST_POL | RESET_PHY);
58         } else {
59                 write32((mmio + CMD3), VAL0 | RESET_PHY);
60         }
61         mdelay(15);
62         write32((mmio + CMD3), RESET_PHY);
63         printk_debug("Done\n");
64 }
65
66 static void lpci_set_subsystem(device_t dev, unsigned vendor, unsigned device)
67 {
68         pci_write_config32(dev, 0xc8,
69                 ((device & 0xffff) << 16) | (vendor & 0xffff));
70 }
71
72 static struct pci_operations lops_pci = {
73         .set_subsystem = lpci_set_subsystem,
74 };
75         
76 static struct device_operations nic_ops  = {
77         .read_resources   = pci_dev_read_resources,
78         .set_resources    = pci_dev_set_resources,
79         .enable_resources = pci_dev_enable_resources,
80         .init             = nic_init,
81         .scan_bus         = 0,
82         .enable           = amd8111_enable,
83         .ops_pci          = &lops_pci,
84 };
85
86 static const struct pci_driver nic_driver __pci_driver = {
87         .ops    = &nic_ops,
88         .vendor = PCI_VENDOR_ID_AMD,
89         .device = PCI_DEVICE_ID_AMD_8111_NIC,
90 };