blob: ec050cb2c3221b92b66f16403dc0e67985946fe6 [file] [log] [blame]
Rudolf Marek133647a2010-04-05 19:47:34 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2010 Advanced Micro Devices, Inc.
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.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <console/console.h>
21#include <device/device.h>
22#include <device/pci.h>
23#include <arch/io.h>
Stefan Reinauer23836e22010-04-15 12:39:29 +000024#include <boot/tables.h>
Rudolf Marek133647a2010-04-05 19:47:34 +000025#include <cpu/x86/msr.h>
26#include <cpu/amd/mtrr.h>
27#include <device/pci_def.h>
efdesign9800c8c4a2011-07-20 12:37:58 -060028#include "southbridge/amd/sb700/sb700.h"
29#include "southbridge/amd/sb700/smbus.h"
Rudolf Marek133647a2010-04-05 19:47:34 +000030#include "chip.h"
31
Rudolf Marek133647a2010-04-05 19:47:34 +000032void set_pcie_dereset(void);
33void set_pcie_reset(void);
Wang Qing Pei543f7672010-08-17 11:11:09 +000034u8 is_dev3_present(void);
Rudolf Marek837403d2011-02-26 19:46:08 +000035
36static void pcie_rst_toggle(u8 val) {
37 u8 byte;
38
39 byte = pm_ioread(0x8d);
40 byte &= ~(3 << 1);
41 pm_iowrite(0x8d, byte);
42
43 byte = pm_ioread(0x94);
44 /* Output enable */
45 byte &= ~(3 << 2);
46 /* Toggle GPM8, GPM9 */
47 byte &= ~(3 << 0);
48 byte |= val;
49 pm_iowrite(0x94, byte);
50}
51
Rudolf Marek133647a2010-04-05 19:47:34 +000052void set_pcie_dereset()
53{
Rudolf Marek837403d2011-02-26 19:46:08 +000054 pcie_rst_toggle(0x3);
Rudolf Marek133647a2010-04-05 19:47:34 +000055}
56
57void set_pcie_reset()
58{
Rudolf Marek837403d2011-02-26 19:46:08 +000059 pcie_rst_toggle(0x0);
Rudolf Marek133647a2010-04-05 19:47:34 +000060}
61
62#if 0 /* not tested yet */
63/********************************************************
64* mahogany uses SB700 GPIO9 to detect IDE_DMA66.
65* IDE_DMA66 is routed to GPIO 9. So we read Gpio 9 to
66* get the cable type, 40 pin or 80 pin?
67********************************************************/
68static void get_ide_dma66(void)
69{
70 u8 byte;
71 /*u32 sm_dev, ide_dev; */
72 device_t sm_dev, ide_dev;
73
74 sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
75
76 byte = pci_read_config8(sm_dev, 0xA9);
77 byte |= (1 << 5); /* Set Gpio9 as input */
78 pci_write_config8(sm_dev, 0xA9, byte);
79
80 ide_dev = dev_find_slot(0, PCI_DEVFN(0x14, 1));
81 byte = pci_read_config8(ide_dev, 0x56);
82 byte &= ~(7 << 0);
83 if ((1 << 5) & pci_read_config8(sm_dev, 0xAA))
84 byte |= 2 << 0; /* mode 2 */
85 else
86 byte |= 5 << 0; /* mode 5 */
87 pci_write_config8(ide_dev, 0x56, byte);
88}
89#endif /* get_ide_dma66 */
90
Wang Qing Pei543f7672010-08-17 11:11:09 +000091u8 is_dev3_present(void)
92{
93 return 0;
94}
95
Rudolf Marek133647a2010-04-05 19:47:34 +000096/*************************************************
97* enable the dedicated function in mahogany board.
98* This function called early than rs780_enable.
99*************************************************/
Rudolf Marekc7d27732010-08-17 21:03:17 +0000100static void mb_enable(device_t dev)
Rudolf Marek133647a2010-04-05 19:47:34 +0000101{
Rudolf Marekc7d27732010-08-17 21:03:17 +0000102 printk(BIOS_INFO, "Mainboard 939A785GMH/128M Enable. dev=0x%p\n", dev);
Rudolf Marek133647a2010-04-05 19:47:34 +0000103
Kyösti Mälkkiba589e32012-07-11 08:03:13 +0300104 setup_uma_memory();
Rudolf Marek133647a2010-04-05 19:47:34 +0000105
106 set_pcie_dereset();
107 /* get_ide_dma66(); */
108}
109
110int add_mainboard_resources(struct lb_memory *mem)
111{
Rudolf Marek133647a2010-04-05 19:47:34 +0000112 return 0;
113}
114
115struct chip_operations mainboard_ops = {
Rudolf Marekc7d27732010-08-17 21:03:17 +0000116 CHIP_NAME("Asrock 939A785GMH/128M Mainboard")
117 .enable_dev = mb_enable,
Rudolf Marek133647a2010-04-05 19:47:34 +0000118};
Rudolf Marek7df50a82010-09-22 22:46:47 +0000119
120/* override the default SATA PHY setup */
Zheng Baoc3422232011-03-28 03:33:10 +0000121void sb7xx_51xx_setup_sata_phys(struct device *dev) {
Rudolf Marek7df50a82010-09-22 22:46:47 +0000122 /* RPR7.6.1 Program the PHY Global Control to 0x2C00 */
123 pci_write_config16(dev, 0x86, 0x2c00);
124
125 /* RPR7.6.2 SATA GENI PHY ports setting */
126 pci_write_config32(dev, 0x88, 0x01B48016);
127 pci_write_config32(dev, 0x8c, 0x01B48016);
128 pci_write_config32(dev, 0x90, 0x01B48016);
129 pci_write_config32(dev, 0x94, 0x01B48016);
130 pci_write_config32(dev, 0x98, 0x01B48016);
131 pci_write_config32(dev, 0x9C, 0x01B48016);
132
133 /* RPR7.6.3 SATA GEN II PHY port setting for port [0~5]. */
134 pci_write_config16(dev, 0xA0, 0xA07A);
135 pci_write_config16(dev, 0xA2, 0xA07A);
136 pci_write_config16(dev, 0xA4, 0xA07A);
137 pci_write_config16(dev, 0xA6, 0xA07A);
138 pci_write_config16(dev, 0xA8, 0xA07A);
139 pci_write_config16(dev, 0xAA, 0xA0FF);
140}