]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - drivers/pinctrl/meson/pinctrl-meson.h
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[mirror_ubuntu-bionic-kernel.git] / drivers / pinctrl / meson / pinctrl-meson.h
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 const void *data;
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,
74 NUM_REG,
75 };
76
77 /**
78 * struct meson bank
79 *
80 * @name: bank name
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
85 *
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.
90 */
91 struct meson_bank {
92 const char *name;
93 unsigned int first;
94 unsigned int last;
95 int irq_first;
96 int irq_last;
97 struct meson_reg_desc regs[NUM_REG];
98 };
99
100 struct meson_pinctrl_data {
101 const char *name;
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;
111 };
112
113 struct meson_pinctrl {
114 struct device *dev;
115 struct pinctrl_dev *pcdev;
116 struct pinctrl_desc desc;
117 struct meson_pinctrl_data *data;
118 struct regmap *reg_mux;
119 struct regmap *reg_pullen;
120 struct regmap *reg_pull;
121 struct regmap *reg_gpio;
122 struct gpio_chip chip;
123 struct device_node *of_node;
124 };
125
126 #define FUNCTION(fn) \
127 { \
128 .name = #fn, \
129 .groups = fn ## _groups, \
130 .num_groups = ARRAY_SIZE(fn ## _groups), \
131 }
132
133 #define BANK(n, f, l, fi, li, per, peb, pr, pb, dr, db, or, ob, ir, ib) \
134 { \
135 .name = n, \
136 .first = f, \
137 .last = l, \
138 .irq_first = fi, \
139 .irq_last = li, \
140 .regs = { \
141 [REG_PULLEN] = { per, peb }, \
142 [REG_PULL] = { pr, pb }, \
143 [REG_DIR] = { dr, db }, \
144 [REG_OUT] = { or, ob }, \
145 [REG_IN] = { ir, ib }, \
146 }, \
147 }
148
149 #define MESON_PIN(x) PINCTRL_PIN(x, #x)
150
151 /* Common pmx functions */
152 int meson_pmx_get_funcs_count(struct pinctrl_dev *pcdev);
153 const char *meson_pmx_get_func_name(struct pinctrl_dev *pcdev,
154 unsigned selector);
155 int meson_pmx_get_groups(struct pinctrl_dev *pcdev,
156 unsigned selector,
157 const char * const **groups,
158 unsigned * const num_groups);
159
160 /* Common probe function */
161 int meson_pinctrl_probe(struct platform_device *pdev);