blob: f9d448099bcb405b5465a1ba5d17f4268423cbb2 [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
141#define PORT_90(fn, pfx, sfx) \
142 PORT_10(fn, pfx##1, sfx), PORT_10(fn, pfx##2, sfx), \
143 PORT_10(fn, pfx##3, sfx), PORT_10(fn, pfx##4, sfx), \
144 PORT_10(fn, pfx##5, sfx), PORT_10(fn, pfx##6, sfx), \
145 PORT_10(fn, pfx##7, sfx), PORT_10(fn, pfx##8, sfx), \
146 PORT_10(fn, pfx##9, sfx)
147
148#define _PORT_ALL(pfx, sfx) pfx##_##sfx
149#define _GPIO_PORT(pfx, sfx) PINMUX_GPIO(GPIO_PORT##pfx, PORT##pfx##_DATA)
150#define PORT_ALL(str) CPU_ALL_PORT(_PORT_ALL, PORT, str)
151#define GPIO_PORT_ALL() CPU_ALL_PORT(_GPIO_PORT, , unused)
Laurent Pincharta373ed02012-11-29 13:24:07 +0100152#define GPIO_FN(str) PINMUX_GPIO_FN(GPIO_FN_##str, PINMUX_FN_BASE, str##_MARK)
Kuninori Morimoto972c3fb2011-11-10 18:45:33 -0800153
Kuninori Morimotobd8d0cba2011-11-10 18:45:23 -0800154/* helper macro for pinmux_enum_t */
155#define PORT_DATA_I(nr) \
156 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_IN)
157
158#define PORT_DATA_I_PD(nr) \
159 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \
160 PORT##nr##_IN, PORT##nr##_IN_PD)
161
162#define PORT_DATA_I_PU(nr) \
163 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \
164 PORT##nr##_IN, PORT##nr##_IN_PU)
165
166#define PORT_DATA_I_PU_PD(nr) \
167 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \
168 PORT##nr##_IN, PORT##nr##_IN_PD, PORT##nr##_IN_PU)
169
170#define PORT_DATA_O(nr) \
171 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT)
172
173#define PORT_DATA_IO(nr) \
174 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
175 PORT##nr##_IN)
176
177#define PORT_DATA_IO_PD(nr) \
178 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
179 PORT##nr##_IN, PORT##nr##_IN_PD)
180
181#define PORT_DATA_IO_PU(nr) \
182 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
183 PORT##nr##_IN, PORT##nr##_IN_PU)
184
185#define PORT_DATA_IO_PU_PD(nr) \
186 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
187 PORT##nr##_IN, PORT##nr##_IN_PD, PORT##nr##_IN_PU)
188
Kuninori Morimoto9b491392011-11-10 18:45:43 -0800189/* helper macro for top 4 bits in PORTnCR */
190#define _PCRH(in, in_pd, in_pu, out) \
191 0, (out), (in), 0, \
192 0, 0, 0, 0, \
193 0, 0, (in_pd), 0, \
194 0, 0, (in_pu), 0
195
196#define PORTCR(nr, reg) \
197 { \
198 PINMUX_CFG_REG("PORT" nr "CR", reg, 8, 4) { \
199 _PCRH(PORT##nr##_IN, PORT##nr##_IN_PD, \
200 PORT##nr##_IN_PU, PORT##nr##_OUT), \
201 PORT##nr##_FN0, PORT##nr##_FN1, \
202 PORT##nr##_FN2, PORT##nr##_FN3, \
203 PORT##nr##_FN4, PORT##nr##_FN5, \
204 PORT##nr##_FN6, PORT##nr##_FN7 } \
205 }
Kuninori Morimotobd8d0cba2011-11-10 18:45:23 -0800206
Magnus Dammfae43392009-11-27 07:38:01 +0000207#endif /* __SH_PFC_H */