Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2016 - Beniamino Galvani <b.galvani@gmail.com> |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef __PINCTRL_MESON_H__ |
| 7 | #define __PINCTRL_MESON_H__ |
| 8 | |
| 9 | #include <linux/types.h> |
| 10 | |
| 11 | struct meson_pmx_group { |
| 12 | const char *name; |
| 13 | const unsigned int *pins; |
| 14 | unsigned int num_pins; |
Jerome Brunet | 707bff4 | 2018-10-05 09:35:26 +0200 | [diff] [blame] | 15 | const void *data; |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 16 | }; |
| 17 | |
| 18 | struct meson_pmx_func { |
| 19 | const char *name; |
| 20 | const char * const *groups; |
| 21 | unsigned int num_groups; |
| 22 | }; |
| 23 | |
| 24 | struct meson_pinctrl_data { |
| 25 | const char *name; |
| 26 | struct meson_pmx_group *groups; |
| 27 | struct meson_pmx_func *funcs; |
Beniamino Galvani | 5aeb135 | 2017-07-10 00:30:04 +0200 | [diff] [blame] | 28 | struct meson_bank *banks; |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 29 | unsigned int pin_base; |
| 30 | unsigned int num_pins; |
| 31 | unsigned int num_groups; |
| 32 | unsigned int num_funcs; |
Beniamino Galvani | 5aeb135 | 2017-07-10 00:30:04 +0200 | [diff] [blame] | 33 | unsigned int num_banks; |
Jerome Brunet | 707bff4 | 2018-10-05 09:35:26 +0200 | [diff] [blame] | 34 | const struct driver *gpio_driver; |
| 35 | void *pmx_data; |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | struct meson_pinctrl { |
| 39 | struct meson_pinctrl_data *data; |
| 40 | void __iomem *reg_mux; |
Beniamino Galvani | 5aeb135 | 2017-07-10 00:30:04 +0200 | [diff] [blame] | 41 | void __iomem *reg_gpio; |
Jerome Brunet | 8702199 | 2019-01-04 15:44:34 +0100 | [diff] [blame] | 42 | void __iomem *reg_pull; |
| 43 | void __iomem *reg_pullen; |
Jerome Brunet | 0ff3cd0 | 2019-02-08 17:40:57 +0100 | [diff] [blame] | 44 | void __iomem *reg_ds; |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 45 | }; |
| 46 | |
Beniamino Galvani | 5aeb135 | 2017-07-10 00:30:04 +0200 | [diff] [blame] | 47 | /** |
| 48 | * struct meson_reg_desc - a register descriptor |
| 49 | * |
| 50 | * @reg: register offset in the regmap |
| 51 | * @bit: bit index in register |
| 52 | * |
| 53 | * The structure describes the information needed to control pull, |
| 54 | * pull-enable, direction, etc. for a single pin |
| 55 | */ |
| 56 | struct meson_reg_desc { |
| 57 | unsigned int reg; |
| 58 | unsigned int bit; |
| 59 | }; |
| 60 | |
| 61 | /** |
| 62 | * enum meson_reg_type - type of registers encoded in @meson_reg_desc |
| 63 | */ |
| 64 | enum meson_reg_type { |
| 65 | REG_PULLEN, |
| 66 | REG_PULL, |
| 67 | REG_DIR, |
| 68 | REG_OUT, |
| 69 | REG_IN, |
| 70 | NUM_REG, |
| 71 | }; |
| 72 | |
| 73 | /** |
| 74 | * struct meson bank |
| 75 | * |
| 76 | * @name: bank name |
| 77 | * @first: first pin of the bank |
| 78 | * @last: last pin of the bank |
| 79 | * @regs: array of register descriptors |
| 80 | * |
| 81 | * A bank represents a set of pins controlled by a contiguous set of |
| 82 | * bits in the domain registers. The structure specifies which bits in |
| 83 | * the regmap control the different functionalities. Each member of |
| 84 | * the @regs array refers to the first pin of the bank. |
| 85 | */ |
| 86 | struct meson_bank { |
| 87 | const char *name; |
| 88 | unsigned int first; |
| 89 | unsigned int last; |
| 90 | struct meson_reg_desc regs[NUM_REG]; |
| 91 | }; |
| 92 | |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 93 | #define PIN(x, b) (b + x) |
| 94 | |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 95 | #define FUNCTION(fn) \ |
| 96 | { \ |
| 97 | .name = #fn, \ |
| 98 | .groups = fn ## _groups, \ |
| 99 | .num_groups = ARRAY_SIZE(fn ## _groups), \ |
| 100 | } |
| 101 | |
Beniamino Galvani | 5aeb135 | 2017-07-10 00:30:04 +0200 | [diff] [blame] | 102 | #define BANK(n, f, l, per, peb, pr, pb, dr, db, or, ob, ir, ib) \ |
| 103 | { \ |
| 104 | .name = n, \ |
| 105 | .first = f, \ |
| 106 | .last = l, \ |
| 107 | .regs = { \ |
| 108 | [REG_PULLEN] = { per, peb }, \ |
| 109 | [REG_PULL] = { pr, pb }, \ |
| 110 | [REG_DIR] = { dr, db }, \ |
| 111 | [REG_OUT] = { or, ob }, \ |
| 112 | [REG_IN] = { ir, ib }, \ |
| 113 | }, \ |
| 114 | } |
| 115 | |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 116 | #define MESON_PIN(x, b) PINCTRL_PIN(PIN(x, b), #x) |
| 117 | |
| 118 | extern const struct pinctrl_ops meson_pinctrl_ops; |
| 119 | |
Jerome Brunet | 707bff4 | 2018-10-05 09:35:26 +0200 | [diff] [blame] | 120 | int meson_pinctrl_get_groups_count(struct udevice *dev); |
| 121 | const char *meson_pinctrl_get_group_name(struct udevice *dev, |
| 122 | unsigned int selector); |
Neil Armstrong | a5ea157 | 2019-06-04 11:04:52 +0200 | [diff] [blame^] | 123 | int meson_pinctrl_get_pins_count(struct udevice *dev); |
| 124 | const char *meson_pinctrl_get_pin_name(struct udevice *dev, |
| 125 | unsigned int selector); |
Jerome Brunet | 707bff4 | 2018-10-05 09:35:26 +0200 | [diff] [blame] | 126 | int meson_pinmux_get_functions_count(struct udevice *dev); |
| 127 | const char *meson_pinmux_get_function_name(struct udevice *dev, |
| 128 | unsigned int selector); |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 129 | int meson_pinctrl_probe(struct udevice *dev); |
| 130 | |
Jerome Brunet | 707bff4 | 2018-10-05 09:35:26 +0200 | [diff] [blame] | 131 | int meson_gpio_get(struct udevice *dev, unsigned int offset); |
| 132 | int meson_gpio_set(struct udevice *dev, unsigned int offset, int value); |
| 133 | int meson_gpio_get_direction(struct udevice *dev, unsigned int offset); |
| 134 | int meson_gpio_direction_input(struct udevice *dev, unsigned int offset); |
| 135 | int meson_gpio_direction_output(struct udevice *dev, unsigned int offset, |
| 136 | int value); |
| 137 | int meson_gpio_probe(struct udevice *dev); |
| 138 | |
Jerome Brunet | 8702199 | 2019-01-04 15:44:34 +0100 | [diff] [blame] | 139 | int meson_pinconf_set(struct udevice *dev, unsigned int pin, |
| 140 | unsigned int param, unsigned int arg); |
| 141 | int meson_pinconf_group_set(struct udevice *dev, |
| 142 | unsigned int group_selector, |
| 143 | unsigned int param, unsigned int arg); |
| 144 | |
Beniamino Galvani | 2176d73 | 2016-08-16 11:49:49 +0200 | [diff] [blame] | 145 | #endif /* __PINCTRL_MESON_H__ */ |