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