18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Marvell MVEBU pinctrl driver 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Authors: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com> 68c2ecf20Sopenharmony_ci * Thomas Petazzoni <thomas.petazzoni@free-electrons.com> 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#ifndef __PINCTRL_MVEBU_H__ 108c2ecf20Sopenharmony_ci#define __PINCTRL_MVEBU_H__ 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci/** 138c2ecf20Sopenharmony_ci * struct mvebu_mpp_ctrl_data - private data for the mpp ctrl operations 148c2ecf20Sopenharmony_ci * @base: base address of pinctrl hardware 158c2ecf20Sopenharmony_ci * @regmap.map: regmap structure 168c2ecf20Sopenharmony_ci * @regmap.offset: regmap offset 178c2ecf20Sopenharmony_ci */ 188c2ecf20Sopenharmony_cistruct mvebu_mpp_ctrl_data { 198c2ecf20Sopenharmony_ci union { 208c2ecf20Sopenharmony_ci void __iomem *base; 218c2ecf20Sopenharmony_ci struct { 228c2ecf20Sopenharmony_ci struct regmap *map; 238c2ecf20Sopenharmony_ci u32 offset; 248c2ecf20Sopenharmony_ci } regmap; 258c2ecf20Sopenharmony_ci }; 268c2ecf20Sopenharmony_ci}; 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci/** 298c2ecf20Sopenharmony_ci * struct mvebu_mpp_ctrl - describe a mpp control 308c2ecf20Sopenharmony_ci * @name: name of the control group 318c2ecf20Sopenharmony_ci * @pid: first pin id handled by this control 328c2ecf20Sopenharmony_ci * @npins: number of pins controlled by this control 338c2ecf20Sopenharmony_ci * @mpp_get: (optional) special function to get mpp setting 348c2ecf20Sopenharmony_ci * @mpp_set: (optional) special function to set mpp setting 358c2ecf20Sopenharmony_ci * @mpp_gpio_req: (optional) special function to request gpio 368c2ecf20Sopenharmony_ci * @mpp_gpio_dir: (optional) special function to set gpio direction 378c2ecf20Sopenharmony_ci * 388c2ecf20Sopenharmony_ci * A mpp_ctrl describes a muxable unit, e.g. pin, group of pins, or 398c2ecf20Sopenharmony_ci * internal function, inside the SoC. Each muxable unit can be switched 408c2ecf20Sopenharmony_ci * between two or more different settings, e.g. assign mpp pin 13 to 418c2ecf20Sopenharmony_ci * uart1 or sata. 428c2ecf20Sopenharmony_ci * 438c2ecf20Sopenharmony_ci * The mpp_get/_set functions are mandatory and are used to get/set a 448c2ecf20Sopenharmony_ci * specific mode. The optional mpp_gpio_req/_dir functions can be used 458c2ecf20Sopenharmony_ci * to allow pin settings with varying gpio pins. 468c2ecf20Sopenharmony_ci */ 478c2ecf20Sopenharmony_cistruct mvebu_mpp_ctrl { 488c2ecf20Sopenharmony_ci const char *name; 498c2ecf20Sopenharmony_ci u8 pid; 508c2ecf20Sopenharmony_ci u8 npins; 518c2ecf20Sopenharmony_ci unsigned *pins; 528c2ecf20Sopenharmony_ci int (*mpp_get)(struct mvebu_mpp_ctrl_data *data, unsigned pid, 538c2ecf20Sopenharmony_ci unsigned long *config); 548c2ecf20Sopenharmony_ci int (*mpp_set)(struct mvebu_mpp_ctrl_data *data, unsigned pid, 558c2ecf20Sopenharmony_ci unsigned long config); 568c2ecf20Sopenharmony_ci int (*mpp_gpio_req)(struct mvebu_mpp_ctrl_data *data, unsigned pid); 578c2ecf20Sopenharmony_ci int (*mpp_gpio_dir)(struct mvebu_mpp_ctrl_data *data, unsigned pid, 588c2ecf20Sopenharmony_ci bool input); 598c2ecf20Sopenharmony_ci}; 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci/** 628c2ecf20Sopenharmony_ci * struct mvebu_mpp_ctrl_setting - describe a mpp ctrl setting 638c2ecf20Sopenharmony_ci * @val: ctrl setting value 648c2ecf20Sopenharmony_ci * @name: ctrl setting name, e.g. uart2, spi0 - unique per mpp_mode 658c2ecf20Sopenharmony_ci * @subname: (optional) additional ctrl setting name, e.g. rts, cts 668c2ecf20Sopenharmony_ci * @variant: (optional) variant identifier mask 678c2ecf20Sopenharmony_ci * @flags: (private) flags to store gpi/gpo/gpio capabilities 688c2ecf20Sopenharmony_ci * 698c2ecf20Sopenharmony_ci * A ctrl_setting describes a specific internal mux function that a mpp pin 708c2ecf20Sopenharmony_ci * can be switched to. The value (val) will be written in the corresponding 718c2ecf20Sopenharmony_ci * register for common mpp pin configuration registers on MVEBU. SoC specific 728c2ecf20Sopenharmony_ci * mpp_get/_set function may use val to distinguish between different settings. 738c2ecf20Sopenharmony_ci * 748c2ecf20Sopenharmony_ci * The name will be used to switch to this setting in DT description, e.g. 758c2ecf20Sopenharmony_ci * marvell,function = "uart2". subname is only for debugging purposes. 768c2ecf20Sopenharmony_ci * 778c2ecf20Sopenharmony_ci * If name is one of "gpi", "gpo", "gpio" gpio capabilities are 788c2ecf20Sopenharmony_ci * parsed during initialization and stored in flags. 798c2ecf20Sopenharmony_ci * 808c2ecf20Sopenharmony_ci * The variant can be used to combine different revisions of one SoC to a 818c2ecf20Sopenharmony_ci * common pinctrl driver. It is matched (AND) with variant of soc_info to 828c2ecf20Sopenharmony_ci * determine if a setting is available on the current SoC revision. 838c2ecf20Sopenharmony_ci */ 848c2ecf20Sopenharmony_cistruct mvebu_mpp_ctrl_setting { 858c2ecf20Sopenharmony_ci u8 val; 868c2ecf20Sopenharmony_ci const char *name; 878c2ecf20Sopenharmony_ci const char *subname; 888c2ecf20Sopenharmony_ci u8 variant; 898c2ecf20Sopenharmony_ci u8 flags; 908c2ecf20Sopenharmony_ci#define MVEBU_SETTING_GPO (1 << 0) 918c2ecf20Sopenharmony_ci#define MVEBU_SETTING_GPI (1 << 1) 928c2ecf20Sopenharmony_ci}; 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci/** 958c2ecf20Sopenharmony_ci * struct mvebu_mpp_mode - link ctrl and settings 968c2ecf20Sopenharmony_ci * @pid: first pin id handled by this mode 978c2ecf20Sopenharmony_ci * @settings: list of settings available for this mode 988c2ecf20Sopenharmony_ci * 998c2ecf20Sopenharmony_ci * A mode connects all available settings with the corresponding mpp_ctrl 1008c2ecf20Sopenharmony_ci * given by pid. 1018c2ecf20Sopenharmony_ci */ 1028c2ecf20Sopenharmony_cistruct mvebu_mpp_mode { 1038c2ecf20Sopenharmony_ci u8 pid; 1048c2ecf20Sopenharmony_ci struct mvebu_mpp_ctrl_setting *settings; 1058c2ecf20Sopenharmony_ci}; 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci/** 1088c2ecf20Sopenharmony_ci * struct mvebu_pinctrl_soc_info - SoC specific info passed to pinctrl-mvebu 1098c2ecf20Sopenharmony_ci * @variant: variant mask of soc_info 1108c2ecf20Sopenharmony_ci * @controls: list of available mvebu_mpp_ctrls 1118c2ecf20Sopenharmony_ci * @control_data: optional array, one entry for each control 1128c2ecf20Sopenharmony_ci * @ncontrols: number of available mvebu_mpp_ctrls 1138c2ecf20Sopenharmony_ci * @modes: list of available mvebu_mpp_modes 1148c2ecf20Sopenharmony_ci * @nmodes: number of available mvebu_mpp_modes 1158c2ecf20Sopenharmony_ci * @gpioranges: list of pinctrl_gpio_ranges 1168c2ecf20Sopenharmony_ci * @ngpioranges: number of available pinctrl_gpio_ranges 1178c2ecf20Sopenharmony_ci * 1188c2ecf20Sopenharmony_ci * This struct describes all pinctrl related information for a specific SoC. 1198c2ecf20Sopenharmony_ci * If variant is unequal 0 it will be matched (AND) with variant of each 1208c2ecf20Sopenharmony_ci * setting and allows to distinguish between different revisions of one SoC. 1218c2ecf20Sopenharmony_ci */ 1228c2ecf20Sopenharmony_cistruct mvebu_pinctrl_soc_info { 1238c2ecf20Sopenharmony_ci u8 variant; 1248c2ecf20Sopenharmony_ci const struct mvebu_mpp_ctrl *controls; 1258c2ecf20Sopenharmony_ci struct mvebu_mpp_ctrl_data *control_data; 1268c2ecf20Sopenharmony_ci int ncontrols; 1278c2ecf20Sopenharmony_ci struct mvebu_mpp_mode *modes; 1288c2ecf20Sopenharmony_ci int nmodes; 1298c2ecf20Sopenharmony_ci struct pinctrl_gpio_range *gpioranges; 1308c2ecf20Sopenharmony_ci int ngpioranges; 1318c2ecf20Sopenharmony_ci}; 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci#define MPP_FUNC_CTRL(_idl, _idh, _name, _func) \ 1348c2ecf20Sopenharmony_ci { \ 1358c2ecf20Sopenharmony_ci .name = _name, \ 1368c2ecf20Sopenharmony_ci .pid = _idl, \ 1378c2ecf20Sopenharmony_ci .npins = _idh - _idl + 1, \ 1388c2ecf20Sopenharmony_ci .pins = (unsigned[_idh - _idl + 1]) { }, \ 1398c2ecf20Sopenharmony_ci .mpp_get = _func ## _get, \ 1408c2ecf20Sopenharmony_ci .mpp_set = _func ## _set, \ 1418c2ecf20Sopenharmony_ci .mpp_gpio_req = NULL, \ 1428c2ecf20Sopenharmony_ci .mpp_gpio_dir = NULL, \ 1438c2ecf20Sopenharmony_ci } 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci#define MPP_FUNC_GPIO_CTRL(_idl, _idh, _name, _func) \ 1468c2ecf20Sopenharmony_ci { \ 1478c2ecf20Sopenharmony_ci .name = _name, \ 1488c2ecf20Sopenharmony_ci .pid = _idl, \ 1498c2ecf20Sopenharmony_ci .npins = _idh - _idl + 1, \ 1508c2ecf20Sopenharmony_ci .pins = (unsigned[_idh - _idl + 1]) { }, \ 1518c2ecf20Sopenharmony_ci .mpp_get = _func ## _get, \ 1528c2ecf20Sopenharmony_ci .mpp_set = _func ## _set, \ 1538c2ecf20Sopenharmony_ci .mpp_gpio_req = _func ## _gpio_req, \ 1548c2ecf20Sopenharmony_ci .mpp_gpio_dir = _func ## _gpio_dir, \ 1558c2ecf20Sopenharmony_ci } 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci#define _MPP_VAR_FUNCTION(_val, _name, _subname, _mask) \ 1588c2ecf20Sopenharmony_ci { \ 1598c2ecf20Sopenharmony_ci .val = _val, \ 1608c2ecf20Sopenharmony_ci .name = _name, \ 1618c2ecf20Sopenharmony_ci .subname = _subname, \ 1628c2ecf20Sopenharmony_ci .variant = _mask, \ 1638c2ecf20Sopenharmony_ci .flags = 0, \ 1648c2ecf20Sopenharmony_ci } 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ci#if defined(CONFIG_DEBUG_FS) 1678c2ecf20Sopenharmony_ci#define MPP_VAR_FUNCTION(_val, _name, _subname, _mask) \ 1688c2ecf20Sopenharmony_ci _MPP_VAR_FUNCTION(_val, _name, _subname, _mask) 1698c2ecf20Sopenharmony_ci#else 1708c2ecf20Sopenharmony_ci#define MPP_VAR_FUNCTION(_val, _name, _subname, _mask) \ 1718c2ecf20Sopenharmony_ci _MPP_VAR_FUNCTION(_val, _name, NULL, _mask) 1728c2ecf20Sopenharmony_ci#endif 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci#define MPP_FUNCTION(_val, _name, _subname) \ 1758c2ecf20Sopenharmony_ci MPP_VAR_FUNCTION(_val, _name, _subname, (u8)-1) 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci#define MPP_MODE(_id, ...) \ 1788c2ecf20Sopenharmony_ci { \ 1798c2ecf20Sopenharmony_ci .pid = _id, \ 1808c2ecf20Sopenharmony_ci .settings = (struct mvebu_mpp_ctrl_setting[]){ \ 1818c2ecf20Sopenharmony_ci __VA_ARGS__, { } }, \ 1828c2ecf20Sopenharmony_ci } 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci#define MPP_GPIO_RANGE(_id, _pinbase, _gpiobase, _npins) \ 1858c2ecf20Sopenharmony_ci { \ 1868c2ecf20Sopenharmony_ci .name = "mvebu-gpio", \ 1878c2ecf20Sopenharmony_ci .id = _id, \ 1888c2ecf20Sopenharmony_ci .pin_base = _pinbase, \ 1898c2ecf20Sopenharmony_ci .base = _gpiobase, \ 1908c2ecf20Sopenharmony_ci .npins = _npins, \ 1918c2ecf20Sopenharmony_ci } 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_ci#define MVEBU_MPPS_PER_REG 8 1948c2ecf20Sopenharmony_ci#define MVEBU_MPP_BITS 4 1958c2ecf20Sopenharmony_ci#define MVEBU_MPP_MASK 0xf 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ciint mvebu_mmio_mpp_ctrl_get(struct mvebu_mpp_ctrl_data *data, unsigned pid, 1988c2ecf20Sopenharmony_ci unsigned long *config); 1998c2ecf20Sopenharmony_ciint mvebu_mmio_mpp_ctrl_set(struct mvebu_mpp_ctrl_data *data, unsigned pid, 2008c2ecf20Sopenharmony_ci unsigned long config); 2018c2ecf20Sopenharmony_ciint mvebu_regmap_mpp_ctrl_get(struct mvebu_mpp_ctrl_data *data, unsigned pid, 2028c2ecf20Sopenharmony_ci unsigned long *config); 2038c2ecf20Sopenharmony_ciint mvebu_regmap_mpp_ctrl_set(struct mvebu_mpp_ctrl_data *data, unsigned pid, 2048c2ecf20Sopenharmony_ci unsigned long config); 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ciint mvebu_pinctrl_probe(struct platform_device *pdev); 2078c2ecf20Sopenharmony_ciint mvebu_pinctrl_simple_mmio_probe(struct platform_device *pdev); 2088c2ecf20Sopenharmony_ciint mvebu_pinctrl_simple_regmap_probe(struct platform_device *pdev, 2098c2ecf20Sopenharmony_ci struct device *syscon_dev, u32 offset); 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci#endif 212