Software APIs
dif_pinmux.h
Go to the documentation of this file.
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 
5 #ifndef OPENTITAN_SW_DEVICE_LIB_DIF_DIF_PINMUX_H_
6 #define OPENTITAN_SW_DEVICE_LIB_DIF_DIF_PINMUX_H_
7 
8 /**
9  * @file
10  * @brief <a href="/hw/ip/pinmux/doc/">Pin Multiplexer</a> Device Interface
11  * Functions
12  */
13 
14 /**
15  * Pin Multiplexer connects peripheral input/output signals to the Padring MIO
16  * pad input/output signals.
17  *
18  * Every peripheral input signal is fed into a multiplexer, where selects
19  * determine which Padring MIO pad input or constants should be connected to it.
20  *
21  * Every Padring MIO pad output signal is fed into a multiplexer, where selects
22  * determine which peripheral output or constants should be connected to it.
23  */
24 
25 #include <stdbool.h>
26 #include <stdint.h>
27 
31 
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif // __cplusplus
37 
38 /**
39  * Pin Multiplexer Padring pad kinds.
40  *
41  * A pad can be a Multiplexed (MIO) or Dedicated (DIO).
42  */
43 typedef enum dif_pinmux_pad_kind {
44  /**
45  * Multiplexed Input/Output pad. Connected to a peripheral input or output
46  * via a multiplexer matrix inside the a Pin Multiplexer.
47  */
49  /**
50  * Dedicated Input/Output pad. Connected directly to a peripheral input
51  * or output, bypassing the multiplexer matrix.
52  */
54  kDifPinmuxPadKindCount,
56 
57 /**
58  * Pin Multiplexer functionality locking.
59  *
60  * Represents a target functionality to be locked for a given
61  * pad/peripheral input.
62  */
63 typedef enum dif_pinmux_lock_target {
64  /**
65  * Lock MIO pad input select for a given peripheral input. This means that
66  * the peripheral input connection can no longer be changed.
67  */
69  /**
70  * Lock peripheral output select for a given MIO pad output. This means
71  * that the MIO pad output connection can no longer be changed.
72  */
74  /**
75  * Lock the sleep mode configuration for a given MIO pad.
76  */
78  /**
79  * Lock the sleep mode configuration for a given DIO pad.
80  */
82  /**
83  * Lock physical characteristics configuration for a given MIO pad.
84  */
86  /**
87  * Lock physical characteristics configuration for a given DIO pad.
88  */
90  /**
91  * Lock wake-up detector configuration for a given detector.
92  */
94 
96 
97 /**
98  * Pin Multiplexer generic index.
99  *
100  * The meaning of this index changes between APIs, and must be documented in
101  * the corresponding function description.
102  */
103 typedef uint32_t dif_pinmux_index_t;
104 
105 /**
106  * Pad slew rate value.
107  *
108  * This selects between available slew rate values, where the largest number
109  * produces the fastest slew rate. See the device's data sheet for the
110  * particular mapping.
111  */
113 
114 /**
115  * Pad drive strength value.
116  *
117  * This selects between available drive strength values, where the largest
118  * number produces the highest drive strength. See the device's data sheet for
119  * the particular mapping.
120  */
122 
123 /**
124  * Pad attribute flag values
125  *
126  * This `enum` is a bitfield, meaning that it is allowed to pass combined value
127  * of multiple individual attributes.
128  *
129  * Some attributes have defined meanings, others are implementation defined. Not
130  * all pads will support all attributes, or attribute combinations. The Pin
131  * Multiplexer DIF checks for conflicting or unsupported attributes provided by
132  * the Write-Any Read-Legal (WARL) semantics of the underlying hardware. If the
133  * combination of attributes is not supported - some/all of these attributes
134  * will still be disabled (relevant bit unset in the attribute field).
135  *
136  * IMPORTANT:
137  * - Functions are used to toggle these attributes, must signal an error if at
138  * least one of the attributes in the bitfield could not be toggled.
139  */
141  kDifPinmuxPadAttrInvertLevel = 1 << 0,
142  kDifPinmuxPadAttrVirtualOpenDrain = 1 << 1,
143  kDifPinmuxPadAttrPullResistorEnable = 1 << 2,
144  kDifPinmuxPadAttrPullResistorUp = 1 << 3,
145  kDifPinmuxPadAttrKeeper = 1 << 4,
146  kDifPinmuxPadAttrSchmittTrigger = 1 << 5,
147  kDifPinmuxPadAttrOpenDrain = 1 << 6,
149 
150 /**
151  * Pin multiplexer padring pad attributes.
152  */
153 typedef struct dif_pinmux_pad_attr {
154  /**
155  * Slew rate attribute. A greater number produces a faster slew rate.
156  */
158  /**
159  * Drive strength pad attribute. A greater number produces a stronger drive.
160  */
162  /**
163  * A bit map of single-bit attribute flags. See dif_pinmux_pad_attr_flags_t
164  * for the mapping and definitions.
165  */
168 
169 /**
170  * A sleep mode for a Padring DIO/MIO pad.
171  *
172  * This determines the behaviour of a pad in deep sleep state.
173  *
174  * NOTE:
175  * After the chip has come back from deep sleep, the mode of the pad
176  * persists until it is explicitly cleared by `dif_pinmux_sleep_clear_state`.
177  * Calling `dif_pinmux_sleep_enable` will configure the pad mode for
178  * the next deep sleep, however it will not change the current mode.
179  */
180 typedef enum dif_pinmux_sleep_mode {
181  /**
182  * The pad is driven actively to zero.
183  */
185  /**
186  * The pad is driven actively to one.
187  */
189  /**
190  * The pad is left undriven. Note that the actual driving behaviour will
191  * depend on the pull-up/-down configuration.
192  */
194  /**
195  * Keep last driven value (including high-Z).
196  */
198  kDifPinmuxSleepModeCount,
200 
201 /**
202  * A Pin Multiplexer wake-up detection mode (edge triggered).
203  */
205  /**
206  * Trigger a wakeup request when observing a positive edge.
207  */
209  /**
210  * Trigger a wakeup request when observing a negative edge.
211  */
213  /**
214  * Trigger a wakeup request when observing an edge in any direction.
215  */
217  /**
218  * Trigger a wakeup request when pin is driven HIGH for a certain amount of
219  * always-on clock cycles as configured in
220  * `dif_pinmux_wakeup_timed_config_t`, `counter_threshold` field.
221  */
223  /**
224  * Trigger a wakeup request when pin is driven LOW for a certain amount of
225  * always-on clock cycles as configured in
226  * `dif_pinmux_wakeup_timed_config_t`, `counter_threshold` field.
227  */
229  kDifPinmuxWakeupModeCount,
231 
232 /**
233  * A Pin Multiplexer common wake-up configuration between different modes.
234  */
235 typedef struct dif_pinmux_wakeup_config {
236  /**
237  * Signal filter - signal must be stable for 4 always-on clock cycles
238  * before the value is being forwarded. Can be used for debouncing.
239  */
241  /**
242  * Pad type (MIO or DIO) to enable the wake-up detection for.
243  */
245  /**
246  * Selects a specific pad. In the case of MIO, the pad select index is the
247  * same as used for `dif_pinmux_input_select`, meaning that index 0 and 1 just
248  * select constant 0, and the MIO pads live at indices >= 2. In the case of
249  * DIO pads, the pad select index corresponds 1:1 to the DIO pad to be
250  * selected.
251  */
253  /**
254  * Wake-up detection mode.
255  */
257  /**
258  * Counter threshold for `kDifPinmuxWakeupModeTimedLow` and
259  * `kDifPinmuxWakeupModeTimedHigh` wake-up detector modes. The threshold is in
260  * terms of always-on clock cycles.
261  */
264 
265 /**
266  * Locks out Pin Multiplexer functionality based on the `target` and `index`.
267  *
268  * This function allows for a fine grained locking of the Pin Multiplexer
269  * parts. `index` changes meaning dependent on the `target`. For example, when
270  * `target` is `kDifPinmuxLockTargetInsel`, `index` represents a peripheral
271  * input for which the MIO input select functionality should be locked.
272  *
273  * NOTE:
274  * Locking an already locked register will succeed with the `kDifOk`
275  * return code.
276  *
277  * @param pinmux A Pin Multiplexer handle.
278  * @param index Exact meaning is determined by the `target`, however, it
279  * represents one of the following: peripheral input index,
280  * MIO pad index, DIO pad index or a wakeup detector index.
281  * @param target Target functionality to be locked.
282  * @return The result of the operation.
283  */
286  dif_pinmux_index_t index,
287  dif_pinmux_lock_target_t target);
288 
289 /**
290  * Obtains the Pin Multiplexer Pad lock status based on `target` and `index`.
291  *
292  * @param pinmux A Pin Multiplexer handle.
293  * @param index Exact meaning is determined by the `target`, however, it
294  * represents one of the following: peripheral input index,
295  * MIO pad index, DIO pad index or a wakeup detector index.
296  * @param target Target functionality to be locked.
297  * @param[out] is_locked Out-param for the locked state.
298  * @return The result of the operation.
299  */
302  dif_pinmux_index_t index,
304  bool *is_locked);
305 
306 /**
307  * Sets a connection between a peripheral input and a MIO pad input.
308  *
309  * A peripheral input can be connected to any available MIO pad input.
310  *
311  * @param pinmux A Pin Multiplexer handle.
312  * @param peripheral_input A Peripheral input index.
313  * @param insel Input connection select - a MIO pad input to be connected to
314  * a peripheral input.
315  * @return The result of the operation.
316  */
319  dif_pinmux_index_t peripheral_input,
320  dif_pinmux_index_t insel);
321 
322 /**
323  * Sets a connection between a MIO pad output and peripheral output.
324  *
325  * A MIO pad output can be connected to any available peripheral output.
326  *
327  * @param pinmux A Pin Multiplexer handle.
328  * @param mio_pad_output Padring MIO output index.
329  * @param outsel Peripheral output connection select - a Peripheral output to be
330  * connected to a MIO pad output.
331  * @return The result of the operation.
332  */
335  dif_pinmux_index_t mio_pad_output,
336  dif_pinmux_index_t outsel);
337 
338 /**
339  * Writes attributes for a pad.
340  *
341  * This function completely overwrites the existing configuration of a pad, and
342  * has both enable and disable semantics.
343  *
344  * Not all pads implement all attributes and some combinations cannot be
345  * enabled together. This function returns a `kDifBadArg` error in case of
346  * invalid `attrs_in`.
347  * Conflicting attributes will be discarded by the hardware, and can be
348  * identified by comparing `attrs_in` to `attrs_out`.
349  *
350  * IMPORTANT:
351  * See `dif_pinmux_pad_attr` for information on which attributes are compulsory
352  * and which invariants are mutually exclusive.
353  *
354  * @param pinmux A Pin Multiplexer handle.
355  * @param pad Pad index to write the attributes for.
356  * @param type Pad type (MIO or DIO).
357  * @param attrs_in Attribute values to write.
358  * @param attrs_out[out] The actual attributes written and accepted by the
359  * hardware.
360  * @return The result of the operation.
361  */
364  dif_pinmux_index_t pad,
366  dif_pinmux_pad_attr_t attrs_in,
367  dif_pinmux_pad_attr_t *attrs_out);
368 
369 /**
370  * Get attributes for a pad.
371  *
372  * @param pinmux A Pin Multiplexer handle.
373  * @param pad Pad index to obtain the attributes for.
374  * @param type Pad type (MIO or DIO).
375  * @param attrs[out] Obtained attributes.
376  * @return The result of the operation.
377  */
380  dif_pinmux_index_t pad,
382  dif_pinmux_pad_attr_t *attrs);
383 
384 /**
385  * Enables deep sleep mode of a particular pad.
386  *
387  * NOTE:
388  * After the chip has come back from deep sleep, the mode of a pad persists
389  * until is explicitly cleared by `dif_pinmux_pad_sleep_clear_state`. Calling
390  * `dif_pinmux_pad_sleep_enable` will configure a pad mode for the next deep
391  * sleep, however it will not change the current mode.
392  *
393  * @param pinmux A Pin Multiplexer handle.
394  * @param pad Pad index.
395  * @param type Pad type (MIO or DIO).
396  * @param mode Pad deep sleep mode.
397  * @return The result of the operation.
398  */
401  dif_pinmux_index_t pad,
404 
405 /**
406  * Disables deep sleep mode of a particular pad.
407  *
408  * NOTE:
409  * After the chip has come back from deep sleep, the mode of a pad persists
410  * until is explicitly cleared by `dif_pinmux_pad_sleep_clear_state`. Calling
411  * `dif_pinmux_pad_sleep_enable` will configure a pad mode for the next deep
412  * sleep, however it will not change the current mode.
413  *
414  * @param pinmux A Pin Multiplexer handle.
415  * @param pad Pad index.
416  * @param type Pad type (MIO or DIO).
417  * @return The result of the operation.
418  */
421  dif_pinmux_index_t pad,
422  dif_pinmux_pad_kind_t type);
423 
424 /**
425  * Returns the state of a particular pad.
426  *
427  * When the pad is in deep sleep mode, the mode persists until is explicitly
428  * cleared via `dif_pinmux_pad_sleep_clear_state`.
429  *
430  * @param padmux A Pin Multiplexer handle.
431  * @param pad Pad index.
432  * @param type Padring pad type (MIO or DIO).
433  * @param[out] in_sleep_mode Pad state, `true` when in deep sleep mode.
434  * @return The result of the operation.
435  */
438  dif_pinmux_index_t pad,
440  bool *in_sleep_mode);
441 
442 /**
443  * Clears deep sleep mode for a particular pad.
444  *
445  * When deep sleep mode is enabled for a pad, and the device has entered deep
446  * sleep mode; upon wake-up, the deep sleep status of this pad can only be
447  * cleared by calling this function. Re-configuring this pad will only take
448  * effect during the next deep sleep.
449  *
450  * @param pinmux A Pin Multiplexer handle.
451  * @param pad Pad index.
452  * @param type Padring pad type (MIO or DIO).
453  * @return The result of the operation.
454  */
457  dif_pinmux_index_t pad,
458  dif_pinmux_pad_kind_t type);
459 
460 /**
461  * Enables wake-up mode detection for a particular detector.
462  *
463  * @param pinmux A Pin Multiplexer handle.
464  * @param detector A detector index.
465  * @param config A wake-up detector configuration.
466  * @return The result of the operation.
467  */
470  const dif_pinmux_t *pinmux, dif_pinmux_index_t detector,
472 
473 /**
474  * Disables wake-up detection for a particular detector.
475  *
476  * @param pinmux A Pin Multiplexer handle.
477  * @param detector A detector index.
478  * @return The result of the operation.
479  */
482  dif_pinmux_index_t detector);
483 
484 /**
485  * Clears the wake-up cause information.
486  *
487  * @param pinmux A Pin Multiplexer handle.
488  * @return The result of the operation.
489  */
492 
493 /**
494  * Retrieves the detectors that have detected wake-up patterns.
495  *
496  * @param pinmux A Pin Multiplexer handle.
497  * @param detector_map[out] A bit map representing detectors that have detected
498  * wake-up patterns.
499  * @return The result of the operation.
500  */
503  uint32_t *detector_map);
504 
505 #ifdef __cplusplus
506 } // extern "C"
507 #endif // __cplusplus
508 
509 #endif // OPENTITAN_SW_DEVICE_LIB_DIF_DIF_PINMUX_H_