blob: e4cbc0734210522fa29ad041440d495cf622cb84 [file] [log] [blame]
zbao246e84b2012-07-13 18:47:03 +08001/*
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
Paul Menzela46a7122013-02-23 18:37:27 +010017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
zbao246e84b2012-07-13 18:47:03 +080018 */
19
20#include <console/console.h>
21
22#include <arch/io.h>
23#include <arch/acpi.h>
24
25#include <device/device.h>
26#include <device/pci.h>
27#include <device/pci_ids.h>
28#include <device/pci_ops.h>
29#include <cbmem.h>
30#include "hudson.h"
31#include "smbus.h"
32
Stefan Reinauer8ada1522012-11-16 13:34:48 -080033#if CONFIG_HAVE_ACPI_RESUME
zbao246e84b2012-07-13 18:47:03 +080034int acpi_get_sleep_type(void)
35{
36 u16 tmp = inw(PM1_CNT_BLK_ADDRESS);
37 tmp = ((tmp & (7 << 10)) >> 10);
38 /* printk(BIOS_DEBUG, "SLP_TYP type was %x\n", tmp); */
39 return (int)tmp;
40}
41#endif
42
43void set_cbmem_toc(struct cbmem_entry *toc)
44{
45 u32 dword = (u32) toc;
46 int nvram_pos = 0xf8, i; /* temp */
47 /* printk(BIOS_DEBUG, "dword=%x\n", dword); */
48 for (i = 0; i<4; i++) {
49 /* printk(BIOS_DEBUG, "nvram_pos=%x, dword>>(8*i)=%x\n", nvram_pos, (dword >>(8 * i)) & 0xff); */
50 outb(nvram_pos, BIOSRAM_INDEX);
51 outb((dword >>(8 * i)) & 0xff , BIOSRAM_DATA);
52 nvram_pos++;
53 }
54}
55
56void set_sm_enable_bits(device_t sm_dev, u32 reg_pos, u32 mask, u32 val)
57{
58 u32 reg_old, reg;
59 reg = reg_old = pci_read_config32(sm_dev, reg_pos);
60 reg &= ~mask;
61 reg |= val;
62 if (reg != reg_old) {
63 pci_write_config32(sm_dev, reg_pos, reg);
64 }
65}
66
67static void pmio_write_index(u16 port_base, u8 reg, u8 value)
68{
69 outb(reg, port_base);
70 outb(value, port_base + 1);
71}
72
73static u8 pmio_read_index(u16 port_base, u8 reg)
74{
75 outb(reg, port_base);
76 return inb(port_base + 1);
77}
78
79void pm_iowrite(u8 reg, u8 value)
80{
81 pmio_write_index(PM_INDEX, reg, value);
82}
83
84u8 pm_ioread(u8 reg)
85{
86 return pmio_read_index(PM_INDEX, reg);
87}
88
89void pm2_iowrite(u8 reg, u8 value)
90{
91 pmio_write_index(PM2_INDEX, reg, value);
92}
93
94u8 pm2_ioread(u8 reg)
95{
96 return pmio_read_index(PM2_INDEX, reg);
97}
98
99
100void hudson_enable(device_t dev)
101{
Martin Rothf5726ea2013-01-18 12:55:40 -0700102 printk(BIOS_DEBUG, "hudson_enable()\n");
Dave Frodinea909632013-05-31 08:15:57 -0600103 switch (dev->path.pci.devfn) {
104 case (0x14 << 3) | 7: /* 0:14.7 SD */
105 if (dev->enabled == 0) {
106 // read the VENDEV ID
107 device_t sd_dev = dev_find_slot( 0, PCI_DEVFN( 0x14, 7));
108 u32 sd_device_id = pci_read_config32( sd_dev, 0) >> 16;
109 /* turn off the SDHC controller in the PM reg */
110 u8 sd_tmp;
111 if (sd_device_id == PCI_DEVICE_ID_AMD_HUDSON_SD) {
112 outb(0xE7, PM_INDEX);
113 sd_tmp = inb(PM_DATA);
114 sd_tmp &= ~(1 << 0);
115 outb(sd_tmp, PM_DATA);
116 }
117 else if (sd_device_id == PCI_DEVICE_ID_AMD_YANGTZE_SD) {
118 outb(0xE8, PM_INDEX);
119 sd_tmp = inb(PM_DATA);
120 sd_tmp &= ~(1 << 0);
121 outb(sd_tmp, PM_DATA);
122 }
123 /* remove device 0:14.7 from PCI space */
124 outb(0xD3, PM_INDEX);
125 sd_tmp = inb(PM_DATA);
126 sd_tmp &= ~(1 << 6);
127 outb(sd_tmp, PM_DATA);
128 }
129 break;
130 default:
131 break;
132 }
zbao246e84b2012-07-13 18:47:03 +0800133}
134
135struct cbmem_entry *get_cbmem_toc(void)
136{
137 uint32_t xdata = 0;
138 int xnvram_pos = 0xf8, xi;
139 for (xi = 0; xi<4; xi++) {
140 outb(xnvram_pos, BIOSRAM_INDEX);
141 xdata &= ~(0xff << (xi * 8));
142 xdata |= inb(BIOSRAM_DATA) << (xi *8);
143 xnvram_pos++;
144 }
145 return (struct cbmem_entry *) xdata;
146}
147
148
149struct chip_operations southbridge_amd_agesa_hudson_ops = {
150 CHIP_NAME("ATI HUDSON")
151 .enable_dev = hudson_enable,
152};