18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * IMX pinmux core definitions 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2012 Freescale Semiconductor, Inc. 68c2ecf20Sopenharmony_ci * Copyright (C) 2012 Linaro Ltd. 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * Author: Dong Aisheng <dong.aisheng@linaro.org> 98c2ecf20Sopenharmony_ci */ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#ifndef __DRIVERS_PINCTRL_IMX_H 128c2ecf20Sopenharmony_ci#define __DRIVERS_PINCTRL_IMX_H 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include <linux/pinctrl/pinconf-generic.h> 158c2ecf20Sopenharmony_ci#include <linux/pinctrl/pinmux.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_cistruct platform_device; 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ciextern struct pinmux_ops imx_pmx_ops; 208c2ecf20Sopenharmony_ciextern const struct dev_pm_ops imx_pinctrl_pm_ops; 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci/** 238c2ecf20Sopenharmony_ci * struct imx_pin_mmio - MMIO pin configurations 248c2ecf20Sopenharmony_ci * @mux_mode: the mux mode for this pin. 258c2ecf20Sopenharmony_ci * @input_reg: the select input register offset for this pin if any 268c2ecf20Sopenharmony_ci * 0 if no select input setting needed. 278c2ecf20Sopenharmony_ci * @input_val: the select input value for this pin. 288c2ecf20Sopenharmony_ci * @configs: the config for this pin. 298c2ecf20Sopenharmony_ci */ 308c2ecf20Sopenharmony_cistruct imx_pin_mmio { 318c2ecf20Sopenharmony_ci unsigned int mux_mode; 328c2ecf20Sopenharmony_ci u16 input_reg; 338c2ecf20Sopenharmony_ci unsigned int input_val; 348c2ecf20Sopenharmony_ci unsigned long config; 358c2ecf20Sopenharmony_ci}; 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci/** 388c2ecf20Sopenharmony_ci * struct imx_pin_scu - SCU pin configurations 398c2ecf20Sopenharmony_ci * @mux: the mux mode for this pin. 408c2ecf20Sopenharmony_ci * @configs: the config for this pin. 418c2ecf20Sopenharmony_ci */ 428c2ecf20Sopenharmony_cistruct imx_pin_scu { 438c2ecf20Sopenharmony_ci unsigned int mux_mode; 448c2ecf20Sopenharmony_ci unsigned long config; 458c2ecf20Sopenharmony_ci}; 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci/** 488c2ecf20Sopenharmony_ci * struct imx_pin - describes a single i.MX pin 498c2ecf20Sopenharmony_ci * @pin: the pin_id of this pin 508c2ecf20Sopenharmony_ci * @conf: config type of this pin, either mmio or scu 518c2ecf20Sopenharmony_ci */ 528c2ecf20Sopenharmony_cistruct imx_pin { 538c2ecf20Sopenharmony_ci unsigned int pin; 548c2ecf20Sopenharmony_ci union { 558c2ecf20Sopenharmony_ci struct imx_pin_mmio mmio; 568c2ecf20Sopenharmony_ci struct imx_pin_scu scu; 578c2ecf20Sopenharmony_ci } conf; 588c2ecf20Sopenharmony_ci}; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci/** 618c2ecf20Sopenharmony_ci * struct imx_pin_reg - describe a pin reg map 628c2ecf20Sopenharmony_ci * @mux_reg: mux register offset 638c2ecf20Sopenharmony_ci * @conf_reg: config register offset 648c2ecf20Sopenharmony_ci */ 658c2ecf20Sopenharmony_cistruct imx_pin_reg { 668c2ecf20Sopenharmony_ci s16 mux_reg; 678c2ecf20Sopenharmony_ci s16 conf_reg; 688c2ecf20Sopenharmony_ci}; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci/* decode a generic config into raw register value */ 718c2ecf20Sopenharmony_cistruct imx_cfg_params_decode { 728c2ecf20Sopenharmony_ci enum pin_config_param param; 738c2ecf20Sopenharmony_ci u32 mask; 748c2ecf20Sopenharmony_ci u8 shift; 758c2ecf20Sopenharmony_ci bool invert; 768c2ecf20Sopenharmony_ci}; 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci/** 798c2ecf20Sopenharmony_ci * @dev: a pointer back to containing device 808c2ecf20Sopenharmony_ci * @base: the offset to the controller in virtual memory 818c2ecf20Sopenharmony_ci */ 828c2ecf20Sopenharmony_cistruct imx_pinctrl { 838c2ecf20Sopenharmony_ci struct device *dev; 848c2ecf20Sopenharmony_ci struct pinctrl_dev *pctl; 858c2ecf20Sopenharmony_ci void __iomem *base; 868c2ecf20Sopenharmony_ci void __iomem *input_sel_base; 878c2ecf20Sopenharmony_ci const struct imx_pinctrl_soc_info *info; 888c2ecf20Sopenharmony_ci struct imx_pin_reg *pin_regs; 898c2ecf20Sopenharmony_ci unsigned int group_index; 908c2ecf20Sopenharmony_ci struct mutex mutex; 918c2ecf20Sopenharmony_ci}; 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_cistruct imx_pinctrl_soc_info { 948c2ecf20Sopenharmony_ci const struct pinctrl_pin_desc *pins; 958c2ecf20Sopenharmony_ci unsigned int npins; 968c2ecf20Sopenharmony_ci unsigned int flags; 978c2ecf20Sopenharmony_ci const char *gpr_compatible; 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci /* MUX_MODE shift and mask in case SHARE_MUX_CONF_REG */ 1008c2ecf20Sopenharmony_ci unsigned int mux_mask; 1018c2ecf20Sopenharmony_ci u8 mux_shift; 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci /* generic pinconf */ 1048c2ecf20Sopenharmony_ci bool generic_pinconf; 1058c2ecf20Sopenharmony_ci const struct pinconf_generic_params *custom_params; 1068c2ecf20Sopenharmony_ci unsigned int num_custom_params; 1078c2ecf20Sopenharmony_ci const struct imx_cfg_params_decode *decodes; 1088c2ecf20Sopenharmony_ci unsigned int num_decodes; 1098c2ecf20Sopenharmony_ci void (*fixup)(unsigned long *configs, unsigned int num_configs, 1108c2ecf20Sopenharmony_ci u32 *raw_config); 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci int (*gpio_set_direction)(struct pinctrl_dev *pctldev, 1138c2ecf20Sopenharmony_ci struct pinctrl_gpio_range *range, 1148c2ecf20Sopenharmony_ci unsigned offset, 1158c2ecf20Sopenharmony_ci bool input); 1168c2ecf20Sopenharmony_ci int (*imx_pinconf_get)(struct pinctrl_dev *pctldev, unsigned int pin_id, 1178c2ecf20Sopenharmony_ci unsigned long *config); 1188c2ecf20Sopenharmony_ci int (*imx_pinconf_set)(struct pinctrl_dev *pctldev, unsigned int pin_id, 1198c2ecf20Sopenharmony_ci unsigned long *configs, unsigned int num_configs); 1208c2ecf20Sopenharmony_ci void (*imx_pinctrl_parse_pin)(struct imx_pinctrl *ipctl, 1218c2ecf20Sopenharmony_ci unsigned int *pin_id, struct imx_pin *pin, 1228c2ecf20Sopenharmony_ci const __be32 **list_p); 1238c2ecf20Sopenharmony_ci}; 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci#define IMX_CFG_PARAMS_DECODE(p, m, o) \ 1268c2ecf20Sopenharmony_ci { .param = p, .mask = m, .shift = o, .invert = false, } 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci#define IMX_CFG_PARAMS_DECODE_INVERT(p, m, o) \ 1298c2ecf20Sopenharmony_ci { .param = p, .mask = m, .shift = o, .invert = true, } 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci#define SHARE_MUX_CONF_REG BIT(0) 1328c2ecf20Sopenharmony_ci#define ZERO_OFFSET_VALID BIT(1) 1338c2ecf20Sopenharmony_ci#define IMX_USE_SCU BIT(2) 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci#define NO_MUX 0x0 1368c2ecf20Sopenharmony_ci#define NO_PAD 0x0 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci#define IMX_PINCTRL_PIN(pin) PINCTRL_PIN(pin, #pin) 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci#define PAD_CTL_MASK(len) ((1 << len) - 1) 1418c2ecf20Sopenharmony_ci#define IMX_MUX_MASK 0x7 1428c2ecf20Sopenharmony_ci#define IOMUXC_CONFIG_SION (0x1 << 4) 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ciint imx_pinctrl_probe(struct platform_device *pdev, 1458c2ecf20Sopenharmony_ci const struct imx_pinctrl_soc_info *info); 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci#define BM_PAD_CTL_GP_ENABLE BIT(30) 1488c2ecf20Sopenharmony_ci#define BM_PAD_CTL_IFMUX_ENABLE BIT(31) 1498c2ecf20Sopenharmony_ci#define BP_PAD_CTL_IFMUX 27 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ciint imx_pinctrl_sc_ipc_init(struct platform_device *pdev); 1528c2ecf20Sopenharmony_ciint imx_pinconf_get_scu(struct pinctrl_dev *pctldev, unsigned pin_id, 1538c2ecf20Sopenharmony_ci unsigned long *config); 1548c2ecf20Sopenharmony_ciint imx_pinconf_set_scu(struct pinctrl_dev *pctldev, unsigned pin_id, 1558c2ecf20Sopenharmony_ci unsigned long *configs, unsigned num_configs); 1568c2ecf20Sopenharmony_civoid imx_pinctrl_parse_pin_scu(struct imx_pinctrl *ipctl, 1578c2ecf20Sopenharmony_ci unsigned int *pin_id, struct imx_pin *pin, 1588c2ecf20Sopenharmony_ci const __be32 **list_p); 1598c2ecf20Sopenharmony_ci#endif /* __DRIVERS_PINCTRL_IMX_H */ 160