Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 1 | /* |
Uwe Hermann | c6a1062 | 2010-10-17 19:30:58 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2005 AMD |
| 5 | * Written by Yinghai Lu <yinghai.lu@amd.com> for AMD. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <console/console.h> |
| 18 | #include <device/device.h> |
| 19 | #include <delay.h> |
| 20 | #include <device/pci.h> |
| 21 | #include <device/pci_ids.h> |
| 22 | #include <device/pci_ops.h> |
| 23 | #include <arch/io.h> |
| 24 | #include "bcm5785.h" |
| 25 | |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 26 | static void sata_init(struct device *dev) |
| 27 | { |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 28 | uint8_t byte; |
| 29 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 30 | u8 *mmio; |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 31 | struct resource *res; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 32 | u8 *mmio_base; |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 33 | int i; |
| 34 | |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 35 | if(!(dev->path.pci.devfn & 7)) { // only set it in Func0 |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 36 | byte = pci_read_config8(dev, 0x78); |
| 37 | byte |= (1<<7); |
| 38 | pci_write_config8(dev, 0x78, byte); |
| 39 | |
| 40 | res = find_resource(dev, 0x24); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 41 | mmio_base = res2mmio(res, 0, 3); |
Stefan Reinauer | c51dc44 | 2010-04-07 01:44:04 +0000 | [diff] [blame] | 42 | |
| 43 | write32(mmio_base + 0x10f0, 0x40000001); |
| 44 | write32(mmio_base + 0x8c, 0x00ff2007); |
bxshi | faea4c5 | 2006-11-02 16:02:33 +0000 | [diff] [blame] | 45 | mdelay( 10 ); |
Stefan Reinauer | c51dc44 | 2010-04-07 01:44:04 +0000 | [diff] [blame] | 46 | write32(mmio_base + 0x8c, 0x78592009); |
bxshi | faea4c5 | 2006-11-02 16:02:33 +0000 | [diff] [blame] | 47 | mdelay( 10 ); |
Stefan Reinauer | c51dc44 | 2010-04-07 01:44:04 +0000 | [diff] [blame] | 48 | write32(mmio_base + 0x8c, 0x00082004); |
bxshi | faea4c5 | 2006-11-02 16:02:33 +0000 | [diff] [blame] | 49 | mdelay( 10 ); |
Stefan Reinauer | c51dc44 | 2010-04-07 01:44:04 +0000 | [diff] [blame] | 50 | write32(mmio_base + 0x8c, 0x00002004); |
bxshi | faea4c5 | 2006-11-02 16:02:33 +0000 | [diff] [blame] | 51 | mdelay( 10 ); |
| 52 | |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 53 | //init PHY |
| 54 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 55 | printk(BIOS_DEBUG, "init PHY...\n"); |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 56 | for(i=0; i<4; i++) { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 57 | mmio = (u8 *)(uintptr_t)(res->base + 0x100 * i); |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 58 | byte = read8(mmio + 0x40); |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 59 | printk(BIOS_DEBUG, "port %d PHY status = %02x\n", i, byte); |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 60 | if(byte & 0x4) {// bit 2 is set |
Stefan Reinauer | 9fe4d79 | 2010-01-16 17:53:38 +0000 | [diff] [blame] | 61 | byte = read8(mmio+0x48); |
| 62 | write8(mmio + 0x48, byte | 1); |
| 63 | write8(mmio + 0x48, byte & (~1)); |
| 64 | byte = read8(mmio + 0x40); |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 65 | printk(BIOS_DEBUG, "after reset port %d PHY status = %02x\n", i, byte); |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 66 | } |
| 67 | } |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 68 | } |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static void lpci_set_subsystem(device_t dev, unsigned vendor, unsigned device) |
| 72 | { |
| 73 | pci_write_config32(dev, 0x40, |
| 74 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 75 | } |
Uwe Hermann | c6a1062 | 2010-10-17 19:30:58 +0000 | [diff] [blame] | 76 | |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 77 | static struct pci_operations lops_pci = { |
| 78 | .set_subsystem = lpci_set_subsystem, |
| 79 | }; |
| 80 | |
| 81 | static struct device_operations sata_ops = { |
| 82 | .read_resources = pci_dev_read_resources, |
| 83 | .set_resources = pci_dev_set_resources, |
| 84 | .enable_resources = pci_dev_enable_resources, |
| 85 | // .enable = bcm5785_enable, |
| 86 | .init = sata_init, |
| 87 | .scan_bus = 0, |
| 88 | .ops_pci = &lops_pci, |
| 89 | }; |
| 90 | |
Stefan Reinauer | f1cf1f7 | 2007-10-24 09:08:58 +0000 | [diff] [blame] | 91 | static const struct pci_driver sata0_driver __pci_driver = { |
Yinghai Lu | afd34e6 | 2006-02-16 17:22:19 +0000 | [diff] [blame] | 92 | .ops = &sata_ops, |
| 93 | .vendor = PCI_VENDOR_ID_SERVERWORKS, |
| 94 | .device = PCI_DEVICE_ID_SERVERWORKS_BCM5785_SATA, |
| 95 | }; |