blob: b01151061c84e6e493abbe5c6f1d37b39a770465 [file] [log] [blame]
Kerry Sheh3c71a852012-02-07 20:31:40 +08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2012 Advanced Micro Devices, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Kerry Sheh3c71a852012-02-07 20:31:40 +080014 */
15
16/* Pre-RAM driver for the SMSC KBC1100 Super I/O chip */
17
Stefan Reinauer24d1d4b2013-03-21 11:51:41 -070018#include <arch/io.h>
Edward O'Callaghan47b80752014-08-02 20:08:35 +100019#include <stdint.h>
20
Kerry Sheh3c71a852012-02-07 20:31:40 +080021#include "sio1036.h"
22
Edward O'Callaghan85836c22014-07-09 20:26:25 +100023static inline void sio1036_enter_conf_state(pnp_devfn_t dev)
Kerry Sheh3c71a852012-02-07 20:31:40 +080024{
Edward O'Callaghan47b80752014-08-02 20:08:35 +100025 unsigned port = dev >> 8;
Kerry Sheh3c71a852012-02-07 20:31:40 +080026 outb(0x55, port);
27}
28
Edward O'Callaghan85836c22014-07-09 20:26:25 +100029static inline void sio1036_exit_conf_state(pnp_devfn_t dev)
Kerry Sheh3c71a852012-02-07 20:31:40 +080030{
Edward O'Callaghan47b80752014-08-02 20:08:35 +100031 unsigned port = dev >> 8;
Kerry Sheh3c71a852012-02-07 20:31:40 +080032 outb(0xaa, port);
33}
34
Edward O'Callaghan47b80752014-08-02 20:08:35 +100035/* Detect SMSC SIO1036 LPC Debug Card status */
Kerry Sheh3c71a852012-02-07 20:31:40 +080036static u8 detect_sio1036_chip(unsigned port)
37{
Edward O'Callaghan85836c22014-07-09 20:26:25 +100038 pnp_devfn_t dev = PNP_DEV(port, SIO1036_SP1);
Kerry Sheh3c71a852012-02-07 20:31:40 +080039 unsigned data;
Edward O'Callaghan47b80752014-08-02 20:08:35 +100040
Kerry Sheh3c71a852012-02-07 20:31:40 +080041 sio1036_enter_conf_state (dev);
42 data = pnp_read_config (dev, 0x0D);
43 sio1036_exit_conf_state(dev);
Edward O'Callaghan47b80752014-08-02 20:08:35 +100044
45 /* Detect SMSC SIO1036 chip */
Kerry Sheh3c71a852012-02-07 20:31:40 +080046 if (data == 0x82) {
47 /* Found SMSC SIO1036 chip */
48 return 0;
49 }
50 else {
Edward O'Callaghan47b80752014-08-02 20:08:35 +100051 return 1;
Kerry Sheh3c71a852012-02-07 20:31:40 +080052 };
53}
54
Edward O'Callaghan85836c22014-07-09 20:26:25 +100055void sio1036_enable_serial(pnp_devfn_t dev, u16 iobase)
Kerry Sheh3c71a852012-02-07 20:31:40 +080056{
Edward O'Callaghan47b80752014-08-02 20:08:35 +100057 unsigned port = dev >> 8;
Kerry Sheh3c71a852012-02-07 20:31:40 +080058
Edward O'Callaghan47b80752014-08-02 20:08:35 +100059 if (detect_sio1036_chip(port) != 0)
Kerry Sheh3c71a852012-02-07 20:31:40 +080060 return;
Edward O'Callaghan47b80752014-08-02 20:08:35 +100061
Kerry Sheh3c71a852012-02-07 20:31:40 +080062 sio1036_enter_conf_state (dev);
63
64 /* Enable SMSC UART 0 */
65 /* Valid configuration cycle */
66 pnp_write_config (dev, 0x00, 0x28);
67
68 /* PP power/mode/cr lock */
69 pnp_write_config (dev, 0x01, 0x98 | LPT_POWER_DOWN);
70 pnp_write_config (dev, 0x02, 0x08 | UART_POWER_DOWN);
71
72 /*Auto power management*/
73 pnp_write_config (dev, 0x07, 0x00 );
74
75 /*ECP FIFO threhod */
76 pnp_write_config (dev, 0x0A, 0x00 | IR_OUPUT_MUX);
77
78 /*GPIO direction register 2 */
79 pnp_write_config (dev, 0x033, 0x00);
80
81 /*UART Mode */
82 pnp_write_config (dev, 0x0C, 0x02);
83
84 /* GPIO polarity regisgter 2 */
85 pnp_write_config (dev, 0x034, 0x00);
86
87 /* Enable SMSC UART 0 */
88 /*Set base io address */
Edward O'Callaghan47b80752014-08-02 20:08:35 +100089 pnp_write_config (dev, 0x25, (u8)(iobase >> 2));
Kerry Sheh3c71a852012-02-07 20:31:40 +080090
91 /* Set UART IRQ onto 0x04 */
92 pnp_write_config (dev, 0x28, 0x04);
93
94 sio1036_exit_conf_state(dev);
95}