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