blob: 9fd62282c625ce15a34b070aed0bd8f971b7e52e [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 {
39 pinmux_enum_t enum_id;
40 pinmux_flag_t flags;
Paul Mundt72c7afa2012-07-10 11:59:29 +090041 const char *name;
Magnus Dammfae43392009-11-27 07:38:01 +000042};
43
Paul Mundt06d56312012-06-21 00:03:41 +090044#define PINMUX_GPIO(gpio, data_or_mark) \
Paul Mundt72c7afa2012-07-10 11:59:29 +090045 [gpio] = { .name = __stringify(gpio), .enum_id = data_or_mark, .flags = PINMUX_TYPE_NONE }
Paul Mundt06d56312012-06-21 00:03:41 +090046
Magnus Dammfae43392009-11-27 07:38:01 +000047#define PINMUX_DATA(data_or_mark, ids...) data_or_mark, ids, 0
48
49struct pinmux_cfg_reg {
50 unsigned long reg, reg_width, field_width;
51 unsigned long *cnt;
52 pinmux_enum_t *enum_ids;
Magnus Dammf78a26f2011-12-14 01:01:05 +090053 unsigned long *var_field_width;
Magnus Dammfae43392009-11-27 07:38:01 +000054};
55
56#define PINMUX_CFG_REG(name, r, r_width, f_width) \
57 .reg = r, .reg_width = r_width, .field_width = f_width, \
58 .cnt = (unsigned long [r_width / f_width]) {}, \
Magnus Dammf78a26f2011-12-14 01:01:05 +090059 .enum_ids = (pinmux_enum_t [(r_width / f_width) * (1 << f_width)])
60
61#define PINMUX_CFG_REG_VAR(name, r, r_width, var_fw0, var_fwn...) \
62 .reg = r, .reg_width = r_width, \
63 .cnt = (unsigned long [r_width]) {}, \
64 .var_field_width = (unsigned long [r_width]) { var_fw0, var_fwn, 0 }, \
65 .enum_ids = (pinmux_enum_t [])
Magnus Dammfae43392009-11-27 07:38:01 +000066
67struct pinmux_data_reg {
68 unsigned long reg, reg_width, reg_shadow;
69 pinmux_enum_t *enum_ids;
Magnus Dammb0e10212011-12-09 12:14:27 +090070 void __iomem *mapped_reg;
Magnus Dammfae43392009-11-27 07:38:01 +000071};
72
73#define PINMUX_DATA_REG(name, r, r_width) \
74 .reg = r, .reg_width = r_width, \
75 .enum_ids = (pinmux_enum_t [r_width]) \
76
Magnus Dammad2a8e72011-09-28 16:50:58 +090077struct pinmux_irq {
78 int irq;
79 pinmux_enum_t *enum_ids;
80};
81
82#define PINMUX_IRQ(irq_nr, ids...) \
83 { .irq = irq_nr, .enum_ids = (pinmux_enum_t []) { ids, 0 } } \
84
Magnus Dammfae43392009-11-27 07:38:01 +000085struct pinmux_range {
86 pinmux_enum_t begin;
87 pinmux_enum_t end;
88 pinmux_enum_t force;
89};
90
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +010091struct sh_pfc_soc_info {
Magnus Dammfae43392009-11-27 07:38:01 +000092 char *name;
93 pinmux_enum_t reserved_id;
94 struct pinmux_range data;
95 struct pinmux_range input;
96 struct pinmux_range input_pd;
97 struct pinmux_range input_pu;
98 struct pinmux_range output;
99 struct pinmux_range mark;
100 struct pinmux_range function;
101
102 unsigned first_gpio, last_gpio;
103
104 struct pinmux_gpio *gpios;
105 struct pinmux_cfg_reg *cfg_regs;
106 struct pinmux_data_reg *data_regs;
107
108 pinmux_enum_t *gpio_data;
109 unsigned int gpio_data_size;
110
Magnus Dammad2a8e72011-09-28 16:50:58 +0900111 struct pinmux_irq *gpio_irq;
112 unsigned int gpio_irq_size;
113
Magnus Damme499ada2011-12-14 01:01:14 +0900114 unsigned long unlock_reg;
Magnus Dammfae43392009-11-27 07:38:01 +0000115};
116
Paul Mundtb3c185a2012-06-20 17:29:04 +0900117/* XXX compat for now */
Laurent Pinchart19bb7fe32012-12-15 23:51:20 +0100118#define pinmux_info sh_pfc_soc_info
Paul Mundtb3c185a2012-06-20 17:29:04 +0900119
Paul Mundtb3c185a2012-06-20 17:29:04 +0900120enum { GPIO_CFG_DRYRUN, GPIO_CFG_REQ, GPIO_CFG_FREE };
Magnus Dammfae43392009-11-27 07:38:01 +0000121
Kuninori Morimoto972c3fb2011-11-10 18:45:33 -0800122/* helper macro for port */
123#define PORT_1(fn, pfx, sfx) fn(pfx, sfx)
124
125#define PORT_10(fn, pfx, sfx) \
126 PORT_1(fn, pfx##0, sfx), PORT_1(fn, pfx##1, sfx), \
127 PORT_1(fn, pfx##2, sfx), PORT_1(fn, pfx##3, sfx), \
128 PORT_1(fn, pfx##4, sfx), PORT_1(fn, pfx##5, sfx), \
129 PORT_1(fn, pfx##6, sfx), PORT_1(fn, pfx##7, sfx), \
130 PORT_1(fn, pfx##8, sfx), PORT_1(fn, pfx##9, sfx)
131
132#define PORT_90(fn, pfx, sfx) \
133 PORT_10(fn, pfx##1, sfx), PORT_10(fn, pfx##2, sfx), \
134 PORT_10(fn, pfx##3, sfx), PORT_10(fn, pfx##4, sfx), \
135 PORT_10(fn, pfx##5, sfx), PORT_10(fn, pfx##6, sfx), \
136 PORT_10(fn, pfx##7, sfx), PORT_10(fn, pfx##8, sfx), \
137 PORT_10(fn, pfx##9, sfx)
138
139#define _PORT_ALL(pfx, sfx) pfx##_##sfx
140#define _GPIO_PORT(pfx, sfx) PINMUX_GPIO(GPIO_PORT##pfx, PORT##pfx##_DATA)
141#define PORT_ALL(str) CPU_ALL_PORT(_PORT_ALL, PORT, str)
142#define GPIO_PORT_ALL() CPU_ALL_PORT(_GPIO_PORT, , unused)
143#define GPIO_FN(str) PINMUX_GPIO(GPIO_FN_##str, str##_MARK)
144
Kuninori Morimotobd8d0cba2011-11-10 18:45:23 -0800145/* helper macro for pinmux_enum_t */
146#define PORT_DATA_I(nr) \
147 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_IN)
148
149#define PORT_DATA_I_PD(nr) \
150 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \
151 PORT##nr##_IN, PORT##nr##_IN_PD)
152
153#define PORT_DATA_I_PU(nr) \
154 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \
155 PORT##nr##_IN, PORT##nr##_IN_PU)
156
157#define PORT_DATA_I_PU_PD(nr) \
158 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, \
159 PORT##nr##_IN, PORT##nr##_IN_PD, PORT##nr##_IN_PU)
160
161#define PORT_DATA_O(nr) \
162 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT)
163
164#define PORT_DATA_IO(nr) \
165 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
166 PORT##nr##_IN)
167
168#define PORT_DATA_IO_PD(nr) \
169 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
170 PORT##nr##_IN, PORT##nr##_IN_PD)
171
172#define PORT_DATA_IO_PU(nr) \
173 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
174 PORT##nr##_IN, PORT##nr##_IN_PU)
175
176#define PORT_DATA_IO_PU_PD(nr) \
177 PINMUX_DATA(PORT##nr##_DATA, PORT##nr##_FN0, PORT##nr##_OUT, \
178 PORT##nr##_IN, PORT##nr##_IN_PD, PORT##nr##_IN_PU)
179
Kuninori Morimoto9b491392011-11-10 18:45:43 -0800180/* helper macro for top 4 bits in PORTnCR */
181#define _PCRH(in, in_pd, in_pu, out) \
182 0, (out), (in), 0, \
183 0, 0, 0, 0, \
184 0, 0, (in_pd), 0, \
185 0, 0, (in_pu), 0
186
187#define PORTCR(nr, reg) \
188 { \
189 PINMUX_CFG_REG("PORT" nr "CR", reg, 8, 4) { \
190 _PCRH(PORT##nr##_IN, PORT##nr##_IN_PD, \
191 PORT##nr##_IN_PU, PORT##nr##_OUT), \
192 PORT##nr##_FN0, PORT##nr##_FN1, \
193 PORT##nr##_FN2, PORT##nr##_FN3, \
194 PORT##nr##_FN4, PORT##nr##_FN5, \
195 PORT##nr##_FN6, PORT##nr##_FN7 } \
196 }
Kuninori Morimotobd8d0cba2011-11-10 18:45:23 -0800197
Magnus Dammfae43392009-11-27 07:38:01 +0000198#endif /* __SH_PFC_H */