This patch is buzzer of TechNexion TIM-5690.
[coreboot.git] / src / mainboard / technexion / tim5690 / tn_post_code.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2009 Libra Li <libra.li@technexion.com>
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; either version 2 of the License, or
9  * (at your option) any later version.
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.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19  */
20
21
22 #ifdef __PRE_RAM__
23
24 #include <arch/cpu.h>
25 #include "southbridge/amd/sb600/sb600.h"
26
27 #else
28
29 #include <device/pci.h>
30 #include <device/pci_ids.h>
31
32 #endif
33
34 #include "tn_post_code.h"
35
36
37 #ifdef __PRE_RAM__
38
39 // TechNexion's Post Code Initially.
40 void technexion_post_code_init(void)
41 {
42    uint8_t reg8_data;
43    device_t dev=0;
44
45    // SMBus Module and ACPI Block (Device 20, Function 0)
46    dev = pci_locate_device(PCI_ID(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SB600_SM), 0);
47
48    // LED[bit0]:GPIO0
49    // This is reference SB600 RRG 4.1.1 GPIO
50    reg8_data = pmio_read(0x60);
51    reg8_data |= (1<<7);  // 1: GPIO if not used by SATA
52    pmio_write(0x60, reg8_data);
53
54    reg8_data = pci_read_config8(dev, 0x80);
55    reg8_data = ((reg8_data | (1<<0)) & ~(1<<4));
56    pci_write_config8(dev, 0x80, reg8_data);
57
58    // LED[bit1]:GPIO1
59    // This is reference SB600 RRG 4.1.1 GPIO
60    reg8_data = pci_read_config8(dev, 0x80);
61    reg8_data = ((reg8_data | (1<<1)) & ~(1<<5));
62    pci_write_config8(dev, 0x80, reg8_data);
63
64    // LED[bit2]:GPIO4
65    // This is reference SB600 RRG 4.1.1 GPIO
66    reg8_data = pmio_read(0x5e);
67    reg8_data &= ~(1<<7); // 0: GPIO if not used by SATA
68    pmio_write(0x5e, reg8_data);
69
70    reg8_data = pci_read_config8(dev, 0xa8);
71    reg8_data |= (1<<0);
72    pci_write_config8(dev, 0xa8, reg8_data);
73
74    reg8_data = pci_read_config8(dev, 0xa9);
75    reg8_data &= ~(1<<0);
76    pci_write_config8(dev, 0xa9, reg8_data);
77
78    // LED[bit3]:GPIO6
79    // This is reference SB600 RRG 4.1.1 GPIO
80    reg8_data = pmio_read(0x60);
81    reg8_data |= (1<<7); // 1: GPIO if not used by SATA
82    pmio_write(0x60, reg8_data);
83
84    reg8_data = pci_read_config8(dev, 0xa8);
85    reg8_data |= (1<<2);
86    pci_write_config8(dev, 0xa8, reg8_data);
87
88    reg8_data = pci_read_config8(dev, 0xa9);
89    reg8_data &= ~(1<<2);
90    pci_write_config8(dev, 0xa9, reg8_data);
91    // LED[bit4]:GPIO7
92    // This is reference SB600 RRG 4.1.1 GPIO
93    reg8_data = pci_read_config8(dev, 0xa8);
94    reg8_data |= (1<<3);
95    pci_write_config8(dev, 0xa8, reg8_data);
96
97    reg8_data = pci_read_config8(dev, 0xa9);
98    reg8_data &= ~(1<<3);
99    pci_write_config8(dev, 0xa9, reg8_data);
100
101    // LED[bit5]:GPIO8
102    // This is reference SB600 RRG 4.1.1 GPIO
103    reg8_data = pci_read_config8(dev, 0xa8);
104    reg8_data |= (1<<4);
105    pci_write_config8(dev, 0xa8, reg8_data);
106
107    reg8_data = pci_read_config8(dev, 0xa9);
108    reg8_data &= ~(1<<4);
109    pci_write_config8(dev, 0xa9, reg8_data);
110
111    // LED[bit6]:GPIO10
112    // This is reference SB600 RRG 4.1.1 GPIO
113    reg8_data = pci_read_config8(dev, 0xab);
114    reg8_data = ((reg8_data | (1<<0)) & ~(1<<1));
115    pci_write_config8(dev, 0xab, reg8_data);
116
117    // LED[bit7]:GPIO66
118    // This is reference SB600 RRG 4.1.1 GPIO
119    reg8_data = pmio_read(0x68);
120    reg8_data &= ~(1<<5); // 0: GPIO
121    pmio_write(0x68, reg8_data);
122
123    reg8_data = pci_read_config8(dev, 0x7e);
124    reg8_data = ((reg8_data | (1<<1)) & ~(1<<5));
125    pci_write_config8(dev, 0x7e, reg8_data);
126
127 }
128
129 #endif
130
131 /* TechNexion's Post Code.
132  */
133 void technexion_post_code(uint8_t udata8)
134 {
135    uint8_t u8_data;
136    device_t dev=0;
137
138    // SMBus Module and ACPI Block (Device 20, Function 0)
139 #ifdef __PRE_RAM__
140    dev = pci_locate_device(PCI_ID(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SB600_SM), 0);
141 #else
142    dev = dev_find_device(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SB600_SM, 0);
143 #endif
144
145    udata8 = ~(udata8);
146
147    // LED[bit0]:GPIO0
148    u8_data = pci_read_config8(dev, 0x80);
149    if (udata8 & 0x1) {
150       u8_data |= (1<<0);
151    }
152    else {
153       u8_data &= ~(1<<0);
154    }
155    pci_write_config8(dev, 0x80, u8_data);
156
157    // LED[bit1]:GPIO1
158    u8_data = pci_read_config8(dev, 0x80);
159    if (udata8 & 0x2) {
160       u8_data |= (1<<1);
161    }
162    else {
163       u8_data &= ~(1<<1);
164    }
165    pci_write_config8(dev, 0x80, u8_data);
166
167    // LED[bit2]:GPIO4
168    u8_data = pci_read_config8(dev, 0xa8);
169    if (udata8 & 0x4) {
170       u8_data |= (1<<0);
171    }
172    else {
173       u8_data &= ~(1<<0);
174    }
175    pci_write_config8(dev, 0xa8, u8_data);
176
177    // LED[bit3]:GPIO6
178    u8_data = pci_read_config8(dev, 0xa8);
179    if (udata8 & 0x8) {
180       u8_data |= (1<<2);
181    }
182    else {
183       u8_data &= ~(1<<2);
184    }
185    pci_write_config8(dev, 0xa8, u8_data);
186
187    // LED[bit4]:GPIO7
188    u8_data = pci_read_config8(dev, 0xa8);
189    if (udata8 & 0x10) {
190       u8_data |= (1<<3);
191    }
192    else {
193       u8_data &= ~(1<<3);
194    }
195    pci_write_config8(dev, 0xa8, u8_data);
196
197    // LED[bit5]:GPIO8
198    u8_data = pci_read_config8(dev, 0xa8);
199    if (udata8 & 0x20) {
200       u8_data |= (1<<4);
201    }
202    else {
203       u8_data &= ~(1<<4);
204    }
205    pci_write_config8(dev, 0xa8, u8_data);
206
207    // LED[bit6]:GPIO10
208    u8_data = pci_read_config8(dev, 0xab);
209    if (udata8 & 0x40) {
210       u8_data |= (1<<0);
211    }
212    else {
213       u8_data &= ~(1<<0);
214    }
215    pci_write_config8(dev, 0xab, u8_data);
216
217    // LED[bit7]:GPIO66
218    u8_data = pci_read_config8(dev, 0x7e);
219    if (udata8 & 0x80) {
220       u8_data |= (1<<1);
221    }
222    else {
223       u8_data &= ~(1<<1);
224    }
225    pci_write_config8(dev, 0x7e, u8_data);
226
227 }