Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 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> |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 9 | #include <arch/io.h> |
Myles Watson | 43bb9cd | 2008-12-18 18:24:11 +0000 | [diff] [blame] | 10 | #include <delay.h> |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 11 | #include "amd8111.h" |
| 12 | |
| 13 | |
Kevin Paul Herbert | 4104e6c | 2015-02-25 00:36:51 -0800 | [diff] [blame] | 14 | #define CMD3 0x54 |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 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), |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 28 | VSIZE = (1 << 20), |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 29 | VLONLY = (1 << 19), |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 30 | VL_TAG_DEL = (1 << 18), |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 31 | /* VAL1 */ |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 32 | EN_PMGR = (1 << 14), |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 33 | INTLEVEL = (1 << 13), |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 34 | FORCE_FULL_DUPLEX = (1 << 12), |
| 35 | FORCE_LINK_STATUS = (1 << 11), |
| 36 | APEP = (1 << 10), |
| 37 | MPPLBA = (1 << 9), |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 38 | /* VAL0 */ |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 39 | RESET_PHY_PULSE = (1 << 2), |
| 40 | RESET_PHY = (1 << 1), |
| 41 | PHY_RST_POL = (1 << 0), |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 42 | }CMD3_BITS; |
| 43 | |
| 44 | static void nic_init(struct device *dev) |
| 45 | { |
| 46 | struct southbridge_amd_amd8111_config *conf; |
| 47 | struct resource *resource; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 48 | u8 *mmio; |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 49 | |
| 50 | conf = dev->chip_info; |
| 51 | resource = find_resource(dev, PCI_BASE_ADDRESS_0); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 52 | mmio = res2mmio(resource, 0, 0); |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 53 | |
| 54 | /* Hard Reset PHY */ |
Paul Menzel | 4159a80 | 2013-07-14 00:24:31 +0200 | [diff] [blame] | 55 | printk(BIOS_DEBUG, "Resetting PHY... "); |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 56 | if (conf->phy_lowreset) { |
Stefan Reinauer | 50776fa | 2010-03-17 04:40:15 +0000 | [diff] [blame] | 57 | write32((mmio + CMD3), VAL0 | PHY_RST_POL | RESET_PHY); |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 58 | } else { |
Stefan Reinauer | 50776fa | 2010-03-17 04:40:15 +0000 | [diff] [blame] | 59 | write32((mmio + CMD3), VAL0 | RESET_PHY); |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 60 | } |
| 61 | mdelay(15); |
Stefan Reinauer | 50776fa | 2010-03-17 04:40:15 +0000 | [diff] [blame] | 62 | write32((mmio + CMD3), RESET_PHY); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 63 | printk(BIOS_DEBUG, "Done\n"); |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 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 | }; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 75 | |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 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, |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 80 | .init = nic_init, |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 81 | .scan_bus = 0, |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 82 | .enable = amd8111_enable, |
| 83 | .ops_pci = &lops_pci, |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 84 | }; |
| 85 | |
Stefan Reinauer | f1cf1f7 | 2007-10-24 09:08:58 +0000 | [diff] [blame] | 86 | static const struct pci_driver nic_driver __pci_driver = { |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 87 | .ops = &nic_ops, |
| 88 | .vendor = PCI_VENDOR_ID_AMD, |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 89 | .device = PCI_DEVICE_ID_AMD_8111_NIC, |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 90 | }; |