blob: 7bd1707f953aa7b3e2d2553fbab9bb280b2294ee [file] [log] [blame]
Edward O'Callaghan5a032c62014-04-27 22:41:31 +10001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2014 Edward O'Callaghan <eocallaghan@alterapraxis.com>
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; either version 2 of the License, or
9 * (at your option) any later version.
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.
Edward O'Callaghan5a032c62014-04-27 22:41:31 +100015 */
16
17/*
18 * A generic romstage (pre-ram) driver for Winbond variant Super I/O chips.
19 *
20 * The following is derived directly from the vendor Winbond's data-sheets:
21 *
22 * To toggle between `configuration mode` and `normal operation mode` as to
23 * manipulation the various LDN's in Winbond Super I/O's we are required to
24 * pass magic numbers `passwords keys`.
25 *
26 * WINBOUND_ENTRY_KEY := enable configuration : 0x87
27 * WINBOUND_EXIT_KEY := disable configuration : 0xAA
28 *
29 * To modify a LDN's configuration register, we use the index port to select
30 * the index of the LDN and then write to the data port to alter the
31 * parameters. A default index, data port pair is 0x4E, 0x4F respectively, a
32 * user modified pair is 0x2E, 0x2F respectively.
33 *
34 */
35
36#include <arch/io.h>
37#include <device/pnp.h>
38#include <stdint.h>
39#include "winbond.h"
40
41#define WINBOND_ENTRY_KEY 0x87
42#define WINBOND_EXIT_KEY 0xAA
43
44/* Enable configuration: pass entry key '0x87' into index port dev. */
Edward O'Callaghan85836c22014-07-09 20:26:25 +100045static void pnp_enter_conf_state(pnp_devfn_t dev)
Edward O'Callaghan5a032c62014-04-27 22:41:31 +100046{
47 u16 port = dev >> 8;
48 outb(WINBOND_ENTRY_KEY, port);
49 outb(WINBOND_ENTRY_KEY, port);
50}
51
52/* Disable configuration: pass exit key '0xAA' into index port dev. */
Edward O'Callaghan85836c22014-07-09 20:26:25 +100053static void pnp_exit_conf_state(pnp_devfn_t dev)
Edward O'Callaghan5a032c62014-04-27 22:41:31 +100054{
55 u16 port = dev >> 8;
56 outb(WINBOND_EXIT_KEY, port);
57}
58
59/* Bring up early serial debugging output before the RAM is initialized. */
Edward O'Callaghan85836c22014-07-09 20:26:25 +100060void winbond_enable_serial(pnp_devfn_t dev, u16 iobase)
Edward O'Callaghan5a032c62014-04-27 22:41:31 +100061{
62 pnp_enter_conf_state(dev);
63 pnp_set_logical_device(dev);
64 pnp_set_enable(dev, 0);
65 pnp_set_iobase(dev, PNP_IDX_IO0, iobase);
66 pnp_set_enable(dev, 1);
67 pnp_exit_conf_state(dev);
68}