Kyle Swenson | 8d8f654 | 2021-03-15 11:02:55 -0600 | [diff] [blame^] | 1 | /* |
| 2 | * Pinctrl driver for the Wondermedia SoC's |
| 3 | * |
| 4 | * Copyright (c) 2013 Tony Prisk <linux@prisktech.co.nz> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms and conditions of the GNU General Public License, |
| 8 | * version 2, as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | * more details. |
| 14 | */ |
| 15 | |
| 16 | #include <linux/gpio.h> |
| 17 | |
| 18 | /* VT8500 has no enable register in the extgpio bank. */ |
| 19 | #define NO_REG 0xFFFF |
| 20 | |
| 21 | #define WMT_PINCTRL_BANK(__en, __dir, __dout, __din, __pen, __pcfg) \ |
| 22 | { \ |
| 23 | .reg_en = __en, \ |
| 24 | .reg_dir = __dir, \ |
| 25 | .reg_data_out = __dout, \ |
| 26 | .reg_data_in = __din, \ |
| 27 | .reg_pull_en = __pen, \ |
| 28 | .reg_pull_cfg = __pcfg, \ |
| 29 | } |
| 30 | |
| 31 | /* Encode/decode the bank/bit pairs into a pin value */ |
| 32 | #define WMT_PIN(__bank, __offset) ((__bank << 5) | __offset) |
| 33 | #define WMT_BANK_FROM_PIN(__pin) (__pin >> 5) |
| 34 | #define WMT_BIT_FROM_PIN(__pin) (__pin & 0x1f) |
| 35 | |
| 36 | #define WMT_GROUP(__name, __data) \ |
| 37 | { \ |
| 38 | .name = __name, \ |
| 39 | .pins = __data, \ |
| 40 | .npins = ARRAY_SIZE(__data), \ |
| 41 | } |
| 42 | |
| 43 | struct wmt_pinctrl_bank_registers { |
| 44 | u32 reg_en; |
| 45 | u32 reg_dir; |
| 46 | u32 reg_data_out; |
| 47 | u32 reg_data_in; |
| 48 | |
| 49 | u32 reg_pull_en; |
| 50 | u32 reg_pull_cfg; |
| 51 | }; |
| 52 | |
| 53 | struct wmt_pinctrl_group { |
| 54 | const char *name; |
| 55 | const unsigned int *pins; |
| 56 | const unsigned npins; |
| 57 | }; |
| 58 | |
| 59 | struct wmt_pinctrl_data { |
| 60 | struct device *dev; |
| 61 | struct pinctrl_dev *pctl_dev; |
| 62 | |
| 63 | /* must be initialized before calling wmt_pinctrl_probe */ |
| 64 | void __iomem *base; |
| 65 | const struct wmt_pinctrl_bank_registers *banks; |
| 66 | const struct pinctrl_pin_desc *pins; |
| 67 | const char * const *groups; |
| 68 | |
| 69 | u32 nbanks; |
| 70 | u32 npins; |
| 71 | u32 ngroups; |
| 72 | |
| 73 | struct gpio_chip gpio_chip; |
| 74 | struct pinctrl_gpio_range gpio_range; |
| 75 | }; |
| 76 | |
| 77 | int wmt_pinctrl_probe(struct platform_device *pdev, |
| 78 | struct wmt_pinctrl_data *data); |
| 79 | int wmt_pinctrl_remove(struct platform_device *pdev); |