blob: 43c858d98321537f47d0350a24d7989b7c5d455c [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 Pincharta373ed02012-11-29 13:24:07 +0100114 struct pinmux_func *func_gpios;
115 unsigned int nr_func_gpios;
Laurent Pinchartd7a7ca52012-11-28 17:51:00 +0100116
Magnus Dammfae43392009-11-27 07:38:01 +0000117 struct pinmux_cfg_reg *cfg_regs;
118 struct pinmux_data_reg *data_regs;
119
120 pinmux_enum_t *gpio_data;
121 unsigned int gpio_data_size;
122
Magnus Dammad2a8e72011-09-28 16:50:58 +0900123 struct pinmux_irq *gpio_irq;
124 unsigned int gpio_irq_size;
125
Magnus Damme499ada2011-12-14 01:01:14 +0900126 unsigned long unlock_reg;
Magnus Dammfae43392009-11-27 07:38:01 +0000127};
128
Paul Mundtb3c185a2012-06-20 17:29:04 +0900129enum { GPIO_CFG_DRYRUN, GPIO_CFG_REQ, GPIO_CFG_FREE };
Magnus Dammfae43392009-11-27 07:38:01 +0000130
Kuninori Morimoto972c3fb2011-11-10 18:45:33 -0800131/* helper macro for port */
132#define PORT_1(fn, pfx, sfx) fn(pfx, sfx)
133
134#define PORT_10(fn, pfx, sfx) \
135 PORT_1(fn, pfx##0, sfx), PORT_1(fn, pfx##1, sfx), \
136 PORT_1(fn, pfx##2, sfx), PORT_1(fn, pfx##3, sfx), \
137 PORT_1(fn, pfx##4, sfx), PORT_1(fn, pfx##5, sfx), \
138 PORT_1(fn, pfx##6, sfx), PORT_1(fn, pfx##7, sfx), \
139 PORT_1(fn, pfx##8, sfx), PORT_1(fn, pfx##9, sfx)
140
Laurent Pinchart17dffe42013-02-13 22:09:27 +0100141#define PORT_10_REV(fn, pfx, sfx) \
142 PORT_1(fn, pfx##9, sfx), PORT_1(fn, pfx##8, sfx), \
143 PORT_1(fn, pfx##7, sfx), PORT_1(fn, pfx##6, sfx), \
144 PORT_1(fn, pfx##5, sfx), PORT_1(fn, pfx##4, sfx), \
145 PORT_1(fn, pfx##3, sfx), PORT_1(fn, pfx##2, sfx), \
146 PORT_1(fn, pfx##1, sfx), PORT_1(fn, pfx##0, sfx)
147
148#define PORT_32(fn, pfx, sfx) \
149 PORT_10(fn, pfx, sfx), PORT_10(fn, pfx##1, sfx), \
150 PORT_10(fn, pfx##2, sfx), PORT_1(fn, pfx##30, sfx), \
151 PORT_1(fn, pfx##31, sfx)
152
153#define PORT_32_REV(fn, pfx, sfx) \
154 PORT_1(fn, pfx##31, sfx), PORT_1(fn, pfx##30, sfx), \
155 PORT_10_REV(fn, pfx##2, sfx), PORT_10_REV(fn, pfx##1, sfx), \
156 PORT_10_REV(fn, pfx, sfx)
157
Kuninori Morimoto972c3fb2011-11-10 18:45:33 -0800158#define PORT_90(fn, pfx, sfx) \
159 PORT_10(fn, pfx##1, sfx), PORT_10(fn, pfx##2, sfx), \
160 PORT_10(fn, pfx##3, sfx), PORT_10(fn, pfx##4, sfx), \
161 PORT_10(fn, pfx##5, sfx), PORT_10(fn, pfx##6, sfx), \
162 PORT_10(fn, pfx##7, sfx), PORT_10(fn, pfx##8, sfx), \
163 PORT_10(fn, pfx##9, sfx)
164
165#define _PORT_ALL(pfx, sfx) pfx##_##sfx
166#define _GPIO_PORT(pfx, sfx) PINMUX_GPIO(GPIO_PORT##pfx, PORT##pfx##_DATA)
167#define PORT_ALL(str) CPU_ALL_PORT(_PORT_ALL, PORT, str)
168#define GPIO_PORT_ALL() CPU_ALL_PORT(_GPIO_PORT, , unused)
Laurent Pincharta373ed02012-11-29 13:24:07 +0100169#define GPIO_FN(str) PINMUX_GPIO_FN(GPIO_FN_##str, PINMUX_FN_BASE, str##_MARK)
Kuninori Morimoto972c3fb2011-11-10 18:45:33 -0800170
Kuninori Morimotobd8d0cba2011-11-10 18:45:23 -0800171/* helper macro for pinmux_enum_t */
172#define PORT_DATA_I(nr) \
173 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_IN)
174
175#define PORT_DATA_I_PD(nr) \
176 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \
177 PORT##nr##_IN, PORT##nr##_IN_PD)
178
179#define PORT_DATA_I_PU(nr) \
180 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \
181 PORT##nr##_IN, PORT##nr##_IN_PU)
182
183#define PORT_DATA_I_PU_PD(nr) \
184 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \
185 PORT##nr##_IN, PORT##nr##_IN_PD, PORT##nr##_IN_PU)
186
187#define PORT_DATA_O(nr) \
188 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT)
189
190#define PORT_DATA_IO(nr) \
191 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
192 PORT##nr##_IN)
193
194#define PORT_DATA_IO_PD(nr) \
195 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
196 PORT##nr##_IN, PORT##nr##_IN_PD)
197
198#define PORT_DATA_IO_PU(nr) \
199 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
200 PORT##nr##_IN, PORT##nr##_IN_PU)
201
202#define PORT_DATA_IO_PU_PD(nr) \
203 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
204 PORT##nr##_IN, PORT##nr##_IN_PD, PORT##nr##_IN_PU)
205
Kuninori Morimoto9b491392011-11-10 18:45:43 -0800206/* helper macro for top 4 bits in PORTnCR */
207#define _PCRH(in, in_pd, in_pu, out) \
208 0, (out), (in), 0, \
209 0, 0, 0, 0, \
210 0, 0, (in_pd), 0, \
211 0, 0, (in_pu), 0
212
213#define PORTCR(nr, reg) \
214 { \
215 PINMUX_CFG_REG("PORT" nr "CR", reg, 8, 4) { \
216 _PCRH(PORT##nr##_IN, PORT##nr##_IN_PD, \
217 PORT##nr##_IN_PU, PORT##nr##_OUT), \
218 PORT##nr##_FN0, PORT##nr##_FN1, \
219 PORT##nr##_FN2, PORT##nr##_FN3, \
220 PORT##nr##_FN4, PORT##nr##_FN5, \
221 PORT##nr##_FN6, PORT##nr##_FN7 } \
222 }
Kuninori Morimotobd8d0cba2011-11-10 18:45:23 -0800223
Magnus Dammfae43392009-11-27 07:38:01 +0000224#endif /* __SH_PFC_H */