162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Renesas RZ/G2L Pin Control and GPIO driver core 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (C) 2021 Renesas Electronics Corporation. 662306a36Sopenharmony_ci */ 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci#include <linux/bitops.h> 962306a36Sopenharmony_ci#include <linux/clk.h> 1062306a36Sopenharmony_ci#include <linux/gpio/driver.h> 1162306a36Sopenharmony_ci#include <linux/interrupt.h> 1262306a36Sopenharmony_ci#include <linux/io.h> 1362306a36Sopenharmony_ci#include <linux/module.h> 1462306a36Sopenharmony_ci#include <linux/mutex.h> 1562306a36Sopenharmony_ci#include <linux/of.h> 1662306a36Sopenharmony_ci#include <linux/of_irq.h> 1762306a36Sopenharmony_ci#include <linux/platform_device.h> 1862306a36Sopenharmony_ci#include <linux/seq_file.h> 1962306a36Sopenharmony_ci#include <linux/spinlock.h> 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci#include <linux/pinctrl/consumer.h> 2262306a36Sopenharmony_ci#include <linux/pinctrl/pinconf-generic.h> 2362306a36Sopenharmony_ci#include <linux/pinctrl/pinconf.h> 2462306a36Sopenharmony_ci#include <linux/pinctrl/pinctrl.h> 2562306a36Sopenharmony_ci#include <linux/pinctrl/pinmux.h> 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci#include <dt-bindings/pinctrl/rzg2l-pinctrl.h> 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci#include "../core.h" 3062306a36Sopenharmony_ci#include "../pinconf.h" 3162306a36Sopenharmony_ci#include "../pinmux.h" 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ci#define DRV_NAME "pinctrl-rzg2l" 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci/* 3662306a36Sopenharmony_ci * Use 16 lower bits [15:0] for pin identifier 3762306a36Sopenharmony_ci * Use 16 higher bits [31:16] for pin mux function 3862306a36Sopenharmony_ci */ 3962306a36Sopenharmony_ci#define MUX_PIN_ID_MASK GENMASK(15, 0) 4062306a36Sopenharmony_ci#define MUX_FUNC_MASK GENMASK(31, 16) 4162306a36Sopenharmony_ci#define MUX_FUNC_OFFS 16 4262306a36Sopenharmony_ci#define MUX_FUNC(pinconf) (((pinconf) & MUX_FUNC_MASK) >> MUX_FUNC_OFFS) 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ci/* PIN capabilities */ 4562306a36Sopenharmony_ci#define PIN_CFG_IOLH_A BIT(0) 4662306a36Sopenharmony_ci#define PIN_CFG_IOLH_B BIT(1) 4762306a36Sopenharmony_ci#define PIN_CFG_SR BIT(2) 4862306a36Sopenharmony_ci#define PIN_CFG_IEN BIT(3) 4962306a36Sopenharmony_ci#define PIN_CFG_PUPD BIT(4) 5062306a36Sopenharmony_ci#define PIN_CFG_IO_VMC_SD0 BIT(5) 5162306a36Sopenharmony_ci#define PIN_CFG_IO_VMC_SD1 BIT(6) 5262306a36Sopenharmony_ci#define PIN_CFG_IO_VMC_QSPI BIT(7) 5362306a36Sopenharmony_ci#define PIN_CFG_IO_VMC_ETH0 BIT(8) 5462306a36Sopenharmony_ci#define PIN_CFG_IO_VMC_ETH1 BIT(9) 5562306a36Sopenharmony_ci#define PIN_CFG_FILONOFF BIT(10) 5662306a36Sopenharmony_ci#define PIN_CFG_FILNUM BIT(11) 5762306a36Sopenharmony_ci#define PIN_CFG_FILCLKSEL BIT(12) 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci#define RZG2L_MPXED_PIN_FUNCS (PIN_CFG_IOLH_A | \ 6062306a36Sopenharmony_ci PIN_CFG_SR | \ 6162306a36Sopenharmony_ci PIN_CFG_PUPD | \ 6262306a36Sopenharmony_ci PIN_CFG_FILONOFF | \ 6362306a36Sopenharmony_ci PIN_CFG_FILNUM | \ 6462306a36Sopenharmony_ci PIN_CFG_FILCLKSEL) 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci#define RZG2L_MPXED_ETH_PIN_FUNCS(x) ((x) | \ 6762306a36Sopenharmony_ci PIN_CFG_FILONOFF | \ 6862306a36Sopenharmony_ci PIN_CFG_FILNUM | \ 6962306a36Sopenharmony_ci PIN_CFG_FILCLKSEL) 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ci/* 7262306a36Sopenharmony_ci * n indicates number of pins in the port, a is the register index 7362306a36Sopenharmony_ci * and f is pin configuration capabilities supported. 7462306a36Sopenharmony_ci */ 7562306a36Sopenharmony_ci#define RZG2L_GPIO_PORT_PACK(n, a, f) (((n) << 28) | ((a) << 20) | (f)) 7662306a36Sopenharmony_ci#define RZG2L_GPIO_PORT_GET_PINCNT(x) (((x) & GENMASK(30, 28)) >> 28) 7762306a36Sopenharmony_ci#define RZG2L_GPIO_PORT_GET_INDEX(x) (((x) & GENMASK(26, 20)) >> 20) 7862306a36Sopenharmony_ci#define RZG2L_GPIO_PORT_GET_CFGS(x) ((x) & GENMASK(19, 0)) 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ci/* 8162306a36Sopenharmony_ci * BIT(31) indicates dedicated pin, p is the register index while 8262306a36Sopenharmony_ci * referencing to SR/IEN/IOLH/FILxx registers, b is the register bits 8362306a36Sopenharmony_ci * (b * 8) and f is the pin configuration capabilities supported. 8462306a36Sopenharmony_ci */ 8562306a36Sopenharmony_ci#define RZG2L_SINGLE_PIN BIT(31) 8662306a36Sopenharmony_ci#define RZG2L_SINGLE_PIN_PACK(p, b, f) (RZG2L_SINGLE_PIN | \ 8762306a36Sopenharmony_ci ((p) << 24) | ((b) << 20) | (f)) 8862306a36Sopenharmony_ci#define RZG2L_SINGLE_PIN_GET_PORT_OFFSET(x) (((x) & GENMASK(30, 24)) >> 24) 8962306a36Sopenharmony_ci#define RZG2L_SINGLE_PIN_GET_BIT(x) (((x) & GENMASK(22, 20)) >> 20) 9062306a36Sopenharmony_ci#define RZG2L_SINGLE_PIN_GET_CFGS(x) ((x) & GENMASK(19, 0)) 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ci#define P(n) (0x0000 + 0x10 + (n)) 9362306a36Sopenharmony_ci#define PM(n) (0x0100 + 0x20 + (n) * 2) 9462306a36Sopenharmony_ci#define PMC(n) (0x0200 + 0x10 + (n)) 9562306a36Sopenharmony_ci#define PFC(n) (0x0400 + 0x40 + (n) * 4) 9662306a36Sopenharmony_ci#define PIN(n) (0x0800 + 0x10 + (n)) 9762306a36Sopenharmony_ci#define IOLH(n) (0x1000 + (n) * 8) 9862306a36Sopenharmony_ci#define IEN(n) (0x1800 + (n) * 8) 9962306a36Sopenharmony_ci#define ISEL(n) (0x2c80 + (n) * 8) 10062306a36Sopenharmony_ci#define PWPR (0x3014) 10162306a36Sopenharmony_ci#define SD_CH(n) (0x3000 + (n) * 4) 10262306a36Sopenharmony_ci#define QSPI (0x3008) 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_ci#define PVDD_1800 1 /* I/O domain voltage <= 1.8V */ 10562306a36Sopenharmony_ci#define PVDD_3300 0 /* I/O domain voltage >= 3.3V */ 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci#define PWPR_B0WI BIT(7) /* Bit Write Disable */ 10862306a36Sopenharmony_ci#define PWPR_PFCWE BIT(6) /* PFC Register Write Enable */ 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ci#define PM_MASK 0x03 11162306a36Sopenharmony_ci#define PVDD_MASK 0x01 11262306a36Sopenharmony_ci#define PFC_MASK 0x07 11362306a36Sopenharmony_ci#define IEN_MASK 0x01 11462306a36Sopenharmony_ci#define IOLH_MASK 0x03 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ci#define PM_INPUT 0x1 11762306a36Sopenharmony_ci#define PM_OUTPUT 0x2 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_ci#define RZG2L_PIN_ID_TO_PORT(id) ((id) / RZG2L_PINS_PER_PORT) 12062306a36Sopenharmony_ci#define RZG2L_PIN_ID_TO_PORT_OFFSET(id) (RZG2L_PIN_ID_TO_PORT(id) + 0x10) 12162306a36Sopenharmony_ci#define RZG2L_PIN_ID_TO_PIN(id) ((id) % RZG2L_PINS_PER_PORT) 12262306a36Sopenharmony_ci 12362306a36Sopenharmony_ci#define RZG2L_TINT_MAX_INTERRUPT 32 12462306a36Sopenharmony_ci#define RZG2L_TINT_IRQ_START_INDEX 9 12562306a36Sopenharmony_ci#define RZG2L_PACK_HWIRQ(t, i) (((t) << 16) | (i)) 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_cistruct rzg2l_dedicated_configs { 12862306a36Sopenharmony_ci const char *name; 12962306a36Sopenharmony_ci u32 config; 13062306a36Sopenharmony_ci}; 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_cistruct rzg2l_pinctrl_data { 13362306a36Sopenharmony_ci const char * const *port_pins; 13462306a36Sopenharmony_ci const u32 *port_pin_configs; 13562306a36Sopenharmony_ci unsigned int n_ports; 13662306a36Sopenharmony_ci struct rzg2l_dedicated_configs *dedicated_pins; 13762306a36Sopenharmony_ci unsigned int n_port_pins; 13862306a36Sopenharmony_ci unsigned int n_dedicated_pins; 13962306a36Sopenharmony_ci}; 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_cistruct rzg2l_pinctrl { 14262306a36Sopenharmony_ci struct pinctrl_dev *pctl; 14362306a36Sopenharmony_ci struct pinctrl_desc desc; 14462306a36Sopenharmony_ci struct pinctrl_pin_desc *pins; 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_ci const struct rzg2l_pinctrl_data *data; 14762306a36Sopenharmony_ci void __iomem *base; 14862306a36Sopenharmony_ci struct device *dev; 14962306a36Sopenharmony_ci 15062306a36Sopenharmony_ci struct gpio_chip gpio_chip; 15162306a36Sopenharmony_ci struct pinctrl_gpio_range gpio_range; 15262306a36Sopenharmony_ci DECLARE_BITMAP(tint_slot, RZG2L_TINT_MAX_INTERRUPT); 15362306a36Sopenharmony_ci spinlock_t bitmap_lock; /* protect tint_slot bitmap */ 15462306a36Sopenharmony_ci unsigned int hwirq[RZG2L_TINT_MAX_INTERRUPT]; 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_ci spinlock_t lock; /* lock read/write registers */ 15762306a36Sopenharmony_ci struct mutex mutex; /* serialize adding groups and functions */ 15862306a36Sopenharmony_ci}; 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_cistatic const unsigned int iolh_groupa_mA[] = { 2, 4, 8, 12 }; 16162306a36Sopenharmony_cistatic const unsigned int iolh_groupb_oi[] = { 100, 66, 50, 33 }; 16262306a36Sopenharmony_ci 16362306a36Sopenharmony_cistatic void rzg2l_pinctrl_set_pfc_mode(struct rzg2l_pinctrl *pctrl, 16462306a36Sopenharmony_ci u8 port, u8 pin, u8 func) 16562306a36Sopenharmony_ci{ 16662306a36Sopenharmony_ci unsigned long flags; 16762306a36Sopenharmony_ci u32 reg; 16862306a36Sopenharmony_ci 16962306a36Sopenharmony_ci spin_lock_irqsave(&pctrl->lock, flags); 17062306a36Sopenharmony_ci 17162306a36Sopenharmony_ci /* Set pin to 'Non-use (Hi-Z input protection)' */ 17262306a36Sopenharmony_ci reg = readw(pctrl->base + PM(port)); 17362306a36Sopenharmony_ci reg &= ~(PM_MASK << (pin * 2)); 17462306a36Sopenharmony_ci writew(reg, pctrl->base + PM(port)); 17562306a36Sopenharmony_ci 17662306a36Sopenharmony_ci /* Temporarily switch to GPIO mode with PMC register */ 17762306a36Sopenharmony_ci reg = readb(pctrl->base + PMC(port)); 17862306a36Sopenharmony_ci writeb(reg & ~BIT(pin), pctrl->base + PMC(port)); 17962306a36Sopenharmony_ci 18062306a36Sopenharmony_ci /* Set the PWPR register to allow PFC register to write */ 18162306a36Sopenharmony_ci writel(0x0, pctrl->base + PWPR); /* B0WI=0, PFCWE=0 */ 18262306a36Sopenharmony_ci writel(PWPR_PFCWE, pctrl->base + PWPR); /* B0WI=0, PFCWE=1 */ 18362306a36Sopenharmony_ci 18462306a36Sopenharmony_ci /* Select Pin function mode with PFC register */ 18562306a36Sopenharmony_ci reg = readl(pctrl->base + PFC(port)); 18662306a36Sopenharmony_ci reg &= ~(PFC_MASK << (pin * 4)); 18762306a36Sopenharmony_ci writel(reg | (func << (pin * 4)), pctrl->base + PFC(port)); 18862306a36Sopenharmony_ci 18962306a36Sopenharmony_ci /* Set the PWPR register to be write-protected */ 19062306a36Sopenharmony_ci writel(0x0, pctrl->base + PWPR); /* B0WI=0, PFCWE=0 */ 19162306a36Sopenharmony_ci writel(PWPR_B0WI, pctrl->base + PWPR); /* B0WI=1, PFCWE=0 */ 19262306a36Sopenharmony_ci 19362306a36Sopenharmony_ci /* Switch to Peripheral pin function with PMC register */ 19462306a36Sopenharmony_ci reg = readb(pctrl->base + PMC(port)); 19562306a36Sopenharmony_ci writeb(reg | BIT(pin), pctrl->base + PMC(port)); 19662306a36Sopenharmony_ci 19762306a36Sopenharmony_ci spin_unlock_irqrestore(&pctrl->lock, flags); 19862306a36Sopenharmony_ci}; 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_cistatic int rzg2l_pinctrl_set_mux(struct pinctrl_dev *pctldev, 20162306a36Sopenharmony_ci unsigned int func_selector, 20262306a36Sopenharmony_ci unsigned int group_selector) 20362306a36Sopenharmony_ci{ 20462306a36Sopenharmony_ci struct rzg2l_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 20562306a36Sopenharmony_ci struct function_desc *func; 20662306a36Sopenharmony_ci unsigned int i, *psel_val; 20762306a36Sopenharmony_ci struct group_desc *group; 20862306a36Sopenharmony_ci int *pins; 20962306a36Sopenharmony_ci 21062306a36Sopenharmony_ci func = pinmux_generic_get_function(pctldev, func_selector); 21162306a36Sopenharmony_ci if (!func) 21262306a36Sopenharmony_ci return -EINVAL; 21362306a36Sopenharmony_ci group = pinctrl_generic_get_group(pctldev, group_selector); 21462306a36Sopenharmony_ci if (!group) 21562306a36Sopenharmony_ci return -EINVAL; 21662306a36Sopenharmony_ci 21762306a36Sopenharmony_ci psel_val = func->data; 21862306a36Sopenharmony_ci pins = group->pins; 21962306a36Sopenharmony_ci 22062306a36Sopenharmony_ci for (i = 0; i < group->num_pins; i++) { 22162306a36Sopenharmony_ci dev_dbg(pctrl->dev, "port:%u pin: %u PSEL:%u\n", 22262306a36Sopenharmony_ci RZG2L_PIN_ID_TO_PORT(pins[i]), RZG2L_PIN_ID_TO_PIN(pins[i]), 22362306a36Sopenharmony_ci psel_val[i]); 22462306a36Sopenharmony_ci rzg2l_pinctrl_set_pfc_mode(pctrl, RZG2L_PIN_ID_TO_PORT(pins[i]), 22562306a36Sopenharmony_ci RZG2L_PIN_ID_TO_PIN(pins[i]), psel_val[i]); 22662306a36Sopenharmony_ci } 22762306a36Sopenharmony_ci 22862306a36Sopenharmony_ci return 0; 22962306a36Sopenharmony_ci}; 23062306a36Sopenharmony_ci 23162306a36Sopenharmony_cistatic int rzg2l_map_add_config(struct pinctrl_map *map, 23262306a36Sopenharmony_ci const char *group_or_pin, 23362306a36Sopenharmony_ci enum pinctrl_map_type type, 23462306a36Sopenharmony_ci unsigned long *configs, 23562306a36Sopenharmony_ci unsigned int num_configs) 23662306a36Sopenharmony_ci{ 23762306a36Sopenharmony_ci unsigned long *cfgs; 23862306a36Sopenharmony_ci 23962306a36Sopenharmony_ci cfgs = kmemdup(configs, num_configs * sizeof(*cfgs), 24062306a36Sopenharmony_ci GFP_KERNEL); 24162306a36Sopenharmony_ci if (!cfgs) 24262306a36Sopenharmony_ci return -ENOMEM; 24362306a36Sopenharmony_ci 24462306a36Sopenharmony_ci map->type = type; 24562306a36Sopenharmony_ci map->data.configs.group_or_pin = group_or_pin; 24662306a36Sopenharmony_ci map->data.configs.configs = cfgs; 24762306a36Sopenharmony_ci map->data.configs.num_configs = num_configs; 24862306a36Sopenharmony_ci 24962306a36Sopenharmony_ci return 0; 25062306a36Sopenharmony_ci} 25162306a36Sopenharmony_ci 25262306a36Sopenharmony_cistatic int rzg2l_dt_subnode_to_map(struct pinctrl_dev *pctldev, 25362306a36Sopenharmony_ci struct device_node *np, 25462306a36Sopenharmony_ci struct device_node *parent, 25562306a36Sopenharmony_ci struct pinctrl_map **map, 25662306a36Sopenharmony_ci unsigned int *num_maps, 25762306a36Sopenharmony_ci unsigned int *index) 25862306a36Sopenharmony_ci{ 25962306a36Sopenharmony_ci struct rzg2l_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 26062306a36Sopenharmony_ci struct pinctrl_map *maps = *map; 26162306a36Sopenharmony_ci unsigned int nmaps = *num_maps; 26262306a36Sopenharmony_ci unsigned long *configs = NULL; 26362306a36Sopenharmony_ci unsigned int *pins, *psel_val; 26462306a36Sopenharmony_ci unsigned int num_pinmux = 0; 26562306a36Sopenharmony_ci unsigned int idx = *index; 26662306a36Sopenharmony_ci unsigned int num_pins, i; 26762306a36Sopenharmony_ci unsigned int num_configs; 26862306a36Sopenharmony_ci struct property *pinmux; 26962306a36Sopenharmony_ci struct property *prop; 27062306a36Sopenharmony_ci int ret, gsel, fsel; 27162306a36Sopenharmony_ci const char **pin_fn; 27262306a36Sopenharmony_ci const char *name; 27362306a36Sopenharmony_ci const char *pin; 27462306a36Sopenharmony_ci 27562306a36Sopenharmony_ci pinmux = of_find_property(np, "pinmux", NULL); 27662306a36Sopenharmony_ci if (pinmux) 27762306a36Sopenharmony_ci num_pinmux = pinmux->length / sizeof(u32); 27862306a36Sopenharmony_ci 27962306a36Sopenharmony_ci ret = of_property_count_strings(np, "pins"); 28062306a36Sopenharmony_ci if (ret == -EINVAL) { 28162306a36Sopenharmony_ci num_pins = 0; 28262306a36Sopenharmony_ci } else if (ret < 0) { 28362306a36Sopenharmony_ci dev_err(pctrl->dev, "Invalid pins list in DT\n"); 28462306a36Sopenharmony_ci return ret; 28562306a36Sopenharmony_ci } else { 28662306a36Sopenharmony_ci num_pins = ret; 28762306a36Sopenharmony_ci } 28862306a36Sopenharmony_ci 28962306a36Sopenharmony_ci if (!num_pinmux && !num_pins) 29062306a36Sopenharmony_ci return 0; 29162306a36Sopenharmony_ci 29262306a36Sopenharmony_ci if (num_pinmux && num_pins) { 29362306a36Sopenharmony_ci dev_err(pctrl->dev, 29462306a36Sopenharmony_ci "DT node must contain either a pinmux or pins and not both\n"); 29562306a36Sopenharmony_ci return -EINVAL; 29662306a36Sopenharmony_ci } 29762306a36Sopenharmony_ci 29862306a36Sopenharmony_ci ret = pinconf_generic_parse_dt_config(np, NULL, &configs, &num_configs); 29962306a36Sopenharmony_ci if (ret < 0) 30062306a36Sopenharmony_ci return ret; 30162306a36Sopenharmony_ci 30262306a36Sopenharmony_ci if (num_pins && !num_configs) { 30362306a36Sopenharmony_ci dev_err(pctrl->dev, "DT node must contain a config\n"); 30462306a36Sopenharmony_ci ret = -ENODEV; 30562306a36Sopenharmony_ci goto done; 30662306a36Sopenharmony_ci } 30762306a36Sopenharmony_ci 30862306a36Sopenharmony_ci if (num_pinmux) 30962306a36Sopenharmony_ci nmaps += 1; 31062306a36Sopenharmony_ci 31162306a36Sopenharmony_ci if (num_pins) 31262306a36Sopenharmony_ci nmaps += num_pins; 31362306a36Sopenharmony_ci 31462306a36Sopenharmony_ci maps = krealloc_array(maps, nmaps, sizeof(*maps), GFP_KERNEL); 31562306a36Sopenharmony_ci if (!maps) { 31662306a36Sopenharmony_ci ret = -ENOMEM; 31762306a36Sopenharmony_ci goto done; 31862306a36Sopenharmony_ci } 31962306a36Sopenharmony_ci 32062306a36Sopenharmony_ci *map = maps; 32162306a36Sopenharmony_ci *num_maps = nmaps; 32262306a36Sopenharmony_ci if (num_pins) { 32362306a36Sopenharmony_ci of_property_for_each_string(np, "pins", prop, pin) { 32462306a36Sopenharmony_ci ret = rzg2l_map_add_config(&maps[idx], pin, 32562306a36Sopenharmony_ci PIN_MAP_TYPE_CONFIGS_PIN, 32662306a36Sopenharmony_ci configs, num_configs); 32762306a36Sopenharmony_ci if (ret < 0) 32862306a36Sopenharmony_ci goto done; 32962306a36Sopenharmony_ci 33062306a36Sopenharmony_ci idx++; 33162306a36Sopenharmony_ci } 33262306a36Sopenharmony_ci ret = 0; 33362306a36Sopenharmony_ci goto done; 33462306a36Sopenharmony_ci } 33562306a36Sopenharmony_ci 33662306a36Sopenharmony_ci pins = devm_kcalloc(pctrl->dev, num_pinmux, sizeof(*pins), GFP_KERNEL); 33762306a36Sopenharmony_ci psel_val = devm_kcalloc(pctrl->dev, num_pinmux, sizeof(*psel_val), 33862306a36Sopenharmony_ci GFP_KERNEL); 33962306a36Sopenharmony_ci pin_fn = devm_kzalloc(pctrl->dev, sizeof(*pin_fn), GFP_KERNEL); 34062306a36Sopenharmony_ci if (!pins || !psel_val || !pin_fn) { 34162306a36Sopenharmony_ci ret = -ENOMEM; 34262306a36Sopenharmony_ci goto done; 34362306a36Sopenharmony_ci } 34462306a36Sopenharmony_ci 34562306a36Sopenharmony_ci /* Collect pin locations and mux settings from DT properties */ 34662306a36Sopenharmony_ci for (i = 0; i < num_pinmux; ++i) { 34762306a36Sopenharmony_ci u32 value; 34862306a36Sopenharmony_ci 34962306a36Sopenharmony_ci ret = of_property_read_u32_index(np, "pinmux", i, &value); 35062306a36Sopenharmony_ci if (ret) 35162306a36Sopenharmony_ci goto done; 35262306a36Sopenharmony_ci pins[i] = value & MUX_PIN_ID_MASK; 35362306a36Sopenharmony_ci psel_val[i] = MUX_FUNC(value); 35462306a36Sopenharmony_ci } 35562306a36Sopenharmony_ci 35662306a36Sopenharmony_ci if (parent) { 35762306a36Sopenharmony_ci name = devm_kasprintf(pctrl->dev, GFP_KERNEL, "%pOFn.%pOFn", 35862306a36Sopenharmony_ci parent, np); 35962306a36Sopenharmony_ci if (!name) { 36062306a36Sopenharmony_ci ret = -ENOMEM; 36162306a36Sopenharmony_ci goto done; 36262306a36Sopenharmony_ci } 36362306a36Sopenharmony_ci } else { 36462306a36Sopenharmony_ci name = np->name; 36562306a36Sopenharmony_ci } 36662306a36Sopenharmony_ci 36762306a36Sopenharmony_ci mutex_lock(&pctrl->mutex); 36862306a36Sopenharmony_ci 36962306a36Sopenharmony_ci /* Register a single pin group listing all the pins we read from DT */ 37062306a36Sopenharmony_ci gsel = pinctrl_generic_add_group(pctldev, name, pins, num_pinmux, NULL); 37162306a36Sopenharmony_ci if (gsel < 0) { 37262306a36Sopenharmony_ci ret = gsel; 37362306a36Sopenharmony_ci goto unlock; 37462306a36Sopenharmony_ci } 37562306a36Sopenharmony_ci 37662306a36Sopenharmony_ci /* 37762306a36Sopenharmony_ci * Register a single group function where the 'data' is an array PSEL 37862306a36Sopenharmony_ci * register values read from DT. 37962306a36Sopenharmony_ci */ 38062306a36Sopenharmony_ci pin_fn[0] = name; 38162306a36Sopenharmony_ci fsel = pinmux_generic_add_function(pctldev, name, pin_fn, 1, psel_val); 38262306a36Sopenharmony_ci if (fsel < 0) { 38362306a36Sopenharmony_ci ret = fsel; 38462306a36Sopenharmony_ci goto remove_group; 38562306a36Sopenharmony_ci } 38662306a36Sopenharmony_ci 38762306a36Sopenharmony_ci mutex_unlock(&pctrl->mutex); 38862306a36Sopenharmony_ci 38962306a36Sopenharmony_ci maps[idx].type = PIN_MAP_TYPE_MUX_GROUP; 39062306a36Sopenharmony_ci maps[idx].data.mux.group = name; 39162306a36Sopenharmony_ci maps[idx].data.mux.function = name; 39262306a36Sopenharmony_ci idx++; 39362306a36Sopenharmony_ci 39462306a36Sopenharmony_ci dev_dbg(pctrl->dev, "Parsed %pOF with %d pins\n", np, num_pinmux); 39562306a36Sopenharmony_ci ret = 0; 39662306a36Sopenharmony_ci goto done; 39762306a36Sopenharmony_ci 39862306a36Sopenharmony_ciremove_group: 39962306a36Sopenharmony_ci pinctrl_generic_remove_group(pctldev, gsel); 40062306a36Sopenharmony_ciunlock: 40162306a36Sopenharmony_ci mutex_unlock(&pctrl->mutex); 40262306a36Sopenharmony_cidone: 40362306a36Sopenharmony_ci *index = idx; 40462306a36Sopenharmony_ci kfree(configs); 40562306a36Sopenharmony_ci return ret; 40662306a36Sopenharmony_ci} 40762306a36Sopenharmony_ci 40862306a36Sopenharmony_cistatic void rzg2l_dt_free_map(struct pinctrl_dev *pctldev, 40962306a36Sopenharmony_ci struct pinctrl_map *map, 41062306a36Sopenharmony_ci unsigned int num_maps) 41162306a36Sopenharmony_ci{ 41262306a36Sopenharmony_ci unsigned int i; 41362306a36Sopenharmony_ci 41462306a36Sopenharmony_ci if (!map) 41562306a36Sopenharmony_ci return; 41662306a36Sopenharmony_ci 41762306a36Sopenharmony_ci for (i = 0; i < num_maps; ++i) { 41862306a36Sopenharmony_ci if (map[i].type == PIN_MAP_TYPE_CONFIGS_GROUP || 41962306a36Sopenharmony_ci map[i].type == PIN_MAP_TYPE_CONFIGS_PIN) 42062306a36Sopenharmony_ci kfree(map[i].data.configs.configs); 42162306a36Sopenharmony_ci } 42262306a36Sopenharmony_ci kfree(map); 42362306a36Sopenharmony_ci} 42462306a36Sopenharmony_ci 42562306a36Sopenharmony_cistatic int rzg2l_dt_node_to_map(struct pinctrl_dev *pctldev, 42662306a36Sopenharmony_ci struct device_node *np, 42762306a36Sopenharmony_ci struct pinctrl_map **map, 42862306a36Sopenharmony_ci unsigned int *num_maps) 42962306a36Sopenharmony_ci{ 43062306a36Sopenharmony_ci struct rzg2l_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 43162306a36Sopenharmony_ci struct device_node *child; 43262306a36Sopenharmony_ci unsigned int index; 43362306a36Sopenharmony_ci int ret; 43462306a36Sopenharmony_ci 43562306a36Sopenharmony_ci *map = NULL; 43662306a36Sopenharmony_ci *num_maps = 0; 43762306a36Sopenharmony_ci index = 0; 43862306a36Sopenharmony_ci 43962306a36Sopenharmony_ci for_each_child_of_node(np, child) { 44062306a36Sopenharmony_ci ret = rzg2l_dt_subnode_to_map(pctldev, child, np, map, 44162306a36Sopenharmony_ci num_maps, &index); 44262306a36Sopenharmony_ci if (ret < 0) { 44362306a36Sopenharmony_ci of_node_put(child); 44462306a36Sopenharmony_ci goto done; 44562306a36Sopenharmony_ci } 44662306a36Sopenharmony_ci } 44762306a36Sopenharmony_ci 44862306a36Sopenharmony_ci if (*num_maps == 0) { 44962306a36Sopenharmony_ci ret = rzg2l_dt_subnode_to_map(pctldev, np, NULL, map, 45062306a36Sopenharmony_ci num_maps, &index); 45162306a36Sopenharmony_ci if (ret < 0) 45262306a36Sopenharmony_ci goto done; 45362306a36Sopenharmony_ci } 45462306a36Sopenharmony_ci 45562306a36Sopenharmony_ci if (*num_maps) 45662306a36Sopenharmony_ci return 0; 45762306a36Sopenharmony_ci 45862306a36Sopenharmony_ci dev_err(pctrl->dev, "no mapping found in node %pOF\n", np); 45962306a36Sopenharmony_ci ret = -EINVAL; 46062306a36Sopenharmony_ci 46162306a36Sopenharmony_cidone: 46262306a36Sopenharmony_ci rzg2l_dt_free_map(pctldev, *map, *num_maps); 46362306a36Sopenharmony_ci 46462306a36Sopenharmony_ci return ret; 46562306a36Sopenharmony_ci} 46662306a36Sopenharmony_ci 46762306a36Sopenharmony_cistatic int rzg2l_validate_gpio_pin(struct rzg2l_pinctrl *pctrl, 46862306a36Sopenharmony_ci u32 cfg, u32 port, u8 bit) 46962306a36Sopenharmony_ci{ 47062306a36Sopenharmony_ci u8 pincount = RZG2L_GPIO_PORT_GET_PINCNT(cfg); 47162306a36Sopenharmony_ci u32 port_index = RZG2L_GPIO_PORT_GET_INDEX(cfg); 47262306a36Sopenharmony_ci u32 data; 47362306a36Sopenharmony_ci 47462306a36Sopenharmony_ci if (bit >= pincount || port >= pctrl->data->n_port_pins) 47562306a36Sopenharmony_ci return -EINVAL; 47662306a36Sopenharmony_ci 47762306a36Sopenharmony_ci data = pctrl->data->port_pin_configs[port]; 47862306a36Sopenharmony_ci if (port_index != RZG2L_GPIO_PORT_GET_INDEX(data)) 47962306a36Sopenharmony_ci return -EINVAL; 48062306a36Sopenharmony_ci 48162306a36Sopenharmony_ci return 0; 48262306a36Sopenharmony_ci} 48362306a36Sopenharmony_ci 48462306a36Sopenharmony_cistatic u32 rzg2l_read_pin_config(struct rzg2l_pinctrl *pctrl, u32 offset, 48562306a36Sopenharmony_ci u8 bit, u32 mask) 48662306a36Sopenharmony_ci{ 48762306a36Sopenharmony_ci void __iomem *addr = pctrl->base + offset; 48862306a36Sopenharmony_ci 48962306a36Sopenharmony_ci /* handle _L/_H for 32-bit register read/write */ 49062306a36Sopenharmony_ci if (bit >= 4) { 49162306a36Sopenharmony_ci bit -= 4; 49262306a36Sopenharmony_ci addr += 4; 49362306a36Sopenharmony_ci } 49462306a36Sopenharmony_ci 49562306a36Sopenharmony_ci return (readl(addr) >> (bit * 8)) & mask; 49662306a36Sopenharmony_ci} 49762306a36Sopenharmony_ci 49862306a36Sopenharmony_cistatic void rzg2l_rmw_pin_config(struct rzg2l_pinctrl *pctrl, u32 offset, 49962306a36Sopenharmony_ci u8 bit, u32 mask, u32 val) 50062306a36Sopenharmony_ci{ 50162306a36Sopenharmony_ci void __iomem *addr = pctrl->base + offset; 50262306a36Sopenharmony_ci unsigned long flags; 50362306a36Sopenharmony_ci u32 reg; 50462306a36Sopenharmony_ci 50562306a36Sopenharmony_ci /* handle _L/_H for 32-bit register read/write */ 50662306a36Sopenharmony_ci if (bit >= 4) { 50762306a36Sopenharmony_ci bit -= 4; 50862306a36Sopenharmony_ci addr += 4; 50962306a36Sopenharmony_ci } 51062306a36Sopenharmony_ci 51162306a36Sopenharmony_ci spin_lock_irqsave(&pctrl->lock, flags); 51262306a36Sopenharmony_ci reg = readl(addr) & ~(mask << (bit * 8)); 51362306a36Sopenharmony_ci writel(reg | (val << (bit * 8)), addr); 51462306a36Sopenharmony_ci spin_unlock_irqrestore(&pctrl->lock, flags); 51562306a36Sopenharmony_ci} 51662306a36Sopenharmony_ci 51762306a36Sopenharmony_cistatic int rzg2l_pinctrl_pinconf_get(struct pinctrl_dev *pctldev, 51862306a36Sopenharmony_ci unsigned int _pin, 51962306a36Sopenharmony_ci unsigned long *config) 52062306a36Sopenharmony_ci{ 52162306a36Sopenharmony_ci struct rzg2l_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 52262306a36Sopenharmony_ci enum pin_config_param param = pinconf_to_config_param(*config); 52362306a36Sopenharmony_ci const struct pinctrl_pin_desc *pin = &pctrl->desc.pins[_pin]; 52462306a36Sopenharmony_ci unsigned int *pin_data = pin->drv_data; 52562306a36Sopenharmony_ci unsigned int arg = 0; 52662306a36Sopenharmony_ci unsigned long flags; 52762306a36Sopenharmony_ci void __iomem *addr; 52862306a36Sopenharmony_ci u32 port_offset; 52962306a36Sopenharmony_ci u32 cfg = 0; 53062306a36Sopenharmony_ci u8 bit = 0; 53162306a36Sopenharmony_ci 53262306a36Sopenharmony_ci if (!pin_data) 53362306a36Sopenharmony_ci return -EINVAL; 53462306a36Sopenharmony_ci 53562306a36Sopenharmony_ci if (*pin_data & RZG2L_SINGLE_PIN) { 53662306a36Sopenharmony_ci port_offset = RZG2L_SINGLE_PIN_GET_PORT_OFFSET(*pin_data); 53762306a36Sopenharmony_ci cfg = RZG2L_SINGLE_PIN_GET_CFGS(*pin_data); 53862306a36Sopenharmony_ci bit = RZG2L_SINGLE_PIN_GET_BIT(*pin_data); 53962306a36Sopenharmony_ci } else { 54062306a36Sopenharmony_ci cfg = RZG2L_GPIO_PORT_GET_CFGS(*pin_data); 54162306a36Sopenharmony_ci port_offset = RZG2L_PIN_ID_TO_PORT_OFFSET(_pin); 54262306a36Sopenharmony_ci bit = RZG2L_PIN_ID_TO_PIN(_pin); 54362306a36Sopenharmony_ci 54462306a36Sopenharmony_ci if (rzg2l_validate_gpio_pin(pctrl, *pin_data, RZG2L_PIN_ID_TO_PORT(_pin), bit)) 54562306a36Sopenharmony_ci return -EINVAL; 54662306a36Sopenharmony_ci } 54762306a36Sopenharmony_ci 54862306a36Sopenharmony_ci switch (param) { 54962306a36Sopenharmony_ci case PIN_CONFIG_INPUT_ENABLE: 55062306a36Sopenharmony_ci if (!(cfg & PIN_CFG_IEN)) 55162306a36Sopenharmony_ci return -EINVAL; 55262306a36Sopenharmony_ci arg = rzg2l_read_pin_config(pctrl, IEN(port_offset), bit, IEN_MASK); 55362306a36Sopenharmony_ci if (!arg) 55462306a36Sopenharmony_ci return -EINVAL; 55562306a36Sopenharmony_ci break; 55662306a36Sopenharmony_ci 55762306a36Sopenharmony_ci case PIN_CONFIG_POWER_SOURCE: { 55862306a36Sopenharmony_ci u32 pwr_reg = 0x0; 55962306a36Sopenharmony_ci 56062306a36Sopenharmony_ci if (cfg & PIN_CFG_IO_VMC_SD0) 56162306a36Sopenharmony_ci pwr_reg = SD_CH(0); 56262306a36Sopenharmony_ci else if (cfg & PIN_CFG_IO_VMC_SD1) 56362306a36Sopenharmony_ci pwr_reg = SD_CH(1); 56462306a36Sopenharmony_ci else if (cfg & PIN_CFG_IO_VMC_QSPI) 56562306a36Sopenharmony_ci pwr_reg = QSPI; 56662306a36Sopenharmony_ci else 56762306a36Sopenharmony_ci return -EINVAL; 56862306a36Sopenharmony_ci 56962306a36Sopenharmony_ci spin_lock_irqsave(&pctrl->lock, flags); 57062306a36Sopenharmony_ci addr = pctrl->base + pwr_reg; 57162306a36Sopenharmony_ci arg = (readl(addr) & PVDD_MASK) ? 1800 : 3300; 57262306a36Sopenharmony_ci spin_unlock_irqrestore(&pctrl->lock, flags); 57362306a36Sopenharmony_ci break; 57462306a36Sopenharmony_ci } 57562306a36Sopenharmony_ci 57662306a36Sopenharmony_ci case PIN_CONFIG_DRIVE_STRENGTH: { 57762306a36Sopenharmony_ci unsigned int index; 57862306a36Sopenharmony_ci 57962306a36Sopenharmony_ci if (!(cfg & PIN_CFG_IOLH_A)) 58062306a36Sopenharmony_ci return -EINVAL; 58162306a36Sopenharmony_ci 58262306a36Sopenharmony_ci index = rzg2l_read_pin_config(pctrl, IOLH(port_offset), bit, IOLH_MASK); 58362306a36Sopenharmony_ci arg = iolh_groupa_mA[index]; 58462306a36Sopenharmony_ci break; 58562306a36Sopenharmony_ci } 58662306a36Sopenharmony_ci 58762306a36Sopenharmony_ci case PIN_CONFIG_OUTPUT_IMPEDANCE_OHMS: { 58862306a36Sopenharmony_ci unsigned int index; 58962306a36Sopenharmony_ci 59062306a36Sopenharmony_ci if (!(cfg & PIN_CFG_IOLH_B)) 59162306a36Sopenharmony_ci return -EINVAL; 59262306a36Sopenharmony_ci 59362306a36Sopenharmony_ci index = rzg2l_read_pin_config(pctrl, IOLH(port_offset), bit, IOLH_MASK); 59462306a36Sopenharmony_ci arg = iolh_groupb_oi[index]; 59562306a36Sopenharmony_ci break; 59662306a36Sopenharmony_ci } 59762306a36Sopenharmony_ci 59862306a36Sopenharmony_ci default: 59962306a36Sopenharmony_ci return -ENOTSUPP; 60062306a36Sopenharmony_ci } 60162306a36Sopenharmony_ci 60262306a36Sopenharmony_ci *config = pinconf_to_config_packed(param, arg); 60362306a36Sopenharmony_ci 60462306a36Sopenharmony_ci return 0; 60562306a36Sopenharmony_ci}; 60662306a36Sopenharmony_ci 60762306a36Sopenharmony_cistatic int rzg2l_pinctrl_pinconf_set(struct pinctrl_dev *pctldev, 60862306a36Sopenharmony_ci unsigned int _pin, 60962306a36Sopenharmony_ci unsigned long *_configs, 61062306a36Sopenharmony_ci unsigned int num_configs) 61162306a36Sopenharmony_ci{ 61262306a36Sopenharmony_ci struct rzg2l_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev); 61362306a36Sopenharmony_ci const struct pinctrl_pin_desc *pin = &pctrl->desc.pins[_pin]; 61462306a36Sopenharmony_ci unsigned int *pin_data = pin->drv_data; 61562306a36Sopenharmony_ci enum pin_config_param param; 61662306a36Sopenharmony_ci unsigned long flags; 61762306a36Sopenharmony_ci void __iomem *addr; 61862306a36Sopenharmony_ci u32 port_offset; 61962306a36Sopenharmony_ci unsigned int i; 62062306a36Sopenharmony_ci u32 cfg = 0; 62162306a36Sopenharmony_ci u8 bit = 0; 62262306a36Sopenharmony_ci 62362306a36Sopenharmony_ci if (!pin_data) 62462306a36Sopenharmony_ci return -EINVAL; 62562306a36Sopenharmony_ci 62662306a36Sopenharmony_ci if (*pin_data & RZG2L_SINGLE_PIN) { 62762306a36Sopenharmony_ci port_offset = RZG2L_SINGLE_PIN_GET_PORT_OFFSET(*pin_data); 62862306a36Sopenharmony_ci cfg = RZG2L_SINGLE_PIN_GET_CFGS(*pin_data); 62962306a36Sopenharmony_ci bit = RZG2L_SINGLE_PIN_GET_BIT(*pin_data); 63062306a36Sopenharmony_ci } else { 63162306a36Sopenharmony_ci cfg = RZG2L_GPIO_PORT_GET_CFGS(*pin_data); 63262306a36Sopenharmony_ci port_offset = RZG2L_PIN_ID_TO_PORT_OFFSET(_pin); 63362306a36Sopenharmony_ci bit = RZG2L_PIN_ID_TO_PIN(_pin); 63462306a36Sopenharmony_ci 63562306a36Sopenharmony_ci if (rzg2l_validate_gpio_pin(pctrl, *pin_data, RZG2L_PIN_ID_TO_PORT(_pin), bit)) 63662306a36Sopenharmony_ci return -EINVAL; 63762306a36Sopenharmony_ci } 63862306a36Sopenharmony_ci 63962306a36Sopenharmony_ci for (i = 0; i < num_configs; i++) { 64062306a36Sopenharmony_ci param = pinconf_to_config_param(_configs[i]); 64162306a36Sopenharmony_ci switch (param) { 64262306a36Sopenharmony_ci case PIN_CONFIG_INPUT_ENABLE: { 64362306a36Sopenharmony_ci unsigned int arg = 64462306a36Sopenharmony_ci pinconf_to_config_argument(_configs[i]); 64562306a36Sopenharmony_ci 64662306a36Sopenharmony_ci if (!(cfg & PIN_CFG_IEN)) 64762306a36Sopenharmony_ci return -EINVAL; 64862306a36Sopenharmony_ci 64962306a36Sopenharmony_ci rzg2l_rmw_pin_config(pctrl, IEN(port_offset), bit, IEN_MASK, !!arg); 65062306a36Sopenharmony_ci break; 65162306a36Sopenharmony_ci } 65262306a36Sopenharmony_ci 65362306a36Sopenharmony_ci case PIN_CONFIG_POWER_SOURCE: { 65462306a36Sopenharmony_ci unsigned int mV = pinconf_to_config_argument(_configs[i]); 65562306a36Sopenharmony_ci u32 pwr_reg = 0x0; 65662306a36Sopenharmony_ci 65762306a36Sopenharmony_ci if (mV != 1800 && mV != 3300) 65862306a36Sopenharmony_ci return -EINVAL; 65962306a36Sopenharmony_ci 66062306a36Sopenharmony_ci if (cfg & PIN_CFG_IO_VMC_SD0) 66162306a36Sopenharmony_ci pwr_reg = SD_CH(0); 66262306a36Sopenharmony_ci else if (cfg & PIN_CFG_IO_VMC_SD1) 66362306a36Sopenharmony_ci pwr_reg = SD_CH(1); 66462306a36Sopenharmony_ci else if (cfg & PIN_CFG_IO_VMC_QSPI) 66562306a36Sopenharmony_ci pwr_reg = QSPI; 66662306a36Sopenharmony_ci else 66762306a36Sopenharmony_ci return -EINVAL; 66862306a36Sopenharmony_ci 66962306a36Sopenharmony_ci addr = pctrl->base + pwr_reg; 67062306a36Sopenharmony_ci spin_lock_irqsave(&pctrl->lock, flags); 67162306a36Sopenharmony_ci writel((mV == 1800) ? PVDD_1800 : PVDD_3300, addr); 67262306a36Sopenharmony_ci spin_unlock_irqrestore(&pctrl->lock, flags); 67362306a36Sopenharmony_ci break; 67462306a36Sopenharmony_ci } 67562306a36Sopenharmony_ci 67662306a36Sopenharmony_ci case PIN_CONFIG_DRIVE_STRENGTH: { 67762306a36Sopenharmony_ci unsigned int arg = pinconf_to_config_argument(_configs[i]); 67862306a36Sopenharmony_ci unsigned int index; 67962306a36Sopenharmony_ci 68062306a36Sopenharmony_ci if (!(cfg & PIN_CFG_IOLH_A)) 68162306a36Sopenharmony_ci return -EINVAL; 68262306a36Sopenharmony_ci 68362306a36Sopenharmony_ci for (index = 0; index < ARRAY_SIZE(iolh_groupa_mA); index++) { 68462306a36Sopenharmony_ci if (arg == iolh_groupa_mA[index]) 68562306a36Sopenharmony_ci break; 68662306a36Sopenharmony_ci } 68762306a36Sopenharmony_ci if (index >= ARRAY_SIZE(iolh_groupa_mA)) 68862306a36Sopenharmony_ci return -EINVAL; 68962306a36Sopenharmony_ci 69062306a36Sopenharmony_ci rzg2l_rmw_pin_config(pctrl, IOLH(port_offset), bit, IOLH_MASK, index); 69162306a36Sopenharmony_ci break; 69262306a36Sopenharmony_ci } 69362306a36Sopenharmony_ci 69462306a36Sopenharmony_ci case PIN_CONFIG_OUTPUT_IMPEDANCE_OHMS: { 69562306a36Sopenharmony_ci unsigned int arg = pinconf_to_config_argument(_configs[i]); 69662306a36Sopenharmony_ci unsigned int index; 69762306a36Sopenharmony_ci 69862306a36Sopenharmony_ci if (!(cfg & PIN_CFG_IOLH_B)) 69962306a36Sopenharmony_ci return -EINVAL; 70062306a36Sopenharmony_ci 70162306a36Sopenharmony_ci for (index = 0; index < ARRAY_SIZE(iolh_groupb_oi); index++) { 70262306a36Sopenharmony_ci if (arg == iolh_groupb_oi[index]) 70362306a36Sopenharmony_ci break; 70462306a36Sopenharmony_ci } 70562306a36Sopenharmony_ci if (index >= ARRAY_SIZE(iolh_groupb_oi)) 70662306a36Sopenharmony_ci return -EINVAL; 70762306a36Sopenharmony_ci 70862306a36Sopenharmony_ci rzg2l_rmw_pin_config(pctrl, IOLH(port_offset), bit, IOLH_MASK, index); 70962306a36Sopenharmony_ci break; 71062306a36Sopenharmony_ci } 71162306a36Sopenharmony_ci 71262306a36Sopenharmony_ci default: 71362306a36Sopenharmony_ci return -EOPNOTSUPP; 71462306a36Sopenharmony_ci } 71562306a36Sopenharmony_ci } 71662306a36Sopenharmony_ci 71762306a36Sopenharmony_ci return 0; 71862306a36Sopenharmony_ci} 71962306a36Sopenharmony_ci 72062306a36Sopenharmony_cistatic int rzg2l_pinctrl_pinconf_group_set(struct pinctrl_dev *pctldev, 72162306a36Sopenharmony_ci unsigned int group, 72262306a36Sopenharmony_ci unsigned long *configs, 72362306a36Sopenharmony_ci unsigned int num_configs) 72462306a36Sopenharmony_ci{ 72562306a36Sopenharmony_ci const unsigned int *pins; 72662306a36Sopenharmony_ci unsigned int i, npins; 72762306a36Sopenharmony_ci int ret; 72862306a36Sopenharmony_ci 72962306a36Sopenharmony_ci ret = pinctrl_generic_get_group_pins(pctldev, group, &pins, &npins); 73062306a36Sopenharmony_ci if (ret) 73162306a36Sopenharmony_ci return ret; 73262306a36Sopenharmony_ci 73362306a36Sopenharmony_ci for (i = 0; i < npins; i++) { 73462306a36Sopenharmony_ci ret = rzg2l_pinctrl_pinconf_set(pctldev, pins[i], configs, 73562306a36Sopenharmony_ci num_configs); 73662306a36Sopenharmony_ci if (ret) 73762306a36Sopenharmony_ci return ret; 73862306a36Sopenharmony_ci } 73962306a36Sopenharmony_ci 74062306a36Sopenharmony_ci return 0; 74162306a36Sopenharmony_ci}; 74262306a36Sopenharmony_ci 74362306a36Sopenharmony_cistatic int rzg2l_pinctrl_pinconf_group_get(struct pinctrl_dev *pctldev, 74462306a36Sopenharmony_ci unsigned int group, 74562306a36Sopenharmony_ci unsigned long *config) 74662306a36Sopenharmony_ci{ 74762306a36Sopenharmony_ci const unsigned int *pins; 74862306a36Sopenharmony_ci unsigned int i, npins, prev_config = 0; 74962306a36Sopenharmony_ci int ret; 75062306a36Sopenharmony_ci 75162306a36Sopenharmony_ci ret = pinctrl_generic_get_group_pins(pctldev, group, &pins, &npins); 75262306a36Sopenharmony_ci if (ret) 75362306a36Sopenharmony_ci return ret; 75462306a36Sopenharmony_ci 75562306a36Sopenharmony_ci for (i = 0; i < npins; i++) { 75662306a36Sopenharmony_ci ret = rzg2l_pinctrl_pinconf_get(pctldev, pins[i], config); 75762306a36Sopenharmony_ci if (ret) 75862306a36Sopenharmony_ci return ret; 75962306a36Sopenharmony_ci 76062306a36Sopenharmony_ci /* Check config matching between to pin */ 76162306a36Sopenharmony_ci if (i && prev_config != *config) 76262306a36Sopenharmony_ci return -EOPNOTSUPP; 76362306a36Sopenharmony_ci 76462306a36Sopenharmony_ci prev_config = *config; 76562306a36Sopenharmony_ci } 76662306a36Sopenharmony_ci 76762306a36Sopenharmony_ci return 0; 76862306a36Sopenharmony_ci}; 76962306a36Sopenharmony_ci 77062306a36Sopenharmony_cistatic const struct pinctrl_ops rzg2l_pinctrl_pctlops = { 77162306a36Sopenharmony_ci .get_groups_count = pinctrl_generic_get_group_count, 77262306a36Sopenharmony_ci .get_group_name = pinctrl_generic_get_group_name, 77362306a36Sopenharmony_ci .get_group_pins = pinctrl_generic_get_group_pins, 77462306a36Sopenharmony_ci .dt_node_to_map = rzg2l_dt_node_to_map, 77562306a36Sopenharmony_ci .dt_free_map = rzg2l_dt_free_map, 77662306a36Sopenharmony_ci}; 77762306a36Sopenharmony_ci 77862306a36Sopenharmony_cistatic const struct pinmux_ops rzg2l_pinctrl_pmxops = { 77962306a36Sopenharmony_ci .get_functions_count = pinmux_generic_get_function_count, 78062306a36Sopenharmony_ci .get_function_name = pinmux_generic_get_function_name, 78162306a36Sopenharmony_ci .get_function_groups = pinmux_generic_get_function_groups, 78262306a36Sopenharmony_ci .set_mux = rzg2l_pinctrl_set_mux, 78362306a36Sopenharmony_ci .strict = true, 78462306a36Sopenharmony_ci}; 78562306a36Sopenharmony_ci 78662306a36Sopenharmony_cistatic const struct pinconf_ops rzg2l_pinctrl_confops = { 78762306a36Sopenharmony_ci .is_generic = true, 78862306a36Sopenharmony_ci .pin_config_get = rzg2l_pinctrl_pinconf_get, 78962306a36Sopenharmony_ci .pin_config_set = rzg2l_pinctrl_pinconf_set, 79062306a36Sopenharmony_ci .pin_config_group_set = rzg2l_pinctrl_pinconf_group_set, 79162306a36Sopenharmony_ci .pin_config_group_get = rzg2l_pinctrl_pinconf_group_get, 79262306a36Sopenharmony_ci .pin_config_config_dbg_show = pinconf_generic_dump_config, 79362306a36Sopenharmony_ci}; 79462306a36Sopenharmony_ci 79562306a36Sopenharmony_cistatic int rzg2l_gpio_request(struct gpio_chip *chip, unsigned int offset) 79662306a36Sopenharmony_ci{ 79762306a36Sopenharmony_ci struct rzg2l_pinctrl *pctrl = gpiochip_get_data(chip); 79862306a36Sopenharmony_ci u32 port = RZG2L_PIN_ID_TO_PORT(offset); 79962306a36Sopenharmony_ci u8 bit = RZG2L_PIN_ID_TO_PIN(offset); 80062306a36Sopenharmony_ci unsigned long flags; 80162306a36Sopenharmony_ci u8 reg8; 80262306a36Sopenharmony_ci int ret; 80362306a36Sopenharmony_ci 80462306a36Sopenharmony_ci ret = pinctrl_gpio_request(chip->base + offset); 80562306a36Sopenharmony_ci if (ret) 80662306a36Sopenharmony_ci return ret; 80762306a36Sopenharmony_ci 80862306a36Sopenharmony_ci spin_lock_irqsave(&pctrl->lock, flags); 80962306a36Sopenharmony_ci 81062306a36Sopenharmony_ci /* Select GPIO mode in PMC Register */ 81162306a36Sopenharmony_ci reg8 = readb(pctrl->base + PMC(port)); 81262306a36Sopenharmony_ci reg8 &= ~BIT(bit); 81362306a36Sopenharmony_ci writeb(reg8, pctrl->base + PMC(port)); 81462306a36Sopenharmony_ci 81562306a36Sopenharmony_ci spin_unlock_irqrestore(&pctrl->lock, flags); 81662306a36Sopenharmony_ci 81762306a36Sopenharmony_ci return 0; 81862306a36Sopenharmony_ci} 81962306a36Sopenharmony_ci 82062306a36Sopenharmony_cistatic void rzg2l_gpio_set_direction(struct rzg2l_pinctrl *pctrl, u32 port, 82162306a36Sopenharmony_ci u8 bit, bool output) 82262306a36Sopenharmony_ci{ 82362306a36Sopenharmony_ci unsigned long flags; 82462306a36Sopenharmony_ci u16 reg16; 82562306a36Sopenharmony_ci 82662306a36Sopenharmony_ci spin_lock_irqsave(&pctrl->lock, flags); 82762306a36Sopenharmony_ci 82862306a36Sopenharmony_ci reg16 = readw(pctrl->base + PM(port)); 82962306a36Sopenharmony_ci reg16 &= ~(PM_MASK << (bit * 2)); 83062306a36Sopenharmony_ci 83162306a36Sopenharmony_ci reg16 |= (output ? PM_OUTPUT : PM_INPUT) << (bit * 2); 83262306a36Sopenharmony_ci writew(reg16, pctrl->base + PM(port)); 83362306a36Sopenharmony_ci 83462306a36Sopenharmony_ci spin_unlock_irqrestore(&pctrl->lock, flags); 83562306a36Sopenharmony_ci} 83662306a36Sopenharmony_ci 83762306a36Sopenharmony_cistatic int rzg2l_gpio_get_direction(struct gpio_chip *chip, unsigned int offset) 83862306a36Sopenharmony_ci{ 83962306a36Sopenharmony_ci struct rzg2l_pinctrl *pctrl = gpiochip_get_data(chip); 84062306a36Sopenharmony_ci u32 port = RZG2L_PIN_ID_TO_PORT(offset); 84162306a36Sopenharmony_ci u8 bit = RZG2L_PIN_ID_TO_PIN(offset); 84262306a36Sopenharmony_ci 84362306a36Sopenharmony_ci if (!(readb(pctrl->base + PMC(port)) & BIT(bit))) { 84462306a36Sopenharmony_ci u16 reg16; 84562306a36Sopenharmony_ci 84662306a36Sopenharmony_ci reg16 = readw(pctrl->base + PM(port)); 84762306a36Sopenharmony_ci reg16 = (reg16 >> (bit * 2)) & PM_MASK; 84862306a36Sopenharmony_ci if (reg16 == PM_OUTPUT) 84962306a36Sopenharmony_ci return GPIO_LINE_DIRECTION_OUT; 85062306a36Sopenharmony_ci } 85162306a36Sopenharmony_ci 85262306a36Sopenharmony_ci return GPIO_LINE_DIRECTION_IN; 85362306a36Sopenharmony_ci} 85462306a36Sopenharmony_ci 85562306a36Sopenharmony_cistatic int rzg2l_gpio_direction_input(struct gpio_chip *chip, 85662306a36Sopenharmony_ci unsigned int offset) 85762306a36Sopenharmony_ci{ 85862306a36Sopenharmony_ci struct rzg2l_pinctrl *pctrl = gpiochip_get_data(chip); 85962306a36Sopenharmony_ci u32 port = RZG2L_PIN_ID_TO_PORT(offset); 86062306a36Sopenharmony_ci u8 bit = RZG2L_PIN_ID_TO_PIN(offset); 86162306a36Sopenharmony_ci 86262306a36Sopenharmony_ci rzg2l_gpio_set_direction(pctrl, port, bit, false); 86362306a36Sopenharmony_ci 86462306a36Sopenharmony_ci return 0; 86562306a36Sopenharmony_ci} 86662306a36Sopenharmony_ci 86762306a36Sopenharmony_cistatic void rzg2l_gpio_set(struct gpio_chip *chip, unsigned int offset, 86862306a36Sopenharmony_ci int value) 86962306a36Sopenharmony_ci{ 87062306a36Sopenharmony_ci struct rzg2l_pinctrl *pctrl = gpiochip_get_data(chip); 87162306a36Sopenharmony_ci u32 port = RZG2L_PIN_ID_TO_PORT(offset); 87262306a36Sopenharmony_ci u8 bit = RZG2L_PIN_ID_TO_PIN(offset); 87362306a36Sopenharmony_ci unsigned long flags; 87462306a36Sopenharmony_ci u8 reg8; 87562306a36Sopenharmony_ci 87662306a36Sopenharmony_ci spin_lock_irqsave(&pctrl->lock, flags); 87762306a36Sopenharmony_ci 87862306a36Sopenharmony_ci reg8 = readb(pctrl->base + P(port)); 87962306a36Sopenharmony_ci 88062306a36Sopenharmony_ci if (value) 88162306a36Sopenharmony_ci writeb(reg8 | BIT(bit), pctrl->base + P(port)); 88262306a36Sopenharmony_ci else 88362306a36Sopenharmony_ci writeb(reg8 & ~BIT(bit), pctrl->base + P(port)); 88462306a36Sopenharmony_ci 88562306a36Sopenharmony_ci spin_unlock_irqrestore(&pctrl->lock, flags); 88662306a36Sopenharmony_ci} 88762306a36Sopenharmony_ci 88862306a36Sopenharmony_cistatic int rzg2l_gpio_direction_output(struct gpio_chip *chip, 88962306a36Sopenharmony_ci unsigned int offset, int value) 89062306a36Sopenharmony_ci{ 89162306a36Sopenharmony_ci struct rzg2l_pinctrl *pctrl = gpiochip_get_data(chip); 89262306a36Sopenharmony_ci u32 port = RZG2L_PIN_ID_TO_PORT(offset); 89362306a36Sopenharmony_ci u8 bit = RZG2L_PIN_ID_TO_PIN(offset); 89462306a36Sopenharmony_ci 89562306a36Sopenharmony_ci rzg2l_gpio_set(chip, offset, value); 89662306a36Sopenharmony_ci rzg2l_gpio_set_direction(pctrl, port, bit, true); 89762306a36Sopenharmony_ci 89862306a36Sopenharmony_ci return 0; 89962306a36Sopenharmony_ci} 90062306a36Sopenharmony_ci 90162306a36Sopenharmony_cistatic int rzg2l_gpio_get(struct gpio_chip *chip, unsigned int offset) 90262306a36Sopenharmony_ci{ 90362306a36Sopenharmony_ci struct rzg2l_pinctrl *pctrl = gpiochip_get_data(chip); 90462306a36Sopenharmony_ci u32 port = RZG2L_PIN_ID_TO_PORT(offset); 90562306a36Sopenharmony_ci u8 bit = RZG2L_PIN_ID_TO_PIN(offset); 90662306a36Sopenharmony_ci u16 reg16; 90762306a36Sopenharmony_ci 90862306a36Sopenharmony_ci reg16 = readw(pctrl->base + PM(port)); 90962306a36Sopenharmony_ci reg16 = (reg16 >> (bit * 2)) & PM_MASK; 91062306a36Sopenharmony_ci 91162306a36Sopenharmony_ci if (reg16 == PM_INPUT) 91262306a36Sopenharmony_ci return !!(readb(pctrl->base + PIN(port)) & BIT(bit)); 91362306a36Sopenharmony_ci else if (reg16 == PM_OUTPUT) 91462306a36Sopenharmony_ci return !!(readb(pctrl->base + P(port)) & BIT(bit)); 91562306a36Sopenharmony_ci else 91662306a36Sopenharmony_ci return -EINVAL; 91762306a36Sopenharmony_ci} 91862306a36Sopenharmony_ci 91962306a36Sopenharmony_cistatic void rzg2l_gpio_free(struct gpio_chip *chip, unsigned int offset) 92062306a36Sopenharmony_ci{ 92162306a36Sopenharmony_ci unsigned int virq; 92262306a36Sopenharmony_ci 92362306a36Sopenharmony_ci pinctrl_gpio_free(chip->base + offset); 92462306a36Sopenharmony_ci 92562306a36Sopenharmony_ci virq = irq_find_mapping(chip->irq.domain, offset); 92662306a36Sopenharmony_ci if (virq) 92762306a36Sopenharmony_ci irq_dispose_mapping(virq); 92862306a36Sopenharmony_ci 92962306a36Sopenharmony_ci /* 93062306a36Sopenharmony_ci * Set the GPIO as an input to ensure that the next GPIO request won't 93162306a36Sopenharmony_ci * drive the GPIO pin as an output. 93262306a36Sopenharmony_ci */ 93362306a36Sopenharmony_ci rzg2l_gpio_direction_input(chip, offset); 93462306a36Sopenharmony_ci} 93562306a36Sopenharmony_ci 93662306a36Sopenharmony_cistatic const char * const rzg2l_gpio_names[] = { 93762306a36Sopenharmony_ci "P0_0", "P0_1", "P0_2", "P0_3", "P0_4", "P0_5", "P0_6", "P0_7", 93862306a36Sopenharmony_ci "P1_0", "P1_1", "P1_2", "P1_3", "P1_4", "P1_5", "P1_6", "P1_7", 93962306a36Sopenharmony_ci "P2_0", "P2_1", "P2_2", "P2_3", "P2_4", "P2_5", "P2_6", "P2_7", 94062306a36Sopenharmony_ci "P3_0", "P3_1", "P3_2", "P3_3", "P3_4", "P3_5", "P3_6", "P3_7", 94162306a36Sopenharmony_ci "P4_0", "P4_1", "P4_2", "P4_3", "P4_4", "P4_5", "P4_6", "P4_7", 94262306a36Sopenharmony_ci "P5_0", "P5_1", "P5_2", "P5_3", "P5_4", "P5_5", "P5_6", "P5_7", 94362306a36Sopenharmony_ci "P6_0", "P6_1", "P6_2", "P6_3", "P6_4", "P6_5", "P6_6", "P6_7", 94462306a36Sopenharmony_ci "P7_0", "P7_1", "P7_2", "P7_3", "P7_4", "P7_5", "P7_6", "P7_7", 94562306a36Sopenharmony_ci "P8_0", "P8_1", "P8_2", "P8_3", "P8_4", "P8_5", "P8_6", "P8_7", 94662306a36Sopenharmony_ci "P9_0", "P9_1", "P9_2", "P9_3", "P9_4", "P9_5", "P9_6", "P9_7", 94762306a36Sopenharmony_ci "P10_0", "P10_1", "P10_2", "P10_3", "P10_4", "P10_5", "P10_6", "P10_7", 94862306a36Sopenharmony_ci "P11_0", "P11_1", "P11_2", "P11_3", "P11_4", "P11_5", "P11_6", "P11_7", 94962306a36Sopenharmony_ci "P12_0", "P12_1", "P12_2", "P12_3", "P12_4", "P12_5", "P12_6", "P12_7", 95062306a36Sopenharmony_ci "P13_0", "P13_1", "P13_2", "P13_3", "P13_4", "P13_5", "P13_6", "P13_7", 95162306a36Sopenharmony_ci "P14_0", "P14_1", "P14_2", "P14_3", "P14_4", "P14_5", "P14_6", "P14_7", 95262306a36Sopenharmony_ci "P15_0", "P15_1", "P15_2", "P15_3", "P15_4", "P15_5", "P15_6", "P15_7", 95362306a36Sopenharmony_ci "P16_0", "P16_1", "P16_2", "P16_3", "P16_4", "P16_5", "P16_6", "P16_7", 95462306a36Sopenharmony_ci "P17_0", "P17_1", "P17_2", "P17_3", "P17_4", "P17_5", "P17_6", "P17_7", 95562306a36Sopenharmony_ci "P18_0", "P18_1", "P18_2", "P18_3", "P18_4", "P18_5", "P18_6", "P18_7", 95662306a36Sopenharmony_ci "P19_0", "P19_1", "P19_2", "P19_3", "P19_4", "P19_5", "P19_6", "P19_7", 95762306a36Sopenharmony_ci "P20_0", "P20_1", "P20_2", "P20_3", "P20_4", "P20_5", "P20_6", "P20_7", 95862306a36Sopenharmony_ci "P21_0", "P21_1", "P21_2", "P21_3", "P21_4", "P21_5", "P21_6", "P21_7", 95962306a36Sopenharmony_ci "P22_0", "P22_1", "P22_2", "P22_3", "P22_4", "P22_5", "P22_6", "P22_7", 96062306a36Sopenharmony_ci "P23_0", "P23_1", "P23_2", "P23_3", "P23_4", "P23_5", "P23_6", "P23_7", 96162306a36Sopenharmony_ci "P24_0", "P24_1", "P24_2", "P24_3", "P24_4", "P24_5", "P24_6", "P24_7", 96262306a36Sopenharmony_ci "P25_0", "P25_1", "P25_2", "P25_3", "P25_4", "P25_5", "P25_6", "P25_7", 96362306a36Sopenharmony_ci "P26_0", "P26_1", "P26_2", "P26_3", "P26_4", "P26_5", "P26_6", "P26_7", 96462306a36Sopenharmony_ci "P27_0", "P27_1", "P27_2", "P27_3", "P27_4", "P27_5", "P27_6", "P27_7", 96562306a36Sopenharmony_ci "P28_0", "P28_1", "P28_2", "P28_3", "P28_4", "P28_5", "P28_6", "P28_7", 96662306a36Sopenharmony_ci "P29_0", "P29_1", "P29_2", "P29_3", "P29_4", "P29_5", "P29_6", "P29_7", 96762306a36Sopenharmony_ci "P30_0", "P30_1", "P30_2", "P30_3", "P30_4", "P30_5", "P30_6", "P30_7", 96862306a36Sopenharmony_ci "P31_0", "P31_1", "P31_2", "P31_3", "P31_4", "P31_5", "P31_6", "P31_7", 96962306a36Sopenharmony_ci "P32_0", "P32_1", "P32_2", "P32_3", "P32_4", "P32_5", "P32_6", "P32_7", 97062306a36Sopenharmony_ci "P33_0", "P33_1", "P33_2", "P33_3", "P33_4", "P33_5", "P33_6", "P33_7", 97162306a36Sopenharmony_ci "P34_0", "P34_1", "P34_2", "P34_3", "P34_4", "P34_5", "P34_6", "P34_7", 97262306a36Sopenharmony_ci "P35_0", "P35_1", "P35_2", "P35_3", "P35_4", "P35_5", "P35_6", "P35_7", 97362306a36Sopenharmony_ci "P36_0", "P36_1", "P36_2", "P36_3", "P36_4", "P36_5", "P36_6", "P36_7", 97462306a36Sopenharmony_ci "P37_0", "P37_1", "P37_2", "P37_3", "P37_4", "P37_5", "P37_6", "P37_7", 97562306a36Sopenharmony_ci "P38_0", "P38_1", "P38_2", "P38_3", "P38_4", "P38_5", "P38_6", "P38_7", 97662306a36Sopenharmony_ci "P39_0", "P39_1", "P39_2", "P39_3", "P39_4", "P39_5", "P39_6", "P39_7", 97762306a36Sopenharmony_ci "P40_0", "P40_1", "P40_2", "P40_3", "P40_4", "P40_5", "P40_6", "P40_7", 97862306a36Sopenharmony_ci "P41_0", "P41_1", "P41_2", "P41_3", "P41_4", "P41_5", "P41_6", "P41_7", 97962306a36Sopenharmony_ci "P42_0", "P42_1", "P42_2", "P42_3", "P42_4", "P42_5", "P42_6", "P42_7", 98062306a36Sopenharmony_ci "P43_0", "P43_1", "P43_2", "P43_3", "P43_4", "P43_5", "P43_6", "P43_7", 98162306a36Sopenharmony_ci "P44_0", "P44_1", "P44_2", "P44_3", "P44_4", "P44_5", "P44_6", "P44_7", 98262306a36Sopenharmony_ci "P45_0", "P45_1", "P45_2", "P45_3", "P45_4", "P45_5", "P45_6", "P45_7", 98362306a36Sopenharmony_ci "P46_0", "P46_1", "P46_2", "P46_3", "P46_4", "P46_5", "P46_6", "P46_7", 98462306a36Sopenharmony_ci "P47_0", "P47_1", "P47_2", "P47_3", "P47_4", "P47_5", "P47_6", "P47_7", 98562306a36Sopenharmony_ci "P48_0", "P48_1", "P48_2", "P48_3", "P48_4", "P48_5", "P48_6", "P48_7", 98662306a36Sopenharmony_ci}; 98762306a36Sopenharmony_ci 98862306a36Sopenharmony_cistatic const u32 rzg2l_gpio_configs[] = { 98962306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x10, RZG2L_MPXED_PIN_FUNCS), 99062306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x11, RZG2L_MPXED_PIN_FUNCS), 99162306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x12, RZG2L_MPXED_PIN_FUNCS), 99262306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x13, RZG2L_MPXED_PIN_FUNCS), 99362306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x14, RZG2L_MPXED_PIN_FUNCS), 99462306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(3, 0x15, RZG2L_MPXED_PIN_FUNCS), 99562306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x16, RZG2L_MPXED_PIN_FUNCS), 99662306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(3, 0x17, RZG2L_MPXED_PIN_FUNCS), 99762306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(3, 0x18, RZG2L_MPXED_PIN_FUNCS), 99862306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x19, RZG2L_MPXED_PIN_FUNCS), 99962306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x1a, RZG2L_MPXED_PIN_FUNCS), 100062306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x1b, RZG2L_MPXED_PIN_FUNCS), 100162306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x1c, RZG2L_MPXED_PIN_FUNCS), 100262306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(3, 0x1d, RZG2L_MPXED_PIN_FUNCS), 100362306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x1e, RZG2L_MPXED_PIN_FUNCS), 100462306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x1f, RZG2L_MPXED_PIN_FUNCS), 100562306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x20, RZG2L_MPXED_PIN_FUNCS), 100662306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(3, 0x21, RZG2L_MPXED_PIN_FUNCS), 100762306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x22, RZG2L_MPXED_PIN_FUNCS), 100862306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x23, RZG2L_MPXED_PIN_FUNCS), 100962306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(3, 0x24, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH0)), 101062306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x25, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH0)), 101162306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x26, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH0)), 101262306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x27, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH0)), 101362306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x28, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH0)), 101462306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x29, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH0)), 101562306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x2a, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH0)), 101662306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x2b, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH0)), 101762306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x2c, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH0)), 101862306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x2d, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH1)), 101962306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x2e, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH1)), 102062306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x2f, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH1)), 102162306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x30, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH1)), 102262306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x31, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH1)), 102362306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x32, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH1)), 102462306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x33, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH1)), 102562306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x34, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH1)), 102662306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(3, 0x35, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH1)), 102762306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x36, RZG2L_MPXED_PIN_FUNCS), 102862306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(3, 0x37, RZG2L_MPXED_PIN_FUNCS), 102962306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(3, 0x38, RZG2L_MPXED_PIN_FUNCS), 103062306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x39, RZG2L_MPXED_PIN_FUNCS), 103162306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(5, 0x3a, RZG2L_MPXED_PIN_FUNCS), 103262306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(4, 0x3b, RZG2L_MPXED_PIN_FUNCS), 103362306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(4, 0x3c, RZG2L_MPXED_PIN_FUNCS), 103462306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(4, 0x3d, RZG2L_MPXED_PIN_FUNCS), 103562306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(4, 0x3e, RZG2L_MPXED_PIN_FUNCS), 103662306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(4, 0x3f, RZG2L_MPXED_PIN_FUNCS), 103762306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(5, 0x40, RZG2L_MPXED_PIN_FUNCS), 103862306a36Sopenharmony_ci}; 103962306a36Sopenharmony_ci 104062306a36Sopenharmony_cistatic const u32 r9a07g043_gpio_configs[] = { 104162306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(4, 0x10, RZG2L_MPXED_PIN_FUNCS), 104262306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(5, 0x11, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH0)), 104362306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(4, 0x12, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH0)), 104462306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(4, 0x13, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH0)), 104562306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(6, 0x14, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH0)), 104662306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(5, 0x15, RZG2L_MPXED_PIN_FUNCS), 104762306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(5, 0x16, RZG2L_MPXED_PIN_FUNCS), 104862306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(5, 0x17, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH1)), 104962306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(5, 0x18, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH1)), 105062306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(4, 0x19, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH1)), 105162306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(5, 0x1a, RZG2L_MPXED_ETH_PIN_FUNCS(PIN_CFG_IO_VMC_ETH1)), 105262306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(4, 0x1b, RZG2L_MPXED_PIN_FUNCS), 105362306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x1c, RZG2L_MPXED_PIN_FUNCS), 105462306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(5, 0x1d, RZG2L_MPXED_PIN_FUNCS), 105562306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(3, 0x1e, RZG2L_MPXED_PIN_FUNCS), 105662306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(4, 0x1f, RZG2L_MPXED_PIN_FUNCS), 105762306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(2, 0x20, RZG2L_MPXED_PIN_FUNCS), 105862306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(4, 0x21, RZG2L_MPXED_PIN_FUNCS), 105962306a36Sopenharmony_ci RZG2L_GPIO_PORT_PACK(6, 0x22, RZG2L_MPXED_PIN_FUNCS), 106062306a36Sopenharmony_ci}; 106162306a36Sopenharmony_ci 106262306a36Sopenharmony_cistatic struct { 106362306a36Sopenharmony_ci struct rzg2l_dedicated_configs common[35]; 106462306a36Sopenharmony_ci struct rzg2l_dedicated_configs rzg2l_pins[7]; 106562306a36Sopenharmony_ci} rzg2l_dedicated_pins = { 106662306a36Sopenharmony_ci .common = { 106762306a36Sopenharmony_ci { "NMI", RZG2L_SINGLE_PIN_PACK(0x1, 0, 106862306a36Sopenharmony_ci (PIN_CFG_FILONOFF | PIN_CFG_FILNUM | PIN_CFG_FILCLKSEL)) }, 106962306a36Sopenharmony_ci { "TMS/SWDIO", RZG2L_SINGLE_PIN_PACK(0x2, 0, 107062306a36Sopenharmony_ci (PIN_CFG_IOLH_A | PIN_CFG_SR | PIN_CFG_IEN)) }, 107162306a36Sopenharmony_ci { "TDO", RZG2L_SINGLE_PIN_PACK(0x3, 0, 107262306a36Sopenharmony_ci (PIN_CFG_IOLH_A | PIN_CFG_SR | PIN_CFG_IEN)) }, 107362306a36Sopenharmony_ci { "AUDIO_CLK1", RZG2L_SINGLE_PIN_PACK(0x4, 0, PIN_CFG_IEN) }, 107462306a36Sopenharmony_ci { "AUDIO_CLK2", RZG2L_SINGLE_PIN_PACK(0x4, 1, PIN_CFG_IEN) }, 107562306a36Sopenharmony_ci { "SD0_CLK", RZG2L_SINGLE_PIN_PACK(0x6, 0, 107662306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_SD0)) }, 107762306a36Sopenharmony_ci { "SD0_CMD", RZG2L_SINGLE_PIN_PACK(0x6, 1, 107862306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_IO_VMC_SD0)) }, 107962306a36Sopenharmony_ci { "SD0_RST#", RZG2L_SINGLE_PIN_PACK(0x6, 2, 108062306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_SD0)) }, 108162306a36Sopenharmony_ci { "SD0_DATA0", RZG2L_SINGLE_PIN_PACK(0x7, 0, 108262306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_IO_VMC_SD0)) }, 108362306a36Sopenharmony_ci { "SD0_DATA1", RZG2L_SINGLE_PIN_PACK(0x7, 1, 108462306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_IO_VMC_SD0)) }, 108562306a36Sopenharmony_ci { "SD0_DATA2", RZG2L_SINGLE_PIN_PACK(0x7, 2, 108662306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_IO_VMC_SD0)) }, 108762306a36Sopenharmony_ci { "SD0_DATA3", RZG2L_SINGLE_PIN_PACK(0x7, 3, 108862306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_IO_VMC_SD0)) }, 108962306a36Sopenharmony_ci { "SD0_DATA4", RZG2L_SINGLE_PIN_PACK(0x7, 4, 109062306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_IO_VMC_SD0)) }, 109162306a36Sopenharmony_ci { "SD0_DATA5", RZG2L_SINGLE_PIN_PACK(0x7, 5, 109262306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_IO_VMC_SD0)) }, 109362306a36Sopenharmony_ci { "SD0_DATA6", RZG2L_SINGLE_PIN_PACK(0x7, 6, 109462306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_IO_VMC_SD0)) }, 109562306a36Sopenharmony_ci { "SD0_DATA7", RZG2L_SINGLE_PIN_PACK(0x7, 7, 109662306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_IO_VMC_SD0)) }, 109762306a36Sopenharmony_ci { "SD1_CLK", RZG2L_SINGLE_PIN_PACK(0x8, 0, 109862306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_SD1)) }, 109962306a36Sopenharmony_ci { "SD1_CMD", RZG2L_SINGLE_PIN_PACK(0x8, 1, 110062306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_IO_VMC_SD1)) }, 110162306a36Sopenharmony_ci { "SD1_DATA0", RZG2L_SINGLE_PIN_PACK(0x9, 0, 110262306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_IO_VMC_SD1)) }, 110362306a36Sopenharmony_ci { "SD1_DATA1", RZG2L_SINGLE_PIN_PACK(0x9, 1, 110462306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_IO_VMC_SD1)) }, 110562306a36Sopenharmony_ci { "SD1_DATA2", RZG2L_SINGLE_PIN_PACK(0x9, 2, 110662306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_IO_VMC_SD1)) }, 110762306a36Sopenharmony_ci { "SD1_DATA3", RZG2L_SINGLE_PIN_PACK(0x9, 3, 110862306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IEN | PIN_CFG_IO_VMC_SD1)) }, 110962306a36Sopenharmony_ci { "QSPI0_SPCLK", RZG2L_SINGLE_PIN_PACK(0xa, 0, 111062306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_QSPI)) }, 111162306a36Sopenharmony_ci { "QSPI0_IO0", RZG2L_SINGLE_PIN_PACK(0xa, 1, 111262306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_QSPI)) }, 111362306a36Sopenharmony_ci { "QSPI0_IO1", RZG2L_SINGLE_PIN_PACK(0xa, 2, 111462306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_QSPI)) }, 111562306a36Sopenharmony_ci { "QSPI0_IO2", RZG2L_SINGLE_PIN_PACK(0xa, 3, 111662306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_QSPI)) }, 111762306a36Sopenharmony_ci { "QSPI0_IO3", RZG2L_SINGLE_PIN_PACK(0xa, 4, 111862306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_QSPI)) }, 111962306a36Sopenharmony_ci { "QSPI0_SSL", RZG2L_SINGLE_PIN_PACK(0xa, 5, 112062306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_QSPI)) }, 112162306a36Sopenharmony_ci { "QSPI_RESET#", RZG2L_SINGLE_PIN_PACK(0xc, 0, 112262306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_QSPI)) }, 112362306a36Sopenharmony_ci { "QSPI_WP#", RZG2L_SINGLE_PIN_PACK(0xc, 1, 112462306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_QSPI)) }, 112562306a36Sopenharmony_ci { "WDTOVF_PERROUT#", RZG2L_SINGLE_PIN_PACK(0xd, 0, (PIN_CFG_IOLH_A | PIN_CFG_SR)) }, 112662306a36Sopenharmony_ci { "RIIC0_SDA", RZG2L_SINGLE_PIN_PACK(0xe, 0, PIN_CFG_IEN) }, 112762306a36Sopenharmony_ci { "RIIC0_SCL", RZG2L_SINGLE_PIN_PACK(0xe, 1, PIN_CFG_IEN) }, 112862306a36Sopenharmony_ci { "RIIC1_SDA", RZG2L_SINGLE_PIN_PACK(0xe, 2, PIN_CFG_IEN) }, 112962306a36Sopenharmony_ci { "RIIC1_SCL", RZG2L_SINGLE_PIN_PACK(0xe, 3, PIN_CFG_IEN) }, 113062306a36Sopenharmony_ci }, 113162306a36Sopenharmony_ci .rzg2l_pins = { 113262306a36Sopenharmony_ci { "QSPI_INT#", RZG2L_SINGLE_PIN_PACK(0xc, 2, (PIN_CFG_SR | PIN_CFG_IO_VMC_QSPI)) }, 113362306a36Sopenharmony_ci { "QSPI1_SPCLK", RZG2L_SINGLE_PIN_PACK(0xb, 0, 113462306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_QSPI)) }, 113562306a36Sopenharmony_ci { "QSPI1_IO0", RZG2L_SINGLE_PIN_PACK(0xb, 1, 113662306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_QSPI)) }, 113762306a36Sopenharmony_ci { "QSPI1_IO1", RZG2L_SINGLE_PIN_PACK(0xb, 2, 113862306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_QSPI)) }, 113962306a36Sopenharmony_ci { "QSPI1_IO2", RZG2L_SINGLE_PIN_PACK(0xb, 3, 114062306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_QSPI)) }, 114162306a36Sopenharmony_ci { "QSPI1_IO3", RZG2L_SINGLE_PIN_PACK(0xb, 4, 114262306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_QSPI)) }, 114362306a36Sopenharmony_ci { "QSPI1_SSL", RZG2L_SINGLE_PIN_PACK(0xb, 5, 114462306a36Sopenharmony_ci (PIN_CFG_IOLH_B | PIN_CFG_SR | PIN_CFG_IO_VMC_QSPI)) }, 114562306a36Sopenharmony_ci } 114662306a36Sopenharmony_ci}; 114762306a36Sopenharmony_ci 114862306a36Sopenharmony_cistatic int rzg2l_gpio_get_gpioint(unsigned int virq, const struct rzg2l_pinctrl_data *data) 114962306a36Sopenharmony_ci{ 115062306a36Sopenharmony_ci unsigned int gpioint; 115162306a36Sopenharmony_ci unsigned int i; 115262306a36Sopenharmony_ci u32 port, bit; 115362306a36Sopenharmony_ci 115462306a36Sopenharmony_ci port = virq / 8; 115562306a36Sopenharmony_ci bit = virq % 8; 115662306a36Sopenharmony_ci 115762306a36Sopenharmony_ci if (port >= data->n_ports || 115862306a36Sopenharmony_ci bit >= RZG2L_GPIO_PORT_GET_PINCNT(data->port_pin_configs[port])) 115962306a36Sopenharmony_ci return -EINVAL; 116062306a36Sopenharmony_ci 116162306a36Sopenharmony_ci gpioint = bit; 116262306a36Sopenharmony_ci for (i = 0; i < port; i++) 116362306a36Sopenharmony_ci gpioint += RZG2L_GPIO_PORT_GET_PINCNT(data->port_pin_configs[i]); 116462306a36Sopenharmony_ci 116562306a36Sopenharmony_ci return gpioint; 116662306a36Sopenharmony_ci} 116762306a36Sopenharmony_ci 116862306a36Sopenharmony_cistatic void rzg2l_gpio_irq_disable(struct irq_data *d) 116962306a36Sopenharmony_ci{ 117062306a36Sopenharmony_ci struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 117162306a36Sopenharmony_ci struct rzg2l_pinctrl *pctrl = container_of(gc, struct rzg2l_pinctrl, gpio_chip); 117262306a36Sopenharmony_ci unsigned int hwirq = irqd_to_hwirq(d); 117362306a36Sopenharmony_ci unsigned long flags; 117462306a36Sopenharmony_ci void __iomem *addr; 117562306a36Sopenharmony_ci u32 port; 117662306a36Sopenharmony_ci u8 bit; 117762306a36Sopenharmony_ci 117862306a36Sopenharmony_ci irq_chip_disable_parent(d); 117962306a36Sopenharmony_ci 118062306a36Sopenharmony_ci port = RZG2L_PIN_ID_TO_PORT(hwirq); 118162306a36Sopenharmony_ci bit = RZG2L_PIN_ID_TO_PIN(hwirq); 118262306a36Sopenharmony_ci 118362306a36Sopenharmony_ci addr = pctrl->base + ISEL(port); 118462306a36Sopenharmony_ci if (bit >= 4) { 118562306a36Sopenharmony_ci bit -= 4; 118662306a36Sopenharmony_ci addr += 4; 118762306a36Sopenharmony_ci } 118862306a36Sopenharmony_ci 118962306a36Sopenharmony_ci spin_lock_irqsave(&pctrl->lock, flags); 119062306a36Sopenharmony_ci writel(readl(addr) & ~BIT(bit * 8), addr); 119162306a36Sopenharmony_ci spin_unlock_irqrestore(&pctrl->lock, flags); 119262306a36Sopenharmony_ci 119362306a36Sopenharmony_ci gpiochip_disable_irq(gc, hwirq); 119462306a36Sopenharmony_ci} 119562306a36Sopenharmony_ci 119662306a36Sopenharmony_cistatic void rzg2l_gpio_irq_enable(struct irq_data *d) 119762306a36Sopenharmony_ci{ 119862306a36Sopenharmony_ci struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 119962306a36Sopenharmony_ci struct rzg2l_pinctrl *pctrl = container_of(gc, struct rzg2l_pinctrl, gpio_chip); 120062306a36Sopenharmony_ci unsigned int hwirq = irqd_to_hwirq(d); 120162306a36Sopenharmony_ci unsigned long flags; 120262306a36Sopenharmony_ci void __iomem *addr; 120362306a36Sopenharmony_ci u32 port; 120462306a36Sopenharmony_ci u8 bit; 120562306a36Sopenharmony_ci 120662306a36Sopenharmony_ci gpiochip_enable_irq(gc, hwirq); 120762306a36Sopenharmony_ci 120862306a36Sopenharmony_ci port = RZG2L_PIN_ID_TO_PORT(hwirq); 120962306a36Sopenharmony_ci bit = RZG2L_PIN_ID_TO_PIN(hwirq); 121062306a36Sopenharmony_ci 121162306a36Sopenharmony_ci addr = pctrl->base + ISEL(port); 121262306a36Sopenharmony_ci if (bit >= 4) { 121362306a36Sopenharmony_ci bit -= 4; 121462306a36Sopenharmony_ci addr += 4; 121562306a36Sopenharmony_ci } 121662306a36Sopenharmony_ci 121762306a36Sopenharmony_ci spin_lock_irqsave(&pctrl->lock, flags); 121862306a36Sopenharmony_ci writel(readl(addr) | BIT(bit * 8), addr); 121962306a36Sopenharmony_ci spin_unlock_irqrestore(&pctrl->lock, flags); 122062306a36Sopenharmony_ci 122162306a36Sopenharmony_ci irq_chip_enable_parent(d); 122262306a36Sopenharmony_ci} 122362306a36Sopenharmony_ci 122462306a36Sopenharmony_cistatic int rzg2l_gpio_irq_set_type(struct irq_data *d, unsigned int type) 122562306a36Sopenharmony_ci{ 122662306a36Sopenharmony_ci return irq_chip_set_type_parent(d, type); 122762306a36Sopenharmony_ci} 122862306a36Sopenharmony_ci 122962306a36Sopenharmony_cistatic void rzg2l_gpio_irqc_eoi(struct irq_data *d) 123062306a36Sopenharmony_ci{ 123162306a36Sopenharmony_ci irq_chip_eoi_parent(d); 123262306a36Sopenharmony_ci} 123362306a36Sopenharmony_ci 123462306a36Sopenharmony_cistatic void rzg2l_gpio_irq_print_chip(struct irq_data *data, struct seq_file *p) 123562306a36Sopenharmony_ci{ 123662306a36Sopenharmony_ci struct gpio_chip *gc = irq_data_get_irq_chip_data(data); 123762306a36Sopenharmony_ci 123862306a36Sopenharmony_ci seq_printf(p, dev_name(gc->parent)); 123962306a36Sopenharmony_ci} 124062306a36Sopenharmony_ci 124162306a36Sopenharmony_cistatic const struct irq_chip rzg2l_gpio_irqchip = { 124262306a36Sopenharmony_ci .name = "rzg2l-gpio", 124362306a36Sopenharmony_ci .irq_disable = rzg2l_gpio_irq_disable, 124462306a36Sopenharmony_ci .irq_enable = rzg2l_gpio_irq_enable, 124562306a36Sopenharmony_ci .irq_mask = irq_chip_mask_parent, 124662306a36Sopenharmony_ci .irq_unmask = irq_chip_unmask_parent, 124762306a36Sopenharmony_ci .irq_set_type = rzg2l_gpio_irq_set_type, 124862306a36Sopenharmony_ci .irq_eoi = rzg2l_gpio_irqc_eoi, 124962306a36Sopenharmony_ci .irq_print_chip = rzg2l_gpio_irq_print_chip, 125062306a36Sopenharmony_ci .flags = IRQCHIP_IMMUTABLE, 125162306a36Sopenharmony_ci GPIOCHIP_IRQ_RESOURCE_HELPERS, 125262306a36Sopenharmony_ci}; 125362306a36Sopenharmony_ci 125462306a36Sopenharmony_cistatic int rzg2l_gpio_child_to_parent_hwirq(struct gpio_chip *gc, 125562306a36Sopenharmony_ci unsigned int child, 125662306a36Sopenharmony_ci unsigned int child_type, 125762306a36Sopenharmony_ci unsigned int *parent, 125862306a36Sopenharmony_ci unsigned int *parent_type) 125962306a36Sopenharmony_ci{ 126062306a36Sopenharmony_ci struct rzg2l_pinctrl *pctrl = gpiochip_get_data(gc); 126162306a36Sopenharmony_ci unsigned long flags; 126262306a36Sopenharmony_ci int gpioint, irq; 126362306a36Sopenharmony_ci 126462306a36Sopenharmony_ci gpioint = rzg2l_gpio_get_gpioint(child, pctrl->data); 126562306a36Sopenharmony_ci if (gpioint < 0) 126662306a36Sopenharmony_ci return gpioint; 126762306a36Sopenharmony_ci 126862306a36Sopenharmony_ci spin_lock_irqsave(&pctrl->bitmap_lock, flags); 126962306a36Sopenharmony_ci irq = bitmap_find_free_region(pctrl->tint_slot, RZG2L_TINT_MAX_INTERRUPT, get_order(1)); 127062306a36Sopenharmony_ci spin_unlock_irqrestore(&pctrl->bitmap_lock, flags); 127162306a36Sopenharmony_ci if (irq < 0) 127262306a36Sopenharmony_ci return -ENOSPC; 127362306a36Sopenharmony_ci pctrl->hwirq[irq] = child; 127462306a36Sopenharmony_ci irq += RZG2L_TINT_IRQ_START_INDEX; 127562306a36Sopenharmony_ci 127662306a36Sopenharmony_ci /* All these interrupts are level high in the CPU */ 127762306a36Sopenharmony_ci *parent_type = IRQ_TYPE_LEVEL_HIGH; 127862306a36Sopenharmony_ci *parent = RZG2L_PACK_HWIRQ(gpioint, irq); 127962306a36Sopenharmony_ci return 0; 128062306a36Sopenharmony_ci} 128162306a36Sopenharmony_ci 128262306a36Sopenharmony_cistatic int rzg2l_gpio_populate_parent_fwspec(struct gpio_chip *chip, 128362306a36Sopenharmony_ci union gpio_irq_fwspec *gfwspec, 128462306a36Sopenharmony_ci unsigned int parent_hwirq, 128562306a36Sopenharmony_ci unsigned int parent_type) 128662306a36Sopenharmony_ci{ 128762306a36Sopenharmony_ci struct irq_fwspec *fwspec = &gfwspec->fwspec; 128862306a36Sopenharmony_ci 128962306a36Sopenharmony_ci fwspec->fwnode = chip->irq.parent_domain->fwnode; 129062306a36Sopenharmony_ci fwspec->param_count = 2; 129162306a36Sopenharmony_ci fwspec->param[0] = parent_hwirq; 129262306a36Sopenharmony_ci fwspec->param[1] = parent_type; 129362306a36Sopenharmony_ci 129462306a36Sopenharmony_ci return 0; 129562306a36Sopenharmony_ci} 129662306a36Sopenharmony_ci 129762306a36Sopenharmony_cistatic void rzg2l_gpio_irq_domain_free(struct irq_domain *domain, unsigned int virq, 129862306a36Sopenharmony_ci unsigned int nr_irqs) 129962306a36Sopenharmony_ci{ 130062306a36Sopenharmony_ci struct irq_data *d; 130162306a36Sopenharmony_ci 130262306a36Sopenharmony_ci d = irq_domain_get_irq_data(domain, virq); 130362306a36Sopenharmony_ci if (d) { 130462306a36Sopenharmony_ci struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 130562306a36Sopenharmony_ci struct rzg2l_pinctrl *pctrl = container_of(gc, struct rzg2l_pinctrl, gpio_chip); 130662306a36Sopenharmony_ci irq_hw_number_t hwirq = irqd_to_hwirq(d); 130762306a36Sopenharmony_ci unsigned long flags; 130862306a36Sopenharmony_ci unsigned int i; 130962306a36Sopenharmony_ci 131062306a36Sopenharmony_ci for (i = 0; i < RZG2L_TINT_MAX_INTERRUPT; i++) { 131162306a36Sopenharmony_ci if (pctrl->hwirq[i] == hwirq) { 131262306a36Sopenharmony_ci spin_lock_irqsave(&pctrl->bitmap_lock, flags); 131362306a36Sopenharmony_ci bitmap_release_region(pctrl->tint_slot, i, get_order(1)); 131462306a36Sopenharmony_ci spin_unlock_irqrestore(&pctrl->bitmap_lock, flags); 131562306a36Sopenharmony_ci pctrl->hwirq[i] = 0; 131662306a36Sopenharmony_ci break; 131762306a36Sopenharmony_ci } 131862306a36Sopenharmony_ci } 131962306a36Sopenharmony_ci } 132062306a36Sopenharmony_ci irq_domain_free_irqs_common(domain, virq, nr_irqs); 132162306a36Sopenharmony_ci} 132262306a36Sopenharmony_ci 132362306a36Sopenharmony_cistatic void rzg2l_init_irq_valid_mask(struct gpio_chip *gc, 132462306a36Sopenharmony_ci unsigned long *valid_mask, 132562306a36Sopenharmony_ci unsigned int ngpios) 132662306a36Sopenharmony_ci{ 132762306a36Sopenharmony_ci struct rzg2l_pinctrl *pctrl = gpiochip_get_data(gc); 132862306a36Sopenharmony_ci struct gpio_chip *chip = &pctrl->gpio_chip; 132962306a36Sopenharmony_ci unsigned int offset; 133062306a36Sopenharmony_ci 133162306a36Sopenharmony_ci /* Forbid unused lines to be mapped as IRQs */ 133262306a36Sopenharmony_ci for (offset = 0; offset < chip->ngpio; offset++) { 133362306a36Sopenharmony_ci u32 port, bit; 133462306a36Sopenharmony_ci 133562306a36Sopenharmony_ci port = offset / 8; 133662306a36Sopenharmony_ci bit = offset % 8; 133762306a36Sopenharmony_ci 133862306a36Sopenharmony_ci if (port >= pctrl->data->n_ports || 133962306a36Sopenharmony_ci bit >= RZG2L_GPIO_PORT_GET_PINCNT(pctrl->data->port_pin_configs[port])) 134062306a36Sopenharmony_ci clear_bit(offset, valid_mask); 134162306a36Sopenharmony_ci } 134262306a36Sopenharmony_ci} 134362306a36Sopenharmony_ci 134462306a36Sopenharmony_cistatic int rzg2l_gpio_register(struct rzg2l_pinctrl *pctrl) 134562306a36Sopenharmony_ci{ 134662306a36Sopenharmony_ci struct device_node *np = pctrl->dev->of_node; 134762306a36Sopenharmony_ci struct gpio_chip *chip = &pctrl->gpio_chip; 134862306a36Sopenharmony_ci const char *name = dev_name(pctrl->dev); 134962306a36Sopenharmony_ci struct irq_domain *parent_domain; 135062306a36Sopenharmony_ci struct of_phandle_args of_args; 135162306a36Sopenharmony_ci struct device_node *parent_np; 135262306a36Sopenharmony_ci struct gpio_irq_chip *girq; 135362306a36Sopenharmony_ci int ret; 135462306a36Sopenharmony_ci 135562306a36Sopenharmony_ci parent_np = of_irq_find_parent(np); 135662306a36Sopenharmony_ci if (!parent_np) 135762306a36Sopenharmony_ci return -ENXIO; 135862306a36Sopenharmony_ci 135962306a36Sopenharmony_ci parent_domain = irq_find_host(parent_np); 136062306a36Sopenharmony_ci of_node_put(parent_np); 136162306a36Sopenharmony_ci if (!parent_domain) 136262306a36Sopenharmony_ci return -EPROBE_DEFER; 136362306a36Sopenharmony_ci 136462306a36Sopenharmony_ci ret = of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3, 0, &of_args); 136562306a36Sopenharmony_ci if (ret) { 136662306a36Sopenharmony_ci dev_err(pctrl->dev, "Unable to parse gpio-ranges\n"); 136762306a36Sopenharmony_ci return ret; 136862306a36Sopenharmony_ci } 136962306a36Sopenharmony_ci 137062306a36Sopenharmony_ci if (of_args.args[0] != 0 || of_args.args[1] != 0 || 137162306a36Sopenharmony_ci of_args.args[2] != pctrl->data->n_port_pins) { 137262306a36Sopenharmony_ci dev_err(pctrl->dev, "gpio-ranges does not match selected SOC\n"); 137362306a36Sopenharmony_ci return -EINVAL; 137462306a36Sopenharmony_ci } 137562306a36Sopenharmony_ci 137662306a36Sopenharmony_ci chip->names = pctrl->data->port_pins; 137762306a36Sopenharmony_ci chip->request = rzg2l_gpio_request; 137862306a36Sopenharmony_ci chip->free = rzg2l_gpio_free; 137962306a36Sopenharmony_ci chip->get_direction = rzg2l_gpio_get_direction; 138062306a36Sopenharmony_ci chip->direction_input = rzg2l_gpio_direction_input; 138162306a36Sopenharmony_ci chip->direction_output = rzg2l_gpio_direction_output; 138262306a36Sopenharmony_ci chip->get = rzg2l_gpio_get; 138362306a36Sopenharmony_ci chip->set = rzg2l_gpio_set; 138462306a36Sopenharmony_ci chip->label = name; 138562306a36Sopenharmony_ci chip->parent = pctrl->dev; 138662306a36Sopenharmony_ci chip->owner = THIS_MODULE; 138762306a36Sopenharmony_ci chip->base = -1; 138862306a36Sopenharmony_ci chip->ngpio = of_args.args[2]; 138962306a36Sopenharmony_ci 139062306a36Sopenharmony_ci girq = &chip->irq; 139162306a36Sopenharmony_ci gpio_irq_chip_set_chip(girq, &rzg2l_gpio_irqchip); 139262306a36Sopenharmony_ci girq->fwnode = of_node_to_fwnode(np); 139362306a36Sopenharmony_ci girq->parent_domain = parent_domain; 139462306a36Sopenharmony_ci girq->child_to_parent_hwirq = rzg2l_gpio_child_to_parent_hwirq; 139562306a36Sopenharmony_ci girq->populate_parent_alloc_arg = rzg2l_gpio_populate_parent_fwspec; 139662306a36Sopenharmony_ci girq->child_irq_domain_ops.free = rzg2l_gpio_irq_domain_free; 139762306a36Sopenharmony_ci girq->init_valid_mask = rzg2l_init_irq_valid_mask; 139862306a36Sopenharmony_ci 139962306a36Sopenharmony_ci pctrl->gpio_range.id = 0; 140062306a36Sopenharmony_ci pctrl->gpio_range.pin_base = 0; 140162306a36Sopenharmony_ci pctrl->gpio_range.base = 0; 140262306a36Sopenharmony_ci pctrl->gpio_range.npins = chip->ngpio; 140362306a36Sopenharmony_ci pctrl->gpio_range.name = chip->label; 140462306a36Sopenharmony_ci pctrl->gpio_range.gc = chip; 140562306a36Sopenharmony_ci ret = devm_gpiochip_add_data(pctrl->dev, chip, pctrl); 140662306a36Sopenharmony_ci if (ret) { 140762306a36Sopenharmony_ci dev_err(pctrl->dev, "failed to add GPIO controller\n"); 140862306a36Sopenharmony_ci return ret; 140962306a36Sopenharmony_ci } 141062306a36Sopenharmony_ci 141162306a36Sopenharmony_ci dev_dbg(pctrl->dev, "Registered gpio controller\n"); 141262306a36Sopenharmony_ci 141362306a36Sopenharmony_ci return 0; 141462306a36Sopenharmony_ci} 141562306a36Sopenharmony_ci 141662306a36Sopenharmony_cistatic int rzg2l_pinctrl_register(struct rzg2l_pinctrl *pctrl) 141762306a36Sopenharmony_ci{ 141862306a36Sopenharmony_ci struct pinctrl_pin_desc *pins; 141962306a36Sopenharmony_ci unsigned int i, j; 142062306a36Sopenharmony_ci u32 *pin_data; 142162306a36Sopenharmony_ci int ret; 142262306a36Sopenharmony_ci 142362306a36Sopenharmony_ci pctrl->desc.name = DRV_NAME; 142462306a36Sopenharmony_ci pctrl->desc.npins = pctrl->data->n_port_pins + pctrl->data->n_dedicated_pins; 142562306a36Sopenharmony_ci pctrl->desc.pctlops = &rzg2l_pinctrl_pctlops; 142662306a36Sopenharmony_ci pctrl->desc.pmxops = &rzg2l_pinctrl_pmxops; 142762306a36Sopenharmony_ci pctrl->desc.confops = &rzg2l_pinctrl_confops; 142862306a36Sopenharmony_ci pctrl->desc.owner = THIS_MODULE; 142962306a36Sopenharmony_ci 143062306a36Sopenharmony_ci pins = devm_kcalloc(pctrl->dev, pctrl->desc.npins, sizeof(*pins), GFP_KERNEL); 143162306a36Sopenharmony_ci if (!pins) 143262306a36Sopenharmony_ci return -ENOMEM; 143362306a36Sopenharmony_ci 143462306a36Sopenharmony_ci pin_data = devm_kcalloc(pctrl->dev, pctrl->desc.npins, 143562306a36Sopenharmony_ci sizeof(*pin_data), GFP_KERNEL); 143662306a36Sopenharmony_ci if (!pin_data) 143762306a36Sopenharmony_ci return -ENOMEM; 143862306a36Sopenharmony_ci 143962306a36Sopenharmony_ci pctrl->pins = pins; 144062306a36Sopenharmony_ci pctrl->desc.pins = pins; 144162306a36Sopenharmony_ci 144262306a36Sopenharmony_ci for (i = 0, j = 0; i < pctrl->data->n_port_pins; i++) { 144362306a36Sopenharmony_ci pins[i].number = i; 144462306a36Sopenharmony_ci pins[i].name = pctrl->data->port_pins[i]; 144562306a36Sopenharmony_ci if (i && !(i % RZG2L_PINS_PER_PORT)) 144662306a36Sopenharmony_ci j++; 144762306a36Sopenharmony_ci pin_data[i] = pctrl->data->port_pin_configs[j]; 144862306a36Sopenharmony_ci pins[i].drv_data = &pin_data[i]; 144962306a36Sopenharmony_ci } 145062306a36Sopenharmony_ci 145162306a36Sopenharmony_ci for (i = 0; i < pctrl->data->n_dedicated_pins; i++) { 145262306a36Sopenharmony_ci unsigned int index = pctrl->data->n_port_pins + i; 145362306a36Sopenharmony_ci 145462306a36Sopenharmony_ci pins[index].number = index; 145562306a36Sopenharmony_ci pins[index].name = pctrl->data->dedicated_pins[i].name; 145662306a36Sopenharmony_ci pin_data[index] = pctrl->data->dedicated_pins[i].config; 145762306a36Sopenharmony_ci pins[index].drv_data = &pin_data[index]; 145862306a36Sopenharmony_ci } 145962306a36Sopenharmony_ci 146062306a36Sopenharmony_ci ret = devm_pinctrl_register_and_init(pctrl->dev, &pctrl->desc, pctrl, 146162306a36Sopenharmony_ci &pctrl->pctl); 146262306a36Sopenharmony_ci if (ret) { 146362306a36Sopenharmony_ci dev_err(pctrl->dev, "pinctrl registration failed\n"); 146462306a36Sopenharmony_ci return ret; 146562306a36Sopenharmony_ci } 146662306a36Sopenharmony_ci 146762306a36Sopenharmony_ci ret = pinctrl_enable(pctrl->pctl); 146862306a36Sopenharmony_ci if (ret) { 146962306a36Sopenharmony_ci dev_err(pctrl->dev, "pinctrl enable failed\n"); 147062306a36Sopenharmony_ci return ret; 147162306a36Sopenharmony_ci } 147262306a36Sopenharmony_ci 147362306a36Sopenharmony_ci ret = rzg2l_gpio_register(pctrl); 147462306a36Sopenharmony_ci if (ret) { 147562306a36Sopenharmony_ci dev_err(pctrl->dev, "failed to add GPIO chip: %i\n", ret); 147662306a36Sopenharmony_ci return ret; 147762306a36Sopenharmony_ci } 147862306a36Sopenharmony_ci 147962306a36Sopenharmony_ci return 0; 148062306a36Sopenharmony_ci} 148162306a36Sopenharmony_ci 148262306a36Sopenharmony_cistatic int rzg2l_pinctrl_probe(struct platform_device *pdev) 148362306a36Sopenharmony_ci{ 148462306a36Sopenharmony_ci struct rzg2l_pinctrl *pctrl; 148562306a36Sopenharmony_ci struct clk *clk; 148662306a36Sopenharmony_ci int ret; 148762306a36Sopenharmony_ci 148862306a36Sopenharmony_ci BUILD_BUG_ON(ARRAY_SIZE(rzg2l_gpio_configs) * RZG2L_PINS_PER_PORT > 148962306a36Sopenharmony_ci ARRAY_SIZE(rzg2l_gpio_names)); 149062306a36Sopenharmony_ci 149162306a36Sopenharmony_ci BUILD_BUG_ON(ARRAY_SIZE(r9a07g043_gpio_configs) * RZG2L_PINS_PER_PORT > 149262306a36Sopenharmony_ci ARRAY_SIZE(rzg2l_gpio_names)); 149362306a36Sopenharmony_ci 149462306a36Sopenharmony_ci pctrl = devm_kzalloc(&pdev->dev, sizeof(*pctrl), GFP_KERNEL); 149562306a36Sopenharmony_ci if (!pctrl) 149662306a36Sopenharmony_ci return -ENOMEM; 149762306a36Sopenharmony_ci 149862306a36Sopenharmony_ci pctrl->dev = &pdev->dev; 149962306a36Sopenharmony_ci 150062306a36Sopenharmony_ci pctrl->data = of_device_get_match_data(&pdev->dev); 150162306a36Sopenharmony_ci if (!pctrl->data) 150262306a36Sopenharmony_ci return -EINVAL; 150362306a36Sopenharmony_ci 150462306a36Sopenharmony_ci pctrl->base = devm_platform_ioremap_resource(pdev, 0); 150562306a36Sopenharmony_ci if (IS_ERR(pctrl->base)) 150662306a36Sopenharmony_ci return PTR_ERR(pctrl->base); 150762306a36Sopenharmony_ci 150862306a36Sopenharmony_ci clk = devm_clk_get_enabled(pctrl->dev, NULL); 150962306a36Sopenharmony_ci if (IS_ERR(clk)) 151062306a36Sopenharmony_ci return dev_err_probe(pctrl->dev, PTR_ERR(clk), 151162306a36Sopenharmony_ci "failed to enable GPIO clk\n"); 151262306a36Sopenharmony_ci 151362306a36Sopenharmony_ci spin_lock_init(&pctrl->lock); 151462306a36Sopenharmony_ci spin_lock_init(&pctrl->bitmap_lock); 151562306a36Sopenharmony_ci mutex_init(&pctrl->mutex); 151662306a36Sopenharmony_ci 151762306a36Sopenharmony_ci platform_set_drvdata(pdev, pctrl); 151862306a36Sopenharmony_ci 151962306a36Sopenharmony_ci ret = rzg2l_pinctrl_register(pctrl); 152062306a36Sopenharmony_ci if (ret) 152162306a36Sopenharmony_ci return ret; 152262306a36Sopenharmony_ci 152362306a36Sopenharmony_ci dev_info(pctrl->dev, "%s support registered\n", DRV_NAME); 152462306a36Sopenharmony_ci return 0; 152562306a36Sopenharmony_ci} 152662306a36Sopenharmony_ci 152762306a36Sopenharmony_cistatic struct rzg2l_pinctrl_data r9a07g043_data = { 152862306a36Sopenharmony_ci .port_pins = rzg2l_gpio_names, 152962306a36Sopenharmony_ci .port_pin_configs = r9a07g043_gpio_configs, 153062306a36Sopenharmony_ci .n_ports = ARRAY_SIZE(r9a07g043_gpio_configs), 153162306a36Sopenharmony_ci .dedicated_pins = rzg2l_dedicated_pins.common, 153262306a36Sopenharmony_ci .n_port_pins = ARRAY_SIZE(r9a07g043_gpio_configs) * RZG2L_PINS_PER_PORT, 153362306a36Sopenharmony_ci .n_dedicated_pins = ARRAY_SIZE(rzg2l_dedicated_pins.common), 153462306a36Sopenharmony_ci}; 153562306a36Sopenharmony_ci 153662306a36Sopenharmony_cistatic struct rzg2l_pinctrl_data r9a07g044_data = { 153762306a36Sopenharmony_ci .port_pins = rzg2l_gpio_names, 153862306a36Sopenharmony_ci .port_pin_configs = rzg2l_gpio_configs, 153962306a36Sopenharmony_ci .n_ports = ARRAY_SIZE(rzg2l_gpio_configs), 154062306a36Sopenharmony_ci .dedicated_pins = rzg2l_dedicated_pins.common, 154162306a36Sopenharmony_ci .n_port_pins = ARRAY_SIZE(rzg2l_gpio_configs) * RZG2L_PINS_PER_PORT, 154262306a36Sopenharmony_ci .n_dedicated_pins = ARRAY_SIZE(rzg2l_dedicated_pins.common) + 154362306a36Sopenharmony_ci ARRAY_SIZE(rzg2l_dedicated_pins.rzg2l_pins), 154462306a36Sopenharmony_ci}; 154562306a36Sopenharmony_ci 154662306a36Sopenharmony_cistatic const struct of_device_id rzg2l_pinctrl_of_table[] = { 154762306a36Sopenharmony_ci { 154862306a36Sopenharmony_ci .compatible = "renesas,r9a07g043-pinctrl", 154962306a36Sopenharmony_ci .data = &r9a07g043_data, 155062306a36Sopenharmony_ci }, 155162306a36Sopenharmony_ci { 155262306a36Sopenharmony_ci .compatible = "renesas,r9a07g044-pinctrl", 155362306a36Sopenharmony_ci .data = &r9a07g044_data, 155462306a36Sopenharmony_ci }, 155562306a36Sopenharmony_ci { /* sentinel */ } 155662306a36Sopenharmony_ci}; 155762306a36Sopenharmony_ci 155862306a36Sopenharmony_cistatic struct platform_driver rzg2l_pinctrl_driver = { 155962306a36Sopenharmony_ci .driver = { 156062306a36Sopenharmony_ci .name = DRV_NAME, 156162306a36Sopenharmony_ci .of_match_table = of_match_ptr(rzg2l_pinctrl_of_table), 156262306a36Sopenharmony_ci }, 156362306a36Sopenharmony_ci .probe = rzg2l_pinctrl_probe, 156462306a36Sopenharmony_ci}; 156562306a36Sopenharmony_ci 156662306a36Sopenharmony_cistatic int __init rzg2l_pinctrl_init(void) 156762306a36Sopenharmony_ci{ 156862306a36Sopenharmony_ci return platform_driver_register(&rzg2l_pinctrl_driver); 156962306a36Sopenharmony_ci} 157062306a36Sopenharmony_cicore_initcall(rzg2l_pinctrl_init); 157162306a36Sopenharmony_ci 157262306a36Sopenharmony_ciMODULE_AUTHOR("Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>"); 157362306a36Sopenharmony_ciMODULE_DESCRIPTION("Pin and gpio controller driver for RZ/G2L family"); 1574