16e908892SMasahiro Yamada /* 26e908892SMasahiro Yamada * Copyright (C) 2015 Masahiro Yamada <yamada.masahiro@socionext.com> 36e908892SMasahiro Yamada * 46e908892SMasahiro Yamada * This program is free software; you can redistribute it and/or modify 56e908892SMasahiro Yamada * it under the terms of the GNU General Public License as published by 66e908892SMasahiro Yamada * the Free Software Foundation; either version 2 of the License, or 76e908892SMasahiro Yamada * (at your option) any later version. 86e908892SMasahiro Yamada * 96e908892SMasahiro Yamada * This program is distributed in the hope that it will be useful, 106e908892SMasahiro Yamada * but WITHOUT ANY WARRANTY; without even the implied warranty of 116e908892SMasahiro Yamada * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 126e908892SMasahiro Yamada * GNU General Public License for more details. 136e908892SMasahiro Yamada */ 146e908892SMasahiro Yamada 156e908892SMasahiro Yamada #ifndef __PINCTRL_UNIPHIER_H__ 166e908892SMasahiro Yamada #define __PINCTRL_UNIPHIER_H__ 176e908892SMasahiro Yamada 18c2ebf475SMasahiro Yamada #include <linux/bitops.h> 196e908892SMasahiro Yamada #include <linux/bug.h> 206e908892SMasahiro Yamada #include <linux/kernel.h> 216e908892SMasahiro Yamada #include <linux/types.h> 226e908892SMasahiro Yamada 23fc78a566SMasahiro Yamada struct platform_device; 24fc78a566SMasahiro Yamada 256e908892SMasahiro Yamada #define UNIPHIER_PINCTRL_PINMUX_BASE 0x0 266e908892SMasahiro Yamada #define UNIPHIER_PINCTRL_LOAD_PINMUX 0x700 276e908892SMasahiro Yamada #define UNIPHIER_PINCTRL_DRVCTRL_BASE 0x800 286e908892SMasahiro Yamada #define UNIPHIER_PINCTRL_DRV2CTRL_BASE 0x900 2972e5706aSMasahiro Yamada #define UNIPHIER_PINCTRL_DRV3CTRL_BASE 0x980 306e908892SMasahiro Yamada #define UNIPHIER_PINCTRL_PUPDCTRL_BASE 0xa00 316e908892SMasahiro Yamada #define UNIPHIER_PINCTRL_IECTRL 0xd00 326e908892SMasahiro Yamada 336e908892SMasahiro Yamada /* input enable control register bit */ 346e908892SMasahiro Yamada #define UNIPHIER_PIN_IECTRL_SHIFT 0 356e908892SMasahiro Yamada #define UNIPHIER_PIN_IECTRL_BITS 8 366e908892SMasahiro Yamada #define UNIPHIER_PIN_IECTRL_MASK ((1UL << (UNIPHIER_PIN_IECTRL_BITS)) \ 376e908892SMasahiro Yamada - 1) 386e908892SMasahiro Yamada 396e908892SMasahiro Yamada /* drive strength control register number */ 406e908892SMasahiro Yamada #define UNIPHIER_PIN_DRVCTRL_SHIFT ((UNIPHIER_PIN_IECTRL_SHIFT) + \ 416e908892SMasahiro Yamada (UNIPHIER_PIN_IECTRL_BITS)) 426e908892SMasahiro Yamada #define UNIPHIER_PIN_DRVCTRL_BITS 9 436e908892SMasahiro Yamada #define UNIPHIER_PIN_DRVCTRL_MASK ((1UL << (UNIPHIER_PIN_DRVCTRL_BITS)) \ 446e908892SMasahiro Yamada - 1) 456e908892SMasahiro Yamada 469eaa98a6SMasahiro Yamada /* drive control type */ 479eaa98a6SMasahiro Yamada #define UNIPHIER_PIN_DRV_TYPE_SHIFT ((UNIPHIER_PIN_DRVCTRL_SHIFT) + \ 486e908892SMasahiro Yamada (UNIPHIER_PIN_DRVCTRL_BITS)) 499eaa98a6SMasahiro Yamada #define UNIPHIER_PIN_DRV_TYPE_BITS 3 509eaa98a6SMasahiro Yamada #define UNIPHIER_PIN_DRV_TYPE_MASK ((1UL << (UNIPHIER_PIN_DRV_TYPE_BITS)) \ 516e908892SMasahiro Yamada - 1) 526e908892SMasahiro Yamada 536e908892SMasahiro Yamada /* pull-up / pull-down register number */ 549eaa98a6SMasahiro Yamada #define UNIPHIER_PIN_PUPDCTRL_SHIFT ((UNIPHIER_PIN_DRV_TYPE_SHIFT) + \ 559eaa98a6SMasahiro Yamada (UNIPHIER_PIN_DRV_TYPE_BITS)) 566e908892SMasahiro Yamada #define UNIPHIER_PIN_PUPDCTRL_BITS 9 576e908892SMasahiro Yamada #define UNIPHIER_PIN_PUPDCTRL_MASK ((1UL << (UNIPHIER_PIN_PUPDCTRL_BITS))\ 586e908892SMasahiro Yamada - 1) 596e908892SMasahiro Yamada 606e908892SMasahiro Yamada /* direction of pull register */ 616e908892SMasahiro Yamada #define UNIPHIER_PIN_PULL_DIR_SHIFT ((UNIPHIER_PIN_PUPDCTRL_SHIFT) + \ 626e908892SMasahiro Yamada (UNIPHIER_PIN_PUPDCTRL_BITS)) 636e908892SMasahiro Yamada #define UNIPHIER_PIN_PULL_DIR_BITS 3 646e908892SMasahiro Yamada #define UNIPHIER_PIN_PULL_DIR_MASK ((1UL << (UNIPHIER_PIN_PULL_DIR_BITS))\ 656e908892SMasahiro Yamada - 1) 666e908892SMasahiro Yamada 676e908892SMasahiro Yamada #if UNIPHIER_PIN_PULL_DIR_SHIFT + UNIPHIER_PIN_PULL_DIR_BITS > BITS_PER_LONG 686e908892SMasahiro Yamada #error "unable to pack pin attributes." 696e908892SMasahiro Yamada #endif 706e908892SMasahiro Yamada 716e908892SMasahiro Yamada #define UNIPHIER_PIN_IECTRL_NONE (UNIPHIER_PIN_IECTRL_MASK) 726e908892SMasahiro Yamada 739eaa98a6SMasahiro Yamada /* drive control type */ 749eaa98a6SMasahiro Yamada enum uniphier_pin_drv_type { 759eaa98a6SMasahiro Yamada UNIPHIER_PIN_DRV_1BIT, /* 2 level control: 4/8 mA */ 769eaa98a6SMasahiro Yamada UNIPHIER_PIN_DRV_2BIT, /* 4 level control: 8/12/16/20 mA */ 7772e5706aSMasahiro Yamada UNIPHIER_PIN_DRV_3BIT, /* 8 level control: 4/5/7/9/11/12/14/16 mA */ 789eaa98a6SMasahiro Yamada UNIPHIER_PIN_DRV_FIXED4, /* fixed to 4mA */ 799eaa98a6SMasahiro Yamada UNIPHIER_PIN_DRV_FIXED5, /* fixed to 5mA */ 809eaa98a6SMasahiro Yamada UNIPHIER_PIN_DRV_FIXED8, /* fixed to 8mA */ 816e908892SMasahiro Yamada UNIPHIER_PIN_DRV_NONE, /* no support (input only pin) */ 826e908892SMasahiro Yamada }; 836e908892SMasahiro Yamada 846e908892SMasahiro Yamada /* direction of pull register (no pin supports bi-directional pull biasing) */ 856e908892SMasahiro Yamada enum uniphier_pin_pull_dir { 866e908892SMasahiro Yamada UNIPHIER_PIN_PULL_UP, /* pull-up or disabled */ 876e908892SMasahiro Yamada UNIPHIER_PIN_PULL_DOWN, /* pull-down or disabled */ 886e908892SMasahiro Yamada UNIPHIER_PIN_PULL_UP_FIXED, /* always pull-up */ 896e908892SMasahiro Yamada UNIPHIER_PIN_PULL_DOWN_FIXED, /* always pull-down */ 906e908892SMasahiro Yamada UNIPHIER_PIN_PULL_NONE, /* no pull register */ 916e908892SMasahiro Yamada }; 926e908892SMasahiro Yamada 936e908892SMasahiro Yamada #define UNIPHIER_PIN_IECTRL(x) \ 946e908892SMasahiro Yamada (((x) & (UNIPHIER_PIN_IECTRL_MASK)) << (UNIPHIER_PIN_IECTRL_SHIFT)) 956e908892SMasahiro Yamada #define UNIPHIER_PIN_DRVCTRL(x) \ 966e908892SMasahiro Yamada (((x) & (UNIPHIER_PIN_DRVCTRL_MASK)) << (UNIPHIER_PIN_DRVCTRL_SHIFT)) 979eaa98a6SMasahiro Yamada #define UNIPHIER_PIN_DRV_TYPE(x) \ 989eaa98a6SMasahiro Yamada (((x) & (UNIPHIER_PIN_DRV_TYPE_MASK)) << (UNIPHIER_PIN_DRV_TYPE_SHIFT)) 996e908892SMasahiro Yamada #define UNIPHIER_PIN_PUPDCTRL(x) \ 1006e908892SMasahiro Yamada (((x) & (UNIPHIER_PIN_PUPDCTRL_MASK)) << (UNIPHIER_PIN_PUPDCTRL_SHIFT)) 1016e908892SMasahiro Yamada #define UNIPHIER_PIN_PULL_DIR(x) \ 1026e908892SMasahiro Yamada (((x) & (UNIPHIER_PIN_PULL_DIR_MASK)) << (UNIPHIER_PIN_PULL_DIR_SHIFT)) 1036e908892SMasahiro Yamada 1049eaa98a6SMasahiro Yamada #define UNIPHIER_PIN_ATTR_PACKED(iectrl, drvctrl, drv_type, pupdctrl, pull_dir)\ 1056e908892SMasahiro Yamada (UNIPHIER_PIN_IECTRL(iectrl) | \ 1066e908892SMasahiro Yamada UNIPHIER_PIN_DRVCTRL(drvctrl) | \ 1079eaa98a6SMasahiro Yamada UNIPHIER_PIN_DRV_TYPE(drv_type) | \ 1086e908892SMasahiro Yamada UNIPHIER_PIN_PUPDCTRL(pupdctrl) | \ 1096e908892SMasahiro Yamada UNIPHIER_PIN_PULL_DIR(pull_dir)) 1106e908892SMasahiro Yamada 1116e908892SMasahiro Yamada static inline unsigned int uniphier_pin_get_iectrl(void *drv_data) 1126e908892SMasahiro Yamada { 1136e908892SMasahiro Yamada return ((unsigned long)drv_data >> UNIPHIER_PIN_IECTRL_SHIFT) & 1146e908892SMasahiro Yamada UNIPHIER_PIN_IECTRL_MASK; 1156e908892SMasahiro Yamada } 1166e908892SMasahiro Yamada 1176e908892SMasahiro Yamada static inline unsigned int uniphier_pin_get_drvctrl(void *drv_data) 1186e908892SMasahiro Yamada { 1196e908892SMasahiro Yamada return ((unsigned long)drv_data >> UNIPHIER_PIN_DRVCTRL_SHIFT) & 1206e908892SMasahiro Yamada UNIPHIER_PIN_DRVCTRL_MASK; 1216e908892SMasahiro Yamada } 1226e908892SMasahiro Yamada 1239eaa98a6SMasahiro Yamada static inline unsigned int uniphier_pin_get_drv_type(void *drv_data) 1246e908892SMasahiro Yamada { 1259eaa98a6SMasahiro Yamada return ((unsigned long)drv_data >> UNIPHIER_PIN_DRV_TYPE_SHIFT) & 1269eaa98a6SMasahiro Yamada UNIPHIER_PIN_DRV_TYPE_MASK; 1276e908892SMasahiro Yamada } 1286e908892SMasahiro Yamada 1296e908892SMasahiro Yamada static inline unsigned int uniphier_pin_get_pupdctrl(void *drv_data) 1306e908892SMasahiro Yamada { 1316e908892SMasahiro Yamada return ((unsigned long)drv_data >> UNIPHIER_PIN_PUPDCTRL_SHIFT) & 1326e908892SMasahiro Yamada UNIPHIER_PIN_PUPDCTRL_MASK; 1336e908892SMasahiro Yamada } 1346e908892SMasahiro Yamada 1356e908892SMasahiro Yamada static inline unsigned int uniphier_pin_get_pull_dir(void *drv_data) 1366e908892SMasahiro Yamada { 1376e908892SMasahiro Yamada return ((unsigned long)drv_data >> UNIPHIER_PIN_PULL_DIR_SHIFT) & 1386e908892SMasahiro Yamada UNIPHIER_PIN_PULL_DIR_MASK; 1396e908892SMasahiro Yamada } 1406e908892SMasahiro Yamada 1416e908892SMasahiro Yamada enum uniphier_pinmux_gpio_range_type { 1426e908892SMasahiro Yamada UNIPHIER_PINMUX_GPIO_RANGE_PORT, 1436e908892SMasahiro Yamada UNIPHIER_PINMUX_GPIO_RANGE_IRQ, 1446e908892SMasahiro Yamada UNIPHIER_PINMUX_GPIO_RANGE_NONE, 1456e908892SMasahiro Yamada }; 1466e908892SMasahiro Yamada 1476e908892SMasahiro Yamada struct uniphier_pinctrl_group { 1486e908892SMasahiro Yamada const char *name; 1496e908892SMasahiro Yamada const unsigned *pins; 1506e908892SMasahiro Yamada unsigned num_pins; 1516e908892SMasahiro Yamada const unsigned *muxvals; 1526e908892SMasahiro Yamada enum uniphier_pinmux_gpio_range_type range_type; 1536e908892SMasahiro Yamada }; 1546e908892SMasahiro Yamada 1556e908892SMasahiro Yamada struct uniphier_pinmux_function { 1566e908892SMasahiro Yamada const char *name; 1576e908892SMasahiro Yamada const char * const *groups; 1586e908892SMasahiro Yamada unsigned num_groups; 1596e908892SMasahiro Yamada }; 1606e908892SMasahiro Yamada 1616e908892SMasahiro Yamada struct uniphier_pinctrl_socdata { 162fc78a566SMasahiro Yamada const struct pinctrl_pin_desc *pins; 163fc78a566SMasahiro Yamada unsigned int npins; 1646e908892SMasahiro Yamada const struct uniphier_pinctrl_group *groups; 1656e908892SMasahiro Yamada int groups_count; 1666e908892SMasahiro Yamada const struct uniphier_pinmux_function *functions; 1676e908892SMasahiro Yamada int functions_count; 168c2ebf475SMasahiro Yamada unsigned int caps; 169aa543888SMasahiro Yamada #define UNIPHIER_PINCTRL_CAPS_PERPIN_IECTRL BIT(1) 170c2ebf475SMasahiro Yamada #define UNIPHIER_PINCTRL_CAPS_DBGMUX_SEPARATE BIT(0) 1716e908892SMasahiro Yamada }; 1726e908892SMasahiro Yamada 1736e908892SMasahiro Yamada #define UNIPHIER_PINCTRL_PIN(a, b, c, d, e, f, g) \ 1746e908892SMasahiro Yamada { \ 1756e908892SMasahiro Yamada .number = a, \ 1766e908892SMasahiro Yamada .name = b, \ 1776e908892SMasahiro Yamada .drv_data = (void *)UNIPHIER_PIN_ATTR_PACKED(c, d, e, f, g), \ 1786e908892SMasahiro Yamada } 1796e908892SMasahiro Yamada 1806e908892SMasahiro Yamada #define __UNIPHIER_PINCTRL_GROUP(grp, type) \ 1816e908892SMasahiro Yamada { \ 1826e908892SMasahiro Yamada .name = #grp, \ 1836e908892SMasahiro Yamada .pins = grp##_pins, \ 1846e908892SMasahiro Yamada .num_pins = ARRAY_SIZE(grp##_pins), \ 1856e908892SMasahiro Yamada .muxvals = grp##_muxvals + \ 1866e908892SMasahiro Yamada BUILD_BUG_ON_ZERO(ARRAY_SIZE(grp##_pins) != \ 1876e908892SMasahiro Yamada ARRAY_SIZE(grp##_muxvals)), \ 1886e908892SMasahiro Yamada .range_type = type, \ 1896e908892SMasahiro Yamada } 1906e908892SMasahiro Yamada 1916e908892SMasahiro Yamada #define UNIPHIER_PINCTRL_GROUP(grp) \ 1926e908892SMasahiro Yamada __UNIPHIER_PINCTRL_GROUP(grp, UNIPHIER_PINMUX_GPIO_RANGE_NONE) 1936e908892SMasahiro Yamada 1946e908892SMasahiro Yamada #define UNIPHIER_PINCTRL_GROUP_GPIO_RANGE_PORT(grp) \ 1956e908892SMasahiro Yamada __UNIPHIER_PINCTRL_GROUP(grp, UNIPHIER_PINMUX_GPIO_RANGE_PORT) 1966e908892SMasahiro Yamada 1976e908892SMasahiro Yamada #define UNIPHIER_PINCTRL_GROUP_GPIO_RANGE_IRQ(grp) \ 1986e908892SMasahiro Yamada __UNIPHIER_PINCTRL_GROUP(grp, UNIPHIER_PINMUX_GPIO_RANGE_IRQ) 1996e908892SMasahiro Yamada 2006e908892SMasahiro Yamada #define UNIPHIER_PINCTRL_GROUP_SINGLE(grp, array, ofst) \ 2016e908892SMasahiro Yamada { \ 2026e908892SMasahiro Yamada .name = #grp, \ 2036e908892SMasahiro Yamada .pins = array##_pins + ofst, \ 2046e908892SMasahiro Yamada .num_pins = 1, \ 2056e908892SMasahiro Yamada .muxvals = array##_muxvals + ofst, \ 2066e908892SMasahiro Yamada } 2076e908892SMasahiro Yamada 2086e908892SMasahiro Yamada #define UNIPHIER_PINMUX_FUNCTION(func) \ 2096e908892SMasahiro Yamada { \ 2106e908892SMasahiro Yamada .name = #func, \ 2116e908892SMasahiro Yamada .groups = func##_groups, \ 2126e908892SMasahiro Yamada .num_groups = ARRAY_SIZE(func##_groups), \ 2136e908892SMasahiro Yamada } 2146e908892SMasahiro Yamada 2156e908892SMasahiro Yamada int uniphier_pinctrl_probe(struct platform_device *pdev, 2166e908892SMasahiro Yamada struct uniphier_pinctrl_socdata *socdata); 2176e908892SMasahiro Yamada 2186e908892SMasahiro Yamada #endif /* __PINCTRL_UNIPHIER_H__ */ 219