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 19c2ebf475SMasahiro Yamada #include <linux/bitops.h> 206e908892SMasahiro Yamada #include <linux/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 286e908892SMasahiro Yamada #define UNIPHIER_PIN_IECTRL_BITS 8 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) 656e908892SMasahiro Yamada 669eaa98a6SMasahiro Yamada /* drive control type */ 679eaa98a6SMasahiro Yamada enum uniphier_pin_drv_type { 689eaa98a6SMasahiro Yamada UNIPHIER_PIN_DRV_1BIT, /* 2 level control: 4/8 mA */ 699eaa98a6SMasahiro Yamada UNIPHIER_PIN_DRV_2BIT, /* 4 level control: 8/12/16/20 mA */ 7072e5706aSMasahiro Yamada UNIPHIER_PIN_DRV_3BIT, /* 8 level control: 4/5/7/9/11/12/14/16 mA */ 719eaa98a6SMasahiro Yamada UNIPHIER_PIN_DRV_FIXED4, /* fixed to 4mA */ 729eaa98a6SMasahiro Yamada UNIPHIER_PIN_DRV_FIXED5, /* fixed to 5mA */ 739eaa98a6SMasahiro Yamada UNIPHIER_PIN_DRV_FIXED8, /* fixed to 8mA */ 746e908892SMasahiro Yamada UNIPHIER_PIN_DRV_NONE, /* no support (input only pin) */ 756e908892SMasahiro Yamada }; 766e908892SMasahiro Yamada 776e908892SMasahiro Yamada /* direction of pull register (no pin supports bi-directional pull biasing) */ 786e908892SMasahiro Yamada enum uniphier_pin_pull_dir { 796e908892SMasahiro Yamada UNIPHIER_PIN_PULL_UP, /* pull-up or disabled */ 806e908892SMasahiro Yamada UNIPHIER_PIN_PULL_DOWN, /* pull-down or disabled */ 816e908892SMasahiro Yamada UNIPHIER_PIN_PULL_UP_FIXED, /* always pull-up */ 826e908892SMasahiro Yamada UNIPHIER_PIN_PULL_DOWN_FIXED, /* always pull-down */ 836e908892SMasahiro Yamada UNIPHIER_PIN_PULL_NONE, /* no pull register */ 846e908892SMasahiro Yamada }; 856e908892SMasahiro Yamada 866e908892SMasahiro Yamada #define UNIPHIER_PIN_IECTRL(x) \ 876e908892SMasahiro Yamada (((x) & (UNIPHIER_PIN_IECTRL_MASK)) << (UNIPHIER_PIN_IECTRL_SHIFT)) 886e908892SMasahiro Yamada #define UNIPHIER_PIN_DRVCTRL(x) \ 896e908892SMasahiro Yamada (((x) & (UNIPHIER_PIN_DRVCTRL_MASK)) << (UNIPHIER_PIN_DRVCTRL_SHIFT)) 909eaa98a6SMasahiro Yamada #define UNIPHIER_PIN_DRV_TYPE(x) \ 919eaa98a6SMasahiro Yamada (((x) & (UNIPHIER_PIN_DRV_TYPE_MASK)) << (UNIPHIER_PIN_DRV_TYPE_SHIFT)) 926e908892SMasahiro Yamada #define UNIPHIER_PIN_PUPDCTRL(x) \ 936e908892SMasahiro Yamada (((x) & (UNIPHIER_PIN_PUPDCTRL_MASK)) << (UNIPHIER_PIN_PUPDCTRL_SHIFT)) 946e908892SMasahiro Yamada #define UNIPHIER_PIN_PULL_DIR(x) \ 956e908892SMasahiro Yamada (((x) & (UNIPHIER_PIN_PULL_DIR_MASK)) << (UNIPHIER_PIN_PULL_DIR_SHIFT)) 966e908892SMasahiro Yamada 979eaa98a6SMasahiro Yamada #define UNIPHIER_PIN_ATTR_PACKED(iectrl, drvctrl, drv_type, pupdctrl, pull_dir)\ 986e908892SMasahiro Yamada (UNIPHIER_PIN_IECTRL(iectrl) | \ 996e908892SMasahiro Yamada UNIPHIER_PIN_DRVCTRL(drvctrl) | \ 1009eaa98a6SMasahiro Yamada UNIPHIER_PIN_DRV_TYPE(drv_type) | \ 1016e908892SMasahiro Yamada UNIPHIER_PIN_PUPDCTRL(pupdctrl) | \ 1026e908892SMasahiro Yamada UNIPHIER_PIN_PULL_DIR(pull_dir)) 1036e908892SMasahiro Yamada 1046e908892SMasahiro Yamada static inline unsigned int uniphier_pin_get_iectrl(void *drv_data) 1056e908892SMasahiro Yamada { 1066e908892SMasahiro Yamada return ((unsigned long)drv_data >> UNIPHIER_PIN_IECTRL_SHIFT) & 1076e908892SMasahiro Yamada UNIPHIER_PIN_IECTRL_MASK; 1086e908892SMasahiro Yamada } 1096e908892SMasahiro Yamada 1106e908892SMasahiro Yamada static inline unsigned int uniphier_pin_get_drvctrl(void *drv_data) 1116e908892SMasahiro Yamada { 1126e908892SMasahiro Yamada return ((unsigned long)drv_data >> UNIPHIER_PIN_DRVCTRL_SHIFT) & 1136e908892SMasahiro Yamada UNIPHIER_PIN_DRVCTRL_MASK; 1146e908892SMasahiro Yamada } 1156e908892SMasahiro Yamada 1169eaa98a6SMasahiro Yamada static inline unsigned int uniphier_pin_get_drv_type(void *drv_data) 1176e908892SMasahiro Yamada { 1189eaa98a6SMasahiro Yamada return ((unsigned long)drv_data >> UNIPHIER_PIN_DRV_TYPE_SHIFT) & 1199eaa98a6SMasahiro Yamada UNIPHIER_PIN_DRV_TYPE_MASK; 1206e908892SMasahiro Yamada } 1216e908892SMasahiro Yamada 1226e908892SMasahiro Yamada static inline unsigned int uniphier_pin_get_pupdctrl(void *drv_data) 1236e908892SMasahiro Yamada { 1246e908892SMasahiro Yamada return ((unsigned long)drv_data >> UNIPHIER_PIN_PUPDCTRL_SHIFT) & 1256e908892SMasahiro Yamada UNIPHIER_PIN_PUPDCTRL_MASK; 1266e908892SMasahiro Yamada } 1276e908892SMasahiro Yamada 1286e908892SMasahiro Yamada static inline unsigned int uniphier_pin_get_pull_dir(void *drv_data) 1296e908892SMasahiro Yamada { 1306e908892SMasahiro Yamada return ((unsigned long)drv_data >> UNIPHIER_PIN_PULL_DIR_SHIFT) & 1316e908892SMasahiro Yamada UNIPHIER_PIN_PULL_DIR_MASK; 1326e908892SMasahiro Yamada } 1336e908892SMasahiro Yamada 1346e908892SMasahiro Yamada struct uniphier_pinctrl_group { 1356e908892SMasahiro Yamada const char *name; 1366e908892SMasahiro Yamada const unsigned *pins; 1376e908892SMasahiro Yamada unsigned num_pins; 13839ec9aceSMasahiro Yamada const int *muxvals; 1396e908892SMasahiro Yamada }; 1406e908892SMasahiro Yamada 1416e908892SMasahiro Yamada struct uniphier_pinmux_function { 1426e908892SMasahiro Yamada const char *name; 1436e908892SMasahiro Yamada const char * const *groups; 1446e908892SMasahiro Yamada unsigned num_groups; 1456e908892SMasahiro Yamada }; 1466e908892SMasahiro Yamada 1476e908892SMasahiro Yamada struct uniphier_pinctrl_socdata { 148fc78a566SMasahiro Yamada const struct pinctrl_pin_desc *pins; 149fc78a566SMasahiro Yamada unsigned int npins; 1506e908892SMasahiro Yamada const struct uniphier_pinctrl_group *groups; 1516e908892SMasahiro Yamada int groups_count; 1526e908892SMasahiro Yamada const struct uniphier_pinmux_function *functions; 1536e908892SMasahiro Yamada int functions_count; 1547f6ee0a5SMasahiro Yamada int (*get_gpio_muxval)(unsigned int pin, unsigned int gpio_offset); 155c2ebf475SMasahiro Yamada unsigned int caps; 156aa543888SMasahiro Yamada #define UNIPHIER_PINCTRL_CAPS_PERPIN_IECTRL BIT(1) 157c2ebf475SMasahiro Yamada #define UNIPHIER_PINCTRL_CAPS_DBGMUX_SEPARATE BIT(0) 1586e908892SMasahiro Yamada }; 1596e908892SMasahiro Yamada 1606e908892SMasahiro Yamada #define UNIPHIER_PINCTRL_PIN(a, b, c, d, e, f, g) \ 1616e908892SMasahiro Yamada { \ 1626e908892SMasahiro Yamada .number = a, \ 1636e908892SMasahiro Yamada .name = b, \ 1646e908892SMasahiro Yamada .drv_data = (void *)UNIPHIER_PIN_ATTR_PACKED(c, d, e, f, g), \ 1656e908892SMasahiro Yamada } 1666e908892SMasahiro Yamada 1677f6ee0a5SMasahiro Yamada #define __UNIPHIER_PINCTRL_GROUP(grp, mux) \ 1686e908892SMasahiro Yamada { \ 1696e908892SMasahiro Yamada .name = #grp, \ 1706e908892SMasahiro Yamada .pins = grp##_pins, \ 1716e908892SMasahiro Yamada .num_pins = ARRAY_SIZE(grp##_pins), \ 1727f6ee0a5SMasahiro Yamada .muxvals = mux, \ 1736e908892SMasahiro Yamada } 1746e908892SMasahiro Yamada 1756e908892SMasahiro Yamada #define UNIPHIER_PINCTRL_GROUP(grp) \ 1767f6ee0a5SMasahiro Yamada __UNIPHIER_PINCTRL_GROUP(grp, \ 1777f6ee0a5SMasahiro Yamada grp##_muxvals + \ 1787f6ee0a5SMasahiro Yamada BUILD_BUG_ON_ZERO(ARRAY_SIZE(grp##_pins) != \ 1797f6ee0a5SMasahiro Yamada ARRAY_SIZE(grp##_muxvals))) 1806e908892SMasahiro Yamada 1817f6ee0a5SMasahiro Yamada #define UNIPHIER_PINCTRL_GROUP_GPIO(grp) \ 1827f6ee0a5SMasahiro Yamada __UNIPHIER_PINCTRL_GROUP(grp, NULL) 1836e908892SMasahiro Yamada 1846e908892SMasahiro Yamada #define UNIPHIER_PINMUX_FUNCTION(func) \ 1856e908892SMasahiro Yamada { \ 1866e908892SMasahiro Yamada .name = #func, \ 1876e908892SMasahiro Yamada .groups = func##_groups, \ 1886e908892SMasahiro Yamada .num_groups = ARRAY_SIZE(func##_groups), \ 1896e908892SMasahiro Yamada } 1906e908892SMasahiro Yamada 1916e908892SMasahiro Yamada int uniphier_pinctrl_probe(struct platform_device *pdev, 1926e908892SMasahiro Yamada struct uniphier_pinctrl_socdata *socdata); 1936e908892SMasahiro Yamada 1946e908892SMasahiro Yamada #endif /* __PINCTRL_UNIPHIER_H__ */ 195