blob: d1958a0431346397102f653401e70d452fa78195 [file] [log] [blame]
Felix Heldda09d022014-06-01 21:44:43 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 Advanced Micro Devices, Inc.
5 * Copyright (C) 2014 Edward O'Callaghan <eocallaghan@alterapraxis.com>
6 * Copyright (C) 2014 Felix Held <felix-coreboot@felixheld.de>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
Felix Heldda09d022014-06-01 21:44:43 +020017 */
18
19/*
20 * A generic romstage (pre-ram) driver for Nuvoton variant Super I/O chips.
21 *
22 * The following is derived directly from the vendor Nuvoton's data-sheets:
23 *
24 * To toggle between `configuration mode` and `normal operation mode` as to
25 * manipulate the various LDN's in Nuvoton Super I/O's we are required to
26 * pass magic numbers `passwords keys`.
27 *
28 * NUVOTON_ENTRY_KEY := enable configuration : 0x87
29 * NUVOTON_EXIT_KEY := disable configuration : 0xAA
30 *
31 * To modify a LDN's configuration register, we use the index port to select
32 * the index of the LDN and then write to the data port to alter the
33 * parameters. A default index, data port pair is 0x4E, 0x4F respectively, a
34 * user modified pair is 0x2E, 0x2F respectively.
35 *
36 */
37
38#include <arch/io.h>
39#include <device/pnp.h>
40#include <stdint.h>
41#include "nuvoton.h"
42
43#define NUVOTON_ENTRY_KEY 0x87
44#define NUVOTON_EXIT_KEY 0xAA
45
46/* Enable configuration: pass entry key '0x87' into index port dev
47 * two times. */
Edward O'Callaghan85836c22014-07-09 20:26:25 +100048static void pnp_enter_conf_state(pnp_devfn_t dev)
Felix Heldda09d022014-06-01 21:44:43 +020049{
50 u16 port = dev >> 8;
51 outb(NUVOTON_ENTRY_KEY, port);
52 outb(NUVOTON_ENTRY_KEY, port);
53}
54
55/* Disable configuration: pass exit key '0xAA' into index port dev. */
Edward O'Callaghan85836c22014-07-09 20:26:25 +100056static void pnp_exit_conf_state(pnp_devfn_t dev)
Felix Heldda09d022014-06-01 21:44:43 +020057{
58 u16 port = dev >> 8;
59 outb(NUVOTON_EXIT_KEY, port);
60}
61
62/* Bring up early serial debugging output before the RAM is initialized. */
Edward O'Callaghan85836c22014-07-09 20:26:25 +100063void nuvoton_enable_serial(pnp_devfn_t dev, u16 iobase)
Felix Heldda09d022014-06-01 21:44:43 +020064{
65 pnp_enter_conf_state(dev);
Teo Boon Tiongf95daa52016-09-05 16:00:07 +080066 if (IS_ENABLED(CONFIG_SUPERIO_NUVOTON_NCT6776_COM_A))
67 /* Route GPIO8 pin group to COM A */
68 pnp_write_config(dev, 0x2a, 0x40);
Felix Heldda09d022014-06-01 21:44:43 +020069 pnp_set_logical_device(dev);
70 pnp_set_enable(dev, 0);
71 pnp_set_iobase(dev, PNP_IDX_IO0, iobase);
72 pnp_set_enable(dev, 1);
73 pnp_exit_conf_state(dev);
74}