16e908892SMasahiro Yamada /* 28ef364b3SMasahiro Yamada * Copyright (C) 2015-2017 Socionext Inc. 38ef364b3SMasahiro Yamada * Author: Masahiro Yamada <yamada.masahiro@socionext.com> 46e908892SMasahiro Yamada * 56e908892SMasahiro Yamada * This program is free software; you can redistribute it and/or modify 66e908892SMasahiro Yamada * it under the terms of the GNU General Public License as published by 76e908892SMasahiro Yamada * the Free Software Foundation; either version 2 of the License, or 86e908892SMasahiro Yamada * (at your option) any later version. 96e908892SMasahiro Yamada * 106e908892SMasahiro Yamada * This program is distributed in the hope that it will be useful, 116e908892SMasahiro Yamada * but WITHOUT ANY WARRANTY; without even the implied warranty of 126e908892SMasahiro Yamada * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 136e908892SMasahiro Yamada * GNU General Public License for more details. 146e908892SMasahiro Yamada */ 156e908892SMasahiro Yamada 166e908892SMasahiro Yamada #ifndef __PINCTRL_UNIPHIER_H__ 176e908892SMasahiro Yamada #define __PINCTRL_UNIPHIER_H__ 186e908892SMasahiro Yamada 19e24cf513SMasahiro Yamada #include <linux/bits.h> 206d363bd1SMasahiro Yamada #include <linux/build_bug.h> 216e908892SMasahiro Yamada #include <linux/kernel.h> 226e908892SMasahiro Yamada #include <linux/types.h> 236e908892SMasahiro Yamada 24fc78a566SMasahiro Yamada struct platform_device; 25fc78a566SMasahiro Yamada 266e908892SMasahiro Yamada /* input enable control register bit */ 276e908892SMasahiro Yamada #define UNIPHIER_PIN_IECTRL_SHIFT 0 284e767983SMasahiro Yamada #define UNIPHIER_PIN_IECTRL_BITS 3 296e908892SMasahiro Yamada #define UNIPHIER_PIN_IECTRL_MASK ((1UL << (UNIPHIER_PIN_IECTRL_BITS)) \ 306e908892SMasahiro Yamada - 1) 316e908892SMasahiro Yamada 326e908892SMasahiro Yamada /* drive strength control register number */ 336e908892SMasahiro Yamada #define UNIPHIER_PIN_DRVCTRL_SHIFT ((UNIPHIER_PIN_IECTRL_SHIFT) + \ 346e908892SMasahiro Yamada (UNIPHIER_PIN_IECTRL_BITS)) 356e908892SMasahiro Yamada #define UNIPHIER_PIN_DRVCTRL_BITS 9 366e908892SMasahiro Yamada #define UNIPHIER_PIN_DRVCTRL_MASK ((1UL << (UNIPHIER_PIN_DRVCTRL_BITS)) \ 376e908892SMasahiro Yamada - 1) 386e908892SMasahiro Yamada 399eaa98a6SMasahiro Yamada /* drive control type */ 409eaa98a6SMasahiro Yamada #define UNIPHIER_PIN_DRV_TYPE_SHIFT ((UNIPHIER_PIN_DRVCTRL_SHIFT) + \ 416e908892SMasahiro Yamada (UNIPHIER_PIN_DRVCTRL_BITS)) 429eaa98a6SMasahiro Yamada #define UNIPHIER_PIN_DRV_TYPE_BITS 3 439eaa98a6SMasahiro Yamada #define UNIPHIER_PIN_DRV_TYPE_MASK ((1UL << (UNIPHIER_PIN_DRV_TYPE_BITS)) \ 446e908892SMasahiro Yamada - 1) 456e908892SMasahiro Yamada 466e908892SMasahiro Yamada /* pull-up / pull-down register number */ 479eaa98a6SMasahiro Yamada #define UNIPHIER_PIN_PUPDCTRL_SHIFT ((UNIPHIER_PIN_DRV_TYPE_SHIFT) + \ 489eaa98a6SMasahiro Yamada (UNIPHIER_PIN_DRV_TYPE_BITS)) 496e908892SMasahiro Yamada #define UNIPHIER_PIN_PUPDCTRL_BITS 9 506e908892SMasahiro Yamada #define UNIPHIER_PIN_PUPDCTRL_MASK ((1UL << (UNIPHIER_PIN_PUPDCTRL_BITS))\ 516e908892SMasahiro Yamada - 1) 526e908892SMasahiro Yamada 536e908892SMasahiro Yamada /* direction of pull register */ 546e908892SMasahiro Yamada #define UNIPHIER_PIN_PULL_DIR_SHIFT ((UNIPHIER_PIN_PUPDCTRL_SHIFT) + \ 556e908892SMasahiro Yamada (UNIPHIER_PIN_PUPDCTRL_BITS)) 566e908892SMasahiro Yamada #define UNIPHIER_PIN_PULL_DIR_BITS 3 576e908892SMasahiro Yamada #define UNIPHIER_PIN_PULL_DIR_MASK ((1UL << (UNIPHIER_PIN_PULL_DIR_BITS))\ 586e908892SMasahiro Yamada - 1) 596e908892SMasahiro Yamada 606e908892SMasahiro Yamada #if UNIPHIER_PIN_PULL_DIR_SHIFT + UNIPHIER_PIN_PULL_DIR_BITS > BITS_PER_LONG 616e908892SMasahiro Yamada #error "unable to pack pin attributes." 626e908892SMasahiro Yamada #endif 636e908892SMasahiro Yamada 646e908892SMasahiro Yamada #define UNIPHIER_PIN_IECTRL_NONE (UNIPHIER_PIN_IECTRL_MASK) 654e767983SMasahiro Yamada #define UNIPHIER_PIN_IECTRL_EXIST 0 666e908892SMasahiro Yamada 679eaa98a6SMasahiro Yamada /* drive control type */ 689eaa98a6SMasahiro Yamada enum uniphier_pin_drv_type { 699eaa98a6SMasahiro Yamada UNIPHIER_PIN_DRV_1BIT, /* 2 level control: 4/8 mA */ 709eaa98a6SMasahiro Yamada UNIPHIER_PIN_DRV_2BIT, /* 4 level control: 8/12/16/20 mA */ 7172e5706aSMasahiro Yamada UNIPHIER_PIN_DRV_3BIT, /* 8 level control: 4/5/7/9/11/12/14/16 mA */ 729eaa98a6SMasahiro Yamada UNIPHIER_PIN_DRV_FIXED4, /* fixed to 4mA */ 739eaa98a6SMasahiro Yamada UNIPHIER_PIN_DRV_FIXED5, /* fixed to 5mA */ 749eaa98a6SMasahiro Yamada UNIPHIER_PIN_DRV_FIXED8, /* fixed to 8mA */ 756e908892SMasahiro Yamada UNIPHIER_PIN_DRV_NONE, /* no support (input only pin) */ 766e908892SMasahiro Yamada }; 776e908892SMasahiro Yamada 786e908892SMasahiro Yamada /* direction of pull register (no pin supports bi-directional pull biasing) */ 796e908892SMasahiro Yamada enum uniphier_pin_pull_dir { 806e908892SMasahiro Yamada UNIPHIER_PIN_PULL_UP, /* pull-up or disabled */ 816e908892SMasahiro Yamada UNIPHIER_PIN_PULL_DOWN, /* pull-down or disabled */ 826e908892SMasahiro Yamada UNIPHIER_PIN_PULL_UP_FIXED, /* always pull-up */ 836e908892SMasahiro Yamada UNIPHIER_PIN_PULL_DOWN_FIXED, /* always pull-down */ 846e908892SMasahiro Yamada UNIPHIER_PIN_PULL_NONE, /* no pull register */ 856e908892SMasahiro Yamada }; 866e908892SMasahiro Yamada 876e908892SMasahiro Yamada #define UNIPHIER_PIN_IECTRL(x) \ 886e908892SMasahiro Yamada (((x) & (UNIPHIER_PIN_IECTRL_MASK)) << (UNIPHIER_PIN_IECTRL_SHIFT)) 896e908892SMasahiro Yamada #define UNIPHIER_PIN_DRVCTRL(x) \ 906e908892SMasahiro Yamada (((x) & (UNIPHIER_PIN_DRVCTRL_MASK)) << (UNIPHIER_PIN_DRVCTRL_SHIFT)) 919eaa98a6SMasahiro Yamada #define UNIPHIER_PIN_DRV_TYPE(x) \ 929eaa98a6SMasahiro Yamada (((x) & (UNIPHIER_PIN_DRV_TYPE_MASK)) << (UNIPHIER_PIN_DRV_TYPE_SHIFT)) 936e908892SMasahiro Yamada #define UNIPHIER_PIN_PUPDCTRL(x) \ 946e908892SMasahiro Yamada (((x) & (UNIPHIER_PIN_PUPDCTRL_MASK)) << (UNIPHIER_PIN_PUPDCTRL_SHIFT)) 956e908892SMasahiro Yamada #define UNIPHIER_PIN_PULL_DIR(x) \ 966e908892SMasahiro Yamada (((x) & (UNIPHIER_PIN_PULL_DIR_MASK)) << (UNIPHIER_PIN_PULL_DIR_SHIFT)) 976e908892SMasahiro Yamada 989eaa98a6SMasahiro Yamada #define UNIPHIER_PIN_ATTR_PACKED(iectrl, drvctrl, drv_type, pupdctrl, pull_dir)\ 996e908892SMasahiro Yamada (UNIPHIER_PIN_IECTRL(iectrl) | \ 1006e908892SMasahiro Yamada UNIPHIER_PIN_DRVCTRL(drvctrl) | \ 1019eaa98a6SMasahiro Yamada UNIPHIER_PIN_DRV_TYPE(drv_type) | \ 1026e908892SMasahiro Yamada UNIPHIER_PIN_PUPDCTRL(pupdctrl) | \ 1036e908892SMasahiro Yamada UNIPHIER_PIN_PULL_DIR(pull_dir)) 1046e908892SMasahiro Yamada 1056e908892SMasahiro Yamada static inline unsigned int uniphier_pin_get_iectrl(void *drv_data) 1066e908892SMasahiro Yamada { 1076e908892SMasahiro Yamada return ((unsigned long)drv_data >> UNIPHIER_PIN_IECTRL_SHIFT) & 1086e908892SMasahiro Yamada UNIPHIER_PIN_IECTRL_MASK; 1096e908892SMasahiro Yamada } 1106e908892SMasahiro Yamada 1116e908892SMasahiro Yamada static inline unsigned int uniphier_pin_get_drvctrl(void *drv_data) 1126e908892SMasahiro Yamada { 1136e908892SMasahiro Yamada return ((unsigned long)drv_data >> UNIPHIER_PIN_DRVCTRL_SHIFT) & 1146e908892SMasahiro Yamada UNIPHIER_PIN_DRVCTRL_MASK; 1156e908892SMasahiro Yamada } 1166e908892SMasahiro Yamada 1179eaa98a6SMasahiro Yamada static inline unsigned int uniphier_pin_get_drv_type(void *drv_data) 1186e908892SMasahiro Yamada { 1199eaa98a6SMasahiro Yamada return ((unsigned long)drv_data >> UNIPHIER_PIN_DRV_TYPE_SHIFT) & 1209eaa98a6SMasahiro Yamada UNIPHIER_PIN_DRV_TYPE_MASK; 1216e908892SMasahiro Yamada } 1226e908892SMasahiro Yamada 1236e908892SMasahiro Yamada static inline unsigned int uniphier_pin_get_pupdctrl(void *drv_data) 1246e908892SMasahiro Yamada { 1256e908892SMasahiro Yamada return ((unsigned long)drv_data >> UNIPHIER_PIN_PUPDCTRL_SHIFT) & 1266e908892SMasahiro Yamada UNIPHIER_PIN_PUPDCTRL_MASK; 1276e908892SMasahiro Yamada } 1286e908892SMasahiro Yamada 1296e908892SMasahiro Yamada static inline unsigned int uniphier_pin_get_pull_dir(void *drv_data) 1306e908892SMasahiro Yamada { 1316e908892SMasahiro Yamada return ((unsigned long)drv_data >> UNIPHIER_PIN_PULL_DIR_SHIFT) & 1326e908892SMasahiro Yamada UNIPHIER_PIN_PULL_DIR_MASK; 1336e908892SMasahiro Yamada } 1346e908892SMasahiro Yamada 1356e908892SMasahiro Yamada struct uniphier_pinctrl_group { 1366e908892SMasahiro Yamada const char *name; 1376e908892SMasahiro Yamada const unsigned *pins; 1386e908892SMasahiro Yamada unsigned num_pins; 13939ec9aceSMasahiro Yamada const int *muxvals; 1406e908892SMasahiro Yamada }; 1416e908892SMasahiro Yamada 1426e908892SMasahiro Yamada struct uniphier_pinmux_function { 1436e908892SMasahiro Yamada const char *name; 1446e908892SMasahiro Yamada const char * const *groups; 1456e908892SMasahiro Yamada unsigned num_groups; 1466e908892SMasahiro Yamada }; 1476e908892SMasahiro Yamada 1486e908892SMasahiro Yamada struct uniphier_pinctrl_socdata { 149fc78a566SMasahiro Yamada const struct pinctrl_pin_desc *pins; 150fc78a566SMasahiro Yamada unsigned int npins; 1516e908892SMasahiro Yamada const struct uniphier_pinctrl_group *groups; 1526e908892SMasahiro Yamada int groups_count; 1536e908892SMasahiro Yamada const struct uniphier_pinmux_function *functions; 1546e908892SMasahiro Yamada int functions_count; 1557f6ee0a5SMasahiro Yamada int (*get_gpio_muxval)(unsigned int pin, unsigned int gpio_offset); 156c2ebf475SMasahiro Yamada unsigned int caps; 157aa543888SMasahiro Yamada #define UNIPHIER_PINCTRL_CAPS_PERPIN_IECTRL BIT(1) 158c2ebf475SMasahiro Yamada #define UNIPHIER_PINCTRL_CAPS_DBGMUX_SEPARATE BIT(0) 1596e908892SMasahiro Yamada }; 1606e908892SMasahiro Yamada 1616e908892SMasahiro Yamada #define UNIPHIER_PINCTRL_PIN(a, b, c, d, e, f, g) \ 1626e908892SMasahiro Yamada { \ 1636e908892SMasahiro Yamada .number = a, \ 1646e908892SMasahiro Yamada .name = b, \ 1656e908892SMasahiro Yamada .drv_data = (void *)UNIPHIER_PIN_ATTR_PACKED(c, d, e, f, g), \ 1666e908892SMasahiro Yamada } 1676e908892SMasahiro Yamada 1687f6ee0a5SMasahiro Yamada #define __UNIPHIER_PINCTRL_GROUP(grp, mux) \ 1696e908892SMasahiro Yamada { \ 1706e908892SMasahiro Yamada .name = #grp, \ 1716e908892SMasahiro Yamada .pins = grp##_pins, \ 1726e908892SMasahiro Yamada .num_pins = ARRAY_SIZE(grp##_pins), \ 1737f6ee0a5SMasahiro Yamada .muxvals = mux, \ 1746e908892SMasahiro Yamada } 1756e908892SMasahiro Yamada 1766e908892SMasahiro Yamada #define UNIPHIER_PINCTRL_GROUP(grp) \ 1777f6ee0a5SMasahiro Yamada __UNIPHIER_PINCTRL_GROUP(grp, \ 1787f6ee0a5SMasahiro Yamada grp##_muxvals + \ 1797f6ee0a5SMasahiro Yamada BUILD_BUG_ON_ZERO(ARRAY_SIZE(grp##_pins) != \ 1807f6ee0a5SMasahiro Yamada ARRAY_SIZE(grp##_muxvals))) 1816e908892SMasahiro Yamada 1827f6ee0a5SMasahiro Yamada #define UNIPHIER_PINCTRL_GROUP_GPIO(grp) \ 1837f6ee0a5SMasahiro Yamada __UNIPHIER_PINCTRL_GROUP(grp, NULL) 1846e908892SMasahiro Yamada 1856e908892SMasahiro Yamada #define UNIPHIER_PINMUX_FUNCTION(func) \ 1866e908892SMasahiro Yamada { \ 1876e908892SMasahiro Yamada .name = #func, \ 1886e908892SMasahiro Yamada .groups = func##_groups, \ 1896e908892SMasahiro Yamada .num_groups = ARRAY_SIZE(func##_groups), \ 1906e908892SMasahiro Yamada } 1916e908892SMasahiro Yamada 1926e908892SMasahiro Yamada int uniphier_pinctrl_probe(struct platform_device *pdev, 1936e908892SMasahiro Yamada struct uniphier_pinctrl_socdata *socdata); 1946e908892SMasahiro Yamada 1959697509eSMasahiro Yamada extern const struct dev_pm_ops uniphier_pinctrl_pm_ops; 1969697509eSMasahiro Yamada 1976e908892SMasahiro Yamada #endif /* __PINCTRL_UNIPHIER_H__ */ 198