LCOV - code coverage report
Current view: top level - zephyr/drivers/pinctrl - pinctrl_rcar_common.h Coverage Total Hit
Test: new.info Lines: 26.3 % 38 10
Test Date: 2025-09-05 20:47:19

            Line data    Source code
       1            0 : /*
       2              :  * Copyright (c) 2023 IoT.bzh
       3              :  *
       4              :  * SPDX-License-Identifier: Apache-2.0
       5              :  *
       6              :  */
       7              : 
       8              : #ifndef ZEPHYR_SOC_ARM_RENESAS_RCAR_COMMON_PINCTRL_SOC_H_
       9              : #define ZEPHYR_SOC_ARM_RENESAS_RCAR_COMMON_PINCTRL_SOC_H_
      10              : 
      11              : #include <zephyr/devicetree.h>
      12              : #include <zephyr/dt-bindings/pinctrl/renesas/pinctrl-rcar-common.h>
      13              : #include <stdint.h>
      14              : #include <zephyr/sys/util_macro.h>
      15              : 
      16            0 : struct rcar_pin_func {
      17            0 :         uint8_t bank:5;      /* bank number 0 - 18 */
      18            0 :         uint8_t shift:5;     /* bit shift 0 - 28 */
      19            0 :         uint8_t func:4;      /* choice from 0x0 to 0xF */
      20              : };
      21              : 
      22              : /** Pull-up, pull-down, or bias disable is requested */
      23            1 : #define RCAR_PIN_FLAGS_PULL_SET BIT(0)
      24              : /** Performs on/off control of the pull resistors */
      25            1 : #define RCAR_PIN_FLAGS_PUEN     BIT(1)
      26              : /** Select pull-up resistor if set pull-down otherwise */
      27            1 : #define RCAR_PIN_FLAGS_PUD      BIT(2)
      28              : /** Alternate function for the pin is requested */
      29            1 : #define RCAR_PIN_FLAGS_FUNC_SET BIT(3)
      30              : /** Ignore IPSR settings for alternate function pin */
      31            1 : #define RCAR_PIN_FLAGS_FUNC_DUMMY BIT(4)
      32              : 
      33            0 : #define RCAR_PIN_PULL_UP      (RCAR_PIN_FLAGS_PULL_SET | RCAR_PIN_FLAGS_PUEN | RCAR_PIN_FLAGS_PUD)
      34            0 : #define RCAR_PIN_PULL_DOWN    (RCAR_PIN_FLAGS_PULL_SET | RCAR_PIN_FLAGS_PUEN)
      35            0 : #define RCAR_PIN_PULL_DISABLE  RCAR_PIN_FLAGS_PULL_SET
      36              : 
      37              : /** Type for R-Car pin. */
      38            1 : typedef struct pinctrl_soc_pin {
      39            0 :         uint16_t pin;
      40            0 :         struct rcar_pin_func func;
      41            0 :         uint8_t flags;
      42            0 :         uint8_t drive_strength;
      43            0 :         uint8_t voltage;
      44            1 : } pinctrl_soc_pin_t;
      45              : 
      46            0 : #define RCAR_IPSR(node_id) DT_PROP_BY_IDX(node_id, pin, 1)
      47            0 : #define RCAR_HAS_IPSR(node_id) DT_PROP_HAS_IDX(node_id, pin, 1)
      48              : 
      49              : /* Offsets are defined in dt-bindings pinctrl-rcar-common.h */
      50            0 : #define RCAR_PIN_FUNC(node_id)                         \
      51              :         {                                              \
      52              :                 ((RCAR_IPSR(node_id) >> 10U) & 0x1FU), \
      53              :                 ((RCAR_IPSR(node_id) >> 4U) & 0x1FU),  \
      54              :                 ((RCAR_IPSR(node_id) & 0xFU))              \
      55              :         }
      56              : 
      57            0 : #define RCAR_PIN_IS_FUNC_DUMMY(node_id)                                        \
      58              :         ((((RCAR_IPSR(node_id) >> 10U) & 0x1FU) == 0x1F) &&                  \
      59              :          (((RCAR_IPSR(node_id) >> 4U) & 0x1FU) == 0x1F) &&                   \
      60              :          ((RCAR_IPSR(node_id) & 0xFU) == 0xF))
      61              : 
      62            0 : #define RCAR_PIN_FLAGS(node_id)                                                \
      63              :         DT_PROP(node_id, bias_pull_up)   * RCAR_PIN_PULL_UP |                  \
      64              :         DT_PROP(node_id, bias_pull_down) * RCAR_PIN_PULL_DOWN |                \
      65              :         DT_PROP(node_id, bias_disable)   * RCAR_PIN_PULL_DISABLE |             \
      66              :         RCAR_HAS_IPSR(node_id) * RCAR_PIN_FLAGS_FUNC_SET |                     \
      67              :         RCAR_PIN_IS_FUNC_DUMMY(node_id) * RCAR_PIN_FLAGS_FUNC_DUMMY
      68              : 
      69            0 : #define RCAR_DT_PIN(node_id)                                                   \
      70              :         {                                                                      \
      71              :                 .pin = DT_PROP_BY_IDX(node_id, pin, 0),                        \
      72              :                 .func = COND_CODE_1(RCAR_HAS_IPSR(node_id),                    \
      73              :                                     (RCAR_PIN_FUNC(node_id)), {0}),            \
      74              :                 .flags = RCAR_PIN_FLAGS(node_id),                              \
      75              :                 .drive_strength =                                              \
      76              :                         COND_CODE_1(DT_NODE_HAS_PROP(node_id, drive_strength), \
      77              :                                     (DT_PROP(node_id, drive_strength)), (0)),  \
      78              :                 .voltage = COND_CODE_1(DT_NODE_HAS_PROP(node_id,               \
      79              :                                                         power_source),         \
      80              :                                        (DT_PROP(node_id, power_source)),       \
      81              :                                        (PIN_VOLTAGE_NONE)),                    \
      82              :         },
      83              : 
      84              : /**
      85              :  * @brief Utility macro to initialize each pin.
      86              :  *
      87              :  * @param node_id Node identifier.
      88              :  * @param state_prop State property name.
      89              :  * @param idx State property entry index.
      90              :  */
      91              : #define Z_PINCTRL_STATE_PIN_INIT(node_id, state_prop, idx) \
      92              :         RCAR_DT_PIN(DT_PROP_BY_IDX(node_id, state_prop, idx))
      93              : 
      94              : /**
      95              :  * @brief Utility macro to initialize state pins contained in a given property.
      96              :  *
      97              :  * @param node_id Node identifier.
      98              :  * @param prop Property name describing state pins.
      99              :  */
     100              : #define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) \
     101              :         { DT_FOREACH_PROP_ELEM(node_id, prop, Z_PINCTRL_STATE_PIN_INIT) }
     102              : 
     103            0 : struct pfc_drive_reg_field {
     104            0 :         uint16_t pin;
     105            0 :         uint8_t offset;
     106            0 :         uint8_t size;
     107              : };
     108              : 
     109            0 : struct pfc_drive_reg {
     110            0 :         uint32_t reg;
     111            0 :         const struct pfc_drive_reg_field fields[8];
     112              : };
     113              : 
     114            0 : struct pfc_bias_reg {
     115            0 :         uint32_t puen;          /** Pull-enable or pull-up control register */
     116            1 :         uint32_t pud;           /** Pull-up/down or pull-down control register */
     117            1 :         const uint16_t pins[32];
     118              : };
     119              : 
     120              : /**
     121              :  * @brief Utility macro to check if a pin is GPIO capable
     122              :  *
     123              :  * @param pin
     124              :  * @return true if pin is GPIO capable false otherwise
     125              :  */
     126            1 : #define RCAR_IS_GP_PIN(pin) (pin < PIN_NOGPSR_START)
     127              : 
     128              : #endif /* ZEPHYR_SOC_ARM_RENESAS_RCAR_COMMON_PINCTRL_SOC_H_ */
        

Generated by: LCOV version 2.0-1