134812fe1SMasahiro Yamada /* SPDX-License-Identifier: GPL-2.0+ */ 26e908892SMasahiro Yamada /* 38ef364b3SMasahiro Yamada * Copyright (C) 2015-2017 Socionext Inc. 48ef364b3SMasahiro Yamada * Author: Masahiro Yamada <yamada.masahiro@socionext.com> 56e908892SMasahiro Yamada */ 66e908892SMasahiro Yamada 76e908892SMasahiro Yamada #ifndef __PINCTRL_UNIPHIER_H__ 86e908892SMasahiro Yamada #define __PINCTRL_UNIPHIER_H__ 96e908892SMasahiro Yamada 10e24cf513SMasahiro Yamada #include <linux/bits.h> 116d363bd1SMasahiro Yamada #include <linux/build_bug.h> 126e908892SMasahiro Yamada #include <linux/kernel.h> 136e908892SMasahiro Yamada #include <linux/types.h> 146e908892SMasahiro Yamada 15fc78a566SMasahiro Yamada struct platform_device; 16fc78a566SMasahiro Yamada 176e908892SMasahiro Yamada /* input enable control register bit */ 186e908892SMasahiro Yamada #define UNIPHIER_PIN_IECTRL_SHIFT 0 194e767983SMasahiro Yamada #define UNIPHIER_PIN_IECTRL_BITS 3 206e908892SMasahiro Yamada #define UNIPHIER_PIN_IECTRL_MASK ((1UL << (UNIPHIER_PIN_IECTRL_BITS)) \ 216e908892SMasahiro Yamada - 1) 226e908892SMasahiro Yamada 236e908892SMasahiro Yamada /* drive strength control register number */ 246e908892SMasahiro Yamada #define UNIPHIER_PIN_DRVCTRL_SHIFT ((UNIPHIER_PIN_IECTRL_SHIFT) + \ 256e908892SMasahiro Yamada (UNIPHIER_PIN_IECTRL_BITS)) 266e908892SMasahiro Yamada #define UNIPHIER_PIN_DRVCTRL_BITS 9 276e908892SMasahiro Yamada #define UNIPHIER_PIN_DRVCTRL_MASK ((1UL << (UNIPHIER_PIN_DRVCTRL_BITS)) \ 286e908892SMasahiro Yamada - 1) 296e908892SMasahiro Yamada 309eaa98a6SMasahiro Yamada /* drive control type */ 319eaa98a6SMasahiro Yamada #define UNIPHIER_PIN_DRV_TYPE_SHIFT ((UNIPHIER_PIN_DRVCTRL_SHIFT) + \ 326e908892SMasahiro Yamada (UNIPHIER_PIN_DRVCTRL_BITS)) 339eaa98a6SMasahiro Yamada #define UNIPHIER_PIN_DRV_TYPE_BITS 3 349eaa98a6SMasahiro Yamada #define UNIPHIER_PIN_DRV_TYPE_MASK ((1UL << (UNIPHIER_PIN_DRV_TYPE_BITS)) \ 356e908892SMasahiro Yamada - 1) 366e908892SMasahiro Yamada 376e908892SMasahiro Yamada /* pull-up / pull-down register number */ 389eaa98a6SMasahiro Yamada #define UNIPHIER_PIN_PUPDCTRL_SHIFT ((UNIPHIER_PIN_DRV_TYPE_SHIFT) + \ 399eaa98a6SMasahiro Yamada (UNIPHIER_PIN_DRV_TYPE_BITS)) 406e908892SMasahiro Yamada #define UNIPHIER_PIN_PUPDCTRL_BITS 9 416e908892SMasahiro Yamada #define UNIPHIER_PIN_PUPDCTRL_MASK ((1UL << (UNIPHIER_PIN_PUPDCTRL_BITS))\ 426e908892SMasahiro Yamada - 1) 436e908892SMasahiro Yamada 446e908892SMasahiro Yamada /* direction of pull register */ 456e908892SMasahiro Yamada #define UNIPHIER_PIN_PULL_DIR_SHIFT ((UNIPHIER_PIN_PUPDCTRL_SHIFT) + \ 466e908892SMasahiro Yamada (UNIPHIER_PIN_PUPDCTRL_BITS)) 476e908892SMasahiro Yamada #define UNIPHIER_PIN_PULL_DIR_BITS 3 486e908892SMasahiro Yamada #define UNIPHIER_PIN_PULL_DIR_MASK ((1UL << (UNIPHIER_PIN_PULL_DIR_BITS))\ 496e908892SMasahiro Yamada - 1) 506e908892SMasahiro Yamada 516e908892SMasahiro Yamada #if UNIPHIER_PIN_PULL_DIR_SHIFT + UNIPHIER_PIN_PULL_DIR_BITS > BITS_PER_LONG 526e908892SMasahiro Yamada #error "unable to pack pin attributes." 536e908892SMasahiro Yamada #endif 546e908892SMasahiro Yamada 556e908892SMasahiro Yamada #define UNIPHIER_PIN_IECTRL_NONE (UNIPHIER_PIN_IECTRL_MASK) 564e767983SMasahiro Yamada #define UNIPHIER_PIN_IECTRL_EXIST 0 576e908892SMasahiro Yamada 589eaa98a6SMasahiro Yamada /* drive control type */ 599eaa98a6SMasahiro Yamada enum uniphier_pin_drv_type { 609eaa98a6SMasahiro Yamada UNIPHIER_PIN_DRV_1BIT, /* 2 level control: 4/8 mA */ 619eaa98a6SMasahiro Yamada UNIPHIER_PIN_DRV_2BIT, /* 4 level control: 8/12/16/20 mA */ 6272e5706aSMasahiro Yamada UNIPHIER_PIN_DRV_3BIT, /* 8 level control: 4/5/7/9/11/12/14/16 mA */ 639eaa98a6SMasahiro Yamada UNIPHIER_PIN_DRV_FIXED4, /* fixed to 4mA */ 649eaa98a6SMasahiro Yamada UNIPHIER_PIN_DRV_FIXED5, /* fixed to 5mA */ 659eaa98a6SMasahiro Yamada UNIPHIER_PIN_DRV_FIXED8, /* fixed to 8mA */ 666e908892SMasahiro Yamada UNIPHIER_PIN_DRV_NONE, /* no support (input only pin) */ 676e908892SMasahiro Yamada }; 686e908892SMasahiro Yamada 696e908892SMasahiro Yamada /* direction of pull register (no pin supports bi-directional pull biasing) */ 706e908892SMasahiro Yamada enum uniphier_pin_pull_dir { 716e908892SMasahiro Yamada UNIPHIER_PIN_PULL_UP, /* pull-up or disabled */ 726e908892SMasahiro Yamada UNIPHIER_PIN_PULL_DOWN, /* pull-down or disabled */ 736e908892SMasahiro Yamada UNIPHIER_PIN_PULL_UP_FIXED, /* always pull-up */ 746e908892SMasahiro Yamada UNIPHIER_PIN_PULL_DOWN_FIXED, /* always pull-down */ 756e908892SMasahiro Yamada UNIPHIER_PIN_PULL_NONE, /* no pull register */ 766e908892SMasahiro Yamada }; 776e908892SMasahiro Yamada 786e908892SMasahiro Yamada #define UNIPHIER_PIN_IECTRL(x) \ 796e908892SMasahiro Yamada (((x) & (UNIPHIER_PIN_IECTRL_MASK)) << (UNIPHIER_PIN_IECTRL_SHIFT)) 806e908892SMasahiro Yamada #define UNIPHIER_PIN_DRVCTRL(x) \ 816e908892SMasahiro Yamada (((x) & (UNIPHIER_PIN_DRVCTRL_MASK)) << (UNIPHIER_PIN_DRVCTRL_SHIFT)) 829eaa98a6SMasahiro Yamada #define UNIPHIER_PIN_DRV_TYPE(x) \ 839eaa98a6SMasahiro Yamada (((x) & (UNIPHIER_PIN_DRV_TYPE_MASK)) << (UNIPHIER_PIN_DRV_TYPE_SHIFT)) 846e908892SMasahiro Yamada #define UNIPHIER_PIN_PUPDCTRL(x) \ 856e908892SMasahiro Yamada (((x) & (UNIPHIER_PIN_PUPDCTRL_MASK)) << (UNIPHIER_PIN_PUPDCTRL_SHIFT)) 866e908892SMasahiro Yamada #define UNIPHIER_PIN_PULL_DIR(x) \ 876e908892SMasahiro Yamada (((x) & (UNIPHIER_PIN_PULL_DIR_MASK)) << (UNIPHIER_PIN_PULL_DIR_SHIFT)) 886e908892SMasahiro Yamada 899eaa98a6SMasahiro Yamada #define UNIPHIER_PIN_ATTR_PACKED(iectrl, drvctrl, drv_type, pupdctrl, pull_dir)\ 906e908892SMasahiro Yamada (UNIPHIER_PIN_IECTRL(iectrl) | \ 916e908892SMasahiro Yamada UNIPHIER_PIN_DRVCTRL(drvctrl) | \ 929eaa98a6SMasahiro Yamada UNIPHIER_PIN_DRV_TYPE(drv_type) | \ 936e908892SMasahiro Yamada UNIPHIER_PIN_PUPDCTRL(pupdctrl) | \ 946e908892SMasahiro Yamada UNIPHIER_PIN_PULL_DIR(pull_dir)) 956e908892SMasahiro Yamada 966e908892SMasahiro Yamada static inline unsigned int uniphier_pin_get_iectrl(void *drv_data) 976e908892SMasahiro Yamada { 986e908892SMasahiro Yamada return ((unsigned long)drv_data >> UNIPHIER_PIN_IECTRL_SHIFT) & 996e908892SMasahiro Yamada UNIPHIER_PIN_IECTRL_MASK; 1006e908892SMasahiro Yamada } 1016e908892SMasahiro Yamada 1026e908892SMasahiro Yamada static inline unsigned int uniphier_pin_get_drvctrl(void *drv_data) 1036e908892SMasahiro Yamada { 1046e908892SMasahiro Yamada return ((unsigned long)drv_data >> UNIPHIER_PIN_DRVCTRL_SHIFT) & 1056e908892SMasahiro Yamada UNIPHIER_PIN_DRVCTRL_MASK; 1066e908892SMasahiro Yamada } 1076e908892SMasahiro Yamada 1089eaa98a6SMasahiro Yamada static inline unsigned int uniphier_pin_get_drv_type(void *drv_data) 1096e908892SMasahiro Yamada { 1109eaa98a6SMasahiro Yamada return ((unsigned long)drv_data >> UNIPHIER_PIN_DRV_TYPE_SHIFT) & 1119eaa98a6SMasahiro Yamada UNIPHIER_PIN_DRV_TYPE_MASK; 1126e908892SMasahiro Yamada } 1136e908892SMasahiro Yamada 1146e908892SMasahiro Yamada static inline unsigned int uniphier_pin_get_pupdctrl(void *drv_data) 1156e908892SMasahiro Yamada { 1166e908892SMasahiro Yamada return ((unsigned long)drv_data >> UNIPHIER_PIN_PUPDCTRL_SHIFT) & 1176e908892SMasahiro Yamada UNIPHIER_PIN_PUPDCTRL_MASK; 1186e908892SMasahiro Yamada } 1196e908892SMasahiro Yamada 1206e908892SMasahiro Yamada static inline unsigned int uniphier_pin_get_pull_dir(void *drv_data) 1216e908892SMasahiro Yamada { 1226e908892SMasahiro Yamada return ((unsigned long)drv_data >> UNIPHIER_PIN_PULL_DIR_SHIFT) & 1236e908892SMasahiro Yamada UNIPHIER_PIN_PULL_DIR_MASK; 1246e908892SMasahiro Yamada } 1256e908892SMasahiro Yamada 1266e908892SMasahiro Yamada struct uniphier_pinctrl_group { 1276e908892SMasahiro Yamada const char *name; 1286e908892SMasahiro Yamada const unsigned *pins; 1296e908892SMasahiro Yamada unsigned num_pins; 13039ec9aceSMasahiro Yamada const int *muxvals; 1316e908892SMasahiro Yamada }; 1326e908892SMasahiro Yamada 1336e908892SMasahiro Yamada struct uniphier_pinmux_function { 1346e908892SMasahiro Yamada const char *name; 1356e908892SMasahiro Yamada const char * const *groups; 1366e908892SMasahiro Yamada unsigned num_groups; 1376e908892SMasahiro Yamada }; 1386e908892SMasahiro Yamada 1396e908892SMasahiro Yamada struct uniphier_pinctrl_socdata { 140fc78a566SMasahiro Yamada const struct pinctrl_pin_desc *pins; 141fc78a566SMasahiro Yamada unsigned int npins; 1426e908892SMasahiro Yamada const struct uniphier_pinctrl_group *groups; 1436e908892SMasahiro Yamada int groups_count; 1446e908892SMasahiro Yamada const struct uniphier_pinmux_function *functions; 1456e908892SMasahiro Yamada int functions_count; 1467f6ee0a5SMasahiro Yamada int (*get_gpio_muxval)(unsigned int pin, unsigned int gpio_offset); 147c2ebf475SMasahiro Yamada unsigned int caps; 148aa543888SMasahiro Yamada #define UNIPHIER_PINCTRL_CAPS_PERPIN_IECTRL BIT(1) 149c2ebf475SMasahiro Yamada #define UNIPHIER_PINCTRL_CAPS_DBGMUX_SEPARATE BIT(0) 1506e908892SMasahiro Yamada }; 1516e908892SMasahiro Yamada 1526e908892SMasahiro Yamada #define UNIPHIER_PINCTRL_PIN(a, b, c, d, e, f, g) \ 1536e908892SMasahiro Yamada { \ 1546e908892SMasahiro Yamada .number = a, \ 1556e908892SMasahiro Yamada .name = b, \ 1566e908892SMasahiro Yamada .drv_data = (void *)UNIPHIER_PIN_ATTR_PACKED(c, d, e, f, g), \ 1576e908892SMasahiro Yamada } 1586e908892SMasahiro Yamada 1597f6ee0a5SMasahiro Yamada #define __UNIPHIER_PINCTRL_GROUP(grp, mux) \ 1606e908892SMasahiro Yamada { \ 1616e908892SMasahiro Yamada .name = #grp, \ 1626e908892SMasahiro Yamada .pins = grp##_pins, \ 1636e908892SMasahiro Yamada .num_pins = ARRAY_SIZE(grp##_pins), \ 1647f6ee0a5SMasahiro Yamada .muxvals = mux, \ 1656e908892SMasahiro Yamada } 1666e908892SMasahiro Yamada 1676e908892SMasahiro Yamada #define UNIPHIER_PINCTRL_GROUP(grp) \ 1687f6ee0a5SMasahiro Yamada __UNIPHIER_PINCTRL_GROUP(grp, \ 1697f6ee0a5SMasahiro Yamada grp##_muxvals + \ 1707f6ee0a5SMasahiro Yamada BUILD_BUG_ON_ZERO(ARRAY_SIZE(grp##_pins) != \ 1717f6ee0a5SMasahiro Yamada ARRAY_SIZE(grp##_muxvals))) 1726e908892SMasahiro Yamada 1737f6ee0a5SMasahiro Yamada #define UNIPHIER_PINCTRL_GROUP_GPIO(grp) \ 1747f6ee0a5SMasahiro Yamada __UNIPHIER_PINCTRL_GROUP(grp, NULL) 1756e908892SMasahiro Yamada 1766e908892SMasahiro Yamada #define UNIPHIER_PINMUX_FUNCTION(func) \ 1776e908892SMasahiro Yamada { \ 1786e908892SMasahiro Yamada .name = #func, \ 1796e908892SMasahiro Yamada .groups = func##_groups, \ 1806e908892SMasahiro Yamada .num_groups = ARRAY_SIZE(func##_groups), \ 1816e908892SMasahiro Yamada } 1826e908892SMasahiro Yamada 1836e908892SMasahiro Yamada int uniphier_pinctrl_probe(struct platform_device *pdev, 1846e908892SMasahiro Yamada struct uniphier_pinctrl_socdata *socdata); 1856e908892SMasahiro Yamada 1869697509eSMasahiro Yamada extern const struct dev_pm_ops uniphier_pinctrl_pm_ops; 1879697509eSMasahiro Yamada 1886e908892SMasahiro Yamada #endif /* __PINCTRL_UNIPHIER_H__ */ 189