blob: b250dacaf8ddc3ecd3c5fc9f6028c137f5fc3f37 [file] [log] [blame]
Magnus Dammfae43392009-11-27 07:38:01 +00001/*
2 * SuperH Pin Function Controller Support
3 *
4 * Copyright (c) 2008 Magnus Damm
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10
11#ifndef __SH_PFC_H
12#define __SH_PFC_H
13
Paul Mundt72c7afa2012-07-10 11:59:29 +090014#include <linux/stringify.h>
Magnus Dammfae43392009-11-27 07:38:01 +000015#include <asm-generic/gpio.h>
16
17typedef unsigned short pinmux_enum_t;
Magnus Dammfae43392009-11-27 07:38:01 +000018
Laurent Pinchart3d8d9f12013-01-03 14:33:13 +010019#define SH_PFC_MARK_INVALID ((pinmux_enum_t)-1)
20
Paul Mundt06d56312012-06-21 00:03:41 +090021enum {
22 PINMUX_TYPE_NONE,
Magnus Dammfae43392009-11-27 07:38:01 +000023
Paul Mundt06d56312012-06-21 00:03:41 +090024 PINMUX_TYPE_FUNCTION,
25 PINMUX_TYPE_GPIO,
26 PINMUX_TYPE_OUTPUT,
27 PINMUX_TYPE_INPUT,
28 PINMUX_TYPE_INPUT_PULLUP,
29 PINMUX_TYPE_INPUT_PULLDOWN,
30
31 PINMUX_FLAG_TYPE, /* must be last */
32};
Magnus Dammfae43392009-11-27 07:38:01 +000033
Laurent Pincharta3db40a2013-01-02 14:53:37 +010034struct sh_pfc_pin {
Laurent Pinchart051fae42012-11-28 19:22:18 +010035 const pinmux_enum_t enum_id;
Paul Mundt72c7afa2012-07-10 11:59:29 +090036 const char *name;
Magnus Dammfae43392009-11-27 07:38:01 +000037};
38
Laurent Pinchart3d8d9f12013-01-03 14:33:13 +010039#define SH_PFC_PIN_GROUP(n) \
40 { \
41 .name = #n, \
42 .pins = n##_pins, \
43 .mux = n##_mux, \
44 .nr_pins = ARRAY_SIZE(n##_pins), \
45 }
46
47struct sh_pfc_pin_group {
48 const char *name;
49 const unsigned int *pins;
50 const unsigned int *mux;
51 unsigned int nr_pins;
52};
53
54#define SH_PFC_FUNCTION(n) \
55 { \
56 .name = #n, \
57 .groups = n##_groups, \
58 .nr_groups = ARRAY_SIZE(n##_groups), \
59 }
60
61struct sh_pfc_function {
62 const char *name;
63 const char * const *groups;
64 unsigned int nr_groups;
65};
66
Laurent Pincharta373ed02012-11-29 13:24:07 +010067struct pinmux_func {
68 const pinmux_enum_t enum_id;
69 const char *name;
70};
71
Laurent Pinchart380c2ed2012-11-29 02:23:26 +010072#define PINMUX_GPIO(gpio, data_or_mark) \
73 [gpio] = { \
74 .name = __stringify(gpio), \
75 .enum_id = data_or_mark, \
Laurent Pinchart380c2ed2012-11-29 02:23:26 +010076 }
Laurent Pincharta373ed02012-11-29 13:24:07 +010077#define PINMUX_GPIO_FN(gpio, base, data_or_mark) \
78 [gpio - (base)] = { \
Laurent Pinchart380c2ed2012-11-29 02:23:26 +010079 .name = __stringify(gpio), \
80 .enum_id = data_or_mark, \
Laurent Pinchart380c2ed2012-11-29 02:23:26 +010081 }
Paul Mundt06d56312012-06-21 00:03:41 +090082
Magnus Dammfae43392009-11-27 07:38:01 +000083#define PINMUX_DATA(data_or_mark, ids...) data_or_mark, ids, 0
84
85struct pinmux_cfg_reg {
86 unsigned long reg, reg_width, field_width;
Laurent Pinchartcd3c1be2013-02-16 18:47:05 +010087 const pinmux_enum_t *enum_ids;
88 const unsigned long *var_field_width;
Magnus Dammfae43392009-11-27 07:38:01 +000089};
90
91#define PINMUX_CFG_REG(name, r, r_width, f_width) \
92 .reg = r, .reg_width = r_width, .field_width = f_width, \
Magnus Dammf78a26f2011-12-14 01:01:05 +090093 .enum_ids = (pinmux_enum_t [(r_width / f_width) * (1 << f_width)])
94
95#define PINMUX_CFG_REG_VAR(name, r, r_width, var_fw0, var_fwn...) \
96 .reg = r, .reg_width = r_width, \
Magnus Dammf78a26f2011-12-14 01:01:05 +090097 .var_field_width = (unsigned long [r_width]) { var_fw0, var_fwn, 0 }, \
98 .enum_ids = (pinmux_enum_t [])
Magnus Dammfae43392009-11-27 07:38:01 +000099
100struct pinmux_data_reg {
Laurent Pinchart51cb2262013-02-16 18:34:32 +0100101 unsigned long reg, reg_width;
Laurent Pinchartcd3c1be2013-02-16 18:47:05 +0100102 const pinmux_enum_t *enum_ids;
Magnus Dammfae43392009-11-27 07:38:01 +0000103};
104
105#define PINMUX_DATA_REG(name, r, r_width) \
106 .reg = r, .reg_width = r_width, \
107 .enum_ids = (pinmux_enum_t [r_width]) \
108
Magnus Dammad2a8e72011-09-28 16:50:58 +0900109struct pinmux_irq {
110 int irq;
Laurent Pinchartc07f54f2013-01-03 14:12:14 +0100111 unsigned short *gpios;
Magnus Dammad2a8e72011-09-28 16:50:58 +0900112};
113
114#define PINMUX_IRQ(irq_nr, ids...) \
Laurent Pinchartc07f54f2013-01-03 14:12:14 +0100115 { .irq = irq_nr, .gpios = (unsigned short []) { ids, 0 } } \
Magnus Dammad2a8e72011-09-28 16:50:58 +0900116
Magnus Dammfae43392009-11-27 07:38:01 +0000117struct pinmux_range {
118 pinmux_enum_t begin;
119 pinmux_enum_t end;
120 pinmux_enum_t force;
121};
122
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100123struct sh_pfc_soc_info {
Laurent Pinchartcd3c1be2013-02-16 18:47:05 +0100124 const char *name;
Magnus Dammfae43392009-11-27 07:38:01 +0000125 struct pinmux_range input;
126 struct pinmux_range input_pd;
127 struct pinmux_range input_pu;
128 struct pinmux_range output;
Magnus Dammfae43392009-11-27 07:38:01 +0000129 struct pinmux_range function;
130
Laurent Pinchartcd3c1be2013-02-16 18:47:05 +0100131 const struct sh_pfc_pin *pins;
Laurent Pinchartcaa5bac2012-11-29 12:24:51 +0100132 unsigned int nr_pins;
Laurent Pinchart63d57382013-02-15 01:33:38 +0100133 const struct pinmux_range *ranges;
134 unsigned int nr_ranges;
Laurent Pinchart3d8d9f12013-01-03 14:33:13 +0100135 const struct sh_pfc_pin_group *groups;
136 unsigned int nr_groups;
137 const struct sh_pfc_function *functions;
138 unsigned int nr_functions;
139
Laurent Pinchartcd3c1be2013-02-16 18:47:05 +0100140 const struct pinmux_func *func_gpios;
Laurent Pincharta373ed02012-11-29 13:24:07 +0100141 unsigned int nr_func_gpios;
Laurent Pinchartd7a7ca52012-11-28 17:51:00 +0100142
Laurent Pinchartcd3c1be2013-02-16 18:47:05 +0100143 const struct pinmux_cfg_reg *cfg_regs;
144 const struct pinmux_data_reg *data_regs;
Magnus Dammfae43392009-11-27 07:38:01 +0000145
Laurent Pinchartcd3c1be2013-02-16 18:47:05 +0100146 const pinmux_enum_t *gpio_data;
Magnus Dammfae43392009-11-27 07:38:01 +0000147 unsigned int gpio_data_size;
148
Laurent Pinchartcd3c1be2013-02-16 18:47:05 +0100149 const struct pinmux_irq *gpio_irq;
Magnus Dammad2a8e72011-09-28 16:50:58 +0900150 unsigned int gpio_irq_size;
151
Magnus Damme499ada2011-12-14 01:01:14 +0900152 unsigned long unlock_reg;
Magnus Dammfae43392009-11-27 07:38:01 +0000153};
154
Laurent Pinchart861601d2013-03-10 15:29:14 +0100155enum { GPIO_CFG_REQ, GPIO_CFG_FREE };
Magnus Dammfae43392009-11-27 07:38:01 +0000156
Kuninori Morimoto972c3fb2011-11-10 18:45:33 -0800157/* helper macro for port */
158#define PORT_1(fn, pfx, sfx) fn(pfx, sfx)
159
160#define PORT_10(fn, pfx, sfx) \
161 PORT_1(fn, pfx##0, sfx), PORT_1(fn, pfx##1, sfx), \
162 PORT_1(fn, pfx##2, sfx), PORT_1(fn, pfx##3, sfx), \
163 PORT_1(fn, pfx##4, sfx), PORT_1(fn, pfx##5, sfx), \
164 PORT_1(fn, pfx##6, sfx), PORT_1(fn, pfx##7, sfx), \
165 PORT_1(fn, pfx##8, sfx), PORT_1(fn, pfx##9, sfx)
166
Laurent Pinchart17dffe42013-02-13 22:09:27 +0100167#define PORT_10_REV(fn, pfx, sfx) \
168 PORT_1(fn, pfx##9, sfx), PORT_1(fn, pfx##8, sfx), \
169 PORT_1(fn, pfx##7, sfx), PORT_1(fn, pfx##6, sfx), \
170 PORT_1(fn, pfx##5, sfx), PORT_1(fn, pfx##4, sfx), \
171 PORT_1(fn, pfx##3, sfx), PORT_1(fn, pfx##2, sfx), \
172 PORT_1(fn, pfx##1, sfx), PORT_1(fn, pfx##0, sfx)
173
174#define PORT_32(fn, pfx, sfx) \
175 PORT_10(fn, pfx, sfx), PORT_10(fn, pfx##1, sfx), \
176 PORT_10(fn, pfx##2, sfx), PORT_1(fn, pfx##30, sfx), \
177 PORT_1(fn, pfx##31, sfx)
178
179#define PORT_32_REV(fn, pfx, sfx) \
180 PORT_1(fn, pfx##31, sfx), PORT_1(fn, pfx##30, sfx), \
181 PORT_10_REV(fn, pfx##2, sfx), PORT_10_REV(fn, pfx##1, sfx), \
182 PORT_10_REV(fn, pfx, sfx)
183
Kuninori Morimoto972c3fb2011-11-10 18:45:33 -0800184#define PORT_90(fn, pfx, sfx) \
185 PORT_10(fn, pfx##1, sfx), PORT_10(fn, pfx##2, sfx), \
186 PORT_10(fn, pfx##3, sfx), PORT_10(fn, pfx##4, sfx), \
187 PORT_10(fn, pfx##5, sfx), PORT_10(fn, pfx##6, sfx), \
188 PORT_10(fn, pfx##7, sfx), PORT_10(fn, pfx##8, sfx), \
189 PORT_10(fn, pfx##9, sfx)
190
191#define _PORT_ALL(pfx, sfx) pfx##_##sfx
192#define _GPIO_PORT(pfx, sfx) PINMUX_GPIO(GPIO_PORT##pfx, PORT##pfx##_DATA)
193#define PORT_ALL(str) CPU_ALL_PORT(_PORT_ALL, PORT, str)
194#define GPIO_PORT_ALL() CPU_ALL_PORT(_GPIO_PORT, , unused)
Laurent Pincharta373ed02012-11-29 13:24:07 +0100195#define GPIO_FN(str) PINMUX_GPIO_FN(GPIO_FN_##str, PINMUX_FN_BASE, str##_MARK)
Kuninori Morimoto972c3fb2011-11-10 18:45:33 -0800196
Kuninori Morimotobd8d0cba2011-11-10 18:45:23 -0800197/* helper macro for pinmux_enum_t */
198#define PORT_DATA_I(nr) \
199 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_IN)
200
201#define PORT_DATA_I_PD(nr) \
202 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \
203 PORT##nr##_IN, PORT##nr##_IN_PD)
204
205#define PORT_DATA_I_PU(nr) \
206 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \
207 PORT##nr##_IN, PORT##nr##_IN_PU)
208
209#define PORT_DATA_I_PU_PD(nr) \
210 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \
211 PORT##nr##_IN, PORT##nr##_IN_PD, PORT##nr##_IN_PU)
212
213#define PORT_DATA_O(nr) \
214 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT)
215
216#define PORT_DATA_IO(nr) \
217 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
218 PORT##nr##_IN)
219
220#define PORT_DATA_IO_PD(nr) \
221 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
222 PORT##nr##_IN, PORT##nr##_IN_PD)
223
224#define PORT_DATA_IO_PU(nr) \
225 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
226 PORT##nr##_IN, PORT##nr##_IN_PU)
227
228#define PORT_DATA_IO_PU_PD(nr) \
229 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
230 PORT##nr##_IN, PORT##nr##_IN_PD, PORT##nr##_IN_PU)
231
Kuninori Morimoto9b491392011-11-10 18:45:43 -0800232/* helper macro for top 4 bits in PORTnCR */
233#define _PCRH(in, in_pd, in_pu, out) \
234 0, (out), (in), 0, \
235 0, 0, 0, 0, \
236 0, 0, (in_pd), 0, \
237 0, 0, (in_pu), 0
238
239#define PORTCR(nr, reg) \
240 { \
241 PINMUX_CFG_REG("PORT" nr "CR", reg, 8, 4) { \
242 _PCRH(PORT##nr##_IN, PORT##nr##_IN_PD, \
243 PORT##nr##_IN_PU, PORT##nr##_OUT), \
244 PORT##nr##_FN0, PORT##nr##_FN1, \
245 PORT##nr##_FN2, PORT##nr##_FN3, \
246 PORT##nr##_FN4, PORT##nr##_FN5, \
247 PORT##nr##_FN6, PORT##nr##_FN7 } \
248 }
Kuninori Morimotobd8d0cba2011-11-10 18:45:23 -0800249
Magnus Dammfae43392009-11-27 07:38:01 +0000250#endif /* __SH_PFC_H */