blob: 75f2d466160cd94e74091592541d9be9bc2dce42 [file] [log] [blame]
Yinghai Luafd34e62006-02-16 17:22:19 +00001/*
Uwe Hermannc6a10622010-10-17 19:30:58 +00002 * 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 Luafd34e62006-02-16 17:22:19 +000015 */
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 Luafd34e62006-02-16 17:22:19 +000026static void sata_init(struct device *dev)
27{
Yinghai Luafd34e62006-02-16 17:22:19 +000028 uint8_t byte;
29
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080030 u8 *mmio;
Yinghai Luafd34e62006-02-16 17:22:19 +000031 struct resource *res;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080032 u8 *mmio_base;
Yinghai Luafd34e62006-02-16 17:22:19 +000033 int i;
34
Stefan Reinauer2b34db82009-02-28 20:10:20 +000035 if(!(dev->path.pci.devfn & 7)) { // only set it in Func0
Yinghai Luafd34e62006-02-16 17:22:19 +000036 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 Herbertbde6d302014-12-24 18:43:20 -080041 mmio_base = res2mmio(res, 0, 3);
Stefan Reinauerc51dc442010-04-07 01:44:04 +000042
43 write32(mmio_base + 0x10f0, 0x40000001);
44 write32(mmio_base + 0x8c, 0x00ff2007);
bxshifaea4c52006-11-02 16:02:33 +000045 mdelay( 10 );
Stefan Reinauerc51dc442010-04-07 01:44:04 +000046 write32(mmio_base + 0x8c, 0x78592009);
bxshifaea4c52006-11-02 16:02:33 +000047 mdelay( 10 );
Stefan Reinauerc51dc442010-04-07 01:44:04 +000048 write32(mmio_base + 0x8c, 0x00082004);
bxshifaea4c52006-11-02 16:02:33 +000049 mdelay( 10 );
Stefan Reinauerc51dc442010-04-07 01:44:04 +000050 write32(mmio_base + 0x8c, 0x00002004);
bxshifaea4c52006-11-02 16:02:33 +000051 mdelay( 10 );
52
Yinghai Luafd34e62006-02-16 17:22:19 +000053 //init PHY
54
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000055 printk(BIOS_DEBUG, "init PHY...\n");
Yinghai Luafd34e62006-02-16 17:22:19 +000056 for(i=0; i<4; i++) {
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080057 mmio = (u8 *)(uintptr_t)(res->base + 0x100 * i);
Stefan Reinauer9fe4d792010-01-16 17:53:38 +000058 byte = read8(mmio + 0x40);
Stefan Reinauer64ed2b72010-03-31 14:47:43 +000059 printk(BIOS_DEBUG, "port %d PHY status = %02x\n", i, byte);
Yinghai Luafd34e62006-02-16 17:22:19 +000060 if(byte & 0x4) {// bit 2 is set
Stefan Reinauer9fe4d792010-01-16 17:53:38 +000061 byte = read8(mmio+0x48);
62 write8(mmio + 0x48, byte | 1);
63 write8(mmio + 0x48, byte & (~1));
64 byte = read8(mmio + 0x40);
Stefan Reinauer64ed2b72010-03-31 14:47:43 +000065 printk(BIOS_DEBUG, "after reset port %d PHY status = %02x\n", i, byte);
Yinghai Luafd34e62006-02-16 17:22:19 +000066 }
67 }
Yinghai Luafd34e62006-02-16 17:22:19 +000068 }
Yinghai Luafd34e62006-02-16 17:22:19 +000069}
70
71static 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 Hermannc6a10622010-10-17 19:30:58 +000076
Yinghai Luafd34e62006-02-16 17:22:19 +000077static struct pci_operations lops_pci = {
78 .set_subsystem = lpci_set_subsystem,
79};
80
81static 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 Reinauerf1cf1f72007-10-24 09:08:58 +000091static const struct pci_driver sata0_driver __pci_driver = {
Yinghai Luafd34e62006-02-16 17:22:19 +000092 .ops = &sata_ops,
93 .vendor = PCI_VENDOR_ID_SERVERWORKS,
94 .device = PCI_DEVICE_ID_SERVERWORKS_BCM5785_SATA,
95};