2 * Pin controller and GPIO driver for Amlogic Meson SoCs
4 * Copyright (C) 2014 Beniamino Galvani <b.galvani@gmail.com>
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.
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/>.
14 #include <linux/gpio.h>
15 #include <linux/pinctrl/pinctrl.h>
16 #include <linux/regmap.h>
17 #include <linux/types.h>
20 * struct meson_pmx_group - a pinmux group
23 * @pins: pins in the group
24 * @num_pins: number of pins in the group
25 * @is_gpio: whether the group is a single GPIO group
26 * @reg: register offset for the group in the domain mux registers
27 * @bit bit index enabling the group
28 * @domain: index of the domain this group belongs to
30 struct meson_pmx_group
{
32 const unsigned int *pins
;
33 unsigned int num_pins
;
40 * struct meson_pmx_func - a pinmux function
42 * @name: function name
43 * @groups: groups in the function
44 * @num_groups: number of groups in the function
46 struct meson_pmx_func
{
48 const char * const *groups
;
49 unsigned int num_groups
;
53 * struct meson_reg_desc - a register descriptor
55 * @reg: register offset in the regmap
56 * @bit: bit index in register
58 * The structure describes the information needed to control pull,
59 * pull-enable, direction, etc. for a single pin
61 struct meson_reg_desc
{
67 * enum meson_reg_type - type of registers encoded in @meson_reg_desc
82 * @first: first pin of the bank
83 * @last: last pin of the bank
84 * @regs: array of register descriptors
86 * A bank represents a set of pins controlled by a contiguous set of
87 * bits in the domain registers. The structure specifies which bits in
88 * the regmap control the different functionalities. Each member of
89 * the @regs array refers to the first pin of the bank.
95 struct meson_reg_desc regs
[NUM_REG
];
99 * struct meson_domain_data - domain platform data
101 * @name: name of the domain
102 * @banks: set of banks belonging to the domain
103 * @num_banks: number of banks in the domain
105 struct meson_domain_data
{
107 struct meson_bank
*banks
;
108 unsigned int num_banks
;
109 unsigned int pin_base
;
110 unsigned int num_pins
;
114 * struct meson_domain
116 * @reg_mux: registers for mux settings
117 * @reg_pullen: registers for pull-enable settings
118 * @reg_pull: registers for pull settings
119 * @reg_gpio: registers for gpio settings
120 * @chip: gpio chip associated with the domain
121 * @data; platform data for the domain
122 * @node: device tree node for the domain
124 * A domain represents a set of banks controlled by the same set of
127 struct meson_domain
{
128 struct regmap
*reg_mux
;
129 struct regmap
*reg_pullen
;
130 struct regmap
*reg_pull
;
131 struct regmap
*reg_gpio
;
133 struct gpio_chip chip
;
134 struct meson_domain_data
*data
;
135 struct device_node
*of_node
;
138 struct meson_pinctrl_data
{
139 const struct pinctrl_pin_desc
*pins
;
140 struct meson_pmx_group
*groups
;
141 struct meson_pmx_func
*funcs
;
142 struct meson_domain_data
*domain_data
;
143 unsigned int num_pins
;
144 unsigned int num_groups
;
145 unsigned int num_funcs
;
148 struct meson_pinctrl
{
150 struct pinctrl_dev
*pcdev
;
151 struct pinctrl_desc desc
;
152 struct meson_pinctrl_data
*data
;
153 struct meson_domain
*domain
;
156 #define PIN(x, b) (b + x)
158 #define GROUP(grp, r, b) \
161 .pins = grp ## _pins, \
162 .num_pins = ARRAY_SIZE(grp ## _pins), \
167 #define GPIO_GROUP(gpio, b) \
170 .pins = (const unsigned int[]){ PIN(gpio, b) }, \
175 #define FUNCTION(fn) \
178 .groups = fn ## _groups, \
179 .num_groups = ARRAY_SIZE(fn ## _groups), \
182 #define BANK(n, f, l, per, peb, pr, pb, dr, db, or, ob, ir, ib) \
188 [REG_PULLEN] = { per, peb }, \
189 [REG_PULL] = { pr, pb }, \
190 [REG_DIR] = { dr, db }, \
191 [REG_OUT] = { or, ob }, \
192 [REG_IN] = { ir, ib }, \
196 #define MESON_PIN(x, b) PINCTRL_PIN(PIN(x, b), #x)
198 extern struct meson_pinctrl_data meson8_cbus_pinctrl_data
;
199 extern struct meson_pinctrl_data meson8_aobus_pinctrl_data
;
200 extern struct meson_pinctrl_data meson8b_cbus_pinctrl_data
;
201 extern struct meson_pinctrl_data meson8b_aobus_pinctrl_data
;
202 extern struct meson_pinctrl_data meson_gxbb_periphs_pinctrl_data
;
203 extern struct meson_pinctrl_data meson_gxbb_aobus_pinctrl_data
;