2 * superio.c: RAM-based driver for SMSC LPC47N217 Super I/O chip
4 * Based on LinuxBIOS code for SMSC 47B397:
5 * Copyright 2000 AG Electronics Ltd.
6 * Copyright 2003-2004 Linux Networx
9 * Copyright (C) 2005 Digital Design Corporation
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 #include <device/device.h>
28 #include <device/pnp.h>
29 #include <console/console.h>
30 #include <device/smbus.h>
36 #include "lpc47n217.h"
38 // Forward declarations
39 static void enable_dev(device_t dev);
40 void lpc47n217_pnp_set_resources(device_t dev);
41 void lpc47n217_pnp_enable_resources(device_t dev);
42 void lpc47n217_pnp_enable(device_t dev);
43 static void lpc47n217_init(device_t dev);
45 static void lpc47n217_pnp_set_resource(device_t dev, struct resource *resource);
46 void lpc47n217_pnp_set_iobase(device_t dev, unsigned iobase);
47 void lpc47n217_pnp_set_drq(device_t dev, unsigned drq);
48 void lpc47n217_pnp_set_irq(device_t dev, unsigned irq);
49 void lpc47n217_pnp_set_enable(device_t dev, int enable);
51 static void pnp_enter_conf_state(device_t dev);
52 static void pnp_exit_conf_state(device_t dev);
55 struct chip_operations superio_smsc_lpc47n217_ops = {
56 CHIP_NAME("SMSC LPC47N217 Super I/O")
57 .enable_dev = enable_dev,
60 static struct device_operations ops = {
61 .read_resources = pnp_read_resources,
62 .set_resources = lpc47n217_pnp_set_resources,
63 .enable_resources = lpc47n217_pnp_enable_resources,
64 .enable = lpc47n217_pnp_enable,
65 .init = lpc47n217_init,
68 static struct pnp_info pnp_dev_info[] = {
69 { &ops, LPC47N217_PP, PNP_IO0 | PNP_IRQ0 | PNP_DRQ0, { 0x07f8, 0}, },
70 { &ops, LPC47N217_SP1, PNP_IO0 | PNP_IRQ0, { 0x7f8, 0 }, },
71 { &ops, LPC47N217_SP2, PNP_IO0 | PNP_IRQ0, { 0x7f8, 0 }, }
74 /**********************************************************************************/
75 /* PUBLIC INTERFACE */
76 /**********************************************************************************/
78 //----------------------------------------------------------------------------------
79 // Function: enable_dev
80 // Parameters: dev - pointer to structure describing a Super I/O device
82 // Description: Create device structures and allocate resources to devices
83 // specified in the pnp_dev_info array (above).
85 static void enable_dev(device_t dev)
87 pnp_enable_devices(dev, &pnp_ops,
88 sizeof(pnp_dev_info)/sizeof(pnp_dev_info[0]),
92 //----------------------------------------------------------------------------------
93 // Function: lpc47n217_pnp_set_resources
94 // Parameters: dev - pointer to structure describing a Super I/O device
96 // Description: Configure the specified Super I/O device with the resources
97 // (I/O space, etc.) that have been allocate for it.
99 void lpc47n217_pnp_set_resources(device_t dev)
103 pnp_enter_conf_state(dev);
105 // NOTE: Cannot use pnp_set_resources() here because it assumes chip
106 // support for logical devices, which the LPC47N217 doesn't have
107 for(i = 0; i < dev->resources; i++)
108 lpc47n217_pnp_set_resource(dev, &dev->resource[i]);
110 // dump_pnp_device(dev);
112 pnp_exit_conf_state(dev);
115 void lpc47n217_pnp_enable_resources(device_t dev)
117 pnp_enter_conf_state(dev);
119 // NOTE: Cannot use pnp_enable_resources() here because it assumes chip
120 // support for logical devices, which the LPC47N217 doesn't have
121 lpc47n217_pnp_set_enable(dev, 1);
123 pnp_exit_conf_state(dev);
126 void lpc47n217_pnp_enable(device_t dev)
128 pnp_enter_conf_state(dev);
130 // NOTE: Cannot use pnp_set_enable() here because it assumes chip
131 // support for logical devices, which the LPC47N217 doesn't have
134 lpc47n217_pnp_set_enable(dev, 1);
137 lpc47n217_pnp_set_enable(dev, 0);
140 pnp_exit_conf_state(dev);
143 //----------------------------------------------------------------------------------
144 // Function: lpc47n217_init
145 // Parameters: dev - pointer to structure describing a Super I/O device
146 // Return Value: None
147 // Description: Initialize the specified Super I/O device.
148 // Devices other than COM ports are ignored.
149 // For COM ports, we configure the baud rate.
151 static void lpc47n217_init(device_t dev)
153 struct superio_smsc_lpc47n217_config* conf = dev->chip_info;
154 struct resource *res0;
159 switch(dev->path.u.pnp.device) {
161 res0 = find_resource(dev, PNP_IDX_IO0);
162 init_uart8250(res0->base, &conf->com1);
166 res0 = find_resource(dev, PNP_IDX_IO0);
167 init_uart8250(res0->base, &conf->com2);
173 /**********************************************************************************/
174 /* PRIVATE FUNCTIONS */
175 /**********************************************************************************/
177 static void lpc47n217_pnp_set_resource(device_t dev, struct resource *resource)
179 if (!(resource->flags & IORESOURCE_ASSIGNED)) {
180 printk_err("ERROR: %s %02x not allocated\n",
181 dev_path(dev), resource->index);
185 /* Now store the resource */
186 // NOTE: Cannot use pnp_set_XXX() here because they assume chip
187 // support for logical devices, which the LPC47N217 doesn't have
189 if (resource->flags & IORESOURCE_IO) {
190 lpc47n217_pnp_set_iobase(dev, resource->base);
192 else if (resource->flags & IORESOURCE_DRQ) {
193 lpc47n217_pnp_set_drq(dev, resource->base);
195 else if (resource->flags & IORESOURCE_IRQ) {
196 lpc47n217_pnp_set_irq(dev, resource->base);
199 printk_err("ERROR: %s %02x unknown resource type\n",
200 dev_path(dev), resource->index);
203 resource->flags |= IORESOURCE_STORED;
205 report_resource_stored(dev, resource, "");
208 void lpc47n217_pnp_set_iobase(device_t dev, unsigned iobase)
210 ASSERT(!(iobase & 0x3));
212 switch(dev->path.u.pnp.device) {
214 pnp_write_config(dev, 0x23, (iobase >> 2) & 0xff);
218 pnp_write_config(dev, 0x24, (iobase >> 2) & 0xff);
222 pnp_write_config(dev, 0x25, (iobase >> 2) & 0xff);
231 void lpc47n217_pnp_set_drq(device_t dev, unsigned drq)
233 if (dev->path.u.pnp.device == LPC47N217_PP) {
234 const uint8_t PP_DMA_MASK = 0x0F;
235 const uint8_t PP_DMA_SELECTION_REGISTER = 0x26;
236 uint8_t current_config = pnp_read_config(dev, PP_DMA_SELECTION_REGISTER);
239 ASSERT(!(drq & ~PP_DMA_MASK)); // DRQ out of range??
240 new_config = (current_config & ~PP_DMA_MASK) | drq;
241 pnp_write_config(dev, PP_DMA_SELECTION_REGISTER, new_config);
247 void lpc47n217_pnp_set_irq(device_t dev, unsigned irq)
249 uint8_t irq_config_register = 0;
250 uint8_t irq_config_mask = 0;
251 uint8_t current_config;
254 switch(dev->path.u.pnp.device) {
256 irq_config_register = 0x27;
257 irq_config_mask = 0x0F;
261 irq_config_register = 0x28;
262 irq_config_mask = 0xF0;
267 irq_config_register = 0x28;
268 irq_config_mask = 0x0F;
276 ASSERT(!(irq & ~irq_config_mask)); // IRQ out of range??
278 current_config = pnp_read_config(dev, irq_config_register);
279 new_config = (current_config & ~irq_config_mask) | irq;
280 pnp_write_config(dev, irq_config_register, new_config);
283 void lpc47n217_pnp_set_enable(device_t dev, int enable)
285 uint8_t power_register = 0;
286 uint8_t power_mask = 0;
287 uint8_t current_power;
290 switch(dev->path.u.pnp.device) {
292 power_register = 0x01;
297 power_register = 0x02;
302 power_register = 0x02;
311 current_power = pnp_read_config(dev, power_register);
312 new_power = current_power & ~power_mask; // disable by default
315 struct resource* ioport_resource = find_resource(dev, PNP_IDX_IO0);
316 lpc47n217_pnp_set_iobase(dev, ioport_resource->base);
318 new_power |= power_mask; // Enable
321 lpc47n217_pnp_set_iobase(dev, 0);
323 pnp_write_config(dev, power_register, new_power);
327 //----------------------------------------------------------------------------------
328 // Function: pnp_enter_conf_state
329 // Parameters: dev - pointer to structure describing a Super I/O device
330 // Return Value: None
331 // Description: Enable access to the LPC47N217's configuration registers.
333 static void pnp_enter_conf_state(device_t dev)
335 outb(0x55, dev->path.u.pnp.port);
338 //----------------------------------------------------------------------------------
339 // Function: pnp_exit_conf_state
340 // Parameters: dev - pointer to structure describing a Super I/O device
341 // Return Value: None
342 // Description: Disable access to the LPC47N217's configuration registers.
344 static void pnp_exit_conf_state(device_t dev)
346 outb(0xaa, dev->path.u.pnp.port);
350 //----------------------------------------------------------------------------------
351 // Function: dump_pnp_device
352 // Parameters: dev - pointer to structure describing a Super I/O device
353 // Return Value: None
354 // Description: Print the values of all of the LPC47N217's configuration registers.
355 // NOTE: The LPC47N217 must be in configuration mode when this
356 // function is called.
358 static void dump_pnp_device(device_t dev)
363 for(register_index = 0; register_index <= LPC47N217_MAX_CONFIG_REGISTER; register_index++) {
364 uint8_t register_value;
366 if ((register_index & 0x0f) == 0) {
367 print_debug_hex8(register_index);
368 print_debug_char(':');
371 // Skip over 'register' that would cause exit from configuration mode
372 if (register_index == 0xaa)
373 register_value = 0xaa;
375 register_value = pnp_read_config(dev, register_index);
377 print_debug_char(' ');
378 print_debug_hex8(register_value);
379 if ((register_index & 0x0f) == 0x0f) {