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