Skip to content

Commit

Permalink
pinctrl: style: remove trailling whitespaces
Browse files Browse the repository at this point in the history
Signed-off-by: Bill Nguyen <bill.nguyen@student.unsw.edu.au>
  • Loading branch information
dreamliner787-9 committed Sep 27, 2024
1 parent df0e3bf commit 6f6aa73
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 87 deletions.
4 changes: 2 additions & 2 deletions drivers/pinctrl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ Also known as pinmux driver

# Terminology
- Port: refers to an input or output line of a logic instance in the chip (e.g. UART, DDR, HDMI, I2C,...). For example, an I2C instance have SDA and SCL ports. Not to be confused with pad.
- Pad: refers to the physical pin on the chip package (example, ball for BGA packaged chips).
- Pad: refers to the physical pin on the chip package (example, ball for BGA packaged chips).

# Overview
<!-- This paragraph is from Linux documentation -->
A chip contains a limited number of pads as it is not feasable to have a one-to-one mapping between all pads and ports. Hence, most of the pads have multiple signal options. I.e. a pad can be connected to one of multiple ports at a given point in time as appropriate for the intended use case. These signal-to-pin and pin-to-signal options are selected by the input-output multiplexer called pinmux. The pinmux is also used to configure other pin characteristics, such as drive strength, bias, etc...

Even though the pinmux parameters can be set dynamically at runtime, we restrict ourselves to settings that are set in the device tree at compile time and disallow any deviations from that.
Even though the pinmux parameters can be set dynamically at runtime, we restrict ourselves to settings that are set in the device tree at compile time and disallow any deviations from that.

Before the pinmux driver is built, a Python script will read the target board's device tree source file, extracting all the pinmux settings and encodes them as binary values in an assembly file. Then the driver is built and linked with the pinmux data assembly file, creating a complete pinmux driver ELF image.

Expand Down
2 changes: 1 addition & 1 deletion drivers/pinctrl/imx/create_pinctrl_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def get_pinctrl_info(device_nodes, enabled_phandles):
print("Usage: ")
print("\tpython3 create_pinmux_setup.py <SoC-name> <dts-source> <pinmux-device-name> <output-dir>")
exit(1)

# Parse device tree file
soc_name = sys.argv[1]
devicetree = dtlib.DT(sys.argv[2], force=True)
Expand Down
16 changes: 8 additions & 8 deletions drivers/pinctrl/imx/pinctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@

// Size of all registers inclusive
#ifdef SOC_IMX8MQ_EVK
#define IOMUXC_DEVICE_EFFECTIVE_SIZE 0x520
#define IOMUXC_DEVICE_EFFECTIVE_SIZE 0x520
#endif
#ifdef SOC_IMX8MM_EVK
#define IOMUXC_DEVICE_EFFECTIVE_SIZE 0x538
#endif

uintptr_t iomuxc_dev_base;
// The registers are only within iomuxc_dev_base + IOMUXC_DEVICE_BASE_PAD and
// The registers are only within iomuxc_dev_base + IOMUXC_DEVICE_BASE_PAD and
// iomuxc_dev_base + IOMUXC_DEVICE_BASE_PAD + IOMUXC_DEVICE_EFFECTIVE_SIZE

