d80e2ed59bbc2335e9e0f50ee809d4d090bde962
[coreboot.git] / src / superio / ite / it8705f / it8705f_early_serial.c
1 /*
2  * Copyright (C) 2006 Uwe Hermann <uwe@hermann-uwe.de>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
17  */
18
19 #include <arch/romcc_io.h>
20 #include "it8705f.h"
21
22 /* The base address is 0x2e or 0x4e, depending on config bytes. */
23 #define SIO_BASE                     0x2e
24 #define SIO_INDEX                    SIO_BASE
25 #define SIO_DATA                     SIO_BASE+1
26
27 /* Global Configuration Registers. */
28 #define IT8705F_CONFIG_REG_CC        0x02 /* Configure Control (write-only). */
29 #define IT8705F_CONFIG_REG_LDN       0x07 /* Logical Device Number. */
30 #define IT8705F_CONFIG_REG_CONFIGSEL 0x22 /* Configuration Select. */
31
32 /* WTF? 0x23 and 0x24 are swapped here (when compared to other IT87xx). */
33 #define IT8705F_CONFIG_REG_CLOCKSEL  0x24 /* Clock Selection. */
34 #define IT8705F_CONFIG_REG_SWSUSP    0x23 /* Software Suspend, Flash I/F. */
35
36 #define IT8705F_CONFIGURATION_PORT   0x2e /* Write-only. */
37
38 /* The content of IT8705F_CONFIG_REG_LDN (index 0x07) must be set to the
39  * LDN the register belongs to, before you can access the register. */
40 static void it8705f_sio_write(uint8_t ldn, uint8_t index, uint8_t value)
41 {
42         outb(IT8705F_CONFIG_REG_LDN, SIO_BASE);
43         outb(ldn, SIO_DATA);
44         outb(index, SIO_BASE);
45         outb(value, SIO_DATA);
46 }
47
48 /* Enable the peripheral devices on the IT8705F Super IO chip. */
49 static void it8705f_enable_serial(device_t dev, unsigned iobase)
50 {
51         /* (1) Enter the configuration state (MB PnP mode). */
52
53         /* Perform MB PnP setup to put the SIO chip at 0x2e. */
54         /* Base address 0x2e: 0x87 0x01 0x55 0x55. */
55         /* Base address 0x4e: 0x87 0x01 0x55 0xaa. */
56         outb(0x87, IT8705F_CONFIGURATION_PORT);
57         outb(0x01, IT8705F_CONFIGURATION_PORT);
58         outb(0x55, IT8705F_CONFIGURATION_PORT);
59         outb(0x55, IT8705F_CONFIGURATION_PORT);
60
61         /* (2) Modify the data of configuration registers. */
62
63         /* Select the chip to configure (if there's more than one).
64          * Set bit 7 to select JP3=1, clear bit 7 to select JP3=0.
65          * If this register is not written, both chips are configured. */
66         /* it8705f_sio_write(0x00, IT8705F_CONFIG_REG_CONFIGSEL, 0x00); */
67
68         /* Enable all devices. */
69         it8705f_sio_write(IT8705F_FDC,  0x30, 0x1); /* Floppy */
70         it8705f_sio_write(IT8705F_SP1,  0x30, 0x1); /* Serial port 1 */
71         it8705f_sio_write(IT8705F_SP2,  0x30, 0x1); /* Serial port 2 */
72         it8705f_sio_write(IT8705F_PP,   0x30, 0x1); /* Parallel port */
73         it8705f_sio_write(IT8705F_EC,   0x30, 0x1); /* Environment controller */
74         /* GPIO */
75         it8705f_sio_write(IT8705F_GAME, 0x30, 0x1); /* GAME port */
76         it8705f_sio_write(IT8705F_IR,   0x30, 0x1); /* Consumer IR */
77         it8705f_sio_write(IT8705F_MIDI, 0x30, 0x1); /* MIDI port */
78
79         /* Select 24MHz/48MHz CLKIN (set/clear bit 0). TODO: Needed? */
80         /* it8705f_sio_write(0x00, IT8705F_CONFIG_REG_CLOCKSEL, 0x00); */
81
82         /* Clear software suspend mode (clear bit 0). TODO: Needed? */
83         /* it8705f_sio_write(0x00, IT8705F_CONFIG_REG_SWSUSP, 0x00); */
84
85         /* (3) Exit the configuration state (MB PnP mode). */
86         it8705f_sio_write(0x00, IT8705F_CONFIG_REG_CC, 0x02); 
87 }
88