Beniamino Galvani | 6ac7309 | 2015-01-17 19:15:14 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Pin controller and GPIO driver for Amlogic Meson SoCs |
| 3 | * |
| 4 | * Copyright (C) 2014 Beniamino Galvani <b.galvani@gmail.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * version 2 as published by the Free Software Foundation. |
| 9 | * |
| 10 | * You should have received a copy of the GNU General Public License |
| 11 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 12 | */ |
| 13 | |
Linus Walleij | 1c5fb66 | 2018-09-13 13:58:21 +0200 | [diff] [blame] | 14 | #include <linux/gpio/driver.h> |
Beniamino Galvani | 6ac7309 | 2015-01-17 19:15:14 +0100 | [diff] [blame] | 15 | #include <linux/pinctrl/pinctrl.h> |
Jerome Brunet | 277d14e | 2017-10-12 14:40:25 +0200 | [diff] [blame] | 16 | #include <linux/platform_device.h> |
Beniamino Galvani | 6ac7309 | 2015-01-17 19:15:14 +0100 | [diff] [blame] | 17 | #include <linux/regmap.h> |
| 18 | #include <linux/types.h> |
| 19 | |
| 20 | /** |
| 21 | * struct meson_pmx_group - a pinmux group |
| 22 | * |
| 23 | * @name: group name |
| 24 | * @pins: pins in the group |
| 25 | * @num_pins: number of pins in the group |
| 26 | * @is_gpio: whether the group is a single GPIO group |
| 27 | * @reg: register offset for the group in the domain mux registers |
| 28 | * @bit bit index enabling the group |
| 29 | * @domain: index of the domain this group belongs to |
| 30 | */ |
| 31 | struct meson_pmx_group { |
| 32 | const char *name; |
| 33 | const unsigned int *pins; |
| 34 | unsigned int num_pins; |
Jerome Brunet | ce385aa | 2017-10-12 14:40:26 +0200 | [diff] [blame] | 35 | const void *data; |
Beniamino Galvani | 6ac7309 | 2015-01-17 19:15:14 +0100 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | /** |
| 39 | * struct meson_pmx_func - a pinmux function |
| 40 | * |
| 41 | * @name: function name |
| 42 | * @groups: groups in the function |
| 43 | * @num_groups: number of groups in the function |
| 44 | */ |
| 45 | struct meson_pmx_func { |
| 46 | const char *name; |
| 47 | const char * const *groups; |
| 48 | unsigned int num_groups; |
| 49 | }; |
| 50 | |
| 51 | /** |
| 52 | * struct meson_reg_desc - a register descriptor |
| 53 | * |
| 54 | * @reg: register offset in the regmap |
| 55 | * @bit: bit index in register |
| 56 | * |
| 57 | * The structure describes the information needed to control pull, |
| 58 | * pull-enable, direction, etc. for a single pin |
| 59 | */ |
| 60 | struct meson_reg_desc { |
| 61 | unsigned int reg; |
| 62 | unsigned int bit; |
| 63 | }; |
| 64 | |
| 65 | /** |
| 66 | * enum meson_reg_type - type of registers encoded in @meson_reg_desc |
| 67 | */ |
| 68 | enum meson_reg_type { |
| 69 | REG_PULLEN, |
| 70 | REG_PULL, |
| 71 | REG_DIR, |
| 72 | REG_OUT, |
| 73 | REG_IN, |
Guillaume La Roque | 6ea3e3b | 2019-05-14 10:26:51 +0200 | [diff] [blame^] | 74 | REG_DS, |
Beniamino Galvani | 6ac7309 | 2015-01-17 19:15:14 +0100 | [diff] [blame] | 75 | NUM_REG, |
| 76 | }; |
| 77 | |
| 78 | /** |
Guillaume La Roque | 6ea3e3b | 2019-05-14 10:26:51 +0200 | [diff] [blame^] | 79 | * enum meson_pinconf_drv - value of drive-strength supported |
| 80 | */ |
| 81 | enum meson_pinconf_drv { |
| 82 | MESON_PINCONF_DRV_500UA, |
| 83 | MESON_PINCONF_DRV_2500UA, |
| 84 | MESON_PINCONF_DRV_3000UA, |
| 85 | MESON_PINCONF_DRV_4000UA, |
| 86 | }; |
| 87 | |
| 88 | /** |
Beniamino Galvani | 6ac7309 | 2015-01-17 19:15:14 +0100 | [diff] [blame] | 89 | * struct meson bank |
| 90 | * |
| 91 | * @name: bank name |
| 92 | * @first: first pin of the bank |
| 93 | * @last: last pin of the bank |
Jerome Brunet | 6c9dc84 | 2017-06-08 21:37:50 +0200 | [diff] [blame] | 94 | * @irq: hwirq base number of the bank |
Beniamino Galvani | 6ac7309 | 2015-01-17 19:15:14 +0100 | [diff] [blame] | 95 | * @regs: array of register descriptors |
| 96 | * |
| 97 | * A bank represents a set of pins controlled by a contiguous set of |
| 98 | * bits in the domain registers. The structure specifies which bits in |
| 99 | * the regmap control the different functionalities. Each member of |
| 100 | * the @regs array refers to the first pin of the bank. |
| 101 | */ |
| 102 | struct meson_bank { |
| 103 | const char *name; |
| 104 | unsigned int first; |
| 105 | unsigned int last; |
Jerome Brunet | 6c9dc84 | 2017-06-08 21:37:50 +0200 | [diff] [blame] | 106 | int irq_first; |
| 107 | int irq_last; |
Beniamino Galvani | 6ac7309 | 2015-01-17 19:15:14 +0100 | [diff] [blame] | 108 | struct meson_reg_desc regs[NUM_REG]; |
| 109 | }; |
| 110 | |
Beniamino Galvani | 6ac7309 | 2015-01-17 19:15:14 +0100 | [diff] [blame] | 111 | struct meson_pinctrl_data { |
Beniamino Galvani | db80f0e | 2016-08-13 19:41:18 +0200 | [diff] [blame] | 112 | const char *name; |
Beniamino Galvani | 6ac7309 | 2015-01-17 19:15:14 +0100 | [diff] [blame] | 113 | const struct pinctrl_pin_desc *pins; |
| 114 | struct meson_pmx_group *groups; |
| 115 | struct meson_pmx_func *funcs; |
Beniamino Galvani | 6ac7309 | 2015-01-17 19:15:14 +0100 | [diff] [blame] | 116 | unsigned int num_pins; |
| 117 | unsigned int num_groups; |
| 118 | unsigned int num_funcs; |
Beniamino Galvani | db80f0e | 2016-08-13 19:41:18 +0200 | [diff] [blame] | 119 | struct meson_bank *banks; |
| 120 | unsigned int num_banks; |
Jerome Brunet | ce385aa | 2017-10-12 14:40:26 +0200 | [diff] [blame] | 121 | const struct pinmux_ops *pmx_ops; |
Xingyu Chen | 0fabe43 | 2017-11-20 18:08:24 +0800 | [diff] [blame] | 122 | void *pmx_data; |
Beniamino Galvani | 6ac7309 | 2015-01-17 19:15:14 +0100 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | struct meson_pinctrl { |
| 126 | struct device *dev; |
| 127 | struct pinctrl_dev *pcdev; |
| 128 | struct pinctrl_desc desc; |
| 129 | struct meson_pinctrl_data *data; |
Beniamino Galvani | db80f0e | 2016-08-13 19:41:18 +0200 | [diff] [blame] | 130 | struct regmap *reg_mux; |
| 131 | struct regmap *reg_pullen; |
| 132 | struct regmap *reg_pull; |
| 133 | struct regmap *reg_gpio; |
Jerome Brunet | 6485697 | 2019-01-17 11:23:15 +0100 | [diff] [blame] | 134 | struct regmap *reg_ds; |
Beniamino Galvani | db80f0e | 2016-08-13 19:41:18 +0200 | [diff] [blame] | 135 | struct gpio_chip chip; |
| 136 | struct device_node *of_node; |
Beniamino Galvani | 6ac7309 | 2015-01-17 19:15:14 +0100 | [diff] [blame] | 137 | }; |
| 138 | |
Beniamino Galvani | 6ac7309 | 2015-01-17 19:15:14 +0100 | [diff] [blame] | 139 | #define FUNCTION(fn) \ |
| 140 | { \ |
| 141 | .name = #fn, \ |
| 142 | .groups = fn ## _groups, \ |
| 143 | .num_groups = ARRAY_SIZE(fn ## _groups), \ |
| 144 | } |
| 145 | |
Guillaume La Roque | 6ea3e3b | 2019-05-14 10:26:51 +0200 | [diff] [blame^] | 146 | #define BANK_DS(n, f, l, fi, li, per, peb, pr, pb, dr, db, or, ob, ir, ib, \ |
| 147 | dsr, dsb) \ |
Beniamino Galvani | 6ac7309 | 2015-01-17 19:15:14 +0100 | [diff] [blame] | 148 | { \ |
Jerome Brunet | 6c9dc84 | 2017-06-08 21:37:50 +0200 | [diff] [blame] | 149 | .name = n, \ |
| 150 | .first = f, \ |
| 151 | .last = l, \ |
| 152 | .irq_first = fi, \ |
| 153 | .irq_last = li, \ |
| 154 | .regs = { \ |
Beniamino Galvani | 6ac7309 | 2015-01-17 19:15:14 +0100 | [diff] [blame] | 155 | [REG_PULLEN] = { per, peb }, \ |
| 156 | [REG_PULL] = { pr, pb }, \ |
| 157 | [REG_DIR] = { dr, db }, \ |
| 158 | [REG_OUT] = { or, ob }, \ |
| 159 | [REG_IN] = { ir, ib }, \ |
Guillaume La Roque | 6ea3e3b | 2019-05-14 10:26:51 +0200 | [diff] [blame^] | 160 | [REG_DS] = { dsr, dsb }, \ |
Beniamino Galvani | 6ac7309 | 2015-01-17 19:15:14 +0100 | [diff] [blame] | 161 | }, \ |
| 162 | } |
| 163 | |
Guillaume La Roque | 6ea3e3b | 2019-05-14 10:26:51 +0200 | [diff] [blame^] | 164 | #define BANK(n, f, l, fi, li, per, peb, pr, pb, dr, db, or, ob, ir, ib) \ |
| 165 | BANK_DS(n, f, l, fi, li, per, peb, pr, pb, dr, db, or, ob, ir, ib, 0, 0) |
| 166 | |
Jerome Brunet | 634e40b | 2017-09-20 15:39:20 +0200 | [diff] [blame] | 167 | #define MESON_PIN(x) PINCTRL_PIN(x, #x) |
Beniamino Galvani | 6ac7309 | 2015-01-17 19:15:14 +0100 | [diff] [blame] | 168 | |
Jerome Brunet | ce385aa | 2017-10-12 14:40:26 +0200 | [diff] [blame] | 169 | /* Common pmx functions */ |
| 170 | int meson_pmx_get_funcs_count(struct pinctrl_dev *pcdev); |
| 171 | const char *meson_pmx_get_func_name(struct pinctrl_dev *pcdev, |
| 172 | unsigned selector); |
| 173 | int meson_pmx_get_groups(struct pinctrl_dev *pcdev, |
| 174 | unsigned selector, |
| 175 | const char * const **groups, |
| 176 | unsigned * const num_groups); |
| 177 | |
Jerome Brunet | 277d14e | 2017-10-12 14:40:25 +0200 | [diff] [blame] | 178 | /* Common probe function */ |
| 179 | int meson_pinctrl_probe(struct platform_device *pdev); |