// General Purpose Registers: a memory region contiguous with the iomuxc device.
Expand Down Expand Up @@ -109,7 +109,7 @@ bool read_mux(uint32_t offset, uint32_t *ret) {
if (!check_offset_bound(offset) || !check_offset_4_bytes_aligned(offset)) {
return false;
}

volatile uint32_t *mux_reg_vaddr = (uint32_t *) (iomuxc_dev_base + (uintptr_t) offset);

asm volatile("" : : : "memory");
Expand Down Expand Up @@ -143,9 +143,9 @@ void debug_dts_print() {
LOG_DRIVER("nums of config is %u\n", num_iomuxc_configs);
LOG_DRIVER("data dump begin...one pin per line\n");
for (uint32_t i = 0; i < num_iomuxc_configs; i += 1) {
LOG_DRIVER("mux reg: 0x%x = %u, input reg: 0x%x = %u, pad conf reg: 0x%x = %u. ",
iomuxc_configs[i].mux_reg, iomuxc_configs[i].mux_val,
iomuxc_configs[i].input_reg, iomuxc_configs[i].input_val,
LOG_DRIVER("mux reg: 0x%x = %u, input reg: 0x%x = %u, pad conf reg: 0x%x = %u. ",
iomuxc_configs[i].mux_reg, iomuxc_configs[i].mux_val,
iomuxc_configs[i].input_reg, iomuxc_configs[i].input_val,
iomuxc_configs[i].conf_reg, iomuxc_configs[i].pad_setting
);

Expand Down Expand Up @@ -261,8 +261,8 @@ microkit_msginfo protected(microkit_channel ch, microkit_msginfo msginfo) {
case SDDF_PINCTRL_READ_MUX: {
if (microkit_msginfo_get_count(msginfo) != READ_MUX_REQ_NUM_ARGS) {
LOG_DRIVER_ERR(
"Read mux PPC from channel %u does not have the correct number of arguments %lu != %d\n",
ch,
"Read mux PPC from channel %u does not have the correct number of arguments %lu != %d\n",
ch,
microkit_msginfo_get_count(msginfo), READ_MUX_REQ_NUM_ARGS
);
return microkit_msginfo_new(SDDF_PINCTRL_INVALID_ARGS, 0);
Expand Down
10 changes: 5 additions & 5 deletions drivers/pinctrl/imx/pinctrl_driver.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#
# NOTES
# Generates pinctrl.elf
# Has 4 parameters:
# Has 4 parameters:
# SDDF: path to sddf root
# PYTHON
# DTS_FILE: absolute path to the device tree source file.
Expand All @@ -27,15 +27,15 @@ ifndef PYTHON
$(error PYTHON is not set)
endif

ifndef DTS_FILE
ifndef DTS_FILE
$(error DTS_FILE is not set)
endif

ifndef PINMUX_DEVICE
ifndef PINMUX_DEVICE
$(error PINMUX_DEVICE is not set)
endif

ifndef SOC
ifndef SOC
$(error SOC is not set)
endif

Expand All @@ -62,7 +62,7 @@ pinctrl/pinctrl_config_data.o: pinctrl/pinctrl_config_data.s
pinctrl/pinctrl_config_data.s: ${DTS_FILE} ${PINCTRL_DIR}/create_pinctrl_config.py
${PYTHON} ${PINCTRL_DIR}/create_pinctrl_config.py ${SOC} ${DTS_FILE} ${PINMUX_DEVICE} pinctrl

pinctrl:
pinctrl:
mkdir -p pinctrl

clean::
Expand Down
68 changes: 34 additions & 34 deletions drivers/pinctrl/meson/create_pinctrl_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# $ dtc -I dtb -O dts -o input.dtb output.dts

# A typical invocation might look like:
# $ python3 create_pinctrl_config.py hardkernel,odroid-c4 your_device_tree.dts build
# $ python3 create_pinctrl_config.py hardkernel,odroid-c4 your_device_tree.dts build

import sys
sys.dont_write_bytecode = True
Expand Down Expand Up @@ -67,16 +67,16 @@ def fetch_enabled_devices(devicetree: dtlib.DT) -> dict[int, str]:
# Each pinctrl data node inside the DTS is represented with this class.
# These data are then converted into memory values for writing into pinmux registers.
class PinData:
def __init__(self,
def __init__(self,
phandle: int,
muxed_device_name: str,
muxed_device_property_node_name: str,
group_names: list[str],
function_name: str,
bias_enable: bool,
bias_pullup: bool,
muxed_device_name: str,
muxed_device_property_node_name: str,
group_names: list[str],
function_name: str,
bias_enable: bool,
bias_pullup: bool,
drive_strength: int):

self.phandle = phandle
# for debugging: name of the device in DTS
self.muxed_device_name = muxed_device_name
Expand Down Expand Up @@ -112,7 +112,7 @@ def __str__(self):
# This function extract pinmux data from the "pinctrl" node in DTS and return a list of PinData.
# It will be called twice, once for peripherals and always-on GPIO chips.
# Returns a list of PinData.
def get_pinctrl_data(pinmux_node: dtlib.Node, enabled_phandles: dict[int, str], func_to_group_map: dict[str, list[str]]) -> list[PinData]:
def get_pinctrl_data(pinmux_node: dtlib.Node, enabled_phandles: dict[int, str], func_to_group_map: dict[str, list[str]]) -> list[PinData]:
# `pinmux_node` looks something like this:
# pinctrl@40 {
# compatible = "amlogic,meson-g12a-periphs-pinctrl";
Expand Down Expand Up @@ -160,7 +160,7 @@ def get_pinctrl_data(pinmux_node: dtlib.Node, enabled_phandles: dict[int, str],
for subproperty_name in muxed_device_property_node.props:
if subproperty_name == "groups":
group_names = muxed_device_property_node.props[subproperty_name].to_string().split('\0')

if subproperty_name == "function":
values_list = muxed_device_property_node.props[subproperty_name].to_string().split('\0')
if len(values_list) != 1:
Expand All @@ -170,7 +170,7 @@ def get_pinctrl_data(pinmux_node: dtlib.Node, enabled_phandles: dict[int, str],

# If for whatever reason the device defined in the DTS does not have data in our
# mapping tables, drop it. This can happens for undocumented devices/pads that does not appear
# in the Linux kernel. An example is the DTS from the OdroidC4's Ubuntu image:
# in the Linux kernel. An example is the DTS from the OdroidC4's Ubuntu image:
# ubuntu-20.04-4.9-minimal-odroid-c4-hc4-20220228
# Where the "cec_ao_a_ee" and "cec_ao_b_ee" groups with "cec_ao_ee" function are not defined in the Linux kernel and datasheet at all.
if function_name not in func_to_group_map:
Expand All @@ -184,7 +184,7 @@ def get_pinctrl_data(pinmux_node: dtlib.Node, enabled_phandles: dict[int, str],

if subproperty_name == "drive-strength-microamp":
drive_strength = muxed_device_property_node.props[subproperty_name].to_num()

if bias_enable == -1:
# We haven't encountered the "bias-disable" property
if "bias-pull-up" in muxed_device_property_node.props:
Expand All @@ -197,17 +197,17 @@ def get_pinctrl_data(pinmux_node: dtlib.Node, enabled_phandles: dict[int, str],
# This isn't an error because that pin could be used for input
log_warning_parser("Warning: bias undefined for device: " + muxed_device_node.name + ". Defaulting to disabling bias!\n")
bias_enable = False

if undocumented:
break

result.append(PinData(muxed_device_node.props["phandle"].to_num(),
muxed_device_name,
muxed_device_property_node_name,
group_names,
function_name,
bias_enable,
bias_pullup,
result.append(PinData(muxed_device_node.props["phandle"].to_num(),
muxed_device_name,
muxed_device_property_node_name,
group_names,
function_name,
bias_enable,
bias_pullup,
drive_strength)
)

Expand All @@ -218,17 +218,17 @@ def zero_n_bits_at_ith_bit_of_32bits(register: int, n: int, ith: int) -> int:
if n < 0 or ith < 0 or register > 0xFFFF_FFFF:
log_error_parser(f"invalid arg to zero_n_bits_at_ith_bit: register = {register}, n = {n}, ith = {ith}\n")
exit(1)

mask = 0xFFFF_FFFF
mask = mask >> (ith + n)

for i in range(n):
mask = mask << 1

for i in range(ith):
mask = mask << 1
mask |= 1

result = register & mask
if result > 0xFFFF_FFFF:
log_error_parser(f"bad output zero_n_bits_at_ith_bit_of_32bits(register={hex(register)}, n={n}, ith={ith}) = {hex(result)}")
Expand Down Expand Up @@ -296,7 +296,7 @@ def pindata_to_register_values(

# Fetch the bank value then zero out the bits that belong to this pad
zeroed_regval = zero_n_bits_at_ith_bit_of_32bits(reg["value"], reg["bits_per_pin"], nth_bit)

# Prepare mux setting value to be OR'ed into the zeroed out slot
data_mask = mux_func << nth_bit

Expand Down Expand Up @@ -325,7 +325,7 @@ def pindata_to_register_values(

nth_pin = pad_idx - reg["first_pad"]
nth_bit = nth_pin * reg["bits_per_pin"]

if pindata.bias_enable:
log_normal_parser(f"pad #{pad_idx} have bias enabled, prev reg is {hex(reg["value"])}, ")
data_mask = 1 << nth_bit
Expand All @@ -334,7 +334,7 @@ def pindata_to_register_values(
else:
log_normal_parser(f"pad #{pad_idx} have bias disabled, prev reg is {hex(reg["value"])}, ")
reg["value"] = zero_n_bits_at_ith_bit_of_32bits(reg["value"], reg["bits_per_pin"], nth_bit)

log_normal_parser(f"after reg is {hex(reg["value"])}\n")

if not found:
Expand All @@ -357,9 +357,9 @@ def pindata_to_register_values(
else:
log_normal_parser(f"pad #{pad_idx} have pull down, prev reg is {hex(reg["value"])}, ")
reg["value"] = zero_n_bits_at_ith_bit_of_32bits(reg["value"], reg["bits_per_pin"], nth_bit)

log_normal_parser(f"after reg is {hex(reg["value"])}\n")

if not found:
log_error_parser(f"cannot find the pin bank that the port {port} belongs in for bias direction\n")
exit(1)
Expand All @@ -378,8 +378,8 @@ def pindata_to_register_values(
ds_val = 3
else:
log_error_parser(f"unknown drive strength value of f{pindata.drive_strength} for pad #{pad_idx}\n")
exit(1)
exit(1)

found = False
for reg in ds_registers:
if pad_idx >= reg["first_pad"] and pad_idx <= reg["last_pad"]:
Expand All @@ -390,7 +390,7 @@ def pindata_to_register_values(

# Fetch the bank value then zero out the bits that belong to this pad
zeroed_regval = zero_n_bits_at_ith_bit_of_32bits(reg["value"], reg["bits_per_pin"], nth_bit)

# Prepare mux setting value to be OR'ed into the zeroed out slot
data_mask = ds_val << nth_bit

Expand Down Expand Up @@ -491,13 +491,13 @@ def register_values_to_assembler(out_dir: str, peripherals_data: OrderedDict[int
log_error_parser("Usage: ")
log_error_parser("\tpython3 create_pinmux_setup.py <SoC-name> <dts-source> <output-dir>")
exit(1)

# Parse device tree file
soc_name = sys.argv[1]
devicetree = dtlib.DT(sys.argv[2], force=True)
pinmux_node_name = "pinctrl@"
out_dir = sys.argv[3]

is_dts_compatible(devicetree)

enabled_phandles: dict[int, str] = fetch_enabled_devices(devicetree)
Expand Down
Loading

0 comments on commit 6f6aa73

Please sign in to comment.