Masahiro Yamada | 5dc626f | 2015-09-11 20:17:32 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 Masahiro Yamada <yamada.masahiro@socionext.com> |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #ifndef __PINCTRL_UNIPHIER_H__ |
| 8 | #define __PINCTRL_UNIPHIER_H__ |
| 9 | |
| 10 | /* TODO: move this to include/linux/bug.h */ |
| 11 | #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) |
| 12 | |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/types.h> |
| 15 | |
| 16 | #define UNIPHIER_PINCTRL_PINMUX_BASE 0x0 |
| 17 | #define UNIPHIER_PINCTRL_LOAD_PINMUX 0x700 |
| 18 | #define UNIPHIER_PINCTRL_IECTRL 0xd00 |
| 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; |
| 50 | const unsigned *muxvals; |
| 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 |
| 64 | * @load_pinctrl: if true, LOAD_PINMUX register must be set to one for new |
| 65 | * values in pinmux registers to become really effective |
| 66 | */ |
| 67 | struct uniphier_pinctrl_socdata { |
| 68 | const struct uniphier_pinctrl_pin *pins; |
| 69 | int pins_count; |
| 70 | const struct uniphier_pinctrl_group *groups; |
| 71 | int groups_count; |
| 72 | const char * const *functions; |
| 73 | int functions_count; |
| 74 | unsigned mux_bits; |
| 75 | unsigned reg_stride; |
| 76 | bool load_pinctrl; |
| 77 | }; |
| 78 | |
| 79 | #define UNIPHIER_PINCTRL_PIN(a, b) \ |
| 80 | { \ |
| 81 | .number = a, \ |
| 82 | .data = UNIPHIER_PIN_ATTR_PACKED(b), \ |
| 83 | } |
| 84 | |
| 85 | #define UNIPHIER_PINCTRL_GROUP(grp) \ |
| 86 | { \ |
| 87 | .name = #grp, \ |
| 88 | .pins = grp##_pins, \ |
| 89 | .num_pins = ARRAY_SIZE(grp##_pins), \ |
| 90 | .muxvals = grp##_muxvals + \ |
| 91 | BUILD_BUG_ON_ZERO(ARRAY_SIZE(grp##_pins) != \ |
| 92 | ARRAY_SIZE(grp##_muxvals)), \ |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * struct uniphier_pinctrl_priv - private data for UniPhier pinctrl driver |
| 97 | * |
| 98 | * @base: base address of the pinctrl device |
| 99 | * @socdata: SoC specific data |
| 100 | */ |
| 101 | struct uniphier_pinctrl_priv { |
| 102 | void __iomem *base; |
| 103 | struct uniphier_pinctrl_socdata *socdata; |
| 104 | }; |
| 105 | |
| 106 | extern const struct pinctrl_ops uniphier_pinctrl_ops; |
| 107 | |
| 108 | int uniphier_pinctrl_probe(struct udevice *dev, |
| 109 | struct uniphier_pinctrl_socdata *socdata); |
| 110 | |
| 111 | int uniphier_pinctrl_remove(struct udevice *dev); |
| 112 | |
| 113 | #endif /* __PINCTRL_UNIPHIER_H__ */ |