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/platform_device.h>
17 #include <linux/regmap.h>
18 #include <linux/types.h>
21 * struct meson_pmx_group - a pinmux group
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
31 struct meson_pmx_group
{
33 const unsigned int *pins
;
34 unsigned int num_pins
;
39 * struct meson_pmx_func - a pinmux function
41 * @name: function name
42 * @groups: groups in the function
43 * @num_groups: number of groups in the function
45 struct meson_pmx_func
{
47 const char * const *groups
;
48 unsigned int num_groups
;
52 * struct meson_reg_desc - a register descriptor
54 * @reg: register offset in the regmap
55 * @bit: bit index in register
57 * The structure describes the information needed to control pull,
58 * pull-enable, direction, etc. for a single pin
60 struct meson_reg_desc
{
66 * enum meson_reg_type - type of registers encoded in @meson_reg_desc
81 * @first: first pin of the bank
82 * @last: last pin of the bank
83 * @irq: hwirq base number 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.
97 struct meson_reg_desc regs
[NUM_REG
];
100 struct meson_pinctrl_data
{
102 const struct pinctrl_pin_desc
*pins
;
103 struct meson_pmx_group
*groups
;
104 struct meson_pmx_func
*funcs
;
105 unsigned int num_pins
;
106 unsigned int num_groups
;
107 unsigned int num_funcs
;
108 struct meson_bank
*banks
;
109 unsigned int num_banks
;
110 const struct pinmux_ops
*pmx_ops
;
114 struct meson_pinctrl
{
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
;
127 #define FUNCTION(fn) \
130 .groups = fn ## _groups, \
131 .num_groups = ARRAY_SIZE(fn ## _groups), \
134 #define BANK(n, f, l, fi, li, per, peb, pr, pb, dr, db, or, ob, ir, ib) \
142 [REG_PULLEN] = { per, peb }, \
143 [REG_PULL] = { pr, pb }, \
144 [REG_DIR] = { dr, db }, \
145 [REG_OUT] = { or, ob }, \
146 [REG_IN] = { ir, ib }, \
150 #define MESON_PIN(x) PINCTRL_PIN(x, #x)
152 /* Common pmx functions */
153 int meson_pmx_get_funcs_count(struct pinctrl_dev
*pcdev
);
154 const char *meson_pmx_get_func_name(struct pinctrl_dev
*pcdev
,
156 int meson_pmx_get_groups(struct pinctrl_dev
*pcdev
,
158 const char * const **groups
,
159 unsigned * const num_groups
);
161 /* Common probe function */
162 int meson_pinctrl_probe(struct platform_device
*pdev
);