Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 2 | /* |
Masahiro Yamada | fa1f73f | 2016-07-19 21:56:13 +0900 | [diff] [blame] | 3 | * Copyright (C) 2015-2016 Socionext Inc. |
| 4 | * Author: Masahiro Yamada <yamada.masahiro@socionext.com> |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef __PINCTRL_UNIPHIER_H__ |
| 8 | #define __PINCTRL_UNIPHIER_H__ |
| 9 | |
Masahiro Yamada | 7a629ef | 2016-03-24 22:32:44 +0900 | [diff] [blame] | 10 | #include <linux/bitops.h> |
Masahiro Yamada | 17ca7f2 | 2018-05-05 19:53:53 +0900 | [diff] [blame^] | 11 | #include <linux/build_bug.h> |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 12 | #include <linux/kernel.h> |
| 13 | #include <linux/types.h> |
| 14 | |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 15 | #define UNIPHIER_PIN_ATTR_PACKED(iectrl) (iectrl) |
| 16 | |
| 17 | static inline unsigned int uniphier_pin_get_iectrl(unsigned long data) |
| 18 | { |
| 19 | return data; |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * struct uniphier_pinctrl_pin - pin data for UniPhier SoC |
| 24 | * |
| 25 | * @number: pin number |
| 26 | * @data: additional per-pin data |
| 27 | */ |
| 28 | struct uniphier_pinctrl_pin { |
| 29 | unsigned number; |
| 30 | unsigned long data; |
| 31 | }; |
| 32 | |
| 33 | /** |
| 34 | * struct uniphier_pinctrl_group - pin group data for UniPhier SoC |
| 35 | * |
| 36 | * @name: pin group name |
| 37 | * @pins: array of pins that belong to the group |
| 38 | * @num_pins: number of pins in the group |
| 39 | * @muxvals: array of values to be set to pinmux registers |
| 40 | */ |
| 41 | struct uniphier_pinctrl_group { |
| 42 | const char *name; |
| 43 | const unsigned *pins; |
| 44 | unsigned num_pins; |
Masahiro Yamada | 9447e13 | 2016-06-29 19:38:59 +0900 | [diff] [blame] | 45 | const int *muxvals; |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | /** |
| 49 | * struct uniphier_pinctrl_socdata - SoC data for UniPhier pin controller |
| 50 | * |
| 51 | * @pins: array of pin data |
| 52 | * @pins_count: number of pin data |
| 53 | * @groups: array of pin group data |
| 54 | * @groups_count: number of pin group data |
| 55 | * @functions: array of pinmux function names |
| 56 | * @functions_count: number of pinmux functions |
| 57 | * @mux_bits: bit width of each pinmux register |
| 58 | * @reg_stride: stride of pinmux register address |
Masahiro Yamada | 7a629ef | 2016-03-24 22:32:44 +0900 | [diff] [blame] | 59 | * @caps: SoC-specific capability flag |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 60 | */ |
| 61 | struct uniphier_pinctrl_socdata { |
| 62 | const struct uniphier_pinctrl_pin *pins; |
| 63 | int pins_count; |
| 64 | const struct uniphier_pinctrl_group *groups; |
| 65 | int groups_count; |
| 66 | const char * const *functions; |
| 67 | int functions_count; |
Masahiro Yamada | 7a629ef | 2016-03-24 22:32:44 +0900 | [diff] [blame] | 68 | unsigned caps; |
Masahiro Yamada | 140e9f1 | 2017-02-12 18:21:15 +0900 | [diff] [blame] | 69 | #define UNIPHIER_PINCTRL_CAPS_PUPD_SIMPLE BIT(3) |
Masahiro Yamada | c3380ed | 2016-09-17 03:32:58 +0900 | [diff] [blame] | 70 | #define UNIPHIER_PINCTRL_CAPS_PERPIN_IECTRL BIT(2) |
| 71 | #define UNIPHIER_PINCTRL_CAPS_DBGMUX_SEPARATE BIT(1) |
| 72 | #define UNIPHIER_PINCTRL_CAPS_MUX_4BIT BIT(0) |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | #define UNIPHIER_PINCTRL_PIN(a, b) \ |
| 76 | { \ |
| 77 | .number = a, \ |
| 78 | .data = UNIPHIER_PIN_ATTR_PACKED(b), \ |
| 79 | } |
| 80 | |
Masahiro Yamada | 65ef4f7 | 2016-06-29 19:39:00 +0900 | [diff] [blame] | 81 | #define __UNIPHIER_PINCTRL_GROUP(grp) \ |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 82 | { \ |
| 83 | .name = #grp, \ |
| 84 | .pins = grp##_pins, \ |
| 85 | .num_pins = ARRAY_SIZE(grp##_pins), \ |
| 86 | .muxvals = grp##_muxvals + \ |
| 87 | BUILD_BUG_ON_ZERO(ARRAY_SIZE(grp##_pins) != \ |
| 88 | ARRAY_SIZE(grp##_muxvals)), \ |
| 89 | } |
| 90 | |
Masahiro Yamada | 65ef4f7 | 2016-06-29 19:39:00 +0900 | [diff] [blame] | 91 | #define __UNIPHIER_PINMUX_FUNCTION(func) #func |
| 92 | |
| 93 | #ifdef CONFIG_SPL_BUILD |
Masahiro Yamada | 945c470 | 2016-10-09 23:52:57 +0900 | [diff] [blame] | 94 | /* |
| 95 | * a tricky way to drop unneeded *_pins and *_muxvals arrays from SPL, |
| 96 | * suppressing "defined but not used" warnings. |
| 97 | */ |
| 98 | #define UNIPHIER_PINCTRL_GROUP(grp) \ |
| 99 | { .num_pins = ARRAY_SIZE(grp##_pins) + ARRAY_SIZE(grp##_muxvals) } |
Masahiro Yamada | 65ef4f7 | 2016-06-29 19:39:00 +0900 | [diff] [blame] | 100 | #define UNIPHIER_PINMUX_FUNCTION(func) NULL |
| 101 | #else |
| 102 | #define UNIPHIER_PINCTRL_GROUP(grp) __UNIPHIER_PINCTRL_GROUP(grp) |
| 103 | #define UNIPHIER_PINMUX_FUNCTION(func) __UNIPHIER_PINMUX_FUNCTION(func) |
| 104 | #endif |
| 105 | |
| 106 | #define UNIPHIER_PINCTRL_GROUP_SPL(grp) __UNIPHIER_PINCTRL_GROUP(grp) |
| 107 | #define UNIPHIER_PINMUX_FUNCTION_SPL(func) __UNIPHIER_PINMUX_FUNCTION(func) |
| 108 | |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 109 | /** |
| 110 | * struct uniphier_pinctrl_priv - private data for UniPhier pinctrl driver |
| 111 | * |
| 112 | * @base: base address of the pinctrl device |
| 113 | * @socdata: SoC specific data |
| 114 | */ |
| 115 | struct uniphier_pinctrl_priv { |
| 116 | void __iomem *base; |
| 117 | struct uniphier_pinctrl_socdata *socdata; |
| 118 | }; |
| 119 | |
| 120 | extern const struct pinctrl_ops uniphier_pinctrl_ops; |
| 121 | |
| 122 | int uniphier_pinctrl_probe(struct udevice *dev, |
| 123 | struct uniphier_pinctrl_socdata *socdata); |
| 124 | |
Masahiro Yamada | 847e618b8 | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 125 | #endif /* __PINCTRL_UNIPHIER_H__ */ |