add smsc part. Mod sun board to use smsc part for now
[coreboot.git] / src / superio / smsc / lpc47m10x / superio.c
1 /*
2  * $Header$
3  *
4  * superio.c: RAM driver for SMSC LPC47M10X2 Super I/O chip
5  *
6  * Copyright 2000  AG Electronics Ltd.
7  * Copyright 2003-2004 Linux Networx
8  * Copyright 2004 Tyan 
9  * Copyright (C) 2005 Digital Design Corporation
10  * Copyright (C) Ron Minnich, LANL
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
25  *
26  * $Log$
27  *
28  */
29
30 #include <arch/io.h>
31 #include <device/device.h>
32 #include <device/pnp.h>
33 #include <console/console.h>
34 #include <device/smbus.h>
35 #include <string.h>
36 #include <bitops.h>
37 #include <uart8250.h>
38 #include <pc80/keyboard.h>
39 #include "chip.h"
40 #include "lpc47m10x.h"
41
42 // Forward declarations
43 static void enable_dev(device_t dev);
44 void lpc47m10x_pnp_set_resources(device_t dev);
45 void lpc47m10x_pnp_set_resources(device_t dev);
46 void lpc47m10x_pnp_enable_resources(device_t dev);
47 void lpc47m10x_pnp_enable(device_t dev);
48 static void lpc47m10x_init(device_t dev);
49
50 static void pnp_enter_conf_state(device_t dev);
51 static void pnp_exit_conf_state(device_t dev);
52 static void dump_pnp_device(device_t dev);
53
54
55 struct chip_operations superio_smsc_lpc47m10x_ops = {
56         CHIP_NAME("smsc lpc47m10x")
57         .enable_dev = enable_dev
58 };
59
60 static struct device_operations ops = {
61         .read_resources   = pnp_read_resources,
62         .set_resources    = lpc47m10x_pnp_set_resources,
63         .enable_resources = lpc47m10x_pnp_enable_resources,
64         .enable           = lpc47m10x_pnp_enable,
65         .init             = lpc47m10x_init,
66 };
67
68 static struct pnp_info pnp_dev_info[] = {
69         { &ops, LPC47M10X2_FDC,  PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, { 0x07f8, 0}, },
70         { &ops, LPC47M10X2_PP,   PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, { 0x07f8, 0}, },
71         { &ops, LPC47M10X2_SP1,  PNP_IO0 | PNP_IRQ0, { 0x7f8, 0 }, },
72         { &ops, LPC47M10X2_SP2,  PNP_IO0 | PNP_IRQ0, { 0x7f8, 0 }, },
73         { &ops, LPC47M10X2_KBC,  PNP_IO0 | PNP_IO1 | PNP_IRQ0 | PNP_IRQ1, { 0x7ff, 0 }, { 0x7ff, 0x4}, },
74         { &ops, LPC47M10X2_RT,   PNP_IO0, { 0x780, 0 }, },
75 };
76
77 /**********************************************************************************/
78 /*                                                              PUBLIC INTERFACE                                                                  */
79 /**********************************************************************************/
80
81 //----------------------------------------------------------------------------------
82 // Function:            enable_dev
83 // Parameters:          dev - pointer to structure describing a Super I/O device 
84 // Return Value:        None
85 // Description:         Create device structures and allocate resources to devices 
86 //                                      specified in the pnp_dev_info array (above).
87 //
88 static void enable_dev(device_t dev)
89 {
90         pnp_enable_devices(dev, &pnp_ops, 
91                                            sizeof(pnp_dev_info)/sizeof(pnp_dev_info[0]), 
92                                            pnp_dev_info);
93 }
94
95 //----------------------------------------------------------------------------------
96 // Function:            lpc47m10x_pnp_set_resources
97 // Parameters:          dev - pointer to structure describing a Super I/O device 
98 // Return Value:        None
99 // Description:         Configure the specified Super I/O device with the resources
100 //                                      (I/O space, etc.) that have been allocated for it.
101 //
102 void lpc47m10x_pnp_set_resources(device_t dev)
103 {
104         pnp_enter_conf_state(dev);  
105         pnp_set_resources(dev);
106     pnp_exit_conf_state(dev);  
107 }       
108
109 void lpc47m10x_pnp_enable_resources(device_t dev)
110 {       
111         pnp_enter_conf_state(dev);
112     pnp_enable_resources(dev);
113     pnp_exit_conf_state(dev);
114 }
115
116 void lpc47m10x_pnp_enable(device_t dev)
117 {
118         pnp_enter_conf_state(dev);   
119         pnp_set_logical_device(dev);
120
121         if(dev->enabled) {
122                 pnp_set_enable(dev, 1);
123         }
124         else {
125                 pnp_set_enable(dev, 0);
126         }
127         pnp_exit_conf_state(dev);  
128 }
129
130 //----------------------------------------------------------------------------------
131 // Function:            lpc47m10x_init
132 // Parameters:          dev - pointer to structure describing a Super I/O device 
133 // Return Value:        None
134 // Description:         Initialize the specified Super I/O device.
135 //                                      Devices other than COM ports and the keyboard controller are 
136 //                                      ignored. For COM ports, we configure the baud rate. 
137 //
138 static void lpc47m10x_init(device_t dev)
139 {
140         struct superio_smsc_lpc47m10x_config *conf = dev->chip_info;
141         struct resource *res0, *res1;
142
143         if (!dev->enabled)
144                 return;
145         
146         switch(dev->path.u.pnp.device) {
147         case LPC47M10X2_SP1: 
148                 res0 = find_resource(dev, PNP_IDX_IO0);
149                 init_uart8250(res0->base, &conf->com1);
150                 break;
151                 
152         case LPC47M10X2_SP2:
153                 res0 = find_resource(dev, PNP_IDX_IO0);
154                 init_uart8250(res0->base, &conf->com2);
155                 break;
156                 
157         case LPC47M10X2_KBC:
158                 res0 = find_resource(dev, PNP_IDX_IO0);
159                 res1 = find_resource(dev, PNP_IDX_IO1);
160                 init_pc_keyboard(res0->base, res1->base, &conf->keyboard);
161                 break;
162         }
163 }
164
165 /**********************************************************************************/
166 /*                                                              PRIVATE FUNCTIONS                                                             */
167 /**********************************************************************************/
168
169 //----------------------------------------------------------------------------------
170 // Function:            pnp_enter_conf_state
171 // Parameters:          dev - pointer to structure describing a Super I/O device 
172 // Return Value:        None
173 // Description:         Enable access to the LPC47M10X2's configuration registers.
174 //
175 static void pnp_enter_conf_state(device_t dev) 
176 {
177         outb(0x55, dev->path.u.pnp.port);
178 }
179
180 //----------------------------------------------------------------------------------
181 // Function:            pnp_exit_conf_state
182 // Parameters:          dev - pointer to structure describing a Super I/O device 
183 // Return Value:        None
184 // Description:         Disable access to the LPC47M10X2's configuration registers.
185 //
186 static void pnp_exit_conf_state(device_t dev) 
187 {
188     outb(0xaa, dev->path.u.pnp.port);
189 }
190
191 #if 0
192 //----------------------------------------------------------------------------------
193 // Function:            dump_pnp_device
194 // Parameters:          dev - pointer to structure describing a Super I/O device 
195 // Return Value:        None
196 // Description:         Print the values of all of the LPC47M10X2's configuration registers.
197 //                                      NOTE: The LPC47M10X2 must be in configuration mode when this
198 //                                                function is called.
199 //
200 static void dump_pnp_device(device_t dev)
201 {
202     int register_index;
203     print_debug("\r\n");
204
205     for(register_index = 0; register_index <= LPC47M10X2_MAX_CONFIG_REGISTER; register_index++) {
206         uint8_t register_value;
207
208         if ((register_index & 0x0f) == 0) {
209                 print_debug_hex8(register_index);
210                 print_debug_char(':');
211         }
212
213                 // Skip over 'register' that would cause exit from configuration mode
214             if (register_index == 0xaa)
215                         register_value = 0xaa;
216                 else
217                 register_value = pnp_read_config(dev, register_index);
218
219         print_debug_char(' ');
220         print_debug_hex8(register_value);
221         if ((register_index & 0x0f) == 0x0f) {
222                 print_debug("\r\n");
223         }
224     }
225
226         print_debug("\r\n");
227 }
228 #endif