.. | .. |
---|
13 | 13 | #include <linux/of.h> |
---|
14 | 14 | #include <linux/platform_device.h> |
---|
15 | 15 | #include <linux/pinctrl/pinctrl.h> |
---|
| 16 | +#include <linux/pinctrl/pinconf-generic.h> |
---|
16 | 17 | #include "pinctrl-owl.h" |
---|
17 | 18 | |
---|
18 | 19 | /* Pinctrl registers offset */ |
---|
.. | .. |
---|
32 | 33 | #define PAD_SR0 (0x0270) |
---|
33 | 34 | #define PAD_SR1 (0x0274) |
---|
34 | 35 | #define PAD_SR2 (0x0278) |
---|
35 | | - |
---|
36 | | -#define OWL_GPIO_PORT_A 0 |
---|
37 | | -#define OWL_GPIO_PORT_B 1 |
---|
38 | | -#define OWL_GPIO_PORT_C 2 |
---|
39 | | -#define OWL_GPIO_PORT_D 3 |
---|
40 | | -#define OWL_GPIO_PORT_E 4 |
---|
41 | | -#define OWL_GPIO_PORT_F 5 |
---|
42 | 36 | |
---|
43 | 37 | #define _GPIOA(offset) (offset) |
---|
44 | 38 | #define _GPIOB(offset) (32 + (offset)) |
---|
.. | .. |
---|
892 | 886 | static unsigned int sensor0_sr_pads[] = { SENSOR0_PCLK, |
---|
893 | 887 | SENSOR0_CKOUT }; |
---|
894 | 888 | |
---|
895 | | -#define MUX_PG(group_name, reg, shift, width) \ |
---|
896 | | - { \ |
---|
897 | | - .name = #group_name, \ |
---|
898 | | - .pads = group_name##_pads, \ |
---|
899 | | - .npads = ARRAY_SIZE(group_name##_pads), \ |
---|
900 | | - .funcs = group_name##_funcs, \ |
---|
901 | | - .nfuncs = ARRAY_SIZE(group_name##_funcs), \ |
---|
902 | | - .mfpctl_reg = MFCTL##reg, \ |
---|
903 | | - .mfpctl_shift = shift, \ |
---|
904 | | - .mfpctl_width = width, \ |
---|
905 | | - .drv_reg = -1, \ |
---|
906 | | - .drv_shift = -1, \ |
---|
907 | | - .drv_width = -1, \ |
---|
908 | | - .sr_reg = -1, \ |
---|
909 | | - .sr_shift = -1, \ |
---|
910 | | - .sr_width = -1, \ |
---|
911 | | - } |
---|
912 | | - |
---|
913 | | -#define DRV_PG(group_name, reg, shift, width) \ |
---|
914 | | - { \ |
---|
915 | | - .name = #group_name, \ |
---|
916 | | - .pads = group_name##_pads, \ |
---|
917 | | - .npads = ARRAY_SIZE(group_name##_pads), \ |
---|
918 | | - .mfpctl_reg = -1, \ |
---|
919 | | - .mfpctl_shift = -1, \ |
---|
920 | | - .mfpctl_width = -1, \ |
---|
921 | | - .drv_reg = PAD_DRV##reg, \ |
---|
922 | | - .drv_shift = shift, \ |
---|
923 | | - .drv_width = width, \ |
---|
924 | | - .sr_reg = -1, \ |
---|
925 | | - .sr_shift = -1, \ |
---|
926 | | - .sr_width = -1, \ |
---|
927 | | - } |
---|
928 | | - |
---|
929 | | -#define SR_PG(group_name, reg, shift, width) \ |
---|
930 | | - { \ |
---|
931 | | - .name = #group_name, \ |
---|
932 | | - .pads = group_name##_pads, \ |
---|
933 | | - .npads = ARRAY_SIZE(group_name##_pads), \ |
---|
934 | | - .mfpctl_reg = -1, \ |
---|
935 | | - .mfpctl_shift = -1, \ |
---|
936 | | - .mfpctl_width = -1, \ |
---|
937 | | - .drv_reg = -1, \ |
---|
938 | | - .drv_shift = -1, \ |
---|
939 | | - .drv_width = -1, \ |
---|
940 | | - .sr_reg = PAD_SR##reg, \ |
---|
941 | | - .sr_shift = shift, \ |
---|
942 | | - .sr_width = width, \ |
---|
943 | | - } |
---|
944 | 889 | |
---|
945 | 890 | /* Pinctrl groups */ |
---|
946 | 891 | static const struct owl_pingroup s900_groups[] = { |
---|
.. | .. |
---|
1442 | 1387 | "sirq2_dummy", |
---|
1443 | 1388 | }; |
---|
1444 | 1389 | |
---|
1445 | | -#define FUNCTION(fname) \ |
---|
1446 | | - { \ |
---|
1447 | | - .name = #fname, \ |
---|
1448 | | - .groups = fname##_groups, \ |
---|
1449 | | - .ngroups = ARRAY_SIZE(fname##_groups), \ |
---|
1450 | | - } |
---|
1451 | | - |
---|
1452 | 1390 | static const struct owl_pinmux_func s900_functions[] = { |
---|
1453 | 1391 | [S900_MUX_ERAM] = FUNCTION(eram), |
---|
1454 | 1392 | [S900_MUX_ETH_RMII] = FUNCTION(eth_rmii), |
---|
.. | .. |
---|
1500 | 1438 | [S900_MUX_SIRQ1] = FUNCTION(sirq1), |
---|
1501 | 1439 | [S900_MUX_SIRQ2] = FUNCTION(sirq2) |
---|
1502 | 1440 | }; |
---|
1503 | | -/* PAD PULL UP/DOWN CONFIGURES */ |
---|
1504 | | -#define PULLCTL_CONF(pull_reg, pull_sft, pull_wdt) \ |
---|
1505 | | - { \ |
---|
1506 | | - .reg = PAD_PULLCTL##pull_reg, \ |
---|
1507 | | - .shift = pull_sft, \ |
---|
1508 | | - .width = pull_wdt, \ |
---|
1509 | | - } |
---|
1510 | | - |
---|
1511 | | -#define PAD_PULLCTL_CONF(pad_name, pull_reg, pull_sft, pull_wdt) \ |
---|
1512 | | - struct owl_pullctl pad_name##_pullctl_conf \ |
---|
1513 | | - = PULLCTL_CONF(pull_reg, pull_sft, pull_wdt) |
---|
1514 | | - |
---|
1515 | | -#define ST_CONF(st_reg, st_sft, st_wdt) \ |
---|
1516 | | - { \ |
---|
1517 | | - .reg = PAD_ST##st_reg, \ |
---|
1518 | | - .shift = st_sft, \ |
---|
1519 | | - .width = st_wdt, \ |
---|
1520 | | - } |
---|
1521 | | - |
---|
1522 | | -#define PAD_ST_CONF(pad_name, st_reg, st_sft, st_wdt) \ |
---|
1523 | | - struct owl_st pad_name##_st_conf \ |
---|
1524 | | - = ST_CONF(st_reg, st_sft, st_wdt) |
---|
1525 | 1441 | |
---|
1526 | 1442 | /* PAD_PULLCTL0 */ |
---|
1527 | 1443 | static PAD_PULLCTL_CONF(ETH_RXER, 0, 18, 2); |
---|
.. | .. |
---|
1639 | 1555 | static PAD_ST_CONF(I2S_BCLK0, 1, 1, 1); |
---|
1640 | 1556 | static PAD_ST_CONF(I2S_MCLK0, 1, 0, 1); |
---|
1641 | 1557 | |
---|
1642 | | -#define PAD_INFO(name) \ |
---|
1643 | | - { \ |
---|
1644 | | - .pad = name, \ |
---|
1645 | | - .pullctl = NULL, \ |
---|
1646 | | - .st = NULL, \ |
---|
1647 | | - } |
---|
1648 | | - |
---|
1649 | | -#define PAD_INFO_ST(name) \ |
---|
1650 | | - { \ |
---|
1651 | | - .pad = name, \ |
---|
1652 | | - .pullctl = NULL, \ |
---|
1653 | | - .st = &name##_st_conf, \ |
---|
1654 | | - } |
---|
1655 | | - |
---|
1656 | | -#define PAD_INFO_PULLCTL(name) \ |
---|
1657 | | - { \ |
---|
1658 | | - .pad = name, \ |
---|
1659 | | - .pullctl = &name##_pullctl_conf, \ |
---|
1660 | | - .st = NULL, \ |
---|
1661 | | - } |
---|
1662 | | - |
---|
1663 | | -#define PAD_INFO_PULLCTL_ST(name) \ |
---|
1664 | | - { \ |
---|
1665 | | - .pad = name, \ |
---|
1666 | | - .pullctl = &name##_pullctl_conf, \ |
---|
1667 | | - .st = &name##_st_conf, \ |
---|
1668 | | - } |
---|
1669 | | - |
---|
1670 | 1558 | /* Pad info table */ |
---|
1671 | | -static struct owl_padinfo s900_padinfo[NUM_PADS] = { |
---|
| 1559 | +static const struct owl_padinfo s900_padinfo[NUM_PADS] = { |
---|
1672 | 1560 | [ETH_TXD0] = PAD_INFO_ST(ETH_TXD0), |
---|
1673 | 1561 | [ETH_TXD1] = PAD_INFO_ST(ETH_TXD1), |
---|
1674 | 1562 | [ETH_TXEN] = PAD_INFO_ST(ETH_TXEN), |
---|
.. | .. |
---|
1821 | 1709 | [SGPIO3] = PAD_INFO_PULLCTL_ST(SGPIO3) |
---|
1822 | 1710 | }; |
---|
1823 | 1711 | |
---|
1824 | | -#define OWL_GPIO_PORT(port, base, count, _outen, _inen, _dat, \ |
---|
1825 | | - _intc_ctl, _intc_pd, _intc_msk, _intc_type) \ |
---|
1826 | | - [OWL_GPIO_PORT_##port] = { \ |
---|
1827 | | - .offset = base, \ |
---|
1828 | | - .pins = count, \ |
---|
1829 | | - .outen = _outen, \ |
---|
1830 | | - .inen = _inen, \ |
---|
1831 | | - .dat = _dat, \ |
---|
1832 | | - .intc_ctl = _intc_ctl, \ |
---|
1833 | | - .intc_pd = _intc_pd, \ |
---|
1834 | | - .intc_msk = _intc_msk, \ |
---|
1835 | | - .intc_type = _intc_type, \ |
---|
| 1712 | +static const struct owl_gpio_port s900_gpio_ports[] = { |
---|
| 1713 | + OWL_GPIO_PORT(A, 0x0000, 32, 0x0, 0x4, 0x8, 0x204, 0x208, 0x20C, 0x240, 0), |
---|
| 1714 | + OWL_GPIO_PORT(B, 0x000C, 32, 0x0, 0x4, 0x8, 0x534, 0x204, 0x208, 0x23C, 0), |
---|
| 1715 | + OWL_GPIO_PORT(C, 0x0018, 12, 0x0, 0x4, 0x8, 0x52C, 0x200, 0x204, 0x238, 0), |
---|
| 1716 | + OWL_GPIO_PORT(D, 0x0024, 30, 0x0, 0x4, 0x8, 0x524, 0x1FC, 0x200, 0x234, 0), |
---|
| 1717 | + OWL_GPIO_PORT(E, 0x0030, 32, 0x0, 0x4, 0x8, 0x51C, 0x1F8, 0x1FC, 0x230, 0), |
---|
| 1718 | + OWL_GPIO_PORT(F, 0x00F0, 8, 0x0, 0x4, 0x8, 0x460, 0x140, 0x144, 0x178, 0) |
---|
| 1719 | +}; |
---|
| 1720 | + |
---|
| 1721 | +enum s900_pinconf_pull { |
---|
| 1722 | + OWL_PINCONF_PULL_HIZ, |
---|
| 1723 | + OWL_PINCONF_PULL_DOWN, |
---|
| 1724 | + OWL_PINCONF_PULL_UP, |
---|
| 1725 | + OWL_PINCONF_PULL_HOLD, |
---|
| 1726 | +}; |
---|
| 1727 | + |
---|
| 1728 | +static int s900_pad_pinconf_arg2val(const struct owl_padinfo *info, |
---|
| 1729 | + unsigned int param, |
---|
| 1730 | + u32 *arg) |
---|
| 1731 | +{ |
---|
| 1732 | + switch (param) { |
---|
| 1733 | + case PIN_CONFIG_BIAS_BUS_HOLD: |
---|
| 1734 | + *arg = OWL_PINCONF_PULL_HOLD; |
---|
| 1735 | + break; |
---|
| 1736 | + case PIN_CONFIG_BIAS_HIGH_IMPEDANCE: |
---|
| 1737 | + *arg = OWL_PINCONF_PULL_HIZ; |
---|
| 1738 | + break; |
---|
| 1739 | + case PIN_CONFIG_BIAS_PULL_DOWN: |
---|
| 1740 | + *arg = OWL_PINCONF_PULL_DOWN; |
---|
| 1741 | + break; |
---|
| 1742 | + case PIN_CONFIG_BIAS_PULL_UP: |
---|
| 1743 | + *arg = OWL_PINCONF_PULL_UP; |
---|
| 1744 | + break; |
---|
| 1745 | + case PIN_CONFIG_INPUT_SCHMITT_ENABLE: |
---|
| 1746 | + *arg = (*arg >= 1 ? 1 : 0); |
---|
| 1747 | + break; |
---|
| 1748 | + default: |
---|
| 1749 | + return -ENOTSUPP; |
---|
1836 | 1750 | } |
---|
1837 | 1751 | |
---|
1838 | | -static const struct owl_gpio_port s900_gpio_ports[] = { |
---|
1839 | | - OWL_GPIO_PORT(A, 0x0000, 32, 0x0, 0x4, 0x8, 0x204, 0x208, 0x20C, 0x240), |
---|
1840 | | - OWL_GPIO_PORT(B, 0x000C, 32, 0x0, 0x4, 0x8, 0x534, 0x204, 0x208, 0x23C), |
---|
1841 | | - OWL_GPIO_PORT(C, 0x0018, 12, 0x0, 0x4, 0x8, 0x52C, 0x200, 0x204, 0x238), |
---|
1842 | | - OWL_GPIO_PORT(D, 0x0024, 30, 0x0, 0x4, 0x8, 0x524, 0x1FC, 0x200, 0x234), |
---|
1843 | | - OWL_GPIO_PORT(E, 0x0030, 32, 0x0, 0x4, 0x8, 0x51C, 0x1F8, 0x1FC, 0x230), |
---|
1844 | | - OWL_GPIO_PORT(F, 0x00F0, 8, 0x0, 0x4, 0x8, 0x460, 0x140, 0x144, 0x178) |
---|
1845 | | -}; |
---|
| 1752 | + return 0; |
---|
| 1753 | +} |
---|
| 1754 | + |
---|
| 1755 | +static int s900_pad_pinconf_val2arg(const struct owl_padinfo *padinfo, |
---|
| 1756 | + unsigned int param, |
---|
| 1757 | + u32 *arg) |
---|
| 1758 | +{ |
---|
| 1759 | + switch (param) { |
---|
| 1760 | + case PIN_CONFIG_BIAS_BUS_HOLD: |
---|
| 1761 | + *arg = *arg == OWL_PINCONF_PULL_HOLD; |
---|
| 1762 | + break; |
---|
| 1763 | + case PIN_CONFIG_BIAS_HIGH_IMPEDANCE: |
---|
| 1764 | + *arg = *arg == OWL_PINCONF_PULL_HIZ; |
---|
| 1765 | + break; |
---|
| 1766 | + case PIN_CONFIG_BIAS_PULL_DOWN: |
---|
| 1767 | + *arg = *arg == OWL_PINCONF_PULL_DOWN; |
---|
| 1768 | + break; |
---|
| 1769 | + case PIN_CONFIG_BIAS_PULL_UP: |
---|
| 1770 | + *arg = *arg == OWL_PINCONF_PULL_UP; |
---|
| 1771 | + break; |
---|
| 1772 | + case PIN_CONFIG_INPUT_SCHMITT_ENABLE: |
---|
| 1773 | + *arg = *arg == 1; |
---|
| 1774 | + break; |
---|
| 1775 | + default: |
---|
| 1776 | + return -ENOTSUPP; |
---|
| 1777 | + } |
---|
| 1778 | + |
---|
| 1779 | + return 0; |
---|
| 1780 | +} |
---|
1846 | 1781 | |
---|
1847 | 1782 | static struct owl_pinctrl_soc_data s900_pinctrl_data = { |
---|
1848 | 1783 | .padinfo = s900_padinfo, |
---|
.. | .. |
---|
1854 | 1789 | .ngroups = ARRAY_SIZE(s900_groups), |
---|
1855 | 1790 | .ngpios = NUM_GPIOS, |
---|
1856 | 1791 | .ports = s900_gpio_ports, |
---|
1857 | | - .nports = ARRAY_SIZE(s900_gpio_ports) |
---|
| 1792 | + .nports = ARRAY_SIZE(s900_gpio_ports), |
---|
| 1793 | + .padctl_arg2val = s900_pad_pinconf_arg2val, |
---|
| 1794 | + .padctl_val2arg = s900_pad_pinconf_val2arg, |
---|
1858 | 1795 | }; |
---|
1859 | 1796 | |
---|
1860 | 1797 | static int s900_pinctrl_probe(struct platform_device *pdev) |
---|