blob: 028e29ae07275863812b91b73214588a25301156 [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
34#define PINMUX_FLAG_DBIT_SHIFT 5
35#define PINMUX_FLAG_DBIT (0x1f << PINMUX_FLAG_DBIT_SHIFT)
36#define PINMUX_FLAG_DREG_SHIFT 10
37#define PINMUX_FLAG_DREG (0x3f << PINMUX_FLAG_DREG_SHIFT)
38
Laurent Pincharta3db40a2013-01-02 14:53:37 +010039struct sh_pfc_pin {
Laurent Pinchart051fae42012-11-28 19:22:18 +010040 const pinmux_enum_t enum_id;
Laurent Pincharta3db40a2013-01-02 14:53:37 +010041 unsigned short flags;
Paul Mundt72c7afa2012-07-10 11:59:29 +090042 const char *name;
Magnus Dammfae43392009-11-27 07:38:01 +000043};
44
Laurent Pinchart3d8d9f12013-01-03 14:33:13 +010045#define SH_PFC_PIN_GROUP(n) \
46 { \
47 .name = #n, \
48 .pins = n##_pins, \
49 .mux = n##_mux, \
50 .nr_pins = ARRAY_SIZE(n##_pins), \
51 }
52
53struct sh_pfc_pin_group {
54 const char *name;
55 const unsigned int *pins;
56 const unsigned int *mux;
57 unsigned int nr_pins;
58};
59
60#define SH_PFC_FUNCTION(n) \
61 { \
62 .name = #n, \
63 .groups = n##_groups, \
64 .nr_groups = ARRAY_SIZE(n##_groups), \
65 }
66
67struct sh_pfc_function {
68 const char *name;
69 const char * const *groups;
70 unsigned int nr_groups;
71};
72
Laurent Pincharta373ed02012-11-29 13:24:07 +010073struct pinmux_func {
74 const pinmux_enum_t enum_id;
75 const char *name;
76};
77
Laurent Pinchart380c2ed2012-11-29 02:23:26 +010078#define PINMUX_GPIO(gpio, data_or_mark) \
79 [gpio] = { \
80 .name = __stringify(gpio), \
81 .enum_id = data_or_mark, \
82 .flags = PINMUX_TYPE_GPIO \
83 }
Laurent Pincharta373ed02012-11-29 13:24:07 +010084#define PINMUX_GPIO_FN(gpio, base, data_or_mark) \
85 [gpio - (base)] = { \
Laurent Pinchart380c2ed2012-11-29 02:23:26 +010086 .name = __stringify(gpio), \
87 .enum_id = data_or_mark, \
Laurent Pinchart380c2ed2012-11-29 02:23:26 +010088 }
Paul Mundt06d56312012-06-21 00:03:41 +090089
Magnus Dammfae43392009-11-27 07:38:01 +000090#define PINMUX_DATA(data_or_mark, ids...) data_or_mark, ids, 0
91
92struct pinmux_cfg_reg {
93 unsigned long reg, reg_width, field_width;
94 unsigned long *cnt;
95 pinmux_enum_t *enum_ids;
Magnus Dammf78a26f2011-12-14 01:01:05 +090096 unsigned long *var_field_width;
Magnus Dammfae43392009-11-27 07:38:01 +000097};
98
99#define PINMUX_CFG_REG(name, r, r_width, f_width) \
100 .reg = r, .reg_width = r_width, .field_width = f_width, \
101 .cnt = (unsigned long [r_width / f_width]) {}, \
Magnus Dammf78a26f2011-12-14 01:01:05 +0900102 .enum_ids = (pinmux_enum_t [(r_width / f_width) * (1 << f_width)])
103
104#define PINMUX_CFG_REG_VAR(name, r, r_width, var_fw0, var_fwn...) \
105 .reg = r, .reg_width = r_width, \
106 .cnt = (unsigned long [r_width]) {}, \
107 .var_field_width = (unsigned long [r_width]) { var_fw0, var_fwn, 0 }, \
108 .enum_ids = (pinmux_enum_t [])
Magnus Dammfae43392009-11-27 07:38:01 +0000109
110struct pinmux_data_reg {
111 unsigned long reg, reg_width, reg_shadow;
112 pinmux_enum_t *enum_ids;
Magnus Dammb0e10212011-12-09 12:14:27 +0900113 void __iomem *mapped_reg;
Magnus Dammfae43392009-11-27 07:38:01 +0000114};
115
116#define PINMUX_DATA_REG(name, r, r_width) \
117 .reg = r, .reg_width = r_width, \
118 .enum_ids = (pinmux_enum_t [r_width]) \
119
Magnus Dammad2a8e72011-09-28 16:50:58 +0900120struct pinmux_irq {
121 int irq;
Laurent Pinchartc07f54f2013-01-03 14:12:14 +0100122 unsigned short *gpios;
Magnus Dammad2a8e72011-09-28 16:50:58 +0900123};
124
125#define PINMUX_IRQ(irq_nr, ids...) \
Laurent Pinchartc07f54f2013-01-03 14:12:14 +0100126 { .irq = irq_nr, .gpios = (unsigned short []) { ids, 0 } } \
Magnus Dammad2a8e72011-09-28 16:50:58 +0900127
Magnus Dammfae43392009-11-27 07:38:01 +0000128struct pinmux_range {
129 pinmux_enum_t begin;
130 pinmux_enum_t end;
131 pinmux_enum_t force;
132};
133
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100134struct sh_pfc_soc_info {
Magnus Dammfae43392009-11-27 07:38:01 +0000135 char *name;
Magnus Dammfae43392009-11-27 07:38:01 +0000136 struct pinmux_range input;
137 struct pinmux_range input_pd;
138 struct pinmux_range input_pu;
139 struct pinmux_range output;
Magnus Dammfae43392009-11-27 07:38:01 +0000140 struct pinmux_range function;
141
Laurent Pincharta3db40a2013-01-02 14:53:37 +0100142 struct sh_pfc_pin *pins;
Laurent Pinchartcaa5bac2012-11-29 12:24:51 +0100143 unsigned int nr_pins;
Laurent Pinchart63d57382013-02-15 01:33:38 +0100144 const struct pinmux_range *ranges;
145 unsigned int nr_ranges;
Laurent Pinchart3d8d9f12013-01-03 14:33:13 +0100146 const struct sh_pfc_pin_group *groups;
147 unsigned int nr_groups;
148 const struct sh_pfc_function *functions;
149 unsigned int nr_functions;
150
Laurent Pincharta373ed02012-11-29 13:24:07 +0100151 struct pinmux_func *func_gpios;
152 unsigned int nr_func_gpios;
Laurent Pinchartd7a7ca52012-11-28 17:51:00 +0100153
Magnus Dammfae43392009-11-27 07:38:01 +0000154 struct pinmux_cfg_reg *cfg_regs;
155 struct pinmux_data_reg *data_regs;
156
157 pinmux_enum_t *gpio_data;
158 unsigned int gpio_data_size;
159
Magnus Dammad2a8e72011-09-28 16:50:58 +0900160 struct pinmux_irq *gpio_irq;
161 unsigned int gpio_irq_size;
162
Magnus Damme499ada2011-12-14 01:01:14 +0900163 unsigned long unlock_reg;
Magnus Dammfae43392009-11-27 07:38:01 +0000164};
165
Paul Mundtb3c185a2012-06-20 17:29:04 +0900166enum { GPIO_CFG_DRYRUN, GPIO_CFG_REQ, GPIO_CFG_FREE };
Magnus Dammfae43392009-11-27 07:38:01 +0000167
Kuninori Morimoto972c3fb2011-11-10 18:45:33 -0800168/* helper macro for port */
169#define PORT_1(fn, pfx, sfx) fn(pfx, sfx)
170
171#define PORT_10(fn, pfx, sfx) \
172 PORT_1(fn, pfx##0, sfx), PORT_1(fn, pfx##1, sfx), \
173 PORT_1(fn, pfx##2, sfx), PORT_1(fn, pfx##3, sfx), \
174 PORT_1(fn, pfx##4, sfx), PORT_1(fn, pfx##5, sfx), \
175 PORT_1(fn, pfx##6, sfx), PORT_1(fn, pfx##7, sfx), \
176 PORT_1(fn, pfx##8, sfx), PORT_1(fn, pfx##9, sfx)
177
Laurent Pinchart17dffe42013-02-13 22:09:27 +0100178#define PORT_10_REV(fn, pfx, sfx) \
179 PORT_1(fn, pfx##9, sfx), PORT_1(fn, pfx##8, sfx), \
180 PORT_1(fn, pfx##7, sfx), PORT_1(fn, pfx##6, sfx), \
181 PORT_1(fn, pfx##5, sfx), PORT_1(fn, pfx##4, sfx), \
182 PORT_1(fn, pfx##3, sfx), PORT_1(fn, pfx##2, sfx), \
183 PORT_1(fn, pfx##1, sfx), PORT_1(fn, pfx##0, sfx)
184
185#define PORT_32(fn, pfx, sfx) \
186 PORT_10(fn, pfx, sfx), PORT_10(fn, pfx##1, sfx), \
187 PORT_10(fn, pfx##2, sfx), PORT_1(fn, pfx##30, sfx), \
188 PORT_1(fn, pfx##31, sfx)
189
190#define PORT_32_REV(fn, pfx, sfx) \
191 PORT_1(fn, pfx##31, sfx), PORT_1(fn, pfx##30, sfx), \
192 PORT_10_REV(fn, pfx##2, sfx), PORT_10_REV(fn, pfx##1, sfx), \
193 PORT_10_REV(fn, pfx, sfx)
194
Kuninori Morimoto972c3fb2011-11-10 18:45:33 -0800195#define PORT_90(fn, pfx, sfx) \
196 PORT_10(fn, pfx##1, sfx), PORT_10(fn, pfx##2, sfx), \
197 PORT_10(fn, pfx##3, sfx), PORT_10(fn, pfx##4, sfx), \
198 PORT_10(fn, pfx##5, sfx), PORT_10(fn, pfx##6, sfx), \
199 PORT_10(fn, pfx##7, sfx), PORT_10(fn, pfx##8, sfx), \
200 PORT_10(fn, pfx##9, sfx)
201
202#define _PORT_ALL(pfx, sfx) pfx##_##sfx
203#define _GPIO_PORT(pfx, sfx) PINMUX_GPIO(GPIO_PORT##pfx, PORT##pfx##_DATA)
204#define PORT_ALL(str) CPU_ALL_PORT(_PORT_ALL, PORT, str)
205#define GPIO_PORT_ALL() CPU_ALL_PORT(_GPIO_PORT, , unused)
Laurent Pincharta373ed02012-11-29 13:24:07 +0100206#define GPIO_FN(str) PINMUX_GPIO_FN(GPIO_FN_##str, PINMUX_FN_BASE, str##_MARK)
Kuninori Morimoto972c3fb2011-11-10 18:45:33 -0800207
Kuninori Morimotobd8d0cba2011-11-10 18:45:23 -0800208/* helper macro for pinmux_enum_t */
209#define PORT_DATA_I(nr) \
210 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_IN)
211
212#define PORT_DATA_I_PD(nr) \
213 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \
214 PORT##nr##_IN, PORT##nr##_IN_PD)
215
216#define PORT_DATA_I_PU(nr) \
217 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \
218 PORT##nr##_IN, PORT##nr##_IN_PU)
219
220#define PORT_DATA_I_PU_PD(nr) \
221 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \
222 PORT##nr##_IN, PORT##nr##_IN_PD, PORT##nr##_IN_PU)
223
224#define PORT_DATA_O(nr) \
225 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT)
226
227#define PORT_DATA_IO(nr) \
228 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
229 PORT##nr##_IN)
230
231#define PORT_DATA_IO_PD(nr) \
232 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
233 PORT##nr##_IN, PORT##nr##_IN_PD)
234
235#define PORT_DATA_IO_PU(nr) \
236 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
237 PORT##nr##_IN, PORT##nr##_IN_PU)
238
239#define PORT_DATA_IO_PU_PD(nr) \
240 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
241 PORT##nr##_IN, PORT##nr##_IN_PD, PORT##nr##_IN_PU)
242
Kuninori Morimoto9b491392011-11-10 18:45:43 -0800243/* helper macro for top 4 bits in PORTnCR */
244#define _PCRH(in, in_pd, in_pu, out) \
245 0, (out), (in), 0, \
246 0, 0, 0, 0, \
247 0, 0, (in_pd), 0, \
248 0, 0, (in_pu), 0
249
250#define PORTCR(nr, reg) \
251 { \
252 PINMUX_CFG_REG("PORT" nr "CR", reg, 8, 4) { \
253 _PCRH(PORT##nr##_IN, PORT##nr##_IN_PD, \
254 PORT##nr##_IN_PU, PORT##nr##_OUT), \
255 PORT##nr##_FN0, PORT##nr##_FN1, \
256 PORT##nr##_FN2, PORT##nr##_FN3, \
257 PORT##nr##_FN4, PORT##nr##_FN5, \
258 PORT##nr##_FN6, PORT##nr##_FN7 } \
259 }
Kuninori Morimotobd8d0cba2011-11-10 18:45:23 -0800260
Magnus Dammfae43392009-11-27 07:38:01 +0000261#endif /* __SH_PFC_H */