| 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | |
| 3 | /* |
| 4 | * A generic romstage (pre-ram) driver for Nuvoton variant Super I/O chips. |
| 5 | * |
| 6 | * The following is derived directly from the vendor Nuvoton's data-sheets: |
| 7 | * |
| 8 | * To toggle between `configuration mode` and `normal operation mode` as to |
| 9 | * manipulate the various LDN's in Nuvoton Super I/O's we are required to |
| 10 | * pass magic numbers `passwords keys`. |
| 11 | * |
| 12 | * NUVOTON_ENTRY_KEY := enable configuration : 0x87 |
| 13 | * NUVOTON_EXIT_KEY := disable configuration : 0xAA |
| 14 | * |
| 15 | * To modify a LDN's configuration register, we use the index port to select |
| 16 | * the index of the LDN and then write to the data port to alter the |
| 17 | * parameters. A default index, data port pair is 0x4E, 0x4F respectively, a |
| 18 | * user modified pair is 0x2E, 0x2F respectively. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <arch/io.h> |
| 23 | #include <device/pnp_ops.h> |
| 24 | #include <device/pnp.h> |
| 25 | #include <stdint.h> |
| 26 | #include "nuvoton.h" |
| 27 | |
| 28 | #define NUVOTON_ENTRY_KEY 0x87 |
| 29 | #define NUVOTON_EXIT_KEY 0xAA |
| 30 | |
| 31 | /* Enable configuration: pass entry key '0x87' into index port dev |
| 32 | * two times. */ |
| 33 | void nuvoton_pnp_enter_conf_state(pnp_devfn_t dev) |
| 34 | { |
| 35 | u16 port = dev >> 8; |
| 36 | outb(NUVOTON_ENTRY_KEY, port); |
| 37 | outb(NUVOTON_ENTRY_KEY, port); |
| 38 | } |
| 39 | |
| 40 | /* Disable configuration: pass exit key '0xAA' into index port dev. */ |
| 41 | void nuvoton_pnp_exit_conf_state(pnp_devfn_t dev) |
| 42 | { |
| 43 | u16 port = dev >> 8; |
| 44 | outb(NUVOTON_EXIT_KEY, port); |
| 45 | } |
| 46 | |
| 47 | /* Bring up early serial debugging output before the RAM is initialized. */ |
| 48 | void nuvoton_enable_serial(pnp_devfn_t dev, u16 iobase) |
| 49 | { |
| 50 | if (!CONFIG(CONSOLE_SERIAL)) |
| 51 | return; |
| 52 | |
| 53 | nuvoton_pnp_enter_conf_state(dev); |
| 54 | |
| 55 | if (CONFIG(SUPERIO_NUVOTON_COMMON_COM_A)) |
| 56 | /* Route COM A to GPIO8 pin group */ |
| 57 | pnp_unset_and_set_config(dev, 0x2a, 1 << 7, 0); |
| 58 | |
| 59 | pnp_set_logical_device(dev); |
| 60 | pnp_set_enable(dev, 0); |
| 61 | pnp_set_iobase(dev, PNP_IDX_IO0, iobase); |
| 62 | pnp_set_enable(dev, 1); |
| 63 | nuvoton_pnp_exit_conf_state(dev); |
| 64 | } |