- First stab at running linuxbios without the old static device tree.
[coreboot.git] / src / superio / via / vt1211 / vt1211.c
1 /*
2  * (C) Copyright 2004 Nick Barker <nick.barker9@btinternet.com>
3  *
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of
8  * the License, or (at your option) any later version.
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., 59 Temple Place, Suite 330, Boston,
18  * MA 02111-1307 USA
19  */
20
21  /* vt1211 routines and defines*/
22
23
24 #include <arch/io.h>
25 #include <device/device.h>
26 #include <device/pci.h>
27 #include <device/pci_ops.h>
28 #include <device/pci_ids.h>
29 #include <console/console.h>
30 #include "vt1211.h"
31 #include "chip.h"
32
33
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};
49
50 static void start_conf_pnp(int dev)
51 {
52         outb(0x87,0x2e);
53         outb(0x87,0x2e);
54         outb(7,0x2e);
55         outb(dev,0x2f);
56 }
57 static void write_pnp(int reg, int val)
58 {
59         outb(reg,0x2e);
60         outb(val,0x2f);
61 }
62 static void end_conf_pnp()
63 {
64         outb(0xaa,0x2e);
65 }
66
67 static void vt1211_init(struct superio_via_vt1211_config *conf)
68 {
69
70         int i;
71         // Activate the vt1211 hardware monitor
72         if(conf->enable_hwmon){
73                 start_conf_pnp(0x0b);
74                 write_pnp(0x60,0xec); 
75                 write_pnp(0x30,1);
76                 end_conf_pnp();
77
78                 // initialize vt1211 hardware monitor registers, which are at 0xECXX
79                 for(i=0;i<sizeof(vt1211hwmonitorinits);i+=2)
80                         outb(vt1211hwmonitorinits[i+1],0xec00+vt1211hwmonitorinits[i]);
81         }
82         if( conf->enable_fdc){
83                 // activate FDC
84                 start_conf_pnp(0); // fdc is device 0
85                 write_pnp(0x60,0xfc); // io address
86                 write_pnp(0x70,0x06); // interupt
87                 write_pnp(0x74,0x02); // dma
88                 write_pnp(0x30,0x01); // activate it
89                 end_conf_pnp();
90         }       
91
92         if( conf->enable_com_ports ){
93                 // activate com2
94                 start_conf_pnp(3);
95                 write_pnp(0x60,0xbe);
96                 write_pnp(0x70,0x3);
97                 write_pnp(0xf0,0x02);
98                 write_pnp(0x30,0x01);
99                 end_conf_pnp();
100         }
101
102         if( conf->enable_lpt ){
103                 // activate lpt
104                 start_conf_pnp(1);
105                 write_pnp(0x60,0xde);
106                 write_pnp(0x70,0x07);
107                 write_pnp(0x74,0x3);
108                 write_pnp(0x30,0x01);
109                 end_conf_pnp();
110         }
111
112 }
113
114 static void superio_init(struct chip *chip, enum chip_pass pass)
115 {
116
117         struct superio_via_vt1211_config *conf = 
118                 (struct superio_via_vt1211_config *)chip->chip_info;
119
120         switch (pass) {
121         case CONF_PASS_PRE_PCI:
122                 break;
123                 
124         case CONF_PASS_POST_PCI:
125                 vt1211_init(conf);
126                 break;
127
128         case CONF_PASS_PRE_BOOT:
129                 break;
130                 
131         default:
132                 /* nothing yet */
133                 break;
134         }
135 }
136
137 static void enumerate(struct chip *chip)
138 {
139         extern struct device_operations default_pci_ops_bus;
140         chip_enumerate(chip);
141         chip->dev->ops = &default_pci_ops_bus;
142 }
143
144 struct chip_control superio_via_vt1211_control = {
145         .enumerate = enumerate,
146         .enable    = superio_init,
147         .name      = "VIA vt1211"
148 };