blob: d482c40b012a622ad720ec7f079a64f5b3d6fcbf [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
Laurent Pinchartbf9f0672013-04-09 14:06:01 +000014#include <linux/bug.h>
Paul Mundt72c7afa2012-07-10 11:59:29 +090015#include <linux/stringify.h>
Magnus Dammfae43392009-11-27 07:38:01 +000016
Paul Mundt06d56312012-06-21 00:03:41 +090017enum {
18 PINMUX_TYPE_NONE,
Paul Mundt06d56312012-06-21 00:03:41 +090019 PINMUX_TYPE_FUNCTION,
20 PINMUX_TYPE_GPIO,
21 PINMUX_TYPE_OUTPUT,
22 PINMUX_TYPE_INPUT,
Paul Mundt06d56312012-06-21 00:03:41 +090023};
Magnus Dammfae43392009-11-27 07:38:01 +000024
Laurent Pinchartc58d9c12013-03-10 16:44:02 +010025#define SH_PFC_PIN_CFG_INPUT (1 << 0)
26#define SH_PFC_PIN_CFG_OUTPUT (1 << 1)
27#define SH_PFC_PIN_CFG_PULL_UP (1 << 2)
28#define SH_PFC_PIN_CFG_PULL_DOWN (1 << 3)
Laurent Pinchart4f82e3e2013-07-15 21:10:54 +020029#define SH_PFC_PIN_CFG_NO_GPIO (1 << 31)
Laurent Pinchartc58d9c12013-03-10 16:44:02 +010030
Laurent Pincharta3db40a2013-01-02 14:53:37 +010031struct sh_pfc_pin {
Laurent Pinchart96898962013-02-14 00:59:49 +010032 u16 pin;
Laurent Pinchart533743d2013-07-15 13:03:20 +020033 u16 enum_id;
Paul Mundt72c7afa2012-07-10 11:59:29 +090034 const char *name;
Laurent Pinchartc58d9c12013-03-10 16:44:02 +010035 unsigned int configs;
Magnus Dammfae43392009-11-27 07:38:01 +000036};
37
Laurent Pinchart3d8d9f12013-01-03 14:33:13 +010038#define SH_PFC_PIN_GROUP(n) \
39 { \
40 .name = #n, \
41 .pins = n##_pins, \
42 .mux = n##_mux, \
43 .nr_pins = ARRAY_SIZE(n##_pins), \
44 }
45
46struct sh_pfc_pin_group {
47 const char *name;
48 const unsigned int *pins;
49 const unsigned int *mux;
50 unsigned int nr_pins;
51};
52
53#define SH_PFC_FUNCTION(n) \
54 { \
55 .name = #n, \
56 .groups = n##_groups, \
57 .nr_groups = ARRAY_SIZE(n##_groups), \
58 }
59
60struct sh_pfc_function {
61 const char *name;
62 const char * const *groups;
63 unsigned int nr_groups;
64};
65
Laurent Pincharta373ed02012-11-29 13:24:07 +010066struct pinmux_func {
Laurent Pinchart533743d2013-07-15 13:03:20 +020067 u16 enum_id;
Laurent Pincharta373ed02012-11-29 13:24:07 +010068 const char *name;
69};
70
Magnus Dammfae43392009-11-27 07:38:01 +000071struct pinmux_cfg_reg {
72 unsigned long reg, reg_width, field_width;
Laurent Pinchart533743d2013-07-15 13:03:20 +020073 const u16 *enum_ids;
Laurent Pinchartcd3c1be2013-02-16 18:47:05 +010074 const unsigned long *var_field_width;
Magnus Dammfae43392009-11-27 07:38:01 +000075};
76
77#define PINMUX_CFG_REG(name, r, r_width, f_width) \
78 .reg = r, .reg_width = r_width, .field_width = f_width, \
Laurent Pinchart9aecff52013-12-16 20:25:14 +010079 .enum_ids = (const u16 [(r_width / f_width) * (1 << f_width)])
Magnus Dammf78a26f2011-12-14 01:01:05 +090080
81#define PINMUX_CFG_REG_VAR(name, r, r_width, var_fw0, var_fwn...) \
82 .reg = r, .reg_width = r_width, \
Laurent Pinchart9aecff52013-12-16 20:25:14 +010083 .var_field_width = (const unsigned long [r_width]) \
84 { var_fw0, var_fwn, 0 }, \
85 .enum_ids = (const u16 [])
Magnus Dammfae43392009-11-27 07:38:01 +000086
87struct pinmux_data_reg {
Laurent Pinchart51cb2262013-02-16 18:34:32 +010088 unsigned long reg, reg_width;
Laurent Pinchart533743d2013-07-15 13:03:20 +020089 const u16 *enum_ids;
Magnus Dammfae43392009-11-27 07:38:01 +000090};
91
92#define PINMUX_DATA_REG(name, r, r_width) \
93 .reg = r, .reg_width = r_width, \
Laurent Pinchart9aecff52013-12-16 20:25:14 +010094 .enum_ids = (const u16 [r_width]) \
Magnus Dammfae43392009-11-27 07:38:01 +000095
Magnus Dammad2a8e72011-09-28 16:50:58 +090096struct pinmux_irq {
97 int irq;
Laurent Pinchart6d5bddd2013-12-16 20:25:15 +010098 const short *gpios;
Magnus Dammad2a8e72011-09-28 16:50:58 +090099};
100
Laurent Pinchart0e26e8d2014-05-13 13:37:46 +0200101#ifdef CONFIG_ARCH_MULTIPLATFORM
102#define PINMUX_IRQ(irq_nr, ids...) \
103 { .gpios = (const short []) { ids, -1 } }
104#else
Magnus Dammad2a8e72011-09-28 16:50:58 +0900105#define PINMUX_IRQ(irq_nr, ids...) \
Laurent Pinchart6d5bddd2013-12-16 20:25:15 +0100106 { .irq = irq_nr, .gpios = (const short []) { ids, -1 } }
Laurent Pinchart0e26e8d2014-05-13 13:37:46 +0200107#endif
Magnus Dammad2a8e72011-09-28 16:50:58 +0900108
Magnus Dammfae43392009-11-27 07:38:01 +0000109struct pinmux_range {
Laurent Pinchart533743d2013-07-15 13:03:20 +0200110 u16 begin;
111 u16 end;
112 u16 force;
Magnus Dammfae43392009-11-27 07:38:01 +0000113};
114
Laurent Pinchartc58d9c12013-03-10 16:44:02 +0100115struct sh_pfc;
116
117struct sh_pfc_soc_operations {
Laurent Pinchart0c151062013-04-21 20:21:57 +0200118 int (*init)(struct sh_pfc *pfc);
119 void (*exit)(struct sh_pfc *pfc);
Laurent Pinchartc58d9c12013-03-10 16:44:02 +0100120 unsigned int (*get_bias)(struct sh_pfc *pfc, unsigned int pin);
121 void (*set_bias)(struct sh_pfc *pfc, unsigned int pin,
122 unsigned int bias);
123};
124
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100125struct sh_pfc_soc_info {
Laurent Pinchartcd3c1be2013-02-16 18:47:05 +0100126 const char *name;
Laurent Pinchartc58d9c12013-03-10 16:44:02 +0100127 const struct sh_pfc_soc_operations *ops;
128
Magnus Dammfae43392009-11-27 07:38:01 +0000129 struct pinmux_range input;
Magnus Dammfae43392009-11-27 07:38:01 +0000130 struct pinmux_range output;
Magnus Dammfae43392009-11-27 07:38:01 +0000131 struct pinmux_range function;
132
Laurent Pinchartcd3c1be2013-02-16 18:47:05 +0100133 const struct sh_pfc_pin *pins;
Laurent Pinchartcaa5bac2012-11-29 12:24:51 +0100134 unsigned int nr_pins;
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 Pinchart533743d2013-07-15 13:03:20 +0200146 const u16 *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 Pincharte3d93b42013-07-15 15:14:22 +0200155/* -----------------------------------------------------------------------------
156 * Helper macros to create pin and port lists
157 */
158
159/*
160 * sh_pfc_soc_info gpio_data array macros
161 */
162
163#define PINMUX_DATA(data_or_mark, ids...) data_or_mark, ids, 0
164
165#define PINMUX_IPSR_NOGP(ispr, fn) \
166 PINMUX_DATA(fn##_MARK, FN_##fn)
167#define PINMUX_IPSR_DATA(ipsr, fn) \
168 PINMUX_DATA(fn##_MARK, FN_##fn, FN_##ipsr)
169#define PINMUX_IPSR_NOGM(ispr, fn, ms) \
170 PINMUX_DATA(fn##_MARK, FN_##fn, FN_##ms)
171#define PINMUX_IPSR_MSEL(ipsr, fn, ms) \
172 PINMUX_DATA(fn##_MARK, FN_##fn, FN_##ipsr, FN_##ms)
173#define PINMUX_IPSR_MODSEL_DATA(ipsr, fn, ms) \
174 PINMUX_DATA(fn##_MARK, FN_##ms, FN_##ipsr, FN_##fn)
175
176/*
177 * GP port style (32 ports banks)
178 */
179
180#define PORT_GP_1(bank, pin, fn, sfx) fn(bank, pin, GP_##bank##_##pin, sfx)
181
182#define PORT_GP_32(bank, fn, sfx) \
183 PORT_GP_1(bank, 0, fn, sfx), PORT_GP_1(bank, 1, fn, sfx), \
184 PORT_GP_1(bank, 2, fn, sfx), PORT_GP_1(bank, 3, fn, sfx), \
185 PORT_GP_1(bank, 4, fn, sfx), PORT_GP_1(bank, 5, fn, sfx), \
186 PORT_GP_1(bank, 6, fn, sfx), PORT_GP_1(bank, 7, fn, sfx), \
187 PORT_GP_1(bank, 8, fn, sfx), PORT_GP_1(bank, 9, fn, sfx), \
188 PORT_GP_1(bank, 10, fn, sfx), PORT_GP_1(bank, 11, fn, sfx), \
189 PORT_GP_1(bank, 12, fn, sfx), PORT_GP_1(bank, 13, fn, sfx), \
190 PORT_GP_1(bank, 14, fn, sfx), PORT_GP_1(bank, 15, fn, sfx), \
191 PORT_GP_1(bank, 16, fn, sfx), PORT_GP_1(bank, 17, fn, sfx), \
192 PORT_GP_1(bank, 18, fn, sfx), PORT_GP_1(bank, 19, fn, sfx), \
193 PORT_GP_1(bank, 20, fn, sfx), PORT_GP_1(bank, 21, fn, sfx), \
194 PORT_GP_1(bank, 22, fn, sfx), PORT_GP_1(bank, 23, fn, sfx), \
195 PORT_GP_1(bank, 24, fn, sfx), PORT_GP_1(bank, 25, fn, sfx), \
196 PORT_GP_1(bank, 26, fn, sfx), PORT_GP_1(bank, 27, fn, sfx), \
197 PORT_GP_1(bank, 28, fn, sfx), PORT_GP_1(bank, 29, fn, sfx), \
198 PORT_GP_1(bank, 30, fn, sfx), PORT_GP_1(bank, 31, fn, sfx)
199
200#define PORT_GP_32_REV(bank, fn, sfx) \
201 PORT_GP_1(bank, 31, fn, sfx), PORT_GP_1(bank, 30, fn, sfx), \
202 PORT_GP_1(bank, 29, fn, sfx), PORT_GP_1(bank, 28, fn, sfx), \
203 PORT_GP_1(bank, 27, fn, sfx), PORT_GP_1(bank, 26, fn, sfx), \
204 PORT_GP_1(bank, 25, fn, sfx), PORT_GP_1(bank, 24, fn, sfx), \
205 PORT_GP_1(bank, 23, fn, sfx), PORT_GP_1(bank, 22, fn, sfx), \
206 PORT_GP_1(bank, 21, fn, sfx), PORT_GP_1(bank, 20, fn, sfx), \
207 PORT_GP_1(bank, 19, fn, sfx), PORT_GP_1(bank, 18, fn, sfx), \
208 PORT_GP_1(bank, 17, fn, sfx), PORT_GP_1(bank, 16, fn, sfx), \
209 PORT_GP_1(bank, 15, fn, sfx), PORT_GP_1(bank, 14, fn, sfx), \
210 PORT_GP_1(bank, 13, fn, sfx), PORT_GP_1(bank, 12, fn, sfx), \
211 PORT_GP_1(bank, 11, fn, sfx), PORT_GP_1(bank, 10, fn, sfx), \
212 PORT_GP_1(bank, 9, fn, sfx), PORT_GP_1(bank, 8, fn, sfx), \
213 PORT_GP_1(bank, 7, fn, sfx), PORT_GP_1(bank, 6, fn, sfx), \
214 PORT_GP_1(bank, 5, fn, sfx), PORT_GP_1(bank, 4, fn, sfx), \
215 PORT_GP_1(bank, 3, fn, sfx), PORT_GP_1(bank, 2, fn, sfx), \
216 PORT_GP_1(bank, 1, fn, sfx), PORT_GP_1(bank, 0, fn, sfx)
217
218/* GP_ALL(suffix) - Expand to a list of GP_#_#_suffix */
219#define _GP_ALL(bank, pin, name, sfx) name##_##sfx
220#define GP_ALL(str) CPU_ALL_PORT(_GP_ALL, str)
221
222/* PINMUX_GPIO_GP_ALL - Expand to a list of sh_pfc_pin entries */
Laurent Pinchart96898962013-02-14 00:59:49 +0100223#define _GP_GPIO(bank, _pin, _name, sfx) \
224 [(bank * 32) + _pin] = { \
225 .pin = (bank * 32) + _pin, \
Laurent Pincharte3d93b42013-07-15 15:14:22 +0200226 .name = __stringify(_name), \
227 .enum_id = _name##_DATA, \
228 }
229#define PINMUX_GPIO_GP_ALL() CPU_ALL_PORT(_GP_GPIO, unused)
230
231/* PINMUX_DATA_GP_ALL - Expand to a list of name_DATA, name_FN marks */
232#define _GP_DATA(bank, pin, name, sfx) PINMUX_DATA(name##_DATA, name##_FN)
233#define PINMUX_DATA_GP_ALL() CPU_ALL_PORT(_GP_DATA, unused)
234
235/*
236 * PORT style (linear pin space)
237 */
238
Laurent Pinchart3ce0d7e2013-02-14 00:41:57 +0100239#define PORT_1(pn, fn, pfx, sfx) fn(pn, pfx, sfx)
Kuninori Morimoto972c3fb2011-11-10 18:45:33 -0800240
Laurent Pinchart16b915e2013-02-14 00:24:32 +0100241#define PORT_10(pn, fn, pfx, sfx) \
242 PORT_1(pn, fn, pfx##0, sfx), PORT_1(pn+1, fn, pfx##1, sfx), \
243 PORT_1(pn+2, fn, pfx##2, sfx), PORT_1(pn+3, fn, pfx##3, sfx), \
244 PORT_1(pn+4, fn, pfx##4, sfx), PORT_1(pn+5, fn, pfx##5, sfx), \
245 PORT_1(pn+6, fn, pfx##6, sfx), PORT_1(pn+7, fn, pfx##7, sfx), \
246 PORT_1(pn+8, fn, pfx##8, sfx), PORT_1(pn+9, fn, pfx##9, sfx)
Kuninori Morimoto972c3fb2011-11-10 18:45:33 -0800247
Laurent Pinchart16b915e2013-02-14 00:24:32 +0100248#define PORT_90(pn, fn, pfx, sfx) \
249 PORT_10(pn+10, fn, pfx##1, sfx), PORT_10(pn+20, fn, pfx##2, sfx), \
250 PORT_10(pn+30, fn, pfx##3, sfx), PORT_10(pn+40, fn, pfx##4, sfx), \
251 PORT_10(pn+50, fn, pfx##5, sfx), PORT_10(pn+60, fn, pfx##6, sfx), \
252 PORT_10(pn+70, fn, pfx##7, sfx), PORT_10(pn+80, fn, pfx##8, sfx), \
253 PORT_10(pn+90, fn, pfx##9, sfx)
Kuninori Morimoto972c3fb2011-11-10 18:45:33 -0800254
Laurent Pincharte3d93b42013-07-15 15:14:22 +0200255/* PORT_ALL(suffix) - Expand to a list of PORT_#_suffix */
Laurent Pinchart3ce0d7e2013-02-14 00:41:57 +0100256#define _PORT_ALL(pn, pfx, sfx) pfx##_##sfx
Laurent Pincharte3d93b42013-07-15 15:14:22 +0200257#define PORT_ALL(str) CPU_ALL_PORT(_PORT_ALL, PORT, str)
Kuninori Morimoto972c3fb2011-11-10 18:45:33 -0800258
Laurent Pincharte3d93b42013-07-15 15:14:22 +0200259/* PINMUX_GPIO - Expand to a sh_pfc_pin entry */
Laurent Pinchart96898962013-02-14 00:59:49 +0100260#define PINMUX_GPIO(_pin) \
261 [GPIO_##_pin] = { \
262 .pin = (u16)-1, \
Laurent Pinchart8620f392013-11-26 02:45:34 +0100263 .name = __stringify(GPIO_##_pin), \
Laurent Pinchart96898962013-02-14 00:59:49 +0100264 .enum_id = _pin##_DATA, \
Laurent Pincharte3d93b42013-07-15 15:14:22 +0200265 }
Kuninori Morimotobd8d0cba2011-11-10 18:45:23 -0800266
Laurent Pinchartdf020272013-07-15 17:42:48 +0200267/* SH_PFC_PIN_CFG - Expand to a sh_pfc_pin entry (named PORT#) with config */
Laurent Pinchart96898962013-02-14 00:59:49 +0100268#define SH_PFC_PIN_CFG(_pin, cfgs) \
Laurent Pinchartdf020272013-07-15 17:42:48 +0200269 { \
Laurent Pinchart96898962013-02-14 00:59:49 +0100270 .pin = _pin, \
271 .name = __stringify(PORT##_pin), \
272 .enum_id = PORT##_pin##_DATA, \
Laurent Pinchartdf020272013-07-15 17:42:48 +0200273 .configs = cfgs, \
274 }
275
Laurent Pinchart4f82e3e2013-07-15 21:10:54 +0200276/* SH_PFC_PIN_NAMED - Expand to a sh_pfc_pin entry with the given name */
277#define SH_PFC_PIN_NAMED(row, col, _name) \
278 { \
279 .pin = PIN_NUMBER(row, col), \
280 .name = __stringify(PIN_##_name), \
281 .configs = SH_PFC_PIN_CFG_NO_GPIO, \
282 }
283
Laurent Pincharte3d93b42013-07-15 15:14:22 +0200284/* PINMUX_DATA_ALL - Expand to a list of PORT_name_DATA, PORT_name_FN0,
285 * PORT_name_OUT, PORT_name_IN marks
286 */
Laurent Pinchart3ce0d7e2013-02-14 00:41:57 +0100287#define _PORT_DATA(pn, pfx, sfx) \
Laurent Pincharte3d93b42013-07-15 15:14:22 +0200288 PINMUX_DATA(PORT##pfx##_DATA, PORT##pfx##_FN0, \
289 PORT##pfx##_OUT, PORT##pfx##_IN)
290#define PINMUX_DATA_ALL() CPU_ALL_PORT(_PORT_DATA, , unused)
291
292/* GPIO_FN(name) - Expand to a sh_pfc_pin entry for a function GPIO */
293#define PINMUX_GPIO_FN(gpio, base, data_or_mark) \
294 [gpio - (base)] = { \
295 .name = __stringify(gpio), \
296 .enum_id = data_or_mark, \
297 }
298#define GPIO_FN(str) \
299 PINMUX_GPIO_FN(GPIO_FN_##str, PINMUX_FN_BASE, str##_MARK)
300
301/*
302 * PORTnCR macro
303 */
Kuninori Morimoto9b491392011-11-10 18:45:43 -0800304#define _PCRH(in, in_pd, in_pu, out) \
305 0, (out), (in), 0, \
306 0, 0, 0, 0, \
307 0, 0, (in_pd), 0, \
308 0, 0, (in_pu), 0
309
310#define PORTCR(nr, reg) \
311 { \
312 PINMUX_CFG_REG("PORT" nr "CR", reg, 8, 4) { \
Laurent Pinchart3f9c1262013-10-29 13:02:18 +0100313 _PCRH(PORT##nr##_IN, 0, 0, PORT##nr##_OUT), \
Kuninori Morimoto9b491392011-11-10 18:45:43 -0800314 PORT##nr##_FN0, PORT##nr##_FN1, \
315 PORT##nr##_FN2, PORT##nr##_FN3, \
316 PORT##nr##_FN4, PORT##nr##_FN5, \
317 PORT##nr##_FN6, PORT##nr##_FN7 } \
318 }
Kuninori Morimotobd8d0cba2011-11-10 18:45:23 -0800319
Magnus Dammfae43392009-11-27 07:38:01 +0000320#endif /* __SH_PFC_H */