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 14 #include <linux/gpio.h> 15 #include <linux/pinctrl/pinctrl.h> 16 #include <linux/platform_device.h> 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; 35 bool is_gpio; 36 unsigned int reg; 37 unsigned int bit; 38 }; 39 40 /** 41 * struct meson_pmx_func - a pinmux function 42 * 43 * @name: function name 44 * @groups: groups in the function 45 * @num_groups: number of groups in the function 46 */ 47 struct meson_pmx_func { 48 const char *name; 49 const char * const *groups; 50 unsigned int num_groups; 51 }; 52 53 /** 54 * struct meson_reg_desc - a register descriptor 55 * 56 * @reg: register offset in the regmap 57 * @bit: bit index in register 58 * 59 * The structure describes the information needed to control pull, 60 * pull-enable, direction, etc. for a single pin 61 */ 62 struct meson_reg_desc { 63 unsigned int reg; 64 unsigned int bit; 65 }; 66 67 /** 68 * enum meson_reg_type - type of registers encoded in @meson_reg_desc 69 */ 70 enum meson_reg_type { 71 REG_PULLEN, 72 REG_PULL, 73 REG_DIR, 74 REG_OUT, 75 REG_IN, 76 NUM_REG, 77 }; 78 79 /** 80 * struct meson bank 81 * 82 * @name: bank name 83 * @first: first pin of the bank 84 * @last: last pin of the bank 85 * @irq: hwirq base number of the bank 86 * @regs: array of register descriptors 87 * 88 * A bank represents a set of pins controlled by a contiguous set of 89 * bits in the domain registers. The structure specifies which bits in 90 * the regmap control the different functionalities. Each member of 91 * the @regs array refers to the first pin of the bank. 92 */ 93 struct meson_bank { 94 const char *name; 95 unsigned int first; 96 unsigned int last; 97 int irq_first; 98 int irq_last; 99 struct meson_reg_desc regs[NUM_REG]; 100 }; 101 102 struct meson_pinctrl_data { 103 const char *name; 104 const struct pinctrl_pin_desc *pins; 105 struct meson_pmx_group *groups; 106 struct meson_pmx_func *funcs; 107 unsigned int num_pins; 108 unsigned int num_groups; 109 unsigned int num_funcs; 110 struct meson_bank *banks; 111 unsigned int num_banks; 112 }; 113 114 struct meson_pinctrl { 115 struct device *dev; 116 struct pinctrl_dev *pcdev; 117 struct pinctrl_desc desc; 118 struct meson_pinctrl_data *data; 119 struct regmap *reg_mux; 120 struct regmap *reg_pullen; 121 struct regmap *reg_pull; 122 struct regmap *reg_gpio; 123 struct gpio_chip chip; 124 struct device_node *of_node; 125 }; 126 127 #define GROUP(grp, r, b) \ 128 { \ 129 .name = #grp, \ 130 .pins = grp ## _pins, \ 131 .num_pins = ARRAY_SIZE(grp ## _pins), \ 132 .reg = r, \ 133 .bit = b, \ 134 } 135 136 #define GPIO_GROUP(gpio) \ 137 { \ 138 .name = #gpio, \ 139 .pins = (const unsigned int[]){ gpio }, \ 140 .num_pins = 1, \ 141 .is_gpio = true, \ 142 } 143 144 #define FUNCTION(fn) \ 145 { \ 146 .name = #fn, \ 147 .groups = fn ## _groups, \ 148 .num_groups = ARRAY_SIZE(fn ## _groups), \ 149 } 150 151 #define BANK(n, f, l, fi, li, per, peb, pr, pb, dr, db, or, ob, ir, ib) \ 152 { \ 153 .name = n, \ 154 .first = f, \ 155 .last = l, \ 156 .irq_first = fi, \ 157 .irq_last = li, \ 158 .regs = { \ 159 [REG_PULLEN] = { per, peb }, \ 160 [REG_PULL] = { pr, pb }, \ 161 [REG_DIR] = { dr, db }, \ 162 [REG_OUT] = { or, ob }, \ 163 [REG_IN] = { ir, ib }, \ 164 }, \ 165 } 166 167 #define MESON_PIN(x) PINCTRL_PIN(x, #x) 168 169 /* Common probe function */ 170 int meson_pinctrl_probe(struct platform_device *pdev); 171