blob: 28085a7495d461b3edf947c92e0db07199d5241a [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Beniamino Galvani677b5352016-08-16 11:49:49 +02002/*
3 * (C) Copyright 2016 - Beniamino Galvani <b.galvani@gmail.com>
Beniamino Galvani677b5352016-08-16 11:49:49 +02004 */
5
6#ifndef __PINCTRL_MESON_H__
7#define __PINCTRL_MESON_H__
8
9#include <linux/types.h>
10
11struct meson_pmx_group {
12 const char *name;
13 const unsigned int *pins;
14 unsigned int num_pins;
Jerome Brunet7c9dcfe2018-10-05 09:35:26 +020015 const void *data;
Beniamino Galvani677b5352016-08-16 11:49:49 +020016};
17
18struct meson_pmx_func {
19 const char *name;
20 const char * const *groups;
21 unsigned int num_groups;
22};
23
24struct meson_pinctrl_data {
25 const char *name;
26 struct meson_pmx_group *groups;
27 struct meson_pmx_func *funcs;
Beniamino Galvani2009a8d2017-07-10 00:30:04 +020028 struct meson_bank *banks;
Beniamino Galvani677b5352016-08-16 11:49:49 +020029 unsigned int pin_base;
30 unsigned int num_pins;
31 unsigned int num_groups;
32 unsigned int num_funcs;
Beniamino Galvani2009a8d2017-07-10 00:30:04 +020033 unsigned int num_banks;
Jerome Brunet7c9dcfe2018-10-05 09:35:26 +020034 const struct driver *gpio_driver;
35 void *pmx_data;
Beniamino Galvani677b5352016-08-16 11:49:49 +020036};
37
38struct meson_pinctrl {
39 struct meson_pinctrl_data *data;
40 void __iomem *reg_mux;
Beniamino Galvani2009a8d2017-07-10 00:30:04 +020041 void __iomem *reg_gpio;
Jerome Brunetc4c726c2019-01-04 15:44:34 +010042 void __iomem *reg_pull;
43 void __iomem *reg_pullen;
Beniamino Galvani2009a8d2017-07-10 00:30:04 +020044};
45
46/**
47 * struct meson_reg_desc - a register descriptor
48 *
49 * @reg: register offset in the regmap
50 * @bit: bit index in register
51 *
52 * The structure describes the information needed to control pull,
53 * pull-enable, direction, etc. for a single pin
54 */
55struct meson_reg_desc {
56 unsigned int reg;
57 unsigned int bit;
58};
59
60/**
61 * enum meson_reg_type - type of registers encoded in @meson_reg_desc
62 */
63enum meson_reg_type {
64 REG_PULLEN,
65 REG_PULL,
66 REG_DIR,
67 REG_OUT,
68 REG_IN,
69 NUM_REG,
70};
71
72/**
73 * struct meson bank
74 *
75 * @name: bank name
76 * @first: first pin of the bank
77 * @last: last pin of the bank
78 * @regs: array of register descriptors
79 *
80 * A bank represents a set of pins controlled by a contiguous set of
81 * bits in the domain registers. The structure specifies which bits in
82 * the regmap control the different functionalities. Each member of
83 * the @regs array refers to the first pin of the bank.
84 */
85struct meson_bank {
86 const char *name;
87 unsigned int first;
88 unsigned int last;
89 struct meson_reg_desc regs[NUM_REG];
Beniamino Galvani677b5352016-08-16 11:49:49 +020090};
91
92#define PIN(x, b) (b + x)
93
Beniamino Galvani677b5352016-08-16 11:49:49 +020094#define FUNCTION(fn) \
95 { \
96 .name = #fn, \
97 .groups = fn ## _groups, \
98 .num_groups = ARRAY_SIZE(fn ## _groups), \
99 }
100
Beniamino Galvani2009a8d2017-07-10 00:30:04 +0200101#define BANK(n, f, l, per, peb, pr, pb, dr, db, or, ob, ir, ib) \
102 { \
103 .name = n, \
104 .first = f, \
105 .last = l, \
106 .regs = { \
107 [REG_PULLEN] = { per, peb }, \
108 [REG_PULL] = { pr, pb }, \
109 [REG_DIR] = { dr, db }, \
110 [REG_OUT] = { or, ob }, \
111 [REG_IN] = { ir, ib }, \
112 }, \
113 }
114
Beniamino Galvani677b5352016-08-16 11:49:49 +0200115#define MESON_PIN(x, b) PINCTRL_PIN(PIN(x, b), #x)
116
117extern const struct pinctrl_ops meson_pinctrl_ops;
118
Jerome Brunet7c9dcfe2018-10-05 09:35:26 +0200119int meson_pinctrl_get_groups_count(struct udevice *dev);
120const char *meson_pinctrl_get_group_name(struct udevice *dev,
121 unsigned int selector);
122int meson_pinmux_get_functions_count(struct udevice *dev);
123const char *meson_pinmux_get_function_name(struct udevice *dev,
124 unsigned int selector);
Beniamino Galvani677b5352016-08-16 11:49:49 +0200125int meson_pinctrl_probe(struct udevice *dev);
126
Jerome Brunet7c9dcfe2018-10-05 09:35:26 +0200127int meson_gpio_get(struct udevice *dev, unsigned int offset);
128int meson_gpio_set(struct udevice *dev, unsigned int offset, int value);
129int meson_gpio_get_direction(struct udevice *dev, unsigned int offset);
130int meson_gpio_direction_input(struct udevice *dev, unsigned int offset);
131int meson_gpio_direction_output(struct udevice *dev, unsigned int offset,
132 int value);
133int meson_gpio_probe(struct udevice *dev);
134
Jerome Brunetc4c726c2019-01-04 15:44:34 +0100135int meson_pinconf_set(struct udevice *dev, unsigned int pin,
136 unsigned int param, unsigned int arg);
137int meson_pinconf_group_set(struct udevice *dev,
138 unsigned int group_selector,
139 unsigned int param, unsigned int arg);
140
Beniamino Galvani677b5352016-08-16 11:49:49 +0200141#endif /* __PINCTRL_MESON_H__ */