C and other Super I/O cosmetic fixes.
[coreboot.git] / src / superio / smsc / lpc47n227 / lpc47n227_early_serial.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2005 Digital Design Corporation
5  * Copyright (C) 2008-2009 coresystems GmbH
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; version 2 of the License.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19  */
20
21 /* Pre-RAM driver for SMSC LPC47N227 Super I/O chip. */
22
23 #include <arch/romcc_io.h>
24 #include "lpc47n227.h"
25
26 static void pnp_enter_conf_state(device_t dev)
27 {
28         u16 port = dev >> 8;
29         outb(0x55, port);
30 }
31
32 static void pnp_exit_conf_state(device_t dev)
33 {
34         u16 port = dev >> 8;
35         outb(0xaa, port);
36 }
37
38 /**
39  * Program the base I/O port for the specified logical device.
40  *
41  * @param dev High 8 bits = Super I/O port, low 8 bits = logical device number.
42  * @param iobase Base I/O port for the logical device.
43  */
44 void lpc47n227_pnp_set_iobase(device_t dev, u16 iobase)
45 {
46         /* LPC47N227 requires base ports to be a multiple of 4. */
47         ASSERT(!(iobase & 0x3));
48
49         switch (dev & 0xFF) {
50         case LPC47N227_PP:
51                 pnp_write_config(dev, 0x23, (iobase >> 2) & 0xff);
52                 break;
53         case LPC47N227_SP1:
54                 pnp_write_config(dev, 0x24, (iobase >> 2) & 0xff);
55                 break;
56         case LPC47N227_SP2:
57                 pnp_write_config(dev, 0x25, (iobase >> 2) & 0xff);
58                 break;
59         default:
60                 break;
61         }
62 }
63
64 /**
65  * Enable or disable the specified logical device.
66  *
67  * Technically, a full disable requires setting the device's base I/O port
68  * below 0x100. We don't do that here, because we don't have access to a data
69  * structure that specifies what the 'real' base port is (when asked to enable
70  * the device). Also the function is used only to disable the device while its
71  * true base port is programmed (see lpc47n227_enable_serial() below).
72  *
73  * @param dev High 8 bits = Super I/O port, low 8 bits = logical device number.
74  * @param enable 0 to disable, anythig else to enable.
75  */
76 void lpc47n227_pnp_set_enable(device_t dev, int enable)
77 {
78         u8 power_register = 0, power_mask = 0, current_power, new_power;
79
80         switch (dev & 0xFF) {
81         case LPC47N227_PP:
82                 power_register = 0x01;
83                 power_mask = 0x04;
84                 break;
85         case LPC47N227_SP1:
86                 power_register = 0x02;
87                 power_mask = 0x08;
88                 break;
89         case LPC47N227_SP2:
90                 power_register = 0x02;
91                 power_mask = 0x80;
92                 break;
93         default:
94                 return;
95         }
96
97         current_power = pnp_read_config(dev, power_register);
98         new_power = current_power & ~power_mask; /* Disable by default. */
99         if (enable)
100                 new_power |= power_mask; /* Enable. */
101         pnp_write_config(dev, power_register, new_power);
102 }
103
104 /**
105  * Configure the base I/O port of the specified serial device and enable the
106  * serial device.
107  *
108  * @param dev High 8 bits = Super I/O port, low 8 bits = logical device number.
109  * @param iobase Processor I/O port address to assign to this serial device.
110  */
111 static void lpc47n227_enable_serial(device_t dev, u16 iobase)
112 {
113         /*
114          * NOTE: Cannot use pnp_set_XXX() here because they assume chip
115          * support for logical devices, which the LPC47N227 doesn't have.
116          */
117         pnp_enter_conf_state(dev);
118         lpc47n227_pnp_set_enable(dev, 0);
119         lpc47n227_pnp_set_iobase(dev, iobase);
120         lpc47n227_pnp_set_enable(dev, 1);
121         pnp_exit_conf_state(dev);
122 }