Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 1 | /* |
Martin Roth | ebace9f | 2018-05-26 18:56:17 -0600 | [diff] [blame^] | 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * (C) 2004 Linux Networx |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 14 | */ |
Martin Roth | ebace9f | 2018-05-26 18:56:17 -0600 | [diff] [blame^] | 15 | |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 16 | #include <console/console.h> |
| 17 | #include <device/device.h> |
| 18 | #include <device/pci.h> |
| 19 | #include <device/pci_ids.h> |
| 20 | #include <device/pci_ops.h> |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 21 | #include <arch/io.h> |
Myles Watson | 43bb9cd | 2008-12-18 18:24:11 +0000 | [diff] [blame] | 22 | #include <delay.h> |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 23 | #include "amd8111.h" |
| 24 | |
| 25 | |
Kevin Paul Herbert | 4104e6c | 2015-02-25 00:36:51 -0800 | [diff] [blame] | 26 | #define CMD3 0x54 |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 27 | |
| 28 | typedef enum { |
| 29 | VAL3 = (1 << 31), /* VAL bit for byte 3 */ |
| 30 | VAL2 = (1 << 23), /* VAL bit for byte 2 */ |
| 31 | VAL1 = (1 << 15), /* VAL bit for byte 1 */ |
| 32 | VAL0 = (1 << 7), /* VAL bit for byte 0 */ |
| 33 | }VAL_BITS; |
| 34 | |
| 35 | typedef enum { |
| 36 | /* VAL3 */ |
| 37 | ASF_INIT_DONE_ALIAS = (1 << 29), |
| 38 | /* VAL2 */ |
| 39 | JUMBO = (1 << 21), |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 40 | VSIZE = (1 << 20), |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 41 | VLONLY = (1 << 19), |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 42 | VL_TAG_DEL = (1 << 18), |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 43 | /* VAL1 */ |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 44 | EN_PMGR = (1 << 14), |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 45 | INTLEVEL = (1 << 13), |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 46 | FORCE_FULL_DUPLEX = (1 << 12), |
| 47 | FORCE_LINK_STATUS = (1 << 11), |
| 48 | APEP = (1 << 10), |
| 49 | MPPLBA = (1 << 9), |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 50 | /* VAL0 */ |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 51 | RESET_PHY_PULSE = (1 << 2), |
| 52 | RESET_PHY = (1 << 1), |
| 53 | PHY_RST_POL = (1 << 0), |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 54 | }CMD3_BITS; |
| 55 | |
| 56 | static void nic_init(struct device *dev) |
| 57 | { |
| 58 | struct southbridge_amd_amd8111_config *conf; |
| 59 | struct resource *resource; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 60 | u8 *mmio; |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 61 | |
| 62 | conf = dev->chip_info; |
| 63 | resource = find_resource(dev, PCI_BASE_ADDRESS_0); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 64 | mmio = res2mmio(resource, 0, 0); |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 65 | |
| 66 | /* Hard Reset PHY */ |
Paul Menzel | 4159a80 | 2013-07-14 00:24:31 +0200 | [diff] [blame] | 67 | printk(BIOS_DEBUG, "Resetting PHY... "); |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 68 | if (conf->phy_lowreset) { |
Stefan Reinauer | 50776fa | 2010-03-17 04:40:15 +0000 | [diff] [blame] | 69 | write32((mmio + CMD3), VAL0 | PHY_RST_POL | RESET_PHY); |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 70 | } else { |
Stefan Reinauer | 50776fa | 2010-03-17 04:40:15 +0000 | [diff] [blame] | 71 | write32((mmio + CMD3), VAL0 | RESET_PHY); |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 72 | } |
| 73 | mdelay(15); |
Stefan Reinauer | 50776fa | 2010-03-17 04:40:15 +0000 | [diff] [blame] | 74 | write32((mmio + CMD3), RESET_PHY); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 75 | printk(BIOS_DEBUG, "Done\n"); |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Elyes HAOUAS | 39733a0 | 2018-05-19 14:45:20 +0200 | [diff] [blame] | 78 | static void lpci_set_subsystem(struct device *dev, unsigned vendor, |
| 79 | unsigned device) |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 80 | { |
| 81 | pci_write_config32(dev, 0xc8, |
| 82 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 83 | } |
| 84 | |
| 85 | static struct pci_operations lops_pci = { |
| 86 | .set_subsystem = lpci_set_subsystem, |
| 87 | }; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 88 | |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 89 | static struct device_operations nic_ops = { |
| 90 | .read_resources = pci_dev_read_resources, |
| 91 | .set_resources = pci_dev_set_resources, |
| 92 | .enable_resources = pci_dev_enable_resources, |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 93 | .init = nic_init, |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 94 | .scan_bus = 0, |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 95 | .enable = amd8111_enable, |
| 96 | .ops_pci = &lops_pci, |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 97 | }; |
| 98 | |
Stefan Reinauer | f1cf1f7 | 2007-10-24 09:08:58 +0000 | [diff] [blame] | 99 | static const struct pci_driver nic_driver __pci_driver = { |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 100 | .ops = &nic_ops, |
| 101 | .vendor = PCI_VENDOR_ID_AMD, |
arch import user (historical) | bc5be47 | 2005-07-06 16:48:04 +0000 | [diff] [blame] | 102 | .device = PCI_DEVICE_ID_AMD_8111_NIC, |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 103 | }; |