162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci * 362306a36Sopenharmony_ci * SuperH Pin Function Controller Support 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (c) 2008 Magnus Damm 662306a36Sopenharmony_ci */ 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci#ifndef __SH_PFC_H 962306a36Sopenharmony_ci#define __SH_PFC_H 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#include <linux/bug.h> 1262306a36Sopenharmony_ci#include <linux/pinctrl/pinconf-generic.h> 1362306a36Sopenharmony_ci#include <linux/spinlock.h> 1462306a36Sopenharmony_ci#include <linux/stringify.h> 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_cienum { 1762306a36Sopenharmony_ci PINMUX_TYPE_NONE, 1862306a36Sopenharmony_ci PINMUX_TYPE_FUNCTION, 1962306a36Sopenharmony_ci PINMUX_TYPE_GPIO, 2062306a36Sopenharmony_ci PINMUX_TYPE_OUTPUT, 2162306a36Sopenharmony_ci PINMUX_TYPE_INPUT, 2262306a36Sopenharmony_ci}; 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci#define SH_PFC_PIN_NONE U16_MAX 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci#define SH_PFC_PIN_CFG_INPUT (1 << 0) 2762306a36Sopenharmony_ci#define SH_PFC_PIN_CFG_OUTPUT (1 << 1) 2862306a36Sopenharmony_ci#define SH_PFC_PIN_CFG_PULL_UP (1 << 2) 2962306a36Sopenharmony_ci#define SH_PFC_PIN_CFG_PULL_DOWN (1 << 3) 3062306a36Sopenharmony_ci#define SH_PFC_PIN_CFG_PULL_UP_DOWN (SH_PFC_PIN_CFG_PULL_UP | \ 3162306a36Sopenharmony_ci SH_PFC_PIN_CFG_PULL_DOWN) 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ci#define SH_PFC_PIN_CFG_IO_VOLTAGE_MASK GENMASK(5, 4) 3462306a36Sopenharmony_ci#define SH_PFC_PIN_CFG_IO_VOLTAGE_18_25 (1 << 4) 3562306a36Sopenharmony_ci#define SH_PFC_PIN_CFG_IO_VOLTAGE_18_33 (2 << 4) 3662306a36Sopenharmony_ci#define SH_PFC_PIN_CFG_IO_VOLTAGE_25_33 (3 << 4) 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci#define SH_PFC_PIN_CFG_DRIVE_STRENGTH (1 << 6) 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci#define SH_PFC_PIN_CFG_NO_GPIO (1 << 31) 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_cistruct sh_pfc_pin { 4362306a36Sopenharmony_ci const char *name; 4462306a36Sopenharmony_ci unsigned int configs; 4562306a36Sopenharmony_ci u16 pin; 4662306a36Sopenharmony_ci u16 enum_id; 4762306a36Sopenharmony_ci}; 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci#define SH_PFC_PIN_GROUP_ALIAS(alias, _name) { \ 5062306a36Sopenharmony_ci .name = #alias, \ 5162306a36Sopenharmony_ci .pins = _name##_pins, \ 5262306a36Sopenharmony_ci .mux = _name##_mux, \ 5362306a36Sopenharmony_ci .nr_pins = ARRAY_SIZE(_name##_pins) + \ 5462306a36Sopenharmony_ci BUILD_BUG_ON_ZERO(sizeof(_name##_pins) != sizeof(_name##_mux)), \ 5562306a36Sopenharmony_ci} 5662306a36Sopenharmony_ci#define SH_PFC_PIN_GROUP(name) SH_PFC_PIN_GROUP_ALIAS(name, name) 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci/* 5962306a36Sopenharmony_ci * Define a pin group referring to a subset of an array of pins. 6062306a36Sopenharmony_ci */ 6162306a36Sopenharmony_ci#define SH_PFC_PIN_GROUP_SUBSET(_name, data, first, n) { \ 6262306a36Sopenharmony_ci .name = #_name, \ 6362306a36Sopenharmony_ci .pins = data##_pins + first, \ 6462306a36Sopenharmony_ci .mux = data##_mux + first, \ 6562306a36Sopenharmony_ci .nr_pins = n + \ 6662306a36Sopenharmony_ci BUILD_BUG_ON_ZERO(first + n > ARRAY_SIZE(data##_pins)) + \ 6762306a36Sopenharmony_ci BUILD_BUG_ON_ZERO(first + n > ARRAY_SIZE(data##_mux)), \ 6862306a36Sopenharmony_ci} 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ci/* 7162306a36Sopenharmony_ci * Define a pin group for the data pins of a resizable bus. 7262306a36Sopenharmony_ci * An optional 'suffix' argument is accepted, to be used when the same group 7362306a36Sopenharmony_ci * can appear on a different set of pins. 7462306a36Sopenharmony_ci */ 7562306a36Sopenharmony_ci#define BUS_DATA_PIN_GROUP(base, n, ...) \ 7662306a36Sopenharmony_ci SH_PFC_PIN_GROUP_SUBSET(base##n##__VA_ARGS__, base##__VA_ARGS__, 0, n) 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_cistruct sh_pfc_pin_group { 7962306a36Sopenharmony_ci const char *name; 8062306a36Sopenharmony_ci const unsigned int *pins; 8162306a36Sopenharmony_ci const unsigned int *mux; 8262306a36Sopenharmony_ci unsigned int nr_pins; 8362306a36Sopenharmony_ci}; 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci#define SH_PFC_FUNCTION(n) { \ 8662306a36Sopenharmony_ci .name = #n, \ 8762306a36Sopenharmony_ci .groups = n##_groups, \ 8862306a36Sopenharmony_ci .nr_groups = ARRAY_SIZE(n##_groups), \ 8962306a36Sopenharmony_ci} 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_cistruct sh_pfc_function { 9262306a36Sopenharmony_ci const char *name; 9362306a36Sopenharmony_ci const char * const *groups; 9462306a36Sopenharmony_ci unsigned int nr_groups; 9562306a36Sopenharmony_ci}; 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_cistruct pinmux_func { 9862306a36Sopenharmony_ci u16 enum_id; 9962306a36Sopenharmony_ci const char *name; 10062306a36Sopenharmony_ci}; 10162306a36Sopenharmony_ci 10262306a36Sopenharmony_cistruct pinmux_cfg_reg { 10362306a36Sopenharmony_ci u32 reg; 10462306a36Sopenharmony_ci u8 reg_width, field_width; 10562306a36Sopenharmony_ci#ifdef DEBUG 10662306a36Sopenharmony_ci u16 nr_enum_ids; /* for variable width regs only */ 10762306a36Sopenharmony_ci#define SET_NR_ENUM_IDS(n) .nr_enum_ids = n, 10862306a36Sopenharmony_ci#else 10962306a36Sopenharmony_ci#define SET_NR_ENUM_IDS(n) 11062306a36Sopenharmony_ci#endif 11162306a36Sopenharmony_ci const u16 *enum_ids; 11262306a36Sopenharmony_ci const s8 *var_field_width; 11362306a36Sopenharmony_ci}; 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ci#define GROUP(...) __VA_ARGS__ 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_ci/* 11862306a36Sopenharmony_ci * Describe a config register consisting of several fields of the same width 11962306a36Sopenharmony_ci * - name: Register name (unused, for documentation purposes only) 12062306a36Sopenharmony_ci * - r: Physical register address 12162306a36Sopenharmony_ci * - r_width: Width of the register (in bits) 12262306a36Sopenharmony_ci * - f_width: Width of the fixed-width register fields (in bits) 12362306a36Sopenharmony_ci * - ids: For each register field (from left to right, i.e. MSB to LSB), 12462306a36Sopenharmony_ci * 2^f_width enum IDs must be specified, one for each possible 12562306a36Sopenharmony_ci * combination of the register field bit values, all wrapped using 12662306a36Sopenharmony_ci * the GROUP() macro. 12762306a36Sopenharmony_ci */ 12862306a36Sopenharmony_ci#define PINMUX_CFG_REG(name, r, r_width, f_width, ids) \ 12962306a36Sopenharmony_ci .reg = r, .reg_width = r_width, \ 13062306a36Sopenharmony_ci .field_width = f_width + BUILD_BUG_ON_ZERO(r_width % f_width) + \ 13162306a36Sopenharmony_ci BUILD_BUG_ON_ZERO(sizeof((const u16 []) { ids }) / sizeof(u16) != \ 13262306a36Sopenharmony_ci (r_width / f_width) << f_width), \ 13362306a36Sopenharmony_ci .enum_ids = (const u16 [(r_width / f_width) << f_width]) { ids } 13462306a36Sopenharmony_ci 13562306a36Sopenharmony_ci/* 13662306a36Sopenharmony_ci * Describe a config register consisting of several fields of different widths 13762306a36Sopenharmony_ci * - name: Register name (unused, for documentation purposes only) 13862306a36Sopenharmony_ci * - r: Physical register address 13962306a36Sopenharmony_ci * - r_width: Width of the register (in bits) 14062306a36Sopenharmony_ci * - f_widths: List of widths of the register fields (in bits), from left 14162306a36Sopenharmony_ci * to right (i.e. MSB to LSB), wrapped using the GROUP() macro. 14262306a36Sopenharmony_ci * Reserved fields are indicated by negating the field width. 14362306a36Sopenharmony_ci * - ids: For each non-reserved register field (from left to right, i.e. MSB 14462306a36Sopenharmony_ci * to LSB), 2^f_widths[i] enum IDs must be specified, one for each 14562306a36Sopenharmony_ci * possible combination of the register field bit values, all wrapped 14662306a36Sopenharmony_ci * using the GROUP() macro. 14762306a36Sopenharmony_ci */ 14862306a36Sopenharmony_ci#define PINMUX_CFG_REG_VAR(name, r, r_width, f_widths, ids) \ 14962306a36Sopenharmony_ci .reg = r, .reg_width = r_width, \ 15062306a36Sopenharmony_ci .var_field_width = (const s8 []) { f_widths, 0 }, \ 15162306a36Sopenharmony_ci SET_NR_ENUM_IDS(sizeof((const u16 []) { ids }) / sizeof(u16)) \ 15262306a36Sopenharmony_ci .enum_ids = (const u16 []) { ids } 15362306a36Sopenharmony_ci 15462306a36Sopenharmony_cistruct pinmux_drive_reg_field { 15562306a36Sopenharmony_ci u16 pin; 15662306a36Sopenharmony_ci u8 offset; 15762306a36Sopenharmony_ci u8 size; 15862306a36Sopenharmony_ci}; 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_cistruct pinmux_drive_reg { 16162306a36Sopenharmony_ci u32 reg; 16262306a36Sopenharmony_ci const struct pinmux_drive_reg_field fields[10]; 16362306a36Sopenharmony_ci}; 16462306a36Sopenharmony_ci 16562306a36Sopenharmony_ci#define PINMUX_DRIVE_REG(name, r) \ 16662306a36Sopenharmony_ci .reg = r, \ 16762306a36Sopenharmony_ci .fields = 16862306a36Sopenharmony_ci 16962306a36Sopenharmony_cistruct pinmux_bias_reg { /* At least one of puen/pud must exist */ 17062306a36Sopenharmony_ci u32 puen; /* Pull-enable or pull-up control register */ 17162306a36Sopenharmony_ci u32 pud; /* Pull-up/down or pull-down control register */ 17262306a36Sopenharmony_ci const u16 pins[32]; 17362306a36Sopenharmony_ci}; 17462306a36Sopenharmony_ci 17562306a36Sopenharmony_ci#define PINMUX_BIAS_REG(name1, r1, name2, r2) \ 17662306a36Sopenharmony_ci .puen = r1, \ 17762306a36Sopenharmony_ci .pud = r2, \ 17862306a36Sopenharmony_ci .pins = 17962306a36Sopenharmony_ci 18062306a36Sopenharmony_cistruct pinmux_ioctrl_reg { 18162306a36Sopenharmony_ci u32 reg; 18262306a36Sopenharmony_ci}; 18362306a36Sopenharmony_ci 18462306a36Sopenharmony_cistruct pinmux_data_reg { 18562306a36Sopenharmony_ci u32 reg; 18662306a36Sopenharmony_ci u8 reg_width; 18762306a36Sopenharmony_ci const u16 *enum_ids; 18862306a36Sopenharmony_ci}; 18962306a36Sopenharmony_ci 19062306a36Sopenharmony_ci/* 19162306a36Sopenharmony_ci * Describe a data register 19262306a36Sopenharmony_ci * - name: Register name (unused, for documentation purposes only) 19362306a36Sopenharmony_ci * - r: Physical register address 19462306a36Sopenharmony_ci * - r_width: Width of the register (in bits) 19562306a36Sopenharmony_ci * - ids: For each register bit (from left to right, i.e. MSB to LSB), one 19662306a36Sopenharmony_ci * enum ID must be specified, all wrapped using the GROUP() macro. 19762306a36Sopenharmony_ci */ 19862306a36Sopenharmony_ci#define PINMUX_DATA_REG(name, r, r_width, ids) \ 19962306a36Sopenharmony_ci .reg = r, .reg_width = r_width + \ 20062306a36Sopenharmony_ci BUILD_BUG_ON_ZERO(sizeof((const u16 []) { ids }) / sizeof(u16) != \ 20162306a36Sopenharmony_ci r_width), \ 20262306a36Sopenharmony_ci .enum_ids = (const u16 [r_width]) { ids } 20362306a36Sopenharmony_ci 20462306a36Sopenharmony_cistruct pinmux_irq { 20562306a36Sopenharmony_ci const short *gpios; 20662306a36Sopenharmony_ci}; 20762306a36Sopenharmony_ci 20862306a36Sopenharmony_ci/* 20962306a36Sopenharmony_ci * Describe the mapping from GPIOs to a single IRQ 21062306a36Sopenharmony_ci * - ids...: List of GPIOs that are mapped to the same IRQ 21162306a36Sopenharmony_ci */ 21262306a36Sopenharmony_ci#define PINMUX_IRQ(ids...) { \ 21362306a36Sopenharmony_ci .gpios = (const short []) { ids, -1 } \ 21462306a36Sopenharmony_ci} 21562306a36Sopenharmony_ci 21662306a36Sopenharmony_cistruct pinmux_range { 21762306a36Sopenharmony_ci u16 begin; 21862306a36Sopenharmony_ci u16 end; 21962306a36Sopenharmony_ci u16 force; 22062306a36Sopenharmony_ci}; 22162306a36Sopenharmony_ci 22262306a36Sopenharmony_cistruct sh_pfc_window { 22362306a36Sopenharmony_ci phys_addr_t phys; 22462306a36Sopenharmony_ci void __iomem *virt; 22562306a36Sopenharmony_ci unsigned long size; 22662306a36Sopenharmony_ci}; 22762306a36Sopenharmony_ci 22862306a36Sopenharmony_cistruct sh_pfc_pin_range; 22962306a36Sopenharmony_ci 23062306a36Sopenharmony_cistruct sh_pfc { 23162306a36Sopenharmony_ci struct device *dev; 23262306a36Sopenharmony_ci const struct sh_pfc_soc_info *info; 23362306a36Sopenharmony_ci spinlock_t lock; 23462306a36Sopenharmony_ci 23562306a36Sopenharmony_ci unsigned int num_windows; 23662306a36Sopenharmony_ci struct sh_pfc_window *windows; 23762306a36Sopenharmony_ci unsigned int num_irqs; 23862306a36Sopenharmony_ci unsigned int *irqs; 23962306a36Sopenharmony_ci 24062306a36Sopenharmony_ci struct sh_pfc_pin_range *ranges; 24162306a36Sopenharmony_ci unsigned int nr_ranges; 24262306a36Sopenharmony_ci 24362306a36Sopenharmony_ci unsigned int nr_gpio_pins; 24462306a36Sopenharmony_ci 24562306a36Sopenharmony_ci struct sh_pfc_chip *gpio; 24662306a36Sopenharmony_ci u32 *saved_regs; 24762306a36Sopenharmony_ci}; 24862306a36Sopenharmony_ci 24962306a36Sopenharmony_cistruct sh_pfc_soc_operations { 25062306a36Sopenharmony_ci int (*init)(struct sh_pfc *pfc); 25162306a36Sopenharmony_ci unsigned int (*get_bias)(struct sh_pfc *pfc, unsigned int pin); 25262306a36Sopenharmony_ci void (*set_bias)(struct sh_pfc *pfc, unsigned int pin, 25362306a36Sopenharmony_ci unsigned int bias); 25462306a36Sopenharmony_ci int (*pin_to_pocctrl)(unsigned int pin, u32 *pocctrl); 25562306a36Sopenharmony_ci int (*pin_to_portcr)(unsigned int pin); 25662306a36Sopenharmony_ci}; 25762306a36Sopenharmony_ci 25862306a36Sopenharmony_cistruct sh_pfc_soc_info { 25962306a36Sopenharmony_ci const char *name; 26062306a36Sopenharmony_ci const struct sh_pfc_soc_operations *ops; 26162306a36Sopenharmony_ci 26262306a36Sopenharmony_ci#ifdef CONFIG_PINCTRL_SH_PFC_GPIO 26362306a36Sopenharmony_ci struct pinmux_range input; 26462306a36Sopenharmony_ci struct pinmux_range output; 26562306a36Sopenharmony_ci const struct pinmux_irq *gpio_irq; 26662306a36Sopenharmony_ci unsigned int gpio_irq_size; 26762306a36Sopenharmony_ci#endif 26862306a36Sopenharmony_ci 26962306a36Sopenharmony_ci struct pinmux_range function; 27062306a36Sopenharmony_ci 27162306a36Sopenharmony_ci const struct sh_pfc_pin *pins; 27262306a36Sopenharmony_ci unsigned int nr_pins; 27362306a36Sopenharmony_ci const struct sh_pfc_pin_group *groups; 27462306a36Sopenharmony_ci unsigned int nr_groups; 27562306a36Sopenharmony_ci const struct sh_pfc_function *functions; 27662306a36Sopenharmony_ci unsigned int nr_functions; 27762306a36Sopenharmony_ci 27862306a36Sopenharmony_ci#ifdef CONFIG_PINCTRL_SH_FUNC_GPIO 27962306a36Sopenharmony_ci const struct pinmux_func *func_gpios; 28062306a36Sopenharmony_ci unsigned int nr_func_gpios; 28162306a36Sopenharmony_ci#endif 28262306a36Sopenharmony_ci 28362306a36Sopenharmony_ci const struct pinmux_cfg_reg *cfg_regs; 28462306a36Sopenharmony_ci const struct pinmux_drive_reg *drive_regs; 28562306a36Sopenharmony_ci const struct pinmux_bias_reg *bias_regs; 28662306a36Sopenharmony_ci const struct pinmux_ioctrl_reg *ioctrl_regs; 28762306a36Sopenharmony_ci const struct pinmux_data_reg *data_regs; 28862306a36Sopenharmony_ci 28962306a36Sopenharmony_ci const u16 *pinmux_data; 29062306a36Sopenharmony_ci unsigned int pinmux_data_size; 29162306a36Sopenharmony_ci 29262306a36Sopenharmony_ci u32 unlock_reg; /* can be literal address or mask */ 29362306a36Sopenharmony_ci}; 29462306a36Sopenharmony_ci 29562306a36Sopenharmony_ciextern const struct sh_pfc_soc_info emev2_pinmux_info; 29662306a36Sopenharmony_ciextern const struct sh_pfc_soc_info r8a73a4_pinmux_info; 29762306a36Sopenharmony_ciextern const struct sh_pfc_soc_info r8a7740_pinmux_info; 29862306a36Sopenharmony_ciextern const struct sh_pfc_soc_info r8a7742_pinmux_info; 29962306a36Sopenharmony_ciextern const struct sh_pfc_soc_info r8a7743_pinmux_info; 30062306a36Sopenharmony_ciextern const struct sh_pfc_soc_info r8a7744_pinmux_info; 30162306a36Sopenharmony_ciextern const struct sh_pfc_soc_info r8a7745_pinmux_info; 30262306a36Sopenharmony_ciextern const struct sh_pfc_soc_info r8a77470_pinmux_info; 30362306a36Sopenharmony_ciextern const struct sh_pfc_soc_info r8a774a1_pinmux_info; 30462306a36Sopenharmony_ciextern const struct sh_pfc_soc_info r8a774b1_pinmux_info; 30562306a36Sopenharmony_ciextern const struct sh_pfc_soc_info r8a774c0_pinmux_info; 30662306a36Sopenharmony_ciextern const struct sh_pfc_soc_info r8a774e1_pinmux_info; 30762306a36Sopenharmony_ciextern const struct sh_pfc_soc_info r8a7778_pinmux_info; 30862306a36Sopenharmony_ciextern const struct sh_pfc_soc_info r8a7779_pinmux_info; 30962306a36Sopenharmony_ciextern const struct sh_pfc_soc_info r8a7790_pinmux_info; 31062306a36Sopenharmony_ciextern const struct sh_pfc_soc_info r8a7791_pinmux_info; 31162306a36Sopenharmony_ciextern const struct sh_pfc_soc_info r8a7792_pinmux_info; 31262306a36Sopenharmony_ciextern const struct sh_pfc_soc_info r8a7793_pinmux_info; 31362306a36Sopenharmony_ciextern const struct sh_pfc_soc_info r8a7794_pinmux_info; 31462306a36Sopenharmony_ciextern const struct sh_pfc_soc_info r8a77951_pinmux_info; 31562306a36Sopenharmony_ciextern const struct sh_pfc_soc_info r8a77960_pinmux_info; 31662306a36Sopenharmony_ciextern const struct sh_pfc_soc_info r8a77961_pinmux_info; 31762306a36Sopenharmony_ciextern const struct sh_pfc_soc_info r8a77965_pinmux_info; 31862306a36Sopenharmony_ciextern const struct sh_pfc_soc_info r8a77970_pinmux_info; 31962306a36Sopenharmony_ciextern const struct sh_pfc_soc_info r8a77980_pinmux_info; 32062306a36Sopenharmony_ciextern const struct sh_pfc_soc_info r8a77990_pinmux_info; 32162306a36Sopenharmony_ciextern const struct sh_pfc_soc_info r8a77995_pinmux_info; 32262306a36Sopenharmony_ciextern const struct sh_pfc_soc_info r8a779a0_pinmux_info; 32362306a36Sopenharmony_ciextern const struct sh_pfc_soc_info r8a779f0_pinmux_info; 32462306a36Sopenharmony_ciextern const struct sh_pfc_soc_info r8a779g0_pinmux_info; 32562306a36Sopenharmony_ciextern const struct sh_pfc_soc_info sh7203_pinmux_info; 32662306a36Sopenharmony_ciextern const struct sh_pfc_soc_info sh7264_pinmux_info; 32762306a36Sopenharmony_ciextern const struct sh_pfc_soc_info sh7269_pinmux_info; 32862306a36Sopenharmony_ciextern const struct sh_pfc_soc_info sh73a0_pinmux_info; 32962306a36Sopenharmony_ciextern const struct sh_pfc_soc_info sh7720_pinmux_info; 33062306a36Sopenharmony_ciextern const struct sh_pfc_soc_info sh7722_pinmux_info; 33162306a36Sopenharmony_ciextern const struct sh_pfc_soc_info sh7723_pinmux_info; 33262306a36Sopenharmony_ciextern const struct sh_pfc_soc_info sh7724_pinmux_info; 33362306a36Sopenharmony_ciextern const struct sh_pfc_soc_info sh7734_pinmux_info; 33462306a36Sopenharmony_ciextern const struct sh_pfc_soc_info sh7757_pinmux_info; 33562306a36Sopenharmony_ciextern const struct sh_pfc_soc_info sh7785_pinmux_info; 33662306a36Sopenharmony_ciextern const struct sh_pfc_soc_info sh7786_pinmux_info; 33762306a36Sopenharmony_ciextern const struct sh_pfc_soc_info shx3_pinmux_info; 33862306a36Sopenharmony_ci 33962306a36Sopenharmony_ci/* ----------------------------------------------------------------------------- 34062306a36Sopenharmony_ci * Helper macros to create pin and port lists 34162306a36Sopenharmony_ci */ 34262306a36Sopenharmony_ci 34362306a36Sopenharmony_ci/* 34462306a36Sopenharmony_ci * sh_pfc_soc_info pinmux_data array macros 34562306a36Sopenharmony_ci */ 34662306a36Sopenharmony_ci 34762306a36Sopenharmony_ci/* 34862306a36Sopenharmony_ci * Describe generic pinmux data 34962306a36Sopenharmony_ci * - data_or_mark: *_DATA or *_MARK enum ID 35062306a36Sopenharmony_ci * - ids...: List of enum IDs to associate with data_or_mark 35162306a36Sopenharmony_ci */ 35262306a36Sopenharmony_ci#define PINMUX_DATA(data_or_mark, ids...) data_or_mark, ids, 0 35362306a36Sopenharmony_ci 35462306a36Sopenharmony_ci/* 35562306a36Sopenharmony_ci * Describe a pinmux configuration without GPIO function that needs 35662306a36Sopenharmony_ci * configuration in a Peripheral Function Select Register (IPSR) 35762306a36Sopenharmony_ci * - ipsr: IPSR field (unused, for documentation purposes only) 35862306a36Sopenharmony_ci * - fn: Function name, referring to a field in the IPSR 35962306a36Sopenharmony_ci */ 36062306a36Sopenharmony_ci#define PINMUX_IPSR_NOGP(ipsr, fn) \ 36162306a36Sopenharmony_ci PINMUX_DATA(fn##_MARK, FN_##fn) 36262306a36Sopenharmony_ci 36362306a36Sopenharmony_ci/* 36462306a36Sopenharmony_ci * Describe a pinmux configuration with GPIO function that needs configuration 36562306a36Sopenharmony_ci * in both a Peripheral Function Select Register (IPSR) and in a 36662306a36Sopenharmony_ci * GPIO/Peripheral Function Select Register (GPSR) 36762306a36Sopenharmony_ci * - ipsr: IPSR field 36862306a36Sopenharmony_ci * - fn: Function name, also referring to the IPSR field 36962306a36Sopenharmony_ci */ 37062306a36Sopenharmony_ci#define PINMUX_IPSR_GPSR(ipsr, fn) \ 37162306a36Sopenharmony_ci PINMUX_DATA(fn##_MARK, FN_##fn, FN_##ipsr) 37262306a36Sopenharmony_ci 37362306a36Sopenharmony_ci/* 37462306a36Sopenharmony_ci * Describe a pinmux configuration without GPIO function that needs 37562306a36Sopenharmony_ci * configuration in a Peripheral Function Select Register (IPSR), and where the 37662306a36Sopenharmony_ci * pinmux function has a representation in a Module Select Register (MOD_SEL). 37762306a36Sopenharmony_ci * - ipsr: IPSR field (unused, for documentation purposes only) 37862306a36Sopenharmony_ci * - fn: Function name, also referring to the IPSR field 37962306a36Sopenharmony_ci * - msel: Module selector 38062306a36Sopenharmony_ci */ 38162306a36Sopenharmony_ci#define PINMUX_IPSR_NOGM(ipsr, fn, msel) \ 38262306a36Sopenharmony_ci PINMUX_DATA(fn##_MARK, FN_##fn, FN_##msel) 38362306a36Sopenharmony_ci 38462306a36Sopenharmony_ci/* 38562306a36Sopenharmony_ci * Describe a pinmux configuration with GPIO function where the pinmux function 38662306a36Sopenharmony_ci * has no representation in a Peripheral Function Select Register (IPSR), but 38762306a36Sopenharmony_ci * instead solely depends on a group selection. 38862306a36Sopenharmony_ci * - gpsr: GPSR field 38962306a36Sopenharmony_ci * - fn: Function name, also referring to the GPSR field 39062306a36Sopenharmony_ci * - gsel: Group selector 39162306a36Sopenharmony_ci */ 39262306a36Sopenharmony_ci#define PINMUX_IPSR_NOFN(gpsr, fn, gsel) \ 39362306a36Sopenharmony_ci PINMUX_DATA(fn##_MARK, FN_##gpsr, FN_##gsel) 39462306a36Sopenharmony_ci 39562306a36Sopenharmony_ci/* 39662306a36Sopenharmony_ci * Describe a pinmux configuration with GPIO function that needs configuration 39762306a36Sopenharmony_ci * in both a Peripheral Function Select Register (IPSR) and a GPIO/Peripheral 39862306a36Sopenharmony_ci * Function Select Register (GPSR), and where the pinmux function has a 39962306a36Sopenharmony_ci * representation in a Module Select Register (MOD_SEL). 40062306a36Sopenharmony_ci * - ipsr: IPSR field 40162306a36Sopenharmony_ci * - fn: Function name, also referring to the IPSR field 40262306a36Sopenharmony_ci * - msel: Module selector 40362306a36Sopenharmony_ci */ 40462306a36Sopenharmony_ci#define PINMUX_IPSR_MSEL(ipsr, fn, msel) \ 40562306a36Sopenharmony_ci PINMUX_DATA(fn##_MARK, FN_##msel, FN_##fn, FN_##ipsr) 40662306a36Sopenharmony_ci 40762306a36Sopenharmony_ci/* 40862306a36Sopenharmony_ci * Describe a pinmux configuration similar to PINMUX_IPSR_MSEL, but with 40962306a36Sopenharmony_ci * an additional select register that controls physical multiplexing 41062306a36Sopenharmony_ci * with another pin. 41162306a36Sopenharmony_ci * - ipsr: IPSR field 41262306a36Sopenharmony_ci * - fn: Function name, also referring to the IPSR field 41362306a36Sopenharmony_ci * - psel: Physical multiplexing selector 41462306a36Sopenharmony_ci * - msel: Module selector 41562306a36Sopenharmony_ci */ 41662306a36Sopenharmony_ci#define PINMUX_IPSR_PHYS_MSEL(ipsr, fn, psel, msel) \ 41762306a36Sopenharmony_ci PINMUX_DATA(fn##_MARK, FN_##psel, FN_##msel, FN_##fn, FN_##ipsr) 41862306a36Sopenharmony_ci 41962306a36Sopenharmony_ci/* 42062306a36Sopenharmony_ci * Describe a pinmux configuration in which a pin is physically multiplexed 42162306a36Sopenharmony_ci * with other pins. 42262306a36Sopenharmony_ci * - ipsr: IPSR field 42362306a36Sopenharmony_ci * - fn: Function name 42462306a36Sopenharmony_ci * - psel: Physical multiplexing selector 42562306a36Sopenharmony_ci */ 42662306a36Sopenharmony_ci#define PINMUX_IPSR_PHYS(ipsr, fn, psel) \ 42762306a36Sopenharmony_ci PINMUX_DATA(fn##_MARK, FN_##psel, FN_##ipsr) 42862306a36Sopenharmony_ci 42962306a36Sopenharmony_ci/* 43062306a36Sopenharmony_ci * Describe a pinmux configuration for a single-function pin with GPIO 43162306a36Sopenharmony_ci * capability. 43262306a36Sopenharmony_ci * - fn: Function name 43362306a36Sopenharmony_ci */ 43462306a36Sopenharmony_ci#define PINMUX_SINGLE(fn) \ 43562306a36Sopenharmony_ci PINMUX_DATA(fn##_MARK, FN_##fn) 43662306a36Sopenharmony_ci 43762306a36Sopenharmony_ci/* 43862306a36Sopenharmony_ci * GP port style (32 ports banks) 43962306a36Sopenharmony_ci */ 44062306a36Sopenharmony_ci 44162306a36Sopenharmony_ci#define PORT_GP_CFG_1(bank, pin, fn, sfx, cfg) \ 44262306a36Sopenharmony_ci fn(bank, pin, GP_##bank##_##pin, sfx, cfg) 44362306a36Sopenharmony_ci#define PORT_GP_1(bank, pin, fn, sfx) PORT_GP_CFG_1(bank, pin, fn, sfx, 0) 44462306a36Sopenharmony_ci 44562306a36Sopenharmony_ci#define PORT_GP_CFG_2(bank, fn, sfx, cfg) \ 44662306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 0, fn, sfx, cfg), \ 44762306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 1, fn, sfx, cfg) 44862306a36Sopenharmony_ci#define PORT_GP_2(bank, fn, sfx) PORT_GP_CFG_2(bank, fn, sfx, 0) 44962306a36Sopenharmony_ci 45062306a36Sopenharmony_ci#define PORT_GP_CFG_4(bank, fn, sfx, cfg) \ 45162306a36Sopenharmony_ci PORT_GP_CFG_2(bank, fn, sfx, cfg), \ 45262306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 2, fn, sfx, cfg), \ 45362306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 3, fn, sfx, cfg) 45462306a36Sopenharmony_ci#define PORT_GP_4(bank, fn, sfx) PORT_GP_CFG_4(bank, fn, sfx, 0) 45562306a36Sopenharmony_ci 45662306a36Sopenharmony_ci#define PORT_GP_CFG_6(bank, fn, sfx, cfg) \ 45762306a36Sopenharmony_ci PORT_GP_CFG_4(bank, fn, sfx, cfg), \ 45862306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 4, fn, sfx, cfg), \ 45962306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 5, fn, sfx, cfg) 46062306a36Sopenharmony_ci#define PORT_GP_6(bank, fn, sfx) PORT_GP_CFG_6(bank, fn, sfx, 0) 46162306a36Sopenharmony_ci 46262306a36Sopenharmony_ci#define PORT_GP_CFG_7(bank, fn, sfx, cfg) \ 46362306a36Sopenharmony_ci PORT_GP_CFG_6(bank, fn, sfx, cfg), \ 46462306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 6, fn, sfx, cfg) 46562306a36Sopenharmony_ci#define PORT_GP_7(bank, fn, sfx) PORT_GP_CFG_7(bank, fn, sfx, 0) 46662306a36Sopenharmony_ci 46762306a36Sopenharmony_ci#define PORT_GP_CFG_8(bank, fn, sfx, cfg) \ 46862306a36Sopenharmony_ci PORT_GP_CFG_7(bank, fn, sfx, cfg), \ 46962306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 7, fn, sfx, cfg) 47062306a36Sopenharmony_ci#define PORT_GP_8(bank, fn, sfx) PORT_GP_CFG_8(bank, fn, sfx, 0) 47162306a36Sopenharmony_ci 47262306a36Sopenharmony_ci#define PORT_GP_CFG_9(bank, fn, sfx, cfg) \ 47362306a36Sopenharmony_ci PORT_GP_CFG_8(bank, fn, sfx, cfg), \ 47462306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 8, fn, sfx, cfg) 47562306a36Sopenharmony_ci#define PORT_GP_9(bank, fn, sfx) PORT_GP_CFG_9(bank, fn, sfx, 0) 47662306a36Sopenharmony_ci 47762306a36Sopenharmony_ci#define PORT_GP_CFG_10(bank, fn, sfx, cfg) \ 47862306a36Sopenharmony_ci PORT_GP_CFG_9(bank, fn, sfx, cfg), \ 47962306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 9, fn, sfx, cfg) 48062306a36Sopenharmony_ci#define PORT_GP_10(bank, fn, sfx) PORT_GP_CFG_10(bank, fn, sfx, 0) 48162306a36Sopenharmony_ci 48262306a36Sopenharmony_ci#define PORT_GP_CFG_11(bank, fn, sfx, cfg) \ 48362306a36Sopenharmony_ci PORT_GP_CFG_10(bank, fn, sfx, cfg), \ 48462306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 10, fn, sfx, cfg) 48562306a36Sopenharmony_ci#define PORT_GP_11(bank, fn, sfx) PORT_GP_CFG_11(bank, fn, sfx, 0) 48662306a36Sopenharmony_ci 48762306a36Sopenharmony_ci#define PORT_GP_CFG_12(bank, fn, sfx, cfg) \ 48862306a36Sopenharmony_ci PORT_GP_CFG_11(bank, fn, sfx, cfg), \ 48962306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 11, fn, sfx, cfg) 49062306a36Sopenharmony_ci#define PORT_GP_12(bank, fn, sfx) PORT_GP_CFG_12(bank, fn, sfx, 0) 49162306a36Sopenharmony_ci 49262306a36Sopenharmony_ci#define PORT_GP_CFG_13(bank, fn, sfx, cfg) \ 49362306a36Sopenharmony_ci PORT_GP_CFG_12(bank, fn, sfx, cfg), \ 49462306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 12, fn, sfx, cfg) 49562306a36Sopenharmony_ci#define PORT_GP_13(bank, fn, sfx) PORT_GP_CFG_13(bank, fn, sfx, 0) 49662306a36Sopenharmony_ci 49762306a36Sopenharmony_ci#define PORT_GP_CFG_14(bank, fn, sfx, cfg) \ 49862306a36Sopenharmony_ci PORT_GP_CFG_13(bank, fn, sfx, cfg), \ 49962306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 13, fn, sfx, cfg) 50062306a36Sopenharmony_ci#define PORT_GP_14(bank, fn, sfx) PORT_GP_CFG_14(bank, fn, sfx, 0) 50162306a36Sopenharmony_ci 50262306a36Sopenharmony_ci#define PORT_GP_CFG_15(bank, fn, sfx, cfg) \ 50362306a36Sopenharmony_ci PORT_GP_CFG_14(bank, fn, sfx, cfg), \ 50462306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 14, fn, sfx, cfg) 50562306a36Sopenharmony_ci#define PORT_GP_15(bank, fn, sfx) PORT_GP_CFG_15(bank, fn, sfx, 0) 50662306a36Sopenharmony_ci 50762306a36Sopenharmony_ci#define PORT_GP_CFG_16(bank, fn, sfx, cfg) \ 50862306a36Sopenharmony_ci PORT_GP_CFG_15(bank, fn, sfx, cfg), \ 50962306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 15, fn, sfx, cfg) 51062306a36Sopenharmony_ci#define PORT_GP_16(bank, fn, sfx) PORT_GP_CFG_16(bank, fn, sfx, 0) 51162306a36Sopenharmony_ci 51262306a36Sopenharmony_ci#define PORT_GP_CFG_17(bank, fn, sfx, cfg) \ 51362306a36Sopenharmony_ci PORT_GP_CFG_16(bank, fn, sfx, cfg), \ 51462306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 16, fn, sfx, cfg) 51562306a36Sopenharmony_ci#define PORT_GP_17(bank, fn, sfx) PORT_GP_CFG_17(bank, fn, sfx, 0) 51662306a36Sopenharmony_ci 51762306a36Sopenharmony_ci#define PORT_GP_CFG_18(bank, fn, sfx, cfg) \ 51862306a36Sopenharmony_ci PORT_GP_CFG_17(bank, fn, sfx, cfg), \ 51962306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 17, fn, sfx, cfg) 52062306a36Sopenharmony_ci#define PORT_GP_18(bank, fn, sfx) PORT_GP_CFG_18(bank, fn, sfx, 0) 52162306a36Sopenharmony_ci 52262306a36Sopenharmony_ci#define PORT_GP_CFG_19(bank, fn, sfx, cfg) \ 52362306a36Sopenharmony_ci PORT_GP_CFG_18(bank, fn, sfx, cfg), \ 52462306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 18, fn, sfx, cfg) 52562306a36Sopenharmony_ci#define PORT_GP_19(bank, fn, sfx) PORT_GP_CFG_19(bank, fn, sfx, 0) 52662306a36Sopenharmony_ci 52762306a36Sopenharmony_ci#define PORT_GP_CFG_20(bank, fn, sfx, cfg) \ 52862306a36Sopenharmony_ci PORT_GP_CFG_19(bank, fn, sfx, cfg), \ 52962306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 19, fn, sfx, cfg) 53062306a36Sopenharmony_ci#define PORT_GP_20(bank, fn, sfx) PORT_GP_CFG_20(bank, fn, sfx, 0) 53162306a36Sopenharmony_ci 53262306a36Sopenharmony_ci#define PORT_GP_CFG_21(bank, fn, sfx, cfg) \ 53362306a36Sopenharmony_ci PORT_GP_CFG_20(bank, fn, sfx, cfg), \ 53462306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 20, fn, sfx, cfg) 53562306a36Sopenharmony_ci#define PORT_GP_21(bank, fn, sfx) PORT_GP_CFG_21(bank, fn, sfx, 0) 53662306a36Sopenharmony_ci 53762306a36Sopenharmony_ci#define PORT_GP_CFG_22(bank, fn, sfx, cfg) \ 53862306a36Sopenharmony_ci PORT_GP_CFG_21(bank, fn, sfx, cfg), \ 53962306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 21, fn, sfx, cfg) 54062306a36Sopenharmony_ci#define PORT_GP_22(bank, fn, sfx) PORT_GP_CFG_22(bank, fn, sfx, 0) 54162306a36Sopenharmony_ci 54262306a36Sopenharmony_ci#define PORT_GP_CFG_23(bank, fn, sfx, cfg) \ 54362306a36Sopenharmony_ci PORT_GP_CFG_22(bank, fn, sfx, cfg), \ 54462306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 22, fn, sfx, cfg) 54562306a36Sopenharmony_ci#define PORT_GP_23(bank, fn, sfx) PORT_GP_CFG_23(bank, fn, sfx, 0) 54662306a36Sopenharmony_ci 54762306a36Sopenharmony_ci#define PORT_GP_CFG_24(bank, fn, sfx, cfg) \ 54862306a36Sopenharmony_ci PORT_GP_CFG_23(bank, fn, sfx, cfg), \ 54962306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 23, fn, sfx, cfg) 55062306a36Sopenharmony_ci#define PORT_GP_24(bank, fn, sfx) PORT_GP_CFG_24(bank, fn, sfx, 0) 55162306a36Sopenharmony_ci 55262306a36Sopenharmony_ci#define PORT_GP_CFG_25(bank, fn, sfx, cfg) \ 55362306a36Sopenharmony_ci PORT_GP_CFG_24(bank, fn, sfx, cfg), \ 55462306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 24, fn, sfx, cfg) 55562306a36Sopenharmony_ci#define PORT_GP_25(bank, fn, sfx) PORT_GP_CFG_25(bank, fn, sfx, 0) 55662306a36Sopenharmony_ci 55762306a36Sopenharmony_ci#define PORT_GP_CFG_26(bank, fn, sfx, cfg) \ 55862306a36Sopenharmony_ci PORT_GP_CFG_25(bank, fn, sfx, cfg), \ 55962306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 25, fn, sfx, cfg) 56062306a36Sopenharmony_ci#define PORT_GP_26(bank, fn, sfx) PORT_GP_CFG_26(bank, fn, sfx, 0) 56162306a36Sopenharmony_ci 56262306a36Sopenharmony_ci#define PORT_GP_CFG_27(bank, fn, sfx, cfg) \ 56362306a36Sopenharmony_ci PORT_GP_CFG_26(bank, fn, sfx, cfg), \ 56462306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 26, fn, sfx, cfg) 56562306a36Sopenharmony_ci#define PORT_GP_27(bank, fn, sfx) PORT_GP_CFG_27(bank, fn, sfx, 0) 56662306a36Sopenharmony_ci 56762306a36Sopenharmony_ci#define PORT_GP_CFG_28(bank, fn, sfx, cfg) \ 56862306a36Sopenharmony_ci PORT_GP_CFG_27(bank, fn, sfx, cfg), \ 56962306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 27, fn, sfx, cfg) 57062306a36Sopenharmony_ci#define PORT_GP_28(bank, fn, sfx) PORT_GP_CFG_28(bank, fn, sfx, 0) 57162306a36Sopenharmony_ci 57262306a36Sopenharmony_ci#define PORT_GP_CFG_29(bank, fn, sfx, cfg) \ 57362306a36Sopenharmony_ci PORT_GP_CFG_28(bank, fn, sfx, cfg), \ 57462306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 28, fn, sfx, cfg) 57562306a36Sopenharmony_ci#define PORT_GP_29(bank, fn, sfx) PORT_GP_CFG_29(bank, fn, sfx, 0) 57662306a36Sopenharmony_ci 57762306a36Sopenharmony_ci#define PORT_GP_CFG_30(bank, fn, sfx, cfg) \ 57862306a36Sopenharmony_ci PORT_GP_CFG_29(bank, fn, sfx, cfg), \ 57962306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 29, fn, sfx, cfg) 58062306a36Sopenharmony_ci#define PORT_GP_30(bank, fn, sfx) PORT_GP_CFG_30(bank, fn, sfx, 0) 58162306a36Sopenharmony_ci 58262306a36Sopenharmony_ci#define PORT_GP_CFG_31(bank, fn, sfx, cfg) \ 58362306a36Sopenharmony_ci PORT_GP_CFG_30(bank, fn, sfx, cfg), \ 58462306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 30, fn, sfx, cfg) 58562306a36Sopenharmony_ci#define PORT_GP_31(bank, fn, sfx) PORT_GP_CFG_31(bank, fn, sfx, 0) 58662306a36Sopenharmony_ci 58762306a36Sopenharmony_ci#define PORT_GP_CFG_32(bank, fn, sfx, cfg) \ 58862306a36Sopenharmony_ci PORT_GP_CFG_31(bank, fn, sfx, cfg), \ 58962306a36Sopenharmony_ci PORT_GP_CFG_1(bank, 31, fn, sfx, cfg) 59062306a36Sopenharmony_ci#define PORT_GP_32(bank, fn, sfx) PORT_GP_CFG_32(bank, fn, sfx, 0) 59162306a36Sopenharmony_ci 59262306a36Sopenharmony_ci#define PORT_GP_32_REV(bank, fn, sfx) \ 59362306a36Sopenharmony_ci PORT_GP_1(bank, 31, fn, sfx), PORT_GP_1(bank, 30, fn, sfx), \ 59462306a36Sopenharmony_ci PORT_GP_1(bank, 29, fn, sfx), PORT_GP_1(bank, 28, fn, sfx), \ 59562306a36Sopenharmony_ci PORT_GP_1(bank, 27, fn, sfx), PORT_GP_1(bank, 26, fn, sfx), \ 59662306a36Sopenharmony_ci PORT_GP_1(bank, 25, fn, sfx), PORT_GP_1(bank, 24, fn, sfx), \ 59762306a36Sopenharmony_ci PORT_GP_1(bank, 23, fn, sfx), PORT_GP_1(bank, 22, fn, sfx), \ 59862306a36Sopenharmony_ci PORT_GP_1(bank, 21, fn, sfx), PORT_GP_1(bank, 20, fn, sfx), \ 59962306a36Sopenharmony_ci PORT_GP_1(bank, 19, fn, sfx), PORT_GP_1(bank, 18, fn, sfx), \ 60062306a36Sopenharmony_ci PORT_GP_1(bank, 17, fn, sfx), PORT_GP_1(bank, 16, fn, sfx), \ 60162306a36Sopenharmony_ci PORT_GP_1(bank, 15, fn, sfx), PORT_GP_1(bank, 14, fn, sfx), \ 60262306a36Sopenharmony_ci PORT_GP_1(bank, 13, fn, sfx), PORT_GP_1(bank, 12, fn, sfx), \ 60362306a36Sopenharmony_ci PORT_GP_1(bank, 11, fn, sfx), PORT_GP_1(bank, 10, fn, sfx), \ 60462306a36Sopenharmony_ci PORT_GP_1(bank, 9, fn, sfx), PORT_GP_1(bank, 8, fn, sfx), \ 60562306a36Sopenharmony_ci PORT_GP_1(bank, 7, fn, sfx), PORT_GP_1(bank, 6, fn, sfx), \ 60662306a36Sopenharmony_ci PORT_GP_1(bank, 5, fn, sfx), PORT_GP_1(bank, 4, fn, sfx), \ 60762306a36Sopenharmony_ci PORT_GP_1(bank, 3, fn, sfx), PORT_GP_1(bank, 2, fn, sfx), \ 60862306a36Sopenharmony_ci PORT_GP_1(bank, 1, fn, sfx), PORT_GP_1(bank, 0, fn, sfx) 60962306a36Sopenharmony_ci 61062306a36Sopenharmony_ci/* GP_ALL(suffix) - Expand to a list of GP_#_#_suffix */ 61162306a36Sopenharmony_ci#define _GP_ALL(bank, pin, name, sfx, cfg) name##_##sfx 61262306a36Sopenharmony_ci#define GP_ALL(str) CPU_ALL_GP(_GP_ALL, str) 61362306a36Sopenharmony_ci 61462306a36Sopenharmony_ci/* PINMUX_GPIO_GP_ALL - Expand to a list of sh_pfc_pin entries */ 61562306a36Sopenharmony_ci#define _GP_GPIO(bank, _pin, _name, sfx, cfg) { \ 61662306a36Sopenharmony_ci .pin = (bank * 32) + _pin, \ 61762306a36Sopenharmony_ci .name = __stringify(_name), \ 61862306a36Sopenharmony_ci .enum_id = _name##_DATA, \ 61962306a36Sopenharmony_ci .configs = cfg, \ 62062306a36Sopenharmony_ci} 62162306a36Sopenharmony_ci#define PINMUX_GPIO_GP_ALL() CPU_ALL_GP(_GP_GPIO, unused) 62262306a36Sopenharmony_ci 62362306a36Sopenharmony_ci/* PINMUX_DATA_GP_ALL - Expand to a list of name_DATA, name_FN marks */ 62462306a36Sopenharmony_ci#define _GP_DATA(bank, pin, name, sfx, cfg) PINMUX_DATA(name##_DATA, name##_FN) 62562306a36Sopenharmony_ci#define PINMUX_DATA_GP_ALL() CPU_ALL_GP(_GP_DATA, unused) 62662306a36Sopenharmony_ci 62762306a36Sopenharmony_ci/* 62862306a36Sopenharmony_ci * GP_ASSIGN_LAST() - Expand to an enum definition for the last GP pin 62962306a36Sopenharmony_ci * 63062306a36Sopenharmony_ci * The largest GP pin index is obtained by taking the size of a union, 63162306a36Sopenharmony_ci * containing one array per GP pin, sized by the corresponding pin index. 63262306a36Sopenharmony_ci * As the fields in the CPU_ALL_GP() macro definition are separated by commas, 63362306a36Sopenharmony_ci * while the members of a union must be terminated by semicolons, the commas 63462306a36Sopenharmony_ci * are absorbed by wrapping them inside dummy attributes. 63562306a36Sopenharmony_ci */ 63662306a36Sopenharmony_ci#define _GP_ENTRY(bank, pin, name, sfx, cfg) \ 63762306a36Sopenharmony_ci deprecated)); char name[(bank * 32) + pin] __attribute__((deprecated 63862306a36Sopenharmony_ci#define GP_ASSIGN_LAST() \ 63962306a36Sopenharmony_ci GP_LAST = sizeof(union { \ 64062306a36Sopenharmony_ci char dummy[0] __attribute__((deprecated, \ 64162306a36Sopenharmony_ci CPU_ALL_GP(_GP_ENTRY, unused), \ 64262306a36Sopenharmony_ci deprecated)); \ 64362306a36Sopenharmony_ci }) 64462306a36Sopenharmony_ci 64562306a36Sopenharmony_ci/* 64662306a36Sopenharmony_ci * PORT style (linear pin space) 64762306a36Sopenharmony_ci */ 64862306a36Sopenharmony_ci 64962306a36Sopenharmony_ci#define PORT_1(pn, fn, pfx, sfx) fn(pn, pfx, sfx) 65062306a36Sopenharmony_ci 65162306a36Sopenharmony_ci#define PORT_10(pn, fn, pfx, sfx) \ 65262306a36Sopenharmony_ci PORT_1(pn, fn, pfx##0, sfx), PORT_1(pn+1, fn, pfx##1, sfx), \ 65362306a36Sopenharmony_ci PORT_1(pn+2, fn, pfx##2, sfx), PORT_1(pn+3, fn, pfx##3, sfx), \ 65462306a36Sopenharmony_ci PORT_1(pn+4, fn, pfx##4, sfx), PORT_1(pn+5, fn, pfx##5, sfx), \ 65562306a36Sopenharmony_ci PORT_1(pn+6, fn, pfx##6, sfx), PORT_1(pn+7, fn, pfx##7, sfx), \ 65662306a36Sopenharmony_ci PORT_1(pn+8, fn, pfx##8, sfx), PORT_1(pn+9, fn, pfx##9, sfx) 65762306a36Sopenharmony_ci 65862306a36Sopenharmony_ci#define PORT_90(pn, fn, pfx, sfx) \ 65962306a36Sopenharmony_ci PORT_10(pn+10, fn, pfx##1, sfx), PORT_10(pn+20, fn, pfx##2, sfx), \ 66062306a36Sopenharmony_ci PORT_10(pn+30, fn, pfx##3, sfx), PORT_10(pn+40, fn, pfx##4, sfx), \ 66162306a36Sopenharmony_ci PORT_10(pn+50, fn, pfx##5, sfx), PORT_10(pn+60, fn, pfx##6, sfx), \ 66262306a36Sopenharmony_ci PORT_10(pn+70, fn, pfx##7, sfx), PORT_10(pn+80, fn, pfx##8, sfx), \ 66362306a36Sopenharmony_ci PORT_10(pn+90, fn, pfx##9, sfx) 66462306a36Sopenharmony_ci 66562306a36Sopenharmony_ci/* PORT_ALL(suffix) - Expand to a list of PORT_#_suffix */ 66662306a36Sopenharmony_ci#define _PORT_ALL(pn, pfx, sfx) pfx##_##sfx 66762306a36Sopenharmony_ci#define PORT_ALL(str) CPU_ALL_PORT(_PORT_ALL, PORT, str) 66862306a36Sopenharmony_ci 66962306a36Sopenharmony_ci/* PINMUX_GPIO - Expand to a sh_pfc_pin entry */ 67062306a36Sopenharmony_ci#define PINMUX_GPIO(_pin) \ 67162306a36Sopenharmony_ci [GPIO_##_pin] = { \ 67262306a36Sopenharmony_ci .pin = (u16)-1, \ 67362306a36Sopenharmony_ci .name = __stringify(GPIO_##_pin), \ 67462306a36Sopenharmony_ci .enum_id = _pin##_DATA, \ 67562306a36Sopenharmony_ci } 67662306a36Sopenharmony_ci 67762306a36Sopenharmony_ci/* SH_PFC_PIN_CFG - Expand to a sh_pfc_pin entry (named PORT#) with config */ 67862306a36Sopenharmony_ci#define SH_PFC_PIN_CFG(_pin, cfgs) { \ 67962306a36Sopenharmony_ci .pin = _pin, \ 68062306a36Sopenharmony_ci .name = __stringify(PORT##_pin), \ 68162306a36Sopenharmony_ci .enum_id = PORT##_pin##_DATA, \ 68262306a36Sopenharmony_ci .configs = cfgs, \ 68362306a36Sopenharmony_ci} 68462306a36Sopenharmony_ci 68562306a36Sopenharmony_ci/* PINMUX_DATA_ALL - Expand to a list of PORT_name_DATA, PORT_name_FN0, 68662306a36Sopenharmony_ci * PORT_name_OUT, PORT_name_IN marks 68762306a36Sopenharmony_ci */ 68862306a36Sopenharmony_ci#define _PORT_DATA(pn, pfx, sfx) \ 68962306a36Sopenharmony_ci PINMUX_DATA(PORT##pfx##_DATA, PORT##pfx##_FN0, \ 69062306a36Sopenharmony_ci PORT##pfx##_OUT, PORT##pfx##_IN) 69162306a36Sopenharmony_ci#define PINMUX_DATA_ALL() CPU_ALL_PORT(_PORT_DATA, , unused) 69262306a36Sopenharmony_ci 69362306a36Sopenharmony_ci/* 69462306a36Sopenharmony_ci * PORT_ASSIGN_LAST() - Expand to an enum definition for the last PORT pin 69562306a36Sopenharmony_ci * 69662306a36Sopenharmony_ci * The largest PORT pin index is obtained by taking the size of a union, 69762306a36Sopenharmony_ci * containing one array per PORT pin, sized by the corresponding pin index. 69862306a36Sopenharmony_ci * As the fields in the CPU_ALL_PORT() macro definition are separated by 69962306a36Sopenharmony_ci * commas, while the members of a union must be terminated by semicolons, the 70062306a36Sopenharmony_ci * commas are absorbed by wrapping them inside dummy attributes. 70162306a36Sopenharmony_ci */ 70262306a36Sopenharmony_ci#define _PORT_ENTRY(pn, pfx, sfx) \ 70362306a36Sopenharmony_ci deprecated)); char pfx[pn] __attribute__((deprecated 70462306a36Sopenharmony_ci#define PORT_ASSIGN_LAST() \ 70562306a36Sopenharmony_ci PORT_LAST = sizeof(union { \ 70662306a36Sopenharmony_ci char dummy[0] __attribute__((deprecated, \ 70762306a36Sopenharmony_ci CPU_ALL_PORT(_PORT_ENTRY, PORT, unused), \ 70862306a36Sopenharmony_ci deprecated)); \ 70962306a36Sopenharmony_ci }) 71062306a36Sopenharmony_ci 71162306a36Sopenharmony_ci/* GPIO_FN(name) - Expand to a sh_pfc_pin entry for a function GPIO */ 71262306a36Sopenharmony_ci#define PINMUX_GPIO_FN(gpio, base, data_or_mark) \ 71362306a36Sopenharmony_ci [gpio - (base)] = { \ 71462306a36Sopenharmony_ci .name = __stringify(gpio), \ 71562306a36Sopenharmony_ci .enum_id = data_or_mark, \ 71662306a36Sopenharmony_ci } 71762306a36Sopenharmony_ci#define GPIO_FN(str) \ 71862306a36Sopenharmony_ci PINMUX_GPIO_FN(GPIO_FN_##str, PINMUX_FN_BASE, str##_MARK) 71962306a36Sopenharmony_ci 72062306a36Sopenharmony_ci/* 72162306a36Sopenharmony_ci * Pins not associated with a GPIO port 72262306a36Sopenharmony_ci */ 72362306a36Sopenharmony_ci 72462306a36Sopenharmony_ci#define PIN_NOGP_CFG(pin, name, fn, cfg) fn(pin, name, cfg) 72562306a36Sopenharmony_ci#define PIN_NOGP(pin, name, fn) fn(pin, name, 0) 72662306a36Sopenharmony_ci 72762306a36Sopenharmony_ci/* NOGP_ALL - Expand to a list of PIN_id */ 72862306a36Sopenharmony_ci#define _NOGP_ALL(pin, name, cfg) PIN_##pin 72962306a36Sopenharmony_ci#define NOGP_ALL() CPU_ALL_NOGP(_NOGP_ALL) 73062306a36Sopenharmony_ci 73162306a36Sopenharmony_ci/* PINMUX_NOGP_ALL - Expand to a list of sh_pfc_pin entries */ 73262306a36Sopenharmony_ci#define _NOGP_PINMUX(_pin, _name, cfg) { \ 73362306a36Sopenharmony_ci .pin = PIN_##_pin, \ 73462306a36Sopenharmony_ci .name = "PIN_" _name, \ 73562306a36Sopenharmony_ci .configs = SH_PFC_PIN_CFG_NO_GPIO | cfg, \ 73662306a36Sopenharmony_ci} 73762306a36Sopenharmony_ci#define PINMUX_NOGP_ALL() CPU_ALL_NOGP(_NOGP_PINMUX) 73862306a36Sopenharmony_ci 73962306a36Sopenharmony_ci/* 74062306a36Sopenharmony_ci * PORTnCR helper macro for SH-Mobile/R-Mobile 74162306a36Sopenharmony_ci */ 74262306a36Sopenharmony_ci#define PORTCR(nr, reg) { \ 74362306a36Sopenharmony_ci PINMUX_CFG_REG_VAR("PORT" nr "CR", reg, 8, GROUP(-2, 2, -1, 3), \ 74462306a36Sopenharmony_ci GROUP( \ 74562306a36Sopenharmony_ci /* PULMD[1:0], handled by .set_bias() */ \ 74662306a36Sopenharmony_ci /* IE and OE */ \ 74762306a36Sopenharmony_ci 0, PORT##nr##_OUT, PORT##nr##_IN, 0, \ 74862306a36Sopenharmony_ci /* SEC, not supported */ \ 74962306a36Sopenharmony_ci /* PTMD[2:0] */ \ 75062306a36Sopenharmony_ci PORT##nr##_FN0, PORT##nr##_FN1, \ 75162306a36Sopenharmony_ci PORT##nr##_FN2, PORT##nr##_FN3, \ 75262306a36Sopenharmony_ci PORT##nr##_FN4, PORT##nr##_FN5, \ 75362306a36Sopenharmony_ci PORT##nr##_FN6, PORT##nr##_FN7 \ 75462306a36Sopenharmony_ci )) \ 75562306a36Sopenharmony_ci} 75662306a36Sopenharmony_ci 75762306a36Sopenharmony_ci/* 75862306a36Sopenharmony_ci * GPIO number helper macro for R-Car 75962306a36Sopenharmony_ci */ 76062306a36Sopenharmony_ci#define RCAR_GP_PIN(bank, pin) (((bank) * 32) + (pin)) 76162306a36Sopenharmony_ci 76262306a36Sopenharmony_ci/* 76362306a36Sopenharmony_ci * Bias helpers 76462306a36Sopenharmony_ci */ 76562306a36Sopenharmony_ciconst struct pinmux_bias_reg * 76662306a36Sopenharmony_circar_pin_to_bias_reg(const struct sh_pfc_soc_info *info, unsigned int pin, 76762306a36Sopenharmony_ci unsigned int *bit); 76862306a36Sopenharmony_ciunsigned int rcar_pinmux_get_bias(struct sh_pfc *pfc, unsigned int pin); 76962306a36Sopenharmony_civoid rcar_pinmux_set_bias(struct sh_pfc *pfc, unsigned int pin, 77062306a36Sopenharmony_ci unsigned int bias); 77162306a36Sopenharmony_ci 77262306a36Sopenharmony_ciunsigned int rmobile_pinmux_get_bias(struct sh_pfc *pfc, unsigned int pin); 77362306a36Sopenharmony_civoid rmobile_pinmux_set_bias(struct sh_pfc *pfc, unsigned int pin, 77462306a36Sopenharmony_ci unsigned int bias); 77562306a36Sopenharmony_ci 77662306a36Sopenharmony_ci#endif /* __SH_PFC_H */ 777