blob: 6ed7ab9d56d4fdbb64b808120a0f7dc3ec8356d4 [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;
18typedef unsigned short pinmux_flag_t;
19
Paul Mundt06d56312012-06-21 00:03:41 +090020enum {
21 PINMUX_TYPE_NONE,
Magnus Dammfae43392009-11-27 07:38:01 +000022
Paul Mundt06d56312012-06-21 00:03:41 +090023 PINMUX_TYPE_FUNCTION,
24 PINMUX_TYPE_GPIO,
25 PINMUX_TYPE_OUTPUT,
26 PINMUX_TYPE_INPUT,
27 PINMUX_TYPE_INPUT_PULLUP,
28 PINMUX_TYPE_INPUT_PULLDOWN,
29
30 PINMUX_FLAG_TYPE, /* must be last */
31};
Magnus Dammfae43392009-11-27 07:38:01 +000032
33#define PINMUX_FLAG_DBIT_SHIFT 5
34#define PINMUX_FLAG_DBIT (0x1f << PINMUX_FLAG_DBIT_SHIFT)
35#define PINMUX_FLAG_DREG_SHIFT 10
36#define PINMUX_FLAG_DREG (0x3f << PINMUX_FLAG_DREG_SHIFT)
37
38struct pinmux_gpio {
Laurent Pinchart051fae42012-11-28 19:22:18 +010039 const pinmux_enum_t enum_id;
Magnus Dammfae43392009-11-27 07:38:01 +000040 pinmux_flag_t flags;
Paul Mundt72c7afa2012-07-10 11:59:29 +090041 const char *name;
Magnus Dammfae43392009-11-27 07:38:01 +000042};
43
Laurent Pinchart380c2ed2012-11-29 02:23:26 +010044#define PINMUX_GPIO(gpio, data_or_mark) \
45 [gpio] = { \
46 .name = __stringify(gpio), \
47 .enum_id = data_or_mark, \
48 .flags = PINMUX_TYPE_GPIO \
49 }
50#define PINMUX_GPIO_FN(gpio, data_or_mark) \
51 [gpio] = { \
52 .name = __stringify(gpio), \
53 .enum_id = data_or_mark, \
54 .flags = PINMUX_TYPE_FUNCTION \
55 }
Paul Mundt06d56312012-06-21 00:03:41 +090056
Magnus Dammfae43392009-11-27 07:38:01 +000057#define PINMUX_DATA(data_or_mark, ids...) data_or_mark, ids, 0
58
59struct pinmux_cfg_reg {
60 unsigned long reg, reg_width, field_width;
61 unsigned long *cnt;
62 pinmux_enum_t *enum_ids;
Magnus Dammf78a26f2011-12-14 01:01:05 +090063 unsigned long *var_field_width;
Magnus Dammfae43392009-11-27 07:38:01 +000064};
65
66#define PINMUX_CFG_REG(name, r, r_width, f_width) \
67 .reg = r, .reg_width = r_width, .field_width = f_width, \
68 .cnt = (unsigned long [r_width / f_width]) {}, \
Magnus Dammf78a26f2011-12-14 01:01:05 +090069 .enum_ids = (pinmux_enum_t [(r_width / f_width) * (1 << f_width)])
70
71#define PINMUX_CFG_REG_VAR(name, r, r_width, var_fw0, var_fwn...) \
72 .reg = r, .reg_width = r_width, \
73 .cnt = (unsigned long [r_width]) {}, \
74 .var_field_width = (unsigned long [r_width]) { var_fw0, var_fwn, 0 }, \
75 .enum_ids = (pinmux_enum_t [])
Magnus Dammfae43392009-11-27 07:38:01 +000076
77struct pinmux_data_reg {
78 unsigned long reg, reg_width, reg_shadow;
79 pinmux_enum_t *enum_ids;
Magnus Dammb0e10212011-12-09 12:14:27 +090080 void __iomem *mapped_reg;
Magnus Dammfae43392009-11-27 07:38:01 +000081};
82
83#define PINMUX_DATA_REG(name, r, r_width) \
84 .reg = r, .reg_width = r_width, \
85 .enum_ids = (pinmux_enum_t [r_width]) \
86
Magnus Dammad2a8e72011-09-28 16:50:58 +090087struct pinmux_irq {
88 int irq;
89 pinmux_enum_t *enum_ids;
90};
91
92#define PINMUX_IRQ(irq_nr, ids...) \
93 { .irq = irq_nr, .enum_ids = (pinmux_enum_t []) { ids, 0 } } \
94
Magnus Dammfae43392009-11-27 07:38:01 +000095struct pinmux_range {
96 pinmux_enum_t begin;
97 pinmux_enum_t end;
98 pinmux_enum_t force;
99};
100
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100101struct sh_pfc_soc_info {
Magnus Dammfae43392009-11-27 07:38:01 +0000102 char *name;
Magnus Dammfae43392009-11-27 07:38:01 +0000103 struct pinmux_range input;
104 struct pinmux_range input_pd;
105 struct pinmux_range input_pu;
106 struct pinmux_range output;
Magnus Dammfae43392009-11-27 07:38:01 +0000107 struct pinmux_range function;
108
Magnus Dammfae43392009-11-27 07:38:01 +0000109 struct pinmux_gpio *gpios;
Laurent Pinchartcaa5bac2012-11-29 12:24:51 +0100110 unsigned int nr_pins;
Laurent Pinchartd7a7ca52012-11-28 17:51:00 +0100111 unsigned int nr_gpios;
112
Magnus Dammfae43392009-11-27 07:38:01 +0000113 struct pinmux_cfg_reg *cfg_regs;
114 struct pinmux_data_reg *data_regs;
115
116 pinmux_enum_t *gpio_data;
117 unsigned int gpio_data_size;
118
Magnus Dammad2a8e72011-09-28 16:50:58 +0900119 struct pinmux_irq *gpio_irq;
120 unsigned int gpio_irq_size;
121
Magnus Damme499ada2011-12-14 01:01:14 +0900122 unsigned long unlock_reg;
Magnus Dammfae43392009-11-27 07:38:01 +0000123};
124
Paul Mundtb3c185a2012-06-20 17:29:04 +0900125enum { GPIO_CFG_DRYRUN, GPIO_CFG_REQ, GPIO_CFG_FREE };
Magnus Dammfae43392009-11-27 07:38:01 +0000126
Kuninori Morimoto972c3fb2011-11-10 18:45:33 -0800127/* helper macro for port */
128#define PORT_1(fn, pfx, sfx) fn(pfx, sfx)
129
130#define PORT_10(fn, pfx, sfx) \
131 PORT_1(fn, pfx##0, sfx), PORT_1(fn, pfx##1, sfx), \
132 PORT_1(fn, pfx##2, sfx), PORT_1(fn, pfx##3, sfx), \
133 PORT_1(fn, pfx##4, sfx), PORT_1(fn, pfx##5, sfx), \
134 PORT_1(fn, pfx##6, sfx), PORT_1(fn, pfx##7, sfx), \
135 PORT_1(fn, pfx##8, sfx), PORT_1(fn, pfx##9, sfx)
136
137#define PORT_90(fn, pfx, sfx) \
138 PORT_10(fn, pfx##1, sfx), PORT_10(fn, pfx##2, sfx), \
139 PORT_10(fn, pfx##3, sfx), PORT_10(fn, pfx##4, sfx), \
140 PORT_10(fn, pfx##5, sfx), PORT_10(fn, pfx##6, sfx), \
141 PORT_10(fn, pfx##7, sfx), PORT_10(fn, pfx##8, sfx), \
142 PORT_10(fn, pfx##9, sfx)
143
144#define _PORT_ALL(pfx, sfx) pfx##_##sfx
145#define _GPIO_PORT(pfx, sfx) PINMUX_GPIO(GPIO_PORT##pfx, PORT##pfx##_DATA)
146#define PORT_ALL(str) CPU_ALL_PORT(_PORT_ALL, PORT, str)
147#define GPIO_PORT_ALL() CPU_ALL_PORT(_GPIO_PORT, , unused)
Laurent Pinchart380c2ed2012-11-29 02:23:26 +0100148#define GPIO_FN(str) PINMUX_GPIO_FN(GPIO_FN_##str, str##_MARK)
Kuninori Morimoto972c3fb2011-11-10 18:45:33 -0800149
Kuninori Morimotobd8d0cba2011-11-10 18:45:23 -0800150/* helper macro for pinmux_enum_t */
151#define PORT_DATA_I(nr) \
152 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_IN)
153
154#define PORT_DATA_I_PD(nr) \
155 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \
156 PORT##nr##_IN, PORT##nr##_IN_PD)
157
158#define PORT_DATA_I_PU(nr) \
159 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \
160 PORT##nr##_IN, PORT##nr##_IN_PU)
161
162#define PORT_DATA_I_PU_PD(nr) \
163 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \
164 PORT##nr##_IN, PORT##nr##_IN_PD, PORT##nr##_IN_PU)
165
166#define PORT_DATA_O(nr) \
167 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT)
168
169#define PORT_DATA_IO(nr) \
170 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
171 PORT##nr##_IN)
172
173#define PORT_DATA_IO_PD(nr) \
174 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
175 PORT##nr##_IN, PORT##nr##_IN_PD)
176
177#define PORT_DATA_IO_PU(nr) \
178 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
179 PORT##nr##_IN, PORT##nr##_IN_PU)
180
181#define PORT_DATA_IO_PU_PD(nr) \
182 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
183 PORT##nr##_IN, PORT##nr##_IN_PD, PORT##nr##_IN_PU)
184
Kuninori Morimoto9b491392011-11-10 18:45:43 -0800185/* helper macro for top 4 bits in PORTnCR */
186#define _PCRH(in, in_pd, in_pu, out) \
187 0, (out), (in), 0, \
188 0, 0, 0, 0, \
189 0, 0, (in_pd), 0, \
190 0, 0, (in_pu), 0
191
192#define PORTCR(nr, reg) \
193 { \
194 PINMUX_CFG_REG("PORT" nr "CR", reg, 8, 4) { \
195 _PCRH(PORT##nr##_IN, PORT##nr##_IN_PD, \
196 PORT##nr##_IN_PU, PORT##nr##_OUT), \
197 PORT##nr##_FN0, PORT##nr##_FN1, \
198 PORT##nr##_FN2, PORT##nr##_FN3, \
199 PORT##nr##_FN4, PORT##nr##_FN5, \
200 PORT##nr##_FN6, PORT##nr##_FN7 } \
201 }
Kuninori Morimotobd8d0cba2011-11-10 18:45:23 -0800202
Magnus Dammfae43392009-11-27 07:38:01 +0000203#endif /* __SH_PFC_H */