18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci * 38c2ecf20Sopenharmony_ci * SuperH Pin Function Controller Support 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (c) 2008 Magnus Damm 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#ifndef __SH_PFC_H 98c2ecf20Sopenharmony_ci#define __SH_PFC_H 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <linux/bug.h> 128c2ecf20Sopenharmony_ci#include <linux/pinctrl/pinconf-generic.h> 138c2ecf20Sopenharmony_ci#include <linux/spinlock.h> 148c2ecf20Sopenharmony_ci#include <linux/stringify.h> 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_cienum { 178c2ecf20Sopenharmony_ci PINMUX_TYPE_NONE, 188c2ecf20Sopenharmony_ci PINMUX_TYPE_FUNCTION, 198c2ecf20Sopenharmony_ci PINMUX_TYPE_GPIO, 208c2ecf20Sopenharmony_ci PINMUX_TYPE_OUTPUT, 218c2ecf20Sopenharmony_ci PINMUX_TYPE_INPUT, 228c2ecf20Sopenharmony_ci}; 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci#define SH_PFC_PIN_NONE U16_MAX 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci#define SH_PFC_PIN_CFG_INPUT (1 << 0) 278c2ecf20Sopenharmony_ci#define SH_PFC_PIN_CFG_OUTPUT (1 << 1) 288c2ecf20Sopenharmony_ci#define SH_PFC_PIN_CFG_PULL_UP (1 << 2) 298c2ecf20Sopenharmony_ci#define SH_PFC_PIN_CFG_PULL_DOWN (1 << 3) 308c2ecf20Sopenharmony_ci#define SH_PFC_PIN_CFG_PULL_UP_DOWN (SH_PFC_PIN_CFG_PULL_UP | \ 318c2ecf20Sopenharmony_ci SH_PFC_PIN_CFG_PULL_DOWN) 328c2ecf20Sopenharmony_ci#define SH_PFC_PIN_CFG_IO_VOLTAGE (1 << 4) 338c2ecf20Sopenharmony_ci#define SH_PFC_PIN_CFG_DRIVE_STRENGTH (1 << 5) 348c2ecf20Sopenharmony_ci#define SH_PFC_PIN_CFG_NO_GPIO (1 << 31) 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_cistruct sh_pfc_pin { 378c2ecf20Sopenharmony_ci u16 pin; 388c2ecf20Sopenharmony_ci u16 enum_id; 398c2ecf20Sopenharmony_ci const char *name; 408c2ecf20Sopenharmony_ci unsigned int configs; 418c2ecf20Sopenharmony_ci}; 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci#define SH_PFC_PIN_GROUP_ALIAS(alias, n) \ 448c2ecf20Sopenharmony_ci { \ 458c2ecf20Sopenharmony_ci .name = #alias, \ 468c2ecf20Sopenharmony_ci .pins = n##_pins, \ 478c2ecf20Sopenharmony_ci .mux = n##_mux, \ 488c2ecf20Sopenharmony_ci .nr_pins = ARRAY_SIZE(n##_pins) + \ 498c2ecf20Sopenharmony_ci BUILD_BUG_ON_ZERO(sizeof(n##_pins) != sizeof(n##_mux)), \ 508c2ecf20Sopenharmony_ci } 518c2ecf20Sopenharmony_ci#define SH_PFC_PIN_GROUP(n) SH_PFC_PIN_GROUP_ALIAS(n, n) 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_cistruct sh_pfc_pin_group { 548c2ecf20Sopenharmony_ci const char *name; 558c2ecf20Sopenharmony_ci const unsigned int *pins; 568c2ecf20Sopenharmony_ci const unsigned int *mux; 578c2ecf20Sopenharmony_ci unsigned int nr_pins; 588c2ecf20Sopenharmony_ci}; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci/* 618c2ecf20Sopenharmony_ci * Using union vin_data{,12,16} saves memory occupied by the VIN data pins. 628c2ecf20Sopenharmony_ci * VIN_DATA_PIN_GROUP() is a macro used to describe the VIN pin groups 638c2ecf20Sopenharmony_ci * in this case. It accepts an optional 'version' argument used when the 648c2ecf20Sopenharmony_ci * same group can appear on a different set of pins. 658c2ecf20Sopenharmony_ci */ 668c2ecf20Sopenharmony_ci#define VIN_DATA_PIN_GROUP(n, s, ...) \ 678c2ecf20Sopenharmony_ci { \ 688c2ecf20Sopenharmony_ci .name = #n#s#__VA_ARGS__, \ 698c2ecf20Sopenharmony_ci .pins = n##__VA_ARGS__##_pins.data##s, \ 708c2ecf20Sopenharmony_ci .mux = n##__VA_ARGS__##_mux.data##s, \ 718c2ecf20Sopenharmony_ci .nr_pins = ARRAY_SIZE(n##__VA_ARGS__##_pins.data##s), \ 728c2ecf20Sopenharmony_ci } 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ciunion vin_data12 { 758c2ecf20Sopenharmony_ci unsigned int data12[12]; 768c2ecf20Sopenharmony_ci unsigned int data10[10]; 778c2ecf20Sopenharmony_ci unsigned int data8[8]; 788c2ecf20Sopenharmony_ci}; 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ciunion vin_data16 { 818c2ecf20Sopenharmony_ci unsigned int data16[16]; 828c2ecf20Sopenharmony_ci unsigned int data12[12]; 838c2ecf20Sopenharmony_ci unsigned int data10[10]; 848c2ecf20Sopenharmony_ci unsigned int data8[8]; 858c2ecf20Sopenharmony_ci}; 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ciunion vin_data { 888c2ecf20Sopenharmony_ci unsigned int data24[24]; 898c2ecf20Sopenharmony_ci unsigned int data20[20]; 908c2ecf20Sopenharmony_ci unsigned int data16[16]; 918c2ecf20Sopenharmony_ci unsigned int data12[12]; 928c2ecf20Sopenharmony_ci unsigned int data10[10]; 938c2ecf20Sopenharmony_ci unsigned int data8[8]; 948c2ecf20Sopenharmony_ci unsigned int data4[4]; 958c2ecf20Sopenharmony_ci}; 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci#define SH_PFC_FUNCTION(n) \ 988c2ecf20Sopenharmony_ci { \ 998c2ecf20Sopenharmony_ci .name = #n, \ 1008c2ecf20Sopenharmony_ci .groups = n##_groups, \ 1018c2ecf20Sopenharmony_ci .nr_groups = ARRAY_SIZE(n##_groups), \ 1028c2ecf20Sopenharmony_ci } 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_cistruct sh_pfc_function { 1058c2ecf20Sopenharmony_ci const char *name; 1068c2ecf20Sopenharmony_ci const char * const *groups; 1078c2ecf20Sopenharmony_ci unsigned int nr_groups; 1088c2ecf20Sopenharmony_ci}; 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_cistruct pinmux_func { 1118c2ecf20Sopenharmony_ci u16 enum_id; 1128c2ecf20Sopenharmony_ci const char *name; 1138c2ecf20Sopenharmony_ci}; 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_cistruct pinmux_cfg_reg { 1168c2ecf20Sopenharmony_ci u32 reg; 1178c2ecf20Sopenharmony_ci u8 reg_width, field_width; 1188c2ecf20Sopenharmony_ci#ifdef DEBUG 1198c2ecf20Sopenharmony_ci u16 nr_enum_ids; /* for variable width regs only */ 1208c2ecf20Sopenharmony_ci#define SET_NR_ENUM_IDS(n) .nr_enum_ids = n, 1218c2ecf20Sopenharmony_ci#else 1228c2ecf20Sopenharmony_ci#define SET_NR_ENUM_IDS(n) 1238c2ecf20Sopenharmony_ci#endif 1248c2ecf20Sopenharmony_ci const u16 *enum_ids; 1258c2ecf20Sopenharmony_ci const u8 *var_field_width; 1268c2ecf20Sopenharmony_ci}; 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci#define GROUP(...) __VA_ARGS__ 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci/* 1318c2ecf20Sopenharmony_ci * Describe a config register consisting of several fields of the same width 1328c2ecf20Sopenharmony_ci * - name: Register name (unused, for documentation purposes only) 1338c2ecf20Sopenharmony_ci * - r: Physical register address 1348c2ecf20Sopenharmony_ci * - r_width: Width of the register (in bits) 1358c2ecf20Sopenharmony_ci * - f_width: Width of the fixed-width register fields (in bits) 1368c2ecf20Sopenharmony_ci * - ids: For each register field (from left to right, i.e. MSB to LSB), 1378c2ecf20Sopenharmony_ci * 2^f_width enum IDs must be specified, one for each possible 1388c2ecf20Sopenharmony_ci * combination of the register field bit values, all wrapped using 1398c2ecf20Sopenharmony_ci * the GROUP() macro. 1408c2ecf20Sopenharmony_ci */ 1418c2ecf20Sopenharmony_ci#define PINMUX_CFG_REG(name, r, r_width, f_width, ids) \ 1428c2ecf20Sopenharmony_ci .reg = r, .reg_width = r_width, \ 1438c2ecf20Sopenharmony_ci .field_width = f_width + BUILD_BUG_ON_ZERO(r_width % f_width) + \ 1448c2ecf20Sopenharmony_ci BUILD_BUG_ON_ZERO(sizeof((const u16 []) { ids }) / sizeof(u16) != \ 1458c2ecf20Sopenharmony_ci (r_width / f_width) * (1 << f_width)), \ 1468c2ecf20Sopenharmony_ci .enum_ids = (const u16 [(r_width / f_width) * (1 << f_width)]) \ 1478c2ecf20Sopenharmony_ci { ids } 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci/* 1508c2ecf20Sopenharmony_ci * Describe a config register consisting of several fields of different widths 1518c2ecf20Sopenharmony_ci * - name: Register name (unused, for documentation purposes only) 1528c2ecf20Sopenharmony_ci * - r: Physical register address 1538c2ecf20Sopenharmony_ci * - r_width: Width of the register (in bits) 1548c2ecf20Sopenharmony_ci * - f_widths: List of widths of the register fields (in bits), from left 1558c2ecf20Sopenharmony_ci * to right (i.e. MSB to LSB), wrapped using the GROUP() macro. 1568c2ecf20Sopenharmony_ci * - ids: For each register field (from left to right, i.e. MSB to LSB), 1578c2ecf20Sopenharmony_ci * 2^f_widths[i] enum IDs must be specified, one for each possible 1588c2ecf20Sopenharmony_ci * combination of the register field bit values, all wrapped using 1598c2ecf20Sopenharmony_ci * the GROUP() macro. 1608c2ecf20Sopenharmony_ci */ 1618c2ecf20Sopenharmony_ci#define PINMUX_CFG_REG_VAR(name, r, r_width, f_widths, ids) \ 1628c2ecf20Sopenharmony_ci .reg = r, .reg_width = r_width, \ 1638c2ecf20Sopenharmony_ci .var_field_width = (const u8 []) { f_widths, 0 }, \ 1648c2ecf20Sopenharmony_ci SET_NR_ENUM_IDS(sizeof((const u16 []) { ids }) / sizeof(u16)) \ 1658c2ecf20Sopenharmony_ci .enum_ids = (const u16 []) { ids } 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_cistruct pinmux_drive_reg_field { 1688c2ecf20Sopenharmony_ci u16 pin; 1698c2ecf20Sopenharmony_ci u8 offset; 1708c2ecf20Sopenharmony_ci u8 size; 1718c2ecf20Sopenharmony_ci}; 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_cistruct pinmux_drive_reg { 1748c2ecf20Sopenharmony_ci u32 reg; 1758c2ecf20Sopenharmony_ci const struct pinmux_drive_reg_field fields[8]; 1768c2ecf20Sopenharmony_ci}; 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ci#define PINMUX_DRIVE_REG(name, r) \ 1798c2ecf20Sopenharmony_ci .reg = r, \ 1808c2ecf20Sopenharmony_ci .fields = 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_cistruct pinmux_bias_reg { 1838c2ecf20Sopenharmony_ci u32 puen; /* Pull-enable or pull-up control register */ 1848c2ecf20Sopenharmony_ci u32 pud; /* Pull-up/down control register (optional) */ 1858c2ecf20Sopenharmony_ci const u16 pins[32]; 1868c2ecf20Sopenharmony_ci}; 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci#define PINMUX_BIAS_REG(name1, r1, name2, r2) \ 1898c2ecf20Sopenharmony_ci .puen = r1, \ 1908c2ecf20Sopenharmony_ci .pud = r2, \ 1918c2ecf20Sopenharmony_ci .pins = 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_cistruct pinmux_ioctrl_reg { 1948c2ecf20Sopenharmony_ci u32 reg; 1958c2ecf20Sopenharmony_ci}; 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_cistruct pinmux_data_reg { 1988c2ecf20Sopenharmony_ci u32 reg; 1998c2ecf20Sopenharmony_ci u8 reg_width; 2008c2ecf20Sopenharmony_ci const u16 *enum_ids; 2018c2ecf20Sopenharmony_ci}; 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci/* 2048c2ecf20Sopenharmony_ci * Describe a data register 2058c2ecf20Sopenharmony_ci * - name: Register name (unused, for documentation purposes only) 2068c2ecf20Sopenharmony_ci * - r: Physical register address 2078c2ecf20Sopenharmony_ci * - r_width: Width of the register (in bits) 2088c2ecf20Sopenharmony_ci * - ids: For each register bit (from left to right, i.e. MSB to LSB), one 2098c2ecf20Sopenharmony_ci * enum ID must be specified, all wrapped using the GROUP() macro. 2108c2ecf20Sopenharmony_ci */ 2118c2ecf20Sopenharmony_ci#define PINMUX_DATA_REG(name, r, r_width, ids) \ 2128c2ecf20Sopenharmony_ci .reg = r, .reg_width = r_width + \ 2138c2ecf20Sopenharmony_ci BUILD_BUG_ON_ZERO(sizeof((const u16 []) { ids }) / sizeof(u16) != \ 2148c2ecf20Sopenharmony_ci r_width), \ 2158c2ecf20Sopenharmony_ci .enum_ids = (const u16 [r_width]) { ids } 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_cistruct pinmux_irq { 2188c2ecf20Sopenharmony_ci const short *gpios; 2198c2ecf20Sopenharmony_ci}; 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_ci/* 2228c2ecf20Sopenharmony_ci * Describe the mapping from GPIOs to a single IRQ 2238c2ecf20Sopenharmony_ci * - ids...: List of GPIOs that are mapped to the same IRQ 2248c2ecf20Sopenharmony_ci */ 2258c2ecf20Sopenharmony_ci#define PINMUX_IRQ(ids...) \ 2268c2ecf20Sopenharmony_ci { .gpios = (const short []) { ids, -1 } } 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_cistruct pinmux_range { 2298c2ecf20Sopenharmony_ci u16 begin; 2308c2ecf20Sopenharmony_ci u16 end; 2318c2ecf20Sopenharmony_ci u16 force; 2328c2ecf20Sopenharmony_ci}; 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_cistruct sh_pfc_window { 2358c2ecf20Sopenharmony_ci phys_addr_t phys; 2368c2ecf20Sopenharmony_ci void __iomem *virt; 2378c2ecf20Sopenharmony_ci unsigned long size; 2388c2ecf20Sopenharmony_ci}; 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_cistruct sh_pfc_pin_range; 2418c2ecf20Sopenharmony_ci 2428c2ecf20Sopenharmony_cistruct sh_pfc { 2438c2ecf20Sopenharmony_ci struct device *dev; 2448c2ecf20Sopenharmony_ci const struct sh_pfc_soc_info *info; 2458c2ecf20Sopenharmony_ci spinlock_t lock; 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_ci unsigned int num_windows; 2488c2ecf20Sopenharmony_ci struct sh_pfc_window *windows; 2498c2ecf20Sopenharmony_ci unsigned int num_irqs; 2508c2ecf20Sopenharmony_ci unsigned int *irqs; 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ci struct sh_pfc_pin_range *ranges; 2538c2ecf20Sopenharmony_ci unsigned int nr_ranges; 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ci unsigned int nr_gpio_pins; 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_ci struct sh_pfc_chip *gpio; 2588c2ecf20Sopenharmony_ci u32 *saved_regs; 2598c2ecf20Sopenharmony_ci}; 2608c2ecf20Sopenharmony_ci 2618c2ecf20Sopenharmony_cistruct sh_pfc_soc_operations { 2628c2ecf20Sopenharmony_ci int (*init)(struct sh_pfc *pfc); 2638c2ecf20Sopenharmony_ci unsigned int (*get_bias)(struct sh_pfc *pfc, unsigned int pin); 2648c2ecf20Sopenharmony_ci void (*set_bias)(struct sh_pfc *pfc, unsigned int pin, 2658c2ecf20Sopenharmony_ci unsigned int bias); 2668c2ecf20Sopenharmony_ci int (*pin_to_pocctrl)(struct sh_pfc *pfc, unsigned int pin, u32 *pocctrl); 2678c2ecf20Sopenharmony_ci}; 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_cistruct sh_pfc_soc_info { 2708c2ecf20Sopenharmony_ci const char *name; 2718c2ecf20Sopenharmony_ci const struct sh_pfc_soc_operations *ops; 2728c2ecf20Sopenharmony_ci 2738c2ecf20Sopenharmony_ci struct pinmux_range input; 2748c2ecf20Sopenharmony_ci struct pinmux_range output; 2758c2ecf20Sopenharmony_ci struct pinmux_range function; 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci const struct sh_pfc_pin *pins; 2788c2ecf20Sopenharmony_ci unsigned int nr_pins; 2798c2ecf20Sopenharmony_ci const struct sh_pfc_pin_group *groups; 2808c2ecf20Sopenharmony_ci unsigned int nr_groups; 2818c2ecf20Sopenharmony_ci const struct sh_pfc_function *functions; 2828c2ecf20Sopenharmony_ci unsigned int nr_functions; 2838c2ecf20Sopenharmony_ci 2848c2ecf20Sopenharmony_ci#ifdef CONFIG_PINCTRL_SH_FUNC_GPIO 2858c2ecf20Sopenharmony_ci const struct pinmux_func *func_gpios; 2868c2ecf20Sopenharmony_ci unsigned int nr_func_gpios; 2878c2ecf20Sopenharmony_ci#endif 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_ci const struct pinmux_cfg_reg *cfg_regs; 2908c2ecf20Sopenharmony_ci const struct pinmux_drive_reg *drive_regs; 2918c2ecf20Sopenharmony_ci const struct pinmux_bias_reg *bias_regs; 2928c2ecf20Sopenharmony_ci const struct pinmux_ioctrl_reg *ioctrl_regs; 2938c2ecf20Sopenharmony_ci const struct pinmux_data_reg *data_regs; 2948c2ecf20Sopenharmony_ci 2958c2ecf20Sopenharmony_ci const u16 *pinmux_data; 2968c2ecf20Sopenharmony_ci unsigned int pinmux_data_size; 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_ci const struct pinmux_irq *gpio_irq; 2998c2ecf20Sopenharmony_ci unsigned int gpio_irq_size; 3008c2ecf20Sopenharmony_ci 3018c2ecf20Sopenharmony_ci u32 unlock_reg; 3028c2ecf20Sopenharmony_ci}; 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info emev2_pinmux_info; 3058c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info r8a73a4_pinmux_info; 3068c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info r8a7740_pinmux_info; 3078c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info r8a7742_pinmux_info; 3088c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info r8a7743_pinmux_info; 3098c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info r8a7744_pinmux_info; 3108c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info r8a7745_pinmux_info; 3118c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info r8a77470_pinmux_info; 3128c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info r8a774a1_pinmux_info; 3138c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info r8a774b1_pinmux_info; 3148c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info r8a774c0_pinmux_info; 3158c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info r8a774e1_pinmux_info; 3168c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info r8a7778_pinmux_info; 3178c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info r8a7779_pinmux_info; 3188c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info r8a7790_pinmux_info; 3198c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info r8a7791_pinmux_info; 3208c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info r8a7792_pinmux_info; 3218c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info r8a7793_pinmux_info; 3228c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info r8a7794_pinmux_info; 3238c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info r8a77950_pinmux_info __weak; 3248c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info r8a77951_pinmux_info __weak; 3258c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info r8a77960_pinmux_info; 3268c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info r8a77961_pinmux_info; 3278c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info r8a77965_pinmux_info; 3288c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info r8a77970_pinmux_info; 3298c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info r8a77980_pinmux_info; 3308c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info r8a77990_pinmux_info; 3318c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info r8a77995_pinmux_info; 3328c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info sh7203_pinmux_info; 3338c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info sh7264_pinmux_info; 3348c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info sh7269_pinmux_info; 3358c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info sh73a0_pinmux_info; 3368c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info sh7720_pinmux_info; 3378c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info sh7722_pinmux_info; 3388c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info sh7723_pinmux_info; 3398c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info sh7724_pinmux_info; 3408c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info sh7734_pinmux_info; 3418c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info sh7757_pinmux_info; 3428c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info sh7785_pinmux_info; 3438c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info sh7786_pinmux_info; 3448c2ecf20Sopenharmony_ciextern const struct sh_pfc_soc_info shx3_pinmux_info; 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_ci/* ----------------------------------------------------------------------------- 3478c2ecf20Sopenharmony_ci * Helper macros to create pin and port lists 3488c2ecf20Sopenharmony_ci */ 3498c2ecf20Sopenharmony_ci 3508c2ecf20Sopenharmony_ci/* 3518c2ecf20Sopenharmony_ci * sh_pfc_soc_info pinmux_data array macros 3528c2ecf20Sopenharmony_ci */ 3538c2ecf20Sopenharmony_ci 3548c2ecf20Sopenharmony_ci/* 3558c2ecf20Sopenharmony_ci * Describe generic pinmux data 3568c2ecf20Sopenharmony_ci * - data_or_mark: *_DATA or *_MARK enum ID 3578c2ecf20Sopenharmony_ci * - ids...: List of enum IDs to associate with data_or_mark 3588c2ecf20Sopenharmony_ci */ 3598c2ecf20Sopenharmony_ci#define PINMUX_DATA(data_or_mark, ids...) data_or_mark, ids, 0 3608c2ecf20Sopenharmony_ci 3618c2ecf20Sopenharmony_ci/* 3628c2ecf20Sopenharmony_ci * Describe a pinmux configuration without GPIO function that needs 3638c2ecf20Sopenharmony_ci * configuration in a Peripheral Function Select Register (IPSR) 3648c2ecf20Sopenharmony_ci * - ipsr: IPSR field (unused, for documentation purposes only) 3658c2ecf20Sopenharmony_ci * - fn: Function name, referring to a field in the IPSR 3668c2ecf20Sopenharmony_ci */ 3678c2ecf20Sopenharmony_ci#define PINMUX_IPSR_NOGP(ipsr, fn) \ 3688c2ecf20Sopenharmony_ci PINMUX_DATA(fn##_MARK, FN_##fn) 3698c2ecf20Sopenharmony_ci 3708c2ecf20Sopenharmony_ci/* 3718c2ecf20Sopenharmony_ci * Describe a pinmux configuration with GPIO function that needs configuration 3728c2ecf20Sopenharmony_ci * in both a Peripheral Function Select Register (IPSR) and in a 3738c2ecf20Sopenharmony_ci * GPIO/Peripheral Function Select Register (GPSR) 3748c2ecf20Sopenharmony_ci * - ipsr: IPSR field 3758c2ecf20Sopenharmony_ci * - fn: Function name, also referring to the IPSR field 3768c2ecf20Sopenharmony_ci */ 3778c2ecf20Sopenharmony_ci#define PINMUX_IPSR_GPSR(ipsr, fn) \ 3788c2ecf20Sopenharmony_ci PINMUX_DATA(fn##_MARK, FN_##fn, FN_##ipsr) 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_ci/* 3818c2ecf20Sopenharmony_ci * Describe a pinmux configuration without GPIO function that needs 3828c2ecf20Sopenharmony_ci * configuration in a Peripheral Function Select Register (IPSR), and where the 3838c2ecf20Sopenharmony_ci * pinmux function has a representation in a Module Select Register (MOD_SEL). 3848c2ecf20Sopenharmony_ci * - ipsr: IPSR field (unused, for documentation purposes only) 3858c2ecf20Sopenharmony_ci * - fn: Function name, also referring to the IPSR field 3868c2ecf20Sopenharmony_ci * - msel: Module selector 3878c2ecf20Sopenharmony_ci */ 3888c2ecf20Sopenharmony_ci#define PINMUX_IPSR_NOGM(ipsr, fn, msel) \ 3898c2ecf20Sopenharmony_ci PINMUX_DATA(fn##_MARK, FN_##fn, FN_##msel) 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_ci/* 3928c2ecf20Sopenharmony_ci * Describe a pinmux configuration with GPIO function where the pinmux function 3938c2ecf20Sopenharmony_ci * has no representation in a Peripheral Function Select Register (IPSR), but 3948c2ecf20Sopenharmony_ci * instead solely depends on a group selection. 3958c2ecf20Sopenharmony_ci * - gpsr: GPSR field 3968c2ecf20Sopenharmony_ci * - fn: Function name, also referring to the GPSR field 3978c2ecf20Sopenharmony_ci * - gsel: Group selector 3988c2ecf20Sopenharmony_ci */ 3998c2ecf20Sopenharmony_ci#define PINMUX_IPSR_NOFN(gpsr, fn, gsel) \ 4008c2ecf20Sopenharmony_ci PINMUX_DATA(fn##_MARK, FN_##gpsr, FN_##gsel) 4018c2ecf20Sopenharmony_ci 4028c2ecf20Sopenharmony_ci/* 4038c2ecf20Sopenharmony_ci * Describe a pinmux configuration with GPIO function that needs configuration 4048c2ecf20Sopenharmony_ci * in both a Peripheral Function Select Register (IPSR) and a GPIO/Peripheral 4058c2ecf20Sopenharmony_ci * Function Select Register (GPSR), and where the pinmux function has a 4068c2ecf20Sopenharmony_ci * representation in a Module Select Register (MOD_SEL). 4078c2ecf20Sopenharmony_ci * - ipsr: IPSR field 4088c2ecf20Sopenharmony_ci * - fn: Function name, also referring to the IPSR field 4098c2ecf20Sopenharmony_ci * - msel: Module selector 4108c2ecf20Sopenharmony_ci */ 4118c2ecf20Sopenharmony_ci#define PINMUX_IPSR_MSEL(ipsr, fn, msel) \ 4128c2ecf20Sopenharmony_ci PINMUX_DATA(fn##_MARK, FN_##msel, FN_##fn, FN_##ipsr) 4138c2ecf20Sopenharmony_ci 4148c2ecf20Sopenharmony_ci/* 4158c2ecf20Sopenharmony_ci * Describe a pinmux configuration similar to PINMUX_IPSR_MSEL, but with 4168c2ecf20Sopenharmony_ci * an additional select register that controls physical multiplexing 4178c2ecf20Sopenharmony_ci * with another pin. 4188c2ecf20Sopenharmony_ci * - ipsr: IPSR field 4198c2ecf20Sopenharmony_ci * - fn: Function name, also referring to the IPSR field 4208c2ecf20Sopenharmony_ci * - psel: Physical multiplexing selector 4218c2ecf20Sopenharmony_ci * - msel: Module selector 4228c2ecf20Sopenharmony_ci */ 4238c2ecf20Sopenharmony_ci#define PINMUX_IPSR_PHYS_MSEL(ipsr, fn, psel, msel) \ 4248c2ecf20Sopenharmony_ci PINMUX_DATA(fn##_MARK, FN_##psel, FN_##msel, FN_##fn, FN_##ipsr) 4258c2ecf20Sopenharmony_ci 4268c2ecf20Sopenharmony_ci/* 4278c2ecf20Sopenharmony_ci * Describe a pinmux configuration in which a pin is physically multiplexed 4288c2ecf20Sopenharmony_ci * with other pins. 4298c2ecf20Sopenharmony_ci * - ipsr: IPSR field 4308c2ecf20Sopenharmony_ci * - fn: Function name 4318c2ecf20Sopenharmony_ci * - psel: Physical multiplexing selector 4328c2ecf20Sopenharmony_ci */ 4338c2ecf20Sopenharmony_ci#define PINMUX_IPSR_PHYS(ipsr, fn, psel) \ 4348c2ecf20Sopenharmony_ci PINMUX_DATA(fn##_MARK, FN_##psel, FN_##ipsr) 4358c2ecf20Sopenharmony_ci 4368c2ecf20Sopenharmony_ci/* 4378c2ecf20Sopenharmony_ci * Describe a pinmux configuration for a single-function pin with GPIO 4388c2ecf20Sopenharmony_ci * capability. 4398c2ecf20Sopenharmony_ci * - fn: Function name 4408c2ecf20Sopenharmony_ci */ 4418c2ecf20Sopenharmony_ci#define PINMUX_SINGLE(fn) \ 4428c2ecf20Sopenharmony_ci PINMUX_DATA(fn##_MARK, FN_##fn) 4438c2ecf20Sopenharmony_ci 4448c2ecf20Sopenharmony_ci/* 4458c2ecf20Sopenharmony_ci * GP port style (32 ports banks) 4468c2ecf20Sopenharmony_ci */ 4478c2ecf20Sopenharmony_ci 4488c2ecf20Sopenharmony_ci#define PORT_GP_CFG_1(bank, pin, fn, sfx, cfg) \ 4498c2ecf20Sopenharmony_ci fn(bank, pin, GP_##bank##_##pin, sfx, cfg) 4508c2ecf20Sopenharmony_ci#define PORT_GP_1(bank, pin, fn, sfx) PORT_GP_CFG_1(bank, pin, fn, sfx, 0) 4518c2ecf20Sopenharmony_ci 4528c2ecf20Sopenharmony_ci#define PORT_GP_CFG_4(bank, fn, sfx, cfg) \ 4538c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 0, fn, sfx, cfg), \ 4548c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 1, fn, sfx, cfg), \ 4558c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 2, fn, sfx, cfg), \ 4568c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 3, fn, sfx, cfg) 4578c2ecf20Sopenharmony_ci#define PORT_GP_4(bank, fn, sfx) PORT_GP_CFG_4(bank, fn, sfx, 0) 4588c2ecf20Sopenharmony_ci 4598c2ecf20Sopenharmony_ci#define PORT_GP_CFG_6(bank, fn, sfx, cfg) \ 4608c2ecf20Sopenharmony_ci PORT_GP_CFG_4(bank, fn, sfx, cfg), \ 4618c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 4, fn, sfx, cfg), \ 4628c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 5, fn, sfx, cfg) 4638c2ecf20Sopenharmony_ci#define PORT_GP_6(bank, fn, sfx) PORT_GP_CFG_6(bank, fn, sfx, 0) 4648c2ecf20Sopenharmony_ci 4658c2ecf20Sopenharmony_ci#define PORT_GP_CFG_8(bank, fn, sfx, cfg) \ 4668c2ecf20Sopenharmony_ci PORT_GP_CFG_6(bank, fn, sfx, cfg), \ 4678c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 6, fn, sfx, cfg), \ 4688c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 7, fn, sfx, cfg) 4698c2ecf20Sopenharmony_ci#define PORT_GP_8(bank, fn, sfx) PORT_GP_CFG_8(bank, fn, sfx, 0) 4708c2ecf20Sopenharmony_ci 4718c2ecf20Sopenharmony_ci#define PORT_GP_CFG_9(bank, fn, sfx, cfg) \ 4728c2ecf20Sopenharmony_ci PORT_GP_CFG_8(bank, fn, sfx, cfg), \ 4738c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 8, fn, sfx, cfg) 4748c2ecf20Sopenharmony_ci#define PORT_GP_9(bank, fn, sfx) PORT_GP_CFG_9(bank, fn, sfx, 0) 4758c2ecf20Sopenharmony_ci 4768c2ecf20Sopenharmony_ci#define PORT_GP_CFG_10(bank, fn, sfx, cfg) \ 4778c2ecf20Sopenharmony_ci PORT_GP_CFG_9(bank, fn, sfx, cfg), \ 4788c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 9, fn, sfx, cfg) 4798c2ecf20Sopenharmony_ci#define PORT_GP_10(bank, fn, sfx) PORT_GP_CFG_10(bank, fn, sfx, 0) 4808c2ecf20Sopenharmony_ci 4818c2ecf20Sopenharmony_ci#define PORT_GP_CFG_11(bank, fn, sfx, cfg) \ 4828c2ecf20Sopenharmony_ci PORT_GP_CFG_10(bank, fn, sfx, cfg), \ 4838c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 10, fn, sfx, cfg) 4848c2ecf20Sopenharmony_ci#define PORT_GP_11(bank, fn, sfx) PORT_GP_CFG_11(bank, fn, sfx, 0) 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_ci#define PORT_GP_CFG_12(bank, fn, sfx, cfg) \ 4878c2ecf20Sopenharmony_ci PORT_GP_CFG_11(bank, fn, sfx, cfg), \ 4888c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 11, fn, sfx, cfg) 4898c2ecf20Sopenharmony_ci#define PORT_GP_12(bank, fn, sfx) PORT_GP_CFG_12(bank, fn, sfx, 0) 4908c2ecf20Sopenharmony_ci 4918c2ecf20Sopenharmony_ci#define PORT_GP_CFG_14(bank, fn, sfx, cfg) \ 4928c2ecf20Sopenharmony_ci PORT_GP_CFG_12(bank, fn, sfx, cfg), \ 4938c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 12, fn, sfx, cfg), \ 4948c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 13, fn, sfx, cfg) 4958c2ecf20Sopenharmony_ci#define PORT_GP_14(bank, fn, sfx) PORT_GP_CFG_14(bank, fn, sfx, 0) 4968c2ecf20Sopenharmony_ci 4978c2ecf20Sopenharmony_ci#define PORT_GP_CFG_15(bank, fn, sfx, cfg) \ 4988c2ecf20Sopenharmony_ci PORT_GP_CFG_14(bank, fn, sfx, cfg), \ 4998c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 14, fn, sfx, cfg) 5008c2ecf20Sopenharmony_ci#define PORT_GP_15(bank, fn, sfx) PORT_GP_CFG_15(bank, fn, sfx, 0) 5018c2ecf20Sopenharmony_ci 5028c2ecf20Sopenharmony_ci#define PORT_GP_CFG_16(bank, fn, sfx, cfg) \ 5038c2ecf20Sopenharmony_ci PORT_GP_CFG_15(bank, fn, sfx, cfg), \ 5048c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 15, fn, sfx, cfg) 5058c2ecf20Sopenharmony_ci#define PORT_GP_16(bank, fn, sfx) PORT_GP_CFG_16(bank, fn, sfx, 0) 5068c2ecf20Sopenharmony_ci 5078c2ecf20Sopenharmony_ci#define PORT_GP_CFG_17(bank, fn, sfx, cfg) \ 5088c2ecf20Sopenharmony_ci PORT_GP_CFG_16(bank, fn, sfx, cfg), \ 5098c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 16, fn, sfx, cfg) 5108c2ecf20Sopenharmony_ci#define PORT_GP_17(bank, fn, sfx) PORT_GP_CFG_17(bank, fn, sfx, 0) 5118c2ecf20Sopenharmony_ci 5128c2ecf20Sopenharmony_ci#define PORT_GP_CFG_18(bank, fn, sfx, cfg) \ 5138c2ecf20Sopenharmony_ci PORT_GP_CFG_17(bank, fn, sfx, cfg), \ 5148c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 17, fn, sfx, cfg) 5158c2ecf20Sopenharmony_ci#define PORT_GP_18(bank, fn, sfx) PORT_GP_CFG_18(bank, fn, sfx, 0) 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_ci#define PORT_GP_CFG_20(bank, fn, sfx, cfg) \ 5188c2ecf20Sopenharmony_ci PORT_GP_CFG_18(bank, fn, sfx, cfg), \ 5198c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 18, fn, sfx, cfg), \ 5208c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 19, fn, sfx, cfg) 5218c2ecf20Sopenharmony_ci#define PORT_GP_20(bank, fn, sfx) PORT_GP_CFG_20(bank, fn, sfx, 0) 5228c2ecf20Sopenharmony_ci 5238c2ecf20Sopenharmony_ci#define PORT_GP_CFG_21(bank, fn, sfx, cfg) \ 5248c2ecf20Sopenharmony_ci PORT_GP_CFG_20(bank, fn, sfx, cfg), \ 5258c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 20, fn, sfx, cfg) 5268c2ecf20Sopenharmony_ci#define PORT_GP_21(bank, fn, sfx) PORT_GP_CFG_21(bank, fn, sfx, 0) 5278c2ecf20Sopenharmony_ci 5288c2ecf20Sopenharmony_ci#define PORT_GP_CFG_22(bank, fn, sfx, cfg) \ 5298c2ecf20Sopenharmony_ci PORT_GP_CFG_21(bank, fn, sfx, cfg), \ 5308c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 21, fn, sfx, cfg) 5318c2ecf20Sopenharmony_ci#define PORT_GP_22(bank, fn, sfx) PORT_GP_CFG_22(bank, fn, sfx, 0) 5328c2ecf20Sopenharmony_ci 5338c2ecf20Sopenharmony_ci#define PORT_GP_CFG_23(bank, fn, sfx, cfg) \ 5348c2ecf20Sopenharmony_ci PORT_GP_CFG_22(bank, fn, sfx, cfg), \ 5358c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 22, fn, sfx, cfg) 5368c2ecf20Sopenharmony_ci#define PORT_GP_23(bank, fn, sfx) PORT_GP_CFG_23(bank, fn, sfx, 0) 5378c2ecf20Sopenharmony_ci 5388c2ecf20Sopenharmony_ci#define PORT_GP_CFG_24(bank, fn, sfx, cfg) \ 5398c2ecf20Sopenharmony_ci PORT_GP_CFG_23(bank, fn, sfx, cfg), \ 5408c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 23, fn, sfx, cfg) 5418c2ecf20Sopenharmony_ci#define PORT_GP_24(bank, fn, sfx) PORT_GP_CFG_24(bank, fn, sfx, 0) 5428c2ecf20Sopenharmony_ci 5438c2ecf20Sopenharmony_ci#define PORT_GP_CFG_25(bank, fn, sfx, cfg) \ 5448c2ecf20Sopenharmony_ci PORT_GP_CFG_24(bank, fn, sfx, cfg), \ 5458c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 24, fn, sfx, cfg) 5468c2ecf20Sopenharmony_ci#define PORT_GP_25(bank, fn, sfx) PORT_GP_CFG_25(bank, fn, sfx, 0) 5478c2ecf20Sopenharmony_ci 5488c2ecf20Sopenharmony_ci#define PORT_GP_CFG_26(bank, fn, sfx, cfg) \ 5498c2ecf20Sopenharmony_ci PORT_GP_CFG_25(bank, fn, sfx, cfg), \ 5508c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 25, fn, sfx, cfg) 5518c2ecf20Sopenharmony_ci#define PORT_GP_26(bank, fn, sfx) PORT_GP_CFG_26(bank, fn, sfx, 0) 5528c2ecf20Sopenharmony_ci 5538c2ecf20Sopenharmony_ci#define PORT_GP_CFG_27(bank, fn, sfx, cfg) \ 5548c2ecf20Sopenharmony_ci PORT_GP_CFG_26(bank, fn, sfx, cfg), \ 5558c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 26, fn, sfx, cfg) 5568c2ecf20Sopenharmony_ci#define PORT_GP_27(bank, fn, sfx) PORT_GP_CFG_27(bank, fn, sfx, 0) 5578c2ecf20Sopenharmony_ci 5588c2ecf20Sopenharmony_ci#define PORT_GP_CFG_28(bank, fn, sfx, cfg) \ 5598c2ecf20Sopenharmony_ci PORT_GP_CFG_27(bank, fn, sfx, cfg), \ 5608c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 27, fn, sfx, cfg) 5618c2ecf20Sopenharmony_ci#define PORT_GP_28(bank, fn, sfx) PORT_GP_CFG_28(bank, fn, sfx, 0) 5628c2ecf20Sopenharmony_ci 5638c2ecf20Sopenharmony_ci#define PORT_GP_CFG_29(bank, fn, sfx, cfg) \ 5648c2ecf20Sopenharmony_ci PORT_GP_CFG_28(bank, fn, sfx, cfg), \ 5658c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 28, fn, sfx, cfg) 5668c2ecf20Sopenharmony_ci#define PORT_GP_29(bank, fn, sfx) PORT_GP_CFG_29(bank, fn, sfx, 0) 5678c2ecf20Sopenharmony_ci 5688c2ecf20Sopenharmony_ci#define PORT_GP_CFG_30(bank, fn, sfx, cfg) \ 5698c2ecf20Sopenharmony_ci PORT_GP_CFG_29(bank, fn, sfx, cfg), \ 5708c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 29, fn, sfx, cfg) 5718c2ecf20Sopenharmony_ci#define PORT_GP_30(bank, fn, sfx) PORT_GP_CFG_30(bank, fn, sfx, 0) 5728c2ecf20Sopenharmony_ci 5738c2ecf20Sopenharmony_ci#define PORT_GP_CFG_32(bank, fn, sfx, cfg) \ 5748c2ecf20Sopenharmony_ci PORT_GP_CFG_30(bank, fn, sfx, cfg), \ 5758c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 30, fn, sfx, cfg), \ 5768c2ecf20Sopenharmony_ci PORT_GP_CFG_1(bank, 31, fn, sfx, cfg) 5778c2ecf20Sopenharmony_ci#define PORT_GP_32(bank, fn, sfx) PORT_GP_CFG_32(bank, fn, sfx, 0) 5788c2ecf20Sopenharmony_ci 5798c2ecf20Sopenharmony_ci#define PORT_GP_32_REV(bank, fn, sfx) \ 5808c2ecf20Sopenharmony_ci PORT_GP_1(bank, 31, fn, sfx), PORT_GP_1(bank, 30, fn, sfx), \ 5818c2ecf20Sopenharmony_ci PORT_GP_1(bank, 29, fn, sfx), PORT_GP_1(bank, 28, fn, sfx), \ 5828c2ecf20Sopenharmony_ci PORT_GP_1(bank, 27, fn, sfx), PORT_GP_1(bank, 26, fn, sfx), \ 5838c2ecf20Sopenharmony_ci PORT_GP_1(bank, 25, fn, sfx), PORT_GP_1(bank, 24, fn, sfx), \ 5848c2ecf20Sopenharmony_ci PORT_GP_1(bank, 23, fn, sfx), PORT_GP_1(bank, 22, fn, sfx), \ 5858c2ecf20Sopenharmony_ci PORT_GP_1(bank, 21, fn, sfx), PORT_GP_1(bank, 20, fn, sfx), \ 5868c2ecf20Sopenharmony_ci PORT_GP_1(bank, 19, fn, sfx), PORT_GP_1(bank, 18, fn, sfx), \ 5878c2ecf20Sopenharmony_ci PORT_GP_1(bank, 17, fn, sfx), PORT_GP_1(bank, 16, fn, sfx), \ 5888c2ecf20Sopenharmony_ci PORT_GP_1(bank, 15, fn, sfx), PORT_GP_1(bank, 14, fn, sfx), \ 5898c2ecf20Sopenharmony_ci PORT_GP_1(bank, 13, fn, sfx), PORT_GP_1(bank, 12, fn, sfx), \ 5908c2ecf20Sopenharmony_ci PORT_GP_1(bank, 11, fn, sfx), PORT_GP_1(bank, 10, fn, sfx), \ 5918c2ecf20Sopenharmony_ci PORT_GP_1(bank, 9, fn, sfx), PORT_GP_1(bank, 8, fn, sfx), \ 5928c2ecf20Sopenharmony_ci PORT_GP_1(bank, 7, fn, sfx), PORT_GP_1(bank, 6, fn, sfx), \ 5938c2ecf20Sopenharmony_ci PORT_GP_1(bank, 5, fn, sfx), PORT_GP_1(bank, 4, fn, sfx), \ 5948c2ecf20Sopenharmony_ci PORT_GP_1(bank, 3, fn, sfx), PORT_GP_1(bank, 2, fn, sfx), \ 5958c2ecf20Sopenharmony_ci PORT_GP_1(bank, 1, fn, sfx), PORT_GP_1(bank, 0, fn, sfx) 5968c2ecf20Sopenharmony_ci 5978c2ecf20Sopenharmony_ci/* GP_ALL(suffix) - Expand to a list of GP_#_#_suffix */ 5988c2ecf20Sopenharmony_ci#define _GP_ALL(bank, pin, name, sfx, cfg) name##_##sfx 5998c2ecf20Sopenharmony_ci#define GP_ALL(str) CPU_ALL_GP(_GP_ALL, str) 6008c2ecf20Sopenharmony_ci 6018c2ecf20Sopenharmony_ci/* PINMUX_GPIO_GP_ALL - Expand to a list of sh_pfc_pin entries */ 6028c2ecf20Sopenharmony_ci#define _GP_GPIO(bank, _pin, _name, sfx, cfg) \ 6038c2ecf20Sopenharmony_ci { \ 6048c2ecf20Sopenharmony_ci .pin = (bank * 32) + _pin, \ 6058c2ecf20Sopenharmony_ci .name = __stringify(_name), \ 6068c2ecf20Sopenharmony_ci .enum_id = _name##_DATA, \ 6078c2ecf20Sopenharmony_ci .configs = cfg, \ 6088c2ecf20Sopenharmony_ci } 6098c2ecf20Sopenharmony_ci#define PINMUX_GPIO_GP_ALL() CPU_ALL_GP(_GP_GPIO, unused) 6108c2ecf20Sopenharmony_ci 6118c2ecf20Sopenharmony_ci/* PINMUX_DATA_GP_ALL - Expand to a list of name_DATA, name_FN marks */ 6128c2ecf20Sopenharmony_ci#define _GP_DATA(bank, pin, name, sfx, cfg) PINMUX_DATA(name##_DATA, name##_FN) 6138c2ecf20Sopenharmony_ci#define PINMUX_DATA_GP_ALL() CPU_ALL_GP(_GP_DATA, unused) 6148c2ecf20Sopenharmony_ci 6158c2ecf20Sopenharmony_ci/* 6168c2ecf20Sopenharmony_ci * GP_ASSIGN_LAST() - Expand to an enum definition for the last GP pin 6178c2ecf20Sopenharmony_ci * 6188c2ecf20Sopenharmony_ci * The largest GP pin index is obtained by taking the size of a union, 6198c2ecf20Sopenharmony_ci * containing one array per GP pin, sized by the corresponding pin index. 6208c2ecf20Sopenharmony_ci * As the fields in the CPU_ALL_GP() macro definition are separated by commas, 6218c2ecf20Sopenharmony_ci * while the members of a union must be terminated by semicolons, the commas 6228c2ecf20Sopenharmony_ci * are absorbed by wrapping them inside dummy attributes. 6238c2ecf20Sopenharmony_ci */ 6248c2ecf20Sopenharmony_ci#define _GP_ENTRY(bank, pin, name, sfx, cfg) \ 6258c2ecf20Sopenharmony_ci deprecated)); char name[(bank * 32) + pin] __attribute__((deprecated 6268c2ecf20Sopenharmony_ci#define GP_ASSIGN_LAST() \ 6278c2ecf20Sopenharmony_ci GP_LAST = sizeof(union { \ 6288c2ecf20Sopenharmony_ci char dummy[0] __attribute__((deprecated, \ 6298c2ecf20Sopenharmony_ci CPU_ALL_GP(_GP_ENTRY, unused), \ 6308c2ecf20Sopenharmony_ci deprecated)); \ 6318c2ecf20Sopenharmony_ci }) 6328c2ecf20Sopenharmony_ci 6338c2ecf20Sopenharmony_ci/* 6348c2ecf20Sopenharmony_ci * PORT style (linear pin space) 6358c2ecf20Sopenharmony_ci */ 6368c2ecf20Sopenharmony_ci 6378c2ecf20Sopenharmony_ci#define PORT_1(pn, fn, pfx, sfx) fn(pn, pfx, sfx) 6388c2ecf20Sopenharmony_ci 6398c2ecf20Sopenharmony_ci#define PORT_10(pn, fn, pfx, sfx) \ 6408c2ecf20Sopenharmony_ci PORT_1(pn, fn, pfx##0, sfx), PORT_1(pn+1, fn, pfx##1, sfx), \ 6418c2ecf20Sopenharmony_ci PORT_1(pn+2, fn, pfx##2, sfx), PORT_1(pn+3, fn, pfx##3, sfx), \ 6428c2ecf20Sopenharmony_ci PORT_1(pn+4, fn, pfx##4, sfx), PORT_1(pn+5, fn, pfx##5, sfx), \ 6438c2ecf20Sopenharmony_ci PORT_1(pn+6, fn, pfx##6, sfx), PORT_1(pn+7, fn, pfx##7, sfx), \ 6448c2ecf20Sopenharmony_ci PORT_1(pn+8, fn, pfx##8, sfx), PORT_1(pn+9, fn, pfx##9, sfx) 6458c2ecf20Sopenharmony_ci 6468c2ecf20Sopenharmony_ci#define PORT_90(pn, fn, pfx, sfx) \ 6478c2ecf20Sopenharmony_ci PORT_10(pn+10, fn, pfx##1, sfx), PORT_10(pn+20, fn, pfx##2, sfx), \ 6488c2ecf20Sopenharmony_ci PORT_10(pn+30, fn, pfx##3, sfx), PORT_10(pn+40, fn, pfx##4, sfx), \ 6498c2ecf20Sopenharmony_ci PORT_10(pn+50, fn, pfx##5, sfx), PORT_10(pn+60, fn, pfx##6, sfx), \ 6508c2ecf20Sopenharmony_ci PORT_10(pn+70, fn, pfx##7, sfx), PORT_10(pn+80, fn, pfx##8, sfx), \ 6518c2ecf20Sopenharmony_ci PORT_10(pn+90, fn, pfx##9, sfx) 6528c2ecf20Sopenharmony_ci 6538c2ecf20Sopenharmony_ci/* PORT_ALL(suffix) - Expand to a list of PORT_#_suffix */ 6548c2ecf20Sopenharmony_ci#define _PORT_ALL(pn, pfx, sfx) pfx##_##sfx 6558c2ecf20Sopenharmony_ci#define PORT_ALL(str) CPU_ALL_PORT(_PORT_ALL, PORT, str) 6568c2ecf20Sopenharmony_ci 6578c2ecf20Sopenharmony_ci/* PINMUX_GPIO - Expand to a sh_pfc_pin entry */ 6588c2ecf20Sopenharmony_ci#define PINMUX_GPIO(_pin) \ 6598c2ecf20Sopenharmony_ci [GPIO_##_pin] = { \ 6608c2ecf20Sopenharmony_ci .pin = (u16)-1, \ 6618c2ecf20Sopenharmony_ci .name = __stringify(GPIO_##_pin), \ 6628c2ecf20Sopenharmony_ci .enum_id = _pin##_DATA, \ 6638c2ecf20Sopenharmony_ci } 6648c2ecf20Sopenharmony_ci 6658c2ecf20Sopenharmony_ci/* SH_PFC_PIN_CFG - Expand to a sh_pfc_pin entry (named PORT#) with config */ 6668c2ecf20Sopenharmony_ci#define SH_PFC_PIN_CFG(_pin, cfgs) \ 6678c2ecf20Sopenharmony_ci { \ 6688c2ecf20Sopenharmony_ci .pin = _pin, \ 6698c2ecf20Sopenharmony_ci .name = __stringify(PORT##_pin), \ 6708c2ecf20Sopenharmony_ci .enum_id = PORT##_pin##_DATA, \ 6718c2ecf20Sopenharmony_ci .configs = cfgs, \ 6728c2ecf20Sopenharmony_ci } 6738c2ecf20Sopenharmony_ci 6748c2ecf20Sopenharmony_ci/* PINMUX_DATA_ALL - Expand to a list of PORT_name_DATA, PORT_name_FN0, 6758c2ecf20Sopenharmony_ci * PORT_name_OUT, PORT_name_IN marks 6768c2ecf20Sopenharmony_ci */ 6778c2ecf20Sopenharmony_ci#define _PORT_DATA(pn, pfx, sfx) \ 6788c2ecf20Sopenharmony_ci PINMUX_DATA(PORT##pfx##_DATA, PORT##pfx##_FN0, \ 6798c2ecf20Sopenharmony_ci PORT##pfx##_OUT, PORT##pfx##_IN) 6808c2ecf20Sopenharmony_ci#define PINMUX_DATA_ALL() CPU_ALL_PORT(_PORT_DATA, , unused) 6818c2ecf20Sopenharmony_ci 6828c2ecf20Sopenharmony_ci/* 6838c2ecf20Sopenharmony_ci * PORT_ASSIGN_LAST() - Expand to an enum definition for the last PORT pin 6848c2ecf20Sopenharmony_ci * 6858c2ecf20Sopenharmony_ci * The largest PORT pin index is obtained by taking the size of a union, 6868c2ecf20Sopenharmony_ci * containing one array per PORT pin, sized by the corresponding pin index. 6878c2ecf20Sopenharmony_ci * As the fields in the CPU_ALL_PORT() macro definition are separated by 6888c2ecf20Sopenharmony_ci * commas, while the members of a union must be terminated by semicolons, the 6898c2ecf20Sopenharmony_ci * commas are absorbed by wrapping them inside dummy attributes. 6908c2ecf20Sopenharmony_ci */ 6918c2ecf20Sopenharmony_ci#define _PORT_ENTRY(pn, pfx, sfx) \ 6928c2ecf20Sopenharmony_ci deprecated)); char pfx[pn] __attribute__((deprecated 6938c2ecf20Sopenharmony_ci#define PORT_ASSIGN_LAST() \ 6948c2ecf20Sopenharmony_ci PORT_LAST = sizeof(union { \ 6958c2ecf20Sopenharmony_ci char dummy[0] __attribute__((deprecated, \ 6968c2ecf20Sopenharmony_ci CPU_ALL_PORT(_PORT_ENTRY, PORT, unused), \ 6978c2ecf20Sopenharmony_ci deprecated)); \ 6988c2ecf20Sopenharmony_ci }) 6998c2ecf20Sopenharmony_ci 7008c2ecf20Sopenharmony_ci/* GPIO_FN(name) - Expand to a sh_pfc_pin entry for a function GPIO */ 7018c2ecf20Sopenharmony_ci#define PINMUX_GPIO_FN(gpio, base, data_or_mark) \ 7028c2ecf20Sopenharmony_ci [gpio - (base)] = { \ 7038c2ecf20Sopenharmony_ci .name = __stringify(gpio), \ 7048c2ecf20Sopenharmony_ci .enum_id = data_or_mark, \ 7058c2ecf20Sopenharmony_ci } 7068c2ecf20Sopenharmony_ci#define GPIO_FN(str) \ 7078c2ecf20Sopenharmony_ci PINMUX_GPIO_FN(GPIO_FN_##str, PINMUX_FN_BASE, str##_MARK) 7088c2ecf20Sopenharmony_ci 7098c2ecf20Sopenharmony_ci/* 7108c2ecf20Sopenharmony_ci * Pins not associated with a GPIO port 7118c2ecf20Sopenharmony_ci */ 7128c2ecf20Sopenharmony_ci 7138c2ecf20Sopenharmony_ci#define PIN_NOGP_CFG(pin, name, fn, cfg) fn(pin, name, cfg) 7148c2ecf20Sopenharmony_ci#define PIN_NOGP(pin, name, fn) fn(pin, name, 0) 7158c2ecf20Sopenharmony_ci 7168c2ecf20Sopenharmony_ci/* NOGP_ALL - Expand to a list of PIN_id */ 7178c2ecf20Sopenharmony_ci#define _NOGP_ALL(pin, name, cfg) PIN_##pin 7188c2ecf20Sopenharmony_ci#define NOGP_ALL() CPU_ALL_NOGP(_NOGP_ALL) 7198c2ecf20Sopenharmony_ci 7208c2ecf20Sopenharmony_ci/* PINMUX_NOGP_ALL - Expand to a list of sh_pfc_pin entries */ 7218c2ecf20Sopenharmony_ci#define _NOGP_PINMUX(_pin, _name, cfg) \ 7228c2ecf20Sopenharmony_ci { \ 7238c2ecf20Sopenharmony_ci .pin = PIN_##_pin, \ 7248c2ecf20Sopenharmony_ci .name = "PIN_" _name, \ 7258c2ecf20Sopenharmony_ci .configs = SH_PFC_PIN_CFG_NO_GPIO | cfg, \ 7268c2ecf20Sopenharmony_ci } 7278c2ecf20Sopenharmony_ci#define PINMUX_NOGP_ALL() CPU_ALL_NOGP(_NOGP_PINMUX) 7288c2ecf20Sopenharmony_ci 7298c2ecf20Sopenharmony_ci/* 7308c2ecf20Sopenharmony_ci * PORTnCR helper macro for SH-Mobile/R-Mobile 7318c2ecf20Sopenharmony_ci */ 7328c2ecf20Sopenharmony_ci#define PORTCR(nr, reg) \ 7338c2ecf20Sopenharmony_ci { \ 7348c2ecf20Sopenharmony_ci PINMUX_CFG_REG_VAR("PORT" nr "CR", reg, 8, \ 7358c2ecf20Sopenharmony_ci GROUP(2, 2, 1, 3), \ 7368c2ecf20Sopenharmony_ci GROUP( \ 7378c2ecf20Sopenharmony_ci /* PULMD[1:0], handled by .set_bias() */ \ 7388c2ecf20Sopenharmony_ci 0, 0, 0, 0, \ 7398c2ecf20Sopenharmony_ci /* IE and OE */ \ 7408c2ecf20Sopenharmony_ci 0, PORT##nr##_OUT, PORT##nr##_IN, 0, \ 7418c2ecf20Sopenharmony_ci /* SEC, not supported */ \ 7428c2ecf20Sopenharmony_ci 0, 0, \ 7438c2ecf20Sopenharmony_ci /* PTMD[2:0] */ \ 7448c2ecf20Sopenharmony_ci PORT##nr##_FN0, PORT##nr##_FN1, \ 7458c2ecf20Sopenharmony_ci PORT##nr##_FN2, PORT##nr##_FN3, \ 7468c2ecf20Sopenharmony_ci PORT##nr##_FN4, PORT##nr##_FN5, \ 7478c2ecf20Sopenharmony_ci PORT##nr##_FN6, PORT##nr##_FN7 \ 7488c2ecf20Sopenharmony_ci )) \ 7498c2ecf20Sopenharmony_ci } 7508c2ecf20Sopenharmony_ci 7518c2ecf20Sopenharmony_ci/* 7528c2ecf20Sopenharmony_ci * GPIO number helper macro for R-Car 7538c2ecf20Sopenharmony_ci */ 7548c2ecf20Sopenharmony_ci#define RCAR_GP_PIN(bank, pin) (((bank) * 32) + (pin)) 7558c2ecf20Sopenharmony_ci 7568c2ecf20Sopenharmony_ci#endif /* __SH_PFC_H */ 757