blob: dbcaa600ccc672bf83670f975b5cda9692da1d9b [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
Paul Mundt06d56312012-06-21 00:03:41 +090019enum {
20 PINMUX_TYPE_NONE,
Magnus Dammfae43392009-11-27 07:38:01 +000021
Paul Mundt06d56312012-06-21 00:03:41 +090022 PINMUX_TYPE_FUNCTION,
23 PINMUX_TYPE_GPIO,
24 PINMUX_TYPE_OUTPUT,
25 PINMUX_TYPE_INPUT,
26 PINMUX_TYPE_INPUT_PULLUP,
27 PINMUX_TYPE_INPUT_PULLDOWN,
28
29 PINMUX_FLAG_TYPE, /* must be last */
30};
Magnus Dammfae43392009-11-27 07:38:01 +000031
32#define PINMUX_FLAG_DBIT_SHIFT 5
33#define PINMUX_FLAG_DBIT (0x1f << PINMUX_FLAG_DBIT_SHIFT)
34#define PINMUX_FLAG_DREG_SHIFT 10
35#define PINMUX_FLAG_DREG (0x3f << PINMUX_FLAG_DREG_SHIFT)
36
Laurent Pincharta3db40a2013-01-02 14:53:37 +010037struct sh_pfc_pin {
Laurent Pinchart051fae42012-11-28 19:22:18 +010038 const pinmux_enum_t enum_id;
Laurent Pincharta3db40a2013-01-02 14:53:37 +010039 unsigned short flags;
Paul Mundt72c7afa2012-07-10 11:59:29 +090040 const char *name;
Magnus Dammfae43392009-11-27 07:38:01 +000041};
42
Laurent Pincharta373ed02012-11-29 13:24:07 +010043struct pinmux_func {
44 const pinmux_enum_t enum_id;
45 const char *name;
46};
47
Laurent Pinchart380c2ed2012-11-29 02:23:26 +010048#define PINMUX_GPIO(gpio, data_or_mark) \
49 [gpio] = { \
50 .name = __stringify(gpio), \
51 .enum_id = data_or_mark, \
52 .flags = PINMUX_TYPE_GPIO \
53 }
Laurent Pincharta373ed02012-11-29 13:24:07 +010054#define PINMUX_GPIO_FN(gpio, base, data_or_mark) \
55 [gpio - (base)] = { \
Laurent Pinchart380c2ed2012-11-29 02:23:26 +010056 .name = __stringify(gpio), \
57 .enum_id = data_or_mark, \
Laurent Pinchart380c2ed2012-11-29 02:23:26 +010058 }
Paul Mundt06d56312012-06-21 00:03:41 +090059
Magnus Dammfae43392009-11-27 07:38:01 +000060#define PINMUX_DATA(data_or_mark, ids...) data_or_mark, ids, 0
61
62struct pinmux_cfg_reg {
63 unsigned long reg, reg_width, field_width;
64 unsigned long *cnt;
65 pinmux_enum_t *enum_ids;
Magnus Dammf78a26f2011-12-14 01:01:05 +090066 unsigned long *var_field_width;
Magnus Dammfae43392009-11-27 07:38:01 +000067};
68
69#define PINMUX_CFG_REG(name, r, r_width, f_width) \
70 .reg = r, .reg_width = r_width, .field_width = f_width, \
71 .cnt = (unsigned long [r_width / f_width]) {}, \
Magnus Dammf78a26f2011-12-14 01:01:05 +090072 .enum_ids = (pinmux_enum_t [(r_width / f_width) * (1 << f_width)])
73
74#define PINMUX_CFG_REG_VAR(name, r, r_width, var_fw0, var_fwn...) \
75 .reg = r, .reg_width = r_width, \
76 .cnt = (unsigned long [r_width]) {}, \
77 .var_field_width = (unsigned long [r_width]) { var_fw0, var_fwn, 0 }, \
78 .enum_ids = (pinmux_enum_t [])
Magnus Dammfae43392009-11-27 07:38:01 +000079
80struct pinmux_data_reg {
81 unsigned long reg, reg_width, reg_shadow;
82 pinmux_enum_t *enum_ids;
Magnus Dammb0e10212011-12-09 12:14:27 +090083 void __iomem *mapped_reg;
Magnus Dammfae43392009-11-27 07:38:01 +000084};
85
86#define PINMUX_DATA_REG(name, r, r_width) \
87 .reg = r, .reg_width = r_width, \
88 .enum_ids = (pinmux_enum_t [r_width]) \
89
Magnus Dammad2a8e72011-09-28 16:50:58 +090090struct pinmux_irq {
91 int irq;
Laurent Pinchartc07f54f2013-01-03 14:12:14 +010092 unsigned short *gpios;
Magnus Dammad2a8e72011-09-28 16:50:58 +090093};
94
95#define PINMUX_IRQ(irq_nr, ids...) \
Laurent Pinchartc07f54f2013-01-03 14:12:14 +010096 { .irq = irq_nr, .gpios = (unsigned short []) { ids, 0 } } \
Magnus Dammad2a8e72011-09-28 16:50:58 +090097
Magnus Dammfae43392009-11-27 07:38:01 +000098struct pinmux_range {
99 pinmux_enum_t begin;
100 pinmux_enum_t end;
101 pinmux_enum_t force;
102};
103
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100104struct sh_pfc_soc_info {
Magnus Dammfae43392009-11-27 07:38:01 +0000105 char *name;
Magnus Dammfae43392009-11-27 07:38:01 +0000106 struct pinmux_range input;
107 struct pinmux_range input_pd;
108 struct pinmux_range input_pu;
109 struct pinmux_range output;
Magnus Dammfae43392009-11-27 07:38:01 +0000110 struct pinmux_range function;
111
Laurent Pincharta3db40a2013-01-02 14:53:37 +0100112 struct sh_pfc_pin *pins;
Laurent Pinchartcaa5bac2012-11-29 12:24:51 +0100113 unsigned int nr_pins;
Laurent Pinchart63d57382013-02-15 01:33:38 +0100114 const struct pinmux_range *ranges;
115 unsigned int nr_ranges;
Laurent Pincharta373ed02012-11-29 13:24:07 +0100116 struct pinmux_func *func_gpios;
117 unsigned int nr_func_gpios;
Laurent Pinchartd7a7ca52012-11-28 17:51:00 +0100118
Magnus Dammfae43392009-11-27 07:38:01 +0000119 struct pinmux_cfg_reg *cfg_regs;
120 struct pinmux_data_reg *data_regs;
121
122 pinmux_enum_t *gpio_data;
123 unsigned int gpio_data_size;
124
Magnus Dammad2a8e72011-09-28 16:50:58 +0900125 struct pinmux_irq *gpio_irq;
126 unsigned int gpio_irq_size;
127
Magnus Damme499ada2011-12-14 01:01:14 +0900128 unsigned long unlock_reg;
Magnus Dammfae43392009-11-27 07:38:01 +0000129};
130
Paul Mundtb3c185a2012-06-20 17:29:04 +0900131enum { GPIO_CFG_DRYRUN, GPIO_CFG_REQ, GPIO_CFG_FREE };
Magnus Dammfae43392009-11-27 07:38:01 +0000132
Kuninori Morimoto972c3fb2011-11-10 18:45:33 -0800133/* helper macro for port */
134#define PORT_1(fn, pfx, sfx) fn(pfx, sfx)
135
136#define PORT_10(fn, pfx, sfx) \
137 PORT_1(fn, pfx##0, sfx), PORT_1(fn, pfx##1, sfx), \
138 PORT_1(fn, pfx##2, sfx), PORT_1(fn, pfx##3, sfx), \
139 PORT_1(fn, pfx##4, sfx), PORT_1(fn, pfx##5, sfx), \
140 PORT_1(fn, pfx##6, sfx), PORT_1(fn, pfx##7, sfx), \
141 PORT_1(fn, pfx##8, sfx), PORT_1(fn, pfx##9, sfx)
142
Laurent Pinchart17dffe42013-02-13 22:09:27 +0100143#define PORT_10_REV(fn, pfx, sfx) \
144 PORT_1(fn, pfx##9, sfx), PORT_1(fn, pfx##8, sfx), \
145 PORT_1(fn, pfx##7, sfx), PORT_1(fn, pfx##6, sfx), \
146 PORT_1(fn, pfx##5, sfx), PORT_1(fn, pfx##4, sfx), \
147 PORT_1(fn, pfx##3, sfx), PORT_1(fn, pfx##2, sfx), \
148 PORT_1(fn, pfx##1, sfx), PORT_1(fn, pfx##0, sfx)
149
150#define PORT_32(fn, pfx, sfx) \
151 PORT_10(fn, pfx, sfx), PORT_10(fn, pfx##1, sfx), \
152 PORT_10(fn, pfx##2, sfx), PORT_1(fn, pfx##30, sfx), \
153 PORT_1(fn, pfx##31, sfx)
154
155#define PORT_32_REV(fn, pfx, sfx) \
156 PORT_1(fn, pfx##31, sfx), PORT_1(fn, pfx##30, sfx), \
157 PORT_10_REV(fn, pfx##2, sfx), PORT_10_REV(fn, pfx##1, sfx), \
158 PORT_10_REV(fn, pfx, sfx)
159
Kuninori Morimoto972c3fb2011-11-10 18:45:33 -0800160#define PORT_90(fn, pfx, sfx) \
161 PORT_10(fn, pfx##1, sfx), PORT_10(fn, pfx##2, sfx), \
162 PORT_10(fn, pfx##3, sfx), PORT_10(fn, pfx##4, sfx), \
163 PORT_10(fn, pfx##5, sfx), PORT_10(fn, pfx##6, sfx), \
164 PORT_10(fn, pfx##7, sfx), PORT_10(fn, pfx##8, sfx), \
165 PORT_10(fn, pfx##9, sfx)
166
167#define _PORT_ALL(pfx, sfx) pfx##_##sfx
168#define _GPIO_PORT(pfx, sfx) PINMUX_GPIO(GPIO_PORT##pfx, PORT##pfx##_DATA)
169#define PORT_ALL(str) CPU_ALL_PORT(_PORT_ALL, PORT, str)
170#define GPIO_PORT_ALL() CPU_ALL_PORT(_GPIO_PORT, , unused)
Laurent Pincharta373ed02012-11-29 13:24:07 +0100171#define GPIO_FN(str) PINMUX_GPIO_FN(GPIO_FN_##str, PINMUX_FN_BASE, str##_MARK)
Kuninori Morimoto972c3fb2011-11-10 18:45:33 -0800172
Kuninori Morimotobd8d0cba2011-11-10 18:45:23 -0800173/* helper macro for pinmux_enum_t */
174#define PORT_DATA_I(nr) \
175 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_IN)
176
177#define PORT_DATA_I_PD(nr) \
178 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \
179 PORT##nr##_IN, PORT##nr##_IN_PD)
180
181#define PORT_DATA_I_PU(nr) \
182 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \
183 PORT##nr##_IN, PORT##nr##_IN_PU)
184
185#define PORT_DATA_I_PU_PD(nr) \
186 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \
187 PORT##nr##_IN, PORT##nr##_IN_PD, PORT##nr##_IN_PU)
188
189#define PORT_DATA_O(nr) \
190 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT)
191
192#define PORT_DATA_IO(nr) \
193 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
194 PORT##nr##_IN)
195
196#define PORT_DATA_IO_PD(nr) \
197 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
198 PORT##nr##_IN, PORT##nr##_IN_PD)
199
200#define PORT_DATA_IO_PU(nr) \
201 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
202 PORT##nr##_IN, PORT##nr##_IN_PU)
203
204#define PORT_DATA_IO_PU_PD(nr) \
205 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
206 PORT##nr##_IN, PORT##nr##_IN_PD, PORT##nr##_IN_PU)
207
Kuninori Morimoto9b491392011-11-10 18:45:43 -0800208/* helper macro for top 4 bits in PORTnCR */
209#define _PCRH(in, in_pd, in_pu, out) \
210 0, (out), (in), 0, \
211 0, 0, 0, 0, \
212 0, 0, (in_pd), 0, \
213 0, 0, (in_pu), 0
214
215#define PORTCR(nr, reg) \
216 { \
217 PINMUX_CFG_REG("PORT" nr "CR", reg, 8, 4) { \
218 _PCRH(PORT##nr##_IN, PORT##nr##_IN_PD, \
219 PORT##nr##_IN_PU, PORT##nr##_OUT), \
220 PORT##nr##_FN0, PORT##nr##_FN1, \
221 PORT##nr##_FN2, PORT##nr##_FN3, \
222 PORT##nr##_FN4, PORT##nr##_FN5, \
223 PORT##nr##_FN6, PORT##nr##_FN7 } \
224 }
Kuninori Morimotobd8d0cba2011-11-10 18:45:23 -0800225
Magnus Dammfae43392009-11-27 07:38:01 +0000226#endif /* __SH_PFC_H */