Edward O'Callaghan | 5a032c6 | 2014-04-27 22:41:31 +1000 | [diff] [blame] | 1 | /* |
| 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'Callaghan | 5a032c6 | 2014-04-27 22:41:31 +1000 | [diff] [blame] | 15 | */ |
| 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. */ |
Timothy Pearson | 9891b4a | 2016-05-18 13:31:05 -0500 | [diff] [blame] | 45 | void pnp_enter_conf_state(pnp_devfn_t dev) |
Edward O'Callaghan | 5a032c6 | 2014-04-27 22:41:31 +1000 | [diff] [blame] | 46 | { |
| 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. */ |
Timothy Pearson | 9891b4a | 2016-05-18 13:31:05 -0500 | [diff] [blame] | 53 | void pnp_exit_conf_state(pnp_devfn_t dev) |
Edward O'Callaghan | 5a032c6 | 2014-04-27 22:41:31 +1000 | [diff] [blame] | 54 | { |
| 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'Callaghan | 85836c2 | 2014-07-09 20:26:25 +1000 | [diff] [blame] | 60 | void winbond_enable_serial(pnp_devfn_t dev, u16 iobase) |
Edward O'Callaghan | 5a032c6 | 2014-04-27 22:41:31 +1000 | [diff] [blame] | 61 | { |
| 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 | } |
Timothy Pearson | e4cca16 | 2016-05-24 15:48:50 -0500 | [diff] [blame] | 69 | |
| 70 | void winbond_set_pinmux(pnp_devfn_t dev, uint8_t offset, uint8_t mask, uint8_t state) |
| 71 | { |
| 72 | uint8_t byte; |
| 73 | |
| 74 | /* Configure pin mux */ |
| 75 | pnp_enter_conf_state(dev); |
| 76 | byte = pnp_read_config(dev, offset); |
| 77 | byte &= ~mask; |
| 78 | byte |= state; |
| 79 | pnp_write_config(dev, offset, byte); |
| 80 | pnp_exit_conf_state(dev); |
| 81 | } |