2 * This file is part of the coreboot project.
4 * Copyright (C) 2004 Nick Barker <nick.barker9@btinternet.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
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.
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,
22 /* vt1211 routines and defines*/
25 #include <console/console.h>
26 #include <device/device.h>
27 #include <device/pnp.h>
34 static unsigned char vt1211hwmonitorinits[]={
35 0x10,0x3, 0x11,0x10, 0x12,0xd, 0x13,0x7f,
36 0x14,0x21, 0x15,0x81, 0x16,0xbd, 0x17,0x8a,
37 0x18,0x0, 0x19,0x0, 0x1a,0x0, 0x1b,0x0,
38 0x1d,0xff, 0x1e,0x0, 0x1f,0x73, 0x20,0x67,
39 0x21,0xc1, 0x22,0xca, 0x23,0x74, 0x24,0xc2,
40 0x25,0xc7, 0x26,0xc9, 0x27,0x7f, 0x29,0x0,
41 0x2a,0x0, 0x2b,0xff, 0x2c,0x0, 0x2d,0xff,
42 0x2e,0x0, 0x2f,0xff, 0x30,0x0, 0x31,0xff,
43 0x32,0x0, 0x33,0xff, 0x34,0x0, 0x39,0xff,
44 0x3a,0x0, 0x3b,0xff, 0x3c,0xff, 0x3d,0xff,
45 0x3e,0x0, 0x3f,0xb0, 0x43,0xff, 0x44,0xff,
46 0x46,0xff, 0x47,0x50, 0x4a,0x3, 0x4b,0xc0,
47 0x4c,0x0, 0x4d,0x0, 0x4e,0xf, 0x5d,0x77,
48 0x5c,0x0, 0x5f,0x33, 0x40,0x1
51 static void pnp_enter_ext_func_mode(device_t dev)
53 outb(0x87, dev->path.pnp.port);
54 outb(0x87, dev->path.pnp.port);
57 static void pnp_exit_ext_func_mode(device_t dev)
59 outb(0xaa, dev->path.pnp.port);
62 static void vt1211_set_iobase(device_t dev, unsigned index, unsigned iobase)
64 switch (dev->path.pnp.device) {
69 pnp_write_config(dev, index + 0, (iobase >> 2) & 0xff);
73 pnp_write_config(dev, index + 0, (iobase >> 8) & 0xff);
74 pnp_write_config(dev, index + 1, iobase & 0xff);
79 static void init_hwm(unsigned long base)
83 /* initialize vt1211 hardware monitor registers, which are at 0xECXX */
84 for(i = 0; i < sizeof(vt1211hwmonitorinits); i += 2) {
85 outb(vt1211hwmonitorinits[i + 1],
86 base + vt1211hwmonitorinits[i]);
90 static void vt1211_init(struct device *dev)
92 struct superio_via_vt1211_config *conf = dev->chip_info;
93 struct resource *res0;
99 switch (dev->path.pnp.device) {
104 res0 = find_resource(dev, PNP_IDX_IO0);
105 init_uart8250(res0->base, &conf->com1);
108 res0 = find_resource(dev, PNP_IDX_IO0);
109 init_uart8250(res0->base, &conf->com2);
112 res0 = find_resource(dev, PNP_IDX_IO0);
113 init_hwm(res0->base);
116 printk(BIOS_INFO, "vt1211 asked to initialise unknown device!\n");
120 static void vt1211_pnp_enable_resources(device_t dev)
122 printk(BIOS_DEBUG, "%s - enabling\n",dev_path(dev));
123 pnp_enter_ext_func_mode(dev);
124 pnp_enable_resources(dev);
125 pnp_exit_ext_func_mode(dev);
128 static void vt1211_pnp_set_resources(struct device *dev)
130 struct resource *res;
132 #if CONFIG_CONSOLE_SERIAL8250 == 1
133 if( dev->path.pnp.device == 2 ){
134 for(res = dev->resource_list; res; res = res->next){
135 res->flags |= IORESOURCE_STORED;
136 report_resource_stored(dev, res, "");
141 pnp_enter_ext_func_mode(dev);
142 /* Select the device */
143 pnp_set_logical_device(dev);
145 /* Paranoia says I should disable the device here... */
146 for(res = dev->resource_list; res; res = res->next){
147 if (!(res->flags & IORESOURCE_ASSIGNED)) {
148 printk(BIOS_ERR, "ERROR: %s %02lx %s size: 0x%010Lx not assigned\n",
149 dev_path(dev), res->index,
155 /* Now store the resource */
156 if (res->flags & IORESOURCE_IO) {
157 vt1211_set_iobase(dev, res->index, res->base);
159 else if (res->flags & IORESOURCE_DRQ) {
160 pnp_set_drq(dev, res->index, res->base);
162 else if (res->flags & IORESOURCE_IRQ) {
163 pnp_set_irq(dev, res->index, res->base);
166 printk(BIOS_ERR, "ERROR: %s %02lx unknown resource type\n",
167 dev_path(dev), res->index);
170 res->flags |= IORESOURCE_STORED;
172 report_resource_stored(dev, res, "");
175 pnp_exit_ext_func_mode(dev);
178 static void vt1211_pnp_enable(device_t dev)
181 pnp_enter_ext_func_mode(dev);
182 pnp_set_logical_device(dev);
183 pnp_set_enable(dev, 0);
184 pnp_exit_ext_func_mode(dev);
188 struct device_operations ops = {
189 .read_resources = pnp_read_resources,
190 .set_resources = vt1211_pnp_set_resources,
191 .enable_resources = vt1211_pnp_enable_resources,
192 .enable = vt1211_pnp_enable,
196 static struct pnp_info pnp_dev_info[] = {
197 { &ops, VT1211_FDC, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, { 0x07f8, 0}, },
198 { &ops, VT1211_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, { 0x07f8, 0}, },
199 { &ops, VT1211_SP1, PNP_IO0 | PNP_IRQ0, { 0x07f8, 0}, },
200 { &ops, VT1211_SP2, PNP_IO0 | PNP_IRQ0, { 0x07f8, 0}, },
201 { &ops, VT1211_HWM, PNP_IO0 , { 0xff00, 0 }, },
204 static void enable_dev(struct device *dev)
206 printk(BIOS_DEBUG, "vt1211 enabling PNP devices.\n");
207 pnp_enable_devices(dev,
209 ARRAY_SIZE(pnp_dev_info),
213 struct chip_operations superio_via_vt1211_ops = {
214 CHIP_NAME("VIA VT1211 Super I/O")
215 .enable_dev = enable_dev,