Hugo McNally | f6298b3 | 2023-02-12 14:47:22 +0000 | [diff] [blame] | 1 | # Pinmux Technical Specification |
Michael Schaffner | 1b1ede9 | 2019-09-24 18:49:47 -0700 | [diff] [blame] | 2 | |
| 3 | |
Garret Kelly | 9eebde0 | 2019-10-22 15:36:49 -0400 | [diff] [blame] | 4 | # Overview |
Michael Schaffner | 1b1ede9 | 2019-09-24 18:49:47 -0700 | [diff] [blame] | 5 | |
| 6 | This document specifies the functionality of the pin multiplexer (`pinmux`) peripheral. |
Hugo McNally | aef0a66 | 2023-02-11 19:44:55 +0000 | [diff] [blame] | 7 | This module conforms to the [OpenTitan guideline for peripheral device functionality](../../../doc/contributing/hw/comportability/README.md). |
Michael Schaffner | 1b1ede9 | 2019-09-24 18:49:47 -0700 | [diff] [blame] | 8 | See that document for integration overview within the broader OpenTitan top level system. |
Timothy Chen | 7f4b557 | 2019-11-02 17:42:27 -0700 | [diff] [blame] | 9 | The module provides a mechanism to reconfigure the peripheral-to-pin mapping at runtime, which greatly enhances the system flexibility. |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 10 | In addition to that, the `pinmux` also allows the user to control pad attributes (such as pull-up, pull-down, open-drain, drive-strength, keeper and inversion), and it contains features that facilitate low-power modes of the system. |
Michael Schaffner | d136b23 | 2022-01-11 10:57:29 -0800 | [diff] [blame] | 11 | For example, the sleep behavior of each pad can be programmed individually, and the module contains additional pattern detectors that can listen on any IO and wake up the system if a specific pattern has been detected. |
Michael Schaffner | 1b1ede9 | 2019-09-24 18:49:47 -0700 | [diff] [blame] | 12 | |
Garret Kelly | 9eebde0 | 2019-10-22 15:36:49 -0400 | [diff] [blame] | 13 | ## Features |
Michael Schaffner | 1b1ede9 | 2019-09-24 18:49:47 -0700 | [diff] [blame] | 14 | |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 15 | - Configurable number of chip bidirectional IOs |
Michael Schaffner | 1b1ede9 | 2019-09-24 18:49:47 -0700 | [diff] [blame] | 16 | |
| 17 | - Configurable number of peripheral inputs and outputs |
| 18 | |
| 19 | - Programmable mapping from peripheral outputs (and output enables) to top-level outputs (and output enables) |
| 20 | |
| 21 | - Programmable mapping from top-level inputs to peripheral inputs |
| 22 | |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 23 | - Programmable control of chip pad attributes like output drive-strength, pull-up, pull-down and virtual open-drain |
Michael Schaffner | 1b1ede9 | 2019-09-24 18:49:47 -0700 | [diff] [blame] | 24 | |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 25 | - Programmable pattern detectors to detect wakeup conditions during sleep mode |
Michael Schaffner | 1b1ede9 | 2019-09-24 18:49:47 -0700 | [diff] [blame] | 26 | |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 27 | - Programmable sleep mode behavior |
Michael Schaffner | 1b1ede9 | 2019-09-24 18:49:47 -0700 | [diff] [blame] | 28 | |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 29 | - Support for life-cycle-based JTAG (TAP) isolation and muxing |
Michael Schaffner | 1b1ede9 | 2019-09-24 18:49:47 -0700 | [diff] [blame] | 30 | |
Garret Kelly | 9eebde0 | 2019-10-22 15:36:49 -0400 | [diff] [blame] | 31 | # Theory of Operations |
Michael Schaffner | 1b1ede9 | 2019-09-24 18:49:47 -0700 | [diff] [blame] | 32 | |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 33 | ## Block Diagram and Overview |
Michael Schaffner | 1b1ede9 | 2019-09-24 18:49:47 -0700 | [diff] [blame] | 34 | |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 35 | The `pinmux` peripheral is a programmable module designed to wire arbitrary peripheral inputs and outputs to arbitrary multiplexable chip bidirectional pins. |
| 36 | It gives much flexibility at the top level of the device, allowing most data pins to be flexibly wired and controlled by many peripherals. |
| 37 | Even though the `pinmux` is referred to as one IP, it is logically split into two modules that are instantiated on the top-level and the chip-level, respectively, as can be seen in the block diagram below. |
| 38 | The top-level module `pinmux` contains the CSRs accessible via the TL-UL interface, the main muxing matrix, retention registers, a set of programmable wakeup detectors, and the HW strap sampling and TAP / JTAG muxing logic. |
| 39 | The chip-level module `padring` instantiates the bidirectional pads and connects the physical pad attributes. |
Michael Schaffner | 1b1ede9 | 2019-09-24 18:49:47 -0700 | [diff] [blame] | 40 | |
Hugo McNally | aef0a66 | 2023-02-11 19:44:55 +0000 | [diff] [blame] | 41 |  |
Michael Schaffner | 1b1ede9 | 2019-09-24 18:49:47 -0700 | [diff] [blame] | 42 | |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 43 | ### MIO and DIO Signal Categories |
Michael Schaffner | 1b1ede9 | 2019-09-24 18:49:47 -0700 | [diff] [blame] | 44 | |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 45 | The `pinmux` supports two different IO signal categories: |
| 46 | Muxed IO (MIO) signals that are routed through the `pinmux` matrix, and dedicated IO (DIO) signals that bypass the `pinmux` matrix. |
| 47 | This distinction is useful for accommodating IO signals that are timing critical or that must have a fixed IO mapping for another reason. |
| 48 | Note that although DIO signals are not routed through the `pinmux` matrix, they are still connected to the retention logic and the wakeup detectors (see next section below). |
Michael Schaffner | 1b1ede9 | 2019-09-24 18:49:47 -0700 | [diff] [blame] | 49 | |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 50 | The number of available peripheral IOs, pads, and their assignment to the MIO / DIO categories is done at design time as part of the top-level configuration. |
| 51 | This configurability is achieved by representing inputs / outputs as packed arrays, in combination with the SystemVerilog parameters `NPeriphIn`, `NPeriphOut`, `NMioPads` and `NDioPads`. |
| 52 | Note however that the register file is also affected by this configuration and needs to be regenerated for each design instance. |
| 53 | |
| 54 | It is assumed that all available pins that the `pinmux` connects to are bidirectional, controlled by logic within this module. |
| 55 | By default, all muxed peripheral inputs are tied to zero. |
| 56 | Further, all output enables are set to zero, which essentially causes all pads to be in high-Z state after reset. |
| 57 | In addition to wiring programmability, each muxed peripheral input can be set constantly to 0 or 1, and each muxed chip output can be set constantly to 0, 1 or high-Z. |
| 58 | |
Hugo McNally | 544e7a6 | 2023-02-12 01:12:36 +0000 | [diff] [blame] | 59 | See the [muxing matrix](#muxing-matrix) section for more details about the mux implementation. |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 60 | |
| 61 | ### Retention and Wakeup Features |
| 62 | |
Michael Schaffner | d136b23 | 2022-01-11 10:57:29 -0800 | [diff] [blame] | 63 | The retention logic allows SW to specify a certain behavior during sleep for each muxed and dedicated output. |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 64 | Legal behaviors are tie low, tie high, high-Z, keeping the previous state, or driving the current value (useful for peripherals that are always on). |
| 65 | |
| 66 | The wakeup detectors can detect patterns such as rising / falling edges and pulses of a certain width up to 255 AON clock cycles. |
| 67 | Each wakeup detector can listen on any one of the MIO / DIO signals that are routed through the `pinmux`, and if a pattern is detected, the power manager is informed of that event via a wakeup request. |
| 68 | |
Michael Schaffner | d136b23 | 2022-01-11 10:57:29 -0800 | [diff] [blame] | 69 | The `pinmux` module itself is in the always-on (AON) power domain, and as such does not loose configuration state when a sleep power cycle is performed. |
| 70 | However, only the wakeup detector logic will be actively clocked during sleep in order to save power. |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 71 | |
Hugo McNally | 544e7a6 | 2023-02-12 01:12:36 +0000 | [diff] [blame] | 72 | See the [retention logic](#retention-logic) and [wakeup detectors](#wakeup-detectors) sections for more details about the mux implementation. |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 73 | |
| 74 | ### Test and Debug Access |
| 75 | |
| 76 | The hardware strap sampling and TAP isolation logic provides test and debug access to the chip during specific life cycle states. |
Hugo McNally | 544e7a6 | 2023-02-12 01:12:36 +0000 | [diff] [blame] | 77 | This mechanism is explained in more detail in the [strap sampling and TAP isolation](#strap-sampling-and-tap-isolation) section. |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 78 | |
| 79 | ### Pad Attributes |
| 80 | |
| 81 | Additional pad-specific features such as inversion, pull-up, pull-down, virtual open-drain, drive-strength and input/output inversion etc. can be exercise via the pad attribute CSRs. |
| 82 | The `pinmux` module supports a comprehensive set of such pad attributes, but it is permissible that some of them may not be supported by the underlying pad implementation. |
| 83 | For example, certain ASIC libraries may not provide open-drain outputs, and FPGAs typically do not allow all of these attributes to be programmed dynamically at runtime. |
Hugo McNally | 544e7a6 | 2023-02-12 01:12:36 +0000 | [diff] [blame] | 84 | See the [generic pad wrapper](#generic-pad-wrapper) section below for more details. |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 85 | Note that static pad attributes for FPGAs are currently not covered in this specification. |
Michael Schaffner | 1b1ede9 | 2019-09-24 18:49:47 -0700 | [diff] [blame] | 86 | |
Timothy Chen | 7f4b557 | 2019-11-02 17:42:27 -0700 | [diff] [blame] | 87 | ## Hardware Interfaces |
| 88 | |
Hugo McNally | ba16bae | 2023-02-12 21:08:04 +0000 | [diff] [blame] | 89 | * [Interface Tables](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#interfaces) |
Michael Schaffner | 1b1ede9 | 2019-09-24 18:49:47 -0700 | [diff] [blame] | 90 | |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 91 | ### Parameters |
Michael Schaffner | 1b1ede9 | 2019-09-24 18:49:47 -0700 | [diff] [blame] | 92 | |
| 93 | The following table lists the main parameters used throughout the `pinmux` design. |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 94 | Note that the `pinmux` is generated based on the system configuration, and hence these parameters are placed into a package. |
Hugo McNally | 544e7a6 | 2023-02-12 01:12:36 +0000 | [diff] [blame] | 95 | The pinout and `pinmux` mappings are listed under [Pinout and Pinmux Mapping](#pinout-and-pinmux-mapping) for specific top-level configurations. |
Michael Schaffner | 1b1ede9 | 2019-09-24 18:49:47 -0700 | [diff] [blame] | 96 | |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 97 | Parameter | Description |
| 98 | ---------------|--------------- |
| 99 | `NPeriphOut` | Number of peripheral outputs. |
| 100 | `NPeriphIn` | Number of peripheral input. |
| 101 | `NMioPads` | Number of muxed bidirectional pads. |
| 102 | `NDioPads` | Number of dedicated pads. |
Michael Schaffner | 1b1ede9 | 2019-09-24 18:49:47 -0700 | [diff] [blame] | 103 | |
Michael Schaffner | a3af1eb | 2022-11-03 21:38:19 -0700 | [diff] [blame] | 104 | ### Primary IO Signals |
Michael Schaffner | a60c1ba | 2019-10-09 18:05:30 -0700 | [diff] [blame] | 105 | |
Michael Schaffner | a3af1eb | 2022-11-03 21:38:19 -0700 | [diff] [blame] | 106 | The table below lists the primary `pinmux` IO signals to/from the pad ring. |
| 107 | The number of dedicated and muxed IOs is parametric, and hence the signals are stacked in packed arrays. |
Michael Schaffner | 1b1ede9 | 2019-09-24 18:49:47 -0700 | [diff] [blame] | 108 | |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 109 | Signal | Direction | Type | Description |
| 110 | ---------------------------------------|-----------|------------------------------------|--------------- |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 111 | `periph_to_mio_i[NPeriphOut-1:0]` | `input` | packed `logic` | Signals from `NPeriphOut` muxed peripheral outputs coming into the `pinmux`. |
| 112 | `periph_to_mio_oe_i[NPeriphOut-1:0]` | `input` | packed `logic` | Signals from `NPeriphOut` muxed peripheral output enables coming into the `pinmux`. |
| 113 | `mio_to_periph_o[NPeriphIn-1:0]` | `output` | packed `logic` | Signals to `NPeriphIn` muxed peripherals coming from the `pinmux`. |
| 114 | `periph_to_dio_i[NDioPads-1:0]` | `input` | packed `logic` | Signals from `NDioPads` dedicated peripheral outputs coming into the `pinmux`. |
| 115 | `periph_to_dio_oe_i[NDioPads-1:0]` | `input` | packed `logic` | Signals from `NDioPads` dedicated peripheral output enables coming into the `pinmux`. |
| 116 | `dio_to_periph_o[NDioPads-1:0]` | `output` | packed `logic` | Signals to `NDioPads` dedicated peripherals coming from the `pinmux`. |
| 117 | `mio_attr_o[NMioPads-1:0]` | `output` | prim_pad_wrapper_pkg::pad_attr_t | Packed array containing the pad attributes of all muxed IOs. |
| 118 | `mio_out_o[NMioPads-1:0]` | `output` | packed `logic` | Signals to `NMioPads` bidirectional muxed pads as output data. |
| 119 | `mio_oe_o[NMioPads-1:0]` | `output` | packed `logic` | Signals to `NMioPads` bidirectional muxed pads as output enables. |
| 120 | `mio_in_i[NMioPads-1:0]` | `input` | packed `logic` | Signals from `NMioPads` bidirectional muxed pads as input data. |
| 121 | `dio_attr_o[NDioPads-1:0]` | `output` | prim_pad_wrapper_pkg::pad_attr_t | Packed array containing the pad attributes of all dedicated IOs. |
| 122 | `dio_out_o[NDioPads-1:0]` | `output` | packed `logic` | Signals to `NDioPads` bidirectional dedicated pads as output data. |
| 123 | `dio_oe_o[NDioPads-1:0]` | `output` | packed `logic` | Signals to `NDioPads` bidirectional dedicated pads as output enables. |
| 124 | `dio_in_i[NDioPads-1:0]` | `input` | packed `logic` | Signals from `NDioPads` bidirectional dedicated pads as input data. |
| 125 | |
| 126 | |
| 127 | ## Muxing Matrix |
| 128 | |
| 129 | The diagram below shows connectivity between four arbitrary chip pins, named `MIO0` .. `MIO3`, and several muxed peripheral inputs and outputs. |
| 130 | This shows the connectivity available in all directions, as well as the control registers described later in this document. |
| 131 | Two example peripherals (`uart` and `spidev`) are attached to the `pinmux` in this example, one with one input and one output, the other with three inputs and one output. |
| 132 | The diagram also shows the `padring` module which instantiates the bidirectional chip pads with output enable control. |
| 133 | |
Hugo McNally | aef0a66 | 2023-02-11 19:44:55 +0000 | [diff] [blame] | 134 |  |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 135 | |
| 136 | Note that apart from selecting a specific input pad, the `periph_insel[*]` signals can also be used to tie the peripheral input to 0 or 1. |
| 137 | Likewise, the output select signals `mio_outsel[*]` can also be used to constantly drive an output pin to 0/1 or to put it into high-Z state (default). |
| 138 | The output enable and the associated data signal (i.e. `periph_to_mio` and `periph_to_mio_oe`) are indexed with the same select signal to allow the peripheral hardware to determine the pad direction instead of demoting that control to SW. |
| 139 | |
| 140 | ## Retention Logic |
| 141 | |
| 142 | As illustrated in the picture above, all muxing matrix and DIO outputs are routed through the retention logic, which essentially consists of a set of multiplexors and two retention registers per output (one register is for the output data and one for the output enable). |
Michael Schaffner | d136b23 | 2022-01-11 10:57:29 -0800 | [diff] [blame] | 143 | This multiplexor can be configured to be automatically activated upon sleep entry in order to either drive the output low, high, high-Z or to the last seen value (keep). |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 144 | If no sleep behavior is specified, the retention logic will continue to drive out the value coming from the peripheral side, which can be useful for peripherals that reside in the AON domain. |
| 145 | |
| 146 | The sleep behavior of all outputs is activated in parallel via a trigger signal asserted by the power manager. |
Michael Schaffner | d136b23 | 2022-01-11 10:57:29 -0800 | [diff] [blame] | 147 | Once activated, it is the task of SW to disable the sleep behavior for each individual pin when waking up from sleep. |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 148 | This ensures that the output values remain stable until the system and its peripherals have been re-initialized. |
| 149 | |
| 150 | ## Wakeup Detectors |
| 151 | |
| 152 | The `pinmux` contains eight programmable wakeup detector modules that can listen on any of the MIO or DIO pins. |
| 153 | Each detector contains a debounce filter and an 8bit counter running on the AON clock domain. |
Hugo McNally | 6321c5e | 2023-02-16 21:39:55 +0000 | [diff] [blame] | 154 | The detectors can be programmed via the [`WKUP_DETECTOR_0`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#wkup_detector_0) and [`WKUP_DETECTOR_CNT_TH_0`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#wkup_detector_cnt_th_0) registers to detect the following patterns: |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 155 | |
| 156 | - rising edge |
| 157 | - falling edge |
| 158 | - rising or falling edge |
| 159 | - positive pulse up to 255 AON clock cycles in length |
| 160 | - negative pulse up to 255 AON clock cycles in length |
| 161 | |
| 162 | Note that for all patterns listed above, the input signal is sampled with the AON clock. |
| 163 | This means that the input signal needs to remain stable for at least one AON clock cycle after a level change for the detector to recognize the event (depending on the debounce filter configuration, the signal needs to remain stable for multiple clock cycles). |
| 164 | |
Hugo McNally | 6321c5e | 2023-02-16 21:39:55 +0000 | [diff] [blame] | 165 | If a pattern is detected, the wakeup detector will send a wakeup request to the power manager, and the cause bit corresponding to that detector will be set in the [`WKUP_CAUSE`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#wkup_cause) register. |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 166 | |
Hugo McNally | 6321c5e | 2023-02-16 21:39:55 +0000 | [diff] [blame] | 167 | Note that the wkup detector should be disabled by setting [`WKUP_DETECTOR_EN_0`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#wkup_detector_en_0) before changing the detection mode. |
Michael Schaffner | 4e0e44a | 2022-03-02 15:13:58 -0800 | [diff] [blame] | 168 | The reason for that is that the pulse width counter is NOT cleared upon a mode change while the detector is enabled. |
| 169 | |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 170 | ## Strap Sampling and TAP Isolation |
| 171 | |
| 172 | The `pinmux` contains a set of dedicated HW "straps", which are essentially signals that are multiplexed onto fixed MIO pad locations. |
| 173 | Depending on the life cycle state, these straps are either continuously sampled, or latched right after POR. |
| 174 | |
| 175 | There are two groups of HW straps: |
| 176 | 1. Three DFT straps that determine the DFT mode. |
| 177 | These bits are output via the `dft_strap_test_o` signal such that they can be routed to the tool-inserted DFT controller. |
| 178 | 2. Two TAP selection straps for determining which TAP should be multiplexed onto the JTAG IOs. |
| 179 | |
| 180 | The conditions under which these two strap groups are sampled are listed in the tables below. |
| 181 | Note that the HW straps can be used just like regular GPIOs once they have been sampled. |
| 182 | |
| 183 | Strap Group \ Life Cycle State | TEST_UNLOCKED* | RMA | DEV | All Other States |
| 184 | --------------------------------|----------------|--------------|--------------|------------------ |
| 185 | DFT straps | Once at boot | Once at boot | - | - |
| 186 | TAP strap 0 | Continuously | Continuously | Once at boot | Once at boot |
| 187 | TAP strap 1 | Continuously | Continuously | Once at boot | - |
| 188 | |
| 189 | *Once at boot:* Sampled once after life cycle initialization (sampling event is initiated by pwrmgr). |
| 190 | |
Dan McArdle | a5ca8fc | 2022-09-27 12:48:08 -0400 | [diff] [blame] | 191 | *Continuously:* Sampled continuously after life cycle initialization. |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 192 | |
| 193 | The TAP muxing logic is further qualified by the life cycle state in order to isolate the TAPs in certain life cycle states. |
| 194 | The following table lists the TAP strap encoding and the life cycle states in which the associated TAPs can be selected and accessed. |
| 195 | |
| 196 | TAP strap 1 | TAP strap 0 | Life Cycle State | Selected TAP |
| 197 | ------------|--------------|--------------------------|--------------- |
| 198 | 0 | 0 | All states | - |
| 199 | 0 | 1 | All states | Life Cycle |
| 200 | 1 | 0 | TEST_UNLOCKED*, RMA, DEV | RISC-V |
| 201 | 1 | 1 | TEST_UNLOCKED*, RMA | DFT |
| 202 | |
| 203 | Note that the tool-inserted DFT controller may assert the `dft_hold_tap_sel_i` during a test (e.g. boundary scan) in which case the `pinmux` will temporarily pause sampling of the TAP selection straps. |
| 204 | |
Michael Schaffner | 827b232 | 2022-01-10 11:23:50 -0800 | [diff] [blame] | 205 | Also, it should be noted that the pad attributes of all JTAG IOs will be gated to all-zero temporarily, while the JTAG is enabled (this does not affect the values in the CSRs). |
| 206 | This is to ensure that any functional attributes like inversion or pull-ups / pull-downs do not interfere with the JTAG while it is in use. |
| 207 | |
Hugo McNally | aef0a66 | 2023-02-11 19:44:55 +0000 | [diff] [blame] | 208 | For more information about the life cycle states, see [Life Cycle Controller Specification](../lc_ctrl/README.md) and the [Life Cycle Definition Table](../../../doc/security/specs/device_life_cycle/README.md#manufacturing-states). |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 209 | |
| 210 | |
| 211 | ## Generic Pad Wrapper |
| 212 | |
| 213 | <center> |
| 214 | <img src="generic_pad_wrapper.svg" width="50%"> |
| 215 | </center> |
| 216 | |
| 217 | The generic pad wrapper is intended to abstract away implementation differences between the target technologies by providing a generic interface that is compatible with the `padring` module. |
| 218 | It is the task of the RTL build flow to select the appropriate pad wrapper implementation. |
| 219 | |
| 220 | A specific implementation of a pad wrapper may choose to instantiate a technology primitive (as it is common in ASIC flows), or it may choose to model the functionality behaviorally such that it can be inferred by the technology mapping tool (e.g., in the case of an FPGA target). |
| 221 | It is permissible to omit the implementation of all IO attributes except input/output inversion. |
| 222 | |
| 223 | The generic pad wrapper must expose the following IOs and parameters, even if they are not connected internally. |
| 224 | In particular, the pad attribute struct `attr_i` must contain all fields listed below, even if not all attributes are supported (it is permissible to just leave them unconnected in the pad wrapper implementation). |
| 225 | |
| 226 | Parameter | Default | Description |
| 227 | ---------------|------------|----------------------------------------------------- |
| 228 | `PadType` | `BidirStd` | Pad variant to be instantiated (technology-specific) |
| 229 | `ScanRole` | `NoScan` | Scan role, can be `NoScan`, `ScanIn` or `ScanOut` |
| 230 | |
| 231 | Note that `PadType` is a technology-specific parameter. |
| 232 | The generic pad wrapper only implements variant `BidirStd`, but for other target technologies, this parameter can be used to select among a variety of different pad flavors. |
| 233 | |
| 234 | The `ScanRole` parameter determines the behavior when scanmode is enabled. |
| 235 | Depending on whether a given pad acts as a scan input or output, certain pad attributes and functionalities need to be bypassed. |
| 236 | This parameter is typically only relevant for ASIC targets and therefore not modeled in the generic pad model. |
| 237 | |
| 238 | Also note that the pad wrapper may implement a "virtual" open-drain termination, where standard bidirectional pads are employed, but instead of driving the output high for a logic 1 the pad is put into tristate mode. |
| 239 | |
| 240 | Signal | Direction | Type | Description |
| 241 | ---------------------|------------|-------------|----------------------------------------------- |
| 242 | `clk_scan_i` | `input` | `logic` | Scan clock of the pad |
| 243 | `scanmode_i` | `input` | `logic` | Scan mode enable of the pad |
| 244 | `pok_i` | `input` | `pad_pok_t` | Technology-specific power sequencing signals |
| 245 | `inout_io` | `inout` | `wire` | Bidirectional inout of the pad |
| 246 | `in_o` | `output` | `logic` | Input data signal |
| 247 | `in_raw_o` | `output` | `logic` | Un-inverted input data signal |
| 248 | `out_i` | `input` | `logic` | Output data signal |
| 249 | `oe_i` | `input` | `logic` | Output data enable |
| 250 | `attr_i[0]` | `input` | `logic` | Input/output inversion |
| 251 | `attr_i[1]` | `input` | `logic` | Virtual open-drain enable |
| 252 | `attr_i[2]` | `input` | `logic` | Pull enable |
| 253 | `attr_i[3]` | `input` | `logic` | Pull select (0: pull-down, 1: pull-up) |
| 254 | `attr_i[4]` | `input` | `logic` | Keeper enable |
| 255 | `attr_i[5]` | `input` | `logic` | Schmitt trigger enable |
Cindy Chen | 18d6a96 | 2022-01-08 11:58:52 -0800 | [diff] [blame] | 256 | `attr_i[6]` | `input` | `logic` | Open drain enable |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 257 | `attr_i[8:7]` | `input` | `logic` | Slew rate (0x0: slowest, 0x3: fastest) |
| 258 | `attr_i[12:9]` | `input` | `logic` | Drive strength (0x0: weakest, 0xf: strongest) |
| 259 | |
Hugo McNally | 6321c5e | 2023-02-16 21:39:55 +0000 | [diff] [blame] | 260 | Note that the corresponding pad attribute registers [`MIO_PAD_ATTR_0`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#mio_pad_attr_0) and [`DIO_PAD_ATTR_0`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#dio_pad_attr_0) have "writes-any-reads-legal" (WARL) behavior (see also [pad attributes](#pad-attributes)). |
Michael Schaffner | 1b1ede9 | 2019-09-24 18:49:47 -0700 | [diff] [blame] | 261 | |
Timothy Chen | 7f4b557 | 2019-11-02 17:42:27 -0700 | [diff] [blame] | 262 | # Programmers Guide |
Michael Schaffner | 1b1ede9 | 2019-09-24 18:49:47 -0700 | [diff] [blame] | 263 | |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 264 | ## Pad Attributes |
| 265 | |
| 266 | Software should determine and program the pad attributes at startup, or reprogram the attributes when the functionality requirements change at runtime. |
| 267 | |
Hugo McNally | 6321c5e | 2023-02-16 21:39:55 +0000 | [diff] [blame] | 268 | This can be achieved by writing to the [`MIO_PAD_ATTR_0`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#mio_pad_attr_0) and [`DIO_PAD_ATTR_0`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#dio_pad_attr_0) registers. |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 269 | Note that the IO attributes should be configured before enabling muxed IOs going through the `pinmux` matrix in order to avoid undesired electrical behavior and/or contention at the pads. |
| 270 | |
Hugo McNally | 6321c5e | 2023-02-16 21:39:55 +0000 | [diff] [blame] | 271 | The pad attributes configuration can be locked down individually for each pad via the [`MIO_PAD_ATTR_REGWEN_0`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#mio_pad_attr_regwen_0) and [`DIO_PAD_ATTR_REGWEN_0`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#dio_pad_attr_regwen_0) registers. |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 272 | The configuration can then not be altered anymore until the next system reset. |
| 273 | |
| 274 | The following pad attributes are supported by this register layout by default: |
| 275 | |
| 276 | ATTR Bits | Description | Access |
| 277 | ----------|-----------------------------------------------|--------- |
Michael Schaffner | 827b232 | 2022-01-10 11:23:50 -0800 | [diff] [blame] | 278 | 0 | Input/output inversion | WARL |
| 279 | 1 | Virtual open drain enable | WARL |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 280 | 2 | Pull enable | WARL |
| 281 | 3 | Pull select (0: down, 1: up) | WARL |
| 282 | 4 | Keeper enable | WARL |
| 283 | 5 | Schmitt trigger enable | WARL |
Cindy Chen | 18d6a96 | 2022-01-08 11:58:52 -0800 | [diff] [blame] | 284 | 6 | Open drain enable | WARL |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 285 | 8:7 | Slew rate (0x0: slowest, 0x3: fastest) | WARL |
| 286 | 12:9 | Drive strength (0x0: weakest, 0xf: strongest) | WARL |
| 287 | |
| 288 | Since some of the pad attributes may not be implemented, SW can probe this capability by writing the CSRs and read them back to determine whether the value was legal. |
| 289 | This behavior is also referred to as "writes-any-reads-legal" or "WARL" in the RISC-V world. |
| 290 | For example, certain pads may only support two drive-strength bits, instead of four. |
| 291 | The unsupported drive-strength bits in the corresponding CSRs would then always read as zero, even if SW attempts to set them to 1. |
| 292 | |
| 293 | ## Pinmux Configuration |
| 294 | |
| 295 | Upon POR, the `pinmux` state is such that all MIO outputs are high-Z, and all MIO peripheral inputs are tied off to 0. |
| 296 | Software should determine and program the `pinmux` mapping at startup, or reprogram it when the functionality requirements change at runtime. |
Hugo McNally | 6321c5e | 2023-02-16 21:39:55 +0000 | [diff] [blame] | 297 | This can be achieved by writing the following values to the [`PERIPH_INSEL_0`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#periph_insel_0) and [`MIO_OUTSEL_0`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#mio_outsel_0) registers. |
Michael Schaffner | 1b1ede9 | 2019-09-24 18:49:47 -0700 | [diff] [blame] | 298 | |
| 299 | `periph_insel` Value | Selected Input Signal |
| 300 | ----------------------|----------------------- |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 301 | 0 | Constant zero (default) |
Michael Schaffner | 1b1ede9 | 2019-09-24 18:49:47 -0700 | [diff] [blame] | 302 | 1 | Constant one |
| 303 | 2 + k | Corresponding MIO input signal at index k |
| 304 | |
| 305 | The global default at reset is `0`, but the default of individual signals can be overridden at design time, if needed. |
| 306 | |
| 307 | `mio_outsel` Value | Selected Output signal |
| 308 | ----------------------|----------------------- |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 309 | 0 | Constant zero (default) |
Michael Schaffner | 1b1ede9 | 2019-09-24 18:49:47 -0700 | [diff] [blame] | 310 | 1 | Constant one |
| 311 | 2 | High-Z |
| 312 | 3 + k | Corresponding peripheral output signal at index k |
| 313 | |
| 314 | The global default at reset is `2`, but the default of individual signals can be overridden at design time, if needed. |
| 315 | |
Hugo McNally | 6321c5e | 2023-02-16 21:39:55 +0000 | [diff] [blame] | 316 | Note that the `pinmux` configuration should be sequenced after any IO attribute-specific configuration in the [`MIO_PAD_ATTR_0`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#mio_pad_attr_0) and [`DIO_PAD_ATTR_0`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#dio_pad_attr_0) registers to avoid any unwanted electric behavior and/or contention. |
| 317 | If needed, each select signal can be individually locked down via [`MIO_PERIPH_INSEL_REGWEN_0`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#mio_periph_insel_regwen_0) or [`MIO_OUTSEL_REGWEN_0`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#mio_outsel_regwen_0). |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 318 | The configuration can then not be altered anymore until the next system reset. |
Michael Schaffner | 1b1ede9 | 2019-09-24 18:49:47 -0700 | [diff] [blame] | 319 | |
Michael Schaffner | d136b23 | 2022-01-11 10:57:29 -0800 | [diff] [blame] | 320 | ## Sleep Features |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 321 | |
Hugo McNally | 6321c5e | 2023-02-16 21:39:55 +0000 | [diff] [blame] | 322 | The sleep behavior of each individual MIO or DIO can be defined via the ([`MIO_PAD_SLEEP_EN_0`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#mio_pad_sleep_en_0), [`DIO_PAD_SLEEP_EN_0`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#dio_pad_sleep_en_0), [`MIO_PAD_SLEEP_MODE_0`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#mio_pad_sleep_mode_0) and [`DIO_PAD_SLEEP_MODE_0`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#dio_pad_sleep_mode_0)) registers. |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 323 | Available sleep behaviors are: |
| 324 | `dio/mio_pad_sleep_en` Value | `dio/mio_pad_sleep_mode` Value | Sleep Behavior |
| 325 | ------------------------------|--------------------------------|----------------------- |
| 326 | 0 | - | Drive (default) |
| 327 | 1 | 0 | Tie-low |
| 328 | 1 | 1 | Tie-high |
| 329 | 1 | 2 | High-Z |
| 330 | 1 | 3 | Keep last value |
| 331 | |
Michael Schaffner | d136b23 | 2022-01-11 10:57:29 -0800 | [diff] [blame] | 332 | Note that if the behavior is set to "Drive", the sleep mode will not be activated upon sleep entry. |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 333 | Rather, the retention logic continues to drive the value coming from the peripheral side. |
| 334 | Also note that the sleep logic is located after the `pinmux` matrix, hence the sleep configuration is per MIO pad and not per MIO peripheral. |
| 335 | |
Hugo McNally | 6321c5e | 2023-02-16 21:39:55 +0000 | [diff] [blame] | 336 | Before sleep entry, SW should configure the appropriate sleep behavior of all MIOs/DIOs via [`MIO_PAD_SLEEP_MODE_0`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#mio_pad_sleep_mode_0), [`DIO_PAD_SLEEP_MODE_0`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#dio_pad_sleep_mode_0). |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 337 | This configuration can be optionally locked down, in which case it cannot be modified again until POR. |
Hugo McNally | 6321c5e | 2023-02-16 21:39:55 +0000 | [diff] [blame] | 338 | The configured behavior is then activated for all pads that have sleep mode set to enabled ([`MIO_PAD_SLEEP_EN_0`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#mio_pad_sleep_en_0) and [`DIO_PAD_SLEEP_EN_0`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#dio_pad_sleep_en_0)) at once by the power manager during the sleep entry sequence. |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 339 | |
| 340 | When exiting sleep, the task of disabling the sleep behavior is however up to SW. |
Hugo McNally | 6321c5e | 2023-02-16 21:39:55 +0000 | [diff] [blame] | 341 | I.e., it must clear the per-pad sleep status bits in registers [`MIO_PAD_SLEEP_STATUS_0`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#mio_pad_sleep_status_0) and [`DIO_PAD_SLEEP_STATUS_0`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#dio_pad_sleep_status_0) that have been set upon sleep entry. |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 342 | The rationale for this is that it may not be desirable to disable sleep behavior on all pads at once due to some additional book keeping / re-initialization that needs to be performed while exiting sleep. |
| 343 | |
| 344 | ## Wakeup Features |
| 345 | |
| 346 | The `pinmux` contains eight wakeup detectors. |
| 347 | These detectors can be individually enabled and disabled regardless of the sleep state. |
| 348 | This ensures that SW can set them up before and disable them after sleep in order to ensure that no events are missed during sleep entry and exit. |
| 349 | |
Hugo McNally | 544e7a6 | 2023-02-12 01:12:36 +0000 | [diff] [blame] | 350 | For more information on the patterns supported by the wakeup detectors, see [wakeup detectors](#wakeup-detectors). |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 351 | |
| 352 | A typical programming sequence for the wakeup detectors looks as follows: |
| 353 | |
Hugo McNally | 6321c5e | 2023-02-16 21:39:55 +0000 | [diff] [blame] | 354 | 1. Before initiating any sleep mode, SW should configure the wakeup detectors appropriately and enable them via the [`WKUP_DETECTOR_0`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#wkup_detector_0), [`WKUP_DETECTOR_CNT_TH_0`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#wkup_detector_cnt_th_0) and [`WKUP_DETECTOR_PADSEL_0`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#wkup_detector_padsel_0) registers. |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 355 | |
Hugo McNally | 6321c5e | 2023-02-16 21:39:55 +0000 | [diff] [blame] | 356 | 2. Optionally, lock the wakeup detector configuration via the [`WKUP_DETECTOR_REGWEN_0`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#wkup_detector_regwen_0) registers. |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 357 | |
Cindy Chen | 17ba69c | 2022-01-04 12:26:01 -0800 | [diff] [blame] | 358 | 3. During sleep, the wakeup detectors will trigger a wakeup request if a matching pattern has been observed. |
Hugo McNally | 6321c5e | 2023-02-16 21:39:55 +0000 | [diff] [blame] | 359 | A bit corresponding to the wakeup detector that has observed the pattern will be set in the [`WKUP_CAUSE`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#wkup_cause) register. |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 360 | |
Hugo McNally | aef0a66 | 2023-02-11 19:44:55 +0000 | [diff] [blame] | 361 | 4. When exiting sleep, SW should read the wake info register in the [power manager](../pwrmgr/README.md) to determine the reason(s) for the wakeup request. |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 362 | |
Hugo McNally | 6321c5e | 2023-02-16 21:39:55 +0000 | [diff] [blame] | 363 | 5. If the wakeup request was due to a pin wakeup pattern detector, SW should inspect the [`WKUP_CAUSE`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#wkup_cause) registers in order to determine the exact cause. |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 364 | |
Hugo McNally | 6321c5e | 2023-02-16 21:39:55 +0000 | [diff] [blame] | 365 | 6. SW should in any case disable the wakeup detectors and clear the [`WKUP_CAUSE`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#wkup_cause) registers once it is safe to do so (in order to not miss any events). |
| 366 | Note that the [`WKUP_CAUSE`](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#wkup_cause) registers reside in the slow AON clock domain, and hence clearing them takes a few uS to take effect. |
Michael Schaffner | 00768a2 | 2021-06-11 22:07:56 -0700 | [diff] [blame] | 367 | If needed, a SW readback can be performed to ensure that the clear operation has completed successfully. |
| 368 | |
| 369 | ## Pinout and Pinmux Mapping |
| 370 | |
Michael Schaffner | 426ed20 | 2021-08-02 17:44:42 -0700 | [diff] [blame] | 371 | The tables below summarize the pinout and pinmux connectivity for certain top-level designs. |
| 372 | |
| 373 | ### Top Earlgrey |
| 374 | |
Amaury Pouly | 934f088 | 2023-02-10 13:38:09 +0000 | [diff] [blame] | 375 | {{#include ../../top_earlgrey/ip/pinmux/doc/autogen/targets.md}} |
Michael Schaffner | 1b1ede9 | 2019-09-24 18:49:47 -0700 | [diff] [blame] | 376 | |
Timothy Trippel | f82e75a | 2022-07-27 14:42:22 -0700 | [diff] [blame] | 377 | ## Device Interface Functions (DIFs) |
| 378 | |
Hugo McNally | ac9f9b5 | 2023-02-14 12:15:34 +0000 | [diff] [blame] | 379 | - [Device Interface Functions](../../../sw/device/lib/dif/dif_pinmux.h) |
Timothy Trippel | f82e75a | 2022-07-27 14:42:22 -0700 | [diff] [blame] | 380 | |
Timothy Chen | 7f4b557 | 2019-11-02 17:42:27 -0700 | [diff] [blame] | 381 | ## Register Table |
Michael Schaffner | 31da039 | 2019-10-02 10:22:54 -0700 | [diff] [blame] | 382 | |
Sam Elliott | d834c70 | 2020-02-12 11:18:47 +0000 | [diff] [blame] | 383 | The register description below matches the instance in the [Earl Grey top level |
Hugo McNally | aef0a66 | 2023-02-11 19:44:55 +0000 | [diff] [blame] | 384 | design](../../top_earlgrey/doc/specification.md). |
Michael Schaffner | a60c1ba | 2019-10-09 18:05:30 -0700 | [diff] [blame] | 385 | |
Sam Elliott | d834c70 | 2020-02-12 11:18:47 +0000 | [diff] [blame] | 386 | Similar register descriptions can be generated with different parameterizations. |
| 387 | |
Hugo McNally | ba16bae | 2023-02-12 21:08:04 +0000 | [diff] [blame] | 388 | * [Register Table](../../top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson#registers) |