1*2025cf9eSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 2170c6152STony Prisk /* 3170c6152STony Prisk * Pinctrl driver for the Wondermedia SoC's 4170c6152STony Prisk * 5170c6152STony Prisk * Copyright (c) 2013 Tony Prisk <linux@prisktech.co.nz> 6170c6152STony Prisk */ 7170c6152STony Prisk 81c5fb66aSLinus Walleij #include <linux/gpio/driver.h> 9170c6152STony Prisk 10170c6152STony Prisk /* VT8500 has no enable register in the extgpio bank. */ 11170c6152STony Prisk #define NO_REG 0xFFFF 12170c6152STony Prisk 13170c6152STony Prisk #define WMT_PINCTRL_BANK(__en, __dir, __dout, __din, __pen, __pcfg) \ 14170c6152STony Prisk { \ 15170c6152STony Prisk .reg_en = __en, \ 16170c6152STony Prisk .reg_dir = __dir, \ 17170c6152STony Prisk .reg_data_out = __dout, \ 18170c6152STony Prisk .reg_data_in = __din, \ 19170c6152STony Prisk .reg_pull_en = __pen, \ 20170c6152STony Prisk .reg_pull_cfg = __pcfg, \ 21170c6152STony Prisk } 22170c6152STony Prisk 23170c6152STony Prisk /* Encode/decode the bank/bit pairs into a pin value */ 24170c6152STony Prisk #define WMT_PIN(__bank, __offset) ((__bank << 5) | __offset) 25170c6152STony Prisk #define WMT_BANK_FROM_PIN(__pin) (__pin >> 5) 26170c6152STony Prisk #define WMT_BIT_FROM_PIN(__pin) (__pin & 0x1f) 27170c6152STony Prisk 28170c6152STony Prisk #define WMT_GROUP(__name, __data) \ 29170c6152STony Prisk { \ 30170c6152STony Prisk .name = __name, \ 31170c6152STony Prisk .pins = __data, \ 32170c6152STony Prisk .npins = ARRAY_SIZE(__data), \ 33170c6152STony Prisk } 34170c6152STony Prisk 35170c6152STony Prisk struct wmt_pinctrl_bank_registers { 36170c6152STony Prisk u32 reg_en; 37170c6152STony Prisk u32 reg_dir; 38170c6152STony Prisk u32 reg_data_out; 39170c6152STony Prisk u32 reg_data_in; 40170c6152STony Prisk 41170c6152STony Prisk u32 reg_pull_en; 42170c6152STony Prisk u32 reg_pull_cfg; 43170c6152STony Prisk }; 44170c6152STony Prisk 45170c6152STony Prisk struct wmt_pinctrl_group { 46170c6152STony Prisk const char *name; 47170c6152STony Prisk const unsigned int *pins; 48170c6152STony Prisk const unsigned npins; 49170c6152STony Prisk }; 50170c6152STony Prisk 51170c6152STony Prisk struct wmt_pinctrl_data { 52170c6152STony Prisk struct device *dev; 53170c6152STony Prisk struct pinctrl_dev *pctl_dev; 54170c6152STony Prisk 55170c6152STony Prisk /* must be initialized before calling wmt_pinctrl_probe */ 56170c6152STony Prisk void __iomem *base; 57170c6152STony Prisk const struct wmt_pinctrl_bank_registers *banks; 58170c6152STony Prisk const struct pinctrl_pin_desc *pins; 59170c6152STony Prisk const char * const *groups; 60170c6152STony Prisk 61170c6152STony Prisk u32 nbanks; 62170c6152STony Prisk u32 npins; 63170c6152STony Prisk u32 ngroups; 64170c6152STony Prisk 65170c6152STony Prisk struct gpio_chip gpio_chip; 66170c6152STony Prisk struct pinctrl_gpio_range gpio_range; 67170c6152STony Prisk }; 68170c6152STony Prisk 69170c6152STony Prisk int wmt_pinctrl_probe(struct platform_device *pdev, 70170c6152STony Prisk struct wmt_pinctrl_data *data); 71